Skip to content

Commit

Permalink
Fix for #971: off-by-one error in GroovyCompilationUnitDeclaration
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Oct 17, 2019
1 parent b32e09a commit f49cec6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,36 @@ public void testBigDecimalLiteralAttributeValue() {
"----------\n");
}

@Test
public void testBooleanLiteralAttributeValue() {
//@formatter:off
String[] sources = {
"Main.groovy",
"@SuppressWarnings(value=\"nls\", unknown=false)\n" +
"class Main {\n" +
"}",
};
//@formatter:on

runNegativeTest(sources,
"----------\n" +
"1. ERROR in Main.groovy (at line 1)\n" +
"\t@SuppressWarnings(value=\"nls\", unknown=false)\n" +
"\t^^^^^^^^^^^^^^^^^\n" +
"Groovy:'unknown'is not part of the annotation SuppressWarnings in @java.lang.SuppressWarnings\n" +
"----------\n" +
"2. ERROR in Main.groovy (at line 1)\n" +
"\t@SuppressWarnings(value=\"nls\", unknown=false)\n" +
"\t ^^^^^^^^^^^^^\n" +
"The attribute unknown is undefined for the annotation type SuppressWarnings\n" +
"----------\n" +
"3. ERROR in Main.groovy (at line 1)\n" +
"\t@SuppressWarnings(value=\"nls\", unknown=false)\n" +
"\t ^^^^^\n" +
"Groovy:Unexpected type java.lang.Object in @java.lang.SuppressWarnings\n" +
"----------\n");
}

@Test
public void testClassLiteralAttributeValue1() {
//@formatter:off
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1667,7 +1667,7 @@ private org.eclipse.jdt.internal.compiler.ast.MemberValuePair[] createAnnotation
return memberValuePairs.entrySet().stream().map(memberValuePair -> {
char[] name = memberValuePair.getKey().toCharArray();
// TODO: What to do when the value expression lacks source position information?
int start = Math.max(0, memberValuePair.getValue().getStart() - name.length - 1), until = memberValuePair.getValue().getEnd();
int start = Math.max(0, memberValuePair.getValue().getStart() - name.length - 1), until = memberValuePair.getValue().getEnd() - 1;
org.eclipse.jdt.internal.compiler.ast.Expression value = createAnnotationMemberExpression(memberValuePair.getValue(), null);
return new org.eclipse.jdt.internal.compiler.ast.MemberValuePair(name, start, until, value);
}).toArray(org.eclipse.jdt.internal.compiler.ast.MemberValuePair[]::new);
Expand Down

0 comments on commit f49cec6

Please sign in to comment.