diff --git a/cpg-language-java/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/java/ExpressionHandler.kt b/cpg-language-java/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/java/ExpressionHandler.kt index 305048c68d5..f7b6742ed89 100644 --- a/cpg-language-java/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/java/ExpressionHandler.kt +++ b/cpg-language-java/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/java/ExpressionHandler.kt @@ -249,10 +249,10 @@ class ExpressionHandler(lang: JavaLanguageFrontend) : // our own. try { val symbol = fieldAccessExpr.resolve() - baseType = frontend.typeOf(symbol.type) + fieldType = frontend.typeOf(symbol.type) if (symbol.isField) { - fieldType = objectType(symbol.asField().declaringType().qualifiedName) + baseType = objectType(symbol.asField().declaringType().qualifiedName) } } catch (_: UnsolvedSymbolException) {} diff --git a/cpg-language-java/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/java/JavaLanguageFrontend.kt b/cpg-language-java/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/java/JavaLanguageFrontend.kt index abe00cf29eb..87769aa050a 100644 --- a/cpg-language-java/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/java/JavaLanguageFrontend.kt +++ b/cpg-language-java/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/java/JavaLanguageFrontend.kt @@ -145,7 +145,7 @@ open class JavaLanguageFrontend(language: Language, ctx: T // We create an implicit import for "java.lang.*" val decl = - newImportDeclaration(Name("java.lang"), wildcardImport = true) + newImportDeclaration(parseName("java.lang"), wildcardImport = true) .implicit("import java.lang.*") scopeManager.addDeclaration(decl) diff --git a/cpg-language-java/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/JavaExtraPass.kt b/cpg-language-java/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/JavaExtraPass.kt index 6b31298fd6d..7984ca5dfca 100644 --- a/cpg-language-java/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/JavaExtraPass.kt +++ b/cpg-language-java/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/JavaExtraPass.kt @@ -27,6 +27,7 @@ package de.fraunhofer.aisec.cpg.passes import de.fraunhofer.aisec.cpg.TranslationContext import de.fraunhofer.aisec.cpg.graph.Node +import de.fraunhofer.aisec.cpg.graph.codeAndLocationFrom import de.fraunhofer.aisec.cpg.graph.declarations.TranslationUnitDeclaration import de.fraunhofer.aisec.cpg.graph.fqn import de.fraunhofer.aisec.cpg.graph.newReference @@ -34,6 +35,7 @@ import de.fraunhofer.aisec.cpg.graph.statements.expressions.CallExpression import de.fraunhofer.aisec.cpg.graph.statements.expressions.MemberExpression import de.fraunhofer.aisec.cpg.graph.statements.expressions.Reference import de.fraunhofer.aisec.cpg.helpers.SubgraphWalker +import de.fraunhofer.aisec.cpg.helpers.replace import de.fraunhofer.aisec.cpg.nameIsType import de.fraunhofer.aisec.cpg.passes.configuration.DependsOn import de.fraunhofer.aisec.cpg.passes.configuration.ExecuteBefore @@ -67,8 +69,11 @@ class JavaExtraPass(ctx: TranslationContext) : TranslationUnitPass(ctx) { // Our base refers to a type, so this is actually a static reference, which we // model not as a member expression, but as a reference with an FQN. Let's build that // and exchange the node - val ref = newReference(type.name.fqn(me.name.localName)).apply { isStaticAccess = true } - println("hello") + val ref = + newReference(type.name.fqn(me.name.localName), type = me.type) + .codeAndLocationFrom(me) + .apply { isStaticAccess = true } + walker.replace(parent, me, ref) } }