@Nullable public static GrExpression addClosureToCall(PsiElement initializer, GrArgumentList list) { if (!(initializer instanceof GrClosableBlock)) return null; final PsiElement parent = list.getParent(); if (!(parent instanceof GrMethodCallExpression)) return null; PsiElement anchor; final GrClosableBlock[] cls = ((GrMethodCallExpression) parent).getClosureArguments(); if (cls.length > 0) { anchor = cls[cls.length - 1]; } else { anchor = list; } return (GrExpression) parent.addAfter(initializer, anchor); }
@NotNull @Override public PsiReference[] getReferencesByElement( @NotNull PsiElement element, @NotNull ProcessingContext context) { GrExpression argument = (GrExpression) element; PsiElement parent = element.getParent(); if (parent instanceof GrConditionalExpression) { // support case: foo(a > b ? "aaa" : "bbb") if (((GrConditionalExpression) parent).getCondition() == parent) return PsiReference.EMPTY_ARRAY; argument = (GrConditionalExpression) parent; parent = parent.getParent(); } if (parent instanceof GrListOrMap) { // support case: foo(["aaa", "bbb"]) if (!((GrListOrMap) parent).isMap()) { argument = (GrListOrMap) parent; parent = parent.getParent(); } } if (parent instanceof GrNamedArgument) { return createReferencesForNamedArgument(element, (GrNamedArgument) parent, context); } if (parent instanceof GrArgumentList) { GrArgumentList argumentList = (GrArgumentList) parent; int index = argumentList.getExpressionArgumentIndex(argument); PsiElement call = argumentList.getParent(); if (!(call instanceof GrMethodCall)) return PsiReference.EMPTY_ARRAY; return PsiReference.EMPTY_ARRAY; } return PsiReference.EMPTY_ARRAY; }