jdk/src/share/classes/com/sun/tools/example/debug/expr/TokenMgrError.java
author malenkov
Tue, 29 Oct 2013 17:01:06 +0400
changeset 21278 ef8a3a2a72f2
parent 14342 8435a30053c1
child 22050 72e7501ac569
permissions -rw-r--r--
8022746: List of spelling errors in API doc Reviewed-by: alexsch, smarks
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
14342
8435a30053c1 7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents: 10292
diff changeset
     2
 * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
10292
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 9520
diff changeset
    26
/*
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 9520
diff changeset
    27
 * This source code is provided to illustrate the usage of a given feature
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 9520
diff changeset
    28
 * or technique and has been deliberately simplified. Additional steps
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 9520
diff changeset
    29
 * required for a production-quality application, such as security checks,
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 9520
diff changeset
    30
 * input validation and proper error handling, might not be present in
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 9520
diff changeset
    31
 * this sample code.
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 9520
diff changeset
    32
 */
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 9520
diff changeset
    33
ed7db6a12c2a 7067811: Update demo/sample code to state it should not be used for production
nloodin
parents: 9520
diff changeset
    34
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
/* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 0.7pre2 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
package com.sun.tools.example.debug.expr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
public class TokenMgrError extends Error
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
   /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    * Ordinals for various reasons why an Error of this type can be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
9520
99d378796e54 7029383: Refresh of non-client demos
nloodin
parents: 5506
diff changeset
    44
    private static final long serialVersionUID = -6236440836177601522L;
99d378796e54 7029383: Refresh of non-client demos
nloodin
parents: 5506
diff changeset
    45
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
   /**
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 14342
diff changeset
    47
    * Lexical error occurred.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
   static final int LEXICAL_ERROR = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    * An attempt wass made to create a second instance of a static token manager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
   static final int STATIC_LEXER_ERROR = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    * Tried to change to an invalid lexical state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
   static final int INVALID_LEXICAL_STATE = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    * Detected (and bailed out of) an infinite loop in the token manager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
   static final int LOOP_DETECTED = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    * Indicates the reason why the exception is thrown. It will have
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    * one of the above 4 values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
   int errorCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    * Replaces unprintable characters by their espaced (or unicode escaped)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    * equivalents in the given string
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
   protected static final String addEscapes(String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
      StringBuffer retval = new StringBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
      char ch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
      for (int i = 0; i < str.length(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        switch (str.charAt(i))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
           case 0 :
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
              continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
           case '\b':
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
              retval.append("\\b");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
              continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
           case '\t':
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
              retval.append("\\t");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
              continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
           case '\n':
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
              retval.append("\\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
              continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
           case '\f':
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
              retval.append("\\f");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
              continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
           case '\r':
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
              retval.append("\\r");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
              continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
           case '\"':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
              retval.append("\\\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
              continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
           case '\'':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
              retval.append("\\\'");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
              continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
           case '\\':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
              retval.append("\\\\");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
              continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
           default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
              if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                 String s = "0000" + Integer.toString(ch, 16);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                 retval.append("\\u" + s.substring(s.length() - 4, s.length()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
              } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                 retval.append(ch);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
              continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
      return retval.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    * Returns a detailed message for the Error when it is thrown by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    * token manager to indicate a lexical error.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    * Parameters :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    *    EOFSeen     : indicates if EOF caused the lexicl error
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 14342
diff changeset
   126
    *    curLexState : lexical state in which this error occurred
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 14342
diff changeset
   127
    *    errorLine   : line number when the error occurred
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 14342
diff changeset
   128
    *    errorColumn : column number when the error occurred
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 14342
diff changeset
   129
    *    errorAfter  : prefix that was seen before this error occurred
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    *    curchar     : the offending character
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    * Note: You can customize the lexical error message by modifying this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
   private static final String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
      return("Lexical error at line " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
           errorLine + ", column " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
           errorColumn + ".  Encountered: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
           (EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
           "after : \"" + addEscapes(errorAfter) + "\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    * You can also modify the body of this method to customize your error messages.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    * of end-users concern, so you can return something like :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    *     "Internal Error : Please file a bug report .... "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    * from this method for such cases in the release version of your parser.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    */
9520
99d378796e54 7029383: Refresh of non-client demos
nloodin
parents: 5506
diff changeset
   150
   @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
   public String getMessage() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
      return super.getMessage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
   /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    * Constructors of various flavors follow.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
   public TokenMgrError() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
   public TokenMgrError(String message, int reason) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
      super(message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
      errorCode = reason;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
   public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
      this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
}