OSDN Git Service

libjava/ChangeLog:
[pf3gnuchains/gcc-fork.git] / libjava / classpath / tools / gnu / classpath / tools / gjdoc / PackageDocImpl.java
1 /* gnu.classpath.tools.gjdoc.PackageDocImpl
2    Copyright (C) 2001 Free Software Foundation, Inc.
3
4 This file is part of GNU Classpath.
5
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10  
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING.  If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA. */
20
21 package gnu.classpath.tools.gjdoc;
22
23 import com.sun.javadoc.*;
24 import java.util.*;
25 import java.io.File;
26
27 class PackageDocImpl extends DocImpl implements GjdocPackageDoc {
28
29    private String packageName;
30    private File   packageDirectory;
31
32    private Set    allClassesSet       = new TreeSet();
33    private List   ordinaryClassesList = new ArrayList();
34    private List   exceptionsList      = new ArrayList();
35    private List   interfacesList      = new ArrayList();
36    private List   errorsList          = new ArrayList();   
37
38    private ClassDoc[] allClasses;
39    private ClassDoc[] ordinaryClasses;
40    private ClassDoc[] exceptions;
41    private ClassDoc[] interfaces;
42    private ClassDoc[] errors;
43
44    PackageDocImpl(String packageName) {
45       super(null);
46       this.packageName=packageName;
47    }
48
49    public void addClass(ClassDoc classDoc) {
50       if (Main.getInstance().includeAccessLevel(((ClassDocImpl)classDoc).accessLevel)) {
51          allClassesSet.add(classDoc);
52       }
53    }
54
55    public void resolve() {
56       for (Iterator it=allClassesSet.iterator(); it.hasNext(); ) {
57          ClassDocImpl classDoc=(ClassDocImpl)it.next();
58          try {
59              classDoc.resolve();
60          } catch (ParseException e) {
61              System.err.println("FIXME: add try-catch to force compilation"
62                                 + e);
63          }
64
65          if (classDoc.isInterface()) {
66             interfacesList.add(classDoc);
67          }
68          else if (classDoc.isException()) {
69             exceptionsList.add(classDoc);
70          }
71          else if (classDoc.isError()) {
72             errorsList.add(classDoc);
73          }
74          else {
75             ordinaryClassesList.add(classDoc);
76          }
77       }
78    }
79
80    public void resolveComments() {
81       if (rawDocumentation!=null) {
82          this.tagMap=parseCommentTags(rawDocumentation.toCharArray(),
83                                       0,
84                                       rawDocumentation.length(),
85                                       null,
86                                       null,
87                                       null,
88                                       null);
89       }
90
91       resolveTags();
92    }
93
94    public String name() { 
95       return packageName; 
96    }
97
98    public ClassDoc[] allClasses() 
99    { 
100       if (null == this.allClasses) {
101          this.allClasses = toClassDocArray(allClassesSet);
102       }
103       return this.allClasses;
104    }
105
106    public ClassDoc[] ordinaryClasses() 
107    { 
108       if (null == this.ordinaryClasses) {
109          this.ordinaryClasses = toClassDocArray(ordinaryClassesList);
110       }
111       return this.ordinaryClasses;
112    }
113
114
115    public ClassDoc[] exceptions() 
116    { 
117       if (null == this.exceptions) {
118          this.exceptions = toClassDocArray(exceptionsList);
119       }
120       return this.exceptions;
121    }
122
123    public ClassDoc[] interfaces() 
124    { 
125       if (null == this.interfaces) {
126          this.interfaces = toClassDocArray(interfacesList);
127       }
128       return this.interfaces;
129    }
130
131    public ClassDoc[] errors() 
132    { 
133       if (null == this.errors) {
134          this.errors = toClassDocArray(errorsList);
135       }
136       return this.errors;
137    }
138
139    private ClassDoc[] toClassDocArray(Collection classDocList)
140    {
141       ClassDoc[] result = (ClassDoc[])classDocList.toArray(new ClassDoc[classDocList.size()]);
142       Arrays.sort(result);
143       return result;
144    }
145
146    public ClassDoc findClass(String name) { 
147       return Main.getRootDoc().classNamed(packageName+"."+name);
148    }
149
150    public void dump(int level) {
151       Debug.log(level, "All classes:");
152       Debug.dumpArray(level, allClasses());
153
154       Debug.log(level, "Ordinary classes:");
155       Debug.dumpArray(level, ordinaryClasses());
156       
157    }
158
159    public static final PackageDocImpl DEFAULT_PACKAGE = new PackageDocImpl("");
160
161    public boolean isPackage() {
162       return true;
163    }
164
165    public boolean isIncluded() {
166       return isIncluded;
167    }
168
169    void setIsIncluded(boolean b) {
170       this.isIncluded=b;
171    }
172
173    private boolean isIncluded = false;
174
175    public String toString() {
176       return packageName;
177    }
178
179    public int compareTo(Object o) {
180       if (o!=null && o instanceof PackageDocImpl)
181          return name().compareTo(((PackageDocImpl)o).name());
182       else
183          return 0;
184    }
185
186    public boolean equals(Object o) {
187       if (o!=null && o instanceof PackageDocImpl)
188          return name().equals(((PackageDocImpl)o).name());
189       else
190          return false;
191    }
192
193    /**
194     *  Sets the directory containing this package's source files.
195     */
196    public void setPackageDirectory(File packageDirectory) {
197       this.packageDirectory = packageDirectory;
198    }
199
200    /**
201     *  Gets the directory containing this package's source files.
202     */
203    public File packageDirectory() {
204       return this.packageDirectory;
205    }
206 }