Search in sources :

Example 11 with TextWithImports

use of com.intellij.debugger.engine.evaluation.TextWithImports 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;
        }
    }
}
Also used : LocalVariableProxyImpl(com.intellij.debugger.jdi.LocalVariableProxyImpl) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException) EvaluationContextImpl(com.intellij.debugger.engine.evaluation.EvaluationContextImpl) XSourcePosition(com.intellij.xdebugger.XSourcePosition) SourcePosition(com.intellij.debugger.SourcePosition) TextWithImports(com.intellij.debugger.engine.evaluation.TextWithImports)

Example 12 with TextWithImports

use of com.intellij.debugger.engine.evaluation.TextWithImports in project intellij-community by JetBrains.

the class EnumerationChildrenRenderer method readExternal.

public void readExternal(Element element) throws InvalidDataException {
    super.readExternal(element);
    myChildren.clear();
    myAppendDefaultChildren = "true".equals(JDOMExternalizerUtil.readField(element, APPEND_DEFAULT_NAME));
    List<Element> children = element.getChildren(CHILDREN_EXPRESSION);
    for (Element item : children) {
        String name = item.getAttributeValue(CHILD_NAME);
        TextWithImports text = DebuggerUtils.getInstance().readTextWithImports(item.getChildren().get(0));
        myChildren.add(Pair.create(name, text));
    }
}
Also used : PsiElement(com.intellij.psi.PsiElement) Element(org.jdom.Element) TextWithImports(com.intellij.debugger.engine.evaluation.TextWithImports)

Example 13 with TextWithImports

use of com.intellij.debugger.engine.evaluation.TextWithImports in project intellij-community by JetBrains.

the class JavaDebuggerEditorsProvider method createExpressionCodeFragment.

@Override
protected PsiFile createExpressionCodeFragment(@NotNull Project project, @NotNull XExpression expression, @Nullable PsiElement context, boolean isPhysical) {
    TextWithImports text = TextWithImportsImpl.fromXExpression(expression);
    if (text != null) {
        CodeFragmentFactory factory = DebuggerUtilsEx.findAppropriateCodeFragmentFactory(text, context);
        JavaCodeFragment codeFragment = factory.createPresentationCodeFragment(text, context, project);
        if (context != null) {
            PsiType contextType = context.getUserData(DebuggerUtilsImpl.PSI_TYPE_KEY);
            if (contextType == null) {
                PsiClass contextClass = PsiTreeUtil.getNonStrictParentOfType(context, PsiClass.class);
                if (contextClass != null) {
                    contextType = JavaPsiFacade.getInstance(codeFragment.getProject()).getElementFactory().createType(contextClass);
                }
            }
            codeFragment.setThisType(contextType);
        }
        return codeFragment;
    } else {
        return super.createExpressionCodeFragment(project, expression, context, isPhysical);
    }
}
Also used : CodeFragmentFactory(com.intellij.debugger.engine.evaluation.CodeFragmentFactory) TextWithImports(com.intellij.debugger.engine.evaluation.TextWithImports)

Aggregations

TextWithImports (com.intellij.debugger.engine.evaluation.TextWithImports)13 EvaluateException (com.intellij.debugger.engine.evaluation.EvaluateException)3 TextWithImportsImpl (com.intellij.debugger.engine.evaluation.TextWithImportsImpl)2 PsiElement (com.intellij.psi.PsiElement)2 Element (org.jdom.Element)2 SourcePosition (com.intellij.debugger.SourcePosition)1 CodeFragmentFactory (com.intellij.debugger.engine.evaluation.CodeFragmentFactory)1 EvaluationContextImpl (com.intellij.debugger.engine.evaluation.EvaluationContextImpl)1 DebuggerContextCommandImpl (com.intellij.debugger.engine.events.DebuggerContextCommandImpl)1 DebuggerContextImpl (com.intellij.debugger.impl.DebuggerContextImpl)1 UserExpressionData (com.intellij.debugger.impl.descriptors.data.UserExpressionData)1 LocalVariableProxyImpl (com.intellij.debugger.jdi.LocalVariableProxyImpl)1 DebuggerTreeNodeImpl (com.intellij.debugger.ui.impl.watch.DebuggerTreeNodeImpl)1 Pair (com.intellij.openapi.util.Pair)1 JBTable (com.intellij.ui.table.JBTable)1 AbstractTableCellEditor (com.intellij.util.ui.AbstractTableCellEditor)1 XSourcePosition (com.intellij.xdebugger.XSourcePosition)1 XDebuggerExpressionEditor (com.intellij.xdebugger.impl.ui.XDebuggerExpressionEditor)1 XDebuggerTreeNode (com.intellij.xdebugger.impl.ui.tree.nodes.XDebuggerTreeNode)1 ArrayList (java.util.ArrayList)1