use of org.eclipse.xtext.scoping.IScope in project xtext-core by eclipse.
the class XtextLinkingService method getLinkedMetaModel.
private List<EObject> getLinkedMetaModel(TypeRef context, EReference ref, ILeafNode text) throws IllegalNodeException {
final ICompositeNode parentNode = text.getParent();
BidiIterator<INode> iterator = parentNode.getChildren().iterator();
while (iterator.hasPrevious()) {
INode child = iterator.previous();
if (child instanceof ILeafNode) {
ILeafNode leaf = (ILeafNode) child;
if (text == leaf)
return super.getLinkedObjects(context, ref, text);
if (!(leaf.getGrammarElement() instanceof Keyword) && !leaf.isHidden()) {
IScope scope = getScope(context, ref);
return XtextMetamodelReferenceHelper.findBestMetamodelForType(context, text.getText(), leaf.getText(), scope);
}
}
}
return Collections.emptyList();
}
use of org.eclipse.xtext.scoping.IScope in project xtext-core by eclipse.
the class XtextScopeProvider method createEPackageScope.
protected IScope createEPackageScope(final Grammar grammar) {
final List<Grammar> allGrammars = getAllGrammars(grammar);
IScope current = new SimpleScope(IScope.NULLSCOPE, Iterables.transform(EPackage.Registry.INSTANCE.keySet(), new Function<String, IEObjectDescription>() {
@Override
public IEObjectDescription apply(String from) {
InternalEObject proxyPackage = (InternalEObject) EcoreFactory.eINSTANCE.createEPackage();
proxyPackage.eSetProxyURI(URI.createURI(from));
return EObjectDescription.create(QualifiedName.create(from), proxyPackage, Collections.singletonMap("nsURI", "true"));
}
}));
for (int i = allGrammars.size() - 1; i >= 0; i--) {
current = createEPackageScope(allGrammars.get(i), current);
}
return current;
}
use of org.eclipse.xtext.scoping.IScope 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.scoping.IScope in project xtext-core by eclipse.
the class ImportedNamespaceAwareLocalScopeProviderTest method testImports_03.
@Test
public void testImports_03() throws Exception {
XtextResource resource = getResource(new StringInputStream("import foo.bar"), URI.createURI("import.indextestlanguage"));
resource.getResourceSet().createResource(URI.createURI("foo.indextestlanguage")).load(new StringInputStream("foo.bar { " + " entity Person { " + " String name " + " } " + " datatype String " + "}"), null);
IScope scope = scopeProvider.getScope(resource.getContents().get(0), IndexTestLanguagePackage.eINSTANCE.getFile_Elements());
List<QualifiedName> names = toListOfNames(scope.getAllElements());
assertEquals(names.toString(), 4, names.size());
assertTrue(names.contains(nameConverter.toQualifiedName("bar")));
assertTrue(names.contains(nameConverter.toQualifiedName("foo.bar")));
assertTrue(names.contains(nameConverter.toQualifiedName("foo.bar.Person")));
assertTrue(names.contains(nameConverter.toQualifiedName("foo.bar.String")));
}
use of org.eclipse.xtext.scoping.IScope 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"));
}
}));
}
Aggregations