Search in sources :

Example 46 with PsiPackage

use of com.intellij.psi.PsiPackage 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 47 with PsiPackage

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

the class AllInPackageGradleConfigurationProducer method doSetupConfigurationFromContext.

@Override
protected boolean doSetupConfigurationFromContext(ExternalSystemRunConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
    final PsiPackage psiPackage = JavaRuntimeConfigurationProducerBase.checkPackage(context.getPsiLocation());
    if (psiPackage == null)
        return false;
    sourceElement.set(psiPackage);
    final Module module = context.getModule();
    if (module == null)
        return false;
    if (!ExternalSystemApiUtil.isExternalSystemAwareModule(GradleConstants.SYSTEM_ID, module))
        return false;
    final String projectPath = ExternalSystemApiUtil.getExternalProjectPath(module);
    if (projectPath == null)
        return false;
    List<String> tasksToRun = getTasksToRun(module);
    if (tasksToRun.isEmpty())
        return false;
    configuration.getSettings().setExternalProjectPath(projectPath);
    configuration.getSettings().setTaskNames(tasksToRun);
    if (psiPackage.getQualifiedName().isEmpty()) {
        configuration.getSettings().setScriptParameters("--tests *");
    } else {
        configuration.getSettings().setScriptParameters(String.format("--tests %s.*", psiPackage.getQualifiedName()));
    }
    configuration.setName(suggestName(psiPackage, module));
    return true;
}
Also used : PsiPackage(com.intellij.psi.PsiPackage) Module(com.intellij.openapi.module.Module)

Example 48 with PsiPackage

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

the class MvcTargetDialogCompletionUtils method collectClassesAndPackageNames.

private static void collectClassesAndPackageNames(Collection<LookupElement> res, @NotNull PsiPackage aPackage, GlobalSearchScope scope) {
    PsiPackage[] subPackages = aPackage.getSubPackages(scope);
    String qualifiedName = aPackage.getQualifiedName();
    if (!qualifiedName.isEmpty()) {
        if (subPackages.length == 0 || aPackage.getClasses(scope).length > 0) {
            res.add(TailTypeDecorator.withTail(LookupElementBuilder.create(qualifiedName), TailType.DOT));
        }
    }
    for (PsiPackage subPackage : subPackages) {
        collectClassesAndPackageNames(res, subPackage, scope);
    }
}
Also used : PsiPackage(com.intellij.psi.PsiPackage)

Example 49 with PsiPackage

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

the class CoverageJavaRunConfigurationExtension method wrapElementListener.

@Override
public RefactoringElementListener wrapElementListener(PsiElement element, RunConfigurationBase configuration, RefactoringElementListener listener) {
    if (!isApplicableFor(configuration)) {
        return listener;
    }
    final JavaCoverageEnabledConfiguration coverageEnabledConfiguration = JavaCoverageEnabledConfiguration.getFrom(configuration);
    if (coverageEnabledConfiguration != null) {
        final Project project = configuration.getProject();
        final ClassFilter[] patterns = coverageEnabledConfiguration.getCoveragePatterns();
        final String[] filters = getFilters(coverageEnabledConfiguration);
        if (patterns != null) {
            assert filters != null;
            if (element instanceof PsiClass) {
                final String qualifiedName = ((PsiClass) element).getQualifiedName();
                final int idx = ArrayUtil.find(filters, qualifiedName);
                if (idx > -1) {
                    final RefactoringListeners.Accessor<PsiClass> accessor = new MyClassAccessor(project, patterns, idx, filters);
                    final RefactoringElementListener classListener = RefactoringListeners.getClassOrPackageListener(element, accessor);
                    if (classListener != null) {
                        listener = appendListener(listener, classListener);
                    }
                } else if (qualifiedName != null) {
                    final String packageName = StringUtil.getPackageName(qualifiedName);
                    if (!StringUtil.isEmpty(packageName)) {
                        for (int i = 0; i < filters.length; i++) {
                            String filter = filters[i];
                            if (filter.equals(packageName + ".*")) {
                                listener = appendListener(listener, new RefactoringListeners.RefactorPackageByClass(new MyClassAccessor(project, patterns, i, filters)));
                                break;
                            }
                        }
                    }
                }
            } else if (element instanceof PsiPackage) {
                final String qualifiedName = ((PsiPackage) element).getQualifiedName();
                for (int i = 0, filtersLength = filters.length; i < filtersLength; i++) {
                    if (filters[i].startsWith(qualifiedName + ".")) {
                        final RefactoringElementListener packageListener;
                        if (filters[i].endsWith("*")) {
                            packageListener = RefactoringListeners.getListener((PsiPackage) element, new MyPackageAccessor(project, patterns, i, filters));
                        } else {
                            packageListener = RefactoringListeners.getClassOrPackageListener(element, new MyClassAccessor(project, patterns, i, filters));
                        }
                        if (packageListener != null) {
                            listener = appendListener(listener, packageListener);
                        }
                    }
                }
            }
        }
    }
    return listener;
}
Also used : RefactoringElementListener(com.intellij.refactoring.listeners.RefactoringElementListener) PsiClass(com.intellij.psi.PsiClass) PsiPackage(com.intellij.psi.PsiPackage) JavaCoverageEnabledConfiguration(com.intellij.execution.configurations.coverage.JavaCoverageEnabledConfiguration) Project(com.intellij.openapi.project.Project) ClassFilter(com.intellij.ui.classFilter.ClassFilter) RefactoringListeners(com.intellij.execution.junit.RefactoringListeners)

