Search in sources :

Example 26 with HashSet

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

the class SchemaDefinitionsSearch method gatherInheritors.

private Collection<SchemaTypeInfo> gatherInheritors(XmlTagImpl xml) {
    XmlAttribute name = getNameAttr(xml);
    if (name == null || StringUtil.isEmptyOrSpaces(name.getValue()))
        return null;
    String localName = name.getValue();
    final boolean hasPrefix = localName.contains(":");
    localName = hasPrefix ? localName.substring(localName.indexOf(':') + 1) : localName;
    final String nsPrefix = hasPrefix ? name.getValue().substring(0, name.getValue().indexOf(':')) : null;
    final XmlFile file = XmlUtil.getContainingFile(xml);
    if (file == null)
        return null;
    final Project project = file.getProject();
    if (project == null)
        return null;
    final Set<SchemaTypeInfo> result = new HashSet<>();
    final ArrayDeque<SchemaTypeInfo> queue = new ArrayDeque<>();
    String nsUri;
    if (!hasPrefix) {
        nsUri = getDefaultNs(file);
    } else {
        nsUri = XmlUtil.findNamespaceByPrefix(nsPrefix, file.getRootTag());
    }
    if (nsUri == null)
        return null;
    queue.add(new SchemaTypeInfo(localName, true, nsUri));
    final BiFunction<String, String, List<Set<SchemaTypeInfo>>> worker = SchemaTypeInheritanceIndex.getWorker(project, file.getContainingFile().getVirtualFile());
    while (!queue.isEmpty()) {
        final SchemaTypeInfo info = queue.removeFirst();
        final List<Set<SchemaTypeInfo>> childrenOfType = worker.apply(info.getNamespaceUri(), info.getTagName());
        for (Set<SchemaTypeInfo> infos : childrenOfType) {
            for (SchemaTypeInfo typeInfo : infos) {
                if (typeInfo.isIsTypeName()) {
                    queue.add(typeInfo);
                }
                result.add(typeInfo);
            }
        }
    }
    return result;
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) HashSet(com.intellij.util.containers.hash.HashSet) XmlFile(com.intellij.psi.xml.XmlFile) Project(com.intellij.openapi.project.Project) SchemaTypeInfo(com.intellij.xml.index.SchemaTypeInfo) HashSet(com.intellij.util.containers.hash.HashSet)

Example 27 with HashSet

use of com.intellij.util.containers.hash.HashSet in project intellij-plugins by JetBrains.

the class FlexCompositeSdkProjectViewStructureProvider method modify.

@NotNull
@Override
public Collection<AbstractTreeNode> modify(@NotNull final AbstractTreeNode parent, @NotNull final Collection<AbstractTreeNode> children, final ViewSettings settings) {
    if (!(parent instanceof ExternalLibrariesNode)) {
        return children;
    }
    Set<Sdk> processedSdks = new HashSet<>();
    Collection<AbstractTreeNode> result = new ArrayList<>();
    for (AbstractTreeNode child : children) {
        Object value = child.getValue();
        if (!(value instanceof NamedLibraryElement)) {
            result.add(child);
            continue;
        }
        NamedLibraryElement libraryElement = (NamedLibraryElement) value;
        OrderEntry orderEntry = libraryElement.getOrderEntry();
        if (!(orderEntry instanceof JdkOrderEntry)) {
            result.add(child);
            continue;
        }
        Sdk sdk = ((JdkOrderEntry) orderEntry).getJdk();
        if (!(sdk instanceof FlexCompositeSdk)) {
            result.add(child);
            continue;
        }
        Sdk[] sdks = ((FlexCompositeSdk) sdk).getSdks();
        for (Sdk individualSdk : sdks) {
            if (processedSdks.add(individualSdk)) {
                IndividualSdkOrderEntry entry = new IndividualSdkOrderEntry(individualSdk, orderEntry.getOwnerModule());
                result.add(new NamedLibraryElementNode(parent.getProject(), new NamedLibraryElement(null, entry), ((ExternalLibrariesNode) parent).getSettings()));
            }
        }
    }
    return result;
}
Also used : FlexCompositeSdk(com.intellij.lang.javascript.flex.projectStructure.FlexCompositeSdk) ExternalLibrariesNode(com.intellij.ide.projectView.impl.nodes.ExternalLibrariesNode) ArrayList(java.util.ArrayList) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) NamedLibraryElement(com.intellij.ide.projectView.impl.nodes.NamedLibraryElement) FlexCompositeSdk(com.intellij.lang.javascript.flex.projectStructure.FlexCompositeSdk) Sdk(com.intellij.openapi.projectRoots.Sdk) HashSet(com.intellij.util.containers.hash.HashSet) NamedLibraryElementNode(com.intellij.ide.projectView.impl.nodes.NamedLibraryElementNode) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

HashSet (com.intellij.util.containers.hash.HashSet)27 Project (com.intellij.openapi.project.Project)10 VirtualFile (com.intellij.openapi.vfs.VirtualFile)9 NotNull (org.jetbrains.annotations.NotNull)6 Nullable (org.jetbrains.annotations.Nullable)5 PsiElement (com.intellij.psi.PsiElement)4 XmlFile (com.intellij.psi.xml.XmlFile)4 Set (java.util.Set)4 Ref (com.intellij.openapi.util.Ref)3 ContainerUtil (com.intellij.util.containers.ContainerUtil)3 UsageDescriptor (com.intellij.internal.statistic.beans.UsageDescriptor)2 ExcludeEntryDescription (com.intellij.openapi.compiler.options.ExcludeEntryDescription)2 Module (com.intellij.openapi.module.Module)2 StringUtil (com.intellij.openapi.util.text.StringUtil)2 PsiClass (com.intellij.psi.PsiClass)2 PsiFile (com.intellij.psi.PsiFile)2 XmlTag (com.intellij.psi.xml.XmlTag)2 Function (com.intellij.util.Function)2 Processor (com.intellij.util.Processor)2 SmartList (com.intellij.util.SmartList)2