Search in sources :

Example 56 with PsiPackage

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

the class AbstractAllInPackageConfigurationProducer method setupConfigurationFromContext.

@Override
protected boolean setupConfigurationFromContext(JUnitConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
    PsiPackage psiPackage = JavaRuntimeConfigurationProducerBase.checkPackage(context.getPsiLocation());
    if (psiPackage == null)
        return false;
    sourceElement.set(psiPackage);
    if (!LocationUtil.isJarAttached(context.getLocation(), psiPackage, JUnitUtil.TESTCASE_CLASS, JUnitUtil.TEST5_ANNOTATION))
        return false;
    final JUnitConfiguration.Data data = configuration.getPersistentData();
    data.PACKAGE_NAME = psiPackage.getQualifiedName();
    data.TEST_OBJECT = JUnitConfiguration.TEST_PACKAGE;
    data.setScope(setupPackageConfiguration(context, configuration, data.getScope()));
    configuration.setGeneratedName();
    return true;
}
Also used : PsiPackage(com.intellij.psi.PsiPackage)

Example 57 with PsiPackage

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

the class JavaClassReferenceCompletionContributor method fillCompletionVariants.

@Override
public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) {
    PsiElement position = parameters.getPosition();
    JavaClassReference reference = findJavaClassReference(position.getContainingFile(), parameters.getOffset());
    if (reference == null) {
        return;
    }
    String[] extendClassNames = reference.getExtendClassNames();
    PsiElement context = reference.getCompletionContext();
    if (extendClassNames != null && context instanceof PsiPackage) {
        if (parameters.getCompletionType() == CompletionType.SMART) {
            JavaClassReferenceSet set = reference.getJavaClassReferenceSet();
            int setStart = set.getRangeInElement().getStartOffset() + set.getElement().getTextRange().getStartOffset();
            String fullPrefix = parameters.getPosition().getContainingFile().getText().substring(setStart, parameters.getOffset());
            reference.processSubclassVariants((PsiPackage) context, extendClassNames, result.withPrefixMatcher(fullPrefix));
            return;
        }
        result.addLookupAdvertisement("Press " + getActionShortcut(IdeActions.ACTION_SMART_TYPE_COMPLETION) + " to see inheritors of " + StringUtil.join(extendClassNames, ", "));
    }
    if (parameters.getCompletionType() == CompletionType.SMART) {
        return;
    }
    if (parameters.isExtendedCompletion() || parameters.getCompletionType() == CompletionType.CLASS_NAME) {
        JavaClassNameCompletionContributor.addAllClasses(parameters, result);
    } else {
        LegacyCompletionContributor.completeReference(parameters, result);
    }
    result.stopHere();
}
Also used : JavaClassReferenceSet(com.intellij.psi.impl.source.resolve.reference.impl.providers.JavaClassReferenceSet) JavaClassReference(com.intellij.psi.impl.source.resolve.reference.impl.providers.JavaClassReference) PsiPackage(com.intellij.psi.PsiPackage) PsiElement(com.intellij.psi.PsiElement)

Example 58 with PsiPackage

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

the class TodoPackageNode method getTodoItemCount.

public int getTodoItemCount(PackageElement packageElement) {
    int count = 0;
    if (getSettings().isFlattenPackages()) {
        final PsiPackage aPackage = packageElement.getPackage();
        final Module module = packageElement.getModule();
        GlobalSearchScope scope = module != null ? GlobalSearchScope.moduleScope(module) : GlobalSearchScope.projectScope(aPackage.getProject());
        final PsiDirectory[] directories = aPackage.getDirectories(scope);
        for (PsiDirectory directory : directories) {
            Iterator<PsiFile> iterator = myBuilder.getFilesUnderDirectory(directory);
            while (iterator.hasNext()) {
                PsiFile psiFile = iterator.next();
                count += getStructure().getTodoItemCount(psiFile);
            }
        }
    } else {
        Iterator<PsiFile> iterator = getFiles(packageElement);
        while (iterator.hasNext()) {
            PsiFile psiFile = iterator.next();
            count += getStructure().getTodoItemCount(psiFile);
        }
    }
    return count;
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiDirectory(com.intellij.psi.PsiDirectory) PsiPackage(com.intellij.psi.PsiPackage) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module)

Example 59 with PsiPackage

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

the class TodoPackageNode method update.

