This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 63953
Collapse All | Expand All

(-)nbproject/project.properties (-1 / +1 lines)
Lines 1-3 Link Here
1
javac.compilerargs=-Xlint:unchecked
1
javac.compilerargs=-Xlint:unchecked
2
javac.source=1.5
2
javac.source=1.5
3
spec.version.base=1.0.0
3
spec.version.base=2.0.0
(-)nbproject/project.xml (-4 / +45 lines)
Lines 6-11 Link Here
6
            <code-name-base>org.netbeans.modules.showtodos</code-name-base>
6
            <code-name-base>org.netbeans.modules.showtodos</code-name-base>
7
            <module-dependencies>
7
            <module-dependencies>
8
                <dependency>
8
                <dependency>
9
                    <code-name-base>org.netbeans.modules.editor</code-name-base>
10
                    <build-prerequisite/>
11
                    <compile-dependency/>
12
                    <run-dependency>
13
                        <release-version>3</release-version>
14
                        <specification-version>1.42</specification-version>
15
                    </run-dependency>
16
                </dependency>
17
                <dependency>
9
                    <code-name-base>org.netbeans.modules.editor.lib</code-name-base>
18
                    <code-name-base>org.netbeans.modules.editor.lib</code-name-base>
10
                    <build-prerequisite/>
19
                    <build-prerequisite/>
11
                    <compile-dependency/>
20
                    <compile-dependency/>
Lines 42-47 Link Here
42
                    </run-dependency>
51
                    </run-dependency>
43
                </dependency>
52
                </dependency>
44
                <dependency>
53
                <dependency>
54
                    <code-name-base>org.netbeans.modules.editor.util</code-name-base>
55
                    <build-prerequisite/>
56
                    <compile-dependency/>
57
                    <run-dependency>
58
                        <release-version>1</release-version>
59
                        <specification-version>1.28</specification-version>
60
                    </run-dependency>
61
                </dependency>
62
                <dependency>
45
                    <code-name-base>org.netbeans.modules.lexer</code-name-base>
63
                    <code-name-base>org.netbeans.modules.lexer</code-name-base>
46
                    <build-prerequisite/>
64
                    <build-prerequisite/>
47
                    <compile-dependency/>
65
                    <compile-dependency/>
Lines 60-81 Link Here
60
                    </run-dependency>
78
                    </run-dependency>
61
                </dependency>
79
                </dependency>
62
                <dependency>
80
                <dependency>
63
                    <code-name-base>org.openide.util</code-name-base>
81
                    <code-name-base>org.openide.filesystems</code-name-base>
64
                    <build-prerequisite/>
82
                    <build-prerequisite/>
65
                    <compile-dependency/>
83
                    <compile-dependency/>
66
                    <run-dependency>
84
                    <run-dependency>
85
                        <specification-version>7.21</specification-version>
86
                    </run-dependency>
87
                </dependency>
88
                <dependency>
89
                    <code-name-base>org.openide.loaders</code-name-base>
90
                    <build-prerequisite/>
91
                    <compile-dependency/>
92
                    <run-dependency>
67
                        <specification-version>6.5</specification-version>
93
                        <specification-version>6.5</specification-version>
68
                    </run-dependency>
94
                    </run-dependency>
69
                </dependency>
95
                </dependency>
70
            <dependency>
96
            <dependency>
71
                    <code-name-base>org.netbeans.modules.editor.deprecated.pre61settings</code-name-base>
97
                    <code-name-base>org.openide.nodes</code-name-base>
72
                    <build-prerequisite/>
98
                    <build-prerequisite/>
73
                    <compile-dependency/>
99
                    <compile-dependency/>
74
                    <run-dependency>
100
                    <run-dependency>
75
                        <release-version>0-1</release-version>
101
                        <specification-version>7.9</specification-version>
76
                        <specification-version>1.0</specification-version>
77
                    </run-dependency>
102
                    </run-dependency>
78
                </dependency>
103
                </dependency>
104
                <dependency>
105
                    <code-name-base>org.openide.text</code-name-base>
106
                    <build-prerequisite/>
107
                    <compile-dependency/>
108
                    <run-dependency>
109
                        <specification-version>6.22</specification-version>
110
                    </run-dependency>
