module
Noir::JvmLiteral
Overview
The request-ready value a JVM-family (Java / Kotlin / Scala) default expression evaluates to.
A field initialiser or route default is source, not a value, and
Param#value is what every HTTP-shaped consumer puts on the wire — the
curl / httpie / PowerShell builders, the --data-raw JSON body, and the
OAS builders, which publish a non-empty value as an enum entry on the
parameter. So a default that has no literal form has no value either, and
passing the source text through produced things like
{"slug":"title.toSlug()"}, {"addedAt":"LocalDateTime.now()"} and
/api/list-all?version=null.
Shared rather than per-analyzer because Kotlin's and Java's tree-sitter
parameter extractors and both Play routes analyzers were each about to
grow their own copy of the same three-line check, and two of them already
had byte-identical normalize_route_default_value bodies.
Extended Modules
Defined in:
utils/jvm_literal.crConstant Summary
-
ABSENT =
["null", "None", "Nil", "nil", "Optional.empty", "Optional.empty()", "Option.empty", "Option.empty()"] of ::String -
Spellings of "no value": Java/Scala
null, Kotlin/ScalaNone, Scala/GroovyNil/nil, and the empty-optional factories. -
NUMERIC_SUFFIXES =
"LlFfDd" -
Numeric literal type suffixes (
10L,1.5f,2.0d). Stripped before the numeric test so a suffixed literal is still recognised as one, and emitted without the suffix —?page=10Lis not a page number.
Instance Method Summary
-
#value_of(expr : String) : String
Returns "" when
expris not a literal.
Instance Method Detail
Returns "" when expr is not a literal. Callers store the result
directly in Param#value, where "" already means "no value recorded".