GroovyEvaluator.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Sat, 19 Jan 2013 23:54:47 +0000
branchrefactoring-vmdata
changeset 1986 9e63ab553922
parent 1864 60a8dc26c8c6
child 2069 75d40b7b986f
permissions -rw-r--r--
JavaNativeMethod & their implementation transformed to pass a reveiver. Java still does not boot at this point, some overloaded natives in sun,misc.Unsafe has to be fixed manually.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
917
ecd1a00132f1 - added JavaEvaluator
vranyj1
parents:
diff changeset
     1
"
ecd1a00132f1 - added JavaEvaluator
vranyj1
parents:
diff changeset
     2
 COPYRIGHT (c) 1996-2011 by Claus Gittinger
1152
040cba55a7d2 Copyright fixes
vranyj1
parents: 1044
diff changeset
     3
1155
vranyj1
parents: 1152
diff changeset
     4
 New code and modifications done at SWING Research Group [1]:
1152
040cba55a7d2 Copyright fixes
vranyj1
parents: 1044
diff changeset
     5
917
ecd1a00132f1 - added JavaEvaluator
vranyj1
parents:
diff changeset
     6
 COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
ecd1a00132f1 - added JavaEvaluator
vranyj1
parents:
diff changeset
     7
                            SWING Research Group, Czech Technical University in Prague
ecd1a00132f1 - added JavaEvaluator
vranyj1
parents:
diff changeset
     8
ecd1a00132f1 - added JavaEvaluator
vranyj1
parents:
diff changeset
     9
 This software is furnished under a license and may be used
ecd1a00132f1 - added JavaEvaluator
vranyj1
parents:
diff changeset
    10
 only in accordance with the terms of that license and with the
ecd1a00132f1 - added JavaEvaluator
vranyj1
parents:
diff changeset
    11
 inclusion of the above copyright notice.   This software may not
ecd1a00132f1 - added JavaEvaluator
vranyj1
parents:
diff changeset
    12
 be provided or otherwise made available to, or used by, any
ecd1a00132f1 - added JavaEvaluator
vranyj1
parents:
diff changeset
    13
 other person.  No title to or ownership of the software is
ecd1a00132f1 - added JavaEvaluator
vranyj1
parents:
diff changeset
    14
 hereby transferred.
ecd1a00132f1 - added JavaEvaluator
vranyj1
parents:
diff changeset
    15
1155
vranyj1
parents: 1152
diff changeset
    16
 [1] Code written at SWING Research Group contains a signature
vranyj1
parents: 1152
diff changeset
    17
     of one of the above copright owners. For exact set of such code,
vranyj1
parents: 1152
diff changeset
    18
     see the differences between this version and version stx:libjava
1152
040cba55a7d2 Copyright fixes
vranyj1
parents: 1044
diff changeset
    19
     as of 1.9.2010
917
ecd1a00132f1 - added JavaEvaluator
vranyj1
parents:
diff changeset
    20
"
ecd1a00132f1 - added JavaEvaluator
vranyj1
parents:
diff changeset
    21
"{ Package: 'stx:libjava' }"
ecd1a00132f1 - added JavaEvaluator
vranyj1
parents:
diff changeset
    22
1370
0708027f69b0 oops, class rename failed. Fixed now
vranyj1
parents: 1368
diff changeset
    23
Object subclass:#GroovyEvaluator
1639
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
    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
ecd1a00132f1 - added JavaEvaluator
vranyj1
parents:
diff changeset
    26
	poolDictionaries:''
1656
c6fee8f3a640 - fixes for Groovy-Smalltalk interop - SmalltalkEvaluator example works
vranyj1
parents: 1649
diff changeset
    27
	category:'Languages-Groovy-Compiler'
917
ecd1a00132f1 - added JavaEvaluator
vranyj1
parents:
diff changeset
    28
!
ecd1a00132f1 - added JavaEvaluator
vranyj1
parents:
diff changeset
    29
