Example usage for org.eclipse.jdt.internal.core PackageFragmentRoot getPath

List of usage examples for org.eclipse.jdt.internal.core PackageFragmentRoot getPath

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.core PackageFragmentRoot getPath.

Prototype

@Override
public IPath getPath() 

Source Link

Usage

From source file:com.codenvy.ide.ext.java.server.internal.core.ClassFile.java

License:Open Source License

public IPath getPath() {
    PackageFragmentRoot root = getPackageFragmentRoot();
    if (root.isArchive()) {
        return root.getPath();
    } else {/*ww  w .jav  a 2  s.  c  o  m*/
        return getParent().getPath().append(getElementName());
    }
}

From source file:com.codenvy.ide.ext.java.server.internal.core.CompilationUnit.java

License:Open Source License

/**
 * @see org.eclipse.jdt.core.IJavaElement#getPath()
 *///from ww  w  . j av a2 s.  c  o  m
public IPath getPath() {
    PackageFragmentRoot root = getPackageFragmentRoot();
    if (root == null)
        return new Path(getElementName()); // working copy not in workspace
    if (root.isArchive()) {
        return root.getPath();
    } else {
        return getParent().getPath().append(getElementName());
    }
}

From source file:com.codenvy.ide.ext.java.server.internal.core.PackageFragment.java

License:Open Source License

/**
 * @see org.eclipse.jdt.core.IJavaElement#getPath()
 *//*  w ww.  ja v a2  s .  c  o  m*/
public IPath getPath() {
    PackageFragmentRoot root = getPackageFragmentRoot();
    if (root.isArchive()) {
        return root.getPath();
    } else {
        IPath path = root.getPath();
        for (int i = 0, length = this.names.length; i < length; i++) {
            String name = this.names[i];
            path = path.append(name);
        }
        return path;
    }
}

From source file:com.codenvy.ide.ext.java.server.internal.core.search.JavaSearchScope.java

License:Open Source License

/**
 * Add an element to the java search scope.
 *
 * @param element// w  w w.j  av  a  2 s . co  m
 *         The element we want to add to current java search scope
 * @throws org.eclipse.jdt.core.JavaModelException
 *         May happen if some Java Model info are not available
 */
public void add(IJavaElement element) throws JavaModelException {
    IPath containerPath = null;
    String containerPathToString = null;
    PackageFragmentRoot root = null;
    int includeMask = SOURCES | APPLICATION_LIBRARIES | SYSTEM_LIBRARIES;
    switch (element.getElementType()) {
    case IJavaElement.JAVA_MODEL:
        // a workspace sope should be used
        break;
    case IJavaElement.JAVA_PROJECT:
        add((JavaProject) element, null, includeMask, new HashSet(2), new HashSet(2), null);
        break;
    case IJavaElement.PACKAGE_FRAGMENT_ROOT:
        root = (PackageFragmentRoot) element;
        IPath rootPath = root.internalPath();
        containerPath = root.getKind() == IPackageFragmentRoot.K_SOURCE ? root.getParent().getPath() : rootPath;
        containerPathToString = containerPath.getDevice() == null ? containerPath.toString()
                : containerPath.toOSString();
        IResource rootResource = root.resource();
        String projectPath = root.getJavaProject().getPath().toString();
        if (rootResource != null && rootResource.isAccessible()) {
            String relativePath = Util.relativePath(rootResource.getFullPath(), containerPath.segmentCount());
            add(projectPath, relativePath, containerPathToString, false/*not a package*/, null);
        } else {
            add(projectPath, "", containerPathToString, false/*not a package*/, null); //$NON-NLS-1$
        }
        break;
    case IJavaElement.PACKAGE_FRAGMENT:
        root = (PackageFragmentRoot) element.getParent();
        projectPath = root.getJavaProject().getPath().toString();
        if (root.isArchive()) {
            String relativePath = Util.concatWith(((PackageFragment) element).names, '/');
            containerPath = root.getPath();
            containerPathToString = containerPath.getDevice() == null ? containerPath.toString()
                    : containerPath.toOSString();
            add(projectPath, relativePath, containerPathToString, true/*package*/, null);
        } else {
            IResource resource = ((JavaElement) element).resource();
            if (resource != null) {
                if (resource.isAccessible()) {
                    containerPath = root.getKind() == IPackageFragmentRoot.K_SOURCE ? root.getParent().getPath()
                            : root.internalPath();
                } else {
                    // for working copies, get resource container full path
                    containerPath = resource.getParent().getFullPath();
                }
                containerPathToString = containerPath.getDevice() == null ? containerPath.toString()
                        : containerPath.toOSString();
                String relativePath = Util.relativePath(resource.getFullPath(), containerPath.segmentCount());
                add(projectPath, relativePath, containerPathToString, true/*package*/, null);
            }
        }
        break;
    default:
        // remember sub-cu (or sub-class file) java elements
        if (element instanceof IMember) {
            if (this.elements == null) {
                this.elements = new ArrayList();
            }
            this.elements.add(element);
        }
        root = (PackageFragmentRoot) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
        projectPath = root.getJavaProject().getPath().toString();
        String relativePath;
        if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
            containerPath = root.getParent().getPath();
            relativePath = Util.relativePath(getPath(element, false/*full path*/), 1/*remove project segment*/);
        } else {
            containerPath = root.internalPath();
            relativePath = getPath(element, true/*relative path*/).toString();
        }
        containerPathToString = containerPath.getDevice() == null ? containerPath.toString()
                : containerPath.toOSString();
        add(projectPath, relativePath, containerPathToString, false/*not a package*/, null);
    }

    if (root != null)
        addEnclosingProjectOrJar(
                root.getKind() == IPackageFragmentRoot.K_SOURCE ? root.getParent().getPath() : root.getPath());
}

