Skip to content

Commit 8469917

Browse files
committed
Apply cleanups to jface.text
* Pattern mathching for instanceof * Use diamond * Simplify lambda
1 parent bb9d623 commit 8469917

File tree

60 files changed

+206
-444
lines changed

Some content is hidden

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

60 files changed

+206
-444
lines changed

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,9 @@ private boolean isCaptionLine(Position position, IDocument document, int line) {
9191
private String getProjectionTextAtLine(ISourceViewer viewer, int line, int numberOfLines) {
9292

9393
IAnnotationModel model= null;
94-
if (viewer instanceof ISourceViewerExtension2) {
95-
ISourceViewerExtension2 viewerExtension= (ISourceViewerExtension2) viewer;
94+
if (viewer instanceof ISourceViewerExtension2 viewerExtension) {
9695
IAnnotationModel visual= viewerExtension.getVisualAnnotationModel();
97-
if (visual instanceof IAnnotationModelExtension) {
98-
IAnnotationModelExtension modelExtension= (IAnnotationModelExtension) visual;
96+
if (visual instanceof IAnnotationModelExtension modelExtension) {
9997
model= modelExtension.getAnnotationModel(ProjectionSupport.PROJECTION);
10098
}
10199
}

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ public ProjectionAnnotationModel() {
4848
* @param annotation the annotation
4949
*/
5050
public void collapse(Annotation annotation) {
51-
if (annotation instanceof ProjectionAnnotation) {
52-
ProjectionAnnotation projection= (ProjectionAnnotation) annotation;
51+
if (annotation instanceof ProjectionAnnotation projection) {
5352
if (!projection.isCollapsed()) {
5453
projection.markCollapsed();
5554
modifyAnnotation(projection, true);
@@ -64,8 +63,7 @@ public void collapse(Annotation annotation) {
6463
* @param annotation the annotation
6564
*/
6665
public void expand(Annotation annotation) {
67-
if (annotation instanceof ProjectionAnnotation) {
68-
ProjectionAnnotation projection= (ProjectionAnnotation) annotation;
66+
if (annotation instanceof ProjectionAnnotation projection) {
6967
if (projection.isCollapsed()) {
7068
projection.markExpanded();
7169
modifyAnnotation(projection, true);
@@ -80,9 +78,7 @@ public void expand(Annotation annotation) {
8078
* @param annotation the annotation
8179
*/
8280
public void toggleExpansionState(Annotation annotation) {
83-
if (annotation instanceof ProjectionAnnotation) {
84-
ProjectionAnnotation projection= (ProjectionAnnotation) annotation;
85-
81+
if (annotation instanceof ProjectionAnnotation projection) {
8682
if (projection.isCollapsed())
8783
projection.markExpanded();
8884
else

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,7 @@ private ProjectionAnnotation findAnnotation(int line, boolean exact) {
119119
Iterator<Annotation> e= model.getAnnotationIterator();
120120
while (e.hasNext()) {
121121
Object next= e.next();
122-
if (next instanceof ProjectionAnnotation) {
123-
ProjectionAnnotation annotation= (ProjectionAnnotation) next;
122+
if (next instanceof ProjectionAnnotation annotation) {
124123
Position p= model.getPosition(annotation);
125124
if (p == null)
126125
continue;
@@ -235,8 +234,7 @@ public void mouseExit(MouseEvent e) {
235234

236235
@Override
237236
public void setModel(IAnnotationModel model) {
238-
if (model instanceof IAnnotationModelExtension) {
239-
IAnnotationModelExtension extension= (IAnnotationModelExtension) model;
237+
if (model instanceof IAnnotationModelExtension extension) {
240238
model= extension.getAnnotationModel(ProjectionSupport.PROJECTION);
241239
}
242240
super.setModel(model);

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,7 @@ private void createSummaries(IProgressMonitor monitor, IAnnotationModel visualAn
221221
}
222222

223223
if (!additions.isEmpty()) {
224-
if (visualAnnotationModel instanceof IAnnotationModelExtension) {
225-
IAnnotationModelExtension extension= (IAnnotationModelExtension)visualAnnotationModel;
224+
if (visualAnnotationModel instanceof IAnnotationModelExtension extension) {
226225
if (!isCanceled(monitor))
227226
extension.replaceAnnotations(null, additions);
228227
} else {
@@ -279,8 +278,7 @@ private void createSummary(Map<Annotation, Position> additions, IRegion[] summar
279278

280279
private AnnotationBag findBagForType(Map<String, AnnotationBag> bagMap, String annotationType) {
281280
AnnotationBag bag= bagMap.get(annotationType);
282-
if (bag == null && fAnnotationAccess instanceof IAnnotationAccessExtension) {
283-
IAnnotationAccessExtension extension= (IAnnotationAccessExtension) fAnnotationAccess;
281+
if (bag == null && fAnnotationAccess instanceof IAnnotationAccessExtension extension) {
284282
Object[] superTypes= extension.getSupertypes(annotationType);
285283
for (int i= 0; i < superTypes.length && bag == null; i++) {
286284
bag= bagMap.get(superTypes[i]);

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ public ProjectionAnnotationsPainter(ISourceViewer sourceViewer, IAnnotationAcces
6565

6666
@Override
6767
protected IAnnotationModel findAnnotationModel(ISourceViewer sourceViewer) {
68-
if (sourceViewer instanceof ProjectionViewer) {
69-
ProjectionViewer projectionViewer= (ProjectionViewer) sourceViewer;
68+
if (sourceViewer instanceof ProjectionViewer projectionViewer) {
7069
return projectionViewer.getProjectionAnnotationModel();
7170
}
7271
return null;
@@ -84,8 +83,7 @@ protected boolean skip(Annotation annotation) {
8483
private static class ProjectionDrawingStrategy implements AnnotationPainter.IDrawingStrategy {
8584
@Override
8685
public void draw(Annotation annotation, GC gc, StyledText textWidget, int offset, int length, Color color) {
87-
if (annotation instanceof ProjectionAnnotation) {
88-
ProjectionAnnotation projectionAnnotation= (ProjectionAnnotation) annotation;
86+
if (annotation instanceof ProjectionAnnotation projectionAnnotation) {
8987
if (projectionAnnotation.isCollapsed()) {
9088

9189
if (gc != null) {
@@ -351,8 +349,7 @@ private IAnnotationHover createProjectionAnnotationHover() {
351349
@SuppressWarnings("unchecked")
352350
public <T> T getAdapter(ISourceViewer viewer, Class<T> required) {
353351
if (ProjectionAnnotationModel.class.equals(required)) {
354-
if (viewer instanceof ProjectionViewer) {
355-
ProjectionViewer projectionViewer= (ProjectionViewer) viewer;
352+
if (viewer instanceof ProjectionViewer projectionViewer) {
356353
return (T) projectionViewer.getProjectionAnnotationModel();
357354
}
358355
}

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

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,7 @@ public void setProjectionSummary(ProjectionSummary projectionSummary) {
330330
* @param model the model to which the projection annotation model is added
331331
*/
332332
private void addProjectionAnnotationModel(IAnnotationModel model) {
333-
if (model instanceof IAnnotationModelExtension) {
334-
IAnnotationModelExtension extension= (IAnnotationModelExtension) model;
333+
if (model instanceof IAnnotationModelExtension extension) {
335334
extension.addAnnotationModel(ProjectionSupport.PROJECTION, fProjectionAnnotationModel);
336335
model.addAnnotationModelListener(fAnnotationModelListener);
337336
}
@@ -344,9 +343,8 @@ private void addProjectionAnnotationModel(IAnnotationModel model) {
344343
* @return the removed projection annotation model or <code>null</code> if there was none
345344
*/
346345
private IAnnotationModel removeProjectionAnnotationModel(IAnnotationModel model) {
347-
if (model instanceof IAnnotationModelExtension) {
346+
if (model instanceof IAnnotationModelExtension extension) {
348347
model.removeAnnotationModelListener(fAnnotationModelListener);
349-
IAnnotationModelExtension extension= (IAnnotationModelExtension) model;
350348
return extension.removeAnnotationModel(ProjectionSupport.PROJECTION);
351349
}
352350
return null;
@@ -387,8 +385,7 @@ protected IAnnotationModel createVisualAnnotationModel(IAnnotationModel annotati
387385
*/
388386
public ProjectionAnnotationModel getProjectionAnnotationModel() {
389387
IAnnotationModel model= getVisualAnnotationModel();
390-
if (model instanceof IAnnotationModelExtension) {
391-
IAnnotationModelExtension extension= (IAnnotationModelExtension) model;
388+
if (model instanceof IAnnotationModelExtension extension) {
392389
return (ProjectionAnnotationModel) extension.getAnnotationModel(ProjectionSupport.PROJECTION);
393390
}
394391
return null;
@@ -401,9 +398,7 @@ protected ISlaveDocumentManager createSlaveDocumentManager() {
401398

402399
@Override
403400
protected boolean updateSlaveDocument(IDocument slaveDocument, int modelRangeOffset, int modelRangeLength) throws BadLocationException {
404-
if (slaveDocument instanceof ProjectionDocument) {
405-
ProjectionDocument projection= (ProjectionDocument) slaveDocument;
406-
401+
if (slaveDocument instanceof ProjectionDocument projection) {
407402
int offset= modelRangeOffset;
408403
int length= modelRangeLength;
409404

@@ -814,9 +809,7 @@ private void collapse(int offset, int length, boolean fireRedraw) throws BadLoca
814809
*/
815810
private void expand(int offset, int length, boolean fireRedraw) throws BadLocationException {
816811
IDocument slave= getVisibleDocument();
817-
if (slave instanceof ProjectionDocument) {
818-
ProjectionDocument projection= (ProjectionDocument) slave;
819-
812+
if (slave instanceof ProjectionDocument projection) {
820813
// expand
821814
addMasterDocumentRange(projection, offset, length);
822815

@@ -1100,8 +1093,7 @@ IRegion[] computeCollapsedRegions(Position position) {
11001093
if (document == null)
11011094
return null;
11021095

1103-
if (position instanceof IProjectionPosition) {
1104-
IProjectionPosition projPosition= (IProjectionPosition) position;
1096+
if (position instanceof IProjectionPosition projPosition) {
11051097
return projPosition.computeProjectionRegions(document);
11061098
}
11071099

@@ -1308,9 +1300,7 @@ protected void handleDispose() {
13081300
*/
13091301
@Override
13101302
protected void handleVisibleDocumentChanged(DocumentEvent event) {
1311-
if (fHandleProjectionChanges && event instanceof ProjectionDocumentEvent && isProjectionMode()) {
1312-
ProjectionDocumentEvent e= (ProjectionDocumentEvent) event;
1313-
1303+
if (fHandleProjectionChanges && event instanceof ProjectionDocumentEvent e && isProjectionMode()) {
13141304
DocumentEvent master= e.getMasterEvent();
13151305
if (master != null)
13161306
fReplaceVisibleDocumentExecutionTrigger= master.getDocument();
@@ -1355,8 +1345,7 @@ public IRegion[] getCoveredModelRanges(IRegion modelRange) {
13551345
if (fInformationMapping == null)
13561346
return new IRegion[] { new Region(modelRange.getOffset(), modelRange.getLength()) };
13571347

1358-
if (fInformationMapping instanceof IDocumentInformationMappingExtension) {
1359-
IDocumentInformationMappingExtension extension= (IDocumentInformationMappingExtension) fInformationMapping;
1348+
if (fInformationMapping instanceof IDocumentInformationMappingExtension extension) {
13601349
try {
13611350
return extension.getExactCoverage(modelRange);
13621351
} catch (BadLocationException x) {

bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/InformationControlReplacer.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,7 @@ public void showInformationControl(Rectangle subjectArea, Object information) {
153153
private Rectangle computeBoundsFromContent(IInformationControl informationControl, Rectangle controlBounds) {
154154
Rectangle result= Geometry.copy(controlBounds);
155155

156-
if (informationControl instanceof IInformationControlExtension3) {
157-
IInformationControlExtension3 iControl3= (IInformationControlExtension3) informationControl;
156+
if (informationControl instanceof IInformationControlExtension3 iControl3) {
158157
Rectangle trim= iControl3.computeTrim();
159158
result= Geometry.add(result, trim);
160159

bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/SelectionProcessor.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -802,8 +802,7 @@ private int visualSizeIncrement(char character, int visual) {
802802
*/
803803
public SelectionProcessor(ITextViewer viewer) {
804804
this(viewer.getDocument(), viewer.getTextWidget().getTabs());
805-
if (viewer instanceof ITextViewerExtension) {
806-
ITextViewerExtension ext= (ITextViewerExtension)viewer;
805+
if (viewer instanceof ITextViewerExtension ext) {
807806
fRewriteTarget= ext.getRewriteTarget();
808807
}
809808
fSelectionProvider= viewer.getSelectionProvider();

bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/StickyHoverManager.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,8 @@ public void handleEvent(Event event) {
207207
return;
208208

209209
IInformationControl infoControl= getCurrentInformationControl2();
210-
if (infoControl != null && !infoControl.isFocusControl() && infoControl instanceof IInformationControlExtension3) {
210+
if (infoControl != null && !infoControl.isFocusControl() && infoControl instanceof IInformationControlExtension3 iControl3) {
211211
// if (DEBUG) System.out.println("StickyHoverManager.Closer.handleEvent(): activeShell= " + fDisplay.getActiveShell()); //$NON-NLS-1$
212-
IInformationControlExtension3 iControl3= (IInformationControlExtension3) infoControl;
213212
Rectangle controlBounds= iControl3.getBounds();
214213
if (controlBounds != null) {
215214
Point mouseLoc= event.display.map((Control) event.widget, null, event.x, event.y);
@@ -319,8 +318,7 @@ public boolean requestWidgetToken(IWidgetTokenOwner owner, int priority) {
319318
@Override
320319
public boolean setFocus(IWidgetTokenOwner owner) {
321320
IInformationControl iControl= getCurrentInformationControl2();
322-
if (iControl instanceof IInformationControlExtension5) {
323-
IInformationControlExtension5 iControl5= (IInformationControlExtension5) iControl;
321+
if (iControl instanceof IInformationControlExtension5 iControl5) {
324322
if (iControl5.isVisible()) {
325323
iControl.setFocus();
326324
return iControl.isFocusControl();

bundles/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/codemining/CodeMiningDocumentFooterAnnotation.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,7 @@ public void markDeleted(boolean deleted) {
114114
@Override
115115
public void draw(GC gc, StyledText textWidget, int offset, int length, Color color, int x, int y) {
116116
int singleLineHeight= super.getHeight();
117-
CodeMiningLineHeaderAnnotation.draw(fMinings, fBounds, singleLineHeight, fResolvedMinings, gc, textWidget, color, x, y, new Runnable() {
118-
119-
@Override
120-
public void run() {
121-
redraw();
122-
}
123-
});
117+
CodeMiningLineHeaderAnnotation.draw(fMinings, fBounds, singleLineHeight, fResolvedMinings, gc, textWidget, color, x, y, this::redraw);
124118
}
125119

126120
@Override

0 commit comments

Comments
 (0)