2 * Copyright (C) 2008 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 import com.sun.javadoc.*;
18 import com.sun.tools.doclets.*;
19 import org.clearsilver.HDF;
20 import org.clearsilver.CS;
24 public class ClassInfo extends DocInfo implements ContainerInfo, Comparable, Scoped
26 public static final Comparator<ClassInfo> comparator = new Comparator<ClassInfo>() {
27 public int compare(ClassInfo a, ClassInfo b) {
28 return a.name().compareTo(b.name());
32 public static final Comparator<ClassInfo> qualifiedComparator = new Comparator<ClassInfo>() {
33 public int compare(ClassInfo a, ClassInfo b) {
34 return a.qualifiedName().compareTo(b.qualifiedName());
40 String rawCommentText, SourcePositionInfo position,
41 boolean isPublic, boolean isProtected, boolean isPackagePrivate,
42 boolean isPrivate, boolean isStatic,
43 boolean isInterface, boolean isAbstract, boolean isOrdinaryClass,
44 boolean isException, boolean isError, boolean isEnum, boolean isAnnotation,
45 boolean isFinal, boolean isIncluded, String name,
46 String qualifiedName, String qualifiedTypeName, boolean isPrimitive)
48 super(rawCommentText, position);
52 mIsProtected = isProtected;
53 mIsPackagePrivate = isPackagePrivate;
54 mIsPrivate = isPrivate;
56 mIsInterface = isInterface;
57 mIsAbstract = isAbstract;
58 mIsOrdinaryClass = isOrdinaryClass;
59 mIsException = isException;
62 mIsAnnotation = isAnnotation;
64 mIsIncluded = isIncluded;
66 mQualifiedName = qualifiedName;
67 mQualifiedTypeName = qualifiedTypeName;
68 mIsPrimitive = isPrimitive;
69 mNameParts = name.split("\\.");
72 public void init(TypeInfo typeInfo, ClassInfo[] interfaces, TypeInfo[] interfaceTypes,
73 ClassInfo[] innerClasses,
74 MethodInfo[] constructors, MethodInfo[] methods, MethodInfo[] annotationElements,
75 FieldInfo[] fields, FieldInfo[] enumConstants,
76 PackageInfo containingPackage, ClassInfo containingClass,
77 ClassInfo superclass, TypeInfo superclassType, AnnotationInstanceInfo[] annotations)
80 mRealInterfaces = interfaces;
81 mRealInterfaceTypes = interfaceTypes;
82 mInnerClasses = innerClasses;
83 mAllConstructors = constructors;
84 mAllSelfMethods = methods;
85 mAnnotationElements = annotationElements;
86 mAllSelfFields = fields;
87 mEnumConstants = enumConstants;
88 mContainingPackage = containingPackage;
89 mContainingClass = containingClass;
90 mRealSuperclass = superclass;
91 mRealSuperclassType = superclassType;
92 mAnnotations = annotations;
94 // after providing new methods and new superclass info,clear any cached
95 // lists of self + superclass methods, ctors, etc.
96 mSuperclassInit = false;
102 mSelfAttributes = null;
103 mDeprecatedKnown = false;
105 Arrays.sort(mEnumConstants, FieldInfo.comparator);
106 Arrays.sort(mInnerClasses, ClassInfo.comparator);
109 public void init2() {
110 // calling this here forces the AttrTagInfo objects to be linked to the AttribtueInfo
115 public void init3(TypeInfo[] types, ClassInfo[] realInnerClasses){
116 mTypeParameters = types;
117 mRealInnerClasses = realInnerClasses;
120 public ClassInfo[] getRealInnerClasses(){
121 return mRealInnerClasses;
124 public TypeInfo[] getTypeParameters(){
125 return mTypeParameters;
128 public boolean checkLevel()
130 int val = mCheckLevel;
134 boolean v = DroidDoc.checkLevel(mIsPublic, mIsProtected,
135 mIsPackagePrivate, mIsPrivate, isHidden());
136 mCheckLevel = v ? 1 : 0;
141 public int compareTo(Object that) {
142 if (that instanceof ClassInfo) {
143 return mQualifiedName.compareTo(((ClassInfo)that).mQualifiedName);
145 return this.hashCode() - that.hashCode();
149 public ContainerInfo parent()
154 public boolean isPublic()
159 public boolean isProtected()
164 public boolean isPackagePrivate()
166 return mIsPackagePrivate;
169 public boolean isPrivate()
174 public boolean isStatic()
179 public boolean isInterface()
184 public boolean isAbstract()
189 public PackageInfo containingPackage()
191 return mContainingPackage;
194 public ClassInfo containingClass()
196 return mContainingClass;
199 public boolean isOrdinaryClass()
201 return mIsOrdinaryClass;
204 public boolean isException()
209 public boolean isError()
214 public boolean isEnum()
219 public boolean isAnnotation()
221 return mIsAnnotation;
224 public boolean isFinal()
229 public boolean isIncluded()
234 public HashSet<String> typeVariables()
236 HashSet<String> result = TypeInfo.typeVariables(mTypeInfo.typeArguments());
237 ClassInfo cl = containingClass();
239 TypeInfo[] types = cl.asTypeInfo().typeArguments();
241 TypeInfo.typeVariables(types, result);
243 cl = cl.containingClass();
248 private static void gatherHiddenInterfaces(ClassInfo cl, HashSet<ClassInfo> interfaces) {
249 for (ClassInfo iface: cl.mRealInterfaces) {
250 if (iface.checkLevel()) {
251 interfaces.add(iface);
253 gatherHiddenInterfaces(iface, interfaces);
258 public ClassInfo[] interfaces()
260 if (mInterfaces == null) {
262 HashSet<ClassInfo> interfaces = new HashSet<ClassInfo>();
263 ClassInfo superclass = mRealSuperclass;
264 while (superclass != null && !superclass.checkLevel()) {
265 gatherHiddenInterfaces(superclass, interfaces);
266 superclass = superclass.mRealSuperclass;
268 gatherHiddenInterfaces(this, interfaces);
269 mInterfaces = interfaces.toArray(new ClassInfo[interfaces.size()]);
271 // put something here in case someone uses it
272 mInterfaces = mRealInterfaces;
274 Arrays.sort(mInterfaces, ClassInfo.qualifiedComparator);
279 public ClassInfo[] realInterfaces()
281 return mRealInterfaces;
284 TypeInfo[] realInterfaceTypes()
286 return mRealInterfaceTypes;
294 public String[] nameParts()
299 public String leafName()
301 return mNameParts[mNameParts.length-1];
304 public String qualifiedName()
306 return mQualifiedName;
309 public String qualifiedTypeName()
311 return mQualifiedTypeName;
314 public boolean isPrimitive()
319 public MethodInfo[] allConstructors() {
320 return mAllConstructors;
323 public MethodInfo[] constructors()
325 if (mConstructors == null) {
326 MethodInfo[] methods = mAllConstructors;
327 ArrayList<MethodInfo> ctors = new ArrayList<MethodInfo>();
328 for (int i=0; i<methods.length; i++) {
329 MethodInfo m = methods[i];
334 mConstructors = ctors.toArray(new MethodInfo[ctors.size()]);
335 Arrays.sort(mConstructors, MethodInfo.comparator);
337 return mConstructors;
340 public ClassInfo[] innerClasses()
342 return mInnerClasses;
345 public TagInfo[] inlineTags()
347 return comment().tags();
350 public TagInfo[] firstSentenceTags()
352 return comment().briefTags();
355 public boolean isDeprecated() {
356 boolean deprecated = false;
357 if (!mDeprecatedKnown) {
358 boolean commentDeprecated = (comment().deprecatedTags().length > 0);
359 boolean annotationDeprecated = false;
360 for (AnnotationInstanceInfo annotation : annotations()) {
361 if (annotation.type().qualifiedName().equals("java.lang.Deprecated")) {
362 annotationDeprecated = true;
367 if (commentDeprecated != annotationDeprecated) {
368 Errors.error(Errors.DEPRECATION_MISMATCH, position(),
369 "Class " + qualifiedName()
370 + ": @Deprecated annotation and @deprecated comment do not match");
373 mIsDeprecated = commentDeprecated | annotationDeprecated;
374 mDeprecatedKnown = true;
376 return mIsDeprecated;
379 public TagInfo[] deprecatedTags()
381 // Should we also do the interfaces?
382 return comment().deprecatedTags();
385 public MethodInfo[] methods()
387 if (mMethods == null) {
388 TreeMap<String,MethodInfo> all = new TreeMap<String,MethodInfo>();
390 ClassInfo[] ifaces = interfaces();
391 for (ClassInfo iface: ifaces) {
393 MethodInfo[] inhereted = iface.methods();
394 for (MethodInfo method: inhereted) {
395 String key = method.name() + method.signature();
396 all.put(key, method);
401 ClassInfo superclass = superclass();
402 if (superclass != null) {
403 MethodInfo[] inhereted = superclass.methods();
404 for (MethodInfo method: inhereted) {
405 String key = method.name() + method.signature();
406 all.put(key, method);
410 MethodInfo[] methods = selfMethods();
411 for (MethodInfo method: methods) {
412 String key = method.name() + method.signature();
413 MethodInfo old = all.put(key, method);
416 mMethods = all.values().toArray(new MethodInfo[all.size()]);
421 public MethodInfo[] annotationElements()
423 return mAnnotationElements;
426 public AnnotationInstanceInfo[] annotations()
431 private static void addFields(ClassInfo cl, TreeMap<String,FieldInfo> all)
433 FieldInfo[] fields = cl.fields();
434 int N = fields.length;
435 for (int i=0; i<N; i++) {
436 FieldInfo f = fields[i];
437 all.put(f.name(), f);
441 public FieldInfo[] fields()
443 if (mFields == null) {
445 TreeMap<String,FieldInfo> all = new TreeMap<String,FieldInfo>();
447 ClassInfo[] interfaces = interfaces();
448 N = interfaces.length;
449 for (int i=0; i<N; i++) {
450 addFields(interfaces[i], all);
453 ClassInfo superclass = superclass();
454 if (superclass != null) {
455 addFields(superclass, all);
458 FieldInfo[] fields = selfFields();
460 for (int i=0; i<N; i++) {
461 FieldInfo f = fields[i];
463 String key = f.name();
468 mFields = all.values().toArray(new FieldInfo[0]);
473 public void gatherFields(ClassInfo owner, ClassInfo cl, HashMap<String,FieldInfo> fields) {
474 FieldInfo[] flds = cl.selfFields();
475 for (FieldInfo f: flds) {
476 if (f.checkLevel()) {
477 fields.put(f.name(), f.cloneForClass(owner));
482 public FieldInfo[] selfFields()
484 if (mSelfFields == null) {
485 HashMap<String,FieldInfo> fields = new HashMap<String,FieldInfo>();
486 // our hidden parents
487 if (mRealSuperclass != null && !mRealSuperclass.checkLevel()) {
488 gatherFields(this, mRealSuperclass, fields);
490 for (ClassInfo iface: mRealInterfaces) {
491 if (!iface.checkLevel()) {
492 gatherFields(this, iface, fields);
496 FieldInfo[] selfFields = mAllSelfFields;
497 for (int i=0; i<selfFields.length; i++) {
498 FieldInfo f = selfFields[i];
500 fields.put(f.name(), f);
503 // combine and return in
504 mSelfFields = fields.values().toArray(new FieldInfo[fields.size()]);
505 Arrays.sort(mSelfFields, FieldInfo.comparator);
510 public FieldInfo[] allSelfFields() {
511 return mAllSelfFields;
514 public void gatherMethods(ClassInfo owner, ClassInfo cl, HashMap<String,MethodInfo> methods) {
515 MethodInfo[] meth = cl.selfMethods();
516 for (MethodInfo m: meth) {
517 if (m.checkLevel()) {
518 methods.put(m.name()+m.signature(), m.cloneForClass(owner));
523 public MethodInfo[] selfMethods()
525 if (mSelfMethods == null) {
526 HashMap<String,MethodInfo> methods = new HashMap<String,MethodInfo>();
527 // our hidden parents
528 if (mRealSuperclass != null && !mRealSuperclass.checkLevel()) {
529 gatherMethods(this, mRealSuperclass, methods);
531 for (ClassInfo iface: mRealInterfaces) {
532 if (!iface.checkLevel()) {
533 gatherMethods(this, iface, methods);
537 MethodInfo[] selfMethods = mAllSelfMethods;
538 for (int i=0; i<selfMethods.length; i++) {
539 MethodInfo m = selfMethods[i];
540 if (m.checkLevel()) {
541 methods.put(m.name()+m.signature(), m);
544 // combine and return it
545 mSelfMethods = methods.values().toArray(new MethodInfo[methods.size()]);
546 Arrays.sort(mSelfMethods, MethodInfo.comparator);
551 public MethodInfo[] allSelfMethods() {
552 return mAllSelfMethods;
555 public void addMethod(MethodInfo method) {
556 MethodInfo[] methods = new MethodInfo[mAllSelfMethods.length + 1];
558 for (MethodInfo m : mAllSelfMethods) {
563 mAllSelfMethods = methods;
566 public AttributeInfo[] selfAttributes()
568 if (mSelfAttributes == null) {
569 TreeMap<FieldInfo,AttributeInfo> attrs = new TreeMap<FieldInfo,AttributeInfo>();
571 // the ones in the class comment won't have any methods
572 for (AttrTagInfo tag: comment().attrTags()) {
573 FieldInfo field = tag.reference();
575 AttributeInfo attr = attrs.get(field);
577 attr = new AttributeInfo(this, field);
578 attrs.put(field, attr);
580 tag.setAttribute(attr);
585 for (MethodInfo m: selfMethods()) {
586 for (AttrTagInfo tag: m.comment().attrTags()) {
587 FieldInfo field = tag.reference();
589 AttributeInfo attr = attrs.get(field);
591 attr = new AttributeInfo(this, field);
592 attrs.put(field, attr);
594 tag.setAttribute(attr);
601 for (MethodInfo m: constructors()) {
602 for (AttrTagInfo tag: m.comment().attrTags()) {
603 FieldInfo field = tag.reference();
605 AttributeInfo attr = attrs.get(field);
607 attr = new AttributeInfo(this, field);
608 attrs.put(field, attr);
610 tag.setAttribute(attr);
616 mSelfAttributes = attrs.values().toArray(new AttributeInfo[attrs.size()]);
617 Arrays.sort(mSelfAttributes, AttributeInfo.comparator);
619 return mSelfAttributes;
622 public FieldInfo[] enumConstants()
624 return mEnumConstants;
627 public ClassInfo superclass()
629 if (!mSuperclassInit) {
630 if (this.checkLevel()) {
631 // rearrange our little inheritance hierarchy, because we need to hide classes that
632 // don't pass checkLevel
633 ClassInfo superclass = mRealSuperclass;
634 while (superclass != null && !superclass.checkLevel()) {
635 superclass = superclass.mRealSuperclass;
637 mSuperclass = superclass;
639 mSuperclass = mRealSuperclass;
645 public ClassInfo realSuperclass()
647 return mRealSuperclass;
650 /** always the real superclass, not the collapsed one we get through superclass(),
651 * also has the type parameter info if it's generic.
653 public TypeInfo superclassType()
655 return mRealSuperclassType;
658 public TypeInfo asTypeInfo()
663 TypeInfo[] interfaceTypes()
665 ClassInfo[] infos = interfaces();
666 int len = infos.length;
667 TypeInfo[] types = new TypeInfo[len];
668 for (int i=0; i<len; i++) {
669 types[i] = infos[i].asTypeInfo();
674 public String htmlPage()
676 String s = containingPackage().name();
677 s = s.replace('.', '/');
681 s = DroidDoc.javadocDir + s;
685 /** Even indirectly */
686 public boolean isDerivedFrom(ClassInfo cl)
688 ClassInfo dad = this.superclass();
690 if (dad.equals(cl)) {
693 if (dad.isDerivedFrom(cl)) {
698 for (ClassInfo iface: interfaces()) {
699 if (iface.equals(cl)) {
702 if (iface.isDerivedFrom(cl)) {
710 public void makeKeywordEntries(List<KeywordEntry> keywords)
716 String htmlPage = htmlPage();
717 String qualifiedName = qualifiedName();
719 keywords.add(new KeywordEntry(name(), htmlPage,
720 "class in " + containingPackage().name()));
722 FieldInfo[] fields = selfFields();
723 FieldInfo[] enumConstants = enumConstants();
724 MethodInfo[] ctors = constructors();
725 MethodInfo[] methods = selfMethods();
728 for (FieldInfo field: enumConstants()) {
729 if (field.checkLevel()) {
730 keywords.add(new KeywordEntry(field.name(),
731 htmlPage + "#" + field.anchor(),
732 "enum constant in " + qualifiedName));
737 for (FieldInfo field: fields) {
738 if (field.isConstant() && field.checkLevel()) {
739 keywords.add(new KeywordEntry(field.name(),
740 htmlPage + "#" + field.anchor(),
741 "constant in " + qualifiedName));
746 for (FieldInfo field: fields) {
747 if (!field.isConstant() && field.checkLevel()) {
748 keywords.add(new KeywordEntry(field.name(),
749 htmlPage + "#" + field.anchor(),
750 "field in " + qualifiedName));
754 // public constructors
755 for (MethodInfo m: ctors) {
756 if (m.isPublic() && m.checkLevel()) {
757 keywords.add(new KeywordEntry(m.name() + m.prettySignature(),
758 htmlPage + "#" + m.anchor(),
759 "constructor in " + qualifiedName));
763 // protected constructors
764 if (DroidDoc.checkLevel(DroidDoc.SHOW_PROTECTED)) {
765 for (MethodInfo m: ctors) {
766 if (m.isProtected() && m.checkLevel()) {
767 keywords.add(new KeywordEntry(m.name() + m.prettySignature(),
768 htmlPage + "#" + m.anchor(),
769 "constructor in " + qualifiedName));
774 // package private constructors
775 if (DroidDoc.checkLevel(DroidDoc.SHOW_PACKAGE)) {
776 for (MethodInfo m: ctors) {
777 if (m.isPackagePrivate() && m.checkLevel()) {
778 keywords.add(new KeywordEntry(m.name() + m.prettySignature(),
779 htmlPage + "#" + m.anchor(),
780 "constructor in " + qualifiedName));
785 // private constructors
786 if (DroidDoc.checkLevel(DroidDoc.SHOW_PRIVATE)) {
787 for (MethodInfo m: ctors) {
788 if (m.isPrivate() && m.checkLevel()) {
789 keywords.add(new KeywordEntry(m.name() + m.prettySignature(),
790 htmlPage + "#" + m.anchor(),
791 "constructor in " + qualifiedName));
797 for (MethodInfo m: methods) {
798 if (m.isPublic() && m.checkLevel()) {
799 keywords.add(new KeywordEntry(m.name() + m.prettySignature(),
800 htmlPage + "#" + m.anchor(),
801 "method in " + qualifiedName));
806 if (DroidDoc.checkLevel(DroidDoc.SHOW_PROTECTED)) {
807 for (MethodInfo m: methods) {
808 if (m.isProtected() && m.checkLevel()) {
809 keywords.add(new KeywordEntry(m.name() + m.prettySignature(),
810 htmlPage + "#" + m.anchor(),
811 "method in " + qualifiedName));
816 // package private methods
817 if (DroidDoc.checkLevel(DroidDoc.SHOW_PACKAGE)) {
818 for (MethodInfo m: methods) {
819 if (m.isPackagePrivate() && m.checkLevel()) {
820 keywords.add(new KeywordEntry(m.name() + m.prettySignature(),
821 htmlPage + "#" + m.anchor(),
822 "method in " + qualifiedName));
828 if (DroidDoc.checkLevel(DroidDoc.SHOW_PRIVATE)) {
829 for (MethodInfo m: methods) {
830 if (m.isPrivate() && m.checkLevel()) {
831 keywords.add(new KeywordEntry(m.name() + m.prettySignature(),
832 htmlPage + "#" + m.anchor(),
833 "method in " + qualifiedName));
839 public void makeLink(HDF data, String base)
841 data.setValue(base + ".label", this.name());
842 if (!this.isPrimitive() && this.isIncluded() && this.checkLevel()) {
843 data.setValue(base + ".link", this.htmlPage());
847 public static void makeLinkListHDF(HDF data, String base, ClassInfo[] classes) {
848 final int N = classes.length;
849 for (int i=0; i<N; i++) {
850 ClassInfo cl = classes[i];
851 if (cl.checkLevel()) {
852 cl.asTypeInfo().makeHDF(data, base + "." + i);
858 * Used in lists of this class (packages, nested classes, known subclasses)
860 public void makeShortDescrHDF(HDF data, String base)
862 mTypeInfo.makeHDF(data, base + ".type");
863 data.setValue(base + ".kind", this.kind());
864 TagInfo.makeHDF(data, base + ".shortDescr", this.firstSentenceTags());
865 TagInfo.makeHDF(data, base + ".deprecated", deprecatedTags());
869 * Turns into the main class page
871 public void makeHDF(HDF data)
874 String name = name();
875 String qualified = qualifiedName();
876 AttributeInfo[] selfAttributes = selfAttributes();
877 MethodInfo[] methods = selfMethods();
878 FieldInfo[] fields = selfFields();
879 FieldInfo[] enumConstants = enumConstants();
880 MethodInfo[] ctors = constructors();
881 ClassInfo[] inners = innerClasses();
884 mTypeInfo.makeHDF(data, "class.type");
885 mTypeInfo.makeQualifiedHDF(data, "class.qualifiedType");
886 data.setValue("class.name", name);
887 data.setValue("class.qualified", qualified);
890 data.setValue("class.scope", "protected");
892 else if (isPublic()) {
893 data.setValue("class.scope", "public");
896 data.setValue("class.static", "static");
899 data.setValue("class.final", "final");
901 if (isAbstract() && !isInterface()) {
902 data.setValue("class.abstract", "abstract");
906 String kind = kind();
908 data.setValue("class.kind", kind);
910 data.setValue("class.since", getSince());
912 // the containing package -- note that this can be passed to type_link,
913 // but it also contains the list of all of the packages
914 containingPackage().makeClassLinkListHDF(data, "class.package");
916 // inheritance hierarchy
917 Vector<ClassInfo> superClasses = new Vector<ClassInfo>();
918 superClasses.add(this);
919 ClassInfo supr = superclass();
920 while (supr != null) {
921 superClasses.add(supr);
922 supr = supr.superclass();
924 n = superClasses.size();
925 for (i=0; i<n; i++) {
926 supr = superClasses.elementAt(n-i-1);
928 supr.asTypeInfo().makeQualifiedHDF(data, "class.inheritance." + i + ".class");
929 supr.asTypeInfo().makeHDF(data, "class.inheritance." + i + ".short_class");
931 for (TypeInfo t: supr.interfaceTypes()) {
932 t.makeHDF(data, "class.inheritance." + i + ".interfaces." + j);
938 TagInfo.makeHDF(data, "class.descr", inlineTags());
939 TagInfo.makeHDF(data, "class.seeAlso", comment().seeTags());
940 TagInfo.makeHDF(data, "class.deprecated", deprecatedTags());
943 TreeMap<String, ClassInfo> direct = new TreeMap<String, ClassInfo>();
944 TreeMap<String, ClassInfo> indirect = new TreeMap<String, ClassInfo>();
945 ClassInfo[] all = Converter.rootClasses();
946 for (ClassInfo cl: all) {
947 if (cl.superclass() != null && cl.superclass().equals(this)) {
948 direct.put(cl.name(), cl);
950 else if (cl.isDerivedFrom(this)) {
951 indirect.put(cl.name(), cl);
956 for (ClassInfo cl: direct.values()) {
957 if (cl.checkLevel()) {
958 cl.makeShortDescrHDF(data, "class.subclasses.direct." + i);
964 for (ClassInfo cl: indirect.values()) {
965 if (cl.checkLevel()) {
966 cl.makeShortDescrHDF(data, "class.subclasses.indirect." + i);
973 for (ClassInfo inner: inners) {
974 if (inner.checkLevel()) {
975 inner.makeShortDescrHDF(data, "class.inners." + i);
982 for (FieldInfo field: enumConstants) {
983 if (field.isConstant()) {
984 field.makeHDF(data, "class.enumConstants." + i);
991 for (FieldInfo field: fields) {
992 if (field.isConstant()) {
993 field.makeHDF(data, "class.constants." + i);
1000 for (FieldInfo field: fields) {
1001 if (!field.isConstant()) {
1002 field.makeHDF(data, "class.fields." + i);
1007 // public constructors
1009 for (MethodInfo ctor: ctors) {
1010 if (ctor.isPublic()) {
1011 ctor.makeHDF(data, "class.ctors.public." + i);
1016 // protected constructors
1017 if (DroidDoc.checkLevel(DroidDoc.SHOW_PROTECTED)) {
1019 for (MethodInfo ctor: ctors) {
1020 if (ctor.isProtected()) {
1021 ctor.makeHDF(data, "class.ctors.protected." + i);
1027 // package private constructors
1028 if (DroidDoc.checkLevel(DroidDoc.SHOW_PACKAGE)) {
1030 for (MethodInfo ctor: ctors) {
1031 if (ctor.isPackagePrivate()) {
1032 ctor.makeHDF(data, "class.ctors.package." + i);
1038 // private constructors
1039 if (DroidDoc.checkLevel(DroidDoc.SHOW_PRIVATE)) {
1041 for (MethodInfo ctor: ctors) {
1042 if (ctor.isPrivate()) {
1043 ctor.makeHDF(data, "class.ctors.private." + i);
1051 for (MethodInfo method: methods) {
1052 if (method.isPublic()) {
1053 method.makeHDF(data, "class.methods.public." + i);
1058 // protected methods
1059 if (DroidDoc.checkLevel(DroidDoc.SHOW_PROTECTED)) {
1061 for (MethodInfo method: methods) {
1062 if (method.isProtected()) {
1063 method.makeHDF(data, "class.methods.protected." + i);
1069 // package private methods
1070 if (DroidDoc.checkLevel(DroidDoc.SHOW_PACKAGE)) {
1072 for (MethodInfo method: methods) {
1073 if (method.isPackagePrivate()) {
1074 method.makeHDF(data, "class.methods.package." + i);
1081 if (DroidDoc.checkLevel(DroidDoc.SHOW_PRIVATE)) {
1083 for (MethodInfo method: methods) {
1084 if (method.isPrivate()) {
1085 method.makeHDF(data, "class.methods.private." + i);
1093 for (AttributeInfo attr: selfAttributes) {
1094 if (attr.checkLevel()) {
1095 attr.makeHDF(data, "class.attrs." + i);
1100 // inherited methods
1101 Set<ClassInfo> interfaces = new TreeSet<ClassInfo>();
1102 addInterfaces(interfaces(), interfaces);
1103 ClassInfo cl = superclass();
1105 while (cl != null) {
1106 addInterfaces(cl.interfaces(), interfaces);
1107 makeInheritedHDF(data, i, cl);
1108 cl = cl.superclass();
1111 for (ClassInfo iface: interfaces) {
1112 makeInheritedHDF(data, i, iface);
1117 private static void addInterfaces(ClassInfo[] ifaces, Set<ClassInfo> out)
1119 for (ClassInfo cl: ifaces) {
1121 addInterfaces(cl.interfaces(), out);
1125 private static void makeInheritedHDF(HDF data, int index, ClassInfo cl)
1129 String base = "class.inherited." + index;
1130 data.setValue(base + ".qualified", cl.qualifiedName());
1131 if (cl.checkLevel()) {
1132 data.setValue(base + ".link", cl.htmlPage());
1134 String kind = cl.kind();
1136 data.setValue(base + ".kind", kind);
1141 for (AttributeInfo attr: cl.selfAttributes()) {
1142 attr.makeHDF(data, base + ".attrs." + i);
1148 for (MethodInfo method: cl.selfMethods()) {
1149 method.makeHDF(data, base + ".methods." + i);
1155 for (FieldInfo field: cl.selfFields()) {
1156 if (!field.isConstant()) {
1157 field.makeHDF(data, base + ".fields." + i);
1164 for (FieldInfo field: cl.selfFields()) {
1165 if (field.isConstant()) {
1166 field.makeHDF(data, base + ".constants." + i);
1172 public boolean isHidden()
1178 boolean v = isHiddenImpl();
1179 mHidden = v ? 1 : 0;
1184 public boolean isHiddenImpl()
1186 ClassInfo cl = this;
1187 while (cl != null) {
1188 PackageInfo pkg = cl.containingPackage();
1189 if (pkg != null && pkg.isHidden()) {
1192 if (cl.comment().isHidden()) {
1195 cl = cl.containingClass();
1200 private MethodInfo matchMethod(MethodInfo[] methods, String name,
1201 String[] params, String[] dimensions)
1203 int len = methods.length;
1204 for (int i=0; i<len; i++) {
1205 MethodInfo method = methods[i];
1206 if (method.name().equals(name)) {
1207 if (params == null) {
1210 if (method.matchesParams(params, dimensions)) {
1219 public MethodInfo findMethod(String name,
1220 String[] params, String[] dimensions)
1222 // first look on our class, and our superclasses
1226 rv = matchMethod(methods(), name, params, dimensions);
1233 rv = matchMethod(constructors(), name, params, dimensions);
1238 // then recursively look at our containing class
1239 ClassInfo containing = containingClass();
1240 if (containing != null) {
1241 return containing.findMethod(name, params, dimensions);
1247 private ClassInfo searchInnerClasses(String[] nameParts, int index)
1249 String part = nameParts[index];
1251 ClassInfo[] inners = mInnerClasses;
1252 for (ClassInfo in: inners) {
1253 String[] innerParts = in.nameParts();
1254 if (part.equals(innerParts[innerParts.length-1])) {
1255 if (index == nameParts.length-1) {
1258 return in.searchInnerClasses(nameParts, index+1);
1265 public ClassInfo extendedFindClass(String className)
1267 // ClassDoc.findClass has this bug that we're working around here:
1268 // If you have a class PackageManager with an inner class PackageInfo
1269 // and you call it with "PackageInfo" it doesn't find it.
1270 return searchInnerClasses(className.split("\\."), 0);
1273 public ClassInfo findClass(String className)
1275 return Converter.obtainClass(mClass.findClass(className));
1278 public ClassInfo findInnerClass(String className)
1280 // ClassDoc.findClass won't find inner classes. To deal with that,
1281 // we try what they gave us first, but if that didn't work, then
1282 // we see if there are any periods in className, and start searching
1284 String[] nodes = className.split("\\.");
1285 ClassDoc cl = mClass;
1286 for (String n: nodes) {
1287 cl = cl.findClass(n);
1292 return Converter.obtainClass(cl);
1295 public FieldInfo findField(String name)
1297 // first look on our class, and our superclasses
1298 for (FieldInfo f: fields()) {
1299 if (f.name().equals(name)) {
1304 // then look at our enum constants (these are really fields, maybe
1305 // they should be mixed into fields(). not sure)
1306 for (FieldInfo f: enumConstants()) {
1307 if (f.name().equals(name)) {
1312 // then recursively look at our containing class
1313 ClassInfo containing = containingClass();
1314 if (containing != null) {
1315 return containing.findField(name);
1321 public static ClassInfo[] sortByName(ClassInfo[] classes)
1324 Sorter[] sorted = new Sorter[classes.length];
1325 for (i=0; i<sorted.length; i++) {
1326 ClassInfo cl = classes[i];
1327 sorted[i] = new Sorter(cl.name(), cl);
1330 Arrays.sort(sorted);
1332 ClassInfo[] rv = new ClassInfo[classes.length];
1333 for (i=0; i<rv.length; i++) {
1334 rv[i] = (ClassInfo)sorted[i].data;
1340 public boolean equals(ClassInfo that)
1343 return this.qualifiedName().equals(that.qualifiedName());
1349 public void setNonWrittenConstructors(MethodInfo[] nonWritten) {
1350 mNonWrittenConstructors = nonWritten;
1353 public MethodInfo[] getNonWrittenConstructors() {
1354 return mNonWrittenConstructors;
1357 public String kind()
1359 if (isOrdinaryClass()) {
1362 else if (isInterface()) {
1365 else if (isEnum()) {
1368 else if (isError()) {
1371 else if (isException()) {
1374 else if (isAnnotation()) {
1375 return "@interface";
1380 public void setHiddenMethods(MethodInfo[] mInfo){
1381 mHiddenMethods = mInfo;
1383 public MethodInfo[] getHiddenMethods(){
1384 return mHiddenMethods;
1386 public String toString(){
1387 return this.qualifiedName();
1390 public void setReasonIncluded(String reason) {
1391 mReasonIncluded = reason;
1394 public String getReasonIncluded() {
1395 return mReasonIncluded;
1398 private ClassDoc mClass;
1401 private boolean mIsPublic;
1402 private boolean mIsProtected;
1403 private boolean mIsPackagePrivate;
1404 private boolean mIsPrivate;
1405 private boolean mIsStatic;
1406 private boolean mIsInterface;
1407 private boolean mIsAbstract;
1408 private boolean mIsOrdinaryClass;
1409 private boolean mIsException;
1410 private boolean mIsError;
1411 private boolean mIsEnum;
1412 private boolean mIsAnnotation;
1413 private boolean mIsFinal;
1414 private boolean mIsIncluded;
1415 private String mName;
1416 private String mQualifiedName;
1417 private String mQualifiedTypeName;
1418 private boolean mIsPrimitive;
1419 private TypeInfo mTypeInfo;
1420 private String[] mNameParts;
1423 private ClassInfo[] mRealInterfaces;
1424 private ClassInfo[] mInterfaces;
1425 private TypeInfo[] mRealInterfaceTypes;
1426 private ClassInfo[] mInnerClasses;
1427 private MethodInfo[] mAllConstructors;
1428 private MethodInfo[] mAllSelfMethods;
1429 private MethodInfo[] mAnnotationElements; // if this class is an annotation
1430 private FieldInfo[] mAllSelfFields;
1431 private FieldInfo[] mEnumConstants;
1432 private PackageInfo mContainingPackage;
1433 private ClassInfo mContainingClass;
1434 private ClassInfo mRealSuperclass;
1435 private TypeInfo mRealSuperclassType;
1436 private ClassInfo mSuperclass;
1437 private AnnotationInstanceInfo[] mAnnotations;
1438 private boolean mSuperclassInit;
1439 private boolean mDeprecatedKnown;
1442 private MethodInfo[] mConstructors;
1443 private ClassInfo[] mRealInnerClasses;
1444 private MethodInfo[] mSelfMethods;
1445 private FieldInfo[] mSelfFields;
1446 private AttributeInfo[] mSelfAttributes;
1447 private MethodInfo[] mMethods;
1448 private FieldInfo[] mFields;
1449 private TypeInfo[] mTypeParameters;
1450 private MethodInfo[] mHiddenMethods;
1451 private int mHidden = -1;
1452 private int mCheckLevel = -1;
1453 private String mReasonIncluded;
1454 private MethodInfo[] mNonWrittenConstructors;
1455 private boolean mIsDeprecated;