GroovyCompiler.st
author hlopkmar
Sat, 01 Dec 2012 22:06:11 +0000
branchdevelopment
changeset 1851 d74d5dc547f3
parent 1818 2e5ed72e7dfd
child 1864 60a8dc26c8c6
permissions -rw-r--r--
junit tests for param annotations
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1368
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
     1
"
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
     2
 COPYRIGHT (c) 1996-2011 by Claus Gittinger
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
     3
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
     4
 New code and modifications done at SWING Research Group [1]:
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
     5
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
     6
 COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
     7
                            SWING Research Group, Czech Technical University in Prague
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
     8
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
     9
 This software is furnished under a license and may be used
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    10
 only in accordance with the terms of that license and with the
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    11
 inclusion of the above copyright notice.   This software may not
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    12
 be provided or otherwise made available to, or used by, any
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    13
 other person.  No title to or ownership of the software is
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    14
 hereby transferred.
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    15
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    16
 [1] Code written at SWING Research Group contains a signature
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    17
     of one of the above copright owners. For exact set of such code,
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    18
     see the differences between this version and version stx:libjava
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    19
     as of 1.9.2010
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    20
"
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    21
"{ Package: 'stx:libjava' }"
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    22
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    23
Object subclass:#GroovyCompiler
1387
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
    24
	instanceVariableNames:'requestor'
1368
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    25
	classVariableNames:'GroovyClassLoader'
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    26
	poolDictionaries:''
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    27
	category:'Languages-Groovy-Compiler'
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    28
!
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    29
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    30
!GroovyCompiler class methodsFor:'documentation'!
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    31
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    32
copyright
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    33
"
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    34
 COPYRIGHT (c) 1996-2011 by Claus Gittinger
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    35
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    36
 New code and modifications done at SWING Research Group [1]:
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    37
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    38
 COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    39
                            SWING Research Group, Czech Technical University in Prague
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    40
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    41
 This software is furnished under a license and may be used
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    42
 only in accordance with the terms of that license and with the
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    43
 inclusion of the above copyright notice.   This software may not
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    44
 be provided or otherwise made available to, or used by, any
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    45
 other person.  No title to or ownership of the software is
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    46
 hereby transferred.
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    47
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    48
 [1] Code written at SWING Research Group contains a signature
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    49
     of one of the above copright owners. For exact set of such code,
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    50
     see the differences between this version and version stx:libjava
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    51
     as of 1.9.2010
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    52
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    53
"
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    54
! !
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    55
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    56
!GroovyCompiler class methodsFor:'initialization'!
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    57
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    58
flushGroovyClassLoader
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    59
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    60
    GroovyClassLoader := nil
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    61
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    62
    "Created: / 18-02-2012 / 22:25:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    63
! !
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    64
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    65
!GroovyCompiler class methodsFor:'instance creation'!
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    66
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    67
new
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    68
    "return an initialized instance"
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    69
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    70
    ^ self basicNew initialize.
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    71
! !
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    72
1453
f7a8861cdbe1 - added JavaMetaclass, GroovyMetaclass
vranyj1
parents: 1441
diff changeset
    73
!GroovyCompiler class methodsFor:'* As yet uncategorized *'!
f7a8861cdbe1 - added JavaMetaclass, GroovyMetaclass
vranyj1
parents: 1441
diff changeset
    74
f7a8861cdbe1 - added JavaMetaclass, GroovyMetaclass
vranyj1
parents: 1441
diff changeset
    75
evaluate: source notifying: requestor compile: doCompile
f7a8861cdbe1 - added JavaMetaclass, GroovyMetaclass
vranyj1
parents: 1441
diff changeset
    76
f7a8861cdbe1 - added JavaMetaclass, GroovyMetaclass
vranyj1
parents: 1441
diff changeset
    77
    ^self new
f7a8861cdbe1 - added JavaMetaclass, GroovyMetaclass
vranyj1
parents: 1441
diff changeset
    78
        requestor: requestor;
f7a8861cdbe1 - added JavaMetaclass, GroovyMetaclass
vranyj1
parents: 1441
diff changeset
    79
        compile: source
f7a8861cdbe1 - added JavaMetaclass, GroovyMetaclass
vranyj1
parents: 1441
diff changeset
    80
f7a8861cdbe1 - added JavaMetaclass, GroovyMetaclass
vranyj1
parents: 1441
diff changeset
    81
    "Created: / 04-04-2012 / 10:07:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
f7a8861cdbe1 - added JavaMetaclass, GroovyMetaclass
vranyj1
parents: 1441
diff changeset
    82
! !
f7a8861cdbe1 - added JavaMetaclass, GroovyMetaclass
vranyj1
parents: 1441
diff changeset
    83
