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;
20 * Reconcile a working copy and signal the changes through a delta.
22 public class ReconcileWorkingCopyOperation extends JavaModelOperation {
24 boolean forceProblemDetection;
26 public ReconcileWorkingCopyOperation(IJavaElement workingCopy, boolean forceProblemDetection) {
27 super(new IJavaElement[] {workingCopy});
28 this.forceProblemDetection = forceProblemDetection;
31 * @exception JavaModelException if setting the source
32 * of the original compilation unit fails
34 protected void executeOperation() throws JavaModelException {
35 if (fMonitor != null){
36 if (fMonitor.isCanceled()) return;
37 fMonitor.beginTask(Util.bind("element.reconciling"), 10); //$NON-NLS-1$
40 WorkingCopy workingCopy = getWorkingCopy();
41 boolean wasConsistent = workingCopy.isConsistent();
42 JavaElementDeltaBuilder deltaBuilder = null;
45 // create the delta builder (this remembers the current content of the cu)
47 deltaBuilder = new JavaElementDeltaBuilder(workingCopy);
49 // update the element infos with the content of the working copy
50 workingCopy.makeConsistent(fMonitor);
51 deltaBuilder.buildDeltas();
55 if (fMonitor != null) fMonitor.worked(2);
57 // force problem detection? - if structure was consistent
58 if (forceProblemDetection && wasConsistent){
59 if (fMonitor != null && fMonitor.isCanceled()) return;
61 IProblemRequestor problemRequestor = workingCopy.problemRequestor;
62 if (problemRequestor != null && problemRequestor.isActive()){
63 problemRequestor.beginReporting();
64 CompilationUnitProblemFinder.process(workingCopy, problemRequestor, fMonitor);
65 problemRequestor.endReporting();
69 // register the deltas
70 if (deltaBuilder != null){
71 if ((deltaBuilder.delta != null) && (deltaBuilder.delta.getAffectedChildren().length > 0)) {
72 addReconcileDelta(workingCopy, deltaBuilder.delta);
76 if (fMonitor != null) fMonitor.done();
80 * Returns the working copy this operation is working on.
82 protected WorkingCopy getWorkingCopy() {
83 return (WorkingCopy)getElementToProcess();
86 * @see JavaModelOperation#isReadOnly
88 public boolean isReadOnly() {
91 protected IJavaModelStatus verify() {
92 IJavaModelStatus status = super.verify();
96 WorkingCopy workingCopy = getWorkingCopy();
97 if (workingCopy.useCount == 0) {
98 return new JavaModelStatus(IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST, workingCopy); //was destroyed