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: inspection on redundant
dropReturn
call (#127)
- Loading branch information
Showing
6 changed files
with
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,17 @@ package de.sirywell.handlehints.inspection | |
|
||
import com.intellij.codeInspection.LocalQuickFix | ||
import com.intellij.codeInspection.ProblemDescriptor | ||
import com.intellij.lang.jvm.JvmModifier | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.psi.PsiMethodCallExpression | ||
import com.siyeh.ig.PsiReplacementUtil | ||
import com.siyeh.ig.psiutils.CommentTracker | ||
import de.sirywell.handlehints.MethodHandleBundle | ||
|
||
/** | ||
* Convert calls of the form Class.method(p0, ..., pn) into p0, | ||
* and calls of the form object.method(p0, ..., pn) into object | ||
*/ | ||
class RedundantInvocationFix : LocalQuickFix { | ||
override fun getFamilyName(): String { | ||
return MethodHandleBundle.message("problem.general.invocation.redundant.remove") | ||
|
@@ -17,9 +22,14 @@ class RedundantInvocationFix : LocalQuickFix { | |
val commentTracker = CommentTracker() | ||
when (val psiElement = descriptor.psiElement) { | ||
is PsiMethodCallExpression -> { | ||
val replacement = if (psiElement.resolveMethod()?.hasModifier(JvmModifier.STATIC) ?: return) { | ||
Check warning on line 25 in src/main/kotlin/de/sirywell/handlehints/inspection/RedundantInvocationFix.kt GitHub Actions / Qodana Community for JVMUnstable API Usage
Check warning on line 25 in src/main/kotlin/de/sirywell/handlehints/inspection/RedundantInvocationFix.kt GitHub Actions / Qodana Community for JVMUnstable API Usage
Check warning on line 25 in src/main/kotlin/de/sirywell/handlehints/inspection/RedundantInvocationFix.kt GitHub Actions / Qodana Community for JVMUnstable API Usage
|
||
psiElement.argumentList.expressions.first() | ||
} else { | ||
psiElement.methodExpression.qualifierExpression | ||
} | ||
PsiReplacementUtil.replaceExpression( | ||
psiElement, | ||
psiElement.methodExpression.qualifierExpression?.text!!, | ||
replacement?.text!!, | ||
commentTracker | ||
) | ||
} | ||
|
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