71
|
1 |
"{ Package: 'stx:goodies/builder/reports' }"
|
|
2 |
|
|
3 |
"{ NameSpace: Builder }"
|
|
4 |
|
|
5 |
Report subclass:#LintReport
|
|
6 |
instanceVariableNames:'environment rules'
|
|
7 |
classVariableNames:''
|
|
8 |
poolDictionaries:''
|
|
9 |
category:'Builder-Reports'
|
|
10 |
!
|
|
11 |
|
|
12 |
|
|
13 |
!LintReport class methodsFor:'class initialization'!
|
|
14 |
|
|
15 |
initialize
|
|
16 |
|
|
17 |
Smalltalk loadPackage: 'stx:goodies/refactoryBrowser/lint'.
|
|
18 |
|
|
19 |
"Modified: / 01-04-2011 / 12:58:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
20 |
! !
|
|
21 |
|
|
22 |
!LintReport methodsFor:'accessing - defaults'!
|
|
23 |
|
|
24 |
defaultFileSuffix
|
|
25 |
|
|
26 |
^ 'Lint'
|
|
27 |
|
|
28 |
"Modified: / 08-10-2011 / 10:49:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
29 |
!
|
|
30 |
|
|
31 |
defaultFormat
|
|
32 |
"raise an error: must be redefined in concrete subclass(es)"
|
|
33 |
|
|
34 |
^ LintReportFormat::PMD new
|
|
35 |
|
|
36 |
"Modified: / 25-11-2011 / 22:06:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
37 |
! !
|
|
38 |
|
|
39 |
!LintReport methodsFor:'generating'!
|
|
40 |
|
|
41 |
generateClass: aClass
|
|
42 |
| sourceStream sourceName |
|
|
43 |
sourceStream := WriteStream on: String new.
|
|
44 |
sourceName := self encodeFilename: (self sourceFilenameFor: aClass).
|
|
45 |
|
|
46 |
format writeFile: sourceName with: [
|
|
47 |
self generateClass: aClass source: sourceStream.
|
|
48 |
self generateClass: aClass class source: sourceStream.
|
|
49 |
].
|
|
50 |
|
|
51 |
format writeSource: sourceStream contents to: sourceName
|
|
52 |
|
|
53 |
"Created: / 06-10-2011 / 23:54:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
54 |
!
|
|
55 |
|
|
56 |
generateClass: aClass selector: aSelector source: sourceStream
|
|
57 |
| offset source matching |
|
|
58 |
offset := self
|
|
59 |
lineAndColumn: sourceStream contents
|
|
60 |
at: sourceStream position.
|
|
61 |
sourceStream
|
|
62 |
nextPutAll: (source := self convert: (aClass sourceCodeAt: aSelector));
|
|
63 |
nextPut: Character lf; nextPut: Character lf.
|
|
64 |
matching := rules select: [ :each |
|
|
65 |
(self isSelectorEnvironment: each result)
|
|
66 |
and: [ each result includesSelector: aSelector in: aClass ] ].
|
|
67 |
self generateViolations: matching class: aClass selector: aSelector source: source offset: offset
|
|
68 |
|
|
69 |
"Created: / 07-10-2011 / 11:04:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
70 |
!
|
|
71 |
|
|
72 |
generateClass: aClass source: sourceStream
|
|
73 |
|
|
74 |
| offset source matching |
|
|
75 |
offset := self
|
|
76 |
lineAndColumn: sourceStream contents
|
|
77 |
at: sourceStream position.
|
|
78 |
sourceStream
|
|
79 |
nextPutAll: (source := self convert: aClass definition);
|
|
80 |
nextPut: Character lf; nextPut: Character lf.
|
|
81 |
(environment definesClass: aClass) ifTrue: [
|
|
82 |
matching := rules select: [ :rule |
|
|
83 |
(self isClassEnvironment: rule result)
|
|
84 |
and: [ rule result includesClass: aClass ] ].
|
|
85 |
self generateViolations: matching class: aClass selector: nil source: source offset: offset ].
|
|
86 |
(environment selectorsForClass: aClass) asSortedCollection
|
|
87 |
do: [ :selector | self generateClass: aClass selector: selector source: sourceStream]
|
|
88 |
|
|
89 |
"Created: / 07-10-2011 / 10:29:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
90 |
!
|
|
91 |
|
|
92 |
generateViolations: aCollection class: aClass selector: aSelector source: aString offset: aPoint
|
|
93 |
|
|
94 |
aCollection do: [ :rule |
|
|
95 |
| interval start stop |
|
|
96 |
|
|
97 |
interval := (rule result selectionIntervalFor: aString) ifNil: [ 1 to: aString size ].
|
|
98 |
start := self lineAndColumn: aString at: interval first.
|
|
99 |
stop := self lineAndColumn: aString at: interval last.
|
|
100 |
|
|
101 |
format writeViolation: rule
|
|
102 |
class: aClass selector: aSelector
|
|
103 |
startLine: aPoint x + start x column: aPoint y + start y - 1
|
|
104 |
stopLine: aPoint x + stop x column: aPoint y + stop y - 1.
|
|
105 |
]
|
|
106 |
|
|
107 |
"Created: / 25-11-2011 / 22:23:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
108 |
! !
|
|
109 |
|
|
110 |
!LintReport methodsFor:'initialization'!
|
|
111 |
|
|
112 |
setupForClasses: classes
|
|
113 |
|
|
114 |
environment := BrowserEnvironment new forClasses: classes.
|
|
115 |
environment label: name
|
|
116 |
|
|
117 |
"Created: / 04-08-2011 / 14:40:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
118 |
!
|
|
119 |
|
|
120 |
setupForPackages: packages
|
|
121 |
|
|
122 |
environment := PackageEnvironment
|
|
123 |
onEnvironment: BrowserEnvironment new
|
|
124 |
packageNames: packages.
|
|
125 |
|
|
126 |
environment label: name.
|
|
127 |
|
|
128 |
"
|
|
129 |
LintReport runPackage:'stx:goodies/monticello'.
|
|
130 |
LintReport runPackage:'stx:libjava'
|
|
131 |
"
|
|
132 |
|
|
133 |
"Created: / 04-08-2011 / 14:40:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
134 |
! !
|
|
135 |
|
|
136 |
!LintReport methodsFor:'private'!
|
|
137 |
|
|
138 |
lineAndColumn: aString at: anInteger
|
|
139 |
| line last stream |
|
|
140 |
line := 1.
|
|
141 |
last := 0.
|
|
142 |
stream := aString readStream.
|
|
143 |
[ (stream nextLine isNil or: [ anInteger <= stream position ])
|
|
144 |
ifTrue: [ ^ line @ (anInteger - last) ].
|
|
145 |
last := stream position.
|
|
146 |
line := line + 1 ]
|
|
147 |
repeat
|
|
148 |
!
|
|
149 |
|
|
150 |
sourceFilenameFor: aClass
|
|
151 |
|
|
152 |
| fn |
|
|
153 |
|
|
154 |
fn := aClass package asString replaceAll:$: with:$_;replaceAll:$/ with:$_.
|
|
155 |
fn := fn , '_' , (aClass asString copyReplaceAll:$: with: $_), '.' , aClass programmingLanguage sourceFileSuffix.
|
|
156 |
|
|
157 |
^self encodeFilename: fn.
|
|
158 |
|
|
159 |
"
|
|
160 |
Builder::LintReportFormat::CheckStyle basicNew
|
|
161 |
sourceFilenameFor: Class
|
|
162 |
|
|
163 |
Builder::LintReportFormat::CheckStyle basicNew
|
|
164 |
sourceFilenameFor: Builder::LintReportFormat
|
|
165 |
"
|
|
166 |
|
|
167 |
"Created: / 07-10-2011 / 09:06:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
168 |
! !
|
|
169 |
|
|
170 |
!LintReport methodsFor:'running'!
|
|
171 |
|
|
172 |
runReport
|
|
173 |
|
|
174 |
SmalllintChecker
|
|
175 |
runRule: (RBCompositeLintRule rules: rules)
|
|
176 |
onEnvironment: environment.
|
|
177 |
|
|
178 |
(environment classes asSortedCollection: [ :a :b | a name <= b name ])
|
|
179 |
do: [ :class | self generateClass: class].
|
|
180 |
|
|
181 |
"Modified (format): / 07-10-2011 / 10:48:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
182 |
!
|
|
183 |
|
|
184 |
setUp
|
|
185 |
|
|
186 |
super setUp.
|
|
187 |
rules := (RBCompositeLintRule rulesFor: RBBasicLintRule)
|
|
188 |
reject: [ :each | each class name endsWith: 'SpellingRule' ]
|
|
189 |
|
|
190 |
"Created: / 04-08-2011 / 14:35:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
|
|
191 |
! !
|
|
192 |
|
|
193 |
!LintReport methodsFor:'testing'!
|
|
194 |
|
|
195 |
isClassEnvironment: anEnvironment
|
|
196 |
^ #(CategoryEnvironment ClassEnvironment VariableEnvironment) includes: anEnvironment class name
|
|
197 |
!
|
|
198 |
|
|
199 |
isSelectorEnvironment: anEnvironment
|
|
200 |
^ #(SelectorEnvironment ParseTreeEnvironment VariableEnvironment) includes: anEnvironment class name
|
|
201 |
! !
|
|
202 |
|
|
203 |
!LintReport class methodsFor:'documentation'!
|
|
204 |
|
|
205 |
version
|
|
206 |
^ '$Header$'
|
|
207 |
!
|
|
208 |
|
|
209 |
version_CVS
|
|
210 |
^ '$Header$'
|
|
211 |
!
|
|
212 |
|
|
213 |
version_SVN
|
|
214 |
^ '§Id: Builder__LintReport.st 293 2011-11-25 21:42:31Z vranyj1 §'
|
|
215 |
! !
|
|
216 |
|
|
217 |
LintReport initialize!
|