Search in sources :

Example 26 with TypeInfo

use of org.eclipse.ceylon.compiler.java.metadata.TypeInfo in project ceylon by eclipse.

the class ValueDeclarationImpl method memberApply.

@TypeInfo("ceylon.language.meta.model::Attribute<Container,Get,Set>")
@TypeParameters({ @TypeParameter("Container"), @TypeParameter("Get"), @TypeParameter(value = "Set", defaultValue = "ceylon.language::Nothing") })
@Override
public <Container, Get, Set> ceylon.language.meta.model.Attribute<Container, Get, Set> memberApply(@Ignore TypeDescriptor $reifiedContainer, @Ignore TypeDescriptor $reifiedGet, @Ignore TypeDescriptor $reifiedSet, @Name("containerType") ceylon.language.meta.model.Type<? extends Object> containerType) {
    if (getToplevel())
        throw new ceylon.language.meta.model.TypeApplicationException("Cannot apply a toplevel declaration to a container type: use apply");
    Type qualifyingType = Metamodel.getModel(containerType);
    Metamodel.checkQualifyingType(qualifyingType, declaration);
    org.eclipse.ceylon.model.typechecker.model.Value modelDecl = (org.eclipse.ceylon.model.typechecker.model.Value) declaration;
    // find the proper qualifying type
    Type memberQualifyingType = qualifyingType.getSupertype((TypeDeclaration) modelDecl.getContainer());
    org.eclipse.ceylon.model.typechecker.model.TypedReference typedReference = modelDecl.appliedTypedReference(memberQualifyingType, Collections.<Type>emptyList());
    TypeDescriptor reifiedContainer = Metamodel.getTypeDescriptorForProducedType(qualifyingType);
    org.eclipse.ceylon.model.typechecker.model.Type getType = typedReference.getType();
    TypeDescriptor reifiedGet = Metamodel.getTypeDescriptorForProducedType(getType);
    // immutable values have Set=Nothing
    org.eclipse.ceylon.model.typechecker.model.Type setType = getVariable() ? getType : modelDecl.getUnit().getNothingType();
    TypeDescriptor reifiedSet = getVariable() ? reifiedGet : TypeDescriptor.NothingType;
    Metamodel.checkReifiedTypeArgument("memberApply", "Attribute<$1,$2,$3>", Variance.IN, memberQualifyingType, $reifiedContainer, Variance.OUT, getType, $reifiedGet, Variance.IN, setType, $reifiedSet);
    return new AttributeImpl<Container, Get, Set>(reifiedContainer, reifiedGet, reifiedSet, this, typedReference, containerType);
}
Also used : AttributeImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.meta.AttributeImpl) Type(org.eclipse.ceylon.model.typechecker.model.Type) Value(org.eclipse.ceylon.model.typechecker.model.Value) Type(org.eclipse.ceylon.model.typechecker.model.Type) OpenType(ceylon.language.meta.declaration.OpenType) TypeDescriptor(org.eclipse.ceylon.compiler.java.runtime.model.TypeDescriptor) Value(org.eclipse.ceylon.model.typechecker.model.Value) 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 27 with TypeInfo

use of org.eclipse.ceylon.compiler.java.metadata.TypeInfo in project ceylon by eclipse.

the class ClassImpl method getDeclaredConstructor.

