use of com.intellij.util.containers.HashMap in project intellij-community by JetBrains.
the class PyTypingTypeProvider method getGenericSubstitutions.
@NotNull
@Override
public Map<PyType, PyType> getGenericSubstitutions(@NotNull PyClass cls, @NotNull TypeEvalContext context) {
final Context ctx = new Context(context);
if (!isGeneric(cls, ctx)) {
return Collections.emptyMap();
}
final Map<PyType, PyType> results = new HashMap<>();
// XXX: Requires switching from stub to AST
for (PyExpression e : cls.getSuperClassExpressions()) {
final PySubscriptionExpression subscriptionExpr = as(e, PySubscriptionExpression.class);
final PyExpression superExpr = subscriptionExpr != null ? subscriptionExpr.getOperand() : e;
final PyType superType = context.getType(superExpr);
final PyClassType superClassType = as(superType, PyClassType.class);
final PyClass superClass = superClassType != null ? superClassType.getPyClass() : null;
final Map<PyType, PyType> superSubstitutions = superClass != null ? doPreventingRecursion(RECURSION_KEY, false, () -> getGenericSubstitutions(superClass, context)) : null;
if (superSubstitutions != null) {
results.putAll(superSubstitutions);
}
final List<PyType> superGenerics = superClass != null ? collectGenericTypes(superClass, ctx) : Collections.emptyList();
final List<PyExpression> indices = subscriptionExpr != null ? getSubscriptionIndices(subscriptionExpr) : Collections.emptyList();
for (int i = 0; i < superGenerics.size(); i++) {
final PyExpression expr = ContainerUtil.getOrElse(indices, i, null);
final PyType superGeneric = superGenerics.get(i);
final Ref<PyType> typeRef = expr != null ? getType(expr, ctx) : null;
final PyType actualType = typeRef != null ? typeRef.get() : null;
if (!superGeneric.equals(actualType)) {
results.put(superGeneric, actualType);
}
}
}
return results;
}
use of com.intellij.util.containers.HashMap in project intellij-community by JetBrains.
the class LightMarkedTestCase method configureByFileText.
/**
* Typically a text is marked with patterns: "foo <ref1>bar() + <ref2>baz", etc, and the result is
* a map where strings "<ref1>" and "<ref2>" are mapped to PSI elements for "bar" and "baz".
* @param fileText text to parse
* @param fileName name to give to the PSI file
* @param markerRegexp regexp to detect markers in the text
* @return mapping of markers to the PSI elements
* @throws Exception
*/
protected Map<String, PsiElement> configureByFileText(String fileText, final String fileName, @NonNls String markerRegexp) {
// build a map of marks to positions, and the text with marks stripped
Pattern pat = Pattern.compile(markerRegexp);
Matcher mat = pat.matcher(fileText);
// from here on fileText is not yet looked at
int rest_index = 0;
Map<String, Integer> offsets = new HashMap<>();
final StringBuffer text = new StringBuffer();
while (mat.find(rest_index)) {
String mark = mat.group();
CharSequence prev_part = fileText.subSequence(rest_index, mat.start());
text.append(prev_part);
offsets.put(mark, text.length());
rest_index = mat.end();
}
if (rest_index < fileText.length())
text.append(fileText.substring(rest_index));
// create a file and map marks to PSI elements
Map<String, PsiElement> result = new HashMap<>();
myFile = myFixture.addFileToProject(fileName, text.toString());
myFixture.configureFromExistingVirtualFile(myFile.getVirtualFile());
for (Map.Entry<String, Integer> entry : offsets.entrySet()) {
result.put(entry.getKey(), myFile.findElementAt(entry.getValue()));
}
return result;
}
use of com.intellij.util.containers.HashMap in project intellij-community by JetBrains.
the class SvnDiffViewer method getProperties.
@NotNull
private static Map<String, PropertyValue> getProperties(@NotNull DiffContent content) {
if (content instanceof EmptyContent)
return Collections.emptyMap();
List<PropertyData> properties = ((SvnPropertiesDiffRequest.PropertyContent) content).getProperties();
Map<String, PropertyValue> map = new HashMap<>();
for (PropertyData data : properties) {
if (map.containsKey(data.getName()))
LOG.warn("Duplicated property: " + data.getName());
map.put(data.getName(), data.getValue());
}
return map;
}
use of com.intellij.util.containers.HashMap in project intellij-community by JetBrains.
the class RngElementDescriptor method computeAttributeDescriptors.
protected XmlAttributeDescriptor[] computeAttributeDescriptors(final Map<DAttributePattern, Pair<? extends Map<String, String>, Boolean>> map) {
final Map<QName, RngXmlAttributeDescriptor> name2descriptor = new HashMap<>();
for (DAttributePattern pattern : map.keySet()) {
final Pair<? extends Map<String, String>, Boolean> value = map.get(pattern);
for (QName name : pattern.getName().listNames()) {
RngXmlAttributeDescriptor descriptor = name2descriptor.get(name);
final RngXmlAttributeDescriptor newDescriptor = new RngXmlAttributeDescriptor(this, pattern, value.first, value.second);
if (descriptor == null) {
descriptor = newDescriptor;
} else {
descriptor = descriptor.mergeWith(newDescriptor);
}
name2descriptor.put(name, descriptor);
}
}
final Collection<RngXmlAttributeDescriptor> result = name2descriptor.values();
return result.toArray(new RngXmlAttributeDescriptor[result.size()]);
}
use of com.intellij.util.containers.HashMap in project intellij-community by JetBrains.
the class HotSwapManager method scanForModifiedClasses.
public Map<String, HotSwapFile> scanForModifiedClasses(final DebuggerSession session, final HotSwapProgress progress) {
DebuggerManagerThreadImpl.assertIsManagerThread();
final long timeStamp = getTimeStamp(session);
final Map<String, HotSwapFile> modifiedClasses = new HashMap<>();
final List<File> outputRoots = new ArrayList<>();
ApplicationManager.getApplication().runReadAction(() -> {
final List<VirtualFile> allDirs = OrderEnumerator.orderEntries(myProject).withoutSdk().withoutLibraries().getPathsList().getRootDirs();
for (VirtualFile dir : allDirs) {
outputRoots.add(new File(dir.getPath()));
}
});
for (File root : outputRoots) {
final String rootPath = FileUtil.toCanonicalPath(root.getPath());
collectModifiedClasses(root, rootPath, rootPath + "/", modifiedClasses, progress, timeStamp);
}
return modifiedClasses;
}
Aggregations