Path: blob/master/src/jdk.jcmd/share/classes/sun/tools/jstat/SyntaxException.java
41159 views
/*1* Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.tools.jstat;2627import java.io.StreamTokenizer;28import java.util.Set;29import java.util.Iterator;3031/**32* An exception class for syntax exceptions detected by the options file33* parser.34*35* @author Brian Doherty36* @since 1.537*/38@SuppressWarnings("serial") // JDK implementation class39public class SyntaxException extends ParserException {40private String message;4142public SyntaxException(String message) {43this.message = message;44}4546public SyntaxException(int lineno, String expected, String found) {47message = "Syntax error at line " + lineno48+ ": Expected " + expected49+ ", Found " + found;50}5152public SyntaxException(int lineno, String expected, Token found) {53message = "Syntax error at line " + lineno54+ ": Expected " + expected55+ ", Found " + found.toMessage();56}5758public SyntaxException(int lineno, Token expected, Token found) {59message = "Syntax error at line " + lineno60+ ": Expected " + expected.toMessage()61+ ", Found " + found.toMessage();62}6364public SyntaxException(int lineno, Set<String> expected, Token found) {65StringBuilder msg = new StringBuilder();6667msg.append("Syntax error at line ").append(lineno)68.append(": Expected one of \'");6970for (String keyWord : expected) {71msg.append(keyWord).append('|');72}73if (!expected.isEmpty()) {74msg.setLength(msg.length() - 1);75}7677message = msg.append("\', Found ").append(found.toMessage()).toString();78}7980public String getMessage() {81return message;82}83}84858687