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;
29 import net.sourceforge.phpeclipse.ui.WebUI;
31 import org.eclipse.core.resources.IFile;
32 import org.eclipse.core.resources.IMarker;
33 import org.eclipse.core.resources.IResource;
34 import org.eclipse.core.resources.IResourceRuleFactory;
35 import org.eclipse.core.resources.ResourcesPlugin;
36 import org.eclipse.core.runtime.CoreException;
37 import org.eclipse.core.runtime.IProgressMonitor;
38 import org.eclipse.core.runtime.jobs.ISchedulingRule;
39 import org.eclipse.jface.preference.IPreferenceStore;
40 import org.eclipse.jface.text.Assert;
41 import org.eclipse.jface.text.BadLocationException;
42 import org.eclipse.jface.text.DefaultLineTracker;
43 import org.eclipse.jface.text.Document;
44 import org.eclipse.jface.text.IDocument;
45 import org.eclipse.jface.text.ILineTracker;
46 import org.eclipse.jface.text.ISynchronizable;
47 import org.eclipse.jface.text.Position;
48 import org.eclipse.jface.text.source.Annotation;
49 import org.eclipse.jface.text.source.AnnotationModelEvent;
50 import org.eclipse.jface.text.source.IAnnotationAccessExtension;
51 import org.eclipse.jface.text.source.IAnnotationModel;
52 import org.eclipse.jface.text.source.IAnnotationModelListener;
53 import org.eclipse.jface.text.source.IAnnotationModelListenerExtension;
54 import org.eclipse.jface.text.source.IAnnotationPresentation;
55 import org.eclipse.jface.text.source.ImageUtilities;
56 import org.eclipse.jface.util.IPropertyChangeListener;
57 import org.eclipse.jface.util.ListenerList;
58 import org.eclipse.jface.util.PropertyChangeEvent;
59 import org.eclipse.swt.SWT;
60 import org.eclipse.swt.graphics.GC;
61 import org.eclipse.swt.graphics.Image;
62 import org.eclipse.swt.graphics.Rectangle;
63 import org.eclipse.swt.widgets.Canvas;
64 import org.eclipse.swt.widgets.Display;
65 import org.eclipse.ui.IFileEditorInput;
66 import org.eclipse.ui.editors.text.EditorsUI;
67 import org.eclipse.ui.editors.text.ForwardingDocumentProvider;
68 import org.eclipse.ui.editors.text.TextFileDocumentProvider;
69 import org.eclipse.ui.texteditor.AbstractMarkerAnnotationModel;
70 import org.eclipse.ui.texteditor.AnnotationPreference;
71 import org.eclipse.ui.texteditor.AnnotationPreferenceLookup;
72 import org.eclipse.ui.texteditor.IDocumentProvider;
73 import org.eclipse.ui.texteditor.MarkerAnnotation;
74 import org.eclipse.ui.texteditor.MarkerUtilities;
75 import org.eclipse.ui.texteditor.ResourceMarkerAnnotationModel;
78 * The PHPDocumentProvider provides the IDocuments used by java editors.
81 public class PHPDocumentProvider extends TextFileDocumentProvider implements
82 ICompilationUnitDocumentProvider {
84 * Here for visibility issues only.
88 * Bundle of all required informations to allow working copy management.
91 * Bundle of all required informations to allow working copy management.
93 static protected class CompilationUnitInfo extends FileInfo {
94 public ICompilationUnit fCopy;
98 * Annotation model dealing with java marker annotations and temporary
99 * problems. Also acts as problem requestor for its compilation unit.
100 * Initialiy inactive. Must explicitly be activated.
102 protected static class CompilationUnitAnnotationModel extends
103 ResourceMarkerAnnotationModel implements IProblemRequestor,
104 IProblemRequestorExtension {
106 private static class ProblemRequestorState {
107 boolean fInsideReportingSequence = false;
109 List fReportedProblems;
112 private ThreadLocal fProblemRequestorState = new ThreadLocal();
114 private int fStateCount = 0;
116 private ICompilationUnit fCompilationUnit;
118 private List fGeneratedAnnotations;
120 private IProgressMonitor fProgressMonitor;
122 private boolean fIsActive = false;
124 private ReverseMap fReverseMap = new ReverseMap();
126 private List fPreviouslyOverlaid = null;
128 private List fCurrentlyOverlaid = new ArrayList();
130 public CompilationUnitAnnotationModel(IResource resource) {
134 public void setCompilationUnit(ICompilationUnit unit) {
135 fCompilationUnit = unit;
138 protected MarkerAnnotation createMarkerAnnotation(IMarker marker) {
139 String markerType = MarkerUtilities.getMarkerType(marker);
140 if (markerType != null
142 .startsWith(JavaMarkerAnnotation.JAVA_MARKER_TYPE_PREFIX))
143 return new JavaMarkerAnnotation(marker);
144 return super.createMarkerAnnotation(marker);
148 * @see org.eclipse.jface.text.source.AnnotationModel#createAnnotationModelEvent()
150 protected AnnotationModelEvent createAnnotationModelEvent() {
151 return new CompilationUnitAnnotationModelEvent(this, getResource());
154 protected Position createPositionFromProblem(IProblem problem) {
155 int start = problem.getSourceStart();
159 int length = problem.getSourceEnd() - problem.getSourceStart() + 1;
163 return new Position(start, length);
167 * @see IProblemRequestor#beginReporting()
169 public void beginReporting() {
170 ProblemRequestorState state = (ProblemRequestorState) fProblemRequestorState
173 internalBeginReporting(false);
177 * @see net.sourceforge.phpdt.internal.ui.text.java.IProblemRequestorExtension#beginReportingSequence()
179 public void beginReportingSequence() {
180 ProblemRequestorState state = (ProblemRequestorState) fProblemRequestorState
183 internalBeginReporting(true);
187 * Sets up the infrastructure necessary for problem reporting.
189 * @param insideReportingSequence
190 * <code>true</code> if this method call is issued from
191 * inside a reporting sequence
193 private void internalBeginReporting(boolean insideReportingSequence) {
194 if (fCompilationUnit != null) {
196 // fCompilationUnit.getJavaProject().isOnClasspath(fCompilationUnit))
198 ProblemRequestorState state = new ProblemRequestorState();
199 state.fInsideReportingSequence = insideReportingSequence;
200 state.fReportedProblems = new ArrayList();
201 synchronized (getLockObject()) {
202 fProblemRequestorState.set(state);
209 * @see IProblemRequestor#acceptProblem(IProblem)
211 public void acceptProblem(IProblem problem) {
213 ProblemRequestorState state = (ProblemRequestorState) fProblemRequestorState
216 state.fReportedProblems.add(problem);
221 * @see IProblemRequestor#endReporting()
223 public void endReporting() {
224 ProblemRequestorState state = (ProblemRequestorState) fProblemRequestorState
226 if (state != null && !state.fInsideReportingSequence)
227 internalEndReporting(state);
231 * @see net.sourceforge.phpdt.internal.ui.text.java.IProblemRequestorExtension#endReportingSequence()
233 public void endReportingSequence() {
234 ProblemRequestorState state = (ProblemRequestorState) fProblemRequestorState
236 if (state != null && state.fInsideReportingSequence)
237 internalEndReporting(state);
240 private void internalEndReporting(ProblemRequestorState state) {
242 synchronized (getLockObject()) {
244 stateCount = fStateCount;
245 fProblemRequestorState.set(null);
248 if (stateCount == 0 && isActive())
249 reportProblems(state.fReportedProblems);
253 * Signals the end of problem reporting.
255 private void reportProblems(List reportedProblems) {
256 if (fProgressMonitor != null && fProgressMonitor.isCanceled())
259 boolean temporaryProblemsChanged = false;
261 synchronized (getLockObject()) {
263 boolean isCanceled = false;
265 fPreviouslyOverlaid = fCurrentlyOverlaid;
266 fCurrentlyOverlaid = new ArrayList();
268 if (fGeneratedAnnotations.size() > 0) {
269 temporaryProblemsChanged = true;
270 removeAnnotations(fGeneratedAnnotations, false, true);
271 fGeneratedAnnotations.clear();
274 if (reportedProblems != null && reportedProblems.size() > 0) {
276 Iterator e = reportedProblems.iterator();
277 while (e.hasNext()) {
279 if (fProgressMonitor != null
280 && fProgressMonitor.isCanceled()) {
285 IProblem problem = (IProblem) e.next();
286 Position position = createPositionFromProblem(problem);
287 if (position != null) {
290 ProblemAnnotation annotation = new ProblemAnnotation(
291 problem, fCompilationUnit);
292 overlayMarkers(position, annotation);
293 addAnnotation(annotation, position, false);
294 fGeneratedAnnotations.add(annotation);
296 temporaryProblemsChanged = true;
297 } catch (BadLocationException x) {
298 // ignore invalid position
304 removeMarkerOverlays(isCanceled);
305 fPreviouslyOverlaid = null;
308 if (temporaryProblemsChanged)
312 private void removeMarkerOverlays(boolean isCanceled) {
314 fCurrentlyOverlaid.addAll(fPreviouslyOverlaid);
315 } else if (fPreviouslyOverlaid != null) {
316 Iterator e = fPreviouslyOverlaid.iterator();
317 while (e.hasNext()) {
318 JavaMarkerAnnotation annotation = (JavaMarkerAnnotation) e
320 annotation.setOverlay(null);
326 * Overlays value with problem annotation.
328 * @param problemAnnotation
330 private void setOverlay(Object value,
331 ProblemAnnotation problemAnnotation) {
332 if (value instanceof JavaMarkerAnnotation) {
333 JavaMarkerAnnotation annotation = (JavaMarkerAnnotation) value;
334 if (annotation.isProblem()) {
335 annotation.setOverlay(problemAnnotation);
336 fPreviouslyOverlaid.remove(annotation);
337 fCurrentlyOverlaid.add(annotation);
343 private void overlayMarkers(Position position,
344 ProblemAnnotation problemAnnotation) {
345 Object value = getAnnotations(position);
346 if (value instanceof List) {
347 List list = (List) value;
348 for (Iterator e = list.iterator(); e.hasNext();)
349 setOverlay(e.next(), problemAnnotation);
351 setOverlay(value, problemAnnotation);
356 * Tells this annotation model to collect temporary problems from now
359 private void startCollectingProblems() {
360 fGeneratedAnnotations = new ArrayList();
364 * Tells this annotation model to no longer collect temporary problems.
366 private void stopCollectingProblems() {
367 if (fGeneratedAnnotations != null)
368 removeAnnotations(fGeneratedAnnotations, true, true);
369 fGeneratedAnnotations = null;
373 * @see IProblemRequestor#isActive()
375 public boolean isActive() {
380 * @see IProblemRequestorExtension#setProgressMonitor(IProgressMonitor)
382 public void setProgressMonitor(IProgressMonitor monitor) {
383 fProgressMonitor = monitor;
387 * @see IProblemRequestorExtension#setIsActive(boolean)
389 public void setIsActive(boolean isActive) {
390 if (fIsActive != isActive) {
391 fIsActive = isActive;
393 startCollectingProblems();
395 stopCollectingProblems();
399 private Object getAnnotations(Position position) {
400 return fReverseMap.get(position);
404 * @see AnnotationModel#addAnnotation(Annotation, Position, boolean)
406 protected void addAnnotation(Annotation annotation, Position position,
407 boolean fireModelChanged) throws BadLocationException {
408 super.addAnnotation(annotation, position, fireModelChanged);
410 Object cached = fReverseMap.get(position);
412 fReverseMap.put(position, annotation);
413 else if (cached instanceof List) {
414 List list = (List) cached;
415 list.add(annotation);
416 } else if (cached instanceof Annotation) {
417 List list = new ArrayList(2);
419 list.add(annotation);
420 fReverseMap.put(position, list);
425 * @see AnnotationModel#removeAllAnnotations(boolean)
427 protected void removeAllAnnotations(boolean fireModelChanged) {
428 super.removeAllAnnotations(fireModelChanged);
433 * @see AnnotationModel#removeAnnotation(Annotation, boolean)
435 protected void removeAnnotation(Annotation annotation,
436 boolean fireModelChanged) {
437 Position position = getPosition(annotation);
438 Object cached = fReverseMap.get(position);
439 if (cached instanceof List) {
440 List list = (List) cached;
441 list.remove(annotation);
442 if (list.size() == 1) {
443 fReverseMap.put(position, list.get(0));
446 } else if (cached instanceof Annotation) {
447 fReverseMap.remove(position);
449 super.removeAnnotation(annotation, fireModelChanged);
453 protected static class GlobalAnnotationModelListener implements
454 IAnnotationModelListener, IAnnotationModelListenerExtension {
456 private ListenerList fListenerList;
458 public GlobalAnnotationModelListener() {
459 fListenerList = new ListenerList();
462 public void addListener(IAnnotationModelListener listener) {
463 fListenerList.add(listener);
467 * @see IAnnotationModelListenerExtension#modelChanged(AnnotationModelEvent)
469 public void modelChanged(AnnotationModelEvent event) {
470 Object[] listeners = fListenerList.getListeners();
471 for (int i = 0; i < listeners.length; i++) {
472 Object curr = listeners[i];
473 if (curr instanceof IAnnotationModelListenerExtension) {
474 ((IAnnotationModelListenerExtension) curr)
475 .modelChanged(event);
481 * @see IAnnotationModelListener#modelChanged(IAnnotationModel)
483 public void modelChanged(IAnnotationModel model) {
484 Object[] listeners = fListenerList.getListeners();
485 for (int i = 0; i < listeners.length; i++) {
486 ((IAnnotationModelListener) listeners[i]).modelChanged(model);
490 public void removeListener(IAnnotationModelListener listener) {
491 fListenerList.remove(listener);
496 * Annotation representating an <code>IProblem</code>.
498 static public class ProblemAnnotation extends Annotation implements
499 IJavaAnnotation, IAnnotationPresentation {
501 private static final String SPELLING_ANNOTATION_TYPE = "org.eclipse.ui.workbench.texteditor.spelling";
503 // XXX: To be fully correct these constants should be non-static
505 * The layer in which task problem annotations are located.
507 private static final int TASK_LAYER;
510 * The layer in which info problem annotations are located.
512 private static final int INFO_LAYER;
515 * The layer in which warning problem annotations representing are
518 private static final int WARNING_LAYER;
521 * The layer in which error problem annotations representing are
524 private static final int ERROR_LAYER;
527 AnnotationPreferenceLookup lookup = EditorsUI
528 .getAnnotationPreferenceLookup();
529 TASK_LAYER = computeLayer(
530 "org.eclipse.ui.workbench.texteditor.task", lookup); //$NON-NLS-1$
531 INFO_LAYER = computeLayer("net.sourceforge.phpdt.ui.info", lookup); //$NON-NLS-1$
532 WARNING_LAYER = computeLayer(
533 "net.sourceforge.phpdt.ui.warning", lookup); //$NON-NLS-1$
534 ERROR_LAYER = computeLayer("net.sourceforge.phpdt.ui.error", lookup); //$NON-NLS-1$
537 private static int computeLayer(String annotationType,
538 AnnotationPreferenceLookup lookup) {
539 Annotation annotation = new Annotation(annotationType, false, null);
540 AnnotationPreference preference = lookup
541 .getAnnotationPreference(annotation);
542 if (preference != null)
543 return preference.getPresentationLayer() + 1;
545 return IAnnotationAccessExtension.DEFAULT_LAYER + 1;
548 // private static Image fgQuickFixImage;
549 // private static Image fgQuickFixErrorImage;
550 // private static boolean fgQuickFixImagesInitialized= false;
552 private ICompilationUnit fCompilationUnit;
554 private List fOverlaids;
556 private IProblem fProblem;
558 private Image fImage;
560 private boolean fQuickFixImagesInitialized = false;
562 private int fLayer = IAnnotationAccessExtension.DEFAULT_LAYER;
564 public ProblemAnnotation(IProblem problem, ICompilationUnit cu) {
567 fCompilationUnit = cu;
569 if (SpellProblem.Spelling == fProblem.getID()) {
570 setType(SPELLING_ANNOTATION_TYPE);
571 fLayer = WARNING_LAYER;
572 } else if (IProblem.Task == fProblem.getID()) {
573 setType(JavaMarkerAnnotation.TASK_ANNOTATION_TYPE);
575 } else if (fProblem.isWarning()) {
576 setType(JavaMarkerAnnotation.WARNING_ANNOTATION_TYPE);
577 fLayer = WARNING_LAYER;
578 } else if (fProblem.isError()) {
579 setType(JavaMarkerAnnotation.ERROR_ANNOTATION_TYPE);
580 fLayer = ERROR_LAYER;
582 setType(JavaMarkerAnnotation.INFO_ANNOTATION_TYPE);
588 * @see org.eclipse.jface.text.source.IAnnotationPresentation#getLayer()
590 public int getLayer() {
594 private void initializeImages() {
595 // http://bugs.eclipse.org/bugs/show_bug.cgi?id=18936
596 // if (!fQuickFixImagesInitialized) {
597 // if (isProblem() && indicateQuixFixableProblems() &&
598 // JavaCorrectionProcessor.hasCorrections(this)) { // no light bulb
600 // if (!fgQuickFixImagesInitialized) {
602 // JavaPluginImages.get(JavaPluginImages.IMG_OBJS_FIXABLE_PROBLEM);
603 // fgQuickFixErrorImage=
604 // JavaPluginImages.get(JavaPluginImages.IMG_OBJS_FIXABLE_ERROR);
605 // fgQuickFixImagesInitialized= true;
607 // if (JavaMarkerAnnotation.ERROR_ANNOTATION_TYPE.equals(getType()))
608 // fImage= fgQuickFixErrorImage;
610 // fImage= fgQuickFixImage;
612 // fQuickFixImagesInitialized= true;
616 private boolean indicateQuixFixableProblems() {
617 return PreferenceConstants.getPreferenceStore().getBoolean(
618 PreferenceConstants.EDITOR_CORRECTION_INDICATION);
622 * @see Annotation#paint
624 public void paint(GC gc, Canvas canvas, Rectangle r) {
627 ImageUtilities.drawImage(fImage, gc, canvas, r, SWT.CENTER,
632 * @see IJavaAnnotation#getImage(Display)
634 public Image getImage(Display display) {
640 * @see IJavaAnnotation#getMessage()
642 public String getText() {
643 return fProblem.getMessage();
647 * @see IJavaAnnotation#getArguments()
649 public String[] getArguments() {
650 return isProblem() ? fProblem.getArguments() : null;
654 * @see IJavaAnnotation#getId()
657 return fProblem.getID();
661 * @see IJavaAnnotation#isProblem()
663 public boolean isProblem() {
664 String type = getType();
665 return JavaMarkerAnnotation.WARNING_ANNOTATION_TYPE.equals(type)
666 || JavaMarkerAnnotation.ERROR_ANNOTATION_TYPE.equals(type)
667 || SPELLING_ANNOTATION_TYPE.equals(type);
671 * @see IJavaAnnotation#hasOverlay()
673 public boolean hasOverlay() {
678 * @see net.sourceforge.phpdt.internal.ui.javaeditor.IJavaAnnotation#getOverlay()
680 public IJavaAnnotation getOverlay() {
685 * @see IJavaAnnotation#addOverlaid(IJavaAnnotation)
687 public void addOverlaid(IJavaAnnotation annotation) {
688 if (fOverlaids == null)
689 fOverlaids = new ArrayList(1);
690 fOverlaids.add(annotation);
694 * @see IJavaAnnotation#removeOverlaid(IJavaAnnotation)
696 public void removeOverlaid(IJavaAnnotation annotation) {
697 if (fOverlaids != null) {
698 fOverlaids.remove(annotation);
699 if (fOverlaids.size() == 0)
705 * @see IJavaAnnotation#getOverlaidIterator()
707 public Iterator getOverlaidIterator() {
708 if (fOverlaids != null)
709 return fOverlaids.iterator();
714 * @see net.sourceforge.phpdt.internal.ui.javaeditor.IJavaAnnotation#getCompilationUnit()
716 public ICompilationUnit getCompilationUnit() {
717 return fCompilationUnit;
722 * Internal structure for mapping positions to some value. The reason for
723 * this specific structure is that positions can change over time. Thus a
724 * lookup is based on value and not on hash value.
726 protected static class ReverseMap {
734 private int fAnchor = 0;
736 private List fList = new ArrayList(2);
738 public ReverseMap() {
741 public void clear() {
745 public Object get(Position position) {
750 int length = fList.size();
751 for (int i = fAnchor; i < length; i++) {
752 entry = (Entry) fList.get(i);
753 if (entry.fPosition.equals(position)) {
760 for (int i = 0; i < fAnchor; i++) {
761 entry = (Entry) fList.get(i);
762 if (entry.fPosition.equals(position)) {
771 private int getIndex(Position position) {
773 int length = fList.size();
774 for (int i = 0; i < length; i++) {
775 entry = (Entry) fList.get(i);
776 if (entry.fPosition.equals(position))
782 public void put(Position position, Object value) {
783 int index = getIndex(position);
785 Entry entry = new Entry();
786 entry.fPosition = position;
787 entry.fValue = value;
790 Entry entry = (Entry) fList.get(index);
791 entry.fValue = value;
795 public void remove(Position position) {
796 int index = getIndex(position);
803 * Document that can also be used by a background reconciler.
805 protected static class PartiallySynchronizedDocument extends Document {
808 * @see IDocumentExtension#startSequentialRewrite(boolean)
810 synchronized public void startSequentialRewrite(boolean normalized) {
811 super.startSequentialRewrite(normalized);
815 * @see IDocumentExtension#stopSequentialRewrite()
817 synchronized public void stopSequentialRewrite() {
818 super.stopSequentialRewrite();
822 * @see IDocument#get()
824 synchronized public String get() {
829 * @see IDocument#get(int, int)
831 synchronized public String get(int offset, int length)
832 throws BadLocationException {
833 return super.get(offset, length);
837 * @see IDocument#getChar(int)
839 synchronized public char getChar(int offset)
840 throws BadLocationException {
841 return super.getChar(offset);
845 * @see IDocument#replace(int, int, String)
847 synchronized public void replace(int offset, int length, String text)
848 throws BadLocationException {
849 super.replace(offset, length, text);
853 * @see IDocument#set(String)
855 synchronized public void set(String text) {
861 // private static PHPPartitionScanner HTML_PARTITION_SCANNER = null;
863 // private static PHPPartitionScanner PHP_PARTITION_SCANNER = null;
864 // private static PHPPartitionScanner SMARTY_PARTITION_SCANNER = null;
866 // // private final static String[] TYPES= new String[] {
867 // PHPPartitionScanner.PHP, PHPPartitionScanner.JAVA_DOC,
868 // PHPPartitionScanner.JAVA_MULTILINE_COMMENT };
869 // private final static String[] TYPES =
871 // IPHPPartitionScannerConstants.PHP,
872 // IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT,
873 // IPHPPartitionScannerConstants.HTML,
874 // IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT,
875 // IPHPPartitionScannerConstants.JAVASCRIPT,
876 // IPHPPartitionScannerConstants.CSS,
877 // IPHPPartitionScannerConstants.SMARTY,
878 // IPHPPartitionScannerConstants.SMARTY_MULTILINE_COMMENT };
879 // private static PHPPartitionScanner XML_PARTITION_SCANNER = null;
881 /* Preference key for temporary problems */
882 private final static String HANDLE_TEMPORARY_PROBLEMS = PreferenceConstants.EDITOR_EVALUTE_TEMPORARY_PROBLEMS;
884 /** Indicates whether the save has been initialized by this provider */
885 private boolean fIsAboutToSave = false;
887 /** The save policy used by this provider */
888 private ISavePolicy fSavePolicy;
890 /** Internal property changed listener */
891 private IPropertyChangeListener fPropertyListener;
893 /** annotation model listener added to all created CU annotation models */
894 private GlobalAnnotationModelListener fGlobalAnnotationModelListener;
896 public PHPDocumentProvider() {
897 // IDocumentProvider provider= new TextFileDocumentProvider(new
898 // JavaStorageDocumentProvider());
899 IDocumentProvider provider = new TextFileDocumentProvider();
900 provider = new ForwardingDocumentProvider(
901 IPHPPartitions.PHP_PARTITIONING,
902 new JavaDocumentSetupParticipant(), provider);
903 setParentDocumentProvider(provider);
905 fGlobalAnnotationModelListener = new GlobalAnnotationModelListener();
906 fPropertyListener = new IPropertyChangeListener() {
907 public void propertyChange(PropertyChangeEvent event) {
908 if (HANDLE_TEMPORARY_PROBLEMS.equals(event.getProperty()))
909 enableHandlingTemporaryProblems();
912 WebUI.getDefault().getPreferenceStore()
913 .addPropertyChangeListener(fPropertyListener);
918 * Sets the document provider's save policy.
920 public void setSavePolicy(ISavePolicy savePolicy) {
921 fSavePolicy = savePolicy;
925 * Creates a compilation unit from the given file.
928 * the file from which to create the compilation unit
930 protected ICompilationUnit createCompilationUnit(IFile file) {
931 Object element = JavaCore.create(file);
932 if (element instanceof ICompilationUnit)
933 return (ICompilationUnit) element;
938 * @see org.eclipse.ui.editors.text.TextFileDocumentProvider#createEmptyFileInfo()
940 protected FileInfo createEmptyFileInfo() {
941 return new CompilationUnitInfo();
945 * @see org.eclipse.ui.editors.text.TextFileDocumentProvider#createAnnotationModel(org.eclipse.core.resources.IFile)
947 protected IAnnotationModel createAnnotationModel(IFile file) {
948 return new CompilationUnitAnnotationModel(file);
952 * @see AbstractDocumentProvider#createElementInfo(Object)
954 // protected ElementInfo createElementInfo(Object element) throws
957 // if (!(element instanceof IFileEditorInput))
958 // return super.createElementInfo(element);
960 // IFileEditorInput input = (IFileEditorInput) element;
961 // ICompilationUnit original = createCompilationUnit(input.getFile());
962 // if (original != null) {
967 // refreshFile(input.getFile());
968 // } catch (CoreException x) {
969 // handleCoreException(x,
970 // PHPEditorMessages.getString("PHPDocumentProvider.error.createElementInfo"));
974 // IAnnotationModel m = createCompilationUnitAnnotationModel(input);
975 // IProblemRequestor r = m instanceof IProblemRequestor ?
976 // (IProblemRequestor) m : null;
977 // ICompilationUnit c = (ICompilationUnit)
978 // original.getSharedWorkingCopy(getProgressMonitor(), fBufferFactory, r);
980 // DocumentAdapter a = null;
982 // a = (DocumentAdapter) c.getBuffer();
983 // } catch (ClassCastException x) {
984 // IStatus status = new Status(IStatus.ERROR, PHPeclipsePlugin.PLUGIN_ID,
985 // PHPStatusConstants.TEMPLATE_IO_EXCEPTION, "Shared working copy has wrong
986 // buffer", x); //$NON-NLS-1$
987 // throw new CoreException(status);
990 // _FileSynchronizer f = new _FileSynchronizer(input);
993 // CompilationUnitInfo info = new CompilationUnitInfo(a.getDocument(), m, f,
995 // info.setModificationStamp(computeModificationStamp(input.getFile()));
996 // info.fStatus = a.getStatus();
997 // info.fEncoding = getPersistedEncoding(input);
999 // if (r instanceof IProblemRequestorExtension) {
1000 // IProblemRequestorExtension extension = (IProblemRequestorExtension) r;
1001 // extension.setIsActive(isHandlingTemporaryProblems());
1003 // m.addAnnotationModelListener(fGlobalAnnotationModelListener);
1007 // } catch (JavaModelException x) {
1008 // throw new CoreException(x.getStatus());
1011 // return super.createElementInfo(element);
1015 * @see AbstractDocumentProvider#disposeElementInfo(Object, ElementInfo)
1017 // protected void disposeElementInfo(Object element, ElementInfo info) {
1019 // if (info instanceof CompilationUnitInfo) {
1020 // CompilationUnitInfo cuInfo = (CompilationUnitInfo) info;
1021 // cuInfo.fCopy.destroy();
1022 // cuInfo.fModel.removeAnnotationModelListener(fGlobalAnnotationModelListener);
1025 // super.disposeElementInfo(element, info);
1028 * @see AbstractDocumentProvider#doSaveDocument(IProgressMonitor, Object,
1029 * IDocument, boolean)
1031 // protected void doSaveDocument(IProgressMonitor monitor, Object element,
1032 // IDocument document, boolean overwrite)
1033 // throws CoreException {
1035 // ElementInfo elementInfo = getElementInfo(element);
1036 // if (elementInfo instanceof CompilationUnitInfo) {
1037 // CompilationUnitInfo info = (CompilationUnitInfo) elementInfo;
1039 // // update structure, assumes lock on info.fCopy
1040 // info.fCopy.reconcile();
1042 // ICompilationUnit original = (ICompilationUnit)
1043 // info.fCopy.getOriginalElement();
1044 // IResource resource = original.getResource();
1046 // if (resource == null) {
1047 // // underlying resource has been deleted, just recreate file, ignore the
1049 // super.doSaveDocument(monitor, element, document, overwrite);
1053 // if (resource != null && !overwrite)
1054 // checkSynchronizationState(info.fModificationStamp, resource);
1056 // if (fSavePolicy != null)
1057 // fSavePolicy.preSave(info.fCopy);
1059 // // inform about the upcoming content change
1060 // fireElementStateChanging(element);
1062 // fIsAboutToSave = true;
1063 // // commit working copy
1064 // info.fCopy.commit(overwrite, monitor);
1065 // } catch (CoreException x) {
1066 // // inform about the failure
1067 // fireElementStateChangeFailed(element);
1069 // } catch (RuntimeException x) {
1070 // // inform about the failure
1071 // fireElementStateChangeFailed(element);
1074 // fIsAboutToSave = false;
1077 // // If here, the dirty state of the editor will change to "not dirty".
1078 // // Thus, the state changing flag will be reset.
1080 // AbstractMarkerAnnotationModel model = (AbstractMarkerAnnotationModel)
1082 // model.updateMarkers(info.fDocument);
1084 // if (resource != null)
1085 // info.setModificationStamp(computeModificationStamp(resource));
1087 // if (fSavePolicy != null) {
1088 // ICompilationUnit unit = fSavePolicy.postSave(original);
1089 // if (unit != null) {
1090 // IResource r = unit.getResource();
1091 // IMarker[] markers = r.findMarkers(IMarker.MARKER, true,
1092 // IResource.DEPTH_ZERO);
1093 // if (markers != null && markers.length > 0) {
1094 // for (int i = 0; i < markers.length; i++)
1095 // model.updateMarker(markers[i], info.fDocument, null);
1101 // super.doSaveDocument(monitor, element, document, overwrite);
1105 * @see org.eclipse.ui.editors.text.TextFileDocumentProvider#createFileInfo(java.lang.Object)
1107 protected FileInfo createFileInfo(Object element) throws CoreException {
1108 if (!(element instanceof IFileEditorInput))
1111 IFileEditorInput input = (IFileEditorInput) element;
1112 ICompilationUnit original = createCompilationUnit(input.getFile());
1113 if (original == null)
1116 FileInfo info = super.createFileInfo(element);
1117 if (!(info instanceof CompilationUnitInfo))
1120 CompilationUnitInfo cuInfo = (CompilationUnitInfo) info;
1121 setUpSynchronization(cuInfo);
1123 IProblemRequestor requestor = cuInfo.fModel instanceof IProblemRequestor ? (IProblemRequestor) cuInfo.fModel
1126 original.becomeWorkingCopy(requestor, getProgressMonitor());
1127 cuInfo.fCopy = original;
1129 if (cuInfo.fModel instanceof CompilationUnitAnnotationModel) {
1130 CompilationUnitAnnotationModel model = (CompilationUnitAnnotationModel) cuInfo.fModel;
1131 model.setCompilationUnit(cuInfo.fCopy);
1134 if (cuInfo.fModel != null)
1136 .addAnnotationModelListener(fGlobalAnnotationModelListener);
1138 if (requestor instanceof IProblemRequestorExtension) {
1139 IProblemRequestorExtension extension = (IProblemRequestorExtension) requestor;
1140 extension.setIsActive(isHandlingTemporaryProblems());
1146 private void setUpSynchronization(CompilationUnitInfo cuInfo) {
1147 IDocument document = cuInfo.fTextFileBuffer.getDocument();
1148 IAnnotationModel model = cuInfo.fModel;
1150 if (document instanceof ISynchronizable
1151 && model instanceof ISynchronizable) {
1152 Object lock = ((ISynchronizable) document).getLockObject();
1153 ((ISynchronizable) model).setLockObject(lock);
1158 * @see org.eclipse.ui.editors.text.TextFileDocumentProvider#disposeFileInfo(java.lang.Object,
1159 * org.eclipse.ui.editors.text.TextFileDocumentProvider.FileInfo)
1161 protected void disposeFileInfo(Object element, FileInfo info) {
1162 if (info instanceof CompilationUnitInfo) {
1163 CompilationUnitInfo cuInfo = (CompilationUnitInfo) info;
1166 cuInfo.fCopy.discardWorkingCopy();
1167 } catch (JavaModelException x) {
1168 handleCoreException(x, x.getMessage());
1171 if (cuInfo.fModel != null)
1173 .removeAnnotationModelListener(fGlobalAnnotationModelListener);
1175 super.disposeFileInfo(element, info);
1178 protected void commitWorkingCopy(IProgressMonitor monitor, Object element,
1179 CompilationUnitInfo info, boolean overwrite) throws CoreException {
1180 synchronized (info.fCopy) {
1181 info.fCopy.reconcile();
1184 IDocument document = info.fTextFileBuffer.getDocument();
1185 IResource resource = info.fCopy.getResource();
1187 Assert.isTrue(resource instanceof IFile);
1188 if (!resource.exists()) {
1189 // underlying resource has been deleted, just recreate file, ignore
1191 createFileFromDocument(monitor, (IFile) resource, document);
1195 if (fSavePolicy != null)
1196 fSavePolicy.preSave(info.fCopy);
1200 fIsAboutToSave = true;
1201 info.fCopy.commitWorkingCopy(overwrite, monitor);
1203 } catch (CoreException x) {
1204 // inform about the failure
1205 fireElementStateChangeFailed(element);
1207 } catch (RuntimeException x) {
1208 // inform about the failure
1209 fireElementStateChangeFailed(element);
1212 fIsAboutToSave = false;
1215 // If here, the dirty state of the editor will change to "not dirty".
1216 // Thus, the state changing flag will be reset.
1217 if (info.fModel instanceof AbstractMarkerAnnotationModel) {
1218 AbstractMarkerAnnotationModel model = (AbstractMarkerAnnotationModel) info.fModel;
1219 model.updateMarkers(document);
1222 if (fSavePolicy != null) {
1223 ICompilationUnit unit = fSavePolicy.postSave(info.fCopy);
1225 && info.fModel instanceof AbstractMarkerAnnotationModel) {
1226 IResource r = unit.getResource();
1227 IMarker[] markers = r.findMarkers(IMarker.MARKER, true,
1228 IResource.DEPTH_ZERO);
1229 if (markers != null && markers.length > 0) {
1230 AbstractMarkerAnnotationModel model = (AbstractMarkerAnnotationModel) info.fModel;
1231 for (int i = 0; i < markers.length; i++)
1232 model.updateMarker(document, markers[i], null);
1240 * @see org.eclipse.ui.editors.text.TextFileDocumentProvider#createSaveOperation(java.lang.Object,
1241 * org.eclipse.jface.text.IDocument, boolean)
1243 protected DocumentProviderOperation createSaveOperation(
1244 final Object element, final IDocument document,
1245 final boolean overwrite) throws CoreException {
1246 // final FileInfo info= getFileInfo(element);
1247 // if (info instanceof CompilationUnitInfo) {
1248 // return new DocumentProviderOperation() {
1251 // org.eclipse.ui.editors.text.TextFileDocumentProvider.DocumentProviderOperation#execute(org.eclipse.core.runtime.IProgressMonitor)
1253 // protected void execute(IProgressMonitor monitor) throws CoreException
1255 // commitWorkingCopy(monitor, element, (CompilationUnitInfo) info,
1260 // org.eclipse.ui.editors.text.TextFileDocumentProvider.DocumentProviderOperation#getSchedulingRule()
1262 // public ISchedulingRule getSchedulingRule() {
1263 // if (info.fElement instanceof IFileEditorInput) {
1264 // IFile file= ((IFileEditorInput) info.fElement).getFile();
1265 // IResourceRuleFactory ruleFactory=
1266 // ResourcesPlugin.getWorkspace().getRuleFactory();
1267 // if (file == null || !file.exists())
1268 // return ruleFactory.createRule(file);
1270 // return ruleFactory.modifyRule(file);
1277 final FileInfo info = getFileInfo(element);
1278 if (info instanceof CompilationUnitInfo) {
1279 return new DocumentProviderOperation() {
1281 * @see org.eclipse.ui.editors.text.TextFileDocumentProvider.DocumentProviderOperation#execute(org.eclipse.core.runtime.IProgressMonitor)
1283 protected void execute(IProgressMonitor monitor)
1284 throws CoreException {
1285 commitWorkingCopy(monitor, element,
1286 (CompilationUnitInfo) info, overwrite);
1290 * @see org.eclipse.ui.editors.text.TextFileDocumentProvider.DocumentProviderOperation#getSchedulingRule()
1292 public ISchedulingRule getSchedulingRule() {
1293 if (info.fElement instanceof IFileEditorInput) {
1294 IFile file = ((IFileEditorInput) info.fElement)
1296 return computeSchedulingRule(file);
1306 * (non-Javadoc) Method declared on AbstractDocumentProvider
1308 // protected IDocument createDocument(Object element) throws CoreException {
1309 // if (element instanceof IEditorInput) {
1310 // Document document = new PartiallySynchronizedDocument();
1311 // if (setDocumentContent(document, (IEditorInput) element,
1312 // getEncoding(element))) {
1313 // initializeDocument(document, (IEditorInput) element);
1316 // // IDocument document = super.createDocument(element);
1317 // // if (document != null) {
1318 // // IDocumentPartitioner partitioner = null;
1319 // // if (element instanceof FileEditorInput) {
1320 // // IFile file = (IFile) ((FileEditorInput)
1321 // element).getAdapter(IFile.class);
1322 // // String filename = file.getLocation().toString();
1323 // // String extension = filename.substring(filename.lastIndexOf("."),
1324 // filename.length());
1325 // // // System.out.println(extension);
1326 // // if (extension.equalsIgnoreCase(".html") ||
1327 // extension.equalsIgnoreCase(".htm")) {
1329 // // partitioner = createHTMLPartitioner();
1330 // // } else if (extension.equalsIgnoreCase(".xml")) {
1332 // // partitioner = createXMLPartitioner();
1333 // // } else if (extension.equalsIgnoreCase(".js")) {
1335 // // partitioner = createJavaScriptPartitioner();
1336 // // } else if (extension.equalsIgnoreCase(".css")) {
1337 // // // cascading style sheets
1338 // // partitioner = createCSSPartitioner();
1339 // // } else if (extension.equalsIgnoreCase(".tpl")) {
1341 // // partitioner = createSmartyPartitioner();
1342 // // } else if (extension.equalsIgnoreCase(".inc")) {
1343 // // // php include files ?
1344 // // partitioner = createIncludePartitioner();
1348 // // if (partitioner == null) {
1349 // // partitioner = createPHPPartitioner();
1351 // // document.setDocumentPartitioner(partitioner);
1352 // // partitioner.connect(document);
1359 // * Return a partitioner for .html files.
1361 // private IDocumentPartitioner createHTMLPartitioner() {
1362 // return new DefaultPartitioner(getHTMLPartitionScanner(), TYPES);
1365 // private IDocumentPartitioner createIncludePartitioner() {
1366 // return new DefaultPartitioner(getPHPPartitionScanner(), TYPES);
1369 // private IDocumentPartitioner createJavaScriptPartitioner() {
1370 // return new DefaultPartitioner(getHTMLPartitionScanner(), TYPES);
1373 * Creates a line tracker working with the same line delimiters as the
1374 * document of the given element. Assumes the element to be managed by this
1375 * document provider.
1378 * the element serving as blue print
1379 * @return a line tracker based on the same line delimiters as the element's
1382 public ILineTracker createLineTracker(Object element) {
1383 return new DefaultLineTracker();
1387 // * Return a partitioner for .php files.
1389 // private IDocumentPartitioner createPHPPartitioner() {
1390 // return new DefaultPartitioner(getPHPPartitionScanner(), TYPES);
1393 // private IDocumentPartitioner createSmartyPartitioner() {
1394 // return new DefaultPartitioner(getSmartyPartitionScanner(), TYPES);
1397 // private IDocumentPartitioner createXMLPartitioner() {
1398 // return new DefaultPartitioner(getXMLPartitionScanner(), TYPES);
1402 // * Return a scanner for creating html partitions.
1404 // private PHPPartitionScanner getHTMLPartitionScanner() {
1405 // if (HTML_PARTITION_SCANNER == null)
1406 // HTML_PARTITION_SCANNER = new
1407 // PHPPartitionScanner(IPHPPartitionScannerConstants.HTML_FILE);
1408 // return HTML_PARTITION_SCANNER;
1411 // * Return a scanner for creating php partitions.
1413 // private PHPPartitionScanner getPHPPartitionScanner() {
1414 // if (PHP_PARTITION_SCANNER == null)
1415 // PHP_PARTITION_SCANNER = new
1416 // PHPPartitionScanner(IPHPPartitionScannerConstants.PHP_FILE);
1417 // return PHP_PARTITION_SCANNER;
1421 // * Return a scanner for creating smarty partitions.
1423 // private PHPPartitionScanner getSmartyPartitionScanner() {
1424 // if (SMARTY_PARTITION_SCANNER == null)
1425 // SMARTY_PARTITION_SCANNER = new
1426 // PHPPartitionScanner(IPHPPartitionScannerConstants.SMARTY_FILE);
1427 // return SMARTY_PARTITION_SCANNER;
1431 // * Return a scanner for creating xml partitions.
1433 // private PHPPartitionScanner getXMLPartitionScanner() {
1434 // if (XML_PARTITION_SCANNER == null)
1435 // XML_PARTITION_SCANNER = new
1436 // PHPPartitionScanner(IPHPPartitionScannerConstants.XML_FILE);
1437 // return XML_PARTITION_SCANNER;
1440 // protected void initializeDocument(IDocument document, IEditorInput
1442 // if (document != null) {
1443 // JavaTextTools tools = PHPeclipsePlugin.getDefault().getJavaTextTools();
1444 // IDocumentPartitioner partitioner = null;
1445 // if (editorInput != null && editorInput instanceof FileEditorInput) {
1446 // IFile file = (IFile) ((FileEditorInput)
1447 // editorInput).getAdapter(IFile.class);
1448 // String filename = file.getLocation().toString();
1449 // String extension = filename.substring(filename.lastIndexOf("."),
1450 // filename.length());
1451 // partitioner = tools.createDocumentPartitioner(extension);
1453 // partitioner = tools.createDocumentPartitioner(".php");
1455 // document.setDocumentPartitioner(partitioner);
1456 // partitioner.connect(document);
1461 * @see org.eclipse.ui.texteditor.AbstractDocumentProvider#doResetDocument(java.lang.Object,
1462 * org.eclipse.core.runtime.IProgressMonitor)
1464 // protected void doResetDocument(Object element, IProgressMonitor monitor)
1465 // throws CoreException {
1466 // if (element == null)
1469 // ElementInfo elementInfo= getElementInfo(element);
1470 // if (elementInfo instanceof CompilationUnitInfo) {
1471 // CompilationUnitInfo info= (CompilationUnitInfo) elementInfo;
1473 // IDocument document;
1474 // IStatus status= null;
1478 // ICompilationUnit original= (ICompilationUnit)
1479 // info.fCopy.getOriginalElement();
1480 // IResource resource= original.getResource();
1481 // if (resource instanceof IFile) {
1483 // IFile file= (IFile) resource;
1486 // refreshFile(file, monitor);
1487 // } catch (CoreException x) {
1488 // handleCoreException(x,
1489 // PHPEditorMessages.getString("CompilationUnitDocumentProvider.error.resetDocument"));
1493 // IFileEditorInput input= new FileEditorInput(file);
1494 // document= super.createDocument(input);
1497 // document= createEmptyDocument();
1500 // } catch (CoreException x) {
1501 // document= createEmptyDocument();
1502 // status= x.getStatus();
1505 // fireElementContentAboutToBeReplaced(element);
1507 // removeUnchangedElementListeners(element, info);
1508 // info.fDocument.set(document.get());
1509 // info.fCanBeSaved= false;
1510 // info.fStatus= status;
1511 // addUnchangedElementListeners(element, info);
1513 // fireElementContentReplaced(element);
1514 // fireElementDirtyStateChanged(element, false);
1517 // super.doResetDocument(element, monitor);
1521 * @see AbstractDocumentProvider#resetDocument(Object)
1523 // public void resetDocument(Object element) throws CoreException {
1524 // if (element == null)
1527 // ElementInfo elementInfo = getElementInfo(element);
1528 // if (elementInfo instanceof CompilationUnitInfo) {
1529 // CompilationUnitInfo info = (CompilationUnitInfo) elementInfo;
1531 // IDocument document;
1532 // IStatus status = null;
1536 // ICompilationUnit original = (ICompilationUnit)
1537 // info.fCopy.getOriginalElement();
1538 // IResource resource = original.getResource();
1539 // if (resource instanceof IFile) {
1541 // IFile file = (IFile) resource;
1544 // refreshFile(file);
1545 // } catch (CoreException x) {
1546 // handleCoreException(x,
1547 // PHPEditorMessages.getString("PHPDocumentProvider.error.resetDocument"));
1551 // IFileEditorInput input = new FileEditorInput(file);
1552 // document = super.createDocument(input);
1555 // document = new Document();
1558 // } catch (CoreException x) {
1559 // document = new Document();
1560 // status = x.getStatus();
1563 // fireElementContentAboutToBeReplaced(element);
1565 // removeUnchangedElementListeners(element, info);
1566 // info.fDocument.set(document.get());
1567 // info.fCanBeSaved = false;
1568 // info.fStatus = status;
1569 // addUnchangedElementListeners(element, info);
1571 // fireElementContentReplaced(element);
1572 // fireElementDirtyStateChanged(element, false);
1575 // super.resetDocument(element);
1579 * Saves the content of the given document to the given element. This is
1580 * only performed when this provider initiated the save.
1583 * the progress monitor
1585 * the element to which to save
1587 * the document to save
1589 * <code>true</code> if the save should be enforced
1591 public void saveDocumentContent(IProgressMonitor monitor, Object element,
1592 IDocument document, boolean overwrite) throws CoreException {
1593 if (!fIsAboutToSave)
1595 super.saveDocument(monitor, element, document, overwrite);
1596 // if (!fIsAboutToSave)
1599 // if (element instanceof IFileEditorInput) {
1600 // IFileEditorInput input = (IFileEditorInput) element;
1602 // String encoding = getEncoding(element);
1603 // if (encoding == null)
1604 // encoding = ResourcesPlugin.getEncoding();
1605 // InputStream stream = new
1606 // ByteArrayInputStream(document.get().getBytes(encoding));
1607 // IFile file = input.getFile();
1608 // file.setContents(stream, overwrite, true, monitor);
1609 // } catch (IOException x) {
1610 // IStatus s = new Status(IStatus.ERROR, PHPeclipsePlugin.PLUGIN_ID,
1611 // IStatus.OK, x.getMessage(), x);
1612 // throw new CoreException(s);
1618 * Returns the underlying resource for the given element.
1622 * @return the underlying resource of the given element
1624 // public IResource getUnderlyingResource(Object element) {
1625 // if (element instanceof IFileEditorInput) {
1626 // IFileEditorInput input = (IFileEditorInput) element;
1627 // return input.getFile();
1632 * @see net.sourceforge.phpdt.internal.ui.javaeditor.ICompilationUnitDocumentProvider#getWorkingCopy(java.lang.Object)
1634 public ICompilationUnit getWorkingCopy(Object element) {
1635 FileInfo fileInfo = getFileInfo(element);
1636 if (fileInfo instanceof CompilationUnitInfo) {
1637 CompilationUnitInfo info = (CompilationUnitInfo) fileInfo;
1644 * @see net.sourceforge.phpdt.internal.ui.javaeditor.ICompilationUnitDocumentProvider#shutdown()
1646 public void shutdown() {
1647 WebUI.getDefault().getPreferenceStore()
1648 .removePropertyChangeListener(fPropertyListener);
1649 Iterator e = getConnectedElementsIterator();
1651 disconnect(e.next());
1655 * Returns the preference whether handling temporary problems is enabled.
1657 protected boolean isHandlingTemporaryProblems() {
1658 IPreferenceStore store = WebUI.getDefault()
1659 .getPreferenceStore();
1660 return store.getBoolean(HANDLE_TEMPORARY_PROBLEMS);
1664 * Switches the state of problem acceptance according to the value in the
1667 protected void enableHandlingTemporaryProblems() {
1668 boolean enable = isHandlingTemporaryProblems();
1669 for (Iterator iter = getFileInfosIterator(); iter.hasNext();) {
1670 FileInfo info = (FileInfo) iter.next();
1671 if (info.fModel instanceof IProblemRequestorExtension) {
1672 IProblemRequestorExtension extension = (IProblemRequestorExtension) info.fModel;
1673 extension.setIsActive(enable);
1679 * Adds a listener that reports changes from all compilation unit annotation
1682 public void addGlobalAnnotationModelListener(
1683 IAnnotationModelListener listener) {
1684 fGlobalAnnotationModelListener.addListener(listener);
1688 * Removes the listener.
1690 public void removeGlobalAnnotationModelListener(
1691 IAnnotationModelListener listener) {
1692 fGlobalAnnotationModelListener.removeListener(listener);
1696 * Computes the scheduling rule needed to create or modify a resource. If
1697 * the resource exists, its modify rule is returned. If it does not, the
1698 * resource hierarchy is iterated towards the workspace root to find the
1699 * first parent of <code>toCreateOrModify</code> that exists. Then the
1700 * 'create' rule for the last non-existing resource is returned.
1702 * XXX This is a workaround for
1703 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=67601
1704 * IResourceRuleFactory.createRule should iterate the hierarchy itself.
1707 * XXX to be replaced by call to
1708 * TextFileDocumentProvider.computeSchedulingRule after 3.0
1711 * @param toCreateOrModify
1712 * the resource to create or modify
1713 * @return the minimal scheduling rule needed to modify or create a resource
1715 protected ISchedulingRule computeSchedulingRule(IResource toCreateOrModify) {
1716 IResourceRuleFactory factory = ResourcesPlugin.getWorkspace()
1718 if (toCreateOrModify.exists()) {
1719 return factory.modifyRule(toCreateOrModify);
1721 IResource parent = toCreateOrModify;
1723 toCreateOrModify = parent;
1724 parent = toCreateOrModify.getParent();
1725 } while (parent != null && !parent.exists());
1727 return factory.createRule(toCreateOrModify);