Search in sources :

Example 56 with IClasspathEntry

use of org.eclipse.jdt.core.IClasspathEntry in project xtext-xtend by eclipse.

the class JavaClasspathTest method testNoJavaInClasspath.

@Test
public void testNoJavaInClasspath() throws Exception {
    LogCapture capturedLogging = LoggingTester.captureLogging(Level.ERROR, AbstractClassMirror.class, new Runnable() {

        @Override
        public void run() {
            LogCapture capturedLogging = LoggingTester.captureLogging(Level.ERROR, JdtTypeMirror.class, new Runnable() {

                @Override
                public void run() {
                    try {
                        IProject project = testHelper.getProject();
                        IJavaProject javaProject = JavaCore.create(project);
                        IFile file = project.getFile("src/Foo.xtend");
                        if (!file.exists())
                            file.create(new StringInputStream(TEST_CLAZZ), true, null);
                        IClasspathEntry jrePath = JavaProjectSetupUtil.getJreContainerClasspathEntry(javaProject);
                        assertNotNull("JRE Lib classpath entry not found.", jrePath);
                        // remove JRE Lib
                        JavaProjectSetupUtil.deleteClasspathEntry(javaProject, jrePath.getPath());
                        IResourcesSetupUtil.waitForBuild();
                        markerAssert.assertErrorMarker(file, IssueCodes.JDK_NOT_ON_CLASSPATH);
                        // add JRE back
                        JavaProjectSetupUtil.addToClasspath(javaProject, jrePath);
                        IResourcesSetupUtil.waitForBuild();
                        markerAssert.assertNoErrorMarker(file);
                    } catch (Exception e) {
                        throw new RuntimeException(e);
                    }
                }
            });
            assertFalse(capturedLogging.getLogEntries().isEmpty());
        }
    });
    assertFalse(capturedLogging.getLogEntries().isEmpty());
}
Also used : JdtTypeMirror(org.eclipse.xtext.common.types.access.jdt.JdtTypeMirror) StringInputStream(org.eclipse.xtext.util.StringInputStream) IJavaProject(org.eclipse.jdt.core.IJavaProject) IFile(org.eclipse.core.resources.IFile) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) LogCapture(org.eclipse.xtext.testing.logging.LoggingTester.LogCapture) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test)

Example 57 with IClasspathEntry

use of org.eclipse.jdt.core.IClasspathEntry in project xtext-xtend by eclipse.

the class SameClassNamesTest method testDuplicateNames_04.

@Test
public void testDuplicateNames_04() {
    try {
        final IJavaProject javaProject = JavaCore.create(this.second);
        final IClasspathEntry[] cp = javaProject.getRawClasspath();
        final List<IClasspathEntry> reversed = ListExtensions.<IClasspathEntry>reverse(((List<IClasspathEntry>) Conversions.doWrapArray(cp)));
        javaProject.setRawClasspath(((IClasspathEntry[]) Conversions.unwrapArray(reversed, IClasspathEntry.class)), null);
        IResourcesSetupUtil.reallyWaitForAutoBuild();
        this.testHelper.createFileImpl("first/src/com/acme/A.xtend", "package com.acme class A { new(String s) {} }");
        this.testHelper.createFileImpl("second/src/com/acme/A.xtend", "package com.acme class A { new(int i) {} }");
        this.testHelper.createFileImpl("second/src/com/acme/B.xtend", "package com.acme class B extends A { new() { super(1) } }");
        this.testHelper.createFileImpl("third/src/com/acme/A.xtend", "package com.acme class A {}");
        IResourcesSetupUtil.waitForBuild();
        IResourcesSetupUtil.assertNoErrorsInWorkspace();
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) List(java.util.List) Test(org.junit.Test)

Example 58 with IClasspathEntry

use of org.eclipse.jdt.core.IClasspathEntry in project xtext-xtend by eclipse.

the class XtendUIValidator method isInSourceFolder.

protected boolean isInSourceFolder(IJavaProject javaProject, IFile resource) {
    IPath path = resource.getFullPath();
    IClasspathEntry[] classpath;
    try {
        classpath = javaProject.getResolvedClasspath(true);
    } catch (JavaModelException e) {
        // not a Java project
        return false;
    }
    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;
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry)

Example 59 with IClasspathEntry

use of org.eclipse.jdt.core.IClasspathEntry in project xtext-xtend by eclipse.

the class JdtBasedProcessorProvider method collectClasspathURLs.

protected void collectClasspathURLs(final IJavaProject projectToUse, final LinkedHashSet<URL> result, final boolean includeOutputFolder, final Set<IJavaProject> visited) throws JavaModelException {
    try {
        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);
    }
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) URL(java.net.URL) IResource(org.eclipse.core.resources.IResource)

Example 60 with IClasspathEntry

use of org.eclipse.jdt.core.IClasspathEntry in project xtext-xtend by eclipse.

the class XtendLibClasspathAdder method addToClasspath.

protected boolean addToClasspath(IJavaProject javaProject, IProgressMonitor monitor) throws JavaModelException {
    IClasspathEntry xtendContainerEntry = JavaCore.newContainerEntry(XtendContainerInitializer.XTEND_LIBRARY_PATH);
    IClasspathEntry[] rawClasspath = javaProject.getRawClasspath();
    IClasspathEntry[] newRawClasspath = new IClasspathEntry[rawClasspath.length + 1];
    for (int i = 0; i < rawClasspath.length; ++i) {
        IClasspathEntry entry = rawClasspath[i];
        if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER && entry.getPath().equals(xtendContainerEntry.getPath())) {
            return false;
        }
        newRawClasspath[i + 1] = entry;
    }
    newRawClasspath[0] = xtendContainerEntry;
    javaProject.setRawClasspath(newRawClasspath, monitor);
    return true;
}
Also used : IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry)

Aggregations

IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)123 IPath (org.eclipse.core.runtime.IPath)55 IJavaProject (org.eclipse.jdt.core.IJavaProject)44 ArrayList (java.util.ArrayList)35 Path (org.eclipse.core.runtime.Path)27 JavaModelException (org.eclipse.jdt.core.JavaModelException)23 IProject (org.eclipse.core.resources.IProject)20 IClasspathAttribute (org.eclipse.jdt.core.IClasspathAttribute)16 File (java.io.File)15 IFolder (org.eclipse.core.resources.IFolder)13 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)13 CoreException (org.eclipse.core.runtime.CoreException)12 IJavaElement (org.eclipse.jdt.core.IJavaElement)12 JavaProject (org.eclipse.jdt.internal.core.JavaProject)11 IFile (org.eclipse.core.resources.IFile)10 IResource (org.eclipse.core.resources.IResource)10 HashMap (java.util.HashMap)9 Test (org.testng.annotations.Test)8 IOException (java.io.IOException)7 URL (java.net.URL)7