Skip to content

Commit d93ad9b

Browse files
author
Stephan Brandauer
committed
Java: remove unneeded abstract metadata extractor classes and fix some names
1 parent 6e21f14 commit d93ad9b

8 files changed

Lines changed: 29 additions & 56 deletions

java/ql/src/Telemetry/AutomodelApplicationModeCharacteristics.qll

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,6 @@ private import semmle.code.java.dataflow.internal.ModelExclusions as ModelExclus
1717
import AutomodelSharedCharacteristics as SharedCharacteristics
1818
import AutomodelEndpointTypes as AutomodelEndpointTypes
1919

20-
/**
21-
* A meta data extractor. Any Java extraction mode needs to implement exactly
22-
* one instance of this class.
23-
*/
24-
abstract class MetadataExtractor extends string {
25-
bindingset[this]
26-
MetadataExtractor() { any() }
27-
28-
abstract predicate hasMetadata(
29-
Endpoint e, string package, string type, boolean subtypes, string name, string signature,
30-
string input
31-
);
32-
}
33-
3420
newtype JavaRelatedLocationType = CallContext()
3521

3622
/**
@@ -41,14 +27,14 @@ private class ArgumentNode extends DataFlow::Node {
4127
}
4228

4329
/**
44-
* A candidates implementation for framework mode.
30+
* A candidates implementation.
4531
*
4632
* Some important notes:
4733
* - This mode is using parameters as endpoints.
4834
* - Sink- and neutral-information is being used from MaD models.
4935
* - When available, we use method- and class-java-docs as related locations.
5036
*/
51-
module FrameworkCandidatesImpl implements SharedCharacteristics::CandidateSig {
37+
module ApplicationCandidatesImpl implements SharedCharacteristics::CandidateSig {
5238
// for documentation of the implementations here, see the QLDoc in the CandidateSig signature module.
5339
class Endpoint = ArgumentNode;
5440

@@ -108,7 +94,7 @@ module FrameworkCandidatesImpl implements SharedCharacteristics::CandidateSig {
10894
additional predicate sinkSpec(
10995
Endpoint e, string package, string type, string name, string signature, string ext, string input
11096
) {
111-
FrameworkCandidatesImpl::getCallable(e).hasQualifiedName(package, type, name) and
97+
ApplicationCandidatesImpl::getCallable(e).hasQualifiedName(package, type, name) and
11298
signature = ExternalFlow::paramsString(getCallable(e)) and
11399
ext = "" and
114100
(
@@ -147,21 +133,22 @@ module FrameworkCandidatesImpl implements SharedCharacteristics::CandidateSig {
147133
}
148134
}
149135

150-
module CharacteristicsImpl = SharedCharacteristics::SharedCharacteristics<FrameworkCandidatesImpl>;
136+
module CharacteristicsImpl =
137+
SharedCharacteristics::SharedCharacteristics<ApplicationCandidatesImpl>;
151138

152139
class EndpointCharacteristic = CharacteristicsImpl::EndpointCharacteristic;
153140

154-
class Endpoint = FrameworkCandidatesImpl::Endpoint;
141+
class Endpoint = ApplicationCandidatesImpl::Endpoint;
155142

156143
/*
157144
* Predicates that are used to surface prompt examples and candidates for classification with an ML model.
158145
*/
159146

160147
/**
161-
* A MetadataExtractor that extracts metadata for framework mode.
148+
* A MetadataExtractor that extracts metadata for application mode.
162149
*/
163-
class FrameworkModeMetadataExtractor extends MetadataExtractor {
164-
FrameworkModeMetadataExtractor() { this = "FrameworkModeMetadataExtractor" }
150+
class ApplicationModeMetadataExtractor extends string {
151+
ApplicationModeMetadataExtractor() { this = "ApplicationModeMetadataExtractor" }
165152

166153
/**
167154
* By convention, the subtypes property of the MaD declaration should only be
@@ -180,7 +167,7 @@ class FrameworkModeMetadataExtractor extends MetadataExtractor {
180167
else result = true
181168
}
182169

183-
override predicate hasMetadata(
170+
predicate hasMetadata(
184171
Endpoint e, string package, string type, boolean subtypes, string name, string signature,
185172
string input
186173
) {
@@ -217,9 +204,9 @@ private class UnexploitableIsCharacteristic extends CharacteristicsImpl::NotASin
217204
UnexploitableIsCharacteristic() { this = "unexploitable (is-style boolean method)" }
218205

219206
override predicate appliesToEndpoint(Endpoint e) {
220-
not FrameworkCandidatesImpl::isSink(e, _) and
221-
FrameworkCandidatesImpl::getCallable(e).getName().matches("is%") and
222-
FrameworkCandidatesImpl::getCallable(e).getReturnType() instanceof BooleanType
207+
not ApplicationCandidatesImpl::isSink(e, _) and
208+
ApplicationCandidatesImpl::getCallable(e).getName().matches("is%") and
209+
ApplicationCandidatesImpl::getCallable(e).getReturnType() instanceof BooleanType
223210
}
224211
}
225212

@@ -235,9 +222,9 @@ private class UnexploitableExistsCharacteristic extends CharacteristicsImpl::Not
235222
UnexploitableExistsCharacteristic() { this = "unexploitable (existence-checking boolean method)" }
236223

237224
override predicate appliesToEndpoint(Endpoint e) {
238-
not FrameworkCandidatesImpl::isSink(e, _) and
225+
not ApplicationCandidatesImpl::isSink(e, _) and
239226
exists(Callable callable |
240-
callable = FrameworkCandidatesImpl::getCallable(e) and
227+
callable = ApplicationCandidatesImpl::getCallable(e) and
241228
callable.getName().toLowerCase() = ["exists", "notexists"] and
242229
callable.getReturnType() instanceof BooleanType
243230
)
@@ -251,7 +238,7 @@ private class ExceptionCharacteristic extends CharacteristicsImpl::NotASinkChara
251238
ExceptionCharacteristic() { this = "exception" }
252239

253240
override predicate appliesToEndpoint(Endpoint e) {
254-
FrameworkCandidatesImpl::getCallable(e).getDeclaringType().getASupertype*() instanceof
241+
ApplicationCandidatesImpl::getCallable(e).getDeclaringType().getASupertype*() instanceof
255242
TypeThrowable
256243
}
257244
}
@@ -286,7 +273,7 @@ private class NonPublicMethodCharacteristic extends CharacteristicsImpl::Uninter
286273
NonPublicMethodCharacteristic() { this = "non-public method" }
287274

288275
override predicate appliesToEndpoint(Endpoint e) {
289-
not FrameworkCandidatesImpl::getCallable(e).isPublic()
276+
not ApplicationCandidatesImpl::getCallable(e).isPublic()
290277
}
291278
}
292279

java/ql/src/Telemetry/AutomodelApplicationModeExtractCandidates.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ private import AutomodelApplicationModeCharacteristics
1616
private import AutomodelSharedUtil
1717

1818
from
19-
Endpoint endpoint, string message, MetadataExtractor meta, string package, string type,
20-
boolean subtypes, string name, string signature, string input
19+
Endpoint endpoint, string message, ApplicationModeMetadataExtractor meta, string package,
20+
string type, boolean subtypes, string name, string signature, string input
2121
where
2222
not exists(CharacteristicsImpl::UninterestingToModelCharacteristic u |
2323
u.appliesToEndpoint(endpoint)

java/ql/src/Telemetry/AutomodelApplicationModeExtractNegativeExamples.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ private import AutomodelSharedUtil
1414

1515
from
1616
Endpoint endpoint, EndpointCharacteristic characteristic, float confidence, string message,
17-
MetadataExtractor meta, string package, string type, boolean subtypes, string name,
17+
ApplicationModeMetadataExtractor meta, string package, string type, boolean subtypes, string name,
1818
string signature, string input
1919
where
2020
characteristic.appliesToEndpoint(endpoint) and

java/ql/src/Telemetry/AutomodelApplicationModeExtractPositiveExamples.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ private import AutomodelEndpointTypes
1313
private import AutomodelSharedUtil
1414

1515
from
16-
Endpoint endpoint, SinkType sinkType, MetadataExtractor meta, string package, string type,
17-
boolean subtypes, string name, string signature, string input
16+
Endpoint endpoint, SinkType sinkType, ApplicationModeMetadataExtractor meta, string package,
17+
string type, boolean subtypes, string name, string signature, string input
1818
where
1919
// Exclude endpoints that have contradictory endpoint characteristics, because we only want examples we're highly
2020
// certain about in the prompt.

java/ql/src/Telemetry/AutomodelFrameworkModeCharacteristics.qll

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,6 @@ private import semmle.code.java.dataflow.internal.ModelExclusions as ModelExclus
1717
import AutomodelSharedCharacteristics as SharedCharacteristics
1818
import AutomodelEndpointTypes as AutomodelEndpointTypes
1919

20-
/**
21-
* A meta data extractor. Any Java extraction mode needs to implement exactly
22-
* one instance of this class.
23-
*/
24-
abstract class MetadataExtractor extends string {
25-
bindingset[this]
26-
MetadataExtractor() { any() }
27-
28-
abstract predicate hasMetadata(
29-
DataFlow::ParameterNode e, string package, string type, boolean subtypes, string name,
30-
string signature, string input, string parameterName
31-
);
32-
}
33-
3420
newtype JavaRelatedLocationType =
3521
MethodDoc() or
3622
ClassDoc()
@@ -145,7 +131,7 @@ class Endpoint = FrameworkCandidatesImpl::Endpoint;
145131
/**
146132
* A MetadataExtractor that extracts metadata for framework mode.
147133
*/
148-
class FrameworkModeMetadataExtractor extends MetadataExtractor {
134+
class FrameworkModeMetadataExtractor extends string {
149135
FrameworkModeMetadataExtractor() { this = "FrameworkModeMetadataExtractor" }
150136

151137
/**
@@ -165,7 +151,7 @@ class FrameworkModeMetadataExtractor extends MetadataExtractor {
165151
else result = true
166152
}
167153

168-
override predicate hasMetadata(
154+
predicate hasMetadata(
169155
Endpoint e, string package, string type, boolean subtypes, string name, string signature,
170156
string input, string parameterName
171157
) {

java/ql/src/Telemetry/AutomodelFrameworkModeExtractCandidates.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ private import AutomodelFrameworkModeCharacteristics
1616
private import AutomodelSharedUtil
1717

1818
from
19-
Endpoint endpoint, string message, MetadataExtractor meta, string package, string type,
20-
boolean subtypes, string name, string signature, string input, string parameterName
19+
Endpoint endpoint, string message, FrameworkModeMetadataExtractor meta, string package,
20+
string type, boolean subtypes, string name, string signature, string input, string parameterName
2121
where
2222
not exists(CharacteristicsImpl::UninterestingToModelCharacteristic u |
2323
u.appliesToEndpoint(endpoint)

java/ql/src/Telemetry/AutomodelFrameworkModeExtractNegativeExamples.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ private import AutomodelSharedUtil
1414

1515
from
1616
Endpoint endpoint, EndpointCharacteristic characteristic, float confidence, string message,
17-
MetadataExtractor meta, string package, string type, boolean subtypes, string name,
17+
FrameworkModeMetadataExtractor meta, string package, string type, boolean subtypes, string name,
1818
string signature, string input, string parameterName
1919
where
2020
characteristic.appliesToEndpoint(endpoint) and

java/ql/src/Telemetry/AutomodelFrameworkModeExtractPositiveExamples.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ private import AutomodelEndpointTypes
1313
private import AutomodelSharedUtil
1414

1515
from
16-
Endpoint endpoint, SinkType sinkType, MetadataExtractor meta, string package, string type,
17-
boolean subtypes, string name, string signature, string input, string parameterName
16+
Endpoint endpoint, SinkType sinkType, FrameworkModeMetadataExtractor meta, string package,
17+
string type, boolean subtypes, string name, string signature, string input, string parameterName
1818
where
1919
// Exclude endpoints that have contradictory endpoint characteristics, because we only want examples we're highly
2020
// certain about in the prompt.

0 commit comments

Comments
 (0)