Search in sources :

Example 96 with RefactoringStatus

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();
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer)

Example 97 with RefactoringStatus

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()]);
}
Also used : ParticipantDescriptor(org.eclipse.ltk.internal.core.refactoring.ParticipantDescriptor) CoreException(org.eclipse.core.runtime.CoreException) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) ArrayList(java.util.ArrayList) List(java.util.List) EvaluationContext(org.eclipse.core.expressions.EvaluationContext)

Example 98 with RefactoringStatus

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;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 99 with RefactoringStatus

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());
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) RenameArguments(org.eclipse.ltk.core.refactoring.participants.RenameArguments) RenameRefactoring(org.eclipse.ltk.core.refactoring.participants.RenameRefactoring) ArrayList(java.util.ArrayList) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) RenameFieldProcessor(org.eclipse.jdt.internal.corext.refactoring.rename.RenameFieldProcessor) IField(org.eclipse.jdt.core.IField) IType(org.eclipse.jdt.core.IType) ArrayList(java.util.ArrayList) List(java.util.List) RenameJavaElementDescriptor(org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor)

Example 100 with RefactoringStatus

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") } });
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) IFile(org.eclipse.core.resources.IFile) RenameRefactoring(org.eclipse.ltk.core.refactoring.participants.RenameRefactoring) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) IResourceMapper(org.eclipse.ltk.core.refactoring.IResourceMapper) ByteArrayInputStream(java.io.ByteArrayInputStream) RefactoringProcessor(org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor) IJavaElementMapper(org.eclipse.jdt.core.refactoring.IJavaElementMapper) RenameJavaElementDescriptor(org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor) IContainer(org.eclipse.core.resources.IContainer) Refactoring(org.eclipse.ltk.core.refactoring.Refactoring) RenameRefactoring(org.eclipse.ltk.core.refactoring.participants.RenameRefactoring) ProcessorBasedRefactoring(org.eclipse.ltk.core.refactoring.participants.ProcessorBasedRefactoring) IFolder(org.eclipse.core.resources.IFolder) Test(org.junit.Test)

Aggregations

RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)251 IType (org.eclipse.jdt.core.IType)62 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)53 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)30 IMethod (org.eclipse.jdt.core.IMethod)29 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)28 IJavaElement (org.eclipse.jdt.core.IJavaElement)28 Test (org.junit.Test)26 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)24 ArrayList (java.util.ArrayList)23 BaseTest (org.eclipse.che.plugin.java.server.che.BaseTest)21 RenameRefactoring (org.eclipse.ltk.core.refactoring.participants.RenameRefactoring)19 RenameJavaElementDescriptor (org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor)18 IFile (org.eclipse.core.resources.IFile)16 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)16 ASTNode (org.eclipse.jdt.core.dom.ASTNode)16 CoreException (org.eclipse.core.runtime.CoreException)15 IField (org.eclipse.jdt.core.IField)15 IStatus (org.eclipse.core.runtime.IStatus)14 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)13