IG: cleanup and test

This commit is contained in:
Bas Leijdekkers
2018-02-12 17:23:25 +01:00
parent a27993115f
commit ecc75bc485
2 changed files with 45 additions and 15 deletions
@@ -37,15 +37,13 @@ public class UnnecessarySuperConstructorInspection extends BaseInspection implem
@Override
@NotNull
public String getDisplayName() {
return InspectionGadgetsBundle.message(
"unnecessary.super.constructor.display.name");
return InspectionGadgetsBundle.message("unnecessary.super.constructor.display.name");
}
@Override
@NotNull
protected String buildErrorString(Object... infos) {
return InspectionGadgetsBundle.message(
"unnecessary.super.constructor.problem.descriptor");
return InspectionGadgetsBundle.message("unnecessary.super.constructor.problem.descriptor");
}
@Override
@@ -53,14 +51,12 @@ public class UnnecessarySuperConstructorInspection extends BaseInspection implem
return new UnnecessarySuperConstructorFix();
}
private static class UnnecessarySuperConstructorFix
extends InspectionGadgetsFix {
private static class UnnecessarySuperConstructorFix extends InspectionGadgetsFix {
@Override
@NotNull
public String getFamilyName() {
return InspectionGadgetsBundle.message(
"unnecessary.super.constructor.remove.quickfix");
return InspectionGadgetsBundle.message("unnecessary.super.constructor.remove.quickfix");
}
@Override
@@ -77,19 +73,16 @@ public class UnnecessarySuperConstructorInspection extends BaseInspection implem
return new UnnecessarySuperConstructorVisitor();
}
private static class UnnecessarySuperConstructorVisitor
extends BaseInspectionVisitor {
private static class UnnecessarySuperConstructorVisitor extends BaseInspectionVisitor {
@Override
public void visitMethodCallExpression(
@NotNull PsiMethodCallExpression call) {
public void visitMethodCallExpression(@NotNull PsiMethodCallExpression call) {
super.visitMethodCallExpression(call);
PsiReferenceExpression methodExpression = call.getMethodExpression();
final PsiReferenceExpression methodExpression = call.getMethodExpression();
if (methodExpression.isQualified() || !PsiKeyword.SUPER.equals(methodExpression.getReferenceName())) {
return;
}
PsiExpression[] args = call.getArgumentList().getExpressions();
if (args.length != 0) {
if (!call.getArgumentList().isEmpty()) {
return;
}
registerError(call, ProblemHighlightType.LIKE_UNUSED_SYMBOL);
@@ -0,0 +1,37 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.siyeh.ig.style;
import com.intellij.codeInspection.InspectionProfileEntry;
import com.siyeh.ig.LightInspectionTestCase;
import org.jetbrains.annotations.Nullable;
/**
* @author Bas Leijdekkers
*/
public class UnnecessarySuperConstructorInspectionTest extends LightInspectionTestCase {
public void testQualifiedSuper() {
doTest("class Outer {" +
" class Super {}" +
" class Inner extends Super {" +
" Inner(Outer outer) {" +
" outer.super();" +
" }" +
" }" +
"}");
}
public void testSimple() {
doTest("class Simple {" +
" Simple() {" +
" /*'super()' is unnecessary*/super()/**/;" +
" }" +
"}");
}
@Nullable
@Override
protected InspectionProfileEntry getInspection() {
return new UnnecessarySuperConstructorInspection();
}
}