Search in sources :

Example 1 with SetterDeclarationImpl

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

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 Constructor (java.lang.reflect.Constructor)1 Metamodel (org.eclipse.ceylon.compiler.java.runtime.metamodel.Metamodel)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 SetterDeclarationImpl (org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.SetterDeclarationImpl)1 ValueConstructorDeclarationImpl (org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ValueConstructorDeclarationImpl)1 ValueDeclarationImpl (org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ValueDeclarationImpl)1 ReflectionClass (org.eclipse.ceylon.model.loader.impl.reflect.mirror.ReflectionClass)1 AnnotationProxyClass (org.eclipse.ceylon.model.loader.model.AnnotationProxyClass)1 FunctionOrValueInterface (org.eclipse.ceylon.model.loader.model.FunctionOrValueInterface)1 LazyClass (org.eclipse.ceylon.model.loader.model.LazyClass)1 LazyFunction (org.eclipse.ceylon.model.loader.model.LazyFunction)1 LazyInterface (org.eclipse.ceylon.model.loader.model.LazyInterface)1 LazyTypeAlias (org.eclipse.ceylon.model.loader.model.LazyTypeAlias)1