diff --git a/java.debug/nbproject/project.xml b/java.debug/nbproject/project.xml --- a/java.debug/nbproject/project.xml +++ b/java.debug/nbproject/project.xml @@ -92,6 +92,15 @@ + org.netbeans.modules.parsing.api + + + + 1 + 1.51 + + + org.netbeans.modules.projectapi diff --git a/java.debug/src/org/netbeans/modules/java/debug/TreeNavigatorJavaSourceFactory.java b/java.debug/src/org/netbeans/modules/java/debug/TreeNavigatorJavaSourceFactory.java --- a/java.debug/src/org/netbeans/modules/java/debug/TreeNavigatorJavaSourceFactory.java +++ b/java.debug/src/org/netbeans/modules/java/debug/TreeNavigatorJavaSourceFactory.java @@ -52,6 +52,7 @@ import org.netbeans.api.java.source.JavaSourceTaskFactory; import org.netbeans.api.java.source.support.CaretAwareJavaSourceTaskFactory; import org.netbeans.api.java.source.support.LookupBasedJavaSourceTaskFactory; +import org.netbeans.modules.parsing.spi.TaskIndexingMode; import org.openide.filesystems.FileObject; import org.openide.util.Lookup; import org.openide.util.lookup.ServiceProvider; @@ -75,7 +76,7 @@ } public TreeNavigatorJavaSourceFactory() { - super(Phase.UP_TO_DATE, Priority.NORMAL); + super(Phase.UP_TO_DATE, Priority.NORMAL, TaskIndexingMode.ALLOWED_DURING_SCAN); } public synchronized CancellableTask createTask(FileObject file) { diff --git a/java.editor/nbproject/project.xml b/java.editor/nbproject/project.xml --- a/java.editor/nbproject/project.xml +++ b/java.editor/nbproject/project.xml @@ -236,7 +236,7 @@ - 0.86 + 0.94 @@ -281,7 +281,7 @@ 1 - 1.26 + 1.51 diff --git a/java.editor/src/org/netbeans/modules/java/editor/fold/JavaElementFoldManagerTaskFactory.java b/java.editor/src/org/netbeans/modules/java/editor/fold/JavaElementFoldManagerTaskFactory.java --- a/java.editor/src/org/netbeans/modules/java/editor/fold/JavaElementFoldManagerTaskFactory.java +++ b/java.editor/src/org/netbeans/modules/java/editor/fold/JavaElementFoldManagerTaskFactory.java @@ -49,6 +49,7 @@ import org.netbeans.api.java.source.JavaSource.Priority; import org.netbeans.api.java.source.JavaSourceTaskFactory; import org.netbeans.api.java.source.support.EditorAwareJavaSourceTaskFactory; +import org.netbeans.modules.parsing.spi.TaskIndexingMode; import org.openide.filesystems.FileObject; import org.openide.util.Lookup; @@ -60,7 +61,7 @@ public class JavaElementFoldManagerTaskFactory extends EditorAwareJavaSourceTaskFactory { public JavaElementFoldManagerTaskFactory() { - super(Phase.PARSED, Priority.NORMAL); + super(Phase.PARSED, Priority.NORMAL, TaskIndexingMode.ALLOWED_DURING_SCAN); } public CancellableTask createTask(FileObject file) { diff --git a/java.editor/src/org/netbeans/modules/java/editor/overridden/ComputeAnnotations.java b/java.editor/src/org/netbeans/modules/java/editor/overridden/ComputeAnnotations.java --- a/java.editor/src/org/netbeans/modules/java/editor/overridden/ComputeAnnotations.java +++ b/java.editor/src/org/netbeans/modules/java/editor/overridden/ComputeAnnotations.java @@ -61,11 +61,8 @@ import org.netbeans.api.java.source.JavaParserResultTask; import org.netbeans.api.java.source.JavaSource.Phase; import org.netbeans.modules.parsing.api.Snapshot; +import org.netbeans.modules.parsing.spi.*; import org.netbeans.modules.parsing.spi.Parser.Result; -import org.netbeans.modules.parsing.spi.Scheduler; -import org.netbeans.modules.parsing.spi.SchedulerEvent; -import org.netbeans.modules.parsing.spi.SchedulerTask; -import org.netbeans.modules.parsing.spi.TaskFactory; import org.openide.text.NbDocument; import org.openide.util.NbBundle; @@ -78,7 +75,7 @@ private final AtomicBoolean cancel = new AtomicBoolean(); public ComputeAnnotations() { - super(Phase.RESOLVED); + super(Phase.RESOLVED, TaskIndexingMode.ALLOWED_DURING_SCAN); } @Override diff --git a/java.editor/src/org/netbeans/modules/java/editor/semantic/MarkOccurrencesHighlighter.java b/java.editor/src/org/netbeans/modules/java/editor/semantic/MarkOccurrencesHighlighter.java --- a/java.editor/src/org/netbeans/modules/java/editor/semantic/MarkOccurrencesHighlighter.java +++ b/java.editor/src/org/netbeans/modules/java/editor/semantic/MarkOccurrencesHighlighter.java @@ -104,6 +104,7 @@ import org.netbeans.modules.parsing.spi.Parser.Result; import org.netbeans.modules.parsing.spi.Scheduler; import org.netbeans.modules.parsing.spi.SchedulerEvent; +import org.netbeans.modules.parsing.spi.TaskIndexingMode; import org.netbeans.spi.editor.highlighting.support.OffsetsBag; import org.openide.filesystems.FileObject; import org.openide.loaders.DataObject; @@ -120,7 +121,7 @@ /** Creates a new instance of SemanticHighlighter */ MarkOccurrencesHighlighter(FileObject file) { - super(Phase.RESOLVED); + super(Phase.RESOLVED, TaskIndexingMode.ALLOWED_DURING_SCAN); this.file = file; } diff --git a/java.editor/src/org/netbeans/modules/java/editor/semantic/SemanticHighlighter.java b/java.editor/src/org/netbeans/modules/java/editor/semantic/SemanticHighlighter.java --- a/java.editor/src/org/netbeans/modules/java/editor/semantic/SemanticHighlighter.java +++ b/java.editor/src/org/netbeans/modules/java/editor/semantic/SemanticHighlighter.java @@ -121,6 +121,7 @@ import org.netbeans.modules.parsing.spi.Parser.Result; import org.netbeans.modules.parsing.spi.Scheduler; import org.netbeans.modules.parsing.spi.SchedulerEvent; +import org.netbeans.modules.parsing.spi.TaskIndexingMode; import org.netbeans.spi.editor.highlighting.support.OffsetsBag; import org.netbeans.spi.editor.hints.ErrorDescription; import org.openide.filesystems.FileObject; @@ -165,7 +166,7 @@ // } // SemanticHighlighter(FileObject file/*, SemanticHighlighterFactory fact*/) { - super(Phase.RESOLVED); + super(Phase.RESOLVED, TaskIndexingMode.ALLOWED_DURING_SCAN); this.file = file; // this.fact = fact; } diff --git a/java.hints.declarative/nbproject/project.xml b/java.hints.declarative/nbproject/project.xml --- a/java.hints.declarative/nbproject/project.xml +++ b/java.hints.declarative/nbproject/project.xml @@ -113,7 +113,7 @@ - 0.43.0.7.7.1 + 0.94 @@ -131,7 +131,7 @@ 1 - 1.12.1 + 1.51 diff --git a/java.hints.declarative/src/org/netbeans/modules/java/hints/declarative/debugging/EvaluationSpanTask.java b/java.hints.declarative/src/org/netbeans/modules/java/hints/declarative/debugging/EvaluationSpanTask.java --- a/java.hints.declarative/src/org/netbeans/modules/java/hints/declarative/debugging/EvaluationSpanTask.java +++ b/java.hints.declarative/src/org/netbeans/modules/java/hints/declarative/debugging/EvaluationSpanTask.java @@ -76,12 +76,8 @@ import org.netbeans.modules.java.hints.declarative.test.TestTokenId; import org.netbeans.modules.java.hints.jackpot.spi.HintContext; import org.netbeans.modules.parsing.api.Snapshot; -import org.netbeans.modules.parsing.spi.CursorMovedSchedulerEvent; +import org.netbeans.modules.parsing.spi.*; import org.netbeans.modules.parsing.spi.Parser.Result; -import org.netbeans.modules.parsing.spi.Scheduler; -import org.netbeans.modules.parsing.spi.SchedulerEvent; -import org.netbeans.modules.parsing.spi.SchedulerTask; -import org.netbeans.modules.parsing.spi.TaskFactory; import org.netbeans.spi.editor.highlighting.support.OffsetsBag; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; @@ -94,7 +90,7 @@ public class EvaluationSpanTask extends JavaParserResultTask { public EvaluationSpanTask() { - super(Phase.RESOLVED); + super(Phase.RESOLVED, TaskIndexingMode.ALLOWED_DURING_SCAN); } @Override diff --git a/java.hints/src/org/netbeans/modules/java/hints/introduce/IntroduceHintFactory.java b/java.hints/src/org/netbeans/modules/java/hints/introduce/IntroduceHintFactory.java --- a/java.hints/src/org/netbeans/modules/java/hints/introduce/IntroduceHintFactory.java +++ b/java.hints/src/org/netbeans/modules/java/hints/introduce/IntroduceHintFactory.java @@ -48,6 +48,7 @@ import org.netbeans.api.java.source.JavaSource.Phase; import org.netbeans.api.java.source.JavaSource.Priority; import org.netbeans.api.java.source.support.SelectionAwareJavaSourceTaskFactory; +import org.netbeans.modules.parsing.spi.TaskIndexingMode; import org.openide.filesystems.FileObject; /** @@ -58,7 +59,7 @@ public class IntroduceHintFactory extends SelectionAwareJavaSourceTaskFactory { public IntroduceHintFactory() { - super(Phase.RESOLVED, Priority.BELOW_NORMAL); + super(Phase.RESOLVED, Priority.BELOW_NORMAL, TaskIndexingMode.ALLOWED_DURING_SCAN); } protected CancellableTask createTask(FileObject file) { diff --git a/java.hints/src/org/netbeans/modules/java/hints/jackpot/impl/hints/HintsTask.java b/java.hints/src/org/netbeans/modules/java/hints/jackpot/impl/hints/HintsTask.java --- a/java.hints/src/org/netbeans/modules/java/hints/jackpot/impl/hints/HintsTask.java +++ b/java.hints/src/org/netbeans/modules/java/hints/jackpot/impl/hints/HintsTask.java @@ -65,6 +65,7 @@ import org.netbeans.lib.editor.util.swing.DocumentUtilities; import org.netbeans.modules.java.hints.infrastructure.JavaHintsPositionRefresher; import org.netbeans.modules.java.hints.options.HintsSettings; +import org.netbeans.modules.parsing.spi.TaskIndexingMode; import org.netbeans.spi.editor.hints.ErrorDescription; import org.netbeans.spi.editor.hints.Severity; import org.openide.util.WeakListeners; @@ -138,7 +139,7 @@ public static final class FactoryImpl extends EditorAwareJavaSourceTaskFactory implements ChangeListener { public FactoryImpl() { - super(Phase.RESOLVED, Priority.LOW); + super(Phase.RESOLVED, Priority.LOW, TaskIndexingMode.ALLOWED_DURING_SCAN); HintsSettings.addChangeListener(WeakListeners.change(this, HintsSettings.class)); } diff --git a/java.navigation/nbproject/project.xml b/java.navigation/nbproject/project.xml --- a/java.navigation/nbproject/project.xml +++ b/java.navigation/nbproject/project.xml @@ -152,7 +152,7 @@ - 0.84 + 0.94 @@ -174,6 +174,15 @@ + org.netbeans.modules.parsing.api + + + + 1 + 1.51 + + + org.netbeans.modules.projectapi diff --git a/java.navigation/src/org/netbeans/modules/java/navigation/CaretListeningFactory.java b/java.navigation/src/org/netbeans/modules/java/navigation/CaretListeningFactory.java --- a/java.navigation/src/org/netbeans/modules/java/navigation/CaretListeningFactory.java +++ b/java.navigation/src/org/netbeans/modules/java/navigation/CaretListeningFactory.java @@ -50,6 +50,7 @@ import org.netbeans.api.java.source.JavaSource.Phase; import org.netbeans.api.java.source.JavaSource.Priority; import org.netbeans.api.java.source.support.CaretAwareJavaSourceTaskFactory; +import org.netbeans.modules.parsing.spi.TaskIndexingMode; import org.openide.filesystems.FileObject; /** @@ -63,7 +64,7 @@ private static CaretListeningFactory INSTANCE; public CaretListeningFactory() { - super(Phase.RESOLVED, Priority.LOW); + super(Phase.RESOLVED, Priority.LOW, TaskIndexingMode.ALLOWED_DURING_SCAN); INSTANCE = this; } diff --git a/java.navigation/src/org/netbeans/modules/java/navigation/ClassMemberNavigatorJavaSourceFactory.java b/java.navigation/src/org/netbeans/modules/java/navigation/ClassMemberNavigatorJavaSourceFactory.java --- a/java.navigation/src/org/netbeans/modules/java/navigation/ClassMemberNavigatorJavaSourceFactory.java +++ b/java.navigation/src/org/netbeans/modules/java/navigation/ClassMemberNavigatorJavaSourceFactory.java @@ -51,6 +51,7 @@ import org.netbeans.api.java.source.JavaSource.Priority; import org.netbeans.api.java.source.JavaSourceTaskFactory; import org.netbeans.api.java.source.support.LookupBasedJavaSourceTaskFactory; +import org.netbeans.modules.parsing.spi.TaskIndexingMode; import org.openide.filesystems.FileObject; import org.openide.util.Lookup; @@ -79,7 +80,12 @@ } public ClassMemberNavigatorJavaSourceFactory() { - super(Phase.ELEMENTS_RESOLVED, Priority.NORMAL, "text/x-java", "application/x-class-file"); + super( + Phase.ELEMENTS_RESOLVED, + Priority.NORMAL, + TaskIndexingMode.ALLOWED_DURING_SCAN, + "text/x-java", + "application/x-class-file"); } public synchronized CancellableTask createTask(FileObject file) { diff --git a/java.source/apichanges.xml b/java.source/apichanges.xml --- a/java.source/apichanges.xml +++ b/java.source/apichanges.xml @@ -108,6 +108,25 @@ + + + Added TaskIndexingMode into JavaSourceTaskFactorys + + + + + + The CancellableTasks created by the JavaSourceTaskFactorys are not executed during the scan to keep the semantic backward compatibility. + Constructors with the TaskIndexingMode were added into these factories to allow tasks to run during the scan. + + + + + + + + + Added TreePathHandle.getElementHandle. diff --git a/java.source/nbproject/project.properties b/java.source/nbproject/project.properties --- a/java.source/nbproject/project.properties +++ b/java.source/nbproject/project.properties @@ -46,7 +46,7 @@ javadoc.title=Java Source javadoc.arch=${basedir}/arch.xml javadoc.apichanges=${basedir}/apichanges.xml -spec.version.base=0.93.0 +spec.version.base=0.94.0 test.qa-functional.cp.extra=${refactoring.java.dir}/modules/ext/javac-api-nb-7.0-b07.jar test.unit.run.cp.extra=${o.n.core.dir}/core/core.jar:\ ${o.n.core.dir}/lib/boot.jar:\ diff --git a/java.source/src/org/netbeans/api/java/source/JavaParserResultTask.java b/java.source/src/org/netbeans/api/java/source/JavaParserResultTask.java --- a/java.source/src/org/netbeans/api/java/source/JavaParserResultTask.java +++ b/java.source/src/org/netbeans/api/java/source/JavaParserResultTask.java @@ -43,18 +43,19 @@ package org.netbeans.api.java.source; import org.netbeans.api.annotations.common.NonNull; +import org.netbeans.modules.parsing.spi.IndexingAwareParserResultTask; import org.netbeans.modules.parsing.spi.Parser; -import org.netbeans.modules.parsing.spi.ParserResultTask; +import org.netbeans.modules.parsing.spi.TaskIndexingMode; import org.openide.util.Parameters; /** - * Java specific version of the {@link ParserResultTask}. In addition to the - * {@link ParserResultTask} it adds a support for javac phases. + * Java specific version of the {@link IndexingAwareParserResultTask}. In addition to the + * {@link IndexingAwareParserResultTask} it adds a support for javac phases. * @see JavaSource * @since 0.42 * @author Tomas Zezula */ -public abstract class JavaParserResultTask extends ParserResultTask { +public abstract class JavaParserResultTask extends IndexingAwareParserResultTask { private final JavaSource.Phase phase; @@ -63,7 +64,22 @@ * @param phase needed by the task. */ protected JavaParserResultTask (final @NonNull JavaSource.Phase phase) { - Parameters.notNull("phase", phase); + this (phase, TaskIndexingMode.DISALLOWED_DURING_SCAN); + } + + /** + * Creates a new JavaParserResultTask + * @param phase needed by the task. + * @param taskIndexingMode the awareness of indexing. For tasks which can run + * during indexing use {@link TaskIndexingMode#ALLOWED_DURING_SCAN} for tasks + * which cannot run during indexing use {@link TaskIndexingMode#DISALLOWED_DURING_SCAN}. + * @since 0.94 + */ + protected JavaParserResultTask ( + @NonNull final JavaSource.Phase phase, + @NonNull final TaskIndexingMode taskIndexingMode) { + super(taskIndexingMode); + Parameters.notNull("phase", phase); //NOI18 this.phase = phase; } diff --git a/java.source/src/org/netbeans/api/java/source/JavaSourceTaskFactory.java b/java.source/src/org/netbeans/api/java/source/JavaSourceTaskFactory.java --- a/java.source/src/org/netbeans/api/java/source/JavaSourceTaskFactory.java +++ b/java.source/src/org/netbeans/api/java/source/JavaSourceTaskFactory.java @@ -62,6 +62,8 @@ import org.netbeans.api.java.source.support.LookupBasedJavaSourceTaskFactory; import org.netbeans.modules.java.source.JavaSourceAccessor; import org.netbeans.modules.java.source.JavaSourceTaskFactoryManager; +import org.netbeans.modules.parsing.spi.TaskIndexingMode; +import org.openide.util.Parameters; import org.openide.util.RequestProcessor; /** @@ -86,6 +88,7 @@ private final Phase phase; private final Priority priority; + private final TaskIndexingMode taskIndexingMode; /**Construct the JavaSourceTaskFactory with given {@link Phase} and {@link Priority}. * @@ -95,6 +98,31 @@ protected JavaSourceTaskFactory(@NonNull Phase phase, @NonNull Priority priority) { this.phase = phase; this.priority = priority; + this.taskIndexingMode = TaskIndexingMode.DISALLOWED_DURING_SCAN; + this.file2Task = new HashMap>(); + this.file2JS = new HashMap(); + } + + /**Construct the JavaSourceTaskFactory with given {@link Phase}, {@link Priority} + * and {@link TaskIndexingMode}. + * + * @param phase phase to use for tasks created by {@link #createTask} + * @param priority priority to use for tasks created by {@link #createTask} + * @param taskIndexingMode the awareness of indexing. For tasks which can run + * during indexing use {@link TaskIndexingMode#ALLOWED_DURING_SCAN} for tasks + * which cannot run during indexing use {@link TaskIndexingMode#DISALLOWED_DURING_SCAN}. + * @since 0.94 + */ + protected JavaSourceTaskFactory( + @NonNull final Phase phase, + @NonNull final Priority priority, + @NonNull final TaskIndexingMode taskIndexingMode) { + Parameters.notNull("phase", phase); //NOI18N + Parameters.notNull("priority", priority); //NOI18N + Parameters.notNull("taskIndexingMode", taskIndexingMode); //NOI18N + this.phase = phase; + this.priority = priority; + this.taskIndexingMode = taskIndexingMode; this.file2Task = new HashMap>(); this.file2JS = new HashMap(); } @@ -184,7 +212,7 @@ if (task == null) { throw new IllegalStateException("createTask(FileObject) returned null for factory: " + getClass().getName()); } - ACCESSOR2.addPhaseCompletionTask(js, task, phase, priority); + ACCESSOR2.addPhaseCompletionTask(js, task, phase, priority, taskIndexingMode); file2Task.put(a, task); file2JS.put(a, js); } @@ -230,8 +258,8 @@ } }; ACCESSOR2 = new Accessor2() { - public void addPhaseCompletionTask(JavaSource js, CancellableTask task, Phase phase, Priority priority) { - JavaSourceAccessor.getINSTANCE().addPhaseCompletionTask (js, task, phase, priority); + public void addPhaseCompletionTask(JavaSource js, CancellableTask task, Phase phase, Priority priority, TaskIndexingMode taskIndexingMode) { + JavaSourceAccessor.getINSTANCE().addPhaseCompletionTask (js, task, phase, priority, taskIndexingMode); } public void removePhaseCompletionTask(JavaSource js, CancellableTask task) { @@ -245,7 +273,7 @@ } static interface Accessor2 { - public abstract void addPhaseCompletionTask(JavaSource js, CancellableTask task, Phase phase, Priority priority ); + public abstract void addPhaseCompletionTask(JavaSource js, CancellableTask task, Phase phase, Priority priority, TaskIndexingMode taskIndexingMode ); public abstract void removePhaseCompletionTask(JavaSource js, CancellableTask task ); public abstract void rescheduleTask(JavaSource js, CancellableTask task); } diff --git a/java.source/src/org/netbeans/api/java/source/support/CaretAwareJavaSourceTaskFactory.java b/java.source/src/org/netbeans/api/java/source/support/CaretAwareJavaSourceTaskFactory.java --- a/java.source/src/org/netbeans/api/java/source/support/CaretAwareJavaSourceTaskFactory.java +++ b/java.source/src/org/netbeans/api/java/source/support/CaretAwareJavaSourceTaskFactory.java @@ -46,8 +46,6 @@ import java.lang.ref.Reference; import java.lang.ref.WeakReference; import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.WeakHashMap; @@ -56,11 +54,13 @@ import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import javax.swing.text.JTextComponent; +import org.netbeans.api.annotations.common.NonNull; import org.netbeans.api.java.source.JavaSource.Phase; import org.netbeans.api.java.source.JavaSource.Priority; import org.netbeans.api.java.source.JavaSourceTaskFactory; -import org.netbeans.api.java.source.SourceUtils; +import org.netbeans.modules.parsing.spi.TaskIndexingMode; import org.openide.filesystems.FileObject; +import org.openide.util.Parameters; import org.openide.util.RequestProcessor; /**A {@link JavaSourceTaskFactorySupport} that registers tasks to all files that are @@ -96,13 +96,38 @@ * @since 0.21 */ public CaretAwareJavaSourceTaskFactory(Phase phase, Priority priority, String... supportedMimeTypes) { - super(phase, priority); + super(phase, priority, TaskIndexingMode.DISALLOWED_DURING_SCAN); //XXX: weak, or something like this: OpenedEditors.getDefault().addChangeListener(new ChangeListenerImpl()); this.timeout = DEFAULT_RESCHEDULE_TIMEOUT; this.supportedMimeTypes = supportedMimeTypes != null ? supportedMimeTypes.clone() : null; } + /**Construct the CaretAwareJavaSourceTaskFactory. + * + * @param phase phase to use for tasks created by {@link #createTask} + * @param priority priority to use for tasks created by {@link #createTask} + * @param taskIndexingMode the awareness of indexing. For tasks which can run + * during indexing use {@link TaskIndexingMode#ALLOWED_DURING_SCAN} for tasks + * which cannot run during indexing use {@link TaskIndexingMode#DISALLOWED_DURING_SCAN}. + * @param supportedMimeTypes a list of mime types on which the tasks created by this factory should be run, + * empty array falls back to default text/x-java. + * + * @since 0.94 + */ + public CaretAwareJavaSourceTaskFactory( + @NonNull Phase phase, + @NonNull Priority priority, + @NonNull TaskIndexingMode taskIndexingMode, + @NonNull String... supportedMimeTypes) { + super(phase, priority, taskIndexingMode); + Parameters.notNull("supportedMimeTypes", supportedMimeTypes); //NOI18N + //XXX: weak, or something like this: + OpenedEditors.getDefault().addChangeListener(new ChangeListenerImpl()); + this.timeout = DEFAULT_RESCHEDULE_TIMEOUT; + this.supportedMimeTypes = supportedMimeTypes.length > 0 ? supportedMimeTypes.clone() : null; + } + /**@inheritDoc*/ public List getFileObjects() { List files = OpenedEditors.filterSupportedMIMETypes(OpenedEditors.getDefault().getVisibleEditorsFiles(), supportedMimeTypes); diff --git a/java.source/src/org/netbeans/api/java/source/support/EditorAwareJavaSourceTaskFactory.java b/java.source/src/org/netbeans/api/java/source/support/EditorAwareJavaSourceTaskFactory.java --- a/java.source/src/org/netbeans/api/java/source/support/EditorAwareJavaSourceTaskFactory.java +++ b/java.source/src/org/netbeans/api/java/source/support/EditorAwareJavaSourceTaskFactory.java @@ -46,11 +46,13 @@ import java.util.List; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; +import org.netbeans.api.annotations.common.NonNull; import org.netbeans.api.java.source.JavaSource.Phase; import org.netbeans.api.java.source.JavaSource.Priority; import org.netbeans.api.java.source.JavaSourceTaskFactory; -import org.netbeans.api.java.source.SourceUtils; +import org.netbeans.modules.parsing.spi.TaskIndexingMode; import org.openide.filesystems.FileObject; +import org.openide.util.Parameters; /**A {@link JavaSourceTaskFactorySupport} that registers tasks to all files that are * opened in the editor and are visible. @@ -78,12 +80,35 @@ * @since 0.21 */ protected EditorAwareJavaSourceTaskFactory(Phase phase, Priority priority, String... supportedMimeTypes) { - super(phase, priority); + super(phase, priority, TaskIndexingMode.DISALLOWED_DURING_SCAN); //XXX: weak, or something like this: OpenedEditors.getDefault().addChangeListener(new ChangeListenerImpl()); this.supportedMimeTypes = supportedMimeTypes != null ? supportedMimeTypes.clone() : null; } + /**Construct the EditorAwareJavaSourceTaskFactory. + * + * @param phase phase to use for tasks created by {@link #createTask} + * @param priority priority to use for tasks created by {@link #createTask} + * @param taskIndexingMode the awareness of indexing. For tasks which can run + * during indexing use {@link TaskIndexingMode#ALLOWED_DURING_SCAN} for tasks + * which cannot run during indexing use {@link TaskIndexingMode#DISALLOWED_DURING_SCAN}. + * @param supportedMimeTypes a list of mime types on which the tasks created by this factory should be run, + * empty array falls back to default text/x-java. + * @since 0.94 + */ + protected EditorAwareJavaSourceTaskFactory( + @NonNull final Phase phase, + @NonNull final Priority priority, + @NonNull final TaskIndexingMode taskIndexingMode, + @NonNull final String... supportedMimeTypes) { + super(phase, priority, taskIndexingMode); + Parameters.notNull("supportedMimeTypes", supportedMimeTypes); //NOI18N + //XXX: weak, or something like this: + OpenedEditors.getDefault().addChangeListener(new ChangeListenerImpl()); + this.supportedMimeTypes = supportedMimeTypes.length > 0 ? supportedMimeTypes.clone() : null; + } + /**@inheritDoc*/ public List getFileObjects() { List files = OpenedEditors.filterSupportedMIMETypes(OpenedEditors.getDefault().getVisibleEditorsFiles(), supportedMimeTypes); diff --git a/java.source/src/org/netbeans/api/java/source/support/LookupBasedJavaSourceTaskFactory.java b/java.source/src/org/netbeans/api/java/source/support/LookupBasedJavaSourceTaskFactory.java --- a/java.source/src/org/netbeans/api/java/source/support/LookupBasedJavaSourceTaskFactory.java +++ b/java.source/src/org/netbeans/api/java/source/support/LookupBasedJavaSourceTaskFactory.java @@ -43,17 +43,16 @@ */ package org.netbeans.api.java.source.support; -import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Set; -import javax.swing.event.ChangeEvent; +import org.netbeans.api.annotations.common.NonNull; import org.netbeans.api.java.source.JavaSource.Phase; import org.netbeans.api.java.source.JavaSource.Priority; import org.netbeans.api.java.source.JavaSourceTaskFactory; -import org.netbeans.api.java.source.SourceUtils; +import org.netbeans.modules.parsing.spi.TaskIndexingMode; import org.openide.filesystems.FileObject; import org.openide.loaders.DataObject; import org.openide.nodes.Node; @@ -61,6 +60,7 @@ import org.openide.util.Lookup.Result; import org.openide.util.LookupEvent; import org.openide.util.LookupListener; +import org.openide.util.Parameters; /**A {@link JavaSourceTaskFactorySupport} that registers tasks to all files that are * found in the given {@link Lookup}. @@ -98,11 +98,34 @@ * @since 0.21 */ public LookupBasedJavaSourceTaskFactory(Phase phase, Priority priority, String... supportedMimeTypes) { - super(phase, priority); + super(phase, priority, TaskIndexingMode.DISALLOWED_DURING_SCAN); currentFiles = Collections.emptyList(); listener = new LookupListenerImpl(); this.supportedMimeTypes = supportedMimeTypes != null ? supportedMimeTypes.clone() : null; } + + /**Construct the LookupBasedJavaSourceTaskFactory with given {@link Phase} and {@link Priority}. + * + * @param phase phase to use for tasks created by {@link #createTask} + * @param priority priority to use for tasks created by {@link #createTask} + * @param taskIndexingMode the awareness of indexing. For tasks which can run + * during indexing use {@link TaskIndexingMode#ALLOWED_DURING_SCAN} for tasks + * which cannot run during indexing use {@link TaskIndexingMode#DISALLOWED_DURING_SCAN}. + * @param supportedMimeTypes a list of mime types on which the tasks created by this factory should be run, + * empty array falls back to default text/x-java. + * @since 0.94 + */ + public LookupBasedJavaSourceTaskFactory( + @NonNull final Phase phase, + @NonNull final Priority priority, + @NonNull final TaskIndexingMode taskIndexingMode, + @NonNull final String... supportedMimeTypes) { + super(phase, priority, taskIndexingMode); + Parameters.notNull("supportedMimeTypes", supportedMimeTypes); //NOI18N + currentFiles = Collections.emptyList(); + listener = new LookupListenerImpl(); + this.supportedMimeTypes = supportedMimeTypes.length > 0 ? supportedMimeTypes.clone() : null; + } /**Sets a new {@link Lookup} to search. * diff --git a/java.source/src/org/netbeans/api/java/source/support/SelectionAwareJavaSourceTaskFactory.java b/java.source/src/org/netbeans/api/java/source/support/SelectionAwareJavaSourceTaskFactory.java --- a/java.source/src/org/netbeans/api/java/source/support/SelectionAwareJavaSourceTaskFactory.java +++ b/java.source/src/org/netbeans/api/java/source/support/SelectionAwareJavaSourceTaskFactory.java @@ -46,7 +46,6 @@ import java.lang.ref.Reference; import java.lang.ref.WeakReference; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.WeakHashMap; @@ -55,10 +54,13 @@ import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import javax.swing.text.JTextComponent; +import org.netbeans.api.annotations.common.NonNull; import org.netbeans.api.java.source.JavaSource.Phase; import org.netbeans.api.java.source.JavaSource.Priority; import org.netbeans.api.java.source.JavaSourceTaskFactory; +import org.netbeans.modules.parsing.spi.TaskIndexingMode; import org.openide.filesystems.FileObject; +import org.openide.util.Parameters; import org.openide.util.RequestProcessor; /**A {@link JavaSourceTaskFactorySupport} that registers tasks to all files that are @@ -96,13 +98,37 @@ * @since 0.22 */ public SelectionAwareJavaSourceTaskFactory(Phase phase, Priority priority, String... supportedMimeTypes) { - super(phase, priority); + super(phase, priority, TaskIndexingMode.DISALLOWED_DURING_SCAN); //XXX: weak, or something like this: OpenedEditors.getDefault().addChangeListener(new ChangeListenerImpl()); this.timeout = DEFAULT_RESCHEDULE_TIMEOUT; this.supportedMimeTypes = supportedMimeTypes != null ? supportedMimeTypes.clone() : null; } + /**Construct the SelectionAwareJavaSourceTaskFactory with given {@link Phase} and {@link Priority}. + * + * @param phase phase to use for tasks created by {@link #createTask} + * @param priority priority to use for tasks created by {@link #createTask} + * @param taskIndexingMode the awareness of indexing. For tasks which can run + * during indexing use {@link TaskIndexingMode#ALLOWED_DURING_SCAN} for tasks + * which cannot run during indexing use {@link TaskIndexingMode#DISALLOWED_DURING_SCAN}. + * @param supportedMimeTypes a list of mime types on which the tasks created by this factory should be run, + * empty array falls back to default text/x-java. + * @since 0.94 + */ + public SelectionAwareJavaSourceTaskFactory( + @NonNull final Phase phase, + @NonNull final Priority priority, + @NonNull final TaskIndexingMode taskIndexingMode, + @NonNull String... supportedMimeTypes) { + super(phase, priority, taskIndexingMode); + Parameters.notNull("supportedMimeTypes", supportedMimeTypes); //NOI18N + //XXX: weak, or something like this: + OpenedEditors.getDefault().addChangeListener(new ChangeListenerImpl()); + this.timeout = DEFAULT_RESCHEDULE_TIMEOUT; + this.supportedMimeTypes = supportedMimeTypes.length > 0 ? supportedMimeTypes.clone() : null; + } + /**@inheritDoc*/ public List getFileObjects() { List files = OpenedEditors.filterSupportedMIMETypes(OpenedEditors.getDefault().getVisibleEditorsFiles(), supportedMimeTypes); diff --git a/java.source/src/org/netbeans/modules/java/source/JavaSourceAccessor.java b/java.source/src/org/netbeans/modules/java/source/JavaSourceAccessor.java --- a/java.source/src/org/netbeans/modules/java/source/JavaSourceAccessor.java +++ b/java.source/src/org/netbeans/modules/java/source/JavaSourceAccessor.java @@ -76,10 +76,10 @@ import org.netbeans.modules.parsing.spi.ParserResultTask; import org.netbeans.modules.parsing.spi.Scheduler; import org.netbeans.modules.parsing.spi.SchedulerEvent; +import org.netbeans.modules.parsing.spi.TaskIndexingMode; import org.openide.filesystems.FileObject; import org.openide.text.PositionRef; import org.openide.util.Exceptions; -import org.openide.util.Mutex; import org.openide.util.Parameters; /** @@ -147,7 +147,8 @@ public void addPhaseCompletionTask (final JavaSource js, final CancellableTask task, final JavaSource.Phase phase, - final JavaSource.Priority priority) { + final JavaSource.Priority priority, + final TaskIndexingMode taskIndexingMode) { final Collection sources = getSources(js); assert sources.size() == 1; @@ -155,7 +156,7 @@ if (tasks.keySet().contains(task)) { throw new IllegalArgumentException(String.format("Task: %s is already scheduled", task.toString())); //NOI18N } - final ParserResultTask hanz = new CancelableTaskWrapper(task, pp, phase, js); + final ParserResultTask hanz = new CancelableTaskWrapper(task, pp, phase, js, taskIndexingMode); tasks.put(task, hanz); Utilities.addParserResultTask(hanz, sources.iterator().next()); } @@ -254,10 +255,13 @@ private final int priority; private final CancellableTask task; - public CancelableTaskWrapper (final CancellableTask task, - final int priority, final Phase phase, - final JavaSource javaSource) { - super (phase); + public CancelableTaskWrapper ( + @NonNull final CancellableTask task, + final int priority, + @NonNull final Phase phase, + @NonNull final JavaSource javaSource, + @NonNull final TaskIndexingMode taskIndexingMode) { + super (phase, taskIndexingMode); assert phase != null; assert javaSource != null; this.task = task; diff --git a/parsing.api/apichanges.xml b/parsing.api/apichanges.xml --- a/parsing.api/apichanges.xml +++ b/parsing.api/apichanges.xml @@ -110,6 +110,25 @@ + + + Added IndexingAwareParserResultTask which is a specialization of ParserResultTask + which can be executed during scan. + + + + + +

+ The ParserResultTasks are not executed during the scan to keep the semantic backward compatibility. + A specialization of the ParserResultTask the IndexingAwareParserResultTask was added. + The IndexingAwareParserResultTask can be executed during the scan. +

+
+ + + +
Added ConstrainedBinaryIndexer.Registration.namePattern to allow indexers to use name pattern rather than expensive diff --git a/parsing.api/nbproject/project.properties b/parsing.api/nbproject/project.properties --- a/parsing.api/nbproject/project.properties +++ b/parsing.api/nbproject/project.properties @@ -3,4 +3,4 @@ javac.source=1.6 javadoc.apichanges=${basedir}/apichanges.xml javadoc.arch=${basedir}/arch.xml -spec.version.base=1.50.0 +spec.version.base=1.51.0 diff --git a/parsing.api/src/org/netbeans/modules/parsing/impl/TaskProcessor.java b/parsing.api/src/org/netbeans/modules/parsing/impl/TaskProcessor.java --- a/parsing.api/src/org/netbeans/modules/parsing/impl/TaskProcessor.java +++ b/parsing.api/src/org/netbeans/modules/parsing/impl/TaskProcessor.java @@ -78,17 +78,11 @@ import org.netbeans.modules.parsing.api.Source; import org.netbeans.modules.parsing.api.Task; import org.netbeans.modules.parsing.api.UserTask; +import org.netbeans.modules.parsing.api.indexing.IndexingManager; import org.netbeans.modules.parsing.impl.indexing.RepositoryUpdater; import org.netbeans.modules.parsing.impl.indexing.Util; -import org.netbeans.modules.parsing.spi.EmbeddingProvider; -import org.netbeans.modules.parsing.spi.ParseException; -import org.netbeans.modules.parsing.spi.Parser; +import org.netbeans.modules.parsing.spi.*; import org.netbeans.modules.parsing.spi.Parser.Result; -import org.netbeans.modules.parsing.spi.ParserResultTask; -import org.netbeans.modules.parsing.spi.SchedulerEvent; -import org.netbeans.modules.parsing.spi.SchedulerTask; -import org.netbeans.modules.parsing.spi.Scheduler; -import org.netbeans.modules.parsing.spi.SourceModificationEvent; import org.openide.util.Exceptions; import org.openide.util.Mutex; import org.openide.util.Parameters; @@ -718,7 +712,11 @@ final Parser.Result currentResult = sourceCache.getResult (r.task); if (currentResult != null) { try { - boolean shouldCall = !SourceAccessor.getINSTANCE().testFlag(source, SourceFlags.INVALID); + final boolean sourceInvalid = SourceAccessor.getINSTANCE().testFlag(source, SourceFlags.INVALID); + final boolean scanInProgress = IndexingManager.getDefault().isIndexing(); + final boolean canRunDuringScan = (r.task instanceof IndexingAwareParserResultTask) && + ((IndexingAwareParserResultTask)r.task).getIndexingMode() == TaskIndexingMode.ALLOWED_DURING_SCAN; + final boolean shouldCall = !sourceInvalid && (!scanInProgress || canRunDuringScan); if (shouldCall) { try { final long startTime = System.currentTimeMillis(); diff --git a/parsing.api/src/org/netbeans/modules/parsing/spi/IndexingAwareParserResultTask.java b/parsing.api/src/org/netbeans/modules/parsing/spi/IndexingAwareParserResultTask.java new file mode 100644 --- /dev/null +++ b/parsing.api/src/org/netbeans/modules/parsing/spi/IndexingAwareParserResultTask.java @@ -0,0 +1,63 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2012 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle 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 2012 Sun Microsystems, Inc. + */ +package org.netbeans.modules.parsing.spi; + +import org.netbeans.api.annotations.common.NonNull; +import org.openide.util.Parameters; + +/** + * + * @author Tomas Zezula + * @since 1.51 + */ +public abstract class IndexingAwareParserResultTask extends ParserResultTask { + private final TaskIndexingMode scanMode; + + protected IndexingAwareParserResultTask(@NonNull final TaskIndexingMode scanMode) { + Parameters.notNull("scanMode", scanMode); //NOI18N + this.scanMode = scanMode; + } + + public final TaskIndexingMode getIndexingMode() { + return scanMode; + } +} diff --git a/parsing.api/src/org/netbeans/modules/parsing/spi/TaskIndexingMode.java b/parsing.api/src/org/netbeans/modules/parsing/spi/TaskIndexingMode.java new file mode 100644 --- /dev/null +++ b/parsing.api/src/org/netbeans/modules/parsing/spi/TaskIndexingMode.java @@ -0,0 +1,52 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 2012 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle 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 2012 Sun Microsystems, Inc. + */ +package org.netbeans.modules.parsing.spi; + +/** + * + * @author Tomas Zezula + * @since 1.51 + */ +public enum TaskIndexingMode { + ALLOWED_DURING_SCAN, + DISALLOWED_DURING_SCAN +} diff --git a/spellchecker.bindings.java/nbproject/project.xml b/spellchecker.bindings.java/nbproject/project.xml --- a/spellchecker.bindings.java/nbproject/project.xml +++ b/spellchecker.bindings.java/nbproject/project.xml @@ -54,7 +54,7 @@ - 0.26 + 0.94 @@ -67,6 +67,15 @@ + org.netbeans.modules.parsing.api + + + + 1 + 1.51 + + + org.netbeans.modules.spellchecker.apimodule diff --git a/spellchecker.bindings.java/src/org/netbeans/modules/spellchecker/bindings/java/JavaSemanticTokenList.java b/spellchecker.bindings.java/src/org/netbeans/modules/spellchecker/bindings/java/JavaSemanticTokenList.java --- a/spellchecker.bindings.java/src/org/netbeans/modules/spellchecker/bindings/java/JavaSemanticTokenList.java +++ b/spellchecker.bindings.java/src/org/netbeans/modules/spellchecker/bindings/java/JavaSemanticTokenList.java @@ -60,6 +60,7 @@ import org.netbeans.api.java.source.JavaSource.Phase; import org.netbeans.api.java.source.JavaSource.Priority; import org.netbeans.api.java.source.support.EditorAwareJavaSourceTaskFactory; +import org.netbeans.modules.parsing.spi.TaskIndexingMode; import org.netbeans.modules.spellchecker.spi.language.TokenList; import org.openide.filesystems.FileObject; import org.openide.util.ChangeSupport; @@ -273,7 +274,7 @@ public static final class FactoryImpl extends EditorAwareJavaSourceTaskFactory { public FactoryImpl() { - super(Phase.PARSED, Priority.LOW); + super(Phase.PARSED, Priority.LOW, TaskIndexingMode.ALLOWED_DURING_SCAN); } @Override