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;
-import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder;
return inProgressPhase;
}
- Optional<AbstractResumedStatement<?, ?, ?>> lookupDeclaredChild(final AbstractResumedStatement<?, ?, ?> current,
- final int childId) {
- if (current == null) {
- return Optional.empty();
- }
-
- // Fast path: we are entering a statement which was emitted in previous phase
- AbstractResumedStatement<?, ?, ?> existing = current.lookupSubstatement(childId);
- while (existing != null && StatementSource.CONTEXT == existing.getStatementSource()) {
- existing = existing.lookupSubstatement(childId);
- }
-
- return Optional.ofNullable(existing);
- }
-
AbstractResumedStatement<?, ?, ?> createDeclaredChild(final AbstractResumedStatement<?, ?, ?> current,
final int childId, final QName name, final String argument, final StatementSourceReference ref) {
StatementDefinitionContext<?, ?, ?> def = currentContext.getStatementDefinition(getRootVersion(), name);
import static java.util.Objects.requireNonNull;
import java.util.Optional;
+import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
@Override
public Optional<? extends ResumedStatement> resumeStatement(final int childId) {
- final Optional<AbstractResumedStatement<?, ?, ?>> existing = ctx.lookupDeclaredChild(current, childId);
- existing.ifPresent(this::resumeStatement);
- return existing;
+ final AbstractResumedStatement<?, ?, ?> existing = lookupDeclaredChild(current, childId);
+ if (existing != null) {
+ resumeStatement(existing);
+ return Optional.of(existing);
+ }
+ return Optional.empty();
}
private void resumeStatement(final AbstractResumedStatement<?, ?, ?> child) {
@Override
public void startStatement(final int childId, final QName name, final String argument,
final StatementSourceReference ref) {
- final Optional<AbstractResumedStatement<?, ?, ?>> existing = ctx.lookupDeclaredChild(current, childId);
- current = existing.isPresent() ? existing.get()
- : verifyNotNull(ctx.createDeclaredChild(current, childId, name, argument, ref));
+ final AbstractResumedStatement<?, ?, ?> existing = lookupDeclaredChild(current, childId);
+ current = existing != null ? existing
+ : verifyNotNull(ctx.createDeclaredChild(current, childId, name, argument, ref));
}
@Override
current = null;
}
}
+
+ private static @Nullable AbstractResumedStatement<?, ?, ?> lookupDeclaredChild(
+ final AbstractResumedStatement<?, ?, ?> current, final int childId) {
+ if (current == null) {
+ return null;
+ }
+
+ // Fast path: we are entering a statement which was emitted in previous phase
+ AbstractResumedStatement<?, ?, ?> existing = current.lookupSubstatement(childId);
+ while (existing != null && StatementSource.CONTEXT == existing.getStatementSource()) {
+ existing = existing.lookupSubstatement(childId);
+ }
+
+ return existing;
+ }
}