tools/JavaSourceHighlighter.st
branchdevelopment
changeset 2729 ac412f6ea6d4
parent 2726 6971720de5a4
child 2732 7d1a1fb5b01a
equal deleted inserted replaced
2728:658220e93dc9 2729:ac412f6ea6d4
   218 
   218 
   219     preferences := prefs.
   219     preferences := prefs.
   220     preferences isNil ifTrue:[
   220     preferences isNil ifTrue:[
   221         preferences := UserPreferences current.
   221         preferences := UserPreferences current.
   222     ].
   222     ].
       
   223 
       
   224     JavaMethod showFullSource ifTrue:[
       
   225         ^self formatClassDefinition: source in: class
       
   226     ].   
       
   227 
   223     sourceText := source asText.
   228     sourceText := source asText.
   224 
   229 
   225     self doLexicalHighlightingOnly ifTrue:[
   230     self doLexicalHighlightingOnly ifTrue:[
   226         scanner := Scanner for: source string.
   231         scanner := Scanner for: source string.
   227         scanner highlighter: self.
   232         scanner highlighter: self.
   229             [ scanner nextToken ~~ #EOF ] whileTrue.
   234             [ scanner nextToken ~~ #EOF ] whileTrue.
   230         ] on: Error do:[:ex|
   235         ] on: Error do:[:ex|
   231             ex
   236             ex
   232         ].
   237         ].
   233     ] ifFalse:[
   238     ] ifFalse:[
   234         | document parser marker nodes |
   239         | document type parser marker nodes debug |
   235 
   240 
   236         document := JavaSourceDocument cachedDocumentFor: class theNonMetaclass.
   241         document := JavaSourceDocument cachedDocumentFor: class theNonMetaclass.
   237         document isNil ifTrue:[
   242         document isNil ifTrue:[
   238             document := JavaSourceDocument for: class theNonMetaclass.
   243             document := JavaSourceDocument for: class theNonMetaclass.
   239             JavaSourceDocument cachedDocumentFor: class theNonMetaclass put: document.  
   244             JavaSourceDocument cachedDocumentFor: class theNonMetaclass put: document.  
   240         ].
   245         ].
   241 
   246 
       
   247 
       
   248         document resolve.
       
   249         type := document sourceTreeForClass: class theNonMetaclass.
   242         marker := Marker new.
   250         marker := Marker new.
   243         marker highlighter: self.     
   251         marker highlighter: self.     
   244         parser := (Java classForName:'stx.libjava.tools.source.JavaSourceHighlighter') new.
   252         parser := (Java classForName:'stx.libjava.tools.text.Highlighter') new.
   245         parser setMarker: marker.
   253         parser setMarker: marker.
   246         nodes := parser parseClassBodyDeclarations: source string from: 0 to: source size unit: document sourceTree.        
   254 
   247         nodes.
   255         debug :=  false.
       
   256         nodes := parser parseClassBodyDeclarations: source string unit: document sourceTree copy type: type copy resolve: debug.
       
   257         debug ifTrue:[
       
   258             nodes inspect.
       
   259         ]
   248     ].
   260     ].
   249     ^ sourceText
   261     ^ sourceText
   250 
   262 
   251     "Created: / 04-08-2011 / 23:45:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   263     "Created: / 04-08-2011 / 23:45:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   252     "Modified: / 09-09-2013 / 02:35:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   264     "Modified: / 14-09-2013 / 11:57:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   253 !
   265 !
   254 
   266 
   255 formatMethod:mth source:source in:class using: prefs elementsInto: els
   267 formatMethod:mth source:source in:class using: prefs elementsInto: els
   256 
   268 
   257     preferences := prefs.
   269     preferences := prefs.
   320         [
   332         [
   321             [ scanner nextToken ~~ #EOF ] whileTrue.
   333             [ scanner nextToken ~~ #EOF ] whileTrue.
   322         ] on: Error do:[:ex|
   334         ] on: Error do:[:ex|
   323         ].  
   335         ].  
   324     ] ifFalse:[
   336     ] ifFalse:[
   325         sourceUnit := (Java classForName:'stx.libjava.tools.source.JavaSource') new.
   337         sourceUnit := (Java classForName:'stx.libjava.tools.Source') new.
   326         sourceUnit setContents: source string.
   338         sourceUnit setContents: source string.
   327         parser := (Java classForName:'stx.libjava.tools.source.JavaSourceHighlighter') new.
   339         parser := (Java classForName:'stx.libjava.tools.text.Highlighter') new.
   328         parser setMarker: marker.
   340         parser setMarker: marker.
   329         parser parse: sourceUnit diet: false.
   341         parser parse: sourceUnit diet: false.
   330     ].
   342     ].
   331     
   343     
   332 
   344 
   339     ] ifFalse:[
   351     ] ifFalse:[
   340         sourceText
   352         sourceText
   341     ]
   353     ]
   342 
   354 
   343     "Created: / 17-03-2012 / 14:02:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   355     "Created: / 17-03-2012 / 14:02:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   344     "Modified: / 09-09-2013 / 10:26:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   356     "Modified: / 12-09-2013 / 01:02:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   345 ! !
   357 ! !
   346 
   358 
   347 !JavaSourceHighlighter methodsFor:'queries'!
   359 !JavaSourceHighlighter methodsFor:'queries'!
   348 
   360 
   349 doLexicalHighlightingOnly
   361 doLexicalHighlightingOnly