2 * Copyright (c) 2021 PANTHEON.tech, s.r.o. 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 static java.util.Objects.requireNonNull;
12 import com.google.common.annotations.Beta;
13 import com.google.common.base.MoreObjects;
14 import java.util.Objects;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.opendaylight.yangtools.concepts.Immutable;
18 import org.opendaylight.yangtools.yang.model.repo.api.StatementParserMode;
21 * A configuration of {@link YangParser} wiring for use with {@link YangParserFactory}.
25 public final class YangParserConfiguration implements Immutable {
27 * System-wide default configuration.
29 public static final YangParserConfiguration DEFAULT = builder().build();
31 private final StatementParserMode parserMode;
32 private final boolean retainDeclarationReferences;
34 private YangParserConfiguration(final StatementParserMode parserMode, final boolean retainDeclarationReferences) {
35 this.parserMode = requireNonNull(parserMode);
36 this.retainDeclarationReferences = retainDeclarationReferences;
39 public StatementParserMode parserMode() {
43 public boolean retainDeclarationReferences() {
44 return retainDeclarationReferences;
48 public int hashCode() {
49 return Objects.hash(parserMode, retainDeclarationReferences);
53 public boolean equals(final @Nullable Object obj) {
57 if (!(obj instanceof YangParserConfiguration)) {
60 final YangParserConfiguration other = (YangParserConfiguration) obj;
61 return parserMode == other.parserMode && retainDeclarationReferences == other.retainDeclarationReferences;
65 public String toString() {
66 return MoreObjects.toStringHelper(this)
67 .add("parserMode", parserMode)
68 .add("retainDeclarationReferences", retainDeclarationReferences)
72 public static Builder builder() {
76 public static final class Builder implements org.opendaylight.yangtools.concepts.Builder<YangParserConfiguration> {
77 private StatementParserMode parserMode = StatementParserMode.DEFAULT_MODE;
78 private boolean retainDeclarationReferences = false;
85 public YangParserConfiguration build() {
86 return new YangParserConfiguration(parserMode, retainDeclarationReferences);
89 public Builder parserMode(final StatementParserMode newParserMode) {
90 this.parserMode = requireNonNull(newParserMode);
94 public Builder retainDeclarationReferences(final boolean newRetainDeclarationReferences) {
95 this.retainDeclarationReferences = newRetainDeclarationReferences;