src/GroovyCompiler.st
author vranyj1
Sat, 18 Feb 2012 23:18:47 +0000
branchjk_new_structure
changeset 1368 5f502e712403
child 1372 dea574a1b6b3
permissions -rw-r--r--
Groovy language support and integration
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
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    24
	instanceVariableNames:''
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
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    73
!GroovyCompiler class methodsFor:'compiler interface'!
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    74
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    75
compileClass: source
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    76
    "Compiles a new Groovy class given the source code"
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    77
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    78
    ^self new compileClass: source.
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    79
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    80
    "Created: / 18-02-2012 / 19:09:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    81
! !
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    82
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    83
!GroovyCompiler methodsFor:'compiler interface'!
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    84
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    85
compileClass: source
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    86
    "Compiles a new Groovy class given the source code"
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    87
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    88
    | jclass class |    
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    89
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    90
    jclass := GroovyClassLoader 
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    91
                perform: #'parseClass(Ljava/lang/String;)Ljava/lang/Class;'
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    92
                   with: (Java as_String: source).
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    93
    jclass isNil ifTrue:[ ^ nil ].
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    94
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    95
    class := JavaVM classForJavaClassObject: jclass.
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    96
    class setSource: source.
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    97
    ^class.
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    98
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
    99
    "Created: / 18-02-2012 / 19:12:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   100
! !
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   101
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   102
!GroovyCompiler methodsFor:'initialization'!
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   103
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   104
initialize
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   105
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   106
    self initializeGroovyClassLoader
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   107
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   108
    "Modified: / 18-02-2012 / 19:18:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   109
!
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   110
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   111
initializeGroovyClassLoader
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   112
    | groovy_lang_GroovyClassLoader |
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   113
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   114
    GroovyClassLoader notNil ifTrue:[ ^ self ].
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   115
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   116
    groovy_lang_GroovyClassLoader := Java classForName:'groovy.lang.GroovyClassLoader'.
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   117
    GroovyClassLoader := groovy_lang_GroovyClassLoader newCleared.
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   118
    GroovyClassLoader
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   119
            perform: #'<init>(Ljava/lang/ClassLoader;)V'
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   120
               with: JavaVM systemClassLoader.
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   121
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   122
    "
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   123
        GroovyClassLoader 
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   124
        GroovyCompiler basicNew initializeGroovyClassLoader.
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   125
        GroovyClassLoader := nil.
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   126
    "
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   127
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   128
    "Created: / 18-02-2012 / 19:14:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   129
! !
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   130
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   131
!GroovyCompiler class methodsFor:'documentation'!
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   132
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   133
version_SVN
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   134
    ^ '$Id$'
5f502e712403 Groovy language support and integration
vranyj1
parents:
diff changeset
   135
! !