Skip to content

Commit 45ed982

Browse files
Perform clean code of bundles/org.eclipse.jface.text
1 parent b431a28 commit 45ed982

File tree

131 files changed

+4190
-2304
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

131 files changed

+4190
-2304
lines changed

bundles/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/AnnotationBag.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ public AnnotationBag(String type) {
4747
* @param annotation the annotation to add
4848
*/
4949
public void add(Annotation annotation) {
50-
if (fAnnotations == null)
50+
if (fAnnotations == null) {
5151
fAnnotations= new HashSet<>(2);
52+
}
5253
fAnnotations.add(annotation);
5354
}
5455

@@ -60,8 +61,9 @@ public void add(Annotation annotation) {
6061
public void remove(Annotation annotation) {
6162
if (fAnnotations != null) {
6263
fAnnotations.remove(annotation);
63-
if (fAnnotations.isEmpty())
64+
if (fAnnotations.isEmpty()) {
6465
fAnnotations= null;
66+
}
6567
}
6668
}
6769

@@ -82,8 +84,9 @@ public boolean isEmpty() {
8284
* @since 3.1
8385
*/
8486
public Iterator<Annotation> iterator() {
85-
if (!isEmpty())
87+
if (!isEmpty()) {
8688
return fAnnotations.iterator();
89+
}
8790
return null;
8891
}
8992
}

bundles/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/ProjectionAnnotationHover.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,11 @@ private boolean isCaptionLine(Position position, IDocument document, int line) {
7676
if (position.getOffset() > -1 && position.getLength() > -1) {
7777
try {
7878
int captionOffset;
79-
if (position instanceof IProjectionPosition)
79+
if (position instanceof IProjectionPosition) {
8080
captionOffset= ((IProjectionPosition) position).computeCaptionOffset(document);
81-
else
81+
} else {
8282
captionOffset= 0;
83+
}
8384
int startLine= document.getLineOfOffset(position.getOffset() + captionOffset);
8485
return line == startLine;
8586
} catch (BadLocationException x) {
@@ -104,15 +105,18 @@ private String getProjectionTextAtLine(ISourceViewer viewer, int line, int numbe
104105
Iterator<Annotation> e= model.getAnnotationIterator();
105106
while (e.hasNext()) {
106107
ProjectionAnnotation annotation= (ProjectionAnnotation) e.next();
107-
if (!annotation.isCollapsed())
108+
if (!annotation.isCollapsed()) {
108109
continue;
110+
}
109111

110112
Position position= model.getPosition(annotation);
111-
if (position == null)
113+
if (position == null) {
112114
continue;
115+
}
113116

114-
if (isCaptionLine(position, document, line))
117+
if (isCaptionLine(position, document, line)) {
115118
return getText(document, position.getOffset(), position.getLength(), numberOfLines);
119+
}
116120

117121
}
118122
} catch (BadLocationException x) {

bundles/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/ProjectionAnnotationModel.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,11 @@ public void expand(Annotation annotation) {
7979
*/
8080
public void toggleExpansionState(Annotation annotation) {
8181
if (annotation instanceof ProjectionAnnotation projection) {
82-
if (projection.isCollapsed())
82+
if (projection.isCollapsed()) {
8383
projection.markExpanded();
84-
else
84+
} else {
8585
projection.markCollapsed();
86+
}
8687

8788
modifyAnnotation(projection, true);
8889
}
@@ -125,8 +126,9 @@ public boolean collapseAll(int offset, int length) {
125126
}
126127
}
127128

128-
if (collapsing)
129+
if (collapsing) {
129130
fireModelChanged();
131+
}
130132

131133
return collapsing;
132134
}
@@ -162,8 +164,9 @@ protected boolean expandAll(int offset, int length, boolean fireModelChanged) {
162164
}
163165
}
164166

165-
if (expanding && fireModelChanged)
167+
if (expanding && fireModelChanged) {
166168
fireModelChanged();
169+
}
167170

168171
return expanding;
169172
}

bundles/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/ProjectionRulerColumn.java

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,9 @@ public ProjectionRulerColumn(int width, IAnnotationAccess annotationAccess) {
7272
@Override
7373
protected void mouseClicked(int line) {
7474
clearCurrentAnnotation();
75-
if (fMouseDownLine != line)
75+
if (fMouseDownLine != line) {
7676
return;
77+
}
7778
ProjectionAnnotation annotation= findAnnotation(line, true);
7879
if (annotation != null) {
7980
ProjectionAnnotationModel model= (ProjectionAnnotationModel) getModel();
@@ -88,8 +89,9 @@ protected void mouseDown(int rulerLine) {
8889

8990
@Override
9091
protected void mouseDoubleClicked(int rulerLine) {
91-
if (findAnnotation(rulerLine, true) != null)
92+
if (findAnnotation(rulerLine, true) != null) {
9293
return;
94+
}
9395

9496
ProjectionAnnotation annotation= findAnnotation(rulerLine, false);
9597
if (annotation != null) {
@@ -121,12 +123,14 @@ private ProjectionAnnotation findAnnotation(int line, boolean exact) {
121123
Object next= e.next();
122124
if (next instanceof ProjectionAnnotation annotation) {
123125
Position p= model.getPosition(annotation);
124-
if (p == null)
126+
if (p == null) {
125127
continue;
128+
}
126129

127130
int distance= getDistance(annotation, p, document, line);
128-
if (distance == -1)
131+
if (distance == -1) {
129132
continue;
133+
}
130134

131135
if (!exact) {
132136
if (distance < previousDistance) {
@@ -167,14 +171,16 @@ private int getDistance(ProjectionAnnotation annotation, Position position, IDoc
167171
if (line < endLine) {
168172
if (annotation.isCollapsed()) {
169173
int captionOffset;
170-
if (position instanceof IProjectionPosition)
174+
if (position instanceof IProjectionPosition) {
171175
captionOffset= ((IProjectionPosition) position).computeCaptionOffset(document);
172-
else
176+
} else {
173177
captionOffset= 0;
178+
}
174179

175180
int captionLine= document.getLineOfOffset(position.getOffset() + captionOffset);
176-
if (startLine <= captionLine && captionLine < endLine)
181+
if (startLine <= captionLine && captionLine < endLine) {
177182
return Math.abs(line - captionLine);
183+
}
178184
}
179185
return line - startLine;
180186
}
@@ -206,8 +212,9 @@ public Control createControl(CompositeRuler parentRuler, Composite parentControl
206212
control.addMouseTrackListener(new MouseTrackAdapter() {
207213
@Override
208214
public void mouseExit(MouseEvent e) {
209-
if (clearCurrentAnnotation())
215+
if (clearCurrentAnnotation()) {
210216
redraw();
217+
}
211218
}
212219
});
213220

@@ -226,8 +233,9 @@ public void mouseExit(MouseEvent e) {
226233
redraw= true;
227234
}
228235
}
229-
if (redraw)
236+
if (redraw) {
230237
redraw();
238+
}
231239
});
232240
return control;
233241
}

bundles/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/ProjectionSummary.java

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ public void reset() {
6666
public void run() {
6767
while (true) {
6868
synchronized (fLock) {
69-
if (!fReset)
69+
if (!fReset) {
7070
break;
71+
}
7172
fReset= false;
7273
fProgressMonitor.setCanceled(false);
7374
}
@@ -81,11 +82,11 @@ public void run() {
8182
}
8283

8384

84-
private ProjectionViewer fProjectionViewer;
85-
private IAnnotationAccess fAnnotationAccess;
85+
private final ProjectionViewer fProjectionViewer;
86+
private final IAnnotationAccess fAnnotationAccess;
8687
private List<String> fConfiguredAnnotationTypes;
8788

88-
private Object fLock= new Object();
89+
private final Object fLock= new Object();
8990
private IProgressMonitor fProgressMonitor;
9091
private volatile Summarizer fSummarizer;
9192

@@ -112,8 +113,9 @@ public void addAnnotationType(String annotationType) {
112113
if (fConfiguredAnnotationTypes == null) {
113114
fConfiguredAnnotationTypes= new ArrayList<>();
114115
fConfiguredAnnotationTypes.add(annotationType);
115-
} else if (!fConfiguredAnnotationTypes.contains(annotationType))
116+
} else if (!fConfiguredAnnotationTypes.contains(annotationType)) {
116117
fConfiguredAnnotationTypes.add(annotationType);
118+
}
117119
}
118120
}
119121

@@ -127,8 +129,9 @@ public void removeAnnotationType(String annotationType) {
127129
synchronized (fLock) {
128130
if (fConfiguredAnnotationTypes != null) {
129131
fConfiguredAnnotationTypes.remove(annotationType);
130-
if (fConfiguredAnnotationTypes.isEmpty())
132+
if (fConfiguredAnnotationTypes.isEmpty()) {
131133
fConfiguredAnnotationTypes= null;
134+
}
132135
}
133136
}
134137
}
@@ -139,22 +142,25 @@ public void removeAnnotationType(String annotationType) {
139142
public void updateSummaries() {
140143
synchronized (fLock) {
141144
if (fConfiguredAnnotationTypes != null) {
142-
if (fSummarizer == null)
145+
if (fSummarizer == null) {
143146
fSummarizer= new Summarizer();
147+
}
144148
fSummarizer.reset();
145149
}
146150
}
147151
}
148152

149153
private void internalUpdateSummaries(IProgressMonitor monitor) {
150154
IAnnotationModel visualAnnotationModel= fProjectionViewer.getVisualAnnotationModel();
151-
if (visualAnnotationModel == null)
155+
if (visualAnnotationModel == null) {
152156
return;
157+
}
153158

154159
removeSummaries(monitor, visualAnnotationModel);
155160

156-
if (isCanceled(monitor))
161+
if (isCanceled(monitor)) {
157162
return;
163+
}
158164

159165
createSummaries(monitor, visualAnnotationModel);
160166
}
@@ -176,28 +182,32 @@ private void removeSummaries(IProgressMonitor monitor, IAnnotationModel visualAn
176182
while (e.hasNext()) {
177183
Annotation annotation= e.next();
178184
if (annotation instanceof AnnotationBag) {
179-
if (bags == null)
185+
if (bags == null) {
180186
visualAnnotationModel.removeAnnotation(annotation);
181-
else
187+
} else {
182188
bags.add(annotation);
189+
}
183190
}
184191

185-
if (isCanceled(monitor))
192+
if (isCanceled(monitor)) {
186193
return;
194+
}
187195
}
188196

189197
if (bags != null && !bags.isEmpty() && extension != null) {
190198
Annotation[] deletions= new Annotation[bags.size()];
191199
bags.toArray(deletions);
192-
if (!isCanceled(monitor))
200+
if (!isCanceled(monitor)) {
193201
extension.replaceAnnotations(deletions, null);
202+
}
194203
}
195204
}
196205

197206
private void createSummaries(IProgressMonitor monitor, IAnnotationModel visualAnnotationModel) {
198207
ProjectionAnnotationModel model= fProjectionViewer.getProjectionAnnotationModel();
199-
if (model == null)
208+
if (model == null) {
200209
return;
210+
}
201211

202212
Map<Annotation, Position> additions= new HashMap<>();
203213

@@ -210,26 +220,30 @@ private void createSummaries(IProgressMonitor monitor, IAnnotationModel visualAn
210220
IRegion[] summaryRegions= fProjectionViewer.computeCollapsedRegions(position);
211221
if (summaryRegions != null) {
212222
Position summaryAnchor= fProjectionViewer.computeCollapsedRegionAnchor(position);
213-
if (summaryAnchor != null)
223+
if (summaryAnchor != null) {
214224
createSummary(additions, summaryRegions, summaryAnchor);
225+
}
215226
}
216227
}
217228
}
218229

219-
if (isCanceled(monitor))
230+
if (isCanceled(monitor)) {
220231
return;
232+
}
221233
}
222234

223235
if (!additions.isEmpty()) {
224236
if (visualAnnotationModel instanceof IAnnotationModelExtension extension) {
225-
if (!isCanceled(monitor))
237+
if (!isCanceled(monitor)) {
226238
extension.replaceAnnotations(null, additions);
239+
}
227240
} else {
228241
for (Entry<Annotation, Position> entry : additions.entrySet()) {
229242
AnnotationBag bag= (AnnotationBag) entry.getKey();
230243
Position position= entry.getValue();
231-
if (isCanceled(monitor))
244+
if (isCanceled(monitor)) {
232245
return;
246+
}
233247
visualAnnotationModel.addAnnotation(bag, position);
234248
}
235249
}
@@ -252,27 +266,31 @@ private void createSummary(Map<Annotation, Position> additions, IRegion[] summar
252266
}
253267
}
254268

255-
if (map == null)
269+
if (map == null) {
256270
return;
271+
}
257272

258273
IAnnotationModel model= fProjectionViewer.getAnnotationModel();
259-
if (model == null)
274+
if (model == null) {
260275
return;
276+
}
261277
Iterator<Annotation> e= model.getAnnotationIterator();
262278
while (e.hasNext()) {
263279
Annotation annotation= e.next();
264280
AnnotationBag bag= findBagForType(map, annotation.getType());
265281
if (bag != null) {
266282
Position position= model.getPosition(annotation);
267-
if (includes(summaryRegions, position))
283+
if (includes(summaryRegions, position)) {
268284
bag.add(annotation);
285+
}
269286
}
270287
}
271288

272289
for (int i= 0; i < size; i++) {
273290
AnnotationBag bag= map.get(fConfiguredAnnotationTypes.get(i));
274-
if (!bag.isEmpty())
291+
if (!bag.isEmpty()) {
275292
additions.put(bag, new Position(summaryAnchor.getOffset(), summaryAnchor.getLength()));
293+
}
276294
}
277295
}
278296

@@ -290,8 +308,9 @@ private AnnotationBag findBagForType(Map<String, AnnotationBag> bagMap, String a
290308
private boolean includes(IRegion[] regions, Position position) {
291309
for (IRegion region : regions) {
292310
if (position != null && !position.isDeleted()
293-
&& region.getOffset() <= position.getOffset() && position.getOffset() + position.getLength() <= region.getOffset() + region.getLength())
311+
&& region.getOffset() <= position.getOffset() && position.getOffset() + position.getLength() <= region.getOffset() + region.getLength()) {
294312
return true;
313+
}
295314
}
296315
return false;
297316
}

0 commit comments

Comments
 (0)