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

项目: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    文件: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    文件:IntroduceParameterObjectDescriptor.java   
/**
 * Creates a new refactoring descriptor.
 *
 * @param project the non-empty name of the project associated with this refactoring, or <code>
 *     null</code> for a workspace refactoring
 * @param description a non-empty human-readable description of the particular refactoring
 *     instance
 * @param comment the human-readable comment of the particular refactoring instance, or <code>null
 *     </code> for no comment
 * @param arguments a map of arguments that will be persisted and describes all settings for this
 *     refactoring
 * @param flags the flags of the refactoring descriptor
 * @throws IllegalArgumentException if the argument map contains invalid keys/values
 */
public IntroduceParameterObjectDescriptor(
    final String project,
    final String description,
    final String comment,
    final Map arguments,
    final int flags)
    throws IllegalArgumentException {
  super(
      IJavaRefactorings.INTRODUCE_PARAMETER_OBJECT,
      project,
      description,
      comment,
      arguments,
      flags);
  initializeFromMap(arguments);
}
项目:che    文件:RenameJavaElementDescriptor.java   
/**
 * Checks whether the refactoring id is valid.
 *
 * @param id the refactoring id
 * @return the outcome of the validation
 */
private boolean checkId(final String id) {
  Assert.isNotNull(id);
  if (id.equals(IJavaRefactorings.RENAME_COMPILATION_UNIT)) return true;
  else if (id.equals(IJavaRefactorings.RENAME_ENUM_CONSTANT)) return true;
  else if (id.equals(IJavaRefactorings.RENAME_FIELD)) return true;
  else if (id.equals(IJavaRefactorings.RENAME_JAVA_PROJECT)) return true;
  else if (id.equals(IJavaRefactorings.RENAME_LOCAL_VARIABLE)) return true;
  else if (id.equals(IJavaRefactorings.RENAME_METHOD)) return true;
  else if (id.equals(IJavaRefactorings.RENAME_PACKAGE)) return true;
  else if (id.equals(RENAME_RESOURCE)) return true;
  else if (id.equals(IJavaRefactorings.RENAME_SOURCE_FOLDER)) return true;
  else if (id.equals(IJavaRefactorings.RENAME_TYPE)) return true;
  else if (id.equals(IJavaRefactorings.RENAME_TYPE_PARAMETER)) return true;
  return false;
}
项目:che    文件:ExtractClassDescriptor.java   
/**
 * Creates a new refactoring descriptor.
 *
 * @param project the non-empty name of the project associated with this refactoring, or <code>
 *     null</code> for a workspace refactoring
 * @param description a non-empty human-readable description of the particular refactoring
 *     instance
 * @param comment the human-readable comment of the particular refactoring instance, or <code>null
 *     </code> for no comment
 * @param arguments a map of arguments that will be persisted and describes all settings for this
 *     refactoring
 * @param flags the flags of the refactoring descriptor
 * @throws IllegalArgumentException if the argument map contains invalid keys/values
 */
