This is an automated email from the ASF dual-hosted git repository.

jlahoda 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 c678b4e  More stabilization of the vanilla javac indexer.
c678b4e is described below

commit c678b4eb09b60904b7fb2db4f6f28c2a5bd1d32f
Author: Jan Lahoda <[email protected]>
AuthorDate: Mon Dec 2 21:58:04 2019 +0100

    More stabilization of the vanilla javac indexer.
---
 .../java/source/indexing/VanillaCompileWorker.java | 36 +++++++++--
 .../api/java/source/SourceUtilsTestUtil.java       | 28 ++++-----
 .../source/indexing/CompileWorkerTestBase.java     | 20 +++++-
 .../source/indexing/VanillaCompileWorkerTest.java  | 73 ++++++++++++++++++++++
 .../org/netbeans/lib/nbjavac/services/NBEnter.java | 18 ++++++
 .../lib/nbjavac/services/NBJavaCompiler.java       | 30 +++++++++
 6 files changed, 184 insertions(+), 21 deletions(-)

diff --git 
a/java/java.source.base/src/org/netbeans/modules/java/source/indexing/VanillaCompileWorker.java
 
b/java/java.source.base/src/org/netbeans/modules/java/source/indexing/VanillaCompileWorker.java
index 7f4f633..8aec3e5 100644
--- 
a/java/java.source.base/src/org/netbeans/modules/java/source/indexing/VanillaCompileWorker.java
+++ 
b/java/java.source.base/src/org/netbeans/modules/java/source/indexing/VanillaCompileWorker.java
@@ -88,6 +88,7 @@ import org.netbeans.api.java.queries.BinaryForSourceQuery;
 import org.netbeans.api.java.queries.CompilerOptionsQuery;
 import org.netbeans.api.java.source.ClasspathInfo;
 import org.netbeans.api.java.source.ElementHandle;
+import org.netbeans.lib.nbjavac.services.NBJavaCompiler;
 import 
org.netbeans.modules.java.source.indexing.JavaCustomIndexer.CompileTuple;
 import org.netbeans.modules.java.source.parsing.FileManagerTransaction;
 import org.netbeans.modules.java.source.parsing.FileObjects;
@@ -305,6 +306,12 @@ final class VanillaCompileWorker extends CompileWorker {
                 return ParsingOutput.lowMemory(moduleName.name, file2FQNs, 
addedTypes, addedModules, createdFiles, finished, modifiedTypes, aptGenerated);
             }
             final JavacTaskImpl jtFin = jt;
