Search in sources :

Example 6 with TIntObjectHashMap

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

the class TestDiscoveryIndex method doUpdateFromTestTrace.

private void doUpdateFromTestTrace(File file, final String testName, @Nullable final String moduleName) throws IOException {
    myLocalTestRunDataController.withTestDataHolder(new ThrowableConvertor<TestInfoHolder, Void, IOException>() {

        @Override
        public Void convert(TestInfoHolder localHolder) throws IOException {
            final int testNameId = localHolder.myTestNameEnumerator.enumerate(testName);
            TIntObjectHashMap<TIntArrayList> classData = loadClassAndMethodsMap(file, localHolder);
            TIntObjectHashMap<TIntArrayList> previousClassData = localHolder.myTestNameToUsedClassesAndMethodMap.get(testNameId);
            if (previousClassData == null) {
                previousClassData = myRemoteTestRunDataController.withTestDataHolder(remoteDataHolder -> {
                    TIntObjectHashMap<TIntArrayList> remoteClassData = remoteDataHolder.myTestNameToUsedClassesAndMethodMap.get(testNameId);
                    if (remoteClassData == null)
                        return null;
                    TIntObjectHashMap<TIntArrayList> result = new TIntObjectHashMap<>(remoteClassData.size());
                    Ref<IOException> exceptionRef = new Ref<>();
                    boolean processingResult = remoteClassData.forEachEntry((remoteClassKey, remoteClassMethodIds) -> {
                        try {
                            int localClassKey = localHolder.myClassEnumeratorCache.enumerate(remoteDataHolder.myClassEnumeratorCache.valueOf(remoteClassKey));
                            TIntArrayList localClassIds = new TIntArrayList(remoteClassMethodIds.size());
                            for (int methodId : remoteClassMethodIds.toNativeArray()) {
                                localClassIds.add(localHolder.myMethodEnumeratorCache.enumerate(remoteDataHolder.myMethodEnumeratorCache.valueOf(methodId)));
                            }
                            result.put(localClassKey, localClassIds);
                            return true;
                        } catch (IOException ex) {
                            exceptionRef.set(ex);
                            return false;
                        }
                    });
                    if (!processingResult)
                        throw exceptionRef.get();
                    return result;
                });
            }
            localHolder.doUpdateFromDiff(testNameId, classData, previousClassData, moduleName != null ? localHolder.myModuleNameEnumerator.enumerate(moduleName) : null);
            return null;
        }
    });
}
Also used : Ref(com.intellij.openapi.util.Ref) TIntObjectHashMap(gnu.trove.TIntObjectHashMap) TIntArrayList(gnu.trove.TIntArrayList)

Example 7 with TIntObjectHashMap

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

the class BuildResult method dumpSourceToOutputMappings.

private static void dumpSourceToOutputMappings(ProjectDescriptor pd, PrintStream stream) throws IOException {
    List<BuildTarget<?>> targets = new ArrayList<>(pd.getBuildTargetIndex().getAllTargets());
    targets.sort((o1, o2) -> StringUtil.comparePairs(o1.getTargetType().getTypeId(), o1.getId(), o2.getTargetType().getTypeId(), o2.getId(), false));
    final TIntObjectHashMap<BuildTarget<?>> id2Target = new TIntObjectHashMap<>();
    for (BuildTarget<?> target : targets) {
        id2Target.put(pd.dataManager.getTargetsState().getBuildTargetId(target), target);
    }
    TIntObjectHashMap<String> hashCodeToOutputPath = new TIntObjectHashMap<>();
    for (BuildTarget<?> target : targets) {
        stream.println("Begin Of SourceToOutput (target " + getTargetIdWithTypeId(target) + ")");
        SourceToOutputMapping map = pd.dataManager.getSourceToOutputMap(target);
        List<String> sourcesList = new ArrayList<>(map.getSources());
        Collections.sort(sourcesList);
        for (String source : sourcesList) {
            List<String> outputs = new ArrayList<>(ObjectUtils.notNull(map.getOutputs(source), Collections.<String>emptySet()));
            Collections.sort(outputs);
            for (String output : outputs) {
                hashCodeToOutputPath.put(FileUtil.pathHashCode(output), output);
            }
            String sourceToCompare = SystemInfo.isFileSystemCaseSensitive ? source : source.toLowerCase(Locale.US);
            stream.println(" " + sourceToCompare + " -> " + StringUtil.join(outputs, ","));
        }
        stream.println("End Of SourceToOutput (target " + getTargetIdWithTypeId(target) + ")");
    }
    OutputToTargetRegistry registry = pd.dataManager.getOutputToTargetRegistry();
    List<Integer> keys = new ArrayList<>(registry.getKeys());
    Collections.sort(keys);
    stream.println("Begin Of OutputToTarget");
    for (Integer key : keys) {
        TIntHashSet targetsIds = registry.getState(key);
        if (targetsIds == null)
            continue;
        final List<String> targetsNames = new ArrayList<>();
        targetsIds.forEach(value -> {
            BuildTarget<?> target = id2Target.get(value);
            targetsNames.add(target != null ? getTargetIdWithTypeId(target) : "<unknown " + value + ">");
            return true;
        });
        Collections.sort(targetsNames);
        stream.println(hashCodeToOutputPath.get(key) + " -> " + targetsNames);
    }
    stream.println("End Of OutputToTarget");
}
Also used : SourceToOutputMapping(org.jetbrains.jps.builders.storage.SourceToOutputMapping) OutputToTargetRegistry(org.jetbrains.jps.incremental.storage.OutputToTargetRegistry) ArrayList(java.util.ArrayList) TIntHashSet(gnu.trove.TIntHashSet) TIntObjectHashMap(gnu.trove.TIntObjectHashMap)

