javapoet-dsl / com.mostlycertain.javapoetdsl

Package com.mostlycertain.javapoetdsl

Types

Annotations

object Annotations

ClassMeta

data class ClassMeta

ClassSpec

class ClassSpec

ClassSpecBuilder

class ClassSpecBuilder

ClassSpecFunc

typealias ClassSpecFunc = ClassSpecBuilder.() -> Unit

CodeBuilder

open class CodeBuilder

CodeExpression

Expression defined with Java code.

abstract class CodeExpression : JavaCodeBlock

CodeFunc

typealias CodeFunc = CodeBuilder.() -> Unit

ConstructorCodeBuilder

class ConstructorCodeBuilder : CodeBuilder

ConstructorCodeFunc

typealias ConstructorCodeFunc = ConstructorCodeBuilder.() -> Unit

ConstructorMeta

data class ConstructorMeta

ExpressionBuilder

class ExpressionBuilder

Format

object Format

JavaVersion

enum class JavaVersion

MethodCodeBuilder

class MethodCodeBuilder : CodeBuilder

MethodCodeFunc

typealias MethodCodeFunc = MethodCodeBuilder.() -> Unit

MethodMeta

data class MethodMeta

TypeNames

object TypeNames

Extensions for External Classes

com.squareup.javapoet.AnnotationSpec

com.squareup.javapoet.ClassName

com.squareup.javapoet.CodeBlock

com.squareup.javapoet.CodeBlock.Builder

com.squareup.javapoet.JavaFile

com.squareup.javapoet.TypeName

Functions

binaryOr

Join a series of expressions with a binary "or" operator (|).

fun binaryOr(expressions: List<CodeExpression>): CodeExpression
fun binaryOr(vararg expressions: CodeExpression): CodeExpression

classSpec

fun classSpec(name: ClassName, modifiers: List<Modifier> = emptyList(), annotations: List<AnnotationSpec> = emptyList(), implements: List<TypeName> = emptyList(), extends: TypeName? = null, block: ClassSpecFunc): ClassSpec
fun classSpec(name: String, modifiers: List<Modifier> = emptyList(), annotations: List<AnnotationSpec> = emptyList(), implements: List<TypeName> = emptyList(), extends: TypeName? = null, block: ClassSpecFunc): ClassSpec

codeBlock

Generate a block of java code.

fun codeBlock(block: CodeFunc): CodeBlock

constructorInvoke

Generate a constructor invocation expression.

fun constructorInvoke(type: TypeName, parameters: List<CodeExpression> = listOf()): CodeExpression
fun constructorInvoke(type: TypeName, vararg parameters: CodeExpression): CodeExpression
fun constructorInvoke(type: KClass<*>, vararg parameters: CodeExpression): CodeExpression
fun constructorInvoke(type: KClass<*>, parameters: List<CodeExpression> = listOf()): CodeExpression

constructorSpec

fun constructorSpec(parameters: List<ParameterSpec> = emptyList(), modifiers: List<Modifier> = emptyList(), annotations: List<AnnotationSpec> = emptyList(), throws: List<TypeName> = emptyList(), varargs: Boolean = false, body: ConstructorCodeFunc): MethodSpec

e

Short alias for expression.

fun e(format: String, vararg args: Any): CodeExpression

emptyExpression

fun emptyExpression(): CodeExpression

expression

Format java code as an expression.

fun expression(format: String, vararg args: Any): CodeExpression

Build a java code expression.

fun expression(block: ExpressionBuilder.() -> Unit): CodeExpression

Build an expression where all the lines after the first are indented.

fun expression(vararg lines: CodeExpression): CodeExpression
fun expression(lines: List<CodeExpression>): CodeExpression

fieldSpec

