Search in sources :

Example 6 with Main

use of org.eclipse.xtext.linking.importedURI.Main in project xtext-core by eclipse.

the class SimpleNameScopeProviderTest method testRelativeScopeWithPath.

// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=266879
@Test
public void testRelativeScopeWithPath() throws Exception {
    SyntheticModelAwareURIConverter models = new SyntheticModelAwareURIConverter();
    ResourceSetImpl rs = new ResourceSetImpl();
    rs.setURIConverter(models);
    models.addModel("testfile://my/folder/foo.importuritestlanguage", "import './../folder/bar.importuritestlanguage' type foo extends bar type bar extends bar2");
    models.addModel("testfile://my/folder/bar.importuritestlanguage", "type bar type bar2 extends bar");
    Resource resource = rs.getResource(URI.createURI("testfile://my/folder/foo.importuritestlanguage"), true);
    Main main = (Main) resource.getContents().get(0);
    assertEquals("bar", main.getTypes().get(0).getExtends().getName());
    assertEquals("bar2", main.getTypes().get(0).getExtends().getExtends().getName());
    assertEquals("bar", main.getTypes().get(0).getExtends().getExtends().getExtends().getName());
    assertNull(main.getTypes().get(0).getExtends().getExtends().getExtends().getExtends());
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) Resource(org.eclipse.emf.ecore.resource.Resource) Main(org.eclipse.xtext.linking.importedURI.Main) Test(org.junit.Test)

Example 7 with Main

use of org.eclipse.xtext.linking.importedURI.Main in project xtext-core by eclipse.

the class URINormalizationTest method testGetElementByClasspathURIEObject.

@Test
public void testGetElementByClasspathURIEObject() throws Exception {
    with(ImportUriTestLanguageStandaloneSetup.class);
    Main main = (Main) getModel("import 'classpath:/org/eclipse/xtext/linking/05.importuritestlanguage'\n" + "type Bar extends Foo");
    Type bar = main.getTypes().get(0);
    Type foo = bar.getExtends();
    assertNotNull(foo);
    assertFalse(foo.eIsProxy());
    // they are partially normalized
    if (Platform.isRunning()) {
        assertEquals("bundleresource", EcoreUtil.getURI(foo).scheme());
    } else {
        assertEquals("file", EcoreUtil.getURI(foo).scheme());
    }
    IScopeProvider scopeProvider = get(IScopeProvider.class);
    IScope scope = scopeProvider.getScope(bar, ImportedURIPackage.Literals.TYPE__EXTENDS);
    Iterable<IEObjectDescription> elements = scope.getElements(foo);
    assertEquals(1, size(elements));
    assertEquals(EcoreUtil2.getPlatformResourceOrNormalizedURI(foo), elements.iterator().next().getEObjectURI());
}
Also used : Type(org.eclipse.xtext.linking.importedURI.Type) IScopeProvider(org.eclipse.xtext.scoping.IScopeProvider) IScope(org.eclipse.xtext.scoping.IScope) Main(org.eclipse.xtext.linking.importedURI.Main) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) Test(org.junit.Test)

Example 8 with Main

use of org.eclipse.xtext.linking.importedURI.Main in project xtext-core by eclipse.

the class ImportUriTestLanguageSemanticSequencer method sequence.

@Override
public void sequence(ISerializationContext context, EObject semanticObject) {
    EPackage epackage = semanticObject.eClass().getEPackage();
    ParserRule rule = context.getParserRule();
    Action action = context.getAssignedAction();
    Set<Parameter> parameters = context.getEnabledBooleanParameters();
    if (epackage == ImportedURIPackage.eINSTANCE)
        switch(semanticObject.eClass().getClassifierID()) {
            case ImportedURIPackage.IMPORT:
                sequence_Import(context, (Import) semanticObject);
                return;
            case ImportedURIPackage.MAIN:
                sequence_Main(context, (Main) semanticObject);
                return;
            case ImportedURIPackage.TYPE:
                sequence_Type(context, (Type) semanticObject);
                return;
        }
    if (errorAcceptor != null)
        errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) Action(org.eclipse.xtext.Action) Type(org.eclipse.xtext.linking.importedURI.Type) Import(org.eclipse.xtext.linking.importedURI.Import) Parameter(org.eclipse.xtext.Parameter) Main(org.eclipse.xtext.linking.importedURI.Main) EPackage(org.eclipse.emf.ecore.EPackage)

