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 //      net.sourceforge.phpdt.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);
 
 127                                         CompilationUnitProblemFinder.process(workingCopy, problemRequestor, progressMonitor);
 
 128                                         problemRequestor.endReporting();
 
 130                                 if (progressMonitor != null) progressMonitor.worked(1);
 
 131                                 if (this.createAST && unit != null) {
 
 132 //                                      Map options = workingCopy.getJavaProject().getOptions(true);
 
 133 //                                      this.ast = AST.convertCompilationUnit(this.astLevel, unit, contents, options, this.progressMonitor);
 
 134                                         if (progressMonitor != null) progressMonitor.worked(1);
 
 143                         // register the deltas
 
 144 //                      if (deltaBuilder != null){
 
 145 //                              if ((deltaBuilder.delta != null) && (deltaBuilder.delta.getAffectedChildren().length > 0)) {
 
 146 //                                      addReconcileDelta(workingCopy, deltaBuilder.delta);
 
 150                         if (progressMonitor != null) progressMonitor.done();
 
 154          * Returns the working copy this operation is working on.
 
 156         protected CompilationUnit getWorkingCopy() {
 
 157                 return (CompilationUnit)getElementToProcess();
 
 160          * @see JavaModelOperation#isReadOnly
 
 162         public boolean isReadOnly() {
 
 166         protected IJavaModelStatus verify() {
 
 167                 IJavaModelStatus status = super.verify();
 
 168                 if (!status.isOK()) {
 
 171                 CompilationUnit workingCopy = getWorkingCopy();
 
 172                 if (!workingCopy.isWorkingCopy()) {
 
 173                         return new JavaModelStatus(IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST, workingCopy); //was destroyed