tools/JavaParser_Eclipse.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Thu, 03 Oct 2013 10:33:47 +0200
changeset 2762 5597a2c77cba
parent 2678 c865275e48a7
child 2731 13f5be2bf83b
permissions -rw-r--r--
Added GroovySourceHighlighter

"
 Copyright (c) 2010-2011 Jan Vrany, Jan Kurs & Marcel Hlopko,
                         SWING Research Group, Czech Technical University 
                         in Prague

 Permission is hereby granted, free of charge, to any person
 obtaining a copy of this software and associated documentation
 files (the 'Software'), to deal in the Software without
 restriction, including without limitation the rights to use,
 copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the
 Software is furnished to do so, subject to the following
 conditions:

 The above copyright notice and this permission notice shall be
 included in all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
"
"{ Package: 'stx:libjava/tools' }"

Object subclass:#JavaParser_Eclipse
	instanceVariableNames:'tree'
	classVariableNames:'ParseTreeCache'
	poolDictionaries:''
	category:'Languages-Java-Tools'
!

!JavaParser_Eclipse class methodsFor:'documentation'!

copyright
"
 Copyright (c) 2010-2011 Jan Vrany, Jan Kurs & Marcel Hlopko,
                         SWING Research Group, Czech Technical University 
                         in Prague

 Permission is hereby granted, free of charge, to any person
 obtaining a copy of this software and associated documentation
 files (the 'Software'), to deal in the Software without
 restriction, including without limitation the rights to use,
 copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the
 Software is furnished to do so, subject to the following
 conditions:

 The above copyright notice and this permission notice shall be
 included in all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.

"
! !

!JavaParser_Eclipse class methodsFor:'class initialization'!

initialize

    ParseTreeCache := CacheDictionary new: 128.

    "Created: / 15-02-2012 / 00:58:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaParser_Eclipse methodsFor:'accessing'!

tree
    ^ tree
! !

!JavaParser_Eclipse methodsFor:'parsing'!

parseClass: class

    self assert: class isJavaClass.

    self parseClassSource: class source.

    "Created: / 16-12-2011 / 21:48:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

parseClassSource: source

    ^ParseTreeCache at: source ifAbsentPut:[self parse: source kind: #K_COMPILATION_UNIT].

    "Created: / 16-12-2011 / 21:49:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaParser_Eclipse methodsFor:'parsing-private'!

parse: source kind: kindSym

    | kind astParser |

    kindSym == #K_EXPRESSION ifTrue:[
        kind := 1
    ] ifFalse:[kindSym == #K_STATEMENTS ifTrue:[
        kind := 2        
    ] ifFalse:[kindSym == #K_CLASS_BODY_DECLARATIONS ifTrue:[
        kind := 4
    ] ifFalse:[kindSym == #K_COMPILATION_UNIT ifTrue:[
        kind := 8
    ] ifFalse:[
        self error: 'Unknown source kind'
    ]]]].

    astParser := (JavaVM classForName:'org.eclipse.jdt.core.dom.ASTParser') newParser: 3"AST.JLS3". 
    astParser setSource: source string.
    astParser setKind: kind.
    tree := astParser createAST: nil.
    ^tree

    "Created: / 16-12-2011 / 21:43:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaParser_Eclipse class methodsFor:'documentation'!

version_CVS
    ^ '$Header: /cvs/stx/stx/libjava/tools/JavaParser_Eclipse.st,v 1.3 2013-09-06 00:45:28 vrany Exp $'
!

version_HG

    ^ '$Changeset: <not expanded> $'
!

version_SVN
    ^ '§Id§'
! !


JavaParser_Eclipse initialize!