libjava/ChangeLog:
[official-gcc.git] / libjava / classpath / tools / gnu / classpath / tools / gjdoc / ExecutableMemberDocImpl.java
blob7dcdd25d215400029dcc6969363bbaca21275c89
1 /* gnu.classpath.tools.gjdoc.ExecutableMemberDocImpl
2 Copyright (C) 2001 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
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.
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.
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. */
21 package gnu.classpath.tools.gjdoc;
23 import java.util.*;
24 import java.io.*;
25 import com.sun.javadoc.*;
27 public class ExecutableMemberDocImpl extends MemberDocImpl implements ExecutableMemberDoc {
29 protected ExecutableMemberDocImpl(ClassDoc containingClass,
30 PackageDoc containingPackage,
31 SourcePosition position) {
33 super(containingClass,
34 containingPackage,
35 position);
38 protected boolean processModifier(String word) {
39 if (super.processModifier(word)) {
40 return true;
42 else if (word.equals("synchronized")) {
43 isSynchronized=true;
44 return true;
46 else if (word.equals("native")) {
47 isNative=true;
48 return true;
50 else if (word.equals("abstract")) {
51 isAbstract=true;
52 return true;
54 else {
55 return false;
59 private boolean isAbstract=false;
60 private boolean isNative=false;
61 private boolean isSynchronized=false;
63 public boolean isAbstract() { return isAbstract; }
65 public boolean isNative() { return isNative; }
67 public boolean isSynchronized() { return isSynchronized; }
69 public ClassDoc[] thrownExceptions() { return thrownExceptions; }
71 public Parameter[] parameters() { return parameters; }
73 public ThrowsTag[] throwsTags() {
74 return (ThrowsTag[])getTagArr("throws", throwsTagEmptyArr);
77 public ParamTag[] paramTags() {
78 return (ParamTag[])getTagArr("param", paramTagEmptyArr);
81 public String signature() { return signature; }
82 public String flatSignature() { return flatSignature; }
84 public ClassDoc overriddenClass() {
85 for (ClassDoc cdi=(ClassDoc)containingClass().superclass(); cdi!=null; cdi=(ClassDoc)cdi.superclass()) {
86 if (null!=ClassDocImpl.findMethod(cdi, name(), signature()))
87 return cdi;
89 return null;
92 public static ExecutableMemberDocImpl createFromSource(ClassDoc containingClass,
93 PackageDoc containingPackage,
94 char[] source, int startIndex, int endIndex) throws IOException, ParseException {
96 int lastchar=32;
97 StringBuffer methodName=new StringBuffer();
98 for (int i=startIndex; i<endIndex && source[i]!='('; ++i) {
99 if ((Parser.WHITESPACE.indexOf(lastchar)>=0 && Parser.WHITESPACE.indexOf(source[i])<0)
100 || (lastchar == ']' && Parser.WHITESPACE.indexOf(source[i])<0 && '[' != source[i])) {
101 methodName.setLength(0);
102 methodName.append(source[i]);
104 else if (Parser.WHITESPACE.indexOf(source[i])<0) {
105 methodName.append(source[i]);
107 lastchar=source[i];
110 ExecutableMemberDocImpl rc;
112 SourcePosition position = DocImpl.getPosition(containingClass, source, startIndex);
114 if (methodName.toString().equals(((ClassDocImpl)containingClass).getClassName())) {
116 // Constructor
118 rc=new ConstructorDocImpl(containingClass,
119 containingPackage,
120 position);
122 else {
124 // Normal method
126 rc=new MethodDocImpl(containingClass,
127 containingPackage,
128 position);
131 if (containingClass.isInterface())
132 rc.accessLevel=ACCESS_PUBLIC;
134 int ndx=rc.parseModifiers(source, startIndex, endIndex);
135 StringBuffer name = new StringBuffer();
137 final int STATE_NORMAL=1;
138 final int STATE_STARC=2;
139 final int STATE_SLASHC=3;
141 int state=STATE_NORMAL;
143 while (source[ndx]!='(' && ndx<endIndex) {
144 if (state==STATE_NORMAL) {
145 if (ndx<endIndex-1 && source[ndx]=='/' && source[ndx+1]=='/') {
146 ++ndx;
147 state=STATE_SLASHC;
149 else if (ndx<endIndex-1 && source[ndx]=='/' && source[ndx+1]=='*') {
150 ++ndx;
151 state=STATE_STARC;
153 else {
154 name.append(source[ndx]);
157 else if (state==STATE_SLASHC) {
158 if (source[ndx]=='\n')
159 state=STATE_NORMAL;
161 else if (state==STATE_STARC) {
162 if (ndx<endIndex-1 && source[ndx]=='*' && source[ndx+1]=='/') {
163 ++ndx;
164 state=STATE_NORMAL;
167 ++ndx;
169 rc.setName(name.toString().trim());
171 state=STATE_NORMAL;
173 ++ndx;
174 int endx;
175 String param="";
176 List parameterList=new ArrayList();
177 for (endx=ndx; endx<endIndex; ++endx) {
178 if (state==STATE_SLASHC) {
179 if (source[endx]=='\n') {
180 state=STATE_NORMAL;
183 else if (state==STATE_STARC) {
184 if (source[endx]=='*' && source[endx+1]=='/') {
185 state=STATE_NORMAL;
186 ++endx;
189 else if (source[endx]=='/' && source[endx+1]=='*') {
190 state=STATE_STARC;
191 ++endx;
193 else if (source[endx]=='/' && source[endx+1]=='/') {
194 state=STATE_SLASHC;
195 ++endx;
197 else if (source[endx]==',' || source[endx]==')') {
198 param=param.trim();
199 if (param.length()>0) {
200 int n = param.length()-1;
201 int paramNameStart = 0;
202 while (n >= 0) {
203 char c = param.charAt(n);
204 if ('[' == c || ']' == c || Parser.WHITESPACE.indexOf(c)>=0) {
205 paramNameStart = n + 1;
206 break;
208 else {
209 -- n;
212 while (n >= 0 && ('[' == param.charAt(n)
213 || ']' == param.charAt(n)
214 || Parser.WHITESPACE.indexOf(param.charAt(n))>=0)) {
215 -- n;
217 int paramTypeEnd = n + 1;
218 int paramTypeStart = 0;
219 while (n >= 0) {
220 char c = param.charAt(n);
221 if ('[' == c || ']' == c || Parser.WHITESPACE.indexOf(c)>=0) {
222 paramTypeStart = n + 1;
223 break;
225 else {
226 -- n;
230 String paramType;
231 String paramName;
232 if (0 != paramNameStart) {
233 paramType=param.substring(paramTypeStart, paramTypeEnd);
234 paramName=param.substring(paramNameStart);
236 else {
237 paramName = "";
238 StringBuffer paramTypeBuffer = new StringBuffer();
239 for (int i=0; i<param.length(); ++i) {
240 char c = param.charAt(i);
241 if ('[' != c && ']' != c && Parser.WHITESPACE.indexOf(c)<0) {
242 paramTypeBuffer.append(c);
245 paramType = paramTypeBuffer.toString();
247 String dimSuffix="";
249 for (int i=0; i<param.length(); ++i) {
250 if ('[' == param.charAt(i)) {
251 dimSuffix += "[]";
254 paramType+=dimSuffix;
256 if (paramType.startsWith("[")) {
257 System.err.println("broken param type in " + rc + " in " +containingClass);
260 parameterList.add(new ParameterImpl(paramName, paramType,
261 ((ClassDocImpl)containingClass).typeForString(paramType)));
263 param="";
266 else
267 param+=source[endx];
269 if (source[endx]==')' && state==STATE_NORMAL)
270 break;
273 rc.setParameters((Parameter[])parameterList.toArray(new Parameter[0]));
275 ++endx;
276 String word="";
277 String dimSuffix="";
278 boolean haveThrowsKeyword=false;
279 List thrownExceptionsList=new ArrayList();
281 state=STATE_NORMAL;
282 for (; endx<endIndex; ++endx) {
283 if (state==STATE_SLASHC) {
284 if (source[endx]=='\n') state=STATE_NORMAL;
286 else if (state==STATE_STARC) {
287 if (source[endx]=='*' && source[endx+1]=='/') {
288 state=STATE_NORMAL;
289 ++endx;
292 else if (source[endx]=='/' && source[endx+1]=='*') {
293 state=STATE_STARC;
294 ++endx;
296 else if (source[endx]=='/' && source[endx+1]=='/') {
297 state=STATE_SLASHC;
298 ++endx;
300 else if (Parser.WHITESPACE.indexOf(source[endx])>=0) {
301 word=word.trim();
302 if (!haveThrowsKeyword && word.length()>0) {
303 if (word.equals("throws")) haveThrowsKeyword=true;
304 else System.err.println("ARGH! "+word);
305 word="";
308 else if (source[endx]=='[' || source[endx]==']') {
309 dimSuffix += source[endx];
311 else if (source[endx]==',' || source[endx]=='{' || source[endx]==';') {
312 word=word.trim();
313 if (word.length()>0) {
314 ClassDoc exceptionType=rc.containingClass().findClass(word);
315 if (exceptionType==null) {
316 exceptionType=new ClassDocProxy(word,
317 rc.containingClass());
319 thrownExceptionsList.add(exceptionType);
321 if (source[endx]=='{') {
322 break;
324 else {
325 word="";
328 else {
329 word+=source[endx];
333 if (dimSuffix.length()>0) {
334 rc.setTypeName(rc.getTypeName()+dimSuffix);
337 rc.setThrownExceptions((ClassDoc[])thrownExceptionsList.toArray(new ClassDoc[0]));
339 return rc;
342 private ClassDoc[] thrownExceptions;
343 private Parameter[] parameters;
344 private String signature;
345 private String flatSignature;
347 void setParameters(Parameter[] parameters) {
348 this.parameters=parameters;
351 void setThrownExceptions(ClassDoc[] thrownExceptions) {
352 this.thrownExceptions=thrownExceptions;
355 void resolve() {
357 for (int i=0; i<thrownExceptions.length; ++i) {
358 if (thrownExceptions[i] instanceof ClassDocProxy) {
359 String className=thrownExceptions[i].qualifiedName();
360 ClassDoc realClassDoc=containingClass().findClass(className);
361 if (realClassDoc!=null)
362 thrownExceptions[i]=realClassDoc;
366 StringBuffer signatureBuf=new StringBuffer();
367 StringBuffer flatSignatureBuf=new StringBuffer();
369 for (int i=0; i<parameters.length; ++i) {
370 ((ParameterImpl)parameters[i]).resolve(containingClass());
372 if (signatureBuf.length()>0) {
373 signatureBuf.append(",");
374 flatSignatureBuf.append(",");
376 signatureBuf.append(parameters[i].type().qualifiedTypeName());
377 flatSignatureBuf.append(parameters[i].type().typeName());
378 signatureBuf.append(parameters[i].type().dimension());
379 flatSignatureBuf.append(parameters[i].type().dimension());
381 this.signature="("+signatureBuf.toString()+")";
382 this.flatSignature="("+flatSignatureBuf.toString()+")";
384 super.resolve();
388 public int compareTo(Object other) {
389 int rc;
390 if (other instanceof MemberDocImpl) {
391 MemberDocImpl otherMember = (MemberDocImpl)other;
392 rc = name().compareTo(otherMember.name());
393 if (0 == rc) {
394 if (other instanceof ExecutableMemberDocImpl) {
395 rc = signature().compareTo(((ExecutableMemberDocImpl)other).signature());
396 if (0 == rc) {
397 return containingClass().compareTo(otherMember.containingClass());
400 else {
401 rc = 1;
405 else {
406 rc = 1;
408 return rc;