use of com.intellij.psi.PsiDirectory in project intellij-community by JetBrains.
the class GeneratePluginClassAction method update.
public void update(final AnActionEvent e) {
super.update(e);
final Presentation presentation = e.getPresentation();
if (presentation.isEnabled()) {
final Project project = e.getProject();
final Module module = e.getData(LangDataKeys.MODULE);
if (project != null && module != null && PsiUtil.isPluginModule(module)) {
final IdeView view = e.getData(LangDataKeys.IDE_VIEW);
if (view != null) {
// from com.intellij.ide.actions.CreateClassAction.update()
ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
PsiDirectory[] dirs = view.getDirectories();
for (PsiDirectory dir : dirs) {
if (projectFileIndex.isUnderSourceRootOfType(dir.getVirtualFile(), JavaModuleSourceRootTypes.SOURCES) && JavaDirectoryService.getInstance().getPackage(dir) != null) {
return;
}
}
}
}
presentation.setEnabledAndVisible(false);
}
}
use of com.intellij.psi.PsiDirectory in project intellij-community by JetBrains.
the class PsiDiffContentFactory method fromPsiElement.
@Nullable
private static DiffContent fromPsiElement(@NotNull PsiElement psiElement) {
DiffContentFactory factory = DiffContentFactory.getInstance();
if (psiElement instanceof PsiFile) {
return factory.create(psiElement.getProject(), ((PsiFile) psiElement).getVirtualFile());
} else if (psiElement instanceof PsiDirectory) {
return factory.create(psiElement.getProject(), ((PsiDirectory) psiElement).getVirtualFile());
}
PsiFile containingFile = psiElement.getContainingFile();
if (containingFile == null) {
String text = psiElement.getText();
if (text == null)
return null;
return factory.create(psiElement.getProject(), text, psiElement.getLanguage().getAssociatedFileType(), false);
}
DocumentContent wholeFileContent = factory.createDocument(psiElement.getProject(), containingFile.getVirtualFile());
if (wholeFileContent == null)
return null;
return factory.createFragment(psiElement.getProject(), wholeFileContent, psiElement.getTextRange());
}
use of com.intellij.psi.PsiDirectory in project intellij-community by JetBrains.
the class ClassBrowser method configureDialog.
private void configureDialog(final TreeClassChooser dialog) {
final String className = getText();
final PsiClass psiClass = findClass(className);
if (psiClass == null)
return;
final PsiDirectory directory = psiClass.getContainingFile().getContainingDirectory();
if (directory != null)
dialog.selectDirectory(directory);
dialog.select(psiClass);
}
use of com.intellij.psi.PsiDirectory in project intellij-community by JetBrains.
the class LocationUtil method isJarAttached.
public static boolean isJarAttached(@NotNull Location location, final PsiDirectory[] directories, final String... fqns) {
final JavaPsiFacade facade = JavaPsiFacade.getInstance(location.getProject());
final Module locationModule = location.getModule();
if (locationModule != null) {
for (String fqn : fqns) {
if (facade.findClass(fqn, GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(locationModule, true)) != null)
return true;
}
} else {
for (PsiDirectory directory : directories) {
final Module module = ModuleUtilCore.findModuleForFile(directory.getVirtualFile(), location.getProject());
if (module != null) {
GlobalSearchScope scope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module, true);
for (String fqn : fqns) {
if (facade.findClass(fqn, scope) != null) {
return true;
}
}
}
}
}
return false;
}
use of com.intellij.psi.PsiDirectory in project intellij-community by JetBrains.
the class ReformatFilesWithFiltersTest method testDirectoryScope.
public void testDirectoryScope() throws IOException {
TestFileStructure fileTree = new TestFileStructure(getModule(), myWorkingDirectory);
PsiFile java1 = fileTree.addTestFile("Test1.java", "empty content");
PsiFile php1 = fileTree.addTestFile("Pair1.php", "empty content");
PsiFile js1 = fileTree.addTestFile("Pair1.js", "empty content");
PsiDirectory outer = fileTree.createDirectoryAndMakeItCurrent("toFormat");
PsiFile java2 = fileTree.addTestFile("Test2.java", "empty content");
PsiFile php2 = fileTree.addTestFile("Pair2.php", "empty content");
PsiFile js2 = fileTree.addTestFile("Pair2.js", "empty content");
PsiDirectory inner = fileTree.createDirectoryAndMakeItCurrent("toFormat");
PsiFile java3 = fileTree.addTestFile("Test3.java", "empty content");
PsiFile php3 = fileTree.addTestFile("Pair3.php", "empty content");
PsiFile js3 = fileTree.addTestFile("Pair3.js", "empty content");
reformatDirectoryWithScopeFilter(myWorkingDirectory, directoryScope(outer, true));
assertWasFormatted(java2, php2, js2, java3, php3, js3);
assertWasNotFormatted(java1, php1, js1);
reformatDirectoryWithScopeFilter(myWorkingDirectory, directoryScope(outer, false));
assertWasFormatted(java2, php2, js2);
assertWasNotFormatted(java1, php1, js1, java3, php3, js3);
reformatDirectoryWithScopeFilter(myWorkingDirectory, directoryScope(inner, true));
assertWasFormatted(java3, php3, js3);
assertWasNotFormatted(java1, php1, js1, java2, php2, js2);
reformatDirectoryWithScopeFilter(myWorkingDirectory, directoryScope(myWorkingDirectory, false).union(directoryScope(inner, false)));
assertWasFormatted(java3, php3, js3, java1, php1, js1);
assertWasNotFormatted(java2, php2, js2);
}
Aggregations