subprojects (accidently added) removed....
"
COPYRIGHT (c) 1996-2011 by Claus Gittinger
New code and modifications done at SWING Research Group [1]:
COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
SWING Research Group, Czech Technical University in Prague
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
[1] Code written at SWING Research Group contains a signature
of one of the above copright owners. For exact set of such code,
see the differences between this version and version stx:libjava
as of 1.9.2010
"
"{ Package: 'stx:libjava' }"
Object subclass:#GroovyEvaluator
instanceVariableNames:'requestor source'
classVariableNames:'WorkspaceShell'
poolDictionaries:''
category:'Languages-Groovy-Compiler'
!
!GroovyEvaluator class methodsFor:'documentation'!
copyright
"
COPYRIGHT (c) 1996-2011 by Claus Gittinger
New code and modifications done at SWING Research Group [1]:
COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
SWING Research Group, Czech Technical University in Prague
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
[1] Code written at SWING Research Group contains a signature
of one of the above copright owners. For exact set of such code,
see the differences between this version and version stx:libjava
as of 1.9.2010
"
! !
!GroovyEvaluator class methodsFor:'evaluating'!
evaluate: source in: context receiver: receiver notifying: requestor logged: log ifFail: failblock
^self new evaluate: source in: context receiver: receiver notifying: requestor logged: log ifFail: failblock
"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
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'!
currentNameSpace: ns
ns notNil ifTrue:[
self error:'Smalltalk namespaces not supported by Groovy'
].
"Created: / 01-08-2012 / 11:18:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
currentNamespace: ns
self currentNameSpace: ns
"Created: / 07-04-2012 / 09:26:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!GroovyEvaluator methodsFor:'compiler interface'!
evaluate:src
| result |
result := self evaluate:src in: nil receiver: nil notifying: nil logged: false ifFail: [self error:'Evaluation failed'].
^result.
"Created: / 02-09-2011 / 10:24:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
evaluate: sourceObj in: context receiver: receiver notifying: requestorObj logged: logged ifFail: fail
| shell binding result wsForWorkspace class |
JavaVM booted ifFalse: [
Java initialize.
JavaVM initializeVM.
].
requestor := requestorObj.
source := sourceObj.
wsForWorkspace := requestor notNil and: [ requestor application isKindOf: WorkspaceApplication ].
wsForWorkspace ifTrue: [
WorkspaceShell isNil ifTrue: [
WorkspaceShell := JAVA stx libjava groovy GroovyShell new.
].
shell:= WorkspaceShell.
] ifFalse: [
binding := (JavaVM classForName: 'groovy.lang.Binding') new.
binding setVariable: 'this' to: receiver.
binding setVariable: 'self' to: receiver.
context notNil ifTrue:[
| pc |
binding setVariable: 'thisContext' to: context.
pc := context pc.
context method localVariableTable do:[:entry|
(pc between: entry startPC and: entry endPC) ifTrue:[
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 shell: shell.
^ result class javaUnwrap: result.
"Created: / 17-08-2011 / 08:54:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
"Modified: / 30-08-2013 / 00:45:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
moreSharedPools: pools
"Ignored for Java"
"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
| error cause |
error := exception getErrorCollector getError: 0.
cause := error getCause.
self syntaxError: exception cause: cause.
"Created: / 21-08-2012 / 14:17:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
syntaxError:message cause: cause
"Notify requestor of an error - if there is no requestor
put it on the transcript. Requestor is typically the CodeView
in which the accept/doIt was triggered, or the PositionableStream
which does the fileIn. The requestor may decide how to highlight the
error (and/or to abort the compile).
Return the result passed back by the requestor."
| sourceStream startCol endCol |
(Smalltalk isInitialized not and:[Smalltalk isStandAloneDebug]) ifTrue:[
"/ error during startup, but sometimes we expect an error and want to supress it
(Smalltalk at:#Parser) parseWarningSignal query ~~ #ignore ifTrue:[
thisContext fullPrintAll.
].
].
"/ backward compatibility - will vanish eventually (use a handler, Luke)
sourceStream := source string readStream.
cause getLine - 1 timesRepeat:[ sourceStream nextLine ].
startCol := sourceStream position - 1 + cause getStartColumn.
endCol := sourceStream position - 1 + cause getEndColumn.
(requestor notNil and:[requestor isTextView]) ifTrue:[
requestor error: cause getOriginalMessage position: startCol to: endCol from: self.
^ self
].
ParseError isHandled ifTrue:[
ParseError new
errorMessage: cause getOriginalMessage startPosition:startCol endPosition:endCol;
parameter:self;
lineNumber:cause getLine;
raiseRequest.
].
"Created: / 21-08-2012 / 17:10:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!GroovyEvaluator class methodsFor:'documentation'!
version_CVS
^ '$Header: /cvs/stx/stx/libjava/GroovyEvaluator.st,v 1.4 2013-09-06 00:41:08 vrany Exp $'
!
version_SVN
^ '§Id§'
! !