Search in sources :

Example 81 with THashMap

use of gnu.trove.THashMap in project intellij-community by JetBrains.

the class FileManagerImpl method checkLanguageChange.

private void checkLanguageChange() {
    Map<VirtualFile, FileViewProvider> fileToPsiFileMap = new THashMap<>(myVFileToViewProviderMap);
    Map<VirtualFile, FileViewProvider> originalFileToPsiFileMap = new THashMap<>(myVFileToViewProviderMap);
    myVFileToViewProviderMap.clear();
    for (Iterator<VirtualFile> iterator = fileToPsiFileMap.keySet().iterator(); iterator.hasNext(); ) {
        VirtualFile vFile = iterator.next();
        Language language = LanguageUtil.getLanguageForPsi(myManager.getProject(), vFile);
        if (language != null && language != fileToPsiFileMap.get(vFile).getBaseLanguage()) {
            iterator.remove();
        }
    }
    myVFileToViewProviderMap.putAll(fileToPsiFileMap);
    markInvalidations(originalFileToPsiFileMap);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) THashMap(gnu.trove.THashMap) Language(com.intellij.lang.Language)

Example 82 with THashMap

use of gnu.trove.THashMap in project intellij-community by JetBrains.

the class IdDataConsumer method getResult.

public Map<IdIndexEntry, Integer> getResult() {
    final Map<IdIndexEntry, Integer> result = new THashMap<>(myResult.size());
    myResult.forEachEntry((key, value) -> {
        result.put(new IdIndexEntry(key), value);
        return true;
    });
    return result;
}
Also used : THashMap(gnu.trove.THashMap) IdIndexEntry(com.intellij.psi.impl.cache.impl.id.IdIndexEntry)

Example 83 with THashMap

use of gnu.trove.THashMap in project intellij-community by JetBrains.

the class BaseFilterLexerUtil method scanContent.

public static ScanContent scanContent(FileContent content, IdAndToDoScannerBasedOnFilterLexer indexer) {
    ScanContent data = content.getUserData(scanContentKey);
    if (data != null) {
        content.putUserData(scanContentKey, null);
        return data;
    }
    // same as TodoIndex.getFilter().isAcceptable
    final boolean needTodo = content.getFile().isInLocalFileSystem();
    final boolean needIdIndex = IdTableBuilding.getFileTypeIndexer(content.getFileType()) instanceof LexerBasedIdIndexer;
    final IdDataConsumer consumer = needIdIndex ? new IdDataConsumer() : null;
    final OccurrenceConsumer todoOccurrenceConsumer = new OccurrenceConsumer(consumer, needTodo);
    final Lexer filterLexer = indexer.createLexer(todoOccurrenceConsumer);
    filterLexer.start(content.getContentAsText());
    while (filterLexer.getTokenType() != null) filterLexer.advance();
    Map<TodoIndexEntry, Integer> todoMap = null;
    if (needTodo) {
        for (IndexPattern indexPattern : IndexPatternUtil.getIndexPatterns()) {
            final int count = todoOccurrenceConsumer.getOccurrenceCount(indexPattern);
            if (count > 0) {
                if (todoMap == null)
                    todoMap = new THashMap<>();
                todoMap.put(new TodoIndexEntry(indexPattern.getPatternString(), indexPattern.isCaseSensitive()), count);
            }
        }
    }
    data = new ScanContent(consumer != null ? consumer.getResult() : Collections.<IdIndexEntry, Integer>emptyMap(), todoMap != null ? todoMap : Collections.<TodoIndexEntry, Integer>emptyMap());
    if (needIdIndex && needTodo)
        content.putUserData(scanContentKey, data);
    return data;
}
Also used : Lexer(com.intellij.lexer.Lexer) THashMap(gnu.trove.THashMap) IndexPattern(com.intellij.psi.search.IndexPattern) IdDataConsumer(com.intellij.util.indexing.IdDataConsumer) LexerBasedIdIndexer(com.intellij.psi.impl.cache.impl.id.LexerBasedIdIndexer) TodoIndexEntry(com.intellij.psi.impl.cache.impl.todo.TodoIndexEntry)

Example 84 with THashMap

use of gnu.trove.THashMap in project intellij-community by JetBrains.

the class BreakpointManager method doRead.

