Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Arthanareeswaran2017-09-01 08:07:35 +0000
committerJay Arthanareeswaran2017-09-01 08:10:24 +0000
commit25bb6e890dbe71055532ee2d73683c38bd8850c4 (patch)
treee640578961bfcaa82bf395123e88f4cd9246312d /org.eclipse.jdt.compiler.apt.tests
parent2f44a37409803e53ebc21afd21032020feb9dbd7 (diff)
downloadeclipse.jdt.core-25bb6e890dbe71055532ee2d73683c38bd8850c4.tar.gz
eclipse.jdt.core-25bb6e890dbe71055532ee2d73683c38bd8850c4.tar.xz
eclipse.jdt.core-25bb6e890dbe71055532ee2d73683c38bd8850c4.zip
Bug 521723: [9] Binary method binding for an interface constructed with
wrong combination of modifiers Change-Id: I91de8e17d0dc28f7abd0297668f03f53ad61256e Signed-off-by: Jay Arthanareeswaran <jarthana@in.ibm.com>
Diffstat (limited to 'org.eclipse.jdt.compiler.apt.tests')
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jarbin211806 -> 215561 bytes
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/processors8/META-INF/services/javax.annotation.processing.Processor3
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java8ElementProcessor.java16
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java9ElementProcessor.java89
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/resources/targets/bug521723/Main.java13
-rw-r--r--org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/Java9ElementsTests.java99
6 files changed, 211 insertions, 9 deletions
diff --git a/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jar b/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jar
index e8edc6750a..7703de1ea1 100644
--- a/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jar
+++ b/org.eclipse.jdt.compiler.apt.tests/lib/apttestprocessors8.jar
Binary files differ
diff --git a/org.eclipse.jdt.compiler.apt.tests/processors8/META-INF/services/javax.annotation.processing.Processor b/org.eclipse.jdt.compiler.apt.tests/processors8/META-INF/services/javax.annotation.processing.Processor
index 5555121aae..839d9ea2ee 100644
--- a/org.eclipse.jdt.compiler.apt.tests/processors8/META-INF/services/javax.annotation.processing.Processor
+++ b/org.eclipse.jdt.compiler.apt.tests/processors8/META-INF/services/javax.annotation.processing.Processor
@@ -1 +1,2 @@
-org.eclipse.jdt.compiler.apt.tests.processors.elements.Java8ElementProcessor \ No newline at end of file
+org.eclipse.jdt.compiler.apt.tests.processors.elements.Java8ElementProcessor
+org.eclipse.jdt.compiler.apt.tests.processors.elements.Java9ElementProcessor \ No newline at end of file
diff --git a/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java8ElementProcessor.java b/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java8ElementProcessor.java
index abb0616d17..ae69eb9347 100644
--- a/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java8ElementProcessor.java
+++ b/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java8ElementProcessor.java
@@ -76,15 +76,15 @@ import org.eclipse.jdt.compiler.apt.tests.processors.base.BaseProcessor;
@SupportedSourceVersion(SourceVersion.RELEASE_8)
public class Java8ElementProcessor extends BaseProcessor {
- private static final String[] ELEMENT_NAMES = new String[] {"targets.model8.X", "T", "U", "K", "V", "KK", "VV", "KKK", "VVV"};
- private static final String[] TYPE_PARAM_ELEMENTS_Z1 = new String[] {"KK", "VV"};
- private static final String[] TYPE_PARAM_ELEMENTS_Z2 = new String[] {"KKK", "VVV"};
- String simpleName = "filer8";
- String packageName = "targets.filer8";
- int roundNo = 0;
- boolean reportSuccessAlready = true;
+ private static final String[] ELEMENT_NAMES = new String[] {"targets.model8.X", "T", "U", "K", "V", "KK", "VV", "KKK", "VVV"};
+ private static final String[] TYPE_PARAM_ELEMENTS_Z1 = new String[] {"KK", "VV"};
+ private static final String[] TYPE_PARAM_ELEMENTS_Z2 = new String[] {"KKK", "VVV"};
+ String simpleName = "filer8";
+ String packageName = "targets.filer8";
+ int roundNo = 0;
+ boolean reportSuccessAlready = true;
- RoundEnvironment roundEnv = null;
+ protected RoundEnvironment roundEnv = null;
// Always return false from this processor, because it supports "*".
// The return value does not signify success or failure!
@Override
diff --git a/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java9ElementProcessor.java b/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java9ElementProcessor.java
new file mode 100644
index 0000000000..6750b61f7f
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/processors8/org/eclipse/jdt/compiler/apt/tests/processors/elements/Java9ElementProcessor.java
@@ -0,0 +1,89 @@
+/*******************************************************************************
+ * Copyright (c) 2017 IBM Corporation.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.jdt.compiler.apt.tests.processors.elements;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import javax.annotation.processing.SupportedAnnotationTypes;
+import javax.annotation.processing.SupportedSourceVersion;
+import javax.lang.model.SourceVersion;
+import javax.lang.model.element.Element;
+import javax.lang.model.element.ExecutableElement;
+import javax.lang.model.element.Modifier;
+import javax.lang.model.element.TypeElement;
+
+@SupportedAnnotationTypes("*")
+@SupportedSourceVersion(SourceVersion.RELEASE_8) // Not at compliance 9 yet
+public class Java9ElementProcessor extends Java8ElementProcessor {
+
+ int roundNo = 0;
+ boolean reportSuccessAlready = true;
+
+ public void testBug521723() {
+ // private int foo1(int i) { return i; }
+ // default int foo2(int i) {return foo(i); }
+ // public default void foo3() {}
+ // static void foo4() {}
+ // private static void foo5() {}
+ // public static void foo6() {}
+ Modifier[] f1 = new Modifier[] {Modifier.PRIVATE};
+ Modifier[] f2 = new Modifier[] {Modifier.PUBLIC, Modifier.DEFAULT};
+ Modifier[] f3 = f2;
+ Modifier[] f4 = new Modifier[] {Modifier.STATIC, Modifier.PUBLIC};
+ Modifier[] f5 = new Modifier[] {Modifier.PRIVATE, Modifier.STATIC};
+ Modifier[] f6 = f4;
+ Set<? extends Element> rootElements = roundEnv.getRootElements();
+ TypeElement t = null;
+ for (Element element : rootElements) {
+ if (element instanceof TypeElement) {
+ if (((TypeElement) element).getQualifiedName().toString().equals("targets.bug521723.I")) {
+ t = (TypeElement) element;
+ }
+ }
+ }
+ assertNotNull("type should not be null", t);
+ List<? extends Element> enclosedElements = t.getEnclosedElements();
+ for (Element element : enclosedElements) {
+ if (element instanceof ExecutableElement) {
+ String string = element.getSimpleName().toString();
+ if (string.equals("foo1")) {
+ validateModifiers((ExecutableElement) element, f1);
+ } else if (string.equals("foo2")) {
+ validateModifiers((ExecutableElement) element, f2);
+ } else if (string.equals("foo3")) {
+ validateModifiers((ExecutableElement) element, f3);
+ } else if (string.equals("foo4")) {
+ validateModifiers((ExecutableElement) element, f4);
+ } else if (string.equals("foo5")) {
+ validateModifiers((ExecutableElement) element, f5);
+ } else if (string.equals("foo6")) {
+ validateModifiers((ExecutableElement) element, f6);
+ }
+ }
+ }
+
+ }
+ private void validateModifiers(ExecutableElement method, Modifier[] expected) {
+ Set<Modifier> modifiers = method.getModifiers();
+ List<Modifier> list = new ArrayList<>(modifiers);
+ for (Modifier modifier : expected) {
+ list.remove(modifier);
+ }
+ assertTrue("modifiers still present: " + list.toString(), list.isEmpty());
+ }
+}
diff --git a/org.eclipse.jdt.compiler.apt.tests/resources/targets/bug521723/Main.java b/org.eclipse.jdt.compiler.apt.tests/resources/targets/bug521723/Main.java
new file mode 100644
index 0000000000..c729b78786
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/resources/targets/bug521723/Main.java
@@ -0,0 +1,13 @@
+package targets.bug521723;
+
+public class Main {
+}
+
+interface I {
+ private int foo1(int i) { return i; }
+ default int foo2(int i) {return foo1(i); }
+ public default void foo3() {}
+ static void foo4() {}
+ private static void foo5() {}
+ public static void foo6() {}
+}
diff --git a/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/Java9ElementsTests.java b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/Java9ElementsTests.java
new file mode 100644
index 0000000000..d55a48a9ef
--- /dev/null
+++ b/org.eclipse.jdt.compiler.apt.tests/src/org/eclipse/jdt/compiler/apt/tests/Java9ElementsTests.java
@@ -0,0 +1,99 @@
+/*******************************************************************************
+ * Copyright (c) 2017 IBM Corporation.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * This is an implementation of an early-draft specification developed under the Java
+ * Community Process (JCP) and is made available for testing and evaluation purposes
+ * only. The code is not compatible with any specification of the JCP.
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.jdt.compiler.apt.tests;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.lang.model.SourceVersion;
+import javax.tools.JavaCompiler;
+import javax.tools.ToolProvider;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.eclipse.jdt.internal.compiler.tool.EclipseCompiler;
+
+public class Java9ElementsTests extends TestCase {
+
+ private static final String JAVA9_ANNOTATION_PROC = "org.eclipse.jdt.compiler.apt.tests.processors.elements.Java9ElementProcessor";
+
+ public static Test suite() {
+ return new TestSuite(Java9ElementsTests.class);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ BatchTestUtils.init();
+ }
+
+ public void testBug521723() throws IOException {
+ JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
+ internalTestWithBinary(compiler, JAVA9_ANNOTATION_PROC, "9", "testBug521723", null, "bug521723");
+ }
+ public void testBug521723Javac() throws IOException {
+ JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+ internalTestWithBinary(compiler, JAVA9_ANNOTATION_PROC, "9", "testBug521723", null, "bug521723");
+ }
+
+ protected void internalTestWithBinary(JavaCompiler compiler, String processor, String compliance, String testMethod, String testClass, String resourceArea) throws IOException {
+ if (!canRunJava9()) {
+ return;
+ }
+ System.clearProperty(processor);
+ File targetFolder = TestUtils.concatPath(BatchTestUtils.getSrcFolderName(), "targets", resourceArea);
+ if (testClass == null || testClass.equals("")) {
+ BatchTestUtils.copyResources("targets/" + resourceArea, targetFolder);
+ } else {
+ BatchTestUtils.copyResource("targets/" + resourceArea + "/" + testClass, targetFolder);
+ }
+
+
+ List<String> options = new ArrayList<String>();
+ options.add("-A" + processor);
+ options.add("-A" + testMethod);
+ options.add("-processor");
+ options.add(processor);
+ // Javac 1.8 doesn't (yet?) support the -1.8 option
+ if (compiler instanceof EclipseCompiler) {
+ options.add("-" + compliance);
+ } else {
+ options.add("-source");
+ options.add(compliance);
+ }
+ BatchTestUtils.compileTreeAndProcessBinaries(compiler, options, processor, targetFolder, null);
+
+ // If it succeeded, the processor will have set this property to "succeeded";
+ // if not, it will set it to an error value.
+ assertEquals("succeeded", System.getProperty(processor));
+ }
+ public boolean canRunJava9() {
+ try {
+ SourceVersion.valueOf("RELEASE_9");
+ } catch(IllegalArgumentException iae) {
+ return false;
+ }
+ return true;
+ }
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+}

Back to the top