tools/JavaSourceDocument.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

"{ Package: 'stx:libjava/tools' }"

Object subclass:#JavaSourceDocument
	instanceVariableNames:'javaClass sourceText sourceTree sourceIndex'
	classVariableNames:'Cache CacheSize'
	poolDictionaries:''
	category:'Languages-Java-Tools-Source'
!

!JavaSourceDocument class methodsFor:'documentation'!

documentation
"
    JavaSourceDocument object keeps various useful information about one source 
    file. In particular, it keeps parse tree and index for navigation/quickfix
    services.

    [author:]
        Jan Vrany <jan.vrany@fit.cvut.cz>

    [instance variables:]

    [class variables:]

    [see also:]

"
! !

!JavaSourceDocument class methodsFor:'initialization'!

initialize
    "Invoked at system start or when the class is dynamically loaded."

    "/ please change as required (and remove this comment)

    CacheSize := 25.
    Cache := OrderedCollection new: CacheSize * 2 "To avoid excessive shifting..."

    "Modified: / 30-08-2013 / 01:43:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaSourceDocument class methodsFor:'instance creation'!

for: aJavaClass
    ^self new javaClass: aJavaClass.

    "Created: / 30-08-2013 / 01:46:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaSourceDocument class methodsFor:'accessing'!

cachedDocumentFor: aJavaClass
    "Returns a cached document for given class or nil if no cached 
     document is found."

    Cache withIndexDo:[:document :index|
        document javaClass == aJavaClass ifTrue:[
            "/ Move that document towards the end so it'll be less likely
            "/ to be removed
            index < Cache size ifTrue:[
                Cache swap: index with: index + 1.                
            ].
            ^ document.
        ]
    ].
    ^ nil

    "Created: / 30-08-2013 / 01:27:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

cachedDocumentFor: aJavaClass put: aJavaSourceDocument
    "Stores given source document in the cache"

    self assert: aJavaSourceDocument javaClass == aJavaClass.
    Cache size = CacheSize ifTrue:[
        Cache removeFirst.
    ].
    Cache addLast: aJavaSourceDocument

    "Created: / 30-08-2013 / 01:42:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaSourceDocument methodsFor:'accessing'!

javaClass
    ^ javaClass
!

javaClass:aJavaClass
    javaClass := aJavaClass.
!

sourceIndex
    ^ sourceIndex
!

sourceIndex:aParseTreeIndex
    sourceIndex := aParseTreeIndex.
!

sourceText
    ^ sourceText
!

sourceText:aText
    sourceText := aText.
!

sourceTree
    ^ sourceTree
!

sourceTree:aJavaSourceNode
    sourceTree := aJavaSourceNode.
! !

!JavaSourceDocument methodsFor:'debugging'!

inspector2TabParseTree

    SmallSense::ParseNodeInspector notNil ifTrue:[
        ^self newInspector2Tab
            label: 'Parse Tree';
            priority: 35;
            application: (SmallSense::ParseNodeInspector new node: sourceTree source: sourceText)
    ].
    ^nil

    "Created: / 30-08-2013 / 01:59:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

inspector2Tabs
    | tabs |

    tabs := super inspector2Tabs.
    (SmallSense::ParseNodeInspector notNil and:[sourceTree notNil and:[sourceText notNil]]) ifTrue:[
        tabs := tabs , #(inspector2TabParseTree)
    ].
    ^tabs

    "Created: / 30-08-2013 / 02:00:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!JavaSourceDocument class methodsFor:'documentation'!

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

version_HG

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


JavaSourceDocument initialize!