Narrow down SuppressFBWarnings in ModelProcessingPhase
[yangtools.git] / yang / yang-parser-spi / src / main / java / org / opendaylight / yangtools / yang / parser / spi / meta / ModelProcessingPhase.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 static java.util.Objects.requireNonNull;
11
12 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
13 import org.eclipse.jdt.annotation.NonNullByDefault;
14 import org.eclipse.jdt.annotation.Nullable;
15
16 @NonNullByDefault
17 public enum ModelProcessingPhase {
18     INIT(),
19
20     /**
21      * Preliminary cross-source relationship resolution phase which collects available module names and module
22      * namespaces. It is necessary in order to correct resolution of unknown statements used in linkage phase (e.g.
23      * semantic version of yang modules).
24      */
25     SOURCE_PRE_LINKAGE(INIT),
26
27     /**
28      * Cross-source relationship resolution phase.
29      *
30      * <p>
31      * In this phase of processing only statements which affects cross-source relationship (e.g. imports / includes)
32      * are processed.
33      *
34      * <p>
35      * At end of this phase all source related contexts should be bind to their imports and includes to allow
36      * visibility of custom defined statements in subsequent phases.
37      */
38     SOURCE_LINKAGE(SOURCE_PRE_LINKAGE),
39     STATEMENT_DEFINITION(SOURCE_LINKAGE),
40     FULL_DECLARATION(STATEMENT_DEFINITION),
41     EFFECTIVE_MODEL(FULL_DECLARATION);
42
43     private final @Nullable ModelProcessingPhase previousPhase;
44
45     @SuppressFBWarnings(value = "NP_STORE_INTO_NONNULL_FIELD",
46         justification = "https://github.com/spotbugs/spotbugs/issues/743")
47     ModelProcessingPhase() {
48         previousPhase = null;
49     }
50
51     ModelProcessingPhase(final ModelProcessingPhase previousPhase) {
52         this.previousPhase = requireNonNull(previousPhase);
53     }
54
55     /**
56      * Return the preceding phase, or null if this phase is the first one.
57      *
58      * @return Preceding phase, if there is one
59      */
60     public @Nullable ModelProcessingPhase getPreviousPhase() {
61         return previousPhase;
62     }
63
64     /**
65      * Determine whether this processing phase is implied to have completed by completion of some other phase.
66      * Algebraically this means that other is not null and is either this phase or its {@link #getPreviousPhase()} chain
67      * contains this phase.
68      *
69      * @param other Other phase
70      * @return True if this phase completes no later than specified phase.
71      */
72     public boolean isCompletedBy(final @Nullable ModelProcessingPhase other) {
73         return other != null && ordinal() <= other.ordinal();
74     }
75 }