blob: 57d78fb128f775632f12ea1c60b8768158259680 [file] [log] [blame]
The Android Open Source Project88b60792009-03-03 19:28:42 -08001/*
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
17import com.sun.javadoc.*;
18
19import org.clearsilver.HDF;
20
21import java.util.*;
22import java.io.*;
23import java.lang.reflect.Proxy;
24import java.lang.reflect.Array;
25import java.lang.reflect.InvocationHandler;
26import java.lang.reflect.InvocationTargetException;
27import java.lang.reflect.Method;
28
29public class DroidDoc
30{
31 private static final String SDK_CONSTANT_ANNOTATION = "android.annotation.SdkConstant";
32 private static final String SDK_CONSTANT_TYPE_ACTIVITY_ACTION = "android.annotation.SdkConstant.SdkConstantType.ACTIVITY_INTENT_ACTION";
33 private static final String SDK_CONSTANT_TYPE_BROADCAST_ACTION = "android.annotation.SdkConstant.SdkConstantType.BROADCAST_INTENT_ACTION";
34 private static final String SDK_CONSTANT_TYPE_SERVICE_ACTION = "android.annotation.SdkConstant.SdkConstantType.SERVICE_INTENT_ACTION";
35 private static final String SDK_CONSTANT_TYPE_CATEGORY = "android.annotation.SdkConstant.SdkConstantType.INTENT_CATEGORY";
Xavier Ducrohetf9b6d382009-12-14 17:55:05 -080036 private static final String SDK_CONSTANT_TYPE_FEATURE = "android.annotation.SdkConstant.SdkConstantType.FEATURE";
The Android Open Source Project88b60792009-03-03 19:28:42 -080037 private static final String SDK_WIDGET_ANNOTATION = "android.annotation.Widget";
38 private static final String SDK_LAYOUT_ANNOTATION = "android.annotation.Layout";
39
40 private static final int TYPE_NONE = 0;
41 private static final int TYPE_WIDGET = 1;
42 private static final int TYPE_LAYOUT = 2;
43 private static final int TYPE_LAYOUT_PARAM = 3;
Xavier Ducrohet5ee390d2009-09-10 13:08:27 -070044
The Android Open Source Project88b60792009-03-03 19:28:42 -080045 public static final int SHOW_PUBLIC = 0x00000001;
46 public static final int SHOW_PROTECTED = 0x00000003;
47 public static final int SHOW_PACKAGE = 0x00000007;
48 public static final int SHOW_PRIVATE = 0x0000000f;
49 public static final int SHOW_HIDDEN = 0x0000001f;
50
51 public static int showLevel = SHOW_PROTECTED;
52
53 public static final String javadocDir = "reference/";
54 public static String htmlExtension;
55
56 public static RootDoc root;
57 public static ArrayList<String[]> mHDFData = new ArrayList<String[]>();
58 public static Map<Character,String> escapeChars = new HashMap<Character,String>();
59 public static String title = "";
Scott Main25fda192009-08-04 11:26:30 -070060 public static SinceTagger sinceTagger = new SinceTagger();
The Android Open Source Project88b60792009-03-03 19:28:42 -080061
Joe Onorato0ee89a72010-08-31 11:27:25 -070062 private static boolean parseComments = false;
63 private static boolean generateDocs = true;
64
65 /**
66 * Returns true if we should parse javadoc comments,
67 * reporting errors in the process.
68 */
69 public static boolean parseComments() {
70 return generateDocs || parseComments;
71 }
72
The Android Open Source Project88b60792009-03-03 19:28:42 -080073 public static boolean checkLevel(int level)
74 {
75 return (showLevel & level) == level;
76 }
77
78 public static boolean checkLevel(boolean pub, boolean prot, boolean pkgp,
79 boolean priv, boolean hidden)
80 {
81 int level = 0;
82 if (hidden && !checkLevel(SHOW_HIDDEN)) {
83 return false;
84 }
85 if (pub && checkLevel(SHOW_PUBLIC)) {
86 return true;
87 }
88 if (prot && checkLevel(SHOW_PROTECTED)) {
89 return true;
90 }
91 if (pkgp && checkLevel(SHOW_PACKAGE)) {
92 return true;
93 }
94 if (priv && checkLevel(SHOW_PRIVATE)) {
95 return true;
96 }
97 return false;
98 }
Xavier Ducrohet5ee390d2009-09-10 13:08:27 -070099
The Android Open Source Project88b60792009-03-03 19:28:42 -0800100 public static boolean start(RootDoc r)
101 {
102 String keepListFile = null;
103 String proofreadFile = null;
104 String todoFile = null;
105 String sdkValuePath = null;
106 ArrayList<SampleCode> sampleCodes = new ArrayList<SampleCode>();
107 String stubsDir = null;
108 //Create the dependency graph for the stubs directory
109 boolean apiXML = false;
Scott Main2fa99f12009-11-20 10:41:49 -0800110 boolean offlineMode = false;
The Android Open Source Project88b60792009-03-03 19:28:42 -0800111 String apiFile = null;
112 String debugStubsFile = "";
113 HashSet<String> stubPackages = null;
114
115 root = r;
116
117 String[][] options = r.options();
118 for (String[] a: options) {
119 if (a[0].equals("-d")) {
120 ClearPage.outputDir = a[1];
121 }
122 else if (a[0].equals("-templatedir")) {
123 ClearPage.addTemplateDir(a[1]);
124 }
125 else if (a[0].equals("-hdf")) {
126 mHDFData.add(new String[] {a[1], a[2]});
127 }
128 else if (a[0].equals("-toroot")) {
129 ClearPage.toroot = a[1];
130 }
131 else if (a[0].equals("-samplecode")) {
132 sampleCodes.add(new SampleCode(a[1], a[2], a[3]));
133 }
134 else if (a[0].equals("-htmldir")) {
Bill Napier0e143c02010-08-24 22:16:01 -0700135 ClearPage.htmlDirs.add(a[1]);
The Android Open Source Project88b60792009-03-03 19:28:42 -0800136 }
137 else if (a[0].equals("-title")) {
138 DroidDoc.title = a[1];
139 }
140 else if (a[0].equals("-werror")) {
141 Errors.setWarningsAreErrors(true);
142 }
143 else if (a[0].equals("-error") || a[0].equals("-warning")
144 || a[0].equals("-hide")) {
145 try {
146 int level = -1;
147 if (a[0].equals("-error")) {
148 level = Errors.ERROR;
149 }
150 else if (a[0].equals("-warning")) {
151 level = Errors.WARNING;
152 }
153 else if (a[0].equals("-hide")) {
154 level = Errors.HIDDEN;
155 }
156 Errors.setErrorLevel(Integer.parseInt(a[1]), level);
157 }
158 catch (NumberFormatException e) {
159 // already printed below
160 return false;
161 }
162 }
163 else if (a[0].equals("-keeplist")) {
164 keepListFile = a[1];
165 }
166 else if (a[0].equals("-proofread")) {
167 proofreadFile = a[1];
168 }
169 else if (a[0].equals("-todo")) {
170 todoFile = a[1];
171 }
172 else if (a[0].equals("-public")) {
173 showLevel = SHOW_PUBLIC;
174 }
175 else if (a[0].equals("-protected")) {
176 showLevel = SHOW_PROTECTED;
177 }
178 else if (a[0].equals("-package")) {
179 showLevel = SHOW_PACKAGE;
180 }
181 else if (a[0].equals("-private")) {
182 showLevel = SHOW_PRIVATE;
183 }
184 else if (a[0].equals("-hidden")) {
185 showLevel = SHOW_HIDDEN;
186 }
187 else if (a[0].equals("-stubs")) {
188 stubsDir = a[1];
189 }
190 else if (a[0].equals("-stubpackages")) {
191 stubPackages = new HashSet();
192 for (String pkg: a[1].split(":")) {
193 stubPackages.add(pkg);
194 }
195 }
196 else if (a[0].equals("-sdkvalues")) {
197 sdkValuePath = a[1];
198 }
199 else if (a[0].equals("-apixml")) {
200 apiXML = true;
201 apiFile = a[1];
202 }
Joe Onoratob7c41aa2009-07-20 11:57:59 -0400203 else if (a[0].equals("-nodocs")) {
Joe Onorato0ee89a72010-08-31 11:27:25 -0700204 generateDocs = false;
205 }
206 else if (a[0].equals("-parsecomments")) {
207 parseComments = true;
Joe Onoratob7c41aa2009-07-20 11:57:59 -0400208 }
Jesse Wilson5e0dd412009-06-01 17:59:44 -0700209 else if (a[0].equals("-since")) {
210 sinceTagger.addVersion(a[1], a[2]);
211 }
Scott Main2fa99f12009-11-20 10:41:49 -0800212 else if (a[0].equals("-offlinemode")) {
213 offlineMode = true;
214 }
The Android Open Source Project88b60792009-03-03 19:28:42 -0800215 }
216
217 // read some prefs from the template
218 if (!readTemplateSettings()) {
219 return false;
220 }
221
222 // Set up the data structures
223 Converter.makeInfo(r);
224
Joe Onorato0ee89a72010-08-31 11:27:25 -0700225 if (generateDocs) {
Joe Onoratob7c41aa2009-07-20 11:57:59 -0400226 long startTime = System.nanoTime();
227
Jesse Wilson5e0dd412009-06-01 17:59:44 -0700228 // Apply @since tags from the XML file
229 sinceTagger.tagAll(Converter.rootClasses());
230
Joe Onoratob7c41aa2009-07-20 11:57:59 -0400231 // Files for proofreading
232 if (proofreadFile != null) {
233 Proofread.initProofread(proofreadFile);
234 }
235 if (todoFile != null) {
236 TodoFile.writeTodoFile(todoFile);
237 }
238
239 // HTML Pages
Bill Napier0e143c02010-08-24 22:16:01 -0700240 if (!ClearPage.htmlDirs.isEmpty()) {
Joe Onoratob7c41aa2009-07-20 11:57:59 -0400241 writeHTMLPages();
242 }
243
244 // Navigation tree
245 NavTree.writeNavTree(javadocDir);
246
247 // Packages Pages
248 writePackages(javadocDir
Bill Napier0e143c02010-08-24 22:16:01 -0700249 + (!ClearPage.htmlDirs.isEmpty()
Joe Onoratob7c41aa2009-07-20 11:57:59 -0400250 ? "packages" + htmlExtension
251 : "index" + htmlExtension));
252
253 // Classes
254 writeClassLists();
255 writeClasses();
256 writeHierarchy();
257 // writeKeywords();
258
259 // Lists for JavaScript
260 writeLists();
261 if (keepListFile != null) {
262 writeKeepList(keepListFile);
263 }
264
265 // Sample Code
266 for (SampleCode sc: sampleCodes) {
Scott Main2fa99f12009-11-20 10:41:49 -0800267 sc.write(offlineMode);
Joe Onoratob7c41aa2009-07-20 11:57:59 -0400268 }
269
270 // Index page
271 writeIndex();
272
273 Proofread.finishProofread(proofreadFile);
274
275 if (sdkValuePath != null) {
276 writeSdkValues(sdkValuePath);
277 }
278
279 long time = System.nanoTime() - startTime;
280 System.out.println("DroidDoc took " + (time / 1000000000) + " sec. to write docs to "
281 + ClearPage.outputDir);
The Android Open Source Project88b60792009-03-03 19:28:42 -0800282 }
The Android Open Source Project88b60792009-03-03 19:28:42 -0800283
284 // Stubs
285 if (stubsDir != null) {
286 Stubs.writeStubs(stubsDir, apiXML, apiFile, stubPackages);
287 }
Jesse Wilson5e0dd412009-06-01 17:59:44 -0700288
The Android Open Source Project88b60792009-03-03 19:28:42 -0800289 Errors.printErrors();
290 return !Errors.hadError;
291 }
292
293 private static void writeIndex() {
294 HDF data = makeHDF();
295 ClearPage.write(data, "index.cs", javadocDir + "index" + htmlExtension);
296 }
297
298 private static boolean readTemplateSettings()
299 {
300 HDF data = makeHDF();
301 htmlExtension = data.getValue("template.extension", ".html");
302 int i=0;
303 while (true) {
304 String k = data.getValue("template.escape." + i + ".key", "");
305 String v = data.getValue("template.escape." + i + ".value", "");
306 if ("".equals(k)) {
307 break;
308 }
309 if (k.length() != 1) {
310 System.err.println("template.escape." + i + ".key must have a length of 1: " + k);
311 return false;
312 }
313 escapeChars.put(k.charAt(0), v);
314 i++;
315 }
316 return true;
317 }
318
319 public static String escape(String s) {
320 if (escapeChars.size() == 0) {
321 return s;
322 }
323 StringBuffer b = null;
324 int begin = 0;
325 final int N = s.length();
326 for (int i=0; i<N; i++) {
327 char c = s.charAt(i);
328 String mapped = escapeChars.get(c);
329 if (mapped != null) {
330 if (b == null) {
331 b = new StringBuffer(s.length() + mapped.length());
332 }
333 if (begin != i) {
334 b.append(s.substring(begin, i));
335 }
336 b.append(mapped);
337 begin = i+1;
338 }
339 }
340 if (b != null) {
341 if (begin != N) {
342 b.append(s.substring(begin, N));
343 }
344 return b.toString();
345 }
346 return s;
347 }
348
349 public static void setPageTitle(HDF data, String title)
350 {
351 String s = title;
352 if (DroidDoc.title.length() > 0) {
353 s += " - " + DroidDoc.title;
354 }
355 data.setValue("page.title", s);
356 }
357
358 public static LanguageVersion languageVersion()
359 {
360 return LanguageVersion.JAVA_1_5;
361 }
362
363 public static int optionLength(String option)
364 {
365 if (option.equals("-d")) {
366 return 2;
367 }
368 if (option.equals("-templatedir")) {
369 return 2;
370 }
371 if (option.equals("-hdf")) {
372 return 3;
373 }
374 if (option.equals("-toroot")) {
375 return 2;
376 }
377 if (option.equals("-samplecode")) {
378 return 4;
379 }
380 if (option.equals("-htmldir")) {
381 return 2;
382 }
383 if (option.equals("-title")) {
384 return 2;
385 }
386 if (option.equals("-werror")) {
387 return 1;
388 }
389 if (option.equals("-hide")) {
390 return 2;
391 }
392 if (option.equals("-warning")) {
393 return 2;
394 }
395 if (option.equals("-error")) {
396 return 2;
397 }
398 if (option.equals("-keeplist")) {
399 return 2;
400 }
401 if (option.equals("-proofread")) {
402 return 2;
403 }
404 if (option.equals("-todo")) {
405 return 2;
406 }
407 if (option.equals("-public")) {
408 return 1;
409 }
410 if (option.equals("-protected")) {
411 return 1;
412 }
413 if (option.equals("-package")) {
414 return 1;
415 }
416 if (option.equals("-private")) {
417 return 1;
418 }
419 if (option.equals("-hidden")) {
420 return 1;
421 }
422 if (option.equals("-stubs")) {
423 return 2;
424 }
425 if (option.equals("-stubpackages")) {
426 return 2;
427 }
428 if (option.equals("-sdkvalues")) {
429 return 2;
430 }
431 if (option.equals("-apixml")) {
432 return 2;
433 }
Joe Onoratob7c41aa2009-07-20 11:57:59 -0400434 if (option.equals("-nodocs")) {
435 return 1;
436 }
Jesse Wilson5e0dd412009-06-01 17:59:44 -0700437 if (option.equals("-since")) {
438 return 3;
439 }
Scott Main2fa99f12009-11-20 10:41:49 -0800440 if (option.equals("-offlinemode")) {
441 return 1;
442 }
The Android Open Source Project88b60792009-03-03 19:28:42 -0800443 return 0;
444 }
Jesse Wilson5e0dd412009-06-01 17:59:44 -0700445
The Android Open Source Project88b60792009-03-03 19:28:42 -0800446 public static boolean validOptions(String[][] options, DocErrorReporter r)
447 {
448 for (String[] a: options) {
449 if (a[0].equals("-error") || a[0].equals("-warning")
450 || a[0].equals("-hide")) {
451 try {
452 Integer.parseInt(a[1]);
453 }
454 catch (NumberFormatException e) {
455 r.printError("bad -" + a[0] + " value must be a number: "
456 + a[1]);
457 return false;
458 }
459 }
460 }
461
462 return true;
463 }
464
465 public static HDF makeHDF()
466 {
467 HDF data = new HDF();
468
469 for (String[] p: mHDFData) {
470 data.setValue(p[0], p[1]);
471 }
472
473 try {
474 for (String p: ClearPage.hdfFiles) {
475 data.readFile(p);
476 }
477 }
478 catch (IOException e) {
479 throw new RuntimeException(e);
480 }
481
482 return data;
483 }
484
485 public static HDF makePackageHDF()
486 {
487 HDF data = makeHDF();
488 ClassInfo[] classes = Converter.rootClasses();
489
490 SortedMap<String, PackageInfo> sorted = new TreeMap<String, PackageInfo>();
491 for (ClassInfo cl: classes) {
492 PackageInfo pkg = cl.containingPackage();
493 String name;
494 if (pkg == null) {
495 name = "";
496 } else {
497 name = pkg.name();
498 }
499 sorted.put(name, pkg);
500 }
501
502 int i = 0;
503 for (String s: sorted.keySet()) {
504 PackageInfo pkg = sorted.get(s);
505
506 if (pkg.isHidden()) {
507 continue;
508 }
509 Boolean allHidden = true;
510 int pass = 0;
511 ClassInfo[] classesToCheck = null;
512 while (pass < 5 ) {
513 switch(pass) {
514 case 0:
515 classesToCheck = pkg.ordinaryClasses();
516 break;
517 case 1:
518 classesToCheck = pkg.enums();
519 break;
520 case 2:
521 classesToCheck = pkg.errors();
522 break;
523 case 3:
524 classesToCheck = pkg.exceptions();
525 break;
526 case 4:
527 classesToCheck = pkg.interfaces();
528 break;
529 default:
530 System.err.println("Error reading package: " + pkg.name());
531 break;
532 }
533 for (ClassInfo cl : classesToCheck) {
534 if (!cl.isHidden()) {
535 allHidden = false;
536 break;
537 }
538 }
539 if (!allHidden) {
540 break;
541 }
542 pass++;
543 }
544 if (allHidden) {
545 continue;
546 }
547
548 data.setValue("reference", "true");
549 data.setValue("docs.packages." + i + ".name", s);
550 data.setValue("docs.packages." + i + ".link", pkg.htmlPage());
Scott Maindf094242009-07-27 09:47:11 -0700551 data.setValue("docs.packages." + i + ".since", pkg.getSince());
The Android Open Source Project88b60792009-03-03 19:28:42 -0800552 TagInfo.makeHDF(data, "docs.packages." + i + ".shortDescr",
553 pkg.firstSentenceTags());
554 i++;
555 }
556
Scott Main25fda192009-08-04 11:26:30 -0700557 sinceTagger.writeVersionNames(data);
The Android Open Source Project88b60792009-03-03 19:28:42 -0800558 return data;
559 }
560
561 public static void writeDirectory(File dir, String relative)
562 {
563 File[] files = dir.listFiles();
564 int i, count = files.length;
565 for (i=0; i<count; i++) {
566 File f = files[i];
567 if (f.isFile()) {
568 String templ = relative + f.getName();
569 int len = templ.length();
570 if (len > 3 && ".cs".equals(templ.substring(len-3))) {
571 HDF data = makeHDF();
572 String filename = templ.substring(0,len-3) + htmlExtension;
573 ClearPage.write(data, templ, filename);
574 }
575 else if (len > 3 && ".jd".equals(templ.substring(len-3))) {
576 String filename = templ.substring(0,len-3) + htmlExtension;
577 DocFile.writePage(f.getAbsolutePath(), relative, filename);
578 }
579 else {
580 ClearPage.copyFile(f, templ);
581 }
582 }
583 else if (f.isDirectory()) {
584 writeDirectory(f, relative + f.getName() + "/");
585 }
586 }
587 }
588
589 public static void writeHTMLPages()
590 {
Bill Napier0e143c02010-08-24 22:16:01 -0700591 for (String htmlDir : ClearPage.htmlDirs) {
592 File f = new File(htmlDir);
593 if (!f.isDirectory()) {
594 System.err.println("htmlDir not a directory: " + htmlDir);
Bill Napier10cd7f92010-08-25 09:59:14 -0700595 continue;
Bill Napier0e143c02010-08-24 22:16:01 -0700596 }
597 writeDirectory(f, "");
The Android Open Source Project88b60792009-03-03 19:28:42 -0800598 }
The Android Open Source Project88b60792009-03-03 19:28:42 -0800599 }
600
601 public static void writeLists()
602 {
603 HDF data = makeHDF();
604
605 ClassInfo[] classes = Converter.rootClasses();
606
607 SortedMap<String, Object> sorted = new TreeMap<String, Object>();
608 for (ClassInfo cl: classes) {
609 if (cl.isHidden()) {
610 continue;
611 }
612 sorted.put(cl.qualifiedName(), cl);
613 PackageInfo pkg = cl.containingPackage();
614 String name;
615 if (pkg == null) {
616 name = "";
617 } else {
618 name = pkg.name();
619 }
620 sorted.put(name, pkg);
621 }
622
623 int i = 0;
624 for (String s: sorted.keySet()) {
625 data.setValue("docs.pages." + i + ".id" , ""+i);
626 data.setValue("docs.pages." + i + ".label" , s);
627
628 Object o = sorted.get(s);
629 if (o instanceof PackageInfo) {
630 PackageInfo pkg = (PackageInfo)o;
631 data.setValue("docs.pages." + i + ".link" , pkg.htmlPage());
632 data.setValue("docs.pages." + i + ".type" , "package");
633 }
634 else if (o instanceof ClassInfo) {
635 ClassInfo cl = (ClassInfo)o;
636 data.setValue("docs.pages." + i + ".link" , cl.htmlPage());
637 data.setValue("docs.pages." + i + ".type" , "class");
638 }
639 i++;
640 }
641
642 ClearPage.write(data, "lists.cs", javadocDir + "lists.js");
643 }
644
645 public static void cantStripThis(ClassInfo cl, HashSet<ClassInfo> notStrippable) {
646 if (!notStrippable.add(cl)) {
647 // slight optimization: if it already contains cl, it already contains
648 // all of cl's parents
649 return;
650 }
651 ClassInfo supr = cl.superclass();
652 if (supr != null) {
653 cantStripThis(supr, notStrippable);
654 }
655 for (ClassInfo iface: cl.interfaces()) {
656 cantStripThis(iface, notStrippable);
657 }
658 }
659
660 private static String getPrintableName(ClassInfo cl) {
661 ClassInfo containingClass = cl.containingClass();
662 if (containingClass != null) {
663 // This is an inner class.
664 String baseName = cl.name();
665 baseName = baseName.substring(baseName.lastIndexOf('.') + 1);
666 return getPrintableName(containingClass) + '$' + baseName;
667 }
668 return cl.qualifiedName();
669 }
670
671 /**
672 * Writes the list of classes that must be present in order to
673 * provide the non-hidden APIs known to javadoc.
674 *
675 * @param filename the path to the file to write the list to
676 */
677 public static void writeKeepList(String filename) {
678 HashSet<ClassInfo> notStrippable = new HashSet<ClassInfo>();
679 ClassInfo[] all = Converter.allClasses();
680 Arrays.sort(all); // just to make the file a little more readable
681
682 // If a class is public and not hidden, then it and everything it derives
683 // from cannot be stripped. Otherwise we can strip it.
684 for (ClassInfo cl: all) {
685 if (cl.isPublic() && !cl.isHidden()) {
686 cantStripThis(cl, notStrippable);
687 }
688 }
689 PrintStream stream = null;
690 try {
691 stream = new PrintStream(filename);
692 for (ClassInfo cl: notStrippable) {
693 stream.println(getPrintableName(cl));
694 }
695 }
696 catch (FileNotFoundException e) {
697 System.err.println("error writing file: " + filename);
698 }
699 finally {
700 if (stream != null) {
701 stream.close();
702 }
703 }
704 }
705
706 private static PackageInfo[] sVisiblePackages = null;
707 public static PackageInfo[] choosePackages() {
708 if (sVisiblePackages != null) {
709 return sVisiblePackages;
710 }
711
712 ClassInfo[] classes = Converter.rootClasses();
713 SortedMap<String, PackageInfo> sorted = new TreeMap<String, PackageInfo>();
714 for (ClassInfo cl: classes) {
715 PackageInfo pkg = cl.containingPackage();
716 String name;
717 if (pkg == null) {
718 name = "";
719 } else {
720 name = pkg.name();
721 }
722 sorted.put(name, pkg);
723 }
724
725 ArrayList<PackageInfo> result = new ArrayList();
726
727 for (String s: sorted.keySet()) {
728 PackageInfo pkg = sorted.get(s);
729
730 if (pkg.isHidden()) {
731 continue;
732 }
733 Boolean allHidden = true;
734 int pass = 0;
735 ClassInfo[] classesToCheck = null;
736 while (pass < 5 ) {
737 switch(pass) {
738 case 0:
739 classesToCheck = pkg.ordinaryClasses();
740 break;
741 case 1:
742 classesToCheck = pkg.enums();
743 break;
744 case 2:
745 classesToCheck = pkg.errors();
746 break;
747 case 3:
748 classesToCheck = pkg.exceptions();
749 break;
750 case 4:
751 classesToCheck = pkg.interfaces();
752 break;
753 default:
754 System.err.println("Error reading package: " + pkg.name());
755 break;
756 }
757 for (ClassInfo cl : classesToCheck) {
758 if (!cl.isHidden()) {
759 allHidden = false;
760 break;
761 }
762 }
763 if (!allHidden) {
764 break;
765 }
766 pass++;
767 }
768 if (allHidden) {
769 continue;
770 }
771
772 result.add(pkg);
773 }
774
775 sVisiblePackages = result.toArray(new PackageInfo[result.size()]);
776 return sVisiblePackages;
777 }
778
779 public static void writePackages(String filename)
780 {
781 HDF data = makePackageHDF();
782
783 int i = 0;
784 for (PackageInfo pkg: choosePackages()) {
785 writePackage(pkg);
786
787 data.setValue("docs.packages." + i + ".name", pkg.name());
788 data.setValue("docs.packages." + i + ".link", pkg.htmlPage());
789 TagInfo.makeHDF(data, "docs.packages." + i + ".shortDescr",
790 pkg.firstSentenceTags());
791
792 i++;
793 }
794
795 setPageTitle(data, "Package Index");
796
797 TagInfo.makeHDF(data, "root.descr",
798 Converter.convertTags(root.inlineTags(), null));
799
800 ClearPage.write(data, "packages.cs", filename);
801 ClearPage.write(data, "package-list.cs", javadocDir + "package-list");
802
803 Proofread.writePackages(filename,
804 Converter.convertTags(root.inlineTags(), null));
805 }
806
807 public static void writePackage(PackageInfo pkg)
808 {
809 // these this and the description are in the same directory,
810 // so it's okay
811 HDF data = makePackageHDF();
812
813 String name = pkg.name();
814
815 data.setValue("package.name", name);
Jesse Wilson5e0dd412009-06-01 17:59:44 -0700816 data.setValue("package.since", pkg.getSince());
The Android Open Source Project88b60792009-03-03 19:28:42 -0800817 data.setValue("package.descr", "...description...");
818
Xavier Ducrohet5ee390d2009-09-10 13:08:27 -0700819 makeClassListHDF(data, "package.interfaces",
The Android Open Source Project88b60792009-03-03 19:28:42 -0800820 ClassInfo.sortByName(pkg.interfaces()));
821 makeClassListHDF(data, "package.classes",
822 ClassInfo.sortByName(pkg.ordinaryClasses()));
823 makeClassListHDF(data, "package.enums",
824 ClassInfo.sortByName(pkg.enums()));
825 makeClassListHDF(data, "package.exceptions",
826 ClassInfo.sortByName(pkg.exceptions()));
827 makeClassListHDF(data, "package.errors",
828 ClassInfo.sortByName(pkg.errors()));
829 TagInfo.makeHDF(data, "package.shortDescr",
830 pkg.firstSentenceTags());
831 TagInfo.makeHDF(data, "package.descr", pkg.inlineTags());
832
833 String filename = pkg.htmlPage();
834 setPageTitle(data, name);
835 ClearPage.write(data, "package.cs", filename);
836
837 filename = pkg.fullDescriptionHtmlPage();
838 setPageTitle(data, name + " Details");
839 ClearPage.write(data, "package-descr.cs", filename);
840
841 Proofread.writePackage(filename, pkg.inlineTags());
842 }
843
844 public static void writeClassLists()
845 {
846 int i;
847 HDF data = makePackageHDF();
848
849 ClassInfo[] classes = PackageInfo.filterHidden(
850 Converter.convertClasses(root.classes()));
851 if (classes.length == 0) {
852 return ;
853 }
854
855 Sorter[] sorted = new Sorter[classes.length];
856 for (i=0; i<sorted.length; i++) {
857 ClassInfo cl = classes[i];
858 String name = cl.name();
859 sorted[i] = new Sorter(name, cl);
860 }
861
862 Arrays.sort(sorted);
863
864 // make a pass and resolve ones that have the same name
865 int firstMatch = 0;
866 String lastName = sorted[0].label;
867 for (i=1; i<sorted.length; i++) {
868 String s = sorted[i].label;
869 if (!lastName.equals(s)) {
870 if (firstMatch != i-1) {
871 // there were duplicates
872 for (int j=firstMatch; j<i; j++) {
873 PackageInfo pkg = ((ClassInfo)sorted[j].data).containingPackage();
874 if (pkg != null) {
875 sorted[j].label = sorted[j].label + " (" + pkg.name() + ")";
876 }
877 }
878 }
879 firstMatch = i;
880 lastName = s;
881 }
882 }
883
884 // and sort again
885 Arrays.sort(sorted);
886
887 for (i=0; i<sorted.length; i++) {
888 String s = sorted[i].label;
889 ClassInfo cl = (ClassInfo)sorted[i].data;
890 char first = Character.toUpperCase(s.charAt(0));
891 cl.makeShortDescrHDF(data, "docs.classes." + first + '.' + i);
892 }
893
894 setPageTitle(data, "Class Index");
895 ClearPage.write(data, "classes.cs", javadocDir + "classes" + htmlExtension);
896 }
897
898 // we use the word keywords because "index" means something else in html land
899 // the user only ever sees the word index
900/* public static void writeKeywords()
901 {
902 ArrayList<KeywordEntry> keywords = new ArrayList<KeywordEntry>();
903
904 ClassInfo[] classes = PackageInfo.filterHidden(Converter.convertClasses(root.classes()));
905
906 for (ClassInfo cl: classes) {
907 cl.makeKeywordEntries(keywords);
908 }
909
910 HDF data = makeHDF();
911
912 Collections.sort(keywords);
Xavier Ducrohet5ee390d2009-09-10 13:08:27 -0700913
The Android Open Source Project88b60792009-03-03 19:28:42 -0800914 int i=0;
915 for (KeywordEntry entry: keywords) {
916 String base = "keywords." + entry.firstChar() + "." + i;
917 entry.makeHDF(data, base);
918 i++;
919 }
920
921 setPageTitle(data, "Index");
922 ClearPage.write(data, "keywords.cs", javadocDir + "keywords" + htmlExtension);
923 } */
924
925 public static void writeHierarchy()
926 {
927 ClassInfo[] classes = Converter.rootClasses();
928 ArrayList<ClassInfo> info = new ArrayList<ClassInfo>();
929 for (ClassInfo cl: classes) {
930 if (!cl.isHidden()) {
931 info.add(cl);
932 }
933 }
934 HDF data = makePackageHDF();
935 Hierarchy.makeHierarchy(data, info.toArray(new ClassInfo[info.size()]));
936 setPageTitle(data, "Class Hierarchy");
937 ClearPage.write(data, "hierarchy.cs", javadocDir + "hierarchy" + htmlExtension);
938 }
939
940 public static void writeClasses()
941 {
942 ClassInfo[] classes = Converter.rootClasses();
943
944 for (ClassInfo cl: classes) {
945 HDF data = makePackageHDF();
946 if (!cl.isHidden()) {
947 writeClass(cl, data);
948 }
949 }
950 }
951
952 public static void writeClass(ClassInfo cl, HDF data)
953 {
954 cl.makeHDF(data);
955
956 setPageTitle(data, cl.name());
957 ClearPage.write(data, "class.cs", cl.htmlPage());
958
959 Proofread.writeClass(cl.htmlPage(), cl);
960 }
961
962 public static void makeClassListHDF(HDF data, String base,
963 ClassInfo[] classes)
964 {
965 for (int i=0; i<classes.length; i++) {
966 ClassInfo cl = classes[i];
967 if (!cl.isHidden()) {
968 cl.makeShortDescrHDF(data, base + "." + i);
969 }
970 }
971 }
972
973 public static String linkTarget(String source, String target)
974 {
975 String[] src = source.split("/");
976 String[] tgt = target.split("/");
977
978 int srclen = src.length;
979 int tgtlen = tgt.length;
980
981 int same = 0;
982 while (same < (srclen-1)
983 && same < (tgtlen-1)
984 && (src[same].equals(tgt[same]))) {
985 same++;
986 }
987
988 String s = "";
989
990 int up = srclen-same-1;
991 for (int i=0; i<up; i++) {
992 s += "../";
993 }
994
995
996 int N = tgtlen-1;
997 for (int i=same; i<N; i++) {
998 s += tgt[i] + '/';
999 }
1000 s += tgt[tgtlen-1];
1001
1002 return s;
1003 }
1004
1005 /**
Xavier Ducrohet02e14df2009-09-10 14:50:12 -07001006 * Returns true if the given element has an @hide or @pending annotation.
The Android Open Source Project88b60792009-03-03 19:28:42 -08001007 */
1008 private static boolean hasHideAnnotation(Doc doc) {
Xavier Ducrohet02e14df2009-09-10 14:50:12 -07001009 String comment = doc.getRawCommentText();
1010 return comment.indexOf("@hide") != -1 || comment.indexOf("@pending") != -1;
The Android Open Source Project88b60792009-03-03 19:28:42 -08001011 }
1012
1013 /**
1014 * Returns true if the given element is hidden.
1015 */
1016 private static boolean isHidden(Doc doc) {
1017 // Methods, fields, constructors.
1018 if (doc instanceof MemberDoc) {
1019 return hasHideAnnotation(doc);
1020 }
1021
1022 // Classes, interfaces, enums, annotation types.
1023 if (doc instanceof ClassDoc) {
1024 ClassDoc classDoc = (ClassDoc) doc;
1025
1026 // Check the containing package.
1027 if (hasHideAnnotation(classDoc.containingPackage())) {
1028 return true;
1029 }
1030
1031 // Check the class doc and containing class docs if this is a
1032 // nested class.
1033 ClassDoc current = classDoc;
1034 do {
1035 if (hasHideAnnotation(current)) {
1036 return true;
1037 }
1038
1039 current = current.containingClass();
1040 } while (current != null);
1041 }
1042
1043 return false;
1044 }
1045
1046 /**
1047 * Filters out hidden elements.
1048 */
1049 private static Object filterHidden(Object o, Class<?> expected) {
1050 if (o == null) {
1051 return null;
1052 }
1053
1054 Class type = o.getClass();
1055 if (type.getName().startsWith("com.sun.")) {
1056 // TODO: Implement interfaces from superclasses, too.
1057 return Proxy.newProxyInstance(type.getClassLoader(),
1058 type.getInterfaces(), new HideHandler(o));
1059 } else if (o instanceof Object[]) {
1060 Class<?> componentType = expected.getComponentType();
1061 Object[] array = (Object[]) o;
1062 List<Object> list = new ArrayList<Object>(array.length);
1063 for (Object entry : array) {
1064 if ((entry instanceof Doc) && isHidden((Doc) entry)) {
1065 continue;
1066 }
1067 list.add(filterHidden(entry, componentType));
1068 }
1069 return list.toArray(
1070 (Object[]) Array.newInstance(componentType, list.size()));
1071 } else {
1072 return o;
1073 }
1074 }
1075
1076 /**
1077 * Filters hidden elements out of method return values.
1078 */
1079 private static class HideHandler implements InvocationHandler {
1080
1081 private final Object target;
1082
1083 public HideHandler(Object target) {
1084 this.target = target;
1085 }
1086
1087 public Object invoke(Object proxy, Method method, Object[] args)
1088 throws Throwable {
1089 String methodName = method.getName();
1090 if (args != null) {
1091 if (methodName.equals("compareTo") ||
1092 methodName.equals("equals") ||
1093 methodName.equals("overrides") ||
1094 methodName.equals("subclassOf")) {
1095 args[0] = unwrap(args[0]);
1096 }
1097 }
1098
1099 if (methodName.equals("getRawCommentText")) {
1100 return filterComment((String) method.invoke(target, args));
1101 }
Xavier Ducrohet5ee390d2009-09-10 13:08:27 -07001102
The Android Open Source Project88b60792009-03-03 19:28:42 -08001103 // escape "&" in disjunctive types.
1104 if (proxy instanceof Type && methodName.equals("toString")) {
1105 return ((String) method.invoke(target, args))
1106 .replace("&", "&amp;");
1107 }
1108
1109 try {
1110 return filterHidden(method.invoke(target, args),
1111 method.getReturnType());
1112 } catch (InvocationTargetException e) {
1113 throw e.getTargetException();
1114 }
1115 }
1116
1117 private String filterComment(String s) {
1118 if (s == null) {
1119 return null;
1120 }
1121
1122 s = s.trim();
1123
1124 // Work around off by one error
1125 while (s.length() >= 5
1126 && s.charAt(s.length() - 5) == '{') {
1127 s += "&nbsp;";
1128 }
1129
1130 return s;
1131 }
1132
1133 private static Object unwrap(Object proxy) {
1134 if (proxy instanceof Proxy)
1135 return ((HideHandler)Proxy.getInvocationHandler(proxy)).target;
1136 return proxy;
1137 }
1138 }
1139
1140 public static String scope(Scoped scoped) {
1141 if (scoped.isPublic()) {
1142 return "public";
1143 }
1144 else if (scoped.isProtected()) {
1145 return "protected";
1146 }
1147 else if (scoped.isPackagePrivate()) {
1148 return "";
1149 }
1150 else if (scoped.isPrivate()) {
1151 return "private";
1152 }
1153 else {
1154 throw new RuntimeException("invalid scope for object " + scoped);
1155 }
1156 }
Xavier Ducrohet5ee390d2009-09-10 13:08:27 -07001157
The Android Open Source Project88b60792009-03-03 19:28:42 -08001158 /**
1159 * Collect the values used by the Dev tools and write them in files packaged with the SDK
1160 * @param output the ouput directory for the files.
1161 */
1162 private static void writeSdkValues(String output) {
1163 ArrayList<String> activityActions = new ArrayList<String>();
1164 ArrayList<String> broadcastActions = new ArrayList<String>();
1165 ArrayList<String> serviceActions = new ArrayList<String>();
1166 ArrayList<String> categories = new ArrayList<String>();
Xavier Ducrohetf9b6d382009-12-14 17:55:05 -08001167 ArrayList<String> features = new ArrayList<String>();
Xavier Ducrohet5ee390d2009-09-10 13:08:27 -07001168
The Android Open Source Project88b60792009-03-03 19:28:42 -08001169 ArrayList<ClassInfo> layouts = new ArrayList<ClassInfo>();
1170 ArrayList<ClassInfo> widgets = new ArrayList<ClassInfo>();
1171 ArrayList<ClassInfo> layoutParams = new ArrayList<ClassInfo>();
Xavier Ducrohet5ee390d2009-09-10 13:08:27 -07001172
The Android Open Source Project88b60792009-03-03 19:28:42 -08001173 ClassInfo[] classes = Converter.allClasses();
1174
1175 // Go through all the fields of all the classes, looking SDK stuff.
1176 for (ClassInfo clazz : classes) {
Xavier Ducrohet5ee390d2009-09-10 13:08:27 -07001177
The Android Open Source Project88b60792009-03-03 19:28:42 -08001178 // first check constant fields for the SdkConstant annotation.
1179 FieldInfo[] fields = clazz.allSelfFields();
1180 for (FieldInfo field : fields) {
1181 Object cValue = field.constantValue();
1182 if (cValue != null) {
1183 AnnotationInstanceInfo[] annotations = field.annotations();
1184 if (annotations.length > 0) {
1185 for (AnnotationInstanceInfo annotation : annotations) {
1186 if (SDK_CONSTANT_ANNOTATION.equals(annotation.type().qualifiedName())) {
1187 AnnotationValueInfo[] values = annotation.elementValues();
1188 if (values.length > 0) {
1189 String type = values[0].valueString();
1190 if (SDK_CONSTANT_TYPE_ACTIVITY_ACTION.equals(type)) {
1191 activityActions.add(cValue.toString());
1192 } else if (SDK_CONSTANT_TYPE_BROADCAST_ACTION.equals(type)) {
1193 broadcastActions.add(cValue.toString());
1194 } else if (SDK_CONSTANT_TYPE_SERVICE_ACTION.equals(type)) {
1195 serviceActions.add(cValue.toString());
1196 } else if (SDK_CONSTANT_TYPE_CATEGORY.equals(type)) {
1197 categories.add(cValue.toString());
Xavier Ducrohetf9b6d382009-12-14 17:55:05 -08001198 } else if (SDK_CONSTANT_TYPE_FEATURE.equals(type)) {
1199 features.add(cValue.toString());
The Android Open Source Project88b60792009-03-03 19:28:42 -08001200 }
1201 }
1202 break;
1203 }
1204 }
1205 }
1206 }
1207 }
Xavier Ducrohet5ee390d2009-09-10 13:08:27 -07001208
The Android Open Source Project88b60792009-03-03 19:28:42 -08001209 // Now check the class for @Widget or if its in the android.widget package
1210 // (unless the class is hidden or abstract, or non public)
1211 if (clazz.isHidden() == false && clazz.isPublic() && clazz.isAbstract() == false) {
1212 boolean annotated = false;
1213 AnnotationInstanceInfo[] annotations = clazz.annotations();
1214 if (annotations.length > 0) {
1215 for (AnnotationInstanceInfo annotation : annotations) {
1216 if (SDK_WIDGET_ANNOTATION.equals(annotation.type().qualifiedName())) {
1217 widgets.add(clazz);
1218 annotated = true;
1219 break;
1220 } else if (SDK_LAYOUT_ANNOTATION.equals(annotation.type().qualifiedName())) {
1221 layouts.add(clazz);
1222 annotated = true;
1223 break;
1224 }
1225 }
1226 }
Xavier Ducrohet5ee390d2009-09-10 13:08:27 -07001227
The Android Open Source Project88b60792009-03-03 19:28:42 -08001228 if (annotated == false) {
1229 // lets check if this is inside android.widget
1230 PackageInfo pckg = clazz.containingPackage();
1231 String packageName = pckg.name();
1232 if ("android.widget".equals(packageName) ||
1233 "android.view".equals(packageName)) {
1234 // now we check what this class inherits either from android.view.ViewGroup
1235 // or android.view.View, or android.view.ViewGroup.LayoutParams
1236 int type = checkInheritance(clazz);
1237 switch (type) {
1238 case TYPE_WIDGET:
1239 widgets.add(clazz);
1240 break;
1241 case TYPE_LAYOUT:
1242 layouts.add(clazz);
1243 break;
1244 case TYPE_LAYOUT_PARAM:
1245 layoutParams.add(clazz);
1246 break;
1247 }
1248 }
1249 }
1250 }
1251 }
1252
1253 // now write the files, whether or not the list are empty.
1254 // the SDK built requires those files to be present.
1255
1256 Collections.sort(activityActions);
1257 writeValues(output + "/activity_actions.txt", activityActions);
1258
1259 Collections.sort(broadcastActions);
1260 writeValues(output + "/broadcast_actions.txt", broadcastActions);
1261
1262 Collections.sort(serviceActions);
1263 writeValues(output + "/service_actions.txt", serviceActions);
1264
1265 Collections.sort(categories);
1266 writeValues(output + "/categories.txt", categories);
Xavier Ducrohet5ee390d2009-09-10 13:08:27 -07001267
Xavier Ducrohetf9b6d382009-12-14 17:55:05 -08001268 Collections.sort(features);
1269 writeValues(output + "/features.txt", features);
1270
The Android Open Source Project88b60792009-03-03 19:28:42 -08001271 // before writing the list of classes, we do some checks, to make sure the layout params
1272 // are enclosed by a layout class (and not one that has been declared as a widget)
1273 for (int i = 0 ; i < layoutParams.size();) {
1274 ClassInfo layoutParamClass = layoutParams.get(i);
1275 ClassInfo containingClass = layoutParamClass.containingClass();
1276 if (containingClass == null || layouts.indexOf(containingClass) == -1) {
1277 layoutParams.remove(i);
1278 } else {
1279 i++;
1280 }
1281 }
Xavier Ducrohet5ee390d2009-09-10 13:08:27 -07001282
The Android Open Source Project88b60792009-03-03 19:28:42 -08001283 writeClasses(output + "/widgets.txt", widgets, layouts, layoutParams);
1284 }
Xavier Ducrohet5ee390d2009-09-10 13:08:27 -07001285
The Android Open Source Project88b60792009-03-03 19:28:42 -08001286 /**
1287 * Writes a list of values into a text files.
1288 * @param pathname the absolute os path of the output file.
1289 * @param values the list of values to write.
1290 */
1291 private static void writeValues(String pathname, ArrayList<String> values) {
1292 FileWriter fw = null;
1293 BufferedWriter bw = null;
1294 try {
1295 fw = new FileWriter(pathname, false);
1296 bw = new BufferedWriter(fw);
Xavier Ducrohet5ee390d2009-09-10 13:08:27 -07001297
The Android Open Source Project88b60792009-03-03 19:28:42 -08001298 for (String value : values) {
1299 bw.append(value).append('\n');
1300 }
1301 } catch (IOException e) {
1302 // pass for now
1303 } finally {
1304 try {
1305 if (bw != null) bw.close();
1306 } catch (IOException e) {
1307 // pass for now
1308 }
1309 try {
1310 if (fw != null) fw.close();
1311 } catch (IOException e) {
1312 // pass for now
1313 }
1314 }
1315 }
1316
1317 /**
1318 * Writes the widget/layout/layout param classes into a text files.
1319 * @param pathname the absolute os path of the output file.
1320 * @param widgets the list of widget classes to write.
1321 * @param layouts the list of layout classes to write.
1322 * @param layoutParams the list of layout param classes to write.
1323 */
1324 private static void writeClasses(String pathname, ArrayList<ClassInfo> widgets,
1325 ArrayList<ClassInfo> layouts, ArrayList<ClassInfo> layoutParams) {
1326 FileWriter fw = null;
1327 BufferedWriter bw = null;
1328 try {
1329 fw = new FileWriter(pathname, false);
1330 bw = new BufferedWriter(fw);
Xavier Ducrohet5ee390d2009-09-10 13:08:27 -07001331
The Android Open Source Project88b60792009-03-03 19:28:42 -08001332 // write the 3 types of classes.
1333 for (ClassInfo clazz : widgets) {
1334 writeClass(bw, clazz, 'W');
1335 }
1336 for (ClassInfo clazz : layoutParams) {
1337 writeClass(bw, clazz, 'P');
1338 }
1339 for (ClassInfo clazz : layouts) {
1340 writeClass(bw, clazz, 'L');
1341 }
1342 } catch (IOException e) {
1343 // pass for now
1344 } finally {
1345 try {
1346 if (bw != null) bw.close();
1347 } catch (IOException e) {
1348 // pass for now
1349 }
1350 try {
1351 if (fw != null) fw.close();
1352 } catch (IOException e) {
1353 // pass for now
1354 }
1355 }
1356 }
1357
1358 /**
1359 * Writes a class name and its super class names into a {@link BufferedWriter}.
1360 * @param writer the BufferedWriter to write into
1361 * @param clazz the class to write
1362 * @param prefix the prefix to put at the beginning of the line.
1363 * @throws IOException
1364 */
1365 private static void writeClass(BufferedWriter writer, ClassInfo clazz, char prefix)
1366 throws IOException {
1367 writer.append(prefix).append(clazz.qualifiedName());
1368 ClassInfo superClass = clazz;
1369 while ((superClass = superClass.superclass()) != null) {
1370 writer.append(' ').append(superClass.qualifiedName());
1371 }
1372 writer.append('\n');
1373 }
Xavier Ducrohet5ee390d2009-09-10 13:08:27 -07001374
The Android Open Source Project88b60792009-03-03 19:28:42 -08001375 /**
1376 * Checks the inheritance of {@link ClassInfo} objects. This method return
1377 * <ul>
1378 * <li>{@link #TYPE_LAYOUT}: if the class extends <code>android.view.ViewGroup</code></li>
1379 * <li>{@link #TYPE_WIDGET}: if the class extends <code>android.view.View</code></li>
1380 * <li>{@link #TYPE_LAYOUT_PARAM}: if the class extends <code>android.view.ViewGroup$LayoutParams</code></li>
1381 * <li>{@link #TYPE_NONE}: in all other cases</li>
Xavier Ducrohet5ee390d2009-09-10 13:08:27 -07001382 * </ul>
The Android Open Source Project88b60792009-03-03 19:28:42 -08001383 * @param clazz the {@link ClassInfo} to check.
1384 */
1385 private static int checkInheritance(ClassInfo clazz) {
1386 if ("android.view.ViewGroup".equals(clazz.qualifiedName())) {
1387 return TYPE_LAYOUT;
1388 } else if ("android.view.View".equals(clazz.qualifiedName())) {
1389 return TYPE_WIDGET;
1390 } else if ("android.view.ViewGroup.LayoutParams".equals(clazz.qualifiedName())) {
1391 return TYPE_LAYOUT_PARAM;
1392 }
Xavier Ducrohet5ee390d2009-09-10 13:08:27 -07001393
The Android Open Source Project88b60792009-03-03 19:28:42 -08001394 ClassInfo parent = clazz.superclass();
1395 if (parent != null) {
1396 return checkInheritance(parent);
1397 }
Xavier Ducrohet5ee390d2009-09-10 13:08:27 -07001398
The Android Open Source Project88b60792009-03-03 19:28:42 -08001399 return TYPE_NONE;
1400 }
1401}