Example usage for org.eclipse.jdt.core IJavaProject getPackageFragmentRoots

List of usage examples for org.eclipse.jdt.core IJavaProject getPackageFragmentRoots

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IJavaProject getPackageFragmentRoots.

Prototype

IPackageFragmentRoot[] getPackageFragmentRoots() throws JavaModelException;

Source Link

Document

Returns all of the package fragment roots contained in this project, identified on this project's resolved classpath.

Usage

From source file:org.summer.ss.ide.builder.SsBuilderParticipant.java

License:Open Source License

protected void registerCurrentSourceFolder(Delta delta, EclipseResourceFileSystemAccess2 fileSystemAccess) {
    if (fileSystemAccess instanceof SourceRelativeFileSystemAccess) {
        try {/*from  w  ww  . j  a v  a  2 s . c o  m*/
            Iterable<Pair<IStorage, IProject>> storages = mapper.getStorages(delta.getUri());
            for (Pair<IStorage, IProject> pair : storages) {
                IJavaProject javaProject = JavaCore.create(pair.getSecond());
                final IResource first = (IResource) pair.getFirst();
                IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots();
                for (IPackageFragmentRoot root : roots) {
                    if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
                        final IResource underlyingResource = root.getUnderlyingResource();
                        if (underlyingResource instanceof IFolder && underlyingResource.contains(first)) {
                            ((SourceRelativeFileSystemAccess) fileSystemAccess)
                                    .setCurrentSource((IFolder) underlyingResource);
                            return;
                        }
                    }
                }
            }
        } catch (CoreException e) {
            LOGGER.error(e.getMessage(), e);
        }
    }
}

From source file:org.summer.ss.ide.builder.SsBuilderParticipant.java

License:Open Source License

/**
 * @since 2.4//from   w ww .  j a  v  a2s .com
 */
protected List<IPath> getSourceFolderPathes(IProject project) {
    List<IPath> sourceFolder = Lists.newArrayList();
    try {
        if (project.isOpen() && JavaProject.hasJavaNature(project)) {
            IJavaProject javaProject = JavaCore.create(project);
            List<IPackageFragmentRoot> packageFragmentRoots = Arrays
                    .asList(javaProject.getPackageFragmentRoots());
            for (IPackageFragmentRoot packageFragmentRoot : packageFragmentRoots) {
                if (packageFragmentRoot.getKind() == IPackageFragmentRoot.K_SOURCE) {
                    IPath path = packageFragmentRoot.getPath();
                    sourceFolder.add(path);
                }
            }
        }
    } catch (JavaModelException e) {
        LOGGER.error(e.getMessage(), e);
    }
    return sourceFolder;
}

From source file:org.switchyard.tools.ui.JavaUtil.java

License:Open Source License

/**
 * Returns the first source folder in the project. If the project is a maven
 * project, the first source folder configured will be used.
 * /*  ww  w.  java 2 s . c o m*/
 * @param project the Java project
 * 
 * @return the source root; may be null.
 */
public static IPackageFragmentRoot getFirstJavaSourceRoot(IJavaProject project) {
    if (project == null) {
        return null;
    }
    try {
        IPackageFragmentRoot sourceRoot = null;
        IMavenProjectFacade facade = MavenPlugin.getMavenProjectRegistry().getProject(project.getProject());
        if (facade == null) {
            for (IPackageFragmentRoot frag : project.getPackageFragmentRoots()) {
                if (frag.getKind() == IPackageFragmentRoot.K_SOURCE) {
                    sourceRoot = frag;
                    break;
                }
            }
        } else {
            IPath projectPath = project.getPath();
            for (IPath sourcePath : facade.getCompileSourceLocations()) {
                IPackageFragmentRoot frag = project.findPackageFragmentRoot(projectPath.append(sourcePath));
                if (frag != null) {
                    sourceRoot = frag;
                    break;
                }
            }
        }
        return sourceRoot;
    } catch (JavaModelException e) {
        return null;
    }
}

From source file:org.switchyard.tools.ui.JavaUtil.java

License:Open Source License

/**
 * Returns the first resource folder in the project. If the project is a
 * maven project, the first resource folder configured will be used.
 * //  w w w .j av a 2 s.c  o m
 * @param project the Java project
 * 
 * @return the resource root; may be null.
 */
