This document describes all public functions in io.github.bpj.BPJ.
BPJ placeholders use braces:
{name}{user.name}{user.getName()}
Root token:
- The first segment (
name,user) is resolved from context.
Nested token:
- Remaining segments (
nameinuser.name) are resolved through:Mapkeys- record components
- getters (
getX,isX, and exact method name) - fields (including inherited fields)
- no-arg method calls when token ends with
()
Escaping:
{{is rendered as literal{}}is rendered as literal}
Method call limits:
- Only zero-argument method calls are supported in placeholders (for example
{user.getName()}). - Method arguments are not supported inside placeholders.
BPJ can resolve placeholders from:
- Explicit map context per call
- Explicit root object per call
- Explicit key-value pairs per call
- Thread-bound context stack (
bind(...))
When multiple bound scopes exist, BPJ resolves from the most recent scope first.
BPJ can highlight resolved placeholder values using ANSI escape codes.
Default color:
BPJ.AnsiColor.CYAN
Configuration:
BPJ.setHighlightColor(...)BPJ.getHighlightColor()
Highlighted rendering methods:
formatHighlighted(...)printHighlighted(...)printlnHighlighted(...)
Returns true if at least one context scope is currently bound in the current thread.
Clears all bound scopes in the current thread.
Use this only for defensive cleanup in managed thread scenarios. Prefer try-with-resources.
Returns the default ANSI color used by highlighted methods.
Changes the default ANSI color used by highlighted methods.
Binds a map scope to the current thread.
Use in try-with-resources:
try (BPJ.Scope ignored = BPJ.bind(Map.of("name", "Ana"))) {
BPJ.println("Hello {name}");
}Binds a root object scope.
If context is a Map, BPJ treats it as map context.
Binds key-value pairs as map context.
The array length must be even and keys must be String.
Formats using currently bound scopes.
If no scope is bound:
- returns template unchanged (except escaped braces normalization).
Important:
- This overload does not automatically read local method variables.
- For "zero extra args" with locals, use Maven/Gradle BPJ source transformation.
Formats using explicit map context.
Formats using explicit root object or map.
Formats using explicit key-value pairs.
Formats using bound scopes and applies ANSI color to resolved placeholder values.
Formats using explicit map context and applies ANSI color to resolved placeholder values.
Formats using explicit root context (or map) and applies ANSI color to resolved placeholder values.
Formats using explicit key-value context and applies ANSI color to resolved placeholder values.
Strict format with bound scopes.
Throws IllegalArgumentException when any placeholder is unresolved.
Strict format with explicit map context.
Strict format with explicit root context (or map).
Strict format with explicit key-value context.
Prints formatted output (no newline), resolving against bound scopes.
Prints formatted output (no newline), resolving against explicit map context.
Prints formatted output (no newline), resolving against explicit root context.
Prints formatted output (no newline), resolving against explicit key-value context.
Prints highlighted formatted output (no newline), resolving against bound scopes.
Prints highlighted formatted output (no newline), resolving against explicit map context.
Prints highlighted formatted output (no newline), resolving against explicit root context.
Prints highlighted formatted output (no newline), resolving against explicit key-value context.
Prints formatted output with newline, resolving against bound scopes.
Prints formatted output with newline, resolving against explicit map context.
Prints formatted output with newline, resolving against explicit root context.
Prints formatted output with newline, resolving against explicit key-value context.
Prints highlighted formatted output with newline, resolving against bound scopes.
Prints highlighted formatted output with newline, resolving against explicit map context.
Prints highlighted formatted output with newline, resolving against explicit root context.
Prints highlighted formatted output with newline, resolving against explicit key-value context.
BPJ.Scope is AutoCloseable:
- Closing is idempotent.
- Closing out of stack order throws
IllegalStateException.
This enforces deterministic lifecycle for nested contexts:
try (BPJ.Scope outer = BPJ.bind("name", "A")) {
try (BPJ.Scope inner = BPJ.bind("name", "B")) {
BPJ.println("{name}"); // B
}
BPJ.println("{name}"); // A
}Non-strict (format / print / println):
- unresolved placeholders remain unchanged (
{missing})
Strict (formatStrict):
- unresolved placeholders throw
IllegalArgumentException
IllegalArgumentException:
- unresolved placeholder in strict mode
- odd varargs length in key-value API
- non-string keys in key-value API
- non-string keys in
Mapcontexts
IllegalStateException:
- reflection access issues for object property resolution
- out-of-order scope close
Bound scopes are thread-local:
- Each thread has independent context stack.
- Context does not cross thread boundaries automatically.