[javasrc2cpg] Populate generic signatures roughly following the class file signature format #5274
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The generic signatures added by this PR follow the format described in https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.9.1 and largely correspond to the generic signatures in class files with some notable differences:
Class type signatures
LString;
will be used instead ofLjava/lang/String
)Ljava.util.List
(note the.
were not substituted for/
.Ltestpackage.TestClass.testMethod.LocalClass;
Type parameter bounds
From the language specification:
If a type parameter only has interface bounds I1, I2, ..., then the signature should contain
<T::LI1;:...>
(note the empty class bound), but in general we won't know if a type is a class or interface without resolving the it, so the signature in the CPG will contain<T:LI1;:...>
instead.Unspecified types
Where no type name is specified, the special
L__unspecified_type;
type is used in generic signatures. This happens in a few places:var
type, for examplevar x = 42
foreach
loops, for example infor (String item : items())
, we create a temporaryString[] $iterLocal0 = items()
local which will have an unspecified signature (item
will still have the signatureLString;
as expected)instanceof
expressions with pattern matching, for example infoo() instanceof String s
, we create anObject o = foo()
local (since the type depends on the return type offoo
).