Search in sources :

Example 16 with Sequential

use of ceylon.language.Sequential in project ceylon by eclipse.

the class ClassOrInterfaceImpl method getDeclaredAttributes.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
@TypeParameters({ @TypeParameter(value = "Container"), @TypeParameter(value = "Get"), @TypeParameter(value = "Set") })
@TypeInfo("ceylon.language::Sequential<ceylon.language.meta.model::Attribute<Container,Get,Set>>")
public <Container, Get, Set> ceylon.language.Sequential<? extends ceylon.language.meta.model.Attribute<? super Container, ? extends Get, ? super Set>> getDeclaredAttributes(@Ignore TypeDescriptor $reifiedContainer, @Ignore TypeDescriptor $reifiedGet, @Ignore TypeDescriptor $reifiedSet, @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 ValueDeclaration> declaredDeclarations = declaration.<ValueDeclaration>declaredMemberDeclarations(ValueDeclaration.$TypeDescriptor$);
    if (declaredDeclarations.getEmpty())
        return (ceylon.language.Sequential) empty_.get_();
    org.eclipse.ceylon.model.typechecker.model.Type reifiedGet = Metamodel.getProducedType($reifiedGet);
    org.eclipse.ceylon.model.typechecker.model.Type reifiedSet = Metamodel.getProducedType($reifiedSet);
    Iterator<?> iterator = declaredDeclarations.iterator();
    Object it;
    TypeDescriptor[] annotationTypeDescriptors = Metamodel.getTypeDescriptors(annotations);
    TypeDescriptor reifiedKind = TypeDescriptor.klass(ceylon.language.meta.model.Attribute.class, $reifiedType, $reifiedGet, $reifiedSet);
    ArrayList<ceylon.language.meta.model.Attribute<? super Container, ? extends Get, ? super Set>> members = new ArrayList<ceylon.language.meta.model.Attribute<? super Container, ? extends Get, ? super Set>>((int) declaredDeclarations.getSize());
    while ((it = iterator.next()) != finished_.get_()) {
        ValueDeclarationImpl decl = (ValueDeclarationImpl) it;
        // ATM this is an AND WRT annotation types: all must be present
        if (!Metamodel.hasAllAnnotations(decl, annotationTypeDescriptors))
            continue;
        addAttributeIfCompatible($reifiedContainer, $reifiedGet, $reifiedSet, members, decl, this.producedType, (ceylon.language.meta.model.Type<Container>) this, reifiedGet, reifiedSet);
    }
    Attribute[] array = members.toArray(new ceylon.language.meta.model.Attribute[0]);
    ObjectArrayIterable<Attribute> iterable = new ObjectArrayIterable<ceylon.language.meta.model.Attribute>(reifiedKind, array);
    return (ceylon.language.Sequential) iterable.sequence();
}
Also used : ValueDeclarationImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ValueDeclarationImpl) Attribute(ceylon.language.meta.model.Attribute) ValueDeclaration(ceylon.language.meta.declaration.ValueDeclaration) ArrayList(java.util.ArrayList) ObjectArrayIterable(org.eclipse.ceylon.compiler.java.language.ObjectArrayIterable) TypeDescriptor(org.eclipse.ceylon.compiler.java.runtime.model.TypeDescriptor) Sequential(ceylon.language.Sequential) Metamodel(org.eclipse.ceylon.compiler.java.runtime.metamodel.Metamodel) TypeParameters(org.eclipse.ceylon.compiler.java.metadata.TypeParameters) TypeInfo(org.eclipse.ceylon.compiler.java.metadata.TypeInfo)

Example 17 with Sequential

use of ceylon.language.Sequential 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();
}
Also used : ArrayList(java.util.ArrayList) ObjectArrayIterable(org.eclipse.ceylon.compiler.java.language.ObjectArrayIterable) ReifiedType(org.eclipse.ceylon.compiler.java.runtime.model.ReifiedType) ClassDeclaration(ceylon.language.meta.declaration.ClassDeclaration) TypeDescriptor(org.eclipse.ceylon.compiler.java.runtime.model.TypeDescriptor) Sequential(ceylon.language.Sequential) ClassDeclarationImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassDeclarationImpl) Metamodel(org.eclipse.ceylon.compiler.java.runtime.metamodel.Metamodel) TypeParameters(org.eclipse.ceylon.compiler.java.metadata.TypeParameters) TypeInfo(org.eclipse.ceylon.compiler.java.metadata.TypeInfo)

Example 18 with Sequential

use of ceylon.language.Sequential in project ceylon by eclipse.

the class CallableConstructorDeclarationImpl method apply.

@Override
public <Result, Arguments extends Sequential<? extends Object>> CallableConstructor<Result, Arguments> apply(TypeDescriptor $reified$Result, TypeDescriptor $reified$Arguments, Sequential<? extends Type<? extends Object>> typeArguments) {
    // apply the given type arguments to the containing class
    ClassDeclaration clsDecl = getContainer();
    ceylon.language.meta.model.Class<? extends Result, ?> cls = clsDecl.<Result, Sequential<? extends java.lang.Object>>classApply($reified$Result, Nothing.NothingType, typeArguments);
    // then get the constructor from that
    return Util.assertExists((CallableConstructor) cls.<Arguments>getDeclaredConstructor($reified$Arguments, getName()));
}
Also used : ClassDeclaration(ceylon.language.meta.declaration.ClassDeclaration) Sequential(ceylon.language.Sequential) Metamodel(org.eclipse.ceylon.compiler.java.runtime.metamodel.Metamodel)

Example 19 with Sequential

use of ceylon.language.Sequential in project ceylon by eclipse.

