GroovyEvaluator.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:
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
1691
826f8d7dc0df thinlocks reintegrated
vranyj1
parents: 1656
diff changeset
    73
1581
70fbc03d2d82 Java reflection support refactoring - moved to use JavaMirrors
vranyj1
parents: 1478
diff changeset
    74
!GroovyEvaluator methodsFor:'accessing'!
1459
9e24f4337d78 Tests for finally
vranyj1
parents: 1370
diff changeset
    75
1581
70fbc03d2d82 Java reflection support refactoring - moved to use JavaMirrors
vranyj1
parents: 1478
diff changeset
    76
currentNameSpace: ns
1459
9e24f4337d78 Tests for finally
vranyj1
parents: 1370
diff changeset
    77
    ns notNil ifTrue:[
9e24f4337d78 Tests for finally
vranyj1
parents: 1370
diff changeset
    78
        self error:'Smalltalk namespaces not supported by Groovy'
9e24f4337d78 Tests for finally
vranyj1
parents: 1370
diff changeset
    79
    ].
9e24f4337d78 Tests for finally
vranyj1
parents: 1370
diff changeset
    80
1581
70fbc03d2d82 Java reflection support refactoring - moved to use JavaMirrors
vranyj1
parents: 1478
diff changeset
    81
    "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
    82
!
70fbc03d2d82 Java reflection support refactoring - moved to use JavaMirrors
vranyj1
parents: 1478
diff changeset
    83
70fbc03d2d82 Java reflection support refactoring - moved to use JavaMirrors
vranyj1
parents: 1478
diff changeset
    84
currentNamespace: ns
70fbc03d2d82 Java reflection support refactoring - moved to use JavaMirrors
vranyj1
parents: 1478
diff changeset
    85
    self currentNameSpace: ns
70fbc03d2d82 Java reflection support refactoring - moved to use JavaMirrors
vranyj1
parents: 1478
diff changeset
    86
1459
9e24f4337d78 Tests for finally
vranyj1
parents: 1370
diff changeset
    87
    "Created: / 07-04-2012 / 09:26:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
9e24f4337d78 Tests for finally
vranyj1
parents: 1370
diff changeset
    88
! !
9e24f4337d78 Tests for finally
vranyj1
parents: 1370
diff changeset
    89
1370
0708027f69b0 oops, class rename failed. Fixed now
vranyj1
parents: 1368
diff changeset
    90
!GroovyEvaluator methodsFor:'compiler interface'!
917
ecd1a00132f1 - added JavaEvaluator
vranyj1
parents:
diff changeset
    91
1691
826f8d7dc0df thinlocks reintegrated
vranyj1
parents: 1656
diff changeset
    92
evaluate:src
826f8d7dc0df thinlocks reintegrated
vranyj1
parents: 1656
diff changeset
    93
    | result |
971
937ed5f288a7 added: #evaluate:
vranyj1
parents: 960
diff changeset
    94
1691
826f8d7dc0df thinlocks reintegrated
vranyj1
parents: 1656
diff changeset
    95
    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
    96
    ^result.
971
937ed5f288a7 added: #evaluate:
vranyj1
parents: 960
diff changeset
    97
937ed5f288a7 added: #evaluate:
vranyj1
parents: 960
diff changeset
    98
    "Created: / 02-09-2011 / 10:24:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
937ed5f288a7 added: #evaluate:
vranyj1
parents: 960
diff changeset
    99
!
937ed5f288a7 added: #evaluate:
vranyj1
parents: 960
diff changeset
   100
1639
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   101
evaluate: sourceObj in: context receiver: receiver notifying: requestorObj logged: logged ifFail: fail 
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   102
    | binding result wsForWorkspace |
918
73bd57f8d3b0 - fixes in natives (reflective support for fields)
vranyj1
parents: 917
diff changeset
   103
1033
a31de6a4cfa4 refactoringl, moved registry to JavaVM
hlopkmar
parents: 972
diff changeset
   104
    JavaVM booted ifFalse: [
959
1f3342b2e728 Fixes...
vranyj1
parents: 918
diff changeset
   105
        Java initialize.
1f3342b2e728 Fixes...
vranyj1
parents: 918
diff changeset
   106
        JavaVM initializeVM.
1f3342b2e728 Fixes...
vranyj1
parents: 918
diff changeset
   107
    ].