1370
0708027f69b0 oops, class rename failed. Fixed now
vranyj1
parents: 1368
diff changeset
    30
!GroovyEvaluator class methodsFor:'documentation'!
917
ecd1a00132f1 - added JavaEvaluator
vranyj1
parents:
diff changeset
    31
ecd1a00132f1 - added JavaEvaluator
vranyj1
parents:
diff changeset
    32
copyright
ecd1a00132f1 - added JavaEvaluator
vranyj1
parents:
diff changeset
    33
"
ecd1a00132f1 - added JavaEvaluator
vranyj1
parents:
diff changeset
    34
 COPYRIGHT (c) 1996-2011 by Claus Gittinger
1152
040cba55a7d2 Copyright fixes
vranyj1
parents: 1044
diff changeset
    35
1155
vranyj1
parents: 1152
diff changeset
    36
 New code and modifications done at SWING Research Group [1]:
1152
040cba55a7d2 Copyright fixes
vranyj1
parents: 1044
diff changeset
    37
917
ecd1a00132f1 - added JavaEvaluator
vranyj1
parents:
diff changeset
    38
 COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
ecd1a00132f1 - added JavaEvaluator
vranyj1
parents:
diff changeset
    39
                            SWING Research Group, Czech Technical University in Prague
ecd1a00132f1 - added JavaEvaluator
vranyj1
parents:
diff changeset
    40
ecd1a00132f1 - added JavaEvaluator
vranyj1
parents:
diff changeset
    41
 This software is furnished under a license and may be used
ecd1a00132f1 - added JavaEvaluator
vranyj1
parents:
diff changeset
    42
 only in accordance with the terms of that license and with the
ecd1a00132f1 - added JavaEvaluator
vranyj1
parents:
diff changeset
    43
 inclusion of the above copyright notice.   This software may not
ecd1a00132f1 - added JavaEvaluator
vranyj1
parents:
diff changeset
    44
 be provided or otherwise made available to, or used by, any
ecd1a00132f1 - added JavaEvaluator
vranyj1
parents:
diff changeset
    45
 other person.  No title to or ownership of the software is
ecd1a00132f1 - added JavaEvaluator
vranyj1
parents:
diff changeset
    46
 hereby transferred.
ecd1a00132f1 - added JavaEvaluator
vranyj1
parents:
diff changeset
    47
1155
vranyj1
parents: 1152
diff changeset
    48
 [1] Code written at SWING Research Group contains a signature
vranyj1
parents: 1152
diff changeset
    49
     of one of the above copright owners. For exact set of such code,
vranyj1
parents: 1152
diff changeset
    50
     see the differences between this version and version stx:libjava
1152
040cba55a7d2 Copyright fixes
vranyj1
parents: 1044
diff changeset
    51
     as of 1.9.2010
917
ecd1a00132f1 - added JavaEvaluator
vranyj1
parents:
diff changeset
    52
ecd1a00132f1 - added JavaEvaluator
vranyj1
parents:
diff changeset
    53
"
ecd1a00132f1 - added JavaEvaluator
vranyj1
parents:
diff changeset
    54
! !
ecd1a00132f1 - added JavaEvaluator
vranyj1
parents:
diff changeset
    55
1478
329a15eedd36 - improvements in class reloading
vranyj1
parents: 1459
diff changeset
    56
!GroovyEvaluator class methodsFor:'* As yet uncategorized *'!
329a15eedd36 - improvements in class reloading
vranyj1
parents: 1459
diff changeset
    57
329a15eedd36 - improvements in class reloading
vranyj1
parents: 1459
diff changeset
    58
evaluate: source in: context receiver: receiver  notifying: requestor logged: log ifFail: failblock
329a15eedd36 - improvements in class reloading
vranyj1
parents: 1459
diff changeset
    59
    ^self new evaluate: source in: context receiver: receiver  notifying: requestor logged: log ifFail: failblock
