Skip to content

Commit b25b6f7

Browse files
authored
Merge pull request github#3210 from yo-h/java14-ql
Java: dbscheme and library changes related to Java 14 extractor upgrade
2 parents 965235a + 2b3ad60 commit b25b6f7

File tree

11 files changed

+1954
-19
lines changed

11 files changed

+1954
-19
lines changed

docs/language/support/versions-compilers.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
.NET Core up to 3.0","``.sln``, ``.csproj``, ``.cs``, ``.cshtml``, ``.xaml``"
1717
Go (aka Golang), "Go up to 1.14", "Go 1.11 or more recent", ``.go``
18-
Java,"Java 6 to 13 [4]_","javac (OpenJDK and Oracle JDK),
18+
Java,"Java 6 to 14 [4]_","javac (OpenJDK and Oracle JDK),
1919

2020
Eclipse compiler for Java (ECJ) [5]_",``.java``
2121
JavaScript,ECMAScript 2019 or lower,Not applicable,"``.js``, ``.jsx``, ``.mjs``, ``.es``, ``.es6``, ``.htm``, ``.html``, ``.xhm``, ``.xhtml``, ``.vue``, ``.json``, ``.yaml``, ``.yml``, ``.raml``, ``.xml`` [6]_"
@@ -27,7 +27,7 @@
2727
.. [1] Support for the clang-cl compiler is preliminary.
2828
.. [2] Support for the Arm Compiler (armcc) is preliminary.
2929
.. [3] In addition, support is included for the preview features of C# 8.0 and .NET Core 3.0.
30-
.. [4] Builds that execute on Java 6 to 12 can be analyzed. The analysis understands Java 12 language features.
30+
.. [4] Builds that execute on Java 6 to 14 can be analyzed. The analysis understands Java 14 standard language features.
3131
.. [5] ECJ is supported when the build invokes it via the Maven Compiler plugin or the Takari Lifecycle plugin.
3232
.. [6] JSX and Flow code, YAML, JSON, HTML, and XML files may also be analyzed with JavaScript files.
3333
.. [7] TypeScript analysis is performed by running the JavaScript extractor with TypeScript enabled. This is the default for LGTM.

java/ql/src/config/semmlecode.dbscheme

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,10 @@ classes(
268268
int sourceid: @class ref
269269
);
270270

