use of com.intellij.xdebugger.frame.presentation.XValuePresentation in project intellij-community by JetBrains.
the class XDebuggerEditorLinePainter method getLineExtensions.
@Override
public Collection<LineExtensionInfo> getLineExtensions(@NotNull Project project, @NotNull VirtualFile file, int lineNumber) {
if (!XDebuggerSettingsManager.getInstance().getDataViewSettings().isShowValuesInline()) {
return null;
}
XVariablesView.InlineVariablesInfo data = project.getUserData(XVariablesView.DEBUG_VARIABLES);
final Document doc = FileDocumentManager.getInstance().getDocument(file);
if (data == null || doc == null) {
return null;
}
Map<Variable, VariableValue> oldValues = project.getUserData(CACHE);
if (oldValues == null) {
oldValues = new HashMap<>();
project.putUserData(CACHE, oldValues);
}
List<XValueNodeImpl> values = data.get(file, lineNumber, doc.getModificationStamp());
if (values != null && !values.isEmpty()) {
XDebugSession session = XDebugView.getSession(values.iterator().next().getTree());
final int bpLine = getCurrentBreakPointLineInFile(session, file);
boolean isTopFrame = session instanceof XDebugSessionImpl && ((XDebugSessionImpl) session).isTopFrameSelected();
final TextAttributes attributes = bpLine == lineNumber && isTopFrame && ((XDebuggerManagerImpl) XDebuggerManager.getInstance(project)).isFullLineHighlighter() ? getTopFrameSelectedAttributes() : getNormalAttributes();
ArrayList<VariableText> result = new ArrayList<>();
for (XValueNodeImpl value : values) {
SimpleColoredText text = new SimpleColoredText();
XValueTextRendererImpl renderer = new XValueTextRendererImpl(text);
final XValuePresentation presentation = value.getValuePresentation();
if (presentation == null)
continue;
try {
if (presentation instanceof XValueCompactPresentation && !value.getTree().isUnderRemoteDebug()) {
((XValueCompactPresentation) presentation).renderValue(renderer, value);
} else {
presentation.renderValue(renderer);
}
if (StringUtil.isEmpty(text.toString())) {
final String type = value.getValuePresentation().getType();
if (!StringUtil.isEmpty(type)) {
text.append(type, SimpleTextAttributes.REGULAR_ATTRIBUTES);
}
}
} catch (Exception ignored) {
continue;
}
final String name = value.getName();
if (StringUtil.isEmpty(text.toString())) {
continue;
}
final VariableText res = new VariableText();
result.add(res);
res.add(new LineExtensionInfo(" " + name + ": ", attributes));
Variable var = new Variable(name, lineNumber);
VariableValue variableValue = oldValues.computeIfAbsent(var, k -> new VariableValue(text.toString(), null, value.hashCode()));
if (variableValue.valueNodeHashCode != value.hashCode()) {
variableValue.old = variableValue.actual;
variableValue.actual = text.toString();
variableValue.valueNodeHashCode = value.hashCode();
}
if (!variableValue.isChanged()) {
for (String s : text.getTexts()) {
res.add(new LineExtensionInfo(s, attributes));
}
} else {
variableValue.produceChangedParts(res.infos);
}
}
final List<LineExtensionInfo> infos = new ArrayList<>();
for (VariableText text : result) {
infos.addAll(text.infos);
}
return infos.size() > LINE_EXTENSIONS_MAX_COUNT ? infos.subList(0, LINE_EXTENSIONS_MAX_COUNT) : infos;
}
return null;
}
Aggregations