111
                </dependency>
112
                <dependency>
113
                    <code-name-base>org.openide.util</code-name-base>
114
                    <build-prerequisite/>
115
                    <compile-dependency/>
116
                    <run-dependency>
117
                        <specification-version>6.5</specification-version>
118
                    </run-dependency>
119
                </dependency>
79
            </module-dependencies>
120
            </module-dependencies>
80
            <public-packages/>
121
            <public-packages/>
81
        </data>
122
        </data>
(-)src/org/netbeans/modules/showtodos/HighlightTodos.java (-66 / +5 lines)
Lines 1-7 Link Here
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
3
 *
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
4
 * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.
5
 *
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
7
 * General Public License Version 2 only ("GPL") or the Common
Lines 40-72 Link Here
40
 */
40
 */
41
package org.netbeans.modules.showtodos;
41
package org.netbeans.modules.showtodos;
42
42
43
import java.util.LinkedList;
43
import static org.netbeans.modules.showtodos.TodoSourceParsing.parse;
44
import java.util.List;
44
import java.util.List;
45
45
46
import java.util.logging.Level;
46
import java.util.logging.Level;
47
import java.util.logging.Logger;
47
import java.util.logging.Logger;
48
import javax.swing.JEditorPane;
48
import javax.swing.JEditorPane;
49
import javax.swing.text.AttributeSet;
49
import javax.swing.text.AttributeSet;
50
import javax.swing.text.BadLocationException;
51
import javax.swing.text.Document;
50
import javax.swing.text.Document;
52
import javax.swing.text.JTextComponent;
51
import javax.swing.text.JTextComponent;
53
52
54
import org.netbeans.api.editor.mimelookup.MimeLookup;
53
import org.netbeans.api.editor.mimelookup.MimeLookup;
55
import org.netbeans.api.editor.settings.FontColorSettings;
54
import org.netbeans.api.editor.settings.FontColorSettings;
56
import org.netbeans.api.lexer.Token;
57
import org.netbeans.api.lexer.TokenHierarchy;
58
import org.netbeans.api.lexer.TokenSequence;
59
import org.netbeans.editor.BaseDocument;
55
import org.netbeans.editor.BaseDocument;
60
import org.netbeans.editor.FinderFactory;
61
import org.netbeans.editor.Utilities;
62
import org.netbeans.modules.tasklist.todo.settings.Settings;
63
import org.netbeans.spi.editor.highlighting.HighlightsChangeListener;
56
import org.netbeans.spi.editor.highlighting.HighlightsChangeListener;
64
import org.netbeans.spi.editor.highlighting.HighlightsContainer;
57
import org.netbeans.spi.editor.highlighting.HighlightsContainer;
65
import org.netbeans.spi.editor.highlighting.HighlightsLayer;
58
import org.netbeans.spi.editor.highlighting.HighlightsLayer;
66
import org.netbeans.spi.editor.highlighting.HighlightsLayerFactory;
59
import org.netbeans.spi.editor.highlighting.HighlightsLayerFactory;
67
import org.netbeans.spi.editor.highlighting.HighlightsSequence;
60
import org.netbeans.spi.editor.highlighting.HighlightsSequence;
68
import org.netbeans.spi.editor.highlighting.ZOrder;
61
import org.netbeans.spi.editor.highlighting.ZOrder;
69
import org.openide.util.Exceptions;
70
import org.openide.util.Lookup;
62
import org.openide.util.Lookup;
71
63
72
64
Lines 98-164 Link Here
98
        }
90
        }
99
        
91
        
100
        AttributeSet coloring = fcs.getTokenFontColors("todo-tasks"); // NOI18N
92
        AttributeSet coloring = fcs.getTokenFontColors("todo-tasks"); // NOI18N
101
        
102
        if (coloring == null) {
93
        if (coloring == null) {
103
            return HighlightsSequence.EMPTY;
94
            return HighlightsSequence.EMPTY;
104
        }
95
        }
105
        
96
        
106
        List<int[]> highlights = new LinkedList<int[]>();
97
        return new SeqImpl(parse(doc, startOffset, endOffset), coloring);
107
108
        TokenHierarchy th = TokenHierarchy.get(doc);
109
        TokenSequence ts = null;
