@@ -22,8 +22,10 @@ package com.demonwav.mcdev.platform.mcp.ct
2222
2323import com.demonwav.mcdev.platform.mcp.ct.gen.psi.CtAccess
2424import com.demonwav.mcdev.platform.mcp.ct.gen.psi.CtClassLiteral
25+ import com.demonwav.mcdev.platform.mcp.ct.gen.psi.CtExtendEnumEntry
2526import com.demonwav.mcdev.platform.mcp.ct.gen.psi.CtFieldLiteral
2627import com.demonwav.mcdev.platform.mcp.ct.gen.psi.CtHeader
28+ import com.demonwav.mcdev.platform.mcp.ct.gen.psi.CtItfEntry
2729import com.demonwav.mcdev.platform.mcp.ct.gen.psi.CtMethodLiteral
2830import com.demonwav.mcdev.util.childOfType
2931import com.google.common.collect.HashMultimap
@@ -38,23 +40,40 @@ import com.intellij.psi.util.PsiTreeUtil
3840class CtAnnotator : Annotator {
3941
4042 override fun annotate (element : PsiElement , holder : AnnotationHolder ) {
41- if (element is CtAccess ) {
42- val access = element.text
43- val target = PsiTreeUtil .skipSiblingsForward(element, PsiWhiteSpace ::class .java)?.text
44- if (! TokenSets .compatibleByAccessMap.get(access).contains(target)) {
45- holder.newAnnotation(HighlightSeverity .ERROR , " Access '$access ' cannot be used on '$target '" ).create()
46- }
43+ val effectiveVersion by lazy { element.containingFile?.childOfType<CtHeader >()?.effectiveVersion ? : 1 }
44+
45+ when (element) {
46+ is CtAccess -> {
47+ val access = element.text
48+ val target = PsiTreeUtil .skipSiblingsForward(element, PsiWhiteSpace ::class .java)?.text
49+ if (! TokenSets .compatibleByAccessMap.get(access).contains(target)) {
50+ holder.newAnnotation(HighlightSeverity .ERROR , " Access '$access ' cannot be used on '$target '" ).create()
51+ }
4752
48- if (element.accessElement.text.startsWith(" transitive-" ) &&
49- element.containingFile?.childOfType<CtHeader >()?.effectiveVersion == 1
50- ) {
51- holder.newAnnotation(HighlightSeverity .ERROR , " Transitive accesses were introduced in v2" ).create()
53+ if (element.accessElement.text.startsWith(" transitive-" ) && effectiveVersion < 2 ) {
54+ holder.newAnnotation(HighlightSeverity .ERROR , " Transitive accesses were introduced in v2" ).create()
55+ }
56+ }
57+ is CtItfEntry -> {
58+ if (effectiveVersion < 3 ) {
59+ holder.newAnnotation(HighlightSeverity .ERROR , " Interface injection was introduced in ClassTweaker v1" )
60+ .range(element.firstChild)
61+ .create()
62+ }
63+ }
64+ is CtExtendEnumEntry -> {
65+ if (effectiveVersion < 4 ) {
66+ holder.newAnnotation(HighlightSeverity .ERROR , " Enum extension was introduced in ClassTweaker v2" )
67+ .range(element.firstChild)
68+ .create()
69+ }
5270 }
53- } else if (element is CtFieldLiteral || element is CtMethodLiteral || element is CtClassLiteral ) {
54- val target = element.text
55- val access = PsiTreeUtil .skipSiblingsBackward(element, PsiWhiteSpace ::class .java)?.text
56- if (! TokenSets .compatibleByTargetMap.get(target).contains(access)) {
57- holder.newAnnotation(HighlightSeverity .ERROR , " '$target ' cannot be used with '$access '" ).create()
71+ is CtFieldLiteral , is CtMethodLiteral , is CtClassLiteral -> {
72+ val target = element.text
73+ val access = PsiTreeUtil .skipSiblingsBackward(element, PsiWhiteSpace ::class .java)?.text
74+ if (! TokenSets .compatibleByTargetMap.get(target).contains(access)) {
75+ holder.newAnnotation(HighlightSeverity .ERROR , " '$target ' cannot be used with '$access '" ).create()
76+ }
5877 }
5978 }
6079 }
0 commit comments