use of com.intellij.debugger.SourcePosition in project intellij-community by JetBrains.
the class RuntimeTypeEvaluator method evaluate.
@Nullable
protected PsiType evaluate(final EvaluationContextImpl evaluationContext) throws EvaluateException {
Project project = evaluationContext.getProject();
SourcePosition position = ContextUtil.getSourcePosition(evaluationContext);
ExpressionEvaluator evaluator = DebuggerInvocationUtil.commitAndRunReadAction(project, new EvaluatingComputable<ExpressionEvaluator>() {
public ExpressionEvaluator compute() throws EvaluateException {
return EvaluatorBuilderImpl.getInstance().build(myElement, position);
}
});
final Value value = evaluator.evaluate(evaluationContext);
if (value != null) {
return getCastableRuntimeType(project, value);
}
throw EvaluateExceptionUtil.createEvaluateException(DebuggerBundle.message("evaluation.error.surrounded.expression.null"));
}
use of com.intellij.debugger.SourcePosition in project intellij-community by JetBrains.
the class BasicStepMethodFilter method locationMatches.
public boolean locationMatches(final DebugProcessImpl process, final Location location) throws EvaluateException {
Method method = location.method();
String name = method.name();
if (!myTargetMethodName.equals(name)) {
if (DebuggerUtilsEx.isLambdaName(name)) {
SourcePosition position = process.getPositionManager().getSourcePosition(location);
return ReadAction.compute(() -> {
PsiElement psiMethod = DebuggerUtilsEx.getContainingMethod(position);
if (psiMethod instanceof PsiLambdaExpression) {
PsiType type = ((PsiLambdaExpression) psiMethod).getFunctionalInterfaceType();
PsiMethod interfaceMethod = LambdaUtil.getFunctionalInterfaceMethod(type);
if (type != null && interfaceMethod != null && myTargetMethodName.equals(interfaceMethod.getName())) {
try {
return InheritanceUtil.isInheritor(type, myDeclaringClassName.getName(process).replace('$', '.'));
} catch (EvaluateException e) {
LOG.info(e);
}
}
}
return false;
});
}
return false;
}
if (myTargetMethodSignature != null && !signatureMatches(method, myTargetMethodSignature.getName(process))) {
return false;
}
if (method.isBridge()) {
// skip bridge methods
return false;
}
return DebuggerUtilsEx.isAssignableFrom(myDeclaringClassName.getName(process), location.declaringType());
}
use of com.intellij.debugger.SourcePosition 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.SourcePosition in project intellij-community by JetBrains.
the class JavaValueModifier method set.
protected void set(@NotNull final String expression, final XModificationCallback callback, final DebuggerContextImpl debuggerContext, final SetValueRunnable setValueRunnable) {
final ProgressWindowWithNotification progressWindow = new ProgressWindowWithNotification(true, debuggerContext.getProject());
final EvaluationContextImpl evaluationContext = myJavaValue.getEvaluationContext();
SuspendContextCommandImpl askSetAction = new DebuggerContextCommandImpl(debuggerContext) {
public Priority getPriority() {
return Priority.HIGH;
}
public void threadAction(@NotNull SuspendContextImpl suspendContext) {
ExpressionEvaluator evaluator;
try {
Project project = evaluationContext.getProject();
SourcePosition position = ContextUtil.getSourcePosition(evaluationContext);
PsiElement context = ContextUtil.getContextElement(evaluationContext, position);
evaluator = DebuggerInvocationUtil.commitAndRunReadAction(project, new EvaluatingComputable<ExpressionEvaluator>() {
public ExpressionEvaluator compute() throws EvaluateException {
return EvaluatorBuilderImpl.build(new TextWithImportsImpl(CodeFragmentKind.EXPRESSION, expression), context, position, project);
}
});
setValue(expression, evaluator, evaluationContext, new SetValueRunnable() {
public void setValue(EvaluationContextImpl evaluationContext, Value newValue) throws ClassNotLoadedException, InvalidTypeException, EvaluateException, IncompatibleThreadStateException {
if (!progressWindow.isCanceled()) {
setValueRunnable.setValue(evaluationContext, newValue);
//node.calcValue();
}
}
public ReferenceType loadClass(EvaluationContextImpl evaluationContext, String className) throws InvocationException, ClassNotLoadedException, EvaluateException, IncompatibleThreadStateException, InvalidTypeException {
return setValueRunnable.loadClass(evaluationContext, className);
}
});
callback.valueModified();
} catch (EvaluateException e) {
callback.errorOccurred(e.getMessage());
}
//String initialString = "";
//if (descriptor instanceof ValueDescriptorImpl) {
// Value currentValue = ((ValueDescriptorImpl) descriptor).getValue();
// if (currentValue instanceof StringReference) {
// initialString = DebuggerUtilsEx.getValueOrErrorAsString(debuggerContext.createEvaluationContext(), currentValue);
// initialString = initialString == null ? "" : "\"" + DebuggerUtilsEx.translateStringValue(initialString) + "\"";
// }
// else if (currentValue instanceof PrimitiveValue) {
// ValueLabelRenderer renderer = ((ValueDescriptorImpl) descriptor).getRenderer(debuggerContext.getDebugProcess());
// initialString = getDisplayableString((PrimitiveValue) currentValue, renderer instanceof NodeRenderer && HexRenderer.UNIQUE_ID.equals(renderer.getUniqueId()));
// }
//
// final String initialString1 = initialString;
// final Project project = debuggerContext.getProject();
// DebuggerInvocationUtil.swingInvokeLater(project, new Runnable() {
// public void run() {
// showEditor(new TextWithImportsImpl(CodeFragmentKind.EXPRESSION, initialString1), node, debuggerContext, setValueRunnable);
// }
// });
//}
}
};
progressWindow.setTitle(DebuggerBundle.message("title.evaluating"));
evaluationContext.getDebugProcess().getManagerThread().startProgress(askSetAction, progressWindow);
}
use of com.intellij.debugger.SourcePosition in project intellij-community by JetBrains.
the class CompilingEvaluator method evaluate.
@Override
public Value evaluate(final EvaluationContext evaluationContext) throws EvaluateException {
DebugProcess process = evaluationContext.getDebugProcess();
EvaluationContextImpl autoLoadContext = ((EvaluationContextImpl) evaluationContext).createEvaluationContext(evaluationContext.getThisObject());
autoLoadContext.setAutoLoadClasses(true);
ClassLoaderReference classLoader = ClassLoadingUtils.getClassLoader(autoLoadContext, process);
autoLoadContext.setClassLoader(classLoader);
String version = ((VirtualMachineProxyImpl) process.getVirtualMachineProxy()).version();
Collection<ClassObject> classes = compile(JdkVersionUtil.getVersion(version));
defineClasses(classes, autoLoadContext, process, classLoader);
try {
// invoke base evaluator on call code
SourcePosition position = ContextUtil.getSourcePosition(evaluationContext);
ExpressionEvaluator evaluator = DebuggerInvocationUtil.commitAndRunReadAction(myProject, new EvaluatingComputable<ExpressionEvaluator>() {
@Override
public ExpressionEvaluator compute() throws EvaluateException {
TextWithImports callCode = getCallCode();
PsiElement copyContext = myData.getAnchor();
CodeFragmentFactory factory = DebuggerUtilsEx.findAppropriateCodeFragmentFactory(callCode, copyContext);
return factory.getEvaluatorBuilder().build(factory.createCodeFragment(callCode, copyContext, myProject), position);
}
});
return evaluator.evaluate(autoLoadContext);
} catch (Exception e) {
throw new EvaluateException("Error during generated code invocation " + e, e);
}
}
Aggregations