use of com.intellij.debugger.engine.evaluation.TextWithImportsImpl in project intellij-community by JetBrains.
the class GroovyEditorTextProvider method getEditorText.
@Override
public TextWithImports getEditorText(PsiElement elementAtCaret) {
String result = "";
PsiElement element = findExpressionInner(elementAtCaret, true);
if (element != null) {
if (element instanceof GrReferenceExpression) {
final GrReferenceExpression reference = (GrReferenceExpression) element;
if (reference.getQualifier() == null) {
final PsiElement resolved = reference.resolve();
if (resolved instanceof PsiEnumConstant) {
final PsiEnumConstant enumConstant = (PsiEnumConstant) resolved;
final PsiClass enumClass = enumConstant.getContainingClass();
if (enumClass != null) {
result = enumClass.getName() + "." + enumConstant.getName();
}
}
}
}
if (result.isEmpty()) {
result = element.getText();
}
}
return new TextWithImportsImpl(CodeFragmentKind.EXPRESSION, result);
}
use of com.intellij.debugger.engine.evaluation.TextWithImportsImpl in project intellij-community by JetBrains.
the class CompoundRendererConfigurable method reset.
public void reset() {
final TextWithImports emptyExpressionFragment = new TextWithImportsImpl(CodeFragmentKind.EXPRESSION, "");
((CardLayout) getLayout()).show(this, myRenderer == null ? EMPTY_PANEL_ID : DATA_PANEL_ID);
if (myRenderer == null) {
return;
}
final String className = myRenderer.getClassName();
myClassNameField.setText(className);
updateContext(className);
final ValueLabelRenderer labelRenderer = myRenderer.getLabelRenderer();
final ChildrenRenderer childrenRenderer = myRenderer.getChildrenRenderer();
myShowTypeCheckBox.setSelected(myRenderer.isShowType());
if (myRenderer.isBaseRenderer(labelRenderer)) {
myLabelEditor.setExpression(TextWithImportsImpl.toXExpression(emptyExpressionFragment));
myRbDefaultLabel.setSelected(true);
} else {
myRbExpressionLabel.setSelected(true);
myLabelEditor.setExpression(TextWithImportsImpl.toXExpression(((LabelRenderer) labelRenderer).getLabelExpression()));
}
getTableModel().clear();
myAppendDefaultChildren.setSelected(false);
if (myRenderer.isBaseRenderer(childrenRenderer)) {
myRbDefaultChildrenRenderer.setSelected(true);
myChildrenEditor.setExpression(TextWithImportsImpl.toXExpression(emptyExpressionFragment));
myChildrenExpandedEditor.setExpression(TextWithImportsImpl.toXExpression(emptyExpressionFragment));
} else if (childrenRenderer instanceof ExpressionChildrenRenderer) {
myRbExpressionChildrenRenderer.setSelected(true);
final ExpressionChildrenRenderer exprRenderer = (ExpressionChildrenRenderer) childrenRenderer;
myChildrenEditor.setExpression(TextWithImportsImpl.toXExpression(exprRenderer.getChildrenExpression()));
myChildrenExpandedEditor.setExpression(TextWithImportsImpl.toXExpression(exprRenderer.getChildrenExpandable()));
} else {
myRbListChildrenRenderer.setSelected(true);
myChildrenEditor.setExpression(TextWithImportsImpl.toXExpression(emptyExpressionFragment));
myChildrenExpandedEditor.setExpression(TextWithImportsImpl.toXExpression(emptyExpressionFragment));
if (childrenRenderer instanceof EnumerationChildrenRenderer) {
EnumerationChildrenRenderer enumerationRenderer = (EnumerationChildrenRenderer) childrenRenderer;
getTableModel().init(enumerationRenderer.getChildren());
myAppendDefaultChildren.setSelected(enumerationRenderer.isAppendDefaultChildren());
}
}
updateEnabledState();
}
use of com.intellij.debugger.engine.evaluation.TextWithImportsImpl in project intellij-community by JetBrains.
the class JavaValue method calculateEvaluationExpression.
@NotNull
@Override
public Promise<XExpression> calculateEvaluationExpression() {
if (evaluationExpression != null) {
return Promise.resolve(evaluationExpression);
} else {
final AsyncPromise<XExpression> res = new AsyncPromise<>();
myEvaluationContext.getManagerThread().schedule(new SuspendContextCommandImpl(myEvaluationContext.getSuspendContext()) {
@Override
public Priority getPriority() {
return Priority.HIGH;
}
@Override
public void contextAction() throws Exception {
evaluationExpression = ApplicationManager.getApplication().runReadAction(new Computable<XExpression>() {
@Override
public XExpression compute() {
try {
PsiElement psiExpression = getDescriptor().getTreeEvaluation(JavaValue.this, getDebuggerContext());
if (psiExpression != null) {
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) {
LOG.info(e);
}
return null;
}
});
res.setResult(evaluationExpression);
}
});
return res;
}
}
use of com.intellij.debugger.engine.evaluation.TextWithImportsImpl in project smali by JesusFreke.
the class SmaliCodeFragmentFactoryTest method assertVariableType.
private void assertVariableType(PsiElement context, String variableName, String expectedType) {
SmaliCodeFragmentFactory codeFragmentFactory = new SmaliCodeFragmentFactory();
JavaCodeFragment fragment = codeFragmentFactory.createCodeFragment(new TextWithImportsImpl(CodeFragmentKind.EXPRESSION, variableName), context, getProject());
Editor editor = createEditor(fragment.getVirtualFile());
editor.getCaretModel().moveToOffset(1);
PsiElement element = fragment.findElementAt(0);
Assert.assertTrue(element.getParent() instanceof PsiReferenceExpressionImpl);
PsiReferenceExpressionImpl reference = (PsiReferenceExpressionImpl) element.getParent();
Assert.assertEquals(expectedType, reference.getType().getCanonicalText());
}
use of com.intellij.debugger.engine.evaluation.TextWithImportsImpl in project intellij-community by JetBrains.
the class DebuggerTreeNodeExpression method createEvaluationText.
public static TextWithImports createEvaluationText(final DebuggerTreeNodeImpl node, final DebuggerContextImpl context) throws EvaluateException {
final EvaluateException[] ex = new EvaluateException[] { null };
final TextWithImports textWithImports = PsiDocumentManager.getInstance(context.getProject()).commitAndRunReadAction((Computable<TextWithImports>) () -> {
try {
final PsiExpression expressionText = getEvaluationExpression(node, context);
if (expressionText != null) {
return new TextWithImportsImpl(expressionText);
}
} catch (EvaluateException e) {
ex[0] = e;
}
return null;
});
if (ex[0] != null) {
throw ex[0];
}
return textWithImports;
}
Aggregations