Skip to content

Commit 46b8fbc

Browse files
Jami CogswellJami Cogswell
authored andcommitted
Java: update remaining models, resolve merge conflict
1 parent 1506925 commit 46b8fbc

File tree

11 files changed

+214
-182
lines changed

11 files changed

+214
-182
lines changed

csharp/ql/lib/semmle/code/csharp/dataflow/internal/FlowSummaryImpl.qll

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,12 @@ module Public {
244244
* Holds if the summary is auto generated.
245245
*/
246246
predicate isAutoGenerated() { none() }
247+
248+
/**
249+
* Holds if the summary has the given provenance where `true` is
250+
* `generated` and `false` is `manual`.
251+
*/
252+
predicate hasProvenance(boolean generated) { none() } // ! merge with PR #11585
247253
}
248254

249255
/** A callable where there is no flow via the callable. */
@@ -254,6 +260,12 @@ module Public {
254260
* Holds if the neutral is auto generated.
255261
*/
256262
predicate isAutoGenerated() { neutralElement(this, true) }
263+
264+
/**
265+
* Holds if the neutral has the given provenance where `true` is
266+
* `generated` and `false` is `manual`.
267+
*/
268+
predicate hasProvenance(boolean generated) { neutralElement(this, generated) }
257269
}
258270
}
259271

@@ -1012,6 +1024,10 @@ module Private {
10121024
}
10131025

10141026
override predicate isAutoGenerated() { this.relevantSummaryElementGenerated(_, _, _) }
1027+
1028+
override predicate hasProvenance(boolean generated) {
1029+
summaryElement(this, _, _, _, generated)
1030+
} // ! merge with PR #11585
10151031
}
10161032

10171033
/** Holds if component `c` of specification `spec` cannot be parsed. */

go/ql/lib/semmle/go/dataflow/internal/FlowSummaryImpl.qll

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,12 @@ module Public {
244244
* Holds if the summary is auto generated.
245245
*/
246246
predicate isAutoGenerated() { none() }
247+
248+
/**
249+
* Holds if the summary has the given provenance where `true` is
250+
* `generated` and `false` is `manual`.
251+
*/
252+
predicate hasProvenance(boolean generated) { none() } // ! merge with PR #11585
247253
}
248254

249255
/** A callable where there is no flow via the callable. */
@@ -254,6 +260,12 @@ module Public {
254260
* Holds if the neutral is auto generated.
255261
*/
256262
predicate isAutoGenerated() { neutralElement(this, true) }
263+
264+
/**
265+
* Holds if the neutral has the given provenance where `true` is
266+
* `generated` and `false` is `manual`.
267+
*/
268+
predicate hasProvenance(boolean generated) { neutralElement(this, generated) }
257269
}
258270
}
259271

@@ -1012,6 +1024,10 @@ module Private {
10121024
}
10131025

10141026
override predicate isAutoGenerated() { this.relevantSummaryElementGenerated(_, _, _) }
1027+
1028+
override predicate hasProvenance(boolean generated) {
1029+
summaryElement(this, _, _, _, generated)
1030+
} // ! merge with PR #11585
10151031
}
10161032

10171033
/** Holds if component `c` of specification `spec` cannot be parsed. */

java/ql/lib/semmle/code/java/dataflow/internal/FlowSummaryImpl.qll

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,12 @@ module Public {
244244
* Holds if the summary is auto generated.
245245
*/
246246
predicate isAutoGenerated() { none() }
247+
248+
/**
249+
* Holds if the summary has the given provenance where `true` is
250+
* `generated` and `false` is `manual`.
251+
*/
252+
predicate hasProvenance(boolean generated) { none() } // ! merge with PR #11585
247253
}
248254

249255
/** A callable where there is no flow via the callable. */
@@ -254,6 +260,12 @@ module Public {
254260
* Holds if the neutral is auto generated.
255261
*/
256262
predicate isAutoGenerated() { neutralElement(this, true) }
263+
264+
/**
265+
* Holds if the neutral has the given provenance where `true` is
266+
* `generated` and `false` is `manual`.
267+
*/
268+
predicate hasProvenance(boolean generated) { neutralElement(this, generated) }
257269
}
258270
}
259271

@@ -1012,6 +1024,10 @@ module Private {
10121024
}
10131025

