Package org.eclipse.ltk.core.refactoring

Examples of org.eclipse.ltk.core.refactoring.CompositeChange


* @coverage gwt.refactoring.participants
*/
public class EntryPointDeleteParticipant extends AbstractDeleteParticipant {
  @Override
  protected Change createChangeEx(IProgressMonitor pm) throws Exception {
    CompositeChange compositeChange = new CompositeChange("EntryPoint delete");
    // add changes
    IType entryPointType = m_type;
    compositeChange.add(GwtRefactoringUtils.module_removeEntryPoint(entryPointType));
    //
    return compositeChange;
  }
View Full Code Here


        return status;
    }

    @Override
    public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException {
        CompositeChange changes = new CompositeChange("Reorganize DRL " + currentName + " Type ");
        drlFiles = drlProjectDetector.detect(file.getProject());
        classPattern = Pattern.compile("(?<=\\W)" + currentName + "(?=\\W)");
        for (IFile drlFile : drlFiles) {
          TextFileChange change = createChangesForFile(drlFile);
            if ( change != null && change.getEdit().getChildrenSize() > 0 ) {
                changes.add(change);
            }
        }
       
        if (changes.getChildren().length == 0) {
          return null;
        }
        DroolsEclipsePlugin.getDefault().setForceFullBuild();
        return changes;
    }
View Full Code Here

        return status;
    }

    @Override
    public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException {
        CompositeChange changes = null;
        String content;
        changes = new CompositeChange("Reorganize DRL " + currentName + " Type ");
        drlFiles = drlProjectDetector.detect(file.getProject());
        Pattern pattern = Pattern.compile("(?<=\\.|\\s)" + currentName + "(?=\\(|\\r\\n|\\s)");
        Pattern packageImportPattern = Pattern.compile("import[\\s]+" + packageName + "\\.*");
        Pattern classImportPattern = Pattern.compile("import[\\s]+" + className);
       
        for (IFile drlFile : drlFiles) {

            if ((content = FileUtil.readFile(drlFile))==null)
                return null;
           
            if (!packageImportPattern.matcher(content).find() && !classImportPattern.matcher(content).find()) {
              return null;
            }

            matcher = pattern.matcher(content);

            TextFileChange change = new TextFileChange(drlFile.getName(), drlFile);
            MultiTextEdit mte = new MultiTextEdit();
            change.setEdit(mte);
            while (matcher.find()) {
                ReplaceEdit replace = new ReplaceEdit(matcher.start(), currentName.length(), newName);
                mte.addChild(replace);
            }
            if (change.getEdit().getChildrenSize() > 0)
                changes.add(change);
        }
        if (changes.getChildren().length==0)
            return null;
        return (changes.getChildren().length > 0)?changes:null;
    }
View Full Code Here

  /**
   * Implementation of {@link #createChange(IProgressMonitor)} that can throw {@link Exception}.
   */
  private Change createChangeEx(IProgressMonitor pm) throws Exception {
    CompositeChange compositeChange = new CompositeChange("synthetic");
    compositeChange.markAsSynthetic();
    // prepare context
    m_oldName = m_field.getElementName();
    m_newName = getArguments().getNewName();
    // add changes
    addHandlerMethodChanges(compositeChange, pm);
    compositeChange.add(createTemplateChange());
    return compositeChange;
  }
View Full Code Here

    return true;
  }

  public Change createChange(IProgressMonitor pm) throws CoreException,
      OperationCanceledException {
    CompositeChange result = new CompositeChange(getName());
    try {
      pm
          .beginTask(
              "beging create change for context-root and artifactId",
              100);
      String oldName = project.getName();
      String underProjectFilePath = getDeploymentPlanFileUnderProjectPath(project);
      String projectRelativeFilePath = deploymentPlanFile.getFullPath()
          .toString();
      String absoluteWorkspacePath = project.getParent().getLocation()
          .toString();
      String absoluteFilePath = absoluteWorkspacePath
          + projectRelativeFilePath;

      DeploymentPlanEditHelper editHelper = new DeploymentPlanEditHelper(
          new DeploymentPlanHandler(absoluteFilePath));

      // Before this change being applied, the project has been
      // renamed. So, use a MovedTextFileChange instead of TextFileChange
      String newName = this.getArguments().getNewName();
      IProject newProject = ((IWorkspaceRoot) deploymentPlanFile
          .getProject().getParent()).getProject(newName);
      IFile newFile = newProject.getFile(underProjectFilePath);

      // if a web project, should create a context-root change if any
      if (JavaEEProjectUtilities.isDynamicWebProject(project)) {
        // create change for context-root
        String oldName1 = editHelper
            .getNodeValue(DeploymentPlanTextNode.CONTEXT_ROOT);
        int offset1 = editHelper
            .getNodeOffset(DeploymentPlanTextNode.CONTEXT_ROOT);
        if (offset1 != -1 && oldName1 != null
            && oldName1.substring(1).equals(oldName)) {
          MovedTextFileChange change1 = new MovedTextFileChange(
              "Rename artifactId's value", newFile,
              deploymentPlanFile);
          MultiTextEdit rootEdit1 = new MultiTextEdit();
          ReplaceEdit edit1 = new ReplaceEdit(offset1, oldName1
              .length(), "/" + newName);
          rootEdit1.addChild(edit1);
          change1.setEdit(rootEdit1);
          result.add(change1);
        }
      }

      // create change for artifactId
      String oldName2 = editHelper
          .getNodeValue(DeploymentPlanTextNode.ARTIFACT_ID);
      int offset2 = editHelper
          .getNodeOffset(DeploymentPlanTextNode.ARTIFACT_ID);
      if (offset2 != -1 && oldName2 != null && oldName2.equals(oldName)) {
        MovedTextFileChange change2 = new MovedTextFileChange(
            "Rename context-root's value", newFile,
            deploymentPlanFile);
        MultiTextEdit rootEdit2 = new MultiTextEdit();
        ReplaceEdit edit2 = new ReplaceEdit(offset2, oldName2.length(),
            newName);
        rootEdit2.addChild(edit2);
        change2.setEdit(rootEdit2);
        result.add(change2);
      }

    } finally {
      pm.done();
    }
    if (result.getChildren().length == 0)
      return null;

    return result;
  }
