示例#1
0
  /**
   * Adds the text and move changes to the root change This change is the a more global change, it
   * includes both the file(s) move, the update of it's includes and update all the references, all
   * the files that have includes to the moved file.
   *
   * @param pm - progress monitor
   * @param rootChange - the root change that the new changes are added to
   * @return the root change after the additions
   */
  private Change createReferenceUpdatingMoveChange(IProgressMonitor pm, CompositeChange rootChange)
      throws CoreException, OperationCanceledException {
    try {
      pm.beginTask(PhpRefactoringCoreMessages.getString("MoveDelegate.0"), 100); // $NON-NLS-1$

      IResource[] sourceResources = fProcessor.getSourceSelection();

      createTextChanges(new SubProgressMonitor(pm, 80), rootChange, phpFiles, sourceResources);
      pm.worked(80);

      // update configuration file.
      createRunConfigurationChange(sourceResources, rootChange);

      // There is a tricky thing here.
      // The resource move must be happened after text change, and run
      // configuration changes(this is because the share file under the
      // project)
      // but before the other changes, e.g. break point and etc.
      createMoveChange(sourceResources, rootChange);

      // update associated break point.
      createBreakPointChange(sourceResources, rootChange);

      createBuildPathChange(sourceResources, rootChange);

      createRenameLibraryFolderChange(sourceResources, rootChange);

      pm.worked(20);

    } finally {
      pm.done();
    }
    return rootChange;
  }
 @Override
 protected IStatus run(IProgressMonitor monitor) {
   MultiStatus result =
       new MultiStatus(
           ResourcesPlugin.PI_RESOURCES,
           IResourceStatus.FAILED_SETTING_CHARSET,
           Messages.resources_updatingEncoding,
           null);
   monitor = Policy.monitorFor(monitor);
   try {
     monitor.beginTask(Messages.resources_charsetUpdating, Policy.totalWork);
     final ISchedulingRule rule = workspace.getRuleFactory().modifyRule(workspace.getRoot());
     try {
       workspace.prepareOperation(rule, monitor);
       workspace.beginOperation(true);
       Map.Entry<IProject, Boolean> next;
       while ((next = getNextChange()) != null) {
         // just exit if the system is shutting down or has been shut down
         // it is too late to change the workspace at this point anyway
         if (systemBundle.getState() != Bundle.ACTIVE) return Status.OK_STATUS;
         IProject project = next.getKey();
         try {
           if (project.isAccessible()) {
             boolean shouldDisableCharsetDeltaJob = next.getValue().booleanValue();
             // flush preferences for non-derived resources
             flushPreferences(
                 getPreferences(project, false, false, true), shouldDisableCharsetDeltaJob);
             // flush preferences for derived resources
             flushPreferences(
                 getPreferences(project, false, true, true), shouldDisableCharsetDeltaJob);
           }
         } catch (BackingStoreException e) {
           // we got an error saving
           String detailMessage = Messages.resources_savingEncoding;
           result.add(
               new ResourceStatus(
                   IResourceStatus.FAILED_SETTING_CHARSET,
                   project.getFullPath(),
                   detailMessage,
                   e));
         }
       }
       monitor.worked(Policy.opWork);
     } catch (OperationCanceledException e) {
       workspace.getWorkManager().operationCanceled();
       throw e;
     } finally {
       workspace.endOperation(rule, true, Policy.subMonitorFor(monitor, Policy.endOpWork));
     }
   } catch (CoreException ce) {
     return ce.getStatus();
   } finally {
     monitor.done();
   }
   return result;
 }
  /**
   * Ausfuehrung der Evaluierung. Jeder Ausdruck wird ueber die Verbindung ausgewertet und das
   * Ergebnis der Evaluierung wird dem {@link IBackgroundEvaluationListener} mitgeteilt.
   *
   * @param monitor - der ProgressMonitor
   * @see IBackgroundEvaluationListener
   * @sse {@link AbstractJob#run0(IProgressMonitor)}
   */
  @Override
  @SuppressWarnings("NP") // Rueckgabe von non-null Wert wird über Methoden-Contract geregelt
  protected IStatus run0(final IProgressMonitor monitor) throws Exception {
    monitor.subTask("Waiting for connection");
    acquireLock();

    ensureConnected(fConnection);
    callPrepare(fForms.size() > 1);

    monitor.beginTask(fJobName, (fForms.size() + 1) * 1000);

    if (monitor.isCanceled()) {
      return Status.CANCEL_STATUS;
    }

    for (int i = 0, n = fForms.size(); i < n; i++) {

      PackageBoundForm form = fForms.get(i);
      monitor.subTask("Starting evaluation " + i + "/" + fForms.size());
      IEvaluation eval = fConnection.getEvaluation();

      eval.evalStart(form.getPackage(), form.getForm());

      // Output Lesen
      readAllOutput(monitor);

      monitor.subTask("Reading result");
      IResult evalResult = eval.evalResult();

      boolean more = i != n - 1;
      IRestartSelection selection = callFormEvaluated(evalResult, more);

      monitor.worked(1000);

      if (evalResult.getTyp() == TResult.SUCCESS) { // Ergebnis ok
        continue; // alles ok mit ergebnis, mit naechstem weitermachen wenn vorhanden
      } else if (evalResult.getTyp()
          == TResult.READ_ERROR) { // Read error, es darf kein abort gesendet werden
        break;
      } else if (selection != null && selection.isAborted()) {
        abort(); // Ein Fehler, kann nur EVAL_ERROR sein, wurde abgebrochen
        break;
      } else { // EVAL_ERROR und es wurde ein Restart gewaehlt, bzw. war verfuegbar
        boolean abort = restart(monitor, selection, more); // eintritt rekursiver restart
        if (abort) { // restart abgebrochen
          abort(); // abort senden
          break; // und (bulk-)eval komplette beenden
        }
        continue; // restart war erfolgreich -> weiter mit naechstem im bulk
      }
    }

    return new Status(IStatus.OK, LispPluginActivator.ID, IStatus.OK, "Evaluation succeeded", null);
  }
