Skip to content

Commit 89341d0

Browse files
committed
GROOVY-9893
1 parent 3602002 commit 89341d0

File tree

4 files changed

+105
-0
lines changed

4 files changed

+105
-0
lines changed

base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/StaticCompilationTests.java

+45
Original file line numberDiff line numberDiff line change
@@ -5557,4 +5557,49 @@ public void testCompileStatic9892() {
55575557

55585558
runConformTest(sources, "X1Y0");
55595559
}
5560+
5561+
@Test
5562+
public void testCompileStatic9893() {
5563+
//@formatter:off
5564+
String[] sources = {
5565+
"Main.groovy",
5566+
"abstract class A {\n" +
5567+
" void setX(String s) { print 'String' }\n" +
5568+
"}\n" +
5569+
"class C extends A {\n" +
5570+
" void setX(boolean b) { print 'boolean' }\n" +
5571+
"}\n" +
5572+
"@groovy.transform.CompileStatic\n" +
5573+
"void test() {\n" +
5574+
" def c = new C()\n" +
5575+
" c.x = 'value'\n" +
5576+
"}\n" +
5577+
"test()\n",
5578+
};
5579+
//@formatter:on
5580+
5581+
runConformTest(sources, "String");
5582+
}
5583+
5584+
@Test
5585+
public void testCompileStatic9893a() {
5586+
//@formatter:off
5587+
String[] sources = {
5588+
"Main.groovy",
5589+
"interface I {\n" +
5590+
" void setX(String s)\n" +
5591+
"}\n" +
5592+
"abstract class A implements I {\n" +
5593+
" void setX(boolean b) { print 'boolean' }\n" +
5594+
"}\n" +
5595+
"@groovy.transform.CompileStatic\n" +
5596+
"void test(A a) {\n" +
5597+
" a.x = 'value'\n" +
5598+
"}\n" +
5599+
"test(new A() { void setX(String s) { print 'String' } })\n",
5600+
};
5601+
//@formatter:on
5602+
5603+
runConformTest(sources, "String");
5604+
}
55605605
}

base/org.codehaus.groovy25/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java

+20
Original file line numberDiff line numberDiff line change
@@ -2351,6 +2351,7 @@ public static boolean isClassClassNodeWrappingConcreteType(ClassNode classNode)
23512351
}
23522352

23532353
public static List<MethodNode> findSetters(ClassNode cn, String setterName, boolean voidOnly) {
2354+
/* GRECLIPSE edit -- GROOVY-9893
23542355
List<MethodNode> result = null;
23552356
for (MethodNode method : cn.getDeclaredMethods(setterName)) {
23562357
if (setterName.equals(method.getName())
@@ -2369,9 +2370,28 @@ public static List<MethodNode> findSetters(ClassNode cn, String setterName, bool
23692370
}
23702371
return Collections.emptyList();
23712372
}
2373+
*/
2374+
List<MethodNode> result = new ArrayList<>();
2375+
if (!cn.isInterface()) {
2376+
for (MethodNode method : cn.getMethods(setterName)) {
2377+
if (isSetter(method, voidOnly)) result.add(method);
2378+
}
2379+
}
2380+
for (ClassNode in : cn.getAllInterfaces()) {
2381+
for (MethodNode method : in.getDeclaredMethods(setterName)) {
2382+
if (isSetter(method, voidOnly)) result.add(method);
2383+
}
2384+
}
2385+
// GRECLIPSE end
23722386
return result;
23732387
}
23742388

