generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: support VarHandle#withInvoke(Exact)Behavior methods (#153)
- Loading branch information
Showing
12 changed files
with
180 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/main/kotlin/de/sirywell/handlehints/mhtype/VarHandleHelper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package de.sirywell.handlehints.mhtype | ||
|
||
import com.intellij.psi.PsiExpression | ||
import com.intellij.psi.PsiMethodCallExpression | ||
import com.intellij.psi.util.parentOfType | ||
import de.sirywell.handlehints.MethodHandleBundle.message | ||
import de.sirywell.handlehints.dfa.SsaAnalyzer | ||
import de.sirywell.handlehints.dfa.SsaConstruction | ||
import de.sirywell.handlehints.inspection.ProblemEmitter | ||
import de.sirywell.handlehints.inspection.RedundantInvocationFix | ||
import de.sirywell.handlehints.type.BotVarHandleType | ||
import de.sirywell.handlehints.type.KnownInvocationBehavior | ||
import de.sirywell.handlehints.type.KnownInvocationBehavior.INVOKE | ||
import de.sirywell.handlehints.type.KnownInvocationBehavior.INVOKE_EXACT | ||
import de.sirywell.handlehints.type.VarHandleType | ||
|
||
class VarHandleHelper(private val ssaAnalyzer: SsaAnalyzer) : ProblemEmitter(ssaAnalyzer.typeData) { | ||
fun withInvokeBehavior(targetExpr: PsiExpression, block: SsaConstruction.Block) : VarHandleType { | ||
return withBehavior(targetExpr, block, INVOKE) | ||
} | ||
|
||
fun withInvokeExactBehavior(targetExpr: PsiExpression, block: SsaConstruction.Block) : VarHandleType { | ||
return withBehavior(targetExpr, block, INVOKE_EXACT) | ||
} | ||
|
||
private fun withBehavior( | ||
targetExpr: PsiExpression, | ||
block: SsaConstruction.Block, | ||
behavior: KnownInvocationBehavior | ||
): VarHandleType { | ||
val varHandleType = ssaAnalyzer.varHandleType(targetExpr, block) ?: BotVarHandleType | ||
val invocationBehavior = varHandleType.invocationBehavior | ||
if (invocationBehavior == behavior) { | ||
emitRedundant( | ||
targetExpr.parentOfType<PsiMethodCallExpression>()!!, | ||
message("problem.transforming.varHandleInvokeBehavior.redundant", behavior.readableName), | ||
RedundantInvocationFix() | ||
) | ||
} | ||
return varHandleType.withInvokeBehavior(behavior) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/test/kotlin/de/sirywell/handlehints/mhtype/VarHandleInspectionsTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package de.sirywell.handlehints.mhtype | ||
|
||
class VarHandleInspectionsTest : TypeAnalysisTestBase() { | ||
|
||
fun testVarHandleWithInvokeBehavior() = doInspectionAndTypeCheckingTest() | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import java.lang.invoke.MethodHandles; | ||
import java.lang.invoke.VarHandle; | ||
|
||
class VarHandleWithInvokeBehavior { | ||
|
||
void invokeBehavior() { | ||
<info descr="(double[],int)(double)">VarHandle vh0 = <info descr="(double[],int)(double)">MethodHandles.arrayElementVarHandle(double[].class)</info>;</info> | ||
// redundant - vh0 has invoke behavior | ||
<info descr="(double[],int)(double)">VarHandle vh1 = <warning descr="VarHandle already has 'invoke' behavior"><info descr="(double[],int)(double)">vh0.withInvokeBehavior()</info></warning>;</info> | ||
// not redundant | ||
<info descr="(double[],int)(double)">VarHandle vh2 = <info descr="(double[],int)(double)">vh0.withInvokeExactBehavior()</info>;</info> | ||
// redundant - vh2 has invokeExact behavior | ||
<info descr="(double[],int)(double)">VarHandle vh3 = <warning descr="VarHandle already has 'invokeExact' behavior"><info descr="(double[],int)(double)">vh2.withInvokeExactBehavior()</info></warning>;</info> | ||
// not redundant | ||
<info descr="(double[],int)(double)">VarHandle vh4 = <info descr="(double[],int)(double)">vh2.withInvokeBehavior()</info>;</info> | ||
} | ||
} |