JRXML Editor
A VS Code extension for working with JasperReports .jrxml files — focused on making expressions readable, editable and safer.
Features
1. Syntax highlighting
.jrxml files get a dedicated language mode with:
- JasperReports built-in functions (
TODAY, IF, SUM, MIN, MAX, …)
- Java keywords (
if, else, new, null, true, false, …)
- Java types (
String, Integer, BigDecimal, Date, …)
- Method calls and static calls
- Jasper field/param/variable references (
$F{name}, $P{name}, $V{name}, $R{name})
- String literals, numbers, comments and colorized brackets
2. Expression editor panel
Open any expression in a dedicated side panel:
- Edit pane — editable text area
- Preview pane — live syntax-highlighted view with bracket colorization
- Format button — auto-formats Java expressions into readable multi-line form:
- ternary chains → indented
? / : layout
- method chains → one call per line
- long
&& / || expressions → broken at operators
- long argument lists → one argument per line
- Apply to File — writes the edited expression back into the
.jrxml file (CDATA preserved)
- Copy / Reset — clipboard and revert to the original expression
- Keeps your edits — switching expressions or reopening the panel preserves unsaved text;
drafts are remembered per expression while the panel is open
- Auto-format on change checkbox — remembered via
jrxml.expressionEditor.autoFormat
Open it from the pencil icon in the editor title bar, the status bar, the JRXML submenu,
or with Ctrl+Alt+E (Cmd+Alt+E on macOS). Ctrl+Alt+B opens the If / Else builder.
3. If / Else expression builder
A visual builder for conditional expressions, opened on demand:
- Automatic schema — reads the open
.jrxml's fields, parameters and variables
(plus the JasperReports built-in variables and parameters) and offers them in name
dropdowns. There is no file upload; the lists refresh when the report is saved or its
declarations change.
- if / else if / else branches — conditions joined with AND/OR, typed comparisons
(String, Number, Boolean, null checks) or a raw Boolean expression.
- Two output styles — a nested ternary or the Jaspersoft
IF() / AND() / OR()
functions. Null-safe guards are written as inline ternaries in function style.
- Apply or copy — Apply writes the expression back into the expression tag the
builder was opened from (CDATA preserved, one undoable edit); Copy puts it on the
clipboard.
- Reverse conversion — paste an existing expression and load it back into the
branches. Anything that cannot be mapped becomes a Custom condition instead of being
dropped.
- Expression Editor hand-off — the expression editor's If / Else… button opens
the builder with the current text.
The builder starts with Null-safe and Multi-line on and ternary style; change the
defaults under jrxml.ifElse.* in Settings. Use JRXML: Open If / Else Builder from
the JRXML submenu or the command palette, with the cursor inside an expression tag to
enable Apply.
4. Bracket / parenthesis colorization
Inside the expression preview, brackets are colored by depth (level 1 gold, level 2 orchid, level 3 sky blue).
5. Diagnostics
Unused fields, parameters and variables
Undeclared $F/$P/$V references
Unbalanced parentheses and unclosed string literals
Structural lint rules ported from the project's commit-time myhooks hook:
jrxml.lint.constantPrintWhen — a <printWhenExpression> that is literally true or false
jrxml.lint.removeLineWhenBlank — a textField/subreport missing removeLineWhenBlank="true" (or with another value)
jrxml.lint.markupTagWithoutMarkup — markup tags inside a textField expression while markup is not styled, html or rtf
jrxml.lint.uncheckedNullDereference — a $F/$P/$V reference used as a method-call receiver without a dominating null check (short-circuit aware: != null &&, == null ||, ternaries, EQUALS(x, null), Objects.nonNull/isNull/equals)
The first three have quick fixes and can be switched off individually. The hook's structural
validate/compile gate is intentionally not ported (it needs the JasperReports engine).
Text check warnings — double spaces, a missing space after ., unrenderable characters and newline normalization, flagged inside <text> CDATA and inside string/text-block literals, each with a quick fix (jrxml.textcheck.diagnostics)
Outline, hover, go-to-definition and Find All References for $F{} / $P{} / $V{}
Act on issues — right-click an issue (or use its lightbulb) to open the offending
expression in the Expression Editor or the If / Else Builder
The Issues (JRXML), Best Practices (JRXML) and Include Chain (JRXML) views live under the extension's own JRXML icon in the Activity Bar. When no report is open, the Issues view shows quick-start actions.
6. Document formatting and text check
The hook's format + textcheck steps run through Format Document and the
source.fixAll.jrxml action "Fix all JRXML format and text issues":
- report name —
jasperReport/@name set to the file base name
- positionType — add/set
positionType="Float" on textField and subreport
- textAdjust — add/set
textAdjust="StretchHeight" on textField
- expression spacing —
== != < > >= <= && ||, ternaries, commas and
uppercase-reference casts. Generic type arguments, string/char/text-block literals and
$F{}/$P{}/$V{}/$P!{} references are left byte-for-byte untouched
- text check — replaces unrenderable characters, adds a space after
. before a capital,
collapses double spaces, and normalizes newlines to the element's markup token
Formatting only runs when you ask for it (Format Document, the fix-all action, or opt-in
jrxml.formatOnSave) and never reorders elements or deletes declarations.
7. Best practices
| Rule |
What it flags |
jrxml.bp001.booleanEquals |
==/!= on Boolean values → use EQUALS(...) / NOT(EQUALS(...)) |
Warnings can be suppressed per rule from the Best Practices (JRXML) view or the lightbulb menu; quick fixes remain available while suppressed. The former bp002/bp003 null-safety rules were retired in favour of the more precise jrxml.lint.uncheckedNullDereference diagnostic.
The view also lists file-level issues, each with an inline action:
- Elements are not sorted by position → opens the sort diff preview
- SQL query can be migrated to … → runs the SQL→jsonql migration
8. Clear fixes and geometry sort
Two destructive steps are opt-in commands, always previewed as a diff before applying:
- Clear fixes (
JRXML: Apply Clear Fixes) — delete unused declarations (never the
built-in parameters), sync field descriptions with their jsonql property, and fix the
legacy/jsonql property. Unused detection collects references from expressions only, so a
$F{x} inside a comment or description does not count as usage.
- SQL → jsonql (
JRXML: Migrate SQL Query to jsonql) — asks for the jsonql expression
and rewrites the <query> language and body; an empty answer applies nothing.
- Sort (
JRXML: Sort Band/Frame Elements by Position) — reorders each band/frame's
direct <element> children by y then x, moving each element's comment/property trivia
with it; missing coordinates and overlaps are reported as warnings.
9. Smart autocomplete
Context-aware completion for fields, parameters and variables, JasperReports built-ins, common Java statics, and user-defined public static helper methods discovered under src/main/java. The Java scan is cached and re-runs when .java files or workspace folders change.
Typed member completion. Typing . after a field, parameter or variable completes the Java members of its declared class:
| Expression |
Offered |
$F{CustomerName}. |
String members — substring(int, int), toUpperCase(), … |
$P{Total}. |
BigDecimal members — add(BigDecimal), setScale(int, RoundingMode), … |
$V{Count}. |
Integer members — intValue(), compareTo(Integer), … |
$P{REPORT_DATA_SOURCE}. |
JRDataSource members — next(), getFieldValue(String) |
$F{Name}.trim(). |
members of trim()'s return type, up to a few calls deep |
Members are ranked with the most used first, overloads are listed with their parameter types, each item inserts a snippet with named placeholders (substring(${1:n}, ${2:n2})) and the documentation names the declaring type. Inherited members are offered too, marked as inherited and sorted after the type's own. Deprecated members are flagged. String.length on a $F{...} whose value can be null still triggers the unchecked null dereference warning — member completion does not change that rule.
The member table ships with the extension (data/jdk-members.json, generated from javap by npm run gen:jdk-index) and covers JDK types plus a few JasperReports engine types (data/extra-types.json). Project classes from src/main/java are not indexed yet, so a parameter typed as your own class completes nothing instead of guessing.
Target Java version. jrxml.typeCompletion.jdkBaseline (default 8) hides members that do not exist on your target JDK, so a Java 8 report is never offered String.isBlank or List.getFirst. Set it to 11, 17 or 21 when your reports compile against a newer JDK.
When a receiver cannot be typed, completion says so instead of showing an unrelated list:
- no
class attribute on the declaration → an item explaining that the type is inferred by JasperReports, with the XML to declare it;
- a class outside the index → an item naming the class that is not covered;
- a short name that matches several types (
Date) → an item listing the candidates, so you can write the full class name.
jrxml.typeCompletion.enabled (default true) turns the whole thing off and restores the previous behaviour.
Expression snippets. Type a snippet prefix in an expression to insert a common pattern:
jif (IF(...)), jternary, jnullsafe, jand, jor, jnot, jequals, jtext,
jstring, jdecimal and jdate.
Date/time helpers: jdatetoday (format TODAY()), jdateadd (TODAY() + N days),
jdateadddate, jdatetodaybefore / jdatetodayafter, jparsedate (string → Date),
jdatecompare (two string dates), jnow, jdatediff, jdatetodaytz (report time zone)
and jdatetodaylocale (report locale).
10. Settings panel
JRXML: Open Settings opens a dedicated panel with every jrxml.* setting grouped by area (Editor, Diagnostics, Formatting, Clear and migration, Sort, Best practices). Toggles are bound live to workspace settings — the panel, VS Code's own Settings UI and the running features always agree — with a filter box and "Reset all to defaults". The panel schema is cross-checked against package.json by a test, so it cannot drift.
11. Include chain view
The Include Chain (JRXML) view sits below Best Practices in the JRXML Activity Bar view and answers "where is the report I have open called from?". For the active .jrxml it renders the chain top-down: the top template(s) that ultimately include it, nested down to the open file, which is highlighted as (current file). Nodes are workspace-relative paths and open the file on click; a report nothing calls shows (not referenced).
A file calls another when it contains a double-quoted token equal to that file's base name (the commit-hook rule), so subreports are picked up however their expression is written. The workspace is scanned once (**/*.jrxml, excluding node_modules/out/target/bin), cached by file mtime, and refreshed when the active editor changes, on edits and saves, on file create/delete/rename and on workspace-folder changes — or manually via JRXML: Refresh Include Chain.
Usage
- Open any
.jrxml file
- Place your cursor inside an expression tag (e.g.
<textFieldExpression>)
- Either:
- Right-click → JRXML: Open Expression Editor
- Click the pencil icon in the editor title bar
- Click
$(edit) JRXML Expr in the status bar, press Ctrl+Alt+E, or run JRXML: Open Expression Editor from the command palette
- To build the same expression visually, right-click → JRXML: Open If / Else Builder
(or use the If / Else… button inside the expression editor, or
Ctrl+Alt+B). The
builder reads the open report's fields, parameters and variables automatically;
Apply to File writes the result back into the expression tag under the cursor.
- The JRXML icon in the Activity Bar holds the Issues, Best Practices and Include
Chain views for the report you have open.
- New here? The Get started with JRXML walkthrough (Welcome page) walks through the
editor, formatting, issue fixes and the If / Else builder.
Commands
| Command |
Description |
JRXML: Open Expression Editor |
Open the expression under the cursor in the side panel |
JRXML: Open If / Else Builder |
Build the expression under the cursor as if / else-if / else branches |
JRXML: Format Expression at Cursor |
Format only the expression under the cursor (CDATA preserved) |
JRXML: Edit Issue in Expression Editor |
Open the expression behind an issue in the Expression Editor |
JRXML: Edit Issue in If / Else Builder |
Open the expression behind an issue in the If / Else Builder |
JRXML: Go to Declaration |
Jump from $F{}/$P{}/$V{} to its declaration |
JRXML: Refresh Best Practices |
Re-run the best-practice rules |
JRXML: Suppress Best Practice Rule |
Hide squiggles for a rule (quick fixes stay) |
JRXML: Re-enable Best Practice Rule |
Restore squiggles for a rule |
JRXML: Jump to Issue |
Move the cursor to a reported best-practice hit |
JRXML: Sort Band/Frame Elements by Position |
Reorder band/frame elements by geometry (previewed) |
JRXML: Apply Clear Fixes |
Delete unused declarations, sync descriptions, fix jsonql (previewed) |
JRXML: Migrate SQL Query to jsonql |
Prompt for jsonql and rewrite the <query> element |
JRXML: Open Settings |
Open the dedicated JRXML settings panel |
JRXML: Refresh Include Chain |
Re-scan the workspace for the include-chain view |
Settings
| Setting |
Default |
Description |
jrxml.indentSize |
4 |
Spaces per indent level when formatting expressions |
jrxml.autoOpenEditor |
false |
Auto-open the editor when the cursor enters an expression |
jrxml.expressionEditor.autoFormat |
false |
Remember the Expression Editor's Auto-format on change setting |
jrxml.ifElse.nullSafe |
true |
Start the If / Else builder with null-safe guards |
jrxml.ifElse.multiline |
true |
Start the If / Else builder with multi-line output |
jrxml.ifElse.style |
ternary |
Default If / Else output style (ternary or functions) |
jrxml.showUnusedWarnings |
true |
Warn about declared fields/parameters/variables that are never used |
jrxml.validateExpressions |
true |
Error on unbalanced parentheses, unclosed strings and undeclared $F/$P/$V references |
jrxml.lint.constantPrintWhen |
true |
Warn when <printWhenExpression> is a constant true/false |
jrxml.lint.removeLineWhenBlank |
true |
Warn when a textField/subreport is missing removeLineWhenBlank="true" |
jrxml.lint.markupTagWithoutMarkup |
true |
Warn when markup tags are used without markup="styled"/html/rtf |
jrxml.lint.nullDereference |
true |
Warn on an unguarded $F/$P/$V method-call receiver |
jrxml.format.reportName |
true |
Set jasperReport/@name to the file base name |
jrxml.format.positionType |
true |
Add/set positionType="Float" on textField/subreport |
jrxml.format.textAdjust |
true |
Add/set textAdjust="StretchHeight" on textField |
jrxml.format.expression |
true |
Normalize expression operator/ternary/comma/cast spacing |
jrxml.textcheck.enabled |
true |
Rendered-text rules in text and string literals |
jrxml.textcheck.diagnostics |
true |
Show warnings + quick fixes for text-check problems |
jrxml.formatOnSave |
false |
Run format + textcheck on save (never clear/sort) |
jrxml.sort.preview |
true |
Show a diff and confirm before applying the geometry sort |
jrxml.clear.preview |
true |
Show a diff and confirm before applying clear fixes or a SQL migration |
jrxml.migrate.targetLanguage |
jsonql |
Language written to <query language="..."> when migrating a SQL query |
jrxml.suppressedBestPractices |
[] |
Best-practice rule IDs whose squiggles are hidden |
Installation
From a .vsix file
- Open VS Code
Ctrl+Shift+P → Extensions: Install from VSIX...
- Select the packaged
jrxml-editor-extension-<version>.vsix (build it with npm run package)
Manual (development)
npm install
Press F5 in VS Code to launch the Extension Development Host.
Tests and linting
npm test # node:test unit suite (parser, formatter, rules, webview HTML)
npm run test:integration # Extension Host smoke suite (@vscode/test-cli; downloads VS Code)
npm run lint # eslint
The unit suite runs on plain Node with no VS Code needed. The integration suite
activates the extension for real and covers command registration, diagnostics,
the sort/clear commands (preview disabled), document formatting and the settings
panel. On a headless Linux box run it under xvfb-run -a npm run test:integration.
Releasing
The Build VSIX workflow can bump the version for you:
- In GitHub, open Actions → Build VSIX → Run workflow.
- Pick the default branch (
master) and a bump: patch, minor, major, or none.
- Run it.
A bump run on the default branch:
- updates
package.json, package-lock.json and the CHANGELOG.md heading through npm version,
- commits
chore(release): <version> and tags v<version>,
- packages the VSIX, uploads the artifact and creates the GitHub release with the VSIX attached.
none rebuilds the current version without a commit, tag, or release. Normal pushes
to master/main and v* tags keep packaging only; a tag build also attaches the
VSIX to the release and fails if the tag does not match package.json.
The bump is pushed with the workflow's GITHUB_TOKEN, so it does not trigger a
second run, and the repository must allow GitHub Actions to push to the default
branch. If that push fails, no tag is created and the VSIX is still available as a
workflow artifact.
Locally, npm version patch performs the same version + changelog update, commit,
and tag; push with git push --follow-tags.
The editor activates for cursor positions inside any of these tags:
textFieldExpression, imageExpression, variableExpression, groupExpression,
printWhenExpression, initialValueExpression, filterExpression, expression,
jr:expression, defaultValueExpression, hyperlinkReferenceExpression,
subreportExpression, bucketExpression, keyExpression, valueExpression,
categoryExpression, seriesExpression, labelExpression, and more.
Security notes
The expression editor and If / Else builder webviews are rendered with a nonce-based Content-Security-Policy and no inline event handlers or style attributes. Expression text, file names and declaration names are escaped (or embedded as JSON-escaped data) before they reach the panel, so .jrxml content cannot inject script. The builder loads no remote resources and reads the report schema in the extension host, not in the webview. Hovers are rendered as untrusted markdown.