Search in sources :

Example 51 with IResource

use of org.eclipse.core.resources.IResource in project che by eclipse.

the class CopyModifications method copy.

public void copy(IPackageFragment pack, CopyArguments javaArgs, CopyArguments resourceArgs) throws CoreException {
    add(pack, javaArgs, null);
    ResourceMapping mapping = JavaElementResourceMapping.create(pack);
    if (mapping != null) {
        add(mapping, resourceArgs, null);
    }
    IPackageFragmentRoot javaDestination = (IPackageFragmentRoot) javaArgs.getDestination();
    if (javaDestination.getResource() == null)
        return;
    IPackageFragment newPack = javaDestination.getPackageFragment(pack.getElementName());
    // the new name yet, so we use the current package name.
    if (!pack.hasSubpackages() && (!newPack.exists() || pack.equals(newPack))) {
        // we can do a simple move
        IContainer resourceDestination = newPack.getResource().getParent();
        createIncludingParents(resourceDestination);
        getResourceModifications().addCopyDelta(pack.getResource(), resourceArgs);
    } else {
        IContainer resourceDestination = (IContainer) newPack.getResource();
        createIncludingParents(resourceDestination);
        CopyArguments arguments = new CopyArguments(resourceDestination, resourceArgs.getExecutionLog());
        IResource[] resourcesToCopy = collectResourcesOfInterest(pack);
        for (int i = 0; i < resourcesToCopy.length; i++) {
            IResource toCopy = resourcesToCopy[i];
            getResourceModifications().addCopyDelta(toCopy, arguments);
        }
    }
}
Also used : IPackageFragment(org.eclipse.jdt.core.IPackageFragment) CopyArguments(org.eclipse.ltk.core.refactoring.participants.CopyArguments) JavaElementResourceMapping(org.eclipse.jdt.internal.corext.util.JavaElementResourceMapping) ResourceMapping(org.eclipse.core.resources.mapping.ResourceMapping) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Example 52 with IResource

use of org.eclipse.core.resources.IResource in project che by eclipse.

the class CreateCopyOfCompilationUnitChange method setEncoding.

private void setEncoding(ICompilationUnit unit) {
    IResource resource = unit.getResource();
    // no file so the encoding is taken from the target
    if (!(resource instanceof IFile))
        return;
    IFile file = (IFile) resource;
    try {
        String encoding = file.getCharset(false);
        if (encoding != null) {
            setEncoding(encoding, true);
        } else {
            encoding = file.getCharset(true);
            if (encoding != null) {
                setEncoding(encoding, false);
            }
        }
    } catch (CoreException e) {
    // Take encoding from target
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) IResource(org.eclipse.core.resources.IResource)

Example 53 with IResource

use of org.eclipse.core.resources.IResource in project che by eclipse.

the class DeleteChangeCreator method createPackageFragmentRootDeleteChange.

private static Change createPackageFragmentRootDeleteChange(IPackageFragmentRoot root) throws JavaModelException {
    IResource resource = root.getResource();
    if (resource != null && resource.isLinked()) {
        //XXX using this code is a workaround for jcore bug 31998
        //jcore cannot handle linked stuff
        //normally, we should always create DeletePackageFragmentRootChange
        CompositeChange composite = new DynamicValidationStateChange(RefactoringCoreMessages.DeleteRefactoring_delete_package_fragment_root);
        ClasspathChange change = ClasspathChange.removeEntryChange(root.getJavaProject(), root.getRawClasspathEntry());
        if (change != null) {
            composite.add(change);
        }
        //checked in preconditions
        Assert.isTrue(!Checks.isClasspathDelete(root));
        composite.add(createDeleteChange(resource));
        return composite;
    } else {
        Assert.isTrue(!root.isExternal());
        // TODO remove the query argument
        return new DeletePackageFragmentRootChange(root, true, null);
    }
}
Also used : ClasspathChange(org.eclipse.jdt.internal.corext.refactoring.changes.ClasspathChange) DeletePackageFragmentRootChange(org.eclipse.jdt.internal.corext.refactoring.changes.DeletePackageFragmentRootChange) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) IResource(org.eclipse.core.resources.IResource) DynamicValidationStateChange(org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationStateChange)