Example 9 with Main

use of org.eclipse.xtext.linking.importedURI.Main in project xtext-core by eclipse.

the class SimpleNameScopeProviderTest method testRelativeScope.

// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=266879
@Test
public void testRelativeScope() throws Exception {
    SyntheticModelAwareURIConverter models = new SyntheticModelAwareURIConverter();
    ResourceSetImpl rs = new ResourceSetImpl();
    rs.setURIConverter(models);
    models.addModel("testfile://my/folder/foo.importuritestlanguage", "import 'bar.importuritestlanguage' type foo extends bar type bar extends bar2");
    models.addModel("testfile://my/folder/bar.importuritestlanguage", "type bar type bar2 extends bar");
    Resource resource = rs.getResource(URI.createURI("testfile://my/folder/foo.importuritestlanguage"), true);
    Main main = (Main) resource.getContents().get(0);
    assertEquals("bar", main.getTypes().get(0).getExtends().getName());
    assertEquals("bar2", main.getTypes().get(0).getExtends().getExtends().getName());
    assertEquals("bar", main.getTypes().get(0).getExtends().getExtends().getExtends().getName());
    assertNull(main.getTypes().get(0).getExtends().getExtends().getExtends().getExtends());
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) Resource(org.eclipse.emf.ecore.resource.Resource) Main(org.eclipse.xtext.linking.importedURI.Main) Test(org.junit.Test)

Example 10 with Main

use of org.eclipse.xtext.linking.importedURI.Main in project xtext-core by eclipse.

the class SimpleNameScopeProviderTest method testGetAllContents.

@Test
public void testGetAllContents() throws Exception {
    SyntheticModelAwareURIConverter models = new SyntheticModelAwareURIConverter();
    ResourceSetImpl rs = new ResourceSetImpl();
    rs.setURIConverter(models);
    models.addModel("foo.importuritestlanguage", "import 'bar.importuritestlanguage' type Foo");
    models.addModel("bar.importuritestlanguage", "type A type B type C");
    Resource resource = rs.getResource(URI.createURI("foo.importuritestlanguage"), true);
    IScope scope = getScopeProvider().getScope(((Main) resource.getContents().get(0)).getTypes().get(0), ImportedURIPackage.Literals.TYPE__EXTENDS);
    HashSet<IEObjectDescription> set = Sets.newHashSet(scope.getAllElements());
    assertEquals(4, set.size());
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) Resource(org.eclipse.emf.ecore.resource.Resource) IScope(org.eclipse.xtext.scoping.IScope) Main(org.eclipse.xtext.linking.importedURI.Main) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) Test(org.junit.Test)

Aggregations

Main (org.eclipse.xtext.linking.importedURI.Main)10 Resource (org.eclipse.emf.ecore.resource.Resource)8 Test (org.junit.Test)8 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)7 Type (org.eclipse.xtext.linking.importedURI.Type)2 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)2 IScope (org.eclipse.xtext.scoping.IScope)2 URI (org.eclipse.emf.common.util.URI)1 EPackage (org.eclipse.emf.ecore.EPackage)1 Action (org.eclipse.xtext.Action)1 Parameter (org.eclipse.xtext.Parameter)1 ParserRule (org.eclipse.xtext.ParserRule)1 Import (org.eclipse.xtext.linking.importedURI.Import)1 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)1 IScopeProvider (org.eclipse.xtext.scoping.IScopeProvider)1