@Override
@TypeParameters(@TypeParameter(value = "Arguments", satisfies = "ceylon.language::Sequential<ceylon.language::Anything>"))
@TypeInfo("ceylon.language.meta.model::CallableConstructor<Type,Arguments>|ceylon.language.meta.model::ValueConstructor<Type>|ceylon.language::Null")
public <Arguments extends Sequential<? extends Object>> java.lang.Object getDeclaredConstructor(@Ignore TypeDescriptor $reified$Arguments, @Name("name") String name) {
    checkInit();
    final ceylon.language.meta.declaration.Declaration ctor = ((ClassDeclarationImpl) declaration).getConstructorDeclaration(name);
    if (ctor == null)
        return null;
    if (ctor instanceof CallableConstructorDeclaration) {
        if (ctor instanceof ClassWithInitializerDeclarationConstructor) {
            TypeDescriptor actualReifiedArguments = Metamodel.getTypeDescriptorForArguments(declaration.declaration.getUnit(), (Functional) ((ClassWithInitializerDeclarationConstructor) ctor).declaration, this.producedType);
            Metamodel.checkReifiedTypeArgument("getDeclaredConstructor", "CallableConstructor<$1,$2>", // // this line is bullshit since it's always true, but otherwise we can't substitute the error message above :(
            Variance.OUT, this.producedType, $reifiedType, Variance.IN, Metamodel.getProducedType(actualReifiedArguments), $reified$Arguments);
            ClassInitializerConstructor c = new ClassInitializerConstructor<>(this);
            return c;
        }
        CallableConstructorDeclarationImpl callableCtor = (CallableConstructorDeclarationImpl) ctor;
        org.eclipse.ceylon.model.typechecker.model.Type constructorType = callableCtor.constructor.appliedType(this.producedType, Collections.<org.eclipse.ceylon.model.typechecker.model.Type>emptyList());
        // return new AppliedConstructor<Type,Args>(this.$reifiedType, actualReifiedArguments, this, constructorType, ctor, this.instance);
        // Reference reference = ((Function)callableCtor.declaration).getReference();
        Reference reference;
        if (callableCtor.declaration instanceof Function) {
            reference = ((Function) callableCtor.declaration).appliedTypedReference(producedType, null);
        } else if (callableCtor.declaration instanceof org.eclipse.ceylon.model.typechecker.model.Class) {
            reference = ((org.eclipse.ceylon.model.typechecker.model.Class) callableCtor.declaration).appliedReference(producedType, null);
        } else if (callableCtor.declaration instanceof org.eclipse.ceylon.model.typechecker.model.Constructor) {
            reference = ((org.eclipse.ceylon.model.typechecker.model.Constructor) callableCtor.declaration).appliedReference(producedType, null);
        } else {
            throw Metamodel.newModelError("Unexpect declaration " + callableCtor.declaration);
        }
        // anonymous classes don't have parameter lists
        TypeDescriptor actualReifiedArguments = Metamodel.getTypeDescriptorForArguments(declaration.declaration.getUnit(), (Functional) callableCtor.declaration, reference);
        // This is all very ugly but we're trying to make it cheaper and friendlier than just checking the full type and showing
        // implementation types to the user, such as AppliedMemberClass
        Metamodel.checkReifiedTypeArgument("getConstructor", "Constructor<$1,$2>", // this line is bullshit since it's always true, but otherwise we can't substitute the error message above :(
        Variance.OUT, this.producedType, $reifiedType, Variance.IN, Metamodel.getProducedType(actualReifiedArguments), $reified$Arguments);
        CallableConstructorImpl<Type, Sequential<? extends Object>> appliedConstructor = new CallableConstructorImpl<Type, Sequential<? extends java.lang.Object>>(this.$reifiedType, $reified$Arguments, reference, callableCtor, this, instance);
        Metamodel.checkReifiedTypeArgument("apply", "CallableConstructor<$1,$2>", Variance.OUT, producedType, $reifiedType, Variance.IN, Metamodel.getProducedTypeForArguments(declaration.declaration.getUnit(), (Functional) callableCtor.declaration, reference), $reified$Arguments);
        return appliedConstructor;
    } else if (ctor instanceof ValueConstructorDeclaration) {
        ValueConstructorDeclarationImpl callableCtor = (ValueConstructorDeclarationImpl) ctor;
        org.eclipse.ceylon.model.typechecker.model.Type constructorType = callableCtor.constructor.appliedType(this.producedType, Collections.<org.eclipse.ceylon.model.typechecker.model.Type>emptyList());
        TypedDeclaration val = (TypedDeclaration) callableCtor.constructor.getContainer().getDirectMember(callableCtor.constructor.getName(), null, false);
        return new ValueConstructorImpl<Type>(this.$reifiedType, callableCtor, val.getTypedReference(), this, instance);
    } else {
        throw new AssertionError("Constructor neither CallableConstructorDeclaration nor ValueConstructorDeclaration");
    }
}
Also used : CallableConstructorDeclarationImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.CallableConstructorDeclarationImpl) ValueConstructorDeclaration(ceylon.language.meta.declaration.ValueConstructorDeclaration) Function(org.eclipse.ceylon.model.typechecker.model.Function) Sequential(ceylon.language.Sequential) ClassWithInitializerDeclarationConstructor(org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassWithInitializerDeclarationConstructor) AssertionError(ceylon.language.AssertionError) ClassDeclarationImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassDeclarationImpl) CallableConstructorImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.meta.CallableConstructorImpl) Metamodel(org.eclipse.ceylon.compiler.java.runtime.metamodel.Metamodel) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) CallableConstructorDeclaration(ceylon.language.meta.declaration.CallableConstructorDeclaration) ClassInitializerConstructor(org.eclipse.ceylon.compiler.java.runtime.metamodel.meta.ClassInitializerConstructor) Reference(org.eclipse.ceylon.model.typechecker.model.Reference) CallableConstructor(ceylon.language.meta.model.CallableConstructor) ValueConstructor(ceylon.language.meta.model.ValueConstructor) ClassWithInitializerDeclarationConstructor(org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassWithInitializerDeclarationConstructor) ClassInitializerConstructor(org.eclipse.ceylon.compiler.java.runtime.metamodel.meta.ClassInitializerConstructor) Class(org.eclipse.ceylon.model.typechecker.model.Class) Functional(org.eclipse.ceylon.model.typechecker.model.Functional) TypeDescriptor(org.eclipse.ceylon.compiler.java.runtime.model.TypeDescriptor) ValueConstructorDeclarationImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ValueConstructorDeclarationImpl) Class(org.eclipse.ceylon.model.typechecker.model.Class) TypeParameters(org.eclipse.ceylon.compiler.java.metadata.TypeParameters) TypeInfo(org.eclipse.ceylon.compiler.java.metadata.TypeInfo)

