use of com.intellij.openapi.roots.ProjectFileIndex in project intellij-community by JetBrains.
the class MarkLibraryRootAction method update.
@Override
public void update(AnActionEvent e) {
final Project project = getEventProject(e);
boolean visible = false;
if (project != null && ModuleManager.getInstance(project).getModules().length > 0) {
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
for (VirtualFile root : getRoots(e)) {
if (!root.isInLocalFileSystem() && FileUtilRt.extensionEquals(root.getName(), "jar") && !fileIndex.isInLibraryClasses(root)) {
visible = true;
break;
}
if (root.isInLocalFileSystem() && root.isDirectory()) {
for (VirtualFile child : root.getChildren()) {
if (FileUtilRt.extensionEquals(child.getName(), "jar")) {
final VirtualFile jarRoot = JarFileSystem.getInstance().getJarRootForLocalFile(child);
if (jarRoot != null && !fileIndex.isInLibraryClasses(child)) {
visible = true;
break;
}
}
}
}
}
}
e.getPresentation().setVisible(visible);
e.getPresentation().setEnabled(visible);
}
use of com.intellij.openapi.roots.ProjectFileIndex in project intellij-community by JetBrains.
the class CreateModuleInfoAction method getTargetDirectory.
@Nullable
@Override
protected PsiDirectory getTargetDirectory(DataContext ctx, IdeView view) {
PsiDirectory[] directories = view.getDirectories();
if (directories.length == 1) {
PsiDirectory psiDir = directories[0];
VirtualFile vDir = psiDir.getVirtualFile();
ProjectFileIndex index = ProjectRootManager.getInstance(psiDir.getProject()).getFileIndex();
if (vDir.equals(index.getSourceRootForFile(vDir)) && index.isUnderSourceRootOfType(vDir, singleton(JavaSourceRootType.SOURCE))) {
return psiDir;
}
}
return null;
}
use of com.intellij.openapi.roots.ProjectFileIndex in project intellij-community by JetBrains.
the class PsiPackageFavoriteNodeProvider method elementContainsFile.
@Override
public boolean elementContainsFile(final Object element, final VirtualFile vFile) {
if (element instanceof PackageElement) {
final Set<Boolean> find = new HashSet<>();
final ContentIterator contentIterator = new ContentIterator() {
@Override
public boolean processFile(VirtualFile fileOrDir) {
if (fileOrDir != null && fileOrDir.getPath().equals(vFile.getPath())) {
find.add(Boolean.TRUE);
}
return true;
}
};
final PackageElement packageElement = (PackageElement) element;
final PsiPackage aPackage = packageElement.getPackage();
final Project project = aPackage.getProject();
final GlobalSearchScope scope = packageElement.getModule() != null ? GlobalSearchScope.moduleScope(packageElement.getModule()) : GlobalSearchScope.projectScope(project);
final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
final PsiDirectory[] directories = aPackage.getDirectories(scope);
for (PsiDirectory directory : directories) {
projectFileIndex.iterateContentUnderDirectory(directory.getVirtualFile(), contentIterator);
}
return !find.isEmpty();
}
return false;
}
use of com.intellij.openapi.roots.ProjectFileIndex in project intellij-community by JetBrains.
the class JavaTestFinder method getModule.
@Nullable
private static Module getModule(PsiElement element) {
ProjectFileIndex index = ProjectRootManager.getInstance(element.getProject()).getFileIndex();
VirtualFile file = PsiUtilCore.getVirtualFile(element);
return file == null ? null : index.getModuleForFile(file);
}
use of com.intellij.openapi.roots.ProjectFileIndex in project intellij-community by JetBrains.
the class PsiTypeTokenizer method tokenize.
@Override
public void tokenize(@NotNull PsiTypeElement element, TokenConsumer consumer) {
final PsiType type = element.getType();
if (type instanceof PsiDisjunctionType) {
tokenizeComplexType(element, consumer);
return;
}
final PsiClass psiClass = PsiUtil.resolveClassInType(type);
if (psiClass == null || psiClass.getContainingFile() == null || psiClass.getContainingFile().getVirtualFile() == null) {
return;
}
final String name = psiClass.getName();
if (name == null) {
return;
}
final VirtualFile virtualFile = psiClass.getContainingFile().getVirtualFile();
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(element.getProject()).getFileIndex();
final boolean isInSource = (virtualFile != null) && fileIndex.isInContent(virtualFile);
if (isInSource) {
final String elementText = element.getText();
if (elementText.contains(name)) {
consumer.consumeToken(element, elementText, true, 0, getRangeToCheck(elementText, name), IdentifierSplitter.getInstance());
}
}
}
Aggregations