329a15eedd36 - improvements in class reloading
vranyj1
parents: 1459
diff changeset
    60
329a15eedd36 - improvements in class reloading
vranyj1
parents: 1459
diff changeset
    61
    "Created: / 13-04-2012 / 17:24:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
329a15eedd36 - improvements in class reloading
vranyj1
parents: 1459
diff changeset
    62
! !
329a15eedd36 - improvements in class reloading
vranyj1
parents: 1459
diff changeset
    63
1370
0708027f69b0 oops, class rename failed. Fixed now
vranyj1
parents: 1368
diff changeset
    64
!GroovyEvaluator class methodsFor:'utilities'!
1204
6c2b887399e8 Few small fixes
vranyj1
parents: 1202
diff changeset
    65
6c2b887399e8 Few small fixes
vranyj1
parents: 1202
diff changeset
    66
flushWorkspaceBinding
6c2b887399e8 Few small fixes
vranyj1
parents: 1202
diff changeset
    67
6c2b887399e8 Few small fixes
vranyj1
parents: 1202
diff changeset
    68
    WorkspaceBinding := nil
6c2b887399e8 Few small fixes
vranyj1
parents: 1202
diff changeset
    69
6c2b887399e8 Few small fixes
vranyj1
parents: 1202
diff changeset
    70
    "Created: / 02-12-2011 / 23:23:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
6c2b887399e8 Few small fixes
vranyj1
parents: 1202
diff changeset
    71
! !
6c2b887399e8 Few small fixes
vranyj1
parents: 1202
diff changeset
    72
1581
70fbc03d2d82 Java reflection support refactoring - moved to use JavaMirrors
vranyj1
parents: 1478
diff changeset
    73
!GroovyEvaluator methodsFor:'accessing'!
1459
9e24f4337d78 Tests for finally
vranyj1
parents: 1370
diff changeset
    74
1581
70fbc03d2d82 Java reflection support refactoring - moved to use JavaMirrors
vranyj1
parents: 1478
diff changeset
    75
currentNameSpace: ns
1459
9e24f4337d78 Tests for finally
vranyj1
parents: 1370
diff changeset
    76
    ns notNil ifTrue:[
9e24f4337d78 Tests for finally
vranyj1
parents: 1370
diff changeset
    77
        self error:'Smalltalk namespaces not supported by Groovy'
9e24f4337d78 Tests for finally
vranyj1
parents: 1370
diff changeset
    78
    ].
9e24f4337d78 Tests for finally
vranyj1
parents: 1370
diff changeset
    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
9e24f4337d78 Tests for finally
vranyj1
parents: 1370
diff changeset
    86
    "Created: / 07-04-2012 / 09:26:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
9e24f4337d78 Tests for finally
vranyj1
parents: 1370
diff changeset
    87
! !
9e24f4337d78 Tests for finally
vranyj1
parents: 1370
diff changeset
    88
1370
0708027f69b0 oops, class rename failed. Fixed now
vranyj1
parents: 1368
diff changeset
    89
!GroovyEvaluator methodsFor:'compiler interface'!
917
ecd1a00132f1 - added JavaEvaluator
vranyj1
parents:
diff changeset
    90
1691
826f8d7dc0df thinlocks reintegrated
vranyj1
parents: 1656
diff changeset
    91
evaluate:src
826f8d7dc0df thinlocks reintegrated
vranyj1
parents: 1656
diff changeset
    92
    | result |
971
937ed5f288a7 added: #evaluate:
vranyj1
parents: 960
diff changeset
    93
1691
826f8d7dc0df thinlocks reintegrated
vranyj1
parents: 1656
diff changeset
    94
    result := self evaluate:src in: nil receiver: nil notifying: nil logged: false ifFail: [self error:'Evaluation failed'].
826f8d7dc0df thinlocks reintegrated
vranyj1
parents: 1656
diff changeset
    95
    ^result.
971
937ed5f288a7 added: #evaluate:
vranyj1
parents: 960
diff changeset
    96
