FileReference (@Nullable PsiReference ref) { if (ref instanceof FileReference) { return (FileReference)ref; } if (ref instanceof PsiMultiReference) { List<PsiReference> filtered = ContainerUtil.filter(((PsiMultiReference)ref).getReferences(), value -> value instanceof FileReference); if (!filtered.isEmpty()) { return (FileReference)filtered.get(0); } } throw new AssertionFailedError("Unable to find FileReference"); }