1 /***********************************************************************************************************************************
2 * Copyright (c) 2000, 2003 IBM Corporation and others. All rights reserved. This program and the accompanying materials are made
3 * available under the terms of the Common Public License v1.0 which accompanies this distribution, and is available at
4 * http://www.eclipse.org/legal/cpl-v10.html
6 * Contributors: IBM Corporation - initial API and implementation
7 **********************************************************************************************************************************/
9 package net.sourceforge.phpdt.internal.ui.text.java;
11 import net.sourceforge.phpdt.core.ICompilationUnit;
12 import net.sourceforge.phpdt.core.JavaModelException;
13 import net.sourceforge.phpdt.ui.IWorkingCopyManager;
14 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
16 import org.eclipse.core.runtime.IProgressMonitor;
17 import org.eclipse.core.runtime.NullProgressMonitor;
18 import org.eclipse.jface.text.IDocument;
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.reconciler.IReconcilingStrategyExtension;
23 import org.eclipse.jface.text.source.IAnnotationModel;
24 import org.eclipse.ui.texteditor.IDocumentProvider;
25 import org.eclipse.ui.texteditor.ITextEditor;
27 public class JavaReconcilingStrategy implements IReconcilingStrategy,
28 IReconcilingStrategyExtension {
30 private ITextEditor fEditor;
32 private IWorkingCopyManager fManager;
34 private IDocumentProvider fDocumentProvider;
36 private IProgressMonitor fProgressMonitor;
38 private boolean fNotify = true;
40 private IJavaReconcilingListener fJavaReconcilingListener;
42 private boolean fIsJavaReconcilingListener;
44 public JavaReconcilingStrategy(ITextEditor editor) {
46 fManager = PHPeclipsePlugin.getDefault().getWorkingCopyManager();
47 fDocumentProvider = PHPeclipsePlugin.getDefault()
48 .getCompilationUnitDocumentProvider();
49 fIsJavaReconcilingListener = fEditor instanceof IJavaReconcilingListener;
50 if (fIsJavaReconcilingListener)
51 fJavaReconcilingListener = (IJavaReconcilingListener) fEditor;
54 private IProblemRequestorExtension getProblemRequestorExtension() {
55 IAnnotationModel model = fDocumentProvider.getAnnotationModel(fEditor
57 if (model instanceof IProblemRequestorExtension)
58 return (IProblemRequestorExtension) model;
62 private void reconcile() {
65 // /* fix for missing cancel flag communication */
66 // IProblemRequestorExtension extension =
67 // getProblemRequestorExtension();
68 // if (extension != null)
69 // extension.setProgressMonitor(fProgressMonitor);
72 // // synchronized (unit) {
73 // // unit.reconcile(true, fProgressMonitor);
76 // Parser parser = new Parser();
77 // parser.initializeScanner();
78 // // actualParser.setFileToParse(fileToParse);
80 // fEditor.getDocumentProvider().getDocument(fEditor.getEditorInput()).get();
82 // parser.reportSyntaxError();
83 // // checkAndReportBracketAnomalies(parser.problemReporter());
85 // /* fix for missing cancel flag communication */
86 // if (extension != null)
87 // extension.setProgressMonitor(null);
89 // // update participants
91 // if (fEditor instanceof IReconcilingParticipant && fNotify &&
92 // !fProgressMonitor.isCanceled()) {
93 // IReconcilingParticipant p = (IReconcilingParticipant) fEditor;
100 // JDT implementation:
102 ICompilationUnit unit = fManager.getWorkingCopy(fEditor
107 /* fix for missing cancel flag communication */
108 IProblemRequestorExtension extension = getProblemRequestorExtension();
109 if (extension != null)
110 extension.setProgressMonitor(fProgressMonitor);
113 synchronized (unit) {
114 unit.reconcile(true, fProgressMonitor);
117 /* fix for missing cancel flag communication */
118 if (extension != null)
119 extension.setProgressMonitor(null);
121 // update participants
123 if (fEditor instanceof IReconcilingParticipant
124 && fNotify && !fProgressMonitor.isCanceled()) {
125 IReconcilingParticipant p = (IReconcilingParticipant) fEditor;
132 } catch (JavaModelException x) {
137 // Always notify listeners, see
138 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=55969 for the final
141 if (fIsJavaReconcilingListener) {
142 IProgressMonitor pm = fProgressMonitor;
144 pm = new NullProgressMonitor();
145 fJavaReconcilingListener.reconciled(null, !fNotify, pm);
155 * @see IReconcilingStrategy#reconcile(IRegion)
157 public void reconcile(IRegion partition) {
162 * @see IReconcilingStrategy#reconcile(DirtyRegion, IRegion)
164 public void reconcile(DirtyRegion dirtyRegion, IRegion subRegion) {
169 * @see IReconcilingStrategy#setDocument(IDocument)
171 public void setDocument(IDocument document) {
175 * @see IReconcilingStrategyExtension#setProgressMonitor(IProgressMonitor)
177 public void setProgressMonitor(IProgressMonitor monitor) {
178 fProgressMonitor = monitor;
182 * @see IReconcilingStrategyExtension#initialReconcile()
184 public void initialReconcile() {
189 * Tells this strategy whether to inform its participants.
192 * <code>true</code> if participant should be notified
194 public void notifyParticipants(boolean notify) {
199 * Tells this strategy whether to inform its listeners.
202 * <code>true</code> if listeners should be notified
204 public void notifyListeners(boolean notify) {
209 * Called before reconciling is started.
213 public void aboutToBeReconciled() {
214 if (fIsJavaReconcilingListener)
215 fJavaReconcilingListener.aboutToBeReconciled();