Skip to content

Commit

Permalink
Fix for #957: check for new collector serialize class (Groovy 2.5.3+)
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Sep 20, 2019
1 parent ed6895f commit ea55d68
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package org.eclipse.jdt.groovy.core.tests.xform;

import static org.eclipse.jdt.groovy.core.tests.GroovyBundle.isAtLeastGroovy;

import java.util.Map;

import org.eclipse.jdt.groovy.core.tests.basic.GroovyCompilerTestSuite;
Expand Down Expand Up @@ -124,4 +126,64 @@ public void testCanonical4() {

runConformTest(sources, "Foo(one, two)", options);
}

@Test // https://github.com/groovy/groovy-eclipse/issues/957
public void testCanonical5() {
//@formatter:off
String[] sources = {
"Main.groovy",
"class Main {\n" +
" static void main(args) {\n" +
" print(new Foo('bar'))\n" +
" }\n" +
"}\n",

"Foo.groovy",
"@groovy.transform.Canonical(excludes='baz')\n" +
"class Foo {\n" +
" String bar, baz\n" +
"}\n",
};
//@formatter:on

runConformTest(sources, "Foo(bar)");
}

@Test
public void testCanonical6() {
//@formatter:off
String[] sources = {
"Foo.groovy",
"@groovy.transform.Canonical(doesNotExist=null)\n" +
"class Foo {\n" +
" String bar, baz\n" +
"}\n",
};
//@formatter:on

runNegativeTest(sources,
"----------\n" +
"1. ERROR in Foo.groovy (at line 1)\n" +
(isAtLeastGroovy(25)
?
"\t@groovy.transform.Canonical(doesNotExist=null)\n" +
"\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
"Groovy:Annotation collector got unmapped names [doesNotExist]. @ line 1, column 1.\n"
:
"\t@groovy.transform.Canonical(doesNotExist=null)\n" +
"\t^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
"Groovy:'doesNotExist'is not part of the annotation Canonical in @groovy.transform.Canonical\n" +
"----------\n" +
"2. ERROR in Foo.groovy (at line 1)\n" +
"\t@groovy.transform.Canonical(doesNotExist=null)\n" +
"\t ^^^^^^^^^^^^^^^^^^\n" +
"The attribute doesNotExist is undefined for the annotation type Canonical\n" +
"----------\n" +
"3. ERROR in Foo.groovy (at line 1)\n" +
"\t@groovy.transform.Canonical(doesNotExist=null)\n" +
"\t ^^^^\n" +
"Groovy:Unexpected type java.lang.Object in @groovy.transform.Canonical\n"
) +
"----------\n");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1283,7 +1283,7 @@ static AnnotationTargetAllowed isAnnotationTargetAllowed(Annotation annotation,
}

static void checkAnnotationTarget(Annotation annotation, BlockScope scope, ReferenceBinding annotationType, int kind, Binding recipient, long tagBitsToRevert) {
// GROOVY start
// GROOVY add
if (!scope.compilationUnitScope().checkTargetCompatibility()) {
return;
}
Expand Down Expand Up @@ -1428,11 +1428,12 @@ private boolean isFakeGroovyAnnotation(TypeBinding tb) {
* Try to eliminate things we don't care about from being 'special groovy handled'.
*/
private static boolean isInterestingGroovyType(ReferenceBinding rtb) {
if (rtb instanceof SourceTypeBinding) return true; // TODO: Find better check
FieldBinding f = rtb.getField(SPECIAL_GROOVY_FIELD_NAME, /*needResolve:*/ false);
return (f != null);
return (!rtb.isBinaryBinding() || // TODO: stricter check for source bindings
rtb.getField(SPECIAL_GROOVY_FIELD_NAME, /*needResolve:*/ false) != null ||
rtb.getPackage().knownTypes.containsKey(CharOperation.concat(rtb.sourceName(), COLLECTOR_HELPER_NAME)));
}

private static final char[] COLLECTOR_HELPER_NAME = "$CollectorHelper".toCharArray(); //$NON-NLS-1$
private static final char[] SPECIAL_GROOVY_FIELD_NAME = "$staticClassInfo".toCharArray(); //$NON-NLS-1$
// GROOVY end
}
Original file line number Diff line number Diff line change
Expand Up @@ -1283,7 +1283,7 @@ static AnnotationTargetAllowed isAnnotationTargetAllowed(Annotation annotation,
}

static void checkAnnotationTarget(Annotation annotation, BlockScope scope, ReferenceBinding annotationType, int kind, Binding recipient, long tagBitsToRevert) {
// GROOVY start
// GROOVY add
if (!scope.compilationUnitScope().checkTargetCompatibility()) {
return;
}
Expand Down Expand Up @@ -1428,11 +1428,12 @@ private boolean isFakeGroovyAnnotation(TypeBinding tb) {
* Try to eliminate things we don't care about from being 'special groovy handled'.
*/
private static boolean isInterestingGroovyType(ReferenceBinding rtb) {
if (rtb instanceof SourceTypeBinding) return true; // TODO: Find better check
FieldBinding f = rtb.getField(SPECIAL_GROOVY_FIELD_NAME, /*needResolve:*/ false);
return (f != null);
return (!rtb.isBinaryBinding() || // TODO: stricter check for source bindings
rtb.getField(SPECIAL_GROOVY_FIELD_NAME, /*needResolve:*/ false) != null ||
rtb.getPackage().knownTypes.containsKey(CharOperation.concat(rtb.sourceName(), COLLECTOR_HELPER_NAME)));
}

private static final char[] COLLECTOR_HELPER_NAME = "$CollectorHelper".toCharArray(); //$NON-NLS-1$
private static final char[] SPECIAL_GROOVY_FIELD_NAME = "$staticClassInfo".toCharArray(); //$NON-NLS-1$
// GROOVY end
}
Original file line number Diff line number Diff line change
Expand Up @@ -1283,7 +1283,7 @@ static AnnotationTargetAllowed isAnnotationTargetAllowed(Annotation annotation,
}

static void checkAnnotationTarget(Annotation annotation, BlockScope scope, ReferenceBinding annotationType, int kind, Binding recipient, long tagBitsToRevert) {
// GROOVY start
// GROOVY add
if (!scope.compilationUnitScope().checkTargetCompatibility()) {
return;
}
Expand Down Expand Up @@ -1428,11 +1428,12 @@ private boolean isFakeGroovyAnnotation(TypeBinding tb) {
* Try to eliminate things we don't care about from being 'special groovy handled'.
*/
private static boolean isInterestingGroovyType(ReferenceBinding rtb) {
if (rtb instanceof SourceTypeBinding) return true; // TODO: Find better check
FieldBinding f = rtb.getField(SPECIAL_GROOVY_FIELD_NAME, /*needResolve:*/ false);
return (f != null);
return (!rtb.isBinaryBinding() || // TODO: stricter check for source bindings
rtb.getField(SPECIAL_GROOVY_FIELD_NAME, /*needResolve:*/ false) != null ||
rtb.getPackage().knownTypes.containsKey(CharOperation.concat(rtb.sourceName(), COLLECTOR_HELPER_NAME)));
}

private static final char[] COLLECTOR_HELPER_NAME = "$CollectorHelper".toCharArray(); //$NON-NLS-1$
private static final char[] SPECIAL_GROOVY_FIELD_NAME = "$staticClassInfo".toCharArray(); //$NON-NLS-1$
// GROOVY end
}
Original file line number Diff line number Diff line change
Expand Up @@ -1428,11 +1428,12 @@ private boolean isFakeGroovyAnnotation(TypeBinding tb) {
* Try to eliminate things we don't care about from being 'special groovy handled'.
*/
private static boolean isInterestingGroovyType(ReferenceBinding rtb) {
if (rtb instanceof SourceTypeBinding) return true; // TODO: Find better check
FieldBinding f = rtb.getField(SPECIAL_GROOVY_FIELD_NAME, /*needResolve:*/ false);
return (f != null);
return (!rtb.isBinaryBinding() || // TODO: stricter check for source bindings
rtb.getField(SPECIAL_GROOVY_FIELD_NAME, /*needResolve:*/ false) != null ||
rtb.getPackage().knownTypes.containsKey(CharOperation.concat(rtb.sourceName(), COLLECTOR_HELPER_NAME)));
}

private static final char[] COLLECTOR_HELPER_NAME = "$CollectorHelper".toCharArray(); //$NON-NLS-1$
private static final char[] SPECIAL_GROOVY_FIELD_NAME = "$staticClassInfo".toCharArray(); //$NON-NLS-1$
// GROOVY end
}
Original file line number Diff line number Diff line change
Expand Up @@ -1280,7 +1280,7 @@ static AnnotationTargetAllowed isAnnotationTargetAllowed(Annotation annotation,
}

static void checkAnnotationTarget(Annotation annotation, BlockScope scope, ReferenceBinding annotationType, int kind, Binding recipient, long tagBitsToRevert) {
// GROOVY start
// GROOVY add
if (!scope.compilationUnitScope().checkTargetCompatibility()) {
return;
}
Expand Down Expand Up @@ -1425,11 +1425,12 @@ private boolean isFakeGroovyAnnotation(TypeBinding tb) {
* Try to eliminate things we don't care about from being 'special groovy handled'.
*/
private static boolean isInterestingGroovyType(ReferenceBinding rtb) {
if (rtb instanceof SourceTypeBinding) return true; // TODO: Find better check
FieldBinding f = rtb.getField(SPECIAL_GROOVY_FIELD_NAME, /*needResolve:*/ false);
return (f != null);
return (!rtb.isBinaryBinding() || // TODO: stricter check for source bindings
rtb.getField(SPECIAL_GROOVY_FIELD_NAME, /*needResolve:*/ false) != null ||
rtb.getPackage().knownTypes.containsKey(CharOperation.concat(rtb.sourceName(), COLLECTOR_HELPER_NAME)));
}

private static final char[] COLLECTOR_HELPER_NAME = "$CollectorHelper".toCharArray(); //$NON-NLS-1$
private static final char[] SPECIAL_GROOVY_FIELD_NAME = "$staticClassInfo".toCharArray(); //$NON-NLS-1$
// GROOVY end
}
Original file line number Diff line number Diff line change
Expand Up @@ -1283,7 +1283,7 @@ static AnnotationTargetAllowed isAnnotationTargetAllowed(Annotation annotation,
}

static void checkAnnotationTarget(Annotation annotation, BlockScope scope, ReferenceBinding annotationType, int kind, Binding recipient, long tagBitsToRevert) {
// GROOVY start
// GROOVY add
if (!scope.compilationUnitScope().checkTargetCompatibility()) {
return;
}
Expand Down Expand Up @@ -1428,11 +1428,12 @@ private boolean isFakeGroovyAnnotation(TypeBinding tb) {
* Try to eliminate things we don't care about from being 'special groovy handled'.
*/
private static boolean isInterestingGroovyType(ReferenceBinding rtb) {
if (rtb instanceof SourceTypeBinding) return true; // TODO: Find better check
FieldBinding f = rtb.getField(SPECIAL_GROOVY_FIELD_NAME, /*needResolve:*/ false);
return (f != null);
return (!rtb.isBinaryBinding() || // TODO: stricter check for source bindings
rtb.getField(SPECIAL_GROOVY_FIELD_NAME, /*needResolve:*/ false) != null ||
rtb.getPackage().knownTypes.containsKey(CharOperation.concat(rtb.sourceName(), COLLECTOR_HELPER_NAME)));
}

private static final char[] COLLECTOR_HELPER_NAME = "$CollectorHelper".toCharArray(); //$NON-NLS-1$
private static final char[] SPECIAL_GROOVY_FIELD_NAME = "$staticClassInfo".toCharArray(); //$NON-NLS-1$
// GROOVY end
}

0 comments on commit ea55d68

Please sign in to comment.