use of com.intellij.openapi.roots.ModuleFileIndex in project intellij-community by JetBrains.
the class GroovyAntCustomCompilerProvider method hasCustomCompile.
/**
* {@inheritDoc}
*/
@Override
public boolean hasCustomCompile(ModuleChunk chunk) {
for (Module m : chunk.getModules()) {
if (LibrariesUtil.hasGroovySdk(m)) {
final Set<String> scriptExtensions = GroovyFileTypeLoader.getCustomGroovyScriptExtensions();
final ContentIterator groovyFileSearcher = new ContentIterator() {
@Override
public boolean processFile(VirtualFile fileOrDir) {
ProgressManager.checkCanceled();
if (isCompilableGroovyFile(fileOrDir, scriptExtensions)) {
return false;
}
return true;
}
};
final ModuleRootManager rootManager = ModuleRootManager.getInstance(m);
final ModuleFileIndex fileIndex = rootManager.getFileIndex();
for (VirtualFile file : rootManager.getSourceRoots(JavaModuleSourceRootTypes.SOURCES)) {
if (!fileIndex.iterateContentUnderDirectory(file, groovyFileSearcher)) {
return true;
}
}
}
}
return false;
}
use of com.intellij.openapi.roots.ModuleFileIndex in project intellij-community by JetBrains.
the class HighlightClassUtil method checkDuplicateTopLevelClass.
@Nullable
static HighlightInfo checkDuplicateTopLevelClass(PsiClass aClass) {
if (!(aClass.getParent() instanceof PsiFile))
return null;
String qualifiedName = aClass.getQualifiedName();
if (qualifiedName == null)
return null;
int numOfClassesToFind = 2;
if (qualifiedName.contains("$")) {
qualifiedName = qualifiedName.replaceAll("\\$", ".");
numOfClassesToFind = 1;
}
PsiManager manager = aClass.getManager();
Module module = ModuleUtilCore.findModuleForPsiElement(aClass);
if (module == null)
return null;
PsiClass[] classes = JavaPsiFacade.getInstance(aClass.getProject()).findClasses(qualifiedName, GlobalSearchScope.moduleScope(module).intersectWith(aClass.getResolveScope()));
if (classes.length < numOfClassesToFind)
return null;
final ModuleFileIndex fileIndex = ModuleRootManager.getInstance(module).getFileIndex();
final VirtualFile virtualFile = PsiUtilCore.getVirtualFile(aClass);
if (virtualFile == null)
return null;
final boolean isTestSourceRoot = fileIndex.isInTestSourceContent(virtualFile);
String dupFileName = null;
for (PsiClass dupClass : classes) {
// do not use equals
if (dupClass != aClass) {
VirtualFile file = dupClass.getContainingFile().getVirtualFile();
if (file != null && manager.isInProject(dupClass) && fileIndex.isInTestSourceContent(file) == isTestSourceRoot) {
dupFileName = FileUtil.toSystemDependentName(file.getPath());
break;
}
}
}
if (dupFileName == null)
return null;
String message = JavaErrorMessages.message("duplicate.class.in.other.file", dupFileName);
TextRange textRange = HighlightNamesUtil.getClassDeclarationTextRange(aClass);
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(textRange).descriptionAndTooltip(message).create();
}
use of com.intellij.openapi.roots.ModuleFileIndex in project intellij-community by JetBrains.
the class AbstractFileProcessor method findFiles.
protected static void findFiles(final Module module, final List<PsiFile> files) {
final ModuleFileIndex idx = ModuleRootManager.getInstance(module).getFileIndex();
final VirtualFile[] roots = ModuleRootManager.getInstance(module).getContentRoots();
for (final VirtualFile root : roots) {
ApplicationManager.getApplication().runReadAction(() -> {
idx.iterateContentUnderDirectory(root, new ContentIterator() {
@Override
public boolean processFile(final VirtualFile dir) {
if (dir.isDirectory()) {
final PsiDirectory psiDir = PsiManager.getInstance(module.getProject()).findDirectory(dir);
if (psiDir != null) {
findFiles(files, psiDir, false);
}
}
return true;
}
});
});
}
}
use of com.intellij.openapi.roots.ModuleFileIndex in project intellij-plugins by JetBrains.
the class InjectionUtil method resolveResult.
@Nullable
private static PsiFileSystemItem resolveResult(PsiElement element, ResolveResult[] resolveResults) {
InjectedLanguageManager manager = InjectedLanguageManager.getInstance(element.getProject());
final PsiFile currentTopLevelFile = manager.getTopLevelFile(element);
// find equal files
for (ResolveResult resolveResult : resolveResults) {
PsiElement resolvedElement = resolveResult.getElement();
assert resolvedElement != null;
if (manager.getTopLevelFile(resolvedElement).equals(currentTopLevelFile)) {
return (PsiFileSystemItem) resolvedElement;
}
}
final Module module = ModuleUtilCore.findModuleForPsiElement(element);
if (module != null) {
final ModuleFileIndex fileIndex = ModuleRootManager.getInstance(module).getFileIndex();
// return if is local file
for (ResolveResult resolveResult : resolveResults) {
PsiFileSystemItem resolvedElement = (PsiFileSystemItem) resolveResult.getElement();
assert resolvedElement != null;
VirtualFile virtualFile = resolvedElement.getVirtualFile();
if (virtualFile != null && fileIndex.isInSourceContent(virtualFile)) {
return resolvedElement;
}
}
}
return (PsiFileSystemItem) resolveResults[0].getElement();
}
Aggregations