示例#4
0
  /**
   * Adds the move changes to the root change This change is the proper move change, nothing else
   *
   * @param pm - progress monitor
   * @param rootChange - the root change that the new changes are added to
   * @return the root change after the additions
   */
  private Change createSimpleMoveChange(final IProgressMonitor pm, final CompositeChange rootChange)
      throws CoreException, OperationCanceledException {
    try {
      pm.beginTask(PhpRefactoringCoreMessages.getString("MoveDelegate.0"), 100); // $NON-NLS-1$

      IResource[] sourceResources = fProcessor.getSourceSelection();
      createMoveChange(sourceResources, rootChange);
      pm.worked(100);

    } finally {
      pm.done();
    }
    return rootChange;
  }
示例#5
0
  /**
   * Creates the text changes for all the affected files. Updates all the include statements in the
   * current file and all the includes in the "including " files. In case of folders, creates the
   * changes recursively
   *
   * @param pm - progress monitor
   * @param rootChange - the root change that the new changes are added to
   * @param sourceResources
   * @return the root change after the additions
   * @throws CoreException
   */
  private Change createTextChanges(
      IProgressMonitor pm,
      CompositeChange rootChange,
      Set<IFile> phpFiles,
      IResource[] sourceResources)
      throws CoreException {
    List<ProgramFileChange> changes = new ArrayList<ProgramFileChange>();
    try {
      pm.beginTask(PhpRefactoringCoreMessages.getString("MoveDelegate.1"), 100); // $NON-NLS-1$

      // creat text changes:
      // for each file that will be moved, update its includes
      // and update all the files that include it,

      IResource[] uniqueSourceResources = removeDuplicateResources(sourceResources);

      for (Iterator<IFile> it = phpFiles.iterator(); it.hasNext(); ) {
        IFile currentMovedResource = it.next();

        Map<IFile, Program> participantFiles = collectReferencingFiles(currentMovedResource, pm);

        for (Entry<IFile, Program> entry : participantFiles.entrySet()) {
          final IFile file = entry.getKey();
          if (phpFiles.contains(file)) {
            continue;
          }
          final Program program = entry.getValue();

          final ChangeIncludePath rename =
              new ChangeIncludePath(
                  currentMovedResource, file, fMainDestinationPath, false, uniqueSourceResources);
          // aggregate the changes identifiers
          program.accept(rename);

          if (pm.isCanceled()) throw new OperationCanceledException();

          pm.worked(1);

          if (rename.hasChanges()) {
            ProgramFileChange change = new ProgramFileChange(file.getName(), file, program);
            change.setEdit(new MultiTextEdit());
            change.setTextType("php"); // $NON-NLS-1$

            changes.add(change);
            rename.updateChange(change);
          }
        }

        ISourceModule sourceModule = DLTKCore.createSourceModuleFrom(currentMovedResource);

        if (sourceModule instanceof ISourceModule) {

          Program program = null;
          try {
            program = ASTUtils.createProgramFromSource(sourceModule);
          } catch (Exception e) {
          }

          if (program != null) {
            final ChangeIncludePath rename =
                new ChangeIncludePath(
                    currentMovedResource,
                    currentMovedResource,
                    fMainDestinationPath,
                    true,
                    uniqueSourceResources);

            // aggregate the changes identifiers
            program.accept(rename);

            if (pm.isCanceled()) throw new OperationCanceledException();

            pm.worked(1);

            if (rename.hasChanges()) {
              ProgramFileChange change =
                  new ProgramFileChange(
                      currentMovedResource.getName(), currentMovedResource, program);
              change.setEdit(new MultiTextEdit());
              change.setTextType("php"); // $NON-NLS-1$

              changes.add(change);
              rename.updateChange(change);
            }
          }
        }
      }
      pm.worked(70);

    } finally {
      pm.done();
    } // getChildren()

    Map<IFile, List<TextEdit>> changeMap = new HashMap<IFile, List<TextEdit>>();
    Map<IFile, ProgramFileChange> fileMap = new HashMap<IFile, ProgramFileChange>();
    for (ProgramFileChange programFileChange : changes) {
      List<TextEdit> list = changeMap.get(programFileChange.getFile());
      if (list == null) {
        list = new ArrayList<TextEdit>();
        changeMap.put(programFileChange.getFile(), list);
        fileMap.put(programFileChange.getFile(), programFileChange);
      } else {

      }
      list.addAll(Arrays.asList(programFileChange.getEdit().getChildren()));
    }
    for (IFile file : changeMap.keySet()) {
      ProgramFileChange change =
          new ProgramFileChange(file.getName(), file, fileMap.get(file).getProgram());
      change.setEdit(new MultiTextEdit());
      change.setTextType("php"); // $NON-NLS-1$

      List<TextEdit> list = changeMap.get(file);
      Collections.sort(
          list,
          new Comparator<TextEdit>() {
            public int compare(TextEdit o1, TextEdit o2) {
              return o2.getOffset() - o1.getOffset();
            }
          });

      for (TextEdit textEdit : list) {
        if (textEdit instanceof ReplaceEdit) {
          ReplaceEdit replaceEdit = (ReplaceEdit) textEdit;
          change.addEdit(
              new ReplaceEdit(
                  replaceEdit.getOffset(), replaceEdit.getLength(), replaceEdit.getText()));
        }
      }
      rootChange.add(change);
    }
    return rootChange;
  }