1639
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   108
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   109
    requestor := requestorObj.
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   110
    source := sourceObj.
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   111
    wsForWorkspace := requestor notNil and: [ requestor application isKindOf: WorkspaceApplication ].
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   112
    binding := (Java classForName: 'groovy.lang.Binding') new.
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   113
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   114
    wsForWorkspace ifTrue: [
1044
84b7d94d9eb8 Java Workspace now share same binding (i.e., workspace variables are remembered)
vranyj1
parents: 1033
diff changeset
   115
        WorkspaceBinding isNil ifTrue: [
84b7d94d9eb8 Java Workspace now share same binding (i.e., workspace variables are remembered)
vranyj1
parents: 1033
diff changeset
   116
            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
   117
        ].
84b7d94d9eb8 Java Workspace now share same binding (i.e., workspace variables are remembered)
vranyj1
parents: 1033
diff changeset
   118
        binding := WorkspaceBinding
84b7d94d9eb8 Java Workspace now share same binding (i.e., workspace variables are remembered)
vranyj1
parents: 1033
diff changeset
   119
    ] ifFalse: [ 
1639
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   120
1612
ba527b3b17aa - fixes for Package.getPackage()
vranyj1
parents: 1581
diff changeset
   121
        binding setVariable: 'this' to: receiver.
ba527b3b17aa - fixes for Package.getPackage()
vranyj1
parents: 1581
diff changeset
   122
        binding setVariable: 'self' to: receiver.
ba527b3b17aa - fixes for Package.getPackage()
vranyj1
parents: 1581
diff changeset
   123
        context notNil ifTrue:[
1626
715cd7e0e518 - fixes in exception handling
vranyj1
parents: 1612
diff changeset
   124
            | pc |
715cd7e0e518 - fixes in exception handling
vranyj1
parents: 1612
diff changeset
   125
1612
ba527b3b17aa - fixes for Package.getPackage()
vranyj1
parents: 1581
diff changeset
   126
            binding setVariable: 'thisContext' to: context.
1626
715cd7e0e518 - fixes in exception handling
vranyj1
parents: 1612
diff changeset
   127
            pc := context pc.
715cd7e0e518 - fixes in exception handling
vranyj1
parents: 1612
diff changeset
   128
            context method localVariableTable do:[:entry|
715cd7e0e518 - fixes in exception handling
vranyj1
parents: 1612
diff changeset
   129
                (pc between: entry startPC and: entry endPC) ifTrue:[
715cd7e0e518 - fixes in exception handling
vranyj1
parents: 1612
diff changeset
   130
                    binding setVariable: entry name to: (context at: entry slot + 1)
715cd7e0e518 - fixes in exception handling
vranyj1
parents: 1612
diff changeset
   131
                ].
715cd7e0e518 - fixes in exception handling
vranyj1
parents: 1612
diff changeset
   132
            ].
1612
ba527b3b17aa - fixes for Package.getPackage()
vranyj1
parents: 1581
diff changeset
   133
        ]
ba527b3b17aa - fixes for Package.getPackage()
vranyj1
parents: 1581
diff changeset
   134
1044
84b7d94d9eb8 Java Workspace now share same binding (i.e., workspace variables are remembered)
vranyj1
parents: 1033
diff changeset
   135
    ].
84b7d94d9eb8 Java Workspace now share same binding (i.e., workspace variables are remembered)
vranyj1
parents: 1033
diff changeset
   136
1639
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   137
    result := self evaluate: source withBinding: binding.
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   138
    ^ result class javaUnwrap: result.
918
73bd57f8d3b0 - fixes in natives (reflective support for fields)
vranyj1
parents: 917
diff changeset
   139
73bd57f8d3b0 - fixes in natives (reflective support for fields)
vranyj1
parents: 917
diff changeset
   140
    "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
   141
!
73bd57f8d3b0 - fixes in natives (reflective support for fields)
vranyj1
parents: 917
diff changeset
   142
