-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add Move2OnlyInspection * move move2 only inspections to its own package * replace with method call is move2only * cleanup
- Loading branch information
Showing
8 changed files
with
107 additions
and
91 deletions.
There are no files selected for viewing
51 changes: 0 additions & 51 deletions
51
src/main/kotlin/org/move/ide/inspections/MvReplaceWithMethodCallInspection.kt
This file was deleted.
Oops, something went wrong.
28 changes: 28 additions & 0 deletions
28
src/main/kotlin/org/move/ide/inspections/compilerV2/Move2OnlyInspectionBase.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,28 @@ | ||
package org.move.ide.inspections.compilerV2 | ||
|
||
import com.intellij.codeInspection.ProblemsHolder | ||
import org.move.cli.settings.moveSettings | ||
import org.move.ide.inspections.MvLocalInspectionTool | ||
import org.move.lang.core.psi.MvElement | ||
import org.move.lang.core.psi.MvVisitor | ||
|
||
abstract class Move2OnlyInspectionBase<TElement: MvElement>( | ||
val elementClass: Class<TElement> | ||
): MvLocalInspectionTool() { | ||
|
||
override fun buildMvVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): MvVisitor = | ||
object: MvVisitor() { | ||
override fun visitElement(o: MvElement) { | ||
super.visitElement(o) | ||
if (!elementClass.isInstance(o) || o.textLength == 0) return | ||
|
||
// disable for move v1 | ||
if (!o.project.moveSettings.enableMove2) return | ||
|
||
@Suppress("UNCHECKED_CAST") | ||
visitTargetElement(o as TElement, holder, isOnTheFly) | ||
} | ||
} | ||
|
||
abstract fun visitTargetElement(element: TElement, holder: ProblemsHolder, isOnTheFly: Boolean) | ||
} |
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
48 changes: 48 additions & 0 deletions
48
src/main/kotlin/org/move/ide/inspections/compilerV2/MvReplaceWithMethodCallInspection.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,48 @@ | ||
package org.move.ide.inspections.compilerV2 | ||
|
||
import com.intellij.codeInspection.ProblemHighlightType | ||
import com.intellij.codeInspection.ProblemsHolder | ||
import org.move.ide.inspections.compilerV2.fixes.ReplaceWithMethodCallFix | ||
import org.move.lang.core.psi.* | ||
import org.move.lang.core.psi.ext.isMsl | ||
import org.move.lang.core.psi.ext.itemModule | ||
import org.move.lang.core.psi.ext.valueArguments | ||
import org.move.lang.core.types.infer.deepFoldTyTypeParameterWith | ||
import org.move.lang.core.types.infer.inference | ||
import org.move.lang.core.types.ty.TyInfer | ||
import org.move.lang.core.types.ty.TyReference.Companion.isCompatibleWithAutoborrow | ||
import org.move.lang.core.types.ty.hasTyUnknown | ||
import org.move.lang.moveProject | ||
|
||
class MvReplaceWithMethodCallInspection: | ||
Move2OnlyInspectionBase<MvCallExpr>(MvCallExpr::class.java) { | ||
|
||
override fun visitTargetElement(element: MvCallExpr, holder: ProblemsHolder, isOnTheFly: Boolean) { | ||
val function = element.path.reference?.resolveFollowingAliases() as? MvFunction ?: return | ||
val msl = element.isMsl() | ||
val inference = element.inference(msl) ?: return | ||
|
||
val firstArgExpr = element.valueArguments.firstOrNull()?.expr ?: return | ||
val firstArgExprTy = inference.getExprType(firstArgExpr) | ||
if (firstArgExprTy.hasTyUnknown) return | ||
|
||
val moveProject = element.moveProject ?: return | ||
val methodModule = function.module ?: return | ||
val itemModule = firstArgExprTy.itemModule(moveProject) ?: return | ||
if (methodModule != itemModule) return | ||
|
||
val selfTy = function.selfParamTy(msl) | ||
?.deepFoldTyTypeParameterWith { TyInfer.TyVar(it) } ?: return | ||
if (selfTy.hasTyUnknown) return | ||
|
||
if (isCompatibleWithAutoborrow(firstArgExprTy, selfTy, msl)) { | ||
// can be converted | ||
holder.registerProblem( | ||
element, | ||
"Can be replaced with method call", | ||
ProblemHighlightType.WEAK_WARNING, | ||
ReplaceWithMethodCallFix(element) | ||
) | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...ections/fixes/ReplaceWithMethodCallFix.kt → ...pilerV2/fixes/ReplaceWithMethodCallFix.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
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
1 change: 0 additions & 1 deletion
1
...otlin/org/move/ide/inspections/compilerV2/MvReplaceWithMethodCallInspectionProjectTest.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
1 change: 0 additions & 1 deletion
1
src/test/kotlin/org/move/ide/inspections/compilerV2/ReplaceWithMethodCallInspectionTest.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