KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > variables > JavaVariableContentProvider


1 /*******************************************************************************
2  * Copyright (c) 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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 /**
30  * Determines the child content of an IJavaVariable.
31  *
32  * @since 3.3
33  * @see VariableContentProvider
34  * @see IJavaVariable
35  * @see JavaVariableAdapterFactory
36  * @see JavaExpressionContentProvider
37  */

38 public class JavaVariableContentProvider extends VariableContentProvider {
39
40     /* (non-Javadoc)
41      * @see org.eclipse.debug.internal.ui.model.elements.VariableContentProvider#getChildren(java.lang.Object, int, int, org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext, org.eclipse.debug.internal.ui.viewers.model.provisional.IViewerUpdate)
42      */

43     protected Object JavaDoc[] getChildren(Object JavaDoc parent, int index, int length, IPresentationContext context, IViewerUpdate monitor) throws CoreException {
44         Object JavaDoc[] variables = getAllChildren(parent, context);
45         if (displayReferencesAsChild(parent)){
46             Object JavaDoc[] moreVariables = new Object JavaDoc[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 JavaDoc[]{((IVariable)parent).getName()}),(IJavaObject)value);
50             return getElements(moreVariables, index, length);
51         }
52         return getElements(variables, index, length);
53     }
54         
55     /* (non-Javadoc)
56      * @see org.eclipse.debug.internal.ui.model.elements.VariableContentProvider#getChildCount(java.lang.Object, org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext, org.eclipse.debug.internal.ui.viewers.model.provisional.IViewerUpdate)
57      */

58     protected int getChildCount(Object JavaDoc 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     /* (non-Javadoc)
67      * @see org.eclipse.debug.internal.ui.model.elements.VariableContentProvider#hasChildren(java.lang.Object, org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext, org.eclipse.debug.internal.ui.viewers.model.provisional.IViewerUpdate)
68      */

69     protected boolean hasChildren(Object JavaDoc 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     /**
77      * Determines if an all references variable should be added as a child to the passed object.
78      *
79      * @param parent element to display references as a child for
80      * @return whether to display references as a child of the given parent
81      * @throws DebugException
82      */

83     public static boolean displayReferencesAsChild(Object JavaDoc parent) throws DebugException{
84         // Note, this method is used by the JavaExpressionContentProvider as well as the JavaVariableContentProvider
85
// Only display references if the target can support it
86
if (HeapWalkingManager.supportsHeapWalking(parent)){
87             // Lists of references don't have references
88
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                 // Only java objects have references
98
if (value instanceof IJavaObject){
99                     // Null objects don't have references
100
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