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;
40 //import org.eclipse.jface.text.Assert;
41 import org.eclipse.core.runtime.Assert;
42 import org.eclipse.jface.text.BadLocationException;
43 import org.eclipse.jface.text.DefaultLineTracker;
44 import org.eclipse.jface.text.Document;
45 import org.eclipse.jface.text.IDocument;
46 import org.eclipse.jface.text.ILineTracker;
47 import org.eclipse.jface.text.ISynchronizable;
48 import org.eclipse.jface.text.Position;
49 import org.eclipse.jface.text.source.Annotation;
50 import org.eclipse.jface.text.source.AnnotationModelEvent;
51 import org.eclipse.jface.text.source.IAnnotationAccessExtension;
52 import org.eclipse.jface.text.source.IAnnotationModel;
53 import org.eclipse.jface.text.source.IAnnotationModelListener;
54 import org.eclipse.jface.text.source.IAnnotationModelListenerExtension;
55 import org.eclipse.jface.text.source.IAnnotationPresentation;
56 import org.eclipse.jface.text.source.ImageUtilities;
57 import org.eclipse.jface.util.IPropertyChangeListener;
59 //import org.eclipse.jface.util.ListenerList;
60 import org.eclipse.core.runtime.ListenerList;
61 import org.eclipse.jface.util.PropertyChangeEvent;
62 import org.eclipse.swt.SWT;
63 import org.eclipse.swt.graphics.GC;
64 import org.eclipse.swt.graphics.Image;
65 import org.eclipse.swt.graphics.Rectangle;
66 import org.eclipse.swt.widgets.Canvas;
67 import org.eclipse.swt.widgets.Display;
68 import org.eclipse.ui.IFileEditorInput;
69 import org.eclipse.ui.editors.text.EditorsUI;
70 import org.eclipse.ui.editors.text.ForwardingDocumentProvider;
71 import org.eclipse.ui.editors.text.TextFileDocumentProvider;
72 import org.eclipse.ui.texteditor.AbstractMarkerAnnotationModel;
73 import org.eclipse.ui.texteditor.AnnotationPreference;
74 import org.eclipse.ui.texteditor.AnnotationPreferenceLookup;
75 import org.eclipse.ui.texteditor.IDocumentProvider;
76 import org.eclipse.ui.texteditor.MarkerAnnotation;
77 import org.eclipse.ui.texteditor.MarkerUtilities;
78 import org.eclipse.ui.texteditor.ResourceMarkerAnnotationModel;
81 * The PHPDocumentProvider provides the IDocuments used by java editors.
84 public class PHPDocumentProvider extends TextFileDocumentProvider implements
85 ICompilationUnitDocumentProvider {
87 * Here for visibility issues only.
91 * Bundle of all required informations to allow working copy management.
94 * Bundle of all required informations to allow working copy management.
96 static protected class CompilationUnitInfo extends FileInfo {
97 public ICompilationUnit fCopy;
101 * Annotation model dealing with java marker annotations and temporary
102 * problems. Also acts as problem requestor for its compilation unit.
103 * Initialiy inactive. Must explicitly be activated.
105 protected static class CompilationUnitAnnotationModel extends
106 ResourceMarkerAnnotationModel implements IProblemRequestor,
107 IProblemRequestorExtension {
109 private static class ProblemRequestorState {
110 boolean fInsideReportingSequence = false;
112 List fReportedProblems;
115 private ThreadLocal fProblemRequestorState = new ThreadLocal();
117 private int fStateCount = 0;
119 private ICompilationUnit fCompilationUnit;
121 private List fGeneratedAnnotations;
123 private IProgressMonitor fProgressMonitor;
125 private boolean fIsActive = false;
127 private ReverseMap fReverseMap = new ReverseMap();
129 private List fPreviouslyOverlaid = null;
131 private List fCurrentlyOverlaid = new ArrayList();
133 public CompilationUnitAnnotationModel(IResource resource) {
137 public void setCompilationUnit(ICompilationUnit unit) {
138 fCompilationUnit = unit;
141 protected MarkerAnnotation createMarkerAnnotation(IMarker marker) {
142 String markerType = MarkerUtilities.getMarkerType(marker);
143 if (markerType != null
145 .startsWith(JavaMarkerAnnotation.JAVA_MARKER_TYPE_PREFIX))
146 return new JavaMarkerAnnotation(marker);
147 return super.createMarkerAnnotation(marker);
151 * @see org.eclipse.jface.text.source.AnnotationModel#createAnnotationModelEvent()
153 protected AnnotationModelEvent createAnnotationModelEvent() {
154 return new CompilationUnitAnnotationModelEvent(this, getResource());
157 protected Position createPositionFromProblem(IProblem problem) {
158 int start = problem.getSourceStart();
162 int length = problem.getSourceEnd() - problem.getSourceStart() + 1;
166 return new Position(start, length);
170 * @see IProblemRequestor#beginReporting()
172 public void beginReporting() {
173 ProblemRequestorState state = (ProblemRequestorState) fProblemRequestorState
176 internalBeginReporting(false);
180 * @see net.sourceforge.phpdt.internal.ui.text.java.IProblemRequestorExtension#beginReportingSequence()
182 public void beginReportingSequence() {
183 ProblemRequestorState state = (ProblemRequestorState) fProblemRequestorState
186 internalBeginReporting(true);
190 * Sets up the infrastructure necessary for problem reporting.
192 * @param insideReportingSequence
193 * <code>true</code> if this method call is issued from
194 * inside a reporting sequence
196 private void internalBeginReporting(boolean insideReportingSequence) {
197 if (fCompilationUnit != null) {
199 // fCompilationUnit.getJavaProject().isOnClasspath(fCompilationUnit))
201 ProblemRequestorState state = new ProblemRequestorState();
202 state.fInsideReportingSequence = insideReportingSequence;
203 state.fReportedProblems = new ArrayList();
204 synchronized (getLockObject()) {
205 fProblemRequestorState.set(state);
212 * @see IProblemRequestor#acceptProblem(IProblem)
214 public void acceptProblem(IProblem problem) {
216 ProblemRequestorState state = (ProblemRequestorState) fProblemRequestorState
219 state.fReportedProblems.add(problem);
224 * @see IProblemRequestor#endReporting()
226 public void endReporting() {
227 ProblemRequestorState state = (ProblemRequestorState) fProblemRequestorState
229 if (state != null && !state.fInsideReportingSequence)
230 internalEndReporting(state);
234 * @see net.sourceforge.phpdt.internal.ui.text.java.IProblemRequestorExtension#endReportingSequence()
236 public void endReportingSequence() {
237 ProblemRequestorState state = (ProblemRequestorState) fProblemRequestorState
239 if (state != null && state.fInsideReportingSequence)
240 internalEndReporting(state);
243 private void internalEndReporting(ProblemRequestorState state) {
245 synchronized (getLockObject()) {
247 stateCount = fStateCount;
248 fProblemRequestorState.set(null);
251 if (stateCount == 0 && isActive())
252 reportProblems(state.fReportedProblems);
256 * Signals the end of problem reporting.
258 private void reportProblems(List reportedProblems) {
259 if (fProgressMonitor != null && fProgressMonitor.isCanceled())
262 boolean temporaryProblemsChanged = false;
264 synchronized (getLockObject()) {
266 boolean isCanceled = false;
268 fPreviouslyOverlaid = fCurrentlyOverlaid;
269 fCurrentlyOverlaid = new ArrayList();
271 if (fGeneratedAnnotations.size() > 0) {
272 temporaryProblemsChanged = true;
273 removeAnnotations(fGeneratedAnnotations, false, true);
274 fGeneratedAnnotations.clear();
277 if (reportedProblems != null && reportedProblems.size() > 0) {
279 Iterator e = reportedProblems.iterator();
280 while (e.hasNext()) {
282 if (fProgressMonitor != null
283 && fProgressMonitor.isCanceled()) {
288 IProblem problem = (IProblem) e.next();
289 Position position = createPositionFromProblem(problem);
290 if (position != null) {
293 ProblemAnnotation annotation = new ProblemAnnotation(
294 problem, fCompilationUnit);
295 overlayMarkers(position, annotation);
296 addAnnotation(annotation, position, false);
297 fGeneratedAnnotations.add(annotation);
299 temporaryProblemsChanged = true;
300 } catch (BadLocationException x) {
301 // ignore invalid position
307 removeMarkerOverlays(isCanceled);
308 fPreviouslyOverlaid = null;
311 if (temporaryProblemsChanged)
315 private void removeMarkerOverlays(boolean isCanceled) {
317 fCurrentlyOverlaid.addAll(fPreviouslyOverlaid);
318 } else if (fPreviouslyOverlaid != null) {
319 Iterator e = fPreviouslyOverlaid.iterator();
320 while (e.hasNext()) {
321 JavaMarkerAnnotation annotation = (JavaMarkerAnnotation) e
323 annotation.setOverlay(null);
329 * Overlays value with problem annotation.
331 * @param problemAnnotation
333 private void setOverlay(Object value,
334 ProblemAnnotation problemAnnotation) {
335 if (value instanceof JavaMarkerAnnotation) {
336 JavaMarkerAnnotation annotation = (JavaMarkerAnnotation) value;
337 if (annotation.isProblem()) {
338 annotation.setOverlay(problemAnnotation);
339 fPreviouslyOverlaid.remove(annotation);
340 fCurrentlyOverlaid.add(annotation);
346 private void overlayMarkers(Position position,
347 ProblemAnnotation problemAnnotation) {
348 Object value = getAnnotations(position);
349 if (value instanceof List) {
350 List list = (List) value;
351 for (Iterator e = list.iterator(); e.hasNext();)
352 setOverlay(e.next(), problemAnnotation);
354 setOverlay(value, problemAnnotation);
359 * Tells this annotation model to collect temporary problems from now
362 private void startCollectingProblems() {
363 fGeneratedAnnotations = new ArrayList();
367 * Tells this annotation model to no longer collect temporary problems.
369 private void stopCollectingProblems() {
370 if (fGeneratedAnnotations != null)
371 removeAnnotations(fGeneratedAnnotations, true, true);
372 fGeneratedAnnotations = null;
376 * @see IProblemRequestor#isActive()
378 public boolean isActive() {
383 * @see IProblemRequestorExtension#setProgressMonitor(IProgressMonitor)
385 public void setProgressMonitor(IProgressMonitor monitor) {
386 fProgressMonitor = monitor;
390 * @see IProblemRequestorExtension#setIsActive(boolean)
392 public void setIsActive(boolean isActive) {
393 if (fIsActive != isActive) {
394 fIsActive = isActive;
396 startCollectingProblems();
398 stopCollectingProblems();
402 private Object getAnnotations(Position position) {
403 return fReverseMap.get(position);
407 * @see AnnotationModel#addAnnotation(Annotation, Position, boolean)
409 protected void addAnnotation(Annotation annotation, Position position,
410 boolean fireModelChanged) throws BadLocationException {
411 super.addAnnotation(annotation, position, fireModelChanged);
413 Object cached = fReverseMap.get(position);
415 fReverseMap.put(position, annotation);
416 else if (cached instanceof List) {
417 List list = (List) cached;
418 list.add(annotation);
419 } else if (cached instanceof Annotation) {
420 List list = new ArrayList(2);
422 list.add(annotation);
423 fReverseMap.put(position, list);
428 * @see AnnotationModel#removeAllAnnotations(boolean)
430 protected void removeAllAnnotations(boolean fireModelChanged) {
431 super.removeAllAnnotations(fireModelChanged);
436 * @see AnnotationModel#removeAnnotation(Annotation, boolean)
438 protected void removeAnnotation(Annotation annotation,
439 boolean fireModelChanged) {
440 Position position = getPosition(annotation);
441 Object cached = fReverseMap.get(position);
442 if (cached instanceof List) {
443 List list = (List) cached;
444 list.remove(annotation);
445 if (list.size() == 1) {
446 fReverseMap.put(position, list.get(0));
449 } else if (cached instanceof Annotation) {
450 fReverseMap.remove(position);
452 super.removeAnnotation(annotation, fireModelChanged);
456 protected static class GlobalAnnotationModelListener implements
457 IAnnotationModelListener, IAnnotationModelListenerExtension {
459 private ListenerList fListenerList;
461 public GlobalAnnotationModelListener() {
462 fListenerList = new ListenerList();
465 public void addListener(IAnnotationModelListener listener) {
466 fListenerList.add(listener);
470 * @see IAnnotationModelListenerExtension#modelChanged(AnnotationModelEvent)
472 public void modelChanged(AnnotationModelEvent event) {
473 Object[] listeners = fListenerList.getListeners();
474 for (int i = 0; i < listeners.length; i++) {
475 Object curr = listeners[i];
476 if (curr instanceof IAnnotationModelListenerExtension) {
477 ((IAnnotationModelListenerExtension) curr)
478 .modelChanged(event);
484 * @see IAnnotationModelListener#modelChanged(IAnnotationModel)
486 public void modelChanged(IAnnotationModel model) {
487 Object[] listeners = fListenerList.getListeners();
488 for (int i = 0; i < listeners.length; i++) {
489 ((IAnnotationModelListener) listeners[i]).modelChanged(model);
493 public void removeListener(IAnnotationModelListener listener) {
494 fListenerList.remove(listener);
499 * Annotation representating an <code>IProblem</code>.
501 static public class ProblemAnnotation extends Annotation implements
502 IJavaAnnotation, IAnnotationPresentation {
504 private static final String SPELLING_ANNOTATION_TYPE = "org.eclipse.ui.workbench.texteditor.spelling";
506 // XXX: To be fully correct these constants should be non-static
508 * The layer in which task problem annotations are located.
510 private static final int TASK_LAYER;
513 * The layer in which info problem annotations are located.
515 private static final int INFO_LAYER;
518 * The layer in which warning problem annotations representing are
521 private static final int WARNING_LAYER;
524 * The layer in which error problem annotations representing are
527 private static final int ERROR_LAYER;
530 AnnotationPreferenceLookup lookup = EditorsUI
531 .getAnnotationPreferenceLookup();
532 TASK_LAYER = computeLayer(
533 "org.eclipse.ui.workbench.texteditor.task", lookup); //$NON-NLS-1$
534 INFO_LAYER = computeLayer("net.sourceforge.phpdt.ui.info", lookup); //$NON-NLS-1$
535 WARNING_LAYER = computeLayer(
536 "net.sourceforge.phpdt.ui.warning", lookup); //$NON-NLS-1$
537 ERROR_LAYER = computeLayer("net.sourceforge.phpdt.ui.error", lookup); //$NON-NLS-1$
540 private static int computeLayer(String annotationType,
541 AnnotationPreferenceLookup lookup) {
542 Annotation annotation = new Annotation(annotationType, false, null);
543 AnnotationPreference preference = lookup
544 .getAnnotationPreference(annotation);
545 if (preference != null)
546 return preference.getPresentationLayer() + 1;
548 return IAnnotationAccessExtension.DEFAULT_LAYER + 1;
551 // private static Image fgQuickFixImage;
552 // private static Image fgQuickFixErrorImage;
553 // private static boolean fgQuickFixImagesInitialized= false;
555 private ICompilationUnit fCompilationUnit;
557 private List fOverlaids;
559 private IProblem fProblem;
561 private Image fImage;
563 //private boolean fQuickFixImagesInitialized = false;
565 private int fLayer = IAnnotationAccessExtension.DEFAULT_LAYER;
567 public ProblemAnnotation(IProblem problem, ICompilationUnit cu) {
570 fCompilationUnit = cu;
572 if (SpellProblem.Spelling == fProblem.getID()) {
573 setType(SPELLING_ANNOTATION_TYPE);
574 fLayer = WARNING_LAYER;
575 } else if (IProblem.Task == fProblem.getID()) {
576 setType(JavaMarkerAnnotation.TASK_ANNOTATION_TYPE);
578 } else if (fProblem.isWarning()) {
579 setType(JavaMarkerAnnotation.WARNING_ANNOTATION_TYPE);
580 fLayer = WARNING_LAYER;
581 } else if (fProblem.isError()) {
582 setType(JavaMarkerAnnotation.ERROR_ANNOTATION_TYPE);
583 fLayer = ERROR_LAYER;
585 setType(JavaMarkerAnnotation.INFO_ANNOTATION_TYPE);
591 * @see org.eclipse.jface.text.source.IAnnotationPresentation#getLayer()
593 public int getLayer() {
597 private void initializeImages() {
598 // http://bugs.eclipse.org/bugs/show_bug.cgi?id=18936
599 // if (!fQuickFixImagesInitialized) {
600 // if (isProblem() && indicateQuixFixableProblems() &&
601 // JavaCorrectionProcessor.hasCorrections(this)) { // no light bulb
603 // if (!fgQuickFixImagesInitialized) {
605 // JavaPluginImages.get(JavaPluginImages.IMG_OBJS_FIXABLE_PROBLEM);
606 // fgQuickFixErrorImage=
607 // JavaPluginImages.get(JavaPluginImages.IMG_OBJS_FIXABLE_ERROR);
608 // fgQuickFixImagesInitialized= true;
610 // if (JavaMarkerAnnotation.ERROR_ANNOTATION_TYPE.equals(getType()))
611 // fImage= fgQuickFixErrorImage;
613 // fImage= fgQuickFixImage;
615 // fQuickFixImagesInitialized= true;
619 // private boolean indicateQuixFixableProblems() {
620 // return PreferenceConstants.getPreferenceStore().getBoolean(
621 // PreferenceConstants.EDITOR_CORRECTION_INDICATION);
625 * @see Annotation#paint
627 public void paint(GC gc, Canvas canvas, Rectangle r) {
630 ImageUtilities.drawImage(fImage, gc, canvas, r, SWT.CENTER,
635 * @see IJavaAnnotation#getImage(Display)
637 public Image getImage(Display display) {
643 * @see IJavaAnnotation#getMessage()
645 public String getText() {
646 return fProblem.getMessage();
650 * @see IJavaAnnotation#getArguments()
652 public String[] getArguments() {
653 return isProblem() ? fProblem.getArguments() : null;
657 * @see IJavaAnnotation#getId()
660 return fProblem.getID();
664 * @see IJavaAnnotation#isProblem()
666 public boolean isProblem() {
667 String type = getType();
668 return JavaMarkerAnnotation.WARNING_ANNOTATION_TYPE.equals(type)
669 || JavaMarkerAnnotation.ERROR_ANNOTATION_TYPE.equals(type)
670 || SPELLING_ANNOTATION_TYPE.equals(type);
674 * @see IJavaAnnotation#hasOverlay()
676 public boolean hasOverlay() {
681 * @see net.sourceforge.phpdt.internal.ui.javaeditor.IJavaAnnotation#getOverlay()
683 public IJavaAnnotation getOverlay() {
688 * @see IJavaAnnotation#addOverlaid(IJavaAnnotation)
690 public void addOverlaid(IJavaAnnotation annotation) {
691 if (fOverlaids == null)
692 fOverlaids = new ArrayList(1);
693 fOverlaids.add(annotation);
697 * @see IJavaAnnotation#removeOverlaid(IJavaAnnotation)
699 public void removeOverlaid(IJavaAnnotation annotation) {
700 if (fOverlaids != null) {
701 fOverlaids.remove(annotation);
702 if (fOverlaids.size() == 0)
708 * @see IJavaAnnotation#getOverlaidIterator()
710 public Iterator getOverlaidIterator() {
711 if (fOverlaids != null)
712 return fOverlaids.iterator();
717 * @see net.sourceforge.phpdt.internal.ui.javaeditor.IJavaAnnotation#getCompilationUnit()
719 public ICompilationUnit getCompilationUnit() {
720 return fCompilationUnit;
725 * Internal structure for mapping positions to some value. The reason for
726 * this specific structure is that positions can change over time. Thus a
727 * lookup is based on value and not on hash value.
729 protected static class ReverseMap {
737 private int fAnchor = 0;
739 private List fList = new ArrayList(2);
741 public ReverseMap() {
744 public void clear() {
748 public Object get(Position position) {
753 int length = fList.size();
754 for (int i = fAnchor; i < length; i++) {
755 entry = (Entry) fList.get(i);
756 if (entry.fPosition.equals(position)) {
763 for (int i = 0; i < fAnchor; i++) {
764 entry = (Entry) fList.get(i);
765 if (entry.fPosition.equals(position)) {
774 private int getIndex(Position position) {
776 int length = fList.size();
777 for (int i = 0; i < length; i++) {
778 entry = (Entry) fList.get(i);
779 if (entry.fPosition.equals(position))
785 public void put(Position position, Object value) {
786 int index = getIndex(position);
788 Entry entry = new Entry();
789 entry.fPosition = position;
790 entry.fValue = value;
793 Entry entry = (Entry) fList.get(index);
794 entry.fValue = value;
798 public void remove(Position position) {
799 int index = getIndex(position);
806 * Document that can also be used by a background reconciler.
808 protected static class PartiallySynchronizedDocument extends Document {
811 * @see IDocumentExtension#startSequentialRewrite(boolean)
813 synchronized public void startSequentialRewrite(boolean normalized) {
814 super.startSequentialRewrite(normalized);
818 * @see IDocumentExtension#stopSequentialRewrite()
820 synchronized public void stopSequentialRewrite() {
821 super.stopSequentialRewrite();
825 * @see IDocument#get()
827 synchronized public String get() {
832 * @see IDocument#get(int, int)
834 synchronized public String get(int offset, int length)
835 throws BadLocationException {
836 return super.get(offset, length);
840 * @see IDocument#getChar(int)
842 synchronized public char getChar(int offset)
843 throws BadLocationException {
844 return super.getChar(offset);
848 * @see IDocument#replace(int, int, String)
850 synchronized public void replace(int offset, int length, String text)
851 throws BadLocationException {
852 super.replace(offset, length, text);
856 * @see IDocument#set(String)
858 synchronized public void set(String text) {
864 // private static PHPPartitionScanner HTML_PARTITION_SCANNER = null;
866 // private static PHPPartitionScanner PHP_PARTITION_SCANNER = null;
867 // private static PHPPartitionScanner SMARTY_PARTITION_SCANNER = null;
869 // // private final static String[] TYPES= new String[] {
870 // PHPPartitionScanner.PHP, PHPPartitionScanner.JAVA_DOC,
871 // PHPPartitionScanner.JAVA_MULTILINE_COMMENT };
872 // private final static String[] TYPES =
874 // IPHPPartitionScannerConstants.PHP,
875 // IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT,
876 // IPHPPartitionScannerConstants.HTML,
877 // IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT,
878 // IPHPPartitionScannerConstants.JAVASCRIPT,
879 // IPHPPartitionScannerConstants.CSS,
880 // IPHPPartitionScannerConstants.SMARTY,
881 // IPHPPartitionScannerConstants.SMARTY_MULTILINE_COMMENT };
882 // private static PHPPartitionScanner XML_PARTITION_SCANNER = null;
884 /* Preference key for temporary problems */
885 private final static String HANDLE_TEMPORARY_PROBLEMS = PreferenceConstants.EDITOR_EVALUTE_TEMPORARY_PROBLEMS;
887 /** Indicates whether the save has been initialized by this provider */
888 private boolean fIsAboutToSave = false;
890 /** The save policy used by this provider */
891 private ISavePolicy fSavePolicy;
893 /** Internal property changed listener */
894 private IPropertyChangeListener fPropertyListener;
896 /** annotation model listener added to all created CU annotation models */
897 private GlobalAnnotationModelListener fGlobalAnnotationModelListener;
899 public PHPDocumentProvider() {
900 // IDocumentProvider provider= new TextFileDocumentProvider(new
901 // JavaStorageDocumentProvider());
902 IDocumentProvider provider = new TextFileDocumentProvider();
903 provider = new ForwardingDocumentProvider(
904 IPHPPartitions.PHP_PARTITIONING,
905 new JavaDocumentSetupParticipant(), provider);
906 setParentDocumentProvider(provider);
908 fGlobalAnnotationModelListener = new GlobalAnnotationModelListener();
909 fPropertyListener = new IPropertyChangeListener() {
910 public void propertyChange(PropertyChangeEvent event) {
911 if (HANDLE_TEMPORARY_PROBLEMS.equals(event.getProperty()))
912 enableHandlingTemporaryProblems();
915 PHPeclipsePlugin.getDefault().getPreferenceStore()
916 .addPropertyChangeListener(fPropertyListener);
921 * Sets the document provider's save policy.
923 public void setSavePolicy(ISavePolicy savePolicy) {
924 fSavePolicy = savePolicy;
928 * Creates a compilation unit from the given file.
931 * the file from which to create the compilation unit
933 protected ICompilationUnit createCompilationUnit(IFile file) {
934 Object element = JavaCore.create(file);
935 if (element instanceof ICompilationUnit)
936 return (ICompilationUnit) element;
941 * @see org.eclipse.ui.editors.text.TextFileDocumentProvider#createEmptyFileInfo()
943 protected FileInfo createEmptyFileInfo() {
944 return new CompilationUnitInfo();
948 * @see org.eclipse.ui.editors.text.TextFileDocumentProvider#createAnnotationModel(org.eclipse.core.resources.IFile)
950 protected IAnnotationModel createAnnotationModel(IFile file) {
951 return new CompilationUnitAnnotationModel(file);
955 * @see AbstractDocumentProvider#createElementInfo(Object)
957 // protected ElementInfo createElementInfo(Object element) throws
960 // if (!(element instanceof IFileEditorInput))
961 // return super.createElementInfo(element);
963 // IFileEditorInput input = (IFileEditorInput) element;
964 // ICompilationUnit original = createCompilationUnit(input.getFile());
965 // if (original != null) {
970 // refreshFile(input.getFile());
971 // } catch (CoreException x) {
972 // handleCoreException(x,
973 // PHPEditorMessages.getString("PHPDocumentProvider.error.createElementInfo"));
977 // IAnnotationModel m = createCompilationUnitAnnotationModel(input);
978 // IProblemRequestor r = m instanceof IProblemRequestor ?
979 // (IProblemRequestor) m : null;
980 // ICompilationUnit c = (ICompilationUnit)
981 // original.getSharedWorkingCopy(getProgressMonitor(), fBufferFactory, r);
983 // DocumentAdapter a = null;
985 // a = (DocumentAdapter) c.getBuffer();
986 // } catch (ClassCastException x) {
987 // IStatus status = new Status(IStatus.ERROR, PHPeclipsePlugin.PLUGIN_ID,
988 // PHPStatusConstants.TEMPLATE_IO_EXCEPTION, "Shared working copy has wrong
989 // buffer", x); //$NON-NLS-1$
990 // throw new CoreException(status);
993 // _FileSynchronizer f = new _FileSynchronizer(input);
996 // CompilationUnitInfo info = new CompilationUnitInfo(a.getDocument(), m, f,
998 // info.setModificationStamp(computeModificationStamp(input.getFile()));
999 // info.fStatus = a.getStatus();
1000 // info.fEncoding = getPersistedEncoding(input);
1002 // if (r instanceof IProblemRequestorExtension) {
1003 // IProblemRequestorExtension extension = (IProblemRequestorExtension) r;
1004 // extension.setIsActive(isHandlingTemporaryProblems());
1006 // m.addAnnotationModelListener(fGlobalAnnotationModelListener);
1010 // } catch (JavaModelException x) {
1011 // throw new CoreException(x.getStatus());
1014 // return super.createElementInfo(element);
1018 * @see AbstractDocumentProvider#disposeElementInfo(Object, ElementInfo)
1020 // protected void disposeElementInfo(Object element, ElementInfo info) {
1022 // if (info instanceof CompilationUnitInfo) {
1023 // CompilationUnitInfo cuInfo = (CompilationUnitInfo) info;
1024 // cuInfo.fCopy.destroy();
1025 // cuInfo.fModel.removeAnnotationModelListener(fGlobalAnnotationModelListener);
1028 // super.disposeElementInfo(element, info);
1031 * @see AbstractDocumentProvider#doSaveDocument(IProgressMonitor, Object,
1032 * IDocument, boolean)
1034 // protected void doSaveDocument(IProgressMonitor monitor, Object element,
1035 // IDocument document, boolean overwrite)
1036 // throws CoreException {
1038 // ElementInfo elementInfo = getElementInfo(element);
1039 // if (elementInfo instanceof CompilationUnitInfo) {
1040 // CompilationUnitInfo info = (CompilationUnitInfo) elementInfo;
1042 // // update structure, assumes lock on info.fCopy
1043 // info.fCopy.reconcile();
1045 // ICompilationUnit original = (ICompilationUnit)
1046 // info.fCopy.getOriginalElement();
1047 // IResource resource = original.getResource();
1049 // if (resource == null) {
1050 // // underlying resource has been deleted, just recreate file, ignore the
1052 // super.doSaveDocument(monitor, element, document, overwrite);
1056 // if (resource != null && !overwrite)
1057 // checkSynchronizationState(info.fModificationStamp, resource);
1059 // if (fSavePolicy != null)
1060 // fSavePolicy.preSave(info.fCopy);
1062 // // inform about the upcoming content change
1063 // fireElementStateChanging(element);
1065 // fIsAboutToSave = true;
1066 // // commit working copy
1067 // info.fCopy.commit(overwrite, monitor);
1068 // } catch (CoreException x) {
1069 // // inform about the failure
1070 // fireElementStateChangeFailed(element);
1072 // } catch (RuntimeException x) {
1073 // // inform about the failure
1074 // fireElementStateChangeFailed(element);
1077 // fIsAboutToSave = false;
1080 // // If here, the dirty state of the editor will change to "not dirty".
1081 // // Thus, the state changing flag will be reset.
1083 // AbstractMarkerAnnotationModel model = (AbstractMarkerAnnotationModel)
1085 // model.updateMarkers(info.fDocument);
1087 // if (resource != null)
1088 // info.setModificationStamp(computeModificationStamp(resource));
1090 // if (fSavePolicy != null) {
1091 // ICompilationUnit unit = fSavePolicy.postSave(original);
1092 // if (unit != null) {
1093 // IResource r = unit.getResource();
1094 // IMarker[] markers = r.findMarkers(IMarker.MARKER, true,
1095 // IResource.DEPTH_ZERO);
1096 // if (markers != null && markers.length > 0) {
1097 // for (int i = 0; i < markers.length; i++)
1098 // model.updateMarker(markers[i], info.fDocument, null);
1104 // super.doSaveDocument(monitor, element, document, overwrite);
1108 * @see org.eclipse.ui.editors.text.TextFileDocumentProvider#createFileInfo(java.lang.Object)
1110 protected FileInfo createFileInfo(Object element) throws CoreException {
1111 if (!(element instanceof IFileEditorInput))
1114 IFileEditorInput input = (IFileEditorInput) element;
1115 ICompilationUnit original = createCompilationUnit(input.getFile());
1116 if (original == null)
1119 FileInfo info = super.createFileInfo(element);
1120 if (!(info instanceof CompilationUnitInfo))
1123 CompilationUnitInfo cuInfo = (CompilationUnitInfo) info;
1124 setUpSynchronization(cuInfo);
1126 IProblemRequestor requestor = cuInfo.fModel instanceof IProblemRequestor ? (IProblemRequestor) cuInfo.fModel
1129 original.becomeWorkingCopy(requestor, getProgressMonitor());
1130 cuInfo.fCopy = original;
1132 if (cuInfo.fModel instanceof CompilationUnitAnnotationModel) {
1133 CompilationUnitAnnotationModel model = (CompilationUnitAnnotationModel) cuInfo.fModel;
1134 model.setCompilationUnit(cuInfo.fCopy);
1137 if (cuInfo.fModel != null)
1139 .addAnnotationModelListener(fGlobalAnnotationModelListener);
1141 if (requestor instanceof IProblemRequestorExtension) {
1142 IProblemRequestorExtension extension = (IProblemRequestorExtension) requestor;
1143 extension.setIsActive(isHandlingTemporaryProblems());
1149 private void setUpSynchronization(CompilationUnitInfo cuInfo) {
1150 IDocument document = cuInfo.fTextFileBuffer.getDocument();
1151 IAnnotationModel model = cuInfo.fModel;
1153 if (document instanceof ISynchronizable
1154 && model instanceof ISynchronizable) {
1155 Object lock = ((ISynchronizable) document).getLockObject();
1156 ((ISynchronizable) model).setLockObject(lock);
1161 * @see org.eclipse.ui.editors.text.TextFileDocumentProvider#disposeFileInfo(java.lang.Object,
1162 * org.eclipse.ui.editors.text.TextFileDocumentProvider.FileInfo)
1164 protected void disposeFileInfo(Object element, FileInfo info) {
1165 if (info instanceof CompilationUnitInfo) {
1166 CompilationUnitInfo cuInfo = (CompilationUnitInfo) info;
1169 cuInfo.fCopy.discardWorkingCopy();
1170 } catch (JavaModelException x) {
1171 handleCoreException(x, x.getMessage());
1174 if (cuInfo.fModel != null)
1176 .removeAnnotationModelListener(fGlobalAnnotationModelListener);
1178 super.disposeFileInfo(element, info);
1181 protected void commitWorkingCopy(IProgressMonitor monitor, Object element,
1182 CompilationUnitInfo info, boolean overwrite) throws CoreException {
1183 synchronized (info.fCopy) {
1184 info.fCopy.reconcile();
1187 IDocument document = info.fTextFileBuffer.getDocument();
1188 IResource resource = info.fCopy.getResource();
1190 Assert.isTrue(resource instanceof IFile);
1191 if (!resource.exists()) {
1192 // underlying resource has been deleted, just recreate file, ignore
1194 createFileFromDocument(monitor, (IFile) resource, document);
1198 if (fSavePolicy != null)
1199 fSavePolicy.preSave(info.fCopy);
1203 fIsAboutToSave = true;
1204 info.fCopy.commitWorkingCopy(overwrite, monitor);
1206 } catch (CoreException x) {
1207 // inform about the failure
1208 fireElementStateChangeFailed(element);
1210 } catch (RuntimeException x) {
1211 // inform about the failure
1212 fireElementStateChangeFailed(element);
1215 fIsAboutToSave = false;
1218 // If here, the dirty state of the editor will change to "not dirty".
1219 // Thus, the state changing flag will be reset.
1220 if (info.fModel instanceof AbstractMarkerAnnotationModel) {
1221 AbstractMarkerAnnotationModel model = (AbstractMarkerAnnotationModel) info.fModel;
1222 model.updateMarkers(document);
1225 if (fSavePolicy != null) {
1226 ICompilationUnit unit = fSavePolicy.postSave(info.fCopy);
1228 && info.fModel instanceof AbstractMarkerAnnotationModel) {
1229 IResource r = unit.getResource();
1230 IMarker[] markers = r.findMarkers(IMarker.MARKER, true,
1231 IResource.DEPTH_ZERO);
1232 if (markers != null && markers.length > 0) {
1233 AbstractMarkerAnnotationModel model = (AbstractMarkerAnnotationModel) info.fModel;
1234 for (int i = 0; i < markers.length; i++)
1235 model.updateMarker(document, markers[i], null);
1243 * @see org.eclipse.ui.editors.text.TextFileDocumentProvider#createSaveOperation(java.lang.Object,
1244 * org.eclipse.jface.text.IDocument, boolean)
1246 protected DocumentProviderOperation createSaveOperation(
1247 final Object element, final IDocument document,
1248 final boolean overwrite) throws CoreException {
1249 // final FileInfo info= getFileInfo(element);
1250 // if (info instanceof CompilationUnitInfo) {
1251 // return new DocumentProviderOperation() {
1254 // org.eclipse.ui.editors.text.TextFileDocumentProvider.DocumentProviderOperation#execute(org.eclipse.core.runtime.IProgressMonitor)
1256 // protected void execute(IProgressMonitor monitor) throws CoreException
1258 // commitWorkingCopy(monitor, element, (CompilationUnitInfo) info,
1263 // org.eclipse.ui.editors.text.TextFileDocumentProvider.DocumentProviderOperation#getSchedulingRule()
1265 // public ISchedulingRule getSchedulingRule() {
1266 // if (info.fElement instanceof IFileEditorInput) {
1267 // IFile file= ((IFileEditorInput) info.fElement).getFile();
1268 // IResourceRuleFactory ruleFactory=
1269 // ResourcesPlugin.getWorkspace().getRuleFactory();
1270 // if (file == null || !file.exists())
1271 // return ruleFactory.createRule(file);
1273 // return ruleFactory.modifyRule(file);
1280 final FileInfo info = getFileInfo(element);
1281 if (info instanceof CompilationUnitInfo) {
1282 return new DocumentProviderOperation() {
1284 * @see org.eclipse.ui.editors.text.TextFileDocumentProvider.DocumentProviderOperation#execute(org.eclipse.core.runtime.IProgressMonitor)
1286 protected void execute(IProgressMonitor monitor)
1287 throws CoreException {
1288 commitWorkingCopy(monitor, element,
1289 (CompilationUnitInfo) info, overwrite);
1293 * @see org.eclipse.ui.editors.text.TextFileDocumentProvider.DocumentProviderOperation#getSchedulingRule()
1295 public ISchedulingRule getSchedulingRule() {
1296 if (info.fElement instanceof IFileEditorInput) {
1297 IFile file = ((IFileEditorInput) info.fElement)
1299 return computeSchedulingRule(file);
1309 * (non-Javadoc) Method declared on AbstractDocumentProvider
1311 // protected IDocument createDocument(Object element) throws CoreException {
1312 // if (element instanceof IEditorInput) {
1313 // Document document = new PartiallySynchronizedDocument();
1314 // if (setDocumentContent(document, (IEditorInput) element,
1315 // getEncoding(element))) {
1316 // initializeDocument(document, (IEditorInput) element);
1319 // // IDocument document = super.createDocument(element);
1320 // // if (document != null) {
1321 // // IDocumentPartitioner partitioner = null;
1322 // // if (element instanceof FileEditorInput) {
1323 // // IFile file = (IFile) ((FileEditorInput)
1324 // element).getAdapter(IFile.class);
1325 // // String filename = file.getLocation().toString();
1326 // // String extension = filename.substring(filename.lastIndexOf("."),
1327 // filename.length());
1328 // // // System.out.println(extension);
1329 // // if (extension.equalsIgnoreCase(".html") ||
1330 // extension.equalsIgnoreCase(".htm")) {
1332 // // partitioner = createHTMLPartitioner();
1333 // // } else if (extension.equalsIgnoreCase(".xml")) {
1335 // // partitioner = createXMLPartitioner();
1336 // // } else if (extension.equalsIgnoreCase(".js")) {
1338 // // partitioner = createJavaScriptPartitioner();
1339 // // } else if (extension.equalsIgnoreCase(".css")) {
1340 // // // cascading style sheets
1341 // // partitioner = createCSSPartitioner();
1342 // // } else if (extension.equalsIgnoreCase(".tpl")) {
1344 // // partitioner = createSmartyPartitioner();
1345 // // } else if (extension.equalsIgnoreCase(".inc")) {
1346 // // // php include files ?
1347 // // partitioner = createIncludePartitioner();
1351 // // if (partitioner == null) {
1352 // // partitioner = createPHPPartitioner();
1354 // // document.setDocumentPartitioner(partitioner);
1355 // // partitioner.connect(document);
1362 // * Return a partitioner for .html files.
1364 // private IDocumentPartitioner createHTMLPartitioner() {
1365 // return new DefaultPartitioner(getHTMLPartitionScanner(), TYPES);
1368 // private IDocumentPartitioner createIncludePartitioner() {
1369 // return new DefaultPartitioner(getPHPPartitionScanner(), TYPES);
1372 // private IDocumentPartitioner createJavaScriptPartitioner() {
1373 // return new DefaultPartitioner(getHTMLPartitionScanner(), TYPES);
1376 * Creates a line tracker working with the same line delimiters as the
1377 * document of the given element. Assumes the element to be managed by this
1378 * document provider.
1381 * the element serving as blue print
1382 * @return a line tracker based on the same line delimiters as the element's
1385 public ILineTracker createLineTracker(Object element) {
1386 return new DefaultLineTracker();
1390 // * Return a partitioner for .php files.
1392 // private IDocumentPartitioner createPHPPartitioner() {
1393 // return new DefaultPartitioner(getPHPPartitionScanner(), TYPES);
1396 // private IDocumentPartitioner createSmartyPartitioner() {
1397 // return new DefaultPartitioner(getSmartyPartitionScanner(), TYPES);
1400 // private IDocumentPartitioner createXMLPartitioner() {
1401 // return new DefaultPartitioner(getXMLPartitionScanner(), TYPES);
1405 // * Return a scanner for creating html partitions.
1407 // private PHPPartitionScanner getHTMLPartitionScanner() {
1408 // if (HTML_PARTITION_SCANNER == null)
1409 // HTML_PARTITION_SCANNER = new
1410 // PHPPartitionScanner(IPHPPartitionScannerConstants.HTML_FILE);
1411 // return HTML_PARTITION_SCANNER;
1414 // * Return a scanner for creating php partitions.
1416 // private PHPPartitionScanner getPHPPartitionScanner() {
1417 // if (PHP_PARTITION_SCANNER == null)
1418 // PHP_PARTITION_SCANNER = new
1419 // PHPPartitionScanner(IPHPPartitionScannerConstants.PHP_FILE);
1420 // return PHP_PARTITION_SCANNER;
1424 // * Return a scanner for creating smarty partitions.
1426 // private PHPPartitionScanner getSmartyPartitionScanner() {
1427 // if (SMARTY_PARTITION_SCANNER == null)
1428 // SMARTY_PARTITION_SCANNER = new
1429 // PHPPartitionScanner(IPHPPartitionScannerConstants.SMARTY_FILE);
1430 // return SMARTY_PARTITION_SCANNER;
1434 // * Return a scanner for creating xml partitions.
1436 // private PHPPartitionScanner getXMLPartitionScanner() {
1437 // if (XML_PARTITION_SCANNER == null)
1438 // XML_PARTITION_SCANNER = new
1439 // PHPPartitionScanner(IPHPPartitionScannerConstants.XML_FILE);
1440 // return XML_PARTITION_SCANNER;
1443 // protected void initializeDocument(IDocument document, IEditorInput
1445 // if (document != null) {
1446 // JavaTextTools tools = PHPeclipsePlugin.getDefault().getJavaTextTools();
1447 // IDocumentPartitioner partitioner = null;
1448 // if (editorInput != null && editorInput instanceof FileEditorInput) {
1449 // IFile file = (IFile) ((FileEditorInput)
1450 // editorInput).getAdapter(IFile.class);
1451 // String filename = file.getLocation().toString();
1452 // String extension = filename.substring(filename.lastIndexOf("."),
1453 // filename.length());
1454 // partitioner = tools.createDocumentPartitioner(extension);
1456 // partitioner = tools.createDocumentPartitioner(".php");
1458 // document.setDocumentPartitioner(partitioner);
1459 // partitioner.connect(document);
1464 * @see org.eclipse.ui.texteditor.AbstractDocumentProvider#doResetDocument(java.lang.Object,
1465 * org.eclipse.core.runtime.IProgressMonitor)
1467 // protected void doResetDocument(Object element, IProgressMonitor monitor)
1468 // throws CoreException {
1469 // if (element == null)
1472 // ElementInfo elementInfo= getElementInfo(element);
1473 // if (elementInfo instanceof CompilationUnitInfo) {
1474 // CompilationUnitInfo info= (CompilationUnitInfo) elementInfo;
1476 // IDocument document;
1477 // IStatus status= null;
1481 // ICompilationUnit original= (ICompilationUnit)
1482 // info.fCopy.getOriginalElement();
1483 // IResource resource= original.getResource();
1484 // if (resource instanceof IFile) {
1486 // IFile file= (IFile) resource;
1489 // refreshFile(file, monitor);
1490 // } catch (CoreException x) {
1491 // handleCoreException(x,
1492 // PHPEditorMessages.getString("CompilationUnitDocumentProvider.error.resetDocument"));
1496 // IFileEditorInput input= new FileEditorInput(file);
1497 // document= super.createDocument(input);
1500 // document= createEmptyDocument();
1503 // } catch (CoreException x) {
1504 // document= createEmptyDocument();
1505 // status= x.getStatus();
1508 // fireElementContentAboutToBeReplaced(element);
1510 // removeUnchangedElementListeners(element, info);
1511 // info.fDocument.set(document.get());
1512 // info.fCanBeSaved= false;
1513 // info.fStatus= status;
1514 // addUnchangedElementListeners(element, info);
1516 // fireElementContentReplaced(element);
1517 // fireElementDirtyStateChanged(element, false);
1520 // super.doResetDocument(element, monitor);
1524 * @see AbstractDocumentProvider#resetDocument(Object)
1526 // public void resetDocument(Object element) throws CoreException {
1527 // if (element == null)
1530 // ElementInfo elementInfo = getElementInfo(element);
1531 // if (elementInfo instanceof CompilationUnitInfo) {
1532 // CompilationUnitInfo info = (CompilationUnitInfo) elementInfo;
1534 // IDocument document;
1535 // IStatus status = null;
1539 // ICompilationUnit original = (ICompilationUnit)
1540 // info.fCopy.getOriginalElement();
1541 // IResource resource = original.getResource();
1542 // if (resource instanceof IFile) {
1544 // IFile file = (IFile) resource;
1547 // refreshFile(file);
1548 // } catch (CoreException x) {
1549 // handleCoreException(x,
1550 // PHPEditorMessages.getString("PHPDocumentProvider.error.resetDocument"));
1554 // IFileEditorInput input = new FileEditorInput(file);
1555 // document = super.createDocument(input);
1558 // document = new Document();
1561 // } catch (CoreException x) {
1562 // document = new Document();
1563 // status = x.getStatus();
1566 // fireElementContentAboutToBeReplaced(element);
1568 // removeUnchangedElementListeners(element, info);
1569 // info.fDocument.set(document.get());
1570 // info.fCanBeSaved = false;
1571 // info.fStatus = status;
1572 // addUnchangedElementListeners(element, info);
1574 // fireElementContentReplaced(element);
1575 // fireElementDirtyStateChanged(element, false);
1578 // super.resetDocument(element);
1582 * Saves the content of the given document to the given element. This is
1583 * only performed when this provider initiated the save.
1586 * the progress monitor
1588 * the element to which to save
1590 * the document to save
1592 * <code>true</code> if the save should be enforced
1594 public void saveDocumentContent(IProgressMonitor monitor, Object element,
1595 IDocument document, boolean overwrite) throws CoreException {
1596 if (!fIsAboutToSave)
1598 super.saveDocument(monitor, element, document, overwrite);
1599 // if (!fIsAboutToSave)
1602 // if (element instanceof IFileEditorInput) {
1603 // IFileEditorInput input = (IFileEditorInput) element;
1605 // String encoding = getEncoding(element);
1606 // if (encoding == null)
1607 // encoding = ResourcesPlugin.getEncoding();
1608 // InputStream stream = new
1609 // ByteArrayInputStream(document.get().getBytes(encoding));
1610 // IFile file = input.getFile();
1611 // file.setContents(stream, overwrite, true, monitor);
1612 // } catch (IOException x) {
1613 // IStatus s = new Status(IStatus.ERROR, PHPeclipsePlugin.PLUGIN_ID,
1614 // IStatus.OK, x.getMessage(), x);
1615 // throw new CoreException(s);
1621 * Returns the underlying resource for the given element.
1625 * @return the underlying resource of the given element
1627 // public IResource getUnderlyingResource(Object element) {
1628 // if (element instanceof IFileEditorInput) {
1629 // IFileEditorInput input = (IFileEditorInput) element;
1630 // return input.getFile();
1635 * @see net.sourceforge.phpdt.internal.ui.javaeditor.ICompilationUnitDocumentProvider#getWorkingCopy(java.lang.Object)
1637 public ICompilationUnit getWorkingCopy(Object element) {
1638 FileInfo fileInfo = getFileInfo(element);
1639 if (fileInfo instanceof CompilationUnitInfo) {
1640 CompilationUnitInfo info = (CompilationUnitInfo) fileInfo;
1647 * @see net.sourceforge.phpdt.internal.ui.javaeditor.ICompilationUnitDocumentProvider#shutdown()
1649 public void shutdown() {
1650 PHPeclipsePlugin.getDefault().getPreferenceStore()
1651 .removePropertyChangeListener(fPropertyListener);
1652 Iterator e = getConnectedElementsIterator();
1654 disconnect(e.next());
1658 * Returns the preference whether handling temporary problems is enabled.
1660 protected boolean isHandlingTemporaryProblems() {
1661 IPreferenceStore store = PHPeclipsePlugin.getDefault()
1662 .getPreferenceStore();
1663 return store.getBoolean(HANDLE_TEMPORARY_PROBLEMS);
1667 * Switches the state of problem acceptance according to the value in the
1670 protected void enableHandlingTemporaryProblems() {
1671 boolean enable = isHandlingTemporaryProblems();
1672 for (Iterator iter = getFileInfosIterator(); iter.hasNext();) {
1673 FileInfo info = (FileInfo) iter.next();
1674 if (info.fModel instanceof IProblemRequestorExtension) {
1675 IProblemRequestorExtension extension = (IProblemRequestorExtension) info.fModel;
1676 extension.setIsActive(enable);
1682 * Adds a listener that reports changes from all compilation unit annotation
1685 public void addGlobalAnnotationModelListener(
1686 IAnnotationModelListener listener) {
1687 fGlobalAnnotationModelListener.addListener(listener);
1691 * Removes the listener.
1693 public void removeGlobalAnnotationModelListener(
1694 IAnnotationModelListener listener) {
1695 fGlobalAnnotationModelListener.removeListener(listener);
1699 * Computes the scheduling rule needed to create or modify a resource. If
1700 * the resource exists, its modify rule is returned. If it does not, the
1701 * resource hierarchy is iterated towards the workspace root to find the
1702 * first parent of <code>toCreateOrModify</code> that exists. Then the
1703 * 'create' rule for the last non-existing resource is returned.
1705 * XXX This is a workaround for
1706 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=67601
1707 * IResourceRuleFactory.createRule should iterate the hierarchy itself.
1710 * XXX to be replaced by call to
1711 * TextFileDocumentProvider.computeSchedulingRule after 3.0
1714 * @param toCreateOrModify
1715 * the resource to create or modify
1716 * @return the minimal scheduling rule needed to modify or create a resource
1718 protected ISchedulingRule computeSchedulingRule(IResource toCreateOrModify) {
1719 IResourceRuleFactory factory = ResourcesPlugin.getWorkspace()
1721 if (toCreateOrModify.exists()) {
1722 return factory.modifyRule(toCreateOrModify);
1724 IResource parent = toCreateOrModify;
1726 toCreateOrModify = parent;
1727 parent = toCreateOrModify.getParent();
1728 } while (parent != null && !parent.exists());
1730 return factory.createRule(toCreateOrModify);