Example 50 with PsiPackage

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

the class CoverageIntegrationTest method testSimple.

public void testSimple() {
    CoverageSuitesBundle bundle = loadCoverageSuite(IDEACoverageRunner.class, "simple$foo_in_simple.coverage");
    PsiPackage psiPackage = JavaPsiFacade.getInstance(myProject).findPackage("foo");
    PackageAnnotator annotator = new PackageAnnotator(psiPackage);
    PackageAnnotationConsumer consumer = new PackageAnnotationConsumer();
    annotator.annotate(bundle, consumer);
    PackageAnnotator.ClassCoverageInfo barClassCoverage = consumer.myClassCoverageInfo.get("foo.bar.BarClass");
    assertEquals(3, barClassCoverage.totalMethodCount);
    assertEquals(1, barClassCoverage.coveredMethodCount);
    PackageAnnotator.PackageCoverageInfo barPackageCoverage = consumer.myPackageCoverage.get("foo.bar");
    assertEquals(2, barPackageCoverage.coveredLineCount);
    assertEquals(9, barPackageCoverage.totalLineCount);
    assertEquals(1, barPackageCoverage.coveredMethodCount);
    assertEquals(7, barPackageCoverage.totalMethodCount);
    PackageAnnotator.ClassCoverageInfo uncoveredClassInfo = consumer.myClassCoverageInfo.get("foo.bar.UncoveredClass");
    assertEquals(4, uncoveredClassInfo.totalMethodCount);
    assertEquals(0, uncoveredClassInfo.coveredMethodCount);
}
Also used : PsiPackage(com.intellij.psi.PsiPackage)

Aggregations

PsiPackage (com.intellij.psi.PsiPackage)79 PsiDirectory (com.intellij.psi.PsiDirectory)17 Module (com.intellij.openapi.module.Module)16 PsiClass (com.intellij.psi.PsiClass)16 JavaAnalysisScope (com.intellij.analysis.JavaAnalysisScope)12 Project (com.intellij.openapi.project.Project)12 VirtualFile (com.intellij.openapi.vfs.VirtualFile)10 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)10 NotNull (org.jetbrains.annotations.NotNull)10 CyclicDependenciesBuilder (com.intellij.cyclicDependencies.CyclicDependenciesBuilder)9 PsiFile (com.intellij.psi.PsiFile)9 AnalysisScope (com.intellij.analysis.AnalysisScope)8 PsiElement (com.intellij.psi.PsiElement)8 JavaPsiFacade (com.intellij.psi.JavaPsiFacade)6 HashSet (java.util.HashSet)6 Nullable (org.jetbrains.annotations.Nullable)6 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)4 PackageElement (com.intellij.ide.projectView.impl.nodes.PackageElement)3 List (java.util.List)3 LookupElement (com.intellij.codeInsight.lookup.LookupElement)2