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;
13 import net.sourceforge.phpdt.core.IJavaElement;
14 import net.sourceforge.phpdt.core.IJavaModelStatus;
15 import net.sourceforge.phpdt.core.IJavaModelStatusConstants;
16 import net.sourceforge.phpdt.core.IProblemRequestor;
17 import net.sourceforge.phpdt.core.JavaModelException;
18 import net.sourceforge.phpdt.core.WorkingCopyOwner;
19 import net.sourceforge.phpdt.internal.compiler.ast.CompilationUnitDeclaration;
20 import net.sourceforge.phpdt.internal.core.util.Util;
23 * Reconcile a working copy and signal the changes through a delta.
25 public class ReconcileWorkingCopyOperation extends JavaModelOperation {
31 boolean forceProblemDetection;
33 WorkingCopyOwner workingCopyOwner;
35 // net.sourceforge.phpdt.core.dom.CompilationUnit ast;
37 public ReconcileWorkingCopyOperation(IJavaElement workingCopy,
38 boolean forceProblemDetection) {
39 super(new IJavaElement[] { workingCopy });
40 this.forceProblemDetection = forceProblemDetection;
43 public ReconcileWorkingCopyOperation(IJavaElement workingCopy,
44 boolean creatAST, int astLevel, boolean forceProblemDetection,
45 WorkingCopyOwner workingCopyOwner) {
46 super(new IJavaElement[] { workingCopy });
47 this.createAST = creatAST;
48 this.astLevel = astLevel;
49 this.forceProblemDetection = forceProblemDetection;
50 this.workingCopyOwner = workingCopyOwner;
54 * @exception JavaModelException
55 * if setting the source of the original compilation unit
58 // protected void executeOperation() throws JavaModelException {
59 // if (fMonitor != null){
60 // if (fMonitor.isCanceled()) return;
61 // fMonitor.beginTask(ProjectPrefUtil.bind("element.reconciling"), 10);
65 // WorkingCopy workingCopy = getWorkingCopy();
66 // boolean wasConsistent = workingCopy.isConsistent();
67 // JavaElementDeltaBuilder deltaBuilder = null;
70 // // create the delta builder (this remembers the current content of the
72 // if (!wasConsistent){
73 // deltaBuilder = new JavaElementDeltaBuilder(workingCopy);
75 // // update the element infos with the content of the working copy
76 // workingCopy.makeConsistent(fMonitor);
77 // deltaBuilder.buildDeltas();
81 // if (fMonitor != null) fMonitor.worked(2);
83 // // force problem detection? - if structure was consistent
84 // if (forceProblemDetection && wasConsistent){
85 // if (fMonitor != null && fMonitor.isCanceled()) return;
87 // IProblemRequestor problemRequestor = workingCopy.problemRequestor;
88 // if (problemRequestor != null && problemRequestor.isActive()){
89 // problemRequestor.beginReporting();
90 // CompilationUnitProblemFinder.process(workingCopy, problemRequestor,
92 // problemRequestor.endReporting();
96 // // register the deltas
97 // if (deltaBuilder != null){
98 // if ((deltaBuilder.delta != null) &&
99 // (deltaBuilder.delta.getAffectedChildren().length > 0)) {
100 // addReconcileDelta(workingCopy, deltaBuilder.delta);
104 // if (fMonitor != null) fMonitor.done();
107 protected void executeOperation() throws JavaModelException {
108 // TODO jsurfer optimize for PHP
109 if (progressMonitor != null) {
110 if (progressMonitor.isCanceled())
112 progressMonitor.beginTask(Util.bind("element.reconciling"), 10); //$NON-NLS-1$
115 CompilationUnit workingCopy = getWorkingCopy();
116 // boolean wasConsistent = workingCopy.isConsistent();
117 // JavaElementDeltaBuilder deltaBuilder = null;
120 // create the delta builder (this remembers the current content of
122 // if (!wasConsistent){
123 // deltaBuilder = new JavaElementDeltaBuilder(workingCopy);
125 // // update the element infos with the content of the working copy
126 // workingCopy.makeConsistent(fMonitor);
127 // deltaBuilder.buildDeltas();
131 if (progressMonitor != null)
132 progressMonitor.worked(2);
134 // force problem detection? - if structure was consistent
135 if (forceProblemDetection) {
136 if (progressMonitor != null && progressMonitor.isCanceled())
138 CompilationUnitDeclaration unit = null;
140 IProblemRequestor problemRequestor = workingCopy
141 .getPerWorkingCopyInfo();
142 if (problemRequestor != null && problemRequestor.isActive()) {
143 problemRequestor.beginReporting();
144 char[] contents = workingCopy.getContents();
145 unit = CompilationUnitProblemFinder.process(
146 workingCopy, contents, this.workingCopyOwner,
147 problemRequestor, false/* don't cleanup cu */,
148 this.progressMonitor);
149 CompilationUnitProblemFinder.process(workingCopy,
150 problemRequestor, progressMonitor);
151 problemRequestor.endReporting();
153 if (progressMonitor != null)
154 progressMonitor.worked(1);
155 if (this.createAST && unit != null) {
157 // workingCopy.getJavaProject().getOptions(true);
158 // this.ast = AST.convertCompilationUnit(this.astLevel,
159 // unit, contents, options, this.progressMonitor);
160 if (progressMonitor != null)
161 progressMonitor.worked(1);
170 // register the deltas
171 // if (deltaBuilder != null){
172 // if ((deltaBuilder.delta != null) &&
173 // (deltaBuilder.delta.getAffectedChildren().length > 0)) {
174 // addReconcileDelta(workingCopy, deltaBuilder.delta);
178 if (progressMonitor != null)
179 progressMonitor.done();
184 * Returns the working copy this operation is working on.
186 protected CompilationUnit getWorkingCopy() {
187 return (CompilationUnit) getElementToProcess();
191 * @see JavaModelOperation#isReadOnly
193 public boolean isReadOnly() {
197 protected IJavaModelStatus verify() {
198 IJavaModelStatus status = super.verify();
199 if (!status.isOK()) {
202 CompilationUnit workingCopy = getWorkingCopy();
203 if (!workingCopy.isWorkingCopy()) {
204 return new JavaModelStatus(
205 IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST,
206 workingCopy); // was destroyed