public ExtractClassDescriptor(
    String project, String description, String comment, Map arguments, int flags)
    throws IllegalArgumentException {
  super(IJavaRefactorings.EXTRACT_CLASS, project, description, comment, arguments, flags);
  if (JavaRefactoringDescriptorUtil.getString(arguments, OLD_FIELD_COUNT, true) != null) {
    String[] oldFieldNames =
        JavaRefactoringDescriptorUtil.getStringArray(
            arguments, OLD_FIELD_COUNT, OLD_FIELD_NAME, 0);
    boolean[] createField =
        JavaRefactoringDescriptorUtil.getBooleanArray(
            arguments, CREATE_FIELD_COUNT, CREATE_FIELD, 0);
    fFields = new Field[oldFieldNames.length];
    for (int i = 0; i < oldFieldNames.length; i++) {
      fFields[i] = new Field(oldFieldNames[i]);
      fFields[i].setCreateField(createField[i]);
      if (createField[i])
        fFields[i].setNewFieldName(
            JavaRefactoringDescriptorUtil.getString(
                arguments, JavaRefactoringDescriptorUtil.getAttributeName(NEW_FIELD_NAME, i)));
    }
  }
}
项目: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());
}
项目: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;
}
项目: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    文件: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    文件:InferTypeArgumentsRefactoring.java   
private RefactoringStatus initialize(JavaRefactoringArguments arguments) {
  final String clone = arguments.getAttribute(ATTRIBUTE_CLONE);
  if (clone != null) {
    fAssumeCloneReturnsSameType = Boolean.valueOf(clone).booleanValue();
  } else
    return RefactoringStatus.createFatalErrorStatus(
        Messages.format(
            RefactoringCoreMessages.InitializableRefactoring_argument_not_exist,
            ATTRIBUTE_CLONE));
  final String leave = arguments.getAttribute(ATTRIBUTE_LEAVE);
  if (leave != null) {
    fLeaveUnconstrainedRaw = Boolean.valueOf(leave).booleanValue();
  } else
    return RefactoringStatus.createFatalErrorStatus(
        Messages.format(
            RefactoringCoreMessages.InitializableRefactoring_argument_not_exist,
            ATTRIBUTE_LEAVE));
  int count = 1;
  final List<IJavaElement> elements = new ArrayList<IJavaElement>();
  String handle = null;
  String attribute = JavaRefactoringDescriptorUtil.ATTRIBUTE_ELEMENT + count;
  final RefactoringStatus status = new RefactoringStatus();
  while ((handle = arguments.getAttribute(attribute)) != null) {
    final IJavaElement element =
        JavaRefactoringDescriptorUtil.handleToElement(arguments.getProject(), handle, false);
    if (element == null || !element.exists())
      return JavaRefactoringDescriptorUtil.createInputFatalStatus(
          element, getName(), IJavaRefactorings.INFER_TYPE_ARGUMENTS);
    else elements.add(element);
    count++;
    attribute = JavaRefactoringDescriptorUtil.ATTRIBUTE_ELEMENT + count;
  }
  fElements = elements.toArray(new IJavaElement[elements.size()]);
  if (elements.isEmpty())
    return JavaRefactoringDescriptorUtil.createInputFatalStatus(
        null, getName(), IJavaRefactorings.INFER_TYPE_ARGUMENTS);
  if (!status.isOK()) return status;
  return new RefactoringStatus();
}
项目: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    文件:RenameCompilationUnitProcessor.java   
private RefactoringStatus initialize(JavaRefactoringArguments extended) {
  final String handle = extended.getAttribute(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT);
  if (handle == null) {
    return RefactoringStatus.createFatalErrorStatus(
        Messages.format(
            RefactoringCoreMessages.InitializableRefactoring_argument_not_exist,
            JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT));
  }

  final IJavaElement element =
      JavaRefactoringDescriptorUtil.handleToElement(extended.getProject(), handle, false);
  if (element == null
      || !element.exists()
      || element.getElementType() != IJavaElement.COMPILATION_UNIT)
    return JavaRefactoringDescriptorUtil.createInputFatalStatus(
        element, getProcessorName(), IJavaRefactorings.RENAME_COMPILATION_UNIT);

  final String name = extended.getAttribute(JavaRefactoringDescriptorUtil.ATTRIBUTE_NAME);
  if (name == null || name.length() == 0)
    return RefactoringStatus.createFatalErrorStatus(
        Messages.format(
            RefactoringCoreMessages.InitializableRefactoring_argument_not_exist,
            JavaRefactoringDescriptorUtil.ATTRIBUTE_NAME));

  fCu = (ICompilationUnit) element;
  try {
    computeRenameTypeRefactoring();
    setNewElementName(name);
  } catch (CoreException exception) {
    JavaPlugin.log(exception);
    return JavaRefactoringDescriptorUtil.createInputFatalStatus(
        element, getProcessorName(), IJavaRefactorings.RENAME_COMPILATION_UNIT);
  }
  return new RefactoringStatus();
}
项目: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;
}
项目:gw4e.project    文件:MoveCompilationUnitChange.java   
@Override
public Change perform(IProgressMonitor pm) throws CoreException {

    RefactoringContribution refactoringContribution = RefactoringCore
            .getRefactoringContribution(IJavaRefactorings.MOVE);
    RefactoringDescriptor desc = refactoringContribution.createDescriptor();
    MoveDescriptor moveDes = (MoveDescriptor) desc;
    moveDes.setComment("Moving " + originalFile);
    moveDes.setDescription("Moving " + originalFile);
    IFolder dest = computeCompilationUnitDestination();
    moveDes.setDestination(JavaCore.create(dest));
    moveDes.setProject(originalFile.getProject().getName());

    moveDes.setMoveResources(new IFile[0], new IFolder[0],
            new ICompilationUnit[] { JavaCore.createCompilationUnitFrom(originalFile) });
    moveDes.setUpdateReferences(true);

    RefactoringStatus status = new RefactoringStatus();

    RefactoringContext context = moveDes.createRefactoringContext(status);
    PerformRefactoringOperation op = new PerformRefactoringOperation(context,
            CheckConditionsOperation.ALL_CONDITIONS);
    Job job = new WorkspaceJob("GW4E Moving Job") {
        @Override
        public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
            Display.getDefault().syncExec(() -> {
                try {

                    op.run(monitor);
                } catch (Exception e) {
                    ResourceManager.logException(e);
                }
            });
            return Status.OK_STATUS;
        }
    };
    job.setRule(originalFile.getProject()); // lock so that we serialize the
                                            // refactoring of the "test
                                            // interface" AND the "test
                                            // implementation"
    job.setUser(true);
    job.schedule();

    return op.getUndoChange();
}
项目:che    文件:ExtractSuperclassDescriptor.java   
/** Creates a new refactoring descriptor. */
public ExtractSuperclassDescriptor() {
  super(IJavaRefactorings.EXTRACT_SUPERCLASS);
}
项目:che    文件:RenameMethodInInterfaceTest.java   
private void helper2_0(
    String methodName,
    String newMethodName,
    String[] signatures,
    boolean shouldPass,
    boolean updateReferences,
    boolean createDelegate)
    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(updateReferences);
  descriptor.setNewName(newMethodName);
  descriptor.setKeepOriginal(createDelegate);
  descriptor.setDeprecateDelegate(true);

  assertEquals("was supposed to pass", null, performRefactoring(descriptor));
  if (!shouldPass) {
    assertTrue(
        "incorrect renaming because of a java model bug",
        !getFileContents(getOutputTestFileName("A")).equals(cu.getSource()));
    return;
  }
  assertEqualLines(
      "incorrect 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    文件:Rename18Test.java   
private void renameLocalVariable(String newFieldName, boolean updateReferences) throws Exception {
  ParticipantTesting.reset();
  ICompilationUnit cu = createCUfromTestFile(getPackageP(), "A");

  ISourceRange selection = getSelection(cu);
  IJavaElement[] elements = cu.codeSelect(selection.getOffset(), selection.getLength());
  assertEquals(1, elements.length);
  RenameJavaElementDescriptor descriptor =
      RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(
          IJavaRefactorings.RENAME_LOCAL_VARIABLE);
  descriptor.setJavaElement(elements[0]);
  descriptor.setNewName(newFieldName);
  descriptor.setUpdateReferences(updateReferences);
  descriptor.setUpdateTextualOccurrences(false);

  RenameRefactoring refactoring = (RenameRefactoring) createRefactoring(descriptor);
  List list = new ArrayList();
  list.add(elements[0]);
  List args = new ArrayList();
  args.add(new RenameArguments(newFieldName, updateReferences));
  String[] renameHandles = ParticipantTesting.createHandles(list.toArray());

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

  ParticipantTesting.testRename(
      renameHandles, (RenameArguments[]) args.toArray(new RenameArguments[args.size()]));

  assertTrue("anythingToUndo", RefactoringCore.getUndoManager().anythingToUndo());
  assertTrue("! anythingToRedo", !RefactoringCore.getUndoManager().anythingToRedo());

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

  assertTrue("! anythingToUndo", !RefactoringCore.getUndoManager().anythingToUndo());
  assertTrue("anythingToRedo", RefactoringCore.getUndoManager().anythingToRedo());

  RefactoringCore.getUndoManager().performRedo(null, new NullProgressMonitor());
  assertEqualLines("invalid redo", getFileContents(getOutputTestFileName("A")), cu.getSource());
}
项目:che    文件:Rename18Test.java   
private void renameMethod(
    String methodName,
    String newMethodName,
    String[] signatures,
    boolean shouldPass,
    boolean updateReferences,
    boolean createDelegate)
    throws Exception {
  ICompilationUnit cu = createCUfromTestFile(getPackageP(), "A");
  IType typeI = getType(cu, "I");
  IMethod method = typeI.getMethod(methodName, signatures);

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

  assertEquals("was supposed to pass", null, performRefactoring(descriptor));
  if (!shouldPass) {
    assertTrue(
        "incorrect renaming because of a java model bug",
        !getFileContents(getOutputTestFileName("A")).equals(cu.getSource()));
    return;
  }
  assertEqualLines(
      "incorrect 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    文件:RenamePrivateFieldTest.java   
private void helper2(
    String fieldName,
    String newFieldName,
    boolean updateReferences,
    boolean updateTextualMatches,
    boolean renameGetter,
    boolean renameSetter,
    boolean expectedGetterRenameEnabled,
    boolean expectedSetterRenameEnabled)
    throws Exception {
  ParticipantTesting.reset();
  ICompilationUnit cu = createCUfromTestFile(getPackageP(), "A");
  IType classA = getType(cu, "A");
  IField field = classA.getField(fieldName);
  RenameJavaElementDescriptor descriptor =
      RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(
          IJavaRefactorings.RENAME_FIELD);
  descriptor.setJavaElement(field);
  descriptor.setNewName(newFieldName);
  descriptor.setUpdateReferences(updateReferences);
  descriptor.setUpdateTextualOccurrences(updateTextualMatches);
  descriptor.setRenameGetters(renameGetter);
  descriptor.setRenameSetters(renameSetter);

  RenameRefactoring refactoring = (RenameRefactoring) createRefactoring(descriptor);
  RenameFieldProcessor processor = (RenameFieldProcessor) refactoring.getProcessor();
  assertEquals(
      "getter rename enabled",
      expectedGetterRenameEnabled,
      processor.canEnableGetterRenaming() == null);
  assertEquals(
      "setter rename enabled",
      expectedSetterRenameEnabled,
      processor.canEnableSetterRenaming() == null);

  String newGetterName = processor.getNewGetterName();
  String newSetterName = processor.getNewSetterName();

  List elements = new ArrayList();
  elements.add(field);
  List args = new ArrayList();
  args.add(new RenameArguments(newFieldName, updateReferences));
  if (renameGetter && expectedGetterRenameEnabled) {
    elements.add(processor.getGetter());
    args.add(new RenameArguments(newGetterName, updateReferences));
  }
  if (renameSetter && expectedSetterRenameEnabled) {
    elements.add(processor.getSetter());
    args.add(new RenameArguments(newSetterName, updateReferences));
  }
  String[] renameHandles = ParticipantTesting.createHandles(elements.toArray());

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

  ParticipantTesting.testRename(
      renameHandles, (RenameArguments[]) args.toArray(new RenameArguments[args.size()]));

  assertTrue("anythingToUndo", RefactoringCore.getUndoManager().anythingToUndo());
  assertTrue("! anythingToRedo", !RefactoringCore.getUndoManager().anythingToRedo());

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

  assertTrue("! anythingToUndo", !RefactoringCore.getUndoManager().anythingToUndo());
  assertTrue("anythingToRedo", RefactoringCore.getUndoManager().anythingToRedo());

  RefactoringCore.getUndoManager().performRedo(null, new NullProgressMonitor());
  assertEqualLines("invalid redo", getFileContents(getOutputTestFileName("A")), cu.getSource());
}
项目:che    文件:RenameVirtualMethodInClassTest.java   
private void helper2_0(
    String methodName,
    String newMethodName,
    String[] signatures,
    boolean shouldPass,
    boolean updateReferences,
    boolean createDelegate)
    throws Exception {
  final ICompilationUnit cu = createCUfromTestFile(getPackageP(), "A");
  final IType classA = getType(cu, "A");
  final IMethod method = classA.getMethod(methodName, signatures);
  final RenameJavaElementDescriptor descriptor =
      RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(
          IJavaRefactorings.RENAME_METHOD);
  descriptor.setJavaElement(method);
  descriptor.setNewName(newMethodName);
  descriptor.setUpdateReferences(updateReferences);
  descriptor.setKeepOriginal(createDelegate);
  descriptor.setDeprecateDelegate(createDelegate);
  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));
  if (!shouldPass) {
    assertTrue(
        "incorrect renaming because of java model",
        !getFileContents(getOutputTestFileName("A")).equals(cu.getSource()));
    return;
  }
  String expectedRenaming = getFileContents(getOutputTestFileName("A"));
  String actuaRenaming = cu.getSource();
  assertEqualLines("incorrect renaming", expectedRenaming, actuaRenaming);

  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    文件:RenameNonPrivateFieldTest.java   
private void helper2(String fieldName, String newFieldName, boolean createDelegates)
    throws Exception {
  ParticipantTesting.reset();
  ICompilationUnit cu = createCUfromTestFile(getPackageP(), "A");
  IType classA = getType(cu, "A");
  IField field = classA.getField(fieldName);
  boolean isEnum = JdtFlags.isEnum(field);
  String id = isEnum ? IJavaRefactorings.RENAME_ENUM_CONSTANT : IJavaRefactorings.RENAME_FIELD;
  RenameJavaElementDescriptor descriptor =
      RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(id);
  descriptor.setJavaElement(field);
  descriptor.setNewName(newFieldName);
  descriptor.setUpdateReferences(fUpdateReferences);
  descriptor.setUpdateTextualOccurrences(fUpdateTextualMatches);
  if (!isEnum) {
    descriptor.setRenameGetters(fRenameGetter);
    descriptor.setRenameSetters(fRenameSetter);
    descriptor.setKeepOriginal(createDelegates);
    descriptor.setDeprecateDelegate(true);
  }
  RenameRefactoring refactoring = (RenameRefactoring) createRefactoring(descriptor);
  RenameFieldProcessor processor = (RenameFieldProcessor) refactoring.getProcessor();

  List elements = new ArrayList();
  elements.add(field);
  List args = new ArrayList();
  args.add(new RenameArguments(newFieldName, fUpdateReferences));
  if (fRenameGetter) {
    elements.add(processor.getGetter());
    args.add(new RenameArguments(processor.getNewGetterName(), fUpdateReferences));
  }
  if (fRenameSetter) {
    elements.add(processor.getSetter());
    args.add(new RenameArguments(processor.getNewSetterName(), fUpdateReferences));
  }
  String[] renameHandles = ParticipantTesting.createHandles(elements.toArray());

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

  ParticipantTesting.testRename(
      renameHandles, (RenameArguments[]) args.toArray(new RenameArguments[args.size()]));

  assertTrue("anythingToUndo", RefactoringCore.getUndoManager().anythingToUndo());
  assertTrue("! anythingToRedo", !RefactoringCore.getUndoManager().anythingToRedo());

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

  assertTrue("! anythingToUndo", !RefactoringCore.getUndoManager().anythingToUndo());
  assertTrue("anythingToRedo", RefactoringCore.getUndoManager().anythingToRedo());

  RefactoringCore.getUndoManager().performRedo(null, new NullProgressMonitor());
  assertEqualLines("invalid redo", getFileContents(getOutputTestFileName("A")), cu.getSource());
}
项目:che    文件:RenamePackageRefactoringContribution.java   
@Override
public RefactoringDescriptor createDescriptor() {
  return RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(
      IJavaRefactorings.RENAME_PACKAGE);
}
项目:che    文件:RenameTypeParameterRefactoringContribution.java   
@Override
public RefactoringDescriptor createDescriptor() {
  return RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(
      IJavaRefactorings.RENAME_TYPE_PARAMETER);
}
项目:che    文件:RenameLocalVariableRefactoringContribution.java   
@Override
public RefactoringDescriptor createDescriptor() {
  return RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(
      IJavaRefactorings.RENAME_LOCAL_VARIABLE);
}
项目:che    文件:RenameTypeRefactoringContribution.java   
@Override
public RefactoringDescriptor createDescriptor() {
  return RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(
      IJavaRefactorings.RENAME_TYPE);
}
项目:che    文件:RenameFieldRefactoringContribution.java   
@Override
public RefactoringDescriptor createDescriptor() {
  return RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(
      IJavaRefactorings.RENAME_FIELD);
}
项目:che    文件:RenameMethodRefactoringContribution.java   
@Override
public RefactoringDescriptor createDescriptor() {
  return RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(
      IJavaRefactorings.RENAME_METHOD);
}
项目:che    文件:RenameEnumConstRefactoringContribution.java   
@Override
public RefactoringDescriptor createDescriptor() {
  return RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(
      IJavaRefactorings.RENAME_ENUM_CONSTANT);
}
项目:che    文件:RenameCompilationUnitRefactoringContribution.java   
@Override
public RefactoringDescriptor createDescriptor() {
  return RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(
      IJavaRefactorings.RENAME_COMPILATION_UNIT);
}
项目:che    文件:RenameFieldProcessor.java   
private RefactoringStatus initialize(JavaRefactoringArguments extended) {
  final String handle = extended.getAttribute(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT);
  if (handle != null) {
    final IJavaElement element =
        JavaRefactoringDescriptorUtil.handleToElement(extended.getProject(), handle, false);
    if (element == null || !element.exists() || element.getElementType() != IJavaElement.FIELD)
      return JavaRefactoringDescriptorUtil.createInputFatalStatus(
          element, getProcessorName(), IJavaRefactorings.RENAME_FIELD);
    else fField = (IField) element;
  } else
    return RefactoringStatus.createFatalErrorStatus(
        Messages.format(
            RefactoringCoreMessages.InitializableRefactoring_argument_not_exist,
            JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT));
  final String name = extended.getAttribute(JavaRefactoringDescriptorUtil.ATTRIBUTE_NAME);
  if (name != null && !"".equals(name)) // $NON-NLS-1$
  setNewElementName(name);
  else
    return RefactoringStatus.createFatalErrorStatus(
        Messages.format(
            RefactoringCoreMessages.InitializableRefactoring_argument_not_exist,
            JavaRefactoringDescriptorUtil.ATTRIBUTE_NAME));
  final String references =
      extended.getAttribute(JavaRefactoringDescriptorUtil.ATTRIBUTE_REFERENCES);
  if (references != null) {
    fUpdateReferences = Boolean.valueOf(references).booleanValue();
  } else
    return RefactoringStatus.createFatalErrorStatus(
        Messages.format(
            RefactoringCoreMessages.InitializableRefactoring_argument_not_exist,
            JavaRefactoringDescriptorUtil.ATTRIBUTE_REFERENCES));
  final String matches = extended.getAttribute(ATTRIBUTE_TEXTUAL_MATCHES);
  if (matches != null) {
    fUpdateTextualMatches = Boolean.valueOf(matches).booleanValue();
  } else
    return RefactoringStatus.createFatalErrorStatus(
        Messages.format(
            RefactoringCoreMessages.InitializableRefactoring_argument_not_exist,
            ATTRIBUTE_TEXTUAL_MATCHES));
  final String getters = extended.getAttribute(ATTRIBUTE_RENAME_GETTER);
  if (getters != null) fRenameGetter = Boolean.valueOf(getters).booleanValue();
  else fRenameGetter = false;
  final String setters = extended.getAttribute(ATTRIBUTE_RENAME_SETTER);
  if (setters != null) fRenameSetter = Boolean.valueOf(setters).booleanValue();
  else fRenameSetter = false;
  final String delegate = extended.getAttribute(ATTRIBUTE_DELEGATE);
  if (delegate != null) {
    fDelegateUpdating = Boolean.valueOf(delegate).booleanValue();
  } else fDelegateUpdating = false;
  final String deprecate = extended.getAttribute(ATTRIBUTE_DEPRECATE);
  if (deprecate != null) {
    fDelegateDeprecation = Boolean.valueOf(deprecate).booleanValue();
  } else fDelegateDeprecation = false;
  return new RefactoringStatus();
}
项目:che    文件:RenameEnumConstProcessor.java   
@Override
protected RenameJavaElementDescriptor createRefactoringDescriptor() {
  final IField field = getField();
  String project = null;
  IJavaProject javaProject = field.getJavaProject();
  if (javaProject != null) project = javaProject.getElementName();
  int flags =
      JavaRefactoringDescriptor.JAR_MIGRATION
          | JavaRefactoringDescriptor.JAR_REFACTORING
          | RefactoringDescriptor.STRUCTURAL_CHANGE;
  final IType declaring = field.getDeclaringType();
  try {
    if (!Flags.isPrivate(declaring.getFlags())) flags |= RefactoringDescriptor.MULTI_CHANGE;
    if (declaring.isAnonymous() || declaring.isLocal())
      flags |= JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT;
  } catch (JavaModelException exception) {
    JavaPlugin.log(exception);
  }
  final String description =
      Messages.format(
          RefactoringCoreMessages.RenameEnumConstProcessor_descriptor_description_short,
          BasicElementLabels.getJavaElementName(fField.getElementName()));
  final String header =
      Messages.format(
          RefactoringCoreMessages.RenameEnumConstProcessor_descriptor_description,
          new String[] {
            BasicElementLabels.getJavaElementName(field.getElementName()),
            JavaElementLabels.getElementLabel(
                field.getParent(), JavaElementLabels.ALL_FULLY_QUALIFIED),
            BasicElementLabels.getJavaElementName(getNewElementName())
          });
  final String comment = new JDTRefactoringDescriptorComment(project, this, header).asString();
  final RenameJavaElementDescriptor descriptor =
      RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(
          IJavaRefactorings.RENAME_ENUM_CONSTANT);
  descriptor.setProject(project);
  descriptor.setDescription(description);
  descriptor.setComment(comment);
  descriptor.setFlags(flags);
  descriptor.setJavaElement(field);
  descriptor.setNewName(getNewElementName());
  descriptor.setUpdateReferences(fUpdateReferences);
  descriptor.setUpdateTextualOccurrences(fUpdateTextualMatches);
  return descriptor;
}
项目:che    文件:RenameEnumConstProcessor.java   
private RefactoringStatus initialize(JavaRefactoringArguments extended) {
  final String handle = extended.getAttribute(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT);
  if (handle != null) {
    final IJavaElement element =
        JavaRefactoringDescriptorUtil.handleToElement(extended.getProject(), handle, false);
    if (element == null || !element.exists() || element.getElementType() != IJavaElement.FIELD)
      return JavaRefactoringDescriptorUtil.createInputFatalStatus(
          element, getProcessorName(), IJavaRefactorings.RENAME_ENUM_CONSTANT);
    else fField = (IField) element;
  } else
    return RefactoringStatus.createFatalErrorStatus(
        Messages.format(
            RefactoringCoreMessages.InitializableRefactoring_argument_not_exist,
            JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT));
  final String name = extended.getAttribute(JavaRefactoringDescriptorUtil.ATTRIBUTE_NAME);
  if (name != null && !"".equals(name)) // $NON-NLS-1$
  setNewElementName(name);
  else
    return RefactoringStatus.createFatalErrorStatus(
        Messages.format(
            RefactoringCoreMessages.InitializableRefactoring_argument_not_exist,
            JavaRefactoringDescriptorUtil.ATTRIBUTE_NAME));
  final String references =
      extended.getAttribute(JavaRefactoringDescriptorUtil.ATTRIBUTE_REFERENCES);
  if (references != null) {
    setUpdateReferences(Boolean.valueOf(references).booleanValue());
  } else
    return RefactoringStatus.createFatalErrorStatus(
        Messages.format(
            RefactoringCoreMessages.InitializableRefactoring_argument_not_exist,
            JavaRefactoringDescriptorUtil.ATTRIBUTE_REFERENCES));
  final String matches = extended.getAttribute(ATTRIBUTE_TEXTUAL_MATCHES);
  if (matches != null) {
    setUpdateTextualMatches(Boolean.valueOf(matches).booleanValue());
  } else
    return RefactoringStatus.createFatalErrorStatus(
        Messages.format(
            RefactoringCoreMessages.InitializableRefactoring_argument_not_exist,
            ATTRIBUTE_TEXTUAL_MATCHES));
  return new RefactoringStatus();
}
项目:che    文件:ExtractMethodDescriptor.java   
/** Creates a new refactoring descriptor. */
public ExtractMethodDescriptor() {
  super(IJavaRefactorings.EXTRACT_METHOD);
}
项目:che    文件:ConvertAnonymousDescriptor.java   
/** Creates a new refactoring descriptor. */
public ConvertAnonymousDescriptor() {
  super(IJavaRefactorings.CONVERT_ANONYMOUS);
}
项目:che    文件:RenameTypeProcessor.java   
private RefactoringStatus initialize(JavaRefactoringArguments extended) {
  final String handle = extended.getAttribute(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT);
  if (handle != null) {
    final IJavaElement element =
        JavaRefactoringDescriptorUtil.handleToElement(extended.getProject(), handle, false);
    if (element == null || !element.exists() || element.getElementType() != IJavaElement.TYPE)
      return JavaRefactoringDescriptorUtil.createInputFatalStatus(
          element, getProcessorName(), IJavaRefactorings.RENAME_TYPE);
    else fType = (IType) element;
  } else
    return RefactoringStatus.createFatalErrorStatus(
        Messages.format(
            RefactoringCoreMessages.InitializableRefactoring_argument_not_exist,
            JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT));
  final String name = extended.getAttribute(JavaRefactoringDescriptorUtil.ATTRIBUTE_NAME);
  if (name != null && !"".equals(name)) // $NON-NLS-1$
  setNewElementName(name);
  else
    return RefactoringStatus.createFatalErrorStatus(
        Messages.format(
            RefactoringCoreMessages.InitializableRefactoring_argument_not_exist,
            JavaRefactoringDescriptorUtil.ATTRIBUTE_NAME));
  final String patterns = extended.getAttribute(ATTRIBUTE_PATTERNS);
  if (patterns != null && !"".equals(patterns)) // $NON-NLS-1$
  fFilePatterns = patterns;
  final String references =
      extended.getAttribute(JavaRefactoringDescriptorUtil.ATTRIBUTE_REFERENCES);
  if (references != null) {
    fUpdateReferences = Boolean.valueOf(references).booleanValue();
  } else
    return RefactoringStatus.createFatalErrorStatus(
        Messages.format(
            RefactoringCoreMessages.InitializableRefactoring_argument_not_exist,
            JavaRefactoringDescriptorUtil.ATTRIBUTE_REFERENCES));
  final String matches = extended.getAttribute(ATTRIBUTE_TEXTUAL_MATCHES);
  if (matches != null) {
    fUpdateTextualMatches = Boolean.valueOf(matches).booleanValue();
  } else
    return RefactoringStatus.createFatalErrorStatus(
        Messages.format(
            RefactoringCoreMessages.InitializableRefactoring_argument_not_exist,
            ATTRIBUTE_TEXTUAL_MATCHES));
  final String qualified = extended.getAttribute(ATTRIBUTE_QUALIFIED);
  if (qualified != null) {
    fUpdateQualifiedNames = Boolean.valueOf(qualified).booleanValue();
  } else
    return RefactoringStatus.createFatalErrorStatus(
        Messages.format(
            RefactoringCoreMessages.InitializableRefactoring_argument_not_exist,
            ATTRIBUTE_QUALIFIED));
  final String similarDeclarations = extended.getAttribute(ATTRIBUTE_SIMILAR_DECLARATIONS);
  if (similarDeclarations != null)
    fUpdateSimilarElements = Boolean.valueOf(similarDeclarations).booleanValue();
  else
    return RefactoringStatus.createFatalErrorStatus(
        Messages.format(
            RefactoringCoreMessages.InitializableRefactoring_argument_not_exist,
            ATTRIBUTE_SIMILAR_DECLARATIONS));
  final String similarDeclarationsMatchingStrategy =
      extended.getAttribute(ATTRIBUTE_MATCHING_STRATEGY);
  if (similarDeclarationsMatchingStrategy != null) {
    try {
      fRenamingStrategy = Integer.valueOf(similarDeclarationsMatchingStrategy).intValue();
    } catch (NumberFormatException e) {
      return RefactoringStatus.createFatalErrorStatus(
          Messages.format(
              RefactoringCoreMessages.InitializableRefactoring_illegal_argument,
              new String[] {similarDeclarationsMatchingStrategy, ATTRIBUTE_QUALIFIED}));
    }
  } else
    return RefactoringStatus.createFatalErrorStatus(
        Messages.format(
            RefactoringCoreMessages.InitializableRefactoring_argument_not_exist,
            ATTRIBUTE_MATCHING_STRATEGY));
  return new RefactoringStatus();
}