mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
preserve comments: merge call seq to chain
This commit is contained in:
+5
-2
@@ -19,6 +19,7 @@ import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.siyeh.ig.PsiReplacementUtil;
|
||||
import com.siyeh.ig.psiutils.CommentTracker;
|
||||
import com.siyeh.ig.psiutils.ParenthesesUtils;
|
||||
import com.siyeh.ipp.base.Intention;
|
||||
import com.siyeh.ipp.base.PsiElementPredicate;
|
||||
@@ -52,8 +53,10 @@ public class MergeCallSequenceToChainIntention extends Intention {
|
||||
return;
|
||||
}
|
||||
PsiMethodCallExpression methodCallExpression = getRootMethodCallExpression((PsiMethodCallExpression)expression1);
|
||||
CommentTracker tracker = new CommentTracker();
|
||||
while (true) {
|
||||
final PsiExpressionList argumentList = methodCallExpression.getArgumentList();
|
||||
tracker.markUnchanged(argumentList);
|
||||
final PsiReferenceExpression methodExpression = methodCallExpression.getMethodExpression();
|
||||
final String methodName = methodExpression.getReferenceName();
|
||||
newMethodCallExpression.append('.').append(methodName).append(argumentList.getText());
|
||||
@@ -64,8 +67,8 @@ public class MergeCallSequenceToChainIntention extends Intention {
|
||||
}
|
||||
methodCallExpression = (PsiMethodCallExpression)grandParent;
|
||||
}
|
||||
PsiReplacementUtil.replaceExpression(expression, newMethodCallExpression.toString());
|
||||
nextSibling.delete();
|
||||
PsiReplacementUtil.replaceExpression(expression, newMethodCallExpression.toString(), false);
|
||||
tracker.deleteAndRestoreComments(nextSibling);
|
||||
}
|
||||
|
||||
private static PsiMethodCallExpression getRootMethodCallExpression(PsiMethodCallExpression expression) {
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// 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.
|
||||
package com.siyeh.ipp.concatenation.merge_sequence;
|
||||
|
||||
class Append {
|
||||
|
||||
void foo(StringBuilder s) {
|
||||
s.append(1)/*in source*/.app<caret>end(2);
|
||||
s.append(3)/*before dot*/./*after dot*/append(4/*in arg*/);//after end
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// 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.
|
||||
package com.siyeh.ipp.concatenation.merge_sequence;
|
||||
|
||||
class Append {
|
||||
|
||||
void foo(StringBuilder s) {
|
||||
s.append(1)/*in source*/.append(2).append(3).append(4/*in arg*/);
|
||||
/*before dot*/
|
||||
/*after dot*/
|
||||
//after end
|
||||
}
|
||||
}
|
||||
+1
@@ -27,6 +27,7 @@ public class MergeCallSequenceToChainIntentionTest extends IPPTestCase {
|
||||
public void testAppend() { doTest(); }
|
||||
public void testParentheses() { doTest(); }
|
||||
public void testParentheses2() { doTest(); }
|
||||
public void testComments() { doTest(); }
|
||||
|
||||
@Override
|
||||
protected String getIntentionName() {
|
||||
|
||||
Reference in New Issue
Block a user