OSDN Git Service

libjava/ChangeLog:
[pf3gnuchains/gcc-fork.git] / libjava / classpath / tools / gnu / classpath / tools / gjdoc / MemberDocImpl.java
1 /* gnu.classpath.tools.gjdoc.MemberDocImpl
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 java.util.*;
24 import com.sun.javadoc.*;
25
26 public abstract class MemberDocImpl extends ProgramElementDocImpl implements MemberDoc {
27
28    protected String typeName;
29    protected Type   type;
30
31    public MemberDocImpl(ClassDoc containingClass,
32                         PackageDoc containingPackage,
33                         SourcePosition position) {
34
35       super(containingClass,
36             containingPackage,
37             position);
38    }
39
40    public String qualifiedName() {
41       return containingClass().qualifiedName()+"."+name();
42    }
43
44    public boolean isSynthetic() {
45       return false;
46    }
47
48    int parseModifiers(char[] source, int startIndex, int endIndex) {
49
50       Debug.log(9,"parseModifiers '"+new String(source,startIndex,endIndex-startIndex)+"'");
51
52       final int STATE_NORMAL = 1;
53       final int STATE_STARC  = 2;
54       final int STATE_SLASHC = 3;
55
56       int state = STATE_NORMAL;
57
58       StringBuffer word = new StringBuffer();
59       StringBuffer typeNameBuf = new StringBuffer();
60       int lastWordStart = startIndex;
61       int firstChar = 0;
62       int lastChar = 0;
63       for (; startIndex<endIndex; ++startIndex) {
64          if (state==STATE_STARC) {
65             if (startIndex<endIndex-1 && source[startIndex]=='*' && source[startIndex+1]=='/') {
66                ++startIndex;
67                state=STATE_NORMAL;
68             }
69          }
70          else if (state==STATE_SLASHC) {
71             if (source[startIndex]=='\n') {
72                state=STATE_NORMAL;
73             }
74          }
75          else if (startIndex<endIndex-1 && source[startIndex]=='/' && source[startIndex+1]=='*') {
76             ++startIndex;
77             state=STATE_STARC;
78          }
79          else if (source[startIndex]=='=' || source[startIndex]=='(' || source[startIndex]==';') {
80             typeName = typeNameBuf.toString();
81             return lastWordStart;
82          }
83          else if (Parser.WHITESPACE.indexOf(source[startIndex])>=0
84                   || (startIndex > 0 && source[startIndex-1] == ']' && source[startIndex] != '[')) {
85             if (word.length()>0 && lastChar != '.') {
86                if (processModifier(word.toString())) {
87                }
88                else if (typeNameBuf.length()==0 && !isConstructor()) {
89                   typeNameBuf.setLength(0);
90                   typeNameBuf.append(word);
91                }
92                else if ((firstChar=='[' || firstChar==']') && !isConstructor()) {
93                   typeNameBuf.append(word);
94                }
95                else {
96                   typeName = typeNameBuf.toString();
97                   return lastWordStart;
98                }
99                word.setLength(0);
100                lastWordStart=startIndex;
101             }
102          }
103          else {
104             if (lastWordStart<0) lastWordStart=startIndex;
105             lastChar = source[startIndex];
106             if (0 == word.length()) {
107                firstChar = lastChar;
108             }
109             word.append((char)lastChar);
110          }
111       }
112
113       typeName = typeNameBuf.toString();
114       return startIndex;
115    }
116
117     public Type type() {
118         //public Type type() throws ParseException { 
119         Debug.log(9,"type() called on "+containingClass()+"."+this);
120         if (type==null) {
121             try {
122                 type=((ClassDocImpl)containingClass()).typeForString(typeName);
123             } catch (ParseException e) {
124                System.err.println("FIXME: add try-catch to force compilation");
125                e.printStackTrace();
126             }
127         }
128         return type;
129     }
130
131
132    protected void setName(String name) {
133       this.name=name;
134    }
135    private String name;
136
137
138    public String name() {
139       return name;
140    }
141
142    public void setTypeName(String typeName) { 
143       this.typeName=typeName;
144       this.type=null;
145    }
146
147    public String getTypeName() {
148       return typeName;
149    }
150
151    // return true if this Doc is include in the active set. 
152    public boolean isIncluded() {
153       return Main.getInstance().includeAccessLevel(accessLevel);
154    } 
155
156    public int compareTo(Object o) {
157       if (o instanceof MemberDocImpl) {
158          int rc=name().compareTo(((MemberDocImpl)o).name());
159          if (rc==0) 
160             rc=containingClass().qualifiedName().compareTo(((MemberDocImpl)o).containingClass().qualifiedName());
161          return rc;
162       }
163       else {
164          return super.compareTo(o);
165       }
166    }
167
168    void resolve() {
169
170       if (type==null && typeName!=null) {
171          Debug.log(1, "MemberDocImpl.resolve(), looking up type named "+typeName);
172          try {
173             type=((ClassDocImpl)containingClass()).typeForString(typeName);
174          } catch (ParseException e) {
175             //System.err.println("FIXME: add try-catch to force compilation");
176             //e.printStackTrace();
177             Debug.log(1, "INTERNAL WARNING: Couldn't find type for name '"+typeName+"'");
178          }
179       }
180
181       if (type instanceof ClassDocProxy) {
182          String className=type.qualifiedTypeName();
183          ClassDoc realClassDoc=((ClassDocImpl)containingClass()).findClass(className, type.dimension());
184          if (realClassDoc!=null) {
185             type=realClassDoc;
186          }
187          else {
188             //throw new Error("Class not found: "+className);
189             /*** This is not an error, the class was not included
190              * on the command line. Perhaps emit a notice here.
191              *
192
193             Main.getRootDoc().printError("Class not found '"
194                                          + className
195                                          + "' in class '"
196                                          + containingClass().qualifiedName()
197                                          + "' member '"
198                                          + name()
199                                          + "'");
200             */
201          }
202       }
203    }
204
205    public void resolveComments()
206    {
207       super.resolveComments();
208
209       if (tagMap.isEmpty()) {
210          TagContainer inheritedTagMap = ClassDocImpl.findInheritedDoc(containingClass(),
211                                                                       this,
212                                                                       null);
213          if (null != inheritedTagMap) {
214             this.tagMap = inheritedTagMap.getTagMap();
215          }
216       }
217    }
218 }