Do not expose StmtContext to StatementFactory
[yangtools.git] / parser / yang-parser-spi / src / main / java / org / opendaylight / yangtools / yang / parser / spi / meta / StatementFactory.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.parser.spi.meta;
9
10 import java.util.Collection;
11 import java.util.stream.Stream;
12 import org.eclipse.jdt.annotation.NonNull;
13 import org.eclipse.jdt.annotation.Nullable;
14 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
15 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
16 import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
17
18 /**
19  * An entity capable of creating {@link DeclaredStatement} and {@link EffectiveStatement} instances for a particular
20  * type. This interface is usually realized as an implementation-specific combination with {@link StatementSupport}.
21  *
22  * @param <A> Argument type
23  * @param <D> Declared Statement representation
24  * @param <E> Effective Statement representation
25  */
26 public interface StatementFactory<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>> {
27     /**
28      * Create a {@link DeclaredStatement} for specified context.
29      *
30      * @param ctx Statement context
31      * @param substatements Declared substatements
32      * @return A declared statement instance.
33      */
34     @NonNull D createDeclared(@NonNull BoundStmtCtx<A> ctx, @NonNull Stream<DeclaredStatement<?>> substatements);
35
36     /**
37      * Create a {@link EffectiveStatement} for specified context.
38      *
39      * @param stmt Effective capture of this statement's significant state
40      * @param declaredSubstatements effectively-visible declared substatements
41      * @param inferredSubstatements effectively-visible inferred substatements
42      * @return An effective statement instance
43      */
44     // FIXME: we really want a single coherent 'effectiveSubstatements' stream
45     @NonNull E createEffective(@NonNull Current<A, D> stmt,
46         Stream<? extends StmtContext<?, ?, ?>> declaredSubstatements,
47         Stream<? extends StmtContext<?, ?, ?>> inferredSubstatements);
48
49     /**
50      * Create a {@link EffectiveStatement} copy of provided original for specified context.
51      *
52      * @param stmt Effective capture of this statement's significant state
53      * @param original Original effective statement
54      * @return An effective statement instance
55      * @throws NullPointerException if any argument is null
56      */
57     @NonNull E copyEffective(@NonNull Current<A, D> stmt, @NonNull E original);
58
59     /**
60      * Determine reactor copy behaviour of a statement instance. Implementations classes are required to determine
61      * their operations with regard to their statements being replicated into different contexts -- potentially sharing
62      * instantiations.
63      *
64      * <p>
65      * Implementations are examine {@code copy} as to whether it would result in the same semantics as {@code current}
66      * does, provided that {@code current}'s {@code substatements} are properly propagated.
67      *
68      * @param copy Copy of current effective context
69      * @param current Current effective context
70      * @param substatements Current effective substatements
71      * @return True if the differences between {@code copy} and {@code current} do not affect this statement's effective
72      *         semantics.
73      * @throws NullPointerException if any argument is null
74      */
75     boolean canReuseCurrent(@NonNull Current<A, D> copy, @NonNull Current<A, D> current,
76         @NonNull Collection<? extends EffectiveStatement<?, ?>> substatements);
77
78     /**
79      * Return the {@link EffectiveStatementState} for a particular statement. This acts as a summary for comparison with
80      * statements created by this factory, without taking substatements into account. This is an optional operation, it
81      * is always safe to return null.
82      *
83      * @param stmt EffectiveStatement to examine
84      * @return EffectiveStatementState or null if the statement cannot be expressed
85      */
86     @Nullable EffectiveStatementState extractEffectiveState(@NonNull E stmt);
87 }