Search in sources :

Example 1 with RefactoringContribution

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;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IUndoManager(org.eclipse.ltk.core.refactoring.IUndoManager) RefactoringContribution(org.eclipse.ltk.core.refactoring.RefactoringContribution) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) Change(org.eclipse.ltk.core.refactoring.Change) IResourceChangeListener(org.eclipse.core.resources.IResourceChangeListener) ChangeDescriptor(org.eclipse.ltk.core.refactoring.ChangeDescriptor) RefactoringChangeDescriptor(org.eclipse.ltk.core.refactoring.RefactoringChangeDescriptor) RefactoringChangeDescriptor(org.eclipse.ltk.core.refactoring.RefactoringChangeDescriptor) JavaRefactoringDescriptor(org.eclipse.jdt.core.refactoring.descriptors.JavaRefactoringDescriptor) RefactoringDescriptor(org.eclipse.ltk.core.refactoring.RefactoringDescriptor) CreateChangeOperation(org.eclipse.ltk.core.refactoring.CreateChangeOperation) PerformChangeOperation(org.eclipse.ltk.core.refactoring.PerformChangeOperation) IResourceChangeEvent(org.eclipse.core.resources.IResourceChangeEvent) IWorkspace(org.eclipse.core.resources.IWorkspace) CheckConditionsOperation(org.eclipse.ltk.core.refactoring.CheckConditionsOperation) JavaRefactoringDescriptor(org.eclipse.jdt.core.refactoring.descriptors.JavaRefactoringDescriptor)

Example 2 with RefactoringContribution

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

Example 3 with RefactoringContribution

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;
}
Also used : RefactoringContribution(org.eclipse.ltk.core.refactoring.RefactoringContribution) Map(java.util.Map) HashMap(java.util.HashMap) NamedNodeMap(org.w3c.dom.NamedNodeMap)

Example 4 with RefactoringContribution

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}));
    //			}
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) HashMap(java.util.HashMap) RefactoringContribution(org.eclipse.ltk.core.refactoring.RefactoringContribution)

Example 5 with RefactoringContribution

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

Aggregations

RefactoringContribution (org.eclipse.ltk.core.refactoring.RefactoringContribution)7 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)4 CoreException (org.eclipse.core.runtime.CoreException)3 Refactoring (org.eclipse.ltk.core.refactoring.Refactoring)3 HashMap (java.util.HashMap)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 Change (org.eclipse.ltk.core.refactoring.Change)2 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Map (java.util.Map)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1 IContainer (org.eclipse.core.resources.IContainer)1 IResourceChangeEvent (org.eclipse.core.resources.IResourceChangeEvent)1 IResourceChangeListener (org.eclipse.core.resources.IResourceChangeListener)1 IWorkspace (org.eclipse.core.resources.IWorkspace)1 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)1 IStatus (org.eclipse.core.runtime.IStatus)1 MultiStatus (org.eclipse.core.runtime.MultiStatus)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1