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.core.util.Util;
20 import net.sourceforge.phpeclipse.internal.compiler.ast.CompilationUnitDeclaration;
23 * Reconcile a working copy and signal the changes through a delta.
25 public class ReconcileWorkingCopyOperation extends JavaModelOperation {
29 boolean forceProblemDetection;
30 WorkingCopyOwner workingCopyOwner;
31 // org.eclipse.jdt.core.dom.CompilationUnit ast;
33 public ReconcileWorkingCopyOperation(IJavaElement workingCopy, boolean forceProblemDetection) {
34 super(new IJavaElement[] {workingCopy});
35 this.forceProblemDetection = forceProblemDetection;
37 public ReconcileWorkingCopyOperation(IJavaElement workingCopy, boolean creatAST, int astLevel, boolean forceProblemDetection, WorkingCopyOwner workingCopyOwner) {
38 super(new IJavaElement[] {workingCopy});
39 this.createAST = creatAST;
40 this.astLevel = astLevel;
41 this.forceProblemDetection = forceProblemDetection;
42 this.workingCopyOwner = workingCopyOwner;
45 * @exception JavaModelException if setting the source
46 * of the original compilation unit fails
48 // protected void executeOperation() throws JavaModelException {
49 // if (fMonitor != null){
50 // if (fMonitor.isCanceled()) return;
51 // fMonitor.beginTask(ProjectPrefUtil.bind("element.reconciling"), 10); //$NON-NLS-1$
54 // WorkingCopy workingCopy = getWorkingCopy();
55 // boolean wasConsistent = workingCopy.isConsistent();
56 // JavaElementDeltaBuilder deltaBuilder = null;
59 // // create the delta builder (this remembers the current content of the cu)
60 // if (!wasConsistent){
61 // deltaBuilder = new JavaElementDeltaBuilder(workingCopy);
63 // // update the element infos with the content of the working copy
64 // workingCopy.makeConsistent(fMonitor);
65 // deltaBuilder.buildDeltas();
69 // if (fMonitor != null) fMonitor.worked(2);
71 // // force problem detection? - if structure was consistent
72 // if (forceProblemDetection && wasConsistent){
73 // if (fMonitor != null && fMonitor.isCanceled()) return;
75 // IProblemRequestor problemRequestor = workingCopy.problemRequestor;
76 // if (problemRequestor != null && problemRequestor.isActive()){
77 // problemRequestor.beginReporting();
78 // CompilationUnitProblemFinder.process(workingCopy, problemRequestor, fMonitor);
79 // problemRequestor.endReporting();
83 // // register the deltas
84 // if (deltaBuilder != null){
85 // if ((deltaBuilder.delta != null) && (deltaBuilder.delta.getAffectedChildren().length > 0)) {
86 // addReconcileDelta(workingCopy, deltaBuilder.delta);
90 // if (fMonitor != null) fMonitor.done();
93 protected void executeOperation() throws JavaModelException {
94 // TODO jsurfer optimize for PHP
95 if (progressMonitor != null){
96 if (progressMonitor.isCanceled()) return;
97 progressMonitor.beginTask(Util.bind("element.reconciling"), 10); //$NON-NLS-1$
100 CompilationUnit workingCopy = getWorkingCopy();
101 // boolean wasConsistent = workingCopy.isConsistent();
102 // JavaElementDeltaBuilder deltaBuilder = null;
105 // create the delta builder (this remembers the current content of the cu)
106 // if (!wasConsistent){
107 // deltaBuilder = new JavaElementDeltaBuilder(workingCopy);
109 // // update the element infos with the content of the working copy
110 // workingCopy.makeConsistent(fMonitor);
111 // deltaBuilder.buildDeltas();
115 if (progressMonitor != null) progressMonitor.worked(2);
117 // force problem detection? - if structure was consistent
118 if (forceProblemDetection){
119 if (progressMonitor != null && progressMonitor.isCanceled()) return;
120 CompilationUnitDeclaration unit = null;
122 IProblemRequestor problemRequestor = workingCopy.getPerWorkingCopyInfo();
123 if (problemRequestor != null && problemRequestor.isActive()){
124 problemRequestor.beginReporting();
125 char[] contents = workingCopy.getContents();
126 unit = CompilationUnitProblemFinder.process(workingCopy, contents, this.workingCopyOwner, problemRequestor, false/*don't cleanup cu*/, this.progressMonitor);
128 CompilationUnitProblemFinder.process(workingCopy, problemRequestor, progressMonitor);
129 problemRequestor.endReporting();
131 if (progressMonitor != null) progressMonitor.worked(1);
132 if (this.createAST && unit != null) {
133 // Map options = workingCopy.getJavaProject().getOptions(true);
134 // this.ast = AST.convertCompilationUnit(this.astLevel, unit, contents, options, this.progressMonitor);
135 if (progressMonitor != null) progressMonitor.worked(1);
144 // register the deltas
145 // if (deltaBuilder != null){
146 // if ((deltaBuilder.delta != null) && (deltaBuilder.delta.getAffectedChildren().length > 0)) {
147 // addReconcileDelta(workingCopy, deltaBuilder.delta);
151 if (progressMonitor != null) progressMonitor.done();
155 * Returns the working copy this operation is working on.
157 protected CompilationUnit getWorkingCopy() {
158 return (CompilationUnit)getElementToProcess();
161 * @see JavaModelOperation#isReadOnly
163 public boolean isReadOnly() {
167 protected IJavaModelStatus verify() {
168 IJavaModelStatus status = super.verify();
169 if (!status.isOK()) {
172 CompilationUnit workingCopy = getWorkingCopy();
173 if (!workingCopy.isWorkingCopy()) {
174 return new JavaModelStatus(IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST, workingCopy); //was destroyed