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]);
}
};
}
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;
}
});
}
use of gnu.trove.TIntObjectHashMap in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoCoverageRunner method parseCoverage.
@Nullable
public static GoCoverageProjectData parseCoverage(@NotNull BufferedReader dataReader, @NotNull Project project, @Nullable Module module) throws IOException {
GoCoverageProjectData result = new GoCoverageProjectData();
String line;
while ((line = dataReader.readLine()) != null) {
if (line.isEmpty())
continue;
List<String> fileNameTail = StringUtil.split(line, ":");
VirtualFile file = GoPackageUtil.findByImportPath(fileNameTail.get(0), project, module);
if (file == null)
continue;
String filePath = file.getPath();
List<String> tailParts = StringUtil.split(fileNameTail.get(1), " ");
if (tailParts.size() != 3)
continue;
int statements = Integer.parseInt(tailParts.get(1));
int hit = Integer.parseInt(tailParts.get(2));
String offsets = tailParts.get(0);
int firstDot = offsets.indexOf('.');
int comma = offsets.indexOf(',', firstDot);
int secondDot = offsets.indexOf('.', comma);
if (firstDot == -1 || comma == -1 || secondDot == -1)
continue;
int lineStart = Integer.parseInt(offsets.substring(0, firstDot));
int columnStart = Integer.parseInt(offsets.substring(firstDot + 1, comma));
int lineEnd = Integer.parseInt(offsets.substring(comma + 1, secondDot));
int columnEnd = Integer.parseInt(offsets.substring(secondDot + 1));
result.addData(filePath, lineStart, columnStart, lineEnd, columnEnd, statements, hit);
}
result.processFiles(fileData -> {
ClassData classData = result.getOrCreateClassData(fileData.myFilePath);
int max = -1;
TIntObjectHashMap<LineData> linesMap = new TIntObjectHashMap<>();
for (GoCoverageProjectData.RangeData rangeData : fileData.myRangesData.values()) {
for (int i = rangeData.startLine; i <= rangeData.endLine; i++) {
LineData existingData = linesMap.get(i);
if (existingData != null) {
existingData.setHits(existingData.getHits() + rangeData.hits);
existingData.setFalseHits(0, 0);
existingData.setTrueHits(0, 0);
} else {
LineData newData = new LineData(i, null);
newData.setHits(newData.getHits() + rangeData.hits);
linesMap.put(i, newData);
}
}
max = Math.max(max, rangeData.endLine);
}
LineData[] linesArray = new LineData[max + 1];
linesMap.forEachValue(data -> {
data.fillArrays();
linesArray[data.getLineNumber()] = data;
return true;
});
classData.setLines(linesArray);
return true;
});
return result;
}
use of gnu.trove.TIntObjectHashMap in project intellij-community by JetBrains.
the class IntObjectHashMapTest method test.
@Test
public void test() {
IntObjectHashMap map = new IntObjectHashMap();
TIntObjectHashMap<Object> checkMap = new TIntObjectHashMap<>();
TIntObjectHashMap<Object> dupesMap = new TIntObjectHashMap<>();
Random random = new Random();
for (int i = 0; i < 1000000; ++i) {
int key = random.nextInt();
String value = String.valueOf(random.nextInt());
if (!checkMap.contains(key)) {
map.put(key, value);
checkMap.put(key, value);
assertEquals(map.size(), checkMap.size());
assertEquals(value, map.get(key));
} else {
dupesMap.put(key, value);
}
}
dupesMap.put(0, "random string");
dupesMap.forEachEntry((int k, Object v) -> {
checkMap.put(k, v);
map.put(k, v);
assertEquals(map.size(), checkMap.size());
assertEquals(v, map.get(k));
return true;
});
String value = "random string2";
checkMap.put(0, value);
map.put(0, value);
checkMap.forEachEntry((k, v) -> {
assertEquals(v, map.get(k));
return true;
});
assertEquals(map.size(), checkMap.size());
}
use of gnu.trove.TIntObjectHashMap in project intellij-community by JetBrains.
the class FileHeaderChecker method checkFileHeader.
static ProblemDescriptor checkFileHeader(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean onTheFly) {
TIntObjectHashMap<String> offsetToProperty = new TIntObjectHashMap<>();
FileTemplate defaultTemplate = FileTemplateManager.getInstance(file.getProject()).getDefaultTemplate(FileTemplateManager.FILE_HEADER_TEMPLATE_NAME);
Pattern pattern = FileTemplateUtil.getTemplatePattern(defaultTemplate, file.getProject(), offsetToProperty);
Matcher matcher = pattern.matcher(file.getViewProvider().getContents());
if (!matcher.matches()) {
return null;
}
PsiComment element = PsiTreeUtil.findElementOfClassAtRange(file, matcher.start(1), matcher.end(1), PsiComment.class);
if (element == null) {
return null;
}
LocalQuickFix[] fixes = createQuickFix(matcher, offsetToProperty, file.getProject(), onTheFly);
String description = InspectionsBundle.message("default.file.template.description");
return manager.createProblemDescriptor(element, description, onTheFly, fixes, ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
}
Aggregations