Search in sources :

Example 1 with DescriptionFacet

use of org.metaborg.core.language.DescriptionFacet in project spoofax by metaborg.

the class LanguageServiceTest method multipleUnexpectedFacets.

/**
 * Try to get a single facet, but have multiple. Assert that exception is thrown.
 */
@Test(expected = MetaborgRuntimeException.class)
public void multipleUnexpectedFacets() throws Exception {
    final LanguageVersion version = version(0, 0, 1);
    final FileObject location = createDir("ram:///");
    final ILanguageComponent component = language(groupId, "org.metaborg.lang.entity", version, location, "Entity", new DescriptionFacet("Entity language", null), new DescriptionFacet("Entity language", null));
    component.facet(DescriptionFacet.class);
}
Also used : LanguageVersion(org.metaborg.core.language.LanguageVersion) FileObject(org.apache.commons.vfs2.FileObject) ILanguageComponent(org.metaborg.core.language.ILanguageComponent) DescriptionFacet(org.metaborg.core.language.DescriptionFacet) Test(org.junit.Test) MetaborgTest(org.metaborg.core.test.MetaborgTest)

Example 2 with DescriptionFacet

use of org.metaborg.core.language.DescriptionFacet in project spoofax by metaborg.

the class LanguageServiceTest method implementationFacets.

/**
 * Add multiple components with facets to a single implementation, assert correctness of returned facets.
 */
@Test
public void implementationFacets() throws Exception {
    final String id1 = "org.metaborg.lang.entity.component1";
    final String id2 = "org.metaborg.lang.entity.component2";
    final LanguageVersion version = version(0, 0, 1);
    final LanguageIdentifier identifier1 = new LanguageIdentifier(groupId, id1, version);
    final LanguageIdentifier identifier2 = new LanguageIdentifier(groupId, id2, version);
    final FileObject location1 = createDir("ram:///Entity1");
    final FileObject location2 = createDir("ram:///Entity2");
    final String implId = "org.metaborg.lang.entity.impl1";
    final String name = "Entity";
    final LanguageIdentifier implIdentifier = new LanguageIdentifier(groupId, implId, version);
    final LanguageContributionIdentifier requestIdentifier = new LanguageContributionIdentifier(implIdentifier, name);
    final DescriptionFacet facet1 = new DescriptionFacet("Component1", null);
    final ResourceExtensionFacet facet2 = new ResourceExtensionFacet(Iterables2.singleton("com"));
    final DescriptionFacet facet3 = new DescriptionFacet("Component2", null);
    final ILanguageComponent component1 = language(identifier1, location1, requestIdentifier, facet1, facet2);
    final ILanguageComponent component2 = language(identifier2, location2, requestIdentifier, facet3);
    final ILanguageImpl impl = languageService.getImpl(implIdentifier);
    assertContains(facet1, component1.facets());
    assertContains(facet2, component1.facets());
    assertContains(facet3, component2.facets());
    assertSize(2, component1.facets());
    assertSize(1, component2.facets());
    assertContains(facet1, component1.facets(DescriptionFacet.class));
    assertSame(facet1, component1.facet(DescriptionFacet.class));
    assertSize(1, component1.facets(DescriptionFacet.class));
    assertContains(facet2, component1.facets(ResourceExtensionFacet.class));
    assertSame(facet2, component1.facet(ResourceExtensionFacet.class));
    assertSize(1, component1.facets(ResourceExtensionFacet.class));
    assertContains(facet3, component2.facets(DescriptionFacet.class));
    assertSame(facet3, component2.facet(DescriptionFacet.class));
    assertSize(1, component2.facets(DescriptionFacet.class));
    assertContains(facet1, impl.facets());
    assertContains(facet2, impl.facets());
    assertContains(facet3, impl.facets());
    assertSize(3, impl.facets());
    assertContains(facet1, impl.facets(DescriptionFacet.class));
    assertContains(facet2, impl.facets(ResourceExtensionFacet.class));
    assertContains(facet3, impl.facets(DescriptionFacet.class));
    assertSize(2, impl.facets(DescriptionFacet.class));
    assertSize(1, impl.facets(ResourceExtensionFacet.class));
    for (FacetContribution<IFacet> facetContribution : component1.facetContributions()) {
        assertSame(facetContribution.contributor, component1);
    }
    assertSame(component1, component1.facetContribution(DescriptionFacet.class).contributor);
    assertSame(facet1, component1.facetContribution(DescriptionFacet.class).facet);
    assertSize(1, component1.facetContributions(DescriptionFacet.class));
    assertSame(component1, component1.facetContribution(ResourceExtensionFacet.class).contributor);
    assertSame(facet2, component1.facetContribution(ResourceExtensionFacet.class).facet);
    assertSize(1, component1.facetContributions(ResourceExtensionFacet.class));
    for (FacetContribution<IFacet> facetContribution : component2.facetContributions()) {
        assertSame(facetContribution.contributor, component2);
    }
    assertSame(component2, component2.facetContribution(DescriptionFacet.class).contributor);
    assertSame(facet3, component2.facetContribution(DescriptionFacet.class).facet);
    assertSize(1, component2.facetContributions(DescriptionFacet.class));
    for (FacetContribution<IFacet> facetContribution : impl.facetContributions()) {
        final ILanguageComponent contributor = facetContribution.contributor;
        final IFacet facet = facetContribution.facet;
        if (facet.equals(facet1)) {
            assertSame(component1, contributor);
        } else if (facet.equals(facet2)) {
            assertSame(component1, contributor);
        } else if (facet.equals(facet3)) {
            assertSame(component2, contributor);
        } else {
            fail("Facet does not equals any created facet");
        }
    }
}
Also used : LanguageIdentifier(org.metaborg.core.language.LanguageIdentifier) ILanguageImpl(org.metaborg.core.language.ILanguageImpl) ResourceExtensionFacet(org.metaborg.core.language.ResourceExtensionFacet) IFacet(org.metaborg.core.language.IFacet) LanguageVersion(org.metaborg.core.language.LanguageVersion) FileObject(org.apache.commons.vfs2.FileObject) ILanguageComponent(org.metaborg.core.language.ILanguageComponent) DescriptionFacet(org.metaborg.core.language.DescriptionFacet) LanguageContributionIdentifier(org.metaborg.core.language.LanguageContributionIdentifier) Test(org.junit.Test) MetaborgTest(org.metaborg.core.test.MetaborgTest)

Aggregations

FileObject (org.apache.commons.vfs2.FileObject)2 Test (org.junit.Test)2 DescriptionFacet (org.metaborg.core.language.DescriptionFacet)2 ILanguageComponent (org.metaborg.core.language.ILanguageComponent)2 LanguageVersion (org.metaborg.core.language.LanguageVersion)2 MetaborgTest (org.metaborg.core.test.MetaborgTest)2 IFacet (org.metaborg.core.language.IFacet)1 ILanguageImpl (org.metaborg.core.language.ILanguageImpl)1 LanguageContributionIdentifier (org.metaborg.core.language.LanguageContributionIdentifier)1 LanguageIdentifier (org.metaborg.core.language.LanguageIdentifier)1 ResourceExtensionFacet (org.metaborg.core.language.ResourceExtensionFacet)1