Skip to content

Commit

Permalink
GROOVY-9206
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Jul 21, 2022
1 parent 8083e5d commit 6d80c05
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ public void testCharLiteralAttributeValue() {

"Main.groovy",
"class Main {\n" +
" @Separator((char)';')\n" +
" @Separator(';')\n" +
" String tokens\n" +
"}\n",
};
Expand All @@ -709,14 +709,9 @@ public void testCharLiteralAttributeValue() {
runNegativeTest(sources,
"----------\n" +
"1. ERROR in Main.groovy (at line 2)\n" +
"\t@Separator((char)';')\n" +
"\t ^^^^^^^^^\n" +
"Groovy:Expected '(char) ;' to be an inline constant of type char in @Separator\n" +
"----------\n" +
"2. ERROR in Main.groovy (at line 2)\n" +
"\t@Separator((char)';')\n" +
"\t ^^^^^^^^^\n" +
"Groovy:Attribute 'value' should have type 'java.lang.Character'; but found type 'java.lang.Object' in @Separator\n" +
"\t@Separator(';')\n" +
"\t ^^^\n" +
"Groovy:Attribute 'value' should have type 'java.lang.Character'; but found type 'java.lang.String' in @Separator\n" +
"----------\n");
}
}
Expand Down Expand Up @@ -2636,7 +2631,7 @@ public void testAnnotationsTargetType13() {
"p/Main.groovy",
"package p;\n" +
"public class Main {\n" +
" void m(@Anno('x') String s) {}\n" +
" void m(@Anno(\"x\") String s) {}\n" +
" static main(args) {\n" +
" print getMethod('m', String).annotatedParameterTypes[0].annotations[0].value()\n" +
" }\n" +
Expand All @@ -2657,7 +2652,7 @@ public void testAnnotationsTargetType13() {
runNegativeTest(sources,
"----------\n" +
"1. ERROR in p\\Main.groovy (at line 3)\n" +
"\tvoid m(@Anno('x') String s) {}\n" +
"\tvoid m(@Anno(\"x\") String s) {}\n" +
"\t ^^^^^\n" +
"Groovy:Annotation @p.Anno is not allowed on element PARAMETER\n" +
"----------\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ public void testParsingRecovery_IncompleteAnnotation10() {
//@formatter:off
String[] sources = {
"X.groovy",
"@A(foo='1',)\n" +
"@A(foo=\"1\",)\n" +
"class X {\n" +
"}\n",

Expand All @@ -387,7 +387,7 @@ public void testParsingRecovery_IncompleteAnnotation10() {
runNegativeTest(sources,
"----------\n" +
"1. ERROR in X.groovy (at line 1)\n" +
"\t@A(foo='1',)\n" +
"\t@A(foo=\"1\",)\n" +
"\t^^\n" +
"Groovy:No explicit/default value found for annotation attribute 'bar' in @A\n" +
"----------\n");
Expand All @@ -404,7 +404,7 @@ public void testParsingRecovery_IncompleteAnnotation11() {
//@formatter:off
String[] sources = {
"X.groovy",
"@A(foo=['1','2'],)\n" +
"@A(foo=[\"1\",\"2\"],)\n" +
"class X {\n" +
"}\n",

Expand All @@ -419,7 +419,7 @@ public void testParsingRecovery_IncompleteAnnotation11() {
runNegativeTest(sources,
"----------\n" +
"1. ERROR in X.groovy (at line 1)\n" +
"\t@A(foo=['1','2'],)\n" +
"\t@A(foo=[\"1\",\"2\"],)\n" +
"\t^^\n" +
"Groovy:No explicit/default value found for annotation attribute 'bar' in @A\n" +
"----------\n");
Expand All @@ -436,7 +436,7 @@ public void testParsingRecovery_IncompleteAnnotation12() {
//@formatter:off
String[] sources = {
"X.groovy",
"@A(foo='1', b)\n" +
"@A(foo=\"1\", b)\n" +
"class X {\n" +
"}\n",

Expand All @@ -454,7 +454,7 @@ public void testParsingRecovery_IncompleteAnnotation12() {
"The attribute b is undefined for the annotation type A\n" +
"----------\n" +
"2. ERROR in X.groovy (at line 1)\n" +
"\t@A(foo='1', b)\n" +
"\t@A(foo=\"1\", b)\n" +
"\t^^\n" +
"Groovy:No explicit/default value found for annotation attribute 'bar' in @A\n" +
"----------\n");
Expand All @@ -471,7 +471,7 @@ public void testParsingRecovery_IncompleteAnnotation13() {
//@formatter:off
String[] sources = {
"X.groovy",
"@A(foo='1', bar=)\n" +
"@A(foo=\"1\", bar=)\n" +
"class X {\n" +
"}\n",

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void testNamedVariant2() {
"import groovy.transform.*\n" +
"\n" +
"@NamedVariant\n" +
"String m(@NamedDelegate Color color, @NamedParam(value='a', required=true) int alpha) {\n" +
"String m(@NamedDelegate Color color, @NamedParam(value=\"a\", required=true) int alpha) {\n" +
" return [color, alpha].join(' ')\n" +
"}\n" +
"\n" +
Expand All @@ -84,7 +84,7 @@ public void testNamedVariant3() {
"import groovy.transform.*\n" +
"\n" +
"@NamedVariant\n" +
"String m(@NamedDelegate Color color, @NamedParam(value='a', type=Number) alpha) {\n" +
"String m(@NamedDelegate Color color, @NamedParam(value=\"a\", type=Number) alpha) {\n" +
" return [color, alpha].join(' ')\n" +
"}\n" +
"print m(r:1, g:2, b:3, a: 0.0)\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ public void testTypeChecked19() {
//@formatter:off
String[] sources = {
"Main.groovy",
"def <T,U extends Configurable<T>> U configure(Class<U> type, @DelegatesTo(type='T',strategy=Closure.DELEGATE_FIRST) Closure<?> spec) {\n" +
"def <T,U extends Configurable<T>> U configure(Class<U> type, @DelegatesTo(type=\"T\",strategy=Closure.DELEGATE_FIRST) Closure<?> spec) {\n" +
" Configurable<T> obj = (Configurable<T>) type.newInstance()\n" +
" obj.configure(spec)\n" +
" obj\n" +
Expand Down Expand Up @@ -600,7 +600,7 @@ public void testTypeChecked25() {
"@groovy.transform.TupleConstructor(defaults=false)\n" +
"class Type<T,U> {\n" +
" final T value\n" +
" U map(@DelegatesTo(type='T') Closure<U> producer) {\n" +
" U map(@DelegatesTo(type=\"T\") Closure<U> producer) {\n" +
" producer.delegate = value\n" +
" producer()\n" +
" }\n" +
Expand Down Expand Up @@ -3766,7 +3766,7 @@ public void testTypeChecked10027() {
"import groovy.transform.*\n" +
"int getAnswer() { return 42 }\n" +
"void m(@NamedParams([\n" +
" @NamedParam(value='n', type=Number)\n" +
" @NamedParam(value=\"n\", type=Number)\n" +
"]) Map<String,?> map) { print map.n }\n" +
"@TypeChecked\n" +
"void test() {\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1950,8 +1950,12 @@ private org.eclipse.jdt.internal.compiler.ast.Expression createInitializationExp
return new CharLiteral(chars, start, until);

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

if (CharOperation.prefixEquals(TRIPLE_QUOTE1, chars) ||
Expand Down

0 comments on commit 6d80c05

Please sign in to comment.