Search in sources :

Example 91 with SmartList

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

the class AntResolveInspection method checkReferences.

private static void checkReferences(final XmlElement xmlElement, @NonNls final DomElementAnnotationHolder holder, DomElement domElement) {
    if (xmlElement == null) {
        return;
    }
    Set<PsiReference> processed = null;
    // to be initialized lazily
    Collection<PropertiesFile> propertyFiles = null;
    for (final PsiReference ref : xmlElement.getReferences()) {
        if (!(ref instanceof AntDomReference)) {
            continue;
        }
        final AntDomReference antDomRef = (AntDomReference) ref;
        if (antDomRef.shouldBeSkippedByAnnotator()) {
            continue;
        }
        if (processed != null && processed.contains(ref)) {
            continue;
        }
        if (!isResolvable(ref)) {
            final List<LocalQuickFix> quickFixList = new SmartList<>();
            quickFixList.add(new AntChangeContextLocalFix());
            if (ref instanceof AntDomPropertyReference) {
                final String canonicalText = ref.getCanonicalText();
                quickFixList.add(new AntCreatePropertyFix(canonicalText, null));
                final PsiFile containingFile = xmlElement.getContainingFile();
                if (containingFile != null) {
                    if (propertyFiles == null) {
                        propertyFiles = getPropertyFiles(AntSupport.getAntDomProject(containingFile), xmlElement);
                    }
                    for (PropertiesFile propertyFile : propertyFiles) {
                        quickFixList.add(new AntCreatePropertyFix(canonicalText, propertyFile));
                    }
                }
            } else if (ref instanceof AntDomTargetReference) {
                quickFixList.add(new AntCreateTargetFix(ref.getCanonicalText()));
            }
            holder.createProblem(domElement, ProblemHighlightType.LIKE_UNKNOWN_SYMBOL, antDomRef.getUnresolvedMessagePattern(), ref.getRangeInElement(), quickFixList.toArray((new LocalQuickFix[quickFixList.size()])));
            if (ref instanceof AntDomFileReference) {
                if (processed == null) {
                    processed = new HashSet<>();
                }
                ContainerUtil.addAll(processed, ((AntDomFileReference) ref).getFileReferenceSet().getAllReferences());
            }
        }
    }
}
Also used : AntCreateTargetFix(com.intellij.lang.ant.quickfix.AntCreateTargetFix) AntChangeContextLocalFix(com.intellij.lang.ant.quickfix.AntChangeContextLocalFix) AntCreatePropertyFix(com.intellij.lang.ant.quickfix.AntCreatePropertyFix) PsiReference(com.intellij.psi.PsiReference) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) PsiFile(com.intellij.psi.PsiFile) SmartList(com.intellij.util.SmartList)

Example 92 with SmartList

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

the class ExtensionPointImpl method collectMissingWithTags.

@Override
public List<PsiField> collectMissingWithTags() {
    PsiClass beanClass = getBeanClass().getValue();
    if (beanClass == null) {
        return Collections.emptyList();
    }
    final List<PsiField> result = new SmartList<>();
    for (PsiField field : beanClass.getAllFields()) {
        if (ExtensionDomExtender.isClassField(field.getName()) && ExtensionDomExtender.findWithElement(getWithElements(), field) == null) {
            result.add(field);
        }
    }
    return result;
}
Also used : PsiField(com.intellij.psi.PsiField) PsiClass(com.intellij.psi.PsiClass) SmartList(com.intellij.util.SmartList)

Example 93 with SmartList

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

the class NestingTreeStructureProvider method getFilesShownAsChildrenInProjectView.

