diff options
author | Curtis Windatt | 2014-04-16 13:54:28 +0000 |
---|---|---|
committer | Curtis Windatt | 2014-04-16 13:54:28 +0000 |
commit | 1c6fe2c59ce4b6a609a1b8fd7b59df473639e2e5 (patch) | |
tree | c43ba3c7f09afb41b4f75f4543150a9c28a133b4 /apitools | |
parent | a0118954ea6adfca51748d92dc13b40dd0d208c6 (diff) | |
download | eclipse.pde.ui-1c6fe2c59ce4b6a609a1b8fd7b59df473639e2e5.tar.gz eclipse.pde.ui-1c6fe2c59ce4b6a609a1b8fd7b59df473639e2e5.tar.xz eclipse.pde.ui-1c6fe2c59ce4b6a609a1b8fd7b59df473639e2e5.zip |
Bug 427502 - [1.8] Support method references
Add annotation tests
Change-Id: I6329428a243df8b6a7371b1c3eef7945002e39b6
Diffstat (limited to 'apitools')
9 files changed, 401 insertions, 4 deletions
diff --git a/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/builder/tests/usage/Java8ConsRefInstantiateUsageTests.java b/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/builder/tests/usage/Java8ConsRefInstantiateUsageTests.java index e9f7a4429b..0eb71eedf5 100644 --- a/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/builder/tests/usage/Java8ConsRefInstantiateUsageTests.java +++ b/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/builder/tests/usage/Java8ConsRefInstantiateUsageTests.java @@ -52,16 +52,14 @@ public class Java8ConsRefInstantiateUsageTests extends Java8UsageTest { /** - * Tests illegal references to method reference and constructor reference - * (full) + * Tests illegal reference to class with no instantiate (full) */ public void testConsRefInstantiateF() { x1(false); } /** - * Tests illegal references to method reference and constructor reference - * (incremental) + * Tests illegal reference to class with no instantiate (incremental) */ public void testConsRefInstantiateI() { x1(true); @@ -94,4 +92,46 @@ public class Java8ConsRefInstantiateUsageTests extends Java8UsageTest { } + /** + * Tests illegal reference to class with no annotation instantiate (full) + */ + public void testConsRefInstantiateAnnoF() { + x2(false); + } + + /** + * Tests illegal reference to class with no annotation instantiate + * (incremental) + */ + public void testConsRefInstantiateAnnoI() { + x2(true); + } + + private void x2(boolean inc) { + int[] pids = new int[] { + + getProblemId(IApiProblem.ILLEGAL_INSTANTIATE, IApiProblem.NO_FLAGS), + getProblemId(IApiProblem.ILLEGAL_INSTANTIATE, IApiProblem.NO_FLAGS), + getProblemId(IApiProblem.ILLEGAL_INSTANTIATE, IApiProblem.NO_FLAGS) }; + setExpectedProblemIds(pids); + String typename = "testConstructorRefInstantiateAnnotation"; //$NON-NLS-1$ + + String[][] args = new String[][] { + { "ConstructorReferenceAnno2", typename }, //$NON-NLS-1$ + { "ConstructorReferenceAnno2", typename }, //$NON-NLS-1$ + { "ConstructorReferenceAnno2", typename } //$NON-NLS-1$ + + }; + setExpectedMessageArgs(args); + setExpectedLineMappings(new LineMapping[] { + new LineMapping(30, pids[0], args[0]), + new LineMapping(32, pids[1], args[1]), + new LineMapping(34, pids[2], args[2]) + + }); + + deployUsageTest(typename, inc); + } + + } diff --git a/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/builder/tests/usage/Java8MethodConstRefUsageTests.java b/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/builder/tests/usage/Java8MethodConstRefUsageTests.java index ae6597c6bc..e9a07c9b7c 100644 --- a/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/builder/tests/usage/Java8MethodConstRefUsageTests.java +++ b/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/builder/tests/usage/Java8MethodConstRefUsageTests.java @@ -139,4 +139,92 @@ public class Java8MethodConstRefUsageTests extends Java8UsageTest { deployUsageTest(typename, inc); } + /** + * Tests illegal annotation references to method reference and constructor + * reference (full) + */ + public void testMethodConstructorRefAnnoF() { + x3(false); + } + + /** + * Tests illegal annotation references to method reference and constructor + * reference (incremental) + */ + public void testMethodConstructorRefAnnoI() { + x3(true); + } + + private void x3(boolean inc) { + int[] pids = new int[] { + + getProblemId(IApiProblem.ILLEGAL_REFERENCE, IApiProblem.METHOD), + getProblemId(IApiProblem.ILLEGAL_REFERENCE, IApiProblem.METHOD), + getProblemId(IApiProblem.ILLEGAL_REFERENCE, IApiProblem.CONSTRUCTOR_METHOD), + getProblemId(IApiProblem.ILLEGAL_REFERENCE, IApiProblem.CONSTRUCTOR_METHOD), + getProblemId(IApiProblem.ILLEGAL_REFERENCE, IApiProblem.CONSTRUCTOR_METHOD) }; + setExpectedProblemIds(pids); + String typename = "testMethodReferenceAnnotation"; //$NON-NLS-1$ + + String[][] args = new String[][] { + { "MethodReferenceAnnotation", typename, "method1()" }, //$NON-NLS-1$ //$NON-NLS-2$ + { "MethodReferenceAnnotation", typename, "method2()" }, //$NON-NLS-1$ //$NON-NLS-2$ + { "ConstructorReferenceAnnotation()", typename, null }, //$NON-NLS-1$ + { "ConstructorReferenceAnnotation(String)", typename, null }, //$NON-NLS-1$ + { + "ConstructorReferenceAnnotation(List<String>)", typename, null } //$NON-NLS-1$ + + }; + setExpectedMessageArgs(args); + setExpectedLineMappings(new LineMapping[] { + new LineMapping(31, pids[0], args[0]), + new LineMapping(34, pids[1], args[1]), + new LineMapping(36, pids[2], args[2]), + new LineMapping(38, pids[3], args[3]), + new LineMapping(40, pids[4], args[4]), + + }); + + deployUsageTest(typename, inc); + } + + /** + * Tests illegal annotation references to method reference (full) + */ + public void testMethodConstructorRefAnno2F() { + x4(false); + } + + /** + * Tests illegal annotation references to method reference (incremental) + */ + public void testMethodConstructorRefAnno2I() { + x4(true); + } + + private void x4(boolean inc) { + int[] pids = new int[] { + + getProblemId(IApiProblem.ILLEGAL_REFERENCE, IApiProblem.METHOD), + getProblemId(IApiProblem.ILLEGAL_REFERENCE, IApiProblem.METHOD), + getProblemId(IApiProblem.ILLEGAL_REFERENCE, IApiProblem.METHOD) }; + setExpectedProblemIds(pids); + String typename = "testMethodReferenceAnnotation2"; //$NON-NLS-1$ + + String[][] args = new String[][] { + { "MRAnnotation", typename, "mrCompare(String, String)" }, //$NON-NLS-1$ //$NON-NLS-2$ + { "MRAnnotation", typename, "mrCompare2(String, String)" }, //$NON-NLS-1$ //$NON-NLS-2$ + { "MRAnnotation", typename, "con(Supplier<T>)" } }; //$NON-NLS-1$ //$NON-NLS-2$ + + setExpectedMessageArgs(args); + setExpectedLineMappings(new LineMapping[] { + new LineMapping(27, pids[0], args[0]), + new LineMapping(29, pids[1], args[1]), + new LineMapping(31, pids[2], args[2]), + + }); + + deployUsageTest(typename, inc); + } + } diff --git a/apitools/org.eclipse.pde.api.tools.tests/test-builder/usage/java8/methodref/testConstructorRefInstantiateAnnotation.java b/apitools/org.eclipse.pde.api.tools.tests/test-builder/usage/java8/methodref/testConstructorRefInstantiateAnnotation.java new file mode 100644 index 0000000000..a0d529cb64 --- /dev/null +++ b/apitools/org.eclipse.pde.api.tools.tests/test-builder/usage/java8/methodref/testConstructorRefInstantiateAnnotation.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) April 15, 2014 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 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + + +package x.y.z; + + +import m.ConstructorReferenceAnno2; +import m.ConstructorReferenceInterface; +import m.ConstructorReferenceInterfaceArg; +import m.ConstructorReferenceInterfaceParamArg; +import java.util.ArrayList; + + + +/** + * Tests illegal use of constructor reference if no instantiate annotation on class + */ +public class testConstructorRefInstantiateAnnotation { + + public void m1(){ + ConstructorReferenceInterface<ConstructorReferenceAnno2> con = ConstructorReferenceAnno2::new; + con.create1().getString(); + ConstructorReferenceInterfaceArg<ConstructorReferenceAnno2,String> conWithArg = ConstructorReferenceAnno2::new; + conWithArg.create2("test").getString(); + ConstructorReferenceInterfaceParamArg<ConstructorReferenceAnno2,String> conParamArg = ConstructorReferenceAnno2::<String>new; + conParamArg.create3(new ArrayList<String>()).getStrings().size(); + } + +} diff --git a/apitools/org.eclipse.pde.api.tools.tests/test-builder/usage/java8/methodref/testMethodReferenceAnnotation.java b/apitools/org.eclipse.pde.api.tools.tests/test-builder/usage/java8/methodref/testMethodReferenceAnnotation.java new file mode 100644 index 0000000000..8f860f734d --- /dev/null +++ b/apitools/org.eclipse.pde.api.tools.tests/test-builder/usage/java8/methodref/testMethodReferenceAnnotation.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * Copyright (c) April 5, 2014 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 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + + +package x.y.z; + +import m.MethodReferenceAnnotation; +import m.MethodReferenceInterface; +import m.ConstructorReferenceAnnotation; +import m.ConstructorReferenceInterface; +import m.ConstructorReferenceInterfaceArg; +import m.ConstructorReferenceInterfaceParamArg; +import java.util.ArrayList; + + + +/** + * Tests illegal use of method accessed by method reference + */ +public class testMethodReferenceAnnotation { + + public void m1(){ + MethodReferenceInterface met = MethodReferenceAnnotation::method1; + met.process(); + MethodReferenceAnnotation m = new MethodReferenceAnnotation(); + met = m::method2; + met.process(); + ConstructorReferenceInterface<ConstructorReferenceAnnotation> con = ConstructorReferenceAnnotation::new; + con.create1().getString(); + ConstructorReferenceInterfaceArg<ConstructorReferenceAnnotation,String> conWithArg = ConstructorReferenceAnnotation::new; + conWithArg.create2("test").getString(); + ConstructorReferenceInterfaceParamArg<ConstructorReferenceAnnotation,String> conParamArg = ConstructorReferenceAnnotation::<String>new; + conParamArg.create3(new ArrayList<String>()).getStrings().size(); + } + +} diff --git a/apitools/org.eclipse.pde.api.tools.tests/test-builder/usage/java8/methodref/testMethodReferenceAnnotation2.java b/apitools/org.eclipse.pde.api.tools.tests/test-builder/usage/java8/methodref/testMethodReferenceAnnotation2.java new file mode 100644 index 0000000000..de211e0985 --- /dev/null +++ b/apitools/org.eclipse.pde.api.tools.tests/test-builder/usage/java8/methodref/testMethodReferenceAnnotation2.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) April 5, 2014 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 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + + + +package x.y.z; + +import m.MRAnnotation; +import java.util.Arrays; +import java.util.HashSet; + +/** + * Tests illegal use of method accessed by method reference + */ + +public class testMethodReferenceAnnotation2 { +public void m1() { + String[] array = {"one"}; + Arrays.sort(array, MRAnnotation::mrCompare); + MRAnnotation mr = new MRAnnotation(); + Arrays.sort(array, mr::mrCompare2); + MRAnnotation mr2 = new MRAnnotation(); + mr2.con(HashSet<String>::new); + } + }
\ No newline at end of file diff --git a/apitools/org.eclipse.pde.api.tools.tests/test-builder/usageprojectsjava8/refprojectjava8/src/m/ConstructorReferenceAnno2.java b/apitools/org.eclipse.pde.api.tools.tests/test-builder/usageprojectsjava8/refprojectjava8/src/m/ConstructorReferenceAnno2.java new file mode 100644 index 0000000000..9ce75e6915 --- /dev/null +++ b/apitools/org.eclipse.pde.api.tools.tests/test-builder/usageprojectsjava8/refprojectjava8/src/m/ConstructorReferenceAnno2.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) April 15, 2014 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 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + +package m; +import java.util.List; +import org.eclipse.pde.api.tools.annotations.NoInstantiate; + +@NoInstantiate +public class ConstructorReferenceAnno2 { + private String str; + + private List<String> strs; + + + public ConstructorReferenceAnno2() { + this.str = "test1"; + } + + public ConstructorReferenceAnno2(String str) { + this.str = str; + } + + public ConstructorReferenceAnno2(List<String> strs) { + this.strs = strs; + } + + public String getString() + { + return str; + } + + public List<String> getStrings() + { + return strs; + } + + +} diff --git a/apitools/org.eclipse.pde.api.tools.tests/test-builder/usageprojectsjava8/refprojectjava8/src/m/ConstructorReferenceAnnotation.java b/apitools/org.eclipse.pde.api.tools.tests/test-builder/usageprojectsjava8/refprojectjava8/src/m/ConstructorReferenceAnnotation.java new file mode 100644 index 0000000000..b258460de5 --- /dev/null +++ b/apitools/org.eclipse.pde.api.tools.tests/test-builder/usageprojectsjava8/refprojectjava8/src/m/ConstructorReferenceAnnotation.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) April 5, 2014 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 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + +package m; +import java.util.List; +import org.eclipse.pde.api.tools.annotations.NoReference; + +public class ConstructorReferenceAnnotation { + private String str; + + private List<String> strs; + + @NoReference + public ConstructorReferenceAnnotation() { + this.str = "test1"; + } + @NoReference + public ConstructorReferenceAnnotation(String str) { + this.str = str; + } + @NoReference + public ConstructorReferenceAnnotation(List<String> strs) { + this.strs = strs; + } + + public String getString() + { + return str; + } + + public List<String> getStrings() + { + return strs; + } + + +} diff --git a/apitools/org.eclipse.pde.api.tools.tests/test-builder/usageprojectsjava8/refprojectjava8/src/m/MRAnnotation.java b/apitools/org.eclipse.pde.api.tools.tests/test-builder/usageprojectsjava8/refprojectjava8/src/m/MRAnnotation.java new file mode 100644 index 0000000000..bdc09263d0 --- /dev/null +++ b/apitools/org.eclipse.pde.api.tools.tests/test-builder/usageprojectsjava8/refprojectjava8/src/m/MRAnnotation.java @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) April 5, 2014 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 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + +package m; + +import java.util.function.Supplier; + +import org.eclipse.pde.api.tools.annotations.NoReference; + +public class MRAnnotation { + + @NoReference + public <T> void con (Supplier<T> supplier) {} + + @NoReference + public int mrCompare2(String str1, String str2) { + return 0; + } + + @NoReference + public static int mrCompare(String str1, String str2) { + return 0; + } + + +} diff --git a/apitools/org.eclipse.pde.api.tools.tests/test-builder/usageprojectsjava8/refprojectjava8/src/m/MethodReferenceAnnotation.java b/apitools/org.eclipse.pde.api.tools.tests/test-builder/usageprojectsjava8/refprojectjava8/src/m/MethodReferenceAnnotation.java new file mode 100644 index 0000000000..2843212d48 --- /dev/null +++ b/apitools/org.eclipse.pde.api.tools.tests/test-builder/usageprojectsjava8/refprojectjava8/src/m/MethodReferenceAnnotation.java @@ -0,0 +1,29 @@ + +/******************************************************************************* + * Copyright (c) 2014 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 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package m; + +import org.eclipse.pde.api.tools.annotations.NoReference; + +public class MethodReferenceAnnotation { + + @NoReference + public static void method1() { + return ; + } + + @NoReference + public void method2() { + return ; + } + + +}
\ No newline at end of file |