use of com.intellij.util.containers.HashMap in project intellij-community by JetBrains.
the class GenericInlineHandler method initializeInliners.
public static Map<Language, InlineHandler.Inliner> initializeInliners(PsiElement element, InlineHandler.Settings settings, Collection<? extends PsiReference> allReferences) {
final Map<Language, InlineHandler.Inliner> inliners = new HashMap<>();
for (PsiReference ref : allReferences) {
if (ref == null) {
LOG.error("element: " + element.getClass() + ", allReferences contains null!");
continue;
}
PsiElement refElement = ref.getElement();
LOG.assertTrue(refElement != null, ref.getClass().getName());
final Language language = refElement.getLanguage();
if (inliners.containsKey(language))
continue;
final List<InlineHandler> handlers = InlineHandlers.getInlineHandlers(language);
for (InlineHandler handler : handlers) {
InlineHandler.Inliner inliner = handler.createInliner(element, settings);
if (inliner != null) {
inliners.put(language, inliner);
break;
}
}
}
return inliners;
}
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 TurnRefsToSuperProcessorBase method performVariablesRenaming.
protected void performVariablesRenaming() {
try {
//forget about smart pointers
Map<PsiElement, String> variableRenames = new HashMap<>();
for (Map.Entry<SmartPsiElementPointer, String> entry : myVariablesRenames.entrySet()) {
variableRenames.put(entry.getKey().getElement(), entry.getValue());
}
for (UsageInfo usage : myVariablesUsages) {
if (usage instanceof MoveRenameUsageInfo) {
final MoveRenameUsageInfo renameUsageInfo = ((MoveRenameUsageInfo) usage);
final String newName = variableRenames.get(renameUsageInfo.getUpToDateReferencedElement());
final PsiReference reference = renameUsageInfo.getReference();
if (reference != null) {
reference.handleElementRename(newName);
}
}
}
for (Map.Entry<SmartPsiElementPointer, String> entry : myVariablesRenames.entrySet()) {
final String newName = entry.getValue();
if (newName != null) {
final PsiVariable variable = (PsiVariable) entry.getKey().getElement();
variable.setName(newName);
}
}
} catch (IncorrectOperationException e) {
LOG.error(e);
}
}
use of com.intellij.util.containers.HashMap in project intellij-community by JetBrains.
the class RefactoringUtil method fixJavadocsForParams.
public static void fixJavadocsForParams(PsiMethod method, Set<PsiParameter> newParameters, Condition<Pair<PsiParameter, String>> eqCondition, Condition<String> matchedToOldParam) throws IncorrectOperationException {
final PsiDocComment docComment = method.getDocComment();
if (docComment == null)
return;
final PsiParameter[] parameters = method.getParameterList().getParameters();
final PsiDocTag[] paramTags = docComment.findTagsByName("param");
if (parameters.length > 0 && newParameters.size() < parameters.length && paramTags.length == 0)
return;
Map<PsiParameter, PsiDocTag> tagForParam = new HashMap<>();
for (PsiParameter parameter : parameters) {
boolean found = false;
for (PsiDocTag paramTag : paramTags) {
if (parameter.getName().equals(getNameOfReferencedParameter(paramTag))) {
tagForParam.put(parameter, paramTag);
found = true;
break;
}
}
if (!found) {
for (PsiDocTag paramTag : paramTags) {
final String paramName = getNameOfReferencedParameter(paramTag);
if (eqCondition.value(Pair.create(parameter, paramName))) {
tagForParam.put(parameter, paramTag);
found = true;
break;
}
}
}
if (!found && !newParameters.contains(parameter)) {
tagForParam.put(parameter, null);
}
}
List<PsiDocTag> newTags = new ArrayList<>();
for (PsiDocTag paramTag : paramTags) {
final String paramName = getNameOfReferencedParameter(paramTag);
if (!tagForParam.containsValue(paramTag) && !matchedToOldParam.value(paramName)) {
newTags.add((PsiDocTag) paramTag.copy());
}
}
for (PsiParameter parameter : parameters) {
if (tagForParam.containsKey(parameter)) {
final PsiDocTag psiDocTag = tagForParam.get(parameter);
if (psiDocTag != null) {
final PsiDocTag copy = (PsiDocTag) psiDocTag.copy();
final PsiDocTagValue valueElement = copy.getValueElement();
if (valueElement != null) {
valueElement.replace(createParamTag(parameter).getValueElement());
}
newTags.add(copy);
}
} else {
newTags.add(createParamTag(parameter));
}
}
PsiElement anchor = paramTags.length > 0 ? paramTags[0].getPrevSibling() : null;
for (PsiDocTag paramTag : paramTags) {
paramTag.delete();
}
for (PsiDocTag psiDocTag : newTags) {
anchor = anchor != null && anchor.isValid() ? docComment.addAfter(psiDocTag, anchor) : docComment.add(psiDocTag);
}
}
Aggregations