- public static final boolean producesDeclared(StmtContext<?, ?, ?> ctx,
- Class<? extends DeclaredStatement<?>> type) {
- return type.isAssignableFrom(ctx.getPublicDefinition()
- .getDeclaredRepresentationClass());
+ public static boolean producesDeclared(final StmtContext<?, ?, ?> ctx,
+ final Class<? extends DeclaredStatement<?>> type) {
+ return type.isAssignableFrom(ctx.getPublicDefinition().getDeclaredRepresentationClass());
+ }
+
+ public static boolean isInExtensionBody(final StmtContext<?,?,?> stmtCtx) {
+ StmtContext<?,?,?> current = stmtCtx;
+ while (!current.getParentContext().isRootContext()) {
+ current = current.getParentContext();
+ if (producesDeclared(current, UnknownStatementImpl.class)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ public static boolean isUnknownStatement(final StmtContext<?, ?, ?> stmtCtx) {
+ return producesDeclared(stmtCtx, UnknownStatementImpl.class);
+ }
+
+ public static Collection<SchemaNodeIdentifier> replaceModuleQNameForKey(
+ final StmtContext<Collection<SchemaNodeIdentifier>, KeyStatement, ?> keyStmtCtx,
+ final QNameModule newQNameModule) {
+
+ Set<SchemaNodeIdentifier> newKeys = new LinkedHashSet<>();
+ for (String keyToken : KEY_SPLITTER.split(keyStmtCtx.rawStatementArgument())) {
+ final QName keyQName = QName.create(newQNameModule, keyToken);
+ newKeys.add(SchemaNodeIdentifier.create(false, keyQName));
+ }
+
+ return newKeys;