You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by lk...@apache.org on 2019/04/25 23:06:31 UTC
[netbeans] branch master updated: [NETBEANS-2392] adjusting handling of erroneous types in TreeFactory … (#1210)
This is an automated email from the ASF dual-hosted git repository.
lkishalmi 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 c1fb428 [NETBEANS-2392] adjusting handling of erroneous types in TreeFactory … (#1210)
c1fb428 is described below
commit c1fb428310c30ba742bf8cea4b1cb501ceea842c
Author: Jan Lahoda <jl...@netbeans.org>
AuthorDate: Fri Apr 26 01:06:25 2019 +0200
[NETBEANS-2392] adjusting handling of erroneous types in TreeFactory … (#1210)
* [NETBEANS-2392] adjusting handling of erroneous types in TreeFactory to current javac model
* Adding forgotten test file.
---
.../modules/java/source/builder/TreeFactory.java | 8 +-
.../modules/java/source/save/ElementOverlay.java | 6 +-
.../source/transform/ImmutableTreeTranslator.java | 2 +-
.../api/java/source/gen/ErrorTypeTest.java | 128 +++++++++++++++++++++
4 files changed, 139 insertions(+), 5 deletions(-)
diff --git a/java/java.source.base/src/org/netbeans/modules/java/source/builder/TreeFactory.java b/java/java.source.base/src/org/netbeans/modules/java/source/builder/TreeFactory.java
index 7fd32f9..0ee4288 100644
--- a/java/java.source.base/src/org/netbeans/modules/java/source/builder/TreeFactory.java
+++ b/java/java.source.base/src/org/netbeans/modules/java/source/builder/TreeFactory.java
@@ -846,6 +846,11 @@ public class TreeFactory {
tp = make.at(NOPOS).Wildcard(make.at(NOPOS).TypeBoundKind(a.kind), (JCExpression) Type(a.type));
break;
}
+ case ERROR:
+ if (t.hasTag(TypeTag.ERROR)) {
+ tp = make.at(NOPOS).Ident(((ErrorType) type).tsym.name);
+ break;
+ }
case DECLARED:
JCExpression clazz = (JCExpression) QualIdent(t.tsym);
tp = t.getTypeArguments().isEmpty()
@@ -859,9 +864,6 @@ public class TreeFactory {
case NULL:
tp = make.at(NOPOS).Literal(TypeTag.BOT, null);
break;
- case ERROR:
- tp = make.at(NOPOS).Ident(((ErrorType) type).tsym.name);
- break;
default:
return make.at(NOPOS).Type((Type)type);
}
diff --git a/java/java.source.base/src/org/netbeans/modules/java/source/save/ElementOverlay.java b/java/java.source.base/src/org/netbeans/modules/java/source/save/ElementOverlay.java
index 94d9c99..d5a722b 100644
--- a/java/java.source.base/src/org/netbeans/modules/java/source/save/ElementOverlay.java
+++ b/java/java.source.base/src/org/netbeans/modules/java/source/save/ElementOverlay.java
@@ -184,7 +184,11 @@ public class ElementOverlay {
}
public Element resolve(ASTService ast, Elements elements, String what, ModuleElement modle) {
- Element result = null;
+ return resolve(ast, elements, what, null, modle);
+ }
+
+ public Element resolve(ASTService ast, Elements elements, String what, Element original, ModuleElement modle) {
+ Element result = original;
if (classes.containsKey(what)) {
result = createElement(ast, elements, what, null, modle);
diff --git a/java/java.source.base/src/org/netbeans/modules/java/source/transform/ImmutableTreeTranslator.java b/java/java.source.base/src/org/netbeans/modules/java/source/transform/ImmutableTreeTranslator.java
index a88916a..a4a93ce 100644
--- a/java/java.source.base/src/org/netbeans/modules/java/source/transform/ImmutableTreeTranslator.java
+++ b/java/java.source.base/src/org/netbeans/modules/java/source/transform/ImmutableTreeTranslator.java
@@ -468,7 +468,7 @@ public class ImmutableTreeTranslator implements TreeVisitor<Tree,Object> {
el = overlay.resolve(model, elements, qit.getFQN());
} else {
if (el.getKind().isClass() || el.getKind().isInterface() || el.getKind() == ElementKind.PACKAGE) {
- el = overlay.resolve(model, elements, ((QualifiedNameable) el).getQualifiedName().toString(), elements.getModuleOf(el));
+ el = overlay.resolve(model, elements, ((QualifiedNameable) el).getQualifiedName().toString(), el, elements.getModuleOf(el));
}
}
diff --git a/java/java.source.base/test/unit/src/org/netbeans/api/java/source/gen/ErrorTypeTest.java b/java/java.source.base/test/unit/src/org/netbeans/api/java/source/gen/ErrorTypeTest.java
new file mode 100644
index 0000000..8c37924
--- /dev/null
+++ b/java/java.source.base/test/unit/src/org/netbeans/api/java/source/gen/ErrorTypeTest.java
@@ -0,0 +1,128 @@
+/*
+ * 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.api.java.source.gen;
+
+import com.sun.source.tree.ClassTree;
+import com.sun.source.tree.CompilationUnitTree;
+import com.sun.source.tree.ExpressionTree;
+import java.io.File;
+import java.nio.file.Files;
+import java.util.Arrays;
+import javax.lang.model.element.TypeElement;
+import javax.tools.JavaCompiler;
+import javax.tools.StandardJavaFileManager;
+import javax.tools.ToolProvider;
+import org.netbeans.api.java.classpath.ClassPath;
+import org.netbeans.api.java.source.Task;
+import org.netbeans.api.java.source.JavaSource;
+import org.netbeans.api.java.source.JavaSource.Phase;
+import org.netbeans.api.java.source.TestUtilities;
+import org.netbeans.api.java.source.TreeMaker;
+import org.netbeans.api.java.source.WorkingCopy;
+import org.netbeans.junit.NbTestSuite;
+import org.netbeans.spi.java.classpath.ClassPathProvider;
+import org.netbeans.spi.java.classpath.support.ClassPathSupport;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
+import org.openide.util.test.MockLookup;
+
+/**
+ * Tests correct error types.
+ */
+public class ErrorTypeTest extends GeneratorTestMDRCompat {
+
+ public ErrorTypeTest(String name) {
+ super(name);
+ }
+
+ public static NbTestSuite suite() {
+ NbTestSuite suite = new NbTestSuite();
+ suite.addTestSuite(ErrorTypeTest.class);
+ return suite;
+ }
+
+ public void testType() throws Exception {
+ File libSrc = new File(getWorkDir(), "libsrc");
+ libSrc.mkdirs();
+ File lib = new File(libSrc, "Lib.java");
+ TestUtilities.copyStringToFile(lib,
+ "package lib;\n" +
+ "public class Lib extends Base {\n" +
+ "}\n" +
+ "class Base {\n" +
+ "}\n"
+ );
+ File libClass = new File(getWorkDir(), "libclass");
+ JavaCompiler javaCompiler = ToolProvider.getSystemJavaCompiler();
+
+ try (StandardJavaFileManager fm = javaCompiler.getStandardFileManager(null, null, null)) {
+ assertTrue(javaCompiler.getTask(null, fm, null, Arrays.asList("-d", libClass.getAbsolutePath(), "-source", "8"), null, fm.getJavaFileObjects(lib))
+ .call());
+ }
+
+ Files.delete(libClass.toPath().resolve("lib").resolve("Base.class"));
+ testFile = new File(getWorkDir(), "Test.java");
+ TestUtilities.copyStringToFile(testFile,
+ "package hierbas.del.litoral;\n\n" +
+ "public class Test {\n" +
+ "}\n");
+ String golden =
+ "package hierbas.del.litoral;\n\n" +
+ "import lib.Base;\n\n" +
+ "public class Test extends Base {\n" +
+ "}\n";
+ ClassPath compile = ClassPathSupport.createClassPath(libClass.toURI().toURL());
+
+ MockLookup.setInstances(new ClassPathProvider() {
+ @Override
+ public ClassPath findClassPath(FileObject file, String type) {
+ if (ClassPath.COMPILE.equals(type) && FileUtil.toFileObject(testFile).equals(file)) {
+ return compile;
+ }
+ return null;
+ }
+ });
+
+ JavaSource src = getJavaSource(testFile);
+ Task<WorkingCopy> task = (WorkingCopy workingCopy) -> {
+ workingCopy.toPhase(Phase.RESOLVED);
+ TypeElement type = workingCopy.getElements().getTypeElement("lib.Lib");
+ assertNotNull(type);
+ CompilationUnitTree cut = workingCopy.getCompilationUnit();
+ TreeMaker make = workingCopy.getTreeMaker();
+ ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0);
+ workingCopy.rewrite(clazz, make.setExtends(clazz, (ExpressionTree) make.Type(type.getSuperclass())));
+ };
+
+ src.runModificationTask(task).commit();
+ String res = TestUtilities.copyFileToString(testFile);
+ System.err.println(res);
+ assertEquals(golden, res);
+ }
+
+ String getGoldenPckg() {
+ return "";
+ }
+
+ String getSourcePckg() {
+ return "";
+ }
+
+
+}
---------------------------------------------------------------------
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