From: Robert Varga Date: Thu, 2 Jul 2020 16:22:18 +0000 (+0200) Subject: Split out AbstractTypeStatementSupport.resolveTypeReference() X-Git-Tag: v5.0.4~38 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=1439def0aa76902f986dfa1f80c8160058958861;p=yangtools.git Split out AbstractTypeStatementSupport.resolveTypeReference() The implementation of createEffective() method is quite huge, split out the switch lookup part out of it, saving a few lines. JIRA: YANGTOOLS-1065 Change-Id: I97c36b2263a3ee2c4f394f77e3d5651846aa91f3 Signed-off-by: Robert Varga --- diff --git a/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/type/AbstractTypeStatementSupport.java b/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/type/AbstractTypeStatementSupport.java index 0f1f85e410..2330fedf67 100644 --- a/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/type/AbstractTypeStatementSupport.java +++ b/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/type/AbstractTypeStatementSupport.java @@ -11,6 +11,7 @@ import static com.google.common.base.Preconditions.checkArgument; import com.google.common.collect.ImmutableMap; import java.util.Collection; +import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.model.api.SchemaPath; import org.opendaylight.yangtools.yang.model.api.TypeDefinition; @@ -143,54 +144,7 @@ abstract class AbstractTypeStatementSupport final StmtContext> ctx) { // First look up the proper base type - final TypeEffectiveStatement typeStmt; - switch (ctx.coerceStatementArgument()) { - case BINARY: - typeStmt = BuiltinEffectiveStatement.BINARY; - break; - case BOOLEAN: - typeStmt = BuiltinEffectiveStatement.BOOLEAN; - break; - case EMPTY: - typeStmt = BuiltinEffectiveStatement.EMPTY; - break; - case INSTANCE_IDENTIFIER: - typeStmt = BuiltinEffectiveStatement.INSTANCE_IDENTIFIER; - break; - case INT8: - typeStmt = BuiltinEffectiveStatement.INT8; - break; - case INT16: - typeStmt = BuiltinEffectiveStatement.INT16; - break; - case INT32: - typeStmt = BuiltinEffectiveStatement.INT32; - break; - case INT64: - typeStmt = BuiltinEffectiveStatement.INT64; - break; - case STRING: - typeStmt = BuiltinEffectiveStatement.STRING; - break; - case UINT8: - typeStmt = BuiltinEffectiveStatement.UINT8; - break; - case UINT16: - typeStmt = BuiltinEffectiveStatement.UINT16; - break; - case UINT32: - typeStmt = BuiltinEffectiveStatement.UINT32; - break; - case UINT64: - typeStmt = BuiltinEffectiveStatement.UINT64; - break; - default: - final QName qname = StmtContextUtils.parseNodeIdentifier(ctx, ctx.getStatementArgument()); - final StmtContext typedef = - SourceException.throwIfNull(ctx.getFromNamespace(TypeNamespace.class, qname), - ctx.getStatementSourceReference(), "Type '%s' not found", qname); - typeStmt = typedef.buildEffective().asTypeEffectiveStatement(); - } + final TypeEffectiveStatement typeStmt = resolveType(ctx); if (ctx.declaredSubstatements().isEmpty() && ctx.effectiveSubstatements().isEmpty()) { return typeStmt; @@ -314,4 +268,49 @@ abstract class AbstractTypeStatementSupport final QName qname = path.getLastComponent().bindTo(parentQName.getModule()).intern(); return parent.createChild(qname); } + + /** + * Resolve type reference, as pointed to by the context's argument. + * + * @param ctx Statement context + * @return Resolved type + * @throws SourceException if the target type cannot be found + */ + private static @NonNull TypeEffectiveStatement resolveType(final StmtContext ctx) { + final String argument = ctx.coerceStatementArgument(); + switch (argument) { + case BINARY: + return BuiltinEffectiveStatement.BINARY; + case BOOLEAN: + return BuiltinEffectiveStatement.BOOLEAN; + case EMPTY: + return BuiltinEffectiveStatement.EMPTY; + case INSTANCE_IDENTIFIER: + return BuiltinEffectiveStatement.INSTANCE_IDENTIFIER; + case INT8: + return BuiltinEffectiveStatement.INT8; + case INT16: + return BuiltinEffectiveStatement.INT16; + case INT32: + return BuiltinEffectiveStatement.INT32; + case INT64: + return BuiltinEffectiveStatement.INT64; + case STRING: + return BuiltinEffectiveStatement.STRING; + case UINT8: + return BuiltinEffectiveStatement.UINT8; + case UINT16: + return BuiltinEffectiveStatement.UINT16; + case UINT32: + return BuiltinEffectiveStatement.UINT32; + case UINT64: + return BuiltinEffectiveStatement.UINT64; + default: + final QName qname = StmtContextUtils.parseNodeIdentifier(ctx, argument); + final StmtContext typedef = + SourceException.throwIfNull(ctx.getFromNamespace(TypeNamespace.class, qname), + ctx.getStatementSourceReference(), "Type '%s' not found", qname); + return typedef.buildEffective().asTypeEffectiveStatement(); + } + } } \ No newline at end of file