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, IReconcilingStrategyExtension {
29 private ITextEditor fEditor;
31 private IWorkingCopyManager fManager;
33 private IDocumentProvider fDocumentProvider;
35 private IProgressMonitor fProgressMonitor;
37 private boolean fNotify = true;
39 private IJavaReconcilingListener fJavaReconcilingListener;
41 private boolean fIsJavaReconcilingListener;
43 public JavaReconcilingStrategy(ITextEditor editor) {
45 fManager = PHPeclipsePlugin.getDefault().getWorkingCopyManager();
46 fDocumentProvider = PHPeclipsePlugin.getDefault().getCompilationUnitDocumentProvider();
47 fIsJavaReconcilingListener = fEditor instanceof IJavaReconcilingListener;
48 if (fIsJavaReconcilingListener)
49 fJavaReconcilingListener = (IJavaReconcilingListener) fEditor;
52 private IProblemRequestorExtension getProblemRequestorExtension() {
53 IAnnotationModel model = fDocumentProvider.getAnnotationModel(fEditor.getEditorInput());
54 if (model instanceof IProblemRequestorExtension)
55 return (IProblemRequestorExtension) model;
59 private void reconcile() {
62 // /* fix for missing cancel flag communication */
63 // IProblemRequestorExtension extension = getProblemRequestorExtension();
64 // if (extension != null)
65 // extension.setProgressMonitor(fProgressMonitor);
68 //// synchronized (unit) {
69 //// unit.reconcile(true, fProgressMonitor);
72 // Parser parser = new Parser();
73 // parser.initializeScanner();
74 // // actualParser.setFileToParse(fileToParse);
75 // String text = fEditor.getDocumentProvider().getDocument(fEditor.getEditorInput()).get();
77 // parser.reportSyntaxError();
78 //// checkAndReportBracketAnomalies(parser.problemReporter());
80 // /* fix for missing cancel flag communication */
81 // if (extension != null)
82 // extension.setProgressMonitor(null);
84 // // update participants
86 // if (fEditor instanceof IReconcilingParticipant && fNotify && !fProgressMonitor.isCanceled()) {
87 // IReconcilingParticipant p = (IReconcilingParticipant) fEditor;
94 // JDT implementation:
96 ICompilationUnit unit = fManager.getWorkingCopy(fEditor.getEditorInput());
100 /* fix for missing cancel flag communication */
101 IProblemRequestorExtension extension = getProblemRequestorExtension();
102 if (extension != null)
103 extension.setProgressMonitor(fProgressMonitor);
106 synchronized (unit) {
107 unit.reconcile(true, fProgressMonitor);
110 /* fix for missing cancel flag communication */
111 if (extension != null)
112 extension.setProgressMonitor(null);
114 // update participants
116 if (fEditor instanceof IReconcilingParticipant && fNotify && !fProgressMonitor.isCanceled()) {
117 IReconcilingParticipant p = (IReconcilingParticipant) fEditor;
124 } catch (JavaModelException x) {
129 // Always notify listeners, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=55969 for the final solution
131 if (fIsJavaReconcilingListener) {
132 IProgressMonitor pm = fProgressMonitor;
134 pm = new NullProgressMonitor();
135 fJavaReconcilingListener.reconciled(null, !fNotify, pm);
145 * @see IReconcilingStrategy#reconcile(IRegion)
147 public void reconcile(IRegion partition) {
152 * @see IReconcilingStrategy#reconcile(DirtyRegion, IRegion)
154 public void reconcile(DirtyRegion dirtyRegion, IRegion subRegion) {
159 * @see IReconcilingStrategy#setDocument(IDocument)
161 public void setDocument(IDocument document) {
165 * @see IReconcilingStrategyExtension#setProgressMonitor(IProgressMonitor)
167 public void setProgressMonitor(IProgressMonitor monitor) {
168 fProgressMonitor = monitor;
172 * @see IReconcilingStrategyExtension#initialReconcile()
174 public void initialReconcile() {
179 * Tells this strategy whether to inform its participants.
182 * <code>true</code> if participant should be notified
184 public void notifyParticipants(boolean notify) {
189 * Tells this strategy whether to inform its listeners.
192 * <code>true</code> if listeners should be notified
194 public void notifyListeners(boolean notify) {
199 * Called before reconciling is started.
203 public void aboutToBeReconciled() {
204 if (fIsJavaReconcilingListener)
205 fJavaReconcilingListener.aboutToBeReconciled();