You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by em...@apache.org on 2022/05/22 19:41:47 UTC
[groovy] branch master updated: GROOVY-4020, GROOVY-5760, GROOVY-7670, GROOVY-9194: dash in file name
This is an automated email from the ASF dual-hosted git repository.
emilles 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 2691fb0d2b GROOVY-4020, GROOVY-5760, GROOVY-7670, GROOVY-9194: dash in file name
2691fb0d2b is described below
commit 2691fb0d2b745a7cc6647edd09a71a3831ffa460
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Sun May 22 14:17:41 2022 -0500
GROOVY-4020, GROOVY-5760, GROOVY-7670, GROOVY-9194: dash in file name
---
.../codehaus/groovy/classgen/GeneratorContext.java | 49 ++++++++++------------
.../ClosureAndInnerClassNodeStructureTest.groovy | 32 +++++++-------
.../org/codehaus/groovy/ast/ModuleNodeTest.java | 2 +-
3 files changed, 41 insertions(+), 42 deletions(-)
diff --git a/src/main/java/org/codehaus/groovy/classgen/GeneratorContext.java b/src/main/java/org/codehaus/groovy/classgen/GeneratorContext.java
index 774b908198..72d6f485d6 100644
--- a/src/main/java/org/codehaus/groovy/classgen/GeneratorContext.java
+++ b/src/main/java/org/codehaus/groovy/classgen/GeneratorContext.java
@@ -24,9 +24,8 @@ import org.codehaus.groovy.ast.ClassNode;
import org.codehaus.groovy.ast.CompileUnit;
import org.codehaus.groovy.ast.MethodNode;
-
/**
- * A context shared across generations of a class and its inner classes
+ * A context shared across generations of a class and its inner classes.
*/
public class GeneratorContext {
@@ -83,33 +82,31 @@ public class GeneratorContext {
+ syntheticMethodIdx++;
}
- private static final int MIN_ENCODING = ' ';
- private static final int MAX_ENCODING = ']';
- private static final boolean[] CHARACTERS_TO_ENCODE = new boolean[MAX_ENCODING-MIN_ENCODING+1];
+ private static final boolean[] CHARACTERS_TO_ENCODE;
+ private static final int MIN_ENCODING, MAX_ENCODING;
static {
- CHARACTERS_TO_ENCODE[' '-MIN_ENCODING] = true;
- CHARACTERS_TO_ENCODE['!'-MIN_ENCODING] = true;
- CHARACTERS_TO_ENCODE['/'-MIN_ENCODING] = true;
- CHARACTERS_TO_ENCODE['.'-MIN_ENCODING] = true;
- CHARACTERS_TO_ENCODE[';'-MIN_ENCODING] = true;
- CHARACTERS_TO_ENCODE['$'-MIN_ENCODING] = true;
- CHARACTERS_TO_ENCODE['<'-MIN_ENCODING] = true;
- CHARACTERS_TO_ENCODE['>'-MIN_ENCODING] = true;
- CHARACTERS_TO_ENCODE['['-MIN_ENCODING] = true;
- CHARACTERS_TO_ENCODE[']'-MIN_ENCODING] = true;
- CHARACTERS_TO_ENCODE[':'-MIN_ENCODING] = true;
- CHARACTERS_TO_ENCODE['\\'-MIN_ENCODING] = true;
+ char[] chars = {' ', '!', '"', '#', '$', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/', ':', ';', '<', '=', '>', '@', '[', '\\', ']', '^', '{', '}', '~'};
+
+ MIN_ENCODING = chars[0];
+ MAX_ENCODING = chars[chars.length - 1];
+ CHARACTERS_TO_ENCODE = new boolean[MAX_ENCODING - MIN_ENCODING + 1];
+
+ for (char c : chars) {
+ CHARACTERS_TO_ENCODE[c - MIN_ENCODING] = true;
+ }
}
- public static String encodeAsValidClassName(String name) {
- final int l = name.length();
- StringBuilder b = null;
+ public static String encodeAsValidClassName(final String name) {
+ if (name.equals("module-info") || name.equals("package-info")) return name;
+
int lastEscape = -1;
- for(int i = 0; i < l; ++i) {
- final int encodeIndex = name.charAt(i) - MIN_ENCODING;
+ StringBuilder b = null;
+ final int n = name.length();
+ for (int i = 0; i < n; i += 1) {
+ int encodeIndex = name.charAt(i) - MIN_ENCODING;
if (encodeIndex >= 0 && encodeIndex < CHARACTERS_TO_ENCODE.length) {
if (CHARACTERS_TO_ENCODE[encodeIndex]) {
- if(b == null) {
+ if (b == null) {
b = new StringBuilder(name.length() + 3);
b.append(name, 0, i);
} else {
@@ -120,9 +117,9 @@ public class GeneratorContext {
}
}
}
- if(b == null) return name;
- if (lastEscape == -1) throw new GroovyBugError("unexpected escape char control flow in "+name);
- b.append(name, lastEscape + 1, l);
+ if (b == null) return name;
+ if (lastEscape == -1) throw new GroovyBugError("unexpected escape char control flow in " + name);
+ b.append(name, lastEscape + 1, n);
return b.toString();
}
}
diff --git a/src/test/org/codehaus/groovy/ClosureAndInnerClassNodeStructureTest.groovy b/src/test/org/codehaus/groovy/ClosureAndInnerClassNodeStructureTest.groovy
index c361058b98..66a69d62d0 100644
--- a/src/test/org/codehaus/groovy/ClosureAndInnerClassNodeStructureTest.groovy
+++ b/src/test/org/codehaus/groovy/ClosureAndInnerClassNodeStructureTest.groovy
@@ -28,11 +28,11 @@ import org.junit.Test
import static groovy.test.GroovyAssert.assertScript
/**
- * Before Groovy 1.8, the structure of closure's inner classes
- * was a bit different than it is now in 1.8+.
- *
- * This test checks that closure inner classes are direct child of their enclosing class,
- * instead of being child of the outermost class.
+ * Before Groovy 1.8, the structure of closure's inner class was a bit different
+ * than it is now.
+ * <p>
+ * This test checks that closure inner class is direct child of its enclosing
+ * class, instead of being child of the outermost class.
*/
final class ClosureAndInnerClassNodeStructureTest {
@@ -97,16 +97,18 @@ final class ClosureAndInnerClassNodeStructureTest {
'''
}
- @Test //GROOVY-7119, GROOVY-7120
- void testIrregularMethodName() {
- assertScript '''
- class X {
- def 'foo!bar'() {
- return {}
+ @Test // GROOVY-7119, GROOVY-7120
+ void testIrregularMethodNames() {
+ [' ', '!', '"', '#', '$', '&', '\\\'', '(', ')', '*', '+', ',', '-', ':', '=', '@', '^', '{', '}', '~'].each { c ->
+ assertScript """
+ class X {
+ def 'foo${c}bar'() {
+ return {}
+ }
}
- }
- def str = new X().'foo!bar'().getClass().getName()
- assert str == 'X$_foo_bar_closure1'
- '''
+ def str = new X().'foo${c}bar'().getClass().getName()
+ assert str == 'X\$_foo_bar_closure1'
+ """
+ }
}
}
diff --git a/src/test/org/codehaus/groovy/ast/ModuleNodeTest.java b/src/test/org/codehaus/groovy/ast/ModuleNodeTest.java
index 67d155f809..a5df3368a1 100644
--- a/src/test/org/codehaus/groovy/ast/ModuleNodeTest.java
+++ b/src/test/org/codehaus/groovy/ast/ModuleNodeTest.java
@@ -45,7 +45,7 @@ public final class ModuleNodeTest {
ModuleNode mn = new ModuleNode((CompileUnit) null);
mn.setDescription("#script.groovy");
- assertEquals("Dummy class name should not be empty", "#script", mn.getScriptClassDummy().getName());
+ assertEquals("Dummy class name should not be empty", "_script", mn.getScriptClassDummy().getName());
}
@Test // GROOVY-9577