Refactory: remove unused classes, imports, fields and methods.
[phpeclipse.git] / net.sourceforge.phpeclipse.ui / src / net / sourceforge / phpdt / internal / ui / text / JavaCompositeReconcilingStrategy.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpdt.internal.ui.text;
12
13 import net.sourceforge.phpdt.internal.ui.text.java.IProblemRequestorExtension;
14 import net.sourceforge.phpdt.internal.ui.text.java.JavaReconcilingStrategy;
15 import net.sourceforge.phpdt.internal.ui.text.spelling.SpellReconcileStrategy;
16 import net.sourceforge.phpdt.ui.PreferenceConstants;
17 import net.sourceforge.phpeclipse.ui.WebUI;
18 //import net.sourceforge.phpeclipse.PHPeclipsePlugin;
19
20 import org.eclipse.jface.text.IRegion;
21 import org.eclipse.jface.text.reconciler.DirtyRegion;
22 import org.eclipse.jface.text.reconciler.IReconcilingStrategy;
23 import org.eclipse.jface.text.source.IAnnotationModel;
24 import org.eclipse.ui.texteditor.IDocumentProvider;
25 import org.eclipse.ui.texteditor.ITextEditor;
26
27 /**
28  * Reconciling strategy for Java code. This is a composite strategy containing
29  * the regular java model reconciler and the comment spell checking strategy.
30  * 
31  * @since 3.0
32  */
33 public class JavaCompositeReconcilingStrategy extends
34                 CompositeReconcilingStrategy {
35
36         private ITextEditor fEditor;
37
38         private JavaReconcilingStrategy fJavaStrategy;
39
40         /**
41          * Creates a new Java reconciling strategy.
42          * 
43          * @param editor
44          *            the editor of the strategy's reconciler
45          * @param documentPartitioning
46          *            the document partitioning this strategy uses for configuration
47          */
48         public JavaCompositeReconcilingStrategy(ITextEditor editor,
49                         String documentPartitioning) {
50                 fEditor = editor;
51                 fJavaStrategy = new JavaReconcilingStrategy(editor);
52                 setReconcilingStrategies(new IReconcilingStrategy[] {
53                                 fJavaStrategy,
54                                 new SpellReconcileStrategy(editor, documentPartitioning,
55                                                 PreferenceConstants.getPreferenceStore()) });
56         }
57
58         /**
59          * Returns the problem requestor for the editor's input element.
60          * 
61          * @return the problem requestor for the editor's input element
62          */
63         private IProblemRequestorExtension getProblemRequestorExtension() {
64                 IDocumentProvider p = fEditor.getDocumentProvider();
65                 if (p == null) {
66                         try {
67                                 // work around for
68                                 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=51522
69                                 p = WebUI.getDefault()
70                                                 .getCompilationUnitDocumentProvider();
71                         } catch (NullPointerException npe) {
72                                 return null;
73                         }
74                 }
75                 IAnnotationModel m = p.getAnnotationModel(fEditor.getEditorInput());
76                 if (m instanceof IProblemRequestorExtension)
77                         return (IProblemRequestorExtension) m;
78                 return null;
79         }
80
81         /*
82          * @see org.eclipse.jface.text.reconciler.CompositeReconcilingStrategy#reconcile(org.eclipse.jface.text.reconciler.DirtyRegion,
83          *      org.eclipse.jface.text.IRegion)
84          */
85         public void reconcile(DirtyRegion dirtyRegion, IRegion subRegion) {
86                 IProblemRequestorExtension e = getProblemRequestorExtension();
87                 if (e != null) {
88                         try {
89                                 e.beginReportingSequence();
90                                 super.reconcile(dirtyRegion, subRegion);
91                         } finally {
92                                 e.endReportingSequence();
93                         }
94                 } else {
95                         super.reconcile(dirtyRegion, subRegion);
96                 }
97         }
98
99         /*
100          * @see org.eclipse.jface.text.reconciler.CompositeReconcilingStrategy#reconcile(org.eclipse.jface.text.IRegion)
101          */
102         public void reconcile(IRegion partition) {
103                 IProblemRequestorExtension e = getProblemRequestorExtension();
104                 if (e != null) {
105                         try {
106                                 e.beginReportingSequence();
107                                 super.reconcile(partition);
108                         } finally {
109                                 e.endReportingSequence();
110                         }
111                 } else {
112                         super.reconcile(partition);
113                 }
114         }
115
116         /**
117          * Tells this strategy whether to inform its listeners.
118          * 
119          * @param notify
120          *            <code>true</code> if listeners should be notified
121          */
122         public void notifyListeners(boolean notify) {
123                 fJavaStrategy.notifyListeners(notify);
124         }
125
126         /*
127          * @see org.eclipse.jface.text.reconciler.CompositeReconcilingStrategy#initialReconcile()
128          */
129         public void initialReconcile() {
130                 IProblemRequestorExtension e = getProblemRequestorExtension();
131                 if (e != null) {
132                         try {
133                                 e.beginReportingSequence();
134                                 super.initialReconcile();
135                         } finally {
136                                 e.endReportingSequence();
137                         }
138                 } else {
139                         super.initialReconcile();
140                 }
141         }
142
143         /**
144          * Called before reconciling is started.
145          * 
146          * @since 3.0
147          */
148         public void aboutToBeReconciled() {
149                 fJavaStrategy.aboutToBeReconciled();
150
151         }
152 }