Search in sources :

Example 1 with TextWithImportsImpl

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);
}
Also used : PsiEnumConstant(com.intellij.psi.PsiEnumConstant) PsiClass(com.intellij.psi.PsiClass) TextWithImportsImpl(com.intellij.debugger.engine.evaluation.TextWithImportsImpl) PsiElement(com.intellij.psi.PsiElement) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)

Example 2 with TextWithImportsImpl

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();
}
Also used : TextWithImports(com.intellij.debugger.engine.evaluation.TextWithImports) TextWithImportsImpl(com.intellij.debugger.engine.evaluation.TextWithImportsImpl)

Example 3 with TextWithImportsImpl

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;
    }
}
Also used : Set(java.util.Set) XExpressionImpl(com.intellij.xdebugger.impl.breakpoints.XExpressionImpl) SuspendContextCommandImpl(com.intellij.debugger.engine.events.SuspendContextCommandImpl) AsyncPromise(org.jetbrains.concurrency.AsyncPromise) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) XExpression(com.intellij.xdebugger.XExpression) TextWithImportsImpl(com.intellij.debugger.engine.evaluation.TextWithImportsImpl) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with TextWithImportsImpl

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());
}
Also used : SmaliCodeFragmentFactory(org.jf.smalidea.debugging.SmaliCodeFragmentFactory) TextWithImportsImpl(com.intellij.debugger.engine.evaluation.TextWithImportsImpl) Editor(com.intellij.openapi.editor.Editor) JavaCodeFragment(com.intellij.psi.JavaCodeFragment) PsiReferenceExpressionImpl(com.intellij.psi.impl.source.tree.java.PsiReferenceExpressionImpl) PsiElement(com.intellij.psi.PsiElement)

Example 5 with TextWithImportsImpl

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;
}
Also used : EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) TextWithImports(com.intellij.debugger.engine.evaluation.TextWithImports) TextWithImportsImpl(com.intellij.debugger.engine.evaluation.TextWithImportsImpl)

Aggregations

TextWithImportsImpl (com.intellij.debugger.engine.evaluation.TextWithImportsImpl)11 EvaluateException (com.intellij.debugger.engine.evaluation.EvaluateException)3 PsiElement (com.intellij.psi.PsiElement)3 TextWithImports (com.intellij.debugger.engine.evaluation.TextWithImports)2 Editor (com.intellij.openapi.editor.Editor)2 JavaCodeFragment (com.intellij.psi.JavaCodeFragment)2 ArrayList (java.util.ArrayList)2 SmaliCodeFragmentFactory (org.jf.smalidea.debugging.SmaliCodeFragmentFactory)2 CodeCompletionHandlerBase (com.intellij.codeInsight.completion.CodeCompletionHandlerBase)1 LookupElement (com.intellij.codeInsight.lookup.LookupElement)1 InstanceFilter (com.intellij.debugger.InstanceFilter)1 SuspendContextCommandImpl (com.intellij.debugger.engine.events.SuspendContextCommandImpl)1 UserExpressionData (com.intellij.debugger.impl.descriptors.data.UserExpressionData)1 MessageDescriptor (com.intellij.debugger.ui.impl.watch.MessageDescriptor)1 NodeManagerImpl (com.intellij.debugger.ui.impl.watch.NodeManagerImpl)1 PsiClass (com.intellij.psi.PsiClass)1 PsiEnumConstant (com.intellij.psi.PsiEnumConstant)1 PsiReferenceExpressionImpl (com.intellij.psi.impl.source.tree.java.PsiReferenceExpressionImpl)1 ClassFilter (com.intellij.ui.classFilter.ClassFilter)1 XExpression (com.intellij.xdebugger.XExpression)1