Icon (final Icon baseIcon, final VirtualFile file, final int flags, final Project project) { if (project == null) { return baseIcon; } FileType fileType = file.getFileType(); if (fileType == JavaFileType.INSTANCE && !FileIndexUtil.isJavaSourceFile(project, file)) { return PlatformIcons.JAVA_OUTSIDE_SOURCE_ICON; } PsiFile psiFile = PsiManager.getInstance(project).findFile(file); if (psiFile instanceof PsiClassOwner && psiFile.getViewProvider().getBaseLanguage() == JavaLanguage.INSTANCE) { PsiClass[] classes = ((PsiClassOwner)psiFile).getClasses(); if (classes.length > 0) { // prefer icon of the class named after file final String fileName = file.getNameWithoutExtension(); for (PsiClass aClass : classes) { if (aClass instanceof SyntheticElement) { return baseIcon; } if (Comparing.strEqual(aClass.getName(), fileName)) { return aClass.getIcon(flags); } } return classes[classes.length - 1].getIcon(flags); } } return baseIcon; }