Search in sources :

Example 1 with SortedList

use of com.intellij.util.containers.SortedList in project intellij-community by JetBrains.

the class DescriptionTypeRelatedItemLineMarkerProvider method addBeforeAfterTemplateFilesGutterIcon.

private static void addBeforeAfterTemplateFilesGutterIcon(PsiElement highlightingElement, PsiDirectory descriptionDirectory, Collection<? super RelatedItemLineMarkerInfo> result) {
    final List<PsiFile> templateFiles = new SortedList<>((o1, o2) -> o1.getName().compareTo(o2.getName()));
    for (PsiFile file : descriptionDirectory.getFiles()) {
        final String fileName = file.getName();
        if (fileName.endsWith(".template")) {
            if (fileName.startsWith("after.") || fileName.startsWith("before.")) {
                templateFiles.add(file);
            }
        }
    }
    if (templateFiles.isEmpty())
        return;
    final RelatedItemLineMarkerInfo<PsiElement> info = NavigationGutterIconBuilder.create(AllIcons.Actions.Diff, CONVERTER, RELATED_ITEM_PROVIDER).setTargets(templateFiles).setPopupTitle("Select Template").setTooltipText("Before/After Templates").setAlignment(GutterIconRenderer.Alignment.RIGHT).createLineMarkerInfo(highlightingElement);
    result.add(info);
}
Also used : SortedList(com.intellij.util.containers.SortedList) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement)

Example 2 with SortedList

use of com.intellij.util.containers.SortedList in project android by JetBrains.

the class DependencyNodes method createNodesFor.

@NotNull
static List<AbstractPsModelNode<?>> createNodesFor(@NotNull AndroidArtifactNode parent, @NotNull Collection<PsDependency> dependencies) {
    List<AbstractPsModelNode<?>> children = Lists.newArrayList();
    List<PsDependency> declared = new SortedList<>(PsDependencyComparator.INSTANCE);
    Multimap<PsDependency, PsDependency> allTransitive = HashMultimap.create();
    List<PsDependency> mayBeTransitive = Lists.newArrayList();
    for (PsDependency dependency : dependencies) {
        Collection<DependencyModel> parsedModels = dependency.getParsedModels();
        if (parsedModels.isEmpty()) {
            mayBeTransitive.add(dependency);
        } else {
            for (DependencyModel parsedModel : parsedModels) {
                // "main" artifact.
                for (PsAndroidArtifact artifact : parent.getModels()) {
                    if (artifact.contains(parsedModel)) {
                        declared.add(dependency);
                        break;
                    }
                }
            }
            addTransitive(dependency, allTransitive);
        }
    }
    Collection<PsDependency> uniqueTransitives = allTransitive.values();
    declared.addAll(mayBeTransitive.stream().filter(dependency -> !uniqueTransitives.contains(dependency)).collect(Collectors.toList()));
    for (PsDependency dependency : declared) {
        AbstractDependencyNode<?> child = AbstractDependencyNode.createNode(parent, dependency);
        if (child != null) {
            children.add(child);
        }
    }
    return children;
}
Also used : DependencyModel(com.android.tools.idea.gradle.dsl.model.dependencies.DependencyModel) PsAndroidArtifact(com.android.tools.idea.gradle.structure.model.android.PsAndroidArtifact) SortedList(com.intellij.util.containers.SortedList) AbstractPsModelNode(com.android.tools.idea.gradle.structure.configurables.ui.treeview.AbstractPsModelNode) PsDependency(com.android.tools.idea.gradle.structure.model.PsDependency) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

SortedList (com.intellij.util.containers.SortedList)2 DependencyModel (com.android.tools.idea.gradle.dsl.model.dependencies.DependencyModel)1 AbstractPsModelNode (com.android.tools.idea.gradle.structure.configurables.ui.treeview.AbstractPsModelNode)1 PsDependency (com.android.tools.idea.gradle.structure.model.PsDependency)1 PsAndroidArtifact (com.android.tools.idea.gradle.structure.model.android.PsAndroidArtifact)1 PsiElement (com.intellij.psi.PsiElement)1 PsiFile (com.intellij.psi.PsiFile)1 NotNull (org.jetbrains.annotations.NotNull)1