use of com.intellij.openapi.roots.FileIndexFacade in project intellij-community by JetBrains.
the class MappingsToRoots method getRootsUnderVcs.
@NotNull
public VirtualFile[] getRootsUnderVcs(@NotNull AbstractVcs vcs) {
List<VirtualFile> result = myMappings.getMappingsAsFilesUnderVcs(vcs);
final AbstractVcs.RootsConvertor convertor = vcs.getCustomConvertor();
if (convertor != null) {
result = convertor.convertRoots(result);
}
Collections.sort(result, FilePathComparator.getInstance());
if (!vcs.allowsNestedRoots()) {
final FileIndexFacade facade = PeriodicalTasksCloser.getInstance().safeGetService(myProject, FileIndexFacade.class);
final List<VirtualFile> finalResult = result;
ApplicationManager.getApplication().runReadAction(() -> {
int i = 1;
while (i < finalResult.size()) {
final VirtualFile previous = finalResult.get(i - 1);
final VirtualFile current = finalResult.get(i);
if (facade.isValidAncestor(previous, current)) {
finalResult.remove(i);
} else {
i++;
}
}
});
}
result.removeIf(file -> !file.isDirectory());
return VfsUtilCore.toVirtualFileArray(result);
}
use of com.intellij.openapi.roots.FileIndexFacade in project intellij-community by JetBrains.
the class GenericsHighlightUtil method isSuperTypeAccessible.
@Nullable
private static String isSuperTypeAccessible(PsiType superType, HashSet<PsiClass> classes, boolean checkParameters, GlobalSearchScope resolveScope, JavaPsiFacade factory) {
final PsiClass aClass = PsiUtil.resolveClassInType(superType);
if (aClass != null && classes.add(aClass)) {
VirtualFile vFile = PsiUtilCore.getVirtualFile(aClass);
if (vFile == null) {
return null;
}
FileIndexFacade index = FileIndexFacade.getInstance(aClass.getProject());
if (!index.isInSource(vFile) && !index.isInLibraryClasses(vFile)) {
return null;
}
final String qualifiedName = aClass.getQualifiedName();
if (qualifiedName != null && factory.findClass(qualifiedName, resolveScope) == null) {
return "Cannot access " + HighlightUtil.formatClass(aClass);
}
if (checkParameters) {
boolean isInLibrary = !index.isInContent(vFile);
if (superType instanceof PsiClassType) {
for (PsiType psiType : ((PsiClassType) superType).getParameters()) {
final String notAccessibleMessage = isSuperTypeAccessible(psiType, classes, true, resolveScope, factory);
if (notAccessibleMessage != null) {
return notAccessibleMessage;
}
}
}
for (PsiClassType type : aClass.getSuperTypes()) {
final String notAccessibleMessage = isSuperTypeAccessible(type, classes, !isInLibrary, resolveScope, factory);
if (notAccessibleMessage != null) {
return notAccessibleMessage;
}
}
}
}
return null;
}
use of com.intellij.openapi.roots.FileIndexFacade in project intellij-community by JetBrains.
the class CoreJavaDirectoryService method getPsiClasses.
@NotNull
public static PsiClass[] getPsiClasses(@NotNull PsiDirectory dir, PsiFile[] psiFiles) {
FileIndexFacade index = FileIndexFacade.getInstance(dir.getProject());
VirtualFile virtualDir = dir.getVirtualFile();
boolean onlyCompiled = index.isInLibraryClasses(virtualDir) && !index.isInSourceContent(virtualDir);
List<PsiClass> classes = null;
for (PsiFile file : psiFiles) {
if (onlyCompiled && !(file instanceof ClsFileImpl)) {
continue;
}
if (file instanceof PsiClassOwner && file.getViewProvider().getLanguages().size() == 1) {
PsiClass[] psiClasses = ((PsiClassOwner) file).getClasses();
if (psiClasses.length == 0)
continue;
if (classes == null)
classes = new ArrayList<>();
ContainerUtil.addAll(classes, psiClasses);
}
}
return classes == null ? PsiClass.EMPTY_ARRAY : classes.toArray(new PsiClass[classes.size()]);
}
use of com.intellij.openapi.roots.FileIndexFacade in project intellij-community by JetBrains.
the class PsiClassImplUtil method isClassEquivalentTo.
public static boolean isClassEquivalentTo(@NotNull PsiClass aClass, PsiElement another) {
if (aClass == another)
return true;
if (!(another instanceof PsiClass))
return false;
String name1 = aClass.getName();
if (name1 == null)
return false;
if (!another.isValid())
return false;
String name2 = ((PsiClass) another).getName();
if (name2 == null)
return false;
if (name1.hashCode() != name2.hashCode())
return false;
if (!name1.equals(name2))
return false;
String qName1 = aClass.getQualifiedName();
String qName2 = ((PsiClass) another).getQualifiedName();
if (qName1 == null || qName2 == null) {
//noinspection StringEquality
if (qName1 != qName2)
return false;
if (aClass instanceof PsiTypeParameter && another instanceof PsiTypeParameter) {
PsiTypeParameter p1 = (PsiTypeParameter) aClass;
PsiTypeParameter p2 = (PsiTypeParameter) another;
return p1.getIndex() == p2.getIndex() && (aClass.getManager().areElementsEquivalent(p1.getOwner(), p2.getOwner()) || TypeConversionUtil.areSameFreshVariables(p1, p2));
} else {
return false;
}
}
if (qName1.hashCode() != qName2.hashCode() || !qName1.equals(qName2)) {
return false;
}
if (aClass.getOriginalElement().equals(another.getOriginalElement())) {
return true;
}
final PsiFile file1 = aClass.getContainingFile().getOriginalFile();
final PsiFile file2 = another.getContainingFile().getOriginalFile();
//see com.intellij.openapi.vcs.changes.PsiChangeTracker
//see com.intellij.psi.impl.PsiFileFactoryImpl#createFileFromText(CharSequence,PsiFile)
final PsiFile original1 = file1.getUserData(PsiFileFactory.ORIGINAL_FILE);
final PsiFile original2 = file2.getUserData(PsiFileFactory.ORIGINAL_FILE);
if (original1 == original2 && original1 != null || original1 == file2 || original2 == file1 || file1 == file2) {
return compareClassSeqNumber(aClass, (PsiClass) another);
}
final FileIndexFacade fileIndex = ServiceManager.getService(file1.getProject(), FileIndexFacade.class);
final VirtualFile vfile1 = file1.getViewProvider().getVirtualFile();
final VirtualFile vfile2 = file2.getViewProvider().getVirtualFile();
boolean lib1 = fileIndex.isInLibraryClasses(vfile1);
boolean lib2 = fileIndex.isInLibraryClasses(vfile2);
return (fileIndex.isInSource(vfile1) || lib1) && (fileIndex.isInSource(vfile2) || lib2);
}
use of com.intellij.openapi.roots.FileIndexFacade in project intellij-community by JetBrains.
the class PsiSuperMethodUtil method correctClassByScope.
@Nullable
public static PsiClass correctClassByScope(PsiClass psiClass, final GlobalSearchScope resolveScope) {
if (psiClass == null)
return null;
String qualifiedName = psiClass.getQualifiedName();
if (qualifiedName == null) {
return psiClass;
}
PsiFile file = psiClass.getContainingFile();
if (file == null || !file.getViewProvider().isPhysical()) {
return psiClass;
}
final VirtualFile vFile = file.getVirtualFile();
if (vFile == null) {
return psiClass;
}
final FileIndexFacade index = FileIndexFacade.getInstance(file.getProject());
if (!index.isInSource(vFile) && !index.isInLibrarySource(vFile) && !index.isInLibraryClasses(vFile)) {
return psiClass;
}
return JavaPsiFacade.getInstance(psiClass.getProject()).findClass(qualifiedName, resolveScope);
}
Aggregations