private static boolean isGetterInvocation(@NotNull GrMethodCall call) { GrExpression expr = call.getInvokedExpression(); if (!(expr instanceof GrReferenceExpression)) return false; PsiMethod method = call.resolveMethod(); if (!GroovyPropertyUtils.isSimplePropertyGetter(method)) return false; LOG.assertTrue(method != null); if (!GroovyNamesUtil.isValidReference( GroovyPropertyUtils.getPropertyNameByGetterName(method.getName(), true), ((GrReferenceExpression) expr).getQualifier() != null, call.getProject())) { return false; } GrArgumentList args = call.getArgumentList(); if (args == null || args.getAllArguments().length != 0) { return false; } GrExpression ref = genRefForGetter(call, ((GrReferenceExpression) expr).getReferenceName()); if (ref instanceof GrReferenceExpression) { PsiElement resolved = ((GrReferenceExpression) ref).resolve(); PsiManager manager = call.getManager(); if (manager.areElementsEquivalent(resolved, method) || areEquivalentAccessors(method, resolved, manager)) { return true; } } return false; }
public static void processChangedMethodCall( PsiElement element, GrIntroduceParameterSettings settings, Project project) { if (!(element.getParent() instanceof GrMethodCallExpression)) { LOG.error(element.getParent()); return; } GrMethodCallExpression methodCall = (GrMethodCallExpression) element.getParent(); GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(project); final String name = settings.getName(); LOG.assertTrue(name != null); GrExpression expression = factory.createExpressionFromText(name, null); final GrArgumentList argList = methodCall.getArgumentList(); final PsiElement[] exprs = argList.getAllArguments(); if (exprs.length > 0) { argList.addAfter(expression, exprs[exprs.length - 1]); } else { argList.add(expression); } removeParametersFromCall(methodCall, settings); }