KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > tools > ajdoc > Util


1 /* -*- Mode: JDE; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2  *
3  * This file is part of the debugger and core tools for the AspectJ(tm)
4  * programming language; see http://aspectj.org
5  *
6  * The contents of this file are subject to the Mozilla Public License
7  * Version 1.1 (the "License"); you may not use this file except in
8  * compliance with the License. You may obtain a copy of the License at
9  * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/.
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the
14  * License.
15  *
16  * The Original Code is AspectJ.
17  *
18  * The Initial Developer of the Original Code is Xerox Corporation. Portions
19  * created by Xerox Corporation are Copyright (C) 1999-2002 Xerox Corporation.
20  * All Rights Reserved.
21  */

22 package org.aspectj.tools.ajdoc;
23
24 import org.aspectj.compiler.base.ast.Constructor;
25 import org.aspectj.compiler.base.ast.ConstructorDec;
26 import org.aspectj.compiler.base.ast.Exprs;
27 import org.aspectj.compiler.base.ast.Field;
28 import org.aspectj.compiler.base.ast.FieldDec;
29 import org.aspectj.compiler.base.ast.Formals;
30 import org.aspectj.compiler.base.ast.Method;
31 import org.aspectj.compiler.base.ast.MethodDec;
32 import org.aspectj.compiler.base.ast.NameType;
33 import org.aspectj.compiler.base.ast.Type;
34 import org.aspectj.compiler.base.ast.TypeDec;
35 import org.aspectj.compiler.crosscuts.ast.PointcutDec;
36 import org.aspectj.compiler.crosscuts.ast.PointcutSO;
37
38 import com.sun.javadoc.Doc;
39 import com.sun.javadoc.ExecutableMemberDoc;
40 import com.sun.javadoc.MemberDoc;
41 import com.sun.javadoc.Parameter;
42 import com.sun.javadoc.Tag;
43
44 import java.io.File JavaDoc;
45 import java.io.FileInputStream JavaDoc;
46 import java.io.IOException JavaDoc;
47 import java.io.InputStream JavaDoc;
48 import java.util.ArrayList JavaDoc;
49 import java.util.Collections JavaDoc;
50 import java.util.Comparator JavaDoc;
51 import java.util.Iterator JavaDoc;
52 import java.util.List JavaDoc;
53 import java.util.Locale JavaDoc;
54 import java.util.StringTokenizer JavaDoc;
55
56 /**
57  * A utility class used by lots of folks.
58  *
59  * @author Jeff Palm
60  */

