Example usage for org.eclipse.jdt.core IPackageFragmentRoot DEFAULT_PACKAGEROOT_PATH

List of usage examples for org.eclipse.jdt.core IPackageFragmentRoot DEFAULT_PACKAGEROOT_PATH

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IPackageFragmentRoot DEFAULT_PACKAGEROOT_PATH.

Prototype

String DEFAULT_PACKAGEROOT_PATH

To view the source code for org.eclipse.jdt.core IPackageFragmentRoot DEFAULT_PACKAGEROOT_PATH.

Click Source Link

Document

Empty root path

Usage

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

License:Open Source License

private char[] getSourceForRootPath(String currentRootPath, String name) {
    String newFullName;// www .  j  a  v a  2s  . c o  m
    if (!currentRootPath.equals(IPackageFragmentRoot.DEFAULT_PACKAGEROOT_PATH)) {
        if (currentRootPath.endsWith("/")) { //$NON-NLS-1$
            newFullName = currentRootPath + name;
        } else {
            newFullName = currentRootPath + '/' + name;
        }
    } else {
        newFullName = name;
    }
    return this.findSource(newFullName);
}

From source file:com.mountainminds.eclemma.internal.core.instr.SourceLocation.java

License:Open Source License

public static ISourceLocation findLocation(IPackageFragmentRoot root) throws JavaModelException {
    if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
        IPath path = EclEmmaCorePlugin.getAbsolutePath(root.getPath());
        return new SourceLocation(path, new Path(IPackageFragmentRoot.DEFAULT_PACKAGEROOT_PATH));
    } else {/*  www . j  av a2  s . co  m*/
        IPath path = root.getSourceAttachmentPath();
        if (path != null) {
            path = EclEmmaCorePlugin.getAbsolutePath(path);
            return new SourceLocation(path, root.getSourceAttachmentRootPath());
        } else {
            return null;
        }
    }
}

From source file:org.eclipse.ajdt.internal.ui.wizards.exports.AJJarFileExportOperation.java

License:Open Source License

/**
 * Exports the passed resource to the JAR file
 *
 * @param element the resource or JavaElement to export
 *//*from w w w  .  j a v  a 2s . com*/
protected void exportElement(Object element, IProgressMonitor progressMonitor) throws InterruptedException {
    // AspectJ Change Begin
    if (!AspectJPlugin.USING_CU_PROVIDER) {
        // Don't export AJCompilationUnits because they are duplicates of files that we also export.
        if (element instanceof AJCompilationUnit) {
            return;
        }
    }
    // AspectJ Change End
    int leadSegmentsToRemove = 1;
    IPackageFragmentRoot pkgRoot = null;
    boolean isInJavaProject = false;
    IResource resource = null;
    IJavaProject jProject = null;
    if (element instanceof IJavaElement) {
        isInJavaProject = true;
        IJavaElement je = (IJavaElement) element;
        int type = je.getElementType();
        if (type != IJavaElement.CLASS_FILE && type != IJavaElement.COMPILATION_UNIT) {
            exportJavaElement(progressMonitor, je);
            return;
        }
        try {
            resource = je.getUnderlyingResource();
        } catch (JavaModelException ex) {
            addWarning(Messages.format(JarPackagerMessages.JarFileExportOperation_resourceNotFound,
                    je.getElementName()), ex);
            return;
        }
        jProject = je.getJavaProject();
        pkgRoot = JavaModelUtil.getPackageFragmentRoot(je);
    } else
        resource = (IResource) element;

    if (!resource.isAccessible()) {
        addWarning(Messages.format(JarPackagerMessages.JarFileExportOperation_resourceNotFound,
                resource.getFullPath()), null);
        return;
    }

    if (resource.getType() == IResource.FILE) {
        if (!isInJavaProject) {
            // check if it's a Java resource
            try {
                isInJavaProject = resource.getProject().hasNature(JavaCore.NATURE_ID);
            } catch (CoreException ex) {
                addWarning(
                        Messages.format(JarPackagerMessages.JarFileExportOperation_projectNatureNotDeterminable,
                                resource.getFullPath()),
                        ex);
                return;
            }
            if (isInJavaProject) {
                jProject = JavaCore.create(resource.getProject());
                try {
                    IPackageFragment pkgFragment = jProject
                            .findPackageFragment(resource.getFullPath().removeLastSegments(1));
                    if (pkgFragment != null)
                        pkgRoot = JavaModelUtil.getPackageFragmentRoot(pkgFragment);
                    else
                        pkgRoot = findPackageFragmentRoot(jProject,
                                resource.getFullPath().removeLastSegments(1));
                } catch (JavaModelException ex) {
                    addWarning(Messages.format(
                            JarPackagerMessages.JarFileExportOperation_javaPackageNotDeterminable,
                            resource.getFullPath()), ex);
                    return;
                }
            }
        }

        if (pkgRoot != null && jProject != null) {
            leadSegmentsToRemove = pkgRoot.getPath().segmentCount();
            boolean isOnBuildPath;
            isOnBuildPath = jProject.isOnClasspath(resource);
            if (!isOnBuildPath || (mustUseSourceFolderHierarchy()
                    && !pkgRoot.getElementName().equals(IPackageFragmentRoot.DEFAULT_PACKAGEROOT_PATH)))
                leadSegmentsToRemove--;
        }

        IPath destinationPath = resource.getFullPath().removeFirstSegments(leadSegmentsToRemove);

        boolean isInOutputFolder = false;
        if (isInJavaProject && jProject != null) {
            try {
                isInOutputFolder = jProject.getOutputLocation().isPrefixOf(resource.getFullPath());
            } catch (JavaModelException ex) {
                isInOutputFolder = false;
            }
        }

        exportClassFiles(progressMonitor, pkgRoot, resource, jProject, destinationPath);
        exportResource(progressMonitor, pkgRoot, isInJavaProject, resource, destinationPath, isInOutputFolder);

        progressMonitor.worked(1);
        ModalContext.checkCanceled(progressMonitor);

    } else
        exportContainer(progressMonitor, (IContainer) resource);
}

