use of com.intellij.util.containers.HashMap in project intellij-community by JetBrains.
the class PackageAnnotator method annotate.
//get read lock myself when needed
public void annotate(final CoverageSuitesBundle suite, Annotator annotator) {
final ProjectData data = suite.getCoverageData();
if (data == null)
return;
final String qualifiedName = myPackage.getQualifiedName();
boolean filtered = false;
for (CoverageSuite coverageSuite : suite.getSuites()) {
if (((JavaCoverageSuite) coverageSuite).isPackageFiltered(qualifiedName)) {
filtered = true;
break;
}
}
if (!filtered)
return;
final GlobalSearchScope scope = suite.getSearchScope(myProject);
final Module[] modules = myCoverageManager.doInReadActionIfProjectOpen(() -> ModuleManager.getInstance(myProject).getModules());
if (modules == null)
return;
Map<String, PackageCoverageInfo> packageCoverageMap = new HashMap<>();
Map<String, PackageCoverageInfo> flattenPackageCoverageMap = new HashMap<>();
for (final Module module : modules) {
if (!scope.isSearchInModuleContent(module))
continue;
final String rootPackageVMName = qualifiedName.replaceAll("\\.", "/");
final VirtualFile output = myCoverageManager.doInReadActionIfProjectOpen(() -> CompilerModuleExtension.getInstance(module).getCompilerOutputPath());
if (output != null) {
File outputRoot = findRelativeFile(rootPackageVMName, output);
if (outputRoot.exists()) {
collectCoverageInformation(outputRoot, packageCoverageMap, flattenPackageCoverageMap, data, rootPackageVMName, annotator, module, suite.isTrackTestFolders(), false);
}
}
if (suite.isTrackTestFolders()) {
final VirtualFile testPackageRoot = myCoverageManager.doInReadActionIfProjectOpen(() -> CompilerModuleExtension.getInstance(module).getCompilerOutputPathForTests());
if (testPackageRoot != null) {
final File outputRoot = findRelativeFile(rootPackageVMName, testPackageRoot);
if (outputRoot.exists()) {
collectCoverageInformation(outputRoot, packageCoverageMap, flattenPackageCoverageMap, data, rootPackageVMName, annotator, module, suite.isTrackTestFolders(), true);
}
}
}
}
for (Map.Entry<String, PackageCoverageInfo> entry : packageCoverageMap.entrySet()) {
final String packageFQName = entry.getKey().replaceAll("/", ".");
final PackageCoverageInfo info = entry.getValue();
annotator.annotatePackage(packageFQName, info);
}
for (Map.Entry<String, PackageCoverageInfo> entry : flattenPackageCoverageMap.entrySet()) {
final String packageFQName = entry.getKey().replaceAll("/", ".");
final PackageCoverageInfo info = entry.getValue();
annotator.annotatePackage(packageFQName, info, true);
}
}
use of com.intellij.util.containers.HashMap in project intellij-community by JetBrains.
the class Converter01 method convert.
/**
* Converts keymap from version "0" (no version specified)
* to version "1".
* @param keymapElement XML element that corresponds to "keymap" tag.
*/
public static void convert(Element keymapElement) throws InvalidDataException {
if (!KEY_MAP.equals(keymapElement.getName())) {
throw new IllegalArgumentException(UNKNOWN_ELEMENT + keymapElement);
}
String version = keymapElement.getAttributeValue(VERSION);
if (version != null) {
throw new InvalidDataException(UNKNOWN_VERSION + version);
}
// Add version
keymapElement.setAttribute(VERSION, Integer.toString(1));
// disableMnemonics -> disable-mnemonics
boolean disableMnemonics = Boolean.valueOf(DISABLE_MNEMONICS).booleanValue();
keymapElement.removeAttribute(DISABLE_MNEMONICS);
keymapElement.setAttribute(DISABLE_MNEMONICS_ATTRIBUTE, Boolean.toString(disableMnemonics));
// Now we have to separate all shortcuts by action's ID and convert binding to keyboard-shortcut
String name = keymapElement.getAttributeValue(NAME_ATTRIBUTE);
if (name == null) {
throw new InvalidDataException("Attribute 'name' of <keymap> must be specified");
}
HashMap id2elements = new HashMap();
for (Iterator i = keymapElement.getChildren().iterator(); i.hasNext(); ) {
Element oldChild = (Element) i.next();
if (BINDING.equals(oldChild.getName())) {
// binding -> keyboard-shortcut
// Remove attribute "id"
String id = oldChild.getAttributeValue(ID_ATTRIBUTE);
if (id == null) {
throw new InvalidDataException("attribute 'id' must be specified");
}
// keystroke -> first-keystroke
String keystroke = oldChild.getAttributeValue(KEYSTROKE_ATTRIBUTE);
// suffix -> second-keystroke
String suffix = oldChild.getAttributeValue(SUFFIX_ATTRIBUTE);
if (keystroke != null) {
Element newChild = new Element(KEYBOARD_SHORTCUT);
newChild.setAttribute(FIRST_KEYSTROKE_ATTRIBUTE, keystroke);
if (suffix != null) {
newChild.setAttribute(SECOND_KEYSTROKE_ATTRIBUTE, suffix);
}
// Put new child into the map
ArrayList elements = (ArrayList) id2elements.get(id);
if (elements == null) {
elements = new ArrayList(2);
id2elements.put(id, elements);
}
elements.add(newChild);
} else {
id2elements.put(id, new ArrayList(0));
}
// Remove old child
i.remove();
} else if (MOUSE_SHORTCUT.equals(oldChild.getName())) {
// Remove attribute "id"
String id = oldChild.getAttributeValue(ID_ATTRIBUTE);
if (id == null) {
throw new InvalidDataException("Attribute 'id' of <mouse-shortcut> must be specified; keymap name=" + name);
}
oldChild.removeAttribute(ID_ATTRIBUTE);
// Remove old child
i.remove();
// Put new child into the map
ArrayList elements = (ArrayList) id2elements.get(id);
if (elements == null) {
elements = new ArrayList(2);
id2elements.put(id, elements);
}
elements.add(oldChild);
} else {
throw new InvalidDataException("unknown element : " + oldChild.getName());
}
}
for (Iterator i = id2elements.keySet().iterator(); i.hasNext(); ) {
String id = (String) i.next();
Element actionElement = new Element(ACTION);
actionElement.setAttribute(ID_ATTRIBUTE, id);
ArrayList elements = (ArrayList) id2elements.get(id);
for (Iterator j = elements.iterator(); j.hasNext(); ) {
Element newChild = (Element) j.next();
actionElement.addContent(newChild);
}
keymapElement.addContent(actionElement);
}
}
use of com.intellij.util.containers.HashMap in project intellij-community by JetBrains.
the class CopyrightProfilesPanel method getAllProfiles.
public Map<String, CopyrightProfile> getAllProfiles() {
final Map<String, CopyrightProfile> profiles = new HashMap<>();
if (!myInitialized.get()) {
for (CopyrightProfile profile : myManager.getCopyrights()) {
profiles.put(profile.getName(), profile);
}
} else {
for (int i = 0; i < myRoot.getChildCount(); i++) {
MyNode node = (MyNode) myRoot.getChildAt(i);
final CopyrightProfile copyrightProfile = ((CopyrightConfigurable) node.getConfigurable()).getEditableObject();
profiles.put(copyrightProfile.getName(), copyrightProfile);
}
}
return profiles;
}
use of com.intellij.util.containers.HashMap in project intellij-community by JetBrains.
the class InvertBooleanProcessor method findUsages.
@Override
@NotNull
protected UsageInfo[] findUsages() {
final List<SmartPsiElementPointer> toInvert = new ArrayList<>();
final LinkedHashSet<PsiElement> elementsToInvert = new LinkedHashSet<>();
myDelegate.collectRefElements(myElement, myRenameProcessor, myNewName, elementsToInvert);
for (PsiElement element : elementsToInvert) {
toInvert.add(mySmartPointerManager.createSmartPsiElementPointer(element));
}
final UsageInfo[] renameUsages = myRenameProcessor != null ? myRenameProcessor.findUsages() : UsageInfo.EMPTY_ARRAY;
final SmartPsiElementPointer[] usagesToInvert = toInvert.toArray(new SmartPsiElementPointer[toInvert.size()]);
//merge rename and invert usages
Map<PsiElement, UsageInfo> expressionsToUsages = new HashMap<>();
List<UsageInfo> result = new ArrayList<>();
for (UsageInfo renameUsage : renameUsages) {
expressionsToUsages.put(renameUsage.getElement(), renameUsage);
result.add(renameUsage);
}
for (SmartPsiElementPointer pointer : usagesToInvert) {
final PsiElement expression = pointer.getElement();
if (!expressionsToUsages.containsKey(expression)) {
final UsageInfo usageInfo = new UsageInfo(expression);
expressionsToUsages.put(expression, usageInfo);
//fake UsageInfo
result.add(usageInfo);
myToInvert.put(usageInfo, pointer);
} else {
myToInvert.put(expressionsToUsages.get(expression), pointer);
}
}
return result.toArray(new UsageInfo[result.size()]);
}
use of com.intellij.util.containers.HashMap in project intellij-community by JetBrains.
the class RenameUtil method renameNonCodeUsages.
public static void renameNonCodeUsages(@NotNull Project project, @NotNull NonCodeUsageInfo[] usages) {
PsiDocumentManager.getInstance(project).commitAllDocuments();
Map<Document, List<UsageOffset>> docsToOffsetsMap = new HashMap<>();
final PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(project);
for (NonCodeUsageInfo usage : usages) {
PsiElement element = usage.getElement();
if (element == null)
continue;
element = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(element, true);
if (element == null)
continue;
final ProperTextRange rangeInElement = usage.getRangeInElement();
if (rangeInElement == null)
continue;
final PsiFile containingFile = element.getContainingFile();
final Document document = psiDocumentManager.getDocument(containingFile);
final Segment segment = usage.getSegment();
LOG.assertTrue(segment != null);
int fileOffset = segment.getStartOffset();
List<UsageOffset> list = docsToOffsetsMap.get(document);
if (list == null) {
list = new ArrayList<>();
docsToOffsetsMap.put(document, list);
}
list.add(new UsageOffset(fileOffset, fileOffset + rangeInElement.getLength(), usage.newText));
}
for (Document document : docsToOffsetsMap.keySet()) {
List<UsageOffset> list = docsToOffsetsMap.get(document);
LOG.assertTrue(list != null, document);
UsageOffset[] offsets = list.toArray(new UsageOffset[list.size()]);
Arrays.sort(offsets);
for (int i = offsets.length - 1; i >= 0; i--) {
UsageOffset usageOffset = offsets[i];
document.replaceString(usageOffset.startOffset, usageOffset.endOffset, usageOffset.newText);
}
PsiDocumentManager.getInstance(project).commitDocument(document);
}
PsiDocumentManager.getInstance(project).commitAllDocuments();
}
Aggregations