Search in sources :

Example 1 with Type

use of org.eclipse.xtext.linking.importedURI.Type 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 2 with Type

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

the class Bug437669Test method testUnresolved_02.

@Test
public void testUnresolved_02() {
    Type type = getContext();
    INode nameNode = NodeModelUtils.findNodesForFeature(type, ImportedURIPackage.Literals.TYPE__NAME).get(0);
    resolve(type, "BlaBlaBla", nameNode.getOffset(), nameNode.getLength());
    Resource resource = type.eResource();
    assertEquals(resource.getErrors().toString(), 1, resource.getErrors().size());
    LineAndColumn lineAndColumn = NodeModelUtils.getLineAndColumn(nameNode, nameNode.getOffset());
    Diagnostic diagnostic = (Diagnostic) resource.getErrors().get(0);
    assertEquals(nameNode.getOffset(), diagnostic.getOffset());
    assertEquals(nameNode.getLength(), diagnostic.getLength());
    assertEquals(lineAndColumn.getLine(), diagnostic.getLine());
    assertEquals(lineAndColumn.getColumn(), diagnostic.getColumn());
    assertEquals("Couldn't resolve reference to Type 'BlaBlaBla'.", diagnostic.getMessage());
}
Also used : Type(org.eclipse.xtext.linking.importedURI.Type) INode(org.eclipse.xtext.nodemodel.INode) Resource(org.eclipse.emf.ecore.resource.Resource) Diagnostic(org.eclipse.xtext.diagnostics.Diagnostic) LineAndColumn(org.eclipse.xtext.util.LineAndColumn) Test(org.junit.Test)

Example 3 with Type

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

the class Bug437669Test method testUnresolved_01.

@Test
public void testUnresolved_01() {
    Type type = resolve("BlaBlaBla");
    Resource resource = type.eResource();
    assertEquals(resource.getErrors().toString(), 1, resource.getErrors().size());
    Diagnostic diagnostic = (Diagnostic) resource.getErrors().get(0);
    assertEquals(0, diagnostic.getOffset());
    assertEquals(1, diagnostic.getLength());
    assertEquals(1, diagnostic.getLine());
    assertEquals(1, diagnostic.getColumn());
    assertEquals("Couldn't resolve reference to Type 'BlaBlaBla'.", diagnostic.getMessage());
}
Also used : Type(org.eclipse.xtext.linking.importedURI.Type) Resource(org.eclipse.emf.ecore.resource.Resource) Diagnostic(org.eclipse.xtext.diagnostics.Diagnostic) Test(org.junit.Test)

Example 4 with Type

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

the class UriBasedReaderTest method testTransitiveReferences.

@SuppressWarnings("unchecked")
@Test
public void testTransitiveReferences() throws Exception {
    UriBasedReader reader = new UriBasedReader();
    reader.addRegister(new ImportUriTestLanguageStandaloneSetup());
    reader.addUri(pathTo2("importUriSubfolder/Start.importuritestlanguage"));
    SlotEntry slotEntry = new SlotEntry();
    slotEntry.setType("Type");
    reader.addLoad(slotEntry);
    WorkflowContext ctx = new WorkflowContextDefaultImpl();
    IssuesImpl issues = new IssuesImpl();
    reader.checkConfiguration(issues);
    try {
        reader.invoke(ctx, new NullProgressMonitor(), issues);
    } catch (Exception e) {
        System.out.println(issues);
        throw e;
    }
    List<Type> types = (List<Type>) ctx.get(slotEntry.getSlot());
    assertEquals(3, types.size());
    for (Type type : types) {
        if (type.getName().equals("Foo")) {
            assertEquals("Bar", type.getExtends().getName());
        } else if (type.getName().equals("Bar")) {
            assertEquals("Baz", type.getExtends().getName());
        } else {
            assertNull(type.getExtends());
        }
    }
}
Also used : NullProgressMonitor(org.eclipse.emf.mwe.core.monitor.NullProgressMonitor) Type(org.eclipse.xtext.linking.importedURI.Type) ImportUriTestLanguageStandaloneSetup(org.eclipse.xtext.linking.ImportUriTestLanguageStandaloneSetup) WorkflowContext(org.eclipse.emf.mwe.core.WorkflowContext) WorkflowContextDefaultImpl(org.eclipse.emf.mwe.core.WorkflowContextDefaultImpl) IssuesImpl(org.eclipse.emf.mwe.core.issues.IssuesImpl) List(java.util.List) Test(org.junit.Test)

Example 5 with Type

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

the class Bug437669Test method testResolved.

@Test
public void testResolved() {
    Type type = resolve("Foo");
    Resource resource = type.eResource();
    assertTrue(resource.getErrors().toString(), resource.getErrors().isEmpty());
    Type resolvedType = type.getExtends();
    assertNotNull(resolvedType);
    assertFalse(resolvedType.eIsProxy());
    assertEquals("Foo", resolvedType.getName());
}
Also used : Type(org.eclipse.xtext.linking.importedURI.Type) Resource(org.eclipse.emf.ecore.resource.Resource) Test(org.junit.Test)

Aggregations

Type (org.eclipse.xtext.linking.importedURI.Type)7 Test (org.junit.Test)5 Resource (org.eclipse.emf.ecore.resource.Resource)3 Diagnostic (org.eclipse.xtext.diagnostics.Diagnostic)2 Main (org.eclipse.xtext.linking.importedURI.Main)2 List (java.util.List)1 EPackage (org.eclipse.emf.ecore.EPackage)1 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)1 WorkflowContext (org.eclipse.emf.mwe.core.WorkflowContext)1 WorkflowContextDefaultImpl (org.eclipse.emf.mwe.core.WorkflowContextDefaultImpl)1 IssuesImpl (org.eclipse.emf.mwe.core.issues.IssuesImpl)1 NullProgressMonitor (org.eclipse.emf.mwe.core.monitor.NullProgressMonitor)1 Action (org.eclipse.xtext.Action)1 Parameter (org.eclipse.xtext.Parameter)1 ParserRule (org.eclipse.xtext.ParserRule)1 ImportUriTestLanguageStandaloneSetup (org.eclipse.xtext.linking.ImportUriTestLanguageStandaloneSetup)1 Import (org.eclipse.xtext.linking.importedURI.Import)1 INode (org.eclipse.xtext.nodemodel.INode)1 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)1 IScope (org.eclipse.xtext.scoping.IScope)1