Example 8 with TIntObjectHashMap

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

the class DuplicatesMatchingVisitor method doMatchInAnyOrder.

@Override
protected boolean doMatchInAnyOrder(NodeIterator it1, NodeIterator it2) {
    final List<PsiElement> elements1 = new ArrayList<>();
    final List<PsiElement> elements2 = new ArrayList<>();
    while (it1.hasNext()) {
        final PsiElement element = it1.current();
        if (element != null) {
            elements1.add(element);
        }
        it1.advance();
    }
    while (it2.hasNext()) {
        final PsiElement element = it2.current();
        if (element != null) {
            elements2.add(element);
        }
        it2.advance();
    }
    if (elements1.size() != elements2.size()) {
        return false;
    }
    final TIntObjectHashMap<List<PsiElement>> hash2element = new TIntObjectHashMap<>(elements1.size());
    for (PsiElement element : elements1) {
        final TreeHashResult result = myTreeHasher.hash(element, null, myNodeSpecificHasher);
        if (result != null) {
            final int hash = result.getHash();
            List<PsiElement> list = hash2element.get(hash);
            if (list == null) {
                list = new ArrayList<>();
                hash2element.put(hash, list);
            }
            list.add(element);
        }
    }
    for (PsiElement element : elements2) {
        final TreeHashResult result = myTreeHasher.hash(element, null, myNodeSpecificHasher);
        if (result != null) {
            final int hash = result.getHash();
            final List<PsiElement> list = hash2element.get(hash);
            if (list == null) {
                return false;
            }
            boolean found = false;
            for (Iterator<PsiElement> it = list.iterator(); it.hasNext(); ) {
                if (match(element, it.next())) {
                    it.remove();
                    found = true;
                }
            }
            if (!found) {
                return false;
            }
            if (list.size() == 0) {
                hash2element.remove(hash);
            }
        }
    }
    return hash2element.size() == 0;
}
Also used : TIntObjectHashMap(gnu.trove.TIntObjectHashMap) PsiElement(com.intellij.psi.PsiElement)

Example 9 with TIntObjectHashMap

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

the class DuplocatorHashCallback method getInfo.

