use of org.eclipse.ceylon.model.typechecker.model.UnknownType in project ceylon by eclipse.
the class ExpressionVisitor method defaultType.
private Type defaultType() {
TypeDeclaration ut = new UnknownType(unit);
Class ad = unit.getAnythingDeclaration();
if (ad != null) {
ut.setExtendedType(ad.getType());
}
return ut.getType();
}
use of org.eclipse.ceylon.model.typechecker.model.UnknownType in project ceylon by eclipse.
the class Metamodel method getAppliedMetamodel.
@SuppressWarnings({ "rawtypes", "unchecked" })
@NonNull
public static <T> ceylon.language.meta.model.Type<T> getAppliedMetamodel(Type pt) {
TypeDeclaration declaration = pt.getDeclaration();
if (declaration instanceof org.eclipse.ceylon.model.typechecker.model.Constructor) {
org.eclipse.ceylon.model.typechecker.model.Constructor ctorDeclaration = (org.eclipse.ceylon.model.typechecker.model.Constructor) declaration;
Type ctorType = pt;
pt = pt.getExtendedType();
declaration = pt.getDeclaration();
TypeDescriptor reifiedArguments;
if (!ModelUtil.isEnumeratedConstructor(ctorDeclaration) && !declaration.isAnonymous() && !isLocalType(declaration))
reifiedArguments = Metamodel.getTypeDescriptorForArguments(declaration.getUnit(), (Functional) ctorDeclaration, ctorType);
else
reifiedArguments = TypeDescriptor.NothingType;
TypeDescriptor reifiedType = getTypeDescriptorForProducedType(pt);
if (declaration.isToplevel() || isLocalType(declaration))
return new org.eclipse.ceylon.compiler.java.runtime.metamodel.meta.ClassImpl(reifiedType, reifiedArguments, pt, Metamodel.getAppliedMetamodel(pt.getQualifyingType()), null);
TypeDescriptor reifiedContainer = getTypeDescriptorForProducedType(pt.getQualifyingType());
return new org.eclipse.ceylon.compiler.java.runtime.metamodel.meta.MemberClassImpl(reifiedContainer, reifiedType, reifiedArguments, pt);
}
if (declaration instanceof org.eclipse.ceylon.model.typechecker.model.Class) {
// anonymous classes don't have parameter lists
TypeDescriptor reifiedArguments;
if (!declaration.isAnonymous() && !isLocalType(declaration))
reifiedArguments = Metamodel.getTypeDescriptorForArguments(declaration.getUnit(), (Functional) declaration, pt);
else
reifiedArguments = TypeDescriptor.NothingType;
TypeDescriptor reifiedType = getTypeDescriptorForProducedType(pt);
if (declaration.isToplevel() || isLocalType(declaration))
return new org.eclipse.ceylon.compiler.java.runtime.metamodel.meta.ClassImpl(reifiedType, reifiedArguments, pt, null, null);
// Workaround for old binaries where static members could have some qualified TDs
// but not always. If the qualifying type is missing treat it as a toplevel
org.eclipse.ceylon.model.typechecker.model.Type qt = pt.getQualifyingType();
if (qt == null && declaration.isStatic()) {
qt = ((org.eclipse.ceylon.model.typechecker.model.ClassOrInterface) declaration.getContainer()).getType();
}
TypeDescriptor reifiedContainer = getTypeDescriptorForProducedType(qt);
return new org.eclipse.ceylon.compiler.java.runtime.metamodel.meta.MemberClassImpl(reifiedContainer, reifiedType, reifiedArguments, pt);
}
if (declaration instanceof org.eclipse.ceylon.model.typechecker.model.Interface) {
TypeDescriptor reifiedType = getTypeDescriptorForProducedType(pt);
if (declaration.isToplevel() || isLocalType(declaration))
return new org.eclipse.ceylon.compiler.java.runtime.metamodel.meta.InterfaceImpl<T>(reifiedType, pt, null, null);
// Workaround for old binaries where static members could have some qualified TDs
// but not always. If the qualifying type is missing treat it as a toplevel
org.eclipse.ceylon.model.typechecker.model.Type qt = pt.getQualifyingType();
if (qt == null && declaration.isStatic()) {
qt = ((org.eclipse.ceylon.model.typechecker.model.ClassOrInterface) declaration.getContainer()).getType();
}
TypeDescriptor reifiedContainer = getTypeDescriptorForProducedType(qt);
return new org.eclipse.ceylon.compiler.java.runtime.metamodel.meta.MemberInterfaceImpl(reifiedContainer, reifiedType, pt);
}
if (declaration instanceof org.eclipse.ceylon.model.typechecker.model.UnionType) {
TypeDescriptor reifiedType = getTypeDescriptorForProducedType(pt);
return new UnionTypeImpl<T>(reifiedType, (org.eclipse.ceylon.model.typechecker.model.UnionType) declaration);
}
if (declaration instanceof org.eclipse.ceylon.model.typechecker.model.IntersectionType) {
TypeDescriptor reifiedType = getTypeDescriptorForProducedType(pt);
return new IntersectionTypeImpl<T>(reifiedType, (org.eclipse.ceylon.model.typechecker.model.IntersectionType) declaration);
}
if (declaration instanceof org.eclipse.ceylon.model.typechecker.model.NothingType) {
return (ceylon.language.meta.model.Type<T>) ceylon.language.meta.model.nothingType_.get_();
}
if (declaration instanceof UnknownType) {
((UnknownType) declaration).reportErrors();
}
throw Metamodel.newModelError("Declaration type not supported yet: " + declaration);
}
use of org.eclipse.ceylon.model.typechecker.model.UnknownType 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.typechecker.model.UnknownType in project ceylon by eclipse.
the class UnknownTypeCollector method collectUnknownTypes.
private void collectUnknownTypes(Type type, Map<Declaration, Declaration> visited) {
if (type != null) {
type = type.resolveAliases();
if (type.isUnknown()) {
UnknownType ut = (UnknownType) type.getDeclaration();
ut.reportErrors();
// don't report it twice
ut.setErrorReporter(null);
} else if (type.isUnion()) {
for (Type t : type.getCaseTypes()) {
collectUnknownTypesResolved(t, visited);
}
} else if (type.isIntersection()) {
for (Type t : type.getSatisfiedTypes()) {
collectUnknownTypesResolved(t, visited);
}
} else if (type.isUnknown() || type.isTypeParameter()) {
// do nothing
} else {
TypeDeclaration declaration = type.getDeclaration();
if (visited.put(declaration, declaration) != null)
return;
if (type.isClassOrInterface()) {
// these are not resolved
if (type.getExtendedType() != null)
collectUnknownTypes(type.getExtendedType(), visited);
for (Type t : type.getSatisfiedTypes()) collectUnknownTypes(t, visited);
}
}
}
}
use of org.eclipse.ceylon.model.typechecker.model.UnknownType in project ceylon by eclipse.
the class AbstractModelLoader method logModelResolutionException.
private Type logModelResolutionException(final String exceptionMessage, Module module, final String message) {
UnknownType.ErrorReporter errorReporter;
if (module != null && !module.isDefaultModule()) {
final StringBuilder sb = new StringBuilder();
sb.append("Error while loading the ").append(module.getNameAsString()).append("/").append(module.getVersion());
sb.append(" module:\n ");
sb.append(message);
if (exceptionMessage != null)
sb.append(":\n ").append(exceptionMessage);
errorReporter = makeModelErrorReporter(module, sb.toString());
} else if (exceptionMessage == null) {
errorReporter = makeModelErrorReporter(message);
} else {
errorReporter = makeModelErrorReporter(message + ": " + exceptionMessage);
}
UnknownType ret = new UnknownType(typeFactory);
ret.setErrorReporter(errorReporter);
return ret.getType();
}
Aggregations