diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ChangeNewOperatorTypeFix.java b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ChangeNewOperatorTypeFix.java index 2f86111823b0..7ad214ac7217 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ChangeNewOperatorTypeFix.java +++ b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ChangeNewOperatorTypeFix.java @@ -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 += "]"; diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ConvertSwitchToIfIntention.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ConvertSwitchToIfIntention.java index fe5fd8aad37b..25277a53a158 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ConvertSwitchToIfIntention.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ConvertSwitchToIfIntention.java @@ -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)); } } diff --git a/java/java-impl/src/com/intellij/codeInsight/intention/impl/ExtractIfConditionAction.java b/java/java-impl/src/com/intellij/codeInsight/intention/impl/ExtractIfConditionAction.java index 1ee65a70d097..2569fceadc81 100644 --- a/java/java-impl/src/com/intellij/codeInsight/intention/impl/ExtractIfConditionAction.java +++ b/java/java-impl/src/com/intellij/codeInsight/intention/impl/ExtractIfConditionAction.java @@ -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)); } diff --git a/java/java-impl/src/com/intellij/codeInsight/intention/impl/SurroundAutoCloseableAction.java b/java/java-impl/src/com/intellij/codeInsight/intention/impl/SurroundAutoCloseableAction.java index cdf86c01f47b..2f698d6ca628 100644 --- a/java/java-impl/src/com/intellij/codeInsight/intention/impl/SurroundAutoCloseableAction.java +++ b/java/java-impl/src/com/intellij/codeInsight/intention/impl/SurroundAutoCloseableAction.java @@ -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 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); diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/PsiReplacementUtil.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/PsiReplacementUtil.java index b20ae86c491c..a1e5765cf580 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/PsiReplacementUtil.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/PsiReplacementUtil.java @@ -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); diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/abstraction/OverlyStrongTypeCastInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/abstraction/OverlyStrongTypeCastInspection.java index aa9b230cba09..b8eff50f0415 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/abstraction/OverlyStrongTypeCastInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/abstraction/OverlyStrongTypeCastInspection.java @@ -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); } } diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/assignment/AssignmentUsedAsConditionInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/assignment/AssignmentUsedAsConditionInspection.java index 6b0bfc388b67..f675e985cb98 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/assignment/AssignmentUsedAsConditionInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/assignment/AssignmentUsedAsConditionInspection.java @@ -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); } } diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/ArrayEqualityInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/ArrayEqualityInspection.java index 7b531475d93d..438049086a56 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/ArrayEqualityInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/ArrayEqualityInspection.java @@ -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); } diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/ArrayEqualsInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/ArrayEqualsInspection.java index 7fb234dd721c..1e4d1f198529 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/ArrayEqualsInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/ArrayEqualsInspection.java @@ -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("); diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/ArrayHashCodeInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/ArrayHashCodeInspection.java index 04ef8e7047fa..2666a159a8e1 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/ArrayHashCodeInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/ArrayHashCodeInspection.java @@ -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; } diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/ArrayObjectsEqualsInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/ArrayObjectsEqualsInspection.java index 33e39c1c312f..7cd3940087b4 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/ArrayObjectsEqualsInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/ArrayObjectsEqualsInspection.java @@ -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); } } diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/ImplicitArrayToStringInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/ImplicitArrayToStringInspection.java index 5163150e2be0..7e0df264053e 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/ImplicitArrayToStringInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/ImplicitArrayToStringInspection.java @@ -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) { diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/MathRandomCastToIntInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/MathRandomCastToIntInspection.java index e93849a106ee..445ffbc823b9 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/MathRandomCastToIntInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/MathRandomCastToIntInspection.java @@ -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(')'); diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/NonShortCircuitBooleanInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/NonShortCircuitBooleanInspection.java index acaf1dac714c..ef919adb0bdb 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/NonShortCircuitBooleanInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/NonShortCircuitBooleanInspection.java @@ -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); } diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/StaticCallOnSubclassInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/StaticCallOnSubclassInspection.java index 0c38aaa61387..225a7fca820e 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/StaticCallOnSubclassInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/StaticCallOnSubclassInspection.java @@ -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); } } diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/UseOfPropertiesAsHashtableInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/UseOfPropertiesAsHashtableInspection.java index c9162702945f..52a2799ea092 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/UseOfPropertiesAsHashtableInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/bugs/UseOfPropertiesAsHashtableInspection.java @@ -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); diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/cloneable/CloneReturnsClassTypeInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/cloneable/CloneReturnsClassTypeInspection.java index b9fe2e34c401..a604b338d5a7 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/cloneable/CloneReturnsClassTypeInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/cloneable/CloneReturnsClassTypeInspection.java @@ -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); diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/controlflow/ConditionalExpressionWithIdenticalBranchesInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/controlflow/ConditionalExpressionWithIdenticalBranchesInspection.java index caec5afafb47..341968fd2054 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/controlflow/ConditionalExpressionWithIdenticalBranchesInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/controlflow/ConditionalExpressionWithIdenticalBranchesInspection.java @@ -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); } } } diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/controlflow/ConstantConditionalExpressionInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/controlflow/ConstantConditionalExpressionInspection.java index 65460e3d8b4e..31a0711307b0 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/controlflow/ConstantConditionalExpressionInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/controlflow/ConstantConditionalExpressionInspection.java @@ -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 diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/controlflow/DoubleNegationInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/controlflow/DoubleNegationInspection.java index d07e5c742cd4..3a2388f44438 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/controlflow/DoubleNegationInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/controlflow/DoubleNegationInspection.java @@ -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); } diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/controlflow/ForLoopReplaceableByWhileInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/controlflow/ForLoopReplaceableByWhileInspection.java index b97d19607866..423178b2da3f 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/controlflow/ForLoopReplaceableByWhileInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/controlflow/ForLoopReplaceableByWhileInspection.java @@ -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 { diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/controlflow/IfMayBeConditionalInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/controlflow/IfMayBeConditionalInspection.java index 5ab64f8ded15..c17bbefd5a62 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/controlflow/IfMayBeConditionalInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/controlflow/IfMayBeConditionalInspection.java @@ -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); diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/controlflow/NegatedConditionalExpressionInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/controlflow/NegatedConditionalExpressionInspection.java index 8b60599fd72c..dbe0a4d994f1 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/controlflow/NegatedConditionalExpressionInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/controlflow/NegatedConditionalExpressionInspection.java @@ -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)); diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/controlflow/NegatedConditionalInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/controlflow/NegatedConditionalInspection.java index 7497b0f90b19..e3a736e82fbe 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/controlflow/NegatedConditionalInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/controlflow/NegatedConditionalInspection.java @@ -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); } } diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/controlflow/NegatedEqualityExpressionInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/controlflow/NegatedEqualityExpressionInspection.java index 23d3da9ad548..5cc354758d5f 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/controlflow/NegatedEqualityExpressionInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/controlflow/NegatedEqualityExpressionInspection.java @@ -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); diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/controlflow/NegatedIfElseInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/controlflow/NegatedIfElseInspection.java index ae42be5a003d..f39c4ed95a71 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/controlflow/NegatedIfElseInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/controlflow/NegatedIfElseInspection.java @@ -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); } } diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/fixes/AddThisQualifierFix.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/fixes/AddThisQualifierFix.java index 42fa285b2a32..615166f0acc3 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/fixes/AddThisQualifierFix.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/fixes/AddThisQualifierFix.java @@ -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); } } diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/fixes/EqualityToEqualsFix.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/fixes/EqualityToEqualsFix.java index 3c053202c014..578335937db6 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/fixes/EqualityToEqualsFix.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/fixes/EqualityToEqualsFix.java @@ -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); } diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/fixes/EqualityToSafeEqualsFix.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/fixes/EqualityToSafeEqualsFix.java index f3fa3a7a7b08..80ec8a434811 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/fixes/EqualityToSafeEqualsFix.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/fixes/EqualityToSafeEqualsFix.java @@ -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())) { diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/imports/StaticImportInspectionBase.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/imports/StaticImportInspectionBase.java index da67650df30e..01d255075b9c 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/imports/StaticImportInspectionBase.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/imports/StaticImportInspectionBase.java @@ -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); diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/jdk/AutoUnboxingInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/jdk/AutoUnboxingInspection.java index f036d56c0a74..e5bcca0b8219 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/jdk/AutoUnboxingInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/jdk/AutoUnboxingInspection.java @@ -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); } diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/jdk/ForeachStatementInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/jdk/ForeachStatementInspection.java index 7f38a7c5c5fc..2a1111e965bf 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/jdk/ForeachStatementInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/jdk/ForeachStatementInspection.java @@ -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); } diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/migration/IndexOfReplaceableByContainsInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/migration/IndexOfReplaceableByContainsInspection.java index ad59303c9f72..09e0881681a0 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/migration/IndexOfReplaceableByContainsInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/migration/IndexOfReplaceableByContainsInspection.java @@ -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; } diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/migration/UnnecessaryBoxingInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/migration/UnnecessaryBoxingInspection.java index 36dbe552dfe0..df7ef73e7e23 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/migration/UnnecessaryBoxingInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/migration/UnnecessaryBoxingInspection.java @@ -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)) { diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/migration/UnnecessaryUnboxingInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/migration/UnnecessaryUnboxingInspection.java index e5d1d59e133c..a06ec631e73a 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/migration/UnnecessaryUnboxingInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/migration/UnnecessaryUnboxingInspection.java @@ -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); } } diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/numeric/BigDecimalEqualsInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/numeric/BigDecimalEqualsInspection.java index 57c94a46014a..408f42096b7f 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/numeric/BigDecimalEqualsInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/numeric/BigDecimalEqualsInspection.java @@ -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); } } diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/numeric/CachedNumberConstructorCallInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/numeric/CachedNumberConstructorCallInspection.java index 72335d7c9685..ffde3819f4aa 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/numeric/CachedNumberConstructorCallInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/numeric/CachedNumberConstructorCallInspection.java @@ -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); } } diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/numeric/CharUsedInArithmeticContextInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/numeric/CharUsedInArithmeticContextInspection.java index bb7eb6d479b3..fbbafef6f734 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/numeric/CharUsedInArithmeticContextInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/numeric/CharUsedInArithmeticContextInspection.java @@ -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); } } diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/numeric/ComparisonToNaNInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/numeric/ComparisonToNaNInspection.java index 70e2aa912251..f567c10db0a1 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/numeric/ComparisonToNaNInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/numeric/ComparisonToNaNInspection.java @@ -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)) { diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/numeric/ImplicitNumericConversionInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/numeric/ImplicitNumericConversionInspection.java index 07b92bc6a63d..4a1b6f38d7ff 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/numeric/ImplicitNumericConversionInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/numeric/ImplicitNumericConversionInspection.java @@ -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); } diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/numeric/UnnecessaryUnaryMinusInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/numeric/UnnecessaryUnaryMinusInspection.java index adffb0dc14d1..b0848a557235 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/numeric/UnnecessaryUnaryMinusInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/numeric/UnnecessaryUnaryMinusInspection.java @@ -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); } } diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/performance/ArraysAsListWithZeroOrOneArgumentInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/performance/ArraysAsListWithZeroOrOneArgumentInspection.java index 64b373bacbdf..5c64fda33e68 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/performance/ArraysAsListWithZeroOrOneArgumentInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/performance/ArraysAsListWithZeroOrOneArgumentInspection.java @@ -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); } } } diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/performance/ManualArrayCopyInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/performance/ManualArrayCopyInspection.java index 2b936230daa5..c59fa09de544 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/performance/ManualArrayCopyInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/performance/ManualArrayCopyInspection.java @@ -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, diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/performance/RandomDoubleForRandomIntegerInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/performance/RandomDoubleForRandomIntegerInspection.java index 7044a16e91e6..bd3d6f407c17 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/performance/RandomDoubleForRandomIntegerInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/performance/RandomDoubleForRandomIntegerInspection.java @@ -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); } } diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/performance/RedundantStringFormatCallInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/performance/RedundantStringFormatCallInspection.java index 49303475115a..963b0a341557 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/performance/RedundantStringFormatCallInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/performance/RedundantStringFormatCallInspection.java @@ -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); } } diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/performance/StringBufferToStringInConcatenationInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/performance/StringBufferToStringInConcatenationInspection.java index 204296f2564c..0e3568e83365 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/performance/StringBufferToStringInConcatenationInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/performance/StringBufferToStringInConcatenationInspection.java @@ -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); } } diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/performance/StringConstructorInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/performance/StringConstructorInspection.java index 431544bf8084..8b5a86c1c509 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/performance/StringConstructorInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/performance/StringConstructorInspection.java @@ -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); } diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/performance/TailRecursionInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/performance/TailRecursionInspection.java index d0e2a2ad7558..944a03daa606 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/performance/TailRecursionInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/performance/TailRecursionInspection.java @@ -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)); } } diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/performance/TrivialStringConcatenationInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/performance/TrivialStringConcatenationInspection.java index f4ed82d757cb..24a657fae1a6 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/performance/TrivialStringConcatenationInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/performance/TrivialStringConcatenationInspection.java @@ -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())); } diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/BoolUtils.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/BoolUtils.java index d885b1abc5a7..a544a8937500 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/BoolUtils.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/BoolUtils.java @@ -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; diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/redundancy/UnusedLabelInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/redundancy/UnusedLabelInspection.java index d96a3bfcbc32..b35b7aa06820 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/redundancy/UnusedLabelInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/redundancy/UnusedLabelInspection.java @@ -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); } } diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/CallToStringConcatCanBeReplacedByOperatorInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/CallToStringConcatCanBeReplacedByOperatorInspection.java index 814e7bcf42ea..4621472e1ed6 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/CallToStringConcatCanBeReplacedByOperatorInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/CallToStringConcatCanBeReplacedByOperatorInspection.java @@ -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); } } diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/ConstantOnLHSOfComparisonInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/ConstantOnLHSOfComparisonInspection.java index f7f90402a410..31f6598d79fe 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/ConstantOnLHSOfComparisonInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/ConstantOnLHSOfComparisonInspection.java @@ -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); } } diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/ConstantOnRHSOfComparisonInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/ConstantOnRHSOfComparisonInspection.java index ecac25e1a531..29dcdf9cd9be 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/ConstantOnRHSOfComparisonInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/ConstantOnRHSOfComparisonInspection.java @@ -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); } } diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/EqualsCalledOnEnumConstantInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/EqualsCalledOnEnumConstantInspection.java index d3bc14338661..b69be8f9283a 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/EqualsCalledOnEnumConstantInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/EqualsCalledOnEnumConstantInspection.java @@ -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(); diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/ListIndexOfReplaceableByContainsInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/ListIndexOfReplaceableByContainsInspection.java index aa5e51e26ae0..f3684436f501 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/ListIndexOfReplaceableByContainsInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/ListIndexOfReplaceableByContainsInspection.java @@ -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; } diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/SimplifiableAnnotationInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/SimplifiableAnnotationInspection.java index b59991d568ac..29301a97f823 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/SimplifiableAnnotationInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/SimplifiableAnnotationInspection.java @@ -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)); } } diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/SingleStatementInBlockInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/SingleStatementInBlockInspection.java index bda509f22d97..5f38a805d449 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/SingleStatementInBlockInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/SingleStatementInBlockInspection.java @@ -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; } diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/SizeReplaceableByIsEmptyInspectionBase.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/SizeReplaceableByIsEmptyInspectionBase.java index 77a5f8ac450d..7ec3588f7cff 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/SizeReplaceableByIsEmptyInspectionBase.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/SizeReplaceableByIsEmptyInspectionBase.java @@ -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; diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/UnqualifiedStaticUsageInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/UnqualifiedStaticUsageInspection.java index 327ed27e917d..7915d7628851 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/UnqualifiedStaticUsageInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/style/UnqualifiedStaticUsageInspection.java @@ -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); } } diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/threading/AbstractReplaceWithAnotherMethodCallFix.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/threading/AbstractReplaceWithAnotherMethodCallFix.java index cb7731e041aa..33ed8e42bb48 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/threading/AbstractReplaceWithAnotherMethodCallFix.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/threading/AbstractReplaceWithAnotherMethodCallFix.java @@ -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); } } diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/asserttoif/AssertionCanBeIfInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/asserttoif/AssertionCanBeIfInspection.java index 01300a53cc72..1ebda78070cf 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/asserttoif/AssertionCanBeIfInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/asserttoif/AssertionCanBeIfInspection.java @@ -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); diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/asserttoif/IfCanBeAssertionInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/asserttoif/IfCanBeAssertionInspection.java index f8e06573ffe0..f4d826acf742 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/asserttoif/IfCanBeAssertionInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/asserttoif/IfCanBeAssertionInspection.java @@ -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]); } } } diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/ConditionalExpressionInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/ConditionalExpressionInspection.java index 3e9d19905279..9eac4e9dbbe3 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/ConditionalExpressionInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/ConditionalExpressionInspection.java @@ -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) { diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/PointlessBooleanExpressionInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/PointlessBooleanExpressionInspection.java index 39836b5a2c50..8775661c78d1 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/PointlessBooleanExpressionInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/PointlessBooleanExpressionInspection.java @@ -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)); } } } diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/dataflow/ReuseOfLocalVariableInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/dataflow/ReuseOfLocalVariableInspection.java index 49c5187e02e7..f405a60c8af2 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/dataflow/ReuseOfLocalVariableInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/dataflow/ReuseOfLocalVariableInspection.java @@ -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); diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/exceptions/TryStatementWithMultipleResourcesInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/exceptions/TryStatementWithMultipleResourcesInspection.java index 5e4744ca6b11..52d7ffcb87dc 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/exceptions/TryStatementWithMultipleResourcesInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/exceptions/TryStatementWithMultipleResourcesInspection.java @@ -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); } diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/fixes/ExtractParameterAsLocalVariableFix.java b/plugins/InspectionGadgets/src/com/siyeh/ig/fixes/ExtractParameterAsLocalVariableFix.java index c6beae682ea9..e9805b1b80c5 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/fixes/ExtractParameterAsLocalVariableFix.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/fixes/ExtractParameterAsLocalVariableFix.java @@ -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); diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/performance/DynamicRegexReplaceableByCompiledPatternInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/performance/DynamicRegexReplaceableByCompiledPatternInspection.java index d007f075b98d..3411710562c2 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/performance/DynamicRegexReplaceableByCompiledPatternInspection.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/performance/DynamicRegexReplaceableByCompiledPatternInspection.java @@ -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) { diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/asserttoif/ObjectsRequireNonNullIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/asserttoif/ObjectsRequireNonNullIntention.java index 59accaefa28c..3ac442c75bd5 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/asserttoif/ObjectsRequireNonNullIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/asserttoif/ObjectsRequireNonNullIntention.java @@ -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); } diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/bool/DemorgansIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/bool/DemorgansIntention.java index 787a9824c9e4..e40f8b92d27a 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/bool/DemorgansIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/bool/DemorgansIntention.java @@ -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); } } } diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/bool/FlipComparisonIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/bool/FlipComparisonIntention.java index 6d58b7dec535..904000f32a5d 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/bool/FlipComparisonIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/bool/FlipComparisonIntention.java @@ -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); } } \ No newline at end of file diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/bool/NegateConditionalIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/bool/NegateConditionalIntention.java index 925c243afb52..21fba19ef224 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/bool/NegateConditionalIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/bool/NegateConditionalIntention.java @@ -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); diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/collections/ReplaceWithArraysAsListIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/collections/ReplaceWithArraysAsListIntention.java index 525fdfa977a4..23de69c91ddd 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/collections/ReplaceWithArraysAsListIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/collections/ReplaceWithArraysAsListIntention.java @@ -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) { diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/JoinConcatenatedStringLiteralsIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/JoinConcatenatedStringLiteralsIntention.java index c46bc5b4aa8f..40c90f138c1d 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/JoinConcatenatedStringLiteralsIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/JoinConcatenatedStringLiteralsIntention.java @@ -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); } diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/ReplaceConcatenationWithFormatStringIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/ReplaceConcatenationWithFormatStringIntention.java index 9941e5a0dc89..2d8f30de395c 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/ReplaceConcatenationWithFormatStringIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/ReplaceConcatenationWithFormatStringIntention.java @@ -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); diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/ReplaceConcatenationWithStringBufferIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/ReplaceConcatenationWithStringBufferIntention.java index e2f1e7545467..c3e7dcde4dcd 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/ReplaceConcatenationWithStringBufferIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/ReplaceConcatenationWithStringBufferIntention.java @@ -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(')'); } diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/ReplaceFormatStringWithConcatenationIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/ReplaceFormatStringWithConcatenationIntention.java index 6ae05390450d..16f584459f8e 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/ReplaceFormatStringWithConcatenationIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/concatenation/ReplaceFormatStringWithConcatenationIntention.java @@ -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); diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/conditional/FlipConditionalIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/conditional/FlipConditionalIntention.java index 94c9cf6c1ea0..a541d7b6affb 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/conditional/FlipConditionalIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/conditional/FlipConditionalIntention.java @@ -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); } } diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/conditional/ReplaceConditionalWithBooleanExpressionIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/conditional/ReplaceConditionalWithBooleanExpressionIntention.java index 01fe6c570f03..1ec05a3a27f9 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/conditional/ReplaceConditionalWithBooleanExpressionIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/conditional/ReplaceConditionalWithBooleanExpressionIntention.java @@ -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); } } } diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/constant/ConstantSubexpressionIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/constant/ConstantSubexpressionIntention.java index 25f5920bb3f6..45b42eca70fa 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/constant/ConstantSubexpressionIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/constant/ConstantSubexpressionIntention.java @@ -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); diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/enumswitch/CreateEnumSwitchBranchesIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/enumswitch/CreateEnumSwitchBranchesIntention.java index 31c0f4ea2a73..8e27b28d5807 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/enumswitch/CreateEnumSwitchBranchesIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/enumswitch/CreateEnumSwitchBranchesIntention.java @@ -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;"); } diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/exceptions/DetailExceptionsIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/exceptions/DetailExceptionsIntention.java index d42067dee512..8bef734ab96d 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/exceptions/DetailExceptionsIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/exceptions/DetailExceptionsIntention.java @@ -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 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 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(); diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/expression/FlipExpressionIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/expression/FlipExpressionIntention.java index b26a0c12dbf3..cb789d7233d8 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/expression/FlipExpressionIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/expression/FlipExpressionIntention.java @@ -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); diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/forloop/ReplaceForEachLoopWithIndexedForLoopIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/forloop/ReplaceForEachLoopWithIndexedForLoopIntention.java index 973e6fd17e88..2ad0f7b96953 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/forloop/ReplaceForEachLoopWithIndexedForLoopIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/forloop/ReplaceForEachLoopWithIndexedForLoopIntention.java @@ -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, diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/forloop/ReplaceForEachLoopWithIteratorForLoopIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/forloop/ReplaceForEachLoopWithIteratorForLoopIntention.java index 753bf128cf4b..930156fb0850 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/forloop/ReplaceForEachLoopWithIteratorForLoopIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/forloop/ReplaceForEachLoopWithIteratorForLoopIntention.java @@ -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('}'); diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/junit/FlipAssertLiteralIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/junit/FlipAssertLiteralIntention.java index fadd746fbc1d..94a8bace0e74 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/junit/FlipAssertLiteralIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/junit/FlipAssertLiteralIntention.java @@ -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(')'); diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/junit/ReplaceAssertLiteralWithAssertEqualsIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/junit/ReplaceAssertLiteralWithAssertEqualsIntention.java index c092c7559d97..b5740aad64cc 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/junit/ReplaceAssertLiteralWithAssertEqualsIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/junit/ReplaceAssertLiteralWithAssertEqualsIntention.java @@ -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(')'); diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/opassign/ReplaceAssignmentWithPostfixExpressionIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/opassign/ReplaceAssignmentWithPostfixExpressionIntention.java index 802dbe17ccba..05b73e84a672 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/opassign/ReplaceAssignmentWithPostfixExpressionIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/opassign/ReplaceAssignmentWithPostfixExpressionIntention.java @@ -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; diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/opassign/ReplaceOperatorAssignmentWithPostfixExpressionIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/opassign/ReplaceOperatorAssignmentWithPostfixExpressionIntention.java index feb329294a6a..f9ea28973d0f 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/opassign/ReplaceOperatorAssignmentWithPostfixExpressionIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/opassign/ReplaceOperatorAssignmentWithPostfixExpressionIntention.java @@ -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)) { diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/opassign/ReplacePostfixExpressionWithAssignmentIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/opassign/ReplacePostfixExpressionWithAssignmentIntention.java index 086ec5cd54dd..e3f8669f98d5 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/opassign/ReplacePostfixExpressionWithAssignmentIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/opassign/ReplacePostfixExpressionWithAssignmentIntention.java @@ -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); } diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/opassign/ReplacePostfixExpressionWithOperatorAssignmentIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/opassign/ReplacePostfixExpressionWithOperatorAssignmentIntention.java index b7c233463f2d..667e3ef229d0 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/opassign/ReplacePostfixExpressionWithOperatorAssignmentIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/opassign/ReplacePostfixExpressionWithOperatorAssignmentIntention.java @@ -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); } diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/opassign/ReplaceWithOperatorAssignmentIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/opassign/ReplaceWithOperatorAssignmentIntention.java index 6c37ed34fd92..09ede84d01aa 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/opassign/ReplaceWithOperatorAssignmentIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/opassign/ReplaceWithOperatorAssignmentIntention.java @@ -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); } diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/shift/ReplaceMultiplyWithShiftIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/shift/ReplaceMultiplyWithShiftIntention.java index 45f54d75d447..41e4225f0428 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/shift/ReplaceMultiplyWithShiftIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/shift/ReplaceMultiplyWithShiftIntention.java @@ -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); } diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/shift/ReplaceShiftWithMultiplyIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/shift/ReplaceShiftWithMultiplyIntention.java index 90dad3adc1db..a001eddd2945 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/shift/ReplaceShiftWithMultiplyIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/shift/ReplaceShiftWithMultiplyIntention.java @@ -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); } diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/trivialif/ConvertToNestedIfIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/trivialif/ConvertToNestedIfIntention.java index 78318f53beb1..6a1e5c24e426 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/trivialif/ConvertToNestedIfIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/trivialif/ConvertToNestedIfIntention.java @@ -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; } diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/trivialif/MergeIfOrIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/trivialif/MergeIfOrIntention.java index 35e086c349e9..98751217e51d 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/trivialif/MergeIfOrIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/trivialif/MergeIfOrIntention.java @@ -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); diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/trivialif/ReplaceIfWithConditionalIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/trivialif/ReplaceIfWithConditionalIntention.java index bf575bf3be9d..9a501b0ddafc 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/trivialif/ReplaceIfWithConditionalIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/trivialif/ReplaceIfWithConditionalIntention.java @@ -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)); diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/whileloop/ReplaceDoWhileLoopWithWhileLoopIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/whileloop/ReplaceDoWhileLoopWithWhileLoopIntention.java index 461afd60a72d..b4ba2a5e388e 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/whileloop/ReplaceDoWhileLoopWithWhileLoopIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/whileloop/ReplaceDoWhileLoopWithWhileLoopIntention.java @@ -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('}'); diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/whileloop/ReplaceWhileLoopWithDoWhileLoopIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/whileloop/ReplaceWhileLoopWithDoWhileLoopIntention.java index 5e93b8d3cb1d..ccb86b97c15a 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/whileloop/ReplaceWhileLoopWithDoWhileLoopIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/whileloop/ReplaceWhileLoopWithDoWhileLoopIntention.java @@ -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) { diff --git a/plugins/devkit/src/inspections/internal/UsePrimitiveTypesInspection.java b/plugins/devkit/src/inspections/internal/UsePrimitiveTypesInspection.java index e63144bdcee3..f0880f2879bb 100644 --- a/plugins/devkit/src/inspections/internal/UsePrimitiveTypesInspection.java +++ b/plugins/devkit/src/inspections/internal/UsePrimitiveTypesInspection.java @@ -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 org.jetbrains.idea.devkit.inspections.internal; @@ -117,8 +105,8 @@ public class UsePrimitiveTypesInspection extends DevKitInspectionBase { final boolean flip = isPrimitiveTypeRef(rOperand); if (flip || isPrimitiveTypeRef(lOperand)) { CommentTracker commentTracker = new CommentTracker(); - final String rText = commentTracker.markUnchanged(PsiUtil.skipParenthesizedExprUp(rOperand)).getText(); - final String lText = commentTracker.markUnchanged(PsiUtil.skipParenthesizedExprUp(lOperand)).getText(); + final String rText = commentTracker.text(PsiUtil.skipParenthesizedExprUp(rOperand)); + final String lText = commentTracker.text(PsiUtil.skipParenthesizedExprUp(lOperand)); final String lhText = flip ? rText : lText; final String rhText = flip ? lText : rText;