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)
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
21 package gnu
.classpath
.tools
.gjdoc
;
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
,
38 protected boolean processModifier(String word
) {
39 if (super.processModifier(word
)) {
42 else if (word
.equals("synchronized")) {
46 else if (word
.equals("native")) {
50 else if (word
.equals("abstract")) {
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()))
92 public static ExecutableMemberDocImpl
createFromSource(ClassDoc containingClass
,
93 PackageDoc containingPackage
,
94 char[] source
, int startIndex
, int endIndex
) throws IOException
, ParseException
{
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
]);
110 ExecutableMemberDocImpl rc
;
112 SourcePosition position
= DocImpl
.getPosition(containingClass
, source
, startIndex
);
114 if (methodName
.toString().equals(((ClassDocImpl
)containingClass
).getClassName())) {
118 rc
=new ConstructorDocImpl(containingClass
,
126 rc
=new MethodDocImpl(containingClass
,
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]=='/') {
149 else if (ndx
<endIndex
-1 && source
[ndx
]=='/' && source
[ndx
+1]=='*') {
154 name
.append(source
[ndx
]);
157 else if (state
==STATE_SLASHC
) {
158 if (source
[ndx
]=='\n')
161 else if (state
==STATE_STARC
) {
162 if (ndx
<endIndex
-1 && source
[ndx
]=='*' && source
[ndx
+1]=='/') {
169 rc
.setName(name
.toString().trim());
176 List parameterList
=new ArrayList();
177 for (endx
=ndx
; endx
<endIndex
; ++endx
) {
178 if (state
==STATE_SLASHC
) {
179 if (source
[endx
]=='\n') {
183 else if (state
==STATE_STARC
) {
184 if (source
[endx
]=='*' && source
[endx
+1]=='/') {
189 else if (source
[endx
]=='/' && source
[endx
+1]=='*') {
193 else if (source
[endx
]=='/' && source
[endx
+1]=='/') {
197 else if (source
[endx
]==',' || source
[endx
]==')') {
199 if (param
.length()>0) {
200 int n
= param
.length()-1;
201 int paramNameStart
= 0;
203 char c
= param
.charAt(n
);
204 if ('[' == c
|| ']' == c
|| Parser
.WHITESPACE
.indexOf(c
)>=0) {
205 paramNameStart
= n
+ 1;
212 while (n
>= 0 && ('[' == param
.charAt(n
)
213 || ']' == param
.charAt(n
)
214 || Parser
.WHITESPACE
.indexOf(param
.charAt(n
))>=0)) {
217 int paramTypeEnd
= n
+ 1;
218 int paramTypeStart
= 0;
220 char c
= param
.charAt(n
);
221 if ('[' == c
|| ']' == c
|| Parser
.WHITESPACE
.indexOf(c
)>=0) {
222 paramTypeStart
= n
+ 1;
232 if (0 != paramNameStart
) {
233 paramType
=param
.substring(paramTypeStart
, paramTypeEnd
);
234 paramName
=param
.substring(paramNameStart
);
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();
249 for (int i
=0; i
<param
.length(); ++i
) {
250 if ('[' == param
.charAt(i
)) {
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
)));
269 if (source
[endx
]==')' && state
==STATE_NORMAL
)
273 rc
.setParameters((Parameter
[])parameterList
.toArray(new Parameter
[0]));
278 boolean haveThrowsKeyword
=false;
279 List thrownExceptionsList
=new ArrayList();
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]=='/') {
292 else if (source
[endx
]=='/' && source
[endx
+1]=='*') {
296 else if (source
[endx
]=='/' && source
[endx
+1]=='/') {
300 else if (Parser
.WHITESPACE
.indexOf(source
[endx
])>=0) {
302 if (!haveThrowsKeyword
&& word
.length()>0) {
303 if (word
.equals("throws")) haveThrowsKeyword
=true;
304 else System
.err
.println("ARGH! "+word
);
308 else if (source
[endx
]=='[' || source
[endx
]==']') {
309 dimSuffix
+= source
[endx
];
311 else if (source
[endx
]==',' || source
[endx
]=='{' || source
[endx
]==';') {
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
]=='{') {
333 if (dimSuffix
.length()>0) {
334 rc
.setTypeName(rc
.getTypeName()+dimSuffix
);
337 rc
.setThrownExceptions((ClassDoc
[])thrownExceptionsList
.toArray(new ClassDoc
[0]));
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
;
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()+")";
388 public int compareTo(Object other
) {
390 if (other
instanceof MemberDocImpl
) {
391 MemberDocImpl otherMember
= (MemberDocImpl
)other
;
392 rc
= name().compareTo(otherMember
.name());
394 if (other
instanceof ExecutableMemberDocImpl
) {
395 rc
= signature().compareTo(((ExecutableMemberDocImpl
)other
).signature());
397 return containingClass().compareTo(otherMember
.containingClass());