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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.ui.text;
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;
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;
27 * Reconciling strategy for Java code. This is a composite strategy containing
28 * the regular java model reconciler and the comment spell checking strategy.
32 public class JavaCompositeReconcilingStrategy extends
33 CompositeReconcilingStrategy {
35 private ITextEditor fEditor;
37 private JavaReconcilingStrategy fJavaStrategy;
40 * Creates a new Java reconciling strategy.
43 * the editor of the strategy's reconciler
44 * @param documentPartitioning
45 * the document partitioning this strategy uses for configuration
47 public JavaCompositeReconcilingStrategy(ITextEditor editor,
48 String documentPartitioning) {
50 fJavaStrategy = new JavaReconcilingStrategy(editor);
51 setReconcilingStrategies(new IReconcilingStrategy[] {
53 new SpellReconcileStrategy(editor, documentPartitioning,
54 PreferenceConstants.getPreferenceStore()) });
58 * Returns the problem requestor for the editor's input element.
60 * @return the problem requestor for the editor's input element
62 private IProblemRequestorExtension getProblemRequestorExtension() {
63 IDocumentProvider p = fEditor.getDocumentProvider();
67 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=51522
68 p = PHPeclipsePlugin.getDefault()
69 .getCompilationUnitDocumentProvider();
70 } catch (NullPointerException npe) {
74 IAnnotationModel m = p.getAnnotationModel(fEditor.getEditorInput());
75 if (m instanceof IProblemRequestorExtension)
76 return (IProblemRequestorExtension) m;
81 * @see org.eclipse.jface.text.reconciler.CompositeReconcilingStrategy#reconcile(org.eclipse.jface.text.reconciler.DirtyRegion,
82 * org.eclipse.jface.text.IRegion)
84 public void reconcile(DirtyRegion dirtyRegion, IRegion subRegion) {
85 IProblemRequestorExtension e = getProblemRequestorExtension();
88 e.beginReportingSequence();
89 super.reconcile(dirtyRegion, subRegion);
91 e.endReportingSequence();
94 super.reconcile(dirtyRegion, subRegion);
99 * @see org.eclipse.jface.text.reconciler.CompositeReconcilingStrategy#reconcile(org.eclipse.jface.text.IRegion)
101 public void reconcile(IRegion partition) {
102 IProblemRequestorExtension e = getProblemRequestorExtension();
105 e.beginReportingSequence();
106 super.reconcile(partition);
108 e.endReportingSequence();
111 super.reconcile(partition);
116 * Tells this strategy whether to inform its listeners.
119 * <code>true</code> if listeners should be notified
121 public void notifyListeners(boolean notify) {
122 fJavaStrategy.notifyListeners(notify);
126 * @see org.eclipse.jface.text.reconciler.CompositeReconcilingStrategy#initialReconcile()
128 public void initialReconcile() {
129 IProblemRequestorExtension e = getProblemRequestorExtension();
132 e.beginReportingSequence();
133 super.initialReconcile();
135 e.endReportingSequence();
138 super.initialReconcile();
143 * Called before reconciling is started.
147 public void aboutToBeReconciled() {
148 fJavaStrategy.aboutToBeReconciled();