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 25, 2023
2 parents 07e5f88 + 2e509b4 commit ef3663e
Show file tree
Hide file tree
Showing 21 changed files with 203 additions and 54 deletions.
3 changes: 3 additions & 0 deletions externalAnnotations/net/minecraft/client/annotations.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
<item name="net.minecraft.client.KeyMapping KeyMapping(java.lang.String, com.mojang.blaze3d.platform.InputConstants.Type, int, java.lang.String) 3">
<annotation name="com.demonwav.mcdev.annotations.Translatable"/>
</item>

<!--region Forge -->
<item name="net.minecraft.client.KeyMapping KeyMapping(java.lang.String, net.minecraftforge.client.settings.IKeyConflictContext, com.mojang.blaze3d.platform.InputConstants.Type, int, java.lang.String) 0">
<annotation name="com.demonwav.mcdev.annotations.Translatable"/>
</item>
Expand All @@ -55,4 +57,5 @@
<item name="net.minecraft.client.KeyMapping KeyMapping(java.lang.String, net.minecraftforge.client.settings.IKeyConflictContext, net.minecraftforge.client.settings.KeyModifier, com.mojang.blaze3d.platform.InputConstants.Key, java.lang.String) 4">
<annotation name="com.demonwav.mcdev.annotations.Translatable"/>
</item>
<!--endregion-->
</root>
36 changes: 36 additions & 0 deletions externalAnnotations/net/minecraft/client/option/annotations.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!--
Minecraft Development for IntelliJ
https://mcdev.io/
Copyright (C) 2023 minecraft-dev
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, version 3.0 only.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
-->

<!-- Yarn mappings -->

<root>
<item name="net.minecraft.client.option.KeyBinding KeyBinding(java.lang.String, int, java.lang.String) 0">
<annotation name="com.demonwav.mcdev.annotations.Translatable"/>
</item>
<item name="net.minecraft.client.option.KeyBinding KeyBinding(java.lang.String, int, java.lang.String) 2">
<annotation name="com.demonwav.mcdev.annotations.Translatable"/>
</item>
<item name="net.minecraft.client.option.KeyBinding KeyBinding(java.lang.String, com.mojang.blaze3d.platform.InputConstants.Type, int, java.lang.String) 0">
<annotation name="com.demonwav.mcdev.annotations.Translatable"/>
</item>
<item name="net.minecraft.client.option.KeyBinding KeyBinding(java.lang.String, com.mojang.blaze3d.platform.InputConstants.Type, int, java.lang.String) 3">
<annotation name="com.demonwav.mcdev.annotations.Translatable"/>
</item>
</root>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!--
Minecraft Development for IntelliJ
https://mcdev.io/
Copyright (C) 2023 minecraft-dev
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, version 3.0 only.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
-->

<!-- Yarn mappings -->
<root>
<item name="net.minecraft.client.resource.language.I18n java.lang.String translate(java.lang.String, java.lang.Object...) 0">
<annotation name="com.demonwav.mcdev.annotations.Translatable">
<val name="foldMethod" val="true"/>
</annotation>
</item>
<item name="net.minecraft.client.resource.language.I18n boolean hasTranslation(java.lang.String) 0">
<annotation name="com.demonwav.mcdev.annotations.Translatable"/>
</item>
</root>
50 changes: 50 additions & 0 deletions externalAnnotations/net/minecraft/text/annotations.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<!--
Minecraft Development for IntelliJ
https://mcdev.io/
Copyright (C) 2023 minecraft-dev
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, version 3.0 only.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
-->

<!-- Yarn mappings -->

<root>
<item name="net.minecraft.text.TranslatableText TranslatableText(java.lang.String) 0">
<annotation name="com.demonwav.mcdev.annotations.Translatable">
<val name="foldMethod" val="true"/>
</annotation>
</item>
<item name="net.minecraft.text.TranslatableText TranslatableText(java.lang.String, java.lang.Object...) 0">
<annotation name="com.demonwav.mcdev.annotations.Translatable">
<val name="foldMethod" val="true"/>
</annotation>
</item>
<item name="net.minecraft.text.Text net.minecraft.text.MutableText translatable(java.lang.String) 0">
<annotation name="com.demonwav.mcdev.annotations.Translatable">
<val name="foldMethod" val="true"/>
</annotation>
</item>
<item name="net.minecraft.text.Text net.minecraft.text.MutableText translatable(java.lang.String, java.lang.Object...) 0">
<annotation name="com.demonwav.mcdev.annotations.Translatable">
<val name="foldMethod" val="true"/>
</annotation>
</item>
<item name="net.minecraft.text.Text net.minecraft.text.MutableText translatableWithFallback(java.lang.String, java.lang.String) 0">
<annotation name="com.demonwav.mcdev.annotations.Translatable"/>
</item>
<item name="net.minecraft.text.Text net.minecraft.text.MutableText translatableWithFallback(java.lang.String, java.lang.String, java.lang.Object...) 0">
<annotation name="com.demonwav.mcdev.annotations.Translatable"/>
</item>
</root>
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)
): PsiMethod? {
val newMethod = createVoidMethodWithParameterType(project, chosenName, chosenClass) ?: return null
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)
val method = createVoidMethodWithParameterType(project, chosenName, chosenClass) ?: return null
val modifierList = method.modifierList

