use of org.eclipse.ltk.core.refactoring.RefactoringContribution 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.RefactoringContribution in project che by eclipse.
the class RefactoringContributionManager method createDescriptor.
/**
* Creates a new refactoring descriptor for the specified input data.
*
* @param id
* the unique id of the refactoring
* @param project
* the project name, or <code>null</code>
* @param description
* a description
* @param comment
* the comment, or <code>null</code>
* @param arguments
* the argument map
* @param flags
* the flags
* @return the refactoring descriptor
* @throws IllegalArgumentException if the argument map contains invalid keys/values
*/
public RefactoringDescriptor createDescriptor(final String id, final String project, final String description, final String comment, final Map arguments, final int flags) throws IllegalArgumentException {
Assert.isNotNull(id);
Assert.isNotNull(description);
Assert.isNotNull(arguments);
Assert.isLegal(flags >= RefactoringDescriptor.NONE);
final RefactoringContribution contribution = getRefactoringContribution(id);
if (contribution != null)
return contribution.createDescriptor(id, project, description, comment, arguments, flags);
return new DefaultRefactoringDescriptor(id, project, description, comment, arguments, flags);
}
use of org.eclipse.ltk.core.refactoring.RefactoringContribution in project che by eclipse.
the class RefactoringHistoryManager method getArgumentMap.
/**
* Returns the argument map of the specified descriptor.
*
* @param descriptor
* the refactoring descriptor
* @return the argument map, or <code>null</code>
*/
public static Map getArgumentMap(final RefactoringDescriptor descriptor) {
Map arguments = null;
final RefactoringContribution contribution = RefactoringContributionManager.getInstance().getRefactoringContribution(descriptor.getID());
if (contribution != null)
arguments = contribution.retrieveArgumentMap(descriptor);
else if (descriptor instanceof DefaultRefactoringDescriptor)
arguments = ((DefaultRefactoringDescriptor) descriptor).getArguments();
return arguments;
}
use of org.eclipse.ltk.core.refactoring.RefactoringContribution in project che by eclipse.
the class RefactoringContributionManager method populateCache.
/**
* Populates the refactoring contribution cache if necessary.
*
* @since 3.3
*/
private void populateCache() {
if (fContributionCache == null || fIdCache == null) {
fContributionCache = new HashMap(32);
fIdCache = new HashMap(32);
Map<String, String> contributions = CheRefactoringContributions.getRefactoringContributions();
contributions.forEach((id, clazz) -> {
try {
final Object implementation = CheRefactoringContributions.createExecutableExtension(clazz);
if (implementation instanceof RefactoringContribution) {
if (fContributionCache.get(id) != null)
RefactoringCorePlugin.logErrorMessage(Messages.format(RefactoringCoreMessages.RefactoringCorePlugin_duplicate_warning, new String[] { id, clazz }));
fContributionCache.put(id, implementation);
fIdCache.put(implementation, id);
} else
RefactoringCorePlugin.logErrorMessage(Messages.format(RefactoringCoreMessages.RefactoringCorePlugin_creation_error, new String[] { id, clazz }));
} catch (CoreException exception) {
RefactoringCorePlugin.log(exception);
}
});
// final IConfigurationElement[] elements= Platform.getExtensionRegistry().getConfigurationElementsFor(RefactoringCore.ID_PLUGIN,
// REFACTORING_CONTRIBUTIONS_EXTENSION_POINT);
// for (int index= 0; index < elements.length; index++) {
// final IConfigurationElement element= elements[index];
// final String attributeId= element.getAttribute(ATTRIBUTE_ID);
// final String point= RefactoringCore.ID_PLUGIN + "." + REFACTORING_CONTRIBUTIONS_EXTENSION_POINT; //$NON-NLS-1$
// if (attributeId != null && !"".equals(attributeId)) { //$NON-NLS-1$
// final String className= element.getAttribute(ATTRIBUTE_CLASS);
// if (className != null && !"".equals(className)) { //$NON-NLS-1$
// try {
// final Object implementation= element.createExecutableExtension(ATTRIBUTE_CLASS);
// if (implementation instanceof RefactoringContribution) {
// if (fContributionCache.get(attributeId) != null)
// RefactoringCorePlugin.logErrorMessage(Messages.format(RefactoringCoreMessages
// .RefactoringCorePlugin_duplicate_warning, new String[] { attributeId, point}));
// fContributionCache.put(attributeId, implementation);
// fIdCache.put(implementation, attributeId);
// } else
// RefactoringCorePlugin.logErrorMessage(Messages.format(RefactoringCoreMessages.RefactoringCorePlugin_creation_error, new String[] { point, attributeId}));
// } catch (CoreException exception) {
// RefactoringCorePlugin.log(exception);
// }
// } else
// RefactoringCorePlugin.logErrorMessage(Messages.format(RefactoringCoreMessages.RefactoringCorePlugin_missing_class_attribute, new String[] { point, attributeId, ATTRIBUTE_CLASS}));
// } else
// RefactoringCorePlugin.logErrorMessage(Messages.format(RefactoringCoreMessages.RefactoringCorePlugin_missing_attribute, new String[] { point, ATTRIBUTE_ID}));
// }
}
}
use of org.eclipse.ltk.core.refactoring.RefactoringContribution in project che by eclipse.
the class JavaRefactoringDescriptor method createRefactoring.
/**
* {@inheritDoc}
*/
public Refactoring createRefactoring(final RefactoringStatus status) throws CoreException {
Refactoring refactoring = null;
final String id = getID();
final RefactoringContribution contribution = RefactoringCore.getRefactoringContribution(id);
if (contribution != null) {
if (contribution instanceof JavaRefactoringContribution) {
JavaRefactoringContribution javaContribution = (JavaRefactoringContribution) contribution;
refactoring = javaContribution.createRefactoring(this, status);
} else
JavaPlugin.log(new Status(IStatus.ERROR, JavaPlugin.getPluginId(), 0, MessageFormat.format(DescriptorMessages.JavaRefactoringDescriptor_no_resulting_descriptor, new Object[] { id }), null));
}
return refactoring;
}
Aggregations