mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IPP: skip parentheses
This commit is contained in:
+7
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
* 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.
|
||||
@@ -17,6 +17,7 @@ package com.siyeh.ipp.concatenation;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.siyeh.ig.psiutils.ParenthesesUtils;
|
||||
import com.siyeh.ipp.base.PsiElementPredicate;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -76,13 +77,15 @@ class CallSequencePredicate implements PsiElementPredicate {
|
||||
return null;
|
||||
}
|
||||
final PsiReferenceExpression methodExpression = methodCallExpression.getMethodExpression();
|
||||
final PsiExpression qualifierExpression = methodExpression.getQualifierExpression();
|
||||
final PsiExpression qualifierExpression = ParenthesesUtils.stripParentheses(methodExpression.getQualifierExpression());
|
||||
if (qualifierExpression instanceof PsiMethodCallExpression) {
|
||||
final PsiMethodCallExpression expression = (PsiMethodCallExpression)qualifierExpression;
|
||||
return getVariable(expression);
|
||||
} else if (!(qualifierExpression instanceof PsiReferenceExpression)) {
|
||||
}
|
||||
else if (!(qualifierExpression instanceof PsiReferenceExpression)) {
|
||||
return null;
|
||||
}final PsiReferenceExpression referenceExpression = (PsiReferenceExpression)qualifierExpression;
|
||||
}
|
||||
final PsiReferenceExpression referenceExpression = (PsiReferenceExpression)qualifierExpression;
|
||||
final PsiElement target = referenceExpression.resolve();
|
||||
if (!(target instanceof PsiVariable)) {
|
||||
return null;
|
||||
|
||||
+7
-6
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
* 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.
|
||||
@@ -17,8 +17,9 @@ package com.siyeh.ipp.concatenation;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.siyeh.ig.PsiReplacementUtil;
|
||||
import com.siyeh.ig.psiutils.ParenthesesUtils;
|
||||
import com.siyeh.ipp.base.Intention;
|
||||
import com.siyeh.ipp.base.PsiElementPredicate;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -35,7 +36,7 @@ public class MergeCallSequenceToChainIntention extends Intention {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processIntention(@NotNull PsiElement element) throws IncorrectOperationException {
|
||||
protected void processIntention(@NotNull PsiElement element) {
|
||||
if (!(element instanceof PsiExpressionStatement)) {
|
||||
return;
|
||||
}
|
||||
@@ -56,7 +57,7 @@ public class MergeCallSequenceToChainIntention extends Intention {
|
||||
final PsiReferenceExpression methodExpression = methodCallExpression.getMethodExpression();
|
||||
final String methodName = methodExpression.getReferenceName();
|
||||
newMethodCallExpression.append('.').append(methodName).append(argumentList.getText());
|
||||
final PsiElement parent = methodCallExpression.getParent();
|
||||
final PsiElement parent = PsiUtil.skipParenthesizedExprUp(methodCallExpression.getParent());
|
||||
final PsiElement grandParent = parent.getParent();
|
||||
if (!(grandParent instanceof PsiMethodCallExpression)) {
|
||||
break;
|
||||
@@ -67,9 +68,9 @@ public class MergeCallSequenceToChainIntention extends Intention {
|
||||
nextSibling.delete();
|
||||
}
|
||||
|
||||
public static PsiMethodCallExpression getRootMethodCallExpression(PsiMethodCallExpression expression) {
|
||||
private static PsiMethodCallExpression getRootMethodCallExpression(PsiMethodCallExpression expression) {
|
||||
final PsiReferenceExpression methodExpression = expression.getMethodExpression();
|
||||
final PsiExpression qualifierExpression = methodExpression.getQualifierExpression();
|
||||
final PsiExpression qualifierExpression = ParenthesesUtils.stripParentheses(methodExpression.getQualifierExpression());
|
||||
if (qualifierExpression instanceof PsiMethodCallExpression) {
|
||||
final PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression)qualifierExpression;
|
||||
return getRootMethodCallExpression(methodCallExpression);
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
|
||||
class Parentheses {
|
||||
|
||||
public static void main(String... args) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("a");
|
||||
(sb).<caret>append("B");
|
||||
sb.append('c');
|
||||
sb.toString();
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package com.siyeh.ipp.concatenation.merge_sequence;
|
||||
|
||||
class Parentheses2 {
|
||||
|
||||
void foo(StringBuilder s) {
|
||||
s.append(1).app<caret>end(2);
|
||||
(s.append(3)).append(4);
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package com.siyeh.ipp.concatenation.merge_sequence;
|
||||
|
||||
class Parentheses2 {
|
||||
|
||||
void foo(StringBuilder s) {
|
||||
s.append(1).append(2).append(3).append(4);
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
|
||||
class Parentheses {
|
||||
|
||||
public static void main(String... args) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("a");
|
||||
(sb).append("B").append('c');
|
||||
sb.toString();
|
||||
}
|
||||
}
|
||||
+18
-1
@@ -1,15 +1,32 @@
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
package com.siyeh.ipp.concatenation;
|
||||
|
||||
import com.siyeh.IntentionPowerPackBundle;
|
||||
import com.siyeh.ipp.IPPTestCase;
|
||||
|
||||
/**
|
||||
* @see MergeCallSequenceToChainIntention
|
||||
* @author Bas Leijdekkers
|
||||
*/
|
||||
public class MergeCallSequenceToChainIntentionTest extends IPPTestCase {
|
||||
|
||||
public void testAppend() { doTest(); }
|
||||
public void testParentheses() { doTest(); }
|
||||
public void testParentheses2() { doTest(); }
|
||||
|
||||
@Override
|
||||
protected String getIntentionName() {
|
||||
|
||||
Reference in New Issue
Block a user