937ed5f288a7 added: #evaluate:
vranyj1
parents: 960
diff changeset
    97
    "Created: / 02-09-2011 / 10:24:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
937ed5f288a7 added: #evaluate:
vranyj1
parents: 960
diff changeset
    98
!
937ed5f288a7 added: #evaluate:
vranyj1
parents: 960
diff changeset
    99
1639
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   100
evaluate: sourceObj in: context receiver: receiver notifying: requestorObj logged: logged ifFail: fail 
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   101
    | binding result wsForWorkspace |
918
73bd57f8d3b0 - fixes in natives (reflective support for fields)
vranyj1
parents: 917
diff changeset
   102
1033
a31de6a4cfa4 refactoringl, moved registry to JavaVM
hlopkmar
parents: 972
diff changeset
   103
    JavaVM booted ifFalse: [
959
1f3342b2e728 Fixes...
vranyj1
parents: 918
diff changeset
   104
        Java initialize.
1f3342b2e728 Fixes...
vranyj1
parents: 918
diff changeset
   105
        JavaVM initializeVM.
1f3342b2e728 Fixes...
vranyj1
parents: 918
diff changeset
   106
    ].
1639
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   107
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   108
    requestor := requestorObj.
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   109
    source := sourceObj.
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   110
    wsForWorkspace := requestor notNil and: [ requestor application isKindOf: WorkspaceApplication ].
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   111
    binding := (Java classForName: 'groovy.lang.Binding') new.
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   112
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   113
    wsForWorkspace ifTrue: [
1044
84b7d94d9eb8 Java Workspace now share same binding (i.e., workspace variables are remembered)
vranyj1
parents: 1033
diff changeset
   114
        WorkspaceBinding isNil ifTrue: [
84b7d94d9eb8 Java Workspace now share same binding (i.e., workspace variables are remembered)
vranyj1
parents: 1033
diff changeset
   115
            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
   116
        ].
84b7d94d9eb8 Java Workspace now share same binding (i.e., workspace variables are remembered)
vranyj1
parents: 1033
diff changeset
   117
        binding := WorkspaceBinding
84b7d94d9eb8 Java Workspace now share same binding (i.e., workspace variables are remembered)
vranyj1
parents: 1033
diff changeset
   118
    ] ifFalse: [ 
1639
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   119
1612
ba527b3b17aa - fixes for Package.getPackage()
vranyj1
parents: 1581
diff changeset
   120
        binding setVariable: 'this' to: receiver.
ba527b3b17aa - fixes for Package.getPackage()
vranyj1
parents: 1581
diff changeset
   121
        binding setVariable: 'self' to: receiver.
ba527b3b17aa - fixes for Package.getPackage()
vranyj1
parents: 1581
diff changeset
   122
        context notNil ifTrue:[
1626
715cd7e0e518 - fixes in exception handling
vranyj1
parents: 1612
diff changeset
   123
            | pc |
715cd7e0e518 - fixes in exception handling
vranyj1
parents: 1612
diff changeset
   124
1612
ba527b3b17aa - fixes for Package.getPackage()
vranyj1
parents: 1581
diff changeset
   125
            binding setVariable: 'thisContext' to: context.
1626
715cd7e0e518 - fixes in exception handling
vranyj1
parents: 1612
diff changeset
   126
            pc := context pc.
715cd7e0e518 - fixes in exception handling
vranyj1
parents: 1612
diff changeset
   127
            context method localVariableTable do:[:entry|
715cd7e0e518 - fixes in exception handling
vranyj1
parents: 1612
diff changeset
   128
                (pc between: entry startPC and: entry endPC) ifTrue:[
715cd7e0e518 - fixes in exception handling
vranyj1
parents: 1612
diff changeset
   129
                    binding setVariable: entry name to: (context at: entry slot + 1)
715cd7e0e518 - fixes in exception handling
vranyj1
parents: 1612
diff changeset
   130
                ].
715cd7e0e518 - fixes in exception handling
vranyj1
parents: 1612
diff changeset
   131
            ].
1612
ba527b3b17aa - fixes for Package.getPackage()
vranyj1
parents: 1581
diff changeset
   132
        ]
ba527b3b17aa - fixes for Package.getPackage()
vranyj1
parents: 1581
diff changeset
   133
1044
84b7d94d9eb8 Java Workspace now share same binding (i.e., workspace variables are remembered)
vranyj1
parents: 1033
diff changeset
   134
    ].
