Search in sources :

Example 1 with ValueDeclarationImpl

use of org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ValueDeclarationImpl in project ceylon by eclipse.

the class ClassOrInterfaceImpl method getAttributes.

@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>> getAttributes(@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();
    Sequential<? extends ValueDeclaration> declaredDeclarations = declaration.<ValueDeclaration>memberDeclarations(ValueDeclaration.$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 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, $reifiedContainer, $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;
        MemberLookup<ValueDeclarationImpl, Container> lookup = lookupMember(ValueDeclarationImpl.$TypeDescriptor$, $reifiedContainer, reifiedContainer, decl);
        if (lookup == null)
            continue;
        // ATM this is an AND WRT annotation types: all must be present
        if (!Metamodel.hasAllAnnotations(lookup.declaration, annotationTypeDescriptors))
            continue;
        addAttributeIfCompatible($reifiedContainer, $reifiedGet, $reifiedSet, members, lookup.declaration, lookup.qualifyingType, lookup.containerMetamodel, reifiedGet, reifiedSet);
    }
    Attribute[] array = members.toArray(new ceylon.language.meta.model.Attribute[members.size()]);
    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 2 with ValueDeclarationImpl

use of org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ValueDeclarationImpl 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 3 with ValueDeclarationImpl

use of org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ValueDeclarationImpl in project ceylon by eclipse.

the class ClassOrInterfaceImpl method getDeclaredAttribute.

@SuppressWarnings({ "unchecked" })
@Override
@TypeParameters({ @TypeParameter(value = "Container"), @TypeParameter(value = "Get"), @TypeParameter(value = "Set") })
@TypeInfo("ceylon.language.meta.model::Attribute<Container,Get,Set>|ceylon.language::Null")
public <Container, Get, Set> ceylon.language.meta.model.Attribute<Container, Get, Set> getDeclaredAttribute(@Ignore TypeDescriptor $reifiedContainer, @Ignore TypeDescriptor $reifiedGet, @Ignore TypeDescriptor $reifiedSet, String name) {
    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 ValueDeclarationImpl value = declaration.findDeclaredValue(name);
    if (value == null)
        return null;
    return value.memberApply($reifiedContainer, $reifiedGet, $reifiedSet, (ceylon.language.meta.model.Type<Container>) this);
}
Also used : ValueDeclarationImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ValueDeclarationImpl) Metamodel(org.eclipse.ceylon.compiler.java.runtime.metamodel.Metamodel) IncompatibleTypeException(ceylon.language.meta.model.IncompatibleTypeException) TypeParameters(org.eclipse.ceylon.compiler.java.metadata.TypeParameters) TypeInfo(org.eclipse.ceylon.compiler.java.metadata.TypeInfo)

Example 4 with ValueDeclarationImpl

use of org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ValueDeclarationImpl in project ceylon by eclipse.

the class ClassOrInterfaceImpl method getAttribute.

@Override
@TypeParameters({ @TypeParameter(value = "Container"), @TypeParameter(value = "Get"), @TypeParameter(value = "Set") })
@TypeInfo("ceylon.language.meta.model::Attribute<Container,Get,Set>|ceylon.language::Null")
public <Container, Get, Set> ceylon.language.meta.model.Attribute<Container, Get, Set> getAttribute(@Ignore TypeDescriptor $reifiedContainer, @Ignore TypeDescriptor $reifiedGet, @Ignore TypeDescriptor $reifiedSet, String name) {
    // checkInit();
    ValueDeclarationImpl value = declaration.findValue(name);
    if (value == null)
        return null;
    MemberLookup<ValueDeclarationImpl, Container> lookup = lookupMember(ValueDeclarationImpl.$TypeDescriptor$, $reifiedContainer, value);
    if (lookup == null)
        return null;
    return lookup.declaration.<Container, Get, Set>memberApply($reifiedContainer, $reifiedGet, $reifiedSet, lookup.containerMetamodel);
}
Also used : ValueDeclarationImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ValueDeclarationImpl) TypeParameters(org.eclipse.ceylon.compiler.java.metadata.TypeParameters) TypeInfo(org.eclipse.ceylon.compiler.java.metadata.TypeInfo)

