Merge pull request #18340 from jbj/diff-informed-getASelectedLocation

Java: make more queries diff-informed with getASelectedLocation
This commit is contained in:
Jonas Jensen
2025-01-22 14:25:33 +01:00
committed by GitHub
13 changed files with 167 additions and 5 deletions

View File

@@ -442,6 +442,28 @@ module Configs<LocationSig Location, InputSig<Location> Lang> {
* are used directly in a query result.
*/
default predicate observeDiffInformedIncrementalMode() { none() }
/**
* Gets a location that will be associated with the given `source` in a
* diff-informed query that uses this configuration (see
* `observeDiffInformedIncrementalMode`). By default, this is the location
* of the source itself, but this predicate should include any locations
* that are reported as the primary-location of the query or as an
* additional location ("$@" interpolation). For a query that doesn't
* report the source at all, this predicate can be `none()`.
*/
default Location getASelectedSourceLocation(Node source) { result = source.getLocation() }
/**
* Gets a location that will be associated with the given `sink` in a
* diff-informed query that uses this configuration (see
* `observeDiffInformedIncrementalMode`). By default, this is the location
* of the sink itself, but this predicate should include any locations
* that are reported as the primary-location of the query or as an
* additional location ("$@" interpolation). For a query that doesn't
* report the sink at all, this predicate can be `none()`.
*/
default Location getASelectedSinkLocation(Node sink) { result = sink.getLocation() }
}
/** An input configuration for data flow using flow state. */
@@ -569,6 +591,28 @@ module Configs<LocationSig Location, InputSig<Location> Lang> {
* are used directly in a query result.
*/
default predicate observeDiffInformedIncrementalMode() { none() }
/**
* Gets a location that will be associated with the given `source` in a
* diff-informed query that uses this configuration (see
* `observeDiffInformedIncrementalMode`). By default, this is the location
* of the source itself, but this predicate should include any locations
* that are reported as the primary-location of the query or as an
* additional location ("$@" interpolation). For a query that doesn't
* report the source at all, this predicate can be `none()`.
*/
default Location getASelectedSourceLocation(Node source) { result = source.getLocation() }
/**
* Gets a location that will be associated with the given `sink` in a
* diff-informed query that uses this configuration (see
* `observeDiffInformedIncrementalMode`). By default, this is the location
* of the sink itself, but this predicate should include any locations
* that are reported as the primary-location of the query or as an
* additional location ("$@" interpolation). For a query that doesn't
* report the sink at all, this predicate can be `none()`.
*/
default Location getASelectedSinkLocation(Node sink) { result = sink.getLocation() }
}
}

View File

@@ -137,6 +137,10 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
* are used directly in a query result.
*/
predicate observeDiffInformedIncrementalMode();
Location getASelectedSourceLocation(Node source);
Location getASelectedSinkLocation(Node sink);
}
/**
@@ -177,7 +181,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
private predicate isFilteredSource(Node source) {
Config::isSource(source, _) and
if Config::observeDiffInformedIncrementalMode()
then AlertFiltering::filterByLocation(source.getLocation())
then AlertFiltering::filterByLocation(Config::getASelectedSourceLocation(source))
else any()
}
@@ -188,7 +192,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
Config::isSink(sink)
) and
if Config::observeDiffInformedIncrementalMode()
then AlertFiltering::filterByLocation(sink.getLocation())
then AlertFiltering::filterByLocation(Config::getASelectedSinkLocation(sink))
else any()
}