Skip to content

Commit 54589c8

Browse files
committed
Java: Add abstraction for discardable locatables
1 parent 0ee6a78 commit 54589c8

File tree

6 files changed

+48
-65
lines changed

6 files changed

+48
-65
lines changed

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

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2704,13 +2704,4 @@ class RecordPatternExpr extends Expr, @recordpatternexpr {
27042704
}
27052705

27062706
overlay[local]
2707-
private predicate discardableExpr(string file, @expr e) {
2708-
not isOverlay() and
2709-
file = getRawFile(e)
2710-
}
2711-
2712-
/** Discard base expressions in files fully extracted in the overlay. */
2713-
overlay[discard_entity]
2714-
private predicate discardExpr(@expr e) {
2715-
exists(string file | discardableExpr(file, e) and extractedInOverlay(file))
2716-
}
2707+
private class DiscardableExpr extends DiscardableLocatable, @expr { }

java/ql/lib/semmle/code/java/Javadoc.qll

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,4 @@ class KtCommentSection extends @ktcommentsection {
199199
}
200200

201201
overlay[local]
202-
private predicate discardableJavadoc(string file, @javadoc d) {
203-
not isOverlay() and
204-
exists(@member m | file = getRawFile(m) and hasJavadoc(m, d))
205-
}
206-
207-
/** Discard javadoc entities in files fully extracted in the overlay. */
208-
overlay[discard_entity]
209-
private predicate discardJavadoc(@javadoc d) {
210-
exists(string file | discardableJavadoc(file, d) and extractedInOverlay(file))
211-
}
202+
private class DiscardableJavadoc extends DiscardableLocatable, @javadoc { }

java/ql/lib/semmle/code/java/Member.qll

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -906,31 +906,12 @@ class ExtensionMethod extends Method {
906906
}
907907

908908
overlay[local]
909-
private predicate discardableMethod(string file, @method m) {
910-
not isOverlay() and
911-
file = getRawFile(m) and
912-
exists(@classorinterface c | methods(m, _, _, _, c, _) and isAnonymClass(c, _))
913-
}
914-
915-
/** Discard base methods on anonymous classes in files fully extracted in the overlay. */
916-
overlay[discard_entity]
917-
private predicate discardAnonMethod(@method m) {
918-
exists(string file | discardableMethod(file, m) and extractedInOverlay(file))
919-
}
920-
921-
overlay[local]
922-
private predicate discardableBaseMethod(string file, @method m) {
923-
not isOverlay() and
924-
file = getRawFile(m)
909+
private class DiscardableAnonymousMethod extends DiscardableLocatable, @method {
910+
DiscardableAnonymousMethod() {
911+
not isOverlay() and
912+
exists(@classorinterface c | methods(this, _, _, _, c, _) and isAnonymClass(c, _))
913+
}
925914
}
926915

927916
overlay[local]
928-
private predicate usedOverlayMethod(@method m) { isOverlay() and methods(m, _, _, _, _, _) }
929-
930-
/** Discard base methods in files fully extracted in the overlay that were not extracted in the overlay. */
931-
overlay[discard_entity]
932-
private predicate discardMethod(@method m) {
933-
exists(string file |
934-
discardableBaseMethod(file, m) and extractedInOverlay(file) and not usedOverlayMethod(m)
935-
)
936-
}
917+
private class DiscardableMethod extends DiscardableReferableLocatable, @method { }

java/ql/lib/semmle/code/java/Overlay.qll

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,41 @@ predicate extractedInOverlay(string file) {
3535
// ignore skeleton extracted files in the overlay
3636
exists(@locatable l | numlines(l, _, _, _) and file = getRawFile(l))
3737
}
38+
39+
/**
40+
* A `@locatable` in the base variant that should be discarded if its file is
41+
* extracted in the overlay variant.
42+
*/
43+
overlay[local]
44+
abstract class DiscardableLocatable extends @locatable {
45+
string getRawFileInBase() { not isOverlay() and result = getRawFile(this) }
46+
47+
string toString() { none() }
48+
}
49+
50+
overlay[discard_entity]
51+
private predicate discardLocatable(@locatable el) {
52+
extractedInOverlay(el.(DiscardableLocatable).getRawFileInBase())
53+
}
54+
55+
/**
56+
* A `@locatable` in the base variant that should be discarded if its file is
57+
* extracted in the overlay variant and it is itself not extracted in the
58+
* overlay, that is, it is deleted in the overlay.
59+
*/
60+
overlay[local]
61+
abstract class DiscardableReferableLocatable extends @locatable {
62+
string getRawFileInBase() { not isOverlay() and result = getRawFile(this) }
63+
64+
predicate existsInOverlay() { isOverlay() and exists(this) }
65+
66+
string toString() { none() }
67+
}
68+
69+
overlay[discard_entity]
70+
private predicate discardReferableLocatable(@locatable el) {
71+
exists(DiscardableReferableLocatable drl | drl = el |
72+
extractedInOverlay(drl.getRawFileInBase()) and
73+
not drl.existsInOverlay()
74+
)
75+
}

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

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -990,13 +990,4 @@ class SuperConstructorInvocationStmt extends Stmt, ConstructorCall, @superconstr
990990
}
991991

992992
overlay[local]
993-
private predicate discardableStmt(string file, @stmt s) {
994-
not isOverlay() and
995-
file = getRawFile(s)
996-
}
997-
998-
/** Discard base statements in files fully extracted in the overlay. */
999-
overlay[discard_entity]
1000-
private predicate discardStmt(@stmt s) {
1001-
exists(string file | discardableStmt(file, s) and extractedInOverlay(file))
1002-
}
993+
private class DiscardableStmt extends DiscardableLocatable, @stmt { }

java/ql/lib/semmle/code/java/Variable.qll

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,4 @@ class Parameter extends Element, @param, LocalScopeVariable {
136136
}
137137

138138
overlay[local]
139-
private predicate discardableLocalVarDecl(string file, @localscopevariable l) {
140-
not isOverlay() and
141-
file = getRawFile(l)
142-
}
143-
144-
/** Discard base local scoped variables in files fully extracted in the overlay. */
145-
overlay[discard_entity]
146-
private predicate discardLocalVarDecl(@localscopevariable l) {
147-
exists(string file | discardableLocalVarDecl(file, l) and extractedInOverlay(file))
148-
}
139+
private class DiscardableLocalScopeVariable extends DiscardableLocatable, @localscopevariable { }

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy