Java 类org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor 实例源码

项目:che    文件:RenameTypeTest.java   
private RefactoringDescriptor initWithAllOptions(
    String oldName,
    String innerOldName,
    String innerNewName,
    boolean updateReferences,
    boolean updateTextualMatches,
    boolean updateSimilar,
    String nonJavaFiles,
    int matchStrategy)
    throws Exception, JavaModelException, CoreException {
  ICompilationUnit cu = createCUfromTestFile(getPackageP(), oldName);
  IType classA = getType(cu, innerOldName);
  RenameJavaElementDescriptor descriptor = createRefactoringDescriptor(classA, innerNewName);
  setTheOptions(
      descriptor,
      updateReferences,
      updateTextualMatches,
      updateSimilar,
      nonJavaFiles,
      matchStrategy);
  return descriptor;
}
项目:che    文件:RenameTypeTest.java   
private void setTheOptions(
    RenameJavaElementDescriptor descriptor,
    boolean updateReferences,
    boolean updateTextualMatches,
    boolean updateSimilar,
    String nonJavaFiles,
    int matchStrategy) {
  descriptor.setUpdateReferences(updateReferences);
  descriptor.setUpdateTextualOccurrences(updateTextualMatches);
  if (nonJavaFiles != null) {
    descriptor.setUpdateQualifiedNames(true);
    descriptor.setFileNamePatterns(nonJavaFiles);
  }
  descriptor.setUpdateSimilarDeclarations(updateSimilar);
  descriptor.setMatchStrategy(matchStrategy);
}
项目:che    文件:RenameTypeTest.java   
@Test
public void testSimilarElements24() throws Exception {
  // Test transplanter for ICompilationUnit and IFile

  ParticipantTesting.reset();
  ICompilationUnit cu = createCUfromTestFile(getPackageP(), "SomeClass");
  IType someClass = getType(cu, "SomeClass");
  IJavaElement[] someClassMembers = someClass.getChildren();

  RenameJavaElementDescriptor descriptor = createRefactoringDescriptor(someClass, "SomeNewClass");
  setTheOptions(descriptor, true, false, true, null, RenamingNameSuggestor.STRATEGY_EMBEDDED);
  Refactoring ref = createRefactoring(descriptor);
  RefactoringStatus status = performRefactoring(ref);
  Assert.assertNull("was supposed to pass", status);

  checkResultInClass("SomeNewClass");

  checkMappers(ref, someClass, "SomeNewClass.java", someClassMembers);
}
项目:che    文件:RenameStaticMethodTest.java   
@Test
public void test10() throws Exception {
  //        printTestDisabledMessage("bug 40628");
  //        if (true)   return;
  ICompilationUnit cuA = createCUfromTestFile(getPackageP(), "A");
  ICompilationUnit cuB = createCUfromTestFile(getPackageP(), "B");

  IType classB = getType(cuB, "B");
  IMethod method = classB.getMethod("method", new String[0]);
  RenameJavaElementDescriptor descriptor =
      RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(
          IJavaRefactorings.RENAME_METHOD);
  descriptor.setUpdateReferences(true);
  descriptor.setJavaElement(method);
  descriptor.setNewName("newmethod");

  assertEquals("was supposed to pass", null, performRefactoring(descriptor));
  assertEqualLines(
      "invalid renaming in A", getFileContents(getOutputTestFileName("A")), cuA.getSource());
  assertEqualLines(
      "invalid renaming in B", getFileContents(getOutputTestFileName("B")), cuB.getSource());
}
项目:che    文件:RenameStaticMethodTest.java   
@Test
public void test11() throws Exception {
  //        printTestDisabledMessage("bug 40452");
  //        if (true)   return;
  IPackageFragment packageA =
      getRoot().createPackageFragment("a", false, new NullProgressMonitor());
  IPackageFragment packageB =
      getRoot().createPackageFragment("b", false, new NullProgressMonitor());
  ICompilationUnit cuA = createCUfromTestFile(packageA, "A");
  ICompilationUnit cuB = createCUfromTestFile(packageB, "B");

  IType classA = getType(cuA, "A");
  IMethod method = classA.getMethod("method2", new String[0]);
  RenameJavaElementDescriptor descriptor =
      RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(
          IJavaRefactorings.RENAME_METHOD);
  descriptor.setUpdateReferences(true);
  descriptor.setJavaElement(method);
  descriptor.setNewName("fred");

  assertEquals("was supposed to pass", null, performRefactoring(descriptor));
  assertEqualLines(
      "invalid renaming in A", getFileContents(getOutputTestFileName("A")), cuA.getSource());
  assertEqualLines(
      "invalid renaming in B", getFileContents(getOutputTestFileName("B")), cuB.getSource());
}
项目:che    文件:RenameMethodInInterfaceTest.java   
private void helper1_0(String methodName, String newMethodName, String[] signatures)
    throws Exception {
  ICompilationUnit cu = createCUfromTestFile(getPackageP(), "A");
  IType interfaceI = getType(cu, "I");
  IMethod method = interfaceI.getMethod(methodName, signatures);

  RenameJavaElementDescriptor descriptor =
      RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(
          IJavaRefactorings.RENAME_METHOD);
  descriptor.setJavaElement(method);
  descriptor.setUpdateReferences(true);
  descriptor.setNewName(newMethodName);

  RefactoringStatus result = performRefactoring(descriptor);
  assertNotNull("precondition was supposed to fail", result);
}
项目:che    文件:RenamePrivateFieldTest.java   
private void helper1_0(
    String fieldName,
    String newFieldName,
    String typeName,
    boolean renameGetter,
    boolean renameSetter)
    throws Exception {
  IType declaringType = getType(createCUfromTestFile(getPackageP(), "A"), typeName);
  IField field = declaringType.getField(fieldName);
  RenameJavaElementDescriptor descriptor =
      RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(
          IJavaRefactorings.RENAME_FIELD);
  descriptor.setJavaElement(field);
  descriptor.setNewName(newFieldName);
  descriptor.setUpdateReferences(true);
  descriptor.setRenameGetters(renameGetter);
  descriptor.setRenameSetters(renameSetter);
  RefactoringStatus result = performRefactoring(descriptor);
  assertNotNull("precondition was supposed to fail", result);
}
项目:che    文件:RenameVirtualMethodInClassTest.java   
@Test
public void test18() throws Exception {
  ICompilationUnit cu = createCUfromTestFile(getPackageP(), "A");
  ICompilationUnit cuC = createCUfromTestFile(getPackageP(), "C");

  IType classB = getType(cu, "B");
  IMethod method = classB.getMethod("m", new String[] {"I"});

  final RenameJavaElementDescriptor descriptor =
      RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(
          IJavaRefactorings.RENAME_METHOD);
  descriptor.setJavaElement(method);
  descriptor.setNewName("kk");
  descriptor.setUpdateReferences(true);
  final RefactoringStatus status = new RefactoringStatus();
  final Refactoring refactoring = descriptor.createRefactoring(status);
  assertNotNull("Refactoring should not be null", refactoring);
  assertTrue("status should be ok", status.isOK());

  assertEquals("was supposed to pass", null, performRefactoring(refactoring));
  assertEqualLines(
      "invalid renaming A", getFileContents(getOutputTestFileName("A")), cu.getSource());
  assertEqualLines(
      "invalid renaming C", getFileContents(getOutputTestFileName("C")), cuC.getSource());
}
项目:che    文件:RenameVirtualMethodInClassTest.java   
@Test
public void test40() throws Exception { // test for bug 68592
  ICompilationUnit cu = createCUfromTestFile(getPackageP(), "A");
  IType localClass = cu.getType("A").getMethod("doit", new String[0]).getType("LocalClass", 1);
  IMethod method = localClass.getMethod("method", new String[] {"I"});

  final RenameJavaElementDescriptor descriptor =
      RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(
          IJavaRefactorings.RENAME_METHOD);
  descriptor.setJavaElement(method);
  descriptor.setNewName("method2");
  descriptor.setUpdateReferences(true);
  final RefactoringStatus status = new RefactoringStatus();
  final Refactoring refactoring = descriptor.createRefactoring(status);
  assertNotNull("Refactoring should not be null", refactoring);
  assertTrue("status should be ok", status.isOK());

  assertEquals("was supposed to pass", null, performRefactoring(refactoring));
  assertEqualLines(
      "invalid renaming A", getFileContents(getOutputTestFileName("A")), cu.getSource());
}
项目:che    文件:RenamePackageProcessor.java   
@Override
public Change createChange(IProgressMonitor monitor) throws CoreException {
  try {
    monitor.beginTask(RefactoringCoreMessages.RenamePackageRefactoring_creating_change, 1);
    final RenameJavaElementDescriptor descriptor = createRefactoringDescriptor();
    final DynamicValidationRefactoringChange result =
        new DynamicValidationRefactoringChange(
            descriptor, RefactoringCoreMessages.RenamePackageRefactoring_change_name);
    result.addAll(fChangeManager.getAllChanges());
    fRenamePackageChange =
        new RenamePackageChange(fPackage, getNewElementName(), fRenameSubpackages);
    result.add(fRenamePackageChange);
    monitor.worked(1);
    return result;
  } finally {
    fChangeManager = null;
    fImportsManager = null;
    monitor.done();
  }
}
项目:gwt-eclipse-plugin    文件:PairedInterfaceRenameParticipant.java   
@Override
protected void configureDescriptor(RenameJavaElementDescriptor descriptor) {
  descriptor.setJavaElement(pairedType);
  descriptor.setNewName(pairedNewName);
  descriptor.setProject(pairedType.getJavaProject().getProject().getName());

  // getFilePatterns and getMatchStrategy could return uninitialized values
  // if they have not been explicitly set

  String filePatterns = processor.getFilePatterns();
  if (filePatterns != null) {
    descriptor.setFileNamePatterns(filePatterns);
  }

  int strategy = processor.getMatchStrategy();
  if (strategy == RenameJavaElementDescriptor.STRATEGY_EXACT
      || strategy == RenameJavaElementDescriptor.STRATEGY_EMBEDDED
      || strategy == RenameJavaElementDescriptor.STRATEGY_SUFFIX) {
    descriptor.setMatchStrategy(strategy);
  }

  descriptor.setUpdateQualifiedNames(processor.getUpdateQualifiedNames());
  descriptor.setUpdateReferences(processor.getUpdateReferences());
  descriptor.setUpdateSimilarDeclarations(processor.getUpdateSimilarDeclarations());
  descriptor.setUpdateTextualOccurrences(processor.getUpdateTextualMatches());
}
项目:Eclipse-Postfix-Code-Completion    文件:RenameSourceFolderProcessor.java   
@Override
public Change createChange(IProgressMonitor monitor) throws CoreException {
    monitor.beginTask(RefactoringCoreMessages.RenameTypeRefactoring_creating_change, 1);
    try {
        final IResource resource= fSourceFolder.getResource();
        final String project= resource.getProject().getName();
        final String newName= getNewElementName();
        final String description= Messages.format(RefactoringCoreMessages.RenameSourceFolderChange_descriptor_description_short, JavaElementLabels.getElementLabel(fSourceFolder, JavaElementLabels.ALL_DEFAULT));
        final String header= Messages.format(RefactoringCoreMessages.RenameSourceFolderChange_descriptor_description, new String[] { BasicElementLabels.getPathLabel(resource.getFullPath(), false), BasicElementLabels.getJavaElementName(newName)});
        final String comment= new JDTRefactoringDescriptorComment(project, this, header).asString();
        final RenameJavaElementDescriptor descriptor= RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_SOURCE_FOLDER);
        descriptor.setProject(project);
        descriptor.setDescription(description);
        descriptor.setComment(comment);
        descriptor.setFlags(RefactoringDescriptor.NONE);
        descriptor.setJavaElement(fSourceFolder);
        descriptor.setNewName(newName);
        return new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.RenameSourceFolderRefactoring_rename, new Change[] { new RenameSourceFolderChange(fSourceFolder, newName)});
    } finally {
        monitor.done();
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:RenameLocalVariableProcessor.java   
private RenameJavaElementDescriptor createRefactoringDescriptor() {
    String project= null;
    IJavaProject javaProject= fCu.getJavaProject();
    if (javaProject != null)
        project= javaProject.getElementName();
    final String header= Messages.format(RefactoringCoreMessages.RenameLocalVariableProcessor_descriptor_description, new String[] { BasicElementLabels.getJavaElementName(fCurrentName), JavaElementLabels.getElementLabel(fLocalVariable.getParent(), JavaElementLabels.ALL_FULLY_QUALIFIED), BasicElementLabels.getJavaElementName(fNewName)});
    final String description= Messages.format(RefactoringCoreMessages.RenameLocalVariableProcessor_descriptor_description_short, BasicElementLabels.getJavaElementName(fCurrentName));
    final String comment= new JDTRefactoringDescriptorComment(project, this, header).asString();
    final RenameJavaElementDescriptor descriptor= RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_LOCAL_VARIABLE);
    descriptor.setProject(project);
    descriptor.setDescription(description);
    descriptor.setComment(comment);
    descriptor.setFlags(RefactoringDescriptor.NONE);
    descriptor.setJavaElement(fLocalVariable);
    descriptor.setNewName(getNewElementName());
    descriptor.setUpdateReferences(fUpdateReferences);
    return descriptor;
}
项目:Eclipse-Postfix-Code-Completion    文件:RenameJavaProjectProcessor.java   
@Override
public Change createChange(IProgressMonitor monitor) throws CoreException {
    try {
        monitor.beginTask("", 1); //$NON-NLS-1$
        final String description= Messages.format(RefactoringCoreMessages.RenameJavaProjectProcessor_descriptor_description_short, BasicElementLabels.getJavaElementName(fProject.getElementName()));
        final String header= Messages.format(RefactoringCoreMessages.RenameJavaProjectChange_descriptor_description, new String[] { BasicElementLabels.getJavaElementName(fProject.getElementName()), BasicElementLabels.getJavaElementName(getNewElementName())});
        final String comment= new JDTRefactoringDescriptorComment(null, this, header).asString();
        final int flags= RefactoringDescriptor.STRUCTURAL_CHANGE | RefactoringDescriptor.MULTI_CHANGE | RefactoringDescriptor.BREAKING_CHANGE;
        final RenameJavaElementDescriptor descriptor= RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_JAVA_PROJECT);
        descriptor.setProject(null);
        descriptor.setDescription(description);
        descriptor.setComment(comment);
        descriptor.setFlags(flags);
        descriptor.setJavaElement(fProject);
        descriptor.setNewName(getNewElementName());
        descriptor.setUpdateReferences(fUpdateReferences);
        return new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.RenameJavaProjectRefactoring_rename, new Change[] { new RenameJavaProjectChange(fProject, getNewElementName(), fUpdateReferences)});
    } finally {
        monitor.done();
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:RenamePackageProcessor.java   
@Override
public Change createChange(IProgressMonitor monitor) throws CoreException {
    try {
        monitor.beginTask(RefactoringCoreMessages.RenamePackageRefactoring_creating_change, 1);
        final RenameJavaElementDescriptor descriptor= createRefactoringDescriptor();
        final DynamicValidationRefactoringChange result= new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.RenamePackageRefactoring_change_name);
        result.addAll(fChangeManager.getAllChanges());
        fRenamePackageChange= new RenamePackageChange( fPackage, getNewElementName(),  fRenameSubpackages);
        result.add(fRenamePackageChange);
        monitor.worked(1);
        return result;
    } finally {
        fChangeManager= null;
        fImportsManager= null;
        monitor.done();
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:RenamePackageProcessor.java   
private RenameJavaElementDescriptor createRefactoringDescriptor() {
    String project= null;
    IJavaProject javaProject= fPackage.getJavaProject();
    if (javaProject != null)
        project= javaProject.getElementName();
    final int flags= JavaRefactoringDescriptor.JAR_MIGRATION | JavaRefactoringDescriptor.JAR_REFACTORING | RefactoringDescriptor.STRUCTURAL_CHANGE | RefactoringDescriptor.MULTI_CHANGE;
    final String description= Messages.format(RefactoringCoreMessages.RenamePackageProcessor_descriptor_description_short, getElementLabel(fPackage));
    final String header= Messages.format(RefactoringCoreMessages.RenamePackageProcessor_descriptor_description, new String[] { getElementLabel(fPackage), getNewElementName()});
    final JDTRefactoringDescriptorComment comment= new JDTRefactoringDescriptorComment(project, this, header);
    if (fRenameSubpackages)
        comment.addSetting(RefactoringCoreMessages.RenamePackageProcessor_rename_subpackages);
    final RenameJavaElementDescriptor descriptor= RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_PACKAGE);
    descriptor.setProject(project);
    descriptor.setDescription(description);
    descriptor.setComment(comment.asString());
    descriptor.setFlags(flags);
    descriptor.setJavaElement(fPackage);
    descriptor.setNewName(getNewElementName());
    descriptor.setUpdateReferences(fUpdateReferences);
    descriptor.setUpdateTextualOccurrences(fUpdateTextualMatches);
    descriptor.setUpdateQualifiedNames(fUpdateQualifiedNames);
    if (fUpdateQualifiedNames && fFilePatterns != null && !"".equals(fFilePatterns)) //$NON-NLS-1$
        descriptor.setFileNamePatterns(fFilePatterns);
    descriptor.setUpdateHierarchy(fRenameSubpackages);
    return descriptor;
}
项目:ImportSmaliVarNames    文件:RefactoringHelper.java   
public static void renameVariable(String task, IJavaElement element, String new_name) {
    RefactoringStatus status = new RefactoringStatus();

    RefactoringContribution contrib = RefactoringCore
            .getRefactoringContribution(IJavaRefactorings.RENAME_LOCAL_VARIABLE);
    RenameJavaElementDescriptor rnDesc = (RenameJavaElementDescriptor) contrib.createDescriptor();
    rnDesc.setFlags(JavaRefactoringDescriptor.JAR_MIGRATION | JavaRefactoringDescriptor.JAR_REFACTORING);
    rnDesc.setProject(element.getJavaProject().getProject().getName());
    rnDesc.setUpdateReferences(true);
    rnDesc.setJavaElement(element);
    rnDesc.setNewName(new_name);

    Refactoring ref;
    try {
        ref = rnDesc.createRefactoring(status);
        ref.checkInitialConditions(NULL_MON);
        ref.checkFinalConditions(NULL_MON);

        Change change = ref.createChange(NULL_MON);
        change.perform(NULL_MON);
    } catch (CoreException e) {
        e.printStackTrace();
    }

}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:RenameSourceFolderProcessor.java   
@Override
public Change createChange(IProgressMonitor monitor) throws CoreException {
    monitor.beginTask(RefactoringCoreMessages.RenameTypeRefactoring_creating_change, 1);
    try {
        final IResource resource= fSourceFolder.getResource();
        final String project= resource.getProject().getName();
        final String newName= getNewElementName();
        final String description= Messages.format(RefactoringCoreMessages.RenameSourceFolderChange_descriptor_description_short, JavaElementLabels.getElementLabel(fSourceFolder, JavaElementLabels.ALL_DEFAULT));
        final String header= Messages.format(RefactoringCoreMessages.RenameSourceFolderChange_descriptor_description, new String[] { BasicElementLabels.getPathLabel(resource.getFullPath(), false), BasicElementLabels.getJavaElementName(newName)});
        final String comment= new JDTRefactoringDescriptorComment(project, this, header).asString();
        final RenameJavaElementDescriptor descriptor= RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_SOURCE_FOLDER);
        descriptor.setProject(project);
        descriptor.setDescription(description);
        descriptor.setComment(comment);
        descriptor.setFlags(RefactoringDescriptor.NONE);
        descriptor.setJavaElement(fSourceFolder);
        descriptor.setNewName(newName);
        return new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.RenameSourceFolderRefactoring_rename, new Change[] { new RenameSourceFolderChange(fSourceFolder, newName)});
    } finally {
        monitor.done();
    }
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:RenameLocalVariableProcessor.java   
private RenameJavaElementDescriptor createRefactoringDescriptor() {
    String project= null;
    IJavaProject javaProject= fCu.getJavaProject();
    if (javaProject != null)
        project= javaProject.getElementName();
    final String header= Messages.format(RefactoringCoreMessages.RenameLocalVariableProcessor_descriptor_description, new String[] { BasicElementLabels.getJavaElementName(fCurrentName), JavaElementLabels.getElementLabel(fLocalVariable.getParent(), JavaElementLabels.ALL_FULLY_QUALIFIED), BasicElementLabels.getJavaElementName(fNewName)});
    final String description= Messages.format(RefactoringCoreMessages.RenameLocalVariableProcessor_descriptor_description_short, BasicElementLabels.getJavaElementName(fCurrentName));
    final String comment= new JDTRefactoringDescriptorComment(project, this, header).asString();
    final RenameJavaElementDescriptor descriptor= RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_LOCAL_VARIABLE);
    descriptor.setProject(project);
    descriptor.setDescription(description);
    descriptor.setComment(comment);
    descriptor.setFlags(RefactoringDescriptor.NONE);
    descriptor.setJavaElement(fLocalVariable);
    descriptor.setNewName(getNewElementName());
    descriptor.setUpdateReferences(fUpdateReferences);
    return descriptor;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:RenameJavaProjectProcessor.java   
@Override
public Change createChange(IProgressMonitor monitor) throws CoreException {
    try {
        monitor.beginTask("", 1); //$NON-NLS-1$
        final String description= Messages.format(RefactoringCoreMessages.RenameJavaProjectProcessor_descriptor_description_short, BasicElementLabels.getJavaElementName(fProject.getElementName()));
        final String header= Messages.format(RefactoringCoreMessages.RenameJavaProjectChange_descriptor_description, new String[] { BasicElementLabels.getJavaElementName(fProject.getElementName()), BasicElementLabels.getJavaElementName(getNewElementName())});
        final String comment= new JDTRefactoringDescriptorComment(null, this, header).asString();
        final int flags= RefactoringDescriptor.STRUCTURAL_CHANGE | RefactoringDescriptor.MULTI_CHANGE | RefactoringDescriptor.BREAKING_CHANGE;
        final RenameJavaElementDescriptor descriptor= RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_JAVA_PROJECT);
        descriptor.setProject(null);
        descriptor.setDescription(description);
        descriptor.setComment(comment);
        descriptor.setFlags(flags);
        descriptor.setJavaElement(fProject);
        descriptor.setNewName(getNewElementName());
        descriptor.setUpdateReferences(fUpdateReferences);
        return new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.RenameJavaProjectRefactoring_rename, new Change[] { new RenameJavaProjectChange(fProject, getNewElementName(), fUpdateReferences)});
    } finally {
        monitor.done();
    }
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:RenamePackageProcessor.java   
@Override
public Change createChange(IProgressMonitor monitor) throws CoreException {
    try {
        monitor.beginTask(RefactoringCoreMessages.RenamePackageRefactoring_creating_change, 1);
        final RenameJavaElementDescriptor descriptor= createRefactoringDescriptor();
        final DynamicValidationRefactoringChange result= new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.RenamePackageRefactoring_change_name);
        result.addAll(fChangeManager.getAllChanges());
        fRenamePackageChange= new RenamePackageChange( fPackage, getNewElementName(),  fRenameSubpackages);
        result.add(fRenamePackageChange);
        monitor.worked(1);
        return result;
    } finally {
        fChangeManager= null;
        fImportsManager= null;
        monitor.done();
    }
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:RenamePackageProcessor.java   
private RenameJavaElementDescriptor createRefactoringDescriptor() {
    String project= null;
    IJavaProject javaProject= fPackage.getJavaProject();
    if (javaProject != null)
        project= javaProject.getElementName();
    final int flags= JavaRefactoringDescriptor.JAR_MIGRATION | JavaRefactoringDescriptor.JAR_REFACTORING | RefactoringDescriptor.STRUCTURAL_CHANGE | RefactoringDescriptor.MULTI_CHANGE;
    final String description= Messages.format(RefactoringCoreMessages.RenamePackageProcessor_descriptor_description_short, getElementLabel(fPackage));
    final String header= Messages.format(RefactoringCoreMessages.RenamePackageProcessor_descriptor_description, new String[] { getElementLabel(fPackage), getNewElementName()});
    final JDTRefactoringDescriptorComment comment= new JDTRefactoringDescriptorComment(project, this, header);
    if (fRenameSubpackages)
        comment.addSetting(RefactoringCoreMessages.RenamePackageProcessor_rename_subpackages);
    final RenameJavaElementDescriptor descriptor= RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_PACKAGE);
    descriptor.setProject(project);
    descriptor.setDescription(description);
    descriptor.setComment(comment.asString());
    descriptor.setFlags(flags);
    descriptor.setJavaElement(fPackage);
    descriptor.setNewName(getNewElementName());
    descriptor.setUpdateReferences(fUpdateReferences);
    descriptor.setUpdateTextualOccurrences(fUpdateTextualMatches);
    descriptor.setUpdateQualifiedNames(fUpdateQualifiedNames);
    if (fUpdateQualifiedNames && fFilePatterns != null && !"".equals(fFilePatterns)) //$NON-NLS-1$
        descriptor.setFileNamePatterns(fFilePatterns);
    descriptor.setUpdateHierarchy(fRenameSubpackages);
    return descriptor;
}
项目:che    文件:RenameTypeTest.java   
private RenameJavaElementDescriptor createRefactoringDescriptor(IType type, String newName) {
  RenameJavaElementDescriptor descriptor =
      RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(
          IJavaRefactorings.RENAME_TYPE);
  descriptor.setJavaElement(type);
  descriptor.setNewName(newName);
  descriptor.setUpdateReferences(true);
  return descriptor;
}
项目:che    文件:RenameTypeTest.java   
private String[] helperWithTextual(
    String oldCuName,
    String oldName,
    String newName,
    String newCUName,
    boolean updateReferences,
    boolean updateTextualMatches)
    throws Exception {
  ICompilationUnit cu = createCUfromTestFile(getPackageP(), oldCuName);
  IType classA = getType(cu, oldName);
  IJavaElement[] classAMembers = classA.getChildren();

  IPackageFragment pack = (IPackageFragment) cu.getParent();
  String[] renameHandles = null;
  if (classA.getDeclaringType() == null
      && cu.getElementName().startsWith(classA.getElementName())) {
    renameHandles = ParticipantTesting.createHandles(classA, cu, cu.getResource());
  } else {
    renameHandles = ParticipantTesting.createHandles(classA);
  }
  RenameJavaElementDescriptor descriptor = createRefactoringDescriptor(classA, newName);
  descriptor.setUpdateReferences(updateReferences);
  descriptor.setUpdateTextualOccurrences(updateTextualMatches);
  Refactoring refactoring = createRefactoring(descriptor);
  assertEquals("was supposed to pass", null, performRefactoring(refactoring));
  ICompilationUnit newcu = pack.getCompilationUnit(newCUName + ".java");
  TestCase.assertTrue("cu " + newcu.getElementName() + " does not exist", newcu.exists());
  assertEqualLines(
      "invalid renaming", getFileContents(getOutputTestFileName(newCUName)), newcu.getSource());

  INameUpdating nameUpdating = ((INameUpdating) refactoring.getAdapter(INameUpdating.class));
  IType newElement = (IType) nameUpdating.getNewElement();
  TestCase.assertTrue(
      "new element does not exist:\n" + newElement.toString(), newElement.exists());

  checkMappers(refactoring, classA, newCUName + ".java", classAMembers);

  return renameHandles;
}
项目:che    文件:RenameStaticMethodTest.java   
private void helper1_0(String methodName, String newMethodName, String[] signatures)
    throws Exception {
  IType classA = getType(createCUfromTestFile(getPackageP(), "A"), "A");
  IMethod method = classA.getMethod(methodName, signatures);
  RenameJavaElementDescriptor descriptor =
      RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(
          IJavaRefactorings.RENAME_METHOD);
  descriptor.setJavaElement(method);
  descriptor.setNewName(newMethodName);
  descriptor.setUpdateReferences(true);
  RefactoringStatus result = performRefactoring(descriptor);
  assertNotNull("precondition was supposed to fail", result);
}
项目:che    文件:RenameStaticMethodTest.java   
private void helper2_0(
    String methodName,
    String newMethodName,
    String[] signatures,
    boolean updateReferences,
    boolean createDelegate)
    throws Exception {
  ICompilationUnit cu = createCUfromTestFile(getPackageP(), "A");
  IType classA = getType(cu, "A");
  IMethod method = classA.getMethod(methodName, signatures);
  RenameJavaElementDescriptor descriptor =
      RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(
          IJavaRefactorings.RENAME_METHOD);
  descriptor.setUpdateReferences(updateReferences);
  descriptor.setJavaElement(method);
  descriptor.setNewName(newMethodName);
  descriptor.setKeepOriginal(createDelegate);
  descriptor.setDeprecateDelegate(true);

  assertEquals("was supposed to pass", null, performRefactoring(descriptor));
  assertEqualLines(
      "invalid renaming", getFileContents(getOutputTestFileName("A")), cu.getSource());

  assertTrue("anythingToUndo", RefactoringCore.getUndoManager().anythingToUndo());
  assertTrue("! anythingToRedo", !RefactoringCore.getUndoManager().anythingToRedo());
  // assertEquals("1 to undo", 1, Refactoring.getUndoManager().getRefactoringLog().size());

  RefactoringCore.getUndoManager().performUndo(null, new NullProgressMonitor());
  assertEqualLines("invalid undo", getFileContents(getInputTestFileName("A")), cu.getSource());

  assertTrue("! anythingToUndo", !RefactoringCore.getUndoManager().anythingToUndo());
  assertTrue("anythingToRedo", RefactoringCore.getUndoManager().anythingToRedo());
  // assertEquals("1 to redo", 1, Refactoring.getUndoManager().getRedoStack().size());

  RefactoringCore.getUndoManager().performRedo(null, new NullProgressMonitor());
  assertEqualLines("invalid redo", getFileContents(getOutputTestFileName("A")), cu.getSource());
}
项目:che    文件:RenamePackageTest.java   
private RenameJavaElementDescriptor createRefactoringDescriptor(
    IPackageFragment pack, String newName) {
  RenameJavaElementDescriptor descriptor =
      RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(
          IJavaRefactorings.RENAME_PACKAGE);
  descriptor.setJavaElement(pack);
  descriptor.setNewName(newName);
  descriptor.setUpdateReferences(true);
  return descriptor;
}
项目:che    文件:RenamePackageTest.java   
@Test
public void testPackageRenameWithResource1() throws Exception {
  IPackageFragment fragment = getRoot().createPackageFragment("org.test", true, null);

  StringBuffer buf = new StringBuffer();
  buf.append("package org.test;\n");
  buf.append("public class MyClass {\n");
  buf.append("  org.test.MyClass me;\n");
  buf.append("}\n");
  fragment.createCompilationUnit("MyClass.java", buf.toString(), true, null);

  IFile file = ((IFolder) getRoot().getResource()).getFile("x.properties");
  byte[] content = "This is about 'org.test' and more".getBytes();
  file.create(new ByteArrayInputStream(content), true, null);
  file.refreshLocal(IResource.DEPTH_ONE, null);

  RenameJavaElementDescriptor descriptor =
      RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(
          IJavaRefactorings.RENAME_PACKAGE);
  descriptor.setJavaElement(fragment);
  descriptor.setNewName("org.test2");
  descriptor.setUpdateReferences(true);
  descriptor.setUpdateQualifiedNames(true);
  descriptor.setFileNamePatterns("*.properties");
  Refactoring refactoring = createRefactoring(descriptor);
  RefactoringStatus status = performRefactoring(refactoring);
  if (status != null) assertTrue(status.toString(), status.isOK());

  RefactoringProcessor processor = ((RenameRefactoring) refactoring).getProcessor();
  IResourceMapper rm = (IResourceMapper) processor.getAdapter(IResourceMapper.class);
  IJavaElementMapper jm = (IJavaElementMapper) processor.getAdapter(IJavaElementMapper.class);
  checkMappingUnchanged(jm, rm, new Object[] {getRoot().getJavaProject(), getRoot(), file});
  IFile newFile = ((IContainer) getRoot().getResource()).getFile(new Path("x.properties"));
  assertEquals("This is about 'org.test2' and more", getContents(newFile));
  checkMappingChanged(
      jm, rm, new Object[][] {{fragment, getRoot().getPackageFragment("org.test2")}});
}
项目:che    文件:RenamePackageTest.java   
@Test
public void testPackageRenameWithResource2() throws Exception {
  IPackageFragment fragment = getRoot().createPackageFragment("org.test", true, null);

  StringBuffer buf = new StringBuffer();
  buf.append("package org.test;\n");
  buf.append("public class MyClass {\n");
  buf.append("}\n");
  fragment.createCompilationUnit("MyClass.java", buf.toString(), true, null);

  IFile file = ((IFolder) fragment.getResource()).getFile("x.properties");
  byte[] content = "This is about 'org.test' and more".getBytes();
  file.create(new ByteArrayInputStream(content), true, null);
  file.refreshLocal(IResource.DEPTH_ONE, null);

  RenameJavaElementDescriptor descriptor =
      RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(
          IJavaRefactorings.RENAME_PACKAGE);
  descriptor.setJavaElement(fragment);
  descriptor.setNewName("org.test2");
  descriptor.setUpdateReferences(true);
  descriptor.setUpdateHierarchy(true);
  descriptor.setUpdateQualifiedNames(true);
  descriptor.setFileNamePatterns("*.properties");
  Refactoring refactoring = createRefactoring(descriptor);
  RefactoringStatus status = performRefactoring(refactoring);
  if (status != null) assertTrue(status.toString(), status.isOK());

  RefactoringProcessor processor = ((RenameRefactoring) refactoring).getProcessor();
  IResourceMapper rm = (IResourceMapper) processor.getAdapter(IResourceMapper.class);
  IJavaElementMapper jm = (IJavaElementMapper) processor.getAdapter(IJavaElementMapper.class);
  checkMappingUnchanged(jm, rm, new Object[] {getRoot().getJavaProject(), getRoot()});
  IPackageFragment newFragment = getRoot().getPackageFragment("org.test2");
  IFile newFile = ((IContainer) newFragment.getResource()).getFile(new Path("x.properties"));
  assertEquals("This is about 'org.test2' and more", getContents(newFile));
  checkMappingChanged(jm, rm, new Object[][] {{file, newFile}});
}
项目:che    文件:RenamePackageTest.java   
public void createAndPerform(int expectedSeverity) throws CoreException, Exception {
  IPackageFragment thisPackage = fPackages[0];
  RenameJavaElementDescriptor descriptor =
      createRefactoringDescriptor(thisPackage, fNewPackageName);
  descriptor.setUpdateReferences(fUpdateReferences);
  descriptor.setUpdateTextualOccurrences(fUpdateTextualMatches);
  setFilePatterns(descriptor);
  descriptor.setUpdateHierarchy(fRenameSubpackages);
  RefactoringStatus result = performRefactoring(descriptor);
  if (expectedSeverity == RefactoringStatus.OK)
    TestCase.assertEquals("preconditions were supposed to pass", null, result);
  else TestCase.assertEquals(expectedSeverity, result.getSeverity());
}
项目:che    文件:RenameNonPrivateFieldTest.java   
private void helper1_0(String fieldName, String newFieldName) throws Exception {
  IType classA = getType(createCUfromTestFile(getPackageP(), "A"), "A");
  IField field = classA.getField(fieldName);
  RenameJavaElementDescriptor descriptor =
      RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(
          IJavaRefactorings.RENAME_FIELD);
  descriptor.setJavaElement(field);
  descriptor.setUpdateReferences(true);
  descriptor.setNewName(newFieldName);
  RefactoringStatus result = performRefactoring(descriptor);
  assertNotNull("precondition was supposed to fail", result);
}
项目:che    文件:RenameSupport.java   
private RenameSupport(RenameJavaElementDescriptor descriptor) throws CoreException {
  RefactoringStatus refactoringStatus = new RefactoringStatus();
  fRefactoring = (RenameRefactoring) descriptor.createRefactoring(refactoringStatus);
  if (refactoringStatus.hasFatalError()) {
    fPreCheckStatus = refactoringStatus;
  } else {
    preCheck();
    refactoringStatus.merge(fPreCheckStatus);
    fPreCheckStatus = refactoringStatus;
  }
}
项目:che    文件:RenameLocalVariableProcessor.java   
@Override
public Change createChange(IProgressMonitor monitor) throws CoreException {
  try {
    monitor.beginTask(RefactoringCoreMessages.RenameTypeProcessor_creating_changes, 1);

    RenameJavaElementDescriptor descriptor = createRefactoringDescriptor();
    fChange.setDescriptor(new RefactoringChangeDescriptor(descriptor));
    return fChange;
  } finally {
    monitor.done();
  }
}
项目:che    文件:RenameLocalVariableProcessor.java   
private RenameJavaElementDescriptor createRefactoringDescriptor() {
  String project = null;
  IJavaProject javaProject = fCu.getJavaProject();
  if (javaProject != null) project = javaProject.getElementName();
  final String header =
      Messages.format(
          RefactoringCoreMessages.RenameLocalVariableProcessor_descriptor_description,
          new String[] {
            BasicElementLabels.getJavaElementName(fCurrentName),
            JavaElementLabels.getElementLabel(
                fLocalVariable.getParent(), JavaElementLabels.ALL_FULLY_QUALIFIED),
            BasicElementLabels.getJavaElementName(fNewName)
          });
  final String description =
      Messages.format(
          RefactoringCoreMessages.RenameLocalVariableProcessor_descriptor_description_short,
          BasicElementLabels.getJavaElementName(fCurrentName));
  final String comment = new JDTRefactoringDescriptorComment(project, this, header).asString();
  final RenameJavaElementDescriptor descriptor =
      RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(
          IJavaRefactorings.RENAME_LOCAL_VARIABLE);
  descriptor.setProject(project);
  descriptor.setDescription(description);
  descriptor.setComment(comment);
  descriptor.setFlags(RefactoringDescriptor.NONE);
  descriptor.setJavaElement(fLocalVariable);
  descriptor.setNewName(getNewElementName());
  descriptor.setUpdateReferences(fUpdateReferences);
  return descriptor;
}
项目:che    文件:RenameFieldProcessor.java   
@Override
public Change createChange(IProgressMonitor monitor) throws CoreException {
  try {
    monitor.beginTask(RefactoringCoreMessages.RenameFieldRefactoring_checking, 1);
    TextChange[] changes = fChangeManager.getAllChanges();
    RenameJavaElementDescriptor descriptor = createRefactoringDescriptor();
    return new DynamicValidationRefactoringChange(descriptor, getProcessorName(), changes);
  } finally {
    monitor.done();
  }
}
项目:che    文件:RenamePackageProcessor.java   
private RenameJavaElementDescriptor createRefactoringDescriptor() {
  String project = null;
  IJavaProject javaProject = fPackage.getJavaProject();
  if (javaProject != null) project = javaProject.getElementName();
  final int flags =
      JavaRefactoringDescriptor.JAR_MIGRATION
          | JavaRefactoringDescriptor.JAR_REFACTORING
          | RefactoringDescriptor.STRUCTURAL_CHANGE
          | RefactoringDescriptor.MULTI_CHANGE;
  final String description =
      Messages.format(
          RefactoringCoreMessages.RenamePackageProcessor_descriptor_description_short,
          getElementLabel(fPackage));
  final String header =
      Messages.format(
          RefactoringCoreMessages.RenamePackageProcessor_descriptor_description,
          new String[] {getElementLabel(fPackage), getNewElementName()});
  final JDTRefactoringDescriptorComment comment =
      new JDTRefactoringDescriptorComment(project, this, header);
  if (fRenameSubpackages)
    comment.addSetting(RefactoringCoreMessages.RenamePackageProcessor_rename_subpackages);
  final RenameJavaElementDescriptor descriptor =
      RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(
          IJavaRefactorings.RENAME_PACKAGE);
  descriptor.setProject(project);
  descriptor.setDescription(description);
  descriptor.setComment(comment.asString());
  descriptor.setFlags(flags);
  descriptor.setJavaElement(fPackage);
  descriptor.setNewName(getNewElementName());
  descriptor.setUpdateReferences(fUpdateReferences);
  descriptor.setUpdateTextualOccurrences(fUpdateTextualMatches);
  descriptor.setUpdateQualifiedNames(fUpdateQualifiedNames);
  if (fUpdateQualifiedNames && fFilePatterns != null && !"".equals(fFilePatterns)) // $NON-NLS-1$
  descriptor.setFileNamePatterns(fFilePatterns);
  descriptor.setUpdateHierarchy(fRenameSubpackages);
  return descriptor;
}
项目:gwt-eclipse-plugin    文件:PairedMethodRenameParticipant.java   
public MethodRenameChangeBuilder(IMethod method, String newName,
    RenameVirtualMethodProcessor processor, IWorkspace workspace) {
  super(RenameJavaElementDescriptor.class, IJavaRefactorings.RENAME_METHOD,
      workspace);

  this.newName = newName;
  this.processor = processor;
  this.method = method;
}
项目:gwt-eclipse-plugin    文件:PairedMethodRenameParticipant.java   
@Override
protected void configureDescriptor(RenameJavaElementDescriptor descriptor) {
  descriptor.setJavaElement(method);
  descriptor.setNewName(newName);
  descriptor.setProject(method.getJavaProject().getProject().getName());
  descriptor.setKeepOriginal(processor.getDelegateUpdating());
  descriptor.setDeprecateDelegate(processor.getDeprecateDelegates());
  descriptor.setUpdateReferences(processor.getUpdateReferences());
}
项目:gwt-eclipse-plugin    文件:PairedInterfaceRenameParticipant.java   
public InterfaceRenameChangeBuilder(IType pairedType, String pairedNewName,
    RenameTypeProcessor processor, IWorkspace workspace) {
  super(RenameJavaElementDescriptor.class, IJavaRefactorings.RENAME_TYPE,
      workspace);

  this.processor = processor;
  this.pairedType = pairedType;
  this.pairedNewName = pairedNewName;
}
项目:Eclipse-Postfix-Code-Completion    文件:RenameLocalVariableProcessor.java   
@Override
public Change createChange(IProgressMonitor monitor) throws CoreException {
    try {
        monitor.beginTask(RefactoringCoreMessages.RenameTypeProcessor_creating_changes, 1);

        RenameJavaElementDescriptor descriptor= createRefactoringDescriptor();
        fChange.setDescriptor(new RefactoringChangeDescriptor(descriptor));
        return fChange;
    } finally {
        monitor.done();
    }
}