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.model.parser.api;
10 import java.util.Optional;
11 import org.eclipse.jdt.annotation.NonNull;
12 import org.eclipse.jdt.annotation.Nullable;
13 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
15 public class YangSyntaxErrorException extends YangParserException {
16 private static final long serialVersionUID = 2L;
18 private final SourceIdentifier source;
19 private final int line;
20 private final int charPositionInLine;
22 public YangSyntaxErrorException(final @Nullable SourceIdentifier source, final int line,
23 final int charPositionInLine, final String message) {
24 this(source, line, charPositionInLine, message, null);
27 public YangSyntaxErrorException(final @Nullable SourceIdentifier source, final int line,
28 final int charPositionInLine, final String message, final @Nullable Throwable cause) {
29 super(message, cause);
32 this.charPositionInLine = charPositionInLine;
35 public final Optional<SourceIdentifier> getSource() {
36 return Optional.ofNullable(source);
39 public final int getLine() {
43 public final int getCharPositionInLine() {
44 return charPositionInLine;
47 public @NonNull String getFormattedMessage() {
48 final StringBuilder sb = new StringBuilder(getMessage());
50 sb.append(" in source ");
54 sb.append(" on line ");
56 if (charPositionInLine != 0) {
57 sb.append(" character ");
58 sb.append(charPositionInLine);
65 public String toString() {
66 return this.getClass().getName() + ": " + getFormattedMessage();