Search in sources :

Example 81 with IPath

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

the class RenamePackageChange method createNewPath.

protected IPath createNewPath(IPackageFragment oldPackage) {
    IPath oldPackagePath = createPath(oldPackage.getElementName());
    IPath newPackagePath = createPath(getNewName(oldPackage));
    return oldPackage.getPath().removeLastSegments(oldPackagePath.segmentCount()).append(newPackagePath);
}
Also used : IPath(org.eclipse.core.runtime.IPath)

Example 82 with IPath

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

the class ClasspathChange method perform.

@Override
public Change perform(IProgressMonitor pm) throws CoreException {
    pm.beginTask(RefactoringCoreMessages.ClasspathChange_progress_message, 1);
    try {
        if (!JavaConventions.validateClasspath(fProject, fNewClasspath, fOutputLocation).matches(IStatus.ERROR)) {
            IClasspathEntry[] oldClasspath = fProject.getRawClasspath();
            IPath oldOutputLocation = fProject.getOutputLocation();
            fProject.setRawClasspath(fNewClasspath, fOutputLocation, new SubProgressMonitor(pm, 1));
            return new ClasspathChange(fProject, oldClasspath, oldOutputLocation);
        } else {
            return new NullChange();
        }
    } finally {
        pm.done();
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) NullChange(org.eclipse.ltk.core.refactoring.NullChange) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor)

Example 83 with IPath

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

the class ClasspathChange method removeEntryChange.

public static ClasspathChange removeEntryChange(IJavaProject project, IClasspathEntry entryToRemove) throws JavaModelException {
    IClasspathEntry[] rawClasspath = project.getRawClasspath();
    ArrayList<IClasspathEntry> newClasspath = new ArrayList<IClasspathEntry>();
    for (int i = 0; i < rawClasspath.length; i++) {
        IClasspathEntry curr = rawClasspath[i];
        if (curr.getEntryKind() != entryToRemove.getEntryKind() || !curr.getPath().equals(entryToRemove.getPath())) {
            newClasspath.add(curr);
        }
    }
    IClasspathEntry[] entries = newClasspath.toArray(new IClasspathEntry[newClasspath.size()]);
    IPath outputLocation = project.getOutputLocation();
    return newChange(project, entries, outputLocation);
}
Also used : IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) ArrayList(java.util.ArrayList)

Example 84 with IPath

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

the class RefactoringFileBuffers method acquire.

/**
	 * Connects to and acquires a text file buffer for the specified compilation unit.
	 * <p>
	 * All text file buffers acquired by a call to {@link RefactoringFileBuffers#acquire(ICompilationUnit)}
	 * must be released using {@link RefactoringFileBuffers#release(ICompilationUnit)}.
	 * </p>
	 *
	 * @param unit the compilation unit to acquire a text file buffer for
	 * @return the text file buffer, or <code>null</code> if no buffer could be acquired
	 * @throws CoreException if no buffer could be acquired
	 */
public static ITextFileBuffer acquire(final ICompilationUnit unit) throws CoreException {
    Assert.isNotNull(unit);
    final IResource resource = unit.getResource();
    if (resource != null && resource.getType() == IResource.FILE) {
        final IPath path = resource.getFullPath();
        FileBuffers.getTextFileBufferManager().connect(path, LocationKind.IFILE, new NullProgressMonitor());
        return FileBuffers.getTextFileBufferManager().getTextFileBuffer(path, LocationKind.IFILE);
    }
    return null;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IPath(org.eclipse.core.runtime.IPath) IResource(org.eclipse.core.resources.IResource)

Example 85 with IPath

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

the class JavaElementLabelComposer method appendVariableLabel.

private boolean appendVariableLabel(IPackageFragmentRoot root, long flags) {
    try {
        IClasspathEntry rawEntry = root.getRawClasspathEntry();
        if (rawEntry.getEntryKind() == IClasspathEntry.CPE_VARIABLE) {
            IClasspathEntry entry = JavaModelUtil.getClasspathEntry(root);
            if (entry.getReferencingEntry() != null) {
                // not the variable entry itself, but a referenced entry
                return false;
            }
            IPath path = rawEntry.getPath().makeRelative();
            if (getFlag(flags, JavaElementLabels.REFERENCED_ROOT_POST_QUALIFIED)) {
                int segements = path.segmentCount();
                if (segements > 0) {
                    fBuffer.append(path.segment(segements - 1));
                    if (segements > 1) {
                        int offset = fBuffer.length();
                        fBuffer.append(JavaElementLabels.CONCAT_STRING);
                        fBuffer.append(path.removeLastSegments(1).toOSString());
                        if (getFlag(flags, JavaElementLabels.COLORIZE)) {
                            fBuffer.setStyle(offset, fBuffer.length() - offset, QUALIFIER_STYLE);
                        }
                    }
                } else {
                    fBuffer.append(path.toString());
                }
            } else {
                fBuffer.append(path.toString());
            }
            int offset = fBuffer.length();
            fBuffer.append(JavaElementLabels.CONCAT_STRING);
            if (root.isExternal())
                fBuffer.append(root.getPath().toOSString());
            else
                fBuffer.append(root.getPath().makeRelative().toString());
            if (getFlag(flags, JavaElementLabels.COLORIZE)) {
                fBuffer.setStyle(offset, fBuffer.length() - offset, QUALIFIER_STYLE);
            }
            return true;
        }
    } catch (JavaModelException e) {
        // problems with class path, ignore (bug 202792)
        return false;
    }
    return false;
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry)

Aggregations

IPath (org.eclipse.core.runtime.IPath)800 Path (org.eclipse.core.runtime.Path)219 File (java.io.File)161 IFile (org.eclipse.core.resources.IFile)150 CoreException (org.eclipse.core.runtime.CoreException)135 IResource (org.eclipse.core.resources.IResource)112 IOException (java.io.IOException)100 ArrayList (java.util.ArrayList)92 IProject (org.eclipse.core.resources.IProject)85 IFolder (org.eclipse.core.resources.IFolder)80 Test (org.junit.Test)72 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)58 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)55 IStatus (org.eclipse.core.runtime.IStatus)48 InputStream (java.io.InputStream)44 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)42 Status (org.eclipse.core.runtime.Status)36 IJavaProject (org.eclipse.jdt.core.IJavaProject)36 URL (java.net.URL)33 IContainer (org.eclipse.core.resources.IContainer)33