StringConcatenationInLoopsInspection: explicit getID(); checkExpression: type parameter removed; cosmetics (IDEA-CR-16590)

This commit is contained in:
Tagir Valeev
2017-01-10 11:47:54 +07:00
parent 3738e54fee
commit e52016be53
2 changed files with 15 additions and 19 deletions
@@ -52,6 +52,13 @@ public class StringConcatenationInLoopsInspection extends BaseInspection {
return InspectionGadgetsBundle.message("string.concatenation.in.loops.display.name");
}
@org.intellij.lang.annotations.Pattern(VALID_ID_PATTERN)
@NotNull
@Override
public String getID() {
return "StringConcatenationInLoop";
}
@Override
@NotNull
protected String buildErrorString(Object... infos) {
@@ -75,7 +82,7 @@ public class StringConcatenationInLoopsInspection extends BaseInspection {
final IElementType tokenType = expression.getOperationTokenType();
if (!tokenType.equals(JavaTokenType.PLUS)) return;
if (!checkExpression(expression, expression.getType())) return;
if (!checkExpression(expression)) return;
if (ExpressionUtils.isEvaluatedAtCompileTime(expression)) return;
@@ -95,19 +102,16 @@ public class StringConcatenationInLoopsInspection extends BaseInspection {
if (!tokenType.equals(JavaTokenType.PLUSEQ)) return;
PsiExpression lhs = expression.getLExpression();
if (!checkExpression(expression)) return;
if (!checkExpression(expression, lhs.getType())) return;
PsiExpression lhs = PsiUtil.skipParenthesizedExprDown(expression.getLExpression());
lhs = PsiUtil.skipParenthesizedExprDown(lhs);
if (!(lhs instanceof PsiReferenceExpression)) {
return;
}
if (!(lhs instanceof PsiReferenceExpression)) return;
registerError(sign, getAppendedVariable(expression));
}
private boolean checkExpression(PsiExpression expression, PsiType type) {
if (!TypeUtils.isJavaLangString(type) || ControlFlowUtils.isInExitStatement(expression) ||
private boolean checkExpression(PsiExpression expression) {
if (!TypeUtils.isJavaLangString(expression.getType()) || ControlFlowUtils.isInExitStatement(expression) ||
!ControlFlowUtils.isInLoop(expression)) return false;
PsiElement parent = expression;
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,7 +16,6 @@
package com.siyeh.ig.performance;
import com.intellij.codeInsight.daemon.quickFix.LightQuickFixParameterizedTestCase;
import com.intellij.codeInspection.LocalInspectionEP;
import com.intellij.codeInspection.LocalInspectionTool;
import org.jetbrains.annotations.NotNull;
@@ -24,14 +23,7 @@ public class StringConcatenationInLoopsInspectionFixTest extends LightQuickFixPa
@NotNull
@Override
protected LocalInspectionTool[] configureLocalInspectionTools() {
// Instantiation via LocalInspectionEP is necessary as tool ID lacks ending -s (shortName is StringConcatenationInLoop)
// which results in error when registering suppress actions
LocalInspectionEP ep = new LocalInspectionEP();
ep.id = "StringConcatenationInLoop";
ep.implementationClass = StringConcatenationInLoopsInspection.class.getName();
LocalInspectionTool tool = (LocalInspectionTool)ep.instantiateTool();
return new LocalInspectionTool[]{tool};
return new LocalInspectionTool[]{new StringConcatenationInLoopsInspection()};
}
public void test() throws Exception { doAllTests(); }