File tree Expand file tree Collapse file tree
java/ql/lib/semmle/code/java Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22 * Provides classes for working with Java expressions.
33 */
44
5- import Member
6- import Type
7- import Variable
8- import Statement
5+ import java
6+ import semmle.code.java.frameworks.android.Compose
97
108/** A common super-class that represents all kinds of expressions. */
119class Expr extends ExprParent , @expr {
@@ -161,6 +159,8 @@ class CompileTimeConstantExpr extends Expr {
161159 v .isFinal ( ) and
162160 v .getInitializer ( ) .isCompileTimeConstant ( )
163161 )
162+ or
163+ this instanceof LiveLiteral
164164 )
165165 }
166166
@@ -185,6 +185,8 @@ class CompileTimeConstantExpr extends Expr {
185185 exists ( Variable v | this = v .getAnAccess ( ) |
186186 result = v .getInitializer ( ) .( CompileTimeConstantExpr ) .getStringValue ( )
187187 )
188+ or
189+ result = this .( LiveLiteral ) .getValue ( ) .getStringValue ( )
188190 }
189191
190192 /**
@@ -297,6 +299,8 @@ class CompileTimeConstantExpr extends Expr {
297299 exists ( Variable v | this = v .getAnAccess ( ) |
298300 result = v .getInitializer ( ) .( CompileTimeConstantExpr ) .getBooleanValue ( )
299301 )
302+ or
303+ result = this .( LiveLiteral ) .getValue ( ) .getBooleanValue ( )
300304 }
301305
302306 /**
@@ -377,6 +381,8 @@ class CompileTimeConstantExpr extends Expr {
377381 result = v .getInitializer ( ) .( CompileTimeConstantExpr ) .getIntValue ( )
378382 )
379383 )
384+ or
385+ result = this .( LiveLiteral ) .getValue ( ) .getIntValue ( )
380386 }
381387}
382388
Original file line number Diff line number Diff line change 1+ /**
2+ * Provides classes and predicates for working with components generated by the Android's Jetpack Compose compiler.
3+ */
4+
5+ import java
6+
7+ /**
8+ * A call to a live literal method.
9+ * This always returns a constant expression and can be considered as such.
10+ */
11+ class LiveLiteral extends MethodAccess {
12+ CompileTimeConstantExpr value ;
13+
14+ LiveLiteral ( ) {
15+ this .getMethod ( ) instanceof LiveLiteralMethod and
16+ not this .getEnclosingCallable ( ) instanceof LiveLiteralMethod
17+ }
18+
19+ /** Gets the constant value that backs this live literal. */
20+ CompileTimeConstantExpr getValue ( ) {
21+ result =
22+ any ( ReturnStmt r | this .getMethod ( ) .calls * ( r .getEnclosingCallable ( ) ) )
23+ .getResult ( )
24+ .( VarAccess )
25+ .getVariable ( )
26+ .getInitializer ( )
27+ }
28+
29+ override string toString ( ) { result = this .getValue ( ) .toString ( ) }
30+ }
31+
32+ /** A live literal method. */
33+ class LiveLiteralMethod extends Method {
34+ LiveLiteralMethod ( ) { this .getDeclaringType ( ) .getName ( ) .matches ( "LiveLiterals$%" ) }
35+ }
You can’t perform that action at this time.
0 commit comments