110
111
        if (th != null) {
112
            ts = th.tokenSequence();
113
        }
98
        }
114
99
115
        try {
116
            startOffset = Utilities.getRowStart(doc, startOffset);
117
            endOffset = Math.min(doc.getLength(), endOffset);
118
        
119
            for (String word : Settings.getDefault().getPatterns()) {
120
                int pos = startOffset;
121
122
                // Search from pos to endPos for TODO markers.
123
                while (pos < endOffset) {
124
                    FinderFactory.WholeWordsFwdFinder finder =
125
                            new FinderFactory.WholeWordsFwdFinder(doc, word, true);
126
                    int next = doc.find(finder, pos, endOffset);
127
128
                    if ((next >= startOffset) && (next < endOffset)) {
129
                        // See if it looks like a token we care about (comments)
130
                        if (ts != null) {
131
                            ts.move(next);
132
133
                            if (ts.moveNext()) {
134
                                Token token = ts.token();
135
                                pos = Math.min(Utilities.getRowEnd(doc, next), ts.offset() + token.length());
136
137
                                if (token != null) {
138
                                    String category = token.id().primaryCategory();
139
140
                                    if ("comment".equals(category)) { // NOI18N
141
                                        highlights.add(new int[]{next, pos});
142
                                    }
143
                                }
144
                            } else {
145
                                pos = next + word.length();
146
                            }
147
                        } else {
148
                            pos = next + word.length();
149
                        }
150
                    } else {
151
                        break;
152
                    }
153
                }
154
            }
155
        } catch (BadLocationException e) {
156
            Exceptions.printStackTrace(e);
157
        }
158
        
159
        return new SeqImpl(highlights, coloring);
160
    }
161
162
    public void addHighlightsChangeListener(HighlightsChangeListener listener) {
100
    public void addHighlightsChangeListener(HighlightsChangeListener listener) {
163
    }
101
    }
164
102
Lines 184-191 Link Here
184
        }
122
        }