private void doRead(@NotNull final Element parentNode) {
    ApplicationManager.getApplication().runReadAction(() -> {
        final Map<String, Breakpoint> nameToBreakpointMap = new THashMap<>();
        try {
            final List groups = parentNode.getChildren();
            for (final Object group1 : groups) {
                final Element group = (Element) group1;
                if (group.getName().equals(RULES_GROUP_NAME)) {
                    continue;
                }
                // skip already converted
                if (group.getAttribute(CONVERTED_PARAM) != null) {
                    continue;
                }
                final String categoryName = group.getName();
                final Key<Breakpoint> breakpointCategory = BreakpointCategory.lookup(categoryName);
                final String defaultPolicy = group.getAttributeValue(DEFAULT_SUSPEND_POLICY_ATTRIBUTE_NAME);
                final boolean conditionEnabled = Boolean.parseBoolean(group.getAttributeValue(DEFAULT_CONDITION_STATE_ATTRIBUTE_NAME, "true"));
                setBreakpointDefaults(breakpointCategory, new BreakpointDefaults(defaultPolicy, conditionEnabled));
                Element anyExceptionBreakpointGroup;
                if (!AnyExceptionBreakpoint.ANY_EXCEPTION_BREAKPOINT.equals(breakpointCategory)) {
                    // for compatibility with previous format
                    anyExceptionBreakpointGroup = group.getChild(AnyExceptionBreakpoint.ANY_EXCEPTION_BREAKPOINT.toString());
                    //if (factory != null) {
                    for (Element breakpointNode : group.getChildren("breakpoint")) {
                        //Breakpoint breakpoint = factory.createBreakpoint(myProject, breakpointNode);
                        Breakpoint breakpoint = createBreakpoint(categoryName, breakpointNode);
                        breakpoint.readExternal(breakpointNode);
                        nameToBreakpointMap.put(breakpoint.getDisplayName(), breakpoint);
                    }
                //}
                } else {
                    anyExceptionBreakpointGroup = group;
                }
                if (anyExceptionBreakpointGroup != null) {
                    final Element breakpointElement = group.getChild("breakpoint");
                    if (breakpointElement != null) {
                        XBreakpointManager manager = XDebuggerManager.getInstance(myProject).getBreakpointManager();
                        JavaExceptionBreakpointType type = XDebuggerUtil.getInstance().findBreakpointType(JavaExceptionBreakpointType.class);
                        XBreakpoint<JavaExceptionBreakpointProperties> xBreakpoint = manager.getDefaultBreakpoint(type);
                        Breakpoint breakpoint = getJavaBreakpoint(xBreakpoint);
                        if (breakpoint != null) {
                            breakpoint.readExternal(breakpointElement);
                            addBreakpoint(breakpoint);
                        }
                    }
                }
            }
        } catch (InvalidDataException ignored) {
        }
        final Element rulesGroup = parentNode.getChild(RULES_GROUP_NAME);
        if (rulesGroup != null) {
            final List<Element> rules = rulesGroup.getChildren("rule");
            for (Element rule : rules) {
                // skip already converted
                if (rule.getAttribute(CONVERTED_PARAM) != null) {
                    continue;
                }
                final Element master = rule.getChild(MASTER_BREAKPOINT_TAG_NAME);
                if (master == null) {
                    continue;
                }
                final Element slave = rule.getChild(SLAVE_BREAKPOINT_TAG_NAME);
                if (slave == null) {
                    continue;
                }
                final Breakpoint masterBreakpoint = nameToBreakpointMap.get(master.getAttributeValue("name"));
                if (masterBreakpoint == null) {
                    continue;
                }
                final Breakpoint slaveBreakpoint = nameToBreakpointMap.get(slave.getAttributeValue("name"));
                if (slaveBreakpoint == null) {
                    continue;
                }
                boolean leaveEnabled = "true".equalsIgnoreCase(rule.getAttributeValue("leaveEnabled"));
                XDependentBreakpointManager dependentBreakpointManager = ((XBreakpointManagerImpl) getXBreakpointManager()).getDependentBreakpointManager();
                dependentBreakpointManager.setMasterBreakpoint(slaveBreakpoint.myXBreakpoint, masterBreakpoint.myXBreakpoint, leaveEnabled);
            //addBreakpointRule(new EnableBreakpointRule(BreakpointManager.this, masterBreakpoint, slaveBreakpoint, leaveEnabled));
            }
        }
        DebuggerInvocationUtil.invokeLater(myProject, this::updateBreakpointsUI);
    });
    myUIProperties.clear();
    final Element props = parentNode.getChild("ui_properties");
    if (props != null) {
        final List children = props.getChildren("property");
        for (Object child : children) {
            Element property = (Element) child;
            final String name = property.getAttributeValue("name");
            final String value = property.getAttributeValue("value");
            if (name != null && value != null) {
                myUIProperties.put(name, value);
            }
        }
    }
}
Also used : XDependentBreakpointManager(com.intellij.xdebugger.impl.breakpoints.XDependentBreakpointManager) JavaExceptionBreakpointProperties(org.jetbrains.java.debugger.breakpoints.properties.JavaExceptionBreakpointProperties) Element(org.jdom.Element) XBreakpointManagerImpl(com.intellij.xdebugger.impl.breakpoints.XBreakpointManagerImpl) THashMap(gnu.trove.THashMap) InvalidDataException(com.intellij.openapi.util.InvalidDataException) List(java.util.List)

