use of org.eclipse.jdt.internal.corext.refactoring.tagging.INameUpdating in project che by eclipse.
the class RenameTypeTest method helperWithTextual.
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;
}
use of org.eclipse.jdt.internal.corext.refactoring.tagging.INameUpdating in project che by eclipse.
the class RenameSession method validateNewName.
public RefactoringStatus validateNewName(String newName) {
INameUpdating updating = getNameUpdating();
updating.setNewElementName(newName);
try {
return updating.checkNewElementName(newName);
} catch (CoreException e) {
JavaPlugin.log(e);
return RefactoringStatus.createFatalErrorStatus("An unexpected exception occurred. See the error log for more details.");
}
}
use of org.eclipse.jdt.internal.corext.refactoring.tagging.INameUpdating in project che by eclipse.
the class JDTRefactoringDescriptorComment method initializeInferredSettings.
/**
* Initializes the inferred settings.
*
* @param object
* the refactoring object
*/
private void initializeInferredSettings(final Object object) {
if (object instanceof INameUpdating) {
final INameUpdating updating = (INameUpdating) object;
fSettings.add(Messages.format(RefactoringCoreMessages.JavaRefactoringDescriptor_original_element_pattern, JavaElementLabels.getTextLabel(updating.getElements()[0], JavaElementLabels.ALL_FULLY_QUALIFIED)));
try {
final Object element = updating.getNewElement();
if (element != null)
fSettings.add(Messages.format(RefactoringCoreMessages.JavaRefactoringDescriptor_renamed_element_pattern, JavaElementLabels.getTextLabel(element, JavaElementLabels.ALL_FULLY_QUALIFIED)));
else {
final String newLabel = BasicElementLabels.getJavaElementName(updating.getCurrentElementName());
fSettings.add(Messages.format(RefactoringCoreMessages.JavaRefactoringDescriptor_renamed_element_pattern, newLabel));
}
} catch (CoreException exception) {
JavaPlugin.log(exception);
}
} else if (object instanceof RefactoringProcessor) {
final RefactoringProcessor processor = (RefactoringProcessor) object;
final Object[] elements = processor.getElements();
if (elements != null) {
if (elements.length == 1 && elements[0] != null)
fSettings.add(Messages.format(RefactoringCoreMessages.JavaRefactoringDescriptor_original_element_pattern, JavaElementLabels.getTextLabel(elements[0], JavaElementLabels.ALL_FULLY_QUALIFIED)));
else if (elements.length > 1) {
final StringBuffer buffer = new StringBuffer(128);
buffer.append(RefactoringCoreMessages.JavaRefactoringDescriptor_original_elements);
for (int index = 0; index < elements.length; index++) {
if (elements[index] != null) {
buffer.append(LINE_DELIMITER);
buffer.append(ELEMENT_DELIMITER);
buffer.append(JavaElementLabels.getTextLabel(elements[index], JavaElementLabels.ALL_FULLY_QUALIFIED));
} else {
buffer.append(LINE_DELIMITER);
buffer.append(ELEMENT_DELIMITER);
buffer.append(RefactoringCoreMessages.JavaRefactoringDescriptor_not_available);
}
}
fSettings.add(buffer.toString());
}
}
} else if (object instanceof IReorgPolicy) {
final IReorgPolicy policy = (IReorgPolicy) object;
Object destination = policy.getJavaElementDestination();
if (destination != null)
fSettings.add(Messages.format(RefactoringCoreMessages.JavaRefactoringDescriptorComment_destination_pattern, JavaElementLabels.getTextLabel(destination, JavaElementLabels.ALL_FULLY_QUALIFIED)));
else {
destination = policy.getResourceDestination();
if (destination != null)
fSettings.add(Messages.format(RefactoringCoreMessages.JavaRefactoringDescriptorComment_destination_pattern, JavaElementLabels.getTextLabel(destination, JavaElementLabels.ALL_FULLY_QUALIFIED)));
}
final List<IAdaptable> list = new ArrayList<IAdaptable>();
list.addAll(Arrays.asList(policy.getJavaElements()));
list.addAll(Arrays.asList(policy.getResources()));
final Object[] elements = list.toArray();
if (elements != null) {
if (elements.length == 1 && elements[0] != null)
fSettings.add(Messages.format(RefactoringCoreMessages.JavaRefactoringDescriptor_original_element_pattern, JavaElementLabels.getTextLabel(elements[0], JavaElementLabels.ALL_FULLY_QUALIFIED)));
else if (elements.length > 1) {
final StringBuffer buffer = new StringBuffer(128);
buffer.append(RefactoringCoreMessages.JavaRefactoringDescriptor_original_elements);
for (int index = 0; index < elements.length; index++) {
if (elements[index] != null) {
buffer.append(LINE_DELIMITER);
buffer.append(ELEMENT_DELIMITER);
buffer.append(JavaElementLabels.getTextLabel(elements[index], JavaElementLabels.ALL_FULLY_QUALIFIED));
} else {
buffer.append(LINE_DELIMITER);
buffer.append(ELEMENT_DELIMITER);
buffer.append(RefactoringCoreMessages.JavaRefactoringDescriptor_not_available);
}
}
fSettings.add(buffer.toString());
}
}
if (object instanceof IMovePolicy) {
final IMovePolicy extended = (IMovePolicy) object;
if (extended.isTextualMove())
fSettings.add(RefactoringCoreMessages.JavaRefactoringDescriptorComment_textual_move_only);
}
}
if (object instanceof IReferenceUpdating) {
final IReferenceUpdating updating = (IReferenceUpdating) object;
if (updating.getUpdateReferences())
fSettings.add(RefactoringCoreMessages.JavaRefactoringDescriptor_update_references);
}
if (object instanceof ISimilarDeclarationUpdating) {
final ISimilarDeclarationUpdating updating = (ISimilarDeclarationUpdating) object;
if (updating.canEnableSimilarDeclarationUpdating() && updating.getUpdateSimilarDeclarations()) {
final int strategy = updating.getMatchStrategy();
if (strategy == RenamingNameSuggestor.STRATEGY_EXACT)
fSettings.add(RefactoringCoreMessages.JavaRefactoringDescriptor_rename_similar);
else if (strategy == RenamingNameSuggestor.STRATEGY_EMBEDDED)
fSettings.add(RefactoringCoreMessages.JavaRefactoringDescriptor_rename_similar_embedded);
else if (strategy == RenamingNameSuggestor.STRATEGY_SUFFIX)
fSettings.add(RefactoringCoreMessages.JavaRefactoringDescriptor_rename_similar_suffix);
}
}
if (object instanceof IQualifiedNameUpdating) {
final IQualifiedNameUpdating updating = (IQualifiedNameUpdating) object;
if (updating.canEnableQualifiedNameUpdating() && updating.getUpdateQualifiedNames()) {
final String patterns = updating.getFilePatterns();
if (//$NON-NLS-1$
patterns != null && !"".equals(patterns))
fSettings.add(Messages.format(RefactoringCoreMessages.JavaRefactoringDescriptor_qualified_names_pattern, BasicElementLabels.getFilePattern(patterns.trim())));
else
fSettings.add(RefactoringCoreMessages.JavaRefactoringDescriptor_qualified_names);
}
}
if (object instanceof ITextUpdating) {
final ITextUpdating updating = (ITextUpdating) object;
if (updating.canEnableTextUpdating())
fSettings.add(RefactoringCoreMessages.JavaRefactoringDescriptor_textual_occurrences);
}
if (object instanceof IDelegateUpdating) {
final IDelegateUpdating updating = (IDelegateUpdating) object;
if (updating.canEnableDelegateUpdating() && updating.getDelegateUpdating()) {
if (updating.getDeprecateDelegates())
fSettings.add(RefactoringCoreMessages.JavaRefactoringDescriptor_keep_original_deprecated);
else
fSettings.add(RefactoringCoreMessages.JavaRefactoringDescriptor_keep_original);
}
}
}
Aggregations