--- a/GroovyEvaluator.st Fri Aug 16 19:52:36 2013 +0200
+++ b/GroovyEvaluator.st Fri Sep 06 02:45:44 2013 +0200
@@ -22,7 +22,7 @@
Object subclass:#GroovyEvaluator
instanceVariableNames:'requestor source'
- classVariableNames:'WorkspaceBinding'
+ classVariableNames:'WorkspaceShell'
poolDictionaries:''
category:'Languages-Groovy-Compiler'
!
@@ -61,6 +61,13 @@
"Created: / 13-04-2012 / 17:24:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
+!GroovyEvaluator class methodsFor:'others'!
+
+version_HG
+
+ ^ '$Changeset: <not expanded> $'
+! !
+
!GroovyEvaluator class methodsFor:'utilities'!
flushWorkspaceBinding
@@ -68,6 +75,13 @@
WorkspaceBinding := nil
"Created: / 02-12-2011 / 23:23:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+flushWorkspaceShell
+
+ WorkspaceShell := nil
+
+ "Created: / 02-09-2013 / 01:00:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!GroovyEvaluator methodsFor:'accessing'!
@@ -98,7 +112,7 @@
!
evaluate: sourceObj in: context receiver: receiver notifying: requestorObj logged: logged ifFail: fail
- | binding result wsForWorkspace |
+ | shell binding result wsForWorkspace class |
JavaVM booted ifFalse: [
Java initialize.
@@ -108,15 +122,14 @@
requestor := requestorObj.
source := sourceObj.
wsForWorkspace := requestor notNil and: [ requestor application isKindOf: WorkspaceApplication ].
- binding := (Java classForName: 'groovy.lang.Binding') new.
wsForWorkspace ifTrue: [
- WorkspaceBinding isNil ifTrue: [
- WorkspaceBinding := (JavaVM classForName: 'groovy.lang.Binding') new.
+ WorkspaceShell isNil ifTrue: [
+ WorkspaceShell := JAVA stx libjava groovy GroovyShell new.
].
- binding := WorkspaceBinding
+ shell:= WorkspaceShell.
] ifFalse: [
-
+ binding := (JavaVM classForName: 'groovy.lang.Binding') new.
binding setVariable: 'this' to: receiver.
binding setVariable: 'self' to: receiver.
context notNil ifTrue:[
@@ -129,35 +142,25 @@
binding setVariable: entry name to: (context at: entry slot + 1)
].
].
+ ].
+ shell := JAVA stx libjava groovy GroovyShell new: binding.
+ class := receiver class theNonMetaclass.
+ class isJavaClass ifTrue:[
+ "/ Import all classes used by the receriver's class.
+ class constantPool do:[:each|
+ (each isJavaRef and:[each isJavaClassRef]) ifTrue:[
+ shell addClassImport: each javaClassName asDottedJavaClassName.
+ ]
+ ]
]
].
- result := self evaluate: source withBinding: binding.
+ result := self evaluate: source shell: shell.
^ result class javaUnwrap: result.
"Created: / 17-08-2011 / 08:54:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-evaluate: source withBinding: binding
- "Given a binding, evaluates given a code"
-
- | shell result |
-
- [
- shell := (Java classForName: 'groovy.lang.GroovyShell') newCleared.
- shell perform: #'<init>(Lgroovy/lang/Binding;)V' with: binding.
- result := shell
- perform: #'evaluate(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/Object;'
- with: (Java as_String: source string)
- with: (Java as_String: 'doIt')
- ] on: JAVA org codehaus groovy control CompilationFailedException do:[:ex|
- self syntaxError: ex.
- ].
-
- ^ result class javaUnwrap: result.
-
- "Created: / 21-08-2012 / 14:08:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 30-08-2013 / 00:45:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
moreSharedPools: pools
@@ -167,6 +170,28 @@
"Created: / 16-08-2011 / 10:15:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
+!GroovyEvaluator methodsFor:'compiler interface-private'!
+
+evaluate: src shell: shell
+ "Given a binding, evaluates given a code"
+
+ | result |
+
+ [
+ result := shell
+ perform: #'evaluate(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/Object;'
+ with: (Java as_String: src string)
+ with: (Java as_String: '$do$It$')
+ ] on: JAVA org codehaus groovy control CompilationFailedException do:[:ex|
+ self syntaxError: ex.
+ ].
+
+ ^ result class javaUnwrap: result.
+
+ "Created: / 24-08-2013 / 13:48:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 29-08-2013 / 00:37:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
!GroovyEvaluator methodsFor:'error reporting'!
syntaxError: exception
@@ -221,12 +246,7 @@
!GroovyEvaluator class methodsFor:'documentation'!
version_CVS
- ^ '$Header: /cvs/stx/stx/libjava/GroovyEvaluator.st,v 1.3 2013-04-11 09:10:13 stefan Exp $'
-!
-
-version_HG
-
- ^ '§Changeset: <not expanded> §'
+ ^ '$Header: /cvs/stx/stx/libjava/GroovyEvaluator.st,v 1.4 2013-09-06 00:41:08 vrany Exp $'
!
version_SVN