Search in sources :

Example 1 with ReifiedType

use of org.eclipse.ceylon.compiler.java.runtime.model.ReifiedType in project ceylon by eclipse.

the class ClassOrInterfaceImpl method getCaseValues.

@Override
@TypeInfo("ceylon.language::Sequential<Type>")
public ceylon.language.Sequential<? extends Type> getCaseValues() {
    if (!((ClassOrInterface) declaration.declaration).isAbstract()) {
        // optimization: a concrete class cannot have cases
        return (Sequential) empty_.get_();
    }
    Sequential<? extends ceylon.language.meta.declaration.OpenType> caseTypeDeclarations = getDeclaration().getCaseTypes();
    Iterator<? extends ceylon.language.meta.declaration.OpenType> iterator = caseTypeDeclarations.iterator();
    Object it;
    Array<Type> ret = new Array<Type>($reifiedType, (int) caseTypeDeclarations.getSize(), (Type) null);
    int count = 0;
    while ((it = iterator.next()) != finished_.get_()) {
        if (it instanceof ceylon.language.meta.declaration.OpenClassType == false)
            continue;
        ceylon.language.meta.declaration.OpenClassType caseClassType = (ceylon.language.meta.declaration.OpenClassType) it;
        ceylon.language.meta.declaration.ClassDeclaration caseClass = caseClassType.getDeclaration();
        if (!caseClass.getAnonymous())
            continue;
        Type value = null;
        Object container = caseClass.getContainer();
        while (true) {
            if (container instanceof ceylon.language.meta.declaration.Package) {
                ValueDeclaration valueDeclaration = ((ceylon.language.meta.declaration.Package) container).getValue(caseClass.getName());
                ceylon.language.meta.model.Value<? extends Type, ? super Object> valueModel = valueDeclaration.<Type, Object>apply($reifiedType, TypeDescriptor.NothingType);
                value = valueModel.get();
                break;
            } else {
                if (container instanceof ClassOrInterfaceDeclaration) {
                    ValueDeclaration valueDeclaration = ((ClassOrInterfaceDeclaration) container).getMemberDeclaration(ValueDeclaration.$TypeDescriptor$, caseClass.getName());
                    Attribute a = valueDeclaration.memberApply($reifiedType, $reifiedType, Nothing.NothingType, this);
                    value = (Type) a.bind(null).get();
                }
                // other nestable decls can't contain members, so keep looking up scopes
                container = ((NestableDeclaration) container).getContainer();
            }
            if (value != null) {
                break;
            }
        }
        if (value == null && !producedType.isNull()) {
            throw new AssertionError("case " + caseClassType + " of " + this + " not found");
        }
        ret.set(count++, value);
    }
    return ret.take(count).sequence();
}
Also used : ClassOrInterfaceDeclaration(ceylon.language.meta.declaration.ClassOrInterfaceDeclaration) Attribute(ceylon.language.meta.model.Attribute) ValueDeclaration(ceylon.language.meta.declaration.ValueDeclaration) ClassDeclaration(ceylon.language.meta.declaration.ClassDeclaration) Array(ceylon.language.Array) ReifiedType(org.eclipse.ceylon.compiler.java.runtime.model.ReifiedType) Sequential(ceylon.language.Sequential) AssertionError(ceylon.language.AssertionError) Metamodel(org.eclipse.ceylon.compiler.java.runtime.metamodel.Metamodel) TypeInfo(org.eclipse.ceylon.compiler.java.metadata.TypeInfo)

Example 2 with ReifiedType

use of org.eclipse.ceylon.compiler.java.runtime.model.ReifiedType in project ceylon by eclipse.

the class ClassOrInterfaceImpl method getMethods.

