You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2019/06/01 13:11:24 UTC
[groovy] branch master updated (54754a5 -> 24f9442)
This is an automated email from the ASF dual-hosted git repository.
paulk pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git.
from 54754a5 slightly improved label on button
new 1a562d2 GROOVY-9156: The metaDataMap table of values should scale with the outer frame
new efe8797 provide getText for AnnotationNode
new 24f9442 display annotations within methods
The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../org/codehaus/groovy/ast/AnnotationNode.java | 17 ++++
.../groovy/groovy/console/ui/AstBrowser.groovy | 7 +-
.../console/ui/ScriptToTreeNodeAdapter.groovy | 98 ++++++++++++----------
3 files changed, 74 insertions(+), 48 deletions(-)
[groovy] 02/03: provide getText for AnnotationNode
Posted by pa...@apache.org.
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
commit efe87975c42dfdde3ebb5f0ffa32e82d7b93e4a8
Author: Paul King <pa...@asert.com.au>
AuthorDate: Sat Jun 1 22:56:22 2019 +1000
provide getText for AnnotationNode
---
.../java/org/codehaus/groovy/ast/AnnotationNode.java | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/src/main/java/org/codehaus/groovy/ast/AnnotationNode.java b/src/main/java/org/codehaus/groovy/ast/AnnotationNode.java
index 55543da..3795d66 100644
--- a/src/main/java/org/codehaus/groovy/ast/AnnotationNode.java
+++ b/src/main/java/org/codehaus/groovy/ast/AnnotationNode.java
@@ -191,4 +191,21 @@ public class AnnotationNode extends ASTNode {
return "unknown target";
}
}
+
+ @Override
+ public String getText() {
+ String memberText = "";
+ if (members != null) {
+ boolean first = true;
+ for (Map.Entry<String, Expression> next : members.entrySet()) {
+ if (first) {
+ first = false;
+ } else {
+ memberText += ", ";
+ }
+ memberText += next.getKey() + ": " + next.getValue().getText();
+ }
+ }
+ return "@" + classNode.getText() + "(" + memberText + ")";
+ }
}
[groovy] 01/03: GROOVY-9156: The metaDataMap table of values should
scale with the outer frame
Posted by pa...@apache.org.
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
commit 1a562d2804305168613b3f06a356bdf73267ba84
Author: Paul King <pa...@asert.com.au>
AuthorDate: Sat Jun 1 16:21:24 2019 +1000
GROOVY-9156: The metaDataMap table of values should scale with the outer frame
---
.../src/main/groovy/groovy/console/ui/AstBrowser.groovy | 7 +++++--
1 file changed, 5 insertions(+), 2 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 dc97c67..e2ac575 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
@@ -43,6 +43,7 @@ import javax.swing.tree.DefaultMutableTreeNode
import javax.swing.tree.DefaultTreeModel
import javax.swing.tree.TreeNode
import javax.swing.tree.TreeSelectionModel
+import java.awt.BorderLayout
import java.awt.Cursor
import java.awt.Font
import java.awt.event.KeyEvent
@@ -245,8 +246,10 @@ class AstBrowser {
String title = titleSuffix ? propList[0] + " (" + titleSuffix + ")" : propList[0]
def props = swing.frame(title: title, defaultCloseOperation: JFrame.DISPOSE_ON_CLOSE,
show: true, locationRelativeTo: null) {
- lookAndFeel("system")
- panel {
+ lookAndFeel 'system'
+ borderLayout(vgap: 5)
+ panel(constraints: BorderLayout.CENTER) {
+ borderLayout()
scrollPane {
mapTable = swing.table {
tableModel(list: [[:]]) {
[groovy] 03/03: display annotations within methods
Posted by pa...@apache.org.
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
commit 24f94426bfdd8eccad76f8a02de5776dc633e07f
Author: Paul King <pa...@asert.com.au>
AuthorDate: Sat Jun 1 23:11:10 2019 +1000
display annotations within methods
---
.../console/ui/ScriptToTreeNodeAdapter.groovy | 98 ++++++++++++----------
1 file changed, 52 insertions(+), 46 deletions(-)
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 d458ead..1ea7e99 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
@@ -24,6 +24,7 @@ import groovy.transform.CompileStatic
import groovy.transform.PackageScope
import org.apache.groovy.io.StringBuilderWriter
import org.codehaus.groovy.GroovyBugError
+import org.codehaus.groovy.ast.AnnotatedNode
import org.codehaus.groovy.ast.AnnotationNode
import org.codehaus.groovy.ast.ClassHelper
import org.codehaus.groovy.ast.ClassNode
@@ -124,14 +125,14 @@ class ScriptToTreeNodeAdapter {
static {
try {
- URL url = ClassLoader.getSystemResource('groovy/inspect/swingui/AstBrowserProperties.groovy')
+ URL url = ClassLoader.getSystemResource('groovy/console/ui/AstBrowserProperties.groovy')
if (!url) {
- url = ScriptToTreeNodeAdapter.class.classLoader.getResource('groovy/inspect/swingui/AstBrowserProperties.groovy')
+ url = ScriptToTreeNodeAdapter.class.classLoader.getResource('groovy/console/ui/AstBrowserProperties.groovy')
}
-
+
def config = new ConfigSlurper().parse(url)
classNameToStringForm = config.toProperties()
-
+
String home = System.getProperty('user.home')
if (home) {
File userFile = new File(home + File.separator + '.groovy/AstBrowserProperties.groovy')
@@ -144,10 +145,10 @@ class ScriptToTreeNodeAdapter {
} catch(ex) {
// on restricted environments like, such calls may fail, but that should not prevent the class
// from being loaded. Tree nodes can still get rendered with their simple names.
- classNameToStringForm = new Properties()
+ classNameToStringForm = new Properties()
}
}
-
+
ScriptToTreeNodeAdapter(classLoader, showScriptFreeForm, showScriptClass, showClosureClasses, nodeMaker, config = null) {
this.classLoader = classLoader ?: new GroovyClassLoader(getClass().classLoader)
this.showScriptFreeForm = showScriptFreeForm
@@ -158,7 +159,7 @@ class ScriptToTreeNodeAdapter {
}
/**
- * Performs the conversion from script to TreeNode.
+ * Performs the conversion from script to TreeNode.
*
* @param script
* a Groovy script in String form
@@ -166,7 +167,7 @@ class ScriptToTreeNodeAdapter {
* 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 scriptName = 'script' + System.currentTimeMillis() + '.groovy'
GroovyCodeSource codeSource = new GroovyCodeSource(script, scriptName, '/groovy/script')
@@ -222,29 +223,29 @@ class ScriptToTreeNodeAdapter {
*/
private List<List<String>> getPropertyTable(node) {
node.metaClass.properties?.
- findAll { it.getter }?.
- collect {
- def name = it.name.toString()
- def value
- try {
- // multiple assignment statements cannot be cast to VariableExpression so
- // instead reference the value through the leftExpression property, which is the same
- if (node instanceof DeclarationExpression &&
- (name == 'variableExpression' || name == 'tupleExpression')) {
- value = toString(node.leftExpression)
- } else {
- value = toString(it.getProperty(node))
+ findAll { it.getter }?.
+ collect {
+ def name = it.name.toString()
+ def value
+ try {
+ // multiple assignment statements cannot be cast to VariableExpression so
+ // instead reference the value through the leftExpression property, which is the same
+ if (node instanceof DeclarationExpression &&
+ (name == 'variableExpression' || name == 'tupleExpression')) {
+ value = toString(node.leftExpression)
+ } else {
+ value = toString(it.getProperty(node))
+ }
+ } catch (GroovyBugError reflectionArtefact) {
+ // compiler throws error if it thinks a field is being accessed
+ // before it is set under certain conditions. It wasn't designed
+ // to be walked reflectively like this.
+ value = null
}
- } catch (GroovyBugError reflectionArtefact) {
- // compiler throws error if it thinks a field is being accessed
- // before it is set under certain conditions. It wasn't designed
- // to be walked reflectively like this.
- value = null
- }
- def type = it.type.simpleName.toString()
- [name, value, type]
- }?.
- sort { it[0] }
+ def type = it.type.simpleName.toString()
+ [name, value, type]
+ }?.
+ sort { it[0] }
}
// GROOVY-8339: to avoid illegal access to a non-visible implementation class - can be removed if a more general solution is found
@@ -350,12 +351,14 @@ class TreeNodeBuildingNodeOperation extends PrimaryClassNodeOperation {
}
}
- private void collectAnnotationData(parent, String name, ClassNode classNode) {
+ private void collectAnnotationData(parent, String name, AnnotatedNode node) {
def allAnnotations = nodeMaker.makeNode(name)
- if (classNode.annotations) parent.add(allAnnotations)
- classNode.annotations?.each {AnnotationNode annotationNode ->
- def ggrandchild = adapter.make(annotationNode)
- allAnnotations.add(ggrandchild)
+ if (node.annotations) {
+ parent.add(allAnnotations)
+ node.annotations?.each {AnnotationNode annotationNode ->
+ def ggrandchild = adapter.make(annotationNode)
+ allAnnotations.add(ggrandchild)
+ }
}
}
@@ -401,12 +404,12 @@ class TreeNodeBuildingNodeOperation extends PrimaryClassNodeOperation {
doCollectMethodData(allMethods, methods)
}
-
+
private void doCollectMethodData(allMethods, List methods) {
methods?.each {MethodNode methodNode ->
def ggrandchild = adapter.make(methodNode)
allMethods.add(ggrandchild)
-
+
// print out parameters of method
methodNode.parameters?.each {Parameter parameter ->
def gggrandchild = adapter.make(parameter)
@@ -416,14 +419,16 @@ class TreeNodeBuildingNodeOperation extends PrimaryClassNodeOperation {
parameter.initialExpression.visit(visitor)
if (visitor.currentNode) gggrandchild.add(visitor.currentNode)
}
+ collectAnnotationData(gggrandchild, 'Annotations', parameter)
}
-
+
// print out code of method
TreeNodeBuildingVisitor visitor = new TreeNodeBuildingVisitor(adapter)
if (methodNode.code) {
methodNode.code.visit(visitor)
if (visitor.currentNode) ggrandchild.add(visitor.currentNode)
}
+ collectAnnotationData(ggrandchild, 'Annotations', methodNode)
}
}
@@ -439,6 +444,7 @@ class TreeNodeBuildingNodeOperation extends PrimaryClassNodeOperation {
ctorNode.code.visit(visitor)
if (visitor.currentNode) ggrandchild.add(visitor.currentNode)
}
+ collectAnnotationData(ggrandchild, 'Annotations', ctorNode)
}
}
@@ -462,8 +468,8 @@ class TreeNodeBuildingNodeOperation extends PrimaryClassNodeOperation {
}
/**
-* This AST visitor builds up a TreeNode.
-*/
+ * This AST visitor builds up a TreeNode.
+ */
@PackageScope
class TreeNodeBuildingVisitor extends CodeVisitorSupport {
@@ -480,12 +486,12 @@ class TreeNodeBuildingVisitor extends CodeVisitorSupport {
}
/**
- * This method looks at the AST node and decides how to represent it in a TreeNode, then it
+ * This method looks at the AST node and decides how to represent it in a TreeNode, then it
* continues walking the tree. If the node and the expectedSubclass are not exactly the same
* Class object then the node is not added to the tree. This is to eliminate seeing duplicate
* nodes, for instance seeing an ArgumentListExpression and a TupleExpression in the tree, when
* an ArgumentList is-a Tuple.
- */
+ */
private void addNode(node, Class expectedSubclass, Closure superMethod) {
if (expectedSubclass.getName() == node.getClass().getName()) {
@@ -640,7 +646,7 @@ class TreeNodeBuildingVisitor extends CodeVisitorSupport {
@Override
void visitClosureExpression(ClosureExpression node) {
- addNode(node, ClosureExpression, {
+ addNode(node, ClosureExpression, {
it.parameters?.each { parameter -> visitParameter(parameter) }
super.visitClosureExpression(it)
})
@@ -786,9 +792,9 @@ class TreeNodeBuildingVisitor extends CodeVisitorSupport {
@Override
void visitCatchStatement(CatchStatement node) {
- addNode(node, CatchStatement, {
- if (it.variable) visitParameter(it.variable)
- super.visitCatchStatement(it)
+ addNode(node, CatchStatement, {
+ if (it.variable) visitParameter(it.variable)
+ super.visitCatchStatement(it)
})
}