From dab9a6446dce43fed80ef45d6820403962d1eb62 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 30 Jan 2024 16:48:59 +0100 Subject: [PATCH 1/2] Update spotless to v6.25.0 (#1413) * Update spotless to v6.25.0 * Fix spotless formatting --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Alexander Kuechler Co-authored-by: KuechA <31155350+KuechA@users.noreply.github.com> --- .../aisec/cpg/analysis/MultiValueEvaluator.kt | 2 +- .../aisec/cpg/TranslationConfiguration.kt | 3 +- .../aisec/cpg/TranslationManager.kt | 3 +- .../de/fraunhofer/aisec/cpg/TypeManager.kt | 3 +- .../fraunhofer/aisec/cpg/frontends/Handler.kt | 2 +- .../aisec/cpg/frontends/Language.kt | 2 +- .../fraunhofer/aisec/cpg/graph/Extensions.kt | 6 +- .../fraunhofer/aisec/cpg/graph/NodeBuilder.kt | 2 - .../fraunhofer/aisec/cpg/graph/TypeBuilder.kt | 3 - .../aisec/cpg/graph/builder/Fluent.kt | 70 ------------------- .../aisec/cpg/helpers/SubgraphWalker.kt | 3 +- .../aisec/cpg/passes/CXXCallResolverHelper.kt | 3 +- .../cpg/passes/ControlDependenceGraphPass.kt | 7 +- .../cpg/passes/ProgramDependenceGraphPass.kt | 3 +- .../aisec/cpg/passes/SymbolResolver.kt | 3 +- .../cpg/frontends/cxx/CXXLanguageFrontend.kt | 2 +- .../cpg/frontends/cxx/DeclarationHandler.kt | 6 +- .../cpg/frontends/cxx/ExpressionHandler.kt | 9 ++- .../aisec/cpg/frontends/golang/GoUtils.kt | 3 +- .../cpg/frontends/java/DeclarationHandler.kt | 3 +- .../cpg/frontends/java/ExpressionHandler.kt | 3 +- .../cpg/frontends/llvm/ExpressionHandler.kt | 3 +- .../frontends/python/PythonFrontendTest.kt | 3 +- .../frontends/typescript/ExpressionHandler.kt | 3 +- .../aisec/cpg_vis_neo4j/Application.kt | 6 +- gradle/libs.versions.toml | 2 +- 26 files changed, 33 insertions(+), 125 deletions(-) diff --git a/cpg-analysis/src/main/kotlin/de/fraunhofer/aisec/cpg/analysis/MultiValueEvaluator.kt b/cpg-analysis/src/main/kotlin/de/fraunhofer/aisec/cpg/analysis/MultiValueEvaluator.kt index 0c89233076..8c24411a4a 100644 --- a/cpg-analysis/src/main/kotlin/de/fraunhofer/aisec/cpg/analysis/MultiValueEvaluator.kt +++ b/cpg-analysis/src/main/kotlin/de/fraunhofer/aisec/cpg/analysis/MultiValueEvaluator.kt @@ -265,7 +265,7 @@ class MultiValueEvaluator : ValueEvaluator() { (forStatement.initializerStatement as? DeclarationStatement)?.singleDeclaration return initializerDecl == node || // The node is the declaration of the loop variable - forStatement.initializerStatement == node || // The node is the initialization + forStatement.initializerStatement == node || // The node is the initialization (initializerDecl != null && initializerDecl == node.astParent) || // The parent of the node is the initializer of the loop diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/TranslationConfiguration.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/TranslationConfiguration.kt index a461a90988..74bfbea49c 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/TranslationConfiguration.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/TranslationConfiguration.kt @@ -406,7 +406,8 @@ private constructor( inline fun < reified OldPass : Pass<*>, reified For : Language<*>, - reified With : Pass<*>> replacePass(): Builder { + reified With : Pass<*> + > replacePass(): Builder { return replacePass(OldPass::class, For::class, With::class) } diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/TranslationManager.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/TranslationManager.kt index e267d9ac3a..49080ca4a5 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/TranslationManager.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/TranslationManager.kt @@ -163,8 +163,7 @@ private constructor( file.language ?.frontend ?.findAnnotation() - ?.supported - ?: true + ?.supported ?: true // By default, the frontends support parallel parsing. But the // SupportsParallelParsing annotation can be set to false and force // to disable it. diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/TypeManager.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/TypeManager.kt index 5f27d5e3de..0a400d4bc1 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/TypeManager.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/TypeManager.kt @@ -345,8 +345,7 @@ val Collection.commonType: Type? // only look at its type. Therefore, ancestors with the same type but // different depths will match here. it == ancestor - } - ?: return@mapNotNull null + } ?: return@mapNotNull null // We then need to select one of both, depending on the depth if (ancestor.depth >= other.depth) { diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/Handler.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/Handler.kt index 9485e0c8e8..7d5b45a2a6 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/Handler.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/Handler.kt @@ -90,7 +90,7 @@ abstract class Handler> : Node() { // A comparison, so we return the type "boolean" return this.builtInTypes.values.firstOrNull { it is BooleanType } ?: this.builtInTypes.values.firstOrNull { it.name.localName.startsWith("bool") } - ?: unknownType() + ?: unknownType() } return when (operation.operatorCode) { diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/Extensions.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/Extensions.kt index c7681c741f..a3e5b55b36 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/Extensions.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/Extensions.kt @@ -161,8 +161,7 @@ inline fun DeclarationHolder.byNameOrNull( base = this.declarations.filterIsInstance().firstOrNull { (it as Node).name.lastPartsMatch(baseName) - } - ?: return null + } ?: return null lookup = name.split(".")[1] } @@ -581,8 +580,7 @@ val Node?.assignments: List get() { return this?.allChildren()?.filterIsInstance()?.flatMap { it.assignments - } - ?: listOf() + } ?: listOf() } /** diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/NodeBuilder.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/NodeBuilder.kt index 685d8d9e03..4b44a56a8d 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/NodeBuilder.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/NodeBuilder.kt @@ -280,7 +280,6 @@ fun T.codeAndLocationFrom(other: Node): T { * expression handler. */ context(CodeAndLocationProvider) - fun T.codeAndLocationFromOtherRawNode(rawNode: AstNode): T { setCodeAndLocation(this@CodeAndLocationProvider, rawNode) return this @@ -299,7 +298,6 @@ fun T.codeAndLocationFromOtherRawNode(rawNode: AstNode): T { * @param parentNode Used to extract the code for this node */ context(CodeAndLocationProvider) - fun T.codeAndLocationFromChildren(parentNode: AstNode): T { var first: Node? = null var last: Node? = null diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/TypeBuilder.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/TypeBuilder.kt index 05a9c75f62..29b7c8229d 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/TypeBuilder.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/TypeBuilder.kt @@ -51,7 +51,6 @@ fun MetadataProvider?.incompleteType(): Type { /** Returns a [PointerType] that describes an array reference to the current type. */ context(ContextProvider) - fun Type.array(): Type { val c = (this@ContextProvider).ctx @@ -65,7 +64,6 @@ fun Type.array(): Type { /** Returns a [PointerType] that describes a pointer reference to the current type. */ context(ContextProvider) - fun Type.pointer(): Type { val c = (this@ContextProvider).ctx @@ -78,7 +76,6 @@ fun Type.pointer(): Type { } context(ContextProvider) - fun Type.ref(): Type { val c = (this@ContextProvider).ctx diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/builder/Fluent.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/builder/Fluent.kt index 56fd3f4d24..39dd32b24b 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/builder/Fluent.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/builder/Fluent.kt @@ -67,7 +67,6 @@ fun LanguageFrontend<*, *>.translationResult( * further sub-nodes as well as configuring the created node itself. */ context(TranslationResult) - fun LanguageFrontend<*, *>.translationUnit( name: CharSequence = Node.EMPTY_NAME, init: TranslationUnitDeclaration.() -> Unit @@ -87,7 +86,6 @@ fun LanguageFrontend<*, *>.translationUnit( * further sub-nodes as well as configuring the created node itself. */ context(DeclarationHolder) - fun LanguageFrontend<*, *>.namespace( name: CharSequence, init: NamespaceDeclaration.() -> Unit @@ -107,7 +105,6 @@ fun LanguageFrontend<*, *>.namespace( * sub-nodes as well as configuring the created node itself. */ context(DeclarationHolder) - fun LanguageFrontend<*, *>.record( name: CharSequence, kind: String = "class", @@ -129,7 +126,6 @@ fun LanguageFrontend<*, *>.record( * created node itself. */ context(DeclarationHolder) - fun LanguageFrontend<*, *>.field( name: CharSequence, type: Type = unknownType(), @@ -149,7 +145,6 @@ fun LanguageFrontend<*, *>.field( * Creates a new [IncludeDeclaration] and adds it to the surrounding [TranslationUnitDeclaration]. */ context(TranslationUnitDeclaration) - fun LanguageFrontend<*, *>.import(name: CharSequence): IncludeDeclaration { val node = newIncludeDeclaration(name) (this@TranslationUnitDeclaration).addDeclaration(node) @@ -162,7 +157,6 @@ fun LanguageFrontend<*, *>.import(name: CharSequence): IncludeDeclaration { * created node itself. */ context(DeclarationHolder) - fun LanguageFrontend<*, *>.function( name: CharSequence, returnType: Type = unknownType(), @@ -195,7 +189,6 @@ fun LanguageFrontend<*, *>.function( * created node itself. */ context(RecordDeclaration) - fun LanguageFrontend<*, *>.method( name: CharSequence, returnType: Type = unknownType(), @@ -223,7 +216,6 @@ fun LanguageFrontend<*, *>.method( * configuring the created node itself. */ context(RecordDeclaration) - fun LanguageFrontend<*, *>.constructor( init: ConstructorDeclaration.() -> Unit ): ConstructorDeclaration { @@ -247,7 +239,6 @@ fun LanguageFrontend<*, *>.constructor( * as well as configuring the created node itself. */ context(FunctionDeclaration) - fun LanguageFrontend<*, *>.body(needsScope: Boolean = true, init: Block.() -> Unit): Block { val node = newBlock() @@ -263,7 +254,6 @@ fun LanguageFrontend<*, *>.body(needsScope: Boolean = true, init: Block.() -> Un * as well as configuring the created node itself. */ context(StatementHolder) - fun LanguageFrontend<*, *>.block(needsScope: Boolean = true, init: Block.() -> Unit): Block { val node = newBlock() @@ -279,7 +269,6 @@ fun LanguageFrontend<*, *>.block(needsScope: Boolean = true, init: Block.() -> U * can be used to create further sub-nodes as well as configuring the created node itself. */ context(FunctionDeclaration) - fun LanguageFrontend<*, *>.param( name: CharSequence, type: Type = unknownType(), @@ -303,7 +292,6 @@ fun LanguageFrontend<*, *>.param( * used to create further sub-nodes as well as configuring the created node itself. */ context(StatementHolder) - fun LanguageFrontend<*, *>.returnStmt(init: ReturnStatement.() -> Unit): ReturnStatement { val node = (this@LanguageFrontend).newReturnStatement() init(node) @@ -314,7 +302,6 @@ fun LanguageFrontend<*, *>.returnStmt(init: ReturnStatement.() -> Unit): ReturnS } context(Holder) - fun LanguageFrontend<*, *>.ase( init: (SubscriptExpression.() -> Unit)? = null ): SubscriptExpression { @@ -339,7 +326,6 @@ fun LanguageFrontend<*, *>.ase( * used to create further sub-nodes as well as configuring the created node itself. */ context(StatementHolder) - fun LanguageFrontend<*, *>.declare(init: DeclarationStatement.() -> Unit): DeclarationStatement { val node = (this@LanguageFrontend).newDeclarationStatement() init(node) @@ -372,7 +358,6 @@ fun LanguageFrontend<*, *>.declareVar( * block can be used to create further sub-nodes as well as configuring the created node itself. */ context(DeclarationStatement) - fun LanguageFrontend<*, *>.variable( name: String, type: Type = unknownType(), @@ -400,7 +385,6 @@ fun LanguageFrontend<*, *>.variable( * can be used to create further sub-nodes as well as configuring the created node itself. */ context(Holder) - fun LanguageFrontend<*, *>.call( name: CharSequence, isStatic: Boolean = false, @@ -442,7 +426,6 @@ fun LanguageFrontend<*, *>.call( * can be used to create further sub-nodes as well as configuring the created node itself. */ context(Holder) - fun LanguageFrontend<*, *>.memberCall( localName: CharSequence, base: Expression, @@ -473,7 +456,6 @@ fun LanguageFrontend<*, *>.memberCall( * used to create further sub-nodes as well as configuring the created node itself. */ context(Holder) - fun LanguageFrontend<*, *>.construct( name: CharSequence, init: (ConstructExpression.() -> Unit)? = null @@ -496,7 +478,6 @@ fun LanguageFrontend<*, *>.construct( } context(Holder) - fun LanguageFrontend<*, *>.cast( castType: Type, init: (CastExpression.() -> Unit)? = null @@ -515,7 +496,6 @@ fun LanguageFrontend<*, *>.cast( } context(Holder) - fun LanguageFrontend<*, *>.new(init: (NewExpression.() -> Unit)? = null): NewExpression { val node = newNewExpression() if (init != null) init(node) @@ -549,7 +529,6 @@ fun LanguageFrontend<*, *>.memberOrRef(name: Name, type: Type = unknownType()): * used to create further sub-nodes as well as configuring the created node itself. */ context(StatementHolder) - fun LanguageFrontend<*, *>.ifStmt(init: IfStatement.() -> Unit): IfStatement { val node = newIfStatement() init(node) @@ -565,7 +544,6 @@ fun LanguageFrontend<*, *>.ifStmt(init: IfStatement.() -> Unit): IfStatement { * used to create further sub-nodes as well as configuring the created node itself. */ context(StatementHolder) - fun LanguageFrontend<*, *>.forEachStmt(init: ForEachStatement.() -> Unit): ForEachStatement { val node = newForEachStatement() @@ -582,7 +560,6 @@ fun LanguageFrontend<*, *>.forEachStmt(init: ForEachStatement.() -> Unit): ForEa * used to create further sub-nodes as well as configuring the created node itself. */ context(StatementHolder) - fun LanguageFrontend<*, *>.forStmt( initializer: DeclarationStatement, condition: Expression, @@ -613,7 +590,6 @@ fun LanguageFrontend<*, *>.forStmt( * used to create further sub-nodes as well as configuring the created node itself. */ context(StatementHolder) - fun LanguageFrontend<*, *>.switchStmt( selector: Expression, needsScope: Boolean = true, @@ -634,7 +610,6 @@ fun LanguageFrontend<*, *>.switchStmt( * used to create further sub-nodes as well as configuring the created node itself. */ context(StatementHolder) - fun LanguageFrontend<*, *>.whileStmt( needsScope: Boolean = true, init: WhileStatement.() -> Unit @@ -653,7 +628,6 @@ fun LanguageFrontend<*, *>.whileStmt( * used to create further sub-nodes as well as configuring the created node itself. */ context(StatementHolder) - fun LanguageFrontend<*, *>.doStmt( needsScope: Boolean = true, init: DoStatement.() -> Unit @@ -674,7 +648,6 @@ fun LanguageFrontend<*, *>.doStmt( * the created node itself. */ context(IfStatement) - fun LanguageFrontend<*, *>.condition(init: IfStatement.() -> Expression): Expression { return init(this@IfStatement) } @@ -685,7 +658,6 @@ fun LanguageFrontend<*, *>.condition(init: IfStatement.() -> Expression): Expres * the created node itself. */ context(WhileStatement) - fun LanguageFrontend<*, *>.whileCondition(init: WhileStatement.() -> Expression): Expression { return init(this@WhileStatement) } @@ -696,7 +668,6 @@ fun LanguageFrontend<*, *>.whileCondition(init: WhileStatement.() -> Expression) * the created node itself. */ context(DoStatement) - fun LanguageFrontend<*, *>.whileCondition(init: DoStatement.() -> Expression): Expression { return init(this@DoStatement) } @@ -707,7 +678,6 @@ fun LanguageFrontend<*, *>.whileCondition(init: DoStatement.() -> Expression): E * well as configuring the created node itself. */ context(IfStatement) - fun LanguageFrontend<*, *>.thenStmt(needsScope: Boolean = true, init: Block.() -> Unit): Block { val node = newBlock() scopeIfNecessary(needsScope, node, init) @@ -723,7 +693,6 @@ fun LanguageFrontend<*, *>.thenStmt(needsScope: Boolean = true, init: Block.() - * can be used to create further sub-nodes as well as configuring the created node itself. */ context(IfStatement) - fun LanguageFrontend<*, *>.elseIf(init: IfStatement.() -> Unit): IfStatement { val node = newIfStatement() init(node) @@ -741,7 +710,6 @@ fun LanguageFrontend<*, *>.elseIf(init: IfStatement.() -> Unit): IfStatement { * well as configuring the created node itself. */ context(WhileStatement) - fun LanguageFrontend<*, *>.loopBody(init: Block.() -> Unit): Block { val node = newBlock() init(node) @@ -756,7 +724,6 @@ fun LanguageFrontend<*, *>.loopBody(init: Block.() -> Unit): Block { * well as configuring the created node itself. */ context(DoStatement) - fun LanguageFrontend<*, *>.loopBody(init: Block.() -> Unit): Block { val node = newBlock() init(node) @@ -771,7 +738,6 @@ fun LanguageFrontend<*, *>.loopBody(init: Block.() -> Unit): Block { * sub-nodes as well as configuring the created node itself. */ context(ForEachStatement) - fun LanguageFrontend<*, *>.loopBody(init: Block.() -> Unit): Block { val node = newBlock() init(node) @@ -786,7 +752,6 @@ fun LanguageFrontend<*, *>.loopBody(init: Block.() -> Unit): Block { * as well as configuring the created node itself. */ context(SwitchStatement) - fun LanguageFrontend<*, *>.switchBody(init: Block.() -> Unit): Block { val node = newBlock() init(node) @@ -801,7 +766,6 @@ fun LanguageFrontend<*, *>.switchBody(init: Block.() -> Unit): Block { * well as configuring the created node itself. */ context(IfStatement) - fun LanguageFrontend<*, *>.elseStmt(needsScope: Boolean = true, init: Block.() -> Unit): Block { val node = newBlock() scopeIfNecessary(needsScope, node, init) @@ -816,7 +780,6 @@ fun LanguageFrontend<*, *>.elseStmt(needsScope: Boolean = true, init: Block.() - * of the nearest enclosing [Holder], but only if it is an [StatementHolder]. */ context(Holder) - fun LanguageFrontend<*, *>.label( label: String, init: (LabelStatement.() -> Statement)? = null @@ -841,7 +804,6 @@ fun LanguageFrontend<*, *>.label( * [StatementHolder.addStatement] of the nearest enclosing [StatementHolder]. */ context(StatementHolder) - fun LanguageFrontend<*, *>.continueStmt(label: String? = null): ContinueStatement { val node = newContinueStatement() node.label = label @@ -856,7 +818,6 @@ fun LanguageFrontend<*, *>.continueStmt(label: String? = null): ContinueStatemen * of the nearest enclosing [Holder], but only if it is an [StatementHolder]. */ context(Holder) - fun LanguageFrontend<*, *>.breakStmt(label: String? = null): BreakStatement { val node = newBreakStatement() node.label = label @@ -875,7 +836,6 @@ fun LanguageFrontend<*, *>.breakStmt(label: String? = null): BreakStatement { * of the nearest enclosing [Holder], but only if it is an [StatementHolder]. */ context(Holder) - fun LanguageFrontend<*, *>.case(caseExpression: Expression? = null): CaseStatement { val node = newCaseStatement() node.caseExpression = caseExpression @@ -894,7 +854,6 @@ fun LanguageFrontend<*, *>.case(caseExpression: Expression? = null): CaseStateme * [StatementHolder]. */ context(Holder) - fun LanguageFrontend<*, *>.default(): DefaultStatement { val node = newDefaultStatement() @@ -912,7 +871,6 @@ fun LanguageFrontend<*, *>.default(): DefaultStatement { * nearest enclosing [Holder], but only if it is an [ArgumentHolder]. */ context(Holder) - fun LanguageFrontend<*, *>.literal(value: N, type: Type = unknownType()): Literal { val node = newLiteral(value, type) @@ -931,7 +889,6 @@ fun LanguageFrontend<*, *>.literal(value: N, type: Type = unknownType()): Li * [ArgumentHolder]. */ context(Holder) - fun LanguageFrontend<*, *>.ile( targetType: Type = unknownType(), init: (InitializerListExpression.() -> Unit)? = null @@ -956,7 +913,6 @@ fun LanguageFrontend<*, *>.ile( * nearest enclosing [Holder], but only if it is an [ArgumentHolder]. */ context(Holder) - fun LanguageFrontend<*, *>.ref( name: CharSequence, type: Type = unknownType(), @@ -987,7 +943,6 @@ fun LanguageFrontend<*, *>.ref( * already contain a fqn, we add an implicit "this" as base. */ context(Holder) - fun LanguageFrontend<*, *>.member( name: CharSequence, base: Expression? = null, @@ -1023,7 +978,6 @@ fun LanguageFrontend<*, *>.member( * and invokes [ArgumentHolder.addArgument] of the nearest enclosing [ArgumentHolder]. */ context(LanguageFrontend<*, *>, ArgumentHolder) - operator fun Expression.times(rhs: Expression): BinaryOperator { val node = (this@LanguageFrontend).newBinaryOperator("*") node.lhs = this @@ -1045,7 +999,6 @@ operator fun Expression.times(rhs: Expression): BinaryOperator { * invokes [ArgumentHolder.addArgument] of the nearest enclosing [ArgumentHolder]. */ context(LanguageFrontend<*, *>, ArgumentHolder) - operator fun Expression.unaryMinus(): UnaryOperator { val node = (this@LanguageFrontend).newUnaryOperator("-", false, false) node.input = this @@ -1065,7 +1018,6 @@ operator fun Expression.unaryMinus(): UnaryOperator { * and invokes [ArgumentHolder.addArgument] of the nearest enclosing [ArgumentHolder]. */ context(LanguageFrontend<*, *>, ArgumentHolder) - operator fun Expression.div(rhs: Expression): BinaryOperator { val node = (this@LanguageFrontend).newBinaryOperator("/") node.lhs = this @@ -1087,7 +1039,6 @@ operator fun Expression.div(rhs: Expression): BinaryOperator { * and invokes [ArgumentHolder.addArgument] of the nearest enclosing [ArgumentHolder]. */ context(LanguageFrontend<*, *>, ArgumentHolder) - operator fun Expression.plus(rhs: Expression): BinaryOperator { val node = (this@LanguageFrontend).newBinaryOperator("+") node.lhs = this @@ -1109,7 +1060,6 @@ operator fun Expression.plus(rhs: Expression): BinaryOperator { * and invokes [StatementHolder.addStatement] of the nearest enclosing [StatementHolder]. */ context(LanguageFrontend<*, *>, StatementHolder) - operator fun Expression.plusAssign(rhs: Expression) { val node = (this@LanguageFrontend).newAssignExpression("+=", listOf(this), listOf(rhs)) @@ -1121,7 +1071,6 @@ operator fun Expression.plusAssign(rhs: Expression) { * and invokes [ArgumentHolder.addArgument] of the nearest enclosing [ArgumentHolder]. */ context(LanguageFrontend<*, *>, ArgumentHolder) - operator fun Expression.rem(rhs: Expression): BinaryOperator { val node = (this@LanguageFrontend).newBinaryOperator("%") node.lhs = this @@ -1143,7 +1092,6 @@ operator fun Expression.rem(rhs: Expression): BinaryOperator { * and invokes [ArgumentHolder.addArgument] of the nearest enclosing [ArgumentHolder]. */ context(LanguageFrontend<*, *>, ArgumentHolder) - operator fun Expression.minus(rhs: Expression): BinaryOperator { val node = (this@LanguageFrontend).newBinaryOperator("-") node.lhs = this @@ -1159,7 +1107,6 @@ operator fun Expression.minus(rhs: Expression): BinaryOperator { * invokes [ArgumentHolder.addArgument] of the nearest enclosing [ArgumentHolder]. */ context(LanguageFrontend<*, *>, ArgumentHolder) - fun reference(input: Expression): UnaryOperator { val node = (this@LanguageFrontend).newUnaryOperator("&", false, false) node.input = input @@ -1174,7 +1121,6 @@ fun reference(input: Expression): UnaryOperator { * invokes [StatementHolder.addStatement] of the nearest enclosing [StatementHolder]. */ context(LanguageFrontend<*, *>, Holder) - operator fun Expression.dec(): UnaryOperator { val node = (this@LanguageFrontend).newUnaryOperator("--", true, false) node.input = this @@ -1191,7 +1137,6 @@ operator fun Expression.dec(): UnaryOperator { * invokes [ArgumentHolder.addArgument] of the nearest enclosing [ArgumentHolder]. */ context(LanguageFrontend<*, *>, Holder) - operator fun Expression.inc(): UnaryOperator { val node = (this@LanguageFrontend).newUnaryOperator("++", true, false) node.input = this @@ -1208,7 +1153,6 @@ operator fun Expression.inc(): UnaryOperator { * invokes [ArgumentHolder.addArgument] of the nearest enclosing [ArgumentHolder]. */ context(LanguageFrontend<*, *>) - fun Expression.incNoContext(): UnaryOperator { val node = (this@LanguageFrontend).newUnaryOperator("++", true, false) node.input = this @@ -1221,7 +1165,6 @@ fun Expression.incNoContext(): UnaryOperator { * and invokes [ArgumentHolder.addArgument] of the nearest enclosing [ArgumentHolder]. */ context(LanguageFrontend<*, *>, ArgumentHolder) - infix fun Expression.eq(rhs: Expression): BinaryOperator { val node = (this@LanguageFrontend).newBinaryOperator("==") node.lhs = this @@ -1237,7 +1180,6 @@ infix fun Expression.eq(rhs: Expression): BinaryOperator { * and invokes [ArgumentHolder.addArgument] of the nearest enclosing [ArgumentHolder]. */ context(LanguageFrontend<*, *>, ArgumentHolder) - infix fun Expression.gt(rhs: Expression): BinaryOperator { val node = (this@LanguageFrontend).newBinaryOperator(">") node.lhs = this @@ -1253,7 +1195,6 @@ infix fun Expression.gt(rhs: Expression): BinaryOperator { * and invokes [ArgumentHolder.addArgument] of the nearest enclosing [ArgumentHolder]. */ context(LanguageFrontend<*, *>, ArgumentHolder) - infix fun Expression.ge(rhs: Expression): BinaryOperator { val node = (this@LanguageFrontend).newBinaryOperator(">=") node.lhs = this @@ -1269,7 +1210,6 @@ infix fun Expression.ge(rhs: Expression): BinaryOperator { * and invokes [ArgumentHolder.addArgument] of the nearest enclosing [ArgumentHolder]. */ context(LanguageFrontend<*, *>, Holder) - infix fun Expression.lt(rhs: Expression): BinaryOperator { val node = (this@LanguageFrontend).newBinaryOperator("<") node.lhs = this @@ -1283,7 +1223,6 @@ infix fun Expression.lt(rhs: Expression): BinaryOperator { } context(LanguageFrontend<*, *>) - infix fun Expression.lt(rhs: Expression): BinaryOperator { val node = (this@LanguageFrontend).newBinaryOperator("<") node.lhs = this @@ -1297,7 +1236,6 @@ infix fun Expression.lt(rhs: Expression): BinaryOperator { * and invokes [ArgumentHolder.addArgument] of the nearest enclosing [ArgumentHolder]. */ context(LanguageFrontend<*, *>, ArgumentHolder) - infix fun Expression.le(rhs: Expression): BinaryOperator { val node = (this@LanguageFrontend).newBinaryOperator("<=") node.lhs = this @@ -1309,7 +1247,6 @@ infix fun Expression.le(rhs: Expression): BinaryOperator { } context(LanguageFrontend<*, *>) - infix fun Expression.le(rhs: Expression): BinaryOperator { val node = (this@LanguageFrontend).newBinaryOperator("<=") node.lhs = this @@ -1323,7 +1260,6 @@ infix fun Expression.le(rhs: Expression): BinaryOperator { * DSL and invokes [StatementHolder.addStatement] of the nearest enclosing [StatementHolder]. */ context(LanguageFrontend<*, *>, Holder) - fun Expression.conditional( condition: Expression, thenExpression: Expression, @@ -1346,7 +1282,6 @@ fun Expression.conditional( * and invokes [StatementHolder.addStatement] of the nearest enclosing [StatementHolder]. */ context(LanguageFrontend<*, *>, StatementHolder) - infix fun Expression.assign(init: AssignExpression.() -> Expression): AssignExpression { val node = (this@LanguageFrontend).newAssignExpression("=") node.lhs = listOf(this) @@ -1363,7 +1298,6 @@ infix fun Expression.assign(init: AssignExpression.() -> Expression): AssignExpr * DSL and invokes [StatementHolder.addStatement] of the nearest enclosing [StatementHolder]. */ context(LanguageFrontend<*, *>, Holder) - infix fun Expression.assign(rhs: Expression): AssignExpression { val node = (this@LanguageFrontend).newAssignExpression("=", listOf(this), listOf(rhs)) @@ -1379,7 +1313,6 @@ infix fun Expression.assign(rhs: Expression): AssignExpression { * DSL and invokes [StatementHolder.addStatement] of the nearest enclosing [StatementHolder]. */ context(LanguageFrontend<*, *>, Holder) - infix fun Expression.assignPlus(rhs: Expression): AssignExpression { val node = (this@LanguageFrontend).newAssignExpression("+=", listOf(this), listOf(rhs)) @@ -1395,7 +1328,6 @@ infix fun Expression.assignPlus(rhs: Expression): AssignExpression { * DSL and invokes [StatementHolder.addStatement] of the nearest enclosing [StatementHolder]. */ context(LanguageFrontend<*, *>, Holder) - infix fun Expression.assignAsExpr(rhs: Expression): AssignExpression { val node = (this@LanguageFrontend).newAssignExpression("=", listOf(this), listOf(rhs)) @@ -1408,7 +1340,6 @@ infix fun Expression.assignAsExpr(rhs: Expression): AssignExpression { * DSL and invokes [StatementHolder.addStatement] of the nearest enclosing [StatementHolder]. */ context(LanguageFrontend<*, *>, Holder) - infix fun Expression.assignAsExpr(rhs: AssignExpression.() -> Unit): AssignExpression { val node = (this@LanguageFrontend).newAssignExpression("=", listOf(this)) rhs(node) @@ -1444,7 +1375,6 @@ private fun LanguageFrontend<*, *>.scopeIfNecessary( } context(MethodDeclaration) - fun LanguageFrontend<*, *>.receiver(name: String, type: Type): VariableDeclaration { val node = newVariableDeclaration(name, type) diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/helpers/SubgraphWalker.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/helpers/SubgraphWalker.kt index 3aea89d0da..4ea525e6b9 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/helpers/SubgraphWalker.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/helpers/SubgraphWalker.kt @@ -152,8 +152,7 @@ object SubgraphWalker { // restore old state field.isAccessible = false obj - } - ?: continue + } ?: continue // skip, if null var outgoing = true // default diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/CXXCallResolverHelper.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/CXXCallResolverHelper.kt index 667b8be101..bd52e83c99 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/CXXCallResolverHelper.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/CXXCallResolverHelper.kt @@ -412,8 +412,7 @@ fun getTemplateInitializationSignature( instantiationType, orderedInitializationSignature, explicitInstantiated - ) - ?: return null + ) ?: return null val parameterizedTypeResolution = getParameterizedSignaturesFromInitialization(signature) // Check for unresolved Parameters and try to deduce Type by looking at call arguments diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/ControlDependenceGraphPass.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/ControlDependenceGraphPass.kt index 0fe72d7cef..6a69f5ffe8 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/ControlDependenceGraphPass.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/ControlDependenceGraphPass.kt @@ -123,8 +123,7 @@ open class ControlDependenceGraphPass(ctx: TranslationContext) : EOGStarterPass( dominatorsList.remove(entry) val update = entry.second.addAll(newV) if (update) dominatorsList.add(entry) else finalDominators.add(entry) - } - ?: dominatorsList.add(Pair(newK, newV.toMutableSet())) + } ?: dominatorsList.add(Pair(newK, newV.toMutableSet())) } } } @@ -199,8 +198,8 @@ open class ControlDependenceGraphPass(ctx: TranslationContext) : EOGStarterPass( properties[Properties.BRANCH] = branchesSet } k is IfStatement && - (branchingNodeConditionals[k]?.size - ?: 0) > 1 -> { // Note: branchesSet must be empty here + (branchingNodeConditionals[k]?.size ?: 0) > + 1 -> { // Note: branchesSet must be empty here // The if statement has only a then branch but there's a way to "jump // out" of this branch. In this case, we want to set the false property // here. diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/ProgramDependenceGraphPass.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/ProgramDependenceGraphPass.kt index 88b103c03a..e9dd97d7d4 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/ProgramDependenceGraphPass.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/ProgramDependenceGraphPass.kt @@ -67,8 +67,7 @@ class ProgramDependenceGraphPass(ctx: TranslationContext) : TranslationUnitPass( (it as? BranchingNode)?.branchedBy?.allChildren { c -> c in prevDfgNode.nextDFG - } - ?: listOf() + } ?: listOf() } if ( cdgConditionChildren.isNotEmpty() && diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/SymbolResolver.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/SymbolResolver.kt index 86f8703d45..26bb321345 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/SymbolResolver.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/SymbolResolver.kt @@ -761,8 +761,7 @@ open class SymbolResolver(ctx: TranslationContext) : ComponentPass(ctx) { // Filter the value declarations for an appropriate method scope?.valueDeclarations?.filterIsInstance()?.filter { it.name.lastPartsMatch(name) && it.hasSignature(call) - } - ?: listOf() + } ?: listOf() } } diff --git a/cpg-language-cxx/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/cxx/CXXLanguageFrontend.kt b/cpg-language-cxx/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/cxx/CXXLanguageFrontend.kt index c3775b6c50..6fee78c81d 100644 --- a/cpg-language-cxx/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/cxx/CXXLanguageFrontend.kt +++ b/cpg-language-cxx/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/cxx/CXXLanguageFrontend.kt @@ -115,7 +115,7 @@ open class CXXLanguageFrontend(language: Language, ctx: Tra // check, if the white-list exists at all if ( hasIncludeWhitelist() && // and ignore the file if it is not on the whitelist - !absoluteOrRelativePathIsInList(Path.of(path), config.includeWhitelist) + !absoluteOrRelativePathIsInList(Path.of(path), config.includeWhitelist) ) { LOGGER.debug("Include file {} not on the whitelist. Ignoring.", path) return null diff --git a/cpg-language-cxx/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/cxx/DeclarationHandler.kt b/cpg-language-cxx/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/cxx/DeclarationHandler.kt index 4ecc8bbdfd..1d3d232dac 100644 --- a/cpg-language-cxx/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/cxx/DeclarationHandler.kt +++ b/cpg-language-cxx/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/cxx/DeclarationHandler.kt @@ -160,8 +160,7 @@ class DeclarationHandler(lang: CXXLanguageFrontend) : var candidates = (holder as? DeclarationHolder) ?.declarations - ?.filterIsInstance() - ?: listOf() + ?.filterIsInstance() ?: listOf() // Look for the method or constructor candidates = @@ -233,8 +232,7 @@ class DeclarationHandler(lang: CXXLanguageFrontend) : !it.isDefinition && it.name.lastPartsMatch(declaration.name) && it.hasSignature(declaration.signatureTypes) - } - ?: listOf() + } ?: listOf() for (candidate in declarationCandidates) { candidate.definition = declaration // Do some additional magic with default parameters, which I do not really understand diff --git a/cpg-language-cxx/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/cxx/ExpressionHandler.kt b/cpg-language-cxx/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/cxx/ExpressionHandler.kt index bae02d04a9..15d82d6389 100644 --- a/cpg-language-cxx/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/cxx/ExpressionHandler.kt +++ b/cpg-language-cxx/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/cxx/ExpressionHandler.kt @@ -67,7 +67,8 @@ class ExpressionHandler(lang: CXXLanguageFrontend) : is IASTFunctionCallExpression -> handleFunctionCallExpression(node) is IASTCastExpression -> handleCastExpression(node) is IASTExpressionList -> handleExpressionList(node) - is IASTInitializerList -> frontend.initializerHandler.handle(node) + is IASTInitializerList -> + frontend.initializerHandler.handle(node) ?: ProblemExpression("could not parse initializer list") is IASTArraySubscriptExpression -> handleArraySubscriptExpression(node) is IASTTypeIdExpression -> handleTypeIdExpression(node) @@ -504,8 +505,7 @@ class ExpressionHandler(lang: CXXLanguageFrontend) : handle(ctx.operand2) } else { handle(ctx.initOperand2) - } - ?: newProblemExpression("could not parse rhs") + } ?: newProblemExpression("could not parse rhs") if ( lhs is CastExpression && @@ -535,8 +535,7 @@ class ExpressionHandler(lang: CXXLanguageFrontend) : handle(ctx.operand2) } else { handle(ctx.initOperand2) - } - ?: newProblemExpression("missing RHS") + } ?: newProblemExpression("missing RHS") val operatorCode = String(ASTStringUtil.getBinaryOperatorString(ctx)) val assign = newAssignExpression(operatorCode, listOf(lhs), listOf(rhs), rawNode = ctx) diff --git a/cpg-language-go/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/golang/GoUtils.kt b/cpg-language-go/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/golang/GoUtils.kt index 15225a7a04..3ad9b58e94 100644 --- a/cpg-language-go/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/golang/GoUtils.kt +++ b/cpg-language-go/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/golang/GoUtils.kt @@ -80,8 +80,7 @@ internal fun shouldBeBuild(file: File, symbols: Map): Boolean { file .bufferedReader() .useLines { lines -> lines.take(50).toList() } - .firstOrNull { it.startsWith("//go:build") } - ?: return true + .firstOrNull { it.startsWith("//go:build") } ?: return true val constraint = BuildConstraintExpression.fromString(goBuildLine.substringAfter("//go:build ")) diff --git a/cpg-language-java/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/java/DeclarationHandler.kt b/cpg-language-java/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/java/DeclarationHandler.kt index fb1d4127b8..9485e75a1e 100644 --- a/cpg-language-java/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/java/DeclarationHandler.kt +++ b/cpg-language-java/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/java/DeclarationHandler.kt @@ -322,8 +322,7 @@ open class DeclarationHandler(lang: JavaLanguageFrontend) : frontend.typeManager.getTypeParameter( frontend.scopeManager.currentRecord, variable.resolve().type.describe() - ) - ?: frontend.typeOf(variable.resolve().type) + ) ?: frontend.typeOf(variable.resolve().type) } catch (e: UnsolvedSymbolException) { val t = frontend.recoverTypeFromUnsolvedException(e) if (t == null) { 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 df852c9aae..ac726a9ede 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 @@ -823,8 +823,7 @@ class ExpressionHandler(lang: JavaLanguageFrontend) : for (i in arguments.indices) { val argument = handle(arguments[i]) - as? de.fraunhofer.aisec.cpg.graph.statements.expressions.Expression - ?: continue + as? de.fraunhofer.aisec.cpg.graph.statements.expressions.Expression ?: continue argument.argumentIndex = i ctor.addArgument(argument) } diff --git a/cpg-language-llvm/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/llvm/ExpressionHandler.kt b/cpg-language-llvm/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/llvm/ExpressionHandler.kt index dc8c7e2fce..194c5cda29 100644 --- a/cpg-language-llvm/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/llvm/ExpressionHandler.kt +++ b/cpg-language-llvm/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/llvm/ExpressionHandler.kt @@ -252,7 +252,8 @@ class ExpressionHandler(lang: LLVMIRLanguageFrontend) : ProblemNode.ProblemType.TRANSLATION, rawNode = value ) - LLVMICmp -> frontend.statementHandler.handleIntegerComparison(value) as? Expression + LLVMICmp -> + frontend.statementHandler.handleIntegerComparison(value) as? Expression ?: newProblemExpression( "Wrong type of constant comparison", ProblemNode.ProblemType.TRANSLATION, diff --git a/cpg-language-python/src/test/kotlin/de/fraunhofer/aisec/cpg/frontends/python/PythonFrontendTest.kt b/cpg-language-python/src/test/kotlin/de/fraunhofer/aisec/cpg/frontends/python/PythonFrontendTest.kt index a0e9c238f2..c9ad376d43 100644 --- a/cpg-language-python/src/test/kotlin/de/fraunhofer/aisec/cpg/frontends/python/PythonFrontendTest.kt +++ b/cpg-language-python/src/test/kotlin/de/fraunhofer/aisec/cpg/frontends/python/PythonFrontendTest.kt @@ -1039,8 +1039,7 @@ class PythonFrontendTest : BaseTest() { val varDefinedBeforeLoopRef = (functionBody.statements.firstOrNull() as? AssignExpression)?.lhs?.firstOrNull() - as? Reference - ?: TODO() + as? Reference ?: TODO() // no dataflow from var declaration to loop variable because it's a write access assert((firstLoop.variable?.prevDFG?.contains(varDefinedBeforeLoopRef) == false)) diff --git a/cpg-language-typescript/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/typescript/ExpressionHandler.kt b/cpg-language-typescript/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/typescript/ExpressionHandler.kt index d0e6543fb2..54adeb603d 100644 --- a/cpg-language-typescript/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/typescript/ExpressionHandler.kt +++ b/cpg-language-typescript/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/typescript/ExpressionHandler.kt @@ -160,8 +160,7 @@ class ExpressionHandler(lang: TypeScriptLanguageFrontend) : ?.trim() ?.replace("\"", "") ?.replace("`", "") - ?.replace("'", "") - ?: "" + ?.replace("'", "") ?: "" return newLiteral(value, primitiveType("string"), rawNode = node) } diff --git a/cpg-neo4j/src/main/kotlin/de/fraunhofer/aisec/cpg_vis_neo4j/Application.kt b/cpg-neo4j/src/main/kotlin/de/fraunhofer/aisec/cpg_vis_neo4j/Application.kt index e1774c3ff5..dfeefaaf28 100644 --- a/cpg-neo4j/src/main/kotlin/de/fraunhofer/aisec/cpg_vis_neo4j/Application.kt +++ b/cpg-neo4j/src/main/kotlin/de/fraunhofer/aisec/cpg_vis_neo4j/Application.kt @@ -314,8 +314,7 @@ class Application : Callable { node.labels.toSet(), node.propertyList.associate { prop -> prop.key to prop.value } ) - } - ?: emptyList() + } ?: emptyList() val edges = newRelationshipBuilders // For some reason, there are edges without start or end node?? @@ -329,8 +328,7 @@ class Application : Callable { edge.endNode, edge.propertyList.associate { prop -> prop.key to prop.value } ) - } - ?: emptyList() + } ?: emptyList() return JsonGraph(nodes, edges) } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index d05f6caf59..55b54c429c 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -3,7 +3,7 @@ kotlin = "1.9.0" neo4j = "4.0.6" log4j = "2.22.0" sonarqube = "4.4.1.3373" -spotless = "6.23.2" +spotless = "6.25.0" nexus-publish = "1.3.0" [libraries] From 3dd242a865150123e2e4e08c0b7f009ab96ada76 Mon Sep 17 00:00:00 2001 From: KuechA <31155350+KuechA@users.noreply.github.com> Date: Tue, 30 Jan 2024 21:41:23 +0100 Subject: [PATCH 2/2] Synchronize adding TUs (#1423) --- .../kotlin/de/fraunhofer/aisec/cpg/TranslationManager.kt | 2 +- .../main/kotlin/de/fraunhofer/aisec/cpg/TranslationResult.kt | 2 +- .../main/kotlin/de/fraunhofer/aisec/cpg/graph/Component.kt | 5 +++++ .../aisec/cpg/frontends/cxx/CXXCompilationDatabaseTest.kt | 3 +-- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/TranslationManager.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/TranslationManager.kt index 49080ca4a5..74b727b546 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/TranslationManager.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/TranslationManager.kt @@ -350,7 +350,7 @@ private constructor( } return null } - component.translationUnits.add(frontend.parse(sourceLocation)) + component.addTranslationUnit(frontend.parse(sourceLocation)) } catch (ex: TranslationException) { log.error("An error occurred during parsing of ${sourceLocation.name}: ${ex.message}") if (config.failOnError) { diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/TranslationResult.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/TranslationResult.kt index 6df9a10a84..fcb04609e5 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/TranslationResult.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/TranslationResult.kt @@ -132,7 +132,7 @@ class TranslationResult( components.add(swc) } } - tu?.let { swc.translationUnits.add(it) } + tu?.let { swc.addTranslationUnit(it) } } /** diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/Component.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/Component.kt index 9eb6d7ad04..3a8e368bd9 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/Component.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/graph/Component.kt @@ -38,6 +38,11 @@ open class Component : Node() { /** All translation units belonging to this application. */ @AST val translationUnits: MutableList = mutableListOf() + @Synchronized + fun addTranslationUnit(tu: TranslationUnitDeclaration) { + translationUnits.add(tu) + } + /** * All points where unknown data may enter this application, e.g., the main method, or other * targets such as listeners to external events such as HTTP requests. This also includes the diff --git a/cpg-language-cxx/src/test/kotlin/de/fraunhofer/aisec/cpg/frontends/cxx/CXXCompilationDatabaseTest.kt b/cpg-language-cxx/src/test/kotlin/de/fraunhofer/aisec/cpg/frontends/cxx/CXXCompilationDatabaseTest.kt index 9017245de9..aa9439518b 100644 --- a/cpg-language-cxx/src/test/kotlin/de/fraunhofer/aisec/cpg/frontends/cxx/CXXCompilationDatabaseTest.kt +++ b/cpg-language-cxx/src/test/kotlin/de/fraunhofer/aisec/cpg/frontends/cxx/CXXCompilationDatabaseTest.kt @@ -130,8 +130,7 @@ class CXXCompilationDatabaseTest { assertEquals(2, tus.size) val ref = mapOf("main_tu_1.c" to 1, "main_tu_2.c" to 2) - for (i in tus.indices) { - val tu = tus[i] + for (tu in tus) { val value = ref[File(tu.name.toString()).name] val mainFunc = tu.byNameOrNull("main") assertNotNull(mainFunc)