Search in sources :

Example 1 with PsiDirectoryFactory

use of com.intellij.psi.impl.file.PsiDirectoryFactory in project intellij-community by JetBrains.

the class CreateDirectoryOrPackageAction method update.

@Override
public void update(AnActionEvent event) {
    Presentation presentation = event.getPresentation();
    Project project = event.getData(CommonDataKeys.PROJECT);
    if (project == null) {
        presentation.setVisible(false);
        presentation.setEnabled(false);
        return;
    }
    IdeView view = event.getData(LangDataKeys.IDE_VIEW);
    if (view == null) {
        presentation.setVisible(false);
        presentation.setEnabled(false);
        return;
    }
    final PsiDirectory[] directories = view.getDirectories();
    if (directories.length == 0) {
        presentation.setVisible(false);
        presentation.setEnabled(false);
        return;
    }
    presentation.setVisible(true);
    presentation.setEnabled(true);
    boolean isPackage = false;
    final PsiDirectoryFactory factory = PsiDirectoryFactory.getInstance(project);
    for (PsiDirectory directory : directories) {
        if (factory.isPackage(directory)) {
            isPackage = true;
            break;
        }
    }
    if (isPackage) {
        presentation.setText(IdeBundle.message("action.package"));
        presentation.setIcon(PlatformIcons.PACKAGE_ICON);
    } else {
        presentation.setText(IdeBundle.message("action.directory"));
        presentation.setIcon(PlatformIcons.DIRECTORY_CLOSED_ICON);
    }
}
Also used : Project(com.intellij.openapi.project.Project) PsiDirectory(com.intellij.psi.PsiDirectory) IdeView(com.intellij.ide.IdeView) PsiDirectoryFactory(com.intellij.psi.impl.file.PsiDirectoryFactory)

Example 2 with PsiDirectoryFactory

use of com.intellij.psi.impl.file.PsiDirectoryFactory in project intellij-community by JetBrains.

the class WrongPackageStatementInspectionBase method isValidPackageName.

private static boolean isValidPackageName(String packageName, final Project project) {
    PsiDirectoryFactory factory = PsiDirectoryFactory.getInstance(project);
    Iterable<String> shortNames = StringUtil.tokenize(packageName, ".");
    for (String shortName : shortNames) {
        if (!factory.isValidPackageName(shortName))
            return false;
    }
    return true;
}
Also used : PsiDirectoryFactory(com.intellij.psi.impl.file.PsiDirectoryFactory)

Aggregations

PsiDirectoryFactory (com.intellij.psi.impl.file.PsiDirectoryFactory)2 IdeView (com.intellij.ide.IdeView)1 Project (com.intellij.openapi.project.Project)1 PsiDirectory (com.intellij.psi.PsiDirectory)1