Meta references

Meta references are a way to obtain models from ceylon.language.meta.model and declarations from ceylon.language.meta.declaration.

Usage

Obtaining models:

Class<String, [{Character*}]> cls = `String`;

CallableConstructor<Array<String>,[Integer, String]> constr = `Array<String>.ofSize`;

Interface<{String*}> iface = `Iterable<String, Null>`;

Function<Integer?, [{Integer*}]> func = `max<Integer, Null>`;

Method<Integer, Integer, [Integer]> meth = `Integer.plus`;

Value<Basic> val = `process`;

Attribute<String, String> attr = `String.string`;

UnionType<String|Integer> union = `String|Integer`;

Type<Nothing(String)> intersection = `String(String)&Integer(String)`;

Obtaining declarations:

ClassDeclaration c = `class String`;

ConstructorDeclaration ctor = `new Array.ofSize`;

InterfaceDeclaration i = `interface Iterable`;

FunctionDeclaration f = `function max`;

FunctionDeclaration iterator = `function Iterable.iterator`;

ValueDeclaration vm = `value process`;

ValueDeclaration str = `value String.string`;

Module m = `module ceylon.language`;

Package p = `package ceylon.language`;

class TypeParameterExample<Other>() {
    TypeParameter otherDecl = `given Other`;
}

When you want a reference to the current type, package, or module, you can use an abbreviated syntax:

ClassDeclaration myClass = `class`;
InterfaceDeclaration myInterface = `interface`;
Package myPackage = `package`;
Module myModule = `module`;

Description

Syntax

To obtain model references you just enclose the name of the thing you're refering to in backticks (`). Type arguments are required for generic references.

To obtain declaration references you also need to use the relevant keyword for the declaration. That is, what you would use to declare the element you are referring to. Type arguments are not required (though not an error).

Type

The type of a model reference depends on the thing being referred to, as detailed in the spec.

The type of a declaration reference also depends on the thing being referred to, as detailed in the spec.

See also