Search in sources :

Example 21 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 22 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 23 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 24 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 25 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)199 IResource (org.eclipse.core.resources.IResource)89 IFile (org.eclipse.core.resources.IFile)71 IPath (org.eclipse.core.runtime.IPath)47 CoreException (org.eclipse.core.runtime.CoreException)46 IFolder (org.eclipse.core.resources.IFolder)45 Path (org.eclipse.core.runtime.Path)43 IProject (org.eclipse.core.resources.IProject)28 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)26 ArrayList (java.util.ArrayList)25 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)21 IOException (java.io.IOException)13 IStatus (org.eclipse.core.runtime.IStatus)13 ByteArrayInputStream (java.io.ByteArrayInputStream)12 File (java.io.File)12 InvocationTargetException (java.lang.reflect.InvocationTargetException)12 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)12 Status (org.eclipse.core.runtime.Status)10 PartInitException (org.eclipse.ui.PartInitException)10 InputStream (java.io.InputStream)9