Fraunhofer-AISEC / cpg

A library to extract Code Property Graphs from C/C++, Java, Go, Python, Ruby and every other language through LLVM-IR.
https://fraunhofer-aisec.github.io/cpg/
Apache License 2.0
246 stars 59 forks source link

Java Frontend: Multi-Field declaration statements omit all but their first declaration #1548

Open robinmaisch opened 3 weeks ago

robinmaisch commented 3 weeks ago

In de.fraunhofer.aisec.cpg.frontends.java.DeclarationHandler::242:

// TODO: can field have more than one variable?

The answer is yes :) Multi-variable declarations are wrapped in a DeclarationStatement, but statements only live inside of methods, so I guess multi-field declarations should be mapped to multiple independent FieldDeclarations. However, the most important thing is that the field declaration appears in the target RecordDeclaration.

Example:

public class Point {
    int x, y;
    ...
}

results in RecordDeclaration with only one field x. Any access to y will be mapped to a placeholder field declaration.