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.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.concepts.Mutable;
21 * A configuration of {@link YangParser} wiring for use with {@link YangParserFactory}.
24 public final class YangParserConfiguration implements Immutable {
26 * System-wide default configuration.
28 public static final YangParserConfiguration DEFAULT = builder().build();
30 private final ImportResolutionMode importResolutionMode;
31 private final boolean retainDeclarationReferences;
33 private YangParserConfiguration(final ImportResolutionMode importResolutionMode,
34 final boolean retainDeclarationReferences) {
35 this.importResolutionMode = requireNonNull(importResolutionMode);
36 this.retainDeclarationReferences = retainDeclarationReferences;
40 public ImportResolutionMode importResolutionMode() {
41 return importResolutionMode;
44 public boolean retainDeclarationReferences() {
45 return retainDeclarationReferences;
49 public int hashCode() {
50 return Objects.hash(importResolutionMode, retainDeclarationReferences);
54 public boolean equals(final @Nullable Object obj) {
58 if (!(obj instanceof YangParserConfiguration)) {
61 final YangParserConfiguration other = (YangParserConfiguration) obj;
62 return importResolutionMode == other.importResolutionMode
63 && retainDeclarationReferences == other.retainDeclarationReferences;
67 public String toString() {
68 return MoreObjects.toStringHelper(this)
69 .add("importResolution", importResolutionMode)
70 .add("declarationReferences", retainDeclarationReferences)
74 public static Builder builder() {
78 public static final class Builder implements Mutable {
79 private ImportResolutionMode importResolutionMode = ImportResolutionMode.DEFAULT;
80 private boolean retainDeclarationReferences = false;
87 * Return a {@link YangParserConfiguration} initialized with contents of this builder.
89 * @return A YangParserConfiguration
91 public YangParserConfiguration build() {
92 return new YangParserConfiguration(importResolutionMode, retainDeclarationReferences);
96 public Builder importResolutionMode(final ImportResolutionMode newImportResolutionMode) {
97 importResolutionMode = requireNonNull(newImportResolutionMode);
101 public Builder retainDeclarationReferences(final boolean newRetainDeclarationReferences) {
102 retainDeclarationReferences = newRetainDeclarationReferences;