2 * Copyright (c) 2020 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.yangtools.yang.parser.spi.meta;
10 import static com.google.common.base.Verify.verifyNotNull;
12 import com.google.common.annotations.Beta;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.eclipse.jdt.annotation.Nullable;
15 import org.opendaylight.yangtools.concepts.Immutable;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.model.api.SchemaNodeDefaults;
18 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
21 // FIXME: remove this class once we ditch SchemaPath.getPath()
22 public abstract class SchemaPathSupport implements Immutable {
23 private static final class Enabled extends SchemaPathSupport {
25 SchemaPath effectivePath(final SchemaPath path) {
30 SchemaPath optionalPath(final SchemaPath path) {
35 private static final SchemaPathSupport DEFAULT = new Enabled();
37 private SchemaPathSupport() {
41 public static @NonNull Object toEffectivePath(final @NonNull SchemaPath path) {
42 return DEFAULT.effectivePath(path);
45 public static @Nullable SchemaPath toOptionalPath(final @Nullable SchemaPath path) {
46 return DEFAULT.optionalPath(path);
49 public static @NonNull QName extractQName(final @NonNull Object path) {
50 return path instanceof QName ? (QName) path : verifyNotNull(((SchemaPath) path).getLastComponent());
53 public static @NonNull SchemaPath extractPath(final @NonNull Object impl, final @NonNull Object path) {
54 return path instanceof SchemaPath ? (SchemaPath) path : SchemaNodeDefaults.throwUnsupported(impl);
57 abstract @NonNull Object effectivePath(@NonNull SchemaPath path);
59 abstract @Nullable SchemaPath optionalPath(@Nullable SchemaPath path);