/*
 * Copyright 2008 Bas Leijdekkers
 *
 * 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 org.jetbrains.plugins.groovy.intentions.conversions;

import com.intellij.psi.PsiElement;
import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrOpenBlock;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList;
import org.jetbrains.plugins.groovy.lang.psi.GroovyFile;

class RemoveParenthesesFromMethodPredicate implements PsiElementPredicate {

  public boolean satisfiedBy(PsiElement element) {
    if (!(element instanceof GrMethodCallExpression)) {
      return false;
    }
    final GrMethodCallExpression methodCallExpression = (GrMethodCallExpression) element;
    final GrArgumentList argumentList = methodCallExpression.getArgumentList();
    if (argumentList ==  null) {
      return false;
    }
    final GrExpression[] arguments = argumentList.getExpressionArguments();
    if (arguments.length == 0) {
      return false;
    }
    final PsiElement parent = element.getParent();
    return parent instanceof GrOpenBlock || parent instanceof GroovyFile || parent instanceof GrClosableBlock;
  }
}
@@ -808,41 +808,176 @@
 psi.
-api.statements.blocks.GrOpenBlock
+GroovyFile;%0Aimport org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrListOrMap;%0Aimport org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList
 ;%0Aim
@@ -1122,47 +1122,26 @@
 nts.
-expressions.path.GrMethodCallExpression
+blocks.GrOpenBlock
 ;%0Aim
@@ -1288,89 +1288,241 @@
 nts.
-arguments.GrArgumentList;%0Aimport org.jetbrains.plugins.groovy.lang.psi.GroovyFile
+expressions.GrReferenceExpression;%0Aimport org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrParenthesizedExpression;%0Aimport org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression
 ;%0A%0Ac
@@ -1810,17 +1810,16 @@
 ression)
- 
 element;
@@ -1926,23 +1926,14 @@
 t ==
- 
  null)
- %7B%0A     
  ret
@@ -1935,37 +1935,32 @@
 ) return false;%0A
-    %7D
 %0A    final GrExp
@@ -2051,23 +2051,113 @@
 h == 0) 
-%7B%0A     
+return false;%0A%0A    GrExpression firstArg = arguments%5B0%5D;%0A    if (firstArg instanceof GrListOrMap)
  return 
@@ -2155,37 +2155,32 @@
 ) return false;%0A
-    %7D
 %0A    final PsiEl
@@ -2219,117 +2219,908 @@
 ();%0A
-    return parent instanceof GrOpenBlock %7C%7C parent instanceof GroovyFile %7C%7C parent instanceof GrClosableBlock
+%0A    if (firstArg instanceof GrMethodCallExpression) %7B%0A      GrMethodCallExpression call = (GrMethodCallExpression)firstArg;%0A%0A      GrExpression invokedExpression = call.getInvokedExpression();%0A%0A      if (invokedExpression instanceof GrReferenceExpression) %7B%0A        invokedExpression = getDeepestInvocationExpression(invokedExpression);%0A      %7D%0A%0A      if (invokedExpression instanceof GrParenthesizedExpression) return false;%0A    %7D%0A%0A    return parent instanceof GrOpenBlock %7C%7C parent instanceof GroovyFile %7C%7C parent instanceof GrClosableBlock;%0A  %7D%0A%0A  private GrExpression getDeepestInvocationExpression(GrExpression invokedExpression) %7B%0A    if (invokedExpression instanceof GrReferenceExpression) %7B%0A      GrReferenceExpression refElement = (GrReferenceExpression)invokedExpression;%0A%0A      return getDeepestInvocationExpression(refElement.getQualifierExpression());%0A    %7D%0A    return invokedExpression
 ;%0A  

Remove parenthesis intetion support fix GRVY-2023