PsiElement (final PsiElement element) { if (element instanceof PsiMethod) { final PsiMethod method = (PsiMethod)element; final PsiType initialMethodReturnType = method.getReturnType(); if (initialMethodReturnType == null) { return null; } final List<PsiMethod> normalized = new SmartList<>(); final Deque<PsiMethod> queue = new ArrayDeque<>(1); queue.addLast(method); while (!queue.isEmpty()) { PsiMethod currentMethod = queue.removeFirst(); if (initialMethodReturnType.equals(currentMethod.getReturnType())) { for (PsiMethod toConsume : currentMethod.findSuperMethods(false)) { queue.addLast(toConsume); } normalized.add(currentMethod); } } //TODO Dmitry Batkovich multiple result is possible return normalized.isEmpty() ? element : normalized.get(normalized.size() - 1); } else if (element instanceof PsiParameter && element.getParent() instanceof PsiParameterList) { final PsiElement declarationScope = ((PsiParameter)element).getDeclarationScope(); if (declarationScope instanceof PsiLambdaExpression) { final PsiType interfaceType = ((PsiLambdaExpression)declarationScope).getFunctionalInterfaceType(); if (interfaceType != null) { final PsiMethod interfaceMethod = LambdaUtil.getFunctionalInterfaceMethod(interfaceType); if (interfaceMethod != null) { final int index = ((PsiParameterList)element.getParent()).getParameterIndex((PsiParameter)element); return interfaceMethod.getParameterList().getParameters()[index]; } } return null; } final PsiMethod method = PsiTreeUtil.getParentOfType(element, PsiMethod.class); if (method != null) { final int index = method.getParameterList().getParameterIndex(((PsiParameter)element)); final PsiMethod superMethod = method.findDeepestSuperMethod(); if (superMethod != null) { return superMethod.getParameterList().getParameters()[index]; } } } return element; }