author | vranyj1 |
Tue, 21 Aug 2012 17:54:21 +0000 | |
branch | jk_new_structure |
changeset 1639 | 1397423bcd97 |
parent 1626 | 715cd7e0e518 |
child 1649 | 0af82006c0b2 |
permissions | -rw-r--r-- |
917 | 1 |
" |
2 |
COPYRIGHT (c) 1996-2011 by Claus Gittinger |
|
1152 | 3 |
|
1155 | 4 |
New code and modifications done at SWING Research Group [1]: |
1152 | 5 |
|
917 | 6 |
COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko |
7 |
SWING Research Group, Czech Technical University in Prague |
|
8 |
||
9 |
This software is furnished under a license and may be used |
|
10 |
only in accordance with the terms of that license and with the |
|
11 |
inclusion of the above copyright notice. This software may not |
|
12 |
be provided or otherwise made available to, or used by, any |
|
13 |
other person. No title to or ownership of the software is |
|
14 |
hereby transferred. |
|
15 |
||
1155 | 16 |
[1] Code written at SWING Research Group contains a signature |
17 |
of one of the above copright owners. For exact set of such code, |
|
18 |
see the differences between this version and version stx:libjava |
|
1152 | 19 |
as of 1.9.2010 |
917 | 20 |
" |
21 |
"{ Package: 'stx:libjava' }" |
|
22 |
||
1370 | 23 |
Object subclass:#GroovyEvaluator |
1639 | 24 |
instanceVariableNames:'requestor source' |
1044
84b7d94d9eb8
Java Workspace now share same binding (i.e., workspace variables are remembered)
vranyj1
parents:
1033
diff
changeset
|
25 |
classVariableNames:'WorkspaceBinding' |
917 | 26 |
poolDictionaries:'' |
27 |
category:'Languages-Java-Support' |
|
28 |
! |
|
29 |
||
1370 | 30 |
!GroovyEvaluator class methodsFor:'documentation'! |
917 | 31 |
|
32 |
copyright |
|
33 |
" |
|
34 |
COPYRIGHT (c) 1996-2011 by Claus Gittinger |
|
1152 | 35 |
|
1155 | 36 |
New code and modifications done at SWING Research Group [1]: |
1152 | 37 |
|
917 | 38 |
COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko |
39 |
SWING Research Group, Czech Technical University in Prague |
|
40 |
||
41 |
This software is furnished under a license and may be used |
|
42 |
only in accordance with the terms of that license and with the |
|
43 |
inclusion of the above copyright notice. This software may not |
|
44 |
be provided or otherwise made available to, or used by, any |
|
45 |
other person. No title to or ownership of the software is |
|
46 |
hereby transferred. |
|
47 |
||
1155 | 48 |
[1] Code written at SWING Research Group contains a signature |
49 |
of one of the above copright owners. For exact set of such code, |
|
50 |
see the differences between this version and version stx:libjava |
|
1152 | 51 |
as of 1.9.2010 |
917 | 52 |
|
53 |
" |
|
54 |
! ! |
|
55 |
||
1478 | 56 |
!GroovyEvaluator class methodsFor:'* As yet uncategorized *'! |
57 |
||
58 |
evaluate: source in: context receiver: receiver notifying: requestor logged: log ifFail: failblock |
|
59 |
^self new evaluate: source in: context receiver: receiver notifying: requestor logged: log ifFail: failblock |
|
60 |
||
61 |
"Created: / 13-04-2012 / 17:24:05 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
62 |
! ! |
|
63 |
||
1370 | 64 |
!GroovyEvaluator class methodsFor:'utilities'! |
1204 | 65 |
|
66 |
flushWorkspaceBinding |
|
67 |
||
68 |
WorkspaceBinding := nil |
|
69 |
||
70 |
"Created: / 02-12-2011 / 23:23:48 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
71 |
! ! |
|
72 |
||
1581
70fbc03d2d82
Java reflection support refactoring - moved to use JavaMirrors
vranyj1
parents:
1478
diff
changeset
|
73 |
!GroovyEvaluator methodsFor:'accessing'! |
1459 | 74 |
|
1581
70fbc03d2d82
Java reflection support refactoring - moved to use JavaMirrors
vranyj1
parents:
1478
diff
changeset
|
75 |
currentNameSpace: ns |
1459 | 76 |
ns notNil ifTrue:[ |
77 |
self error:'Smalltalk namespaces not supported by Groovy' |
|
78 |
]. |
|
79 |
||
1581
70fbc03d2d82
Java reflection support refactoring - moved to use JavaMirrors
vranyj1
parents:
1478
diff
changeset
|
80 |
"Created: / 01-08-2012 / 11:18:05 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
70fbc03d2d82
Java reflection support refactoring - moved to use JavaMirrors
vranyj1
parents:
1478
diff
changeset
|
81 |
! |
70fbc03d2d82
Java reflection support refactoring - moved to use JavaMirrors
vranyj1
parents:
1478
diff
changeset
|
82 |
|
70fbc03d2d82
Java reflection support refactoring - moved to use JavaMirrors
vranyj1
parents:
1478
diff
changeset
|
83 |
currentNamespace: ns |
70fbc03d2d82
Java reflection support refactoring - moved to use JavaMirrors
vranyj1
parents:
1478
diff
changeset
|
84 |
self currentNameSpace: ns |
70fbc03d2d82
Java reflection support refactoring - moved to use JavaMirrors
vranyj1
parents:
1478
diff
changeset
|
85 |
|
1459 | 86 |
"Created: / 07-04-2012 / 09:26:39 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
87 |
! ! |
|
88 |
||
1370 | 89 |
!GroovyEvaluator methodsFor:'compiler interface'! |
917 | 90 |
|
971 | 91 |
evaluate:source |
92 |
||
93 |
^self evaluate:source in: nil receiver: nil notifying: nil logged: false ifFail: [self error:'Evaluation failed']. |
|
94 |
||
95 |
"Created: / 02-09-2011 / 10:24:46 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
96 |
! |
|
97 |
||
1639 | 98 |
evaluate: sourceObj in: context receiver: receiver notifying: requestorObj logged: logged ifFail: fail |
99 |
| binding result wsForWorkspace | |
|
918 | 100 |
|
1033 | 101 |
JavaVM booted ifFalse: [ |
959 | 102 |
Java initialize. |
103 |
JavaVM initializeVM. |
|
104 |
]. |
|
1639 | 105 |
|
106 |
requestor := requestorObj. |
|
107 |
source := sourceObj. |
|
108 |
wsForWorkspace := requestor notNil and: [ requestor application isKindOf: WorkspaceApplication ]. |
|
109 |
binding := (Java classForName: 'groovy.lang.Binding') new. |
|
110 |
||
111 |
wsForWorkspace ifTrue: [ |
|
1044
84b7d94d9eb8
Java Workspace now share same binding (i.e., workspace variables are remembered)
vranyj1
parents:
1033
diff
changeset
|
112 |
WorkspaceBinding isNil ifTrue: [ |
84b7d94d9eb8
Java Workspace now share same binding (i.e., workspace variables are remembered)
vranyj1
parents:
1033
diff
changeset
|
113 |
WorkspaceBinding := (JavaVM classForName: 'groovy.lang.Binding') new. |
84b7d94d9eb8
Java Workspace now share same binding (i.e., workspace variables are remembered)
vranyj1
parents:
1033
diff
changeset
|
114 |
]. |
84b7d94d9eb8
Java Workspace now share same binding (i.e., workspace variables are remembered)
vranyj1
parents:
1033
diff
changeset
|
115 |
binding := WorkspaceBinding |
84b7d94d9eb8
Java Workspace now share same binding (i.e., workspace variables are remembered)
vranyj1
parents:
1033
diff
changeset
|
116 |
] ifFalse: [ |
1639 | 117 |
|
1612 | 118 |
binding setVariable: 'this' to: receiver. |
119 |
binding setVariable: 'self' to: receiver. |
|
120 |
context notNil ifTrue:[ |
|
1626 | 121 |
| pc | |
122 |
||
1612 | 123 |
binding setVariable: 'thisContext' to: context. |
1626 | 124 |
pc := context pc. |
125 |
context method localVariableTable do:[:entry| |
|
126 |
(pc between: entry startPC and: entry endPC) ifTrue:[ |
|
127 |
binding setVariable: entry name to: (context at: entry slot + 1) |
|
128 |
]. |
|
129 |
]. |
|
1612 | 130 |
] |
131 |
||
1044
84b7d94d9eb8
Java Workspace now share same binding (i.e., workspace variables are remembered)
vranyj1
parents:
1033
diff
changeset
|
132 |
]. |
84b7d94d9eb8
Java Workspace now share same binding (i.e., workspace variables are remembered)
vranyj1
parents:
1033
diff
changeset
|
133 |
|
1639 | 134 |
result := self evaluate: source withBinding: binding. |
135 |
^ result class javaUnwrap: result. |
|
918 | 136 |
|
137 |
"Created: / 17-08-2011 / 08:54:23 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
138 |
! |
|
139 |
||
1639 | 140 |
evaluate: source withBinding: binding |
141 |
"Given a binding, evaluates given a code" |
|
142 |
||
143 |
| shell result | |
|
144 |
||
145 |
[ |
|
146 |
shell := (Java classForName: 'groovy.lang.GroovyShell') newCleared. |
|
147 |
shell perform: #'<init>(Lgroovy/lang/Binding;)V' with: binding. |
|
148 |
result := shell |
|
149 |
perform: #'evaluate(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/Object;' |
|
150 |
with: (Java as_String: source string) |
|
151 |
with: (Java as_String: 'doIt') |
|
152 |
] on: JAVA org codehaus groovy control CompilationFailedException do:[:ex| |
|
153 |
self syntaxError: ex. |
|
154 |
]. |
|
155 |
||
156 |
^ result class javaUnwrap: result. |
|
157 |
||
158 |
"Created: / 21-08-2012 / 14:08:06 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
159 |
! |
|
160 |
||
917 | 161 |
moreSharedPools: pools |
162 |
||
163 |
"Ignored for Java" |
|
164 |
||
165 |
"Created: / 16-08-2011 / 10:15:18 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
166 |
! ! |
|
167 |
||
1639 | 168 |
!GroovyEvaluator methodsFor:'error reporting'! |
169 |
||
170 |
syntaxError: exception |
|
171 |
| error cause | |
|
1202
7d9f24940ed5
- JavaVM: fix in method/ctor invocation using reflection
vranyj1
parents:
1155
diff
changeset
|
172 |
|
1639 | 173 |
error := exception getErrorCollector getError: 0. |
174 |
cause := error getCause. |
|
175 |
self syntaxError: exception cause: cause. |
|
1202
7d9f24940ed5
- JavaVM: fix in method/ctor invocation using reflection
vranyj1
parents:
1155
diff
changeset
|
176 |
|
1639 | 177 |
"Created: / 21-08-2012 / 14:17:41 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
178 |
! |
|
1202
7d9f24940ed5
- JavaVM: fix in method/ctor invocation using reflection
vranyj1
parents:
1155
diff
changeset
|
179 |
|
1639 | 180 |
syntaxError:message atLine: line from: startCol to:endCol |
181 |
"Notify requestor of an error - if there is no requestor |
|
182 |
put it on the transcript. Requestor is typically the CodeView |
|
183 |
in which the accept/doIt was triggered, or the PositionableStream |
|
184 |
which does the fileIn. The requestor may decide how to highlight the |
|
185 |
error (and/or to abort the compile). |
|
186 |
Return the result passed back by the requestor." |
|
187 |
||
188 |
(Smalltalk isInitialized not and:[Smalltalk isStandAloneDebug]) ifTrue:[ |
|
189 |
"/ error during startup, but sometimes we expect an error and want to supress it |
|
190 |
Parser parseWarningSignal query ~~ #ignore ifTrue:[ |
|
191 |
thisContext fullPrintAll. |
|
192 |
]. |
|
1202
7d9f24940ed5
- JavaVM: fix in method/ctor invocation using reflection
vranyj1
parents:
1155
diff
changeset
|
193 |
]. |
7d9f24940ed5
- JavaVM: fix in method/ctor invocation using reflection
vranyj1
parents:
1155
diff
changeset
|
194 |
|
1639 | 195 |
|
196 |
"/ backward compatibility - will vanish eventually (use a handler, Luke) |
|
197 |
(requestor notNil and:[requestor isTextView]) ifTrue:[ |
|
198 |
| sourceStream lineStart | |
|
199 |
sourceStream := source string readStream. |
|
200 |
line - 1 timesRepeat:[ sourceStream nextLine ]. |
|
201 |
lineStart := sourceStream position - 1. |
|
202 |
||
203 |
||
204 |
requestor error:message position: lineStart + startCol to: lineStart + endCol from: self. |
|
205 |
^ self |
|
206 |
]. |
|
207 |
Parser::ParseError isHandled ifTrue:[ |
|
208 |
Parser::ParseError new |
|
209 |
errorMessage:message startPosition:startCol endPosition:endCol; |
|
210 |
parameter:self; |
|
211 |
lineNumber:line; |
|
212 |
raiseRequest. |
|
213 |
]. |
|
214 |
||
215 |
"Created: / 21-08-2012 / 16:57:33 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
216 |
! |
|
217 |
||
218 |
syntaxError:message cause: cause |
|
219 |
"Notify requestor of an error - if there is no requestor |
|
220 |
put it on the transcript. Requestor is typically the CodeView |
|
221 |
in which the accept/doIt was triggered, or the PositionableStream |
|
222 |
which does the fileIn. The requestor may decide how to highlight the |
|
223 |
error (and/or to abort the compile). |
|
224 |
Return the result passed back by the requestor." |
|
1202
7d9f24940ed5
- JavaVM: fix in method/ctor invocation using reflection
vranyj1
parents:
1155
diff
changeset
|
225 |
|
1639 | 226 |
| sourceStream startCol endCol | |
227 |
||
228 |
(Smalltalk isInitialized not and:[Smalltalk isStandAloneDebug]) ifTrue:[ |
|
229 |
"/ error during startup, but sometimes we expect an error and want to supress it |
|
230 |
Parser parseWarningSignal query ~~ #ignore ifTrue:[ |
|
231 |
thisContext fullPrintAll. |
|
232 |
]. |
|
233 |
]. |
|
234 |
||
235 |
||
236 |
"/ backward compatibility - will vanish eventually (use a handler, Luke) |
|
237 |
||
238 |
sourceStream := source string readStream. |
|
239 |
cause getLine - 1 timesRepeat:[ sourceStream nextLine ]. |
|
240 |
startCol := sourceStream position - 1 + cause getStartColumn. |
|
241 |
endCol := sourceStream position - 1 + cause getEndColumn. |
|
242 |
||
243 |
(requestor notNil and:[requestor isTextView]) ifTrue:[ |
|
244 |
requestor error: cause getOriginalMessage position: startCol to: endCol from: self. |
|
245 |
^ self |
|
246 |
]. |
|
247 |
Parser::ParseError isHandled ifTrue:[ |
|
248 |
Parser::ParseError new |
|
249 |
errorMessage: cause getOriginalMessage startPosition:startCol endPosition:endCol; |
|
250 |
parameter:self; |
|
251 |
lineNumber:cause getLine; |
|
252 |
raiseRequest. |
|
253 |
]. |
|
254 |
||
255 |
"Created: / 21-08-2012 / 17:10:11 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1202
7d9f24940ed5
- JavaVM: fix in method/ctor invocation using reflection
vranyj1
parents:
1155
diff
changeset
|
256 |
! ! |
7d9f24940ed5
- JavaVM: fix in method/ctor invocation using reflection
vranyj1
parents:
1155
diff
changeset
|
257 |
|
1370 | 258 |
!GroovyEvaluator class methodsFor:'documentation'! |
917 | 259 |
|
260 |
version_SVN |
|
261 |
^ '$Id$' |
|
262 |
! ! |