1 11 package org.eclipse.jdt.internal.debug.ui.variables; 12 13 import org.eclipse.debug.core.DebugException; 14 import org.eclipse.debug.internal.ui.elements.adapters.DefaultVariableCellModifier; 15 import org.eclipse.debug.internal.ui.elements.adapters.VariableColumnPresentation; 16 import org.eclipse.jdt.core.Signature; 17 import org.eclipse.jdt.debug.core.IJavaVariable; 18 19 23 public class JavaVariableCellModifier extends DefaultVariableCellModifier { 24 25 31 public boolean canModify(Object element, String property) { 32 if (VariableColumnPresentation.COLUMN_VARIABLE_VALUE.equals(property)) { 33 if (element instanceof IJavaVariable) { 34 IJavaVariable var = (IJavaVariable) element; 35 if (var.supportsValueModification()){ 36 try { 37 String signature = var.getSignature(); 38 if (signature != null) { 39 if (signature.length() == 1) { 40 return true; 42 } 43 return signature.equals("Ljava/lang/String;"); } 45 } catch (DebugException e) { 46 } 47 } 48 } 49 } 50 return false; 51 } 52 53 59 public Object getValue(Object element, String property) { 60 if (VariableColumnPresentation.COLUMN_VARIABLE_VALUE.equals(property)) { 61 if (element instanceof IJavaVariable) { 62 IJavaVariable var = (IJavaVariable) element; 63 if (isBoolean(var)) { 64 try { 65 if (var.getValue().getValueString().equals(Boolean.toString(true))) { 66 return new Integer (0); 67 } else { 68 return new Integer (1); 69 } 70 } catch (DebugException e) { 71 } 72 } 73 } 74 } 75 return super.getValue(element, property); 76 } 77 78 public void modify(Object element, String property, Object value) { 79 Object oldValue = getValue(element, property); 80 if (!value.equals(oldValue)) { 81 if (VariableColumnPresentation.COLUMN_VARIABLE_VALUE.equals(property)) { 82 if (element instanceof IJavaVariable) { 83 IJavaVariable var = (IJavaVariable) element; 84 if (isBoolean(var)) { 85 if (value instanceof Integer ) { 86 switch (((Integer ) value).intValue()) { 87 case 0: 88 super.modify(element, property, Boolean.toString(true)); 89 return; 90 case 1: 91 super.modify(element, property, Boolean.toString(false)); 92 return; 93 default: 94 return; 96 } 97 } else { 98 return; 100 } 101 } 102 } 103 } 104 super.modify(element, property, value); 105 } 106 } 107 108 114 public static boolean isBoolean(IJavaVariable variable) { 115 try { 116 String signature = variable.getSignature(); 117 return (signature.length() == 1 && signature.charAt(0) == Signature.C_BOOLEAN); 118 } catch (DebugException e) { 119 } 120 return false; 121 } 122 123 } 124 | Popular Tags |