import com.intellij.xdebugger.evaluation.XInstanceEvaluator;
import com.intellij.xdebugger.frame.*;
import com.intellij.xdebugger.frame.presentation.XValuePresentation;
+import com.intellij.xdebugger.impl.breakpoints.XExpressionImpl;
import com.intellij.xdebugger.impl.evaluate.XValueCompactPresentation;
import com.intellij.xdebugger.impl.ui.XValueTextProvider;
import com.intellij.xdebugger.impl.ui.tree.XValueExtendedPresentation;
import javax.swing.*;
import java.util.ArrayList;
import java.util.List;
+import java.util.Set;
/**
* @author egor
try {
PsiExpression psiExpression = getDescriptor().getTreeEvaluation(JavaValue.this, getDebuggerContext());
if (psiExpression != null) {
- return TextWithImportsImpl.toXExpression(new TextWithImportsImpl(psiExpression));
+ XExpression res = TextWithImportsImpl.toXExpression(new TextWithImportsImpl(psiExpression));
+ // add runtime imports if any
+ Set<String> imports = psiExpression.getUserData(DebuggerTreeNodeExpression.ADDITIONAL_IMPORTS_KEY);
+ if (imports != null && res != null) {
+ if (res.getCustomInfo() != null) {
+ imports.add(res.getCustomInfo());
+ }
+ res = new XExpressionImpl(res.getExpression(), res.getLanguage(), StringUtil.join(imports, ","), res.getMode());
+ }
+ return res;
}
}
catch (EvaluateException e) {
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Computable;
+import com.intellij.openapi.util.Key;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.*;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.util.PsiUtil;
import com.intellij.util.IncorrectOperationException;
+import com.intellij.util.containers.SmartHashSet;
import com.sun.jdi.ObjectReference;
import com.sun.jdi.ReferenceType;
import com.sun.jdi.Value;
import org.jetbrains.annotations.Nullable;
+import java.util.Set;
+
/**
* User: lex
* Date: Oct 29, 2003
}
if (castNeeded) {
- howToEvaluateThis = castToRuntimeType(howToEvaluateThis, howToEvaluateThisValue, howToEvaluateThis.getContext());
+ howToEvaluateThis = castToRuntimeType(howToEvaluateThis, howToEvaluateThisValue);
}
ChangeContextUtil.encodeContextInfo(result, false);
}
try {
- return JavaPsiFacade.getInstance(howToEvaluateThis.getProject()).getElementFactory()
+ PsiExpression res = JavaPsiFacade.getInstance(howToEvaluateThis.getProject()).getElementFactory()
.createExpressionFromText(psiExpression.getText(), howToEvaluateThis.getContext());
+ res.putUserData(ADDITIONAL_IMPORTS_KEY, howToEvaluateThis.getUserData(ADDITIONAL_IMPORTS_KEY));
+ return res;
}
catch (IncorrectOperationException e) {
throw new EvaluateException(e.getMessage(), e);
}
}
- public static PsiExpression castToRuntimeType(PsiExpression expression, Value value, PsiElement contextElement) throws EvaluateException {
+ public static final Key<Set<String>> ADDITIONAL_IMPORTS_KEY = Key.create("ADDITIONAL_IMPORTS");
+
+ public static PsiExpression castToRuntimeType(PsiExpression expression, Value value) throws EvaluateException {
if (!(value instanceof ObjectReference)) {
return expression;
}
}
PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(project);
+ String typeName = type.getQualifiedName();
try {
PsiParenthesizedExpression parenthExpression = (PsiParenthesizedExpression)elementFactory.createExpressionFromText(
- "((" + type.getQualifiedName() + ")expression)", null);
+ "((" + typeName + ")expression)", null);
((PsiTypeCastExpression)parenthExpression.getExpression()).getOperand().replace(expression);
+ Set<String> imports = expression.getUserData(ADDITIONAL_IMPORTS_KEY);
+ if (imports == null) {
+ imports = new SmartHashSet<String>();
+ }
+ imports.add(typeName);
+ parenthExpression.putUserData(ADDITIONAL_IMPORTS_KEY, imports);
return parenthExpression;
}
catch (IncorrectOperationException e) {
- throw new EvaluateException(DebuggerBundle.message("error.invalid.type.name", type.getQualifiedName()), e);
+ throw new EvaluateException(DebuggerBundle.message("error.invalid.type.name", typeName), e);
}
}