public static IResource getFirstResourceRoot(IJavaProject project) {
    if (project == null) {
        return null;
    }
    try {
        IResource sourceRoot = null;
        IMavenProjectFacade facade = MavenPlugin.getMavenProjectRegistry().getProject(project.getProject());
        if (facade == null) {
            for (IPackageFragmentRoot frag : project.getPackageFragmentRoots()) {
                if (frag.getKind() == IPackageFragmentRoot.K_SOURCE) {
                    sourceRoot = frag.getUnderlyingResource();
                    break;
                }
            }
        } else {
            IProject projectResource = project.getProject();
            for (IPath sourcePath : facade.getResourceLocations()) {
                sourceRoot = projectResource.findMember(sourcePath);
                if (sourceRoot != null) {
                    break;
                }
            }
        }
        return sourceRoot;
    } catch (JavaModelException e) {
        return null;
    }
}

From source file:org.teavm.eclipse.debugger.TeaVMSourceLookupParticipant.java

License:Apache License

@Override
public void sourceContainersChanged(ISourceLookupDirector director) {
    delegateContainers.clear();//from  w w  w.ja v a2  s .  c  o m
    ISourceContainer[] containers = director.getSourceContainers();
    for (int i = 0; i < containers.length; i++) {
        ISourceContainer container = containers[i];
        if (container.getType().getId().equals(ArchiveSourceContainer.TYPE_ID)) {
            IFile file = ((ArchiveSourceContainer) container).getFile();
            IProject project = file.getProject();
            IJavaProject javaProject = JavaCore.create(project);
            if (javaProject.exists()) {
                try {
                    IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots();
                    for (int j = 0; j < roots.length; j++) {
                        IPackageFragmentRoot root = roots[j];
                        if (file.equals(root.getUnderlyingResource())) {
                            delegateContainers.put(container, new PackageFragmentRootSourceContainer(root));
                        } else {
                            IPath path = root.getSourceAttachmentPath();
                            if (path != null) {
                                if (file.getFullPath().equals(path)) {
                                    delegateContainers.put(container,
                                            new PackageFragmentRootSourceContainer(root));
                                }
                            }
                        }
                    }
                } catch (JavaModelException e) {
                }
            }
        }
    }
}

From source file:org.umlgraph.doclet.EclipseJavaUtil.java

License:Open Source License

public static IType findType(IJavaProject javaProject, String qualifiedName) throws JavaModelException {
    if (qualifiedName == null || qualifiedName.length() == 0)
        return null;
    IType type = javaProject.findType(qualifiedName);
    if (type != null)
        return type;
    int dot = qualifiedName.lastIndexOf('.');
    String packageName = (dot < 0) ? "" : qualifiedName.substring(0, dot);
    String shortName = qualifiedName.substring(dot + 1);
    IPackageFragmentRoot[] rs = javaProject.getPackageFragmentRoots();
    for (int i = 0; i < rs.length; i++) {
        IPackageFragment f = rs[i].getPackageFragment(packageName);
        if (f == null || !f.exists())
            continue;
        ICompilationUnit[] us = f.getCompilationUnits();

        for (int j = 0; j < us.length; j++) {
            IType t = us[j].getType(shortName);
            if (t != null && t.exists())
                return t;
        }/*from ww w.ja v a 2 s . co  m*/
    }
    return null;
}

From source file:org.wso2.developerstudio.eclipse.utils.jdt.JavaUtils.java

License:Open Source License

public static IPackageFragmentRoot[] getReferencedLibrariesForProject(IProject project)
        throws JavaModelException {
    IJavaProject p = JavaCore.create(project);
    IPackageFragmentRoot[] packageFragmentRoots = null;
    if (p != null) {
        packageFragmentRoots = p.getPackageFragmentRoots();
    }// w w w.j av a  2s  . co m

    ArrayList<IPackageFragmentRoot> jarClassPaths = new ArrayList<IPackageFragmentRoot>();
    if (packageFragmentRoots != null) {
        for (IPackageFragmentRoot packageFragmentRoot : packageFragmentRoots) {
            if (isWebApp && packageFragmentRoot.isArchive()) {
                if (packageFragmentRoot.getRawClasspathEntry().getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                    jarClassPaths.add(packageFragmentRoot);
                }

            } else if (!isWebApp) {
                if (packageFragmentRoot.getRawClasspathEntry().getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                    jarClassPaths.add(packageFragmentRoot);
                }
            }
        }
    }
    return jarClassPaths.toArray(new IPackageFragmentRoot[] {});
}

