Permalink
Please
sign in to comment.
Showing
with
62 additions
and 0 deletions.
- +38 −0 src/main/kotlin/org/rust/ide/inspections/RustAnonParamInspection.kt
- +3 −0 src/main/kotlin/org/rust/lang/core/psi/RustElementFactory.kt
- +5 −0 src/main/resources/META-INF/plugin.xml
- +7 −0 src/test/kotlin/org/rust/ide/inspections/RustInspectionsTest.kt
- +3 −0 src/test/resources/org/rust/ide/inspections/fixtures/anon_param.rs
- +3 −0 src/test/resources/org/rust/ide/inspections/fixtures/anon_param_fix.rs
- +3 −0 src/test/resources/org/rust/ide/inspections/fixtures/anon_param_fix_after.rs
| @@ -0,0 +1,38 @@ | |||
| package org.rust.ide.inspections | |||
|
|
|||
| import com.intellij.codeInspection.LocalQuickFix | |||
| import com.intellij.codeInspection.ProblemDescriptor | |||
| import com.intellij.codeInspection.ProblemHighlightType | |||
| import com.intellij.codeInspection.ProblemsHolder | |||
| import com.intellij.openapi.project.Project | |||
| import com.intellij.psi.PsiElementVisitor | |||
| import org.rust.lang.core.psi.RustElementFactory | |||
| import org.rust.lang.core.psi.RustElementVisitor | |||
| import org.rust.lang.core.psi.RustParameterElement | |||
| import org.rust.lang.core.psi.RustTraitMethodMemberElement | |||
|
|
|||
| class RustAnonParamInspection : RustLocalInspectionTool() { | |||
|
|
|||
| override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor { | |||
| return object : RustElementVisitor() { | |||
| override fun visitTraitMethodMember(o: RustTraitMethodMemberElement) { | |||
| for (param in o.parameters?.parameterList.orEmpty()) { | |||
| if (param.pat == null) { | |||
| holder.registerProblem(param, "Anonymous trait method parameter", object : LocalQuickFix { | |||
| override fun getName(): String = "Add parameter pattern" | |||
|
|
|||
| override fun getFamilyName(): String = name | |||
|
|
|||
| override fun applyFix(project: Project, descriptor: ProblemDescriptor) { | |||
| val p = descriptor.startElement as RustParameterElement | |||
| check(p.pat == null && p.type != null) | |||
| p.replace(RustElementFactory.paramWithPattern(project, p)) | |||
| } | |||
| }) | |||
| } | |||
| } | |||
| } | |||
| } | |||
| } | |||
| } | |||
|
|
|||
| @@ -0,0 +1,3 @@ | |||
| trait T { | |||
| fn foo(<warning>i32</warning>, <warning>String</warning>); | |||
| } | |||
| @@ -0,0 +1,3 @@ | |||
| trait T { | |||
| fn foo(<caret>i32); | |||
| } | |||
| @@ -0,0 +1,3 @@ | |||
| trait T { | |||
| fn foo(_: i32); | |||
| } | |||
0 comments on commit
28c5b94