added syntax color for {} operators
[phpeclipse.git] / net.sourceforge.phpeclipse / 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.PHPeclipsePlugin;
18
19 import org.eclipse.jface.text.IRegion;
20 import org.eclipse.jface.text.reconciler.DirtyRegion;
21 import org.eclipse.jface.text.reconciler.IReconcilingStrategy;
22 import org.eclipse.jface.text.source.IAnnotationModel;
23 import org.eclipse.ui.texteditor.IDocumentProvider;
24 import org.eclipse.ui.texteditor.ITextEditor;
25
26 /**
27  * Reconciling strategy for Java code. This is a composite strategy containing the regular java model reconciler and the comment
28  * spell checking strategy.
29  * 
30  * @since 3.0
31  */
32 public class JavaCompositeReconcilingStrategy extends CompositeReconcilingStrategy {
33
34   private ITextEditor fEditor;
35
36   private JavaReconcilingStrategy fJavaStrategy;
37
38   /**
39    * Creates a new Java reconciling strategy.
40    * 
41    * @param editor
42    *          the editor of the strategy's reconciler
43    * @param documentPartitioning
44    *          the document partitioning this strategy uses for configuration
45    */
46   public JavaCompositeReconcilingStrategy(ITextEditor editor, String documentPartitioning) {
47     fEditor = editor;
48     fJavaStrategy = new JavaReconcilingStrategy(editor);
49     setReconcilingStrategies(new IReconcilingStrategy[] { fJavaStrategy,
50         new SpellReconcileStrategy(editor, documentPartitioning, PreferenceConstants.getPreferenceStore()) });
51   }
52
53   /**
54    * Returns the problem requestor for the editor's input element.
55    * 
56    * @return the problem requestor for the editor's input element
57    */
58   private IProblemRequestorExtension getProblemRequestorExtension() {
59     IDocumentProvider p = fEditor.getDocumentProvider();
60     if (p == null) {
61       try {
62         // work around for https://bugs.eclipse.org/bugs/show_bug.cgi?id=51522
63         p = PHPeclipsePlugin.getDefault().getCompilationUnitDocumentProvider();
64       } catch (NullPointerException npe) {
65         return null;
66       }
67     }
68     IAnnotationModel m = p.getAnnotationModel(fEditor.getEditorInput());
69     if (m instanceof IProblemRequestorExtension)
70       return (IProblemRequestorExtension) m;
71     return null;
72   }
73
74   /*
75    * @see org.eclipse.jface.text.reconciler.CompositeReconcilingStrategy#reconcile(org.eclipse.jface.text.reconciler.DirtyRegion,
76    *      org.eclipse.jface.text.IRegion)
77    */
78   public void reconcile(DirtyRegion dirtyRegion, IRegion subRegion) {
79     IProblemRequestorExtension e = getProblemRequestorExtension();
80     if (e != null) {
81       try {
82         e.beginReportingSequence();
83         super.reconcile(dirtyRegion, subRegion);
84       } finally {
85         e.endReportingSequence();
86       }
87     } else {
88       super.reconcile(dirtyRegion, subRegion);
89     }
90   }
91
92   /*
93    * @see org.eclipse.jface.text.reconciler.CompositeReconcilingStrategy#reconcile(org.eclipse.jface.text.IRegion)
94    */
95   public void reconcile(IRegion partition) {
96     IProblemRequestorExtension e = getProblemRequestorExtension();
97     if (e != null) {
98       try {
99         e.beginReportingSequence();
100         super.reconcile(partition);
101       } finally {
102         e.endReportingSequence();
103       }
104     } else {
105       super.reconcile(partition);
106     }
107   }
108
109   /**
110    * Tells this strategy whether to inform its listeners.
111    * 
112    * @param notify
113    *          <code>true</code> if listeners should be notified
114    */
115   public void notifyListeners(boolean notify) {
116     fJavaStrategy.notifyListeners(notify);
117   }
118
119   /*
120    * @see org.eclipse.jface.text.reconciler.CompositeReconcilingStrategy#initialReconcile()
121    */
122   public void initialReconcile() {
123     IProblemRequestorExtension e = getProblemRequestorExtension();
124     if (e != null) {
125       try {
126         e.beginReportingSequence();
127         super.initialReconcile();
128       } finally {
129         e.endReportingSequence();
130       }
131     } else {
132       super.initialReconcile();
133     }
134   }
135
136   /**
137    * Called before reconciling is started.
138    * 
139    * @since 3.0
140    */
141   public void aboutToBeReconciled() {
142     fJavaStrategy.aboutToBeReconciled();
143
144   }
145 }