You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2020/04/19 06:52:01 UTC
[groovy] branch GROOVY-9513 updated: Remove indy flags in the
groovy console
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch GROOVY-9513
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/GROOVY-9513 by this push:
new 5c97a2f Remove indy flags in the groovy console
5c97a2f is described below
commit 5c97a2ff2de7d4181693ae82895a78272ddc46ad
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sun Apr 19 14:51:40 2020 +0800
Remove indy flags in the groovy console
---
.../groovy/groovy/console/ui/AstBrowser.groovy | 40 ++++-----------------
.../main/groovy/groovy/console/ui/Console.groovy | 41 +---------------------
.../groovy/groovy/console/ui/ConsoleActions.groovy | 7 ----
.../console/ui/ScriptToTreeNodeAdapter.groovy | 7 +---
.../groovy/console/ui/view/BasicMenuBar.groovy | 1 -
.../resources/groovy/console/ui/Console.properties | 2 --
.../src/spec/doc/groovy-console.adoc | 3 --
.../groovy/console/SwingBuilderConsoleTest.groovy | 17 +++------
.../console/ui/ScriptToTreeNodeAdapterTest.groovy | 2 +-
9 files changed, 13 insertions(+), 107 deletions(-)
diff --git a/subprojects/groovy-console/src/main/groovy/groovy/console/ui/AstBrowser.groovy b/subprojects/groovy-console/src/main/groovy/groovy/console/ui/AstBrowser.groovy
index d2f6fab..1b21ea8 100644
--- a/subprojects/groovy-console/src/main/groovy/groovy/console/ui/AstBrowser.groovy
+++ b/subprojects/groovy-console/src/main/groovy/groovy/console/ui/AstBrowser.groovy
@@ -69,7 +69,7 @@ class AstBrowser {
private static final String NO_BYTECODE_AVAILABLE_AT_THIS_PHASE = '// No bytecode available at this phase'
private inputArea, rootElement, decompiledSource, jTree, propertyTable, splitterPane, mainSplitter, bytecodeView, asmifierView
- boolean showScriptFreeForm, showScriptClass, showClosureClasses, showTreeView, showIndyBytecode
+ boolean showScriptFreeForm, showScriptClass, showClosureClasses, showTreeView
GeneratedBytecodeAwareGroovyClassLoader classLoader
def prefs = new AstBrowserUiPreferences()
Action refreshAction
@@ -118,14 +118,13 @@ class AstBrowser {
showScriptClass = prefs.showScriptClass
showClosureClasses = prefs.showClosureClasses
showTreeView = prefs.showTreeView
- showIndyBytecode = prefs.showIndyBytecode
frame = swing.frame(title: 'Groovy AST Browser' + (name ? " - $name" : ''),
location: prefs.frameLocation,
size: prefs.frameSize,
iconImage: swing.imageIcon(Console.ICON_PATH).image,
defaultCloseOperation: WindowConstants.DISPOSE_ON_CLOSE,
- windowClosing: { event -> prefs.save(frame, splitterPane, mainSplitter, showScriptFreeForm, showScriptClass, showClosureClasses, phasePicker.selectedItem, showTreeView, showIndyBytecode) }) {
+ windowClosing: { event -> prefs.save(frame, splitterPane, mainSplitter, showScriptFreeForm, showScriptClass, showClosureClasses, phasePicker.selectedItem, showTreeView) }) {
menuBar {
menu(text: 'Show Script', mnemonic: 'S') {
@@ -145,10 +144,6 @@ class AstBrowser {
action(name: 'Tree View', closure: this.&showTreeView,
mnemonic: 'T')
}
- checkBoxMenuItem(selected: showIndyBytecode) {
- action(name: 'Generate Indy Bytecode', closure: this.&showIndyBytecode,
- mnemonic: 'I')
- }
}
menu(text: 'View', mnemonic: 'V') {
menuItem {
@@ -435,32 +430,12 @@ class AstBrowser {
}
}
- void showIndyBytecode(EventObject evt = null) {
- showIndyBytecode = evt.source.selected
- initAuxViews()
- refreshAction.actionPerformed(null)
- updateTabTitles()
- }
-
- private void updateTabTitles() {
- def tabPane = mainSplitter.bottomComponent
- int tabCount = tabPane.getTabCount()
- for (int i = 0; i < tabCount; i++) {
- def component = tabPane.getComponentAt(i)
- if (bytecodeView.is(component)) {
- tabPane.setTitleAt(i, getByteCodeTitle())
- } else if (asmifierView.is(component)) {
- tabPane.setTitleAt(i, getASMifierTitle())
- }
- }
- }
-
private String getByteCodeTitle() {
- 'Bytecode' + (showIndyBytecode ? ' (Indy)' : '')
+ 'Bytecode'
}
private String getASMifierTitle() {
- 'ASMifier' + (showIndyBytecode ? ' (Indy)' : '')
+ 'ASMifier'
}
void decompile(phaseId, source) {
@@ -502,7 +477,7 @@ class AstBrowser {
def nodeMaker = new SwingTreeNodeMaker()
def adapter = new ScriptToTreeNodeAdapter(classLoader, showScriptFreeForm, showScriptClass, showClosureClasses, nodeMaker, config)
classLoader.clearBytecodeTable()
- def result = adapter.compile(script, compilePhase, showIndyBytecode)
+ def result = adapter.compile(script, compilePhase)
swing.doLater {
model.setRoot(result)
model.reload()
@@ -531,7 +506,6 @@ class AstBrowserUiPreferences {
final boolean showTreeView
final boolean showScriptClass
final boolean showClosureClasses
- final boolean showIndyBytecode
int decompiledSourceFontSize
final CompilePhaseAdapter selectedPhase
@@ -551,14 +525,13 @@ class AstBrowserUiPreferences {
showScriptClass = prefs.getBoolean('showScriptClass', true)
showClosureClasses = prefs.getBoolean('showClosureClasses', false)
showTreeView = prefs.getBoolean('showTreeView', true)
- showIndyBytecode = prefs.getBoolean('showIndyBytecode', false)
int phase = prefs.getInt('compilerPhase', Phases.SEMANTIC_ANALYSIS)
selectedPhase = CompilePhaseAdapter.values().find {
it.phaseId == phase
}
}
- def save(frame, vSplitter, hSplitter, scriptFreeFormPref, scriptClassPref, closureClassesPref, CompilePhaseAdapter phase, showTreeView, showIndyBytecode = false) {
+ def save(frame, vSplitter, hSplitter, scriptFreeFormPref, scriptClassPref, closureClassesPref, CompilePhaseAdapter phase, showTreeView) {
Preferences prefs = Preferences.userNodeForPackage(AstBrowserUiPreferences)
prefs.putInt('decompiledFontSize', decompiledSourceFontSize as int)
prefs.putInt('frameX', frame.location.x as int)
@@ -571,7 +544,6 @@ class AstBrowserUiPreferences {
prefs.putBoolean('showScriptClass', scriptClassPref)
prefs.putBoolean('showClosureClasses', closureClassesPref)
prefs.putBoolean('showTreeView', showTreeView)
- prefs.putBoolean('showIndyBytecode', showIndyBytecode)
prefs.putInt('compilerPhase', phase.phaseId)
}
}
diff --git a/subprojects/groovy-console/src/main/groovy/groovy/console/ui/Console.groovy b/subprojects/groovy-console/src/main/groovy/groovy/console/ui/Console.groovy
index 6a5a90c..72b8e5e 100644
--- a/subprojects/groovy-console/src/main/groovy/groovy/console/ui/Console.groovy
+++ b/subprojects/groovy-console/src/main/groovy/groovy/console/ui/Console.groovy
@@ -162,9 +162,6 @@ class Console implements CaretListener, HyperlinkListener, ComponentListener, Fo
boolean loopMode = prefs.getBoolean('loopMode', false)
int inputAreaContentHash
- boolean indy = prefs.getBoolean('indy', false)
- Action indyAction
-
//to allow loading classes dynamically when using @Grab (GROOVY-4877, GROOVY-5871)
boolean useScriptClassLoaderForScriptExecution = false
@@ -254,7 +251,6 @@ class Console implements CaretListener, HyperlinkListener, ComponentListener, Fo
V(longOpt: 'version', messages['cli.option.version.description'])
pa(longOpt: 'parameters', messages['cli.option.parameters.description'])
pr(longOpt: 'enable-preview', messages['cli.option.enable.preview.description'])
- i(longOpt: 'indy', messages['cli.option.indy.description'])
D(longOpt: 'define', type: Map, argName: 'name=value', messages['cli.option.define.description'])
_(longOpt: 'configscript', args: 1, messages['cli.option.configscript.description'])
}
@@ -300,10 +296,6 @@ class Console implements CaretListener, HyperlinkListener, ComponentListener, Fo
baseConfig.setParameters(options.hasOption("pa"))
- if (options.i) {
- enableIndy(baseConfig)
- }
-
def console = new Console(Thread.currentThread().contextClassLoader, new Binding(), baseConfig)
console.useScriptClassLoaderForScriptExecution = true
console.run()
@@ -360,10 +352,6 @@ class Console implements CaretListener, HyperlinkListener, ComponentListener, Fo
Console(ClassLoader parent, Binding binding = new Binding(), CompilerConfiguration baseConfig = new CompilerConfiguration(System.getProperties())) {
this.baseConfig = baseConfig
this.maxOutputChars = loadMaxOutputChars()
- indy = indy || isIndyEnabled(baseConfig)
- if (indy) {
- enableIndy(baseConfig)
- }
// Set up output file for stdout/stderr, if any
def outputLogFileName = prefs.get('outputLogFileName', null)
@@ -477,7 +465,7 @@ class Console implements CaretListener, HyperlinkListener, ComponentListener, Fo
swing.consoleFrame.show()
}
installInterceptor()
- updateTitle() // Title changes based on indy setting
+ updateTitle()
swing.doLater inputArea.&requestFocus
}
@@ -1259,30 +1247,6 @@ class Console implements CaretListener, HyperlinkListener, ComponentListener, Fo
prefs.putBoolean('loopMode', loopMode)
}
- void indy(EventObject evt = null) {
- indy = evt.source.selected
- prefs.putBoolean('indy', indy)
- if (indy) {
- enableIndy(baseConfig)
- } else {
- disableIndy(baseConfig)
- }
- updateTitle()
- newScript(shell.classLoader, shell.context)
- }
-
- private static void enableIndy(CompilerConfiguration cc) {
- cc.getOptimizationOptions().put(CompilerConfiguration.INVOKEDYNAMIC, true)
- }
-
- private static void disableIndy(CompilerConfiguration cc) {
- cc.getOptimizationOptions().remove(CompilerConfiguration.INVOKEDYNAMIC)
- }
-
- private static boolean isIndyEnabled(CompilerConfiguration cc) {
- cc.getOptimizationOptions().get(CompilerConfiguration.INVOKEDYNAMIC)
- }
-
void runSelectedJava(EventObject evt = null) {
runSelectedScript(evt, new JavaSourceType())
}
@@ -1746,9 +1710,6 @@ class Console implements CaretListener, HyperlinkListener, ComponentListener, Fo
void updateTitle() {
if (frame.title) {
String title = 'GroovyConsole'
- if (indy) {
- title += ' (Indy)'
- }
if (scriptFile != null) {
frame.title = scriptFile.name + (dirty ? ' * ' : '') + ' - ' + title
} else {
diff --git a/subprojects/groovy-console/src/main/groovy/groovy/console/ui/ConsoleActions.groovy b/subprojects/groovy-console/src/main/groovy/groovy/console/ui/ConsoleActions.groovy
index eea6bcd..5c9b52b 100644
--- a/subprojects/groovy-console/src/main/groovy/groovy/console/ui/ConsoleActions.groovy
+++ b/subprojects/groovy-console/src/main/groovy/groovy/console/ui/ConsoleActions.groovy
@@ -446,13 +446,6 @@ selectBlockAction = action(
shortDescription: 'Selects current Word, Line or Block in Script'
)
-indyAction = action(
- name: 'Enable Indy Compilation',
- closure: controller.&indy,
- mnemonic: 'I',
- shortDescription: 'Enable InvokeDynamic (Indy) compilation for scripts'
-)
-
preferencesAction = action(
name: 'Preferences',
closure: controller.&preferences,
diff --git a/subprojects/groovy-console/src/main/groovy/groovy/console/ui/ScriptToTreeNodeAdapter.groovy b/subprojects/groovy-console/src/main/groovy/groovy/console/ui/ScriptToTreeNodeAdapter.groovy
index c9e78f4..f2f0fb3 100644
--- a/subprojects/groovy-console/src/main/groovy/groovy/console/ui/ScriptToTreeNodeAdapter.groovy
+++ b/subprojects/groovy-console/src/main/groovy/groovy/console/ui/ScriptToTreeNodeAdapter.groovy
@@ -164,19 +164,14 @@ class ScriptToTreeNodeAdapter {
* a Groovy script in String form
* @param compilePhase
* the int based CompilePhase to compile it to.
- * @param indy
- * if {@code true} InvokeDynamic (Indy) bytecode is generated
*/
- def compile(String script, int compilePhase, boolean indy=false) {
+ def compile(String script, int compilePhase) {
def scriptName = 'script' + System.currentTimeMillis() + '.groovy'
GroovyCodeSource codeSource = new GroovyCodeSource(script, scriptName, '/groovy/script')
CompilerConfiguration cc = new CompilerConfiguration(config ?: CompilerConfiguration.DEFAULT)
if (config) {
cc.addCompilationCustomizers(*config.compilationCustomizers)
}
- if (indy) {
- cc.optimizationOptions.put(CompilerConfiguration.INVOKEDYNAMIC, true)
- }
CompilationUnit cu = new CompilationUnit(cc, codeSource.codeSource, classLoader)
cu.setClassgenCallback(classLoader.createCollector(cu, null))
diff --git a/subprojects/groovy-console/src/main/groovy/groovy/console/ui/view/BasicMenuBar.groovy b/subprojects/groovy-console/src/main/groovy/groovy/console/ui/view/BasicMenuBar.groovy
index f584595..f598e40 100644
--- a/subprojects/groovy-console/src/main/groovy/groovy/console/ui/view/BasicMenuBar.groovy
+++ b/subprojects/groovy-console/src/main/groovy/groovy/console/ui/view/BasicMenuBar.groovy
@@ -87,7 +87,6 @@ menuBar {
menuItem(interruptAction)
menuItem(compileAction)
menuItem(compileJavaAction)
- checkBoxMenuItem(indyAction, selected: controller.indy)
separator()
menuItem(addClasspathJar)
menuItem(addClasspathDir)
diff --git a/subprojects/groovy-console/src/main/resources/groovy/console/ui/Console.properties b/subprojects/groovy-console/src/main/resources/groovy/console/ui/Console.properties
index 56371c2..f0ad966 100644
--- a/subprojects/groovy-console/src/main/resources/groovy/console/ui/Console.properties
+++ b/subprojects/groovy-console/src/main/resources/groovy/console/ui/Console.properties
@@ -30,8 +30,6 @@ cli.option.enable.preview.description=Enable preview Java features (JEP 12) (jdk
cli.option.parameters.description=Generate metadata for reflection on method parameter names (jdk8+ only)
-cli.option.indy.description=Enable InvokeDynamic (Indy) compilation for scripts
-
cli.option.define.description=Define a system property
cli.option.configscript.description=A script for tweaking the compiler configuration options
diff --git a/subprojects/groovy-console/src/spec/doc/groovy-console.adoc b/subprojects/groovy-console/src/spec/doc/groovy-console.adoc
index a77d7df..d149f9d 100644
--- a/subprojects/groovy-console/src/spec/doc/groovy-console.adoc
+++ b/subprojects/groovy-console/src/spec/doc/groovy-console.adoc
@@ -61,7 +61,6 @@ The Groovy Swing Console allows a user to enter and run Groovy scripts.
argument
-D, --define=<name=value> Define a system property
-h, --help Display this help message
- -i, --indy Enable InvokeDynamic (Indy) compilation for scripts
-pa, --parameters Generate metadata for reflection on method parameter
names (jdk8+ only)
-pr, --enable-preview Enable preview Java features (JEP 12) (jdk12+ only)
@@ -142,8 +141,6 @@ being run by adding a new JAR or a directory to the classpath from the
`Script` menu
* Error hyperlinking from the output area when a compilation error is
expected or when an exception is thrown
-* You can enable InvokeDynamic (Indy) compilation mode by selecting
-`Enable Indy Compilation` from the `Script` menu
[[GroovyConsole-EmbeddingtheConsole]]
== Embedding the Console
diff --git a/subprojects/groovy-console/src/test/groovy/groovy/console/SwingBuilderConsoleTest.groovy b/subprojects/groovy-console/src/test/groovy/groovy/console/SwingBuilderConsoleTest.groovy
index 6e4be7b..6d57206 100644
--- a/subprojects/groovy-console/src/test/groovy/groovy/console/SwingBuilderConsoleTest.groovy
+++ b/subprojects/groovy-console/src/test/groovy/groovy/console/SwingBuilderConsoleTest.groovy
@@ -25,14 +25,13 @@ import groovy.console.ui.view.MacOSXMenuBar
import groovy.swing.GroovySwingTestCase
import groovy.swing.SwingBuilder
import org.codehaus.groovy.control.CompilerConfiguration
-
-import javax.swing.JTextPane
-import java.awt.event.ActionEvent
-import java.util.prefs.Preferences
import org.junit.rules.TemporaryFolder
+import javax.swing.JTextPane
import javax.swing.SwingUtilities
import java.awt.Color
+import java.awt.event.ActionEvent
+import java.util.prefs.Preferences
class SwingBuilderConsoleTest extends GroovySwingTestCase {
@@ -591,21 +590,13 @@ class SwingBuilderConsoleTest extends GroovySwingTestCase {
def outputDocument = console.outputArea.document
console.inputEditor.textEditor.text = scriptSource
- console.indy(new EventObject([selected: true]))
- assert console.prefs.getBoolean('indy', false)
- assert console.frame.title == 'GroovyConsole (Indy)'
-
console.runScript(new EventObject([:]))
assert console.config.getOptimizationOptions().get(CompilerConfiguration.INVOKEDYNAMIC)
assert outputDocument.getText(0, outputDocument.length) == 'Result: foobar'
- console.indy(new EventObject([selected: false]))
- assert !console.prefs.getBoolean('indy', true)
- assert console.frame.title == 'GroovyConsole'
-
console.outputArea.text = ''
console.runScript(new EventObject([:]))
- assert !console.config.getOptimizationOptions().get(CompilerConfiguration.INVOKEDYNAMIC)
+ assert console.config.getOptimizationOptions().get(CompilerConfiguration.INVOKEDYNAMIC)
assert outputDocument.getText(0, outputDocument.length) == 'Result: foobar'
} finally {
GroovySystem.metaClassRegistry.removeMetaClass(Thread)
diff --git a/subprojects/groovy-console/src/test/groovy/groovy/console/ui/ScriptToTreeNodeAdapterTest.groovy b/subprojects/groovy-console/src/test/groovy/groovy/console/ui/ScriptToTreeNodeAdapterTest.groovy
index 7653a81..538d974 100644
--- a/subprojects/groovy-console/src/test/groovy/groovy/console/ui/ScriptToTreeNodeAdapterTest.groovy
+++ b/subprojects/groovy-console/src/test/groovy/groovy/console/ui/ScriptToTreeNodeAdapterTest.groovy
@@ -611,7 +611,7 @@ class ScriptToTreeNodeAdapterTest extends GroovyTestCase {
void test() {}
}
- ''', Phases.CLASS_GENERATION, true) as TreeNode
+ ''', Phases.CLASS_GENERATION) as TreeNode
def classNodeTest = root.children().find { it.toString() == 'ClassNode - Test' }
def methods = classNodeTest.children().find { it.toString() == 'Methods' }