1368
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    84
!GroovyCompiler class methodsFor:'compiler interface'!
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    85
1388
71a9ff13de80 Improvements in interop
vranyj1
parents: 1387
diff changeset
    86
compile: source
71a9ff13de80 Improvements in interop
vranyj1
parents: 1387
diff changeset
    87
    "Compiles a new Groovy class given the source code"
71a9ff13de80 Improvements in interop
vranyj1
parents: 1387
diff changeset
    88
71a9ff13de80 Improvements in interop
vranyj1
parents: 1387
diff changeset
    89
    ^self new compile: source.
71a9ff13de80 Improvements in interop
vranyj1
parents: 1387
diff changeset
    90
71a9ff13de80 Improvements in interop
vranyj1
parents: 1387
diff changeset
    91
    "Created: / 27-02-2012 / 23:27:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
71a9ff13de80 Improvements in interop
vranyj1
parents: 1387
diff changeset
    92
!
71a9ff13de80 Improvements in interop
vranyj1
parents: 1387
diff changeset
    93
1372
dea574a1b6b3 Some initial class reloading support. Not yet finished, just sketched out.
vranyj1
parents: 1368
diff changeset
    94
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
    95
dea574a1b6b3 Some initial class reloading support. Not yet finished, just sketched out.
vranyj1
parents: 1368
diff changeset
    96
    "We allways compile whole class"
dea574a1b6b3 Some initial class reloading support. Not yet finished, just sketched out.
vranyj1
parents: 1368
diff changeset
    97
1387
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
    98
    ^self new
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
    99
        requestor: requestor;
1388
71a9ff13de80 Improvements in interop
vranyj1
parents: 1387
diff changeset
   100
        compile: source.
1372
dea574a1b6b3 Some initial class reloading support. Not yet finished, just sketched out.
vranyj1
parents: 1368
diff changeset
   101
dea574a1b6b3 Some initial class reloading support. Not yet finished, just sketched out.
vranyj1
parents: 1368
diff changeset
   102
    "Created: / 21-02-2012 / 11:10:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
1699
73003b9f58fc - Support for extension methods finished (ready for testing)
vranyj1
parents: 1697
diff changeset
   103
!
73003b9f58fc - Support for extension methods finished (ready for testing)
vranyj1
parents: 1697
diff changeset
   104
73003b9f58fc - Support for extension methods finished (ready for testing)
vranyj1
parents: 1697
diff changeset
   105
compile:aString forClass:aClass inCategory:cat notifying:requestor
73003b9f58fc - Support for extension methods finished (ready for testing)
vranyj1
parents: 1697
diff changeset
   106
                 install:install skipIfSame:skipIfSame silent:silent
73003b9f58fc - Support for extension methods finished (ready for testing)
vranyj1
parents: 1697
diff changeset
   107
73003b9f58fc - Support for extension methods finished (ready for testing)
vranyj1
parents: 1697
diff changeset
   108
    "HACK.
73003b9f58fc - Support for extension methods finished (ready for testing)
vranyj1
parents: 1697
diff changeset
   109
     Problem:
73003b9f58fc - Support for extension methods finished (ready for testing)
vranyj1
parents: 1697
diff changeset
   110
     SmalltalkChunkFileReader always uses class's compiler to compile source. 
73003b9f58fc - Support for extension methods finished (ready for testing)
vranyj1
parents: 1697
diff changeset
   111
     However, when filing in Smalltalk extensions to Java classes, a Smalltalk 
73003b9f58fc - Support for extension methods finished (ready for testing)
vranyj1
parents: 1697
diff changeset
   112
     code is passed to me.
73003b9f58fc - Support for extension methods finished (ready for testing)
vranyj1
parents: 1697
diff changeset
   113
73003b9f58fc - Support for extension methods finished (ready for testing)
vranyj1
parents: 1697
diff changeset
   114
     See ClassCategoryReader>>fileInFrom:notifying:passChunk:single:silent:
73003b9f58fc - Support for extension methods finished (ready for testing)
vranyj1
parents: 1697
diff changeset
   115
73003b9f58fc - Support for extension methods finished (ready for testing)
vranyj1
parents: 1697
diff changeset
   116
     Workaround:
73003b9f58fc - Support for extension methods finished (ready for testing)
vranyj1
parents: 1697
diff changeset
   117
     Detect such a situation and compile using Smalltalk compiler...bad, I know.
73003b9f58fc - Support for extension methods finished (ready for testing)
vranyj1
parents: 1697
diff changeset
   118
     Better to move logic from Stream>>fileIn into SmalltalkChunkSourceFileReader.
73003b9f58fc - Support for extension methods finished (ready for testing)
vranyj1
parents: 1697
diff changeset
   119
     "
73003b9f58fc - Support for extension methods finished (ready for testing)
vranyj1
parents: 1697
diff changeset
   120
