use of com.intellij.debugger.engine.evaluation.TextWithImports in project intellij-community by JetBrains.
the class JavaStackFrame method buildVariables.
// copied from FrameVariablesTree
private void buildVariables(DebuggerContextImpl debuggerContext, final EvaluationContextImpl evaluationContext, @NotNull DebugProcessImpl debugProcess, XValueChildrenList children, ObjectReference thisObjectReference, Location location) throws EvaluateException {
final Set<String> visibleLocals = new HashSet<>();
if (NodeRendererSettings.getInstance().getClassRenderer().SHOW_VAL_FIELDS_AS_LOCAL_VARIABLES) {
if (thisObjectReference != null && debugProcess.getVirtualMachineProxy().canGetSyntheticAttribute()) {
final ReferenceType thisRefType = thisObjectReference.referenceType();
if (thisRefType instanceof ClassType && location != null && thisRefType.equals(location.declaringType()) && thisRefType.name().contains("$")) {
// makes sense for nested classes only
for (Field field : thisRefType.fields()) {
if (DebuggerUtils.isSynthetic(field) && StringUtil.startsWith(field.name(), FieldDescriptorImpl.OUTER_LOCAL_VAR_FIELD_PREFIX)) {
final FieldDescriptorImpl fieldDescriptor = myNodeManager.getFieldDescriptor(myDescriptor, thisObjectReference, field);
children.add(JavaValue.create(fieldDescriptor, evaluationContext, myNodeManager));
visibleLocals.add(fieldDescriptor.calcValueName());
}
}
}
}
}
boolean myAutoWatchMode = DebuggerSettings.getInstance().AUTO_VARIABLES_MODE;
if (evaluationContext == null) {
return;
}
try {
if (!XDebuggerSettingsManager.getInstance().getDataViewSettings().isAutoExpressions() && !myAutoWatchMode) {
// optimization
superBuildVariables(evaluationContext, children);
} else {
final SourcePosition sourcePosition = debuggerContext.getSourcePosition();
final Map<String, LocalVariableProxyImpl> visibleVariables = ContainerUtil.map2Map(getVisibleVariables(), var -> Pair.create(var.name(), var));
Pair<Set<String>, Set<TextWithImports>> usedVars = EMPTY_USED_VARS;
if (sourcePosition != null) {
usedVars = ApplicationManager.getApplication().runReadAction(new Computable<Pair<Set<String>, Set<TextWithImports>>>() {
@Override
public Pair<Set<String>, Set<TextWithImports>> compute() {
return findReferencedVars(ContainerUtil.union(visibleVariables.keySet(), visibleLocals), sourcePosition);
}
});
}
// add locals
if (myAutoWatchMode) {
for (String var : usedVars.first) {
LocalVariableProxyImpl local = visibleVariables.get(var);
if (local != null) {
children.add(JavaValue.create(myNodeManager.getLocalVariableDescriptor(null, local), evaluationContext, myNodeManager));
}
}
} else {
superBuildVariables(evaluationContext, children);
}
final EvaluationContextImpl evalContextCopy = evaluationContext.createEvaluationContext(evaluationContext.getThisObject());
evalContextCopy.setAutoLoadClasses(false);
if (sourcePosition != null) {
Set<TextWithImports> extraVars = computeExtraVars(usedVars, sourcePosition, evaluationContext);
// add extra vars
addToChildrenFrom(extraVars, children, evaluationContext);
}
// add expressions
addToChildrenFrom(usedVars.second, children, evalContextCopy);
}
} catch (EvaluateException e) {
if (e.getCause() instanceof AbsentInformationException) {
children.add(LOCAL_VARIABLES_INFO_UNAVAILABLE_MESSAGE_NODE);
// trying to collect values from variable slots
try {
for (Map.Entry<DecompiledLocalVariable, Value> entry : LocalVariablesUtil.fetchValues(getStackFrameProxy(), debugProcess, true).entrySet()) {
children.add(JavaValue.create(myNodeManager.getArgumentValueDescriptor(null, entry.getKey(), entry.getValue()), evaluationContext, myNodeManager));
}
} catch (Exception ex) {
LOG.info(ex);
}
} else {
throw e;
}
}
}
use of com.intellij.debugger.engine.evaluation.TextWithImports in project intellij-community by JetBrains.
the class EnumerationChildrenRenderer method readExternal.
public void readExternal(Element element) throws InvalidDataException {
super.readExternal(element);
myChildren.clear();
myAppendDefaultChildren = "true".equals(JDOMExternalizerUtil.readField(element, APPEND_DEFAULT_NAME));
List<Element> children = element.getChildren(CHILDREN_EXPRESSION);
for (Element item : children) {
String name = item.getAttributeValue(CHILD_NAME);
TextWithImports text = DebuggerUtils.getInstance().readTextWithImports(item.getChildren().get(0));
myChildren.add(Pair.create(name, text));
}
}
use of com.intellij.debugger.engine.evaluation.TextWithImports in project intellij-community by JetBrains.
the class JavaDebuggerEditorsProvider method createExpressionCodeFragment.
@Override
protected PsiFile createExpressionCodeFragment(@NotNull Project project, @NotNull XExpression expression, @Nullable PsiElement context, boolean isPhysical) {
TextWithImports text = TextWithImportsImpl.fromXExpression(expression);
if (text != null) {
CodeFragmentFactory factory = DebuggerUtilsEx.findAppropriateCodeFragmentFactory(text, context);
JavaCodeFragment codeFragment = factory.createPresentationCodeFragment(text, context, project);
if (context != null) {
PsiType contextType = context.getUserData(DebuggerUtilsImpl.PSI_TYPE_KEY);
if (contextType == null) {
PsiClass contextClass = PsiTreeUtil.getNonStrictParentOfType(context, PsiClass.class);
if (contextClass != null) {
contextType = JavaPsiFacade.getInstance(codeFragment.getProject()).getElementFactory().createType(contextClass);
}
}
codeFragment.setThisType(contextType);
}
return codeFragment;
} else {
return super.createExpressionCodeFragment(project, expression, context, isPhysical);
}
}
Aggregations