-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Migration Guide 3.25.10 to 3.26.0
JavaParser version 3.26.0 brings in support for java 21 features that required changes to switch entries and pattern expressions.
In JavaParser versions before 3.26.0, pattern matching was limited to instanceof
expressions, but from JavaParser 3.26.0 onwards, patterns are also supported as labels in switch expression entries, for example
switch (o) {
case String s -> ...
}
Since switch entry labels are are already of type Expression
, no API changes were made to support this, but it is mentioned here as it is used in some of the examples below.
In Java 21, it is possible to have a combined null
and default
case for switch expressions, for example:
switch (o) {
case String s -> ...
case null, default -> ...
}
This means that checking for an empty label list in a SwitchEntry
of a switch expression is no longer sufficient to determine whether an entry is the default or not. A new isDefault
field was therefore added so, from JavaParser 3.26.0 onwards, switchEntry.isDefault()
should be used to determine whether an entry is the default case.
In JavaParser versions up to and including 3.25.10, the PatternExpr
node was used to represent type pattern expressions of the form
input instanceof String s
but Java 21 added support for record patterns which can be used to pattern match on fields of records, for example
input instanceof Box(String s)
In JavaParser 3.26.0, there are 2 new pattern nodes: TypePatternExpr
and RecordPatternExpr
. TypePatternExpr
is used to represent type pattern expressions and is therefore identical to PatternExpr
from JavaParser 3.25.10. RecordPatternExpr
is used to represent the new record pattern expression. PatternExpr
has been repurposed and is now a common base class for TypePatternExpr
and RecordPatternExpr
This means that, when upgrading, everywhere PatternExpr
was being handled with JavaParser < 3.26.0, there are now 2 cases which must be handled separately. If the PatternExpr
is a TypePatternExpr
, then it should be handled the same as the old PatternExpr
, except with a new name. Only the RecordPatternExpr
case is brand new.
Website: JavaParser.org Chat: Gitter.im/JavaParser/JavaParser Free eBook: leanpub.com/JavaParserVisited
- Home
- Migration Guide (2.5.1 to 3.0.0)
- Migration Guide (3.25.10 to 3.26.0)
- Inspecting an AST
JavaParser
vsStaticJavaParser
Pro* jectRoot
vsSourceRoot
(Analysing a Whole Project)- Parsing Java Comments
- Getting started with JavaParser: analyzing Java Code programmatically
- Observers for AST nodes in JavaParser
- Implementing Lexical Preservation for JavaParser
- JavaParser’s logging framework in one file
- Making strings in JavaParser
- The quick and the full API of JavaParser
- Less Casting in JavaParser
- Parse error recovery
- Inverting ifs in JavaParser
- Code generation and Maven in JavaParser
- Semantic validations in JavaParser
- Setting Java 8, 9, 10, etc
- Analysing an entire project in one go
- Pragmatic Versioning
- Testing JavaParser Code
- Functional Tree Traversal
- Coding Guidelines
- Eclipse Project Setup Guide
- Code Style / Architecture
- Build Process
- Release Process
- A Detailed Guide to Adding New Nodes and Fields
Visit the JavaParser blog
Download the JavaParserVisited book (free!).
Join the chatroom on Gitter!