You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by db...@apache.org on 2022/03/28 06:37:33 UTC
[netbeans] branch master updated: GroovyVirtualSourceProvider should run GroovyParser in 'indexing' mode. (#3859)
This is an automated email from the ASF dual-hosted git repository.
dbalek pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git
The following commit(s) were added to refs/heads/master by this push:
new 93db1c4 GroovyVirtualSourceProvider should run GroovyParser in 'indexing' mode. (#3859)
93db1c4 is described below
commit 93db1c4fb105a9ab8c3e08f1495bc28b4b5dcbf3
Author: Dusan Balek <du...@oracle.com>
AuthorDate: Mon Mar 28 08:37:07 2022 +0200
GroovyVirtualSourceProvider should run GroovyParser in 'indexing' mode. (#3859)
---
.../groovy/editor/api/parser/GroovyParser.java | 7 ++--
.../api/parser/GroovyVirtualSourceProvider.java | 46 +++++++++++++---------
.../groovy/editor/compiler/GroovyIndexingTask.java | 22 +++++++++++
.../compiler/SimpleTransformationCustomizer.java | 8 ++--
.../modules/groovy/editor/utils/GroovyUtils.java | 7 +++-
5 files changed, 62 insertions(+), 28 deletions(-)
diff --git a/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/api/parser/GroovyParser.java b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/api/parser/GroovyParser.java
index bf5d691..24191cd 100644
--- a/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/api/parser/GroovyParser.java
+++ b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/api/parser/GroovyParser.java
@@ -82,7 +82,6 @@ import org.netbeans.modules.parsing.api.Task;
import org.netbeans.modules.parsing.spi.ParseException;
import org.netbeans.modules.parsing.spi.Parser;
import org.netbeans.modules.parsing.spi.SourceModificationEvent;
-import org.netbeans.modules.parsing.spi.indexing.support.IndexingSupport;
import org.netbeans.spi.java.classpath.support.ClassPathSupport;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;
@@ -152,7 +151,7 @@ public class GroovyParser extends Parser {
cancelled.set(false);
if (!GroovyUtils.isIndexingEnabled()) {
- if (IndexingSupport.isIndexingTask(task)) { // NOI18N
+ if (GroovyUtils.isIndexingTask(task)) {
lastResult = createParseResult(snapshot, null, null);
return;
}
@@ -640,7 +639,7 @@ public class GroovyParser extends Parser {
);
}
- boolean indexing = IndexingSupport.isIndexingTask(context.parserTask);
+ boolean indexing = GroovyUtils.isIndexingTask(context.parserTask);
configuration = makeConfiguration(configuration, context, indexing);
CU compilationUnit = new CU(indexing, this, configuration,
null, classLoader, transformationLoader, cpInfo, classNodeCache,
@@ -803,7 +802,7 @@ public class GroovyParser extends Parser {
return sanitize(context, sanitizing);
}
}
-
+
private static void logParsingTime(Context context, long start, boolean cancelled) {
long diff = System.currentTimeMillis() - start;
long full = PARSING_TIME.addAndGet(diff);
diff --git a/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/api/parser/GroovyVirtualSourceProvider.java b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/api/parser/GroovyVirtualSourceProvider.java
index b69bd3f..9d303de 100644
--- a/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/api/parser/GroovyVirtualSourceProvider.java
+++ b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/api/parser/GroovyVirtualSourceProvider.java
@@ -54,6 +54,7 @@ import org.codehaus.groovy.ast.stmt.Statement;
import org.codehaus.groovy.control.ResolveVisitor;
import org.netbeans.modules.groovy.editor.api.ASTUtils;
import org.netbeans.modules.groovy.editor.api.elements.ast.ASTRoot;
+import org.netbeans.modules.groovy.editor.compiler.GroovyIndexingTask;
import org.netbeans.modules.java.preprocessorbridge.spi.VirtualSourceProvider;
import org.netbeans.modules.parsing.api.ParserManager;
import org.netbeans.modules.parsing.api.ResultIterator;
@@ -124,7 +125,7 @@ public class GroovyVirtualSourceProvider implements VirtualSourceProvider {
@SuppressWarnings("unchecked")
static List<ClassNode> getClassNodes(File file) {
- final List<ClassNode> resultList = new ArrayList<ClassNode>();
+ final List<ClassNode> resultList = new ArrayList<>();
FileObject fo = FileUtil.toFileObject(file);
if (fo != null) {
Source source = Source.create(fo);
@@ -132,23 +133,7 @@ public class GroovyVirtualSourceProvider implements VirtualSourceProvider {
if (GroovyLanguage.GROOVY_MIME_TYPE.equals(source.getMimeType())) {
try {
// FIXME can we move this out of task (?)
- ParserManager.parse(Collections.singleton(source), new UserTask() {
- @Override
- public void run(ResultIterator resultIterator) throws Exception {
- Parser.Result parseResult = resultIterator.getParserResult();
- if (parseResult != null) {
- GroovyParserResult result = ASTUtils.getParseResult(parseResult);
-
- ASTRoot astRootElement = result.getRootElement();
- if (astRootElement != null) {
- ModuleNode moduleNode = astRootElement.getModuleNode();
- if (moduleNode != null) {
- resultList.addAll(moduleNode.getClasses());
- }
- }
- }
- }
- });
+ ParserManager.parse(Collections.singleton(source), new Task(resultList));
} catch (ParseException ex) {
Exceptions.printStackTrace(ex);
}
@@ -158,6 +143,31 @@ public class GroovyVirtualSourceProvider implements VirtualSourceProvider {
return resultList;
}
+ static class Task extends UserTask implements GroovyIndexingTask {
+
+ private final List<ClassNode> resultList;
+
+ public Task(List<ClassNode> resultList) {
+ this.resultList = resultList;
+ }
+
+ @Override
+ public void run(ResultIterator resultIterator) throws Exception {
+ Parser.Result parseResult = resultIterator.getParserResult();
+ if (parseResult != null) {
+ GroovyParserResult result = ASTUtils.getParseResult(parseResult);
+
+ ASTRoot astRootElement = result.getRootElement();
+ if (astRootElement != null) {
+ ModuleNode moduleNode = astRootElement.getModuleNode();
+ if (moduleNode != null) {
+ resultList.addAll(moduleNode.getClasses());
+ }
+ }
+ }
+ }
+ }
+
@SuppressWarnings("unchecked")
static final class JavaStubGenerator {
diff --git a/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/compiler/GroovyIndexingTask.java b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/compiler/GroovyIndexingTask.java
new file mode 100644
index 0000000..44d753a
--- /dev/null
+++ b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/compiler/GroovyIndexingTask.java
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.netbeans.modules.groovy.editor.compiler;
+
+public interface GroovyIndexingTask {
+}
diff --git a/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/compiler/SimpleTransformationCustomizer.java b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/compiler/SimpleTransformationCustomizer.java
index 0594444..699af9b 100644
--- a/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/compiler/SimpleTransformationCustomizer.java
+++ b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/compiler/SimpleTransformationCustomizer.java
@@ -34,7 +34,7 @@ import org.codehaus.groovy.control.CompilerConfiguration;
import org.codehaus.groovy.transform.ASTTransformation;
import org.codehaus.groovy.transform.GroovyASTTransformation;
import org.netbeans.modules.groovy.editor.api.parser.ApplyGroovyTransformation;
-import org.netbeans.modules.parsing.spi.indexing.support.IndexingSupport;
+import org.netbeans.modules.groovy.editor.utils.GroovyUtils;
/**
* Simple {@link ParsingCompilerCustomizer} implementation: adds or disables Groovy AST
@@ -88,8 +88,7 @@ public final class SimpleTransformationCustomizer implements ParsingCompilerCust
@Override
public CompilerConfiguration configureParsingCompiler(Context ctx, CompilerConfiguration cfg) {
- Cfg c = IndexingSupport.isIndexingTask(ctx.getConsumerTask()) ?
- indexing : parsing;
+ Cfg c = GroovyUtils.isIndexingTask(ctx.getConsumerTask()) ? indexing : parsing;
if (!c.disableTransformations.isEmpty()) {
Set<String> disabled = cfg.getDisabledGlobalASTTransformations();
if (disabled == null) {
@@ -105,8 +104,7 @@ public final class SimpleTransformationCustomizer implements ParsingCompilerCust
@Override
public void decorateCompilation(Context ctx, CompilationUnit cu) {
- Cfg c = IndexingSupport.isIndexingTask(ctx.getConsumerTask()) ?
- indexing : parsing;
+ Cfg c = GroovyUtils.isIndexingTask(ctx.getConsumerTask()) ? indexing : parsing;
GroovyClassLoader transformLoader = cu.getTransformLoader();
Collection<String> clist = c.addTransformations;
if (clist == null || clist.isEmpty()) {
diff --git a/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/utils/GroovyUtils.java b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/utils/GroovyUtils.java
index a4eed92..fa0f786 100644
--- a/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/utils/GroovyUtils.java
+++ b/groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/utils/GroovyUtils.java
@@ -22,9 +22,11 @@ package org.netbeans.modules.groovy.editor.utils;
import javax.swing.text.BadLocationException;
import org.codehaus.groovy.ast.ASTNode;
import org.codehaus.groovy.ast.ClassNode;
-import org.codehaus.groovy.ast.GenericsType;
import org.codehaus.groovy.ast.expr.Expression;
import org.codehaus.groovy.transform.stc.StaticTypesMarker;
+import org.netbeans.modules.groovy.editor.compiler.GroovyIndexingTask;
+import org.netbeans.modules.parsing.api.Task;
+import org.netbeans.modules.parsing.spi.indexing.support.IndexingSupport;
/**
*
@@ -306,4 +308,7 @@ public final class GroovyUtils {
return indexingEnabled;
}
+ public static boolean isIndexingTask(Task t) {
+ return IndexingSupport.isIndexingTask(t) || t instanceof GroovyIndexingTask;
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists