File tree Expand file tree Collapse file tree 3 files changed +18
-13
lines changed
Expand file tree Collapse file tree 3 files changed +18
-13
lines changed Original file line number Diff line number Diff line change 11"
2- Bulk editor on a Java file : comment out a collection of methods
2+ Bulk editor on Java files : comment out or remove a collection of methods
33Can be applied for example on dead methods:
44- compute all dead methods in a file -> `deadMethodCollection`
55- call: `MiBulkEditor new runOn: deadMethodCollection.`
6- - Output the resulting lines in a file
6+
7+ The following will comment out or remove a list of methods from their respective source files
78```
89bulkEditor := MiBulkEditor new.
9- bulkEditor runOn: deadMethods.
10- file := 'SomeFile.java' asFileReference.
11- file ifExists: [ file delete ].
12- file writeStreamDo: [ :st | bulkEditor lines do: [ :line | st << line ; cr ] ].
10+ bulkEditor runOn: <deadMethodCollection>.
1311```
12+
13+ The default is to comment out the methods: `bulkEditor commentLines`
14+ The editor can be instructed to remove the methods from their files: `bulkEditor removeLines`
1415"
1516Class {
1617 #name : ' MiBulkEditor' ,
Original file line number Diff line number Diff line change @@ -86,7 +86,8 @@ MiSourceTextRendererModel >> addKeywordHighlight: anInterval [
8686
8787{ #category : ' highlights' }
8888MiSourceTextRendererModel >> clearHighlightsInComments [
89-
89+ " note: potential issue here as #clearNoncommentHighlightFrom:to: modifies the list of highlights
90+ However, it should remove only non-comment highlights, so in the end there is no harm done"
9091 self highlights copy do: [ :highlight |
9192 (highlight class = MiSourceTextCommentHighlight )
9293 ifTrue: [
@@ -142,6 +143,8 @@ MiSourceTextRendererModel >> createHighlights [
142143 self prepareSourceAnchorAdapter.
143144 self createKeywordHighlights.
144145 self createEntitiesHighlightsFor: entity.
146+ " bypassing bug in #createEntitiesHighlightsFor:"
147+ self highlights removeAllSuchThat: [ :hglght | hglght hasInterval not ].
145148 self clearHighlightsInComments
146149]
147150
@@ -163,7 +166,7 @@ MiSourceTextRendererModel >> createKeywordHighlights [
163166{ #category : ' highlights' }
164167MiSourceTextRendererModel >> createKeywordHighlightsFor: aKeyWord [
165168 " Search for a keyword in the displayedText and creates a keyWordHighlight for it
166- keywords should be whole words (after and before a word separator) or strat the text or end it"
169+ keywords should be whole words (after and before a word separator) or start the text or end it"
167170
168171 | matcher |
169172
Original file line number Diff line number Diff line change @@ -129,12 +129,17 @@ MiSourceTextRendererModelTest >> testHighlightChildWithIndexedFileAnchor [
129129
130130{ #category : ' tests - highlighting' }
131131MiSourceTextRendererModelTest >> testHighlightChildWithNoAnchor [
132+ " Although it uses FamixStClass and FamixStMethod, the code given in sourceAnchor is not
133+ formated as normal Pharo code.
134+ This is not a problem as long the entities' names are found in it"
135+
132136 | entity |
137+
133138 entity := FamixStClass new
134139 name: ' aClass' ;
135140 sourceAnchor: (self stubIndexedAnchorText:
136141' code of aClass {
137- code of aMethod()
142+ code of aClass >> aMethod()
138143}' ).
139144 FamixStMethod new
140145 name: ' aMethod' ;
@@ -147,10 +152,6 @@ MiSourceTextRendererModelTest >> testHighlightChildWithNoAnchor [
147152 self assert: highlight class equals: MiSourceTextIdentifierHighlight
148153 ].
149154
150- " one highlight has an interval, the other not"
151- self assert: (rendererModel highlights anySatisfy: #hasInterval ).
152- self assert: (rendererModel highlights anySatisfy: [ :highlight | highlight hasInterval not ]).
153-
154155]
155156
156157{ #category : ' tests - highlighting' }
You can’t perform that action at this time.
0 commit comments