use of org.eclipse.xtext.resource.IResourceDescriptions in project n4js by eclipse.
the class StaticPolyfillHelper method hasStaticPolyfill.
/**
* For a given N4JSResource annotated with {@code @@StaticPolyfillAware} lookup the filling Module. returns
* {@code true} if the filling Module exists in the project.
*/
public boolean hasStaticPolyfill(Resource resource) {
// ensure right resource
if (resource instanceof N4JSResource) {
final N4JSResource res = (N4JSResource) resource;
if (isContainedInStaticPolyfillAware(res.getScript())) {
// TODO GHOLD-196 resolve inconsistency in logic between this method and #findStaticPolyfiller(Resource)
// (i.e. if possible, delete strategy #1 and only use strategy #2; but make sure this isn't a
// performance issue, esp. with respect to the call "srcConti.findArtifact(fqn, fileExtension)" in
// #findStaticPolyfiller(Resource))
boolean strategyIndex = true;
if (strategyIndex) {
// 1. query index
final QualifiedName qnFilled = qualifiedNameConverter.toQualifiedName(res.getModule().getQualifiedName());
final IResourceDescriptions index = indexAccess.getResourceDescriptions(res.getResourceSet());
final java.util.Optional<QualifiedName> optQnFilling = N4TSQualifiedNameProvider.toStaticPolyfillFQN(qnFilled);
if (optQnFilling.isPresent()) {
final QualifiedName qnFilling = optQnFilling.get();
final Iterable<IEObjectDescription> modules = index.getExportedObjectsByType(TypesPackage.Literals.TMODULE);
for (IEObjectDescription module : modules) {
if (module.getQualifiedName() == qnFilling) {
return true;
}
}
}
} else {
// 2. query all source-containers for file with same QN
final URI fillingURI = findStaticPolyfiller(res);
if (null != fillingURI)
return true;
}
}
}
return false;
}
use of org.eclipse.xtext.resource.IResourceDescriptions in project n4js by eclipse.
the class AbstractBuilderTest method assertXtextIndexIsValidInternal.
private void assertXtextIndexIsValidInternal() {
final IResourceDescriptions index = getXtextIndex();
final StringBuilder sb = new StringBuilder();
for (IResourceDescription desc : index.getAllResourceDescriptions()) {
if (desc instanceof ResourceDescriptionWithoutModuleUserData) {
sb.append("\n");
sb.append(IResourceDescription.class.getSimpleName());
sb.append(" in index must not be an instance of ");
sb.append(ResourceDescriptionWithoutModuleUserData.class.getSimpleName());
sb.append(" but it was. URI: ");
sb.append(desc.getURI());
}
}
assertTrue(sb.toString(), 0 == sb.length());
}
use of org.eclipse.xtext.resource.IResourceDescriptions in project n4js by eclipse.
the class BuilderUtil method indexContainsElement.
/**
*/
public static boolean indexContainsElement(final String fileUri, final String eObjectName) {
IResourceDescriptions descriptions = getBuilderState();
URI uri = URI.createURI("platform:/resource" + fileUri);
IResourceDescription description = descriptions.getResourceDescription(uri);
if (description != null) {
return description.getExportedObjects(EcorePackage.Literals.EOBJECT, QualifiedName.create(eObjectName), false).iterator().hasNext();
}
return false;
}
use of org.eclipse.xtext.resource.IResourceDescriptions in project xtext-xtend by eclipse.
the class FilesInJarsAreNotIndexedTest method testXtendInSourceIsIndexed_02.
@Test
public void testXtendInSourceIsIndexed_02() throws Exception {
IProject project = workbenchTestHelper.getProject();
IJavaProject javaProject = JavaCore.create(project);
addSourceFolder(javaProject, "src");
IFile file = workbenchTestHelper.createFile("my/XtendClass.xtend", "package my\n" + "import static extension example5.Distance.*\n" + "import static extension example5.Time.*\n" + "import static extension example5.Speed.*\n" + "class XtendClass {\n" + " def foo() {\n" + " println((13.km + 2_000.m) * 2)\n" + " println(65.sec + 59.min - 5_000.msec)\n" + " println(42.km/h == (40_000.m + 2.km) / 60.min)\n" + " }\n" + " } ");
addJarToClasspath(javaProject, copyAndGetXtendExampleJar(javaProject));
waitForBuild();
IMarker[] markers = file.findMarkers(IMarker.PROBLEM, true, -1);
if (markers.length > 0) {
fail("No markers expected but got: " + markers[0].getAttribute(IMarker.MESSAGE));
}
IResourceDescriptions descriptions = descriptionsProvider.get();
Iterator<IResourceDescription> iterator = descriptions.getAllResourceDescriptions().iterator();
assertEquals(URI.createPlatformResourceURI(file.getFullPath().toString(), true), iterator.next().getURI());
assertFalse(iterator.hasNext());
}
use of org.eclipse.xtext.resource.IResourceDescriptions in project xtext-xtend by eclipse.
the class FilesInJarsAreNotIndexedTest method testXtendInSourceIsIndexed.
@Test
public void testXtendInSourceIsIndexed() throws Exception {
IProject project = workbenchTestHelper.getProject();
IJavaProject javaProject = JavaCore.create(project);
addSourceFolder(javaProject, "src");
IFile file = workbenchTestHelper.createFile("src/my/XtendClass.xtend", "package my class XtendClass { } ");
waitForBuild();
IResourceDescriptions descriptions = descriptionsProvider.get();
assertEquals(URI.createPlatformResourceURI(file.getFullPath().toString(), true), descriptions.getAllResourceDescriptions().iterator().next().getURI());
}
Aggregations