Removed option to switch back to marker based example
diff --git a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jdt/internal/ui/examples/jspeditor/JavaReconcilePipeParticipant.java b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jdt/internal/ui/examples/jspeditor/JavaReconcilePipeParticipant.java
index 8434214..afc1a18 100644
--- a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jdt/internal/ui/examples/jspeditor/JavaReconcilePipeParticipant.java
+++ b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jdt/internal/ui/examples/jspeditor/JavaReconcilePipeParticipant.java
@@ -21,10 +21,11 @@
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.Position;
import org.eclipse.jface.text.reconciler.DirtyRegion;
-import org.eclipse.jface.text.source.*;
+import org.eclipse.jface.text.source.IAnnotationExtension;
+import org.eclipse.jface.text.source.TemporaryAnnotation;
-import org.eclipse.text.reconcilerpipe.*;
import org.eclipse.text.reconcilerpipe.AbstractReconcilePipeParticipant;
+import org.eclipse.text.reconcilerpipe.AnnotationAdapter;
import org.eclipse.text.reconcilerpipe.IReconcilePipeParticipant;
import org.eclipse.text.reconcilerpipe.IReconcileResult;
import org.eclipse.text.reconcilerpipe.ITextModel;
@@ -99,7 +100,7 @@
else if (fProblem.isWarning())
type= TemporaryAnnotation.WARNING;
- return new TemporaryAnnotation(type, fProblem.getMessage(), fProblem.getID());
+ return new TemporaryAnnotation(type, fProblem.getMessage());
}
private Position createPositionFromProblem() {
@@ -228,7 +229,6 @@
try {
fWorkingCopy= new CompilationUnitAdapter(createTemporaryWorkingCopy(jspFile));
} catch (JavaModelException e) {
- // XXX Auto-generated catch block
e.printStackTrace();
}
}
@@ -244,7 +244,6 @@
try {
fWorkingCopy= new CompilationUnitAdapter(createTemporaryWorkingCopy(jspFile));
} catch (JavaModelException e) {
- // XXX Auto-generated catch block
e.printStackTrace();
}
}
diff --git a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jdt/internal/ui/examples/jspeditor/Jsp2JavaReconcilePipeParticipant.java b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jdt/internal/ui/examples/jspeditor/Jsp2JavaReconcilePipeParticipant.java
index e091ed6..5c0094d 100644
--- a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jdt/internal/ui/examples/jspeditor/Jsp2JavaReconcilePipeParticipant.java
+++ b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jdt/internal/ui/examples/jspeditor/Jsp2JavaReconcilePipeParticipant.java
@@ -128,7 +128,6 @@
}
pos.offset += javaPartitionStart;
} catch (BadLocationException e) {
- // XXX Auto-generated catch block
e.printStackTrace();
}
}
diff --git a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jdt/internal/ui/examples/jspeditor/JspReconcilingStrategy.java b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jdt/internal/ui/examples/jspeditor/JspReconcilingStrategy.java
index 77947a0..f721f3e 100644
--- a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jdt/internal/ui/examples/jspeditor/JspReconcilingStrategy.java
+++ b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jdt/internal/ui/examples/jspeditor/JspReconcilingStrategy.java
@@ -12,14 +12,9 @@
package org.eclipse.jdt.internal.ui.examples.jspeditor;
import java.lang.reflect.InvocationTargetException;
-import java.util.HashMap;
import java.util.Iterator;
-import java.util.Map;
import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IMarker;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -30,8 +25,8 @@
import org.eclipse.jface.text.reconciler.DirtyRegion;
import org.eclipse.jface.text.reconciler.IReconcilingStrategy;
import org.eclipse.jface.text.reconciler.IReconcilingStrategyExtension;
-import org.eclipse.jface.text.source.*;
import org.eclipse.jface.text.source.Annotation;
+import org.eclipse.jface.text.source.IAnnotationExtension;
import org.eclipse.jface.text.source.IAnnotationModel;
import org.eclipse.jface.text.source.ISourceViewer;
@@ -39,9 +34,8 @@
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.actions.WorkspaceModifyOperation;
import org.eclipse.ui.texteditor.ITextEditor;
-import org.eclipse.ui.texteditor.MarkerUtilities;
-import org.eclipse.text.reconcilerpipe.*;
+import org.eclipse.text.reconcilerpipe.AnnotationAdapter;
import org.eclipse.text.reconcilerpipe.IReconcilePipeParticipant;
import org.eclipse.text.reconcilerpipe.IReconcileResult;
import org.eclipse.text.reconcilerpipe.TextModelAdapter;
@@ -53,15 +47,7 @@
*/
public class JspReconcilingStrategy implements IReconcilingStrategy, IReconcilingStrategyExtension {
- /**
- * Allows to toggle the example between using markers
- * or annotations.
- */
- public static final boolean USE_MARKERS= false;
-
-
private IReconcilePipeParticipant fFirstParticipant;
- private HashMap fOffsetToMarkerMap;
private ITextEditor fTextEditor;
private IProgressMonitor fProgressMonitor;
@@ -82,18 +68,16 @@
* @see org.eclipse.jface.text.reconciler.IReconcilingStrategy#reconcile(org.eclipse.jface.text.reconciler.DirtyRegion, org.eclipse.jface.text.IRegion)
*/
public void reconcile(DirtyRegion dirtyRegion, IRegion subRegion) {
- initializeProblemMarkers();
+ removeTemporaryAnnotations();
process(fFirstParticipant.reconcile(dirtyRegion, subRegion));
- removeRemainingMarkers();
}
/*
* @see org.eclipse.jface.text.reconciler.IReconcilingStrategy#reconcile(org.eclipse.jface.text.IRegion)
*/
public void reconcile(IRegion partition) {
- initializeProblemMarkers();
+ removeTemporaryAnnotations();
process(fFirstParticipant.reconcile(partition));
- removeRemainingMarkers();
}
/*
@@ -135,42 +119,15 @@
Position pos= result.getPosition();
IAnnotationExtension annotation= result.createAnnotation();
-
- if (!USE_MARKERS) {
- getAnnotationModel().addAnnotation((Annotation)annotation, pos);
- } else {
-
- // Check if marker already exists.
- Integer offset= new Integer(pos.offset);
- IMarker marker= (IMarker)fOffsetToMarkerMap.get(offset);
-
- if (marker != null && marker.getAttribute(IMarker.MESSAGE, "").equals(annotation.getMessage())) //$NON-NLS-1$
- fOffsetToMarkerMap.remove(offset);
- else {
-
- Map attributes= new HashMap(4);
- attributes.put(IMarker.SEVERITY, new Integer(getMarkerSeverity(annotation)));
- attributes.put(IMarker.CHAR_START, offset);
- attributes.put(IMarker.CHAR_END, new Integer(pos.offset + pos.length));
- attributes.put(IMarker.MESSAGE, annotation.getMessage());
- try {
- MarkerUtilities.createMarker(getFile(), attributes, "org.eclipse.jdt.core.problem"); //$NON-NLS-1$
- } catch (CoreException e) {
- e.printStackTrace();
- continue;
- }
- }
- }
+ getAnnotationModel().addAnnotation((Annotation)annotation, pos);
}
}
};
try {
runnable.run(null);
} catch (InvocationTargetException e) {
- // XXX Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
- // XXX Auto-generated catch block
e.printStackTrace();
}
}
@@ -178,65 +135,24 @@
private IAnnotationModel getAnnotationModel() {
return fTextEditor.getDocumentProvider().getAnnotationModel(fTextEditor.getEditorInput());
}
-
- private int getMarkerSeverity(IAnnotationExtension annotation) {
- if (annotation instanceof TemporaryAnnotation) {
- if (((TemporaryAnnotation)annotation).isWarning())
- return IMarker.SEVERITY_WARNING;
- else if (((TemporaryAnnotation)annotation).isError())
- return IMarker.SEVERITY_ERROR;
- }
- return IMarker.SEVERITY_INFO;
- }
-
-
- private void initializeProblemMarkers() {
- if (USE_MARKERS) {
- IMarker[] markers;
- try {
- markers= getFile().findMarkers("org.eclipse.jdt.core.problem", true, IResource.DEPTH_INFINITE); //$NON-NLS-1$
- } catch (CoreException e) {
- fOffsetToMarkerMap= new HashMap();
- return;
- }
-
- fOffsetToMarkerMap= new HashMap(markers.length);
- for (int i= 0; i < markers.length; i++) {
- int offset= markers[i].getAttribute(IMarker.CHAR_START, -1);
- if (offset != -1 && markers[i].exists())
- fOffsetToMarkerMap.put(new Integer(offset), markers[i]);
- }
- } else {
-
- // for now we simply remove all temporary markers
-
- Iterator iter= getAnnotationModel().getAnnotationIterator();
- while (iter.hasNext()) {
- Object annotation= iter.next();
- if (annotation instanceof IAnnotationExtension) {
- IAnnotationExtension extension= (IAnnotationExtension)annotation;
- if (extension.isTemporary())
- getAnnotationModel().removeAnnotation((Annotation)annotation);
- }
+ /*
+ * XXX: A "real" implementation must be smarter
+ * i.e. don't remove and add the annotations
+ * which are the same.
+ */
+ private void removeTemporaryAnnotations() {
+ Iterator iter= getAnnotationModel().getAnnotationIterator();
+ while (iter.hasNext()) {
+ Object annotation= iter.next();
+ if (annotation instanceof IAnnotationExtension) {
+ IAnnotationExtension extension= (IAnnotationExtension)annotation;
+ if (extension.isTemporary())
+ getAnnotationModel().removeAnnotation((Annotation)annotation);
}
}
}
- private void removeRemainingMarkers() {
-
- if (USE_MARKERS) {
- IMarker[] markers= (IMarker[])fOffsetToMarkerMap.values().toArray(new IMarker[fOffsetToMarkerMap.values().size()]);
- try {
- ResourcesPlugin.getWorkspace().deleteMarkers(markers);
- } catch (CoreException e) {
- e.printStackTrace();
- }
- } else {
- // nothing to do here
- }
- }
-
private IFile getFile() {
IEditorInput input= fTextEditor.getEditorInput();
if (!(input instanceof IFileEditorInput))
diff --git a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jface/text/source/DefaultAnnotationAccess.java b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jface/text/source/DefaultAnnotationAccess.java
index b06f998..5bf929b 100644
--- a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jface/text/source/DefaultAnnotationAccess.java
+++ b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jface/text/source/DefaultAnnotationAccess.java
@@ -17,7 +17,8 @@
/**
* Default annotation access.
* <p>
- * FIXME: the "extends" relationship needs to be inverted in the final solution.
+ * FIXME: The "extends" relationship needs to be inverted in the final solution
+ * and there should be no reference to "*marker*".
* </p>
*
* @since 3.0
diff --git a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jface/text/source/IAnnotationExtension.java b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jface/text/source/IAnnotationExtension.java
index 454aa6f..19f64a2 100644
--- a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jface/text/source/IAnnotationExtension.java
+++ b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jface/text/source/IAnnotationExtension.java
@@ -18,7 +18,7 @@
* Interface for marker and temporary annotations.
*
* @see org.eclipse.core.resources.IMarker
- * @see java.text.Annotation
+ * @see org.eclipse.jface.text.source.Annotation
* @since 3.0
*/
public interface IAnnotationExtension {
@@ -46,13 +46,6 @@
String getMessage();
/**
- * Returns the id of this annotation.
- *
- * @return the id for this annotation or <code>-1</code> if no id is assigned
- */
- int getId();
-
- /**
* Returns an image for this annotation.
*
* @param display the display for which the image is requested
diff --git a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jface/text/source/TemporaryAnnotation.java b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jface/text/source/TemporaryAnnotation.java
index 22e6e5c..93d2ade 100644
--- a/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jface/text/source/TemporaryAnnotation.java
+++ b/org.eclipse.jdt.ui.examples.javafamily/src/org/eclipse/jface/text/source/TemporaryAnnotation.java
@@ -28,9 +28,6 @@
import org.eclipse.ui.texteditor.MarkerAnnotation;
import org.eclipse.ui.texteditor.MarkerAnnotationPreferences;
-// XXX: This layer breaker will go away. Only needed for the marker based example.
-import org.eclipse.jdt.internal.ui.examples.jspeditor.JspReconcilingStrategy;
-
/**
* Temporary annotation.
* <p>
@@ -57,17 +54,15 @@
private Image fImage;
private boolean fImageInitialized= false;
private int fSeverity;
- private int fId;
private String fMessage;
/** The marker annotation preferences */
- protected MarkerAnnotationPreferences fMarkerAnnotationPreferences;
+ private MarkerAnnotationPreferences fMarkerAnnotationPreferences;
- public TemporaryAnnotation(int severity, String message, int id) {
+ public TemporaryAnnotation(int severity, String message) {
Assert.isTrue(severity == NONE || severity == WARNING || severity == ERROR);
fSeverity= severity;
- fId= id;
fMessage= message;
setLayer(MarkerAnnotation.PROBLEM_LAYER + 1);
fMarkerAnnotationPreferences= new MarkerAnnotationPreferences();
@@ -114,30 +109,6 @@
return fImage;
}
- /**
- * Returns whether this annotation is a temporary warning.
- * <p>
- * XXX: this method can go a away once we decide to remove
- * the marker based example.</p>
- *
- * @see JspReconcilingStrategy#USE_MARKERS
- */
- public boolean isWarning() {
- return fSeverity == WARNING;
- }
-
- /**
- * Returns whether this annotation is a temporary error.
- * <p>
- * XXX: this method can go a away once we decide to remove
- * the marker based example.</p>
- *
- * @see JspReconcilingStrategy#USE_MARKERS
- */
- public boolean isError() {
- return fSeverity == ERROR;
- }
-
/*
* @see IAnnotationExtension#getMessage()
*/
@@ -146,29 +117,14 @@
}
/*
- * @see IAnnotationExtension#getId()
- */
- public int getId() {
- return fId;
- }
-
- /*
* @see IAnnotationExtension#getType()
*/
public Object getType() {
- if (JspReconcilingStrategy.USE_MARKERS) {
- // XXX: This is currently a hack to bring the marker-based demo to live
- return new Integer(fSeverity);
-
- } else {
-
- AnnotationPreference pref= getAnnotationPreference();
-
- if (pref != null)
- return pref.getAnnotationType();
- else
- return null;
- }
+ AnnotationPreference pref= getAnnotationPreference();
+ if (pref != null)
+ return pref.getAnnotationType();
+ else
+ return null;
}
/**