This module contains helper functions to simplify creating ceylon.ast.core nodes.
The most useful functions are baseExpression()
and baseType()
,
which allow you to abbreviate
BaseExpression(MemberNameWithTypeArguments(LIdentifier("null"))) BaseType(TypeNameWithTypeArguments(UIdentifier("String")))
as
baseExpression("null") baseType("String")
Many of the functions in this package are also designed to be used with named arguments, where the “listed” argument (comma-separated) is assigned to the first unassigned iterable parameter. For example, we intend you to write
annotations { documentation = "Documentation."; "shared", "actual", "default" }
and not
annotations { documentation = "Documentation."; annotations = { "shared", "actual", "default" }; }
This is especially important for the functionDefinition()
,
classDefinition()
and interfaceDefinition()
functions.
Packages | |
ceylon.ast.create |
Dependencies | ||
ceylon.ast.core | 1.1.0 | |
ceylon.collection | 1.1.0 |
Aliases | |
BodyIsh | Source Codeshared BodyIsh=> Body|{<Declaration|Statement>*} Something that can readily be converted to a |
CaseTypeIsh | Source Codeshared CaseTypeIsh=> PrimaryTypeIsh|IdentifierIsh |
IdentifierIsh | Source Codeshared IdentifierIsh=> Identifier|String Something that can readily be converted to an |
PositionalArgumentIsh | Source Codeshared PositionalArgumentIsh=> Expression|SpreadArgument|Comprehension |
PrimaryTypeIsh | Source Codeshared PrimaryTypeIsh=> PrimaryType|IdentifierIsh |
TypeParameterIsh | Source Codeshared TypeParameterIsh=> TypeParameter|IdentifierIsh |
Functions | |
annotations | Source Codeshared Annotations annotations(StringLiteral|String? doc = null, {<Annotation|IdentifierIsh>*} annotations = ...) Converts a string (or literal) and a stream of annotation
names (or annotations) to Usage examples: annotations { "shared", "actual" } annotations { doc = "Determines if the stream is empty, that is to say, if the iterator returns no elements."; "shared", "default" } Parameters:
|
baseExpression | Source Codeshared BaseExpression baseExpression(IdentifierIsh name, <IdentifierIsh|Type>[] typeArguments) A utility function to create a (The type arguments will all be invariant; if you want to use use-site variance,
you have to construct the Usage examples: baseExpression("null") // null baseExpression("String") // String; not to be confused with baseType("String")! baseExpression("emptyOrSingleton", "Integer") // emptyOrSingleton<Integer> |
baseType | Source Codeshared BaseType baseType(IdentifierIsh name, <IdentifierIsh|Type>[] typeArguments) A utility function to create a (The type arguments will all be invariant; if you want to use use-site variance,
you have to construct the Usage examples: baseType("String") // String baseType("Sequence", "Integer") // Sequence<Integer> |
block | Source Codeshared Block block(BodyIsh content) Converts a stream of declarations and statements
to a Throws
|
caseTypes | Source Codeshared CaseTypes caseTypes([CaseTypeIsh+] caseTypes) Converts a stream of primary types and anonymous class names
to Usage examples: caseTypes("Other") // self type constraint caseTypes("true", "false") |
classBody | Source Codeshared ClassBody classBody(BodyIsh content) Converts a stream of declarations and statements
to a Throws
|
classDefinition | Source Codeshared ClassDefinition classDefinition(IdentifierIsh name, Parameters|{Parameter*} parameters = ..., {<Declaration|Statement>*} body = [], {CaseTypeIsh*}|CaseTypes? caseTypes = null, ExtendedType? extendedType = null, {PrimaryTypeIsh*}|SatisfiedTypes? satisfiedTypes = null, {TypeParameterIsh*}|TypeParameters? typeParameters = null, {TypeConstraint*} typeConstraints = [], Annotations annotations = ...) Creates a class definition. Usage example: classDefinition { name = "MyClass"; parameters = { ValueParameter { annotations = annotations { "shared", "actual" }; type = baseType("String"); name = lidentifier("string"); } }; caseTypes = { "CT1", "CT2" }; extendedType = extendedType { "Super"; IntegerLiteral("1"), baseExpression("string") }; satisfiedTypes = { "Identifiable" }; typeParameters = { "Element", "Absent" }; annotations = annotations { "My class does something. It’s the most amazing class ever."; "shared" }; functionDefinition { // ... }, functionDefinition { // ... } } Parameters:
|
classInstantiation | Source Codeshared ClassInstantiation classInstantiation(IdentifierIsh|TypeNameWithTypeArguments name, Super? qualifier = null, {PositionalArgumentIsh*} arguments = ...) Creates a Keep in mind that Usage examples: classInstantiation("Sup") classInstantiation { name = "Point"; baseExpression("x"), baseExpression("y") } Parameters:
|
classSpecifier | Source Codeshared ClassSpecifier classSpecifier(IdentifierIsh|TypeNameWithTypeArguments name, Super? qualifier = null, {PositionalArgumentIsh*} arguments = ...) Creates a Usage examples: classSpecifier("Object") classSpecifier { name = "Point"; baseExpression("y"), baseExpression("x") } Parameters:
|
extendedType | Source Codeshared ExtendedType extendedType(IdentifierIsh|TypeNameWithTypeArguments name, Super? qualifier = null, {PositionalArgumentIsh*} arguments = ...) Creates an Usage examples: extendedType("Sup") extendedType { name = "Point"; baseExpression("x"), baseExpression("y") } Parameters:
|
functionDefinition | Source Codeshared FunctionDefinition functionDefinition(IdentifierIsh name, Type|VoidModifier|FunctionModifier|DynamicModifier type, {Parameters+}|Parameters|{Parameter*} parameters = ..., {<Declaration|Statement>*} block = [], {TypeParameterIsh*}|TypeParameters? typeParameters = null, {TypeConstraint*} typeConstraints = [], Annotations annotations = ...) Creates a function definition. Usage example: functionDefinition { name = "myFunction"; type = VoidModifier(); parameters = { ValueParameter { type = baseType("String"); name = lidentifier("name"); } }; typeParameters = { "Element" }; annotations = annotations { "My function does something. It’s the most amazing function ever."; "shared", "actual", "default" }; invocationStatement { invoked = "print"; StringLiteral("Hello, World!") } } Parameters:
|
identifier | Source Codeshared Identifier identifier(IdentifierIsh text) Parses an identifier from its text. The text may contain the prefix, but no escape sequences. Examples: identifier("name") identifier("S_``state``") |
interfaceBody | Source Codeshared InterfaceBody interfaceBody(BodyIsh content) Converts a stream of declarations
to an Throws
|
interfaceDefinition | Source Codeshared InterfaceDefinition interfaceDefinition(IdentifierIsh name, {Declaration*} body = [], {CaseTypeIsh*}|CaseTypes? caseTypes = null, {PrimaryTypeIsh*}|SatisfiedTypes? satisfiedTypes = null, {TypeParameterIsh*}|TypeParameters? typeParameters = null, {TypeConstraint*} typeConstraints = [], Annotations annotations = ...) Creates an interface definition. Usage example: interfaceDefinition { name = "MyInterface"; caseTypes = { "CT1", "CT2" }; satisfiedTypes = { "Identifiable" }; typeParameters = { "Element", "Absent" }; annotations = annotations { "My interface does something. It’s the most amazing interface ever."; "shared", "sealed" }; functionDefinition { // ... }, functionDefinition { // ... } } Parameters:
|
invocation | Source Codeshared Invocation invocation(Primary|IdentifierIsh invoked, {PositionalArgumentIsh*} arguments) Creates an Usage example: invocation { "printAll"; StringLiteral("Hello, World!"), StringLiteral("Goodbye, World!") } |
invocationStatement | Source Codeshared InvocationStatement invocationStatement(Primary|IdentifierIsh invoked, {PositionalArgumentIsh*} arguments) Creates an Usage example: invocationStatement { "printAll"; StringLiteral("Hello, World!"), StringLiteral("Goodbye, World!") } |
lidentifier | Source Codeshared LIdentifier lidentifier(IdentifierIsh name) Utility function to create an Examples: lidentifier("null") lidentifier(attributeName) Throws
|
nameWithTypeArguments | Source Codeshared NameWithTypeArguments nameWithTypeArguments(IdentifierIsh name, TypeArguments? typeArguments = null) Convenience function to create either a Parameters:
|
positionalArguments | Source Codeshared PositionalArguments positionalArguments(PositionalArgumentIsh[] arguments) A utility function to create Usage examples: positionalArguments() positionalArguments(thisInstance, SpreadArgument(baseExpression("others"))) |
primaryType | Source Codeshared PrimaryType primaryType(PrimaryTypeIsh name) Converts a type name to a This function is not intended for external use.
Use |
qualifiedExpression | Source Codeshared QualifiedExpression qualifiedExpression(IdentifierIsh|Primary receiverExpression, IdentifierIsh name, <IdentifierIsh|Type>[] typeArguments) A utility function to create a (The type arguments will all be invariant; if you want to use use-site variance,
you have to construct the Usage examples: qualifiedExpression("x", "Y") // x.Y qualifiedExpression(qualifiedExpression(baseExpression("process"), "arguments"), "first") // process.arguments.first |
qualifiedType | Source Codeshared QualifiedType qualifiedType(IdentifierIsh|SimpleType|GroupedType qualifyingType, IdentifierIsh name, <IdentifierIsh|Type>[] typeArguments) A utility function to create a (The type arguments will all be invariant; if you want to use use-site variance,
you have to construct the Usage examples: qualifiedType("X", "Y") // X.Y qualifiedType(qualifiedType(baseType("X", "A"), "Y", "B"), "Z", "C") //X<A>.Y<B>.Z<C> |
satisfiedTypes | Source Codeshared SatisfiedTypes satisfiedTypes([PrimaryTypeIsh+] satisfiedTypes) Converts a stream of primary types
to Usage examples: satisfiedTypes("Identifiable") satisfiedTypes(baseType("MutableList", "Element")) |
stringTemplate | Source Codeshared StringTemplate stringTemplate([<StringLiteral|ValueExpression>+] parts) Utility function to construct a Using this function, you can list the string literals and expressions
in exactly the order in which they appear in the string template
(rather than separated into two sequences, as in |
typeParameters | Source Codeshared TypeParameters typeParameters([TypeParameterIsh+] typeParameters) A utility function to create Usage examples: typeParameters("Other") // self type typeParameters("Element") // invariant, e. g. MutableList typeParameters( TypeParameter(UIdentifier("Element"), OutModifier()), TypeParameter(UIdentifier("Absent"), OutModifier(), baseType("Null")) ) // covariant, e. g. Iterable |
uidentifier | Source Codeshared UIdentifier uidentifier(IdentifierIsh name) Utility function to create an Examples: uidentifier("Anything") uidentifier(className) Throws
|