Search in sources :

Example 1 with ValueConstructorDeclarationImpl

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

the class ClassImpl method getCaseValues.

@Override
@TypeInfo("ceylon.language::Sequential<Type>")
public ceylon.language.Sequential<? extends Type> getCaseValues() {
    Class classDecl = (Class) declaration.declaration;
    if (classDecl.hasEnumerated()) {
        // can only possibly have value constructor cases
        if (classDecl.getCaseTypes() == null || classDecl.getCaseTypes().isEmpty()) {
            // it's not a closed enum of value constructors
            return (Sequential) empty_.get_();
        }
        ArrayList<Type> ctors = new ArrayList<>();
        for (ceylon.language.meta.declaration.Declaration d : ((ClassDeclarationImpl) declaration).constructors()) {
            Declaration dd = null;
            if (d instanceof CallableConstructorDeclarationImpl) {
                continue;
            } else if (d instanceof ValueConstructorDeclarationImpl) {
                dd = ((ValueConstructorDeclarationImpl) d).declaration;
            }
            // ATM this is an AND WRT annotation types: all must be present
            ctors.add(((ValueConstructor<Type>) getDeclaredConstructor(TypeDescriptor.NothingType, d.getName())).get());
        }
        Object[] array = ctors.toArray(new Object[ctors.size()]);
        ObjectArrayIterable<ceylon.language.meta.declaration.Declaration> iterable = new ObjectArrayIterable<ceylon.language.meta.declaration.Declaration>(this.$reifiedType, (Object[]) array);
        return (ceylon.language.Sequential) iterable.sequence();
    } else {
        return super.getCaseValues();
    }
}
Also used : CallableConstructorDeclarationImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.CallableConstructorDeclarationImpl) ArrayList(java.util.ArrayList) ObjectArrayIterable(org.eclipse.ceylon.compiler.java.language.ObjectArrayIterable) Sequential(ceylon.language.Sequential) ValueConstructorDeclarationImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ValueConstructorDeclarationImpl) ClassDeclarationImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassDeclarationImpl) Class(org.eclipse.ceylon.model.typechecker.model.Class) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) CallableConstructorDeclaration(ceylon.language.meta.declaration.CallableConstructorDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) ValueConstructorDeclaration(ceylon.language.meta.declaration.ValueConstructorDeclaration) TypeInfo(org.eclipse.ceylon.compiler.java.metadata.TypeInfo)

Example 2 with ValueConstructorDeclarationImpl

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

the class Metamodel method getConstructors.