2389+
// GRECLIPSE add
2390+
private static boolean isSetter(final MethodNode mn, final boolean voidOnly) {
2391+
return (!voidOnly || mn.isVoidMethod()) && mn.getParameters().length == 1;
2392+
}
2393+
// GRECLIPSE end
2394+
23752395
public static ClassNode isTraitSelf(VariableExpression vexp) {
23762396
if (Traits.THIS_OBJECT.equals(vexp.getName())) {
23772397
Variable accessedVariable = vexp.getAccessedVariable();

base/org.codehaus.groovy30/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java

+20
Original file line numberDiff line numberDiff line change
@@ -2215,6 +2215,7 @@ public static boolean isClassClassNodeWrappingConcreteType(final ClassNode class
22152215
}
22162216

22172217
public static List<MethodNode> findSetters(final ClassNode cn, final String setterName, final boolean voidOnly) {
2218+
/* GRECLIPSE edit -- GROOVY-9893
22182219
List<MethodNode> result = null;
22192220
for (MethodNode method : cn.getDeclaredMethods(setterName)) {
22202221
if (setterName.equals(method.getName())
@@ -2233,9 +2234,28 @@ public static List<MethodNode> findSetters(final ClassNode cn, final String sett
22332234
}
22342235
return Collections.emptyList();
22352236
}
2237+
*/
2238+
List<MethodNode> result = new ArrayList<>();
2239+
if (!cn.isInterface()) {
2240+
for (MethodNode method : cn.getMethods(setterName)) {
2241+
if (isSetter(method, voidOnly)) result.add(method);
2242+
}
2243+
}
2244+
for (ClassNode in : cn.getAllInterfaces()) {
2245+
for (MethodNode method : in.getDeclaredMethods(setterName)) {
2246+
if (isSetter(method, voidOnly)) result.add(method);
2247+
}
2248+
}
2249+
// GRECLIPSE end
22362250
return result;
22372251
}
22382252

2253+
// GRECLIPSE add
2254+
private static boolean isSetter(final MethodNode mn, final boolean voidOnly) {
2255+
return (!voidOnly || mn.isVoidMethod()) && mn.getParameters().length == 1;
2256+
}
2257+
// GRECLIPSE end
2258+
22392259
public static ClassNode isTraitSelf(final VariableExpression vexp) {
22402260
if (Traits.THIS_OBJECT.equals(vexp.getName())) {
22412261
Variable accessedVariable = vexp.getAccessedVariable();

base/org.codehaus.groovy40/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingSupport.java

+20
Original file line numberDiff line numberDiff line change
@@ -2210,6 +2210,7 @@ public static boolean isClassClassNodeWrappingConcreteType(final ClassNode class
22102210
}
22112211

22122212
public static List<MethodNode> findSetters(final ClassNode cn, final String setterName, final boolean voidOnly) {
2213+
/* GRECLIPSE edit -- GROOVY-9893
22132214
List<MethodNode> result = null;
22142215
for (MethodNode method : cn.getDeclaredMethods(setterName)) {
22152216
if (setterName.equals(method.getName())
@@ -2228,9 +2229,28 @@ public static List<MethodNode> findSetters(final ClassNode cn, final String sett
22282229
}
22292230
return Collections.emptyList();
22302231
}
2232+
*/
2233+
List<MethodNode> result = new ArrayList<>();
2234+
if (!cn.isInterface()) {
2235+
for (MethodNode method : cn.getMethods(setterName)) {
2236+
if (isSetter(method, voidOnly)) result.add(method);
2237+
}
2238+
}
2239+
for (ClassNode in : cn.getAllInterfaces()) {
2240+
for (MethodNode method : in.getDeclaredMethods(setterName)) {
2241+
if (isSetter(method, voidOnly)) result.add(method);
2242+
}
2243+
}
2244+
// GRECLIPSE end
22312245
return result;
22322246
}
22332247

2248+
// GRECLIPSE add
2249+
private static boolean isSetter(final MethodNode mn, final boolean voidOnly) {
2250+
return (!voidOnly || mn.isVoidMethod()) && mn.getParameters().length == 1;
2251+
}
2252+
// GRECLIPSE end
2253+
22342254
public static ClassNode isTraitSelf(final VariableExpression vexp) {
22352255
if (Traits.THIS_OBJECT.equals(vexp.getName())) {
22362256
Variable accessedVariable = vexp.getAccessedVariable();

0 commit comments

Comments
 (0)