Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ats for mojmap #978

Draft
wants to merge 1 commit into
base: 2021.1
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/main/kotlin/platform/mcp/actions/CopyAtAction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ import java.awt.Toolkit
import java.awt.datatransfer.StringSelection

class CopyAtAction : SrgActionBase() {
override fun withSrgTarget(parent: PsiElement, srgMap: McpSrgMap, e: AnActionEvent, data: ActionData) {
override fun withSrgTarget(parent: PsiElement, srgMap: McpSrgMap?, e: AnActionEvent, data: ActionData) {
when (parent) {
is PsiField -> {
val containing = parent.containingClass ?: return showBalloon("No SRG name found", e)
val classSrg = srgMap.getSrgClass(containing) ?: return showBalloon("No SRG name found", e)
val srg = srgMap.getSrgField(parent) ?: return showBalloon("No SRG name found", e)
val classSrg = getSrgClass(srgMap, containing) ?: return showBalloon("No SRG name found", e)
val srg = getSrgField(srgMap, parent) ?: return showBalloon("No SRG name found", e)
copyToClipboard(
data.editor,
data.element,
Expand All @@ -36,16 +36,16 @@ class CopyAtAction : SrgActionBase() {
}
is PsiMethod -> {
val containing = parent.containingClass ?: return showBalloon("No SRG name found", e)
val classSrg = srgMap.getSrgClass(containing) ?: return showBalloon("No SRG name found", e)
val srg = srgMap.getSrgMethod(parent) ?: return showBalloon("No SRG name found", e)
val classSrg = getSrgClass(srgMap, containing) ?: return showBalloon("No SRG name found", e)
val srg = getSrgMethod(srgMap, parent) ?: return showBalloon("No SRG name found", e)
copyToClipboard(
data.editor,
data.element,
classSrg + " " + srg.name + srg.descriptor + " # " + parent.name
)
}
is PsiClass -> {
val classMcpToSrg = srgMap.getSrgClass(parent) ?: return showBalloon("No SRG name found", e)
val classMcpToSrg = getSrgClass(srgMap, parent) ?: return showBalloon("No SRG name found", e)
copyToClipboard(data.editor, data.element, classMcpToSrg)
}
else -> showBalloon("Not a valid element", e)
Expand Down
11 changes: 7 additions & 4 deletions src/main/kotlin/platform/mcp/actions/FindSrgMappingAction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,21 @@ import com.intellij.psi.PsiMethod

class FindSrgMappingAction : SrgActionBase() {

override fun withSrgTarget(parent: PsiElement, srgMap: McpSrgMap, e: AnActionEvent, data: ActionData) {
override fun withSrgTarget(parent: PsiElement, srgMap: McpSrgMap?, e: AnActionEvent, data: ActionData) {
if (srgMap == null) {
return showBalloon("No mappings found", e)
}
when (parent) {
is PsiField -> {
val srg = srgMap.getSrgField(parent) ?: return showBalloon("No SRG name found", e)
val srg = getSrgField(srgMap, parent) ?: return showBalloon("No SRG name found", e)
showSuccessBalloon(data.editor, data.element, "SRG name: " + srg.name)
}
is PsiMethod -> {
val srg = srgMap.getSrgMethod(parent) ?: return showBalloon("No SRG name found", e)
val srg = getSrgMethod(srgMap, parent) ?: return showBalloon("No SRG name found", e)
showSuccessBalloon(data.editor, data.element, "SRG name: " + srg.name + srg.descriptor)
}
is PsiClass -> {
val classMcpToSrg = srgMap.getSrgClass(parent) ?: return showBalloon("No SRG name found", e)
val classMcpToSrg = getSrgClass(srgMap, parent) ?: return showBalloon("No SRG name found", e)
showSuccessBalloon(data.editor, data.element, "SRG name: " + classMcpToSrg)
}
else -> showBalloon("Not a valid element", e)
Expand Down
57 changes: 17 additions & 40 deletions src/main/kotlin/platform/mcp/actions/GotoAtEntryAction.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,72 +12,49 @@ package com.demonwav.mcdev.platform.mcp.actions

import com.demonwav.mcdev.facet.MinecraftFacet
import com.demonwav.mcdev.platform.mcp.McpModuleType
import com.demonwav.mcdev.platform.mcp.srg.SrgManager
import com.demonwav.mcdev.platform.mixin.util.findFirstShadowTarget
import com.demonwav.mcdev.platform.mcp.srg.McpSrgMap
import com.demonwav.mcdev.util.ActionData
import com.demonwav.mcdev.util.getDataFromActionEvent
import com.demonwav.mcdev.util.gotoTargetElement
import com.demonwav.mcdev.util.invokeLater
import com.demonwav.mcdev.util.qualifiedMemberReference
import com.demonwav.mcdev.util.simpleQualifiedMemberReference
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.module.ModuleManager
import com.intellij.openapi.ui.popup.Balloon
import com.intellij.openapi.ui.popup.JBPopupFactory
import com.intellij.openapi.wm.WindowManager
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiField
import com.intellij.psi.PsiIdentifier
import com.intellij.psi.PsiManager
import com.intellij.psi.PsiMember
import com.intellij.psi.PsiMethod
import com.intellij.psi.search.LocalSearchScope
import com.intellij.psi.search.PsiSearchHelper
import com.intellij.psi.search.UsageSearchContext
import com.intellij.ui.LightColors
import com.intellij.ui.awt.RelativePoint

class GotoAtEntryAction : AnAction() {
override fun actionPerformed(e: AnActionEvent) {
val data = getDataFromActionEvent(e) ?: return showBalloon(e)

if (data.element !is PsiIdentifier) {
showBalloon(e)
return
}

val srgManager = data.instance.getModuleOfType(McpModuleType)?.srgManager
// Not all ATs are in MCP modules, fallback to this if possible
// TODO try to find SRG references for all modules if current module isn't found?
?: SrgManager.findAnyInstance(data.project) ?: return showBalloon(e)

srgManager.srgMap.onSuccess { srgMap ->
var parent = data.element.parent

if (parent is PsiMember) {
val shadowTarget = parent.findFirstShadowTarget()?.element
if (shadowTarget != null) {
parent = shadowTarget
}
class GotoAtEntryAction : SrgActionBase() {
override fun withSrgTarget(parent: PsiElement, srgMap: McpSrgMap?, e: AnActionEvent, data: ActionData) {
when (parent) {
is PsiField -> {
val reference = getSrgField(srgMap, parent) ?: parent.simpleQualifiedMemberReference
searchForText(e, data, reference.name)
}

when (parent) {
is PsiField -> {
val reference = srgMap.getSrgField(parent) ?: parent.simpleQualifiedMemberReference
searchForText(e, data, reference.name)
}
is PsiMethod -> {
val reference = srgMap.getSrgMethod(parent) ?: parent.qualifiedMemberReference
searchForText(e, data, reference.name + reference.descriptor)
}
else ->
showBalloon(e)
is PsiMethod -> {
val reference = getSrgMethod(srgMap, parent) ?: parent.qualifiedMemberReference
searchForText(e, data, reference.name + reference.descriptor)
}
else ->
showBalloon(e)
}
}

private fun searchForText(e: AnActionEvent, data: ActionData, text: String) {
val manager = ModuleManager.getInstance(data.project)
val toList = manager.modules.asSequence()
.mapNotNull { MinecraftFacet.getInstance(it, McpModuleType) }
.toList()

manager.modules.asSequence()
.mapNotNull { MinecraftFacet.getInstance(it, McpModuleType) }
.flatMap { it.accessTransformers.asSequence() }
Expand Down
69 changes: 53 additions & 16 deletions src/main/kotlin/platform/mcp/actions/SrgActionBase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,26 @@ package com.demonwav.mcdev.platform.mcp.actions

import com.demonwav.mcdev.platform.mcp.McpModuleType
import com.demonwav.mcdev.platform.mcp.srg.McpSrgMap
import com.demonwav.mcdev.platform.mcp.srg.SrgManager
import com.demonwav.mcdev.platform.mixin.util.findFirstShadowTarget
import com.demonwav.mcdev.util.ActionData
import com.demonwav.mcdev.util.MemberReference
import com.demonwav.mcdev.util.fullQualifiedName
import com.demonwav.mcdev.util.getDataFromActionEvent
import com.demonwav.mcdev.util.invokeLater
import com.demonwav.mcdev.util.qualifiedMemberReference
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.ui.popup.Balloon
import com.intellij.openapi.ui.popup.JBPopupFactory
import com.intellij.openapi.wm.WindowManager
import com.intellij.psi.PsiClass
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiField
import com.intellij.psi.PsiIdentifier
import com.intellij.psi.PsiMember
import com.intellij.psi.PsiMethod
import com.intellij.psi.PsiReference
import com.intellij.ui.LightColors
import com.intellij.ui.awt.RelativePoint
Expand All @@ -39,29 +46,59 @@ abstract class SrgActionBase : AnAction() {
return
}

val mcpModule = data.instance.getModuleOfType(McpModuleType) ?: return showBalloon("No mappings found", e)
var parent = data.element.parent ?: return showBalloon("Not a valid element", e)

mcpModule.srgManager?.srgMap?.onSuccess { srgMap ->
var parent = data.element.parent

if (parent is PsiMember) {
val shadowTarget = parent.findFirstShadowTarget()?.element
if (shadowTarget != null) {
parent = shadowTarget
}
if (parent is PsiMember) {
val shadowTarget = parent.findFirstShadowTarget()?.element
if (shadowTarget != null) {
parent = shadowTarget
}
}

if (parent is PsiReference) {
parent = parent.resolve() ?: return showBalloon("Not a valid element", e)
}

if (parent is PsiReference) {
parent = parent.resolve()
val srgManager = data.instance.getModuleOfType(McpModuleType)?.srgManager
// Not all ATs are in MCP modules, fallback to this if possible
// TODO try to find SRG references for all modules if current module isn't found?
?: SrgManager.findAnyInstance(data.project)
if (srgManager == null) {
withSrgTarget(parent, null, e, data)
} else {
srgManager.srgMap.onSuccess { srgMap ->
withSrgTarget(parent, srgMap, e, data)
}.onError {
showBalloon(it.message ?: "No MCP data available", e)
}
}
}

abstract fun withSrgTarget(parent: PsiElement, srgMap: McpSrgMap?, e: AnActionEvent, data: ActionData)

withSrgTarget(parent, srgMap, e, data)
}?.onError {
showBalloon(it.message ?: "No MCP data available", e)
} ?: showBalloon("No mappings found", e)
protected fun getSrgClass(srgMap: McpSrgMap?, clazz: PsiClass): String? {
return if (srgMap != null) {
srgMap.getSrgClass(clazz)
} else {
clazz.fullQualifiedName
}
}

protected fun getSrgMethod(srgMap: McpSrgMap?, element: PsiMethod): MemberReference? {
return if (srgMap != null) {
srgMap.getSrgMethod(element)
} else {
element.qualifiedMemberReference
}
}

abstract fun withSrgTarget(parent: PsiElement, srgMap: McpSrgMap, e: AnActionEvent, data: ActionData)
protected fun getSrgField(srgMap: McpSrgMap?, element: PsiField): MemberReference? {
return if (srgMap != null) {
srgMap.getSrgField(element)
} else {
element.qualifiedMemberReference
}
}

protected fun showBalloon(message: String, e: AnActionEvent) {
val balloon = JBPopupFactory.getInstance()
Expand Down
36 changes: 17 additions & 19 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
</change-notes>

<!-- please see https://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/build_number_ranges.html for description -->
<idea-version since-build="211.4961.33" until-build="211.*"/>
<idea-version since-build="201.6668" until-build="201.*"/>

<extensions defaultExtensionNs="com.intellij">
<!-- This is grouped in the following order EXCEPT for localInspections and moduleTypes. All localInspections are grouped at the
Expand Down Expand Up @@ -65,11 +65,11 @@
<!-- Project-independent Line Marker Providers -->
<codeInsight.lineMarkerProvider language="" implementationClass="com.demonwav.mcdev.insight.ListenerLineMarkerProvider"/>
<codeInsight.lineMarkerProvider language="" implementationClass="com.demonwav.mcdev.insight.ColorLineMarkerProvider"/>
<codeInsight.lineMarkerProvider language="" implementationClass="com.demonwav.mcdev.insight.PluginLineMarkerProvider"/>
<codeInsight.lineMarkerProvider language="JAVA" implementationClass="com.demonwav.mcdev.insight.PluginLineMarkerProvider"/>

<!-- Project-independent Annotators-->
<annotator language="UAST" implementationClass="com.demonwav.mcdev.insight.ListenerEventAnnotator"/>
<annotator language="UAST" implementationClass="com.demonwav.mcdev.insight.ColorAnnotator"/>
<annotator language="JAVA" implementationClass="com.demonwav.mcdev.insight.ListenerEventAnnotator"/>
<annotator language="JAVA" implementationClass="com.demonwav.mcdev.insight.ColorAnnotator"/>

<!-- Project-independent Inspection Suppressors -->
<lang.inspectionSuppressor language="JAVA" implementationClass="com.demonwav.mcdev.inspection.StaticListenerInspectionSuppressor"/>
Expand Down Expand Up @@ -171,25 +171,23 @@
<!---->

<!-- Sponge Line Marker Provider -->
<codeInsight.lineMarkerProvider language=""
implementationClass="com.demonwav.mcdev.platform.sponge.color.SpongeColorLineMarkerProvider"/>
<codeInsight.lineMarkerProvider language="" implementationClass="com.demonwav.mcdev.platform.sponge.color.SpongeColorLineMarkerProvider"/>

<implicitUsageProvider implementation="com.demonwav.mcdev.platform.sponge.insight.SpongeImplicitUsageProvider"/>
<implicitUsageProvider implementation="com.demonwav.mcdev.platform.sponge.insight.SpongeImplicitUsageProvider" />

<!-- Sponge Annotator -->
<annotator language="UAST" implementationClass="com.demonwav.mcdev.platform.sponge.color.SpongeColorAnnotator"/>
<annotator language="JAVA" implementationClass="com.demonwav.mcdev.platform.sponge.color.SpongeColorAnnotator"/>

<psi.referenceContributor language="UAST"
implementation="com.demonwav.mcdev.platform.sponge.reference.SpongeReferenceContributor"/>
<completion.contributor language="JAVA" implementationClass="com.demonwav.mcdev.platform.sponge.completion.SpongeGetterFilterCompletionContributor" />
<psi.referenceContributor language="JAVA" implementation="com.demonwav.mcdev.platform.sponge.reference.SpongeReferenceContributor" />
<completion.confidence language="JAVA" implementationClass="com.demonwav.mcdev.platform.sponge.completion.SpongeCompletionConfidence"
order="before javaSkipAutopopupInStrings" />

<library.presentationProvider
implementation="com.demonwav.mcdev.platform.sponge.framework.SpongePresentationProvider"/>
<importFilter implementation="com.demonwav.mcdev.platform.sponge.SpongeImportFilter"/>
<library.presentationProvider implementation="com.demonwav.mcdev.platform.sponge.framework.SpongePresentationProvider" />
<importFilter implementation="com.demonwav.mcdev.platform.sponge.SpongeImportFilter" />

<lang.inspectionSuppressor language="JAVA"
implementationClass="com.demonwav.mcdev.platform.sponge.inspection.suppress.SpongeGetterParamOptionalInspectionSuppressor"/>
<daemon.highlightInfoFilter
implementation="com.demonwav.mcdev.platform.sponge.codeInsight.highlighting.SpongeGetterFilterInfoFilter"/>
<lang.inspectionSuppressor language="JAVA" implementationClass="com.demonwav.mcdev.platform.sponge.inspection.suppress.SpongeGetterParamOptionalInspectionSuppressor" />
<daemon.highlightInfoFilter implementation="com.demonwav.mcdev.platform.sponge.codeInsight.highlighting.SpongeGetterFilterInfoFilter" />
<!--endregion-->

<!--region FORGE-->
Expand Down Expand Up @@ -362,14 +360,14 @@

<localInspection displayName="@Getter targeted method does not exist"
groupName="Sponge"
language="UAST"
language="JAVA"
enabledByDefault="true"
level="ERROR"
hasStaticDescription="true"
implementationClass="com.demonwav.mcdev.platform.sponge.inspection.SpongeInvalidGetterTargetInspection"/>
<localInspection displayName="Parameter's type is not assignable to its @Getter method return type"
groupName="Sponge"
language="UAST"
language="JAVA"
enabledByDefault="true"
level="ERROR"
hasStaticDescription="true"
Expand Down