+            ((NBJavaCompiler) 
NBJavaCompiler.instance(jt.getContext())).setDesugarCallback(env -> {
+                if (env == null) {
+                    return;
+                }
+                dropMethodsAndErrors(jtFin.getContext(), env.toplevel);
+            });
             final Future<Void> done = FileManagerTransaction.runConcurrent(new 
FileSystem.AtomicAction() {
                 @Override
                 public void run() throws IOException {
@@ -547,15 +554,23 @@ final class VanillaCompileWorker extends CompileWorker {
                     return null;
                 }
                 Type.ClassType ct = (Type.ClassType) csym.type;
-                ct.all_interfaces_field = 
error2Object(ct.all_interfaces_field);
-                ct.allparams_field = error2Object(ct.allparams_field);
-                ct.interfaces_field = error2Object(ct.interfaces_field);
-                ct.typarams_field = error2Object(ct.typarams_field);
-                ct.supertype_field = error2Object(ct.supertype_field);
+                if (csym == syms.objectType.tsym) {
+                    ct.all_interfaces_field = 
com.sun.tools.javac.util.List.nil();
+                    ct.allparams_field = com.sun.tools.javac.util.List.nil();
+                    ct.interfaces_field = com.sun.tools.javac.util.List.nil();
+                    ct.typarams_field = com.sun.tools.javac.util.List.nil();
+                    ct.supertype_field = Type.noType;
+                } else {
+                    ct.all_interfaces_field = 
error2Object(ct.all_interfaces_field);
+                    ct.allparams_field = error2Object(ct.allparams_field);
+                    ct.interfaces_field = error2Object(ct.interfaces_field);
+                    ct.typarams_field = error2Object(ct.typarams_field);
+                    ct.supertype_field = error2Object(ct.supertype_field);
+                }
                 clearAnnotations(clazz.sym.getMetadata());
                 super.visitClass(node, p);
                 for (JCTree def : clazz.defs) {
-                    if (def.hasTag(JCTree.Tag.ERRONEOUS)) {
+                    if (def.hasTag(JCTree.Tag.ERRONEOUS) || 
def.hasTag(JCTree.Tag.BLOCK)) {
                         clazz.defs = 
com.sun.tools.javac.util.List.filter(clazz.defs, def);
                     }
                 }
@@ -618,7 +633,16 @@ final class VanillaCompileWorker extends CompileWorker {
                         clearTypeVar((Type.TypeVar) t);
                         break;
                     }
+                    case ARRAY: {
+                        Type.ArrayType at = (Type.ArrayType) t;
+                        Type component = error2Object(at.elemtype);
+                        if (component != at.elemtype) {
+                            at.elemtype = types.makeArrayType(component);
+                        }
+                        break;
+                    }
                 }
+
                 return t;
             }
 
diff --git 
a/java/java.source.base/test/unit/src/org/netbeans/api/java/source/SourceUtilsTestUtil.java
 
b/java/java.source.base/test/unit/src/org/netbeans/api/java/source/SourceUtilsTestUtil.java
index 5beacba..8c46bdf 100644
--- 
a/java/java.source.base/test/unit/src/org/netbeans/api/java/source/SourceUtilsTestUtil.java
+++ 
b/java/java.source.base/test/unit/src/org/netbeans/api/java/source/SourceUtilsTestUtil.java
@@ -184,6 +184,10 @@ public final class SourceUtilsTestUtil extends ProxyLookup 
{
     }
     
     public static void prepareTest(FileObject sourceRoot, FileObject 
buildRoot, FileObject cache, FileObject[] classPathElements) throws Exception {
+        prepareTest(ClassPathSupport.createClassPath(sourceRoot), buildRoot, 
cache, classPathElements);
+    }
+
+    public static void prepareTest(ClassPath sourceCP, FileObject buildRoot, 
FileObject cache, FileObject[] classPathElements) throws Exception {
         if (extraLookupContent == null)
             prepareTest(new String[0], new Object[0]);
         
@@ -191,8 +195,8 @@ public final class SourceUtilsTestUtil extends ProxyLookup {
         
         System.arraycopy(extraLookupContent, 0, lookupContent, 4, 
extraLookupContent.length);
         
-        lookupContent[0] = new TestProxyClassPathProvider(sourceRoot, 
buildRoot, classPathElements);
-        lookupContent[1] = new TestSourceForBinaryQuery(sourceRoot, buildRoot);
+        lookupContent[0] = new TestProxyClassPathProvider(sourceCP, buildRoot, 
classPathElements);
+        lookupContent[1] = new TestSourceForBinaryQuery(sourceCP, buildRoot);
         lookupContent[2] = new TestSourceLevelQueryImplementation();
         lookupContent[3] = JavaDataLoader.findObject(JavaDataLoader.class, 
true);
         
@@ -235,11 +239,11 @@ public final class SourceUtilsTestUtil extends 
ProxyLookup {
 
     private static class TestSourceForBinaryQuery implements 
SourceForBinaryQueryImplementation {
         
-        private final FileObject sourceRoot;
+        private final ClassPath sourcePath;
         private final FileObject buildRoot;
         
-        public TestSourceForBinaryQuery(FileObject sourceRoot, FileObject 
buildRoot) {
-            this.sourceRoot = sourceRoot;
+        public TestSourceForBinaryQuery(ClassPath sourcePath, FileObject 
buildRoot) {
+            this.sourcePath = sourcePath;
             this.buildRoot = buildRoot;
         }
         
@@ -249,9 +253,7 @@ public final class SourceUtilsTestUtil extends ProxyLookup {
             if (buildRoot.equals(f)) {
                 return new SourceForBinaryQuery.Result() {
                     public FileObject[] getRoots() {
-                        return new FileObject[] {
-                            sourceRoot,
-                        };
+                        return sourcePath.getRoots();
                     }
 
                     public void addChangeListener(ChangeListener l) {
@@ -269,12 +271,12 @@ public final class SourceUtilsTestUtil extends 
ProxyLookup {
     
     private static class TestProxyClassPathProvider implements 
ClassPathProvider {
         
-        private FileObject sourceRoot;
+        private ClassPath sourcePath;
         private FileObject buildRoot;
         private FileObject[] classPathElements;
         
-        public TestProxyClassPathProvider(FileObject sourceRoot, FileObject 
buildRoot, FileObject[] classPathElements) {
-            this.sourceRoot = sourceRoot;
+        public TestProxyClassPathProvider(ClassPath sourcePath, FileObject 
buildRoot, FileObject[] classPathElements) {
+            this.sourcePath = sourcePath;
             this.buildRoot = buildRoot;
             this.classPathElements = classPathElements;
         }
@@ -290,9 +292,7 @@ public final class SourceUtilsTestUtil extends ProxyLookup {
                 }
             
             if (ClassPath.SOURCE == type) {
-                return ClassPathSupport.createClassPath(new FileObject[] {
-                    sourceRoot
-                });
+                return sourcePath;
             }
             
             if (ClassPath.COMPILE == type) {
diff --git 
a/java/java.source.base/test/unit/src/org/netbeans/modules/java/source/indexing/CompileWorkerTestBase.java
 
b/java/java.source.base/test/unit/src/org/netbeans/modules/java/source/indexing/CompileWorkerTestBase.java
index b64a2d1..3e9b1ad 100644
--- 
a/java/java.source.base/test/unit/src/org/netbeans/modules/java/source/indexing/CompileWorkerTestBase.java
+++ 
b/java/java.source.base/test/unit/src/org/netbeans/modules/java/source/indexing/CompileWorkerTestBase.java
@@ -20,10 +20,14 @@ package org.netbeans.modules.java.source.indexing;
 
 import com.sun.tools.javac.code.Symbol.ClassSymbol;
 import java.io.File;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
@@ -128,6 +132,10 @@ public abstract class CompileWorkerTestBase extends 
NbTestCase {
     }
 
     protected ParsingOutput runIndexing(List<CompileTuple> files, 
List<CompileTuple> virtualFiles) throws Exception {
+        return runIndexing(files, virtualFiles, Collections.emptyList());
+    }
+
+    protected ParsingOutput runIndexing(List<CompileTuple> files, 
List<CompileTuple> virtualFiles, List<CompileTuple> extraSourceFiles) throws 
Exception {
         TransactionContext txc = 
TransactionContext.beginStandardTransaction(src.toURL(), true, ()->false, 
false);
         Factory f = new JavaCustomIndexer.Factory();
         Context ctx = 
SPIAccessor.getInstance().createContext(CacheFolder.getDataFolder(src.toURL()), 
src.toURL(), f.getIndexerName(), f.getIndexVersion(), 
LuceneIndexFactory.getDefault(), false, false, true, 
SPIAccessor.getInstance().createSuspendStatus(new SuspendStatusImpl() {
@@ -151,6 +159,13 @@ public abstract class CompileWorkerTestBase extends 
NbTestCase {
         toIndex.addAll(files);
         toIndex.addAll(virtualFiles);
         
+        for (CompileTuple extra : extraSourceFiles) {
+            try (OutputStream out = FileUtil.createData(extraSrc, 
extra.indexable.getRelativePath()).getOutputStream();
+                 Writer w = new OutputStreamWriter(out)) {
+                w.append(extra.jfo.getCharContent(true));
+            }
+        }
+
         ParsingOutput result = runCompileWorker(ctx, javaContext, toIndex);
         
         txc.commit();
@@ -171,13 +186,16 @@ public abstract class CompileWorkerTestBase extends 
NbTestCase {
         FileObject wd = FileUtil.toFileObject(wdFile);
         assertNotNull(wd);
         src = FileUtil.createFolder(wd, "src");
+        extraSrc = FileUtil.createFolder(wd, "extraSrc");
         FileObject buildRoot = FileUtil.createFolder(wd, "build");
         FileObject cache = FileUtil.createFolder(wd, "cache");
+        ClassPath sourcePath = ClassPathSupport.createClassPath(src, extraSrc);
 
-        SourceUtilsTestUtil.prepareTest(src, buildRoot, cache);
+        SourceUtilsTestUtil.prepareTest(sourcePath, buildRoot, cache, new 
FileObject[0]);
     }
     
     private FileObject src;
+    private FileObject extraSrc;
     private String sourceLevel;
     
     private FileObject createSrcFile(String pathAndName, String content) 
throws Exception {
diff --git 
a/java/java.source.base/test/unit/src/org/netbeans/modules/java/source/indexing/VanillaCompileWorkerTest.java
 
b/java/java.source.base/test/unit/src/org/netbeans/modules/java/source/indexing/VanillaCompileWorkerTest.java
index 77fbe73..44c2a64 100644
--- 
a/java/java.source.base/test/unit/src/org/netbeans/modules/java/source/indexing/VanillaCompileWorkerTest.java
+++ 
b/java/java.source.base/test/unit/src/org/netbeans/modules/java/source/indexing/VanillaCompileWorkerTest.java
@@ -333,6 +333,79 @@ public class VanillaCompileWorkerTest extends 
CompileWorkerTestBase {
         //TODO: check file content!!!
     }
 
+    public void testArrayType() throws Exception {
+        ParsingOutput result = 
runIndexing(Arrays.asList(compileTuple("test/Test4.java", "package test; public 
class Test4 { public void test(Undef[] undef1, Undef undef2) { 
undef1.invoke(undef2); } }")),
+                                           Arrays.asList());
+
+        assertFalse(result.lowMemory);
+        assertTrue(result.success);
+
+        Set<String> createdFiles = new HashSet<String>();
+
+        for (File created : result.createdFiles) {
+            
createdFiles.add(getWorkDir().toURI().relativize(created.toURI()).getPath());
+        }
+
+        assertEquals(new 
HashSet<String>(Arrays.asList("cache/s1/java/15/classes/test/Test4.sig")),
+                     createdFiles);
+        //TODO: check file content!!!
+    }
+
+    public void testStaticInitializer() throws Exception {
+        ParsingOutput result = 
runIndexing(Arrays.asList(compileTuple("test/Test4.java", "package test; public 
class Test4 { static { undef1.invoke(undef2); } }")),
+                                           Arrays.asList());
+
+        assertFalse(result.lowMemory);
+        assertTrue(result.success);
+
+        Set<String> createdFiles = new HashSet<String>();
+
+        for (File created : result.createdFiles) {
+            
createdFiles.add(getWorkDir().toURI().relativize(created.toURI()).getPath());
+        }
+
+        assertEquals(new 
HashSet<String>(Arrays.asList("cache/s1/java/15/classes/test/Test4.sig")),
+                     createdFiles);
+        //TODO: check file content!!!
+    }
+
+    public void testJLObject() throws Exception {
+        ParsingOutput result = 
runIndexing(Arrays.asList(compileTuple("java/lang/Object.java", "package 
java.lang; public class Object { }")),
+                                           Arrays.asList());
+
+        assertFalse(result.lowMemory);
+        assertTrue(result.success);
+
+        Set<String> createdFiles = new HashSet<String>();
+
+        for (File created : result.createdFiles) {
+            
createdFiles.add(getWorkDir().toURI().relativize(created.toURI()).getPath());
+        }
+
+        assertEquals(new 
HashSet<String>(Arrays.asList("cache/s1/java/15/classes/java/lang/Object.sig")),
+                     createdFiles);
+        //TODO: check file content!!!
+    }
+
+    public void testFromOtherSourceRootBroken() throws Exception {
+        ParsingOutput result = 
runIndexing(Arrays.asList(compileTuple("test/Test4.java", "package test; public 
class Test4 extends extra.Extra { }")),
+                                           Arrays.asList(),
+                                           
Arrays.asList(compileTuple("extra/Extra.java", "package extra; public class 
Extra { private void get() { undef(); } }")));
+
+        assertFalse(result.lowMemory);
+        assertTrue(result.success);
+
+        Set<String> createdFiles = new HashSet<String>();
+
+        for (File created : result.createdFiles) {
+            
createdFiles.add(getWorkDir().toURI().relativize(created.toURI()).getPath());
+        }
+
+        assertEquals(new 
HashSet<String>(Arrays.asList("cache/s1/java/15/classes/test/Test4.sig")),
+                     createdFiles);
+        //TODO: check file content!!!
+    }
+
     public static void noop() {}
 
     @Override
diff --git 
a/java/lib.nbjavac/src/org/netbeans/lib/nbjavac/services/NBEnter.java 
b/java/lib.nbjavac/src/org/netbeans/lib/nbjavac/services/NBEnter.java
index 475fa4d..2ef77f3 100644
--- a/java/lib.nbjavac/src/org/netbeans/lib/nbjavac/services/NBEnter.java
+++ b/java/lib.nbjavac/src/org/netbeans/lib/nbjavac/services/NBEnter.java
@@ -18,8 +18,13 @@
  */
 package org.netbeans.lib.nbjavac.services;
 
+import com.sun.tools.javac.code.Symbol;
+import com.sun.tools.javac.code.Symbol.TypeSymbol;
 import com.sun.tools.javac.code.Symtab;
+import com.sun.tools.javac.comp.AttrContext;
 import com.sun.tools.javac.comp.Enter;
+import com.sun.tools.javac.comp.Env;
+import com.sun.tools.javac.main.JavaCompiler;
 import com.sun.tools.javac.tree.JCTree;
 import com.sun.tools.javac.tree.JCTree.JCClassDecl;
 import com.sun.tools.javac.tree.TreeInfo;
@@ -42,11 +47,14 @@ public class NBEnter extends Enter {
 
     private final CancelService cancelService;
     private final Symtab syms;
+    private final NBJavaCompiler compiler;
 
     public NBEnter(Context context) {
         super(context);
         cancelService = CancelService.instance(context);
         syms = Symtab.instance(context);
+        JavaCompiler c = JavaCompiler.instance(context);
+        compiler = c instanceof NBJavaCompiler ? (NBJavaCompiler) c : null;
     }
 
     @Override
@@ -68,4 +76,14 @@ public class NBEnter extends Enter {
     protected int getIndex(JCClassDecl clazz) {
         return clazz instanceof IndexedClassDecl ? ((IndexedClassDecl) 
clazz).index : -1;
     }
+
+    @Override
+    public Env<AttrContext> getEnv(TypeSymbol sym) {
+        Env<AttrContext> env = super.getEnv(sym);
+        if (compiler != null) {
+            compiler.maybeInvokeDesugarCallback(env);
+        }
+        return env;
+    }
+
 }
diff --git 
a/java/lib.nbjavac/src/org/netbeans/lib/nbjavac/services/NBJavaCompiler.java 
b/java/lib.nbjavac/src/org/netbeans/lib/nbjavac/services/NBJavaCompiler.java
index 8a96595..65f1182 100644
--- a/java/lib.nbjavac/src/org/netbeans/lib/nbjavac/services/NBJavaCompiler.java
+++ b/java/lib.nbjavac/src/org/netbeans/lib/nbjavac/services/NBJavaCompiler.java
@@ -18,12 +18,17 @@
  */
 package org.netbeans.lib.nbjavac.services;
 
+import com.sun.tools.javac.comp.AttrContext;
+import com.sun.tools.javac.comp.Env;
 import com.sun.tools.javac.main.JavaCompiler;
 import com.sun.tools.javac.tree.JCTree;
 import com.sun.tools.javac.util.Context;
 import com.sun.tools.javac.util.List;
+import com.sun.tools.javac.util.Pair;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Queue;
+import java.util.function.Consumer;
 
 /**
  *
@@ -40,6 +45,7 @@ public class NBJavaCompiler extends JavaCompiler {
     }
 
     private final CancelService cancelService;
+    private Consumer<Env<AttrContext>> desugarCallback;
 
     public NBJavaCompiler(Context context) {
         super(context);
@@ -63,4 +69,28 @@ public class NBJavaCompiler extends JavaCompiler {
     private void setOrigin(String origin) {
         fileManager.handleOption("apt-origin", 
Collections.singletonList(origin).iterator());
     }
+
+    public void setDesugarCallback(Consumer<Env<AttrContext>> callback) {
+        this.desugarCallback = callback;
+    }
+
+    private boolean desugaring;
+
+    @Override
+    protected void desugar(Env<AttrContext> env, Queue<Pair<Env<AttrContext>, 
JCTree.JCClassDecl>> results) {
+        boolean prevDesugaring = desugaring;
+        try {
+            desugaring = true;
+        super.desugar(env, results);
+        } finally {
+            desugaring = prevDesugaring;
+        }
+    }
+
+    void maybeInvokeDesugarCallback(Env<AttrContext> env) {
+        if (desugaring && desugarCallback != null) {
+            desugarCallback.accept(env);
+        }
+    }
+
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to