@@ -16,7 +16,6 @@ import com.demonwav.mcdev.platform.fabric.util.FabricConstants
16
16
import com.demonwav.mcdev.platform.forge.util.ForgeConstants
17
17
import com.demonwav.mcdev.platform.mixin.util.isMixin
18
18
import com.demonwav.mcdev.platform.mixin.util.mixinTargets
19
- import com.demonwav.mcdev.util.findAnnotation
20
19
import com.demonwav.mcdev.util.findModule
21
20
import com.demonwav.mcdev.util.packageName
22
21
import com.intellij.codeInspection.ProblemsHolder
@@ -25,6 +24,7 @@ import com.intellij.json.psi.JsonFile
25
24
import com.intellij.json.psi.JsonObject
26
25
import com.intellij.json.psi.JsonStringLiteral
27
26
import com.intellij.psi.JavaPsiFacade
27
+ import com.intellij.psi.PsiAnnotation
28
28
import com.intellij.psi.PsiArrayType
29
29
import com.intellij.psi.PsiClass
30
30
import com.intellij.psi.PsiClassObjectAccessExpression
@@ -49,63 +49,53 @@ object SideOnlyUtil {
49
49
const val MCDEV_SIDEONLY_ANNOTATION = " com.demonwav.mcdev.annotations.CheckEnv"
50
50
const val MCDEV_SIDE = " com.demonwav.mcdev.annotations.Env"
51
51
52
- internal fun getExplicitAnnotation (element : PsiModifierListOwner , hardness : SideHardness ): SideInstance ? {
52
+ internal fun getAnnotationSide (annotation : PsiAnnotation , hardness : SideHardness ): Side {
53
+ var isSideAnnotation = false
54
+
53
55
if (hardness != SideHardness .HARD ) {
54
- val mcDevAnnotation = element.findAnnotation(MCDEV_SIDEONLY_ANNOTATION )
55
- if (mcDevAnnotation != null ) {
56
- val side = mcDevAnnotation.findAttributeValue(" value" ) as ? PsiReferenceExpression
57
- ? : return null
58
- val sideConstant = side.resolve() as ? PsiEnumConstant ? : return null
59
- return when (sideConstant.name) {
60
- " CLIENT" -> SideInstance .createMcDev(Side .CLIENT , element)
61
- " SERVER" -> SideInstance .createMcDev(Side .SERVER , element)
62
- else -> null
63
- }
56
+ if (annotation.hasQualifiedName(MCDEV_SIDEONLY_ANNOTATION )) {
57
+ isSideAnnotation = true
64
58
}
65
59
}
66
60
67
61
if (hardness != SideHardness .SOFT ) {
68
- val sideOnlyAnnotation = element.findAnnotation(ForgeConstants .SIDE_ONLY_ANNOTATION )
69
- if (sideOnlyAnnotation != null ) {
70
- val side = sideOnlyAnnotation.findAttributeValue(" value" ) as ? PsiReferenceExpression
71
- ? : return null
72
- val sideConstant = side.resolve() as ? PsiEnumConstant ? : return null
73
- return when (sideConstant.name) {
74
- " CLIENT" -> SideInstance .createSideOnly(Side .CLIENT , element)
75
- " SERVER" -> SideInstance .createSideOnly(Side .SERVER , element)
76
- else -> null
62
+ if (annotation.hasQualifiedName(ForgeConstants .SIDE_ONLY_ANNOTATION ) ||
63
+ annotation.hasQualifiedName(FabricConstants .ENVIRONMENT_ANNOTATION )
64
+ ) {
65
+ isSideAnnotation = true
66
+ } else if (annotation.hasQualifiedName(ForgeConstants .ONLY_IN_ANNOTATION )) {
67
+ if (annotation.findAttributeValue(" _interface" ) != null ) {
68
+ isSideAnnotation = true
77
69
}
78
70
}
71
+ }
79
72
80
- val environmentAnnotation = element.findAnnotation(FabricConstants .ENVIRONMENT_ANNOTATION )
81
- if (environmentAnnotation != null ) {
82
- val env = environmentAnnotation.findAttributeValue(" value" ) as ? PsiReferenceExpression
83
- ? : return null
84
- val envConstant = env.resolve() as ? PsiEnumConstant ? : return null
85
- return when (envConstant.name) {
86
- " CLIENT" -> SideInstance .createEnvironment(Side .CLIENT , element)
87
- " SERVER" -> SideInstance .createEnvironment(Side .SERVER , element)
88
- else -> null
89
- }
90
- }
73
+ if (! isSideAnnotation) {
74
+ return Side .BOTH
75
+ }
91
76
92
- val onlyInAnnotation = element.annotations.firstOrNull {
93
- it.hasQualifiedName(ForgeConstants .ONLY_IN_ANNOTATION ) &&
94
- it.findAttributeValue(" _interface" ) == null
95
- }
96
- if (onlyInAnnotation != null ) {
97
- val dist = onlyInAnnotation.findAttributeValue(" value" ) as ? PsiReferenceExpression
98
- ? : return null
99
- val distConstant = dist.resolve() as ? PsiEnumConstant ? : return null
100
- return when (distConstant.name) {
101
- " CLIENT" -> SideInstance .createOnlyIn(Side .CLIENT , element)
102
- " DEDICATED_SERVER" -> SideInstance .createOnlyIn(Side .SERVER , element)
77
+ val side = annotation.findAttributeValue(" value" ) as ? PsiReferenceExpression ? : return Side .BOTH
78
+ val sideConstant = side.resolve() as ? PsiEnumConstant ? : return Side .BOTH
79
+ return when (sideConstant.name) {
80
+ " CLIENT" -> Side .CLIENT
81
+ " SERVER" , " DEDICATED_SERVER" -> Side .SERVER
82
+ else -> Side .BOTH
83
+ }
84
+ }
85
+
86
+ internal fun getExplicitAnnotation (element : PsiModifierListOwner , hardness : SideHardness ): SideInstance ? {
87
+ return element.annotations.asSequence()
88
+ .map { it to getAnnotationSide(it, hardness) }
89
+ .firstOrNull { it.second != Side .BOTH }
90
+ ?.let {
91
+ when (it.first.qualifiedName) {
92
+ MCDEV_SIDEONLY_ANNOTATION -> SideInstance .createMcDev(it.second, element)
93
+ ForgeConstants .SIDE_ONLY_ANNOTATION -> SideInstance .createSideOnly(it.second, element)
94
+ ForgeConstants .ONLY_IN_ANNOTATION -> SideInstance .createOnlyIn(it.second, element)
95
+ FabricConstants .ENVIRONMENT_ANNOTATION -> SideInstance .createEnvironment(it.second, element)
103
96
else -> null
104
97
}
105
98
}
106
- }
107
-
108
- return null
109
99
}
110
100
111
101
internal fun getExplicitOrInferredAnnotation (element : PsiModifierListOwner , hardness : SideHardness ): SideInstance ? {
0 commit comments