groovy git commit: Trivial refactoring for `AstStringCompiler`
Repository: groovy Updated Branches: refs/heads/GROOVY_2_5_X 0311b7745 -> fc3b18171 Trivial refactoring for `AstStringCompiler` (cherry picked from commit d8e35f6) Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/fc3b1817 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/fc3b1817 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/fc3b1817 Branch: refs/heads/GROOVY_2_5_X Commit: fc3b18171d91c8f2e92d1f23427f6bc161924de7 Parents: 0311b77 Author: danielsun1106Authored: Sat Apr 7 00:00:44 2018 +0800 Committer: danielsun1106 Committed: Sat Apr 7 00:02:58 2018 +0800 -- .../groovy/ast/builder/AstStringCompiler.groovy | 18 ++ 1 file changed, 10 insertions(+), 8 deletions(-) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/fc3b1817/src/main/groovy/org/codehaus/groovy/ast/builder/AstStringCompiler.groovy -- diff --git a/src/main/groovy/org/codehaus/groovy/ast/builder/AstStringCompiler.groovy b/src/main/groovy/org/codehaus/groovy/ast/builder/AstStringCompiler.groovy index ec18993..6089c0c 100644 --- a/src/main/groovy/org/codehaus/groovy/ast/builder/AstStringCompiler.groovy +++ b/src/main/groovy/org/codehaus/groovy/ast/builder/AstStringCompiler.groovy @@ -44,17 +44,16 @@ import org.codehaus.groovy.control.CompilerConfiguration * @param statementsOnly */ List compile(String script, CompilePhase compilePhase, boolean statementsOnly) { -def scriptClassName = "script" + System.currentTimeMillis() -GroovyClassLoader classLoader = new GroovyClassLoader() -GroovyCodeSource codeSource = new GroovyCodeSource(script, scriptClassName + ".groovy", "/groovy/script") -CompilationUnit cu = new CompilationUnit(CompilerConfiguration.DEFAULT, codeSource.codeSource, classLoader) -cu.addSource(codeSource.getName(), script); +final scriptClassName = makeScriptClassName() +GroovyCodeSource codeSource = new GroovyCodeSource(script, "${scriptClassName}.groovy", "/groovy/script") +CompilationUnit cu = new CompilationUnit(CompilerConfiguration.DEFAULT, codeSource.codeSource, new GroovyClassLoader()) +cu.addSource(codeSource.getName(), script) cu.compile(compilePhase.getPhaseNumber()) // collect all the ASTNodes into the result, possibly ignoring the script body if desired -return (List) cu.getAST().modules.inject([]) {List acc, ModuleNode node -> +return (List) cu.getAST().modules.inject([]) { List acc, ModuleNode node -> if (node.statementBlock) acc.add(node.statementBlock) node.classes?.each { -if (!(it.name == scriptClassName && statementsOnly)) { +if (!(statementsOnly && it.name == scriptClassName)) { acc << it } } @@ -62,4 +61,7 @@ import org.codehaus.groovy.control.CompilerConfiguration } } -} \ No newline at end of file +private static String makeScriptClassName() { +return "Script${System.nanoTime()}" +} +}
groovy git commit: Trivial refactoring for `AstStringCompiler`
Repository: groovy Updated Branches: refs/heads/GROOVY_2_6_X b3b570489 -> 15fb59614 Trivial refactoring for `AstStringCompiler` (cherry picked from commit d8e35f6) Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/15fb5961 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/15fb5961 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/15fb5961 Branch: refs/heads/GROOVY_2_6_X Commit: 15fb59614d78896bb79f703abdd804fcdd551fb9 Parents: b3b5704 Author: danielsun1106Authored: Sat Apr 7 00:00:44 2018 +0800 Committer: danielsun1106 Committed: Sat Apr 7 00:02:33 2018 +0800 -- .../groovy/ast/builder/AstStringCompiler.groovy | 18 ++ 1 file changed, 10 insertions(+), 8 deletions(-) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/15fb5961/src/main/groovy/org/codehaus/groovy/ast/builder/AstStringCompiler.groovy -- diff --git a/src/main/groovy/org/codehaus/groovy/ast/builder/AstStringCompiler.groovy b/src/main/groovy/org/codehaus/groovy/ast/builder/AstStringCompiler.groovy index ec18993..6089c0c 100644 --- a/src/main/groovy/org/codehaus/groovy/ast/builder/AstStringCompiler.groovy +++ b/src/main/groovy/org/codehaus/groovy/ast/builder/AstStringCompiler.groovy @@ -44,17 +44,16 @@ import org.codehaus.groovy.control.CompilerConfiguration * @param statementsOnly */ List compile(String script, CompilePhase compilePhase, boolean statementsOnly) { -def scriptClassName = "script" + System.currentTimeMillis() -GroovyClassLoader classLoader = new GroovyClassLoader() -GroovyCodeSource codeSource = new GroovyCodeSource(script, scriptClassName + ".groovy", "/groovy/script") -CompilationUnit cu = new CompilationUnit(CompilerConfiguration.DEFAULT, codeSource.codeSource, classLoader) -cu.addSource(codeSource.getName(), script); +final scriptClassName = makeScriptClassName() +GroovyCodeSource codeSource = new GroovyCodeSource(script, "${scriptClassName}.groovy", "/groovy/script") +CompilationUnit cu = new CompilationUnit(CompilerConfiguration.DEFAULT, codeSource.codeSource, new GroovyClassLoader()) +cu.addSource(codeSource.getName(), script) cu.compile(compilePhase.getPhaseNumber()) // collect all the ASTNodes into the result, possibly ignoring the script body if desired -return (List) cu.getAST().modules.inject([]) {List acc, ModuleNode node -> +return (List) cu.getAST().modules.inject([]) { List acc, ModuleNode node -> if (node.statementBlock) acc.add(node.statementBlock) node.classes?.each { -if (!(it.name == scriptClassName && statementsOnly)) { +if (!(statementsOnly && it.name == scriptClassName)) { acc << it } } @@ -62,4 +61,7 @@ import org.codehaus.groovy.control.CompilerConfiguration } } -} \ No newline at end of file +private static String makeScriptClassName() { +return "Script${System.nanoTime()}" +} +}
groovy git commit: Trivial refactoring for `AstStringCompiler`
Repository: groovy Updated Branches: refs/heads/master 697136d31 -> d8e35f637 Trivial refactoring for `AstStringCompiler` Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/d8e35f63 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/d8e35f63 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/d8e35f63 Branch: refs/heads/master Commit: d8e35f637ddc24563cc98970b2423ef806383de2 Parents: 697136d Author: danielsun1106Authored: Sat Apr 7 00:00:44 2018 +0800 Committer: danielsun1106 Committed: Sat Apr 7 00:00:44 2018 +0800 -- .../groovy/ast/builder/AstStringCompiler.groovy | 18 ++ 1 file changed, 10 insertions(+), 8 deletions(-) -- http://git-wip-us.apache.org/repos/asf/groovy/blob/d8e35f63/src/main/groovy/org/codehaus/groovy/ast/builder/AstStringCompiler.groovy -- diff --git a/src/main/groovy/org/codehaus/groovy/ast/builder/AstStringCompiler.groovy b/src/main/groovy/org/codehaus/groovy/ast/builder/AstStringCompiler.groovy index ec18993..6089c0c 100644 --- a/src/main/groovy/org/codehaus/groovy/ast/builder/AstStringCompiler.groovy +++ b/src/main/groovy/org/codehaus/groovy/ast/builder/AstStringCompiler.groovy @@ -44,17 +44,16 @@ import org.codehaus.groovy.control.CompilerConfiguration * @param statementsOnly */ List compile(String script, CompilePhase compilePhase, boolean statementsOnly) { -def scriptClassName = "script" + System.currentTimeMillis() -GroovyClassLoader classLoader = new GroovyClassLoader() -GroovyCodeSource codeSource = new GroovyCodeSource(script, scriptClassName + ".groovy", "/groovy/script") -CompilationUnit cu = new CompilationUnit(CompilerConfiguration.DEFAULT, codeSource.codeSource, classLoader) -cu.addSource(codeSource.getName(), script); +final scriptClassName = makeScriptClassName() +GroovyCodeSource codeSource = new GroovyCodeSource(script, "${scriptClassName}.groovy", "/groovy/script") +CompilationUnit cu = new CompilationUnit(CompilerConfiguration.DEFAULT, codeSource.codeSource, new GroovyClassLoader()) +cu.addSource(codeSource.getName(), script) cu.compile(compilePhase.getPhaseNumber()) // collect all the ASTNodes into the result, possibly ignoring the script body if desired -return (List) cu.getAST().modules.inject([]) {List acc, ModuleNode node -> +return (List) cu.getAST().modules.inject([]) { List acc, ModuleNode node -> if (node.statementBlock) acc.add(node.statementBlock) node.classes?.each { -if (!(it.name == scriptClassName && statementsOnly)) { +if (!(statementsOnly && it.name == scriptClassName)) { acc << it } } @@ -62,4 +61,7 @@ import org.codehaus.groovy.control.CompilerConfiguration } } -} \ No newline at end of file +private static String makeScriptClassName() { +return "Script${System.nanoTime()}" +} +}