use of org.eclipse.ltk.core.refactoring.RefactoringDescriptor 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.RefactoringDescriptor in project che by eclipse.
the class RefactoringSessionReader method readSession.
/**
* Reads a refactoring history descriptor from the specified input object.
*
* @param source
* the input source
* @return a corresponding refactoring history descriptor, or
* <code>null</code>
* @throws CoreException
* if an error occurs while reading form the input source
*/
public RefactoringSessionDescriptor readSession(final InputSource source) throws CoreException {
fSessionFound = false;
try {
//$NON-NLS-1$
source.setSystemId("/");
createParser(SAXParserFactory.newInstance()).parse(source, this);
if (!fSessionFound)
throw new CoreException(new Status(IStatus.ERROR, RefactoringCorePlugin.getPluginId(), IRefactoringCoreStatusCodes.REFACTORING_HISTORY_FORMAT_ERROR, RefactoringCoreMessages.RefactoringSessionReader_no_session, null));
if (fRefactoringDescriptors != null) {
if (//$NON-NLS-1$
fVersion == null || "".equals(fVersion))
throw new CoreException(new Status(IStatus.ERROR, RefactoringCorePlugin.getPluginId(), IRefactoringCoreStatusCodes.MISSING_REFACTORING_HISTORY_VERSION, RefactoringCoreMessages.RefactoringSessionReader_missing_version_information, null));
if (!IRefactoringSerializationConstants.CURRENT_VERSION.equals(fVersion))
throw new CoreException(new Status(IStatus.ERROR, RefactoringCorePlugin.getPluginId(), IRefactoringCoreStatusCodes.UNSUPPORTED_REFACTORING_HISTORY_VERSION, RefactoringCoreMessages.RefactoringSessionReader_unsupported_version_information, null));
return new RefactoringSessionDescriptor((RefactoringDescriptor[]) fRefactoringDescriptors.toArray(new RefactoringDescriptor[fRefactoringDescriptors.size()]), fVersion, fComment);
}
} catch (IOException exception) {
throwCoreException(exception, exception.getLocalizedMessage());
} catch (ParserConfigurationException exception) {
throwCoreException(exception, exception.getLocalizedMessage());
} catch (SAXParseException exception) {
String message = Messages.format(RefactoringCoreMessages.RefactoringSessionReader_invalid_contents_at, new Object[] { Integer.toString(exception.getLineNumber()), Integer.toString(exception.getColumnNumber()) });
throwCoreException(exception, message);
} catch (SAXException exception) {
throwCoreException(exception, exception.getLocalizedMessage());
} finally {
fRefactoringDescriptors = null;
fVersion = null;
fComment = null;
fLocator = null;
}
return null;
}
use of org.eclipse.ltk.core.refactoring.RefactoringDescriptor in project che by eclipse.
the class RefactoringSessionReader method startElement.
/**
* {@inheritDoc}
*/
public void startElement(final String uri, final String localName, final String qualifiedName, final Attributes attributes) throws SAXException {
if (IRefactoringSerializationConstants.ELEMENT_REFACTORING.equals(qualifiedName)) {
final int length = attributes.getLength();
final Map map = new HashMap(length);
//$NON-NLS-1$
String id = "";
//$NON-NLS-1$
String stamp = "";
//$NON-NLS-1$
String description = "";
String comment = null;
//$NON-NLS-1$
String flags = "0";
String project = null;
for (int index = 0; index < length; index++) {
final String name = attributes.getQName(index);
final String value = attributes.getValue(index);
if (IRefactoringSerializationConstants.ATTRIBUTE_ID.equals(name)) {
id = value;
} else if (IRefactoringSerializationConstants.ATTRIBUTE_STAMP.equals(name)) {
stamp = value;
} else if (IRefactoringSerializationConstants.ATTRIBUTE_DESCRIPTION.equals(name)) {
description = value;
} else if (IRefactoringSerializationConstants.ATTRIBUTE_FLAGS.equals(name)) {
flags = value;
} else if (IRefactoringSerializationConstants.ATTRIBUTE_COMMENT.equals(name)) {
if (//$NON-NLS-1$
!"".equals(value))
comment = value;
} else if (IRefactoringSerializationConstants.ATTRIBUTE_PROJECT.equals(name)) {
project = value;
} else if (!"".equals(name)) {
//$NON-NLS-1$
map.put(name, value);
}
}
int flag = 0;
try {
flag = Integer.parseInt(flags);
} catch (NumberFormatException exception) {
// Do nothing
}
RefactoringDescriptor descriptor = null;
if (fCreateDefaultDescriptors) {
descriptor = new DefaultRefactoringDescriptor(id, project, description, comment, map, flag);
} else {
if (fProject != null && project == null) {
// override project from file if fProject != null
project = fProject;
}
try {
descriptor = RefactoringContributionManager.getInstance().createDescriptor(id, project, description, comment, map, flag);
} catch (RuntimeException e) {
throw new SAXParseException(RefactoringCoreMessages.RefactoringSessionReader_invalid_values_in_xml, fLocator, e) {
private static final long serialVersionUID = 1L;
public Throwable getCause() {
// support proper 1.4-style exception chaining
return getException();
}
};
}
}
try {
descriptor.setTimeStamp(Long.valueOf(stamp).longValue());
} catch (NumberFormatException exception) {
// Do nothing
}
if (fRefactoringDescriptors == null)
fRefactoringDescriptors = new ArrayList();
fRefactoringDescriptors.add(descriptor);
} else if (IRefactoringSerializationConstants.ELEMENT_SESSION.equals(qualifiedName)) {
fSessionFound = true;
final String version = attributes.getValue(IRefactoringSerializationConstants.ATTRIBUTE_VERSION);
if (//$NON-NLS-1$
version != null && !"".equals(version))
fVersion = version;
fComment = attributes.getValue(IRefactoringSerializationConstants.ATTRIBUTE_COMMENT);
}
}
use of org.eclipse.ltk.core.refactoring.RefactoringDescriptor in project che by eclipse.
the class RefactoringHistoryService method readRefactoringHistory.
/**
* {@inheritDoc}
*/
public RefactoringHistory readRefactoringHistory(final InputStream stream, final int flags) throws CoreException {
Assert.isNotNull(stream);
Assert.isTrue(flags >= RefactoringDescriptor.NONE);
final List list = new ArrayList();
final RefactoringSessionDescriptor descriptor = new RefactoringSessionReader(false, null).readSession(new InputSource(stream));
if (descriptor != null) {
final RefactoringDescriptor[] descriptors = descriptor.getRefactorings();
if (flags > RefactoringDescriptor.NONE) {
for (int index = 0; index < descriptors.length; index++) {
final int current = descriptors[index].getFlags();
if ((current | flags) == current)
list.add(descriptors[index]);
}
} else
list.addAll(Arrays.asList(descriptors));
}
final RefactoringDescriptorProxy[] proxies = new RefactoringDescriptorProxy[list.size()];
for (int index = 0; index < list.size(); index++) proxies[index] = new RefactoringDescriptorProxyAdapter((RefactoringDescriptor) list.get(index));
return new RefactoringHistoryImplementation(proxies);
}
use of org.eclipse.ltk.core.refactoring.RefactoringDescriptor in project che by eclipse.
the class RenameTypeTest method helper3_fail.
private void helper3_fail(String oldName, String newName, boolean updateSimilar, boolean updateTextual, boolean updateRef) throws JavaModelException, CoreException, IOException, Exception {
RefactoringDescriptor descriptor = initWithAllOptions(oldName, oldName, newName, updateRef, updateTextual, updateSimilar, null, RenamingNameSuggestor.STRATEGY_SUFFIX);
Assert.assertNotNull("was supposed to fail", performRefactoring(descriptor));
}
Aggregations