Metamodel

The Ceylon metamodel closed type and model package.

As described in the ceylon.language.meta documentation, this package contains all the types that represent Ceylon closed types and models.

### Usage example

The following code will list all the value declarations in the `ceylon.language` package and print their current value:

    Package languagePackage = `package ceylon.language`;
    ValueDeclaration[] valueDeclarations = languagePackage.members<ValueDeclaration>();
    Value<Anything>[] valueModels = valueDeclarations*.apply<Anything>();
    for(val in valueModels){
        // skip the nothing value which cannot be read
        if(val.type != `Nothing`){
            print(val.get());
        }
    }

The following code will iterate all the class declarations in the `ceylon.language` package that are not abstract, anonymous or annotations, and that have no type parameters nor initialiser parameters. For each matching class, we will apply it to get a class model which we can then use to instantiate the class and display its instance:

    for(decl in `package ceylon.language`.members<ClassDeclaration>()){
        if(!decl.abstract
                && !decl.anonymous
                && !decl.annotation
                && decl.parameterDeclarations.empty
                && decl.typeParameterDeclarations.empty){
            Class<Object,[]> classModel = decl.classApply<Object,[]>();
            Object instance = classModel();
            print("Instance of ``decl.name`` is: ``instance``");
        }
    }

By: Gavin King, Stephane Epardaud, Tom Bentley

Aliases
`TypeArgument` | Source Code `shared TypeArgument=> [ClosedType<Anything>, Variance]` A tuple representing a type argument and its use-site variance.

Values
`nothingType` | Source Code `shared nothingType nothingType` The singleton closed type for Nothing.

Interfaces
`Applicable` | Source Code `shared Applicable<out Type = Anything,in Arguments = Nothing> given Arguments satisfies Anything[]` Represents classes or functions that you can apply in a type-unsafe way.
`Attribute` | Source Code `shared Attribute<in Container = Nothing,out Get = Anything,in Set = Nothing>` An attribute model represents the model of a Ceylon attribute that you can read and inspect. An attribute is a member value: it is declared on classes or interfaces. This is both a `ValueModel` and a `Member`: you can invoke it with an instance value to bind it to that instance and obtain a `Value`:
    class Outer(){
        shared String foo = "Hello";
    }

    void test(){
        Attribute<Outer,String> attribute = `Outer.foo`;
        Value<String> boundAttribute = attribute(Outer());
        // This will print: Hello
        print(boundAttribute.get());
    }
