@@ -17,6 +17,22 @@ private import semmle.code.java.dataflow.internal.ModelExclusions as ModelExclus
1717import AutomodelSharedCharacteristics as SharedCharacteristics
1818import AutomodelEndpointTypes as AutomodelEndpointTypes
1919
20+ Callable getCallable ( DataFlow:: ParameterNode e ) { result = e .getEnclosingCallable ( ) }
21+
22+ /**
23+ * A meta data extractor. Any Java extraction mode needs to implement exactly
24+ * one instance of this class.
25+ */
26+ abstract class MetadataExtractor extends string {
27+ bindingset [ this ]
28+ MetadataExtractor ( ) { any ( ) }
29+
30+ abstract predicate hasMetadata (
31+ DataFlow:: ParameterNode e , string package , string type , boolean subtypes , string name ,
32+ string signature , int input
33+ ) ;
34+ }
35+
2036module FrameworkCandidatesImpl implements SharedCharacteristics:: CandidateSig {
2137 class Endpoint = DataFlow:: ParameterNode ;
2238
@@ -87,26 +103,6 @@ module FrameworkCandidatesImpl implements SharedCharacteristics::CandidateSig {
87103 exists ( int paramIdx | e .isParameterOf ( _, paramIdx ) | input = "Argument[" + paramIdx + "]" )
88104 }
89105
90- predicate hasMetadata ( Endpoint e , string metadata ) {
91- exists (
92- string package , string type , boolean subtypes , string name , string signature , int input ,
93- boolean isPublic , boolean isFinal , boolean isStatic
94- |
95- hasMetadata ( e , package , type , name , signature , input , isFinal , isStatic , isPublic ) and
96- ( if isFinal = true or isStatic = true then subtypes = false else subtypes = true ) and
97- metadata =
98- "{" //
99- + "'Package': '" + package //
100- + "', 'Type': '" + type //
101- + "', 'Subtypes': " + subtypes //
102- + ", 'Name': '" + name //
103- + ", 'ParamName': '" + e .toString ( ) //
104- + "', 'Signature': '" + signature //
105- + "', 'Argument index': " + input //
106- + "'}" // TODO: Why are the curly braces added twice?
107- )
108- }
109-
110106 RelatedLocation getRelatedLocation ( Endpoint e , string name ) {
111107 name = "Callable-JavaDoc" and
112108 result = getCallable ( e ) .( Documentable ) .getJavadoc ( )
@@ -116,8 +112,6 @@ module FrameworkCandidatesImpl implements SharedCharacteristics::CandidateSig {
116112 }
117113}
118114
119- Callable getCallable ( Endpoint e ) { result = e .getEnclosingCallable ( ) }
120-
121115module CharacteristicsImpl = SharedCharacteristics:: SharedCharacteristics< FrameworkCandidatesImpl > ;
122116
123117class EndpointCharacteristic = CharacteristicsImpl:: EndpointCharacteristic ;
@@ -129,32 +123,32 @@ class Endpoint = FrameworkCandidatesImpl::Endpoint;
129123 */
130124
131125/**
132- * Holds if `n` has the given metadata.
133- *
134- * This is a helper function to extract and export needed information about each endpoint.
126+ * A MetadataExtractor that extracts metadata for framework mode.
135127 */
136- predicate hasMetadata (
137- Endpoint n , string package , string type , string name , string signature , int input ,
138- boolean isFinal , boolean isStatic , boolean isPublic
139- ) {
140- exists ( Callable callable |
141- n .asParameter ( ) = callable .getParameter ( input ) and
142- package = callable .getDeclaringType ( ) .getPackage ( ) .getName ( ) and
143- type = callable .getDeclaringType ( ) .getErasure ( ) .( RefType ) .nestedName ( ) and
144- (
145- if callable .isStatic ( ) or callable .getDeclaringType ( ) .isStatic ( )
146- then isStatic = true
147- else isStatic = false
148- ) and
149- (
150- if callable .isFinal ( ) or callable .getDeclaringType ( ) .isFinal ( )
151- then isFinal = true
152- else isFinal = false
153- ) and
154- name = callable .getSourceDeclaration ( ) .getName ( ) and
155- signature = ExternalFlow:: paramsString ( callable ) and // TODO: Why are brackets being escaped (`\[\]` vs `[]`)?
156- ( if callable .isPublic ( ) then isPublic = true else isPublic = false )
157- )
128+ class FrameworkModeMetadataExtractor extends MetadataExtractor {
129+ FrameworkModeMetadataExtractor ( ) { this = "FrameworkModeMetadataExtractor" }
130+
131+ override predicate hasMetadata (
132+ Endpoint e , string package , string type , boolean subtypes , string name , string signature ,
133+ int input
134+ ) {
135+ exists ( Callable callable |
136+ e .asParameter ( ) = callable .getParameter ( input ) and
137+ package = callable .getDeclaringType ( ) .getPackage ( ) .getName ( ) and
138+ type = callable .getDeclaringType ( ) .getErasure ( ) .( RefType ) .nestedName ( ) and
139+ (
140+ if
141+ callable .isStatic ( ) or
142+ callable .getDeclaringType ( ) .isStatic ( ) or
143+ callable .isFinal ( ) or
144+ callable .getDeclaringType ( ) .isFinal ( )
145+ then subtypes = true
146+ else subtypes = false
147+ ) and
148+ name = e .toString ( ) and
149+ signature = ExternalFlow:: paramsString ( callable )
150+ )
151+ }
158152}
159153
160154/*
0 commit comments