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
12 Klaus Hartlage - www.eclipseproject.de
13 **********************************************************************/
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;
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;
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;
84 * The PHPDocumentProvider provides the IDocuments used by java editors.
87 public class PHPDocumentProvider extends TextFileDocumentProvider {
89 * Here for visibility issues only.
93 * Bundle of all required informations to allow working copy management.
96 * Bundle of all required informations to allow working copy management.
98 static protected class CompilationUnitInfo extends FileInfo {
99 public ICompilationUnit fCopy;
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
107 protected static class CompilationUnitAnnotationModel extends ResourceMarkerAnnotationModel implements IProblemRequestor, IProblemRequestorExtension {
109 private static class ProblemRequestorState {
110 boolean fInsideReportingSequence= false;
111 List fReportedProblems;
114 private ThreadLocal fProblemRequestorState= new ThreadLocal();
115 private int fStateCount= 0;
117 private ICompilationUnit fCompilationUnit;
118 private List fGeneratedAnnotations;
119 private IProgressMonitor fProgressMonitor;
120 private boolean fIsActive= false;
122 private ReverseMap fReverseMap= new ReverseMap();
123 private List fPreviouslyOverlaid= null;
124 private List fCurrentlyOverlaid= new ArrayList();
127 public CompilationUnitAnnotationModel(IResource resource) {
131 public void setCompilationUnit(ICompilationUnit unit) {
132 fCompilationUnit= unit;
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);
143 * @see org.eclipse.jface.text.source.AnnotationModel#createAnnotationModelEvent()
145 protected AnnotationModelEvent createAnnotationModelEvent() {
146 return new CompilationUnitAnnotationModelEvent(this, getResource());
149 protected Position createPositionFromProblem(IProblem problem) {
150 int start= problem.getSourceStart();
154 int length= problem.getSourceEnd() - problem.getSourceStart() + 1;
158 return new Position(start, length);
162 * @see IProblemRequestor#beginReporting()
164 public void beginReporting() {
165 ProblemRequestorState state= (ProblemRequestorState) fProblemRequestorState.get();
167 internalBeginReporting(false);
171 * @see org.eclipse.jdt.internal.ui.text.java.IProblemRequestorExtension#beginReportingSequence()
173 public void beginReportingSequence() {
174 ProblemRequestorState state= (ProblemRequestorState) fProblemRequestorState.get();
176 internalBeginReporting(true);
180 * Sets up the infrastructure necessary for problem reporting.
182 * @param insideReportingSequence <code>true</code> if this method
183 * call is issued from inside a reporting sequence
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);
199 * @see IProblemRequestor#acceptProblem(IProblem)
201 public void acceptProblem(IProblem problem) {
203 ProblemRequestorState state= (ProblemRequestorState) fProblemRequestorState.get();
205 state.fReportedProblems.add(problem);
210 * @see IProblemRequestor#endReporting()
212 public void endReporting() {
213 ProblemRequestorState state= (ProblemRequestorState) fProblemRequestorState.get();
214 if (state != null && !state.fInsideReportingSequence)
215 internalEndReporting(state);
219 * @see org.eclipse.jdt.internal.ui.text.java.IProblemRequestorExtension#endReportingSequence()
221 public void endReportingSequence() {
222 ProblemRequestorState state= (ProblemRequestorState) fProblemRequestorState.get();
223 if (state != null && state.fInsideReportingSequence)
224 internalEndReporting(state);
227 private void internalEndReporting(ProblemRequestorState state) {
229 synchronized(getLockObject()) {
231 stateCount= fStateCount;
232 fProblemRequestorState.set(null);
235 if (stateCount == 0 && isActive())
236 reportProblems(state.fReportedProblems);
240 * Signals the end of problem reporting.
242 private void reportProblems(List reportedProblems) {
243 if (fProgressMonitor != null && fProgressMonitor.isCanceled())
246 boolean temporaryProblemsChanged= false;
248 synchronized (getLockObject()) {
250 boolean isCanceled= false;
252 fPreviouslyOverlaid= fCurrentlyOverlaid;
253 fCurrentlyOverlaid= new ArrayList();
255 if (fGeneratedAnnotations.size() > 0) {
256 temporaryProblemsChanged= true;
257 removeAnnotations(fGeneratedAnnotations, false, true);
258 fGeneratedAnnotations.clear();
261 if (reportedProblems != null && reportedProblems.size() > 0) {
263 Iterator e= reportedProblems.iterator();
264 while (e.hasNext()) {
266 if (fProgressMonitor != null && fProgressMonitor.isCanceled()) {
271 IProblem problem= (IProblem) e.next();
272 Position position= createPositionFromProblem(problem);
273 if (position != null) {
276 ProblemAnnotation annotation= new ProblemAnnotation(problem, fCompilationUnit);
277 overlayMarkers(position, annotation);
278 addAnnotation(annotation, position, false);
279 fGeneratedAnnotations.add(annotation);
281 temporaryProblemsChanged= true;
282 } catch (BadLocationException x) {
283 // ignore invalid position
289 removeMarkerOverlays(isCanceled);
290 fPreviouslyOverlaid= null;
293 if (temporaryProblemsChanged)
297 private void removeMarkerOverlays(boolean 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);
310 * Overlays value with problem annotation.
311 * @param problemAnnotation
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);
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);
332 setOverlay(value, problemAnnotation);
337 * Tells this annotation model to collect temporary problems from now on.
339 private void startCollectingProblems() {
340 fGeneratedAnnotations= new ArrayList();
344 * Tells this annotation model to no longer collect temporary problems.
346 private void stopCollectingProblems() {
347 if (fGeneratedAnnotations != null)
348 removeAnnotations(fGeneratedAnnotations, true, true);
349 fGeneratedAnnotations= null;
353 * @see IProblemRequestor#isActive()
355 public boolean isActive() {
360 * @see IProblemRequestorExtension#setProgressMonitor(IProgressMonitor)
362 public void setProgressMonitor(IProgressMonitor monitor) {
363 fProgressMonitor= monitor;
367 * @see IProblemRequestorExtension#setIsActive(boolean)
369 public void setIsActive(boolean isActive) {
370 if (fIsActive != isActive) {
373 startCollectingProblems();
375 stopCollectingProblems();
379 private Object getAnnotations(Position position) {
380 return fReverseMap.get(position);
384 * @see AnnotationModel#addAnnotation(Annotation, Position, boolean)
386 protected void addAnnotation(Annotation annotation, Position position, boolean fireModelChanged) throws BadLocationException {
387 super.addAnnotation(annotation, position, fireModelChanged);
389 Object cached= fReverseMap.get(position);
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);
398 list.add(annotation);
399 fReverseMap.put(position, list);
404 * @see AnnotationModel#removeAllAnnotations(boolean)
406 protected void removeAllAnnotations(boolean fireModelChanged) {
407 super.removeAllAnnotations(fireModelChanged);
412 * @see AnnotationModel#removeAnnotation(Annotation, boolean)
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));
424 } else if (cached instanceof Annotation) {
425 fReverseMap.remove(position);
427 super.removeAnnotation(annotation, fireModelChanged);
433 protected static class GlobalAnnotationModelListener implements IAnnotationModelListener, IAnnotationModelListenerExtension {
435 private ListenerList fListenerList;
437 public GlobalAnnotationModelListener() {
438 fListenerList = new ListenerList();
441 public void addListener(IAnnotationModelListener listener) {
442 fListenerList.add(listener);
446 * @see IAnnotationModelListenerExtension#modelChanged(AnnotationModelEvent)
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);
459 * @see IAnnotationModelListener#modelChanged(IAnnotationModel)
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);
468 public void removeListener(IAnnotationModelListener listener) {
469 fListenerList.remove(listener);
474 * Annotation representating an <code>IProblem</code>.
476 static protected class ProblemAnnotation extends Annotation implements IJavaAnnotation, IAnnotationPresentation {
478 private static final String SPELLING_ANNOTATION_TYPE= "org.eclipse.ui.workbench.texteditor.spelling";
480 //XXX: To be fully correct these constants should be non-static
482 * The layer in which task problem annotations are located.
484 private static final int TASK_LAYER;
486 * The layer in which info problem annotations are located.
488 private static final int INFO_LAYER;
490 * The layer in which warning problem annotations representing are located.
492 private static final int WARNING_LAYER;
494 * The layer in which error problem annotations representing are located.
496 private static final int ERROR_LAYER;
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$
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;
512 return IAnnotationAccessExtension.DEFAULT_LAYER + 1;
515 // private static Image fgQuickFixImage;
516 // private static Image fgQuickFixErrorImage;
517 // private static boolean fgQuickFixImagesInitialized= false;
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;
526 public ProblemAnnotation(IProblem problem, ICompilationUnit cu) {
529 fCompilationUnit= cu;
531 // if (SpellProblem.Spelling == fProblem.getID()) {
532 // setType(SPELLING_ANNOTATION_TYPE);
533 // fLayer= WARNING_LAYER;
535 if (IProblem.Task == fProblem.getID()) {
536 setType(JavaMarkerAnnotation.TASK_ANNOTATION_TYPE);
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);
545 setType(JavaMarkerAnnotation.INFO_ANNOTATION_TYPE);
551 * @see org.eclipse.jface.text.source.IAnnotationPresentation#getLayer()
553 public int getLayer() {
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;
566 // if (JavaMarkerAnnotation.ERROR_ANNOTATION_TYPE.equals(getType()))
567 // fImage= fgQuickFixErrorImage;
569 // fImage= fgQuickFixImage;
571 // fQuickFixImagesInitialized= true;
575 private boolean indicateQuixFixableProblems() {
576 return PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_CORRECTION_INDICATION);
580 * @see Annotation#paint
582 public void paint(GC gc, Canvas canvas, Rectangle r) {
585 ImageUtilities.drawImage(fImage, gc, canvas, r, SWT.CENTER, SWT.TOP);
588 * @see IJavaAnnotation#getImage(Display)
590 public Image getImage(Display display) {
596 * @see IJavaAnnotation#getMessage()
598 public String getText() {
599 return fProblem.getMessage();
603 * @see IJavaAnnotation#getArguments()
605 public String[] getArguments() {
606 return isProblem() ? fProblem.getArguments() : null;
610 * @see IJavaAnnotation#getId()
613 return fProblem.getID();
617 * @see IJavaAnnotation#isProblem()
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);
627 * @see IJavaAnnotation#hasOverlay()
629 public boolean hasOverlay() {
634 * @see org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation#getOverlay()
636 public IJavaAnnotation getOverlay() {
641 * @see IJavaAnnotation#addOverlaid(IJavaAnnotation)
643 public void addOverlaid(IJavaAnnotation annotation) {
644 if (fOverlaids == null)
645 fOverlaids= new ArrayList(1);
646 fOverlaids.add(annotation);
650 * @see IJavaAnnotation#removeOverlaid(IJavaAnnotation)
652 public void removeOverlaid(IJavaAnnotation annotation) {
653 if (fOverlaids != null) {
654 fOverlaids.remove(annotation);
655 if (fOverlaids.size() == 0)
661 * @see IJavaAnnotation#getOverlaidIterator()
663 public Iterator getOverlaidIterator() {
664 if (fOverlaids != null)
665 return fOverlaids.iterator();
670 * @see org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation#getCompilationUnit()
672 public ICompilationUnit getCompilationUnit() {
673 return fCompilationUnit;
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
684 protected static class ReverseMap {
690 private int fAnchor = 0;
692 private List fList = new ArrayList(2);
694 public ReverseMap() {
697 public void clear() {
701 public Object get(Position position) {
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)) {
716 for (int i = 0; i < fAnchor; i++) {
717 entry = (Entry) fList.get(i);
718 if (entry.fPosition.equals(position)) {
727 private int getIndex(Position position) {
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))
738 public void put(Position position, Object value) {
739 int index = getIndex(position);
741 Entry entry = new Entry();
742 entry.fPosition = position;
743 entry.fValue = value;
746 Entry entry = (Entry) fList.get(index);
747 entry.fValue = value;
751 public void remove(Position position) {
752 int index = getIndex(position);
759 * Document that can also be used by a background reconciler.
761 protected static class PartiallySynchronizedDocument extends Document {
764 * @see IDocumentExtension#startSequentialRewrite(boolean)
766 synchronized public void startSequentialRewrite(boolean normalized) {
767 super.startSequentialRewrite(normalized);
771 * @see IDocumentExtension#stopSequentialRewrite()
773 synchronized public void stopSequentialRewrite() {
774 super.stopSequentialRewrite();
778 * @see IDocument#get()
780 synchronized public String get() {
785 * @see IDocument#get(int, int)
787 synchronized public String get(int offset, int length) throws BadLocationException {
788 return super.get(offset, length);
792 * @see IDocument#getChar(int)
794 synchronized public char getChar(int offset) throws BadLocationException {
795 return super.getChar(offset);
799 * @see IDocument#replace(int, int, String)
801 synchronized public void replace(int offset, int length, String text) throws BadLocationException {
802 super.replace(offset, length, text);
806 * @see IDocument#set(String)
808 synchronized public void set(String text) {
813 // private static PHPPartitionScanner HTML_PARTITION_SCANNER = null;
815 // private static PHPPartitionScanner PHP_PARTITION_SCANNER = null;
816 // private static PHPPartitionScanner SMARTY_PARTITION_SCANNER = null;
818 // // private final static String[] TYPES= new String[] { PHPPartitionScanner.PHP, PHPPartitionScanner.JAVA_DOC, PHPPartitionScanner.JAVA_MULTILINE_COMMENT };
819 // private final static String[] TYPES =
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;
831 /* Preference key for temporary problems */
832 private final static String HANDLE_TEMPORARY_PROBLEMS = PreferenceConstants.EDITOR_EVALUTE_TEMPORARY_PROBLEMS;
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;
841 /** annotation model listener added to all created CU annotation models */
842 private GlobalAnnotationModelListener fGlobalAnnotationModelListener;
844 public PHPDocumentProvider() {
845 setParentDocumentProvider(new TextFileDocumentProvider(new JavaStorageDocumentProvider()));
847 fPropertyListener= new IPropertyChangeListener() {
848 public void propertyChange(PropertyChangeEvent event) {
849 if (HANDLE_TEMPORARY_PROBLEMS.equals(event.getProperty()))
850 enableHandlingTemporaryProblems();
853 fGlobalAnnotationModelListener= new GlobalAnnotationModelListener();
854 PHPeclipsePlugin.getDefault().getPreferenceStore().addPropertyChangeListener(fPropertyListener);
859 * Sets the document provider's save policy.
861 public void setSavePolicy(ISavePolicy savePolicy) {
862 fSavePolicy = savePolicy;
866 * Creates a compilation unit from the given file.
868 * @param file the file from which to create the compilation unit
870 protected ICompilationUnit createCompilationUnit(IFile file) {
871 Object element = JavaCore.create(file);
872 if (element instanceof ICompilationUnit)
873 return (ICompilationUnit) element;
879 * @see org.eclipse.ui.editors.text.TextFileDocumentProvider#createEmptyFileInfo()
881 protected FileInfo createEmptyFileInfo() {
882 return new CompilationUnitInfo();
885 * @see org.eclipse.ui.editors.text.TextFileDocumentProvider#createAnnotationModel(org.eclipse.core.resources.IFile)
887 protected IAnnotationModel createAnnotationModel(IFile file) {
888 return new CompilationUnitAnnotationModel(file);
891 * @see AbstractDocumentProvider#createElementInfo(Object)
893 // protected ElementInfo createElementInfo(Object element) throws CoreException {
895 // if (!(element instanceof IFileEditorInput))
896 // return super.createElementInfo(element);
898 // IFileEditorInput input = (IFileEditorInput) element;
899 // ICompilationUnit original = createCompilationUnit(input.getFile());
900 // if (original != null) {
905 // refreshFile(input.getFile());
906 // } catch (CoreException x) {
907 // handleCoreException(x, PHPEditorMessages.getString("PHPDocumentProvider.error.createElementInfo")); //$NON-NLS-1$
910 // IAnnotationModel m = createCompilationUnitAnnotationModel(input);
911 // IProblemRequestor r = m instanceof IProblemRequestor ? (IProblemRequestor) m : null;
912 // ICompilationUnit c = (ICompilationUnit) original.getSharedWorkingCopy(getProgressMonitor(), fBufferFactory, r);
914 // DocumentAdapter a = null;
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);
922 // _FileSynchronizer f = new _FileSynchronizer(input);
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);
930 // if (r instanceof IProblemRequestorExtension) {
931 // IProblemRequestorExtension extension = (IProblemRequestorExtension) r;
932 // extension.setIsActive(isHandlingTemporaryProblems());
934 // m.addAnnotationModelListener(fGlobalAnnotationModelListener);
938 // } catch (JavaModelException x) {
939 // throw new CoreException(x.getStatus());
942 // return super.createElementInfo(element);
947 * @see AbstractDocumentProvider#disposeElementInfo(Object, ElementInfo)
949 // protected void disposeElementInfo(Object element, ElementInfo info) {
951 // if (info instanceof CompilationUnitInfo) {
952 // CompilationUnitInfo cuInfo = (CompilationUnitInfo) info;
953 // cuInfo.fCopy.destroy();
954 // cuInfo.fModel.removeAnnotationModelListener(fGlobalAnnotationModelListener);
957 // super.disposeElementInfo(element, info);
961 * @see AbstractDocumentProvider#doSaveDocument(IProgressMonitor, Object, IDocument, boolean)
963 // protected void doSaveDocument(IProgressMonitor monitor, Object element, IDocument document, boolean overwrite)
964 // throws CoreException {
966 // ElementInfo elementInfo = getElementInfo(element);
967 // if (elementInfo instanceof CompilationUnitInfo) {
968 // CompilationUnitInfo info = (CompilationUnitInfo) elementInfo;
970 // // update structure, assumes lock on info.fCopy
971 // info.fCopy.reconcile();
973 // ICompilationUnit original = (ICompilationUnit) info.fCopy.getOriginalElement();
974 // IResource resource = original.getResource();
976 // if (resource == null) {
977 // // underlying resource has been deleted, just recreate file, ignore the rest
978 // super.doSaveDocument(monitor, element, document, overwrite);
982 // if (resource != null && !overwrite)
983 // checkSynchronizationState(info.fModificationStamp, resource);
985 // if (fSavePolicy != null)
986 // fSavePolicy.preSave(info.fCopy);
988 // // inform about the upcoming content change
989 // fireElementStateChanging(element);
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);
998 // } catch (RuntimeException x) {
999 // // inform about the failure
1000 // fireElementStateChangeFailed(element);
1003 // fIsAboutToSave = false;
1006 // // If here, the dirty state of the editor will change to "not dirty".
1007 // // Thus, the state changing flag will be reset.
1009 // AbstractMarkerAnnotationModel model = (AbstractMarkerAnnotationModel) info.fModel;
1010 // model.updateMarkers(info.fDocument);
1012 // if (resource != null)
1013 // info.setModificationStamp(computeModificationStamp(resource));
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);
1028 // super.doSaveDocument(monitor, element, document, overwrite);
1033 * @see org.eclipse.ui.editors.text.TextFileDocumentProvider#createFileInfo(java.lang.Object)
1035 protected FileInfo createFileInfo(Object element) throws CoreException {
1036 if (!(element instanceof IFileEditorInput))
1039 IFileEditorInput input= (IFileEditorInput) element;
1040 ICompilationUnit original= createCompilationUnit(input.getFile());
1041 if (original == null)
1044 FileInfo info= super.createFileInfo(element);
1045 if (!(info instanceof CompilationUnitInfo))
1048 CompilationUnitInfo cuInfo= (CompilationUnitInfo) info;
1049 setUpSynchronization(cuInfo);
1051 IProblemRequestor requestor= cuInfo.fModel instanceof IProblemRequestor ? (IProblemRequestor) cuInfo.fModel : null;
1053 original.becomeWorkingCopy(requestor, getProgressMonitor());
1054 cuInfo.fCopy= original;
1056 if (cuInfo.fModel instanceof CompilationUnitAnnotationModel) {
1057 CompilationUnitAnnotationModel model= (CompilationUnitAnnotationModel) cuInfo.fModel;
1058 model.setCompilationUnit(cuInfo.fCopy);
1061 if (cuInfo.fModel != null)
1062 cuInfo.fModel.addAnnotationModelListener(fGlobalAnnotationModelListener);
1064 if (requestor instanceof IProblemRequestorExtension) {
1065 IProblemRequestorExtension extension= (IProblemRequestorExtension) requestor;
1066 extension.setIsActive(isHandlingTemporaryProblems());
1072 private void setUpSynchronization(CompilationUnitInfo cuInfo) {
1073 IDocument document= cuInfo.fTextFileBuffer.getDocument();
1074 IAnnotationModel model= cuInfo.fModel;
1076 if (document instanceof ISynchronizable && model instanceof ISynchronizable) {
1077 Object lock= ((ISynchronizable) document).getLockObject();
1078 ((ISynchronizable) model).setLockObject(lock);
1083 * @see org.eclipse.ui.editors.text.TextFileDocumentProvider#disposeFileInfo(java.lang.Object, org.eclipse.ui.editors.text.TextFileDocumentProvider.FileInfo)
1085 protected void disposeFileInfo(Object element, FileInfo info) {
1086 if (info instanceof CompilationUnitInfo) {
1087 CompilationUnitInfo cuInfo= (CompilationUnitInfo) info;
1090 cuInfo.fCopy.discardWorkingCopy();
1091 } catch (JavaModelException x) {
1092 handleCoreException(x, x.getMessage());
1095 if (cuInfo.fModel != null)
1096 cuInfo.fModel.removeAnnotationModelListener(fGlobalAnnotationModelListener);
1098 super.disposeFileInfo(element, info);
1101 protected void commitWorkingCopy(IProgressMonitor monitor, Object element, CompilationUnitInfo info, boolean overwrite) throws CoreException {
1103 synchronized (info.fCopy) {
1104 info.fCopy.reconcile();
1107 IDocument document= info.fTextFileBuffer.getDocument();
1108 IResource resource= info.fCopy.getResource();
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);
1117 if (fSavePolicy != null)
1118 fSavePolicy.preSave(info.fCopy);
1122 fIsAboutToSave= true;
1123 info.fCopy.commitWorkingCopy(overwrite, monitor);
1125 } catch (CoreException x) {
1126 // inform about the failure
1127 fireElementStateChangeFailed(element);
1129 } catch (RuntimeException x) {
1130 // inform about the failure
1131 fireElementStateChangeFailed(element);
1134 fIsAboutToSave= false;
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);
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);
1159 * @see org.eclipse.ui.editors.text.TextFileDocumentProvider#createSaveOperation(java.lang.Object, org.eclipse.jface.text.IDocument, boolean)
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() {
1166 * @see org.eclipse.ui.editors.text.TextFileDocumentProvider.DocumentProviderOperation#execute(org.eclipse.core.runtime.IProgressMonitor)
1168 protected void execute(IProgressMonitor monitor) throws CoreException {
1169 commitWorkingCopy(monitor, element, (CompilationUnitInfo) info, overwrite);
1172 * @see org.eclipse.ui.editors.text.TextFileDocumentProvider.DocumentProviderOperation#getSchedulingRule()
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);
1181 return ruleFactory.modifyRule(file);
1191 * Method declared on AbstractDocumentProvider
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);
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")) {
1210 // // partitioner = createHTMLPartitioner();
1211 // // } else if (extension.equalsIgnoreCase(".xml")) {
1213 // // partitioner = createXMLPartitioner();
1214 // // } else if (extension.equalsIgnoreCase(".js")) {
1216 // // partitioner = createJavaScriptPartitioner();
1217 // // } else if (extension.equalsIgnoreCase(".css")) {
1218 // // // cascading style sheets
1219 // // partitioner = createCSSPartitioner();
1220 // // } else if (extension.equalsIgnoreCase(".tpl")) {
1222 // // partitioner = createSmartyPartitioner();
1223 // // } else if (extension.equalsIgnoreCase(".inc")) {
1224 // // // php include files ?
1225 // // partitioner = createIncludePartitioner();
1229 // // if (partitioner == null) {
1230 // // partitioner = createPHPPartitioner();
1232 // // document.setDocumentPartitioner(partitioner);
1233 // // partitioner.connect(document);
1241 // * Return a partitioner for .html files.
1243 // private IDocumentPartitioner createHTMLPartitioner() {
1244 // return new DefaultPartitioner(getHTMLPartitionScanner(), TYPES);
1247 // private IDocumentPartitioner createIncludePartitioner() {
1248 // return new DefaultPartitioner(getPHPPartitionScanner(), TYPES);
1251 // private IDocumentPartitioner createJavaScriptPartitioner() {
1252 // return new DefaultPartitioner(getHTMLPartitionScanner(), TYPES);
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.
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
1262 public ILineTracker createLineTracker(Object element) {
1263 return new DefaultLineTracker();
1267 // * Return a partitioner for .php files.
1269 // private IDocumentPartitioner createPHPPartitioner() {
1270 // return new DefaultPartitioner(getPHPPartitionScanner(), TYPES);
1273 // private IDocumentPartitioner createSmartyPartitioner() {
1274 // return new DefaultPartitioner(getSmartyPartitionScanner(), TYPES);
1277 // private IDocumentPartitioner createXMLPartitioner() {
1278 // return new DefaultPartitioner(getXMLPartitionScanner(), TYPES);
1282 // * Return a scanner for creating html partitions.
1284 // private PHPPartitionScanner getHTMLPartitionScanner() {
1285 // if (HTML_PARTITION_SCANNER == null)
1286 // HTML_PARTITION_SCANNER = new PHPPartitionScanner(IPHPPartitionScannerConstants.HTML_FILE);
1287 // return HTML_PARTITION_SCANNER;
1290 // * Return a scanner for creating php partitions.
1292 // private PHPPartitionScanner getPHPPartitionScanner() {
1293 // if (PHP_PARTITION_SCANNER == null)
1294 // PHP_PARTITION_SCANNER = new PHPPartitionScanner(IPHPPartitionScannerConstants.PHP_FILE);
1295 // return PHP_PARTITION_SCANNER;
1299 // * Return a scanner for creating smarty partitions.
1301 // private PHPPartitionScanner getSmartyPartitionScanner() {
1302 // if (SMARTY_PARTITION_SCANNER == null)
1303 // SMARTY_PARTITION_SCANNER = new PHPPartitionScanner(IPHPPartitionScannerConstants.SMARTY_FILE);
1304 // return SMARTY_PARTITION_SCANNER;
1308 // * Return a scanner for creating xml partitions.
1310 // private PHPPartitionScanner getXMLPartitionScanner() {
1311 // if (XML_PARTITION_SCANNER == null)
1312 // XML_PARTITION_SCANNER = new PHPPartitionScanner(IPHPPartitionScannerConstants.XML_FILE);
1313 // return XML_PARTITION_SCANNER;
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);
1326 // partitioner = tools.createDocumentPartitioner(".php");
1328 // document.setDocumentPartitioner(partitioner);
1329 // partitioner.connect(document);
1334 * @see org.eclipse.ui.texteditor.AbstractDocumentProvider#doResetDocument(java.lang.Object, org.eclipse.core.runtime.IProgressMonitor)
1336 // protected void doResetDocument(Object element, IProgressMonitor monitor) throws CoreException {
1337 // if (element == null)
1340 // ElementInfo elementInfo= getElementInfo(element);
1341 // if (elementInfo instanceof CompilationUnitInfo) {
1342 // CompilationUnitInfo info= (CompilationUnitInfo) elementInfo;
1344 // IDocument document;
1345 // IStatus status= null;
1349 // ICompilationUnit original= (ICompilationUnit) info.fCopy.getOriginalElement();
1350 // IResource resource= original.getResource();
1351 // if (resource instanceof IFile) {
1353 // IFile file= (IFile) resource;
1356 // refreshFile(file, monitor);
1357 // } catch (CoreException x) {
1358 // handleCoreException(x, PHPEditorMessages.getString("CompilationUnitDocumentProvider.error.resetDocument")); //$NON-NLS-1$
1361 // IFileEditorInput input= new FileEditorInput(file);
1362 // document= super.createDocument(input);
1365 // document= createEmptyDocument();
1368 // } catch (CoreException x) {
1369 // document= createEmptyDocument();
1370 // status= x.getStatus();
1373 // fireElementContentAboutToBeReplaced(element);
1375 // removeUnchangedElementListeners(element, info);
1376 // info.fDocument.set(document.get());
1377 // info.fCanBeSaved= false;
1378 // info.fStatus= status;
1379 // addUnchangedElementListeners(element, info);
1381 // fireElementContentReplaced(element);
1382 // fireElementDirtyStateChanged(element, false);
1385 // super.doResetDocument(element, monitor);
1390 * @see AbstractDocumentProvider#resetDocument(Object)
1392 // public void resetDocument(Object element) throws CoreException {
1393 // if (element == null)
1396 // ElementInfo elementInfo = getElementInfo(element);
1397 // if (elementInfo instanceof CompilationUnitInfo) {
1398 // CompilationUnitInfo info = (CompilationUnitInfo) elementInfo;
1400 // IDocument document;
1401 // IStatus status = null;
1405 // ICompilationUnit original = (ICompilationUnit) info.fCopy.getOriginalElement();
1406 // IResource resource = original.getResource();
1407 // if (resource instanceof IFile) {
1409 // IFile file = (IFile) resource;
1412 // refreshFile(file);
1413 // } catch (CoreException x) {
1414 // handleCoreException(x, PHPEditorMessages.getString("PHPDocumentProvider.error.resetDocument")); //$NON-NLS-1$
1417 // IFileEditorInput input = new FileEditorInput(file);
1418 // document = super.createDocument(input);
1421 // document = new Document();
1424 // } catch (CoreException x) {
1425 // document = new Document();
1426 // status = x.getStatus();
1429 // fireElementContentAboutToBeReplaced(element);
1431 // removeUnchangedElementListeners(element, info);
1432 // info.fDocument.set(document.get());
1433 // info.fCanBeSaved = false;
1434 // info.fStatus = status;
1435 // addUnchangedElementListeners(element, info);
1437 // fireElementContentReplaced(element);
1438 // fireElementDirtyStateChanged(element, false);
1441 // super.resetDocument(element);
1445 * Saves the content of the given document to the given element.
1446 * This is only performed when this provider initiated the save.
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
1453 public void saveDocumentContent(IProgressMonitor monitor, Object element, IDocument document, boolean overwrite)
1454 throws CoreException {
1456 if (!fIsAboutToSave)
1459 if (element instanceof IFileEditorInput) {
1460 IFileEditorInput input = (IFileEditorInput) element;
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);
1475 * Returns the underlying resource for the given element.
1477 * @param the element
1478 * @return the underlying resource of the given element
1480 public IResource getUnderlyingResource(Object element) {
1481 if (element instanceof IFileEditorInput) {
1482 IFileEditorInput input = (IFileEditorInput) element;
1483 return input.getFile();
1489 * @see org.eclipse.jdt.internal.ui.javaeditor.ICompilationUnitDocumentProvider#getWorkingCopy(java.lang.Object)
1491 public ICompilationUnit getWorkingCopy(Object element) {
1492 FileInfo fileInfo= getFileInfo(element);
1493 if (fileInfo instanceof CompilationUnitInfo) {
1494 CompilationUnitInfo info= (CompilationUnitInfo) fileInfo;
1502 * @see org.eclipse.jdt.internal.ui.javaeditor.ICompilationUnitDocumentProvider#shutdown()
1504 public void shutdown() {
1505 PHPeclipsePlugin.getDefault().getPreferenceStore().removePropertyChangeListener(fPropertyListener);
1506 Iterator e= getConnectedElementsIterator();
1508 disconnect(e.next());
1512 * Returns the preference whether handling temporary problems is enabled.
1514 protected boolean isHandlingTemporaryProblems() {
1515 IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
1516 return store.getBoolean(HANDLE_TEMPORARY_PROBLEMS);
1520 * Switches the state of problem acceptance according to the value in the preference store.
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);
1534 * Adds a listener that reports changes from all compilation unit annotation models.
1536 public void addGlobalAnnotationModelListener(IAnnotationModelListener listener) {
1537 fGlobalAnnotationModelListener.addListener(listener);
1541 * Removes the listener.
1543 public void removeGlobalAnnotationModelListener(IAnnotationModelListener listener) {
1544 fGlobalAnnotationModelListener.removeListener(listener);