1414import org .eclipse .jdt .ui .JavaUI ;
1515import org .eclipse .jface .text .IDocument ;
1616import org .eclipse .jface .text .Position ;
17+ import org .eclipse .jface .text .source .Annotation ;
1718import org .eclipse .jface .text .source .IAnnotationModel ;
1819import org .eclipse .ui .IEditorPart ;
1920import 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