PsiFile (final Project project, final Location location) { if (location == null) { return null; } final ReferenceType refType = location.declaringType(); if (refType == null) { return null; } // We should find a class no matter what // setAlternativeResolveEnabled is turned on here //if (DumbService.getInstance(project).isDumb()) { // return null; //} final String originalQName = refType.name(); Ref<PsiFile> altSource = new Ref<>(); PsiClass psiClass = findPsiClassByName(originalQName, c -> altSource.set(findAlternativeJreSourceFile(c))); if (!altSource.isNull()) { return altSource.get(); } if (psiClass != null) { PsiElement element = psiClass.getNavigationElement(); // see IDEA-137167, prefer not compiled elements if (element instanceof PsiCompiledElement) { PsiElement fileElement = psiClass.getContainingFile().getNavigationElement(); if (!(fileElement instanceof PsiCompiledElement)) { element = fileElement; } } return element.getContainingFile(); } else { // try to search by filename try { PsiFile[] files = FilenameIndex.getFilesByName(project, refType.sourceName(), GlobalSearchScope.allScope(project)); for (PsiFile file : files) { if (file instanceof PsiJavaFile) { for (PsiClass cls : PsiTreeUtil.findChildrenOfAnyType(file, PsiClass.class)) { if (StringUtil.equals(originalQName, JVMNameUtil.getClassVMName(cls))) { return file; } } } } } catch (AbsentInformationException ignore) { } } return null; }