keep comments (IDEA-140861)

This commit is contained in:
Anna Kozlova
2018-06-18 17:05:41 +03:00
parent c647e7e306
commit dabef9b7b1
4 changed files with 36 additions and 1 deletions
@@ -292,7 +292,7 @@ public class SimplifyBooleanExpressionFix extends LocalQuickFixOnPsiElement {
public static void simplifyExpression(PsiExpression expression) throws IncorrectOperationException {
final PsiExpression result = createSimplifiedReplacement(expression);
PsiExpression newExpression = (PsiExpression)expression.replace(result);
PsiExpression newExpression = (PsiExpression)new CommentTracker().replaceAndRestoreComments(expression, result);
if (newExpression instanceof PsiLiteralExpression) {
final PsiElement parent = newExpression.getParent();
if (parent instanceof PsiAssertStatement && ((PsiLiteralExpression)newExpression).getValue() == Boolean.TRUE) {
@@ -0,0 +1,15 @@
// "Simplify boolean expression" "true"
class A {
public static void m(boolean fullSearch, boolean partialSearch) {
if (!partialSearch) {
return;
}
String str
= fullSearch ? "str1"
: <warning descr="Condition 'partialSearch' is always 'true'"><caret>partialSearch</warning> ? "str2 " + "str3" // comment
: null;
}
}
@@ -0,0 +1,15 @@
// "Simplify boolean expression" "true"
class A {
public static void m(boolean fullSearch, boolean partialSearch) {
if (!partialSearch) {
return;
}
// comment
String str
= fullSearch ? "str1"
: "str2 " + "str3";
}
}
@@ -280,6 +280,11 @@ public class DataFlowInspectionTest extends DataFlowInspectionTestCase {
public void testFinalGetter() { doTest(); }
public void testGetterResultsNotSame() { doTest(); }
public void testIntersectionTypeInstanceof() { doTest(); }
public void testKeepComments() {
doTest();
checkIntentionResult("Simplify");
}
public void testImmutableClassNonGetterMethod() {
myFixture.addClass("package javax.annotation.concurrent; public @interface Immutable {}");