1 11 package org.eclipse.jdt.internal.debug.ui.variables; 12 13 import org.eclipse.core.runtime.CoreException; 14 import org.eclipse.debug.core.DebugException; 15 import org.eclipse.debug.core.model.IExpression; 16 import org.eclipse.debug.core.model.IValue; 17 import org.eclipse.debug.core.model.IVariable; 18 import org.eclipse.debug.internal.ui.model.elements.VariableContentProvider; 19 import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext; 20 import org.eclipse.debug.internal.ui.viewers.model.provisional.IViewerUpdate; 21 import org.eclipse.jdt.debug.core.IJavaDebugTarget; 22 import org.eclipse.jdt.debug.core.IJavaObject; 23 import org.eclipse.jdt.internal.debug.core.HeapWalkingManager; 24 import org.eclipse.jdt.internal.debug.core.model.JDIDebugModelMessages; 25 import org.eclipse.jdt.internal.debug.core.model.JDIReferenceListVariable; 26 27 import com.ibm.icu.text.MessageFormat; 28 29 38 public class JavaVariableContentProvider extends VariableContentProvider { 39 40 43 protected Object [] getChildren(Object parent, int index, int length, IPresentationContext context, IViewerUpdate monitor) throws CoreException { 44 Object [] variables = getAllChildren(parent, context); 45 if (displayReferencesAsChild(parent)){ 46 Object [] moreVariables = new Object [variables.length+1]; 47 System.arraycopy(variables, 0, moreVariables, 1, variables.length); 48 IValue value = ((IVariable)parent).getValue(); 49 moreVariables[0] = new JDIReferenceListVariable(MessageFormat.format(JDIDebugModelMessages.JDIReferenceListValue_6, new String []{((IVariable)parent).getName()}),(IJavaObject)value); 50 return getElements(moreVariables, index, length); 51 } 52 return getElements(variables, index, length); 53 } 54 55 58 protected int getChildCount(Object element, IPresentationContext context, IViewerUpdate monitor) throws CoreException { 59 int count = super.getChildCount(element, context, monitor); 60 if (displayReferencesAsChild(element)){ 61 count++; 62 } 63 return count; 64 } 65 66 69 protected boolean hasChildren(Object element, IPresentationContext context, IViewerUpdate monitor) throws CoreException { 70 if (displayReferencesAsChild(element)){ 71 return true; 72 } 73 return super.hasChildren(element, context, monitor); 74 } 75 76 83 public static boolean displayReferencesAsChild(Object parent) throws DebugException{ 84 if (HeapWalkingManager.supportsHeapWalking(parent)){ 87 if (!(parent instanceof JDIReferenceListVariable)){ 89 IValue value = null; 90 if (parent instanceof IVariable){ 91 value = ((IVariable)parent).getValue(); 92 } else if (parent instanceof IExpression){ 93 value = ((IExpression)parent).getValue(); 94 } else{ 95 return false; 96 } 97 if (value instanceof IJavaObject){ 99 if (!((IJavaDebugTarget)value.getDebugTarget()).nullValue().equals(value)){ 101 return HeapWalkingManager.getDefault().isShowReferenceInVarView(); 102 } 103 } 104 } 105 } 106 return false; 107 } 108 109 } 110 | Popular Tags |