Example 54 with IResource

use of org.eclipse.core.resources.IResource in project che by eclipse.

the class MoveModifications method move.

public void move(IPackageFragment pack, MoveArguments args) throws CoreException {
    add(pack, args, null);
    if (pack.getResource() == null)
        return;
    IPackageFragmentRoot javaDestination = (IPackageFragmentRoot) args.getDestination();
    if (javaDestination.getResource() == null)
        return;
    IPackageFragment newPack = javaDestination.getPackageFragment(pack.getElementName());
    if (!pack.hasSubpackages() && !newPack.exists()) {
        // we can do a simple move
        IContainer resourceDestination = newPack.getResource().getParent();
        createIncludingParents(resourceDestination);
        getResourceModifications().addMove(pack.getResource(), new MoveArguments(resourceDestination, args.getUpdateReferences()));
    } else {
        IContainer resourceSource = (IContainer) pack.getResource();
        IContainer resourceDestination = (IContainer) newPack.getResource();
        createIncludingParents(resourceDestination);
        MoveArguments arguments = new MoveArguments(resourceDestination, args.getUpdateReferences());
        IResource[] resourcesToMove = collectResourcesOfInterest(pack);
        Set<IResource> allMembers = new HashSet<IResource>(Arrays.asList(resourceSource.members()));
        for (int i = 0; i < resourcesToMove.length; i++) {
            IResource toMove = resourcesToMove[i];
            getResourceModifications().addMove(toMove, arguments);
            allMembers.remove(toMove);
        }
        for (Iterator<IResource> iter = allMembers.iterator(); iter.hasNext(); ) {
            IResource element = iter.next();
            if (element instanceof IFile) {
                getResourceModifications().addDelete(element);
                iter.remove();
            }
        }
        if (allMembers.isEmpty()) {
            getResourceModifications().addDelete(resourceSource);
        }
    }
}
Also used : IPackageFragment(org.eclipse.jdt.core.IPackageFragment) IFile(org.eclipse.core.resources.IFile) MoveArguments(org.eclipse.ltk.core.refactoring.participants.MoveArguments) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) HashSet(java.util.HashSet)

Example 55 with IResource

use of org.eclipse.core.resources.IResource in project che by eclipse.

the class MoveModifications method move.

public void move(IPackageFragmentRoot sourceFolder, MoveArguments arguments) {
    add(sourceFolder, arguments, null);
    IResource sourceResource = sourceFolder.getResource();
    if (sourceResource != null) {
        getResourceModifications().addMove(sourceResource, new MoveArguments(getResourceDestination(arguments), arguments.getUpdateReferences()));
        IFile classpath = getClasspathFile(sourceResource);
        if (classpath != null) {
            getResourceModifications().addChanged(classpath);
        }
        classpath = getClasspathFile(getResourceDestination(arguments));
        if (classpath != null) {
            getResourceModifications().addChanged(classpath);
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) MoveArguments(org.eclipse.ltk.core.refactoring.participants.MoveArguments) IResource(org.eclipse.core.resources.IResource)

Aggregations

IResource (org.eclipse.core.resources.IResource)559 CoreException (org.eclipse.core.runtime.CoreException)141 IFile (org.eclipse.core.resources.IFile)140 IPath (org.eclipse.core.runtime.IPath)119 IProject (org.eclipse.core.resources.IProject)104 IContainer (org.eclipse.core.resources.IContainer)88 ArrayList (java.util.ArrayList)84 IFolder (org.eclipse.core.resources.IFolder)64 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)52 IStatus (org.eclipse.core.runtime.IStatus)47 IOException (java.io.IOException)46 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)44 Path (org.eclipse.core.runtime.Path)42 File (java.io.File)39 Status (org.eclipse.core.runtime.Status)38 IJavaProject (org.eclipse.jdt.core.IJavaProject)31 IJavaElement (org.eclipse.jdt.core.IJavaElement)30 ISelection (org.eclipse.jface.viewers.ISelection)26 List (java.util.List)25 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)22