use of com.intellij.openapi.roots.ProjectFileIndex in project intellij-community by JetBrains.
the class IndexedRelevantResource method getResources.
public static <K, V extends Comparable> List<IndexedRelevantResource<K, V>> getResources(ID<K, V> indexId, final K key, @Nullable final Module module, @NotNull Project project, @Nullable final GlobalSearchScope additionalScope) {
if (project.isDefault())
return Collections.emptyList();
final ArrayList<IndexedRelevantResource<K, V>> resources = new ArrayList<>();
final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
FileBasedIndex.getInstance().processValues(indexId, key, null, new FileBasedIndex.ValueProcessor<V>() {
@Override
public boolean process(VirtualFile file, V value) {
ResourceRelevance relevance = ResourceRelevance.getRelevance(file, module, fileIndex, additionalScope);
resources.add(new IndexedRelevantResource<>(file, key, value, relevance));
return true;
}
}, new AdditionalIndexedRootsScope(GlobalSearchScope.allScope(project)));
return resources;
}
use of com.intellij.openapi.roots.ProjectFileIndex in project intellij-community by JetBrains.
the class MavenActionUtil method getMavenProjects.
public static List<MavenProject> getMavenProjects(DataContext context) {
Project project = CommonDataKeys.PROJECT.getData(context);
if (project == null)
return Collections.emptyList();
VirtualFile[] virtualFiles = CommonDataKeys.VIRTUAL_FILE_ARRAY.getData(context);
if (virtualFiles == null || virtualFiles.length == 0)
return Collections.emptyList();
MavenProjectsManager projectsManager = MavenProjectsManager.getInstance(project);
if (!projectsManager.isMavenizedProject())
return Collections.emptyList();
Set<MavenProject> res = new LinkedHashSet<>();
ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
for (VirtualFile file : virtualFiles) {
MavenProject mavenProject;
if (file.isDirectory()) {
VirtualFile contentRoot = fileIndex.getContentRootForFile(file);
if (!file.equals(contentRoot))
return Collections.emptyList();
Module module = fileIndex.getModuleForFile(file);
if (module == null || !projectsManager.isMavenizedModule(module))
return Collections.emptyList();
mavenProject = projectsManager.findProject(module);
} else {
mavenProject = projectsManager.findProject(file);
}
if (mavenProject == null)
return Collections.emptyList();
res.add(mavenProject);
}
return new ArrayList<>(res);
}
use of com.intellij.openapi.roots.ProjectFileIndex in project intellij-community by JetBrains.
the class JavaFxApplicationIconsDialog method doOKAction.
@Override
protected void doOKAction() {
final ProjectFileIndex index = ProjectRootManager.getInstance(myProject).getFileIndex();
if (!isValidPath(myPanel.myLinuxIconPath, index, "Linux"))
return;
if (!isValidPath(myPanel.myMacIconPath, index, "Mac"))
return;
if (!isValidPath(myPanel.myWindowsIconPath, index, "Windows"))
return;
super.doOKAction();
}
use of com.intellij.openapi.roots.ProjectFileIndex in project intellij-community by JetBrains.
the class CreateSnapShotAction method hasDirectoryInPackage.
private static boolean hasDirectoryInPackage(final Project project, final IdeView view) {
ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
PsiDirectory[] dirs = view.getDirectories();
for (PsiDirectory dir : dirs) {
if (projectFileIndex.isInSourceContent(dir.getVirtualFile()) && JavaDirectoryService.getInstance().getPackage(dir) != null) {
return true;
}
}
return false;
}
use of com.intellij.openapi.roots.ProjectFileIndex in project intellij-community by JetBrains.
the class Generator method createBeanClass.
@NotNull
private static PsiClass createBeanClass(final WizardData wizardData) throws MyException {
final PsiManager psiManager = PsiManager.getInstance(wizardData.myProject);
final ProjectRootManager projectRootManager = ProjectRootManager.getInstance(wizardData.myProject);
final ProjectFileIndex fileIndex = projectRootManager.getFileIndex();
final VirtualFile sourceRoot = fileIndex.getSourceRootForFile(wizardData.myFormFile);
if (sourceRoot == null) {
throw new MyException(UIDesignerBundle.message("error.form.file.is.not.in.source.root"));
}
final PsiDirectory rootDirectory = psiManager.findDirectory(sourceRoot);
LOG.assertTrue(rootDirectory != null);
final PsiPackage aPackage = JavaPsiFacade.getInstance(psiManager.getProject()).findPackage(wizardData.myPackageName);
if (aPackage == null) {
throw new MyException(UIDesignerBundle.message("error.package.does.not.exist", wizardData.myPackageName));
}
PsiDirectory targetDir = null;
final PsiDirectory[] directories = aPackage.getDirectories();
for (final PsiDirectory psiDirectory : directories) {
if (PsiTreeUtil.isAncestor(rootDirectory, psiDirectory, false)) {
targetDir = psiDirectory;
break;
}
}
if (targetDir == null) {
// todo
throw new MyException(UIDesignerBundle.message("error.cannot.find.package", wizardData.myPackageName));
}
//noinspection HardCodedStringLiteral
final String body = "public class " + wizardData.myShortClassName + "{\n" + "public " + wizardData.myShortClassName + "(){}\n" + "}";
try {
PsiFile sourceFile = PsiFileFactory.getInstance(psiManager.getProject()).createFileFromText(wizardData.myShortClassName + ".java", body);
sourceFile = (PsiFile) targetDir.add(sourceFile);
final PsiClass beanClass = ((PsiJavaFile) sourceFile).getClasses()[0];
final ArrayList<String> properties = new ArrayList<>();
final HashMap<String, String> property2fqClassName = new HashMap<>();
final FormProperty2BeanProperty[] bindings = wizardData.myBindings;
for (final FormProperty2BeanProperty binding : bindings) {
if (binding == null || binding.myBeanProperty == null) {
continue;
}
properties.add(binding.myBeanProperty.myName);
// todo: handle "casts" ?
final String propertyClassName = binding.myFormProperty.getComponentPropertyClassName();
property2fqClassName.put(binding.myBeanProperty.myName, propertyClassName);
}
generateBean(beanClass, ArrayUtil.toStringArray(properties), property2fqClassName);
return beanClass;
} catch (IncorrectOperationException e) {
throw new MyException(e.getMessage());
}
}
Aggregations