forked from phoedos/pmd
Fix kotlin compiler warnings
This commit is contained in:
parent
150c0c88a4
commit
cc3da7b21e
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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({
|
||||
|
@ -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) {
|
||||
|
||||
|
@ -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) {
|
||||
|
||||
|
@ -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") {
|
||||
|
@ -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
|
||||
|
||||
|
@ -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<C>.super::foo" shouldNot parse()
|
||||
"T.B<C>.super.foo()" shouldNot parse()
|
||||
"T.@F B.super.foo()" shouldNot parse()
|
||||
|
@ -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<C>.this" shouldNot parse()
|
||||
"T.@F B.this" shouldNot parse()
|
||||
}
|
||||
|
@ -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) {
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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<JavaVersion> {
|
||||
/** 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<JavaVersion> = values().toList() - this
|
||||
@ -64,9 +61,9 @@ enum class JavaVersion : Comparable<JavaVersion> {
|
||||
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<JavaVersion>) = values().toList() - versions
|
||||
fun except(versions: List<JavaVersion>) = values().toList() - versions.toSet()
|
||||
}
|
||||
}
|
||||
|
||||
@ -151,8 +148,8 @@ inline fun <reified N : Node> 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 <reified N : Node> 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:
|
||||
|
@ -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<ASTTypeDeclaration>("top-level declaration") {
|
||||
|
@ -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", ")")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -256,8 +256,8 @@ fun TreeNodeWrapper<Node, *>.returnStatement(contents: ValuedNodeSpec<ASTReturnS
|
||||
|
||||
fun TreeNodeWrapper<Node, *>.forLoop(body: ValuedNodeSpec<ASTForStatement, ASTStatement?> = { null }) =
|
||||
child<ASTForStatement> {
|
||||
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<Node, *>.statementExprList(body: NodeSpec<ASTStatementExpres
|
||||
|
||||
fun TreeNodeWrapper<Node, *>.foreachLoop(body: ValuedNodeSpec<ASTForeachStatement, ASTStatement?> = { null }) =
|
||||
child<ASTForeachStatement> {
|
||||
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<Node, *>.doLoop(body: ValuedNodeSpec<ASTDoStatement, ASTStatement?> = { null }) =
|
||||
child<ASTDoStatement> {
|
||||
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<Node, *>.whileLoop(body: ValuedNodeSpec<ASTWhileStatement, ASTStatement?> = { null }) =
|
||||
child<ASTWhileStatement> {
|
||||
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<Node, *>.unionType(contents: NodeSpec<ASTUnionType> = EmptyA
|
||||
contents()
|
||||
}
|
||||
|
||||
fun TreeNodeWrapper<Node, *>.voidType() = child<ASTVoidType>() {}
|
||||
fun TreeNodeWrapper<Node, *>.voidType() = child<ASTVoidType> {}
|
||||
|
||||
|
||||
fun TreeNodeWrapper<Node, *>.typeExpr(contents: ValuedNodeSpec<ASTTypeExpression, ASTType>) =
|
||||
@ -425,7 +425,7 @@ fun TreeNodeWrapper<Node, *>.arrayType(contents: NodeSpec<ASTArrayType> = EmptyA
|
||||
fun TreeNodeWrapper<Node, *>.primitiveType(type: PrimitiveTypeKind, assertions: NodeSpec<ASTPrimitiveType> = EmptyAssertions) =
|
||||
child<ASTPrimitiveType> {
|
||||
it::getKind shouldBe type
|
||||
PrettyPrintingUtil.prettyPrintType(it) shouldBe type.toString();
|
||||
PrettyPrintingUtil.prettyPrintType(it) shouldBe type.toString()
|
||||
assertions()
|
||||
}
|
||||
|
||||
@ -586,8 +586,8 @@ fun TreeNodeWrapper<Node, *>.switchStmt(assertions: NodeSpec<ASTSwitchStatement>
|
||||
|
||||
fun TreeNodeWrapper<Node, *>.switchArrow(rhs: ValuedNodeSpec<ASTSwitchArrowBranch, ASTSwitchArrowRHS?> = { null }) =
|
||||
child<ASTSwitchArrowBranch> {
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -246,18 +246,18 @@ class TypeDisambiguationTest : ParserTestSpec({
|
||||
|
||||
val outerUnresolved = m0.qualifier!!
|
||||
val outerT = outerUnresolved.typeMirror.shouldBeA<JClassType> {
|
||||
it.symbol.shouldBeA<JClassSymbol> {
|
||||
it::isUnresolved shouldBe true
|
||||
it::getSimpleName shouldBe "OuterUnresolved"
|
||||
it.symbol.shouldBeA<JClassSymbol> { classSymbol ->
|
||||
classSymbol::isUnresolved shouldBe true
|
||||
classSymbol::getSimpleName shouldBe "OuterUnresolved"
|
||||
}
|
||||
}
|
||||
|
||||
val innerT = m0.typeMirror.shouldBeA<JClassType> {
|
||||
it::getEnclosingType shouldBe outerT
|
||||
it.symbol.shouldBeA<JClassSymbol> {
|
||||
it::isUnresolved shouldBe true
|
||||
it::getSimpleName shouldBe "InnerUnresolved"
|
||||
it.enclosingClass.shouldBeSameInstanceAs(outerT.symbol)
|
||||
it.symbol.shouldBeA<JClassSymbol> { 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.*;
|
||||
|
||||
|
@ -65,13 +65,13 @@ class UsageResolutionTest : ProcessorTestSpec({
|
||||
p::isRecordComponent shouldBe true
|
||||
p.localUsages.shouldHaveSize(2)
|
||||
p.localUsages[0].shouldBeA<ASTVariableAccess> {
|
||||
it.referencedSym!!.shouldBeA<JFormalParamSymbol> {
|
||||
it.tryGetNode() shouldBe p
|
||||
it.referencedSym!!.shouldBeA<JFormalParamSymbol> { symbol ->
|
||||
symbol.tryGetNode() shouldBe p
|
||||
}
|
||||
}
|
||||
p.localUsages[1].shouldBeA<ASTVariableAccess> {
|
||||
it.referencedSym!!.shouldBeA<JFieldSymbol> {
|
||||
it.tryGetNode() shouldBe p
|
||||
it.referencedSym!!.shouldBeA<JFieldSymbol> { symbol ->
|
||||
symbol.tryGetNode() shouldBe p
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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({
|
||||
|
@ -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))
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ import net.sourceforge.pmd.lang.java.types.testTypeSystem
|
||||
*/
|
||||
class PrimitiveSymbolTests : WordSpec({
|
||||
|
||||
fun primitives(): List<JClassSymbol> = testTypeSystem.allPrimitives.map { it.symbol!! }
|
||||
fun primitives(): List<JClassSymbol> = testTypeSystem.allPrimitives.map { it.symbol }
|
||||
|
||||
"A primitive symbol" should {
|
||||
|
||||
|
@ -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) }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<UnsupportedOperationException> {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<Class<*>>() {
|
||||
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)
|
||||
|
@ -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<D,D>
|
||||
// Except SuperItf is unresolved.
|
||||
|
@ -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
|
||||
|
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -112,7 +112,7 @@ class LocalTypeScopesTest : ParserTestSpec({
|
||||
}
|
||||
""")
|
||||
|
||||
val (foo, inner, other) =
|
||||
val (foo, inner, _) =
|
||||
acu.descendants(ASTClassDeclaration::class.java).toList()
|
||||
|
||||
val (insideFoo, insideInner, insideOther) =
|
||||
|
@ -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`
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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()
|
||||
|
@ -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)
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user