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)
46 // if (!wasConsistent){
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();
79 protected void executeOperation() throws JavaModelException {
80 // TODO jsurfer optimize for PHP
81 if (fMonitor != null){
82 if (fMonitor.isCanceled()) return;
83 fMonitor.beginTask(Util.bind("element.reconciling"), 10); //$NON-NLS-1$
86 WorkingCopy workingCopy = getWorkingCopy();
87 // boolean wasConsistent = workingCopy.isConsistent();
88 // JavaElementDeltaBuilder deltaBuilder = null;
91 // create the delta builder (this remembers the current content of the cu)
92 // if (!wasConsistent){
93 // deltaBuilder = new JavaElementDeltaBuilder(workingCopy);
95 // // update the element infos with the content of the working copy
96 // workingCopy.makeConsistent(fMonitor);
97 // deltaBuilder.buildDeltas();
101 if (fMonitor != null) fMonitor.worked(2);
103 // force problem detection? - if structure was consistent
104 if (forceProblemDetection){
105 if (fMonitor != null && fMonitor.isCanceled()) return;
107 IProblemRequestor problemRequestor = workingCopy.problemRequestor;
108 if (problemRequestor != null && problemRequestor.isActive()){
109 problemRequestor.beginReporting();
110 CompilationUnitProblemFinder.process(workingCopy, problemRequestor, fMonitor);
111 problemRequestor.endReporting();
115 // register the deltas
116 // if (deltaBuilder != null){
117 // if ((deltaBuilder.delta != null) && (deltaBuilder.delta.getAffectedChildren().length > 0)) {
118 // addReconcileDelta(workingCopy, deltaBuilder.delta);
122 if (fMonitor != null) fMonitor.done();
126 * Returns the working copy this operation is working on.
128 protected WorkingCopy getWorkingCopy() {
129 return (WorkingCopy)getElementToProcess();
132 * @see JavaModelOperation#isReadOnly
134 public boolean isReadOnly() {
137 protected IJavaModelStatus verify() {
138 IJavaModelStatus status = super.verify();
139 if (!status.isOK()) {
142 WorkingCopy workingCopy = getWorkingCopy();
143 if (workingCopy.useCount == 0) {
144 return new JavaModelStatus(IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST, workingCopy); //was destroyed