Search in sources :

Example 16 with RenameArguments

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

the class RenameModifications method rename.

public void rename(IPackageFragment rootPackage, RenameArguments args, boolean renameSubPackages) throws CoreException {
    add(rootPackage, args, null);
    IPackageFragment[] allSubPackages = null;
    if (renameSubPackages) {
        allSubPackages = getSubpackages(rootPackage);
        for (int i = 0; i < allSubPackages.length; i++) {
            IPackageFragment pack = allSubPackages[i];
            RenameArguments subArgs = new RenameArguments(getNewPackageName(rootPackage, args.getNewName(), pack.getElementName()), args.getUpdateReferences());
            add(pack, subArgs, null);
        }
    }
    IContainer container = (IContainer) rootPackage.getResource();
    if (container == null)
        return;
    IContainer target = (IContainer) ((IPackageFragmentRoot) rootPackage.getParent()).getPackageFragment(args.getNewName()).getResource();
    if ((!rootPackage.hasSubpackages() || renameSubPackages) && canMove(container, target)) {
        createIncludingParents(target.getParent());
        if (container.getParent().equals(target.getParent())) {
            getResourceModifications().addRename(container, new RenameArguments(target.getName(), args.getUpdateReferences()));
        } else {
            // moves and deletes.
            try {
                getResourceModifications().ignoreForDelta();
                addAllResourceModifications(rootPackage, args, renameSubPackages, allSubPackages);
            } finally {
                getResourceModifications().trackForDelta();
            }
            getResourceModifications().addDelta(new ResourceModifications.MoveDescription(container, target.getFullPath()));
        }
    } else {
        addAllResourceModifications(rootPackage, args, renameSubPackages, allSubPackages);
    }
}
Also used : IPackageFragment(org.eclipse.jdt.core.IPackageFragment) RenameArguments(org.eclipse.ltk.core.refactoring.participants.RenameArguments) ResourceModifications(org.eclipse.jdt.internal.corext.refactoring.participants.ResourceModifications) IContainer(org.eclipse.core.resources.IContainer) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Example 17 with RenameArguments

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

the class ResourceModifications method addRename.

/**
	 * Adds the given resource to the list of renamed
	 * resources.
	 *
	 * @param rename the resource to be renamed
	 * @param arguments the arguments of the rename
	 */
public void addRename(IResource rename, RenameArguments arguments) {
    Assert.isNotNull(rename);
    Assert.isNotNull(arguments);
    if (fRename == null) {
        fRename = new ArrayList<IResource>(2);
        fRenameArguments = new ArrayList<RenameArguments>(2);
    }
    fRename.add(rename);
    fRenameArguments.add(arguments);
    if (fIgnoreCount == 0) {
        IPath newPath = rename.getFullPath().removeLastSegments(1).append(arguments.getNewName());
        internalAdd(new MoveDescription(rename, newPath));
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) RenameArguments(org.eclipse.ltk.core.refactoring.participants.RenameArguments) IResource(org.eclipse.core.resources.IResource)

Example 18 with RenameArguments

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

the class RenameLocalVariableProcessor method computeRenameModifications.

@Override
protected RenameModifications computeRenameModifications() throws CoreException {
    RenameModifications result = new RenameModifications();
    result.rename(fLocalVariable, new RenameArguments(getNewElementName(), getUpdateReferences()));
    return result;
}
Also used : RenameArguments(org.eclipse.ltk.core.refactoring.participants.RenameArguments)

Example 19 with RenameArguments

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

the class RenameResourceProcessor method checkFinalConditions.

/* (non-Javadoc)
	 * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#checkFinalConditions(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext)
	 */
public RefactoringStatus checkFinalConditions(IProgressMonitor pm, CheckConditionsContext context) throws CoreException {
    //$NON-NLS-1$
    pm.beginTask("", 1);
    try {
        fRenameArguments = new RenameArguments(getNewResourceName(), isUpdateReferences());
        ResourceChangeChecker checker = (ResourceChangeChecker) context.getChecker(ResourceChangeChecker.class);
        IResourceChangeDescriptionFactory deltaFactory = checker.getDeltaFactory();
        ResourceModifications.buildMoveDelta(deltaFactory, fResource, fRenameArguments);
        return new RefactoringStatus();
    } finally {
        pm.done();
    }
}
Also used : RenameArguments(org.eclipse.ltk.core.refactoring.participants.RenameArguments) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) IResourceChangeDescriptionFactory(org.eclipse.core.resources.mapping.IResourceChangeDescriptionFactory) ResourceChangeChecker(org.eclipse.ltk.core.refactoring.participants.ResourceChangeChecker)

