Tools__LintHighlighter.st
changeset 10485 abd25bbd5625
child 10503 a01809c3af32
equal deleted inserted replaced
10484:efc1f0809373 10485:abd25bbd5625
       
     1 "{ Package: 'stx:libtool' }"
       
     2 
       
     3 "{ NameSpace: Tools }"
       
     4 
       
     5 Object subclass:#LintHighlighter
       
     6 	instanceVariableNames:'rules formattingMethod emphasisError emphasisInformation
       
     7 		emphasisWarning'
       
     8 	classVariableNames:''
       
     9 	poolDictionaries:''
       
    10 	category:'Interface-Lint'
       
    11 !
       
    12 
       
    13 
       
    14 !LintHighlighter methodsFor:'accessing'!
       
    15 
       
    16 rules
       
    17     ^ rules
       
    18 !
       
    19 
       
    20 rules:something
       
    21     rules := something.
       
    22 ! !
       
    23 
       
    24 !LintHighlighter methodsFor:'accessing-emphasis'!
       
    25 
       
    26 emphasisForError
       
    27 
       
    28     emphasisError isNil ifTrue:[
       
    29         emphasisError := Array 
       
    30             with: #underwave 
       
    31             with: #underlineColor -> Color red                    
       
    32     ].
       
    33     ^emphasisError
       
    34 
       
    35     "Created: / 05-08-2011 / 09:31:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    36 !
       
    37 
       
    38 emphasisForInformation
       
    39 
       
    40     emphasisInformation isNil ifTrue:[
       
    41         emphasisInformation := Array 
       
    42             with: #underwave 
       
    43             with: #underlineColor -> Color blue lighter                    
       
    44     ].
       
    45     ^emphasisInformation
       
    46 
       
    47     "Created: / 05-08-2011 / 09:31:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    48 !
       
    49 
       
    50 emphasisForSeverity: severity
       
    51 
       
    52     severity == #error ifTrue:[^self emphasisForError].
       
    53     severity == #information ifTrue:[^self emphasisForInformation].
       
    54 
       
    55     ^self emphasisForWarning
       
    56 
       
    57     "Created: / 05-08-2011 / 09:31:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    58 !
       
    59 
       
    60 emphasisForWarning
       
    61 
       
    62     emphasisWarning isNil ifTrue:[
       
    63         emphasisWarning := Array 
       
    64             with: #underwave 
       
    65             with: #underlineColor -> Color yellow darker                  
       
    66     ].
       
    67     ^emphasisWarning
       
    68 
       
    69     "Created: / 05-08-2011 / 09:31:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    70 ! !
       
    71 
       
    72 !LintHighlighter methodsFor:'formatting'!
       
    73 
       
    74 formatClassDefinition:source in:class
       
    75 
       
    76     formattingMethod := false.
       
    77     ^ self format: source
       
    78 
       
    79     "Created: / 04-08-2011 / 23:44:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    80 !
       
    81 
       
    82 formatClassDefinition:source in:class elementsInto: elements
       
    83 
       
    84     formattingMethod := false.
       
    85     ^ self format: source
       
    86 
       
    87     "Created: / 04-08-2011 / 23:44:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    88 !
       
    89 
       
    90 formatExpression:source in:class
       
    91 
       
    92     formattingMethod := false.
       
    93     ^ self format: source
       
    94 
       
    95     "Created: / 04-08-2011 / 23:45:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    96 !
       
    97 
       
    98 formatExpression:source in:class elementsInto: elements
       
    99 
       
   100     formattingMethod := false.
       
   101     ^ self format: source
       
   102 
       
   103     "Created: / 04-08-2011 / 23:43:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   104 !
       
   105 
       
   106 formatMethod:mth source:source in:class using: preferences
       
   107 
       
   108     formattingMethod := true.
       
   109     ^ self format: source
       
   110 
       
   111     "Created: / 04-08-2011 / 23:45:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   112 !
       
   113 
       
   114 formatMethod:mth source:source in:class using: preferences elementsInto: elements
       
   115 
       
   116     formattingMethod := true.
       
   117     ^ self format: source
       
   118 
       
   119     "Created: / 04-08-2011 / 23:42:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   120 ! !
       
   121 
       
   122 !LintHighlighter methodsFor:'formatting-private'!
       
   123 
       
   124 format: text
       
   125 
       
   126     rules ? #() do:[:rule|
       
   127         self format: text rule: rule
       
   128     ].
       
   129     ^text
       
   130 
       
   131     "Created: / 04-08-2011 / 23:51:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   132 !
       
   133 
       
   134 format: text rule: rule
       
   135 
       
   136     | string emphasis |
       
   137 
       
   138     string := text asString.
       
   139     emphasis := self emphasisForSeverity: rule severity.
       
   140 
       
   141     rule result isParseTreeEnvironment ifTrue:[
       
   142         formattingMethod ifTrue:[
       
   143             | interval |
       
   144             interval := rule result selectionIntervalFor: string.
       
   145             text emphasisFrom: interval first to: interval last 
       
   146                      add: emphasis.            
       
   147         ].
       
   148     ] ifFalse:[
       
   149         | searches |
       
   150 
       
   151         searches := rule result searchStrings asSet.
       
   152 
       
   153         searches do:[:search|
       
   154             | i |
       
   155             i := 1.
       
   156             [ 
       
   157                 i := string findString: search startingAt: i.
       
   158                 i ~~ 0
       
   159             ] whileTrue:[
       
   160                 text emphasisFrom: i to: i + search size - 1 
       
   161                      add: emphasis.
       
   162                 i := i + search size + 1.
       
   163             ]
       
   164             
       
   165 
       
   166         ]
       
   167     ]
       
   168 
       
   169     "Created: / 04-08-2011 / 23:55:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   170 ! !
       
   171 
       
   172 !LintHighlighter class methodsFor:'documentation'!
       
   173 
       
   174 version
       
   175     ^ '$Header: /cvs/stx/stx/libtool/Tools__LintHighlighter.st,v 1.1 2011-08-05 11:13:08 vrany Exp $'
       
   176 !
       
   177 
       
   178 version_CVS
       
   179     ^ '$Header: /cvs/stx/stx/libtool/Tools__LintHighlighter.st,v 1.1 2011-08-05 11:13:08 vrany Exp $'
       
   180 ! !