Skip to content

Commit 7a7dc9b

Browse files
author
Stephan Brandauer
authored
Merge pull request #14184 from github/kaeluka/application-mode-new-candidates-fixes
Java: Automodel, new candidates fix
2 parents ecf1d98 + 928898e commit 7a7dc9b

9 files changed

+53
-31
lines changed

java/ql/automodel/src/AutomodelApplicationModeCharacteristics.qll

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ private import AutomodelSharedGetCallable as AutomodelSharedGetCallable
1919
import AutomodelSharedCharacteristics as SharedCharacteristics
2020
import AutomodelEndpointTypes as AutomodelEndpointTypes
2121

22-
newtype JavaRelatedLocationType = CallContext()
22+
newtype JavaRelatedLocationType =
23+
CallContext() or
24+
MethodDoc() or
25+
ClassDoc()
2326

2427
newtype TApplicationModeEndpoint =
2528
TExplicitArgument(Call call, DataFlow::Node arg) {
@@ -312,6 +315,12 @@ module ApplicationCandidatesImpl implements SharedCharacteristics::CandidateSig
312315
RelatedLocation getRelatedLocation(Endpoint e, RelatedLocationType type) {
313316
type = CallContext() and
314317
result = e.getCall()
318+
or
319+
type = MethodDoc() and
320+
result = e.getCallable().(Documentable).getJavadoc()
321+
or
322+
type = ClassDoc() and
323+
result = e.getCallable().getDeclaringType().(Documentable).getJavadoc()
315324
}
316325
}
317326

java/ql/automodel/src/AutomodelApplicationModeExtractCandidates.ql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,11 @@ where
8989
sinkType, ", "
9090
)
9191
select endpoint.asNode(),
92-
message + "\nrelated locations: $@." + "\nmetadata: $@, $@, $@, $@, $@, $@, $@, $@, $@, $@.", //
92+
message + "\nrelated locations: $@, $@, $@." +
93+
"\nmetadata: $@, $@, $@, $@, $@, $@, $@, $@, $@, $@.", //
9394
CharacteristicsImpl::getRelatedLocationOrCandidate(endpoint, CallContext()), "CallContext", //
95+
CharacteristicsImpl::getRelatedLocationOrCandidate(endpoint, MethodDoc()), "MethodDoc", //
96+
CharacteristicsImpl::getRelatedLocationOrCandidate(endpoint, ClassDoc()), "ClassDoc", //
9497
package, "package", //
9598
type, "type", //
9699
subtypes, "subtypes", //

java/ql/automodel/src/AutomodelApplicationModeExtractNegativeExamples.ql

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@ from
4444
Endpoint endpoint, EndpointCharacteristic characteristic, float confidence, string message,
4545
ApplicationModeMetadataExtractor meta, DollarAtString package, DollarAtString type,
4646
DollarAtString subtypes, DollarAtString name, DollarAtString signature, DollarAtString input,
47-
DollarAtString output, DollarAtString isVarargsArray
47+
DollarAtString output, DollarAtString isVarargsArray, DollarAtString extensibleType
4848
where
4949
endpoint = getSampleForCharacteristic(characteristic, 100) and
50+
extensibleType = endpoint.getExtensibleType() and
5051
confidence >= SharedCharacteristics::highConfidence() and
5152
characteristic.hasImplications(any(NegativeSinkType negative), true, confidence) and
5253
// Exclude endpoints that have contradictory endpoint characteristics, because we only want examples we're highly
@@ -65,13 +66,16 @@ where
6566
) and
6667
message = characteristic
6768
select endpoint.asNode(),
68-
message + "\nrelated locations: $@." + "\nmetadata: $@, $@, $@, $@, $@, $@, $@, $@.", //
69+
message + "\nrelated locations: $@, $@, $@." + "\nmetadata: $@, $@, $@, $@, $@, $@, $@, $@.", //
6970
CharacteristicsImpl::getRelatedLocationOrCandidate(endpoint, CallContext()), "CallContext", //
71+
CharacteristicsImpl::getRelatedLocationOrCandidate(endpoint, MethodDoc()), "MethodDoc", //
72+
CharacteristicsImpl::getRelatedLocationOrCandidate(endpoint, ClassDoc()), "ClassDoc", //
7073
package, "package", //
7174
type, "type", //
7275
subtypes, "subtypes", //
7376
name, "name", //
7477
signature, "signature", //
7578
input, "input", //
7679
output, "output", //
77-
isVarargsArray, "isVarargsArray" //
80+
isVarargsArray, "isVarargsArray", //
81+
extensibleType, "extensibleType"

java/ql/automodel/src/AutomodelApplicationModeExtractPositiveExamples.ql

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,27 @@ from
1616
Endpoint endpoint, EndpointType endpointType, ApplicationModeMetadataExtractor meta,
1717
DollarAtString package, DollarAtString type, DollarAtString subtypes, DollarAtString name,
1818
DollarAtString signature, DollarAtString input, DollarAtString output,
19-
DollarAtString isVarargsArray
19+
DollarAtString isVarargsArray, DollarAtString extensibleType
2020
where
2121
// Exclude endpoints that have contradictory endpoint characteristics, because we only want examples we're highly
2222
// certain about in the prompt.
2323
not erroneousEndpoints(endpoint, _, _, _, _, false) and
24+
extensibleType = endpoint.getExtensibleType() and
2425
meta.hasMetadata(endpoint, package, type, subtypes, name, signature, input, output, isVarargsArray) and
2526
// Extract positive examples of sinks belonging to the existing ATM query configurations.
2627
CharacteristicsImpl::isKnownAs(endpoint, endpointType, _) and
2728
exists(CharacteristicsImpl::getRelatedLocationOrCandidate(endpoint, CallContext()))
2829
select endpoint.asNode(),
29-
endpointType + "\nrelated locations: $@." + "\nmetadata: $@, $@, $@, $@, $@, $@, $@, $@.", //
30+
endpointType + "\nrelated locations: $@, $@, $@." + "\nmetadata: $@, $@, $@, $@, $@, $@, $@, $@.", //
3031
CharacteristicsImpl::getRelatedLocationOrCandidate(endpoint, CallContext()), "CallContext", //
32+
CharacteristicsImpl::getRelatedLocationOrCandidate(endpoint, MethodDoc()), "MethodDoc", //
33+
CharacteristicsImpl::getRelatedLocationOrCandidate(endpoint, ClassDoc()), "ClassDoc", //
3134
package, "package", //
3235
type, "type", //
3336
subtypes, "subtypes", //
3437
name, "name", //
3538
signature, "signature", //
3639
input, "input", //
3740
output, "output", //
38-
isVarargsArray, "isVarargsArray"
41+
isVarargsArray, "isVarargsArray", //
42+
extensibleType, "extensibleType"

0 commit comments

Comments
 (0)