73003b9f58fc - Support for extension methods finished (ready for testing)
vranyj1
parents: 1697
diff changeset
   121
    (requestor isKindOf: SourceFileLoader) ifTrue:[
73003b9f58fc - Support for extension methods finished (ready for testing)
vranyj1
parents: 1697
diff changeset
   122
        ^Compiler compile:aString forClass:aClass inCategory:cat notifying:requestor
73003b9f58fc - Support for extension methods finished (ready for testing)
vranyj1
parents: 1697
diff changeset
   123
                 install:install skipIfSame:skipIfSame silent:silent
73003b9f58fc - Support for extension methods finished (ready for testing)
vranyj1
parents: 1697
diff changeset
   124
    ].
73003b9f58fc - Support for extension methods finished (ready for testing)
vranyj1
parents: 1697
diff changeset
   125
73003b9f58fc - Support for extension methods finished (ready for testing)
vranyj1
parents: 1697
diff changeset
   126
    self breakPoint:#jv.
73003b9f58fc - Support for extension methods finished (ready for testing)
vranyj1
parents: 1697
diff changeset
   127
    self error: 'Not (yet) supported'
73003b9f58fc - Support for extension methods finished (ready for testing)
vranyj1
parents: 1697
diff changeset
   128
73003b9f58fc - Support for extension methods finished (ready for testing)
vranyj1
parents: 1697
diff changeset
   129
    "Created: / 07-09-2012 / 10:35:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
1368
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   130
! !
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   131
1387
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   132
!GroovyCompiler methodsFor:'accessing'!
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   133
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   134
requestor
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   135
    ^ requestor
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   136
!
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   137
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   138
requestor:something
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   139
    requestor := something.
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   140
! !
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   141
1368
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   142
!GroovyCompiler methodsFor:'compiler interface'!
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   143
1388
71a9ff13de80 Improvements in interop
vranyj1
parents: 1387
diff changeset
   144
compile: source
1368
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   145
    "Compiles a new Groovy class given the source code"
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   146
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   147
    | jclass class |    
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   148
1387
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   149
    [
1441
0faa0f8eda0c Minor improvements in reloading
vranyj1
parents: 1388
diff changeset
   150
        "Do no change it to 'GroovyClassLoader compile:'
0faa0f8eda0c Minor improvements in reloading
vranyj1
parents: 1388
diff changeset
   151
         #compile: is already implemented so no interop will
0faa0f8eda0c Minor improvements in reloading
vranyj1
parents: 1388
diff changeset
   152
         handle it, sigh"
1387
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   153
        jclass := GroovyClassLoader 
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   154
                    perform: #'parseClass(Ljava/lang/String;)Ljava/lang/Class;'
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   155
                       with: (Java as_String: source).
1441
0faa0f8eda0c Minor improvements in reloading
vranyj1
parents: 1388
diff changeset
   156
    ] on: JAVA org codehaus groovy control CompilationFailedException do:[:cfe|
0faa0f8eda0c Minor improvements in reloading
vranyj1
parents: 1388
diff changeset
   157
        self handleException: cfe.
1387
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   158
    ].
1368
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   159
    jclass isNil ifTrue:[ ^ nil ].
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   160
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   161
    class := JavaVM classForJavaClassObject: jclass.
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   162
    class setSource: source.
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   163
    ^class.
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   164
1388
71a9ff13de80 Improvements in interop
vranyj1
parents: 1387
diff changeset
   165
    "Created: / 27-02-2012 / 23:27:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
1697
0a9d598a6408 - Initial support for fileouting Java extension methods
vranyj1
parents: 1656
diff changeset
   166
!
0a9d598a6408 - Initial support for fileouting Java extension methods
vranyj1
parents: 1656
diff changeset
   167
0a9d598a6408 - Initial support for fileouting Java extension methods
vranyj1
parents: 1656
diff changeset
   168
compile:source in: class notifying: requestor ifFail: block
0a9d598a6408 - Initial support for fileouting Java extension methods
vranyj1
parents: 1656
diff changeset
   169
0a9d598a6408 - Initial support for fileouting Java extension methods
vranyj1
parents: 1656
diff changeset
   170
    requestor class == SourceFileLoader ifTrue:[
0a9d598a6408 - Initial support for fileouting Java extension methods
vranyj1
parents: 1656
diff changeset
   171
        ^Compiler compile:source in: class notifying: requestor ifFail: block
0a9d598a6408 - Initial support for fileouting Java extension methods
vranyj1
parents: 1656
diff changeset
   172
    ].
0a9d598a6408 - Initial support for fileouting Java extension methods
vranyj1
parents: 1656
diff changeset
   173
0a9d598a6408 - Initial support for fileouting Java extension methods
vranyj1
parents: 1656
diff changeset
   174
    self error:'Not yet supported'.
