2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.parser.api;
10 import com.google.common.annotations.Beta;
11 import java.util.Optional;
12 import org.eclipse.jdt.annotation.NonNull;
13 import org.eclipse.jdt.annotation.Nullable;
14 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
17 public class YangSyntaxErrorException extends YangParserException {
18 private static final long serialVersionUID = 2L;
20 private final SourceIdentifier source;
21 private final int line;
22 private final int charPositionInLine;
24 public YangSyntaxErrorException(final @Nullable SourceIdentifier source, final int line,
25 final int charPositionInLine, final String message) {
26 this(source, line, charPositionInLine, message, null);
29 public YangSyntaxErrorException(final @Nullable SourceIdentifier source, final int line,
30 final int charPositionInLine, final String message, final @Nullable Throwable cause) {
31 super(message, cause);
34 this.charPositionInLine = charPositionInLine;
37 public final Optional<SourceIdentifier> getSource() {
38 return Optional.ofNullable(source);
41 public final int getLine() {
45 public final int getCharPositionInLine() {
46 return charPositionInLine;
49 public @NonNull String getFormattedMessage() {
50 final StringBuilder sb = new StringBuilder(getMessage());
52 sb.append(" in source ").append(source);
55 sb.append(" on line ").append(line);
56 if (charPositionInLine != 0) {
57 sb.append(" character ").append(charPositionInLine);
64 public String toString() {
65 return this.getClass().getName() + ": " + getFormattedMessage();