the class ClassOrInterfaceDeclarationImpl method filteredMembers.

@SuppressWarnings({ "rawtypes", "unchecked" })
private <Kind> Sequential<? extends Kind> filteredMembers(@Ignore TypeDescriptor $reifiedKind, Predicates.Predicate predicate) {
    if (predicate == Predicates.false_()) {
        return (Sequential<? extends Kind>) empty_.get_();
    }
    checkInit();
    ArrayList<Kind> members = new ArrayList<Kind>(declarations.size());
    for (ceylon.language.meta.declaration.NestableDeclaration decl : declarations) {
        Declaration declaration2 = ((NestableDeclarationImpl) decl).declaration;
        if (!declaration2.isNativeHeader() && predicate.accept(declaration2)) {
            members.add((Kind) decl);
        }
    }
    java.lang.Object[] array = members.toArray(new java.lang.Object[0]);
    ObjectArrayIterable<Kind> iterable = new ObjectArrayIterable<Kind>($reifiedKind, (Kind[]) array);
    return (ceylon.language.Sequential) iterable.sequence();
}
Also used : NestableDeclarationImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.NestableDeclarationImpl) ArrayList(java.util.ArrayList) ObjectArrayIterable(org.eclipse.ceylon.compiler.java.language.ObjectArrayIterable) Sequential(ceylon.language.Sequential) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration)

Example 20 with Sequential

use of ceylon.language.Sequential in project ceylon by eclipse.

the class ClassOrInterfaceDeclarationImpl method init.

@SuppressWarnings({ "unchecked", "rawtypes" })
protected void init() {
    org.eclipse.ceylon.model.typechecker.model.ClassOrInterface declaration = (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface) this.declaration;
    Type superType = declaration.getExtendedType();
    if (superType != null)
        this.superclass = (ceylon.language.meta.declaration.OpenClassType) Metamodel.getMetamodel(superType);
    List<Type> satisfiedTypes = declaration.getSatisfiedTypes();
    ceylon.language.meta.declaration.OpenInterfaceType[] interfaces = new ceylon.language.meta.declaration.OpenInterfaceType[satisfiedTypes.size()];
    int i = 0;
    for (Type pt : satisfiedTypes) {
        interfaces[i++] = (ceylon.language.meta.declaration.OpenInterfaceType) Metamodel.getMetamodel(pt);
    }
    this.interfaces = Util.sequentialWrapper(ceylon.language.meta.declaration.OpenInterfaceType.$TypeDescriptor$, interfaces);
    if (declaration.getCaseTypes() != null)
        this.caseTypes = Metamodel.getMetamodelSequential(declaration.getCaseTypes());
    else
        this.caseTypes = (Sequential<? extends ceylon.language.meta.declaration.OpenType>) (Sequential) empty_.get_();
    this.typeParameters = Metamodel.getTypeParameters(declaration);
    List<org.eclipse.ceylon.model.typechecker.model.Declaration> memberModelDeclarations = declaration.getMembers();
    this.declaredDeclarations = new LinkedList<ceylon.language.meta.declaration.NestableDeclaration>();
    for (org.eclipse.ceylon.model.typechecker.model.Declaration memberModelDeclaration : memberModelDeclarations) {
        addDeclarationTo(memberModelDeclaration, declaredDeclarations);
    }
    Collection<org.eclipse.ceylon.model.typechecker.model.Declaration> inheritedModelDeclarations = collectMembers(declaration);
    this.declarations = new LinkedList<ceylon.language.meta.declaration.NestableDeclaration>();
    for (org.eclipse.ceylon.model.typechecker.model.Declaration memberModelDeclaration : inheritedModelDeclarations) {
        addDeclarationTo(memberModelDeclaration, declarations);
    }
}
Also used : ClassOrInterface(ceylon.language.meta.model.ClassOrInterface) OpenType(ceylon.language.meta.declaration.OpenType) Type(org.eclipse.ceylon.model.typechecker.model.Type) OpenType(ceylon.language.meta.declaration.OpenType) Sequential(ceylon.language.Sequential) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) Metamodel(org.eclipse.ceylon.compiler.java.runtime.metamodel.Metamodel) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration)

Aggregations

Sequential (ceylon.language.Sequential)21 Metamodel (org.eclipse.ceylon.compiler.java.runtime.metamodel.Metamodel)16 ArrayList (java.util.ArrayList)12 ObjectArrayIterable (org.eclipse.ceylon.compiler.java.language.ObjectArrayIterable)12 TypeInfo (org.eclipse.ceylon.compiler.java.metadata.TypeInfo)12 TypeDescriptor (org.eclipse.ceylon.compiler.java.runtime.model.TypeDescriptor)12 TypeParameters (org.eclipse.ceylon.compiler.java.metadata.TypeParameters)10 ReifiedType (org.eclipse.ceylon.compiler.java.runtime.model.ReifiedType)9 ClassDeclaration (ceylon.language.meta.declaration.ClassDeclaration)6 ClassDeclarationImpl (org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassDeclarationImpl)5 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)5 Type (org.eclipse.ceylon.model.typechecker.model.Type)5 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)4 AssertionError (ceylon.language.AssertionError)3 CallableConstructorDeclaration (ceylon.language.meta.declaration.CallableConstructorDeclaration)3 ClassOrInterfaceDeclaration (ceylon.language.meta.declaration.ClassOrInterfaceDeclaration)3 OpenType (ceylon.language.meta.declaration.OpenType)3 ValueConstructorDeclaration (ceylon.language.meta.declaration.ValueConstructorDeclaration)3 ValueDeclaration (ceylon.language.meta.declaration.ValueDeclaration)3 Attribute (ceylon.language.meta.model.Attribute)3