Skip to content

Commit

Permalink
Add inspection for when @Inject could be @overwrite (#2090)
Browse files Browse the repository at this point in the history
* Add inspection for when @Inject could be @overwrite

* Don't apply @Inject could be @overwrite inspection for optional injects

* Use a walking visitor

* Disable inspection by default
  • Loading branch information
Earthcomputer authored Jul 26, 2023
1 parent b7761aa commit 287e647
Show file tree
Hide file tree
Showing 4 changed files with 415 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
package com.demonwav.mcdev.platform.mixin.handlers.injectionPoint

import com.demonwav.mcdev.platform.mixin.reference.MixinSelector
import com.intellij.codeInsight.daemon.impl.analysis.HighlightControlFlowUtil
import com.demonwav.mcdev.util.hasImplicitReturnStatement
import com.intellij.codeInsight.lookup.LookupElementBuilder
import com.intellij.openapi.project.Project
import com.intellij.psi.JavaPsiFacade
Expand All @@ -37,7 +37,6 @@ import com.intellij.psi.PsiMethodReferenceExpression
import com.intellij.psi.PsiReturnStatement
import com.intellij.psi.PsiType
import com.intellij.psi.controlFlow.AnalysisCanceledException
import com.intellij.psi.controlFlow.ControlFlowUtil
import org.objectweb.asm.Opcodes
import org.objectweb.asm.tree.AbstractInsnNode
import org.objectweb.asm.tree.ClassNode
Expand Down Expand Up @@ -114,13 +113,13 @@ abstract class AbstractReturnInjectionPoint(private val tailOnly: Boolean) : Inj
}

val rBrace = codeBlockToAnalyze.rBrace ?: return
val controlFlow = try {
HighlightControlFlowUtil.getControlFlowNoConstantEvaluate(codeBlockToAnalyze)
val hasImplicitReturnStatement = try {
hasImplicitReturnStatement(codeBlockToAnalyze)
} catch (e: AnalysisCanceledException) {
return
}

if (ControlFlowUtil.canCompleteNormally(controlFlow, 0, controlFlow.size)) {
if (hasImplicitReturnStatement) {
if (tailOnly) {
result.clear()
}
Expand Down
Loading

0 comments on commit 287e647

Please sign in to comment.