Skip to content

Commit 6d80c05

Browse files
committed
GROOVY-9206
1 parent 8083e5d commit 6d80c05

File tree

5 files changed

+24
-25
lines changed

5 files changed

+24
-25
lines changed

base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/basic/AnnotationsTests.java

+6-11
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ public void testCharLiteralAttributeValue() {
697697

698698
"Main.groovy",
699699
"class Main {\n" +
700-
" @Separator((char)';')\n" +
700+
" @Separator(';')\n" +
701701
" String tokens\n" +
702702
"}\n",
703703
};
@@ -709,14 +709,9 @@ public void testCharLiteralAttributeValue() {
709709
runNegativeTest(sources,
710710
"----------\n" +
711711
"1. ERROR in Main.groovy (at line 2)\n" +
712-
"\t@Separator((char)';')\n" +
713-
"\t ^^^^^^^^^\n" +
714-
"Groovy:Expected '(char) ;' to be an inline constant of type char in @Separator\n" +
715-
"----------\n" +
716-
"2. ERROR in Main.groovy (at line 2)\n" +
717-
"\t@Separator((char)';')\n" +
718-
"\t ^^^^^^^^^\n" +
719-
"Groovy:Attribute 'value' should have type 'java.lang.Character'; but found type 'java.lang.Object' in @Separator\n" +
712+
"\t@Separator(';')\n" +
713+
"\t ^^^\n" +
714+
"Groovy:Attribute 'value' should have type 'java.lang.Character'; but found type 'java.lang.String' in @Separator\n" +
720715
"----------\n");
721716
}
722717
}
@@ -2636,7 +2631,7 @@ public void testAnnotationsTargetType13() {
26362631
"p/Main.groovy",
26372632
"package p;\n" +
26382633
"public class Main {\n" +
2639-
" void m(@Anno('x') String s) {}\n" +
2634+
" void m(@Anno(\"x\") String s) {}\n" +
26402635
" static main(args) {\n" +
26412636
" print getMethod('m', String).annotatedParameterTypes[0].annotations[0].value()\n" +
26422637
" }\n" +
@@ -2657,7 +2652,7 @@ public void testAnnotationsTargetType13() {
26572652
runNegativeTest(sources,
26582653
"----------\n" +
26592654
"1. ERROR in p\\Main.groovy (at line 3)\n" +
2660-
"\tvoid m(@Anno('x') String s) {}\n" +
2655+
"\tvoid m(@Anno(\"x\") String s) {}\n" +
26612656
"\t ^^^^^\n" +
26622657
"Groovy:Annotation @p.Anno is not allowed on element PARAMETER\n" +
26632658
"----------\n");

base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/basic/ErrorRecoveryTests.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ public void testParsingRecovery_IncompleteAnnotation10() {
372372
//@formatter:off
373373
String[] sources = {
374374
"X.groovy",
375-
"@A(foo='1',)\n" +
375+
"@A(foo=\"1\",)\n" +
376376
"class X {\n" +
377377
"}\n",
378378

@@ -387,7 +387,7 @@ public void testParsingRecovery_IncompleteAnnotation10() {
387387
runNegativeTest(sources,
388388
"----------\n" +
389389
"1. ERROR in X.groovy (at line 1)\n" +
390-
"\t@A(foo='1',)\n" +
390+
"\t@A(foo=\"1\",)\n" +
391391
"\t^^\n" +
392392
"Groovy:No explicit/default value found for annotation attribute 'bar' in @A\n" +
393393
"----------\n");
@@ -404,7 +404,7 @@ public void testParsingRecovery_IncompleteAnnotation11() {
404404
//@formatter:off
405405
String[] sources = {
406406
"X.groovy",
407-
"@A(foo=['1','2'],)\n" +
407+
"@A(foo=[\"1\",\"2\"],)\n" +
408408
"class X {\n" +
409409
"}\n",
410410

@@ -419,7 +419,7 @@ public void testParsingRecovery_IncompleteAnnotation11() {
419419
runNegativeTest(sources,
420420
"----------\n" +
421421
"1. ERROR in X.groovy (at line 1)\n" +
422-
"\t@A(foo=['1','2'],)\n" +
422+
"\t@A(foo=[\"1\",\"2\"],)\n" +
423423
"\t^^\n" +
424424
"Groovy:No explicit/default value found for annotation attribute 'bar' in @A\n" +
425425
"----------\n");
@@ -436,7 +436,7 @@ public void testParsingRecovery_IncompleteAnnotation12() {
436436
//@formatter:off
437437
String[] sources = {
438438
"X.groovy",
439-
"@A(foo='1', b)\n" +
439+
"@A(foo=\"1\", b)\n" +
440440
"class X {\n" +
441441
"}\n",
442442

@@ -454,7 +454,7 @@ public void testParsingRecovery_IncompleteAnnotation12() {
454454
"The attribute b is undefined for the annotation type A\n" +
455455
"----------\n" +
456456
"2. ERROR in X.groovy (at line 1)\n" +
457-
"\t@A(foo='1', b)\n" +
457+
"\t@A(foo=\"1\", b)\n" +
458458
"\t^^\n" +
459459
"Groovy:No explicit/default value found for annotation attribute 'bar' in @A\n" +
460460
"----------\n");
@@ -471,7 +471,7 @@ public void testParsingRecovery_IncompleteAnnotation13() {
471471
//@formatter:off
472472
String[] sources = {
473473
"X.groovy",
474-
"@A(foo='1', bar=)\n" +
474+
"@A(foo=\"1\", bar=)\n" +
475475
"class X {\n" +
476476
"}\n",
477477

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public void testNamedVariant2() {
6262
"import groovy.transform.*\n" +
6363
"\n" +
6464
"@NamedVariant\n" +
65-
"String m(@NamedDelegate Color color, @NamedParam(value='a', required=true) int alpha) {\n" +
65+
"String m(@NamedDelegate Color color, @NamedParam(value=\"a\", required=true) int alpha) {\n" +
6666
" return [color, alpha].join(' ')\n" +
6767
"}\n" +
6868
"\n" +
@@ -84,7 +84,7 @@ public void testNamedVariant3() {
8484
"import groovy.transform.*\n" +
8585
"\n" +
8686
"@NamedVariant\n" +
87-
"String m(@NamedDelegate Color color, @NamedParam(value='a', type=Number) alpha) {\n" +
87+
"String m(@NamedDelegate Color color, @NamedParam(value=\"a\", type=Number) alpha) {\n" +
8888
" return [color, alpha].join(' ')\n" +
8989
"}\n" +
9090
"print m(r:1, g:2, b:3, a: 0.0)\n",

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ public void testTypeChecked19() {
446446
//@formatter:off
447447
String[] sources = {
448448
"Main.groovy",
449-
"def <T,U extends Configurable<T>> U configure(Class<U> type, @DelegatesTo(type='T',strategy=Closure.DELEGATE_FIRST) Closure<?> spec) {\n" +
449+
"def <T,U extends Configurable<T>> U configure(Class<U> type, @DelegatesTo(type=\"T\",strategy=Closure.DELEGATE_FIRST) Closure<?> spec) {\n" +
450450
" Configurable<T> obj = (Configurable<T>) type.newInstance()\n" +
451451
" obj.configure(spec)\n" +
452452
" obj\n" +
@@ -600,7 +600,7 @@ public void testTypeChecked25() {
600600
"@groovy.transform.TupleConstructor(defaults=false)\n" +
601601
"class Type<T,U> {\n" +
602602
" final T value\n" +
603-
" U map(@DelegatesTo(type='T') Closure<U> producer) {\n" +
603+
" U map(@DelegatesTo(type=\"T\") Closure<U> producer) {\n" +
604604
" producer.delegate = value\n" +
605605
" producer()\n" +
606606
" }\n" +
@@ -3766,7 +3766,7 @@ public void testTypeChecked10027() {
37663766
"import groovy.transform.*\n" +
37673767
"int getAnswer() { return 42 }\n" +
37683768
"void m(@NamedParams([\n" +
3769-
" @NamedParam(value='n', type=Number)\n" +
3769+
" @NamedParam(value=\"n\", type=Number)\n" +
37703770
"]) Map<String,?> map) { print map.n }\n" +
37713771
"@TypeChecked\n" +
37723772
"void test() {\n" +

base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/internal/compiler/ast/GroovyCompilationUnitDeclaration.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -1950,8 +1950,12 @@ private org.eclipse.jdt.internal.compiler.ast.Expression createInitializationExp
19501950
return new CharLiteral(chars, start, until);
19511951

19521952
case "java.lang.String":
1953-
if (ClassHelper.char_TYPE.equals(type) && ((String) value).length() == 1) {
1954-
return new CharLiteral(new char[] {'\'', ((String) value).charAt(0), '\''}, start, until);
1953+
if (((String) value).length() == 1) {
1954+
if (ClassHelper.char_TYPE.equals(type)) {
1955+
return new CharLiteral(new char[] {'\'', ((String) value).charAt(0), '\''}, start, until);
1956+
} else if (type == null && chars[0] == '\'' && chars[chars.length - 1] == '\'') {//GROOVY-9206
1957+
return new CharLiteral(chars, start, until);
1958+
}
19551959
}
19561960

19571961
if (CharOperation.prefixEquals(TRIPLE_QUOTE1, chars) ||

0 commit comments

Comments
 (0)