Collection<VirtualFile> (final String className, final GlobalSearchScope scope, final ProjectFileIndex fileIndex) { final int dollarIndex = className.indexOf("$"); final String topLevelClassName = dollarIndex >= 0 ? className.substring(0, dollarIndex) : className; return ReadAction.compute(() -> { final PsiClass[] classes = JavaPsiFacade.getInstance(myProject).findClasses(topLevelClassName, scope); if (LOG.isDebugEnabled()) { LOG.debug("Found " + classes.length + " classes " + topLevelClassName + " in scope " + scope); } if (classes.length == 0) { return null; } final List<VirtualFile> list = new ArrayList<>(classes.length); for (PsiClass aClass : classes) { final PsiFile psiFile = aClass.getContainingFile(); if (LOG.isDebugEnabled()) { final StringBuilder msg = new StringBuilder(); msg.append("Checking class ").append(aClass.getQualifiedName()); msg.append("\n\t").append("PsiFile=").append(psiFile); if (psiFile != null) { final VirtualFile vFile = psiFile.getVirtualFile(); msg.append("\n\t").append("VirtualFile=").append(vFile); if (vFile != null) { msg.append("\n\t").append("isInSourceContent=").append(fileIndex.isUnderSourceRootOfType(vFile, JavaModuleSourceRootTypes.SOURCES)); } } LOG.debug(msg.toString()); } if (psiFile == null) { return null; } final VirtualFile vFile = psiFile.getVirtualFile(); if (vFile == null || !fileIndex.isUnderSourceRootOfType(vFile, JavaModuleSourceRootTypes.SOURCES)) { return null; // this will switch off the check if at least one class is from libraries } list.add(vFile); } return list; }); }