1639
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   143
evaluate: source withBinding: binding
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   144
    "Given a binding, evaluates given a code"
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   145
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   146
    | shell result |
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
    [
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   149
        shell := (Java classForName: 'groovy.lang.GroovyShell') newCleared.
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   150
        shell perform: #'<init>(Lgroovy/lang/Binding;)V' with: binding.
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   151
        result := shell 
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   152
                    perform: #'evaluate(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/Object;'
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   153
                    with: (Java as_String: source string)
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   154
                    with: (Java as_String: 'doIt')
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   155
    ] on: JAVA org codehaus groovy control CompilationFailedException do:[:ex|
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   156
        self syntaxError: ex.    
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
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   159
    ^ result class javaUnwrap: result.
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   160
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   161
    "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
   162
!
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   163
917
ecd1a00132f1 - added JavaEvaluator
vranyj1
parents:
diff changeset
   164
moreSharedPools: pools
ecd1a00132f1 - added JavaEvaluator
vranyj1
parents:
diff changeset
   165
ecd1a00132f1 - added JavaEvaluator
vranyj1
parents:
diff changeset
   166
    "Ignored for Java"
ecd1a00132f1 - added JavaEvaluator
vranyj1
parents:
diff changeset
   167
ecd1a00132f1 - added JavaEvaluator
vranyj1
parents:
diff changeset
   168
    "Created: / 16-08-2011 / 10:15:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
ecd1a00132f1 - added JavaEvaluator
vranyj1
parents:
diff changeset
   169
! !
ecd1a00132f1 - added JavaEvaluator
vranyj1
parents:
diff changeset
   170
1639
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   171
!GroovyEvaluator methodsFor:'error reporting'!
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   172
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   173
syntaxError: exception
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   174
    | error cause |
1202
7d9f24940ed5 - JavaVM: fix in method/ctor invocation using reflection
vranyj1
parents: 1155
diff changeset
   175
1639
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   176
    error := exception getErrorCollector getError: 0.
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   177
    cause := error getCause.
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   178
    self syntaxError: exception cause: cause.
1202
7d9f24940ed5 - JavaVM: fix in method/ctor invocation using reflection
vranyj1
parents: 1155
diff changeset
   179
1639
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   180
    "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
   181
!
1202
7d9f24940ed5 - JavaVM: fix in method/ctor invocation using reflection
vranyj1
parents: 1155
diff changeset
   182
1639
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   183
syntaxError:message cause: cause
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   184
    "Notify requestor of an error - if there is no requestor
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   185
     put it on the transcript. Requestor is typically the CodeView
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   186
     in which the accept/doIt was triggered, or the PositionableStream
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   187
     which does the fileIn. The requestor may decide how to highlight the
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   188
     error (and/or to abort the compile).
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   189
     Return the result passed back by the requestor."
1202
7d9f24940ed5 - JavaVM: fix in method/ctor invocation using reflection
vranyj1
parents: 1155
diff changeset
   190
1639
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   191
    | sourceStream startCol endCol |
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   192
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   193
    (Smalltalk isInitialized not and:[Smalltalk isStandAloneDebug]) ifTrue:[
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   194
        "/ 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
   195
        (Smalltalk at:#Parser) parseWarningSignal query ~~ #ignore ifTrue:[
1639
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   196
            thisContext fullPrintAll.
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
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   201
    "/ backward compatibility - will vanish eventually (use a handler, Luke)
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   202
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   203
    sourceStream := source string readStream.
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   204
    cause getLine - 1 timesRepeat:[ sourceStream nextLine ].
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   205
    startCol := sourceStream position - 1 + cause getStartColumn.
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   206
    endCol := sourceStream position - 1 + cause getEndColumn.
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   207
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   208
    (requestor notNil and:[requestor isTextView]) ifTrue:[
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   209
        requestor error: cause getOriginalMessage position: startCol to: endCol from: self.
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   210
        ^ self
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   211
    ].
1656
c6fee8f3a640 - fixes for Groovy-Smalltalk interop - SmalltalkEvaluator example works
vranyj1
parents: 1649
diff changeset
   212
    (Smalltalk at:#'Parser::ParseError') isHandled ifTrue:[
c6fee8f3a640 - fixes for Groovy-Smalltalk interop - SmalltalkEvaluator example works
vranyj1
parents: 1649
diff changeset
   213
        (Smalltalk at:#'Parser::ParseError') new
1639
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   214
            errorMessage: cause getOriginalMessage startPosition:startCol endPosition:endCol;
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   215
            parameter:self;
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   216
            lineNumber:cause getLine;
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   217
            raiseRequest.
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
1397423bcd97 Better error reporting in Groovy workspace
vranyj1
parents: 1626
diff changeset
   220
    "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
   221
! !
7d9f24940ed5 - JavaVM: fix in method/ctor invocation using reflection
vranyj1
parents: 1155
diff changeset
   222
1370
0708027f69b0 oops, class rename failed. Fixed now
vranyj1
parents: 1368
diff changeset
   223
!GroovyEvaluator class methodsFor:'documentation'!
917
ecd1a00132f1 - added JavaEvaluator
vranyj1
parents:
diff changeset
   224
ecd1a00132f1 - added JavaEvaluator
vranyj1
parents:
diff changeset
   225
version_SVN
ecd1a00132f1 - added JavaEvaluator
vranyj1
parents:
diff changeset
   226
    ^ '$Id$'
ecd1a00132f1 - added JavaEvaluator
vranyj1
parents:
diff changeset
   227
! !
1691
826f8d7dc0df thinlocks reintegrated
vranyj1
parents: 1656
diff changeset
   228