84b7d94d9eb8 Java Workspace now share same binding (i.e., workspace variables are remembered)
vranyj1
parents: 1033
diff changeset
   135
1639
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   136
    result := self evaluate: source withBinding: binding.
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   137
    ^ result class javaUnwrap: result.
918
73bd57f8d3b0 - fixes in natives (reflective support for fields)
vranyj1
parents: 917
diff changeset
   138
73bd57f8d3b0 - fixes in natives (reflective support for fields)
vranyj1
parents: 917
diff changeset
   139
    "Created: / 17-08-2011 / 08:54:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
73bd57f8d3b0 - fixes in natives (reflective support for fields)
vranyj1
parents: 917
diff changeset
   140
!
73bd57f8d3b0 - fixes in natives (reflective support for fields)
vranyj1
parents: 917
diff changeset
   141
1639
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   142
evaluate: source withBinding: binding
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   143
    "Given a binding, evaluates given a code"
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   144
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   145
    | shell result |
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   146
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   147
    [
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   148
        shell := (Java classForName: 'groovy.lang.GroovyShell') newCleared.
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   149
        shell perform: #'<init>(Lgroovy/lang/Binding;)V' with: binding.
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   150
        result := shell 
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   151
                    perform: #'evaluate(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/Object;'
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   152
                    with: (Java as_String: source string)
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   153
                    with: (Java as_String: 'doIt')
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   154
    ] on: JAVA org codehaus groovy control CompilationFailedException do:[:ex|
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   155
        self syntaxError: ex.    
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   156
    ].
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   157
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   158
    ^ result class javaUnwrap: result.
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   159
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   160
    "Created: / 21-08-2012 / 14:08:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   161
!
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   162
917
ecd1a00132f1 - added JavaEvaluator
vranyj1
parents:
diff changeset
   163
moreSharedPools: pools
ecd1a00132f1 - added JavaEvaluator
vranyj1
parents:
diff changeset
   164
ecd1a00132f1 - added JavaEvaluator
vranyj1
parents:
diff changeset
   165
    "Ignored for Java"
ecd1a00132f1 - added JavaEvaluator
vranyj1
parents:
diff changeset
   166
ecd1a00132f1 - added JavaEvaluator
vranyj1
parents:
diff changeset
   167
    "Created: / 16-08-2011 / 10:15:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
ecd1a00132f1 - added JavaEvaluator
vranyj1
parents:
diff changeset
   168
! !
ecd1a00132f1 - added JavaEvaluator
vranyj1
parents:
diff changeset
   169
1639
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   170
!GroovyEvaluator methodsFor:'error reporting'!
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   171
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   172
syntaxError: exception
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   173
    | error cause |
1202
7d9f24940ed5 - JavaVM: fix in method/ctor invocation using reflection
vranyj1
parents: 1155
diff changeset
   174
1639
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   175
    error := exception getErrorCollector getError: 0.
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   176
    cause := error getCause.
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   177
    self syntaxError: exception cause: cause.
1202
7d9f24940ed5 - JavaVM: fix in method/ctor invocation using reflection
vranyj1
parents: 1155
diff changeset
   178
1639
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   179
    "Created: / 21-08-2012 / 14:17:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   180
!
1202
7d9f24940ed5 - JavaVM: fix in method/ctor invocation using reflection
vranyj1
parents: 1155
diff changeset
   181
