Skip to content

Commit 170e895

Browse files
author
Stephan Brandauer
committed
use newtype for related location type
1 parent 5dab1b2 commit 170e895

5 files changed

+28
-17
lines changed

java/ql/src/Telemetry/AutomodelExtractCandidates.ql

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ where
3939
)
4040
select endpoint,
4141
message + "\nrelated locations: $@, $@." + "\nmetadata: $@, $@, $@, $@, $@, $@.", //
42-
CharacteristicsImpl::getRelatedLocationOrCandidate(endpoint, "Callable-JavaDoc"),
43-
"Callable-JavaDoc", CharacteristicsImpl::getRelatedLocationOrCandidate(endpoint, "Class-JavaDoc"),
44-
"Class-JavaDoc", //
42+
CharacteristicsImpl::getRelatedLocationOrCandidate(endpoint, MethodDoc()), "MethodDoc", //
43+
CharacteristicsImpl::getRelatedLocationOrCandidate(endpoint, ClassDoc()), "ClassDoc", //
4544
package, "package", type, "type", subtypes.toString(), "subtypes", name, "name", signature,
4645
"signature", input.toString(), "input" //

java/ql/src/Telemetry/AutomodelExtractNegativeExamples.ql

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ where
3636
message = characteristic
3737
select endpoint,
3838
message + "\nrelated locations: $@, $@." + "\nmetadata: $@, $@, $@, $@, $@, $@.", //
39-
CharacteristicsImpl::getRelatedLocationOrCandidate(endpoint, "Callable-JavaDoc"),
40-
"Callable-JavaDoc", CharacteristicsImpl::getRelatedLocationOrCandidate(endpoint, "Class-JavaDoc"),
41-
"Class-JavaDoc", //
39+
CharacteristicsImpl::getRelatedLocationOrCandidate(endpoint, MethodDoc()), "MethodDoc", //
40+
CharacteristicsImpl::getRelatedLocationOrCandidate(endpoint, ClassDoc()), "ClassDoc", //
4241
package, "package", type, "type", subtypes.toString(), "subtypes", name, "name", signature,
4342
"signature", input.toString(), "input" //

java/ql/src/Telemetry/AutomodelExtractPositiveExamples.ql

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ where
2323
CharacteristicsImpl::isKnownSink(endpoint, sinkType)
2424
select endpoint,
2525
sinkType + "\nrelated locations: $@, $@." + "\nmetadata: $@, $@, $@, $@, $@, $@.", //
26-
CharacteristicsImpl::getRelatedLocationOrCandidate(endpoint, "Callable-JavaDoc"),
27-
"Callable-JavaDoc", CharacteristicsImpl::getRelatedLocationOrCandidate(endpoint, "Class-JavaDoc"),
28-
"Class-JavaDoc", //
26+
CharacteristicsImpl::getRelatedLocationOrCandidate(endpoint, MethodDoc()), "MethodDoc", //
27+
CharacteristicsImpl::getRelatedLocationOrCandidate(endpoint, ClassDoc()), "ClassDoc", //
2928
package, "package", type, "type", subtypes.toString(), "subtypes", name, "name", signature,
3029
"signature", input.toString(), "input" //

java/ql/src/Telemetry/AutomodelFrameworkModeCharacteristics.qll

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ abstract class MetadataExtractor extends string {
3131
);
3232
}
3333

34+
newtype JavaRelatedLocationType =
35+
MethodDoc() or
36+
ClassDoc()
37+
3438
// for documentation of the implementations here, see the QLDoc in the CandidateSig signature module.
3539
module FrameworkCandidatesImpl implements SharedCharacteristics::CandidateSig {
3640
class Endpoint = DataFlow::ParameterNode;
@@ -41,6 +45,8 @@ module FrameworkCandidatesImpl implements SharedCharacteristics::CandidateSig {
4145

4246
class RelatedLocation = Location::Top;
4347

48+
class RelatedLocationType = JavaRelatedLocationType;
49+
4450
// Sanitizers are currently not modeled in MaD. TODO: check if this has large negative impact.
4551
predicate isSanitizer(Endpoint e, EndpointType t) { none() }
4652

@@ -107,11 +113,11 @@ module FrameworkCandidatesImpl implements SharedCharacteristics::CandidateSig {
107113
*
108114
* Related locations can be JavaDoc comments of the class or the method.
109115
*/
110-
RelatedLocation getRelatedLocation(Endpoint e, string name) {
111-
name = "Callable-JavaDoc" and
116+
RelatedLocation getRelatedLocation(Endpoint e, RelatedLocationType type) {
117+
type = MethodDoc() and
112118
result = FrameworkCandidatesImpl::getCallable(e).(Documentable).getJavadoc()
113119
or
114-
name = "Class-JavaDoc" and
120+
type = ClassDoc() and
115121
result = FrameworkCandidatesImpl::getCallable(e).getDeclaringType().(Documentable).getJavadoc()
116122
}
117123

java/ql/src/Telemetry/AutomodelSharedCharacteristics.qll

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ signature module CandidateSig {
2323
*/
2424
class RelatedLocation;
2525

26+
/**
27+
* A label for a related location.
28+
*
29+
* Eg., method-doc, class-doc, etc.
30+
*/
31+
class RelatedLocationType;
32+
2633
/**
2734
* A class kind for an endpoint.
2835
*/
@@ -68,7 +75,7 @@ signature module CandidateSig {
6875
*
6976
* For example, a related location for a method call may be the documentation comment of a method.
7077
*/
71-
RelatedLocation getRelatedLocation(Endpoint e, string name);
78+
RelatedLocation getRelatedLocation(Endpoint e, RelatedLocationType name);
7279
}
7380

7481
/**
@@ -111,10 +118,11 @@ module SharedCharacteristics<CandidateSig Candidate> {
111118
* Gets the related location of `e` with name `name`, if it exists.
112119
* Otherwise, gets the candidate itself.
113120
*/
114-
bindingset[name]
115-
Candidate::RelatedLocation getRelatedLocationOrCandidate(Candidate::Endpoint e, string name) {
116-
if exists(Candidate::getRelatedLocation(e, name))
117-
then result = Candidate::getRelatedLocation(e, name)
121+
Candidate::RelatedLocation getRelatedLocationOrCandidate(
122+
Candidate::Endpoint e, Candidate::RelatedLocationType type
123+
) {
124+
if exists(Candidate::getRelatedLocation(e, type))
125+
then result = Candidate::getRelatedLocation(e, type)
118126
else result = Candidate::asLocation(e)
119127
}
120128

0 commit comments

Comments
 (0)