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;
20 * A configuration of {@link YangParser} wiring for use with {@link YangParserFactory}.
23 public final class YangParserConfiguration implements Immutable {
25 * System-wide default configuration.
27 public static final YangParserConfiguration DEFAULT = builder().build();
29 private final ImportResolutionMode importResolutionMode;
30 private final boolean retainDeclarationReferences;
32 private YangParserConfiguration(final ImportResolutionMode importResolutionMode,
33 final boolean retainDeclarationReferences) {
34 this.importResolutionMode = requireNonNull(importResolutionMode);
35 this.retainDeclarationReferences = retainDeclarationReferences;
39 public ImportResolutionMode importResolutionMode() {
40 return importResolutionMode;
43 public boolean retainDeclarationReferences() {
44 return retainDeclarationReferences;
48 public int hashCode() {
49 return Objects.hash(importResolutionMode, retainDeclarationReferences);
53 public boolean equals(final @Nullable Object obj) {
57 if (!(obj instanceof YangParserConfiguration)) {
60 final YangParserConfiguration other = (YangParserConfiguration) obj;
61 return importResolutionMode == other.importResolutionMode
62 && retainDeclarationReferences == other.retainDeclarationReferences;
66 public String toString() {
67 return MoreObjects.toStringHelper(this)
68 .add("importResolution", importResolutionMode)
69 .add("declarationReferences", retainDeclarationReferences)
73 public static Builder builder() {
77 public static final class Builder implements org.opendaylight.yangtools.concepts.Builder<YangParserConfiguration> {
78 private ImportResolutionMode importResolutionMode = ImportResolutionMode.DEFAULT;
79 private boolean retainDeclarationReferences = false;
86 public YangParserConfiguration build() {
87 return new YangParserConfiguration(importResolutionMode, retainDeclarationReferences);
91 public Builder importResolutionMode(final ImportResolutionMode newImportResolutionMode) {
92 this.importResolutionMode = requireNonNull(newImportResolutionMode);
96 public Builder retainDeclarationReferences(final boolean newRetainDeclarationReferences) {
97 this.retainDeclarationReferences = newRetainDeclarationReferences;