Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/tools/jstat/SyntaxException.java
38918 views
/*1* Copyright (c) 2004, 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*/38public class SyntaxException extends ParserException {39private String message;4041public SyntaxException(String message) {42this.message = message;43}4445public SyntaxException(int lineno, String expected, String found) {46message = "Syntax error at line " + lineno47+ ": Expected " + expected48+ ", Found " + found;49}5051public SyntaxException(int lineno, String expected, Token found) {52message = "Syntax error at line " + lineno53+ ": Expected " + expected54+ ", Found " + found.toMessage();55}5657public SyntaxException(int lineno, Token expected, Token found) {58message = "Syntax error at line " + lineno59+ ": Expected " + expected.toMessage()60+ ", Found " + found.toMessage();61}6263public SyntaxException(int lineno, Set expected, Token found) {64StringBuilder msg = new StringBuilder();6566msg.append("Syntax error at line " + lineno + ": Expected one of \'");6768boolean first = true;69for (Iterator i = expected.iterator(); i.hasNext(); /* empty */) {70String keyWord = (String)i.next();71if (first) {72msg.append(keyWord);73first = false;74} else {75msg.append("|" + keyWord);76}77}7879msg.append("\', Found " + found.toMessage());80message = msg.toString();81}8283public String getMessage() {84return message;85}86}878889