public static <Type> Sequential getConstructors(ClassOrInterfaceImpl<Type> cls, boolean justShared, boolean callableConstructors, TypeDescriptor $reified$Arguments, ceylon.language.Sequential<? extends ceylon.language.meta.model.Type<? extends java.lang.annotation.Annotation>> annotations) {
    ArrayList<Object> ctors = new ArrayList<>();
    org.eclipse.ceylon.model.typechecker.model.Type reifiedArguments = $reified$Arguments == null ? null : Metamodel.getProducedType($reified$Arguments);
    TypeDescriptor[] annotationTypeDescriptors = Metamodel.getTypeDescriptors(annotations);
    if (cls.declaration instanceof ClassWithInitializerDeclarationImpl) {
        Reference producedReference = cls.declaration.declaration.appliedReference(cls.producedType, Collections.<org.eclipse.ceylon.model.typechecker.model.Type>emptyList());
        org.eclipse.ceylon.model.typechecker.model.Type argumentsType = Metamodel.getProducedTypeForArguments(cls.declaration.declaration.getUnit(), (Functional) cls.declaration.declaration, producedReference);
        if (reifiedArguments == null || reifiedArguments.isSubtypeOf(argumentsType)) {
            if (hasAllAnnotations(((ClassWithInitializerDeclarationImpl) cls.declaration).getDefaultConstructor(), annotationTypeDescriptors)) {
                // TODO test for arguments too
                // ctors.add(new AppliedInitializer((AppliedClass)cls));
                ctors.add(((ClassModel<?, ?>) cls).getDefaultConstructor());
            }
        }
    } else {
        for (ceylon.language.meta.declaration.Declaration d : ((ClassDeclarationImpl) cls.declaration).constructors()) {
            Declaration dd = null;
            AnnotatedDeclaration annotated;
            if (d instanceof CallableConstructorDeclarationImpl && callableConstructors) {
                dd = ((CallableConstructorDeclarationImpl) d).declaration;
                annotated = (CallableConstructorDeclaration) d;
            } else if (d instanceof ValueConstructorDeclarationImpl && !callableConstructors) {
                dd = ((ValueConstructorDeclarationImpl) d).declaration;
                annotated = (ValueConstructorDeclaration) d;
            } else {
                continue;
            }
            // ATM this is an AND WRT annotation types: all must be present
            if (!hasAllAnnotations(annotated, annotationTypeDescriptors))
                continue;
            if (dd instanceof Functional && reifiedArguments != null) {
                // CallableConstructor need a check on the <Arguments>
                Reference producedReference = dd.appliedReference(cls.producedType, Collections.<org.eclipse.ceylon.model.typechecker.model.Type>emptyList());
                org.eclipse.ceylon.model.typechecker.model.Type argumentsType = Metamodel.getProducedTypeForArguments(dd.getUnit(), (Functional) dd, producedReference);
                if (!reifiedArguments.isSubtypeOf(argumentsType))
                    continue;
            }
            // ATM this is an AND WRT annotation types: all must be present
            if (!Metamodel.hasAllAnnotations((AnnotatedDeclaration) d, annotationTypeDescriptors))
                continue;
            if (dd instanceof Functional && reifiedArguments != null) {
                // CallableConstructor need a check on the <Arguments>
                Reference producedReference = dd.appliedReference(cls.producedType, Collections.<org.eclipse.ceylon.model.typechecker.model.Type>emptyList());
                org.eclipse.ceylon.model.typechecker.model.Type argumentsType = Metamodel.getProducedTypeForArguments(dd.getUnit(), (Functional) dd, producedReference);
                if (!reifiedArguments.isSubtypeOf(argumentsType))
                    continue;
            }
            if (!justShared || (d instanceof NestableDeclaration && ((NestableDeclaration) d).getShared())) {
                Object ctor;
                if (cls instanceof ClassImpl<?, ?>) {
                    ctor = ((ClassImpl<?, ?>) cls).getDeclaredConstructor(TypeDescriptor.NothingType, d.getName());
                } else {
                    // if (cls instanceof AppliedMemberClass<?,?,?>) {
                    ctor = ((MemberClassImpl<?, ?, ?>) cls).getDeclaredConstructor(TypeDescriptor.NothingType, d.getName());
                }
                ctors.add(ctor);
            }
        }
    }
    Object[] array = ctors.toArray(new Object[ctors.size()]);
    ObjectArrayIterable<ceylon.language.meta.declaration.Declaration> iterable = new ObjectArrayIterable<ceylon.language.meta.declaration.Declaration>(TypeDescriptor.union(TypeDescriptor.klass(FunctionModel.class, cls.$reifiedType, TypeDescriptor.NothingType), TypeDescriptor.klass(ValueModel.class, cls.$reifiedType, TypeDescriptor.NothingType)), (Object[]) array);
    return (ceylon.language.Sequential) iterable.sequence();
}
Also used : CallableConstructorDeclarationImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.CallableConstructorDeclarationImpl) MemberClassImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.meta.MemberClassImpl) ClassImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.meta.ClassImpl) ValueConstructorDeclaration(ceylon.language.meta.declaration.ValueConstructorDeclaration) ArrayList(java.util.ArrayList) Type(org.eclipse.ceylon.model.typechecker.model.Type) NestableDeclaration(ceylon.language.meta.declaration.NestableDeclaration) ClassWithInitializerDeclarationImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassWithInitializerDeclarationImpl) AnnotatedDeclaration(ceylon.language.meta.declaration.AnnotatedDeclaration) Sequential(ceylon.language.Sequential) ClassDeclarationImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassDeclarationImpl) 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) Reference(org.eclipse.ceylon.model.typechecker.model.Reference) ObjectArrayIterable(org.eclipse.ceylon.compiler.java.language.ObjectArrayIterable) 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)

Example 3 with ValueConstructorDeclarationImpl

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

use of org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ValueConstructorDeclarationImpl 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)

Example 5 with ValueConstructorDeclarationImpl

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

the class MemberClassImpl method getDeclaredConstructor.

