|
|
|
Re: Combining importURI and importedNamespace [message #769671 is a reply to message #769649] |
Thu, 22 December 2011 14:03 |
|
Hi,
without knowledge of your metamodel(s) - is it one is it two ....
it is hard to answer such a question. so two reproducable grammars would help.
never the less have a look how global scopeproviders are used:
org.eclipse.xtext.scoping.impl.AbstractGlobalScopeDelegatingScopeProvider.getGlobalScope(Resource, EReference, Predicate<IEObjectDescription>)
maybe you should delegate here to one of both global scopeproviders
depending of the type of the ereference.
(or you combine both and take care that stuff from the imported files is not in the index)
~Christian
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
[Updated on: Thu, 22 December 2011 14:19] Report message to a moderator
|
|
|
|
|
|
|
|
|
Re: Combining importURI and importedNamespace [message #769708 is a reply to message #769701] |
Thu, 22 December 2011 15:10 |
Torsten Schiefer Messages: 26 Registered: December 2011 |
Junior Member |
|
|
Oh, I'm sorry.
Ok now I've tried the following:
public class OSImportUriGlobalScopeProvider extends ImportUriGlobalScopeProvider {
@Inject
DefaultGlobalScopeProvider provider;
//Is bound in the RuntimeModule
@Override
public IScope getScope(final Resource resource, final EReference reference,
final Predicate < IEObjectDescription > filter) {
final IScope scope = this.provider.getScope(resource, reference, filter);
return getScope(scope, resource, isIgnoreCase(reference), reference.getEReferenceType(), filter);
}
protected IScope getScope(final IScope parent, final Resource resource, final boolean ignoreCase,
final EClass type, final Predicate < IEObjectDescription > filter) {
final LinkedHashSet < URI > uniqueImportURIs = getImportedUris(resource);
final IResourceDescriptions descriptions = getResourceDescriptions(resource, uniqueImportURIs);
final List < URI > urisAsList = Lists.newArrayList(uniqueImportURIs);
Collections.reverse(urisAsList);
IScope scope = parent;
for (final URI uri : urisAsList) {
scope = createLazyResourceScope(scope, uri, descriptions, type, filter, ignoreCase);
}
return scope;
}
}
and it works.
But the scope contains all objects of the anonymousNamespaces.
So it's the same result like I would get without using the ImportUriGlobalScope.
|
|
|
Re: Combining importURI and importedNamespace [message #769717 is a reply to message #769708] |
Thu, 22 December 2011 15:30 |
|
Hi,
if you store the anon stuff to the index it is in the index.
so this is what could work
(quick and dirty try with your grammar)
public class StrangeResourceDescriptionStrategy extends
DefaultResourceDescriptionStrategy {
private final static Logger LOG = Logger.getLogger(StrangeResourceDescriptionStrategy.class);
@Override
public boolean createEObjectDescriptions(EObject eObject, IAcceptor<IEObjectDescription> acceptor) {
if (getQualifiedNameProvider() == null)
return false;
try {
QualifiedName qualifiedName = getQualifiedNameProvider().getFullyQualifiedName(eObject);
if (qualifiedName != null) {
Map<String, String> userData = new HashMap<String, String>();
if (EcoreUtil2.getContainerOfType(eObject, AnonymousNamespace.class)!=null) {
userData.put("anon", Boolean.TRUE.toString());
}
IEObjectDescription create = EObjectDescription.create(qualifiedName, eObject, userData);
acceptor.accept(create);
}
} catch (Exception exc) {
LOG.error(exc.getMessage());
}
return true;
}
}
public class OSImportUriGlobalScopeProvider extends ImportUriGlobalScopeProvider {
@Inject
DefaultGlobalScopeProvider provider;
//Is bound in the RuntimeModule
@Override
public IScope getScope(final Resource resource, final EReference reference,
final Predicate < IEObjectDescription > filter) {
Predicate<IEObjectDescription> filter2 =new Predicate<IEObjectDescription>() {
@Override
public boolean apply(IEObjectDescription d) {
return ! Boolean.TRUE.toString().equals(d.getUserData("anon"));
}
};
final IScope scope = this.provider.getScope(resource, reference, filter != null ? Predicates.and(filter, filter2) : filter2);
return getScope(scope, resource, isIgnoreCase(reference), reference.getEReferenceType(), filter);
}
protected IScope getScope(final IScope parent, final Resource resource, final boolean ignoreCase,
final EClass type, final Predicate < IEObjectDescription > filter) {
final LinkedHashSet < URI > uniqueImportURIs = getImportedUris(resource);
final IResourceDescriptions descriptions = getResourceDescriptions(resource, uniqueImportURIs);
final List < URI > urisAsList = Lists.newArrayList(uniqueImportURIs);
Collections.reverse(urisAsList);
IScope scope = parent;
for (final URI uri : urisAsList) {
scope = createLazyResourceScope(scope, uri, descriptions, type, filter, ignoreCase);
}
return scope;
}
}
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
Powered by
FUDForum. Page generated in 0.52481 seconds