Search in sources :

Example 1 with HashSet

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

the class XmlSchemaTypeInheritanceTest method testIndex.

public void testIndex() throws Exception {
    myFixture.copyDirectoryToProject("", "");
    final Project project = getProject();
    final List<Set<SchemaTypeInfo>> childrenOfType = SchemaTypeInheritanceIndex.getWorker(project, null).apply("http://a.b.c", "baseSimpleType");
    Assert.assertNotNull(childrenOfType);
    final Set<SchemaTypeInfo> expected = new HashSet<>();
    expected.add(new SchemaTypeInfo("extSimple4", true, "http://a.b.c"));
    expected.add(new SchemaTypeInfo("extSimple1", true, "http://a.b.c"));
    expected.add(new SchemaTypeInfo("extComplex2", true, "http://a.b.c"));
    expected.add(new SchemaTypeInfo("extComplex2", true, "http://a.b.c.d"));
    for (Set<SchemaTypeInfo> infos : childrenOfType) {
        for (SchemaTypeInfo info : infos) {
            expected.remove(info);
        }
    }
    Assert.assertTrue(expected.isEmpty());
    //
    final List<Set<SchemaTypeInfo>> childrenOfSimple4Type = SchemaTypeInheritanceIndex.getWorker(project, null).apply("http://a.b.c", "extSimple4");
    Assert.assertNotNull(childrenOfSimple4Type);
    final Set<SchemaTypeInfo> expectedSimple4 = new HashSet<>();
    expectedSimple4.add(new SchemaTypeInfo("extSimple5", true, "http://a.b.c"));
    expectedSimple4.add(new SchemaTypeInfo("wiseElement", false, "http://a.b.c"));
    for (Set<SchemaTypeInfo> infos : childrenOfSimple4Type) {
        for (SchemaTypeInfo info : infos) {
            expectedSimple4.remove(info);
        }
    }
    Assert.assertTrue(expectedSimple4.isEmpty());
}
Also used : Project(com.intellij.openapi.project.Project) HashSet(com.intellij.util.containers.hash.HashSet) Set(java.util.Set) HashSet(com.intellij.util.containers.hash.HashSet)

Example 2 with HashSet

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

the class XmlSchemaTypeInheritanceTest method testBuilder.

public void testBuilder() throws Exception {
    VirtualFile file = myFixture.copyFileToProject("Semantic.xsd");
    assert file != null;
    final FileInputStream is = new FileInputStream(new File(file.getPath()));
    final MultiMap<SchemaTypeInfo, SchemaTypeInfo> map = XsdComplexTypeInfoBuilder.parse(is);
    final Collection<SchemaTypeInfo> node = map.get(new SchemaTypeInfo("tConversationNode", true, ourNs));
    Assert.assertNotNull(node);
    Assert.assertEquals(3, node.size());
    final Set<SchemaTypeInfo> expected = new HashSet<>();
    expected.add(new SchemaTypeInfo("tConversation", true, ourNs));
    expected.add(new SchemaTypeInfo("tCallConversation", true, ourNs));
    expected.add(new SchemaTypeInfo("tSubConversation", true, ourNs));
    for (SchemaTypeInfo info : node) {
        expected.remove(info);
    }
    Assert.assertTrue(expected.isEmpty());
    //
    final Collection<SchemaTypeInfo> stringNode = map.get(new SchemaTypeInfo("string", true, "http://www.w3.org/2001/XMLSchema"));
    Assert.assertNotNull(stringNode);
    Assert.assertEquals(9, stringNode.size());
    Assert.assertTrue(stringNode.contains(new SchemaTypeInfo("tAdHocOrdering", true, ourNs)));
    Assert.assertTrue(stringNode.contains(new SchemaTypeInfo("tEventBasedGatewayType", true, ourNs)));
    //
    final Collection<SchemaTypeInfo> baseNode = map.get(new SchemaTypeInfo("tBaseElement", true, ourNs));
    Assert.assertNotNull(baseNode);
    Assert.assertEquals(39, baseNode.size());
    Assert.assertTrue(baseNode.contains(new SchemaTypeInfo("tAuditing", true, ourNs)));
    Assert.assertTrue(baseNode.contains(new SchemaTypeInfo("tDataInput", true, ourNs)));
    Assert.assertTrue(baseNode.contains(new SchemaTypeInfo("tDataOutput", true, ourNs)));
    Assert.assertTrue(baseNode.contains(new SchemaTypeInfo("tFlowElement", true, ourNs)));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) FileInputStream(java.io.FileInputStream) HashSet(com.intellij.util.containers.hash.HashSet)

Example 3 with HashSet

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

the class GenerationUtil method getVarTypes.

static Set<String> getVarTypes(GrVariableDeclaration variableDeclaration) {
    GrVariable[] variables = variableDeclaration.getVariables();
    final GrTypeElement typeElement = variableDeclaration.getTypeElementGroovy();
    Set<String> types = new HashSet<>(variables.length);
    if (typeElement == null) {
        if (variables.length > 1) {
            for (GrVariable variable : variables) {
                final GrExpression initializer = variable.getInitializerGroovy();
                if (initializer != null) {
                    final PsiType varType = initializer.getType();
                    if (varType != null) {
                        types.add(getTypeText(varType, variableDeclaration));
                    }
                }
            }
        }
    }
    return types;
}
Also used : GrVariable(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable) GrTypeElement(org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement) HashSet(com.intellij.util.containers.hash.HashSet)