@Override
@TypeParameters({ @TypeParameter(value = "Arguments", satisfies = "ceylon.language::Anything[]") })
@TypeInfo("ceylon.language.meta.model::MemberClassCallableConstructor<Container,Type,Arguments>|ceylon.language.meta.model::MemberClassValueConstructor<Container,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) {
            return new MemberClassInitializerConstructor<>(this.$reifiedContainer, this.$reifiedType, $reified$Arguments, this);
        }
        CallableConstructorDeclarationImpl callableCtor = (CallableConstructorDeclarationImpl) ctor;
        // anonymous classes don't have parameter lists
        // TypeDescriptor actualReifiedArguments = Metamodel.getTypeDescriptorForArguments(declaration.declaration.getUnit(), (Functional)callableCtor.constructor, this.producedType);
        // 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), $reifiedArguments);
        // return new AppliedConstructor<Type,Args>(this.$reifiedType, actualReifiedArguments, this, constructorType, ctor, this.instance);
        org.eclipse.ceylon.model.typechecker.model.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);
        }
        return new MemberClassCallableConstructorImpl<Container, Type, Sequential<? extends java.lang.Object>>($reifiedContainer, this.$reifiedType, $reified$Arguments, reference, callableCtor, this);
    } 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 MemberClassValueConstructorImpl<Container, Type>(// <Container>
        $reifiedContainer, // <Get>
        this.$reifiedType, callableCtor, val.getTypedReference(), this);
    } else {
        throw new AssertionError("Constructor neither CallableConstructorDeclaration nor ValueConstructorDeclaration");
    }
/*checkInit();
        final FreeConstructor ctor = (FreeConstructor)((FreeClass)declaration).getConstructorDeclaration(name);
        if(ctor == null)
            return null;
        return new AppliedMemberClassConstructor($reifiedContainer, this.$reifiedType, reified$Arguments, this, ctor.constructor.appliedType(this.producedType, Collections.<org.eclipse.ceylon.model.typechecker.model.Type>emptyList()), ctor);*/
}
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) ClassWithInitializerDeclarationConstructor(org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassWithInitializerDeclarationConstructor) AssertionError(ceylon.language.AssertionError) ClassDeclarationImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassDeclarationImpl) Metamodel(org.eclipse.ceylon.compiler.java.runtime.metamodel.Metamodel) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) MemberClassInitializerConstructor(org.eclipse.ceylon.compiler.java.runtime.metamodel.meta.MemberClassInitializerConstructor) MemberClassCallableConstructorImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.meta.MemberClassCallableConstructorImpl) CallableConstructorDeclaration(ceylon.language.meta.declaration.CallableConstructorDeclaration) CallableConstructor(ceylon.language.meta.model.CallableConstructor) ClassWithInitializerDeclarationConstructor(org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassWithInitializerDeclarationConstructor) MemberClassCallableConstructor(ceylon.language.meta.model.MemberClassCallableConstructor) MemberClassInitializerConstructor(org.eclipse.ceylon.compiler.java.runtime.metamodel.meta.MemberClassInitializerConstructor) ValueConstructorDeclarationImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ValueConstructorDeclarationImpl) Class(ceylon.language.meta.model.Class) TypeParameters(org.eclipse.ceylon.compiler.java.metadata.TypeParameters) TypeInfo(org.eclipse.ceylon.compiler.java.metadata.TypeInfo)

Aggregations

CallableConstructorDeclaration (ceylon.language.meta.declaration.CallableConstructorDeclaration)5 ValueConstructorDeclaration (ceylon.language.meta.declaration.ValueConstructorDeclaration)5 CallableConstructorDeclarationImpl (org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.CallableConstructorDeclarationImpl)5 ValueConstructorDeclarationImpl (org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ValueConstructorDeclarationImpl)5 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)5 Metamodel (org.eclipse.ceylon.compiler.java.runtime.metamodel.Metamodel)4 ClassDeclarationImpl (org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassDeclarationImpl)4 Sequential (ceylon.language.Sequential)3 TypeInfo (org.eclipse.ceylon.compiler.java.metadata.TypeInfo)3 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)3 Function (org.eclipse.ceylon.model.typechecker.model.Function)3 AssertionError (ceylon.language.AssertionError)2 AnnotatedDeclaration (ceylon.language.meta.declaration.AnnotatedDeclaration)2 NestableDeclaration (ceylon.language.meta.declaration.NestableDeclaration)2 CallableConstructor (ceylon.language.meta.model.CallableConstructor)2 ArrayList (java.util.ArrayList)2 ObjectArrayIterable (org.eclipse.ceylon.compiler.java.language.ObjectArrayIterable)2 TypeParameters (org.eclipse.ceylon.compiler.java.metadata.TypeParameters)2 ClassWithInitializerDeclarationConstructor (org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassWithInitializerDeclarationConstructor)2 ClassWithInitializerDeclarationImpl (org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassWithInitializerDeclarationImpl)2