Search in sources :

Example 11 with ObjectArrayIterable

use of org.eclipse.ceylon.compiler.java.language.ObjectArrayIterable 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 12 with ObjectArrayIterable

use of org.eclipse.ceylon.compiler.java.language.ObjectArrayIterable 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 13 with ObjectArrayIterable

use of org.eclipse.ceylon.compiler.java.language.ObjectArrayIterable 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 14 with ObjectArrayIterable

use of org.eclipse.ceylon.compiler.java.language.ObjectArrayIterable in project ceylon by eclipse.

the class ModuleImpl method getDependencies.

@Override
@TypeInfo("ceylon.language::Sequential<ceylon.language.meta.declaration::Import>")
public Sequential<? extends Import> getDependencies() {
    // no need to synchronise as concurrent invocations should get the same array back
    if (this.dependencies == null) {
        List<org.eclipse.ceylon.model.typechecker.model.ModuleImport> modelImports = declaration.getImports();
        // FreeImport[] imports = new FreeImport[modelImports.size()];
        ArrayList<ImportImpl> sb = new ArrayList<ImportImpl>(modelImports.size());
        for (org.eclipse.ceylon.model.typechecker.model.ModuleImport moduleImport : modelImports) {
            sb.add(new ImportImpl(this, moduleImport));
        }
        ImportImpl[] array = sb.toArray(new ImportImpl[0]);
        this.dependencies = new ObjectArrayIterable<ImportImpl>(Import.$TypeDescriptor$, array).sequence();
    }
    return this.dependencies;
}
Also used : ArrayList(java.util.ArrayList) ObjectArrayIterable(org.eclipse.ceylon.compiler.java.language.ObjectArrayIterable) Metamodel(org.eclipse.ceylon.compiler.java.runtime.metamodel.Metamodel) ImportImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ImportImpl) TypeInfo(org.eclipse.ceylon.compiler.java.metadata.TypeInfo)

Aggregations

ObjectArrayIterable (org.eclipse.ceylon.compiler.java.language.ObjectArrayIterable)14 ArrayList (java.util.ArrayList)13 Sequential (ceylon.language.Sequential)12 Metamodel (org.eclipse.ceylon.compiler.java.runtime.metamodel.Metamodel)11 TypeInfo (org.eclipse.ceylon.compiler.java.metadata.TypeInfo)10 TypeDescriptor (org.eclipse.ceylon.compiler.java.runtime.model.TypeDescriptor)9 TypeParameters (org.eclipse.ceylon.compiler.java.metadata.TypeParameters)8 ReifiedType (org.eclipse.ceylon.compiler.java.runtime.model.ReifiedType)6 ClassDeclarationImpl (org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassDeclarationImpl)4 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)4 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)3 CallableConstructorDeclaration (ceylon.language.meta.declaration.CallableConstructorDeclaration)2 ClassDeclaration (ceylon.language.meta.declaration.ClassDeclaration)2 ClassOrInterfaceDeclaration (ceylon.language.meta.declaration.ClassOrInterfaceDeclaration)2 FunctionDeclaration (ceylon.language.meta.declaration.FunctionDeclaration)2 InterfaceDeclaration (ceylon.language.meta.declaration.InterfaceDeclaration)2 ValueConstructorDeclaration (ceylon.language.meta.declaration.ValueConstructorDeclaration)2 ValueDeclaration (ceylon.language.meta.declaration.ValueDeclaration)2 Attribute (ceylon.language.meta.model.Attribute)2 CallableConstructorDeclarationImpl (org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.CallableConstructorDeclarationImpl)2