-
Notifications
You must be signed in to change notification settings - Fork 380
/
RemoveAssocTypeBindingFix.kt
40 lines (33 loc) · 1.37 KB
/
RemoveAssocTypeBindingFix.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
* Use of this source code is governed by the MIT license that can be
* found in the LICENSE file.
*/
package org.rust.ide.inspections.fixes
import com.intellij.codeInspection.LocalQuickFixOnPsiElement
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile
import com.intellij.psi.util.elementType
import org.rust.lang.core.psi.RsAssocTypeBinding
import org.rust.lang.core.psi.RsElementTypes.COMMA
import org.rust.lang.core.psi.RsTypeArgumentList
import org.rust.lang.core.psi.ext.getNextNonCommentSibling
class RemoveAssocTypeBindingFix(binding: PsiElement) : LocalQuickFixOnPsiElement(binding) {
override fun getFamilyName(): String = text
override fun getText(): String = "Remove redundant associated type"
override fun invoke(project: Project, file: PsiFile, startElement: PsiElement, endElement: PsiElement) {
val binding = startElement as? RsAssocTypeBinding ?: return
val parent = binding.parent as? RsTypeArgumentList
val next = binding.getNextNonCommentSibling()
binding.delete()
if (next?.elementType == COMMA) {
next?.delete()
}
if (parent != null &&
parent.typeReferenceList.isEmpty() &&
parent.assocTypeBindingList.isEmpty() &&
parent.lifetimeList.isEmpty()) {
parent.delete()
}
}
}