tools/JavaParser_Eclipse.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Wed, 16 Jan 2013 21:31:50 +0000
branchrefactoring-vmdata
changeset 1973 617e6a088dd1
parent 1879 7d232ff32dde
child 2069 75d40b7b986f
permissions -rw-r--r--
- JavaListInspectorView class: JavaListInspectorView - JavaFormalParameterNode class: JavaFormalParameterNode - JavaTypeNode class: JavaTypeNode - JavaScanner class: JavaScanner - JavaArrayTypeNode class: JavaArrayTypeNode - JavaParser class: JavaParser - JavaCommentNode class: JavaCommentNode - JavaIntTypeNode class: JavaIntTypeNode - JavaParseNodeBuilder class: JavaParseNodeBuilder - JavaMethodDeclaratorNode class: JavaMethodDeclaratorNode - JavaScannerBase class: JavaScannerBase - JavaFloatTypeNode class: JavaFloatTypeNode - JavaDocNode class: JavaDocNode - JavaClassOrInterfaceTypeNode class: JavaClassOrInterfaceTypeNode - stx_libjava_tools class: stx_libjava_tools - JavaSettingsApplication class: JavaSettingsApplication - JavaLongTypeNode class: JavaLongTypeNode - JavaParserII class: JavaParserII - JavaSourceReference class: JavaSourceReference - JavaCharTypeNode class: JavaCharTypeNode - JavaParser_Eclipse class: JavaParser_Eclipse - JavaSyntaxHighlighter class: JavaSyntaxHighlighter - JavaMethodNode class: JavaMethodNode - JavaBooleanTypeNode class: JavaBooleanTypeNode - JavaDoubleTypeNode class: JavaDoubleTypeNode - JavaSetInspectorView class: JavaSetInspectorView - JavaParseNode class: JavaParseNode - JavaVoidTypeNode class: JavaVoidTypeNode - JavaMapInspectorView class: JavaMapInspectorView - JavaParserI class: JavaParserI - extensions ...

"
 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_HG

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

version_SVN
    ^ '§Id§'
! !

JavaParser_Eclipse initialize!