GrMethod (@NotNull PsiElement at, int offset) { if (at.getParent() instanceof GrReturnStatement returnStatement) { final PsiElement word = returnStatement.getReturnWord(); if (!word.getTextRange().contains(offset)) return null; final GroovyPsiElement returnOwner = PsiTreeUtil.getParentOfType(returnStatement, GrClosableBlock.class, GrMethod.class); if (returnOwner instanceof GrMethod) { final GrTypeElement returnTypeElement = ((GrMethod)returnOwner).getReturnTypeElementGroovy(); if (returnTypeElement == null) { return (GrMethod)returnOwner; } } return null; } final GrMethod method = PsiTreeUtil.getParentOfType(at, GrMethod.class, false, GrTypeDefinition.class, GrClosableBlock.class); if (method == null) return null; final TextRange headerRange = GrHighlightUtil.getMethodHeaderTextRange(method); if (!headerRange.contains(offset) && !headerRange.contains(offset - 1)) return null; if (method.isConstructor()) return null; if (method.getReturnTypeElementGroovy() != null) return null; return method; }