use of com.intellij.util.containers.HashMap in project intellij-community by JetBrains.
the class ColorSettingsUtil method keyToDisplayTextMap.
public static Map<TextAttributesKey, String> keyToDisplayTextMap(final ColorSettingsPage page) {
final List<AttributesDescriptor> attributeDescriptors = getAllAttributeDescriptors(page);
final Map<TextAttributesKey, String> displayText = new HashMap<>();
for (AttributesDescriptor attributeDescriptor : attributeDescriptors) {
final TextAttributesKey key = attributeDescriptor.getKey();
displayText.put(key, attributeDescriptor.getDisplayName());
}
return displayText;
}
use of com.intellij.util.containers.HashMap in project intellij-community by JetBrains.
the class GlobalInspectionContextImpl method exportResults.
private void exportResults(@NotNull List<File> inspectionsResults, @Nullable String outputPath) {
@NonNls final String ext = ".xml";
final Map<Element, Tools> globalTools = new HashMap<>();
for (Map.Entry<String, Tools> entry : getTools().entrySet()) {
final Tools sameTools = entry.getValue();
boolean hasProblems = false;
String toolName = entry.getKey();
if (sameTools != null) {
for (ScopeToolState toolDescr : sameTools.getTools()) {
InspectionToolWrapper toolWrapper = toolDescr.getTool();
if (toolWrapper instanceof LocalInspectionToolWrapper) {
hasProblems = new File(outputPath, toolName + ext).exists();
} else {
InspectionToolPresentation presentation = getPresentation(toolWrapper);
presentation.updateContent();
if (presentation.hasReportedProblems()) {
final Element root = new Element(InspectionsBundle.message("inspection.problems"));
globalTools.put(root, sameTools);
LOG.assertTrue(!hasProblems, toolName);
break;
}
}
}
}
if (hasProblems) {
try {
new File(outputPath).mkdirs();
final File file = new File(outputPath, toolName + ext);
inspectionsResults.add(file);
FileUtil.writeToFile(file, ("</" + InspectionsBundle.message("inspection.problems") + ">").getBytes(CharsetToolkit.UTF8_CHARSET), true);
} catch (IOException e) {
LOG.error(e);
}
}
}
getRefManager().iterate(new RefVisitor() {
@Override
public void visitElement(@NotNull final RefEntity refEntity) {
for (Map.Entry<Element, Tools> entry : globalTools.entrySet()) {
Tools tools = entry.getValue();
Element element = entry.getKey();
for (ScopeToolState state : tools.getTools()) {
try {
InspectionToolWrapper toolWrapper = state.getTool();
InspectionToolPresentation presentation = getPresentation(toolWrapper);
presentation.exportResults(element, refEntity, d -> false);
} catch (Throwable e) {
LOG.error("Problem when exporting: " + refEntity.getExternalName(), e);
}
}
}
}
});
for (Map.Entry<Element, Tools> entry : globalTools.entrySet()) {
final String toolName = entry.getValue().getShortName();
Element element = entry.getKey();
element.setAttribute(LOCAL_TOOL_ATTRIBUTE, Boolean.toString(false));
final org.jdom.Document doc = new org.jdom.Document(element);
PathMacroManager.getInstance(getProject()).collapsePaths(doc.getRootElement());
try {
new File(outputPath).mkdirs();
final File file = new File(outputPath, toolName + ext);
inspectionsResults.add(file);
try (OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(file), CharsetToolkit.UTF8_CHARSET)) {
JDOMUtil.writeDocument(doc, writer, "\n");
}
} catch (IOException e) {
LOG.error(e);
}
}
}
use of com.intellij.util.containers.HashMap in project intellij-community by JetBrains.
the class AbstractListBuilder method updateList.
protected final void updateList() {
if (myIsDisposed || myCurrentParent == null) {
return;
}
if (myTreeStructure.hasSomethingToCommit()) {
myTreeStructure.commit();
}
AbstractTreeNode parentDescriptor = myCurrentParent;
while (true) {
parentDescriptor.update();
if (parentDescriptor.getValue() != null)
break;
parentDescriptor = parentDescriptor.getParent();
}
final Object[] children = getChildren(parentDescriptor);
final HashMap<Object, Integer> elementToIndexMap = new HashMap<>();
for (int i = 0; i < children.length; i++) {
elementToIndexMap.put(children[i], Integer.valueOf(i));
}
final List<NodeDescriptor> resultDescriptors = new ArrayList<>();
final Object[] listChildren = myModel.toArray();
for (final Object child : listChildren) {
if (!(child instanceof NodeDescriptor)) {
continue;
}
final NodeDescriptor descriptor = (NodeDescriptor) child;
descriptor.update();
final Object newElement = descriptor.getElement();
final Integer index = newElement != null ? elementToIndexMap.get(newElement) : null;
if (index != null) {
resultDescriptors.add(descriptor);
descriptor.setIndex(index.intValue());
elementToIndexMap.remove(newElement);
}
}
for (final Object child : elementToIndexMap.keySet()) {
final Integer index = elementToIndexMap.get(child);
if (index != null) {
final NodeDescriptor childDescr = myTreeStructure.createDescriptor(child, parentDescriptor);
childDescr.setIndex(index.intValue());
childDescr.update();
resultDescriptors.add(childDescr);
}
}
final SelectionInfo selection = storeSelection();
if (myComparator != null) {
Collections.sort(resultDescriptors, myComparator);
} else {
Collections.sort(resultDescriptors, IndexComparator.INSTANCE);
}
if (shouldAddTopElement()) {
final List elems = new ArrayList();
elems.add(new TopLevelNode(myProject, parentDescriptor.getValue()));
elems.addAll(resultDescriptors);
myModel.replaceElements(elems);
} else {
myModel.replaceElements(resultDescriptors);
}
restoreSelection(selection);
updateParentTitle();
}
use of com.intellij.util.containers.HashMap in project intellij-community by JetBrains.
the class EncapsulateFieldsProcessor method processUsagesPerFile.
private void processUsagesPerFile(UsageInfo[] usages) {
Map<PsiFile, List<EncapsulateFieldUsageInfo>> usagesInFiles = new HashMap<>();
for (UsageInfo usage : usages) {
PsiElement element = usage.getElement();
if (element == null)
continue;
final PsiFile file = element.getContainingFile();
List<EncapsulateFieldUsageInfo> usagesInFile = usagesInFiles.get(file);
if (usagesInFile == null) {
usagesInFile = new ArrayList<>();
usagesInFiles.put(file, usagesInFile);
}
usagesInFile.add(((EncapsulateFieldUsageInfo) usage));
}
for (List<EncapsulateFieldUsageInfo> usageInfos : usagesInFiles.values()) {
//this is to avoid elements to become invalid as a result of processUsage
final EncapsulateFieldUsageInfo[] infos = usageInfos.toArray(new EncapsulateFieldUsageInfo[usageInfos.size()]);
CommonRefactoringUtil.sortDepthFirstRightLeftOrder(infos);
for (EncapsulateFieldUsageInfo info : infos) {
final PsiElement element = info.getElement();
if (element == null)
continue;
EncapsulateFieldHelper helper = EncapsulateFieldHelper.getHelper(element.getLanguage());
helper.processUsage(info, myDescriptor, myNameToSetter.get(info.getFieldDescriptor().getSetterName()), myNameToGetter.get(info.getFieldDescriptor().getGetterName()));
}
}
}
use of com.intellij.util.containers.HashMap in project intellij-community by JetBrains.
the class JavaDirectInheritorsSearcher method calculateDirectSubClasses.
@NotNull
private static PsiClass[] calculateDirectSubClasses(@NotNull Project project, @NotNull PsiClass baseClass, @NotNull String baseClassName, @NotNull SearchScope useScope) {
DumbService dumbService = DumbService.getInstance(project);
GlobalSearchScope globalUseScope = dumbService.runReadActionInSmartMode(() -> StubHierarchyInheritorSearcher.restrictScope(GlobalSearchScopeUtil.toGlobalSearchScope(useScope, project)));
Collection<PsiReferenceList> candidates = dumbService.runReadActionInSmartMode(() -> JavaSuperClassNameOccurenceIndex.getInstance().get(baseClassName, project, globalUseScope));
// memory/speed optimisation: it really is a map(string -> PsiClass or List<PsiClass>)
final Map<String, Object> classesWithFqn = new HashMap<>();
processConcurrentlyIfTooMany(candidates, referenceList -> {
ProgressManager.checkCanceled();
ApplicationManager.getApplication().runReadAction(() -> {
final PsiClass candidate = (PsiClass) referenceList.getParent();
boolean isInheritor = candidate.isInheritor(baseClass, false);
if (isInheritor) {
String fqn = candidate.getQualifiedName();
synchronized (classesWithFqn) {
Object value = classesWithFqn.get(fqn);
if (value == null) {
classesWithFqn.put(fqn, candidate);
} else if (value instanceof PsiClass) {
List<PsiClass> list = new ArrayList<>();
list.add((PsiClass) value);
list.add(candidate);
classesWithFqn.put(fqn, list);
} else {
@SuppressWarnings("unchecked") List<PsiClass> list = (List<PsiClass>) value;
list.add(candidate);
}
}
}
});
return true;
});
final List<PsiClass> result = new ArrayList<>();
for (Object value : classesWithFqn.values()) {
if (value instanceof PsiClass) {
result.add((PsiClass) value);
} else {
@SuppressWarnings("unchecked") List<PsiClass> list = (List<PsiClass>) value;
result.addAll(list);
}
}
Collection<PsiAnonymousClass> anonymousCandidates = dumbService.runReadActionInSmartMode(() -> JavaAnonymousClassBaseRefOccurenceIndex.getInstance().get(baseClassName, project, globalUseScope));
processConcurrentlyIfTooMany(anonymousCandidates, candidate -> {
boolean isInheritor = dumbService.runReadActionInSmartMode(() -> candidate.isInheritor(baseClass, false));
if (isInheritor) {
synchronized (result) {
result.add(candidate);
}
}
return true;
});
boolean isEnum = ReadAction.compute(baseClass::isEnum);
if (isEnum) {
// abstract enum can be subclassed in the body
PsiField[] fields = ReadAction.compute(baseClass::getFields);
for (final PsiField field : fields) {
ProgressManager.checkCanceled();
if (field instanceof PsiEnumConstant) {
PsiEnumConstantInitializer initializingClass = ReadAction.compute(((PsiEnumConstant) field)::getInitializingClass);
if (initializingClass != null) {
// it surely is an inheritor
result.add(initializingClass);
}
}
}
}
return result.isEmpty() ? PsiClass.EMPTY_ARRAY : result.toArray(new PsiClass[result.size()]);
}
Aggregations