int (@NotNull PsiElement[] parameters, @NotNull IElementType delimiter, int offset) { for (int i = 0; i < parameters.length; i++) { PsiElement parameter = parameters[i]; TextRange textRange = parameter.getTextRange(); int startOffset = textRange.getStartOffset(); if (offset < startOffset) { if (i == 0) return 0; PsiElement elementInBetween = parameters[i - 1]; int currOffset = elementInBetween.getTextRange().getEndOffset(); while ((elementInBetween = PsiTreeUtil.nextLeaf(elementInBetween)) != null) { if (currOffset >= startOffset) break; ASTNode node = elementInBetween.getNode(); if (node != null && node.getElementType() == delimiter) { return offset <= currOffset ? i - 1 : i; } currOffset += elementInBetween.getTextLength(); } return i; } else if (offset <= textRange.getEndOffset()) { return i; } } return Math.max(0, parameters.length - 1); }