Skip to content

Commit 16241ee

Browse files
Centralized all protoIds into (#1809)
As a means of record keeping, aggregated all ProtoIds entries into a single object.
1 parent b416f7b commit 16241ee

21 files changed

+345
-170
lines changed

Diff for: schema/src/main/scala/io/shiftleft/codepropertygraph/schema/Annotation.scala

+5-5
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ object Annotation extends SchemaBase {
4747
|itself and not the ANNOTATION node.
4848
|""".stripMargin
4949
)
50-
.protoId(5)
50+
.protoId(ProtoIds.Annotation)
5151
.addProperties(name, fullName)
5252
.extendz(expression)
5353

@@ -56,23 +56,23 @@ object Annotation extends SchemaBase {
5656
name = "ANNOTATION_PARAMETER_ASSIGN",
5757
comment = "Assignment of annotation argument to annotation parameter"
5858
)
59-
.protoId(6)
59+
.protoId(ProtoIds.AnnotationParameterAssign)
6060
.extendz(astNode)
6161

6262
val annotationParameter: NodeType = builder
6363
.addNodeType(name = "ANNOTATION_PARAMETER", comment = "Formal annotation parameter")
64-
.protoId(7)
64+
.protoId(ProtoIds.AnnotationParameter)
6565
.extendz(astNode)
6666

6767
val annotationLiteral: NodeType = builder
6868
.addNodeType(name = "ANNOTATION_LITERAL", comment = "A literal value assigned to an ANNOTATION_PARAMETER")
69-
.protoId(49)
69+
.protoId(ProtoIds.AnnotationLiteral)
7070
.addProperties(name)
7171
.extendz(expression)
7272

7373
val arrayInitializer: NodeType = builder
7474
.addNodeType(name = "ARRAY_INITIALIZER", comment = "Initialization construct for arrays")
75-
.protoId(14)
75+
.protoId(ProtoIds.ArrayInitializer)
7676
.extendz(astNode)
7777

7878
arrayInitializer

Diff for: schema/src/main/scala/io/shiftleft/codepropertygraph/schema/Ast.scala

+48-48
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ object Ast extends SchemaBase {
6565
|""".stripMargin
6666
)
6767
.mandatory(-1)
68-
.protoId(4)
68+
.protoId(ProtoIds.Order)
6969

7070
val astNode = builder
7171
.addNodeBaseType(
@@ -116,7 +116,7 @@ object Ast extends SchemaBase {
116116
|"block expression") to describe what in the CPG we call "Block".
117117
|""".stripMargin
118118
)
119-
.protoId(31)
119+
.protoId(ProtoIds.Block)
120120
.addProperties(typeFullName)
121121

122122
val literal: NodeType = builder
@@ -128,7 +128,7 @@ object Ast extends SchemaBase {
128128
|e.g., `java.lang.Integer`.
129129
|""".stripMargin
130130
)
131-
.protoId(8)
131+
.protoId(ProtoIds.Literal)
132132
.addProperties(typeFullName)
133133
.primaryKey(code)
134134

@@ -141,7 +141,7 @@ object Ast extends SchemaBase {
141141
|`int x = 10;`, it contains `int x`.
142142
|""".stripMargin
143143
)
144-
.protoId(23)
144+
.protoId(ProtoIds.Local)
145145
.addProperties(typeFullName)
146146
.extendz(declaration, astNode)
147147
.primaryKey(name)
@@ -154,7 +154,7 @@ object Ast extends SchemaBase {
154154
|name in `TYPE_FULL_NAME`.
155155
|""".stripMargin
156156
)
157-
.protoId(27)
157+
.protoId(ProtoIds.Identifier)
158158
.addProperties(typeFullName, name)
159159
.primaryKey(name)
160160

@@ -172,7 +172,7 @@ object Ast extends SchemaBase {
172172
|""".stripMargin
173173
)
174174
.mandatory(PropertyDefaults.String)
175-
.protoId(2001092)
175+
.protoId(ProtoIds.CanonicalName)
176176

177177
val fieldIdentifier: NodeType = builder
178178
.addNodeType(
@@ -189,7 +189,7 @@ object Ast extends SchemaBase {
189189
|it.
190190
|""".stripMargin
191191
)
192-
.protoId(2001081)
192+
.protoId(ProtoIds.FieldIdentifier)
193193
.addProperties(canonicalName)
194194

195195
val modifierType = builder
@@ -201,55 +201,55 @@ object Ast extends SchemaBase {
201201
|""".stripMargin
202202
)
203203
.mandatory(PropertyDefaults.String)
204-
.protoId(26)
204+
.protoId(ProtoIds.ModifierType)
205205

206206
val modifierTypes = builder.addConstants(
207207
category = "ModifierTypes",
208208
Constant(name = "STATIC", value = "STATIC", valueType = ValueType.String, comment = "The static modifier")
209-
.protoId(1),
209+
.protoId(ProtoIds.Static),
210210
Constant(name = "PUBLIC", value = "PUBLIC", valueType = ValueType.String, comment = "The public modifier")
211-
.protoId(2),
211+
.protoId(ProtoIds.Public),
212212
Constant(
213213
name = "PROTECTED",
214214
value = "PROTECTED",
215215
valueType = ValueType.String,
216216
comment = "The protected modifier"
217-
).protoId(3),
217+
).protoId(ProtoIds.Protected),
218218
Constant(name = "PRIVATE", value = "PRIVATE", valueType = ValueType.String, comment = "The private modifier")
219-
.protoId(4),
219+
.protoId(ProtoIds.Private),
220220
Constant(name = "ABSTRACT", value = "ABSTRACT", valueType = ValueType.String, comment = "The abstract modifier")
221-
.protoId(5),
221+
.protoId(ProtoIds.Abstract),
222222
Constant(name = "NATIVE", value = "NATIVE", valueType = ValueType.String, comment = "The native modifier")
223-
.protoId(6),
223+
.protoId(ProtoIds.Native),
224224
Constant(
225225
name = "CONSTRUCTOR",
226226
value = "CONSTRUCTOR",
227227
valueType = ValueType.String,
228228
comment = "The constructor modifier"
229-
).protoId(7),
229+
).protoId(ProtoIds.Constructor),
230230
Constant(name = "VIRTUAL", value = "VIRTUAL", valueType = ValueType.String, comment = "The virtual modifier")
231-
.protoId(8),
231+
.protoId(ProtoIds.Virtual),
232232
Constant(name = "INTERNAL", value = "INTERNAL", valueType = ValueType.String, comment = "The internal modifier")
233-
.protoId(9),
233+
.protoId(ProtoIds.Internal),
234234
Constant(name = "FINAL", value = "FINAL", valueType = ValueType.String, comment = "The final modifier")
235-
.protoId(10),
235+
.protoId(ProtoIds.Final),
236236
Constant(name = "READONLY", value = "READONLY", valueType = ValueType.String, comment = "The readonly modifier")
237-
.protoId(11),
237+
.protoId(ProtoIds.ReadOnly),
238238
Constant(
239239
name = "MODULE",
240240
value = "MODULE",
241241
valueType = ValueType.String,
242242
comment =
243243
"Indicate that a method defines a module in the sense e.g. a python module does with the creation of a module object"
244244
)
245-
.protoId(12),
245+
.protoId(ProtoIds.Module),
246246
Constant(
247247
name = "LAMBDA",
248248
value = "LAMBDA",
249249
valueType = ValueType.String,
250250
comment = "Indicate that a method is an anonymous function, lambda, or closure"
251251
)
252-
.protoId(13)
252+
.protoId(ProtoIds.Lambda)
253253
)
254254

255255
val modifier: NodeType = builder
@@ -260,7 +260,7 @@ object Ast extends SchemaBase {
260260
|cannot be evaluated and cannot be passed as an argument in function calls.
261261
|""".stripMargin
262262
)
263-
.protoId(300)
263+
.protoId(ProtoIds.Modifier)
264264
.addProperties(modifierType)
265265
.extendz(astNode)
266266

@@ -273,7 +273,7 @@ object Ast extends SchemaBase {
273273
|that this jump target is created from, e.g., "Label".
274274
|""".stripMargin
275275
)
276-
.protoId(340)
276+
.protoId(ProtoIds.JumpTarget)
277277
.addProperties(name, parserTypeName)
278278
.extendz(astNode)
279279

@@ -286,7 +286,7 @@ object Ast extends SchemaBase {
286286
|label is created from, e.g., "Label".
287287
|""".stripMargin
288288
)
289-
.protoId(341)
289+
.protoId(ProtoIds.JumpLabel)
290290
.addProperties(name, parserTypeName)
291291
.extendz(astNode)
292292

@@ -299,12 +299,12 @@ object Ast extends SchemaBase {
299299
|`TYPE_FULL_NAME` holds its fully-qualified type name.
300300
|""".stripMargin
301301
)
302-
.protoId(333)
302+
.protoId(ProtoIds.MethodRef)
303303
.addProperties(typeFullName)
304304

305305
val typeRef: NodeType = builder
306306
.addNodeType(name = "TYPE_REF", comment = "Reference to a type/class")
307-
.protoId(335)
307+
.protoId(ProtoIds.TypeRef)
308308
.addProperties(typeFullName)
309309

310310
val ret: NodeType = builder
@@ -315,7 +315,7 @@ object Ast extends SchemaBase {
315315
|represented via `METHOD_RETURN` nodes.
316316
|""".stripMargin
317317
)
318-
.protoId(30)
318+
.protoId(ProtoIds.Return)
319319
.starterName("ret")
320320
.primaryKey(code)
321321

@@ -329,7 +329,7 @@ object Ast extends SchemaBase {
329329
|""".stripMargin
330330
)
331331
.mandatory(PropertyDefaults.String)
332-
.protoId(27)
332+
.protoId(ProtoIds.ControlStructureType)
333333

334334
val controlStructureTypes = builder.addConstants(
335335
category = "ControlStructureTypes",
@@ -339,49 +339,49 @@ object Ast extends SchemaBase {
339339
valueType = ValueType.String,
340340
comment = """Represents a break statement. Labeled breaks are expected to have a JUMP_LABEL
341341
|node AST child with ORDER 1""".stripMargin
342-
).protoId(1),
342+
).protoId(ProtoIds.Break),
343343
Constant(
344344
name = "CONTINUE",
345345
value = "CONTINUE",
346346
valueType = ValueType.String,
347347
comment = """Represents a continue statement. Labeled continues are expected to have a JUMP_LABEL
348348
|node AST child with ORDER 1""".stripMargin
349-
).protoId(2),
349+
).protoId(ProtoIds.Continue),
350350
Constant(name = "WHILE", value = "WHILE", valueType = ValueType.String, comment = "Represents a while statement")
351-
.protoId(3),
351+
.protoId(ProtoIds.While),
352352
Constant(name = "DO", value = "DO", valueType = ValueType.String, comment = "Represents a do statement")
353-
.protoId(4),
353+
.protoId(ProtoIds.Do),
354354
Constant(name = "FOR", value = "FOR", valueType = ValueType.String, comment = "Represents a for statement")
355-
.protoId(5),
355+
.protoId(ProtoIds.For),
356356
Constant(name = "GOTO", value = "GOTO", valueType = ValueType.String, comment = "Represents a goto statement")
357-
.protoId(6),
357+
.protoId(ProtoIds.Goto),
358358
Constant(name = "IF", value = "IF", valueType = ValueType.String, comment = "Represents an if statement")
359-
.protoId(7),
359+
.protoId(ProtoIds.If),
360360
Constant(name = "ELSE", value = "ELSE", valueType = ValueType.String, comment = "Represents an else statement")
361-
.protoId(8),
361+
.protoId(ProtoIds.Else),
362362
Constant(
363363
name = "SWITCH",
364364
value = "SWITCH",
365365
valueType = ValueType.String,
366366
comment = "Represents a switch statement"
367-
).protoId(9),
367+
).protoId(ProtoIds.Switch),
368368
Constant(name = "TRY", value = "TRY", valueType = ValueType.String, comment = "Represents a try statement")
369-
.protoId(10),
369+
.protoId(ProtoIds.Try),
370370
Constant(name = "THROW", value = "THROW", valueType = ValueType.String, comment = "Represents a throw statement")
371-
.protoId(11),
371+
.protoId(ProtoIds.Throw),
372372
Constant(name = "MATCH", value = "MATCH", valueType = ValueType.String, comment = "Represents a match expression")
373-
.protoId(12),
373+
.protoId(ProtoIds.Match),
374374
Constant(name = "YIELD", value = "YIELD", valueType = ValueType.String, comment = "Represents a yield expression")
375-
.protoId(13),
375+
.protoId(ProtoIds.Yield),
376376
Constant(name = "CATCH", value = "CATCH", valueType = ValueType.String, comment = "Represents a catch clause")
377-
.protoId(14),
377+
.protoId(ProtoIds.Catch),
378378
Constant(
379379
name = "FINALLY",
380380
value = "FINALLY",
381381
valueType = ValueType.String,
382382
comment = "Represents a finally clause"
383383
)
384-
.protoId(15)
384+
.protoId(ProtoIds.Finally)
385385
)
386386

387387
val controlStructure: NodeType = builder
@@ -399,7 +399,7 @@ object Ast extends SchemaBase {
399399
|for construction of the control flow layer.
400400
|""".stripMargin
401401
)
402-
.protoId(339)
402+
.protoId(ProtoIds.ControlStructure)
403403
.addProperties(parserTypeName, controlStructureType)
404404

405405
val unknown: NodeType = builder
@@ -410,21 +410,21 @@ object Ast extends SchemaBase {
410410
|included using a node of type `UNKNOWN`.
411411
|""".stripMargin
412412
)
413-
.protoId(44)
413+
.protoId(ProtoIds.Unknown)
414414
.addProperties(parserTypeName, typeFullName)
415415

416416
// Edge types
417417

418418
val ast = builder
419419
.addEdgeType(name = "AST", comment = "This edge connects a parent node to its child in the syntax tree.")
420-
.protoId(3)
420+
.protoId(ProtoIds.Ast)
421421

422422
val condition = builder
423423
.addEdgeType(
424424
name = "CONDITION",
425425
comment = "The edge connects control structure nodes to the expressions that holds their conditions."
426426
)
427-
.protoId(56)
427+
.protoId(ProtoIds.Condition)
428428

429429
file.addOutEdge(edge = ast, inNode = namespaceBlock, cardinalityIn = Cardinality.ZeroOrOne)
430430

@@ -578,7 +578,7 @@ object Ast extends SchemaBase {
578578
|any information we may have about the types of arguments and return value.
579579
|""".stripMargin
580580
)
581-
.protoId(15)
581+
.protoId(ProtoIds.CallNode)
582582
.extendz(callRepr)
583583
.addProperties(typeFullName)
584584
.primaryKey(name)

0 commit comments

Comments
 (0)