@Override
protected void update(PresentationData data) {
    super.update(data);
    final PackageElement packageElement = getValue();
    try {
        if (packageElement == null || !packageElement.getPackage().isValid()) {
            setValue(null);
            return;
        }
        int fileCount = getFileCount(packageElement);
        if (fileCount == 0) {
            setValue(null);
            return;
        }
        PsiPackage aPackage = packageElement.getPackage();
        String newName;
        if (getStructure().areFlattenPackages()) {
            newName = aPackage.getQualifiedName();
        } else {
            newName = myPresentationName != null ? myPresentationName : "";
        }
        int nameEndOffset = newName.length();
        int todoItemCount = getTodoItemCount(packageElement);
        newName = IdeBundle.message("node.todo.group", newName, todoItemCount, fileCount);
        myHighlightedRegions.clear();
        TextAttributes textAttributes = new TextAttributes();
        Color newColor = null;
        if (CopyPasteManager.getInstance().isCutElement(packageElement)) {
            newColor = CopyPasteManager.CUT_COLOR;
        }
        textAttributes.setForegroundColor(newColor);
        myHighlightedRegions.add(new HighlightedRegion(0, nameEndOffset, textAttributes));
        EditorColorsScheme colorsScheme = UsageTreeColorsScheme.getInstance().getScheme();
        myHighlightedRegions.add(new HighlightedRegion(nameEndOffset, newName.length(), colorsScheme.getAttributes(UsageTreeColors.NUMBER_OF_USAGES)));
        data.setPresentableText(newName);
    } catch (IndexNotReadyException e) {
        LOG.info(e);
        data.setPresentableText("N/A");
    }
}
Also used : IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) HighlightedRegion(com.intellij.ui.HighlightedRegion) PsiPackage(com.intellij.psi.PsiPackage) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) PackageElement(com.intellij.ide.projectView.impl.nodes.PackageElement)

Example 60 with PsiPackage

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

the class TodoPackageNode method getChildren.

@Override
@NotNull
public Collection<AbstractTreeNode> getChildren() {
    ArrayList<AbstractTreeNode> children = new ArrayList<>();
    final Project project = getProject();
    final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
    final PsiPackage psiPackage = getValue().getPackage();
    final Module module = getValue().getModule();
    if (!getStructure().getIsFlattenPackages() || psiPackage == null) {
        final Iterator<PsiFile> iterator = getFiles(getValue());
        while (iterator.hasNext()) {
            final PsiFile psiFile = iterator.next();
            final Module psiFileModule = projectFileIndex.getModuleForFile(psiFile.getVirtualFile());
            //group by module
            if (module != null && psiFileModule != null && !module.equals(psiFileModule)) {
                continue;
            }
            // Add files
            final PsiDirectory containingDirectory = psiFile.getContainingDirectory();
            TodoFileNode todoFileNode = new TodoFileNode(project, psiFile, myBuilder, false);
            if (ArrayUtil.find(psiPackage.getDirectories(), containingDirectory) > -1 && !children.contains(todoFileNode)) {
                children.add(todoFileNode);
                continue;
            }
            // Add packages
            PsiDirectory _dir = psiFile.getContainingDirectory();
            while (_dir != null) {
                final PsiDirectory parentDirectory = _dir.getParentDirectory();
                if (parentDirectory != null) {
                    PsiPackage _package = JavaDirectoryService.getInstance().getPackage(_dir);
                    if (_package != null && _package.getParentPackage() != null && psiPackage.equals(_package.getParentPackage())) {
                        final GlobalSearchScope scope = module != null ? GlobalSearchScope.moduleScope(module) : GlobalSearchScope.projectScope(project);
                        //compact empty middle packages
                        _package = TodoJavaTreeHelper.findNonEmptyPackage(_package, module, project, myBuilder, scope);
                        final String name = _package.getParentPackage().equals(psiPackage) ? //non compacted
                        null : _package.getQualifiedName().substring(psiPackage.getQualifiedName().length() + 1);
                        TodoPackageNode todoPackageNode = new TodoPackageNode(project, new PackageElement(module, _package, false), myBuilder, name);
                        if (!children.contains(todoPackageNode)) {
                            children.add(todoPackageNode);
                            break;
                        }
                    }
                }
                _dir = parentDirectory;
            }
        }
    } else {
        // flatten packages
        final Iterator<PsiFile> iterator = getFiles(getValue());
        while (iterator.hasNext()) {
            final PsiFile psiFile = iterator.next();
            //group by module
            final Module psiFileModule = projectFileIndex.getModuleForFile(psiFile.getVirtualFile());
            if (module != null && psiFileModule != null && !module.equals(psiFileModule)) {
                continue;
            }
            final PsiDirectory _dir = psiFile.getContainingDirectory();
            // Add files
            TodoFileNode todoFileNode = new TodoFileNode(getProject(), psiFile, myBuilder, false);
            if (ArrayUtil.find(psiPackage.getDirectories(), _dir) > -1 && !children.contains(todoFileNode)) {
                children.add(todoFileNode);
                continue;
            }
        }
    }
    Collections.sort(children, TodoFileDirAndModuleComparator.INSTANCE);
    return children;
}
Also used : AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) PsiPackage(com.intellij.psi.PsiPackage) Project(com.intellij.openapi.project.Project) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiDirectory(com.intellij.psi.PsiDirectory) PsiFile(com.intellij.psi.PsiFile) PackageElement(com.intellij.ide.projectView.impl.nodes.PackageElement) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

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