Search in sources :

Example 1 with Datatype

use of org.eclipse.xtext.index.indexTestLanguage.Datatype in project xtext-core by eclipse.

the class ReaderTest method testShadowingPathes.

@SuppressWarnings("unchecked")
@Test
public void testShadowingPathes() throws Exception {
    Reader reader = getReader();
    // also test adding multiple paths as comma-separated list, see bug#356750
    reader.addPath(pathTo("shadowingtest/folder 1") + "," + pathTo("shadowingtest/folder 2") + " , " + pathTo("shadowingtest/folder 3"));
    reader.addRegister(new IndexTestLanguageStandaloneSetup());
    SlotEntry entry = createSlotEntry();
    entry.setType("Entity");
    reader.addLoad(entry);
    SlotEntry entry2 = createSlotEntry();
    entry2.setType("Datatype");
    entry2.setSlot("stringTypes");
    entry2.setName("String");
    reader.addLoad(entry2);
    SlotEntry entry3 = createSlotEntry();
    entry3.setType("Datatype");
    entry3.setSlot("booleanTypes");
    entry3.setName("Boolean");
    reader.addLoad(entry3);
    WorkflowContext ctx = ctx();
    Issues issues = issues();
    try {
        reader.invoke(ctx, monitor(), issues);
    } catch (Exception e) {
        System.out.println(issues);
        throw e;
    }
    List<Entity> entities = (List<Entity>) ctx.get(entry.getSlot());
    List<Datatype> stringTypes = (List<Datatype>) ctx.get(entry2.getSlot());
    List<Datatype> booleanTypes = (List<Datatype>) ctx.get(entry3.getSlot());
    assertEquals(3, entities.size());
    assertEquals(2, stringTypes.size());
    assertEquals(2, booleanTypes.size());
    Entity ent1 = Iterables.find(entities, getPredicate("1"));
    Entity ent2 = Iterables.find(entities, getPredicate("2"));
    Entity ent3 = Iterables.find(entities, getPredicate("3"));
    Datatype string2 = Iterables.find(stringTypes, getPredicate("2"));
    Datatype string3 = Iterables.find(stringTypes, getPredicate("3"));
    Datatype bool1 = Iterables.find(booleanTypes, getPredicate("1"));
    Datatype bool2 = Iterables.find(booleanTypes, getPredicate("2"));
    assertEquals(string2, ent1.getProperties().get(0).getType());
    assertEquals(bool1, ent1.getProperties().get(1).getType());
    assertEquals(ent1, ent1.getProperties().get(2).getType());
    assertEquals(string2, ent2.getProperties().get(0).getType());
    assertEquals(bool2, ent2.getProperties().get(1).getType());
    assertEquals(ent2, ent2.getProperties().get(2).getType());
    assertEquals(string3, ent3.getProperties().get(0).getType());
    assertEquals(bool1, ent3.getProperties().get(1).getType());
    assertEquals(ent3, ent3.getProperties().get(2).getType());
}
Also used : Entity(org.eclipse.xtext.index.indexTestLanguage.Entity) Issues(org.eclipse.emf.mwe.core.issues.Issues) WorkflowContext(org.eclipse.emf.mwe.core.WorkflowContext) List(java.util.List) IndexTestLanguageStandaloneSetup(org.eclipse.xtext.index.IndexTestLanguageStandaloneSetup) Datatype(org.eclipse.xtext.index.indexTestLanguage.Datatype) Test(org.junit.Test)

Example 2 with Datatype

use of org.eclipse.xtext.index.indexTestLanguage.Datatype in project xtext-core by eclipse.

the class AbstractIndexTestLanguageSemanticSequencer 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 == IndexTestLanguagePackage.eINSTANCE)
        switch(semanticObject.eClass().getClassifierID()) {
            case IndexTestLanguagePackage.DATATYPE:
                sequence_Datatype(context, (Datatype) semanticObject);
                return;
            case IndexTestLanguagePackage.ENTITY:
                sequence_Entity(context, (Entity) semanticObject);
                return;
            case IndexTestLanguagePackage.FILE:
                sequence_File(context, (File) semanticObject);
                return;
            case IndexTestLanguagePackage.IMPORT:
                sequence_Import(context, (Import) semanticObject);
                return;
            case IndexTestLanguagePackage.NAMESPACE:
                sequence_Namespace(context, (Namespace) semanticObject);
                return;
            case IndexTestLanguagePackage.PROPERTY:
                sequence_Property(context, (Property) semanticObject);
                return;
        }
    if (errorAcceptor != null)
        errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) Entity(org.eclipse.xtext.index.indexTestLanguage.Entity) Action(org.eclipse.xtext.Action) Import(org.eclipse.xtext.index.indexTestLanguage.Import) Parameter(org.eclipse.xtext.Parameter) File(org.eclipse.xtext.index.indexTestLanguage.File) Property(org.eclipse.xtext.index.indexTestLanguage.Property) Namespace(org.eclipse.xtext.index.indexTestLanguage.Namespace) EPackage(org.eclipse.emf.ecore.EPackage) Datatype(org.eclipse.xtext.index.indexTestLanguage.Datatype)

