mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
$tracker$.markUnchanged($element$).getText()->$tracker$.text($element$)
This commit is contained in:
+3
-15
@@ -1,17 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2013 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* 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.intellij.codeInsight.daemon.impl.quickfix;
|
||||
|
||||
@@ -82,7 +70,7 @@ public class ChangeNewOperatorTypeFix implements IntentionAction {
|
||||
caretOffset = 0;
|
||||
@NonNls String text = "new " + toType.getDeepComponentType().getCanonicalText() + "[";
|
||||
if (originalExpressionArrayDimensions.length > 0) {
|
||||
text += commentTracker.markUnchanged(originalExpressionArrayDimensions[0]).getText();
|
||||
text += commentTracker.text(originalExpressionArrayDimensions[0]);
|
||||
}
|
||||
else {
|
||||
text += "0";
|
||||
@@ -93,7 +81,7 @@ public class ChangeNewOperatorTypeFix implements IntentionAction {
|
||||
text += "[";
|
||||
String arrayDimension = "";
|
||||
if (originalExpressionArrayDimensions.length > i) {
|
||||
arrayDimension = commentTracker.markUnchanged(originalExpressionArrayDimensions[i]).getText();
|
||||
arrayDimension = commentTracker.text(originalExpressionArrayDimensions[i]);
|
||||
text += arrayDimension;
|
||||
}
|
||||
text += "]";
|
||||
|
||||
+6
-19
@@ -1,17 +1,5 @@
|
||||
/*
|
||||
* 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* 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.intellij.codeInsight.daemon.impl.quickfix;
|
||||
|
||||
@@ -224,21 +212,20 @@ public class ConvertSwitchToIfIntention implements IntentionAction {
|
||||
return "";
|
||||
}
|
||||
if (!(value instanceof PsiReferenceExpression)) {
|
||||
return commentTracker.markUnchanged(value).getText();
|
||||
return commentTracker.text(value);
|
||||
}
|
||||
final PsiReferenceExpression referenceExpression = (PsiReferenceExpression)value;
|
||||
final PsiElement target = referenceExpression.resolve();
|
||||
|
||||
if (!(target instanceof PsiEnumConstant)) {
|
||||
return commentTracker.markUnchanged(value).getText();
|
||||
return commentTracker.text(value);
|
||||
}
|
||||
final PsiEnumConstant enumConstant = (PsiEnumConstant)target;
|
||||
final PsiClass aClass = enumConstant.getContainingClass();
|
||||
if (aClass == null) {
|
||||
return commentTracker.markUnchanged(value).getText();
|
||||
return commentTracker.text(value);
|
||||
}
|
||||
final String name = aClass.getQualifiedName();
|
||||
return name + '.' + commentTracker.markUnchanged(referenceExpression).getText();
|
||||
return aClass.getQualifiedName() + '.' + commentTracker.text(referenceExpression);
|
||||
}
|
||||
|
||||
private static void dumpBranch(SwitchStatementBranch branch,
|
||||
@@ -316,6 +303,6 @@ public class ConvertSwitchToIfIntention implements IntentionAction {
|
||||
return;
|
||||
}
|
||||
}
|
||||
out.append(commentTracker.markUnchanged(element).getText());
|
||||
out.append(commentTracker.text(element));
|
||||
}
|
||||
}
|
||||
|
||||
+4
-16
@@ -1,17 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2016 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* 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.intellij.codeInsight.intention.impl;
|
||||
|
||||
@@ -127,7 +115,7 @@ public class ExtractIfConditionAction extends PsiElementBaseIntentionAction {
|
||||
if (token != null && sb.length() != 0) {
|
||||
sb.append(token.getText()).append(" ");
|
||||
}
|
||||
sb.append(tracker.markUnchanged(e).getText());
|
||||
sb.append(tracker.text(e));
|
||||
}
|
||||
return factory.createExpressionFromText(sb.toString(), expression);
|
||||
}
|
||||
@@ -202,7 +190,7 @@ public class ExtractIfConditionAction extends PsiElementBaseIntentionAction {
|
||||
@NotNull PsiStatement thenBranch,
|
||||
@Nullable String elseBranch,
|
||||
CommentTracker tracker) {
|
||||
return createIfString(tracker.markUnchanged(condition).getText(), toThenBranchString(tracker.markUnchanged(thenBranch)), elseBranch);
|
||||
return createIfString(tracker.text(condition), toThenBranchString(tracker.markUnchanged(thenBranch)), elseBranch);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -210,7 +198,7 @@ public class ExtractIfConditionAction extends PsiElementBaseIntentionAction {
|
||||
@NotNull String thenBranch,
|
||||
@Nullable PsiStatement elseBranch,
|
||||
CommentTracker tracker) {
|
||||
return createIfString(tracker.markUnchanged(condition).getText(), thenBranch,
|
||||
return createIfString(tracker.text(condition), thenBranch,
|
||||
toElseBranchString(elseBranch != null ? tracker.markUnchanged(elseBranch) : null, true));
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -134,7 +134,7 @@ public class SurroundAutoCloseableAction extends PsiElementBaseIntentionAction {
|
||||
}
|
||||
|
||||
CommentTracker tracker = new CommentTracker();
|
||||
String text = "try (" + variable.getTypeElement().getText() + " " + variable.getName() + " = " + tracker.markUnchanged(initializer).getText() + ") {}";
|
||||
String text = "try (" + variable.getTypeElement().getText() + " " + variable.getName() + " = " + tracker.text(initializer) + ") {}";
|
||||
PsiTryStatement armStatement = (PsiTryStatement)tracker.replaceAndRestoreComments(declaration, text);
|
||||
|
||||
List<PsiElement> toFormat = null;
|
||||
@@ -201,7 +201,7 @@ public class SurroundAutoCloseableAction extends PsiElementBaseIntentionAction {
|
||||
CommentTracker commentTracker = new CommentTracker();
|
||||
PsiExpression varInit = var.getInitializer();
|
||||
if (varInit != null) {
|
||||
String varAssignText = name + " = " + commentTracker.markUnchanged(varInit).getText() + ";";
|
||||
String varAssignText = name + " = " + commentTracker.text(varInit) + ";";
|
||||
anchor = parent.addAfter(factory.createStatementFromText(varAssignText, parent), anchor);
|
||||
}
|
||||
|
||||
@@ -226,7 +226,7 @@ public class SurroundAutoCloseableAction extends PsiElementBaseIntentionAction {
|
||||
PsiElement statement = expression.getParent();
|
||||
|
||||
CommentTracker commentTracker = new CommentTracker();
|
||||
String text = "try (" + type.getCanonicalText(true) + " r = " + commentTracker.markUnchanged(expression).getText() + ") {}";
|
||||
String text = "try (" + type.getCanonicalText(true) + " r = " + commentTracker.text(expression) + ") {}";
|
||||
PsiTryStatement tryStatement = (PsiTryStatement)commentTracker.replaceAndRestoreComments(statement, text);
|
||||
|
||||
tryStatement = (PsiTryStatement)CodeStyleManager.getInstance(project).reformat(tryStatement);
|
||||
|
||||
+3
-15
@@ -1,17 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2015 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* 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;
|
||||
|
||||
@@ -165,8 +153,8 @@ public class PsiReplacementUtil {
|
||||
final PsiExpression rhs = assignmentExpression.getRExpression();
|
||||
final String operator = sign.getText();
|
||||
final String newOperator = operator.substring(0, operator.length() - 1);
|
||||
final String lhsText = tracker.markUnchanged(lhs).getText();
|
||||
final String rhsText = (rhs == null) ? "" : tracker.markUnchanged(rhs).getText();
|
||||
final String lhsText = tracker.text(lhs);
|
||||
final String rhsText = (rhs == null) ? "" : tracker.text(rhs);
|
||||
final boolean parentheses = ParenthesesUtils.areParenthesesNeeded(sign, rhs);
|
||||
final String cast = getCastString(lhs, rhs);
|
||||
final StringBuilder newExpression = new StringBuilder(lhsText);
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2017 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2018 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -88,7 +88,7 @@ public class OverlyStrongTypeCastInspection extends BaseInspection {
|
||||
}
|
||||
CommentTracker commentTracker = new CommentTracker();
|
||||
@NonNls
|
||||
final String newExpression = '(' + expectedType.getCanonicalText() + ')' + commentTracker.markUnchanged(operand).getText();
|
||||
final String newExpression = '(' + expectedType.getCanonicalText() + ')' + commentTracker.text(operand);
|
||||
PsiReplacementUtil.replaceExpressionAndShorten(expression, newExpression, commentTracker);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2013 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2018 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -64,7 +64,7 @@ public class AssignmentUsedAsConditionInspection extends BaseInspection {
|
||||
final PsiExpression rightExpression = expression.getRExpression();
|
||||
assert rightExpression != null;
|
||||
CommentTracker commentTracker = new CommentTracker();
|
||||
final String newExpression = commentTracker.markUnchanged(leftExpression).getText() + "==" + commentTracker.markUnchanged(rightExpression).getText();
|
||||
final String newExpression = commentTracker.text(leftExpression) + "==" + commentTracker.text(rightExpression);
|
||||
PsiReplacementUtil.replaceExpression(expression, newExpression, commentTracker);
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2015 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2011-2018 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -105,13 +105,13 @@ public class ArrayEqualityInspection extends BaseInspection {
|
||||
else {
|
||||
newExpressionText.append("java.util.Arrays.equals(");
|
||||
}
|
||||
newExpressionText.append(commentTracker.markUnchanged(binaryExpression.getLOperand()).getText());
|
||||
newExpressionText.append(commentTracker.text(binaryExpression.getLOperand()));
|
||||
newExpressionText.append(',');
|
||||
final PsiExpression rhs = binaryExpression.getROperand();
|
||||
if (rhs == null) {
|
||||
return;
|
||||
}
|
||||
newExpressionText.append(commentTracker.markUnchanged(rhs).getText());
|
||||
newExpressionText.append(commentTracker.text(rhs));
|
||||
newExpressionText.append(')');
|
||||
PsiReplacementUtil.replaceExpressionAndShorten(binaryExpression, newExpressionText.toString(), commentTracker);
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2018 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -97,11 +97,11 @@ public class ArrayEqualsInspection extends BaseInspection {
|
||||
final PsiExpression qualifier = expression.getQualifierExpression();
|
||||
assert qualifier != null;
|
||||
CommentTracker commentTracker = new CommentTracker();
|
||||
final String qualifierText = commentTracker.markUnchanged(qualifier).getText();
|
||||
final String qualifierText = commentTracker.text(qualifier);
|
||||
assert call != null;
|
||||
final PsiExpressionList argumentList = call.getArgumentList();
|
||||
final PsiExpression[] arguments = argumentList.getExpressions();
|
||||
final String argumentText = commentTracker.markUnchanged(arguments[0]).getText();
|
||||
final String argumentText = commentTracker.text(arguments[0]);
|
||||
@NonNls final StringBuilder newExpressionText = new StringBuilder();
|
||||
if (deepEquals) {
|
||||
newExpressionText.append("java.util.Arrays.deepEquals(");
|
||||
|
||||
+4
-6
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011 Bas Leijdekkers
|
||||
* Copyright 2011-2018 Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -108,7 +108,7 @@ public class ArrayHashCodeInspection extends BaseInspection {
|
||||
newExpressionText.append("java.util.Arrays.hashCode(");
|
||||
}
|
||||
CommentTracker commentTracker = new CommentTracker();
|
||||
newExpressionText.append(commentTracker.markUnchanged(qualifier).getText());
|
||||
newExpressionText.append(commentTracker.text(qualifier));
|
||||
newExpressionText.append(')');
|
||||
PsiReplacementUtil.replaceExpressionAndShorten(methodCallExpression, newExpressionText.toString(), commentTracker);
|
||||
}
|
||||
@@ -125,8 +125,7 @@ public class ArrayHashCodeInspection extends BaseInspection {
|
||||
public void visitMethodCallExpression(
|
||||
PsiMethodCallExpression expression) {
|
||||
super.visitMethodCallExpression(expression);
|
||||
final PsiReferenceExpression methodExpression =
|
||||
expression.getMethodExpression();
|
||||
final PsiReferenceExpression methodExpression = expression.getMethodExpression();
|
||||
final String methodName = methodExpression.getReferenceName();
|
||||
if (!HardcodedMethodConstants.HASH_CODE.equals(methodName)) {
|
||||
return;
|
||||
@@ -136,8 +135,7 @@ public class ArrayHashCodeInspection extends BaseInspection {
|
||||
if (arguments.length != 0) {
|
||||
return;
|
||||
}
|
||||
final PsiExpression qualifier =
|
||||
methodExpression.getQualifierExpression();
|
||||
final PsiExpression qualifier = methodExpression.getQualifierExpression();
|
||||
if (qualifier == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
+2
-14
@@ -1,17 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2015 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* 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 filse.
|
||||
*/
|
||||
package com.siyeh.ig.bugs;
|
||||
|
||||
@@ -99,7 +87,7 @@ public class ArrayObjectsEqualsInspection extends BaseInspection {
|
||||
newExpression.append("equals");
|
||||
}
|
||||
CommentTracker commentTracker = new CommentTracker();
|
||||
newExpression.append(commentTracker.markUnchanged(methodCallExpression.getArgumentList()).getText());
|
||||
newExpression.append(commentTracker.text(methodCallExpression.getArgumentList()));
|
||||
PsiReplacementUtil.replaceExpressionAndShorten(methodCallExpression, newExpression.toString(), commentTracker);
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2007-2011 Bas Leijdekkers
|
||||
* Copyright 2007-2018 Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -126,10 +126,10 @@ public class ImplicitArrayToStringInspection extends BaseInspection {
|
||||
if (qualifier == null) {
|
||||
return;
|
||||
}
|
||||
expressionText = commentTracker.markUnchanged(qualifier).getText();
|
||||
expressionText = commentTracker.text(qualifier);
|
||||
}
|
||||
else {
|
||||
expressionText = commentTracker.markUnchanged(expression).getText();
|
||||
expressionText = commentTracker.text(expression);
|
||||
}
|
||||
@NonNls final String newExpressionText;
|
||||
if (deepString) {
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2016 Bas Leijdekkers
|
||||
* Copyright 2011-2018 Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -106,10 +106,10 @@ public class MathRandomCastToIntInspection extends BaseInspection {
|
||||
newExpression.append(token.getText());
|
||||
}
|
||||
if (typeCastExpression.equals(expression)) {
|
||||
newExpression.append(commentTracker.markUnchanged(operand).getText());
|
||||
newExpression.append(commentTracker.text(operand));
|
||||
}
|
||||
else {
|
||||
newExpression.append(commentTracker.markUnchanged(expression).getText());
|
||||
newExpression.append(commentTracker.text(expression));
|
||||
}
|
||||
}
|
||||
newExpression.append(')');
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2018 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -77,7 +77,7 @@ public class NonShortCircuitBooleanInspection extends BaseInspection {
|
||||
if (newExpression.length() != 0) {
|
||||
newExpression.append(operandText);
|
||||
}
|
||||
newExpression.append(commentTracker.markUnchanged(operand).getText());
|
||||
newExpression.append(commentTracker.text(operand));
|
||||
}
|
||||
PsiReplacementUtil.replaceExpression(expression, newExpression.toString(), commentTracker);
|
||||
}
|
||||
|
||||
+4
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2014 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2018 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -90,8 +90,9 @@ public class StaticCallOnSubclassInspection extends BaseInspection implements Cl
|
||||
}
|
||||
final String containingClassName = containingClass.getQualifiedName();
|
||||
CommentTracker commentTracker = new CommentTracker();
|
||||
final String argText = commentTracker.markUnchanged(argumentList).getText();
|
||||
PsiReplacementUtil.replaceExpressionAndShorten(call, containingClassName + '.' + commentTracker.markUnchanged(call.getTypeArgumentList()).getText() + methodName + argText, commentTracker);
|
||||
final String argText = commentTracker.text(argumentList);
|
||||
final String typeArgText = commentTracker.text(call.getTypeArgumentList());
|
||||
PsiReplacementUtil.replaceExpressionAndShorten(call, containingClassName + '.' + typeArgText + methodName + argText, commentTracker);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2018 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -114,7 +114,7 @@ public class UseOfPropertiesAsHashtableInspection extends BaseInspection {
|
||||
@NonNls final StringBuilder newExpression = new StringBuilder();
|
||||
final PsiExpression qualifierExpression = methodExpression.getQualifierExpression();
|
||||
if (qualifierExpression != null) {
|
||||
newExpression.append(commentTracker.markUnchanged(qualifierExpression).getText());
|
||||
newExpression.append(commentTracker.text(qualifierExpression));
|
||||
newExpression.append('.');
|
||||
}
|
||||
if (put) {
|
||||
@@ -125,7 +125,7 @@ public class UseOfPropertiesAsHashtableInspection extends BaseInspection {
|
||||
}
|
||||
final PsiExpressionList argumentList = methodCallExpression.getArgumentList();
|
||||
final PsiExpression[] arguments = argumentList.getExpressions();
|
||||
newExpression.append(StringUtil.join(arguments, arg -> commentTracker.markUnchanged(arg).getText(), ","));
|
||||
newExpression.append(StringUtil.join(arguments, arg -> commentTracker.text(arg), ","));
|
||||
newExpression.append(')');
|
||||
|
||||
PsiReplacementUtil.replaceExpression(methodCallExpression, newExpression.toString(), commentTracker);
|
||||
|
||||
+2
-14
@@ -1,17 +1,5 @@
|
||||
/*
|
||||
* 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* 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.cloneable;
|
||||
|
||||
@@ -106,7 +94,7 @@ public class CloneReturnsClassTypeInspection extends BaseInspection {
|
||||
return;
|
||||
}
|
||||
CommentTracker commentTracker = new CommentTracker();
|
||||
PsiReplacementUtil.replaceStatement(statement, "return (" + myClassName + ')' + commentTracker.markUnchanged(returnValue).getText() + ';', commentTracker);
|
||||
PsiReplacementUtil.replaceStatement(statement, "return (" + myClassName + ')' + commentTracker.text(returnValue) + ';', commentTracker);
|
||||
}
|
||||
});
|
||||
element.replace(newTypeElement);
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2017 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2018 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -66,7 +66,7 @@ public class ConditionalExpressionWithIdenticalBranchesInspection extends BaseIn
|
||||
final PsiExpression elseExpression = conditionalExpression.getElseExpression();
|
||||
if (EquivalenceChecker.getCanonicalPsiEquivalence().expressionsAreEquivalent(thenExpression, elseExpression)) {
|
||||
CommentTracker commentTracker = new CommentTracker();
|
||||
PsiReplacementUtil.replaceExpression(conditionalExpression, commentTracker.markUnchanged(thenExpression).getText(), commentTracker);
|
||||
PsiReplacementUtil.replaceExpression(conditionalExpression, commentTracker.text(thenExpression), commentTracker);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-7
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2008 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2018 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -60,12 +60,7 @@ public class ConstantConditionalExpressionInspection
|
||||
final PsiExpression condition = exp.getCondition();
|
||||
assert thenExpression != null;
|
||||
assert elseExpression != null;
|
||||
if (BoolUtils.isTrue(condition)) {
|
||||
return commentTracker.markUnchanged(thenExpression).getText();
|
||||
}
|
||||
else {
|
||||
return commentTracker.markUnchanged(elseExpression).getText();
|
||||
}
|
||||
return BoolUtils.isTrue(condition) ? commentTracker.text(thenExpression) : commentTracker.text(elseExpression);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+4
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2017 Bas Leijdekkers
|
||||
* Copyright 2006-2018 Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -80,11 +80,11 @@ public class DoubleNegationInspection extends BaseInspection {
|
||||
final PsiExpression secondOperand = operands[1];
|
||||
if (isNegation(firstOperand)) {
|
||||
PsiReplacementUtil
|
||||
.replaceExpression(polyadicExpression, BoolUtils.getNegatedExpressionText(firstOperand, tracker) + "==" + tracker.markUnchanged(secondOperand).getText(), tracker);
|
||||
.replaceExpression(polyadicExpression, BoolUtils.getNegatedExpressionText(firstOperand, tracker) + "==" + tracker.text(secondOperand), tracker);
|
||||
}
|
||||
else {
|
||||
PsiReplacementUtil
|
||||
.replaceExpression(polyadicExpression, tracker.markUnchanged(firstOperand).getText() + "==" + BoolUtils.getNegatedExpressionText(secondOperand, tracker), tracker);
|
||||
.replaceExpression(polyadicExpression, tracker.text(firstOperand) + "==" + BoolUtils.getNegatedExpressionText(secondOperand, tracker), tracker);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -98,7 +98,7 @@ public class DoubleNegationInspection extends BaseInspection {
|
||||
newExpressionText.append("==");
|
||||
}
|
||||
}
|
||||
newExpressionText.append(tracker.markUnchanged(operands[i]).getText());
|
||||
newExpressionText.append(tracker.text(operands[i]));
|
||||
}
|
||||
PsiReplacementUtil.replaceExpression(polyadicExpression, newExpressionText.toString(), tracker);
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2009 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2018 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -132,7 +132,7 @@ public class ForLoopReplaceableByWhileInspection extends BaseInspection {
|
||||
final PsiExpression[] expressions = expressionList.getExpressions();
|
||||
updateStatements = new PsiStatement[expressions.length];
|
||||
for (int i = 0; i < expressions.length; i++) {
|
||||
updateStatements[i] = factory.createStatementFromText(commentTracker.markUnchanged(expressions[i]).getText() + ';', element);
|
||||
updateStatements[i] = factory.createStatementFromText(commentTracker.text(expressions[i]) + ';', element);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
+6
-8
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2008-2015 Bas Leijdekkers
|
||||
* Copyright 2008-2018 Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -110,7 +110,7 @@ public class IfMayBeConditionalInspection extends BaseInspection {
|
||||
if (thenExpression instanceof PsiAssignmentExpression && elseExpression instanceof PsiAssignmentExpression) {
|
||||
final PsiAssignmentExpression thenAssignmentExpression = (PsiAssignmentExpression)thenExpression;
|
||||
final PsiExpression lhs = thenAssignmentExpression.getLExpression();
|
||||
replacementText.append(tracker.markUnchanged(lhs).getText());
|
||||
replacementText.append(tracker.text(lhs));
|
||||
final PsiJavaToken token = thenAssignmentExpression.getOperationSign();
|
||||
replacementText.append(token.getText());
|
||||
appendExpressionText(condition, replacementText, tracker);
|
||||
@@ -127,7 +127,7 @@ public class IfMayBeConditionalInspection extends BaseInspection {
|
||||
final PsiMethodCallExpression thenMethodCallExpression = (PsiMethodCallExpression)thenExpression;
|
||||
final PsiMethodCallExpression elseMethodCallExpression = (PsiMethodCallExpression)elseExpression;
|
||||
final PsiReferenceExpression thenMethodExpression = thenMethodCallExpression.getMethodExpression();
|
||||
replacementText.append(tracker.markUnchanged(thenMethodExpression).getText());
|
||||
replacementText.append(tracker.text(thenMethodExpression));
|
||||
replacementText.append('(');
|
||||
final PsiExpressionList thenArgumentList = thenMethodCallExpression.getArgumentList();
|
||||
final PsiExpression[] thenArguments = thenArgumentList.getExpressions();
|
||||
@@ -140,7 +140,7 @@ public class IfMayBeConditionalInspection extends BaseInspection {
|
||||
final PsiExpression thenArgument = thenArguments[i];
|
||||
final PsiExpression elseArgument = elseArguments[i];
|
||||
if (EquivalenceChecker.getCanonicalPsiEquivalence().expressionsAreEquivalent(thenArgument, elseArgument)) {
|
||||
replacementText.append(tracker.markUnchanged(thenArgument).getText());
|
||||
replacementText.append(tracker.text(thenArgument));
|
||||
}
|
||||
else {
|
||||
appendExpressionText(condition, replacementText, tracker);
|
||||
@@ -167,11 +167,9 @@ public class IfMayBeConditionalInspection extends BaseInspection {
|
||||
if (expression == null) {
|
||||
return;
|
||||
}
|
||||
final String expressionText = tracker.markUnchanged(expression).getText();
|
||||
final String expressionText = tracker.text(expression);
|
||||
if (ParenthesesUtils.getPrecedence(expression) > ParenthesesUtils.CONDITIONAL_PRECEDENCE) {
|
||||
out.append('(');
|
||||
out.append(expressionText);
|
||||
out.append(')');
|
||||
out.append('(').append(expressionText).append(')');
|
||||
}
|
||||
else {
|
||||
out.append(expressionText);
|
||||
|
||||
+2
-14
@@ -1,17 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2015 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* 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.controlflow;
|
||||
|
||||
@@ -78,7 +66,7 @@ public class NegatedConditionalExpressionInspection extends BaseInspection imple
|
||||
final StringBuilder newExpression = new StringBuilder();
|
||||
final PsiExpression condition = conditionalExpression.getCondition();
|
||||
CommentTracker tracker = new CommentTracker();
|
||||
newExpression.append(tracker.markUnchanged(condition).getText()).append('?');
|
||||
newExpression.append(tracker.text(condition)).append('?');
|
||||
final PsiExpression thenExpression = conditionalExpression.getThenExpression();
|
||||
if (thenExpression != null) {
|
||||
newExpression.append(BoolUtils.getNegatedExpressionText(thenExpression, tracker));
|
||||
|
||||
+2
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2012 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2018 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -98,8 +98,7 @@ public class NegatedConditionalInspection extends BaseInspection {
|
||||
final String negatedCondition = BoolUtils.getNegatedExpressionText(condition, tracker);
|
||||
assert elseBranch != null;
|
||||
assert thenBranch != null;
|
||||
final String newStatement = negatedCondition + '?' + tracker.markUnchanged(elseBranch).getText() +
|
||||
':' + tracker.markUnchanged(thenBranch).getText();
|
||||
final String newStatement = negatedCondition + '?' + tracker.text(elseBranch) + ':' + tracker.text(thenBranch);
|
||||
PsiReplacementUtil.replaceExpression(conditionalExpression, newStatement);
|
||||
}
|
||||
}
|
||||
|
||||
+3
-15
@@ -1,17 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2012 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* 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.controlflow;
|
||||
|
||||
@@ -77,7 +65,7 @@ public class NegatedEqualityExpressionInspection extends BaseInspection {
|
||||
final PsiBinaryExpression binaryExpression = (PsiBinaryExpression)operand;
|
||||
final IElementType tokenType = binaryExpression.getOperationTokenType();
|
||||
CommentTracker commentTracker = new CommentTracker();
|
||||
StringBuilder text = new StringBuilder(commentTracker.markUnchanged(binaryExpression.getLOperand()).getText());
|
||||
StringBuilder text = new StringBuilder(commentTracker.text(binaryExpression.getLOperand()));
|
||||
if (JavaTokenType.EQEQ.equals(tokenType)) {
|
||||
text.append("!=");
|
||||
}
|
||||
@@ -89,7 +77,7 @@ public class NegatedEqualityExpressionInspection extends BaseInspection {
|
||||
}
|
||||
final PsiExpression rhs = binaryExpression.getROperand();
|
||||
if (rhs != null) {
|
||||
text.append(commentTracker.markUnchanged(rhs).getText());
|
||||
text.append(commentTracker.text(rhs));
|
||||
}
|
||||
|
||||
PsiReplacementUtil.replaceExpression(prefixExpression, text.toString(), commentTracker);
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2012 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2018 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -103,7 +103,7 @@ public class NegatedIfElseInspection extends BaseInspection {
|
||||
}
|
||||
CommentTracker tracker = new CommentTracker();
|
||||
final String negatedCondition = BoolUtils.getNegatedExpressionText(condition, tracker);
|
||||
String elseText = tracker.markUnchanged(elseBranch).getText();
|
||||
String elseText = tracker.text(elseBranch);
|
||||
final PsiElement lastChild = elseBranch.getLastChild();
|
||||
if (lastChild instanceof PsiComment) {
|
||||
final PsiComment comment = (PsiComment)lastChild;
|
||||
@@ -112,7 +112,7 @@ public class NegatedIfElseInspection extends BaseInspection {
|
||||
elseText += '\n';
|
||||
}
|
||||
}
|
||||
@NonNls final String newStatement = "if(" + negatedCondition + ')' + elseText + " else " + tracker.markUnchanged(thenBranch).getText();
|
||||
@NonNls final String newStatement = "if(" + negatedCondition + ')' + elseText + " else " + tracker.text(thenBranch);
|
||||
PsiReplacementUtil.replaceStatement(ifStatement, newStatement, tracker);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2017 Bas Leijdekkers
|
||||
* Copyright 2011-2018 Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -78,7 +78,7 @@ public class AddThisQualifierFix extends InspectionGadgetsFix {
|
||||
}
|
||||
final PsiExpression thisQualifier = ExpressionUtils.getQualifierOrThis(expression);
|
||||
CommentTracker commentTracker = new CommentTracker();
|
||||
@NonNls final String newExpression = commentTracker.markUnchanged(thisQualifier).getText() + "." + commentTracker.markUnchanged(expression).getText();
|
||||
@NonNls final String newExpression = commentTracker.text(thisQualifier) + "." + commentTracker.text(expression);
|
||||
PsiReplacementUtil.replaceExpressionAndShorten(expression, newExpression, commentTracker);
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2017 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2018 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -105,12 +105,12 @@ public class EqualityToEqualsFix extends InspectionGadgetsFix {
|
||||
newExpression.append('!');
|
||||
}
|
||||
if (ParenthesesUtils.getPrecedence(lhs) > ParenthesesUtils.METHOD_CALL_PRECEDENCE) {
|
||||
newExpression.append('(').append(commentTracker.markUnchanged(lhs).getText()).append(')');
|
||||
newExpression.append('(').append(commentTracker.text(lhs)).append(')');
|
||||
}
|
||||
else {
|
||||
newExpression.append(commentTracker.markUnchanged(lhs).getText());
|
||||
newExpression.append(commentTracker.text(lhs));
|
||||
}
|
||||
newExpression.append(".equals(").append(commentTracker.markUnchanged(rhs).getText()).append(')');
|
||||
newExpression.append(".equals(").append(commentTracker.text(rhs)).append(')');
|
||||
|
||||
PsiReplacementUtil.replaceExpressionAndShorten(expression, newExpression.toString(), commentTracker);
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2017 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2018 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -84,8 +84,8 @@ public class EqualityToSafeEqualsFix extends InspectionGadgetsFix {
|
||||
return;
|
||||
}
|
||||
CommentTracker tracker = new CommentTracker();
|
||||
final String lhsText = tracker.markUnchanged(lhs).getText();
|
||||
final String rhsText = tracker.markUnchanged(rhs).getText();
|
||||
final String lhsText = tracker.text(lhs);
|
||||
final String rhsText = tracker.text(rhs);
|
||||
@NonNls final StringBuilder newExpression = new StringBuilder();
|
||||
if (PsiUtil.isLanguageLevel7OrHigher(expression) && ClassUtils.findClass("java.util.Objects", expression) != null) {
|
||||
if (JavaTokenType.NE.equals(expression.getOperationTokenType())) {
|
||||
|
||||
+2
-14
@@ -1,17 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2016 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* 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.imports;
|
||||
|
||||
@@ -123,7 +111,7 @@ public class StaticImportInspectionBase extends BaseInspection {
|
||||
}
|
||||
CommentTracker tracker = new CommentTracker();
|
||||
final String qualifiedName = aClass.getQualifiedName();
|
||||
final String text = tracker.markUnchanged(reference).getText();
|
||||
final String text = tracker.text(reference);
|
||||
final String referenceText = qualifiedName + '.' + text;
|
||||
if (reference instanceof PsiReferenceExpression) {
|
||||
final PsiElement insertedElement = tracker.replaceAndRestoreComments(reference, referenceText);
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2015 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2018 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -203,7 +203,7 @@ public class AutoUnboxingInspection extends BaseInspection {
|
||||
if (rExpression == null) {
|
||||
return;
|
||||
}
|
||||
final String text = commentTracker.markUnchanged(lExpression).getText() + '=' + newExpressionText + sign + commentTracker.markUnchanged(rExpression).getText();
|
||||
final String text = commentTracker.text(lExpression) + '=' + newExpressionText + sign + commentTracker.text(rExpression);
|
||||
final PsiExpression newExpression = factory.createExpressionFromText(text, assignmentExpression);
|
||||
commentTracker.replaceAndRestoreComments(assignmentExpression, newExpression);
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2013 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2018 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -119,7 +119,7 @@ public class ForeachStatementInspection extends BaseInspection {
|
||||
final PsiElement[] children = block.getChildren();
|
||||
for (int i = 1; i < children.length - 1; i++) {
|
||||
//skip the braces
|
||||
newStatement.append(tracker.markUnchanged(children[i]).getText());
|
||||
newStatement.append(tracker.text(children[i]));
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -128,7 +128,7 @@ public class ForeachStatementInspection extends BaseInspection {
|
||||
bodyText = "";
|
||||
}
|
||||
else {
|
||||
bodyText = tracker.markUnchanged(body).getText();
|
||||
bodyText = tracker.text(body);
|
||||
}
|
||||
newStatement.append(bodyText);
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2005-2014 Bas Leijdekkers
|
||||
* Copyright 2005-2018 Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -127,12 +127,12 @@ public class IndexOfReplaceableByContainsInspection
|
||||
qualifierText = "";
|
||||
}
|
||||
else {
|
||||
qualifierText = commentTracker.markUnchanged(qualifierExpression).getText();
|
||||
qualifierText = commentTracker.text(qualifierExpression);
|
||||
}
|
||||
final PsiExpressionList argumentList = call.getArgumentList();
|
||||
final PsiExpression expression = argumentList.getExpressions()[0];
|
||||
@NonNls final String newExpressionText =
|
||||
qualifierText + ".contains(" + commentTracker.markUnchanged(expression).getText() + ')';
|
||||
qualifierText + ".contains(" + commentTracker.text(expression) + ')';
|
||||
if (tokenType.equals(JavaTokenType.EQEQ)) {
|
||||
return '!' + newExpressionText;
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2017 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2018 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -125,7 +125,7 @@ public class UnnecessaryBoxingInspection extends BaseInspection {
|
||||
if (unboxedType == null) {
|
||||
return null;
|
||||
}
|
||||
final String text = commentTracker.markUnchanged(unboxedExpression).getText();
|
||||
final String text = commentTracker.text(unboxedExpression);
|
||||
if (expressionType.equals(unboxedType)) {
|
||||
final PsiElement parent = boxedExpression.getParent();
|
||||
if (parent instanceof PsiExpression && ParenthesesUtils.areParenthesesNeeded(unboxedExpression, (PsiExpression) parent, false)) {
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2017 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2018 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -126,7 +126,7 @@ public class UnnecessaryUnboxingInspection extends BaseInspection {
|
||||
}
|
||||
}
|
||||
}
|
||||
final String strippedQualifierText = commentTracker.markUnchanged(strippedQualifier).getText();
|
||||
final String strippedQualifierText = commentTracker.text(strippedQualifier);
|
||||
PsiReplacementUtil.replaceExpression(methodCall, strippedQualifierText, commentTracker);
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2012 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2018 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -66,11 +66,11 @@ public class BigDecimalEqualsInspection extends BaseInspection {
|
||||
return;
|
||||
}
|
||||
CommentTracker commentTracker = new CommentTracker();
|
||||
final String qualifierText = commentTracker.markUnchanged(qualifier).getText();
|
||||
final String qualifierText = commentTracker.text(qualifier);
|
||||
assert call != null;
|
||||
final PsiExpressionList argumentList = call.getArgumentList();
|
||||
final PsiExpression[] args = argumentList.getExpressions();
|
||||
final String argText = commentTracker.markUnchanged(args[0]).getText();
|
||||
final String argText = commentTracker.text(args[0]);
|
||||
PsiReplacementUtil.replaceExpression(call, qualifierText + ".compareTo(" + argText + ")==0", commentTracker);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2017 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2018 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -125,7 +125,7 @@ public class CachedNumberConstructorCallInspection extends BaseInspection {
|
||||
final PsiExpression[] args = argList.getExpressions();
|
||||
final PsiExpression arg = args[0];
|
||||
CommentTracker commentTracker = new CommentTracker();
|
||||
final String text = commentTracker.markUnchanged(arg).getText();
|
||||
final String text = commentTracker.text(arg);
|
||||
PsiReplacementUtil.replaceExpression(expression, className + ".valueOf(" + text + ')', commentTracker);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2008-2011 Bas Leijdekkers
|
||||
* Copyright 2008-2018 Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -131,7 +131,7 @@ public class CharUsedInArithmeticContextInspection extends BaseInspection {
|
||||
}
|
||||
final PsiExpression expression = (PsiExpression)element;
|
||||
CommentTracker commentTracker = new CommentTracker();
|
||||
final String expressionText = commentTracker.markUnchanged(expression).getText();
|
||||
final String expressionText = commentTracker.text(expression);
|
||||
PsiReplacementUtil.replaceExpression(expression, '(' + typeText + ')' + expressionText, commentTracker);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2012 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2018 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -95,7 +95,7 @@ public class ComparisonToNaNInspection extends BaseInspection {
|
||||
}
|
||||
assert operand != null;
|
||||
CommentTracker commentTracker = new CommentTracker();
|
||||
final String operandText = commentTracker.markUnchanged(operand).getText();
|
||||
final String operandText = commentTracker.text(operand);
|
||||
final IElementType tokenType = comparison.getOperationTokenType();
|
||||
final String negationText;
|
||||
if (tokenType.equals(JavaTokenType.EQEQ)) {
|
||||
|
||||
+5
-5
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2016 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2018 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -126,9 +126,9 @@ public class ImplicitNumericConversionInspection extends BaseInspection {
|
||||
final PsiJavaToken sign = assignmentExpression.getOperationSign();
|
||||
if (!JavaTokenType.EQ.equals(sign.getTokenType())) {
|
||||
CommentTracker commentTracker = new CommentTracker();
|
||||
final String lhsText = commentTracker.markUnchanged(assignmentExpression.getLExpression()).getText();
|
||||
final String lhsText = commentTracker.text(assignmentExpression.getLExpression());
|
||||
final String newExpressionText =
|
||||
lhsText + "=(" + expectedType.getCanonicalText() + ")(" + lhsText + sign.getText().charAt(0) + commentTracker.markUnchanged(expression).getText() + ')';
|
||||
lhsText + "=(" + expectedType.getCanonicalText() + ")(" + lhsText + sign.getText().charAt(0) + commentTracker.text(expression) + ')';
|
||||
PsiReplacementUtil.replaceExpression(assignmentExpression, newExpressionText, commentTracker);
|
||||
return;
|
||||
}
|
||||
@@ -136,10 +136,10 @@ public class ImplicitNumericConversionInspection extends BaseInspection {
|
||||
CommentTracker commentTracker = new CommentTracker();
|
||||
final String castExpression;
|
||||
if (ParenthesesUtils.getPrecedence(expression) <= ParenthesesUtils.TYPE_CAST_PRECEDENCE) {
|
||||
castExpression = '(' + expectedType.getCanonicalText() + ')' + commentTracker.markUnchanged(expression).getText();
|
||||
castExpression = '(' + expectedType.getCanonicalText() + ')' + commentTracker.text(expression);
|
||||
}
|
||||
else {
|
||||
castExpression = '(' + expectedType.getCanonicalText() + ")(" + commentTracker.markUnchanged(expression).getText() + ')';
|
||||
castExpression = '(' + expectedType.getCanonicalText() + ")(" + commentTracker.text(expression) + ')';
|
||||
}
|
||||
PsiReplacementUtil.replaceExpression(expression, castExpression, commentTracker);
|
||||
}
|
||||
|
||||
+4
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2007-2015 Bas Leijdekkers
|
||||
* Copyright 2007-2018 Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -68,7 +68,7 @@ public class UnnecessaryUnaryMinusInspection extends BaseInspection {
|
||||
if (parentExpression instanceof PsiAssignmentExpression) {
|
||||
final PsiAssignmentExpression assignmentExpression = (PsiAssignmentExpression)parentExpression;
|
||||
final PsiExpression lhs = assignmentExpression.getLExpression();
|
||||
newExpression.append(commentTracker.markUnchanged(lhs).getText());
|
||||
newExpression.append(commentTracker.text(lhs));
|
||||
final IElementType tokenType = assignmentExpression.getOperationTokenType();
|
||||
if (tokenType.equals(JavaTokenType.PLUSEQ)) {
|
||||
newExpression.append("-=");
|
||||
@@ -80,7 +80,7 @@ public class UnnecessaryUnaryMinusInspection extends BaseInspection {
|
||||
else if (parentExpression instanceof PsiBinaryExpression) {
|
||||
final PsiBinaryExpression binaryExpression = (PsiBinaryExpression)parentExpression;
|
||||
final PsiExpression lhs = binaryExpression.getLOperand();
|
||||
newExpression.append(commentTracker.markUnchanged(lhs).getText());
|
||||
newExpression.append(commentTracker.text(lhs));
|
||||
final IElementType tokenType = binaryExpression.getOperationTokenType();
|
||||
if (tokenType.equals(JavaTokenType.PLUS)) {
|
||||
newExpression.append('-');
|
||||
@@ -94,7 +94,7 @@ public class UnnecessaryUnaryMinusInspection extends BaseInspection {
|
||||
return;
|
||||
}
|
||||
|
||||
newExpression.append(commentTracker.markUnchanged(operand).getText());
|
||||
newExpression.append(commentTracker.text(operand));
|
||||
PsiReplacementUtil.replaceExpression(parentExpression, newExpression.toString(), commentTracker);
|
||||
}
|
||||
}
|
||||
|
||||
+3
-15
@@ -1,17 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2016 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* 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.performance;
|
||||
|
||||
@@ -100,7 +88,7 @@ public class ArraysAsListWithZeroOrOneArgumentInspection extends BaseInspection
|
||||
final PsiReferenceExpression methodExpression = methodCallExpression.getMethodExpression();
|
||||
final PsiReferenceParameterList parameterList = methodExpression.getParameterList();
|
||||
CommentTracker commentTracker = new CommentTracker();
|
||||
final String parameterText = parameterList != null ? commentTracker.markUnchanged(parameterList).getText() : "";
|
||||
final String parameterText = parameterList != null ? commentTracker.text(parameterList) : "";
|
||||
if (myEmpty) {
|
||||
PsiReplacementUtil.replaceExpressionAndShorten(methodCallExpression, "java.util.Collections." + parameterText +
|
||||
"emptyList()", commentTracker);
|
||||
@@ -108,7 +96,7 @@ public class ArraysAsListWithZeroOrOneArgumentInspection extends BaseInspection
|
||||
else {
|
||||
final PsiExpressionList argumentList = methodCallExpression.getArgumentList();
|
||||
PsiReplacementUtil.replaceExpressionAndShorten(methodCallExpression, "java.util.Collections." + parameterText +
|
||||
"singletonList" + commentTracker.markUnchanged(argumentList).getText(), commentTracker);
|
||||
"singletonList" + commentTracker.text(argumentList), commentTracker);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+13
-17
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2012 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2018 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -139,13 +139,13 @@ public class ManualArrayCopyInspection extends BaseInspection {
|
||||
return null;
|
||||
}
|
||||
final PsiExpression lArray = lhs.getArrayExpression();
|
||||
final String toArrayText = commentTracker.markUnchanged(lArray).getText();
|
||||
final String toArrayText = commentTracker.text(lArray);
|
||||
final PsiArrayAccessExpression rhs = getRhsArrayAccessExpression(forStatement);
|
||||
if (rhs == null) {
|
||||
return null;
|
||||
}
|
||||
final PsiExpression rArray = rhs.getArrayExpression();
|
||||
final String fromArrayText = commentTracker.markUnchanged(rArray).getText();
|
||||
final String fromArrayText = commentTracker.text(rArray);
|
||||
final PsiExpression rhsIndexExpression = rhs.getIndexExpression();
|
||||
final PsiExpression strippedRhsIndexExpression = ParenthesesUtils.stripParentheses(rhsIndexExpression);
|
||||
final PsiExpression limitExpression;
|
||||
@@ -320,10 +320,10 @@ public class ManualArrayCopyInspection extends BaseInspection {
|
||||
final int precedence = ParenthesesUtils.getPrecedence(min);
|
||||
final String minText;
|
||||
if (precedence >= ParenthesesUtils.ADDITIVE_PRECEDENCE) {
|
||||
minText = '(' + commentTracker.markUnchanged(min).getText() + ')';
|
||||
minText = '(' + commentTracker.text(min) + ')';
|
||||
}
|
||||
else {
|
||||
minText = commentTracker.markUnchanged(min).getText();
|
||||
minText = commentTracker.text(min);
|
||||
}
|
||||
final String maxText = buildExpressionText(max, plusOne, false, commentTracker);
|
||||
return maxText + '-' + minText;
|
||||
@@ -336,13 +336,13 @@ public class ManualArrayCopyInspection extends BaseInspection {
|
||||
if (!plusOne) {
|
||||
final int precedence = ParenthesesUtils.getPrecedence(expression);
|
||||
if (precedence > ParenthesesUtils.ADDITIVE_PRECEDENCE) {
|
||||
return '(' + commentTracker.markUnchanged(expression).getText() + ')';
|
||||
return '(' + commentTracker.text(expression) + ')';
|
||||
}
|
||||
else {
|
||||
if (parenthesize && precedence >= ParenthesesUtils.ADDITIVE_PRECEDENCE) {
|
||||
return '(' + commentTracker.markUnchanged(expression).getText() + ')';
|
||||
return '(' + commentTracker.text(expression) + ')';
|
||||
}
|
||||
return commentTracker.markUnchanged(expression).getText();
|
||||
return commentTracker.text(expression);
|
||||
}
|
||||
}
|
||||
if (expression instanceof PsiBinaryExpression) {
|
||||
@@ -351,7 +351,7 @@ public class ManualArrayCopyInspection extends BaseInspection {
|
||||
if (tokenType == JavaTokenType.MINUS) {
|
||||
final PsiExpression rhs = binaryExpression.getROperand();
|
||||
if (ExpressionUtils.isOne(rhs)) {
|
||||
return commentTracker.markUnchanged(binaryExpression.getLOperand()).getText();
|
||||
return commentTracker.text(binaryExpression.getLOperand());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -366,10 +366,10 @@ public class ManualArrayCopyInspection extends BaseInspection {
|
||||
final int precedence = ParenthesesUtils.getPrecedence(expression);
|
||||
final String result;
|
||||
if (precedence > ParenthesesUtils.ADDITIVE_PRECEDENCE) {
|
||||
result = '(' + getText(expression, commentTracker) + ")+1";
|
||||
result = '(' + commentTracker.text(expression) + ")+1";
|
||||
}
|
||||
else {
|
||||
result = getText(expression, commentTracker) + "+1";
|
||||
result = commentTracker.text(expression) + "+1";
|
||||
}
|
||||
if (parenthesize) {
|
||||
return '(' + result + ')';
|
||||
@@ -377,10 +377,6 @@ public class ManualArrayCopyInspection extends BaseInspection {
|
||||
return result;
|
||||
}
|
||||
|
||||
private static String getText(PsiExpression expression, CommentTracker commentTracker) {
|
||||
return commentTracker.markUnchanged(expression).getText();
|
||||
}
|
||||
|
||||
@NonNls
|
||||
@Nullable
|
||||
private static String buildOffsetText(PsiExpression expression,
|
||||
@@ -391,7 +387,7 @@ public class ManualArrayCopyInspection extends BaseInspection {
|
||||
if (expression == null) {
|
||||
return null;
|
||||
}
|
||||
final String expressionText = getText(expression, commentTracker);
|
||||
final String expressionText = commentTracker.text(expression);
|
||||
final String variableName = variable.getName();
|
||||
if (expressionText.equals(variableName)) {
|
||||
final PsiExpression initialValue =
|
||||
@@ -429,7 +425,7 @@ public class ManualArrayCopyInspection extends BaseInspection {
|
||||
return collapseConstant(lhsText + sign.getText() + rhsText,
|
||||
variable);
|
||||
}
|
||||
return collapseConstant(getText(expression, commentTracker), variable);
|
||||
return collapseConstant(commentTracker.text(expression), variable);
|
||||
}
|
||||
|
||||
private static String collapseConstant(@NonNls String expressionText,
|
||||
|
||||
+8
-21
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2018 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -59,8 +59,7 @@ public class RandomDoubleForRandomIntegerInspection
|
||||
return new RandomDoubleForRandomIntegerFix();
|
||||
}
|
||||
|
||||
private static class RandomDoubleForRandomIntegerFix
|
||||
extends InspectionGadgetsFix {
|
||||
private static class RandomDoubleForRandomIntegerFix extends InspectionGadgetsFix {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
@@ -84,9 +83,7 @@ public class RandomDoubleForRandomIntegerInspection
|
||||
if (qualifier == null) {
|
||||
return;
|
||||
}
|
||||
final String qualifierText = qualifier.getText();
|
||||
final PsiBinaryExpression multiplication =
|
||||
(PsiBinaryExpression)getContainingExpression(call);
|
||||
final PsiBinaryExpression multiplication = (PsiBinaryExpression)getContainingExpression(call);
|
||||
if (multiplication == null) {
|
||||
return;
|
||||
}
|
||||
@@ -94,23 +91,13 @@ public class RandomDoubleForRandomIntegerInspection
|
||||
if (cast == null) {
|
||||
return;
|
||||
}
|
||||
CommentTracker commentTracker = new CommentTracker();
|
||||
final PsiExpression multiplierExpression;
|
||||
final PsiExpression lhs = multiplication.getLOperand();
|
||||
final PsiExpression strippedLhs =
|
||||
ParenthesesUtils.stripParentheses(lhs);
|
||||
if (call.equals(strippedLhs)) {
|
||||
multiplierExpression = multiplication.getROperand();
|
||||
}
|
||||
else {
|
||||
multiplierExpression = lhs;
|
||||
}
|
||||
final PsiExpression strippedLhs = ParenthesesUtils.stripParentheses(lhs);
|
||||
final PsiExpression multiplierExpression = call.equals(strippedLhs) ? multiplication.getROperand() : lhs;
|
||||
assert multiplierExpression != null;
|
||||
final String multiplierText = commentTracker.markUnchanged(multiplierExpression).getText();
|
||||
@NonNls final String nextInt = ".nextInt((int) ";
|
||||
commentTracker.markUnchanged(qualifier);
|
||||
PsiReplacementUtil.replaceExpression(cast, qualifierText + nextInt + multiplierText +
|
||||
')', commentTracker);
|
||||
CommentTracker commentTracker = new CommentTracker();
|
||||
final String multiplierText = commentTracker.text(multiplierExpression);
|
||||
PsiReplacementUtil.replaceExpression(cast, commentTracker.text(qualifier) + ".nextInt((int) " + multiplierText + ')', commentTracker);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2008-2017 Bas Leijdekkers
|
||||
* Copyright 2008-2018 Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -77,9 +77,9 @@ public class RedundantStringFormatCallInspection extends BaseInspection {
|
||||
@NonNls final StringBuilder newExpression = new StringBuilder();
|
||||
final PsiExpression qualifierExpression = methodExpression.getQualifierExpression();
|
||||
if (qualifierExpression != null) {
|
||||
newExpression.append(commentTracker.markUnchanged(qualifierExpression).getText()).append('.');
|
||||
newExpression.append(commentTracker.text(qualifierExpression)).append('.');
|
||||
}
|
||||
newExpression.append("print").append(commentTracker.markUnchanged(methodCallExpression.getArgumentList()).getText());
|
||||
newExpression.append("print").append(commentTracker.text(methodCallExpression.getArgumentList()));
|
||||
PsiReplacementUtil.replaceExpression(methodCallExpression, newExpression.toString(), commentTracker);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2017 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2018 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -72,7 +72,7 @@ public class StringBufferToStringInConcatenationInspection extends BaseInspectio
|
||||
final PsiExpression qualifier = expression.getQualifierExpression();
|
||||
assert qualifier != null;
|
||||
CommentTracker commentTracker = new CommentTracker();
|
||||
final String newExpression = commentTracker.markUnchanged(qualifier).getText();
|
||||
final String newExpression = commentTracker.text(qualifier);
|
||||
PsiReplacementUtil.replaceExpression(methodCall, newExpression, commentTracker);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-8
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2010 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2018 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -120,13 +120,7 @@ public class StringConstructorInspection extends BaseInspection {
|
||||
assert argList != null;
|
||||
final PsiExpression[] args = argList.getExpressions();
|
||||
CommentTracker commentTracker = new CommentTracker();
|
||||
final String argText;
|
||||
if (args.length == 1) {
|
||||
argText = commentTracker.markUnchanged(args[0]).getText();
|
||||
}
|
||||
else {
|
||||
argText = "\"\"";
|
||||
}
|
||||
final String argText = (args.length == 1) ? commentTracker.text(args[0]) : "\"\"";
|
||||
|
||||
PsiReplacementUtil.replaceExpression(expression, argText, commentTracker);
|
||||
}
|
||||
|
||||
+5
-5
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2017 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2018 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -199,7 +199,7 @@ public class TailRecursionInspection extends BaseInspection {
|
||||
if (thisVariableName != null) {
|
||||
out.append(thisVariableName).append('.');
|
||||
}
|
||||
out.append(tracker.markUnchanged(element).getText());
|
||||
out.append(tracker.text(element));
|
||||
}
|
||||
else if (element instanceof PsiThisExpression || element instanceof PsiSuperExpression) {
|
||||
if (thisVariableName == null) {
|
||||
@@ -294,7 +294,7 @@ public class TailRecursionInspection extends BaseInspection {
|
||||
else {
|
||||
final PsiElement[] children = element.getChildren();
|
||||
if (children.length == 0) {
|
||||
out.append(tracker.markUnchanged(element).getText());
|
||||
out.append(tracker.text(element));
|
||||
}
|
||||
else {
|
||||
for (final PsiElement child : children) {
|
||||
@@ -312,7 +312,7 @@ public class TailRecursionInspection extends BaseInspection {
|
||||
final PsiReferenceExpression referenceExpression = (PsiReferenceExpression)element;
|
||||
final PsiElement target = referenceExpression.resolve();
|
||||
final String replacement = replacements.get(target);
|
||||
out.append(replacement != null ? replacement : tracker.markUnchanged(element).getText());
|
||||
out.append(replacement != null ? replacement : tracker.text(element));
|
||||
return;
|
||||
}
|
||||
final PsiElement[] children = element.getChildren();
|
||||
@@ -322,7 +322,7 @@ public class TailRecursionInspection extends BaseInspection {
|
||||
}
|
||||
}
|
||||
else {
|
||||
out.append(tracker.markUnchanged(element).getText());
|
||||
out.append(tracker.text(element));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+5
-5
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2013 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2018 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -89,7 +89,7 @@ public class TrivialStringConcatenationInspection extends BaseInspection {
|
||||
}
|
||||
text.append(buildReplacement(operandToReplace, seenString, commentTracker));
|
||||
text.append(" + ");
|
||||
text.append(commentTracker.markUnchanged(operand).getText());
|
||||
text.append(commentTracker.text(operand));
|
||||
replaced = true;
|
||||
continue;
|
||||
}
|
||||
@@ -107,7 +107,7 @@ public class TrivialStringConcatenationInspection extends BaseInspection {
|
||||
if (text.length() > 0) {
|
||||
text.append(" + ");
|
||||
}
|
||||
text.append(commentTracker.markUnchanged(operand).getText());
|
||||
text.append(commentTracker.text(operand));
|
||||
}
|
||||
if (!replaced && operandToReplace != null) {
|
||||
text.append(" + ");
|
||||
@@ -131,7 +131,7 @@ public class TrivialStringConcatenationInspection extends BaseInspection {
|
||||
if (seenString || ExpressionUtils.hasStringType(operandToReplace)) {
|
||||
return operandToReplace.getText();
|
||||
}
|
||||
return "String.valueOf(" + commentTracker.markUnchanged(operandToReplace).getText() + ')';
|
||||
return "String.valueOf(" + commentTracker.text(operandToReplace) + ')';
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -143,7 +143,7 @@ public class TrivialStringConcatenationInspection extends BaseInspection {
|
||||
|
||||
private final String m_name;
|
||||
|
||||
private UnnecessaryTemporaryObjectFix(PsiLiteralExpression expression) {
|
||||
UnnecessaryTemporaryObjectFix(PsiLiteralExpression expression) {
|
||||
m_name = InspectionGadgetsBundle.message("string.replace.quickfix", calculateReplacementExpression(expression, new CommentTracker()));
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2017 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2018 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -89,7 +89,7 @@ public class BoolUtils {
|
||||
if (expression instanceof PsiConditionalExpression) {
|
||||
final PsiConditionalExpression conditionalExpression = (PsiConditionalExpression)expression;
|
||||
final boolean needParenthesis = ParenthesesUtils.getPrecedence(conditionalExpression) >= precedence;
|
||||
final String text = tracker.markUnchanged(conditionalExpression.getCondition()).getText() +
|
||||
final String text = tracker.text(conditionalExpression.getCondition()) +
|
||||
'?' + getNegatedExpressionText(conditionalExpression.getThenExpression(), tracker) +
|
||||
':' + getNegatedExpressionText(conditionalExpression.getElseExpression(), tracker);
|
||||
return needParenthesis ? "(" + text + ")" : text;
|
||||
@@ -125,7 +125,7 @@ public class BoolUtils {
|
||||
result.append(negatedComparison);
|
||||
}
|
||||
}
|
||||
result.append(tracker.markUnchanged(operand).getText());
|
||||
result.append(tracker.text(operand));
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
@@ -144,7 +144,7 @@ public class BoolUtils {
|
||||
if (child instanceof PsiExpression) {
|
||||
return getNegatedExpressionText((PsiExpression)child, newPrecedence, tracker);
|
||||
}
|
||||
return child instanceof PsiJavaToken ? targetToken : tracker.markUnchanged(child).getText();
|
||||
return child instanceof PsiJavaToken ? targetToken : tracker.text(child);
|
||||
};
|
||||
final String join = StringUtil.join(polyadicExpression.getChildren(), replacer, "");
|
||||
return (newPrecedence > precedence) ? '(' + join + ')' : join;
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2016 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2018 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -78,7 +78,7 @@ public class UnusedLabelInspection extends BaseInspection {
|
||||
return;
|
||||
}
|
||||
CommentTracker commentTracker = new CommentTracker();
|
||||
final String statementText = commentTracker.markUnchanged(statement).getText();
|
||||
final String statementText = commentTracker.text(statement);
|
||||
PsiReplacementUtil.replaceStatement(labeledStatement, statementText, commentTracker);
|
||||
}
|
||||
}
|
||||
|
||||
+6
-12
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2007-2010 Bas Leijdekkers
|
||||
* Copyright 2007-2018 Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -77,10 +77,8 @@ public class CallToStringConcatCanBeReplacedByOperatorInspection
|
||||
if (!(parent instanceof PsiReferenceExpression)) {
|
||||
return;
|
||||
}
|
||||
final PsiReferenceExpression referenceExpression =
|
||||
(PsiReferenceExpression)parent;
|
||||
final PsiExpression qualifier =
|
||||
referenceExpression.getQualifierExpression();
|
||||
final PsiReferenceExpression referenceExpression = (PsiReferenceExpression)parent;
|
||||
final PsiExpression qualifier = referenceExpression.getQualifierExpression();
|
||||
if (qualifier == null) {
|
||||
return;
|
||||
}
|
||||
@@ -88,19 +86,15 @@ public class CallToStringConcatCanBeReplacedByOperatorInspection
|
||||
if (!(grandParent instanceof PsiMethodCallExpression)) {
|
||||
return;
|
||||
}
|
||||
final PsiMethodCallExpression methodCallExpression =
|
||||
(PsiMethodCallExpression)grandParent;
|
||||
final PsiExpressionList argumentList =
|
||||
methodCallExpression.getArgumentList();
|
||||
final PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression)grandParent;
|
||||
final PsiExpressionList argumentList = methodCallExpression.getArgumentList();
|
||||
final PsiExpression[] arguments = argumentList.getExpressions();
|
||||
if (arguments.length != 1) {
|
||||
return;
|
||||
}
|
||||
final PsiExpression argument = arguments[0];
|
||||
CommentTracker tracker = new CommentTracker();
|
||||
@NonNls
|
||||
final String newExpression =
|
||||
tracker.markUnchanged(qualifier).getText() + '+' + tracker.markUnchanged(argument).getText();
|
||||
@NonNls final String newExpression = tracker.text(qualifier) + '+' + tracker.text(argument);
|
||||
PsiReplacementUtil.replaceExpression(methodCallExpression, newExpression, tracker);
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2018 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -82,8 +82,8 @@ public class ConstantOnLHSOfComparisonInspection extends BaseInspection {
|
||||
}
|
||||
final PsiExpression lhs = expression.getLOperand();
|
||||
CommentTracker commentTracker = new CommentTracker();
|
||||
final String rhsText = commentTracker.markUnchanged(rhs).getText();
|
||||
final String lhsText = commentTracker.markUnchanged(lhs).getText();
|
||||
final String rhsText = commentTracker.text(rhs);
|
||||
final String lhsText = commentTracker.text(lhs);
|
||||
PsiReplacementUtil.replaceExpression(expression, rhsText + ' ' + flippedComparison + ' ' + lhsText, commentTracker);
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2018 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -82,8 +82,8 @@ public class ConstantOnRHSOfComparisonInspection extends BaseInspection {
|
||||
}
|
||||
final PsiExpression lhs = expression.getLOperand();
|
||||
CommentTracker commentTracker = new CommentTracker();
|
||||
final String rhsText = commentTracker.markUnchanged(rhs).getText();
|
||||
final String lhsText = commentTracker.markUnchanged(lhs).getText();
|
||||
final String rhsText = commentTracker.text(rhs);
|
||||
final String lhsText = commentTracker.text(lhs);
|
||||
PsiReplacementUtil.replaceExpression(expression, rhsText + ' ' + flippedComparison + ' ' + lhsText, commentTracker);
|
||||
}
|
||||
}
|
||||
|
||||
+6
-16
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2008-2015 Bas Leijdekkers
|
||||
* Copyright 2008-2018 Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -100,22 +100,12 @@ public class EqualsCalledOnEnumConstantInspection extends BaseInspection {
|
||||
not = false;
|
||||
}
|
||||
CommentTracker commentTracker = new CommentTracker();
|
||||
newExpression.append(commentTracker.markUnchanged(qualifier).getText());
|
||||
if (not) {
|
||||
newExpression.append("!=");
|
||||
}
|
||||
else {
|
||||
newExpression.append("==");
|
||||
}
|
||||
newExpression.append(commentTracker.text(qualifier));
|
||||
newExpression.append(not ? "!=" : "==");
|
||||
if (arguments.length == 1) {
|
||||
newExpression.append(commentTracker.markUnchanged(arguments[0]).getText());
|
||||
}
|
||||
if (not) {
|
||||
PsiReplacementUtil.replaceExpression(prefixExpression, newExpression.toString(), commentTracker);
|
||||
}
|
||||
else {
|
||||
PsiReplacementUtil.replaceExpression(methodCallExpression, newExpression.toString(), commentTracker);
|
||||
newExpression.append(commentTracker.text(arguments[0]));
|
||||
}
|
||||
PsiReplacementUtil.replaceExpression(not ? prefixExpression : methodCallExpression, newExpression.toString(), commentTracker);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,7 +124,7 @@ public class EqualsCalledOnEnumConstantInspection extends BaseInspection {
|
||||
}
|
||||
final PsiReferenceExpression methodExpression = expression.getMethodExpression();
|
||||
final PsiExpression qualifier = methodExpression.getQualifierExpression();
|
||||
if (qualifier == null || !TypeUtils.expressionHasTypeOrSubtype(qualifier, CommonClassNames.JAVA_LANG_ENUM)) {
|
||||
if (!TypeUtils.expressionHasTypeOrSubtype(qualifier, CommonClassNames.JAVA_LANG_ENUM)) {
|
||||
return;
|
||||
}
|
||||
final PsiExpressionList argumentList = expression.getArgumentList();
|
||||
|
||||
+3
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2011 Bas Leijdekkers
|
||||
* Copyright 2006-2018 Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -119,12 +119,11 @@ public class ListIndexOfReplaceableByContainsInspection
|
||||
qualifierText = "";
|
||||
}
|
||||
else {
|
||||
qualifierText = tracker.markUnchanged(qualifierExpression).getText();
|
||||
qualifierText = tracker.text(qualifierExpression);
|
||||
}
|
||||
final PsiExpressionList argumentList = call.getArgumentList();
|
||||
final PsiExpression expression = argumentList.getExpressions()[0];
|
||||
@NonNls final String newExpressionText =
|
||||
qualifierText + ".contains(" + tracker.markUnchanged(expression).getText() + ')';
|
||||
@NonNls final String newExpressionText = qualifierText + ".contains(" + tracker.text(expression) + ')';
|
||||
if (tokenType.equals(JavaTokenType.EQEQ)) {
|
||||
return '!' + newExpressionText;
|
||||
}
|
||||
|
||||
+4
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2015 Bas Leijdekkers
|
||||
* Copyright 2010-2018 Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -90,7 +90,7 @@ public class SimplifiableAnnotationInspection extends BaseInspection implements
|
||||
final StringBuilder out = new StringBuilder("@");
|
||||
final PsiJavaCodeReferenceElement nameReferenceElement = annotation.getNameReferenceElement();
|
||||
assert nameReferenceElement != null;
|
||||
out.append(tracker.markUnchanged(nameReferenceElement).getText());
|
||||
out.append(tracker.text(nameReferenceElement));
|
||||
final PsiAnnotationParameterList parameterList = annotation.getParameterList();
|
||||
final PsiNameValuePair[] attributes = parameterList.getAttributes();
|
||||
if (attributes.length == 0) {
|
||||
@@ -126,7 +126,7 @@ public class SimplifiableAnnotationInspection extends BaseInspection implements
|
||||
final PsiArrayInitializerMemberValue arrayValue = (PsiArrayInitializerMemberValue)value;
|
||||
final PsiAnnotationMemberValue[] initializers = arrayValue.getInitializers();
|
||||
if (initializers.length == 1) {
|
||||
out.append(tracker.markUnchanged(initializers[0]).getText());
|
||||
out.append(tracker.text(initializers[0]));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -134,7 +134,7 @@ public class SimplifiableAnnotationInspection extends BaseInspection implements
|
||||
out.append(buildAnnotationText((PsiAnnotation)value, tracker));
|
||||
return;
|
||||
}
|
||||
out.append(tracker.markUnchanged(value).getText());
|
||||
out.append(tracker.text(value));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-15
@@ -1,17 +1,5 @@
|
||||
/*
|
||||
* 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* 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;
|
||||
|
||||
@@ -66,7 +54,7 @@ public class SingleStatementInBlockInspection extends BaseInspection {
|
||||
final PsiStatement[] statements = codeBlock.getStatements();
|
||||
|
||||
CommentTracker commentTracker = new CommentTracker();
|
||||
final String text = commentTracker.markUnchanged(statements[0]).getText();
|
||||
final String text = commentTracker.text(statements[0]);
|
||||
PsiElement parent = blockStatement.getParent();
|
||||
final Project project = blockStatement.getProject();
|
||||
final PsiElement replacementExp = commentTracker.replace(blockStatement, text);
|
||||
@@ -156,7 +144,7 @@ public class SingleStatementInBlockInspection extends BaseInspection {
|
||||
private static class SingleStatementInBlockFix extends InspectionGadgetsFix {
|
||||
private final String myKeywordText;
|
||||
|
||||
private SingleStatementInBlockFix(String keywordText) {
|
||||
SingleStatementInBlockFix(String keywordText) {
|
||||
myKeywordText = keywordText;
|
||||
}
|
||||
|
||||
|
||||
+2
-14
@@ -1,17 +1,5 @@
|
||||
/*
|
||||
* 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* 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;
|
||||
|
||||
@@ -86,7 +74,7 @@ public class SizeReplaceableByIsEmptyInspectionBase extends BaseInspection {
|
||||
return;
|
||||
}
|
||||
CommentTracker commentTracker = new CommentTracker();
|
||||
@NonNls String newExpression = commentTracker.markUnchanged(qualifierExpression).getText();
|
||||
@NonNls String newExpression = commentTracker.text(qualifierExpression);
|
||||
final IElementType tokenType = binaryExpression.getOperationTokenType();
|
||||
if (!JavaTokenType.EQEQ.equals(tokenType)) {
|
||||
newExpression = '!' + newExpression;
|
||||
|
||||
+2
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2008 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2018 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -138,8 +138,7 @@ public class UnqualifiedStaticUsageInspection extends BaseInspection implements
|
||||
assert containingClass != null;
|
||||
final String className = containingClass.getName();
|
||||
CommentTracker commentTracker = new CommentTracker();
|
||||
final String text = commentTracker.markUnchanged(expression).getText();
|
||||
PsiReplacementUtil.replaceExpression(expression, className + '.' + text, commentTracker);
|
||||
PsiReplacementUtil.replaceExpression(expression, className + '.' + commentTracker.text(expression), commentTracker);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-2
@@ -1,4 +1,6 @@
|
||||
// Copyright 2000-2017 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.
|
||||
/*
|
||||
* 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.threading;
|
||||
|
||||
import com.intellij.codeInspection.ProblemDescriptor;
|
||||
@@ -25,7 +27,7 @@ abstract class AbstractReplaceWithAnotherMethodCallFix extends InspectionGadgets
|
||||
PsiReplacementUtil.replaceExpression(methodExpression, getMethodName(), commentTracker);
|
||||
}
|
||||
else {
|
||||
final String qualifierText = commentTracker.markUnchanged(qualifier).getText();
|
||||
final String qualifierText = commentTracker.text(qualifier);
|
||||
PsiReplacementUtil.replaceExpression(methodExpression, qualifierText + '.' + getMethodName(), commentTracker);
|
||||
}
|
||||
}
|
||||
|
||||
+5
-5
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2017 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2018 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -93,12 +93,12 @@ public class AssertionCanBeIfInspection extends BaseInspection {
|
||||
element instanceof PsiKeyword ? (PsiAssertStatement)element.getParent() : (PsiAssertStatement)element;
|
||||
final PsiExpression condition = assertStatement.getAssertCondition();
|
||||
CommentTracker tracker = new CommentTracker();
|
||||
@NonNls final StringBuilder newStatement =
|
||||
new StringBuilder("if(").append(BoolUtils.getNegatedExpressionText(condition,
|
||||
tracker)).append(") throw new java.lang.AssertionError(");
|
||||
final StringBuilder newStatement = new StringBuilder("if(");
|
||||
newStatement.append(BoolUtils.getNegatedExpressionText(condition, tracker));
|
||||
newStatement.append(") throw new java.lang.AssertionError(");
|
||||
final PsiExpression description = assertStatement.getAssertDescription();
|
||||
if (description != null) {
|
||||
newStatement.append(tracker.markUnchanged(description).getText());
|
||||
newStatement.append(tracker.text(description));
|
||||
}
|
||||
newStatement.append(");");
|
||||
PsiReplacementUtil.replaceStatement(assertStatement, newStatement.toString(), tracker);
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2017 Bas Leijdekkers
|
||||
* Copyright 2010-2018 Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -236,7 +236,7 @@ public class IfCanBeAssertionInspection extends BaseInspection {
|
||||
if (arguments.length < 1) {
|
||||
return null;
|
||||
}
|
||||
return tracker.markUnchanged(arguments[0]).getText();
|
||||
return tracker.text(arguments[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2017 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2018 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -123,7 +123,7 @@ public class ConditionalExpressionInspection extends BaseInspection {
|
||||
final StringBuilder newStatement = new StringBuilder();
|
||||
newStatement.append("if(");
|
||||
if (condition != null) {
|
||||
newStatement.append(tracker.markUnchanged(condition).getText());
|
||||
newStatement.append(tracker.text(condition));
|
||||
}
|
||||
newStatement.append(')');
|
||||
if (variable != null) {
|
||||
@@ -220,7 +220,7 @@ public class ConditionalExpressionInspection extends BaseInspection {
|
||||
final PsiElement[] children = element.getChildren();
|
||||
if (children.length == 0) {
|
||||
if (!(element instanceof PsiComment)) {
|
||||
out.append(tracker.markUnchanged(element).getText());
|
||||
out.append(tracker.text(element));
|
||||
}
|
||||
}
|
||||
for (PsiElement child : children) {
|
||||
|
||||
+7
-7
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2017 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2018 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -104,7 +104,7 @@ public class PointlessBooleanExpressionInspection extends BaseInspection {
|
||||
out.append(')');
|
||||
}
|
||||
else if (expression != null) {
|
||||
out.append(tracker.markUnchanged(expression).getText());
|
||||
out.append(tracker.text(expression));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
@@ -195,7 +195,7 @@ public class PointlessBooleanExpressionInspection extends BaseInspection {
|
||||
buildSimplifiedExpression(expressions, "==", negate, out, tracker);
|
||||
}
|
||||
else {
|
||||
out.append(tracker.markUnchanged(expression).getText());
|
||||
out.append(tracker.text(expression));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -207,7 +207,7 @@ public class PointlessBooleanExpressionInspection extends BaseInspection {
|
||||
if (expressions.size() == 1) {
|
||||
final PsiExpression expression = expressions.get(0);
|
||||
if (!negate) {
|
||||
out.append(tracker.markUnchanged(expression).getText());
|
||||
out.append(tracker.text(expression));
|
||||
return;
|
||||
}
|
||||
if (ComparisonUtils.isComparison(expression)) {
|
||||
@@ -216,14 +216,14 @@ public class PointlessBooleanExpressionInspection extends BaseInspection {
|
||||
final PsiExpression lhs = binaryExpression.getLOperand();
|
||||
final PsiExpression rhs = binaryExpression.getROperand();
|
||||
assert rhs != null;
|
||||
out.append(tracker.markUnchanged(lhs).getText()).append(negatedComparison).append(tracker.markUnchanged(rhs).getText());
|
||||
out.append(tracker.text(lhs)).append(negatedComparison).append(tracker.text(rhs));
|
||||
}
|
||||
else {
|
||||
if (ParenthesesUtils.getPrecedence(expression) > ParenthesesUtils.PREFIX_PRECEDENCE) {
|
||||
out.append("!(").append(tracker.markUnchanged(expression).getText()).append(')');
|
||||
out.append("!(").append(tracker.text(expression)).append(')');
|
||||
}
|
||||
else {
|
||||
out.append('!').append(tracker.markUnchanged(expression).getText());
|
||||
out.append('!').append(tracker.text(expression));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-8
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2009 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2018 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -96,13 +96,7 @@ public class ReuseOfLocalVariableInspection extends ReuseOfLocalVariableInspecti
|
||||
}
|
||||
CommentTracker commentTracker = new CommentTracker();
|
||||
final PsiExpression rhs = assignment.getRExpression();
|
||||
final String rhsText;
|
||||
if (rhs == null) {
|
||||
rhsText = "";
|
||||
}
|
||||
else {
|
||||
rhsText = commentTracker.markUnchanged(rhs).getText();
|
||||
}
|
||||
final String rhsText = rhs == null ? "" : commentTracker.text(rhs);
|
||||
@NonNls final String newStatementText = type.getCanonicalText() + ' ' + newVariableName + " = " + rhsText + ';';
|
||||
|
||||
final PsiDeclarationStatement declarationStatement = (PsiDeclarationStatement)commentTracker.replaceAndRestoreComments(assignmentStatement, newStatementText);
|
||||
|
||||
+5
-5
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
* Copyright 2000-2018 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.
|
||||
@@ -72,23 +72,23 @@ public class TryStatementWithMultipleResourcesInspection extends BaseInspection
|
||||
newTryStatementText.append("{\n");
|
||||
}
|
||||
++count;
|
||||
newTryStatementText.append("try (").append(tracker.markUnchanged(resource).getText()).append(")");
|
||||
newTryStatementText.append("try (").append(tracker.text(resource)).append(")");
|
||||
}
|
||||
final PsiCodeBlock tryBlock = tryStatement.getTryBlock();
|
||||
if (tryBlock == null) {
|
||||
return;
|
||||
}
|
||||
newTryStatementText.append(tracker.markUnchanged(tryBlock).getText());
|
||||
newTryStatementText.append(tracker.text(tryBlock));
|
||||
for (int i = 1; i < count; i++) {
|
||||
newTryStatementText.append("\n}");
|
||||
}
|
||||
final PsiCatchSection[] catchSections = tryStatement.getCatchSections();
|
||||
for (PsiCatchSection catchSection : catchSections) {
|
||||
newTryStatementText.append(tracker.markUnchanged(catchSection).getText());
|
||||
newTryStatementText.append(tracker.text(catchSection));
|
||||
}
|
||||
final PsiCodeBlock finallyBlock = tryStatement.getFinallyBlock();
|
||||
if (finallyBlock != null) {
|
||||
newTryStatementText.append("finally").append(tracker.markUnchanged(finallyBlock).getText());
|
||||
newTryStatementText.append("finally").append(tracker.text(finallyBlock));
|
||||
}
|
||||
PsiReplacementUtil.replaceStatement(tryStatement, newTryStatementText.toString(), tracker);
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2008-2017 Bas Leijdekkers
|
||||
* Copyright 2008-2018 Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -80,7 +80,7 @@ public class ExtractParameterAsLocalVariableFix extends InspectionGadgetsFix {
|
||||
final JavaCodeStyleManager javaCodeStyleManager = JavaCodeStyleManager.getInstance(project);
|
||||
final String variableName = javaCodeStyleManager.suggestUniqueVariableName(parameterName, body, true);
|
||||
CommentTracker tracker = new CommentTracker();
|
||||
final String initializerText = (rhs == null) ? parameterName : tracker.markUnchanged(rhs).getText();
|
||||
final String initializerText = (rhs == null) ? parameterName : tracker.text(rhs);
|
||||
final PsiElementFactory factory = JavaPsiFacade.getElementFactory(project);
|
||||
PsiDeclarationStatement newStatement = (PsiDeclarationStatement)
|
||||
factory.createStatementFromText(parameter.getType().getCanonicalText() + ' ' + variableName + '=' + initializerText + ';', body);
|
||||
|
||||
+6
-6
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2009-2015 Bas Leijdekkers
|
||||
* Copyright 2009-2018 Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -66,7 +66,7 @@ public class DynamicRegexReplaceableByCompiledPatternInspection extends DynamicR
|
||||
new StringBuilder("private static final java.util.regex.Pattern PATTERN = java.util.regex.Pattern.compile(");
|
||||
final int expressionsLength = expressions.length;
|
||||
if (expressionsLength > 0) {
|
||||
fieldText.append(commentTracker.markUnchanged(expressions[0]).getText());
|
||||
fieldText.append(commentTracker.text(expressions[0]));
|
||||
}
|
||||
@NonNls final String methodName = methodExpression.getReferenceName();
|
||||
final boolean literalReplacement = "replace".equals(methodName);
|
||||
@@ -77,13 +77,13 @@ public class DynamicRegexReplaceableByCompiledPatternInspection extends DynamicR
|
||||
|
||||
@NonNls final StringBuilder expressionText = new StringBuilder("PATTERN.");
|
||||
final PsiExpression qualifier = methodExpression.getQualifierExpression();
|
||||
@NonNls final String qualifierText = (qualifier == null) ? "this" : commentTracker.markUnchanged(qualifier).getText();
|
||||
@NonNls final String qualifierText = (qualifier == null) ? "this" : commentTracker.text(qualifier);
|
||||
if ("split".equals(methodName)) {
|
||||
expressionText.append(methodName);
|
||||
expressionText.append('(');
|
||||
expressionText.append(qualifierText);
|
||||
for (int i = 1; i < expressionsLength; i++) {
|
||||
expressionText.append(',').append(commentTracker.markUnchanged(expressions[i]).getText());
|
||||
expressionText.append(',').append(commentTracker.text(expressions[i]));
|
||||
}
|
||||
expressionText.append(')');
|
||||
}
|
||||
@@ -100,9 +100,9 @@ public class DynamicRegexReplaceableByCompiledPatternInspection extends DynamicR
|
||||
expressionText.append("java.util.regex.Matcher.quoteReplacement(");
|
||||
}
|
||||
if (expressionsLength > 1) {
|
||||
expressionText.append(commentTracker.markUnchanged(expressions[1]).getText());
|
||||
expressionText.append(commentTracker.text(expressions[1]));
|
||||
for (int i = 2; i < expressionsLength; i++) {
|
||||
expressionText.append(',').append(commentTracker.markUnchanged(expressions[i]).getText());
|
||||
expressionText.append(',').append(commentTracker.text(expressions[i]));
|
||||
}
|
||||
}
|
||||
if (literalReplacement) {
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
* Copyright 2000-2018 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.
|
||||
@@ -83,7 +83,7 @@ public class ObjectsRequireNonNullIntention extends Intention {
|
||||
commentTracker.delete(statementToDelete);
|
||||
}
|
||||
PsiReplacementUtil.replaceExpressionAndShorten(referenceExpression,
|
||||
"java.util.Objects.requireNonNull(" + commentTracker.markUnchanged(referenceExpression).getText() + ")",
|
||||
"java.util.Objects.requireNonNull(" + commentTracker.text(referenceExpression) + ")",
|
||||
commentTracker);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2015 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2018 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -79,12 +79,12 @@ public class DemorgansIntention extends MutablyNamedIntention {
|
||||
}
|
||||
if (tokenTypeAndAnd) {
|
||||
if (ParenthesesUtils.getPrecedence(negatedExpression) > ParenthesesUtils.OR_PRECEDENCE) {
|
||||
return '(' + tracker.markUnchanged(negatedExpression).getText() + ')';
|
||||
return '(' + tracker.text(negatedExpression) + ')';
|
||||
}
|
||||
} else if (ParenthesesUtils.getPrecedence(negatedExpression) > ParenthesesUtils.AND_PRECEDENCE) {
|
||||
return '(' + tracker.markUnchanged(negatedExpression).getText() + ')';
|
||||
return '(' + tracker.text(negatedExpression) + ')';
|
||||
}
|
||||
return tracker.markUnchanged(negatedExpression).getText();
|
||||
return tracker.text(negatedExpression);
|
||||
}
|
||||
else if (ComparisonUtils.isComparison(expression)) {
|
||||
final PsiBinaryExpression binaryExpression = (PsiBinaryExpression)expression;
|
||||
@@ -92,13 +92,13 @@ public class DemorgansIntention extends MutablyNamedIntention {
|
||||
final PsiExpression lhs = binaryExpression.getLOperand();
|
||||
final PsiExpression rhs = binaryExpression.getROperand();
|
||||
assert rhs != null;
|
||||
return tracker.markUnchanged(lhs).getText() + negatedComparison + tracker.markUnchanged(rhs).getText();
|
||||
return tracker.text(lhs) + negatedComparison + tracker.text(rhs);
|
||||
}
|
||||
else if (ParenthesesUtils.getPrecedence(expression) > ParenthesesUtils.PREFIX_PRECEDENCE) {
|
||||
return "!(" + tracker.markUnchanged(expression).getText() + ')';
|
||||
return "!(" + tracker.text(expression) + ')';
|
||||
}
|
||||
else {
|
||||
return '!' + tracker.markUnchanged(expression).getText();
|
||||
return '!' + tracker.text(expression);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2014 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2018 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -66,9 +66,9 @@ public class FlipComparisonIntention extends MutablyNamedIntention {
|
||||
final IElementType tokenType = expression.getOperationTokenType();
|
||||
assert rhs != null;
|
||||
CommentTracker commentTracker = new CommentTracker();
|
||||
final String expString = commentTracker.markUnchanged(rhs).getText() +
|
||||
final String expString = commentTracker.text(rhs) +
|
||||
ComparisonUtils.getFlippedComparison(tokenType) +
|
||||
commentTracker.markUnchanged(lhs).getText();
|
||||
commentTracker.text(lhs);
|
||||
PsiReplacementUtil.replaceExpression(expression, expString, commentTracker);
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2013 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* 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.ipp.bool;
|
||||
|
||||
@@ -37,7 +25,7 @@ public class NegateConditionalIntention extends Intention {
|
||||
PsiExpression thenExpression = conditionalExpression.getThenExpression();
|
||||
PsiExpression elseExpression = conditionalExpression.getElseExpression();
|
||||
CommentTracker tracker = new CommentTracker();
|
||||
final String newExpression = tracker.markUnchanged(condition).getText() + '?' +
|
||||
final String newExpression = tracker.text(condition) + '?' +
|
||||
BoolUtils.getNegatedExpressionText(thenExpression, tracker) + ':' +
|
||||
BoolUtils.getNegatedExpressionText(elseExpression, tracker);
|
||||
replaceExpressionWithNegatedExpressionString(newExpression, conditionalExpression, tracker);
|
||||
|
||||
+3
-15
@@ -1,17 +1,5 @@
|
||||
/*
|
||||
* 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* 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.ipp.collections;
|
||||
|
||||
@@ -78,9 +66,9 @@ public class ReplaceWithArraysAsListIntention extends Intention implements HighP
|
||||
CommentTracker commentTracker = new CommentTracker();
|
||||
if (parameterList != null) {
|
||||
final int dotIndex = replacementText.lastIndexOf('.') + 1;
|
||||
replacementText = replacementText.substring(0, dotIndex) + commentTracker.markUnchanged(parameterList).getText() + replacementText.substring(dotIndex);
|
||||
replacementText = replacementText.substring(0, dotIndex) + commentTracker.text(parameterList) + replacementText.substring(dotIndex);
|
||||
}
|
||||
PsiReplacementUtil.replaceExpressionAndShorten(methodCallExpression, replacementText + commentTracker.markUnchanged(argumentList).getText(), commentTracker);
|
||||
PsiReplacementUtil.replaceExpressionAndShorten(methodCallExpression, replacementText + commentTracker.text(argumentList), commentTracker);
|
||||
}
|
||||
|
||||
private static String getReplacementMethodText(String methodName, PsiMethodCallExpression context) {
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2017 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2018 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -79,7 +79,7 @@ public class JoinConcatenatedStringLiteralsIntention extends Intention {
|
||||
}
|
||||
else {
|
||||
if (buffer.isEmpty()) {
|
||||
newExpression.append(tracker.markUnchanged(child).getText());
|
||||
newExpression.append(tracker.text(child));
|
||||
}
|
||||
else {
|
||||
buffer.add(child);
|
||||
@@ -87,7 +87,7 @@ public class JoinConcatenatedStringLiteralsIntention extends Intention {
|
||||
}
|
||||
}
|
||||
for (PsiElement bufferedElement : buffer) {
|
||||
newExpression.append(tracker.markUnchanged(bufferedElement).getText());
|
||||
newExpression.append(tracker.text(bufferedElement));
|
||||
}
|
||||
PsiReplacementUtil.replaceExpression(polyadicExpression, newExpression.toString(), tracker);
|
||||
}
|
||||
|
||||
+4
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2008-2017 Bas Leijdekkers
|
||||
* Copyright 2008-2018 Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -56,7 +56,7 @@ public class ReplaceConcatenationWithFormatStringIntention extends Intention {
|
||||
newExpression.append('\"');
|
||||
for (PsiExpression formatParameter : formatParameters) {
|
||||
newExpression.append(", ");
|
||||
newExpression.append(commentTracker.markUnchanged(formatParameter).getText());
|
||||
newExpression.append(commentTracker.text(formatParameter));
|
||||
}
|
||||
newExpression.append(')');
|
||||
PsiReplacementUtil.replaceExpression(expression, newExpression.toString(), commentTracker);
|
||||
@@ -102,7 +102,7 @@ public class ReplaceConcatenationWithFormatStringIntention extends Intention {
|
||||
final StringBuilder newExpression = new StringBuilder();
|
||||
final PsiExpression qualifier = methodExpression.getQualifierExpression();
|
||||
if (qualifier != null) {
|
||||
newExpression.append(commentTracker.markUnchanged(qualifier).getText()).append('.');
|
||||
newExpression.append(commentTracker.text(qualifier)).append('.');
|
||||
}
|
||||
newExpression.append("printf(\"").append(formatString);
|
||||
if (insertNewline) {
|
||||
@@ -110,7 +110,7 @@ public class ReplaceConcatenationWithFormatStringIntention extends Intention {
|
||||
}
|
||||
newExpression.append('\"');
|
||||
for (PsiExpression formatParameter : formatParameters) {
|
||||
newExpression.append(", ").append(commentTracker.markUnchanged(formatParameter).getText());
|
||||
newExpression.append(", ").append(commentTracker.text(formatParameter));
|
||||
}
|
||||
newExpression.append(')');
|
||||
PsiReplacementUtil.replaceExpression(methodCallExpression, newExpression.toString(), commentTracker);
|
||||
|
||||
+5
-5
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2015 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2018 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -65,7 +65,7 @@ public class ReplaceConcatenationWithStringBufferIntention extends MutablyNamedI
|
||||
final PsiExpression qualifierExpression = methodExpression.getQualifierExpression();
|
||||
|
||||
if (qualifierExpression != null) {
|
||||
final String qualifierText = commentTracker.markUnchanged(qualifierExpression).getText();
|
||||
final String qualifierText = commentTracker.text(qualifierExpression);
|
||||
newExpression.append(qualifierText);
|
||||
}
|
||||
turnExpressionIntoChainedAppends(expression, newExpression, commentTracker);
|
||||
@@ -114,7 +114,7 @@ public class ReplaceConcatenationWithStringBufferIntention extends MutablyNamedI
|
||||
final PsiPolyadicExpression concatenation = (PsiPolyadicExpression)expression;
|
||||
final PsiType type = concatenation.getType();
|
||||
if (type != null && !type.equalsToText(CommonClassNames.JAVA_LANG_STRING)) {
|
||||
result.append(".append(").append(commentTracker.markUnchanged(concatenation).getText()).append(')');
|
||||
result.append(".append(").append(commentTracker.text(concatenation)).append(')');
|
||||
return;
|
||||
}
|
||||
final PsiExpression[] operands = concatenation.getOperands();
|
||||
@@ -138,7 +138,7 @@ public class ReplaceConcatenationWithStringBufferIntention extends MutablyNamedI
|
||||
turnExpressionIntoChainedAppends(operand, result, commentTracker);
|
||||
string = true;
|
||||
}
|
||||
newExpressionText.append('+').append(commentTracker.markUnchanged(operand).getText());
|
||||
newExpressionText.append('+').append(commentTracker.text(operand));
|
||||
} else {
|
||||
turnExpressionIntoChainedAppends(operand, result, commentTracker);
|
||||
}
|
||||
@@ -148,7 +148,7 @@ public class ReplaceConcatenationWithStringBufferIntention extends MutablyNamedI
|
||||
final PsiExpression strippedExpression = ParenthesesUtils.stripParentheses(expression);
|
||||
result.append(".append(");
|
||||
if (strippedExpression != null) {
|
||||
result.append(commentTracker.markUnchanged(strippedExpression).getText());
|
||||
result.append(commentTracker.text(strippedExpression));
|
||||
}
|
||||
result.append(')');
|
||||
}
|
||||
|
||||
+5
-3
@@ -1,4 +1,6 @@
|
||||
// Copyright 2000-2017 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.
|
||||
/*
|
||||
* 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.ipp.concatenation;
|
||||
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
@@ -102,10 +104,10 @@ public class ReplaceFormatStringWithConcatenationIntention extends Intention {
|
||||
count++;
|
||||
final PsiExpression argument = arguments[indexOfFormatString + count];
|
||||
if (builder.length() == 0 && !ExpressionUtils.hasStringType(argument)) {
|
||||
builder.append("String.valueOf(").append(commentTracker.markUnchanged(argument).getText()).append(')');
|
||||
builder.append("String.valueOf(").append(commentTracker.text(argument)).append(')');
|
||||
}
|
||||
else {
|
||||
builder.append(commentTracker.markUnchanged(argument).getText());
|
||||
builder.append(commentTracker.text(argument));
|
||||
}
|
||||
start = end + 2;
|
||||
end = value.indexOf("%s", start);
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2015 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2018 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -44,7 +44,7 @@ public class FlipConditionalIntention extends Intention {
|
||||
assert thenExpression != null;
|
||||
CommentTracker tracker = new CommentTracker();
|
||||
final String newExpression = BoolUtils.getNegatedExpressionText(condition, tracker) + '?' +
|
||||
tracker.markUnchanged(elseExpression).getText() + ':' + tracker.markUnchanged(thenExpression).getText();
|
||||
tracker.text(elseExpression) + ':' + tracker.text(thenExpression);
|
||||
PsiReplacementUtil.replaceExpression(exp, newExpression, tracker);
|
||||
}
|
||||
}
|
||||
|
||||
+3
-15
@@ -1,17 +1,5 @@
|
||||
/*
|
||||
* 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* 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.ipp.conditional;
|
||||
|
||||
@@ -68,10 +56,10 @@ public class ReplaceConditionalWithBooleanExpressionIntention extends Intention
|
||||
return "";
|
||||
}
|
||||
if (ParenthesesUtils.getPrecedence(expression) > AND_PRECEDENCE) {
|
||||
return '(' + tracker.markUnchanged(expression).getText() + ')';
|
||||
return '(' + tracker.text(expression) + ')';
|
||||
}
|
||||
else {
|
||||
return tracker.markUnchanged(expression).getText();
|
||||
return tracker.text(expression);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2013 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2018 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -135,7 +135,7 @@ public class ConstantSubexpressionIntention extends MutablyNamedIntention {
|
||||
newExpressionText.append(prevToken.getText());
|
||||
}
|
||||
if (prevOperand != null) {
|
||||
newExpressionText.append(commentTracker.markUnchanged(prevOperand).getText());
|
||||
newExpressionText.append(commentTracker.text(prevOperand));
|
||||
}
|
||||
prevOperand = operand;
|
||||
prevToken = currentToken;
|
||||
@@ -145,7 +145,7 @@ public class ConstantSubexpressionIntention extends MutablyNamedIntention {
|
||||
newExpressionText.append(prevToken.getText());
|
||||
}
|
||||
if (prevOperand != null) {
|
||||
newExpressionText.append(commentTracker.markUnchanged(prevOperand).getText());
|
||||
newExpressionText.append(commentTracker.text(prevOperand));
|
||||
}
|
||||
|
||||
PsiReplacementUtil.replaceExpression(polyadicExpression, newExpressionText.toString(), commentTracker);
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2016 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2018 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -70,7 +70,7 @@ public class CreateEnumSwitchBranchesIntention extends Intention {
|
||||
// replace entire switch statement if no code block is present
|
||||
@NonNls final StringBuilder newStatementText = new StringBuilder();
|
||||
CommentTracker commentTracker = new CommentTracker();
|
||||
newStatementText.append("switch(").append(commentTracker.markUnchanged(switchExpression).getText()).append("){");
|
||||
newStatementText.append("switch(").append(commentTracker.text(switchExpression)).append("){");
|
||||
for (PsiEnumConstant missingEnumElement : missingEnumElements) {
|
||||
newStatementText.append("case ").append(commentTracker.markUnchanged(missingEnumElement).getName()).append(": break;");
|
||||
}
|
||||
|
||||
+5
-5
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2016 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2018 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -44,14 +44,14 @@ public class DetailExceptionsIntention extends Intention {
|
||||
final Set<PsiClassType> exceptionsThrown = new HashSet<>();
|
||||
final PsiResourceList resourceList = tryStatement.getResourceList();
|
||||
if (resourceList != null) {
|
||||
newTryStatement.append(commentTracker.markUnchanged(resourceList).getText());
|
||||
newTryStatement.append(commentTracker.text(resourceList));
|
||||
ExceptionUtils.calculateExceptionsThrown(resourceList, exceptionsThrown);
|
||||
}
|
||||
final PsiCodeBlock tryBlock = tryStatement.getTryBlock();
|
||||
if (tryBlock == null) {
|
||||
return;
|
||||
}
|
||||
final String tryBlockText = commentTracker.markUnchanged(tryBlock).getText();
|
||||
final String tryBlockText = commentTracker.text(tryBlock);
|
||||
newTryStatement.append(tryBlockText);
|
||||
ExceptionUtils.calculateExceptionsThrown(tryBlock, exceptionsThrown);
|
||||
final Comparator<PsiType> comparator = new HierarchicalTypeComparator();
|
||||
@@ -85,13 +85,13 @@ public class DetailExceptionsIntention extends Intention {
|
||||
}
|
||||
for (PsiClassType thrownType : exceptionsToExpand) {
|
||||
newTryStatement.append("catch(").append(thrownType.getCanonicalText()).append(' ').append(parameter.getName()).append(')');
|
||||
newTryStatement.append(commentTracker.markUnchanged(block).getText());
|
||||
newTryStatement.append(commentTracker.text(block));
|
||||
}
|
||||
}
|
||||
}
|
||||
final PsiCodeBlock finallyBlock = tryStatement.getFinallyBlock();
|
||||
if (finallyBlock != null) {
|
||||
newTryStatement.append("finally").append(commentTracker.markUnchanged(finallyBlock).getText());
|
||||
newTryStatement.append("finally").append(commentTracker.text(finallyBlock));
|
||||
}
|
||||
final String newStatement = newTryStatement.toString();
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2007-2015 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2007-2018 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -71,13 +71,13 @@ public class FlipExpressionIntention extends MutablyNamedIntention {
|
||||
for (PsiExpression operand : operands) {
|
||||
final PsiJavaToken token1 = polyadicExpression.getTokenBeforeOperand(operand);
|
||||
if (token == token1) {
|
||||
newExpression.append(commentTracker.markUnchanged(operand).getText()).append(tokenText);
|
||||
newExpression.append(commentTracker.text(operand)).append(tokenText);
|
||||
continue;
|
||||
}
|
||||
if (prevOperand != null) {
|
||||
newExpression.append(prevOperand).append(tokenText);
|
||||
}
|
||||
prevOperand = commentTracker.markUnchanged(operand).getText();
|
||||
prevOperand = commentTracker.text(operand);
|
||||
}
|
||||
newExpression.append(prevOperand);
|
||||
|
||||
|
||||
+4
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2015 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2018 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -95,11 +95,11 @@ public class ReplaceForEachLoopWithIndexedForLoopIntention extends Intention {
|
||||
final PsiElement[] children = block.getChildren();
|
||||
for (int i = 1; i < children.length - 1; i++) {
|
||||
//skip the braces
|
||||
newStatement.append(tracker.markUnchanged(children[i]).getText());
|
||||
newStatement.append(tracker.text(children[i]));
|
||||
}
|
||||
}
|
||||
else {
|
||||
newStatement.append(tracker.markUnchanged(body).getText());
|
||||
newStatement.append(tracker.text(body));
|
||||
}
|
||||
newStatement.append('}');
|
||||
PsiReplacementUtil.replaceStatementAndShortenClassNames(statement, newStatement.toString(), tracker);
|
||||
@@ -219,7 +219,7 @@ public class ReplaceForEachLoopWithIndexedForLoopIntention extends Intention {
|
||||
}
|
||||
return createVariable(variableName, expression, context);
|
||||
}
|
||||
return tracker.markUnchanged(expression).getText();
|
||||
return tracker.text(expression);
|
||||
}
|
||||
|
||||
private static String createVariable(String variableNameRoot,
|
||||
|
||||
+5
-5
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2013 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2018 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -55,10 +55,10 @@ public class ReplaceForEachLoopWithIteratorForLoopIntention extends Intention {
|
||||
CommentTracker tracker = new CommentTracker();
|
||||
@NonNls final StringBuilder methodCall = new StringBuilder();
|
||||
if (ParenthesesUtils.getPrecedence(iteratedValue) > ParenthesesUtils.METHOD_CALL_PRECEDENCE) {
|
||||
methodCall.append('(').append(tracker.markUnchanged(iteratedValue).getText()).append(')');
|
||||
methodCall.append('(').append(tracker.text(iteratedValue)).append(')');
|
||||
}
|
||||
else {
|
||||
methodCall.append(tracker.markUnchanged(iteratedValue).getText());
|
||||
methodCall.append(tracker.text(iteratedValue));
|
||||
}
|
||||
methodCall.append(".iterator()");
|
||||
final Project project = statement.getProject();
|
||||
@@ -91,11 +91,11 @@ public class ReplaceForEachLoopWithIteratorForLoopIntention extends Intention {
|
||||
final PsiElement[] children = block.getChildren();
|
||||
for (int i = 1; i < children.length - 1; i++) {
|
||||
//skip the braces
|
||||
newStatement.append(tracker.markUnchanged(children[i]).getText());
|
||||
newStatement.append(tracker.text(children[i]));
|
||||
}
|
||||
}
|
||||
else {
|
||||
newStatement.append(tracker.markUnchanged(body).getText());
|
||||
newStatement.append(tracker.text(body));
|
||||
}
|
||||
newStatement.append('}');
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2015 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2018 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -76,7 +76,7 @@ public class FlipAssertLiteralIntention extends MutablyNamedIntention {
|
||||
}
|
||||
}
|
||||
else {
|
||||
newCall.append(tracker.markUnchanged(qualifier).getText()).append('.');
|
||||
newCall.append(tracker.text(qualifier)).append('.');
|
||||
}
|
||||
newCall.append(toMethodName).append('(');
|
||||
final PsiExpressionList argumentList = call.getArgumentList();
|
||||
@@ -86,7 +86,7 @@ public class FlipAssertLiteralIntention extends MutablyNamedIntention {
|
||||
newCall.append(BoolUtils.getNegatedExpressionText(arguments[0], tracker));
|
||||
}
|
||||
else {
|
||||
newCall.append(tracker.markUnchanged(arguments[0]).getText()).append(',');
|
||||
newCall.append(tracker.text(arguments[0])).append(',');
|
||||
newCall.append(BoolUtils.getNegatedExpressionText(arguments[1], tracker));
|
||||
}
|
||||
newCall.append(')');
|
||||
|
||||
+6
-6
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2014 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2018 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -91,7 +91,7 @@ public class ReplaceAssertLiteralWithAssertEqualsIntention extends MutablyNamedI
|
||||
final PsiExpression[] arguments = argumentList.getExpressions();
|
||||
CommentTracker commentTracker = new CommentTracker();
|
||||
if (arguments.length > 1) {
|
||||
newExpression.append(commentTracker.markUnchanged(arguments[0]).getText()).append(", ");
|
||||
newExpression.append(commentTracker.text(arguments[0])).append(", ");
|
||||
}
|
||||
final PsiExpression lastArgument = arguments[arguments.length - 1];
|
||||
if (lastArgument instanceof PsiBinaryExpression) {
|
||||
@@ -100,18 +100,18 @@ public class ReplaceAssertLiteralWithAssertEqualsIntention extends MutablyNamedI
|
||||
if (("assertTrue".equals(methodName) && JavaTokenType.EQEQ.equals(tokenType)) ||
|
||||
("assertFalse".equals(methodName) && JavaTokenType.NE.equals(tokenType))) {
|
||||
final PsiExpression lhs = binaryExpression.getLOperand();
|
||||
newExpression.append(commentTracker.markUnchanged(lhs).getText()).append(", ");
|
||||
newExpression.append(commentTracker.text(lhs)).append(", ");
|
||||
final PsiExpression rhs = binaryExpression.getROperand();
|
||||
if (rhs != null) {
|
||||
newExpression.append(commentTracker.markUnchanged(rhs).getText());
|
||||
newExpression.append(commentTracker.text(rhs));
|
||||
}
|
||||
}
|
||||
else {
|
||||
newExpression.append(literal).append(", ").append(commentTracker.markUnchanged(lastArgument).getText());
|
||||
newExpression.append(literal).append(", ").append(commentTracker.text(lastArgument));
|
||||
}
|
||||
}
|
||||
else {
|
||||
newExpression.append(literal).append(", ").append(commentTracker.markUnchanged(lastArgument).getText());
|
||||
newExpression.append(literal).append(", ").append(commentTracker.text(lastArgument));
|
||||
}
|
||||
newExpression.append(')');
|
||||
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2009 Bas Leijdekkers
|
||||
* Copyright 2009-2018 Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -68,7 +68,7 @@ public class ReplaceAssignmentWithPostfixExpressionIntention
|
||||
(PsiAssignmentExpression)element;
|
||||
final PsiExpression lhs = assignmentExpression.getLExpression();
|
||||
CommentTracker commentTracker = new CommentTracker();
|
||||
final String lhsText = commentTracker.markUnchanged(lhs).getText();
|
||||
final String lhsText = commentTracker.text(lhs);
|
||||
final PsiExpression rhs = assignmentExpression.getRExpression();
|
||||
if (!(rhs instanceof PsiBinaryExpression)) {
|
||||
return;
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2009 Bas Leijdekkers
|
||||
* Copyright 2009-2018 Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -60,7 +60,7 @@ public class ReplaceOperatorAssignmentWithPostfixExpressionIntention
|
||||
(PsiAssignmentExpression)element;
|
||||
final PsiExpression expression = assignment.getLExpression();
|
||||
CommentTracker commentTracker = new CommentTracker();
|
||||
final String expressionText = commentTracker.markUnchanged(expression).getText();
|
||||
final String expressionText = commentTracker.text(expression);
|
||||
final IElementType tokenType = assignment.getOperationTokenType();
|
||||
final String newExpressionText;
|
||||
if (JavaTokenType.PLUSEQ.equals(tokenType)) {
|
||||
|
||||
+3
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2009 Bas Leijdekkers
|
||||
* Copyright 2009-2018 Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -52,9 +52,8 @@ public class ReplacePostfixExpressionWithAssignmentIntention
|
||||
final PsiPostfixExpression postfixExpression = (PsiPostfixExpression)element;
|
||||
final PsiExpression operand = postfixExpression.getOperand();
|
||||
CommentTracker commentTracker = new CommentTracker();
|
||||
final String operandText = commentTracker.markUnchanged(operand).getText();
|
||||
final IElementType tokenType =
|
||||
postfixExpression.getOperationTokenType();
|
||||
final String operandText = commentTracker.text(operand);
|
||||
final IElementType tokenType = postfixExpression.getOperationTokenType();
|
||||
if (JavaTokenType.PLUSPLUS.equals(tokenType)) {
|
||||
PsiReplacementUtil.replaceExpression(postfixExpression, operandText + '=' + operandText + "+1", commentTracker);
|
||||
}
|
||||
|
||||
+3
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2009 Bas Leijdekkers
|
||||
* Copyright 2009-2018 Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -60,9 +60,8 @@ public class ReplacePostfixExpressionWithOperatorAssignmentIntention
|
||||
(PsiPostfixExpression)element;
|
||||
final PsiExpression operand = postfixExpression.getOperand();
|
||||
CommentTracker commentTracker = new CommentTracker();
|
||||
final String operandText = commentTracker.markUnchanged(operand).getText();
|
||||
final IElementType tokenType =
|
||||
postfixExpression.getOperationTokenType();
|
||||
final String operandText = commentTracker.text(operand);
|
||||
final IElementType tokenType = postfixExpression.getOperationTokenType();
|
||||
if (JavaTokenType.PLUSPLUS.equals(tokenType)) {
|
||||
PsiReplacementUtil.replaceExpression(postfixExpression, operandText + "+=1", commentTracker);
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2013 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2018 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -65,7 +65,7 @@ public class ReplaceWithOperatorAssignmentIntention extends MutablyNamedIntentio
|
||||
else {
|
||||
token = true;
|
||||
}
|
||||
newExpression.append(commentTracker.markUnchanged(operand).getText());
|
||||
newExpression.append(commentTracker.text(operand));
|
||||
}
|
||||
PsiReplacementUtil.replaceExpression(expression, newExpression.toString(), commentTracker);
|
||||
}
|
||||
|
||||
+2
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2013 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2018 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -92,8 +92,7 @@ public class ReplaceMultiplyWithShiftIntention extends MutablyNamedIntention {
|
||||
assignString = ">>=";
|
||||
}
|
||||
CommentTracker commentTracker = new CommentTracker();
|
||||
final String expString =
|
||||
commentTracker.markUnchanged(lhs).getText() + assignString + ShiftUtils.getLogBase2(rhs);
|
||||
final String expString = commentTracker.text(lhs) + assignString + ShiftUtils.getLogBase2(rhs);
|
||||
PsiReplacementUtil.replaceExpression(expression, expString, commentTracker);
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2013 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2018 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -97,7 +97,7 @@ public class ReplaceShiftWithMultiplyIntention extends MutablyNamedIntention {
|
||||
}
|
||||
CommentTracker commentTracker = new CommentTracker();
|
||||
final String expString =
|
||||
commentTracker.markUnchanged(lhs).getText() + assignString + ShiftUtils.getExpBase2(rhs);
|
||||
commentTracker.text(lhs) + assignString + ShiftUtils.getExpBase2(rhs);
|
||||
PsiReplacementUtil.replaceExpression(exp, expString, commentTracker);
|
||||
}
|
||||
|
||||
|
||||
+2
-14
@@ -1,17 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2013 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
* 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.ipp.trivialif;
|
||||
|
||||
@@ -107,7 +95,7 @@ public class ConvertToNestedIfIntention extends Intention {
|
||||
return out;
|
||||
}
|
||||
if (expression != null) {
|
||||
out.append("if(").append(tracker.markUnchanged(expression).getText()).append(")");
|
||||
out.append("if(").append(tracker.text(expression)).append(")");
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2013 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2018 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -56,10 +56,10 @@ public class MergeIfOrIntention extends Intention {
|
||||
CommentTracker tracker = new CommentTracker();
|
||||
final String childConditionText;
|
||||
if (ParenthesesUtils.getPrecedence(childCondition) > ParenthesesUtils.OR_PRECEDENCE) {
|
||||
childConditionText = '(' + tracker.markUnchanged(childCondition).getText() + ')';
|
||||
childConditionText = '(' + tracker.text(childCondition) + ')';
|
||||
}
|
||||
else {
|
||||
childConditionText = tracker.markUnchanged(childCondition).getText();
|
||||
childConditionText = tracker.text(childCondition);
|
||||
}
|
||||
final PsiExpression condition = parentStatement.getCondition();
|
||||
if (condition == null) {
|
||||
@@ -67,16 +67,16 @@ public class MergeIfOrIntention extends Intention {
|
||||
}
|
||||
final String parentConditionText;
|
||||
if (ParenthesesUtils.getPrecedence(condition) > ParenthesesUtils.OR_PRECEDENCE) {
|
||||
parentConditionText = '(' + tracker.markUnchanged(condition).getText() + ')';
|
||||
parentConditionText = '(' + tracker.text(condition) + ')';
|
||||
}
|
||||
else {
|
||||
parentConditionText = tracker.markUnchanged(condition).getText();
|
||||
parentConditionText = tracker.text(condition);
|
||||
}
|
||||
final PsiStatement parentThenBranch = parentStatement.getThenBranch();
|
||||
if (parentThenBranch == null) {
|
||||
return;
|
||||
}
|
||||
final String parentThenBranchText = tracker.markUnchanged(parentThenBranch).getText();
|
||||
final String parentThenBranchText = tracker.text(parentThenBranch);
|
||||
@NonNls final StringBuilder statement = new StringBuilder();
|
||||
statement.append("if(");
|
||||
statement.append(parentConditionText);
|
||||
@@ -87,7 +87,7 @@ public class MergeIfOrIntention extends Intention {
|
||||
final PsiStatement childElseBranch = childStatement.getElseBranch();
|
||||
if (childElseBranch != null) {
|
||||
statement.append("else ");
|
||||
statement.append(tracker.markUnchanged(childElseBranch).getText());
|
||||
statement.append(tracker.text(childElseBranch));
|
||||
}
|
||||
final String newStatement = statement.toString();
|
||||
PsiReplacementUtil.replaceStatement(parentStatement, newStatement, tracker);
|
||||
@@ -104,10 +104,10 @@ public class MergeIfOrIntention extends Intention {
|
||||
CommentTracker tracker = new CommentTracker();
|
||||
final String childConditionText;
|
||||
if (ParenthesesUtils.getPrecedence(childCondition) > ParenthesesUtils.OR_PRECEDENCE) {
|
||||
childConditionText = '(' + tracker.markUnchanged(childCondition).getText() + ')';
|
||||
childConditionText = '(' + tracker.text(childCondition) + ')';
|
||||
}
|
||||
else {
|
||||
childConditionText = tracker.markUnchanged(childCondition).getText();
|
||||
childConditionText = tracker.text(childCondition);
|
||||
}
|
||||
final PsiExpression condition = parentStatement.getCondition();
|
||||
if (condition == null) {
|
||||
@@ -115,10 +115,10 @@ public class MergeIfOrIntention extends Intention {
|
||||
}
|
||||
final String parentConditionText;
|
||||
if (ParenthesesUtils.getPrecedence(condition) > ParenthesesUtils.OR_PRECEDENCE) {
|
||||
parentConditionText = '(' + tracker.markUnchanged(condition).getText() + ')';
|
||||
parentConditionText = '(' + tracker.text(condition) + ')';
|
||||
}
|
||||
else {
|
||||
parentConditionText = tracker.markUnchanged(condition).getText();
|
||||
parentConditionText = tracker.text(condition);
|
||||
}
|
||||
final PsiStatement parentThenBranch = parentStatement.getThenBranch();
|
||||
if (parentThenBranch == null) {
|
||||
@@ -130,11 +130,11 @@ public class MergeIfOrIntention extends Intention {
|
||||
newStatement.append("||");
|
||||
newStatement.append(childConditionText);
|
||||
newStatement.append(')');
|
||||
newStatement.append(tracker.markUnchanged(parentThenBranch).getText());
|
||||
newStatement.append(tracker.text(parentThenBranch));
|
||||
final PsiStatement childElseBranch = childStatement.getElseBranch();
|
||||
if (childElseBranch != null) {
|
||||
newStatement.append("else ");
|
||||
newStatement.append(tracker.markUnchanged(childElseBranch).getText());
|
||||
newStatement.append(tracker.text(childElseBranch));
|
||||
}
|
||||
PsiReplacementUtil.replaceStatement(parentStatement, newStatement.toString());
|
||||
tracker.deleteAndRestoreComments(childStatement);
|
||||
|
||||
+6
-6
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2013 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2018 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -57,7 +57,7 @@ public class ReplaceIfWithConditionalIntention extends Intention {
|
||||
final PsiAssignmentExpression elseAssign = (PsiAssignmentExpression)strippedElseBranch.getExpression();
|
||||
CommentTracker commentTracker = new CommentTracker();
|
||||
final PsiExpression lhs = thenAssign.getLExpression();
|
||||
final String lhsText = commentTracker.markUnchanged(lhs).getText();
|
||||
final String lhsText = commentTracker.text(lhs);
|
||||
final PsiJavaToken sign = thenAssign.getOperationSign();
|
||||
final String operator = sign.getText();
|
||||
final PsiExpression thenRhs = thenAssign.getRExpression();
|
||||
@@ -105,7 +105,7 @@ public class ReplaceIfWithConditionalIntention extends Intention {
|
||||
final PsiExpressionStatement elseBranch = (PsiExpressionStatement)ControlFlowUtils.stripBraces(ifStatement.getElseBranch());
|
||||
final PsiMethodCallExpression thenMethodCallExpression = (PsiMethodCallExpression)thenBranch.getExpression();
|
||||
final PsiMethodCallExpression elseMethodCallExpression = (PsiMethodCallExpression)elseBranch.getExpression();
|
||||
final StringBuilder replacementText = new StringBuilder(commentTracker.markUnchanged(thenMethodCallExpression.getMethodExpression()).getText());
|
||||
final StringBuilder replacementText = new StringBuilder(commentTracker.text(thenMethodCallExpression.getMethodExpression()));
|
||||
replacementText.append('(');
|
||||
final PsiExpressionList thenArgumentList = thenMethodCallExpression.getArgumentList();
|
||||
final PsiExpression[] thenArguments = thenArgumentList.getExpressions();
|
||||
@@ -118,7 +118,7 @@ public class ReplaceIfWithConditionalIntention extends Intention {
|
||||
final PsiExpression thenArgument = thenArguments[i];
|
||||
final PsiExpression elseArgument = elseArguments[i];
|
||||
if (EquivalenceChecker.getCanonicalPsiEquivalence().expressionsAreEquivalent(thenArgument, elseArgument)) {
|
||||
replacementText.append(commentTracker.markUnchanged(thenArgument).getText());
|
||||
replacementText.append(commentTracker.text(thenArgument));
|
||||
}
|
||||
else {
|
||||
final PsiMethod method = thenMethodCallExpression.resolveMethod();
|
||||
@@ -202,7 +202,7 @@ public class ReplaceIfWithConditionalIntention extends Intention {
|
||||
// prevent unboxing of boxed value to preserve semantics (IDEADEV-36008)
|
||||
final PsiPrimitiveType primitiveType = (PsiPrimitiveType)thenType;
|
||||
conditional.append(primitiveType.getBoxedTypeName());
|
||||
conditional.append(".valueOf(").append(commentTracker.markUnchanged(thenValue).getText()).append("):");
|
||||
conditional.append(".valueOf(").append(commentTracker.text(thenValue)).append("):");
|
||||
conditional.append(getExpressionText(commentTracker.markUnchanged(elseValue), false));
|
||||
}
|
||||
else if (elseType instanceof PsiPrimitiveType &&
|
||||
@@ -214,7 +214,7 @@ public class ReplaceIfWithConditionalIntention extends Intention {
|
||||
conditional.append(':');
|
||||
final PsiPrimitiveType primitiveType = (PsiPrimitiveType)elseType;
|
||||
conditional.append(primitiveType.getBoxedTypeName());
|
||||
conditional.append(".valueOf(").append(commentTracker.markUnchanged(elseValue).getText()).append(')');
|
||||
conditional.append(".valueOf(").append(commentTracker.text(elseValue)).append(')');
|
||||
}
|
||||
else {
|
||||
conditional.append(getExpressionText(commentTracker.markUnchanged(thenValue), false));
|
||||
|
||||
+10
-10
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2013 Bas Leijdekkers
|
||||
* Copyright 2006-2018 Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -43,9 +43,9 @@ public class ReplaceDoWhileLoopWithWhileLoopIntention extends Intention {
|
||||
CommentTracker commentTracker = new CommentTracker();
|
||||
if (BoolUtils.isTrue(condition)) {
|
||||
// no trickery needed
|
||||
replacementText.append("while(").append(commentTracker.markUnchanged(condition).getText()).append(')');
|
||||
replacementText.append("while(").append(commentTracker.text(condition)).append(')');
|
||||
if (body != null) {
|
||||
replacementText.append(commentTracker.markUnchanged(body).getText());
|
||||
replacementText.append(commentTracker.text(body));
|
||||
}
|
||||
PsiReplacementUtil.replaceStatement(doWhileStatement, replacementText.toString(), commentTracker);
|
||||
return;
|
||||
@@ -57,7 +57,7 @@ public class ReplaceDoWhileLoopWithWhileLoopIntention extends Intention {
|
||||
if (child == doWhileStatement) {
|
||||
break;
|
||||
}
|
||||
replacementText.append(commentTracker.markUnchanged(child).getText());
|
||||
replacementText.append(commentTracker.text(child));
|
||||
}
|
||||
replacementText.append('{');
|
||||
}
|
||||
@@ -82,7 +82,7 @@ public class ReplaceDoWhileLoopWithWhileLoopIntention extends Intention {
|
||||
}
|
||||
}
|
||||
if (noBraces) {
|
||||
replacementText.append(commentTracker.markUnchanged(child).getText());
|
||||
replacementText.append(commentTracker.text(child));
|
||||
}
|
||||
else {
|
||||
parent.addBefore(child, doWhileStatement);
|
||||
@@ -92,7 +92,7 @@ public class ReplaceDoWhileLoopWithWhileLoopIntention extends Intention {
|
||||
}
|
||||
else if (body != null) {
|
||||
if (noBraces) {
|
||||
replacementText.append(commentTracker.markUnchanged(body).getText()).append("\n");
|
||||
replacementText.append(commentTracker.text(body)).append("\n");
|
||||
}
|
||||
else {
|
||||
parent.addBefore(body, doWhileStatement);
|
||||
@@ -100,7 +100,7 @@ public class ReplaceDoWhileLoopWithWhileLoopIntention extends Intention {
|
||||
}
|
||||
replacementText.append("while(");
|
||||
if (condition != null) {
|
||||
replacementText.append(commentTracker.markUnchanged(condition).getText());
|
||||
replacementText.append(commentTracker.text(condition));
|
||||
}
|
||||
replacementText.append(')');
|
||||
if (body instanceof PsiBlockStatement) {
|
||||
@@ -120,20 +120,20 @@ public class ReplaceDoWhileLoopWithWhileLoopIntention extends Intention {
|
||||
final PsiVariable variable = (PsiVariable)declaredElement;
|
||||
final PsiExpression initializer = variable.getInitializer();
|
||||
if (initializer != null) {
|
||||
replacementText.append(variable.getName()).append(" = ").append(commentTracker.markUnchanged(initializer).getText()).append(';');
|
||||
replacementText.append(variable.getName()).append(" = ").append(commentTracker.text(initializer)).append(';');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
replacementText.append(commentTracker.markUnchanged(child).getText());
|
||||
replacementText.append(commentTracker.text(child));
|
||||
}
|
||||
}
|
||||
}
|
||||
replacementText.append('}');
|
||||
}
|
||||
else if (body != null) {
|
||||
replacementText.append(commentTracker.markUnchanged(body).getText()).append("\n");
|
||||
replacementText.append(commentTracker.text(body)).append("\n");
|
||||
}
|
||||
if (noBraces) {
|
||||
replacementText.append('}');
|
||||
|
||||
+5
-5
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2013 Bas Leijdekkers
|
||||
* Copyright 2006-2018 Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -44,7 +44,7 @@ public class ReplaceWhileLoopWithDoWhileLoopIntention extends Intention {
|
||||
if (!infiniteLoop) {
|
||||
doWhileStatementText.append("if(");
|
||||
if (condition != null) {
|
||||
doWhileStatementText.append(tracker.markUnchanged((PsiElement)condition).getText());
|
||||
doWhileStatementText.append(tracker.text(condition));
|
||||
}
|
||||
doWhileStatementText.append(") {\n");
|
||||
}
|
||||
@@ -56,17 +56,17 @@ public class ReplaceWhileLoopWithDoWhileLoopIntention extends Intention {
|
||||
if (children.length > 2) {
|
||||
for (int i = 1; i < children.length - 1; i++) {
|
||||
final PsiElement child = children[i];
|
||||
doWhileStatementText.append(tracker.markUnchanged(child).getText());
|
||||
doWhileStatementText.append(tracker.text(child));
|
||||
}
|
||||
}
|
||||
doWhileStatementText.append('}');
|
||||
}
|
||||
else if (body != null) {
|
||||
doWhileStatementText.append("do ").append(tracker.markUnchanged((PsiElement)body).getText()).append('\n');
|
||||
doWhileStatementText.append("do ").append(tracker.text(body)).append('\n');
|
||||
}
|
||||
doWhileStatementText.append("while(");
|
||||
if (condition != null) {
|
||||
doWhileStatementText.append(tracker.markUnchanged((PsiElement)condition).getText());
|
||||
doWhileStatementText.append(tracker.text(condition));
|
||||
}
|
||||
doWhileStatementText.append(");");
|
||||
if (!infiniteLoop) {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user