Search in sources :

Example 1 with HashMap

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;
}
Also used : PyResolveContext(com.jetbrains.python.psi.resolve.PyResolveContext) HashMap(com.intellij.util.containers.HashMap) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with HashMap

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 &lt;ref1>bar() + &lt;ref2>baz", etc, and the result is
   * a map where strings "&lt;ref1>" and "&lt;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;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) HashMap(com.intellij.util.containers.HashMap) HashMap(com.intellij.util.containers.HashMap) Map(java.util.Map) PsiElement(com.intellij.psi.PsiElement)

Example 3 with HashMap

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;
}
Also used : PropertyData(org.jetbrains.idea.svn.properties.PropertyData) HashMap(com.intellij.util.containers.HashMap) PropertyValue(org.jetbrains.idea.svn.properties.PropertyValue) EmptyContent(com.intellij.diff.contents.EmptyContent) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with HashMap

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()]);
}
Also used : HashMap(com.intellij.util.containers.HashMap) QName(javax.xml.namespace.QName)

Example 5 with HashMap

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HashMap(com.intellij.util.containers.HashMap) ArrayList(java.util.ArrayList) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Aggregations

HashMap (com.intellij.util.containers.HashMap)118 NotNull (org.jetbrains.annotations.NotNull)23 VirtualFile (com.intellij.openapi.vfs.VirtualFile)22 File (java.io.File)22 Nullable (org.jetbrains.annotations.Nullable)18 Map (java.util.Map)17 Module (com.intellij.openapi.module.Module)15 Project (com.intellij.openapi.project.Project)15 ArrayList (java.util.ArrayList)14 PsiElement (com.intellij.psi.PsiElement)11 HashSet (com.intellij.util.containers.HashSet)10 List (java.util.List)9 IncorrectOperationException (com.intellij.util.IncorrectOperationException)8 IOException (java.io.IOException)8 Pair (com.intellij.openapi.util.Pair)6 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)6 SearchScope (com.intellij.psi.search.SearchScope)6 Logger (com.intellij.openapi.diagnostic.Logger)5 PsiFile (com.intellij.psi.PsiFile)5 UsageInfo (com.intellij.usageView.UsageInfo)5