Example 28 with TypeInfo

use of org.eclipse.ceylon.compiler.java.metadata.TypeInfo in project ceylon by eclipse.

the class ClassOrInterfaceImpl method getDeclaredInterface.

@SuppressWarnings({ "unchecked", "hiding" })
@Override
@TypeParameters({ @TypeParameter(value = "Container"), @TypeParameter(value = "Type") })
@TypeInfo("ceylon.language.meta.model::MemberInterface<Container,Type>|ceylon.language::Null")
public <Container, Type> ceylon.language.meta.model.MemberInterface<Container, Type> getDeclaredInterface(@Ignore TypeDescriptor $reifiedContainer, @Ignore TypeDescriptor $reifiedType, String name, @Name("types") @Sequenced Sequential<? extends ceylon.language.meta.model.Type<?>> types) {
    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 ClassOrInterfaceDeclarationImpl type = declaration.findDeclaredType(name);
    if (type == null)
        return null;
    if (type instanceof InterfaceDeclarationImpl == false)
        throw new IncompatibleTypeException("Specified member is not an interface: " + name);
    return (ceylon.language.meta.model.MemberInterface<Container, Type>) type.memberApply($reifiedContainer, $reifiedType, (ceylon.language.meta.model.Type<Container>) this, types);
}
Also used : ReifiedType(org.eclipse.ceylon.compiler.java.runtime.model.ReifiedType) ClassOrInterfaceDeclarationImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassOrInterfaceDeclarationImpl) Metamodel(org.eclipse.ceylon.compiler.java.runtime.metamodel.Metamodel) IncompatibleTypeException(ceylon.language.meta.model.IncompatibleTypeException) InterfaceDeclarationImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.InterfaceDeclarationImpl) ClassOrInterfaceDeclarationImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassOrInterfaceDeclarationImpl) TypeParameters(org.eclipse.ceylon.compiler.java.metadata.TypeParameters) TypeInfo(org.eclipse.ceylon.compiler.java.metadata.TypeInfo)

Example 29 with TypeInfo

use of org.eclipse.ceylon.compiler.java.metadata.TypeInfo 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 30 with TypeInfo

use of org.eclipse.ceylon.compiler.java.metadata.TypeInfo 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)

Aggregations

TypeInfo (org.eclipse.ceylon.compiler.java.metadata.TypeInfo)38 TypeParameters (org.eclipse.ceylon.compiler.java.metadata.TypeParameters)32 Metamodel (org.eclipse.ceylon.compiler.java.runtime.metamodel.Metamodel)25 TypeDescriptor (org.eclipse.ceylon.compiler.java.runtime.model.TypeDescriptor)18 Sequential (ceylon.language.Sequential)12 ArrayList (java.util.ArrayList)10 ObjectArrayIterable (org.eclipse.ceylon.compiler.java.language.ObjectArrayIterable)10 ReifiedType (org.eclipse.ceylon.compiler.java.runtime.model.ReifiedType)9 ClassOrInterfaceDeclarationImpl (org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassOrInterfaceDeclarationImpl)8 IncompatibleTypeException (ceylon.language.meta.model.IncompatibleTypeException)7 ClassDeclarationImpl (org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassDeclarationImpl)7 ClassDeclaration (ceylon.language.meta.declaration.ClassDeclaration)5 Type (org.eclipse.ceylon.model.typechecker.model.Type)5 OpenType (ceylon.language.meta.declaration.OpenType)4 FunctionDeclarationImpl (org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.FunctionDeclarationImpl)4 InterfaceDeclarationImpl (org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.InterfaceDeclarationImpl)4 MemberClassImpl (org.eclipse.ceylon.compiler.java.runtime.metamodel.meta.MemberClassImpl)4 AssertionError (ceylon.language.AssertionError)3 CallableConstructorDeclaration (ceylon.language.meta.declaration.CallableConstructorDeclaration)3 ClassOrInterfaceDeclaration (ceylon.language.meta.declaration.ClassOrInterfaceDeclaration)3