misc changes
[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
19 /**
20  * Reconcile a working copy and signal the changes through a delta.
21  */
22 public class ReconcileWorkingCopyOperation extends JavaModelOperation {
23                 
24         boolean forceProblemDetection;
25         
26         public ReconcileWorkingCopyOperation(IJavaElement workingCopy, boolean forceProblemDetection) {
27                 super(new IJavaElement[] {workingCopy});
28                 this.forceProblemDetection = forceProblemDetection;
29         }
30         /**
31          * @exception JavaModelException if setting the source
32          *      of the original compilation unit fails
33          */
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$
38 //              }
39 //      
40 //              WorkingCopy workingCopy = getWorkingCopy();
41 //              boolean wasConsistent = workingCopy.isConsistent();
42 //              JavaElementDeltaBuilder deltaBuilder = null;
43 //      
44 //              try {
45 //                      // create the delta builder (this remembers the current content of the cu)
46 //                      if (!wasConsistent){
47 //                              deltaBuilder = new JavaElementDeltaBuilder(workingCopy);
48 //                              
49 //                              // update the element infos with the content of the working copy
50 //                              workingCopy.makeConsistent(fMonitor);
51 //                              deltaBuilder.buildDeltas();
52 //              
53 //                      }
54 //      
55 //                      if (fMonitor != null) fMonitor.worked(2);
56 //                      
57 //                      // force problem detection? - if structure was consistent
58 //                      if (forceProblemDetection && wasConsistent){
59 //                              if (fMonitor != null && fMonitor.isCanceled()) return;
60 //              
61 //                              IProblemRequestor problemRequestor = workingCopy.problemRequestor;
62 //                              if (problemRequestor != null && problemRequestor.isActive()){
63 //                                      problemRequestor.beginReporting();
64 //                                      CompilationUnitProblemFinder.process(workingCopy, problemRequestor, fMonitor);
65 //                                      problemRequestor.endReporting();
66 //                              }
67 //                      }
68 //                      
69 //                      // register the deltas
70 //                      if (deltaBuilder != null){
71 //                              if ((deltaBuilder.delta != null) && (deltaBuilder.delta.getAffectedChildren().length > 0)) {
72 //                                      addReconcileDelta(workingCopy, deltaBuilder.delta);
73 //                              }
74 //                      }
75 //              } finally {
76 //                      if (fMonitor != null) fMonitor.done();
77 //              }
78 //      }
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$
84                 }
85         
86                 WorkingCopy workingCopy = getWorkingCopy();
87 //              boolean wasConsistent = workingCopy.isConsistent();
88 //              JavaElementDeltaBuilder deltaBuilder = null;
89         
90                 try {
91                         // create the delta builder (this remembers the current content of the cu)
92 //                      if (!wasConsistent){
93 //                              deltaBuilder = new JavaElementDeltaBuilder(workingCopy);
94 //                              
95 //                              // update the element infos with the content of the working copy
96 //                              workingCopy.makeConsistent(fMonitor);
97 //                              deltaBuilder.buildDeltas();
98 //              
99 //                      }
100         
101                         if (fMonitor != null) fMonitor.worked(2);
102                         
103                         // force problem detection? - if structure was consistent
104                         if (forceProblemDetection){
105                                 if (fMonitor != null && fMonitor.isCanceled()) return;
106                 
107                                 IProblemRequestor problemRequestor = workingCopy.problemRequestor;
108                                 if (problemRequestor != null && problemRequestor.isActive()){
109                                         problemRequestor.beginReporting();
110                                         CompilationUnitProblemFinder.process(workingCopy, problemRequestor, fMonitor);
111                                         problemRequestor.endReporting();
112                                 }
113                         }
114                         
115                         // register the deltas
116 //                      if (deltaBuilder != null){
117 //                              if ((deltaBuilder.delta != null) && (deltaBuilder.delta.getAffectedChildren().length > 0)) {
118 //                                      addReconcileDelta(workingCopy, deltaBuilder.delta);
119 //                              }
120 //                      }
121                 } finally {
122                         if (fMonitor != null) fMonitor.done();
123                 }
124         }
125         /**
126          * Returns the working copy this operation is working on.
127          */
128         protected WorkingCopy getWorkingCopy() {
129                 return (WorkingCopy)getElementToProcess();
130         }
131         /**
132          * @see JavaModelOperation#isReadOnly
133          */
134         public boolean isReadOnly() {
135                 return true;
136         }
137         protected IJavaModelStatus verify() {
138                 IJavaModelStatus status = super.verify();
139                 if (!status.isOK()) {
140                         return status;
141                 }
142                 WorkingCopy workingCopy = getWorkingCopy();
143                 if (workingCopy.useCount == 0) {
144                         return new JavaModelStatus(IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST, workingCopy); //was destroyed
145                 }
146                 return status;
147         }
148
149
150 }