Search in sources :

Example 1 with IContainer

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

the class Util method getPackageFragment.

public static IPackageFragment getPackageFragment(char[] fileName, int pkgEnd, int jarSeparator) {
    if (jarSeparator != -1) {
        String jarMemento = new String(fileName, 0, jarSeparator);
        PackageFragmentRoot root = (PackageFragmentRoot) JavaCore.create(jarMemento);
        if (pkgEnd == jarSeparator)
            return root.getPackageFragment(CharOperation.NO_STRINGS);
        char[] pkgName = CharOperation.subarray(fileName, jarSeparator + 1, pkgEnd);
        char[][] compoundName = CharOperation.splitOn('/', pkgName);
        return root.getPackageFragment(CharOperation.toStrings(compoundName));
    } else {
        Path path = new Path(new String(fileName, 0, pkgEnd));
        IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
        IContainer folder = path.segmentCount() == 1 ? workspaceRoot.getProject(path.lastSegment()) : (IContainer) workspaceRoot.getFolder(path);
        IJavaElement element = JavaCore.create(folder);
        if (element == null)
            return null;
        switch(element.getElementType()) {
            case IJavaElement.PACKAGE_FRAGMENT:
                return (IPackageFragment) element;
            case IJavaElement.PACKAGE_FRAGMENT_ROOT:
                return ((PackageFragmentRoot) element).getPackageFragment(CharOperation.NO_STRINGS);
            case IJavaElement.JAVA_PROJECT:
                PackageFragmentRoot root = (PackageFragmentRoot) ((IJavaProject) element).getPackageFragmentRoot(folder);
                if (root == null)
                    return null;
                return root.getPackageFragment(CharOperation.NO_STRINGS);
        }
        return null;
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IJavaElement(org.eclipse.jdt.core.IJavaElement) PackageFragmentRoot(org.eclipse.jdt.internal.core.PackageFragmentRoot) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IContainer(org.eclipse.core.resources.IContainer)

Example 2 with IContainer

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

the class RenamePackageProcessor method getRefactoredResource.

//---- IResourceMapper  ----------------------------------
public IResource getRefactoredResource(IResource element) {
    IFolder packageFolder = (IFolder) fPackage.getResource();
    if (packageFolder == null)
        return element;
    IContainer newPackageFolder = (IContainer) getNewPackage().getResource();
    if (packageFolder.equals(element))
        return newPackageFolder;
    IPath packagePath = packageFolder.getProjectRelativePath();
    IPath elementPath = element.getProjectRelativePath();
    if (packagePath.isPrefixOf(elementPath)) {
        if (fRenameSubpackages || (element instanceof IFile && packageFolder.equals(element.getParent()))) {
            IPath pathInPackage = elementPath.removeFirstSegments(packagePath.segmentCount());
            if (element instanceof IFile)
                return newPackageFolder.getFile(pathInPackage);
            else
                return newPackageFolder.getFolder(pathInPackage);
        }
    }
    return element;
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) IContainer(org.eclipse.core.resources.IContainer) IFolder(org.eclipse.core.resources.IFolder)

Example 3 with IContainer

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

the class RenameModifications method addAllResourceModifications.

private void addAllResourceModifications(IPackageFragment rootPackage, RenameArguments args, boolean renameSubPackages, IPackageFragment[] allSubPackages) throws CoreException {
    IFolder target = addResourceModifications(rootPackage, args, rootPackage, renameSubPackages);
    if (renameSubPackages) {
        IContainer container = (IContainer) rootPackage.getResource();
        if (container == null)
            return;
        boolean removeContainer = !container.contains(target);
        for (int i = 0; i < allSubPackages.length; i++) {
            IPackageFragment pack = allSubPackages[i];
            IFolder subTarget = addResourceModifications(rootPackage, args, pack, renameSubPackages);
            if (container.contains(subTarget))
                removeContainer = false;
        }
        if (removeContainer) {
            getResourceModifications().addDelete(container);
        }
    }
}
Also used : IPackageFragment(org.eclipse.jdt.core.IPackageFragment) IContainer(org.eclipse.core.resources.IContainer) IFolder(org.eclipse.core.resources.IFolder)

Example 4 with IContainer

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

the class ImportOperation method createFromRoot.

/**
     * Creates the folders that appear in the specified resource path
     * assuming that the destinationContainer begins at the root. Do not create projects.
     *
     * @param path the relative path of the resource
     * @return the container resource coresponding to the given path
     * @exception CoreException if this method failed
     */
private IContainer createFromRoot(IPath path) throws CoreException {
    int segmentCount = path.segmentCount();
    //Assume the project exists 
    IContainer currentFolder = ((IWorkspaceRoot) destinationContainer).getProject(path.segment(0));
    for (int i = 1; i < segmentCount; i++) {
        currentFolder = currentFolder.getFolder(new Path(path.segment(i)));
        if (!currentFolder.exists()) {
            ((IFolder) currentFolder).create(false, true, null);
        }
    }
    return currentFolder;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IContainer(org.eclipse.core.resources.IContainer) IFolder(org.eclipse.core.resources.IFolder)

Example 5 with IContainer

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

the class AbstractResourceDescription method verifyExistence.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ui.ide.undo.ResourceDescription#verifyExistence(boolean)
	 */
public boolean verifyExistence(boolean checkMembers) {
    IContainer p = parent;
    if (p == null) {
        p = getWorkspace().getRoot();
    }
    IResource handle = p.findMember(getName());
    return handle != null;
}
Also used : IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource)

Aggregations

IContainer (org.eclipse.core.resources.IContainer)114 IResource (org.eclipse.core.resources.IResource)45 IFile (org.eclipse.core.resources.IFile)44 IFolder (org.eclipse.core.resources.IFolder)33 CoreException (org.eclipse.core.runtime.CoreException)29 IPath (org.eclipse.core.runtime.IPath)29 IProject (org.eclipse.core.resources.IProject)20 Path (org.eclipse.core.runtime.Path)20 ArrayList (java.util.ArrayList)14 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)10 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)8 File (java.io.File)7 IOException (java.io.IOException)7 IStatus (org.eclipse.core.runtime.IStatus)7 ISelection (org.eclipse.jface.viewers.ISelection)7 ExecutionException (org.eclipse.core.commands.ExecutionException)6 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)6 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)6