Search in sources :

Example 6 with Entity

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

the class AbstractReaderTest method testLoadByType.

@SuppressWarnings("unchecked")
@Test
public void testLoadByType() throws Exception {
    Reader reader = getReader();
    reader.addPath(pathTo("emptyFolder"));
    reader.addPath(pathTo("nonemptyFolder"));
    reader.addRegister(new IndexTestLanguageStandaloneSetup());
    SlotEntry entry = createSlotEntry();
    entry.setType("Entity");
    reader.addLoad(entry);
    WorkflowContext ctx = ctx();
    reader.invoke(ctx, monitor(), issues());
    List<Entity> entities = (List<Entity>) ctx.get("model");
    assertEquals(2, entities.size());
}
Also used : Entity(org.eclipse.xtext.index.indexTestLanguage.Entity) WorkflowContext(org.eclipse.emf.mwe.core.WorkflowContext) List(java.util.List) IndexTestLanguageStandaloneSetup(org.eclipse.xtext.index.IndexTestLanguageStandaloneSetup) Test(org.junit.Test)

Example 7 with Entity

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

the class AbstractReaderTest method testLoadBySuperType.

@SuppressWarnings("unchecked")
@Test
public void testLoadBySuperType() throws Exception {
    Reader reader = getReader();
    reader.addPath(pathTo("emptyFolder"));
    reader.addPath(pathTo("nonemptyFolder"));
    reader.addRegister(new IndexTestLanguageStandaloneSetup());
    SlotEntry entry = createSlotEntry();
    entry.setType("Type");
    reader.addLoad(entry);
    WorkflowContext ctx = ctx();
    reader.invoke(ctx, monitor(), issues());
    List<Entity> entities = (List<Entity>) ctx.get("model");
    assertEquals(3, entities.size());
}
Also used : Entity(org.eclipse.xtext.index.indexTestLanguage.Entity) WorkflowContext(org.eclipse.emf.mwe.core.WorkflowContext) List(java.util.List) IndexTestLanguageStandaloneSetup(org.eclipse.xtext.index.IndexTestLanguageStandaloneSetup) Test(org.junit.Test)

Example 8 with Entity

use of org.eclipse.xtext.index.indexTestLanguage.Entity 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 9 with Entity

use of org.eclipse.xtext.index.indexTestLanguage.Entity 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 10 with Entity

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

the class IndexTestLanguageGenerator method doGenerate.

@Override
public void doGenerate(final Resource input, final IFileSystemAccess2 fsa, final IGeneratorContext context) {
    final TreeIterator<EObject> iter = input.getAllContents();
    while (iter.hasNext()) {
        EObject _next = iter.next();
        final EObject e = _next;
        boolean _matched = false;
        if (e instanceof Entity) {
            _matched = true;
            String _name = ((Entity) e).getName();
            String _plus = (_name + ".txt");
            StringConcatenation _builder = new StringConcatenation();
            _builder.append("Hello ");
            String _name_1 = ((Entity) e).getName();
            _builder.append(_name_1);
            _builder.append("!");
            _builder.newLineIfNotEmpty();
            fsa.generateFile(_plus, _builder);
        }
    }
}
Also used : Entity(org.eclipse.xtext.index.indexTestLanguage.Entity) EObject(org.eclipse.emf.ecore.EObject) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation)

Aggregations

Entity (org.eclipse.xtext.index.indexTestLanguage.Entity)19 Test (org.junit.Test)16 EObject (org.eclipse.emf.ecore.EObject)13 StringInputStream (org.eclipse.xtext.util.StringInputStream)12 XtextResource (org.eclipse.xtext.resource.XtextResource)10 IScope (org.eclipse.xtext.scoping.IScope)10 Predicate (com.google.common.base.Predicate)6 Resource (org.eclipse.emf.ecore.resource.Resource)5 List (java.util.List)4 WorkflowContext (org.eclipse.emf.mwe.core.WorkflowContext)4 IndexTestLanguageStandaloneSetup (org.eclipse.xtext.index.IndexTestLanguageStandaloneSetup)4 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)4 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)3 ResourceSetReferencingResourceSetImpl (org.eclipse.xtext.resource.ResourceSetReferencingResourceSetImpl)3 InternalEObject (org.eclipse.emf.ecore.InternalEObject)2 Datatype (org.eclipse.xtext.index.indexTestLanguage.Datatype)2 EPackage (org.eclipse.emf.ecore.EPackage)1 Issues (org.eclipse.emf.mwe.core.issues.Issues)1 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)1 Action (org.eclipse.xtext.Action)1