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 the regular java model reconciler and the comment
28 * spell checking strategy.
32 public class JavaCompositeReconcilingStrategy extends CompositeReconcilingStrategy {
34 private ITextEditor fEditor;
36 private JavaReconcilingStrategy fJavaStrategy;
39 * Creates a new Java reconciling strategy.
42 * the editor of the strategy's reconciler
43 * @param documentPartitioning
44 * the document partitioning this strategy uses for configuration
46 public JavaCompositeReconcilingStrategy(ITextEditor editor, String documentPartitioning) {
48 fJavaStrategy = new JavaReconcilingStrategy(editor);
49 setReconcilingStrategies(new IReconcilingStrategy[] { fJavaStrategy,
50 new SpellReconcileStrategy(editor, documentPartitioning, PreferenceConstants.getPreferenceStore()) });
54 * Returns the problem requestor for the editor's input element.
56 * @return the problem requestor for the editor's input element
58 private IProblemRequestorExtension getProblemRequestorExtension() {
59 IDocumentProvider p = fEditor.getDocumentProvider();
62 // work around for https://bugs.eclipse.org/bugs/show_bug.cgi?id=51522
63 p = PHPeclipsePlugin.getDefault().getCompilationUnitDocumentProvider();
64 } catch (NullPointerException npe) {
68 IAnnotationModel m = p.getAnnotationModel(fEditor.getEditorInput());
69 if (m instanceof IProblemRequestorExtension)
70 return (IProblemRequestorExtension) m;
75 * @see org.eclipse.jface.text.reconciler.CompositeReconcilingStrategy#reconcile(org.eclipse.jface.text.reconciler.DirtyRegion,
76 * org.eclipse.jface.text.IRegion)
78 public void reconcile(DirtyRegion dirtyRegion, IRegion subRegion) {
79 IProblemRequestorExtension e = getProblemRequestorExtension();
82 e.beginReportingSequence();
83 super.reconcile(dirtyRegion, subRegion);
85 e.endReportingSequence();
88 super.reconcile(dirtyRegion, subRegion);
93 * @see org.eclipse.jface.text.reconciler.CompositeReconcilingStrategy#reconcile(org.eclipse.jface.text.IRegion)
95 public void reconcile(IRegion partition) {
96 IProblemRequestorExtension e = getProblemRequestorExtension();
99 e.beginReportingSequence();
100 super.reconcile(partition);
102 e.endReportingSequence();
105 super.reconcile(partition);
110 * Tells this strategy whether to inform its listeners.
113 * <code>true</code> if listeners should be notified
115 public void notifyListeners(boolean notify) {
116 fJavaStrategy.notifyListeners(notify);
120 * @see org.eclipse.jface.text.reconciler.CompositeReconcilingStrategy#initialReconcile()
122 public void initialReconcile() {
123 IProblemRequestorExtension e = getProblemRequestorExtension();
126 e.beginReportingSequence();
127 super.initialReconcile();
129 e.endReportingSequence();
132 super.initialReconcile();
137 * Called before reconciling is started.
141 public void aboutToBeReconciled() {
142 fJavaStrategy.aboutToBeReconciled();