Bug 5077: Codes break the security rules
[nemo.git] / nemo-impl / src / main / java / org / opendaylight / nemo / user / vnspacemanager / languagestyle / NEMOParse / ParseException.java
1 /*\r
2  * Copyright (c) 2015 Huawei, Inc. and others. All rights reserved.\r
3  *\r
4  * This program and the accompanying materials are made available under the\r
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
6  * and is available at http://www.eclipse.org/legal/epl-v10.html\r
7  */\r
8 /* Generated By:JavaCC: Do not edit this line. ParseException.java Version 5.0 */\r
9 /* JavaCCOptions:KEEP_LINE_COL=null */\r
10 package org.opendaylight.nemo.user.vnspacemanager.languagestyle.NEMOParse;\r
11 import java.util.Arrays;\r
12 \r
13 /**\r
14  * This exception is thrown when parse errors are encountered.\r
15  * You can explicitly create objects of this exception type by\r
16  * calling the method generateParseException in the generated\r
17  * parser.\r
18  *\r
19  * You can modify this class to customize your error reporting\r
20  * mechanisms so long as you retain the public fields.\r
21  */\r
22 public class ParseException extends Exception {\r
23 \r
24   /**\r
25    * The version identifier for this Serializable class.\r
26    * Increment only if the <i>serialized</i> form of the\r
27    * class changes.\r
28    */\r
29   private static final long serialVersionUID = 1L;\r
30 \r
31   /**\r
32    * This constructor is used by the method "generateParseException"\r
33    * in the generated parser.  Calling this constructor generates\r
34    * a new object of this type with the fields "currentToken",\r
35    * "expectedTokenSequences", and "tokenImage" set.\r
36    */\r
37   public ParseException(Token currentTokenVal,\r
38                         int[][] expectedTokenSequencesVal,\r
39                         String[] tokenImageVal\r
40                        )\r
41   {\r
42 \r
43       super(initialise(currentTokenVal, expectedTokenSequencesVal, tokenImageVal));\r
44       this.currentToken = currentTokenVal;\r
45       this.tokenImage = Arrays.copyOf(tokenImageVal,tokenImageVal.length);\r
46       this.expectedTokenSequences = Arrays.copyOf(expectedTokenSequencesVal,expectedTokenSequencesVal.length);\r
47 //    currentToken = currentTokenVal;\r
48 //    expectedTokenSequences = expectedTokenSequencesVal;\r
49 //    tokenImage = tokenImageVal;\r
50   }\r
51 \r
52   /**\r
53    * The following constructors are for use by you for whatever\r
54    * purpose you can think of.  Constructing the exception in this\r
55    * manner makes the exception behave in the normal way - i.e., as\r
56    * documented in the class "Throwable".  The fields "errorToken",\r
57    * "expectedTokenSequences", and "tokenImage" do not contain\r
58    * relevant information.  The JavaCC generated code does not use\r
59    * these constructors.\r
60    */\r
61 \r
62   public ParseException() {\r
63     super();\r
64   }\r
65 \r
66   /** Constructor with message. */\r
67   public ParseException(String message) {\r
68     super(message);\r
69   }\r
70 \r
71 \r
72   /**\r
73    * This is the last token that has been consumed successfully.  If\r
74    * this object has been created due to a parse error, the token\r
75    * followng this token will (therefore) be the first error token.\r
76    */\r
77   public Token currentToken;\r
78 \r
79   /**\r
80    * Each entry in this array is an array of integers.  Each array\r
81    * of integers represents a sequence of tokens (by their ordinal\r
82    * values) that is expected at this point of the parse.\r
83    */\r
84   public int[][] expectedTokenSequences;\r
85 \r
86   /**\r
87    * This is a reference to the "tokenImage" array of the generated\r
88    * parser within which the parse error occurred.  This array is\r
89    * defined in the generated ...Constants interface.\r
90    */\r
91   public String[] tokenImage;\r
92 \r
93   /**\r
94    * It uses "currentToken" and "expectedTokenSequences" to generate a parse\r
95    * error message and returns it.  If this object has been created\r
96    * due to a parse error, and you do not catch it (it gets thrown\r
97    * from the parser) the correct error message\r
98    * gets displayed.\r
99    */\r
100   private static String initialise(Token currentToken,\r
101                            int[][] expectedTokenSequences,\r
102                            String[] tokenImage) {\r
103     String eol = System.getProperty("line.separator", "\n");\r
104     StringBuffer expected = new StringBuffer();\r
105     int maxSize = 0;\r
106     for (int i = 0; i < expectedTokenSequences.length; i++) {\r
107       if (maxSize < expectedTokenSequences[i].length) {\r
108         maxSize = expectedTokenSequences[i].length;\r
109       }\r
110       for (int j = 0; j < expectedTokenSequences[i].length; j++) {\r
111         expected.append(tokenImage[expectedTokenSequences[i][j]]).append(' ');\r
112       }\r
113       if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) {\r
114         expected.append("...");\r
115       }\r
116       expected.append(eol).append("    ");\r
117     }\r
118     String retval = "Encountered \"";\r
119     Token tok = currentToken.next;\r
120     for (int i = 0; i < maxSize; i++) {\r
121       if (i != 0) retval += " ";\r
122       if (tok.kind == 0) {\r
123         retval += tokenImage[0];\r
124         break;\r
125       }\r
126       retval += " " + tokenImage[tok.kind];\r
127       retval += " \"";\r
128       retval += add_escapes(tok.image);\r
129       retval += " \"";\r
130       tok = tok.next;\r
131     }\r
132     retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn;\r
133     retval += "." + eol;\r
134     if (expectedTokenSequences.length == 1) {\r
135       retval += "Was expecting:" + eol + "    ";\r
136     } else {\r
137       retval += "Was expecting one of:" + eol + "    ";\r
138     }\r
139     retval += expected.toString();\r
140     return retval;\r
141   }\r
142 \r
143   /**\r
144    * The end of line string for this machine.\r
145    */\r
146   protected String eol = System.getProperty("line.separator", "\n");\r
147 \r
148   /**\r
149    * Used to convert raw characters to their escaped version\r
150    * when these raw version cannot be used as part of an ASCII\r
151    * string literal.\r
152    */\r
153   static String add_escapes(String str) {\r
154       StringBuffer retval = new StringBuffer();\r
155       char ch;\r
156       for (int i = 0; i < str.length(); i++) {\r
157         switch (str.charAt(i))\r
158         {\r
159            case 0 :\r
160               continue;\r
161            case '\b':\r
162               retval.append("\\b");\r
163               continue;\r
164            case '\t':\r
165               retval.append("\\t");\r
166               continue;\r
167            case '\n':\r
168               retval.append("\\n");\r
169               continue;\r
170            case '\f':\r
171               retval.append("\\f");\r
172               continue;\r
173            case '\r':\r
174               retval.append("\\r");\r
175               continue;\r
176            case '\"':\r
177               retval.append("\\\"");\r
178               continue;\r
179            case '\'':\r
180               retval.append("\\\'");\r
181               continue;\r
182            case '\\':\r
183               retval.append("\\\\");\r
184               continue;\r
185            default:\r
186               if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {\r
187                  String s = "0000" + Integer.toString(ch, 16);\r
188                  retval.append("\\u" + s.substring(s.length() - 4, s.length()));\r
189               } else {\r
190                  retval.append(ch);\r
191               }\r
192               continue;\r
193         }\r
194       }\r
195       return retval.toString();\r
196    }\r
197 \r
198 }\r
199 /* JavaCC - OriginalChecksum=e5e4e351aea2c3ff97c4b9bdac453a62 (do not edit this line) */\r