|
|
|
|
|
|
|
|
|
|
Re: Combining importURI and importedNamespace [message #769708 is a reply to message #769701] |
Thu, 22 December 2011 10:10   |
Eclipse User |
|
|
|
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 10:30   |
Eclipse User |
|
|
|
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;
}
}
|
|
|
|
Powered by
FUDForum. Page generated in 0.22581 seconds