--- /dev/null
+/*
+ * Copyright (c) 2022 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.model.api.meta;
+
+import com.google.common.collect.ImmutableList;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.yang.common.Empty;
+
+/**
+ * Abstract base class for {@link DeclaredStatement} implementations.
+ *
+ * @param <A> Argument type ({@link Empty} if statement does not have argument.)
+ */
+public abstract non-sealed class AbstractDeclaredStatement<A> extends AbstractModelStatement<A>
+ implements DeclaredStatement<A> {
+ /**
+ * Utility method for recovering singleton lists squashed by {@link #maskList(ImmutableList)}.
+ *
+ * @param masked list to unmask
+ * @return Unmasked list
+ * @throws NullPointerException if masked is null
+ * @throws ClassCastException if masked object does not match DeclaredStatement
+ */
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ protected static final @NonNull ImmutableList<? extends DeclaredStatement<?>> unmaskList(
+ final @NonNull Object masked) {
+ return (ImmutableList) unmaskList(masked, DeclaredStatement.class);
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2022 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.model.api.meta;
+
+import com.google.common.collect.ImmutableList;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.yang.common.Empty;
+
+/**
+ * Abstract base class for {@link EffectiveStatement} implementations.
+ *
+ * @param <A> Argument type ({@link Empty} if statement does not have argument.)
+ * @param <D> Class representing declared version of this statement.
+ */
+public abstract non-sealed class AbstractEffectiveStatement<A, D extends DeclaredStatement<A>>
+ extends AbstractModelStatement<A> implements EffectiveStatement<A, D> {
+ /**
+ * Utility method for recovering singleton lists squashed by {@link #maskList(ImmutableList)}.
+ *
+ * @param masked list to unmask
+ * @return Unmasked list
+ * @throws NullPointerException if masked is null
+ * @throws ClassCastException if masked object does not match EffectiveStatement
+ */
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ protected static final @NonNull ImmutableList<? extends @NonNull EffectiveStatement<?, ?>> unmaskList(
+ final @NonNull Object masked) {
+ return (ImmutableList) unmaskList(masked, EffectiveStatement.class);
+ }
+}
* 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.model.spi.meta;
+package org.opendaylight.yangtools.yang.model.api.meta;
import com.google.common.base.MoreObjects;
import com.google.common.base.MoreObjects.ToStringHelper;
import com.google.common.collect.ImmutableSet;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.common.Empty;
-import org.opendaylight.yangtools.yang.model.api.meta.ModelStatement;
/**
* Abstract base class for {@link ModelStatement} implementations. It mostly provides static methods for efficiently
*
* @param <A> Argument type ({@link Empty} if statement does not have argument.)
*/
-abstract class AbstractModelStatement<A> implements ModelStatement<A> {
-
+abstract sealed class AbstractModelStatement<A> implements ModelStatement<A>
+ permits AbstractDeclaredStatement, AbstractEffectiveStatement {
@Override
public final int hashCode() {
return System.identityHashCode(this);
*
* @param <A> Argument type ({@link Empty} if statement does not have argument.)
*/
-public interface DeclaredStatement<A> extends ModelStatement<A> {
+public non-sealed interface DeclaredStatement<A> extends ModelStatement<A> {
/**
* Returns statement argument as was present in original source.
*
* @param <A> Argument type ({@link Empty} if statement does not have argument.)
* @param <D> Class representing declared version of this statement.
*/
-public interface EffectiveStatement<A, D extends DeclaredStatement<A>> extends ModelStatement<A> {
+public non-sealed interface EffectiveStatement<A, D extends DeclaredStatement<A>> extends ModelStatement<A> {
/**
* Returns {@link StatementOrigin}, which denotes if statement was explicitly declared in original model or inferred
* during semantic processing of model.
*
* @param <A> Argument type ({@link Empty} if statement does not have argument.)
*/
-// FIXME: sealed interface when we have JDK17+
-public interface ModelStatement<A> {
+public sealed interface ModelStatement<A> permits DeclaredStatement, EffectiveStatement, AbstractModelStatement {
/**
* Statement Definition of this statement.
*
requires org.slf4j;
// Annotations
+ requires static com.github.spotbugs.annotations;
requires static transitive org.eclipse.jdt.annotation;
}
* @param <D> Class representing declared version of this statement.
*/
@Beta
-public abstract class AbstractDeclaredEffectiveStatement<A, D extends DeclaredStatement<A>>
- extends AbstractEffectiveStatement<A, D> {
+public abstract non-sealed class AbstractDeclaredEffectiveStatement<A, D extends DeclaredStatement<A>>
+ extends AbstractIndexedEffectiveStatement<A, D> {
@Override
public abstract @NonNull D getDeclared();
import com.google.common.annotations.Beta;
import com.google.common.collect.ImmutableList;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.common.Empty;
import org.opendaylight.yangtools.yang.common.QName;
* stateful subclasses.
*/
@Beta
-public abstract class AbstractDeclaredStatement<A> extends AbstractModelStatement<A> implements DeclaredStatement<A> {
+@SuppressFBWarnings(value = "NM_SAME_SIMPLE_NAME_AS_SUPERCLASS", justification = "Migration")
+public abstract class AbstractDeclaredStatement<A>
+ extends org.opendaylight.yangtools.yang.model.api.meta.AbstractDeclaredStatement<A> {
@Override
public ImmutableList<? extends DeclaredStatement<?>> declaredSubstatements() {
// Default to reduce load on subclasses and keep the number of implementations down
return ImmutableList.of();
}
- /**
- * Utility method for recovering singleton lists squashed by {@link #maskList(ImmutableList)}.
- *
- * @param masked list to unmask
- * @return Unmasked list
- * @throws NullPointerException if masked is null
- * @throws ClassCastException if masked object does not match DeclaredStatement
- */
- @SuppressWarnings({ "rawtypes", "unchecked" })
- protected static final @NonNull ImmutableList<? extends DeclaredStatement<?>> unmaskList(
- final @NonNull Object masked) {
- return (ImmutableList) unmaskList(masked, DeclaredStatement.class);
- }
-
public abstract static class WithRawArgument<A> extends AbstractDeclaredStatement<A> {
public abstract static class WithSubstatements<A> extends WithRawArgument<A> {
private final @NonNull Object substatements;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.common.Empty;
import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.meta.AbstractEffectiveStatement;
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.meta.IdentifierNamespace;
* @param <A> Argument type ({@link Empty} if statement does not have argument.)
* @param <D> Class representing declared version of this statement.
*/
-abstract class AbstractEffectiveStatement<A, D extends DeclaredStatement<A>>
- extends AbstractModelStatement<A> implements EffectiveStatement<A, D> {
+abstract sealed class AbstractIndexedEffectiveStatement<A, D extends DeclaredStatement<A>>
+ extends AbstractEffectiveStatement<A, D>
+ permits AbstractDeclaredEffectiveStatement, AbstractUndeclaredEffectiveStatement {
@Override
public final <K, V, N extends IdentifierNamespace<K, V>> Optional<V> get(final Class<N> namespace,
final K identifier) {
return Optional.empty();
}
- /**
- * Utility method for recovering singleton lists squashed by {@link #maskList(ImmutableList)}.
- *
- * @param masked list to unmask
- * @return Unmasked list
- * @throws NullPointerException if masked is null
- * @throws ClassCastException if masked object does not match EffectiveStatement
- */
- @SuppressWarnings({ "rawtypes", "unchecked" })
- protected static final @NonNull ImmutableList<? extends @NonNull EffectiveStatement<?, ?>> unmaskList(
- final @NonNull Object masked) {
- return (ImmutableList) unmaskList(masked, EffectiveStatement.class);
- }
-
// TODO: below methods need to find a better place, this is just a temporary hideout as their public class is on
// its way out
/**
import org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeEffectiveStatement;
@Beta
-public abstract class AbstractUndeclaredEffectiveStatement<A, D extends DeclaredStatement<A>>
- extends AbstractEffectiveStatement<A, D> {
+public abstract non-sealed class AbstractUndeclaredEffectiveStatement<A, D extends DeclaredStatement<A>>
+ extends AbstractIndexedEffectiveStatement<A, D> {
@Override
public final D getDeclared() {
return null;
package org.opendaylight.yangtools.yang.model.spi.meta;
import com.google.common.annotations.Beta;
+import com.google.common.collect.ForwardingObject;
import java.util.List;
import java.util.Optional;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.model.api.meta.DeclarationReference;
import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
+import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
/**
* Common base class for forwarding implementations of {@link DeclaredStatement}.
*/
@Beta
public abstract class ForwardingDeclaredStatement<A, D extends DeclaredStatement<A>>
- extends ForwardingModelStatement<A, D> implements DeclaredStatement<A> {
+ extends ForwardingObject implements DeclaredStatement<A> {
+ @Override
+ public StatementDefinition statementDefinition() {
+ return delegate().statementDefinition();
+ }
+
+ @Override
+ public A argument() {
+ return delegate().argument();
+ }
+
@Override
public String rawArgument() {
return delegate().rawArgument();
+++ /dev/null
-/*
- * Copyright (c) 2021 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.model.spi.meta;
-
-import com.google.common.collect.ForwardingObject;
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.yang.model.api.meta.ModelStatement;
-import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
-
-/**
- * Common base class for forwarding implementations of {@link ModelStatement}.
- */
-public abstract class ForwardingModelStatement<A, S extends ModelStatement<A>> extends ForwardingObject
- implements ModelStatement<A> {
- @Override
- public StatementDefinition statementDefinition() {
- return delegate().statementDefinition();
- }
-
- @Override
- public A argument() {
- return delegate().argument();
- }
-
- @Override
- protected abstract @NonNull S delegate();
-}
import com.google.common.annotations.Beta;
/**
- * Exception thrown when indexing of substatements of a {@link AbstractEffectiveStatement} fails.
+ * Exception thrown when indexing of substatements of either a {@link AbstractDeclaredEffectiveStatement} or
+ * {@link AbstractUndeclaredEffectiveStatement} fails.
*/
@Beta
public final class SubstatementIndexingException extends IllegalArgumentException {