Deprecate StmtContext.getSchemaPath()
[yangtools.git] / yang / yang-parser-reactor / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / reactor / StatementContextBase.java
index 5c1095e061188870e6f9be77b35616be59462f9e..3d1f8f97b31a4d4bfebfe8c8880b6784104ae4c8 100644 (file)
@@ -532,8 +532,12 @@ public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E
 
     @Override
     public E buildEffective() {
-        final E existing = effectiveInstance;
-        return existing != null ? existing : (effectiveInstance = definition.getFactory().createEffective(this));
+        final E existing;
+        return (existing = effectiveInstance) != null ? existing : loadEffective();
+    }
+
+    private E loadEffective() {
+        return effectiveInstance = definition.getFactory().createEffective(this);
     }
 
     /**
@@ -1002,15 +1006,15 @@ public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E
         return false;
     }
 
-    // Exists only to support SubstatementContext/InferredStatementContext
+    // Exists only to support {SubstatementContext,InferredStatementContext}.getSchemaPath()
+    @Deprecated
     final @NonNull Optional<SchemaPath> substatementGetSchemaPath() {
         SchemaPath local = schemaPath;
         if (local == null) {
             synchronized (this) {
                 local = schemaPath;
                 if (local == null) {
-                    local = createSchemaPath(coerceParentContext());
-                    schemaPath = local;
+                    schemaPath = local = createSchemaPath(coerceParentContext());
                 }
             }
         }
@@ -1018,6 +1022,7 @@ public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E
         return Optional.ofNullable(local);
     }
 
+    @Deprecated
     private SchemaPath createSchemaPath(final Mutable<?, ?, ?> parent) {
         final Optional<SchemaPath> maybeParentPath = parent.getSchemaPath();
         verify(maybeParentPath.isPresent(), "Parent %s does not have a SchemaPath", parent);
@@ -1029,7 +1034,7 @@ public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E
         final Object argument = getStatementArgument();
         if (argument instanceof QName) {
             final QName qname = (QName) argument;
-            if (StmtContextUtils.producesDeclared(this, UsesStatement.class)) {
+            if (producesDeclared(UsesStatement.class)) {
                 return maybeParentPath.orElse(null);
             }
 
@@ -1042,11 +1047,10 @@ public abstract class StatementContextBase<A, D extends DeclaredStatement<A>, E
             return parentPath.createChild(qname);
         }
         if (argument instanceof SchemaNodeIdentifier
-                && (StmtContextUtils.producesDeclared(this, AugmentStatement.class)
-                        || StmtContextUtils.producesDeclared(this, RefineStatement.class)
-                        || StmtContextUtils.producesDeclared(this, DeviationStatement.class))) {
+                && (producesDeclared(AugmentStatement.class) || producesDeclared(RefineStatement.class)
+                        || producesDeclared(DeviationStatement.class))) {
 
-            return parentPath.createChild(((SchemaNodeIdentifier) argument).getPathFromRoot());
+            return parentPath.createChild(((SchemaNodeIdentifier) argument).getNodeIdentifiers());
         }
 
         // FIXME: this does not look right