PsiMethod (final PsiClass psiClass, final String methodName, final int lineNumber) { final PsiMethod[] methods; if (INIT_MESSAGE.equals(methodName)) methods = psiClass.getConstructors(); else methods = psiClass.findMethodsByName(methodName, true); if (methods.length == 0) return null; final PsiFile psiFile = methods[0].getContainingFile(); final int offset = offsetOfLine(psiFile, lineNumber); for (final PsiMethod method : methods) { if (method.getTextRange().contains(offset)) return method; } //if (!methods.hasNext() || location == null) return null; //return location.getPsiElement(); //if ("<init>".equals(methodName)) methods = psiClass.getConstructors(); //else methods = psiClass.findMethodsByName(methodName, true); //if (methods.length == 0) return null; //for (int i = 0; i < methods.length; i++) { // PsiMethod method = methods[i]; // if (method.getTextRange().contains(offset)) return method; //} return null; }