RC2 compatibility
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / core / ReconcileWorkingCopyOperation.java
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
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpdt.internal.core;
12
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;
21
22 /**
23  * Reconcile a working copy and signal the changes through a delta.
24  */
25 public class ReconcileWorkingCopyOperation extends JavaModelOperation {
26                 
27         boolean createAST;
28         int astLevel;
29         boolean forceProblemDetection;
30         WorkingCopyOwner workingCopyOwner;
31 //      org.eclipse.jdt.core.dom.CompilationUnit ast;
32         
33         public ReconcileWorkingCopyOperation(IJavaElement workingCopy, boolean forceProblemDetection) {
34                 super(new IJavaElement[] {workingCopy});
35                 this.forceProblemDetection = forceProblemDetection;
36         }
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;
43         }
44         /**
45          * @exception JavaModelException if setting the source
46          *      of the original compilation unit fails
47          */
48 //      protected void executeOperation() throws JavaModelException {
49 //              if (fMonitor != null){
50 //                      if (fMonitor.isCanceled()) return;
51 //                      fMonitor.beginTask(Util.bind("element.reconciling"), 10); //$NON-NLS-1$
52 //              }
53 //      
54 //              WorkingCopy workingCopy = getWorkingCopy();
55 //              boolean wasConsistent = workingCopy.isConsistent();
56 //              JavaElementDeltaBuilder deltaBuilder = null;
57 //      
58 //              try {
59 //                      // create the delta builder (this remembers the current content of the cu)
60 //                      if (!wasConsistent){
61 //                              deltaBuilder = new JavaElementDeltaBuilder(workingCopy);
62 //                              
63 //                              // update the element infos with the content of the working copy
64 //                              workingCopy.makeConsistent(fMonitor);
65 //                              deltaBuilder.buildDeltas();
66 //              
67 //                      }
68 //      
69 //                      if (fMonitor != null) fMonitor.worked(2);
70 //                      
71 //                      // force problem detection? - if structure was consistent
72 //                      if (forceProblemDetection && wasConsistent){
73 //                              if (fMonitor != null && fMonitor.isCanceled()) return;
74 //              
75 //                              IProblemRequestor problemRequestor = workingCopy.problemRequestor;
76 //                              if (problemRequestor != null && problemRequestor.isActive()){
77 //                                      problemRequestor.beginReporting();
78 //                                      CompilationUnitProblemFinder.process(workingCopy, problemRequestor, fMonitor);
79 //                                      problemRequestor.endReporting();
80 //                              }
81 //                      }
82 //                      
83 //                      // register the deltas
84 //                      if (deltaBuilder != null){
85 //                              if ((deltaBuilder.delta != null) && (deltaBuilder.delta.getAffectedChildren().length > 0)) {
86 //                                      addReconcileDelta(workingCopy, deltaBuilder.delta);
87 //                              }
88 //                      }
89 //              } finally {
90 //                      if (fMonitor != null) fMonitor.done();
91 //              }
92 //      }
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$
98                 }
99         
100                 CompilationUnit workingCopy = getWorkingCopy();
101 //              boolean wasConsistent = workingCopy.isConsistent();
102 //              JavaElementDeltaBuilder deltaBuilder = null;
103         
104                 try {
105                         // create the delta builder (this remembers the current content of the cu)
106 //                      if (!wasConsistent){
107 //                              deltaBuilder = new JavaElementDeltaBuilder(workingCopy);
108 //                              
109 //                              // update the element infos with the content of the working copy
110 //                              workingCopy.makeConsistent(fMonitor);
111 //                              deltaBuilder.buildDeltas();
112 //              
113 //                      }
114         
115                         if (progressMonitor != null) progressMonitor.worked(2);
116                         
117                         // force problem detection? - if structure was consistent
118                         if (forceProblemDetection){
119                                 if (progressMonitor != null && progressMonitor.isCanceled()) return;
120                                 CompilationUnitDeclaration unit = null;
121                                 try {
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);
127                                         
128                                         CompilationUnitProblemFinder.process(workingCopy, problemRequestor, progressMonitor);
129                                         problemRequestor.endReporting();
130                                 }
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);
136                                 }
137                                 } finally {
138                                 if (unit != null) {
139                                     unit.cleanUp();
140                                 }
141                             }
142                         }
143                         
144                         // register the deltas
145 //                      if (deltaBuilder != null){
146 //                              if ((deltaBuilder.delta != null) && (deltaBuilder.delta.getAffectedChildren().length > 0)) {
147 //                                      addReconcileDelta(workingCopy, deltaBuilder.delta);
148 //                              }
149 //                      }
150                 } finally {
151                         if (progressMonitor != null) progressMonitor.done();
152                 }
153         }
154         /**
155          * Returns the working copy this operation is working on.
156          */
157         protected CompilationUnit getWorkingCopy() {
158                 return (CompilationUnit)getElementToProcess();
159         }
160         /**
161          * @see JavaModelOperation#isReadOnly
162          */
163         public boolean isReadOnly() {
164                 return true;
165         }
166         
167         protected IJavaModelStatus verify() {
168                 IJavaModelStatus status = super.verify();
169                 if (!status.isOK()) {
170                         return status;
171                 }
172                 CompilationUnit workingCopy = getWorkingCopy();
173                 if (!workingCopy.isWorkingCopy()) {
174                         return new JavaModelStatus(IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST, workingCopy); //was destroyed
175                 }
176                 return status;
177         }
178
179 }