use of org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor in project che by eclipse.
the class RenameLocalVariableProcessor method createChange.
@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();
}
}
use of org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor in project che by eclipse.
the class RenamePackageProcessor method createChange.
@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();
}
}
use of org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor in project che by eclipse.
the class RenameTypeParameterProcessor method createChange.
@Override
public Change createChange(IProgressMonitor monitor) throws CoreException, OperationCanceledException {
Assert.isNotNull(monitor);
try {
Change change = fChange;
if (change != null) {
String project = null;
IJavaProject javaProject = fTypeParameter.getJavaProject();
if (javaProject != null)
project = javaProject.getElementName();
String description = Messages.format(RefactoringCoreMessages.RenameTypeParameterProcessor_descriptor_description_short, BasicElementLabels.getJavaElementName(fTypeParameter.getElementName()));
String header = Messages.format(RefactoringCoreMessages.RenameTypeParameterProcessor_descriptor_description, new String[] { BasicElementLabels.getJavaElementName(fTypeParameter.getElementName()), JavaElementLabels.getElementLabel(fTypeParameter.getDeclaringMember(), JavaElementLabels.ALL_FULLY_QUALIFIED), BasicElementLabels.getJavaElementName(getNewElementName()) });
String comment = new JDTRefactoringDescriptorComment(project, this, header).asString();
RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_TYPE_PARAMETER);
descriptor.setProject(project);
descriptor.setDescription(description);
descriptor.setComment(comment);
descriptor.setFlags(RefactoringDescriptor.NONE);
descriptor.setJavaElement(fTypeParameter);
descriptor.setNewName(getNewElementName());
descriptor.setUpdateReferences(fUpdateReferences);
change = new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.RenameTypeParameterProcessor_change_name, new Change[] { change });
}
return change;
} finally {
fChange = null;
monitor.done();
}
}
use of org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor in project che by eclipse.
the class RenameLinkedModeRefactoringSession method createRenameDescriptor.
/**
* Creates a rename descriptor.
*
* @param javaElement element to rename
* @param newName new name
* @return a rename descriptor with current settings as used in the refactoring dialogs
* @throws JavaModelException if an error occurs while accessing the element
*/
private RenameJavaElementDescriptor createRenameDescriptor(IJavaElement javaElement, String newName) throws JavaModelException {
String contributionId;
// see RefactoringExecutionStarter#createRenameSupport(..):
int elementType = javaElement.getElementType();
switch(elementType) {
case IJavaElement.JAVA_PROJECT:
contributionId = IJavaRefactorings.RENAME_JAVA_PROJECT;
break;
case IJavaElement.PACKAGE_FRAGMENT_ROOT:
contributionId = IJavaRefactorings.RENAME_SOURCE_FOLDER;
break;
case IJavaElement.PACKAGE_FRAGMENT:
contributionId = IJavaRefactorings.RENAME_PACKAGE;
break;
case IJavaElement.COMPILATION_UNIT:
contributionId = IJavaRefactorings.RENAME_COMPILATION_UNIT;
break;
case IJavaElement.TYPE:
contributionId = IJavaRefactorings.RENAME_TYPE;
break;
case IJavaElement.METHOD:
final IMethod method = (IMethod) javaElement;
if (method.isConstructor())
return createRenameDescriptor(method.getDeclaringType(), newName);
else
contributionId = IJavaRefactorings.RENAME_METHOD;
break;
case IJavaElement.FIELD:
IField field = (IField) javaElement;
if (field.isEnumConstant())
contributionId = IJavaRefactorings.RENAME_ENUM_CONSTANT;
else
contributionId = IJavaRefactorings.RENAME_FIELD;
break;
case IJavaElement.TYPE_PARAMETER:
contributionId = IJavaRefactorings.RENAME_TYPE_PARAMETER;
break;
case IJavaElement.LOCAL_VARIABLE:
contributionId = IJavaRefactorings.RENAME_LOCAL_VARIABLE;
break;
default:
return null;
}
RenameJavaElementDescriptor descriptor = (RenameJavaElementDescriptor) RefactoringCore.getRefactoringContribution(contributionId).createDescriptor();
descriptor.setJavaElement(javaElement);
descriptor.setNewName(newName);
if (elementType != IJavaElement.PACKAGE_FRAGMENT_ROOT)
descriptor.setUpdateReferences(true);
switch(elementType) {
case IJavaElement.METHOD:
case IJavaElement.FIELD:
descriptor.setDeprecateDelegate(/*refactoringSettings.getBoolean(DelegateUIHelper.DELEGATE_DEPRECATION)*/
false);
descriptor.setKeepOriginal(/*refactoringSettings.getBoolean(DelegateUIHelper.DELEGATE_UPDATING)*/
false);
}
switch(elementType) {
case IJavaElement.TYPE:
// case IJavaElement.COMPILATION_UNIT: // TODO
descriptor.setUpdateSimilarDeclarations(/*refactoringSettings.getBoolean(RenameRefactoringWizard.TYPE_UPDATE_SIMILAR_ELEMENTS)*/
false);
int strategy;
try {
//refactoringSettings.getInt(RenameRefactoringWizard.TYPE_SIMILAR_MATCH_STRATEGY);
strategy = 1;
} catch (NumberFormatException e) {
strategy = RenamingNameSuggestor.STRATEGY_EXACT;
}
descriptor.setMatchStrategy(strategy);
}
switch(elementType) {
case IJavaElement.PACKAGE_FRAGMENT:
descriptor.setUpdateHierarchy(/*refactoringSettings.getBoolean(RenameRefactoringWizard.PACKAGE_RENAME_SUBPACKAGES)*/
true);
}
switch(elementType) {
case IJavaElement.PACKAGE_FRAGMENT:
case IJavaElement.TYPE:
String fileNamePatterns = /*refactoringSettings.get(RenameRefactoringWizard.QUALIFIED_NAMES_PATTERNS)*/
"*";
if (fileNamePatterns != null && fileNamePatterns.length() != 0) {
descriptor.setFileNamePatterns(fileNamePatterns);
boolean updateQualifiedNames = /*refactoringSettings.getBoolean(RenameRefactoringWizard.UPDATE_QUALIFIED_NAMES)*/
false;
descriptor.setUpdateQualifiedNames(updateQualifiedNames);
// fShowPreview|= updateQualifiedNames;
}
}
switch(elementType) {
case IJavaElement.PACKAGE_FRAGMENT:
case IJavaElement.TYPE:
case IJavaElement.FIELD:
//refactoringSettings.getBoolean(RenameRefactoringWizard.UPDATE_TEXTUAL_MATCHES);
boolean updateTextualOccurrences = false;
descriptor.setUpdateTextualOccurrences(updateTextualOccurrences);
}
switch(elementType) {
case IJavaElement.FIELD:
descriptor.setRenameGetters(/*refactoringSettings.getBoolean(RenameRefactoringWizard.FIELD_RENAME_GETTER)*/
false);
descriptor.setRenameSetters(/*refactoringSettings.getBoolean(RenameRefactoringWizard.FIELD_RENAME_SETTER)*/
false);
}
return descriptor;
}
use of org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor in project evosuite by EvoSuite.
the class TestGenerationAction method renameSuite.
/**
* If there already exists a test suite for the chosen target class, then
* renaming the old test suite is one of the options the user can choose
*
* @param suite
* @param packageName
* @param suitePath
*/
public void renameSuite(final IResource suite, String packageName, String suitePath) {
System.out.println("Renaming " + suitePath + " in package " + packageName);
IPackageFragment[] packages;
try {
packages = JavaCore.create(suite.getProject()).getPackageFragments();
System.out.println("Packages found: " + packages.length);
for (IPackageFragment f : packages) {
if ((f.getKind() == IPackageFragmentRoot.K_SOURCE) && (f.getElementName().equals(packageName))) {
for (ICompilationUnit cu : f.getCompilationUnits()) {
String cuName = cu.getElementName();
System.out.println("targetPath = " + suitePath);
System.out.println("cuName = " + cuName);
if (cuName.equals(suitePath)) {
RefactoringContribution contribution = RefactoringCore.getRefactoringContribution(IJavaRefactorings.RENAME_COMPILATION_UNIT);
RenameJavaElementDescriptor descriptor = (RenameJavaElementDescriptor) contribution.createDescriptor();
descriptor.setProject(cu.getResource().getProject().getName());
String newName = getNewName(cuName, f.getCompilationUnits());
System.out.println("New name for Test Suite: " + newName);
// new name for a Class
descriptor.setNewName(newName);
descriptor.setJavaElement(cu);
RefactoringStatus status = new RefactoringStatus();
try {
Refactoring refactoring = descriptor.createRefactoring(status);
IProgressMonitor monitor = new NullProgressMonitor();
refactoring.checkInitialConditions(monitor);
refactoring.checkFinalConditions(monitor);
Change change = refactoring.createChange(monitor);
change.perform(monitor);
} catch (CoreException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
} catch (JavaModelException e1) {
e1.printStackTrace();
}
}
Aggregations