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.3.1 | |
ceylon.collection | 1.3.1 |
Aliases | |
BodyIsh | shared BodyIsh=> Body|{Declaration|Statement*} Something that can readily be converted to a |
CaseTypeIsh | shared CaseTypeIsh=> PrimaryTypeIsh|IdentifierIsh |
IdentifierIsh | shared IdentifierIsh=> Identifier|String Something that can readily be converted to an |
PositionalArgumentIsh | shared PositionalArgumentIsh=> Expression|SpreadArgument|Comprehension |
PrimaryTypeIsh | shared PrimaryTypeIsh=> PrimaryType|IdentifierIsh |
TypeParameterIsh | shared TypeParameterIsh=> TypeParameter|IdentifierIsh |
Functions | |
annotations | shared 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 | shared BaseExpression baseExpression(IdentifierIsh name, <IdentifierIsh|Type>[] typeArguments) A utility function to create a This function is not suitable in all cases; if the following restrictions affect you, you should instead use the regular constructors:
Usage examples: baseExpression("null") // null baseExpression("String") // String; not to be confused with baseType("String")! baseExpression("emptyOrSingleton", "Integer") // emptyOrSingleton<Integer> |
baseType | shared BaseType baseType(IdentifierIsh name, <IdentifierIsh|Type>[] typeArguments) A utility function to create a This function is not suitable in all cases; if the following restrictions affect you, you should instead use the regular constructors:
Usage examples: baseType("String") // String baseType("Sequence", "Integer") // Sequence<Integer> |
block | shared Block block(BodyIsh content) Converts a stream of declarations and statements
to a Throws
|
callableConstructorDefinition | shared CallableConstructorDefinition callableConstructorDefinition(IdentifierIsh name, Parameters|{Parameter*} parameters = ..., {Declaration|Statement*} block = [], ExtendedType? extendedType = null, Annotations annotations = ...) Creates a callable constructor definition. Usage example: callableConstructorDefinition { name = "rgb"; parameters = { ValueParameter { type = baseType("Integer"); name = lidentifier("rgb"); } }; annotations = annotations { "Constructs a color, taking the red, green, and blue values from the argument integer."; "shared" }; ValueSpecification { qualifier = This(); name = lidentifier("rgb"); specifier = Specifier(baseExpression("rgb")); } } Parameters:
|
caseTypes | shared 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 | shared ClassBody classBody(BodyIsh content) Converts a stream of declarations and statements
to a Throws
|
classDefinition | shared ClassDefinition classDefinition(IdentifierIsh name, Parameters|{Parameter*}? parameters = ..., {Declaration|Statement*} body = ..., {CaseTypeIsh*}|CaseTypes? caseTypes = ..., ExtendedType? extendedType = ..., {PrimaryTypeIsh*}|SatisfiedTypes? satisfiedTypes = ..., {TypeParameterIsh*}|TypeParameters? typeParameters = ..., {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:
|
classSpecifier | shared ClassSpecifier classSpecifier(IdentifierIsh|TypeNameWithTypeArguments name, PackageQualifier|Super? qualifier = null, {PositionalArgumentIsh*} arguments = ...) Creates a Note: this only supports extension. If you want to delegate to a constructor, do it manually. Usage examples: classSpecifier("Object") classSpecifier { name = "Point"; baseExpression("y"), baseExpression("x") } Parameters:
|
extendedType | shared ExtendedType extendedType(IdentifierIsh|TypeNameWithTypeArguments name, PackageQualifier|Super? qualifier = null, {PositionalArgumentIsh*} arguments = ...) Creates an Note: this only supports extension. If you want to delegate to a constructor, do it manually. Usage examples: extendedType("Sup") extendedType { name = "Point"; baseExpression("x"), baseExpression("y") } Parameters:
|
extension | shared Extension extension(IdentifierIsh|TypeNameWithTypeArguments name, PackageQualifier|Super? qualifier = null, {PositionalArgumentIsh*} arguments = ...) Creates an Note: this function does not support Usage examples: extension("Object") extension { name = "Point"; baseExpression("y"), baseExpression("x") } Parameters:
|
functionDefinition | shared FunctionDefinition functionDefinition(IdentifierIsh name, Type|VoidModifier|FunctionModifier|DynamicModifier type, {Parameters+}|Parameters|{Parameter*} parameters = ..., {Declaration|Statement*} block = ..., {TypeParameterIsh*}|TypeParameters? typeParameters = ..., {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 | shared 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 | shared InterfaceBody interfaceBody(BodyIsh content) Converts a stream of declarations
to an Throws
|
interfaceDefinition | shared InterfaceDefinition interfaceDefinition(IdentifierIsh name, {Declaration|Specification*} body = ..., {CaseTypeIsh*}|CaseTypes? caseTypes = ..., {PrimaryTypeIsh*}|SatisfiedTypes? satisfiedTypes = ..., {TypeParameterIsh*}|TypeParameters? typeParameters = ..., {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 | shared Invocation invocation(Primary|IdentifierIsh invoked, {PositionalArgumentIsh*} arguments) Creates an Usage example: invocation { "printAll"; StringLiteral("Hello, World!"), StringLiteral("Goodbye, World!") } |
invocationStatement | shared InvocationStatement invocationStatement(Primary|IdentifierIsh invoked, {PositionalArgumentIsh*} arguments) Creates an Usage example: invocationStatement { "printAll"; StringLiteral("Hello, World!"), StringLiteral("Goodbye, World!") } |
lidentifier | shared LIdentifier lidentifier(IdentifierIsh name) Utility function to create an Examples: lidentifier("null") lidentifier(attributeName) Throws
|
nameWithTypeArguments | shared NameWithTypeArguments nameWithTypeArguments(IdentifierIsh name, TypeArguments? typeArguments = null) Convenience function to create either a Parameters:
|
positionalArguments | shared PositionalArguments positionalArguments(PositionalArgumentIsh[] arguments) A utility function to create Usage examples: positionalArguments() positionalArguments(This(), SpreadArgument(baseExpression("others"))) |
primaryType | shared PrimaryType primaryType(PrimaryTypeIsh name) Converts a type name to a This function is not intended for external use.
Use |
qualifiedExpression | shared QualifiedExpression qualifiedExpression(IdentifierIsh|Primary receiverExpression, IdentifierIsh name, <IdentifierIsh|Type>[] typeArguments) A utility function to create a This function is not suitable in all cases; if the following restrictions affect you, you should instead use the regular constructors:
Usage examples: qualifiedExpression("x", "Y") // x.Y qualifiedExpression(qualifiedExpression(baseExpression("process"), "arguments"), "first") // process.arguments.first |
qualifiedType | shared QualifiedType qualifiedType(IdentifierIsh|SimpleType|GroupedType qualifyingType, IdentifierIsh name, <IdentifierIsh|Type>[] typeArguments) A utility function to create a This function is not suitable in all cases; if the following restrictions affect you, you should instead use the regular constructors:
Usage examples: qualifiedType("X", "Y") // X.Y qualifiedType(qualifiedType(baseType("X", "A"), "Y", "B"), "Z", "C") //X<A>.Y<B>.Z<C> |
satisfiedTypes | shared SatisfiedTypes satisfiedTypes([PrimaryTypeIsh+] satisfiedTypes) Converts a stream of primary types
to Usage examples: satisfiedTypes("Identifiable") satisfiedTypes(baseType("MutableList", "Element")) |
stringTemplate | shared StringTemplate stringTemplate([StringLiteral|Expression+] 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 | shared 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 | shared UIdentifier uidentifier(IdentifierIsh name) Utility function to create an Examples: uidentifier("Anything") uidentifier(className) Throws
|
valueConstructorDefinition | shared ValueConstructorDefinition valueConstructorDefinition(IdentifierIsh name, {Declaration|Statement*} block = [], ExtendedType? extendedType = null, Annotations annotations = ...) Creates a value constructor definition. Usage example: valueConstructorDefinition { name = "red"; annotations = annotations { "The color red."; "shared" }; ValueSpecification { qualifier = This(); name = lidentifier("rgb"); specifier = Specifier(IntegerLiteral("#FF0000")); } } Parameters:
|