Example 4 with HashSet

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

the class MavenArtifactCoordinatesGroupIdConverter method getSmartVariants.

@Override
public Collection<String> getSmartVariants(ConvertContext convertContext) {
    Set<String> groupIds = new HashSet<>();
    String artifactId = MavenArtifactCoordinatesHelper.getId(convertContext).getArtifactId();
    if (!StringUtil.isEmptyOrSpaces(artifactId)) {
        MavenProjectIndicesManager manager = MavenProjectIndicesManager.getInstance(convertContext.getFile().getProject());
        for (String groupId : manager.getGroupIds()) {
            if (manager.getArtifactIds(groupId).contains(artifactId)) {
                groupIds.add(groupId);
            }
        }
    }
    return groupIds;
}
Also used : MavenProjectIndicesManager(org.jetbrains.idea.maven.indices.MavenProjectIndicesManager) HashSet(com.intellij.util.containers.hash.HashSet)

Example 5 with HashSet

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

the class SchemaDefinitionsSearch method execute.

@Override
public boolean execute(@NotNull final PsiElement queryParameters, @NotNull final Processor<PsiElement> consumer) {
    if (queryParameters instanceof XmlTagImpl) {
        final XmlTagImpl xml = (XmlTagImpl) queryParameters;
        if (ReadAction.compute(() -> isTypeElement(xml))) {
            final Collection<SchemaTypeInfo> infos = ApplicationManager.getApplication().runReadAction(new Computable<Collection<SchemaTypeInfo>>() {

                @Override
                public Collection<SchemaTypeInfo> compute() {
                    return gatherInheritors(xml);
                }
            });
            if (infos != null && !infos.isEmpty()) {
                final XmlFile file = XmlUtil.getContainingFile(xml);
                final Project project = file.getProject();
                final Module module = ModuleUtilCore.findModuleForPsiElement(queryParameters);
                //if (module == null) return false;
                final VirtualFile vf = file.getVirtualFile();
                String thisNs = ApplicationManager.getApplication().runReadAction(new Computable<String>() {

                    @Override
                    public String compute() {
                        return XmlNamespaceIndex.getNamespace(vf, project, file);
                    }
                });
                thisNs = thisNs == null ? getDefaultNs(file) : thisNs;
                // so thisNs can be null
                if (thisNs == null)
                    return false;
                final ArrayList<SchemaTypeInfo> infosLst = new ArrayList<>(infos);
                Collections.sort(infosLst);
                final Map<String, Set<XmlFile>> nsMap = new HashMap<>();
                for (final SchemaTypeInfo info : infosLst) {
                    Set<XmlFile> targetFiles = nsMap.get(info.getNamespaceUri());
                    if (targetFiles == null) {
                        targetFiles = new HashSet<>();
                        if (Comparing.equal(info.getNamespaceUri(), thisNs)) {
                            targetFiles.add(file);
                        }
                        final Collection<XmlFile> files = ApplicationManager.getApplication().runReadAction(new Computable<Collection<XmlFile>>() {

                            @Override
                            public Collection<XmlFile> compute() {
                                return XmlUtil.findNSFilesByURI(info.getNamespaceUri(), project, module);
                            }
                        });
                        if (files != null) {
                            targetFiles.addAll(files);
                        }
                        nsMap.put(info.getNamespaceUri(), targetFiles);
                    }
                    if (!targetFiles.isEmpty()) {
                        for (final XmlFile targetFile : targetFiles) {
                            ApplicationManager.getApplication().runReadAction(() -> {
                                final String prefixByURI = XmlUtil.findNamespacePrefixByURI(targetFile, info.getNamespaceUri());
                                if (prefixByURI == null)
                                    return;
                                final PsiElementProcessor processor = new PsiElementProcessor() {

                                    @Override
                                    public boolean execute(@NotNull PsiElement element) {
                                        if (element instanceof XmlTagImpl) {
                                            if (isCertainTypeElement((XmlTagImpl) element, info.getTagName(), prefixByURI) || isElementWithEmbeddedType((XmlTagImpl) element, info.getTagName(), prefixByURI)) {
                                                consumer.process(element);
                                                return false;
                                            }
                                        }
                                        return true;
                                    }
                                };
                                XmlUtil.processXmlElements(targetFile, processor, true);
                            });
                        }
                    }
                }
            }
        }
    }
    return true;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) XmlTagImpl(com.intellij.psi.impl.source.xml.XmlTagImpl) HashSet(com.intellij.util.containers.hash.HashSet) XmlFile(com.intellij.psi.xml.XmlFile) HashMap(com.intellij.util.containers.hash.HashMap) NotNull(org.jetbrains.annotations.NotNull) PsiElementProcessor(com.intellij.psi.search.PsiElementProcessor) Project(com.intellij.openapi.project.Project) SchemaTypeInfo(com.intellij.xml.index.SchemaTypeInfo) Module(com.intellij.openapi.module.Module) PsiElement(com.intellij.psi.PsiElement)

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