AnnotationContext (@Nullable PsiModifierListOwner owner) { if (owner instanceof PsiMethod) { PsiMethod method = (PsiMethod)owner; return new AnnotationContext(owner, (method).getReturnType(), () -> { HashSet<PsiMethod> visited = new HashSet<>(); return StreamEx.ofNullable(getKotlinProperty(owner)) .append(StreamEx.ofTree(method, m -> StreamEx.of(m.findSuperMethods()).filter(visited::add)).skip(1)); }); } if (owner instanceof PsiParameter parameter) { PsiParameterList parameterList = ObjectUtils.tryCast(parameter.getParent(), PsiParameterList.class); PsiMethod method = parameterList == null ? null : ObjectUtils.tryCast(parameterList.getParent(), PsiMethod.class); if (parameterList != null && method != null) { int index = parameterList.getParameterIndex(parameter); if (index >= 0) { Supplier<Stream<PsiModifierListOwner>> supplier = () -> { HashSet<PsiMethod> visited = new HashSet<>(); return StreamEx.ofTree(method, m -> StreamEx.of(m.findSuperMethods()).filter(visited::add)).skip(1) .map(m -> m.getParameterList().getParameter(index)).select(PsiModifierListOwner.class); }; return new AnnotationContext(owner, ((PsiVariable)owner).getType(), supplier); } } } if (owner instanceof PsiVariable) { return new AnnotationContext(owner, ((PsiVariable)owner).getType()); } return EMPTY; }