Skip to content

Commit

Permalink
++
Browse files Browse the repository at this point in the history
  • Loading branch information
oxisto committed Nov 21, 2024
1 parent 69e2d04 commit 3163354
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -242,24 +242,28 @@ class ExpressionHandler(lang: JavaLanguageFrontend) :
): de.fraunhofer.aisec.cpg.graph.statements.expressions.Expression {
val fieldAccessExpr = expr.asFieldAccessExpr()

var baseType = unknownType()
var fieldType = unknownType()
// We can "try" to resolve the field using JavaParser's logic. The main reason we WANT to do
// this is to get information about system types, as long as we are not fully doing that on
// our own.
var type =
try {
val symbol = fieldAccessExpr.resolve()
objectType(symbol.type.describe())
} catch (_: UnsolvedSymbolException) {
unknownType()
try {
val symbol = fieldAccessExpr.resolve()
baseType = frontend.typeOf(symbol.type)

if (symbol.isField) {
fieldType = objectType(symbol.asField().declaringType().qualifiedName)
}
} catch (_: UnsolvedSymbolException) {}

var base =
handle(fieldAccessExpr.scope)
as de.fraunhofer.aisec.cpg.graph.statements.expressions.Expression
base.type = baseType
return newMemberExpression(
fieldAccessExpr.name.identifier,
base,
type,
fieldType,
operatorCode = ".",
rawNode = fieldAccessExpr
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ open class JavaLanguageFrontend(language: Language<JavaLanguageFrontend>, ctx: T
scopeManager.addDeclaration(incl)
}

// We create an implicit import for "java.lang.*"
val decl =
newImportDeclaration(Name("java.lang"), wildcardImport = true)
.implicit("import java.lang.*")
scopeManager.addDeclaration(decl)

if (namespaceDeclaration != null) {
scopeManager.leaveScope(namespaceDeclaration)
}
Expand Down

0 comments on commit 3163354

Please sign in to comment.