Example 5 with ValueDeclarationImpl

use of org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ValueDeclarationImpl in project ceylon by eclipse.

the class Metamodel method getOrCreateMetamodel.

public static <R> R getOrCreateMetamodel(org.eclipse.ceylon.model.typechecker.model.Declaration declaration) {
    synchronized (getLock()) {
        Object ret = typeCheckModelToRuntimeModel.get(declaration);
        if (ret == null) {
            // make sure its module is loaded
            org.eclipse.ceylon.model.typechecker.model.Package pkg = getPackage(declaration);
            org.eclipse.ceylon.model.typechecker.model.Module mod = pkg.getModule();
            getOrCreateMetamodel(mod);
            if (declaration instanceof org.eclipse.ceylon.model.typechecker.model.Class) {
                org.eclipse.ceylon.model.typechecker.model.Class klass = (org.eclipse.ceylon.model.typechecker.model.Class) declaration;
                ret = klass.hasConstructors() || klass.hasEnumerated() || klass.isAnonymous() ? new org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassWithConstructorsDeclarationImpl(klass) : new org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassWithInitializerDeclarationImpl(klass);
            } else if (declaration instanceof org.eclipse.ceylon.model.typechecker.model.Interface) {
                org.eclipse.ceylon.model.typechecker.model.Interface interf = (org.eclipse.ceylon.model.typechecker.model.Interface) declaration;
                ret = new org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.InterfaceDeclarationImpl(interf);
            } else if (declaration instanceof org.eclipse.ceylon.model.typechecker.model.TypeAlias) {
                org.eclipse.ceylon.model.typechecker.model.TypeAlias alias = (org.eclipse.ceylon.model.typechecker.model.TypeAlias) declaration;
                ret = new org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.AliasDeclarationImpl(alias);
            } else if (declaration instanceof org.eclipse.ceylon.model.typechecker.model.Function) {
                org.eclipse.ceylon.model.typechecker.model.Function method = (org.eclipse.ceylon.model.typechecker.model.Function) declaration;
                if (method.getTypeDeclaration() instanceof org.eclipse.ceylon.model.typechecker.model.Constructor) {
                    ret = new CallableConstructorDeclarationImpl(method, (org.eclipse.ceylon.model.typechecker.model.Constructor) method.getTypeDeclaration());
                } else {
                    ret = new org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.FunctionDeclarationImpl(method);
                }
            } else if (declaration instanceof org.eclipse.ceylon.model.typechecker.model.Value) {
                org.eclipse.ceylon.model.typechecker.model.Value value = (org.eclipse.ceylon.model.typechecker.model.Value) declaration;
                if (value.getTypeDeclaration() instanceof org.eclipse.ceylon.model.typechecker.model.Constructor) {
                    ret = new ValueConstructorDeclarationImpl(value, (org.eclipse.ceylon.model.typechecker.model.Constructor) value.getTypeDeclaration());
                } else {
                    ret = new ValueDeclarationImpl(value);
                }
            } else if (declaration instanceof org.eclipse.ceylon.model.typechecker.model.Setter) {
                org.eclipse.ceylon.model.typechecker.model.Setter value = (org.eclipse.ceylon.model.typechecker.model.Setter) declaration;
                ret = new SetterDeclarationImpl(value);
            } else if (declaration instanceof org.eclipse.ceylon.model.typechecker.model.Constructor) {
                org.eclipse.ceylon.model.typechecker.model.Constructor value = (org.eclipse.ceylon.model.typechecker.model.Constructor) declaration;
                Declaration functionOrValue = value.getContainer().getDirectMember(value.getName(), null, false);
                if (functionOrValue instanceof org.eclipse.ceylon.model.typechecker.model.Function) {
                    ret = new CallableConstructorDeclarationImpl((org.eclipse.ceylon.model.typechecker.model.Function) functionOrValue, value);
                } else if (functionOrValue instanceof org.eclipse.ceylon.model.typechecker.model.Value) {
                    ret = new ValueConstructorDeclarationImpl((org.eclipse.ceylon.model.typechecker.model.Value) functionOrValue, value);
                } else if (functionOrValue == null) {
                    ret = new CallableConstructorDeclarationImpl(value, value);
                } else {
                    throw Metamodel.newModelError("Declaration type not supported yet: " + declaration);
                }
            } else {
                throw Metamodel.newModelError("Declaration type not supported yet: " + declaration);
            }
            typeCheckModelToRuntimeModel.put(declaration, ret);
        }
        return (R) ret;
    }
}
Also used : ValueDeclarationImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ValueDeclarationImpl) CallableConstructorDeclarationImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.CallableConstructorDeclarationImpl) ClassOrInterfaceDeclarationImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassOrInterfaceDeclarationImpl) Function(org.eclipse.ceylon.model.typechecker.model.Function) LazyFunction(org.eclipse.ceylon.model.loader.model.LazyFunction) ClassWithInitializerDeclarationImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassWithInitializerDeclarationImpl) Function(org.eclipse.ceylon.model.typechecker.model.Function) Metamodel(org.eclipse.ceylon.compiler.java.runtime.metamodel.Metamodel) CallableConstructorDeclaration(ceylon.language.meta.declaration.CallableConstructorDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) ValueConstructorDeclaration(ceylon.language.meta.declaration.ValueConstructorDeclaration) NestableDeclaration(ceylon.language.meta.declaration.NestableDeclaration) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) AnnotatedDeclaration(ceylon.language.meta.declaration.AnnotatedDeclaration) SetterDeclarationImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.SetterDeclarationImpl) Constructor(java.lang.reflect.Constructor) LazyTypeAlias(org.eclipse.ceylon.model.loader.model.LazyTypeAlias) ValueConstructorDeclarationImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ValueConstructorDeclarationImpl) LazyValue(org.eclipse.ceylon.model.loader.model.LazyValue) Setter(org.eclipse.ceylon.model.typechecker.model.Setter) AnnotationProxyClass(org.eclipse.ceylon.model.loader.model.AnnotationProxyClass) ReflectionClass(org.eclipse.ceylon.model.loader.impl.reflect.mirror.ReflectionClass) LazyClass(org.eclipse.ceylon.model.loader.model.LazyClass) Setter(org.eclipse.ceylon.model.typechecker.model.Setter) FunctionOrValueInterface(org.eclipse.ceylon.model.loader.model.FunctionOrValueInterface) ClassOrInterface(ceylon.language.meta.model.ClassOrInterface) LazyInterface(org.eclipse.ceylon.model.loader.model.LazyInterface)