From source file:jd.ide.eclipse.editors.JDClassFileEditor.java

License:Open Source License

@SuppressWarnings("rawtypes")
protected void setupSourceMapper(IClassFile classFile) {
    try {/*from  w w w.  j  ava  2 s.c  om*/
        // Search package fragment root and classPath
        IJavaElement packageFragment = classFile.getParent();
        IJavaElement packageFragmentRoot = packageFragment.getParent();

        if (packageFragmentRoot instanceof PackageFragmentRoot) {
            // Setup a new source mapper.
            PackageFragmentRoot root = (PackageFragmentRoot) packageFragmentRoot;

            // Location of the archive file containing classes.
            IPath basePath = root.getPath();
            File baseFile = basePath.makeAbsolute().toFile();

            if (!baseFile.exists()) {
                IResource resource = root.getCorrespondingResource();
                basePath = resource.getLocation();
                baseFile = basePath.makeAbsolute().toFile();
            }

            // Class path
            String classPath = classFile.getElementName();
            String packageName = packageFragment.getElementName();
            if ((packageName != null) && (packageName.length() > 0))
                classPath = packageName.replace('.', '/') + '/' + classPath;

            // Location of the archive file containing source.
            IPath sourcePath = root.getSourceAttachmentPath();
            if (sourcePath == null)
                sourcePath = basePath;

            // Location of the package fragment root within the zip 
            // (empty specifies the default root).
            IPath sourceAttachmentRootPath = root.getSourceAttachmentRootPath();
            String sourceRootPath;

            if (sourceAttachmentRootPath == null) {
                sourceRootPath = null;
            } else {
                sourceRootPath = sourceAttachmentRootPath.toString();
                if ((sourceRootPath != null) && (sourceRootPath.length() == 0))
                    sourceRootPath = null;
            }

            // Options
            Map options = root.getJavaProject().getOptions(true);

            root.setSourceMapper(new JDSourceMapper(baseFile, sourcePath, sourceRootPath, options));
        }
    } catch (CoreException e) {
        JavaDecompilerPlugin.getDefault().getLog()
                .log(new Status(Status.ERROR, JavaDecompilerPlugin.PLUGIN_ID, 0, e.getMessage(), e));
    }
}