2 * Copyright (c) 2022 PANTHEON.tech, s.r.o. and others. All rights reserved.
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
8 package org.opendaylight.mdsal.binding.generator.impl.reactor;
10 import static com.google.common.base.Verify.verify;
11 import static com.google.common.base.Verify.verifyNotNull;
12 import static java.util.Objects.requireNonNull;
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.eclipse.jdt.annotation.Nullable;
16 import org.opendaylight.mdsal.binding.generator.impl.tree.SchemaTreeChild;
17 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaTreeEffectiveStatement;
20 * A placeholder {@link SchemaTreeChild}.
23 final class SchemaTreePlaceholder<S extends SchemaTreeEffectiveStatement<?>,
24 G extends AbstractExplicitGenerator<S> & SchemaTreeChild<S, G>> implements SchemaTreeChild<S, G> {
25 private final @NonNull Class<G> generatorType;
26 private final @NonNull S statement;
28 private @Nullable G generator;
30 SchemaTreePlaceholder(final S statement, final Class<G> generatorType) {
31 this.statement = requireNonNull(statement);
32 this.generatorType = requireNonNull(generatorType);
36 public S statement() {
41 public G generator() {
42 final var local = generator;
44 throw new IllegalStateException("Unresolved generator in " + this);
49 void setGenerator(final AbstractCompositeGenerator<?> parent) {
50 verify(generator == null, "Attempted to set generator for %s", this);
51 final var qname = getIdentifier();
52 generator = generatorType.cast(verifyNotNull(parent.findSchemaTreeGenerator(qname),
53 "Failed to find generator for child %s in %s", qname, parent));