X-Git-Url: http://secure.phpeclipse.com
diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPDocumentProvider.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPDocumentProvider.java
index ec23358..74f98be 100644
--- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPDocumentProvider.java
+++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPDocumentProvider.java
@@ -19,16 +19,12 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import net.sourceforge.phpdt.core.IBuffer;
-import net.sourceforge.phpdt.core.IBufferFactory;
import net.sourceforge.phpdt.core.ICompilationUnit;
import net.sourceforge.phpdt.core.IJavaModelStatusConstants;
-import net.sourceforge.phpdt.core.IOpenable;
import net.sourceforge.phpdt.core.IProblemRequestor;
-import net.sourceforge.phpdt.core.JavaModelException;
import net.sourceforge.phpdt.core.JavaCore;
+import net.sourceforge.phpdt.core.JavaModelException;
import net.sourceforge.phpdt.core.compiler.IProblem;
-import net.sourceforge.phpdt.internal.ui.PHPStatusConstants;
import net.sourceforge.phpdt.internal.ui.PHPUIStatus;
import net.sourceforge.phpdt.internal.ui.text.java.IProblemRequestorExtension;
import net.sourceforge.phpdt.ui.PreferenceConstants;
@@ -39,18 +35,21 @@ import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IMarkerDelta;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceRuleFactory;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.text.Assert;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.DefaultLineTracker;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IDocumentPartitioner;
import org.eclipse.jface.text.ILineTracker;
+import org.eclipse.jface.text.ISynchronizable;
import org.eclipse.jface.text.Position;
import org.eclipse.jface.text.source.Annotation;
import org.eclipse.jface.text.source.AnnotationModelEvent;
@@ -59,6 +58,7 @@ import org.eclipse.jface.text.source.IAnnotationModel;
import org.eclipse.jface.text.source.IAnnotationModelListener;
import org.eclipse.jface.text.source.IAnnotationModelListenerExtension;
import org.eclipse.jface.text.source.IAnnotationPresentation;
+import org.eclipse.jface.text.source.ImageUtilities;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.ListenerList;
import org.eclipse.jface.util.PropertyChangeEvent;
@@ -71,430 +71,365 @@ import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.editors.text.EditorsUI;
-import org.eclipse.ui.editors.text.FileDocumentProvider;
+import org.eclipse.ui.editors.text.TextFileDocumentProvider;
import org.eclipse.ui.part.FileEditorInput;
import org.eclipse.ui.texteditor.AbstractMarkerAnnotationModel;
import org.eclipse.ui.texteditor.AnnotationPreference;
import org.eclipse.ui.texteditor.AnnotationPreferenceLookup;
import org.eclipse.ui.texteditor.MarkerAnnotation;
+import org.eclipse.ui.texteditor.MarkerUtilities;
import org.eclipse.ui.texteditor.ResourceMarkerAnnotationModel;
/**
* The PHPDocumentProvider provides the IDocuments used by java editors.
*/
-public class PHPDocumentProvider extends FileDocumentProvider {
+public class PHPDocumentProvider extends TextFileDocumentProvider {
/**
* Here for visibility issues only.
*/
- protected class _FileSynchronizer extends FileSynchronizer {
- public _FileSynchronizer(IFileEditorInput fileEditorInput) {
- super(fileEditorInput);
- }
- };
- /**
- * Bundle of all required informations to allow working copy management.
- */
- protected class CompilationUnitInfo extends FileInfo {
-
- ICompilationUnit fCopy;
- public CompilationUnitInfo(
- IDocument document,
- IAnnotationModel model,
- _FileSynchronizer fileSynchronizer,
- ICompilationUnit copy) {
- super(document, model, fileSynchronizer);
- fCopy = copy;
- }
-
- public void setModificationStamp(long timeStamp) {
- fModificationStamp = timeStamp;
- }
- };
/**
- * Annotation model dealing with java marker annotations and temporary problems.
- * Also acts as problem requestor for its compilation unit. Initialiy inactive. Must explicitly be
- * activated.
- */
- protected class CompilationUnitAnnotationModel
- extends ResourceMarkerAnnotationModel
- implements IProblemRequestor, IProblemRequestorExtension {
- private List fCollectedProblems;
- private List fCurrentlyOverlaid = new ArrayList();
- private List fGeneratedAnnotations;
-
- private IFileEditorInput fInput;
- private boolean fIsActive = false;
- private List fPreviouslyOverlaid = null;
- private IProgressMonitor fProgressMonitor;
-
- private ReverseMap fReverseMap = new ReverseMap();
-
- public CompilationUnitAnnotationModel(IFileEditorInput input) {
- super(input.getFile());
- fInput = input;
- }
-
- /*
- * @see IProblemRequestor#acceptProblem(IProblem)
- */
- public void acceptProblem(IProblem problem) {
- if (isActive())
- fCollectedProblems.add(problem);
- }
-
- /*
- * @see AnnotationModel#addAnnotation(Annotation, Position, boolean)
- */
- protected void addAnnotation(Annotation annotation, Position position, boolean fireModelChanged) throws BadLocationException {
- super.addAnnotation(annotation, position, fireModelChanged);
-
- Object cached = fReverseMap.get(position);
- if (cached == null)
- fReverseMap.put(position, annotation);
- else if (cached instanceof List) {
- List list = (List) cached;
- list.add(annotation);
- } else if (cached instanceof Annotation) {
- List list = new ArrayList(2);
- list.add(cached);
- list.add(annotation);
- fReverseMap.put(position, list);
- }
- }
-
- /*
- * @see IProblemRequestor#beginReporting()
- */
- public void beginReporting() {
- ICompilationUnit unit = getWorkingCopy(fInput);
- if (unit != null) // && unit.getJavaProject().isOnClasspath(unit))
- fCollectedProblems = new ArrayList();
- else
- fCollectedProblems = null;
- }
-
- protected MarkerAnnotation createMarkerAnnotation(IMarker marker) {
- return new JavaMarkerAnnotation(marker);
- }
-
- protected Position createPositionFromProblem(IProblem problem) {
- int start = problem.getSourceStart();
- if (start < 0)
- return null;
-
- int length = problem.getSourceEnd() - problem.getSourceStart() + 1;
- if (length < 0)
- return null;
-
- return new Position(start, length);
- }
- /*
- * @see IProblemRequestor#endReporting()
- */
- public void endReporting() {
- if (!isActive())
- return;
-
- if (fProgressMonitor != null && fProgressMonitor.isCanceled())
- return;
-
-
- boolean isCanceled= false;
- boolean temporaryProblemsChanged= false;
-
- synchronized (fAnnotations) {
-
- fPreviouslyOverlaid= fCurrentlyOverlaid;
- fCurrentlyOverlaid= new ArrayList();
-
- if (fGeneratedAnnotations.size() > 0) {
- temporaryProblemsChanged= true;
- removeAnnotations(fGeneratedAnnotations, false, true);
- fGeneratedAnnotations.clear();
- }
-
- if (fCollectedProblems != null && fCollectedProblems.size() > 0) {
-
- ICompilationUnit cu= getWorkingCopy(fInput);
- Iterator e= fCollectedProblems.iterator();
- while (e.hasNext()) {
-
- IProblem problem= (IProblem) e.next();
-
- if (fProgressMonitor != null && fProgressMonitor.isCanceled()) {
- isCanceled= true;
- break;
- }
-
- Position position= createPositionFromProblem(problem);
- if (position != null) {
- try {
- ProblemAnnotation annotation= new ProblemAnnotation(problem, cu);
- addAnnotation(annotation, position, false);
- overlayMarkers(position, annotation);
- fGeneratedAnnotations.add(annotation);
-
- temporaryProblemsChanged= true;
- } catch (BadLocationException x) {
- // ignore invalid position
- }
- }
- }
-
- fCollectedProblems.clear();
- }
-
- removeMarkerOverlays(isCanceled);
- fPreviouslyOverlaid.clear();
- fPreviouslyOverlaid= null;
- }
-
- if (temporaryProblemsChanged)
- fireModelChanged();
- }
- /*
- * @see IProblemRequestor#endReporting()
- */
-// public void endReporting() {
-// if (!isActive())
-// return;
-//
-// if (fProgressMonitor != null && fProgressMonitor.isCanceled())
-// return;
-//
-// boolean isCanceled = false;
-// boolean temporaryProblemsChanged = false;
-// fPreviouslyOverlaid = fCurrentlyOverlaid;
-// fCurrentlyOverlaid = new ArrayList();
-//
-// synchronized (fAnnotations) {
-//
-// if (fGeneratedAnnotations.size() > 0) {
-// temporaryProblemsChanged = true;
-// removeAnnotations(fGeneratedAnnotations, false, true);
-// fGeneratedAnnotations.clear();
-// }
-//
-// if (fCollectedProblems != null && fCollectedProblems.size() > 0) {
-//
-// Iterator e = fCollectedProblems.iterator();
-// while (e.hasNext()) {
-//
-// IProblem problem = (IProblem) e.next();
-//
-// if (fProgressMonitor != null && fProgressMonitor.isCanceled()) {
-// isCanceled = true;
-// break;
-// }
-//
-// Position position = createPositionFromProblem(problem);
-// if (position != null) {
-//
-// ProblemAnnotation annotation = new ProblemAnnotation(problem);
-// overlayMarkers(position, annotation);
-// fGeneratedAnnotations.add(annotation);
-// addAnnotation(annotation, position, false);
-//
-// temporaryProblemsChanged = true;
-// }
-// }
-//
-// fCollectedProblems.clear();
-// }
-//
-// removeMarkerOverlays(isCanceled);
-// fPreviouslyOverlaid.clear();
-// fPreviouslyOverlaid = null;
-// }
-//
-// if (temporaryProblemsChanged)
-// fireModelChanged(new CompilationUnitAnnotationModelEvent(this, getResource(), false));
-// }
-
- private Object getAnnotations(Position position) {
- return fReverseMap.get(position);
- }
-
- /*
- * @see AnnotationModel#fireModelChanged()
- */
- protected void fireModelChanged() {
- fireModelChanged(new CompilationUnitAnnotationModelEvent(this, getResource(), true));
- }
-
- /*
- * @see IProblemRequestor#isActive()
- */
- public boolean isActive() {
- return fIsActive && (fCollectedProblems != null);
- }
-
- /*
- * @see AnnotationModel#removeAllAnnotations(boolean)
- */
- protected void removeAllAnnotations(boolean fireModelChanged) {
- super.removeAllAnnotations(fireModelChanged);
- fReverseMap.clear();
- }
-
- /*
- * @see AnnotationModel#removeAnnotation(Annotation, boolean)
- */
- protected void removeAnnotation(Annotation annotation, boolean fireModelChanged) {
- Position position = getPosition(annotation);
- Object cached = fReverseMap.get(position);
- if (cached instanceof List) {
- List list = (List) cached;
- list.remove(annotation);
- if (list.size() == 1) {
- fReverseMap.put(position, list.get(0));
- list.clear();
- }
- } else if (cached instanceof Annotation) {
- fReverseMap.remove(position);
- }
-
- super.removeAnnotation(annotation, fireModelChanged);
- }
-
- private void removeMarkerOverlays(boolean isCanceled) {
- if (isCanceled) {
- fCurrentlyOverlaid.addAll(fPreviouslyOverlaid);
- } else if (fPreviouslyOverlaid != null) {
- Iterator e = fPreviouslyOverlaid.iterator();
- while (e.hasNext()) {
- JavaMarkerAnnotation annotation = (JavaMarkerAnnotation) e.next();
- annotation.setOverlay(null);
- }
- }
- }
-
- /*
- * @see IProblemRequestorExtension#setIsActive(boolean)
- */
- public void setIsActive(boolean isActive) {
- if (fIsActive != isActive) {
- fIsActive = isActive;
- if (fIsActive)
- startCollectingProblems();
- else
- stopCollectingProblems();
- }
- }
-
- /*
- * @see IProblemRequestorExtension#setProgressMonitor(IProgressMonitor)
- */
- public void setProgressMonitor(IProgressMonitor monitor) {
- fProgressMonitor = monitor;
- }
-
- /**
- * Overlays value with problem annotation.
- * @param problemAnnotation
- */
- private void setOverlay(Object value, ProblemAnnotation problemAnnotation) {
- if (value instanceof JavaMarkerAnnotation) {
- JavaMarkerAnnotation annotation = (JavaMarkerAnnotation) value;
- if (annotation.isProblem()) {
- annotation.setOverlay(problemAnnotation);
- fPreviouslyOverlaid.remove(annotation);
- fCurrentlyOverlaid.add(annotation);
- }
- }
- }
-
- private void overlayMarkers(Position position, ProblemAnnotation problemAnnotation) {
- Object value = getAnnotations(position);
- if (value instanceof List) {
- List list = (List) value;
- for (Iterator e = list.iterator(); e.hasNext();)
- setOverlay(e.next(), problemAnnotation);
- } else {
- setOverlay(value, problemAnnotation);
- }
- }
-
- /**
- * Tells this annotation model to collect temporary problems from now on.
- */
- private void startCollectingProblems() {
- fCollectedProblems = new ArrayList();
- fGeneratedAnnotations = new ArrayList();
- }
-
- /**
- * Tells this annotation model to no longer collect temporary problems.
- */
- private void stopCollectingProblems() {
- if (fGeneratedAnnotations != null) {
- removeAnnotations(fGeneratedAnnotations, true, true);
- fGeneratedAnnotations.clear();
- }
- fCollectedProblems = null;
- fGeneratedAnnotations = null;
- }
-
- protected void update(IMarkerDelta[] markerDeltas) {
-
- super.update(markerDeltas);
-
- if (markerDeltas != null && markerDeltas.length > 0) {
- try {
- ICompilationUnit workingCopy = getWorkingCopy(fInput);
- if (workingCopy != null)
- workingCopy.reconcile(true, null);
- } catch (JavaModelException ex) {
- handleCoreException(ex, ex.getMessage());
- }
- }
- }
- }
- /**
- * Creates IBuffer
s based on documents.
+ * Bundle of all required informations to allow working copy management.
*/
- protected class BufferFactory implements IBufferFactory {
-
- private IDocument internalGetDocument(IFileEditorInput input) throws CoreException {
- IDocument document = getDocument(input);
- if (document != null)
- return document;
- return PHPDocumentProvider.this.createDocument(input);
- }
+ /**
+ * Bundle of all required informations to allow working copy management.
+ */
+ static protected class CompilationUnitInfo extends FileInfo {
+ public ICompilationUnit fCopy;
+ }
+
+ /**
+ * Annotation model dealing with java marker annotations and temporary problems.
+ * Also acts as problem requestor for its compilation unit. Initialiy inactive. Must explicitly be
+ * activated.
+ */
+ protected static class CompilationUnitAnnotationModel extends ResourceMarkerAnnotationModel implements IProblemRequestor, IProblemRequestorExtension {
+
+ private static class ProblemRequestorState {
+ boolean fInsideReportingSequence= false;
+ List fReportedProblems;
+ }
+
+ private ThreadLocal fProblemRequestorState= new ThreadLocal();
+ private int fStateCount= 0;
+
+ private ICompilationUnit fCompilationUnit;
+ private List fGeneratedAnnotations;
+ private IProgressMonitor fProgressMonitor;
+ private boolean fIsActive= false;
+
+ private ReverseMap fReverseMap= new ReverseMap();
+ private List fPreviouslyOverlaid= null;
+ private List fCurrentlyOverlaid= new ArrayList();
- public IBuffer createBuffer(IOpenable owner) {
- if (owner instanceof ICompilationUnit) {
-
- ICompilationUnit unit = (ICompilationUnit) owner;
- ICompilationUnit original = (ICompilationUnit) unit.getOriginalElement();
- IResource resource = original.getResource();
- if (resource instanceof IFile) {
- IFileEditorInput providerKey = new FileEditorInput((IFile) resource);
-
- IDocument document = null;
- IStatus status = null;
-
- try {
- document = internalGetDocument(providerKey);
- } catch (CoreException x) {
- status = x.getStatus();
- document = new Document();
- initializeDocument(document, providerKey);
- }
-
- DocumentAdapter adapter =
- new DocumentAdapter(unit, document, new DefaultLineTracker(), PHPDocumentProvider.this, providerKey);
- adapter.setStatus(status);
- return adapter;
- }
+
+ public CompilationUnitAnnotationModel(IResource resource) {
+ super(resource);
+ }
+
+ public void setCompilationUnit(ICompilationUnit unit) {
+ fCompilationUnit= unit;
+ }
+
+ protected MarkerAnnotation createMarkerAnnotation(IMarker marker) {
+ String markerType= MarkerUtilities.getMarkerType(marker);
+ if (markerType != null && markerType.startsWith(JavaMarkerAnnotation.JAVA_MARKER_TYPE_PREFIX))
+ return new JavaMarkerAnnotation(marker);
+ return super.createMarkerAnnotation(marker);
+ }
+
+ /*
+ * @see org.eclipse.jface.text.source.AnnotationModel#createAnnotationModelEvent()
+ */
+ protected AnnotationModelEvent createAnnotationModelEvent() {
+ return new CompilationUnitAnnotationModelEvent(this, getResource());
+ }
+
+ protected Position createPositionFromProblem(IProblem problem) {
+ int start= problem.getSourceStart();
+ if (start < 0)
+ return null;
+
+ int length= problem.getSourceEnd() - problem.getSourceStart() + 1;
+ if (length < 0)
+ return null;
+
+ return new Position(start, length);
+ }
+
+ /*
+ * @see IProblemRequestor#beginReporting()
+ */
+ public void beginReporting() {
+ ProblemRequestorState state= (ProblemRequestorState) fProblemRequestorState.get();
+ if (state == null)
+ internalBeginReporting(false);
+ }
+
+ /*
+ * @see org.eclipse.jdt.internal.ui.text.java.IProblemRequestorExtension#beginReportingSequence()
+ */
+ public void beginReportingSequence() {
+ ProblemRequestorState state= (ProblemRequestorState) fProblemRequestorState.get();
+ if (state == null)
+ internalBeginReporting(true);
+ }
+
+ /**
+ * Sets up the infrastructure necessary for problem reporting.
+ *
+ * @param insideReportingSequence true
if this method
+ * call is issued from inside a reporting sequence
+ */
+ private void internalBeginReporting(boolean insideReportingSequence) {
+ if (fCompilationUnit != null) {
+ // && fCompilationUnit.getJavaProject().isOnClasspath(fCompilationUnit)) {
+ ProblemRequestorState state= new ProblemRequestorState();
+ state.fInsideReportingSequence= insideReportingSequence;
+ state.fReportedProblems= new ArrayList();
+ synchronized (getLockObject()) {
+ fProblemRequestorState.set(state);
+ ++fStateCount;
+ }
+ }
+ }
- }
- return DocumentAdapter.NULL;
- }
- };
+ /*
+ * @see IProblemRequestor#acceptProblem(IProblem)
+ */
+ public void acceptProblem(IProblem problem) {
+ if (isActive()) {
+ ProblemRequestorState state= (ProblemRequestorState) fProblemRequestorState.get();
+ if (state != null)
+ state.fReportedProblems.add(problem);
+ }
+ }
+
+ /*
+ * @see IProblemRequestor#endReporting()
+ */
+ public void endReporting() {
+ ProblemRequestorState state= (ProblemRequestorState) fProblemRequestorState.get();
+ if (state != null && !state.fInsideReportingSequence)
+ internalEndReporting(state);
+ }
+
+ /*
+ * @see org.eclipse.jdt.internal.ui.text.java.IProblemRequestorExtension#endReportingSequence()
+ */
+ public void endReportingSequence() {
+ ProblemRequestorState state= (ProblemRequestorState) fProblemRequestorState.get();
+ if (state != null && state.fInsideReportingSequence)
+ internalEndReporting(state);
+ }
+
+ private void internalEndReporting(ProblemRequestorState state) {
+ int stateCount= 0;
+ synchronized(getLockObject()) {
+ -- fStateCount;
+ stateCount= fStateCount;
+ fProblemRequestorState.set(null);
+ }
+
+ if (stateCount == 0 && isActive())
+ reportProblems(state.fReportedProblems);
+ }
+
+ /**
+ * Signals the end of problem reporting.
+ */
+ private void reportProblems(List reportedProblems) {
+ if (fProgressMonitor != null && fProgressMonitor.isCanceled())
+ return;
+
+ boolean temporaryProblemsChanged= false;
+
+ synchronized (getLockObject()) {
+
+ boolean isCanceled= false;
+
+ fPreviouslyOverlaid= fCurrentlyOverlaid;
+ fCurrentlyOverlaid= new ArrayList();
+
+ if (fGeneratedAnnotations.size() > 0) {
+ temporaryProblemsChanged= true;
+ removeAnnotations(fGeneratedAnnotations, false, true);
+ fGeneratedAnnotations.clear();
+ }
+
+ if (reportedProblems != null && reportedProblems.size() > 0) {
+
+ Iterator e= reportedProblems.iterator();
+ while (e.hasNext()) {
+
+ if (fProgressMonitor != null && fProgressMonitor.isCanceled()) {
+ isCanceled= true;
+ break;
+ }
+
+ IProblem problem= (IProblem) e.next();
+ Position position= createPositionFromProblem(problem);
+ if (position != null) {
+
+ try {
+ ProblemAnnotation annotation= new ProblemAnnotation(problem, fCompilationUnit);
+ overlayMarkers(position, annotation);
+ addAnnotation(annotation, position, false);
+ fGeneratedAnnotations.add(annotation);
+
+ temporaryProblemsChanged= true;
+ } catch (BadLocationException x) {
+ // ignore invalid position
+ }
+ }
+ }
+ }
+
+ removeMarkerOverlays(isCanceled);
+ fPreviouslyOverlaid= null;
+ }
+
+ if (temporaryProblemsChanged)
+ fireModelChanged();
+ }
+ private void removeMarkerOverlays(boolean isCanceled) {
+ if (isCanceled) {
+ fCurrentlyOverlaid.addAll(fPreviouslyOverlaid);
+ } else if (fPreviouslyOverlaid != null) {
+ Iterator e= fPreviouslyOverlaid.iterator();
+ while (e.hasNext()) {
+ JavaMarkerAnnotation annotation= (JavaMarkerAnnotation) e.next();
+ annotation.setOverlay(null);
+ }
+ }
+ }
+
+ /**
+ * Overlays value with problem annotation.
+ * @param problemAnnotation
+ */
+ private void setOverlay(Object value, ProblemAnnotation problemAnnotation) {
+ if (value instanceof JavaMarkerAnnotation) {
+ JavaMarkerAnnotation annotation= (JavaMarkerAnnotation) value;
+ if (annotation.isProblem()) {
+ annotation.setOverlay(problemAnnotation);
+ fPreviouslyOverlaid.remove(annotation);
+ fCurrentlyOverlaid.add(annotation);
+ }
+ } else {
+ }
+ }
+
+ private void overlayMarkers(Position position, ProblemAnnotation problemAnnotation) {
+ Object value= getAnnotations(position);
+ if (value instanceof List) {
+ List list= (List) value;
+ for (Iterator e = list.iterator(); e.hasNext();)
+ setOverlay(e.next(), problemAnnotation);
+ } else {
+ setOverlay(value, problemAnnotation);
+ }
+ }
+
+ /**
+ * Tells this annotation model to collect temporary problems from now on.
+ */
+ private void startCollectingProblems() {
+ fGeneratedAnnotations= new ArrayList();
+ }
+
+ /**
+ * Tells this annotation model to no longer collect temporary problems.
+ */
+ private void stopCollectingProblems() {
+ if (fGeneratedAnnotations != null)
+ removeAnnotations(fGeneratedAnnotations, true, true);
+ fGeneratedAnnotations= null;
+ }
+
+ /*
+ * @see IProblemRequestor#isActive()
+ */
+ public boolean isActive() {
+ return fIsActive;
+ }
+
+ /*
+ * @see IProblemRequestorExtension#setProgressMonitor(IProgressMonitor)
+ */
+ public void setProgressMonitor(IProgressMonitor monitor) {
+ fProgressMonitor= monitor;
+ }
+
+ /*
+ * @see IProblemRequestorExtension#setIsActive(boolean)
+ */
+ public void setIsActive(boolean isActive) {
+ if (fIsActive != isActive) {
+ fIsActive= isActive;
+ if (fIsActive)
+ startCollectingProblems();
+ else
+ stopCollectingProblems();
+ }
+ }
+
+ private Object getAnnotations(Position position) {
+ return fReverseMap.get(position);
+ }
+
+ /*
+ * @see AnnotationModel#addAnnotation(Annotation, Position, boolean)
+ */
+ protected void addAnnotation(Annotation annotation, Position position, boolean fireModelChanged) throws BadLocationException {
+ super.addAnnotation(annotation, position, fireModelChanged);
+
+ Object cached= fReverseMap.get(position);
+ if (cached == null)
+ fReverseMap.put(position, annotation);
+ else if (cached instanceof List) {
+ List list= (List) cached;
+ list.add(annotation);
+ } else if (cached instanceof Annotation) {
+ List list= new ArrayList(2);
+ list.add(cached);
+ list.add(annotation);
+ fReverseMap.put(position, list);
+ }
+ }
+
+ /*
+ * @see AnnotationModel#removeAllAnnotations(boolean)
+ */
+ protected void removeAllAnnotations(boolean fireModelChanged) {
+ super.removeAllAnnotations(fireModelChanged);
+ fReverseMap.clear();
+ }
+
+ /*
+ * @see AnnotationModel#removeAnnotation(Annotation, boolean)
+ */
+ protected void removeAnnotation(Annotation annotation, boolean fireModelChanged) {
+ Position position= getPosition(annotation);
+ Object cached= fReverseMap.get(position);
+ if (cached instanceof List) {
+ List list= (List) cached;
+ list.remove(annotation);
+ if (list.size() == 1) {
+ fReverseMap.put(position, list.get(0));
+ list.clear();
+ }
+ } else if (cached instanceof Annotation) {
+ fReverseMap.remove(position);
+ }
+ super.removeAnnotation(annotation, fireModelChanged);
+ }
+ }
+
+
+
protected static class GlobalAnnotationModelListener implements IAnnotationModelListener, IAnnotationModelListenerExtension {
private ListenerList fListenerList;
@@ -640,16 +575,15 @@ public class PHPDocumentProvider extends FileDocumentProvider {
private boolean indicateQuixFixableProblems() {
return PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_CORRECTION_INDICATION);
}
-
+
/*
* @see Annotation#paint
*/
public void paint(GC gc, Canvas canvas, Rectangle r) {
initializeImages();
if (fImage != null)
- drawImage(fImage, gc, canvas, r, SWT.CENTER, SWT.TOP);
+ ImageUtilities.drawImage(fImage, gc, canvas, r, SWT.CENTER, SWT.TOP);
}
-
/*
* @see IJavaAnnotation#getImage(Display)
*/
@@ -897,8 +831,6 @@ public class PHPDocumentProvider extends FileDocumentProvider {
/* Preference key for temporary problems */
private final static String HANDLE_TEMPORARY_PROBLEMS = PreferenceConstants.EDITOR_EVALUTE_TEMPORARY_PROBLEMS;
- /** The buffer factory */
- private IBufferFactory fBufferFactory = new BufferFactory();
/** Indicates whether the save has been initialized by this provider */
private boolean fIsAboutToSave = false;
/** The save policy used by this provider */
@@ -910,17 +842,16 @@ public class PHPDocumentProvider extends FileDocumentProvider {
private GlobalAnnotationModelListener fGlobalAnnotationModelListener;
public PHPDocumentProvider() {
-
- fPropertyListener = new IPropertyChangeListener() {
- public void propertyChange(PropertyChangeEvent event) {
- if (HANDLE_TEMPORARY_PROBLEMS.equals(event.getProperty()))
- enableHandlingTemporaryProblems();
- }
- };
-
- fGlobalAnnotationModelListener = new GlobalAnnotationModelListener();
-
- PHPeclipsePlugin.getDefault().getPreferenceStore().addPropertyChangeListener(fPropertyListener);
+ setParentDocumentProvider(new TextFileDocumentProvider(new JavaStorageDocumentProvider()));
+
+ fPropertyListener= new IPropertyChangeListener() {
+ public void propertyChange(PropertyChangeEvent event) {
+ if (HANDLE_TEMPORARY_PROBLEMS.equals(event.getProperty()))
+ enableHandlingTemporaryProblems();
+ }
+ };
+ fGlobalAnnotationModelListener= new GlobalAnnotationModelListener();
+ PHPeclipsePlugin.getDefault().getPreferenceStore().addPropertyChangeListener(fPropertyListener);
}
@@ -942,214 +873,369 @@ public class PHPDocumentProvider extends FileDocumentProvider {
return (ICompilationUnit) element;
return null;
}
+
/*
+ * @see org.eclipse.ui.editors.text.TextFileDocumentProvider#createEmptyFileInfo()
+ */
+ protected FileInfo createEmptyFileInfo() {
+ return new CompilationUnitInfo();
+ }
+ /*
+ * @see org.eclipse.ui.editors.text.TextFileDocumentProvider#createAnnotationModel(org.eclipse.core.resources.IFile)
+ */
+ protected IAnnotationModel createAnnotationModel(IFile file) {
+ return new CompilationUnitAnnotationModel(file);
+ }
+ /*
* @see AbstractDocumentProvider#createElementInfo(Object)
*/
- protected ElementInfo createElementInfo(Object element) throws CoreException {
-
- if (!(element instanceof IFileEditorInput))
- return super.createElementInfo(element);
-
- IFileEditorInput input = (IFileEditorInput) element;
- ICompilationUnit original = createCompilationUnit(input.getFile());
- if (original != null) {
-
- try {
-
- try {
- refreshFile(input.getFile());
- } catch (CoreException x) {
- handleCoreException(x, PHPEditorMessages.getString("PHPDocumentProvider.error.createElementInfo")); //$NON-NLS-1$
- }
-
- IAnnotationModel m = createCompilationUnitAnnotationModel(input);
- IProblemRequestor r = m instanceof IProblemRequestor ? (IProblemRequestor) m : null;
- ICompilationUnit c = (ICompilationUnit) original.getSharedWorkingCopy(getProgressMonitor(), fBufferFactory, r);
-
- DocumentAdapter a = null;
- try {
- a = (DocumentAdapter) c.getBuffer();
- } catch (ClassCastException x) {
- IStatus status = new Status(IStatus.ERROR, PHPeclipsePlugin.PLUGIN_ID, PHPStatusConstants.TEMPLATE_IO_EXCEPTION, "Shared working copy has wrong buffer", x); //$NON-NLS-1$
- throw new CoreException(status);
- }
-
- _FileSynchronizer f = new _FileSynchronizer(input);
- f.install();
-
- CompilationUnitInfo info = new CompilationUnitInfo(a.getDocument(), m, f, c);
- info.setModificationStamp(computeModificationStamp(input.getFile()));
- info.fStatus = a.getStatus();
- info.fEncoding = getPersistedEncoding(input);
-
- if (r instanceof IProblemRequestorExtension) {
- IProblemRequestorExtension extension = (IProblemRequestorExtension) r;
- extension.setIsActive(isHandlingTemporaryProblems());
- }
- m.addAnnotationModelListener(fGlobalAnnotationModelListener);
-
- return info;
-
- } catch (JavaModelException x) {
- throw new CoreException(x.getStatus());
- }
- } else {
- return super.createElementInfo(element);
- }
- }
+// protected ElementInfo createElementInfo(Object element) throws CoreException {
+//
+// if (!(element instanceof IFileEditorInput))
+// return super.createElementInfo(element);
+//
+// IFileEditorInput input = (IFileEditorInput) element;
+// ICompilationUnit original = createCompilationUnit(input.getFile());
+// if (original != null) {
+//
+// try {
+//
+// try {
+// refreshFile(input.getFile());
+// } catch (CoreException x) {
+// handleCoreException(x, PHPEditorMessages.getString("PHPDocumentProvider.error.createElementInfo")); //$NON-NLS-1$
+// }
+//
+// IAnnotationModel m = createCompilationUnitAnnotationModel(input);
+// IProblemRequestor r = m instanceof IProblemRequestor ? (IProblemRequestor) m : null;
+// ICompilationUnit c = (ICompilationUnit) original.getSharedWorkingCopy(getProgressMonitor(), fBufferFactory, r);
+//
+// DocumentAdapter a = null;
+// try {
+// a = (DocumentAdapter) c.getBuffer();
+// } catch (ClassCastException x) {
+// IStatus status = new Status(IStatus.ERROR, PHPeclipsePlugin.PLUGIN_ID, PHPStatusConstants.TEMPLATE_IO_EXCEPTION, "Shared working copy has wrong buffer", x); //$NON-NLS-1$
+// throw new CoreException(status);
+// }
+//
+// _FileSynchronizer f = new _FileSynchronizer(input);
+// f.install();
+//
+// CompilationUnitInfo info = new CompilationUnitInfo(a.getDocument(), m, f, c);
+// info.setModificationStamp(computeModificationStamp(input.getFile()));
+// info.fStatus = a.getStatus();
+// info.fEncoding = getPersistedEncoding(input);
+//
+// if (r instanceof IProblemRequestorExtension) {
+// IProblemRequestorExtension extension = (IProblemRequestorExtension) r;
+// extension.setIsActive(isHandlingTemporaryProblems());
+// }
+// m.addAnnotationModelListener(fGlobalAnnotationModelListener);
+//
+// return info;
+//
+// } catch (JavaModelException x) {
+// throw new CoreException(x.getStatus());
+// }
+// } else {
+// return super.createElementInfo(element);
+// }
+// }
/*
* @see AbstractDocumentProvider#disposeElementInfo(Object, ElementInfo)
*/
- protected void disposeElementInfo(Object element, ElementInfo info) {
-
- if (info instanceof CompilationUnitInfo) {
- CompilationUnitInfo cuInfo = (CompilationUnitInfo) info;
- cuInfo.fCopy.destroy();
- cuInfo.fModel.removeAnnotationModelListener(fGlobalAnnotationModelListener);
- }
-
- super.disposeElementInfo(element, info);
- }
+// protected void disposeElementInfo(Object element, ElementInfo info) {
+//
+// if (info instanceof CompilationUnitInfo) {
+// CompilationUnitInfo cuInfo = (CompilationUnitInfo) info;
+// cuInfo.fCopy.destroy();
+// cuInfo.fModel.removeAnnotationModelListener(fGlobalAnnotationModelListener);
+// }
+//
+// super.disposeElementInfo(element, info);
+// }
/*
* @see AbstractDocumentProvider#doSaveDocument(IProgressMonitor, Object, IDocument, boolean)
*/
- protected void doSaveDocument(IProgressMonitor monitor, Object element, IDocument document, boolean overwrite)
- throws CoreException {
-
- ElementInfo elementInfo = getElementInfo(element);
- if (elementInfo instanceof CompilationUnitInfo) {
- CompilationUnitInfo info = (CompilationUnitInfo) elementInfo;
-
- // update structure, assumes lock on info.fCopy
- info.fCopy.reconcile();
-
- ICompilationUnit original = (ICompilationUnit) info.fCopy.getOriginalElement();
- IResource resource = original.getResource();
-
- if (resource == null) {
- // underlying resource has been deleted, just recreate file, ignore the rest
- super.doSaveDocument(monitor, element, document, overwrite);
- return;
- }
-
- if (resource != null && !overwrite)
- checkSynchronizationState(info.fModificationStamp, resource);
-
- if (fSavePolicy != null)
- fSavePolicy.preSave(info.fCopy);
-
- // inform about the upcoming content change
- fireElementStateChanging(element);
- try {
- fIsAboutToSave = true;
- // commit working copy
- info.fCopy.commit(overwrite, monitor);
- } catch (CoreException x) {
- // inform about the failure
- fireElementStateChangeFailed(element);
- throw x;
- } catch (RuntimeException x) {
- // inform about the failure
- fireElementStateChangeFailed(element);
- throw x;
- } finally {
- fIsAboutToSave = false;
- }
-
- // If here, the dirty state of the editor will change to "not dirty".
- // Thus, the state changing flag will be reset.
-
- AbstractMarkerAnnotationModel model = (AbstractMarkerAnnotationModel) info.fModel;
- model.updateMarkers(info.fDocument);
+// protected void doSaveDocument(IProgressMonitor monitor, Object element, IDocument document, boolean overwrite)
+// throws CoreException {
+//
+// ElementInfo elementInfo = getElementInfo(element);
+// if (elementInfo instanceof CompilationUnitInfo) {
+// CompilationUnitInfo info = (CompilationUnitInfo) elementInfo;
+//
+// // update structure, assumes lock on info.fCopy
+// info.fCopy.reconcile();
+//
+// ICompilationUnit original = (ICompilationUnit) info.fCopy.getOriginalElement();
+// IResource resource = original.getResource();
+//
+// if (resource == null) {
+// // underlying resource has been deleted, just recreate file, ignore the rest
+// super.doSaveDocument(monitor, element, document, overwrite);
+// return;
+// }
+//
+// if (resource != null && !overwrite)
+// checkSynchronizationState(info.fModificationStamp, resource);
+//
+// if (fSavePolicy != null)
+// fSavePolicy.preSave(info.fCopy);
+//
+// // inform about the upcoming content change
+// fireElementStateChanging(element);
+// try {
+// fIsAboutToSave = true;
+// // commit working copy
+// info.fCopy.commit(overwrite, monitor);
+// } catch (CoreException x) {
+// // inform about the failure
+// fireElementStateChangeFailed(element);
+// throw x;
+// } catch (RuntimeException x) {
+// // inform about the failure
+// fireElementStateChangeFailed(element);
+// throw x;
+// } finally {
+// fIsAboutToSave = false;
+// }
+//
+// // If here, the dirty state of the editor will change to "not dirty".
+// // Thus, the state changing flag will be reset.
+//
+// AbstractMarkerAnnotationModel model = (AbstractMarkerAnnotationModel) info.fModel;
+// model.updateMarkers(info.fDocument);
+//
+// if (resource != null)
+// info.setModificationStamp(computeModificationStamp(resource));
+//
+// if (fSavePolicy != null) {
+// ICompilationUnit unit = fSavePolicy.postSave(original);
+// if (unit != null) {
+// IResource r = unit.getResource();
+// IMarker[] markers = r.findMarkers(IMarker.MARKER, true, IResource.DEPTH_ZERO);
+// if (markers != null && markers.length > 0) {
+// for (int i = 0; i < markers.length; i++)
+// model.updateMarker(markers[i], info.fDocument, null);
+// }
+// }
+// }
+//
+// } else {
+// super.doSaveDocument(monitor, element, document, overwrite);
+// }
+// }
- if (resource != null)
- info.setModificationStamp(computeModificationStamp(resource));
+ /*
+ * @see org.eclipse.ui.editors.text.TextFileDocumentProvider#createFileInfo(java.lang.Object)
+ */
+ protected FileInfo createFileInfo(Object element) throws CoreException {
+ if (!(element instanceof IFileEditorInput))
+ return null;
+
+ IFileEditorInput input= (IFileEditorInput) element;
+ ICompilationUnit original= createCompilationUnit(input.getFile());
+ if (original == null)
+ return null;
+
+ FileInfo info= super.createFileInfo(element);
+ if (!(info instanceof CompilationUnitInfo))
+ return null;
+
+ CompilationUnitInfo cuInfo= (CompilationUnitInfo) info;
+ setUpSynchronization(cuInfo);
+
+ IProblemRequestor requestor= cuInfo.fModel instanceof IProblemRequestor ? (IProblemRequestor) cuInfo.fModel : null;
- if (fSavePolicy != null) {
- ICompilationUnit unit = fSavePolicy.postSave(original);
- if (unit != null) {
- IResource r = unit.getResource();
- IMarker[] markers = r.findMarkers(IMarker.MARKER, true, IResource.DEPTH_ZERO);
- if (markers != null && markers.length > 0) {
- for (int i = 0; i < markers.length; i++)
- model.updateMarker(markers[i], info.fDocument, null);
- }
+ original.becomeWorkingCopy(requestor, getProgressMonitor());
+ cuInfo.fCopy= original;
+
+ if (cuInfo.fModel instanceof CompilationUnitAnnotationModel) {
+ CompilationUnitAnnotationModel model= (CompilationUnitAnnotationModel) cuInfo.fModel;
+ model.setCompilationUnit(cuInfo.fCopy);
+ }
+
+ if (cuInfo.fModel != null)
+ cuInfo.fModel.addAnnotationModelListener(fGlobalAnnotationModelListener);
+
+ if (requestor instanceof IProblemRequestorExtension) {
+ IProblemRequestorExtension extension= (IProblemRequestorExtension) requestor;
+ extension.setIsActive(isHandlingTemporaryProblems());
+ }
+
+ return cuInfo;
+ }
+
+ private void setUpSynchronization(CompilationUnitInfo cuInfo) {
+ IDocument document= cuInfo.fTextFileBuffer.getDocument();
+ IAnnotationModel model= cuInfo.fModel;
+
+ if (document instanceof ISynchronizable && model instanceof ISynchronizable) {
+ Object lock= ((ISynchronizable) document).getLockObject();
+ ((ISynchronizable) model).setLockObject(lock);
}
- }
-
- } else {
- super.doSaveDocument(monitor, element, document, overwrite);
}
- }
-
- /**
- * Replaces createAnnotionModel of the super class.
- */
- protected IAnnotationModel createCompilationUnitAnnotationModel(Object element) throws CoreException {
- if ( !(element instanceof IFileEditorInput))
- throw new CoreException(PHPUIStatus.createError(
- IJavaModelStatusConstants.INVALID_RESOURCE_TYPE, "", null)); //$NON-NLS-1$
+
+ /*
+ * @see org.eclipse.ui.editors.text.TextFileDocumentProvider#disposeFileInfo(java.lang.Object, org.eclipse.ui.editors.text.TextFileDocumentProvider.FileInfo)
+ */
+ protected void disposeFileInfo(Object element, FileInfo info) {
+ if (info instanceof CompilationUnitInfo) {
+ CompilationUnitInfo cuInfo= (CompilationUnitInfo) info;
+
+ try {
+ cuInfo.fCopy.discardWorkingCopy();
+ } catch (JavaModelException x) {
+ handleCoreException(x, x.getMessage());
+ }
+
+ if (cuInfo.fModel != null)
+ cuInfo.fModel.removeAnnotationModelListener(fGlobalAnnotationModelListener);
+ }
+ super.disposeFileInfo(element, info);
+ }
+
+ protected void commitWorkingCopy(IProgressMonitor monitor, Object element, CompilationUnitInfo info, boolean overwrite) throws CoreException {
+
+ synchronized (info.fCopy) {
+ info.fCopy.reconcile();
+ }
+
+ IDocument document= info.fTextFileBuffer.getDocument();
+ IResource resource= info.fCopy.getResource();
+
+ Assert.isTrue(resource instanceof IFile);
+ if (!resource.exists()) {
+ // underlying resource has been deleted, just recreate file, ignore the rest
+ createFileFromDocument(monitor, (IFile) resource, document);
+ return;
+ }
+
+ if (fSavePolicy != null)
+ fSavePolicy.preSave(info.fCopy);
+
+ try {
- IFileEditorInput input= (IFileEditorInput) element;
- return new CompilationUnitAnnotationModel(input);
- }
+ fIsAboutToSave= true;
+ info.fCopy.commitWorkingCopy(overwrite, monitor);
+
+ } catch (CoreException x) {
+ // inform about the failure
+ fireElementStateChangeFailed(element);
+ throw x;
+ } catch (RuntimeException x) {
+ // inform about the failure
+ fireElementStateChangeFailed(element);
+ throw x;
+ } finally {
+ fIsAboutToSave= false;
+ }
+
+ // If here, the dirty state of the editor will change to "not dirty".
+ // Thus, the state changing flag will be reset.
+ if (info.fModel instanceof AbstractMarkerAnnotationModel) {
+ AbstractMarkerAnnotationModel model= (AbstractMarkerAnnotationModel) info.fModel;
+ model.updateMarkers(document);
+ }
+
+ if (fSavePolicy != null) {
+ ICompilationUnit unit= fSavePolicy.postSave(info.fCopy);
+ if (unit != null && info.fModel instanceof AbstractMarkerAnnotationModel) {
+ IResource r= unit.getResource();
+ IMarker[] markers= r.findMarkers(IMarker.MARKER, true, IResource.DEPTH_ZERO);
+ if (markers != null && markers.length > 0) {
+ AbstractMarkerAnnotationModel model= (AbstractMarkerAnnotationModel) info.fModel;
+ for (int i= 0; i < markers.length; i++)
+ model.updateMarker(document, markers[i], null);
+ }
+ }
+ }
+}
- // private IDocumentPartitioner createCSSPartitioner() {
- // return new DefaultPartitioner(getHTMLPartitionScanner(), TYPES);
- // }
+/*
+ * @see org.eclipse.ui.editors.text.TextFileDocumentProvider#createSaveOperation(java.lang.Object, org.eclipse.jface.text.IDocument, boolean)
+ */
+protected DocumentProviderOperation createSaveOperation(final Object element, final IDocument document, final boolean overwrite) throws CoreException {
+ final FileInfo info= getFileInfo(element);
+ if (info instanceof CompilationUnitInfo) {
+ return new DocumentProviderOperation() {
+ /*
+ * @see org.eclipse.ui.editors.text.TextFileDocumentProvider.DocumentProviderOperation#execute(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ protected void execute(IProgressMonitor monitor) throws CoreException {
+ commitWorkingCopy(monitor, element, (CompilationUnitInfo) info, overwrite);
+ }
+ /*
+ * @see org.eclipse.ui.editors.text.TextFileDocumentProvider.DocumentProviderOperation#getSchedulingRule()
+ */
+ public ISchedulingRule getSchedulingRule() {
+ if (info.fElement instanceof IFileEditorInput) {
+ IFile file= ((IFileEditorInput) info.fElement).getFile();
+ IResourceRuleFactory ruleFactory= ResourcesPlugin.getWorkspace().getRuleFactory();
+ if (file == null || !file.exists())
+ return ruleFactory.createRule(file);
+ else
+ return ruleFactory.modifyRule(file);
+ } else
+ return null;
+ }
+ };
+ }
+ return null;
+}
/* (non-Javadoc)
* Method declared on AbstractDocumentProvider
*/
- protected IDocument createDocument(Object element) throws CoreException {
- if (element instanceof IEditorInput) {
- Document document = new PartiallySynchronizedDocument();
- if (setDocumentContent(document, (IEditorInput) element, getEncoding(element))) {
- initializeDocument(document, (IEditorInput) element);
-
- //
- // IDocument document = super.createDocument(element);
- // if (document != null) {
- // IDocumentPartitioner partitioner = null;
- // if (element instanceof FileEditorInput) {
- // IFile file = (IFile) ((FileEditorInput) element).getAdapter(IFile.class);
- // String filename = file.getLocation().toString();
- // String extension = filename.substring(filename.lastIndexOf("."), filename.length());
- // // System.out.println(extension);
- // if (extension.equalsIgnoreCase(".html") || extension.equalsIgnoreCase(".htm")) {
- // // html
- // partitioner = createHTMLPartitioner();
- // } else if (extension.equalsIgnoreCase(".xml")) {
- // // xml
- // partitioner = createXMLPartitioner();
- // } else if (extension.equalsIgnoreCase(".js")) {
- // // javascript
- // partitioner = createJavaScriptPartitioner();
- // } else if (extension.equalsIgnoreCase(".css")) {
- // // cascading style sheets
- // partitioner = createCSSPartitioner();
- // } else if (extension.equalsIgnoreCase(".tpl")) {
- // // smarty ?
- // partitioner = createSmartyPartitioner();
- // } else if (extension.equalsIgnoreCase(".inc")) {
- // // php include files ?
- // partitioner = createIncludePartitioner();
- // }
- // }
- //
- // if (partitioner == null) {
- // partitioner = createPHPPartitioner();
- // }
- // document.setDocumentPartitioner(partitioner);
- // partitioner.connect(document);
- }
- return document;
- }
- return null;
- }
+// protected IDocument createDocument(Object element) throws CoreException {
+// if (element instanceof IEditorInput) {
+// Document document = new PartiallySynchronizedDocument();
+// if (setDocumentContent(document, (IEditorInput) element, getEncoding(element))) {
+// initializeDocument(document, (IEditorInput) element);
+//
+// //
+// // IDocument document = super.createDocument(element);
+// // if (document != null) {
+// // IDocumentPartitioner partitioner = null;
+// // if (element instanceof FileEditorInput) {
+// // IFile file = (IFile) ((FileEditorInput) element).getAdapter(IFile.class);
+// // String filename = file.getLocation().toString();
+// // String extension = filename.substring(filename.lastIndexOf("."), filename.length());
+// // // System.out.println(extension);
+// // if (extension.equalsIgnoreCase(".html") || extension.equalsIgnoreCase(".htm")) {
+// // // html
+// // partitioner = createHTMLPartitioner();
+// // } else if (extension.equalsIgnoreCase(".xml")) {
+// // // xml
+// // partitioner = createXMLPartitioner();
+// // } else if (extension.equalsIgnoreCase(".js")) {
+// // // javascript
+// // partitioner = createJavaScriptPartitioner();
+// // } else if (extension.equalsIgnoreCase(".css")) {
+// // // cascading style sheets
+// // partitioner = createCSSPartitioner();
+// // } else if (extension.equalsIgnoreCase(".tpl")) {
+// // // smarty ?
+// // partitioner = createSmartyPartitioner();
+// // } else if (extension.equalsIgnoreCase(".inc")) {
+// // // php include files ?
+// // partitioner = createIncludePartitioner();
+// // }
+// // }
+// //
+// // if (partitioner == null) {
+// // partitioner = createPHPPartitioner();
+// // }
+// // document.setDocumentPartitioner(partitioner);
+// // partitioner.connect(document);
+// }
+// return document;
+// }
+// return null;
+// }
// /**
// * Return a partitioner for .html files.
@@ -1227,78 +1313,78 @@ public class PHPDocumentProvider extends FileDocumentProvider {
// return XML_PARTITION_SCANNER;
// }
- protected void initializeDocument(IDocument document, IEditorInput editorInput) {
- if (document != null) {
- JavaTextTools tools = PHPeclipsePlugin.getDefault().getJavaTextTools();
- IDocumentPartitioner partitioner = null;
- if (editorInput != null && editorInput instanceof FileEditorInput) {
- IFile file = (IFile) ((FileEditorInput) editorInput).getAdapter(IFile.class);
- String filename = file.getLocation().toString();
- String extension = filename.substring(filename.lastIndexOf("."), filename.length());
- partitioner = tools.createDocumentPartitioner(extension);
- } else {
- partitioner = tools.createDocumentPartitioner(".php");
- }
- document.setDocumentPartitioner(partitioner);
- partitioner.connect(document);
- }
- }
+// protected void initializeDocument(IDocument document, IEditorInput editorInput) {
+// if (document != null) {
+// JavaTextTools tools = PHPeclipsePlugin.getDefault().getJavaTextTools();
+// IDocumentPartitioner partitioner = null;
+// if (editorInput != null && editorInput instanceof FileEditorInput) {
+// IFile file = (IFile) ((FileEditorInput) editorInput).getAdapter(IFile.class);
+// String filename = file.getLocation().toString();
+// String extension = filename.substring(filename.lastIndexOf("."), filename.length());
+// partitioner = tools.createDocumentPartitioner(extension);
+// } else {
+// partitioner = tools.createDocumentPartitioner(".php");
+// }
+// document.setDocumentPartitioner(partitioner);
+// partitioner.connect(document);
+// }
+// }
/*
* @see org.eclipse.ui.texteditor.AbstractDocumentProvider#doResetDocument(java.lang.Object, org.eclipse.core.runtime.IProgressMonitor)
*/
- protected void doResetDocument(Object element, IProgressMonitor monitor) throws CoreException {
- if (element == null)
- return;
-
- ElementInfo elementInfo= getElementInfo(element);
- if (elementInfo instanceof CompilationUnitInfo) {
- CompilationUnitInfo info= (CompilationUnitInfo) elementInfo;
-
- IDocument document;
- IStatus status= null;
-
- try {
-
- ICompilationUnit original= (ICompilationUnit) info.fCopy.getOriginalElement();
- IResource resource= original.getResource();
- if (resource instanceof IFile) {
-
- IFile file= (IFile) resource;
-
- try {
- refreshFile(file, monitor);
- } catch (CoreException x) {
- handleCoreException(x, PHPEditorMessages.getString("CompilationUnitDocumentProvider.error.resetDocument")); //$NON-NLS-1$
- }
-
- IFileEditorInput input= new FileEditorInput(file);
- document= super.createDocument(input);
-
- } else {
- document= createEmptyDocument();
- }
-
- } catch (CoreException x) {
- document= createEmptyDocument();
- status= x.getStatus();
- }
-
- fireElementContentAboutToBeReplaced(element);
-
- removeUnchangedElementListeners(element, info);
- info.fDocument.set(document.get());
- info.fCanBeSaved= false;
- info.fStatus= status;
- addUnchangedElementListeners(element, info);
-
- fireElementContentReplaced(element);
- fireElementDirtyStateChanged(element, false);
-
- } else {
- super.doResetDocument(element, monitor);
- }
- }
+// protected void doResetDocument(Object element, IProgressMonitor monitor) throws CoreException {
+// if (element == null)
+// return;
+//
+// ElementInfo elementInfo= getElementInfo(element);
+// if (elementInfo instanceof CompilationUnitInfo) {
+// CompilationUnitInfo info= (CompilationUnitInfo) elementInfo;
+//
+// IDocument document;
+// IStatus status= null;
+//
+// try {
+//
+// ICompilationUnit original= (ICompilationUnit) info.fCopy.getOriginalElement();
+// IResource resource= original.getResource();
+// if (resource instanceof IFile) {
+//
+// IFile file= (IFile) resource;
+//
+// try {
+// refreshFile(file, monitor);
+// } catch (CoreException x) {
+// handleCoreException(x, PHPEditorMessages.getString("CompilationUnitDocumentProvider.error.resetDocument")); //$NON-NLS-1$
+// }
+//
+// IFileEditorInput input= new FileEditorInput(file);
+// document= super.createDocument(input);
+//
+// } else {
+// document= createEmptyDocument();
+// }
+//
+// } catch (CoreException x) {
+// document= createEmptyDocument();
+// status= x.getStatus();
+// }
+//
+// fireElementContentAboutToBeReplaced(element);
+//
+// removeUnchangedElementListeners(element, info);
+// info.fDocument.set(document.get());
+// info.fCanBeSaved= false;
+// info.fStatus= status;
+// addUnchangedElementListeners(element, info);
+//
+// fireElementContentReplaced(element);
+// fireElementDirtyStateChanged(element, false);
+//
+// } else {
+// super.doResetDocument(element, monitor);
+// }
+// }
/*
* @see AbstractDocumentProvider#resetDocument(Object)
@@ -1399,42 +1485,28 @@ public class PHPDocumentProvider extends FileDocumentProvider {
return null;
}
- /**
- * Returns the working copy this document provider maintains for the given
- * element.
- *
- * @param element the given element
- * @return the working copy for the given element
- */
- ICompilationUnit getWorkingCopy(IEditorInput element) {
-
- ElementInfo elementInfo = getElementInfo(element);
- if (elementInfo instanceof CompilationUnitInfo) {
- CompilationUnitInfo info = (CompilationUnitInfo) elementInfo;
- return info.fCopy;
- }
-
- return null;
- }
-
- /**
- * Gets the BufferFactory.
- */
- public IBufferFactory getBufferFactory() {
- return fBufferFactory;
- }
-
- /**
- * Shuts down this document provider.
- */
- public void shutdown() {
+ /*
+ * @see org.eclipse.jdt.internal.ui.javaeditor.ICompilationUnitDocumentProvider#getWorkingCopy(java.lang.Object)
+ */
+ public ICompilationUnit getWorkingCopy(Object element) {
+ FileInfo fileInfo= getFileInfo(element);
+ if (fileInfo instanceof CompilationUnitInfo) {
+ CompilationUnitInfo info= (CompilationUnitInfo) fileInfo;
+ return info.fCopy;
+ }
+ return null;
+ }
- PHPeclipsePlugin.getDefault().getPreferenceStore().removePropertyChangeListener(fPropertyListener);
- Iterator e = getConnectedElements();
- while (e.hasNext())
- disconnect(e.next());
- }
+ /*
+ * @see org.eclipse.jdt.internal.ui.javaeditor.ICompilationUnitDocumentProvider#shutdown()
+ */
+ public void shutdown() {
+ PHPeclipsePlugin.getDefault().getPreferenceStore().removePropertyChangeListener(fPropertyListener);
+ Iterator e= getConnectedElementsIterator();
+ while (e.hasNext())
+ disconnect(e.next());
+ }
/**
* Returns the preference whether handling temporary problems is enabled.
@@ -1445,21 +1517,18 @@ public class PHPDocumentProvider extends FileDocumentProvider {
}
/**
- * Switches the state of problem acceptance according to the value in the preference store.
- */
- protected void enableHandlingTemporaryProblems() {
- boolean enable = isHandlingTemporaryProblems();
- for (Iterator iter = getConnectedElements(); iter.hasNext();) {
- ElementInfo element = getElementInfo(iter.next());
- if (element instanceof CompilationUnitInfo) {
- CompilationUnitInfo info = (CompilationUnitInfo) element;
- if (info.fModel instanceof IProblemRequestorExtension) {
- IProblemRequestorExtension extension = (IProblemRequestorExtension) info.fModel;
- extension.setIsActive(enable);
- }
- }
- }
- }
+ * Switches the state of problem acceptance according to the value in the preference store.
+ */
+ protected void enableHandlingTemporaryProblems() {
+ boolean enable= isHandlingTemporaryProblems();
+ for (Iterator iter= getFileInfosIterator(); iter.hasNext();) {
+ FileInfo info= (FileInfo) iter.next();
+ if (info.fModel instanceof IProblemRequestorExtension) {
+ IProblemRequestorExtension extension= (IProblemRequestorExtension) info.fModel;
+ extension.setIsActive(enable);
+ }
+ }
+ }
/**
* Adds a listener that reports changes from all compilation unit annotation models.
@@ -1475,13 +1544,4 @@ public class PHPDocumentProvider extends FileDocumentProvider {
fGlobalAnnotationModelListener.removeListener(listener);
}
- /**
- * Returns whether the given element is connected to this document provider.
- *
- * @param element the element
- * @return true
if the element is connected, false
otherwise
- */
- boolean isConnected(Object element) {
- return getElementInfo(element) != null;
- }
}