Skip to content

Commit

Permalink
More accurate owner information and cross-library compatibility tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ogolberg committed Sep 29, 2023
1 parent 21a8f13 commit b95aeca
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 8 deletions.
18 changes: 11 additions & 7 deletions core/src/main/kotlin/com/toasttab/expediter/Expediter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,18 @@ fun <M : MemberType> findIssue(type: TypeDescriptor, access: MemberAccess<M>, ch

if (member == null) {
Issue.MissingMember(type.name, access)
} else if (member.member.declaration == AccessDeclaration.STATIC && !access.accessType.isStatic()) {
Issue.AccessStaticMemberNonStatically(type.name, access)
} else if (member.member.declaration == AccessDeclaration.INSTANCE && access.accessType.isStatic()) {
Issue.AccessInstanceMemberStatically(type.name, access)
} else if (!AccessCheck.allowedAccess(type, member.owner, member.member)) {
Issue.AccessInaccessibleMember(type.name, access)
} else {
null
val clarifiedAccess = access.clarifyOwner(member.owner.name)

if (member.member.declaration == AccessDeclaration.STATIC && !access.accessType.isStatic()) {
Issue.AccessStaticMemberNonStatically(type.name, clarifiedAccess)
} else if (member.member.declaration == AccessDeclaration.INSTANCE && access.accessType.isStatic()) {
Issue.AccessInstanceMemberStatically(type.name, clarifiedAccess)
} else if (!AccessCheck.allowedAccess(type, member.owner, member.member)) {
Issue.AccessInaccessibleMember(type.name, clarifiedAccess)
} else {
null
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ sealed interface Issue {
data class AccessStaticMemberNonStatically(val caller: String, val member: MemberAccess<*>) : Issue {
override val target: String get() = member.owner

override fun toString() = "$caller acceses static $member non-statically"
override fun toString() = "$caller accesses static $member non-statically"
}

@Serializable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ sealed interface MemberAccess<M : MemberType> {
val ref: MemberSymbolicReference<M>
val accessType: MemberAccessType

fun clarifyOwner(moreSpecificOwner: String): MemberAccess<M>

@Serializable
@SerialName("method")
data class MethodAccess(
Expand All @@ -32,6 +34,7 @@ sealed interface MemberAccess<M : MemberType> {
override val accessType: MethodAccessType
) : MemberAccess<MemberType.Method> {
override fun toString() = "${ref.type} $owner.$ref"
override fun clarifyOwner(moreSpecificOwner: String) = MethodAccess(moreSpecificOwner, ref, accessType)
}

@Serializable
Expand All @@ -42,6 +45,7 @@ sealed interface MemberAccess<M : MemberType> {
override val accessType: FieldAccessType
) : MemberAccess<MemberType.Field> {
override fun toString() = "${ref.type} $owner.$ref"
override fun clarifyOwner(moreSpecificOwner: String) = FieldAccess(moreSpecificOwner, ref, accessType)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import com.toasttab.gradle.testkit.TestKit
import com.toasttab.gradle.testkit.TestProject
import org.junit.jupiter.api.Test
import strikt.api.expectThat
import strikt.assertions.contains
import strikt.assertions.containsExactlyInAnyOrder
import kotlin.io.path.readText

Expand Down Expand Up @@ -107,4 +108,20 @@ class ExpediterPluginIntegrationTest {
)
)
}

@Test
fun `cross library`(project: TestProject) {
project.createRunner().withArguments("check").buildAndFail()

val report = IssueReport.fromJson(project.dir.resolve("build/expediter.json").readText())

expectThat(report.issues).contains(
Issue.AccessInaccessibleMember("com/fasterxml/jackson/databind/ser/impl/PropertyBasedObjectIdGenerator",
MemberAccess.MethodAccess(
"com/fasterxml/jackson/annotation/ObjectIdGenerators\$Base",
MemberSymbolicReference.MethodSymbolicReference("getScope", "()Ljava/lang/Class;"),
MethodAccessType.VIRTUAL
))
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
plugins {
java
id("com.toasttab.expediter")
id("com.toasttab.testkit.coverage") version "0.0.2"
}

repositories {
mavenCentral()
}

dependencies {
implementation("com.fasterxml.jackson.core:jackson-databind:2.15.2")
implementation("com.fasterxml.jackson.core:jackson-core:2.13.5")
}

expediter {
failOnIssues = true

platform {
jvmVersion = 8
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = "test"

0 comments on commit b95aeca

Please sign in to comment.