IDEA-162696 Intention "Merge filter chain" does not add parentheses if necessary

This commit is contained in:
Tagir Valeev
2016-10-18 13:49:07 +07:00
parent fcbe9f8027
commit ab6907ca07
3 changed files with 22 additions and 2 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2015 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.
@@ -28,6 +28,7 @@ import com.intellij.psi.search.searches.ReferencesSearch;
import com.intellij.psi.util.InheritanceUtil;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.IncorrectOperationException;
import com.siyeh.ig.psiutils.ParenthesesUtils;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
@@ -139,7 +140,9 @@ public class MergeFilterChainAction extends PsiElementBaseIntentionAction {
final PsiExpression compoundExpression = JavaPsiFacade.getElementFactory(project)
.createExpressionFromText(targetBody.getText() + " && " + sourceLambdaBody.getText(), sourceLambda);
.createExpressionFromText(
ParenthesesUtils.getText((PsiExpression)targetBody, ParenthesesUtils.OR_PRECEDENCE) + " && " +
ParenthesesUtils.getText((PsiExpression)sourceLambdaBody, ParenthesesUtils.OR_PRECEDENCE), sourceLambda);
targetBody = targetBody.replace(compoundExpression);
CodeStyleManager.getInstance(project).reformat(targetBody);