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 che by eclipse.
the class RenameCompilationUnitProcessor method createChange.
@Override
public Change createChange(IProgressMonitor pm) throws CoreException {
// renaming the file is taken care of in renameTypeRefactoring
if (fWillRenameType)
return fRenameTypeProcessor.createChange(pm);
fRenameTypeProcessor = null;
final String newName = getNewElementName();
final IResource resource = fCu.getResource();
if (resource != null && resource.isLinked()) {
final IProject project = resource.getProject();
final String name = project.getName();
final String description = Messages.format(RefactoringCoreMessages.RenameCompilationUnitChange_descriptor_description_short, BasicElementLabels.getResourceName(resource.getName()));
final String header = Messages.format(RefactoringCoreMessages.RenameCompilationUnitChange_descriptor_description, new String[] { BasicElementLabels.getPathLabel(resource.getFullPath(), false), BasicElementLabels.getResourceName(resource.getName()) });
final String comment = new JDTRefactoringDescriptorComment(name, this, header).asString();
final int flags = RefactoringDescriptor.STRUCTURAL_CHANGE;
final RenameResourceDescriptor descriptor = (RenameResourceDescriptor) RefactoringCore.getRefactoringContribution(RenameResourceDescriptor.ID).createDescriptor();
descriptor.setProject(name);
descriptor.setDescription(description);
descriptor.setComment(comment);
descriptor.setFlags(flags);
descriptor.setResourcePath(resource.getFullPath());
descriptor.setNewName(newName);
RenameResourceChange resourceChange = new RenameResourceChange(resource.getFullPath(), newName);
resourceChange.setDescriptor(new RefactoringChangeDescriptor(descriptor));
return new DynamicValidationStateChange(resourceChange);
}
String label = JavaElementLabels.getTextLabel(fCu, JavaElementLabels.ALL_FULLY_QUALIFIED);
final String name = fCu.getJavaProject().getElementName();
final String description = Messages.format(RefactoringCoreMessages.RenameCompilationUnitChange_descriptor_description_short, BasicElementLabels.getFileName(fCu));
final String header = Messages.format(RefactoringCoreMessages.RenameCompilationUnitChange_descriptor_description, new String[] { label, BasicElementLabels.getResourceName(newName) });
final String comment = new JDTRefactoringDescriptorComment(name, this, header).asString();
final int flags = RefactoringDescriptor.STRUCTURAL_CHANGE;
final RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_COMPILATION_UNIT);
descriptor.setProject(name);
descriptor.setDescription(description);
descriptor.setComment(comment);
descriptor.setFlags(flags);
descriptor.setJavaElement(fCu);
descriptor.setNewName(newName);
return new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.RenameCompilationUnitRefactoring_name, new Change[] { new RenameCompilationUnitChange(fCu, newName) });
}
use of org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor in project che by eclipse.
the class RenameFieldProcessor method createChange.
@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();
}
}
use of org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor in project che by eclipse.
the class RenameFieldProcessor method createRefactoringDescriptor.
/**
* Overridden by subclasses.
* @return return the refactoring descriptor for this refactoring
*/
protected RenameJavaElementDescriptor createRefactoringDescriptor() {
String project = null;
IJavaProject javaProject = fField.getJavaProject();
if (javaProject != null)
project = javaProject.getElementName();
int flags = JavaRefactoringDescriptor.JAR_MIGRATION | JavaRefactoringDescriptor.JAR_REFACTORING | RefactoringDescriptor.STRUCTURAL_CHANGE;
try {
if (!Flags.isPrivate(fField.getFlags()))
flags |= RefactoringDescriptor.MULTI_CHANGE;
} catch (JavaModelException exception) {
JavaPlugin.log(exception);
}
final IType declaring = fField.getDeclaringType();
try {
if (declaring.isAnonymous() || declaring.isLocal())
flags |= JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT;
} catch (JavaModelException exception) {
JavaPlugin.log(exception);
}
final String description = Messages.format(RefactoringCoreMessages.RenameFieldRefactoring_descriptor_description_short, BasicElementLabels.getJavaElementName(fField.getElementName()));
final String header = Messages.format(RefactoringCoreMessages.RenameFieldProcessor_descriptor_description, new String[] { BasicElementLabels.getJavaElementName(fField.getElementName()), JavaElementLabels.getElementLabel(fField.getParent(), JavaElementLabels.ALL_FULLY_QUALIFIED), getNewElementName() });
final JDTRefactoringDescriptorComment comment = new JDTRefactoringDescriptorComment(project, this, header);
if (fRenameGetter)
comment.addSetting(RefactoringCoreMessages.RenameFieldRefactoring_setting_rename_getter);
if (fRenameSetter)
comment.addSetting(RefactoringCoreMessages.RenameFieldRefactoring_setting_rename_settter);
final RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_FIELD);
descriptor.setProject(project);
descriptor.setDescription(description);
descriptor.setComment(comment.asString());
descriptor.setFlags(flags);
descriptor.setJavaElement(fField);
descriptor.setNewName(getNewElementName());
descriptor.setUpdateReferences(fUpdateReferences);
descriptor.setUpdateTextualOccurrences(fUpdateTextualMatches);
descriptor.setRenameGetters(fRenameGetter);
descriptor.setRenameSetters(fRenameSetter);
descriptor.setKeepOriginal(fDelegateUpdating);
descriptor.setDeprecateDelegate(fDelegateDeprecation);
return descriptor;
}
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();
}
}
Aggregations