1 19 20 package org.netbeans.modules.debugger.jpda.expr; 21 22 import com.sun.jdi.ArrayReference; 23 import com.sun.jdi.Value; 24 import com.sun.jdi.InvocationException; 25 26 import java.util.*; 27 import java.text.MessageFormat ; 28 29 import org.openide.util.NbBundle; 30 31 37 public class EvaluationException extends RuntimeException { 38 39 private SimpleNode node; 40 private String reason; 41 private Object [] params; 42 43 private String message; 44 45 public EvaluationException(SimpleNode node, String reason, Object [] params) { 46 this.node = node; 47 this.reason = reason; 48 this.params = params; 49 } 50 51 public String getMessage() { 52 try { 53 return getMessageImpl(); 54 } catch (Exception e) { 55 return message = formatMessage("CTL_EvalError_unknownInternalError", null); 56 } 57 } 58 59 public String getMessageImpl() { 60 if (message != null) return message; 61 62 String [] msgParams = null; 63 64 if (reason.equals("unknownNonterminal")) 65 msgParams = new String [] { JavaParserTreeConstants.jjtNodeName[node.jjtGetID()] }; 66 else if (reason.equals("internalError")) 67 msgParams = new String [] { JavaParserTreeConstants.jjtNodeName[node.jjtGetID()] }; 68 else if (reason.equals("invalidArrayInitializer")) 69 msgParams = new String [] { params[0] == null ? null : params[0].toString() }; 70 else if (reason.equals("arraySizeBadType")) 71 msgParams = new String [] { params[0] == null ? null : params[0].toString() }; 72 else if (reason.equals("arrayCreateError")) 73 msgParams = new String [] { params[0] == null ? null : params[0].toString() }; 74 else if (reason.equals("instantiateInterface")) 75 msgParams = new String [] { params[0] == null ? null : params[0].toString() }; 76 else if (reason.equals("castToBooleanRequired")) 77 msgParams = new String [] { params[0].toString() }; 78 else if (reason.equals("castFromBooleanRequired")) 79 msgParams = new String [] { params[0].toString() }; 80 else if (reason.equals("castError")) 81 msgParams = new String [] { params[0].toString(), params[1].toString() }; 82 else if (reason.equals("badOperandForPostfixOperator")) 83 msgParams = new String [] { params[0].toString() }; 84 else if (reason.equals("postfixOperatorEvaluationError")) 85 msgParams = new String [] { params[1].toString() }; 86 else if (reason.equals("badOperandForPrefixOperator")) 87 msgParams = new String [] { params[0].toString() }; 88 else if (reason.equals("prefixOperatorEvaluationError")) 89 msgParams = new String [] { params[1].toString() }; 90 else if (reason.equals("badOperandForUnaryOperator")) 91 msgParams = new String [] { params[0].toString() }; 92 else if (reason.equals("unaryOperatorEvaluationError")) 93 msgParams = new String [] { params[1].toString() }; 94 else if (reason.equals("unknownType")) 95 msgParams = new String [] { params[0].toString() }; 96 else if (reason.equals("internalErrorResolvingType")) 97 msgParams = new String [] { params[0].toString() }; 98 else if (reason.equals("instanceOfLeftOperandNotAReference")) 99 msgParams = new String [] { ((Value)params[0]).type().name() }; 100 else if (reason.equals("conditionalOrAndBooleanOperandRequired")) 101 msgParams = new String [] { ((Value)params[0]).type().name() }; 102 else if (reason.equals("conditionalQuestionMarkBooleanOperandRequired")) 103 msgParams = new String [] { ((Value)params[0]).type().name() }; 104 else if (reason.equals("thisObjectUnavailable")) 105 msgParams = null; 106 else if (reason.equals("objectReferenceRequiredOnDereference")) 107 msgParams = new String [] { ((Value)params[0]).type().name() }; 108 else if (reason.equals("badArgument")) 109 msgParams = new String [] { params[0].toString() }; 110 else if (reason.equals("argumentsBadSyntax")) 111 msgParams = new String [] { params[0].toString() }; 112 else if (reason.equals("ambigousMethod")) 113 msgParams = new String [] { ((Identifier)params[0]).typeContext.name(), ((Identifier)params[0]).identifier }; 114 else if (reason.equals("noSuchMethod")) 115 msgParams = new String [] { ((Identifier)params[0]).typeContext.name(), ((Identifier)params[0]).identifier }; 116 else if (reason.equals("callException")) 117 msgParams = new String [] { ((Identifier)params[1]).typeContext.name(), ((Identifier)params[1]).identifier, params[0].toString() }; 118 else if (reason.equals("calleeException")) 119 msgParams = new String [] { ((Identifier)params[1]).typeContext.name(), ((Identifier)params[1]).identifier, 120 ((InvocationException)(params[0])).exception().toString() }; 121 else if (reason.equals("identifierNotAReference")) 122 msgParams = new String [] { ((Value)params[0]).type().name() }; 123 else if (reason.equals("notarray")) 124 msgParams = new String [] { params[0].toString() }; 125 else if (reason.equals("arrayIndexNAN")) 126 msgParams = new String [] { params[1].toString() }; 127 else if (reason.equals("arrayIndexOutOfBounds")) 128 msgParams = new String [] { params[1].toString(), Integer.toString(((ArrayReference)params[0]).length() - 1) }; 129 else if (reason.equals("unknownVariable")) 130 msgParams = new String [] { ((Identifier)params[0]).identifier }; 131 else if (reason.equals("integerLiteralTooBig")) 132 msgParams = new String [] { params[0].toString() }; 133 else if (reason.equals("badFormatOfIntegerLiteral")) 134 msgParams = new String [] { params[0].toString() }; 135 else if (reason.equals("unknownLiteralType")) 136 msgParams = new String [] { params[0].toString() }; 137 else if (reason.equals("evaluateError")) 138 msgParams = new String [] { params[1].toString(), params[0].toString(), params[2].toString() }; 140 else if (reason.equals("notEnclosingType")) 141 msgParams = new String [] { ((Identifier)params[0]).typeContext.name(), ((Identifier)params[0]).superQualifier }; 142 else if (reason.equals("accessInstanceVariableFromStaticContext")) 143 msgParams = new String [] { ((Identifier)params[0]).identifier }; 144 else if (reason.equals("methodCallOnNull")) 145 msgParams = new String [] { params[0].toString() }; 146 else { 147 reason = "unknownInternalError"; 148 msgParams = null; 149 } 150 151 message = formatMessage("CTL_EvalError_" + reason, msgParams); 152 153 return message; 154 } 155 156 private String formatMessage(String msg, String [] params) { 157 ResourceBundle bundle = NbBundle.getBundle (EvaluationException.class); 158 msg = bundle.getString(msg); 159 return MessageFormat.format(msg, (Object []) params); 160 } 161 } 162 | Popular Tags |