mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[groovy] unnecessary def: offer to remove modifier when other
modifiers are present even if there are generics
This commit is contained in:
+5
-4
@@ -25,12 +25,13 @@ import org.jetbrains.plugins.groovy.codeInspection.GroovyInspectionBundle;
|
||||
import org.jetbrains.plugins.groovy.codeInspection.GroovySuppressableInspectionTool;
|
||||
import org.jetbrains.plugins.groovy.codeInspection.bugs.GrModifierFix;
|
||||
import org.jetbrains.plugins.groovy.codeInspection.bugs.GrRemoveModifierFix;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifier;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtilKt;
|
||||
|
||||
public class GrUnnecessaryDefModifierInspection extends GroovySuppressableInspectionTool implements CleanupLocalInspectionTool{
|
||||
import static org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes.kDEF;
|
||||
|
||||
public class GrUnnecessaryDefModifierInspection extends GroovySuppressableInspectionTool implements CleanupLocalInspectionTool {
|
||||
|
||||
private static final GrModifierFix FIX = new GrRemoveModifierFix(GrModifier.DEF);
|
||||
|
||||
@@ -40,13 +41,13 @@ public class GrUnnecessaryDefModifierInspection extends GroovySuppressableInspec
|
||||
return new PsiElementVisitor() {
|
||||
@Override
|
||||
public void visitElement(PsiElement modifier) {
|
||||
if (modifier.getNode().getElementType() != GroovyTokenTypes.kDEF) return;
|
||||
if (modifier.getNode().getElementType() != kDEF) return;
|
||||
|
||||
PsiElement list = modifier.getParent();
|
||||
if (!(list instanceof GrModifierList)) return;
|
||||
|
||||
PsiElement owner = list.getParent();
|
||||
if (!PsiUtilKt.modifierListMayBeEmpty(owner)) return;
|
||||
if (!PsiUtilKt.modifierListMayBeEmpty(owner) && !PsiUtilKt.hasOtherModifiers((GrModifierList)list, kDEF)) return;
|
||||
|
||||
holder.registerProblem(
|
||||
modifier,
|
||||
|
||||
@@ -16,7 +16,9 @@
|
||||
package org.jetbrains.plugins.groovy.lang.psi.util
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.tree.IElementType
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes.mCOLON
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariableDeclaration
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.clauses.GrForInClause
|
||||
@@ -46,3 +48,7 @@ fun modifierListMayBeEmpty(owner: PsiElement?): Boolean = when (owner) {
|
||||
is GrVariableDeclaration -> owner.typeElementGroovy != null
|
||||
else -> true
|
||||
}
|
||||
|
||||
fun GrModifierList.hasOtherModifiers(modifierElementType: IElementType): Boolean {
|
||||
return modifiers.any { it.node.elementType != modifierElementType }
|
||||
}
|
||||
|
||||
+4
@@ -37,6 +37,8 @@ def baw(<warning descr="Modifier 'def' is not necessary">def</warning> a) {}
|
||||
|
||||
def <T> T bax() {}
|
||||
|
||||
synchronized <warning descr="Modifier 'def' is not necessary">def</warning> <T> T baxx(Class<T> c) {}
|
||||
|
||||
<warning descr="Modifier 'def' is not necessary">def</warning> Object bar
|
||||
|
||||
def baf
|
||||
@@ -64,6 +66,8 @@ boolean baz(a) {}
|
||||
|
||||
def <T> T bax() {}
|
||||
|
||||
synchronized <T> T baxx(Class<T> c) {}
|
||||
|
||||
Object bar
|
||||
|
||||
def baf
|
||||
|
||||
Reference in New Issue
Block a user