1639
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   182
syntaxError:message cause: cause
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   183
    "Notify requestor of an error - if there is no requestor
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   184
     put it on the transcript. Requestor is typically the CodeView
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   185
     in which the accept/doIt was triggered, or the PositionableStream
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   186
     which does the fileIn. The requestor may decide how to highlight the
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   187
     error (and/or to abort the compile).
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   188
     Return the result passed back by the requestor."
1202
7d9f24940ed5 - JavaVM: fix in method/ctor invocation using reflection
vranyj1
parents: 1155
diff changeset
   189
1639
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   190
    | sourceStream startCol endCol |
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   191
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   192
    (Smalltalk isInitialized not and:[Smalltalk isStandAloneDebug]) ifTrue:[
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   193
        "/ error during startup, but sometimes we expect an error and want to supress it
1656
c6fee8f3a640 - fixes for Groovy-Smalltalk interop - SmalltalkEvaluator example works
vranyj1
parents: 1649
diff changeset
   194
        (Smalltalk at:#Parser) parseWarningSignal query ~~ #ignore ifTrue:[
1639
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   195
            thisContext fullPrintAll.
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   196
        ].
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   197
    ].
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   198
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   199
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   200
    "/ backward compatibility - will vanish eventually (use a handler, Luke)
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   201
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   202
    sourceStream := source string readStream.
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   203
    cause getLine - 1 timesRepeat:[ sourceStream nextLine ].
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   204
    startCol := sourceStream position - 1 + cause getStartColumn.
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   205
    endCol := sourceStream position - 1 + cause getEndColumn.
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   206
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   207
    (requestor notNil and:[requestor isTextView]) ifTrue:[
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   208
        requestor error: cause getOriginalMessage position: startCol to: endCol from: self.
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   209
        ^ self
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   210
    ].
1656
c6fee8f3a640 - fixes for Groovy-Smalltalk interop - SmalltalkEvaluator example works
vranyj1
parents: 1649
diff changeset
   211
    (Smalltalk at:#'Parser::ParseError') isHandled ifTrue:[
c6fee8f3a640 - fixes for Groovy-Smalltalk interop - SmalltalkEvaluator example works
vranyj1
parents: 1649
diff changeset
   212
        (Smalltalk at:#'Parser::ParseError') new
1639
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   213
            errorMessage: cause getOriginalMessage startPosition:startCol endPosition:endCol;
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   214
            parameter:self;
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   215
            lineNumber:cause getLine;
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   216
            raiseRequest.
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   217
    ].
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   218
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   219
    "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
   220
! !
7d9f24940ed5 - JavaVM: fix in method/ctor invocation using reflection
vranyj1
parents: 1155
diff changeset
   221
1370
0708027f69b0 oops, class rename failed. Fixed now
vranyj1
parents: 1368
diff changeset
   222
!GroovyEvaluator class methodsFor:'documentation'!
917
ecd1a00132f1 - added JavaEvaluator
vranyj1
parents:
diff changeset
   223
1864
60a8dc26c8c6 Updated from HG
vranyj1
parents: 1818
diff changeset
   224
version_HG
60a8dc26c8c6 Updated from HG
vranyj1
parents: 1818
diff changeset
   225
60a8dc26c8c6 Updated from HG
vranyj1
parents: 1818
diff changeset
   226
    ^ '$Changeset: <not expanded> $'
60a8dc26c8c6 Updated from HG
vranyj1
parents: 1818
diff changeset
   227
!
60a8dc26c8c6 Updated from HG
vranyj1
parents: 1818
diff changeset
   228
917
ecd1a00132f1 - added JavaEvaluator
vranyj1
parents:
diff changeset
   229
version_SVN
1864
60a8dc26c8c6 Updated from HG
vranyj1
parents: 1818
diff changeset
   230
    ^ '§Id§'
917
ecd1a00132f1 - added JavaEvaluator
vranyj1
parents:
diff changeset
   231
! !