5d9358402e7df59e76895fa157e93f0a98396474
[yangtools.git] / yang / yang-parser-rfc7950 / src / main / java / org / opendaylight / yangtools / yang / parser / rfc7950 / stmt / EffectiveStatementMixins.java
1 /*
2  * Copyright (c) 2020 PANTHEON.tech, s.r.o. 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.rfc7950.stmt;
9
10 import com.google.common.annotations.Beta;
11 import com.google.common.base.MoreObjects;
12 import com.google.common.base.Strings;
13 import com.google.common.collect.Collections2;
14 import com.google.common.collect.ImmutableSet;
15 import java.util.Collection;
16 import java.util.Optional;
17 import org.eclipse.jdt.annotation.NonNull;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.eclipse.jdt.annotation.Nullable;
20 import org.opendaylight.yangtools.concepts.Immutable;
21 import org.opendaylight.yangtools.concepts.Mutable;
22 import org.opendaylight.yangtools.yang.common.QName;
23 import org.opendaylight.yangtools.yang.model.api.ActionDefinition;
24 import org.opendaylight.yangtools.yang.model.api.ActionNodeContainer;
25 import org.opendaylight.yangtools.yang.model.api.AddedByUsesAware;
26 import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
27 import org.opendaylight.yangtools.yang.model.api.AugmentationTarget;
28 import org.opendaylight.yangtools.yang.model.api.ConstraintMetaDefinition;
29 import org.opendaylight.yangtools.yang.model.api.ContainerLike;
30 import org.opendaylight.yangtools.yang.model.api.CopyableNode;
31 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
32 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
33 import org.opendaylight.yangtools.yang.model.api.DerivableSchemaNode;
34 import org.opendaylight.yangtools.yang.model.api.DocumentedNode;
35 import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
36 import org.opendaylight.yangtools.yang.model.api.InputSchemaNode;
37 import org.opendaylight.yangtools.yang.model.api.MandatoryAware;
38 import org.opendaylight.yangtools.yang.model.api.MustConstraintAware;
39 import org.opendaylight.yangtools.yang.model.api.MustDefinition;
40 import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
41 import org.opendaylight.yangtools.yang.model.api.NotificationNodeContainer;
42 import org.opendaylight.yangtools.yang.model.api.OperationDefinition;
43 import org.opendaylight.yangtools.yang.model.api.OutputSchemaNode;
44 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
45 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
46 import org.opendaylight.yangtools.yang.model.api.Status;
47 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
48 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
49 import org.opendaylight.yangtools.yang.model.api.UsesNode;
50 import org.opendaylight.yangtools.yang.model.api.WhenConditionAware;
51 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
52 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
53 import org.opendaylight.yangtools.yang.model.api.stmt.DescriptionEffectiveStatement;
54 import org.opendaylight.yangtools.yang.model.api.stmt.ErrorAppTagEffectiveStatement;
55 import org.opendaylight.yangtools.yang.model.api.stmt.ErrorMessageEffectiveStatement;
56 import org.opendaylight.yangtools.yang.model.api.stmt.InputEffectiveStatement;
57 import org.opendaylight.yangtools.yang.model.api.stmt.OutputEffectiveStatement;
58 import org.opendaylight.yangtools.yang.model.api.stmt.ReferenceEffectiveStatement;
59 import org.opendaylight.yangtools.yang.model.api.stmt.StatusEffectiveStatement;
60 import org.opendaylight.yangtools.yang.model.api.stmt.TypedefEffectiveStatement;
61 import org.opendaylight.yangtools.yang.model.api.stmt.WhenEffectiveStatement;
62 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.EffectiveStatementMixins.EffectiveStatementWithFlags.FlagsBuilder;
63 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
64 import org.opendaylight.yangtools.yang.parser.spi.meta.CopyHistory;
65 import org.opendaylight.yangtools.yang.parser.spi.meta.SchemaPathSupport;
66 import org.opendaylight.yangtools.yang.xpath.api.YangXPathExpression.QualifiedBound;
67
68 /**
69  * Mix-in interfaces providing services required by SchemaNode et al. These interfaces provide implementations, or
70  * implementation helpers based on default methods, so the correct behavior can be logically centralized.
71  */
72 @Beta
73 public final class EffectiveStatementMixins {
74     // Marker interface requiring all mixins to be derived from EffectiveStatement.
75     private interface Mixin<A, D extends DeclaredStatement<A>> extends EffectiveStatement<A, D> {
76         @SuppressWarnings("unchecked")
77         default <T> @NonNull Collection<? extends @NonNull T> filterEffectiveStatements(final Class<T> type) {
78             // Yeah, this is not nice, but saves one transformation
79             return (Collection<? extends T>) Collections2.filter(effectiveSubstatements(), type::isInstance);
80         }
81     }
82
83     /**
84      * Bridge between {@link EffectiveStatement} and {@link AugmentationTarget}.
85      *
86      * @param <A> Argument type ({@link Void} if statement does not have argument.)
87      * @param <D> Class representing declared version of this statement.
88      */
89     public interface AugmentationTargetMixin<A, D extends DeclaredStatement<A>>
90             extends Mixin<A, D>, AugmentationTarget {
91         @Override
92         default Collection<? extends AugmentationSchemaNode> getAvailableAugmentations() {
93             return filterEffectiveStatements(AugmentationSchemaNode.class);
94         }
95     }
96
97     /**
98      * Bridge between {@link EffectiveStatementWithFlags} and {@link AddedByUsesAware}.
99      *
100      * @param <A> Argument type ({@link Void} if statement does not have argument.)
101      * @param <D> Class representing declared version of this statement.
102      */
103     public interface AddedByUsesMixin<A, D extends DeclaredStatement<A>>
104             extends EffectiveStatementWithFlags<A, D>, AddedByUsesAware {
105         @Override
106         @Deprecated
107         default boolean isAddedByUses() {
108             return (flags() & FlagsBuilder.ADDED_BY_USES) != 0;
109         }
110     }
111
112     /**
113      * Bridge between {@link EffectiveStatementWithFlags} and {@link ActionNodeContainer}.
114      *
115      * @param <A> Argument type ({@link Void} if statement does not have argument.)
116      * @param <D> Class representing declared version of this statement.
117      */
118     public interface ActionNodeContainerMixin<A, D extends DeclaredStatement<A>>
119             extends Mixin<A, D>, ActionNodeContainer {
120         @Override
121         default Collection<? extends ActionDefinition> getActions() {
122             return filterEffectiveStatements(ActionDefinition.class);
123         }
124     }
125
126     /**
127      * Bridge between {@link EffectiveStatementWithFlags} and {@link NotificationNodeContainer}.
128      *
129      * @param <A> Argument type ({@link Void} if statement does not have argument.)
130      * @param <D> Class representing declared version of this statement.
131      */
132     public interface NotificationNodeContainerMixin<A, D extends DeclaredStatement<A>>
133             extends Mixin<A, D>, NotificationNodeContainer {
134         @Override
135         default Collection<? extends NotificationDefinition> getNotifications() {
136             return filterEffectiveStatements(NotificationDefinition.class);
137         }
138     }
139
140     /**
141      * Bridge between {@link EffectiveStatementWithFlags} and {@link MustConstraintAware}.
142      *
143      * @param <A> Argument type ({@link Void} if statement does not have argument.)
144      * @param <D> Class representing declared version of this statement.
145      */
146     public interface MustConstraintMixin<A, D extends DeclaredStatement<A>> extends Mixin<A, D>, MustConstraintAware {
147         @Override
148         default Collection<? extends @NonNull MustDefinition> getMustConstraints() {
149             return filterEffectiveStatements(MustDefinition.class);
150         }
151     }
152
153     /**
154      * Bridge between {@link EffectiveStatementWithFlags} and {@link CopyableNode}.
155      *
156      * @param <A> Argument type ({@link Void} if statement does not have argument.)
157      * @param <D> Class representing declared version of this statement.
158      */
159     public interface CopyableMixin<A, D extends DeclaredStatement<A>> extends AddedByUsesMixin<A, D>, CopyableNode {
160         @Override
161         @Deprecated
162         default boolean isAugmenting() {
163             return (flags() & FlagsBuilder.AUGMENTING) != 0;
164         }
165     }
166
167     /**
168      * Bridge between {@link EffectiveStatementWithFlags} and {@link DataNodeContainer}.
169      *
170      * @param <A> Argument type ({@link Void} if statement does not have argument.)
171      * @param <D> Class representing declared version of this statement.
172      */
173     public interface DataNodeContainerMixin<A, D extends DeclaredStatement<A>> extends DataNodeContainer, Mixin<A, D> {
174         @Override
175         default Collection<? extends TypeDefinition<?>> getTypeDefinitions() {
176             return filterTypeDefinitions(this);
177         }
178
179         @Override
180         default Collection<? extends DataSchemaNode> getChildNodes() {
181             return filterEffectiveStatements(DataSchemaNode.class);
182         }
183
184         @Override
185         default Collection<? extends GroupingDefinition> getGroupings() {
186             return filterEffectiveStatements(GroupingDefinition.class);
187         }
188
189         @Override
190         default Collection<? extends UsesNode> getUses() {
191             return filterEffectiveStatements(UsesNode.class);
192         }
193     }
194
195     /**
196      * Bridge between {@link EffectiveStatementWithFlags} and {@link DataSchemaNode}.
197      *
198      * @param <A> Argument type ({@link Void} if statement does not have argument.)
199      * @param <D> Class representing declared version of this statement.
200      */
201     public interface DataSchemaNodeMixin<A, D extends DeclaredStatement<A>>
202             extends DataSchemaNode, CopyableMixin<A, D>, SchemaNodeMixin<A, D>, WhenConditionMixin<A, D> {
203         @Override
204         default Optional<Boolean> effectiveConfig() {
205             final int fl = flags() & FlagsBuilder.MASK_CONFIG;
206             switch (fl) {
207                 case FlagsBuilder.CONFIG_FALSE:
208                     return Optional.of(Boolean.FALSE);
209                 case FlagsBuilder.CONFIG_TRUE:
210                     return Optional.of(Boolean.TRUE);
211                 case FlagsBuilder.CONFIG_UNDEF:
212                     return Optional.empty();
213                 default:
214                     throw new IllegalStateException("Unhandled effective config flags " + fl);
215             }
216         }
217     }
218
219     /**
220      * Bridge between {@link EffectiveStatementWithFlags} and {@link DocumentedNode}.
221      *
222      * @param <A> Argument type ({@link Void} if statement does not have argument.)
223      * @param <D> Class representing declared version of this statement.
224      */
225     public interface DocumentedNodeMixin<A, D extends DeclaredStatement<A>> extends Mixin<A, D>, DocumentedNode {
226         /**
227          * Bridge between {@link EffectiveStatementWithFlags} and
228          * {@link org.opendaylight.yangtools.yang.model.api.DocumentedNode.WithStatus}.
229          *
230          * @param <A> Argument type ({@link Void} if statement does not have argument.)
231          * @param <D> Class representing declared version of this statement.
232          */
233         interface WithStatus<A, D extends DeclaredStatement<A>>
234                 extends EffectiveStatementWithFlags<A, D>, DocumentedNodeMixin<A, D>, DocumentedNode.WithStatus {
235             @Override
236             default Status getStatus() {
237                 final int status = flags() & FlagsBuilder.MASK_STATUS;
238                 switch (status) {
239                     case FlagsBuilder.STATUS_CURRENT:
240                         return Status.CURRENT;
241                     case FlagsBuilder.STATUS_DEPRECATED:
242                         return Status.DEPRECATED;
243                     case FlagsBuilder.STATUS_OBSOLETE:
244                         return Status.OBSOLETE;
245                     default:
246                         throw new IllegalStateException("Illegal status " + status);
247                 }
248             }
249         }
250
251         @Override
252         default Optional<String> getDescription() {
253             return findFirstEffectiveSubstatementArgument(DescriptionEffectiveStatement.class);
254         }
255
256         @Override
257         default Optional<String> getReference() {
258             return findFirstEffectiveSubstatementArgument(ReferenceEffectiveStatement.class);
259         }
260
261         @Override
262         default Collection<? extends UnknownSchemaNode> getUnknownSchemaNodes() {
263             return filterEffectiveStatements(UnknownSchemaNode.class);
264         }
265     }
266
267     /**
268      * Bridge between {@link EffectiveStatementWithFlags} and {@link ConstraintMetaDefinition}.
269      *
270      * @param <A> Argument type ({@link Void} if statement does not have argument.)
271      * @param <D> Class representing declared version of this statement.
272      */
273     public interface ConstraintMetaDefinitionMixin<A, D extends DeclaredStatement<A>> extends DocumentedNodeMixin<A, D>,
274             ConstraintMetaDefinition {
275         @Override
276         default Optional<String> getErrorAppTag() {
277             return findFirstEffectiveSubstatementArgument(ErrorAppTagEffectiveStatement.class);
278         }
279
280         @Override
281         default Optional<String> getErrorMessage() {
282             return findFirstEffectiveSubstatementArgument(ErrorMessageEffectiveStatement.class);
283         }
284     }
285
286     /**
287      * Bridge between {@link EffectiveStatementWithFlags} and {@link MandatoryAware}.
288      *
289      * @param <A> Argument type ({@link Void} if statement does not have argument.)
290      * @param <D> Class representing declared version of this statement.
291      */
292     public interface MandatoryMixin<A, D extends DeclaredStatement<A>>
293             extends EffectiveStatementWithFlags<A, D>, MandatoryAware {
294         @Override
295         default boolean isMandatory() {
296             return (flags() & FlagsBuilder.MANDATORY) != 0;
297         }
298     }
299
300     /**
301      * Bridge between {@link EffectiveStatementWithFlags} and {@code presence} statement.
302      *
303      * @param <A> Argument type ({@link Void} if statement does not have argument.)
304      * @param <D> Class representing declared version of this statement.
305      */
306     public interface PresenceMixin<A, D extends DeclaredStatement<A>> extends EffectiveStatementWithFlags<A, D> {
307         default boolean presence() {
308             return (flags() & FlagsBuilder.PRESENCE) != 0;
309         }
310     }
311
312     /**
313      * Bridge between {@link EffectiveStatementWithFlags} and {@link SchemaNode}.
314      *
315      * @param <A> Argument type ({@link Void} if statement does not have argument.)
316      * @param <D> Class representing declared version of this statement.
317      */
318     public interface SchemaNodeMixin<A, D extends DeclaredStatement<A>>
319             extends DocumentedNodeMixin.WithStatus<A, D>, SchemaNode {
320         // FIXME: ditch all this complexity once we do not require SchemaPath
321         @Override
322         default QName getQName() {
323             return SchemaPathSupport.extractQName(pathObject());
324         }
325
326         @Override
327         @Deprecated
328         default SchemaPath getPath() {
329             return SchemaPathSupport.extractPath(this, pathObject());
330         }
331
332         @NonNull Immutable pathObject();
333     }
334
335     /**
336      * Bridge between {@link EffectiveStatementWithFlags} and {@link UnknownSchemaNode}.
337      *
338      * @param <A> Argument type ({@link Void} if statement does not have argument.)
339      * @param <D> Class representing declared version of this statement.
340      */
341     public interface UnknownSchemaNodeMixin<A, D extends DeclaredStatement<A>>
342             extends SchemaNodeMixin<A, D>, CopyableMixin<A, D>, UnknownSchemaNode {
343
344         @Override
345         default String getNodeParameter() {
346             return Strings.nullToEmpty(getDeclared().rawArgument());
347         }
348     }
349
350     /**
351      * Bridge between {@link EffectiveStatementWithFlags} and {@code ordered-by} statement.
352      *
353      * @param <A> Argument type ({@link Void} if statement does not have argument.)
354      * @param <D> Class representing declared version of this statement.
355      */
356     public interface UserOrderedMixin<A, D extends DeclaredStatement<A>> extends EffectiveStatementWithFlags<A, D> {
357         default boolean userOrdered() {
358             return (flags() & FlagsBuilder.USER_ORDERED) != 0;
359         }
360     }
361
362     /**
363      * Helper used to locate the effective {@code when} statement and exposing its argument as per
364      * {@link WhenConditionAware}.
365      *
366      * @param <A> Argument type ({@link Void} if statement does not have argument.)
367      * @param <D> Class representing declared version of this statement.
368      */
369     public interface WhenConditionMixin<A, D extends DeclaredStatement<A>> extends Mixin<A, D>, WhenConditionAware {
370         @Override
371         default Optional<QualifiedBound> getWhenCondition() {
372             return findFirstEffectiveSubstatementArgument(WhenEffectiveStatement.class);
373         }
374     }
375
376     /**
377      * Helper bridge for operation containers ({@code input} and {@code output}).
378      *
379      * @param <D> Class representing declared version of this statement.
380      */
381     public interface OperationContainerMixin<D extends DeclaredStatement<QName>>
382             extends ContainerLike, DocumentedNodeMixin.WithStatus<QName, D>, DataNodeContainerMixin<QName, D>,
383                     MustConstraintMixin<QName, D>, WhenConditionMixin<QName, D>, AugmentationTargetMixin<QName, D>,
384                     SchemaNodeMixin<QName, D>, CopyableMixin<QName, D> {
385         @Override
386         default @NonNull QName argument() {
387             return getQName();
388         }
389
390         @Override
391         default Optional<ActionDefinition> findAction(final QName qname) {
392             return Optional.empty();
393         }
394
395         @Override
396         default Optional<NotificationDefinition> findNotification(final QName qname) {
397             return Optional.empty();
398         }
399
400         @Override
401         default Collection<? extends ActionDefinition> getActions() {
402             return ImmutableSet.of();
403         }
404
405         @Override
406         default Collection<? extends NotificationDefinition> getNotifications() {
407             return ImmutableSet.of();
408         }
409
410         @Override
411         default Optional<Boolean> effectiveConfig() {
412             return Optional.empty();
413         }
414
415         default String defaultToString() {
416             return MoreObjects.toStringHelper(this).add("qname", getQName()).toString();
417         }
418     }
419
420     /**
421      * Helper bridge for {@code anydata} and {@code anyxml} opaque data.
422      *
423      * @param <D> Class representing declared version of this statement.
424      */
425     public interface OpaqueDataSchemaNodeMixin<D extends DeclaredStatement<QName>>
426             extends DerivableSchemaNode, DataSchemaNodeMixin<QName, D>, DocumentedNodeMixin.WithStatus<QName, D>,
427                     MandatoryMixin<QName, D>, MustConstraintMixin<QName, D>, WhenConditionMixin<QName, D> {
428         @Override
429         default @NonNull QName argument() {
430             return getQName();
431         }
432     }
433
434     /**
435      * Helper bridge for {@code rpc} and {@code action} operations.
436      *
437      * @param <D> Class representing declared version of this statement.
438      */
439     public interface OperationDefinitionMixin<D extends DeclaredStatement<QName>>
440             extends SchemaNodeMixin<QName, D>, OperationDefinition {
441         @Override
442         default @NonNull QName argument() {
443             return getQName();
444         }
445
446         @Override
447         default Collection<? extends @NonNull TypeDefinition<?>> getTypeDefinitions() {
448             return filterTypeDefinitions(this);
449         }
450
451         @Override
452         default Collection<? extends @NonNull GroupingDefinition> getGroupings() {
453             return filterEffectiveStatements(GroupingDefinition.class);
454         }
455
456         @Override
457         default InputSchemaNode getInput() {
458             return findAsContainer(this, InputEffectiveStatement.class, InputSchemaNode.class);
459         }
460
461         @Override
462         default OutputSchemaNode getOutput() {
463             return findAsContainer(this, OutputEffectiveStatement.class, OutputSchemaNode.class);
464         }
465     }
466
467     /**
468      * Support interface for various mixins. Implementations are required to store 32bits worth of flags, which are
469      * globally assigned to sub-interfaces -- thus providing storage for many low-cardinality properties.
470      *
471      * @param <A> Argument type ({@link Void} if statement does not have argument.)
472      * @param <D> Class representing declared version of this statement.
473      */
474     public interface EffectiveStatementWithFlags<A, D extends DeclaredStatement<A>> extends Mixin<A, D> {
475         /**
476          * Return flags associated with this statements. Flags can be built using {@link FlagsBuilder}.
477          *
478          * @return Flag field value (32 bits).
479          */
480         int flags();
481
482         @NonNullByDefault
483         final class FlagsBuilder implements Mutable {
484             // We still have 23 flags remaining
485             static final int STATUS_CURRENT       = 0x0001;
486             static final int STATUS_DEPRECATED    = 0x0002;
487             static final int STATUS_OBSOLETE      = 0x0003;
488             static final int MASK_STATUS          = 0x0003;
489
490             static final int MANDATORY            = 0x0004;
491
492             static final int AUGMENTING           = 0x0010;
493             static final int ADDED_BY_USES        = 0x0020;
494             private static final int MASK_HISTORY = 0x0030;
495
496             static final int USER_ORDERED         = 0x0040;
497             static final int PRESENCE             = 0x0080;
498
499             static final int CONFIG_UNDEF         = 0x0100;
500             static final int CONFIG_FALSE         = 0x0200;
501             static final int CONFIG_TRUE          = 0x0300;
502             static final int MASK_CONFIG          = CONFIG_TRUE;
503
504             private int flags;
505
506             public FlagsBuilder setConfiguration(final @Nullable Boolean config) {
507                 final int fl;
508                 if (config != null) {
509                     fl = config ? CONFIG_TRUE : CONFIG_FALSE;
510                 } else {
511                     fl = CONFIG_UNDEF;
512                 }
513                 flags = flags & ~MASK_CONFIG | fl;
514                 return this;
515             }
516
517             public FlagsBuilder setHistory(final CopyHistory history) {
518                 flags = flags & ~MASK_HISTORY
519                     | (history.isAugmenting() ? AUGMENTING : 0) | (history.isAddedByUses() ? ADDED_BY_USES : 0);
520                 return this;
521             }
522
523             public FlagsBuilder setMandatory(final boolean mandatory) {
524                 if (mandatory) {
525                     flags |= MANDATORY;
526                 } else {
527                     flags &= ~MANDATORY;
528                 }
529                 return this;
530             }
531
532             public FlagsBuilder setPresence(final boolean presence) {
533                 if (presence) {
534                     flags |= PRESENCE;
535                 } else {
536                     flags &= ~PRESENCE;
537                 }
538                 return this;
539             }
540
541             public FlagsBuilder setStatus(final Status status) {
542                 final int bits;
543                 switch (status) {
544                     case CURRENT:
545                         bits = STATUS_CURRENT;
546                         break;
547                     case DEPRECATED:
548                         bits = STATUS_DEPRECATED;
549                         break;
550                     case OBSOLETE:
551                         bits = STATUS_OBSOLETE;
552                         break;
553                     default:
554                         throw new IllegalStateException("Unhandled status " + status);
555                 }
556
557                 flags = flags & ~MASK_STATUS | bits;
558                 return this;
559             }
560
561             public FlagsBuilder setUserOrdered(final boolean userOrdered) {
562                 if (userOrdered) {
563                     flags |= USER_ORDERED;
564                 } else {
565                     flags &= ~USER_ORDERED;
566                 }
567                 return this;
568             }
569
570             public int toFlags() {
571                 return flags;
572             }
573         }
574     }
575
576     private EffectiveStatementMixins() {
577     }
578
579     static <T extends ContainerLike> T findAsContainer(final EffectiveStatement<?, ?> stmt,
580             final Class<? extends EffectiveStatement<QName, ?>> type, final Class<T> target) {
581         return target.cast(stmt.findFirstEffectiveSubstatement(type).get());
582     }
583
584     static Collection<? extends @NonNull TypeDefinition<?>> filterTypeDefinitions(final Mixin<?, ?> stmt) {
585         return Collections2.transform(stmt.filterEffectiveStatements(TypedefEffectiveStatement.class),
586             TypedefEffectiveStatement::getTypeDefinition);
587     }
588
589     public static int historyAndStatusFlags(final CopyHistory history,
590             final Collection<? extends EffectiveStatement<?, ?>> substatements) {
591         return new FlagsBuilder()
592                 .setHistory(history)
593                 .setStatus(AbstractStatementSupport.findFirstArgument(substatements,
594                     StatusEffectiveStatement.class, Status.CURRENT))
595                 .toFlags();
596     }
597 }