Example usage for org.eclipse.jdt.core IClasspathEntry CPE_SOURCE

List of usage examples for org.eclipse.jdt.core IClasspathEntry CPE_SOURCE

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IClasspathEntry CPE_SOURCE.

Prototype

int CPE_SOURCE

To view the source code for org.eclipse.jdt.core IClasspathEntry CPE_SOURCE.

Click Source Link

Document

Entry kind constant describing a classpath entry identifying a folder containing package fragments with source code to be compiled.

Usage

From source file:org.eclipse.xtend.ide.macro.JdtBasedProcessorProvider.java

License:Open Source License

protected void collectClasspathURLs(final IJavaProject projectToUse, final LinkedHashSet<URL> result,
        final boolean includeOutputFolder, final Set<IJavaProject> visited) throws JavaModelException {
    try {/*from w  ww  . ja v  a 2s  .c om*/
        if (((!projectToUse.getProject().isAccessible()) || (!visited.add(projectToUse)))) {
            return;
        }
        if (includeOutputFolder) {
            IPath path = projectToUse.getOutputLocation().addTrailingSeparator();
            String _string = URI.createPlatformResourceURI(path.toString(), true).toString();
            URL url = new URL(_string);
            result.add(url);
        }
        final IClasspathEntry[] resolvedClasspath = projectToUse.getResolvedClasspath(true);
        for (final IClasspathEntry entry : resolvedClasspath) {
            {
                URL url_1 = null;
                int _entryKind = entry.getEntryKind();
                switch (_entryKind) {
                case IClasspathEntry.CPE_SOURCE:
                    if (includeOutputFolder) {
                        final IPath path_1 = entry.getOutputLocation();
                        if ((path_1 != null)) {
                            String _string_1 = URI
                                    .createPlatformResourceURI(path_1.addTrailingSeparator().toString(), true)
                                    .toString();
                            URL _uRL = new URL(_string_1);
                            url_1 = _uRL;
                        }
                    }
                    break;
                case IClasspathEntry.CPE_PROJECT:
                    IPath path_2 = entry.getPath();
                    final IResource project = this.getWorkspaceRoot(projectToUse).findMember(path_2);
                    final IJavaProject referencedProject = JavaCore.create(project.getProject());
                    this.collectClasspathURLs(referencedProject, result, true, visited);
                    break;
                case IClasspathEntry.CPE_LIBRARY:
                    IPath path_3 = entry.getPath();
                    final IResource library = this.getWorkspaceRoot(projectToUse).findMember(path_3);
                    URL _xifexpression = null;
                    if ((library != null)) {
                        URL _xblockexpression = null;
                        {
                            final java.net.URI locationUri = library.getLocationURI();
                            URL _xifexpression_1 = null;
                            String _scheme = null;
                            if (locationUri != null) {
                                _scheme = locationUri.getScheme();
                            }
                            boolean _equals = Objects.equal(EFS.SCHEME_FILE, _scheme);
                            if (_equals) {
                                java.net.URI _rawLocationURI = library.getRawLocationURI();
                                URL _uRL_1 = null;
                                if (_rawLocationURI != null) {
                                    _uRL_1 = _rawLocationURI.toURL();
                                }
                                _xifexpression_1 = _uRL_1;
                            } else {
                                _xifexpression_1 = null;
                            }
                            _xblockexpression = _xifexpression_1;
                        }
                        _xifexpression = _xblockexpression;
                    } else {
                        _xifexpression = path_3.toFile().toURI().toURL();
                    }
                    url_1 = _xifexpression;
                    break;
                default: {
                    IPath path_4 = entry.getPath();
                    url_1 = path_4.toFile().toURI().toURL();
                }
                    break;
                }
                if ((url_1 != null)) {
                    result.add(url_1);
                }
            }
        }
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}

From source file:org.eclipse.xtend.ide.validator.XtendUIValidator.java

License:Open Source License

protected boolean isInSourceFolder(IJavaProject javaProject, IFile resource) {
    IPath path = resource.getFullPath();
    IClasspathEntry[] classpath;//from  w  ww . j a  va 2 s.c o  m
    try {
        classpath = javaProject.getResolvedClasspath(true);
    } catch (JavaModelException e) {
        return false; // not a Java project
    }
    for (int i = 0; i < classpath.length; i++) {
        IClasspathEntry entry = classpath[i];
        if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            IPath entryPath = entry.getPath();
            if (entryPath.isPrefixOf(path)) {
                return true;
            }
        }
    }
    return false;
}

