private PsiElement findElementUpstream(PsiElement startingElement, Class className) { PsiElement parent = startingElement.getParent(); if (parent == null) { return null; } PsiElement element = PsiTreeUtil.findChildOfType(parent, className); if (className.isInstance(element)) { return element; } else { try { return findElementUpstream(parent, className); } catch (Exception e) { return null; } } }
private static <T> T narrowImpl(Remote remote, Class<T> to) { //noinspection unchecked return (T) (to.isInstance(remote) ? remote : PortableRemoteObject.narrow(remote, to)); }