From source file:org.eclipse.che.jdt.internal.core.JavaProject.java

License:Open Source License

@Override
public IJavaElement getHandleFromMemento(String token, MementoTokenizer memento, WorkingCopyOwner owner) {
    switch (token.charAt(0)) {
    case JEM_PACKAGEFRAGMENTROOT:
        String rootPath = IPackageFragmentRoot.DEFAULT_PACKAGEROOT_PATH;
        token = null;//from   w w  w. j  av  a 2  s  .co  m
        while (memento.hasMoreTokens()) {
            token = memento.nextToken();
            // https://bugs.eclipse.org/bugs/show_bug.cgi?id=331821
            if (token == MementoTokenizer.PACKAGEFRAGMENT || token == MementoTokenizer.COUNT) {
                break;
            }
            rootPath += token;
        }
        JavaElement root = (JavaElement) getPackageFragmentRoot(new File(rootPath));
        if (token != null && token.charAt(0) == JEM_PACKAGEFRAGMENT) {
            return root.getHandleFromMemento(token, memento, owner);
        } else {
            return root.getHandleFromMemento(memento, owner);
        }
    }
    return null;
}

From source file:org.eclipse.jdt.internal.core.JavaProject.java

License:Open Source License

public IJavaElement getHandleFromMemento(String token, MementoTokenizer memento, WorkingCopyOwner owner) {
    switch (token.charAt(0)) {
    case JEM_PACKAGEFRAGMENTROOT:
        String rootPath = IPackageFragmentRoot.DEFAULT_PACKAGEROOT_PATH;
        token = null;//from   w w w  .  j av a  2  s.c o  m
        while (memento.hasMoreTokens()) {
            token = memento.nextToken();
            // https://bugs.eclipse.org/bugs/show_bug.cgi?id=331821
            if (token == MementoTokenizer.PACKAGEFRAGMENT || token == MementoTokenizer.COUNT) {
                break;
            }
            rootPath += token;
        }
        JavaElement root = (JavaElement) getPackageFragmentRoot(new Path(rootPath));
        if (token != null && token.charAt(0) == JEM_PACKAGEFRAGMENT) {
            return root.getHandleFromMemento(token, memento, owner);
        } else {
            return root.getHandleFromMemento(memento, owner);
        }
    }
    return null;
}

From source file:org.eclipse.jst.jsp.core.internal.java.JSPTranslation.java

License:Open Source License

/**
 * Originally from ReconcileStepForJava.  Creates an ICompilationUnit from the contents of the JSP document.
 * //  w ww.j  a v  a  2  s.  com
 * @return an ICompilationUnit from the contents of the JSP document
 */
