use of org.eclipse.ltk.core.refactoring.RefactoringStatus in project che by eclipse.
the class MultiStateUndoChange method isValid.
/**
* {@inheritDoc}
*/
public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException {
if (pm == null)
pm = new NullProgressMonitor();
//$NON-NLS-1$
pm.beginTask("", 1);
try {
if (fValidationState == null)
//$NON-NLS-1$
throw new CoreException(new Status(IStatus.ERROR, RefactoringCorePlugin.getPluginId(), "MultiStateUndoChange has not been initialialized"));
ITextFileBuffer buffer = FileBuffers.getTextFileBufferManager().getTextFileBuffer(fFile.getFullPath(), LocationKind.IFILE);
fDirty = buffer != null && buffer.isDirty();
return fValidationState.isValid(needsSaving(), true);
} finally {
pm.done();
}
}
use of org.eclipse.ltk.core.refactoring.RefactoringStatus in project che by eclipse.
the class ParticipantExtensionPoint method getParticipants.
/**
* Returns all participants for a given element.
*
* @param status a refactoring status to report status if problems occurred while
* loading the participants
* @param processor the processor that will own the participants
* @param element the element to be copied or a corresponding descriptor
* @param arguments the arguments for the participants
* @param filter a participant filter to exclude certain participants, or <code>null</code>
* if no filtering is desired
* @param affectedNatures an array of project natures affected by the refactoring
* @param shared a list of shared participants
*
* @return an array of participants
*/
public RefactoringParticipant[] getParticipants(RefactoringStatus status, RefactoringProcessor processor, Object element, RefactoringArguments arguments, IParticipantDescriptorFilter filter, String[] affectedNatures, SharableParticipants shared) {
if (fParticipants == null)
init();
EvaluationContext evalContext = createEvaluationContext(processor, element, affectedNatures);
List result = new ArrayList();
for (Iterator iter = fParticipants.iterator(); iter.hasNext(); ) {
ParticipantDescriptor descriptor = (ParticipantDescriptor) iter.next();
if (!descriptor.isEnabled()) {
iter.remove();
} else {
try {
RefactoringStatus filterStatus = new RefactoringStatus();
if (descriptor.matches(evalContext, filter, filterStatus)) {
RefactoringParticipant participant = shared.get(descriptor);
if (participant != null) {
((ISharableParticipant) participant).addElement(element, arguments);
} else {
participant = descriptor.createParticipant();
if (fParticipantClass.isInstance(participant)) {
if (participant.initialize(processor, element, arguments)) {
participant.setDescriptor(descriptor);
result.add(participant);
if (participant instanceof ISharableParticipant)
shared.put(descriptor, participant);
}
} else {
status.addError(Messages.format(RefactoringCoreMessages.ParticipantExtensionPoint_participant_removed, descriptor.getName()));
RefactoringCorePlugin.logErrorMessage(Messages.format(RefactoringCoreMessages.ParticipantExtensionPoint_wrong_type, new String[] { descriptor.getName(), fParticipantClass.getName() }));
iter.remove();
}
}
} else {
status.merge(filterStatus);
}
} catch (CoreException e) {
logMalfunctioningParticipant(status, descriptor, e);
iter.remove();
} catch (RuntimeException e) {
logMalfunctioningParticipant(status, descriptor, e);
iter.remove();
}
}
}
return (RefactoringParticipant[]) result.toArray(new RefactoringParticipant[result.size()]);
}
use of org.eclipse.ltk.core.refactoring.RefactoringStatus in project che by eclipse.
the class ProcessorBasedRefactoring method checkInitialConditions.
/**
* {@inheritDoc}
*/
public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException {
if (pm == null)
pm = new NullProgressMonitor();
RefactoringStatus result = new RefactoringStatus();
//$NON-NLS-1$
pm.beginTask("", 10);
pm.setTaskName(RefactoringCoreMessages.ProcessorBasedRefactoring_initial_conditions);
result.merge(getProcessor().checkInitialConditions(new SubProgressMonitor(pm, 8)));
if (result.hasFatalError()) {
pm.done();
return result;
}
pm.done();
return result;
}
use of org.eclipse.ltk.core.refactoring.RefactoringStatus in project che by eclipse.
the class RenameNonPrivateFieldTest method helper2.
private void helper2(String fieldName, String newFieldName, boolean createDelegates) throws Exception {
ParticipantTesting.reset();
ICompilationUnit cu = createCUfromTestFile(getPackageP(), "A");
IType classA = getType(cu, "A");
IField field = classA.getField(fieldName);
boolean isEnum = JdtFlags.isEnum(field);
String id = isEnum ? IJavaRefactorings.RENAME_ENUM_CONSTANT : IJavaRefactorings.RENAME_FIELD;
RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(id);
descriptor.setJavaElement(field);
descriptor.setNewName(newFieldName);
descriptor.setUpdateReferences(fUpdateReferences);
descriptor.setUpdateTextualOccurrences(fUpdateTextualMatches);
if (!isEnum) {
descriptor.setRenameGetters(fRenameGetter);
descriptor.setRenameSetters(fRenameSetter);
descriptor.setKeepOriginal(createDelegates);
descriptor.setDeprecateDelegate(true);
}
RenameRefactoring refactoring = (RenameRefactoring) createRefactoring(descriptor);
RenameFieldProcessor processor = (RenameFieldProcessor) refactoring.getProcessor();
List elements = new ArrayList();
elements.add(field);
List args = new ArrayList();
args.add(new RenameArguments(newFieldName, fUpdateReferences));
if (fRenameGetter) {
elements.add(processor.getGetter());
args.add(new RenameArguments(processor.getNewGetterName(), fUpdateReferences));
}
if (fRenameSetter) {
elements.add(processor.getSetter());
args.add(new RenameArguments(processor.getNewSetterName(), fUpdateReferences));
}
String[] renameHandles = ParticipantTesting.createHandles(elements.toArray());
RefactoringStatus result = performRefactoring(refactoring);
assertEquals("was supposed to pass", null, result);
assertEqualLines("invalid renaming", getFileContents(getOutputTestFileName("A")), cu.getSource());
ParticipantTesting.testRename(renameHandles, (RenameArguments[]) args.toArray(new RenameArguments[args.size()]));
assertTrue("anythingToUndo", RefactoringCore.getUndoManager().anythingToUndo());
assertTrue("! anythingToRedo", !RefactoringCore.getUndoManager().anythingToRedo());
RefactoringCore.getUndoManager().performUndo(null, new NullProgressMonitor());
assertEqualLines("invalid undo", getFileContents(getInputTestFileName("A")), cu.getSource());
assertTrue("! anythingToUndo", !RefactoringCore.getUndoManager().anythingToUndo());
assertTrue("anythingToRedo", RefactoringCore.getUndoManager().anythingToRedo());
RefactoringCore.getUndoManager().performRedo(null, new NullProgressMonitor());
assertEqualLines("invalid redo", getFileContents(getOutputTestFileName("A")), cu.getSource());
}
use of org.eclipse.ltk.core.refactoring.RefactoringStatus in project che by eclipse.
the class RenamePackageTest method testPackageRenameWithResource1.
@Test
public void testPackageRenameWithResource1() throws Exception {
IPackageFragment fragment = getRoot().createPackageFragment("org.test", true, null);
StringBuffer buf = new StringBuffer();
buf.append("package org.test;\n");
buf.append("public class MyClass {\n");
buf.append(" org.test.MyClass me;\n");
buf.append("}\n");
fragment.createCompilationUnit("MyClass.java", buf.toString(), true, null);
IFile file = ((IFolder) getRoot().getResource()).getFile("x.properties");
byte[] content = "This is about 'org.test' and more".getBytes();
file.create(new ByteArrayInputStream(content), true, null);
file.refreshLocal(IResource.DEPTH_ONE, null);
RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_PACKAGE);
descriptor.setJavaElement(fragment);
descriptor.setNewName("org.test2");
descriptor.setUpdateReferences(true);
descriptor.setUpdateQualifiedNames(true);
descriptor.setFileNamePatterns("*.properties");
Refactoring refactoring = createRefactoring(descriptor);
RefactoringStatus status = performRefactoring(refactoring);
if (status != null)
assertTrue(status.toString(), status.isOK());
RefactoringProcessor processor = ((RenameRefactoring) refactoring).getProcessor();
IResourceMapper rm = (IResourceMapper) processor.getAdapter(IResourceMapper.class);
IJavaElementMapper jm = (IJavaElementMapper) processor.getAdapter(IJavaElementMapper.class);
checkMappingUnchanged(jm, rm, new Object[] { getRoot().getJavaProject(), getRoot(), file });
IFile newFile = ((IContainer) getRoot().getResource()).getFile(new Path("x.properties"));
assertEquals("This is about 'org.test2' and more", getContents(newFile));
checkMappingChanged(jm, rm, new Object[][] { { fragment, getRoot().getPackageFragment("org.test2") } });
}
Aggregations