Merge 'pmd6-java-20' into pmd7-java-20

This commit is contained in:
Andreas Dangel
2023-02-04 19:10:37 +01:00
46 changed files with 2103 additions and 2674 deletions

View File

@ -1,4 +1,13 @@
/**
* Support "JEP 433: Pattern Matching for switch (Fourth Preview)" for Java 20 Preview
* SwitchLabel simplified
* Support "JEP 432: Record Patterns (Second Preview)" for Java 20 Preview
* ForStatement allows record patterns
* Removed named record patterns (optional VariableDeclaratorId following the pattern)
* Remove support for Java 18 preview language features
* GuardedPattern is removed
* Andreas Dangel 02/2023
*====================================================================
* Support "JEP 427: Pattern Matching for switch (Third Preview)" for Java 19 Preview
* Note: GuardedPattern is deprecated and only valid for 17-preview and 18-preview
* New AST node: ASTSwitchGuard (production "Guard") - used within switch case labels for refining a pattern
@ -1733,13 +1742,7 @@ void Pattern() #void:
{
LOOKAHEAD((Annotation())* ReferenceType() "(") RecordPattern()
| LOOKAHEAD("(") ParenthesizedPattern()
| TypePattern() [ LOOKAHEAD({getToken(1).kind == SC_AND && jdkVersion < 19}) GuardedPatternCondition() #GuardedPattern(2) ]
}
void GuardedPatternCondition() #void:
{}
{
"&&" ConditionalAndExpression()
| TypePattern()
}
void ParenthesizedPattern() #void:
@ -1757,7 +1760,7 @@ void TypePattern():
void RecordPattern():
{}
{
(Annotation())* ReferenceType() RecordStructurePattern() [ VariableDeclaratorId() ]
(Annotation())* ReferenceType() RecordStructurePattern()
}
void RecordStructurePattern() #ComponentPatternList:
@ -1782,13 +1785,6 @@ void InstanceOfExpression() #void:
| AnnotatedRefType() [
VariableDeclaratorId() #TypePattern(2)
| RecordStructurePattern() #RecordPattern(2)
[ VariableDeclaratorId()
{
AbstractJavaNode id = jjtree.popNode();
ASTRecordPattern pat = (ASTRecordPattern) jjtree.peekNode();
pat.addChild(id, pat.getNumChildren());
}
]
]
| Pattern()
)
@ -2481,7 +2477,15 @@ void SwitchLabel() :
void CaseLabelElement(ASTSwitchLabel label) #void:
{}
{
"default" {label.setDefault();}
"default" {label.setDefault();} // only valid in java-19-preview
|
"null" #NullLiteral
[
// this lookahead is only required to allow parsing java-19-preview code
// since java-20-preview, combining null is only allowed with default
LOOKAHEAD(2)
"," "default" {label.setDefault();}
]
|
LOOKAHEAD(Pattern()) Pattern() {
AbstractJavaNode top = jjtree.popNode();
@ -2540,8 +2544,8 @@ void ForStatement() #void:
{
t="for" "("
(
LOOKAHEAD(LocalVariableDeclaration() ":")
(LocalVariableDeclaration() ":" Expression() ")" Statement() { jjtThis.setFirstToken(t); }) #ForeachStatement
LOOKAHEAD(EnhancedForDeclaration() ":")
(EnhancedForDeclaration() ":" Expression() ")" Statement() { jjtThis.setFirstToken(t); }) #ForeachStatement
| (
[ ForInit() ] ";"
[ Expression() ] ";"
@ -2552,6 +2556,13 @@ void ForStatement() #void:
)
}
void EnhancedForDeclaration() #void:
{}
{
LOOKAHEAD(LocalVariableDeclaration()) LocalVariableDeclaration()
| RecordPattern()
}
void ForInit() :
{}
{