Search in sources :

Example 6 with OfflineProblemDescriptor

use of com.intellij.codeInspection.offline.OfflineProblemDescriptor 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)

Example 7 with OfflineProblemDescriptor

use of com.intellij.codeInspection.offline.OfflineProblemDescriptor in project intellij-community by JetBrains.

the class OfflineInspectionResultViewTest method parse.

private Map<String, Map<String, Set<OfflineProblemDescriptor>>> parse() throws IOException {
    final String moduleName = getModule().getName();
    final File res = new File(PathManagerEx.getTestDataPath(), getTestPath() + File.separator + "res");
    final File[] files = res.listFiles();
    assert files != null;
    final Map<String, Map<String, Set<OfflineProblemDescriptor>>> map = new HashMap<>();
    for (File file : files) {
        final String problems = FileUtil.loadFile(file);
        final Map<String, Set<OfflineProblemDescriptor>> descriptors = OfflineViewParseUtil.parse(problems);
        for (Set<OfflineProblemDescriptor> problemDescriptors : descriptors.values()) {
            for (OfflineProblemDescriptor descriptor : problemDescriptors) {
                descriptor.setModule(moduleName);
            }
        }
        final String name = file.getName();
        map.put(name.substring(0, name.lastIndexOf('.')), descriptors);
    }
    return map;
}
Also used : OfflineProblemDescriptor(com.intellij.codeInspection.offline.OfflineProblemDescriptor) Set(java.util.Set) HashMap(java.util.HashMap) THashMap(gnu.trove.THashMap) File(java.io.File) HashMap(java.util.HashMap) THashMap(gnu.trove.THashMap) Map(java.util.Map)

Aggregations

OfflineProblemDescriptor (com.intellij.codeInspection.offline.OfflineProblemDescriptor)7 THashMap (gnu.trove.THashMap)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Set (java.util.Set)2 PerformAnalysisInBackgroundOption (com.intellij.analysis.PerformAnalysisInBackgroundOption)1 DaemonProgressIndicator (com.intellij.codeInsight.daemon.impl.DaemonProgressIndicator)1 GlobalInspectionToolWrapper (com.intellij.codeInspection.ex.GlobalInspectionToolWrapper)1 LocalInspectionToolWrapper (com.intellij.codeInspection.ex.LocalInspectionToolWrapper)1 RefElement (com.intellij.codeInspection.reference.RefElement)1 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)1 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 Task (com.intellij.openapi.progress.Task)1 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 HashSet (com.intellij.util.containers.HashSet)1 XppReader (com.thoughtworks.xstream.io.xml.XppReader)1 THashSet (gnu.trove.THashSet)1 TObjectIntHashMap (gnu.trove.TObjectIntHashMap)1