Remove hashCode()/equals() from SchemaNode implementations
[yangtools.git] / yang / yang-parser-rfc7950 / src / main / java / org / opendaylight / yangtools / yang / parser / rfc7950 / stmt / extension / UnrecognizedEffectiveStatementImpl.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.rfc7950.stmt.extension;
9
10 import org.eclipse.jdt.annotation.NonNull;
11 import org.opendaylight.yangtools.yang.common.QName;
12 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
13 import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
14 import org.opendaylight.yangtools.yang.model.api.stmt.UnrecognizedEffectiveStatement;
15 import org.opendaylight.yangtools.yang.model.api.stmt.UnrecognizedStatement;
16 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.UnknownEffectiveStatementBase;
17 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
18 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
19 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23 final class UnrecognizedEffectiveStatementImpl extends UnknownEffectiveStatementBase<String, UnrecognizedStatement>
24         implements UnrecognizedEffectiveStatement {
25     private static final Logger LOG = LoggerFactory.getLogger(UnrecognizedEffectiveStatementImpl.class);
26
27     private final QName maybeQNameArgument;
28     private final @NonNull SchemaPath path;
29
30     UnrecognizedEffectiveStatementImpl(final StmtContext<String, UnrecognizedStatement, ?> ctx) {
31         super(ctx);
32
33         // FIXME: Remove following section after fixing 4380
34         final UnknownSchemaNode original = (UnknownSchemaNode) ctx.getOriginalCtx().map(StmtContext::buildEffective)
35                 .orElse(null);
36         if (original != null) {
37             this.maybeQNameArgument = original.getQName();
38         } else {
39             QName maybeQNameArgumentInit = null;
40             try {
41                 maybeQNameArgumentInit = StmtContextUtils.qnameFromArgument(ctx, argument());
42             } catch (SourceException e) {
43                 LOG.debug("Not constructing QName from {}", argument(), e);
44                 maybeQNameArgumentInit = getNodeType();
45             }
46             this.maybeQNameArgument = maybeQNameArgumentInit;
47         }
48
49         SchemaPath maybePath;
50         try {
51             maybePath = ctx.coerceParentContext().getSchemaPath()
52                     .map(parentPath -> parentPath.createChild(maybeQNameArgument)).orElse(null);
53         } catch (IllegalArgumentException | SourceException e) {
54             LOG.debug("Cannot construct path for {}, attempting to recover", ctx, e);
55             maybePath = null;
56         }
57         path = maybePath;
58     }
59
60     @Override
61     public QName getQName() {
62         return maybeQNameArgument;
63     }
64
65     @Override
66     public SchemaPath getPath() {
67         return path;
68     }
69 }