View Full Code Here

      }
    } catch (LocateException e) {
      throw new CoreException(new Status(IStatus.ERROR, RefactoringPlugin.getDefault().getBundleID(), IStatus.ERROR, "Could not locate component: " + _resourcePath.lastSegment(), null)); //$NON-NLS-1$
    }
    if (oldApiFile != null || oldWoFolders.length > 0) {
      CompositeChange compositeChange = new CompositeChange("Rename WOComponent Files");
      if (oldApiFile != null) {
        TextFileChange apiTextFileChange = new TextFileChange("Rename Java class name in API file", oldApiFile);
        apiTextFileChange.setTextType("xml");
        String javaFileName = getCompilationUnit().getElementName();
        String apiContent = apiTextFileChange.getCurrentContent(null);
        apiTextFileChange.setEdit(new ReplaceEdit(apiContent.indexOf(javaFileName), javaFileName.length(), getNewName() + ".java"));
        compositeChange.add(apiTextFileChange);
        compositeChange.add(new RenameResourceChange(oldApiFile.getFullPath(), getNewName() + ".api"));
      }
      for (int i = 0; i < oldWoFolders.length; i++) {
        IFolder oldWoFolder = oldWoFolders[i];
        if (oldWoFolder == null) {
          continue;
        }
        CompositeChange renameWoFolderChange = new CompositeChange("Rename " + oldWoFolder.getName());

        String[] renameExtensions = { ".html", ".wod", ".woo", ".xml", ".xhtml" };
        for (int j = 0; j < renameExtensions.length; j++) {
          IFile woFile = oldWoFolder.getFile(getOldName() + renameExtensions[j]);
          if (woFile.exists()) {
            renameWoFolderChange.add(new RenameResourceChange(woFile.getFullPath(), getNewName() + renameExtensions[j]));
          }
        }
        renameWoFolderChange.add(new RenameResourceChange(oldWoFolder.getFullPath(), getNewName() + ".wo"));
        compositeChange.add(renameWoFolderChange);

      }
      add(compositeChange);
      if (_renameClass) {
View Full Code Here

        return status;
    }

    @Override
    public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException {
        CompositeChange changes = new CompositeChange("Reorganize DRL " + currentName + " Type ");
        drlFiles = drlProjectDetector.detect(file.getProject());
        classPattern = Pattern.compile("(?<=\\W)" + currentName + "(?=\\W)");
        for (IFile drlFile : drlFiles) {
          TextFileChange change = createChangesForFile(drlFile);
            if ( change != null && change.getEdit().getChildrenSize() > 0 ) {
                changes.add(change);
            }
        }
       
        if (changes.getChildren().length == 0) {
          return null;
        }
        DroolsEclipsePlugin.getDefault().setForceFullBuild();
        return changes;
    }
View Full Code Here

        return status;
    }

    @Override
    public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException {
        CompositeChange changes = new CompositeChange("Reorganize DRL " + currentName + "." + className + " imports ");
        String content;
        for (IFile drlFile : drlProjectDetector.detect(file.getProject())) {

            content = refactoringContent.getIFileContent(drlFile);
            if (content==null && (content = FileUtil.readFile(drlFile))==null)
                continue;

            String toReplace = currentName + "." + className;
            String replaceWith = newName + "." + className;

            Pattern pattern = Pattern.compile(toReplace);
            matcher = pattern.matcher(content);

            if (matcher.find()) {
                TextFileChange change = new TextFileChange(drlFile.getName(), drlFile);
                MultiTextEdit mte = new MultiTextEdit();
                change.setEdit(mte);
                ReplaceEdit replace = new ReplaceEdit(matcher.start(), toReplace.length(), replaceWith);
                mte.addChild(replace);
                changes.add(change);
                refactoringContent.updateContent(drlFile, content.replace(toReplace, replaceWith));
            }
        }
        return (changes.getChildren().length > 0)?changes:null;
    }
View Full Code Here

        this.name = name;
        this.processors = processors;
    }

    public Change createChange() throws MisconfigurationException {
        CompositeChange change = new CompositeChange(name);
        for (IChangeProcessor processor : processors) {
            change.add(processor.createChange());
        }

        return change;
    }
View Full Code Here

    public Change createChange(IProgressMonitor pm,
        INewNameQueries newNameQueries) throws ModelException {
      NewNameProposer nameProposer = new NewNameProposer();
      IScriptFolder[] fragments = getPackages();
      pm.beginTask("", fragments.length); //$NON-NLS-1$
      CompositeChange composite = new DynamicValidationStateChange(
          RefactoringCoreMessages.ReorgPolicy_copy_package);
      composite.markAsSynthetic();
      IProjectFragment root = getDestinationAsProjectFragment();
      for (int i = 0; i < fragments.length; i++) {
        composite.add(createChange(fragments[i], root, nameProposer,
            newNameQueries));
        pm.worked(1);
      }
      pm.done();
      return composite;
View Full Code Here

TOP

Related Classes of org.eclipse.ltk.core.refactoring.CompositeChange

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.