Example 3 with Datatype

use of org.eclipse.xtext.index.indexTestLanguage.Datatype in project xtext-core by eclipse.

the class ImportedNamespaceAwareLocalScopeProviderTest method testLocalElementsNotFromIndex.

@Test
public void testLocalElementsNotFromIndex() throws Exception {
    final XtextResource resource = getResource(new StringInputStream("A { " + "  B { " + "    entity D {}" + "  }" + "}" + "E {" + "  datatype Context" + "}"), URI.createURI("foo23.indextestlanguage"));
    Iterable<EObject> allContents = new Iterable<EObject>() {

        @Override
        public Iterator<EObject> iterator() {
            return resource.getAllContents();
        }
    };
    Datatype datatype = filter(allContents, Datatype.class).iterator().next();
    IScope scope = scopeProvider.getScope(datatype, IndexTestLanguagePackage.eINSTANCE.getProperty_Type());
    assertNotNull(scope.getSingleElement(nameConverter.toQualifiedName("A.B.D")));
}
Also used : StringInputStream(org.eclipse.xtext.util.StringInputStream) EObject(org.eclipse.emf.ecore.EObject) IScope(org.eclipse.xtext.scoping.IScope) XtextResource(org.eclipse.xtext.resource.XtextResource) Datatype(org.eclipse.xtext.index.indexTestLanguage.Datatype) Test(org.junit.Test)

Example 4 with Datatype

use of org.eclipse.xtext.index.indexTestLanguage.Datatype in project xtext-core by eclipse.

the class ImportedNamespaceAwareLocalScopeProviderTest method testReexports2.

@Test
public void testReexports2() throws Exception {
    final XtextResource resource = getResource(new StringInputStream("A { " + "  B { " + "    entity D {}" + "  }" + "}" + "E {" + "  import A.B.*" + "  entity D {}" + "  datatype Context" + "}"), URI.createURI("testReexports2.indextestlanguage"));
    Iterable<EObject> allContents = new Iterable<EObject>() {

        @Override
        public Iterator<EObject> iterator() {
            return resource.getAllContents();
        }
    };
    Datatype datatype = filter(allContents, Datatype.class).iterator().next();
    IScope scope = scopeProvider.getScope(datatype, IndexTestLanguagePackage.eINSTANCE.getProperty_Type());
    assertNotNull(scope.getSingleElement(nameConverter.toQualifiedName("D")));
    assertNotNull(scope.getSingleElement(nameConverter.toQualifiedName("E.D")));
    assertNotNull(scope.getSingleElement(nameConverter.toQualifiedName("A.B.D")));
}
Also used : StringInputStream(org.eclipse.xtext.util.StringInputStream) EObject(org.eclipse.emf.ecore.EObject) IScope(org.eclipse.xtext.scoping.IScope) XtextResource(org.eclipse.xtext.resource.XtextResource) Datatype(org.eclipse.xtext.index.indexTestLanguage.Datatype) Test(org.junit.Test)

Aggregations

Datatype (org.eclipse.xtext.index.indexTestLanguage.Datatype)4 Test (org.junit.Test)3 EObject (org.eclipse.emf.ecore.EObject)2 Entity (org.eclipse.xtext.index.indexTestLanguage.Entity)2 XtextResource (org.eclipse.xtext.resource.XtextResource)2 IScope (org.eclipse.xtext.scoping.IScope)2 StringInputStream (org.eclipse.xtext.util.StringInputStream)2 List (java.util.List)1 EPackage (org.eclipse.emf.ecore.EPackage)1 WorkflowContext (org.eclipse.emf.mwe.core.WorkflowContext)1 Issues (org.eclipse.emf.mwe.core.issues.Issues)1 Action (org.eclipse.xtext.Action)1 Parameter (org.eclipse.xtext.Parameter)1 ParserRule (org.eclipse.xtext.ParserRule)1 IndexTestLanguageStandaloneSetup (org.eclipse.xtext.index.IndexTestLanguageStandaloneSetup)1 File (org.eclipse.xtext.index.indexTestLanguage.File)1 Import (org.eclipse.xtext.index.indexTestLanguage.Import)1 Namespace (org.eclipse.xtext.index.indexTestLanguage.Namespace)1 Property (org.eclipse.xtext.index.indexTestLanguage.Property)1