1 package net.sourceforge.phpeclipse.phpeditor;
3 /**********************************************************************
4 Copyright (c) 2000, 2002 IBM Corp. and others.
5 All rights reserved. This program and the accompanying materials
6 are made available under the terms of the Common Public License v1.0
7 which accompanies this distribution, and is available at
8 http://www.eclipse.org/legal/cpl-v10.html
11 IBM Corporation - Initial implementation
13 **********************************************************************/
15 import java.util.ArrayList;
16 import java.util.Iterator;
17 import java.util.List;
19 import net.sourceforge.phpdt.core.ICompilationUnit;
20 import net.sourceforge.phpdt.core.IProblemRequestor;
21 import net.sourceforge.phpdt.core.JavaCore;
22 import net.sourceforge.phpdt.core.JavaModelException;
23 import net.sourceforge.phpdt.core.compiler.IProblem;
24 import net.sourceforge.phpdt.internal.ui.text.IPHPPartitions;
25 import net.sourceforge.phpdt.internal.ui.text.java.IProblemRequestorExtension;
26 import net.sourceforge.phpdt.internal.ui.text.spelling.SpellReconcileStrategy.SpellProblem;
27 import net.sourceforge.phpdt.ui.PreferenceConstants;
28 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
30 import org.eclipse.core.resources.IFile;
31 import org.eclipse.core.resources.IMarker;
32 import org.eclipse.core.resources.IResource;
33 import org.eclipse.core.resources.IResourceRuleFactory;
34 import org.eclipse.core.resources.ResourcesPlugin;
35 import org.eclipse.core.runtime.CoreException;
36 import org.eclipse.core.runtime.IProgressMonitor;
37 import org.eclipse.core.runtime.jobs.ISchedulingRule;
38 import org.eclipse.jface.preference.IPreferenceStore;
39 import org.eclipse.jface.text.Assert;
40 import org.eclipse.jface.text.BadLocationException;
41 import org.eclipse.jface.text.DefaultLineTracker;
42 import org.eclipse.jface.text.Document;
43 import org.eclipse.jface.text.IDocument;
44 import org.eclipse.jface.text.ILineTracker;
45 import org.eclipse.jface.text.ISynchronizable;
46 import org.eclipse.jface.text.Position;
47 import org.eclipse.jface.text.source.Annotation;
48 import org.eclipse.jface.text.source.AnnotationModelEvent;
49 import org.eclipse.jface.text.source.IAnnotationAccessExtension;
50 import org.eclipse.jface.text.source.IAnnotationModel;
51 import org.eclipse.jface.text.source.IAnnotationModelListener;
52 import org.eclipse.jface.text.source.IAnnotationModelListenerExtension;
53 import org.eclipse.jface.text.source.IAnnotationPresentation;
54 import org.eclipse.jface.text.source.ImageUtilities;
55 import org.eclipse.jface.util.IPropertyChangeListener;
56 import org.eclipse.jface.util.ListenerList;
57 import org.eclipse.jface.util.PropertyChangeEvent;
58 import org.eclipse.swt.SWT;
59 import org.eclipse.swt.graphics.GC;
60 import org.eclipse.swt.graphics.Image;
61 import org.eclipse.swt.graphics.Rectangle;
62 import org.eclipse.swt.widgets.Canvas;
63 import org.eclipse.swt.widgets.Display;
64 import org.eclipse.ui.IFileEditorInput;
65 import org.eclipse.ui.editors.text.EditorsUI;
66 import org.eclipse.ui.editors.text.ForwardingDocumentProvider;
67 import org.eclipse.ui.editors.text.TextFileDocumentProvider;
68 import org.eclipse.ui.texteditor.AbstractMarkerAnnotationModel;
69 import org.eclipse.ui.texteditor.AnnotationPreference;
70 import org.eclipse.ui.texteditor.AnnotationPreferenceLookup;
71 import org.eclipse.ui.texteditor.IDocumentProvider;
72 import org.eclipse.ui.texteditor.MarkerAnnotation;
73 import org.eclipse.ui.texteditor.MarkerUtilities;
74 import org.eclipse.ui.texteditor.ResourceMarkerAnnotationModel;
77 * The PHPDocumentProvider provides the IDocuments used by java editors.
80 public class PHPDocumentProvider extends TextFileDocumentProvider implements
81 ICompilationUnitDocumentProvider {
83 * Here for visibility issues only.
87 * Bundle of all required informations to allow working copy management.
90 * Bundle of all required informations to allow working copy management.
92 static protected class CompilationUnitInfo extends FileInfo {
93 public ICompilationUnit fCopy;
97 * Annotation model dealing with java marker annotations and temporary
98 * problems. Also acts as problem requestor for its compilation unit.
99 * Initialiy inactive. Must explicitly be activated.
101 protected static class CompilationUnitAnnotationModel extends
102 ResourceMarkerAnnotationModel implements IProblemRequestor,
103 IProblemRequestorExtension {
105 private static class ProblemRequestorState {
106 boolean fInsideReportingSequence = false;
108 List fReportedProblems;
111 private ThreadLocal fProblemRequestorState = new ThreadLocal();
113 private int fStateCount = 0;
115 private ICompilationUnit fCompilationUnit;
117 private List fGeneratedAnnotations;
119 private IProgressMonitor fProgressMonitor;
121 private boolean fIsActive = false;
123 private ReverseMap fReverseMap = new ReverseMap();
125 private List fPreviouslyOverlaid = null;
127 private List fCurrentlyOverlaid = new ArrayList();
129 public CompilationUnitAnnotationModel(IResource resource) {
133 public void setCompilationUnit(ICompilationUnit unit) {
134 fCompilationUnit = unit;
137 protected MarkerAnnotation createMarkerAnnotation(IMarker marker) {
138 String markerType = MarkerUtilities.getMarkerType(marker);
139 if (markerType != null
141 .startsWith(JavaMarkerAnnotation.JAVA_MARKER_TYPE_PREFIX))
142 return new JavaMarkerAnnotation(marker);
143 return super.createMarkerAnnotation(marker);
147 * @see org.eclipse.jface.text.source.AnnotationModel#createAnnotationModelEvent()
149 protected AnnotationModelEvent createAnnotationModelEvent() {
150 return new CompilationUnitAnnotationModelEvent(this, getResource());
153 protected Position createPositionFromProblem(IProblem problem) {
154 int start = problem.getSourceStart();
158 int length = problem.getSourceEnd() - problem.getSourceStart() + 1;
162 return new Position(start, length);
166 * @see IProblemRequestor#beginReporting()
168 public void beginReporting() {
169 ProblemRequestorState state = (ProblemRequestorState) fProblemRequestorState
172 internalBeginReporting(false);
176 * @see net.sourceforge.phpdt.internal.ui.text.java.IProblemRequestorExtension#beginReportingSequence()
178 public void beginReportingSequence() {
179 ProblemRequestorState state = (ProblemRequestorState) fProblemRequestorState
182 internalBeginReporting(true);
186 * Sets up the infrastructure necessary for problem reporting.
188 * @param insideReportingSequence
189 * <code>true</code> if this method call is issued from
190 * inside a reporting sequence
192 private void internalBeginReporting(boolean insideReportingSequence) {
193 if (fCompilationUnit != null) {
195 // fCompilationUnit.getJavaProject().isOnClasspath(fCompilationUnit))
197 ProblemRequestorState state = new ProblemRequestorState();
198 state.fInsideReportingSequence = insideReportingSequence;
199 state.fReportedProblems = new ArrayList();
200 synchronized (getLockObject()) {
201 fProblemRequestorState.set(state);
208 * @see IProblemRequestor#acceptProblem(IProblem)
210 public void acceptProblem(IProblem problem) {
212 ProblemRequestorState state = (ProblemRequestorState) fProblemRequestorState
215 state.fReportedProblems.add(problem);
220 * @see IProblemRequestor#endReporting()
222 public void endReporting() {
223 ProblemRequestorState state = (ProblemRequestorState) fProblemRequestorState
225 if (state != null && !state.fInsideReportingSequence)
226 internalEndReporting(state);
230 * @see net.sourceforge.phpdt.internal.ui.text.java.IProblemRequestorExtension#endReportingSequence()
232 public void endReportingSequence() {
233 ProblemRequestorState state = (ProblemRequestorState) fProblemRequestorState
235 if (state != null && state.fInsideReportingSequence)
236 internalEndReporting(state);
239 private void internalEndReporting(ProblemRequestorState state) {
241 synchronized (getLockObject()) {
243 stateCount = fStateCount;
244 fProblemRequestorState.set(null);
247 if (stateCount == 0 && isActive())
248 reportProblems(state.fReportedProblems);
252 * Signals the end of problem reporting.
254 private void reportProblems(List reportedProblems) {
255 if (fProgressMonitor != null && fProgressMonitor.isCanceled())
258 boolean temporaryProblemsChanged = false;
260 synchronized (getLockObject()) {
262 boolean isCanceled = false;
264 fPreviouslyOverlaid = fCurrentlyOverlaid;
265 fCurrentlyOverlaid = new ArrayList();
267 if (fGeneratedAnnotations.size() > 0) {
268 temporaryProblemsChanged = true;
269 removeAnnotations(fGeneratedAnnotations, false, true);
270 fGeneratedAnnotations.clear();
273 if (reportedProblems != null && reportedProblems.size() > 0) {
275 Iterator e = reportedProblems.iterator();
276 while (e.hasNext()) {
278 if (fProgressMonitor != null
279 && fProgressMonitor.isCanceled()) {
284 IProblem problem = (IProblem) e.next();
285 Position position = createPositionFromProblem(problem);
286 if (position != null) {
289 ProblemAnnotation annotation = new ProblemAnnotation(
290 problem, fCompilationUnit);
291 overlayMarkers(position, annotation);
292 addAnnotation(annotation, position, false);
293 fGeneratedAnnotations.add(annotation);
295 temporaryProblemsChanged = true;
296 } catch (BadLocationException x) {
297 // ignore invalid position
303 removeMarkerOverlays(isCanceled);
304 fPreviouslyOverlaid = null;
307 if (temporaryProblemsChanged)
311 private void removeMarkerOverlays(boolean isCanceled) {
313 fCurrentlyOverlaid.addAll(fPreviouslyOverlaid);
314 } else if (fPreviouslyOverlaid != null) {
315 Iterator e = fPreviouslyOverlaid.iterator();
316 while (e.hasNext()) {
317 JavaMarkerAnnotation annotation = (JavaMarkerAnnotation) e
319 annotation.setOverlay(null);
325 * Overlays value with problem annotation.
327 * @param problemAnnotation
329 private void setOverlay(Object value,
330 ProblemAnnotation problemAnnotation) {
331 if (value instanceof JavaMarkerAnnotation) {
332 JavaMarkerAnnotation annotation = (JavaMarkerAnnotation) value;
333 if (annotation.isProblem()) {
334 annotation.setOverlay(problemAnnotation);
335 fPreviouslyOverlaid.remove(annotation);
336 fCurrentlyOverlaid.add(annotation);
342 private void overlayMarkers(Position position,
343 ProblemAnnotation problemAnnotation) {
344 Object value = getAnnotations(position);
345 if (value instanceof List) {
346 List list = (List) value;
347 for (Iterator e = list.iterator(); e.hasNext();)
348 setOverlay(e.next(), problemAnnotation);
350 setOverlay(value, problemAnnotation);
355 * Tells this annotation model to collect temporary problems from now
358 private void startCollectingProblems() {
359 fGeneratedAnnotations = new ArrayList();
363 * Tells this annotation model to no longer collect temporary problems.
365 private void stopCollectingProblems() {
366 if (fGeneratedAnnotations != null)
367 removeAnnotations(fGeneratedAnnotations, true, true);
368 fGeneratedAnnotations = null;
372 * @see IProblemRequestor#isActive()
374 public boolean isActive() {
379 * @see IProblemRequestorExtension#setProgressMonitor(IProgressMonitor)
381 public void setProgressMonitor(IProgressMonitor monitor) {
382 fProgressMonitor = monitor;
386 * @see IProblemRequestorExtension#setIsActive(boolean)
388 public void setIsActive(boolean isActive) {
389 if (fIsActive != isActive) {
390 fIsActive = isActive;
392 startCollectingProblems();
394 stopCollectingProblems();
398 private Object getAnnotations(Position position) {
399 return fReverseMap.get(position);
403 * @see AnnotationModel#addAnnotation(Annotation, Position, boolean)
405 protected void addAnnotation(Annotation annotation, Position position,
406 boolean fireModelChanged) throws BadLocationException {
407 super.addAnnotation(annotation, position, fireModelChanged);
409 Object cached = fReverseMap.get(position);
411 fReverseMap.put(position, annotation);
412 else if (cached instanceof List) {
413 List list = (List) cached;
414 list.add(annotation);
415 } else if (cached instanceof Annotation) {
416 List list = new ArrayList(2);
418 list.add(annotation);
419 fReverseMap.put(position, list);
424 * @see AnnotationModel#removeAllAnnotations(boolean)
426 protected void removeAllAnnotations(boolean fireModelChanged) {
427 super.removeAllAnnotations(fireModelChanged);
432 * @see AnnotationModel#removeAnnotation(Annotation, boolean)
434 protected void removeAnnotation(Annotation annotation,
435 boolean fireModelChanged) {
436 Position position = getPosition(annotation);
437 Object cached = fReverseMap.get(position);
438 if (cached instanceof List) {
439 List list = (List) cached;
440 list.remove(annotation);
441 if (list.size() == 1) {
442 fReverseMap.put(position, list.get(0));
445 } else if (cached instanceof Annotation) {
446 fReverseMap.remove(position);
448 super.removeAnnotation(annotation, fireModelChanged);
452 protected static class GlobalAnnotationModelListener implements
453 IAnnotationModelListener, IAnnotationModelListenerExtension {
455 private ListenerList fListenerList;
457 public GlobalAnnotationModelListener() {
458 fListenerList = new ListenerList();
461 public void addListener(IAnnotationModelListener listener) {
462 fListenerList.add(listener);
466 * @see IAnnotationModelListenerExtension#modelChanged(AnnotationModelEvent)
468 public void modelChanged(AnnotationModelEvent event) {
469 Object[] listeners = fListenerList.getListeners();
470 for (int i = 0; i < listeners.length; i++) {
471 Object curr = listeners[i];
472 if (curr instanceof IAnnotationModelListenerExtension) {
473 ((IAnnotationModelListenerExtension) curr)
474 .modelChanged(event);
480 * @see IAnnotationModelListener#modelChanged(IAnnotationModel)
482 public void modelChanged(IAnnotationModel model) {
483 Object[] listeners = fListenerList.getListeners();
484 for (int i = 0; i < listeners.length; i++) {
485 ((IAnnotationModelListener) listeners[i]).modelChanged(model);
489 public void removeListener(IAnnotationModelListener listener) {
490 fListenerList.remove(listener);
495 * Annotation representating an <code>IProblem</code>.
497 static public class ProblemAnnotation extends Annotation implements
498 IJavaAnnotation, IAnnotationPresentation {
500 private static final String SPELLING_ANNOTATION_TYPE = "org.eclipse.ui.workbench.texteditor.spelling";
502 // XXX: To be fully correct these constants should be non-static
504 * The layer in which task problem annotations are located.
506 private static final int TASK_LAYER;
509 * The layer in which info problem annotations are located.
511 private static final int INFO_LAYER;
514 * The layer in which warning problem annotations representing are
517 private static final int WARNING_LAYER;
520 * The layer in which error problem annotations representing are
523 private static final int ERROR_LAYER;
526 AnnotationPreferenceLookup lookup = EditorsUI
527 .getAnnotationPreferenceLookup();
528 TASK_LAYER = computeLayer(
529 "org.eclipse.ui.workbench.texteditor.task", lookup); //$NON-NLS-1$
530 INFO_LAYER = computeLayer("net.sourceforge.phpdt.ui.info", lookup); //$NON-NLS-1$
531 WARNING_LAYER = computeLayer(
532 "net.sourceforge.phpdt.ui.warning", lookup); //$NON-NLS-1$
533 ERROR_LAYER = computeLayer("net.sourceforge.phpdt.ui.error", lookup); //$NON-NLS-1$
536 private static int computeLayer(String annotationType,
537 AnnotationPreferenceLookup lookup) {
538 Annotation annotation = new Annotation(annotationType, false, null);
539 AnnotationPreference preference = lookup
540 .getAnnotationPreference(annotation);
541 if (preference != null)
542 return preference.getPresentationLayer() + 1;
544 return IAnnotationAccessExtension.DEFAULT_LAYER + 1;
547 // private static Image fgQuickFixImage;
548 // private static Image fgQuickFixErrorImage;
549 // private static boolean fgQuickFixImagesInitialized= false;
551 private ICompilationUnit fCompilationUnit;
553 private List fOverlaids;
555 private IProblem fProblem;
557 private Image fImage;
559 private boolean fQuickFixImagesInitialized = false;
561 private int fLayer = IAnnotationAccessExtension.DEFAULT_LAYER;
563 public ProblemAnnotation(IProblem problem, ICompilationUnit cu) {
566 fCompilationUnit = cu;
568 if (SpellProblem.Spelling == fProblem.getID()) {
569 setType(SPELLING_ANNOTATION_TYPE);
570 fLayer = WARNING_LAYER;
571 } else if (IProblem.Task == fProblem.getID()) {
572 setType(JavaMarkerAnnotation.TASK_ANNOTATION_TYPE);
574 } else if (fProblem.isWarning()) {
575 setType(JavaMarkerAnnotation.WARNING_ANNOTATION_TYPE);
576 fLayer = WARNING_LAYER;
577 } else if (fProblem.isError()) {
578 setType(JavaMarkerAnnotation.ERROR_ANNOTATION_TYPE);
579 fLayer = ERROR_LAYER;
581 setType(JavaMarkerAnnotation.INFO_ANNOTATION_TYPE);
587 * @see org.eclipse.jface.text.source.IAnnotationPresentation#getLayer()
589 public int getLayer() {
593 private void initializeImages() {
594 // http://bugs.eclipse.org/bugs/show_bug.cgi?id=18936
595 // if (!fQuickFixImagesInitialized) {
596 // if (isProblem() && indicateQuixFixableProblems() &&
597 // JavaCorrectionProcessor.hasCorrections(this)) { // no light bulb
599 // if (!fgQuickFixImagesInitialized) {
601 // JavaPluginImages.get(JavaPluginImages.IMG_OBJS_FIXABLE_PROBLEM);
602 // fgQuickFixErrorImage=
603 // JavaPluginImages.get(JavaPluginImages.IMG_OBJS_FIXABLE_ERROR);
604 // fgQuickFixImagesInitialized= true;
606 // if (JavaMarkerAnnotation.ERROR_ANNOTATION_TYPE.equals(getType()))
607 // fImage= fgQuickFixErrorImage;
609 // fImage= fgQuickFixImage;
611 // fQuickFixImagesInitialized= true;
615 private boolean indicateQuixFixableProblems() {
616 return PreferenceConstants.getPreferenceStore().getBoolean(
617 PreferenceConstants.EDITOR_CORRECTION_INDICATION);
621 * @see Annotation#paint
623 public void paint(GC gc, Canvas canvas, Rectangle r) {
626 ImageUtilities.drawImage(fImage, gc, canvas, r, SWT.CENTER,
631 * @see IJavaAnnotation#getImage(Display)
633 public Image getImage(Display display) {
639 * @see IJavaAnnotation#getMessage()
641 public String getText() {
642 return fProblem.getMessage();
646 * @see IJavaAnnotation#getArguments()
648 public String[] getArguments() {
649 return isProblem() ? fProblem.getArguments() : null;
653 * @see IJavaAnnotation#getId()
656 return fProblem.getID();
660 * @see IJavaAnnotation#isProblem()
662 public boolean isProblem() {
663 String type = getType();
664 return JavaMarkerAnnotation.WARNING_ANNOTATION_TYPE.equals(type)
665 || JavaMarkerAnnotation.ERROR_ANNOTATION_TYPE.equals(type)
666 || SPELLING_ANNOTATION_TYPE.equals(type);
670 * @see IJavaAnnotation#hasOverlay()
672 public boolean hasOverlay() {
677 * @see net.sourceforge.phpdt.internal.ui.javaeditor.IJavaAnnotation#getOverlay()
679 public IJavaAnnotation getOverlay() {
684 * @see IJavaAnnotation#addOverlaid(IJavaAnnotation)
686 public void addOverlaid(IJavaAnnotation annotation) {
687 if (fOverlaids == null)
688 fOverlaids = new ArrayList(1);
689 fOverlaids.add(annotation);
693 * @see IJavaAnnotation#removeOverlaid(IJavaAnnotation)
695 public void removeOverlaid(IJavaAnnotation annotation) {
696 if (fOverlaids != null) {
697 fOverlaids.remove(annotation);
698 if (fOverlaids.size() == 0)
704 * @see IJavaAnnotation#getOverlaidIterator()
706 public Iterator getOverlaidIterator() {
707 if (fOverlaids != null)
708 return fOverlaids.iterator();
713 * @see net.sourceforge.phpdt.internal.ui.javaeditor.IJavaAnnotation#getCompilationUnit()
715 public ICompilationUnit getCompilationUnit() {
716 return fCompilationUnit;
721 * Internal structure for mapping positions to some value. The reason for
722 * this specific structure is that positions can change over time. Thus a
723 * lookup is based on value and not on hash value.
725 protected static class ReverseMap {
733 private int fAnchor = 0;
735 private List fList = new ArrayList(2);
737 public ReverseMap() {
740 public void clear() {
744 public Object get(Position position) {
749 int length = fList.size();
750 for (int i = fAnchor; i < length; i++) {
751 entry = (Entry) fList.get(i);
752 if (entry.fPosition.equals(position)) {
759 for (int i = 0; i < fAnchor; i++) {
760 entry = (Entry) fList.get(i);
761 if (entry.fPosition.equals(position)) {
770 private int getIndex(Position position) {
772 int length = fList.size();
773 for (int i = 0; i < length; i++) {
774 entry = (Entry) fList.get(i);
775 if (entry.fPosition.equals(position))
781 public void put(Position position, Object value) {
782 int index = getIndex(position);
784 Entry entry = new Entry();
785 entry.fPosition = position;
786 entry.fValue = value;
789 Entry entry = (Entry) fList.get(index);
790 entry.fValue = value;
794 public void remove(Position position) {
795 int index = getIndex(position);
802 * Document that can also be used by a background reconciler.
804 protected static class PartiallySynchronizedDocument extends Document {
807 * @see IDocumentExtension#startSequentialRewrite(boolean)
809 synchronized public void startSequentialRewrite(boolean normalized) {
810 super.startSequentialRewrite(normalized);
814 * @see IDocumentExtension#stopSequentialRewrite()
816 synchronized public void stopSequentialRewrite() {
817 super.stopSequentialRewrite();
821 * @see IDocument#get()
823 synchronized public String get() {
828 * @see IDocument#get(int, int)
830 synchronized public String get(int offset, int length)
831 throws BadLocationException {
832 return super.get(offset, length);
836 * @see IDocument#getChar(int)
838 synchronized public char getChar(int offset)
839 throws BadLocationException {
840 return super.getChar(offset);
844 * @see IDocument#replace(int, int, String)
846 synchronized public void replace(int offset, int length, String text)
847 throws BadLocationException {
848 super.replace(offset, length, text);
852 * @see IDocument#set(String)
854 synchronized public void set(String text) {
860 // private static PHPPartitionScanner HTML_PARTITION_SCANNER = null;
862 // private static PHPPartitionScanner PHP_PARTITION_SCANNER = null;
863 // private static PHPPartitionScanner SMARTY_PARTITION_SCANNER = null;
865 // // private final static String[] TYPES= new String[] {
866 // PHPPartitionScanner.PHP, PHPPartitionScanner.JAVA_DOC,
867 // PHPPartitionScanner.JAVA_MULTILINE_COMMENT };
868 // private final static String[] TYPES =
870 // IPHPPartitionScannerConstants.PHP,
871 // IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT,
872 // IPHPPartitionScannerConstants.HTML,
873 // IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT,
874 // IPHPPartitionScannerConstants.JAVASCRIPT,
875 // IPHPPartitionScannerConstants.CSS,
876 // IPHPPartitionScannerConstants.SMARTY,
877 // IPHPPartitionScannerConstants.SMARTY_MULTILINE_COMMENT };
878 // private static PHPPartitionScanner XML_PARTITION_SCANNER = null;
880 /* Preference key for temporary problems */
881 private final static String HANDLE_TEMPORARY_PROBLEMS = PreferenceConstants.EDITOR_EVALUTE_TEMPORARY_PROBLEMS;
883 /** Indicates whether the save has been initialized by this provider */
884 private boolean fIsAboutToSave = false;
886 /** The save policy used by this provider */
887 private ISavePolicy fSavePolicy;
889 /** Internal property changed listener */
890 private IPropertyChangeListener fPropertyListener;
892 /** annotation model listener added to all created CU annotation models */
893 private GlobalAnnotationModelListener fGlobalAnnotationModelListener;
895 public PHPDocumentProvider() {
896 // IDocumentProvider provider= new TextFileDocumentProvider(new
897 // JavaStorageDocumentProvider());
898 IDocumentProvider provider = new TextFileDocumentProvider();
899 provider = new ForwardingDocumentProvider(
900 IPHPPartitions.PHP_PARTITIONING,
901 new JavaDocumentSetupParticipant(), provider);
902 setParentDocumentProvider(provider);
904 fGlobalAnnotationModelListener = new GlobalAnnotationModelListener();
905 fPropertyListener = new IPropertyChangeListener() {
906 public void propertyChange(PropertyChangeEvent event) {
907 if (HANDLE_TEMPORARY_PROBLEMS.equals(event.getProperty()))
908 enableHandlingTemporaryProblems();
911 PHPeclipsePlugin.getDefault().getPreferenceStore()
912 .addPropertyChangeListener(fPropertyListener);
917 * Sets the document provider's save policy.
919 public void setSavePolicy(ISavePolicy savePolicy) {
920 fSavePolicy = savePolicy;
924 * Creates a compilation unit from the given file.
927 * the file from which to create the compilation unit
929 protected ICompilationUnit createCompilationUnit(IFile file) {
930 Object element = JavaCore.create(file);
931 if (element instanceof ICompilationUnit)
932 return (ICompilationUnit) element;
937 * @see org.eclipse.ui.editors.text.TextFileDocumentProvider#createEmptyFileInfo()
939 protected FileInfo createEmptyFileInfo() {
940 return new CompilationUnitInfo();
944 * @see org.eclipse.ui.editors.text.TextFileDocumentProvider#createAnnotationModel(org.eclipse.core.resources.IFile)
946 protected IAnnotationModel createAnnotationModel(IFile file) {
947 return new CompilationUnitAnnotationModel(file);
951 * @see AbstractDocumentProvider#createElementInfo(Object)
953 // protected ElementInfo createElementInfo(Object element) throws
956 // if (!(element instanceof IFileEditorInput))
957 // return super.createElementInfo(element);
959 // IFileEditorInput input = (IFileEditorInput) element;
960 // ICompilationUnit original = createCompilationUnit(input.getFile());
961 // if (original != null) {
966 // refreshFile(input.getFile());
967 // } catch (CoreException x) {
968 // handleCoreException(x,
969 // PHPEditorMessages.getString("PHPDocumentProvider.error.createElementInfo"));
973 // IAnnotationModel m = createCompilationUnitAnnotationModel(input);
974 // IProblemRequestor r = m instanceof IProblemRequestor ?
975 // (IProblemRequestor) m : null;
976 // ICompilationUnit c = (ICompilationUnit)
977 // original.getSharedWorkingCopy(getProgressMonitor(), fBufferFactory, r);
979 // DocumentAdapter a = null;
981 // a = (DocumentAdapter) c.getBuffer();
982 // } catch (ClassCastException x) {
983 // IStatus status = new Status(IStatus.ERROR, PHPeclipsePlugin.PLUGIN_ID,
984 // PHPStatusConstants.TEMPLATE_IO_EXCEPTION, "Shared working copy has wrong
985 // buffer", x); //$NON-NLS-1$
986 // throw new CoreException(status);
989 // _FileSynchronizer f = new _FileSynchronizer(input);
992 // CompilationUnitInfo info = new CompilationUnitInfo(a.getDocument(), m, f,
994 // info.setModificationStamp(computeModificationStamp(input.getFile()));
995 // info.fStatus = a.getStatus();
996 // info.fEncoding = getPersistedEncoding(input);
998 // if (r instanceof IProblemRequestorExtension) {
999 // IProblemRequestorExtension extension = (IProblemRequestorExtension) r;
1000 // extension.setIsActive(isHandlingTemporaryProblems());
1002 // m.addAnnotationModelListener(fGlobalAnnotationModelListener);
1006 // } catch (JavaModelException x) {
1007 // throw new CoreException(x.getStatus());
1010 // return super.createElementInfo(element);
1014 * @see AbstractDocumentProvider#disposeElementInfo(Object, ElementInfo)
1016 // protected void disposeElementInfo(Object element, ElementInfo info) {
1018 // if (info instanceof CompilationUnitInfo) {
1019 // CompilationUnitInfo cuInfo = (CompilationUnitInfo) info;
1020 // cuInfo.fCopy.destroy();
1021 // cuInfo.fModel.removeAnnotationModelListener(fGlobalAnnotationModelListener);
1024 // super.disposeElementInfo(element, info);
1027 * @see AbstractDocumentProvider#doSaveDocument(IProgressMonitor, Object,
1028 * IDocument, boolean)
1030 // protected void doSaveDocument(IProgressMonitor monitor, Object element,
1031 // IDocument document, boolean overwrite)
1032 // throws CoreException {
1034 // ElementInfo elementInfo = getElementInfo(element);
1035 // if (elementInfo instanceof CompilationUnitInfo) {
1036 // CompilationUnitInfo info = (CompilationUnitInfo) elementInfo;
1038 // // update structure, assumes lock on info.fCopy
1039 // info.fCopy.reconcile();
1041 // ICompilationUnit original = (ICompilationUnit)
1042 // info.fCopy.getOriginalElement();
1043 // IResource resource = original.getResource();
1045 // if (resource == null) {
1046 // // underlying resource has been deleted, just recreate file, ignore the
1048 // super.doSaveDocument(monitor, element, document, overwrite);
1052 // if (resource != null && !overwrite)
1053 // checkSynchronizationState(info.fModificationStamp, resource);
1055 // if (fSavePolicy != null)
1056 // fSavePolicy.preSave(info.fCopy);
1058 // // inform about the upcoming content change
1059 // fireElementStateChanging(element);
1061 // fIsAboutToSave = true;
1062 // // commit working copy
1063 // info.fCopy.commit(overwrite, monitor);
1064 // } catch (CoreException x) {
1065 // // inform about the failure
1066 // fireElementStateChangeFailed(element);
1068 // } catch (RuntimeException x) {
1069 // // inform about the failure
1070 // fireElementStateChangeFailed(element);
1073 // fIsAboutToSave = false;
1076 // // If here, the dirty state of the editor will change to "not dirty".
1077 // // Thus, the state changing flag will be reset.
1079 // AbstractMarkerAnnotationModel model = (AbstractMarkerAnnotationModel)
1081 // model.updateMarkers(info.fDocument);
1083 // if (resource != null)
1084 // info.setModificationStamp(computeModificationStamp(resource));
1086 // if (fSavePolicy != null) {
1087 // ICompilationUnit unit = fSavePolicy.postSave(original);
1088 // if (unit != null) {
1089 // IResource r = unit.getResource();
1090 // IMarker[] markers = r.findMarkers(IMarker.MARKER, true,
1091 // IResource.DEPTH_ZERO);
1092 // if (markers != null && markers.length > 0) {
1093 // for (int i = 0; i < markers.length; i++)
1094 // model.updateMarker(markers[i], info.fDocument, null);
1100 // super.doSaveDocument(monitor, element, document, overwrite);
1104 * @see org.eclipse.ui.editors.text.TextFileDocumentProvider#createFileInfo(java.lang.Object)
1106 protected FileInfo createFileInfo(Object element) throws CoreException {
1107 if (!(element instanceof IFileEditorInput))
1110 IFileEditorInput input = (IFileEditorInput) element;
1111 ICompilationUnit original = createCompilationUnit(input.getFile());
1112 if (original == null)
1115 FileInfo info = super.createFileInfo(element);
1116 if (!(info instanceof CompilationUnitInfo))
1119 CompilationUnitInfo cuInfo = (CompilationUnitInfo) info;
1120 setUpSynchronization(cuInfo);
1122 IProblemRequestor requestor = cuInfo.fModel instanceof IProblemRequestor ? (IProblemRequestor) cuInfo.fModel
1125 original.becomeWorkingCopy(requestor, getProgressMonitor());
1126 cuInfo.fCopy = original;
1128 if (cuInfo.fModel instanceof CompilationUnitAnnotationModel) {
1129 CompilationUnitAnnotationModel model = (CompilationUnitAnnotationModel) cuInfo.fModel;
1130 model.setCompilationUnit(cuInfo.fCopy);
1133 if (cuInfo.fModel != null)
1135 .addAnnotationModelListener(fGlobalAnnotationModelListener);
1137 if (requestor instanceof IProblemRequestorExtension) {
1138 IProblemRequestorExtension extension = (IProblemRequestorExtension) requestor;
1139 extension.setIsActive(isHandlingTemporaryProblems());
1145 private void setUpSynchronization(CompilationUnitInfo cuInfo) {
1146 IDocument document = cuInfo.fTextFileBuffer.getDocument();
1147 IAnnotationModel model = cuInfo.fModel;
1149 if (document instanceof ISynchronizable
1150 && model instanceof ISynchronizable) {
1151 Object lock = ((ISynchronizable) document).getLockObject();
1152 ((ISynchronizable) model).setLockObject(lock);
1157 * @see org.eclipse.ui.editors.text.TextFileDocumentProvider#disposeFileInfo(java.lang.Object,
1158 * org.eclipse.ui.editors.text.TextFileDocumentProvider.FileInfo)
1160 protected void disposeFileInfo(Object element, FileInfo info) {
1161 if (info instanceof CompilationUnitInfo) {
1162 CompilationUnitInfo cuInfo = (CompilationUnitInfo) info;
1165 cuInfo.fCopy.discardWorkingCopy();
1166 } catch (JavaModelException x) {
1167 handleCoreException(x, x.getMessage());
1170 if (cuInfo.fModel != null)
1172 .removeAnnotationModelListener(fGlobalAnnotationModelListener);
1174 super.disposeFileInfo(element, info);
1177 protected void commitWorkingCopy(IProgressMonitor monitor, Object element,
1178 CompilationUnitInfo info, boolean overwrite) throws CoreException {
1179 synchronized (info.fCopy) {
1180 info.fCopy.reconcile();
1183 IDocument document = info.fTextFileBuffer.getDocument();
1184 IResource resource = info.fCopy.getResource();
1186 Assert.isTrue(resource instanceof IFile);
1187 if (!resource.exists()) {
1188 // underlying resource has been deleted, just recreate file, ignore
1190 createFileFromDocument(monitor, (IFile) resource, document);
1194 if (fSavePolicy != null)
1195 fSavePolicy.preSave(info.fCopy);
1199 fIsAboutToSave = true;
1200 info.fCopy.commitWorkingCopy(overwrite, monitor);
1202 } catch (CoreException x) {
1203 // inform about the failure
1204 fireElementStateChangeFailed(element);
1206 } catch (RuntimeException x) {
1207 // inform about the failure
1208 fireElementStateChangeFailed(element);
1211 fIsAboutToSave = false;
1214 // If here, the dirty state of the editor will change to "not dirty".
1215 // Thus, the state changing flag will be reset.
1216 if (info.fModel instanceof AbstractMarkerAnnotationModel) {
1217 AbstractMarkerAnnotationModel model = (AbstractMarkerAnnotationModel) info.fModel;
1218 model.updateMarkers(document);
1221 if (fSavePolicy != null) {
1222 ICompilationUnit unit = fSavePolicy.postSave(info.fCopy);
1224 && info.fModel instanceof AbstractMarkerAnnotationModel) {
1225 IResource r = unit.getResource();
1226 IMarker[] markers = r.findMarkers(IMarker.MARKER, true,
1227 IResource.DEPTH_ZERO);
1228 if (markers != null && markers.length > 0) {
1229 AbstractMarkerAnnotationModel model = (AbstractMarkerAnnotationModel) info.fModel;
1230 for (int i = 0; i < markers.length; i++)
1231 model.updateMarker(document, markers[i], null);
1239 * @see org.eclipse.ui.editors.text.TextFileDocumentProvider#createSaveOperation(java.lang.Object,
1240 * org.eclipse.jface.text.IDocument, boolean)
1242 protected DocumentProviderOperation createSaveOperation(
1243 final Object element, final IDocument document,
1244 final boolean overwrite) throws CoreException {
1245 // final FileInfo info= getFileInfo(element);
1246 // if (info instanceof CompilationUnitInfo) {
1247 // return new DocumentProviderOperation() {
1250 // org.eclipse.ui.editors.text.TextFileDocumentProvider.DocumentProviderOperation#execute(org.eclipse.core.runtime.IProgressMonitor)
1252 // protected void execute(IProgressMonitor monitor) throws CoreException
1254 // commitWorkingCopy(monitor, element, (CompilationUnitInfo) info,
1259 // org.eclipse.ui.editors.text.TextFileDocumentProvider.DocumentProviderOperation#getSchedulingRule()
1261 // public ISchedulingRule getSchedulingRule() {
1262 // if (info.fElement instanceof IFileEditorInput) {
1263 // IFile file= ((IFileEditorInput) info.fElement).getFile();
1264 // IResourceRuleFactory ruleFactory=
1265 // ResourcesPlugin.getWorkspace().getRuleFactory();
1266 // if (file == null || !file.exists())
1267 // return ruleFactory.createRule(file);
1269 // return ruleFactory.modifyRule(file);
1276 final FileInfo info = getFileInfo(element);
1277 if (info instanceof CompilationUnitInfo) {
1278 return new DocumentProviderOperation() {
1280 * @see org.eclipse.ui.editors.text.TextFileDocumentProvider.DocumentProviderOperation#execute(org.eclipse.core.runtime.IProgressMonitor)
1282 protected void execute(IProgressMonitor monitor)
1283 throws CoreException {
1284 commitWorkingCopy(monitor, element,
1285 (CompilationUnitInfo) info, overwrite);
1289 * @see org.eclipse.ui.editors.text.TextFileDocumentProvider.DocumentProviderOperation#getSchedulingRule()
1291 public ISchedulingRule getSchedulingRule() {
1292 if (info.fElement instanceof IFileEditorInput) {
1293 IFile file = ((IFileEditorInput) info.fElement)
1295 return computeSchedulingRule(file);
1305 * (non-Javadoc) Method declared on AbstractDocumentProvider
1307 // protected IDocument createDocument(Object element) throws CoreException {
1308 // if (element instanceof IEditorInput) {
1309 // Document document = new PartiallySynchronizedDocument();
1310 // if (setDocumentContent(document, (IEditorInput) element,
1311 // getEncoding(element))) {
1312 // initializeDocument(document, (IEditorInput) element);
1315 // // IDocument document = super.createDocument(element);
1316 // // if (document != null) {
1317 // // IDocumentPartitioner partitioner = null;
1318 // // if (element instanceof FileEditorInput) {
1319 // // IFile file = (IFile) ((FileEditorInput)
1320 // element).getAdapter(IFile.class);
1321 // // String filename = file.getLocation().toString();
1322 // // String extension = filename.substring(filename.lastIndexOf("."),
1323 // filename.length());
1324 // // // System.out.println(extension);
1325 // // if (extension.equalsIgnoreCase(".html") ||
1326 // extension.equalsIgnoreCase(".htm")) {
1328 // // partitioner = createHTMLPartitioner();
1329 // // } else if (extension.equalsIgnoreCase(".xml")) {
1331 // // partitioner = createXMLPartitioner();
1332 // // } else if (extension.equalsIgnoreCase(".js")) {
1334 // // partitioner = createJavaScriptPartitioner();
1335 // // } else if (extension.equalsIgnoreCase(".css")) {
1336 // // // cascading style sheets
1337 // // partitioner = createCSSPartitioner();
1338 // // } else if (extension.equalsIgnoreCase(".tpl")) {
1340 // // partitioner = createSmartyPartitioner();
1341 // // } else if (extension.equalsIgnoreCase(".inc")) {
1342 // // // php include files ?
1343 // // partitioner = createIncludePartitioner();
1347 // // if (partitioner == null) {
1348 // // partitioner = createPHPPartitioner();
1350 // // document.setDocumentPartitioner(partitioner);
1351 // // partitioner.connect(document);
1358 // * Return a partitioner for .html files.
1360 // private IDocumentPartitioner createHTMLPartitioner() {
1361 // return new DefaultPartitioner(getHTMLPartitionScanner(), TYPES);
1364 // private IDocumentPartitioner createIncludePartitioner() {
1365 // return new DefaultPartitioner(getPHPPartitionScanner(), TYPES);
1368 // private IDocumentPartitioner createJavaScriptPartitioner() {
1369 // return new DefaultPartitioner(getHTMLPartitionScanner(), TYPES);
1372 * Creates a line tracker working with the same line delimiters as the
1373 * document of the given element. Assumes the element to be managed by this
1374 * document provider.
1377 * the element serving as blue print
1378 * @return a line tracker based on the same line delimiters as the element's
1381 public ILineTracker createLineTracker(Object element) {
1382 return new DefaultLineTracker();
1386 // * Return a partitioner for .php files.
1388 // private IDocumentPartitioner createPHPPartitioner() {
1389 // return new DefaultPartitioner(getPHPPartitionScanner(), TYPES);
1392 // private IDocumentPartitioner createSmartyPartitioner() {
1393 // return new DefaultPartitioner(getSmartyPartitionScanner(), TYPES);
1396 // private IDocumentPartitioner createXMLPartitioner() {
1397 // return new DefaultPartitioner(getXMLPartitionScanner(), TYPES);
1401 // * Return a scanner for creating html partitions.
1403 // private PHPPartitionScanner getHTMLPartitionScanner() {
1404 // if (HTML_PARTITION_SCANNER == null)
1405 // HTML_PARTITION_SCANNER = new
1406 // PHPPartitionScanner(IPHPPartitionScannerConstants.HTML_FILE);
1407 // return HTML_PARTITION_SCANNER;
1410 // * Return a scanner for creating php partitions.
1412 // private PHPPartitionScanner getPHPPartitionScanner() {
1413 // if (PHP_PARTITION_SCANNER == null)
1414 // PHP_PARTITION_SCANNER = new
1415 // PHPPartitionScanner(IPHPPartitionScannerConstants.PHP_FILE);
1416 // return PHP_PARTITION_SCANNER;
1420 // * Return a scanner for creating smarty partitions.
1422 // private PHPPartitionScanner getSmartyPartitionScanner() {
1423 // if (SMARTY_PARTITION_SCANNER == null)
1424 // SMARTY_PARTITION_SCANNER = new
1425 // PHPPartitionScanner(IPHPPartitionScannerConstants.SMARTY_FILE);
1426 // return SMARTY_PARTITION_SCANNER;
1430 // * Return a scanner for creating xml partitions.
1432 // private PHPPartitionScanner getXMLPartitionScanner() {
1433 // if (XML_PARTITION_SCANNER == null)
1434 // XML_PARTITION_SCANNER = new
1435 // PHPPartitionScanner(IPHPPartitionScannerConstants.XML_FILE);
1436 // return XML_PARTITION_SCANNER;
1439 // protected void initializeDocument(IDocument document, IEditorInput
1441 // if (document != null) {
1442 // JavaTextTools tools = PHPeclipsePlugin.getDefault().getJavaTextTools();
1443 // IDocumentPartitioner partitioner = null;
1444 // if (editorInput != null && editorInput instanceof FileEditorInput) {
1445 // IFile file = (IFile) ((FileEditorInput)
1446 // editorInput).getAdapter(IFile.class);
1447 // String filename = file.getLocation().toString();
1448 // String extension = filename.substring(filename.lastIndexOf("."),
1449 // filename.length());
1450 // partitioner = tools.createDocumentPartitioner(extension);
1452 // partitioner = tools.createDocumentPartitioner(".php");
1454 // document.setDocumentPartitioner(partitioner);
1455 // partitioner.connect(document);
1460 * @see org.eclipse.ui.texteditor.AbstractDocumentProvider#doResetDocument(java.lang.Object,
1461 * org.eclipse.core.runtime.IProgressMonitor)
1463 // protected void doResetDocument(Object element, IProgressMonitor monitor)
1464 // throws CoreException {
1465 // if (element == null)
1468 // ElementInfo elementInfo= getElementInfo(element);
1469 // if (elementInfo instanceof CompilationUnitInfo) {
1470 // CompilationUnitInfo info= (CompilationUnitInfo) elementInfo;
1472 // IDocument document;
1473 // IStatus status= null;
1477 // ICompilationUnit original= (ICompilationUnit)
1478 // info.fCopy.getOriginalElement();
1479 // IResource resource= original.getResource();
1480 // if (resource instanceof IFile) {
1482 // IFile file= (IFile) resource;
1485 // refreshFile(file, monitor);
1486 // } catch (CoreException x) {
1487 // handleCoreException(x,
1488 // PHPEditorMessages.getString("CompilationUnitDocumentProvider.error.resetDocument"));
1492 // IFileEditorInput input= new FileEditorInput(file);
1493 // document= super.createDocument(input);
1496 // document= createEmptyDocument();
1499 // } catch (CoreException x) {
1500 // document= createEmptyDocument();
1501 // status= x.getStatus();
1504 // fireElementContentAboutToBeReplaced(element);
1506 // removeUnchangedElementListeners(element, info);
1507 // info.fDocument.set(document.get());
1508 // info.fCanBeSaved= false;
1509 // info.fStatus= status;
1510 // addUnchangedElementListeners(element, info);
1512 // fireElementContentReplaced(element);
1513 // fireElementDirtyStateChanged(element, false);
1516 // super.doResetDocument(element, monitor);
1520 * @see AbstractDocumentProvider#resetDocument(Object)
1522 // public void resetDocument(Object element) throws CoreException {
1523 // if (element == null)
1526 // ElementInfo elementInfo = getElementInfo(element);
1527 // if (elementInfo instanceof CompilationUnitInfo) {
1528 // CompilationUnitInfo info = (CompilationUnitInfo) elementInfo;
1530 // IDocument document;
1531 // IStatus status = null;
1535 // ICompilationUnit original = (ICompilationUnit)
1536 // info.fCopy.getOriginalElement();
1537 // IResource resource = original.getResource();
1538 // if (resource instanceof IFile) {
1540 // IFile file = (IFile) resource;
1543 // refreshFile(file);
1544 // } catch (CoreException x) {
1545 // handleCoreException(x,
1546 // PHPEditorMessages.getString("PHPDocumentProvider.error.resetDocument"));
1550 // IFileEditorInput input = new FileEditorInput(file);
1551 // document = super.createDocument(input);
1554 // document = new Document();
1557 // } catch (CoreException x) {
1558 // document = new Document();
1559 // status = x.getStatus();
1562 // fireElementContentAboutToBeReplaced(element);
1564 // removeUnchangedElementListeners(element, info);
1565 // info.fDocument.set(document.get());
1566 // info.fCanBeSaved = false;
1567 // info.fStatus = status;
1568 // addUnchangedElementListeners(element, info);
1570 // fireElementContentReplaced(element);
1571 // fireElementDirtyStateChanged(element, false);
1574 // super.resetDocument(element);
1578 * Saves the content of the given document to the given element. This is
1579 * only performed when this provider initiated the save.
1582 * the progress monitor
1584 * the element to which to save
1586 * the document to save
1588 * <code>true</code> if the save should be enforced
1590 public void saveDocumentContent(IProgressMonitor monitor, Object element,
1591 IDocument document, boolean overwrite) throws CoreException {
1592 if (!fIsAboutToSave)
1594 super.saveDocument(monitor, element, document, overwrite);
1595 // if (!fIsAboutToSave)
1598 // if (element instanceof IFileEditorInput) {
1599 // IFileEditorInput input = (IFileEditorInput) element;
1601 // String encoding = getEncoding(element);
1602 // if (encoding == null)
1603 // encoding = ResourcesPlugin.getEncoding();
1604 // InputStream stream = new
1605 // ByteArrayInputStream(document.get().getBytes(encoding));
1606 // IFile file = input.getFile();
1607 // file.setContents(stream, overwrite, true, monitor);
1608 // } catch (IOException x) {
1609 // IStatus s = new Status(IStatus.ERROR, PHPeclipsePlugin.PLUGIN_ID,
1610 // IStatus.OK, x.getMessage(), x);
1611 // throw new CoreException(s);
1617 * Returns the underlying resource for the given element.
1621 * @return the underlying resource of the given element
1623 // public IResource getUnderlyingResource(Object element) {
1624 // if (element instanceof IFileEditorInput) {
1625 // IFileEditorInput input = (IFileEditorInput) element;
1626 // return input.getFile();
1631 * @see net.sourceforge.phpdt.internal.ui.javaeditor.ICompilationUnitDocumentProvider#getWorkingCopy(java.lang.Object)
1633 public ICompilationUnit getWorkingCopy(Object element) {
1634 FileInfo fileInfo = getFileInfo(element);
1635 if (fileInfo instanceof CompilationUnitInfo) {
1636 CompilationUnitInfo info = (CompilationUnitInfo) fileInfo;
1643 * @see net.sourceforge.phpdt.internal.ui.javaeditor.ICompilationUnitDocumentProvider#shutdown()
1645 public void shutdown() {
1646 PHPeclipsePlugin.getDefault().getPreferenceStore()
1647 .removePropertyChangeListener(fPropertyListener);
1648 Iterator e = getConnectedElementsIterator();
1650 disconnect(e.next());
1654 * Returns the preference whether handling temporary problems is enabled.
1656 protected boolean isHandlingTemporaryProblems() {
1657 IPreferenceStore store = PHPeclipsePlugin.getDefault()
1658 .getPreferenceStore();
1659 return store.getBoolean(HANDLE_TEMPORARY_PROBLEMS);
1663 * Switches the state of problem acceptance according to the value in the
1666 protected void enableHandlingTemporaryProblems() {
1667 boolean enable = isHandlingTemporaryProblems();
1668 for (Iterator iter = getFileInfosIterator(); iter.hasNext();) {
1669 FileInfo info = (FileInfo) iter.next();
1670 if (info.fModel instanceof IProblemRequestorExtension) {
1671 IProblemRequestorExtension extension = (IProblemRequestorExtension) info.fModel;
1672 extension.setIsActive(enable);
1678 * Adds a listener that reports changes from all compilation unit annotation
1681 public void addGlobalAnnotationModelListener(
1682 IAnnotationModelListener listener) {
1683 fGlobalAnnotationModelListener.addListener(listener);
1687 * Removes the listener.
1689 public void removeGlobalAnnotationModelListener(
1690 IAnnotationModelListener listener) {
1691 fGlobalAnnotationModelListener.removeListener(listener);
1695 * Computes the scheduling rule needed to create or modify a resource. If
1696 * the resource exists, its modify rule is returned. If it does not, the
1697 * resource hierarchy is iterated towards the workspace root to find the
1698 * first parent of <code>toCreateOrModify</code> that exists. Then the
1699 * 'create' rule for the last non-existing resource is returned.
1701 * XXX This is a workaround for
1702 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=67601
1703 * IResourceRuleFactory.createRule should iterate the hierarchy itself.
1706 * XXX to be replaced by call to
1707 * TextFileDocumentProvider.computeSchedulingRule after 3.0
1710 * @param toCreateOrModify
1711 * the resource to create or modify
1712 * @return the minimal scheduling rule needed to modify or create a resource
1714 protected ISchedulingRule computeSchedulingRule(IResource toCreateOrModify) {
1715 IResourceRuleFactory factory = ResourcesPlugin.getWorkspace()
1717 if (toCreateOrModify.exists()) {
1718 return factory.modifyRule(toCreateOrModify);
1720 IResource parent = toCreateOrModify;
1722 toCreateOrModify = parent;
1723 parent = toCreateOrModify.getParent();
1724 } while (parent != null && !parent.exists());
1726 return factory.createRule(toCreateOrModify);