1 11 package org.eclipse.jdt.internal.debug.ui.contentassist; 12 13 import org.eclipse.core.runtime.CoreException; 14 import org.eclipse.debug.core.model.IExpression; 15 import org.eclipse.debug.core.model.IValue; 16 import org.eclipse.debug.core.model.IVariable; 17 import org.eclipse.debug.ui.IDebugView; 18 import org.eclipse.jdt.core.IType; 19 import org.eclipse.jdt.debug.core.IJavaArray; 20 import org.eclipse.jdt.debug.core.IJavaDebugTarget; 21 import org.eclipse.jdt.debug.core.IJavaObject; 22 import org.eclipse.jdt.debug.core.IJavaPrimitiveValue; 23 import org.eclipse.jdt.debug.core.IJavaStackFrame; 24 import org.eclipse.jdt.debug.core.IJavaType; 25 import org.eclipse.jdt.debug.core.IJavaValue; 26 import org.eclipse.jdt.internal.debug.core.JavaDebugUtils; 27 import org.eclipse.jdt.internal.debug.eval.ast.engine.ASTEvaluationEngine; 28 import org.eclipse.jdt.internal.debug.eval.ast.engine.ArrayRuntimeContext; 29 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin; 30 import org.eclipse.jface.viewers.ISelection; 31 import org.eclipse.jface.viewers.IStructuredSelection; 32 import org.eclipse.ui.IWorkbenchPage; 33 import org.eclipse.ui.IWorkbenchWindow; 34 35 public class CurrentValueContext extends CurrentFrameContext { 36 37 40 public IType getType() throws CoreException { 41 IJavaValue value = resolveValue(); 42 if (value == null || value instanceof IJavaPrimitiveValue) { 43 return super.getType(); 45 } 46 IType type = null; 47 if (value instanceof IJavaArray) { 48 IJavaType[] types = ((IJavaDebugTarget)value.getDebugTarget()).getJavaTypes("java.lang.Object"); if (types.length > 0) { 51 type = JavaDebugUtils.resolveType(types[0]); 52 } 53 } else { 54 type = JavaDebugUtils.resolveType(value); 55 } 56 if (type == null) { 57 unableToResolveType(); 58 } 59 return type; 60 } 61 62 68 protected IJavaValue resolveValue() throws CoreException { 69 IJavaStackFrame stackFrame= getStackFrame(); 70 if (stackFrame == null) { 71 unableToResolveType(); 72 } 73 74 IWorkbenchWindow window= JDIDebugUIPlugin.getActiveWorkbenchWindow(); 75 if (window == null) { 76 unableToResolveType(); 77 } 78 IWorkbenchPage page= window.getActivePage(); 79 if (page == null) { 80 unableToResolveType(); 81 } 82 IDebugView view= (IDebugView)page.getActivePart(); 83 if (view == null) { 84 unableToResolveType(); 85 } 86 ISelection selection= view.getViewer().getSelection(); 87 if (!selection.isEmpty() && selection instanceof IStructuredSelection) { 88 IStructuredSelection viewerSelection= (IStructuredSelection)selection; 89 if (viewerSelection.size() > 1) { 90 unableToResolveType(); 91 } 92 Object element= viewerSelection.getFirstElement(); 93 94 IValue value= null; 95 if (element instanceof IVariable) { 96 IVariable variable = (IVariable)element; 97 if (!variable.getName().equals("this")) { value= variable.getValue(); 99 } 100 } else if (element instanceof IExpression) { 101 value= ((IExpression)element).getValue(); 102 } 103 if (value instanceof IJavaValue) { 104 return (IJavaValue) value; 105 } 106 } 107 return null; 108 } 109 110 113 public String [][] getLocalVariables() throws CoreException { 114 IJavaValue value = resolveValue(); 115 if (value instanceof IJavaArray) { 116 return new String [][]{new String [] {ArrayRuntimeContext.ARRAY_THIS_VARIABLE}, new String [] {value.getJavaType().getName()}}; 118 } else if (value instanceof IJavaObject) { 119 return new String [][]{}; 120 } 121 return super.getLocalVariables(); 122 } 123 124 127 public String getSnippet(String snippet) throws CoreException { 128 IJavaValue value = resolveValue(); 129 if (value instanceof IJavaArray) { 130 return ASTEvaluationEngine.replaceThisReferences(snippet); 131 } 132 return super.getSnippet(snippet); 133 } 134 135 138 public boolean isStatic() throws CoreException { 139 IJavaValue value = resolveValue(); 140 if (value instanceof IJavaObject) { 141 return false; 142 } 143 return super.isStatic(); 144 } 145 146 147 } 148 | Popular Tags |