87 ^self new compileClass: source. |
89 ^self new compileClass: source. |
88 |
90 |
89 "Created: / 18-02-2012 / 19:09:11 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
91 "Created: / 18-02-2012 / 19:09:11 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
90 ! ! |
92 ! ! |
91 |
93 |
|
94 !GroovyCompiler methodsFor:'accessing'! |
|
95 |
|
96 requestor |
|
97 ^ requestor |
|
98 ! |
|
99 |
|
100 requestor:something |
|
101 requestor := something. |
|
102 ! ! |
|
103 |
92 !GroovyCompiler methodsFor:'compiler interface'! |
104 !GroovyCompiler methodsFor:'compiler interface'! |
93 |
105 |
94 compileClass: source |
106 compileClass: source |
95 "Compiles a new Groovy class given the source code" |
107 "Compiles a new Groovy class given the source code" |
96 |
108 |
97 | jclass class | |
109 | jclass class | |
98 |
110 |
99 jclass := GroovyClassLoader |
111 [ |
100 perform: #'parseClass(Ljava/lang/String;)Ljava/lang/Class;' |
112 jclass := GroovyClassLoader |
101 with: (Java as_String: source). |
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 ]. |
102 jclass isNil ifTrue:[ ^ nil ]. |
118 jclass isNil ifTrue:[ ^ nil ]. |
103 |
119 |
104 class := JavaVM classForJavaClassObject: jclass. |
120 class := JavaVM classForJavaClassObject: jclass. |
105 class setSource: source. |
121 class setSource: source. |
106 ^class. |
122 ^class. |
107 |
123 |
108 "Created: / 18-02-2012 / 19:12:02 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
124 "Created: / 18-02-2012 / 19:12:02 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
125 ! ! |
|
126 |
|
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>" |
109 ! ! |
177 ! ! |
110 |
178 |
111 !GroovyCompiler methodsFor:'initialization'! |
179 !GroovyCompiler methodsFor:'initialization'! |
112 |
180 |
113 initialize |
181 initialize |