This is an automated email from the ASF dual-hosted git repository.
paulk 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 b9141a6ef0 GROOVY-8162: Update Groovysh to JLine3 (clarify duplicate
var handling)
b9141a6ef0 is described below
commit b9141a6ef066da93dc953d8e2d6bdbaa43c6bc76
Author: Paul King <[email protected]>
AuthorDate: Tue Aug 5 23:52:53 2025 +1000
GROOVY-8162: Update Groovysh to JLine3 (clarify duplicate var handling)
---
.../org/apache/groovy/groovysh/jline/GroovyEngine.java | 14 ++++++++++++--
subprojects/groovy-groovysh/src/spec/doc/groovysh.adoc | 2 ++
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git
a/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/jline/GroovyEngine.java
b/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/jline/GroovyEngine.java
index cfc886b3a0..3117c22744 100644
---
a/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/jline/GroovyEngine.java
+++
b/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/jline/GroovyEngine.java
@@ -437,9 +437,17 @@ public class GroovyEngine implements ScriptEngine {
EnumSet<SnippetType> filter = iMode
? EnumSet.of(SnippetType.IMPORT, SnippetType.VARIABLE,
SnippetType.METHOD)
: EnumSet.of(SnippetType.IMPORT);
+ Matcher matcher = PATTERN_VAR_DEF.matcher(statement);
+ if (matcher.matches()) {
+ String name = matcher.group(1);
+ Integer existing = variables.get(name);
+ if (existing != null) {
+ snippets.set(existing, null);
+ }
+ }
out = executeStatement(shell, snippets, filter, statement);
classLoader.purgeClassCache();
- Matcher matcher = PATTERN_TYPE_DEF.matcher(statement);
+ matcher = PATTERN_TYPE_DEF.matcher(statement);
if (matcher.matches()) {
String name = matcher.group(2) != null ? matcher.group(2) :
matcher.group(3);
types.put(name, addSnippet(SnippetType.TYPE,
removeTrailingSemi(matcher.group(0))));
@@ -447,7 +455,9 @@ public class GroovyEngine implements ScriptEngine {
}
matcher = PATTERN_VAR_DEF.matcher(statement);
if (matcher.matches()) {
- variables.put(matcher.group(1),
addSnippet(SnippetType.VARIABLE, removeTrailingSemi(matcher.group(0))));
+ String name = matcher.group(1);
+ String code = removeTrailingSemi(matcher.group(0));
+ variables.put(name, addSnippet(SnippetType.VARIABLE, code));
}
}
return out;
diff --git a/subprojects/groovy-groovysh/src/spec/doc/groovysh.adoc
b/subprojects/groovy-groovysh/src/spec/doc/groovysh.adoc
index e094a7c994..0916b8b0c5 100644
--- a/subprojects/groovy-groovysh/src/spec/doc/groovysh.adoc
+++ b/subprojects/groovy-groovysh/src/spec/doc/groovysh.adoc
@@ -243,6 +243,8 @@ def foo = "bar"
This behavior can be changed by activating
<<GroovyShell-InterpreterMode,interpreter mode>>.
+Variables definitions having the same name as existing definitions will
replace the old definition with the new one.
+
[[GroovyShell-Methods]]
==== Methods