Example 20 with RenameArguments

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

the class ResourceModifications method getParticipants.

public RefactoringParticipant[] getParticipants(RefactoringStatus status, RefactoringProcessor processor, String[] natures, SharableParticipants shared) {
    List result = new ArrayList(5);
    if (fDelete != null) {
        DeleteArguments arguments = new DeleteArguments();
        for (Iterator iter = fDelete.iterator(); iter.hasNext(); ) {
            DeleteParticipant[] deletes = ParticipantManager.loadDeleteParticipants(status, processor, iter.next(), arguments, natures, shared);
            result.addAll(Arrays.asList(deletes));
        }
    }
    if (fCreate != null) {
        CreateArguments arguments = new CreateArguments();
        for (Iterator iter = fCreate.iterator(); iter.hasNext(); ) {
            CreateParticipant[] creates = ParticipantManager.loadCreateParticipants(status, processor, iter.next(), arguments, natures, shared);
            result.addAll(Arrays.asList(creates));
        }
    }
    if (fMove != null) {
        for (int i = 0; i < fMove.size(); i++) {
            Object element = fMove.get(i);
            MoveArguments arguments = (MoveArguments) fMoveArguments.get(i);
            MoveParticipant[] moves = ParticipantManager.loadMoveParticipants(status, processor, element, arguments, natures, shared);
            result.addAll(Arrays.asList(moves));
        }
    }
    if (fCopy != null) {
        for (int i = 0; i < fCopy.size(); i++) {
            Object element = fCopy.get(i);
            CopyArguments arguments = (CopyArguments) fCopyArguments.get(i);
            CopyParticipant[] copies = ParticipantManager.loadCopyParticipants(status, processor, element, arguments, natures, shared);
            result.addAll(Arrays.asList(copies));
        }
    }
    if (fRename != null) {
        for (int i = 0; i < fRename.size(); i++) {
            Object resource = fRename.get(i);
            RenameArguments arguments = (RenameArguments) fRenameArguments.get(i);
            RenameParticipant[] renames = ParticipantManager.loadRenameParticipants(status, processor, resource, arguments, natures, shared);
            result.addAll(Arrays.asList(renames));
        }
    }
    return (RefactoringParticipant[]) result.toArray(new RefactoringParticipant[result.size()]);
}
Also used : RenameArguments(org.eclipse.ltk.core.refactoring.participants.RenameArguments) RefactoringParticipant(org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant) ArrayList(java.util.ArrayList) MoveParticipant(org.eclipse.ltk.core.refactoring.participants.MoveParticipant) DeleteParticipant(org.eclipse.ltk.core.refactoring.participants.DeleteParticipant) CreateArguments(org.eclipse.ltk.core.refactoring.participants.CreateArguments) DeleteArguments(org.eclipse.ltk.core.refactoring.participants.DeleteArguments) CopyArguments(org.eclipse.ltk.core.refactoring.participants.CopyArguments) CreateParticipant(org.eclipse.ltk.core.refactoring.participants.CreateParticipant) CopyParticipant(org.eclipse.ltk.core.refactoring.participants.CopyParticipant) MoveArguments(org.eclipse.ltk.core.refactoring.participants.MoveArguments) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) RenameParticipant(org.eclipse.ltk.core.refactoring.participants.RenameParticipant)

Aggregations

RenameArguments (org.eclipse.ltk.core.refactoring.participants.RenameArguments)36 Test (org.junit.Test)15 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)13 ArrayList (java.util.ArrayList)12 List (java.util.List)11 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)9 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)8 RenameJavaElementDescriptor (org.eclipse.jdt.core.refactoring.descriptors.RenameJavaElementDescriptor)7 MoveArguments (org.eclipse.ltk.core.refactoring.participants.MoveArguments)7 IType (org.eclipse.jdt.core.IType)6 RenameRefactoring (org.eclipse.ltk.core.refactoring.participants.RenameRefactoring)6 BaseTest (org.eclipse.che.plugin.java.server.che.BaseTest)5 IFolder (org.eclipse.core.resources.IFolder)5 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)5 IField (org.eclipse.jdt.core.IField)5 Ignore (org.junit.Ignore)5 IMethod (org.eclipse.jdt.core.IMethod)4 IResource (org.eclipse.core.resources.IResource)3 IPath (org.eclipse.core.runtime.IPath)3 RenamePackageProcessor (org.eclipse.jdt.internal.corext.refactoring.rename.RenamePackageProcessor)3