# This patch file was generated by NetBeans IDE
# Following Index: paths are relative to: /home/hmichel/projetos/netbeans/main/contrib/showtodos
# This patch can be applied using context Tools: Patch action on respective folder.
# It uses platform neutral UTF-8 encoding and \n newlines.
# Above lines and this line are ignored by the patching process.
Index: nbproject/project.properties
--- nbproject/project.properties Base (BASE)
+++ nbproject/project.properties Locally Modified (Based On LOCAL)
@@ -1,3 +1,3 @@
javac.compilerargs=-Xlint:unchecked
javac.source=1.5
-spec.version.base=1.0.0
+spec.version.base=2.0.0
Index: nbproject/project.xml
--- nbproject/project.xml Base (BASE)
+++ nbproject/project.xml Locally Modified (Based On LOCAL)
@@ -6,6 +6,15 @@
org.netbeans.modules.showtodos
+ org.netbeans.modules.editor
+
+
+
+ 3
+ 1.42
+
+
+
org.netbeans.modules.editor.lib
@@ -42,6 +51,15 @@
+ org.netbeans.modules.editor.util
+
+
+
+ 1
+ 1.28
+
+
+
org.netbeans.modules.lexer
@@ -60,22 +78,45 @@
- org.openide.util
+ org.openide.filesystems
+ 7.21
+
+
+
+ org.openide.loaders
+
+
+
6.5
- org.netbeans.modules.editor.deprecated.pre61settings
+ org.openide.nodes
- 0-1
- 1.0
+ 7.9
+
+ org.openide.text
+
+
+
+ 6.22
+
+
+
+ org.openide.util
+
+
+
+ 6.5
+
+
Index: src/org/netbeans/modules/showtodos/HighlightTodos.java
--- src/org/netbeans/modules/showtodos/HighlightTodos.java Base (BASE)
+++ src/org/netbeans/modules/showtodos/HighlightTodos.java Locally Modified (Based On LOCAL)
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
- * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common
@@ -40,33 +40,25 @@
*/
package org.netbeans.modules.showtodos;
-import java.util.LinkedList;
+import static org.netbeans.modules.showtodos.TodoSourceParsing.parse;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JEditorPane;
import javax.swing.text.AttributeSet;
-import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
import javax.swing.text.JTextComponent;
import org.netbeans.api.editor.mimelookup.MimeLookup;
import org.netbeans.api.editor.settings.FontColorSettings;
-import org.netbeans.api.lexer.Token;
-import org.netbeans.api.lexer.TokenHierarchy;
-import org.netbeans.api.lexer.TokenSequence;
import org.netbeans.editor.BaseDocument;
-import org.netbeans.editor.FinderFactory;
-import org.netbeans.editor.Utilities;
-import org.netbeans.modules.tasklist.todo.settings.Settings;
import org.netbeans.spi.editor.highlighting.HighlightsChangeListener;
import org.netbeans.spi.editor.highlighting.HighlightsContainer;
import org.netbeans.spi.editor.highlighting.HighlightsLayer;
import org.netbeans.spi.editor.highlighting.HighlightsLayerFactory;
import org.netbeans.spi.editor.highlighting.HighlightsSequence;
import org.netbeans.spi.editor.highlighting.ZOrder;
-import org.openide.util.Exceptions;
import org.openide.util.Lookup;
@@ -98,67 +90,13 @@
}
AttributeSet coloring = fcs.getTokenFontColors("todo-tasks"); // NOI18N
-
if (coloring == null) {
return HighlightsSequence.EMPTY;
}
- List highlights = new LinkedList();
-
- TokenHierarchy th = TokenHierarchy.get(doc);
- TokenSequence ts = null;
-
- if (th != null) {
- ts = th.tokenSequence();
+ return new SeqImpl(parse(doc, startOffset, endOffset), coloring);
}
- try {
- startOffset = Utilities.getRowStart(doc, startOffset);
- endOffset = Math.min(doc.getLength(), endOffset);
-
- for (String word : Settings.getDefault().getPatterns()) {
- int pos = startOffset;
-
- // Search from pos to endPos for TODO markers.
- while (pos < endOffset) {
- FinderFactory.WholeWordsFwdFinder finder =
- new FinderFactory.WholeWordsFwdFinder(doc, word, true);
- int next = doc.find(finder, pos, endOffset);
-
- if ((next >= startOffset) && (next < endOffset)) {
- // See if it looks like a token we care about (comments)
- if (ts != null) {
- ts.move(next);
-
- if (ts.moveNext()) {
- Token token = ts.token();
- pos = Math.min(Utilities.getRowEnd(doc, next), ts.offset() + token.length());
-
- if (token != null) {
- String category = token.id().primaryCategory();
-
- if ("comment".equals(category)) { // NOI18N
- highlights.add(new int[]{next, pos});
- }
- }
- } else {
- pos = next + word.length();
- }
- } else {
- pos = next + word.length();
- }
- } else {
- break;
- }
- }
- }
- } catch (BadLocationException e) {
- Exceptions.printStackTrace(e);
- }
-
- return new SeqImpl(highlights, coloring);
- }
-
public void addHighlightsChangeListener(HighlightsChangeListener listener) {
}
@@ -184,8 +122,9 @@
}
public boolean moveNext() {
- if (highlights.isEmpty())
+ if (highlights.isEmpty()) {
return false;
+ }
current = highlights.remove(0);
Index: src/org/netbeans/modules/showtodos/TodoAnnotation.java
--- src/org/netbeans/modules/showtodos/TodoAnnotation.java Base (BASE)
+++ src/org/netbeans/modules/showtodos/TodoAnnotation.java Locally New
@@ -0,0 +1,62 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common
+ * Development and Distribution License("CDDL") (collectively, the
+ * "License"). You may not use this file except in compliance with the
+ * License. You can obtain a copy of the License at
+ * http://www.netbeans.org/cddl-gplv2.html
+ * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
+ * specific language governing permissions and limitations under the
+ * License. When distributing the software, include this License Header
+ * Notice in each file and include the License file at
+ * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the
+ * License Header, with the fields enclosed by brackets [] replaced by
+ * your own identifying information:
+ * "Portions Copyrighted [year] [name of copyright owner]"
+ *
+ * If you wish your version of this file to be governed by only the CDDL
+ * or only the GPL Version 2, indicate your decision by adding
+ * "[Contributor] elects to include this software in this distribution
+ * under the [CDDL or GPL Version 2] license." If you do not indicate a
+ * single choice of license, a recipient has the option to distribute
+ * your version of this file under either the CDDL, the GPL Version 2 or
+ * to extend the choice of license to its licensees as provided above.
+ * However, if you add GPL Version 2 code and therefore, elected the GPL
+ * Version 2 license, then the option applies only if the new code is
+ * made subject to such option by the copyright holder.
+ *
+ * Contributor(s):
+ *
+ * Portions Copyrighted 2009 Sun Microsystems, Inc.
+ */
+package org.netbeans.modules.showtodos;
+
+import org.openide.text.Annotation;
+
+/**
+ * @author Michel Graciano
+ */
+public final class TodoAnnotation extends Annotation {
+ private final String message;
+
+ public TodoAnnotation(String message) {
+ this.message = message;
+ }
+
+ @Override
+ public String getAnnotationType() {
+ return "org-netbeans-spi-editor-hints-parser_annotation_todo";
+ }
+
+ @Override
+ public String getShortDescription() {
+ return message;
+ }
+}
Index: src/org/netbeans/modules/showtodos/TodoAnnotationProvider.java
--- src/org/netbeans/modules/showtodos/TodoAnnotationProvider.java Base (BASE)
+++ src/org/netbeans/modules/showtodos/TodoAnnotationProvider.java Locally New
@@ -0,0 +1,163 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common
+ * Development and Distribution License("CDDL") (collectively, the
+ * "License"). You may not use this file except in compliance with the
+ * License. You can obtain a copy of the License at
+ * http://www.netbeans.org/cddl-gplv2.html
+ * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
+ * specific language governing permissions and limitations under the
+ * License. When distributing the software, include this License Header
+ * Notice in each file and include the License file at
+ * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the
+ * License Header, with the fields enclosed by brackets [] replaced by
+ * your own identifying information:
+ * "Portions Copyrighted [year] [name of copyright owner]"
+ *
+ * If you wish your version of this file to be governed by only the CDDL
+ * or only the GPL Version 2, indicate your decision by adding
+ * "[Contributor] elects to include this software in this distribution
+ * under the [CDDL or GPL Version 2] license." If you do not indicate a
+ * single choice of license, a recipient has the option to distribute
+ * your version of this file under either the CDDL, the GPL Version 2 or
+ * to extend the choice of license to its licensees as provided above.
+ * However, if you add GPL Version 2 code and therefore, elected the GPL
+ * Version 2 license, then the option applies only if the new code is
+ * made subject to such option by the copyright holder.
+ *
+ * Contributor(s):
+ *
+ * Portions Copyrighted 2009 Sun Microsystems, Inc.
+ */
+package org.netbeans.modules.showtodos;
+
+import static org.netbeans.modules.showtodos.TodoSourceParsing.parseForLines;
+import java.io.IOException;
+import java.lang.ref.Reference;
+import java.lang.ref.WeakReference;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.WeakHashMap;
+import javax.swing.event.DocumentEvent;
+import javax.swing.event.DocumentListener;
+import javax.swing.text.Document;
+import org.netbeans.editor.BaseDocument;
+import org.netbeans.lib.editor.util.swing.DocumentListenerPriority;
+import org.netbeans.lib.editor.util.swing.DocumentUtilities;
+import org.openide.cookies.EditorCookie;
+import org.openide.filesystems.FileObject;
+import org.openide.loaders.DataObject;
+import org.openide.text.Annotation;
+import org.openide.text.AnnotationProvider;
+import org.openide.text.Line;
+import org.openide.util.Exceptions;
+import org.openide.util.Lookup;
+import org.openide.util.RequestProcessor;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ * @author Michel Graciano
+ */
+@ServiceProvider(service = AnnotationProvider.class)
+public class TodoAnnotationProvider implements AnnotationProvider {
+ private static final RequestProcessor requestProcessor =
+ new RequestProcessor("TODO Annotation Parser", 2);
+ private final Map> file2annotation =
+ new WeakHashMap>();
+
+ public void annotate(Line.Set lines, Lookup context) {
+ final DataObject dataObj = context.lookup(DataObject.class);
+ new ScanningDocumentListener().attachTo(dataObj);
+ annotate(dataObj);
+ }
+
+ private void annotate(final DataObject dataObj) {
+ final FileObject fo = dataObj.getPrimaryFile();
+ if (file2annotation.containsKey(fo)) {
+ for (Annotation annotation : file2annotation.get(fo)) {
+ annotation.detach();
+ }
+ }
+
+ final List annotations = new ArrayList();
+ final BaseDocument doc = documentFor(dataObj);
+ for (Line line : parse(doc)) {
+ final TodoAnnotation ann = new TodoAnnotation(line.getText().trim());
+ ann.attach(line);
+ annotations.add(ann);
+ }
+ file2annotation.put(fo, annotations);
+ }
+
+ private List parse(final BaseDocument doc) {
+ return parseForLines(doc);
+ }
+
+ private static BaseDocument documentFor(final DataObject ob) {
+ try {
+ EditorCookie ck = ob.getCookie(EditorCookie.class);
+ if (ck != null) {
+ return (BaseDocument)ck.openDocument();
+ }
+ } catch (IOException ioe) {
+ Exceptions.printStackTrace(ioe);
+ }
+ return null;
+ }
+
+ private class ScanningDocumentListener implements DocumentListener, Runnable {
+ private static final int AUTO_SCANNING_DELAY = 2000; //ms
+ private final RequestProcessor.Task parseTask;
+ private Reference dobref;
+
+ ScanningDocumentListener() {
+ parseTask = requestProcessor.create(this);
+ }
+
+ public void insertUpdate(DocumentEvent e) {
+ change(e);
+ }
+
+ public void changedUpdate(DocumentEvent e) {
+ }
+
+ public void removeUpdate(DocumentEvent e) {
+ change(e);
+ }
+
+ private void attachTo(Document document) {
+ DocumentUtilities.addDocumentListener(document, this,
+ DocumentListenerPriority.AFTER_CARET_UPDATE);
+ restartTimer();
+ }
+
+ private void attachTo(DataObject dob) {
+ dobref = new WeakReference(dob);
+ attachTo(documentFor(dob));
+ }
+
+ private void change(DocumentEvent e) {
+ restartTimer();
+ }
+
+ private void restartTimer() {
+ parseTask.schedule(AUTO_SCANNING_DELAY);
+ }
+
+ public void run() {
+ DataObject dob = dobref.get();
+ if (dob != null) {
+ annotate(dob);
+ }
+ }
+ }
+}
Index: src/org/netbeans/modules/showtodos/TodoSourceParsing.java
--- src/org/netbeans/modules/showtodos/TodoSourceParsing.java Base (BASE)
+++ src/org/netbeans/modules/showtodos/TodoSourceParsing.java Locally New
@@ -0,0 +1,129 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common
+ * Development and Distribution License("CDDL") (collectively, the
+ * "License"). You may not use this file except in compliance with the
+ * License. You can obtain a copy of the License at
+ * http://www.netbeans.org/cddl-gplv2.html
+ * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
+ * specific language governing permissions and limitations under the
+ * License. When distributing the software, include this License Header
+ * Notice in each file and include the License file at
+ * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the
+ * License Header, with the fields enclosed by brackets [] replaced by
+ * your own identifying information:
+ * "Portions Copyrighted [year] [name of copyright owner]"
+ *
+ * If you wish your version of this file to be governed by only the CDDL
+ * or only the GPL Version 2, indicate your decision by adding
+ * "[Contributor] elects to include this software in this distribution
+ * under the [CDDL or GPL Version 2] license." If you do not indicate a
+ * single choice of license, a recipient has the option to distribute
+ * your version of this file under either the CDDL, the GPL Version 2 or
+ * to extend the choice of license to its licensees as provided above.
+ * However, if you add GPL Version 2 code and therefore, elected the GPL
+ * Version 2 license, then the option applies only if the new code is
+ * made subject to such option by the copyright holder.
+ *
+ * Contributor(s):
+ *
+ * Portions Copyrighted 2009 Sun Microsystems, Inc.
+ */
+package org.netbeans.modules.showtodos;
+
+import java.util.LinkedList;
+import java.util.List;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.Document;
+import org.netbeans.api.lexer.Token;
+import org.netbeans.api.lexer.TokenHierarchy;
+import org.netbeans.api.lexer.TokenSequence;
+import org.netbeans.editor.BaseDocument;
+import org.netbeans.editor.FinderFactory;
+import org.netbeans.editor.Utilities;
+import org.netbeans.modules.editor.NbEditorUtilities;
+import org.netbeans.modules.tasklist.todo.settings.Settings;
+import org.openide.text.Line;
+import org.openide.util.Exceptions;
+
+/**
+ *
+ * @author Michel Graciano
+ */
+final class TodoSourceParsing {
+ private TodoSourceParsing() {
+ }
+
+ static List parse(final BaseDocument doc, int startOffset,
+ int endOffset) {
+ List pairsPosition = new LinkedList();
+ TokenHierarchy th = TokenHierarchy.get(doc);
+ TokenSequence ts = null;
+
+ if (th != null) {
+ ts = th.tokenSequence();
+ }
+
+ try {
+ startOffset = Utilities.getRowStart(doc, startOffset);
+ endOffset = Math.min(doc.getLength(), endOffset);
+
+ for (String word : Settings.getDefault().getPatterns()) {
+ int pos = startOffset;
+
+ // Search from pos to endPos for TODO markers.
+ while (pos < endOffset) {
+ FinderFactory.WholeWordsFwdFinder finder =
+ new FinderFactory.WholeWordsFwdFinder(doc, word, true);
+ int next = doc.find(finder, pos, endOffset);
+
+ if ((next >= startOffset) && (next < endOffset)) {
+ // See if it looks like a token we care about (comments)
+ if (ts != null) {
+ ts.move(next);
+
+ if (ts.moveNext()) {
+ Token token = ts.token();
+ pos = Math.min(Utilities.getRowEnd(doc, next),
+ ts.offset() + token.length());
+
+ if (token != null) {
+ String category = token.id().primaryCategory();
+
+ if ("comment".equals(category)) { // NOI18N
+ pairsPosition.add(new int[] {next, pos});
+ }
+ }
+ } else {
+ pos = next + word.length();
+ }
+ } else {
+ pos = next + word.length();
+ }
+ } else {
+ break;
+ }
+ }
+ }
+ } catch (BadLocationException e) {
+ Exceptions.printStackTrace(e);
+ }
+ return pairsPosition;
+ }
+
+ static List parseForLines(final BaseDocument doc) {
+ final List lines = new LinkedList();
+ for (int[] pairs : parse(doc, doc.getStartPosition().getOffset(), doc.
+ getEndPosition().getOffset())) {
+ lines.add(NbEditorUtilities.getLine((Document)doc, pairs[1], false));
+ }
+ return lines;
+ }
+}