Search in sources :

Example 1 with JavaDirectoryService

use of com.intellij.psi.JavaDirectoryService in project android by JetBrains.

the class JavaSourceAction method isAvailable.

protected static boolean isAvailable(DataContext dataContext) {
    final Module module = LangDataKeys.MODULE.getData(dataContext);
    final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
    if (module == null || view == null || view.getDirectories().length == 0 || AndroidFacet.getInstance(module) == null) {
        return false;
    }
    final ProjectFileIndex projectIndex = ProjectRootManager.getInstance(module.getProject()).getFileIndex();
    final JavaDirectoryService dirService = JavaDirectoryService.getInstance();
    for (PsiDirectory dir : view.getDirectories()) {
        if (projectIndex.isUnderSourceRootOfType(dir.getVirtualFile(), JavaModuleSourceRootTypes.SOURCES) && dirService.getPackage(dir) != null && !dirService.getPackage(dir).getQualifiedName().isEmpty()) {
            return true;
        }
    }
    return false;
}
Also used : ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) PsiDirectory(com.intellij.psi.PsiDirectory) Module(com.intellij.openapi.module.Module) IdeView(com.intellij.ide.IdeView) JavaDirectoryService(com.intellij.psi.JavaDirectoryService)

Example 2 with JavaDirectoryService

use of com.intellij.psi.JavaDirectoryService in project android by JetBrains.

the class LegacyNewAndroidComponentAction method isAvailable.

private static boolean isAvailable(DataContext dataContext) {
    final Module module = LangDataKeys.MODULE.getData(dataContext);
    final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
    if (module == null || view == null || view.getDirectories().length == 0) {
        return false;
    }
    final AndroidFacet facet = AndroidFacet.getInstance(module);
    if (facet == null || facet.requiresAndroidModel()) {
        return false;
    }
    final ProjectFileIndex projectIndex = ProjectRootManager.getInstance(module.getProject()).getFileIndex();
    final JavaDirectoryService dirService = JavaDirectoryService.getInstance();
    for (PsiDirectory dir : view.getDirectories()) {
        if (projectIndex.isUnderSourceRootOfType(dir.getVirtualFile(), JavaModuleSourceRootTypes.SOURCES) && dirService.getPackage(dir) != null) {
            return true;
        }
    }
    return false;
}
Also used : ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) PsiDirectory(com.intellij.psi.PsiDirectory) Module(com.intellij.openapi.module.Module) IdeView(com.intellij.ide.IdeView) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) JavaDirectoryService(com.intellij.psi.JavaDirectoryService)

Example 3 with JavaDirectoryService

use of com.intellij.psi.JavaDirectoryService in project intellij-community by JetBrains.

the class CreatePackageInfoAction method isAvailable.

private static boolean isAvailable(DataContext dataContext) {
    final Project project = CommonDataKeys.PROJECT.getData(dataContext);
    final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
    if (project == null || view == null) {
        return false;
    }
    final PsiDirectory[] directories = view.getDirectories();
    if (directories.length == 0) {
        return false;
    }
    final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
    final JavaDirectoryService directoryService = JavaDirectoryService.getInstance();
    final PsiNameHelper nameHelper = PsiNameHelper.getInstance(project);
    for (PsiDirectory directory : directories) {
        if (projectFileIndex.isUnderSourceRootOfType(directory.getVirtualFile(), JavaModuleSourceRootTypes.SOURCES) && PsiUtil.isLanguageLevel5OrHigher(directory)) {
            final PsiPackage aPackage = directoryService.getPackage(directory);
            if (aPackage != null) {
                final String qualifiedName = aPackage.getQualifiedName();
                if (StringUtil.isEmpty(qualifiedName) || nameHelper.isQualifiedName(qualifiedName)) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : PsiNameHelper(com.intellij.psi.PsiNameHelper) Project(com.intellij.openapi.project.Project) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) PsiDirectory(com.intellij.psi.PsiDirectory) PsiPackage(com.intellij.psi.PsiPackage) IdeView(com.intellij.ide.IdeView) JavaDirectoryService(com.intellij.psi.JavaDirectoryService)

Example 4 with JavaDirectoryService

use of com.intellij.psi.JavaDirectoryService in project qi4j-sdk by Qi4j.

the class CreateConcernOfInPackageAction method doCheckCreate.

protected final void doCheckCreate(final PsiDirectory dir, final String className) throws IncorrectOperationException {
    JavaDirectoryService javaDirectoryService = JavaDirectoryService.getInstance();
    javaDirectoryService.checkCreateClass(dir, className);
}
Also used : JavaDirectoryService(com.intellij.psi.JavaDirectoryService)

Aggregations

JavaDirectoryService (com.intellij.psi.JavaDirectoryService)4 IdeView (com.intellij.ide.IdeView)3 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)3 PsiDirectory (com.intellij.psi.PsiDirectory)3 Module (com.intellij.openapi.module.Module)2 Project (com.intellij.openapi.project.Project)1 PsiNameHelper (com.intellij.psi.PsiNameHelper)1 PsiPackage (com.intellij.psi.PsiPackage)1 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)1