use of org.eclipse.ceylon.model.loader.model.FunctionOrValueInterface in project ceylon by eclipse.
the class Metamodel method getTypeDescriptorForProducedType.
public static TypeDescriptor getTypeDescriptorForProducedType(org.eclipse.ceylon.model.typechecker.model.Type type) {
TypeDeclaration declaration = type.getDeclaration();
if (type.isNothing()) {
return TypeDescriptor.NothingType;
}
if (type.isUnion()) {
TypeDescriptor[] tdArgs = getTypeDescriptorsForProducedTypes(type.getCaseTypes());
return TypeDescriptor.union(tdArgs);
}
if (type.isIntersection()) {
TypeDescriptor[] tdArgs = getTypeDescriptorsForProducedTypes(type.getSatisfiedTypes());
return TypeDescriptor.intersection(tdArgs);
}
if (declaration instanceof LazyClass) {
ReflectionClass classMirror = (ReflectionClass) ((LazyClass) declaration).classMirror;
TypeDescriptor[] tdArgs = getTypeDescriptorsForProducedTypes(type.getTypeArgumentList());
TypeDescriptor ret = TypeDescriptor.klass(classMirror.klass, tdArgs);
if (type.getQualifyingType() != null)
return TypeDescriptor.member(getTypeDescriptorForProducedType(type.getQualifyingType()), ret);
return ret;
}
if (declaration instanceof LazyInterface) {
ReflectionClass classMirror = (ReflectionClass) ((LazyInterface) declaration).classMirror;
TypeDescriptor[] tdArgs = getTypeDescriptorsForProducedTypes(type.getTypeArgumentList());
TypeDescriptor ret = TypeDescriptor.klass(classMirror.klass, tdArgs);
if (type.getQualifyingType() != null)
return TypeDescriptor.member(getTypeDescriptorForProducedType(type.getQualifyingType()), ret);
return ret;
}
if (declaration instanceof FunctionOrValueInterface) {
TypedDeclaration underlyingDeclaration = ((FunctionOrValueInterface) declaration).getUnderlyingDeclaration();
TypeDescriptor[] tdArgs = getTypeDescriptorsForProducedTypes(type.getTypeArgumentList());
TypeDescriptor ret;
if (underlyingDeclaration.isToplevel()) {
ReflectionClass classMirror;
// type arguments
if (underlyingDeclaration instanceof Setter)
underlyingDeclaration = ((Setter) underlyingDeclaration).getGetter();
if (underlyingDeclaration instanceof LazyValue)
classMirror = (ReflectionClass) ((LazyValue) underlyingDeclaration).classMirror;
else if (underlyingDeclaration instanceof LazyFunction)
classMirror = (ReflectionClass) ((LazyFunction) underlyingDeclaration).classMirror;
else
throw Metamodel.newModelError("Unsupported underlying declaration type: " + underlyingDeclaration);
ret = TypeDescriptor.functionOrValue(classMirror.klass, tdArgs);
} else
ret = TypeDescriptor.functionOrValue(underlyingDeclaration.getPrefixedName(), tdArgs);
if (type.getQualifyingType() != null)
return TypeDescriptor.member(getTypeDescriptorForProducedType(type.getQualifyingType()), ret);
return ret;
}
if (declaration instanceof UnknownType) {
((UnknownType) declaration).reportErrors();
}
throw Metamodel.newModelError("Unsupported declaration type: " + (declaration == null ? "null" : declaration.getClass()));
}
use of org.eclipse.ceylon.model.loader.model.FunctionOrValueInterface in project ceylon by eclipse.
the class TypeParser method loadType.
private Type loadType(String pkg, String fullName, Part part, Type qualifyingType) {
// try to find a qualified type
try {
Declaration newDeclaration;
if (qualifyingType == null) {
// FIXME: this only works for packages not contained in multiple modules
Package foundPackage = moduleScope.getPackage(pkg);
if (foundPackage != null)
newDeclaration = loader.getDeclaration(foundPackage.getModule(), pkg, fullName, scope);
else if (scope != null && !pkg.isEmpty() && loader.isDynamicMetamodel()) {
// try the default module, damnit
newDeclaration = loader.getDeclaration(loader.getLoadedModule(Module.DEFAULT_MODULE_NAME, null), pkg, fullName, scope);
} else if (scope != null) {
// if we did not find any package and the scope is null, chances are we're after a type variable
// or a relative type, so use the module scope
newDeclaration = loader.getDeclaration(moduleScope, pkg, fullName, scope);
} else
newDeclaration = null;
} else {
// look it up via its qualifying type or decl
Declaration qualifyingDeclaration = qualifyingType.getDeclaration();
if (qualifyingType.isUnion() || qualifyingType.isIntersection()) {
newDeclaration = qualifyingDeclaration.getMember(part.name, null, false);
} else {
if (qualifyingDeclaration instanceof FunctionOrValueInterface)
qualifyingDeclaration = ((FunctionOrValueInterface) qualifyingDeclaration).getUnderlyingDeclaration();
newDeclaration = AbstractModelLoader.getDirectMember((Scope) qualifyingDeclaration, part.name);
}
if (newDeclaration == null)
throw new ModelResolutionException("Failed to resolve inner type or declaration " + part.name + " in " + qualifyingDeclaration.getQualifiedNameString());
}
if (newDeclaration == null)
return null;
TypeDeclaration newTypeDeclaration;
if (newDeclaration instanceof TypeDeclaration)
newTypeDeclaration = (TypeDeclaration) newDeclaration;
else
newTypeDeclaration = new FunctionOrValueInterface((TypedDeclaration) newDeclaration);
Type ret = newTypeDeclaration.appliedType(qualifyingType, part.getParameters());
// set the use-site variance if required, now that we know the TypeParameter declarations
if (!part.getVariance().isEmpty()) {
List<TypeParameter> tps = newTypeDeclaration.getTypeParameters();
List<SiteVariance> variance = part.getVariance();
for (int i = 0, l1 = tps.size(), l2 = variance.size(); i < l1 && i < l2; i++) {
SiteVariance siteVariance = variance.get(i);
if (siteVariance != null) {
ret.setVariance(tps.get(i), siteVariance);
}
}
}
return ret;
} catch (ModelResolutionException x) {
// - if we have type parameters we must have a type
if (qualifyingType != null || (part.parameters != null && !part.parameters.isEmpty()))
throw x;
return null;
}
}
Aggregations