You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by ke...@apache.org on 2021/03/10 03:34:59 UTC
[groovy] branch master updated: fix GROOVY-9962 Don't replace
dollars in strings
This is an automated email from the ASF dual-hosted git repository.
keegan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/master by this push:
new 4e3b365 fix GROOVY-9962 Don't replace dollars in strings
4e3b365 is described below
commit 4e3b3657d5c887437f2f658b71f9f60734c906a4
Author: Keegan Witt <ke...@gmail.com>
AuthorDate: Tue Mar 9 22:34:39 2021 -0500
fix GROOVY-9962
Don't replace dollars in strings
---
.../groovy/tools/javac/JavaStubGenerator.java | 11 ++++--
.../groovy/tools/stubgenerator/Groovy9962.groovy | 43 ++++++++++++++++++++++
2 files changed, 50 insertions(+), 4 deletions(-)
diff --git a/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java b/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
index 3d4158c..35b7ae5 100644
--- a/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
+++ b/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
@@ -935,13 +935,14 @@ public class JavaStubGenerator {
String key = entry.getKey();
if (first) first = false;
else out.print(", ");
- out.print(key + "=" + getAnnotationValue(entry.getValue()).replace('$', '.'));
+ out.print(key + "=" + getAnnotationValue(entry.getValue()));
}
out.print(") ");
}
private String getAnnotationValue(Object memberValue) {
String val = "null";
+ boolean replaceDollars = true;
if (memberValue instanceof ListExpression) {
StringBuilder sb = new StringBuilder("{");
boolean first = true;
@@ -961,10 +962,12 @@ public class JavaStubGenerator {
PrintWriter out = new PrintWriter(writer);
printAnnotation(out, (AnnotationNode) constValue);
val = writer.toString();
- } else if (constValue instanceof Number || constValue instanceof Boolean)
+ } else if (constValue instanceof Number || constValue instanceof Boolean) {
val = constValue.toString();
- else
+ } else {
val = "\"" + escapeSpecialChars(constValue.toString()) + "\"";
+ replaceDollars = false;
+ }
} else if (memberValue instanceof PropertyExpression) {
// assume must be static class field or enum value or class that Java can resolve
val = ((Expression) memberValue).getText();
@@ -981,7 +984,7 @@ public class JavaStubGenerator {
} else if (memberValue instanceof ClassExpression) {
val = ((Expression) memberValue).getText() + ".class";
}
- return val;
+ return replaceDollars ? val.replace('$', '.') : val;
}
private static void printModifiers(PrintWriter out, int modifiers) {
diff --git a/src/test/org/codehaus/groovy/tools/stubgenerator/Groovy9962.groovy b/src/test/org/codehaus/groovy/tools/stubgenerator/Groovy9962.groovy
new file mode 100644
index 0000000..145780a
--- /dev/null
+++ b/src/test/org/codehaus/groovy/tools/stubgenerator/Groovy9962.groovy
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.codehaus.groovy.tools.stubgenerator
+
+/**
+ * Test that annotations with string values containing dollar signs don't change string value in stub.
+ */
+class Groovy9962 extends StringSourcesStubTestCase {
+
+ Map<String, String> provideSources() {
+ [
+ 'Foo.java': '''
+ public class Foo {}
+ ''',
+ 'Groovy9962.groovy': '''
+ @Deprecated(since = '${name} paid $7')
+ class Groovy9962 {}
+ '''
+ ]
+ }
+
+ void verifyStubs() {
+ def stubSource = stubJavaSourceFor('Groovy9962')
+ assert stubSource.contains('${name} paid $7')
+ }
+}