Source Code Cross Referenced for MethodAnalyzer.java in  » UML » jrefactory » org » acm » seguin » pretty » ai » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » UML » jrefactory » org.acm.seguin.pretty.ai 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Author:  Chris Seguin
003:         *
004:         *  This software has been developed under the copyleft
005:         *  rules of the GNU General Public License.  Please
006:         *  consult the GNU General Public License for more
007:         *  details about use and distribution of this software.
008:         */
009:        package org.acm.seguin.pretty.ai;
010:
011:        import java.text.MessageFormat;
012:
013:        import net.sourceforge.jrefactory.ast.ASTAnnotation;
014:        import net.sourceforge.jrefactory.ast.ASTMemberValuePairs;
015:        import net.sourceforge.jrefactory.ast.ASTMemberValuePair;
016:        import net.sourceforge.jrefactory.ast.ASTMemberValue;
017:        import net.sourceforge.jrefactory.ast.ASTMemberValueArrayInitializer;
018:
019:        import net.sourceforge.jrefactory.ast.ASTClassOrInterfaceType;
020:        import net.sourceforge.jrefactory.ast.ASTFormalParameter;
021:        import net.sourceforge.jrefactory.ast.ASTFormalParameters;
022:        import net.sourceforge.jrefactory.ast.ASTMethodDeclaration;
023:        import net.sourceforge.jrefactory.ast.ASTMethodDeclarator;
024:        import net.sourceforge.jrefactory.ast.ASTName;
025:        import net.sourceforge.jrefactory.ast.ASTNameList;
026:
027:        import net.sourceforge.jrefactory.ast.ASTReferenceType;
028:        import net.sourceforge.jrefactory.ast.ASTResultType;
029:        import net.sourceforge.jrefactory.ast.ASTType;
030:        import net.sourceforge.jrefactory.ast.ASTTypeParameters;
031:        import net.sourceforge.jrefactory.ast.ASTVariableDeclaratorId;
032:        import net.sourceforge.jrefactory.ast.Node;
033:        import org.acm.seguin.pretty.DescriptionPadder;
034:        import org.acm.seguin.pretty.JavaDocableImpl;
035:        import org.acm.seguin.pretty.JavadocTags;
036:        import org.acm.seguin.util.FileSettings;
037:        import org.acm.seguin.util.MissingSettingsException;
038:
039:        /**
040:         *  Basis for the artificial intelligence that analyzes the method and determines the appropriate javadoc descriptions
041:         *
042:         * @author    Chris Seguin
043:         * @author    Mike Atkinson
044:         */
045:        public class MethodAnalyzer {
046:            private ASTMethodDeclaration node;
047:            private JavaDocableImpl jdi;
048:            private ParseVariableName pvn;
049:            private JavadocTags jt;
050:            private String operationType = null;
051:
052:            /**
053:             *  Constructor for the MethodAnalyzer object
054:             *
055:             * @param  node  Description of Parameter
056:             * @param  jdi   Description of Parameter
057:             */
058:            public MethodAnalyzer(ASTMethodDeclaration node, JavaDocableImpl jdi) {
059:                this .node = node;
060:                this .jdi = jdi;
061:                pvn = new ParseVariableName();
062:                jt = JavadocTags.get();
063:            }
064:
065:            /**
066:             *  Makes sure all the java doc components are present. For methods and constructors we need to do more work -
067:             *  checking parameters, return types, and exceptions.
068:             *
069:             * @param  className  Description of Parameter
070:             */
071:            public void finish(String className) {
072:                //  Get the resource bundle
073:                FileSettings bundle = FileSettings.getRefactoryPrettySettings();
074:
075:                //  Require a description of this method
076:                requireDescription(bundle, className);
077:
078:                String methodTags = "return,param,exception,throws";
079:                try {
080:                    methodTags = bundle.getString("method.tags");
081:                } catch (MissingSettingsException mse) {
082:                }
083:
084:                //  Check that if there is a return type
085:                if (methodTags.indexOf("return") >= 0) {
086:                    finishReturn(bundle);
087:                }
088:
089:                //  Check for parameters
090:                if (methodTags.indexOf("param") >= 0) {
091:                    finishParameters(bundle);
092:                }
093:                sortParameters();
094:                // sort parameters into order the occur in the method
095:
096:                //  Check for exceptions
097:                if ((methodTags.indexOf("exception") >= 0)
098:                        || (methodTags.indexOf("throws") >= 0)
099:                        || (methodTags.indexOf(jt.getExceptionTag()) >= 0)) {
100:                    finishExceptions(bundle);
101:                }
102:            }
103:
104:            /**
105:             *  Determine if this is a setter method
106:             *
107:             * @return    true if it is a setter
108:             */
109:            private boolean isSetter() {
110:                String name = getName();
111:                return ((name.length() > 3) && name.startsWith("set") && Character
112:                        .isUpperCase(name.charAt(3)));
113:            }
114:
115:            /**
116:             *  Determine if this is a getter method
117:             *
118:             * @return    true if it is a getter
119:             */
120:            private boolean isGetter() {
121:                String name = getName();
122:                return ((name.length() > 3)
123:                        && (name.startsWith("get") && Character
124:                                .isUpperCase(name.charAt(3))) || ((name
125:                        .length() > 2)
126:                        && name.startsWith("is") && Character.isUpperCase(name
127:                        .charAt(2))));
128:            }
129:
130:            /**
131:             *  Determine if this is a getter method
132:             *
133:             * @return    true if it is a getter
134:             */
135:            private boolean isAdder() {
136:                String name = getName();
137:                return (name.length() > 3)
138:                        && (name.startsWith("add") && Character
139:                                .isUpperCase(name.charAt(3)));
140:            }
141:
142:            /**
143:             *  Determine if this is a getter method
144:             *
145:             * @return    true if it is a getter
146:             */
147:            private boolean isListener() {
148:                String name = getName();
149:                return (name.length() > 11)
150:                        && (name.endsWith("Listener"))
151:                        && (name.startsWith("add") || name.startsWith("remove"));
152:            }
153:
154:            /**
155:             *  Determine if this is a run method
156:             *
157:             * @return    true if it is a run method
158:             */
159:            private boolean isRunMethod() {
160:                String name = getName();
161:                return name.equals("run");
162:            }
163:
164:            /**
165:             *  Gets the MainMethod attribute of the MethodAnalyzer object
166:             *
167:             * @return    The MainMethod value
168:             */
169:            private boolean isMainMethod() {
170:                String name = getName();
171:                if (!(name.equals("main") && node.isStatic())) {
172:                    return false;
173:                }
174:
175:                // If it has JDK 1.5 attributes ignore them
176:                int childNo = node.skipAnnotations();
177:
178:                // If it has JDK 1.5 type parameters it cannot be a main() method.
179:                Node child = node.jjtGetChild(childNo);
180:                if (child instanceof  ASTTypeParameters) {
181:                    return false;
182:                }
183:
184:                //  Check for the void return type
185:                ASTResultType result = (ASTResultType) child;
186:                if (result.hasAnyChildren()) {
187:                    return false;
188:                }
189:
190:                //  Check the parameters
191:                ASTMethodDeclarator decl = (ASTMethodDeclarator) node
192:                        .jjtGetChild(childNo + 1);
193:                ASTFormalParameters params = (ASTFormalParameters) decl
194:                        .jjtGetFirstChild();
195:                int childCount = params.jjtGetNumChildren();
196:                if (childCount != 1) {
197:                    return false;
198:                }
199:
200:                ASTFormalParameter nextParam = (ASTFormalParameter) params
201:                        .jjtGetFirstChild();
202:                childNo = nextParam.skipAnnotations();
203:                ASTType type = (ASTType) nextParam.jjtGetChild(childNo);
204:                child = type.jjtGetFirstChild();
205:                if (child instanceof  ASTReferenceType) {
206:                    ASTReferenceType reference = (ASTReferenceType) child;
207:                    childCount = reference.jjtGetNumChildren();
208:                    if (childCount != 1) {
209:                        return false;
210:                    }
211:                    if (reference.jjtGetFirstChild() instanceof  ASTClassOrInterfaceType) {
212:                        ASTClassOrInterfaceType nameNode = (ASTClassOrInterfaceType) reference
213:                                .jjtGetFirstChild();
214:                        if (nameNode.getName().equals("String")
215:                                || nameNode.getName()
216:                                        .equals("java.lang.String")) {
217:                            if (reference.getArrayCount() == 1) {
218:                                return true;
219:                            }
220:                        }
221:                    }
222:                }
223:
224:                return false;
225:            }
226:
227:            /**
228:             *  Determine if this is a JUnit setUp method
229:             *
230:             * @return    true if it is a JUnit setUp method
231:             */
232:            private boolean isJUnitSetupMethod() {
233:                String name = getName();
234:                return name.equals("setUp");
235:            }
236:
237:            /**
238:             *  Determine if this is a JUnit test method
239:             *
240:             * @return    true if it is a JUnit test method
241:             */
242:            private boolean isJUnitTestMethod() {
243:                String name = getName();
244:                return name.startsWith("test");
245:            }
246:
247:            /**
248:             *  Determine if this is a JUnit tearDown method
249:             *
250:             * @return    true if it is a JUnit tearDown method
251:             */
252:            private boolean isJUnitTeardownMethod() {
253:                String name = getName();
254:                return name.equals("tearDown");
255:            }
256:
257:            /**
258:             *  Determine if this is a JUnit suite method
259:             *
260:             * @return    true if it is a JUnit suite method
261:             */
262:            private boolean isJUnitSuiteMethod() {
263:                String name = getName();
264:                return name.equals("suite");
265:            }
266:
267:            /**
268:             *  Determine if this is s toString() method
269:             *
270:             * @return    true if it is a toString() suite method
271:             */
272:            private boolean isToStringMethod() {
273:                String name = getName();
274:                if (!name.equals("toString")) {
275:                    return false;
276:                }
277:
278:                // If it has JDK 1.5 attributes ignore them
279:                int childNo = node.skipAnnotations();
280:
281:                // If it has JDK 1.5 type parameters it cannot be a main() method.
282:                Node child = node.jjtGetChild(childNo);
283:                if (child instanceof  ASTTypeParameters) {
284:                    return false;
285:                }
286:
287:                //  Check for the void return type
288:                ASTResultType result = (ASTResultType) child;
289:                if (!result.hasAnyChildren()) {
290:                    return false;
291:                }
292:                String type = result.getImage();
293:
294:                ASTMethodDeclarator decl = (ASTMethodDeclarator) node
295:                        .jjtGetChild(childNo + 1);
296:                return hasNoParameters(decl);
297:            }
298:
299:            /**
300:             *  Determine if this is s toString() method
301:             *
302:             * @return    true if it is a toString() suite method
303:             */
304:            private boolean isEqualsMethod() {
305:                String name = getName();
306:                if (!name.equals("equals")) {
307:                    return false;
308:                }
309:                return true;
310:            }
311:
312:            /**
313:             *  Determine if this is s toString() method
314:             *
315:             * @return    true if it is a toString() suite method
316:             */
317:            private boolean isHashCodeMethod() {
318:                String name = getName();
319:                if (!name.equals("hashCode")) {
320:                    return false;
321:                }
322:                return true;
323:            }
324:
325:            /**
326:             *  Determine if this is s toString() method
327:             *
328:             * @return    true if it is a toString() suite method
329:             */
330:            private boolean isCloneMethod() {
331:                String name = getName();
332:                if (!name.equals("clone")) {
333:                    return false;
334:                }
335:                return true;
336:            }
337:
338:            /**
339:             *  Determine if this is s toString() method
340:             *
341:             * @return    true if it is a toString() suite method
342:             */
343:            private boolean isFinalizeMethod() {
344:                String name = getName();
345:                if (!name.equals("finalize")) {
346:                    return false;
347:                }
348:                return true;
349:            }
350:
351:            /**
352:             *  Determine if this is s toString() method
353:             *
354:             * @return    true if it is a toString() suite method
355:             */
356:            private boolean isListenerAddMethod() {
357:                String name = getName();
358:                if (!name.startsWith("add")) {
359:                    return false;
360:                }
361:                if (!name.endsWith("Listener")) {
362:                    return false;
363:                }
364:                operationType = "add";
365:                return true;
366:            }
367:
368:            /**
369:             *  Determine if this is s toString() method
370:             *
371:             * @return    true if it is a toString() suite method
372:             */
373:            private boolean isListenerRemoveMethod() {
374:                String name = getName();
375:                if (!name.startsWith("remove")) {
376:                    return false;
377:                }
378:                if (!name.endsWith("Listener")) {
379:                    return false;
380:                }
381:                operationType = "remove";
382:                return true;
383:            }
384:
385:            /**
386:             *  Determine if this is s toString() method
387:             *
388:             * @return    true if it is a toString() suite method
389:             */
390:            private boolean isInstanceMethod() {
391:                String name = getName();
392:                if (!name.equals("instance")) {
393:                    return false;
394:                }
395:                // If it has JDK 1.5 attributes ignore them
396:                int childNo = node.skipAnnotations();
397:
398:                // If it has JDK 1.5 type parameters it cannot be a instance() method.
399:                Node child = node.jjtGetChild(childNo);
400:                if (child instanceof  ASTTypeParameters) {
401:                    return false;
402:                }
403:
404:                //  Check for the void return type
405:                ASTResultType result = (ASTResultType) child;
406:                if (!result.hasAnyChildren()) {
407:                    return false;
408:                }
409:                String type = result.getImage();
410:                System.out.println("isInstanceMethod(): type=" + type);
411:
412:                ASTMethodDeclarator decl = (ASTMethodDeclarator) node
413:                        .jjtGetChild(childNo + 1);
414:                return hasNoParameters(decl);
415:            }
416:
417:            /**
418:             *  Returns the name of the method
419:             *
420:             * @return    the name
421:             */
422:            private String getName() {
423:                int childNo = node.skipAnnotations();
424:                if (node.jjtGetChild(childNo) instanceof  ASTTypeParameters) {
425:                    childNo++;
426:                }
427:                ASTMethodDeclarator decl = (ASTMethodDeclarator) node
428:                        .jjtGetChild(childNo + 1);
429:                return decl.getName();
430:            }
431:
432:            private boolean hasNoParameters(ASTMethodDeclarator method) {
433:                ASTFormalParameters decl = (ASTFormalParameters) method
434:                        .jjtGetFirstChild();
435:                if (!decl.hasAnyChildren()) {
436:                    return true;
437:                }
438:                //System.out.println("MethodAnalyser.hasNoParameters(): decl.jjtGetFirstChild()="+decl.jjtGetFirstChild());
439:                ASTFormalParameter params = (ASTFormalParameter) decl
440:                        .jjtGetFirstChild();
441:                return (!params.hasAnyChildren());
442:            }
443:
444:            /**
445:             *  Guesses the name ofthe setter or getter's attribute
446:             *
447:             * @return    the attribute name
448:             */
449:            private String getAttributeName() {
450:                String name = getName();
451:
452:                if (!isGetter() && !isSetter() && !isAdder() && !isListener()) {
453:                    return "";
454:                } else if (name.startsWith("is")) {
455:                    return name.substring(2);
456:                } else if (name.endsWith("Listener")) {
457:                    int start = (name.startsWith("add")) ? 3 : 6;
458:                    return name.substring(start, name.length() - 8);
459:                } else {
460:                    return name.substring(3);
461:                }
462:            }
463:
464:            /**
465:             *  Gets the ParameterDescription attribute of the MethodAnalyzer object
466:             *
467:             * @param  bundle  Description of Parameter
468:             * @param  param   Description of Parameter
469:             * @return         The ParameterDescription value
470:             */
471:            private String getParameterDescription(FileSettings bundle,
472:                    String param) {
473:                String pattern = "";
474:
475:                if (isSetter()) {
476:                    pattern = bundle.getProperty("setter.param.descr",
477:                            "The new {0} value");
478:                } else if (isListener()) {
479:                    pattern = bundle.getProperty("listener.param.descr",
480:                            "Contains the {0}Listener for {0}Event data.");
481:                } else if (isEqualsMethod()) {
482:                    pattern = bundle.getProperty("equals.param.descr",
483:                            "the reference object with which to compare.");
484:                } else if (isAdder()) {
485:                    pattern = bundle.getProperty("adder.param.descr",
486:                            "The feature to be added to the {0} attribute");
487:                } else if (isMainMethod()) {
488:                    pattern = bundle.getProperty("main.param.descr",
489:                            "The command line arguments");
490:                } else {
491:                    pattern = jt.getParamDescr();
492:                }
493:
494:                if (pattern == null || pattern.equals("")) {
495:                    return null;
496:                }
497:
498:                return createDescription(pattern, getAttributeName(), param);
499:            }
500:
501:            /**
502:             *  Gets the ReturnDescription attribute of the MethodAnalyzer object
503:             *
504:             * @param  bundle  Description of Parameter
505:             * @return         The ReturnDescription value
506:             */
507:            private String getReturnDescription(FileSettings bundle) {
508:                String pattern = "";
509:
510:                if (isToStringMethod()) {
511:                    pattern = bundle.getProperty("tostring.return.descr",
512:                            "A string representation of the {0} object.");
513:                } else if (isEqualsMethod()) {
514:                    pattern = bundle
515:                            .getProperty(
516:                                    "equals.return.descr",
517:                                    "<tt>true</tt> if this object is the same as the obj argument; <tt>false</tt> otherwise.");
518:                } else if (isHashCodeMethod()) {
519:                    pattern = bundle.getProperty("hashcode.return.descr",
520:                            "The hash value for this {0} object.");
521:                } else if (isInstanceMethod()) {
522:                    pattern = bundle.getProperty("instance.return.descr",
523:                            "An instance of {0}.");
524:                } else if (isJUnitSuiteMethod()) {
525:                    pattern = bundle.getProperty("junit.suite.return.descr",
526:                            "The test suite");
527:                } else if (isJUnitSuiteMethod()) {
528:                    pattern = bundle.getProperty("clone.return.descr",
529:                            "A clone of this {0} object.");
530:                } else if (isGetter()) {
531:                    pattern = bundle.getProperty("getter.return.descr",
532:                            "The {0} value");
533:                } else {
534:                    pattern = jt.getReturnDescr();
535:                }
536:
537:                return createDescription(pattern, getAttributeName(), "");
538:            }
539:
540:            /**
541:             *  Description of the Method
542:             *
543:             * @param  bundle  Description of Parameter
544:             */
545:            private void finishReturn(FileSettings bundle) {
546:                int childNo = node.skipAnnotations();
547:                if (node.jjtGetChild(childNo) instanceof  ASTTypeParameters) {
548:                    childNo++;
549:                }
550:                ASTResultType result = (ASTResultType) node
551:                        .jjtGetChild(childNo);
552:                if (result.hasAnyChildren()) {
553:                    if (!jdi.contains("@return")) {
554:                        jdi.require("@return", getReturnDescription(bundle));
555:                    }
556:                }
557:            }
558:
559:            /**
560:             *  Description of the Method
561:             *
562:             * @param  bundle  Description of Parameter
563:             */
564:            private void finishParameters(FileSettings bundle) {
565:                int childNo = node.skipAnnotations();
566:                if (node.jjtGetChild(childNo++) instanceof  ASTTypeParameters) {
567:                    childNo++;
568:                }
569:                ASTMethodDeclarator decl = (ASTMethodDeclarator) node
570:                        .jjtGetChild(childNo);
571:                ASTFormalParameters params = (ASTFormalParameters) decl
572:                        .jjtGetFirstChild();
573:
574:                int childCount = params.jjtGetNumChildren();
575:                for (int ndx = 0; ndx < childCount; ndx++) {
576:                    ASTFormalParameter nextParam = (ASTFormalParameter) params
577:                            .jjtGetChild(ndx);
578:                    childNo = nextParam.skipAnnotations();
579:                    ASTVariableDeclaratorId id = (ASTVariableDeclaratorId) nextParam
580:                            .jjtGetChild(childNo + 1);
581:                    if (!jdi.contains("@param", id.getName())) {
582:                        jdi.require("@param", id.getName(),
583:                                getParameterDescription(bundle, id.getName()));
584:                    }
585:                }
586:            }
587:
588:            /**
589:             *  Sort the "@param" elements of the method.
590:             *
591:             * @since    JRefactory 2.7.00
592:             */
593:            private void sortParameters() {
594:                int childNo = node.skipAnnotations();
595:                if (node.jjtGetChild(childNo++) instanceof  ASTTypeParameters) {
596:                    childNo++;
597:                }
598:                ASTMethodDeclarator decl = (ASTMethodDeclarator) node
599:                        .jjtGetChild(childNo);
600:                ASTFormalParameters params = (ASTFormalParameters) decl
601:                        .jjtGetFirstChild();
602:
603:                int childCount = params.jjtGetNumChildren();
604:                String[] methodParams = new String[childCount];
605:                for (int ndx = 0; ndx < childCount; ndx++) {
606:                    ASTFormalParameter nextParam = (ASTFormalParameter) params
607:                            .jjtGetChild(ndx);
608:                    childNo = nextParam.skipAnnotations();
609:                    ASTVariableDeclaratorId id = (ASTVariableDeclaratorId) nextParam
610:                            .jjtGetChild(childNo + 1);
611:                    methodParams[ndx] = id.getName();
612:                }
613:                jdi.sort("@param", methodParams);
614:            }
615:
616:            /**
617:             *  Description of the Method
618:             *
619:             * @param  bundle  Description of Parameter
620:             */
621:            private void finishExceptions(FileSettings bundle) {
622:                if ((node.jjtGetNumChildren() > 2)
623:                        && (node.jjtGetChild(2) instanceof  ASTNameList)) {
624:                    String exceptionTagName = jt.getExceptionTag();
625:
626:                    ASTNameList exceptions = (ASTNameList) node.jjtGetChild(2);
627:                    int childCount = exceptions.jjtGetNumChildren();
628:                    for (int ndx = 0; ndx < childCount; ndx++) {
629:                        ASTName name = (ASTName) exceptions.jjtGetChild(ndx);
630:                        if (!(jdi.contains("@exception", name.getName())
631:                                || jdi.contains("@throws", name.getName()) || jdi
632:                                .contains(exceptionTagName, name.getName()))) {
633:                            jdi.require(exceptionTagName, name.getName(), jt
634:                                    .getExceptionDescr());
635:                        }
636:                    }
637:                }
638:            }
639:
640:            /**
641:             *  Create the description string
642:             *
643:             * @param  pattern    Description of Parameter
644:             * @param  attribute  Description of Parameter
645:             * @param  className  Description of Parameter
646:             * @return            the expanded string
647:             */
648:            private String createDescription(String pattern, String attribute,
649:                    String className) {
650:                if (pattern == null || pattern.length() == 0) {
651:                    return "";
652:                }
653:                //  Description of the constructor
654:                Object[] nameArray = new Object[6];
655:                nameArray[0] = attribute;
656:                nameArray[1] = className;
657:                nameArray[2] = (node.isStatic()) ? "class" : "object";
658:                nameArray[3] = lowerCaseFirstLetter(attribute);
659:                nameArray[4] = pvn.parse(attribute);
660:                nameArray[5] = operationType; // add, remove, etc.
661:
662:                return MessageFormat.format(pattern, nameArray);
663:            }
664:
665:            /**
666:             *  Require the description
667:             *
668:             * @param  bundle     Description of Parameter
669:             * @param  className  Description of Parameter
670:             */
671:            private void requireDescription(FileSettings bundle,
672:                    String className) {
673:                String pattern = "";
674:
675:                try {
676:                    if (isJUnitSetupMethod()) {
677:                        pattern = bundle.getProperty("junit.setUp.descr",
678:                                "The JUnit setup method");
679:                    } else if (isJUnitTestMethod()) {
680:                        pattern = bundle.getProperty("junit.test.descr",
681:                                "A unit test for JUnit");
682:                    } else if (isJUnitTeardownMethod()) {
683:                        pattern = bundle.getProperty("junit.tearDown.descr",
684:                                "The teardown method for JUnit");
685:                    } else if (isJUnitSuiteMethod()) {
686:                        pattern = bundle.getProperty("junit.suite.descr",
687:                                "A suite of unit tests for JUnit");
688:                    } else if (isListenerAddMethod()) {
689:                        pattern = bundle
690:                                .getProperty(
691:                                        "listener.add.descr",
692:                                        "Adds the specified {0} listener to receive {0} events from this component. If listener l is null, no exception is thrown and no action is performed.");
693:                    } else if (isListenerRemoveMethod()) {
694:                        pattern = bundle
695:                                .getProperty(
696:                                        "listener.remove.descr",
697:                                        "Removes the specified {0} listener so that it no longer receives {0} events from this component. This method performs no function, nor does it throw an exception, if the listener specified by the argument was not previously added to this component. If listener l is null, no exception is thrown and no action is performed.");
698:                    } else if (isGetter()) {
699:                        pattern = bundle.getProperty("getter.descr",
700:                                "Gets the {0} attribute of the {1} {2}");
701:                    } else if (isSetter()) {
702:                        pattern = bundle.getProperty("setter.descr",
703:                                "Sets the {0} attribute of the {1} {2}");
704:                    } else if (isRunMethod()) {
705:                        pattern = bundle.getProperty("run.descr",
706:                                "Main processing method for the {1} {2}");
707:                    } else if (isMainMethod()) {
708:                        pattern = bundle.getProperty("main.descr",
709:                                "The main program for the {1} {2}");
710:                    } else if (isToStringMethod()) {
711:                        pattern = bundle
712:                                .getProperty("tostring.descr",
713:                                        "Converts to a String representation of the {0} object.");
714:                    } else if (isEqualsMethod()) {
715:                        pattern = bundle.getProperty("equals.descr",
716:                                "Compares this {0} to the parameter.");
717:                    } else if (isHashCodeMethod()) {
718:                        pattern = bundle.getProperty("hashcode.descr",
719:                                "Computes a hash value for this {0} object.");
720:                    } else if (isCloneMethod()) {
721:                        pattern = bundle.getProperty("clone.descr",
722:                                "Creates an exact copy of this {0} object.");
723:                    } else if (isFinalizeMethod()) {
724:                        pattern = bundle
725:                                .getProperty(
726:                                        "finalize.descr",
727:                                        "Overrides the finalize method to dispose of system resources or to perform other cleanup when the {1} object is garbage collected.");
728:                    } else if (isInstanceMethod()) {
729:                        pattern = bundle.getProperty("instance.descr",
730:                                "Gets an instance of this {0} class.");
731:                    } else if (isAdder()) {
732:                        pattern = bundle
733:                                .getProperty("adder.descr",
734:                                        "Adds a feature to the {0} attribute of the {1} {2}");
735:                    } else {
736:                        pattern = bundle.getProperty("method.descr",
737:                                "Description of the Method");
738:                    }
739:                } catch (Exception e) {
740:                    pattern = "";
741:                }
742:
743:                String message = createDescription(pattern, getAttributeName(),
744:                        className);
745:                if (bundle.getInteger("javadoc.indent") < 1) {
746:                    message = " " + message;
747:                } else {
748:                    message = DescriptionPadder.padBuffer(message, bundle);
749:                }
750:                jdi.require("", message);
751:            }
752:
753:            /**
754:             *  Description of the Method
755:             *
756:             * @param  value  Description of Parameter
757:             * @return        Description of the Returned Value
758:             */
759:            private String lowerCaseFirstLetter(String value) {
760:                if ((value == null) || (value.length() == 0)) {
761:                    return "";
762:                }
763:                if (value.length() == 1) {
764:                    return value.toLowerCase();
765:                }
766:                return Character.toLowerCase(value.charAt(0))
767:                        + value.substring(1);
768:            }
769:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.