- Improvements in GroovyCompiler (error handling) jk_new_structure
authorvranyj1
Mon, 27 Feb 2012 22:27:35 +0000
branchjk_new_structure
changeset 1387 4c609318f0e5
parent 1386 5a5fc5c71e48
child 1388 71a9ff13de80
- Improvements in GroovyCompiler (error handling) - fixes in interop
src/GroovyCompiler.st
src/JavaLookup.st
src/JavaVM.st
src/libjava.rc
--- a/src/GroovyCompiler.st	Fri Feb 24 22:36:28 2012 +0000
+++ b/src/GroovyCompiler.st	Mon Feb 27 22:27:35 2012 +0000
@@ -21,7 +21,7 @@
 "{ Package: 'stx:libjava' }"
 
 Object subclass:#GroovyCompiler
-	instanceVariableNames:''
+	instanceVariableNames:'requestor'
 	classVariableNames:'GroovyClassLoader'
 	poolDictionaries:''
 	category:'Languages-Groovy-Compiler'
@@ -76,7 +76,9 @@
 
     "We allways compile whole class"
 
-    ^self compileClass: source.
+    ^self new
+        requestor: requestor;
+        compileClass: source.
 
     "Created: / 21-02-2012 / 11:10:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
@@ -89,6 +91,16 @@
     "Created: / 18-02-2012 / 19:09:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
+!GroovyCompiler methodsFor:'accessing'!
+
+requestor
+    ^ requestor
+!
+
+requestor:something
+    requestor := something.
+! !
+
 !GroovyCompiler methodsFor:'compiler interface'!
 
 compileClass: source
@@ -96,9 +108,13 @@
 
     | jclass class |    
 
-    jclass := GroovyClassLoader 
-                perform: #'parseClass(Ljava/lang/String;)Ljava/lang/Class;'
-                   with: (Java as_String: source).
+    [
+        jclass := GroovyClassLoader 
+                    perform: #'parseClass(Ljava/lang/String;)Ljava/lang/Class;'
+                       with: (Java as_String: source).
+    ] on: JavaError do:[:jex|
+        self handleException: jex.
+    ].
     jclass isNil ifTrue:[ ^ nil ].
 
     class := JavaVM classForJavaClassObject: jclass.
@@ -108,6 +124,58 @@
     "Created: / 18-02-2012 / 19:12:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
+!GroovyCompiler methodsFor:'error reporting'!
+
+error: message line: line from: start to: end
+    "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."
+
+    |err|
+
+    Smalltalk isInitialized ifFalse:[
+        Smalltalk isStandAloneDebug ifTrue:[
+            "/ error during startup
+            thisContext fullPrintAll.
+        ]
+    ].
+
+
+    "/ backward compatibility - will vanish eventually (use a handler, Luke)
+    requestor notNil ifTrue:[
+        requestor error:message position:start to:end from:self.
+        ^ self
+    ].
+    Parser::ParseError isHandled ifTrue:[
+        err := Parser::ParseError new.
+        err errorMessage: message startPosition: start endPosition: end.
+        err parameter:self.
+        err lineNumber:line.
+        err raiseRequest.
+        ^ self
+    ].
+
+    "Created: / 27-02-2012 / 21:10:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+handleException: javaError
+
+    | errors cause |
+             "Arggghhh...that's Javas' clean OO design, sigh."
+    errors := javaError parameter getErrorCollector getErrors.
+    cause := errors getFirst getCause.
+    self 
+        error:  javaError parameter getMessage
+         line: cause getLine
+         from: cause getStartColumn
+           to: cause getEndColumn.
+
+    "Created: / 27-02-2012 / 21:09:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
 !GroovyCompiler methodsFor:'initialization'!
 
 initialize
--- a/src/JavaLookup.st	Fri Feb 24 22:36:28 2012 +0000
+++ b/src/JavaLookup.st	Mon Feb 27 22:27:35 2012 +0000
@@ -265,11 +265,15 @@
     candidates := OrderedCollection new.
     finder := [:cls|
         cls methodDictionary keysAndValuesDo:[:sel :mthd|
-            (mthd mclass ~~ ProxyMethod
-                and:[((sel size >= nameSizePlusOne) and:[(sel at: nameSizePlusOne) == $( and:[(sel startsWith: name)]])
-                    and:[mthd descriptor numArgs == argArrayOrNil size]]) ifTrue:[
-                        candidates add: mthd
-                    ]
+            "candidates may contain a method with same selector ->
+             do not add super-class's method"
+            (candidates contains:[:each|each selector == sel]) ifFalse:[
+                (mthd mclass ~~ ProxyMethod
+                    and:[((sel size >= nameSizePlusOne) and:[(sel at: nameSizePlusOne) == $( and:[(sel startsWith: name)]])
+                        and:[mthd descriptor numArgs == argArrayOrNil size]]) ifTrue:[
+                            candidates add: mthd
+                        ]
+            ]
         ]
     ].
 
@@ -299,9 +303,9 @@
     "Modified: / 20-09-2011 / 00:03:48 / Jan Kurs <kursjan@fit.cvut.cz>"
     "Modified (format): / 25-09-2011 / 21:08:45 / Jan Kurs <kursjan@fit.cvut.cz>"
     "Created: / 19-11-2011 / 13:03:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 01-01-2012 / 17:41:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     "Modified: / 01-01-2012 / 19:58:59 / kursjan <kursjan@fit.cvut.cz>"
     "Modified (comment): / 02-01-2012 / 10:35:25 / kursjan <kursjan@fit.cvut.cz>"
+    "Modified: / 27-02-2012 / 19:43:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !JavaLookup::Smalltalk2Java methodsFor:'lookup (old)'!
--- a/src/JavaVM.st	Fri Feb 24 22:36:28 2012 +0000
+++ b/src/JavaVM.st	Mon Feb 27 22:27:35 2012 +0000
@@ -2634,6 +2634,7 @@
     ExceptionDebugPatterns add: 'java/lang/IllegalArgumentException'.
     ExceptionDebugPatterns add: 'java/lang/ClassNotFoundException'.
     ExceptionDebugPatterns add: 'java/io/IOException'.
+    ExceptionDebugPatterns add: 'java/io/FileNotFoundException'.
     ExceptionDebugPatterns add: 'java/lang/NoSuchMethodException'.
     ExceptionDebugPatterns add: 'java/lang/ArrayIndexOutOfBoundsException'.
     "
--- a/src/libjava.rc	Fri Feb 24 22:36:28 2012 +0000
+++ b/src/libjava.rc	Mon Feb 27 22:27:35 2012 +0000
@@ -25,7 +25,7 @@
       VALUE "LegalCopyright", "Copyright Claus Gittinger 1988-2011\nCopyright eXept Software AG 1998-2011\nCopyright Jan Vrany, Jan Kurs and Marcel Hlopko\b          SWING Research Group, Czech Technical University In Prague\0"
       VALUE "ProductName", "Smalltalk/X\0"
       VALUE "ProductVersion", "6.2.1.1\0"
-      VALUE "ProductDate", "Fri, 24 Feb 2012 22:31:59 GMT\0"
+      VALUE "ProductDate", "Mon, 27 Feb 2012 22:24:29 GMT\0"
     END
 
   END