private ICompilationUnit createCompilationUnit() throws JavaModelException {

    IJavaProject je = getJavaProject();

    if (je == null || !je.exists())
        return null;

    final String name = getClassname() + ".java";
    IPackageFragmentRoot packageFragmentRoot = null;
    IPackageFragmentRoot[] packageFragmentRoots = je.getPackageFragmentRoots();
    for (int i = 0; i < packageFragmentRoots.length; i++) {
        if (!packageFragmentRoots[i].isArchive() && !packageFragmentRoots[i].isExternal()) {
            packageFragmentRoot = packageFragmentRoots[i];
            break;
        }
    }
    if (packageFragmentRoot == null) {
        if (DEBUG) {
            System.out.println(
                    "** Abort create working copy: cannot create working copy: JSP is not in a Java project with source package fragment root"); //$NON-NLS-1$
        }
        return null;
    }
    final IPackageFragment fragment = packageFragmentRoot
            .getPackageFragment(IPackageFragmentRoot.DEFAULT_PACKAGEROOT_PATH);
    ICompilationUnit cu = fragment.getCompilationUnit(name).getWorkingCopy(getWorkingCopyOwner(),
            getProgressMonitor());
    setContents(cu);

    if (DEBUG) {
        System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); //$NON-NLS-1$
        System.out.println("(+) JSPTranslation [" + this + "] finished creating CompilationUnit: " + cu); //$NON-NLS-1$ //$NON-NLS-2$
        System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); //$NON-NLS-1$
    }

    return cu;
}

From source file:org.grails.ide.eclipse.editor.gsp.translation.GSPTranslation.java

License:Open Source License

/**
 * Originally from ReconcileStepForJava.  Creates an ICompilationUnit from the contents of the JSP document.
 * //from ww  w.j av a 2  s  .  co  m
 * @return an ICompilationUnit from the contents of the JSP document
 */
private ICompilationUnit createCompilationUnit() throws JavaModelException {

    IPackageFragment packageFragment = null;
    IJavaElement je = getJavaProject();

    if (je == null || !je.exists())
        return null;

    switch (je.getElementType()) {
    case IJavaElement.PACKAGE_FRAGMENT:
        je = je.getParent();
        // fall through

    case IJavaElement.PACKAGE_FRAGMENT_ROOT:
        IPackageFragmentRoot packageFragmentRoot = (IPackageFragmentRoot) je;
        packageFragment = packageFragmentRoot.getPackageFragment(IPackageFragmentRoot.DEFAULT_PACKAGEROOT_PATH);
        break;

    case IJavaElement.JAVA_PROJECT:
        IJavaProject jProject = (IJavaProject) je;

        if (!jProject.exists()) {
            if (DEBUG) {
                System.out.println(
                        "** Abort create working copy: cannot create working copy: JSP is not in a Java project"); //$NON-NLS-1$
            }
            return null;
        }

        packageFragmentRoot = null;
        IPackageFragmentRoot[] packageFragmentRoots = jProject.getPackageFragmentRoots();
        int i = 0;
        while (i < packageFragmentRoots.length) {
            if (!packageFragmentRoots[i].isArchive() && !packageFragmentRoots[i].isExternal()) {
                packageFragmentRoot = packageFragmentRoots[i];
                break;
            }
            i++;
        }
        if (packageFragmentRoot == null) {
            if (DEBUG) {
                System.out.println(
                        "** Abort create working copy: cannot create working copy: JSP is not in a Java project with source package fragment root"); //$NON-NLS-1$
            }
            return null;
        }
        packageFragment = packageFragmentRoot.getPackageFragment(IPackageFragmentRoot.DEFAULT_PACKAGEROOT_PATH);
        break;

    default:
        return null;
    }

    // GRAILS CHANGE
    // create compilation unit with .groovy instead of .java file extension
    ICompilationUnit cu = packageFragment.getCompilationUnit(getClassname() + ".groovy") //$NON-NLS-1$
            .getWorkingCopy(getWorkingCopyOwner(), getProgressMonitor());
    //        ICompilationUnit cu = packageFragment.getCompilationUnit(getClassname() + ".java").getWorkingCopy(getWorkingCopyOwner(), getProgressMonitor()); //$NON-NLS-1$
    setContents(cu);

    // GRAILS CHANGE
    // need extra call to makeConsistent
    // https://issuetracker.springsource.com/browse/STS-3091#comment-79054
    cu.makeConsistent(getProgressMonitor());

    if (DEBUG) {
        System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); //$NON-NLS-1$
        System.out.println("(+) JSPTranslation [" + this + "] finished creating CompilationUnit: " + cu); //$NON-NLS-1$ //$NON-NLS-2$
        System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); //$NON-NLS-1$
    }

    return cu;
}