use of org.eclipse.xtext.common.types.xtext.AbstractTypeScope in project xtext-xtend by eclipse.
the class XtendImportedNamespaceScopeProvider method getScope.
@Override
public IScope getScope(final EObject context, final EReference reference) {
EClass referenceType = reference.getEReferenceType();
if (TypesPackage.Literals.JVM_TYPE.isSuperTypeOf(referenceType)) {
if (context instanceof XImportDeclaration) {
Resource resource = context.eResource();
IJvmTypeProvider typeProvider = typeScopeProvider.getTypeProvider(resource.getResourceSet());
AbstractTypeScope typeScope = typeScopeProvider.createTypeScope(typeProvider, null);
IResourceDescriptions descriptions = resourceDescriptionsProvider.getResourceDescriptions(context.eResource().getResourceSet());
IResourceDescription resourceDescription = descriptions.getResourceDescription(resource.getURI());
if (resourceDescription != null) {
typeScope = new LocalResourceFilteringTypeScope(typeScope, resourceDescription);
}
RecordingTypeScope recordingTypeScope = new RecordingTypeScope(typeScope, getImportedNamesSet(resource), getQualifiedNameConverter());
// TODO this scope doesn't support binary syntax for inner types. It should be a KnownTypes scope which doesn't allow simple names
// Unfortunately I cannot use a RecordingTypeScope as a parent as it is not compatible...
IScope scope = SelectableBasedScope.createScope(recordingTypeScope, getAllDescriptions(resource), reference.getEReferenceType(), false);
return scope;
}
final XtendFile xtendFile = getXtendFile(context);
final Resource resource = xtendFile.eResource();
AbstractScope result = resourceScopeCache.get("type.scope", xtendFile.eResource(), new Provider<AbstractScope>() {
@Override
public AbstractScope get() {
IJvmTypeProvider typeProvider = typeScopeProvider.getTypeProvider(resource.getResourceSet());
AbstractTypeScope typeScope = typeScopeProvider.createTypeScope(typeProvider, null);
IResourceDescriptions descriptions = resourceDescriptionsProvider.getResourceDescriptions(context.eResource().getResourceSet());
IResourceDescription resourceDescription = descriptions.getResourceDescription(resource.getURI());
if (resourceDescription != null) {
typeScope = new LocalResourceFilteringTypeScope(typeScope, resourceDescription);
}
RecordingTypeScope recordingTypeScope = new RecordingTypeScope(typeScope, getImportedNamesSet(resource), getQualifiedNameConverter());
AbstractScope rootTypeScope = getRootTypeScope(xtendFile, recordingTypeScope);
AbstractScope importScope = getImportScope(xtendFile.getImportSection(), rootTypeScope, recordingTypeScope);
AbstractScope localTypes = getResourceTypeScope(xtendFile.eResource(), xtendFile.getPackage(), importScope);
AbstractScope primitiveAware = new PrimitiveAwareScope(localTypes, typeScope);
AbstractScope caching = new CachingTypeScope(primitiveAware);
return caching;
}
});
if (context instanceof AnonymousClass) {
// necessary for the super type of an anonymous class expression
JvmDeclaredType inferredAnonymousType = associations.getInferredType((AnonymousClass) context);
if (inferredAnonymousType != null)
result = new LocalTypeScope(singletonList(inferredAnonymousType), result);
}
XtendMember syntacticContainer = EcoreUtil2.getContainerOfType(context, XtendMember.class);
if (syntacticContainer != null) {
result = getContainerScope(syntacticContainer, result);
}
EObject logicalContainer = logicalContainerProvider.getNearestLogicalContainer(context);
if (logicalContainer != null) {
List<List<JvmTypeParameter>> typeParameters = new ArrayList<List<JvmTypeParameter>>();
while (logicalContainer instanceof JvmTypeParameterDeclarator) {
JvmTypeParameterDeclarator typeParamProvider = (JvmTypeParameterDeclarator) logicalContainer;
if (!typeParamProvider.getTypeParameters().isEmpty()) {
typeParameters.add(typeParamProvider.getTypeParameters());
}
logicalContainer = logicalContainer.eContainer();
}
if (!typeParameters.isEmpty())
result = new TypeParameterScope(typeParameters, result);
}
return result;
} else if (TypesPackage.Literals.JVM_CONSTRUCTOR.isSuperTypeOf(referenceType)) {
IScope typeScope = getScope(context, TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE);
// this is not called from the type resolution where we want to allow constructors to link to interfaces
// in order to improve the error message, therefore we use a strict wrapper here
IScope result = new ConstructorTypeScopeWrapper(context, IVisibilityHelper.ALL, typeScope, true);
return result;
} else {
throw new IllegalArgumentException("Unexpected global request for " + reference);
}
}
Aggregations