author | vranyj1 |
Tue, 28 Feb 2012 12:57:53 +0000 | |
branch | jk_new_structure |
changeset 1388 | 71a9ff13de80 |
parent 1387 | 4c609318f0e5 |
child 1441 | 0faa0f8eda0c |
permissions | -rw-r--r-- |
1368 | 1 |
" |
2 |
COPYRIGHT (c) 1996-2011 by Claus Gittinger |
|
3 |
||
4 |
New code and modifications done at SWING Research Group [1]: |
|
5 |
||
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 |
||
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 |
|
19 |
as of 1.9.2010 |
|
20 |
" |
|
21 |
"{ Package: 'stx:libjava' }" |
|
22 |
||
23 |
Object subclass:#GroovyCompiler |
|
1387 | 24 |
instanceVariableNames:'requestor' |
1368 | 25 |
classVariableNames:'GroovyClassLoader' |
26 |
poolDictionaries:'' |
|
27 |
category:'Languages-Groovy-Compiler' |
|
28 |
! |
|
29 |
||
30 |
!GroovyCompiler class methodsFor:'documentation'! |
|
31 |
||
32 |
copyright |
|
33 |
" |
|
34 |
COPYRIGHT (c) 1996-2011 by Claus Gittinger |
|
35 |
||
36 |
New code and modifications done at SWING Research Group [1]: |
|
37 |
||
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 |
||
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 |
|
51 |
as of 1.9.2010 |
|
52 |
||
53 |
" |
|
54 |
! ! |
|
55 |
||
56 |
!GroovyCompiler class methodsFor:'initialization'! |
|
57 |
||
58 |
flushGroovyClassLoader |
|
59 |
||
60 |
GroovyClassLoader := nil |
|
61 |
||
62 |
"Created: / 18-02-2012 / 22:25:01 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
63 |
! ! |
|
64 |
||
65 |
!GroovyCompiler class methodsFor:'instance creation'! |
|
66 |
||
67 |
new |
|
68 |
"return an initialized instance" |
|
69 |
||
70 |
^ self basicNew initialize. |
|
71 |
! ! |
|
72 |
||
73 |
!GroovyCompiler class methodsFor:'compiler interface'! |
|
74 |
||
1388 | 75 |
compile: source |
76 |
"Compiles a new Groovy class given the source code" |
|
77 |
||
78 |
^self new compile: source. |
|
79 |
||
80 |
"Created: / 27-02-2012 / 23:27:54 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
81 |
! |
|
82 |
||
1372
dea574a1b6b3
Some initial class reloading support. Not yet finished, just sketched out.
vranyj1
parents:
1368
diff
changeset
|
83 |
compile: source forClass: class inCategory: category notifying: requestor install: doInstall |
dea574a1b6b3
Some initial class reloading support. Not yet finished, just sketched out.
vranyj1
parents:
1368
diff
changeset
|
84 |
|
dea574a1b6b3
Some initial class reloading support. Not yet finished, just sketched out.
vranyj1
parents:
1368
diff
changeset
|
85 |
"We allways compile whole class" |
dea574a1b6b3
Some initial class reloading support. Not yet finished, just sketched out.
vranyj1
parents:
1368
diff
changeset
|
86 |
|
1387 | 87 |
^self new |
88 |
requestor: requestor; |
|
1388 | 89 |
compile: source. |
1372
dea574a1b6b3
Some initial class reloading support. Not yet finished, just sketched out.
vranyj1
parents:
1368
diff
changeset
|
90 |
|
dea574a1b6b3
Some initial class reloading support. Not yet finished, just sketched out.
vranyj1
parents:
1368
diff
changeset
|
91 |
"Created: / 21-02-2012 / 11:10:57 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1368 | 92 |
! ! |
93 |
||
1387 | 94 |
!GroovyCompiler methodsFor:'accessing'! |
95 |
||
96 |
requestor |
|
97 |
^ requestor |
|
98 |
! |
|
99 |
||
100 |
requestor:something |
|
101 |
requestor := something. |
|
102 |
! ! |
|
103 |
||
1368 | 104 |
!GroovyCompiler methodsFor:'compiler interface'! |
105 |
||
1388 | 106 |
compile: source |
1368 | 107 |
"Compiles a new Groovy class given the source code" |
108 |
||
109 |
| jclass class | |
|
110 |
||
1387 | 111 |
[ |
112 |
jclass := GroovyClassLoader |
|
113 |
perform: #'parseClass(Ljava/lang/String;)Ljava/lang/Class;' |
|
114 |
with: (Java as_String: source). |
|
115 |
] on: JavaError do:[:jex| |
|
116 |
self handleException: jex. |
|
117 |
]. |
|
1368 | 118 |
jclass isNil ifTrue:[ ^ nil ]. |
119 |
||
120 |
class := JavaVM classForJavaClassObject: jclass. |
|
121 |
class setSource: source. |
|
122 |
^class. |
|
123 |
||
1388 | 124 |
"Created: / 27-02-2012 / 23:27:35 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1368 | 125 |
! ! |
126 |
||
1387 | 127 |
!GroovyCompiler methodsFor:'error reporting'! |
128 |
||
129 |
error: message line: line from: start to: end |
|
130 |
"notify requestor of an error - if there is no requestor |
|
131 |
put it on the transcript. Requestor is typically the CodeView |
|
132 |
in which the accept/doIt was triggered, or the PositionableStream |
|
133 |
which does the fileIn. The requestor may decide how to highlight the |
|
134 |
error (and/or to abort the compile). |
|
135 |
Return the result passed back by the requestor." |
|
136 |
||
137 |
|err| |
|
138 |
||
139 |
Smalltalk isInitialized ifFalse:[ |
|
140 |
Smalltalk isStandAloneDebug ifTrue:[ |
|
141 |
"/ error during startup |
|
142 |
thisContext fullPrintAll. |
|
143 |
] |
|
144 |
]. |
|
145 |
||
146 |
||
147 |
"/ backward compatibility - will vanish eventually (use a handler, Luke) |
|
148 |
requestor notNil ifTrue:[ |
|
149 |
requestor error:message position:start to:end from:self. |
|
150 |
^ self |
|
151 |
]. |
|
152 |
Parser::ParseError isHandled ifTrue:[ |
|
153 |
err := Parser::ParseError new. |
|
154 |
err errorMessage: message startPosition: start endPosition: end. |
|
155 |
err parameter:self. |
|
156 |
err lineNumber:line. |
|
157 |
err raiseRequest. |
|
158 |
^ self |
|
159 |
]. |
|
160 |
||
161 |
"Created: / 27-02-2012 / 21:10:41 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
162 |
! |
|
163 |
||
164 |
handleException: javaError |
|
165 |
||
166 |
| errors cause | |
|
167 |
"Arggghhh...that's Javas' clean OO design, sigh." |
|
168 |
errors := javaError parameter getErrorCollector getErrors. |
|
169 |
cause := errors getFirst getCause. |
|
170 |
self |
|
171 |
error: javaError parameter getMessage |
|
172 |
line: cause getLine |
|
173 |
from: cause getStartColumn |
|
174 |
to: cause getEndColumn. |
|
175 |
||
176 |
"Created: / 27-02-2012 / 21:09:46 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
177 |
! ! |
|
178 |
||
1368 | 179 |
!GroovyCompiler methodsFor:'initialization'! |
180 |
||
181 |
initialize |
|
182 |
||
183 |
self initializeGroovyClassLoader |
|
184 |
||
185 |
"Modified: / 18-02-2012 / 19:18:05 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
186 |
! |
|
187 |
||
188 |
initializeGroovyClassLoader |
|
189 |
| groovy_lang_GroovyClassLoader | |
|
190 |
||
191 |
GroovyClassLoader notNil ifTrue:[ ^ self ]. |
|
192 |
||
1385 | 193 |
JavaVM booted ifFalse:[ JavaVM boot ]. |
1372
dea574a1b6b3
Some initial class reloading support. Not yet finished, just sketched out.
vranyj1
parents:
1368
diff
changeset
|
194 |
groovy_lang_GroovyClassLoader := Java classForName:'stx.libjava.groovy.GroovyClassLoader'. |
1368 | 195 |
GroovyClassLoader := groovy_lang_GroovyClassLoader newCleared. |
196 |
GroovyClassLoader |
|
197 |
perform: #'<init>(Ljava/lang/ClassLoader;)V' |
|
198 |
with: JavaVM systemClassLoader. |
|
199 |
||
200 |
" |
|
201 |
GroovyClassLoader |
|
202 |
GroovyCompiler basicNew initializeGroovyClassLoader. |
|
203 |
GroovyClassLoader := nil. |
|
204 |
" |
|
205 |
||
206 |
"Created: / 18-02-2012 / 19:14:14 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
207 |
! ! |
|
208 |
||
209 |
!GroovyCompiler class methodsFor:'documentation'! |
|
210 |
||
211 |
version_SVN |
|
212 |
^ '$Id$' |
|
213 |
! ! |