use of org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassDeclarationImpl in project ceylon by eclipse.
the class ClassImpl method getCaseValues.
@Override
@TypeInfo("ceylon.language::Sequential<Type>")
public ceylon.language.Sequential<? extends Type> getCaseValues() {
Class classDecl = (Class) declaration.declaration;
if (classDecl.hasEnumerated()) {
// can only possibly have value constructor cases
if (classDecl.getCaseTypes() == null || classDecl.getCaseTypes().isEmpty()) {
// it's not a closed enum of value constructors
return (Sequential) empty_.get_();
}
ArrayList<Type> ctors = new ArrayList<>();
for (ceylon.language.meta.declaration.Declaration d : ((ClassDeclarationImpl) declaration).constructors()) {
Declaration dd = null;
if (d instanceof CallableConstructorDeclarationImpl) {
continue;
} else if (d instanceof ValueConstructorDeclarationImpl) {
dd = ((ValueConstructorDeclarationImpl) d).declaration;
}
// ATM this is an AND WRT annotation types: all must be present
ctors.add(((ValueConstructor<Type>) getDeclaredConstructor(TypeDescriptor.NothingType, d.getName())).get());
}
Object[] array = ctors.toArray(new Object[ctors.size()]);
ObjectArrayIterable<ceylon.language.meta.declaration.Declaration> iterable = new ObjectArrayIterable<ceylon.language.meta.declaration.Declaration>(this.$reifiedType, (Object[]) array);
return (ceylon.language.Sequential) iterable.sequence();
} else {
return super.getCaseValues();
}
}
use of org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassDeclarationImpl in project ceylon by eclipse.
the class ClassOrInterfaceImpl method getDeclaredClasses.
@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>> getDeclaredClasses(@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();
// 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 ClassDeclaration> declaredDeclarations = declaration.<ClassDeclaration>declaredMemberDeclarations(ClassDeclaration.$TypeDescriptor$);
if (declaredDeclarations.getEmpty())
return (ceylon.language.Sequential) empty_.get_();
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;
// 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;
addClassIfCompatible($reifiedContainer, $reifiedType, $reifiedArguments, members, decl, producedType, (ClassOrInterfaceImpl<Container>) this, 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();
}
use of org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassDeclarationImpl in project ceylon by eclipse.
the class ClassOrInterfaceImpl method getDeclaredClass.
@SuppressWarnings({ "unchecked", "hiding" })
@Override
@TypeParameters({ @TypeParameter(value = "Container"), @TypeParameter(value = "Type"), @TypeParameter(value = "Arguments", satisfies = "ceylon.language::Sequential<ceylon.language::Anything>") })
@TypeInfo("ceylon.language.meta.model::MemberClass<Container,Type,Arguments>|ceylon.language::Null")
public <Container, Type, Arguments extends ceylon.language.Sequential<? extends java.lang.Object>> ceylon.language.meta.model.MemberClass<Container, Type, Arguments> getDeclaredClass(@Ignore TypeDescriptor $reifiedContainer, @Ignore TypeDescriptor $reifiedType, @Ignore TypeDescriptor $reifiedArguments, 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 ClassDeclarationImpl == false)
throw new IncompatibleTypeException("Specified member is not a class: " + name);
return ((ClassDeclarationImpl) type).memberClassApply($reifiedContainer, $reifiedType, $reifiedArguments, (ceylon.language.meta.model.Type<Container>) this, types);
}
use of org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassDeclarationImpl in project ceylon by eclipse.
the class ClassOrInterfaceImpl method $getClass.
@SuppressWarnings("hiding")
@Override
@TypeParameters({ @TypeParameter(value = "Container"), @TypeParameter(value = "Type"), @TypeParameter(value = "Arguments", satisfies = "ceylon.language::Sequential<ceylon.language::Anything>") })
@TypeInfo("ceylon.language.meta.model::MemberClass<Container,Type,Arguments>|ceylon.language::Null")
public <Container, Type, Arguments extends ceylon.language.Sequential<? extends java.lang.Object>> ceylon.language.meta.model.MemberClass<Container, Type, Arguments> $getClass(@Ignore TypeDescriptor $reifiedContainer, @Ignore TypeDescriptor $reifiedType, @Ignore TypeDescriptor $reifiedArguments, String name, @Name("types") @Sequenced Sequential<? extends ceylon.language.meta.model.Type<?>> types) {
checkInit();
final ClassOrInterfaceDeclarationImpl type = declaration.findType(name);
if (type == null)
return null;
if (type instanceof ClassDeclarationImpl == false)
throw new IncompatibleTypeException("Specified member is not a class: " + name);
MemberLookup<ClassDeclarationImpl, Container> lookup = lookupMember(ClassDeclarationImpl.$TypeDescriptor$, $reifiedContainer, (ClassDeclarationImpl) type);
if (lookup == null)
return null;
return lookup.declaration.memberClassApply($reifiedContainer, $reifiedType, $reifiedArguments, lookup.containerMetamodel, types);
}
use of org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassDeclarationImpl in project ceylon by eclipse.
the class Metamodel method getConstructors.
public static <Type> Sequential getConstructors(ClassOrInterfaceImpl<Type> cls, boolean justShared, boolean callableConstructors, TypeDescriptor $reified$Arguments, ceylon.language.Sequential<? extends ceylon.language.meta.model.Type<? extends java.lang.annotation.Annotation>> annotations) {
ArrayList<Object> ctors = new ArrayList<>();
org.eclipse.ceylon.model.typechecker.model.Type reifiedArguments = $reified$Arguments == null ? null : Metamodel.getProducedType($reified$Arguments);
TypeDescriptor[] annotationTypeDescriptors = Metamodel.getTypeDescriptors(annotations);
if (cls.declaration instanceof ClassWithInitializerDeclarationImpl) {
Reference producedReference = cls.declaration.declaration.appliedReference(cls.producedType, Collections.<org.eclipse.ceylon.model.typechecker.model.Type>emptyList());
org.eclipse.ceylon.model.typechecker.model.Type argumentsType = Metamodel.getProducedTypeForArguments(cls.declaration.declaration.getUnit(), (Functional) cls.declaration.declaration, producedReference);
if (reifiedArguments == null || reifiedArguments.isSubtypeOf(argumentsType)) {
if (hasAllAnnotations(((ClassWithInitializerDeclarationImpl) cls.declaration).getDefaultConstructor(), annotationTypeDescriptors)) {
// TODO test for arguments too
// ctors.add(new AppliedInitializer((AppliedClass)cls));
ctors.add(((ClassModel<?, ?>) cls).getDefaultConstructor());
}
}
} else {
for (ceylon.language.meta.declaration.Declaration d : ((ClassDeclarationImpl) cls.declaration).constructors()) {
Declaration dd = null;
AnnotatedDeclaration annotated;
if (d instanceof CallableConstructorDeclarationImpl && callableConstructors) {
dd = ((CallableConstructorDeclarationImpl) d).declaration;
annotated = (CallableConstructorDeclaration) d;
} else if (d instanceof ValueConstructorDeclarationImpl && !callableConstructors) {
dd = ((ValueConstructorDeclarationImpl) d).declaration;
annotated = (ValueConstructorDeclaration) d;
} else {
continue;
}
// ATM this is an AND WRT annotation types: all must be present
if (!hasAllAnnotations(annotated, annotationTypeDescriptors))
continue;
if (dd instanceof Functional && reifiedArguments != null) {
// CallableConstructor need a check on the <Arguments>
Reference producedReference = dd.appliedReference(cls.producedType, Collections.<org.eclipse.ceylon.model.typechecker.model.Type>emptyList());
org.eclipse.ceylon.model.typechecker.model.Type argumentsType = Metamodel.getProducedTypeForArguments(dd.getUnit(), (Functional) dd, producedReference);
if (!reifiedArguments.isSubtypeOf(argumentsType))
continue;
}
// ATM this is an AND WRT annotation types: all must be present
if (!Metamodel.hasAllAnnotations((AnnotatedDeclaration) d, annotationTypeDescriptors))
continue;
if (dd instanceof Functional && reifiedArguments != null) {
// CallableConstructor need a check on the <Arguments>
Reference producedReference = dd.appliedReference(cls.producedType, Collections.<org.eclipse.ceylon.model.typechecker.model.Type>emptyList());
org.eclipse.ceylon.model.typechecker.model.Type argumentsType = Metamodel.getProducedTypeForArguments(dd.getUnit(), (Functional) dd, producedReference);
if (!reifiedArguments.isSubtypeOf(argumentsType))
continue;
}
if (!justShared || (d instanceof NestableDeclaration && ((NestableDeclaration) d).getShared())) {
Object ctor;
if (cls instanceof ClassImpl<?, ?>) {
ctor = ((ClassImpl<?, ?>) cls).getDeclaredConstructor(TypeDescriptor.NothingType, d.getName());
} else {
// if (cls instanceof AppliedMemberClass<?,?,?>) {
ctor = ((MemberClassImpl<?, ?, ?>) cls).getDeclaredConstructor(TypeDescriptor.NothingType, d.getName());
}
ctors.add(ctor);
}
}
}
Object[] array = ctors.toArray(new Object[ctors.size()]);
ObjectArrayIterable<ceylon.language.meta.declaration.Declaration> iterable = new ObjectArrayIterable<ceylon.language.meta.declaration.Declaration>(TypeDescriptor.union(TypeDescriptor.klass(FunctionModel.class, cls.$reifiedType, TypeDescriptor.NothingType), TypeDescriptor.klass(ValueModel.class, cls.$reifiedType, TypeDescriptor.NothingType)), (Object[]) array);
return (ceylon.language.Sequential) iterable.sequence();
}
Aggregations