private void replaceCref(Element element, bool exception, TypeInfo type, String suffix, String arguments) { if (suffix == null) { if (arguments != null) { context.addWarning(CompileErrorId.UnresolvedCref, node, element.getAttribute("cref")); element.setAttribute("cref", "!" + element.getAttribute("cref")); return; } if (exception) { if (!context.TypeSystem.getType("java/lang/Throwable").isAssignableFrom(type)) { context.addWarning(CompileErrorId.ExpectedExceptionInCref, node, element.getAttribute("cref")); element.setAttribute("cref", "!" + element.getAttribute("cref")); return; } } element.setAttribute("cref", getIdString(type)); } else { int idx = suffix.indexOf('.'); String name; if (idx == -1) { name = suffix; suffix = null; } else { name = suffix.substring(0, idx); suffix = suffix.substring(idx + 1); } var members = MemberInfo.getMembers(context.AnnotatedTypeSystem, context.CurrentType, type, name, true); replaceCref(element, exception, members, suffix, arguments); } }
private void replaceCref(Element element, bool exception, Iterable <MemberInfo> members, String suffix, String arguments) { if (members.count() > 1 && !members.all(p => p.MemberKind == MemberKind.Method)) { context.addWarning(CompileErrorId.UnresolvedCref, node, element.getAttribute("cref")); element.setAttribute("cref", "!" + element.getAttribute("cref")); return; } var member = members.first(); switch (member.MemberKind) { case Type: replaceCref(element, exception, member.Type, suffix, arguments); break; case Field: if (exception) { context.addWarning(CompileErrorId.ExpectedExceptionInCref, node, element.getAttribute("cref")); element.setAttribute("cref", "!" + element.getAttribute("cref")); return; } if (suffix != null || arguments != null) { context.addWarning(CompileErrorId.UnresolvedCref, node, element.getAttribute("cref")); element.setAttribute("cref", "!" + element.getAttribute("cref")); return; } element.setAttribute("cref", getIdString(member.Field)); break; case Property: if (exception) { context.addWarning(CompileErrorId.ExpectedExceptionInCref, node, element.getAttribute("cref")); element.setAttribute("cref", "!" + element.getAttribute("cref")); return; } if (suffix != null || arguments != null) { context.addWarning(CompileErrorId.UnresolvedCref, node, element.getAttribute("cref")); element.setAttribute("cref", "!" + element.getAttribute("cref")); return; } element.setAttribute("cref", getIdString(member.GetAccessor ?? member.SetAccessor)); break; case Method: if (!exception && suffix == null) { if (arguments == null && members.count() == 1) { element.setAttribute("cref", getIdString(member.Method)); return; } else if (arguments != null && arguments.endsWith(")")) { var args = new ArrayList <TypeInfo>(); if (arguments.length() > 2) { arguments = arguments.substring(1, arguments.length() - 1); int idx; while ((idx = arguments.indexOf(',')) != -1) { var name = arguments.substring(0, idx); arguments = arguments.substring(idx + 1); var type = getType(name); if (type == null) { goto failed; } args.add(type); } if (arguments.length() == 0) { goto failed; } var type = getType(arguments); if (type == null) { goto failed; } args.add(type); } foreach (var m in members) { if (m.Method.Parameters.select(p => p.Type).sequenceEqual(args)) { element.setAttribute("cref", getIdString(m.Method)); return; } } } } failed: context.addWarning(CompileErrorId.UnresolvedCref, node, element.getAttribute("cref")); element.setAttribute("cref", "!" + element.getAttribute("cref")); break; default: break; } }
private void replaceCref(Element element, bool exception) { var cref = element.getAttribute("cref"); if (Helper.isNullOrEmpty(cref)) { context.addWarning(CompileErrorId.MissingDocAttribute, node, "cref", element.getLocalName()); } else { if (cref.length() > 1 && cref[1] == ':') { return; } String arguments = null; int idx = cref.indexOf('('); if (idx != -1) { arguments = cref.substring(idx); cref = cref.substring(0, idx); } idx = cref.indexOf('.'); String name; if (idx == -1) { name = cref; cref = null; } else { name = cref.substring(0, idx); cref = cref.substring(idx + 1); } var members = context.MemberResolver.resolveName(context.CurrentType, name, Query.empty <TypeInfo>()).toList(); if (!members.any()) { if (cref == null) { context.addWarning(CompileErrorId.UnresolvedCref, node, element.getAttribute("cref")); element.setAttribute("cref", "!" + element.getAttribute("cref")); return; } var packageName = context.MemberResolver.getPackageFromAlias(name); if (packageName == null) { if (context.MemberResolver.TypeFinder.getSubPackages(name).any() || context.MemberResolver.TypeFinder.getClasses(name).any()) { packageName = name; } else { context.addWarning(CompileErrorId.UnresolvedCref, node, element.getAttribute("cref")); element.setAttribute("cref", "!" + element.getAttribute("cref")); return; } } bool found; do { idx = cref.indexOf('.'); if (idx == -1) { name = cref; cref = null; } else { name = cref.substring(0, idx); cref = cref.substring(idx + 1); } found = false; foreach (var s in context.MemberResolver.TypeFinder.getSubPackages(packageName)) { if (s.equals(name)) { packageName = packageName + '/' + name; found = true; break; } } if (!found && !context.MemberResolver.TypeFinder.getClasses(packageName).contains(name)) { context.addWarning(CompileErrorId.UnresolvedCref, node, element.getAttribute("cref")); element.setAttribute("cref", "!" + element.getAttribute("cref")); return; } } while (cref != null && found); var type = context.TypeSystem.getType(packageName + '/' + name); replaceCref(element, exception, type, cref, arguments); } else { replaceCref(element, exception, members, cref, arguments); } } }
private void replaceCref(Element element, bool exception, Iterable<MemberInfo> members, String suffix, String arguments) { if (members.count() > 1 && !members.all(p => p.MemberKind == MemberKind.Method)) { context.addWarning(CompileErrorId.UnresolvedCref, node, element.getAttribute("cref")); element.setAttribute("cref", "!" + element.getAttribute("cref")); return; } var member = members.first(); switch (member.MemberKind) { case Type: replaceCref(element, exception, member.Type, suffix, arguments); break; case Field: if (exception) { context.addWarning(CompileErrorId.ExpectedExceptionInCref, node, element.getAttribute("cref")); element.setAttribute("cref", "!" + element.getAttribute("cref")); return; } if (suffix != null || arguments != null) { context.addWarning(CompileErrorId.UnresolvedCref, node, element.getAttribute("cref")); element.setAttribute("cref", "!" + element.getAttribute("cref")); return; } element.setAttribute("cref", getIdString(member.Field)); break; case Property: if (exception) { context.addWarning(CompileErrorId.ExpectedExceptionInCref, node, element.getAttribute("cref")); element.setAttribute("cref", "!" + element.getAttribute("cref")); return; } if (suffix != null || arguments != null) { context.addWarning(CompileErrorId.UnresolvedCref, node, element.getAttribute("cref")); element.setAttribute("cref", "!" + element.getAttribute("cref")); return; } element.setAttribute("cref", getIdString(member.GetAccessor ?? member.SetAccessor)); break; case Method: if (!exception && suffix == null) { if (arguments == null && members.count() == 1) { element.setAttribute("cref", getIdString(member.Method)); return; } else if (arguments != null && arguments.endsWith(")")) { var args = new ArrayList<TypeInfo>(); if (arguments.length() > 2) { arguments = arguments.substring(1, arguments.length() - 1); int idx; while ((idx = arguments.indexOf(',')) != -1) { var name = arguments.substring(0, idx); arguments = arguments.substring(idx + 1); var type = getType(name); if (type == null) { goto failed; } args.add(type); } if (arguments.length() == 0) { goto failed; } var type = getType(arguments); if (type == null) { goto failed; } args.add(type); } foreach (var m in members) { if (m.Method.Parameters.select(p => p.Type).sequenceEqual(args)) { element.setAttribute("cref", getIdString(m.Method)); return; } } } } failed: context.addWarning(CompileErrorId.UnresolvedCref, node, element.getAttribute("cref")); element.setAttribute("cref", "!" + element.getAttribute("cref")); break; default: break; } }
private void replaceCref(Element element, bool exception) { var cref = element.getAttribute("cref"); if (Helper.isNullOrEmpty(cref)) { context.addWarning(CompileErrorId.MissingDocAttribute, node, "cref", element.getLocalName()); } else { if (cref.length() > 1 && cref[1] == ':') { return; } String arguments = null; int idx = cref.indexOf('('); if (idx != -1) { arguments = cref.substring(idx); cref = cref.substring(0, idx); } idx = cref.indexOf('.'); String name; if (idx == -1) { name = cref; cref = null; } else { name = cref.substring(0, idx); cref = cref.substring(idx + 1); } var members = context.MemberResolver.resolveName(context.CurrentType, name, Query.empty<TypeInfo>()).toList(); if (!members.any()) { if (cref == null) { context.addWarning(CompileErrorId.UnresolvedCref, node, element.getAttribute("cref")); element.setAttribute("cref", "!" + element.getAttribute("cref")); return; } var packageName = context.MemberResolver.getPackageFromAlias(name); if (packageName == null) { if (context.MemberResolver.TypeFinder.getSubPackages(name).any() || context.MemberResolver.TypeFinder.getClasses(name).any()) { packageName = name; } else { context.addWarning(CompileErrorId.UnresolvedCref, node, element.getAttribute("cref")); element.setAttribute("cref", "!" + element.getAttribute("cref")); return; } } bool found; do { idx = cref.indexOf('.'); if (idx == -1) { name = cref; cref = null; } else { name = cref.substring(0, idx); cref = cref.substring(idx + 1); } found = false; foreach (var s in context.MemberResolver.TypeFinder.getSubPackages(packageName)) { if (s.equals(name)) { packageName = packageName + '/' + name; found = true; break; } } if (!found && !context.MemberResolver.TypeFinder.getClasses(packageName).contains(name)) { context.addWarning(CompileErrorId.UnresolvedCref, node, element.getAttribute("cref")); element.setAttribute("cref", "!" + element.getAttribute("cref")); return; } } while (cref != null && found); var type = context.TypeSystem.getType(packageName + '/' + name); replaceCref(element, exception, type, cref, arguments); } else { replaceCref(element, exception, members, cref, arguments); } } }