diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexTreeBuilder.kt b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexTreeBuilder.kt index c48f2ad0cd..5c9728c01c 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexTreeBuilder.kt +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexTreeBuilder.kt @@ -76,10 +76,9 @@ import com.google.summit.ast.statement.WhileLoopStatement import kotlin.reflect.KClass -@Suppress("DEPRECATION") -class ApexTreeBuilder(val task: ParserTask, val proc: ApexLanguageProcessor) { - private val sourceCode = task.getTextDocument() - private val commentBuilder = ApexCommentBuilder(sourceCode, proc.getProperties().getSuppressMarker()) +class ApexTreeBuilder(private val task: ParserTask, private val proc: ApexLanguageProcessor) { + private val sourceCode = task.textDocument + private val commentBuilder = ApexCommentBuilder(sourceCode, proc.properties.suppressMarker) /** Builds and returns an [ASTApexFile] corresponding to the given [CompilationUnit]. */ fun buildTree(compilationUnit: CompilationUnit): ASTApexFile { @@ -87,7 +86,7 @@ class ApexTreeBuilder(val task: ParserTask, val proc: ApexLanguageProcessor) { val baseClass = build(compilationUnit, parent = null) as? BaseApexClass<*> ?: throw ParseException("Unable to build tree") - val result = ASTApexFile(task, compilationUnit, commentBuilder.getSuppressMap(), proc) + val result = ASTApexFile(task, compilationUnit, commentBuilder.suppressMap, proc) baseClass.setParent(result) // Post-processing passes @@ -759,8 +758,8 @@ class ApexTreeBuilder(val task: ParserTask, val proc: ApexLanguageProcessor) { } } - for(i in 0..node.getNumChildren()-1) { - node.setChild(children.get(i) as AbstractApexNode, i) + for(i in 0 until node.getNumChildren()) { + node.setChild(children[i] as AbstractApexNode, i) } } @@ -794,12 +793,10 @@ class ApexTreeBuilder(val task: ParserTask, val proc: ApexLanguageProcessor) { } /** - * If [parent] is not null, adds this [ApexNode] as a [child][ApexNode.jjtAddChild] and sets - * [parent] as the [parent][ApexNode.jjtSetParent]. + * If [parent] is not null, adds this [ApexNode] as a [child][AbstractApexNode.addChild] and sets + * [parent] as the [parent][AbstractApexNode.setParent]. */ private fun AbstractApexNode.setParent(parent: AbstractApexNode?) { - if (parent != null) { - parent.addChild(this, parent.numChildren) - } + parent?.addChild(this, parent.numChildren) } } diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ASTCastExpressionTest.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ASTCastExpressionTest.kt index ed3cb48cea..acb334402a 100644 --- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ASTCastExpressionTest.kt +++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ASTCastExpressionTest.kt @@ -7,7 +7,6 @@ package net.sourceforge.pmd.lang.java.ast import net.sourceforge.pmd.lang.ast.test.shouldBe import net.sourceforge.pmd.lang.java.ast.JavaVersion.Companion.Earliest import net.sourceforge.pmd.lang.java.ast.JavaVersion.Companion.Latest -import net.sourceforge.pmd.lang.java.ast.ExpressionParsingCtx import net.sourceforge.pmd.lang.java.types.JPrimitiveType.PrimitiveTypeKind.* class ASTCastExpressionTest : ParserTestSpec({ diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ASTFieldAccessTest.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ASTFieldAccessTest.kt index b259b9c1bc..8be8683fdd 100644 --- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ASTFieldAccessTest.kt +++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ASTFieldAccessTest.kt @@ -4,7 +4,6 @@ package net.sourceforge.pmd.lang.java.ast -import io.kotest.matchers.shouldBe import net.sourceforge.pmd.lang.ast.test.shouldBe /** @@ -12,7 +11,7 @@ import net.sourceforge.pmd.lang.ast.test.shouldBe */ class ASTFieldAccessTest : ParserTestSpec({ - parserTest("Field access exprs") { + parserTest("Field access expressions") { inContext(ExpressionParsingCtx) { diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ASTMethodCallTest.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ASTMethodCallTest.kt index e22d343589..5fe7339255 100644 --- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ASTMethodCallTest.kt +++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ASTMethodCallTest.kt @@ -13,7 +13,7 @@ import net.sourceforge.pmd.lang.ast.test.shouldBe class ASTMethodCallTest : ParserTestSpec({ - parserTest("Method call exprs") { + parserTest("Method call expressions") { inContext(ExpressionParsingCtx) { diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ASTMethodDeclarationTest.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ASTMethodDeclarationTest.kt index ff47a82431..0f621ebb93 100644 --- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ASTMethodDeclarationTest.kt +++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ASTMethodDeclarationTest.kt @@ -138,7 +138,7 @@ class ASTMethodDeclarationTest : ParserTestSpec({ } } - // default abstract is an invalid combination of modifiers so we won't encounter it in real analysis + // default abstract is an invalid combination of modifiers, so we won't encounter it in real analysis } parserTest("Throws list") { diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ASTPatternTest.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ASTPatternTest.kt index 80549663cd..b9ba5114a4 100644 --- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ASTPatternTest.kt +++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ASTPatternTest.kt @@ -5,7 +5,6 @@ package net.sourceforge.pmd.lang.java.ast import io.kotest.matchers.shouldBe -import io.kotest.matchers.shouldNot import net.sourceforge.pmd.lang.java.ast.JavaVersion.J16 import java.io.IOException diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ASTSuperExpressionTest.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ASTSuperExpressionTest.kt index bd2bd9096f..067756e2fe 100644 --- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ASTSuperExpressionTest.kt +++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ASTSuperExpressionTest.kt @@ -31,7 +31,7 @@ class ASTSuperExpressionTest : ParserTestSpec({ // a method call, field access, or method reference "super" shouldNot parse() - // type arguments and annots are disallowed on the qualifier + // type arguments and annotations are disallowed on the qualifier "T.B.super::foo" shouldNot parse() "T.B.super.foo()" shouldNot parse() "T.@F B.super.foo()" shouldNot parse() diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ASTThisExpressionTest.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ASTThisExpressionTest.kt index dc49ff18d4..f3e0b7209a 100644 --- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ASTThisExpressionTest.kt +++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ASTThisExpressionTest.kt @@ -47,7 +47,7 @@ class ASTThisExpressionTest : ParserTestSpec({ parserTest("Neg cases") { inContext(ExpressionParsingCtx) { - // type arguments and annots are disallowed on the qualifier + // type arguments and annotations are disallowed on the qualifier "T.B.this" shouldNot parse() "T.@F B.this" shouldNot parse() } diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ASTTypeTest.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ASTTypeTest.kt index bee2963f29..2f85f2ceaf 100644 --- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ASTTypeTest.kt +++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ASTTypeTest.kt @@ -59,9 +59,9 @@ class ASTTypeTest : ParserTestSpec({ // So @B binds to "java" // If the annotation is not applicable to TYPE_USE then it doesn't compile - // this happens in type context, eg in a cast, or in an extends list + // this happens in type context, e.g. in a cast, or in an extends list - // TYPE_USE annotations are prohibited eg before a declaration + // TYPE_USE annotations are prohibited e.g. before a declaration inContext(TypeParsingCtx) { diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ASTUnaryExpressionTest.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ASTUnaryExpressionTest.kt index fd2bb913fc..d13cb2483c 100644 --- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ASTUnaryExpressionTest.kt +++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ASTUnaryExpressionTest.kt @@ -84,7 +84,7 @@ class ASTUnaryExpressionTest : ParserTestSpec({ parserTest("Unary expression ambiguity corner cases") { - // the following cases test ambiguity between cast of unary, and eg parenthesized additive expr + // the following cases test ambiguity between cast of unary, and e.g. parenthesized additive expr // see https://docs.oracle.com/javase/specs/jls/se9/html/jls-15.html#jls-UnaryExpressionNotPlusMinus // comments about ambiguity are below grammar diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/Java11Test.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/Java11Test.kt index 8a0e225520..5626dba682 100644 --- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/Java11Test.kt +++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/Java11Test.kt @@ -4,9 +4,7 @@ package net.sourceforge.pmd.lang.java.ast -import io.kotest.matchers.shouldBe import net.sourceforge.pmd.lang.ast.test.shouldBe -import net.sourceforge.pmd.lang.java.ast.* import net.sourceforge.pmd.lang.java.ast.JavaVersion.* import net.sourceforge.pmd.lang.java.ast.JavaVersion.Companion.Latest diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/KotlinTestingDsl.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/KotlinTestingDsl.kt index 791df7c2a3..aa4260bdc3 100644 --- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/KotlinTestingDsl.kt +++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/KotlinTestingDsl.kt @@ -14,7 +14,6 @@ import io.kotest.matchers.MatcherResult import io.kotest.matchers.collections.shouldContainAll import net.sourceforge.pmd.lang.ast.* import net.sourceforge.pmd.lang.ast.test.* -import net.sourceforge.pmd.lang.java.JavaLanguageModule import net.sourceforge.pmd.lang.java.JavaParsingHelper import net.sourceforge.pmd.lang.java.JavaParsingHelper.* import java.beans.PropertyDescriptor @@ -40,8 +39,6 @@ enum class JavaVersion : Comparable { /** Name suitable for use with e.g. [JavaParsingHelper.parse] */ val pmdName: String = name.removePrefix("J").replaceFirst("__", "-").replace('_', '.').lowercase() - val pmdVersion get() = JavaLanguageModule.getInstance().getVersion(pmdName) - val parser: JavaParsingHelper = DEFAULT.withDefaultVersion(pmdName) operator fun not(): List = values().toList() - this @@ -64,9 +61,9 @@ enum class JavaVersion : Comparable { fun since(v: JavaVersion) = v.rangeTo(Latest) fun except(v1: JavaVersion, vararg versions: JavaVersion) = - values().toList() - v1 - versions + values().toList() - v1 - versions.toSet() - fun except(versions: List) = values().toList() - versions + fun except(versions: List) = values().toList() - versions.toSet() } } @@ -151,8 +148,8 @@ inline fun JavaNode?.shouldMatchNode(ignoreChildren: Boolean * Can be used inside of a [ParserTestSpec] with [ParserTestSpec.parserTest]. * * Parsing contexts allow to parse a string containing only the node you're interested - * in instead of writing up a full class that the parser can handle. See [parseExpression], - * [parseStatement]. + * in instead of writing up a full class that the parser can handle. See [ExpressionParsingCtx], + * [StatementParsingCtx]. * * These are implicitly used by [matchExpr] and [matchStmt], which specify a matcher directly * on the strings, using their type parameter and the info in this test context to parse, find @@ -169,7 +166,7 @@ inline fun JavaNode?.shouldMatchNode(ignoreChildren: Boolean * Import statements in the parsing contexts can be configured by adding types to [importedTypes], * or strings to [otherImports]. * - * Technically the utilities provided by this class may be used outside of [io.kotest.specs.FunSpec]s, + * Technically the utilities provided by this class may be used outside of [io.kotest.core.spec.Spec]s, * e.g. in regular JUnit tests, but I think we should strive to uniformize our testing style, * especially since KotlinTest defines so many. * @@ -224,7 +221,7 @@ open class ParserTestCtx(testScope: TestScope, /** * Places all node parsing contexts inside the declaration of the given class * of the given class. - * It's like you were writing eg expressions inside the class, with the method + * It's like you were writing e.g. expressions inside the class, with the method * declarations around it and all. * * LIMITATIONS: diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/NodeParsingCtx.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/NodeParsingCtx.kt index 2bf63f7669..cecc164d17 100644 --- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/NodeParsingCtx.kt +++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/NodeParsingCtx.kt @@ -5,6 +5,7 @@ package net.sourceforge.pmd.lang.java.ast import net.sourceforge.pmd.lang.ast.Node +import net.sourceforge.pmd.lang.ast.ParseException import net.sourceforge.pmd.lang.java.JavaParsingHelper /** @@ -139,7 +140,7 @@ $construct } override fun retrieveNode(acu: ASTCompilationUnit): ASTBodyDeclaration = - acu.typeDeclarations.firstOrThrow().getDeclarations().firstOrThrow() + acu.typeDeclarations.firstOrThrow().declarations.firstOrThrow() } object TopLevelTypeDeclarationParsingCtx : NodeParsingCtx("top-level declaration") { diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ParenthesesTest.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ParenthesesTest.kt index d5a59df21a..12efd016a2 100644 --- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ParenthesesTest.kt +++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/ParenthesesTest.kt @@ -73,7 +73,7 @@ class ParenthesesTest : ParserTestSpec({ it::getParenthesisDepth shouldBe 2 it::isParenthesized shouldBe true - it.tokenList().map { it.image } shouldBe listOf("(", "(", "a", ")", ")") + it.tokenList().map { token -> token.image } shouldBe listOf("(", "(", "a", ")", ")") } } } @@ -95,7 +95,7 @@ class ParenthesesTest : ParserTestSpec({ it::getParenthesisDepth shouldBe 1 it::isParenthesized shouldBe true - it.tokenList().map { it.image } shouldBe listOf("(", "a", ")") + it.tokenList().map { token -> token.image } shouldBe listOf("(", "a", ")") } } } diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/TestExtensions.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/TestExtensions.kt index 1759e7c91b..de4ae950d9 100644 --- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/TestExtensions.kt +++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/TestExtensions.kt @@ -256,8 +256,8 @@ fun TreeNodeWrapper.returnStatement(contents: ValuedNodeSpec.forLoop(body: ValuedNodeSpec = { null }) = child { - val body = body() - if (body != null) it::getBody shouldBe body + val expectedBody = body() + if (expectedBody != null) it::getBody shouldBe expectedBody else unspecifiedChildren(it.numChildren) } @@ -280,22 +280,22 @@ fun TreeNodeWrapper.statementExprList(body: NodeSpec.foreachLoop(body: ValuedNodeSpec = { null }) = child { - val body = body() - if (body != null) it::getBody shouldBe body + val expectedBody = body() + if (expectedBody != null) it::getBody shouldBe expectedBody else unspecifiedChildren(it.numChildren) } fun TreeNodeWrapper.doLoop(body: ValuedNodeSpec = { null }) = child { - val body = body() - if (body != null) it::getBody shouldBe body + val expectedBody = body() + if (expectedBody != null) it::getBody shouldBe expectedBody else unspecifiedChildren(it.numChildren) } fun TreeNodeWrapper.whileLoop(body: ValuedNodeSpec = { null }) = child { - val body = body() - if (body != null) it::getBody shouldBe body + val expectedBody = body() + if (expectedBody != null) it::getBody shouldBe expectedBody else unspecifiedChildren(it.numChildren) } @@ -398,7 +398,7 @@ fun TreeNodeWrapper.unionType(contents: NodeSpec = EmptyA contents() } -fun TreeNodeWrapper.voidType() = child() {} +fun TreeNodeWrapper.voidType() = child {} fun TreeNodeWrapper.typeExpr(contents: ValuedNodeSpec) = @@ -425,7 +425,7 @@ fun TreeNodeWrapper.arrayType(contents: NodeSpec = EmptyA fun TreeNodeWrapper.primitiveType(type: PrimitiveTypeKind, assertions: NodeSpec = EmptyAssertions) = child { it::getKind shouldBe type - PrettyPrintingUtil.prettyPrintType(it) shouldBe type.toString(); + PrettyPrintingUtil.prettyPrintType(it) shouldBe type.toString() assertions() } @@ -586,8 +586,8 @@ fun TreeNodeWrapper.switchStmt(assertions: NodeSpec fun TreeNodeWrapper.switchArrow(rhs: ValuedNodeSpec = { null }) = child { - val rhs = rhs() - if (rhs != null) it::getRightHandSide shouldBe rhs + val expectedRhs = rhs() + if (expectedRhs != null) it::getRightHandSide shouldBe expectedRhs else unspecifiedChildren(2) // label + rhs } diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/TypeDisambiguationTest.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/TypeDisambiguationTest.kt index 7cf336cf72..3fcc73d62f 100644 --- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/TypeDisambiguationTest.kt +++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/TypeDisambiguationTest.kt @@ -246,18 +246,18 @@ class TypeDisambiguationTest : ParserTestSpec({ val outerUnresolved = m0.qualifier!! val outerT = outerUnresolved.typeMirror.shouldBeA { - it.symbol.shouldBeA { - it::isUnresolved shouldBe true - it::getSimpleName shouldBe "OuterUnresolved" + it.symbol.shouldBeA { classSymbol -> + classSymbol::isUnresolved shouldBe true + classSymbol::getSimpleName shouldBe "OuterUnresolved" } } val innerT = m0.typeMirror.shouldBeA { it::getEnclosingType shouldBe outerT - it.symbol.shouldBeA { - it::isUnresolved shouldBe true - it::getSimpleName shouldBe "InnerUnresolved" - it.enclosingClass.shouldBeSameInstanceAs(outerT.symbol) + it.symbol.shouldBeA { classSymbol -> + classSymbol::isUnresolved shouldBe true + classSymbol::getSimpleName shouldBe "InnerUnresolved" + classSymbol.enclosingClass.shouldBeSameInstanceAs(outerT.symbol) } } @@ -314,7 +314,7 @@ class TypeDisambiguationTest : ParserTestSpec({ // before all classes of the CU have been visited enableProcessing() - val acu = parser.parse(""" + @Suppress("UNUSED_VARIABLE") val acu = parser.parse(""" package p; import static p.Assert2.*; diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/UsageResolutionTest.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/UsageResolutionTest.kt index bf332c059f..b6f3e05e0e 100644 --- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/UsageResolutionTest.kt +++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/UsageResolutionTest.kt @@ -65,13 +65,13 @@ class UsageResolutionTest : ProcessorTestSpec({ p::isRecordComponent shouldBe true p.localUsages.shouldHaveSize(2) p.localUsages[0].shouldBeA { - it.referencedSym!!.shouldBeA { - it.tryGetNode() shouldBe p + it.referencedSym!!.shouldBeA { symbol -> + symbol.tryGetNode() shouldBe p } } p.localUsages[1].shouldBeA { - it.referencedSym!!.shouldBeA { - it.tryGetNode() shouldBe p + it.referencedSym!!.shouldBeA { symbol -> + symbol.tryGetNode() shouldBe p } } } diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/VarDisambiguationTest.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/VarDisambiguationTest.kt index d890ddd97d..a96b9b9077 100644 --- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/VarDisambiguationTest.kt +++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/VarDisambiguationTest.kt @@ -11,7 +11,6 @@ import net.sourceforge.pmd.lang.ast.test.shouldMatchN import net.sourceforge.pmd.lang.java.JavaParsingHelper import net.sourceforge.pmd.lang.java.symbols.JClassSymbol import net.sourceforge.pmd.lang.java.symbols.JTypeParameterSymbol -import net.sourceforge.pmd.lang.java.symbols.table.internal.JavaSemanticErrors import net.sourceforge.pmd.lang.java.symbols.table.internal.JavaSemanticErrors.* class VarDisambiguationTest : ParserTestSpec({ diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/symbols/internal/AstSymbolTests.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/symbols/internal/AstSymbolTests.kt index cb8c48b9c8..7933491035 100644 --- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/symbols/internal/AstSymbolTests.kt +++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/symbols/internal/AstSymbolTests.kt @@ -386,7 +386,7 @@ class AstSymbolTests : ParserTestSpec({ val (canonCtor1, canonCtor2) = acu.descendants(ASTRecordComponentList::class.java).toList { it.symbol } val (auxCtor) = acu.descendants(ASTConstructorDeclaration::class.java).toList { it.symbol } val (xAccessor) = acu.descendants(ASTMethodDeclaration::class.java).toList { it.symbol } - val (xComp, yComp, x2Comp, y2Comp, x2Formal) = acu.descendants(ASTVariableId::class.java).toList { it.symbol } + val (xComp, yComp, _, y2Comp, _) = acu.descendants(ASTVariableId::class.java).toList { it.symbol } doTest("should reflect their modifiers") { @@ -550,7 +550,7 @@ class AstSymbolTests : ParserTestSpec({ } // all others are Runnable - (allAnons - anonsWithSuperClass).forEach { + (allAnons - anonsWithSuperClass.toSet()).forEach { it::getSuperclass shouldBe it.typeSystem.OBJECT.symbol it::getSuperInterfaces shouldBe listOf(it.typeSystem.getClassSymbol(Runnable::class.java)) } diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/symbols/internal/PrimitiveSymbolTests.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/symbols/internal/PrimitiveSymbolTests.kt index fae15094cd..676f0ffb01 100644 --- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/symbols/internal/PrimitiveSymbolTests.kt +++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/symbols/internal/PrimitiveSymbolTests.kt @@ -17,7 +17,7 @@ import net.sourceforge.pmd.lang.java.types.testTypeSystem */ class PrimitiveSymbolTests : WordSpec({ - fun primitives(): List = testTypeSystem.allPrimitives.map { it.symbol!! } + fun primitives(): List = testTypeSystem.allPrimitives.map { it.symbol } "A primitive symbol" should { diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/symbols/internal/ReflectedClassSymbolTests.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/symbols/internal/ReflectedClassSymbolTests.kt index 5051b1396e..51ab28b726 100644 --- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/symbols/internal/ReflectedClassSymbolTests.kt +++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/symbols/internal/ReflectedClassSymbolTests.kt @@ -40,7 +40,7 @@ class ReflectedClassSymbolTests : IntelliMarker, WordSpec({ "reflect its superinterfaces correctly" { TestClassesGen.forAllEqual { - classSym(it)!!.superInterfaces to it.interfaces.toList().map { classSym(it) } + classSym(it)!!.superInterfaces to it.interfaces.toList().map { clazz -> classSym(clazz) } } } diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/symbols/internal/ReflectedFieldSymbolTest.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/symbols/internal/ReflectedFieldSymbolTest.kt index bf09835375..4e5e07f00f 100644 --- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/symbols/internal/ReflectedFieldSymbolTest.kt +++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/symbols/internal/ReflectedFieldSymbolTest.kt @@ -6,6 +6,7 @@ package net.sourceforge.pmd.lang.java.symbols.internal import io.kotest.assertions.throwables.shouldThrow import io.kotest.core.spec.style.WordSpec +import io.kotest.matchers.ints.shouldBeExactly import io.kotest.matchers.shouldBe import io.kotest.matchers.shouldNotBe import io.kotest.property.arbitrary.filterNot @@ -39,8 +40,8 @@ class ReflectedFieldSymbolTest : IntelliMarker, WordSpec({ "reflect its modifiers properly" { TestClassesGen.filterNot { it.isArray }.forAllEqual { Pair( - classSym(it)!!.declaredFields.map { it.simpleName to it.modifiers }, - it.declaredFields.map { it.name to it.modifiers } + classSym(it)!!.declaredFields.map { fieldSymbol -> fieldSymbol.simpleName to fieldSymbol.modifiers }, + it.declaredFields.map { field -> field.name to field.modifiers } ) } } @@ -56,9 +57,14 @@ class ReflectedFieldSymbolTest : IntelliMarker, WordSpec({ } "be unmodifiable" { - shouldThrow { - classSym(SomeFields::class.java)!!.getDeclaredField("foo")!!.declaredAnnotations.add(null) - } + val declaredAnnotations = classSym(SomeFields::class.java)!!.getDeclaredField("foo")!!.declaredAnnotations + declaredAnnotations.size shouldBeExactly 1 + val annot = declaredAnnotations.first() + declaredAnnotations.plus(annot) + declaredAnnotations.size shouldBeExactly 1 + + // still unmodified + classSym(SomeFields::class.java)!!.getDeclaredField("foo")!!.declaredAnnotations.size shouldBeExactly 1 } } diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/symbols/internal/Utils.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/symbols/internal/Utils.kt index d83b1cafbc..549db7c9e8 100644 --- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/symbols/internal/Utils.kt +++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/symbols/internal/Utils.kt @@ -8,7 +8,6 @@ import io.kotest.assertions.withClue import io.kotest.matchers.collections.haveSize import io.kotest.matchers.should import io.kotest.property.* -import io.kotest.property.arbitrary.arbitrary import net.sourceforge.pmd.lang.java.symbols.JClassSymbol import net.sourceforge.pmd.lang.java.symbols.SymbolResolver import net.sourceforge.pmd.lang.java.types.testTypeSystem @@ -80,7 +79,7 @@ object TestClassesGen : Arb>() { return } val files = directory.listFiles() - for (file in files) { + for (file in files!!) { if (file.isDirectory) { assert(!file.name.contains(".")) findClasses(file, packageName + "." + file.name) diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/symbols/internal/asm/BrokenClasspathTest.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/symbols/internal/asm/BrokenClasspathTest.kt index 85f988420c..adce5714d8 100644 --- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/symbols/internal/asm/BrokenClasspathTest.kt +++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/symbols/internal/asm/BrokenClasspathTest.kt @@ -59,7 +59,7 @@ class BrokenClasspathTest : FunSpec({ // since we're loading things lazily this type hasn't tried to populate its superinterfaces val superItfType = ts.declaration(unresolvedItfSym) as JClassType val subclassType = ts.declaration(subclassSym) as JClassType - val (tvarC, tvarD) = subclassType.formalTypeParams + val (_, tvarD) = subclassType.formalTypeParams // and now since the super interface *type* is parameterized, we'll try to create SuperItf // Except SuperItf is unresolved. diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/symbols/internal/asm/SigParserTest.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/symbols/internal/asm/SigParserTest.kt index 4d16fdc868..70732ce819 100644 --- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/symbols/internal/asm/SigParserTest.kt +++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/symbols/internal/asm/SigParserTest.kt @@ -7,9 +7,7 @@ package net.sourceforge.pmd.lang.java.symbols.internal.asm import io.kotest.assertions.throwables.shouldThrow import io.kotest.assertions.withClue import io.kotest.core.spec.style.FunSpec -import io.kotest.matchers.Matcher import io.kotest.matchers.collections.shouldHaveSize -import io.kotest.matchers.should import io.kotest.matchers.shouldBe import io.kotest.matchers.string.shouldContain import javasymbols.testdata.impls.SomeInnerClasses diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/symbols/table/internal/HeaderScopesTest.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/symbols/table/internal/HeaderScopesTest.kt index e580ec1ceb..2275d89510 100644 --- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/symbols/table/internal/HeaderScopesTest.kt +++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/symbols/table/internal/HeaderScopesTest.kt @@ -7,8 +7,6 @@ package net.sourceforge.pmd.lang.java.symbols.table.internal import io.kotest.matchers.collections.* -import io.kotest.matchers.maps.shouldBeEmpty -import io.kotest.matchers.maps.shouldContain import io.kotest.matchers.nulls.shouldNotBeNull import io.kotest.matchers.should import io.kotest.matchers.shouldBe @@ -252,8 +250,8 @@ class HeaderScopesTest : ProcessorTestSpec({ it.apply { scopeTag shouldBe SINGLE_IMPORT results should haveSize(2) - results.forEach { - it.symbol.enclosingClass.canonicalName shouldBe "javasymbols.testdata.StaticNameCollision" + results.forEach { methodSig -> + methodSig.symbol.enclosingClass.canonicalName shouldBe "javasymbols.testdata.StaticNameCollision" } } @@ -261,8 +259,8 @@ class HeaderScopesTest : ProcessorTestSpec({ it.apply { scopeTag shouldBe IMPORT_ON_DEMAND results should haveSize(2) - results.forEach { - it.symbol.enclosingClass.canonicalName shouldBe "javasymbols.testdata.Statics" + results.forEach { methodSig -> + methodSig.symbol.enclosingClass.canonicalName shouldBe "javasymbols.testdata.Statics" } } } @@ -276,8 +274,8 @@ class HeaderScopesTest : ProcessorTestSpec({ it.apply { scopeTag shouldBe IMPORT_ON_DEMAND results should haveSize(1) - results.forEach { - it.symbol.enclosingClass.canonicalName shouldBe "javasymbols.testdata.Statics" + results.forEach { methodSig -> + methodSig.symbol.enclosingClass.canonicalName shouldBe "javasymbols.testdata.Statics" } } } diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/symbols/table/internal/LocalTypeScopesTest.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/symbols/table/internal/LocalTypeScopesTest.kt index eb874dca5e..e069eacc04 100644 --- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/symbols/table/internal/LocalTypeScopesTest.kt +++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/symbols/table/internal/LocalTypeScopesTest.kt @@ -112,7 +112,7 @@ class LocalTypeScopesTest : ParserTestSpec({ } """) - val (foo, inner, other) = + val (foo, inner, _) = acu.descendants(ASTClassDeclaration::class.java).toList() val (insideFoo, insideInner, insideOther) = diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/symbols/table/internal/MemberInheritanceTest.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/symbols/table/internal/MemberInheritanceTest.kt index 47f9947c13..425d703d0b 100644 --- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/symbols/table/internal/MemberInheritanceTest.kt +++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/symbols/table/internal/MemberInheritanceTest.kt @@ -261,26 +261,26 @@ class MemberInheritanceTest : ParserTestSpec({ } """) - val (t_Scratch, t_Inner) = + val (typeScratch, typeInner) = acu.descendants(ASTClassDeclaration::class.java).toList { it.typeMirror } val insideFoo = acu.descendants(ASTClassBody::class.java) .crossFindBoundaries().get(2)!! - val `t_Scratch{String}Inner` = with (acu.typeDsl) { - t_Scratch[gen.t_String].selectInner(t_Inner.symbol, emptyList()) + val `typeScratch{String}Inner` = with (acu.typeDsl) { + typeScratch[gen.t_String].selectInner(typeInner.symbol, emptyList()) } insideFoo.symbolTable.types().resolve("Inner").shouldBeSingleton { - it.shouldBe(`t_Scratch{String}Inner`) + it.shouldBe(`typeScratch{String}Inner`) } val typeNode = acu.descendants(ASTClassType::class.java).first { it.simpleName == "Inner" }!! typeNode.shouldMatchN { classType("Inner") { - it shouldHaveType `t_Scratch{String}Inner` + it shouldHaveType `typeScratch{String}Inner` } } diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/symbols/table/internal/VarScopingTest.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/symbols/table/internal/VarScopingTest.kt index 2435e576d5..6018dc47d8 100644 --- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/symbols/table/internal/VarScopingTest.kt +++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/symbols/table/internal/VarScopingTest.kt @@ -426,7 +426,7 @@ class VarScopingTest : ProcessorTestSpec({ """.trimIndent()) - val (_, t_SomeEnum) = acu.descendants(ASTTypeDeclaration::class.java).toList { it.typeMirror } + val (_, typeSomeEnum) = acu.descendants(ASTTypeDeclaration::class.java).toList { it.typeMirror } val (enumA, enumB) = acu.descendants(ASTEnumDeclaration::class.java) @@ -443,17 +443,17 @@ class VarScopingTest : ProcessorTestSpec({ qualifiedA.referencedSym shouldBe enumA.symbol qualifiedA.referencedSym!!.tryGetNode() shouldBe enumA - qualifiedA shouldHaveType t_SomeEnum + qualifiedA shouldHaveType typeSomeEnum caseA.referencedSym shouldBe enumA.symbol caseA.referencedSym!!.tryGetNode() shouldBe enumA - caseA shouldHaveType t_SomeEnum + caseA shouldHaveType typeSomeEnum caseB.referencedSym shouldBe enumB.symbol caseB.referencedSym!!.tryGetNode() shouldBe enumB - caseB shouldHaveType t_SomeEnum + caseB shouldHaveType typeSomeEnum - e shouldHaveType t_SomeEnum + e shouldHaveType typeSomeEnum // symbol tables don't carry that info, this is documented on JSymbolTable#variables() caseB.symbolTable.variables().resolve("A").shouldBeEmpty() diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/ArraySymbolTests.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/ArraySymbolTests.kt index 34d72f2690..c3fbed8538 100644 --- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/ArraySymbolTests.kt +++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/ArraySymbolTests.kt @@ -21,7 +21,7 @@ import net.sourceforge.pmd.lang.java.symbols.internal.getDeclaredMethods */ class ArraySymbolTests : WordSpec({ - val INT_SYM = testTypeSystem.getClassSymbol(java.lang.Integer.TYPE) + val INT_SYM = testTypeSystem.getClassSymbol(Integer.TYPE) val STRING_SYM = testTypeSystem.getClassSymbol(java.lang.String::class.java) fun makeArraySym(comp: JTypeDeclSymbol?) = ArraySymbolImpl(testTypeSystem, comp) diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/BoxingTest.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/BoxingTest.kt index f061b0050a..2d0739dda1 100644 --- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/BoxingTest.kt +++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/BoxingTest.kt @@ -10,7 +10,6 @@ import io.kotest.core.spec.style.FunSpec import io.kotest.matchers.shouldNotBe import io.kotest.matchers.types.shouldBeInstanceOf import io.kotest.matchers.types.shouldBeSameInstanceAs -import io.kotest.property.forAll import net.sourceforge.pmd.lang.java.symbols.internal.forAllEqual /** diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/CaptureTest.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/CaptureTest.kt index 951f12c671..03125a0a58 100644 --- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/CaptureTest.kt +++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/CaptureTest.kt @@ -7,7 +7,6 @@ package net.sourceforge.pmd.lang.java.types import io.kotest.core.spec.style.FunSpec import io.kotest.matchers.shouldBe -import net.sourceforge.pmd.lang.java.symbols.JClassSymbol import net.sourceforge.pmd.lang.java.symbols.internal.asm.createUnresolvedAsmSymbol import net.sourceforge.pmd.lang.java.types.TypeConversion.* @@ -58,7 +57,7 @@ class CaptureTest : FunSpec({ } test("Capture of malformed types") { - val sym = ts.createUnresolvedAsmSymbol("does.not.Exist") as JClassSymbol + val sym = ts.createUnresolvedAsmSymbol("does.not.Exist") val matcher = captureMatcher(`?` extends t_String).also { capture(sym[t_String, `?` extends t_String]) shouldBe sym[t_String, it] diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/SubtypingTest.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/SubtypingTest.kt index 1fdb1affa0..e370ca9112 100644 --- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/SubtypingTest.kt +++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/SubtypingTest.kt @@ -15,7 +15,6 @@ import io.kotest.property.exhaustive.ints import io.kotest.property.forAll import net.sourceforge.pmd.lang.ast.test.shouldBeA import net.sourceforge.pmd.lang.java.ast.ParserTestCtx -import net.sourceforge.pmd.lang.java.symbols.JClassSymbol import net.sourceforge.pmd.lang.java.symbols.internal.UnresolvedClassStore import net.sourceforge.pmd.lang.java.symbols.internal.asm.createUnresolvedAsmSymbol import net.sourceforge.pmd.lang.java.types.TypeConversion.* @@ -157,10 +156,10 @@ class SubtypingTest : FunSpec({ test("Test raw type is convertible to wildcard parameterized type without unchecked conversion") { val `Class{String}` = Class::class[ts.STRING] - val `Class{?}` = Class::class[`?`] + val `Class{Wildcard}` = Class::class[`?`] val Class = Class::class.raw - val `Comparable{?}` = java.lang.Comparable::class[`?`] + val `Comparable{Wildcard}` = java.lang.Comparable::class[`?`] /* Class raw = String.class; @@ -179,15 +178,15 @@ class SubtypingTest : FunSpec({ `Class{String}` shouldBeSubtypeOf Class - `Class{?}` shouldBeSubtypeOf Class + `Class{Wildcard}` shouldBeSubtypeOf Class - `Class{String}` shouldBeSubtypeOf `Class{?}` - `Class{?}` shouldNotBeSubtypeOf `Class{String}` + `Class{String}` shouldBeSubtypeOf `Class{Wildcard}` + `Class{Wildcard}` shouldNotBeSubtypeOf `Class{String}` - assertSubtype(Class, `Class{?}`) { this == UNCHECKED_NO_WARNING } + assertSubtype(Class, `Class{Wildcard}`) { this == UNCHECKED_NO_WARNING } Class shouldBeUncheckedSubtypeOf `Class{String}` - ts.STRING shouldBeSubtypeOf `Comparable{?}` + ts.STRING shouldBeSubtypeOf `Comparable{Wildcard}` } test("Test wildcard subtyping") { @@ -319,7 +318,7 @@ class SubtypingTest : FunSpec({ } test("Test non well-formed types") { - val sym = ts.createUnresolvedAsmSymbol("does.not.Exist") as JClassSymbol + val sym = ts.createUnresolvedAsmSymbol("does.not.Exist") sym[t_String, t_String] shouldBeUnrelatedTo sym[t_String] sym[t_String] shouldBeSubtypeOf sym[t_String] sym[t_String] shouldBeSubtypeOf sym[`?` extends t_String] // containment diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/TestUtilitiesForTypes.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/TestUtilitiesForTypes.kt index 90482a9828..ae87d1890e 100644 --- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/TestUtilitiesForTypes.kt +++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/TestUtilitiesForTypes.kt @@ -8,7 +8,6 @@ package net.sourceforge.pmd.lang.java.types import io.kotest.assertions.* -import io.kotest.assertions.print.Printed import io.kotest.assertions.print.print import io.kotest.matchers.shouldBe import net.sourceforge.pmd.lang.ast.test.shouldBe @@ -18,8 +17,8 @@ import net.sourceforge.pmd.lang.java.ast.* import net.sourceforge.pmd.lang.java.symbols.internal.asm.AsmSymbolResolver import net.sourceforge.pmd.lang.java.types.TypeOps.* import org.hamcrest.Description +import java.util.stream.Collectors import kotlin.String -import kotlin.streams.toList import kotlin.test.assertTrue /* @@ -45,7 +44,7 @@ val TypeSystem.STRING get() = declaration(getClassSymbol(String::class.java)) as typealias TypePair = Pair -fun JTypeMirror.getMethodsByName(name: String) = streamMethods { it.simpleName == name }.toList() +fun JTypeMirror.getMethodsByName(name: String): List = streamMethods { it.simpleName == name }.collect(Collectors.toList()) fun JTypeMirror.shouldBeUnresolvedClass(canonicalName: String) = this.shouldBeA { @@ -225,6 +224,7 @@ val JTypeMirror.isExlusiveIntersectionBound /** * Was added in java 12. */ +@Suppress("UNCHECKED_CAST") val Class.arrayType: Class> get() { val arr = java.lang.reflect.Array.newInstance(this, 0) diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/TypeCreationDsl.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/TypeCreationDsl.kt index f274fd9122..e0afd0284a 100644 --- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/TypeCreationDsl.kt +++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/TypeCreationDsl.kt @@ -7,7 +7,6 @@ package net.sourceforge.pmd.lang.java.types import net.sourceforge.pmd.lang.java.ast.JavaNode -import net.sourceforge.pmd.lang.java.ast.ParserTestSpec import net.sourceforge.pmd.lang.java.symbols.JClassSymbol import net.sourceforge.pmd.lang.java.symbols.SymbolicValue.SymAnnot import net.sourceforge.pmd.lang.java.symbols.internal.FakeSymAnnot @@ -26,7 +25,7 @@ val JavaNode.typeDsl get() = TypeDslOf(this.typeSystem) * int[][]: int.toArray(2) * List: List::class[`?` extends Number::class] * - * Use [typeDsl] (eg `with(node.typeDsl) { ... }`, + * Use [typeDsl] (eg `with(node.typeDsl) { ... }`), * or [TypeDslOf] (eg `with(TypeDslOf(ts)) { ... }`) * * to bring it into scope. @@ -125,13 +124,14 @@ interface TypeDslMixin { * List::class[`?` super String::class] * */ + @Suppress("DANGEROUS_CHARACTERS") val `?`: WildcardDsl get() = WildcardDsl(ts) } /** See [TypeDslMixin.@A]. */ -val ParserTestSpec.GroupTestCtx.VersionedTestCtx.ImplicitNodeParsingCtx<*>.AnnotA +val AnnotA get() = "@" + ClassWithTypeAnnotationsInside.A::class.java.canonicalName class TypeDslOf(override val ts: TypeSystem) : TypeDslMixin diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/TypeEqualityTest.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/TypeEqualityTest.kt index 99e363d56e..439fb9a03e 100644 --- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/TypeEqualityTest.kt +++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/TypeEqualityTest.kt @@ -10,9 +10,7 @@ import io.kotest.matchers.shouldBe import io.kotest.matchers.shouldNotBe import io.kotest.property.checkAll import io.kotest.property.forAll -import net.sourceforge.pmd.lang.java.symbols.JClassSymbol import net.sourceforge.pmd.lang.java.symbols.internal.asm.createUnresolvedAsmSymbol -import net.sourceforge.pmd.lang.java.symbols.internal.forAllEqual /** * @author Clément Fournier @@ -83,7 +81,7 @@ class TypeEqualityTest : FunSpec({ test("Test non well-formed types") { - val sym = ts.createUnresolvedAsmSymbol("does.not.Exist") as JClassSymbol + val sym = ts.createUnresolvedAsmSymbol("does.not.Exist") // not equal sym[t_String, t_String] shouldNotBe sym[t_String] sym[t_String] shouldNotBe sym[t_String, t_String] diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/TypeGenerationUtil.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/TypeGenerationUtil.kt index 455c7ba3fd..69260414da 100644 --- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/TypeGenerationUtil.kt +++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/TypeGenerationUtil.kt @@ -10,7 +10,9 @@ import io.kotest.property.Arb import io.kotest.property.Exhaustive import io.kotest.property.RandomSource import io.kotest.property.Sample -import io.kotest.property.arbitrary.* +import io.kotest.property.arbitrary.arbitrary +import io.kotest.property.arbitrary.filter +import io.kotest.property.arbitrary.pair import io.kotest.property.exhaustive.exhaustive import net.sourceforge.pmd.lang.java.JavaParsingHelper import net.sourceforge.pmd.lang.java.ast.ASTTypeParameter @@ -18,8 +20,7 @@ import net.sourceforge.pmd.lang.java.ast.ASTTypeParameters import net.sourceforge.pmd.lang.java.ast.ParserTestCtx import net.sourceforge.pmd.lang.java.symbols.internal.TestClassesGen import net.sourceforge.pmd.lang.java.symbols.internal.asm.createUnresolvedAsmSymbol -import javax.lang.model.type.TypeMirror -import kotlin.streams.toList +import java.util.stream.Collectors val TypeSystem.primitiveGen: Exhaustive get() = exhaustive(this.allPrimitives.toList()) @@ -48,7 +49,7 @@ class RefTypeGenArb(val ts: TypeSystem) : Arb() { // we exclude the null type because it's not ok as an array component ts.SERIALIZABLE, ts.CLONEABLE - ); + ) override fun edgecase(rs: RandomSource): JTypeMirror { return allEdgecases.random(rs.random) @@ -105,7 +106,7 @@ class RefTypeGenArb(val ts: TypeSystem) : Arb() { -@Suppress("ObjectPropertyName", "MemberVisibilityCanBePrivate") +@Suppress("MemberVisibilityCanBePrivate", "DANGEROUS_CHARACTERS") class RefTypeConstants(override val ts: TypeSystem) : TypeDslMixin { val t_String: JClassType get() = java.lang.String::class.decl @@ -192,7 +193,7 @@ fun JavaParsingHelper.makeDummyTVars(vararg names: String): List { .toStream() .map { it.typeMirror - }.toList() + }.collect(Collectors.toList()) } diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/TypesFromReflectionTest.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/TypesFromReflectionTest.kt index 0e8c5a6cc3..9785fc2669 100644 --- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/TypesFromReflectionTest.kt +++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/TypesFromReflectionTest.kt @@ -90,6 +90,7 @@ class TypesFromReflectionTest : FunSpec({ } + @Suppress("unused") private class GenericKlass /** diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/ast/ConversionContextTests.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/ast/ConversionContextTests.kt index b17eeae84e..c7ddf6d271 100644 --- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/ast/ConversionContextTests.kt +++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/ast/ConversionContextTests.kt @@ -49,7 +49,7 @@ class ConversionContextTests : ProcessorTestSpec({ } """) - val (ternary, _, num1, shortCast, num5) = acu.descendants(ASTExpression::class.java).toList() + val (ternary, _, num1, shortCast, _) = acu.descendants(ASTExpression::class.java).toList() spy.shouldBeOk { // ternary is in double assignment context @@ -80,7 +80,7 @@ class ConversionContextTests : ProcessorTestSpec({ } """) - val (ternary, _, integerCast, nullLit, num4) = acu.descendants(ASTExpression::class.java).toList() + val (ternary, _, integerCast, _, num4) = acu.descendants(ASTExpression::class.java).toList() spy.shouldBeOk { // ternary is in double assignment context diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/internal/infer/BranchingExprsTestCases.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/internal/infer/BranchingExprsTestCases.kt index 3810efe856..54d7834c04 100644 --- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/internal/infer/BranchingExprsTestCases.kt +++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/internal/infer/BranchingExprsTestCases.kt @@ -4,7 +4,6 @@ package net.sourceforge.pmd.lang.java.types.internal.infer -import io.kotest.matchers.shouldBe import net.sourceforge.pmd.lang.ast.test.shouldBe import net.sourceforge.pmd.lang.ast.test.shouldMatchN import net.sourceforge.pmd.lang.java.ast.* diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/internal/infer/CaptureInferenceTest.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/internal/infer/CaptureInferenceTest.kt index b4f84781af..f9b36667de 100644 --- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/internal/infer/CaptureInferenceTest.kt +++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/internal/infer/CaptureInferenceTest.kt @@ -476,7 +476,6 @@ public class SubClass { """.trimIndent() ) - val cvar = acu.typeVar("C") val tvar = acu.typeVar("T") spy.shouldBeOk { diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/internal/infer/CtorInferenceTest.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/internal/infer/CtorInferenceTest.kt index ce73c75bfb..8719732856 100644 --- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/internal/infer/CtorInferenceTest.kt +++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/internal/infer/CtorInferenceTest.kt @@ -215,7 +215,7 @@ class CtorInferenceTest : ProcessorTestSpec({ """) - val (t_Outer, t_Inner, t_Scratch) = acu.declaredTypeSignatures() + val (t_Outer, t_Inner, _) = acu.declaredTypeSignatures() val (innerCtor) = acu.ctorDeclarations().toList() val (ctor) = acu.descendants(ASTExplicitConstructorInvocation::class.java).toList() @@ -260,7 +260,7 @@ class CtorInferenceTest : ProcessorTestSpec({ """) - val (t_Outer, t_Inner, t_Scratch) = acu.declaredTypeSignatures() + val (t_Outer, t_Inner, _) = acu.declaredTypeSignatures() val (innerCtor) = acu.ctorDeclarations().toList() val (ctor) = acu.descendants(ASTExplicitConstructorInvocation::class.java).toList() @@ -335,7 +335,7 @@ class CtorInferenceTest : ProcessorTestSpec({ parserTest("Mapping of type params doesn't fail") { - val (acu, spy) = parser.parseWithTypeInferenceSpy( + val (acu, _) = parser.parseWithTypeInferenceSpy( """ class Gen { diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/internal/infer/Java7InferenceTest.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/internal/infer/Java7InferenceTest.kt index bb2778d52c..c67186fe28 100644 --- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/internal/infer/Java7InferenceTest.kt +++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/internal/infer/Java7InferenceTest.kt @@ -193,7 +193,7 @@ class Java7InferenceTest : ProcessorTestSpec({ }) -private fun TypeDslMixin.ctorInfersTo( +private fun ctorInfersTo( call: ASTConstructorCall, inferredType: JClassType ) { @@ -204,7 +204,7 @@ private fun TypeDslMixin.ctorInfersTo( ) } -private fun TypeDslMixin.methodInfersTo(call: ASTMethodCall, returnType: JClassType) { +private fun methodInfersTo(call: ASTMethodCall, returnType: JClassType) { call.methodType.shouldMatchMethod( named = call.methodName, declaredIn = null, // not asserted diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/internal/infer/OverridingTest.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/internal/infer/OverridingTest.kt index 4265682cfc..c7f41da2b8 100644 --- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/internal/infer/OverridingTest.kt +++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/internal/infer/OverridingTest.kt @@ -10,7 +10,6 @@ import io.kotest.matchers.shouldBe import net.sourceforge.pmd.lang.java.ast.* import net.sourceforge.pmd.lang.java.types.* import net.sourceforge.pmd.util.OptionalBool -import org.intellij.lang.annotations.Language import kotlin.test.assertFalse import kotlin.test.assertTrue diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/internal/infer/SpecialMethodsTest.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/internal/infer/SpecialMethodsTest.kt index 05ae0ee19a..1c3d7feb0e 100644 --- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/internal/infer/SpecialMethodsTest.kt +++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/internal/infer/SpecialMethodsTest.kt @@ -5,6 +5,7 @@ package net.sourceforge.pmd.lang.java.types.internal.infer import io.kotest.matchers.shouldBe +import io.kotest.matchers.shouldNotBe import net.sourceforge.pmd.lang.ast.test.shouldBeA import net.sourceforge.pmd.lang.ast.test.shouldMatchN import net.sourceforge.pmd.lang.java.ast.* @@ -44,7 +45,7 @@ class SpecialMethodsTest : ProcessorTestSpec({ val t_Scratch = acu.declaredTypeSignatures()[0] val kvar = acu.typeVar("K") - val (k, k2, raw, call) = acu.methodCalls().toList() + val (k, k2, _, call) = acu.methodCalls().toList() doTest("Test this::getClass") { spy.shouldBeOk { @@ -137,7 +138,7 @@ class SpecialMethodsTest : ProcessorTestSpec({ """.trimIndent()) - val t_Scratch = acu.descendants(ASTTypeDeclaration::class.java).firstOrThrow().typeMirror + acu.descendants(ASTTypeDeclaration::class.java).firstOrThrow().typeMirror shouldNotBe null val call = acu.descendants(ASTMethodCall::class.java).firstOrThrow() diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/internal/infer/StandaloneTypesTest.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/internal/infer/StandaloneTypesTest.kt index 51729be664..ada89eb28b 100644 --- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/internal/infer/StandaloneTypesTest.kt +++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/internal/infer/StandaloneTypesTest.kt @@ -8,10 +8,7 @@ package net.sourceforge.pmd.lang.java.types.internal.infer import io.kotest.assertions.withClue import io.kotest.matchers.shouldBe import io.kotest.matchers.shouldNotBe -import io.kotest.property.arbitrary.filterNot -import io.kotest.property.checkAll import net.sourceforge.pmd.lang.ast.test.shouldBe -import net.sourceforge.pmd.lang.ast.test.shouldBeA import net.sourceforge.pmd.lang.ast.test.shouldMatchN import net.sourceforge.pmd.lang.java.ast.* import net.sourceforge.pmd.lang.java.ast.BinaryOp.* diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/internal/infer/StressTest.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/internal/infer/StressTest.kt index 587e564fd7..2af70e82aa 100644 --- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/internal/infer/StressTest.kt +++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/internal/infer/StressTest.kt @@ -39,7 +39,7 @@ class StressTest : ProcessorTestSpec({ fun TreeNodeWrapper.typeIs(value: Boolean) { it.typeMirror.shouldBeA { it.symbol.binaryName shouldBe "net.sourceforge.pmd.lang.java.types.testdata.BoolLogic\$${value.toString() - .replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }}" + .replaceFirstChar { char -> if (char.isLowerCase()) char.titlecase(Locale.getDefault()) else char.toString() }}" } } diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/internal/infer/TypeAnnotationsInferenceTest.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/internal/infer/TypeAnnotationsInferenceTest.kt index b43cc4be6f..05ecc933b9 100644 --- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/internal/infer/TypeAnnotationsInferenceTest.kt +++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/internal/infer/TypeAnnotationsInferenceTest.kt @@ -8,8 +8,6 @@ package net.sourceforge.pmd.lang.java.types.internal.infer import net.sourceforge.pmd.lang.java.ast.* import net.sourceforge.pmd.lang.java.types.* -import net.sourceforge.pmd.lang.java.types.internal.infer.TypeInferenceLogger.VerboseLogger -import java.util.* /** */ diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/internal/infer/TypeInferenceTest.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/internal/infer/TypeInferenceTest.kt index 8a1e246d74..27d8af4949 100644 --- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/internal/infer/TypeInferenceTest.kt +++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/internal/infer/TypeInferenceTest.kt @@ -248,7 +248,7 @@ class Scratch { } """.trimIndent()) - val (t_I, t_C) = acu.declaredTypeSignatures() + val (_, t_C) = acu.declaredTypeSignatures() val tParam = acu.typeVariables().first { it.name == "T" } spy.shouldBeOk { diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/internal/infer/UnresolvedTypesRecoveryTest.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/internal/infer/UnresolvedTypesRecoveryTest.kt index 9c2b3e147d..99ca3b5dd2 100644 --- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/internal/infer/UnresolvedTypesRecoveryTest.kt +++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/types/internal/infer/UnresolvedTypesRecoveryTest.kt @@ -261,7 +261,7 @@ class C { val (fooM, idM) = acu.descendants(ASTMethodDeclaration::class.java).toList { it.symbol } val t_Foo = fooM.getReturnType(Substitution.EMPTY).shouldBeUnresolvedClass("ooo.Foo") - val t_Bound = idM.typeParameters[0].upperBound.shouldBeUnresolvedClass("ooo.Bound") + idM.typeParameters[0].upperBound.shouldBeUnresolvedClass("ooo.Bound") val call = acu.descendants(ASTMethodCall::class.java).firstOrThrow() diff --git a/pmd-lang-test/src/main/kotlin/net/sourceforge/pmd/cpd/test/CpdTextComparisonTest.kt b/pmd-lang-test/src/main/kotlin/net/sourceforge/pmd/cpd/test/CpdTextComparisonTest.kt index 7e462d2c99..abf42e6d75 100644 --- a/pmd-lang-test/src/main/kotlin/net/sourceforge/pmd/cpd/test/CpdTextComparisonTest.kt +++ b/pmd-lang-test/src/main/kotlin/net/sourceforge/pmd/cpd/test/CpdTextComparisonTest.kt @@ -130,9 +130,9 @@ abstract class CpdTextComparisonTest( private fun StringBuilder.formatLine(escapedImage: String, bcol: Any, ecol: Any): StringBuilder { var colStart = length - colStart = append(Indent).append(escapedImage).padCol(colStart, Col0Width) + colStart = append(INDENT).append(escapedImage).padCol(colStart, COL_0_WIDTH) @Suppress("UNUSED_VALUE") - colStart = append(Indent).append(bcol).padCol(colStart, Col1Width) + colStart = append(INDENT).append(bcol).padCol(colStart, COL_1_WIDTH) return append(ecol) } @@ -152,7 +152,7 @@ abstract class CpdTextComparisonTest( .replace(Regex("\\u000D\\u000A|[\\u000A\\u000B\\u000C\\u000D\\u0085\\u2028\\u2029]"), "\\\\n") // escape other newlines (normalizing), use \\R with java8+ .replace(Regex("[]\\[]"), "\\\\$0") // escape [] - var truncated = StringUtils.truncate(escaped, ImageSize) + var truncated = StringUtils.truncate(escaped, IMAGE_SIZE) if (truncated.endsWith('\\') && !truncated.endsWith("\\\\")) truncated = truncated.substring(0, truncated.length - 1) // cut inside an escape @@ -176,10 +176,10 @@ abstract class CpdTextComparisonTest( CpdLexer.tokenize(cpdLexer, sourceCodeOf(fileData)) private companion object { - const val Indent = " " - const val Col0Width = 40 - const val Col1Width = 10 + Indent.length - val ImageSize = Col0Width - Indent.length - 2 // -2 is for the "[]" + const val INDENT = " " + const val COL_0_WIDTH = 40 + const val COL_1_WIDTH = 10 + INDENT.length + const val IMAGE_SIZE = COL_0_WIDTH - INDENT.length - 2 // -2 is for the "[]" } } diff --git a/pmd-lang-test/src/main/kotlin/net/sourceforge/pmd/lang/ast/test/NodeExtensions.kt b/pmd-lang-test/src/main/kotlin/net/sourceforge/pmd/lang/ast/test/NodeExtensions.kt index 2a132ce149..a6d0ea0892 100644 --- a/pmd-lang-test/src/main/kotlin/net/sourceforge/pmd/lang/ast/test/NodeExtensions.kt +++ b/pmd-lang-test/src/main/kotlin/net/sourceforge/pmd/lang/ast/test/NodeExtensions.kt @@ -20,8 +20,6 @@ val TextAvailableNode.textStr: String infix fun TextAvailableNode.shouldHaveText(str: String) { this::textStr shouldBe str } -inline fun Node.getDescendantsOfType(): List = descendants(T::class.java).toList() -inline fun Node.getFirstDescendantOfType(): T = descendants(T::class.java).firstOrThrow() fun Node.textOfReportLocation(): String? = reportLocation.regionInFile?.let(textDocument::sliceOriginalText)?.toString() diff --git a/pmd-lang-test/src/main/kotlin/net/sourceforge/pmd/lang/ast/test/NodePrinters.kt b/pmd-lang-test/src/main/kotlin/net/sourceforge/pmd/lang/ast/test/NodePrinters.kt index 709b18c115..9d3dad1d49 100644 --- a/pmd-lang-test/src/main/kotlin/net/sourceforge/pmd/lang/ast/test/NodePrinters.kt +++ b/pmd-lang-test/src/main/kotlin/net/sourceforge/pmd/lang/ast/test/NodePrinters.kt @@ -27,10 +27,10 @@ val SimpleNodePrinter = TextTreeRenderer(true, -1) open class RelevantAttributePrinter : BaseNodeAttributePrinter() { - private val Ignored = setOf("BeginLine", "EndLine", "BeginColumn", "EndColumn", "FindBoundary", "SingleLine") + private val defaultIgnoredAttributes = setOf("BeginLine", "EndLine", "BeginColumn", "EndColumn", "FindBoundary", "SingleLine") override fun ignoreAttribute(node: Node, attribute: Attribute): Boolean = - Ignored.contains(attribute.name) || attribute.name == "Image" && attribute.value == null + defaultIgnoredAttributes.contains(attribute.name) || attribute.name == "Image" && attribute.value == null } @@ -102,7 +102,7 @@ open class BaseNodeAttributePrinter : TextTreeRenderer(true, -1) { get() = this.javaClass.let { when { it.isEnum -> it - else -> it.enclosingClass.takeIf { it.isEnum } + else -> it.enclosingClass.takeIf { clazz -> clazz.isEnum } ?: throw IllegalStateException() } } diff --git a/pmd-lang-test/src/main/kotlin/net/sourceforge/pmd/lang/ast/test/TestUtils.kt b/pmd-lang-test/src/main/kotlin/net/sourceforge/pmd/lang/ast/test/TestUtils.kt index e037138889..b7d9a5127e 100644 --- a/pmd-lang-test/src/main/kotlin/net/sourceforge/pmd/lang/ast/test/TestUtils.kt +++ b/pmd-lang-test/src/main/kotlin/net/sourceforge/pmd/lang/ast/test/TestUtils.kt @@ -12,6 +12,7 @@ import net.sourceforge.pmd.reporting.Report import net.sourceforge.pmd.reporting.RuleViolation import net.sourceforge.pmd.lang.ast.Node import net.sourceforge.pmd.lang.document.Chars +import java.util.* import kotlin.reflect.KCallable import kotlin.reflect.jvm.isAccessible import kotlin.test.assertEquals @@ -29,9 +30,9 @@ infix fun KCallable.shouldEqual(expected: V?) = n.should(equalityMatcher(v) as Matcher) } -private fun assertWrapper(callable: KCallable, right: V, asserter: (N, V) -> Unit) { +private fun assertWrapper(callable: KCallable, expected: V, asserter: (N, V) -> Unit) { - fun formatName() = "::" + callable.name.removePrefix("get").decapitalize() + fun formatName() = "::" + callable.name.removePrefix("get").replaceFirstChar { it.lowercase(Locale.getDefault()) } val value: N = try { callable.isAccessible = true @@ -41,7 +42,7 @@ private fun assertWrapper(callable: KCallable, right: V, asserter: (N, } try { - asserter(value, right) + asserter(value, expected) } catch (e: AssertionError) { if (e.message?.contains("expected:") == true) { diff --git a/pmd-lang-test/src/main/kotlin/net/sourceforge/pmd/test/BaseTextComparisonTest.kt b/pmd-lang-test/src/main/kotlin/net/sourceforge/pmd/test/BaseTextComparisonTest.kt index 635a85655c..9c67e29a9a 100644 --- a/pmd-lang-test/src/main/kotlin/net/sourceforge/pmd/test/BaseTextComparisonTest.kt +++ b/pmd-lang-test/src/main/kotlin/net/sourceforge/pmd/test/BaseTextComparisonTest.kt @@ -31,8 +31,8 @@ abstract class BaseTextComparisonTest { data class FileData(val fileName: FileId, val fileText:String) /** - * Executes the test. The test files are looked up using the [parser]. - * The reference test file must be named [fileBaseName] + [ExpectedExt]. + * Executes the test. The test files are looked up using the [resourceLoader]. + * The reference test file must be named [fileBaseName] + [EXPECTED_EXTENSION]. * The source file to parse must be named [fileBaseName] + [extensionIncludingDot]. * * @param transformTextContent Function that maps the contents of the source file to the @@ -41,7 +41,7 @@ abstract class BaseTextComparisonTest { internal fun doTest(fileBaseName: String, expectedSuffix: String = "", transformTextContent: (FileData) -> String) { - val expectedFile = findTestFile(resourceLoader, "${resourcePrefix}/$fileBaseName$expectedSuffix$ExpectedExt").toFile() + val expectedFile = findTestFile(resourceLoader, "${resourcePrefix}/$fileBaseName$expectedSuffix$EXPECTED_EXTENSION").toFile() val actual = transformTextContent(sourceText(fileBaseName)) @@ -97,7 +97,7 @@ abstract class BaseTextComparisonTest { } companion object { - const val ExpectedExt = ".txt" + const val EXPECTED_EXTENSION = ".txt" }