@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>> getMethods(@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 FunctionDeclaration> declaredDeclarations = declaration.<FunctionDeclaration>memberDeclarations(FunctionDeclaration.$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.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;
        MemberLookup<FunctionDeclarationImpl, Container> lookup = lookupMember(FunctionDeclarationImpl.$TypeDescriptor$, $reifiedContainer, reifiedContainer, decl);
        if (lookup == null)
            continue;
        // skip generic functions
        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;
        addMethodIfCompatible($reifiedContainer, $reifiedType, $reifiedArguments, members, lookup.declaration, lookup.qualifyingType, lookup.containerMetamodel, 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();
}
Also used : ArrayList(java.util.ArrayList) ObjectArrayIterable(org.eclipse.ceylon.compiler.java.language.ObjectArrayIterable) FunctionDeclaration(ceylon.language.meta.declaration.FunctionDeclaration) ReifiedType(org.eclipse.ceylon.compiler.java.runtime.model.ReifiedType) TypeDescriptor(org.eclipse.ceylon.compiler.java.runtime.model.TypeDescriptor) Sequential(ceylon.language.Sequential) Metamodel(org.eclipse.ceylon.compiler.java.runtime.metamodel.Metamodel) FunctionDeclarationImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.FunctionDeclarationImpl) TypeParameters(org.eclipse.ceylon.compiler.java.metadata.TypeParameters) TypeInfo(org.eclipse.ceylon.compiler.java.metadata.TypeInfo)

Example 3 with ReifiedType

use of org.eclipse.ceylon.compiler.java.runtime.model.ReifiedType 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();
}
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 4 with ReifiedType

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

Example 5 with ReifiedType

use of org.eclipse.ceylon.compiler.java.runtime.model.ReifiedType 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();
}
Also used : ArrayList(java.util.ArrayList) InterfaceDeclaration(ceylon.language.meta.declaration.InterfaceDeclaration) ClassOrInterfaceDeclaration(ceylon.language.meta.declaration.ClassOrInterfaceDeclaration) InterfaceDeclarationImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.InterfaceDeclarationImpl) ClassOrInterfaceDeclarationImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassOrInterfaceDeclarationImpl) ObjectArrayIterable(org.eclipse.ceylon.compiler.java.language.ObjectArrayIterable) ReifiedType(org.eclipse.ceylon.compiler.java.runtime.model.ReifiedType) 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)

Aggregations

ReifiedType (org.eclipse.ceylon.compiler.java.runtime.model.ReifiedType)12 Metamodel (org.eclipse.ceylon.compiler.java.runtime.metamodel.Metamodel)9 TypeDescriptor (org.eclipse.ceylon.compiler.java.runtime.model.TypeDescriptor)9 Sequential (ceylon.language.Sequential)8 TypeInfo (org.eclipse.ceylon.compiler.java.metadata.TypeInfo)8 TypeParameters (org.eclipse.ceylon.compiler.java.metadata.TypeParameters)7 ArrayList (java.util.ArrayList)6 ObjectArrayIterable (org.eclipse.ceylon.compiler.java.language.ObjectArrayIterable)6 ClassDeclaration (ceylon.language.meta.declaration.ClassDeclaration)3 ClassOrInterfaceDeclaration (ceylon.language.meta.declaration.ClassOrInterfaceDeclaration)3 OpenClassOrInterfaceType (ceylon.language.meta.declaration.OpenClassOrInterfaceType)3 OpenType (ceylon.language.meta.declaration.OpenType)3 ClassOrInterfaceDeclarationImpl (org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassOrInterfaceDeclarationImpl)3 InterfaceDeclarationImpl (org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.InterfaceDeclarationImpl)3 DeclarationType (org.eclipse.ceylon.model.loader.ModelLoader.DeclarationType)3 NothingType (org.eclipse.ceylon.model.typechecker.model.NothingType)3 Type (org.eclipse.ceylon.model.typechecker.model.Type)3 FunctionDeclaration (ceylon.language.meta.declaration.FunctionDeclaration)2 InterfaceDeclaration (ceylon.language.meta.declaration.InterfaceDeclaration)2 ClassDeclarationImpl (org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassDeclarationImpl)2