use of com.intellij.util.containers.HashMap in project intellij-community by JetBrains.
the class ImportTree method getIgnoreFileFilter.
public IIgnoreFileFilter getIgnoreFileFilter() {
final Collection<File> excludedFiles = new HashSet<>();
for (final VirtualFile excludedFile : myExcludedFiles) {
excludedFiles.add(CvsVfsUtil.getFileFor(excludedFile));
}
final Collection<File> includedFiles = new HashSet<>();
for (VirtualFile includedFile : myIncludedFiles) {
includedFiles.add(CvsVfsUtil.getFileFor(includedFile));
}
return new IIgnoreFileFilter() {
private final Map<File, IgnoredFilesInfo> myParentToIgnoresMap = new HashMap<>();
public boolean shouldBeIgnored(AbstractFileObject abstractFileObject, ICvsFileSystem cvsFileSystem) {
final File file = cvsFileSystem.getLocalFileSystem().getFile(abstractFileObject);
if (file.isDirectory() && file.getName().equals(CvsUtil.CVS))
return true;
if (FileTypeManager.getInstance().isFileIgnored(abstractFileObject.getName()))
return true;
final VirtualFile vFile = LocalFileSystem.getInstance().findFileByIoFile(file);
if (myProject != null && !includedFiles.contains(file)) {
if (vFile != null && isIgnoredByVcs(vFile)) {
return true;
}
}
if (excludedFiles.contains(file))
return true;
final File parentFile = file.getParentFile();
if (parentFile == null)
return false;
if (!myParentToIgnoresMap.containsKey(parentFile)) {
myParentToIgnoresMap.put(parentFile, IgnoredFilesInfoImpl.createForFile(new File(parentFile, CvsUtil.CVS_IGNORE_FILE)));
}
return myParentToIgnoresMap.get(parentFile).shouldBeIgnored(vFile);
}
};
}
use of com.intellij.util.containers.HashMap in project intellij-community by JetBrains.
the class BaseToolKeymapExtension method createGroup.
@Override
public KeymapGroup createGroup(final Condition<AnAction> filtered, final Project project) {
final ActionManagerEx actionManager = ActionManagerEx.getInstanceEx();
String[] ids = actionManager.getActionIds(getActionIdPrefix());
Arrays.sort(ids);
Group group = new Group(getGroupName(), AllIcons.Nodes.KeymapTools);
HashMap<String, Group> toolGroupNameToGroup = new HashMap<>();
for (String id : ids) {
if (filtered != null && !filtered.value(actionManager.getActionOrStub(id)))
continue;
String groupName = getGroupByActionId(id);
if (groupName != null && groupName.trim().length() == 0) {
groupName = null;
}
Group subGroup = toolGroupNameToGroup.get(groupName);
if (subGroup == null) {
subGroup = new Group(groupName, null, null);
toolGroupNameToGroup.put(groupName, subGroup);
if (groupName != null) {
group.addGroup(subGroup);
}
}
subGroup.addActionId(id);
}
Group subGroup = toolGroupNameToGroup.get(null);
if (subGroup != null) {
group.addAll(subGroup);
}
return group;
}
use of com.intellij.util.containers.HashMap in project intellij-community by JetBrains.
the class VariableAccessVisitor method buildReferenceMap.
private static HashMap<PsiMethod, Collection<PsiReference>> buildReferenceMap(Set<PsiMethod> privateMethods) {
final HashMap<PsiMethod, Collection<PsiReference>> referenceMap = new HashMap<>();
for (PsiMethod method : privateMethods) {
ProgressManager.checkCanceled();
final SearchScope scope = method.getUseScope();
final Collection<PsiReference> references = ReferencesSearch.search(method, scope).findAll();
referenceMap.put(method, references);
}
return referenceMap;
}
use of com.intellij.util.containers.HashMap in project intellij-community by JetBrains.
the class PackageAnnotator method collectCoverageInformation.
@Nullable
private DirCoverageInfo[] collectCoverageInformation(final File packageOutputRoot, final Map<String, PackageCoverageInfo> packageCoverageMap, Map<String, PackageCoverageInfo> flattenPackageCoverageMap, final ProjectData projectInfo, final String packageVMName, final Annotator annotator, final Module module, final boolean trackTestFolders, final boolean isTestHierarchy) {
final List<DirCoverageInfo> dirs = new ArrayList<>();
final ContentEntry[] contentEntries = ModuleRootManager.getInstance(module).getContentEntries();
for (ContentEntry contentEntry : contentEntries) {
for (SourceFolder folder : contentEntry.getSourceFolders(isTestHierarchy ? JavaSourceRootType.TEST_SOURCE : JavaSourceRootType.SOURCE)) {
final VirtualFile file = folder.getFile();
if (file == null)
continue;
final String prefix = folder.getPackagePrefix().replaceAll("\\.", "/");
final VirtualFile relativeSrcRoot = file.findFileByRelativePath(StringUtil.trimStart(packageVMName, prefix));
dirs.add(new DirCoverageInfo(relativeSrcRoot));
}
}
final PackageCoverageInfo classWithoutSourceCoverageInfo = new PackageCoverageInfo();
final File[] children = packageOutputRoot.listFiles();
if (children == null)
return null;
Map<String, ClassCoverageInfo> toplevelClassCoverage = new HashMap<>();
for (File child : children) {
if (child.isDirectory()) {
final String childName = child.getName();
final String childPackageVMName = packageVMName.length() > 0 ? packageVMName + "/" + childName : childName;
final DirCoverageInfo[] childCoverageInfo = collectCoverageInformation(child, packageCoverageMap, flattenPackageCoverageMap, projectInfo, childPackageVMName, annotator, module, trackTestFolders, isTestHierarchy);
if (childCoverageInfo != null) {
for (int i = 0; i < childCoverageInfo.length; i++) {
DirCoverageInfo coverageInfo = childCoverageInfo[i];
final DirCoverageInfo parentDir = dirs.get(i);
parentDir.totalClassCount += coverageInfo.totalClassCount;
parentDir.coveredClassCount += coverageInfo.coveredClassCount;
parentDir.totalLineCount += coverageInfo.totalLineCount;
parentDir.coveredLineCount += coverageInfo.coveredLineCount;
parentDir.totalMethodCount += coverageInfo.totalMethodCount;
parentDir.coveredMethodCount += coverageInfo.coveredMethodCount;
}
}
} else {
if (isClassFile(child)) {
final String childName = getClassName(child);
final String classFqVMName = packageVMName.length() > 0 ? packageVMName + "/" + childName : childName;
final String toplevelClassSrcFQName = getSourceToplevelFQName(classFqVMName);
final Ref<VirtualFile> containingFileRef = new Ref<>();
final Ref<PsiClass> psiClassRef = new Ref<>();
final CoverageSuitesBundle suitesBundle = myCoverageManager.getCurrentSuitesBundle();
if (suitesBundle == null)
continue;
final Boolean isInSource = DumbService.getInstance(myProject).runReadActionInSmartMode(() -> {
if (myProject.isDisposed())
return null;
final PsiClass aClass = JavaPsiFacade.getInstance(myManager.getProject()).findClass(toplevelClassSrcFQName, GlobalSearchScope.moduleScope(module));
if (aClass == null || !aClass.isValid())
return Boolean.FALSE;
psiClassRef.set(aClass);
containingFileRef.set(aClass.getNavigationElement().getContainingFile().getVirtualFile());
if (containingFileRef.isNull()) {
LOG.info("No virtual file found for: " + aClass);
return null;
}
final ModuleFileIndex fileIndex = ModuleRootManager.getInstance(module).getFileIndex();
return fileIndex.isUnderSourceRootOfType(containingFileRef.get(), JavaModuleSourceRootTypes.SOURCES) && (trackTestFolders || !fileIndex.isInTestSourceContent(containingFileRef.get()));
});
PackageCoverageInfo coverageInfoForClass = null;
String classCoverageKey = classFqVMName.replace('/', '.');
boolean ignoreClass = false;
boolean keepWithoutSource = false;
for (JavaCoverageEngineExtension extension : JavaCoverageEngineExtension.EP_NAME.getExtensions()) {
if (extension.ignoreCoverageForClass(suitesBundle, child)) {
ignoreClass = true;
break;
}
if (extension.keepCoverageInfoForClassWithoutSource(suitesBundle, child)) {
keepWithoutSource = true;
}
}
if (ignoreClass) {
continue;
}
if (isInSource != null && isInSource.booleanValue()) {
for (DirCoverageInfo dirCoverageInfo : dirs) {
if (dirCoverageInfo.sourceRoot != null && VfsUtil.isAncestor(dirCoverageInfo.sourceRoot, containingFileRef.get(), false)) {
coverageInfoForClass = dirCoverageInfo;
classCoverageKey = toplevelClassSrcFQName;
break;
}
}
}
if (coverageInfoForClass == null && keepWithoutSource) {
coverageInfoForClass = classWithoutSourceCoverageInfo;
}
if (coverageInfoForClass != null) {
collectClassCoverageInformation(child, psiClassRef.get(), coverageInfoForClass, projectInfo, toplevelClassCoverage, classFqVMName.replace("/", "."), classCoverageKey);
}
}
}
}
for (Map.Entry<String, ClassCoverageInfo> entry : toplevelClassCoverage.entrySet()) {
final String toplevelClassName = entry.getKey();
final ClassCoverageInfo coverageInfo = entry.getValue();
annotator.annotateClass(toplevelClassName, coverageInfo);
}
PackageCoverageInfo flattenPackageCoverageInfo = getOrCreateCoverageInfo(flattenPackageCoverageMap, packageVMName);
for (Map.Entry<String, ClassCoverageInfo> entry : toplevelClassCoverage.entrySet()) {
final ClassCoverageInfo coverageInfo = entry.getValue();
flattenPackageCoverageInfo.append(coverageInfo);
}
PackageCoverageInfo packageCoverageInfo = getOrCreateCoverageInfo(packageCoverageMap, packageVMName);
for (DirCoverageInfo dir : dirs) {
packageCoverageInfo.append(dir);
if (isTestHierarchy) {
annotator.annotateTestDirectory(dir.sourceRoot, dir, module);
} else {
annotator.annotateSourceDirectory(dir.sourceRoot, dir, module);
}
}
packageCoverageInfo.append(classWithoutSourceCoverageInfo);
return dirs.toArray(new DirCoverageInfo[dirs.size()]);
}
use of com.intellij.util.containers.HashMap in project intellij-community by JetBrains.
the class PackageAnnotator method annotateFilteredClass.
public void annotateFilteredClass(PsiClass psiClass, CoverageSuitesBundle bundle, Annotator annotator) {
final ProjectData data = bundle.getCoverageData();
if (data == null)
return;
final Module module = ModuleUtil.findModuleForPsiElement(psiClass);
if (module != null) {
final boolean isInTests = ProjectRootManager.getInstance(module.getProject()).getFileIndex().isInTestSourceContent(psiClass.getContainingFile().getVirtualFile());
final CompilerModuleExtension moduleExtension = CompilerModuleExtension.getInstance(module);
final VirtualFile outputPath = isInTests ? moduleExtension.getCompilerOutputPathForTests() : moduleExtension.getCompilerOutputPath();
if (outputPath != null) {
final String qualifiedName = psiClass.getQualifiedName();
if (qualifiedName == null)
return;
final String packageVMName = StringUtil.getPackageName(qualifiedName).replace('.', '/');
final File packageRoot = findRelativeFile(packageVMName, outputPath);
if (packageRoot != null && packageRoot.exists()) {
Map<String, ClassCoverageInfo> toplevelClassCoverage = new HashMap<>();
final File[] files = packageRoot.listFiles();
if (files != null) {
for (File child : files) {
if (isClassFile(child)) {
final String childName = getClassName(child);
final String classFqVMName = packageVMName.length() > 0 ? packageVMName + "/" + childName : childName;
final String toplevelClassSrcFQName = getSourceToplevelFQName(classFqVMName);
if (toplevelClassSrcFQName.equals(qualifiedName)) {
collectClassCoverageInformation(child, psiClass, new PackageCoverageInfo(), data, toplevelClassCoverage, classFqVMName.replace("/", "."), toplevelClassSrcFQName);
}
}
}
}
for (ClassCoverageInfo coverageInfo : toplevelClassCoverage.values()) {
annotator.annotateClass(qualifiedName, coverageInfo);
}
}
}
}
}
Aggregations