PsiElement (@NotNull PsiElement element, @NotNull String path) { final String[] classes = path.split("\\$"); List<Integer> indexes = new ArrayList<>(); for (String cls : classes) { if (cls.isEmpty()) continue; try { indexes.add(Integer.parseInt(cls) - 1); } catch (Exception e) { return element; } } PsiElement current = element; for (int index : indexes) { final PsiElement[] anonymousClasses = getAnonymousClasses(current); if (index >= 0 && index < anonymousClasses.length) { current = anonymousClasses[index]; } else { return current; } } return current; }