Skip to content

Commit

Permalink
Merge branch '2022.3' into 2023.1
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/main/kotlin/util/code-gen.kt
  • Loading branch information
Earthcomputer committed Sep 24, 2023
2 parents 6a04b37 + 09aa901 commit 07e5f88
Show file tree
Hide file tree
Showing 18 changed files with 32 additions and 166 deletions.
8 changes: 4 additions & 4 deletions src/main/kotlin/platform/bukkit/BukkitModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class BukkitModule<out T : AbstractModuleType<*>>(facet: MinecraftFacet, type: T
chosenClass: PsiClass,
chosenName: String,
data: GenerationData?,
): PsiMethod? {
): PsiMethod {
val bukkitData = data as BukkitGenerationData

val method = generateBukkitStyleEventListenerMethod(
Expand All @@ -101,7 +101,7 @@ class BukkitModule<out T : AbstractModuleType<*>>(facet: MinecraftFacet, type: T
project,
BukkitConstants.HANDLER_ANNOTATION,
bukkitData.isIgnoreCanceled,
) ?: return null
)

if (bukkitData.eventPriority != "NORMAL") {
val list = method.modifierList
Expand Down Expand Up @@ -217,8 +217,8 @@ class BukkitModule<out T : AbstractModuleType<*>>(facet: MinecraftFacet, type: T
project: Project,
annotationName: String,
setIgnoreCancelled: Boolean,
): PsiMethod? {
val newMethod = createVoidMethodWithParameterType(project, chosenName, chosenClass) ?: return null
): PsiMethod {
val newMethod = createVoidMethodWithParameterType(project, chosenName, chosenClass)
val modifierList = newMethod.modifierList
val annotation = modifierList.addAnnotation(annotationName)

Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/platform/forge/ForgeModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,10 @@ class ForgeModule internal constructor(facet: MinecraftFacet) : AbstractModule(f
chosenClass: PsiClass,
chosenName: String,
data: GenerationData?,
): PsiMethod? {
): PsiMethod {
val isFmlEvent = chosenClass.extendsOrImplements(ForgeConstants.FML_EVENT)

val method = createVoidMethodWithParameterType(project, chosenName, chosenClass) ?: return null
val method = createVoidMethodWithParameterType(project, chosenName, chosenClass)
val modifierList = method.modifierList

if (isFmlEvent) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import com.intellij.openapi.project.Project
import com.intellij.psi.JavaPsiFacade
import com.intellij.psi.JavaTokenType
import com.intellij.psi.PsiBinaryExpression
import com.intellij.psi.PsiClassType
import com.intellij.psi.PsiExpression
import com.intellij.psi.PsiField
import com.intellij.psi.PsiReferenceExpression
Expand Down Expand Up @@ -118,7 +117,7 @@ class StackEmptyInspection : BaseInspection() {
}

private fun isExpressionStack(expression: PsiExpression?): Boolean {
return (expression?.type as? PsiClassType)?.resolve()?.fullQualifiedName == STACK_FQ_NAME
return expression?.type?.equalsToText(STACK_FQ_NAME) == true
}

private fun isExpressionEmptyConstant(expression: PsiExpression?): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import com.intellij.psi.CommonClassNames.JAVA_LANG_INTEGER
import com.intellij.psi.CommonClassNames.JAVA_LANG_LONG
import com.intellij.psi.CommonClassNames.JAVA_LANG_SHORT
import com.intellij.psi.CommonClassNames.JAVA_LANG_STRING
import com.intellij.psi.CommonClassNames.JAVA_LANG_STRING_SHORT
import com.intellij.psi.PsiArrayType
import com.intellij.psi.PsiClassType
import com.intellij.psi.PsiElementVisitor
Expand Down Expand Up @@ -97,27 +96,23 @@ class ConfigValueInspection : MixinConfigInspection() {
return true // Idk, it's fine I guess
}

if (type.className == JAVA_LANG_STRING_SHORT && type.resolve()?.qualifiedName == JAVA_LANG_STRING) {
if (type.equalsToText(JAVA_LANG_STRING)) {
return value is JsonStringLiteral
}

if (type.className == "Boolean" && type.resolve()?.qualifiedName == CommonClassNames.JAVA_LANG_BOOLEAN) {
if (type.equalsToText(CommonClassNames.JAVA_LANG_BOOLEAN)) {
return value is JsonBooleanLiteral || value is JsonNullLiteral
}

if (
shortNumberNames.contains(type.className) &&
qualifiedNumberNames.contains(type.resolve()?.qualifiedName)
) {
if (qualifiedNumberNames.any(type::equalsToText)) {
return value is JsonNumberLiteral || value is JsonNullLiteral
}

PsiUtil.extractIterableTypeParameter(type, true)?.let { return checkArray(it, value) }
return value is JsonObject
}

private val shortNumberNames = setOf("Byte", "Character", "Double", "Float", "Integer", "Long", "Short")
private val qualifiedNumberNames = setOf(
private val qualifiedNumberNames = listOf(
JAVA_LANG_BYTE,
JAVA_LANG_CHARACTER,
JAVA_LANG_DOUBLE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import com.intellij.openapi.editor.Document
import com.intellij.openapi.util.TextRange
import com.intellij.psi.CommonClassNames
import com.intellij.psi.JavaRecursiveElementWalkingVisitor
import com.intellij.psi.PsiClassType
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiJavaFile
import com.intellij.psi.PsiTypeCastExpression
Expand Down Expand Up @@ -74,7 +73,7 @@ class MixinObjectCastFoldingBuilder : CustomFoldingBuilder() {
}

val innerCast = expression.operand as? PsiTypeCastExpression ?: return
if ((innerCast.type as? PsiClassType)?.resolve()?.qualifiedName == CommonClassNames.JAVA_LANG_OBJECT) {
if (innerCast.type?.equalsToText(CommonClassNames.JAVA_LANG_OBJECT) == true) {
// Fold the two casts

val start = (expression as? CompositeElement)?.findChildByRole(ChildRole.LPARENTH) ?: return
Expand Down
4 changes: 1 addition & 3 deletions src/main/kotlin/platform/mixin/handlers/InvokerHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ import com.demonwav.mcdev.util.constantStringValue
import com.demonwav.mcdev.util.decapitalize
import com.demonwav.mcdev.util.descriptor
import com.demonwav.mcdev.util.findAnnotation
import com.demonwav.mcdev.util.fullQualifiedName
import com.intellij.psi.PsiAnnotation
import com.intellij.psi.PsiClassType
import com.intellij.psi.PsiMember
import com.intellij.psi.PsiMethod
import com.intellij.psi.SmartPsiElementPointer
Expand All @@ -55,7 +53,7 @@ class InvokerHandler : MixinMemberAnnotationHandler {
val name = getInvokerTargetName(annotation, member) ?: return emptyList()
val constructor = name == "<init>"
if (constructor &&
(member.returnType as? PsiClassType)?.resolve()?.fullQualifiedName?.replace('.', '/') != targetClass.name
member.returnType?.equalsToText(targetClass.name.replace('/', '.').replace('$', '.')) != true
) {
return emptyList()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ package com.demonwav.mcdev.platform.mixin.inspection
import com.demonwav.mcdev.platform.mixin.util.MixinConstants.Annotations.INJECT
import com.demonwav.mcdev.platform.mixin.util.MixinConstants.Classes.CALLBACK_INFO
import com.demonwav.mcdev.platform.mixin.util.MixinConstants.Classes.CALLBACK_INFO_RETURNABLE
import com.demonwav.mcdev.util.fullQualifiedName
import com.intellij.codeInspection.LocalQuickFixAndIntentionActionOnPsiElement
import com.intellij.codeInspection.ProblemHighlightType
import com.intellij.codeInspection.ProblemsHolder
Expand Down Expand Up @@ -58,8 +57,7 @@ class MixinCancellableInspection : MixinInspection() {
val isCancellable = cancellableAttribute.value == true

val ciParam = method.parameterList.parameters.firstOrNull {
val className = (it.type as? PsiClassType)?.fullQualifiedName ?: return@firstOrNull false
className == CALLBACK_INFO || className == CALLBACK_INFO_RETURNABLE
it.type.equalsToText(CALLBACK_INFO) || it.type.equalsToText(CALLBACK_INFO_RETURNABLE)
} ?: return

val ciType = (ciParam.type as? PsiClassType)?.resolve() ?: return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,11 +360,8 @@ class InjectCouldBeOverwriteInspection : MixinInspection() {
}

companion object {
private fun isCallbackInfoParam(param: PsiParameter): Boolean {
val type = (param.type as? PsiClassType)?.resolve() ?: return false
val qName = type.qualifiedName ?: return false
return qName == MixinConstants.Classes.CALLBACK_INFO ||
qName == MixinConstants.Classes.CALLBACK_INFO_RETURNABLE
}
private fun isCallbackInfoParam(param: PsiParameter) =
param.type.equalsToText(MixinConstants.Classes.CALLBACK_INFO) ||
param.type.equalsToText(MixinConstants.Classes.CALLBACK_INFO_RETURNABLE)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import com.demonwav.mcdev.platform.mixin.util.isAssignable
import com.demonwav.mcdev.platform.mixin.util.isConstructor
import com.demonwav.mcdev.platform.mixin.util.isMixinExtrasSugar
import com.demonwav.mcdev.util.Parameter
import com.demonwav.mcdev.util.fullQualifiedName
import com.demonwav.mcdev.util.synchronize
import com.intellij.codeInsight.intention.FileModifier.SafeFieldForPreview
import com.intellij.codeInsight.intention.QuickFixFactory
Expand All @@ -43,7 +42,6 @@ import com.intellij.codeInspection.ProblemsHolder
import com.intellij.openapi.project.Project
import com.intellij.psi.JavaElementVisitor
import com.intellij.psi.JavaPsiFacade
import com.intellij.psi.PsiClassType
import com.intellij.psi.PsiElementVisitor
import com.intellij.psi.PsiMethod
import com.intellij.psi.PsiModifier
Expand Down Expand Up @@ -307,9 +305,8 @@ class InvalidInjectorMethodSignatureInspection : MixinInspection() {
val parameters = descriptor.psiElement as PsiParameterList
// We want to preserve captured locals
val locals = parameters.parameters.dropWhile {
val fqname = (it.type as? PsiClassType)?.fullQualifiedName ?: return@dropWhile true
return@dropWhile fqname != MixinConstants.Classes.CALLBACK_INFO &&
fqname != MixinConstants.Classes.CALLBACK_INFO_RETURNABLE
!it.type.equalsToText(MixinConstants.Classes.CALLBACK_INFO) &&
!it.type.equalsToText(MixinConstants.Classes.CALLBACK_INFO_RETURNABLE)
}.drop(1) // the first element in the list is the CallbackInfo but we don't want it
.takeWhile { !it.isMixinExtrasSugar }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import com.intellij.psi.JavaElementVisitor
import com.intellij.psi.JavaPsiFacade
import com.intellij.psi.PsiCallExpression
import com.intellij.psi.PsiClass
import com.intellij.psi.PsiClassType
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiExpressionList
import com.intellij.psi.PsiField
Expand Down Expand Up @@ -68,7 +67,7 @@ class WrongOperationParametersInspection : MixinInspection() {
val (operationIndex, operationParam) = containingMethod.parameterList.parameters.asSequence()
.withIndex()
.firstOrNull { (_, param) ->
(param.type as? PsiClassType)?.resolve()?.qualifiedName == MixinConstants.MixinExtras.OPERATION
param.type.equalsToText(MixinConstants.MixinExtras.OPERATION)
} ?: return
val (expectedParamTypes, paramNames) = containingMethod.parameterList.parameters.asSequence()
.take(operationIndex)
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/platform/sponge/SpongeModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ class SpongeModule(facet: MinecraftFacet) : AbstractModule(facet) {
chosenClass: PsiClass,
chosenName: String,
data: GenerationData?,
): PsiMethod? {
val method = createVoidMethodWithParameterType(project, chosenName, chosenClass) ?: return null
): PsiMethod {
val method = createVoidMethodWithParameterType(project, chosenName, chosenClass)
val modifierList = method.modifierList

val listenerAnnotation = modifierList.addAnnotation("org.spongepowered.api.event.Listener")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@ package com.demonwav.mcdev.platform.sponge.inspection

import com.demonwav.mcdev.platform.sponge.SpongeModuleType
import com.demonwav.mcdev.util.Constants
import com.demonwav.mcdev.util.fullQualifiedName
import com.intellij.codeInspection.AbstractBaseJavaLocalInspectionTool
import com.intellij.codeInspection.InspectionManager
import com.intellij.codeInspection.ProblemDescriptor
import com.intellij.codeInspection.ProblemHighlightType
import com.intellij.codeInspection.ProblemsHolder
import com.intellij.psi.JavaElementVisitor
import com.intellij.psi.PsiClassType
import com.intellij.psi.PsiElementVisitor
import com.intellij.psi.PsiField
import com.intellij.psi.PsiFile
Expand Down Expand Up @@ -60,9 +58,8 @@ class SpongeLoggingInspection : AbstractBaseJavaLocalInspectionTool() {

override fun visitField(field: PsiField) {
val element = field.typeElement ?: return
val name = (field.type as? PsiClassType)?.fullQualifiedName ?: return

if (name != Constants.JAVA_UTIL_LOGGER) {
if (!field.type.equalsToText(Constants.JAVA_UTIL_LOGGER)) {
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ package com.demonwav.mcdev.platform.sponge.inspection
import com.demonwav.mcdev.platform.sponge.util.SpongeConstants
import com.demonwav.mcdev.platform.sponge.util.isValidSpongeListener
import com.demonwav.mcdev.platform.sponge.util.resolveSpongeGetterTarget
import com.demonwav.mcdev.util.isJavaOptional
import com.intellij.codeInspection.AbstractBaseUastLocalInspectionTool
import com.intellij.codeInspection.InspectionManager
import com.intellij.codeInspection.IntentionAndQuickFixAction
Expand All @@ -36,6 +35,7 @@ import com.intellij.lang.jvm.actions.expectedParameter
import com.intellij.lang.jvm.actions.updateMethodParametersRequest
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.project.Project
import com.intellij.psi.CommonClassNames
import com.intellij.psi.JavaPsiFacade
import com.intellij.psi.PsiClassType
import com.intellij.psi.PsiFile
Expand Down Expand Up @@ -126,7 +126,7 @@ class SpongeWrongGetterTypeInspection : AbstractBaseUastLocalInspectionTool() {

private fun isOptional(type: PsiType): Boolean {
val typeClass = type as? PsiClassType ?: return false
return typeClass.isJavaOptional() && typeClass.hasParameters()
return typeClass.equalsToText(CommonClassNames.JAVA_UTIL_OPTIONAL) && typeClass.hasParameters()
}

private fun getFirstGenericType(typeElement: PsiType): PsiType? =
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/platform/velocity/VelocityModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ class VelocityModule(facet: MinecraftFacet) : AbstractModule(facet) {
chosenClass: PsiClass,
chosenName: String,
data: GenerationData?,
): PsiMethod? {
val method = createVoidMethodWithParameterType(project, chosenName, chosenClass) ?: return null
): PsiMethod {
val method = createVoidMethodWithParameterType(project, chosenName, chosenClass)
val modifierList = method.modifierList

val subscribeAnnotation = modifierList.addAnnotation(SUBSCRIBE_ANNOTATION)
Expand Down
Loading

0 comments on commit 07e5f88

Please sign in to comment.