Update jdt.core to a0e5f98b1c0224b51eff41180a89042104376c95 (03-05-16)
- with manual repair / refresh from orig
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/ComplianceDiagnoseTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/ComplianceDiagnoseTest.java
index 922f122..725dd03 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/ComplianceDiagnoseTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/ComplianceDiagnoseTest.java
@@ -3282,4 +3282,98 @@
expectedProblemLog
);
}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406846: [1.8] compiler NPE for method reference/lambda code compiled with < 1.8 compliance
+public void test406846() {
+
+ if (this.complianceLevel >= ClassFileConstants.JDK1_8) // tested in LET.
+ return;
+
+ String[] testFiles = new String[] {
+ "X.java",
+ "import java.util.*;\n" +
+ "public class X {\n" +
+ " public static <E> void printItem(E value, int index) {\n" +
+ " String output = String.format(\"%d -> %s\", index, value);\n" +
+ " System.out.println(output);\n" +
+ " }\n" +
+ " public static void main(String[] argv) {\n" +
+ " List<String> list = Arrays.asList(\"A\",\"B\",\"C\");\n" +
+ " eachWithIndex(list,X::printItem);\n" +
+ " }\n" +
+ " interface ItemWithIndexVisitor<E> {\n" +
+ " public void visit(E item, int index);\n" +
+ " }\n" +
+ " public static <E> void eachWithIndex(List<E> list, ItemWithIndexVisitor<E> visitor) {\n" +
+ " for (int i = 0; i < list.size(); i++) {\n" +
+ " visitor.visit(list.get(i), i);\n" +
+ " }\n" +
+ " }\n" +
+ "}\n",
+ };
+
+ String expectedProblemLog =
+ "----------\n" +
+ "1. ERROR in X.java (at line 9)\n" +
+ " eachWithIndex(list,X::printItem);\n" +
+ " ^^^^^^^^^^^^\n" +
+ "Method references are allowed only at source level 1.8 or above\n" +
+ "----------\n";
+ String expected1314ProblemLog =
+ "----------\n" +
+ "1. ERROR in X.java (at line 3)\n" +
+ " public static <E> void printItem(E value, int index) {\n" +
+ " ^\n" +
+ "Syntax error, type parameters are only available if source level is 1.5 or greater\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 4)\n" +
+ " String output = String.format(\"%d -> %s\", index, value);\n" +
+ " ^^^^^^\n" +
+ "The method format(String, Object[]) in the type String is not applicable for the arguments (String, int, E)\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 8)\n" +
+ " List<String> list = Arrays.asList(\"A\",\"B\",\"C\");\n" +
+ " ^^^^^^\n" +
+ "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" +
+ "----------\n" +
+ "4. ERROR in X.java (at line 8)\n" +
+ " List<String> list = Arrays.asList(\"A\",\"B\",\"C\");\n" +
+ " ^^^^^^\n" +
+ "The method asList(T[]) in the type Arrays is not applicable for the arguments (String, String, String)\n" +
+ "----------\n" +
+ "5. ERROR in X.java (at line 9)\n" +
+ " eachWithIndex(list,X::printItem);\n" +
+ " ^^^^^^^^^^^^\n" +
+ "Method references are allowed only at source level 1.8 or above\n" +
+ "----------\n" +
+ "6. ERROR in X.java (at line 11)\n" +
+ " interface ItemWithIndexVisitor<E> {\n" +
+ " ^\n" +
+ "Syntax error, type parameters are only available if source level is 1.5 or greater\n" +
+ "----------\n" +
+ "7. ERROR in X.java (at line 14)\n" +
+ " public static <E> void eachWithIndex(List<E> list, ItemWithIndexVisitor<E> visitor) {\n" +
+ " ^\n" +
+ "Syntax error, type parameters are only available if source level is 1.5 or greater\n" +
+ "----------\n" +
+ "8. ERROR in X.java (at line 14)\n" +
+ " public static <E> void eachWithIndex(List<E> list, ItemWithIndexVisitor<E> visitor) {\n" +
+ " ^\n" +
+ "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" +
+ "----------\n" +
+ "9. ERROR in X.java (at line 14)\n" +
+ " public static <E> void eachWithIndex(List<E> list, ItemWithIndexVisitor<E> visitor) {\n" +
+ " ^\n" +
+ "Syntax error, parameterized types are only available if source level is 1.5 or greater\n" +
+ "----------\n";
+
+ runComplianceParserTest(
+ testFiles,
+ expected1314ProblemLog,
+ expected1314ProblemLog,
+ expectedProblemLog,
+ expectedProblemLog,
+ expectedProblemLog,
+ expectedProblemLog
+ );
+}
}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/TestAll.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/TestAll.java
index 491d0ed..61516cf 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/TestAll.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/TestAll.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 IBM Corporation and others.
* 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
@@ -48,7 +48,7 @@
super(testName);
}
-public static Test suite() {
+public static TestSuite getTestSuite(boolean addComplianceDiagnoseTest) {
ArrayList testClasses = new ArrayList();
/* completion tests */
@@ -74,7 +74,8 @@
testClasses.add(SyntaxErrorTest.class);
testClasses.add(DualParseSyntaxErrorTest.class);
testClasses.add(ParserTest.class);
- testClasses.add(ComplianceDiagnoseTest.class);
+ if (addComplianceDiagnoseTest)
+ testClasses.add(ComplianceDiagnoseTest.class);
TestSuite all = new TestSuite(TestAll.class.getName());
int possibleComplianceLevels = AbstractCompilerTest.getPossibleComplianceLevels();
@@ -150,4 +151,7 @@
return all;
}
+public static Test suite() {
+ return getTestSuite(true);
+}
}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InterfaceMethodsTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InterfaceMethodsTest.java
index c9f04f9..5ec8f87 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InterfaceMethodsTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InterfaceMethodsTest.java
@@ -18,6 +18,7 @@
import java.util.Map;
import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
import junit.framework.Test;
@@ -1742,6 +1743,26 @@
"Cannot use super in a static context\n" +
"----------\n");
}
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=406619, [1.8][compiler] Incorrect suggestion that method can be made static.
+ public void test406619() {
+ Map compilerOptions = getCompilerOptions();
+ compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR);
+ compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR);
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "interface X {\n" +
+ " default int foo() {\n" +
+ " return 10;\n" +
+ " }\n" +
+ "}\n"
+ },
+ "",
+ null /* no extra class libraries */,
+ true /* flush output directory */,
+ compilerOptions /* custom options */
+ );
+ }
// class implements interface with default method.
// - synth. access needed for visibility reasons
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Jsr335ClassFileTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Jsr335ClassFileTest.java
new file mode 100644
index 0000000..98cfcde
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Jsr335ClassFileTest.java
@@ -0,0 +1,2526 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Jesper Steen Moller and others.
+ * 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:
+ * Jesper Steen Moller - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jdt.core.tests.compiler.regression;
+
+import java.io.File;
+import java.io.IOException;
+
+import junit.framework.Test;
+
+import org.eclipse.jdt.core.ToolFactory;
+import org.eclipse.jdt.core.tests.util.Util;
+import org.eclipse.jdt.core.util.ClassFileBytesDisassembler;
+import org.eclipse.jdt.core.util.ClassFormatException;
+
+public class Jsr335ClassFileTest extends AbstractComparableTest {
+
+public Jsr335ClassFileTest(String name) {
+ super(name);
+}
+
+/*
+ * Toggle compiler in mode -1.8
+ */
+// Static initializer to specify tests subset using TESTS_* static variables
+// All specified tests which do not belong to the class are skipped...
+static {
+// TESTS_NAMES = new String[] { "test055" };
+// TESTS_NUMBERS = new int[] { 50, 51, 52, 53 };
+// TESTS_RANGE = new int[] { 34, 38 };
+}
+public static Test suite() {
+ return buildMinimalComplianceTestSuite(testClass(), F_1_8);
+}
+private void verifyClassFile(String expectedOutput, String classFileName, int mode) throws IOException,
+ ClassFormatException {
+ File f = new File(OUTPUT_DIR + File.separator + classFileName);
+ byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f);
+ ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler();
+ String result = disassembler.disassemble(classFileBytes, "\n", mode);
+ int index = result.indexOf(expectedOutput);
+ if (index == -1 || expectedOutput.length() == 0) {
+ System.out.println(Util.displayString(result, 3));
+ }
+ if (index == -1) {
+ assertEquals("Wrong contents", expectedOutput, result);
+ }
+}
+public void test001() throws Exception {
+ this.runConformTest(
+ new String[] {
+ "Main.java",
+ "public class Main {\n" +
+ " public static void main(String[] args) {\n" +
+ " new X().referenceExpression.run();\n" +
+ " System.out.println(\"SUCCESS\");\n" +
+ " }\n" +
+ "}\n",
+ "X.java",
+ "public class X {\n" +
+ " public Runnable referenceExpression = Thread::yield;\n" +
+ "}\n",
+ },
+ "SUCCESS"
+ );
+
+ String expectedOutput =
+ "// Compiled from X.java (version 1.8 : 52.0, super bit)\n" +
+ "public class X {\n" +
+ " Constant pool:\n" +
+ " constant #1 class: #2 X\n" +
+ " constant #2 utf8: \"X\"\n" +
+ " constant #3 class: #4 java/lang/Object\n" +
+ " constant #4 utf8: \"java/lang/Object\"\n" +
+ " constant #5 utf8: \"referenceExpression\"\n" +
+ " constant #6 utf8: \"Ljava/lang/Runnable;\"\n" +
+ " constant #7 utf8: \"<init>\"\n" +
+ " constant #8 utf8: \"()V\"\n" +
+ " constant #9 utf8: \"Code\"\n" +
+ " constant #10 method_ref: #3.#11 java/lang/Object.<init> ()V\n" +
+ " constant #11 name_and_type: #7.#8 <init> ()V\n" +
+ " constant #12 name_and_type: #13.#14 lambda ()Ljava/lang/Runnable;\n" +
+ " constant #13 utf8: \"lambda\"\n" +
+ " constant #14 utf8: \"()Ljava/lang/Runnable;\"\n" +
+ " constant #15 invoke dynamic: #0 #12 lambda ()Ljava/lang/Runnable;\n" +
+ " constant #16 field_ref: #1.#17 X.referenceExpression Ljava/lang/Runnable;\n" +
+ " constant #17 name_and_type: #5.#6 referenceExpression Ljava/lang/Runnable;\n" +
+ " constant #18 utf8: \"LineNumberTable\"\n" +
+ " constant #19 utf8: \"LocalVariableTable\"\n" +
+ " constant #20 utf8: \"this\"\n" +
+ " constant #21 utf8: \"LX;\"\n" +
+ " constant #22 utf8: \"SourceFile\"\n" +
+ " constant #23 utf8: \"X.java\"\n" +
+ " constant #24 method_ref: #25.#27 java/lang/invoke/LambdaMetafactory.metaFactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" +
+ " constant #25 class: #26 java/lang/invoke/LambdaMetafactory\n" +
+ " constant #26 utf8: \"java/lang/invoke/LambdaMetafactory\"\n" +
+ " constant #27 name_and_type: #28.#29 metaFactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" +
+ " constant #28 utf8: \"metaFactory\"\n" +
+ " constant #29 utf8: \"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\"\n" +
+ " constant #30 method handle: invokestatic (6) #24 \n" +
+ " constant #31 utf8: \"BootstrapMethods\"\n" +
+ " constant #32 interface_method_ref: #33.#35 java/lang/Runnable.run ()V\n" +
+ " constant #33 class: #34 java/lang/Runnable\n" +
+ " constant #34 utf8: \"java/lang/Runnable\"\n" +
+ " constant #35 name_and_type: #36.#8 run ()V\n" +
+ " constant #36 utf8: \"run\"\n" +
+ " constant #37 method handle: invokeinterface (9) #32 \n" +
+ " constant #38 method_ref: #39.#41 java/lang/Thread.yield ()V\n" +
+ " constant #39 class: #40 java/lang/Thread\n" +
+ " constant #40 utf8: \"java/lang/Thread\"\n" +
+ " constant #41 name_and_type: #42.#8 yield ()V\n" +
+ " constant #42 utf8: \"yield\"\n" +
+ " constant #43 method handle: invokestatic (6) #38 \n" +
+ " constant #44 method type: #8 ()V\n" +
+ " constant #45 utf8: \"InnerClasses\"\n" +
+ " constant #46 class: #47 java/lang/invoke/MethodHandles$Lookup\n" +
+ " constant #47 utf8: \"java/lang/invoke/MethodHandles$Lookup\"\n" +
+ " constant #48 class: #49 java/lang/invoke/MethodHandles\n" +
+ " constant #49 utf8: \"java/lang/invoke/MethodHandles\"\n" +
+ " constant #50 utf8: \"Lookup\"\n" +
+ " \n" +
+ " // Field descriptor #6 Ljava/lang/Runnable;\n" +
+ " public java.lang.Runnable referenceExpression;\n" +
+ " \n" +
+ " // Method descriptor #8 ()V\n" +
+ " // Stack: 2, Locals: 1\n" +
+ " public X();\n" +
+ " 0 aload_0 [this]\n" +
+ " 1 invokespecial java.lang.Object() [10]\n" +
+ " 4 aload_0 [this]\n" +
+ " 5 invokedynamic 0 lambda() : java.lang.Runnable [15]\n" +
+ " 10 putfield X.referenceExpression : java.lang.Runnable [16]\n" +
+ " 13 return\n" +
+ " Line numbers:\n" +
+ " [pc: 0, line: 1]\n" +
+ " [pc: 4, line: 2]\n" +
+ " [pc: 13, line: 1]\n" +
+ " Local variable table:\n" +
+ " [pc: 0, pc: 14] local: this index: 0 type: X\n" +
+ "\n" +
+ " Inner classes:\n" +
+ " [inner class info: #46 java/lang/invoke/MethodHandles$Lookup, outer class info: #48 java/lang/invoke/MethodHandles\n" +
+ " inner name: #50 Lookup, accessflags: 25 public static final]\n" +
+ "Bootstrap methods:\n" +
+ " 0 : # 30 arguments: {#37,#43,#44}\n" +
+ "}";
+
+ verifyClassFile(expectedOutput, "X.class", ClassFileBytesDisassembler.SYSTEM);
+}
+public void test002() throws Exception {
+ this.runConformTest(
+ new String[] {
+ "Main.java",
+ "public class Main {\n" +
+ " public static void main(String[] args) {\n" +
+ " new X().referenceExpression.consume(\"SUCCESS\");\n" +
+ " }\n" +
+ " public static void printIt(Object o) {\n" +
+ " System.out.println(o.toString());\n" +
+ " }\n" +
+ "}\n",
+ "X.java",
+ "public class X {\n" +
+ " public ObjectConsumer referenceExpression = Main::printIt;\n" +
+ "}\n",
+ "ObjectConsumer.java",
+ "public interface ObjectConsumer {\n" +
+ " void consume(Object obj);\n" +
+ "}\n",
+ },
+ "SUCCESS"
+ );
+
+ String expectedOutput =
+ "// Compiled from X.java (version 1.8 : 52.0, super bit)\n" +
+ "public class X {\n" +
+ " Constant pool:\n" +
+ " constant #1 class: #2 X\n" +
+ " constant #2 utf8: \"X\"\n" +
+ " constant #3 class: #4 java/lang/Object\n" +
+ " constant #4 utf8: \"java/lang/Object\"\n" +
+ " constant #5 utf8: \"referenceExpression\"\n" +
+ " constant #6 utf8: \"LObjectConsumer;\"\n" +
+ " constant #7 utf8: \"<init>\"\n" +
+ " constant #8 utf8: \"()V\"\n" +
+ " constant #9 utf8: \"Code\"\n" +
+ " constant #10 method_ref: #3.#11 java/lang/Object.<init> ()V\n" +
+ " constant #11 name_and_type: #7.#8 <init> ()V\n" +
+ " constant #12 name_and_type: #13.#14 lambda ()LObjectConsumer;\n" +
+ " constant #13 utf8: \"lambda\"\n" +
+ " constant #14 utf8: \"()LObjectConsumer;\"\n" +
+ " constant #15 invoke dynamic: #0 #12 lambda ()LObjectConsumer;\n" +
+ " constant #16 field_ref: #1.#17 X.referenceExpression LObjectConsumer;\n" +
+ " constant #17 name_and_type: #5.#6 referenceExpression LObjectConsumer;\n" +
+ " constant #18 utf8: \"LineNumberTable\"\n" +
+ " constant #19 utf8: \"LocalVariableTable\"\n" +
+ " constant #20 utf8: \"this\"\n" +
+ " constant #21 utf8: \"LX;\"\n" +
+ " constant #22 utf8: \"SourceFile\"\n" +
+ " constant #23 utf8: \"X.java\"\n" +
+ " constant #24 method_ref: #25.#27 java/lang/invoke/LambdaMetafactory.metaFactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" +
+ " constant #25 class: #26 java/lang/invoke/LambdaMetafactory\n" +
+ " constant #26 utf8: \"java/lang/invoke/LambdaMetafactory\"\n" +
+ " constant #27 name_and_type: #28.#29 metaFactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" +
+ " constant #28 utf8: \"metaFactory\"\n" +
+ " constant #29 utf8: \"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\"\n" +
+ " constant #30 method handle: invokestatic (6) #24 \n" +
+ " constant #31 utf8: \"BootstrapMethods\"\n" +
+ " constant #32 interface_method_ref: #33.#35 ObjectConsumer.consume (Ljava/lang/Object;)V\n" +
+ " constant #33 class: #34 ObjectConsumer\n" +
+ " constant #34 utf8: \"ObjectConsumer\"\n" +
+ " constant #35 name_and_type: #36.#37 consume (Ljava/lang/Object;)V\n" +
+ " constant #36 utf8: \"consume\"\n" +
+ " constant #37 utf8: \"(Ljava/lang/Object;)V\"\n" +
+ " constant #38 method handle: invokeinterface (9) #32 \n" +
+ " constant #39 method_ref: #40.#42 Main.printIt (Ljava/lang/Object;)V\n" +
+ " constant #40 class: #41 Main\n" +
+ " constant #41 utf8: \"Main\"\n" +
+ " constant #42 name_and_type: #43.#37 printIt (Ljava/lang/Object;)V\n" +
+ " constant #43 utf8: \"printIt\"\n" +
+ " constant #44 method handle: invokestatic (6) #39 \n" +
+ " constant #45 method type: #37 (Ljava/lang/Object;)V\n" +
+ " constant #46 utf8: \"InnerClasses\"\n" +
+ " constant #47 class: #48 java/lang/invoke/MethodHandles$Lookup\n" +
+ " constant #48 utf8: \"java/lang/invoke/MethodHandles$Lookup\"\n" +
+ " constant #49 class: #50 java/lang/invoke/MethodHandles\n" +
+ " constant #50 utf8: \"java/lang/invoke/MethodHandles\"\n" +
+ " constant #51 utf8: \"Lookup\"\n" +
+ " \n" +
+ " // Field descriptor #6 LObjectConsumer;\n" +
+ " public ObjectConsumer referenceExpression;\n" +
+ " \n" +
+ " // Method descriptor #8 ()V\n" +
+ " // Stack: 2, Locals: 1\n" +
+ " public X();\n" +
+ " 0 aload_0 [this]\n" +
+ " 1 invokespecial java.lang.Object() [10]\n" +
+ " 4 aload_0 [this]\n" +
+ " 5 invokedynamic 0 lambda() : ObjectConsumer [15]\n" +
+ " 10 putfield X.referenceExpression : ObjectConsumer [16]\n" +
+ " 13 return\n" +
+ " Line numbers:\n" +
+ " [pc: 0, line: 1]\n" +
+ " [pc: 4, line: 2]\n" +
+ " [pc: 13, line: 1]\n" +
+ " Local variable table:\n" +
+ " [pc: 0, pc: 14] local: this index: 0 type: X\n" +
+ "\n" +
+ " Inner classes:\n" +
+ " [inner class info: #47 java/lang/invoke/MethodHandles$Lookup, outer class info: #49 java/lang/invoke/MethodHandles\n" +
+ " inner name: #51 Lookup, accessflags: 25 public static final]\n" +
+ "Bootstrap methods:\n" +
+ " 0 : # 30 arguments: {#38,#44,#45}\n" +
+ "}";
+
+ verifyClassFile(expectedOutput, "X.class", ClassFileBytesDisassembler.SYSTEM);
+}
+public void test003() throws Exception {
+ this.runConformTest(
+ new String[] {
+ "Main.java",
+ "public class Main {\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(new X().referenceExpression.makeString(new Main()));\n" +
+ " }\n" +
+ " @Override\n" +
+ " public String toString() {\n" +
+ " return \"SUCCESS\";\n" +
+ " }\n" +
+ "}\n",
+ "X.java",
+ "public class X {\n" +
+ " public ObjectToString referenceExpression = Object::toString;\n" +
+ "}\n",
+ "ObjectToString.java",
+ "public interface ObjectToString {\n" +
+ " String makeString(Object obj);\n" +
+ "}\n",
+ },
+ "SUCCESS"
+ );
+
+ String expectedOutput =
+ "// Compiled from X.java (version 1.8 : 52.0, super bit)\n" +
+ "public class X {\n" +
+ " Constant pool:\n" +
+ " constant #1 class: #2 X\n" +
+ " constant #2 utf8: \"X\"\n" +
+ " constant #3 class: #4 java/lang/Object\n" +
+ " constant #4 utf8: \"java/lang/Object\"\n" +
+ " constant #5 utf8: \"referenceExpression\"\n" +
+ " constant #6 utf8: \"LObjectToString;\"\n" +
+ " constant #7 utf8: \"<init>\"\n" +
+ " constant #8 utf8: \"()V\"\n" +
+ " constant #9 utf8: \"Code\"\n" +
+ " constant #10 method_ref: #3.#11 java/lang/Object.<init> ()V\n" +
+ " constant #11 name_and_type: #7.#8 <init> ()V\n" +
+ " constant #12 name_and_type: #13.#14 lambda ()LObjectToString;\n" +
+ " constant #13 utf8: \"lambda\"\n" +
+ " constant #14 utf8: \"()LObjectToString;\"\n" +
+ " constant #15 invoke dynamic: #0 #12 lambda ()LObjectToString;\n" +
+ " constant #16 field_ref: #1.#17 X.referenceExpression LObjectToString;\n" +
+ " constant #17 name_and_type: #5.#6 referenceExpression LObjectToString;\n" +
+ " constant #18 utf8: \"LineNumberTable\"\n" +
+ " constant #19 utf8: \"LocalVariableTable\"\n" +
+ " constant #20 utf8: \"this\"\n" +
+ " constant #21 utf8: \"LX;\"\n" +
+ " constant #22 utf8: \"SourceFile\"\n" +
+ " constant #23 utf8: \"X.java\"\n" +
+ " constant #24 method_ref: #25.#27 java/lang/invoke/LambdaMetafactory.metaFactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" +
+ " constant #25 class: #26 java/lang/invoke/LambdaMetafactory\n" +
+ " constant #26 utf8: \"java/lang/invoke/LambdaMetafactory\"\n" +
+ " constant #27 name_and_type: #28.#29 metaFactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" +
+ " constant #28 utf8: \"metaFactory\"\n" +
+ " constant #29 utf8: \"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\"\n" +
+ " constant #30 method handle: invokestatic (6) #24 \n" +
+ " constant #31 utf8: \"BootstrapMethods\"\n" +
+ " constant #32 interface_method_ref: #33.#35 ObjectToString.makeString (Ljava/lang/Object;)Ljava/lang/String;\n" +
+ " constant #33 class: #34 ObjectToString\n" +
+ " constant #34 utf8: \"ObjectToString\"\n" +
+ " constant #35 name_and_type: #36.#37 makeString (Ljava/lang/Object;)Ljava/lang/String;\n" +
+ " constant #36 utf8: \"makeString\"\n" +
+ " constant #37 utf8: \"(Ljava/lang/Object;)Ljava/lang/String;\"\n" +
+ " constant #38 method handle: invokeinterface (9) #32 \n" +
+ " constant #39 method_ref: #3.#40 java/lang/Object.toString ()Ljava/lang/String;\n" +
+ " constant #40 name_and_type: #41.#42 toString ()Ljava/lang/String;\n" +
+ " constant #41 utf8: \"toString\"\n" +
+ " constant #42 utf8: \"()Ljava/lang/String;\"\n" +
+ " constant #43 method handle: invokevirtual (5) #39 \n" +
+ " constant #44 method type: #37 (Ljava/lang/Object;)Ljava/lang/String;\n" +
+ " constant #45 utf8: \"InnerClasses\"\n" +
+ " constant #46 class: #47 java/lang/invoke/MethodHandles$Lookup\n" +
+ " constant #47 utf8: \"java/lang/invoke/MethodHandles$Lookup\"\n" +
+ " constant #48 class: #49 java/lang/invoke/MethodHandles\n" +
+ " constant #49 utf8: \"java/lang/invoke/MethodHandles\"\n" +
+ " constant #50 utf8: \"Lookup\"\n" +
+ " \n" +
+ " // Field descriptor #6 LObjectToString;\n" +
+ " public ObjectToString referenceExpression;\n" +
+ " \n" +
+ " // Method descriptor #8 ()V\n" +
+ " // Stack: 2, Locals: 1\n" +
+ " public X();\n" +
+ " 0 aload_0 [this]\n" +
+ " 1 invokespecial java.lang.Object() [10]\n" +
+ " 4 aload_0 [this]\n" +
+ " 5 invokedynamic 0 lambda() : ObjectToString [15]\n" +
+ " 10 putfield X.referenceExpression : ObjectToString [16]\n" +
+ " 13 return\n" +
+ " Line numbers:\n" +
+ " [pc: 0, line: 1]\n" +
+ " [pc: 4, line: 2]\n" +
+ " [pc: 13, line: 1]\n" +
+ " Local variable table:\n" +
+ " [pc: 0, pc: 14] local: this index: 0 type: X\n" +
+ "\n" +
+ " Inner classes:\n" +
+ " [inner class info: #46 java/lang/invoke/MethodHandles$Lookup, outer class info: #48 java/lang/invoke/MethodHandles\n" +
+ " inner name: #50 Lookup, accessflags: 25 public static final]\n" +
+ "Bootstrap methods:\n" +
+ " 0 : # 30 arguments: {#38,#43,#44}\n" +
+ "}";
+
+ verifyClassFile(expectedOutput, "X.class", ClassFileBytesDisassembler.SYSTEM);
+}
+public void test004() throws Exception {
+ this.runConformTest(
+ new String[] {
+ "Main.java",
+ "public class Main {\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(new X().referenceExpression.produce());\n" +
+ " }\n" +
+ "}\n",
+ "X.java",
+ "public class X {\n" +
+ " String s = \"SUCCESS\";\n"+
+ " public StringProducer referenceExpression = s::toString;\n" +
+ "}\n",
+ "StringProducer.java",
+ "public interface StringProducer {\n" +
+ " String produce();\n" +
+ "}\n",
+ },
+ "SUCCESS"
+ );
+
+ String expectedOutput =
+ "// Compiled from X.java (version 1.8 : 52.0, super bit)\n" +
+ "public class X {\n" +
+ " Constant pool:\n" +
+ " constant #1 class: #2 X\n" +
+ " constant #2 utf8: \"X\"\n" +
+ " constant #3 class: #4 java/lang/Object\n" +
+ " constant #4 utf8: \"java/lang/Object\"\n" +
+ " constant #5 utf8: \"s\"\n" +
+ " constant #6 utf8: \"Ljava/lang/String;\"\n" +
+ " constant #7 utf8: \"referenceExpression\"\n" +
+ " constant #8 utf8: \"LStringProducer;\"\n" +
+ " constant #9 utf8: \"<init>\"\n" +
+ " constant #10 utf8: \"()V\"\n" +
+ " constant #11 utf8: \"Code\"\n" +
+ " constant #12 method_ref: #3.#13 java/lang/Object.<init> ()V\n" +
+ " constant #13 name_and_type: #9.#10 <init> ()V\n" +
+ " constant #14 string: #15 \"SUCCESS\"\n" +
+ " constant #15 utf8: \"SUCCESS\"\n" +
+ " constant #16 field_ref: #1.#17 X.s Ljava/lang/String;\n" +
+ " constant #17 name_and_type: #5.#6 s Ljava/lang/String;\n" +
+ " constant #18 name_and_type: #19.#20 lambda (Ljava/lang/String;)LStringProducer;\n" +
+ " constant #19 utf8: \"lambda\"\n" +
+ " constant #20 utf8: \"(Ljava/lang/String;)LStringProducer;\"\n" +
+ " constant #21 invoke dynamic: #0 #18 lambda (Ljava/lang/String;)LStringProducer;\n" +
+ " constant #22 field_ref: #1.#23 X.referenceExpression LStringProducer;\n" +
+ " constant #23 name_and_type: #7.#8 referenceExpression LStringProducer;\n" +
+ " constant #24 utf8: \"LineNumberTable\"\n" +
+ " constant #25 utf8: \"LocalVariableTable\"\n" +
+ " constant #26 utf8: \"this\"\n" +
+ " constant #27 utf8: \"LX;\"\n" +
+ " constant #28 utf8: \"SourceFile\"\n" +
+ " constant #29 utf8: \"X.java\"\n" +
+ " constant #30 method_ref: #31.#33 java/lang/invoke/LambdaMetafactory.metaFactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" +
+ " constant #31 class: #32 java/lang/invoke/LambdaMetafactory\n" +
+ " constant #32 utf8: \"java/lang/invoke/LambdaMetafactory\"\n" +
+ " constant #33 name_and_type: #34.#35 metaFactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" +
+ " constant #34 utf8: \"metaFactory\"\n" +
+ " constant #35 utf8: \"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\"\n" +
+ " constant #36 method handle: invokestatic (6) #30 \n" +
+ " constant #37 utf8: \"BootstrapMethods\"\n" +
+ " constant #38 interface_method_ref: #39.#41 StringProducer.produce ()Ljava/lang/String;\n" +
+ " constant #39 class: #40 StringProducer\n" +
+ " constant #40 utf8: \"StringProducer\"\n" +
+ " constant #41 name_and_type: #42.#43 produce ()Ljava/lang/String;\n" +
+ " constant #42 utf8: \"produce\"\n" +
+ " constant #43 utf8: \"()Ljava/lang/String;\"\n" +
+ " constant #44 method handle: invokeinterface (9) #38 \n" +
+ " constant #45 method_ref: #46.#48 java/lang/String.toString ()Ljava/lang/String;\n" +
+ " constant #46 class: #47 java/lang/String\n" +
+ " constant #47 utf8: \"java/lang/String\"\n" +
+ " constant #48 name_and_type: #49.#43 toString ()Ljava/lang/String;\n" +
+ " constant #49 utf8: \"toString\"\n" +
+ " constant #50 method handle: invokevirtual (5) #45 \n" +
+ " constant #51 method type: #43 ()Ljava/lang/String;\n" +
+ " constant #52 utf8: \"InnerClasses\"\n" +
+ " constant #53 class: #54 java/lang/invoke/MethodHandles$Lookup\n" +
+ " constant #54 utf8: \"java/lang/invoke/MethodHandles$Lookup\"\n" +
+ " constant #55 class: #56 java/lang/invoke/MethodHandles\n" +
+ " constant #56 utf8: \"java/lang/invoke/MethodHandles\"\n" +
+ " constant #57 utf8: \"Lookup\"\n" +
+ " \n" +
+ " // Field descriptor #6 Ljava/lang/String;\n" +
+ " java.lang.String s;\n" +
+ " \n" +
+ " // Field descriptor #8 LStringProducer;\n" +
+ " public StringProducer referenceExpression;\n" +
+ " \n" +
+ " // Method descriptor #10 ()V\n" +
+ " // Stack: 2, Locals: 1\n" +
+ " public X();\n" +
+ " 0 aload_0 [this]\n" +
+ " 1 invokespecial java.lang.Object() [12]\n" +
+ " 4 aload_0 [this]\n" +
+ " 5 ldc <String \"SUCCESS\"> [14]\n" +
+ " 7 putfield X.s : java.lang.String [16]\n" +
+ " 10 aload_0 [this]\n" +
+ " 11 aload_0 [this]\n" +
+ " 12 getfield X.s : java.lang.String [16]\n" +
+ " 15 invokedynamic 0 lambda(java.lang.String) : StringProducer [21]\n" +
+ " 20 putfield X.referenceExpression : StringProducer [22]\n" +
+ " 23 return\n" +
+ " Line numbers:\n" +
+ " [pc: 0, line: 1]\n" +
+ " [pc: 4, line: 2]\n" +
+ " [pc: 10, line: 3]\n" +
+ " [pc: 23, line: 1]\n" +
+ " Local variable table:\n" +
+ " [pc: 0, pc: 24] local: this index: 0 type: X\n" +
+ "\n" +
+ " Inner classes:\n" +
+ " [inner class info: #53 java/lang/invoke/MethodHandles$Lookup, outer class info: #55 java/lang/invoke/MethodHandles\n" +
+ " inner name: #57 Lookup, accessflags: 25 public static final]\n" +
+ "Bootstrap methods:\n" +
+ " 0 : # 36 arguments: {#44,#50,#51}\n" +
+ "}";
+
+ verifyClassFile(expectedOutput, "X.class", ClassFileBytesDisassembler.SYSTEM);
+}
+public void test005() throws Exception {
+ this.runConformTest(
+ new String[] {
+ "Main.java",
+ "public class Main {\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(X.allocatorExpression.produce());\n" +
+ " }\n" +
+ " @Override\n" +
+ " public String toString() {\n" +
+ " return \"SUCCESS\";" +
+ " }\n" +
+ "}\n",
+ "X.java",
+ "public class X {\n" +
+ " public static MainProducer allocatorExpression = Main::new;\n" +
+ "}\n",
+ "MainProducer.java",
+ "public interface MainProducer {\n" +
+ " Main produce();\n" +
+ "}\n",
+ },
+ "SUCCESS"
+ );
+ verifyClassFile("// Compiled from X.java (version 1.8 : 52.0, super bit)\n" +
+ "public class X {\n" +
+ " Constant pool:\n" +
+ " constant #1 class: #2 X\n" +
+ " constant #2 utf8: \"X\"\n" +
+ " constant #3 class: #4 java/lang/Object\n" +
+ " constant #4 utf8: \"java/lang/Object\"\n" +
+ " constant #5 utf8: \"allocatorExpression\"\n" +
+ " constant #6 utf8: \"LMainProducer;\"\n" +
+ " constant #7 utf8: \"<clinit>\"\n" +
+ " constant #8 utf8: \"()V\"\n" +
+ " constant #9 utf8: \"Code\"\n" +
+ " constant #10 name_and_type: #11.#12 lambda ()LMainProducer;\n" +
+ " constant #11 utf8: \"lambda\"\n" +
+ " constant #12 utf8: \"()LMainProducer;\"\n" +
+ " constant #13 invoke dynamic: #0 #10 lambda ()LMainProducer;\n" +
+ " constant #14 field_ref: #1.#15 X.allocatorExpression LMainProducer;\n" +
+ " constant #15 name_and_type: #5.#6 allocatorExpression LMainProducer;\n" +
+ " constant #16 utf8: \"LineNumberTable\"\n" +
+ " constant #17 utf8: \"LocalVariableTable\"\n" +
+ " constant #18 utf8: \"<init>\"\n" +
+ " constant #19 method_ref: #3.#20 java/lang/Object.<init> ()V\n" +
+ " constant #20 name_and_type: #18.#8 <init> ()V\n" +
+ " constant #21 utf8: \"this\"\n" +
+ " constant #22 utf8: \"LX;\"\n" +
+ " constant #23 utf8: \"SourceFile\"\n" +
+ " constant #24 utf8: \"X.java\"\n" +
+ " constant #25 method_ref: #26.#28 java/lang/invoke/LambdaMetafactory.metaFactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" +
+ " constant #26 class: #27 java/lang/invoke/LambdaMetafactory\n" +
+ " constant #27 utf8: \"java/lang/invoke/LambdaMetafactory\"\n" +
+ " constant #28 name_and_type: #29.#30 metaFactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" +
+ " constant #29 utf8: \"metaFactory\"\n" +
+ " constant #30 utf8: \"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\"\n" +
+ " constant #31 method handle: invokestatic (6) #25 \n" +
+ " constant #32 utf8: \"BootstrapMethods\"\n" +
+ " constant #33 interface_method_ref: #34.#36 MainProducer.produce ()LMain;\n" +
+ " constant #34 class: #35 MainProducer\n" +
+ " constant #35 utf8: \"MainProducer\"\n" +
+ " constant #36 name_and_type: #37.#38 produce ()LMain;\n" +
+ " constant #37 utf8: \"produce\"\n" +
+ " constant #38 utf8: \"()LMain;\"\n" +
+ " constant #39 method handle: invokeinterface (9) #33 \n" +
+ " constant #40 method_ref: #41.#20 Main.<init> ()V\n" +
+ " constant #41 class: #42 Main\n" +
+ " constant #42 utf8: \"Main\"\n" +
+ " constant #43 method handle: newinvokespecial (8) #40 \n" +
+ " constant #44 method type: #38 ()LMain;\n" +
+ " constant #45 utf8: \"InnerClasses\"\n" +
+ " constant #46 class: #47 java/lang/invoke/MethodHandles$Lookup\n" +
+ " constant #47 utf8: \"java/lang/invoke/MethodHandles$Lookup\"\n" +
+ " constant #48 class: #49 java/lang/invoke/MethodHandles\n" +
+ " constant #49 utf8: \"java/lang/invoke/MethodHandles\"\n" +
+ " constant #50 utf8: \"Lookup\"\n" +
+ " \n" +
+ " // Field descriptor #6 LMainProducer;\n" +
+ " public static MainProducer allocatorExpression;\n" +
+ " \n" +
+ " // Method descriptor #8 ()V\n" +
+ " // Stack: 1, Locals: 0\n" +
+ " static {};\n" +
+ " 0 invokedynamic 0 lambda() : MainProducer [13]\n" +
+ " 5 putstatic X.allocatorExpression : MainProducer [14]\n" +
+ " 8 return\n" +
+ " Line numbers:\n" +
+ " [pc: 0, line: 2]\n" +
+ " \n" +
+ " // Method descriptor #8 ()V\n" +
+ " // Stack: 1, Locals: 1\n" +
+ " public X();\n" +
+ " 0 aload_0 [this]\n" +
+ " 1 invokespecial java.lang.Object() [19]\n" +
+ " 4 return\n" +
+ " Line numbers:\n" +
+ " [pc: 0, line: 1]\n" +
+ " Local variable table:\n" +
+ " [pc: 0, pc: 5] local: this index: 0 type: X\n" +
+ "\n" +
+ " Inner classes:\n" +
+ " [inner class info: #46 java/lang/invoke/MethodHandles$Lookup, outer class info: #48 java/lang/invoke/MethodHandles\n" +
+ " inner name: #50 Lookup, accessflags: 25 public static final]\n" +
+ "Bootstrap methods:\n" +
+ " 0 : # 31 arguments: {#39,#43,#44}\n" +
+ "}", "X.class", ClassFileBytesDisassembler.SYSTEM);
+}
+public void test006() throws Exception {
+ this.runConformTest(
+ new String[] {
+ "Main.java",
+ "public class Main {\n" +
+ " String s1, s2;\n" +
+ " public Main(String val1, String val2) {" +
+ " s1 = val1;\n" +
+ " s2 = val2;\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " Main m = X.producer.apply(\"SUCC\", \"ESS\");\n" +
+ " System.out.println(m);\n" +
+ " }\n" +
+ " public String toString() {\n" +
+ " return s1 + s2;" +
+ " }\n" +
+ "}\n",
+ "X.java",
+ "public class X {\n" +
+ " public static Function2<Main, String, String> producer = Main::new;\n" +
+ "}\n",
+ "Function2.java",
+ "public interface Function2<R, T1, T2> {\n" +
+ " R apply(T1 a1, T2 a2);\n" +
+ "}\n",
+ },
+ "SUCCESS"
+ );
+ String expected = "// Compiled from X.java (version 1.8 : 52.0, super bit)\n" +
+ "public class X {\n" +
+ " Constant pool:\n" +
+ " constant #1 class: #2 X\n" +
+ " constant #2 utf8: \"X\"\n" +
+ " constant #3 class: #4 java/lang/Object\n" +
+ " constant #4 utf8: \"java/lang/Object\"\n" +
+ " constant #5 utf8: \"producer\"\n" +
+ " constant #6 utf8: \"LFunction2;\"\n" +
+ " constant #7 utf8: \"Signature\"\n" +
+ " constant #8 utf8: \"LFunction2<LMain;Ljava/lang/String;Ljava/lang/String;>;\"\n" +
+ " constant #9 utf8: \"<clinit>\"\n" +
+ " constant #10 utf8: \"()V\"\n" +
+ " constant #11 utf8: \"Code\"\n" +
+ " constant #12 name_and_type: #13.#14 lambda ()LFunction2;\n" +
+ " constant #13 utf8: \"lambda\"\n" +
+ " constant #14 utf8: \"()LFunction2;\"\n" +
+ " constant #15 invoke dynamic: #0 #12 lambda ()LFunction2;\n" +
+ " constant #16 field_ref: #1.#17 X.producer LFunction2;\n" +
+ " constant #17 name_and_type: #5.#6 producer LFunction2;\n" +
+ " constant #18 utf8: \"LineNumberTable\"\n" +
+ " constant #19 utf8: \"LocalVariableTable\"\n" +
+ " constant #20 utf8: \"<init>\"\n" +
+ " constant #21 method_ref: #3.#22 java/lang/Object.<init> ()V\n" +
+ " constant #22 name_and_type: #20.#10 <init> ()V\n" +
+ " constant #23 utf8: \"this\"\n" +
+ " constant #24 utf8: \"LX;\"\n" +
+ " constant #25 utf8: \"SourceFile\"\n" +
+ " constant #26 utf8: \"X.java\"\n" +
+ " constant #27 method_ref: #28.#30 java/lang/invoke/LambdaMetafactory.metaFactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" +
+ " constant #28 class: #29 java/lang/invoke/LambdaMetafactory\n" +
+ " constant #29 utf8: \"java/lang/invoke/LambdaMetafactory\"\n" +
+ " constant #30 name_and_type: #31.#32 metaFactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" +
+ " constant #31 utf8: \"metaFactory\"\n" +
+ " constant #32 utf8: \"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\"\n" +
+ " constant #33 method handle: invokestatic (6) #27 \n" +
+ " constant #34 utf8: \"BootstrapMethods\"\n" +
+ " constant #35 interface_method_ref: #36.#38 Function2.apply (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;\n" +
+ " constant #36 class: #37 Function2\n" +
+ " constant #37 utf8: \"Function2\"\n" +
+ " constant #38 name_and_type: #39.#40 apply (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;\n" +
+ " constant #39 utf8: \"apply\"\n" +
+ " constant #40 utf8: \"(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;\"\n" +
+ " constant #41 method handle: invokeinterface (9) #35 \n" +
+ " constant #42 method_ref: #43.#45 Main.<init> (Ljava/lang/String;Ljava/lang/String;)V\n" +
+ " constant #43 class: #44 Main\n" +
+ " constant #44 utf8: \"Main\"\n" +
+ " constant #45 name_and_type: #20.#46 <init> (Ljava/lang/String;Ljava/lang/String;)V\n" +
+ " constant #46 utf8: \"(Ljava/lang/String;Ljava/lang/String;)V\"\n" +
+ " constant #47 method handle: newinvokespecial (8) #42 \n" +
+ " constant #48 utf8: \"(Ljava/lang/String;Ljava/lang/String;)LMain;\"\n" +
+ " constant #49 method type: #48 (Ljava/lang/String;Ljava/lang/String;)LMain;\n" +
+ " constant #50 utf8: \"InnerClasses\"\n" +
+ " constant #51 class: #52 java/lang/invoke/MethodHandles$Lookup\n" +
+ " constant #52 utf8: \"java/lang/invoke/MethodHandles$Lookup\"\n" +
+ " constant #53 class: #54 java/lang/invoke/MethodHandles\n" +
+ " constant #54 utf8: \"java/lang/invoke/MethodHandles\"\n" +
+ " constant #55 utf8: \"Lookup\"\n" +
+ " \n" +
+ " // Field descriptor #6 LFunction2;\n" +
+ " // Signature: LFunction2<LMain;Ljava/lang/String;Ljava/lang/String;>;\n" +
+ " public static Function2 producer;\n" +
+ " \n" +
+ " // Method descriptor #10 ()V\n" +
+ " // Stack: 1, Locals: 0\n" +
+ " static {};\n" +
+ " 0 invokedynamic 0 lambda() : Function2 [15]\n" +
+ " 5 putstatic X.producer : Function2 [16]\n" +
+ " 8 return\n" +
+ " Line numbers:\n" +
+ " [pc: 0, line: 2]\n" +
+ " \n" +
+ " // Method descriptor #10 ()V\n" +
+ " // Stack: 1, Locals: 1\n" +
+ " public X();\n" +
+ " 0 aload_0 [this]\n" +
+ " 1 invokespecial java.lang.Object() [21]\n" +
+ " 4 return\n" +
+ " Line numbers:\n" +
+ " [pc: 0, line: 1]\n" +
+ " Local variable table:\n" +
+ " [pc: 0, pc: 5] local: this index: 0 type: X\n" +
+ "\n" +
+ " Inner classes:\n" +
+ " [inner class info: #51 java/lang/invoke/MethodHandles$Lookup, outer class info: #53 java/lang/invoke/MethodHandles\n" +
+ " inner name: #55 Lookup, accessflags: 25 public static final]\n" +
+ "Bootstrap methods:\n" +
+ " 0 : # 33 arguments: {#41,#47,#49}\n" +
+ "}";
+ verifyClassFile(expected, "X.class", ClassFileBytesDisassembler.SYSTEM);
+}
+public void test007() throws Exception {
+ this.runConformTest(
+ new String[] {
+ "Main.java",
+ "public class Main {\n" +
+ " public static void main(String[] args) {\n" +
+ " new X().referenceExpression.run();\n" +
+ " }\n" +
+ "}\n",
+ "X.java",
+ "public class X {\n" +
+ " public Runnable referenceExpression = () -> {" +
+ " System.out.println(\"SUCCESS\");\n" +
+ " };\n" +
+ "}\n",
+ },
+ "SUCCESS"
+ );
+
+ String expectedOutput =
+ "// Compiled from X.java (version 1.8 : 52.0, super bit)\n" +
+ "public class X {\n" +
+ " Constant pool:\n" +
+ " constant #1 class: #2 X\n" +
+ " constant #2 utf8: \"X\"\n" +
+ " constant #3 class: #4 java/lang/Object\n" +
+ " constant #4 utf8: \"java/lang/Object\"\n" +
+ " constant #5 utf8: \"referenceExpression\"\n" +
+ " constant #6 utf8: \"Ljava/lang/Runnable;\"\n" +
+ " constant #7 utf8: \"<init>\"\n" +
+ " constant #8 utf8: \"()V\"\n" +
+ " constant #9 utf8: \"Code\"\n" +
+ " constant #10 method_ref: #3.#11 java/lang/Object.<init> ()V\n" +
+ " constant #11 name_and_type: #7.#8 <init> ()V\n" +
+ " constant #12 name_and_type: #13.#14 lambda$ ()Ljava/lang/Runnable;\n" +
+ " constant #13 utf8: \"lambda$\"\n" +
+ " constant #14 utf8: \"()Ljava/lang/Runnable;\"\n" +
+ " constant #15 invoke dynamic: #0 #12 lambda$ ()Ljava/lang/Runnable;\n" +
+ " constant #16 field_ref: #1.#17 X.referenceExpression Ljava/lang/Runnable;\n" +
+ " constant #17 name_and_type: #5.#6 referenceExpression Ljava/lang/Runnable;\n" +
+ " constant #18 utf8: \"LineNumberTable\"\n" +
+ " constant #19 utf8: \"LocalVariableTable\"\n" +
+ " constant #20 utf8: \"this\"\n" +
+ " constant #21 utf8: \"LX;\"\n" +
+ " constant #22 utf8: \"lambda$0\"\n" +
+ " constant #23 field_ref: #24.#26 java/lang/System.out Ljava/io/PrintStream;\n" +
+ " constant #24 class: #25 java/lang/System\n" +
+ " constant #25 utf8: \"java/lang/System\"\n" +
+ " constant #26 name_and_type: #27.#28 out Ljava/io/PrintStream;\n" +
+ " constant #27 utf8: \"out\"\n" +
+ " constant #28 utf8: \"Ljava/io/PrintStream;\"\n" +
+ " constant #29 string: #30 \"SUCCESS\"\n" +
+ " constant #30 utf8: \"SUCCESS\"\n" +
+ " constant #31 method_ref: #32.#34 java/io/PrintStream.println (Ljava/lang/String;)V\n" +
+ " constant #32 class: #33 java/io/PrintStream\n" +
+ " constant #33 utf8: \"java/io/PrintStream\"\n" +
+ " constant #34 name_and_type: #35.#36 println (Ljava/lang/String;)V\n" +
+ " constant #35 utf8: \"println\"\n" +
+ " constant #36 utf8: \"(Ljava/lang/String;)V\"\n" +
+ " constant #37 utf8: \"SourceFile\"\n" +
+ " constant #38 utf8: \"X.java\"\n" +
+ " constant #39 method_ref: #40.#42 java/lang/invoke/LambdaMetafactory.metaFactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" +
+ " constant #40 class: #41 java/lang/invoke/LambdaMetafactory\n" +
+ " constant #41 utf8: \"java/lang/invoke/LambdaMetafactory\"\n" +
+ " constant #42 name_and_type: #43.#44 metaFactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" +
+ " constant #43 utf8: \"metaFactory\"\n" +
+ " constant #44 utf8: \"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\"\n" +
+ " constant #45 method handle: invokestatic (6) #39 \n" +
+ " constant #46 utf8: \"BootstrapMethods\"\n" +
+ " constant #47 interface_method_ref: #48.#50 java/lang/Runnable.run ()V\n" +
+ " constant #48 class: #49 java/lang/Runnable\n" +
+ " constant #49 utf8: \"java/lang/Runnable\"\n" +
+ " constant #50 name_and_type: #51.#8 run ()V\n" +
+ " constant #51 utf8: \"run\"\n" +
+ " constant #52 method handle: invokeinterface (9) #47 \n" +
+ " constant #53 method_ref: #1.#54 X.lambda$0 ()V\n" +
+ " constant #54 name_and_type: #22.#8 lambda$0 ()V\n" +
+ " constant #55 method handle: invokestatic (6) #53 \n" +
+ " constant #56 method type: #8 ()V\n" +
+ " constant #57 utf8: \"InnerClasses\"\n" +
+ " constant #58 class: #59 java/lang/invoke/MethodHandles$Lookup\n" +
+ " constant #59 utf8: \"java/lang/invoke/MethodHandles$Lookup\"\n" +
+ " constant #60 class: #61 java/lang/invoke/MethodHandles\n" +
+ " constant #61 utf8: \"java/lang/invoke/MethodHandles\"\n" +
+ " constant #62 utf8: \"Lookup\"\n" +
+ " \n" +
+ " // Field descriptor #6 Ljava/lang/Runnable;\n" +
+ " public java.lang.Runnable referenceExpression;\n" +
+ " \n" +
+ " // Method descriptor #8 ()V\n" +
+ " // Stack: 2, Locals: 1\n" +
+ " public X();\n" +
+ " 0 aload_0 [this]\n" +
+ " 1 invokespecial java.lang.Object() [10]\n" +
+ " 4 aload_0 [this]\n" +
+ " 5 invokedynamic 0 lambda$() : java.lang.Runnable [15]\n" +
+ " 10 putfield X.referenceExpression : java.lang.Runnable [16]\n" +
+ " 13 return\n" +
+ " Line numbers:\n" +
+ " [pc: 0, line: 1]\n" +
+ " [pc: 4, line: 2]\n" +
+ " [pc: 13, line: 1]\n" +
+ " Local variable table:\n" +
+ " [pc: 0, pc: 14] local: this index: 0 type: X\n" +
+ " \n" +
+ " // Method descriptor #8 ()V\n" +
+ " // Stack: 2, Locals: 0\n" +
+ " private static synthetic void lambda$0();\n" +
+ " 0 getstatic java.lang.System.out : java.io.PrintStream [23]\n" +
+ " 3 ldc <String \"SUCCESS\"> [29]\n" +
+ " 5 invokevirtual java.io.PrintStream.println(java.lang.String) : void [31]\n" +
+ " 8 return\n" +
+ " Line numbers:\n" +
+ " [pc: 0, line: 2]\n" +
+ " [pc: 8, line: 3]\n" +
+ "\n" +
+ " Inner classes:\n" +
+ " [inner class info: #58 java/lang/invoke/MethodHandles$Lookup, outer class info: #60 java/lang/invoke/MethodHandles\n" +
+ " inner name: #62 Lookup, accessflags: 25 public static final]\n" +
+ "Bootstrap methods:\n" +
+ " 0 : # 45 arguments: {#52,#55,#56}\n" +
+ "}";
+
+ verifyClassFile(expectedOutput, "X.class", ClassFileBytesDisassembler.SYSTEM);
+}
+public void test007a() throws Exception {
+ this.runConformTest(
+ new String[] {
+ "Main.java",
+ "public class Main {\n" +
+ " public static void main(String[] args) {\n" +
+ " new X().referenceExpression.run();\n" +
+ " }\n" +
+ "}\n",
+ "X.java",
+ "public class X {\n" +
+ " public Runnable referenceExpression = () -> System.out.println(\"SUCCESS\");\n" +
+ "}\n",
+ },
+ "SUCCESS"
+ );
+
+ String expectedOutput =
+ "// Compiled from X.java (version 1.8 : 52.0, super bit)\n" +
+ "public class X {\n" +
+ " Constant pool:\n" +
+ " constant #1 class: #2 X\n" +
+ " constant #2 utf8: \"X\"\n" +
+ " constant #3 class: #4 java/lang/Object\n" +
+ " constant #4 utf8: \"java/lang/Object\"\n" +
+ " constant #5 utf8: \"referenceExpression\"\n" +
+ " constant #6 utf8: \"Ljava/lang/Runnable;\"\n" +
+ " constant #7 utf8: \"<init>\"\n" +
+ " constant #8 utf8: \"()V\"\n" +
+ " constant #9 utf8: \"Code\"\n" +
+ " constant #10 method_ref: #3.#11 java/lang/Object.<init> ()V\n" +
+ " constant #11 name_and_type: #7.#8 <init> ()V\n" +
+ " constant #12 name_and_type: #13.#14 lambda$ ()Ljava/lang/Runnable;\n" +
+ " constant #13 utf8: \"lambda$\"\n" +
+ " constant #14 utf8: \"()Ljava/lang/Runnable;\"\n" +
+ " constant #15 invoke dynamic: #0 #12 lambda$ ()Ljava/lang/Runnable;\n" +
+ " constant #16 field_ref: #1.#17 X.referenceExpression Ljava/lang/Runnable;\n" +
+ " constant #17 name_and_type: #5.#6 referenceExpression Ljava/lang/Runnable;\n" +
+ " constant #18 utf8: \"LineNumberTable\"\n" +
+ " constant #19 utf8: \"LocalVariableTable\"\n" +
+ " constant #20 utf8: \"this\"\n" +
+ " constant #21 utf8: \"LX;\"\n" +
+ " constant #22 utf8: \"lambda$0\"\n" +
+ " constant #23 field_ref: #24.#26 java/lang/System.out Ljava/io/PrintStream;\n" +
+ " constant #24 class: #25 java/lang/System\n" +
+ " constant #25 utf8: \"java/lang/System\"\n" +
+ " constant #26 name_and_type: #27.#28 out Ljava/io/PrintStream;\n" +
+ " constant #27 utf8: \"out\"\n" +
+ " constant #28 utf8: \"Ljava/io/PrintStream;\"\n" +
+ " constant #29 string: #30 \"SUCCESS\"\n" +
+ " constant #30 utf8: \"SUCCESS\"\n" +
+ " constant #31 method_ref: #32.#34 java/io/PrintStream.println (Ljava/lang/String;)V\n" +
+ " constant #32 class: #33 java/io/PrintStream\n" +
+ " constant #33 utf8: \"java/io/PrintStream\"\n" +
+ " constant #34 name_and_type: #35.#36 println (Ljava/lang/String;)V\n" +
+ " constant #35 utf8: \"println\"\n" +
+ " constant #36 utf8: \"(Ljava/lang/String;)V\"\n" +
+ " constant #37 utf8: \"SourceFile\"\n" +
+ " constant #38 utf8: \"X.java\"\n" +
+ " constant #39 method_ref: #40.#42 java/lang/invoke/LambdaMetafactory.metaFactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" +
+ " constant #40 class: #41 java/lang/invoke/LambdaMetafactory\n" +
+ " constant #41 utf8: \"java/lang/invoke/LambdaMetafactory\"\n" +
+ " constant #42 name_and_type: #43.#44 metaFactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" +
+ " constant #43 utf8: \"metaFactory\"\n" +
+ " constant #44 utf8: \"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\"\n" +
+ " constant #45 method handle: invokestatic (6) #39 \n" +
+ " constant #46 utf8: \"BootstrapMethods\"\n" +
+ " constant #47 interface_method_ref: #48.#50 java/lang/Runnable.run ()V\n" +
+ " constant #48 class: #49 java/lang/Runnable\n" +
+ " constant #49 utf8: \"java/lang/Runnable\"\n" +
+ " constant #50 name_and_type: #51.#8 run ()V\n" +
+ " constant #51 utf8: \"run\"\n" +
+ " constant #52 method handle: invokeinterface (9) #47 \n" +
+ " constant #53 method_ref: #1.#54 X.lambda$0 ()V\n" +
+ " constant #54 name_and_type: #22.#8 lambda$0 ()V\n" +
+ " constant #55 method handle: invokestatic (6) #53 \n" +
+ " constant #56 method type: #8 ()V\n" +
+ " constant #57 utf8: \"InnerClasses\"\n" +
+ " constant #58 class: #59 java/lang/invoke/MethodHandles$Lookup\n" +
+ " constant #59 utf8: \"java/lang/invoke/MethodHandles$Lookup\"\n" +
+ " constant #60 class: #61 java/lang/invoke/MethodHandles\n" +
+ " constant #61 utf8: \"java/lang/invoke/MethodHandles\"\n" +
+ " constant #62 utf8: \"Lookup\"\n" +
+ " \n" +
+ " // Field descriptor #6 Ljava/lang/Runnable;\n" +
+ " public java.lang.Runnable referenceExpression;\n" +
+ " \n" +
+ " // Method descriptor #8 ()V\n" +
+ " // Stack: 2, Locals: 1\n" +
+ " public X();\n" +
+ " 0 aload_0 [this]\n" +
+ " 1 invokespecial java.lang.Object() [10]\n" +
+ " 4 aload_0 [this]\n" +
+ " 5 invokedynamic 0 lambda$() : java.lang.Runnable [15]\n" +
+ " 10 putfield X.referenceExpression : java.lang.Runnable [16]\n" +
+ " 13 return\n" +
+ " Line numbers:\n" +
+ " [pc: 0, line: 1]\n" +
+ " [pc: 4, line: 2]\n" +
+ " [pc: 13, line: 1]\n" +
+ " Local variable table:\n" +
+ " [pc: 0, pc: 14] local: this index: 0 type: X\n" +
+ " \n" +
+ " // Method descriptor #8 ()V\n" +
+ " // Stack: 2, Locals: 0\n" +
+ " private static synthetic void lambda$0();\n" +
+ " 0 getstatic java.lang.System.out : java.io.PrintStream [23]\n" +
+ " 3 ldc <String \"SUCCESS\"> [29]\n" +
+ " 5 invokevirtual java.io.PrintStream.println(java.lang.String) : void [31]\n" +
+ " 8 return\n" +
+ " Line numbers:\n" +
+ " [pc: 0, line: 2]\n" +
+ "\n" +
+ " Inner classes:\n" +
+ " [inner class info: #58 java/lang/invoke/MethodHandles$Lookup, outer class info: #60 java/lang/invoke/MethodHandles\n" +
+ " inner name: #62 Lookup, accessflags: 25 public static final]\n" +
+ "Bootstrap methods:\n" +
+ " 0 : # 45 arguments: {#52,#55,#56}\n" +
+ "}";
+
+ verifyClassFile(expectedOutput, "X.class", ClassFileBytesDisassembler.SYSTEM);
+}
+public void test008() throws Exception {
+ this.runConformTest(
+ new String[] {
+ "Main.java",
+ "public class Main {\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(new X().lambda.get());\n" +
+ " }\n" +
+ "}\n",
+ "X.java",
+ "public class X {\n" +
+ " public java.util.function.Supplier<String> lambda = () -> { return \"SUCCESS\"; }; \n" +
+ "}\n",
+ },
+ "SUCCESS"
+ );
+
+ String expectedOutput =
+ "// Compiled from X.java (version 1.8 : 52.0, super bit)\n" +
+ "public class X {\n" +
+ " Constant pool:\n" +
+ " constant #1 class: #2 X\n" +
+ " constant #2 utf8: \"X\"\n" +
+ " constant #3 class: #4 java/lang/Object\n" +
+ " constant #4 utf8: \"java/lang/Object\"\n" +
+ " constant #5 utf8: \"lambda\"\n" +
+ " constant #6 utf8: \"Ljava/util/function/Supplier;\"\n" +
+ " constant #7 utf8: \"Signature\"\n" +
+ " constant #8 utf8: \"Ljava/util/function/Supplier<Ljava/lang/String;>;\"\n" +
+ " constant #9 utf8: \"<init>\"\n" +
+ " constant #10 utf8: \"()V\"\n" +
+ " constant #11 utf8: \"Code\"\n" +
+ " constant #12 method_ref: #3.#13 java/lang/Object.<init> ()V\n" +
+ " constant #13 name_and_type: #9.#10 <init> ()V\n" +
+ " constant #14 name_and_type: #15.#16 lambda$ ()Ljava/util/function/Supplier;\n" +
+ " constant #15 utf8: \"lambda$\"\n" +
+ " constant #16 utf8: \"()Ljava/util/function/Supplier;\"\n" +
+ " constant #17 invoke dynamic: #0 #14 lambda$ ()Ljava/util/function/Supplier;\n" +
+ " constant #18 field_ref: #1.#19 X.lambda Ljava/util/function/Supplier;\n" +
+ " constant #19 name_and_type: #5.#6 lambda Ljava/util/function/Supplier;\n" +
+ " constant #20 utf8: \"LineNumberTable\"\n" +
+ " constant #21 utf8: \"LocalVariableTable\"\n" +
+ " constant #22 utf8: \"this\"\n" +
+ " constant #23 utf8: \"LX;\"\n" +
+ " constant #24 utf8: \"lambda$0\"\n" +
+ " constant #25 utf8: \"()Ljava/lang/String;\"\n" +
+ " constant #26 string: #27 \"SUCCESS\"\n" +
+ " constant #27 utf8: \"SUCCESS\"\n" +
+ " constant #28 utf8: \"SourceFile\"\n" +
+ " constant #29 utf8: \"X.java\"\n" +
+ " constant #30 method_ref: #31.#33 java/lang/invoke/LambdaMetafactory.metaFactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" +
+ " constant #31 class: #32 java/lang/invoke/LambdaMetafactory\n" +
+ " constant #32 utf8: \"java/lang/invoke/LambdaMetafactory\"\n" +
+ " constant #33 name_and_type: #34.#35 metaFactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" +
+ " constant #34 utf8: \"metaFactory\"\n" +
+ " constant #35 utf8: \"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\"\n" +
+ " constant #36 method handle: invokestatic (6) #30 \n" +
+ " constant #37 utf8: \"BootstrapMethods\"\n" +
+ " constant #38 interface_method_ref: #39.#41 java/util/function/Supplier.get ()Ljava/lang/Object;\n" +
+ " constant #39 class: #40 java/util/function/Supplier\n" +
+ " constant #40 utf8: \"java/util/function/Supplier\"\n" +
+ " constant #41 name_and_type: #42.#43 get ()Ljava/lang/Object;\n" +
+ " constant #42 utf8: \"get\"\n" +
+ " constant #43 utf8: \"()Ljava/lang/Object;\"\n" +
+ " constant #44 method handle: invokeinterface (9) #38 \n" +
+ " constant #45 method_ref: #1.#46 X.lambda$0 ()Ljava/lang/String;\n" +
+ " constant #46 name_and_type: #24.#25 lambda$0 ()Ljava/lang/String;\n" +
+ " constant #47 method handle: invokestatic (6) #45 \n" +
+ " constant #48 method type: #25 ()Ljava/lang/String;\n" +
+ " constant #49 utf8: \"InnerClasses\"\n" +
+ " constant #50 class: #51 java/lang/invoke/MethodHandles$Lookup\n" +
+ " constant #51 utf8: \"java/lang/invoke/MethodHandles$Lookup\"\n" +
+ " constant #52 class: #53 java/lang/invoke/MethodHandles\n" +
+ " constant #53 utf8: \"java/lang/invoke/MethodHandles\"\n" +
+ " constant #54 utf8: \"Lookup\"\n" +
+ " \n" +
+ " // Field descriptor #6 Ljava/util/function/Supplier;\n" +
+ " // Signature: Ljava/util/function/Supplier<Ljava/lang/String;>;\n" +
+ " public java.util.function.Supplier lambda;\n" +
+ " \n" +
+ " // Method descriptor #10 ()V\n" +
+ " // Stack: 2, Locals: 1\n" +
+ " public X();\n" +
+ " 0 aload_0 [this]\n" +
+ " 1 invokespecial java.lang.Object() [12]\n" +
+ " 4 aload_0 [this]\n" +
+ " 5 invokedynamic 0 lambda$() : java.util.function.Supplier [17]\n" +
+ " 10 putfield X.lambda : java.util.function.Supplier [18]\n" +
+ " 13 return\n" +
+ " Line numbers:\n" +
+ " [pc: 0, line: 1]\n" +
+ " [pc: 4, line: 2]\n" +
+ " [pc: 13, line: 1]\n" +
+ " Local variable table:\n" +
+ " [pc: 0, pc: 14] local: this index: 0 type: X\n" +
+ " \n" +
+ " // Method descriptor #25 ()Ljava/lang/String;\n" +
+ " // Stack: 1, Locals: 0\n" +
+ " private static synthetic java.lang.String lambda$0();\n" +
+ " 0 ldc <String \"SUCCESS\"> [26]\n" +
+ " 2 areturn\n" +
+ " Line numbers:\n" +
+ " [pc: 0, line: 2]\n" +
+ "\n" +
+ " Inner classes:\n" +
+ " [inner class info: #50 java/lang/invoke/MethodHandles$Lookup, outer class info: #52 java/lang/invoke/MethodHandles\n" +
+ " inner name: #54 Lookup, accessflags: 25 public static final]\n" +
+ "Bootstrap methods:\n" +
+ " 0 : # 36 arguments: {#44,#47,#48}\n" +
+ "}";
+
+ verifyClassFile(expectedOutput, "X.class", ClassFileBytesDisassembler.SYSTEM);
+}
+public void test009() throws Exception {
+ this.runConformTest(
+ new String[] {
+ "Main.java",
+ "public class Main {\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(new X().concat.apply(\"SUCC\",\"ESS\"));\n" +
+ " }\n" +
+ "}\n",
+ "X.java",
+ "public class X {\n" +
+ " public Function2<String, String, String> concat = (s1, s2) -> { return s1 + s2; }; \n" +
+ "}\n",
+ "Function2.java",
+ "public interface Function2<R, T1, T2> {\n" +
+ " R apply(T1 a1, T2 a2);\n" +
+ "}\n",
+
+ },
+ "SUCCESS"
+ );
+
+ String expectedOutput =
+ "// Compiled from X.java (version 1.8 : 52.0, super bit)\n" +
+ "public class X {\n" +
+ " Constant pool:\n" +
+ " constant #1 class: #2 X\n" +
+ " constant #2 utf8: \"X\"\n" +
+ " constant #3 class: #4 java/lang/Object\n" +
+ " constant #4 utf8: \"java/lang/Object\"\n" +
+ " constant #5 utf8: \"concat\"\n" +
+ " constant #6 utf8: \"LFunction2;\"\n" +
+ " constant #7 utf8: \"Signature\"\n" +
+ " constant #8 utf8: \"LFunction2<Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;>;\"\n" +
+ " constant #9 utf8: \"<init>\"\n" +
+ " constant #10 utf8: \"()V\"\n" +
+ " constant #11 utf8: \"Code\"\n" +
+ " constant #12 method_ref: #3.#13 java/lang/Object.<init> ()V\n" +
+ " constant #13 name_and_type: #9.#10 <init> ()V\n" +
+ " constant #14 name_and_type: #15.#16 lambda$ ()LFunction2;\n" +
+ " constant #15 utf8: \"lambda$\"\n" +
+ " constant #16 utf8: \"()LFunction2;\"\n" +
+ " constant #17 invoke dynamic: #0 #14 lambda$ ()LFunction2;\n" +
+ " constant #18 field_ref: #1.#19 X.concat LFunction2;\n" +
+ " constant #19 name_and_type: #5.#6 concat LFunction2;\n" +
+ " constant #20 utf8: \"LineNumberTable\"\n" +
+ " constant #21 utf8: \"LocalVariableTable\"\n" +
+ " constant #22 utf8: \"this\"\n" +
+ " constant #23 utf8: \"LX;\"\n" +
+ " constant #24 utf8: \"lambda$0\"\n" +
+ " constant #25 utf8: \"(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;\"\n" +
+ " constant #26 class: #27 java/lang/StringBuilder\n" +
+ " constant #27 utf8: \"java/lang/StringBuilder\"\n" +
+ " constant #28 method_ref: #29.#31 java/lang/String.valueOf (Ljava/lang/Object;)Ljava/lang/String;\n" +
+ " constant #29 class: #30 java/lang/String\n" +
+ " constant #30 utf8: \"java/lang/String\"\n" +
+ " constant #31 name_and_type: #32.#33 valueOf (Ljava/lang/Object;)Ljava/lang/String;\n" +
+ " constant #32 utf8: \"valueOf\"\n" +
+ " constant #33 utf8: \"(Ljava/lang/Object;)Ljava/lang/String;\"\n" +
+ " constant #34 method_ref: #26.#35 java/lang/StringBuilder.<init> (Ljava/lang/String;)V\n" +
+ " constant #35 name_and_type: #9.#36 <init> (Ljava/lang/String;)V\n" +
+ " constant #36 utf8: \"(Ljava/lang/String;)V\"\n" +
+ " constant #37 method_ref: #26.#38 java/lang/StringBuilder.append (Ljava/lang/String;)Ljava/lang/StringBuilder;\n" +
+ " constant #38 name_and_type: #39.#40 append (Ljava/lang/String;)Ljava/lang/StringBuilder;\n" +
+ " constant #39 utf8: \"append\"\n" +
+ " constant #40 utf8: \"(Ljava/lang/String;)Ljava/lang/StringBuilder;\"\n" +
+ " constant #41 method_ref: #26.#42 java/lang/StringBuilder.toString ()Ljava/lang/String;\n" +
+ " constant #42 name_and_type: #43.#44 toString ()Ljava/lang/String;\n" +
+ " constant #43 utf8: \"toString\"\n" +
+ " constant #44 utf8: \"()Ljava/lang/String;\"\n" +
+ " constant #45 utf8: \"s1\"\n" +
+ " constant #46 utf8: \"Ljava/lang/String;\"\n" +
+ " constant #47 utf8: \"s2\"\n" +
+ " constant #48 utf8: \"SourceFile\"\n" +
+ " constant #49 utf8: \"X.java\"\n" +
+ " constant #50 method_ref: #51.#53 java/lang/invoke/LambdaMetafactory.metaFactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" +
+ " constant #51 class: #52 java/lang/invoke/LambdaMetafactory\n" +
+ " constant #52 utf8: \"java/lang/invoke/LambdaMetafactory\"\n" +
+ " constant #53 name_and_type: #54.#55 metaFactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" +
+ " constant #54 utf8: \"metaFactory\"\n" +
+ " constant #55 utf8: \"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\"\n" +
+ " constant #56 method handle: invokestatic (6) #50 \n" +
+ " constant #57 utf8: \"BootstrapMethods\"\n" +
+ " constant #58 interface_method_ref: #59.#61 Function2.apply (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;\n" +
+ " constant #59 class: #60 Function2\n" +
+ " constant #60 utf8: \"Function2\"\n" +
+ " constant #61 name_and_type: #62.#63 apply (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;\n" +
+ " constant #62 utf8: \"apply\"\n" +
+ " constant #63 utf8: \"(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;\"\n" +
+ " constant #64 method handle: invokeinterface (9) #58 \n" +
+ " constant #65 method_ref: #1.#66 X.lambda$0 (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;\n" +
+ " constant #66 name_and_type: #24.#25 lambda$0 (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;\n" +
+ " constant #67 method handle: invokestatic (6) #65 \n" +
+ " constant #68 method type: #25 (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;\n" +
+ " constant #69 utf8: \"InnerClasses\"\n" +
+ " constant #70 class: #71 java/lang/invoke/MethodHandles$Lookup\n" +
+ " constant #71 utf8: \"java/lang/invoke/MethodHandles$Lookup\"\n" +
+ " constant #72 class: #73 java/lang/invoke/MethodHandles\n" +
+ " constant #73 utf8: \"java/lang/invoke/MethodHandles\"\n" +
+ " constant #74 utf8: \"Lookup\"\n" +
+ " \n" +
+ " // Field descriptor #6 LFunction2;\n" +
+ " // Signature: LFunction2<Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;>;\n" +
+ " public Function2 concat;\n" +
+ " \n" +
+ " // Method descriptor #10 ()V\n" +
+ " // Stack: 2, Locals: 1\n" +
+ " public X();\n" +
+ " 0 aload_0 [this]\n" +
+ " 1 invokespecial java.lang.Object() [12]\n" +
+ " 4 aload_0 [this]\n" +
+ " 5 invokedynamic 0 lambda$() : Function2 [17]\n" +
+ " 10 putfield X.concat : Function2 [18]\n" +
+ " 13 return\n" +
+ " Line numbers:\n" +
+ " [pc: 0, line: 1]\n" +
+ " [pc: 4, line: 2]\n" +
+ " [pc: 13, line: 1]\n" +
+ " Local variable table:\n" +
+ " [pc: 0, pc: 14] local: this index: 0 type: X\n" +
+ " \n" +
+ " // Method descriptor #25 (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;\n" +
+ " // Stack: 3, Locals: 2\n" +
+ " private static synthetic java.lang.String lambda$0(java.lang.String s1, java.lang.String s2);\n" +
+ " 0 new java.lang.StringBuilder [26]\n" +
+ " 3 dup\n" +
+ " 4 aload_0 [s1]\n" +
+ " 5 invokestatic java.lang.String.valueOf(java.lang.Object) : java.lang.String [28]\n" +
+ " 8 invokespecial java.lang.StringBuilder(java.lang.String) [34]\n" +
+ " 11 aload_1 [s2]\n" +
+ " 12 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [37]\n" +
+ " 15 invokevirtual java.lang.StringBuilder.toString() : java.lang.String [41]\n" +
+ " 18 areturn\n" +
+ " Line numbers:\n" +
+ " [pc: 0, line: 2]\n" +
+ " Local variable table:\n" +
+ " [pc: 0, pc: 19] local: s1 index: 0 type: java.lang.String\n" +
+ " [pc: 0, pc: 19] local: s2 index: 1 type: java.lang.String\n" +
+ "\n" +
+ " Inner classes:\n" +
+ " [inner class info: #70 java/lang/invoke/MethodHandles$Lookup, outer class info: #72 java/lang/invoke/MethodHandles\n" +
+ " inner name: #74 Lookup, accessflags: 25 public static final]\n" +
+ "Bootstrap methods:\n" +
+ " 0 : # 56 arguments: {#64,#67,#68}\n" +
+ "}";
+
+ verifyClassFile(expectedOutput, "X.class", ClassFileBytesDisassembler.SYSTEM);
+}
+public void test010() throws Exception {
+ this.runConformTest(
+ new String[] {
+ "Main.java",
+ "public class Main {\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(new X().concat.apply(\"UCC\",\"ESS\"));\n" +
+ " }\n" +
+ "}\n",
+ "X.java",
+ "public class X {\n" +
+ " public Function2<String, String, String> concat; \n" +
+ " {\n" +
+ " String s0 = new String(\"S\");\n" +
+ " concat = (s1, s2) -> { return s0 + s1 + s2; }; \n" +
+ " }\n" +
+ "}\n",
+ "Function2.java",
+ "public interface Function2<R, T1, T2> {\n" +
+ " R apply(T1 a1, T2 a2);\n" +
+ "}\n",
+
+ },
+ "SUCCESS"
+ );
+
+ String expectedOutput =
+ "// Compiled from X.java (version 1.8 : 52.0, super bit)\n" +
+ "public class X {\n" +
+ " Constant pool:\n" +
+ " constant #1 class: #2 X\n" +
+ " constant #2 utf8: \"X\"\n" +
+ " constant #3 class: #4 java/lang/Object\n" +
+ " constant #4 utf8: \"java/lang/Object\"\n" +
+ " constant #5 utf8: \"concat\"\n" +
+ " constant #6 utf8: \"LFunction2;\"\n" +
+ " constant #7 utf8: \"Signature\"\n" +
+ " constant #8 utf8: \"LFunction2<Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;>;\"\n" +
+ " constant #9 utf8: \"<init>\"\n" +
+ " constant #10 utf8: \"()V\"\n" +
+ " constant #11 utf8: \"Code\"\n" +
+ " constant #12 method_ref: #3.#13 java/lang/Object.<init> ()V\n" +
+ " constant #13 name_and_type: #9.#10 <init> ()V\n" +
+ " constant #14 class: #15 java/lang/String\n" +
+ " constant #15 utf8: \"java/lang/String\"\n" +
+ " constant #16 string: #17 \"S\"\n" +
+ " constant #17 utf8: \"S\"\n" +
+ " constant #18 method_ref: #14.#19 java/lang/String.<init> (Ljava/lang/String;)V\n" +
+ " constant #19 name_and_type: #9.#20 <init> (Ljava/lang/String;)V\n" +
+ " constant #20 utf8: \"(Ljava/lang/String;)V\"\n" +
+ " constant #21 name_and_type: #22.#23 lambda$ (Ljava/lang/String;)LFunction2;\n" +
+ " constant #22 utf8: \"lambda$\"\n" +
+ " constant #23 utf8: \"(Ljava/lang/String;)LFunction2;\"\n" +
+ " constant #24 invoke dynamic: #0 #21 lambda$ (Ljava/lang/String;)LFunction2;\n" +
+ " constant #25 field_ref: #1.#26 X.concat LFunction2;\n" +
+ " constant #26 name_and_type: #5.#6 concat LFunction2;\n" +
+ " constant #27 utf8: \"LineNumberTable\"\n" +
+ " constant #28 utf8: \"LocalVariableTable\"\n" +
+ " constant #29 utf8: \"this\"\n" +
+ " constant #30 utf8: \"LX;\"\n" +
+ " constant #31 utf8: \"s0\"\n" +
+ " constant #32 utf8: \"Ljava/lang/String;\"\n" +
+ " constant #33 utf8: \"lambda$0\"\n" +
+ " constant #34 utf8: \"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;\"\n" +
+ " constant #35 class: #36 java/lang/StringBuilder\n" +
+ " constant #36 utf8: \"java/lang/StringBuilder\"\n" +
+ " constant #37 method_ref: #14.#38 java/lang/String.valueOf (Ljava/lang/Object;)Ljava/lang/String;\n" +
+ " constant #38 name_and_type: #39.#40 valueOf (Ljava/lang/Object;)Ljava/lang/String;\n" +
+ " constant #39 utf8: \"valueOf\"\n" +
+ " constant #40 utf8: \"(Ljava/lang/Object;)Ljava/lang/String;\"\n" +
+ " constant #41 method_ref: #35.#19 java/lang/StringBuilder.<init> (Ljava/lang/String;)V\n" +
+ " constant #42 method_ref: #35.#43 java/lang/StringBuilder.append (Ljava/lang/String;)Ljava/lang/StringBuilder;\n" +
+ " constant #43 name_and_type: #44.#45 append (Ljava/lang/String;)Ljava/lang/StringBuilder;\n" +
+ " constant #44 utf8: \"append\"\n" +
+ " constant #45 utf8: \"(Ljava/lang/String;)Ljava/lang/StringBuilder;\"\n" +
+ " constant #46 method_ref: #35.#47 java/lang/StringBuilder.toString ()Ljava/lang/String;\n" +
+ " constant #47 name_and_type: #48.#49 toString ()Ljava/lang/String;\n" +
+ " constant #48 utf8: \"toString\"\n" +
+ " constant #49 utf8: \"()Ljava/lang/String;\"\n" +
+ " constant #50 utf8: \"s1\"\n" +
+ " constant #51 utf8: \"s2\"\n" +
+ " constant #52 utf8: \"SourceFile\"\n" +
+ " constant #53 utf8: \"X.java\"\n" +
+ " constant #54 method_ref: #55.#57 java/lang/invoke/LambdaMetafactory.metaFactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" +
+ " constant #55 class: #56 java/lang/invoke/LambdaMetafactory\n" +
+ " constant #56 utf8: \"java/lang/invoke/LambdaMetafactory\"\n" +
+ " constant #57 name_and_type: #58.#59 metaFactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" +
+ " constant #58 utf8: \"metaFactory\"\n" +
+ " constant #59 utf8: \"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\"\n" +
+ " constant #60 method handle: invokestatic (6) #54 \n" +
+ " constant #61 utf8: \"BootstrapMethods\"\n" +
+ " constant #62 interface_method_ref: #63.#65 Function2.apply (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;\n" +
+ " constant #63 class: #64 Function2\n" +
+ " constant #64 utf8: \"Function2\"\n" +
+ " constant #65 name_and_type: #66.#67 apply (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;\n" +
+ " constant #66 utf8: \"apply\"\n" +
+ " constant #67 utf8: \"(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;\"\n" +
+ " constant #68 method handle: invokeinterface (9) #62 \n" +
+ " constant #69 method_ref: #1.#70 X.lambda$0 (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;\n" +
+ " constant #70 name_and_type: #33.#34 lambda$0 (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;\n" +
+ " constant #71 method handle: invokestatic (6) #69 \n" +
+ " constant #72 utf8: \"(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;\"\n" +
+ " constant #73 method type: #72 (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;\n" +
+ " constant #74 utf8: \"InnerClasses\"\n" +
+ " constant #75 class: #76 java/lang/invoke/MethodHandles$Lookup\n" +
+ " constant #76 utf8: \"java/lang/invoke/MethodHandles$Lookup\"\n" +
+ " constant #77 class: #78 java/lang/invoke/MethodHandles\n" +
+ " constant #78 utf8: \"java/lang/invoke/MethodHandles\"\n" +
+ " constant #79 utf8: \"Lookup\"\n" +
+ " \n" +
+ " // Field descriptor #6 LFunction2;\n" +
+ " // Signature: LFunction2<Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;>;\n" +
+ " public Function2 concat;\n" +
+ " \n" +
+ " // Method descriptor #10 ()V\n" +
+ " // Stack: 3, Locals: 2\n" +
+ " public X();\n" +
+ " 0 aload_0 [this]\n" +
+ " 1 invokespecial java.lang.Object() [12]\n" +
+ " 4 new java.lang.String [14]\n" +
+ " 7 dup\n" +
+ " 8 ldc <String \"S\"> [16]\n" +
+ " 10 invokespecial java.lang.String(java.lang.String) [18]\n" +
+ " 13 astore_1 [s0]\n" +
+ " 14 aload_0 [this]\n" +
+ " 15 aload_1 [s0]\n" +
+ " 16 invokedynamic 0 lambda$(java.lang.String) : Function2 [24]\n" +
+ " 21 putfield X.concat : Function2 [25]\n" +
+ " 24 return\n" +
+ " Line numbers:\n" +
+ " [pc: 0, line: 1]\n" +
+ " [pc: 4, line: 4]\n" +
+ " [pc: 14, line: 5]\n" +
+ " [pc: 24, line: 1]\n" +
+ " Local variable table:\n" +
+ " [pc: 0, pc: 25] local: this index: 0 type: X\n" +
+ " [pc: 14, pc: 24] local: s0 index: 1 type: java.lang.String\n" +
+ " \n" +
+ " // Method descriptor #34 (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;\n" +
+ " // Stack: 3, Locals: 3\n" +
+ " private static synthetic java.lang.String lambda$0(java.lang.String arg0, java.lang.String s1, java.lang.String s2);\n" +
+ " 0 new java.lang.StringBuilder [35]\n" +
+ " 3 dup\n" +
+ " 4 aload_0 [arg0]\n" +
+ " 5 invokestatic java.lang.String.valueOf(java.lang.Object) : java.lang.String [37]\n" +
+ " 8 invokespecial java.lang.StringBuilder(java.lang.String) [41]\n" +
+ " 11 aload_1 [s1]\n" +
+ " 12 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [42]\n" +
+ " 15 aload_2 [s2]\n" +
+ " 16 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [42]\n" +
+ " 19 invokevirtual java.lang.StringBuilder.toString() : java.lang.String [46]\n" +
+ " 22 areturn\n" +
+ " Line numbers:\n" +
+ " [pc: 0, line: 5]\n" +
+ " Local variable table:\n" +
+ " [pc: 0, pc: 23] local: s1 index: 1 type: java.lang.String\n" +
+ " [pc: 0, pc: 23] local: s2 index: 2 type: java.lang.String\n" +
+ "\n" +
+ " Inner classes:\n" +
+ " [inner class info: #75 java/lang/invoke/MethodHandles$Lookup, outer class info: #77 java/lang/invoke/MethodHandles\n" +
+ " inner name: #79 Lookup, accessflags: 25 public static final]\n" +
+ "Bootstrap methods:\n" +
+ " 0 : # 60 arguments: {#68,#71,#73}\n" +
+ "}";
+
+ verifyClassFile(expectedOutput, "X.class", ClassFileBytesDisassembler.SYSTEM);
+}
+public void test011() throws Exception {
+ this.runConformTest(
+ new String[] {
+ "Main.java",
+ "public class Main {\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(new X().concat.apply(\"UCC\",\"ESS\"));\n" +
+ " }\n" +
+ "}\n",
+ "X.java",
+ "public class X {\n" +
+ " public Function2<String, String, String> concat; \n" +
+ " {\n" +
+ " String s0 = new String(\"S\");\n" +
+ " concat = (s1, s2) -> s0 + s1 + s2; \n" +
+ " }\n" +
+ "}\n",
+ "Function2.java",
+ "public interface Function2<R, T1, T2> {\n" +
+ " R apply(T1 a1, T2 a2);\n" +
+ "}\n",
+
+ },
+ "SUCCESS"
+ );
+
+ String expectedOutput =
+ "// Compiled from X.java (version 1.8 : 52.0, super bit)\n" +
+ "public class X {\n" +
+ " Constant pool:\n" +
+ " constant #1 class: #2 X\n" +
+ " constant #2 utf8: \"X\"\n" +
+ " constant #3 class: #4 java/lang/Object\n" +
+ " constant #4 utf8: \"java/lang/Object\"\n" +
+ " constant #5 utf8: \"concat\"\n" +
+ " constant #6 utf8: \"LFunction2;\"\n" +
+ " constant #7 utf8: \"Signature\"\n" +
+ " constant #8 utf8: \"LFunction2<Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;>;\"\n" +
+ " constant #9 utf8: \"<init>\"\n" +
+ " constant #10 utf8: \"()V\"\n" +
+ " constant #11 utf8: \"Code\"\n" +
+ " constant #12 method_ref: #3.#13 java/lang/Object.<init> ()V\n" +
+ " constant #13 name_and_type: #9.#10 <init> ()V\n" +
+ " constant #14 class: #15 java/lang/String\n" +
+ " constant #15 utf8: \"java/lang/String\"\n" +
+ " constant #16 string: #17 \"S\"\n" +
+ " constant #17 utf8: \"S\"\n" +
+ " constant #18 method_ref: #14.#19 java/lang/String.<init> (Ljava/lang/String;)V\n" +
+ " constant #19 name_and_type: #9.#20 <init> (Ljava/lang/String;)V\n" +
+ " constant #20 utf8: \"(Ljava/lang/String;)V\"\n" +
+ " constant #21 name_and_type: #22.#23 lambda$ (Ljava/lang/String;)LFunction2;\n" +
+ " constant #22 utf8: \"lambda$\"\n" +
+ " constant #23 utf8: \"(Ljava/lang/String;)LFunction2;\"\n" +
+ " constant #24 invoke dynamic: #0 #21 lambda$ (Ljava/lang/String;)LFunction2;\n" +
+ " constant #25 field_ref: #1.#26 X.concat LFunction2;\n" +
+ " constant #26 name_and_type: #5.#6 concat LFunction2;\n" +
+ " constant #27 utf8: \"LineNumberTable\"\n" +
+ " constant #28 utf8: \"LocalVariableTable\"\n" +
+ " constant #29 utf8: \"this\"\n" +
+ " constant #30 utf8: \"LX;\"\n" +
+ " constant #31 utf8: \"s0\"\n" +
+ " constant #32 utf8: \"Ljava/lang/String;\"\n" +
+ " constant #33 utf8: \"lambda$0\"\n" +
+ " constant #34 utf8: \"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;\"\n" +
+ " constant #35 class: #36 java/lang/StringBuilder\n" +
+ " constant #36 utf8: \"java/lang/StringBuilder\"\n" +
+ " constant #37 method_ref: #14.#38 java/lang/String.valueOf (Ljava/lang/Object;)Ljava/lang/String;\n" +
+ " constant #38 name_and_type: #39.#40 valueOf (Ljava/lang/Object;)Ljava/lang/String;\n" +
+ " constant #39 utf8: \"valueOf\"\n" +
+ " constant #40 utf8: \"(Ljava/lang/Object;)Ljava/lang/String;\"\n" +
+ " constant #41 method_ref: #35.#19 java/lang/StringBuilder.<init> (Ljava/lang/String;)V\n" +
+ " constant #42 method_ref: #35.#43 java/lang/StringBuilder.append (Ljava/lang/String;)Ljava/lang/StringBuilder;\n" +
+ " constant #43 name_and_type: #44.#45 append (Ljava/lang/String;)Ljava/lang/StringBuilder;\n" +
+ " constant #44 utf8: \"append\"\n" +
+ " constant #45 utf8: \"(Ljava/lang/String;)Ljava/lang/StringBuilder;\"\n" +
+ " constant #46 method_ref: #35.#47 java/lang/StringBuilder.toString ()Ljava/lang/String;\n" +
+ " constant #47 name_and_type: #48.#49 toString ()Ljava/lang/String;\n" +
+ " constant #48 utf8: \"toString\"\n" +
+ " constant #49 utf8: \"()Ljava/lang/String;\"\n" +
+ " constant #50 utf8: \"s1\"\n" +
+ " constant #51 utf8: \"s2\"\n" +
+ " constant #52 utf8: \"SourceFile\"\n" +
+ " constant #53 utf8: \"X.java\"\n" +
+ " constant #54 method_ref: #55.#57 java/lang/invoke/LambdaMetafactory.metaFactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" +
+ " constant #55 class: #56 java/lang/invoke/LambdaMetafactory\n" +
+ " constant #56 utf8: \"java/lang/invoke/LambdaMetafactory\"\n" +
+ " constant #57 name_and_type: #58.#59 metaFactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" +
+ " constant #58 utf8: \"metaFactory\"\n" +
+ " constant #59 utf8: \"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\"\n" +
+ " constant #60 method handle: invokestatic (6) #54 \n" +
+ " constant #61 utf8: \"BootstrapMethods\"\n" +
+ " constant #62 interface_method_ref: #63.#65 Function2.apply (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;\n" +
+ " constant #63 class: #64 Function2\n" +
+ " constant #64 utf8: \"Function2\"\n" +
+ " constant #65 name_and_type: #66.#67 apply (Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;\n" +
+ " constant #66 utf8: \"apply\"\n" +
+ " constant #67 utf8: \"(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;\"\n" +
+ " constant #68 method handle: invokeinterface (9) #62 \n" +
+ " constant #69 method_ref: #1.#70 X.lambda$0 (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;\n" +
+ " constant #70 name_and_type: #33.#34 lambda$0 (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;\n" +
+ " constant #71 method handle: invokestatic (6) #69 \n" +
+ " constant #72 utf8: \"(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;\"\n" +
+ " constant #73 method type: #72 (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;\n" +
+ " constant #74 utf8: \"InnerClasses\"\n" +
+ " constant #75 class: #76 java/lang/invoke/MethodHandles$Lookup\n" +
+ " constant #76 utf8: \"java/lang/invoke/MethodHandles$Lookup\"\n" +
+ " constant #77 class: #78 java/lang/invoke/MethodHandles\n" +
+ " constant #78 utf8: \"java/lang/invoke/MethodHandles\"\n" +
+ " constant #79 utf8: \"Lookup\"\n" +
+ " \n" +
+ " // Field descriptor #6 LFunction2;\n" +
+ " // Signature: LFunction2<Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;>;\n" +
+ " public Function2 concat;\n" +
+ " \n" +
+ " // Method descriptor #10 ()V\n" +
+ " // Stack: 3, Locals: 2\n" +
+ " public X();\n" +
+ " 0 aload_0 [this]\n" +
+ " 1 invokespecial java.lang.Object() [12]\n" +
+ " 4 new java.lang.String [14]\n" +
+ " 7 dup\n" +
+ " 8 ldc <String \"S\"> [16]\n" +
+ " 10 invokespecial java.lang.String(java.lang.String) [18]\n" +
+ " 13 astore_1 [s0]\n" +
+ " 14 aload_0 [this]\n" +
+ " 15 aload_1 [s0]\n" +
+ " 16 invokedynamic 0 lambda$(java.lang.String) : Function2 [24]\n" +
+ " 21 putfield X.concat : Function2 [25]\n" +
+ " 24 return\n" +
+ " Line numbers:\n" +
+ " [pc: 0, line: 1]\n" +
+ " [pc: 4, line: 4]\n" +
+ " [pc: 14, line: 5]\n" +
+ " [pc: 24, line: 1]\n" +
+ " Local variable table:\n" +
+ " [pc: 0, pc: 25] local: this index: 0 type: X\n" +
+ " [pc: 14, pc: 24] local: s0 index: 1 type: java.lang.String\n" +
+ " \n" +
+ " // Method descriptor #34 (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;\n" +
+ " // Stack: 3, Locals: 3\n" +
+ " private static synthetic java.lang.String lambda$0(java.lang.String arg0, java.lang.String s1, java.lang.String s2);\n" +
+ " 0 new java.lang.StringBuilder [35]\n" +
+ " 3 dup\n" +
+ " 4 aload_0 [arg0]\n" +
+ " 5 invokestatic java.lang.String.valueOf(java.lang.Object) : java.lang.String [37]\n" +
+ " 8 invokespecial java.lang.StringBuilder(java.lang.String) [41]\n" +
+ " 11 aload_1 [s1]\n" +
+ " 12 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [42]\n" +
+ " 15 aload_2 [s2]\n" +
+ " 16 invokevirtual java.lang.StringBuilder.append(java.lang.String) : java.lang.StringBuilder [42]\n" +
+ " 19 invokevirtual java.lang.StringBuilder.toString() : java.lang.String [46]\n" +
+ " 22 areturn\n" +
+ " Line numbers:\n" +
+ " [pc: 0, line: 5]\n" +
+ " Local variable table:\n" +
+ " [pc: 0, pc: 23] local: s1 index: 1 type: java.lang.String\n" +
+ " [pc: 0, pc: 23] local: s2 index: 2 type: java.lang.String\n" +
+ "\n" +
+ " Inner classes:\n" +
+ " [inner class info: #75 java/lang/invoke/MethodHandles$Lookup, outer class info: #77 java/lang/invoke/MethodHandles\n" +
+ " inner name: #79 Lookup, accessflags: 25 public static final]\n" +
+ "Bootstrap methods:\n" +
+ " 0 : # 60 arguments: {#68,#71,#73}\n" +
+ "}";
+
+ verifyClassFile(expectedOutput, "X.class", ClassFileBytesDisassembler.SYSTEM);
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406627, [1.8][compiler][codegen] Annotations on lambda parameters go the way of /dev/null
+public void test012() throws Exception {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "import java.lang.annotation.ElementType;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import java.lang.annotation.RetentionPolicy;\n" +
+ "import java.lang.annotation.Target;\n" +
+ "interface I {\n" +
+ " void doit (Object o, Object p);\n" +
+ "}\n" +
+ "public class X {\n" +
+ " public static void main(String [] args) {\n" +
+ " int local1 = 0, local2 = 1;\n" +
+ " I i = (@Annotation Object o, @Annotation Object p) -> {\n" +
+ " int j = args.length + local1 + local2;\n" +
+ " };\n" +
+ "}\n" +
+ "}\n" +
+ "@Target(ElementType.PARAMETER)\n" +
+ "@Retention(RetentionPolicy.RUNTIME)\n" +
+ "@interface Annotation {\n" +
+ "}\n",
+ },
+ "");
+
+ String expectedOutput =
+ "// Compiled from X.java (version 1.8 : 52.0, super bit)\n" +
+ "public class X {\n" +
+ " Constant pool:\n" +
+ " constant #1 class: #2 X\n" +
+ " constant #2 utf8: \"X\"\n" +
+ " constant #3 class: #4 java/lang/Object\n" +
+ " constant #4 utf8: \"java/lang/Object\"\n" +
+ " constant #5 utf8: \"<init>\"\n" +
+ " constant #6 utf8: \"()V\"\n" +
+ " constant #7 utf8: \"Code\"\n" +
+ " constant #8 method_ref: #3.#9 java/lang/Object.<init> ()V\n" +
+ " constant #9 name_and_type: #5.#6 <init> ()V\n" +
+ " constant #10 utf8: \"LineNumberTable\"\n" +
+ " constant #11 utf8: \"LocalVariableTable\"\n" +
+ " constant #12 utf8: \"this\"\n" +
+ " constant #13 utf8: \"LX;\"\n" +
+ " constant #14 utf8: \"main\"\n" +
+ " constant #15 utf8: \"([Ljava/lang/String;)V\"\n" +
+ " constant #16 name_and_type: #17.#18 lambda$ ([Ljava/lang/String;II)LI;\n" +
+ " constant #17 utf8: \"lambda$\"\n" +
+ " constant #18 utf8: \"([Ljava/lang/String;II)LI;\"\n" +
+ " constant #19 invoke dynamic: #0 #16 lambda$ ([Ljava/lang/String;II)LI;\n" +
+ " constant #20 utf8: \"args\"\n" +
+ " constant #21 utf8: \"[Ljava/lang/String;\"\n" +
+ " constant #22 utf8: \"local1\"\n" +
+ " constant #23 utf8: \"I\"\n" +
+ " constant #24 utf8: \"local2\"\n" +
+ " constant #25 utf8: \"i\"\n" +
+ " constant #26 utf8: \"LI;\"\n" +
+ " constant #27 utf8: \"lambda$0\"\n" +
+ " constant #28 utf8: \"([Ljava/lang/String;IILjava/lang/Object;Ljava/lang/Object;)V\"\n" +
+ " constant #29 utf8: \"RuntimeVisibleParameterAnnotations\"\n" +
+ " constant #30 utf8: \"LAnnotation;\"\n" +
+ " constant #31 utf8: \"o\"\n" +
+ " constant #32 utf8: \"Ljava/lang/Object;\"\n" +
+ " constant #33 utf8: \"p\"\n" +
+ " constant #34 utf8: \"SourceFile\"\n" +
+ " constant #35 utf8: \"X.java\"\n" +
+ " constant #36 method_ref: #37.#39 java/lang/invoke/LambdaMetafactory.metaFactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" +
+ " constant #37 class: #38 java/lang/invoke/LambdaMetafactory\n" +
+ " constant #38 utf8: \"java/lang/invoke/LambdaMetafactory\"\n" +
+ " constant #39 name_and_type: #40.#41 metaFactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" +
+ " constant #40 utf8: \"metaFactory\"\n" +
+ " constant #41 utf8: \"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\"\n" +
+ " constant #42 method handle: invokestatic (6) #36 \n" +
+ " constant #43 utf8: \"BootstrapMethods\"\n" +
+ " constant #44 interface_method_ref: #45.#46 I.doit (Ljava/lang/Object;Ljava/lang/Object;)V\n" +
+ " constant #45 class: #23 I\n" +
+ " constant #46 name_and_type: #47.#48 doit (Ljava/lang/Object;Ljava/lang/Object;)V\n" +
+ " constant #47 utf8: \"doit\"\n" +
+ " constant #48 utf8: \"(Ljava/lang/Object;Ljava/lang/Object;)V\"\n" +
+ " constant #49 method handle: invokeinterface (9) #44 \n" +
+ " constant #50 method_ref: #1.#51 X.lambda$0 ([Ljava/lang/String;IILjava/lang/Object;Ljava/lang/Object;)V\n" +
+ " constant #51 name_and_type: #27.#28 lambda$0 ([Ljava/lang/String;IILjava/lang/Object;Ljava/lang/Object;)V\n" +
+ " constant #52 method handle: invokestatic (6) #50 \n" +
+ " constant #53 method type: #48 (Ljava/lang/Object;Ljava/lang/Object;)V\n" +
+ " constant #54 utf8: \"InnerClasses\"\n" +
+ " constant #55 class: #56 java/lang/invoke/MethodHandles$Lookup\n" +
+ " constant #56 utf8: \"java/lang/invoke/MethodHandles$Lookup\"\n" +
+ " constant #57 class: #58 java/lang/invoke/MethodHandles\n" +
+ " constant #58 utf8: \"java/lang/invoke/MethodHandles\"\n" +
+ " constant #59 utf8: \"Lookup\"\n" +
+ " \n" +
+ " // Method descriptor #6 ()V\n" +
+ " // Stack: 1, Locals: 1\n" +
+ " public X();\n" +
+ " 0 aload_0 [this]\n" +
+ " 1 invokespecial java.lang.Object() [8]\n" +
+ " 4 return\n" +
+ " Line numbers:\n" +
+ " [pc: 0, line: 8]\n" +
+ " Local variable table:\n" +
+ " [pc: 0, pc: 5] local: this index: 0 type: X\n" +
+ " \n" +
+ " // Method descriptor #15 ([Ljava/lang/String;)V\n" +
+ " // Stack: 3, Locals: 4\n" +
+ " public static void main(java.lang.String[] args);\n" +
+ " 0 iconst_0\n" +
+ " 1 istore_1 [local1]\n" +
+ " 2 iconst_1\n" +
+ " 3 istore_2 [local2]\n" +
+ " 4 aload_0 [args]\n" +
+ " 5 iload_1 [local1]\n" +
+ " 6 iload_2 [local2]\n" +
+ " 7 invokedynamic 0 lambda$(java.lang.String[], int, int) : I [19]\n" +
+ " 12 astore_3 [i]\n" +
+ " 13 return\n" +
+ " Line numbers:\n" +
+ " [pc: 0, line: 10]\n" +
+ " [pc: 4, line: 11]\n" +
+ " [pc: 13, line: 14]\n" +
+ " Local variable table:\n" +
+ " [pc: 0, pc: 14] local: args index: 0 type: java.lang.String[]\n" +
+ " [pc: 2, pc: 14] local: local1 index: 1 type: int\n" +
+ " [pc: 4, pc: 14] local: local2 index: 2 type: int\n" +
+ " [pc: 13, pc: 14] local: i index: 3 type: I\n" +
+ " \n" +
+ " // Method descriptor #28 ([Ljava/lang/String;IILjava/lang/Object;Ljava/lang/Object;)V\n" +
+ " // Stack: 2, Locals: 6\n" +
+ " private static synthetic void lambda$0(java.lang.String[] arg0, int arg1, int arg2, java.lang.Object o, java.lang.Object p);\n" +
+ " 0 aload_0 [arg0]\n" +
+ " 1 arraylength\n" +
+ " 2 iload_1 [arg1]\n" +
+ " 3 iadd\n" +
+ " 4 iload_2 [arg2]\n" +
+ " 5 iadd\n" +
+ " 6 istore 5\n" +
+ " 8 return\n" +
+ " Line numbers:\n" +
+ " [pc: 0, line: 12]\n" +
+ " [pc: 8, line: 13]\n" +
+ " Local variable table:\n" +
+ " [pc: 0, pc: 9] local: o index: 3 type: java.lang.Object\n" +
+ " [pc: 0, pc: 9] local: p index: 4 type: java.lang.Object\n" +
+ " RuntimeVisibleParameterAnnotations: \n" +
+ " Number of annotations for parameter 0: 0\n" +
+ " Number of annotations for parameter 1: 0\n" +
+ " Number of annotations for parameter 2: 0\n" +
+ " Number of annotations for parameter 3: 1\n" +
+ " #30 @Annotation(\n" +
+ " )\n" +
+ " Number of annotations for parameter 4: 1\n" +
+ " #30 @Annotation(\n" +
+ " )\n" +
+ "\n" +
+ " Inner classes:\n" +
+ " [inner class info: #55 java/lang/invoke/MethodHandles$Lookup, outer class info: #57 java/lang/invoke/MethodHandles\n" +
+ " inner name: #59 Lookup, accessflags: 25 public static final]\n" +
+ "Bootstrap methods:\n" +
+ " 0 : # 42 arguments: {#49,#52,#53}\n" +
+ "}";
+
+ verifyClassFile(expectedOutput, "X.class", ClassFileBytesDisassembler.SYSTEM);
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406627, [1.8][compiler][codegen] Annotations on lambda parameters go the way of /dev/null
+public void test013() throws Exception {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "import java.lang.annotation.ElementType;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import java.lang.annotation.RetentionPolicy;\n" +
+ "import java.lang.annotation.Target;\n" +
+ "interface I {\n" +
+ " void doit (Object o, Object p);\n" +
+ "}\n" +
+ "public class X {\n" +
+ " public static void main(String [] args) {\n" +
+ " I i = (@Annotation Object o, @Annotation Object p) -> {\n" +
+ " };\n" +
+ "}\n" +
+ "}\n" +
+ "@Target(ElementType.PARAMETER)\n" +
+ "@Retention(RetentionPolicy.RUNTIME)\n" +
+ "@interface Annotation {\n" +
+ "}\n",
+ },
+ "");
+
+ String expectedOutput =
+ "// Compiled from X.java (version 1.8 : 52.0, super bit)\n" +
+ "public class X {\n" +
+ " Constant pool:\n" +
+ " constant #1 class: #2 X\n" +
+ " constant #2 utf8: \"X\"\n" +
+ " constant #3 class: #4 java/lang/Object\n" +
+ " constant #4 utf8: \"java/lang/Object\"\n" +
+ " constant #5 utf8: \"<init>\"\n" +
+ " constant #6 utf8: \"()V\"\n" +
+ " constant #7 utf8: \"Code\"\n" +
+ " constant #8 method_ref: #3.#9 java/lang/Object.<init> ()V\n" +
+ " constant #9 name_and_type: #5.#6 <init> ()V\n" +
+ " constant #10 utf8: \"LineNumberTable\"\n" +
+ " constant #11 utf8: \"LocalVariableTable\"\n" +
+ " constant #12 utf8: \"this\"\n" +
+ " constant #13 utf8: \"LX;\"\n" +
+ " constant #14 utf8: \"main\"\n" +
+ " constant #15 utf8: \"([Ljava/lang/String;)V\"\n" +
+ " constant #16 name_and_type: #17.#18 lambda$ ()LI;\n" +
+ " constant #17 utf8: \"lambda$\"\n" +
+ " constant #18 utf8: \"()LI;\"\n" +
+ " constant #19 invoke dynamic: #0 #16 lambda$ ()LI;\n" +
+ " constant #20 utf8: \"args\"\n" +
+ " constant #21 utf8: \"[Ljava/lang/String;\"\n" +
+ " constant #22 utf8: \"i\"\n" +
+ " constant #23 utf8: \"LI;\"\n" +
+ " constant #24 utf8: \"lambda$0\"\n" +
+ " constant #25 utf8: \"(Ljava/lang/Object;Ljava/lang/Object;)V\"\n" +
+ " constant #26 utf8: \"RuntimeVisibleParameterAnnotations\"\n" +
+ " constant #27 utf8: \"LAnnotation;\"\n" +
+ " constant #28 utf8: \"o\"\n" +
+ " constant #29 utf8: \"Ljava/lang/Object;\"\n" +
+ " constant #30 utf8: \"p\"\n" +
+ " constant #31 utf8: \"SourceFile\"\n" +
+ " constant #32 utf8: \"X.java\"\n" +
+ " constant #33 method_ref: #34.#36 java/lang/invoke/LambdaMetafactory.metaFactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" +
+ " constant #34 class: #35 java/lang/invoke/LambdaMetafactory\n" +
+ " constant #35 utf8: \"java/lang/invoke/LambdaMetafactory\"\n" +
+ " constant #36 name_and_type: #37.#38 metaFactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" +
+ " constant #37 utf8: \"metaFactory\"\n" +
+ " constant #38 utf8: \"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\"\n" +
+ " constant #39 method handle: invokestatic (6) #33 \n" +
+ " constant #40 utf8: \"BootstrapMethods\"\n" +
+ " constant #41 interface_method_ref: #42.#44 I.doit (Ljava/lang/Object;Ljava/lang/Object;)V\n" +
+ " constant #42 class: #43 I\n" +
+ " constant #43 utf8: \"I\"\n" +
+ " constant #44 name_and_type: #45.#25 doit (Ljava/lang/Object;Ljava/lang/Object;)V\n" +
+ " constant #45 utf8: \"doit\"\n" +
+ " constant #46 method handle: invokeinterface (9) #41 \n" +
+ " constant #47 method_ref: #1.#48 X.lambda$0 (Ljava/lang/Object;Ljava/lang/Object;)V\n" +
+ " constant #48 name_and_type: #24.#25 lambda$0 (Ljava/lang/Object;Ljava/lang/Object;)V\n" +
+ " constant #49 method handle: invokestatic (6) #47 \n" +
+ " constant #50 method type: #25 (Ljava/lang/Object;Ljava/lang/Object;)V\n" +
+ " constant #51 utf8: \"InnerClasses\"\n" +
+ " constant #52 class: #53 java/lang/invoke/MethodHandles$Lookup\n" +
+ " constant #53 utf8: \"java/lang/invoke/MethodHandles$Lookup\"\n" +
+ " constant #54 class: #55 java/lang/invoke/MethodHandles\n" +
+ " constant #55 utf8: \"java/lang/invoke/MethodHandles\"\n" +
+ " constant #56 utf8: \"Lookup\"\n" +
+ " \n" +
+ " // Method descriptor #6 ()V\n" +
+ " // Stack: 1, Locals: 1\n" +
+ " public X();\n" +
+ " 0 aload_0 [this]\n" +
+ " 1 invokespecial java.lang.Object() [8]\n" +
+ " 4 return\n" +
+ " Line numbers:\n" +
+ " [pc: 0, line: 8]\n" +
+ " Local variable table:\n" +
+ " [pc: 0, pc: 5] local: this index: 0 type: X\n" +
+ " \n" +
+ " // Method descriptor #15 ([Ljava/lang/String;)V\n" +
+ " // Stack: 1, Locals: 2\n" +
+ " public static void main(java.lang.String[] args);\n" +
+ " 0 invokedynamic 0 lambda$() : I [19]\n" +
+ " 5 astore_1 [i]\n" +
+ " 6 return\n" +
+ " Line numbers:\n" +
+ " [pc: 0, line: 10]\n" +
+ " [pc: 6, line: 12]\n" +
+ " Local variable table:\n" +
+ " [pc: 0, pc: 7] local: args index: 0 type: java.lang.String[]\n" +
+ " [pc: 6, pc: 7] local: i index: 1 type: I\n" +
+ " \n" +
+ " // Method descriptor #25 (Ljava/lang/Object;Ljava/lang/Object;)V\n" +
+ " // Stack: 0, Locals: 2\n" +
+ " private static synthetic void lambda$0(java.lang.Object o, java.lang.Object p);\n" +
+ " 0 return\n" +
+ " Line numbers:\n" +
+ " [pc: 0, line: 11]\n" +
+ " Local variable table:\n" +
+ " [pc: 0, pc: 1] local: o index: 0 type: java.lang.Object\n" +
+ " [pc: 0, pc: 1] local: p index: 1 type: java.lang.Object\n" +
+ " RuntimeVisibleParameterAnnotations: \n" +
+ " Number of annotations for parameter 0: 1\n" +
+ " #27 @Annotation(\n" +
+ " )\n" +
+ " Number of annotations for parameter 1: 1\n" +
+ " #27 @Annotation(\n" +
+ " )\n" +
+ "\n" +
+ " Inner classes:\n" +
+ " [inner class info: #52 java/lang/invoke/MethodHandles$Lookup, outer class info: #54 java/lang/invoke/MethodHandles\n" +
+ " inner name: #56 Lookup, accessflags: 25 public static final]\n" +
+ "Bootstrap methods:\n" +
+ " 0 : # 39 arguments: {#46,#49,#50}\n" +
+ "}";
+
+ verifyClassFile(expectedOutput, "X.class", ClassFileBytesDisassembler.SYSTEM);
+}
+public void test014() throws Exception {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "import java.lang.annotation.ElementType;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import java.lang.annotation.RetentionPolicy;\n" +
+ "import java.lang.annotation.Target;\n" +
+ "interface I {\n" +
+ " void doit (Object o, Object p);\n" +
+ "}\n" +
+ "public class X {\n" +
+ " I i = (@Annotation Object o, @Annotation Object p) -> {\n" +
+ " };\n" +
+ " public static void main(String [] args) {\n" +
+ " int local1 = 0, local2 = 1;\n" +
+ " I i = (@Annotation Object o, @Annotation Object p) -> {\n" +
+ " int j = args.length + local1 + local2;\n" +
+ " };\n" +
+ "}\n" +
+ "}\n" +
+ "@Target(ElementType.PARAMETER)\n" +
+ "@Retention(RetentionPolicy.RUNTIME)\n" +
+ "@interface Annotation {\n" +
+ "}\n",
+ },
+ "");
+
+ String expectedOutput =
+ "// Compiled from X.java (version 1.8 : 52.0, super bit)\n" +
+ "public class X {\n" +
+ " Constant pool:\n" +
+ " constant #1 class: #2 X\n" +
+ " constant #2 utf8: \"X\"\n" +
+ " constant #3 class: #4 java/lang/Object\n" +
+ " constant #4 utf8: \"java/lang/Object\"\n" +
+ " constant #5 utf8: \"i\"\n" +
+ " constant #6 utf8: \"LI;\"\n" +
+ " constant #7 utf8: \"<init>\"\n" +
+ " constant #8 utf8: \"()V\"\n" +
+ " constant #9 utf8: \"Code\"\n" +
+ " constant #10 method_ref: #3.#11 java/lang/Object.<init> ()V\n" +
+ " constant #11 name_and_type: #7.#8 <init> ()V\n" +
+ " constant #12 name_and_type: #13.#14 lambda$ ()LI;\n" +
+ " constant #13 utf8: \"lambda$\"\n" +
+ " constant #14 utf8: \"()LI;\"\n" +
+ " constant #15 invoke dynamic: #0 #12 lambda$ ()LI;\n" +
+ " constant #16 field_ref: #1.#17 X.i LI;\n" +
+ " constant #17 name_and_type: #5.#6 i LI;\n" +
+ " constant #18 utf8: \"LineNumberTable\"\n" +
+ " constant #19 utf8: \"LocalVariableTable\"\n" +
+ " constant #20 utf8: \"this\"\n" +
+ " constant #21 utf8: \"LX;\"\n" +
+ " constant #22 utf8: \"main\"\n" +
+ " constant #23 utf8: \"([Ljava/lang/String;)V\"\n" +
+ " constant #24 name_and_type: #13.#25 lambda$ ([Ljava/lang/String;II)LI;\n" +
+ " constant #25 utf8: \"([Ljava/lang/String;II)LI;\"\n" +
+ " constant #26 invoke dynamic: #1 #24 lambda$ ([Ljava/lang/String;II)LI;\n" +
+ " constant #27 utf8: \"args\"\n" +
+ " constant #28 utf8: \"[Ljava/lang/String;\"\n" +
+ " constant #29 utf8: \"local1\"\n" +
+ " constant #30 utf8: \"I\"\n" +
+ " constant #31 utf8: \"local2\"\n" +
+ " constant #32 utf8: \"lambda$0\"\n" +
+ " constant #33 utf8: \"(Ljava/lang/Object;Ljava/lang/Object;)V\"\n" +
+ " constant #34 utf8: \"RuntimeVisibleParameterAnnotations\"\n" +
+ " constant #35 utf8: \"LAnnotation;\"\n" +
+ " constant #36 utf8: \"o\"\n" +
+ " constant #37 utf8: \"Ljava/lang/Object;\"\n" +
+ " constant #38 utf8: \"p\"\n" +
+ " constant #39 utf8: \"lambda$1\"\n" +
+ " constant #40 utf8: \"([Ljava/lang/String;IILjava/lang/Object;Ljava/lang/Object;)V\"\n" +
+ " constant #41 utf8: \"SourceFile\"\n" +
+ " constant #42 utf8: \"X.java\"\n" +
+ " constant #43 method_ref: #44.#46 java/lang/invoke/LambdaMetafactory.metaFactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" +
+ " constant #44 class: #45 java/lang/invoke/LambdaMetafactory\n" +
+ " constant #45 utf8: \"java/lang/invoke/LambdaMetafactory\"\n" +
+ " constant #46 name_and_type: #47.#48 metaFactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" +
+ " constant #47 utf8: \"metaFactory\"\n" +
+ " constant #48 utf8: \"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\"\n" +
+ " constant #49 method handle: invokestatic (6) #43 \n" +
+ " constant #50 utf8: \"BootstrapMethods\"\n" +
+ " constant #51 interface_method_ref: #52.#53 I.doit (Ljava/lang/Object;Ljava/lang/Object;)V\n" +
+ " constant #52 class: #30 I\n" +
+ " constant #53 name_and_type: #54.#33 doit (Ljava/lang/Object;Ljava/lang/Object;)V\n" +
+ " constant #54 utf8: \"doit\"\n" +
+ " constant #55 method handle: invokeinterface (9) #51 \n" +
+ " constant #56 method_ref: #1.#57 X.lambda$0 (Ljava/lang/Object;Ljava/lang/Object;)V\n" +
+ " constant #57 name_and_type: #32.#33 lambda$0 (Ljava/lang/Object;Ljava/lang/Object;)V\n" +
+ " constant #58 method handle: invokestatic (6) #56 \n" +
+ " constant #59 method type: #33 (Ljava/lang/Object;Ljava/lang/Object;)V\n" +
+ " constant #60 method handle: invokeinterface (9) #51 \n" +
+ " constant #61 method_ref: #1.#62 X.lambda$1 ([Ljava/lang/String;IILjava/lang/Object;Ljava/lang/Object;)V\n" +
+ " constant #62 name_and_type: #39.#40 lambda$1 ([Ljava/lang/String;IILjava/lang/Object;Ljava/lang/Object;)V\n" +
+ " constant #63 method handle: invokestatic (6) #61 \n" +
+ " constant #64 method type: #33 (Ljava/lang/Object;Ljava/lang/Object;)V\n" +
+ " constant #65 utf8: \"InnerClasses\"\n" +
+ " constant #66 class: #67 java/lang/invoke/MethodHandles$Lookup\n" +
+ " constant #67 utf8: \"java/lang/invoke/MethodHandles$Lookup\"\n" +
+ " constant #68 class: #69 java/lang/invoke/MethodHandles\n" +
+ " constant #69 utf8: \"java/lang/invoke/MethodHandles\"\n" +
+ " constant #70 utf8: \"Lookup\"\n" +
+ " \n" +
+ " // Field descriptor #6 LI;\n" +
+ " I i;\n" +
+ " \n" +
+ " // Method descriptor #8 ()V\n" +
+ " // Stack: 2, Locals: 1\n" +
+ " public X();\n" +
+ " 0 aload_0 [this]\n" +
+ " 1 invokespecial java.lang.Object() [10]\n" +
+ " 4 aload_0 [this]\n" +
+ " 5 invokedynamic 0 lambda$() : I [15]\n" +
+ " 10 putfield X.i : I [16]\n" +
+ " 13 return\n" +
+ " Line numbers:\n" +
+ " [pc: 0, line: 8]\n" +
+ " [pc: 4, line: 9]\n" +
+ " [pc: 13, line: 8]\n" +
+ " Local variable table:\n" +
+ " [pc: 0, pc: 14] local: this index: 0 type: X\n" +
+ " \n" +
+ " // Method descriptor #23 ([Ljava/lang/String;)V\n" +
+ " // Stack: 3, Locals: 4\n" +
+ " public static void main(java.lang.String[] args);\n" +
+ " 0 iconst_0\n" +
+ " 1 istore_1 [local1]\n" +
+ " 2 iconst_1\n" +
+ " 3 istore_2 [local2]\n" +
+ " 4 aload_0 [args]\n" +
+ " 5 iload_1 [local1]\n" +
+ " 6 iload_2 [local2]\n" +
+ " 7 invokedynamic 1 lambda$(java.lang.String[], int, int) : I [26]\n" +
+ " 12 astore_3 [i]\n" +
+ " 13 return\n" +
+ " Line numbers:\n" +
+ " [pc: 0, line: 12]\n" +
+ " [pc: 4, line: 13]\n" +
+ " [pc: 13, line: 16]\n" +
+ " Local variable table:\n" +
+ " [pc: 0, pc: 14] local: args index: 0 type: java.lang.String[]\n" +
+ " [pc: 2, pc: 14] local: local1 index: 1 type: int\n" +
+ " [pc: 4, pc: 14] local: local2 index: 2 type: int\n" +
+ " [pc: 13, pc: 14] local: i index: 3 type: I\n" +
+ " \n" +
+ " // Method descriptor #33 (Ljava/lang/Object;Ljava/lang/Object;)V\n" +
+ " // Stack: 0, Locals: 2\n" +
+ " private static synthetic void lambda$0(java.lang.Object o, java.lang.Object p);\n" +
+ " 0 return\n" +
+ " Line numbers:\n" +
+ " [pc: 0, line: 10]\n" +
+ " Local variable table:\n" +
+ " [pc: 0, pc: 1] local: o index: 0 type: java.lang.Object\n" +
+ " [pc: 0, pc: 1] local: p index: 1 type: java.lang.Object\n" +
+ " RuntimeVisibleParameterAnnotations: \n" +
+ " Number of annotations for parameter 0: 1\n" +
+ " #35 @Annotation(\n" +
+ " )\n" +
+ " Number of annotations for parameter 1: 1\n" +
+ " #35 @Annotation(\n" +
+ " )\n" +
+ " \n" +
+ " // Method descriptor #40 ([Ljava/lang/String;IILjava/lang/Object;Ljava/lang/Object;)V\n" +
+ " // Stack: 2, Locals: 6\n" +
+ " private static synthetic void lambda$1(java.lang.String[] arg0, int arg1, int arg2, java.lang.Object o, java.lang.Object p);\n" +
+ " 0 aload_0 [arg0]\n" +
+ " 1 arraylength\n" +
+ " 2 iload_1 [arg1]\n" +
+ " 3 iadd\n" +
+ " 4 iload_2 [arg2]\n" +
+ " 5 iadd\n" +
+ " 6 istore 5\n" +
+ " 8 return\n" +
+ " Line numbers:\n" +
+ " [pc: 0, line: 14]\n" +
+ " [pc: 8, line: 15]\n" +
+ " Local variable table:\n" +
+ " [pc: 0, pc: 9] local: o index: 3 type: java.lang.Object\n" +
+ " [pc: 0, pc: 9] local: p index: 4 type: java.lang.Object\n" +
+ " RuntimeVisibleParameterAnnotations: \n" +
+ " Number of annotations for parameter 0: 0\n" +
+ " Number of annotations for parameter 1: 0\n" +
+ " Number of annotations for parameter 2: 0\n" +
+ " Number of annotations for parameter 3: 1\n" +
+ " #35 @Annotation(\n" +
+ " )\n" +
+ " Number of annotations for parameter 4: 1\n" +
+ " #35 @Annotation(\n" +
+ " )\n" +
+ "\n" +
+ " Inner classes:\n" +
+ " [inner class info: #66 java/lang/invoke/MethodHandles$Lookup, outer class info: #68 java/lang/invoke/MethodHandles\n" +
+ " inner name: #70 Lookup, accessflags: 25 public static final]\n" +
+ "Bootstrap methods:\n" +
+ " 0 : # 49 arguments: {#55,#58,#59},\n" +
+ " 1 : # 49 arguments: {#60,#63,#64}\n" +
+ "}";
+
+ verifyClassFile(expectedOutput, "X.class", ClassFileBytesDisassembler.SYSTEM);
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406641, [1.8][compiler][codegen] Code generation for intersection cast.
+public void test015() throws Exception {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ " void foo();\n" +
+ "}\n" +
+ "public class X {\n" +
+ " public static void main( String [] args) { \n" +
+ " I i = (I & java.io.Serializable) () -> {};\n" +
+ " }\n" +
+ "}\n",
+ },
+ "");
+
+ String expectedOutput =
+ "// Compiled from X.java (version 1.8 : 52.0, super bit)\n" +
+ "public class X {\n" +
+ " Constant pool:\n" +
+ " constant #1 class: #2 X\n" +
+ " constant #2 utf8: \"X\"\n" +
+ " constant #3 class: #4 java/lang/Object\n" +
+ " constant #4 utf8: \"java/lang/Object\"\n" +
+ " constant #5 utf8: \"<init>\"\n" +
+ " constant #6 utf8: \"()V\"\n" +
+ " constant #7 utf8: \"Code\"\n" +
+ " constant #8 method_ref: #3.#9 java/lang/Object.<init> ()V\n" +
+ " constant #9 name_and_type: #5.#6 <init> ()V\n" +
+ " constant #10 utf8: \"LineNumberTable\"\n" +
+ " constant #11 utf8: \"LocalVariableTable\"\n" +
+ " constant #12 utf8: \"this\"\n" +
+ " constant #13 utf8: \"LX;\"\n" +
+ " constant #14 utf8: \"main\"\n" +
+ " constant #15 utf8: \"([Ljava/lang/String;)V\"\n" +
+ " constant #16 name_and_type: #17.#18 lambda$ ()LI;\n" +
+ " constant #17 utf8: \"lambda$\"\n" +
+ " constant #18 utf8: \"()LI;\"\n" +
+ " constant #19 invoke dynamic: #0 #16 lambda$ ()LI;\n" +
+ " constant #20 utf8: \"args\"\n" +
+ " constant #21 utf8: \"[Ljava/lang/String;\"\n" +
+ " constant #22 utf8: \"i\"\n" +
+ " constant #23 utf8: \"LI;\"\n" +
+ " constant #24 utf8: \"lambda$0\"\n" +
+ " constant #25 utf8: \"SourceFile\"\n" +
+ " constant #26 utf8: \"X.java\"\n" +
+ " constant #27 method_ref: #28.#30 java/lang/invoke/LambdaMetafactory.metaFactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" +
+ " constant #28 class: #29 java/lang/invoke/LambdaMetafactory\n" +
+ " constant #29 utf8: \"java/lang/invoke/LambdaMetafactory\"\n" +
+ " constant #30 name_and_type: #31.#32 metaFactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" +
+ " constant #31 utf8: \"metaFactory\"\n" +
+ " constant #32 utf8: \"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\"\n" +
+ " constant #33 method handle: invokestatic (6) #27 \n" +
+ " constant #34 utf8: \"BootstrapMethods\"\n" +
+ " constant #35 interface_method_ref: #36.#38 I.foo ()V\n" +
+ " constant #36 class: #37 I\n" +
+ " constant #37 utf8: \"I\"\n" +
+ " constant #38 name_and_type: #39.#6 foo ()V\n" +
+ " constant #39 utf8: \"foo\"\n" +
+ " constant #40 method handle: invokeinterface (9) #35 \n" +
+ " constant #41 method_ref: #1.#42 X.lambda$0 ()V\n" +
+ " constant #42 name_and_type: #24.#6 lambda$0 ()V\n" +
+ " constant #43 method handle: invokestatic (6) #41 \n" +
+ " constant #44 method type: #6 ()V\n" +
+ " constant #45 utf8: \"InnerClasses\"\n" +
+ " constant #46 class: #47 java/lang/invoke/MethodHandles$Lookup\n" +
+ " constant #47 utf8: \"java/lang/invoke/MethodHandles$Lookup\"\n" +
+ " constant #48 class: #49 java/lang/invoke/MethodHandles\n" +
+ " constant #49 utf8: \"java/lang/invoke/MethodHandles\"\n" +
+ " constant #50 utf8: \"Lookup\"\n" +
+ " \n" +
+ " // Method descriptor #6 ()V\n" +
+ " // Stack: 1, Locals: 1\n" +
+ " public X();\n" +
+ " 0 aload_0 [this]\n" +
+ " 1 invokespecial java.lang.Object() [8]\n" +
+ " 4 return\n" +
+ " Line numbers:\n" +
+ " [pc: 0, line: 4]\n" +
+ " Local variable table:\n" +
+ " [pc: 0, pc: 5] local: this index: 0 type: X\n" +
+ " \n" +
+ " // Method descriptor #15 ([Ljava/lang/String;)V\n" +
+ " // Stack: 1, Locals: 2\n" +
+ " public static void main(java.lang.String[] args);\n" +
+ " 0 invokedynamic 0 lambda$() : I [19]\n" +
+ " 5 astore_1 [i]\n" +
+ " 6 return\n" +
+ " Line numbers:\n" +
+ " [pc: 0, line: 6]\n" +
+ " [pc: 6, line: 7]\n" +
+ " Local variable table:\n" +
+ " [pc: 0, pc: 7] local: args index: 0 type: java.lang.String[]\n" +
+ " [pc: 6, pc: 7] local: i index: 1 type: I\n" +
+ " \n" +
+ " // Method descriptor #6 ()V\n" +
+ " // Stack: 0, Locals: 0\n" +
+ " private static synthetic void lambda$0();\n" +
+ " 0 return\n" +
+ " Line numbers:\n" +
+ " [pc: 0, line: 6]\n" +
+ "\n" +
+ " Inner classes:\n" +
+ " [inner class info: #46 java/lang/invoke/MethodHandles$Lookup, outer class info: #48 java/lang/invoke/MethodHandles\n" +
+ " inner name: #50 Lookup, accessflags: 25 public static final]\n" +
+ "Bootstrap methods:\n" +
+ " 0 : # 33 arguments: {#40,#43,#44}\n" +
+ "}";
+
+ verifyClassFile(expectedOutput, "X.class", ClassFileBytesDisassembler.SYSTEM);
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406392, [1.8][compiler][codegen] Improve identification of lambdas that must capture enclosing instance
+public void test016() throws Exception {
+ // This test proves that when a lambda body references a type variable of an enclosing method, it can still be emitted as a static method.
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ " void doit();\n" +
+ "}\n" +
+ "public class X {\n" +
+ " <T> void foo() {\n" +
+ " class Y {\n" +
+ " T goo() {\n" +
+ " ((I) () -> {\n" +
+ " T t = null;\n" +
+ " System.out.println(\"Lambda\");\n" +
+ " }).doit();\n" +
+ " return null;\n" +
+ " }\n" +
+ " }\n" +
+ " new Y().goo();\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " new X().<String>foo(); \n" +
+ " }\n" +
+ "}\n",
+ },
+ "Lambda");
+
+ String expectedOutput =
+ "// Compiled from X.java (version 1.8 : 52.0, super bit)\n" +
+ "class X$1Y {\n" +
+ " Constant pool:\n" +
+ " constant #1 class: #2 X$1Y\n" +
+ " constant #2 utf8: \"X$1Y\"\n" +
+ " constant #3 class: #4 java/lang/Object\n" +
+ " constant #4 utf8: \"java/lang/Object\"\n" +
+ " constant #5 utf8: \"this$0\"\n" +
+ " constant #6 utf8: \"LX;\"\n" +
+ " constant #7 utf8: \"<init>\"\n" +
+ " constant #8 utf8: \"(LX;)V\"\n" +
+ " constant #9 utf8: \"Code\"\n" +
+ " constant #10 field_ref: #1.#11 X$1Y.this$0 LX;\n" +
+ " constant #11 name_and_type: #5.#6 this$0 LX;\n" +
+ " constant #12 method_ref: #3.#13 java/lang/Object.<init> ()V\n" +
+ " constant #13 name_and_type: #7.#14 <init> ()V\n" +
+ " constant #14 utf8: \"()V\"\n" +
+ " constant #15 utf8: \"LineNumberTable\"\n" +
+ " constant #16 utf8: \"LocalVariableTable\"\n" +
+ " constant #17 utf8: \"this\"\n" +
+ " constant #18 utf8: \"LX$1Y;\"\n" +
+ " constant #19 utf8: \"goo\"\n" +
+ " constant #20 utf8: \"()Ljava/lang/Object;\"\n" +
+ " constant #21 utf8: \"Signature\"\n" +
+ " constant #22 utf8: \"()TT;\"\n" +
+ " constant #23 name_and_type: #24.#25 lambda$ ()LI;\n" +
+ " constant #24 utf8: \"lambda$\"\n" +
+ " constant #25 utf8: \"()LI;\"\n" +
+ " constant #26 invoke dynamic: #0 #23 lambda$ ()LI;\n" +
+ " constant #27 interface_method_ref: #28.#30 I.doit ()V\n" +
+ " constant #28 class: #29 I\n" +
+ " constant #29 utf8: \"I\"\n" +
+ " constant #30 name_and_type: #31.#14 doit ()V\n" +
+ " constant #31 utf8: \"doit\"\n" +
+ " constant #32 utf8: \"lambda$0\"\n" +
+ " constant #33 field_ref: #34.#36 java/lang/System.out Ljava/io/PrintStream;\n" +
+ " constant #34 class: #35 java/lang/System\n" +
+ " constant #35 utf8: \"java/lang/System\"\n" +
+ " constant #36 name_and_type: #37.#38 out Ljava/io/PrintStream;\n" +
+ " constant #37 utf8: \"out\"\n" +
+ " constant #38 utf8: \"Ljava/io/PrintStream;\"\n" +
+ " constant #39 string: #40 \"Lambda\"\n" +
+ " constant #40 utf8: \"Lambda\"\n" +
+ " constant #41 method_ref: #42.#44 java/io/PrintStream.println (Ljava/lang/String;)V\n" +
+ " constant #42 class: #43 java/io/PrintStream\n" +
+ " constant #43 utf8: \"java/io/PrintStream\"\n" +
+ " constant #44 name_and_type: #45.#46 println (Ljava/lang/String;)V\n" +
+ " constant #45 utf8: \"println\"\n" +
+ " constant #46 utf8: \"(Ljava/lang/String;)V\"\n" +
+ " constant #47 utf8: \"t\"\n" +
+ " constant #48 utf8: \"Ljava/lang/Object;\"\n" +
+ " constant #49 utf8: \"LocalVariableTypeTable\"\n" +
+ " constant #50 utf8: \"TT;\"\n" +
+ " constant #51 utf8: \"SourceFile\"\n" +
+ " constant #52 utf8: \"X.java\"\n" +
+ " constant #53 utf8: \"EnclosingMethod\"\n" +
+ " constant #54 class: #55 X\n" +
+ " constant #55 utf8: \"X\"\n" +
+ " constant #56 name_and_type: #57.#14 foo ()V\n" +
+ " constant #57 utf8: \"foo\"\n" +
+ " constant #58 method_ref: #59.#61 java/lang/invoke/LambdaMetafactory.metaFactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" +
+ " constant #59 class: #60 java/lang/invoke/LambdaMetafactory\n" +
+ " constant #60 utf8: \"java/lang/invoke/LambdaMetafactory\"\n" +
+ " constant #61 name_and_type: #62.#63 metaFactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" +
+ " constant #62 utf8: \"metaFactory\"\n" +
+ " constant #63 utf8: \"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\"\n" +
+ " constant #64 method handle: invokestatic (6) #58 \n" +
+ " constant #65 utf8: \"BootstrapMethods\"\n" +
+ " constant #66 method handle: invokeinterface (9) #27 \n" +
+ " constant #67 method_ref: #1.#68 X$1Y.lambda$0 ()V\n" +
+ " constant #68 name_and_type: #32.#14 lambda$0 ()V\n" +
+ " constant #69 method handle: invokestatic (6) #67 \n" +
+ " constant #70 method type: #14 ()V\n" +
+ " constant #71 utf8: \"InnerClasses\"\n" +
+ " constant #72 utf8: \"Y\"\n" +
+ " constant #73 class: #74 java/lang/invoke/MethodHandles$Lookup\n" +
+ " constant #74 utf8: \"java/lang/invoke/MethodHandles$Lookup\"\n" +
+ " constant #75 class: #76 java/lang/invoke/MethodHandles\n" +
+ " constant #76 utf8: \"java/lang/invoke/MethodHandles\"\n" +
+ " constant #77 utf8: \"Lookup\"\n" +
+ " \n" +
+ " // Field descriptor #6 LX;\n" +
+ " final synthetic X this$0;\n" +
+ " \n" +
+ " // Method descriptor #8 (LX;)V\n" +
+ " // Stack: 2, Locals: 2\n" +
+ " X$1Y(X arg0);\n" +
+ " 0 aload_0 [this]\n" +
+ " 1 aload_1 [arg0]\n" +
+ " 2 putfield X$1Y.this$0 : X [10]\n" +
+ " 5 aload_0 [this]\n" +
+ " 6 invokespecial java.lang.Object() [12]\n" +
+ " 9 return\n" +
+ " Line numbers:\n" +
+ " [pc: 0, line: 6]\n" +
+ " Local variable table:\n" +
+ " [pc: 0, pc: 10] local: this index: 0 type: new X(){}\n" +
+ " \n" +
+ " // Method descriptor #20 ()Ljava/lang/Object;\n" +
+ " // Signature: ()TT;\n" +
+ " // Stack: 1, Locals: 1\n" +
+ " java.lang.Object goo();\n" +
+ " 0 invokedynamic 0 lambda$() : I [26]\n" +
+ " 5 invokeinterface I.doit() : void [27] [nargs: 1]\n" +
+ " 10 aconst_null\n" +
+ " 11 areturn\n" +
+ " Line numbers:\n" +
+ " [pc: 0, line: 8]\n" +
+ " [pc: 5, line: 11]\n" +
+ " [pc: 10, line: 12]\n" +
+ " Local variable table:\n" +
+ " [pc: 0, pc: 12] local: this index: 0 type: new X(){}\n" +
+ " \n" +
+ " // Method descriptor #14 ()V\n" +
+ " // Stack: 2, Locals: 1\n" +
+ " private static synthetic void lambda$0();\n" +
+ " 0 aconst_null\n" +
+ " 1 astore_0 [t]\n" +
+ " 2 getstatic java.lang.System.out : java.io.PrintStream [33]\n" +
+ " 5 ldc <String \"Lambda\"> [39]\n" +
+ " 7 invokevirtual java.io.PrintStream.println(java.lang.String) : void [41]\n" +
+ " 10 return\n" +
+ " Line numbers:\n" +
+ " [pc: 0, line: 9]\n" +
+ " [pc: 2, line: 10]\n" +
+ " [pc: 10, line: 11]\n" +
+ " Local variable table:\n" +
+ " [pc: 2, pc: 10] local: t index: 0 type: java.lang.Object\n" +
+ " Local variable type table:\n" +
+ " [pc: 2, pc: 10] local: t index: 0 type: T\n" +
+ "\n" +
+ " Inner classes:\n" +
+ " [inner class info: #1 X$1Y, outer class info: #0\n" +
+ " inner name: #72 Y, accessflags: 0 default],\n" +
+ " [inner class info: #73 java/lang/invoke/MethodHandles$Lookup, outer class info: #75 java/lang/invoke/MethodHandles\n" +
+ " inner name: #77 Lookup, accessflags: 25 public static final]\n" +
+ " Enclosing Method: #54 #56 X.foo()V\n" +
+ "Bootstrap methods:\n" +
+ " 0 : # 64 arguments: {#66,#69,#70}\n" +
+ "}";
+
+ verifyClassFile(expectedOutput, "X$1Y.class", ClassFileBytesDisassembler.SYSTEM);
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406392, [1.8][compiler][codegen] Improve identification of lambdas that must capture enclosing instance
+public void test017() throws Exception {
+ // This test proves that when a lambda body references a type variable of an enclosing class, it can still be emitted as a static method.
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ " void doit();\n" +
+ "}\n" +
+ "public class X<T> {\n" +
+ " void foo() {\n" +
+ " class Y {\n" +
+ " T goo() {\n" +
+ " ((I) () -> {\n" +
+ " T t = null;\n" +
+ " System.out.println(\"Lambda\"); \n" +
+ " }).doit();\n" +
+ " return null;\n" +
+ " }\n" +
+ " }\n" +
+ " new Y().goo();\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " new X().<String>foo(); \n" +
+ " }\n" +
+ "}\n",
+ },
+ "Lambda");
+
+ String expectedOutput =
+ "// Compiled from X.java (version 1.8 : 52.0, super bit)\n" +
+ "class X$1Y {\n" +
+ " Constant pool:\n" +
+ " constant #1 class: #2 X$1Y\n" +
+ " constant #2 utf8: \"X$1Y\"\n" +
+ " constant #3 class: #4 java/lang/Object\n" +
+ " constant #4 utf8: \"java/lang/Object\"\n" +
+ " constant #5 utf8: \"this$0\"\n" +
+ " constant #6 utf8: \"LX;\"\n" +
+ " constant #7 utf8: \"<init>\"\n" +
+ " constant #8 utf8: \"(LX;)V\"\n" +
+ " constant #9 utf8: \"Code\"\n" +
+ " constant #10 field_ref: #1.#11 X$1Y.this$0 LX;\n" +
+ " constant #11 name_and_type: #5.#6 this$0 LX;\n" +
+ " constant #12 method_ref: #3.#13 java/lang/Object.<init> ()V\n" +
+ " constant #13 name_and_type: #7.#14 <init> ()V\n" +
+ " constant #14 utf8: \"()V\"\n" +
+ " constant #15 utf8: \"LineNumberTable\"\n" +
+ " constant #16 utf8: \"LocalVariableTable\"\n" +
+ " constant #17 utf8: \"this\"\n" +
+ " constant #18 utf8: \"LX$1Y;\"\n" +
+ " constant #19 utf8: \"goo\"\n" +
+ " constant #20 utf8: \"()Ljava/lang/Object;\"\n" +
+ " constant #21 utf8: \"Signature\"\n" +
+ " constant #22 utf8: \"()TT;\"\n" +
+ " constant #23 name_and_type: #24.#25 lambda$ ()LI;\n" +
+ " constant #24 utf8: \"lambda$\"\n" +
+ " constant #25 utf8: \"()LI;\"\n" +
+ " constant #26 invoke dynamic: #0 #23 lambda$ ()LI;\n" +
+ " constant #27 interface_method_ref: #28.#30 I.doit ()V\n" +
+ " constant #28 class: #29 I\n" +
+ " constant #29 utf8: \"I\"\n" +
+ " constant #30 name_and_type: #31.#14 doit ()V\n" +
+ " constant #31 utf8: \"doit\"\n" +
+ " constant #32 utf8: \"lambda$0\"\n" +
+ " constant #33 field_ref: #34.#36 java/lang/System.out Ljava/io/PrintStream;\n" +
+ " constant #34 class: #35 java/lang/System\n" +
+ " constant #35 utf8: \"java/lang/System\"\n" +
+ " constant #36 name_and_type: #37.#38 out Ljava/io/PrintStream;\n" +
+ " constant #37 utf8: \"out\"\n" +
+ " constant #38 utf8: \"Ljava/io/PrintStream;\"\n" +
+ " constant #39 string: #40 \"Lambda\"\n" +
+ " constant #40 utf8: \"Lambda\"\n" +
+ " constant #41 method_ref: #42.#44 java/io/PrintStream.println (Ljava/lang/String;)V\n" +
+ " constant #42 class: #43 java/io/PrintStream\n" +
+ " constant #43 utf8: \"java/io/PrintStream\"\n" +
+ " constant #44 name_and_type: #45.#46 println (Ljava/lang/String;)V\n" +
+ " constant #45 utf8: \"println\"\n" +
+ " constant #46 utf8: \"(Ljava/lang/String;)V\"\n" +
+ " constant #47 utf8: \"t\"\n" +
+ " constant #48 utf8: \"Ljava/lang/Object;\"\n" +
+ " constant #49 utf8: \"LocalVariableTypeTable\"\n" +
+ " constant #50 utf8: \"TT;\"\n" +
+ " constant #51 utf8: \"SourceFile\"\n" +
+ " constant #52 utf8: \"X.java\"\n" +
+ " constant #53 utf8: \"EnclosingMethod\"\n" +
+ " constant #54 class: #55 X\n" +
+ " constant #55 utf8: \"X\"\n" +
+ " constant #56 name_and_type: #57.#14 foo ()V\n" +
+ " constant #57 utf8: \"foo\"\n" +
+ " constant #58 method_ref: #59.#61 java/lang/invoke/LambdaMetafactory.metaFactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" +
+ " constant #59 class: #60 java/lang/invoke/LambdaMetafactory\n" +
+ " constant #60 utf8: \"java/lang/invoke/LambdaMetafactory\"\n" +
+ " constant #61 name_and_type: #62.#63 metaFactory (Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\n" +
+ " constant #62 utf8: \"metaFactory\"\n" +
+ " constant #63 utf8: \"(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;\"\n" +
+ " constant #64 method handle: invokestatic (6) #58 \n" +
+ " constant #65 utf8: \"BootstrapMethods\"\n" +
+ " constant #66 method handle: invokeinterface (9) #27 \n" +
+ " constant #67 method_ref: #1.#68 X$1Y.lambda$0 ()V\n" +
+ " constant #68 name_and_type: #32.#14 lambda$0 ()V\n" +
+ " constant #69 method handle: invokestatic (6) #67 \n" +
+ " constant #70 method type: #14 ()V\n" +
+ " constant #71 utf8: \"InnerClasses\"\n" +
+ " constant #72 utf8: \"Y\"\n" +
+ " constant #73 class: #74 java/lang/invoke/MethodHandles$Lookup\n" +
+ " constant #74 utf8: \"java/lang/invoke/MethodHandles$Lookup\"\n" +
+ " constant #75 class: #76 java/lang/invoke/MethodHandles\n" +
+ " constant #76 utf8: \"java/lang/invoke/MethodHandles\"\n" +
+ " constant #77 utf8: \"Lookup\"\n" +
+ " \n" +
+ " // Field descriptor #6 LX;\n" +
+ " final synthetic X this$0;\n" +
+ " \n" +
+ " // Method descriptor #8 (LX;)V\n" +
+ " // Stack: 2, Locals: 2\n" +
+ " X$1Y(X arg0);\n" +
+ " 0 aload_0 [this]\n" +
+ " 1 aload_1 [arg0]\n" +
+ " 2 putfield X$1Y.this$0 : X [10]\n" +
+ " 5 aload_0 [this]\n" +
+ " 6 invokespecial java.lang.Object() [12]\n" +
+ " 9 return\n" +
+ " Line numbers:\n" +
+ " [pc: 0, line: 6]\n" +
+ " Local variable table:\n" +
+ " [pc: 0, pc: 10] local: this index: 0 type: new X(){}\n" +
+ " \n" +
+ " // Method descriptor #20 ()Ljava/lang/Object;\n" +
+ " // Signature: ()TT;\n" +
+ " // Stack: 1, Locals: 1\n" +
+ " java.lang.Object goo();\n" +
+ " 0 invokedynamic 0 lambda$() : I [26]\n" +
+ " 5 invokeinterface I.doit() : void [27] [nargs: 1]\n" +
+ " 10 aconst_null\n" +
+ " 11 areturn\n" +
+ " Line numbers:\n" +
+ " [pc: 0, line: 8]\n" +
+ " [pc: 5, line: 11]\n" +
+ " [pc: 10, line: 12]\n" +
+ " Local variable table:\n" +
+ " [pc: 0, pc: 12] local: this index: 0 type: new X(){}\n" +
+ " \n" +
+ " // Method descriptor #14 ()V\n" +
+ " // Stack: 2, Locals: 1\n" +
+ " private static synthetic void lambda$0();\n" +
+ " 0 aconst_null\n" +
+ " 1 astore_0 [t]\n" +
+ " 2 getstatic java.lang.System.out : java.io.PrintStream [33]\n" +
+ " 5 ldc <String \"Lambda\"> [39]\n" +
+ " 7 invokevirtual java.io.PrintStream.println(java.lang.String) : void [41]\n" +
+ " 10 return\n" +
+ " Line numbers:\n" +
+ " [pc: 0, line: 9]\n" +
+ " [pc: 2, line: 10]\n" +
+ " [pc: 10, line: 11]\n" +
+ " Local variable table:\n" +
+ " [pc: 2, pc: 10] local: t index: 0 type: java.lang.Object\n" +
+ " Local variable type table:\n" +
+ " [pc: 2, pc: 10] local: t index: 0 type: T\n" +
+ "\n" +
+ " Inner classes:\n" +
+ " [inner class info: #1 X$1Y, outer class info: #0\n" +
+ " inner name: #72 Y, accessflags: 0 default],\n" +
+ " [inner class info: #73 java/lang/invoke/MethodHandles$Lookup, outer class info: #75 java/lang/invoke/MethodHandles\n" +
+ " inner name: #77 Lookup, accessflags: 25 public static final]\n" +
+ " Enclosing Method: #54 #56 X.foo()V\n" +
+ "Bootstrap methods:\n" +
+ " 0 : # 64 arguments: {#66,#69,#70}\n" +
+ "}";
+
+ verifyClassFile(expectedOutput, "X$1Y.class", ClassFileBytesDisassembler.SYSTEM);
+}
+public static Class testClass() {
+ return Jsr335ClassFileTest.class;
+}
+}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LambdaExpressionsTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LambdaExpressionsTest.java
new file mode 100644
index 0000000..83592ff
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LambdaExpressionsTest.java
@@ -0,0 +1,1633 @@
+/*******************************************************************************
+ * Copyright (c) 2011, 2013 IBM Corporation and others.
+ * 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.core.tests.compiler.regression;
+
+import junit.framework.Test;
+public class LambdaExpressionsTest extends AbstractRegressionTest {
+
+static {
+// TESTS_NAMES = new String[] { "testSuperReference03"};
+// TESTS_NUMBERS = new int[] { 50 };
+// TESTS_RANGE = new int[] { 11, -1 };
+}
+public LambdaExpressionsTest(String name) {
+ super(name);
+}
+public static Test suite() {
+ return buildMinimalComplianceTestSuite(testClass(), F_1_8);
+}
+
+public void test001() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ " int add(int x, int y);\n" +
+ "}\n" +
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " I i = (x, y) -> {\n" +
+ " return x + y;\n" +
+ " };\n" +
+ " System.out.println(i.add(1234, 5678));\n" +
+ " }\n" +
+ "}\n",
+ },
+ "6912"
+ );
+}
+public void test002() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "interface Greetings {\n" +
+ " void greet(String head, String tail);\n" +
+ "}\n" +
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " Greetings g = (x, y) -> {\n" +
+ " System.out.println(x + y);\n" +
+ " };\n" +
+ " g.greet(\"Hello, \", \"World!\");\n" +
+ " }\n" +
+ "}\n",
+ },
+ "Hello, World!"
+ );
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406178, [1.8][compiler] Some functional interfaces are wrongly rejected
+public void test003() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ " void foo(int x, int y);\n" +
+ "}\n" +
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " BinaryOperator<String> binOp = (x,y) -> { return x+y; };\n" +
+ " System.out.println(\"SUCCESS\");\n" +
+ " // System.out.println(binOp.apply(\"SUCC\", \"ESS\")); // when lambdas run\n" +
+ " }\n" +
+ "}\n",
+ "BiFunction.java",
+ "@FunctionalInterface\n" +
+ "public interface BiFunction<T, U, R> {\n" +
+ " R apply(T t, U u);\n" +
+ "}",
+ "BinaryOperator.java",
+ "@FunctionalInterface\n" +
+ "public interface BinaryOperator<T> extends BiFunction<T,T,T> {\n" +
+ "}"
+ },
+ "SUCCESS");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406178, [1.8][compiler] Some functional interfaces are wrongly rejected
+public void test004() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ " void foo(int x, int y);\n" +
+ "}\n" +
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " BinaryOperator binOp = (x,y) -> { return x+y; };\n" +
+ " System.out.println(\"SUCCESS\");\n" +
+ " // System.out.println(binOp.apply(\"SUCC\", \"ESS\")); // when lambdas run\n" +
+ " }\n" +
+ "}\n",
+ "BiFunction.java",
+ "@FunctionalInterface\n" +
+ "public interface BiFunction<T, U, R> {\n" +
+ " R apply(T t, U u);\n" +
+ "}",
+ "BinaryOperator.java",
+ "@FunctionalInterface\n" +
+ "public interface BinaryOperator<T> extends BiFunction<T,T,T> {\n" +
+ "}"
+ },
+ "----------\n" +
+ "1. WARNING in X.java (at line 6)\n" +
+ " BinaryOperator binOp = (x,y) -> { return x+y; };\n" +
+ " ^^^^^^^^^^^^^^\n" +
+ "BinaryOperator is a raw type. References to generic type BinaryOperator<T> should be parameterized\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 6)\n" +
+ " BinaryOperator binOp = (x,y) -> { return x+y; };\n" +
+ " ^^^\n" +
+ "The operator + is undefined for the argument type(s) java.lang.Object, java.lang.Object\n" +
+ "----------\n");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406175, [1.8][compiler][codegen] Generate code for lambdas with expression body.
+public void test005() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ " String id(String s);\n" +
+ "}\n" +
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " I i = (s) -> s;\n" +
+ " System.out.println(i.id(\"Hello\"));\n" +
+ " }\n" +
+ "}\n"
+ },
+ "Hello");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406175, [1.8][compiler][codegen] Generate code for lambdas with expression body.
+public void test006() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ " String id(String s);\n" +
+ "}\n" +
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " I i = (s) -> s + s;\n" +
+ " System.out.println(i.id(\"Hello\"));\n" +
+ " }\n" +
+ "}\n"
+ },
+ "HelloHello");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406175, [1.8][compiler][codegen] Generate code for lambdas with expression body.
+public void test007() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ " void print(String s);\n" +
+ "}\n" +
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " I i = (s) -> System.out.println(s);\n" +
+ " i.print(\"Hello\");\n" +
+ " }\n" +
+ "}\n"
+ },
+ "Hello");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406175, [1.8][compiler][codegen] Generate code for lambdas with expression body.
+public void test008() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ " String print(String s);\n" +
+ "}\n" +
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " I i = (s) -> new String(s).toUpperCase();\n" +
+ " System.out.println(i.print(\"Hello\"));\n" +
+ " }\n" +
+ "}\n"
+ },
+ "HELLO");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406175, [1.8][compiler][codegen] Generate code for lambdas with expression body.
+public void test009() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ " String print(String s);\n" +
+ "}\n" +
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " I i = (s) -> new String(s);\n" +
+ " System.out.println(i.print(\"Hello\"));\n" +
+ " }\n" +
+ "}\n"
+ },
+ "Hello");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406175, [1.8][compiler][codegen] Generate code for lambdas with expression body.
+public void test010() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ " int unbox(Integer i);\n" +
+ "}\n" +
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " I i = (s) -> s;\n" +
+ " System.out.println(i.unbox(new Integer(1234)));\n" +
+ " }\n" +
+ "}\n"
+ },
+ "1234");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406175, [1.8][compiler][codegen] Generate code for lambdas with expression body.
+public void test011() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ " Integer box(int i);\n" +
+ "}\n" +
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " I i = (s) -> s;\n" +
+ " System.out.println(i.box(1234));\n" +
+ " }\n" +
+ "}\n"
+ },
+ "1234");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406175, [1.8][compiler][codegen] Generate code for lambdas with expression body.
+public void test012() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ " X subType();\n" +
+ "}\n" +
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " I i = () -> new Y();\n" +
+ " System.out.println(i.subType());\n" +
+ " }\n" +
+ "}\n" +
+ "class Y extends X {\n" +
+ " public String toString() {\n" +
+ " return \"Some Y\";\n" +
+ " }\n" +
+ "}"
+ },
+ "Some Y");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406175, [1.8][compiler][codegen] Generate code for lambdas with expression body.
+public void test013() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ " void foo(String s);\n" +
+ "}\n" +
+ "public class X {\n" +
+ " public static void main(String [] args) {\n" +
+ " int in = 12345678;\n" +
+ " I i = (s) -> {\n" +
+ " I j = (s2) -> {\n" +
+ " System.out.println(s + s2 + in); \n" +
+ " };\n" +
+ " j.foo(\"Number=\");\n" +
+ " };\n" +
+ " i.foo(\"The \");\n" +
+ " }\n" +
+ "}\n"
+ },
+ "The Number=12345678");
+}
+public void test014() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ " void doit();\n" +
+ "}\n" +
+ "public class X {\n" +
+ " public static void nonmain(String[] args) {\n" +
+ " int var = 2;\n" +
+ " I x2 = () -> {\n" +
+ " System.out.println(\"Argc = \" + args.length);\n" +
+ " for (int i = 0; i < args.length; i++) {\n" +
+ " System.out.println(\"Argv[\" + i + \"] = \" + args[i]);\n" +
+ " }\n" +
+ " };\n" +
+ " x2.doit();\n" +
+ " var=2;\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " nonmain(new String[] {\"Hello! \", \"World!\" });\n" +
+ " }\n" +
+ "}" ,
+ },
+ "Argc = 2\n" +
+ "Argv[0] = Hello! \n" +
+ "Argv[1] = World!");
+}
+public void test015() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ " void doit();\n" +
+ "}\n" +
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " try {\n" +
+ " new java.io.File((String) null).getCanonicalPath();\n" +
+ " } catch (NullPointerException | java.io.IOException ioe) {\n" +
+ " I x2 = () -> {\n" +
+ " System.out.println(ioe.getMessage()); // OK: args is not re-assignment since declaration/first assignment\n" +
+ " };\n" +
+ " x2.doit();\n" +
+ " };\n"+
+ " }\n" +
+ "}\n"
+ },
+ "null");
+}
+public void test016() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ " void doit();\n" +
+ "}\n" +
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " java.util.List<String> list = new java.util.ArrayList<>();\n" +
+ " list.add(\"SomeString\");\n" +
+ " for (String s : list) {\n" +
+ " I x2 = () -> {\n" +
+ " System.out.println(s); // OK: args is not re-assignment since declaration/first assignment\n" +
+ " };\n" +
+ " x2.doit();\n" +
+ " };\n" +
+ " }\n" +
+ "\n" +
+ "}\n" ,
+ },
+ "SomeString");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406181, [1.8][compiler][codegen] IncompatibleClassChangeError when running code with lambda method
+public void test017() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ " void foo(int x, int y);\n" +
+ "}\n" +
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " BinaryOperator<String> binOp = (x,y) -> { return x+y; }; \n" +
+ " System.out.println(binOp.apply(\"SUCC\", \"ESS\")); // when lambdas run\n" +
+ " }\n" +
+ "}\n" +
+ "@FunctionalInterface\n" +
+ "interface BiFunction<T, U, R> { \n" +
+ " R apply(T t, U u);\n" +
+ "}\n" +
+ "@FunctionalInterface \n" +
+ "interface BinaryOperator<T> extends BiFunction<T,T,T> { \n" +
+ "}\n",
+ },
+ "SUCCESS");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=405071, [1.8][compiler][codegen] Generate code for array constructor references
+public void test018() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ " X [][][] copy (short x);\n" +
+ "}\n" +
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " I i = X[][][]::new;\n" +
+ " I j = X[][][]::new;\n" +
+ " X[][][] x = i.copy((short) 631);\n" +
+ " System.out.println(x.length);\n" +
+ " x = j.copy((short) 136);\n" +
+ " System.out.println(x.length);\n" +
+ " }\n" +
+ "}\n",
+ },
+ "631\n" +
+ "136");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=405071, [1.8][compiler][codegen] Generate code for array constructor references
+public void test019() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ " X [][][] copy (int x);\n" +
+ "}\n" +
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " I i = X[][][]::new;\n" +
+ " I j = X[][][]::new;\n" +
+ " X[][][] x = i.copy(631);\n" +
+ " System.out.println(x.length);\n" +
+ " x = j.copy(136);\n" +
+ " System.out.println(x.length);\n" +
+ " }\n" +
+ "}\n",
+ },
+ "631\n" +
+ "136");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=405071, [1.8][compiler][codegen] Generate code for array constructor references
+public void test020() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ " X [][][] copy (Integer x);\n" +
+ "}\n" +
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " I i = X[][][]::new;\n" +
+ " I j = X[][][]::new;\n" +
+ " X[][][] x = i.copy(631);\n" +
+ " System.out.println(x.length);\n" +
+ " x = j.copy(136);\n" +
+ " System.out.println(x.length);\n" +
+ " }\n" +
+ "}\n",
+ },
+ "631\n" +
+ "136");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=405071, [1.8][compiler][codegen] Generate code for array constructor references
+public void test021() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ " X [][][] copy (Integer x);\n" +
+ "}\n" +
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " I i = X[][][]::new;\n" +
+ " I j = X[][][]::new;\n" +
+ " X[][][] x = i.copy(new Integer(631));\n" +
+ " System.out.println(x.length);\n" +
+ " x = j.copy(new Integer((short)136));\n" +
+ " System.out.println(x.length);\n" +
+ " }\n" +
+ "}\n",
+ },
+ "631\n" +
+ "136");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406388, [1.8][compiler][codegen] Runtime evaluation of method reference produces "BootstrapMethodError: call site initialization exception"
+public void test022() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ " Object copy(int [] ia);\n" +
+ "}\n" +
+ "interface J {\n" +
+ " int [] copy(int [] ia);\n" +
+ "}\n" +
+ "public class X {\n" +
+ " public static void main(String [] args) {\n" +
+ " I i = int[]::<String>clone;\n" +
+ " int [] x = new int [] { 10, 20, 30 };\n" +
+ " int [] y = (int []) i.copy(x);\n" +
+ " if (x == y || x.length != y.length || x[0] != y[0] || x[1] != y[1] || x[2] != y[2]) {\n" +
+ " System.out.println(\"Broken\");\n" +
+ " } else {\n" +
+ " System.out.println(\"OK\");\n" +
+ " }\n" +
+ " J j = int []::clone;\n" +
+ " y = null;\n" +
+ " y = j.copy(x);\n" +
+ " if (x == y || x.length != y.length || x[0] != y[0] || x[1] != y[1] || x[2] != y[2]) {\n" +
+ " System.out.println(\"Broken\");\n" +
+ " } else {\n" +
+ " System.out.println(\"OK\");\n" +
+ " }\n" +
+ " }\n" +
+ "}\n" ,
+ },
+ "OK\n" +
+ "OK");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406388, [1.8][compiler][codegen] Runtime evaluation of method reference produces "BootstrapMethodError: call site initialization exception"
+public void test023() {
+this.runConformTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ " Object copy(int [] ia);\n" +
+ "}\n" +
+ "\n" +
+ "public class X {\n" +
+ " public static void main(String [] args) {\n" +
+ " I i = int[]::<String>clone;\n" +
+ " int [] ia = (int []) i.copy(new int[10]);\n" +
+ " System.out.println(ia.length);\n" +
+ " }\n" +
+ "}\n",
+ },
+ "10");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406388, [1.8][compiler][codegen] Runtime evaluation of method reference produces "BootstrapMethodError: call site initialization exception"
+public void test024() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ " YBase copy(Y ia);\n" +
+ "}\n" +
+ "public class X {\n" +
+ " public static void main(String [] args) {\n" +
+ " I i = Y::<String>copy;\n" +
+ " YBase yb = i.copy(new Y());\n" +
+ " System.out.println(yb.getClass());\n" +
+ " }\n" +
+ "}\n" +
+ "class YBase {\n" +
+ " public YBase copy() {\n" +
+ " return this;\n" +
+ " }\n" +
+ "}\n" +
+ "class Y extends YBase {\n" +
+ "}\n",
+ },
+ "class Y");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406388, [1.8][compiler][codegen] Runtime evaluation of method reference produces "BootstrapMethodError: call site initialization exception"
+public void test025() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ " int foo(int [] ia);\n" +
+ "}\n" +
+ "public class X {\n" +
+ " public static void main(String [] args) {\n" +
+ " I i = int[]::<String>hashCode;\n" +
+ " i.foo(new int[10]);\n" +
+ " }\n" +
+ "}\n",
+ },
+ "");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406589, [1.8][compiler][codegen] super call misdispatched
+public void test026() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ " Integer foo(int x, int y);\n" +
+ "}\n" +
+ "class Y {\n" +
+ " int foo(int x, int y) {\n" +
+ " System.out.println(\"Y.foo(\" + x + \",\" + y + \")\");\n" +
+ " return foo(x, y);\n" +
+ " }\n" +
+ "}\n" +
+ "public class X extends Y {\n" +
+ " int foo(int x, int y) {\n" +
+ " System.out.println(\"X.foo(\" + x + \",\" + y + \")\");\n" +
+ " return x + y;\n" +
+ " }\n" +
+ " void goo() {\n" +
+ " I i = super::foo;\n" +
+ " System.out.println(i.foo(1234, 4321));\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " new X().goo();\n" +
+ " }\n" +
+ "}\n",
+ },
+ "Y.foo(1234,4321)\n" +
+ "X.foo(1234,4321)\n" +
+ "5555");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406589, [1.8][compiler][codegen] super call misdispatched
+public void test027() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ " int foo(int x, int y);\n" +
+ "}\n" +
+ "interface J {\n" +
+ " default int foo(int x, int y) {\n" +
+ " System.out.println(\"I.foo(\" + x + \",\" + y + \")\");\n" +
+ " return x + y;\n" +
+ " }\n" +
+ "}\n" +
+ "public class X implements J {\n" +
+ " public static void main(String[] args) {\n" +
+ " I i = new X().f();\n" +
+ " System.out.println(i.foo(1234, 4321));\n" +
+ " i = new X().g();\n" +
+ " try {\n" +
+ " System.out.println(i.foo(1234, 4321));\n" +
+ " } catch (Throwable e) {\n" +
+ " System.out.println(e.getMessage());\n" +
+ " }\n" +
+ " }\n" +
+ " I f() {\n" +
+ " return J.super::foo;\n" +
+ " }\n" +
+ " I g() {\n" +
+ " return new X()::foo;\n" +
+ " }\n" +
+ " public int foo(int x, int y) {\n" +
+ " throw new RuntimeException(\"Exception\");\n" +
+ " }\n" +
+ "}\n",
+ },
+ "I.foo(1234,4321)\n" +
+ "5555\n" +
+ "Exception");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406584, Bug 406584 - [1.8][compiler][codegen] ClassFormatError: Invalid method signature
+public void test028() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ " Object copy();\n" +
+ "}\n" +
+ "public class X {\n" +
+ " public static void main(String [] args) {\n" +
+ " int [] x = new int[] { 0xdeadbeef, 0xfeedface };\n" +
+ " I i = x::<String>clone;\n" +
+ " System.out.println(Integer.toHexString(((int []) i.copy())[0]));\n" +
+ " System.out.println(Integer.toHexString(((int []) i.copy())[1]));\n" +
+ " }\n" +
+ "}\n",
+ },
+ "deadbeef\n" +
+ "feedface");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406588, [1.8][compiler][codegen] java.lang.invoke.LambdaConversionException: Incorrect number of parameters for static method newinvokespecial
+public void test029() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ " X.Y.Z makexyz(int val);\n" +
+ "}\n" +
+ "public class X {\n" +
+ " public static void main(String args []) {\n" +
+ " new X().new Y().new Z().new P().goo();\n" +
+ " }\n" +
+ " class Y {\n" +
+ " class Z {\n" +
+ " Z(int val) {\n" +
+ " System.out.println(Integer.toHexString(val));\n" +
+ " } \n" +
+ " Z() {\n" +
+ " }\n" +
+ " class P {\n" +
+ " void goo() {\n" +
+ " I i = Z::new;\n" +
+ " i.makexyz(0xdeadbeef);\n" +
+ " }\n" +
+ " I i = Z::new;\n" +
+ " { i.makexyz(0xfeedface); }\n" +
+ " }\n" +
+ " }\n" +
+ " I i = Z::new;\n" +
+ " { i.makexyz(0xbeeffeed); }\n" +
+ " }\n" +
+ "}\n",
+ },
+ "beeffeed\n" +
+ "feedface\n" +
+ "deadbeef");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406588, [1.8][compiler][codegen] java.lang.invoke.LambdaConversionException: Incorrect number of parameters for static method newinvokespecial
+public void test030() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ " X.Y makeY();\n" +
+ "}\n" +
+ "public class X {\n" +
+ " public class Y {\n" +
+ " public String toString() {\n" +
+ " return \"class Y\";\n" +
+ " }\n" +
+ " }\n" +
+ " void foo() {\n" +
+ " I i = Y::new;\n" +
+ " System.out.println(i.makeY());\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " new X().foo();\n" +
+ " }\n" +
+ "}\n",
+ },
+ "class Y");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406588, [1.8][compiler][codegen] java.lang.invoke.LambdaConversionException: Incorrect number of parameters for static method newinvokespecial
+public void test031() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ " X.Y makeY(int x);\n" +
+ "}\n" +
+ "public class X {\n" +
+ " class Y {\n" +
+ " String state; \n" +
+ " Y(int x) {\n" +
+ " state = Integer.toHexString(x);\n" +
+ " }\n" +
+ " public String toString() {\n" +
+ " return state;\n" +
+ " }\n" +
+ " }\n" +
+ " class Z extends Y {\n" +
+ " Z(int x) {\n" +
+ " super(x);\n" +
+ " }\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " new X().f();\n" +
+ " }\n" +
+ " void f() {\n" +
+ " I i = Y::new;\n" +
+ " System.out.println(i.makeY(0xdeadbeef));\n" +
+ " }\n" +
+ "}\n",
+ },
+ "deadbeef");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406588, [1.8][compiler][codegen] java.lang.invoke.LambdaConversionException: Incorrect number of parameters for static method newinvokespecial
+public void test032() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ " X.Y makeY(int x);\n" +
+ "}\n" +
+ "public class X {\n" +
+ " class Y {\n" +
+ " String state; \n" +
+ " Y(int x) {\n" +
+ " state = Integer.toHexString(x);\n" +
+ " }\n" +
+ " public String toString() {\n" +
+ " return state;\n" +
+ " }\n" +
+ " }\n" +
+ " class Z extends Y {\n" +
+ " Z(int x) {\n" +
+ " super(x);\n" +
+ " }\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " new X().f();\n" +
+ " }\n" +
+ " void f() {\n" +
+ " I i = Z::new;\n" +
+ " System.out.println(i.makeY(0xdeadbeef));\n" +
+ " }\n" +
+ "}\n",
+ },
+ "deadbeef");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406588, [1.8][compiler][codegen] java.lang.invoke.LambdaConversionException: Incorrect number of parameters for static method newinvokespecial
+public void test033() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ " X.Y.Z makeY(int x);\n" +
+ "}\n" +
+ "public class X {\n" +
+ " class Y {\n" +
+ " Y() {\n" +
+ " }\n" +
+ " class Z {\n" +
+ " String state;\n" +
+ " Z(int x) {\n" +
+ " state = Integer.toHexString(x);\n" +
+ " }\n" +
+ " public String toString() {\n" +
+ " return state;\n" +
+ " }\n" +
+ " }\n" +
+ " }\n" +
+ " class YS extends Y {\n" +
+ " YS() {\n" +
+ " }\n" +
+ " void f() {\n" +
+ " I i = Z::new;\n" +
+ " System.out.println(i.makeY(0xbeefface));\n" +
+ " }\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " new X().new YS().f();\n" +
+ " }\n" +
+ "}\n",
+ },
+ "beefface");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406319, [1.8][compiler][codegen] Generate code for enclosing instance capture in lambda methods.
+public void test034() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ " int foo();\n" +
+ "}\n" +
+ "public class X {\n" +
+ " int f = 1234;\n" +
+ " void foo() {\n" +
+ " int x = 4321;\n" +
+ " I i = () -> x + f;\n" +
+ " System.out.println(i.foo());\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " new X().foo();\n" +
+ " }\n" +
+ "}\n",
+ },
+ "5555");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406319, [1.8][compiler][codegen] Generate code for enclosing instance capture in lambda methods.
+public void test035() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ " void foo(int p, int q);\n" +
+ "}\n" +
+ "public class X {\n" +
+ " int f;\n" +
+ " void foo(int outerp) {\n" +
+ " int locouter;\n" +
+ " I i = (int p, int q) -> {\n" +
+ " class Local {\n" +
+ " void foo() {\n" +
+ " }\n" +
+ " };\n" +
+ " new Local();\n" +
+ " };\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(\"OK\");\n" +
+ " }\n" +
+ "}\n",
+ },
+ "OK");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406319, [1.8][compiler][codegen] Generate code for enclosing instance capture in lambda methods.
+public void test036() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ " String foo(String x, String y);\n" +
+ "}\n" +
+ "public class X {\n" +
+ " String xf = \"Lambda \";\n" +
+ " String x() {\n" +
+ " String xl = \"code \";\n" +
+ " class Y {\n" +
+ " String yf = \"generation \";\n" +
+ " String y () {\n" +
+ " String yl = \"with \";\n" +
+ " class Z {\n" +
+ " String zf = \"instance \";\n" +
+ " String z () {\n" +
+ " String zl = \"and \";\n" +
+ " class P {\n" +
+ " String pf = \"local \";\n" +
+ " String p () {\n" +
+ " String pl = \"capture \";\n" +
+ " I i = (x1, y1) -> {\n" +
+ " return (((I) ((x2, y2) -> {\n" +
+ " return ( ((I) ((x3, y3) -> {\n" +
+ " return xf + xl + yf + yl + zf + zl + pf + pl + x3 + y3;\n" +
+ " })).foo(\"works \", \"fine \") + x2 + y2);\n" +
+ " })).foo(\"in \", \"the \") + x1 + y1);\n" +
+ " };\n" +
+ " return i.foo(\"eclipse \", \"compiler \");\n" +
+ " }\n" +
+ " }\n" +
+ " return new P().p();\n" +
+ " }\n" +
+ " }\n" +
+ " return new Z().z();\n" +
+ " }\n" +
+ " }\n" +
+ " return new Y().y();\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(new X().x());\n" +
+ " }\n" +
+ "}\n",
+ },
+ "Lambda code generation with instance and local capture works fine in the eclipse compiler");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406319, [1.8][compiler][codegen] Generate code for enclosing instance capture in lambda methods.
+public void test037() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ " String foo(String x, String y);\n" +
+ "}\n" +
+ "public class X {\n" +
+ " String xf = \"Lambda \";\n" +
+ " String x() {\n" +
+ " String xl = \"code \";\n" +
+ " class Y {\n" +
+ " String yf = \"generation \";\n" +
+ " String y () {\n" +
+ " String yl = \"with \";\n" +
+ " class Z {\n" +
+ " String zf = \"instance \";\n" +
+ " String z () {\n" +
+ " String zl = \"and \";\n" +
+ " class P {\n" +
+ " String pf = \"local \";\n" +
+ " String p () {\n" +
+ " String pl = \"capture \";\n" +
+ " I i = (x1, y1) -> {\n" +
+ " return (((I) ((x2, y2) -> {\n" +
+ " return ( ((I) ((x3, y3) -> {\n" +
+ " String exclaim = \"!\";\n" +
+ " return xf + xl + yf + yl + zf + zl + pf + pl + x3 + y3 + x2 + y2 + x1 + y1 + exclaim;\n" +
+ " })).foo(\"works \", \"fine \"));\n" +
+ " })).foo(\"in \", \"the \"));\n" +
+ " };\n" +
+ " return i.foo(\"eclipse \", \"compiler \");\n" +
+ " }\n" +
+ " }\n" +
+ " return new P().p();\n" +
+ " }\n" +
+ " }\n" +
+ " return new Z().z();\n" +
+ " }\n" +
+ " }\n" +
+ " return new Y().y();\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(new X().x());\n" +
+ " }\n" +
+ "}\n",
+ },
+ "Lambda code generation with instance and local capture works fine in the eclipse compiler !");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406641, [1.8][compiler][codegen] Code generation for intersection cast.
+public void test038() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ "}\n" +
+ "interface J {\n" +
+ "}\n" +
+ "public class X implements I, J {\n" +
+ " public static void main( String [] args) { \n" +
+ " f(new X());\n" +
+ " }\n" +
+ " static void f(Object o) {\n" +
+ " X x = (X & I & J) o;\n" +
+ " System.out.println(\"OK\");\n" +
+ " }\n" +
+ "}\n",
+ },
+ "OK");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406641, [1.8][compiler][codegen] Code generation for intersection cast.
+public void test039() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ "}\n" +
+ "interface J {\n" +
+ "}\n" +
+ "public class X implements J {\n" +
+ " public static void main( String [] args) { \n" +
+ " f(new X());\n" +
+ " }\n" +
+ " static void f(Object o) {\n" +
+ " try {\n" +
+ " X x = (X & I & J) o;\n" +
+ " } catch (ClassCastException e) {\n" +
+ " System.out.println(e.getMessage());\n" +
+ " }\n" +
+ " }\n" +
+ "}\n",
+ },
+ "X cannot be cast to I");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406744, [1.8][compiler][codegen] LambdaConversionException seen when method reference targets a varargs method
+public void _test040() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ " void foo(Integer a1, Integer a2, String a3);\n" +
+ "}\n" +
+ "class Y {\n" +
+ " static void m(Number a1, Object... rest) { \n" +
+ " System.out.println(a1);\n" +
+ " print(rest);\n" +
+ " }\n" +
+ " static void print (Object [] o) {\n" +
+ " for (int i = 0; i < o.length; i++)\n" +
+ " System.out.println(o[i]);\n" +
+ " }\n" +
+ "}\n" +
+ "public class X {\n" +
+ " public static void main(String [] args) {\n" +
+ " I i = Y::m;\n" +
+ " i.foo(10, 20, \"10, 20\");\n" +
+ " }\n" +
+ "}\n",
+ },
+ "X cannot be cast to I");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406773, [1.8][compiler][codegen] "java.lang.IncompatibleClassChangeError" caused by attempted invocation of private constructor
+public void test041() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ " X makeX(int x);\n" +
+ "}\n" +
+ "public class X {\n" +
+ " class Z {\n" +
+ " void f() {\n" +
+ " I i = X::new;\n" +
+ " i.makeX(123456);\n" +
+ " }\n" +
+ " }\n" +
+ " private X(int x) {\n" +
+ " System.out.println(x);\n" +
+ " }\n" +
+ " X() {\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " new X().new Z().f();\n" +
+ " }\n" +
+ "}\n",
+ },
+ "123456");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406773, [1.8][compiler][codegen] "java.lang.IncompatibleClassChangeError" caused by attempted invocation of private constructor
+public void test042() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ " X makeX(int x);\n" +
+ "}\n" +
+ "public class X {\n" +
+ " class Y extends X {\n" +
+ " class Z {\n" +
+ " void f() {\n" +
+ " I i = X::new;\n" +
+ " i.makeX(123456);\n" +
+ " i = Y::new;\n" +
+ " i.makeX(987654);\n" +
+ " }\n" +
+ " }\n" +
+ " private Y(int y) {\n" +
+ " System.out.println(\"Y(\" + y + \")\");\n" +
+ " }\n" +
+ " private Y() {\n" +
+ " \n" +
+ " }\n" +
+ " }\n" +
+ " private X(int x) {\n" +
+ " System.out.println(\"X(\" + x + \")\");\n" +
+ " }\n" +
+ "\n" +
+ " X() {\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " new X().new Y().new Z().f();\n" +
+ " }\n" +
+ "\n" +
+ "}\n",
+ },
+ "X(123456)\n" +
+ "Y(987654)");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406773, [1.8][compiler][codegen] "java.lang.IncompatibleClassChangeError" caused by attempted invocation of private constructor
+public void test043() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ " X makeX(int x);\n" +
+ "}\n" +
+ "public class X {\n" +
+ " class Y extends X {\n" +
+ " class Z extends X {\n" +
+ " void f() {\n" +
+ " I i = X::new;\n" +
+ " i.makeX(123456);\n" +
+ " i = Y::new;\n" +
+ " i.makeX(987654);\n" +
+ " i = Z::new;\n" +
+ " i.makeX(456789);\n" +
+ " }\n" +
+ " private Z(int z) {\n" +
+ " System.out.println(\"Z(\" + z + \")\");\n" +
+ " }\n" +
+ " Z() {\n" +
+ " }\n" +
+ " }\n" +
+ " private Y(int y) {\n" +
+ " System.out.println(\"Y(\" + y + \")\");\n" +
+ " }\n" +
+ " private Y() {\n" +
+ " \n" +
+ " }\n" +
+ " }\n" +
+ " private X(int x) {\n" +
+ " System.out.println(\"X(\" + x + \")\");\n" +
+ " }\n" +
+ "\n" +
+ " X() {\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " new X().new Y().new Z().f();\n" +
+ " }\n" +
+ "\n" +
+ "}\n",
+ },
+ "X(123456)\n" +
+ "Y(987654)\n" +
+ "Z(456789)");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406773, [1.8][compiler][codegen] "java.lang.IncompatibleClassChangeError" caused by attempted invocation of private constructor
+public void test044() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ " X makeX(int x);\n" +
+ "}\n" +
+ "public class X {\n" +
+ " void foo() {\n" +
+ " int local;\n" +
+ " class Y extends X {\n" +
+ " class Z extends X {\n" +
+ " void f() {\n" +
+ " I i = X::new;\n" +
+ " i.makeX(123456);\n" +
+ " i = Y::new;\n" +
+ " i.makeX(987654);\n" +
+ " i = Z::new;\n" +
+ " i.makeX(456789);\n" +
+ " }\n" +
+ " private Z(int z) {\n" +
+ " System.out.println(\"Z(\" + z + \")\");\n" +
+ " }\n" +
+ " Z() {}\n" +
+ " }\n" +
+ " private Y(int y) {\n" +
+ " System.out.println(\"Y(\" + y + \")\");\n" +
+ " }\n" +
+ " private Y() {\n" +
+ " }\n" +
+ " }\n" +
+ " new Y().new Z().f();\n" +
+ " }\n" +
+ " private X(int x) {\n" +
+ " System.out.println(\"X(\" + x + \")\");\n" +
+ " }\n" +
+ "\n" +
+ " X() {\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " new X().foo();\n" +
+ " }\n" +
+ "}\n",
+ },
+ "X(123456)\n" +
+ "Y(987654)\n" +
+ "Z(456789)");
+}
+public void test045() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ " X makeX(int x);\n" +
+ "}\n" +
+ "public class X {\n" +
+ " I i = (x) -> {\n" +
+ " class Y extends X {\n" +
+ " private Y (int y) {\n" +
+ " System.out.println(y);\n" +
+ " }\n" +
+ " Y() {\n" +
+ " }\n" +
+ " void f() {\n" +
+ " I i = X::new;\n" +
+ " i.makeX(123456);\n" +
+ " i = X.Y::new;\n" +
+ " i.makeX(987654);\n" +
+ " }\n" +
+ " }\n" +
+ " return null; \n" +
+ " };\n" +
+ " private X(int x) {\n" +
+ " System.out.println(x);\n" +
+ " }\n" +
+ " X() {\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " new X().new Y().f();\n" +
+ " }\n" +
+ "}\n",
+ },
+ "----------\n" +
+ "1. WARNING in X.java (at line 6)\n" +
+ " class Y extends X {\n" +
+ " ^\n" +
+ "The type Y is never used locally\n" +
+ "----------\n" +
+ "2. WARNING in X.java (at line 7)\n" +
+ " private Y (int y) {\n" +
+ " ^^^^^^^^^\n" +
+ "The constructor Y(int) is never used locally\n" +
+ "----------\n" +
+ "3. WARNING in X.java (at line 10)\n" +
+ " Y() {\n" +
+ " ^^^\n" +
+ "The constructor Y() is never used locally\n" +
+ "----------\n" +
+ "4. WARNING in X.java (at line 13)\n" +
+ " I i = X::new;\n" +
+ " ^\n" +
+ "The local variable i is hiding a field from type X\n" +
+ "----------\n" +
+ "5. ERROR in X.java (at line 15)\n" +
+ " i = X.Y::new;\n" +
+ " ^\n" +
+ "Y cannot be resolved or is not a field\n" +
+ "----------\n" +
+ "6. ERROR in X.java (at line 27)\n" +
+ " new X().new Y().f();\n" +
+ " ^\n" +
+ "X.Y cannot be resolved to a type\n" +
+ "----------\n");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406760, [1.8][compiler][codegen] "VerifyError: Bad type on operand stack" with qualified super method references
+public void test046() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ " String doit();\n" +
+ "}\n" +
+ "public class X extends B {\n" +
+ " class Y {\n" +
+ " class Z {\n" +
+ " void f() {\n" +
+ " \n" +
+ " I i = X.super::toString; // Verify error\n" +
+ " System.out.println(i.doit());\n" +
+ " i = X.this::toString; // This call gets dispatched OK.\n" +
+ " System.out.println(i.doit());\n" +
+ " }\n" +
+ " }\n" +
+ " }\n" +
+ " \n" +
+ " public static void main(String[] args) {\n" +
+ " new X().new Y().new Z().f(); \n" +
+ " }\n" +
+ " \n" +
+ " public String toString() {\n" +
+ " return \"X's toString\";\n" +
+ " }\n" +
+ "}\n" +
+ "class B {\n" +
+ " public String toString() {\n" +
+ " return \"B's toString\";\n" +
+ " }\n" +
+ "}\n",
+ },
+ "B\'s toString\n" +
+ "X\'s toString");
+}
+public void test047() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ " void foo(int x, int y);\n" +
+ "}\n" +
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " long lng = 1234;\n" +
+ " double d = 1234.5678;\n" +
+ " I i = (x, y) -> {\n" +
+ " System.out.println(\"long = \" + lng);\n" +
+ " System.out.println(\"args length = \" + args.length);\n" +
+ " System.out.println(\"double = \" + d);\n" +
+ " System.out.println(\"x = \" + x);\n" +
+ " System.out.println(\"y = \" + y);\n" +
+ " };\n" +
+ " i.foo(9876, 4321);\n" +
+ " }\n" +
+ "}\n",
+ },
+ "long = 1234\n" +
+ "args length = 0\n" +
+ "double = 1234.5678\n" +
+ "x = 9876\n" +
+ "y = 4321");
+}
+public void test048() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "interface I<T, J> {\n" +
+ " void foo(T x, J y);\n" +
+ "}\n" +
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " long lng = 1234;\n" +
+ " double d = 1234.5678;\n" +
+ " I<Object, Object> i = (x, y) -> {\n" +
+ " System.out.println(\"long = \" + lng);\n" +
+ " System.out.println(\"args length = \" + args.length);\n" +
+ " System.out.println(\"double = \" + d);\n" +
+ " System.out.println(\"x = \" + x);\n" +
+ " System.out.println(\"y = \" + y);\n" +
+ " };\n" +
+ " i.foo(9876, 4321);\n" +
+ " \n" +
+ " I<String, String> i2 = (x, y) -> {\n" +
+ " System.out.println(x);\n" +
+ " System.out.println(y);\n" +
+ " };\n" +
+ " i2.foo(\"Hello !\", \"World\");\n" +
+ " }\n" +
+ "}\n",
+ },
+ "long = 1234\n" +
+ "args length = 0\n" +
+ "double = 1234.5678\n" +
+ "x = 9876\n" +
+ "y = 4321\n" +
+ "Hello !\n" +
+ "World");
+}
+public void test049() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "interface I<T, J> {\n" +
+ " void foo(X x, T t, J j);\n" +
+ "}\n" +
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " I<String, String> i = X::foo;\n" +
+ " i.foo(new X(), \"Hello\", \"World!\");\n" +
+ " }\n" +
+ " void foo(String s, String t) {\n" +
+ " System.out.println(s);\n" +
+ " System.out.println(t);\n" +
+ " }\n" +
+ "}\n",
+ },
+ "Hello\n" +
+ "World!");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406773, [1.8][compiler][codegen] "java.lang.IncompatibleClassChangeError" caused by attempted invocation of private constructor
+public void test050() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ " void foo(int x, int y);\n" +
+ "}\n" +
+ "public class X {\n" +
+ " static private void add(int x, int y) {\n" +
+ " System.out.println(x + y);\n" +
+ " }\n" +
+ " private void multiply(int x, int y) {\n" +
+ " System.out.println(x * y);\n" +
+ " }\n" +
+ " static class Y {\n" +
+ " static private void subtract(int x, int y) {\n" +
+ " System.out.println(x - y);\n" +
+ " }\n" +
+ " private void divide (int x, int y) {\n" +
+ " System.out.println(x / y);\n" +
+ " }\n" +
+ " static void doy() {\n" +
+ " I i = X::add;\n" +
+ " i.foo(1234, 12);\n" +
+ " i = new X()::multiply;\n" +
+ " i.foo(12, 20);\n" +
+ " i = Y::subtract;\n" +
+ " i.foo(123, 13);\n" +
+ " i = new Y()::divide;\n" +
+ " i.foo(99, 9);\n" +
+ " }\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " I i = X::add;\n" +
+ " i.foo(1234, 12);\n" +
+ " i = new X()::multiply;\n" +
+ " i.foo(12, 20);\n" +
+ " i = Y::subtract;\n" +
+ " i.foo(123, 13);\n" +
+ " i = new Y()::divide;\n" +
+ " i.foo(99, 9);\n" +
+ " Y.subtract(10, 7);\n" +
+ " Y.doy();\n" +
+ " }\n" +
+ "}\n",
+ },
+ "1246\n" +
+ "240\n" +
+ "110\n" +
+ "11\n" +
+ "3\n" +
+ "1246\n" +
+ "240\n" +
+ "110\n" +
+ "11");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406773, [1.8][compiler][codegen] "java.lang.IncompatibleClassChangeError" caused by attempted invocation of private constructor
+public void test051() {
+ this.runConformTest(
+ new String[] {
+ "p2/B.java",
+ "package p2;\n" +
+ "import p1.*; \n" +
+ "interface I {\n" +
+ " void foo();\n" +
+ "}\n" +
+ "interface J {\n" +
+ " void foo();\n" +
+ "}\n" +
+ "public class B extends A {\n" +
+ " class Y {\n" +
+ " void g() {\n" +
+ " I i = B::foo;\n" +
+ " i.foo();\n" +
+ " J j = new B()::goo;\n" +
+ " j.foo();\n" +
+ " }\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " new B().new Y().g();\n" +
+ " }\n" +
+ "}\n",
+ "p1/A.java",
+ "package p1;\n" +
+ "import p2.*;\n" +
+ "public class A {\n" +
+ " protected static void foo() {\n" +
+ " System.out.println(\"A's static foo\");\n" +
+ " }\n" +
+ " protected void goo() {\n" +
+ " System.out.println(\"A's instance goo\");\n" +
+ " }\n" +
+ "}"
+ },
+ "A\'s static foo\n" +
+ "A\'s instance goo");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406773, [1.8][compiler][codegen] "java.lang.IncompatibleClassChangeError" caused by attempted invocation of private constructor
+public void test052() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ " void foo(int x);\n" +
+ "}\n" +
+ "public class X {\n" +
+ " void foo() {\n" +
+ " int local = 10;\n" +
+ " class Y {\n" +
+ " void foo(int x) {\n" +
+ " System.out.println(local);\n" +
+ " }\n" +
+ " void goo() {\n" +
+ " I i = this::foo;\n" +
+ " i.foo(10);\n" +
+ " }\n" +
+ " }\n" +
+ " new Y().goo();\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " new X().foo();\n" +
+ " }\n" +
+ "}\n"
+ },
+ "10");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406847, [1.8] lambda code compiles but then produces IncompatibleClassChangeError when run
+public void test053() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "import java.util.*;\n" +
+ "public class X {\n" +
+ " public static <E> void printItem(E value, int index) {\n" +
+ " String output = String.format(\"%d -> %s\", index, value);\n" +
+ " System.out.println(output);\n" +
+ " }\n" +
+ " public static void main(String[] argv) {\n" +
+ " List<String> list = Arrays.asList(\"A\",\"B\",\"C\");\n" +
+ " eachWithIndex(list,X::printItem);\n" +
+ " }\n" +
+ " interface ItemWithIndexVisitor<E> {\n" +
+ " public void visit(E item, int index);\n" +
+ " }\n" +
+ " public static <E> void eachWithIndex(List<E> list, ItemWithIndexVisitor<E> visitor) {\n" +
+ " for (int i = 0; i < list.size(); i++) {\n" +
+ " visitor.visit(list.get(i), i);\n" +
+ " }\n" +
+ " }\n" +
+ "}\n"
+ },
+ "0 -> A\n" +
+ "1 -> B\n" +
+ "2 -> C");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406847, [1.8] lambda code compiles but then produces IncompatibleClassChangeError when run
+public void test054() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "import java.util.*;\n" +
+ "public class X {\n" +
+ " public static <E> void printItem(E value) {}\n" +
+ " public static void main(String[] argv) {\n" +
+ " List<String> list = null;\n" +
+ " eachWithIndex(list, X::printItem);\n" +
+ " }\n" +
+ " interface ItemWithIndexVisitor<E> {\n" +
+ " public void visit(E item);\n" +
+ " }\n" +
+ " public static <E> void eachWithIndex(List<E> list, ItemWithIndexVisitor<E> visitor) {}\n" +
+ "}\n"
+ },
+ "");
+}
+public void test055() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ " void foo(int i);\n" +
+ "}\n" +
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " X x = null;\n" +
+ " I i = x::foo;\n" +
+ " }\n" +
+ " int foo(int x) {\n" +
+ " return x;\n" +
+ " }\n" +
+ "}\n"
+ },
+ "");
+}
+public void test056() {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ " void foo(int i);\n" +
+ "}\n" +
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " X x = null;\n" +
+ " I i = x::foo;\n" +
+ " try {\n" +
+ " i.foo(10);\n" +
+ " } catch (NullPointerException npe) {\n" +
+ " System.out.println(npe.getMessage());\n" +
+ " }\n" +
+ " }\n" +
+ " int foo(int x) {\n" +
+ " return x;\n" +
+ " }\n" +
+ "}\n"
+ },
+ "null");
+}
+public static Class testClass() {
+ return LambdaExpressionsTest.class;
+}
+}
\ No newline at end of file
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NegativeLambdaExpressionsTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NegativeLambdaExpressionsTest.java
index f5fc426..d00f07a 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NegativeLambdaExpressionsTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NegativeLambdaExpressionsTest.java
@@ -1815,12 +1815,7 @@
" }\n" +
"}" ,
},
- "----------\n" +
- "1. ERROR in X.java (at line 8)\n" +
- " System.out.println(args); // OK: args is not re-assignment since declaration/first assignment\n" +
- " ^^^^\n" +
- "Missing code implementation in the compiler\n" + // expected since emulation path computation is not in place.
- "----------\n");
+ "");
}
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382721, [1.8][compiler] Effectively final variables needs special treatment
public void test050() {
@@ -1843,12 +1838,7 @@
" }\n" +
"}\n"
},
- "----------\n" +
- "1. ERROR in X.java (at line 10)\n" +
- " System.out.println(ioe.getMessage()); // OK: args is not re-assignment since declaration/first assignment\n" +
- " ^^^\n" +
- "Missing code implementation in the compiler\n" + // expected since emulation path computation is not in place.
- "----------\n");
+ "");
}
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382721, [1.8][compiler] Effectively final variables needs special treatment
public void test051() {
@@ -1871,12 +1861,7 @@
"\n" +
"}\n" ,
},
- "----------\n" +
- "1. ERROR in X.java (at line 9)\n" +
- " System.out.println(s); // OK: args is not re-assignment since declaration/first assignment\n" +
- " ^\n" +
- "Missing code implementation in the compiler\n" + // expected since emulation path computation is not in place.
- "----------\n");
+ "");
}
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382721, [1.8][compiler] Effectively final variables needs special treatment
public void test052() {
@@ -1928,12 +1913,7 @@
" }\n" +
"}\n" ,
},
- "----------\n" +
- "1. ERROR in X.java (at line 10)\n" +
- " System.out.println(e);\n" +
- " ^\n" +
- "Missing code implementation in the compiler\n" +
- "----------\n");
+ "");
}
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382721, [1.8][compiler] Effectively final variables needs special treatment
public void test054() {
@@ -2105,12 +2085,7 @@
" }\n" +
"}\n",
},
- "----------\n" +
- "1. ERROR in X.java (at line 8)\n" +
- " System.out.println(is);\n" +
- " ^^\n" +
- "Missing code implementation in the compiler\n" + // expected.
- "----------\n");
+ "");
}
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=382721, [1.8][compiler] Effectively final variables needs special treatment
public void test061() {
@@ -4204,7 +4179,12 @@
" X<?> foo(int x, String p) { return null; }\n" +
"}\n"
},
- "");
+ "----------\n" +
+ "1. WARNING in X.java (at line 5)\n" +
+ " I i = super::foo;\n" +
+ " ^^^^^^^^^^\n" +
+ "Access to enclosing method foo(int, String) from the type Y is emulated by a synthetic accessor method\n" +
+ "----------\n");
}
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=384750, [1.8] Compiler should reject invalid method reference expressions
public void test384750k() {
@@ -4247,7 +4227,12 @@
" }\n" +
"}\n"
},
- "");
+ "----------\n" +
+ "1. WARNING in X.java (at line 9)\n" +
+ " I i = X.super::zoo;\n" +
+ " ^^^^^^^^^^^^\n" +
+ "Access to enclosing method zoo() from the type Z is emulated by a synthetic accessor method\n" +
+ "----------\n");
}
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=384750, [1.8] Compiler should reject invalid method reference expressions
public void test384750m() {
@@ -5064,9 +5049,8 @@
"----------\n" +
"1. ERROR in X.java (at line 20)\n" +
" new X().foo((s)->{});\n" +
- " ^^^\n" +
- "The method foo(I) in the type X is not applicable for the arguments ((<no type> s) -> {\n" +
- "})\n" +
+ " ^^^^^^^\n" +
+ "Lambda expression\'s signature does not match the signature of the functional interface method\n" +
"----------\n");
}
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=401610, [1.8][compiler] Allow lambda/reference expressions in non-overloaded method invocation contexts
@@ -5102,28 +5086,23 @@
"----------\n" +
"1. ERROR in X.java (at line 15)\n" +
" new X().foo(()->{ return \"\";});\n" +
- " ^^^\n" +
- "The method foo(I) in the type X is not applicable for the arguments (() -> {\n" +
- " return \"\";\n" +
- "})\n" +
+ " ^^^^^^^^^^\n" +
+ "Void methods cannot return a value\n" +
"----------\n" +
"2. ERROR in X.java (at line 16)\n" +
" new X().foo(()-> 10);\n" +
- " ^^^\n" +
- "The method foo(I) in the type X is not applicable for the arguments (() -> 10)\n" +
+ " ^^\n" +
+ "Void methods cannot return a value\n" +
"----------\n" +
"3. ERROR in X.java (at line 17)\n" +
" new X().foo((s)->{});\n" +
- " ^^^\n" +
- "The method foo(I) in the type X is not applicable for the arguments ((<no type> s) -> {\n" +
- "})\n" +
+ " ^^^^^^^\n" +
+ "Lambda expression\'s signature does not match the signature of the functional interface method\n" +
"----------\n" +
"4. ERROR in X.java (at line 18)\n" +
" new X().foo((s)->{ return;});\n" +
- " ^^^\n" +
- "The method foo(I) in the type X is not applicable for the arguments ((<no type> s) -> {\n" +
- " return ;\n" +
- "})\n" +
+ " ^^^^^^^^^^^^^^^\n" +
+ "Lambda expression\'s signature does not match the signature of the functional interface method\n" +
"----------\n");
}
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=401610, [1.8][compiler] Allow lambda/reference expressions in non-overloaded method invocation contexts
@@ -5166,9 +5145,8 @@
"----------\n" +
"3. ERROR in X.java (at line 7)\n" +
" new X().foo(()->{});\n" +
- " ^^^\n" +
- "The method foo(I<T>) in the type X is not applicable for the arguments (() -> {\n" +
- "})\n" +
+ " ^^^^^^\n" +
+ "The target type of this expression is not a well formed parameterized type due to bound(s) mismatch\n" +
"----------\n");
}
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=401610, [1.8][compiler] Allow lambda/reference expressions in non-overloaded method invocation contexts
@@ -5231,10 +5209,8 @@
"----------\n" +
"1. ERROR in X.java (at line 11)\n" +
" new X().foo(()->{ return 10; });\n" +
- " ^^^\n" +
- "The method foo(I) in the type X is not applicable for the arguments (() -> {\n" +
- " return 10;\n" +
- "})\n" +
+ " ^^^^^^^^^^\n" +
+ "Void methods cannot return a value\n" +
"----------\n");
}
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=401610, [1.8][compiler] Allow lambda/reference expressions in non-overloaded method invocation contexts
@@ -5282,9 +5258,8 @@
"----------\n" +
"1. ERROR in X.java (at line 11)\n" +
" new X().foo((Object o)->{});\n" +
- " ^^^\n" +
- "The method foo(I) in the type X is not applicable for the arguments ((Object o) -> {\n" +
- "})\n" +
+ " ^^^^^^\n" +
+ "Lambda expression\'s parameter o is expected to be of type int\n" +
"----------\n");
}
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=401789, [1.8][compiler] Enable support for method/constructor references in non-overloaded method calls.
@@ -5375,60 +5350,45 @@
"----------\n" +
"1. ERROR in X.java (at line 9)\n" +
" this(X::goo);\n" +
- " ^^^^^^^^^^^^^\n" +
- "The constructor X.Y(X::goo) is undefined\n" +
+ " ^^^^^^\n" +
+ "The type of goo() from the type X is int, this is incompatible with the descriptor\'s return type: String\n" +
"----------\n" +
"2. ERROR in X.java (at line 14)\n" +
" this((x) -> { return 10;});\n" +
- " ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
- "The constructor X((<no type> x) -> {\n" +
- " return 10;\n" +
- "}) is undefined\n" +
+ " ^^\n" +
+ "Type mismatch: cannot convert from int to String\n" +
"----------\n" +
"3. ERROR in X.java (at line 18)\n" +
" foo(X::goo);\n" +
- " ^^^\n" +
- "The method foo(I) in the type X is not applicable for the arguments (X::goo)\n" +
+ " ^^^^^^\n" +
+ "The type of goo() from the type X is int, this is incompatible with the descriptor\'s return type: String\n" +
"----------\n" +
"4. ERROR in X.java (at line 19)\n" +
" new X((x)->{ return 10;});\n" +
- " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
- "The constructor X((<no type> x) -> {\n" +
- " return 10;\n" +
- "}) is undefined\n" +
+ " ^^\n" +
+ "Type mismatch: cannot convert from int to String\n" +
"----------\n" +
"5. ERROR in X.java (at line 20)\n" +
" new X((x)->{ return 10;}).new Y((x) -> { return 0;});\n" +
- " ^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
- "The constructor X((<no type> x) -> {\n" +
- " return 10;\n" +
- "}) is undefined\n" +
+ " ^^\n" +
+ "Type mismatch: cannot convert from int to String\n" +
"----------\n" +
- "6. ERROR in X.java (at line 20)\n" +
- " new X((x)->{ return 10;}).new Y((x) -> { return 0;});\n" +
- " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
- "The constructor X.Y((<no type> x) -> {\n" +
- " return 0;\n" +
- "}) is undefined\n" +
- "----------\n" +
- "7. ERROR in X.java (at line 21)\n" +
+ "6. ERROR in X.java (at line 21)\n" +
" new X((x)->{ return 10;}) {};\n" +
- " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
- "The constructor X((<no type> x) -> {\n" +
- " return 10;\n" +
- "}) is undefined\n" +
+ " ^^\n" +
+ "Type mismatch: cannot convert from int to String\n" +
"----------\n" +
- "8. ERROR in X.java (at line 26)\n" +
+ "7. ERROR in X.java (at line 26)\n" +
" super(X::goo);\n" +
- " ^^^^^^^^^^^^^^\n" +
- "The constructor X(X::goo) is undefined\n" +
+ " ^^^^^^\n" +
+ "The type of goo() from the type X is int, this is incompatible with the descriptor\'s return type: String\n" +
"----------\n" +
- "9. ERROR in X.java (at line 29)\n" +
+ "8. ERROR in X.java (at line 29)\n" +
" super (x -> 10);\n" +
- " ^^^^^^^^^^^^^^^^\n" +
- "The constructor X((<no type> x) -> 10) is undefined\n" +
+ " ^^\n" +
+ "Type mismatch: cannot convert from int to String\n" +
"----------\n" +
- "10. ERROR in X.java (at line 31)\n" +
+ "9. ERROR in X.java (at line 31)\n" +
" Zork z;\n" +
" ^^^^\n" +
"Zork cannot be resolved to a type\n" +
@@ -5478,15 +5438,13 @@
"----------\n" +
"1. ERROR in X.java (at line 8)\n" +
" foo(X::goo);\n" +
- " ^^^\n" +
- "The method foo(I[]...) in the type X is not applicable for the arguments (X::goo)\n" +
+ " ^^^^^^\n" +
+ "The target type of this expression must be a functional interface\n" +
"----------\n" +
"2. ERROR in X.java (at line 9)\n" +
" foo((x)-> {return 10;});\n" +
- " ^^^\n" +
- "The method foo(I[]...) in the type X is not applicable for the arguments ((<no type> x) -> {\n" +
- " return 10;\n" +
- "})\n" +
+ " ^^^^^^^^^^^^^^^^^^\n" +
+ "The target type of this expression must be a functional interface\n" +
"----------\n");
}
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=401845, [1.8][compiler] Bad interaction between varargs and lambas/references
@@ -5642,13 +5600,28 @@
"----------\n" +
"1. ERROR in X.java (at line 8)\n" +
" foo(true ? X::goo : X::goo);\n" +
- " ^^^\n" +
- "The method foo(I...) in the type X is not applicable for the arguments ((true ? X::goo : X::goo))\n" +
+ " ^^^^^^\n" +
+ "The type of goo() from the type X is int, this is incompatible with the descriptor\'s return type: String\n" +
"----------\n" +
- "2. ERROR in X.java (at line 9)\n" +
+ "2. ERROR in X.java (at line 8)\n" +
+ " foo(true ? X::goo : X::goo);\n" +
+ " ^^^^^^\n" +
+ "The type of goo() from the type X is int, this is incompatible with the descriptor\'s return type: String\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 9)\n" +
" foo(true ? x-> 1 : x->0);\n" +
" ^^^\n" +
"The method foo(I...) in the type X is not applicable for the arguments ((true ? (<no type> x) -> 1 : (<no type> x) -> 0))\n" +
+ "----------\n" +
+ "4. ERROR in X.java (at line 9)\n" +
+ " foo(true ? x-> 1 : x->0);\n" +
+ " ^\n" +
+ "Type mismatch: cannot convert from int to String\n" +
+ "----------\n" +
+ "5. ERROR in X.java (at line 9)\n" +
+ " foo(true ? x-> 1 : x->0);\n" +
+ " ^\n" +
+ "Type mismatch: cannot convert from int to String\n" +
"----------\n");
}
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=401939, [1.8][compiler] Incorrect shape analysis leads to method resolution failure .
@@ -5782,11 +5755,8 @@
"----------\n" +
"1. ERROR in X.java (at line 8)\n" +
" goo((x) -> { if (x) return null; });\n" +
- " ^^^\n" +
- "The method goo(I) in the type X is not applicable for the arguments ((<no type> x) -> {\n" +
- " if (x)\n" +
- " return null;\n" +
- "})\n" +
+ " ^\n" +
+ "Type mismatch: cannot convert from String to boolean\n" +
"----------\n" +
"2. ERROR in X.java (at line 9)\n" +
" goo((x) -> {});\n" +
@@ -5835,10 +5805,8 @@
"----------\n" +
"1. ERROR in X.java (at line 8)\n" +
" goo((x) -> { return null; });\n" +
- " ^^^\n" +
- "The method goo(I) in the type X is not applicable for the arguments ((<no type> x) -> {\n" +
- " return null;\n" +
- "})\n" +
+ " ^^^^^^^^^^^^\n" +
+ "Void methods cannot return a value\n" +
"----------\n");
}
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=401939, [1.8][compiler] Incorrect shape analysis leads to method resolution failure .
@@ -6124,11 +6092,6 @@
"----------\n" +
"1. ERROR in X.java (at line 18)\n" +
" f(super::foo);\n" +
- " ^\n" +
- "The method f(I) in the type X is not applicable for the arguments (super::foo)\n" +
- "----------\n" +
- "2. ERROR in X.java (at line 18)\n" +
- " f(super::foo);\n" +
" ^^^^^\n" +
"Cannot use super in a static context\n" +
"----------\n");
@@ -6202,6 +6165,11 @@
" f(super::foo);\n" +
" ^\n" +
"The method f(I) is ambiguous for the type X\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 18)\n" +
+ " f(super::foo);\n" +
+ " ^^^^^^^^^^\n" +
+ "Cannot directly invoke the abstract method foo() for the type Y\n" +
"----------\n");
}
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=402609, [1.8][compiler] AIOOB exception with a program using method references.
@@ -6362,6 +6330,210 @@
"y cannot be resolved to a type\n" +
"----------\n");
}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406614, [1.8][compiler] Missing and incorrect errors for lambda in explicit constructor call.
+public void test406614() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ " int doit();\n" +
+ "}\n" +
+ "public class X {\n" +
+ " int f;\n" +
+ " X(I i) {\n" +
+ " }\n" +
+ " X() {\n" +
+ " this(() -> this.f);\n" +
+ " }\n" +
+ " X(short s) {\n" +
+ " this(() -> this.g());\n" +
+ " }\n" +
+ " X (int x) {\n" +
+ " this(() -> f);\n" +
+ " }\n" +
+ " X (long x) {\n" +
+ " this(() -> g());\n" +
+ " }\n" +
+ " int g() {\n" +
+ " return 0;\n" +
+ " }\n" +
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 9)\n" +
+ " this(() -> this.f);\n" +
+ " ^^^^\n" +
+ "Cannot refer to \'this\' nor \'super\' while explicitly invoking a constructor\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 12)\n" +
+ " this(() -> this.g());\n" +
+ " ^^^^\n" +
+ "Cannot refer to \'this\' nor \'super\' while explicitly invoking a constructor\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 15)\n" +
+ " this(() -> f);\n" +
+ " ^\n" +
+ "Cannot refer to an instance field f while explicitly invoking a constructor\n" +
+ "----------\n" +
+ "4. ERROR in X.java (at line 18)\n" +
+ " this(() -> g());\n" +
+ " ^\n" +
+ "Cannot refer to an instance method while explicitly invoking a constructor\n" +
+ "----------\n");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406588, [1.8][compiler][codegen] java.lang.invoke.LambdaConversionException: Incorrect number of parameters for static method newinvokespecial
+public void test406588() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ " X.Y.Z makeY(int x);\n" +
+ "}\n" +
+ "public class X {\n" +
+ " class Y {\n" +
+ " Y(I i) {\n" +
+ " \n" +
+ " }\n" +
+ " Y() {\n" +
+ " this(Z::new);\n" +
+ " }\n" +
+ " class Z {\n" +
+ " Z(int x) {\n" +
+ "\n" +
+ " }\n" +
+ " }\n" +
+ " }\n" +
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 10)\n" +
+ " this(Z::new);\n" +
+ " ^^^^^^^\n" +
+ "No enclosing instance of the type X.Y is accessible in scope\n" +
+ "----------\n");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406586, [1.8][compiler] Missing error about unavailable enclosing instance
+public void test406586() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ " X.Y makeY();\n" +
+ "}\n" +
+ "public class X {\n" +
+ " public class Y {\n" +
+ " }\n" +
+ " static void foo() {\n" +
+ " I i = Y::new;\n" +
+ " }\n" +
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 8)\n" +
+ " I i = Y::new;\n" +
+ " ^^^^^^^\n" +
+ "No enclosing instance of the type X is accessible in scope\n" +
+ "----------\n");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=401989, [1.8][compiler] hook lambda expressions into "can be static" analysis
+public void test401989() {
+ Map compilerOptions = getCompilerOptions();
+ compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR);
+ compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR);
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ " void make();\n" +
+ "}\n" +
+ "public class X {\n" +
+ " int val;\n" +
+ " private I test() {\n" +
+ " return () -> System.out.println(val);\n" +
+ " }\n" +
+ " private I testCanBeStatic() {\n" +
+ " return () -> System.out.println();\n" +
+ " }\n" +
+ " public void call() { test().make(); testCanBeStatic().make();}\n" +
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 9)\n" +
+ " private I testCanBeStatic() {\n" +
+ " ^^^^^^^^^^^^^^^^^\n" +
+ "The method testCanBeStatic() from the type X can be declared as static\n" +
+ "----------\n",
+ null /* no extra class libraries */,
+ true /* flush output directory */,
+ compilerOptions /* custom options */
+ );
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406773, [1.8][compiler][codegen] "java.lang.IncompatibleClassChangeError" caused by attempted invocation of private constructor
+public void test406773() {
+ Map compilerOptions = getCompilerOptions();
+ compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR);
+ compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR);
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "interface I {\n" +
+ " X makeX(int x);\n" +
+ "}\n" +
+ "public class X {\n" +
+ " void foo() {\n" +
+ " int local = 10;\n" +
+ " class Y extends X {\n" +
+ " class Z extends X {\n" +
+ " void f() {\n" +
+ " I i = X::new;\n" +
+ " i.makeX(123456);\n" +
+ " i = Y::new;\n" +
+ " i.makeX(987654);\n" +
+ " i = Z::new;\n" +
+ " i.makeX(456789);\n" +
+ " }\n" +
+ " private Z(int z) {\n" +
+ " }\n" +
+ " Z() {}\n" +
+ " }\n" +
+ " private Y(int y) {\n" +
+ " System.out.println(local);\n" +
+ " }\n" +
+ " private Y() {\n" +
+ " }\n" +
+ " }\n" +
+ " new Y().new Z().f();\n" +
+ " }\n" +
+ " private X(int x) {\n" +
+ " }\n" +
+ " X() {\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " new X().foo();\n" +
+ " }\n" +
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 5)\n" +
+ " void foo() {\n" +
+ " ^^^^^\n" +
+ "The method foo() from the type X can potentially be declared as static\n" +
+ "----------\n" +
+ "2. WARNING in X.java (at line 10)\n" +
+ " I i = X::new;\n" +
+ " ^^^^^^^\n" +
+ "Access to enclosing constructor X(int) is emulated by a synthetic accessor method\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 12)\n" +
+ " i = Y::new;\n" +
+ " ^^^^^^^\n" +
+ "No enclosing instance of the type X is accessible in scope\n" +
+ "----------\n",
+ null /* no extra class libraries */,
+ true /* flush output directory */,
+ compilerOptions /* custom options */
+ );
+}
public static Class testClass() {
return NegativeLambdaExpressionsTest.class;
}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ProblemTypeAndMethodTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ProblemTypeAndMethodTest.java
index 5ef1b36..d2c0f2f 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ProblemTypeAndMethodTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ProblemTypeAndMethodTest.java
@@ -8374,4 +8374,97 @@
"}\n"
);
}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406396, Method can be static analysis misses a bunch of cases...
+public void test406396() {
+ Map compilerOptions = getCompilerOptions();
+ compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR);
+ compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR);
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " int f;\n" +
+ " void foo() {\n" +
+ " class Y {\n" +
+ " int p;\n" +
+ " {\n" +
+ " class Z {\n" +
+ " int f = p;\n" +
+ " }\n" +
+ " }\n" +
+ " };\n" +
+ " }\n" +
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 3)\n" +
+ " void foo() {\n" +
+ " ^^^^^\n" +
+ "The method foo() from the type X can potentially be declared as static\n" +
+ "----------\n" +
+ "2. WARNING in X.java (at line 4)\n" +
+ " class Y {\n" +
+ " ^\n" +
+ "The type Y is never used locally\n" +
+ "----------\n" +
+ "3. WARNING in X.java (at line 7)\n" +
+ " class Z {\n" +
+ " ^\n" +
+ "The type Z is never used locally\n" +
+ "----------\n" +
+ "4. WARNING in X.java (at line 8)\n" +
+ " int f = p;\n" +
+ " ^\n" +
+ "The field Z.f is hiding a field from type X\n" +
+ "----------\n" +
+ "5. WARNING in X.java (at line 8)\n" +
+ " int f = p;\n" +
+ " ^\n" +
+ "The value of the field Z.f is not used\n" +
+ "----------\n",
+ null /* no extra class libraries */,
+ true /* flush output directory */,
+ compilerOptions /* custom options */
+ );
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=406396, Method can be static analysis misses a bunch of cases...
+public void test406396a() {
+ Map compilerOptions = getCompilerOptions();
+ compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBeStatic, CompilerOptions.ERROR);
+ compilerOptions.put(CompilerOptions.OPTION_ReportMethodCanBePotentiallyStatic, CompilerOptions.ERROR);
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " int f;\n" +
+ " int foo() {\n" +
+ " int f = 0;\n" +
+ " return f;\n" +
+ " }\n" +
+ " int goo() {\n" +
+ " return 0;\n" +
+ " }\n" +
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 3)\n" +
+ " int foo() {\n" +
+ " ^^^^^\n" +
+ "The method foo() from the type X can potentially be declared as static\n" +
+ "----------\n" +
+ "2. WARNING in X.java (at line 4)\n" +
+ " int f = 0;\n" +
+ " ^\n" +
+ "The local variable f is hiding a field from type X\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 7)\n" +
+ " int goo() {\n" +
+ " ^^^^^\n" +
+ "The method goo() from the type X can potentially be declared as static\n" +
+ "----------\n",
+ null /* no extra class libraries */,
+ true /* flush output directory */,
+ compilerOptions /* custom options */
+ );
+}
}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TestAll.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TestAll.java
index 52fdaa0..7bd6d2c 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TestAll.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TestAll.java
@@ -15,6 +15,8 @@
* Stephan Herrmann - Contributions for
* bug 186342 - [compiler][null] Using annotations for null checking
* bug 358903 - Filter practically unimportant resource leak warnings
+ * Andy Clement - Contributions for
+ * Bug 383624 - [1.8][compiler] Revive code generation support for type annotations (from Olivier's work)
*******************************************************************************/
package org.eclipse.jdt.core.tests.compiler.regression;
@@ -132,10 +134,13 @@
since_1_8.add(NegativeTypeAnnotationTest.class);
since_1_8.add(NullTypeAnnotationTest.class);
since_1_8.add(NegativeLambdaExpressionsTest.class);
+ since_1_8.add(LambdaExpressionsTest.class);
+ since_1_8.add(Jsr335ClassFileTest.class);
since_1_8.add(ExpressionContextTests.class);
since_1_8.add(InterfaceMethodsTest.class);
since_1_8.add(GrammarCoverageTests308.class);
since_1_8.add(FlowAnalysisTest8.class);
+ since_1_8.add(TypeAnnotationTest.class);
// Build final test suite
TestSuite all = new TestSuite(TestAll.class.getName());
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TypeAnnotationTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TypeAnnotationTest.java
new file mode 100644
index 0000000..0443b26
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TypeAnnotationTest.java
@@ -0,0 +1,2292 @@
+/*******************************************************************************
+ * Copyright (c) 2011, 2012 IBM Corporation and others.
+ * 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.core.tests.compiler.regression;
+
+import java.io.File;
+
+import org.eclipse.jdt.core.util.ClassFileBytesDisassembler;
+
+import junit.framework.Test;
+
+public class TypeAnnotationTest extends AbstractRegressionTest {
+
+ static {
+// TESTS_NUMBERS = new int [] { 40 };
+ }
+ public static Class testClass() {
+ return TypeAnnotationTest.class;
+ }
+ public static Test suite() {
+ return buildMinimalComplianceTestSuite(testClass(), F_1_8);
+ }
+ public TypeAnnotationTest(String testName){
+ super(testName);
+ }
+// // superclass
+// public void test001() throws Exception {
+// this.runConformTest(
+// new String[] {
+// "Marker.java",
+// "import java.lang.annotation.Target;\n" +
+// "import static java.lang.annotation.ElementType.*;\n" +
+// "@Target(TYPE_USE)\n" +
+// "@interface Marker {}",
+// "X.java",
+// "public class X extends @Marker Object {}",
+// },
+// "");
+// String expectedOutput =
+// " RuntimeInvisibleTypeAnnotations: \n" +
+// " #17 @Marker(\n" +
+// " target type = 0x14 CLASS_EXTENDS_IMPLEMENTS\n" +
+// " type index = -1\n" +
+// " )\n";
+// checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM);
+// }
+// // type parameter
+// public void test002() throws Exception {
+// this.runConformTest(
+// new String[] {
+// "Marker.java",
+// "import java.lang.annotation.Target;\n" +
+// "import static java.lang.annotation.ElementType.*;\n" +
+// "@Target(TYPE_PARAMETER)\n" +
+// "@interface Marker {}",
+// "X.java",
+// "public class X<@Marker T> {}",
+// },
+// "");
+// String expectedOutput =
+// " RuntimeInvisibleTypeAnnotations: \n" +
+// " #21 @Marker(\n" +
+// " target type = 0x22 CLASS_TYPE_PARAMETER\n" +
+// " type parameter index = 0\n" +
+// " )\n";
+// checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM);
+// }
+// // superclass
+// public void test003() throws Exception {
+// this.runConformTest(
+// new String[] {
+// "A.java",
+// "import java.lang.annotation.Target;\n" +
+// "import static java.lang.annotation.ElementType.*;\n" +
+// "import java.lang.annotation.Retention;\n" +
+// "import static java.lang.annotation.RetentionPolicy.*;\n" +
+// "@Target(TYPE_USE)\n" +
+// "@Retention(RUNTIME)\n" +
+// "@interface A {\n" +
+// " String id() default \"default\";\n" +
+// "}\n",
+// "B.java",
+// "import java.lang.annotation.Target;\n" +
+// "import static java.lang.annotation.ElementType.*;\n" +
+// "import java.lang.annotation.Retention;\n" +
+// "import static java.lang.annotation.RetentionPolicy.*;\n" +
+// "@Target(TYPE_USE)\n" +
+// "@Retention(CLASS)\n" +
+// "@interface B {\n" +
+// " int value() default -1;\n" +
+// "}",
+// "C.java",
+// "import java.lang.annotation.Target;\n" +
+// "import static java.lang.annotation.ElementType.*;\n" +
+// "import java.lang.annotation.Retention;\n" +
+// "import static java.lang.annotation.RetentionPolicy.*;\n" +
+// "@Target(TYPE_USE)\n" +
+// "@Retention(RUNTIME)\n" +
+// "@interface C {\n" +
+// " char value() default '-';\n" +
+// "}\n",
+// "Y.java",
+// "class Y {}\n",
+// "X.java",
+// "public class X extends @A(id=\"Hello, World!\") @B @C('(') Y {\n" +
+// "}",
+// },
+// "");
+// String expectedOutput =
+// " RuntimeVisibleTypeAnnotations: \n" +
+// " #19 @A(\n" +
+// " #20 id=\"Hello, World!\" (constant type)\n" +
+// " target type = 0x14 CLASS_EXTENDS_IMPLEMENTS\n" +
+// " type index = -1\n" +
+// " )\n" +
+// " #22 @C(\n" +
+// " #23 value=\'(\' (constant type)\n" +
+// " target type = 0x14 CLASS_EXTENDS_IMPLEMENTS\n" +
+// " type index = -1\n" +
+// " )\n" +
+// " RuntimeInvisibleTypeAnnotations: \n" +
+// " #17 @B(\n" +
+// " target type = 0x14 CLASS_EXTENDS_IMPLEMENTS\n" +
+// " type index = -1\n" +
+// " )\n";
+// checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM);
+// }
+// // super interfaces
+// public void test004() throws Exception {
+// this.runConformTest(
+// new String[] {
+// "A.java",
+// "import java.lang.annotation.Target;\n" +
+// "import static java.lang.annotation.ElementType.*;\n" +
+// "import java.lang.annotation.Retention;\n" +
+// "import static java.lang.annotation.RetentionPolicy.*;\n" +
+// "@Target(TYPE_USE)\n" +
+// "@Retention(RUNTIME)\n" +
+// "@interface A {\n" +
+// " String id() default \"default\";\n" +
+// "}\n",
+// "B.java",
+// "import java.lang.annotation.Target;\n" +
+// "import static java.lang.annotation.ElementType.*;\n" +
+// "import java.lang.annotation.Retention;\n" +
+// "import static java.lang.annotation.RetentionPolicy.*;\n" +
+// "@Target(TYPE_USE)\n" +
+// "@Retention(CLASS)\n" +
+// "@interface B {\n" +
+// " int value() default -1;\n" +
+// "}",
+// "C.java",
+// "import java.lang.annotation.Target;\n" +
+// "import static java.lang.annotation.ElementType.*;\n" +
+// "import java.lang.annotation.Retention;\n" +
+// "import static java.lang.annotation.RetentionPolicy.*;\n" +
+// "@Target(TYPE_USE)\n" +
+// "@Retention(RUNTIME)\n" +
+// "@interface C {\n" +
+// " char value() default '-';\n" +
+// "}\n",
+// "I.java",
+// "interface I {}\n",
+// "J.java",
+// "interface J {}\n",
+// "X.java",
+// "public class X implements @A(id=\"Hello, World!\") I, @B @C('(') J {}",
+// },
+// "");
+// String expectedOutput =
+// " RuntimeVisibleTypeAnnotations: \n" +
+// " #23 @A(\n" +
+// " #24 id=\"Hello, World!\" (constant type)\n" +
+// " target type = 0x14 CLASS_EXTENDS_IMPLEMENTS\n" +
+// " type index = 0\n" +
+// " )\n" +
+// " #26 @C(\n" +
+// " #27 value=\'(\' (constant type)\n" +
+// " target type = 0x14 CLASS_EXTENDS_IMPLEMENTS\n" +
+// " type index = 1\n" +
+// " )\n" +
+// " RuntimeInvisibleTypeAnnotations: \n" +
+// " #21 @B(\n" +
+// " target type = 0x14 CLASS_EXTENDS_IMPLEMENTS\n" +
+// " type index = 1\n" +
+// " )\n";
+// checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM);
+// }
+// // class literal
+// public void test005() throws Exception {
+// this.runConformTest(
+// new String[] {
+// "A.java",
+// "import java.lang.annotation.Target;\n" +
+// "import static java.lang.annotation.ElementType.*;\n" +
+// "import java.lang.annotation.Retention;\n" +
+// "import static java.lang.annotation.RetentionPolicy.*;\n" +
+// "@Target(TYPE_USE)\n" +
+// "@Retention(RUNTIME)\n" +
+// "@interface A {\n" +
+// " String value() default \"default\";\n" +
+// "}\n",
+// "B.java",
+// "import java.lang.annotation.Target;\n" +
+// "import static java.lang.annotation.ElementType.*;\n" +
+// "import java.lang.annotation.Retention;\n" +
+// "import static java.lang.annotation.RetentionPolicy.*;\n" +
+// "@Target(TYPE_USE)\n" +
+// "@Retention(CLASS)\n" +
+// "@interface B {\n" +
+// " int value() default -1;\n" +
+// "}",
+// "C.java",
+// "import java.lang.annotation.Target;\n" +
+// "import static java.lang.annotation.ElementType.*;\n" +
+// "import java.lang.annotation.Retention;\n" +
+// "import static java.lang.annotation.RetentionPolicy.*;\n" +
+// "@Target(TYPE_USE)\n" +
+// "@Retention(RUNTIME)\n" +
+// "@interface C {\n" +
+// " char value() default '-';\n" +
+// "}\n",
+// "I.java",
+// "interface I {}\n",
+// "J.java",
+// "interface J {}\n",
+// "X.java",
+// "public class X {\n" +
+// " public boolean foo(String s) {\n" +
+// " boolean b = (s instanceof @C('_') Object);\n" +
+// " Object o = new @B(3) @A(\"new Object\") Object();\n" +
+// " Class<?> c = @B(4) Object.class;\n" +
+// " Class<?> c2 = @A(\"int class literal\") @B(5) int.class;\n" +
+// " System.out.println(o.toString() + c.toString() + c2.toString());\n" +
+// " return b;\n" +
+// " }\n" +
+// "}",
+// },
+// "");
+// String expectedOutput =
+// " RuntimeVisibleTypeAnnotations: \n" +
+// " #73 @C(\n" +
+// " #68 value=\'_\' (constant type)\n" +
+// " target type = 0x2 TYPE_INSTANCEOF\n" +
+// " offset = 1\n" +
+// " )\n" +
+// " #75 @A(\n" +
+// " #68 value=\"new Object\" (constant type)\n" +
+// " target type = 0x4 OBJECT_CREATION\n" +
+// " offset = 5\n" +
+// " )\n" +
+// " #75 @A(\n" +
+// " #68 value=\"int class literal\" (constant type)\n" +
+// " target type = 0x1e CLASS_LITERAL\n" +
+// " offset = 17\n" +
+// " )\n" +
+// " RuntimeInvisibleTypeAnnotations: \n" +
+// " #67 @B(\n" +
+// " #68 value=(int) 3 (constant type)\n" +
+// " target type = 0x4 OBJECT_CREATION\n" +
+// " offset = 5\n" +
+// " )\n" +
+// " #67 @B(\n" +
+// " #68 value=(int) 4 (constant type)\n" +
+// " target type = 0x1e CLASS_LITERAL\n" +
+// " offset = 13\n" +
+// " )\n" +
+// " #67 @B(\n" +
+// " #68 value=(int) 5 (constant type)\n" +
+// " target type = 0x1e CLASS_LITERAL\n" +
+// " offset = 17\n" +
+// " )\n";
+// checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM);
+// }
+// // class literal generic and array
+// public void test006() throws Exception {
+// this.runConformTest(
+// new String[] {
+// "A.java",
+// "import java.lang.annotation.Target;\n" +
+// "import static java.lang.annotation.ElementType.*;\n" +
+// "import java.lang.annotation.Retention;\n" +
+// "import static java.lang.annotation.RetentionPolicy.*;\n" +
+// "@Target(TYPE_USE)\n" +
+// "@Retention(RUNTIME)\n" +
+// "@interface A {\n" +
+// " String value() default \"default\";\n" +
+// "}\n",
+// "B.java",
+// "import java.lang.annotation.Target;\n" +
+// "import static java.lang.annotation.ElementType.*;\n" +
+// "import java.lang.annotation.Retention;\n" +
+// "import static java.lang.annotation.RetentionPolicy.*;\n" +
+// "@Target(TYPE_USE)\n" +
+// "@Retention(CLASS)\n" +
+// "@interface B {\n" +
+// " int value() default -1;\n" +
+// "}",
+// "C.java",
+// "import java.lang.annotation.Target;\n" +
+// "import static java.lang.annotation.ElementType.*;\n" +
+// "import java.lang.annotation.Retention;\n" +
+// "import static java.lang.annotation.RetentionPolicy.*;\n" +
+// "@Target(TYPE_USE)\n" +
+// "@Retention(RUNTIME)\n" +
+// "@interface C {\n" +
+// " char value() default '-';\n" +
+// "}\n",
+// "I.java",
+// "interface I {}\n",
+// "J.java",
+// "interface J {}\n",
+// "X.java",
+// "public class X {\n" +
+// " public boolean foo(Object o) {\n" +
+// " boolean b = (o instanceof @C('_') Object[]);\n" +
+// " Object o1 = new @B(3) @A(\"new Object\") Object[] {};\n" +
+// " Class<?> c = @B(4) Object[].class;\n" +
+// " Class<?> c2 = @A(\"int class literal\") @B(5) int[].class;\n" +
+// " System.out.println(o1.toString() + c.toString() + c2.toString());\n" +
+// " return b;\n" +
+// " }\n" +
+// "}",
+// },
+// "");
+// String expectedOutput =
+// " RuntimeVisibleTypeAnnotations: \n" +
+// " #70 @C(\n" +
+// " #66 value=\'_\' (constant type)\n" +
+// " target type = 0x2 TYPE_INSTANCEOF\n" +
+// " offset = 1\n" +
+// " )\n" +
+// " #72 @A(\n" +
+// " #66 value=\"int class literal\" (constant type)\n" +
+// " target type = 0x1e CLASS_LITERAL\n" +
+// " offset = 14\n" +
+// " )\n" +
+// " RuntimeInvisibleTypeAnnotations: \n" +
+// " #65 @B(\n" +
+// " #66 value=(int) 4 (constant type)\n" +
+// " target type = 0x1e CLASS_LITERAL\n" +
+// " offset = 10\n" +
+// " )\n" +
+// " #65 @B(\n" +
+// " #66 value=(int) 5 (constant type)\n" +
+// " target type = 0x1e CLASS_LITERAL\n" +
+// " offset = 14\n" +
+// " )\n";
+// checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM);
+// }
+// // parameterized superclass
+// public void test007() throws Exception {
+// this.runConformTest(
+// new String[] {
+// "A.java",
+// "import java.lang.annotation.Target;\n" +
+// "import static java.lang.annotation.ElementType.*;\n" +
+// "import java.lang.annotation.Retention;\n" +
+// "import static java.lang.annotation.RetentionPolicy.*;\n" +
+// "@Target(TYPE_USE)\n" +
+// "@Retention(RUNTIME)\n" +
+// "@interface A {\n" +
+// " String value() default \"default\";\n" +
+// "}\n",
+// "B.java",
+// "import java.lang.annotation.Target;\n" +
+// "import static java.lang.annotation.ElementType.*;\n" +
+// "import java.lang.annotation.Retention;\n" +
+// "import static java.lang.annotation.RetentionPolicy.*;\n" +
+// "@Target(TYPE_USE)\n" +
+// "@Retention(CLASS)\n" +
+// "@interface B {\n" +
+// " int value() default -1;\n" +
+// "}",
+// "C.java",
+// "import java.lang.annotation.Target;\n" +
+// "import static java.lang.annotation.ElementType.*;\n" +
+// "import java.lang.annotation.Retention;\n" +
+// "import static java.lang.annotation.RetentionPolicy.*;\n" +
+// "@Target(TYPE_USE)\n" +
+// "@Retention(RUNTIME)\n" +
+// "@interface C {\n" +
+// " char value() default '-';\n" +
+// "}\n",
+// "Y.java",
+// "class Y<T> {}\n",
+// "X.java",
+// "public class X extends @A(\"Hello, World!\") Y<@B @C('(') String> {\n" +
+// "}",
+// },
+// "");
+// String expectedOutput =
+// " RuntimeVisibleTypeAnnotations: \n" +
+// " #21 @A(\n" +
+// " #22 value=\"Hello, World!\" (constant type)\n" +
+// " target type = 0x14 CLASS_EXTENDS_IMPLEMENTS\n" +
+// " type index = -1\n" +
+// " )\n" +
+// " #24 @C(\n" +
+// " #22 value=\'(\' (constant type)\n" +
+// " target type = 0x15 CLASS_EXTENDS_IMPLEMENTS_GENERIC_OR_ARRAY\n" +
+// " type index = -1\n" +
+// " locations = {0}\n" +
+// " )\n" +
+// " RuntimeInvisibleTypeAnnotations: \n" +
+// " #19 @B(\n" +
+// " target type = 0x15 CLASS_EXTENDS_IMPLEMENTS_GENERIC_OR_ARRAY\n" +
+// " type index = -1\n" +
+// " locations = {0}\n" +
+// " )\n";
+// checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM);
+// }
+// public void test008() throws Exception {
+// this.runConformTest(
+// new String[] {
+// "A.java",
+// "import java.lang.annotation.Target;\n" +
+// "import static java.lang.annotation.ElementType.*;\n" +
+// "import java.lang.annotation.Retention;\n" +
+// "import static java.lang.annotation.RetentionPolicy.*;\n" +
+// "@Target(TYPE_USE)\n" +
+// "@Retention(RUNTIME)\n" +
+// "@interface A {\n" +
+// " String value() default \"default\";\n" +
+// "}\n",
+// "B.java",
+// "import java.lang.annotation.Target;\n" +
+// "import static java.lang.annotation.ElementType.*;\n" +
+// "import java.lang.annotation.Retention;\n" +
+// "import static java.lang.annotation.RetentionPolicy.*;\n" +
+// "@Target(TYPE_USE)\n" +
+// "@Retention(CLASS)\n" +
+// "@interface B {\n" +
+// " int value() default -1;\n" +
+// "}",
+// "C.java",
+// "import java.lang.annotation.Target;\n" +
+// "import static java.lang.annotation.ElementType.*;\n" +
+// "import java.lang.annotation.Retention;\n" +
+// "import static java.lang.annotation.RetentionPolicy.*;\n" +
+// "@Target(TYPE_USE)\n" +
+// "@Retention(RUNTIME)\n" +
+// "@interface C {\n" +
+// " char value() default '-';\n" +
+// "}\n",
+// "I.java",
+// "interface I<T> {}\n",
+// "J.java",
+// "interface J<U,T> {}\n",
+// "X.java",
+// "public class X implements I<@A(\"Hello, World!\") String>, @B J<String, @C('(') Integer> {}",
+// },
+// "");
+// String expectedOutput =
+// " RuntimeVisibleTypeAnnotations: \n" +
+// " #25 @A(\n" +
+// " #26 value=\"Hello, World!\" (constant type)\n" +
+// " target type = 0x15 CLASS_EXTENDS_IMPLEMENTS_GENERIC_OR_ARRAY\n" +
+// " type index = 0\n" +
+// " locations = {0}\n" +
+// " )\n" +
+// " #28 @C(\n" +
+// " #26 value=\'(\' (constant type)\n" +
+// " target type = 0x15 CLASS_EXTENDS_IMPLEMENTS_GENERIC_OR_ARRAY\n" +
+// " type index = 1\n" +
+// " locations = {1}\n" +
+// " )\n" +
+// " RuntimeInvisibleTypeAnnotations: \n" +
+// " #23 @B(\n" +
+// " target type = 0x14 CLASS_EXTENDS_IMPLEMENTS\n" +
+// " type index = 1\n" +
+// " )\n";
+// checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM);
+// }
+ // throws
+ public void test009() throws Exception {
+ this.runConformTest(
+ new String[] {
+ "A.java",
+ "import java.lang.annotation.Target;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.*;\n" +
+ "@Target(TYPE_USE)\n" +
+ "@Retention(RUNTIME)\n" +
+ "@interface A {\n" +
+ " String value() default \"default\";\n" +
+ "}\n",
+ "B.java",
+ "import java.lang.annotation.Target;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.*;\n" +
+ "@Target(TYPE_USE)\n" +
+ "@Retention(CLASS)\n" +
+ "@interface B {\n" +
+ " int value() default -1;\n" +
+ "}",
+ "C.java",
+ "import java.lang.annotation.Target;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.*;\n" +
+ "@Target(TYPE_USE)\n" +
+ "@Retention(RUNTIME)\n" +
+ "@interface C {\n" +
+ " char value() default '-';\n" +
+ "}\n",
+ "E.java",
+ "class E extends RuntimeException {\n" +
+ " private static final long serialVersionUID = 1L;\n" +
+ "}\n",
+ "E1.java",
+ "class E1 extends RuntimeException {\n" +
+ " private static final long serialVersionUID = 1L;\n" +
+ "}\n",
+ "E2.java",
+ "class E2 extends RuntimeException {\n" +
+ " private static final long serialVersionUID = 1L;\n" +
+ "}\n",
+ "X.java",
+ "public class X {\n" +
+ " void foo() throws @A(\"Hello, World!\") E, E1, @B @C('(') E2 {}\n" +
+ "}",
+ },
+ "");
+ String expectedOutput =
+ " RuntimeVisibleTypeAnnotations: \n" +
+ " #25 @A(\n" +
+ " #26 value=\"Hello, World!\" (constant type)\n" +
+ " target type = 0x16 THROWS\n" +
+ " throws index = 0\n" +
+ " )\n" +
+ " #28 @C(\n" +
+ " #26 value=\'(\' (constant type)\n" +
+ " target type = 0x16 THROWS\n" +
+ " throws index = 2\n" +
+ " )\n" +
+ " RuntimeInvisibleTypeAnnotations: \n" +
+ " #23 @B(\n" +
+ " target type = 0x16 THROWS\n" +
+ " throws index = 2\n" +
+ " )\n";
+ checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM);
+ }
+// // method receiver
+// public void test010() throws Exception {
+// this.runConformTest(
+// new String[] {
+// "A.java",
+// "import java.lang.annotation.Target;\n" +
+// "import static java.lang.annotation.ElementType.*;\n" +
+// "import java.lang.annotation.Retention;\n" +
+// "import static java.lang.annotation.RetentionPolicy.*;\n" +
+// "@Target(TYPE_USE)\n" +
+// "@Retention(RUNTIME)\n" +
+// "@interface A {\n" +
+// " String value() default \"default\";\n" +
+// "}\n",
+// "B.java",
+// "import java.lang.annotation.Target;\n" +
+// "import static java.lang.annotation.ElementType.*;\n" +
+// "import java.lang.annotation.Retention;\n" +
+// "import static java.lang.annotation.RetentionPolicy.*;\n" +
+// "@Target(TYPE_USE)\n" +
+// "@Retention(CLASS)\n" +
+// "@interface B {\n" +
+// " int value() default -1;\n" +
+// "}",
+// "X.java",
+// "public class X {\n" +
+// " void foo() @B(3) {}\n" +
+// "}",
+// },
+// "");
+// String expectedOutput =
+// " RuntimeInvisibleTypeAnnotations: \n" +
+// " #16 @B(\n" +
+// " #17 value=(int) 3 (constant type)\n" +
+// " target type = 0x6 METHOD_RECEIVER\n" +
+// " )\n";
+// checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM);
+// }
+ // method return type
+ public void test011() throws Exception {
+ this.runConformTest(
+ new String[] {
+ "A.java",
+ "import java.lang.annotation.Target;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.*;\n" +
+ "@Target(TYPE_USE)\n" +
+ "@Retention(RUNTIME)\n" +
+ "@interface A {\n" +
+ " String value() default \"default\";\n" +
+ "}\n",
+ "B.java",
+ "import java.lang.annotation.Target;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.*;\n" +
+ "@Target(TYPE_USE)\n" +
+ "@Retention(CLASS)\n" +
+ "@interface B {\n" +
+ " int value() default -1;\n" +
+ "}",
+ "X.java",
+ "public class X {\n" +
+ " @B(3) @A(value=\"test\") int foo() {\n" +
+ " return 1;\n" +
+ " }\n" +
+ "}",
+ },
+ "");
+ String expectedOutput =
+ " RuntimeVisibleTypeAnnotations: \n" +
+ " #21 @A(\n" +
+ " #18 value=\"test\" (constant type)\n" +
+ " target type = 0xa METHOD_RETURN_TYPE\n" +
+ " )\n" +
+ " RuntimeInvisibleTypeAnnotations: \n" +
+ " #17 @B(\n" +
+ " #18 value=(int) 3 (constant type)\n" +
+ " target type = 0xa METHOD_RETURN_TYPE\n" +
+ " )\n";
+ checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM);
+ }
+ // field type
+ public void test012() throws Exception {
+ this.runConformTest(
+ new String[] {
+ "A.java",
+ "import java.lang.annotation.Target;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.*;\n" +
+ "@Target(TYPE_USE)\n" +
+ "@Retention(RUNTIME)\n" +
+ "@interface A {\n" +
+ " String value() default \"default\";\n" +
+ "}\n",
+ "B.java",
+ "import java.lang.annotation.Target;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.*;\n" +
+ "@Target(TYPE_USE)\n" +
+ "@Retention(CLASS)\n" +
+ "@interface B {\n" +
+ " int value() default -1;\n" +
+ "}",
+ "X.java",
+ "public class X {\n" +
+ " @B(3) @A int field;\n" +
+ "}",
+ },
+ "");
+ String expectedOutput =
+ " RuntimeVisibleTypeAnnotations: \n" +
+ " #12 @A(\n" +
+ " target type = 0xe FIELD\n" +
+ " )\n" +
+ " RuntimeInvisibleTypeAnnotations: \n" +
+ " #8 @B(\n" +
+ " #9 value=(int) 3 (constant type)\n" +
+ " target type = 0xe FIELD\n" +
+ " )\n";
+ checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM);
+ }
+// // method parameter
+// public void test013() throws Exception {
+// this.runConformTest(
+// new String[] {
+// "B.java",
+// "import java.lang.annotation.Target;\n" +
+// "import static java.lang.annotation.ElementType.*;\n" +
+// "import java.lang.annotation.Retention;\n" +
+// "import static java.lang.annotation.RetentionPolicy.*;\n" +
+// "@Target(TYPE_USE)\n" +
+// "@Retention(CLASS)\n" +
+// "@interface B {\n" +
+// " int value() default -1;\n" +
+// "}",
+// "X.java",
+// "public class X {\n" +
+// " int foo(@B(3) String s) {\n" +
+// " return s.length();\n" +
+// " }\n" +
+// "}",
+// },
+// "");
+// String expectedOutput =
+// " RuntimeInvisibleTypeAnnotations: \n" +
+// " #25 @B(\n" +
+// " #26 value=(int) 3 (constant type)\n" +
+// " target type = 0xc METHOD_PARAMETER\n" +
+// " method parameter index = 0\n" +
+// " )\n";
+// checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM);
+// }
+// // method parameter generic or array
+// public void test014() throws Exception {
+// this.runConformTest(
+// new String[] {
+// "A.java",
+// "import java.lang.annotation.Target;\n" +
+// "import static java.lang.annotation.ElementType.*;\n" +
+// "import java.lang.annotation.Retention;\n" +
+// "import static java.lang.annotation.RetentionPolicy.*;\n" +
+// "@Target(TYPE_USE)\n" +
+// "@Retention(RUNTIME)\n" +
+// "@interface A {\n" +
+// " String value() default \"default\";\n" +
+// "}\n",
+// "B.java",
+// "import java.lang.annotation.Target;\n" +
+// "import static java.lang.annotation.ElementType.*;\n" +
+// "import java.lang.annotation.Retention;\n" +
+// "import static java.lang.annotation.RetentionPolicy.*;\n" +
+// "@Target(TYPE_USE)\n" +
+// "@Retention(CLASS)\n" +
+// "@interface B {\n" +
+// " int value() default -1;\n" +
+// "}",
+// "X.java",
+// "public class X {\n" +
+// " int foo(String @A [] @B(3) [] s) {\n" +
+// " return s.length;\n" +
+// " }\n" +
+// "}",
+// },
+// "");
+// String expectedOutput =
+// " RuntimeVisibleTypeAnnotations: \n" +
+// " #23 @A(\n" +
+// " target type = 0xc METHOD_PARAMETER\n" +
+// " method parameter index = 0\n" +
+// " )\n" +
+// " RuntimeInvisibleTypeAnnotations: \n" +
+// " #19 @B(\n" +
+// " #20 value=(int) 3 (constant type)\n" +
+// " target type = 0xd METHOD_PARAMETER_GENERIC_OR_ARRAY\n" +
+// " method parameter index = 0\n" +
+// " locations = {0}\n" +
+// " )\n";
+// checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM);
+// }
+ // field type generic or array
+ public void test015() throws Exception {
+ this.runConformTest(
+ new String[] {
+ "A.java",
+ "import java.lang.annotation.Target;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.*;\n" +
+ "@Target(TYPE_USE)\n" +
+ "@Retention(RUNTIME)\n" +
+ "@interface A {\n" +
+ " String value() default \"default\";\n" +
+ "}\n",
+ "B.java",
+ "import java.lang.annotation.Target;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.*;\n" +
+ "@Target(TYPE_USE)\n" +
+ "@Retention(CLASS)\n" +
+ "@interface B {\n" +
+ " int value() default -1;\n" +
+ "}",
+ "X.java",
+ "public class X {\n" +
+ " @A int [] @B(3) [] field;\n" +
+ "}",
+ },
+ "");
+ String expectedOutput =
+ " RuntimeVisibleTypeAnnotations: \n" +
+ " #12 @A(\n" +
+ " target type = 0xf FIELD_GENERIC_OR_ARRAY\n" +
+ " locations = {1}\n" +
+ " )\n" +
+ " RuntimeInvisibleTypeAnnotations: \n" +
+ " #8 @B(\n" +
+ " #9 value=(int) 3 (constant type)\n" +
+ " target type = 0xf FIELD_GENERIC_OR_ARRAY\n" +
+ " locations = {0}\n" +
+ " )\n";
+ checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM);
+ }
+// // class type parameter
+// public void test016() throws Exception {
+// this.runConformTest(
+// new String[] {
+// "A.java",
+// "import java.lang.annotation.Target;\n" +
+// "import static java.lang.annotation.ElementType.*;\n" +
+// "import java.lang.annotation.Retention;\n" +
+// "import static java.lang.annotation.RetentionPolicy.*;\n" +
+// "@Target(TYPE_PARAMETER)\n" +
+// "@Retention(RUNTIME)\n" +
+// "@interface A {\n" +
+// " String value() default \"default\";\n" +
+// "}\n",
+// "B.java",
+// "import java.lang.annotation.Target;\n" +
+// "import static java.lang.annotation.ElementType.*;\n" +
+// "import java.lang.annotation.Retention;\n" +
+// "import static java.lang.annotation.RetentionPolicy.*;\n" +
+// "@Target(TYPE_PARAMETER)\n" +
+// "@Retention(CLASS)\n" +
+// "@interface B {\n" +
+// " int value() default -1;\n" +
+// "}",
+// "X.java",
+// "public class X<@A @B(3) T> {}",
+// },
+// "");
+// String expectedOutput =
+// " RuntimeVisibleTypeAnnotations: \n" +
+// " #25 @A(\n" +
+// " target type = 0x22 CLASS_TYPE_PARAMETER\n" +
+// " type parameter index = 0\n" +
+// " )\n" +
+// " RuntimeInvisibleTypeAnnotations: \n" +
+// " #21 @B(\n" +
+// " #22 value=(int) 3 (constant type)\n" +
+// " target type = 0x22 CLASS_TYPE_PARAMETER\n" +
+// " type parameter index = 0\n" +
+// " )\n";
+// checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM);
+// }
+ // method type parameter
+ public void test017() throws Exception {
+ this.runConformTest(
+ new String[] {
+ "A.java",
+ "import java.lang.annotation.Target;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.*;\n" +
+ "@Target(TYPE_PARAMETER)\n" +
+ "@Retention(RUNTIME)\n" +
+ "@interface A {\n" +
+ " String value() default \"default\";\n" +
+ "}\n",
+ "B.java",
+ "import java.lang.annotation.Target;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.*;\n" +
+ "@Target(TYPE_PARAMETER)\n" +
+ "@Retention(CLASS)\n" +
+ "@interface B {\n" +
+ " int value() default -1;\n" +
+ "}",
+ "X.java",
+ "public class X {\n" +
+ " <@A @B(3) T> void foo(T t) {}\n" +
+ "}",
+ },
+ "");
+ String expectedOutput =
+ " RuntimeVisibleTypeAnnotations: \n" +
+ " #27 @A(\n" +
+ " target type = 0x20 METHOD_TYPE_PARAMETER\n" +
+ " type parameter index = 0\n" +
+ " )\n" +
+ " RuntimeInvisibleTypeAnnotations: \n" +
+ " #23 @B(\n" +
+ " #24 value=(int) 3 (constant type)\n" +
+ " target type = 0x20 METHOD_TYPE_PARAMETER\n" +
+ " type parameter index = 0\n" +
+ " )\n";
+ checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM);
+ }
+// // class type parameter bound
+// public void test018() throws Exception {
+// this.runConformTest(
+// new String[] {
+// "A.java",
+// "import java.lang.annotation.Target;\n" +
+// "import static java.lang.annotation.ElementType.*;\n" +
+// "import java.lang.annotation.Retention;\n" +
+// "import static java.lang.annotation.RetentionPolicy.*;\n" +
+// "@Target(TYPE_USE)\n" +
+// "@Retention(RUNTIME)\n" +
+// "@interface A {\n" +
+// " String value() default \"default\";\n" +
+// "}\n",
+// "B.java",
+// "import java.lang.annotation.Target;\n" +
+// "import static java.lang.annotation.ElementType.*;\n" +
+// "import java.lang.annotation.Retention;\n" +
+// "import static java.lang.annotation.RetentionPolicy.*;\n" +
+// "@Target(TYPE_USE)\n" +
+// "@Retention(CLASS)\n" +
+// "@interface B {\n" +
+// " int value() default -1;\n" +
+// "}",
+// "X.java",
+// "public class X<T extends @A String & @B(3) Cloneable> {}",
+// },
+// "");
+// String expectedOutput =
+// " RuntimeVisibleTypeAnnotations: \n" +
+// " #25 @A(\n" +
+// " target type = 0x10 CLASS_TYPE_PARAMETER_BOUND\n" +
+// " type parameter index = 0 type parameter bound index = 0\n" +
+// " )\n" +
+// " RuntimeInvisibleTypeAnnotations: \n" +
+// " #21 @B(\n" +
+// " #22 value=(int) 3 (constant type)\n" +
+// " target type = 0x10 CLASS_TYPE_PARAMETER_BOUND\n" +
+// " type parameter index = 0 type parameter bound index = 1\n" +
+// " )\n" ;
+// checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM);
+// }
+// // class type parameter bound generic or array
+// public void test019() throws Exception {
+// this.runConformTest(
+// new String[] {
+// "A.java",
+// "import java.lang.annotation.Target;\n" +
+// "import static java.lang.annotation.ElementType.*;\n" +
+// "import java.lang.annotation.Retention;\n" +
+// "import static java.lang.annotation.RetentionPolicy.*;\n" +
+// "@Target(TYPE_USE)\n" +
+// "@Retention(RUNTIME)\n" +
+// "@interface A {\n" +
+// " String value() default \"default\";\n" +
+// "}\n",
+// "B.java",
+// "import java.lang.annotation.Target;\n" +
+// "import static java.lang.annotation.ElementType.*;\n" +
+// "import java.lang.annotation.Retention;\n" +
+// "import static java.lang.annotation.RetentionPolicy.*;\n" +
+// "@Target(TYPE_USE)\n" +
+// "@Retention(CLASS)\n" +
+// "@interface B {\n" +
+// " int value() default -1;\n" +
+// "}",
+// "C.java",
+// "import java.lang.annotation.Target;\n" +
+// "import static java.lang.annotation.ElementType.*;\n" +
+// "import java.lang.annotation.Retention;\n" +
+// "import static java.lang.annotation.RetentionPolicy.*;\n" +
+// "@Target(TYPE_USE)\n" +
+// "@Retention(RUNTIME)\n" +
+// "@interface C {\n" +
+// " char value() default '-';\n" +
+// "}\n",
+// "Y.java",
+// "public class Y<T> {}",
+// "X.java",
+// "public class X<U, T extends Y<@A String @C[][]@B[]> & @B(3) Cloneable> {}",
+// },
+// "");
+// String expectedOutput =
+// " RuntimeVisibleTypeAnnotations: \n" +
+// " #25 @A(\n" +
+// " target type = 0x11 CLASS_TYPE_PARAMETER_BOUND_GENERIC_OR_ARRAY\n" +
+// " type parameter index = 1 type parameter bound index = 0\n" +
+// " locations = {0,2}\n" +
+// " )\n" +
+// " #26 @C(\n" +
+// " target type = 0x11 CLASS_TYPE_PARAMETER_BOUND_GENERIC_OR_ARRAY\n" +
+// " type parameter index = 1 type parameter bound index = 0\n" +
+// " locations = {0}\n" +
+// " )\n" +
+// " RuntimeInvisibleTypeAnnotations: \n" +
+// " #21 @B(\n" +
+// " target type = 0x11 CLASS_TYPE_PARAMETER_BOUND_GENERIC_OR_ARRAY\n" +
+// " type parameter index = 1 type parameter bound index = 0\n" +
+// " locations = {0,1}\n" +
+// " )\n" +
+// " #21 @B(\n" +
+// " #22 value=(int) 3 (constant type)\n" +
+// " target type = 0x10 CLASS_TYPE_PARAMETER_BOUND\n" +
+// " type parameter index = 1 type parameter bound index = 1\n" +
+// " )\n";
+// checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM);
+// }
+ // method type parameter bound
+ public void test020() throws Exception {
+ this.runConformTest(
+ new String[] {
+ "A.java",
+ "import java.lang.annotation.Target;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.*;\n" +
+ "@Target(TYPE_USE)\n" +
+ "@Retention(RUNTIME)\n" +
+ "@interface A {\n" +
+ " String value() default \"default\";\n" +
+ "}\n",
+ "B.java",
+ "import java.lang.annotation.Target;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.*;\n" +
+ "@Target(TYPE_USE)\n" +
+ "@Retention(CLASS)\n" +
+ "@interface B {\n" +
+ " int value() default -1;\n" +
+ "}",
+ "Z.java",
+ "public class Z {}",
+ "X.java",
+ "public class X {\n" +
+ " <T extends @A Z & @B(3) Cloneable> void foo(T t) {}\n" +
+ "}",
+ },
+ "");
+ String expectedOutput =
+ " RuntimeVisibleTypeAnnotations: \n" +
+ " #27 @A(\n" +
+ " target type = 0x12 METHOD_TYPE_PARAMETER_BOUND\n" +
+ " type parameter index = 0 type parameter bound index = 0\n" +
+ " )\n" +
+ " RuntimeInvisibleTypeAnnotations: \n" +
+ " #23 @B(\n" +
+ " #24 value=(int) 3 (constant type)\n" +
+ " target type = 0x12 METHOD_TYPE_PARAMETER_BOUND\n" +
+ " type parameter index = 0 type parameter bound index = 1\n" +
+ " )\n";
+ checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM);
+ }
+ // class type parameter bound generic or array
+ public void test021() throws Exception {
+ this.runConformTest(
+ new String[] {
+ "A.java",
+ "import java.lang.annotation.Target;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.*;\n" +
+ "@Target(TYPE_USE)\n" +
+ "@Retention(RUNTIME)\n" +
+ "@interface A {\n" +
+ " String value() default \"default\";\n" +
+ "}\n",
+ "B.java",
+ "import java.lang.annotation.Target;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.*;\n" +
+ "@Target(TYPE_USE)\n" +
+ "@Retention(CLASS)\n" +
+ "@interface B {\n" +
+ " int value() default -1;\n" +
+ "}",
+ "C.java",
+ "import java.lang.annotation.Target;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.*;\n" +
+ "@Target(TYPE_USE)\n" +
+ "@Retention(RUNTIME)\n" +
+ "@interface C {\n" +
+ " char value() default '-';\n" +
+ "}\n",
+ "Z.java",
+ "public class Z {}",
+ "Y.java",
+ "public class Y<T> {}",
+ "X.java",
+ "public class X {\n" +
+ " <T extends Y<@A Z @C[][]@B[]> & @B(3) Cloneable> void foo(T t) {}\n" +
+ "}",
+ },
+ "");
+ String expectedOutput =
+ " RuntimeVisibleTypeAnnotations: \n" +
+ " #27 @A(\n" +
+ " target type = 0x13 METHOD_TYPE_PARAMETER_BOUND_GENERIC_OR_ARRAY\n" +
+ " type parameter index = 0 type parameter bound index = 0\n" +
+ " locations = {0,2}\n" +
+ " )\n" +
+ " #28 @C(\n" +
+ " target type = 0x13 METHOD_TYPE_PARAMETER_BOUND_GENERIC_OR_ARRAY\n" +
+ " type parameter index = 0 type parameter bound index = 0\n" +
+ " locations = {0}\n" +
+ " )\n" +
+ " RuntimeInvisibleTypeAnnotations: \n" +
+ " #23 @B(\n" +
+ " target type = 0x13 METHOD_TYPE_PARAMETER_BOUND_GENERIC_OR_ARRAY\n" +
+ " type parameter index = 0 type parameter bound index = 0\n" +
+ " locations = {0,1}\n" +
+ " )\n" +
+ " #23 @B(\n" +
+ " #24 value=(int) 3 (constant type)\n" +
+ " target type = 0x12 METHOD_TYPE_PARAMETER_BOUND\n" +
+ " type parameter index = 0 type parameter bound index = 1\n" +
+ " )\n";
+ checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM);
+ }
+ // local variable + generic or array
+ public void test022() throws Exception {
+ this.runConformTest(
+ new String[] {
+ "A.java",
+ "import java.lang.annotation.Target;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.*;\n" +
+ "@Target(TYPE_USE)\n" +
+ "@Retention(RUNTIME)\n" +
+ "@interface A {\n" +
+ " String value() default \"default\";\n" +
+ "}\n",
+ "B.java",
+ "import java.lang.annotation.Target;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.*;\n" +
+ "@Target(TYPE_USE)\n" +
+ "@Retention(CLASS)\n" +
+ "@interface B {\n" +
+ " int value() default -1;\n" +
+ "}",
+ "C.java",
+ "import java.lang.annotation.Target;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.*;\n" +
+ "@Target(TYPE_USE)\n" +
+ "@Retention(RUNTIME)\n" +
+ "@interface C {\n" +
+ " char value() default '-';\n" +
+ "}\n",
+ "X.java",
+ "public class X {\n" +
+ " String[][] bar() {\n" +
+ " return new String[][] {};" +
+ " }\n" +
+ " void foo(String s) {\n" +
+ " @C int i;\n" +
+ " @A String [] @B(3)[] tab = bar();\n" +
+ " if (tab != null) {\n" +
+ " i = 0;\n" +
+ " System.out.println(i + tab.length);\n" +
+ " } else {\n" +
+ " System.out.println(tab.length);\n" +
+ " }\n" +
+ " i = 4;\n" +
+ " System.out.println(-i + tab.length);\n" +
+ " }\n" +
+ "}",
+ },
+ "");
+ String expectedOutput =
+ " RuntimeVisibleTypeAnnotations: \n" +
+ " #49 @C(\n" +
+ " target type = 0x8 LOCAL_VARIABLE\n" +
+ " local variable entries:\n" +
+ " [pc: 11, pc: 24] index: 2\n" +
+ " [pc: 34, pc: 46] index: 2\n" +
+ " )\n" +
+ " #50 @A(\n" +
+ " target type = 0x9 LOCAL_VARIABLE_GENERIC_OR_ARRAY\n" +
+ " local variable entries:\n" +
+ " [pc: 5, pc: 46] index: 3\n" +
+ " locations = {1}\n" +
+ " )\n" +
+ " RuntimeInvisibleTypeAnnotations: \n" +
+ " #45 @B(\n" +
+ " #46 value=(int) 3 (constant type)\n" +
+ " target type = 0x9 LOCAL_VARIABLE_GENERIC_OR_ARRAY\n" +
+ " local variable entries:\n" +
+ " [pc: 5, pc: 46] index: 3\n" +
+ " locations = {0}\n" +
+ " )\n";
+ checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM);
+ }
+ // type argument constructor call
+ public void test023() throws Exception {
+ this.runConformTest(
+ new String[] {
+ "A.java",
+ "import java.lang.annotation.Target;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.*;\n" +
+ "@Target(TYPE_USE)\n" +
+ "@Retention(RUNTIME)\n" +
+ "@interface A {\n" +
+ " String value() default \"default\";\n" +
+ "}\n",
+ "B.java",
+ "import java.lang.annotation.Target;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.*;\n" +
+ "@Target(TYPE_USE)\n" +
+ "@Retention(CLASS)\n" +
+ "@interface B {\n" +
+ " int value() default -1;\n" +
+ "}",
+ "X.java",
+ "public class X {\n" +
+ " <T> X(T t) {\n" +
+ " }\n" +
+ " public Object foo() {\n" +
+ " X x = new <@A @B(1) String>X(null);\n" +
+ " return x;\n" +
+ " }\n" +
+ "}",
+ },
+ "");
+ String expectedOutput =
+ " RuntimeVisibleTypeAnnotations: \n" +
+ " #31 @A(\n" +
+ " target type = 0x18 TYPE_ARGUMENT_CONSTRUCTOR_CALL\n" +
+ " offset = 5\n" +
+ " type argument index = 0\n" +
+ " )\n" +
+ " RuntimeInvisibleTypeAnnotations: \n" +
+ " #27 @B(\n" +
+ " #28 value=(int) 1 (constant type)\n" +
+ " target type = 0x18 TYPE_ARGUMENT_CONSTRUCTOR_CALL\n" +
+ " offset = 5\n" +
+ " type argument index = 0\n" +
+ " )\n";
+ checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM);
+ }
+ // type argument constructor call generic or array
+ public void test024() throws Exception {
+ this.runConformTest(
+ new String[] {
+ "A.java",
+ "import java.lang.annotation.Target;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.*;\n" +
+ "@Target(TYPE_USE)\n" +
+ "@Retention(RUNTIME)\n" +
+ "@interface A {\n" +
+ " String value() default \"default\";\n" +
+ "}\n",
+ "B.java",
+ "import java.lang.annotation.Target;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.*;\n" +
+ "@Target(TYPE_USE)\n" +
+ "@Retention(CLASS)\n" +
+ "@interface B {\n" +
+ " int value() default -1;\n" +
+ "}",
+ "C.java",
+ "import java.lang.annotation.Target;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.*;\n" +
+ "@Target(TYPE_USE)\n" +
+ "@Retention(RUNTIME)\n" +
+ "@interface C {\n" +
+ " char value() default '-';\n" +
+ "}\n",
+ "X.java",
+ "public class X {\n" +
+ " <T, U> X(T t, U u) {\n" +
+ " }\n" +
+ " public Object foo() {\n" +
+ " X x = new <@A Integer, @A String @C [] @B(1)[]>X(null, null);\n" +
+ " return x;\n" +
+ " }\n" +
+ "}",
+ },
+ "");
+ String expectedOutput =
+ " RuntimeVisibleTypeAnnotations: \n" +
+ " #33 @A(\n" +
+ " target type = 0x18 TYPE_ARGUMENT_CONSTRUCTOR_CALL\n" +
+ " offset = 6\n" +
+ " type argument index = 0\n" +
+ " )\n" +
+ " #33 @A(\n" +
+ " target type = 0x19 TYPE_ARGUMENT_CONSTRUCTOR_CALL_GENERIC_OR_ARRAY\n" +
+ " offset = 6\n" +
+ " type argument index = 1\n" +
+ " locations = {1}\n" +
+ " )\n" +
+ " #34 @C(\n" +
+ " target type = 0x18 TYPE_ARGUMENT_CONSTRUCTOR_CALL\n" +
+ " offset = 6\n" +
+ " type argument index = 1\n" +
+ " )\n" +
+ " RuntimeInvisibleTypeAnnotations: \n" +
+ " #29 @B(\n" +
+ " #30 value=(int) 1 (constant type)\n" +
+ " target type = 0x19 TYPE_ARGUMENT_CONSTRUCTOR_CALL_GENERIC_OR_ARRAY\n" +
+ " offset = 6\n" +
+ " type argument index = 1\n" +
+ " locations = {0}\n" +
+ " )\n";
+ checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM);
+ }
+ // type argument method call
+ public void test025() throws Exception {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ "\n" +
+ " static <T, U> T foo(T t, U u) {\n" +
+ " return t;\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(X.<@A @B(1) String[], @C('-') X>foo(new String[]{\"SUCCESS\"}, null)[0]);\n" +
+ " }\n" +
+ "}\n",
+ "A.java",
+ "import java.lang.annotation.Target;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.*;\n" +
+ "@Target(TYPE_USE)\n" +
+ "@Retention(RUNTIME)\n" +
+ "@interface A {\n" +
+ " String value() default \"default\";\n" +
+ "}\n",
+ "B.java",
+ "import java.lang.annotation.Target;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.*;\n" +
+ "@Target(TYPE_USE)\n" +
+ "@Retention(CLASS)\n" +
+ "@interface B {\n" +
+ " int value() default -1;\n" +
+ "}",
+ "C.java",
+ "import java.lang.annotation.Target;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.*;\n" +
+ "@Target(TYPE_USE)\n" +
+ "@Retention(RUNTIME)\n" +
+ "@interface C {\n" +
+ " char value() default '-';\n" +
+ "}\n",
+ },
+ "SUCCESS");
+ String expectedOutput =
+ " RuntimeVisibleTypeAnnotations: \n" +
+ " #52 @A(\n" +
+ " target type = 0x1a TYPE_ARGUMENT_METHOD_CALL\n" +
+ " offset = 13\n" +
+ " type argument index = 0\n" +
+ " )\n" +
+ " #53 @C(\n" +
+ " #49 value=\'-\' (constant type)\n" +
+ " target type = 0x1a TYPE_ARGUMENT_METHOD_CALL\n" +
+ " offset = 13\n" +
+ " type argument index = 1\n" +
+ " )\n" +
+ " RuntimeInvisibleTypeAnnotations: \n" +
+ " #48 @B(\n" +
+ " #49 value=(int) 1 (constant type)\n" +
+ " target type = 0x1a TYPE_ARGUMENT_METHOD_CALL\n" +
+ " offset = 13\n" +
+ " type argument index = 0\n" +
+ " )\n";
+ checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM);
+ }
+ // check locations
+ public void test026() throws Exception {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "import java.util.Map;\n" +
+ "import java.util.List;\n" +
+ "public class X {\n" +
+ " @H String @E[] @F[] @G[] field;\n" +
+ " @A Map<@B String, @C List<@D Object>> field2;\n" +
+ " @A Map<@B String, @H String @E[] @F[] @G[]> field3;\n" +
+ "}",
+ "A.java",
+ "import java.lang.annotation.Target;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.*;\n" +
+ "@Target(TYPE_USE)\n" +
+ "@Retention(RUNTIME)\n" +
+ "@interface A {\n" +
+ " String value() default \"default\";\n" +
+ "}\n",
+ "B.java",
+ "import java.lang.annotation.Target;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.*;\n" +
+ "@Target(TYPE_USE)\n" +
+ "@Retention(CLASS)\n" +
+ "@interface B {\n" +
+ " int value() default -1;\n" +
+ "}",
+ "C.java",
+ "import java.lang.annotation.Target;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.*;\n" +
+ "@Target(TYPE_USE)\n" +
+ "@Retention(RUNTIME)\n" +
+ "@interface C {\n" +
+ " char value() default '-';\n" +
+ "}\n",
+ "D.java",
+ "import java.lang.annotation.Target;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.*;\n" +
+ "@Target(TYPE_USE)\n" +
+ "@Retention(RUNTIME)\n" +
+ "@interface D {\n" +
+ " String value() default \"default\";\n" +
+ "}\n",
+ "E.java",
+ "import java.lang.annotation.Target;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.*;\n" +
+ "@Target(TYPE_USE)\n" +
+ "@Retention(CLASS)\n" +
+ "@interface E {\n" +
+ " int value() default -1;\n" +
+ "}",
+ "F.java",
+ "import java.lang.annotation.Target;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.*;\n" +
+ "@Target(TYPE_USE)\n" +
+ "@Retention(RUNTIME)\n" +
+ "@interface F {\n" +
+ " char value() default '-';\n" +
+ "}\n",
+ "G.java",
+ "import java.lang.annotation.Target;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.*;\n" +
+ "@Target(TYPE_USE)\n" +
+ "@Retention(CLASS)\n" +
+ "@interface G {\n" +
+ " int value() default -1;\n" +
+ "}",
+ "H.java",
+ "import java.lang.annotation.Target;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.*;\n" +
+ "@Target(TYPE_USE)\n" +
+ "@Retention(RUNTIME)\n" +
+ "@interface H {\n" +
+ " char value() default '-';\n" +
+ "}\n",
+ },
+ "");
+ String expectedOutput =
+ " // Field descriptor #6 [[[Ljava/lang/String;\n" +
+ " java.lang.String[][][] field;\n" +
+ " RuntimeVisibleTypeAnnotations: \n" +
+ " #11 @H(\n" +
+ " target type = 0xf FIELD_GENERIC_OR_ARRAY\n" +
+ " locations = {2}\n" +
+ " )\n" +
+ " #12 @F(\n" +
+ " target type = 0xf FIELD_GENERIC_OR_ARRAY\n" +
+ " locations = {0}\n" +
+ " )\n" +
+ " RuntimeInvisibleTypeAnnotations: \n" +
+ " #8 @E(\n" +
+ " target type = 0xe FIELD\n" +
+ " )\n" +
+ " #9 @G(\n" +
+ " target type = 0xf FIELD_GENERIC_OR_ARRAY\n" +
+ " locations = {1}\n" +
+ " )\n" +
+ " \n" +
+ " // Field descriptor #14 Ljava/util/Map;\n" +
+ " // Signature: Ljava/util/Map<Ljava/lang/String;Ljava/util/List<Ljava/lang/Object;>;>;\n" +
+ " java.util.Map field2;\n" +
+ " RuntimeVisibleTypeAnnotations: \n" +
+ " #18 @A(\n" +
+ " target type = 0xe FIELD\n" +
+ " )\n" +
+ " #19 @C(\n" +
+ " target type = 0xf FIELD_GENERIC_OR_ARRAY\n" +
+ " locations = {1}\n" +
+ " )\n" +
+ " #20 @D(\n" +
+ " target type = 0xf FIELD_GENERIC_OR_ARRAY\n" +
+ " locations = {1,0}\n" +
+ " )\n" +
+ " RuntimeInvisibleTypeAnnotations: \n" +
+ " #17 @B(\n" +
+ " target type = 0xf FIELD_GENERIC_OR_ARRAY\n" +
+ " locations = {0}\n" +
+ " )\n" +
+ " \n" +
+ " // Field descriptor #14 Ljava/util/Map;\n" +
+ " // Signature: Ljava/util/Map<Ljava/lang/String;[[[Ljava/lang/String;>;\n" +
+ " java.util.Map field3;\n" +
+ " RuntimeVisibleTypeAnnotations: \n" +
+ " #18 @A(\n" +
+ " target type = 0xe FIELD\n" +
+ " )\n" +
+ " #11 @H(\n" +
+ " target type = 0xf FIELD_GENERIC_OR_ARRAY\n" +
+ " locations = {1,2}\n" +
+ " )\n" +
+ " #12 @F(\n" +
+ " target type = 0xf FIELD_GENERIC_OR_ARRAY\n" +
+ " locations = {1,0}\n" +
+ " )\n" +
+ " RuntimeInvisibleTypeAnnotations: \n" +
+ " #17 @B(\n" +
+ " target type = 0xf FIELD_GENERIC_OR_ARRAY\n" +
+ " locations = {0}\n" +
+ " )\n" +
+ " #8 @E(\n" +
+ " target type = 0xf FIELD_GENERIC_OR_ARRAY\n" +
+ " locations = {1}\n" +
+ " )\n" +
+ " #9 @G(\n" +
+ " target type = 0xf FIELD_GENERIC_OR_ARRAY\n" +
+ " locations = {1,1}\n" +
+ " )\n";
+ checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM);
+ }
+ // check locations
+ public void test027() throws Exception {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " @H java.lang.String @E[] @F[] @G[] field;\n" +
+ "}",
+ "E.java",
+ "import java.lang.annotation.Target;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.*;\n" +
+ "@Target(TYPE_USE)\n" +
+ "@Retention(CLASS)\n" +
+ "@interface E {\n" +
+ " int value() default -1;\n" +
+ "}",
+ "F.java",
+ "import java.lang.annotation.Target;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.*;\n" +
+ "@Target(TYPE_USE)\n" +
+ "@Retention(RUNTIME)\n" +
+ "@interface F {\n" +
+ " char value() default '-';\n" +
+ "}\n",
+ "G.java",
+ "import java.lang.annotation.Target;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.*;\n" +
+ "@Target(TYPE_USE)\n" +
+ "@Retention(CLASS)\n" +
+ "@interface G {\n" +
+ " int value() default -1;\n" +
+ "}",
+ "H.java",
+ "import java.lang.annotation.Target;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.*;\n" +
+ "@Target(TYPE_USE)\n" +
+ "@Retention(RUNTIME)\n" +
+ "@interface H {\n" +
+ " char value() default '-';\n" +
+ "}\n",
+ },
+ "");
+ String expectedOutput =
+ " RuntimeVisibleTypeAnnotations: \n" +
+ " #11 @H(\n" +
+ " target type = 0xf FIELD_GENERIC_OR_ARRAY\n" +
+ " locations = {2}\n" +
+ " )\n" +
+ " #12 @F(\n" +
+ " target type = 0xf FIELD_GENERIC_OR_ARRAY\n" +
+ " locations = {0}\n" +
+ " )\n" +
+ " RuntimeInvisibleTypeAnnotations: \n" +
+ " #8 @E(\n" +
+ " target type = 0xe FIELD\n" +
+ " )\n" +
+ " #9 @G(\n" +
+ " target type = 0xf FIELD_GENERIC_OR_ARRAY\n" +
+ " locations = {1}\n" +
+ " )\n";
+ checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM);
+ }
+ // cast
+ public void test028() throws Exception {
+ this.runConformTest(
+ new String[] {
+ "A.java",
+ "import java.lang.annotation.Target;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.*;\n" +
+ "@Target(TYPE_USE)\n" +
+ "@Retention(RUNTIME)\n" +
+ "@interface A {\n" +
+ " String value() default \"default\";\n" +
+ "}\n",
+ "B.java",
+ "import java.lang.annotation.Target;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.*;\n" +
+ "@Target(TYPE_USE)\n" +
+ "@Retention(CLASS)\n" +
+ "@interface B {\n" +
+ " int value() default -1;\n" +
+ "}",
+ "C.java",
+ "import java.lang.annotation.Target;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.*;\n" +
+ "@Target(TYPE_USE)\n" +
+ "@Retention(RUNTIME)\n" +
+ "@interface C {\n" +
+ " char value() default '-';\n" +
+ "}\n",
+ "I.java",
+ "interface I {}\n",
+ "J.java",
+ "interface J {}\n",
+ "X.java",
+ "public class X {\n" +
+ " public void foo(Object o) {\n" +
+ " if (o instanceof String[][]) {\n" +
+ " String[][] tab = (@C('_') @B(3) String[] @A[]) o;\n" +
+ " System.out.println(tab.length);\n" +
+ " }\n" +
+ " System.out.println(o);\n" +
+ " }\n" +
+ "}",
+ },
+ "");
+ String expectedOutput =
+ " RuntimeVisibleTypeAnnotations: \n" +
+ " #41 @C(\n" +
+ " #38 value=\'_\' (constant type)\n" +
+ " target type = 0x1 TYPE_CAST_GENERIC_OR_ARRAY\n" +
+ " offset = 8\n" +
+ " locations = {1}\n" +
+ " )\n" +
+ " #43 @A(\n" +
+ " target type = 0x1 TYPE_CAST_GENERIC_OR_ARRAY\n" +
+ " offset = 8\n" +
+ " locations = {0}\n" +
+ " )\n" +
+ " RuntimeInvisibleTypeAnnotations: \n" +
+ " #37 @B(\n" +
+ " #38 value=(int) 3 (constant type)\n" +
+ " target type = 0x1 TYPE_CAST_GENERIC_OR_ARRAY\n" +
+ " offset = 8\n" +
+ " locations = {1}\n" +
+ " )\n";
+ checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM);
+ }
+ // qualified allocation expression with type arguments
+ public void test029() throws Exception {
+ this.runConformTest(
+ new String[] {
+ "A.java",
+ "import java.lang.annotation.Target;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.*;\n" +
+ "@Target(TYPE_USE)\n" +
+ "@Retention(RUNTIME)\n" +
+ "@interface A {\n" +
+ " String value() default \"default\";\n" +
+ "}\n",
+ "B.java",
+ "import java.lang.annotation.Target;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.*;\n" +
+ "@Target(TYPE_USE)\n" +
+ "@Retention(CLASS)\n" +
+ "@interface B {\n" +
+ " int value() default -1;\n" +
+ "}",
+ "C.java",
+ "import java.lang.annotation.Target;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.*;\n" +
+ "@Target(TYPE_USE)\n" +
+ "@Retention(RUNTIME)\n" +
+ "@interface C {\n" +
+ " char value() default '-';\n" +
+ "}\n",
+ "D.java",
+ "import java.lang.annotation.Target;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.*;\n" +
+ "@Target(TYPE_USE)\n" +
+ "@Retention(RUNTIME)\n" +
+ "@interface D {\n" +
+ " char value() default '-';\n" +
+ "}\n",
+ "X.java",
+ "public class X {\n" +
+ " class Y {\n" +
+ " <T, U> Y(T t, U u) {}\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " Y y = new X().new <@D() @A(value = \"hello\") String, @B X> Y(\"SUCCESS\", null);\n" +
+ " System.out.println(y);\n" +
+ " }\n" +
+ "}",
+ },
+ "");
+ String expectedOutput =
+ " RuntimeVisibleTypeAnnotations: \n" +
+ " #47 @D(\n" +
+ " target type = 0x18 TYPE_ARGUMENT_CONSTRUCTOR_CALL\n" +
+ " offset = 19\n" +
+ " type argument index = 0\n" +
+ " )\n" +
+ " #48 @A(\n" +
+ " #49 value=\"hello\" (constant type)\n" +
+ " target type = 0x18 TYPE_ARGUMENT_CONSTRUCTOR_CALL\n" +
+ " offset = 19\n" +
+ " type argument index = 0\n" +
+ " )\n" +
+ " RuntimeInvisibleTypeAnnotations: \n" +
+ " #45 @B(\n" +
+ " target type = 0x18 TYPE_ARGUMENT_CONSTRUCTOR_CALL\n" +
+ " offset = 19\n" +
+ " type argument index = 1\n" +
+ " )\n";
+ checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM);
+ }
+ // local + wildcard
+ // qualified allocation expression with type arguments
+ public void test030() throws Exception {
+ this.runConformTest(
+ new String[] {
+ "A.java",
+ "import java.lang.annotation.Target;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.*;\n" +
+ "@Target(TYPE_USE)\n" +
+ "@Retention(RUNTIME)\n" +
+ "@interface A {\n" +
+ " String value() default \"default\";\n" +
+ "}\n",
+ "B.java",
+ "import java.lang.annotation.Target;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.*;\n" +
+ "@Target(TYPE_USE)\n" +
+ "@Retention(CLASS)\n" +
+ "@interface B {\n" +
+ " int value() default -1;\n" +
+ "}",
+ "C.java",
+ "import java.lang.annotation.Target;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.*;\n" +
+ "@Target(TYPE_USE)\n" +
+ "@Retention(RUNTIME)\n" +
+ "@interface C {\n" +
+ " char value() default '-';\n" +
+ "}\n",
+ "D.java",
+ "import java.lang.annotation.Target;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.*;\n" +
+ "@Target(TYPE_USE)\n" +
+ "@Retention(RUNTIME)\n" +
+ "@interface D {\n" +
+ " char value() default '-';\n" +
+ "}\n",
+ "X.java",
+ "import java.util.Map;\n" +
+ "import java.util.HashMap;\n" +
+ "@SuppressWarnings({\"unchecked\",\"rawtypes\"})\n" +
+ "public class X {\n" +
+ " Object newMap(Object o) {\n" +
+ " Map<@A Object, ? super @C Map<@B String, @D Comparable>> map;\n" +
+ " if (o == null) {\n" +
+ " map = null;\n" +
+ " System.out.println(map);\n" +
+ " } else {\n" +
+ " System.out.println(\"No map yet\");\n" +
+ " }\n" +
+ " map = new HashMap();\n" +
+ " return map;\n" +
+ " } \n" +
+ "}",
+ },
+ "");
+ String expectedOutput =
+ " RuntimeVisibleTypeAnnotations: \n" +
+ " #46 @A(\n" +
+ " target type = 0x9 LOCAL_VARIABLE_GENERIC_OR_ARRAY\n" +
+ " local variable entries:\n" +
+ " [pc: 6, pc: 16] index: 2\n" +
+ " [pc: 32, pc: 34] index: 2\n" +
+ " locations = {0}\n" +
+ " )\n" +
+ " #47 @C(\n" +
+ " target type = 0x1c WILDCARD_BOUND\n" +
+ " wildcard location type = 0x9 LOCAL_VARIABLE_GENERIC_OR_ARRAY\n" +
+ " local variable entries:\n" +
+ " [pc: 6, pc: 16] index: 2\n" +
+ " [pc: 32, pc: 34] index: 2\n" +
+ " wildcard locations = {1}\n" +
+ " )\n" +
+ " #48 @D(\n" +
+ " target type = 0x1d WILDCARD_BOUND_GENERIC_OR_ARRAY\n" +
+ " wildcard location type = 0x9 LOCAL_VARIABLE_GENERIC_OR_ARRAY\n" +
+ " local variable entries:\n" +
+ " [pc: 6, pc: 16] index: 2\n" +
+ " [pc: 32, pc: 34] index: 2\n" +
+ " wildcard locations = {1}\n" +
+ " locations = {1}\n" +
+ " )\n" +
+ " RuntimeInvisibleTypeAnnotations: \n" +
+ " #44 @B(\n" +
+ " target type = 0x1d WILDCARD_BOUND_GENERIC_OR_ARRAY\n" +
+ " wildcard location type = 0x9 LOCAL_VARIABLE_GENERIC_OR_ARRAY\n" +
+ " local variable entries:\n" +
+ " [pc: 6, pc: 16] index: 2\n" +
+ " [pc: 32, pc: 34] index: 2\n" +
+ " wildcard locations = {1}\n" +
+ " locations = {0}\n" +
+ " )\n";
+ checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM);
+ }
+ // method type parameter bound generic or array
+ public void test031() throws Exception {
+ this.runConformTest(
+ new String[] {
+ "A.java",
+ "import java.lang.annotation.Target;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.*;\n" +
+ "@Target(TYPE_USE)\n" +
+ "@Retention(RUNTIME)\n" +
+ "@interface A {\n" +
+ " String value() default \"default\";\n" +
+ "}\n",
+ "B.java",
+ "import java.lang.annotation.Target;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.*;\n" +
+ "@Target(TYPE_USE)\n" +
+ "@Retention(CLASS)\n" +
+ "@interface B {\n" +
+ " int value() default -1;\n" +
+ "}",
+ "C.java",
+ "import java.lang.annotation.Target;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.*;\n" +
+ "@Target(TYPE_USE)\n" +
+ "@Retention(CLASS)\n" +
+ "@interface C {\n" +
+ " int value() default -1;\n" +
+ "}",
+ "D.java",
+ "import java.lang.annotation.Target;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.*;\n" +
+ "@Target(TYPE_PARAMETER)\n" +
+ "@Retention(RUNTIME)\n" +
+ "@interface D {\n" +
+ " String value() default \"default\";\n" +
+ "}\n",
+ "Z.java",
+ "public class Z<T> {}",
+ "X.java",
+ "public class X {\n" +
+ " <@D U, T extends Z<@A String @C[][]@B[]> & @B(3) Cloneable> void foo(U u, T t) {}\n" +
+ "}",
+ },
+ "");
+ String expectedOutput =
+ " RuntimeVisibleTypeAnnotations: \n" +
+ " #31 @D(\n" +
+ " target type = 0x20 METHOD_TYPE_PARAMETER\n" +
+ " type parameter index = 0\n" +
+ " )\n" +
+ " #32 @A(\n" +
+ " target type = 0x13 METHOD_TYPE_PARAMETER_BOUND_GENERIC_OR_ARRAY\n" +
+ " type parameter index = 1 type parameter bound index = 0\n" +
+ " locations = {0,2}\n" +
+ " )\n" +
+ " RuntimeInvisibleTypeAnnotations: \n" +
+ " #26 @C(\n" +
+ " target type = 0x13 METHOD_TYPE_PARAMETER_BOUND_GENERIC_OR_ARRAY\n" +
+ " type parameter index = 1 type parameter bound index = 0\n" +
+ " locations = {0}\n" +
+ " )\n" +
+ " #27 @B(\n" +
+ " target type = 0x13 METHOD_TYPE_PARAMETER_BOUND_GENERIC_OR_ARRAY\n" +
+ " type parameter index = 1 type parameter bound index = 0\n" +
+ " locations = {0,1}\n" +
+ " )\n" +
+ " #27 @B(\n" +
+ " #28 value=(int) 3 (constant type)\n" +
+ " target type = 0x12 METHOD_TYPE_PARAMETER_BOUND\n" +
+ " type parameter index = 1 type parameter bound index = 1\n" +
+ " )\n";
+ checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM);
+ }
+ // type argument method call and generic or array
+ public void test032() throws Exception {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ "\n" +
+ " static <T, U> T foo(T t, U u) {\n" +
+ " return t;\n" +
+ " }\n" +
+ " public static void bar() {\n" +
+ " System.out.println(X.<@A String[] @B(1) [], @C('-') X>foo(new String[][]{{\"SUCCESS\"}}, null)[0]);\n" +
+ " }\n" +
+ "}\n",
+ "A.java",
+ "import java.lang.annotation.Target;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.*;\n" +
+ "@Target(TYPE_USE)\n" +
+ "@Retention(RUNTIME)\n" +
+ "@interface A {\n" +
+ " String value() default \"default\";\n" +
+ "}\n",
+ "B.java",
+ "import java.lang.annotation.Target;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.*;\n" +
+ "@Target(TYPE_USE)\n" +
+ "@Retention(CLASS)\n" +
+ "@interface B {\n" +
+ " int value() default -1;\n" +
+ "}",
+ "C.java",
+ "import java.lang.annotation.Target;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.*;\n" +
+ "@Target(TYPE_USE)\n" +
+ "@Retention(RUNTIME)\n" +
+ "@interface C {\n" +
+ " char value() default '-';\n" +
+ "}\n",
+ },
+ "");
+ String expectedOutput =
+ " RuntimeVisibleTypeAnnotations: \n" +
+ " #52 @A(\n" +
+ " target type = 0x1b TYPE_ARGUMENT_METHOD_CALL_GENERIC_OR_ARRAY\n" +
+ " offset = 20\n" +
+ " type argument index = 0\n" +
+ " locations = {1}\n" +
+ " )\n" +
+ " #53 @C(\n" +
+ " #49 value=\'-\' (constant type)\n" +
+ " target type = 0x1a TYPE_ARGUMENT_METHOD_CALL\n" +
+ " offset = 20\n" +
+ " type argument index = 1\n" +
+ " )\n" +
+ " RuntimeInvisibleTypeAnnotations: \n" +
+ " #48 @B(\n" +
+ " #49 value=(int) 1 (constant type)\n" +
+ " target type = 0x1b TYPE_ARGUMENT_METHOD_CALL_GENERIC_OR_ARRAY\n" +
+ " offset = 20\n" +
+ " type argument index = 0\n" +
+ " locations = {0}\n" +
+ " )\n";
+ checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM);
+ }
+// // superclass
+// public void test033() throws Exception {
+// this.runConformTest(
+// new String[] {
+// "Marker.java",
+// "@interface Marker {}",
+// "X.java",
+// "public class X extends @Marker Object {}",
+// },
+// "");
+// }
+ // superclass
+ public void test034() throws Exception {
+ this.runNegativeTest(
+ new String[] {
+ "Marker.java",
+ "import java.lang.annotation.Target;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "@Target(TYPE_PARAMETER)\n" +
+ "@interface Marker {}",
+ "X.java",
+ "public class X extends @Marker Object {}",
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 1)\n" +
+ " public class X extends @Marker Object {}\n" +
+ " ^^^^^^^\n" +
+ "The annotation @Marker is disallowed for this location\n" +
+ "----------\n");
+ }
+// // annotation on catch variable
+// public void test035() throws Exception {
+// this.runConformTest(
+// new String[] {
+// "X.java",
+// "import java.lang.annotation.Target;\n" +
+// "import java.lang.annotation.Retention;\n" +
+// "import static java.lang.annotation.ElementType.*;\n" +
+// "import static java.lang.annotation.RetentionPolicy.*;\n" +
+// "public class X {\n" +
+// " public static void main(String[] args) {\n" +
+// " @A Exception test = new Exception() {\n" +
+// " private static final long serialVersionUID = 1L;\n" +
+// " @Override\n" +
+// " public String toString() {\n" +
+// " return \"SUCCESS\";\n" +
+// " }\n" +
+// " };\n" +
+// " try {\n" +
+// " System.out.println(test);\n" +
+// " } catch(@A Exception e) {\n" +
+// " e.printStackTrace();\n" +
+// " }\n" +
+// " }\n" +
+// "}",
+// "A.java",
+// "import java.lang.annotation.Target;\n" +
+// "import static java.lang.annotation.ElementType.*;\n" +
+// "import java.lang.annotation.Retention;\n" +
+// "import static java.lang.annotation.RetentionPolicy.*;\n" +
+// "@Target(TYPE_USE)\n" +
+// "@Retention(RUNTIME)\n" +
+// "@interface A {\n" +
+// " String value() default \"default\";\n" +
+// "}\n",
+// },
+// "SUCCESS");
+// String expectedOutput =
+// " RuntimeVisibleTypeAnnotations: \n" +
+// " #44 @A(\n" +
+// " target type = 0x8 LOCAL_VARIABLE\n" +
+// " local variable entries:\n" +
+// " [pc: 8, pc: 24] index: 1\n" +
+// " )\n" +
+// " #44 @A(\n" +
+// " target type = 0x8 LOCAL_VARIABLE\n" +
+// " local variable entries:\n" +
+// " [pc: 19, pc: 23] index: 2\n" +
+// " )\n";
+// checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM);
+// }
+ // annotation on catch variable
+ public void test036() throws Exception {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "import java.lang.annotation.Target;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import static java.lang.annotation.RetentionPolicy.*;\n" +
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " @B int j = 9;\n" +
+ " try {\n" +
+ " System.out.print(\"SUCCESS\" + j);\n" +
+ " } catch(@A Exception e) {\n" +
+ " }\n" +
+ " @B int k = 3;\n" +
+ " System.out.println(k);\n" +
+ " }\n" +
+ "}",
+ "A.java",
+ "import java.lang.annotation.Target;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.*;\n" +
+ "@Target(TYPE_USE)\n" +
+ "@Retention(RUNTIME)\n" +
+ "@interface A {\n" +
+ " String value() default \"default\";\n" +
+ "}\n",
+ "B.java",
+ "import java.lang.annotation.Target;\n" +
+ "import static java.lang.annotation.ElementType.*;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "import static java.lang.annotation.RetentionPolicy.*;\n" +
+ "@Target(TYPE_USE)\n" +
+ "@Retention(CLASS)\n" +
+ "@interface B {\n" +
+ " String value() default \"default\";\n" +
+ "}\n",
+ },
+ "SUCCESS93");
+ String expectedOutput =
+ " RuntimeInvisibleTypeAnnotations: \n" +
+ " #56 @B(\n" +
+ " target type = 0x8 LOCAL_VARIABLE\n" +
+ " local variable entries:\n" +
+ " [pc: 3, pc: 39] index: 1\n" +
+ " )\n" +
+ " #56 @B(\n" +
+ " target type = 0x8 LOCAL_VARIABLE\n" +
+ " local variable entries:\n" +
+ " [pc: 31, pc: 39] index: 2\n" +
+ " )\n";
+ checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM);
+ }
+ // make sure annotation without target appears twice when set on a method declaration
+ public void test037() throws Exception {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "import java.lang.annotation.Target;\r\n" +
+ "import static java.lang.annotation.ElementType.*;\r\n" +
+ "\r\n" +
+ "@Target(METHOD)\r\n" +
+ "@interface Annot {\r\n" +
+ " int value() default 0;\r\n" +
+ "}\r\n" +
+ "public class X {\r\n" +
+ " @Annot(4)\r\n" +
+ " public void foo() {\r\n" +
+ " }\r\n" +
+ "}",
+ },
+ "");
+ String expectedOutput =
+ " public void foo();\n" +
+ " 0 return\n" +
+ " Line numbers:\n" +
+ " [pc: 0, line: 11]\n" +
+ " Local variable table:\n" +
+ " [pc: 0, pc: 1] local: this index: 0 type: X\n" +
+ " RuntimeInvisibleAnnotations: \n" +
+ " #16 @Annot(\n" +
+ " #17 value=(int) 4 (constant type)\n" +
+ " )\n" +
+ "}";
+ checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM);
+ }
+ // make sure annotation without target appears twice when set on a method declaration
+ public void test038() throws Exception {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "@interface Annot {\r\n" +
+ " int value() default 0;\r\n" +
+ "}\r\n" +
+ "public class X {\r\n" +
+ " @Annot(4)\r\n" +
+ " public void foo() {\r\n" +
+ " }\r\n" +
+ "}",
+ },
+ "");
+ String expectedOutput =
+ " // Method descriptor #6 ()V\n" +
+ " // Stack: 0, Locals: 1\n" +
+ " public void foo();\n" +
+ " 0 return\n" +
+ " Line numbers:\n" +
+ " [pc: 0, line: 7]\n" +
+ " Local variable table:\n" +
+ " [pc: 0, pc: 1] local: this index: 0 type: X\n" +
+ " RuntimeInvisibleAnnotations: \n" +
+ " #16 @Annot(\n" +
+ " #17 value=(int) 4 (constant type)\n" +
+ " )\n" +
+ "}";
+ checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM);
+ }
+// // make sure annotation without target appears twice when set on a method declaration
+// public void test039() throws Exception {
+// this.runConformTest(
+// new String[] {
+// "X.java",
+// "@interface Annot {\r\n" +
+// " int value() default 0;\r\n" +
+// "}\r\n" +
+// "public class X {\r\n" +
+// " @Annot(4)\r\n" +
+// " public int foo() {\r\n" +
+// " return 0;\r\n" +
+// " }\r\n" +
+// "}",
+// },
+// "");
+// String expectedOutput =
+// " public int foo();\n" +
+// " 0 iconst_0\n" +
+// " 1 ireturn\n" +
+// " Line numbers:\n" +
+// " [pc: 0, line: 7]\n" +
+// " Local variable table:\n" +
+// " [pc: 0, pc: 2] local: this index: 0 type: X\n" +
+// " RuntimeInvisibleAnnotations: \n" +
+// " #17 @Annot(\n" +
+// " #18 value=(int) 4 (constant type)\n" +
+// " )\n" +
+// " RuntimeInvisibleTypeAnnotations: \n" +
+// " #17 @Annot(\n" +
+// " #18 value=(int) 4 (constant type)\n" +
+// " target type = 0xa METHOD_RETURN_TYPE\n" +
+// " )\n" +
+// "}";
+// checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM);
+// }
+ // make sure annotation without target appears twice when set on a method declaration
+ public void test040() throws Exception {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "import java.lang.annotation.Target;\r\n" +
+ "import static java.lang.annotation.ElementType.*;\r\n" +
+ "\r\n" +
+ "@Target(METHOD)\r\n" +
+ "@interface Annot {\r\n" +
+ " int value() default 0;\r\n" +
+ "}\r\n" +
+ "public class X {\r\n" +
+ " @Annot(4)\r\n" +
+ " public int foo() {\r\n" +
+ " return 0;\r\n" +
+ " }\r\n" +
+ "}",
+ },
+ "");
+ String expectedOutput =
+ " public int foo();\n" +
+ " 0 iconst_0\n" +
+ " 1 ireturn\n" +
+ " Line numbers:\n" +
+ " [pc: 0, line: 11]\n" +
+ " Local variable table:\n" +
+ " [pc: 0, pc: 2] local: this index: 0 type: X\n" +
+ " RuntimeInvisibleAnnotations: \n" +
+ " #17 @Annot(\n" +
+ " #18 value=(int) 4 (constant type)\n" +
+ " )\n" +
+ "}";
+ checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput, ClassFileBytesDisassembler.SYSTEM);
+ }
+}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/AbstractCompilerTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/AbstractCompilerTest.java
index 40e9d8b..bae9601 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/AbstractCompilerTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/AbstractCompilerTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 IBM Corporation and others.
* 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
@@ -118,6 +118,10 @@
return suite;
}
+ public static void setpossibleComplianceLevels(int complianceLevel) {
+ possibleComplianceLevels = complianceLevel;
+ }
+
/**
* Build a test suite for a compliance and a list of test suites.
* Returned test suite has only one child: {@link RegressionTestSetup} test suite.
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunAllJava8Tests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunAllJava8Tests.java
index 3bd54f6..4a2cb71 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunAllJava8Tests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunAllJava8Tests.java
@@ -18,25 +18,12 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Arrays;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.eclipse.jdt.core.tests.compiler.parser.ComplianceDiagnoseTest;
-import org.eclipse.jdt.core.tests.compiler.parser.LambdaExpressionSyntaxTest;
-import org.eclipse.jdt.core.tests.compiler.parser.ReferenceExpressionSyntaxTest;
-import org.eclipse.jdt.core.tests.compiler.parser.TypeAnnotationSyntaxTest;
-import org.eclipse.jdt.core.tests.compiler.regression.ExpressionContextTests;
-import org.eclipse.jdt.core.tests.compiler.regression.CompilerInvocationTests;
-import org.eclipse.jdt.core.tests.compiler.regression.FlowAnalysisTest8;
-import org.eclipse.jdt.core.tests.compiler.regression.GrammarCoverageTests308;
-import org.eclipse.jdt.core.tests.compiler.regression.InterfaceMethodsTest;
-import org.eclipse.jdt.core.tests.compiler.regression.NegativeLambdaExpressionsTest;
-import org.eclipse.jdt.core.tests.compiler.regression.NegativeTypeAnnotationTest;
-import org.eclipse.jdt.core.tests.compiler.regression.NullTypeAnnotationTest;
import org.eclipse.jdt.core.tests.dom.ASTConverter15JLS8Test;
import org.eclipse.jdt.core.tests.dom.ASTConverter18Test;
import org.eclipse.jdt.core.tests.dom.ASTConverterAST8Test;
@@ -46,7 +33,9 @@
import org.eclipse.jdt.core.tests.dom.TypeAnnotationsConverterTest;
import org.eclipse.jdt.core.tests.formatter.FormatterJSR308Tests;
import org.eclipse.jdt.core.tests.formatter.FormatterJSR335Tests;
+import org.eclipse.jdt.core.tests.model.JavaSearchBugs8Tests;
import org.eclipse.jdt.core.tests.rewrite.describing.ASTRewritingTest;
+import org.eclipse.jdt.core.tests.util.AbstractCompilerTest;
public class RunAllJava8Tests extends TestCase {
@@ -55,20 +44,10 @@
}
public static Class[] getAllTestClasses() {
return new Class[] {
- LambdaExpressionSyntaxTest.class,
- NegativeLambdaExpressionsTest.class,
- NegativeTypeAnnotationTest.class,
- TypeAnnotationSyntaxTest.class,
- ReferenceExpressionSyntaxTest.class,
- InterfaceMethodsTest.class,
ComplianceDiagnoseTest.class,
- GrammarCoverageTests308.class,
- NullTypeAnnotationTest.class,
- CompilerInvocationTests.class,
- ExpressionContextTests.class,
- FlowAnalysisTest8.class,
FormatterJSR335Tests.class,
FormatterJSR308Tests.class,
+ JavaSearchBugs8Tests.class,
};
}
@@ -83,14 +62,26 @@
ASTRewritingTest.class,
};
}
+
+ public static Class[] getCompilerClasses() {
+ return new Class[] {
+ org.eclipse.jdt.core.tests.eval.TestAll.class,
+ org.eclipse.jdt.core.tests.compiler.regression.TestAll.class,
+ };
+ }
+
public static Test suite() {
TestSuite ts = new TestSuite(RunAllJava8Tests.class.getName());
Class[] testClasses = getAllTestClasses();
addTestsToSuite(ts, testClasses);
testClasses = getConverterTestClasses();
- ConverterTestSetup.TEST_SUITES = new ArrayList(Arrays.asList(testClasses));
addTestsToSuite(ts, testClasses);
+
+ AbstractCompilerTest.setpossibleComplianceLevels(AbstractCompilerTest.F_1_8);
+ addTestsToSuite(ts, getCompilerClasses());
+ // ComplianceDiagnoseTest is already added to the test suite through getTestSuite
+ ts.addTest(org.eclipse.jdt.core.tests.compiler.parser.TestAll.getTestSuite(false));
return ts;
}
public static void addTestsToSuite(TestSuite suite, Class[] testClasses) {
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunOnlyJava8Tests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunOnlyJava8Tests.java
new file mode 100644
index 0000000..17d56dd
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunOnlyJava8Tests.java
@@ -0,0 +1,122 @@
+/*******************************************************************************
+ * Copyright (c) 2013 IBM Corporation and others.
+ * 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.core.tests;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.eclipse.jdt.core.tests.compiler.parser.ComplianceDiagnoseTest;
+import org.eclipse.jdt.core.tests.compiler.parser.LambdaExpressionSyntaxTest;
+import org.eclipse.jdt.core.tests.compiler.parser.ReferenceExpressionSyntaxTest;
+import org.eclipse.jdt.core.tests.compiler.parser.TypeAnnotationSyntaxTest;
+import org.eclipse.jdt.core.tests.compiler.regression.ExpressionContextTests;
+import org.eclipse.jdt.core.tests.compiler.regression.CompilerInvocationTests;
+import org.eclipse.jdt.core.tests.compiler.regression.FlowAnalysisTest8;
+import org.eclipse.jdt.core.tests.compiler.regression.GrammarCoverageTests308;
+import org.eclipse.jdt.core.tests.compiler.regression.InterfaceMethodsTest;
+import org.eclipse.jdt.core.tests.compiler.regression.Jsr335ClassFileTest;
+import org.eclipse.jdt.core.tests.compiler.regression.LambdaExpressionsTest;
+import org.eclipse.jdt.core.tests.compiler.regression.NegativeLambdaExpressionsTest;
+import org.eclipse.jdt.core.tests.compiler.regression.NegativeTypeAnnotationTest;
+import org.eclipse.jdt.core.tests.compiler.regression.NullTypeAnnotationTest;
+import org.eclipse.jdt.core.tests.dom.ASTConverter15JLS8Test;
+import org.eclipse.jdt.core.tests.dom.ASTConverter18Test;
+import org.eclipse.jdt.core.tests.dom.ASTConverterAST8Test;
+import org.eclipse.jdt.core.tests.dom.ASTConverterBugsTestJLS8;
+import org.eclipse.jdt.core.tests.dom.ASTConverterTestAST8_2;
+import org.eclipse.jdt.core.tests.dom.ConverterTestSetup;
+import org.eclipse.jdt.core.tests.dom.TypeAnnotationsConverterTest;
+import org.eclipse.jdt.core.tests.formatter.FormatterJSR308Tests;
+import org.eclipse.jdt.core.tests.formatter.FormatterJSR335Tests;
+import org.eclipse.jdt.core.tests.model.JavaSearchBugs8Tests;
+import org.eclipse.jdt.core.tests.rewrite.describing.ASTRewritingTest;
+
+public class RunOnlyJava8Tests extends TestCase {
+
+ public RunOnlyJava8Tests(String name) {
+ super(name);
+ }
+ public static Class[] getAllTestClasses() {
+ return new Class[] {
+ LambdaExpressionSyntaxTest.class,
+ NegativeLambdaExpressionsTest.class,
+ LambdaExpressionsTest.class,
+ Jsr335ClassFileTest.class,
+ NegativeTypeAnnotationTest.class,
+ TypeAnnotationSyntaxTest.class,
+ ReferenceExpressionSyntaxTest.class,
+ InterfaceMethodsTest.class,
+ ComplianceDiagnoseTest.class,
+ GrammarCoverageTests308.class,
+ NullTypeAnnotationTest.class,
+ CompilerInvocationTests.class,
+ ExpressionContextTests.class,
+ FlowAnalysisTest8.class,
+ FormatterJSR335Tests.class,
+ FormatterJSR308Tests.class,
+ JavaSearchBugs8Tests.class,
+ };
+ }
+
+ public static Class[] getConverterTestClasses() {
+ return new Class[] {
+ TypeAnnotationsConverterTest.class,
+ ASTConverterTestAST8_2.class,
+ ASTConverterAST8Test.class,
+ ASTConverterBugsTestJLS8.class,
+ ASTConverter15JLS8Test.class,
+ ASTConverter18Test.class,
+ ASTRewritingTest.class,
+ };
+ }
+ public static Test suite() {
+ TestSuite ts = new TestSuite(RunOnlyJava8Tests.class.getName());
+
+ Class[] testClasses = getAllTestClasses();
+ addTestsToSuite(ts, testClasses);
+ testClasses = getConverterTestClasses();
+ ConverterTestSetup.TEST_SUITES = new ArrayList(Arrays.asList(testClasses));
+ addTestsToSuite(ts, testClasses);
+ return ts;
+ }
+ public static void addTestsToSuite(TestSuite suite, Class[] testClasses) {
+
+ for (int i = 0; i < testClasses.length; i++) {
+ Class testClass = testClasses[i];
+ // call the suite() method and add the resulting suite to the suite
+ try {
+ Method suiteMethod = testClass.getDeclaredMethod("suite", new Class[0]); //$NON-NLS-1$
+ Test test = (Test)suiteMethod.invoke(null, new Object[0]);
+ suite.addTest(test);
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ } catch (InvocationTargetException e) {
+ e.getTargetException().printStackTrace();
+ } catch (NoSuchMethodException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ protected void tearDown() throws Exception {
+ ConverterTestSetup.PROJECT_SETUP = false;
+ super.tearDown();
+ }
+}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java
index 9c28c59..aec1a3c 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java
@@ -5,6 +5,10 @@
* 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
* Stephan Herrmann - Contributions for
@@ -11527,4 +11531,36 @@
deleteProject(jp);
}
}
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=404489
+ public void testBug404489() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter18" , "src", "test404489.bug", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(this.ast.apiLevel(), sourceUnit, true);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ TypeDeclaration typeDeclaration = (TypeDeclaration) compilationUnit.types().get(0);
+
+ node = (ASTNode) typeDeclaration.bodyDeclarations().get(2);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDecl = (MethodDeclaration) node;
+ Type type = methodDecl.getReturnType2();
+ assertTrue(type.isQualifiedType());
+ assertTrue(isMalformed(type));
+
+ // parameter
+ SingleVariableDeclaration param = (SingleVariableDeclaration) methodDecl.parameters().get(0);
+ type = param.getType();
+ assertTrue(type.isQualifiedType());
+ assertTrue(isMalformed(type));
+
+ node = (ASTNode) typeDeclaration.bodyDeclarations().get(3);
+ assertEquals("Not a field declaration", ASTNode.FIELD_DECLARATION, node.getNodeType());
+ FieldDeclaration field = (FieldDeclaration) node;
+ type = field.getType();
+ assertTrue(type.isQualifiedType());
+ assertTrue(type.isQualifiedType());
+ assertTrue(isMalformed(type));
+ }
}
\ No newline at end of file
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter18Test.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter18Test.java
index 140b56b..5a36264 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter18Test.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter18Test.java
@@ -149,10 +149,10 @@
assertNotNull(assignment);
CastExpression castExpression = (CastExpression) assignment.getRightHandSide();
assertNotNull(castExpression);
- SimpleType simpleType = (SimpleType) castExpression.getType();
- assertNotNull(simpleType);
- assertEquals("java.lang.@Marker String", simpleType.toString());
- List annotations = simpleType.annotations();
+ PackageQualifiedType packageQualifiedType = (PackageQualifiedType) castExpression.getType();
+ assertNotNull(packageQualifiedType);
+ assertEquals("java.lang.@Marker String", packageQualifiedType.toString());
+ List annotations = packageQualifiedType.annotations();
assertTrue(annotations.size() == 1);
assertEquals("@Marker", annotations.get(0).toString());
@@ -160,7 +160,7 @@
VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) statements.get(sCount++);
Type type = variableDeclarationStatement.getType();
assertTrue(type.isSimpleType());
- simpleType = (SimpleType) type;
+ SimpleType simpleType = (SimpleType) type;
assertEquals("Outer.Inner", simpleType.toString());
annotations = simpleType.annotations();
assertTrue(annotations.size() == 0);
@@ -169,22 +169,22 @@
// annotations.
variableDeclarationStatement = (VariableDeclarationStatement) statements.get(sCount++);
type = variableDeclarationStatement.getType();
- assertTrue(type.isSimpleType());
- simpleType = (SimpleType) type;
- assertNotNull(simpleType);
- assertEquals("Outer.@Marker2 Inner", simpleType.toString());
- annotations = simpleType.annotations();
+ assertTrue(type.isQualifiedType());
+ QualifiedType qualifiedType = (QualifiedType) type;
+ assertNotNull(qualifiedType);
+ assertEquals("Outer.@Marker2 Inner", qualifiedType.toString());
+ annotations = qualifiedType.annotations();
assertTrue(annotations.size() == 1);
assertEquals("@Marker2", annotations.get(0).toString());
// case 4 - Multiple levels with annotations at the last only.
variableDeclarationStatement = (VariableDeclarationStatement) statements.get(sCount++);
type = variableDeclarationStatement.getType();
- assertTrue(type.isSimpleType());
- simpleType = (SimpleType) type;
- assertNotNull(simpleType);
- assertEquals("Outer.Inner.@Marker1 Deeper", simpleType.toString());
- annotations = simpleType.annotations();
+ assertTrue(type.isQualifiedType());
+ qualifiedType = (QualifiedType) type;
+ assertNotNull(qualifiedType);
+ assertEquals("Outer.Inner.@Marker1 Deeper", qualifiedType.toString());
+ annotations = qualifiedType.annotations();
assertTrue(annotations.size() == 1);
assertEquals("@Marker1", annotations.get(0).toString());
@@ -192,7 +192,7 @@
variableDeclarationStatement = (VariableDeclarationStatement) statements.get(sCount++);
type = variableDeclarationStatement.getType();
assertTrue(type.isQualifiedType());
- QualifiedType qualifiedType = (QualifiedType) type;
+ qualifiedType = (QualifiedType) type;
assertNotNull(qualifiedType);
assertEquals("Outer.@Marker1 Inner.@Marker2 Deeper", qualifiedType.toString());
annotations = qualifiedType.annotations();
@@ -201,10 +201,10 @@
SimpleName simpleName = qualifiedType.getName();
assertEquals("Deeper", simpleName.toString());
Type qualifierType = qualifiedType.getQualifier();
- assertTrue(qualifierType.isSimpleType());
- simpleType = (SimpleType) qualifierType;
- assertEquals("Outer.@Marker1 Inner", simpleType.toString());
- annotations = simpleType.annotations();
+ assertTrue(qualifierType.isQualifiedType());
+ qualifiedType = (QualifiedType) qualifierType;
+ assertEquals("Outer.@Marker1 Inner", qualifiedType.toString());
+ annotations = qualifiedType.annotations();
assertTrue(annotations.size() == 1);
assertEquals("@Marker1", annotations.get(0).toString());
}
@@ -342,10 +342,10 @@
typeArguments = parametrizedType.typeArguments();
assertEquals(1, typeArguments.size());
type = (Type) typeArguments.get(0);
- assertTrue(type.isSimpleType());
- SimpleType simpleType = (SimpleType) type;
- assertEquals("Outer.@Marker1 Inner", simpleType.toString());
- List annotations = simpleType.annotations();
+ assertTrue(type.isQualifiedType());
+ QualifiedType qualifiedType = (QualifiedType) type;
+ assertEquals("Outer.@Marker1 Inner", qualifiedType.toString());
+ List annotations = qualifiedType.annotations();
assertTrue(annotations.size() == 1);
Annotation annotation = (Annotation) annotations.get(0);
assertEquals("@Marker1", annotation.toString());
@@ -359,13 +359,13 @@
type = (Type) typeArguments.get(0);
assertTrue(type.isQualifiedType());
assertEquals("@Marker1 Outer.Inner", type.toString());
- QualifiedType qualifiedType = (QualifiedType) type;
+ qualifiedType = (QualifiedType) type;
assertEquals("Inner", qualifiedType.getName().toString());
annotations = qualifiedType.annotations();
assertTrue(annotations.size() == 0);
Type qualifierType = qualifiedType.getQualifier();
assertTrue(qualifierType.isSimpleType());
- simpleType = (SimpleType) qualifierType;
+ SimpleType simpleType = (SimpleType) qualifierType;
assertEquals("@Marker1 Outer", simpleType.toString());
annotations = simpleType.annotations();
assertTrue(annotations.size() == 1);
@@ -1546,7 +1546,7 @@
assertEquals("vlambda -> {\n return 200;\n}\n", lambdaExpression.toString());
assertTrue(lambdaExpression.parameters().size() == 1);
IMethodBinding binding = lambdaExpression.resolveMethodBinding();
- assertEquals("public int foo(int) ", binding.toString());
+ assertEquals("private static int lambda$0(int) ", binding.toString());
VariableDeclaration variableDeclaration = (VariableDeclaration) lambdaExpression.parameters().get(0);
assertTrue(variableDeclaration instanceof VariableDeclarationFragment);
fragment = (VariableDeclarationFragment)variableDeclaration;
@@ -1581,7 +1581,7 @@
LambdaExpression lambdaExpression = (LambdaExpression)expression;
assertEquals("vlambda -> 200", lambdaExpression.toString());
IMethodBinding binding = lambdaExpression.resolveMethodBinding();
- assertEquals("public int foo(int) ", binding.toString());
+ assertEquals("private static int lambda$0(int) ", binding.toString());
assertTrue(lambdaExpression.parameters().size() == 1);
VariableDeclaration variableDeclaration = (VariableDeclaration) lambdaExpression.parameters().get(0);
assertTrue(variableDeclaration instanceof VariableDeclarationFragment);
@@ -1615,7 +1615,7 @@
LambdaExpression lambdaExpression = (LambdaExpression)expression;
assertEquals("(int[] ia) -> {\n return ia.clone();\n}\n", lambdaExpression.toString());
IMethodBinding binding = lambdaExpression.resolveMethodBinding();
- assertEquals("public java.lang.Object foo(int[]) ", binding.toString());
+ assertEquals("private static java.lang.Object lambda$0(int[]) ", binding.toString());
assertTrue(lambdaExpression.parameters().size() == 1);
VariableDeclaration variableDeclaration = (VariableDeclaration) lambdaExpression.parameters().get(0);
assertTrue(variableDeclaration instanceof SingleVariableDeclaration);
@@ -1657,7 +1657,7 @@
LambdaExpression lambdaExpression = (LambdaExpression)expression;
assertEquals("() -> {\n System.out.println(this);\n I j=() -> {\n System.out.println(this);\n I k=() -> {\n System.out.println(this);\n }\n;\n }\n;\n}\n", lambdaExpression.toString());
IMethodBinding binding = lambdaExpression.resolveMethodBinding();
- assertEquals("public void doit() ", binding.toString());
+ assertEquals("private void lambda$0() ", binding.toString());
assertTrue(lambdaExpression.parameters().size() == 0);
}
@@ -1689,7 +1689,7 @@
LambdaExpression lambdaExpression = (LambdaExpression)expression;
assertEquals("() -> () -> 10", lambdaExpression.toString());
IMethodBinding binding = lambdaExpression.resolveMethodBinding();
- assertEquals("public test399793.J foo() ", binding.toString());
+ assertEquals("private static test399793.J lambda$0() ", binding.toString());
assertTrue(lambdaExpression.parameters().size() == 0);
}
@@ -1926,7 +1926,7 @@
assertEquals("Incorrect no of modfiers", 2, modifiers.size());
modifier = (Modifier) modifiers.get(1);
assertSame("Incorrect modifier keyword", Modifier.ModifierKeyword.DEFAULT_KEYWORD, modifier.getKeyword());
- assertTrue("Incorrect modifier", modifier.isDefaultMethod());
+ assertTrue("Incorrect modifier", modifier.isDefault());
assertEquals("Incorrect AST", "public default void foo(int i){\n}\n", method.toString());
method = (MethodDeclaration) type.bodyDeclarations().get(2);
@@ -1935,4 +1935,450 @@
method = (MethodDeclaration) type.bodyDeclarations().get(3);
assertEquals("Method should be malformed", ASTNode.MALFORMED, (method.getFlags() & ASTNode.MALFORMED));
}
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=404489
+ public void testBug404489a() throws JavaModelException {
+ String contents =
+ "package test404489.bug;\n" +
+ "public class X { \n" +
+ " class Y { \n" +
+ " class Z {\n" +
+ " public Z(@A X.@B Y Y.this){}\n" +
+ " }\n" +
+ " }\n" +
+ " Object o=(@A X.@B Y.@Marker Z)null;\n" +
+ " }\n" +
+ "@java.lang.annotation.Target(java.lang.annotation.ElementType.TYPE_USE) @interface Marker {} \n" +
+ "@java.lang.annotation.Target(java.lang.annotation.ElementType.TYPE_USE) @interface A {} \n" +
+ "@java.lang.annotation.Target(java.lang.annotation.ElementType.TYPE_USE) @interface B {} \n";
+ this.workingCopy = getWorkingCopy("/Converter18/src/test404489/bug/X.java", true/* resolve */);
+ ASTNode node = buildAST(contents, this.workingCopy);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ TypeDeclaration type = (TypeDeclaration) unit.types().get(0);
+ node = (ASTNode) type.bodyDeclarations().get(0);
+ assertEquals("Not a Type Declaration", ASTNode.TYPE_DECLARATION, node.getNodeType());
+ node = (ASTNode) ((TypeDeclaration)node).bodyDeclarations().get(0);
+ assertEquals("Not a Type Declaration", ASTNode.TYPE_DECLARATION, node.getNodeType());
+ node = (ASTNode) ((TypeDeclaration)node).bodyDeclarations().get(0);
+ assertEquals("Not a method Declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration method = (MethodDeclaration) node;
+ assertEquals("Method should not be malformed", 0, (method.getFlags() & ASTNode.MALFORMED));
+ AnnotatableType annotatableType = method.getReceiverType();
+ assertTrue(annotatableType.isQualifiedType());
+ QualifiedType qualifiedType = (QualifiedType) annotatableType;
+ assertEquals("wrong qualified type", "@A X.@B Y", qualifiedType.toString());
+ ITypeBinding binding = qualifiedType.resolveBinding();
+ assertNotNull("No binding", binding);
+ assertEquals("Wrong qualified name", "test404489.bug.X.Y", binding.getQualifiedName());
+ List annotations = qualifiedType.annotations();
+ assertTrue(annotations.size() == 1);
+ MarkerAnnotation marker = (MarkerAnnotation) annotations.get(0);
+ assertEquals("wrong annotation name", "@B", marker.toString());
+ binding = marker.resolveTypeBinding();
+ assertNotNull("No binding", binding);
+ assertEquals("Wrong qualified name", "test404489.bug.B", binding.getQualifiedName());
+ IAnnotationBinding annotationBinding = marker.resolveAnnotationBinding();
+ assertNotNull(annotationBinding);
+ assertEquals("wrong annotation binding", "B", annotationBinding.getName());
+ Name name = marker.getTypeName();
+ assertTrue(name.isSimpleName());
+ SimpleName simpleName = (SimpleName) name;
+ assertEquals("wrong type name", "B", simpleName.toString());
+ assertEquals("wrong simple name", "B",simpleName.getIdentifier());
+ binding = simpleName.resolveTypeBinding();
+ assertNotNull("No binding", binding);
+ assertEquals("Wrong qualified name", "test404489.bug.B", binding.getQualifiedName());
+ assertTrue(qualifiedType.getQualifier().isSimpleType());
+ SimpleType simpleType = (SimpleType) qualifiedType.getQualifier();
+ assertEquals("incorrect type", "@A X", simpleType.toString());
+ binding = simpleType.resolveBinding();
+ assertNotNull("No binding", binding);
+ assertEquals("Wrong qualified name", "test404489.bug.X.Y", binding.getQualifiedName());
+ }
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=404489
+ public void testBug404489b() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter18" , "src", "test404489.bug", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(this.ast.apiLevel(), sourceUnit, true);
+ char[] source = sourceUnit.getSource().toCharArray();
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ TypeDeclaration typeDeclaration = (TypeDeclaration) compilationUnit.types().get(0);
+
+ node = (ASTNode) typeDeclaration.bodyDeclarations().get(2);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDecl = (MethodDeclaration) node;
+ Type type = methodDecl.getReturnType2();
+ assertTrue(type.isPackageQualifiedType());
+ PackageQualifiedType packageQualifiedType = (PackageQualifiedType) type;
+ checkSourceRange(packageQualifiedType, "test404489.bug.@NonNull IOException", source);
+ ITypeBinding typeBinding = packageQualifiedType.resolveBinding();
+ assertNotNull("null binding", typeBinding);
+ assertEquals("not a valid binding", "test404489.bug.IOException", typeBinding.getQualifiedName());
+
+ // qualifier of the package qualified type
+ Name name = packageQualifiedType.getQualifier();
+ assertTrue(name.isQualifiedName());
+ QualifiedName qualifiedName = (QualifiedName) name;
+ checkSourceRange(qualifiedName, "test404489.bug", source);
+ typeBinding = qualifiedName.resolveTypeBinding();
+ assertNull(typeBinding);
+ IBinding binding = qualifiedName.resolveBinding();
+ assertTrue("not a package binding", binding.getKind() == IBinding.PACKAGE);
+ assertEquals("wrong package binding", "package test404489.bug", binding.toString());
+ name = qualifiedName.getQualifier();
+ assertTrue("wrong name type", name.isSimpleName());
+ SimpleName simpleName = (SimpleName) name;
+ checkSourceRange(simpleName, "test404489", source);
+ typeBinding = simpleName.resolveTypeBinding();
+ assertNull(typeBinding);
+ binding = simpleName.resolveBinding();
+ assertTrue("not a package binding", binding.getKind() == IBinding.PACKAGE);
+ assertEquals("wrong package binding", "package test404489", binding.toString());
+ simpleName = qualifiedName.getName();
+ checkSourceRange(simpleName, "bug", source);
+ typeBinding = simpleName.resolveTypeBinding();
+ assertNull(typeBinding);
+ binding = simpleName.resolveBinding();
+ assertTrue("not a package binding", binding.getKind() == IBinding.PACKAGE);
+ assertEquals("wrong package binding", "package test404489.bug", binding.toString());
+
+ // annotations of package qualified type
+ List annotations = packageQualifiedType.annotations();
+ assertTrue(annotations.size() == 1);
+ Annotation annotation = (Annotation) annotations.get(0);
+ typeBinding = annotation.resolveTypeBinding();
+ assertNotNull("null binding", typeBinding);
+ assertEquals("not a valid binding", "test404489.bug.X.NonNull", typeBinding.getQualifiedName());
+ IAnnotationBinding annotationBinding = annotation.resolveAnnotationBinding();
+ assertEquals("not a valid annotation binding", "@NonNull()", annotationBinding.toString());
+ name = annotation.getTypeName();
+ assertTrue(name.isSimpleName());
+ simpleName = (SimpleName) name;
+ typeBinding = simpleName.resolveTypeBinding();
+ checkSourceRange(simpleName, "NonNull", source);
+ assertNotNull(typeBinding);
+
+ // name of the package qualified type
+ simpleName = packageQualifiedType.getName();
+ checkSourceRange(simpleName, "IOException", source);
+ typeBinding = simpleName.resolveTypeBinding();
+ assertNotNull(typeBinding);
+
+ // parameter
+ SingleVariableDeclaration param = (SingleVariableDeclaration) methodDecl.parameters().get(0);
+ type = param.getType();
+ assertTrue(type.isPackageQualifiedType());
+ packageQualifiedType = (PackageQualifiedType) type;
+ checkSourceRange(packageQualifiedType, "test404489.bug.@NonNull FileNotFoundException", source);
+ typeBinding = packageQualifiedType.resolveBinding();
+ assertNotNull("null binding", typeBinding);
+ assertEquals("not a valid binding", "test404489.bug.FileNotFoundException", typeBinding.getQualifiedName());
+
+ // qualifier of the package qualified type
+ name = packageQualifiedType.getQualifier();
+ assertTrue(name.isQualifiedName());
+ qualifiedName = (QualifiedName) name;
+ checkSourceRange(qualifiedName, "test404489.bug", source);
+ typeBinding = qualifiedName.resolveTypeBinding();
+ assertNull(typeBinding);
+ binding = qualifiedName.resolveBinding();
+ assertTrue("not a package binding", binding.getKind() == IBinding.PACKAGE);
+ assertEquals("wrong package binding", "package test404489.bug", binding.toString());
+ name = qualifiedName.getQualifier();
+ assertTrue("wrong name type", name.isSimpleName());
+ simpleName = (SimpleName) name;
+ checkSourceRange(simpleName, "test404489", source);
+ typeBinding = simpleName.resolveTypeBinding();
+ assertNull(typeBinding);
+ binding = simpleName.resolveBinding();
+ assertTrue("not a package binding", binding.getKind() == IBinding.PACKAGE);
+ assertEquals("wrong package binding", "package test404489", binding.toString());
+ simpleName = qualifiedName.getName();
+ checkSourceRange(simpleName, "bug", source);
+ typeBinding = simpleName.resolveTypeBinding();
+ assertNull(typeBinding);
+ binding = simpleName.resolveBinding();
+ assertTrue("not a package binding", binding.getKind() == IBinding.PACKAGE);
+ assertEquals("wrong package binding", "package test404489.bug", binding.toString());
+
+ // annotations of package qualified type
+ annotations = packageQualifiedType.annotations();
+ assertTrue(annotations.size() == 1);
+ annotation = (Annotation) annotations.get(0);
+ typeBinding = annotation.resolveTypeBinding();
+ assertNotNull("null binding", typeBinding);
+ assertEquals("not a valid binding", "test404489.bug.X.NonNull", typeBinding.getQualifiedName());
+ annotationBinding = annotation.resolveAnnotationBinding();
+ assertEquals("not a valid annotation binding", "@NonNull()", annotationBinding.toString());
+ name = annotation.getTypeName();
+ assertTrue(name.isSimpleName());
+ simpleName = (SimpleName) name;
+ typeBinding = simpleName.resolveTypeBinding();
+ checkSourceRange(simpleName, "NonNull", source);
+ assertNotNull(typeBinding);
+
+ // name of the package qualified type
+ simpleName = packageQualifiedType.getName();
+ checkSourceRange(simpleName, "FileNotFoundException", source);
+ typeBinding = simpleName.resolveTypeBinding();
+ assertNotNull(typeBinding);
+
+ // throws
+ type = (Type) methodDecl.thrownExceptionTypes().get(0);
+ assertTrue(type.isPackageQualifiedType());
+ packageQualifiedType = (PackageQualifiedType) type;
+ checkSourceRange(packageQualifiedType, "test404489.bug.@NonNull EOFException", source);
+ typeBinding = packageQualifiedType.resolveBinding();
+ assertNotNull("null binding", typeBinding);
+ assertEquals("not a valid binding", "test404489.bug.EOFException", typeBinding.getQualifiedName());
+
+ // qualifier of the package qualified type
+ name = packageQualifiedType.getQualifier();
+ assertTrue(name.isQualifiedName());
+ qualifiedName = (QualifiedName) name;
+ checkSourceRange(qualifiedName, "test404489.bug", source);
+ typeBinding = qualifiedName.resolveTypeBinding();
+ assertNull(typeBinding);
+ binding = qualifiedName.resolveBinding();
+ assertTrue("not a package binding", binding.getKind() == IBinding.PACKAGE);
+ assertEquals("wrong package binding", "package test404489.bug", binding.toString());
+ name = qualifiedName.getQualifier();
+ assertTrue("wrong name type", name.isSimpleName());
+ simpleName = (SimpleName) name;
+ checkSourceRange(simpleName, "test404489", source);
+ typeBinding = simpleName.resolveTypeBinding();
+ assertNull(typeBinding);
+ binding = simpleName.resolveBinding();
+ assertTrue("not a package binding", binding.getKind() == IBinding.PACKAGE);
+ assertEquals("wrong package binding", "package test404489", binding.toString());
+ simpleName = qualifiedName.getName();
+ checkSourceRange(simpleName, "bug", source);
+ typeBinding = simpleName.resolveTypeBinding();
+ assertNull(typeBinding);
+ binding = simpleName.resolveBinding();
+ assertTrue("not a package binding", binding.getKind() == IBinding.PACKAGE);
+ assertEquals("wrong package binding", "package test404489.bug", binding.toString());
+
+ // annotations of package qualified type
+ annotations = packageQualifiedType.annotations();
+ assertTrue(annotations.size() == 1);
+ annotation = (Annotation) annotations.get(0);
+ typeBinding = annotation.resolveTypeBinding();
+ assertNotNull("null binding", typeBinding);
+ assertEquals("not a valid binding", "test404489.bug.X.NonNull", typeBinding.getQualifiedName());
+ annotationBinding = annotation.resolveAnnotationBinding();
+ assertEquals("not a valid annotation binding", "@NonNull()", annotationBinding.toString());
+ name = annotation.getTypeName();
+ assertTrue(name.isSimpleName());
+ simpleName = (SimpleName) name;
+ typeBinding = simpleName.resolveTypeBinding();
+ checkSourceRange(simpleName, "NonNull", source);
+ assertNotNull(typeBinding);
+
+ // name of the package qualified type
+ simpleName = packageQualifiedType.getName();
+ checkSourceRange(simpleName, "EOFException", source);
+ typeBinding = simpleName.resolveTypeBinding();
+ assertNotNull(typeBinding);
+
+ node = (ASTNode) typeDeclaration.bodyDeclarations().get(3);
+ assertEquals("Not a field declaration", ASTNode.FIELD_DECLARATION, node.getNodeType());
+ FieldDeclaration field = (FieldDeclaration) node;
+ type = field.getType();
+ assertTrue(type.isQualifiedType());
+ QualifiedType qualifiedType = (QualifiedType) type;
+ packageQualifiedType = (PackageQualifiedType)qualifiedType.getQualifier();
+ checkSourceRange(packageQualifiedType, "test404489.bug.@NonNull X", source);
+ typeBinding = packageQualifiedType.resolveBinding();
+ assertNotNull("null binding", typeBinding);
+ assertEquals("not a valid binding", "test404489.bug.X", typeBinding.getQualifiedName());
+ name = packageQualifiedType.getName();
+ assertSame("bindings different for package qualified type and assocated name", typeBinding, name.resolveTypeBinding());
+
+ // qualifier of the package qualified type
+ name = packageQualifiedType.getQualifier();
+ assertTrue(name.isQualifiedName());
+ qualifiedName = (QualifiedName) name;
+ checkSourceRange(qualifiedName, "test404489.bug", source);
+ typeBinding = qualifiedName.resolveTypeBinding();
+ assertNull(typeBinding);
+ binding = qualifiedName.resolveBinding();
+ assertTrue("not a package binding", binding.getKind() == IBinding.PACKAGE);
+ assertEquals("wrong package binding", "package test404489.bug", binding.toString());
+ name = qualifiedName.getQualifier();
+ assertTrue("wrong name type", name.isSimpleName());
+ simpleName = (SimpleName) name;
+ checkSourceRange(simpleName, "test404489", source);
+ typeBinding = simpleName.resolveTypeBinding();
+ assertNull(typeBinding);
+ binding = simpleName.resolveBinding();
+ assertTrue("not a package binding", binding.getKind() == IBinding.PACKAGE);
+ assertEquals("wrong package binding", "package test404489", binding.toString());
+ simpleName = qualifiedName.getName();
+ checkSourceRange(simpleName, "bug", source);
+ typeBinding = simpleName.resolveTypeBinding();
+ assertNull(typeBinding);
+ binding = simpleName.resolveBinding();
+ assertTrue("not a package binding", binding.getKind() == IBinding.PACKAGE);
+ assertEquals("wrong package binding", "package test404489.bug", binding.toString());
+
+ // annotations of package qualified type
+ annotations = packageQualifiedType.annotations();
+ assertTrue(annotations.size() == 1);
+ annotation = (Annotation) annotations.get(0);
+ typeBinding = annotation.resolveTypeBinding();
+ assertNotNull("null binding", typeBinding);
+ assertEquals("not a valid binding", "test404489.bug.X.NonNull", typeBinding.getQualifiedName());
+ annotationBinding = annotation.resolveAnnotationBinding();
+ assertEquals("not a valid annotation binding", "@NonNull()", annotationBinding.toString());
+ name = annotation.getTypeName();
+ assertTrue(name.isSimpleName());
+ simpleName = (SimpleName) name;
+ typeBinding = simpleName.resolveTypeBinding();
+ checkSourceRange(simpleName, "NonNull", source);
+ assertNotNull(typeBinding);
+
+ // name of the package qualified type
+ simpleName = packageQualifiedType.getName();
+ checkSourceRange(simpleName, "X", source);
+ typeBinding = simpleName.resolveTypeBinding();
+ assertNotNull(typeBinding);
+
+ }
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=399792
+ public void testBug399792() throws JavaModelException {
+ String content =
+ "import java.lang.annotation.ElementType;\n" +
+ "import java.io.Serializable;\n" +
+ "public class X {\n" +
+ " Object o = (@Marker1 @Marker2 Serializable & I & @Marker3 @Marker1 J) () -> {};" +
+ " public Serializable main(Object o) {\n" +
+ " Serializable oo = (Serializable & @Marker3 @Marker1 @Marker2 I & J) o;\n" +
+ " return oo;\n" +
+ " }\n" +
+ "}\n" +
+ "interface I {\n" +
+ " public void foo();\n" +
+ "}\n" +
+ "interface J {\n" +
+ " public void foo();\n" +
+ " public void bar();\n" +
+ "}\n" +
+ "interface K {\n" +
+ " public void foo();\n" +
+ " public void bar();\n" +
+ "}\n" +
+ "@java.lang.annotation.Target (ElementType.TYPE_USE)\n" +
+ "@interface Marker {}\n" +
+ "@java.lang.annotation.Target (ElementType.TYPE_USE)\n" +
+ "@interface Marker2 {}\n" +
+ "@java.lang.annotation.Target (ElementType.TYPE_USE)\n" +
+ "@interface Marker3 {}";
+
+ this.workingCopy = getWorkingCopy("/Converter18/src/X.java", false);
+ ASTNode node = buildAST(content, this.workingCopy, false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ TypeDeclaration type = (TypeDeclaration) unit.types().get(0);
+ node = (ASTNode) type.bodyDeclarations().get(0);
+ assertEquals("Not a field Declaration", ASTNode.FIELD_DECLARATION, node.getNodeType());
+ FieldDeclaration field = (FieldDeclaration) node;
+ assertEquals("Field should not be malformed", 0, (field.getFlags() & ASTNode.MALFORMED));
+
+ List fragments = field.fragments();
+ assertEquals("Incorrect no of fragments", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ CastExpression cast = (CastExpression) fragment.getInitializer();
+ Type castType = cast.getType();
+ assertEquals("Not an intersection cast type", ASTNode.INTERSECTION_TYPE, castType.getNodeType());
+ assertTrue("Not an intersection cast type", castType.isIntersectionType());
+ assertEquals("Type should not be malformed", 0, (castType.getFlags() & ASTNode.MALFORMED));
+
+ List intersectionTypes = ((IntersectionType) castType).types();
+ assertEquals("Incorrect no of types", 3, intersectionTypes.size());
+ castType = (Type) intersectionTypes.get(0);
+ assertEquals("Incorrect type", ASTNode.SIMPLE_TYPE, castType.getNodeType());
+ SimpleName name = (SimpleName) ((SimpleType) castType).getName();
+ assertEquals("Incorrect name", "Serializable", name.getIdentifier());
+
+ List annotations = ((SimpleType) castType).annotations();
+ assertEquals("Incorrect no of annotations", 2, annotations.size());
+ assertEquals("Incorrect receiver", "@Marker1 @Marker2 Serializable", castType.toString());
+
+ castType = (Type) intersectionTypes.get(1);
+ assertEquals("Incorrect type", ASTNode.SIMPLE_TYPE, castType.getNodeType());
+ name = (SimpleName) ((SimpleType) castType).getName();
+ assertEquals("Incorrect name", "I", name.getIdentifier());
+
+ annotations = ((SimpleType) castType).annotations();
+ assertEquals("Incorrect no of annotations", 0, annotations.size());
+ assertEquals("Incorrect receiver", "I", castType.toString());
+
+ castType = (Type) intersectionTypes.get(2);
+ assertEquals("Incorrect type", ASTNode.SIMPLE_TYPE, castType.getNodeType());
+ name = (SimpleName) ((SimpleType) castType).getName();
+ assertEquals("Incorrect name", "J", name.getIdentifier());
+
+ annotations = ((SimpleType) castType).annotations();
+ assertEquals("Incorrect no of annotations", 2, annotations.size());
+ assertEquals("Incorrect receiver", "@Marker3 @Marker1 J", castType.toString());
+
+ node = (ASTNode) type.bodyDeclarations().get(1);
+ assertEquals("Not a method Declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration method = (MethodDeclaration) node;
+ assertEquals("Method should not be malformed", 0, (method.getFlags() & ASTNode.MALFORMED));
+
+ List statements = method.getBody().statements();
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) statements.get(0);
+ fragment = (VariableDeclarationFragment) statement.fragments().get(0);
+ cast = (CastExpression) fragment.getInitializer();
+ castType = cast.getType();
+
+ intersectionTypes = ((IntersectionType) castType).types();
+ assertEquals("Incorrect no of types", 3, intersectionTypes.size());
+ castType = (Type) intersectionTypes.get(0);
+
+ annotations = ((SimpleType) castType).annotations();
+ assertEquals("Incorrect no of annotations", 0, annotations.size());
+ assertEquals("Incorrect receiver", "Serializable", castType.toString());
+
+ castType = (Type) intersectionTypes.get(1);
+ annotations = ((SimpleType) castType).annotations();
+ assertEquals("Incorrect no of annotations", 3, annotations.size());
+ assertEquals("Incorrect receiver", "@Marker3 @Marker1 @Marker2 I", castType.toString());
+
+ castType = (Type) intersectionTypes.get(2);
+
+ annotations = ((SimpleType) castType).annotations();
+ assertEquals("Incorrect no of annotations", 0, annotations.size());
+ assertEquals("Incorrect receiver", "J", castType.toString());
+ }
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=406505
+ * tests the source range issue that resulted in bad ast node.
+ *
+ * @throws JavaModelException
+ */
+ public void testBug406505() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter18/src/test406505/X.java",
+ true/* resolve */);
+ String contents = "package test406505;"
+ + "import java.lang.annotation.Target;\n"
+ + "import java.io.File;\n"
+ + "public class X {\n"
+ + " class Folder<@Marker F extends File> { }\n"
+ + "}\n"
+ + "@Target (java.lang.annotation.ElementType.TYPE_USE)\n"
+ + "@interface Marker {}\n";
+ CompilationUnit cu = (CompilationUnit) buildAST(contents, this.workingCopy);
+ TypeDeclaration typedeclaration = (TypeDeclaration) getASTNode(cu, 0);
+ typedeclaration = (TypeDeclaration)typedeclaration.bodyDeclarations().get(0);
+ TypeParameter typeParameter = (TypeParameter) typedeclaration.typeParameters().get(0);
+ checkSourceRange(typeParameter, "@Marker F extends File", contents);
+ }
+
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTMatcherTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTMatcherTest.java
index eb059aa..4ec7759 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTMatcherTest.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTMatcherTest.java
@@ -453,6 +453,9 @@
public boolean match(PackageDeclaration node, Object other) {
return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
}
+ public boolean match(PackageQualifiedType node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
public boolean match(ParameterizedType node, Object other) {
return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
}
@@ -561,6 +564,9 @@
public boolean match(LambdaExpression node, Object other) {
return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
}
+ public boolean match(IntersectionType node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
}
/**
@@ -705,6 +711,15 @@
}
/** @deprecated using deprecated code */
+ public void testPackageQualifiedType() {
+ if (this.ast.apiLevel() < AST.JLS8) {
+ return;
+ }
+ Type x1 = this.ast.newPackageQualifiedType(this.ast.newQualifiedName(this.N2, this.N3), this.N1);
+ basicMatch(x1);
+ }
+
+ /** @deprecated using deprecated code */
public void testParameterizedType() {
if (this.ast.apiLevel() == AST.JLS2) {
return;
@@ -1622,4 +1637,12 @@
x1.setBody(this.E1);
basicMatch(x1);
}
+ public void testIntersectionType() {
+ if (this.ast.apiLevel() < AST.JLS8) {
+ return;
+ }
+ IntersectionType x1 = this.ast.newIntersectionType();
+ x1.types().add(this.ast.newSimpleType(this.N1));
+ basicMatch(x1);
+ }
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTStructuralPropertyTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTStructuralPropertyTest.java
index a4c5240..9d7b5f6 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTStructuralPropertyTest.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTStructuralPropertyTest.java
@@ -20,6 +20,7 @@
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
@@ -40,6 +41,8 @@
if (methods[i].getName().startsWith("test")) { //$NON-NLS-1$
suite.addTest(new ASTStructuralPropertyTest(methods[i].getName(), AST.JLS2));
suite.addTest(new ASTStructuralPropertyTest(methods[i].getName(), AST.JLS3));
+ suite.addTest(new ASTStructuralPropertyTest(methods[i].getName(), AST.JLS4));
+ suite.addTest(new ASTStructuralPropertyTest(methods[i].getName(), AST.JLS8));
}
}
return suite;
@@ -49,6 +52,12 @@
ASTParser parser;
int API_LEVEL;
+ public ASTStructuralPropertyTest(String name) {
+ super(name.substring(0, name.indexOf(" - JLS")));
+ name.indexOf(" - JLS");
+ this.API_LEVEL = Integer.parseInt(name.substring(name.indexOf(" - JLS") + 6));
+ }
+
public ASTStructuralPropertyTest(String name, int apiLevel) {
super(name);
this.API_LEVEL = apiLevel;
@@ -65,17 +74,8 @@
super.tearDown();
}
- /** @deprecated using deprecated code */
public String getName() {
- String name = super.getName();
- switch (this.API_LEVEL) {
- case AST.JLS2:
- name = "JLS2 - " + name;
- break;
- case AST.JLS3:
- name = "JLS3 - " + name;
- break;
- }
+ String name = super.getName() + " - JLS" + this.API_LEVEL;
return name;
}
@@ -111,11 +111,11 @@
public void testStructuralProperties() {
final ASTNode root = SampleASTs.oneOfEach(this.ast);
- final Set simpleProperties = new HashSet(400);
- final Set childProperties = new HashSet(400);
- final Set childListProperties = new HashSet(400);
- final Set visitedProperties = new HashSet(400);
- final Set nodeClasses = new HashSet(100);
+ final Set simpleProperties = new LinkedHashSet(400);
+ final Set childProperties = new LinkedHashSet(400);
+ final Set childListProperties = new LinkedHashSet(400);
+ final Set visitedProperties = new LinkedHashSet(400);
+ final Set nodeClasses = new LinkedHashSet(100);
ASTVisitor v = new ASTVisitor(true) {
public void postVisit(ASTNode node) {
@@ -123,7 +123,6 @@
if (me != null) {
visitedProperties.add(me);
}
- visitedProperties.add(me);
nodeClasses.add(node.getClass());
List ps = node.structuralPropertiesForType();
for (Iterator it = ps.iterator(); it.hasNext(); ) {
@@ -153,7 +152,7 @@
switch(this.API_LEVEL) {
case AST.JLS2 :
assertEquals("Wrong number of visited node classes", 67, nodeClasses.size());
- assertEquals("Wrong number of visited properties", 82, visitedProperties.size());
+ assertEquals("Wrong number of visited properties", 81, visitedProperties.size());
//{ObjectTeams: 2 new simple properties in TypeDeclaration: TEAM_PROPERTY and ROLE_PROPERTY:
/* orig:
assertEquals("Wrong number of simple properties", 26, simpleProperties.size());
@@ -174,7 +173,7 @@
break;
case AST.JLS3 :
assertEquals("Wrong number of visited node classes", 80, nodeClasses.size());
- assertEquals("Wrong number of visited properties", 104, visitedProperties.size());
+ assertEquals("Wrong number of visited properties", 103, visitedProperties.size());
//{ObjectTeams: 2 new simple properties in TypeDeclaration: TEAM_PROPERTY and ROLE_PROPERTY:
// 1 new property in ImportDeclaration: BASE_PROPERTY
/* orig:
@@ -193,6 +192,23 @@
:giro */
assertEquals("Wrong number of child list properties", 53, childListProperties.size());
// SH}
+ break;
+ case AST.JLS4 :
+ assertEquals("Wrong number of visited node classes", 81, nodeClasses.size());
+ assertEquals("Wrong number of visited properties", 103, visitedProperties.size());
+ assertEquals("Wrong number of simple properties", 23, simpleProperties.size());
+ assertEquals("Wrong number of child properties", 115, childProperties.size());
+ assertEquals("Wrong number of child list properties", 54, childListProperties.size());
+ break;
+ case AST.JLS8 :
+ assertEquals("Wrong number of visited node classes", 84, nodeClasses.size());
+ assertEquals("Wrong number of visited properties", 105, visitedProperties.size());
+ assertEquals("Wrong number of simple properties", 21, simpleProperties.size());
+ assertEquals("Wrong number of child properties", 118, childProperties.size());
+ assertEquals("Wrong number of child list properties", 66, childListProperties.size());
+ break;
+ default :
+ fail();
}
// visit should rebuild tree
ASTNode newRoot = SampleASTs.oneOfEach(this.ast);
@@ -330,6 +346,24 @@
/** @deprecated using deprecated code */
public void testCreateInstance() {
+ int maxNodeType;
+ switch (this.ast.apiLevel()) {
+ case AST.JLS2:
+ maxNodeType = 69;
+ break;
+ case AST.JLS3:
+ maxNodeType = 83;
+ break;
+ case AST.JLS4:
+ maxNodeType = 84;
+ break;
+ case AST.JLS8:
+ maxNodeType = 88;
+ break;
+ default:
+ fail();
+ return;
+ }
for (int nodeType = 0; nodeType < 100; nodeType++) {
Class nodeClass = null;
try {
@@ -345,24 +379,12 @@
// good: OT node
} else
// SH}
- if (this.ast.apiLevel() == AST.JLS2) {
- assertTrue((nodeType >= 1) && (nodeType <= 69));
- } else if (this.ast.apiLevel() == AST.JLS3) {
- assertTrue((nodeType >= 1) && (nodeType <= 83));
- } else if (this.ast.apiLevel() == AST.JLS4) {
- assertTrue((nodeType >= 1) && (nodeType <= 84));
- }
+ assertTrue(nodeType <= maxNodeType);
assertTrue(node.getNodeType() == nodeType);
//ASTNode node2 = ast.createInstance(nodeType);
//assertTrue(node2.getNodeType() == nodeType);
} catch (RuntimeException e) {
- if (this.ast.apiLevel() == AST.JLS2) {
- assertTrue((nodeType < 1) || (nodeType > 69));
- } else if (this.ast.apiLevel() == AST.JLS3) {
- assertTrue((nodeType < 1) || (nodeType > 83));
- } else if (this.ast.apiLevel() == AST.JLS4) {
- assertTrue((nodeType < 1) || (nodeType > 84));
- }
+ assertTrue((nodeType < 1) || (nodeType > maxNodeType));
}
}
}
@@ -395,9 +417,9 @@
}
// {ObjectTeams: adapted for OT specific ASTNodes
/* orig:
- assertEquals("Wrong last known type", 86, hi); // last known one
+ assertEquals("Wrong last known type", 88, hi); // last known one
:giro */
- assertEquals("Wrong last known type", 101, hi); // last known one
+ assertEquals("Wrong last known type", 103, hi); // last known one
// jwl}
assertEquals("Wrong number of distinct types", hi, classes.size()); // all classes are distinct
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTTest.java
index b78d5d0..ee25c3b 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTTest.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTTest.java
@@ -16,17 +16,19 @@
package org.eclipse.jdt.core.tests.dom;
+import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
-import java.util.Set;
-
import java.util.Map;
+import junit.framework.AssertionFailedError;
import junit.framework.Test;
+
import org.eclipse.jdt.core.dom.*;
// testing
@@ -750,7 +752,7 @@
suite.addTest(new ASTTest(methods[i].getName(), AST.JLS2));
suite.addTest(new ASTTest(methods[i].getName(), JLS3_INTERNAL));
suite.addTest(new ASTTest(methods[i].getName(), AST.JLS4));
- // suite.addTest(new ASTTest(methods[i].getName(), AST.JLS8));
+ suite.addTest(new ASTTest(methods[i].getName(), AST.JLS8));
}
}
return suite;
@@ -759,6 +761,11 @@
AST ast;
int API_LEVEL;
+ public ASTTest(String name) {
+ super(name.substring(0, name.indexOf(" - JLS")));
+ name.indexOf(" - JLS");
+ this.API_LEVEL = Integer.parseInt(name.substring(name.indexOf(" - JLS") + 6));
+ }
public ASTTest(String name, int apiLevel) {
super(name);
@@ -775,17 +782,8 @@
super.tearDown();
}
- /** @deprecated using deprecated code */
public String getName() {
- String name = super.getName();
- switch (this.API_LEVEL) {
- case AST.JLS2:
- name = "JLS2 - " + name;
- break;
- case JLS3_INTERNAL:
- name = "JLS3 - " + name;
- break;
- }
+ String name = super.getName() + " - JLS" + this.API_LEVEL;
return name;
}
@@ -3178,12 +3176,20 @@
}
previousCount = this.ast.modificationCount();
- x.setExtraDimensions(1);
+ if (this.ast.apiLevel() < AST.JLS8) {
+ x.setExtraDimensions(1);
+ } else {
+ x.extraDimensions().add(this.ast.newExtraDimension());
+ }
assertTrue(this.ast.modificationCount() > previousCount);
assertTrue(x.getExtraDimensions() == 1);
previousCount = this.ast.modificationCount();
- x.setExtraDimensions(0);
+ if (this.ast.apiLevel() < AST.JLS8) {
+ x.setExtraDimensions(0);
+ } else {
+ x.extraDimensions().remove(0);
+ }
assertTrue(this.ast.modificationCount() > previousCount);
assertTrue(x.getExtraDimensions() == 0);
@@ -3282,6 +3288,19 @@
}
});
+ if (this.ast.apiLevel() >= AST.JLS8) {
+ genericPropertyListTest(x, x.extraDimensions(),
+ new Property("ExtraDimensions", true, ExtraDimension.class) { //$NON-NLS-1$
+ public ASTNode sample(AST targetAst, boolean parented) {
+ ExtraDimension result = targetAst.newExtraDimension();
+ if (parented) {
+ targetAst.newMethodDeclaration().extraDimensions().add(result);
+ }
+ return result;
+ }
+ });
+ }
+
genericPropertyTest(x, new Property("Initializer", false, Expression.class) { //$NON-NLS-1$
public ASTNode sample(AST targetAst, boolean parented) {
SimpleName result = targetAst.newSimpleName("foo"); //$NON-NLS-1$
@@ -3327,21 +3346,31 @@
assertTrue(this.ast.modificationCount() == previousCount);
previousCount = this.ast.modificationCount();
- setExtraDimensions(x, 1);
+ if (this.ast.apiLevel() < AST.JLS8) {
+ setExtraDimensions(x, 1);
+ } else {
+ x.extraDimensions().add(this.ast.newExtraDimension());
+ }
assertTrue(this.ast.modificationCount() > previousCount);
assertTrue(x.getExtraDimensions() == 1);
previousCount = this.ast.modificationCount();
- setExtraDimensions(x, 0);
+ if (this.ast.apiLevel() < AST.JLS8) {
+ setExtraDimensions(x, 0);
+ } else {
+ x.extraDimensions().remove(0);
+ }
assertTrue(this.ast.modificationCount() > previousCount);
assertTrue(x.getExtraDimensions() == 0);
// check that property cannot be set negative
- try {
- setExtraDimensions(x, -1);
- assertTrue(false);
- } catch (RuntimeException e) {
- // pass
+ if (this.ast.apiLevel() < AST.JLS8) {
+ try {
+ setExtraDimensions(x, -1);
+ fail();
+ } catch (IllegalArgumentException e) {
+ // pass
+ }
}
genericPropertyTest(x, new Property("Name", true, SimpleName.class) { //$NON-NLS-1$
@@ -3360,6 +3389,19 @@
}
});
+ if (this.ast.apiLevel() >= AST.JLS8) {
+ genericPropertyListTest(x, x.extraDimensions(),
+ new Property("ExtraDimensions", true, ExtraDimension.class) { //$NON-NLS-1$
+ public ASTNode sample(AST targetAst, boolean parented) {
+ ExtraDimension result = targetAst.newExtraDimension();
+ if (parented) {
+ targetAst.newMethodDeclaration().extraDimensions().add(result);
+ }
+ return result;
+ }
+ });
+ }
+
genericPropertyTest(x, new Property("Initializer", false, Expression.class) { //$NON-NLS-1$
public ASTNode sample(AST targetAst, boolean parented) {
SimpleName result = targetAst.newSimpleName("foo"); //$NON-NLS-1$
@@ -3466,12 +3508,20 @@
}
previousCount = this.ast.modificationCount();
- x.setExtraDimensions(1);
+ if (this.ast.apiLevel() < AST.JLS8) {
+ x.setExtraDimensions(1);
+ } else {
+ x.extraDimensions().add(this.ast.newExtraDimension());
+ }
assertTrue(this.ast.modificationCount() > previousCount);
assertTrue(x.getExtraDimensions() == 1);
previousCount = this.ast.modificationCount();
- x.setExtraDimensions(0);
+ if (this.ast.apiLevel() < AST.JLS8) {
+ x.setExtraDimensions(0);
+ } else {
+ x.extraDimensions().remove(0);
+ }
assertTrue(this.ast.modificationCount() > previousCount);
assertTrue(x.getExtraDimensions() == 0);
@@ -3545,6 +3595,19 @@
});
}
+ if (this.ast.apiLevel() >= AST.JLS8) {
+ genericPropertyListTest(x, x.extraDimensions(),
+ new Property("ExtraDimensions", true, ExtraDimension.class) { //$NON-NLS-1$
+ public ASTNode sample(AST targetAst, boolean parented) {
+ ExtraDimension result = targetAst.newExtraDimension();
+ if (parented) {
+ targetAst.newMethodDeclaration().extraDimensions().add(result);
+ }
+ return result;
+ }
+ });
+ }
+
genericPropertyListTest(x, x.parameters(),
new Property("Parameters", true, SingleVariableDeclaration.class) { //$NON-NLS-1$
public ASTNode sample(AST targetAst, boolean parented) {
@@ -3637,11 +3700,13 @@
x.parameters().add(this.ast.newSingleVariableDeclaration());
assertTrue(!x.isVarargs()); // only last param counts
}
- try {
- x.setExtraDimensions(-1);
- assertTrue("Should fail", false);
- } catch(IllegalArgumentException e) {
- // pass
+ if (this.ast.apiLevel() < AST.JLS8) {
+ try {
+ x.setExtraDimensions(-1);
+ fail("Should fail");
+ } catch(IllegalArgumentException e) {
+ // pass
+ }
}
}
@@ -8417,7 +8482,7 @@
* @param x the annotation to test
* @since 3.0
*/
- public void tAnnotationName(final Annotation x) {
+ void tAnnotationName(final Annotation x) {
genericPropertyTest(x, new Property("TypeName", true, Name.class) { //$NON-NLS-1$
public ASTNode sample(AST targetAst, boolean parented) {
SimpleName result = targetAst.newSimpleName("a"); //$NON-NLS-1$
@@ -8638,190 +8703,145 @@
assertTrue(subtreeBytes > 0);
}
- public void testNodeTypeConstants() {
+ public void testNodeTypeConstants() throws Exception {
// it would be a breaking API change to change the numeric values of
// public static final ints
- assertSame(ASTNode.ANONYMOUS_CLASS_DECLARATION, 1);
- assertSame(ASTNode.ARRAY_ACCESS, 2);
- assertSame(ASTNode.ARRAY_CREATION, 3);
- assertSame(ASTNode.ARRAY_INITIALIZER, 4);
- assertSame(ASTNode.ARRAY_TYPE, 5);
- assertSame(ASTNode.ASSERT_STATEMENT, 6);
- assertSame(ASTNode.ASSIGNMENT, 7);
- assertSame(ASTNode.BLOCK, 8);
- assertSame(ASTNode.BOOLEAN_LITERAL, 9);
- assertSame(ASTNode.BREAK_STATEMENT, 10);
- assertSame(ASTNode.CAST_EXPRESSION, 11);
- assertSame(ASTNode.CATCH_CLAUSE, 12);
- assertSame(ASTNode.CHARACTER_LITERAL, 13);
- assertSame(ASTNode.CLASS_INSTANCE_CREATION, 14);
- assertSame(ASTNode.COMPILATION_UNIT, 15);
- assertSame(ASTNode.CONDITIONAL_EXPRESSION, 16);
- assertSame(ASTNode.CONSTRUCTOR_INVOCATION, 17);
- assertSame(ASTNode.CONTINUE_STATEMENT, 18);
- assertSame(ASTNode.DO_STATEMENT, 19);
- assertSame(ASTNode.EMPTY_STATEMENT, 20);
- assertSame(ASTNode.EXPRESSION_STATEMENT, 21);
- assertSame(ASTNode.FIELD_ACCESS, 22);
- assertSame(ASTNode.FIELD_DECLARATION, 23);
- assertSame(ASTNode.FOR_STATEMENT, 24);
- assertSame(ASTNode.IF_STATEMENT, 25);
- assertSame(ASTNode.IMPORT_DECLARATION, 26);
- assertSame(ASTNode.INFIX_EXPRESSION, 27);
- assertSame(ASTNode.INITIALIZER, 28);
- assertSame(ASTNode.JAVADOC, 29);
- assertSame(ASTNode.LABELED_STATEMENT, 30);
- assertSame(ASTNode.METHOD_DECLARATION, 31);
- assertSame(ASTNode.METHOD_INVOCATION, 32);
- assertSame(ASTNode.NULL_LITERAL, 33);
- assertSame(ASTNode.NUMBER_LITERAL, 34);
- assertSame(ASTNode.PACKAGE_DECLARATION, 35);
- assertSame(ASTNode.PARENTHESIZED_EXPRESSION, 36);
- assertSame(ASTNode.POSTFIX_EXPRESSION, 37);
- assertSame(ASTNode.PREFIX_EXPRESSION, 38);
- assertSame(ASTNode.PRIMITIVE_TYPE, 39);
- assertSame(ASTNode.QUALIFIED_NAME, 40);
- assertSame(ASTNode.RETURN_STATEMENT, 41);
- assertSame(ASTNode.SIMPLE_NAME, 42);
- assertSame(ASTNode.SIMPLE_TYPE, 43);
- assertSame(ASTNode.SINGLE_VARIABLE_DECLARATION, 44);
- assertSame(ASTNode.STRING_LITERAL, 45);
- assertSame(ASTNode.SUPER_CONSTRUCTOR_INVOCATION, 46);
- assertSame(ASTNode.SUPER_FIELD_ACCESS, 47);
- assertSame(ASTNode.SUPER_METHOD_INVOCATION, 48);
- assertSame(ASTNode.SWITCH_CASE, 49);
- assertSame(ASTNode.SWITCH_STATEMENT, 50);
- assertSame(ASTNode.SYNCHRONIZED_STATEMENT, 51);
- assertSame(ASTNode.THIS_EXPRESSION, 52);
- assertSame(ASTNode.THROW_STATEMENT, 53);
- assertSame(ASTNode.TRY_STATEMENT, 54);
- assertSame(ASTNode.TYPE_DECLARATION, 55);
- assertSame(ASTNode.TYPE_DECLARATION_STATEMENT, 56);
- assertSame(ASTNode.TYPE_LITERAL, 57);
- assertSame(ASTNode.VARIABLE_DECLARATION_EXPRESSION, 58);
- assertSame(ASTNode.VARIABLE_DECLARATION_FRAGMENT, 59);
- assertSame(ASTNode.VARIABLE_DECLARATION_STATEMENT, 60);
- assertSame(ASTNode.WHILE_STATEMENT, 61);
- assertSame(ASTNode.INSTANCEOF_EXPRESSION, 62);
- assertSame(ASTNode.LINE_COMMENT, 63);
- assertSame(ASTNode.BLOCK_COMMENT, 64);
- assertSame(ASTNode.TAG_ELEMENT, 65);
- assertSame(ASTNode.TEXT_ELEMENT, 66);
- assertSame(ASTNode.MEMBER_REF, 67);
- assertSame(ASTNode.METHOD_REF, 68);
- assertSame(ASTNode.METHOD_REF_PARAMETER, 69);
- assertSame(ASTNode.ENHANCED_FOR_STATEMENT, 70);
- assertSame(ASTNode.ENUM_DECLARATION, 71);
- assertSame(ASTNode.ENUM_CONSTANT_DECLARATION, 72);
- assertSame(ASTNode.TYPE_PARAMETER, 73);
- assertSame(ASTNode.PARAMETERIZED_TYPE, 74);
- assertSame(ASTNode.QUALIFIED_TYPE, 75);
- assertSame(ASTNode.WILDCARD_TYPE, 76);
- assertSame(ASTNode.NORMAL_ANNOTATION, 77);
- assertSame(ASTNode.MARKER_ANNOTATION, 78);
- assertSame(ASTNode.SINGLE_MEMBER_ANNOTATION, 79);
- assertSame(ASTNode.MEMBER_VALUE_PAIR, 80);
- assertSame(ASTNode.ANNOTATION_TYPE_DECLARATION, 81);
- assertSame(ASTNode.ANNOTATION_TYPE_MEMBER_DECLARATION, 82);
- assertSame(ASTNode.MODIFIER, 83);
-
- // ensure that all constants are distinct, positive, and small
- // (this may seem paranoid, but this test did uncover a stupid bug!)
- int[] all= {
- ASTNode.ANNOTATION_TYPE_DECLARATION,
- ASTNode.ANNOTATION_TYPE_MEMBER_DECLARATION,
- ASTNode.ANONYMOUS_CLASS_DECLARATION,
- ASTNode.ARRAY_ACCESS,
- ASTNode.ARRAY_CREATION,
- ASTNode.ARRAY_INITIALIZER,
- ASTNode.ARRAY_TYPE,
- ASTNode.ASSERT_STATEMENT,
- ASTNode.ASSIGNMENT,
- ASTNode.BLOCK,
- ASTNode.BLOCK_COMMENT,
- ASTNode.BOOLEAN_LITERAL,
- ASTNode.BREAK_STATEMENT,
- ASTNode.CAST_EXPRESSION,
- ASTNode.CATCH_CLAUSE,
- ASTNode.CHARACTER_LITERAL,
- ASTNode.CLASS_INSTANCE_CREATION,
- ASTNode.COMPILATION_UNIT,
- ASTNode.CONDITIONAL_EXPRESSION,
- ASTNode.CONSTRUCTOR_INVOCATION,
- ASTNode.CONTINUE_STATEMENT,
- ASTNode.DO_STATEMENT,
- ASTNode.EMPTY_STATEMENT,
- ASTNode.ENHANCED_FOR_STATEMENT,
- ASTNode.ENUM_CONSTANT_DECLARATION,
- ASTNode.ENUM_DECLARATION,
- ASTNode.EXPRESSION_STATEMENT,
- ASTNode.FIELD_ACCESS,
- ASTNode.FIELD_DECLARATION,
- ASTNode.FOR_STATEMENT,
- ASTNode.IF_STATEMENT,
- ASTNode.IMPORT_DECLARATION,
- ASTNode.INFIX_EXPRESSION,
- ASTNode.INSTANCEOF_EXPRESSION,
- ASTNode.INITIALIZER,
- ASTNode.JAVADOC,
- ASTNode.LABELED_STATEMENT,
- ASTNode.LINE_COMMENT,
- ASTNode.MARKER_ANNOTATION,
- ASTNode.MEMBER_REF,
- ASTNode.MEMBER_VALUE_PAIR,
- ASTNode.METHOD_DECLARATION,
- ASTNode.METHOD_INVOCATION,
- ASTNode.METHOD_REF,
- ASTNode.METHOD_REF_PARAMETER,
- ASTNode.MODIFIER,
- ASTNode.NORMAL_ANNOTATION,
- ASTNode.NULL_LITERAL,
- ASTNode.NUMBER_LITERAL,
- ASTNode.PACKAGE_DECLARATION,
- ASTNode.PARAMETERIZED_TYPE,
- ASTNode.PARENTHESIZED_EXPRESSION,
- ASTNode.POSTFIX_EXPRESSION,
- ASTNode.PREFIX_EXPRESSION,
- ASTNode.PRIMITIVE_TYPE,
- ASTNode.QUALIFIED_NAME,
- ASTNode.QUALIFIED_TYPE,
- ASTNode.RETURN_STATEMENT,
- ASTNode.SIMPLE_NAME,
- ASTNode.SIMPLE_TYPE,
- ASTNode.SINGLE_MEMBER_ANNOTATION,
- ASTNode.SINGLE_VARIABLE_DECLARATION,
- ASTNode.STRING_LITERAL,
- ASTNode.SUPER_CONSTRUCTOR_INVOCATION,
- ASTNode.SUPER_FIELD_ACCESS,
- ASTNode.SUPER_METHOD_INVOCATION,
- ASTNode.SWITCH_CASE,
- ASTNode.SWITCH_STATEMENT,
- ASTNode.SYNCHRONIZED_STATEMENT,
- ASTNode.TAG_ELEMENT,
- ASTNode.TEXT_ELEMENT,
- ASTNode.THIS_EXPRESSION,
- ASTNode.THROW_STATEMENT,
- ASTNode.TRY_STATEMENT,
- ASTNode.TYPE_DECLARATION,
- ASTNode.TYPE_DECLARATION_STATEMENT,
- ASTNode.TYPE_LITERAL,
- ASTNode.TYPE_PARAMETER,
- ASTNode.VARIABLE_DECLARATION_EXPRESSION,
- ASTNode.VARIABLE_DECLARATION_FRAGMENT,
- ASTNode.VARIABLE_DECLARATION_STATEMENT,
- ASTNode.WHILE_STATEMENT,
- ASTNode.WILDCARD_TYPE,
+ int[] nodeTypes = {
+ ASTNode.ANONYMOUS_CLASS_DECLARATION,
+ ASTNode.ARRAY_ACCESS,
+ ASTNode.ARRAY_CREATION,
+ ASTNode.ARRAY_INITIALIZER,
+ ASTNode.ARRAY_TYPE,
+ ASTNode.ASSERT_STATEMENT,
+ ASTNode.ASSIGNMENT,
+ ASTNode.BLOCK,
+ ASTNode.BOOLEAN_LITERAL,
+ ASTNode.BREAK_STATEMENT,
+ ASTNode.CAST_EXPRESSION,
+ ASTNode.CATCH_CLAUSE,
+ ASTNode.CHARACTER_LITERAL,
+ ASTNode.CLASS_INSTANCE_CREATION,
+ ASTNode.COMPILATION_UNIT,
+ ASTNode.CONDITIONAL_EXPRESSION,
+ ASTNode.CONSTRUCTOR_INVOCATION,
+ ASTNode.CONTINUE_STATEMENT,
+ ASTNode.DO_STATEMENT,
+ ASTNode.EMPTY_STATEMENT,
+ ASTNode.EXPRESSION_STATEMENT,
+ ASTNode.FIELD_ACCESS,
+ ASTNode.FIELD_DECLARATION,
+ ASTNode.FOR_STATEMENT,
+ ASTNode.IF_STATEMENT,
+ ASTNode.IMPORT_DECLARATION,
+ ASTNode.INFIX_EXPRESSION,
+ ASTNode.INITIALIZER,
+ ASTNode.JAVADOC,
+ ASTNode.LABELED_STATEMENT,
+ ASTNode.METHOD_DECLARATION,
+ ASTNode.METHOD_INVOCATION,
+ ASTNode.NULL_LITERAL,
+ ASTNode.NUMBER_LITERAL,
+ ASTNode.PACKAGE_DECLARATION,
+ ASTNode.PARENTHESIZED_EXPRESSION,
+ ASTNode.POSTFIX_EXPRESSION,
+ ASTNode.PREFIX_EXPRESSION,
+ ASTNode.PRIMITIVE_TYPE,
+ ASTNode.QUALIFIED_NAME,
+ ASTNode.RETURN_STATEMENT,
+ ASTNode.SIMPLE_NAME,
+ ASTNode.SIMPLE_TYPE,
+ ASTNode.SINGLE_VARIABLE_DECLARATION,
+ ASTNode.STRING_LITERAL,
+ ASTNode.SUPER_CONSTRUCTOR_INVOCATION,
+ ASTNode.SUPER_FIELD_ACCESS,
+ ASTNode.SUPER_METHOD_INVOCATION,
+ ASTNode.SWITCH_CASE,
+ ASTNode.SWITCH_STATEMENT,
+ ASTNode.SYNCHRONIZED_STATEMENT,
+ ASTNode.THIS_EXPRESSION,
+ ASTNode.THROW_STATEMENT,
+ ASTNode.TRY_STATEMENT,
+ ASTNode.TYPE_DECLARATION,
+ ASTNode.TYPE_DECLARATION_STATEMENT,
+ ASTNode.TYPE_LITERAL,
+ ASTNode.VARIABLE_DECLARATION_EXPRESSION,
+ ASTNode.VARIABLE_DECLARATION_FRAGMENT,
+ ASTNode.VARIABLE_DECLARATION_STATEMENT,
+ ASTNode.WHILE_STATEMENT,
+ ASTNode.INSTANCEOF_EXPRESSION,
+ ASTNode.LINE_COMMENT,
+ ASTNode.BLOCK_COMMENT,
+ ASTNode.TAG_ELEMENT,
+ ASTNode.TEXT_ELEMENT,
+ ASTNode.MEMBER_REF,
+ ASTNode.METHOD_REF,
+ ASTNode.METHOD_REF_PARAMETER,
+ ASTNode.ENHANCED_FOR_STATEMENT,
+ ASTNode.ENUM_DECLARATION,
+ ASTNode.ENUM_CONSTANT_DECLARATION,
+ ASTNode.TYPE_PARAMETER,
+ ASTNode.PARAMETERIZED_TYPE,
+ ASTNode.QUALIFIED_TYPE,
+ ASTNode.WILDCARD_TYPE,
+ ASTNode.NORMAL_ANNOTATION,
+ ASTNode.MARKER_ANNOTATION,
+ ASTNode.SINGLE_MEMBER_ANNOTATION,
+ ASTNode.MEMBER_VALUE_PAIR,
+ ASTNode.ANNOTATION_TYPE_DECLARATION,
+ ASTNode.ANNOTATION_TYPE_MEMBER_DECLARATION,
+ ASTNode.MODIFIER,
+ ASTNode.UNION_TYPE,
+ ASTNode.EXTRA_DIMENSION,
+ ASTNode.LAMBDA_EXPRESSION,
+ ASTNode.INTERSECTION_TYPE,
+ ASTNode.PACKAGE_QUALIFIED_TYPE,
};
- int MIN = 1;
- int MAX = 100;
- Set s = new HashSet();
- for (int i=0; i<all.length; i++) {
- assertTrue(MIN <= all[i] && all[i] <= MAX);
- s.add(new Integer(all[i]));
+
+ // assert that nodeType values are correct:
+ for (int i= 0; i < nodeTypes.length; i++) {
+ assertSame(i + 1, nodeTypes[i]);
}
- assertTrue(s.size() == all.length);
- // ensure that Integers really do compare properly with equals
- assertTrue(new Integer(1).equals(new Integer(1)));
+
+ // test nodeClassForType:
+ for (int i= 0; i < nodeTypes.length; i++) {
+ int nodeType = nodeTypes[i];
+ ASTNode node;
+ try {
+ node = this.ast.createInstance(nodeType);
+ } catch (IllegalArgumentException e) {
+ if (this.API_LEVEL < AST.JLS8 && e.getCause() instanceof UnsupportedOperationException) {
+ continue;
+ } else {
+ throw new AssertionFailedError("missing node type: " + nodeType);
+ }
+ }
+ assertEquals(nodeType, node.getNodeType());
+ }
+
+ // assert that test covers all nodeTypes:
+ Field[] fields = ASTNode.class.getDeclaredFields();
+ HashSet declaredNodeTypes = new HashSet();
+ for (int i= 0; i < fields.length; i++) {
+ Field field= fields[i];
+ if (field.getType() != int.class)
+ continue;
+ if (field.getModifiers() != (java.lang.reflect.Modifier.PUBLIC | java.lang.reflect.Modifier.STATIC | java.lang.reflect.Modifier.FINAL))
+ continue;
+ String name = field.getName();
+ if ("MALFORMED".equals(name) || "ORIGINAL".equals(name) || "PROTECT".equals(name) || "RECOVERED".equals(name))
+ continue;
+ declaredNodeTypes.add(new Integer(field.getInt(null)));
+ }
+ for (int i= 0; i < nodeTypes.length; i++) {
+ int nodeType= nodeTypes[i];
+ assertTrue("node type " + nodeType + " from test is missing in ASTNode", declaredNodeTypes.remove(new Integer(nodeType)));
+ nodeTypes[i] = -1;
+ }
+ for (int i= 0; i < nodeTypes.length; i++) {
+ int nodeType= nodeTypes[i];
+ assertEquals("node type " + nodeType + " missing in ASTNode", -1, nodeType);
+ }
+ assertEquals("node types missing in test", Collections.EMPTY_SET, declaredNodeTypes);
}
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTVisitorTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTVisitorTest.java
index 0072ed8..ff0db3a 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTVisitorTest.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTVisitorTest.java
@@ -383,6 +383,13 @@
ASTVisitorTest.this.b.append(node.getPrimitiveTypeCode().toString());
ASTVisitorTest.this.b.append("tP)"); //$NON-NLS-1$
}
+ public boolean visit(PackageQualifiedType node) {
+ ASTVisitorTest.this.b.append("(tPQ"); //$NON-NLS-1$
+ return isVisitingChildren();
+ }
+ public void endVisit(PackageQualifiedType node) {
+ ASTVisitorTest.this.b.append("tPQ)"); //$NON-NLS-1$
+ }
public boolean visit(ParameterizedType node) {
ASTVisitorTest.this.b.append("(tM"); //$NON-NLS-1$
return isVisitingChildren();
@@ -1122,6 +1129,20 @@
}
/** @deprecated using deprecated code */
+ public void testPackageQualifiedType() {
+ if (this.ast.apiLevel() < AST.JLS8) {
+ return;
+ }
+ QualifiedName q = this.ast.newQualifiedName(this.N2, this.N3);
+ PackageQualifiedType x1 = this.ast.newPackageQualifiedType(q, this.N1);
+ TestVisitor v1 = new TestVisitor();
+ this.b.setLength(0);
+ x1.accept(v1);
+ String result = this.b.toString();
+ assertTrue(result.equals("[(tPQ"+"[(nQ"+this.N2S+this.N3S+"nQ)]"+this.N1S+"tPQ)]")); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /** @deprecated using deprecated code */
public void testParameterizedType() {
if (this.ast.apiLevel() == AST.JLS2) {
return;
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/SampleASTs.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/SampleASTs.java
index b23fda1..7536623 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/SampleASTs.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/SampleASTs.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2012 IBM Corporation and others.
+ * Copyright (c) 2004, 2013 IBM Corporation and others.
* 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
@@ -22,6 +22,12 @@
* @deprecated
*/
/*package*/ static final int JLS3_INTERNAL = AST.JLS3;
+ /**
+ * Internal synonym for deprecated constant AST.JSL4
+ * to alleviate deprecation warnings.
+ * @deprecated
+ */
+ /*package*/ static final int JLS4_INTERNAL = AST.JLS4;
/**
* Returns a subtree of sample of AST nodes. The sample includes
@@ -86,6 +92,10 @@
pmt.typeArguments().add(qt);
md.setReturnType2(pmt);
}
+ if (target.apiLevel() >= AST.JLS8) {
+ ExtraDimension ed = target.newExtraDimension();
+ md.extraDimensions().add(ed);
+ }
Block b = target.newBlock();
md.setBody(b);
@@ -138,6 +148,10 @@
CatchClause catchClause = target.newCatchClause();
tr.catchClauses().add(catchClause);
b.statements().add(tr);
+ if (target.apiLevel() >= JLS4_INTERNAL) {
+ UnionType ut = target.newUnionType();
+ catchClause.getException().setType(ut);
+ }
TypeDeclaration typeDeclaration = target.newTypeDeclaration();
TypeDeclarationStatement typeDeclarationStatement = target.newTypeDeclarationStatement(typeDeclaration);
@@ -165,6 +179,10 @@
z.add(booleanLiteral);
CastExpression castExpression = target.newCastExpression();
z.add(castExpression);
+ if (target.apiLevel() >= AST.JLS8) {
+ IntersectionType it = target.newIntersectionType();
+ castExpression.setType(it);
+ }
CharacterLiteral characterLiteral = target.newCharacterLiteral();
z.add(characterLiteral);
ClassInstanceCreation cic = target.newClassInstanceCreation();
@@ -179,6 +197,10 @@
z.add(infixExpression);
InstanceofExpression instanceofExpression = target.newInstanceofExpression();
z.add(instanceofExpression);
+ if (target.apiLevel() >= AST.JLS8) {
+ LambdaExpression lambdaExpression = target.newLambdaExpression();
+ z.add(lambdaExpression);
+ }
MethodInvocation methodInvocation = target.newMethodInvocation();
z.add(methodInvocation);
Name name = target.newName(new String[]{"a", "b"}); //$NON-NLS-1$ //$NON-NLS-2$
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests.java
index 2b22377..234f13d 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests.java
@@ -1054,6 +1054,12 @@
suite.addTest(new CompletionTests("testBug385858b"));
suite.addTest(new CompletionTests("testBug385858c"));
suite.addTest(new CompletionTests("testBug385858d"));
+ suite.addTest(new CompletionTests("testBug402574"));
+ suite.addTest(new CompletionTests("testBug402812a"));
+ suite.addTest(new CompletionTests("testBug402812b"));
+ suite.addTest(new CompletionTests("testBug402812c"));
+ suite.addTest(new CompletionTests("testBug402812d"));
+
return suite;
}
public CompletionTests(String name) {
@@ -25950,4 +25956,224 @@
"completion token location={CONSTRUCTOR_START}",
requestor.getContext());
}
+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=402812
+//Bug 402812 - [1.8][completion] Code Completion problems with static/default interface methods.
+public void testBug402812a() throws Exception {
+ Hashtable javaCoreOldOptions = JavaCore.getOptions();
+ Map completionProjectOptions = COMPLETION_PROJECT.getOptions(true);
+ Object savedOptionCompliance = completionProjectOptions.get(CompilerOptions.OPTION_Compliance);
+ Object savedOptionSource = completionProjectOptions.get(CompilerOptions.OPTION_Source);
+ try {
+ Hashtable options = new Hashtable(javaCoreOldOptions);
+ options.put(JavaCore.CODEASSIST_VISIBILITY_CHECK, JavaCore.ENABLED);
+ JavaCore.setOptions(options);
+
+ completionProjectOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_8);
+ completionProjectOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_8);
+ COMPLETION_PROJECT.setOptions(completionProjectOptions);
+
+ IJavaProject p = createJavaProject("P", new String[] {"src"}, new String[]{"JCL_LIB", "/P/lib402812.jar"}, "bin");
+
+ refresh(p);
+
+ waitUntilIndexesReady();
+
+ this.workingCopies = new ICompilationUnit[1];
+
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/test/Test.java",
+ "interface Test { \n" +
+ "static void staticMethod() {}" +
+ " default void defaultMethod() {" +
+ " stat" +
+ " }" +
+ "}\n");
+ // do completion
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, false, true, true);
+ requestor.allowAllRequiredProposals();
+ NullProgressMonitor monitor = new NullProgressMonitor();
+
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = " stat";
+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner, monitor);
+
+ assertResults(
+ "staticMethod[METHOD_REF]{staticMethod(), Ltest.Test;, ()V, staticMethod, null, 27}",
+ requestor.getResults());
+ } finally {
+ deleteProject("P");
+
+ JavaCore.setOptions(javaCoreOldOptions);
+ completionProjectOptions.put(CompilerOptions.OPTION_Compliance, savedOptionCompliance);
+ completionProjectOptions.put(CompilerOptions.OPTION_Source, savedOptionSource);
+ COMPLETION_PROJECT.setOptions(completionProjectOptions);
+ }
+}
+public void testBug402812b() throws Exception {
+ Hashtable javaCoreOldOptions = JavaCore.getOptions();
+ Map completionProjectOptions = COMPLETION_PROJECT.getOptions(true);
+ Object savedOptionCompliance = completionProjectOptions.get(CompilerOptions.OPTION_Compliance);
+ Object savedOptionSource = completionProjectOptions.get(CompilerOptions.OPTION_Source);
+ try {
+ Hashtable options = new Hashtable(javaCoreOldOptions);
+ options.put(JavaCore.CODEASSIST_VISIBILITY_CHECK, JavaCore.ENABLED);
+ JavaCore.setOptions(options);
+
+ completionProjectOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_8);
+ completionProjectOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_8);
+ COMPLETION_PROJECT.setOptions(completionProjectOptions);
+
+ IJavaProject p = createJavaProject("P", new String[] {"src"}, new String[]{"JCL_LIB", "/P/lib402812.jar"}, "bin");
+
+ refresh(p);
+
+ waitUntilIndexesReady();
+
+ this.workingCopies = new ICompilationUnit[1];
+
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/test/Test.java",
+ "interface I { \n" +
+ " static void staticMethod() {}" +
+ " default void defaultMethod() {}" +
+ "}" +
+ "public class X implements I {" +
+ " public void foo(I i) {" +
+ " I.stat " +
+ " }" +
+ "}\n");
+ // do completion
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, false, true, true);
+ requestor.allowAllRequiredProposals();
+ NullProgressMonitor monitor = new NullProgressMonitor();
+
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "I.stat";
+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner, monitor);
+
+ assertResults(
+ "staticMethod[METHOD_REF]{staticMethod(), Ltest.I;, ()V, staticMethod, null, 26}",
+ requestor.getResults());
+ } finally {
+ deleteProject("P");
+
+ JavaCore.setOptions(javaCoreOldOptions);
+ completionProjectOptions.put(CompilerOptions.OPTION_Compliance, savedOptionCompliance);
+ completionProjectOptions.put(CompilerOptions.OPTION_Source, savedOptionSource);
+ COMPLETION_PROJECT.setOptions(completionProjectOptions);
+ }
+}
+public void testBug402812c() throws Exception {
+ Hashtable javaCoreOldOptions = JavaCore.getOptions();
+ Map completionProjectOptions = COMPLETION_PROJECT.getOptions(true);
+ Object savedOptionCompliance = completionProjectOptions.get(CompilerOptions.OPTION_Compliance);
+ Object savedOptionSource = completionProjectOptions.get(CompilerOptions.OPTION_Source);
+ try {
+ Hashtable options = new Hashtable(javaCoreOldOptions);
+ options.put(JavaCore.CODEASSIST_VISIBILITY_CHECK, JavaCore.ENABLED);
+ JavaCore.setOptions(options);
+
+ completionProjectOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_8);
+ completionProjectOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_8);
+ COMPLETION_PROJECT.setOptions(completionProjectOptions);
+
+ IJavaProject p = createJavaProject("P", new String[] {"src"}, new String[]{"JCL_LIB", "/P/lib402812.jar"}, "bin");
+
+ refresh(p);
+
+ waitUntilIndexesReady();
+
+ this.workingCopies = new ICompilationUnit[1];
+
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/test/Test.java",
+ "interface I { \n" +
+ "static void staticMethod() {}" +
+ " default void defaultMethod() {" +
+ " }" +
+ "}" +
+ "public class X implements I {" +
+ " public void foo(I i) {" +
+ " this.defa " +
+ " }" +
+ "}\n");
+ // do completion
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, false, true, true);
+ requestor.allowAllRequiredProposals();
+ NullProgressMonitor monitor = new NullProgressMonitor();
+
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "this.defa";
+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner, monitor);
+
+ assertResults(
+ "defaultMethod[METHOD_REF]{defaultMethod(), Ltest.I;, ()V, defaultMethod, null, 35}",
+ requestor.getResults());
+ } finally {
+ deleteProject("P");
+
+ JavaCore.setOptions(javaCoreOldOptions);
+ completionProjectOptions.put(CompilerOptions.OPTION_Compliance, savedOptionCompliance);
+ completionProjectOptions.put(CompilerOptions.OPTION_Source, savedOptionSource);
+ COMPLETION_PROJECT.setOptions(completionProjectOptions);
+ }
+}
+public void testBug402812d() throws Exception {
+ Hashtable javaCoreOldOptions = JavaCore.getOptions();
+ Map completionProjectOptions = COMPLETION_PROJECT.getOptions(true);
+ Object savedOptionCompliance = completionProjectOptions.get(CompilerOptions.OPTION_Compliance);
+ Object savedOptionSource = completionProjectOptions.get(CompilerOptions.OPTION_Source);
+ try {
+ Hashtable options = new Hashtable(javaCoreOldOptions);
+ options.put(JavaCore.CODEASSIST_VISIBILITY_CHECK, JavaCore.ENABLED);
+ JavaCore.setOptions(options);
+
+ completionProjectOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_8);
+ completionProjectOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_8);
+ COMPLETION_PROJECT.setOptions(completionProjectOptions);
+
+ IJavaProject p = createJavaProject("P", new String[] {"src"}, new String[]{"JCL_LIB", "/P/lib402812.jar"}, "bin");
+
+ refresh(p);
+
+ waitUntilIndexesReady();
+
+ this.workingCopies = new ICompilationUnit[1];
+
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/test/Test.java",
+ "interface I { \n" +
+ " static void staticMethod() {}" +
+ " default void defaultMethod() {}" +
+ "}" +
+ "public class X implements I {" +
+ " public void foo(I i) {" +
+ " defaultM " +
+ " }" +
+ "}\n");
+ // do completion
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, false, true, true);
+ requestor.allowAllRequiredProposals();
+ NullProgressMonitor monitor = new NullProgressMonitor();
+
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "defaultM";
+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner, monitor);
+
+ assertResults(
+ "defaultMethod[METHOD_REF]{defaultMethod(), Ltest.I;, ()V, defaultMethod, null, 27}",
+ requestor.getResults());
+ } finally {
+ deleteProject("P");
+
+ JavaCore.setOptions(javaCoreOldOptions);
+ completionProjectOptions.put(CompilerOptions.OPTION_Compliance, savedOptionCompliance);
+ completionProjectOptions.put(CompilerOptions.OPTION_Source, savedOptionSource);
+ COMPLETION_PROJECT.setOptions(completionProjectOptions);
+ }
+}
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugs8Tests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugs8Tests.java
new file mode 100644
index 0000000..d53f243
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugs8Tests.java
@@ -0,0 +1,1590 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2013 IBM Corporation and others.
+ * 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.core.tests.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.WorkingCopyOwner;
+import org.eclipse.jdt.core.search.IJavaSearchScope;
+import org.eclipse.jdt.core.search.ReferenceMatch;
+import org.eclipse.jdt.core.search.SearchEngine;
+import org.eclipse.jdt.core.search.SearchMatch;
+import org.eclipse.jdt.core.search.SearchParticipant;
+import org.eclipse.jdt.core.search.SearchPattern;
+import org.eclipse.jdt.core.search.TypeReferenceMatch;
+
+/**
+ * Non-regression tests for bugs fixed in Java Search engine.
+ */
+public class JavaSearchBugs8Tests extends AbstractJavaSearchTests {
+
+ static {
+// org.eclipse.jdt.internal.core.search.BasicSearchEngine.VERBOSE = true;
+// TESTS_NAMES = new String[] {"testBug400899g29"};
+}
+
+public JavaSearchBugs8Tests(String name) {
+ super(name);
+ this.endChar = "";
+}
+public static Test suite() {
+ if (TESTS_PREFIX != null || TESTS_NAMES != null || TESTS_NUMBERS!=null || TESTS_RANGE !=null) {
+ return buildModelTestSuite(JavaSearchBugs8Tests.class);
+ }
+ // hack to guarantee the test order
+ TestSuite suite = new Suite(JavaSearchBugs8Tests.class.getName());
+ suite.addTest(new JavaSearchBugs8Tests("testBug400899g1"));
+ suite.addTest(new JavaSearchBugs8Tests("testBug400899g2"));
+ suite.addTest(new JavaSearchBugs8Tests("testBug400899g3"));
+ suite.addTest(new JavaSearchBugs8Tests("testBug400899g4"));
+ suite.addTest(new JavaSearchBugs8Tests("testBug400899g5"));
+ suite.addTest(new JavaSearchBugs8Tests("testBug400899g6"));
+ suite.addTest(new JavaSearchBugs8Tests("testBug400899g7"));
+ suite.addTest(new JavaSearchBugs8Tests("testBug400899g8"));
+ suite.addTest(new JavaSearchBugs8Tests("testBug400899g9"));
+ suite.addTest(new JavaSearchBugs8Tests("testBug400899g10"));
+ suite.addTest(new JavaSearchBugs8Tests("testBug400899g11"));
+ suite.addTest(new JavaSearchBugs8Tests("testBug400899g12"));
+ suite.addTest(new JavaSearchBugs8Tests("testBug400899g13"));
+ suite.addTest(new JavaSearchBugs8Tests("testBug400899g14"));
+ suite.addTest(new JavaSearchBugs8Tests("testBug400899g15"));
+ suite.addTest(new JavaSearchBugs8Tests("testBug400899g16"));
+ suite.addTest(new JavaSearchBugs8Tests("testBug400899g17"));
+// suite.addTest(new JavaSearchBugs8Tests("testBug400899g18"));
+// suite.addTest(new JavaSearchBugs8Tests("testBug400899g19"));
+ suite.addTest(new JavaSearchBugs8Tests("testBug400899g20"));
+// suite.addTest(new JavaSearchBugs8Tests("testBug400899g22"));
+ suite.addTest(new JavaSearchBugs8Tests("testBug400899g23"));
+ suite.addTest(new JavaSearchBugs8Tests("testBug400899g24"));
+// suite.addTest(new JavaSearchBugs8Tests("testBug400899g25"));
+ suite.addTest(new JavaSearchBugs8Tests("testBug400899g26"));
+ suite.addTest(new JavaSearchBugs8Tests("testBug400899g27"));
+ suite.addTest(new JavaSearchBugs8Tests("testBug400899g28"));
+// suite.addTest(new JavaSearchBugs8Tests("testBug400899g29"));
+ suite.addTest(new JavaSearchBugs8Tests("testBug400899g30"));
+ suite.addTest(new JavaSearchBugs8Tests("testBug400899g31"));
+ suite.addTest(new JavaSearchBugs8Tests("testBug400899g32"));
+ suite.addTest(new JavaSearchBugs8Tests("testBug400899g33"));
+ suite.addTest(new JavaSearchBugs8Tests("testBug400899g34"));
+ suite.addTest(new JavaSearchBugs8Tests("testBug400899g35"));
+ suite.addTest(new JavaSearchBugs8Tests("testBug400899g36"));
+ suite.addTest(new JavaSearchBugs8Tests("testBug400899g37"));
+ suite.addTest(new JavaSearchBugs8Tests("testBug400899g38"));
+ suite.addTest(new JavaSearchBugs8Tests("testBug400902"));
+ return suite;
+}
+class TestCollector extends JavaSearchResultCollector {
+ public List matches = new ArrayList();
+ public void acceptSearchMatch(SearchMatch searchMatch) throws CoreException {
+ super.acceptSearchMatch(searchMatch);
+ this.matches.add(searchMatch);
+ }
+}
+class ReferenceCollector extends JavaSearchResultCollector {
+ protected void writeLine() throws CoreException {
+ super.writeLine();
+ ReferenceMatch refMatch = (ReferenceMatch) this.match;
+ IJavaElement localElement = refMatch.getLocalElement();
+ if (localElement != null) {
+ this.line.append("+[");
+ if (localElement.getElementType() == IJavaElement.ANNOTATION) {
+ this.line.append('@');
+ this.line.append(localElement.getElementName());
+ this.line.append(" on ");
+ this.line.append(localElement.getParent().getElementName());
+ } else {
+ this.line.append(localElement.getElementName());
+ }
+ this.line.append(']');
+ }
+ }
+
+}
+class TypeReferenceCollector extends ReferenceCollector {
+ protected void writeLine() throws CoreException {
+ super.writeLine();
+ TypeReferenceMatch typeRefMatch = (TypeReferenceMatch) this.match;
+ IJavaElement[] others = typeRefMatch.getOtherElements();
+ int length = others==null ? 0 : others.length;
+ if (length > 0) {
+ this.line.append("+[");
+ for (int i=0; i<length; i++) {
+ IJavaElement other = others[i];
+ if (i>0) this.line.append(',');
+ if (other.getElementType() == IJavaElement.ANNOTATION) {
+ this.line.append('@');
+ this.line.append(other.getElementName());
+ this.line.append(" on ");
+ this.line.append(other.getParent().getElementName());
+ } else {
+ this.line.append(other.getElementName());
+ }
+ }
+ this.line.append(']');
+ }
+ }
+}
+
+IJavaSearchScope getJavaSearchScope() {
+ return SearchEngine.createJavaSearchScope(new IJavaProject[] {getJavaProject("JavaSearchBugs")});
+}
+IJavaSearchScope getJavaSearchScopeBugs(String packageName, boolean addSubpackages) throws JavaModelException {
+ if (packageName == null) return getJavaSearchScope();
+ return getJavaSearchPackageScope("JavaSearchBugs", packageName, addSubpackages);
+}
+public ICompilationUnit getWorkingCopy(String path, String source) throws JavaModelException {
+ if (this.wcOwner == null) {
+ this.wcOwner = new WorkingCopyOwner() {};
+ }
+ return getWorkingCopy(path, source, this.wcOwner);
+}
+/* (non-Javadoc)
+ * @see org.eclipse.jdt.core.tests.model.SuiteOfTestCases#setUpSuite()
+ */
+public void setUpSuite() throws Exception {
+ super.setUpSuite();
+ JAVA_PROJECT = setUpJavaProject("JavaSearchBugs", "1.8");
+}
+public void tearDownSuite() throws Exception {
+ deleteProject("JavaSearchBugs");
+ super.tearDownSuite();
+}
+protected void setUp () throws Exception {
+ super.setUp();
+ this.resultCollector = new TestCollector();
+ this.resultCollector.showAccuracy(true);
+}
+
+/**
+ * @bug 400899: [1.8][search] Search engine/indexer should evolve to support Java 8 constructs
+ * @test Ensures that the search for type use annotation finds matches in the following
+ * FieldDeclaration ::= Modifiersopt Type VariableDeclarators ';'
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=400899"
+ */
+public void testBug400899g1() throws CoreException {
+this.workingCopies = new ICompilationUnit[1];
+this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b400899/X.java",
+ "import java.lang.annotation.ElementType;\n" +
+ "import java.lang.annotation.Target;\n" +
+ "public class X {\n" +
+ " @Marker int x;\n" +
+ "}\n" +
+ "@Target(ElementType.TYPE_USE)\n" +
+ "@interface Marker {}\n"
+ );
+SearchPattern pattern = SearchPattern.createPattern(
+ "Marker",
+ ANNOTATION_TYPE,
+ REFERENCES,
+ EXACT_RULE);
+new SearchEngine(this.workingCopies).search(pattern,
+new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
+getJavaSearchWorkingCopiesScope(),
+this.resultCollector,
+null);
+assertSearchResults(
+ "src/b400899/X.java b400899.X.x [Marker] EXACT_MATCH"
+);
+}
+
+/**
+ * @bug 400899: [1.8][search] Search engine/indexer should evolve to support Java 8 constructs
+ * @test Ensures that the search for type use annotation finds matches in the following
+ * TYPE: MethodHeaderName ::= Modifiersopt TypeParameters Type 'Identifier' '('
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=400899"
+ */
+public void testBug400899g2() throws CoreException {
+this.workingCopies = new ICompilationUnit[1];
+this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b400899/X.java",
+ "import java.lang.annotation.ElementType;\n" +
+ "import java.lang.annotation.Target;\n" +
+ "public class X {\n" +
+ " @Marker <T> int x() { return 10; };\n" +
+ "}\n" +
+ "@Target(ElementType.TYPE_USE)\n" +
+ "@interface Marker {}\n"
+ );
+SearchPattern pattern = SearchPattern.createPattern(
+ "Marker",
+ ANNOTATION_TYPE,
+ REFERENCES,
+ EXACT_RULE);
+new SearchEngine(this.workingCopies).search(pattern,
+new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
+getJavaSearchWorkingCopiesScope(),
+this.resultCollector,
+null);
+assertSearchResults(
+ "src/b400899/X.java int b400899.X.x() [Marker] EXACT_MATCH"
+);
+}
+
+/**
+ * @bug 400899: [1.8][search] Search engine/indexer should evolve to support Java 8 constructs
+ * @test Ensures that the search for type use annotation finds matches in the following
+ * FormalParameter ::= Modifiersopt Type VariableDeclaratorIdOrThis
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=400899"
+ */
+public void testBug400899g3() throws CoreException {
+this.workingCopies = new ICompilationUnit[1];
+this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b400899/X.java",
+ "import java.lang.annotation.ElementType;\n" +
+ "import java.lang.annotation.Target;\n" +
+ "public class X {\n" +
+ " int x(@Marker int p) { return 10; };\n" +
+ "}\n" +
+ "@Target(ElementType.TYPE_USE)\n" +
+ "@interface Marker {}\n"
+ );
+SearchPattern pattern = SearchPattern.createPattern(
+ "Marker",
+ ANNOTATION_TYPE,
+ REFERENCES,
+ EXACT_RULE);
+new SearchEngine(this.workingCopies).search(pattern,
+new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
+getJavaSearchWorkingCopiesScope(),
+this.resultCollector,
+null);
+assertSearchResults(
+ "src/b400899/X.java int b400899.X.x(int) [Marker] EXACT_MATCH"
+);
+}
+
+/**
+ * @bug 400899: [1.8][search] Search engine/indexer should evolve to support Java 8 constructs
+ * @test Ensures that the search for type use annotation finds matches in the following
+ * FormalParameter ::= Modifiersopt Type PushZeroTypeAnnotations '...' VariableDeclaratorIdOrThis
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=400899"
+ */
+public void testBug400899g4() throws CoreException {
+this.workingCopies = new ICompilationUnit[1];
+this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b400899/X.java",
+ "import java.lang.annotation.ElementType;\n" +
+ "import java.lang.annotation.Target;\n" +
+ "public class X {\n" +
+ " int x(@Marker int ... p) { return 10; };\n" +
+ "}\n" +
+ "@Target(ElementType.TYPE_USE)\n" +
+ "@interface Marker {}\n"
+ );
+SearchPattern pattern = SearchPattern.createPattern(
+ "Marker",
+ ANNOTATION_TYPE,
+ REFERENCES,
+ EXACT_RULE);
+new SearchEngine(this.workingCopies).search(pattern,
+new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
+getJavaSearchWorkingCopiesScope(),
+this.resultCollector,
+null);
+assertSearchResults(
+ "src/b400899/X.java int b400899.X.x(int ...) [Marker] EXACT_MATCH"
+);
+}
+
+/**
+ * @bug 400899: [1.8][search] Search engine/indexer should evolve to support Java 8 constructs
+ * @test Ensures that the search for type use annotation finds matches in the following
+ * FormalParameter ::= Modifiersopt Type @308... TypeAnnotations '...' VariableDeclaratorIdOrThis
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=400899"
+ */
+public void testBug400899g5() throws CoreException {
+this.workingCopies = new ICompilationUnit[1];
+this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b400899/X.java",
+ "import java.lang.annotation.ElementType;\n" +
+ "import java.lang.annotation.Target;\n" +
+ "public class X {\n" +
+ " int x(@Marker int [] @Marker ... p) { return 10; };\n" +
+ "}\n" +
+ "@Target(ElementType.TYPE_USE)\n" +
+ "@interface Marker {}\n"
+ );
+SearchPattern pattern = SearchPattern.createPattern(
+ "Marker",
+ ANNOTATION_TYPE,
+ REFERENCES,
+ EXACT_RULE);
+new SearchEngine(this.workingCopies).search(pattern,
+new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
+getJavaSearchWorkingCopiesScope(),
+this.resultCollector,
+null);
+assertSearchResults(
+ "src/b400899/X.java int b400899.X.x(int[] ...) [Marker] EXACT_MATCH\n" +
+ "src/b400899/X.java int b400899.X.x(int[] ...) [Marker] EXACT_MATCH"
+);
+}
+
+/**
+ * @bug 400899: [1.8][search] Search engine/indexer should evolve to support Java 8 constructs
+ * @test Ensures that the search for type use annotation finds matches in the following
+ * UnionType ::= Type
+ * UnionType ::= UnionType '|' Type
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=400899"
+ */
+public void testBug400899g6() throws CoreException {
+this.workingCopies = new ICompilationUnit[1];
+this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b400899/X.java",
+ "import java.lang.annotation.ElementType;\n" +
+ "import java.lang.annotation.Target;\n" +
+ "public class X {\n" +
+ " int x() {\n" +
+ " try {\n" +
+ " } catch (@Marker NullPointerException | @Marker ArrayIndexOutOfBoundsException e) {\n" +
+ " }\n" +
+ " return 10;\n" +
+ " }\n" +
+ "}\n" +
+ "@Target(ElementType.TYPE_USE)\n" +
+ "@interface Marker {}\n"
+ );
+SearchPattern pattern = SearchPattern.createPattern(
+ "Marker",
+ ANNOTATION_TYPE,
+ REFERENCES,
+ EXACT_RULE);
+new SearchEngine(this.workingCopies).search(pattern,
+new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
+getJavaSearchWorkingCopiesScope(),
+this.resultCollector,
+null);
+assertSearchResults(
+ "src/b400899/X.java int b400899.X.x() [Marker] EXACT_MATCH\n" +
+ "src/b400899/X.java int b400899.X.x() [Marker] EXACT_MATCH"
+);
+}
+
+/**
+ * @bug 400899: [1.8][search] Search engine/indexer should evolve to support Java 8 constructs
+ * @test Ensures that the search for type use annotation finds matches in the following
+ * LocalVariableDeclaration ::= Type PushModifiers VariableDeclarators
+ * LocalVariableDeclaration ::= Modifiers Type PushRealModifiers VariableDeclarators
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=400899"
+ */
+public void testBug400899g7() throws CoreException {
+this.workingCopies = new ICompilationUnit[1];
+this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b400899/X.java",
+ "import java.lang.annotation.ElementType;\n" +
+ "import java.lang.annotation.Target;\n" +
+ "public class X {\n" +
+ " int x() {\n" +
+ " @Marker int p;\n" +
+ " final @Marker int q;\n" +
+ " @Marker final int r;\n" +
+ " return 10;\n" +
+ " }\n" +
+ "}\n" +
+ "@Target(ElementType.TYPE_USE)\n" +
+ "@interface Marker {}\n"
+ );
+SearchPattern pattern = SearchPattern.createPattern(
+ "Marker",
+ ANNOTATION_TYPE,
+ REFERENCES,
+ EXACT_RULE);
+new SearchEngine(this.workingCopies).search(pattern,
+new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
+getJavaSearchWorkingCopiesScope(),
+this.resultCollector,
+null);
+assertSearchResults(
+ "src/b400899/X.java int b400899.X.x() [Marker] EXACT_MATCH\n" +
+ "src/b400899/X.java int b400899.X.x() [Marker] EXACT_MATCH\n" +
+ "src/b400899/X.java int b400899.X.x() [Marker] EXACT_MATCH"
+);
+}
+
+/**
+ * @bug 400899: [1.8][search] Search engine/indexer should evolve to support Java 8 constructs
+ * @test Ensures that the search for type use annotation finds matches in the following:
+ * Resource ::= Type PushModifiers VariableDeclaratorId EnterVariable '=' ForceNoDiet VariableInitializer RestoreDiet ExitVariableWithInitialization
+ * Resource ::= Modifiers Type PushRealModifiers VariableDeclaratorId EnterVariable '=' ForceNoDiet VariableInitializer RestoreDiet ExitVariableWithInitialization
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=400899"
+ */
+public void testBug400899g8() throws CoreException {
+this.workingCopies = new ICompilationUnit[1];
+this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b400899/X.java",
+ "import java.lang.annotation.ElementType;\n" +
+ "import java.lang.annotation.Target;\n" +
+ "public class X {\n" +
+ " int x() {\n" +
+ " try (@Marker Integer p = null; final @Marker Integer q = null; @Marker final Integer r = null) {\n" +
+ " }\n" +
+ " return 10;\n" +
+ " }\n" +
+ "}\n" +
+ "@Target(ElementType.TYPE_USE)\n" +
+ "@interface Marker {}\n"
+ );
+SearchPattern pattern = SearchPattern.createPattern(
+ "Marker",
+ ANNOTATION_TYPE,
+ REFERENCES,
+ EXACT_RULE);
+new SearchEngine(this.workingCopies).search(pattern,
+new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
+getJavaSearchWorkingCopiesScope(),
+this.resultCollector,
+null);
+assertSearchResults(
+ "src/b400899/X.java int b400899.X.x() [Marker] EXACT_MATCH\n" +
+ "src/b400899/X.java int b400899.X.x() [Marker] EXACT_MATCH\n" +
+ "src/b400899/X.java int b400899.X.x() [Marker] EXACT_MATCH"
+);
+}
+
+/**
+ * @bug 400899: [1.8][search] Search engine/indexer should evolve to support Java 8 constructs
+ * @test Ensures that the search for type use annotation finds matches in the following:
+ * EnhancedForStatementHeaderInit ::= 'for' '(' Type PushModifiers Identifier Dimsopt
+ * EnhancedForStatementHeaderInit ::= 'for' '(' Modifiers Type PushRealModifiers Identifier Dimsopt
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=400899"
+ */
+public void testBug400899g9() throws CoreException {
+this.workingCopies = new ICompilationUnit[1];
+this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b400899/X.java",
+ "import java.lang.annotation.ElementType;\n" +
+ "import java.lang.annotation.Target;\n" +
+ "public class X {\n" +
+ " int x() {\n" +
+ " for (@Marker int i: new int[3]) {}\n" +
+ " for (final @Marker int i: new int[3]) {}\n" +
+ " for (@Marker final int i: new int[3]) {}\n" +
+ " return 10;\n" +
+ " }\n" +
+ "}\n" +
+ "@Target(ElementType.TYPE_USE)\n" +
+ "@interface Marker {}\n"
+ );
+SearchPattern pattern = SearchPattern.createPattern(
+ "Marker",
+ ANNOTATION_TYPE,
+ REFERENCES,
+ EXACT_RULE);
+new SearchEngine(this.workingCopies).search(pattern,
+new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
+getJavaSearchWorkingCopiesScope(),
+this.resultCollector,
+null);
+assertSearchResults(
+ "src/b400899/X.java int b400899.X.x() [Marker] EXACT_MATCH\n" +
+ "src/b400899/X.java int b400899.X.x() [Marker] EXACT_MATCH\n" +
+ "src/b400899/X.java int b400899.X.x() [Marker] EXACT_MATCH"
+);
+}
+
+/**
+ * @bug 400899: [1.8][search] Search engine/indexer should evolve to support Java 8 constructs
+ * @test Ensures that the search for type use annotation finds matches in the following
+ * AnnotationMethodHeaderName ::= Modifiersopt TypeParameters Type 'Identifier' '('
+ * AnnotationMethodHeaderName ::= Modifiersopt Type 'Identifier' '('
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=400899"
+ */
+public void testBug400899g10() throws CoreException {
+this.workingCopies = new ICompilationUnit[1];
+this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b400899/X.java",
+ "import java.lang.annotation.ElementType;\n" +
+ "import java.lang.annotation.Target;\n" +
+ "public @interface X { \n" +
+ " public @Marker String value(); \n" +
+ " @Marker String value2(); \n" +
+ " @Marker public String value3(); \n" +
+ "}\n" +
+ "@Target(ElementType.TYPE_USE)\n" +
+ "@interface Marker {}\n"
+ );
+SearchPattern pattern = SearchPattern.createPattern(
+ "Marker",
+ ANNOTATION_TYPE,
+ REFERENCES,
+ EXACT_RULE);
+new SearchEngine(this.workingCopies).search(pattern,
+new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
+getJavaSearchWorkingCopiesScope(),
+this.resultCollector,
+null);
+assertSearchResults(
+ "src/b400899/X.java String b400899.X.value() [Marker] EXACT_MATCH\n" +
+ "src/b400899/X.java String b400899.X.value2() [Marker] EXACT_MATCH\n" +
+ "src/b400899/X.java String b400899.X.value3() [Marker] EXACT_MATCH"
+);
+}
+
+/**
+ * @bug 400899: [1.8][search] Search engine/indexer should evolve to support Java 8 constructs
+ * @test Ensures that the search for type use annotation finds matches in the following
+ * PrimaryNoNewArray ::= PrimitiveType Dims '.' 'class'
+ * PrimaryNoNewArray ::= PrimitiveType '.' 'class'
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=400899"
+ */
+public void testBug400899g11() throws CoreException {
+this.workingCopies = new ICompilationUnit[1];
+this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b400899/X.java",
+ "import java.lang.annotation.ElementType;\n" +
+ "import java.lang.annotation.Target;\n" +
+ "public class X { \n" +
+ " public void value() {\n" +
+ " Object o = @Marker int.class;\n" +
+ " Object o2 = @Marker int @Marker[] [] @Marker[].class;\n" +
+ " }\n" +
+ "}\n" +
+ "@Target(ElementType.TYPE_USE)\n" +
+ "@interface Marker {}\n"
+ );
+SearchPattern pattern = SearchPattern.createPattern(
+ "Marker",
+ ANNOTATION_TYPE,
+ REFERENCES,
+ EXACT_RULE);
+new SearchEngine(this.workingCopies).search(pattern,
+new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
+getJavaSearchWorkingCopiesScope(),
+this.resultCollector,
+null);
+assertSearchResults(
+ "src/b400899/X.java void b400899.X.value() [Marker] POTENTIAL_MATCH\n" +
+ "src/b400899/X.java void b400899.X.value() [Marker] POTENTIAL_MATCH\n" +
+ "src/b400899/X.java void b400899.X.value() [Marker] POTENTIAL_MATCH\n" +
+ "src/b400899/X.java void b400899.X.value() [Marker] POTENTIAL_MATCH"
+);
+}
+
+/**
+ * @bug 400899: [1.8][search] Search engine/indexer should evolve to support Java 8 constructs
+ * @test Ensures that the search for type use annotation finds matches in the following
+ * ReferenceExpression ::= PrimitiveType Dims '::' NonWildTypeArgumentsopt IdentifierOrNew
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=400899"
+ */
+public void testBug400899g12() throws CoreException {
+this.workingCopies = new ICompilationUnit[1];
+this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b400899/X.java",
+ "import java.lang.annotation.ElementType;\n" +
+ "import java.lang.annotation.Target;\n" +
+ "interface I {\n" +
+ " Object copy(int [] ia);\n" +
+ "}\n" +
+ "public class X {\n" +
+ " public static void main(String [] args) {\n" +
+ " I i = @Marker int @Marker []::<String>clone;\n" +
+ " }\n" +
+ "}\n" +
+ "@Target(ElementType.TYPE_USE)\n" +
+ "@interface Marker {}\n"
+ );
+SearchPattern pattern = SearchPattern.createPattern(
+ "Marker",
+ ANNOTATION_TYPE,
+ REFERENCES,
+ EXACT_RULE);
+new SearchEngine(this.workingCopies).search(pattern,
+new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
+getJavaSearchWorkingCopiesScope(),
+this.resultCollector,
+null);
+assertSearchResults(
+ "src/b400899/X.java void b400899.X.main(String[]) [Marker] EXACT_MATCH\n" +
+ "src/b400899/X.java void b400899.X.main(String[]) [Marker] EXACT_MATCH"
+);
+}
+
+/**
+ * @bug 400899: [1.8][search] Search engine/indexer should evolve to support Java 8 constructs
+ * @test Ensures that the search for type use annotation finds matches in the following
+ * ArrayCreationWithoutArrayInitializer ::= 'new' PrimitiveType DimWithOrWithOutExprs
+ * ArrayCreationWithArrayInitializer ::= 'new' PrimitiveType DimWithOrWithOutExprs ArrayInitializer
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=400899"
+ */
+public void testBug400899g13() throws CoreException {
+this.workingCopies = new ICompilationUnit[1];
+this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b400899/X.java",
+ "import java.lang.annotation.ElementType;\n" +
+ "import java.lang.annotation.Target;\n" +
+ "public class X {\n" +
+ " public static void main(String [] args) {\n" +
+ " int i [] = new @Marker int @Marker [4];\n" +
+ " int j [] = new @Marker int @Marker [] { 10 };\n" +
+ " }\n" +
+ "}\n" +
+ "@Target(ElementType.TYPE_USE)\n" +
+ "@interface Marker {}\n"
+ );
+SearchPattern pattern = SearchPattern.createPattern(
+ "Marker",
+ ANNOTATION_TYPE,
+ REFERENCES,
+ EXACT_RULE);
+new SearchEngine(this.workingCopies).search(pattern,
+new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
+getJavaSearchWorkingCopiesScope(),
+this.resultCollector,
+null);
+assertSearchResults(
+ "src/b400899/X.java void b400899.X.main(String[]) [Marker] EXACT_MATCH\n" +
+ "src/b400899/X.java void b400899.X.main(String[]) [Marker] EXACT_MATCH\n" +
+ "src/b400899/X.java void b400899.X.main(String[]) [Marker] EXACT_MATCH\n" +
+ "src/b400899/X.java void b400899.X.main(String[]) [Marker] EXACT_MATCH"
+);
+}
+
+/**
+ * @bug 400899: [1.8][search] Search engine/indexer should evolve to support Java 8 constructs
+ * @test Ensures that the search for type use annotation finds matches in the following
+ * CastExpression ::= PushLPAREN PrimitiveType Dimsopt PushRPAREN InsideCastExpression UnaryExpression
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=400899"
+ */
+public void testBug400899g14() throws CoreException {
+this.workingCopies = new ICompilationUnit[1];
+this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b400899/X.java",
+ "import java.lang.annotation.ElementType;\n" +
+ "import java.lang.annotation.Target;\n" +
+ "public class X {\n" +
+ " public static void main(String [] args) {\n" +
+ " int i = (@Marker int) 0;\n" +
+ " int j [] = (@Marker int @Marker []) null;\n" +
+ " }\n" +
+ "}\n" +
+ "@Target(ElementType.TYPE_USE)\n" +
+ "@interface Marker {}\n"
+ );
+SearchPattern pattern = SearchPattern.createPattern(
+ "Marker",
+ ANNOTATION_TYPE,
+ REFERENCES,
+ EXACT_RULE);
+new SearchEngine(this.workingCopies).search(pattern,
+new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
+getJavaSearchWorkingCopiesScope(),
+this.resultCollector,
+null);
+assertSearchResults(
+ "src/b400899/X.java void b400899.X.main(String[]) [Marker] EXACT_MATCH\n" +
+ "src/b400899/X.java void b400899.X.main(String[]) [Marker] EXACT_MATCH\n" +
+ "src/b400899/X.java void b400899.X.main(String[]) [Marker] EXACT_MATCH"
+);
+}
+
+/**
+ * @bug 400899: [1.8][search] Search engine/indexer should evolve to support Java 8 constructs
+ * @test Ensures that the search for type use annotation finds matches in the following
+ * InstanceofExpression ::= InstanceofExpression 'instanceof' ReferenceType
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=400899"
+ */
+public void testBug400899g15() throws CoreException {
+this.workingCopies = new ICompilationUnit[1];
+this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b400899/X.java",
+ "import java.lang.annotation.ElementType;\n" +
+ "import java.lang.annotation.Target;\n" +
+ "public class X {\n" +
+ " public static void main(String [] args) {\n" +
+ " if (args instanceof @Marker String[]) {\n" +
+ " }\n" +
+ " }\n" +
+ "}\n" +
+ "@Target(ElementType.TYPE_USE)\n" +
+ "@interface Marker {}\n"
+ );
+SearchPattern pattern = SearchPattern.createPattern(
+ "Marker",
+ ANNOTATION_TYPE,
+ REFERENCES,
+ EXACT_RULE);
+new SearchEngine(this.workingCopies).search(pattern,
+new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
+getJavaSearchWorkingCopiesScope(),
+this.resultCollector,
+null);
+assertSearchResults(
+ "src/b400899/X.java void b400899.X.main(String[]) [Marker] EXACT_MATCH"
+);
+}
+
+/**
+ * @bug 400899: [1.8][search] Search engine/indexer should evolve to support Java 8 constructs
+ * @test Ensures that the search for type use annotation finds matches in the following
+ * TypeArgument ::= ReferenceType
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=400899"
+ */
+public void testBug400899g16() throws CoreException {
+this.workingCopies = new ICompilationUnit[1];
+this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b400899/X.java",
+ "import java.lang.annotation.ElementType;\n" +
+ "import java.lang.annotation.Target;\n" +
+ "public class X extends Y<@Marker Integer, String> {}\n" +
+ "class Y<T, V> {\n" +
+ "}\n" +
+ "@Target(ElementType.TYPE_USE)\n" +
+ "@interface Marker {}\n"
+ );
+SearchPattern pattern = SearchPattern.createPattern(
+ "Marker",
+ ANNOTATION_TYPE,
+ REFERENCES,
+ EXACT_RULE);
+new SearchEngine(this.workingCopies).search(pattern,
+new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
+getJavaSearchWorkingCopiesScope(),
+this.resultCollector,
+null);
+assertSearchResults(
+ "src/b400899/X.java b400899.X [Marker] EXACT_MATCH"
+);
+}
+
+/**
+ * @bug 400899: [1.8][search] Search engine/indexer should evolve to support Java 8 constructs
+ * @test Ensures that the search for type use annotation finds matches in the following
+ * ReferenceType1 ::= ReferenceType '>'
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=400899"
+ */
+public void testBug400899g17() throws CoreException {
+this.workingCopies = new ICompilationUnit[1];
+this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b400899/X.java",
+ "import java.lang.annotation.ElementType;\n" +
+ "import java.lang.annotation.Target;\n" +
+ "public class X extends Y<@Marker Integer> {}\n" +
+ "class Y<T> {\n" +
+ "}\n" +
+ "@Target(ElementType.TYPE_USE)\n" +
+ "@interface Marker {}\n"
+ );
+SearchPattern pattern = SearchPattern.createPattern(
+ "Marker",
+ ANNOTATION_TYPE,
+ REFERENCES,
+ EXACT_RULE);
+new SearchEngine(this.workingCopies).search(pattern,
+new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
+getJavaSearchWorkingCopiesScope(),
+this.resultCollector,
+null);
+assertSearchResults(
+ "src/b400899/X.java b400899.X [Marker] EXACT_MATCH"
+);
+}
+
+/**
+ * @bug 400899: [1.8][search] Search engine/indexer should evolve to support Java 8 constructs
+ * @test Ensures that the search for type use annotation finds matches in the following
+ * ReferenceType2 ::= ReferenceType '>>'
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=400899"
+ */
+public void _testBug400899g18() throws CoreException {
+this.workingCopies = new ICompilationUnit[1];
+this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b400899/X.java",
+ "import java.lang.annotation.ElementType;\n" +
+ "import java.lang.annotation.Target;\n" +
+ "public class X<T extends Object & Comparable<? super @Marker String>> {}\n" +
+ "class Y<T> {\n" +
+ "}\n" +
+ "@Target(ElementType.TYPE_USE)\n" +
+ "@interface Marker {}\n"
+ );
+SearchPattern pattern = SearchPattern.createPattern(
+ "Marker",
+ ANNOTATION_TYPE,
+ REFERENCES,
+ EXACT_RULE);
+new SearchEngine(this.workingCopies).search(pattern,
+new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
+getJavaSearchWorkingCopiesScope(),
+this.resultCollector,
+null);
+assertSearchResults(
+ "<TODO : ADD THE EXPECTED RESULT HERE>"
+);
+}
+
+/**
+ * @bug 400899: [1.8][search] Search engine/indexer should evolve to support Java 8 constructs
+ * @test Ensures that the search for type use annotation finds matches in the following
+ * ReferenceType3 ::= ReferenceType '>>>'
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=400899"
+ */
+public void _testBug400899g19() throws CoreException {
+this.workingCopies = new ICompilationUnit[1];
+this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b400899/X.java",
+ "import java.lang.annotation.ElementType;\n" +
+ "import java.lang.annotation.Target;\n" +
+ "public class X<A extends X<X<X<@Marker String>>>> {}\n" +
+ "class Y<T> {\n" +
+ "}\n" +
+ "@Target(ElementType.TYPE_USE)\n" +
+ "@interface Marker {}\n"
+ );
+SearchPattern pattern = SearchPattern.createPattern(
+ "Marker",
+ ANNOTATION_TYPE,
+ REFERENCES,
+ EXACT_RULE);
+new SearchEngine(this.workingCopies).search(pattern,
+new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
+getJavaSearchWorkingCopiesScope(),
+this.resultCollector,
+null);
+assertSearchResults(
+ "<TODO : ADD THE EXPECTED RESULT HERE>"
+);
+}
+
+/**
+ * @bug 400899: [1.8][search] Search engine/indexer should evolve to support Java 8 constructs
+ * @test Ensures that the search for type use annotation finds matches in the following
+ * WildcardBounds ::= 'extends' ReferenceType
+ * WildcardBounds ::= 'super' ReferenceType
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=400899"
+ */
+public void testBug400899g20() throws CoreException {
+this.workingCopies = new ICompilationUnit[1];
+this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b400899/X.java",
+ "import java.lang.annotation.ElementType;\n" +
+ "import java.lang.annotation.Target;\n" +
+ "public class X {\n" +
+ " void foo(Map<@Marker ? super @Marker Object, @Marker ? extends @Marker String> m){}\n" +
+ " void goo(Map<@Marker ? extends @Marker Object, @Marker ? super @Marker String> m){}\n" +
+ "}\n" +
+ "@Target(ElementType.TYPE_USE)\n" +
+ "@interface Marker {}\n"
+ );
+SearchPattern pattern = SearchPattern.createPattern(
+ "Marker",
+ ANNOTATION_TYPE,
+ REFERENCES,
+ EXACT_RULE);
+new SearchEngine(this.workingCopies).search(pattern,
+new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
+getJavaSearchWorkingCopiesScope(),
+this.resultCollector,
+null);
+assertSearchResults(
+ "src/b400899/X.java void b400899.X.foo(Map<? super Object,? extends String>) [Marker] EXACT_MATCH\n" +
+ "src/b400899/X.java void b400899.X.foo(Map<? super Object,? extends String>) [Marker] EXACT_MATCH\n" +
+ "src/b400899/X.java void b400899.X.foo(Map<? super Object,? extends String>) [Marker] EXACT_MATCH\n" +
+ "src/b400899/X.java void b400899.X.foo(Map<? super Object,? extends String>) [Marker] EXACT_MATCH\n" +
+ "src/b400899/X.java void b400899.X.goo(Map<? extends Object,? super String>) [Marker] EXACT_MATCH\n" +
+ "src/b400899/X.java void b400899.X.goo(Map<? extends Object,? super String>) [Marker] EXACT_MATCH\n" +
+ "src/b400899/X.java void b400899.X.goo(Map<? extends Object,? super String>) [Marker] EXACT_MATCH\n" +
+ "src/b400899/X.java void b400899.X.goo(Map<? extends Object,? super String>) [Marker] EXACT_MATCH"
+);
+}
+
+/**
+ * @bug 400899: [1.8][search] Search engine/indexer should evolve to support Java 8 constructs
+ * @test Ensures that the search for type use annotation finds matches in the following
+ * TypeParameter ::= TypeParameterHeader 'extends' ReferenceType AdditionalBoundList
+ * AdditionalBound ::= '&' ReferenceType
+ * TypeParameter1 ::= TypeParameterHeader 'extends' ReferenceType AdditionalBoundList1
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=400899"
+ */
+public void _testBug400899g22() throws CoreException {
+this.workingCopies = new ICompilationUnit[1];
+this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b400899/X.java",
+ "import java.lang.annotation.ElementType;\n" +
+ "import java.lang.annotation.Target;\n" +
+ "public interface X<U extends J<? extends X<U>>> {\n" +
+ "}\n" +
+ "interface J<T extends X<? extends J<T>>> {\n" +
+ "}\n" +
+ "class CI<U extends CJ<T, U> & @Marker J<@Marker T>,\n" +
+ " T extends CI<U, T> & @Marker X<U>>\n" +
+ " implements X<U> {\n" +
+ "}\n" +
+ "class CJ<T extends CI<U, T> & @Marker X<@Marker U>,\n" +
+ " U extends CJ<T, U> & J<T>>\n" +
+ " implements J<T> {\n" +
+ "}\n" +
+ "@Target(ElementType.TYPE_USE)\n" +
+ "@interface Marker {}\n"
+ );
+SearchPattern pattern = SearchPattern.createPattern(
+ "Marker",
+ ANNOTATION_TYPE,
+ REFERENCES,
+ EXACT_RULE);
+new SearchEngine(this.workingCopies).search(pattern,
+new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
+getJavaSearchWorkingCopiesScope(),
+this.resultCollector,
+null);
+assertSearchResults(
+ "TODO - ADD THE RESULT HERE"
+);
+}
+
+/**
+ * @bug 400899: [1.8][search] Search engine/indexer should evolve to support Java 8 constructs
+ * @test Ensures that the search for type use annotation finds matches in the following
+ * InstanceofExpression_NotName ::= Name 'instanceof' ReferenceType
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=400899"
+ */
+public void testBug400899g23() throws CoreException {
+this.workingCopies = new ICompilationUnit[1];
+this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b400899/X.java",
+ "import java.lang.annotation.ElementType;\n" +
+ "import java.lang.annotation.Target;\n" +
+ "public class X<E> {\n" +
+ " class Y {\n" +
+ " E e;\n" +
+ " E getOtherElement(Object other) {\n" +
+ " if (!(other instanceof @Marker X<?>.Y)) {};\n" +
+ " return null;\n" +
+ " }\n" +
+ " }\n" +
+ "}\n" +
+ "@Target(ElementType.TYPE_USE)\n" +
+ "@interface Marker {}\n"
+ );
+SearchPattern pattern = SearchPattern.createPattern(
+ "Marker",
+ ANNOTATION_TYPE,
+ REFERENCES,
+ EXACT_RULE);
+new SearchEngine(this.workingCopies).search(pattern,
+new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
+getJavaSearchWorkingCopiesScope(),
+this.resultCollector,
+null);
+assertSearchResults(
+ "src/b400899/X.java E b400899.X$Y.getOtherElement(Object) [Marker] EXACT_MATCH");
+}
+
+/**
+ * @bug 400899: [1.8][search] Search engine/indexer should evolve to support Java 8 constructs
+ * @test Ensures that the search for type use annotation finds matches in the following
+ * InstanceofExpression_NotName ::= InstanceofExpression_NotName 'instanceof' ReferenceType
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=400899"
+ */
+public void testBug400899g24() throws CoreException {
+this.workingCopies = new ICompilationUnit[1];
+this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b400899/X.java",
+ "import java.lang.annotation.ElementType;\n" +
+ "import java.lang.annotation.Target;\n" +
+ "public class X<P, C> {\n" +
+ " public X() {\n" +
+ " if (!(this instanceof @Marker X)) {}\n" +
+ " }\n" +
+ "}\n" +
+ "@Target(ElementType.TYPE_USE)\n" +
+ "@interface Marker {}\n"
+ );
+SearchPattern pattern = SearchPattern.createPattern(
+ "Marker",
+ ANNOTATION_TYPE,
+ REFERENCES,
+ EXACT_RULE);
+new SearchEngine(this.workingCopies).search(pattern,
+new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
+getJavaSearchWorkingCopiesScope(),
+this.resultCollector,
+null);
+assertSearchResults(
+ "src/b400899/X.java b400899.X() [Marker] EXACT_MATCH"
+);
+}
+
+/**
+ * @bug 400899: [1.8][search] Search engine/indexer should evolve to support Java 8 constructs
+ * @test Ensures that the search for type use annotation finds matches in the following
+ * ReferenceExpressionTypeArgumentsAndTrunk ::= OnlyTypeArguments '.' ClassOrInterfaceType Dimsopt
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=400899"
+ */
+public void _testBug400899g25() throws CoreException {
+this.workingCopies = new ICompilationUnit[1];
+this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b400899/X.java",
+ "import java.lang.annotation.ElementType;\n" +
+ "import java.lang.annotation.Target;\n" +
+ "public class X {\n" +
+ " public class X <@Marker T extends @Marker Y<@Marker ?>, @Marker Q extends @Marker Integer> {\n" +
+ "}\n" +
+ "@Target(ElementType.TYPE_USE)\n" +
+ "@interface Marker {}\n"
+ );
+SearchPattern pattern = SearchPattern.createPattern(
+ "Marker",
+ ANNOTATION_TYPE,
+ REFERENCES,
+ EXACT_RULE);
+new SearchEngine(this.workingCopies).search(pattern,
+new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
+getJavaSearchWorkingCopiesScope(),
+this.resultCollector,
+null);
+assertSearchResults(
+ "TODO: ADD THE EXPECTED RESULT HERE"
+);
+}
+
+/**
+ * @bug 400899: [1.8][search] Search engine/indexer should evolve to support Java 8 constructs
+ * @test Ensures that the search for type use annotation finds matches in the following
+ * ArrayCreationWithoutArrayInitializer ::= 'new' ClassOrInterfaceType DimWithOrWithOutExprs
+ * ArrayCreationWithArrayInitializer ::= 'new' ClassOrInterfaceType DimWithOrWithOutExprs ArrayInitializer
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=400899"
+ */
+public void testBug400899g26() throws CoreException {
+this.workingCopies = new ICompilationUnit[1];
+this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b400899/X.java",
+ "import java.lang.annotation.ElementType;\n" +
+ "import java.lang.annotation.Target;\n" +
+ "public class X {\n" +
+ " public static void main(String [] args) {\n" +
+ " X [] x = new @Marker X @Marker [5];\n" +
+ " X [] x2 = new @Marker X @Marker [] { null };\n" +
+ " }\n" +
+ "}\n" +
+ "@Target(ElementType.TYPE_USE)\n" +
+ "@interface Marker {}\n"
+ );
+SearchPattern pattern = SearchPattern.createPattern(
+ "Marker",
+ ANNOTATION_TYPE,
+ REFERENCES,
+ EXACT_RULE);
+new SearchEngine(this.workingCopies).search(pattern,
+new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
+getJavaSearchWorkingCopiesScope(),
+this.resultCollector,
+null);
+assertSearchResults(
+ "src/b400899/X.java void b400899.X.main(String[]) [Marker] EXACT_MATCH\n" +
+ "src/b400899/X.java void b400899.X.main(String[]) [Marker] EXACT_MATCH\n" +
+ "src/b400899/X.java void b400899.X.main(String[]) [Marker] EXACT_MATCH\n" +
+ "src/b400899/X.java void b400899.X.main(String[]) [Marker] EXACT_MATCH"
+);
+}
+
+/**
+ * @bug 400899: [1.8][search] Search engine/indexer should evolve to support Java 8 constructs
+ * @test Ensures that the search for type use annotation finds matches in the following
+ * CastExpression ::= PushLPAREN Name OnlyTypeArgumentsForCastExpression '.' ClassOrInterfaceType Dimsopt PushRPAREN InsideCastExpressionWithQualifiedGenerics UnaryExpressionNotPlusMinus
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=400899"
+ */
+public void testBug400899g27() throws CoreException {
+this.workingCopies = new ICompilationUnit[1];
+this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b400899/X.java",
+ "import java.lang.annotation.ElementType;\n" +
+ "import java.lang.annotation.Target;\n" +
+ "public class X {\n" +
+ " public static void main(String [] args) {\n" +
+ " java.util.Map.Entry [] e = (java.util.Map<String, String>.@Marker Entry []) null;\n" +
+ " }\n" +
+ "}\n" +
+ "@Target(ElementType.TYPE_USE)\n" +
+ "@interface Marker {}\n"
+ );
+SearchPattern pattern = SearchPattern.createPattern(
+ "Marker",
+ ANNOTATION_TYPE,
+ REFERENCES,
+ EXACT_RULE);
+new SearchEngine(this.workingCopies).search(pattern,
+new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
+getJavaSearchWorkingCopiesScope(),
+this.resultCollector,
+null);
+assertSearchResults(
+ "src/b400899/X.java void b400899.X.main(String[]) [Marker] EXACT_MATCH"
+);
+}
+
+/**
+ * @bug 400899: [1.8][search] Search engine/indexer should evolve to support Java 8 constructs
+ * @test Ensures that the search for type use annotation finds matches in the following
+ * ReferenceType1 ::= ClassOrInterface '<' TypeArgumentList2
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=400899"
+ */
+public void testBug400899g28() throws CoreException {
+this.workingCopies = new ICompilationUnit[1];
+this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b400899/X.java",
+ "import java.lang.annotation.ElementType;\n" +
+ "import java.lang.annotation.Target;\n" +
+ "import java.io.Serializable;\n" +
+ "import java.util.List;\n" +
+ "public class X<T extends Comparable<T> & Serializable> {\n" +
+ " void foo(List<? extends @Marker Comparable<T>> p) {} \n" +
+ "}\n" +
+ "@Target(ElementType.TYPE_USE)\n" +
+ "@interface Marker {}\n"
+ );
+SearchPattern pattern = SearchPattern.createPattern(
+ "Marker",
+ ANNOTATION_TYPE,
+ REFERENCES,
+ EXACT_RULE);
+new SearchEngine(this.workingCopies).search(pattern,
+new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
+getJavaSearchWorkingCopiesScope(),
+this.resultCollector,
+null);
+assertSearchResults(
+ "src/b400899/X.java void b400899.X.foo(List<? extends Comparable<T>>) [Marker] EXACT_MATCH"
+);
+}
+
+/**
+ * @bug 400899: [1.8][search] Search engine/indexer should evolve to support Java 8 constructs
+ * @test Ensures that the search for type use annotation finds matches in the following
+ * ReferenceType2 ::= ClassOrInterface '<' TypeArgumentList3
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=400899"
+ */
+public void _testBug400899g29() throws CoreException {
+this.workingCopies = new ICompilationUnit[1];
+this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b400899/X.java",
+ "import java.lang.annotation.ElementType;\n" +
+ "import java.lang.annotation.Target;\n" +
+ "class Base {\n" +
+ "}\n" +
+ "class Foo<U extends Base, V extends Bar<U, @Marker Foo<U, V>>> {\n" +
+ "}\n" +
+ "class Bar<E extends Base, F extends Foo<E, @Marker Bar<E, F>>> {\n" +
+ "}\n" +
+ "@Target(ElementType.TYPE_USE)\n" +
+ "@interface Marker {}\n"
+ );
+SearchPattern pattern = SearchPattern.createPattern(
+ "Marker",
+ ANNOTATION_TYPE,
+ REFERENCES,
+ EXACT_RULE);
+new SearchEngine(this.workingCopies).search(pattern,
+new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
+getJavaSearchWorkingCopiesScope(),
+this.resultCollector,
+null);
+assertSearchResults(
+ "TODO: EXACT MATCH RESULTS TO BE ADDED"
+);
+}
+
+/**
+ * @bug 400899: [1.8][search] Search engine/indexer should evolve to support Java 8 constructs
+ * @test Ensures that the search for type use annotation finds matches in the following
+ * ClassHeaderExtends ::= 'extends' ClassType
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=400899"
+ */
+public void testBug400899g30() throws CoreException {
+this.workingCopies = new ICompilationUnit[1];
+this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b400899/X.java",
+ "import java.lang.annotation.ElementType;\n" +
+ "import java.lang.annotation.Target;\n" +
+ "public class X extends @Marker Object {\n" +
+ "}\n" +
+ "@Target(ElementType.TYPE_USE)\n" +
+ "@interface Marker {}\n"
+ );
+SearchPattern pattern = SearchPattern.createPattern(
+ "Marker",
+ ANNOTATION_TYPE,
+ REFERENCES,
+ EXACT_RULE);
+new SearchEngine(this.workingCopies).search(pattern,
+new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
+getJavaSearchWorkingCopiesScope(),
+this.resultCollector,
+null);
+assertSearchResults(
+ "src/b400899/X.java b400899.X [Marker] EXACT_MATCH"
+);
+}
+
+/**
+ * @bug 400899: [1.8][search] Search engine/indexer should evolve to support Java 8 constructs
+ * @test Ensures that the search for type use annotation finds matches in the following
+ * ClassInstanceCreationExpression ::= 'new' OnlyTypeArguments ClassType EnterInstanceCreationArgumentList '(' ArgumentListopt ')' UnqualifiedClassBodyopt
+ * ClassInstanceCreationExpression ::= 'new' ClassType EnterInstanceCreationArgumentList '(' ArgumentListopt ')' UnqualifiedClassBodyopt
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=400899"
+ */
+public void testBug400899g31() throws CoreException {
+this.workingCopies = new ICompilationUnit[1];
+this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b400899/X.java",
+ "import java.lang.annotation.ElementType;\n" +
+ "import java.lang.annotation.Target;\n" +
+ "public class X {\n" +
+ " X x = new @Marker X();\n" +
+ " X y = new <String> @Marker X();\n" +
+ "}\n" +
+ "@Target(ElementType.TYPE_USE)\n" +
+ "@interface Marker {}\n"
+ );
+SearchPattern pattern = SearchPattern.createPattern(
+ "Marker",
+ ANNOTATION_TYPE,
+ REFERENCES,
+ EXACT_RULE);
+new SearchEngine(this.workingCopies).search(pattern,
+new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
+getJavaSearchWorkingCopiesScope(),
+this.resultCollector,
+null);
+assertSearchResults(
+ "src/b400899/X.java b400899.X.x [Marker] EXACT_MATCH\n" +
+ "src/b400899/X.java b400899.X.y [Marker] EXACT_MATCH"
+);
+}
+
+/**
+ * @bug 400899: [1.8][search] Search engine/indexer should evolve to support Java 8 constructs
+ * @test Ensures that the search for type use annotation finds matches in the following
+ * ClassInstanceCreationExpression ::= Primary '.' 'new' OnlyTypeArguments ClassType EnterInstanceCreationArgumentList '(' ArgumentListopt ')' QualifiedClassBodyopt
+ * ClassInstanceCreationExpression ::= Primary '.' 'new' ClassType EnterInstanceCreationArgumentList '(' ArgumentListopt ')' QualifiedClassBodyopt
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=400899"
+ */
+public void testBug400899g32() throws CoreException {
+this.workingCopies = new ICompilationUnit[1];
+this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b400899/X.java",
+ "import java.lang.annotation.ElementType;\n" +
+ "import java.lang.annotation.Target;\n" +
+ "public class X {\n" +
+ " class Y {\n" +
+ " }\n" +
+ " Y y1 = new @Marker X().new @Marker Y();\n" +
+ " Y y2 = new @Marker X().new <String> @Marker Y();\n" +
+ "}\n" +
+ "@Target(ElementType.TYPE_USE)\n" +
+ "@interface Marker {}\n"
+ );
+SearchPattern pattern = SearchPattern.createPattern(
+ "Marker",
+ ANNOTATION_TYPE,
+ REFERENCES,
+ EXACT_RULE);
+new SearchEngine(this.workingCopies).search(pattern,
+new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
+getJavaSearchWorkingCopiesScope(),
+this.resultCollector,
+null);
+assertSearchResults(
+ "src/b400899/X.java b400899.X.y1 [Marker] EXACT_MATCH\n" +
+ "src/b400899/X.java b400899.X.y1 [Marker] EXACT_MATCH\n" +
+ "src/b400899/X.java b400899.X.y2 [Marker] POTENTIAL_MATCH\n" +
+ "src/b400899/X.java b400899.X.y2 [Marker] EXACT_MATCH"
+);
+}
+
+/**
+ * @bug 400899: [1.8][search] Search engine/indexer should evolve to support Java 8 constructs
+ * @test Ensures that the search for type use annotation finds matches in the following
+ * ClassInstanceCreationExpression ::= ClassInstanceCreationExpressionName 'new' ClassType EnterInstanceCreationArgumentList '(' ArgumentListopt ')' QualifiedClassBodyopt
+ * ClassInstanceCreationExpression ::= ClassInstanceCreationExpressionName 'new' OnlyTypeArguments ClassType EnterInstanceCreationArgumentList '(' ArgumentListopt ')' QualifiedClassBodyopt
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=400899"
+ */
+public void testBug400899g33() throws CoreException {
+this.workingCopies = new ICompilationUnit[1];
+this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b400899/X.java",
+ "import java.lang.annotation.ElementType;\n" +
+ "import java.lang.annotation.Target;\n" +
+ "public class X {\n" +
+ " X x;\n" +
+ " class Y {\n" +
+ " }\n" +
+ " Y y1 = x.new @Marker Y();\n" +
+ " Y y2 = x.new <String> @Marker Y();\n" +
+ "}\n" +
+ "@Target(ElementType.TYPE_USE)\n" +
+ "@interface Marker {}\n"
+ );
+SearchPattern pattern = SearchPattern.createPattern(
+ "Marker",
+ ANNOTATION_TYPE,
+ REFERENCES,
+ EXACT_RULE);
+new SearchEngine(this.workingCopies).search(pattern,
+new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
+getJavaSearchWorkingCopiesScope(),
+this.resultCollector,
+null);
+assertSearchResults(
+ "src/b400899/X.java b400899.X.y1 [Marker] EXACT_MATCH\n" +
+ "src/b400899/X.java b400899.X.y2 [Marker] EXACT_MATCH"
+);
+}
+
+/**
+ * @bug 400899: [1.8][search] Search engine/indexer should evolve to support Java 8 constructs
+ * @test Ensures that the search for type use annotation finds matches in the following
+ * MethodHeaderThrowsClause ::= 'throws' ClassTypeList
+ * ClassTypeList -> ClassTypeElt
+ * ClassTypeList ::= ClassTypeList ',' ClassTypeElt
+ * ClassTypeElt ::= ClassType
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=400899"
+ */
+public void testBug400899g34() throws CoreException {
+this.workingCopies = new ICompilationUnit[1];
+this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b400899/X.java",
+ "import java.lang.annotation.ElementType;\n" +
+ "import java.lang.annotation.Target;\n" +
+ "public class X {\n" +
+ " void foo() throws @Marker NullPointerException, @Marker ArrayIndexOutOfBoundsException {}\n" +
+ "}\n" +
+ "@Target(ElementType.TYPE_USE)\n" +
+ "@interface Marker {}\n"
+ );
+SearchPattern pattern = SearchPattern.createPattern(
+ "Marker",
+ ANNOTATION_TYPE,
+ REFERENCES,
+ EXACT_RULE);
+new SearchEngine(this.workingCopies).search(pattern,
+new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
+getJavaSearchWorkingCopiesScope(),
+this.resultCollector,
+null);
+assertSearchResults(
+ "src/b400899/X.java void b400899.X.foo() [Marker] EXACT_MATCH\n" +
+ "src/b400899/X.java void b400899.X.foo() [Marker] EXACT_MATCH"
+);
+}
+
+/**
+ * @bug 400899: [1.8][search] Search engine/indexer should evolve to support Java 8 constructs
+ * @test Ensures that the search for type use annotation finds matches in the following
+ * ClassHeaderImplements ::= 'implements' InterfaceTypeList
+ * InterfaceHeaderExtends ::= 'extends' InterfaceTypeList
+ * InterfaceTypeList -> InterfaceType
+ * InterfaceTypeList ::= InterfaceTypeList ',' InterfaceType
+ * InterfaceType ::= ClassOrInterfaceType
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=400899"
+ */
+public void testBug400899g35() throws CoreException {
+this.workingCopies = new ICompilationUnit[1];
+this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b400899/X.java",
+ "import java.lang.annotation.ElementType;\n" +
+ "import java.lang.annotation.Target;\n" +
+ "interface I {}\n" +
+ "interface J {}\n" +
+ "interface K extends @Marker I, @Marker J {}\n" +
+ "interface L {}\n" +
+ "public class X implements @Marker K, @Marker L {\n" +
+ "}\n" +
+ "@Target(ElementType.TYPE_USE)\n" +
+ "@interface Marker {}\n"
+ );
+SearchPattern pattern = SearchPattern.createPattern(
+ "Marker",
+ ANNOTATION_TYPE,
+ REFERENCES,
+ EXACT_RULE);
+new SearchEngine(this.workingCopies).search(pattern,
+new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
+getJavaSearchWorkingCopiesScope(),
+this.resultCollector,
+null);
+assertSearchResults(
+ "src/b400899/X.java b400899.K [Marker] EXACT_MATCH\n" +
+ "src/b400899/X.java b400899.K [Marker] EXACT_MATCH\n" +
+ "src/b400899/X.java b400899.X [Marker] EXACT_MATCH\n" +
+ "src/b400899/X.java b400899.X [Marker] EXACT_MATCH"
+);
+}
+
+/**
+ * @bug 400899: [1.8][search] Search engine/indexer should evolve to support Java 8 constructs
+ * @test Ensures that the search for type use annotation finds matches in the following
+ * ReferenceExpression ::= Name Dimsopt '::' NonWildTypeArgumentsopt IdentifierOrNew
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=400899"
+ */
+public void testBug400899g36() throws CoreException {
+this.workingCopies = new ICompilationUnit[1];
+this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b400899/X.java",
+ "import java.lang.annotation.ElementType;\n" +
+ "import java.lang.annotation.Target;\n" +
+ "interface I {\n" +
+ " void foo(int x);\n" +
+ "}\n" +
+ "public class X {\n" +
+ " public static void main(String [] args) {\n" +
+ " I i = @Marker Y. @Marker Z @Marker [] [] @Marker [] ::foo;\n" +
+ " i.foo(10); \n" +
+ "}\n" +
+ "@Target(ElementType.TYPE_USE)\n" +
+ "@interface Marker {}\n"
+ );
+SearchPattern pattern = SearchPattern.createPattern(
+ "Marker",
+ ANNOTATION_TYPE,
+ REFERENCES,
+ EXACT_RULE);
+new SearchEngine(this.workingCopies).search(pattern,
+new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
+getJavaSearchWorkingCopiesScope(),
+this.resultCollector,
+null);
+assertSearchResults(
+ "src/b400899/X.java void b400899.X.main(String[]) [Marker] EXACT_MATCH\n" +
+ "src/b400899/X.java void b400899.X.main(String[]) [Marker] EXACT_MATCH\n" +
+ "src/b400899/X.java void b400899.X.main(String[]) [Marker] EXACT_MATCH\n" +
+ "src/b400899/X.java void b400899.X.main(String[]) [Marker] EXACT_MATCH"
+);
+}
+
+/**
+ * @bug 400899: [1.8][search] Search engine/indexer should evolve to support Java 8 constructs
+ * @test Ensures that the search for type use annotation finds matches in the following
+ * ReferenceExpression ::= Name BeginTypeArguments ReferenceExpressionTypeArgumentsAndTrunk '::' NonWildTypeArgumentsopt IdentifierOrNew
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=400899"
+ */
+public void testBug400899g37() throws CoreException {
+this.workingCopies = new ICompilationUnit[1];
+this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b400899/X.java",
+ "import java.lang.annotation.ElementType;\n" +
+ "import java.lang.annotation.Target;\n" +
+ "interface I {\n" +
+ " Y foo(int x);\n" +
+ "}\n" +
+ "public class X {\n" +
+ " class Z extends Y {\n" +
+ " public Z(int x) {\n" +
+ " super(x);\n" +
+ " System.out.println();\n" +
+ " }\n" +
+ " }\n" +
+ " public static void main(String [] args) {\n" +
+ " i = @Marker W<@Marker Integer>::<@Marker String> new;\n" +
+ " }\n" +
+ "}\n" +
+ "class W<T> extends Y {\n" +
+ " public W(T x) {\n" +
+ " super(0);\n" +
+ " System.out.println(x);\n" +
+ " }\n" +
+ "}\n" +
+ "class Y {\n" +
+ " public Y(int x) {\n" +
+ " System.out.println(x);\n" +
+ " }\n" +
+ "}\n" +
+ "@Target(ElementType.TYPE_USE)\n" +
+ "@interface Marker {}\n"
+ );
+SearchPattern pattern = SearchPattern.createPattern(
+ "Marker",
+ ANNOTATION_TYPE,
+ REFERENCES,
+ EXACT_RULE);
+new SearchEngine(this.workingCopies).search(pattern,
+new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
+getJavaSearchWorkingCopiesScope(),
+this.resultCollector,
+null);
+assertSearchResults(
+ "src/b400899/X.java void b400899.X.main(String[]) [Marker] EXACT_MATCH\n" +
+ "src/b400899/X.java void b400899.X.main(String[]) [Marker] EXACT_MATCH\n" +
+ "src/b400899/X.java void b400899.X.main(String[]) [Marker] EXACT_MATCH"
+);
+}
+
+/**
+ * @bug 400899: [1.8][search] Search engine/indexer should evolve to support Java 8 constructs
+ * @test Ensures that the search for type use annotation finds matches in the following
+ * CastExpression ::= PushLPAREN Name PushRPAREN InsideCastExpressionLL1 UnaryExpressionNotPlusMinus
+ * CastExpression ::= PushLPAREN Name Dims PushRPAREN InsideCastExpression UnaryExpressionNotPlusMinus
+ * CastExpression ::= PushLPAREN Name OnlyTypeArgumentsForCastExpression Dimsopt PushRPAREN InsideCastExpression UnaryExpressionNotPlusMinus
+ * CastExpression ::= PushLPAREN Name OnlyTypeArgumentsForCastExpression '.' ClassOrInterfaceType Dimsopt PushRPAREN InsideCastExpressionWithQualifiedGenerics UnaryExpressionNotPlusMinus
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=400899"
+ */
+public void testBug400899g38() throws CoreException {
+this.workingCopies = new ICompilationUnit[1];
+this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b400899/X.java",
+ "import java.lang.annotation.ElementType;\n" +
+ "import java.lang.annotation.Target;\n" +
+ "public class X {\n" +
+ " Object o = (@Marker X) null;\n" +
+ " Object p = (@Marker X @Marker []) null;\n" +
+ " Object q = (@Marker java. @Marker util. @Marker List<@Marker String> []) null;\n" +
+ " Object r = (@Marker java. @Marker util.@Marker Map<@Marker String, @Marker String>.@Marker Entry @Marker []) null;\n" +
+ "}\n" +
+ "@Target(ElementType.TYPE_USE)\n" +
+ "@interface Marker {}\n"
+ );
+SearchPattern pattern = SearchPattern.createPattern(
+ "Marker",
+ ANNOTATION_TYPE,
+ REFERENCES,
+ EXACT_RULE);
+new SearchEngine(this.workingCopies).search(pattern,
+new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
+getJavaSearchWorkingCopiesScope(),
+this.resultCollector,
+null);
+assertSearchResults(
+ "src/b400899/X.java b400899.X.o [Marker] EXACT_MATCH\n" +
+ "src/b400899/X.java b400899.X.p [Marker] EXACT_MATCH\n" +
+ "src/b400899/X.java b400899.X.p [Marker] EXACT_MATCH\n" +
+ "src/b400899/X.java b400899.X.q [Marker] EXACT_MATCH\n" +
+ "src/b400899/X.java b400899.X.q [Marker] EXACT_MATCH\n" +
+ "src/b400899/X.java b400899.X.q [Marker] EXACT_MATCH\n" +
+ "src/b400899/X.java b400899.X.q [Marker] EXACT_MATCH\n" +
+ "src/b400899/X.java b400899.X.r [Marker] EXACT_MATCH\n" +
+ "src/b400899/X.java b400899.X.r [Marker] EXACT_MATCH\n" +
+ "src/b400899/X.java b400899.X.r [Marker] EXACT_MATCH\n" +
+ "src/b400899/X.java b400899.X.r [Marker] EXACT_MATCH\n" +
+ "src/b400899/X.java b400899.X.r [Marker] EXACT_MATCH\n" +
+ "src/b400899/X.java b400899.X.r [Marker] EXACT_MATCH\n" +
+ "src/b400899/X.java b400899.X.r [Marker] EXACT_MATCH"
+);
+}
+
+/**
+ * @bug 402902: [1.8][search] Search engine fails to annotation matches in extends/implements clauses
+ * @test Ensures that the search for type use annotation finds matches
+ * in extends and implements clauses.
+ *
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=402902"
+ */
+public void testBug400902() throws CoreException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b400902/X.java",
+ "import java.lang.annotation.ElementType;\n" +
+ "import java.lang.annotation.Target;\n" +
+ "import java.io.Serializable;\n" +
+ "@Marker1 @Marker public class X extends @Marker Object implements @Marker Serializable {\n" +
+ " private static final long serialVersionUID = 1L;\n" +
+ " int x = (@Marker int) 0;\n" +
+ " @Marker public class Y {}\n" +
+ "}\n" +
+ "@Target(ElementType.TYPE_USE)\n" +
+ "@interface Marker {}\n" +
+ "@Target(ElementType.TYPE)\n" +
+ "@interface Marker1 {}"
+ );
+ SearchPattern pattern = SearchPattern.createPattern(
+ "Marker",
+ ANNOTATION_TYPE,
+ REFERENCES,
+ EXACT_RULE);
+ new SearchEngine(this.workingCopies).search(pattern,
+ new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
+ getJavaSearchWorkingCopiesScope(),
+ this.resultCollector,
+ null);
+ assertSearchResults(
+ "src/b400902/X.java b400902.X [Marker] EXACT_MATCH\n" +
+ "src/b400902/X.java b400902.X [Marker] EXACT_MATCH\n" +
+ "src/b400902/X.java b400902.X [Marker] EXACT_MATCH\n" +
+ "src/b400902/X.java b400902.X.x [Marker] EXACT_MATCH\n" +
+ "src/b400902/X.java b400902.X$Y [Marker] EXACT_MATCH"
+ );
+}
+// Add new tests in JavaSearchBugs8Tests
+}
\ No newline at end of file
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java
index 6a71096..2f81df1 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java
@@ -716,6 +716,10 @@
suite.addTest(new JavaSearchBugsTests("testBug345807"));
suite.addTest(new JavaSearchBugsTests("testBug355605"));
suite.addTest(new JavaSearchBugsTests("testBug241834"));
+ suite.addTest(new JavaSearchBugsTests("testBug400902a"));
+ suite.addTest(new JavaSearchBugsTests("testBug400919a"));
+ suite.addTest(new JavaSearchBugsTests("testBug400919b"));
+ suite.addTest(new JavaSearchBugsTests("testBug400919c"));
return suite;
}
class TestCollector extends JavaSearchResultCollector {
@@ -13796,5 +13800,258 @@
"src/b400902/X.java b400902.X$Y [Marker] EXACT_MATCH"
);
}
+
+/**
+ * @bug 400919: [1.8][search] Search engine fails to annotation matches in type variable bounds
+ * @test Ensures that the search for type use annotation finds matches in type variable bounds
+ *
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=400919"
+ */
+public void testBug400919a() throws CoreException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b400919/X.java",
+ "import java.lang.annotation.ElementType;\n" +
+ "import java.lang.annotation.Target;\n" +
+ "import java.util.Collection;\n" +
+ "\n" +
+ "interface I {\n" +
+ " I doit();\n" +
+ "}\n" +
+ "\n" +
+ "@Marker public class X {\n" +
+ " @SuppressWarnings(\"unused\")\n" +
+ " @Marker <@Existing T> int x(@Existing T t) { return 10; };\n" +
+ " /**\n" +
+ " * @param <F> \n" +
+ " */\n" +
+ " class Folder<@Existing F extends @Existing XYZ> { }\n" +
+ " Collection<@Existing ? super @Existing XYZ> s;\n" +
+ " /**\n" +
+ " * @param <T> \n" +
+ " */\n" +
+ " class Test <T extends Outer.@Existing Inner> {}\n" +
+ "}\n" +
+ "\n" +
+ "class Y extends Object {\n" +
+ " int x = ( int) 0;\n" +
+ "}\n" +
+ "\n" +
+ "/**\n" +
+ " * @param <T> \n" +
+ " */\n" +
+ "class XY<@Existing T> {}\n" +
+ "class XYZ {}\n" +
+ "\n" +
+ "class Outer {\n" +
+ " class Inner {\n" +
+ " \n" +
+ " }\n" +
+ "}\n" +
+ "/**\n" +
+ " * @param <T> \n" +
+ " * @param <Q> \n" +
+ " */\n" +
+ "class X2 <@Marker T extends @Marker Y2<@Marker ? extends @Marker X>, @Marker Q extends @Marker Object> {\n" +
+ "}\n" +
+ "/**\n" +
+ " * @param <T> \n" +
+ " */\n" +
+ "class Y2<T> {}\n" +
+ "@Target(ElementType.TYPE_USE)\n" +
+ "@interface Existing {\n" +
+ " \n" +
+ "}\n" +
+ "@Target (ElementType.TYPE_USE)\n" +
+ "@interface Marker {}\n"
+ );
+ SearchPattern pattern = SearchPattern.createPattern(
+ "Existing",
+ ANNOTATION_TYPE,
+ REFERENCES,
+ EXACT_RULE);
+ new SearchEngine(this.workingCopies).search(pattern,
+ new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
+ getJavaSearchWorkingCopiesScope(),
+ this.resultCollector,
+ null);
+ assertSearchResults(
+ "src/b400919/X.java b400919.X.s [Existing] EXACT_MATCH\n" +
+ "src/b400919/X.java b400919.X.s [Existing] EXACT_MATCH\n" +
+ "src/b400919/X.java int b400919.X.x(T) [Existing] EXACT_MATCH\n" +
+ "src/b400919/X.java int b400919.X.x(T) [Existing] EXACT_MATCH\n" +
+ "src/b400919/X.java b400919.X$Folder [Existing] EXACT_MATCH\n" +
+ "src/b400919/X.java b400919.X$Folder [Existing] EXACT_MATCH\n" +
+ "src/b400919/X.java b400919.X$Test [Existing] EXACT_MATCH\n" +
+ "src/b400919/X.java b400919.XY [Existing] EXACT_MATCH"
+ );
+}
+/**
+ * @bug 400919: [1.8][search] Search engine fails to annotation matches in type variable bounds
+ * @test Ensures that the search for type use annotation finds matches in type variable bounds with TYPE
+ *
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=400919"
+ */
+public void testBug400919b() throws CoreException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b400919/X.java",
+ "import java.lang.annotation.ElementType;\n" +
+ "import java.lang.annotation.Target;\n" +
+ "import java.util.Collection;\n" +
+ "\n" +
+ "interface I {\n" +
+ " I doit();\n" +
+ "}\n" +
+ "\n" +
+ "@Marker public class X {\n" +
+ " @SuppressWarnings(\"unused\")\n" +
+ " @Marker <@Existing T> int x(@Existing T t) { return 10; };\n" +
+ " /**\n" +
+ " * @param <F> \n" +
+ " */\n" +
+ " class Folder<@Existing F extends @Existing XYZ> { }\n" +
+ " Collection<@Existing ? super @Existing XYZ> s;\n" +
+ " /**\n" +
+ " * @param <T> \n" +
+ " */\n" +
+ " class Test <T extends Outer.@Existing Inner> {}\n" +
+ "}\n" +
+ "\n" +
+ "class Y extends Object {\n" +
+ " int x = ( int) 0;\n" +
+ "}\n" +
+ "\n" +
+ "/**\n" +
+ " * @param <T> \n" +
+ " */\n" +
+ "class XY<@Existing T> {}\n" +
+ "class XYZ {}\n" +
+ "\n" +
+ "class Outer {\n" +
+ " class Inner {\n" +
+ " \n" +
+ " }\n" +
+ "}\n" +
+ "/**\n" +
+ " * @param <T> \n" +
+ " * @param <Q> \n" +
+ " */\n" +
+ "class X2 <@Marker T extends @Marker Y2<@Marker ? extends @Marker X>, @Marker Q extends @Marker Object> {\n" +
+ "}\n" +
+ "/**\n" +
+ " * @param <T> \n" +
+ " */\n" +
+ "class Y2<T> {}\n" +
+ "@Target(ElementType.TYPE_USE)\n" +
+ "@interface Existing {\n" +
+ " \n" +
+ "}\n" +
+ "@Target (ElementType.TYPE_USE)\n" +
+ "@interface Marker {}\n"
+ );
+ SearchPattern pattern = SearchPattern.createPattern(
+ "Existing",
+ TYPE,
+ REFERENCES,
+ EXACT_RULE);
+ new SearchEngine(this.workingCopies).search(pattern,
+ new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
+ getJavaSearchWorkingCopiesScope(),
+ this.resultCollector,
+ null);
+ assertSearchResults(
+ "src/b400919/X.java b400919.X.s [Existing] EXACT_MATCH\n" +
+ "src/b400919/X.java b400919.X.s [Existing] EXACT_MATCH\n" +
+ "src/b400919/X.java int b400919.X.x(T) [Existing] EXACT_MATCH\n" +
+ "src/b400919/X.java int b400919.X.x(T) [Existing] EXACT_MATCH\n" +
+ "src/b400919/X.java b400919.X$Folder [Existing] EXACT_MATCH\n" +
+ "src/b400919/X.java b400919.X$Folder [Existing] EXACT_MATCH\n" +
+ "src/b400919/X.java b400919.X$Test [Existing] EXACT_MATCH\n" +
+ "src/b400919/X.java b400919.XY [Existing] EXACT_MATCH"
+ );
+}
+/**
+ * @bug 400919: [1.8][search] Search engine fails to annotation matches in type variable bounds
+ * @test Ensures that the search for type use annotation finds matches in type variable bounds
+ *
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=400919"
+ */
+public void testBug400919c() throws CoreException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/JavaSearchBugs/src/b400919/X.java",
+ "import java.lang.annotation.ElementType;\n" +
+ "import java.lang.annotation.Target;\n" +
+ "import java.util.Collection;\n" +
+ "\n" +
+ "interface I {\n" +
+ " I doit();\n" +
+ "}\n" +
+ "\n" +
+ "@Marker public class X {\n" +
+ " @SuppressWarnings(\"unused\")\n" +
+ " @Marker <T> int x(T t) { return 10; };\n" +
+ " /**\n" +
+ " * @param <F> \n" +
+ " */\n" +
+ " class Folder<@Existing F extends @Existing XYZ> { }\n" +
+ " Collection<? super @Existing XYZ> s;\n" +
+ " /**\n" +
+ " * @param <T> \n" +
+ " */\n" +
+ " class Test <T extends Outer.@Existing Inner> {}\n" +
+ "}\n" +
+ "\n" +
+ "class Y extends Object {\n" +
+ " int x = ( int) 0;\n" +
+ "}\n" +
+ "\n" +
+ "/**\n" +
+ " * @param <T> \n" +
+ " */\n" +
+ "class XY<@Existing T> {}\n" +
+ "class XYZ {}\n" +
+ "\n" +
+ "class Outer {\n" +
+ " class Inner {\n" +
+ " \n" +
+ " }\n" +
+ "}\n" +
+ "/**\n" +
+ " * @param <T> \n" +
+ " * @param <Q> \n" +
+ " */\n" +
+ "class X2 <@Marker T extends @Marker Y2<@Marker ? extends @Marker X>, @Marker Q extends @Marker Object> {\n" +
+ "}\n" +
+ "/**\n" +
+ " * @param <T> \n" +
+ " */\n" +
+ "class Y2<T> {}\n" +
+ "@Target(ElementType.TYPE_USE)\n" +
+ "@interface Existing {\n" +
+ " \n" +
+ "}\n" +
+ "@Target (ElementType.TYPE_USE)\n" +
+ "@interface Marker {}\n"
+ );
+ SearchPattern pattern = SearchPattern.createPattern(
+ "Marker",
+ ANNOTATION_TYPE,
+ REFERENCES,
+ EXACT_RULE);
+ new SearchEngine(this.workingCopies).search(pattern,
+ new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
+ getJavaSearchWorkingCopiesScope(),
+ this.resultCollector,
+ null);
+ assertSearchResults(
+ "src/b400919/X.java b400919.X [Marker] EXACT_MATCH\n" +
+ "src/b400919/X.java int b400919.X.x(T) [Marker] EXACT_MATCH\n" +
+ "src/b400919/X.java b400919.X2 [Marker] EXACT_MATCH\n" +
+ "src/b400919/X.java b400919.X2 [Marker] EXACT_MATCH\n" +
+ "src/b400919/X.java b400919.X2 [Marker] EXACT_MATCH\n" +
+ "src/b400919/X.java b400919.X2 [Marker] EXACT_MATCH\n" +
+ "src/b400919/X.java b400919.X2 [Marker] EXACT_MATCH\n" +
+ "src/b400919/X.java b400919.X2 [Marker] EXACT_MATCH"
+ );
+}
// Add new tests in JavaSearchBugsTests2
}
\ No newline at end of file
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingExpressionsTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingExpressionsTest.java
index b70a460..63d2631 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingExpressionsTest.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingExpressionsTest.java
@@ -36,7 +36,6 @@
return createSuite(ASTRewritingExpressionsTest.class);
}
- /** @deprecated using deprecated code */
public void testArrayAccess() throws Exception {
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf= new StringBuffer();
@@ -93,7 +92,6 @@
}
- /** @deprecated using deprecated code */
public void testArrayCreation() throws Exception {
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf= new StringBuffer();
@@ -200,6 +198,14 @@
rewrite.getListRewrite(arrayCreation, ArrayCreation.DIMENSIONS_PROPERTY).insertLast(literal2, null);
}
+ { // add a new ArrayCreation
+ ArrayCreation arrayCreation= ast.newArrayCreation();
+ arrayCreation.setType(ast.newArrayType(ast.newSimpleType(ast.newSimpleName("Object")), 3));
+ arrayCreation.dimensions().add(ast.newNumberLiteral("1"));
+ arrayCreation.dimensions().add(ast.newNumberLiteral("2"));
+
+ rewrite.getListRewrite(invocation, MethodInvocation.ARGUMENTS_PROPERTY).insertLast(arrayCreation, null);
+ }
String preview= evaluateRewrite(cu, rewrite);
@@ -212,14 +218,82 @@
buf.append(" new int[],\n");
buf.append(" new int[2][10][11],\n");
buf.append(" new int[2][][][][],\n");
- buf.append(" new int[10][11][]);\n");
+ buf.append(" new int[10][11][], new Object[1][2][]);\n");
buf.append(" }\n");
buf.append("}\n");
assertEqualString(preview, buf.toString());
}
- /** @deprecated using deprecated code */
+ public void testArrayCreation2_since_8() throws Exception {
+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
+ StringBuffer buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("public class E {\n");
+ buf.append(" public void foo() {\n");
+ buf.append(" goo();\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= createAST(cu);
+ ASTRewrite rewrite= ASTRewrite.create(astRoot.getAST());
+
+ AST ast= astRoot.getAST();
+
+ assertTrue("Parse errors", (astRoot.getFlags() & ASTNode.MALFORMED) == 0);
+ TypeDeclaration type= findTypeDeclaration(astRoot, "E");
+ MethodDeclaration methodDecl= findMethodDeclaration(type, "foo");
+ Block block= methodDecl.getBody();
+ List statements= block.statements();
+ assertTrue("Number of statements not 1", statements.size() == 1);
+ ExpressionStatement statement= (ExpressionStatement) statements.get(0);
+ MethodInvocation invocation= (MethodInvocation) statement.getExpression();
+
+ { // add a new ArrayCreation with annotations
+ ArrayCreation arrayCreation= ast.newArrayCreation();
+ SimpleType elementType= ast.newSimpleType(ast.newName("java.lang.String"));
+
+ ArrayType arrayType= ast.newArrayType(elementType);
+ NormalAnnotation annotationC= ast.newNormalAnnotation();
+ annotationC.setTypeName(ast.newSimpleName("C"));
+ MemberValuePair memberValuePair= ast.newMemberValuePair();
+ memberValuePair.setName(ast.newSimpleName("v"));
+ memberValuePair.setValue(ast.newNumberLiteral("99"));
+ annotationC.values().add(memberValuePair);
+ arrayType.annotations().add(annotationC);
+
+ arrayType= ast.newArrayType(arrayType);
+ SingleMemberAnnotation annotationB= ast.newSingleMemberAnnotation();
+ annotationB.setTypeName(ast.newSimpleName("B"));
+ annotationB.setValue(ast.newNumberLiteral("0"));
+ arrayType.annotations().add(annotationB);
+
+ arrayType= ast.newArrayType(arrayType);
+ MarkerAnnotation annotationA= ast.newMarkerAnnotation();
+ annotationA.setTypeName(ast.newSimpleName("A"));
+ arrayType.annotations().add(annotationA);
+
+ arrayCreation.setType(arrayType);
+
+ arrayCreation.dimensions().add(ast.newNumberLiteral("1"));
+ arrayCreation.dimensions().add(ast.newNumberLiteral("2"));
+
+ rewrite.getListRewrite(invocation, MethodInvocation.ARGUMENTS_PROPERTY).insertLast(arrayCreation, null);
+ }
+
+ String preview= evaluateRewrite(cu, rewrite);
+
+ buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("public class E {\n");
+ buf.append(" public void foo() {\n");
+ buf.append(" goo(new java.lang.String @A[1]@B(0)[2]@C(v = 99)[]);\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ assertEqualString(preview, buf.toString());
+
+ }
public void testArrayInitializer() throws Exception {
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf= new StringBuffer();
@@ -301,7 +375,6 @@
}
- /** @deprecated using deprecated code */
public void testArrayInitializer2() throws Exception {
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf= new StringBuffer();
@@ -380,7 +453,6 @@
}
- /** @deprecated using deprecated code */
public void testAssignment() throws Exception {
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf= new StringBuffer();
@@ -444,7 +516,6 @@
}
- /** @deprecated using deprecated code */
public void testCastExpression() throws Exception {
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf= new StringBuffer();
@@ -509,7 +580,6 @@
}
- /** @deprecated using deprecated code */
public void testCastExpression_bug28824() throws Exception {
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
@@ -565,8 +635,7 @@
}
- /** @deprecated using deprecated code */
- public void testCatchClause_only_2_3_4() throws Exception {
+ public void testCatchClause() throws Exception {
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf= new StringBuffer();
buf.append("package test1;\n");
@@ -797,7 +866,6 @@
- /** @deprecated using deprecated code */
public void testConditionalExpression() throws Exception {
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf= new StringBuffer();
@@ -852,7 +920,6 @@
}
- /** @deprecated using deprecated code */
public void testFieldAccess() throws Exception {
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf= new StringBuffer();
@@ -905,7 +972,6 @@
}
- /** @deprecated using deprecated code */
public void testInfixExpression() throws Exception {
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf= new StringBuffer();
@@ -986,7 +1052,6 @@
}
- /** @deprecated using deprecated code */
public void testInstanceofExpression() throws Exception {
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf= new StringBuffer();
@@ -1049,7 +1114,6 @@
}
- /** @deprecated using deprecated code */
public void testMethodInvocation() throws Exception {
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf= new StringBuffer();
@@ -1126,7 +1190,6 @@
}
- /** @deprecated using deprecated code */
public void _testMethodParamsRenameReorder() throws Exception {
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf= new StringBuffer();
@@ -1204,7 +1267,6 @@
}
- /** @deprecated using deprecated code */
public void testMethodInvocation1() throws Exception {
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf= new StringBuffer();
@@ -1314,7 +1376,6 @@
}
- /** @deprecated using deprecated code */
public void testParenthesizedExpression() throws Exception {
//System.out.println(getClass().getName()+"::" + getName() +" disabled (bug 23362)");
@@ -1365,7 +1426,6 @@
}
- /** @deprecated using deprecated code */
public void testPrefixExpression() throws Exception {
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf= new StringBuffer();
@@ -1413,7 +1473,6 @@
}
- /** @deprecated using deprecated code */
public void testPostfixExpression() throws Exception {
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf= new StringBuffer();
@@ -1461,7 +1520,6 @@
}
- /** @deprecated using deprecated code */
public void testSuperConstructorInvocation() throws Exception {
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf= new StringBuffer();
@@ -1646,7 +1704,6 @@
assertEqualString(preview, buf.toString());
}
- /** @deprecated using deprecated code */
public void testSuperFieldInvocation() throws Exception {
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf= new StringBuffer();
@@ -1696,7 +1753,6 @@
assertEqualString(preview, buf.toString());
}
- /** @deprecated using deprecated code */
public void testSuperMethodInvocation() throws Exception {
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf= new StringBuffer();
@@ -1826,7 +1882,6 @@
}
- /** @deprecated using deprecated code */
public void testThisExpression() throws Exception {
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf= new StringBuffer();
@@ -1882,7 +1937,6 @@
}
- /** @deprecated using deprecated code */
public void testTypeLiteral() throws Exception {
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf= new StringBuffer();
@@ -1930,7 +1984,6 @@
}
- /** @deprecated using deprecated code */
public void testSimpleName() throws Exception {
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf= new StringBuffer();
@@ -1972,7 +2025,6 @@
}
- /** @deprecated using deprecated code */
public void testNumberLiteral() throws Exception {
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf= new StringBuffer();
@@ -2014,7 +2066,6 @@
}
- /** @deprecated using deprecated code */
public void testBooleanLiteral() throws Exception {
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf= new StringBuffer();
@@ -2056,7 +2107,6 @@
}
- /** @deprecated using deprecated code */
public void testStringLiteral() throws Exception {
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf= new StringBuffer();
@@ -2098,7 +2148,6 @@
}
- /** @deprecated using deprecated code */
public void testCharacterLiteral() throws Exception {
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf= new StringBuffer();
@@ -2140,4 +2189,151 @@
}
+ public void testIntersectionCastExpression_since_8() throws Exception {
+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
+ String content =
+ "import java.io.Serializable;\n" +
+ "public class X {\n" +
+ " public Serializable main(Object obj) {\n" +
+ " Serializable o = ((@Marker1 @Marker2 Serializable & I) () -> {});\n" +
+ " Serializable oo = obj;\n" +
+ " Serializable ooo = (Serializable) obj;\n" +
+ " }\n" +
+ "}\n" +
+ "interface I {\n" +
+ " public void foo();\n" +
+ "}\n" +
+ "interface J {\n" +
+ " public void foo();\n" +
+ " public void bar();\n" +
+ "}\n" +
+ "interface K {\n" +
+ " public void foo();\n" +
+ " public void bar();\n" +
+ "}\n";
+ ICompilationUnit cu= pack1.createCompilationUnit("X.java", content, false, null);
+
+ CompilationUnit unit= createAST(cu);
+ ASTRewrite rewrite= ASTRewrite.create(unit.getAST());
+ AST ast= unit.getAST();
+
+ TypeDeclaration type = (TypeDeclaration) unit.types().get(0);
+ ASTNode node = (ASTNode) type.bodyDeclarations().get(0);
+ MethodDeclaration method = (MethodDeclaration) node;
+
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) method.getBody().statements().get(0);
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) statement.fragments().get(0);
+ CastExpression cast = (CastExpression) ((ParenthesizedExpression)fragment.getInitializer()).getExpression();
+ Type castType = cast.getType();
+ assertEquals("Not an intersection cast type", ASTNode.INTERSECTION_TYPE, castType.getNodeType());
+
+ {
+ // Modify intersection cast types by adding new types and removing and adding annotations
+ ListRewrite listRewrite = rewrite.getListRewrite(castType, IntersectionType.TYPES_PROPERTY);
+ SimpleType simpleType = ast.newSimpleType(ast.newSimpleName("J"));
+ MarkerAnnotation annot = ast.newMarkerAnnotation();
+ annot.setTypeName(ast.newSimpleName("Marker3"));
+ simpleType.annotations().add(annot);
+ listRewrite.insertLast(simpleType, null);
+
+ simpleType = (SimpleType) ((IntersectionType) castType).types().get(0);
+ listRewrite = rewrite.getListRewrite(simpleType, SimpleType.ANNOTATIONS_PROPERTY);
+ listRewrite.remove((ASTNode) simpleType.annotations().get(0), null);
+ listRewrite.remove((ASTNode) simpleType.annotations().get(1), null);
+ }
+ {
+ // Create new intersection cast types
+ IntersectionType intersection = ast.newIntersectionType();
+ SimpleType simpleType = ast.newSimpleType(ast.newSimpleName("I"));
+ MarkerAnnotation annot = ast.newMarkerAnnotation();
+ annot.setTypeName(ast.newSimpleName("Marker1"));
+ simpleType.annotations().add(annot);
+ intersection.types().add(simpleType);
+
+ simpleType = ast.newSimpleType(ast.newSimpleName("J"));
+ annot = ast.newMarkerAnnotation();
+ annot.setTypeName(ast.newSimpleName("Marker2"));
+ simpleType.annotations().add(annot);
+ intersection.types().add(simpleType);
+
+ simpleType = ast.newSimpleType(ast.newSimpleName("Serializable"));
+ annot = ast.newMarkerAnnotation();
+ annot.setTypeName(ast.newSimpleName("Marker3"));
+ simpleType.annotations().add(annot);
+ intersection.types().add(simpleType);
+
+ statement = (VariableDeclarationStatement) method.getBody().statements().get(1);
+ fragment = (VariableDeclarationFragment) statement.fragments().get(0);
+ CastExpression castExp = ast.newCastExpression();
+ castExp.setType(intersection);
+ castExp.setExpression(ast.newSimpleName("obj"));
+ rewrite.set(fragment, VariableDeclarationFragment.INITIALIZER_PROPERTY, castExp, null);
+ }
+ {
+ IntersectionType intersection = ast.newIntersectionType();
+ SimpleType simpleType = ast.newSimpleType(ast.newSimpleName("I"));
+ MarkerAnnotation annot = ast.newMarkerAnnotation();
+ annot.setTypeName(ast.newSimpleName("Marker1"));
+ simpleType.annotations().add(annot);
+ intersection.types().add(simpleType);
+
+ simpleType = ast.newSimpleType(ast.newSimpleName("Serializable"));
+ annot = ast.newMarkerAnnotation();
+ annot.setTypeName(ast.newSimpleName("Marker2"));
+ simpleType.annotations().add(annot);
+ intersection.types().add(simpleType);
+
+ statement = (VariableDeclarationStatement) method.getBody().statements().get(2);
+ fragment = (VariableDeclarationFragment) statement.fragments().get(0);
+ CastExpression castExp = (CastExpression) fragment.getInitializer();
+ rewrite.set(castExp, CastExpression.TYPE_PROPERTY, intersection, null);
+ }
+ { // Add a new cast expression
+ cast = ast.newCastExpression();
+ IntersectionType intersection = ast.newIntersectionType();
+ SimpleType simpleType = ast.newSimpleType(ast.newSimpleName("I"));
+ MarkerAnnotation annot = ast.newMarkerAnnotation();
+ annot.setTypeName(ast.newSimpleName("Marker1"));
+ simpleType.annotations().add(annot);
+ intersection.types().add(simpleType);
+
+ simpleType = ast.newSimpleType(ast.newSimpleName("Serializable"));
+ annot = ast.newMarkerAnnotation();
+ annot.setTypeName(ast.newSimpleName("Marker2"));
+ simpleType.annotations().add(annot);
+ intersection.types().add(simpleType);
+ cast.setType(intersection);
+ cast.setExpression(ast.newSimpleName("obj"));
+
+ ReturnStatement returnSt = ast.newReturnStatement();
+ returnSt.setExpression(cast);
+ ListRewrite listRewrite = rewrite.getListRewrite(method.getBody(), Block.STATEMENTS_PROPERTY);
+ listRewrite.insertLast(returnSt, null);
+ }
+ String preview= evaluateRewrite(cu, rewrite);
+ content =
+ "import java.io.Serializable;\n" +
+ "public class X {\n" +
+ " public Serializable main(Object obj) {\n" +
+ " Serializable o = ((Serializable & I & @Marker3\n" +
+ " J) () -> {});\n" +
+ " Serializable oo = (@Marker1 I & @Marker2 J & @Marker3 Serializable) obj;\n" +
+ " Serializable ooo = (@Marker1 I & @Marker2 Serializable) obj;\n" +
+ " return (@Marker1 I & @Marker2 Serializable) obj;\n" +
+ " }\n" +
+ "}\n" +
+ "interface I {\n" +
+ " public void foo();\n" +
+ "}\n" +
+ "interface J {\n" +
+ " public void foo();\n" +
+ " public void bar();\n" +
+ "}\n" +
+ "interface K {\n" +
+ " public void foo();\n" +
+ " public void bar();\n" +
+ "}\n";
+ assertEqualString(preview, content);
+ }
+
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingLambdaExpressionTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingLambdaExpressionTest.java
new file mode 100644
index 0000000..e0ac46b
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingLambdaExpressionTest.java
@@ -0,0 +1,289 @@
+/*******************************************************************************
+ * Copyright (c) 2013 IBM Corporation and others.
+ * 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.core.tests.rewrite.describing;
+
+import java.util.List;
+
+import junit.framework.Test;
+
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.jdt.core.dom.*;
+import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
+
+public class ASTRewritingLambdaExpressionTest extends ASTRewritingTest {
+
+ public ASTRewritingLambdaExpressionTest(String name) {
+ super(name);
+ }
+
+ public ASTRewritingLambdaExpressionTest(String name, int apiLevel) {
+ super(name, apiLevel);
+ }
+
+ public static Test suite() {
+ return createSuite(ASTRewritingLambdaExpressionTest.class);
+ }
+
+ public void testLambdaExpressions_since_8() throws Exception {
+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
+ StringBuffer buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("interface I {\n");
+ buf.append(" int foo(int x);\n");
+ buf.append("}\n");
+ buf.append("interface J {\n");
+ buf.append(" int foo();\n");
+ buf.append("}\n");
+ buf.append("public class X {\n");
+ buf.append(" I i = vlambda -> {return 200;};\n");
+ buf.append(" J j = () -> 1729;\n");
+ buf.append("}\n");
+ ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= createAST(cu);
+ ASTRewrite rewrite= ASTRewrite.create(astRoot.getAST());
+ AST ast= astRoot.getAST();
+
+ TypeDeclaration typedeclaration= findTypeDeclaration(astRoot, "I");
+
+ { // change return type
+ MethodDeclaration methodDecl= findMethodDeclaration(typedeclaration, "foo");
+ assertTrue("null return type: foo", methodDecl.getReturnType2() != null);
+
+ Type returnType= methodDecl.getReturnType2();
+ Type newReturnType= astRoot.getAST().newPrimitiveType(PrimitiveType.FLOAT);
+ rewrite.replace(returnType, newReturnType, null);
+ }
+ { // add a parameter to the singleton function in the interface.
+ MethodDeclaration methodDecl= findMethodDeclaration(typedeclaration, "foo");
+ List parameters= methodDecl.parameters();
+ assertTrue("must be 1 parameter", parameters.size() == 1);
+
+ SingleVariableDeclaration decl= ast.newSingleVariableDeclaration();
+ decl.setType(ast.newPrimitiveType(PrimitiveType.INT));
+ decl.setName(ast.newSimpleName("y"));
+ rewrite.getListRewrite(methodDecl, MethodDeclaration.PARAMETERS_PROPERTY).insertLast(decl, null);
+ }
+
+ { // insert a parameter
+ typedeclaration= findTypeDeclaration(astRoot, "J");
+ MethodDeclaration methodDecl = findMethodDeclaration(typedeclaration, "foo");
+ List parameters = methodDecl.parameters();
+ assertTrue("must be 0 parameters", parameters.size() == 0);
+
+ SingleVariableDeclaration newParam= ast.newSingleVariableDeclaration();
+ newParam.setName(ast.newSimpleName("x"));
+ newParam.setType(ast.newPrimitiveType(PrimitiveType.INT));
+ rewrite.getListRewrite(methodDecl, MethodDeclaration.PARAMETERS_PROPERTY).insertFirst(newParam, null);
+ }
+
+ typedeclaration= findTypeDeclaration(astRoot, "X");
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) typedeclaration.bodyDeclarations().get(0);
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment)fieldDeclaration.fragments().get(0);
+ Expression expression = fragment.getInitializer();
+ assertTrue(expression instanceof LambdaExpression);
+ LambdaExpression lambdaExpression = (LambdaExpression)expression;
+
+ {// add a parameter to the lambda expression
+ List parameters= lambdaExpression.parameters();
+ assertTrue("must be 1 parameter", parameters.size() == 1);
+ ASTNode firstParam= (ASTNode) parameters.get(0);
+ VariableDeclarationFragment newParam= ast.newVariableDeclarationFragment();
+ newParam.setName(ast.newSimpleName("wlambda"));
+ rewrite.getListRewrite(lambdaExpression, LambdaExpression.PARAMETERS_PROPERTY).insertAfter(newParam, firstParam, null);
+ }
+
+ {// replace the block body with a float literal expression body.
+ ASTNode body = lambdaExpression.getBody();
+ ASTNode newBody = ast.newNumberLiteral("3.14");
+ rewrite.replace(body, newBody, null);
+ }
+
+ fieldDeclaration = (FieldDeclaration) typedeclaration.bodyDeclarations().get(1);
+ fragment = (VariableDeclarationFragment)fieldDeclaration.fragments().get(0);
+ expression = fragment.getInitializer();
+ assertTrue(expression instanceof LambdaExpression);
+ lambdaExpression = (LambdaExpression)expression;
+
+ {// add a parameter to the lambda expression - border case - empty list initially
+ List parameters= lambdaExpression.parameters();
+ assertTrue("must be 0 parameter", parameters.size() == 0);
+ VariableDeclarationFragment newParam= ast.newVariableDeclarationFragment();
+ newParam.setName(ast.newSimpleName("vlambda"));
+ rewrite.getListRewrite(lambdaExpression, LambdaExpression.PARAMETERS_PROPERTY).insertFirst(newParam, null);
+ }
+ String preview= evaluateRewrite(cu, rewrite);
+
+ buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("interface I {\n");
+ buf.append(" float foo(int x, int y);\n");
+ buf.append("}\n");
+ buf.append("interface J {\n");
+ buf.append(" int foo(int x);\n");
+ buf.append("}\n");
+ buf.append("public class X {\n");
+ buf.append(" I i = (vlambda, wlambda) -> 3.14;\n");
+ buf.append(" J j = (vlambda) -> 1729;\n");
+ buf.append("}\n");
+ assertEqualString(preview, buf.toString());
+ }
+
+ public void testLambdaExpressions_Parentheses_since_8() throws Exception {
+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
+ StringBuffer buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("interface I {\n");
+ buf.append(" int foo(int x);\n");
+ buf.append("}\n");
+ buf.append("interface J {\n");
+ buf.append(" int foo();\n");
+ buf.append("}\n");
+ buf.append("interface K {\n");
+ buf.append(" int foo(int x, int y);\n");
+ buf.append("}\n");
+ buf.append("interface L {\n");
+ buf.append(" int foo(int x);\n");
+ buf.append("}\n");
+ buf.append("public class X {\n");
+ buf.append(" I i = vlambda -> 22121887;\n");
+ buf.append(" I idash = (vlambda) -> 1729;\n");
+ buf.append(" J j = () -> 26041920;\n");
+ buf.append(" K k = (x, y) -> 1729;\n");
+ buf.append(" K kdash = (int x, int y) -> 1729;\n");
+ buf.append(" L l = vlambda -> 1729;\n");
+ buf.append("}\n");
+ ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot= createAST(cu);
+ ASTRewrite rewrite= ASTRewrite.create(astRoot.getAST());
+ AST ast= astRoot.getAST();
+
+ { // remove a parameter
+ TypeDeclaration typedeclaration= findTypeDeclaration(astRoot, "L");
+ MethodDeclaration methodDecl = findMethodDeclaration(typedeclaration, "foo");
+ List parameters = methodDecl.parameters();
+ assertTrue("must be 1 parameter", parameters.size() == 1);
+ ASTNode param = (ASTNode) parameters.get(0);
+ rewrite.getListRewrite(methodDecl, MethodDeclaration.PARAMETERS_PROPERTY).remove(param, null);
+ }
+
+ int fCount = 0;
+
+ TypeDeclaration typedeclaration= findTypeDeclaration(astRoot, "X");
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) typedeclaration.bodyDeclarations().get(fCount++);
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment)fieldDeclaration.fragments().get(0);
+ LambdaExpression lambdaExpression = (LambdaExpression)fragment.getInitializer();
+
+ {// set parentheses
+ assertTrue("lambda expression has parantheses", lambdaExpression.hasParentheses() == false);
+ rewrite.set(lambdaExpression, LambdaExpression.PARENTHESES_PROPERTY, Boolean.TRUE, null);
+ }
+
+ fieldDeclaration = (FieldDeclaration) typedeclaration.bodyDeclarations().get(fCount++);
+ fragment = (VariableDeclarationFragment)fieldDeclaration.fragments().get(0);
+ lambdaExpression = (LambdaExpression)fragment.getInitializer();
+
+ {// reset parentheses - a legal operation here.
+ assertTrue("lambda expression has parantheses", lambdaExpression.hasParentheses() == true);
+ rewrite.set(lambdaExpression, LambdaExpression.PARENTHESES_PROPERTY, Boolean.FALSE, null);
+ }
+
+ fieldDeclaration = (FieldDeclaration) typedeclaration.bodyDeclarations().get(fCount++);
+ fragment = (VariableDeclarationFragment)fieldDeclaration.fragments().get(0);
+ lambdaExpression = (LambdaExpression)fragment.getInitializer();
+
+ {// reset parentheses - an illegal operation here.
+ assertTrue("lambda expression does not have parantheses", lambdaExpression.hasParentheses() == true);
+ rewrite.set(lambdaExpression, LambdaExpression.PARENTHESES_PROPERTY, Boolean.FALSE, null);
+ }
+
+ fieldDeclaration = (FieldDeclaration) typedeclaration.bodyDeclarations().get(fCount++);
+ fragment = (VariableDeclarationFragment)fieldDeclaration.fragments().get(0);
+ lambdaExpression = (LambdaExpression)fragment.getInitializer();
+
+ {// reset parentheses - an illegal operation here.
+ assertTrue("lambda expression does not have parantheses", lambdaExpression.hasParentheses() == true);
+ rewrite.set(lambdaExpression, LambdaExpression.PARENTHESES_PROPERTY, Boolean.FALSE, null);
+ }
+
+ {// change all the parameter to SVD ie add type info to the parameters.
+ List parameters = lambdaExpression.parameters();
+ VariableDeclaration param = (VariableDeclaration)parameters.get(0);
+ SingleVariableDeclaration newParam= ast.newSingleVariableDeclaration();
+ newParam.setName(ast.newSimpleName(new String(param.toString())));
+ newParam.setType(ast.newPrimitiveType(PrimitiveType.INT));
+ rewrite.getListRewrite(lambdaExpression, LambdaExpression.PARAMETERS_PROPERTY).replace(param, newParam, null);
+
+ param = (VariableDeclaration)parameters.get(1);
+ newParam= ast.newSingleVariableDeclaration();
+ newParam.setName(ast.newSimpleName(new String(param.toString())));
+ newParam.setType(ast.newPrimitiveType(PrimitiveType.INT));
+ rewrite.getListRewrite(lambdaExpression, LambdaExpression.PARAMETERS_PROPERTY).replace(param, newParam, null);
+ }
+
+ {// Remove type info from the parameters.
+
+ fieldDeclaration = (FieldDeclaration) typedeclaration.bodyDeclarations().get(fCount++);
+ fragment = (VariableDeclarationFragment)fieldDeclaration.fragments().get(0);
+ lambdaExpression = (LambdaExpression)fragment.getInitializer();
+ List parameters = lambdaExpression.parameters();
+
+ for (int i = 0; i < parameters.size(); ++i) {
+ SingleVariableDeclaration param = (SingleVariableDeclaration)parameters.get(i);
+ VariableDeclarationFragment newParam= ast.newVariableDeclarationFragment();
+ newParam.setName(ast.newSimpleName(new String(param.getName().toString())));
+ rewrite.getListRewrite(lambdaExpression, LambdaExpression.PARAMETERS_PROPERTY).replace(param, newParam, null);
+ }
+ }
+
+ fieldDeclaration = (FieldDeclaration) typedeclaration.bodyDeclarations().get(fCount++);
+ fragment = (VariableDeclarationFragment)fieldDeclaration.fragments().get(0);
+ lambdaExpression = (LambdaExpression)fragment.getInitializer();
+
+ {// remove the only parameter and the rewriter should automatically add the parentheses
+ List parameters = lambdaExpression.parameters();
+ ASTNode param = (ASTNode)parameters.get(0);
+ rewrite.getListRewrite(lambdaExpression, LambdaExpression.PARAMETERS_PROPERTY).remove(param, null);
+ }
+
+ String preview= evaluateRewrite(cu, rewrite);
+
+ buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("interface I {\n");
+ buf.append(" int foo(int x);\n");
+ buf.append("}\n");
+ buf.append("interface J {\n");
+ buf.append(" int foo();\n");
+ buf.append("}\n");
+ buf.append("interface K {\n");
+ buf.append(" int foo(int x, int y);\n");
+ buf.append("}\n");
+ buf.append("interface L {\n");
+ buf.append(" int foo();\n");
+ buf.append("}\n");
+ buf.append("public class X {\n");
+ buf.append(" I i = (vlambda) -> 22121887;\n");
+ buf.append(" I idash = vlambda -> 1729;\n");
+ buf.append(" J j = () -> 26041920;\n");
+ buf.append(" K k = (int x, int y) -> 1729;\n");
+ buf.append(" K kdash = (x, y) -> 1729;\n");
+ buf.append(" L l = () -> 1729;\n");
+ buf.append("}\n");
+ assertEqualString(preview, buf.toString());
+ }
+}
\ No newline at end of file
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingMethodDeclTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingMethodDeclTest.java
index 2e63c50..7a21225 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingMethodDeclTest.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingMethodDeclTest.java
@@ -3646,4 +3646,106 @@
"}\n";
assertEqualString(preview, contents);
}
+
+ public void testReceiverParam_since_8() throws Exception {
+ IPackageFragment pack1 = this.sourceFolder.createPackageFragment("test1", false, null);
+ StringBuffer buf = new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("public abstract class E {\n");
+ buf.append(" public void foo() {\n");
+ buf.append(" }\n");
+ buf.append("\n");
+ buf.append("}\n");
+ ICompilationUnit cu = pack1.createCompilationUnit("E.java", buf.toString(), false, null);
+
+ CompilationUnit astRoot = createAST(cu);
+ AST ast = astRoot.getAST();
+ ASTRewrite rewrite = ASTRewrite.create(astRoot.getAST());
+ TypeDeclaration type = findTypeDeclaration(astRoot, "E");
+
+ MethodDeclaration newMethodDeclaration = ast.newMethodDeclaration();
+ SimpleName methodName = ast.newSimpleName("bar");
+ SimpleType simpleType = ast.newSimpleType(ast.newSimpleName("E"));
+ MarkerAnnotation annotationC = ast.newMarkerAnnotation();
+ annotationC.setTypeName(ast.newSimpleName("C"));
+ simpleType.annotations().add(annotationC);
+ newMethodDeclaration.setName(methodName);
+ newMethodDeclaration.setReceiverType(simpleType);
+
+ MethodDeclaration[] methods = type.getMethods();
+ MethodDeclaration methodDeclaration = methods[0];
+ methodDeclaration.setReceiverType(ast.newSimpleType(ast.newSimpleName("E")));
+
+ ListRewrite listRewrite = rewrite.getListRewrite(type, TypeDeclaration.BODY_DECLARATIONS_PROPERTY);
+ listRewrite.insertLast(newMethodDeclaration, null);
+
+ String preview = evaluateRewrite(cu, rewrite);
+
+ buf = new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("public abstract class E {\n");
+ buf.append(" public void foo() {\n");
+ buf.append(" }\n");
+ buf.append("\n");
+ buf.append(" void bar(@C E this);\n");
+ buf.append("\n");
+ buf.append("}\n");
+
+ assertEqualString(preview, buf.toString());
+ }
+
+ public void testReceiverParam_InnerClass_since_8() throws Exception {
+ IPackageFragment pack1 = this.sourceFolder.createPackageFragment(
+ "test1", false, null);
+ StringBuffer buf = new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("public class E {\n");
+ buf.append(" public void foo() {\n");
+ buf.append(" }\n");
+ buf.append("\n");
+ buf.append(" class Inner{\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ ICompilationUnit cu = pack1.createCompilationUnit("E.java",
+ buf.toString(), false, null);
+
+ CompilationUnit astRoot = createAST(cu);
+ AST ast = astRoot.getAST();
+ ASTRewrite rewrite = ASTRewrite.create(astRoot.getAST());
+ TypeDeclaration type = findTypeDeclaration(astRoot, "E");
+ TypeDeclaration inner = (TypeDeclaration) type.bodyDeclarations().get(1);
+
+ MethodDeclaration newMethodDeclaration = ast.newMethodDeclaration();
+ SimpleName methodName = ast.newSimpleName("Inner");
+ SimpleType simpleType = ast.newSimpleType(ast.newSimpleName("E"));
+ MarkerAnnotation annotationC = ast.newMarkerAnnotation();
+ annotationC.setTypeName(ast.newSimpleName("C"));
+ simpleType.annotations().add(annotationC);
+ newMethodDeclaration.setName(methodName);
+ newMethodDeclaration.setConstructor(true);
+ newMethodDeclaration.setReceiverType(simpleType);
+ newMethodDeclaration.setReceiverQualifier(ast.newSimpleName("E"));
+ newMethodDeclaration.setBody(ast.newBlock());
+
+ ListRewrite listRewrite = rewrite.getListRewrite(inner, TypeDeclaration.BODY_DECLARATIONS_PROPERTY);
+ listRewrite.insertLast(newMethodDeclaration, null);
+
+ String preview = evaluateRewrite(cu, rewrite);
+
+ buf = new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("public class E {\n");
+ buf.append(" public void foo() {\n");
+ buf.append(" }\n");
+ buf.append("\n");
+ buf.append(" class Inner{\n");
+ buf.append("\n");
+ buf.append(" Inner(@C E E.this) {\n");
+ buf.append(" }\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+
+ assertEqualString(preview, buf.toString());
+ }
+
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingTest.java
index dac2a1e..4da4896 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingTest.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingTest.java
@@ -114,17 +114,30 @@
suite.addTest(ASTRewritingWithStatementsRecoveryTest.suite());
suite.addTest(ASTRewritePropertyTest.suite());
suite.addTest(ASTRewritingPackageDeclTest.suite());
-
+ suite.addTest(ASTRewritingLambdaExpressionTest.suite());
suite.addTest(SourceModifierTest.suite());
suite.addTest(ImportRewriteTest.suite());
return suite;
}
/**
+ * Creates a test suite according to the rules in {@link ASTRewritingTest}.
+ *
* @param testClass subclass of ASTRewritingTest
* @return test suite that runs all tests with all supported AST levels
*/
protected static TestSuite createSuite(Class testClass) {
+ return createSuite(testClass, -1);
+ }
+
+ /**
+ * Creates a test suite according to the rules in {@link ASTRewritingTest}.
+ *
+ * @param testClass subclass of ASTRewritingTest
+ * @param classSince smallest supported AST level for this test class, or -1 to support all levels
+ * @return test suite that runs all tests with all supported AST levels
+ */
+ protected static TestSuite createSuite(Class testClass, int classSince) {
TestSuite suite = new TestSuite(testClass.getName());
try {
Method[] methods = testClass.getMethods();
@@ -150,8 +163,8 @@
}
for (int j= 0; j < JLS_LEVELS.length; j++) {
int level = JLS_LEVELS[j];
- if (level >= since) {
- suite.addTest((Test) cons.newInstance(new Object[]{name, new Integer(level)}));
+ if (level >= since && level >= classSince) {
+ suite.addTest((Test) cons.newInstance(new Object[]{name, new Integer(level)}));
}
}
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingTypeAnnotationsTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingTypeAnnotationsTest.java
index bb1ab58..56d7886 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingTypeAnnotationsTest.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingTypeAnnotationsTest.java
@@ -32,11 +32,10 @@
}
public static Test suite() {
- return createSuite(ASTRewritingTypeAnnotationsTest.class);
+ return createSuite(ASTRewritingTypeAnnotationsTest.class, AST.JLS8);
}
public void testCastAnnotations() throws Exception {
- if (this.apiLevel < AST.JLS8) return;
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf= new StringBuffer();
buf.append("package test1;\n");
@@ -101,7 +100,6 @@
}
public void testWildcardTypeArgumentAnnotations() throws Exception {
- if (this.apiLevel < AST.JLS8) return;
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf= new StringBuffer();
buf.append("package test1;\n");
@@ -201,7 +199,6 @@
}
public void testWildcardBoudAnnotation() throws Exception {
- if (this.apiLevel < AST.JLS8) return;
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf= new StringBuffer();
@@ -262,7 +259,6 @@
}
public void testTypeParameterBoundAnnotations() throws Exception {
- if (this.apiLevel < AST.JLS8) return;
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf= new StringBuffer();
@@ -329,7 +325,6 @@
}
public void testTypeArgumentsParameterizedClassesAnnotations() throws Exception {
- if (this.apiLevel < AST.JLS8) return;
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf= new StringBuffer();
@@ -396,7 +391,6 @@
}
public void testTypeArgumentsMethodInvocation() throws Exception {
- if (this.apiLevel < AST.JLS8) return;
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf= new StringBuffer();
@@ -477,7 +471,6 @@
}
public void testClassInheritenceAnnotations() throws Exception {
- if (this.apiLevel < AST.JLS8) return;
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf= new StringBuffer();
@@ -544,7 +537,6 @@
}
public void testTypeTests() throws Exception {
- if (this.apiLevel < AST.JLS8) return;
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf= new StringBuffer();
@@ -620,7 +612,6 @@
}
public void testConstructorInvocation() throws Exception {
- if (this.apiLevel < AST.JLS8) return;
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf= new StringBuffer();
buf.append("import java.lang.annotation.ElementType;\n");
@@ -690,7 +681,6 @@
}
public void testConstructorDeclaration() throws Exception {
- if (this.apiLevel < AST.JLS8) return;
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf= new StringBuffer();
buf.append("import java.lang.annotation.ElementType;\n");
@@ -749,7 +739,6 @@
}
public void testRewriteInsertAPIAnnotation() throws Exception {
- if (this.apiLevel < AST.JLS8) return;
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf= new StringBuffer();
@@ -821,7 +810,6 @@
}
public void _testEmptyListInsertAnnotation() throws Exception {
- if (this.apiLevel < AST.JLS8) return;
IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
StringBuffer buf= new StringBuffer();
buf.append("package test1;\n");
@@ -860,4 +848,128 @@
assertEqualString(preview, buf.toString());
}
+ /**
+ * ASTRewriterTests for PackageQualifiedType
+ * @throws Exception
+ *
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=406469
+ */
+ public void testPackageQualifiedTypeAnnotations() throws Exception {
+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("test406469.bug", false, null);
+ String contents = "package test406469.bug;\n" +
+ "import java.lang.annotation.*;\n" +
+ "public class X {\n" +
+ " @Target(ElementType.TYPE_USE)\n" +
+ " @Retention(RetentionPolicy.RUNTIME)\n" +
+ " @Documented\n" +
+ " static @interface NonNull { }\n" +
+ " class Inner {}\n" +
+ " \n" +
+ " /**\n" +
+ " * @param arg \n" +
+ " */\n" +
+ " test406469.bug.@NonNull IOException foo(\n" +
+ " test406469.bug.@NonNull FileNotFoundException arg)\n" +
+ " throws test406469.bug.@NonNull EOFException {\n" +
+ " try {\n" +
+ " test406469.bug.@NonNull IOError e = new test406469.bug.IOError();\n" +
+ " throw e;\n" +
+ " } catch (test406469.bug.@NonNull IOError e) {\n" +
+ " }\n" +
+ " return null;\n" +
+ " } \n" +
+ " test406469.bug.@NonNull X.@NonNull Inner fInner;\n" +
+ "} \n" +
+ "@java.lang.annotation.Target(java.lang.annotation.ElementType.TYPE_USE) @interface Marker {} \n" +
+ "\n" +
+ "class Outer {\n" +
+ " public class Inner {\n" +
+ " public class Deeper {}\n" +
+ " }\n" +
+ "}\n" +
+ "class IOException extends Exception {private static final long serialVersionUID=10001L;}\n" +
+ "class FileNotFoundException extends Exception{private static final long serialVersionUID=10002L;}\n" +
+ "class EOFException extends Exception{private static final long serialVersionUID=10003L;}\n" +
+ "class IOError extends Exception{private static final long serialVersionUID=10004L;}\n";
+ StringBuffer buf = new StringBuffer(contents);
+ ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
+ CompilationUnit astRoot= createAST(cu, /* resolve */ true, false);
+ ASTRewrite rewrite= ASTRewrite.create(astRoot.getAST());
+ AST ast= astRoot.getAST();
+ TypeDeclaration typeDeclaration= findTypeDeclaration(astRoot, "X");
+ MethodDeclaration methodDeclaration= findMethodDeclaration(typeDeclaration, "foo");
+ { //replace an annotation.
+ PackageQualifiedType packageQualifiedType = (PackageQualifiedType) methodDeclaration.getReturnType2();
+ MarkerAnnotation markerAnnotation= ast.newMarkerAnnotation();
+ markerAnnotation.setTypeName(ast.newSimpleName("Marker"));
+ rewrite.replace((ASTNode) packageQualifiedType.annotations().get(0), markerAnnotation, null);
+
+ // remove an annotation
+ SingleVariableDeclaration param = (SingleVariableDeclaration) methodDeclaration.parameters().get(0);
+ packageQualifiedType = (PackageQualifiedType) param.getType();
+ rewrite.remove((ASTNode) packageQualifiedType.annotations().get(0), null);
+
+ // insert an annotation after an existing annotation
+ packageQualifiedType = (PackageQualifiedType) methodDeclaration.thrownExceptionTypes().get(0);
+ markerAnnotation= ast.newMarkerAnnotation();
+ markerAnnotation.setTypeName(ast.newSimpleName("Marker"));
+ rewrite.getListRewrite(packageQualifiedType, PackageQualifiedType.ANNOTATIONS_PROPERTY).insertLast(markerAnnotation, null);
+
+ /* insert an annotation in a type not converted as a PackageQualifiedType. This would involve
+ * creation of a PackageQualifiedType from fields of the existing type.
+ */
+ TryStatement tryStatement = (TryStatement) methodDeclaration.getBody().statements().get(0);
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) tryStatement.getBody().statements().get(0);
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) variableDeclarationStatement.fragments().get(0);
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) variableDeclarationFragment.getInitializer();
+ SimpleType simpleType = (SimpleType) classInstanceCreation.getType();
+ QualifiedName qualifiedName = (QualifiedName) simpleType.getName();
+ SimpleName simpleName = ast.newSimpleName(qualifiedName.getName().getIdentifier());
+ qualifiedName = (QualifiedName) qualifiedName.getQualifier();
+ qualifiedName = ast.newQualifiedName(ast.newName(qualifiedName.getQualifier().toString()), ast.newSimpleName(qualifiedName.getName().toString()));
+ packageQualifiedType = ast.newPackageQualifiedType(qualifiedName, simpleName);
+ markerAnnotation= ast.newMarkerAnnotation();
+ markerAnnotation.setTypeName(ast.newSimpleName("Marker"));
+ rewrite.getListRewrite(packageQualifiedType, PackageQualifiedType.ANNOTATIONS_PROPERTY).insertLast(markerAnnotation, null);
+ rewrite.replace(classInstanceCreation.getType(), packageQualifiedType, null);
+ }
+ String preview= evaluateRewrite(cu, rewrite);
+ String contentsmodified = "package test406469.bug;\n" +
+ "import java.lang.annotation.*;\n" +
+ "public class X {\n" +
+ " @Target(ElementType.TYPE_USE)\n" +
+ " @Retention(RetentionPolicy.RUNTIME)\n" +
+ " @Documented\n" +
+ " static @interface NonNull { }\n" +
+ " class Inner {}\n" +
+ " \n" +
+ " /**\n" +
+ " * @param arg \n" +
+ " */\n" +
+ " test406469.bug.@Marker IOException foo(\n" +
+ " FileNotFoundException arg)\n" +
+ " throws test406469.bug.@NonNull @Marker EOFException {\n" +
+ " try {\n" +
+ " test406469.bug.@NonNull IOError e = new test406469.bug.@Marker IOError();\n" +
+ " throw e;\n" +
+ " } catch (test406469.bug.@NonNull IOError e) {\n" +
+ " }\n" +
+ " return null;\n" +
+ " } \n" +
+ " test406469.bug.@NonNull X.@NonNull Inner fInner;\n" +
+ "} \n" +
+ "@java.lang.annotation.Target(java.lang.annotation.ElementType.TYPE_USE) @interface Marker {} \n" +
+ "\n" +
+ "class Outer {\n" +
+ " public class Inner {\n" +
+ " public class Deeper {}\n" +
+ " }\n" +
+ "}\n" +
+ "class IOException extends Exception {private static final long serialVersionUID=10001L;}\n" +
+ "class FileNotFoundException extends Exception{private static final long serialVersionUID=10002L;}\n" +
+ "class EOFException extends Exception{private static final long serialVersionUID=10003L;}\n" +
+ "class IOError extends Exception{private static final long serialVersionUID=10004L;}\n";
+ assertEqualString(preview, contentsmodified);
+ }
+
}
\ No newline at end of file
diff --git a/org.eclipse.jdt.core.tests.model/workspace/Converter15/src/test404489/bug/X.java b/org.eclipse.jdt.core.tests.model/workspace/Converter15/src/test404489/bug/X.java
new file mode 100644
index 0000000..4cf542a
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/workspace/Converter15/src/test404489/bug/X.java
@@ -0,0 +1,37 @@
+package test404489.bug;
+import java.lang.annotation.*;
+public class X {
+ @Target(ElementType.TYPE_USE)
+ @Retention(RetentionPolicy.RUNTIME)
+ @Documented
+ static @interface NonNull { }
+ class Inner {}
+
+ /**
+ * @param arg
+ */
+ test404489.bug.@NonNull IOException foo(
+ test404489.bug.@NonNull FileNotFoundException arg)
+ throws test404489.bug.@NonNull EOFException {
+ try {
+ test404489.bug.@NonNull IOError e = new test404489.bug.IOError();
+ throw e;
+ } catch (test404489.bug.@NonNull IOError e) {
+ }
+ return null;
+ }
+ test404489.bug.@NonNull X.@NonNull Inner fInner;
+}
+@java.lang.annotation.Target(java.lang.annotation.ElementType.TYPE_USE) @interface Marker {}
+@java.lang.annotation.Target(java.lang.annotation.ElementType.TYPE_USE) @interface A {}
+@java.lang.annotation.Target(java.lang.annotation.ElementType.TYPE_USE) @interface B {}
+
+class Outer {
+ public class Inner {
+ public class Deeper {}
+ }
+}
+class IOException extends Exception {private static final long serialVersionUID=10001L;}
+class FileNotFoundException extends Exception{private static final long serialVersionUID=10002L;}
+class EOFException extends Exception{private static final long serialVersionUID=10003L;}
+class IOError extends Exception{private static final long serialVersionUID=10004L;}
\ No newline at end of file
diff --git a/org.eclipse.jdt.core.tests.model/workspace/Converter18/src/test404489/bug/X.java b/org.eclipse.jdt.core.tests.model/workspace/Converter18/src/test404489/bug/X.java
new file mode 100644
index 0000000..4cf542a
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/workspace/Converter18/src/test404489/bug/X.java
@@ -0,0 +1,37 @@
+package test404489.bug;
+import java.lang.annotation.*;
+public class X {
+ @Target(ElementType.TYPE_USE)
+ @Retention(RetentionPolicy.RUNTIME)
+ @Documented
+ static @interface NonNull { }
+ class Inner {}
+
+ /**
+ * @param arg
+ */
+ test404489.bug.@NonNull IOException foo(
+ test404489.bug.@NonNull FileNotFoundException arg)
+ throws test404489.bug.@NonNull EOFException {
+ try {
+ test404489.bug.@NonNull IOError e = new test404489.bug.IOError();
+ throw e;
+ } catch (test404489.bug.@NonNull IOError e) {
+ }
+ return null;
+ }
+ test404489.bug.@NonNull X.@NonNull Inner fInner;
+}
+@java.lang.annotation.Target(java.lang.annotation.ElementType.TYPE_USE) @interface Marker {}
+@java.lang.annotation.Target(java.lang.annotation.ElementType.TYPE_USE) @interface A {}
+@java.lang.annotation.Target(java.lang.annotation.ElementType.TYPE_USE) @interface B {}
+
+class Outer {
+ public class Inner {
+ public class Deeper {}
+ }
+}
+class IOException extends Exception {private static final long serialVersionUID=10001L;}
+class FileNotFoundException extends Exception{private static final long serialVersionUID=10002L;}
+class EOFException extends Exception{private static final long serialVersionUID=10003L;}
+class IOError extends Exception{private static final long serialVersionUID=10004L;}
\ No newline at end of file
diff --git a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java
index 3bd6108..04c4977 100644
--- a/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java
+++ b/org.eclipse.jdt.core/codeassist/org/eclipse/jdt/internal/codeassist/CompletionEngine.java
@@ -658,6 +658,7 @@
public int sourceEnd() { return 0; }
public int sourceStart() { return 0; }
public TypeBinding expectedType() { return null; }
+ public boolean receiverIsImplicitThis() { return false;}
};
private int foundTypesCount;
@@ -6391,7 +6392,7 @@
// We maybe asking for a proposal inside this field's initialization. So record its id
ASTNode astNode = this.parser.assistNode;
if (fieldDeclaration != null && fieldDeclaration.initialization != null && astNode != null) {
- if (fieldDeclaration.initialization.sourceEnd > 0) {
+ if (CharOperation.equals(this.fileName, field.declaringClass.getFileName()) && fieldDeclaration.initialization.sourceEnd > 0) {
if (fieldDeclaration.initialization.sourceStart <= astNode.sourceStart &&
astNode.sourceEnd <= fieldDeclaration.initialization.sourceEnd) {
// completion is inside a field initializer
@@ -10415,8 +10416,8 @@
Argument[] arguments = methodDecl.arguments;
parameterNames = new char[length][];
-//{ObjectTeams:
for(int i = 0 ; i < length ; i++){
+//{ObjectTeams:
/* orig:
parameterNames[i] = arguments[i].name;
:giro */
@@ -10573,6 +10574,7 @@
}
}
boolean hasPotentialDefaultAbstractMethods = true;
+ boolean java8Plus = this.compilerOptions.sourceLevel >= ClassFileConstants.JDK1_8;
while (currentType != null) {
//{ObjectTeams: don't let availableMethods() look in the interface part!
currentType = currentType.getRealClass();
@@ -10607,11 +10609,12 @@
receiverEnd);
}
+ /* Searching of superinterfaces for candidate proposal methods can be skipped if current type is concrete, but only for source levels below 1.8.
+ For 1.8 even a concrete type's superinterfaces should be searched as they could have default methods which are not implemented by the concrete
+ type.
+ */
if (hasPotentialDefaultAbstractMethods &&
- (currentType.isAbstract() ||
- currentType.isTypeVariable() ||
- currentType.isIntersectionType() ||
- currentType.isEnum())){
+ (java8Plus || (currentType.isAbstract() || currentType.isTypeVariable() || currentType.isIntersectionType() || currentType.isEnum()))) {
ReferenceBinding[] superInterfaces = currentType.superInterfaces();
if (superInterfaces != null && currentType.isIntersectionType()) {
@@ -10643,7 +10646,8 @@
receiverStart,
receiverEnd);
} else {
- hasPotentialDefaultAbstractMethods = false;
+ if (!java8Plus)
+ hasPotentialDefaultAbstractMethods = false;
}
currentType = currentType.superclass();
}
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ClassFile.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ClassFile.java
index 834c85a..ab883e0 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ClassFile.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ClassFile.java
@@ -13,6 +13,8 @@
* IBM Corporation - initial API and implementation
* Fraunhofer FIRST - extended API and implementation
* Technical University Berlin - extended API and implementation
+ * Jesper S Moller - Contributions for
+ * Bug 405066 - [1.8][compiler][codegen] Implement code generation infrastructure for JSR335
*******************************************************************************/
package org.eclipse.jdt.internal.compiler;
@@ -26,6 +28,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.Stack;
import org.eclipse.jdt.core.compiler.CategorizedProblem;
import org.eclipse.jdt.core.compiler.CharOperation;
@@ -39,14 +42,24 @@
import org.eclipse.jdt.internal.compiler.ast.ClassLiteralAccess;
import org.eclipse.jdt.internal.compiler.ast.Expression;
import org.eclipse.jdt.internal.compiler.ast.FieldDeclaration;
+import org.eclipse.jdt.internal.compiler.ast.FunctionalExpression;
+import org.eclipse.jdt.internal.compiler.ast.LambdaExpression;
+import org.eclipse.jdt.internal.compiler.ast.LocalDeclaration;
import org.eclipse.jdt.internal.compiler.ast.MemberValuePair;
import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration;
import org.eclipse.jdt.internal.compiler.ast.NormalAnnotation;
+import org.eclipse.jdt.internal.compiler.ast.ParameterizedQualifiedTypeReference;
+import org.eclipse.jdt.internal.compiler.ast.ParameterizedSingleTypeReference;
import org.eclipse.jdt.internal.compiler.ast.QualifiedNameReference;
import org.eclipse.jdt.internal.compiler.ast.SingleMemberAnnotation;
import org.eclipse.jdt.internal.compiler.ast.SingleNameReference;
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
+import org.eclipse.jdt.internal.compiler.ast.TypeParameter;
+import org.eclipse.jdt.internal.compiler.ast.TypeReference;
+import org.eclipse.jdt.internal.compiler.ast.Wildcard;
impo