KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tasklist > checkstyle > InsertFinalVariableKeywordSuggestionPerformer


1 /*
2  *
3  * InsertSpaceSuggestionPerformer.java
4  *
5  * Created on 8 January 2006, 22:28
6  *
7  */

8
9 package org.netbeans.modules.tasklist.checkstyle;
10
11 import javax.swing.text.BadLocationException JavaDoc;
12 import javax.swing.text.Document JavaDoc;
13 import javax.swing.text.Element JavaDoc;
14 import org.openide.ErrorManager;
15
16 /** TODO rename to InsertStringBeforeVariableDeclarationSuggestionPerformer and refactor accordingly.
17  *
18  * @version $Id: InsertFinalVariableKeywordSuggestionPerformer.java,v 1.2 2006/07/12 15:23:34 hair Exp $
19  * @author <a HREF="mailto:mick@wever.org">Michael Semb Wever</a>
20  */

21 public final class InsertFinalVariableKeywordSuggestionPerformer extends AbstractSuggestionPerformer{
22     
23     /** Creates a new instance of InsertSpaceSuggestionPerformer */
24     public InsertFinalVariableKeywordSuggestionPerformer(
25             final Document JavaDoc doc,
26             final int lineno,
27             final int column) {
28         
29         super(doc,lineno,column);
30     }
31
32     protected void performImpl(final int docPosition) throws BadLocationException JavaDoc {
33         
34         final Element JavaDoc elm = getElement(doc, lineno-1);
35         if (elm == null) {
36             ErrorManager.getDefault().log(ErrorManager.USER, "getElement was null");
37             return;
38         }
39
40         int wsStart = docPosition - 2;
41         try {
42             // hit identifier first (covers arrays and generics).
43
while( !Character.isJavaIdentifierPart( doc.getText(wsStart,1).charAt(0) ) ){
44                 --wsStart;
45             }
46             // look for beginning of identitifer
47
while( Character.isJavaIdentifierStart( doc.getText(wsStart,1).charAt(0) ) ){
48                 --wsStart;
49             }
50         } catch (BadLocationException JavaDoc ex) {
51             ErrorManager.getDefault().notify(ErrorManager.WARNING, ex);
52         }
53         doc.insertString(wsStart+1 ,"final ",null);
54     }
55     
56 }
57
Popular Tags