KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > xdoclet > tagshandler > AbstractProgramElementTagsHandler


1 /*
2  * Copyright (c) 2001, 2002 The XDoclet team
3  * All rights reserved.
4  */

5 package xdoclet.tagshandler;
6
7 import java.util.*;
8
9 import org.apache.commons.logging.Log;
10
11 import xjavadoc.*;
12
13 import xdoclet.DocletContext;
14 import xdoclet.SubTask;
15 import xdoclet.XDocletException;
16 import xdoclet.XDocletTagSupport;
17 import xdoclet.template.PrettyPrintWriter;
18 import xdoclet.util.LogUtil;
19 import xdoclet.util.Translator;
20 import xdoclet.util.TypeConversionUtil;
21
22 /**
23  * @author Ara Abrahamian (ara_e@email.com)
24  * @created Oct 15, 2001
25  * @version $Revision: 1.17 $
26  */

27 public abstract class AbstractProgramElementTagsHandler extends XDocletTagSupport
28 {
29     /**
30      * The current token. Currently forAllParameterTypes and forAllClassTagTokens set it and currentToken returns the
31      * value. Tokens are computed for cases where the value should be tokenized by a set of delimiters.
32      */

33     protected static String JavaDoc currentToken;
34
35     /**
36      * The StringTokenizer object doing the tokenization. It should be shared by different tag implementations, that's
37      * why its defined class-level.
38      */

39     protected static StringTokenizer tagTokenizer;
40
41     /**
42      * Template can use matchPattern as a place where they can put volatile variable. You can set the value somewhere in
43      * the template and later use the value.
44      */

45     protected static String JavaDoc matchPattern;
46
47     /**
48      * Returns the not-full-qualified name of the specified class without the package name.
49      *
50      * @param clazz class
51      * @return classname
52      */

53     public static String JavaDoc getClassNameFor(XClass clazz)
54     {
55         return clazz.getName();
56     }
57
58     /**
59      * Returns the full-qualified name of the current class with the package name.
60      *
61      * @param clazz class
62      * @return fully qualified classname
63      */

64     public static String JavaDoc getFullClassNameFor(XClass clazz)
65     {
66         return clazz.getQualifiedName();
67     }
68
69     /**
70      * Returns the full-qualified name of the superclass of the specified class.
71      *
72      * @param clazz class
73      * @return superclass' fully qualified classname
74      */

75     public static String JavaDoc getFullSuperclassNameFor(XClass clazz)
76     {
77         if (clazz.getSuperclass() != null) {
78             return clazz.getSuperclass().getQualifiedName();
79         }
80         else {
81             return "java.lang.Object";
82         }
83     }
84
85     /**
86      * Utility method to get classes for iteration used by various methods. The result depends on the context: are we
87      * within a forAllPackages iteration or not.
88      *
89      * @return An array with all classes in that context in it.
90      */

91     public static Collection getAllClasses()
92     {
93         if (DocletContext.getInstance().getActiveSubTask().getCurrentPackage() == null) {
94             // not in a forAllPackages context
95
return getXJavaDoc().getSourceClasses();
96         }
97         else {
98             return DocletContext.getInstance().getActiveSubTask().getCurrentPackage().getClasses();
99         }
100     }
101
102     /**
103      * @param clazz
104      * @param executableMemberName
105      * @param parameters
106      * @param setCurrentExecutableMember
107      * @param forType
108      * @return
109      * @exception XDocletException
110      * @todo Remove. For archeologists only
111      */

112     protected static boolean hasExecutableMember_OLD(XClass clazz, String JavaDoc executableMemberName, String JavaDoc[] parameters, boolean setCurrentExecutableMember, int forType)
113          throws XDocletException
114     {
115         Log log = LogUtil.getLog(AbstractProgramElementTagsHandler.class, "hasExecutableMember");
116
117         while (clazz != null) {
118             Collection executableMembers = null;
119
120             switch (forType) {
121             case FOR_CONSTRUCTOR:
122                 executableMembers = clazz.getConstructors();
123                 break;
124             case FOR_METHOD:
125                 executableMembers = clazz.getMethods();
126                 break;
127             default:
128                 throw new XDocletException("Bad type: " + forType);
129             }
130
131             int j = 0;
132
133             loop :
134             for (Iterator m = executableMembers.iterator(); m.hasNext(); ) {
135                 XExecutableMember executableMember = (XExecutableMember) m.next();
136
137                 if (executableMember.getName().equals(executableMemberName)) {
138                     // All parameters must be equal too
139
if (parameters != null) {
140                         Collection params = executableMember.getParameters();
141
142                         log.debug("params.length=" + params.size());
143
144                         for (Iterator p = params.iterator(); p.hasNext(); ) {
145                             XParameter param = (XParameter) p.next();
146
147                             String JavaDoc paramType = new StringBuffer JavaDoc(param.getType().getQualifiedName()).append(param.getDimensionAsString()).toString();
148
149                             if (log.isDebugEnabled()) {
150                                 log.debug("params[j]=" + paramType);
151                                 log.debug("parameters[j]=" + parameters[j]);
152                             }
153                             if (paramType.equals(parameters[j++])) {
154                                 continue loop;
155                             }
156                         }
157                     }
158
159                     // The class has the given executable member
160
if (setCurrentExecutableMember) {
161                         switch (forType) {
162                         case FOR_CONSTRUCTOR:
163                             setCurrentConstructor((XConstructor) executableMember);
164                             break;
165                         case FOR_METHOD:
166                             setCurrentMethod((XMethod) executableMember);
167                             break;
168                         default:
169                             throw new XDocletException("Bad type: " + forType);
170                         }
171                     }
172                     return true;
173                 }
174             }
175
176             // Check super class info
177
clazz = clazz.getSuperclass();
178         }
179
180         return false;
181     }
182
183     /**
184      * Used to protect returned arrays from being modified (sorted, reordered for example).
185      *
186      * @param objects array of objects
187      * @return copy of array
188      */

189     protected static Object JavaDoc[] makeCopyOfArray(Object JavaDoc[] objects)
190     {
191         Object JavaDoc[] objects_copy = (Object JavaDoc[]) java.lang.reflect.Array.newInstance(objects.getClass().getComponentType(), objects.length);
192
193         System.arraycopy(objects, 0, objects_copy, 0, objects.length);
194
195         return objects_copy;
196     }
197
198     protected static boolean hasExecutableMember(XClass clazz, String JavaDoc executableMemberName, String JavaDoc[] parameters, boolean setCurrentExecutableMember, int forType)
199          throws XDocletException
200     {
201         Log log = LogUtil.getLog(AbstractProgramElementTagsHandler.class, "hasExecutableMember");
202
203         StringBuffer JavaDoc executableMemberNameWithSignature = new StringBuffer JavaDoc(executableMemberName).append("(");
204         boolean comma = false;
205
206         if (parameters != null) {
207             for (int i = 0; i < parameters.length; i++) {
208                 if (comma) {
209                     executableMemberNameWithSignature.append(',');
210                 }
211                 executableMemberNameWithSignature.append(getXJavaDoc().getXClass(parameters[i]).getQualifiedName());
212             }
213         }
214         executableMemberNameWithSignature.append(')');
215
216         XExecutableMember executableMember = null;
217
218         switch (forType) {
219         case FOR_CONSTRUCTOR:
220             executableMember = clazz.getConstructor(executableMemberNameWithSignature.toString());
221             break;
222         case FOR_METHOD:
223             executableMember = clazz.getMethod(executableMemberNameWithSignature.toString(), true);
224             break;
225         default:
226             throw new XDocletException("Bad type: " + forType);
227         }
228         if (setCurrentExecutableMember && executableMember != null) {
229             switch (forType) {
230             case FOR_CONSTRUCTOR:
231                 setCurrentConstructor((XConstructor) executableMember);
232                 break;
233             case FOR_METHOD:
234                 setCurrentMethod((XMethod) executableMember);
235                 break;
236             default:
237                 throw new XDocletException("Bad type: " + forType);
238             }
239         }
240
241         return executableMember != null;
242     }
243
244     /**
245      * Sets the value of match variable.
246      *
247      * @param template The body of the block tag
248      * @param attributes The attributes of the template tag
249      * @exception XDocletException Description of Exception
250      * @doc.tag type="block"
251      * @doc.param name="value" optional="false" description="The new value for matchPattern."
252      */

253     public void setMatchValue(String JavaDoc template, Properties attributes) throws XDocletException
254     {
255         matchPattern = attributes.getProperty("value");
256         generate(template);
257         matchPattern = null;
258     }
259
260     /**
261      * Returns the value of match variable. Match variable serves as a variable for templates, you set it somewhere in
262      * template and look it up somewhere else in template.
263      *
264      * @return Description of the Returned Value
265      * @exception XDocletException Description of Exception
266      * @doc.tag type="content"
267      */

268     public String JavaDoc matchValue() throws XDocletException
269     {
270         return matchPattern;
271     }
272
273     /**
274      * Returns current token inside forAllClassTagTokens.
275      *
276      * @param attributes The attributes of the template tag
277      * @return value of currently processed token
278      * @exception XDocletException Description of Exception
279      * @doc.tag type="content"
280      */

281     public String JavaDoc currentToken(Properties attributes) throws XDocletException
282     {
283         Log log = LogUtil.getLog(SubTask.class, "currentToken");
284
285         log.debug("current token: " + currentToken);
286
287         if (currentToken == null) {
288             log.error("null token found");
289             return "";
290         }
291         else {
292             return currentToken;
293         }
294     }
295
296     /**
297      * Skips current token. Returns empty string.
298      *
299      * @param attributes The attributes of the template tag
300      * @return Empty string
301      * @exception XDocletException Description of Exception
302      * @doc.tag type="content"
303      */

304     public String JavaDoc skipToken(Properties attributes) throws XDocletException
305     {
306         if (tagTokenizer.hasMoreTokens()) {
307             tagTokenizer.nextToken();
308         }
309
310         return "";
311     }
312
313     /**
314      * Gets the XExecutableMemberForMemberName attribute of the AbstractProgramElementTagsHandler object
315      *
316      * @param memberName Describe what the parameter does
317      * @param forType Describe what the parameter does
318      * @return The XExecutableMemberForMemberName value
319      * @exception XDocletException Describe the exception
320      */

321     protected XExecutableMember getXExecutableMemberForMemberName(String JavaDoc memberName, int forType) throws XDocletException
322     {
323         if (memberName != null) {
324             return extractXExecutableMember(getCurrentClass(), memberName, forType);
325         }
326
327         return null;
328     }
329
330     /**
331      * Searches for the XExecutableMember of the member with name methodName and returns it.
332      *
333      * @param superclasses Search superclasses.
334      * @param memberName
335      * @param forType
336      * @return The XMethod for the method named value
337      * @exception XDocletException
338      */

339     protected XExecutableMember getXExecutableMemberForMemberName(String JavaDoc memberName, boolean superclasses, int forType) throws XDocletException
340     {
341         if (!superclasses) {
342             return getXExecutableMemberForMemberName(memberName, forType);
343         }
344
345         for (XClass clazz = getCurrentClass(); clazz != null; clazz = clazz.getSuperclass()) {
346             XExecutableMember member = extractXExecutableMember(clazz, memberName, forType);
347
348             if (member != null) {
349                 return member;
350             }
351         }
352         return null;
353     }
354
355     /**
356      * A utility method to get the blank space characters used for indenting comments. The number of spaces is read from
357      * the <code>indent</code> tag attribute. Defaults to zero spaces if no <code>indent</code> attribute is present.
358      *
359      * @param attributes The attributes of the template tag
360      * @return Array of <code>indent</code> space characters
361      * @see #memberComment(java.util.Properties, int)
362      * @see ClassTagsHandler#classComment(java.util.Properties)
363      * @see ClassTagsHandler#classCommentText(java.util.Properties)
364      * @see ClassTagsHandler#classCommentTags(java.util.Properties)
365      */

366     protected char[] getIndentChars(Properties attributes)
367     {
368         String JavaDoc indentStr = attributes.getProperty("indent");
369
370         if (indentStr == null) {
371             return new char[0];
372         }
373
374         int indent = new Integer JavaDoc(indentStr).intValue();
375         char[] spaces = new char[indent];
376
377         Arrays.fill(spaces, ' ');
378         return spaces;
379     }
380
381     /**
382      * Return the throws clause of the specified constructor or method declaration. If no constructor/method is
383      * specified, the current one is used.
384      *
385      * @param attributes The attributes of the template tag
386      * @param forType Constant indicating constructor or method
387      * @return throws clause
388      * @exception XDocletException Describe the exception
389      * @see MethodTagsHandler#exceptionList(java.util.Properties)
390      * @see ConstructorTagsHandler#exceptionList(java.util.Properties)
391      */

392     protected String JavaDoc exceptionList(Properties attributes, int forType) throws XDocletException
393     {
394         String JavaDoc skipExceptions = attributes.getProperty("skip");
395         String JavaDoc appendExceptions = attributes.getProperty("append");
396         String JavaDoc memberName = null;
397         Collection exceptions = null;
398
399         XExecutableMember executableMember = null;
400
401         switch (forType) {
402         case FOR_CONSTRUCTOR:
403             executableMember = getCurrentConstructor();
404             memberName = attributes.getProperty("constructor");
405             break;
406         case FOR_METHOD:
407             executableMember = getCurrentMethod();
408             memberName = attributes.getProperty("method");
409             break;
410         default:
411             throw new XDocletException("Can't exceptionList for type " + forType);
412         }
413
414         if (executableMember == null && memberName == null) {
415             exceptions = new ArrayList();
416         }
417
418         if (memberName == null) {
419             exceptions = executableMember.getThrownExceptions();
420         }
421         else {
422             executableMember = getXExecutableMemberForMemberName(memberName, true, forType);
423
424             // no member with the specified name found in class
425
if (executableMember != null) {
426                 exceptions = executableMember.getThrownExceptions();
427             }
428             else {
429                 exceptions = new ArrayList();
430             }
431         }
432
433         StringBuffer JavaDoc sbuf = new StringBuffer JavaDoc();
434         String JavaDoc type = null;
435
436         for (Iterator i = exceptions.iterator(); i.hasNext(); ) {
437             type = ((XClass) i.next()).getQualifiedName();
438
439             if (isInSkipExceptionsList(skipExceptions, type) == false &&
440                 isInAppendExceptionsList(appendExceptions, type) == false) {
441                 appendException(sbuf, type);
442             }
443         }
444
445         // append all exceptions specified to be always appended by default
446
if (appendExceptions != null) {
447             appendException(sbuf, appendExceptions);
448         }
449
450         return sbuf.toString();
451     }
452
453     /**
454      * Describe what the method does
455      *
456      * @param template The body of the block tag
457      * @param attributes The attributes of the template tag
458      * @param for_type Describe what the parameter does
459      * @exception XDocletException Describe the exception
460      */

461     protected void forAllMemberTagTokens(String JavaDoc template, Properties attributes, int for_type) throws XDocletException
462     {
463         Log log = LogUtil.getLog(MethodTagsHandler.class, "forAllMemberTagTokens");
464
465         String JavaDoc tagValue;
466
467         tagValue = getTagValue(attributes, for_type);
468
469         String JavaDoc delimiter = attributes.getProperty("delimiter");
470         String JavaDoc skipStr = attributes.getProperty("skip");
471         int skip;
472
473         try {
474             skip = Integer.valueOf(skipStr).intValue();
475         }
476         catch (Throwable JavaDoc t) {
477             skip = 0;
478         }
479
480         if (delimiter == null) {
481             log.debug("got null delimiter - forAllMemberTagTokens");
482             delimiter = PARAMETER_DELIMITER;
483         }
484
485         log.debug("Tag Value = " + tagValue);
486
487         tagTokenizer = new StringTokenizer(tagValue, delimiter, false);
488         currentToken = "";
489         matchPattern = null;
490
491         for (int i = 0; tagTokenizer.hasMoreTokens() && i < skip; i++) {
492             tagTokenizer.nextToken();
493         }
494
495         while (tagTokenizer.hasMoreTokens()) {
496             currentToken = tagTokenizer.nextToken();
497
498             log.debug("generate current token: " + currentToken);
499
500             generate(template);
501         }
502
503         currentToken = null;
504         tagTokenizer = null;
505         matchPattern = null;
506     }
507
508     /**
509      * Describe what the method does
510      *
511      * @param template The body of the block tag
512      * @param attributes The attributes of the template tag
513      * @param forType Describe what the parameter does
514      * @param resourceKey Describe what the parameter does
515      * @param arguments Describe what the parameter does
516      * @exception XDocletException Describe the exception
517      */

518     protected void forAllMemberTags(String JavaDoc template, Properties attributes, int forType, String JavaDoc resourceKey, String JavaDoc[] arguments) throws XDocletException
519     {
520         Log log = LogUtil.getLog(AbstractProgramElementTagsHandler.class, "forAllMemberTags");
521         boolean superclasses = TypeConversionUtil.stringToBoolean(attributes.getProperty("superclasses"), true);
522         XMember member = null;
523
524         switch (forType) {
525         case FOR_FIELD:
526             member = getCurrentField();
527             break;
528         case FOR_CONSTRUCTOR:
529             member = getCurrentConstructor();
530             break;
531         case FOR_METHOD:
532             member = getCurrentMethod();
533             break;
534         default:
535             throw new XDocletException("Bad type " + forType);
536         }
537
538         if (member == null) {
539             throw new XDocletException(Translator.getString(XDocletTagshandlerMessages.class, resourceKey, arguments));
540         }
541
542         /*
543          * If the tagName contains a "|" it's to support deprecated tags.
544          * If we find an occurrance for the first tag, we won't loop over the second one.
545          */

546         StringTokenizer st = new StringTokenizer(attributes.getProperty("tagName"), "|");
547         boolean found = false;
548
549         while (st.hasMoreTokens() && !found) {
550             String JavaDoc tagName = st.nextToken();
551             Collection tags = member.getDoc().getTags(tagName, superclasses);
552
553             for (Iterator i = tags.iterator(); i.hasNext(); ) {
554                 found = true;
555
556                 XTag tag = (XTag) i.next();
557
558                 if (forType == FOR_METHOD || forType == FOR_CONSTRUCTOR) {
559                     setCurrentMethodTag(tag);
560                 }
561                 else {
562                     setCurrentFieldTag(tag);
563                 }
564
565                 String JavaDoc m = getTagValue(attributes, forType);
566
567                 if (log.isDebugEnabled()) {
568                     log.debug((getCurrentMethod() == null) ? "<no current method>" : getCurrentMethod().getName() + " ** Tag/Param = "
569                         + attributes.getProperty("tagName") + '/' + attributes.getProperty("paramName")
570                         + " ** Value = " + m
571                         + " MatchPattern = " + matchPattern);
572                 }
573
574                 if (matchPattern == null) {
575                     generate(template);
576                 }
577                 else if (matchPattern != null && (matchPattern.equals(m) || m.equals("*"))) {
578                     generate(template);
579                 }
580             }
581
582             if (forType == FOR_METHOD || forType == FOR_CONSTRUCTOR) {
583                 setCurrentMethodTag(null);
584             }
585             else {
586                 setCurrentFieldTag(null);
587             }
588         }
589     }
590
591     /**
592      * The comment for the current class member of the specified type (field, constructor or method).
593      *
594      * @param attributes The attributes of the template tag
595      * @param forType Member type
596      * @return javadoc comment
597      * @exception XDocletException Describe the exception
598      * @todo There is similar functionality in xjavadoc.XDoc. Use that instead (needs a little
599      * rework to be more flexible).
600      * @see MethodTagsHandler#methodComment(java.util.Properties)
601      * @see FieldTagsHandler#fieldComment(java.util.Properties)
602      * @see ConstructorTagsHandler#constructorComment(java.util.Properties)
603      */

604     protected String JavaDoc memberComment(Properties attributes, int forType) throws XDocletException
605     {
606         String JavaDoc noCommentSigns = attributes.getProperty("no-comment-signs");
607
608         XMember member = null;
609
610         switch (forType) {
611         case FOR_FIELD:
612             member = getCurrentField();
613             break;
614         case FOR_CONSTRUCTOR:
615             member = getCurrentConstructor();
616             break;
617         case FOR_METHOD:
618             member = getCurrentMethod();
619             break;
620         default:
621             throw new XDocletException("Bad type " + forType);
622         }
623
624         if (noCommentSigns != null && noCommentSigns.equalsIgnoreCase("true")) {
625             return member.getDoc().getCommentText();
626         }
627
628         char[] spaces = getIndentChars(attributes);
629         Collection memberTags = member.getDoc().getTags();
630
631         if (memberTags.size() > 0) {
632             StringBuffer JavaDoc sbuf = new StringBuffer JavaDoc();
633
634             // add user comments
635
StringTokenizer st = new StringTokenizer(member.getDoc().getCommentText().trim(), "\n", false);
636
637             if (st.countTokens() > 0) {
638                 sbuf.append(spaces).append("/**").append(PrettyPrintWriter.LINE_SEPARATOR);
639                 while (st.hasMoreTokens()) {
640                     sbuf.append(spaces).append(" * ").append(st.nextToken().trim()).append(PrettyPrintWriter.LINE_SEPARATOR);
641                 }
642
643                 for (Iterator i = memberTags.iterator(); i.hasNext(); ) {
644                     XTag memberTag = (XTag) i.next();
645                     // all of our xdoclet-specific tags have a ":" or "."
646
String JavaDoc memberTagName = memberTag.getName();
647
648                     if (memberTagName.indexOf(':') == -1 && memberTagName.indexOf('.') == -1
649                         && getDocletContext().getExcludedTags().indexOf(memberTagName) == -1) {
650                         sbuf.append(spaces).append(" * ")
651                             .append('@').append(memberTag.getName()).append(' ')
652                             .append(memberTag.getValue());
653
654                         // for all lines but not the last line
655
if (i.hasNext()) {
656                             sbuf.append(PrettyPrintWriter.LINE_SEPARATOR);
657                         }
658                     }
659                 }
660                 sbuf.append(spaces).append(" */");
661             }
662
663             return sbuf.toString();
664         }
665         else {
666             return "";
667         }
668     }
669
670     /**
671      * Describe what the method does
672      *
673      * @param member Describe what the parameter does
674      * @return Describe the return value
675      * @exception XDocletException Describe the exception
676      */

677     protected String JavaDoc firstSentenceDescriptionOfCurrentMember(XMember member) throws XDocletException
678     {
679         return member.getDoc().getFirstSentence() != null ? member.getDoc().getFirstSentence() : "";
680     }
681
682     /**
683      * @param template Describe what the parameter does
684      * @param attributes Describe what the parameter does
685      * @param forType Describe what the parameter does
686      * @exception XDocletException Describe the exception
687      * @todo the already Set contains XMember objects. equals/hashCode should be defined in
688      * XMember and be implemented in all of the implementing classes.
689      */

690     protected void forAllMembers(String JavaDoc template, Properties attributes, int forType) throws XDocletException
691     {
692         boolean superclasses = TypeConversionUtil.stringToBoolean(attributes.getProperty("superclasses"), true);
693         boolean sort = TypeConversionUtil.stringToBoolean(attributes.getProperty("sort"), true);
694         XClass currentClass = getCurrentClass();
695
696         if (currentClass == null) {
697             throw new XDocletException("currentClass == null!!!");
698         }
699
700         Collection members = null;
701
702         switch (forType) {
703         case FOR_FIELD:
704             members = currentClass.getFields(superclasses);
705             break;
706         case FOR_CONSTRUCTOR:
707             members = currentClass.getConstructors();
708             break;
709         case FOR_METHOD:
710             members = currentClass.getMethods(superclasses);
711             break;
712         default:
713             throw new XDocletException("Bad type: " + forType);
714         }
715
716         if (sort) {
717             // sort fields, but we should make a copy first, because members is not a new copy, it's shared by all
718
List sortedMembers = new ArrayList(members);
719
720             members = sortedMembers;
721         }
722
723         for (Iterator j = members.iterator(); j.hasNext(); ) {
724             XMember member = (XMember) j.next();
725
726             switch (forType) {
727             case FOR_FIELD:
728                 setCurrentField((XField) member);
729                 break;
730             case FOR_CONSTRUCTOR:
731                 setCurrentConstructor((XConstructor) member);
732                 break;
733             case FOR_METHOD:
734                 setCurrentMethod((XMethod) member);
735                 break;
736             default:
737                 throw new XDocletException("Bad type: " + forType);
738             }
739
740             setCurrentClass(member.getContainingClass());
741             generate(template);
742         }
743         setCurrentClass(currentClass);
744
745     }
746
747     /**
748      * A utility method used by firstSentenceDescription to replace end of line by space.
749      *
750      * @param pText Description of Parameter
751      * @return Description of the Returned Value
752      */

753     protected String JavaDoc checkForWrap(String JavaDoc pText)
754     {
755         int lIndex = pText.indexOf(PrettyPrintWriter.LINE_SEPARATOR);
756
757         while (lIndex >= 0) {
758             if (lIndex < pText.length() - 1) {
759                 pText = new StringBuffer JavaDoc(pText.substring(0, lIndex).trim()).append(' ').append(pText.substring(lIndex + 1).trim()).toString();
760             }
761             else {
762                 pText = pText.substring(0, lIndex);
763             }
764
765             lIndex = pText.indexOf(PrettyPrintWriter.LINE_SEPARATOR);
766         }
767
768         // Avoid any trailing spaces
769
return pText.trim();
770     }
771
772     /**
773      * Gets the InAppendExceptionsList attribute of the AbstractProgramElementTagsHandler object
774      *
775      * @param appendExceptions Describe what the parameter does
776      * @param type Describe what the parameter does
777      * @return The InAppendExceptionsList value
778      */

779     private boolean isInAppendExceptionsList(String JavaDoc appendExceptions, String JavaDoc type)
780     {
781         if (appendExceptions == null) {
782             return false;
783         }
784         else {
785             return appendExceptions.indexOf(type) != -1;
786         }
787     }
788
789     /**
790      * Gets the InSkipExceptionsList attribute of the AbstractProgramElementTagsHandler object
791      *
792      * @param skipExceptions Describe what the parameter does
793      * @param type Describe what the parameter does
794      * @return The InSkipExceptionsList value
795      */

796     private boolean isInSkipExceptionsList(String JavaDoc skipExceptions, String JavaDoc type)
797     {
798         if (skipExceptions == null) {
799             return false;
800         }
801         else {
802             return skipExceptions.indexOf(type) != -1;
803         }
804     }
805
806     /**
807      * Append an exception to the supplied string buffer, building up a throws clause.
808      *
809      * @param sbuf String buffer containing the throws clause
810      * @param type String containing an exception type to add
811      */

812     private void appendException(StringBuffer JavaDoc sbuf, String JavaDoc type)
813     {
814         if (sbuf.length() == 0) {
815             sbuf.append("throws ").append(type);
816         }
817         else {
818             sbuf.append(", ").append(type);
819         }
820     }
821
822     /**
823      * Describe what the method does
824      *
825      * @param clazz Describe what the parameter does
826      * @param memberName Describe what the parameter does
827      * @param forType Describe what the parameter does
828      * @return Describe the return value
829      * @exception XDocletException Describe the exception
830      */

831     private XExecutableMember extractXExecutableMember(XClass clazz, String JavaDoc memberName, int forType) throws XDocletException
832     {
833         Collection executableMembers = null;
834
835         switch (forType) {
836         case FOR_CONSTRUCTOR:
837             executableMembers = clazz.getConstructors();
838             break;
839         case FOR_METHOD:
840             executableMembers = clazz.getMethods();
841             break;
842         default:
843             throw new XDocletException("Bad type: " + forType);
844         }
845
846         for (Iterator i = executableMembers.iterator(); i.hasNext(); ) {
847             XExecutableMember executableMember = (XExecutableMember) i.next();
848
849             if (executableMember.getName().equals(memberName)) {
850                 return executableMember;
851             }
852         }
853
854         return null;
855     }
856 }
857
Popular Tags