--- a/tools/JavaLintHighlighter.st Fri Oct 04 08:59:25 2013 +0100
+++ b/tools/JavaLintHighlighter.st Fri Oct 04 12:22:42 2013 +0100
@@ -12,7 +12,7 @@
"{ Package: 'stx:libjava/tools' }"
Object subclass:#JavaLintHighlighter
- instanceVariableNames:'problems class annotations formattingMethod emphasisError
+ instanceVariableNames:'sourceIndex class annotations formattingMethod emphasisError
emphasisInformation emphasisWarning'
classVariableNames:''
poolDictionaries:''
@@ -39,17 +39,6 @@
annotations
^ annotations
-!
-
-problems
- ^ problems
-!
-
-problems:aCollection
- self reset.
- problems := aCollection.
-
- "Modified: / 20-09-2013 / 03:16:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!JavaLintHighlighter methodsFor:'accessing-emphasis'!
@@ -128,10 +117,11 @@
formatClassDefinition:source in:jclass elementsInto: elements
class := jclass.
+ sourceIndex := elements.
^ self format: source
"Created: / 04-08-2011 / 23:44:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 15-04-2013 / 23:27:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 04-10-2013 / 10:37:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
formatExpression:source in:jclass
@@ -162,23 +152,34 @@
formatMethod:mth source:source in:jclass using: preferences elementsInto: elements
class := jclass.
+ sourceIndex := elements.
^ self format: source
"Created: / 04-08-2011 / 23:42:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 15-04-2013 / 23:28:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 04-10-2013 / 10:37:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!JavaLintHighlighter methodsFor:'formatting-private'!
-format: text
- ^ problems notEmptyOrNil ifTrue:[
- self format: text problems: problems
- ] ifFalse:[
- text
- ]
+format: text
+ | problems |
+
+ "/ Fetch problems from Java parse tree
+ sourceIndex notNil ifTrue: [
+ | tree |
+
+ tree := sourceIndex perform: #tree ifNotUnderstood: [ nil ].
+ tree notNil ifTrue: [
+ self reset.
+ problems := tree compilationResult problems.
+ ].
+ ].
+ ^ problems notEmptyOrNil
+ ifTrue: [ self format: text problems: problems ]
+ ifFalse: [ text ]
"Created: / 04-08-2011 / 23:51:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 21-09-2013 / 05:07:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified (comment): / 04-10-2013 / 10:45:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
format: source problem: problem
@@ -205,21 +206,27 @@
problems isEmptyOrNil ifTrue:[ ^ givenSource ].
source := givenSource deepCopy.
problems do:[:problem|
- self format: source problem: problem.
+ "/ `problem` may be nil, the reporter allocates
+ "/ larger array ot avoid reallocation each time a
+ "/ problem is added. We do not trim the array to avoid
+ "/ extra array creation
+ problem notNil ifTrue:[
+ self format: source problem: problem.
+ ].
].
^source
"Created: / 15-04-2013 / 22:11:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 04-10-2013 / 10:45:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!JavaLintHighlighter methodsFor:'initialization'!
reset
annotations := OrderedCollection new.
- problems := #().
"Created: / 18-02-2012 / 22:54:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 16-09-2013 / 13:48:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+ "Modified: / 04-10-2013 / 10:45:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !
!JavaLintHighlighter methodsFor:'markup'!