use of com.intellij.debugger.engine.evaluation.EvaluateException in project intellij-community by JetBrains.
the class ThrowEvaluator method evaluate.
@Override
public Object evaluate(EvaluationContextImpl context) throws EvaluateException {
ObjectReference exception = (ObjectReference) myExceptionEvaluator.evaluate(context);
EvaluateException ex = new EvaluateException(DebuggerBundle.message("evaluation.error.method.exception", exception.referenceType().name()));
ex.setTargetException(exception);
throw ex;
}
use of com.intellij.debugger.engine.evaluation.EvaluateException 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.EvaluateException in project intellij-community by JetBrains.
the class CompilingEvaluatorImpl method compile.
@Override
@NotNull
protected Collection<ClassObject> compile(@Nullable JavaSdkVersion debuggeeVersion) throws EvaluateException {
if (myCompiledClasses == null) {
Module module = ReadAction.compute(() -> ModuleUtilCore.findModuleForPsiElement(myPsiContext));
List<String> options = new ArrayList<>();
options.add("-encoding");
options.add("UTF-8");
List<File> platformClasspath = new ArrayList<>();
List<File> classpath = new ArrayList<>();
AnnotationProcessingConfiguration profile = null;
if (module != null) {
assert myProject.equals(module.getProject()) : module + " is from another project";
profile = CompilerConfiguration.getInstance(myProject).getAnnotationProcessingConfiguration(module);
ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
for (String s : rootManager.orderEntries().compileOnly().recursively().exportedOnly().withoutSdk().getPathsList().getPathList()) {
classpath.add(new File(s));
}
for (String s : rootManager.orderEntries().compileOnly().sdkOnly().getPathsList().getPathList()) {
platformClasspath.add(new File(s));
}
}
JavaBuilder.addAnnotationProcessingOptions(options, profile);
Pair<Sdk, JavaSdkVersion> runtime = BuildManager.getJavacRuntimeSdk(myProject);
JavaSdkVersion buildRuntimeVersion = runtime.getSecond();
// if compiler or debuggee version or both are unknown, let source and target be the compiler's defaults
if (buildRuntimeVersion != null && debuggeeVersion != null) {
JavaSdkVersion minVersion = buildRuntimeVersion.ordinal() > debuggeeVersion.ordinal() ? debuggeeVersion : buildRuntimeVersion;
String sourceOption = getSourceOption(minVersion.getMaxLanguageLevel());
options.add("-source");
options.add(sourceOption);
options.add("-target");
options.add(sourceOption);
}
CompilerManager compilerManager = CompilerManager.getInstance(myProject);
File sourceFile = null;
try {
sourceFile = generateTempSourceFile(compilerManager.getJavacCompilerWorkingDir());
File srcDir = sourceFile.getParentFile();
List<File> sourcePath = Collections.emptyList();
Set<File> sources = Collections.singleton(sourceFile);
myCompiledClasses = compilerManager.compileJavaCode(options, platformClasspath, classpath, Collections.emptyList(), sourcePath, sources, srcDir);
} catch (CompilationException e) {
StringBuilder res = new StringBuilder("Compilation failed:\n");
for (CompilationException.Message m : e.getMessages()) {
if (m.getCategory() == CompilerMessageCategory.ERROR) {
res.append(m.getText()).append("\n");
}
}
throw new EvaluateException(res.toString());
} catch (Exception e) {
throw new EvaluateException(e.getMessage());
} finally {
if (sourceFile != null) {
FileUtil.delete(sourceFile);
}
}
}
return myCompiledClasses;
}
use of com.intellij.debugger.engine.evaluation.EvaluateException in project intellij-community by JetBrains.
the class DebuggerTreeNodeExpression method castToRuntimeType.
public static PsiExpression castToRuntimeType(PsiExpression expression, Value value) throws EvaluateException {
if (!(value instanceof ObjectReference)) {
return expression;
}
ReferenceType valueType = ((ObjectReference) value).referenceType();
if (valueType == null) {
return expression;
}
Project project = expression.getProject();
PsiType type = RuntimeTypeEvaluator.getCastableRuntimeType(project, value);
if (type == null) {
return expression;
}
PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(project);
String typeName = type.getCanonicalText();
try {
PsiParenthesizedExpression parenthExpression = (PsiParenthesizedExpression) elementFactory.createExpressionFromText("((" + typeName + ")expression)", null);
//noinspection ConstantConditions
((PsiTypeCastExpression) parenthExpression.getExpression()).getOperand().replace(expression);
Set<String> imports = expression.getUserData(ADDITIONAL_IMPORTS_KEY);
if (imports == null) {
imports = new SmartHashSet<>();
}
imports.add(typeName);
parenthExpression.putUserData(ADDITIONAL_IMPORTS_KEY, imports);
return parenthExpression;
} catch (IncorrectOperationException e) {
throw new EvaluateException(DebuggerBundle.message("error.invalid.type.name", typeName), e);
}
}
use of com.intellij.debugger.engine.evaluation.EvaluateException in project intellij-community by JetBrains.
the class NodeDescriptorImpl method updateRepresentationNoNotify.
protected void updateRepresentationNoNotify(EvaluationContextImpl context, DescriptorLabelListener labelListener) {
try {
try {
myEvaluateException = null;
myLabel = calcRepresentation(context, labelListener);
} catch (InconsistentDebugInfoException e) {
throw new EvaluateException(DebuggerBundle.message("error.inconsistent.debug.info"));
} catch (InvalidStackFrameException e) {
throw new EvaluateException(DebuggerBundle.message("error.invalid.stackframe"));
} catch (VMDisconnectedException e) {
throw e;
} catch (RuntimeException e) {
if (e.getCause() instanceof InterruptedException) {
throw e;
}
LOG.error(e);
throw new EvaluateException("Internal error, see logs for more details");
}
} catch (EvaluateException e) {
setFailed(e);
}
}
Aggregations