271+
isRecord(
272+
unique int id: @class ref
273+
);
274+
271275
interfaces(
272276
unique int id: @interface,
273277
string nodeName: string ref,

java/ql/src/config/semmlecode.dbscheme.stats

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9263,6 +9263,17 @@
92639263
</dependencies>
92649264
</relation>
92659265
<relation>
9266+
<name>isRecord</name>
9267+
<cardinality>100</cardinality>
9268+
<columnsizes>
9269+
<e>
9270+
<k>id</k>
9271+
<v>100</v>
9272+
</e>
9273+
</columnsizes>
9274+
<dependencies/>
9275+
</relation>
9276+
<relation>
92669277
<name>interfaces</name>
92679278
<cardinality>249736</cardinality>
92689279
<columnsizes>

java/ql/src/semmle/code/java/Expr.qll

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,8 +1076,6 @@ class ConditionalExpr extends Expr, @conditionalexpr {
10761076
}
10771077

10781078
/**
1079-
* PREVIEW FEATURE in Java 13. Subject to removal in a future release.
1080-
*
10811079
* A `switch` expression.
10821080
*/
10831081
class SwitchExpr extends Expr, @switchexpr {
@@ -1132,7 +1130,25 @@ deprecated class ParExpr extends Expr, @parexpr {
11321130
/** An `instanceof` expression. */
11331131
class InstanceOfExpr extends Expr, @instanceofexpr {
11341132
/** Gets the expression on the left-hand side of the `instanceof` operator. */
1135-
Expr getExpr() { result.isNthChildOf(this, 0) }
1133+
Expr getExpr() {
1134+
if isPattern()
1135+
then result = getLocalVariableDeclExpr().getInit()
1136+
else result.isNthChildOf(this, 0)
1137+
}
1138+
1139+
/**
1140+
* PREVIEW FEATURE in Java 14. Subject to removal in a future release.
1141+
*
1142+
* Holds if this `instanceof` expression uses pattern matching.
1143+
*/
1144+
predicate isPattern() { exists(getLocalVariableDeclExpr()) }
1145+
1146+
/**
1147+
* PREVIEW FEATURE in Java 14. Subject to removal in a future release.
1148+
*
1149+
* Gets the local variable declaration of this `instanceof` expression if pattern matching is used.
1150+
*/
1151+
LocalVariableDeclExpr getLocalVariableDeclExpr() { result.isNthChildOf(this, 0) }
11361152

11371153
/** Gets the access to the type on the right-hand side of the `instanceof` operator. */
11381154
Expr getTypeName() { result.isNthChildOf(this, 1) }
@@ -1163,6 +1179,8 @@ class LocalVariableDeclExpr extends Expr, @localvariabledeclexpr {
11631179
exists(ForStmt fs | fs.getAnInit() = this | result.isNthChildOf(fs, 0))
11641180
or
11651181
exists(EnhancedForStmt efs | efs.getVariable() = this | result.isNthChildOf(efs, -1))
1182+
or
1183+
exists(InstanceOfExpr ioe | this.getParent() = ioe | result.isNthChildOf(ioe, 1))
11661184
}
11671185

11681186
/** Gets the name of the variable declared by this local variable declaration expression. */

java/ql/src/semmle/code/java/Statement.qll

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -417,8 +417,6 @@ class SwitchCase extends Stmt, @case {
417417
SwitchStmt getSwitch() { result.getACase() = this }
418418

419419
/**
420-
* PREVIEW FEATURE in Java 13. Subject to removal in a future release.
421-
*
422420
* Gets the switch expression to which this case belongs, if any.
423421
*/
424422
SwitchExpr getSwitchExpr() { result.getACase() = this }
@@ -432,8 +430,6 @@ class SwitchCase extends Stmt, @case {
432430
}
433431

434432
/**
435-
* PREVIEW FEATURE in Java 13. Subject to removal in a future release.
436-
*
437433
* Holds if this `case` is a switch labeled rule of the form `... -> ...`.
438434
*/
439435
predicate isRule() {
@@ -443,15 +439,11 @@ class SwitchCase extends Stmt, @case {
443439
}
444440

445441
/**
446-
* PREVIEW FEATURE in Java 13. Subject to removal in a future release.
447-
*
448442
* Gets the expression on the right-hand side of the arrow, if any.
449443
*/
450444
Expr getRuleExpression() { result.getParent() = this and result.getIndex() = -1 }
451445

452446
/**
453-
* PREVIEW FEATURE in Java 13. Subject to removal in a future release.
454-
*
455447
* Gets the statement on the right-hand side of the arrow, if any.
456448
*/
457449
Stmt getRuleStatement() { result.getParent() = this and result.getIndex() = -1 }
@@ -465,8 +457,6 @@ class ConstCase extends SwitchCase {
465457
Expr getValue() { result.getParent() = this and result.getIndex() = 0 }
466458

467459
/**
468-
* PREVIEW FEATURE in Java 13. Subject to removal in a future release.
469-
*
470460
* Gets the `case` constant at the specified index.
471461
*/
472462
Expr getValue(int i) { result.getParent() = this and result.getIndex() = i and i >= 0 }
@@ -624,8 +614,6 @@ class BreakStmt extends Stmt, @breakstmt {
624614
}
625615

626616
/**
627-
* PREVIEW FEATURE in Java 13. Subject to removal in a future release.
628-
*
629617
* A `yield` statement.
630618
*/
631619
class YieldStmt extends Stmt, @yieldstmt {

java/ql/src/semmle/code/java/Type.qll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,15 @@ class Class extends RefType, @class {
615615
}
616616
}
617617

618+
/**
619+
* PREVIEW FEATURE in Java 14. Subject to removal in a future release.
620+
*
621+
* A record declaration.
622+
*/
623+
class Record extends Class {
624+
Record() { isRecord(this) }
625+
}
626+
618627
/** An intersection type. */
619628
class IntersectionType extends RefType, @class {
620629
IntersectionType() {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
//semmle-extractor-options: --javac-args --enable-preview -source 13 -target 13
1+
//semmle-extractor-options: --javac-args -source 14 -target 14

java/ql/test/library-tests/structure/DeclaresMember.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
| LocalClass | LocalClass |
2929
| LocalClass | n |
3030
| MemberClass | MemberClass |
31-
| Object | <clinit> |
3231
| Object | Object |
3332
| Object | clone |
3433
| Object | equals |

0 commit comments

Comments
 (0)