185
123
186
        public boolean moveNext() {
124
        public boolean moveNext() {
187
            if (highlights.isEmpty())
125
            if (highlights.isEmpty()) {
188
                return false;
126
                return false;
127
           }
189
            
128
            
190
            current = highlights.remove(0);
129
            current = highlights.remove(0);
191
            
130
            
(-)src/org/netbeans/modules/showtodos/TodoAnnotation.java (+62 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 *
35
 * Contributor(s):
36
 *
37
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
38
 */
39
package org.netbeans.modules.showtodos;
40
41
import org.openide.text.Annotation;
42
43
/**
44
 * @author Michel Graciano
45
 */
46
public final class TodoAnnotation extends Annotation {
47
   private final String message;
48
49
   public TodoAnnotation(String message) {
50
      this.message = message;
51
   }
52
53
   @Override
54
   public String getAnnotationType() {
55
      return "org-netbeans-spi-editor-hints-parser_annotation_todo";
56
   }
57
58
   @Override
59
   public String getShortDescription() {
60
      return message;
61
   }
62
}
(-)src/org/netbeans/modules/showtodos/TodoAnnotationProvider.java (+184 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 *
35
 * Contributor(s):
36
 *
37
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
38
 */
39
package org.netbeans.modules.showtodos;
40
41
import java.beans.PropertyChangeEvent;
42
import java.beans.PropertyChangeListener;
43
import javax.swing.text.BadLocationException;
44
import static org.netbeans.modules.showtodos.TodoSourceParsing.parseForAnnotatable;
45
import java.io.IOException;
46
import java.lang.ref.Reference;
47
import java.lang.ref.WeakReference;
48
import java.util.ArrayList;
49
import java.util.Collection;
50
import java.util.List;
51
import java.util.Map;
52
import java.util.WeakHashMap;
53
import javax.swing.event.DocumentEvent;
54
import javax.swing.event.DocumentListener;
55
import javax.swing.text.Document;
56
import org.netbeans.editor.BaseDocument;
57
import org.netbeans.lib.editor.util.swing.DocumentListenerPriority;
58
import org.netbeans.lib.editor.util.swing.DocumentUtilities;
59
import org.netbeans.modules.tasklist.todo.settings.Settings;
60
import org.openide.cookies.EditorCookie;
61
import org.openide.filesystems.FileObject;
62
import org.openide.loaders.DataObject;
63
import org.openide.text.Annotatable;
64
import org.openide.text.Annotation;
65
import org.openide.text.AnnotationProvider;
66
import org.openide.text.Line;
67
import org.openide.util.Exceptions;
68
import org.openide.util.Lookup;
69
import org.openide.util.RequestProcessor;
70
import org.openide.util.WeakListeners;
71
import org.openide.util.lookup.ServiceProvider;
72
73
/**
74
 * @author Michel Graciano
75
 */
76
@ServiceProvider(service = AnnotationProvider.class)
77
public class TodoAnnotationProvider implements AnnotationProvider {
78
   private static final RequestProcessor requestProcessor =
79
         new RequestProcessor("TODO Annotation Parser", 2);
80
   private final Map<FileObject, Collection<Annotation>> file2annotation =
81
         new WeakHashMap<FileObject, Collection<Annotation>>();
82
83
   public void annotate(Line.Set lines, Lookup context) {
84
      final DataObject dataObj = context.lookup(DataObject.class);
85
      new ScanningListener().attachTo(dataObj);
86
      annotate(dataObj);
87
   }
88
89
   private void annotate(final DataObject dataObj) {
90
      try {
91
         final FileObject fo = dataObj.getPrimaryFile();
92
         if (file2annotation.containsKey(fo)) {
93
            for (Annotation annotation : file2annotation.get(fo)) {
94
               annotation.detach();
95
            }
96
         }
97
         final List<Annotation> annotations =
98
               new ArrayList<Annotation>();
99
         final BaseDocument doc = documentFor(dataObj);
100
         for (Annotatable annotatable : parse(doc)) {
101
            final TodoAnnotation ann =
102
                  new TodoAnnotation(annotatable.getText());
103
            ann.attach(annotatable);
104
            annotations.add(ann);
105
         }
106
         file2annotation.put(fo, annotations);
107
      } catch (BadLocationException ex) {
108
         Exceptions.printStackTrace(ex);
109
      }
110
   }
111
112
   private List<Annotatable> parse(final BaseDocument doc) throws
113
         BadLocationException {
114
      return parseForAnnotatable(doc);
115
   }
116
117
   private static BaseDocument documentFor(final DataObject ob) {
118
      try {
119
         EditorCookie ck = ob.getCookie(EditorCookie.class);
120
         if (ck != null) {
121
            return (BaseDocument)ck.openDocument();
122
         }
123
      } catch (IOException ioe) {
124
         Exceptions.printStackTrace(ioe);
125
      }
126
      return null;
127
   }
128
129
   private class ScanningListener implements DocumentListener,
130
         PropertyChangeListener, Runnable {
131
      private static final int AUTO_SCANNING_DELAY = 2000; //ms
132
      private final RequestProcessor.Task parseTask;
133
      private Reference<DataObject> dobref;
134
135
      ScanningListener() {
136
         parseTask = requestProcessor.create(this);
137
      }
138
139
      public void insertUpdate(DocumentEvent e) {
140
         change();
141
      }
142
143
      public void changedUpdate(DocumentEvent e) {
144
      }
145
146
      public void removeUpdate(DocumentEvent e) {
147
         change();
148
      }
149
150
      public void propertyChange(PropertyChangeEvent evt) {
151
         if (Settings.PROP_SCAN_COMMENTS_ONLY.equals(evt.getPropertyName())) {
152
            change();
153
         }
154
      }
155
156
      private void attachTo(Document document) {
157
         DocumentUtilities.addDocumentListener(document, this,
158
               DocumentListenerPriority.AFTER_CARET_UPDATE);
159
         Settings.getDefault().addPropertyChangeListener(WeakListeners.
160
               propertyChange(this, Settings.getDefault()));
161
         restartTimer();
162
      }
163
164
      private void attachTo(DataObject dob) {
165
         dobref = new WeakReference<DataObject>(dob);
166
         attachTo(documentFor(dob));
167
      }
168
169
      private void change() {
170
         restartTimer();
171
      }
172
173
      private void restartTimer() {
174
         parseTask.schedule(AUTO_SCANNING_DELAY);
175
      }
176
177
      public void run() {
178
         DataObject dob = dobref.get();
179
         if (dob != null) {
180
            annotate(dob);
181
         }
182
      }
183
   }
184
}
(-)src/org/netbeans/modules/showtodos/TodoSourceParsing.java (+137 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 *
35
 * Contributor(s):
36
 *
37
 * Portions Copyrighted 2009 Sun Microsystems, Inc.
38
 */
39
package org.netbeans.modules.showtodos;
40
41
import java.util.LinkedList;
42
import java.util.List;
43
import javax.swing.text.BadLocationException;
44
import javax.swing.text.Document;
45
import org.netbeans.api.lexer.Token;
46
import org.netbeans.api.lexer.TokenHierarchy;
47
import org.netbeans.api.lexer.TokenSequence;
48
import org.netbeans.editor.BaseDocument;
49
import org.netbeans.editor.FinderFactory;
50
import org.netbeans.editor.Utilities;
51
import org.netbeans.modules.editor.NbEditorUtilities;
52
import org.netbeans.modules.tasklist.todo.settings.Settings;
53
import org.openide.text.Annotatable;
54
import org.openide.text.Line;
55
import org.openide.util.Exceptions;
56
57
/**
58
 *
59
 * @author Michel Graciano
60
 */
61
final class TodoSourceParsing {
62
   private TodoSourceParsing() {
63
   }
64
65
   static List<int[]> parse(final BaseDocument doc, int startOffset,
66
         int endOffset) {
67
      List<int[]> pairsPosition = new LinkedList<int[]>();
68
      TokenHierarchy th = TokenHierarchy.get(doc);
69
      TokenSequence ts = null;
70
71
      if (th != null) {
72
         ts = th.tokenSequence();
73
      }
74
75
      try {
76
         startOffset = Utilities.getRowStart(doc, startOffset);
77
         endOffset = Math.min(doc.getLength(), endOffset);
78
79
         for (String word : Settings.getDefault().getPatterns()) {
80
            int pos = startOffset;
81
82
            // Search from pos to endPos for TODO markers.
83
            while (pos < endOffset) {
84
               FinderFactory.WholeWordsFwdFinder finder =
85
                     new FinderFactory.WholeWordsFwdFinder(doc, word, true);
86
               int next = doc.find(finder, pos, endOffset);
87
88
               if ((next >= startOffset) && (next < endOffset)) {
89
                  // See if it looks like a token we care about (comments)
90
                  if (ts != null) {
91
                     ts.move(next);
92
93
                     if (ts.moveNext()) {
94
                        Token token = ts.token();
95
                        pos = Math.min(Utilities.getRowEnd(doc, next),
96
                              ts.offset() + token.length());
97
98
                        if (token != null) {
99
                           String category = token.id().primaryCategory();
100
                           final boolean commentsOnly = Settings.getDefault().
101
                                 isScanCommentsOnly();
102
                           final boolean valid = !commentsOnly || ("comment".
103
                                 equals(category) && commentsOnly); // NOI18N
104
                           if (valid) {
105
                              pairsPosition.add(new int[] {next, pos});
106
                           }
107
                        }
108
                     } else {
109
                        pos = next + word.length();
110
                     }
111
                  } else {
112
                     pos = next + word.length();
113
                  }
114
               } else {
115
                  break;
116
               }
117
            }
118
         }
119
      } catch (BadLocationException e) {
120
         Exceptions.printStackTrace(e);
121
      }
122
      return pairsPosition;
123
   }
124
125
   static List<Annotatable> parseForAnnotatable(final BaseDocument doc) throws BadLocationException {
126
      final List<Annotatable> lines = new LinkedList<Annotatable>();
127
      for (int[] pairs : parse(doc, doc.getStartPosition().getOffset(), doc.
128
            getEndPosition().getOffset())) {
129
         final String text = doc.getText(pairs[0], pairs[1] - pairs[0]);
130
         final Line line = NbEditorUtilities.getLine((Document)doc, pairs[1],
131
               false);
132
         final int initialIndex = line.getText().indexOf(text);
133
         lines.add(line.createPart(initialIndex, text.length()));
134
      }
135
      return lines;
136
   }
137
}

Return to bug 63953