tools/JavaSourceHighlighter.st
branchdevelopment
changeset 2735 e20dd8496371
parent 2733 3d97124aebf5
child 2738 a633a2e8e67e
equal deleted inserted replaced
2734:f56049613ff3 2735:e20dd8496371
    24 	instanceVariableNames:'preferences cachedStringEmphasis cachedStringColor sourceText
    24 	instanceVariableNames:'preferences cachedStringEmphasis cachedStringColor sourceText
    25 		sourceIndex'
    25 		sourceIndex'
    26 	classVariableNames:''
    26 	classVariableNames:''
    27 	poolDictionaries:''
    27 	poolDictionaries:''
    28 	category:'Languages-Java-Tools-Source'
    28 	category:'Languages-Java-Tools-Source'
       
    29 !
       
    30 
       
    31 Object subclass:#Indexer
       
    32 	instanceVariableNames:'index'
       
    33 	classVariableNames:''
       
    34 	poolDictionaries:''
       
    35 	privateIn:JavaSourceHighlighter
    29 !
    36 !
    30 
    37 
    31 Object subclass:#Marker
    38 Object subclass:#Marker
    32 	instanceVariableNames:'highlighter'
    39 	instanceVariableNames:'highlighter'
    33 	classVariableNames:'MARK_KEYWORD MARK_NUMBER MARK_STRING MARK_CHARACTER MARK_COMMENT
    40 	classVariableNames:'MARK_KEYWORD MARK_NUMBER MARK_STRING MARK_CHARACTER MARK_COMMENT
   311     cacheIt := kind == #start and: [class notNil].
   318     cacheIt := kind == #start and: [class notNil].
   312     cacheIt ifTrue:[
   319     cacheIt ifTrue:[
   313         document := JavaSourceDocument cachedDocumentFor: class theNonMetaclass.
   320         document := JavaSourceDocument cachedDocumentFor: class theNonMetaclass.
   314         document notNil ifTrue:[
   321         document notNil ifTrue:[
   315             (document sourceText notNil and:[document sourceText string = source]) ifTrue:[
   322             (document sourceText notNil and:[document sourceText string = source]) ifTrue:[
       
   323                 (sourceIndex notNil and:[document sourceTreeIndex notNil]) ifTrue:[
       
   324                      sourceIndex addAll: document sourceTreeIndex.
       
   325                 ].
   316                 ^ document sourceText copy.
   326                 ^ document sourceText copy.
   317             ].
   327             ].
       
   328         ] ifFalse:[
       
   329             document := JavaSourceDocument for: class theNonMetaclass.
       
   330             (sourceIndex isNil and:[SmallSense::ParseTreeIndex notNil]) ifTrue:[
       
   331                  sourceIndex := SmallSense::ParseTreeIndex new.
       
   332             ].
       
   333             JavaSourceDocument cachedDocumentFor: class theNonMetaclass put: document.  
   318         ].
   334         ].
   319         document := JavaSourceDocument for: class theNonMetaclass.
       
   320         JavaSourceDocument cachedDocumentFor: class theNonMetaclass put: document.  
       
   321     ].
   335     ].
   322     marker := Marker new.
   336     marker := Marker new.
   323     marker highlighter: self.
   337     marker highlighter: self.
   324 
   338 
   325     sourceText := source isText 
   339     sourceText := source isText 
   336     ] ifFalse:[
   350     ] ifFalse:[
   337         sourceUnit := (Java classForName:'stx.libjava.tools.Source') new.
   351         sourceUnit := (Java classForName:'stx.libjava.tools.Source') new.
   338         sourceUnit setContents: source string.
   352         sourceUnit setContents: source string.
   339         parser := (Java classForName:'stx.libjava.tools.text.Highlighter') new.
   353         parser := (Java classForName:'stx.libjava.tools.text.Highlighter') new.
   340         parser setMarker: marker.
   354         parser setMarker: marker.
       
   355         (sourceIndex notNil and:[sourceIndex isKindOf: SmallSense::ParseTreeIndex]) ifTrue:[
       
   356             | indexer |
       
   357 
       
   358             indexer := Indexer new.
       
   359             indexer index: sourceIndex.
       
   360             parser setIndexer: indexer.
       
   361         ].
   341         parser parse: sourceUnit diet: false resolve: true.
   362         parser parse: sourceUnit diet: false resolve: true.
   342     ].
   363     ].
   343     
   364     
   344 
   365 
   345 
   366 
   346 
   367 
   347 
   368 
   348     ^ cacheIt ifTrue:[
   369     ^ cacheIt ifTrue:[
   349         document sourceText: sourceText.
   370         document sourceText: sourceText.
       
   371         document sourceTreeIndex: sourceIndex.
   350         sourceText copy
   372         sourceText copy
   351     ] ifFalse:[
   373     ] ifFalse:[
   352         sourceText
   374         sourceText
   353     ]
   375     ]
   354 
   376 
   355     "Created: / 17-03-2012 / 14:02:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   377     "Created: / 17-03-2012 / 14:02:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   356     "Modified: / 12-09-2013 / 01:02:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   378     "Modified: / 17-09-2013 / 01:31:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   357 ! !
   379 ! !
   358 
   380 
   359 !JavaSourceHighlighter methodsFor:'queries'!
   381 !JavaSourceHighlighter methodsFor:'queries'!
   360 
   382 
   361 doLexicalHighlightingOnly
   383 doLexicalHighlightingOnly
   695 
   717 
   696     "Created: / 16.4.1998 / 18:49:34 / cg"
   718     "Created: / 16.4.1998 / 18:49:34 / cg"
   697     "Modified: / 4.3.1999 / 12:56:13 / cg"
   719     "Modified: / 4.3.1999 / 12:56:13 / cg"
   698 ! !
   720 ! !
   699 
   721 
       
   722 !JavaSourceHighlighter::Indexer class methodsFor:'initialization'!
       
   723 
       
   724 initialize
       
   725     "Invoked at system start or when the class is dynamically loaded."
       
   726 
       
   727     self lookupObject: JavaLookup instance.
       
   728 
       
   729 
       
   730     "/ please change as required (and remove this comment)
       
   731 
       
   732     "Modified: / 17-09-2013 / 01:33:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   733 ! !
       
   734 
       
   735 
       
   736 !JavaSourceHighlighter::Indexer methodsFor:'accessing'!
       
   737 
       
   738 index
       
   739     ^ index
       
   740 !
       
   741 
       
   742 index:aParseTreeIndex
       
   743     index := aParseTreeIndex.
       
   744 ! !
       
   745 
       
   746 !JavaSourceHighlighter::Indexer methodsFor:'indexing'!
       
   747 
       
   748 index: node from: start to: stop
       
   749 
       
   750     index add: (index newElementFor: node)
       
   751 
       
   752     "Created: / 17-09-2013 / 01:08:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   753 ! !
       
   754 
   700 !JavaSourceHighlighter::Marker class methodsFor:'initialization'!
   755 !JavaSourceHighlighter::Marker class methodsFor:'initialization'!
   701 
   756 
   702 initialize
   757 initialize
   703     "Invoked at system start or when the class is dynamically loaded."
   758     "Invoked at system start or when the class is dynamically loaded."
   704 
   759 
   880 version_SVN
   935 version_SVN
   881     ^ 'Id'
   936     ^ 'Id'
   882 ! !
   937 ! !
   883 
   938 
   884 
   939 
       
   940 JavaSourceHighlighter::Indexer initialize!
   885 JavaSourceHighlighter::Marker initialize!
   941 JavaSourceHighlighter::Marker initialize!