Search in sources :

Example 1 with MoveRefactoring

use of org.eclipse.ltk.core.refactoring.participants.MoveRefactoring in project che by eclipse.

the class RefactoringManager method createMoveRefactoringSession.

/**
     * Create move refactoring session.
     *
     * @param javaElements
     *         the java elements
     * @return the ID of the refactoring session
     */
public String createMoveRefactoringSession(IJavaElement[] javaElements) throws JavaModelException, RefactoringException {
    IReorgPolicy.IMovePolicy policy = ReorgPolicyFactory.createMovePolicy(new IResource[0], javaElements);
    if (policy.canEnable()) {
        JavaMoveProcessor processor = new JavaMoveProcessor(policy);
        //TODO this may overwrite existing sources.
        processor.setReorgQueries(new NullReorgQueries());
        processor.setCreateTargetQueries(() -> null);
        Refactoring refactoring = new MoveRefactoring(processor);
        MoveRefactoringSession session = new MoveRefactoringSession(refactoring, processor);
        final String id = String.format("move-%s", sessionId.getAndIncrement());
        sessions.put(id, session);
        return id;
    } else {
        throw new RefactoringException("Can't create move refactoring session.");
    }
}
Also used : IReorgPolicy(org.eclipse.jdt.internal.corext.refactoring.reorg.IReorgPolicy) NullReorgQueries(org.eclipse.jdt.internal.corext.refactoring.reorg.NullReorgQueries) Refactoring(org.eclipse.ltk.core.refactoring.Refactoring) RenameRefactoring(org.eclipse.ltk.core.refactoring.participants.RenameRefactoring) MoveRefactoring(org.eclipse.ltk.core.refactoring.participants.MoveRefactoring) MoveRefactoring(org.eclipse.ltk.core.refactoring.participants.MoveRefactoring) MoveRefactoringSession(org.eclipse.che.plugin.java.server.refactoring.session.MoveRefactoringSession) JavaMoveProcessor(org.eclipse.jdt.internal.corext.refactoring.reorg.JavaMoveProcessor)

Example 2 with MoveRefactoring

use of org.eclipse.ltk.core.refactoring.participants.MoveRefactoring in project che by eclipse.

the class MoveResourcesDescriptor method createRefactoring.

/* (non-Javadoc)
	 * @see org.eclipse.ltk.core.refactoring.RefactoringDescriptor#createRefactoring(org.eclipse.ltk.core.refactoring.RefactoringStatus)
	 */
public Refactoring createRefactoring(RefactoringStatus status) throws CoreException {
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    IPath destinationPath = getDestinationPath();
    if (destinationPath == null) {
        status.addFatalError(RefactoringCoreMessages.MoveResourcesDescriptor_error_destination_not_set);
        return null;
    }
    IResource destination = root.findMember(destinationPath);
    if (!(destination instanceof IFolder || destination instanceof IProject) || !destination.exists()) {
        status.addFatalError(Messages.format(RefactoringCoreMessages.MoveResourcesDescriptor_error_destination_not_exists, BasicElementLabels.getPathLabel(destinationPath, false)));
        return null;
    }
    IPath[] paths = getResourcePathsToMove();
    if (paths == null) {
        status.addFatalError(RefactoringCoreMessages.MoveResourcesDescriptor_error_moved_not_set);
        return null;
    }
    IResource[] resources = new IResource[paths.length];
    for (int i = 0; i < paths.length; i++) {
        IPath path = paths[i];
        if (path == null) {
            status.addFatalError(RefactoringCoreMessages.MoveResourcesDescriptor_error_moved_contains_null);
            return null;
        }
        IResource resource = root.findMember(path);
        if (resource == null || !resource.exists()) {
            status.addFatalError(Messages.format(RefactoringCoreMessages.MoveResourcesDescriptor_error_moved_not_exists, BasicElementLabels.getPathLabel(path, false)));
            return null;
        }
        if (!(resource instanceof IFile || resource instanceof IFolder)) {
            status.addFatalError(Messages.format(RefactoringCoreMessages.MoveResourcesDescriptor_error_moved_not_file_or_folder, BasicElementLabels.getPathLabel(path, false)));
            return null;
        }
        resources[i] = resource;
    }
    MoveResourcesProcessor processor = new MoveResourcesProcessor(resources);
    processor.setDestination((IContainer) destination);
    processor.setUpdateReferences(isUpdateReferences());
    return new MoveRefactoring(processor);
}
Also used : IFile(org.eclipse.core.resources.IFile) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IPath(org.eclipse.core.runtime.IPath) MoveResourcesProcessor(org.eclipse.ltk.internal.core.refactoring.resource.MoveResourcesProcessor) MoveRefactoring(org.eclipse.ltk.core.refactoring.participants.MoveRefactoring) IResource(org.eclipse.core.resources.IResource) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

MoveRefactoring (org.eclipse.ltk.core.refactoring.participants.MoveRefactoring)2 MoveRefactoringSession (org.eclipse.che.plugin.java.server.refactoring.session.MoveRefactoringSession)1 IFile (org.eclipse.core.resources.IFile)1 IFolder (org.eclipse.core.resources.IFolder)1 IProject (org.eclipse.core.resources.IProject)1 IResource (org.eclipse.core.resources.IResource)1 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)1 IPath (org.eclipse.core.runtime.IPath)1 IReorgPolicy (org.eclipse.jdt.internal.corext.refactoring.reorg.IReorgPolicy)1 JavaMoveProcessor (org.eclipse.jdt.internal.corext.refactoring.reorg.JavaMoveProcessor)1 NullReorgQueries (org.eclipse.jdt.internal.corext.refactoring.reorg.NullReorgQueries)1 Refactoring (org.eclipse.ltk.core.refactoring.Refactoring)1 RenameRefactoring (org.eclipse.ltk.core.refactoring.participants.RenameRefactoring)1 MoveResourcesProcessor (org.eclipse.ltk.internal.core.refactoring.resource.MoveResourcesProcessor)1