1 11 package org.eclipse.jdt.internal.debug.ui.contentassist; 12 13 import org.eclipse.core.runtime.CoreException; 14 import org.eclipse.core.runtime.IAdaptable; 15 import org.eclipse.debug.core.model.IVariable; 16 import org.eclipse.debug.ui.DebugUITools; 17 import org.eclipse.jdt.core.IType; 18 import org.eclipse.jdt.debug.core.IJavaStackFrame; 19 import org.eclipse.jdt.debug.core.IJavaVariable; 20 import org.eclipse.jdt.internal.debug.core.JavaDebugUtils; 21 22 23 28 public class CurrentFrameContext extends TypeContext { 29 30 34 public CurrentFrameContext() { 35 super(null, -1); 36 } 37 38 41 public IType getType() throws CoreException { 42 IJavaStackFrame frame = getStackFrame(); 43 if (frame != null) { 44 IType type = JavaDebugUtils.resolveDeclaringType(frame); 45 if (type != null) { 46 return type; 47 } 48 } 49 return super.getType(); 50 } 51 52 55 public String [][] getLocalVariables() throws CoreException { 56 IJavaStackFrame frame = getStackFrame(); 57 if (frame != null) { 58 IVariable[] variables = frame.getVariables(); 59 int index = 0; 60 if (!frame.isStatic()) { 61 index = 1; 62 } 63 String [][] locals = new String [2][variables.length - index]; 64 for (int i = 0; i < locals[0].length; i++) { 65 IJavaVariable var = (IJavaVariable) variables[index]; 66 locals[0][i] = var.getName(); 67 locals[1][i] = var.getJavaType().getName(); 68 index++; 69 } 70 return locals; 71 } 72 return super.getLocalVariables(); 73 } 74 75 78 public boolean isStatic() throws CoreException { 79 IJavaStackFrame frame = getStackFrame(); 80 if (frame != null) { 81 return frame.isStatic(); 82 } 83 return false; 84 } 85 86 92 protected IJavaStackFrame getStackFrame() { 93 IAdaptable debugContext = DebugUITools.getDebugContext(); 94 IJavaStackFrame frame = null; 95 if (debugContext != null) { 96 frame = (IJavaStackFrame) debugContext.getAdapter(IJavaStackFrame.class); 97 } 98 return frame; 99 } 100 101 102 } 103 | Popular Tags |