`CallableConstructor` | Source Code `shared CallableConstructor<out Type = Object,in Arguments = Nothing> given Arguments satisfies Anything[]` A callable constructor model represents the model of a Ceylon class constructor that you can invoke and inspect ## Callablity As with `Function` you can also invoke a `CallableConstructor`, doing so instantiates an instance:
     shared class Foo {
         shared String name;
         shared new foo(String name) {
             this.name = name;
         }
     }

     void test() {
     Constructor<Foo,[String]> ctor = `Foo.foo`;
     // This will print: Stef
     print(ctor("Stef").name);
## Genericity This class inherits `Generic` but a constructor in Ceylon cannot have a type parameters. For symmetry with `CallableConstructorDeclaration.apply()` the `Generic.typeArguments` and `Generic.typeArgumentList` refer to the type arguments of the constructor's class.
`Class` | Source Code `shared Class<out Type = Anything,in Arguments = Nothing> given Arguments satisfies Anything[]` A class model represents the model of a Ceylon class that you can instantiate and inspect. A class is a toplevel type, declared on a package. This is a `ClassModel` that you can also invoke to instantiate new instances of the class:
    shared class Foo(String name){
        shared String hello => "Hello "+name;
    }

    void test(){
        Class<Foo,[String]> c = `Foo`;
        // This will print: Hello Stef
        print(c("Stef").hello);
    }
`ClassModel` | Source Code `shared ClassModel<out Type = Anything,in Arguments = Nothing> given Arguments satisfies Anything[]` A class model represents the model of a Ceylon class that you can inspect. A class model can be either a toplevel `Class` or a member `MemberClass`.
`ClassOrInterface` | Source Code `shared ClassOrInterface<out Type = Anything>` Model of a class or interface that you can inspect. The models of classes and interfaces are also closed types.
`Declared` | Source Code `shared Declared` A model element that has a declaration.
`Function` | Source Code `shared Function<out Type = Anything,in Arguments = Nothing> given Arguments satisfies Anything[]` A function model represents the model of a Ceylon function that you can invoke and inspect. A function is a toplevel binding, declared on a package. This is a `FunctionModel` that you can also invoke:
    shared String foo(String name) => "Hello "+name;

    void test(){
        Function<String,[String]> f = `foo`;
        // This will print: Hello Stef
        print(f("Stef"));
    }
`FunctionModel` | Source Code `shared FunctionModel<out Type = Anything,in Arguments = Nothing> given Arguments satisfies Anything[]` A function model represents the model of a Ceylon function that you can inspect. A function model can be either a toplevel `Function`, a CallableConstructor (`callable constructor`) of a toplevel Class, a member `Method` or CallableMemberConstructor (`callable constructor`) of a member class.
`Functional` | Source Code `shared Functional` Abstraction for models which have a parameter list.
`Generic` | Source Code `shared Generic` A generic model which has closed type arguments.
`Gettable` | Source Code `shared Gettable<out Get = Anything,in Set = Nothing>` An abstraction of things that have a value which be got, and possibley set.
`Interface` | Source Code `shared Interface<out Type = Anything>` An interface model that you can inspect.
`InterfaceModel` | Source Code `shared InterfaceModel<out Type = Anything>` An interface model represents the model of a Ceylon interface that you can inspect. An interface model can be either a toplevel `Interface` or a member `MemberInterface`.
`IntersectionType` | Source Code `shared IntersectionType<out Intersection = Anything>` A closed intersection type.
`Member` | Source Code `shared Member<in Container = Nothing,out Kind = Model> given Kind satisfies Model` Model for members that can be bound to a containing instance to turn them into toplevel models. You can bind a member to an instance by invoking that member with the instance as parameter:
    shared class Outer(String name){
        shared class Inner(){
            shared String hello => "Hello "+name;
        }
    }

    void test(){
        Member<Outer,Class<Outer.Inner,[]>> memberClass = `Outer.Inner`;
        Class<Outer.Inner,[]> c = memberClass(Outer("Stef"));
        // This will print: Hello Stef
        print(c().hello);
    }
`MemberClass` | Source Code `shared MemberClass<in Container = Nothing,out Type = Anything,in Arguments = Nothing> given Arguments satisfies Anything[]` A class model represents the model of a Ceylon class that you can instantiate and inspect. A member class is is declared on classes or interfaces. This is both a `ClassModel` and a `Member`: you can invoke it with an instance value to bind it to that instance and obtain a `Class`:
    shared class Outer(String name){
        shared class Inner(){
            shared String hello => "Hello "+name;
        }
    }

    void test(){
        MemberClass<Outer,Outer.Inner,[]> memberClass = `Outer.Inner`;
        Class<Outer.Inner,[]> c = memberClass(Outer("Stef"));
        // This will print: Hello Stef
        print(c().hello);
    }
`MemberClassCallableConstructor` | Source Code `shared MemberClassCallableConstructor<in Container = Nothing,out Type = Object,in Arguments = Nothing> given Arguments satisfies Anything[]` A model for a callable constructor of a member class.
`MemberClassValueConstructor` | Source Code `shared MemberClassValueConstructor<in Container = Nothing,out Type = Object>` A model for a value constructor of a member class.
`MemberInterface` | Source Code `shared MemberInterface<in Container = Nothing,out Type = Anything>` A member interface model that you can inspect.
`Method` | Source Code `shared Method<in Container = Nothing,out Type = Anything,in Arguments = Nothing> given Arguments satisfies Anything[]` A function model represents the model of a Ceylon function that you can invoke and inspect. A method is a member function: it is declared on classes or interfaces. This is both a `FunctionModel` and a `Member`: you can invoke it with an instance value to bind it to that instance and obtain a `Function`:
    class Outer(){
        shared String foo(String name) => "Hello "+name;
    }

    void test(){
        Method<Outer,String,[String]> method = `Outer.foo`;
        // Bind it to an instance value
        Function<String,[String]> f = method(Outer());
        // This will print: Hello Stef
        print(f("Stef"));
    }
`Model` | Source Code `shared Model` The root of all models. There are several types of models: `ClassOrInterface` `FunctionModel` `ValueModel`
`Qualified` | Source Code `shared Qualified<out Kind = Anything,in Container = Nothing>` Abstraction for models of elements which must be qualified by an instance to order to be evaluated, including: `Attribute`s (a Qualified `Value`), `Method`s (a Qualified `Function`), MemberClass (`member classes`) (a Qualified `Class`) and, MemberClassConstructor (`member constructors`) (a constructor of a Qualified `Class`). To qualify a `Qualified` metamodel instance in a type-safe way you simply invoke it. Alternatively use `Qualified.bind()` if the qualifying instance's type is unknown until runtime.
`Type` | Source Code `shared AppliedType<out Target = Anything>` A closed type. A closed type is a type which is fully resolved and bound and contains no open type variables. All instance types are closed at runtime. You have only four sorts of types: `ClassOrInterface` `UnionType` `IntersectionType` `nothingType`
`UnionType` | Source Code `shared UnionType<out Union = Anything>` A closed union type.
`Value` | Source Code `shared Value<out Get = Anything,in Set = Nothing>` A value model represents the model of a Ceylon value that you can read and inspect. A value is a toplevel binding, declared on a package. This is a `ValueModel` that you can query for a value declaration's current value:
    shared String foo = "Hello";

    void test(){
        Value<String> val = `foo`;
        // This will print: Hello
        print(val.get());
    }
`ValueConstructor` | Source Code `shared ValueConstructor<out Type = Object>` A callable constructor model represents the model of a Ceylon class value constructor that you can get and inspect ## Gettablity As with `Value` you can also get the value of a `ValueConstructor`, doing so obtains instance:
     shared class Color {
         shared String hex;
         shared new black {
             this.hex="#000000";
         }
         shared new white {
             this.hex="#ffffff";
         }
     }

     void test() {
     ValueConstructor<Color> ctor = `Color.black`;
     // This will print: #000000
     print(ctor.get());
`ValueModel` | Source Code `shared ValueModel<out Get = Anything,in Set = Nothing>` A value model represents the model of a Ceylon value that you can inspect. A value model can be either a toplevel `Value` or a member `Attribute`.

Classes
`nothingType` | Source Code `shared nothingType` The singleton closed type for Nothing.

Exceptions
`IncompatibleTypeException` | Source Code `shared IncompatibleTypeException` Thrown when you invoke metamodel methods with invalid or incompatible type arguments. For example if you try to get an attribute from a class and expect an attribute of `String` type but it is an attribute of `Integer` type.
`InvocationException` | Source Code `shared InvocationException` Thrown when attempting to invoke something which can't be invoked, like abstract class initialisers.
`MutationException` | Source Code `shared MutationException` Thrown when you try to change the value of a non-variable value
`StorageException` | Source Code `shared StorageException` Thrown when you try to read attributes that were not shared nor captured and had no physical storage allocated, so do not exist at runtime. For example if you try to read the attribute from this class:
    shared class Foo(){
        Integer x = 2;
    }
This will not work because `x` is neither shared nor captured and so it is just not retained in the runtime instances of `Foo`.
`TypeApplicationException` | Source Code `shared TypeApplicationException` Thrown when declarations are applied with invalid or incompatible type arguments. Also throw when trying to apply member declarations with no containers, or toplevel declarations with a container. For example if you try to apply `Foo` with `String`, hoping to get a `Foo<String>` but the type parameter for `Foo` only accepts types that satisfy `Numeric`.