Skip to content

Commit e4a7743

Browse files
authored
null guard for AnnotationModel in EditorsUtil (#40)
1 parent 049775e commit e4a7743

1 file changed

Lines changed: 15 additions & 14 deletions

File tree

  • org.eclipse.babel.tapiji.tools.core.ui/src/org/eclipse/babel/tapiji/tools/core/ui/utils

org.eclipse.babel.tapiji.tools.core.ui/src/org/eclipse/babel/tapiji/tools/core/ui/utils/EditorUtils.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.eclipse.jdt.ui.JavaUI;
1515
import org.eclipse.jface.text.IDocument;
1616
import org.eclipse.jface.text.Position;
17+
import org.eclipse.jface.text.source.Annotation;
1718
import org.eclipse.jface.text.source.IAnnotationModel;
1819
import org.eclipse.ui.IEditorPart;
1920
import org.eclipse.ui.IWorkbenchPage;
@@ -49,8 +50,7 @@ public static IEditorPart openEditor(IWorkbenchPage page, IFile file,
4950
String editor, String key) {
5051
// open the rb-editor for this file type and selects given msg key
5152
IEditorPart part = openEditor(page, file, editor);
52-
if (part instanceof IMessagesEditor) {
53-
IMessagesEditor msgEditor = (IMessagesEditor) part;
53+
if (part instanceof IMessagesEditor msgEditor) {
5454
msgEditor.setSelectedKey(key);
5555
}
5656
return part;
@@ -60,13 +60,14 @@ public static void updateMarker(IMarker marker) {
6060
FileEditorInput input = new FileEditorInput(
6161
(IFile) marker.getResource());
6262

63-
AbstractMarkerAnnotationModel model = (AbstractMarkerAnnotationModel) getAnnotationModel(marker);
6463
IDocument doc = JavaUI.getDocumentProvider().getDocument(input);
65-
66-
try {
67-
model.updateMarker(doc, marker, getCurPosition(marker, model));
68-
} catch (CoreException e) {
69-
Logger.logError(e);
64+
AbstractMarkerAnnotationModel model = (AbstractMarkerAnnotationModel) getAnnotationModel(marker);
65+
if ( model != null ) {
66+
try {
67+
model.updateMarker(doc, marker, getCurPosition(marker, model));
68+
} catch (CoreException e) {
69+
Logger.logError(e);
70+
}
7071
}
7172
}
7273

@@ -79,14 +80,14 @@ public static IAnnotationModel getAnnotationModel(IMarker marker) {
7980

8081
private static Position getCurPosition(IMarker marker,
8182
IAnnotationModel model) {
82-
Iterator iter = model.getAnnotationIterator();
83+
Iterator<Annotation> iter = model.getAnnotationIterator();
84+
8385
Logger.logInfo("Updates Position!");
8486
while (iter.hasNext()) {
85-
Object curr = iter.next();
86-
if (curr instanceof SimpleMarkerAnnotation) {
87-
SimpleMarkerAnnotation annot = (SimpleMarkerAnnotation) curr;
88-
if (marker.equals(annot.getMarker())) {
89-
return model.getPosition(annot);
87+
Annotation annotation = iter.next();
88+
if (annotation instanceof SimpleMarkerAnnotation simpleMarkerAnnotation ) {
89+
if (marker.equals(simpleMarkerAnnotation.getMarker())) {
90+
return model.getPosition(simpleMarkerAnnotation);
9091
}
9192
}
9293
}

0 commit comments

Comments
 (0)