if (isFmlEvent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ 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 @@ -117,7 +118,7 @@ class StackEmptyInspection : BaseInspection() {
}

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

private fun isExpressionEmptyConstant(expression: PsiExpression?): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ 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 @@ -96,23 +97,27 @@ class ConfigValueInspection : MixinConfigInspection() {
return true // Idk, it's fine I guess
}

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

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

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

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

private val qualifiedNumberNames = listOf(
private val shortNumberNames = setOf("Byte", "Character", "Double", "Float", "Integer", "Long", "Short")
private val qualifiedNumberNames = setOf(
JAVA_LANG_BYTE,
JAVA_LANG_CHARACTER,
JAVA_LANG_DOUBLE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ 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 @@ -73,7 +74,7 @@ class MixinObjectCastFoldingBuilder : CustomFoldingBuilder() {
}

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

val start = (expression as? CompositeElement)?.findChildByRole(ChildRole.LPARENTH) ?: return
Expand Down
4 changes: 3 additions & 1 deletion src/main/kotlin/platform/mixin/handlers/InvokerHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ 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 @@ -53,7 +55,7 @@ class InvokerHandler : MixinMemberAnnotationHandler {
val name = getInvokerTargetName(annotation, member) ?: return emptyList()
val constructor = name == "<init>"
if (constructor &&
member.returnType?.equalsToText(targetClass.name.replace('/', '.').replace('$', '.')) != true
(member.returnType as? PsiClassType)?.resolve()?.fullQualifiedName?.replace('.', '/') != targetClass.name
) {
return emptyList()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ 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 @@ -57,7 +58,8 @@ class MixinCancellableInspection : MixinInspection() {
val isCancellable = cancellableAttribute.value == true

val ciParam = method.parameterList.parameters.firstOrNull {
it.type.equalsToText(CALLBACK_INFO) || it.type.equalsToText(CALLBACK_INFO_RETURNABLE)
val className = (it.type as? PsiClassType)?.fullQualifiedName ?: return@firstOrNull false
className == CALLBACK_INFO || className == 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,8 +360,11 @@ class InjectCouldBeOverwriteInspection : MixinInspection() {
}

companion object {
private fun isCallbackInfoParam(param: PsiParameter) =
param.type.equalsToText(MixinConstants.Classes.CALLBACK_INFO) ||
param.type.equalsToText(MixinConstants.Classes.CALLBACK_INFO_RETURNABLE)
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
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ 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 @@ -42,6 +43,7 @@ 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 @@ -305,8 +307,9 @@ class InvalidInjectorMethodSignatureInspection : MixinInspection() {
val parameters = descriptor.psiElement as PsiParameterList
// We want to preserve captured locals
val locals = parameters.parameters.dropWhile {
!it.type.equalsToText(MixinConstants.Classes.CALLBACK_INFO) &&
!it.type.equalsToText(MixinConstants.Classes.CALLBACK_INFO_RETURNABLE)
val fqname = (it.type as? PsiClassType)?.fullQualifiedName ?: return@dropWhile true
return@dropWhile fqname != MixinConstants.Classes.CALLBACK_INFO &&
fqname != 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,6 +32,7 @@ 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 @@ -67,7 +68,7 @@ class WrongOperationParametersInspection : MixinInspection() {
val (operationIndex, operationParam) = containingMethod.parameterList.parameters.asSequence()
.withIndex()
.firstOrNull { (_, param) ->
param.type.equalsToText(MixinConstants.MixinExtras.OPERATION)
(param.type as? PsiClassType)?.resolve()?.qualifiedName == MixinConstants.MixinExtras.OPERATION
} ?: return
val (expectedParamTypes, paramNames) = containingMethod.parameterList.parameters.asSequence()
.take(operationIndex)
Expand Down
Loading

0 comments on commit ef3663e

Please sign in to comment.