From source file:org.eclipse.xtend.ide.XtendResourceUiServiceProvider.java

License:Open Source License

public boolean isInSourceFolder(IJavaProject javaProject, IFile resource) {
    IPath path = resource.getFullPath();
    IClasspathEntry[] classpath;/*from www. j  a v  a  2s.  c  o m*/
    try {
        classpath = javaProject.getResolvedClasspath(true);
    } catch (JavaModelException e) {
        return false; // not a Java project
    }
    for (int i = 0; i < classpath.length; i++) {
        IClasspathEntry entry = classpath[i];
        if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            IPath entryPath = entry.getPath();
            if (entryPath.isPrefixOf(path) && !isExcluded(entry, path)) {
                return true;
            }
        }
    }
    return false;
}

From source file:org.eclipse.xtext.builder.JDTAwareSourceFolderProvider.java

License:Open Source License

@Override
public List<? extends IContainer> getSourceFolders(IProject project) {
    List<IContainer> sourceFolders = Lists.newArrayList();
    IJavaProject javaProject = JavaCore.create(project);
    IClasspathEntry[] classpath;//from  w  w w  . j a  v a 2s  . c  o m
    if (!javaProject.exists()) {
        return Collections.emptyList();
    }
    try {
        classpath = javaProject.getRawClasspath();
    } catch (JavaModelException e) {
        log.error("Error determining source folders for project " + project.getName(), e);
        return Collections.emptyList();
    }
    for (IClasspathEntry entry : classpath) {
        if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            IPath path = entry.getPath();
            // see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=436371
            if (path.segmentCount() == 1) {
                sourceFolders.add(project);
            } else {
                sourceFolders.add(project.getWorkspace().getRoot().getFolder(entry.getPath()));
            }
        }
    }
    return sourceFolders;
}

From source file:org.eclipse.xtext.common.types.access.jdt.JdtTypeProvider.java

License:Open Source License

/**
 * @see JavaProject#computePackageFragmentRoots(IClasspathEntry, ObjectVector, HashSet, IClasspathEntry, boolean, java.util.Map)
 *//*w w w  . j  av a2  s . c o  m*/
private void collectSourcePackageFragmentRoots(JavaProject javaProject, HashSet<String> rootIDs,
        IClasspathEntry referringEntry, ObjectVector result) throws JavaModelException {
    if (referringEntry == null) {
        rootIDs.add(javaProject.rootID());
    } else if (rootIDs.contains(javaProject.rootID())) {
        return;
    }
    IWorkspaceRoot workspaceRoot = javaProject.getProject().getWorkspace().getRoot();
    for (IClasspathEntry entry : javaProject.getResolvedClasspath()) {
        switch (entry.getEntryKind()) {
        case IClasspathEntry.CPE_PROJECT:
            if (referringEntry != null && !entry.isExported())
                return;

            IPath pathToProject = entry.getPath();
            IResource referencedProject = workspaceRoot.findMember(pathToProject);
            if (referencedProject != null && referencedProject.getType() == IResource.PROJECT) {
                IProject casted = (IProject) referencedProject;
                if (JavaProject.hasJavaNature(casted)) {
                    rootIDs.add(javaProject.rootID());
                    JavaProject referencedJavaProject = (JavaProject) JavaCore.create(casted);
                    collectSourcePackageFragmentRoots(referencedJavaProject, rootIDs, entry, result);
                }
            }
            break;
        case IClasspathEntry.CPE_SOURCE:
            javaProject.computePackageFragmentRoots(entry, result, rootIDs, referringEntry, true, null);
            break;
        }
    }
}

From source file:org.eclipse.xtext.ui.shared.JdtHelper.java

License:Open Source License

