KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tasklist > javadoc > AutoCommenterMethod


1 package org.netbeans.modules.tasklist.javadoc;
2
3 import org.openide.src.ElementFormat;
4 import org.openide.src.JavaDoc;
5 import org.openide.src.JavaDocSupport;
6 import org.openide.src.JavaDocTag;
7 import org.openide.src.MethodElement;
8 import org.openide.src.SourceException;
9 import org.openide.src.Type;
10 import org.openide.util.NbBundle;
11 import org.netbeans.modules.tasklist.javadoc.ext.JavaTagNames;
12
13 public class AutoCommenterMethod extends AutoCommenterConstructor {
14     private static final ElementFormat nameFormat = new ElementFormat( "{m} {r} {n} ( {p} )" ); // NOI18N
15

16     private static final String JavaDoc[] NOT_PERMITTED_TAGS = {
17         JavaTagNames.TAG_AUTHOR,
18         JavaTagNames.TAG_SERIAL,
19         JavaTagNames.TAG_SERIALFIELD,
20         JavaTagNames.TAG_VERSION
21     };
22
23     public AutoCommenterMethod( MethodElement element ) {
24         super( element );
25     }
26
27     JavaDoc getJavaDoc() {
28         return ((MethodElement)srcElement).getJavaDoc();
29     }
30
31     String JavaDoc typeToString() {
32         return "method"; // NOI18N
33
}
34
35     String JavaDoc[] getNotPermittedTags() {
36         return NOT_PERMITTED_TAGS;
37     }
38
39     boolean elementTagsOk() {
40         boolean superOk = super.elementTagsOk();
41         boolean retOk = checkReturnType( false );
42         return !superOk ? false : retOk;
43     }
44
45     private boolean checkReturnType( boolean checkOnly ) {
46
47         boolean retOk = true;
48
49         Type ret = ((MethodElement)srcElement).getReturn();
50         JavaDocTag[] retTags = ((MethodElement)srcElement).getJavaDoc().getTags( JavaTagNames.TAG_RETURN );
51
52         if ( ret == Type.VOID && retTags.length > 0 ) {
53             if ( checkOnly ) {
54                 return false;
55             }
56             errorList.add(NbBundle.getMessage(AutoCommenter.class, "ERR_ReturnForVoid" ) ); //NOI18N
57
resolutionList.add(NbBundle.getMessage(AutoCommenter.class, "FIX_ReturnForVoid" ) ); //NOI18N
58
retOk = false;
59         }
60         else if ( ret != Type.VOID && retTags.length <= 0 ) {
61             if ( checkOnly ) {
62                 return false;
63             }
64             errorList.add( NbBundle.getMessage(AutoCommenter.class, "ERR_NoReturn") ); //NOI18N
65
resolutionList.add(NbBundle.getMessage(AutoCommenter.class, "FIX_NoReturn") ); //NOI18N
66
retOk = false;
67         } else if ( ret != Type.VOID && retTags.length > 1 ) {
68             if ( checkOnly) {
69                 return false;
70             }
71             errorList.add( NbBundle.getMessage(AutoCommenter.class, "ERR_DuplicatedReturn") ); //NOI18N
72
resolutionList.add(NbBundle.getMessage(AutoCommenter.class, "FIX_DuplicatedReturn") ); //NOI18N
73
retOk = false;
74         }
75
76         return retOk;
77     }
78
79
80     boolean isCorrectable() {
81
82         if ( super.isCorrectable() )
83             return true;
84
85         return !checkReturnType( true );
86     }
87
88     void autoCorrect() throws SourceException {
89         JavaDoc jdTemp = JavaDocSupport.createMethodJavaDoc( getJavaDoc().getRawText() );
90         super.autoCorrect( jdTemp );
91
92         if (!checkReturnType( true ) ) {
93             if ( ((MethodElement)srcElement).getReturn() != Type.VOID ) {
94                 jdTemp.changeTags(
95                     new JavaDocTag[] { JavaDocSupport.createTag( JavaTagNames.TAG_RETURN, "" ) }, // NOI18N
96
JavaDoc.ADD );
97             }
98             else {
99                 JavaDocTag toRemove[] = jdTemp.getTags( JavaTagNames.TAG_RETURN );
100
101                 jdTemp.changeTags( toRemove, JavaDoc.REMOVE );
102             }
103         }
104
105         getJavaDoc().setRawText( jdTemp.getRawText() );
106
107     }
108
109     ElementFormat getNameFormat () {
110         return nameFormat;
111     }
112 }
113
114
Popular Tags