Search in sources :

Example 36 with IResourceDescriptions

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;
}
Also used : QualifiedName(org.eclipse.xtext.naming.QualifiedName) IResourceDescriptions(org.eclipse.xtext.resource.IResourceDescriptions) N4JSResource(org.eclipse.n4js.resource.N4JSResource) URI(org.eclipse.emf.common.util.URI) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 37 with IResourceDescriptions

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());
}
Also used : IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) ResourceDescriptionWithoutModuleUserData(org.eclipse.n4js.ui.building.ResourceDescriptionWithoutModuleUserData) IResourceDescriptions(org.eclipse.xtext.resource.IResourceDescriptions)

Example 38 with IResourceDescriptions

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;
}
Also used : IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) IResourceDescriptions(org.eclipse.xtext.resource.IResourceDescriptions) URI(org.eclipse.emf.common.util.URI)

Example 39 with IResourceDescriptions

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());
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) IFile(org.eclipse.core.resources.IFile) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) IResourceDescriptions(org.eclipse.xtext.resource.IResourceDescriptions) IMarker(org.eclipse.core.resources.IMarker) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test)

Example 40 with IResourceDescriptions

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());
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) IFile(org.eclipse.core.resources.IFile) IResourceDescriptions(org.eclipse.xtext.resource.IResourceDescriptions) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test)

Aggregations

IResourceDescriptions (org.eclipse.xtext.resource.IResourceDescriptions)46 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)23 URI (org.eclipse.emf.common.util.URI)18 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)15 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)13 Resource (org.eclipse.emf.ecore.resource.Resource)12 EObject (org.eclipse.emf.ecore.EObject)11 QualifiedName (org.eclipse.xtext.naming.QualifiedName)7 IContainer (org.eclipse.xtext.resource.IContainer)7 List (java.util.List)6 Test (org.junit.Test)6 IN4JSProject (org.eclipse.n4js.projectModel.IN4JSProject)5 IScope (org.eclipse.xtext.scoping.IScope)5 IProject (org.eclipse.core.resources.IProject)4 EClass (org.eclipse.emf.ecore.EClass)4 XtextResource (org.eclipse.xtext.resource.XtextResource)4 IFile (org.eclipse.core.resources.IFile)3 CoreException (org.eclipse.core.runtime.CoreException)3 EPackage (org.eclipse.emf.ecore.EPackage)3 TModule (org.eclipse.n4js.ts.types.TModule)3