@Override
public boolean isFromOutputPath(IResource resource) {
    IProject project = resource.getProject();
    IJavaProject javaProject = JavaCore.create(project);
    if (javaProject != null && javaProject.exists()) {
        try {/* w ww. j  av a 2 s.  c om*/
            IPath defaultOutputLocation = javaProject.getOutputLocation();
            IPath resourcePath = resource.getFullPath();
            if (defaultOutputLocation != null && !defaultOutputLocation.isEmpty()
                    && defaultOutputLocation.isPrefixOf(resourcePath)) {
                return true;
            }
            IClasspathEntry[] classpathEntries = javaProject.getRawClasspath();
            for (IClasspathEntry classpathEntry : classpathEntries) {
                if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                    IPath specializedOutputLocation = classpathEntry.getOutputLocation();
                    if (specializedOutputLocation != null) {
                        if (!specializedOutputLocation.equals(classpathEntry.getPath())
                                && specializedOutputLocation.isPrefixOf(resourcePath)) {
                            return true;
                        }
                    }
                }
            }
        } catch (CoreException e) {
            if (log.isDebugEnabled())
                log.debug("Error in isJavaTargetFolder():" + e.getMessage(), e);
        }
    }
    return false;
}

From source file:org.eclipse.xtext.ui.workspace.JdtProjectConfig.java

License:Open Source License

