Search in sources :

Example 6 with IPath

use of org.eclipse.core.runtime.IPath in project che by eclipse.

the class HandleFactory method getPkgFragmentRoot.

/**
	 * Returns the package fragment root that contains the given resource path.
	 */
private PackageFragmentRoot getPkgFragmentRoot(String pathString) {
    IPath path = new Path(pathString);
    IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
    for (int i = 0, max = projects.length; i < max; i++) {
        try {
            IProject project = projects[i];
            if (!project.isAccessible() || !project.hasNature(JavaCore.NATURE_ID))
                continue;
            IJavaProject javaProject = this.javaModel.getJavaProject(project);
            IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots();
            for (int j = 0, rootCount = roots.length; j < rootCount; j++) {
                PackageFragmentRoot root = (PackageFragmentRoot) roots[j];
                if (root.internalPath().isPrefixOf(path) && !Util.isExcluded(path, root.fullInclusionPatternChars(), root.fullExclusionPatternChars(), false)) {
                    return root;
                }
            }
        } catch (CoreException e) {
        // CoreException from hasNature - should not happen since we check that the project is accessible
        // JavaModelException from getPackageFragmentRoots - a problem occured while accessing project: nothing we can do, ignore
        }
    }
    return null;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) PackageFragmentRoot(org.eclipse.jdt.internal.core.PackageFragmentRoot) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) IJavaProject(org.eclipse.jdt.core.IJavaProject) IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) IProject(org.eclipse.core.resources.IProject) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Example 7 with IPath

use of org.eclipse.core.runtime.IPath 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 8 with IPath

use of org.eclipse.core.runtime.IPath in project che by eclipse.

the class ResourceModifications method addCopyDelta.

public void addCopyDelta(IResource copy, CopyArguments arguments) {
    if (fIgnoreCount == 0) {
        IPath destination = ((IResource) arguments.getDestination()).getFullPath().append(copy.getName());
        internalAdd(new CopyDescription(copy, destination));
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath)

Example 9 with IPath

use of org.eclipse.core.runtime.IPath in project che by eclipse.

the class ResourceModifications method buildMoveDelta.

public static void buildMoveDelta(IResourceChangeDescriptionFactory builder, IResource resource, MoveArguments args) {
    IPath destination = ((IResource) args.getDestination()).getFullPath().append(resource.getName());
    new MoveDescription(resource, destination).buildDelta(builder);
}
Also used : IPath(org.eclipse.core.runtime.IPath)

Example 10 with IPath

use of org.eclipse.core.runtime.IPath in project che by eclipse.

the class ImportOperation method collectExistingReadonlyFiles.

/**
     * Prompts if existing resources should be overwritten. Recursively collects
     * existing read-only files to overwrite and resources that should not be
     * overwritten.
     *
     * @param sourceStart destination path to check for existing files
     * @param sources file system objects that may exist in the destination
     * @param noOverwrite files that were selected to be skipped (don't overwrite).
     * 	object type IPath
     * @param overwriteReadonly the collected existing read-only files to overwrite.
     * 	object type IPath
     * @param policy on of the POLICY constants defined in the
     * class.
     */
void collectExistingReadonlyFiles(IPath sourceStart, List sources, ArrayList noOverwrite, ArrayList overwriteReadonly, int policy) {
    IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
    Iterator sourceIter = sources.iterator();
    IPath sourceRootPath = null;
    if (this.source != null) {
        sourceRootPath = new Path(provider.getFullPath(this.source));
    }
    while (sourceIter.hasNext()) {
        Object nextSource = sourceIter.next();
        IPath sourcePath = new Path(provider.getFullPath(nextSource));
        IPath newDestinationPath;
        IResource newDestination;
        if (sourceRootPath == null) {
            newDestinationPath = sourceStart.append(provider.getLabel(nextSource));
        } else {
            int prefixLength = sourcePath.matchingFirstSegments(sourceRootPath);
            IPath relativeSourcePath = sourcePath.removeFirstSegments(prefixLength);
            newDestinationPath = this.destinationPath.append(relativeSourcePath);
        }
        newDestination = workspaceRoot.findMember(newDestinationPath);
        if (newDestination == null) {
            continue;
        }
        IFolder folder = getFolder(newDestination);
        if (folder != null) {
            if (policy != POLICY_FORCE_OVERWRITE) {
                if (this.overwriteState == OVERWRITE_NONE || !queryOverwrite(newDestinationPath)) {
                    noOverwrite.add(folder);
                    continue;
                }
            }
            if (provider.isFolder(nextSource)) {
                collectExistingReadonlyFiles(newDestinationPath, provider.getChildren(nextSource), noOverwrite, overwriteReadonly, POLICY_FORCE_OVERWRITE);
            }
        } else {
            IFile file = getFile(newDestination);
            if (file != null) {
                if (!queryOverwriteFile(file, policy)) {
                    noOverwrite.add(file.getFullPath());
                } else if (file.isReadOnly()) {
                    overwriteReadonly.add(file);
                }
            }
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IPath(org.eclipse.core.runtime.IPath) Iterator(java.util.Iterator) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

IPath (org.eclipse.core.runtime.IPath)500 Path (org.eclipse.core.runtime.Path)128 File (java.io.File)106 IFile (org.eclipse.core.resources.IFile)89 IResource (org.eclipse.core.resources.IResource)80 CoreException (org.eclipse.core.runtime.CoreException)74 ArrayList (java.util.ArrayList)72 IFolder (org.eclipse.core.resources.IFolder)63 IProject (org.eclipse.core.resources.IProject)60 IOException (java.io.IOException)57 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)51 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)40 IStatus (org.eclipse.core.runtime.IStatus)33 IJavaProject (org.eclipse.jdt.core.IJavaProject)33 URL (java.net.URL)26 InputStream (java.io.InputStream)23 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)23 Status (org.eclipse.core.runtime.Status)23 HashSet (java.util.HashSet)22 Test (org.junit.Test)22