PageRenderTime 65ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 1ms

/tools/droiddoc/src/ClassInfo.java

https://github.com/jsherman/platform_build
Java | 1455 lines | 1193 code | 164 blank | 98 comment | 265 complexity | 62cc672b5d892975f87299c5c8b52b82 MD5 | raw file
  1. /*
  2. * Copyright (C) 2008 The Android Open Source Project
  3. *
  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
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  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.
  15. */
  16. import com.sun.javadoc.*;
  17. import com.sun.tools.doclets.*;
  18. import org.clearsilver.HDF;
  19. import org.clearsilver.CS;
  20. import java.util.*;
  21. import java.io.*;
  22. public class ClassInfo extends DocInfo implements ContainerInfo, Comparable, Scoped
  23. {
  24. public static final Comparator<ClassInfo> comparator = new Comparator<ClassInfo>() {
  25. public int compare(ClassInfo a, ClassInfo b) {
  26. return a.name().compareTo(b.name());
  27. }
  28. };
  29. public static final Comparator<ClassInfo> qualifiedComparator = new Comparator<ClassInfo>() {
  30. public int compare(ClassInfo a, ClassInfo b) {
  31. return a.qualifiedName().compareTo(b.qualifiedName());
  32. }
  33. };
  34. public ClassInfo(
  35. ClassDoc cl,
  36. String rawCommentText, SourcePositionInfo position,
  37. boolean isPublic, boolean isProtected, boolean isPackagePrivate,
  38. boolean isPrivate, boolean isStatic,
  39. boolean isInterface, boolean isAbstract, boolean isOrdinaryClass,
  40. boolean isException, boolean isError, boolean isEnum, boolean isAnnotation,
  41. boolean isFinal, boolean isIncluded, String name,
  42. String qualifiedName, String qualifiedTypeName, boolean isPrimitive)
  43. {
  44. super(rawCommentText, position);
  45. mClass = cl;
  46. mIsPublic = isPublic;
  47. mIsProtected = isProtected;
  48. mIsPackagePrivate = isPackagePrivate;
  49. mIsPrivate = isPrivate;
  50. mIsStatic = isStatic;
  51. mIsInterface = isInterface;
  52. mIsAbstract = isAbstract;
  53. mIsOrdinaryClass = isOrdinaryClass;
  54. mIsException = isException;
  55. mIsError = isError;
  56. mIsEnum = isEnum;
  57. mIsAnnotation = isAnnotation;
  58. mIsFinal = isFinal;
  59. mIsIncluded = isIncluded;
  60. mName = name;
  61. mQualifiedName = qualifiedName;
  62. mQualifiedTypeName = qualifiedTypeName;
  63. mIsPrimitive = isPrimitive;
  64. mNameParts = name.split("\\.");
  65. }
  66. public void init(TypeInfo typeInfo, ClassInfo[] interfaces, TypeInfo[] interfaceTypes,
  67. ClassInfo[] innerClasses,
  68. MethodInfo[] constructors, MethodInfo[] methods, MethodInfo[] annotationElements,
  69. FieldInfo[] fields, FieldInfo[] enumConstants,
  70. PackageInfo containingPackage, ClassInfo containingClass,
  71. ClassInfo superclass, TypeInfo superclassType, AnnotationInstanceInfo[] annotations)
  72. {
  73. mTypeInfo = typeInfo;
  74. mRealInterfaces = interfaces;
  75. mRealInterfaceTypes = interfaceTypes;
  76. mInnerClasses = innerClasses;
  77. mAllConstructors = constructors;
  78. mAllSelfMethods = methods;
  79. mAnnotationElements = annotationElements;
  80. mAllSelfFields = fields;
  81. mEnumConstants = enumConstants;
  82. mContainingPackage = containingPackage;
  83. mContainingClass = containingClass;
  84. mRealSuperclass = superclass;
  85. mRealSuperclassType = superclassType;
  86. mAnnotations = annotations;
  87. // after providing new methods and new superclass info,clear any cached
  88. // lists of self + superclass methods, ctors, etc.
  89. mSuperclassInit = false;
  90. mConstructors = null;
  91. mMethods = null;
  92. mSelfMethods = null;
  93. mFields = null;
  94. mSelfFields = null;
  95. mSelfAttributes = null;
  96. mDeprecatedKnown = false;
  97. Arrays.sort(mEnumConstants, FieldInfo.comparator);
  98. Arrays.sort(mInnerClasses, ClassInfo.comparator);
  99. }
  100. public void init2() {
  101. // calling this here forces the AttrTagInfo objects to be linked to the AttribtueInfo
  102. // objects
  103. selfAttributes();
  104. }
  105. public void init3(TypeInfo[] types, ClassInfo[] realInnerClasses){
  106. mTypeParameters = types;
  107. mRealInnerClasses = realInnerClasses;
  108. }
  109. public ClassInfo[] getRealInnerClasses(){
  110. return mRealInnerClasses;
  111. }
  112. public TypeInfo[] getTypeParameters(){
  113. return mTypeParameters;
  114. }
  115. public boolean checkLevel()
  116. {
  117. int val = mCheckLevel;
  118. if (val >= 0) {
  119. return val != 0;
  120. } else {
  121. boolean v = DroidDoc.checkLevel(mIsPublic, mIsProtected,
  122. mIsPackagePrivate, mIsPrivate, isHidden());
  123. mCheckLevel = v ? 1 : 0;
  124. return v;
  125. }
  126. }
  127. public int compareTo(Object that) {
  128. if (that instanceof ClassInfo) {
  129. return mQualifiedName.compareTo(((ClassInfo)that).mQualifiedName);
  130. } else {
  131. return this.hashCode() - that.hashCode();
  132. }
  133. }
  134. public ContainerInfo parent()
  135. {
  136. return this;
  137. }
  138. public boolean isPublic()
  139. {
  140. return mIsPublic;
  141. }
  142. public boolean isProtected()
  143. {
  144. return mIsProtected;
  145. }
  146. public boolean isPackagePrivate()
  147. {
  148. return mIsPackagePrivate;
  149. }
  150. public boolean isPrivate()
  151. {
  152. return mIsPrivate;
  153. }
  154. public boolean isStatic()
  155. {
  156. return mIsStatic;
  157. }
  158. public boolean isInterface()
  159. {
  160. return mIsInterface;
  161. }
  162. public boolean isAbstract()
  163. {
  164. return mIsAbstract;
  165. }
  166. public PackageInfo containingPackage()
  167. {
  168. return mContainingPackage;
  169. }
  170. public ClassInfo containingClass()
  171. {
  172. return mContainingClass;
  173. }
  174. public boolean isOrdinaryClass()
  175. {
  176. return mIsOrdinaryClass;
  177. }
  178. public boolean isException()
  179. {
  180. return mIsException;
  181. }
  182. public boolean isError()
  183. {
  184. return mIsError;
  185. }
  186. public boolean isEnum()
  187. {
  188. return mIsEnum;
  189. }
  190. public boolean isAnnotation()
  191. {
  192. return mIsAnnotation;
  193. }
  194. public boolean isFinal()
  195. {
  196. return mIsFinal;
  197. }
  198. public boolean isIncluded()
  199. {
  200. return mIsIncluded;
  201. }
  202. public HashSet<String> typeVariables()
  203. {
  204. HashSet<String> result = TypeInfo.typeVariables(mTypeInfo.typeArguments());
  205. ClassInfo cl = containingClass();
  206. while (cl != null) {
  207. TypeInfo[] types = cl.asTypeInfo().typeArguments();
  208. if (types != null) {
  209. TypeInfo.typeVariables(types, result);
  210. }
  211. cl = cl.containingClass();
  212. }
  213. return result;
  214. }
  215. private static void gatherHiddenInterfaces(ClassInfo cl, HashSet<ClassInfo> interfaces) {
  216. for (ClassInfo iface: cl.mRealInterfaces) {
  217. if (iface.checkLevel()) {
  218. interfaces.add(iface);
  219. } else {
  220. gatherHiddenInterfaces(iface, interfaces);
  221. }
  222. }
  223. }
  224. public ClassInfo[] interfaces()
  225. {
  226. if (mInterfaces == null) {
  227. if (checkLevel()) {
  228. HashSet<ClassInfo> interfaces = new HashSet<ClassInfo>();
  229. ClassInfo superclass = mRealSuperclass;
  230. while (superclass != null && !superclass.checkLevel()) {
  231. gatherHiddenInterfaces(superclass, interfaces);
  232. superclass = superclass.mRealSuperclass;
  233. }
  234. gatherHiddenInterfaces(this, interfaces);
  235. mInterfaces = interfaces.toArray(new ClassInfo[interfaces.size()]);
  236. } else {
  237. // put something here in case someone uses it
  238. mInterfaces = mRealInterfaces;
  239. }
  240. Arrays.sort(mInterfaces, ClassInfo.qualifiedComparator);
  241. }
  242. return mInterfaces;
  243. }
  244. public ClassInfo[] realInterfaces()
  245. {
  246. return mRealInterfaces;
  247. }
  248. TypeInfo[] realInterfaceTypes()
  249. {
  250. return mRealInterfaceTypes;
  251. }
  252. public String name()
  253. {
  254. return mName;
  255. }
  256. public String[] nameParts()
  257. {
  258. return mNameParts;
  259. }
  260. public String leafName()
  261. {
  262. return mNameParts[mNameParts.length-1];
  263. }
  264. public String qualifiedName()
  265. {
  266. return mQualifiedName;
  267. }
  268. public String qualifiedTypeName()
  269. {
  270. return mQualifiedTypeName;
  271. }
  272. public boolean isPrimitive()
  273. {
  274. return mIsPrimitive;
  275. }
  276. public MethodInfo[] allConstructors() {
  277. return mAllConstructors;
  278. }
  279. public MethodInfo[] constructors()
  280. {
  281. if (mConstructors == null) {
  282. MethodInfo[] methods = mAllConstructors;
  283. ArrayList<MethodInfo> ctors = new ArrayList<MethodInfo>();
  284. for (int i=0; i<methods.length; i++) {
  285. MethodInfo m = methods[i];
  286. if (!m.isHidden()) {
  287. ctors.add(m);
  288. }
  289. }
  290. mConstructors = ctors.toArray(new MethodInfo[ctors.size()]);
  291. Arrays.sort(mConstructors, MethodInfo.comparator);
  292. }
  293. return mConstructors;
  294. }
  295. public ClassInfo[] innerClasses()
  296. {
  297. return mInnerClasses;
  298. }
  299. public TagInfo[] inlineTags()
  300. {
  301. return comment().tags();
  302. }
  303. public TagInfo[] firstSentenceTags()
  304. {
  305. return comment().briefTags();
  306. }
  307. public boolean isDeprecated() {
  308. boolean deprecated = false;
  309. if (!mDeprecatedKnown) {
  310. boolean commentDeprecated = (comment().deprecatedTags().length > 0);
  311. boolean annotationDeprecated = false;
  312. for (AnnotationInstanceInfo annotation : annotations()) {
  313. if (annotation.type().qualifiedName().equals("java.lang.Deprecated")) {
  314. annotationDeprecated = true;
  315. break;
  316. }
  317. }
  318. if (commentDeprecated != annotationDeprecated) {
  319. Errors.error(Errors.DEPRECATION_MISMATCH, position(),
  320. "Class " + qualifiedName()
  321. + ": @Deprecated annotation and @deprecated comment do not match");
  322. }
  323. mIsDeprecated = commentDeprecated | annotationDeprecated;
  324. mDeprecatedKnown = true;
  325. }
  326. return mIsDeprecated;
  327. }
  328. public TagInfo[] deprecatedTags()
  329. {
  330. // Should we also do the interfaces?
  331. return comment().deprecatedTags();
  332. }
  333. public MethodInfo[] methods()
  334. {
  335. if (mMethods == null) {
  336. TreeMap<String,MethodInfo> all = new TreeMap<String,MethodInfo>();
  337. ClassInfo[] ifaces = interfaces();
  338. for (ClassInfo iface: ifaces) {
  339. if (iface != null) {
  340. MethodInfo[] inhereted = iface.methods();
  341. for (MethodInfo method: inhereted) {
  342. String key = method.name() + method.signature();
  343. all.put(key, method);
  344. }
  345. }
  346. }
  347. ClassInfo superclass = superclass();
  348. if (superclass != null) {
  349. MethodInfo[] inhereted = superclass.methods();
  350. for (MethodInfo method: inhereted) {
  351. String key = method.name() + method.signature();
  352. all.put(key, method);
  353. }
  354. }
  355. MethodInfo[] methods = selfMethods();
  356. for (MethodInfo method: methods) {
  357. String key = method.name() + method.signature();
  358. MethodInfo old = all.put(key, method);
  359. }
  360. mMethods = all.values().toArray(new MethodInfo[all.size()]);
  361. }
  362. return mMethods;
  363. }
  364. public MethodInfo[] annotationElements()
  365. {
  366. return mAnnotationElements;
  367. }
  368. public AnnotationInstanceInfo[] annotations()
  369. {
  370. return mAnnotations;
  371. }
  372. private static void addFields(ClassInfo cl, TreeMap<String,FieldInfo> all)
  373. {
  374. FieldInfo[] fields = cl.fields();
  375. int N = fields.length;
  376. for (int i=0; i<N; i++) {
  377. FieldInfo f = fields[i];
  378. all.put(f.name(), f);
  379. }
  380. }
  381. public FieldInfo[] fields()
  382. {
  383. if (mFields == null) {
  384. int N;
  385. TreeMap<String,FieldInfo> all = new TreeMap<String,FieldInfo>();
  386. ClassInfo[] interfaces = interfaces();
  387. N = interfaces.length;
  388. for (int i=0; i<N; i++) {
  389. addFields(interfaces[i], all);
  390. }
  391. ClassInfo superclass = superclass();
  392. if (superclass != null) {
  393. addFields(superclass, all);
  394. }
  395. FieldInfo[] fields = selfFields();
  396. N = fields.length;
  397. for (int i=0; i<N; i++) {
  398. FieldInfo f = fields[i];
  399. if (!f.isHidden()) {
  400. String key = f.name();
  401. all.put(key, f);
  402. }
  403. }
  404. mFields = all.values().toArray(new FieldInfo[0]);
  405. }
  406. return mFields;
  407. }
  408. public void gatherFields(ClassInfo owner, ClassInfo cl, HashMap<String,FieldInfo> fields) {
  409. FieldInfo[] flds = cl.selfFields();
  410. for (FieldInfo f: flds) {
  411. if (f.checkLevel()) {
  412. fields.put(f.name(), f.cloneForClass(owner));
  413. }
  414. }
  415. }
  416. public FieldInfo[] selfFields()
  417. {
  418. if (mSelfFields == null) {
  419. HashMap<String,FieldInfo> fields = new HashMap<String,FieldInfo>();
  420. // our hidden parents
  421. if (mRealSuperclass != null && !mRealSuperclass.checkLevel()) {
  422. gatherFields(this, mRealSuperclass, fields);
  423. }
  424. for (ClassInfo iface: mRealInterfaces) {
  425. if (!iface.checkLevel()) {
  426. gatherFields(this, iface, fields);
  427. }
  428. }
  429. // mine
  430. FieldInfo[] selfFields = mAllSelfFields;
  431. for (int i=0; i<selfFields.length; i++) {
  432. FieldInfo f = selfFields[i];
  433. if (!f.isHidden()) {
  434. fields.put(f.name(), f);
  435. }
  436. }
  437. // combine and return in
  438. mSelfFields = fields.values().toArray(new FieldInfo[fields.size()]);
  439. Arrays.sort(mSelfFields, FieldInfo.comparator);
  440. }
  441. return mSelfFields;
  442. }
  443. public FieldInfo[] allSelfFields() {
  444. return mAllSelfFields;
  445. }
  446. public void gatherMethods(ClassInfo owner, ClassInfo cl, HashMap<String,MethodInfo> methods) {
  447. MethodInfo[] meth = cl.selfMethods();
  448. for (MethodInfo m: meth) {
  449. if (m.checkLevel()) {
  450. methods.put(m.name()+m.signature(), m.cloneForClass(owner));
  451. }
  452. }
  453. }
  454. public MethodInfo[] selfMethods()
  455. {
  456. if (mSelfMethods == null) {
  457. HashMap<String,MethodInfo> methods = new HashMap<String,MethodInfo>();
  458. // our hidden parents
  459. if (mRealSuperclass != null && !mRealSuperclass.checkLevel()) {
  460. gatherMethods(this, mRealSuperclass, methods);
  461. }
  462. for (ClassInfo iface: mRealInterfaces) {
  463. if (!iface.checkLevel()) {
  464. gatherMethods(this, iface, methods);
  465. }
  466. }
  467. // mine
  468. MethodInfo[] selfMethods = mAllSelfMethods;
  469. for (int i=0; i<selfMethods.length; i++) {
  470. MethodInfo m = selfMethods[i];
  471. if (m.checkLevel()) {
  472. methods.put(m.name()+m.signature(), m);
  473. }
  474. }
  475. // combine and return it
  476. mSelfMethods = methods.values().toArray(new MethodInfo[methods.size()]);
  477. Arrays.sort(mSelfMethods, MethodInfo.comparator);
  478. }
  479. return mSelfMethods;
  480. }
  481. public MethodInfo[] allSelfMethods() {
  482. return mAllSelfMethods;
  483. }
  484. public void addMethod(MethodInfo method) {
  485. MethodInfo[] methods = new MethodInfo[mAllSelfMethods.length + 1];
  486. int i = 0;
  487. for (MethodInfo m : mAllSelfMethods) {
  488. methods[i] = m;
  489. i++;
  490. }
  491. methods[i] = method;
  492. mAllSelfMethods = methods;
  493. }
  494. public AttributeInfo[] selfAttributes()
  495. {
  496. if (mSelfAttributes == null) {
  497. TreeMap<FieldInfo,AttributeInfo> attrs = new TreeMap<FieldInfo,AttributeInfo>();
  498. // the ones in the class comment won't have any methods
  499. for (AttrTagInfo tag: comment().attrTags()) {
  500. FieldInfo field = tag.reference();
  501. if (field != null) {
  502. AttributeInfo attr = attrs.get(field);
  503. if (attr == null) {
  504. attr = new AttributeInfo(this, field);
  505. attrs.put(field, attr);
  506. }
  507. tag.setAttribute(attr);
  508. }
  509. }
  510. // in the methods
  511. for (MethodInfo m: selfMethods()) {
  512. for (AttrTagInfo tag: m.comment().attrTags()) {
  513. FieldInfo field = tag.reference();
  514. if (field != null) {
  515. AttributeInfo attr = attrs.get(field);
  516. if (attr == null) {
  517. attr = new AttributeInfo(this, field);
  518. attrs.put(field, attr);
  519. }
  520. tag.setAttribute(attr);
  521. attr.methods.add(m);
  522. }
  523. }
  524. }
  525. //constructors too
  526. for (MethodInfo m: constructors()) {
  527. for (AttrTagInfo tag: m.comment().attrTags()) {
  528. FieldInfo field = tag.reference();
  529. if (field != null) {
  530. AttributeInfo attr = attrs.get(field);
  531. if (attr == null) {
  532. attr = new AttributeInfo(this, field);
  533. attrs.put(field, attr);
  534. }
  535. tag.setAttribute(attr);
  536. attr.methods.add(m);
  537. }
  538. }
  539. }
  540. mSelfAttributes = attrs.values().toArray(new AttributeInfo[attrs.size()]);
  541. Arrays.sort(mSelfAttributes, AttributeInfo.comparator);
  542. }
  543. return mSelfAttributes;
  544. }
  545. public FieldInfo[] enumConstants()
  546. {
  547. return mEnumConstants;
  548. }
  549. public ClassInfo superclass()
  550. {
  551. if (!mSuperclassInit) {
  552. if (this.checkLevel()) {
  553. // rearrange our little inheritance hierarchy, because we need to hide classes that
  554. // don't pass checkLevel
  555. ClassInfo superclass = mRealSuperclass;
  556. while (superclass != null && !superclass.checkLevel()) {
  557. superclass = superclass.mRealSuperclass;
  558. }
  559. mSuperclass = superclass;
  560. } else {
  561. mSuperclass = mRealSuperclass;
  562. }
  563. }
  564. return mSuperclass;
  565. }
  566. public ClassInfo realSuperclass()
  567. {
  568. return mRealSuperclass;
  569. }
  570. /** always the real superclass, not the collapsed one we get through superclass(),
  571. * also has the type parameter info if it's generic.
  572. */
  573. public TypeInfo superclassType()
  574. {
  575. return mRealSuperclassType;
  576. }
  577. public TypeInfo asTypeInfo()
  578. {
  579. return mTypeInfo;
  580. }
  581. TypeInfo[] interfaceTypes()
  582. {
  583. ClassInfo[] infos = interfaces();
  584. int len = infos.length;
  585. TypeInfo[] types = new TypeInfo[len];
  586. for (int i=0; i<len; i++) {
  587. types[i] = infos[i].asTypeInfo();
  588. }
  589. return types;
  590. }
  591. public String htmlPage()
  592. {
  593. String s = containingPackage().name();
  594. s = s.replace('.', '/');
  595. s += '/';
  596. s += name();
  597. s += ".html";
  598. s = DroidDoc.javadocDir + s;
  599. return s;
  600. }
  601. /** Even indirectly */
  602. public boolean isDerivedFrom(ClassInfo cl)
  603. {
  604. ClassInfo dad = this.superclass();
  605. if (dad != null) {
  606. if (dad.equals(cl)) {
  607. return true;
  608. } else {
  609. if (dad.isDerivedFrom(cl)) {
  610. return true;
  611. }
  612. }
  613. }
  614. for (ClassInfo iface: interfaces()) {
  615. if (iface.equals(cl)) {
  616. return true;
  617. } else {
  618. if (iface.isDerivedFrom(cl)) {
  619. return true;
  620. }
  621. }
  622. }
  623. return false;
  624. }
  625. public void makeKeywordEntries(List<KeywordEntry> keywords)
  626. {
  627. if (!checkLevel()) {
  628. return;
  629. }
  630. String htmlPage = htmlPage();
  631. String qualifiedName = qualifiedName();
  632. keywords.add(new KeywordEntry(name(), htmlPage,
  633. "class in " + containingPackage().name()));
  634. FieldInfo[] fields = selfFields();
  635. FieldInfo[] enumConstants = enumConstants();
  636. MethodInfo[] ctors = constructors();
  637. MethodInfo[] methods = selfMethods();
  638. // enum constants
  639. for (FieldInfo field: enumConstants()) {
  640. if (field.checkLevel()) {
  641. keywords.add(new KeywordEntry(field.name(),
  642. htmlPage + "#" + field.anchor(),
  643. "enum constant in " + qualifiedName));
  644. }
  645. }
  646. // constants
  647. for (FieldInfo field: fields) {
  648. if (field.isConstant() && field.checkLevel()) {
  649. keywords.add(new KeywordEntry(field.name(),
  650. htmlPage + "#" + field.anchor(),
  651. "constant in " + qualifiedName));
  652. }
  653. }
  654. // fields
  655. for (FieldInfo field: fields) {
  656. if (!field.isConstant() && field.checkLevel()) {
  657. keywords.add(new KeywordEntry(field.name(),
  658. htmlPage + "#" + field.anchor(),
  659. "field in " + qualifiedName));
  660. }
  661. }
  662. // public constructors
  663. for (MethodInfo m: ctors) {
  664. if (m.isPublic() && m.checkLevel()) {
  665. keywords.add(new KeywordEntry(m.name() + m.prettySignature(),
  666. htmlPage + "#" + m.anchor(),
  667. "constructor in " + qualifiedName));
  668. }
  669. }
  670. // protected constructors
  671. if (DroidDoc.checkLevel(DroidDoc.SHOW_PROTECTED)) {
  672. for (MethodInfo m: ctors) {
  673. if (m.isProtected() && m.checkLevel()) {
  674. keywords.add(new KeywordEntry(m.name() + m.prettySignature(),
  675. htmlPage + "#" + m.anchor(),
  676. "constructor in " + qualifiedName));
  677. }
  678. }
  679. }
  680. // package private constructors
  681. if (DroidDoc.checkLevel(DroidDoc.SHOW_PACKAGE)) {
  682. for (MethodInfo m: ctors) {
  683. if (m.isPackagePrivate() && m.checkLevel()) {
  684. keywords.add(new KeywordEntry(m.name() + m.prettySignature(),
  685. htmlPage + "#" + m.anchor(),
  686. "constructor in " + qualifiedName));
  687. }
  688. }
  689. }
  690. // private constructors
  691. if (DroidDoc.checkLevel(DroidDoc.SHOW_PRIVATE)) {
  692. for (MethodInfo m: ctors) {
  693. if (m.isPrivate() && m.checkLevel()) {
  694. keywords.add(new KeywordEntry(m.name() + m.prettySignature(),
  695. htmlPage + "#" + m.anchor(),
  696. "constructor in " + qualifiedName));
  697. }
  698. }
  699. }
  700. // public methods
  701. for (MethodInfo m: methods) {
  702. if (m.isPublic() && m.checkLevel()) {
  703. keywords.add(new KeywordEntry(m.name() + m.prettySignature(),
  704. htmlPage + "#" + m.anchor(),
  705. "method in " + qualifiedName));
  706. }
  707. }
  708. // protected methods
  709. if (DroidDoc.checkLevel(DroidDoc.SHOW_PROTECTED)) {
  710. for (MethodInfo m: methods) {
  711. if (m.isProtected() && m.checkLevel()) {
  712. keywords.add(new KeywordEntry(m.name() + m.prettySignature(),
  713. htmlPage + "#" + m.anchor(),
  714. "method in " + qualifiedName));
  715. }
  716. }
  717. }
  718. // package private methods
  719. if (DroidDoc.checkLevel(DroidDoc.SHOW_PACKAGE)) {
  720. for (MethodInfo m: methods) {
  721. if (m.isPackagePrivate() && m.checkLevel()) {
  722. keywords.add(new KeywordEntry(m.name() + m.prettySignature(),
  723. htmlPage + "#" + m.anchor(),
  724. "method in " + qualifiedName));
  725. }
  726. }
  727. }
  728. // private methods
  729. if (DroidDoc.checkLevel(DroidDoc.SHOW_PRIVATE)) {
  730. for (MethodInfo m: methods) {
  731. if (m.isPrivate() && m.checkLevel()) {
  732. keywords.add(new KeywordEntry(m.name() + m.prettySignature(),
  733. htmlPage + "#" + m.anchor(),
  734. "method in " + qualifiedName));
  735. }
  736. }
  737. }
  738. }
  739. public void makeLink(HDF data, String base)
  740. {
  741. data.setValue(base + ".label", this.name());
  742. if (!this.isPrimitive() && this.isIncluded() && this.checkLevel()) {
  743. data.setValue(base + ".link", this.htmlPage());
  744. }
  745. }
  746. public static void makeLinkListHDF(HDF data, String base, ClassInfo[] classes) {
  747. final int N = classes.length;
  748. for (int i=0; i<N; i++) {
  749. ClassInfo cl = classes[i];
  750. if (cl.checkLevel()) {
  751. cl.asTypeInfo().makeHDF(data, base + "." + i);
  752. }
  753. }
  754. }
  755. /**
  756. * Used in lists of this class (packages, nested classes, known subclasses)
  757. */
  758. public void makeShortDescrHDF(HDF data, String base)
  759. {
  760. mTypeInfo.makeHDF(data, base + ".type");
  761. data.setValue(base + ".kind", this.kind());
  762. TagInfo.makeHDF(data, base + ".shortDescr", this.firstSentenceTags());
  763. TagInfo.makeHDF(data, base + ".deprecated", deprecatedTags());
  764. }
  765. /**
  766. * Turns into the main class page
  767. */
  768. public void makeHDF(HDF data)
  769. {
  770. int i, j, n;
  771. String name = name();
  772. String qualified = qualifiedName();
  773. AttributeInfo[] selfAttributes = selfAttributes();
  774. MethodInfo[] methods = selfMethods();
  775. FieldInfo[] fields = selfFields();
  776. FieldInfo[] enumConstants = enumConstants();
  777. MethodInfo[] ctors = constructors();
  778. ClassInfo[] inners = innerClasses();
  779. // class name
  780. mTypeInfo.makeHDF(data, "class.type");
  781. mTypeInfo.makeQualifiedHDF(data, "class.qualifiedType");
  782. data.setValue("class.name", name);
  783. data.setValue("class.qualified", qualified);
  784. String scope = "";
  785. if (isProtected()) {
  786. data.setValue("class.scope", "protected");
  787. }
  788. else if (isPublic()) {
  789. data.setValue("class.scope", "public");
  790. }
  791. if (isStatic()) {
  792. data.setValue("class.static", "static");
  793. }
  794. if (isFinal()) {
  795. data.setValue("class.final", "final");
  796. }
  797. if (isAbstract() && !isInterface()) {
  798. data.setValue("class.abstract", "abstract");
  799. }
  800. // class info
  801. String kind = kind();
  802. if (kind != null) {
  803. data.setValue("class.kind", kind);
  804. }
  805. // the containing package -- note that this can be passed to type_link,
  806. // but it also contains the list of all of the packages
  807. containingPackage().makeClassLinkListHDF(data, "class.package");
  808. // inheritance hierarchy
  809. Vector<ClassInfo> superClasses = new Vector<ClassInfo>();
  810. superClasses.add(this);
  811. ClassInfo supr = superclass();
  812. while (supr != null) {
  813. superClasses.add(supr);
  814. supr = supr.superclass();
  815. }
  816. n = superClasses.size();
  817. for (i=0; i<n; i++) {
  818. supr = superClasses.elementAt(n-i-1);
  819. supr.asTypeInfo().makeQualifiedHDF(data, "class.inheritance." + i + ".class");
  820. supr.asTypeInfo().makeHDF(data, "class.inheritance." + i + ".short_class");
  821. j = 0;
  822. for (TypeInfo t: supr.interfaceTypes()) {
  823. t.makeHDF(data, "class.inheritance." + i + ".interfaces." + j);
  824. j++;
  825. }
  826. }
  827. // class description
  828. TagInfo.makeHDF(data, "class.descr", inlineTags());
  829. TagInfo.makeHDF(data, "class.seeAlso", comment().seeTags());
  830. TagInfo.makeHDF(data, "class.deprecated", deprecatedTags());
  831. // known subclasses
  832. TreeMap<String, ClassInfo> direct = new TreeMap<String, ClassInfo>();
  833. TreeMap<String, ClassInfo> indirect = new TreeMap<String, ClassInfo>();
  834. ClassInfo[] all = Converter.rootClasses();
  835. for (ClassInfo cl: all) {
  836. if (cl.superclass() != null && cl.superclass().equals(this)) {
  837. direct.put(cl.name(), cl);
  838. }
  839. else if (cl.isDerivedFrom(this)) {
  840. indirect.put(cl.name(), cl);
  841. }
  842. }
  843. // direct
  844. i = 0;
  845. for (ClassInfo cl: direct.values()) {
  846. if (cl.checkLevel()) {
  847. cl.makeShortDescrHDF(data, "class.subclasses.direct." + i);
  848. }
  849. i++;
  850. }
  851. // indirect
  852. i = 0;
  853. for (ClassInfo cl: indirect.values()) {
  854. if (cl.checkLevel()) {
  855. cl.makeShortDescrHDF(data, "class.subclasses.indirect." + i);
  856. }
  857. i++;
  858. }
  859. // nested classes
  860. i=0;
  861. for (ClassInfo inner: inners) {
  862. if (inner.checkLevel()) {
  863. inner.makeShortDescrHDF(data, "class.inners." + i);
  864. }
  865. i++;
  866. }
  867. // enum constants
  868. i=0;
  869. for (FieldInfo field: enumConstants) {
  870. if (field.isConstant()) {
  871. field.makeHDF(data, "class.enumConstants." + i);
  872. i++;
  873. }
  874. }
  875. // constants
  876. i=0;
  877. for (FieldInfo field: fields) {
  878. if (field.isConstant()) {
  879. field.makeHDF(data, "class.constants." + i);
  880. i++;
  881. }
  882. }
  883. // fields
  884. i=0;
  885. for (FieldInfo field: fields) {
  886. if (!field.isConstant()) {
  887. field.makeHDF(data, "class.fields." + i);
  888. i++;
  889. }
  890. }
  891. // public constructors
  892. i=0;
  893. for (MethodInfo ctor: ctors) {
  894. if (ctor.isPublic()) {
  895. ctor.makeHDF(data, "class.ctors.public." + i);
  896. i++;
  897. }
  898. }
  899. // protected constructors
  900. if (DroidDoc.checkLevel(DroidDoc.SHOW_PROTECTED)) {
  901. i=0;
  902. for (MethodInfo ctor: ctors) {
  903. if (ctor.isProtected()) {
  904. ctor.makeHDF(data, "class.ctors.protected." + i);
  905. i++;
  906. }
  907. }
  908. }
  909. // package private constructors
  910. if (DroidDoc.checkLevel(DroidDoc.SHOW_PACKAGE)) {
  911. i=0;
  912. for (MethodInfo ctor: ctors) {
  913. if (ctor.isPackagePrivate()) {
  914. ctor.makeHDF(data, "class.ctors.package." + i);
  915. i++;
  916. }
  917. }
  918. }
  919. // private constructors
  920. if (DroidDoc.checkLevel(DroidDoc.SHOW_PRIVATE)) {
  921. i=0;
  922. for (MethodInfo ctor: ctors) {
  923. if (ctor.isPrivate()) {
  924. ctor.makeHDF(data, "class.ctors.private." + i);
  925. i++;
  926. }
  927. }
  928. }
  929. // public methods
  930. i=0;
  931. for (MethodInfo method: methods) {
  932. if (method.isPublic()) {
  933. method.makeHDF(data, "class.methods.public." + i);
  934. i++;
  935. }
  936. }
  937. // protected methods
  938. if (DroidDoc.checkLevel(DroidDoc.SHOW_PROTECTED)) {
  939. i=0;
  940. for (MethodInfo method: methods) {
  941. if (method.isProtected()) {
  942. method.makeHDF(data, "class.methods.protected." + i);
  943. i++;
  944. }
  945. }
  946. }
  947. // package private methods
  948. if (DroidDoc.checkLevel(DroidDoc.SHOW_PACKAGE)) {
  949. i=0;
  950. for (MethodInfo method: methods) {
  951. if (method.isPackagePrivate()) {
  952. method.makeHDF(data, "class.methods.package." + i);
  953. i++;
  954. }
  955. }
  956. }
  957. // private methods
  958. if (DroidDoc.checkLevel(DroidDoc.SHOW_PRIVATE)) {
  959. i=0;
  960. for (MethodInfo method: methods) {
  961. if (method.isPrivate()) {
  962. method.makeHDF(data, "class.methods.private." + i);
  963. i++;
  964. }
  965. }
  966. }
  967. // xml attributes
  968. i=0;
  969. for (AttributeInfo attr: selfAttributes) {
  970. if (attr.checkLevel()) {
  971. attr.makeHDF(data, "class.attrs." + i);
  972. i++;
  973. }
  974. }
  975. // inherited methods
  976. Set<ClassInfo> interfaces = new TreeSet<ClassInfo>();
  977. addInterfaces(interfaces(), interfaces);
  978. ClassInfo cl = superclass();
  979. i=0;
  980. while (cl != null) {
  981. addInterfaces(cl.interfaces(), interfaces);
  982. makeInheritedHDF(data, i, cl);
  983. cl = cl.superclass();
  984. i++;
  985. }
  986. for (ClassInfo iface: interfaces) {
  987. makeInheritedHDF(data, i, iface);
  988. i++;
  989. }
  990. }
  991. private static void addInterfaces(ClassInfo[] ifaces, Set<ClassInfo> out)
  992. {
  993. for (ClassInfo cl: ifaces) {
  994. out.add(cl);
  995. addInterfaces(cl.interfaces(), out);
  996. }
  997. }
  998. private static void makeInheritedHDF(HDF data, int index, ClassInfo cl)
  999. {
  1000. int i;
  1001. String base = "class.inherited." + index;
  1002. data.setValue(base + ".qualified", cl.qualifiedName());
  1003. if (cl.checkLevel()) {
  1004. data.setValue(base + ".link", cl.htmlPage());
  1005. }
  1006. String kind = cl.kind();
  1007. if (kind != null) {
  1008. data.setValue(base + ".kind", kind);
  1009. }
  1010. // xml attributes
  1011. i=0;
  1012. for (AttributeInfo attr: cl.selfAttributes()) {
  1013. attr.makeHDF(data, base + ".attrs." + i);
  1014. i++;
  1015. }
  1016. // methods
  1017. i=0;
  1018. for (MethodInfo method: cl.selfMethods()) {
  1019. method.makeHDF(data, base + ".methods." + i);
  1020. i++;
  1021. }
  1022. // fields
  1023. i=0;
  1024. for (FieldInfo field: cl.selfFields()) {
  1025. if (!field.isConstant()) {
  1026. field.makeHDF(data, base + ".fields." + i);
  1027. i++;
  1028. }
  1029. }
  1030. // constants
  1031. i=0;
  1032. for (FieldInfo field: cl.selfFields()) {
  1033. if (field.isConstant()) {
  1034. field.makeHDF(data, base + ".constants." + i);
  1035. i++;
  1036. }
  1037. }
  1038. }
  1039. public boolean isHidden()
  1040. {
  1041. int val = mHidden;
  1042. if (val >= 0) {
  1043. return val != 0;
  1044. } else {
  1045. boolean v = isHiddenImpl();
  1046. mHidden = v ? 1 : 0;
  1047. return v;
  1048. }
  1049. }
  1050. public boolean isHiddenImpl()
  1051. {
  1052. ClassInfo cl = this;
  1053. while (cl != null) {
  1054. PackageInfo pkg = cl.containingPackage();
  1055. if (pkg.isHidden()) {
  1056. return true;
  1057. }
  1058. if (cl.comment().isHidden()) {
  1059. return true;
  1060. }
  1061. cl = cl.containingClass();
  1062. }
  1063. return false;
  1064. }
  1065. private MethodInfo matchMethod(MethodInfo[] methods, String name,
  1066. String[] params, String[] dimensions)
  1067. {
  1068. int len = methods.length;
  1069. for (int i=0; i<len; i++) {
  1070. MethodInfo method = methods[i];
  1071. if (method.name().equals(name)) {
  1072. if (params == null) {
  1073. return method;
  1074. } else {
  1075. if (method.matchesParams(params, dimensions)) {
  1076. return method;
  1077. }
  1078. }
  1079. }
  1080. }
  1081. return null;
  1082. }
  1083. public MethodInfo findMethod(String name,
  1084. String[] params, String[] dimensions)
  1085. {
  1086. // first look on our class, and our superclasses
  1087. // for methods
  1088. MethodInfo rv;
  1089. rv = matchMethod(methods(), name, params, dimensions);
  1090. if (rv != null) {
  1091. return rv;
  1092. }
  1093. // for constructors
  1094. rv = matchMethod(constructors(), name, params, dimensions);
  1095. if (rv != null) {
  1096. return rv;
  1097. }
  1098. // then recursively look at our containing class
  1099. ClassInfo containing = containingClass();
  1100. if (containing != null) {
  1101. return containing.findMethod(name, params, dimensions);
  1102. }
  1103. return null;
  1104. }
  1105. private ClassInfo searchInnerClasses(String[] nameParts, int index)
  1106. {
  1107. String part = nameParts[index];
  1108. ClassInfo[] inners = mInnerClasses;
  1109. for (ClassInfo in: inners) {
  1110. String[] innerParts = in.nameParts();
  1111. if (part.equals(innerParts[innerParts.length-1])) {
  1112. if (index == nameParts.length-1) {
  1113. return in;
  1114. } else {
  1115. return in.searchInnerClasses(nameParts, index+1);
  1116. }
  1117. }
  1118. }
  1119. return null;
  1120. }
  1121. public ClassInfo extendedFindClass(String className)
  1122. {
  1123. // ClassDoc.findClass has this bug that we're working around here:
  1124. // If you have a class PackageManager with an inner class PackageInfo
  1125. // and you call it with "PackageInfo" it doesn't find it.
  1126. return searchInnerClasses(className.split("\\."), 0);
  1127. }
  1128. public ClassInfo findClass(String className)
  1129. {
  1130. return Converter.obtainClass(mClass.findClass(className));
  1131. }
  1132. public ClassInfo findInnerClass(String className)
  1133. {
  1134. // ClassDoc.findClass won't find inner classes. To deal with that,
  1135. // we try what they gave us first, but if that didn't work, then
  1136. // we see if there are any periods in className, and start searching
  1137. // from there.
  1138. String[] nodes = className.split("\\.");
  1139. ClassDoc cl = mClass;
  1140. for (String n: nodes) {
  1141. cl = cl.findClass(n);
  1142. if (cl == null) {
  1143. return null;
  1144. }
  1145. }
  1146. return Converter.obtainClass(cl);
  1147. }
  1148. public FieldInfo findField(String name)
  1149. {
  1150. // first look on our class, and our superclasses
  1151. for (FieldInfo f: fields()) {
  1152. if (f.name().equals(name)) {
  1153. return f;
  1154. }
  1155. }
  1156. // then look at our enum constants (these are really fields, maybe
  1157. // they should be mixed into fields(). not sure)
  1158. for (FieldInfo f: enumConstants()) {
  1159. if (f.name().equals(name)) {
  1160. return f;
  1161. }
  1162. }
  1163. // then recursively look at our containing class
  1164. ClassInfo containing = containingClass();
  1165. if (containing != null) {
  1166. return containing.findField(name);
  1167. }
  1168. return null;
  1169. }
  1170. public static ClassInfo[] sortByName(ClassInfo[] classes)
  1171. {
  1172. int i;
  1173. Sorter[] sorted = new Sorter[classes.length];
  1174. for (i=0; i<sorted.length; i++) {
  1175. ClassInfo cl = classes[i];
  1176. sorted[i] = new Sorter(cl.name(), cl);
  1177. }
  1178. Arrays.sort(sorted);
  1179. ClassInfo[] rv = new ClassInfo[classes.length];
  1180. for (i=0; i<rv.length; i++) {
  1181. rv[i] = (ClassInfo)sorted[i].data;
  1182. }
  1183. return rv;
  1184. }
  1185. public boolean equals(ClassInfo that)
  1186. {
  1187. if (that != null) {
  1188. return this.qualifiedName().equals(that.qualifiedName());
  1189. } else {
  1190. return false;
  1191. }
  1192. }
  1193. public void setNonWrittenConstructors(MethodInfo[] nonWritten) {
  1194. mNonWrittenConstructors = nonWritten;
  1195. }
  1196. public MethodInfo[] getNonWrittenConstructors() {
  1197. return mNonWrittenConstructors;
  1198. }
  1199. public String kind()
  1200. {
  1201. if (isOrdinaryClass()) {
  1202. return "class";
  1203. }
  1204. else if (isInterface()) {
  1205. return "interface";
  1206. }
  1207. else if (isEnum()) {
  1208. return "enum";
  1209. }
  1210. else if (isError()) {
  1211. return "class";
  1212. }
  1213. else if (isException()) {
  1214. return "class";
  1215. }
  1216. else if (isAnnotation()) {
  1217. return "@interface";
  1218. }
  1219. return null;
  1220. }
  1221. public void setHiddenMethods(MethodInfo[] mInfo){
  1222. mHiddenMethods = mInfo;
  1223. }
  1224. public MethodInfo[] getHiddenMethods(){
  1225. return mHiddenMethods;
  1226. }
  1227. public String toString(){
  1228. return this.qualifiedName();
  1229. }
  1230. public void setReasonIncluded(String reason) {
  1231. mReasonIncluded = reason;
  1232. }
  1233. public String getReasonIncluded() {
  1234. return mReasonIncluded;
  1235. }
  1236. private ClassDoc mClass;
  1237. // ctor
  1238. private boolean mIsPublic;
  1239. private boolean mIsProtected;
  1240. private boolean mIsPackagePrivate;
  1241. private boolean mIsPrivate;
  1242. private boolean mIsStatic;
  1243. private boolean mIsInterface;
  1244. private boolean mIsAbstract;
  1245. private boolean mIsOrdinaryClass;
  1246. private boolean mIsException;
  1247. private boolean mIsError;
  1248. private boolean mIsEnum;
  1249. private boolean mIsAnnotation;
  1250. private boolean mIsFinal;
  1251. private boolean mIsIncluded;
  1252. private String mName;
  1253. private String mQualifiedName;
  1254. private String mQualifiedTypeName;
  1255. private boolean mIsPrimitive;
  1256. private TypeInfo mTypeInfo;
  1257. private String[] mNameParts;
  1258. // init
  1259. private ClassInfo[] mRealInterfaces;
  1260. private ClassInfo[] mInterfaces;
  1261. private TypeInfo[] mRealInterfaceTypes;
  1262. private ClassInfo[] mInnerClasses;
  1263. private MethodInfo[] mAllConstructors;
  1264. private MethodInfo[] mAllSelfMethods;
  1265. private MethodInfo[] mAnnotationElements; // if this class is an annotation
  1266. private FieldInfo[] mAllSelfFields;
  1267. private FieldInfo[] mEnumConstants;
  1268. private PackageInfo mContainingPackage;
  1269. private ClassInfo mContainingClass;
  1270. private ClassInfo mRealSuperclass;
  1271. private TypeInfo mRealSuperclassType;
  1272. private ClassInfo mSuperclass;
  1273. private AnnotationInstanceInfo[] mAnnotations;
  1274. private boolean mSuperclassInit;
  1275. private boolean mDeprecatedKnown;
  1276. // lazy
  1277. private MethodInfo[] mConstructors;
  1278. private ClassInfo[] mRealInnerClasses;
  1279. private MethodInfo[] mSelfMethods;
  1280. private FieldInfo[] mSelfFields;
  1281. private AttributeInfo[] mSelfAttributes;
  1282. private MethodInfo[] mMethods;
  1283. private FieldInfo[] mFields;
  1284. private TypeInfo[] mTypeParameters;
  1285. private MethodInfo[] mHiddenMethods;
  1286. private int mHidden = -1;
  1287. private int mCheckLevel = -1;
  1288. private String mReasonIncluded;
  1289. private MethodInfo[] mNonWrittenConstructors;
  1290. private boolean mIsDeprecated;
  1291. }