Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Herrmann2018-02-09 22:36:47 +0000
committerStephan Herrmann2018-02-10 15:24:44 +0000
commitd2152487a0d4527ec9f6b272501afec3598abc00 (patch)
tree11b6a9895f1922649f1ec90122a4c7f079bbc5a6
parent2336dbd29509e7557735693482262b233d3fb1bd (diff)
downloadorg.eclipse.objectteams-d2152487a0d4527ec9f6b272501afec3598abc00.tar.gz
org.eclipse.objectteams-d2152487a0d4527ec9f6b272501afec3598abc00.tar.xz
org.eclipse.objectteams-d2152487a0d4527ec9f6b272501afec3598abc00.zip
Backport Bug 530931 - callin replace with propagation of type parameters
cannot resolve type argument use cherry-pick of commit 0c175b2ec21e308f3266db2eafd56245b31a8f14
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java8
-rw-r--r--testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/other/Java5.java111
2 files changed, 119 insertions, 0 deletions
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java
index 75cf9f46b..0676e676b 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java
@@ -7642,6 +7642,7 @@ private void consumePredicate(boolean isBase) {
int kind = GuardPredicateDeclaration.UNKNOWN_PREDICATE;
ASTNode parentDecl = null;
boolean typeIsRole = false;
+ TypeParameter[] typeParamters = null;
if (this.astStack[this.astPtr] instanceof TypeDeclaration) {
typeDecl = (TypeDeclaration) this.astStack[this.astPtr];
@@ -7665,6 +7666,9 @@ private void consumePredicate(boolean isBase) {
else
arguments = makePredicateArguments(
null, MethodSignatureEnhancer.maybeRetrenchArguments(methodDecl, this.options.weavingScheme), null, poss);
+
+ if (methodDecl.typeParameters != null)
+ typeParamters = AstClone.copyTypeParameters(methodDecl.typeParameters);
} else if (this.astStack[this.astPtr] instanceof MethodSpec) {
bmSpec = (MethodSpec)this.astStack[this.astPtr];
mappingDecl = (CallinMappingDeclaration)this.astStack[this.astPtr-this.astLengthStack[this.astLengthPtr]];
@@ -7688,6 +7692,9 @@ private void consumePredicate(boolean isBase) {
else
arguments = makePredicateArguments(
null, mappingDecl.roleMethodSpec.arguments, resultType, poss);
+
+ if (mappingDecl.roleMethodSpec.typeParameters != null)
+ typeParamters = AstClone.copyTypeParameters(mappingDecl.roleMethodSpec.typeParameters);
}
typeIsRole |= (typeDecl != null && typeDecl.isRole());
@@ -7699,6 +7706,7 @@ private void consumePredicate(boolean isBase) {
predicateMethod.sourceStart = start; // make 'when' act as the method's selector.
predicateMethod.arguments = arguments;
+ predicateMethod.typeParameters = typeParamters;
switch (kind) {
case GuardPredicateDeclaration.TYPE_PREDICATE:
diff --git a/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/other/Java5.java b/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/other/Java5.java
index 921748998..6a1de0510 100644
--- a/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/other/Java5.java
+++ b/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/other/Java5.java
@@ -393,6 +393,117 @@ public class Java5 extends AbstractOTJLDTest {
"cannot be resolved");
}
+ // a base has a parameterized method, type variable used as type argument - which is bound via callin
+ public void testA11_genericFeatureInBase3cih() {
+
+ runConformTest(
+ new String[] {
+ "TeamA11gfib3ci.java",
+ "\n" +
+ "public team class TeamA11gfib3ci {\n" +
+ " protected class R playedBy TA11gfib3ci {\n" +
+ " <T> T getIt(Object it, Class<T> c) <- replace T getIt(Object it, Class<T> c)\n" +
+ " base when (c.isInstance(it));" +
+ " callin <T> T getIt(Object it, Class<T> c) {\n" +
+ " System.out.print(\">>\");\n" +
+ " return base.getIt(it, c);\n" +
+ " }\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " new TeamA11gfib3ci().activate();\n" +
+ " System.out.print(new TA11gfib3ci().getIt(\"OK\", String.class));\n" +
+ " }\n" +
+ "}\n" +
+ " \n",
+ "TA11gfib3ci.java",
+ "\n" +
+ "public class TA11gfib3ci {\n" +
+ " <T> T getIt(Object it, Class<T> c) { return c.cast(it); }\n" +
+ "}\n" +
+ " \n"
+ },
+ ">>OK");
+ }
+
+ // a base has a parameterized method, base's type parameter omitted - which is bound via callin
+ public void testA11_genericFeatureInBase3cii() {
+
+ runNegativeTest(
+ new String[] {
+ "TeamA11gfib3ci.java",
+ "\n" +
+ "public team class TeamA11gfib3ci {\n" +
+ " protected class R playedBy TA11gfib3ci {\n" +
+ " <T> T getIt(Object it, Class<T> c) <- replace T getIt(Object it, Class c)\n" +
+ " base when (c.isInstance(it));" +
+ " callin <T> T getIt(Object it, Class<T> c) {\n" +
+ " System.out.print(\">>\");\n" +
+ " return base.getIt(it, c);\n" +
+ " }\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " new TeamA11gfib3ci().activate();\n" +
+ " System.out.print(new TA11gfib3ci().getIt(\"OK\", String.class));\n" +
+ " }\n" +
+ "}\n" +
+ " \n",
+ "TA11gfib3ci.java",
+ "\n" +
+ "public class TA11gfib3ci {\n" +
+ " <T> T getIt(Object it, Class<T> c) { return c.cast(it); }\n" +
+ "}\n" +
+ " \n"
+ },
+ "----------\n" +
+ "1. WARNING in TeamA11gfib3ci.java (at line 4)\n" +
+ " <T> T getIt(Object it, Class<T> c) <- replace T getIt(Object it, Class c)\n" +
+ " ^^^^^\n" +
+ "Class is a raw type. References to generic type Class<T> should be parameterized\n" +
+ "----------\n" +
+ "2. ERROR in TeamA11gfib3ci.java (at line 4)\n" +
+ " <T> T getIt(Object it, Class<T> c) <- replace T getIt(Object it, Class c)\n" +
+ " ^^^^^\n" +
+ "Method specifier finds no direct match, argument of closest match is Class<Object> instead of Class (OTJLD 4.1(c)).\n" +
+ "----------\n");
+ }
+
+ // a base has a parameterized method, base's type parameter erased to Object - which is bound via callin
+ public void testA11_genericFeatureInBase3cij() {
+
+ runNegativeTest(
+ new String[] {
+ "TeamA11gfib3ci.java",
+ "\n" +
+ "public team class TeamA11gfib3ci {\n" +
+ " protected class R playedBy TA11gfib3ci {\n" +
+ " <T> T getIt(Object it, Class<T> c) <- replace T getIt(Object it, Class<Object> c)\n" +
+ " base when (c.isInstance(it));" +
+ " callin <T> T getIt(Object it, Class<T> c) {\n" +
+ " System.out.print(\">>\");\n" +
+ " return base.getIt(it, c);\n" +
+ " }\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " new TeamA11gfib3ci().activate();\n" +
+ " System.out.print(new TA11gfib3ci().getIt(\"OK\", String.class));\n" +
+ " }\n" +
+ "}\n" +
+ " \n",
+ "TA11gfib3ci.java",
+ "\n" +
+ "public class TA11gfib3ci {\n" +
+ " <T> T getIt(Object it, Class<T> c) { return c.cast(it); }\n" +
+ "}\n" +
+ " \n"
+ },
+ "----------\n" +
+ "1. ERROR in TeamA11gfib3ci.java (at line 4)\n" +
+ " <T> T getIt(Object it, Class<T> c) <- replace T getIt(Object it, Class<Object> c)\n" +
+ " ^\n" +
+ "When mapping the 2. argument of getIt(Object, Class): cannot convert from java.lang.Class<java.lang.Object> to java.lang.Class<T> (OTJLD 4.5(d)).\n" +
+ "----------\n");
+ }
+
// a base has a parameterized method which is bound via callout
// A.1.1-otjld-generic-feature-in-base-4
public void testA11_genericFeatureInBase4() {

Back to the top