KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > debugger > jpda > expr > EvaluationException


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

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 JavaDoc;
28
29 import org.openide.util.NbBundle;
30
31 /**
32  * This class is a runtime exception because it integrates better with the generated code and
33  * it also prevents unnecessary code bloat.
34  *
35  * @author Maros Sandor
36  */

37 public class EvaluationException extends RuntimeException JavaDoc {
38
39     private SimpleNode node;
40     private String JavaDoc reason;
41     private Object JavaDoc [] params;
42
43     private String JavaDoc message;
44
45     public EvaluationException(SimpleNode node, String JavaDoc reason, Object JavaDoc[] params) {
46         this.node = node;
47         this.reason = reason;
48         this.params = params;
49     }
50
51     public String JavaDoc getMessage() {
52         try {
53             return getMessageImpl();
54         } catch (Exception JavaDoc e) {
55             return message = formatMessage("CTL_EvalError_unknownInternalError", null);
56         }
57     }
58
59     public String JavaDoc getMessageImpl() {
60         if (message != null) return message;
61
62         String JavaDoc [] msgParams = null;
63
64         if (reason.equals("unknownNonterminal"))
65             msgParams = new String JavaDoc [] { JavaParserTreeConstants.jjtNodeName[node.jjtGetID()] };
66         else if (reason.equals("internalError"))
67             msgParams = new String JavaDoc [] { JavaParserTreeConstants.jjtNodeName[node.jjtGetID()] };
68         else if (reason.equals("invalidArrayInitializer"))
69             msgParams = new String JavaDoc [] { params[0] == null ? null : params[0].toString() };
70         else if (reason.equals("arraySizeBadType"))
71             msgParams = new String JavaDoc [] { params[0] == null ? null : params[0].toString() };
72         else if (reason.equals("arrayCreateError"))
73             msgParams = new String JavaDoc [] { params[0] == null ? null : params[0].toString() };
74         else if (reason.equals("instantiateInterface"))
75             msgParams = new String JavaDoc [] { params[0] == null ? null : params[0].toString() };
76         else if (reason.equals("castToBooleanRequired"))
77             msgParams = new String JavaDoc [] { params[0].toString() };
78         else if (reason.equals("castFromBooleanRequired"))
79             msgParams = new String JavaDoc [] { params[0].toString() };
80         else if (reason.equals("castError"))
81             msgParams = new String JavaDoc [] { params[0].toString(), params[1].toString() };
82         else if (reason.equals("badOperandForPostfixOperator"))
83             msgParams = new String JavaDoc [] { params[0].toString() };
84         else if (reason.equals("postfixOperatorEvaluationError"))
85             msgParams = new String JavaDoc [] { params[1].toString() };
86         else if (reason.equals("badOperandForPrefixOperator"))
87             msgParams = new String JavaDoc [] { params[0].toString() };
88         else if (reason.equals("prefixOperatorEvaluationError"))
89             msgParams = new String JavaDoc [] { params[1].toString() };
90         else if (reason.equals("badOperandForUnaryOperator"))
91             msgParams = new String JavaDoc [] { params[0].toString() };
92         else if (reason.equals("unaryOperatorEvaluationError"))
93             msgParams = new String JavaDoc [] { params[1].toString() };
94         else if (reason.equals("unknownType"))
95             msgParams = new String JavaDoc [] { params[0].toString() };
96         else if (reason.equals("internalErrorResolvingType"))
97             msgParams = new String JavaDoc [] { params[0].toString() };
98         else if (reason.equals("instanceOfLeftOperandNotAReference"))
99             msgParams = new String JavaDoc [] { ((Value)params[0]).type().name() };
100         else if (reason.equals("conditionalOrAndBooleanOperandRequired"))
101             msgParams = new String JavaDoc [] { ((Value)params[0]).type().name() };
102         else if (reason.equals("conditionalQuestionMarkBooleanOperandRequired"))
103             msgParams = new String JavaDoc [] { ((Value)params[0]).type().name() };
104         else if (reason.equals("thisObjectUnavailable"))
105             msgParams = null;
106         else if (reason.equals("objectReferenceRequiredOnDereference"))
107             msgParams = new String JavaDoc [] { ((Value)params[0]).type().name() };
108         else if (reason.equals("badArgument"))
109             msgParams = new String JavaDoc [] { params[0].toString() };
110         else if (reason.equals("argumentsBadSyntax"))
111             msgParams = new String JavaDoc [] { params[0].toString() };
112         else if (reason.equals("ambigousMethod"))
113             msgParams = new String JavaDoc [] { ((Identifier)params[0]).typeContext.name(), ((Identifier)params[0]).identifier };
114         else if (reason.equals("noSuchMethod"))
115             msgParams = new String JavaDoc [] { ((Identifier)params[0]).typeContext.name(), ((Identifier)params[0]).identifier };
116         else if (reason.equals("callException"))
117             msgParams = new String JavaDoc [] { ((Identifier)params[1]).typeContext.name(), ((Identifier)params[1]).identifier, params[0].toString() };
118         else if (reason.equals("calleeException"))
119             msgParams = new String JavaDoc [] { ((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 JavaDoc [] { ((Value)params[0]).type().name() };
123         else if (reason.equals("notarray"))
124             msgParams = new String JavaDoc [] { params[0].toString() };
125         else if (reason.equals("arrayIndexNAN"))
126             msgParams = new String JavaDoc [] { params[1].toString() };
127         else if (reason.equals("arrayIndexOutOfBounds"))
128             msgParams = new String JavaDoc [] { params[1].toString(), Integer.toString(((ArrayReference)params[0]).length() - 1) };
129         else if (reason.equals("unknownVariable"))
130             msgParams = new String JavaDoc [] { ((Identifier)params[0]).identifier };
131         else if (reason.equals("integerLiteralTooBig"))
132             msgParams = new String JavaDoc [] { params[0].toString() };
133         else if (reason.equals("badFormatOfIntegerLiteral"))
134             msgParams = new String JavaDoc [] { params[0].toString() };
135         else if (reason.equals("unknownLiteralType"))
136             msgParams = new String JavaDoc [] { params[0].toString() };
137         else if (reason.equals("evaluateError"))
138 // return Assert.error(node, "evaluateError", value, ((Token) operators[i-1]).image, next);
139
msgParams = new String JavaDoc [] { params[1].toString(), params[0].toString(), params[2].toString() };
140         else if (reason.equals("notEnclosingType"))
141             msgParams = new String JavaDoc [] { ((Identifier)params[0]).typeContext.name(), ((Identifier)params[0]).superQualifier };
142         else if (reason.equals("accessInstanceVariableFromStaticContext"))
143             msgParams = new String JavaDoc [] { ((Identifier)params[0]).identifier };
144         else if (reason.equals("methodCallOnNull"))
145             msgParams = new String JavaDoc[] { 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 JavaDoc formatMessage(String JavaDoc msg, String JavaDoc [] params) {
157         ResourceBundle bundle = NbBundle.getBundle (EvaluationException.class);
158         msg = bundle.getString(msg);
159         return MessageFormat.format(msg, (Object JavaDoc[]) params);
160     }
161 }
162
Popular Tags