1 /*******************************************************************************
2 * Copyright (c) 2000, 2003 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 *******************************************************************************/
12 package net.sourceforge.phpdt.internal.ui.text.java;
14 import net.sourceforge.phpdt.core.ICompilationUnit;
15 import net.sourceforge.phpdt.core.JavaModelException;
16 import net.sourceforge.phpdt.ui.IWorkingCopyManager;
17 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
19 import org.eclipse.core.runtime.IProgressMonitor;
20 import org.eclipse.jface.text.IDocument;
21 import org.eclipse.jface.text.IRegion;
22 import org.eclipse.jface.text.reconciler.DirtyRegion;
23 import org.eclipse.jface.text.reconciler.IReconcilingStrategy;
24 import org.eclipse.jface.text.reconciler.IReconcilingStrategyExtension;
25 import org.eclipse.jface.text.source.IAnnotationModel;
26 import org.eclipse.ui.texteditor.IDocumentProvider;
27 import org.eclipse.ui.texteditor.ITextEditor;
29 public class JavaReconcilingStrategy implements IReconcilingStrategy, IReconcilingStrategyExtension {
31 private ITextEditor fEditor;
33 private IWorkingCopyManager fManager;
34 private IDocumentProvider fDocumentProvider;
35 private IProgressMonitor fProgressMonitor;
36 private boolean fNotify = true;
38 public JavaReconcilingStrategy(ITextEditor editor) {
40 fManager = PHPeclipsePlugin.getDefault().getWorkingCopyManager();
41 fDocumentProvider = PHPeclipsePlugin.getDefault().getCompilationUnitDocumentProvider();
44 private IProblemRequestorExtension getProblemRequestorExtension() {
45 IAnnotationModel model = fDocumentProvider.getAnnotationModel(fEditor.getEditorInput());
46 if (model instanceof IProblemRequestorExtension)
47 return (IProblemRequestorExtension) model;
51 private void reconcile() {
54 // /* fix for missing cancel flag communication */
55 // IProblemRequestorExtension extension = getProblemRequestorExtension();
56 // if (extension != null)
57 // extension.setProgressMonitor(fProgressMonitor);
60 //// synchronized (unit) {
61 //// unit.reconcile(true, fProgressMonitor);
64 // Parser parser = new Parser();
65 // parser.initializeScanner();
66 // // actualParser.setFileToParse(fileToParse);
67 // String text = fEditor.getDocumentProvider().getDocument(fEditor.getEditorInput()).get();
69 // parser.reportSyntaxError();
70 //// checkAndReportBracketAnomalies(parser.problemReporter());
72 // /* fix for missing cancel flag communication */
73 // if (extension != null)
74 // extension.setProgressMonitor(null);
76 // // update participants
78 // if (fEditor instanceof IReconcilingParticipant && fNotify && !fProgressMonitor.isCanceled()) {
79 // IReconcilingParticipant p = (IReconcilingParticipant) fEditor;
86 // JDT implementation:
87 ICompilationUnit unit = fManager.getWorkingCopy(fEditor.getEditorInput());
91 /* fix for missing cancel flag communication */
92 IProblemRequestorExtension extension = getProblemRequestorExtension();
93 if (extension != null)
94 extension.setProgressMonitor(fProgressMonitor);
98 unit.reconcile(true, fProgressMonitor);
101 /* fix for missing cancel flag communication */
102 if (extension != null)
103 extension.setProgressMonitor(null);
105 // update participants
107 if (fEditor instanceof IReconcilingParticipant && fNotify && !fProgressMonitor.isCanceled()) {
108 IReconcilingParticipant p = (IReconcilingParticipant) fEditor;
115 } catch (JavaModelException x) {
122 * @see IReconcilingStrategy#reconcile(IRegion)
124 public void reconcile(IRegion partition) {
129 * @see IReconcilingStrategy#reconcile(DirtyRegion, IRegion)
131 public void reconcile(DirtyRegion dirtyRegion, IRegion subRegion) {
136 * @see IReconcilingStrategy#setDocument(IDocument)
138 public void setDocument(IDocument document) {
142 * @see IReconcilingStrategyExtension#setProgressMonitor(IProgressMonitor)
144 public void setProgressMonitor(IProgressMonitor monitor) {
145 fProgressMonitor = monitor;
149 * @see IReconcilingStrategyExtension#initialReconcile()
151 public void initialReconcile() {
156 * Tells this strategy whether to inform its participants.
158 * @param notify <code>true</code> if participant should be notified
160 public void notifyParticipants(boolean notify) {