+ // These two exist only for StatementContextBase. Since we are squeezed for size, with only a single bit available
+ // in flags, we default to 'false' and only set the flag to true when we are absolutely sure -- and all other cases
+ // err on the side of caution by taking the time to evaluate each substatement separately.
+ final boolean allSubstatementsContextIndependent() {
+ return (flags & ALL_INDEPENDENT) != 0;
+ }
+
+ final void setAllSubstatementsContextIndependent() {
+ flags |= ALL_INDEPENDENT;
+ }
+
+ //
+ //
+ // Various functionality from AbstractTypeStatementSupport. This used to work on top of SchemaPath, now it still
+ // lives here. Ultimate future is either proper graduation or (more likely) move to AbstractTypeStatementSupport.
+ //
+ //
+
+ @Override
+ public final QName argumentAsTypeQName() {
+ final Object argument = argument();
+ verify(argument instanceof String, "Unexpected argument %s", argument);
+ return interpretAsQName((String) argument);
+ }
+
+ @Override
+ public final QNameModule effectiveNamespace() {
+ // FIXME: there has to be a better way to do this
+ return getSchemaPath().getLastComponent().getModule();
+ }
+
+ //
+ //
+ // Common SchemaPath cache. All of this is bound to be removed once YANGTOOLS-1066 is done.
+ //
+ //
+
+ // Exists only to support {SubstatementContext,InferredStatementContext}.schemaPath()
+ @Deprecated
+ final @Nullable SchemaPath substatementGetSchemaPath() {
+ if (schemaPath == null) {
+ schemaPath = createSchemaPath((StatementContextBase<?, ?, ?>) coerceParentContext());
+ }
+ return schemaPath;
+ }
+
+ // FIXME: 7.0.0: this method's logic needs to be moved to the respective StatementSupport classes
+ @Deprecated
+ private SchemaPath createSchemaPath(final StatementContextBase<?, ?, ?> parent) {
+ final SchemaPath parentPath = parent.getSchemaPath();
+ if (StmtContextUtils.isUnknownStatement(this)) {
+ return parentPath.createChild(publicDefinition().getStatementName());
+ }
+ final Object argument = argument();
+ if (argument instanceof QName) {
+ final QName qname = (QName) argument;
+ if (producesDeclared(UsesStatement.class)) {
+ return parentPath;
+ }
+
+ return parentPath.createChild(qname);
+ }
+ if (argument instanceof String) {
+ return parentPath.createChild(interpretAsQName((String) argument));
+ }
+ if (argument instanceof SchemaNodeIdentifier
+ && (producesDeclared(AugmentStatement.class) || producesDeclared(RefineStatement.class)
+ || producesDeclared(DeviationStatement.class))) {
+
+ return parentPath.createChild(((SchemaNodeIdentifier) argument).getNodeIdentifiers());
+ }
+
+ // FIXME: this does not look right, investigate more?
+ return parentPath;
+ }
+
+ private @NonNull QName interpretAsQName(final String argument) {
+ // FIXME: This may yield illegal argument exceptions
+ return StmtContextUtils.qnameFromArgument(getOriginalCtx().orElse(this), argument);
+ }
+