/*
 * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */
package org.opendaylight.yangtools.yang.model.api;

import static com.google.common.base.Verify.verifyNotNull;

import com.google.common.annotations.Beta;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.yangtools.concepts.Immutable;
import org.opendaylight.yangtools.yang.common.QName;

@Beta
@NonNullByDefault
public final class SchemaNodeDefaults {
    private SchemaNodeDefaults() {
        // Hidden on purpose
    }

    /**
     * Report unsupported {@link SchemaNode#getPath()} implementation. This method is guaranteed to throw a
     * RuntimeException.
     *
     * @param impl {@code this} object of invoking implementation
     * @throws NullPointerException if impl is null
     * @throws UnsupportedOperationException if impl is not null
     * @see SchemaNode#getPath()
     */
    // FIXME: 8.0.0: consider deprecating this method
    public static SchemaPath throwUnsupported(final Object impl) {
        throw new UnsupportedOperationException(impl.getClass() + " does not support SchemaNode.getPath()");
    }

    /**
     * Report unsupported {@link SchemaNode#getPath()} implementation if provided path is null.
     *
     * @param impl {@code this} object of invoking implementation
     * @throws NullPointerException if impl is null
     * @throws UnsupportedOperationException if path is null
     * @see SchemaNode#getPath()
     */
    // FIXME: 8.0.0: consider deprecating this method
    public static SchemaPath throwUnsupportedIfNull(final Object impl, final @Nullable SchemaPath path) {
        return path != null ? path : throwUnsupported(impl);
    }

    /**
     * Extract {@link QName} from a path object.
     *
     * @param path Path handle
     * @return Extracted QName
     * @throws NullPointerException if {@code path} is null
     * @throws IllegalArgumentException if {@code path} is not supported
     */
    // FIXME: 8.0.0: consider deprecating this method
    public static QName extractQName(final Immutable path) {
        if (path instanceof QName) {
            return (QName) path;
        } else if (path instanceof SchemaPath) {
            return verifyNotNull(((SchemaPath) path).getLastComponent());
        } else {
            throw new IllegalArgumentException("Unhandled object " + path);
        }
    }

    /**
     * Extract {@link SchemaPath} from a path object.
     *
     * @param impl Implementation object
     * @param path Path handle
     * @return Extracted SchemaPath
     * @throws UnsupportedOperationException if {@code path} does not hold a SchemaPath
     */
    // FIXME: 8.0.0: consider deprecating this method
    public static SchemaPath extractPath(final Object impl, final Immutable path) {
        return path instanceof SchemaPath ? (SchemaPath) path : SchemaNodeDefaults.throwUnsupported(impl);
    }
}

@@ -912,24 +912,25 @@
  throw a
+n
 %0A     * 
 RuntimeE
@@ -925,15 +925,35 @@
   * 
-Runtime
+%7B@link UnsupportedOperation
 Exce
@@ -957,16 +957,17 @@
 xception
+%7D
 .%0A     *
@@ -1025,32 +1025,55 @@
  implementation%0A
+     * @return Nothing%0A
      * @throws N
@@ -1087,36 +1087,44 @@
 terException if 
+%7B@code 
 impl
+%7D
  is null%0A     * 
@@ -1165,27 +1165,14 @@
 ion 
-if impl is not null
+always
 %0A   
@@ -1615,32 +1615,105 @@
  implementation%0A
+     * @param path A schema path%0A     * @return %7B@code path%7D if non-null%0A
      * @throws N
@@ -1735,20 +1735,28 @@
 tion if 
+%7B@code 
 impl
+%7D
  is null
@@ -1804,20 +1804,28 @@
 tion if 
+@%7Bcode 
 path
+%7D
  is null

Fix javadoc warnings in SchemaNodeDefaults