@Override
public Set<? extends ISourceFolder> getSourceFolders() {
    try {//from w w w.j  a  v a2 s . c  om
        final IJavaProject javaProject = JavaCore.create(this.getProject());
        boolean _exists = javaProject.exists();
        boolean _not = (!_exists);
        if (_not) {
            return CollectionLiterals.<ISourceFolder>emptySet();
        }
        final IClasspathEntry[] classpath = javaProject.getRawClasspath();
        final Function1<IClasspathEntry, Boolean> _function = (IClasspathEntry it) -> {
            int _entryKind = it.getEntryKind();
            return Boolean.valueOf((_entryKind == IClasspathEntry.CPE_SOURCE));
        };
        final Iterable<IClasspathEntry> sourceEntries = IterableExtensions.<IClasspathEntry>filter(
                ((Iterable<IClasspathEntry>) Conversions.doWrapArray(classpath)), _function);
        final Function1<IClasspathEntry, String> _function_1 = (IClasspathEntry it) -> {
            return it.getPath().removeFirstSegments(1).toString();
        };
        final Iterable<String> sourceFolders = IterableExtensions.<IClasspathEntry, String>map(sourceEntries,
                _function_1);
        final Function1<String, EclipseSourceFolder> _function_2 = (String it) -> {
            IProject _project = this.getProject();
            return new EclipseSourceFolder(_project, it);
        };
        return IterableExtensions.<EclipseSourceFolder>toSet(
                IterableExtensions.<String, EclipseSourceFolder>map(sourceFolders, _function_2));
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}

From source file:org.eclipse.xtext.xbase.ui.editor.XbaseEditorInputRedirector.java

License:Open Source License

/**
 * @param an input//from   w w w .j a  v  a2  s  .co m
 * 
 * @return the original source for an editor input that points to an Xtext resource copied to the output folder, the given input otherwise
 */
public IEditorInput findOriginalSourceForOuputFolderCopy(final IEditorInput input) {
    try {
        final IFile resource = ResourceUtil.getFile(input);
        if ((resource != null)) {
            boolean _isValid = this.fileExtensionProvider.isValid(resource.getFullPath().getFileExtension());
            if (_isValid) {
                final IJavaProject project = JavaCore.create(resource.getProject());
                boolean _exists = project.exists();
                if (_exists) {
                    boolean _isPrefixOf = project.getOutputLocation().isPrefixOf(resource.getFullPath());
                    if (_isPrefixOf) {
                        final IPath relative = resource.getFullPath()
                                .removeFirstSegments(project.getOutputLocation().segmentCount());
                        final Function1<IPackageFragmentRoot, Boolean> _function = (
                                IPackageFragmentRoot it) -> {
                            try {
                                int _kind = it.getKind();
                                return Boolean.valueOf((_kind == IPackageFragmentRoot.K_SOURCE));
                            } catch (Throwable _e) {
                                throw Exceptions.sneakyThrow(_e);
                            }
                        };
                        Iterable<IPackageFragmentRoot> _filter = IterableExtensions
                                .<IPackageFragmentRoot>filter(((Iterable<IPackageFragmentRoot>) Conversions
                                        .doWrapArray(project.getPackageFragmentRoots())), _function);
                        for (final IPackageFragmentRoot source : _filter) {
                            {
                                final IPath fullPath = source.getCorrespondingResource()
                                        .getProjectRelativePath().append(relative);
                                final IFile newFile = resource.getProject().getFile(fullPath);
                                boolean _exists_1 = newFile.exists();
                                if (_exists_1) {
                                    return new FileEditorInput(newFile);
                                }
                            }
                        }
                    }
                    final Function1<IClasspathEntry, Boolean> _function_1 = (IClasspathEntry it) -> {
                        int _entryKind = it.getEntryKind();
                        return Boolean.valueOf((_entryKind == IClasspathEntry.CPE_SOURCE));
                    };
                    Iterable<IClasspathEntry> _filter_1 = IterableExtensions.<IClasspathEntry>filter(
                            ((Iterable<IClasspathEntry>) Conversions.doWrapArray(project.getRawClasspath())),
                            _function_1);
                    for (final IClasspathEntry sourceFolder : _filter_1) {
                        if (((sourceFolder.getOutputLocation() != null)
                                && sourceFolder.getOutputLocation().isPrefixOf(resource.getFullPath()))) {
                            final IPath relative_1 = resource.getFullPath()
                                    .removeFirstSegments(sourceFolder.getOutputLocation().segmentCount());
                            final IPackageFragmentRoot source_1 = IterableExtensions
                                    .<IPackageFragmentRoot>head(((Iterable<IPackageFragmentRoot>) Conversions
                                            .doWrapArray(project.findPackageFragmentRoots(sourceFolder))));
                            final IPath fullPath = source_1.getCorrespondingResource().getProjectRelativePath()
                                    .append(relative_1);
                            final IFile newFile = resource.getProject().getFile(fullPath);
                            boolean _exists_1 = newFile.exists();
                            if (_exists_1) {
                                return new FileEditorInput(newFile);
                            }
                        }
                    }
                }
            }
        }
        return input;
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}

From source file:org.eclipse.xtext.xtext.ecoreInference.ProjectAwareXtendXtext2EcorePostProcessor.java

License:Open Source License

protected ClassLoader createClassLoader(IJavaProject javaProject) throws CoreException {
    List<URL> urls = Lists.newArrayListWithExpectedSize(javaProject.getResolvedClasspath(true).length);
    try {/*w w  w .j a v a2  s .co  m*/
        IWorkspaceRoot workspaceRoot = getWorkspace().getRoot();
        urls.addAll(getOutputFolders(javaProject));
        for (IClasspathEntry entry : javaProject.getResolvedClasspath(true)) {
            IPath path = null;
            URL url = null;
            switch (entry.getEntryKind()) {
            case IClasspathEntry.CPE_SOURCE:
                break;
            case IClasspathEntry.CPE_PROJECT:
                IResource project = workspaceRoot.findMember(entry.getPath());
                urls.addAll(getOutputFolders(JavaCore.create(project.getProject())));
                break;
            default:
                path = entry.getPath();
                url = path.toFile().toURI().toURL();
                break;
            }
            if (url != null) {
                urls.add(url);
            }
        }
    } catch (MalformedURLException e) {
        logger.error(
                "Error creating class loader for java project '" + javaProject.getProject().getName() + "'", e);
    }
    return new URLClassLoader(urls.toArray(new URL[urls.size()]), getClass().getClassLoader());
}

From source file:org.eclipse.xtext.xtext.ecoreInference.ProjectAwareXtendXtext2EcorePostProcessor.java

License:Open Source License

private List<URL> getOutputFolders(IJavaProject javaProject) throws CoreException, MalformedURLException {
    List<URL> result = Lists.newArrayListWithExpectedSize(1);
    IPath path = javaProject.getOutputLocation().addTrailingSeparator();
    URL url = new URL(URI.createPlatformResourceURI(path.toString(), true).toString());
    result.add(url);/*w ww.j av a2s. co m*/
    for (IClasspathEntry entry : javaProject.getRawClasspath()) {
        switch (entry.getEntryKind()) {
        case IClasspathEntry.CPE_SOURCE:
            path = entry.getOutputLocation();
            if (path != null) {
                url = new URL(
                        URI.createPlatformResourceURI(path.addTrailingSeparator().toString(), true).toString());
                result.add(url);
            }
            break;
        default:
            break;
        }
    }
    return result;
}