Skip to content

Commit 0a2cf00

Browse files
Add isModuleImport field for java 25 module import support (#1842)
* Add isModuleImport node property * Generate code --------- Co-authored-by: Johannes Coetzee <johannes.coetzee@harness.io>
1 parent 66866d6 commit 0a2cf00

File tree

101 files changed

+1147
-1026
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+1147
-1026
lines changed

domainClasses/src/main/generated/io/shiftleft/codepropertygraph/generated/GraphSchema.scala

Lines changed: 601 additions & 595 deletions
Large diffs are not rendered by default.

domainClasses/src/main/generated/io/shiftleft/codepropertygraph/generated/Properties.scala

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -169,114 +169,119 @@ object Properties {
169169
*/
170170
val IsExternal = flatgraph.SinglePropertyKey[Boolean](kind = 29, name = "IS_EXTERNAL", default = false)
171171

172+
/** Specifies whether this is a module import. This is used for languages like Java >= 25 where packages exported by a
173+
* module can be imported via the module name (which does not need to match the package names in any way).
174+
*/
175+
val IsModuleImport = flatgraph.OptionalPropertyKey[Boolean](kind = 30, name = "IS_MODULE_IMPORT")
176+
172177
/** Specifies whether a parameter is the variadic argument handling parameter of a variadic method. Only one parameter
173178
* of a method is allowed to have this property set to true.
174179
*/
175-
val IsVariadic = flatgraph.SinglePropertyKey[Boolean](kind = 30, name = "IS_VARIADIC", default = false)
180+
val IsVariadic = flatgraph.SinglePropertyKey[Boolean](kind = 31, name = "IS_VARIADIC", default = false)
176181

177182
/** Specifies whether this is a wildcard import. For a Java import like "import java.nio.*;" IS_WILDCARD would be
178183
* "true" and IMPORTED_ENTITY would be "java.nio". For wildcard imports the IMPORTED_AS property is ignored.
179184
*/
180-
val IsWildcard = flatgraph.OptionalPropertyKey[Boolean](kind = 31, name = "IS_WILDCARD")
185+
val IsWildcard = flatgraph.OptionalPropertyKey[Boolean](kind = 32, name = "IS_WILDCARD")
181186

182187
/** This property denotes a key of a key-value pair. */
183-
val Key = flatgraph.SinglePropertyKey[String](kind = 32, name = "KEY", default = "<empty>")
188+
val Key = flatgraph.SinglePropertyKey[String](kind = 33, name = "KEY", default = "<empty>")
184189

185190
/** This field indicates which CPG language frontend generated the CPG. Frontend developers may freely choose a value
186191
* that describes their frontend so long as it is not used by an existing frontend. Reserved values are to date: C,
187192
* LLVM, GHIDRA, PHP.
188193
*/
189-
val Language = flatgraph.SinglePropertyKey[String](kind = 33, name = "LANGUAGE", default = "<empty>")
194+
val Language = flatgraph.SinglePropertyKey[String](kind = 34, name = "LANGUAGE", default = "<empty>")
190195

191196
/** This optional field provides the line number of the program construct represented by the node.
192197
*/
193-
val LineNumber = flatgraph.OptionalPropertyKey[Int](kind = 34, name = "LINE_NUMBER")
198+
val LineNumber = flatgraph.OptionalPropertyKey[Int](kind = 35, name = "LINE_NUMBER")
194199

195200
/** This optional fields provides the line number at which the program construct represented by the node ends.
196201
*/
197-
val LineNumberEnd = flatgraph.OptionalPropertyKey[Int](kind = 35, name = "LINE_NUMBER_END")
202+
val LineNumberEnd = flatgraph.OptionalPropertyKey[Int](kind = 36, name = "LINE_NUMBER_END")
198203

199204
/** The FULL_NAME of a method. Used to link CALL and METHOD nodes. It is required to have exactly one METHOD node for
200205
* each METHOD_FULL_NAME
201206
*/
202-
val MethodFullName = flatgraph.SinglePropertyKey[String](kind = 36, name = "METHOD_FULL_NAME", default = "<empty>")
207+
val MethodFullName = flatgraph.SinglePropertyKey[String](kind = 37, name = "METHOD_FULL_NAME", default = "<empty>")
203208

204209
/** The modifier type is a free-form string. The following are known modifier types: `STATIC`, `PUBLIC`, `PROTECTED`,
205210
* `PRIVATE`, `ABSTRACT`, `NATIVE`, `CONSTRUCTOR`, `VIRTUAL`.
206211
*/
207-
val ModifierType = flatgraph.SinglePropertyKey[String](kind = 37, name = "MODIFIER_TYPE", default = "<empty>")
212+
val ModifierType = flatgraph.SinglePropertyKey[String](kind = 38, name = "MODIFIER_TYPE", default = "<empty>")
208213

209214
/** Name of represented object, e.g., method name (e.g. "run") */
210-
val Name = flatgraph.SinglePropertyKey[String](kind = 38, name = "NAME", default = "<empty>")
215+
val Name = flatgraph.SinglePropertyKey[String](kind = 39, name = "NAME", default = "<empty>")
211216

212217
/** Start offset into the CONTENT property of the corresponding FILE node. The offset is such that parts of the
213218
* content can easily be accessed via `content.substring(offset, offsetEnd)`. This means that the offset must be
214219
* measured in utf16 encoding (i.e. neither in characters/codeunits nor in byte-offsets into a utf8 encoding). E.g.
215220
* for METHOD nodes this start offset points to the start of the methods source code in the string holding the source
216221
* code of the entire file.
217222
*/
218-
val Offset = flatgraph.OptionalPropertyKey[Int](kind = 39, name = "OFFSET")
223+
val Offset = flatgraph.OptionalPropertyKey[Int](kind = 40, name = "OFFSET")
219224

220225
/** End offset (exclusive) into the CONTENT property of the corresponding FILE node. See OFFSET documentation for
221226
* finer details. E.g. for METHOD nodes this end offset points to the first code position which is not part of the
222227
* method.
223228
*/
224-
val OffsetEnd = flatgraph.OptionalPropertyKey[Int](kind = 40, name = "OFFSET_END")
229+
val OffsetEnd = flatgraph.OptionalPropertyKey[Int](kind = 41, name = "OFFSET_END")
225230

226231
/** This integer indicates the position of the node among its siblings in the AST. The left-most child has an order of
227232
* 0.
228233
*/
229-
val Order = flatgraph.SinglePropertyKey[Int](kind = 41, name = "ORDER", default = -1: Int)
234+
val Order = flatgraph.SinglePropertyKey[Int](kind = 42, name = "ORDER", default = -1: Int)
230235

231236
/** The field contains the names of the overlays applied to this CPG, in order of their application. Names are
232237
* free-form strings, that is, this specification does not dictate them but rather requires tool producers and
233238
* consumers to communicate them between each other.
234239
*/
235-
val Overlays = flatgraph.MultiPropertyKey[String](kind = 42, name = "OVERLAYS")
240+
val Overlays = flatgraph.MultiPropertyKey[String](kind = 43, name = "OVERLAYS")
236241

237242
/** AST node type name emitted by parser. */
238-
val ParserTypeName = flatgraph.SinglePropertyKey[String](kind = 43, name = "PARSER_TYPE_NAME", default = "<empty>")
243+
val ParserTypeName = flatgraph.SinglePropertyKey[String](kind = 44, name = "PARSER_TYPE_NAME", default = "<empty>")
239244

240245
/** Similar to `DYNAMIC_TYPE_HINT_FULL_NAME`, but that this makes no guarantee that types within this property are
241246
* correct. This property is used to capture observations between node interactions during a 'may-analysis'.
242247
*/
243-
val PossibleTypes = flatgraph.MultiPropertyKey[String](kind = 44, name = "POSSIBLE_TYPES")
248+
val PossibleTypes = flatgraph.MultiPropertyKey[String](kind = 45, name = "POSSIBLE_TYPES")
244249

245250
/** The path to the root directory of the source/binary this CPG is generated from. */
246-
val Root = flatgraph.SinglePropertyKey[String](kind = 45, name = "ROOT", default = "<empty>")
251+
val Root = flatgraph.SinglePropertyKey[String](kind = 46, name = "ROOT", default = "<empty>")
247252

248253
/** The method signature encodes the types of parameters in a string. The string SHOULD be human readable and suitable
249254
* for differentiating methods with different parameter types sufficiently to allow for resolving of function
250255
* overloading. The present specification does not enforce a strict format for the signature, that is, it can be
251256
* chosen by the frontend implementor to fit the source language.
252257
*/
253-
val Signature = flatgraph.SinglePropertyKey[String](kind = 46, name = "SIGNATURE", default = "")
258+
val Signature = flatgraph.SinglePropertyKey[String](kind = 47, name = "SIGNATURE", default = "")
254259

255260
/** The `STATIC_RECEIVER` field is used to keep track of the type on which a static method is called for static
256261
* methods which may be inherited. This information can then be used to find the true `METHOD_FULL_NAME` of the
257262
* method being called during call linking. For example, if a class `Foo` defines a static method `foo` and a class
258263
* `Bar extends Foo`, then the `STATIC_RECEIVER` of a`Bar.foo()` call is `Bar` and the `METHOD_FULL_NAME` of the
259264
* `foo` call is rewritten to `Foo.foo:<signature>`.
260265
*/
261-
val StaticReceiver = flatgraph.OptionalPropertyKey[String](kind = 47, name = "STATIC_RECEIVER")
266+
val StaticReceiver = flatgraph.OptionalPropertyKey[String](kind = 48, name = "STATIC_RECEIVER")
262267

263268
/** The static type decl of a TYPE. This property is matched against the FULL_NAME of TYPE_DECL nodes. It is required
264269
* to have exactly one TYPE_DECL for each different TYPE_DECL_FULL_NAME
265270
*/
266271
val TypeDeclFullName =
267-
flatgraph.SinglePropertyKey[String](kind = 48, name = "TYPE_DECL_FULL_NAME", default = "<empty>")
272+
flatgraph.SinglePropertyKey[String](kind = 49, name = "TYPE_DECL_FULL_NAME", default = "<empty>")
268273

269274
/** This field contains the fully-qualified static type name of the program construct represented by a node. It is the
270275
* name of an instantiated type, e.g., `java.util.List<Integer>`, rather than `java.util.List[T]`. If the type cannot
271276
* be determined, this field should be set to the empty string.
272277
*/
273-
val TypeFullName = flatgraph.SinglePropertyKey[String](kind = 49, name = "TYPE_FULL_NAME", default = "<empty>")
278+
val TypeFullName = flatgraph.SinglePropertyKey[String](kind = 50, name = "TYPE_FULL_NAME", default = "<empty>")
274279

275280
/** This property denotes a string value as used in a key-value pair. */
276-
val Value = flatgraph.SinglePropertyKey[String](kind = 50, name = "VALUE", default = "")
281+
val Value = flatgraph.SinglePropertyKey[String](kind = 51, name = "VALUE", default = "")
277282

278283
/** A version, given as a string. Used, for example, in the META_DATA node to indicate which version of the CPG spec
279284
* this CPG conforms to
280285
*/
281-
val Version = flatgraph.SinglePropertyKey[String](kind = 51, name = "VERSION", default = "<empty>")
286+
val Version = flatgraph.SinglePropertyKey[String](kind = 52, name = "VERSION", default = "<empty>")
282287
}

domainClasses/src/main/generated/io/shiftleft/codepropertygraph/generated/PropertyNames.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,11 @@ object PropertyNames {
169169
*/
170170
val IsExternal: String = "IS_EXTERNAL"
171171

172+
/** Specifies whether this is a module import. This is used for languages like Java >= 25 where packages exported by a
173+
* module can be imported via the module name (which does not need to match the package names in any way).
174+
*/
175+
val IsModuleImport: String = "IS_MODULE_IMPORT"
176+
172177
/** Specifies whether a parameter is the variadic argument handling parameter of a variadic method. Only one parameter
173178
* of a method is allowed to have this property set to true.
174179
*/
@@ -331,6 +336,7 @@ object PropertyNames {
331336
InheritsFromTypeFullName,
332337
IsExplicit,
333338
IsExternal,
339+
IsModuleImport,
334340
IsVariadic,
335341
IsWildcard,
336342
Key,

domainClasses/src/main/generated/io/shiftleft/codepropertygraph/generated/accessors/Accessors.scala

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -202,24 +202,28 @@ object Accessors {
202202
default = false: Boolean
203203
)
204204
}
205+
final class AccessPropertyIsModuleImport(val node: nodes.StoredNode) extends AnyVal {
206+
def isModuleImport: Option[Boolean] = flatgraph.Accessors
207+
.getNodePropertyOption[Boolean](node.graph, nodeKind = node.nodeKind, propertyKind = 30, seq = node.seq)
208+
}
205209
final class AccessPropertyIsVariadic(val node: nodes.StoredNode) extends AnyVal {
206210
def isVariadic: Boolean = flatgraph.Accessors.getNodePropertySingle(
207211
node.graph,
208212
nodeKind = node.nodeKind,
209-
propertyKind = 30,
213+
propertyKind = 31,
210214
seq = node.seq(),
211215
default = false: Boolean
212216
)
213217
}
214218
final class AccessPropertyIsWildcard(val node: nodes.StoredNode) extends AnyVal {
215219
def isWildcard: Option[Boolean] = flatgraph.Accessors
216-
.getNodePropertyOption[Boolean](node.graph, nodeKind = node.nodeKind, propertyKind = 31, seq = node.seq)
220+
.getNodePropertyOption[Boolean](node.graph, nodeKind = node.nodeKind, propertyKind = 32, seq = node.seq)
217221
}
218222
final class AccessPropertyKey(val node: nodes.StoredNode) extends AnyVal {
219223
def key: String = flatgraph.Accessors.getNodePropertySingle(
220224
node.graph,
221225
nodeKind = node.nodeKind,
222-
propertyKind = 32,
226+
propertyKind = 33,
223227
seq = node.seq(),
224228
default = "<empty>": String
225229
)
@@ -228,24 +232,24 @@ object Accessors {
228232
def language: String = flatgraph.Accessors.getNodePropertySingle(
229233
node.graph,
230234
nodeKind = node.nodeKind,
231-
propertyKind = 33,
235+
propertyKind = 34,
232236
seq = node.seq(),
233237
default = "<empty>": String
234238
)
235239
}
236240
final class AccessPropertyLineNumber(val node: nodes.StoredNode) extends AnyVal {
237241
def lineNumber: Option[Int] = flatgraph.Accessors
238-
.getNodePropertyOption[Int](node.graph, nodeKind = node.nodeKind, propertyKind = 34, seq = node.seq)
242+
.getNodePropertyOption[Int](node.graph, nodeKind = node.nodeKind, propertyKind = 35, seq = node.seq)
239243
}
240244
final class AccessPropertyLineNumberEnd(val node: nodes.StoredNode) extends AnyVal {
241245
def lineNumberEnd: Option[Int] = flatgraph.Accessors
242-
.getNodePropertyOption[Int](node.graph, nodeKind = node.nodeKind, propertyKind = 35, seq = node.seq)
246+
.getNodePropertyOption[Int](node.graph, nodeKind = node.nodeKind, propertyKind = 36, seq = node.seq)
243247
}
244248
final class AccessPropertyMethodFullName(val node: nodes.StoredNode) extends AnyVal {
245249
def methodFullName: String = flatgraph.Accessors.getNodePropertySingle(
246250
node.graph,
247251
nodeKind = node.nodeKind,
248-
propertyKind = 36,
252+
propertyKind = 37,
249253
seq = node.seq(),
250254
default = "<empty>": String
251255
)
@@ -254,7 +258,7 @@ object Accessors {
254258
def modifierType: String = flatgraph.Accessors.getNodePropertySingle(
255259
node.graph,
256260
nodeKind = node.nodeKind,
257-
propertyKind = 37,
261+
propertyKind = 38,
258262
seq = node.seq(),
259263
default = "<empty>": String
260264
)
@@ -263,50 +267,50 @@ object Accessors {
263267
def name: String = flatgraph.Accessors.getNodePropertySingle(
264268
node.graph,
265269
nodeKind = node.nodeKind,
266-
propertyKind = 38,
270+
propertyKind = 39,
267271
seq = node.seq(),
268272
default = "<empty>": String
269273
)
270274
}
271275
final class AccessPropertyOffset(val node: nodes.StoredNode) extends AnyVal {
272276
def offset: Option[Int] = flatgraph.Accessors
273-
.getNodePropertyOption[Int](node.graph, nodeKind = node.nodeKind, propertyKind = 39, seq = node.seq)
277+
.getNodePropertyOption[Int](node.graph, nodeKind = node.nodeKind, propertyKind = 40, seq = node.seq)
274278
}
275279
final class AccessPropertyOffsetEnd(val node: nodes.StoredNode) extends AnyVal {
276280
def offsetEnd: Option[Int] = flatgraph.Accessors
277-
.getNodePropertyOption[Int](node.graph, nodeKind = node.nodeKind, propertyKind = 40, seq = node.seq)
281+
.getNodePropertyOption[Int](node.graph, nodeKind = node.nodeKind, propertyKind = 41, seq = node.seq)
278282
}
279283
final class AccessPropertyOrder(val node: nodes.StoredNode) extends AnyVal {
280284
def order: Int = flatgraph.Accessors.getNodePropertySingle(
281285
node.graph,
282286
nodeKind = node.nodeKind,
283-
propertyKind = 41,
287+
propertyKind = 42,
284288
seq = node.seq(),
285289
default = -1: Int
286290
)
287291
}
288292
final class AccessPropertyOverlays(val node: nodes.StoredNode) extends AnyVal {
289293
def overlays: IndexedSeq[String] = flatgraph.Accessors
290-
.getNodePropertyMulti[String](node.graph, nodeKind = node.nodeKind, propertyKind = 42, seq = node.seq)
294+
.getNodePropertyMulti[String](node.graph, nodeKind = node.nodeKind, propertyKind = 43, seq = node.seq)
291295
}
292296
final class AccessPropertyParserTypeName(val node: nodes.StoredNode) extends AnyVal {
293297
def parserTypeName: String = flatgraph.Accessors.getNodePropertySingle(
294298
node.graph,
295299
nodeKind = node.nodeKind,
296-
propertyKind = 43,
300+
propertyKind = 44,
297301
seq = node.seq(),
298302
default = "<empty>": String
299303
)
300304
}
301305
final class AccessPropertyPossibleTypes(val node: nodes.StoredNode) extends AnyVal {
302306
def possibleTypes: IndexedSeq[String] = flatgraph.Accessors
303-
.getNodePropertyMulti[String](node.graph, nodeKind = node.nodeKind, propertyKind = 44, seq = node.seq)
307+
.getNodePropertyMulti[String](node.graph, nodeKind = node.nodeKind, propertyKind = 45, seq = node.seq)
304308
}
305309
final class AccessPropertyRoot(val node: nodes.StoredNode) extends AnyVal {
306310
def root: String = flatgraph.Accessors.getNodePropertySingle(
307311
node.graph,
308312
nodeKind = node.nodeKind,
309-
propertyKind = 45,
313+
propertyKind = 46,
310314
seq = node.seq(),
311315
default = "<empty>": String
312316
)
@@ -315,20 +319,20 @@ object Accessors {
315319
def signature: String = flatgraph.Accessors.getNodePropertySingle(
316320
node.graph,
317321
nodeKind = node.nodeKind,
318-
propertyKind = 46,
322+
propertyKind = 47,
319323
seq = node.seq(),
320324
default = "": String
321325
)
322326
}
323327
final class AccessPropertyStaticReceiver(val node: nodes.StoredNode) extends AnyVal {
324328
def staticReceiver: Option[String] = flatgraph.Accessors
325-
.getNodePropertyOption[String](node.graph, nodeKind = node.nodeKind, propertyKind = 47, seq = node.seq)
329+
.getNodePropertyOption[String](node.graph, nodeKind = node.nodeKind, propertyKind = 48, seq = node.seq)
326330
}
327331
final class AccessPropertyTypeDeclFullName(val node: nodes.StoredNode) extends AnyVal {
328332
def typeDeclFullName: String = flatgraph.Accessors.getNodePropertySingle(
329333
node.graph,
330334
nodeKind = node.nodeKind,
331-
propertyKind = 48,
335+
propertyKind = 49,
332336
seq = node.seq(),
333337
default = "<empty>": String
334338
)
@@ -337,7 +341,7 @@ object Accessors {
337341
def typeFullName: String = flatgraph.Accessors.getNodePropertySingle(
338342
node.graph,
339343
nodeKind = node.nodeKind,
340-
propertyKind = 49,
344+
propertyKind = 50,
341345
seq = node.seq(),
342346
default = "<empty>": String
343347
)
@@ -346,7 +350,7 @@ object Accessors {
346350
def value: String = flatgraph.Accessors.getNodePropertySingle(
347351
node.graph,
348352
nodeKind = node.nodeKind,
349-
propertyKind = 50,
353+
propertyKind = 51,
350354
seq = node.seq(),
351355
default = "": String
352356
)
@@ -355,7 +359,7 @@ object Accessors {
355359
def version: String = flatgraph.Accessors.getNodePropertySingle(
356360
node.graph,
357361
nodeKind = node.nodeKind,
358-
propertyKind = 51,
362+
propertyKind = 52,
359363
seq = node.seq(),
360364
default = "<empty>": String
361365
)
@@ -547,6 +551,10 @@ object Accessors {
547551
case stored: nodes.StoredNode => new AccessPropertyIsExplicit(stored).isExplicit
548552
case newNode: nodes.NewImport => newNode.isExplicit
549553
}
554+
def isModuleImport: Option[Boolean] = node match {
555+
case stored: nodes.StoredNode => new AccessPropertyIsModuleImport(stored).isModuleImport
556+
case newNode: nodes.NewImport => newNode.isModuleImport
557+
}
550558
def isWildcard: Option[Boolean] = node match {
551559
case stored: nodes.StoredNode => new AccessPropertyIsWildcard(stored).isWildcard
552560
case newNode: nodes.NewImport => newNode.isWildcard
@@ -1084,6 +1092,9 @@ trait ConcreteStoredConversions extends ConcreteBaseConversions {
10841092
implicit def accessPropertyIsExternal(
10851093
node: nodes.StoredNode & nodes.StaticType[nodes.HasIsExternalEMT]
10861094
): AccessPropertyIsExternal = new AccessPropertyIsExternal(node)
1095+
implicit def accessPropertyIsModuleImport(
1096+
node: nodes.StoredNode & nodes.StaticType[nodes.HasIsModuleImportEMT]
1097+
): AccessPropertyIsModuleImport = new AccessPropertyIsModuleImport(node)
10871098
implicit def accessPropertyIsVariadic(
10881099
node: nodes.StoredNode & nodes.StaticType[nodes.HasIsVariadicEMT]
10891100
): AccessPropertyIsVariadic = new AccessPropertyIsVariadic(node)

domainClasses/src/main/generated/io/shiftleft/codepropertygraph/generated/nodes/BaseTypes.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,11 @@ trait HasIsExplicitEMT
263263
*/
264264
trait HasIsExternalEMT
265265

266+
/** Node types with this marker trait are guaranteed to have the IS_MODULE_IMPORT property. EMT stands for: "erased
267+
* marker trait", it exists only at compile time in order to improve type safety.
268+
*/
269+
trait HasIsModuleImportEMT
270+
266271
/** Node types with this marker trait are guaranteed to have the IS_VARIADIC property. EMT stands for: "erased marker
267272
* trait", it exists only at compile time in order to improve type safety.
268273
*/

0 commit comments

Comments
 (0)