Aggregations

ValueDeclarationImpl (org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ValueDeclarationImpl)5 TypeInfo (org.eclipse.ceylon.compiler.java.metadata.TypeInfo)4 TypeParameters (org.eclipse.ceylon.compiler.java.metadata.TypeParameters)4 Metamodel (org.eclipse.ceylon.compiler.java.runtime.metamodel.Metamodel)4 Sequential (ceylon.language.Sequential)2 ValueDeclaration (ceylon.language.meta.declaration.ValueDeclaration)2 Attribute (ceylon.language.meta.model.Attribute)2 ArrayList (java.util.ArrayList)2 ObjectArrayIterable (org.eclipse.ceylon.compiler.java.language.ObjectArrayIterable)2 TypeDescriptor (org.eclipse.ceylon.compiler.java.runtime.model.TypeDescriptor)2 AnnotatedDeclaration (ceylon.language.meta.declaration.AnnotatedDeclaration)1 CallableConstructorDeclaration (ceylon.language.meta.declaration.CallableConstructorDeclaration)1 NestableDeclaration (ceylon.language.meta.declaration.NestableDeclaration)1 ValueConstructorDeclaration (ceylon.language.meta.declaration.ValueConstructorDeclaration)1 ClassOrInterface (ceylon.language.meta.model.ClassOrInterface)1 IncompatibleTypeException (ceylon.language.meta.model.IncompatibleTypeException)1 Constructor (java.lang.reflect.Constructor)1 CallableConstructorDeclarationImpl (org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.CallableConstructorDeclarationImpl)1 ClassOrInterfaceDeclarationImpl (org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassOrInterfaceDeclarationImpl)1 ClassWithInitializerDeclarationImpl (org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassWithInitializerDeclarationImpl)1