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());
}
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)));
}
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;
}
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;
}
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;
}
Aggregations