Skip to content

Commit

Permalink
GROOVY-10249
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Sep 29, 2021
1 parent 8328da8 commit c51f96d
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2979,10 +2979,37 @@ public void testTraitBasics2() throws Exception {
expectingCompiledClasses("C", "T", "T$Trait$FieldHelper", "T$Trait$Helper", "T$Trait$StaticFieldHelper");
}

@Test // https://github.com/groovy/groovy-eclipse/issues/1267
@Test // GROOVY-10249
public void testTraitBasics3() throws Exception {
IPath[] paths = createSimpleProject("Project", true);

//@formatter:off
env.addGroovyClass(paths[1], "C",
"class C implements T {\n" +
" static main(args) {\n" +
" setP()\n" +
" print p\n" +
" setP(1)\n" +
" print p\n" +
" setP(1,2)\n" +
" print p\n" +
" }\n" +
"}\n");
env.addGroovyClass(paths[1], "T",
"trait T {\n" +
" static Number[] p\n" +
"}\n");
//@formatter:on

fullBuild(paths[0]);
expectingNoProblems();
executeClass(paths[0], "C", "[][1][1, 2]", "");
}

@Test // https://github.com/groovy/groovy-eclipse/issues/1267
public void testTraitBasics4() throws Exception {
IPath[] paths = createSimpleProject("Project", true);

//@formatter:off
env.addGroovyClass(paths[1], "p", "C",
"package p\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,26 @@ public void testProperty19() {
assertExprType(source, "setNumber", "java.lang.Void");
}

@Test
public void testProperty20() {
createUnit("T",
"trait T {\n" +
" Number[] numbers\n" +
"}\n");

//@formatter:off
String source =
"class C implements T {\n" +
" void meth() {\n" +
" def arr = numbers\n" +
" }\n" +
"}\n";
//@formatter:on

assertDeclType(source, "numbers", "T");
assertExprType(source, "numbers", "java.lang.Number[]");
}

//

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,8 @@ private Optional<MethodBinding> createSetterMethod(final PropertyNode propertyNo
TypeBinding[] parameterTypes = {Scope.getBaseType(propertyNode.getType().getName().toCharArray())};
return asGenerated(new MethodBinding(modifiers, nameChars, TypeBinding.VOID, parameterTypes, Binding.NO_EXCEPTIONS, referenceContext.binding));
}
return asGenerated(new LazilyResolvedMethodBinding(false, propertyNode.getName(), modifiers, nameChars, Binding.NO_EXCEPTIONS, referenceContext.binding));
int va = (propertyNode.getType().isArray() ? Flags.AccVarargs : 0); // GROOVY-10249: see AsmClassGenerator#visitConstructorOrMethod
return asGenerated(new LazilyResolvedMethodBinding(false, propertyNode.getName(), modifiers | va, nameChars, Binding.NO_EXCEPTIONS, referenceContext.binding));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public class JDTResolver extends ResolveVisitor {
commonTypes.put("java.lang.Short", ClassHelper.Short_TYPE);
commonTypes.put("java.lang.Void", ClassHelper.void_WRAPPER_TYPE);

commonTypes.put("java.lang.Number", ClassHelper.Number_TYPE);
commonTypes.put("java.lang.Object", ClassHelper.OBJECT_TYPE);
commonTypes.put("java.lang.String", ClassHelper.STRING_TYPE);

Expand Down Expand Up @@ -269,7 +270,20 @@ public ClassNode resolve(String name) {
}
}

int i = name.indexOf('<');
int i = 0;
while (name.charAt(i) == '[') {
i += 1;
}
if (i > 0) { // resolve "name" from "[[Lname;" then make dims
name = name.substring(i + 1, name.length() - 1);
ClassNode type = resolve(name);
for (; i > 0; i -= 1) {
type = type.makeArray();
}
return type;
}

i = name.indexOf('<');
if (i > 0) {
name = name.substring(0, i);
}
Expand Down

0 comments on commit c51f96d

Please sign in to comment.