Skip to content

Commit 971ced0

Browse files
authored
Merge pull request github#14671 from smowton/smowton/feature/jdk21-switch-pattern-matching
Java: Add support for Java 21 language features
2 parents eccc373 + aa8f798 commit 971ced0

File tree

105 files changed

+7896
-205
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+7896
-205
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
class Expr extends @expr {
2+
string toString() { result = "expr" }
3+
}
4+
5+
class LocalVariableDeclExpr extends @localvariabledeclexpr, Expr { }
6+
7+
class InstanceOfExpr extends @instanceofexpr, Expr { }
8+
9+
class SimplePatternInstanceOfExpr extends InstanceOfExpr {
10+
SimplePatternInstanceOfExpr() { getNthChild(this, 2) instanceof LocalVariableDeclExpr }
11+
}
12+
13+
class Type extends @type {
14+
string toString() { result = "type" }
15+
}
16+
17+
class ExprParent extends @exprparent {
18+
string toString() { result = "exprparent" }
19+
}
20+
21+
Expr getNthChild(ExprParent parent, int i) { exprs(result, _, _, parent, i) }
22+
23+
// Where an InstanceOfExpr has a 2nd child that is a LocalVariableDeclExpr, that expression should becomes its 0th child and the existing 0th child should become its initialiser.
24+
// Any RecordPatternExpr should be replaced with an error expression, as it can't be represented in the downgraded dbscheme.
25+
// This reverts a reorganisation of the representation of "o instanceof String s", which used to be InstanceOfExpr -0-> LocalVariableDeclExpr --init-> o
26+
// \-name-> s
27+
// It is now InstanceOfExpr --0-> o
28+
// \-2-> LocalVariableDeclExpr -name-> s
29+
//
30+
// Other children are unaffected.
31+
predicate hasNewParent(Expr e, ExprParent newParent, int newIndex) {
32+
exists(SimplePatternInstanceOfExpr oldParent, int oldIndex |
33+
e = getNthChild(oldParent, oldIndex)
34+
|
35+
oldIndex = 0 and newParent = getNthChild(oldParent, 2) and newIndex = 0
36+
or
37+
oldIndex = 1 and newParent = oldParent and newIndex = oldIndex
38+
or
39+
oldIndex = 2 and newParent = oldParent and newIndex = 0
40+
)
41+
or
42+
not exists(SimplePatternInstanceOfExpr oldParent | e = getNthChild(oldParent, _)) and
43+
exprs(e, _, _, newParent, newIndex)
44+
}
45+
46+
from Expr e, int oldKind, int newKind, Type typeid, ExprParent parent, int index
47+
where
48+
exprs(e, oldKind, typeid, _, _) and
49+
hasNewParent(e, parent, index) and
50+
(
51+
if oldKind = /* record pattern */ 89
52+
then newKind = /* error expression */ 74
53+
else oldKind = newKind
54+
)
55+
select e, newKind, typeid, parent, index

0 commit comments

Comments
 (0)