use of org.eclipse.xtext.index.indexTestLanguage.Entity in project xtext-core by eclipse.
the class ImportedNamespaceAwareLocalScopeProviderTest method getEntityByName.
protected Entity getEntityByName(final Resource res2, String name) {
Iterable<EObject> allContents = new Iterable<EObject>() {
@Override
public Iterator<EObject> iterator() {
return res2.getAllContents();
}
};
Iterable<Entity> iterator = Iterables.filter(allContents, Entity.class);
for (Entity entity : iterator) {
if (entity.getName().equals(name))
return entity;
}
return null;
}
use of org.eclipse.xtext.index.indexTestLanguage.Entity in project xtext-core by eclipse.
the class ImportedNamespaceAwareLocalScopeProviderTest method testUnambiguousImportAreShadowed_01.
@Test
public void testUnambiguousImportAreShadowed_01() throws Exception {
final XtextResource resource = getResource(new StringInputStream("foo { " + " entity Foo {}" + " entity Bar {}" + "}" + "bar {" + " entity Foo {}" + "}" + "baz {" + " import foo.*" + " import bar.Foo" + " entity Baz{}" + "}"), URI.createURI("withoutwildcard.indextestlanguage"));
Iterable<EObject> allContents = new Iterable<EObject>() {
@Override
public Iterator<EObject> iterator() {
return resource.getAllContents();
}
};
Entity foo = find(Iterables.filter(allContents, Entity.class), new Predicate<Entity>() {
@Override
public boolean apply(Entity input) {
return input.getName().equals("Baz");
}
});
IScope scope = scopeProvider.getScope(foo, IndexTestLanguagePackage.eINSTANCE.getProperty_Type());
assertNotNull(scope.getSingleElement(nameConverter.toQualifiedName("Bar")));
assertNull(scope.getSingleElement(nameConverter.toQualifiedName("Foo")));
ArrayList<IEObjectDescription> list = newArrayList(scope.getAllElements());
assertEquals(6, list.size());
assertFalse(any(list, new Predicate<IEObjectDescription>() {
@Override
public boolean apply(IEObjectDescription input) {
return input.getName().equals(QualifiedName.create("Foo"));
}
}));
}
use of org.eclipse.xtext.index.indexTestLanguage.Entity in project xtext-core by eclipse.
the class ImportedNamespaceAwareLocalScopeProviderTest method testRelativePath.
@Test
public void testRelativePath() throws Exception {
final XtextResource resource = getResource(new StringInputStream("stuff { " + " import baz.*" + " baz { " + " datatype String " + " } " + " entity Person {" + " }" + "}"), URI.createURI("relative.indextestlanguage"));
Iterable<EObject> allContents = new Iterable<EObject>() {
@Override
public Iterator<EObject> iterator() {
return resource.getAllContents();
}
};
Entity entity = filter(allContents, Entity.class).iterator().next();
IScope scope = scopeProvider.getScope(entity, IndexTestLanguagePackage.eINSTANCE.getProperty_Type());
assertNotNull(scope.getSingleElement(nameConverter.toQualifiedName("String")));
assertNotNull(scope.getSingleElement(nameConverter.toQualifiedName("baz.String")));
assertNotNull(scope.getSingleElement(nameConverter.toQualifiedName("stuff.baz.String")));
}
use of org.eclipse.xtext.index.indexTestLanguage.Entity in project xtext-core by eclipse.
the class ImportedNamespaceAwareLocalScopeProviderTest method testUnambiguousImportAreShadowed_00.
@Test
public void testUnambiguousImportAreShadowed_00() throws Exception {
final XtextResource resource = getResource(new StringInputStream("foo { " + " entity Foo {}" + " entity Bar {}" + "}" + "bar {" + " entity Foo {}" + "}" + "baz {" + " import foo.*" + " import bar.*" + " entity Baz{}" + "}"), URI.createURI("withoutwildcard.indextestlanguage"));
Iterable<EObject> allContents = new Iterable<EObject>() {
@Override
public Iterator<EObject> iterator() {
return resource.getAllContents();
}
};
Entity foo = find(Iterables.filter(allContents, Entity.class), new Predicate<Entity>() {
@Override
public boolean apply(Entity input) {
return input.getName().equals("Baz");
}
});
IScope scope = scopeProvider.getScope(foo, IndexTestLanguagePackage.eINSTANCE.getProperty_Type());
assertNotNull(scope.getSingleElement(nameConverter.toQualifiedName("Bar")));
assertNull(scope.getSingleElement(nameConverter.toQualifiedName("Foo")));
ArrayList<IEObjectDescription> list = newArrayList(scope.getAllElements());
assertEquals(6, list.size());
assertFalse(any(list, new Predicate<IEObjectDescription>() {
@Override
public boolean apply(IEObjectDescription input) {
return input.getName().equals(QualifiedName.create("Foo"));
}
}));
}
use of org.eclipse.xtext.index.indexTestLanguage.Entity in project xtext-core by eclipse.
the class AbstractReaderTest method testLoadByType_withNsURI.
@SuppressWarnings("unchecked")
@Test
public void testLoadByType_withNsURI() throws Exception {
Reader reader = getReader();
reader.addPath(pathTo("emptyFolder"));
reader.addPath(pathTo("nonemptyFolder"));
reader.addRegister(new IndexTestLanguageStandaloneSetup());
SlotEntry entry = createSlotEntry();
entry.setType("Entity");
entry.setNsURI(IndexTestLanguagePackage.eNS_URI);
reader.addLoad(entry);
WorkflowContext ctx = ctx();
reader.invoke(ctx, monitor(), issues());
List<Entity> entities = (List<Entity>) ctx.get("model");
assertEquals(2, entities.size());
}
Aggregations