61 public class Util {
62
63     /**
64      * Delegate to Character.isJavaIdentifierStart(char).
65      *
66      * @return <code>true</code> if <code>c</code> can
67      * start a java identifier.
68      */

69     public final static boolean start(char c) {
70         return Character.isJavaIdentifierStart(c);
71     }
72
73     /**
74      * Delegate to Character.isJavaIdentifierPart(char).
75      *
76      * @return <code>true</code> if <code>c</code> can
77      * be a part of a java identifier.
78      */

79     public final static boolean ident(char c) {
80         return Character.isJavaIdentifierPart(c);
81     }
82
83     /**
84      * Delegate to Character.isWhitespace(char).
85      *
86      * @return <code>true</code> if <code>c</code> is
87      * valid white space.
88      */

89     public final static boolean space(char c) {
90         return Character.isWhitespace(c);
91     }
92
93     /**
94      * Returns true is <code>c</code> is a newline character.
95      *
96      * @return <code>true</code> if
97      * <code>c == '\n' || c == '\r'</code>.
98      */

99     public final static boolean newline(char c) {
100         return c == '\n' || c == '\r';
101     }
102
103     /**
104      * Returns two strings split at the first white space.
105      *
106      * @return an array of two Strings split at
107      * the first white space.
108      */

109     public static String JavaDoc[] split(String JavaDoc str) {
110         String JavaDoc[] strs = new String JavaDoc[2];
111         for (int i = 0; i < str.length(); i++) {
112             if (space(str.charAt(i))) {
113                 strs[0] = str.substring(0, i);
114                 strs[1] = str.substring(i+1);
115                 break;
116             }
117         }
118         if (strs[0] == null) {
119             strs[0] = str;
120             strs[1] = "";
121         }
122         return strs;
123     }
124
125     /**
126      * Returns the inline tags found in <code>str</code>.
127      *
128      * @param doc Doc to give to the new tag.
129      * @param str String from which to create the tags.
130      * @param loc Locale to give to the new tag.
131      * @param err ErrPrinter to give to the new tag.
132      * @return an array of Tag representing the inline
133      * tags found in str.
134      */

135     public final static Tag[] inlineTags(Doc doc,
136                                          String JavaDoc str,
137                                          Locale JavaDoc loc,
138                                          ErrPrinter err) {
139         if (str == null || str.length() < 1) {
140             return new Tag[0];
141         }
142         
143         int N = str.length();
144
145         List JavaDoc list = new ArrayList JavaDoc();
146        
147         int i = 0;
148         for (int j = i; i < N; j = i) {
149             
150             // Try to match a link tag
151
int ileft = str.indexOf("{@", i);
152             
153             // If there are no more link tags, return the rest
154
// of str as a 'Text' Tag
155
if (ileft == -1) {
156                 list.add(new TagImpl(doc, "Text",
157                                      str.substring(i),
158                                      loc, err));
159                 break;
160             }
161
162             if (j < ileft) {
163                 list.add(new TagImpl(doc, "Text",
164                                      str.substring(j, ileft),
165                                      loc, err));
166             }
167
168             // If there is a tag and it's name is 'link ' try to
169
// match it
170
i = ileft;
171             if (i+7 < N &&
172                 str.substring(i+2, i+7).toLowerCase().equals("link ")) {
173                 i += 7;
174                 for (; str.charAt(i) != '}'; i++) {
175                     if (i == N-1) {
176                         err.error("tag_unterminated_link_tag",
177                                     str.substring(i));
178                         break;
179                     }
180                 }
181                 list.add(new SeeTagImpl(doc, "@link",
182                                         str.substring(ileft+7, i),
183                                         loc, err));
184             } else {
185                 err.error("tag_invalid_link_tag",
186                             str.substring(i));
187             }
188
189             // Don't want to include the right brace
190
i += 1;
191         }
192         return (Tag[])list.toArray(new Tag[list.size()]);
193     }
194
195     /**
196      * Returns the first sentence tags found in <code>str</code>.
197      *
198      * @param doc Doc to give to the new tag.
199      * @param str String from which to create the tags.
200      * @param loc Locale to give to the new tag.
201      * @param err ErrPrinter to give to the new tag.
202      * @return an array of Tag representing the first
203      * sentence tags found in str.
204      */

205     public final static Tag[] firstSentenceTags(Doc doc,
206                                                 String JavaDoc str,
207                                                 Locale JavaDoc loc,
208                                                 ErrPrinter err) {
209         return inlineTags(doc, firstSentenceText(str, loc, err), loc, err);
210     }
211
212     /**
213      * Returns the first sentence tags found in <code>str</code>,
214      * using <code>Locale.US</code> as the default locale.
215      *
216      * @param doc Doc to give to the new tag.
217      * @param str String from which to create the tags.
218      * @param err ErrPrinter to give to the new tag.
219      * @return an array of Tag representing the first
220      * sentence tags found in str.
221      */

222     private static String JavaDoc firstSentenceText(String JavaDoc str,
223                                             Locale JavaDoc loc,
224                                             ErrPrinter err) {
225         if (str == null || loc == null || !loc.equals(Locale.US)) {
226             return "";
227         }
228         final int N = str.length();
229         int i;
230         for (i = 0; i < N; i++) {
231             
232             // A period at the end of the text or a
233
// period followed by white space is the
234
// end of a sentence
235
if (str.charAt(i) == '.') {
236                 if (i == N-1) {
237                     return str.substring(0, i+1);
238                 }
239                 if (space(str.charAt(i+1))) {
240                     return str.substring(0, i+2);
241                 }
242             }
243             
244             // An HTML tag the signals the end -- one of:
245
// <p> </p> <h1> <h2> <h3> <h4>
246
// <h5> <h6> <hr> <pre> or </pre>
247
if (str.charAt(i) == '<') {
248                 int j = i+1;
249                 
250                 // Find the closing '>'
251
while (j < N && str.charAt(j) != '>') j++;
252                 
253                 // If there's no closing '>' signal an error
254
if (j == N) {
255                     err.error("unterminated_html_tag", str);
256                     return str;
257                 }
258                 
259                 // Inspect the inside of the tag
260
String JavaDoc innards = str.substring(i+1, j).trim().toLowerCase();
261                 if (innards.equals("p") || innards.equals("pre") ||
262                     innards.equals("h1") || innards.equals("h2") ||
263                     innards.equals("h3") || innards.equals("h4") ||
264                     innards.equals("h5") || innards.equals("h6") ||
265                     innards.equals("hr")) {
266                     return str.substring(0, i+1);
267                 }
268             }
269         }
270         return str;
271     }
272
273     /**
274      * Returns the tags found in <code>str</code>.
275      *
276      * @param doc Doc to give to the new tag.
277      * @param str String from which to create the tags.
278      * @param loc Locale to give to the new tag.
279      * @param err ErrPrinter to give to the new tag.
280      * @return an array of Tag representing the
281      * tags found in str.
282      */

283     public final static List JavaDoc findTags(Doc doc,
284                                       String JavaDoc str,
285                                       Locale JavaDoc loc,
286                                       ErrPrinter err) {
287                                       
288         //XXX This sucks!!! Will redo later.
289
boolean newline = true;
290         List JavaDoc result = new ArrayList JavaDoc();
291         if (str == null) return result;
292         final int N = str.length();
293         int lastTag = -1;
294         for (int i = 0; i < N; i++) {
295             if (newline(str.charAt(i))) {
296                 newline = true;
297                 // XXX need to evaluate - some tags can span newlines?
298
// if (lastTag != -1) { // now requiring tags not to span newlines
299
// result.add(parse(doc, str.substring(lastTag, i),
300
// loc, err));
301
// }
302
// lastTag = -1
303
} else if (space(str.charAt(i)) && newline) {
304             } else if (str.charAt(i) == '@' && newline) {
305                 if (lastTag != -1) {
306                     result.add(parse(doc, str.substring(lastTag, i),
307                                      loc, err));
308                 }
309                 lastTag = i;
310             } else {
311                 newline = false;
312             }
313         }
314         if (lastTag != -1) {
315             result.add(parse(doc, str.substring(lastTag),
316                              loc, err));
317         }
318         return result;
319     }
320
321     private final static Tag parse(Doc doc,
322                                    String JavaDoc str,
323                                    Locale JavaDoc loc,
324                                    ErrPrinter err) {
325         Tag result = null;
326         String JavaDoc[] split = split(str);
327         String JavaDoc name = split[0];
328         String JavaDoc rest = split[1];
329         if (name.equals("@see")) {
330             result = new SeeTagImpl(doc, name, rest, loc, err);
331         } else if (name.equals("@exception") || name.equals("@throws")) {
332             result = new ThrowsTagImpl(doc, name, rest, loc, err);
333         } else if (name.equals("@serialField")) {
334             result = new SerialFieldTagImpl(doc, name, rest, loc, err);
335         } else if (name.equals("@param")) {
336             result = new ParamTagImpl(doc, name, rest, loc, err);
337         } else {
338             result = new TagImpl(doc, name, rest, loc, err);
339         }
340         return result;
341     }
342
343     /**
344      * Returns the raw comment text found in <code>str</code>.
345      *
346      * @param str String containing comment from which
347      * the raw comment is found.
348      * @return String with the raw comment taken
349      * from <code>str</code>.
350      */

351     public final static String JavaDoc rawCommentText(String JavaDoc str) {
352         if (str == null) return "";
353         if (str.length() < 3) return "";
354         String JavaDoc withstars = "";
355         int islash = str.indexOf('/');
356         if (islash == -1 || islash+2 >= str.length()) {
357             return "";
358         }
359         if (str.charAt(islash+1) != '*' ||
360             str.charAt(islash+2) != '*') {
361             return "";
362         }
363         int start = islash+2+1;
364         while (str.charAt(start) == '*' || space(str.charAt(start))) start++;
365         int end = str.length()-2;
366         while (str.charAt(end) == '*') end--;
367         if (start != -1 && end > start) {
368             withstars = str.substring(start, end+1);
369         }
370         //String result = "";
371
StringBuffer JavaDoc result = new StringBuffer JavaDoc(withstars.length());
372         for (StringTokenizer JavaDoc t = new StringTokenizer JavaDoc(withstars, "\n", true);
373              t.hasMoreTokens();) {
374             String JavaDoc line = t.nextToken();
375             if (line == null || line.length() == 0) continue;
376             int i;
377             for (i = 0; i < line.length(); i++) {
378                 if (!(line.charAt(i) == '*' ||
379                       line.charAt(i) == ' ')) {
380                     break;
381                 }
382             }
383             //result += line.substring(i);
384
result.append(line.substring(i));
385         }
386         //return result;
387
return result.toString();
388     }
389
390     /**
391      * Returns the comment text from the passed in
392      * raw comment text -- e.g. no tags at the end.
393      *
394      * @param rawCommentText raw comment text to search.
395      * @return the comment text from
396      * <code>rawCommentText</code>.
397      */

398     public final static String JavaDoc commentText(String JavaDoc rawCommentText) {
399         //String result = "";
400
if (rawCommentText == null) {
401             return "";
402         }
403         StringBuffer JavaDoc result = new StringBuffer JavaDoc(rawCommentText.length());
404     outer:
405         for (StringTokenizer JavaDoc t = new StringTokenizer JavaDoc(rawCommentText, "\n", true);
406              t.hasMoreTokens();) {
407             String JavaDoc line = t.nextToken();
408             if (line == null || line.length() == 0) continue;
409             int i;
410             for (i = 0; i < line.length(); i++) {
411                 char c = line.charAt(i);
412                 if (c == ' ' || c == '\t') {
413                 } else if (c == '@') {
414                     break outer;
415                 } else {
416                     //result += line;
417
result.append(line);
418                     continue outer;
419                 }
420             }
421         }
422         //return result;
423
return result.toString();
424     }
425
426     /**
427      * Compares using names.
428      *
429      * @param $ First Doc.
430      * @param _ Second Doc.
431      * @return -1 if either are null, else
432      * <code>$.name.compareTo(_.name</code>.
433      */

434     public final static int compareTo(Doc $, Doc _) {
435         return ($ == null || _ == null) ? -1 : $.name().compareTo(_.name());
436     }
437
438     /**
439      * Returns the signature, given <code>parameters</code>,
440      * without flattening.
441      *
442      * @param parameters an array of Parameter.
443      * @return String representation of the parameters.
444      * @see #signature(Parameter[],boolean)
445      */

446     public final static String JavaDoc signature(Parameter[] parameters) {
447         return signature(parameters, false);
448     }
449
450     /**
451      * Returns the signature, given <code>parameters</code>,
452      * with flattening.
453      *
454      * @param parameters an array of Parameter.
455      * @return String representation of the parameters.
456      * @see #signature(Parameter[],boolean)
457      */

458     public final static String JavaDoc flatSignature(Parameter[] parameters) {
459         return signature(parameters, true);
460     }
461
462     /**
463      * Returns the signature, given <code>parameters</code>
464      * and flattens if <code>flatten</code>.
465      *
466      * @param parameters an array of Parameter.
467      * @param flatten <code>true</code> if the parameter names
468      * should be flattened.
469      * @return String representation of the parameters.
470      */

471     public final static String JavaDoc signature(Parameter[] parameters,
472                                          boolean flatten) {
473         if (parameters == null || parameters.length == 0) {
474             return "()";
475         }
476         //String str = "(";
477
StringBuffer JavaDoc str = new StringBuffer JavaDoc((flatten ? 8 : 20) *
478                                             parameters.length);
479         str.append("(");
480         final int N = parameters.length;
481         for (int i = 0; i < N; i++) {
482             String JavaDoc typeName = parameters[i].typeName();
483             if (flatten) {
484                 int idot = typeName.lastIndexOf('.');
485                 if (idot != -1) {
486                     typeName = typeName.substring(idot+1);
487                 }
488             }
489             //str += typeName + (i < N-1 ? "," : "");
490
str.append(typeName + (i < N-1 ? "," : ""));
491                 
492         }
493         //str += ")";
494
str.append(")");
495         //return str;
496
return str.toString();
497     }
498
499     /**
500      * Returns <code>true</code> -- include all members for now.
501      *
502      * @param doc member to consider.
503      * @param flags access flags.
504      */

505     public final static boolean isIncluded(MemberDoc doc, long flags) {
506         return true;
507     }
508
509     /**
510      * Returns <code>true</code> if <code>dec</code>
511      * isn't local or annonymous or <code>null</code>.
512      *
513      * @param dec TypeDec to consider.
514      * @return <code>true</code> isn't dec is local or
515      * annonymous or <code>null</code>.
516      */

517     public final static boolean isIncluded(TypeDec dec) {
518         if (dec == null) {
519             return false;
520         }
521         if (dec.isLocal() && dec.isAnonymous()) {
522             return false;
523         }
524         return true; //XXX to do
525
}
526
527     //XXX Debugging
528
public final static void dump(Object JavaDoc o, String JavaDoc prefix) {
529         System.err.println(">> Dumping:"+o);
530         java.lang.reflect.Method JavaDoc[] ms = o.getClass().getMethods();
531         List JavaDoc list = new ArrayList JavaDoc();
532         for (int i = 0; i < ms.length; i++) {
533             list.add(ms[i]);
534         }
535         Collections.sort(list, new Comparator JavaDoc() {
536                 public int compare(Object JavaDoc o1, Object JavaDoc o2) {
537                     return str(o1).compareTo(str(o2));
538                 }
539                 public boolean equals(Object JavaDoc o1, Object JavaDoc o2) {
540                     return str(o1).equals(str(o2));
541                 }
542                 private String JavaDoc str(Object JavaDoc _) {
543                     return (_ != null && _ instanceof java.lang.reflect.Method JavaDoc)
544                         ? ((java.lang.reflect.Method JavaDoc)_).getName() : _+"";
545                 }
546             });
547         for (Iterator JavaDoc i = list.iterator(); i.hasNext();) {
548             java.lang.reflect.Method JavaDoc m = (java.lang.reflect.Method JavaDoc)i.next();
549             if (m.getParameterTypes().length == 0 &&
550                 m.getName().startsWith(prefix)) {
551                 try {
552                     System.err.println(" "+m.getName()+":"+
553                                        m.invoke(o, new Object JavaDoc[0]));
554                 } catch (Throwable JavaDoc _) {}
555             }
556         }
557     }
558     public final static void gets(Object JavaDoc o) {
559         dump(o, "get");
560     }
561     public final static void array(Object JavaDoc[] os) {
562         array(os, false);
563     }
564     public final static void array(Object JavaDoc[] os, boolean gets) {
565         if (os == null) {
566             System.err.println("NULL");
567             return;
568         }
569         System.err.println(os.getClass().getName()+":" + os.length);
570         for (int i = 0; i < os.length; i++) {
571             System.err.println(" [" + i +"]:" + os[i]);
572             if (gets) gets(os[i]);
573         }
574     }
575
576     /**
577      * Returns the HTML documentation found in <code>html</code>
578      * using <code>err</code> to report errors.
579      *
580      * @param html File in which to look.
581      * @param err ErrPrinter to use to report errors.
582      * @return HTML documentaiton found in <code>html</code>.
583      */

584     public static String JavaDoc documentation(File JavaDoc html, ErrPrinter err) {
585         String JavaDoc str = "";
586         InputStream JavaDoc in = null;
587         try {
588             in = new FileInputStream JavaDoc(html);
589         } catch (IOException JavaDoc ioe) {
590             err.ex(ioe, "ioexception_open", html.getAbsolutePath());
591             return "";
592         }
593         try {
594             byte[] bytes = new byte[in.available()];
595             in.read(bytes, 0, bytes.length);
596             in.close();
597             str = new String JavaDoc(bytes);
598         } catch (IOException JavaDoc ioe) {
599             err.ex(ioe, "ioexception_reading", html.getAbsolutePath());
600         }
601
602         int[] is = new int[]{-10,-1};
603         int i = 0;
604         final char[] chars = new char[]{'/','B','O','D','Y','>'};
605         for (int j = 1; j >= 0; j--) {
606         nextTag:
607             for (; i != -1; i = str.indexOf('<', i+1)) {
608             nextLt:
609                 for (int s = i+1, k = j; s < str.length(); s++, k++) {
610                     char c = str.charAt(s);
611                     if (k == chars.length) {
612                         is[j] += s+2;
613                         break nextTag;
614                     }
615                     if (!(c == chars[k] || c == (chars[k] | 0x01000000))) {
616                         break nextLt;
617                     }
618                 }
619             }
620         }
621         if (is[0] > -1 && is[1] > -1) {
622             str = str.substring(is[1], is[0]);
623         }
624         return str;
625     }
626
627     /**
628      * Returns the result of invoking the method <code>name</code>
629      * on <code>target</code> with parameters <code>params</code>
630      * declared in the <code>target</code>'s class using arguments
631      * <code>args</code>.
632      *
633      * @param target target Object.
634      * @param name name of the method.
635      * @param params array of Class of parameters of the method.
636      * @param args array of Object of arguments to the method.
637      * @return the result of invoking the method.
638      * @see #invoke(Class,Object,String,Class[],Object[])
639      */

640     public static Object JavaDoc invoke(Object JavaDoc target, String JavaDoc name,
641                                 Class JavaDoc[] params, Object JavaDoc[] args) {
642         return invoke(target.getClass(), target, name, params, args);
643     }
644
645     /**
646      * Returns the result of invoking the method <code>name</code>
647      * on <code>target</code> with parameters <code>params</code>
648      * declared in the <code>type</code> using arguments
649      * <code>args</code>.
650      * This method handles any errors that arise in doing so.
651      *
652      * @param type type in which the method is declared.
653      * @param target target Object -- null for static methods.
654      * @param name name of the method.
655      * @param params array of Class of parameters of the method.
656      * @param args array of Object of arguments to the method.
657      * @return the result of invoking the method.
658      */

659     public static Object JavaDoc invoke(Class JavaDoc type, Object JavaDoc target, String JavaDoc name,
660                                 Class JavaDoc[] params, Object JavaDoc[] args) {
661         try {
662             java.lang.reflect.Method JavaDoc method = type.getDeclaredMethod(name, params);
663             method.setAccessible(true);
664             return method.invoke(target, args);
665         } catch (Exception JavaDoc e) {
666             e.printStackTrace(); //TODO
667
}
668         return null;
669     }
670
671     /**
672      * Returns the value of access the field <code>name</code>
673      * declared in <code>type</code> on <code>target</code>.
674      * This method handles any errors that arise in doing so.
675      *
676      * @param type type in which the field is declared.
677      * @param target target that is currently holding the field --
678      * null for static fields.
679      * @param name name of the field.
680      * @return the result of accessing this field.
681      */

682     public static Object JavaDoc access(Class JavaDoc type, Object JavaDoc target, String JavaDoc name) {
683         try {
684             java.lang.reflect.Field JavaDoc field = type.getDeclaredField(name);
685             field.setAccessible(true);
686             return field.get(target);
687         } catch (Exception JavaDoc e) { //TODO
688
e.printStackTrace();
689         }
690         return null;
691     }
692
693     /**
694      * Returns the ExecutableMemberDoc from the array passed
695      * in whose parameters <i>weakly</i> match those of
696      * <code>params</code> and whose name matches exactly
697      * with <code>name</code>.
698      * This method <b>can</b> return <code>null</code>.
699      *
700      * @param emds an array of ExecutableMemberDoc from which
701      * the returned value comes.
702      * @param name the name of the member to return.
703      * @param params an array of Parameter that represent
704      * the parameters we're trying to match.
705      * @return an ExecutableMemberDoc whose parameters
706      * match the names and order found in
707      * <code>params</code> and whose name
708      * exactly equals <code>name</code>.
709      */

710     public final static ExecutableMemberDoc executableMemberDoc
711         (ExecutableMemberDoc[] emds,
712          String JavaDoc name,
713          Parameter[] params) {
714         ExecutableMemberDoc result = null;
715         next:
716         for (int i = 0; i < emds.length; i++) {
717             ExecutableMemberDoc emd = emds[i];
718             if (emd.name().equals(name) &&
719                 params.length == emd.parameters().length) {
720                 for (int j = 0; j < params.length; j++) {
721                     if (!params[j].typeName().equals
722                         (emd.parameters()[j].typeName())) {
723                         continue next;
724                     }
725                     result = emd;
726                     break next;
727                 }
728             }
729         }
730         return result;
731     }
732
733     /**
734      * Returns the PointcutDoc from the array passed
735      * in whose parameters <i>weakly</i> match those of
736      * <code>formals</code> and whose name matches exactly
737      * with <code>id</code>.
738      * This method <b>can</b> return <code>null</code>.
739      *
740      * @param nameType the type in which we're searching.
741      * @param id the name of the pointcut to return.
742      * @param formals the Formals whose name and order
743      * must match to return a pointcut.
744      * @return a PointcutDoc whose parameters
745      * match the names and order found in
746      * <code>formals</code> and whose name
747      * exactly equals <code>id</code>.
748      */

749     public final static PointcutDec pointcutDec(NameType nameType,
750                                                 String JavaDoc id,
751                                                 Formals formals) {
752         PointcutDec result = null;
753     next:
754         for (Iterator JavaDoc i = nameType.getPointcuts().iterator(); i.hasNext();) {
755             PointcutDec md = ((PointcutSO)i.next()).getPointcutDec();
756             if (md.getFormals().size() == formals.size() &&
757                 id.equals(md.getId())) {
758                 for (int j = 0; j < formals.size(); j++) {
759                     if (!md.getFormals().get(j).getType().getString().
760                         equals(formals.get(j).getType().getString())) {
761                         continue next;
762                     }
763                 }
764                 result = md;
765                 break next;
766             }
767         }
768         return result;
769     }
770
771     
772
773     /**
774      * Returns the MethodDoc from the array passed
775      * in whose parameters <i>weakly</i> match those of
776      * <code>formals</code> and whose name matches exactly
777      * with <code>id</code>.
778      * This method <b>can</b> return <code>null</code>.
779      *
780      * @param nameType the type in which we're searching.
781      * @param id the name of the method to return.
782      * @param formals the Formals whose name and order
783      * must match to return a method.
784      * @return a MethodDoc whose parameters
785      * match the names and order found in
786      * <code>formals</code> and whose name
787      * exactly equals <code>id</code>.
788      */

789     public final static MethodDec methodDec(NameType nameType,
790                                             String JavaDoc id,
791                                             Formals formals) {
792         MethodDec result = null;
793     next:
794         for (Iterator JavaDoc i = nameType.getMethods().iterator(); i.hasNext();) {
795             //MethodDec md = (MethodDec)i.next();
796
MethodDec md = ((Method)i.next()).getMethodDec();
797             if (md.getFormals().size() == formals.size() &&
798                 id.equals(md.getId())) {
799                 for (int j = 0; j < formals.size(); j++) {
800                     if (!md.getFormals().get(j).getType().getString().
801                         equals(formals.get(j).getType().getString())) {
802                         continue next;
803                     }
804                 }
805                 result = md;
806                 break next;
807             }
808         }
809         return result;
810     }
811
812     /**
813      * Returns the PointcutDec named <code>name</code>,
814      * contained in <code>typeDec</code> with type <code>type</code>.
815      * <code>showError</code> is passed to subsequent methods
816      * to supress or warrant error printing.
817      * This may return null.
818      *
819      * @param type Type in which this pointcut was declared.
820      * @param name name of the pointcut.
821      * @param typeDec TypeDec in which we're searching.
822      * @param showError <code>true</code> is an error should
823      * be printed upon not finding a pointcut.
824      * @return the pointcut declared in <code>type</code>
825      * named <code>name</code>, found by searching
826      * from <code>typeDec</code>. This may be
827      * null.
828      */

829     public static PointcutDec getPointcutDec(Type type,
830                                              String JavaDoc name,
831                                              TypeDec typeDec,
832                                              boolean showError) {
833         PointcutSO so = ((NameType)type).getPointcut(name, typeDec, showError);
834         PointcutDec dec = null;
835         if (so != null) {
836             dec = (PointcutDec)so.getCorrespondingDec();
837         }
838         return dec;
839     }
840     
841     /**
842      * Returns the FieldDec named <code>name</code>,
843      * contained in <code>typeDec</code> with type <code>type</code>.
844      * <code>showError</code> is passed to subsequent methods
845      * to supress or warrant error printing.
846      * This may return null.
847      *
848      * @param type Type in which this field was declared.
849      * @param name name of the field.
850      * @param typeDec TypeDec in which we're searching.
851      * @param showError <code>true</code> is an error should
852      * be printed upon not finding a field.
853      * @return the field declared in <code>type</code>
854      * named <code>name</code>, found by searching
855      * from <code>typeDec</code>. This may be
856      * null.
857      */

858     public static FieldDec getFieldDec(Type type,
859                                        String JavaDoc name,
860                                        TypeDec typeDec,
861                                        boolean showError) {
862         Field so = ((NameType)type).getField(name, typeDec, showError);
863         FieldDec dec = null;
864         if (so != null) {
865             dec = (FieldDec)so.getCorrespondingDec();
866         }
867         return dec;
868     }
869
870     /**
871      * Returns the MethodDec named <code>name</code>, with
872      * formals <code>params</code>,
873      * contained in <code>typeDec</code> with type <code>type</code>.
874      * <code>showError</code> is passed to subsequent methods
875      * to supress or warrant error printing.
876      * This may return null.
877      *
878      * @param type Type in which this method was declared.
879      * @param name name of the method.
880      * @param typeDec TypeDec in which we're searching.
881      * @param params the method's formal parameters.
882      * @param showError <code>true</code> is an error should
883      * be printed upon not finding a method.
884      * @return the method declared in <code>type</code>
885      * named <code>name</code>, found by searching
886      * from <code>typeDec</code>. This may be
887      * null.
888      */

889     public static MethodDec getMethodDec(Type type,
890                                          String JavaDoc name,
891                                          TypeDec typeDec,
892                                          Exprs params,
893                                          boolean showError) {
894         Method so = ((NameType)type).getMethod(name, typeDec, params, showError);
895         MethodDec dec = null;
896         if (so != null) {
897             dec = so.getMethodDec();
898         }
899         return dec;
900     }
901     
902     /**
903      * Returns the ConstructorDec named <code>name</code>, with
904      * formals <code>params</code>,
905      * contained in <code>typeDec</code> with type <code>type</code>.
906      * <code>showError</code> is passed to subsequent constructors
907      * to supress or warrant error printing.
908      * This may return null.
909      *
910      * @param type Type in which this constructor was declared.
911      * @param name name of the constructor.
912      * @param typeDec TypeDec in which we're searching.
913      * @param params the constructor's formal parameters.
914      * @param showError <code>true</code> is an error should
915      * be printed upon not finding a constructor.
916      * @return the constructor declared in <code>type</code>
917      * named <code>name</code>, found by searching
918      * from <code>typeDec</code>. This may be
919      * null.
920      */

921     public static ConstructorDec getConstructorDec(Type type,
922                                                    TypeDec typeDec,
923                                                    Exprs params,
924                                                    boolean showError) {
925         Constructor so = ((NameType)type).getConstructor(typeDec,
926                                                          params, showError);
927         ConstructorDec dec = null;
928         if (so != null) {
929             dec = (ConstructorDec)so.getCorrespondingDec();
930         }
931         return dec;
932     }
933 }
934
Popular Tags