public DupInfo getInfo() {
    final TObjectIntHashMap<PsiFragment[]> duplicateList = new TObjectIntHashMap<>();
    myDuplicates.forEachEntry(new TIntObjectProcedure<List<List<PsiFragment>>>() {

        public boolean execute(final int hash, final List<List<PsiFragment>> listList) {
            for (List<PsiFragment> list : listList) {
                final int len = list.size();
                if (len > 1) {
                    PsiFragment[] filtered = new PsiFragment[len];
                    int idx = 0;
                    for (final PsiFragment fragment : list) {
                        fragment.markDuplicate();
                        filtered[idx++] = fragment;
                    }
                    duplicateList.put(filtered, hash);
                }
            }
            return true;
        }
    });
    myDuplicates = null;
    for (TObjectIntIterator<PsiFragment[]> dups = duplicateList.iterator(); dups.hasNext(); ) {
        dups.advance();
        PsiFragment[] fragments = dups.key();
        LOG.assertTrue(fragments.length > 1);
        boolean nested = false;
        for (PsiFragment fragment : fragments) {
            if (fragment.isNested()) {
                nested = true;
                break;
            }
        }
        if (nested) {
            dups.remove();
        }
    }
    final Object[] duplicates = duplicateList.keys();
    Arrays.sort(duplicates, (x, y) -> ((PsiFragment[]) y)[0].getCost() - ((PsiFragment[]) x)[0].getCost());
    return new DupInfo() {

        private final TIntObjectHashMap<GroupNodeDescription> myPattern2Description = new TIntObjectHashMap<>();

        public int getPatterns() {
            return duplicates.length;
        }

        public int getPatternCost(int number) {
            return ((PsiFragment[]) duplicates[number])[0].getCost();
        }

        public int getPatternDensity(int number) {
            return ((PsiFragment[]) duplicates[number]).length;
        }

        public PsiFragment[] getFragmentOccurences(int pattern) {
            return (PsiFragment[]) duplicates[pattern];
        }

        public UsageInfo[] getUsageOccurences(int pattern) {
            PsiFragment[] occs = getFragmentOccurences(pattern);
            UsageInfo[] infos = new UsageInfo[occs.length];
            for (int i = 0; i < infos.length; i++) {
                infos[i] = occs[i].getUsageInfo();
            }
            return infos;
        }

        public int getFileCount(final int pattern) {
            if (myPattern2Description.containsKey(pattern)) {
                return myPattern2Description.get(pattern).getFilesCount();
            }
            return cacheGroupNodeDescription(pattern).getFilesCount();
        }

        private GroupNodeDescription cacheGroupNodeDescription(final int pattern) {
            final Set<PsiFile> files = new HashSet<>();
            final PsiFragment[] occurencies = getFragmentOccurences(pattern);
            for (PsiFragment occurency : occurencies) {
                final PsiFile file = occurency.getFile();
                if (file != null) {
                    files.add(file);
                }
            }
            final int fileCount = files.size();
            final PsiFile psiFile = occurencies[0].getFile();
            DuplicatesProfile profile = DuplicatesProfileCache.getProfile(this, pattern);
            String comment = profile != null ? profile.getComment(this, pattern) : "";
            final GroupNodeDescription description = new GroupNodeDescription(fileCount, psiFile != null ? psiFile.getName() : "unknown", comment);
            myPattern2Description.put(pattern, description);
            return description;
        }

        @Nullable
        public String getTitle(int pattern) {
            if (getFileCount(pattern) == 1) {
                if (myPattern2Description.containsKey(pattern)) {
                    return myPattern2Description.get(pattern).getTitle();
                }
                return cacheGroupNodeDescription(pattern).getTitle();
            }
            return null;
        }

        @Nullable
        public String getComment(int pattern) {
            if (getFileCount(pattern) == 1) {
                if (myPattern2Description.containsKey(pattern)) {
                    return myPattern2Description.get(pattern).getComment();
                }
                return cacheGroupNodeDescription(pattern).getComment();
            }
            return null;
        }

        public int getHash(final int i) {
            return duplicateList.get((PsiFragment[]) duplicates[i]);
        }
    };
}
Also used : PsiFragment(com.intellij.dupLocator.util.PsiFragment) TObjectIntHashMap(gnu.trove.TObjectIntHashMap) TIntObjectHashMap(gnu.trove.TIntObjectHashMap) PsiFile(com.intellij.psi.PsiFile) UsageInfo(com.intellij.usageView.UsageInfo)

Example 10 with TIntObjectHashMap

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

the class ProcessListUtil method parseMacOutput.

@Nullable
static List<ProcessInfo> parseMacOutput(String commandOnly, String full) {
    List<MacProcessInfo> commands = doParseMacOutput(commandOnly);
    List<MacProcessInfo> fulls = doParseMacOutput(full);
    if (commands == null || fulls == null)
        return null;
    TIntObjectHashMap<String> idToCommand = new TIntObjectHashMap<>();
    for (MacProcessInfo each : commands) {
        idToCommand.put(each.pid, each.commandLine);
    }
    List<ProcessInfo> result = new ArrayList<>();
    for (MacProcessInfo each : fulls) {
        if (!idToCommand.containsKey(each.pid))
            continue;
        String command = idToCommand.get(each.pid);
        if (!(each.commandLine.equals(command) || each.commandLine.startsWith(command + " ")))
            continue;
        String name = PathUtil.getFileName(command);
        String args = each.commandLine.substring(command.length()).trim();
        result.add(new ProcessInfo(each.pid, each.commandLine, name, args, command));
    }
    return result;
}
Also used : TIntObjectHashMap(gnu.trove.TIntObjectHashMap) ArrayList(java.util.ArrayList) ProcessInfo(com.intellij.execution.process.ProcessInfo) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

TIntObjectHashMap (gnu.trove.TIntObjectHashMap)22 ArrayList (java.util.ArrayList)4 TObjectIntHashMap (gnu.trove.TObjectIntHashMap)3 HashMap (java.util.HashMap)3 Nullable (org.jetbrains.annotations.Nullable)3 FileTemplate (com.intellij.ide.fileTemplates.FileTemplate)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 MultiMap (com.intellij.util.containers.MultiMap)2 TIntArrayList (gnu.trove.TIntArrayList)2 Collection (java.util.Collection)2 List (java.util.List)2 Map (java.util.Map)2 Random (java.util.Random)2 NotNull (org.jetbrains.annotations.NotNull)2 VisibleForTesting (com.android.annotations.VisibleForTesting)1 IntArrayWrapper (com.android.ide.common.resources.IntArrayWrapper)1 ResourceType (com.android.resources.ResourceType)1 AppResourceRepository (com.android.tools.idea.res.AppResourceRepository)1 Pair (com.android.util.Pair)1 JavaChainLookupElement (com.intellij.codeInsight.completion.JavaChainLookupElement)1