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.ui.WebUI;
15 //import net.sourceforge.phpeclipse.PHPeclipsePlugin;
17 import org.eclipse.core.runtime.IProgressMonitor;
18 import org.eclipse.core.runtime.NullProgressMonitor;
19 import org.eclipse.jface.text.IDocument;
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.reconciler.IReconcilingStrategyExtension;
24 import org.eclipse.jface.text.source.IAnnotationModel;
25 import org.eclipse.ui.texteditor.IDocumentProvider;
26 import org.eclipse.ui.texteditor.ITextEditor;
28 public class JavaReconcilingStrategy implements IReconcilingStrategy,
29 IReconcilingStrategyExtension {
31 private ITextEditor fEditor;
33 private IWorkingCopyManager fManager;
35 private IDocumentProvider fDocumentProvider;
37 private IProgressMonitor fProgressMonitor;
39 private boolean fNotify = true;
41 private IJavaReconcilingListener fJavaReconcilingListener;
43 private boolean fIsJavaReconcilingListener;
45 public JavaReconcilingStrategy(ITextEditor editor) {
47 fManager = WebUI.getDefault().getWorkingCopyManager();
48 fDocumentProvider = WebUI.getDefault()
49 .getCompilationUnitDocumentProvider();
50 fIsJavaReconcilingListener = fEditor instanceof IJavaReconcilingListener;
51 if (fIsJavaReconcilingListener)
52 fJavaReconcilingListener = (IJavaReconcilingListener) fEditor;
55 private IProblemRequestorExtension getProblemRequestorExtension() {
56 IAnnotationModel model = fDocumentProvider.getAnnotationModel(fEditor
58 if (model instanceof IProblemRequestorExtension)
59 return (IProblemRequestorExtension) model;
63 private void reconcile() {
66 // /* fix for missing cancel flag communication */
67 // IProblemRequestorExtension extension =
68 // getProblemRequestorExtension();
69 // if (extension != null)
70 // extension.setProgressMonitor(fProgressMonitor);
73 // // synchronized (unit) {
74 // // unit.reconcile(true, fProgressMonitor);
77 // Parser parser = new Parser();
78 // parser.initializeScanner();
79 // // actualParser.setFileToParse(fileToParse);
81 // fEditor.getDocumentProvider().getDocument(fEditor.getEditorInput()).get();
83 // parser.reportSyntaxError();
84 // // checkAndReportBracketAnomalies(parser.problemReporter());
86 // /* fix for missing cancel flag communication */
87 // if (extension != null)
88 // extension.setProgressMonitor(null);
90 // // update participants
92 // if (fEditor instanceof IReconcilingParticipant && fNotify &&
93 // !fProgressMonitor.isCanceled()) {
94 // IReconcilingParticipant p = (IReconcilingParticipant) fEditor;
101 // JDT implementation:
103 ICompilationUnit unit = fManager.getWorkingCopy(fEditor
108 /* fix for missing cancel flag communication */
109 IProblemRequestorExtension extension = getProblemRequestorExtension();
110 if (extension != null)
111 extension.setProgressMonitor(fProgressMonitor);
114 synchronized (unit) {
115 unit.reconcile(true, fProgressMonitor);
118 /* fix for missing cancel flag communication */
119 if (extension != null)
120 extension.setProgressMonitor(null);
122 // update participants
124 if (fEditor instanceof IReconcilingParticipant
125 && fNotify && !fProgressMonitor.isCanceled()) {
126 IReconcilingParticipant p = (IReconcilingParticipant) fEditor;
133 } catch (JavaModelException x) {
138 // Always notify listeners, see
139 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=55969 for the final
142 if (fIsJavaReconcilingListener) {
143 IProgressMonitor pm = fProgressMonitor;
145 pm = new NullProgressMonitor();
146 fJavaReconcilingListener.reconciled(null, !fNotify, pm);
156 * @see IReconcilingStrategy#reconcile(IRegion)
158 public void reconcile(IRegion partition) {
163 * @see IReconcilingStrategy#reconcile(DirtyRegion, IRegion)
165 public void reconcile(DirtyRegion dirtyRegion, IRegion subRegion) {
170 * @see IReconcilingStrategy#setDocument(IDocument)
172 public void setDocument(IDocument document) {
176 * @see IReconcilingStrategyExtension#setProgressMonitor(IProgressMonitor)
178 public void setProgressMonitor(IProgressMonitor monitor) {
179 fProgressMonitor = monitor;
183 * @see IReconcilingStrategyExtension#initialReconcile()
185 public void initialReconcile() {
190 * Tells this strategy whether to inform its participants.
193 * <code>true</code> if participant should be notified
195 // public void notifyParticipants(boolean notify) {
200 * Tells this strategy whether to inform its listeners.
203 * <code>true</code> if listeners should be notified
205 public void notifyListeners(boolean notify) {
210 * Called before reconciling is started.
214 public void aboutToBeReconciled() {
215 if (fIsJavaReconcilingListener)
216 fJavaReconcilingListener.aboutToBeReconciled();