added class fields to outline
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / phpeditor / PHPDocumentProvider.java
1 package net.sourceforge.phpeclipse.phpeditor;
2
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
9
10 Contributors:
11     IBM Corporation - Initial implementation
12     Klaus Hartlage - www.eclipseproject.de
13 **********************************************************************/
14
15 import java.io.ByteArrayInputStream;
16 import java.io.IOException;
17 import java.io.InputStream;
18 import java.util.ArrayList;
19 import java.util.Iterator;
20 import java.util.List;
21
22 import net.sourceforge.phpdt.core.ICompilationUnit;
23 import net.sourceforge.phpdt.core.IJavaModelStatusConstants;
24 import net.sourceforge.phpdt.core.IProblemRequestor;
25 import net.sourceforge.phpdt.core.JavaCore;
26 import net.sourceforge.phpdt.core.JavaModelException;
27 import net.sourceforge.phpdt.core.compiler.IProblem;
28 import net.sourceforge.phpdt.internal.ui.PHPUIStatus;
29 import net.sourceforge.phpdt.internal.ui.text.java.IProblemRequestorExtension;
30 import net.sourceforge.phpdt.ui.PreferenceConstants;
31 import net.sourceforge.phpdt.ui.text.JavaTextTools;
32 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
33
34 import org.eclipse.core.resources.IFile;
35 import org.eclipse.core.resources.IMarker;
36 import org.eclipse.core.resources.IMarkerDelta;
37 import org.eclipse.core.resources.IResource;
38 import org.eclipse.core.resources.IResourceRuleFactory;
39 import org.eclipse.core.resources.ResourcesPlugin;
40 import org.eclipse.core.runtime.CoreException;
41 import org.eclipse.core.runtime.IProgressMonitor;
42 import org.eclipse.core.runtime.IStatus;
43 import org.eclipse.core.runtime.Status;
44 import org.eclipse.core.runtime.jobs.ISchedulingRule;
45 import org.eclipse.jface.preference.IPreferenceStore;
46 import org.eclipse.jface.text.Assert;
47 import org.eclipse.jface.text.BadLocationException;
48 import org.eclipse.jface.text.DefaultLineTracker;
49 import org.eclipse.jface.text.Document;
50 import org.eclipse.jface.text.IDocument;
51 import org.eclipse.jface.text.ILineTracker;
52 import org.eclipse.jface.text.ISynchronizable;
53 import org.eclipse.jface.text.Position;
54 import org.eclipse.jface.text.source.Annotation;
55 import org.eclipse.jface.text.source.AnnotationModelEvent;
56 import org.eclipse.jface.text.source.IAnnotationAccessExtension;
57 import org.eclipse.jface.text.source.IAnnotationModel;
58 import org.eclipse.jface.text.source.IAnnotationModelListener;
59 import org.eclipse.jface.text.source.IAnnotationModelListenerExtension;
60 import org.eclipse.jface.text.source.IAnnotationPresentation;
61 import org.eclipse.jface.text.source.ImageUtilities;
62 import org.eclipse.jface.util.IPropertyChangeListener;
63 import org.eclipse.jface.util.ListenerList;
64 import org.eclipse.jface.util.PropertyChangeEvent;
65 import org.eclipse.swt.SWT;
66 import org.eclipse.swt.graphics.GC;
67 import org.eclipse.swt.graphics.Image;
68 import org.eclipse.swt.graphics.Rectangle;
69 import org.eclipse.swt.widgets.Canvas;
70 import org.eclipse.swt.widgets.Display;
71 import org.eclipse.ui.IEditorInput;
72 import org.eclipse.ui.IFileEditorInput;
73 import org.eclipse.ui.editors.text.EditorsUI;
74 import org.eclipse.ui.editors.text.TextFileDocumentProvider;
75 import org.eclipse.ui.part.FileEditorInput;
76 import org.eclipse.ui.texteditor.AbstractMarkerAnnotationModel;
77 import org.eclipse.ui.texteditor.AnnotationPreference;
78 import org.eclipse.ui.texteditor.AnnotationPreferenceLookup;
79 import org.eclipse.ui.texteditor.MarkerAnnotation;
80 import org.eclipse.ui.texteditor.MarkerUtilities;
81 import org.eclipse.ui.texteditor.ResourceMarkerAnnotationModel;
82
83 /** 
84  * The PHPDocumentProvider provides the IDocuments used by java editors.
85  */
86
87 public class PHPDocumentProvider extends TextFileDocumentProvider {
88   /**
89                          * Here for visibility issues only.
90                          */
91
92   /**
93                  * Bundle of all required informations to allow working copy management. 
94                  */
95         /**
96          * Bundle of all required informations to allow working copy management. 
97          */
98         static protected class CompilationUnitInfo extends FileInfo {
99                 public ICompilationUnit fCopy;
100         }
101         
102         /**
103          * Annotation model dealing with java marker annotations and temporary problems.
104          * Also acts as problem requestor for its compilation unit. Initialiy inactive. Must explicitly be
105          * activated.
106          */
107         protected static class CompilationUnitAnnotationModel extends ResourceMarkerAnnotationModel implements IProblemRequestor, IProblemRequestorExtension {
108                 
109                 private static class ProblemRequestorState {
110                         boolean fInsideReportingSequence= false;
111                         List fReportedProblems;
112                 }
113                 
114                 private ThreadLocal fProblemRequestorState= new ThreadLocal();
115                 private int fStateCount= 0;
116                 
117                 private ICompilationUnit fCompilationUnit;
118                 private List fGeneratedAnnotations;
119                 private IProgressMonitor fProgressMonitor;
120                 private boolean fIsActive= false;
121                 
122                 private ReverseMap fReverseMap= new ReverseMap();
123                 private List fPreviouslyOverlaid= null; 
124                 private List fCurrentlyOverlaid= new ArrayList();
125
126                 
127                 public CompilationUnitAnnotationModel(IResource resource) {
128                         super(resource);
129                 }
130                 
131                 public void setCompilationUnit(ICompilationUnit unit)  {
132                         fCompilationUnit= unit;
133                 }
134                 
135                 protected MarkerAnnotation createMarkerAnnotation(IMarker marker) {
136                         String markerType= MarkerUtilities.getMarkerType(marker);
137                         if (markerType != null && markerType.startsWith(JavaMarkerAnnotation.JAVA_MARKER_TYPE_PREFIX))
138                                 return new JavaMarkerAnnotation(marker);
139                         return super.createMarkerAnnotation(marker);
140                 }
141                 
142                 /*
143                  * @see org.eclipse.jface.text.source.AnnotationModel#createAnnotationModelEvent()
144                  */
145                 protected AnnotationModelEvent createAnnotationModelEvent() {
146                         return new CompilationUnitAnnotationModelEvent(this, getResource());
147                 }
148                 
149                 protected Position createPositionFromProblem(IProblem problem) {
150                         int start= problem.getSourceStart();
151                         if (start < 0)
152                                 return null;
153                                 
154                         int length= problem.getSourceEnd() - problem.getSourceStart() + 1;
155                         if (length < 0)
156                                 return null;
157                                 
158                         return new Position(start, length);
159                 }
160                 
161                 /*
162                  * @see IProblemRequestor#beginReporting()
163                  */
164                 public void beginReporting() {
165                         ProblemRequestorState state= (ProblemRequestorState) fProblemRequestorState.get();
166                         if (state == null)
167                                 internalBeginReporting(false);                          
168                 }
169                 
170                 /*
171                  * @see org.eclipse.jdt.internal.ui.text.java.IProblemRequestorExtension#beginReportingSequence()
172                  */
173                 public void beginReportingSequence() {
174                         ProblemRequestorState state= (ProblemRequestorState) fProblemRequestorState.get();
175                         if (state == null)
176                                 internalBeginReporting(true);
177                 }
178                 
179                 /**
180                  * Sets up the infrastructure necessary for problem reporting.
181                  * 
182                  * @param insideReportingSequence <code>true</code> if this method
183                  *            call is issued from inside a reporting sequence
184                  */
185                 private void internalBeginReporting(boolean insideReportingSequence) {
186                         if (fCompilationUnit != null) {
187                 // && fCompilationUnit.getJavaProject().isOnClasspath(fCompilationUnit)) {
188                                 ProblemRequestorState state= new ProblemRequestorState();
189                                 state.fInsideReportingSequence= insideReportingSequence;
190                                 state.fReportedProblems= new ArrayList();
191                                 synchronized (getLockObject()) {
192                                         fProblemRequestorState.set(state);
193                                         ++fStateCount;
194                                 }
195                         }
196                 }
197
198                 /*
199                  * @see IProblemRequestor#acceptProblem(IProblem)
200                  */
201                 public void acceptProblem(IProblem problem) {
202                         if (isActive()) {
203                                 ProblemRequestorState state= (ProblemRequestorState) fProblemRequestorState.get();
204                                 if (state != null)
205                                         state.fReportedProblems.add(problem);
206                         }
207                 }
208                 
209                 /*
210                  * @see IProblemRequestor#endReporting()
211                  */
212                 public void endReporting() {
213                         ProblemRequestorState state= (ProblemRequestorState) fProblemRequestorState.get();
214                         if (state != null && !state.fInsideReportingSequence)
215                                 internalEndReporting(state);
216                 }
217                 
218                 /*
219                  * @see org.eclipse.jdt.internal.ui.text.java.IProblemRequestorExtension#endReportingSequence()
220                  */
221                 public void endReportingSequence() {
222                         ProblemRequestorState state= (ProblemRequestorState) fProblemRequestorState.get();
223                         if (state != null && state.fInsideReportingSequence)
224                                 internalEndReporting(state);
225                 }
226                 
227                 private void internalEndReporting(ProblemRequestorState state) {
228                         int stateCount= 0;
229                         synchronized(getLockObject()) {
230                                 -- fStateCount;
231                                 stateCount= fStateCount;
232                                 fProblemRequestorState.set(null);
233                         }
234                         
235                         if (stateCount == 0 && isActive())
236                                 reportProblems(state.fReportedProblems);
237                 }
238                 
239                 /**
240                  * Signals the end of problem reporting.
241                  */
242                 private void reportProblems(List reportedProblems) {
243                         if (fProgressMonitor != null && fProgressMonitor.isCanceled())
244                                 return;
245                                 
246                         boolean temporaryProblemsChanged= false;
247                         
248                         synchronized (getLockObject()) {
249                                 
250                                 boolean isCanceled= false;
251
252                                 fPreviouslyOverlaid= fCurrentlyOverlaid;
253                                 fCurrentlyOverlaid= new ArrayList();
254
255                                 if (fGeneratedAnnotations.size() > 0) {
256                                         temporaryProblemsChanged= true; 
257                                         removeAnnotations(fGeneratedAnnotations, false, true);
258                                         fGeneratedAnnotations.clear();
259                                 }
260                                 
261                                 if (reportedProblems != null && reportedProblems.size() > 0) {
262                                                                                         
263                                         Iterator e= reportedProblems.iterator();
264                                         while (e.hasNext()) {
265                                                 
266                                                 if (fProgressMonitor != null && fProgressMonitor.isCanceled()) {
267                                                         isCanceled= true;
268                                                         break;
269                                                 }
270                                                         
271                                                 IProblem problem= (IProblem) e.next();
272                                                 Position position= createPositionFromProblem(problem);
273                                                 if (position != null) {
274                                                         
275                                                         try {
276                                                                 ProblemAnnotation annotation= new ProblemAnnotation(problem, fCompilationUnit);
277                                                                 overlayMarkers(position, annotation);                                                           
278                                                                 addAnnotation(annotation, position, false);
279                                                                 fGeneratedAnnotations.add(annotation);
280                                                         
281                                                                 temporaryProblemsChanged= true;
282                                                         } catch (BadLocationException x) {
283                                                                 // ignore invalid position
284                                                         }
285                                                 }
286                                         }
287                                 }
288                                 
289                                 removeMarkerOverlays(isCanceled);
290                                 fPreviouslyOverlaid= null;
291                         }
292                                 
293                         if (temporaryProblemsChanged)
294                                 fireModelChanged();
295                 }
296
297                 private void removeMarkerOverlays(boolean isCanceled) {
298                         if (isCanceled) {
299                                 fCurrentlyOverlaid.addAll(fPreviouslyOverlaid);
300                         } else if (fPreviouslyOverlaid != null) {
301                                 Iterator e= fPreviouslyOverlaid.iterator();
302                                 while (e.hasNext()) {
303                                         JavaMarkerAnnotation annotation= (JavaMarkerAnnotation) e.next();
304                                         annotation.setOverlay(null);
305                                 }
306                         }                       
307                 }
308                 
309                 /**
310                  * Overlays value with problem annotation.
311                  * @param problemAnnotation
312                  */
313                 private void setOverlay(Object value, ProblemAnnotation problemAnnotation) {
314                         if (value instanceof  JavaMarkerAnnotation) {
315                                 JavaMarkerAnnotation annotation= (JavaMarkerAnnotation) value;
316                                 if (annotation.isProblem()) {
317                                         annotation.setOverlay(problemAnnotation);
318                                         fPreviouslyOverlaid.remove(annotation);
319                                         fCurrentlyOverlaid.add(annotation);
320                                 }
321                         } else {
322                         }
323                 }
324                 
325                 private void  overlayMarkers(Position position, ProblemAnnotation problemAnnotation) {
326                         Object value= getAnnotations(position);
327                         if (value instanceof List) {
328                                 List list= (List) value;
329                                 for (Iterator e = list.iterator(); e.hasNext();)
330                                         setOverlay(e.next(), problemAnnotation);
331                         } else {
332                                 setOverlay(value, problemAnnotation);
333                         }
334                 }
335                 
336                 /**
337                  * Tells this annotation model to collect temporary problems from now on.
338                  */
339                 private void startCollectingProblems() {
340                         fGeneratedAnnotations= new ArrayList();  
341                 }
342                 
343                 /**
344                  * Tells this annotation model to no longer collect temporary problems.
345                  */
346                 private void stopCollectingProblems() {
347                         if (fGeneratedAnnotations != null)
348                                 removeAnnotations(fGeneratedAnnotations, true, true);
349                         fGeneratedAnnotations= null;
350                 }
351                 
352                 /*
353                  * @see IProblemRequestor#isActive()
354                  */
355                 public boolean isActive() {
356                         return fIsActive;
357                 }
358                 
359                 /*
360                  * @see IProblemRequestorExtension#setProgressMonitor(IProgressMonitor)
361                  */
362                 public void setProgressMonitor(IProgressMonitor monitor) {
363                         fProgressMonitor= monitor;
364                 }
365                 
366                 /*
367                  * @see IProblemRequestorExtension#setIsActive(boolean)
368                  */
369                 public void setIsActive(boolean isActive) {
370                         if (fIsActive != isActive) {
371                                 fIsActive= isActive;
372                                 if (fIsActive)
373                                         startCollectingProblems();
374                                 else
375                                         stopCollectingProblems();
376                         }
377                 }
378                 
379                 private Object getAnnotations(Position position) {
380                         return fReverseMap.get(position);
381                 }
382                                         
383                 /*
384                  * @see AnnotationModel#addAnnotation(Annotation, Position, boolean)
385                  */
386                 protected void addAnnotation(Annotation annotation, Position position, boolean fireModelChanged) throws BadLocationException {                          
387                         super.addAnnotation(annotation, position, fireModelChanged);
388
389                         Object cached= fReverseMap.get(position);
390                         if (cached == null)
391                                 fReverseMap.put(position, annotation);
392                         else if (cached instanceof List) {
393                                 List list= (List) cached;
394                                 list.add(annotation);
395                         } else if (cached instanceof Annotation) {
396                                 List list= new ArrayList(2);
397                                 list.add(cached);
398                                 list.add(annotation);
399                                 fReverseMap.put(position, list);
400                         }
401                 }
402                 
403                 /*
404                  * @see AnnotationModel#removeAllAnnotations(boolean)
405                  */
406                 protected void removeAllAnnotations(boolean fireModelChanged) {
407                         super.removeAllAnnotations(fireModelChanged);
408                         fReverseMap.clear();
409                 }
410                 
411                 /*
412                  * @see AnnotationModel#removeAnnotation(Annotation, boolean)
413                  */
414                 protected void removeAnnotation(Annotation annotation, boolean fireModelChanged) {
415                         Position position= getPosition(annotation);
416                         Object cached= fReverseMap.get(position);
417                         if (cached instanceof List) {
418                                 List list= (List) cached;
419                                 list.remove(annotation);
420                                 if (list.size() == 1) {
421                                         fReverseMap.put(position, list.get(0));
422                                         list.clear();
423                                 }
424                         } else if (cached instanceof Annotation) {
425                                 fReverseMap.remove(position);
426                         }
427                         super.removeAnnotation(annotation, fireModelChanged);
428                 }
429         }
430   
431    
432   
433   protected static class GlobalAnnotationModelListener implements IAnnotationModelListener, IAnnotationModelListenerExtension {
434
435     private ListenerList fListenerList;
436
437     public GlobalAnnotationModelListener() {
438       fListenerList = new ListenerList();
439     }
440
441     public void addListener(IAnnotationModelListener listener) {
442       fListenerList.add(listener);
443     }
444
445     /**
446      * @see IAnnotationModelListenerExtension#modelChanged(AnnotationModelEvent)
447      */
448     public void modelChanged(AnnotationModelEvent event) {
449       Object[] listeners = fListenerList.getListeners();
450       for (int i = 0; i < listeners.length; i++) {
451         Object curr = listeners[i];
452         if (curr instanceof IAnnotationModelListenerExtension) {
453           ((IAnnotationModelListenerExtension) curr).modelChanged(event);
454         }
455       }
456     }
457
458     /**
459      * @see IAnnotationModelListener#modelChanged(IAnnotationModel)
460      */
461     public void modelChanged(IAnnotationModel model) {
462       Object[] listeners = fListenerList.getListeners();
463       for (int i = 0; i < listeners.length; i++) {
464         ((IAnnotationModelListener) listeners[i]).modelChanged(model);
465       }
466     }
467
468     public void removeListener(IAnnotationModelListener listener) {
469       fListenerList.remove(listener);
470     }
471   }
472
473   /**
474          * Annotation representating an <code>IProblem</code>.
475          */
476         static protected class ProblemAnnotation extends Annotation implements IJavaAnnotation, IAnnotationPresentation {
477                 
478                 private static final String SPELLING_ANNOTATION_TYPE= "org.eclipse.ui.workbench.texteditor.spelling";
479
480                 //XXX: To be fully correct these constants should be non-static
481                 /** 
482                  * The layer in which task problem annotations are located.
483                  */
484                 private static final int TASK_LAYER;
485                 /** 
486                  * The layer in which info problem annotations are located.
487                  */
488                 private static final int INFO_LAYER;
489                 /** 
490                  * The layer in which warning problem annotations representing are located.
491                  */
492                 private static final int WARNING_LAYER;
493                 /** 
494                  * The layer in which error problem annotations representing are located.
495                  */
496                 private static final int ERROR_LAYER;
497                 
498                 static {
499                         AnnotationPreferenceLookup lookup= EditorsUI.getAnnotationPreferenceLookup();
500                         TASK_LAYER= computeLayer("org.eclipse.ui.workbench.texteditor.task", lookup); //$NON-NLS-1$
501                         INFO_LAYER= computeLayer("net.sourceforge.phpdt.ui.info", lookup); //$NON-NLS-1$
502                         WARNING_LAYER= computeLayer("net.sourceforge.phpdt.ui.warning", lookup); //$NON-NLS-1$
503                         ERROR_LAYER= computeLayer("net.sourceforge.phpdt.ui.error", lookup); //$NON-NLS-1$
504                 }
505                 
506                 private static int computeLayer(String annotationType, AnnotationPreferenceLookup lookup) {
507                         Annotation annotation= new Annotation(annotationType, false, null);
508                         AnnotationPreference preference= lookup.getAnnotationPreference(annotation);
509                         if (preference != null)
510                                 return preference.getPresentationLayer() + 1;
511                         else
512                                 return IAnnotationAccessExtension.DEFAULT_LAYER + 1;
513                 }
514
515 //              private static Image fgQuickFixImage;
516 //              private static Image fgQuickFixErrorImage;
517 //              private static boolean fgQuickFixImagesInitialized= false;
518                 
519                 private ICompilationUnit fCompilationUnit;
520                 private List fOverlaids;
521                 private IProblem fProblem;
522                 private Image fImage;
523                 private boolean fQuickFixImagesInitialized= false;
524                 private int fLayer= IAnnotationAccessExtension.DEFAULT_LAYER;
525                 
526                 public ProblemAnnotation(IProblem problem, ICompilationUnit cu) {
527                         
528                         fProblem= problem;
529                         fCompilationUnit= cu;
530                         
531 //                      if (SpellProblem.Spelling == fProblem.getID()) {
532 //                              setType(SPELLING_ANNOTATION_TYPE);
533 //                              fLayer= WARNING_LAYER;
534 //                      } else 
535                     if (IProblem.Task == fProblem.getID()) {
536                                 setType(JavaMarkerAnnotation.TASK_ANNOTATION_TYPE);
537                                 fLayer= TASK_LAYER;
538                         } else if (fProblem.isWarning()) {
539                                 setType(JavaMarkerAnnotation.WARNING_ANNOTATION_TYPE);
540                                 fLayer= WARNING_LAYER;
541                         } else if (fProblem.isError()) {
542                                 setType(JavaMarkerAnnotation.ERROR_ANNOTATION_TYPE);
543                                 fLayer= ERROR_LAYER;
544                         } else {
545                                 setType(JavaMarkerAnnotation.INFO_ANNOTATION_TYPE);
546                                 fLayer= INFO_LAYER;
547                         }
548                 }
549                 
550                 /*
551                  * @see org.eclipse.jface.text.source.IAnnotationPresentation#getLayer()
552                  */
553                 public int getLayer() {
554                         return fLayer;
555                 }
556                 
557                 private void initializeImages() {
558                         // http://bugs.eclipse.org/bugs/show_bug.cgi?id=18936
559 //                      if (!fQuickFixImagesInitialized) {
560 //                              if (isProblem() && indicateQuixFixableProblems() && JavaCorrectionProcessor.hasCorrections(this)) { // no light bulb for tasks
561 //                                      if (!fgQuickFixImagesInitialized) {
562 //                                              fgQuickFixImage= JavaPluginImages.get(JavaPluginImages.IMG_OBJS_FIXABLE_PROBLEM);
563 //                                              fgQuickFixErrorImage= JavaPluginImages.get(JavaPluginImages.IMG_OBJS_FIXABLE_ERROR);
564 //                                              fgQuickFixImagesInitialized= true;
565 //                                      }
566 //                                      if (JavaMarkerAnnotation.ERROR_ANNOTATION_TYPE.equals(getType()))
567 //                                              fImage= fgQuickFixErrorImage;
568 //                                      else
569 //                                              fImage= fgQuickFixImage;
570 //                              }
571 //                              fQuickFixImagesInitialized= true;
572 //                      }
573                 }
574
575                 private boolean indicateQuixFixableProblems() {
576                         return PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_CORRECTION_INDICATION);
577                 }
578                 
579                 /*
580                  * @see Annotation#paint
581                  */
582                 public void paint(GC gc, Canvas canvas, Rectangle r) {
583                         initializeImages();
584                         if (fImage != null)
585                                 ImageUtilities.drawImage(fImage, gc, canvas, r, SWT.CENTER, SWT.TOP);
586                 }
587                 /*
588                  * @see IJavaAnnotation#getImage(Display)
589                  */
590                 public Image getImage(Display display) {
591                         initializeImages();
592                         return fImage;
593                 }
594                 
595                 /*
596                  * @see IJavaAnnotation#getMessage()
597                  */
598                 public String getText() {
599                         return fProblem.getMessage();
600                 }
601                 
602                 /*
603                  * @see IJavaAnnotation#getArguments()
604                  */
605                 public String[] getArguments() {
606                         return isProblem() ? fProblem.getArguments() : null;
607                 }
608
609                 /*
610                  * @see IJavaAnnotation#getId()
611                  */
612                 public int getId() {
613                         return fProblem.getID();
614                 }
615
616                 /*
617                  * @see IJavaAnnotation#isProblem()
618                  */
619                 public boolean isProblem() {
620                         String type= getType();
621                         return  JavaMarkerAnnotation.WARNING_ANNOTATION_TYPE.equals(type)  || 
622                                                 JavaMarkerAnnotation.ERROR_ANNOTATION_TYPE.equals(type) ||
623                                                 SPELLING_ANNOTATION_TYPE.equals(type);
624                 }
625                 
626                 /*
627                  * @see IJavaAnnotation#hasOverlay()
628                  */
629                 public boolean hasOverlay() {
630                         return false;
631                 }
632                 
633                 /*
634                  * @see org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation#getOverlay()
635                  */
636                 public IJavaAnnotation getOverlay() {
637                         return null;
638                 }
639                 
640                 /*
641                  * @see IJavaAnnotation#addOverlaid(IJavaAnnotation)
642                  */
643                 public void addOverlaid(IJavaAnnotation annotation) {
644                         if (fOverlaids == null)
645                                 fOverlaids= new ArrayList(1);
646                         fOverlaids.add(annotation);
647                 }
648
649                 /*
650                  * @see IJavaAnnotation#removeOverlaid(IJavaAnnotation)
651                  */
652                 public void removeOverlaid(IJavaAnnotation annotation) {
653                         if (fOverlaids != null) {
654                                 fOverlaids.remove(annotation);
655                                 if (fOverlaids.size() == 0)
656                                         fOverlaids= null;
657                         }
658                 }
659                 
660                 /*
661                  * @see IJavaAnnotation#getOverlaidIterator()
662                  */
663                 public Iterator getOverlaidIterator() {
664                         if (fOverlaids != null)
665                                 return fOverlaids.iterator();
666                         return null;
667                 }
668                 
669                 /*
670                  * @see org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation#getCompilationUnit()
671                  */
672                 public ICompilationUnit getCompilationUnit() {
673                         return fCompilationUnit;
674                 }
675         }
676         
677  
678   /**
679                  * Internal structure for mapping positions to some value. 
680                  * The reason for this specific structure is that positions can
681                  * change over time. Thus a lookup is based on value and not
682                  * on hash value.
683                  */
684   protected static class ReverseMap {
685
686     static class Entry {
687       Position fPosition;
688       Object fValue;
689     }
690     private int fAnchor = 0;
691
692     private List fList = new ArrayList(2);
693
694     public ReverseMap() {
695     }
696
697     public void clear() {
698       fList.clear();
699     }
700
701     public Object get(Position position) {
702
703       Entry entry;
704
705       // behind anchor
706       int length = fList.size();
707       for (int i = fAnchor; i < length; i++) {
708         entry = (Entry) fList.get(i);
709         if (entry.fPosition.equals(position)) {
710           fAnchor = i;
711           return entry.fValue;
712         }
713       }
714
715       // before anchor
716       for (int i = 0; i < fAnchor; i++) {
717         entry = (Entry) fList.get(i);
718         if (entry.fPosition.equals(position)) {
719           fAnchor = i;
720           return entry.fValue;
721         }
722       }
723
724       return null;
725     }
726
727     private int getIndex(Position position) {
728       Entry entry;
729       int length = fList.size();
730       for (int i = 0; i < length; i++) {
731         entry = (Entry) fList.get(i);
732         if (entry.fPosition.equals(position))
733           return i;
734       }
735       return -1;
736     }
737
738     public void put(Position position, Object value) {
739       int index = getIndex(position);
740       if (index == -1) {
741         Entry entry = new Entry();
742         entry.fPosition = position;
743         entry.fValue = value;
744         fList.add(entry);
745       } else {
746         Entry entry = (Entry) fList.get(index);
747         entry.fValue = value;
748       }
749     }
750
751     public void remove(Position position) {
752       int index = getIndex(position);
753       if (index > -1)
754         fList.remove(index);
755     }
756   }
757
758   /**
759                  * Document that can also be used by a background reconciler.
760                  */
761   protected static class PartiallySynchronizedDocument extends Document {
762
763     /*
764      * @see IDocumentExtension#startSequentialRewrite(boolean)
765      */
766     synchronized public void startSequentialRewrite(boolean normalized) {
767       super.startSequentialRewrite(normalized);
768     }
769
770     /*
771      * @see IDocumentExtension#stopSequentialRewrite()
772      */
773     synchronized public void stopSequentialRewrite() {
774       super.stopSequentialRewrite();
775     }
776
777     /*
778      * @see IDocument#get()
779      */
780     synchronized public String get() {
781       return super.get();
782     }
783
784     /*
785      * @see IDocument#get(int, int)
786      */
787     synchronized public String get(int offset, int length) throws BadLocationException {
788       return super.get(offset, length);
789     }
790
791     /*
792      * @see IDocument#getChar(int)
793      */
794     synchronized public char getChar(int offset) throws BadLocationException {
795       return super.getChar(offset);
796     }
797
798     /*
799      * @see IDocument#replace(int, int, String)
800      */
801     synchronized public void replace(int offset, int length, String text) throws BadLocationException {
802       super.replace(offset, length, text);
803     }
804
805     /*
806      * @see IDocument#set(String)
807      */
808     synchronized public void set(String text) {
809       super.set(text);
810     }
811   };
812   //
813   //  private static PHPPartitionScanner HTML_PARTITION_SCANNER = null;
814   //
815   //  private static PHPPartitionScanner PHP_PARTITION_SCANNER = null;
816   //  private static PHPPartitionScanner SMARTY_PARTITION_SCANNER = null;
817   //
818   //  // private final static String[] TYPES= new String[] { PHPPartitionScanner.PHP, PHPPartitionScanner.JAVA_DOC, PHPPartitionScanner.JAVA_MULTILINE_COMMENT };
819   //  private final static String[] TYPES =
820   //    new String[] {
821   //      IPHPPartitionScannerConstants.PHP,
822   //      IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT,
823   //      IPHPPartitionScannerConstants.HTML,
824   //      IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT,
825   //      IPHPPartitionScannerConstants.JAVASCRIPT,
826   //      IPHPPartitionScannerConstants.CSS,
827   //      IPHPPartitionScannerConstants.SMARTY,
828   //      IPHPPartitionScannerConstants.SMARTY_MULTILINE_COMMENT };
829   //  private static PHPPartitionScanner XML_PARTITION_SCANNER = null;
830
831   /* Preference key for temporary problems */
832   private final static String HANDLE_TEMPORARY_PROBLEMS = PreferenceConstants.EDITOR_EVALUTE_TEMPORARY_PROBLEMS;
833
834   /** Indicates whether the save has been initialized by this provider */
835   private boolean fIsAboutToSave = false;
836   /** The save policy used by this provider */
837   private ISavePolicy fSavePolicy;
838   /** Internal property changed listener */
839   private IPropertyChangeListener fPropertyListener;
840
841   /** annotation model listener added to all created CU annotation models */
842   private GlobalAnnotationModelListener fGlobalAnnotationModelListener;
843
844   public PHPDocumentProvider() {
845         setParentDocumentProvider(new TextFileDocumentProvider(new JavaStorageDocumentProvider()));             
846         
847         fPropertyListener= new IPropertyChangeListener() {
848                 public void propertyChange(PropertyChangeEvent event) {
849                         if (HANDLE_TEMPORARY_PROBLEMS.equals(event.getProperty()))
850                                 enableHandlingTemporaryProblems();
851                 }
852         };
853         fGlobalAnnotationModelListener= new GlobalAnnotationModelListener();
854         PHPeclipsePlugin.getDefault().getPreferenceStore().addPropertyChangeListener(fPropertyListener);
855
856   }
857
858   /**
859    * Sets the document provider's save policy.
860    */
861   public void setSavePolicy(ISavePolicy savePolicy) {
862     fSavePolicy = savePolicy;
863   }
864
865   /**
866    * Creates a compilation unit from the given file.
867    * 
868    * @param file the file from which to create the compilation unit
869    */
870   protected ICompilationUnit createCompilationUnit(IFile file) {
871     Object element = JavaCore.create(file);
872     if (element instanceof ICompilationUnit)
873       return (ICompilationUnit) element;
874     return null;
875   }
876   
877
878   /*
879          * @see org.eclipse.ui.editors.text.TextFileDocumentProvider#createEmptyFileInfo()
880          */
881         protected FileInfo createEmptyFileInfo() {
882                 return new CompilationUnitInfo();
883         }
884         /*
885          * @see org.eclipse.ui.editors.text.TextFileDocumentProvider#createAnnotationModel(org.eclipse.core.resources.IFile)
886          */
887         protected IAnnotationModel createAnnotationModel(IFile file) {
888                 return new CompilationUnitAnnotationModel(file);
889         }
890   /*
891          * @see AbstractDocumentProvider#createElementInfo(Object)
892          */
893 //  protected ElementInfo createElementInfo(Object element) throws CoreException {
894 //
895 //    if (!(element instanceof IFileEditorInput))
896 //      return super.createElementInfo(element);
897 //
898 //    IFileEditorInput input = (IFileEditorInput) element;
899 //    ICompilationUnit original = createCompilationUnit(input.getFile());
900 //    if (original != null) {
901 //
902 //      try {
903 //
904 //        try {
905 //          refreshFile(input.getFile());
906 //        } catch (CoreException x) {
907 //          handleCoreException(x, PHPEditorMessages.getString("PHPDocumentProvider.error.createElementInfo")); //$NON-NLS-1$
908 //        }
909 //
910 //        IAnnotationModel m = createCompilationUnitAnnotationModel(input);
911 //        IProblemRequestor r = m instanceof IProblemRequestor ? (IProblemRequestor) m : null;
912 //        ICompilationUnit c = (ICompilationUnit) original.getSharedWorkingCopy(getProgressMonitor(), fBufferFactory, r);
913 //
914 //        DocumentAdapter a = null;
915 //        try {
916 //          a = (DocumentAdapter) c.getBuffer();
917 //        } catch (ClassCastException x) {
918 //          IStatus status = new Status(IStatus.ERROR, PHPeclipsePlugin.PLUGIN_ID, PHPStatusConstants.TEMPLATE_IO_EXCEPTION, "Shared working copy has wrong buffer", x); //$NON-NLS-1$
919 //          throw new CoreException(status);
920 //        }
921 //
922 //        _FileSynchronizer f = new _FileSynchronizer(input);
923 //        f.install();
924 //
925 //        CompilationUnitInfo info = new CompilationUnitInfo(a.getDocument(), m, f, c);
926 //        info.setModificationStamp(computeModificationStamp(input.getFile()));
927 //        info.fStatus = a.getStatus();
928 //        info.fEncoding = getPersistedEncoding(input);
929 //
930 //        if (r instanceof IProblemRequestorExtension) {
931 //          IProblemRequestorExtension extension = (IProblemRequestorExtension) r;
932 //          extension.setIsActive(isHandlingTemporaryProblems());
933 //        }
934 //        m.addAnnotationModelListener(fGlobalAnnotationModelListener);
935 //
936 //        return info;
937 //
938 //      } catch (JavaModelException x) {
939 //        throw new CoreException(x.getStatus());
940 //      }
941 //    } else {
942 //      return super.createElementInfo(element);
943 //    }
944 //  }
945
946   /*
947    * @see AbstractDocumentProvider#disposeElementInfo(Object, ElementInfo)
948    */
949 //  protected void disposeElementInfo(Object element, ElementInfo info) {
950 //
951 //    if (info instanceof CompilationUnitInfo) {
952 //      CompilationUnitInfo cuInfo = (CompilationUnitInfo) info;
953 //      cuInfo.fCopy.destroy();
954 //      cuInfo.fModel.removeAnnotationModelListener(fGlobalAnnotationModelListener);
955 //    }
956 //
957 //    super.disposeElementInfo(element, info);
958 //  }
959
960   /*
961          * @see AbstractDocumentProvider#doSaveDocument(IProgressMonitor, Object, IDocument, boolean)
962          */
963 //  protected void doSaveDocument(IProgressMonitor monitor, Object element, IDocument document, boolean overwrite)
964 //    throws CoreException {
965 //
966 //    ElementInfo elementInfo = getElementInfo(element);
967 //    if (elementInfo instanceof CompilationUnitInfo) {
968 //      CompilationUnitInfo info = (CompilationUnitInfo) elementInfo;
969 //
970 //      // update structure, assumes lock on info.fCopy
971 //      info.fCopy.reconcile();
972 //
973 //      ICompilationUnit original = (ICompilationUnit) info.fCopy.getOriginalElement();
974 //      IResource resource = original.getResource();
975 //
976 //      if (resource == null) {
977 //        // underlying resource has been deleted, just recreate file, ignore the rest
978 //        super.doSaveDocument(monitor, element, document, overwrite);
979 //        return;
980 //      }
981 //
982 //      if (resource != null && !overwrite)
983 //        checkSynchronizationState(info.fModificationStamp, resource);
984 //
985 //      if (fSavePolicy != null)
986 //        fSavePolicy.preSave(info.fCopy);
987 //
988 //      // inform about the upcoming content change
989 //      fireElementStateChanging(element);
990 //      try {
991 //        fIsAboutToSave = true;
992 //        // commit working copy
993 //        info.fCopy.commit(overwrite, monitor);
994 //      } catch (CoreException x) {
995 //        // inform about the failure
996 //        fireElementStateChangeFailed(element);
997 //        throw x;
998 //      } catch (RuntimeException x) {
999 //        // inform about the failure
1000 //        fireElementStateChangeFailed(element);
1001 //        throw x;
1002 //      } finally {
1003 //        fIsAboutToSave = false;
1004 //      }
1005 //
1006 //      // If here, the dirty state of the editor will change to "not dirty".
1007 //      // Thus, the state changing flag will be reset.
1008 //
1009 //      AbstractMarkerAnnotationModel model = (AbstractMarkerAnnotationModel) info.fModel;
1010 //      model.updateMarkers(info.fDocument);
1011 //
1012 //      if (resource != null)
1013 //        info.setModificationStamp(computeModificationStamp(resource));
1014 //
1015 //      if (fSavePolicy != null) {
1016 //        ICompilationUnit unit = fSavePolicy.postSave(original);
1017 //        if (unit != null) {
1018 //          IResource r = unit.getResource();
1019 //          IMarker[] markers = r.findMarkers(IMarker.MARKER, true, IResource.DEPTH_ZERO);
1020 //          if (markers != null && markers.length > 0) {
1021 //            for (int i = 0; i < markers.length; i++)
1022 //              model.updateMarker(markers[i], info.fDocument, null);
1023 //          }
1024 //        }
1025 //      }
1026 //
1027 //    } else {
1028 //      super.doSaveDocument(monitor, element, document, overwrite);
1029 //    }
1030 //  }
1031
1032         /*
1033          * @see org.eclipse.ui.editors.text.TextFileDocumentProvider#createFileInfo(java.lang.Object)
1034          */
1035         protected FileInfo createFileInfo(Object element) throws CoreException {
1036                 if (!(element instanceof IFileEditorInput))
1037                         return null;
1038                         
1039                 IFileEditorInput input= (IFileEditorInput) element;
1040                 ICompilationUnit original= createCompilationUnit(input.getFile());
1041                 if (original == null)
1042                         return null;
1043                 
1044                 FileInfo info= super.createFileInfo(element);
1045                 if (!(info instanceof CompilationUnitInfo))
1046                         return null;
1047                         
1048                 CompilationUnitInfo cuInfo= (CompilationUnitInfo) info;
1049                 setUpSynchronization(cuInfo);
1050                         
1051                 IProblemRequestor requestor= cuInfo.fModel instanceof IProblemRequestor ? (IProblemRequestor) cuInfo.fModel : null;
1052
1053                 original.becomeWorkingCopy(requestor, getProgressMonitor());
1054                 cuInfo.fCopy= original;
1055                 
1056                 if (cuInfo.fModel instanceof CompilationUnitAnnotationModel)   {
1057                         CompilationUnitAnnotationModel model= (CompilationUnitAnnotationModel) cuInfo.fModel;
1058                         model.setCompilationUnit(cuInfo.fCopy);
1059                 } 
1060                 
1061                 if (cuInfo.fModel != null)
1062                         cuInfo.fModel.addAnnotationModelListener(fGlobalAnnotationModelListener);
1063                 
1064                 if (requestor instanceof IProblemRequestorExtension) {
1065                         IProblemRequestorExtension extension= (IProblemRequestorExtension) requestor;
1066                         extension.setIsActive(isHandlingTemporaryProblems());
1067                 }
1068                 
1069                 return cuInfo;
1070         }
1071         
1072     private void setUpSynchronization(CompilationUnitInfo cuInfo) {
1073         IDocument document= cuInfo.fTextFileBuffer.getDocument();
1074         IAnnotationModel model= cuInfo.fModel;
1075         
1076         if (document instanceof ISynchronizable && model instanceof ISynchronizable) {
1077             Object lock= ((ISynchronizable) document).getLockObject();
1078             ((ISynchronizable) model).setLockObject(lock);
1079         }
1080     }
1081     
1082     /*
1083          * @see org.eclipse.ui.editors.text.TextFileDocumentProvider#disposeFileInfo(java.lang.Object, org.eclipse.ui.editors.text.TextFileDocumentProvider.FileInfo)
1084          */
1085         protected void disposeFileInfo(Object element, FileInfo info) {
1086                 if (info instanceof CompilationUnitInfo) {
1087                         CompilationUnitInfo cuInfo= (CompilationUnitInfo) info;
1088                         
1089                         try  {
1090                             cuInfo.fCopy.discardWorkingCopy();
1091                         } catch (JavaModelException x)  {
1092                             handleCoreException(x, x.getMessage());
1093                         }                       
1094                         
1095                         if (cuInfo.fModel != null)
1096                                 cuInfo.fModel.removeAnnotationModelListener(fGlobalAnnotationModelListener);
1097                 }
1098                 super.disposeFileInfo(element, info);
1099         }
1100         
1101   protected void commitWorkingCopy(IProgressMonitor monitor, Object element, CompilationUnitInfo info, boolean overwrite) throws CoreException {
1102         
1103         synchronized (info.fCopy) {
1104                 info.fCopy.reconcile();
1105         }
1106         
1107         IDocument document= info.fTextFileBuffer.getDocument();
1108         IResource resource= info.fCopy.getResource();
1109         
1110         Assert.isTrue(resource instanceof IFile);
1111         if (!resource.exists()) {
1112                 // underlying resource has been deleted, just recreate file, ignore the rest
1113                 createFileFromDocument(monitor, (IFile) resource, document);
1114                 return;
1115         }
1116         
1117         if (fSavePolicy != null)
1118                 fSavePolicy.preSave(info.fCopy);
1119         
1120         try {
1121                 
1122                 fIsAboutToSave= true;
1123                 info.fCopy.commitWorkingCopy(overwrite, monitor);
1124                         
1125         } catch (CoreException x) {
1126                 // inform about the failure
1127                 fireElementStateChangeFailed(element);
1128                 throw x;
1129         } catch (RuntimeException x) {
1130                 // inform about the failure
1131                 fireElementStateChangeFailed(element);
1132                 throw x;
1133         } finally {
1134                 fIsAboutToSave= false;
1135         }
1136         
1137         // If here, the dirty state of the editor will change to "not dirty".
1138         // Thus, the state changing flag will be reset.
1139         if (info.fModel instanceof AbstractMarkerAnnotationModel) {
1140                 AbstractMarkerAnnotationModel model= (AbstractMarkerAnnotationModel) info.fModel;
1141                 model.updateMarkers(document);
1142         }
1143         
1144         if (fSavePolicy != null) {
1145                 ICompilationUnit unit= fSavePolicy.postSave(info.fCopy);
1146                 if (unit != null && info.fModel instanceof AbstractMarkerAnnotationModel) {
1147                         IResource r= unit.getResource();
1148                         IMarker[] markers= r.findMarkers(IMarker.MARKER, true, IResource.DEPTH_ZERO);
1149                         if (markers != null && markers.length > 0) {
1150                                 AbstractMarkerAnnotationModel model= (AbstractMarkerAnnotationModel) info.fModel;                                               
1151                                 for (int i= 0; i < markers.length; i++)
1152                                         model.updateMarker(document, markers[i], null);
1153                         }
1154                 }
1155         }
1156 }
1157
1158 /*
1159  * @see org.eclipse.ui.editors.text.TextFileDocumentProvider#createSaveOperation(java.lang.Object, org.eclipse.jface.text.IDocument, boolean)
1160  */
1161 protected DocumentProviderOperation createSaveOperation(final Object element, final IDocument document, final boolean overwrite) throws CoreException {
1162         final FileInfo info= getFileInfo(element);
1163         if (info instanceof CompilationUnitInfo) {
1164                 return new DocumentProviderOperation() {
1165                         /*
1166                          * @see org.eclipse.ui.editors.text.TextFileDocumentProvider.DocumentProviderOperation#execute(org.eclipse.core.runtime.IProgressMonitor)
1167                          */
1168                         protected void execute(IProgressMonitor monitor) throws CoreException {
1169                                 commitWorkingCopy(monitor, element, (CompilationUnitInfo) info, overwrite);
1170                         }
1171                         /*
1172                          * @see org.eclipse.ui.editors.text.TextFileDocumentProvider.DocumentProviderOperation#getSchedulingRule()
1173                          */
1174                         public ISchedulingRule getSchedulingRule() {
1175                                 if (info.fElement instanceof IFileEditorInput) {
1176                                         IFile file= ((IFileEditorInput) info.fElement).getFile();
1177                                         IResourceRuleFactory ruleFactory= ResourcesPlugin.getWorkspace().getRuleFactory();
1178                                         if (file == null || !file.exists())
1179                                                 return ruleFactory.createRule(file);
1180                                         else
1181                                                 return ruleFactory.modifyRule(file);
1182                                 } else
1183                                         return null;
1184                         }
1185                 };
1186         }
1187         return null;
1188 }
1189
1190   /* (non-Javadoc)
1191    * Method declared on AbstractDocumentProvider
1192    */
1193 //  protected IDocument createDocument(Object element) throws CoreException {
1194 //    if (element instanceof IEditorInput) {
1195 //      Document document = new PartiallySynchronizedDocument();
1196 //      if (setDocumentContent(document, (IEditorInput) element, getEncoding(element))) {
1197 //        initializeDocument(document, (IEditorInput) element);
1198 //
1199 //        //    
1200 //        //    IDocument document = super.createDocument(element);
1201 //        //    if (document != null) {
1202 //        //        IDocumentPartitioner partitioner = null;
1203 //        //        if (element instanceof FileEditorInput) {
1204 //        //          IFile file = (IFile) ((FileEditorInput) element).getAdapter(IFile.class);
1205 //        //          String filename = file.getLocation().toString();
1206 //        //          String extension = filename.substring(filename.lastIndexOf("."), filename.length());
1207 //        //          //   System.out.println(extension);
1208 //        //          if (extension.equalsIgnoreCase(".html") || extension.equalsIgnoreCase(".htm")) {
1209 //        //            // html
1210 //        //            partitioner = createHTMLPartitioner();
1211 //        //          } else if (extension.equalsIgnoreCase(".xml")) {
1212 //        //            // xml
1213 //        //            partitioner = createXMLPartitioner();
1214 //        //          } else if (extension.equalsIgnoreCase(".js")) {
1215 //        //            // javascript
1216 //        //            partitioner = createJavaScriptPartitioner();
1217 //        //          } else if (extension.equalsIgnoreCase(".css")) {
1218 //        //            // cascading style sheets
1219 //        //            partitioner = createCSSPartitioner();
1220 //        //          } else if (extension.equalsIgnoreCase(".tpl")) {
1221 //        //            // smarty ?
1222 //        //            partitioner = createSmartyPartitioner();
1223 //        //          } else if (extension.equalsIgnoreCase(".inc")) {
1224 //        //            // php include files ?
1225 //        //            partitioner = createIncludePartitioner();
1226 //        //          }
1227 //        //        }
1228 //        //
1229 //        //        if (partitioner == null) {
1230 //        //          partitioner = createPHPPartitioner();
1231 //        //        }
1232 //        //        document.setDocumentPartitioner(partitioner);
1233 //        //        partitioner.connect(document);
1234 //      }
1235 //      return document;
1236 //    }
1237 //    return null;
1238 //  }
1239
1240   //  /**
1241   //   * Return a partitioner for .html files.
1242   //   */
1243   //  private IDocumentPartitioner createHTMLPartitioner() {
1244   //    return new DefaultPartitioner(getHTMLPartitionScanner(), TYPES);
1245   //  }
1246   //
1247   //  private IDocumentPartitioner createIncludePartitioner() {
1248   //    return new DefaultPartitioner(getPHPPartitionScanner(), TYPES);
1249   //  }
1250   //
1251   //  private IDocumentPartitioner createJavaScriptPartitioner() {
1252   //    return new DefaultPartitioner(getHTMLPartitionScanner(), TYPES);
1253   //  }
1254
1255   /**
1256    * Creates a line tracker working with the same line delimiters as the document
1257    * of the given element. Assumes the element to be managed by this document provider.
1258    * 
1259    * @param element the element serving as blue print
1260    * @return a line tracker based on the same line delimiters as the element's document
1261    */
1262   public ILineTracker createLineTracker(Object element) {
1263     return new DefaultLineTracker();
1264   }
1265
1266   //  /**
1267   //   * Return a partitioner for .php files.
1268   //   */
1269   //  private IDocumentPartitioner createPHPPartitioner() {
1270   //    return new DefaultPartitioner(getPHPPartitionScanner(), TYPES);
1271   //  }
1272   //
1273   //  private IDocumentPartitioner createSmartyPartitioner() {
1274   //    return new DefaultPartitioner(getSmartyPartitionScanner(), TYPES);
1275   //  }
1276   //
1277   //  private IDocumentPartitioner createXMLPartitioner() {
1278   //    return new DefaultPartitioner(getXMLPartitionScanner(), TYPES);
1279   //  }
1280   //
1281   //  /**
1282   //   * Return a scanner for creating html partitions.
1283   //   */
1284   //  private PHPPartitionScanner getHTMLPartitionScanner() {
1285   //    if (HTML_PARTITION_SCANNER == null)
1286   //      HTML_PARTITION_SCANNER = new PHPPartitionScanner(IPHPPartitionScannerConstants.HTML_FILE);
1287   //    return HTML_PARTITION_SCANNER;
1288   //  }
1289   //  /**
1290   //   * Return a scanner for creating php partitions.
1291   //   */
1292   //  private PHPPartitionScanner getPHPPartitionScanner() {
1293   //    if (PHP_PARTITION_SCANNER == null)
1294   //      PHP_PARTITION_SCANNER = new PHPPartitionScanner(IPHPPartitionScannerConstants.PHP_FILE);
1295   //    return PHP_PARTITION_SCANNER;
1296   //  }
1297   //
1298   //  /**
1299   //   * Return a scanner for creating smarty partitions.
1300   //   */
1301   //  private PHPPartitionScanner getSmartyPartitionScanner() {
1302   //    if (SMARTY_PARTITION_SCANNER == null)
1303   //      SMARTY_PARTITION_SCANNER = new PHPPartitionScanner(IPHPPartitionScannerConstants.SMARTY_FILE);
1304   //    return SMARTY_PARTITION_SCANNER;
1305   //  }
1306   //
1307   //  /**
1308   //   * Return a scanner for creating xml partitions.
1309   //   */
1310   //  private PHPPartitionScanner getXMLPartitionScanner() {
1311   //    if (XML_PARTITION_SCANNER == null)
1312   //      XML_PARTITION_SCANNER = new PHPPartitionScanner(IPHPPartitionScannerConstants.XML_FILE);
1313   //    return XML_PARTITION_SCANNER;
1314   //  }
1315
1316 //  protected void initializeDocument(IDocument document, IEditorInput editorInput) {
1317 //    if (document != null) {
1318 //      JavaTextTools tools = PHPeclipsePlugin.getDefault().getJavaTextTools();
1319 //      IDocumentPartitioner partitioner = null;
1320 //      if (editorInput != null && editorInput instanceof FileEditorInput) {
1321 //        IFile file = (IFile) ((FileEditorInput) editorInput).getAdapter(IFile.class);
1322 //        String filename = file.getLocation().toString();
1323 //        String extension = filename.substring(filename.lastIndexOf("."), filename.length());
1324 //        partitioner = tools.createDocumentPartitioner(extension);
1325 //      } else {
1326 //        partitioner = tools.createDocumentPartitioner(".php");
1327 //      }
1328 //      document.setDocumentPartitioner(partitioner);
1329 //      partitioner.connect(document);
1330 //    }
1331 //  }
1332
1333   /*
1334    * @see org.eclipse.ui.texteditor.AbstractDocumentProvider#doResetDocument(java.lang.Object, org.eclipse.core.runtime.IProgressMonitor)
1335    */
1336 //  protected void doResetDocument(Object element, IProgressMonitor monitor) throws CoreException {
1337 //    if (element == null)
1338 //      return;
1339 //    
1340 //    ElementInfo elementInfo= getElementInfo(element);         
1341 //    if (elementInfo instanceof CompilationUnitInfo) {
1342 //      CompilationUnitInfo info= (CompilationUnitInfo) elementInfo;
1343 //      
1344 //      IDocument document;
1345 //      IStatus status= null;
1346 //      
1347 //      try {
1348 //        
1349 //        ICompilationUnit original= (ICompilationUnit) info.fCopy.getOriginalElement();
1350 //        IResource resource= original.getResource();
1351 //        if (resource instanceof IFile) {
1352 //          
1353 //          IFile file= (IFile) resource;
1354 //          
1355 //          try {
1356 //            refreshFile(file, monitor);
1357 //          } catch (CoreException x) {
1358 //            handleCoreException(x, PHPEditorMessages.getString("CompilationUnitDocumentProvider.error.resetDocument")); //$NON-NLS-1$
1359 //          }
1360 //          
1361 //          IFileEditorInput input= new FileEditorInput(file);
1362 //          document= super.createDocument(input);
1363 //          
1364 //        } else {
1365 //          document= createEmptyDocument();
1366 //        }
1367 //        
1368 //      } catch (CoreException x) {
1369 //        document= createEmptyDocument();
1370 //        status= x.getStatus();
1371 //      }
1372 //      
1373 //      fireElementContentAboutToBeReplaced(element);
1374 //      
1375 //      removeUnchangedElementListeners(element, info);
1376 //      info.fDocument.set(document.get());
1377 //      info.fCanBeSaved= false;
1378 //      info.fStatus= status;
1379 //      addUnchangedElementListeners(element, info);
1380 //      
1381 //      fireElementContentReplaced(element);
1382 //      fireElementDirtyStateChanged(element, false);
1383 //      
1384 //    } else {
1385 //      super.doResetDocument(element, monitor);
1386 //    }
1387 //  }
1388   
1389   /*
1390    * @see AbstractDocumentProvider#resetDocument(Object)
1391    */
1392 //  public void resetDocument(Object element) throws CoreException {
1393 //    if (element == null)
1394 //      return;
1395 //
1396 //    ElementInfo elementInfo = getElementInfo(element);
1397 //    if (elementInfo instanceof CompilationUnitInfo) {
1398 //      CompilationUnitInfo info = (CompilationUnitInfo) elementInfo;
1399 //
1400 //      IDocument document;
1401 //      IStatus status = null;
1402 //
1403 //      try {
1404 //
1405 //        ICompilationUnit original = (ICompilationUnit) info.fCopy.getOriginalElement();
1406 //        IResource resource = original.getResource();
1407 //        if (resource instanceof IFile) {
1408 //
1409 //          IFile file = (IFile) resource;
1410 //
1411 //          try {
1412 //            refreshFile(file);
1413 //          } catch (CoreException x) {
1414 //            handleCoreException(x, PHPEditorMessages.getString("PHPDocumentProvider.error.resetDocument")); //$NON-NLS-1$
1415 //          }
1416 //
1417 //          IFileEditorInput input = new FileEditorInput(file);
1418 //          document = super.createDocument(input);
1419 //
1420 //        } else {
1421 //          document = new Document();
1422 //        }
1423 //
1424 //      } catch (CoreException x) {
1425 //        document = new Document();
1426 //        status = x.getStatus();
1427 //      }
1428 //
1429 //      fireElementContentAboutToBeReplaced(element);
1430 //
1431 //      removeUnchangedElementListeners(element, info);
1432 //      info.fDocument.set(document.get());
1433 //      info.fCanBeSaved = false;
1434 //      info.fStatus = status;
1435 //      addUnchangedElementListeners(element, info);
1436 //
1437 //      fireElementContentReplaced(element);
1438 //      fireElementDirtyStateChanged(element, false);
1439 //
1440 //    } else {
1441 //      super.resetDocument(element);
1442 //    }
1443 //  }
1444   /**
1445          * Saves the content of the given document to the given element.
1446          * This is only performed when this provider initiated the save.
1447          * 
1448          * @param monitor the progress monitor
1449          * @param element the element to which to save
1450          * @param document the document to save
1451          * @param overwrite <code>true</code> if the save should be enforced
1452          */
1453   public void saveDocumentContent(IProgressMonitor monitor, Object element, IDocument document, boolean overwrite)
1454     throws CoreException {
1455
1456     if (!fIsAboutToSave)
1457       return;
1458
1459     if (element instanceof IFileEditorInput) {
1460       IFileEditorInput input = (IFileEditorInput) element;
1461       try {
1462         String encoding = getEncoding(element);
1463         if (encoding == null)
1464           encoding = ResourcesPlugin.getEncoding();
1465         InputStream stream = new ByteArrayInputStream(document.get().getBytes(encoding));
1466         IFile file = input.getFile();
1467         file.setContents(stream, overwrite, true, monitor);
1468       } catch (IOException x) {
1469         IStatus s = new Status(IStatus.ERROR, PHPeclipsePlugin.PLUGIN_ID, IStatus.OK, x.getMessage(), x);
1470         throw new CoreException(s);
1471       }
1472     }
1473   }
1474   /**
1475    * Returns the underlying resource for the given element.
1476    * 
1477    * @param the element
1478    * @return the underlying resource of the given element
1479    */
1480   public IResource getUnderlyingResource(Object element) {
1481     if (element instanceof IFileEditorInput) {
1482       IFileEditorInput input = (IFileEditorInput) element;
1483       return input.getFile();
1484     }
1485     return null;
1486   }
1487
1488         /*
1489          * @see org.eclipse.jdt.internal.ui.javaeditor.ICompilationUnitDocumentProvider#getWorkingCopy(java.lang.Object)
1490          */
1491         public ICompilationUnit getWorkingCopy(Object element) {
1492                 FileInfo fileInfo= getFileInfo(element);                
1493                 if (fileInfo instanceof CompilationUnitInfo) {
1494                         CompilationUnitInfo info= (CompilationUnitInfo) fileInfo;
1495                         return info.fCopy;
1496                 }
1497                 return null;
1498         }
1499
1500
1501   /*
1502          * @see org.eclipse.jdt.internal.ui.javaeditor.ICompilationUnitDocumentProvider#shutdown()
1503          */
1504         public void shutdown() {
1505                 PHPeclipsePlugin.getDefault().getPreferenceStore().removePropertyChangeListener(fPropertyListener);
1506                 Iterator e= getConnectedElementsIterator();
1507                 while (e.hasNext())
1508                         disconnect(e.next());
1509         }
1510
1511   /**
1512    * Returns the preference whether handling temporary problems is enabled.
1513    */
1514   protected boolean isHandlingTemporaryProblems() {
1515     IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
1516     return store.getBoolean(HANDLE_TEMPORARY_PROBLEMS);
1517   }
1518
1519   /**
1520          * Switches the state of problem acceptance according to the value in the preference store.
1521          */
1522         protected void enableHandlingTemporaryProblems() {
1523                 boolean enable= isHandlingTemporaryProblems();
1524                 for (Iterator iter= getFileInfosIterator(); iter.hasNext();) {
1525                         FileInfo info= (FileInfo) iter.next();
1526                         if (info.fModel instanceof IProblemRequestorExtension) {
1527                                 IProblemRequestorExtension  extension= (IProblemRequestorExtension) info.fModel;
1528                                 extension.setIsActive(enable);
1529                         }
1530                 }
1531         }
1532
1533   /**
1534    * Adds a listener that reports changes from all compilation unit annotation models.
1535    */
1536   public void addGlobalAnnotationModelListener(IAnnotationModelListener listener) {
1537     fGlobalAnnotationModelListener.addListener(listener);
1538   }
1539
1540   /**
1541    * Removes the listener.
1542    */
1543   public void removeGlobalAnnotationModelListener(IAnnotationModelListener listener) {
1544     fGlobalAnnotationModelListener.removeListener(listener);
1545   }
1546
1547 }