Example 85 with THashMap

use of gnu.trove.THashMap in project intellij-community by JetBrains.

the class OfflineViewParseUtil method parse.

public static Map<String, Set<OfflineProblemDescriptor>> parse(final String problems) {
    final TObjectIntHashMap<String> fqName2IdxMap = new TObjectIntHashMap<>();
    final Map<String, Set<OfflineProblemDescriptor>> package2Result = new THashMap<>();
    final XppReader reader = new XppReader(new StringReader(problems));
    try {
        while (reader.hasMoreChildren()) {
            //problem
            reader.moveDown();
            final OfflineProblemDescriptor descriptor = new OfflineProblemDescriptor();
            boolean added = false;
            while (reader.hasMoreChildren()) {
                reader.moveDown();
                if (SmartRefElementPointerImpl.ENTRY_POINT.equals(reader.getNodeName())) {
                    descriptor.setType(reader.getAttribute(SmartRefElementPointerImpl.TYPE_ATTR));
                    final String fqName = reader.getAttribute(SmartRefElementPointerImpl.FQNAME_ATTR);
                    descriptor.setFQName(fqName);
                    if (!fqName2IdxMap.containsKey(fqName)) {
                        fqName2IdxMap.put(fqName, 0);
                    }
                    int idx = fqName2IdxMap.get(fqName);
                    descriptor.setProblemIndex(idx);
                    fqName2IdxMap.put(fqName, idx + 1);
                }
                if (DESCRIPTION.equals(reader.getNodeName())) {
                    descriptor.setDescription(reader.getValue());
                }
                if (LINE.equals(reader.getNodeName())) {
                    descriptor.setLine(Integer.parseInt(reader.getValue()));
                }
                if (MODULE.equals(reader.getNodeName())) {
                    descriptor.setModule(reader.getValue());
                }
                if (HINTS.equals(reader.getNodeName())) {
                    while (reader.hasMoreChildren()) {
                        reader.moveDown();
                        List<String> hints = descriptor.getHints();
                        if (hints == null) {
                            hints = new ArrayList<>();
                            descriptor.setHints(hints);
                        }
                        hints.add(reader.getAttribute("value"));
                        reader.moveUp();
                    }
                }
                if (PACKAGE.equals(reader.getNodeName())) {
                    appendDescriptor(package2Result, reader.getValue(), descriptor);
                    added = true;
                }
                while (reader.hasMoreChildren()) {
                    reader.moveDown();
                    if (PACKAGE.equals(reader.getNodeName())) {
                        appendDescriptor(package2Result, reader.getValue(), descriptor);
                        added = true;
                    }
                    reader.moveUp();
                }
                reader.moveUp();
            }
            if (!added)
                appendDescriptor(package2Result, "", descriptor);
            reader.moveUp();
        }
    } finally {
        reader.close();
    }
    return package2Result;
}
Also used : Set(java.util.Set) THashSet(gnu.trove.THashSet) OfflineProblemDescriptor(com.intellij.codeInspection.offline.OfflineProblemDescriptor) THashMap(gnu.trove.THashMap) TObjectIntHashMap(gnu.trove.TObjectIntHashMap) XppReader(com.thoughtworks.xstream.io.xml.XppReader) StringReader(java.io.StringReader)

Aggregations

THashMap (gnu.trove.THashMap)129 NotNull (org.jetbrains.annotations.NotNull)33 THashSet (gnu.trove.THashSet)26 VirtualFile (com.intellij.openapi.vfs.VirtualFile)18 Element (org.jdom.Element)18 PsiElement (com.intellij.psi.PsiElement)16 IOException (java.io.IOException)16 File (java.io.File)15 Nullable (org.jetbrains.annotations.Nullable)10 Project (com.intellij.openapi.project.Project)9 List (java.util.List)9 Module (com.intellij.openapi.module.Module)8 Pair (com.intellij.openapi.util.Pair)7 PsiFile (com.intellij.psi.PsiFile)7 Map (java.util.Map)7 java.util (java.util)6 ArrayList (java.util.ArrayList)6 ApplicationManager (com.intellij.openapi.application.ApplicationManager)5 Document (com.intellij.openapi.editor.Document)5 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)5