/** * Returns the . * * @param constructors The constructors. * @param node The node to add the XML to. */ private static XMLNode toConstructorsNode(ConstructorDoc[] constructors) { if (constructors.length < 1) return null; // Create the <constructors> node XMLNode node = new XMLNode("constructors"); // Add the <constructor> nodes for (ConstructorDoc constructor : constructors) { XMLNode c = new XMLNode("constructor"); updateExecutableMemberNode(constructor, c); node.child(c); } return node; }
private String parseIdentifier(Doc doc) { if (doc instanceof ClassDoc) { ClassDoc classDoc = (ClassDoc) doc; return parseIdentifier((Doc) classDoc.containingPackage()) + classDoc.name() + "/"; } else if (doc instanceof AnnotationTypeElementDoc) { AnnotationTypeElementDoc annotationTypeElementDoc = (AnnotationTypeElementDoc) doc; return parseIdentifier((Doc) annotationTypeElementDoc.containingClass()) + "#" + annotationTypeElementDoc.name(); } else if (doc instanceof FieldDoc) { FieldDoc fieldDoc = (FieldDoc) doc; return parseIdentifier((Doc) fieldDoc.containingClass()) + "#" + fieldDoc.name(); } else if (doc instanceof ConstructorDoc) { ConstructorDoc constructorDoc = (ConstructorDoc) doc; return parseIdentifier((Doc) constructorDoc.containingClass()) + "#" + constructorDoc.name() + URLEncoder.encode(constructorDoc.flatSignature()); } else if (doc instanceof MethodDoc) { MethodDoc methodDoc = (MethodDoc) doc; return parseIdentifier((Doc) methodDoc.containingClass()) + "#" + methodDoc.name() + URLEncoder.encode(methodDoc.flatSignature()); } else { return "/" + doc.name() + "/"; } }
/** * Returns the . * * @param constructors The constructors. * @param node The node to add the XML to. */ private static XMLNode toConstructorsNode(ConstructorDoc[] constructors) { if (constructors.length < 1) return null; // Create the <constructors> node XMLNode node = new XMLNode("constructors"); // Add the <constructor> nodes for (ConstructorDoc constructor : constructors) { XMLNode c = new XMLNode("constructor"); updateExecutableMemberNode(constructor, c); // standard block tags c.child(toStandardTags(constructor)); // deprecated toDeprecated(constructor, c); node.child(c); } return node; }
private SignatureInformation constructorInfo(ExecutableElement method) { Optional<ConstructorDoc> doc = docs.constructorDoc(docs.methodKey(method)); Optional<String> docText = doc.flatMap(constructor -> Optional.ofNullable(constructor.commentText())) .map(Javadocs::htmlToMarkdown) .map(Javadocs::firstSentence); return new SignatureInformation( Hovers.methodSignature(method, false, true), docText.orElse(null), paramInfo(method)); }
protected ConstructorDoc[] getSortedConstructors(ClassDoc classDoc) { ConstructorDoc[] result = (ConstructorDoc[])sortedConstructorMap.get(classDoc); if (null == result) { ConstructorDoc[] constructors = classDoc.constructors(); result = (ConstructorDoc[])constructors.clone(); Arrays.sort(result); return result; } return result; }
private boolean hasMethods(ClassDoc clz) { int countExportedMethods = 0; for (ConstructorDoc cd : clz.constructors()) { if (isExportable(cd)) { countExportedMethods++; } } for (MethodDoc md : clz.methods()) { if (isExportable(md)) { countExportedMethods++; } } return countExportedMethods > 0; }
private boolean isExportable(ConstructorDoc cd) { boolean export = isExported(cd.containingClass()); for (AnnotationDesc a : cd.annotations()) { if (a.annotationType().name().equals("Export")) { export = true; } if (a.annotationType().name().equals("NoExport")) { export = false; } } return export; }
/** * @return full JSON objects for the given ConstructorDoc[] */ protected JSONArray processConstructorDocs(ConstructorDoc[] constructorDocs) { JSONArray retMe = new JSONArray(); for (ConstructorDoc constructorDoc: constructorDocs) { retMe.add( processConstructorDoc( constructorDoc ) ); } return retMe; }
/** * @return JSON stubs for the given ConstructorDoc[]. */ protected JSONArray processConstructorDocStubs(ConstructorDoc[] constructorDocs) { JSONArray retMe = new JSONArray(); for (ConstructorDoc constructorDoc: constructorDocs) { retMe.add( processConstructorDocStub( constructorDoc ) ); } return retMe; }
int process(Parser parser, char[] source, int startIndex, int endIndex) throws IOException, ParseException { //ctx.fieldList.add(FieldDocImpl.createFromSource(source, startIndex, endIndex)); //System.out.println("function match '"+new String(source,startIndex,endIndex-startIndex)+"'"); ExecutableMemberDocImpl execDoc=MethodDocImpl.createFromSource(parser.ctx.classDoc, parser.ctx.classDoc.containingPackage(), source, startIndex, endIndex); if (parser.getAddComments()) execDoc.setRawCommentText(parser.getLastComment()); parser.setLastComment(null); if (execDoc.isMethod()) { MethodDoc methDoc = (MethodDoc) execDoc; parser.ctx.methodList.add(methDoc); if (methDoc.isIncluded()) { parser.ctx.filteredMethodList.add(methDoc); } if (methDoc.name().equals("readObject") || methDoc.name().equals("writeObject") || methDoc.name().equals("readExternal") || methDoc.name().equals("writeExternal") || methDoc.name().equals("readResolve")) { // FIXME: add readExternal here? parser.ctx.maybeSerMethodList.add(methDoc); } } else { ConstructorDoc constDoc = (ConstructorDoc) execDoc; parser.ctx.constructorList.add(constDoc); if (constDoc.isIncluded()) { parser.ctx.filteredConstructorList.add(constDoc); } } return endIndex; }
void classClosed() throws ParseException, IOException { ctx.classDoc.setFields(toArray(ctx.fieldList,new FieldDoc[ctx.fieldList.size()])); ctx.classDoc.setFilteredFields(toArray(ctx.filteredFieldList,new FieldDoc[ctx.filteredFieldList.size()])); ctx.classDoc.setSerializableFields(toArray(ctx.sfieldList, new FieldDoc[ctx.sfieldList.size()])); ctx.classDoc.setMethods(toArray(ctx.methodList, new MethodDoc[ctx.methodList.size()])); ctx.classDoc.setFilteredMethods(toArray(ctx.filteredMethodList, new MethodDoc[ctx.filteredMethodList.size()])); ctx.classDoc.setMaybeSerMethodList(ctx.maybeSerMethodList); ctx.classDoc.setConstructors(toArray(ctx.constructorList, new ConstructorDoc[ctx.constructorList.size()])); ctx.classDoc.setFilteredConstructors(toArray(ctx.filteredConstructorList, new ConstructorDoc[ctx.filteredConstructorList.size()])); ctx.classDoc.setInnerClasses(toArray(ctx.innerClassesList, new ClassDocImpl[ctx.innerClassesList.size()])); ctx.classDoc.setFilteredInnerClasses(toArray(ctx.filteredInnerClassesList, new ClassDocImpl[ctx.filteredInnerClassesList.size()])); ctx.classDoc.setBoilerplateComment(boilerplateComment); Main.getRootDoc().addClassDoc(ctx.classDoc); if (Main.DESCEND_INTERFACES) { for (int i=0; i<ctx.classDoc.interfaces().length; ++i) { Main.getRootDoc().scheduleClass(ctx.classDoc, ctx.classDoc.interfaces()[i].qualifiedName()); } } Debug.log(1,"classClosed: "+ctx.classDoc); ctx=(Context)contextStack.pop(); Debug.log(1, "Popping " + ctx); ClassDoc[] referencedClasses=(ClassDoc[])referencedClassesList.toArray(new ClassDoc[0]); if (Main.DESCEND_SUPERCLASS) { for (int i=0; i<referencedClasses.length; ++i) { Main.getRootDoc().scheduleClass(currentClass, referencedClasses[i].qualifiedName()); } } }
public String getSignature(Doc doc) { if (doc instanceof MethodDoc) { return doc.name() + ((MethodDoc) doc).signature(); } else if (doc instanceof FieldDoc) { return doc.name(); } else if (doc instanceof ConstructorDoc) { return doc.name() + ((ConstructorDoc) doc).signature(); } return doc.name(); }
public String getSignature(Doc doc) { if (doc instanceof MethodDoc) { return doc.name() + ((MethodDoc) doc).signature(); } else if (doc instanceof FieldDoc) { return doc.name(); } else if (doc instanceof ConstructorDoc) { return doc.name() + ((ConstructorDoc) doc).signature(); } return ""; }
public ConstructorDoc[] getConstructors() { ClassDoc doc = (ClassDoc) getVariables().get("curitem"); ConstructorDoc[] docs = doc.constructors(false); // constructors are not inherited. // we show private constructors as this is useful info. Arrays.sort(docs); return docs; }
public String getParamString(ConstructorDoc doc) { String str = "("; Parameter[] params = doc.parameters(); str = str + processParams(params); str += ")"; return str; }
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { String methodName = method.getName(); if (target instanceof Doc) { if (methodName.equals("isIncluded")) { Doc doc = (Doc) target; return !exclude(doc) && doc.isIncluded(); } if (target instanceof RootDoc) { if (methodName.equals("classes")) { return filter(((RootDoc) target).classes(), ClassDoc.class); } else if (methodName.equals("specifiedClasses")) { return filter(((RootDoc) target).specifiedClasses(), ClassDoc.class); } else if (methodName.equals("specifiedPackages")) { return filter(((RootDoc) target).specifiedPackages(), PackageDoc.class); } } else if (target instanceof ClassDoc) { if (isFiltered(args)) { if (methodName.equals("methods")) { return filter(((ClassDoc) target).methods(true), MethodDoc.class); } else if (methodName.equals("fields")) { return filter(((ClassDoc) target).fields(true), FieldDoc.class); } else if (methodName.equals("innerClasses")) { return filter(((ClassDoc) target).innerClasses(true), ClassDoc.class); } else if (methodName.equals("constructors")) { return filter(((ClassDoc) target).constructors(true), ConstructorDoc.class); } } } else if (target instanceof PackageDoc) { if (methodName.equals("allClasses")) { if (isFiltered(args)) { return filter(((PackageDoc) target).allClasses(true), ClassDoc.class); } else { return filter(((PackageDoc) target).allClasses(), ClassDoc.class); } } else if (methodName.equals("annotationTypes")) { return filter(((PackageDoc) target).annotationTypes(), AnnotationTypeDoc.class); } else if (methodName.equals("enums")) { return filter(((PackageDoc) target).enums(), ClassDoc.class); } else if (methodName.equals("errors")) { return filter(((PackageDoc) target).errors(), ClassDoc.class); } else if (methodName.equals("exceptions")) { return filter(((PackageDoc) target).exceptions(), ClassDoc.class); } else if (methodName.equals("interfaces")) { return filter(((PackageDoc) target).interfaces(), ClassDoc.class); } else if (methodName.equals("ordinaryClasses")) { return filter(((PackageDoc) target).ordinaryClasses(), ClassDoc.class); } } } if (args != null) { if (methodName.equals("compareTo") || methodName.equals("equals") || methodName.equals("overrides") || methodName.equals("subclassOf")) { args[0] = unwrap(args[0]); } } try { return process(method.invoke(target, args), method.getReturnType()); } catch (InvocationTargetException e) { throw e.getTargetException(); } }
protected Class parseClass(ClassDoc classDoc) { Class classNode = objectFactory.createClass(); classNode.setName(classDoc.name()); classNode.setDisplayName(classDoc.simpleTypeName()); classNode.setIdentifier(parseIdentifier((Doc) classDoc)); classNode.setFull(classDoc.qualifiedName()); classNode.setComment(parseComment(classDoc)); classNode.setAbstract(classDoc.isAbstract()); classNode.setError(classDoc.isError()); classNode.setException(classDoc.isException()); classNode.setExternalizable(classDoc.isExternalizable()); classNode.setSerializable(classDoc.isSerializable()); classNode.setScope(parseScope(classDoc)); for (TypeVariable typeVariable : classDoc.typeParameters()) { classNode.getGeneric().add(parseGeneric(typeVariable)); } Type superClassType = classDoc.superclassType(); if (superClassType != null) { classNode.setClazz(parseTypeInfo(superClassType)); } for (Type interfaceType : classDoc.interfaceTypes()) { classNode.getInterface().add(parseTypeInfo(interfaceType)); } for (MethodDoc method : classDoc.methods()) { classNode.getMethod().add(parseMethod(method)); } for (ConstructorDoc constructor : classDoc.constructors()) { classNode.getConstructor().add(parseConstructor(constructor)); } for (FieldDoc field : classDoc.fields()) { classNode.getField().add(parseField(field)); } Tag[] tags; SeeTag[] seeTags; tags = classDoc.tags("@deprecated"); if (tags.length > 0) { classNode.setDeprecated(parseComment(tags[0])); } tags = classDoc.tags("@since"); if (tags.length > 0) { classNode.setSince(tags[0].text()); } tags = classDoc.tags("@version"); if (tags.length > 0) { classNode.setVersion(tags[0].text()); } tags = classDoc.tags("@author"); for (int i = 0; i < tags.length; i++) { classNode.getAuthor().add(tags[i].text()); } seeTags = classDoc.seeTags(); for (int i = 0; i < seeTags.length; i++) { classNode.getLink().add(parseLink(seeTags[i])); } return classNode; }
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { String methodName = method.getName(); if (target instanceof Doc) { if (methodName.equals("isIncluded")) { Doc doc = (Doc) target; return !exclude(doc) && doc.isIncluded(); } if (target instanceof RootDoc) { if (methodName.equals("classes")) { return filter(((RootDoc) target).classes(), ClassDoc.class); } else if (methodName.equals("specifiedClasses")) { return filter(((RootDoc) target).specifiedClasses(), ClassDoc.class); } else if (methodName.equals("specifiedPackages")) { return filter(((RootDoc) target).specifiedPackages(), PackageDoc.class); } } else if (target instanceof ClassDoc) { if (isFiltered(args)) { if (methodName.equals("methods")) { return filter(((ClassDoc) target).methods(true), MethodDoc.class); } else if (methodName.equals("fields")) { return filter(((ClassDoc) target).fields(true), FieldDoc.class); } else if (methodName.equals("innerClasses")) { return filter(((ClassDoc) target).innerClasses(true), ClassDoc.class); } else if (methodName.equals("constructors")) { return filter(((ClassDoc) target).constructors(true), ConstructorDoc.class); } } else { if (methodName.equals("methods")) { return filter(((ClassDoc) target).methods(true), MethodDoc.class); } } } else if (target instanceof PackageDoc) { if (methodName.equals("allClasses")) { if (isFiltered(args)) { return filter(((PackageDoc) target).allClasses(true), ClassDoc.class); } else { return filter(((PackageDoc) target).allClasses(), ClassDoc.class); } } else if (methodName.equals("annotationTypes")) { return filter(((PackageDoc) target).annotationTypes(), AnnotationTypeDoc.class); } else if (methodName.equals("enums")) { return filter(((PackageDoc) target).enums(), ClassDoc.class); } else if (methodName.equals("errors")) { return filter(((PackageDoc) target).errors(), ClassDoc.class); } else if (methodName.equals("exceptions")) { return filter(((PackageDoc) target).exceptions(), ClassDoc.class); } else if (methodName.equals("interfaces")) { return filter(((PackageDoc) target).interfaces(), ClassDoc.class); } else if (methodName.equals("ordinaryClasses")) { return filter(((PackageDoc) target).ordinaryClasses(), ClassDoc.class); } } } if (args != null) { if (methodName.equals("compareTo") || methodName.equals("equals") || methodName.equals("overrides") || methodName.equals("subclassOf")) { args[0] = unwrap(args[0]); } } try { return process(method.invoke(target, args), method.getReturnType()); } catch (InvocationTargetException e) { throw e.getTargetException(); } }
private void printClass(ClassDoc classDoc, int indent) { String name = classDoc.toString(); indent(indent); ps.print(formatModifiers(classDoc)); ps.print(removePackage(name)); Type superType = classDoc.superclassType(); if (superType != null && !superType.toString().equals("java.lang.Object")) { ps.print(color(" extends ", "blue")); ps.print(formatType(superType.toString())); } Type[] types = classDoc.interfaceTypes(); if (types.length > 0) { ps.print(color(" implements ", "blue")); boolean first = true; for (Type type : types) { if (!first) { ps.print(", "); } first = false; ps.print(formatType(type.toString())); } } ps.println(); for (FieldDoc fieldDoc : (FieldDoc[]) sort(classDoc.fields())) { printField(fieldDoc); } for (ConstructorDoc constructor : (ConstructorDoc[]) sort(classDoc.constructors())) { printMethod(null, constructor, constructor.parameters(), indent + 4); } for (MethodDoc method : (MethodDoc[]) sort(classDoc.methods())) { printMethod(method.returnType().toString(), method, method.parameters(), indent + 4); } for (ClassDoc innerCd : classDoc.innerClasses()) { printClass(innerCd, indent + 4); } }
/** * @return the full JSON for the given ConstructorDoc */ protected JSONObject processConstructorDoc(ConstructorDoc constructorDoc) { return processExecutableMemberDoc(constructorDoc); }
/** * @return a JSON stub for the given ConstructorDoc */ protected JSONObject processConstructorDocStub(ConstructorDoc constructorDoc) { return processExecutableMemberDocStub(constructorDoc); }
public String getDirectLink(ConstructorDoc doc) { return getDirectLink(getAnchorName(doc)); }
public String getAnchorName(ConstructorDoc doc) { return getSignature(doc); }
public boolean hasDeclaredThrows(ConstructorDoc doc) { return getDeclaredThrows(doc).size() > 0; }
public Vector getDeclaredThrows(ConstructorDoc doc) { ClassDoc[] exceptions = doc.thrownExceptions(); return getDeclaredThrows(exceptions); }
public ConstructorDoc[] constructors() { return new ConstructorDoc[0]; }
public ConstructorDoc[] constructors(boolean filtered) { return new ConstructorDoc[0]; }