fun fieldSpec(type: TypeName, name: String, modifiers: List<Modifier> = emptyList(), annotations: List<AnnotationSpec> = emptyList(), initializer: CodeExpression? = null): FieldSpec
fun fieldSpec(type: Type, name: String, modifiers: List<Modifier> = emptyList(), annotations: List<AnnotationSpec> = emptyList(), initializer: CodeExpression? = null): FieldSpec
fun fieldSpec(type: KClass<*>, name: String, modifiers: List<Modifier> = emptyList(), annotations: List<AnnotationSpec> = emptyList(), initializer: CodeExpression? = null): FieldSpec

lambda

Render a lambda function.

fun lambda(vararg parameterNames: String, block: CodeFunc): CodeExpression
fun lambda(parameterNames: List<String>, block: CodeFunc): CodeExpression

Render a lambda function with a single expression and no curly braces.

fun lambda(parameterNames: List<String>, expression: CodeExpression): CodeExpression
fun lambda(vararg parameterNames: String, expression: CodeExpression): CodeExpression

Render a lambda function with a single expression and no curly braces or parameters.

fun lambda(expression: CodeExpression): CodeExpression

literal

fun literal(value: String): CodeExpression
fun literal(value: Char): CodeExpression
fun literal(value: Byte): CodeExpression
fun literal(value: Short): CodeExpression
fun literal(value: Int): CodeExpression
fun literal(value: Long): CodeExpression
fun literal(value: Float): CodeExpression
fun literal(value: Double): CodeExpression
fun literal(value: Boolean): CodeExpression

literalNull

fun literalNull(): CodeExpression

logicalAnd

Join a series of expressions with a logical "and" operator (&&).

fun logicalAnd(expressions: List<CodeExpression>): CodeExpression
fun logicalAnd(vararg expressions: CodeExpression): CodeExpression

logicalOr

Join a series of expressions with a logical "or" operator (||).

fun logicalOr(expressions: List<CodeExpression>): CodeExpression
fun logicalOr(vararg expressions: CodeExpression): CodeExpression

methodInvoke

Generate a method invocation expression.

fun methodInvoke(context: CodeExpression, parameters: List<CodeExpression> = listOf()): CodeExpressionfun methodInvoke(context: CodeExpression, vararg parameters: CodeExpression): CodeExpression
fun methodInvoke(context: String, vararg parameters: CodeExpression): CodeExpression
fun methodInvoke(context: String, parameters: List<CodeExpression> = listOf()): CodeExpression

methodSpec

fun methodSpec(name: String, parameters: List<ParameterSpec> = emptyList(), modifiers: List<Modifier> = emptyList(), annotations: List<AnnotationSpec> = emptyList(), throws: List<TypeName> = emptyList(), varargs: Boolean = false, body: MethodCodeFunc? = null): MethodSpec
fun methodSpec(returns: TypeName, name: String, parameters: List<ParameterSpec> = emptyList(), modifiers: List<Modifier> = emptyList(), annotations: List<AnnotationSpec> = emptyList(), throws: List<TypeName> = emptyList(), varargs: Boolean = false, body: MethodCodeFunc? = null): MethodSpec
fun methodSpec(returns: Type, name: String, parameters: List<ParameterSpec> = emptyList(), modifiers: List<Modifier> = emptyList(), annotations: List<AnnotationSpec> = emptyList(), throws: List<TypeName> = emptyList(), varargs: Boolean = false, body: MethodCodeFunc? = null): MethodSpec
fun methodSpec(returns: KClass<*>, name: String, parameters: List<ParameterSpec> = emptyList(), modifiers: List<Modifier> = emptyList(), annotations: List<AnnotationSpec> = emptyList(), throws: List<TypeName> = emptyList(), varargs: Boolean = false, body: MethodCodeFunc? = null): MethodSpec

parameterSpec

fun parameterSpec(type: TypeName, name: String, final: Boolean = true, annotations: List<AnnotationSpec> = emptyList()): ParameterSpec
fun parameterSpec(type: Type, name: String, final: Boolean = true, annotations: List<AnnotationSpec> = emptyList()): ParameterSpec
fun parameterSpec(type: KClass<*>, name: String, final: Boolean = true, annotations: List<AnnotationSpec> = emptyList()): ParameterSpec