use of org.eclipse.ceylon.compiler.java.runtime.model.ReifiedType in project ceylon by eclipse.
the class ClassOrInterfaceImpl method getDeclaredInterfaces.
@SuppressWarnings({ "unchecked", "rawtypes", "hiding" })
@Override
@TypeParameters({ @TypeParameter(value = "Container"), @TypeParameter(value = "Type") })
@TypeInfo("ceylon.language::Sequential<ceylon.language.meta.model::MemberInterface<Container,Type>>")
public <Container, Type> ceylon.language.Sequential<? extends ceylon.language.meta.model.MemberInterface<? super Container, ? extends Type>> getDeclaredInterfaces(@Ignore TypeDescriptor $reifiedContainer, @Ignore TypeDescriptor $reifiedType, @Sequenced ceylon.language.Sequential<? extends ceylon.language.meta.model.Type<? extends java.lang.annotation.Annotation>> annotations) {
checkInit();
// check the container type first
org.eclipse.ceylon.model.typechecker.model.Type reifiedContainer = Metamodel.getProducedType($reifiedContainer);
if (!reifiedContainer.isSubtypeOf(this.producedType))
return (ceylon.language.Sequential) empty_.get_();
Sequential<? extends InterfaceDeclaration> declaredDeclarations = declaration.<InterfaceDeclaration>declaredMemberDeclarations(InterfaceDeclaration.$TypeDescriptor$);
if (declaredDeclarations.getEmpty())
return (ceylon.language.Sequential) empty_.get_();
org.eclipse.ceylon.model.typechecker.model.Type reifiedType = Metamodel.getProducedType($reifiedType);
Iterator<?> iterator = declaredDeclarations.iterator();
Object it;
TypeDescriptor[] annotationTypeDescriptors = Metamodel.getTypeDescriptors(annotations);
TypeDescriptor reifiedKind = TypeDescriptor.klass(ceylon.language.meta.model.MemberInterface.class, $reifiedContainer, $reifiedType);
ArrayList<ceylon.language.meta.model.MemberInterface<? super Container, ? extends Type>> members = new ArrayList<ceylon.language.meta.model.MemberInterface<? super Container, ? extends Type>>((int) declaredDeclarations.getSize());
while ((it = iterator.next()) != finished_.get_()) {
InterfaceDeclarationImpl decl = (InterfaceDeclarationImpl) it;
// skip generic classes
if (!decl.getTypeParameterDeclarations().getEmpty())
continue;
// ATM this is an AND WRT annotation types: all must be present
if (!Metamodel.hasAllAnnotations(decl, annotationTypeDescriptors))
continue;
addInterfaceIfCompatible($reifiedContainer, $reifiedType, members, decl, producedType, (ClassOrInterfaceImpl<Container>) this, reifiedType);
}
ceylon.language.meta.model.MemberInterface[] array = members.toArray(new ceylon.language.meta.model.MemberInterface[0]);
ObjectArrayIterable<ceylon.language.meta.model.MemberInterface> iterable = new ObjectArrayIterable<ceylon.language.meta.model.MemberInterface>(reifiedKind, array);
return (ceylon.language.Sequential) iterable.sequence();
}
use of org.eclipse.ceylon.compiler.java.runtime.model.ReifiedType 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.compiler.java.runtime.model.ReifiedType in project ceylon by eclipse.
the class Metamodel method isReified.
/**
* Implementation of {@code is} operator
*/
public static boolean isReified(java.lang.Object instance, TypeDescriptor type) {
if (instance == null) {
return type.containsNull();
}
TypeDescriptor instanceType = getTypeDescriptor(instance);
if (instanceType == null) {
return false;
}
if (instanceType == type) {
return true;
}
boolean result = type.is(instanceType);
if (!result && // we lack reified types
!(instance instanceof ReifiedType) && // we're testing for a generic type
type instanceof TypeDescriptor.Class && ((TypeDescriptor.Class) type).isGeneric() && // the instance is an instance of the base type
((TypeDescriptor.Class) type).getKlass().isInstance(instance) && // the type isn't reified by inheritance
!reifiedByInheritance(instance.getClass(), ((TypeDescriptor.Class) type).getKlass())) {
// throw when asked if an instance of a Java class is
// of a generic type and we don't have sufficient information to
// answer correctly.
// note we do this only if the isSubtypeOf() test fails
// that's so that we don't have to worry about type applications
// such as like <out Anything> which is true even in the absence
// of reified type arguments
// throw new ReifiedTypeError("Cannot determine whether " + instance.getClass() + " is a " + type);
// I can do it in Java, so what the hell ;-)
result = true;
}
return result;
}
use of org.eclipse.ceylon.compiler.java.runtime.model.ReifiedType in project ceylon by eclipse.
the class ClassOrInterfaceImpl method getDeclaredInterface.
@SuppressWarnings({ "unchecked", "hiding" })
@Override
@TypeParameters({ @TypeParameter(value = "Container"), @TypeParameter(value = "Type") })
@TypeInfo("ceylon.language.meta.model::MemberInterface<Container,Type>|ceylon.language::Null")
public <Container, Type> ceylon.language.meta.model.MemberInterface<Container, Type> getDeclaredInterface(@Ignore TypeDescriptor $reifiedContainer, @Ignore TypeDescriptor $reifiedType, String name, @Name("types") @Sequenced Sequential<? extends ceylon.language.meta.model.Type<?>> types) {
checkInit();
// do not return the attribute if the container is not a subtype of this type
org.eclipse.ceylon.model.typechecker.model.Type reifiedContainer = Metamodel.getProducedType($reifiedContainer);
if (!reifiedContainer.isSubtypeOf(producedType))
throw new IncompatibleTypeException("Specified container type '" + reifiedContainer.asString() + "' is not a valid subtype of this type");
final ClassOrInterfaceDeclarationImpl type = declaration.findDeclaredType(name);
if (type == null)
return null;
if (type instanceof InterfaceDeclarationImpl == false)
throw new IncompatibleTypeException("Specified member is not an interface: " + name);
return (ceylon.language.meta.model.MemberInterface<Container, Type>) type.memberApply($reifiedContainer, $reifiedType, (ceylon.language.meta.model.Type<Container>) this, types);
}
use of org.eclipse.ceylon.compiler.java.runtime.model.ReifiedType in project ceylon by eclipse.
the class ClassOrInterfaceImpl method getClasses.
@SuppressWarnings({ "unchecked", "rawtypes", "hiding" })
@Override
@TypeParameters({ @TypeParameter(value = "Container"), @TypeParameter(value = "Type"), @TypeParameter(value = "Arguments", satisfies = "ceylon.language::Sequential<ceylon.language::Anything>") })
@TypeInfo("ceylon.language::Sequential<ceylon.language.meta.model::MemberClass<Container,Type,Arguments>>")
public <Container, Type, Arguments extends Sequential<? extends Object>> ceylon.language.Sequential<? extends ceylon.language.meta.model.MemberClass<? super Container, ? extends Type, ? super Arguments>> getClasses(@Ignore TypeDescriptor $reifiedContainer, @Ignore TypeDescriptor $reifiedType, @Ignore TypeDescriptor $reifiedArguments, @Sequenced ceylon.language.Sequential<? extends ceylon.language.meta.model.Type<? extends java.lang.annotation.Annotation>> annotations) {
checkInit();
Sequential<? extends ClassDeclaration> declaredDeclarations = declaration.<ClassDeclaration>memberDeclarations(ClassDeclaration.$TypeDescriptor$);
if (declaredDeclarations.getEmpty())
return (ceylon.language.Sequential) empty_.get_();
org.eclipse.ceylon.model.typechecker.model.Type reifiedContainer = Metamodel.getProducedType($reifiedContainer);
org.eclipse.ceylon.model.typechecker.model.Type reifiedType = Metamodel.getProducedType($reifiedType);
org.eclipse.ceylon.model.typechecker.model.Type reifiedArguments = Metamodel.getProducedType($reifiedArguments);
Iterator<?> iterator = declaredDeclarations.iterator();
Object it;
TypeDescriptor[] annotationTypeDescriptors = Metamodel.getTypeDescriptors(annotations);
TypeDescriptor reifiedKind = TypeDescriptor.klass(ceylon.language.meta.model.MemberClass.class, $reifiedContainer, $reifiedType, $reifiedArguments);
ArrayList<ceylon.language.meta.model.MemberClass<? super Container, ? extends Type, ? super Arguments>> members = new ArrayList<ceylon.language.meta.model.MemberClass<? super Container, ? extends Type, ? super Arguments>>((int) declaredDeclarations.getSize());
while ((it = iterator.next()) != finished_.get_()) {
ClassDeclarationImpl decl = (ClassDeclarationImpl) it;
MemberLookup<ClassDeclarationImpl, Container> lookup = lookupMember(ClassDeclarationImpl.$TypeDescriptor$, $reifiedContainer, reifiedContainer, decl);
if (lookup == null)
continue;
// skip generic classes
if (!lookup.declaration.getTypeParameterDeclarations().getEmpty())
continue;
// ATM this is an AND WRT annotation types: all must be present
if (!Metamodel.hasAllAnnotations(lookup.declaration, annotationTypeDescriptors))
continue;
addClassIfCompatible($reifiedContainer, $reifiedType, $reifiedArguments, members, lookup.declaration, lookup.qualifyingType, lookup.containerMetamodel, reifiedType, reifiedArguments);
}
ceylon.language.meta.model.MemberClass[] array = members.toArray(new ceylon.language.meta.model.MemberClass[0]);
ObjectArrayIterable<ceylon.language.meta.model.MemberClass> iterable = new ObjectArrayIterable<ceylon.language.meta.model.MemberClass>(reifiedKind, array);
return (ceylon.language.Sequential) iterable.sequence();
}
Aggregations