print synthetic constructors in PrintAst.ql

This commit is contained in:
Erik Krogh Kristensen
2020-10-19 11:10:14 +02:00
parent 5b1ed97d68
commit 8f6165cd5f
3 changed files with 61 additions and 11 deletions

View File

@@ -30,22 +30,12 @@ private predicate shouldPrint(Locatable e, Location l) {
exists(PrintAstConfiguration config | config.shouldPrint(e, l))
}
/** Holds if the given element does not need to be rendered in the AST, due to being compiler-generated or being a `TopLevel`. */
/** Holds if the given element does not need to be rendered in the AST, due to being the `TopLevel` for a file. */
private predicate isNotNeeded(Locatable el) {
exists(ClassDefinition c, ConstructorDeclaration constructor |
constructor = c.getConstructor() and
constructor.isSynthetic() and
el = constructor
)
or
el instanceof TopLevel and
el.getLocation().getStartLine() = 0 and
el.getLocation().getStartColumn() = 0
or
exists(ASTNode parent | isNotNeeded(parent) and not parent instanceof TopLevel |
el = parent.getAChild()
)
or
// relaxing aggresive type inference.
none()
}