UsageGroup (@NotNull Usage usage, UsageTarget @NotNull [] targets) { if (!(usage instanceof PsiElementUsage)) return null; PsiElement psiElement = ((PsiElementUsage)usage).getElement(); PsiFile containingFile = psiElement.getContainingFile(); if (containingFile == null) return null; InjectedLanguageManager manager = InjectedLanguageManager.getInstance(containingFile.getProject()); PsiFile topLevelFile = manager.getTopLevelFile(containingFile); if (topLevelFile instanceof PsiJavaFile && !topLevelFile.getFileType().isBinary()) { PsiElement containingMethod = topLevelFile == containingFile ? psiElement : manager.getInjectionHost(containingFile); if (usage instanceof UsageInfo2UsageAdapter && topLevelFile == containingFile) { int offset = ((UsageInfo2UsageAdapter)usage).getUsageInfo().getNavigationOffset(); containingMethod = containingFile.findElementAt(offset); } do { containingMethod = PsiTreeUtil.getParentOfType(containingMethod, PsiMethod.class, true); if (containingMethod == null) break; final PsiClass containingClass = ((PsiMethod)containingMethod).getContainingClass(); if (containingClass == null || containingClass.getQualifiedName() != null) break; } while (true); if (containingMethod != null) { return new MethodUsageGroup((PsiMethod)containingMethod, myUsageViewSettings); } } return null; }