AstCreator

class AstCreator(filename: String, javaParserAst: CompilationUnit, global: Global) extends AstCreatorBase

Translate a Java Parser AST into a CPG AST

Companion:
object
class AstCreatorBase
class Object
trait Matchable
class Any

Value members

Concrete methods

def astForArrayAccessExpr(expr: ArrayAccessExpr, order: Int, expectedType: Option[String]): AstWithCtx
def astForArrayCreationExpr(expr: ArrayCreationExpr, order: Int, expectedType: Option[String]): AstWithCtx
def astForArrayInitializerExpr(expr: ArrayInitializerExpr, order: Int, expectedType: Option[String]): AstWithCtx
def astForBinaryExpr(expr: BinaryExpr, order: Int, expectedType: Option[String]): AstWithCtx
def astForBreakStatement(stmt: BreakStmt, order: Int): AstWithCtx
def astForCastExpr(expr: CastExpr, order: Int, expectedType: Option[String]): AstWithCtx
def astForCatchClause(catchClause: CatchClause, order: Int): AstWithCtx
def astForClassExpr(expr: ClassExpr, order: Int): AstWithCtx
def astForConditionalExpr(expr: ConditionalExpr, order: Int, expectedType: Option[String]): AstWithCtx
def astForContinueStatement(stmt: ContinueStmt, order: Int): AstWithCtx
def astForDo(stmt: DoStmt, order: Int): AstWithCtx
def astForEnclosedExpression(expr: EnclosedExpr, order: Int, expectedType: Option[String]): Seq[AstWithCtx]
def astForFieldAccessExpr(expr: FieldAccessExpr, order: Int, expectedType: Option[String]): AstWithCtx
def astForFor(stmt: ForStmt, order: Int): AstWithCtx
def astForForEach(stmt: ForEachStmt, order: Int): AstWithCtx
def astForIf(stmt: IfStmt, order: Int): AstWithCtx
def astForInstanceOfExpr(expr: InstanceOfExpr, order: Int): AstWithCtx
def astForNameExpr(x: NameExpr, order: Int, expectedType: Option[String]): AstWithCtx
def astForObjectCreationExpr(expr: ObjectCreationExpr, order: Int, expectedType: Option[String]): AstWithCtx

The below representation for constructor invocations and object creations was chosen for the sake of consistency with the Java frontend. It follows the bytecode approach of splitting a constructor call into separate alloc and init calls.

The below representation for constructor invocations and object creations was chosen for the sake of consistency with the Java frontend. It follows the bytecode approach of splitting a constructor call into separate alloc and init calls.

There are two cases to consider. The first is a constructor invocation in an assignment, for example:

Foo f = new Foo(42);

is represented as

Foo f = .alloc() f.init(42);

The second case is a constructor invocation not in an assignment, for example as an argument to a method call. In this case, the representation does not stay as close to Java as in case

  1. In particular, a new BLOCK is introduced to contain the constructor invocation. For example:

foo(new Foo(42));

is represented as

foo({ Foo temp = alloc(); temp.init(42); temp })

This is not valid Java code, but this representation is a decent compromise between staying faithful to Java and being consistent with the Java bytecode frontend.

def astForSwitchEntry(entry: SwitchEntry, order: Int): Seq[AstWithCtx]
def astForSwitchStatement(stmt: SwitchStmt, order: Int): AstWithCtx
def astForThisExpr(expr: ThisExpr, order: Int, expectedType: Option[String]): AstWithCtx
def astForThrow(stmt: ThrowStmt, order: Int): AstWithCtx
def astForTry(stmt: TryStmt, order: Int): AstWithCtx
def astForUnaryExpr(expr: UnaryExpr, order: Int, expectedType: Option[String]): AstWithCtx
def astForWhile(stmt: WhileStmt, order: Int): AstWithCtx
def astsForAssignExpr(expr: AssignExpr, order: Int, expectedType: Option[String]): Seq[AstWithCtx]
def astsForLabeledStatement(stmt: LabeledStmt, order: Int): Seq[AstWithCtx]
def astsForVariableDecl(varDecl: VariableDeclarationExpr, order: Int): Seq[AstWithCtx]
def callAst(rootNode: NewCall, args: Seq[AstWithCtx]): AstWithCtx
def createAst(): DiffGraphBuilder

Entry point of AST creation. Translates a compilation unit created by JavaParser into a DiffGraph containing the corresponding CPG AST.

Entry point of AST creation. Translates a compilation unit created by JavaParser into a DiffGraph containing the corresponding CPG AST.

def storeInDiffGraph(astWithCtx: AstWithCtx): Unit

Copy nodes/edges of given AST into the diff graph

Copy nodes/edges of given AST into the diff graph

Inherited methods

def absolutePath(filename: String): String

Absolute path for the given file name

Absolute path for the given file name

Inherited from:
AstCreatorBase
def callAst(callNode: NewCall, arguments: List[Ast], receiver: Option[Ast]): Ast

For a given call node, arguments, and optionally, a receiver, create an AST that represents the call site. The main purpose of this method is to automatically assign the correct argument indices.

For a given call node, arguments, and optionally, a receiver, create an AST that represents the call site. The main purpose of this method is to automatically assign the correct argument indices.

Inherited from:
AstCreatorBase
def globalNamespaceBlock(): NewNamespaceBlock

Create a global namespace block for the given filename

Create a global namespace block for the given filename

Inherited from:
AstCreatorBase
def methodAst(method: NewMethod, parameters: Seq[NewMethodParameterIn], body: Ast, methodReturn: NewMethodReturn): Ast

Creates an AST that represents an entire method, including its content.

Creates an AST that represents an entire method, including its content.

Inherited from:
AstCreatorBase
def methodReturnNode(line: Option[Integer], column: Option[Integer], tpe: String): NewMethodReturn

Create a method return node

Create a method return node

Inherited from:
AstCreatorBase
def methodStubAst(method: NewMethod, parameters: Seq[NewMethodParameterIn], methodReturn: NewMethodReturn): Ast

Creates an AST that represents a method stub, containing information about the method, its parameters, and the return type.

Creates an AST that represents a method stub, containing information about the method, its parameters, and the return type.

Inherited from:
AstCreatorBase
def withIndex[T, X](nodes: Array[T])(f: (T, Int) => X): Seq[X]
Inherited from:
AstCreatorBase
def withIndex[T, X](nodes: Seq[T])(f: (T, Int) => X): Seq[X]
Inherited from:
AstCreatorBase

Concrete fields

var lambdaCounter: Int

Inherited fields

val diffGraph: DiffGraphBuilder
Inherited from:
AstCreatorBase