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());
}
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);
}
}
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;
}
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);
}
}
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;
}
Aggregations