@Override public UsageGroup groupUsage(@NotNull Usage usage) { if (!(usage instanceof PsiElementUsage)) { return null; } final PsiElement psiElement = ((PsiElementUsage) usage).getElement(); final PsiFile containingFile = psiElement.getContainingFile(); if (containingFile == null) return null; PsiFile topLevelFile = InjectedLanguageManager.getInstance(containingFile.getProject()) .getTopLevelFile(containingFile); if (!(topLevelFile instanceof PsiJavaFile) || topLevelFile instanceof JspFile) { return null; } PsiElement containingClass = topLevelFile == containingFile ? psiElement : InjectedLanguageManager.getInstance(containingFile.getProject()) .getInjectionHost(containingFile); do { containingClass = PsiTreeUtil.getParentOfType(containingClass, PsiClass.class, true); if (containingClass == null || ((PsiClass) containingClass).getQualifiedName() != null) break; } while (true); if (containingClass == null) { // check whether the element is in the import list PsiImportList importList = PsiTreeUtil.getParentOfType(psiElement, PsiImportList.class, true); if (importList != null) { final String fileName = getFileNameWithoutExtension(topLevelFile); final PsiClass[] classes = ((PsiJavaFile) topLevelFile).getClasses(); for (final PsiClass aClass : classes) { if (fileName.equals(aClass.getName())) { containingClass = aClass; break; } } } } else { // skip JspClass synthetic classes. if (containingClass.getParent() instanceof PsiFile && JspPsiUtil.isInJspFile(containingClass)) { containingClass = null; } } if (containingClass != null) { return new ClassUsageGroup((PsiClass) containingClass); } final VirtualFile virtualFile = topLevelFile.getVirtualFile(); if (virtualFile != null) { return new FileGroupingRule.FileUsageGroup(topLevelFile.getProject(), virtualFile); } return null; }
@Override public void visitTryStatement(@NotNull PsiTryStatement statement) { super.visitTryStatement(statement); if (JspPsiUtil.isInJspFile(statement.getContainingFile())) { return; } if (m_ignoreTestCases) { if (TestUtils.isPartOfJUnitTestMethod(statement)) { return; } final PsiClass containingClass = PsiTreeUtil.getParentOfType(statement, PsiClass.class); if (containingClass != null && TestFrameworks.getInstance().isTestClass(containingClass)) { return; } } final PsiCatchSection[] catchSections = statement.getCatchSections(); for (final PsiCatchSection section : catchSections) { checkCatchSection(section); } }