// Algorithm is similar to calcParentToChildren(), but a bit simpler, because we have one specific parentFile.
public static Collection<ChildFileInfo> getFilesShownAsChildrenInProjectView(@NotNull final Project project, @NotNull final VirtualFile parentFile) {
    LOG.assertTrue(!parentFile.isDirectory());
    final VirtualFile dir = parentFile.getParent();
    if (dir == null)
        return Collections.emptyList();
    final Collection<NestingRule> rules = getNestingRulesStatic(project);
    if (rules.isEmpty())
        return Collections.emptyList();
    final VirtualFile[] children = dir.getChildren();
    if (children.length <= 1)
        return Collections.emptyList();
    final Collection<NestingRule> rulesWhereItCanBeParent = filterRules(rules, parentFile.getName(), true);
    if (rulesWhereItCanBeParent.isEmpty())
        return Collections.emptyList();
    final Collection<NestingRule> rulesWhereItCanBeChild = filterRules(rules, parentFile.getName(), false);
    final SmartList<ChildFileInfo> result = new SmartList<>();
    for (VirtualFile child : children) {
        if (child.isDirectory())
            continue;
        if (child.equals(parentFile))
            continue;
        // if given parentFile itself appears to be a child of some other file, it means that it is not shown as parent node in Project View
        for (NestingRule rule : rulesWhereItCanBeChild) {
            final String childName = child.getName();
            final Couple<Boolean> c = checkMatchingAsParentOrChild(rule, childName);
            final boolean matchesParent = c.first;
            if (matchesParent) {
                final String baseName = childName.substring(0, childName.length() - rule.myParentFileSuffix.length());
                if (parentFile.getName().equals(baseName + rule.myChildFileSuffix)) {
                    // parentFile itself appears to be a child of childFile
                    return Collections.emptyList();
                }
            }
        }
        for (NestingRule rule : rulesWhereItCanBeParent) {
            final String childName = child.getName();
            final Couple<Boolean> c = checkMatchingAsParentOrChild(rule, childName);
            final boolean matchesChild = c.second;
            if (matchesChild) {
                final String baseName = childName.substring(0, childName.length() - rule.myChildFileSuffix.length());
                if (parentFile.getName().equals(baseName + rule.myParentFileSuffix)) {
                    result.add(new ChildFileInfo(child, baseName));
                }
            }
        }
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SmartList(com.intellij.util.SmartList)

Example 94 with SmartList

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

the class ProjectTreeBuilder method updateNodesContaining.

private void updateNodesContaining(@NotNull Collection<VirtualFile> filesToRefresh, @NotNull DefaultMutableTreeNode rootNode) {
    if (!(rootNode.getUserObject() instanceof ProjectViewNode))
        return;
    ProjectViewNode node = (ProjectViewNode) rootNode.getUserObject();
    Collection<VirtualFile> containingFiles = null;
    for (VirtualFile virtualFile : filesToRefresh) {
        if (!virtualFile.isValid()) {
            // file must be deleted
            addSubtreeToUpdate(rootNode);
            return;
        }
        if (node.contains(virtualFile)) {
            if (containingFiles == null)
                containingFiles = new SmartList<>();
            containingFiles.add(virtualFile);
        }
    }
    if (containingFiles != null) {
        updateNode(rootNode);
        Enumeration children = rootNode.children();
        while (children.hasMoreElements()) {
            DefaultMutableTreeNode child = (DefaultMutableTreeNode) children.nextElement();
            updateNodesContaining(containingFiles, child);
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Enumeration(java.util.Enumeration) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ProjectViewNode(com.intellij.ide.projectView.ProjectViewNode) SmartList(com.intellij.util.SmartList)

Example 95 with SmartList

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

the class UsageFavoriteNodeProvider method getFavoriteNodes.

@Override
public Collection<AbstractTreeNode> getFavoriteNodes(DataContext context, ViewSettings viewSettings) {
    final Project project = CommonDataKeys.PROJECT.getData(context);
    if (project == null) {
        return null;
    }
    final Usage[] usages = UsageView.USAGES_KEY.getData(context);
    if (usages != null) {
        final List<AbstractTreeNode> result = new SmartList<>();
        final MultiMap<VirtualFile, Usage> map = new MultiMap<>();
        final List<Usage> nonMapped = new ArrayList<>();
        for (Usage usage : usages) {
            if (usage instanceof UsageInFile) {
                map.putValue(((UsageInFile) usage).getFile(), usage);
            } else if (usage instanceof UsageInFiles) {
                final VirtualFile[] files = ((UsageInFiles) usage).getFiles();
                for (VirtualFile file : files) {
                    map.putValue(file, usage);
                }
            } else {
                nonMapped.add(usage);
            }
        }
        final TreeSet<VirtualFile> keys = new TreeSet<>(VIRTUAL_FILE_COMPARATOR);
        keys.addAll(map.keySet());
        for (VirtualFile key : keys) {
            final FileGroupingProjectNode grouping = new FileGroupingProjectNode(project, new File(key.getPath()), viewSettings);
            result.add(grouping);
            final Collection<Usage> subUsages = map.get(key);
            for (Usage usage : subUsages) {
                if (usage instanceof UsageInfo2UsageAdapter) {
                    final UsageProjectTreeNode node = new UsageProjectTreeNode(project, ((UsageInfo2UsageAdapter) usage).getUsageInfo(), viewSettings);
                    grouping.addChild(node);
                } else if (NullUsage.INSTANCE.equals(usage)) {
                    continue;
                } else {
                    grouping.addChild(new NoteProjectNode(project, new NoteNode(usage.getPresentation().getPlainText(), true), viewSettings));
                }
            }
        }
        for (Usage usage : nonMapped) {
            if (usage instanceof UsageInfo2UsageAdapter) {
                final UsageProjectTreeNode node = new UsageProjectTreeNode(project, ((UsageInfo2UsageAdapter) usage).getUsageInfo(), viewSettings);
                result.add(node);
            } else if (NullUsage.INSTANCE.equals(usage)) {
                continue;
            } else {
                result.add(new NoteProjectNode(project, new NoteNode(usage.getPresentation().getPlainText(), true), viewSettings));
            }
        }
        return result;
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) NullUsage(com.intellij.usages.impl.NullUsage) Usage(com.intellij.usages.Usage) UsageInFiles(com.intellij.usages.rules.UsageInFiles) UsageInFile(com.intellij.usages.rules.UsageInFile) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) Project(com.intellij.openapi.project.Project) MultiMap(com.intellij.util.containers.MultiMap) UsageInfo2UsageAdapter(com.intellij.usages.UsageInfo2UsageAdapter) SmartList(com.intellij.util.SmartList) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) UsageInFile(com.intellij.usages.rules.UsageInFile) File(java.io.File)

Aggregations

SmartList (com.intellij.util.SmartList)163 NotNull (org.jetbrains.annotations.NotNull)70 Nullable (org.jetbrains.annotations.Nullable)25 VirtualFile (com.intellij.openapi.vfs.VirtualFile)24 Module (com.intellij.openapi.module.Module)15 Project (com.intellij.openapi.project.Project)14 TextRange (com.intellij.openapi.util.TextRange)12 PsiElement (com.intellij.psi.PsiElement)12 List (java.util.List)12 Element (org.jdom.Element)12 File (java.io.File)11 THashSet (gnu.trove.THashSet)9 ContainerUtil (com.intellij.util.containers.ContainerUtil)8 ArrayList (java.util.ArrayList)8 Collection (java.util.Collection)8 Pair (com.intellij.openapi.util.Pair)7 PsiFile (com.intellij.psi.PsiFile)6 IOException (java.io.IOException)6 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)5 IElementType (com.intellij.psi.tree.IElementType)5