/** * Given a class, return the closest visible super class. * * @param classDoc the class we are searching the parent for. * @param configuration the current configuration of the doclet. * @return the closest visible super class. Return null if it cannot be found (i.e. classDoc is * java.lang.Object). */ public static Type getFirstVisibleSuperClass(ClassDoc classDoc, Configuration configuration) { if (classDoc == null) { return null; } Type sup = classDoc.superclassType(); ClassDoc supClassDoc = classDoc.superclass(); while (sup != null && (!(supClassDoc.isPublic() || isLinkable(supClassDoc, configuration)))) { if (supClassDoc.superclass().qualifiedName().equals(supClassDoc.qualifiedName())) break; sup = supClassDoc.superclassType(); supClassDoc = supClassDoc.superclass(); } if (classDoc.equals(supClassDoc)) { return null; } return sup; }
private static void findAllInterfaceTypes( Map results, ClassDoc c, boolean raw, Configuration configuration) { Type superType = c.superclassType(); if (superType == null) return; addAllInterfaceTypes( results, superType, superType instanceof ClassDoc ? ((ClassDoc) superType).interfaceTypes() : ((ParameterizedType) superType).interfaceTypes(), raw, configuration); }
private Type[] getInterfaceTypeArguments(ClassDoc iface, Type t) { if (t instanceof ParameterizedType) { ParameterizedType pt = (ParameterizedType) t; if (iface != null && iface.equals(t.asClassDoc())) { return pt.typeArguments(); } else { for (Type pti : pt.interfaceTypes()) { Type[] result = getInterfaceTypeArguments(iface, pti); if (result != null) return result; } if (pt.superclassType() != null) return getInterfaceTypeArguments(iface, pt.superclassType()); } } else if (t instanceof ClassDoc) { ClassDoc cd = (ClassDoc) t; for (Type pti : cd.interfaceTypes()) { Type[] result = getInterfaceTypeArguments(iface, pti); if (result != null) return result; } if (cd.superclassType() != null) return getInterfaceTypeArguments(iface, cd.superclassType()); } return null; }
public static Type findSuperTypeFromClass(final ClassDoc klass, String typeName) { if (klass.qualifiedTypeName().equals(typeName)) return klass; // find it in the interfaces final Type foundType = findSuperTypeFromInterface(klass, typeName); if (foundType != null) { return foundType; } final Type superclass = klass.superclassType(); if (superclass != null && superclass.asClassDoc() != null) { return findSuperTypeFromClass(superclass.asClassDoc(), typeName); } return null; }
public static ClassDoc findAnnotatedClass( final ClassDoc klass, final Class<?>... soughtAnnotations) { if (!klass.isClass() || isExcluded(klass)) return null; if (hasAnnotation(klass, soughtAnnotations)) { return klass; } // find it in the interfaces final ClassDoc foundClassDoc = findAnnotatedInterface(klass, soughtAnnotations); if (foundClassDoc != null) { return foundClassDoc; } final Type superclass = klass.superclassType(); if (superclass != null && superclass.asClassDoc() != null) { return findAnnotatedClass(superclass.asClassDoc(), soughtAnnotations); } return null; }
/** * Parses the enum type definition * * @param docClass * @return */ protected static Enum ParseEnum(ClassDoc docClass) { assert (docClass != null); Enum xmlEnum = new Enum(); xmlEnum.name = docClass.name(); xmlEnum.qualifiedName = docClass.qualifiedName(); xmlEnum.comment = docClass.commentText(); xmlEnum.isIncluded = docClass.isIncluded(); xmlEnum.scope = DetermineScope(docClass); Type superClassType = docClass.superclassType(); if (superClassType != null) { xmlEnum.superClass = superClassType.qualifiedTypeName(); } Type[] interfaces = docClass.interfaceTypes(); ArrayList<String> interfaceTypeNames = new ArrayList<String>(); if (interfaces != null && interfaces.length > 0) { for (Type interfaceType : interfaces) { interfaceTypeNames.add(interfaceType.qualifiedTypeName()); } } xmlEnum.extendedFrom = interfaceTypeNames.toArray(new String[] {}); FieldDoc[] fields = docClass.enumConstants(); if (fields != null && fields.length > 0) { ArrayList<EnumField> fieldList = new ArrayList<EnumField>(); for (FieldDoc field : fields) { fieldList.add(ParseEnumField(field)); } xmlEnum.fields = fieldList.toArray(new EnumField[] {}); } xmlEnum.annotationInstances = ParseAnnotationInstances(docClass.annotations(), docClass.qualifiedName()); return xmlEnum; }
/** * Return true if the given ClassDoc should be included in the serialized form. * * @param cd the ClassDoc object to check for serializability. */ private static boolean serialClassInclude(ClassDoc cd) { if (cd.isEnum()) { return false; } try { cd.superclassType(); } catch (NullPointerException e) { // Workaround for null pointer bug in ClassDoc.superclassType(). return false; } if (cd.isSerializable()) { if (cd.tags("serial").length > 0) { return serialDocInclude(cd); } else if (cd.isPublic() || cd.isProtected()) { return true; } else { return false; } } return false; }
/** * Parses the data for a class type definition * * @param docClass * @return */ protected static Class ParseClass(ClassDoc docClass) { assert (docClass != null); Class xmlClass = new Class(); // illegal use of this class. assert (xmlClass != null); xmlClass.name = docClass.name(); xmlClass.qualifiedName = docClass.qualifiedName(); xmlClass.isSerializable = docClass.isSerializable(); xmlClass.isExternalizable = docClass.isExternalizable(); xmlClass.isAbstract = docClass.isAbstract(); xmlClass.isException = docClass.isException(); xmlClass.isError = docClass.isError(); xmlClass.comment = docClass.commentText(); xmlClass.scope = DetermineScope(docClass); xmlClass.isIncluded = docClass.isIncluded(); xmlClass.typeVariables = ParseTypeVariables(docClass.typeParameters(), docClass.typeParamTags()); Type superClassType = docClass.superclassType(); if (superClassType != null) { xmlClass.superClass = ParseType(superClassType); } Type[] interfaces = docClass.interfaceTypes(); ArrayList<TypeInfo> interfaceTypeNames = new ArrayList<TypeInfo>(); if (interfaces != null && interfaces.length > 0) { for (Type interfaceType : interfaces) { interfaceTypeNames.add(ParseType(interfaceType)); } xmlClass.interfaces = interfaceTypeNames.toArray(new TypeInfo[] {}); } ConstructorDoc[] constructors = docClass.constructors(); if (constructors != null && constructors.length > 0) { ArrayList<Constructor> constructorList = new ArrayList<Constructor>(); for (ConstructorDoc constructor : constructors) { constructorList.add(ParseConstructor(constructor)); } xmlClass.constructors = constructorList.toArray(new Constructor[] {}); } else { log.debug("No constructors in class: " + docClass.name()); } MethodDoc[] methods = docClass.methods(); if (methods != null && methods.length > 0) { ArrayList<Method> methodList = new ArrayList<Method>(); for (MethodDoc method : methods) { methodList.add(ParseMethod(method)); } xmlClass.methods = methodList.toArray(new Method[] {}); } else { log.debug("No methods in class: " + docClass.name()); } FieldDoc[] fields = docClass.fields(); if (fields != null && fields.length > 0) { ArrayList<Field> fieldList = new ArrayList<Field>(); for (FieldDoc field : fields) { fieldList.add(ParseField(field)); } xmlClass.fields = fieldList.toArray(new Field[] {}); } xmlClass.annotationInstances = ParseAnnotationInstances(docClass.annotations(), docClass.qualifiedName()); return xmlClass; }
/** Print a class's relations */ public void printRelations(ClassDoc c) { Options opt = optionProvider.getOptionsFor(c); if (hidden(c) || c.name() .equals("")) // avoid phantom classes, they may pop up when the source uses annotations return; String className = c.toString(); // Print generalization (through the Java superclass) Type s = c.superclassType(); if (s != null && !s.toString().equals("java.lang.Object") && !c.isEnum() && !hidden(s.asClassDoc())) { ClassDoc sc = s.asClassDoc(); w.println( "\t//" + c + " extends " + s + "\n" + "\t" + relationNode(sc) + " -> " + relationNode(c) + " [dir=back,arrowtail=empty];"); getClassInfo(className) .addRelation(sc.toString(), RelationType.EXTENDS, RelationDirection.OUT); getClassInfo(sc.toString()) .addRelation(className, RelationType.EXTENDS, RelationDirection.IN); } // Print generalizations (through @extends tags) for (Tag tag : c.tags("extends")) if (!hidden(tag.text())) { ClassDoc from = c.findClass(tag.text()); w.println( "\t//" + c + " extends " + tag.text() + "\n" + "\t" + relationNode(from, tag.text()) + " -> " + relationNode(c) + " [dir=back,arrowtail=empty];"); getClassInfo(className) .addRelation(tag.text(), RelationType.EXTENDS, RelationDirection.OUT); getClassInfo(tag.text()).addRelation(className, RelationType.EXTENDS, RelationDirection.IN); } // Print realizations (Java interfaces) for (Type iface : c.interfaceTypes()) { ClassDoc ic = iface.asClassDoc(); if (!hidden(ic)) { w.println( "\t//" + c + " implements " + ic + "\n\t" + relationNode(ic) + " -> " + relationNode(c) + " [dir=back,arrowtail=empty,style=dashed];"); getClassInfo(className) .addRelation(ic.toString(), RelationType.IMPLEMENTS, RelationDirection.OUT); getClassInfo(ic.toString()) .addRelation(className, RelationType.IMPLEMENTS, RelationDirection.IN); } } // Print other associations allRelation(opt, RelationType.ASSOC, c); allRelation(opt, RelationType.NAVASSOC, c); allRelation(opt, RelationType.HAS, c); allRelation(opt, RelationType.NAVHAS, c); allRelation(opt, RelationType.COMPOSED, c); allRelation(opt, RelationType.NAVCOMPOSED, c); allRelation(opt, RelationType.DEPEND, c); }