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 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.core;
15 import net.sourceforge.phpdt.core.IJavaElement;
16 import net.sourceforge.phpdt.core.IJavaModelStatus;
17 import net.sourceforge.phpdt.core.IJavaModelStatusConstants;
18 import net.sourceforge.phpdt.core.IProblemRequestor;
19 import net.sourceforge.phpdt.core.JavaModelException;
20 import net.sourceforge.phpdt.core.WorkingCopyOwner;
21 import net.sourceforge.phpdt.internal.core.util.Util;
22 import net.sourceforge.phpeclipse.internal.compiler.ast.CompilationUnitDeclaration;
25 * Reconcile a working copy and signal the changes through a delta.
27 public class ReconcileWorkingCopyOperation extends JavaModelOperation {
31 boolean forceProblemDetection;
32 WorkingCopyOwner workingCopyOwner;
33 // org.eclipse.jdt.core.dom.CompilationUnit ast;
35 public ReconcileWorkingCopyOperation(IJavaElement workingCopy, boolean forceProblemDetection) {
36 super(new IJavaElement[] {workingCopy});
37 this.forceProblemDetection = forceProblemDetection;
39 public ReconcileWorkingCopyOperation(IJavaElement workingCopy, boolean creatAST, int astLevel, boolean forceProblemDetection, WorkingCopyOwner workingCopyOwner) {
40 super(new IJavaElement[] {workingCopy});
41 this.createAST = creatAST;
42 this.astLevel = astLevel;
43 this.forceProblemDetection = forceProblemDetection;
44 this.workingCopyOwner = workingCopyOwner;
47 * @exception JavaModelException if setting the source
48 * of the original compilation unit fails
50 // protected void executeOperation() throws JavaModelException {
51 // if (fMonitor != null){
52 // if (fMonitor.isCanceled()) return;
53 // fMonitor.beginTask(Util.bind("element.reconciling"), 10); //$NON-NLS-1$
56 // WorkingCopy workingCopy = getWorkingCopy();
57 // boolean wasConsistent = workingCopy.isConsistent();
58 // JavaElementDeltaBuilder deltaBuilder = null;
61 // // create the delta builder (this remembers the current content of the cu)
62 // if (!wasConsistent){
63 // deltaBuilder = new JavaElementDeltaBuilder(workingCopy);
65 // // update the element infos with the content of the working copy
66 // workingCopy.makeConsistent(fMonitor);
67 // deltaBuilder.buildDeltas();
71 // if (fMonitor != null) fMonitor.worked(2);
73 // // force problem detection? - if structure was consistent
74 // if (forceProblemDetection && wasConsistent){
75 // if (fMonitor != null && fMonitor.isCanceled()) return;
77 // IProblemRequestor problemRequestor = workingCopy.problemRequestor;
78 // if (problemRequestor != null && problemRequestor.isActive()){
79 // problemRequestor.beginReporting();
80 // CompilationUnitProblemFinder.process(workingCopy, problemRequestor, fMonitor);
81 // problemRequestor.endReporting();
85 // // register the deltas
86 // if (deltaBuilder != null){
87 // if ((deltaBuilder.delta != null) && (deltaBuilder.delta.getAffectedChildren().length > 0)) {
88 // addReconcileDelta(workingCopy, deltaBuilder.delta);
92 // if (fMonitor != null) fMonitor.done();
95 protected void executeOperation() throws JavaModelException {
96 // TODO jsurfer optimize for PHP
97 if (progressMonitor != null){
98 if (progressMonitor.isCanceled()) return;
99 progressMonitor.beginTask(Util.bind("element.reconciling"), 10); //$NON-NLS-1$
102 CompilationUnit workingCopy = getWorkingCopy();
103 // boolean wasConsistent = workingCopy.isConsistent();
104 // JavaElementDeltaBuilder deltaBuilder = null;
107 // create the delta builder (this remembers the current content of the cu)
108 // if (!wasConsistent){
109 // deltaBuilder = new JavaElementDeltaBuilder(workingCopy);
111 // // update the element infos with the content of the working copy
112 // workingCopy.makeConsistent(fMonitor);
113 // deltaBuilder.buildDeltas();
117 if (progressMonitor != null) progressMonitor.worked(2);
119 // force problem detection? - if structure was consistent
120 if (forceProblemDetection){
121 if (progressMonitor != null && progressMonitor.isCanceled()) return;
122 CompilationUnitDeclaration unit = null;
124 IProblemRequestor problemRequestor = workingCopy.getPerWorkingCopyInfo();
125 if (problemRequestor != null && problemRequestor.isActive()){
126 problemRequestor.beginReporting();
127 char[] contents = workingCopy.getContents();
128 unit = CompilationUnitProblemFinder.process(workingCopy, contents, this.workingCopyOwner, problemRequestor, false/*don't cleanup cu*/, this.progressMonitor);
130 CompilationUnitProblemFinder.process(workingCopy, problemRequestor, progressMonitor);
131 problemRequestor.endReporting();
133 if (progressMonitor != null) progressMonitor.worked(1);
134 if (this.createAST && unit != null) {
135 // Map options = workingCopy.getJavaProject().getOptions(true);
136 // this.ast = AST.convertCompilationUnit(this.astLevel, unit, contents, options, this.progressMonitor);
137 if (progressMonitor != null) progressMonitor.worked(1);
146 // register the deltas
147 // if (deltaBuilder != null){
148 // if ((deltaBuilder.delta != null) && (deltaBuilder.delta.getAffectedChildren().length > 0)) {
149 // addReconcileDelta(workingCopy, deltaBuilder.delta);
153 if (progressMonitor != null) progressMonitor.done();
157 * Returns the working copy this operation is working on.
159 protected CompilationUnit getWorkingCopy() {
160 return (CompilationUnit)getElementToProcess();
163 * @see JavaModelOperation#isReadOnly
165 public boolean isReadOnly() {
169 protected IJavaModelStatus verify() {
170 IJavaModelStatus status = super.verify();
171 if (!status.isOK()) {
174 CompilationUnit workingCopy = getWorkingCopy();
175 if (!workingCopy.isWorkingCopy()) {
176 return new JavaModelStatus(IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST, workingCopy); //was destroyed