import org.opendaylight.yangtools.yang.model.api.ConstraintMetaDefinition;
import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.DescriptionEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ErrorAppTagEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ErrorMessageEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ModifierEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.ReferenceEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.type.ModifierKind;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
@Beta
public abstract class AbstractConstraintEffectiveStatement<A, D extends DeclaredStatement<A>> extends
- DeclaredEffectiveStatementBase<A, D> implements ConstraintMetaDefinition {
- private final String description;
- private final String reference;
+ AbstractEffectiveDocumentedNodeWithoutStatus<A, D> implements ConstraintMetaDefinition {
private final String errorAppTag;
private final String errorMessage;
private final ModifierKind modifier;
protected AbstractConstraintEffectiveStatement(final StmtContext<A, D, ?> ctx) {
super(ctx);
- String descriptionInit = null;
- String referenceInit = null;
String errorAppTagInit = null;
String errorMessageInit = null;
ModifierKind modifierInit = null;
for (final EffectiveStatement<?, ?> stmt : effectiveSubstatements()) {
- if (stmt instanceof DescriptionEffectiveStatement) {
- descriptionInit = ((DescriptionEffectiveStatement) stmt).argument();
- }
- if (stmt instanceof ReferenceEffectiveStatement) {
- referenceInit = ((ReferenceEffectiveStatement) stmt).argument();
- }
if (stmt instanceof ErrorAppTagEffectiveStatement) {
errorAppTagInit = ((ErrorAppTagEffectiveStatement) stmt).argument();
}
}
}
- this.description = descriptionInit;
- this.reference = referenceInit;
this.errorAppTag = errorAppTagInit;
this.errorMessage = errorMessageInit;
this.modifier = modifierInit;
}
public final boolean isCustomizedStatement() {
- return this.description != null || this.reference != null || this.errorAppTag != null
+ return getDescription().isPresent() || getReference().isPresent() || this.errorAppTag != null
|| this.errorMessage != null || this.modifier != null;
}
- @Override
- public final Optional<String> getDescription() {
- return Optional.ofNullable(description);
- }
-
public final ModifierKind getModifier() {
return modifier;
}
- @Override
- public final Optional<String> getReference() {
- return Optional.ofNullable(reference);
- }
-
@Override
public final Optional<String> getErrorAppTag() {
return Optional.ofNullable(errorAppTag);
*/
package org.opendaylight.yangtools.yang.parser.rfc7950.stmt;
-import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.model.api.DocumentedNode;
import org.opendaylight.yangtools.yang.model.api.Status;
import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.DescriptionEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.ReferenceEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.StatusEffectiveStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+// FIXME: 5.0.0: rename to AbstractEffectiveDocumentedNodeWithStatus
public abstract class AbstractEffectiveDocumentedNode<A, D extends DeclaredStatement<A>>
- extends DeclaredEffectiveStatementBase<A, D> implements DocumentedNode.WithStatus {
-
- private final String description;
- private final String reference;
+ extends AbstractEffectiveDocumentedNodeWithoutStatus<A, D> implements DocumentedNode.WithStatus {
private final @NonNull Status status;
/**
*/
protected AbstractEffectiveDocumentedNode(final StmtContext<A, D, ?> ctx) {
super(ctx);
- description = findFirstEffectiveSubstatementArgument(DescriptionEffectiveStatement.class).orElse(null);
- reference = findFirstEffectiveSubstatementArgument(ReferenceEffectiveStatement.class).orElse(null);
status = findFirstEffectiveSubstatementArgument(StatusEffectiveStatement.class).orElse(Status.CURRENT);
}
- @Override
- public final Optional<String> getDescription() {
- return Optional.ofNullable(description);
- }
-
- @Override
- public final Optional<String> getReference() {
- return Optional.ofNullable(reference);
- }
-
@Override
public final Status getStatus() {
return status;
--- /dev/null
+/*
+ * Copyright (c) 2019 PANTHEON.tech, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.parser.rfc7950.stmt;
+
+import com.google.common.annotations.Beta;
+import java.util.Optional;
+import org.eclipse.jdt.annotation.Nullable;
+import org.opendaylight.yangtools.yang.model.api.DocumentedNode;
+import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.DescriptionEffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.ReferenceEffectiveStatement;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+
+@Beta
+//FIXME: 5.0.0: rename to AbstractEffectiveDocumentedNode
+public abstract class AbstractEffectiveDocumentedNodeWithoutStatus<A, D extends DeclaredStatement<A>>
+ extends DeclaredEffectiveStatementBase<A, D> implements DocumentedNode {
+
+ private final @Nullable String description;
+ private final @Nullable String reference;
+
+ protected AbstractEffectiveDocumentedNodeWithoutStatus(final StmtContext<A, D, ?> ctx) {
+ super(ctx);
+ description = findFirstEffectiveSubstatementArgument(DescriptionEffectiveStatement.class).orElse(null);
+ reference = findFirstEffectiveSubstatementArgument(ReferenceEffectiveStatement.class).orElse(null);
+ }
+
+ @Override
+ public final Optional<String> getDescription() {
+ return Optional.ofNullable(description);
+ }
+
+ @Override
+ public final Optional<String> getReference() {
+ return Optional.ofNullable(reference);
+ }
+
+ protected final @Nullable String nullableDescription() {
+ return description;
+ }
+
+ protected final @Nullable String nullableReference() {
+ return reference;
+ }
+}
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
-import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.concepts.Immutable;
import org.opendaylight.yangtools.yang.model.api.DeviateDefinition;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.DescriptionEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.DeviationEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.DeviationStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.ReferenceEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
-import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.DeclaredEffectiveStatementBase;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractEffectiveDocumentedNodeWithoutStatus;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
final class DeviationEffectiveStatementImpl
- extends DeclaredEffectiveStatementBase<SchemaNodeIdentifier, DeviationStatement>
+ extends AbstractEffectiveDocumentedNodeWithoutStatus<SchemaNodeIdentifier, DeviationStatement>
implements Deviation, DeviationEffectiveStatement, Immutable {
private final SchemaPath targetPath;
- private final String description;
- private final String reference;
private final @NonNull ImmutableList<UnknownSchemaNode> unknownSchemaNodes;
private final ImmutableList<DeviateDefinition> deviateDefinitions;
DeviationEffectiveStatementImpl(final StmtContext<SchemaNodeIdentifier, DeviationStatement, ?> ctx) {
super(ctx);
this.targetPath = ctx.getStatementArgument().asSchemaPath();
-
this.deviateDefinitions = ImmutableList.copyOf(allSubstatementsOfType(DeviateDefinition.class));
- description = findFirstEffectiveSubstatementArgument(DescriptionEffectiveStatement.class).orElse(null);
- reference = findFirstEffectiveSubstatementArgument(ReferenceEffectiveStatement.class).orElse(null);
-
List<UnknownSchemaNode> unknownSchemaNodesInit = new ArrayList<>();
for (final EffectiveStatement<?, ?> effectiveStatement : effectiveSubstatements()) {
if (effectiveStatement instanceof UnknownSchemaNode) {
return deviateDefinitions;
}
- @Override
- public Optional<String> getDescription() {
- return Optional.ofNullable(description);
- }
-
- @Override
- public Optional<String> getReference() {
- return Optional.ofNullable(reference);
- }
-
@Override
public List<UnknownSchemaNode> getUnknownSchemaNodes() {
return unknownSchemaNodes;
@Override
public int hashCode() {
- return Objects.hash(targetPath, deviateDefinitions, description, reference);
+ return Objects.hash(targetPath, deviateDefinitions, nullableDescription(), nullableReference());
}
@Override
final DeviationEffectiveStatementImpl other = (DeviationEffectiveStatementImpl) obj;
return Objects.equals(targetPath, other.targetPath)
&& Objects.equals(deviateDefinitions, other.deviateDefinitions)
- && Objects.equals(description, other.description) && Objects.equals(reference, other.reference);
+ && Objects.equals(nullableDescription(), other.nullableDescription())
+ && Objects.equals(nullableReference(), other.nullableReference());
}
@Override
return DeviationEffectiveStatementImpl.class.getSimpleName() + "["
+ "targetPath=" + targetPath
+ ", deviates=" + deviateDefinitions
- + ", description=" + description
- + ", reference=" + reference
+ + ", description=" + nullableDescription()
+ + ", reference=" + nullableReference()
+ "]";
}
}
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.model.api.ModuleImport;
-import org.opendaylight.yangtools.yang.model.api.stmt.DescriptionEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ImportEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ImportStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.PrefixEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.ReferenceEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.RevisionDateEffectiveStatement;
import org.opendaylight.yangtools.yang.model.repo.api.SemVerSourceIdentifier;
-import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.DeclaredEffectiveStatementBase;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractEffectiveDocumentedNodeWithoutStatus;
import org.opendaylight.yangtools.yang.parser.spi.meta.MissingSubstatementException;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
import org.opendaylight.yangtools.yang.parser.spi.source.ImportPrefixToSemVerSourceIdentifier;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
-final class ImportEffectiveStatementImpl extends DeclaredEffectiveStatementBase<String, ImportStatement>
+final class ImportEffectiveStatementImpl extends AbstractEffectiveDocumentedNodeWithoutStatus<String, ImportStatement>
implements ImportEffectiveStatement, ModuleImport {
private final String moduleName;
private final Revision revision;
private final SemVer semVer;
private final String prefix;
- private final String description;
- private final String reference;
ImportEffectiveStatementImpl(final StmtContext<String, ImportStatement, ?> ctx) {
super(ctx);
revision = importedModuleIdentifier.getRevision().orElse(null);
semVer = importedModuleIdentifier.getSemanticVersion().orElse(null);
}
-
- description = findFirstEffectiveSubstatementArgument(DescriptionEffectiveStatement.class).orElse(null);
- reference = findFirstEffectiveSubstatementArgument(ReferenceEffectiveStatement.class).orElse(null);
}
private Revision getImportedRevision(final StmtContext<String, ImportStatement, ?> ctx) {
return prefix;
}
- @Override
- public Optional<String> getDescription() {
- return Optional.ofNullable(description);
- }
-
- @Override
- public Optional<String> getReference() {
- return Optional.ofNullable(reference);
- }
-
@Override
public int hashCode() {
- return Objects.hash(moduleName, revision, prefix, semVer, description, reference);
+ return Objects.hash(moduleName, revision, prefix, semVer, nullableDescription(), nullableReference());
}
@Override
final ImportEffectiveStatementImpl other = (ImportEffectiveStatementImpl) obj;
return Objects.equals(moduleName, other.moduleName) && Objects.equals(revision, other.revision)
&& Objects.equals(semVer, other.semVer) && Objects.equals(prefix, other.prefix)
- && Objects.equals(description, other.description) && Objects.equals(reference, other.reference);
+ && Objects.equals(nullableDescription(), other.nullableDescription())
+ && Objects.equals(nullableReference(), other.nullableReference());
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this).omitNullValues().add("moduleName", getModuleName())
.add("revision", revision).add("version", semVer).add("prefix", getPrefix())
- .add("description", description).add("reference", reference).toString();
+ .add("description", nullableDescription()).add("reference", nullableReference()).toString();
}
}
*/
package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.revision;
-import java.util.Optional;
import org.opendaylight.yangtools.yang.common.Revision;
-import org.opendaylight.yangtools.yang.model.api.DocumentedNode;
-import org.opendaylight.yangtools.yang.model.api.stmt.DescriptionEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.ReferenceEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.RevisionEffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.RevisionStatement;
-import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.DeclaredEffectiveStatementBase;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractEffectiveDocumentedNodeWithoutStatus;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-final class RevisionEffectiveStatementImpl extends DeclaredEffectiveStatementBase<Revision, RevisionStatement>
- implements DocumentedNode, RevisionEffectiveStatement {
-
- private final String reference;
- private final String description;
-
+final class RevisionEffectiveStatementImpl
+ extends AbstractEffectiveDocumentedNodeWithoutStatus<Revision, RevisionStatement>
+ implements RevisionEffectiveStatement {
RevisionEffectiveStatementImpl(final StmtContext<Revision, RevisionStatement, ?> ctx) {
super(ctx);
- description = findFirstEffectiveSubstatementArgument(DescriptionEffectiveStatement.class).orElse(null);
- reference = findFirstEffectiveSubstatementArgument(ReferenceEffectiveStatement.class).orElse(null);
- }
-
- @Override
- public Optional<String> getDescription() {
- return Optional.ofNullable(description);
- }
-
- @Override
- public Optional<String> getReference() {
- return Optional.ofNullable(reference);
}
}