use of org.eclipse.jdt.internal.corext.refactoring.rename.RenameFieldProcessor in project che by eclipse.
the class RenameFieldRefactoringContribution method createRefactoring.
/**
* {@inheritDoc}
*/
@Override
public Refactoring createRefactoring(JavaRefactoringDescriptor descriptor, RefactoringStatus status) {
JavaRefactoringArguments arguments = new JavaRefactoringArguments(descriptor.getProject(), retrieveArgumentMap(descriptor));
RenameFieldProcessor processor = new RenameFieldProcessor(arguments, status);
return new RenameRefactoring(processor);
}
use of org.eclipse.jdt.internal.corext.refactoring.rename.RenameFieldProcessor in project che by eclipse.
the class RenameSupport method create.
/**
* Creates a new rename support for the given {@link IField}.
*
* @param field the {@link IField} to be renamed.
* @param newName the field's new name. <code>null</code> is a valid value
* indicating that no new name is provided.
* @param flags flags controlling additional parameters. Valid flags are
* <code>UPDATE_REFERENCES</code>, <code>UPDATE_TEXTUAL_MATCHES</code>,
* <code>UPDATE_GETTER_METHOD</code>, and <code>UPDATE_SETTER_METHOD</code>,
* or their bitwise OR, or <code>NONE</code>.
* @return the {@link RenameSupport}.
* @throws CoreException if an unexpected error occurred while creating
* the {@link RenameSupport}.
*/
public static RenameSupport create(IField field, String newName, int flags) throws CoreException {
if (JdtFlags.isEnum(field))
return new RenameSupport(new RenameEnumConstProcessor(field), newName, flags);
else {
final RenameFieldProcessor processor = new RenameFieldProcessor(field);
processor.setRenameGetter(updateGetterMethod(flags));
processor.setRenameSetter(updateSetterMethod(flags));
return new RenameSupport(processor, newName, flags);
}
}
use of org.eclipse.jdt.internal.corext.refactoring.rename.RenameFieldProcessor in project che by eclipse.
the class RenameNonPrivateFieldTest method helper2.
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());
}
use of org.eclipse.jdt.internal.corext.refactoring.rename.RenameFieldProcessor in project che by eclipse.
the class RenamePrivateFieldTest method helper2.
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());
}
Aggregations