Search in sources :

Example 16 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 17 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 18 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 19 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 20 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)1487 IFile (org.eclipse.core.resources.IFile)390 CoreException (org.eclipse.core.runtime.CoreException)390 IPath (org.eclipse.core.runtime.IPath)315 IProject (org.eclipse.core.resources.IProject)286 ArrayList (java.util.ArrayList)237 IFolder (org.eclipse.core.resources.IFolder)187 IContainer (org.eclipse.core.resources.IContainer)175 Path (org.eclipse.core.runtime.Path)141 File (java.io.File)124 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)109 IOException (java.io.IOException)103 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)95 IStatus (org.eclipse.core.runtime.IStatus)89 List (java.util.List)83 IJavaProject (org.eclipse.jdt.core.IJavaProject)75 HashSet (java.util.HashSet)71 Status (org.eclipse.core.runtime.Status)66 HashMap (java.util.HashMap)60 IAdaptable (org.eclipse.core.runtime.IAdaptable)59