use of com.intellij.xdebugger.impl.XDebugSessionImpl 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;
}
use of com.intellij.xdebugger.impl.XDebugSessionImpl in project intellij-community by JetBrains.
the class XDebuggerEvaluationDialog method addToWatches.
private void addToWatches() {
if (myMode == EvaluationMode.EXPRESSION) {
XExpression expression = getInputEditor().getExpression();
if (!XDebuggerUtilImpl.isEmptyExpression(expression)) {
XDebugSessionTab tab = ((XDebugSessionImpl) mySession).getSessionTab();
if (tab != null) {
tab.getWatchesView().addWatchExpression(expression, -1, true);
getInputEditor().requestFocusInEditor();
}
}
}
}
use of com.intellij.xdebugger.impl.XDebugSessionImpl in project intellij-community by JetBrains.
the class XWatchesViewImpl method updateSessionData.
public void updateSessionData() {
List<XExpression> watchExpressions = ContainerUtil.newArrayList();
List<? extends WatchNode> children = myRootNode.getWatchChildren();
for (WatchNode child : children) {
watchExpressions.add(child.getExpression());
}
XDebugSession session = getSession(getTree());
XExpression[] expressions = watchExpressions.toArray(new XExpression[watchExpressions.size()]);
if (session != null) {
((XDebugSessionImpl) session).setWatchExpressions(expressions);
} else {
XDebugSessionData data = getData(XDebugSessionData.DATA_KEY, getTree());
if (data != null) {
data.setWatchExpressions(expressions);
}
}
}
use of com.intellij.xdebugger.impl.XDebugSessionImpl in project intellij-community by JetBrains.
the class XWatchesViewImpl method getExpressions.
@NotNull
private XExpression[] getExpressions() {
XDebuggerTree tree = getTree();
XDebugSession session = getSession(tree);
XExpression[] expressions;
if (session != null) {
expressions = ((XDebugSessionImpl) session).getSessionData().getWatchExpressions();
} else {
XDebuggerTreeNode root = tree.getRoot();
List<? extends WatchNode> current = root instanceof WatchesRootNode ? ((WatchesRootNode) tree.getRoot()).getWatchChildren() : Collections.emptyList();
List<XExpression> list = ContainerUtil.newArrayList();
for (WatchNode child : current) {
list.add(child.getExpression());
}
expressions = list.toArray(new XExpression[list.size()]);
}
return expressions;
}
use of com.intellij.xdebugger.impl.XDebugSessionImpl in project intellij-community by JetBrains.
the class CodeFragmentFactoryContextWrapper method wrapContext.
private PsiElement wrapContext(Project project, final PsiElement originalContext) {
if (project.isDefault())
return originalContext;
//TODO [egor] : does not work for anything other than java anyway, see IDEA-132677
if (!(myDelegate instanceof DefaultCodeFragmentFactory)) {
return originalContext;
}
PsiElement context = originalContext;
XDebugSession session = XDebuggerManager.getInstance(project).getCurrentSession();
if (session != null) {
XValueMarkers<?, ?> markers = ((XDebugSessionImpl) session).getValueMarkers();
Map<?, ValueMarkup> markupMap = markers != null ? markers.getAllMarkers() : null;
//final Map<ObjectReference, ValueMarkup> markupMap = ValueDescriptorImpl.getMarkupMap(process);
if (!ContainerUtil.isEmpty(markupMap)) {
final Pair<String, Map<String, ObjectReference>> markupVariables = createMarkupVariablesText(markupMap);
int offset = markupVariables.getFirst().length() - 1;
final TextWithImportsImpl textWithImports = new TextWithImportsImpl(CodeFragmentKind.CODE_BLOCK, markupVariables.getFirst(), "", myDelegate.getFileType());
final JavaCodeFragment codeFragment = myDelegate.createCodeFragment(textWithImports, context, project);
codeFragment.accept(new JavaRecursiveElementVisitor() {
public void visitLocalVariable(PsiLocalVariable variable) {
final String name = variable.getName();
variable.putUserData(LABEL_VARIABLE_VALUE_KEY, markupVariables.getSecond().get(name));
}
});
final PsiElement newContext = codeFragment.findElementAt(offset);
if (newContext != null) {
context = newContext;
}
}
}
return context;
}
Aggregations