Search in sources :

Example 6 with TextWithImportsImpl

use of com.intellij.debugger.engine.evaluation.TextWithImportsImpl in project android by JetBrains.

the class ArrayMapRendererBase method buildChildren.

/** Builds a list of {@link DebuggerTreeNode}'s that are the children of this node. */
@Override
public void buildChildren(Value value, ChildrenBuilder builder, EvaluationContext evaluationContext) {
    DebuggerManagerThreadImpl.assertIsManagerThread();
    List<DebuggerTreeNode> children = new ArrayList<DebuggerTreeNode>();
    NodeManagerImpl nodeManager = (NodeManagerImpl) builder.getNodeManager();
    NodeDescriptorFactory descriptorFactory = builder.getDescriptorManager();
    int size;
    try {
        size = getArrayMapSize(value, evaluationContext);
    } catch (Exception e) {
        size = 0;
    }
    for (int i = 0, n = Math.min(size, MAX_CHILDREN); i < n; i++) {
        // For each entry, display the value at that entry. TODO: we need to show the key corresponding to this as well.
        // We used to show the key and value by using the following expression:
        // String expression = String.format("new Object[] {this.keyAt(%1$d), this.valueAt(%2$d)}", i, i);
        // But it turns out that this throws "java.lang.ClassNotFoundException: [LObject;"
        // Until we find an alternate scheme, just show the value.
        String expression = String.format("this.valueAt(%1$d)", i);
        UserExpressionData descriptorData = new UserExpressionData((ValueDescriptorImpl) builder.getParentDescriptor(), myFqn, String.format("value[%1$d]", i), new TextWithImportsImpl(CodeFragmentKind.EXPRESSION, expression, "", StdFileTypes.JAVA));
        UserExpressionDescriptor userExpressionDescriptor = descriptorFactory.getUserExpressionDescriptor(builder.getParentDescriptor(), descriptorData);
        DebuggerTreeNode arrayMapItemNode = nodeManager.createNode(userExpressionDescriptor, evaluationContext);
        children.add(arrayMapItemNode);
    }
    if (size > MAX_CHILDREN) {
        children.add(nodeManager.createMessageNode(new MessageDescriptor(MORE_ELEMENTS, MessageDescriptor.SPECIAL)));
    }
    builder.setChildren(children);
}
Also used : MessageDescriptor(com.intellij.debugger.ui.impl.watch.MessageDescriptor) UserExpressionData(com.intellij.debugger.impl.descriptors.data.UserExpressionData) ArrayList(java.util.ArrayList) TextWithImportsImpl(com.intellij.debugger.engine.evaluation.TextWithImportsImpl) NodeManagerImpl(com.intellij.debugger.ui.impl.watch.NodeManagerImpl) EvaluateException(com.intellij.debugger.engine.evaluation.EvaluateException)

Example 7 with TextWithImportsImpl

use of com.intellij.debugger.engine.evaluation.TextWithImportsImpl in project smali by JesusFreke.

the class SmaliCodeFragmentFactoryTest method assertCompletionContains.

private void assertCompletionContains(String completionText, PsiElement context, String[] expectedItems, String[] disallowedItems) {
    SmaliCodeFragmentFactory codeFragmentFactory = new SmaliCodeFragmentFactory();
    JavaCodeFragment fragment = codeFragmentFactory.createCodeFragment(new TextWithImportsImpl(CodeFragmentKind.EXPRESSION, completionText), context, getProject());
    Editor editor = createEditor(fragment.getVirtualFile());
    editor.getCaretModel().moveToOffset(completionText.length());
    new CodeCompletionHandlerBase(CompletionType.BASIC).invokeCompletion(getProject(), editor);
    List<LookupElement> elements = LookupManager.getInstance(getProject()).getActiveLookup().getItems();
    HashSet expectedSet = Sets.newHashSet(expectedItems);
    HashSet disallowedSet = Sets.newHashSet(disallowedItems);
    for (LookupElement element : elements) {
        expectedSet.remove(element.toString());
        Assert.assertFalse(disallowedSet.contains(element.toString()));
    }
    Assert.assertTrue(expectedSet.size() == 0);
}
Also used : SmaliCodeFragmentFactory(org.jf.smalidea.debugging.SmaliCodeFragmentFactory) TextWithImportsImpl(com.intellij.debugger.engine.evaluation.TextWithImportsImpl) CodeCompletionHandlerBase(com.intellij.codeInsight.completion.CodeCompletionHandlerBase) Editor(com.intellij.openapi.editor.Editor) LookupElement(com.intellij.codeInsight.lookup.LookupElement) JavaCodeFragment(com.intellij.psi.JavaCodeFragment) HashSet(java.util.HashSet)