10141026
override predicate isAutoGenerated() { this.relevantSummaryElementGenerated(_, _, _) }
1027+
1028+
override predicate hasProvenance(boolean generated) {
1029+
summaryElement(this, _, _, _, generated)
1030+
} // ! merge with PR #11585
10151031
}
10161032

10171033
/** Holds if component `c` of specification `spec` cannot be parsed. */

java/ql/test/ext/TopJdkApis/TopJdkApis-100.csv

Lines changed: 0 additions & 101 deletions
This file was deleted.

java/ql/test/ext/TopJdkApis/TopJdkApis.qll

Lines changed: 17 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,18 @@
1-
/** Provides classes and predicates for the Top JDK APIs. */
1+
/** Provides a class to identify Top JDK APIs. */
22

33
import java
44
private import semmle.code.java.dataflow.FlowSummary
55
private import semmle.code.java.dataflow.internal.FlowSummaryImpl as FlowSummaryImpl
6-
private import semmle.code.java.dataflow.ExternalFlow // for paramsString
6+
private import semmle.code.java.dataflow.ExternalFlow
77

8-
// Note: from ExternalApi.qll for getting the api name returned in the telemetry query results
9-
// /**
10-
// * Gets information about the external API in the form expected by the CSV modeling framework.
11-
// */
12-
// string getApiName() {
13-
// result =
14-
// this.getDeclaringType().getPackage() + "." + this.getDeclaringType().getSourceDeclaration() +
15-
// "#" + this.getName() + paramsString(this)
16-
// }
178
class TopJdkApi extends Callable {
189
TopJdkApi() {
19-
// (
20-
// this instanceof SummarizedCallable or
21-
// this instanceof FlowSummaryImpl::Public::NegativeSummarizedCallable
22-
// ) and
23-
// top 101 jdk apis
24-
//this.asCallable().getQualifiedName() in ["java.util.Set.add"]
25-
exists(string api |
26-
api =
10+
exists(string apiName |
11+
apiName =
2712
this.getDeclaringType().getPackage() + "." + this.getDeclaringType().getSourceDeclaration() +
2813
"#" + this.getName() + paramsString(this) and
29-
api in [
14+
apiName in [
15+
// top 100 JDK APIs
3016
"java.lang.StringBuilder#append(String)", "java.util.List#get(int)",
3117
"java.util.List#add(Object)", "java.util.Map#put(Object,Object)",
3218
"java.lang.String#equals(Object)", "java.util.Map#get(Object)", "java.util.List#size()",
@@ -80,27 +66,18 @@ class TopJdkApi extends Callable {
8066
)
8167
}
8268

83-
/** Holds if this API has a supported summary model. */
84-
private predicate hasSummary() { this = any(SummarizedCallable sc).asCallable() }
69+
/** Holds if this API has a manual summary model. */
70+
private predicate hasManualSummary() {
71+
exists(SummarizedCallable sc | this = sc.asCallable() and sc.hasProvenance(false))
72+
}
8573

86-
/** Holds if this API has a supported neutral model. */
87-
private predicate hasNeutral() {
88-
this = any(FlowSummaryImpl::Public::NegativeSummarizedCallable nsc).asCallable()
74+
/** Holds if this API has a manual neutral model. */
75+
private predicate hasManualNeutral() {
76+
exists(FlowSummaryImpl::Public::NegativeSummarizedCallable nsc |
77+
this = nsc.asCallable() and nsc.hasProvenance(false)
78+
)
8979
}
9080

91-
// ! note: the below will hold for either manual or generated models, should I restrict to just manual?
92-
/** Holds if this API has a MaD model. */
93-
predicate hasMadModel() { this.hasSummary() or this.hasNeutral() }
81+
/** Holds if this API has a manual MaD model. */
82+
predicate hasManualMadModel() { this.hasManualSummary() or this.hasManualNeutral() }
9483
}
95-
// class TopJdkApiSummary extends SummarizedCallableBase {
96-
// TopJdkApiSummary() {
97-
// this instanceof SummarizedCallable and
98-
// this.asCallable().getQualifiedName() in ["java.util.Objects."]
99-
// }
100-
// }
101-
// class TopJdkApiNeutral extends SummarizedCallableBase {
102-
// TopJdkApiNeutral() {
103-
// this instanceof FlowSummaryImpl::Public::NegativeSummarizedCallable and
104-
// this.asCallable().getCompilationUnit().getPackage().getName() = "java.util"
105-
// }
106-
// }
Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,87 @@
1-
| 87 |
1+
| java.io.File#File(String) |
2+
| java.io.PrintWriter#write(String) |
3+
| java.lang.Class#getName() |
4+
| java.lang.Class#getSimpleName() |
5+
| java.lang.Enum#Enum(String,int) |
6+
| java.lang.Enum#equals(Object) |
7+
| java.lang.Enum#name() |
8+
| java.lang.Enum#toString() |
9+
| java.lang.Iterable#forEach(Consumer) |
10+
| java.lang.Object#equals(Object) |
11+
| java.lang.Object#getClass() |
12+
| java.lang.Object#hashCode() |
13+
| java.lang.Object#toString() |
14+
| java.lang.String#charAt(int) |
15+
| java.lang.String#contains(CharSequence) |
16+
| java.lang.String#equals(Object) |
17+
| java.lang.String#equalsIgnoreCase(String) |
18+
| java.lang.String#format(String,Object[]) |
19+
| java.lang.String#hashCode() |
20+
| java.lang.String#isEmpty() |
21+
| java.lang.String#length() |
22+
| java.lang.String#replace(CharSequence,CharSequence) |
23+
| java.lang.String#split(String) |
24+
| java.lang.String#startsWith(String) |
25+
| java.lang.String#substring(int) |
26+
| java.lang.String#substring(int,int) |
27+
| java.lang.String#toLowerCase() |
28+
| java.lang.String#trim() |
29+
| java.lang.StringBuffer#append(String) |
30+
| java.lang.StringBuilder#append(Object) |
31+
| java.lang.StringBuilder#append(String) |
32+
| java.lang.StringBuilder#append(char) |
33+
| java.lang.StringBuilder#append(int) |
34+
| java.lang.StringBuilder#toString() |
35+
| java.lang.System#currentTimeMillis() |
36+
| java.nio.file.Path#resolve(String) |
37+
| java.util.ArrayList#ArrayList(Collection) |
38+
| java.util.ArrayList#add(Object) |
39+
| java.util.Arrays#asList(Object[]) |
40+
| java.util.Collection#size() |
41+
| java.util.Collection#stream() |
42+
| java.util.Collections#emptyList() |
43+
| java.util.Collections#singletonList(Object) |
44+
| java.util.Entry#getKey() |
45+
| java.util.Entry#getValue() |
46+
| java.util.HashMap#get(Object) |
47+
| java.util.HashMap#put(Object,Object) |
48+
| java.util.Iterator#hasNext() |
49+
| java.util.Iterator#next() |
50+
| java.util.List#add(Object) |
51+
| java.util.List#addAll(Collection) |
52+
| java.util.List#contains(Object) |
53+
| java.util.List#get(int) |
54+
| java.util.List#isEmpty() |
55+
| java.util.List#of(Object) |
56+
| java.util.List#size() |
57+
| java.util.Map#containsKey(Object) |
58+
| java.util.Map#entrySet() |
59+
| java.util.Map#get(Object) |
60+
| java.util.Map#isEmpty() |
61+
| java.util.Map#keySet() |
62+
| java.util.Map#put(Object,Object) |
63+
| java.util.Map#remove(Object) |
64+
| java.util.Map#size() |
65+
| java.util.Map#values() |
66+
| java.util.Objects#equals(Object,Object) |
67+
| java.util.Objects#hash(Object[]) |
68+
| java.util.Objects#requireNonNull(Object,String) |
69+
| java.util.Optional#empty() |
70+
| java.util.Optional#get() |
71+
| java.util.Optional#ifPresent(Consumer) |
72+
| java.util.Optional#isPresent() |
73+
| java.util.Optional#map(Function) |
74+
| java.util.Optional#of(Object) |
75+
| java.util.Optional#ofNullable(Object) |
76+
| java.util.Optional#orElse(Object) |
77+
| java.util.Set#add(Object) |
78+
| java.util.Set#contains(Object) |
79+
| java.util.Set#isEmpty() |
80+
| java.util.Set#size() |
81+
| java.util.UUID#randomUUID() |
82+
| java.util.UUID#toString() |
83+
| java.util.stream.Collectors#toList() |
84+
| java.util.stream.Stream#filter(Predicate) |
85+
| java.util.stream.Stream#findFirst() |
86+
| java.util.stream.Stream#forEach(Consumer) |
87+
| java.util.stream.Stream#map(Function) |

0 commit comments

Comments
 (0)