From source file:org.wso2.developerstudio.eclipse.utils.jdt.JavaUtils.java

License:Open Source License

public static IPackageFragmentRoot[] getReferencedVariablesForProject(IProject project)
        throws JavaModelException {
    IJavaProject p = JavaCore.create(project);
    IPackageFragmentRoot[] packageFragmentRoots = p.getPackageFragmentRoots();
    ArrayList<IPackageFragmentRoot> jarClassPaths = new ArrayList<IPackageFragmentRoot>();
    for (IPackageFragmentRoot packageFragmentRoot : packageFragmentRoots) {
        if (packageFragmentRoot.getRawClasspathEntry().getEntryKind() == IClasspathEntry.CPE_VARIABLE) {
            jarClassPaths.add(packageFragmentRoot);
        }/*from  w w  w . j a v  a  2 s. c om*/
    }
    return jarClassPaths.toArray(new IPackageFragmentRoot[] {});
}

From source file:org.wso2.developerstudio.eclipse.utils.jdt.JavaUtils.java

License:Open Source License

public static IPackageFragmentRoot[] getReferencedVariableLibrariesForProject(IProject project)
        throws JavaModelException {
    IJavaProject p = JavaCore.create(project);
    IPackageFragmentRoot[] packageFragmentRoots = p.getPackageFragmentRoots();
    ArrayList<IPackageFragmentRoot> jarClassPaths = new ArrayList<IPackageFragmentRoot>();
    for (IPackageFragmentRoot packageFragmentRoot : packageFragmentRoots) {
        if (isWebApp && packageFragmentRoot.isArchive()) {
            IClasspathEntry rawClasspathEntry = packageFragmentRoot.getRawClasspathEntry();
            IClasspathEntry resolvedClasspathEntry = JavaCore.getResolvedClasspathEntry(rawClasspathEntry);
            if (rawClasspathEntry.getEntryKind() == IClasspathEntry.CPE_VARIABLE
                    && resolvedClasspathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                jarClassPaths.add(packageFragmentRoot);
            }//  www  .ja  va 2  s.com
        } else if (!isWebApp) {
            IClasspathEntry rawClasspathEntry = packageFragmentRoot.getRawClasspathEntry();
            IClasspathEntry resolvedClasspathEntry = JavaCore.getResolvedClasspathEntry(rawClasspathEntry);
            if (rawClasspathEntry.getEntryKind() == IClasspathEntry.CPE_VARIABLE
                    && resolvedClasspathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                jarClassPaths.add(packageFragmentRoot);
            }
        }
    }
    return jarClassPaths.toArray(new IPackageFragmentRoot[] {});
}

From source file:org.wso2.developerstudio.eclipse.utils.jdt.JavaUtils.java

License:Open Source License

public static IPackageFragmentRoot[] getSourceFoldersForProject(IProject project) throws JavaModelException {
    IJavaProject p = JavaCore.create(project);
    IPackageFragmentRoot[] packageFragmentRoots = p.getPackageFragmentRoots();
    ArrayList<IPackageFragmentRoot> jarClassPaths = new ArrayList<IPackageFragmentRoot>();
    for (IPackageFragmentRoot packageFragmentRoot : packageFragmentRoots) {
        if (isWebApp && packageFragmentRoot.isArchive()) {
            if (packageFragmentRoot.getRawClasspathEntry().getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                jarClassPaths.add(packageFragmentRoot);
            }/*from w  ww  . ja va2  s.  c o  m*/
        } else if (!isWebApp) {
            if (packageFragmentRoot.getRawClasspathEntry().getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                jarClassPaths.add(packageFragmentRoot);
            }
        }
    }
    return jarClassPaths.toArray(new IPackageFragmentRoot[] {});
}