Example 8 with TextWithImportsImpl

use of com.intellij.debugger.engine.evaluation.TextWithImportsImpl in project android by JetBrains.

the class ArrayMapRendererBase method calcLabel.

@Override
public String calcLabel(ValueDescriptor descriptor, EvaluationContext evaluationContext, DescriptorLabelListener listener) throws EvaluateException {
    if (!(descriptor.getValue() instanceof ObjectReference)) {
        return DebuggerBundle.message("label.undefined");
    }
    ObjectReference ref = (ObjectReference) descriptor.getValue();
    myLabelRenderer.setLabelExpression(new TextWithImportsImpl(CodeFragmentKind.EXPRESSION, "size()", "", StdFileTypes.JAVA));
    return ValueDescriptorImpl.getIdLabel(ref) + ", size = " + myLabelRenderer.calcLabel(descriptor, evaluationContext, listener);
}
Also used : TextWithImportsImpl(com.intellij.debugger.engine.evaluation.TextWithImportsImpl)

Example 9 with TextWithImportsImpl

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

the class DebuggerUtilsImpl method readTextWithImports.

@Override
public TextWithImports readTextWithImports(Element root, String name) {
    String s = JDOMExternalizerUtil.readField(root, name);
    if (s != null) {
        return new TextWithImportsImpl(CodeFragmentKind.EXPRESSION, s);
    } else {
        Element option = JDOMExternalizerUtil.getOption(root, name);
        if (option != null) {
            XExpressionState state = new XExpressionState();
            XmlSerializer.deserializeInto(state, option);
            return TextWithImportsImpl.fromXExpression(state.toXExpression());
        }
    }
    return null;
}
Also used : Element(org.jdom.Element) TextWithImportsImpl(com.intellij.debugger.engine.evaluation.TextWithImportsImpl) XExpressionState(com.intellij.xdebugger.impl.breakpoints.XExpressionState)

Example 10 with TextWithImportsImpl

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

the class FilteredRequestorImpl method readExternal.

public void readExternal(Element parentNode) throws InvalidDataException {
    DefaultJDOMExternalizer.readExternal(this, parentNode);
    if (DebuggerSettings.SUSPEND_NONE.equals(SUSPEND_POLICY)) {
        // compatibility with older format
        SUSPEND = false;
        SUSPEND_POLICY = DebuggerSettings.SUSPEND_ALL;
    }
    String condition = JDOMExternalizerUtil.readField(parentNode, CONDITION_OPTION_NAME);
    if (condition != null) {
        setCondition(new TextWithImportsImpl(CodeFragmentKind.EXPRESSION, condition));
    }
    myClassFilters = DebuggerUtilsEx.readFilters(parentNode.getChildren(FILTER_OPTION_NAME));
    myClassExclusionFilters = DebuggerUtilsEx.readFilters(parentNode.getChildren(EXCLUSION_FILTER_OPTION_NAME));
    final ClassFilter[] instanceFilters = DebuggerUtilsEx.readFilters(parentNode.getChildren(INSTANCE_ID_OPTION_NAME));
    final List<InstanceFilter> iFilters = new ArrayList<>(instanceFilters.length);
    for (ClassFilter instanceFilter : instanceFilters) {
        try {
            iFilters.add(InstanceFilter.create(instanceFilter));
        } catch (Exception ignored) {
        }
    }
    myInstanceFilters = iFilters.isEmpty() ? InstanceFilter.EMPTY_ARRAY : iFilters.toArray(new InstanceFilter[iFilters.size()]);
}
Also used : InstanceFilter(com.intellij.debugger.InstanceFilter) ClassFilter(com.intellij.ui.classFilter.ClassFilter) ArrayList(java.util.ArrayList) 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