Skip to content

Commit d6b0d83

Browse files
committed
Treat classTweaker header as v3. Fixes #2547
1 parent f107172 commit d6b0d83

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

src/main/kotlin/platform/mcp/ct/CtAnnotator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class CtAnnotator : Annotator {
4646
}
4747

4848
if (element.accessElement.text.startsWith("transitive-") &&
49-
element.containingFile?.childOfType<CtHeader>()?.versionString == "v1"
49+
element.containingFile?.childOfType<CtHeader>()?.effectiveVersion == 1
5050
) {
5151
holder.newAnnotation(HighlightSeverity.ERROR, "Transitive accesses were introduced in v2").create()
5252
}

src/main/kotlin/platform/mcp/ct/psi/mixins/CtHeaderMixin.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import com.demonwav.mcdev.platform.mcp.ct.psi.CtElement
2424

2525
interface CtHeaderMixin : CtElement {
2626

27+
val nameString: String
2728
val versionString: String?
2829
val namespaceString: String?
30+
val effectiveVersion: Int?
2931
}

src/main/kotlin/platform/mcp/ct/psi/mixins/impl/CtHeaderImplMixin.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,33 @@ import com.demonwav.mcdev.platform.mcp.ct.gen.psi.CtTypes
2424
import com.demonwav.mcdev.platform.mcp.ct.psi.mixins.CtHeaderMixin
2525
import com.intellij.extapi.psi.ASTWrapperPsiElement
2626
import com.intellij.lang.ASTNode
27+
import com.intellij.openapi.diagnostic.logger
2728
import com.intellij.psi.PsiElement
2829

2930
abstract class CtHeaderImplMixin(node: ASTNode) : ASTWrapperPsiElement(node), CtHeaderMixin {
31+
companion object {
32+
private val LOG = logger<CtHeaderImplMixin>()
33+
}
34+
35+
override val nameString: String
36+
get() = findNotNullChildByType<PsiElement>(CtTypes.HEADER_NAME).text
3037

3138
override val versionString: String?
3239
get() = findChildByType<PsiElement>(CtTypes.HEADER_VERSION_ELEMENT)?.text
3340

3441
override val namespaceString: String?
3542
get() = findChildByType<PsiElement>(CtTypes.HEADER_NAMESPACE_ELEMENT)?.text
43+
44+
override val effectiveVersion: Int?
45+
get() {
46+
val version = versionString?.removePrefix("v")?.toIntOrNull() ?: return null
47+
return when (nameString) {
48+
"accessWidener" -> version
49+
"classTweaker" -> version + 2
50+
else -> {
51+
LOG.error("Unknown header name: $nameString")
52+
null
53+
}
54+
}
55+
}
3656
}

0 commit comments

Comments
 (0)