use of org.eclipse.ltk.core.refactoring.RefactoringChangeDescriptor in project che by eclipse.
the class RenameResourceProcessor method createChange.
/* (non-Javadoc)
* @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#createChange(org.eclipse.core.runtime.IProgressMonitor)
*/
public Change createChange(IProgressMonitor pm) throws CoreException {
//$NON-NLS-1$
pm.beginTask("", 1);
try {
RenameResourceChange change = new RenameResourceChange(fResource.getFullPath(), getNewResourceName());
change.setDescriptor(new RefactoringChangeDescriptor(createDescriptor()));
return change;
} finally {
pm.done();
}
}
use of org.eclipse.ltk.core.refactoring.RefactoringChangeDescriptor in project che by eclipse.
the class InferTypeArgumentsRefactoring method createChange.
/*
* @see org.eclipse.ltk.core.refactoring.Refactoring#createChange(org.eclipse.core.runtime.IProgressMonitor)
*/
@Override
public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException {
//$NON-NLS-1$
pm.beginTask("", 1);
try {
DynamicValidationStateChange result = new DynamicValidationStateChange(RefactoringCoreMessages.InferTypeArgumentsRefactoring_name, fChangeManager.getAllChanges()) {
@Override
public final ChangeDescriptor getDescriptor() {
final Map<String, String> arguments = new HashMap<String, String>();
final IJavaProject project = getSingleProject();
final String description = RefactoringCoreMessages.InferTypeArgumentsRefactoring_descriptor_description;
final String header = project != null ? Messages.format(RefactoringCoreMessages.InferTypeArgumentsRefactoring_descriptor_description_project, BasicElementLabels.getJavaElementName(project.getElementName())) : RefactoringCoreMessages.InferTypeArgumentsRefactoring_descriptor_description;
final String name = project != null ? project.getElementName() : null;
final JDTRefactoringDescriptorComment comment = new JDTRefactoringDescriptorComment(name, this, header);
final String[] settings = new String[fElements.length];
for (int index = 0; index < settings.length; index++) settings[index] = JavaElementLabels.getTextLabel(fElements[index], JavaElementLabels.ALL_FULLY_QUALIFIED);
comment.addSetting(JDTRefactoringDescriptorComment.createCompositeSetting(RefactoringCoreMessages.InferTypeArgumentsRefactoring_original_elements, settings));
if (fAssumeCloneReturnsSameType)
comment.addSetting(RefactoringCoreMessages.InferTypeArgumentsRefactoring_assume_clone);
if (fLeaveUnconstrainedRaw)
comment.addSetting(RefactoringCoreMessages.InferTypeArgumentsRefactoring_leave_unconstrained);
final InferTypeArgumentsDescriptor descriptor = RefactoringSignatureDescriptorFactory.createInferTypeArgumentsDescriptor(name, description, comment.asString(), arguments, RefactoringDescriptor.STRUCTURAL_CHANGE | RefactoringDescriptor.MULTI_CHANGE);
for (int index = 0; index < fElements.length; index++) arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_ELEMENT + (index + 1), JavaRefactoringDescriptorUtil.elementToHandle(name, fElements[index]));
arguments.put(ATTRIBUTE_CLONE, Boolean.valueOf(fAssumeCloneReturnsSameType).toString());
arguments.put(ATTRIBUTE_LEAVE, Boolean.valueOf(fLeaveUnconstrainedRaw).toString());
return new RefactoringChangeDescriptor(descriptor);
}
};
return result;
} finally {
pm.done();
}
}
use of org.eclipse.ltk.core.refactoring.RefactoringChangeDescriptor in project che by eclipse.
the class PromoteTempToFieldRefactoring method createChange.
/*
* @see org.eclipse.jdt.internal.corext.refactoring.base.IRefactoring#createChange(org.eclipse.core.runtime.IProgressMonitor)
*/
@Override
public Change createChange(IProgressMonitor pm) throws CoreException {
//$NON-NLS-1$
pm.beginTask("", 1);
try {
if (fFieldName.length() == 0) {
fFieldName = getInitialFieldName();
}
ASTRewrite rewrite = ASTRewrite.create(fCompilationUnitNode.getAST());
if (fInitializeIn == INITIALIZE_IN_METHOD && tempHasInitializer())
addLocalDeclarationSplit(rewrite);
else
addLocalDeclarationRemoval(rewrite);
if (fInitializeIn == INITIALIZE_IN_CONSTRUCTOR)
addInitializersToConstructors(rewrite);
addTempRenames(rewrite);
addFieldDeclaration(rewrite);
CompilationUnitChange result = new CompilationUnitChange(RefactoringCoreMessages.PromoteTempToFieldRefactoring_name, fCu);
result.setDescriptor(new RefactoringChangeDescriptor(getRefactoringDescriptor()));
TextEdit resultingEdits = rewrite.rewriteAST();
TextChangeCompatibility.addTextEdit(result, RefactoringCoreMessages.PromoteTempToFieldRefactoring_editName, resultingEdits);
return result;
} finally {
pm.done();
}
}
use of org.eclipse.ltk.core.refactoring.RefactoringChangeDescriptor in project che by eclipse.
the class RefactoringTest method performRefactoring.
protected final RefactoringStatus performRefactoring(Refactoring ref, boolean providesUndo) throws Exception {
performDummySearch();
IUndoManager undoManager = getUndoManager();
if (DESCRIPTOR_TEST) {
final CreateChangeOperation create = new CreateChangeOperation(new CheckConditionsOperation(ref, CheckConditionsOperation.ALL_CONDITIONS), RefactoringStatus.FATAL);
create.run(new NullProgressMonitor());
RefactoringStatus checkingStatus = create.getConditionCheckingStatus();
if (!checkingStatus.isOK())
return checkingStatus;
Change change = create.getChange();
ChangeDescriptor descriptor = change.getDescriptor();
if (descriptor instanceof RefactoringChangeDescriptor) {
RefactoringChangeDescriptor rcd = (RefactoringChangeDescriptor) descriptor;
RefactoringDescriptor refactoringDescriptor = rcd.getRefactoringDescriptor();
if (refactoringDescriptor instanceof JavaRefactoringDescriptor) {
JavaRefactoringDescriptor jrd = (JavaRefactoringDescriptor) refactoringDescriptor;
RefactoringStatus validation = jrd.validateDescriptor();
if (!validation.isOK())
return validation;
RefactoringStatus refactoringStatus = new RefactoringStatus();
Class expected = jrd.getClass();
RefactoringContribution contribution = RefactoringCore.getRefactoringContribution(jrd.getID());
jrd = (JavaRefactoringDescriptor) contribution.createDescriptor(jrd.getID(), jrd.getProject(), jrd.getDescription(), jrd.getComment(), contribution.retrieveArgumentMap(jrd), jrd.getFlags());
assertEquals(expected, jrd.getClass());
ref = jrd.createRefactoring(refactoringStatus);
if (!refactoringStatus.isOK())
return refactoringStatus;
TestRenameParticipantSingle.reset();
TestCreateParticipantSingle.reset();
TestMoveParticipantSingle.reset();
TestDeleteParticipantSingle.reset();
}
}
}
final CreateChangeOperation create = new CreateChangeOperation(new CheckConditionsOperation(ref, CheckConditionsOperation.ALL_CONDITIONS), RefactoringStatus.FATAL);
final PerformChangeOperation perform = new PerformChangeOperation(create);
perform.setUndoManager(undoManager, ref.getName());
IWorkspace workspace = ResourcesPlugin.getWorkspace();
if (fIsPreDeltaTest) {
IResourceChangeListener listener = new IResourceChangeListener() {
public void resourceChanged(IResourceChangeEvent event) {
if (create.getConditionCheckingStatus().isOK() && perform.changeExecuted()) {
TestModelProvider.assertTrue(event.getDelta());
}
}
};
try {
TestModelProvider.clearDelta();
workspace.checkpoint(false);
workspace.addResourceChangeListener(listener);
executePerformOperation(perform, workspace);
} finally {
workspace.removeResourceChangeListener(listener);
}
} else {
executePerformOperation(perform, workspace);
}
RefactoringStatus status = create.getConditionCheckingStatus();
if (!status.isOK())
return status;
assertTrue("Change wasn't executed", perform.changeExecuted());
Change undo = perform.getUndoChange();
if (providesUndo) {
assertNotNull("Undo doesn't exist", undo);
assertTrue("Undo manager is empty", undoManager.anythingToUndo());
} else {
assertNull("Undo manager contains undo but shouldn't", undo);
}
return null;
}
use of org.eclipse.ltk.core.refactoring.RefactoringChangeDescriptor in project che by eclipse.
the class ConvertAnonymousToNestedRefactoring method createRefactoringDescriptor.
private RefactoringChangeDescriptor createRefactoringDescriptor() {
final ITypeBinding binding = fAnonymousInnerClassNode.resolveBinding();
final String[] labels = new String[] { BindingLabelProvider.getBindingLabel(binding, JavaElementLabels.ALL_FULLY_QUALIFIED), BindingLabelProvider.getBindingLabel(binding.getDeclaringMethod(), JavaElementLabels.ALL_FULLY_QUALIFIED) };
final Map<String, String> arguments = new HashMap<String, String>();
final String projectName = fCu.getJavaProject().getElementName();
final int flags = RefactoringDescriptor.STRUCTURAL_CHANGE | JavaRefactoringDescriptor.JAR_REFACTORING | JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT;
final String description = RefactoringCoreMessages.ConvertAnonymousToNestedRefactoring_descriptor_description_short;
final String header = Messages.format(RefactoringCoreMessages.ConvertAnonymousToNestedRefactoring_descriptor_description, labels);
final JDTRefactoringDescriptorComment comment = new JDTRefactoringDescriptorComment(projectName, this, header);
comment.addSetting(Messages.format(RefactoringCoreMessages.ConvertAnonymousToNestedRefactoring_original_pattern, BindingLabelProvider.getBindingLabel(binding, JavaElementLabels.ALL_FULLY_QUALIFIED)));
comment.addSetting(Messages.format(RefactoringCoreMessages.ConvertAnonymousToNestedRefactoring_class_name_pattern, BasicElementLabels.getJavaElementName(fClassName)));
String visibility = JdtFlags.getVisibilityString(fVisibility);
if (visibility.length() == 0)
visibility = RefactoringCoreMessages.ConvertAnonymousToNestedRefactoring_default_visibility;
comment.addSetting(Messages.format(RefactoringCoreMessages.ConvertAnonymousToNestedRefactoring_visibility_pattern, visibility));
if (fDeclareFinal && fDeclareStatic)
comment.addSetting(RefactoringCoreMessages.ConvertAnonymousToNestedRefactoring_declare_final_static);
else if (fDeclareFinal)
comment.addSetting(RefactoringCoreMessages.ConvertAnonymousToNestedRefactoring_declare_final);
else if (fDeclareStatic)
comment.addSetting(RefactoringCoreMessages.ConvertAnonymousToNestedRefactoring_declare_static);
arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT, JavaRefactoringDescriptorUtil.elementToHandle(projectName, fCu));
arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_NAME, fClassName);
arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_SELECTION, new Integer(fSelectionStart).toString() + ' ' + new Integer(fSelectionLength).toString());
arguments.put(ATTRIBUTE_FINAL, Boolean.valueOf(fDeclareFinal).toString());
arguments.put(ATTRIBUTE_STATIC, Boolean.valueOf(fDeclareStatic).toString());
arguments.put(ATTRIBUTE_VISIBILITY, new Integer(fVisibility).toString());
ConvertAnonymousDescriptor descriptor = RefactoringSignatureDescriptorFactory.createConvertAnonymousDescriptor(projectName, description, comment.asString(), arguments, flags);
return new RefactoringChangeDescriptor(descriptor);
}
Aggregations