mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fix CCE and cleanup
This commit is contained in:
@@ -1974,7 +1974,7 @@ externalizable.without.public.no.arg.constructor.problem.descriptor=Externalizab
|
||||
make.constructor.public=Make constructor 'public'
|
||||
string.concatenation.missing.whitespace.display.name=String literal concatenation missing whitespace
|
||||
string.concatenation.missing.whitespace.problem.descriptor=String literal concatenation missing whitespace #loc
|
||||
string.concatenation.missing.whitespace.option=Ignore when not both sides are string literals
|
||||
string.concatenation.missing.whitespace.option=Ignore when one or both sides are not string literals
|
||||
negated.equality.expression.display.name=Negated equality expression
|
||||
negated.equality.expression.problem.descriptor=Negating ''{0}'' #loc
|
||||
negated.equality.expression.quickfix=Remove negation
|
||||
|
||||
+12
-15
@@ -21,7 +21,7 @@ import com.intellij.psi.tree.IElementType;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.psiutils.ParenthesesUtils;
|
||||
import com.siyeh.ig.psiutils.ExpressionUtils;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -83,9 +83,11 @@ public class StringConcatenationMissingWhitespaceInspection extends BaseInspecti
|
||||
}
|
||||
|
||||
private boolean isMissingWhitespace(PsiExpression lhs, PsiExpression rhs) {
|
||||
if (isLiteral(lhs) && hasStringType(lhs)) {
|
||||
final PsiLiteralExpression literalExpression = (PsiLiteralExpression)lhs;
|
||||
final String value = (String)literalExpression.getValue();
|
||||
final boolean lhsIsString = hasStringType(lhs);
|
||||
final PsiLiteralExpression lhsLiteral = ExpressionUtils.getLiteral(lhs);
|
||||
final PsiLiteralExpression rhsLiteral = ExpressionUtils.getLiteral(rhs);
|
||||
if (lhsLiteral != null && lhsIsString) {
|
||||
final String value = (String)lhsLiteral.getValue();
|
||||
if (value == null) {
|
||||
return false;
|
||||
}
|
||||
@@ -98,13 +100,13 @@ public class StringConcatenationMissingWhitespaceInspection extends BaseInspecti
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (ignoreNonStringLiterals || !isLiteral(rhs) || hasStringType(lhs)) {
|
||||
else if (ignoreNonStringLiterals || rhsLiteral == null || lhsIsString) {
|
||||
return false;
|
||||
}
|
||||
if (isLiteral(rhs) && hasStringType(rhs)) {
|
||||
final PsiLiteralExpression literalExpression = (PsiLiteralExpression)rhs;
|
||||
final String value = (String)literalExpression.getValue();
|
||||
if ((value == null) || (value.length() == 0)) {
|
||||
final boolean rhsIsString = hasStringType(rhs);
|
||||
if (rhsLiteral != null && rhsIsString) {
|
||||
final String value = (String)rhsLiteral.getValue();
|
||||
if ((value == null) || value.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
final char c = value.charAt(0);
|
||||
@@ -112,17 +114,12 @@ public class StringConcatenationMissingWhitespaceInspection extends BaseInspecti
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (ignoreNonStringLiterals || hasStringType(rhs)) {
|
||||
else if (ignoreNonStringLiterals || rhsIsString) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isLiteral(PsiExpression expression) {
|
||||
expression = ParenthesesUtils.stripParentheses(expression);
|
||||
return expression instanceof PsiLiteralExpression;
|
||||
}
|
||||
|
||||
private boolean hasStringType(PsiExpression expression) {
|
||||
final PsiType type = expression.getType();
|
||||
return (type != null) && type.equalsToText(CommonClassNames.JAVA_LANG_STRING);
|
||||
|
||||
@@ -26,14 +26,15 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class ExpressionUtils {
|
||||
|
||||
private ExpressionUtils() {
|
||||
}
|
||||
private ExpressionUtils() {}
|
||||
|
||||
@Nullable
|
||||
public static Object computeConstantExpression(
|
||||
@Nullable PsiExpression expression) {
|
||||
return computeConstantExpression(expression, false);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Object computeConstantExpression(
|
||||
@Nullable PsiExpression expression,
|
||||
boolean throwConstantEvaluationOverflowException) {
|
||||
@@ -161,6 +162,27 @@ public class ExpressionUtils {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static PsiLiteralExpression getLiteral(@Nullable PsiExpression expression) {
|
||||
expression = ParenthesesUtils.stripParentheses(expression);
|
||||
if (expression instanceof PsiLiteralExpression) {
|
||||
return (PsiLiteralExpression)expression;
|
||||
}
|
||||
if (!(expression instanceof PsiTypeCastExpression)) {
|
||||
return null;
|
||||
}
|
||||
final PsiTypeCastExpression typeCastExpression = (PsiTypeCastExpression)expression;
|
||||
final PsiExpression operand = ParenthesesUtils.stripParentheses(typeCastExpression.getOperand());
|
||||
if (!(operand instanceof PsiTypeCastExpression)) {
|
||||
return null;
|
||||
}
|
||||
return (PsiLiteralExpression)operand;
|
||||
}
|
||||
|
||||
public static boolean isLiteral(@Nullable PsiExpression expression) {
|
||||
return getLiteral(expression) != null;
|
||||
}
|
||||
|
||||
public static boolean isEmptyStringLiteral(@Nullable PsiExpression expression) {
|
||||
expression = ParenthesesUtils.stripParentheses(expression);
|
||||
if (!(expression instanceof PsiLiteralExpression)) {
|
||||
|
||||
+1
@@ -7,5 +7,6 @@ class Concatenations {
|
||||
"FROM table");
|
||||
System.out.println("no:" + i);
|
||||
System.out.println("i" + i);
|
||||
System.out.println("i" + ((String)"j"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user