0a9d598a6408 - Initial support for fileouting Java extension methods
vranyj1
parents: 1656
diff changeset
   175
0a9d598a6408 - Initial support for fileouting Java extension methods
vranyj1
parents: 1656
diff changeset
   176
    "Created: / 04-09-2012 / 23:56:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
1368
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   177
! !
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   178
1387
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   179
!GroovyCompiler methodsFor:'error reporting'!
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   180
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   181
error: message line: line from: start to: end
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   182
    "notify requestor of an error - if there is no requestor
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   183
     put it on the transcript. Requestor is typically the CodeView
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   184
     in which the accept/doIt was triggered, or the PositionableStream
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   185
     which does the fileIn. The requestor may decide how to highlight the
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   186
     error (and/or to abort the compile).
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   187
     Return the result passed back by the requestor."
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   188
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   189
    |err|
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   190
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   191
    Smalltalk isInitialized ifFalse:[
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   192
        Smalltalk isStandAloneDebug ifTrue:[
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   193
            "/ error during startup
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   194
            thisContext fullPrintAll.
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   195
        ]
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   196
    ].
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   197
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   198
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   199
    "/ backward compatibility - will vanish eventually (use a handler, Luke)
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   200
    requestor notNil ifTrue:[
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   201
        requestor error:message position:start to:end from:self.
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   202
        ^ self
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   203
    ].
1656
c6fee8f3a640 - fixes for Groovy-Smalltalk interop - SmalltalkEvaluator example works
vranyj1
parents: 1453
diff changeset
   204
   (Smalltalk at:#'Parser::ParseError') isHandled ifTrue:[
c6fee8f3a640 - fixes for Groovy-Smalltalk interop - SmalltalkEvaluator example works
vranyj1
parents: 1453
diff changeset
   205
        err := (Smalltalk at:#'Parser::ParseError') new.
1387
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   206
        err errorMessage: message startPosition: start endPosition: end.
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   207
        err parameter:self.
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   208
        err lineNumber:line.
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   209
        err raiseRequest.
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   210
        ^ self
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   211
    ].
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   212
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   213
    "Created: / 27-02-2012 / 21:10:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   214
!
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   215
1441
0faa0f8eda0c Minor improvements in reloading
vranyj1
parents: 1388
diff changeset
   216
handleException: exception
1387
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   217
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   218
    | errors cause |
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   219
             "Arggghhh...that's Javas' clean OO design, sigh."
1441
0faa0f8eda0c Minor improvements in reloading
vranyj1
parents: 1388
diff changeset
   220
    errors := exception getErrorCollector getErrors.
1387
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   221
    cause := errors getFirst getCause.
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   222
    self 
1441
0faa0f8eda0c Minor improvements in reloading
vranyj1
parents: 1388
diff changeset
   223
        error: exception getMessage
1387
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   224
         line: cause getLine
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   225
         from: cause getStartColumn
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   226
           to: cause getEndColumn.
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   227
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   228
    "Created: / 27-02-2012 / 21:09:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   229
! !
4c609318f0e5 - Improvements in GroovyCompiler (error handling)
vranyj1
parents: 1385
diff changeset
   230
1368
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   231
!GroovyCompiler methodsFor:'initialization'!
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   232
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   233
initialize
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   234
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   235
    self initializeGroovyClassLoader
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   236
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   237
    "Modified: / 18-02-2012 / 19:18:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   238
!
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   239
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   240
initializeGroovyClassLoader
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   241
    | groovy_lang_GroovyClassLoader |
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   242
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   243
    GroovyClassLoader notNil ifTrue:[ ^ self ].
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   244
1385
3426388640da Improvements in interop
vranyj1
parents: 1372
diff changeset
   245
    JavaVM booted ifFalse:[ JavaVM boot ].
1372
dea574a1b6b3 Some initial class reloading support. Not yet finished, just sketched out.
vranyj1
parents: 1368
diff changeset
   246
    groovy_lang_GroovyClassLoader := Java classForName:'stx.libjava.groovy.GroovyClassLoader'.
1368
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   247
    GroovyClassLoader := groovy_lang_GroovyClassLoader newCleared.
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   248
    GroovyClassLoader
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   249
            perform: #'<init>(Ljava/lang/ClassLoader;)V'
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   250
               with: JavaVM systemClassLoader.
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   251
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   252
    "
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   253
        GroovyClassLoader 
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   254
        GroovyCompiler basicNew initializeGroovyClassLoader.
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   255
        GroovyClassLoader := nil.
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   256
    "
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   257
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   258
    "Created: / 18-02-2012 / 19:14:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   259
! !
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   260
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   261
!GroovyCompiler class methodsFor:'documentation'!
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   262
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   263
version_SVN
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   264
    ^ '$Id$'
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   265
! !