Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

null guard for AnnotationModel in EditorsUtil #38 #40

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.eclipse.jdt.ui.JavaUI;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.Position;
import org.eclipse.jface.text.source.Annotation;
import org.eclipse.jface.text.source.IAnnotationModel;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPage;
Expand Down Expand Up @@ -49,8 +50,7 @@ public static IEditorPart openEditor(IWorkbenchPage page, IFile file,
String editor, String key) {
// open the rb-editor for this file type and selects given msg key
IEditorPart part = openEditor(page, file, editor);
if (part instanceof IMessagesEditor) {
IMessagesEditor msgEditor = (IMessagesEditor) part;
if (part instanceof IMessagesEditor msgEditor) {
msgEditor.setSelectedKey(key);
}
return part;
Expand All @@ -60,13 +60,14 @@ public static void updateMarker(IMarker marker) {
FileEditorInput input = new FileEditorInput(
(IFile) marker.getResource());

AbstractMarkerAnnotationModel model = (AbstractMarkerAnnotationModel) getAnnotationModel(marker);
IDocument doc = JavaUI.getDocumentProvider().getDocument(input);

try {
model.updateMarker(doc, marker, getCurPosition(marker, model));
} catch (CoreException e) {
Logger.logError(e);
AbstractMarkerAnnotationModel model = (AbstractMarkerAnnotationModel) getAnnotationModel(marker);
if ( model != null ) {
try {
model.updateMarker(doc, marker, getCurPosition(marker, model));
} catch (CoreException e) {
Logger.logError(e);
}
}
}

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

private static Position getCurPosition(IMarker marker,
IAnnotationModel model) {
Iterator iter = model.getAnnotationIterator();
Iterator<Annotation> iter = model.getAnnotationIterator();

Logger.logInfo("Updates Position!");
while (iter.hasNext()) {
Object curr = iter.next();
if (curr instanceof SimpleMarkerAnnotation) {
SimpleMarkerAnnotation annot = (SimpleMarkerAnnotation) curr;
if (marker.equals(annot.getMarker())) {
return model.getPosition(annot);
Annotation annotation = iter.next();
if (annotation instanceof SimpleMarkerAnnotation simpleMarkerAnnotation ) {
if (marker.equals(simpleMarkerAnnotation.getMarker())) {
return model.getPosition(simpleMarkerAnnotation);
}
}
}
Expand Down
Loading