use of ceylon.language.Sequential in project ceylon by eclipse.
the class ClassOrInterfaceImpl method getDeclaredMethods.
@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::Method<Container,Type,Arguments>>")
public <Container, Type, Arguments extends Sequential<? extends Object>> ceylon.language.Sequential<? extends ceylon.language.meta.model.Method<? super Container, ? extends Type, ? super Arguments>> getDeclaredMethods(@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 FunctionDeclaration> declaredDeclarations = declaration.<FunctionDeclaration>declaredMemberDeclarations(FunctionDeclaration.$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.Method.class, $reifiedContainer, $reifiedType, $reifiedArguments);
ArrayList<ceylon.language.meta.model.Method<? super Container, ? extends Type, ? super Arguments>> members = new ArrayList<ceylon.language.meta.model.Method<? super Container, ? extends Type, ? super Arguments>>((int) declaredDeclarations.getSize());
while ((it = iterator.next()) != finished_.get_()) {
FunctionDeclarationImpl decl = (FunctionDeclarationImpl) it;
// skip generic functions
if (!decl.getTypeParameterDeclarations().getEmpty())
continue;
// ATM this is an AND WRT annotation types: all must be present
if (!Metamodel.hasAllAnnotations(decl, annotationTypeDescriptors))
continue;
addMethodIfCompatible($reifiedContainer, $reifiedType, $reifiedArguments, members, decl, producedType, (ClassOrInterfaceImpl<Container>) this, reifiedType, reifiedArguments);
}
ceylon.language.meta.model.Method[] array = members.toArray(new ceylon.language.meta.model.Method[0]);
ObjectArrayIterable<ceylon.language.meta.model.Method> iterable = new ObjectArrayIterable<ceylon.language.meta.model.Method>(reifiedKind, array);
return (ceylon.language.Sequential) iterable.sequence();
}
use of ceylon.language.Sequential in project ceylon by eclipse.
the class ClassOrInterfaceImpl method getInterfaces.
@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>> getInterfaces(@Ignore TypeDescriptor $reifiedContainer, @Ignore TypeDescriptor $reifiedType, @Sequenced ceylon.language.Sequential<? extends ceylon.language.meta.model.Type<? extends java.lang.annotation.Annotation>> annotations) {
checkInit();
Sequential<? extends InterfaceDeclaration> declaredDeclarations = declaration.<InterfaceDeclaration>memberDeclarations(InterfaceDeclaration.$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);
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;
MemberLookup<InterfaceDeclarationImpl, Container> lookup = lookupMember(InterfaceDeclarationImpl.$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;
addInterfaceIfCompatible($reifiedContainer, $reifiedType, members, lookup.declaration, lookup.qualifyingType, lookup.containerMetamodel, 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 ceylon.language.Sequential 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 ceylon.language.Sequential in project ceylon by eclipse.
the class Metamodel method getAppliedMetamodelSequential.
@SuppressWarnings({ "unchecked", "rawtypes" })
public static Sequential<? extends ceylon.language.meta.model.Type<? extends Object>> getAppliedMetamodelSequential(List<Type> types) {
if (types.isEmpty())
return (Sequential<? extends ceylon.language.meta.model.Type<? extends Object>>) (Sequential) empty_.get_();
ceylon.language.meta.model.Type<?>[] ret = new ceylon.language.meta.model.Type[types.size()];
int i = 0;
for (Type pt : types) {
ret[i++] = Metamodel.getAppliedMetamodel(pt);
}
return Util.sequentialWrapper(TypeDescriptor.klass(ceylon.language.meta.model.Type.class, Anything.$TypeDescriptor$), ret);
}
use of ceylon.language.Sequential 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