• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 import com.sun.javadoc.*;
18 import com.sun.tools.doclets.*;
19 import org.clearsilver.HDF;
20 import org.clearsilver.CS;
21 import java.util.*;
22 import java.io.*;
23 
24 public class PackageInfo extends DocInfo implements ContainerInfo
25 {
26     public static final Comparator<PackageInfo> comparator = new Comparator<PackageInfo>() {
27         public int compare(PackageInfo a, PackageInfo b) {
28             return a.name().compareTo(b.name());
29         }
30     };
31 
PackageInfo(PackageDoc pkg, String name, SourcePositionInfo position)32     public PackageInfo(PackageDoc pkg, String name, SourcePositionInfo position)
33     {
34         super(pkg.getRawCommentText(), position);
35         mName = name;
36 
37         if (pkg == null) {
38             throw new RuntimeException("pkg is null");
39         }
40         mPackage = pkg;
41     }
42 
htmlPage()43     public String htmlPage()
44     {
45         String s = mName;
46         s = s.replace('.', '/');
47         s += "/package-summary.html";
48         s = DroidDoc.javadocDir + s;
49         return s;
50     }
51 
fullDescriptionHtmlPage()52     public String fullDescriptionHtmlPage() {
53         String s = mName;
54         s = s.replace('.', '/');
55         s += "/package-descr.html";
56         s = DroidDoc.javadocDir + s;
57         return s;
58     }
59 
60     @Override
parent()61     public ContainerInfo parent()
62     {
63         return null;
64     }
65 
66     @Override
isHidden()67     public boolean isHidden()
68     {
69         return comment().isHidden();
70     }
71 
checkLevel()72     public boolean checkLevel() {
73         // TODO should return false if all classes are hidden but the package isn't.
74         // We don't have this so I'm not doing it now.
75         return !isHidden();
76     }
77 
name()78     public String name()
79     {
80         return mName;
81     }
82 
qualifiedName()83     public String qualifiedName()
84     {
85         return mName;
86     }
87 
inlineTags()88     public TagInfo[] inlineTags()
89     {
90         return comment().tags();
91     }
92 
firstSentenceTags()93     public TagInfo[] firstSentenceTags()
94     {
95         return comment().briefTags();
96     }
97 
filterHidden(ClassInfo[] classes)98     public static ClassInfo[] filterHidden(ClassInfo[] classes)
99     {
100         ArrayList<ClassInfo> out = new ArrayList<ClassInfo>();
101 
102         for (ClassInfo cl: classes) {
103             if (!cl.isHidden()) {
104                 out.add(cl);
105             }
106         }
107 
108         return out.toArray(new ClassInfo[0]);
109     }
110 
makeLink(HDF data, String base)111     public void makeLink(HDF data, String base)
112     {
113         if (checkLevel()) {
114             data.setValue(base + ".link", htmlPage());
115         }
116         data.setValue(base + ".name", name());
117         data.setValue(base + ".since", getSince());
118     }
119 
makeClassLinkListHDF(HDF data, String base)120     public void makeClassLinkListHDF(HDF data, String base)
121     {
122         makeLink(data, base);
123         ClassInfo.makeLinkListHDF(data, base + ".interfaces", interfaces());
124         ClassInfo.makeLinkListHDF(data, base + ".classes", ordinaryClasses());
125         ClassInfo.makeLinkListHDF(data, base + ".enums", enums());
126         ClassInfo.makeLinkListHDF(data, base + ".exceptions", exceptions());
127         ClassInfo.makeLinkListHDF(data, base + ".errors", errors());
128         data.setValue(base + ".since", getSince());
129     }
130 
interfaces()131     public ClassInfo[] interfaces()
132     {
133         if (mInterfaces == null) {
134             mInterfaces = ClassInfo.sortByName(filterHidden(Converter.convertClasses(
135                             mPackage.interfaces())));
136         }
137         return mInterfaces;
138     }
139 
ordinaryClasses()140     public ClassInfo[] ordinaryClasses()
141     {
142         if (mOrdinaryClasses == null) {
143             mOrdinaryClasses = ClassInfo.sortByName(filterHidden(Converter.convertClasses(
144                             mPackage.ordinaryClasses())));
145         }
146         return mOrdinaryClasses;
147     }
148 
enums()149     public ClassInfo[] enums()
150     {
151         if (mEnums == null) {
152             mEnums = ClassInfo.sortByName(filterHidden(Converter.convertClasses(mPackage.enums())));
153         }
154         return mEnums;
155     }
156 
exceptions()157     public ClassInfo[] exceptions()
158     {
159         if (mExceptions == null) {
160             mExceptions = ClassInfo.sortByName(filterHidden(Converter.convertClasses(
161                         mPackage.exceptions())));
162         }
163         return mExceptions;
164     }
165 
errors()166     public ClassInfo[] errors()
167     {
168         if (mErrors == null) {
169             mErrors = ClassInfo.sortByName(filterHidden(Converter.convertClasses(
170                         mPackage.errors())));
171         }
172         return mErrors;
173     }
174 
175     // in hashed containers, treat the name as the key
176     @Override
hashCode()177     public int hashCode() {
178         return mName.hashCode();
179     }
180 
181     private String mName;
182     private PackageDoc mPackage;
183     private ClassInfo[] mInterfaces;
184     private ClassInfo[] mOrdinaryClasses;
185     private ClassInfo[] mEnums;
186     private ClassInfo[] mExceptions;
187     private ClassInfo[] mErrors;
188 }
189 
190