X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fsal%2Fyang-prototype%2Fcode-generator%2Fyang-model-parser-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fyang%2Fmodel%2Fparser%2Fimpl%2FYangModelParserListenerImpl.java;h=511c610e3f42e25241e8ae2e01c82c3a82e2bb78;hb=a3ff738aee0c392a1adbd3c6397539bb4130b57d;hp=bc5f77be838eb6b329feec9e1e756c6522d14d20;hpb=11b0c275f1abb01bac9b122895a002c8e7905de1;p=controller.git diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/impl/YangModelParserListenerImpl.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/impl/YangModelParserListenerImpl.java index bc5f77be83..511c610e3f 100644 --- a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/impl/YangModelParserListenerImpl.java +++ b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/model/parser/impl/YangModelParserListenerImpl.java @@ -52,11 +52,11 @@ import org.opendaylight.controller.antlrv4.code.gen.YangParser.When_stmtContext; import org.opendaylight.controller.antlrv4.code.gen.YangParser.Yang_version_stmtContext; import org.opendaylight.controller.antlrv4.code.gen.YangParserBaseListener; import org.opendaylight.controller.yang.common.QName; +import org.opendaylight.controller.yang.model.api.SchemaPath; import org.opendaylight.controller.yang.model.api.Status; import org.opendaylight.controller.yang.model.api.TypeDefinition; import org.opendaylight.controller.yang.model.parser.builder.api.AugmentationSchemaBuilder; import org.opendaylight.controller.yang.model.parser.builder.api.GroupingBuilder; -import org.opendaylight.controller.yang.model.parser.builder.api.UsesNodeBuilder; import org.opendaylight.controller.yang.model.parser.builder.impl.AnyXmlBuilder; import org.opendaylight.controller.yang.model.parser.builder.impl.ChoiceBuilder; import org.opendaylight.controller.yang.model.parser.builder.impl.ChoiceCaseBuilder; @@ -78,8 +78,8 @@ import org.opendaylight.controller.yang.model.util.YangTypesConverter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public final class YangModelParserListenerImpl extends YangParserBaseListener { - +public final class YangModelParserListenerImpl extends YangParserBaseListener { + private static final Logger logger = LoggerFactory .getLogger(YangModelParserListenerImpl.class); @@ -90,7 +90,7 @@ public final class YangModelParserListenerImpl extends YangParserBaseListener { private String yangModelPrefix; private Date revision = new Date(0L); - public final static DateFormat simpleDateFormat = new SimpleDateFormat( + public final static DateFormat simpleDateFormat = new SimpleDateFormat( "yyyy-MM-dd"); private final Stack actualPath = new Stack(); @@ -238,7 +238,7 @@ public final class YangModelParserListenerImpl extends YangParserBaseListener { public void enterAugment_stmt(YangParser.Augment_stmtContext ctx) { final String augmentPath = stringFromNode(ctx); AugmentationSchemaBuilder builder = moduleBuilder.addAugment( - augmentPath, actualPath); + augmentPath, actualPath, ctx.getStart().getLine()); updatePath(augmentPath); for (int i = 0; i < ctx.getChildCount(); i++) { @@ -269,7 +269,8 @@ public final class YangModelParserListenerImpl extends YangParserBaseListener { public void enterExtension_stmt(YangParser.Extension_stmtContext ctx) { final String extName = stringFromNode(ctx); QName qname = new QName(namespace, revision, yangModelPrefix, extName); - ExtensionBuilder builder = moduleBuilder.addExtension(qname); + ExtensionBuilder builder = moduleBuilder.addExtension(qname, ctx + .getStart().getLine()); parseSchemaNodeArgs(ctx, builder); String argument = null; @@ -292,7 +293,7 @@ public final class YangModelParserListenerImpl extends YangParserBaseListener { QName typedefQName = new QName(namespace, revision, yangModelPrefix, typedefName); TypedefBuilder builder = moduleBuilder.addTypedef(typedefQName, - actualPath); + actualPath, ctx.getStart().getLine()); updatePath(typedefName); builder.setPath(createActualSchemaPath(actualPath, namespace, revision, @@ -310,7 +311,8 @@ public final class YangModelParserListenerImpl extends YangParserBaseListener { @Override public void enterType_stmt(YangParser.Type_stmtContext ctx) { final String typeName = stringFromNode(ctx); - QName typeQName = parseQName(typeName); + final int line = ctx.getStart().getLine(); + final QName typeQName = parseQName(typeName); TypeDefinition type = null; Type_body_stmtsContext typeBody = null; @@ -324,14 +326,22 @@ public final class YangModelParserListenerImpl extends YangParserBaseListener { // if this is base yang type... if (YangTypesConverter.isBaseYangType(typeName)) { if (typeBody == null) { + // check for types which must have body + checkMissingBody(typeName, moduleName, line); // if there are no constraints, just grab default base yang type - type = YangTypesConverter.javaTypeForBaseYangType(actualPath, namespace, revision, typeName); + type = YangTypesConverter.javaTypeForBaseYangType(actualPath, + namespace, revision, typeName); moduleBuilder.setType(type, actualPath); } else { if ("union".equals(typeName)) { - moduleBuilder.addUnionType(actualPath); - } else if("identityref".equals(typeName)) { - moduleBuilder.addIdentityrefType(getIdentityrefBase(typeBody), actualPath); + moduleBuilder.addUnionType(actualPath, namespace, revision, + line); + } else if ("identityref".equals(typeName)) { + SchemaPath path = createActualSchemaPath(actualPath, + namespace, revision, yangModelPrefix); + moduleBuilder.addIdentityrefType( + getIdentityrefBase(typeBody), actualPath, path, + line); } else { List typePath = new ArrayList(actualPath); typePath.remove(0); @@ -380,7 +390,7 @@ public final class YangModelParserListenerImpl extends YangParserBaseListener { QName groupQName = new QName(namespace, revision, yangModelPrefix, groupName); GroupingBuilder groupBuilder = moduleBuilder.addGrouping(groupQName, - actualPath); + actualPath, ctx.getStart().getLine()); updatePath("grouping"); updatePath(groupName); parseSchemaNodeArgs(ctx, groupBuilder); @@ -399,7 +409,8 @@ public final class YangModelParserListenerImpl extends YangParserBaseListener { QName containerQName = new QName(namespace, revision, yangModelPrefix, containerName); ContainerSchemaNodeBuilder containerBuilder = moduleBuilder - .addContainerNode(containerQName, actualPath); + .addContainerNode(containerQName, actualPath, ctx.getStart() + .getLine()); updatePath(containerName); containerBuilder.setPath(createActualSchemaPath(actualPath, namespace, @@ -428,7 +439,7 @@ public final class YangModelParserListenerImpl extends YangParserBaseListener { QName leafQName = new QName(namespace, revision, yangModelPrefix, leafName); LeafSchemaNodeBuilder leafBuilder = moduleBuilder.addLeafNode( - leafQName, actualPath); + leafQName, actualPath, ctx.getStart().getLine()); updatePath(leafName); leafBuilder.setPath(createActualSchemaPath(actualPath, namespace, @@ -459,12 +470,9 @@ public final class YangModelParserListenerImpl extends YangParserBaseListener { @Override public void enterUses_stmt(YangParser.Uses_stmtContext ctx) { final String groupingPathStr = stringFromNode(ctx); - UsesNodeBuilder builder = moduleBuilder.addUsesNode(groupingPathStr, - actualPath); + moduleBuilder.addUsesNode(groupingPathStr, actualPath, ctx.getStart() + .getLine()); updatePath(groupingPathStr); - - final List refines = parseRefines(ctx); - builder.setRefines(refines); } @Override @@ -473,13 +481,28 @@ public final class YangModelParserListenerImpl extends YangParserBaseListener { logger.debug("exiting " + actContainer); } + @Override + public void enterRefine_stmt(YangParser.Refine_stmtContext ctx) { + String refineString = stringFromNode(ctx); + RefineHolder refine = parseRefine(ctx); + moduleBuilder.addRefine(refine, actualPath); + updatePath(refineString); + } + + @Override + public void exitRefine_stmt(YangParser.Refine_stmtContext ctx) { + final String actContainer = actualPath.pop(); + logger.debug("exiting " + actContainer); + } + @Override public void enterLeaf_list_stmt(Leaf_list_stmtContext ctx) { final String leafListName = stringFromNode(ctx); QName leafListQName = new QName(namespace, revision, yangModelPrefix, leafListName); LeafListSchemaNodeBuilder leafListBuilder = moduleBuilder - .addLeafListNode(leafListQName, actualPath); + .addLeafListNode(leafListQName, actualPath, ctx.getStart() + .getLine()); updatePath(leafListName); parseSchemaNodeArgs(ctx, leafListBuilder); @@ -508,7 +531,7 @@ public final class YangModelParserListenerImpl extends YangParserBaseListener { QName containerQName = new QName(namespace, revision, yangModelPrefix, containerName); ListSchemaNodeBuilder listBuilder = moduleBuilder.addListNode( - containerQName, actualPath); + containerQName, actualPath, ctx.getStart().getLine()); updatePath(containerName); listBuilder.setPath(createActualSchemaPath(actualPath, namespace, @@ -544,7 +567,7 @@ public final class YangModelParserListenerImpl extends YangParserBaseListener { QName anyXmlQName = new QName(namespace, revision, yangModelPrefix, anyXmlName); AnyXmlBuilder anyXmlBuilder = moduleBuilder.addAnyXml(anyXmlQName, - actualPath); + actualPath, ctx.getStart().getLine()); updatePath(anyXmlName); anyXmlBuilder.setPath(createActualSchemaPath(actualPath, namespace, @@ -565,7 +588,7 @@ public final class YangModelParserListenerImpl extends YangParserBaseListener { QName choiceQName = new QName(namespace, revision, yangModelPrefix, choiceName); ChoiceBuilder choiceBuilder = moduleBuilder.addChoice(choiceQName, - actualPath); + actualPath, ctx.getStart().getLine()); updatePath(choiceName); choiceBuilder.setPath(createActualSchemaPath(actualPath, namespace, @@ -596,7 +619,7 @@ public final class YangModelParserListenerImpl extends YangParserBaseListener { QName choiceQName = new QName(namespace, revision, yangModelPrefix, caseName); ChoiceCaseBuilder caseBuilder = moduleBuilder.addCase(choiceQName, - actualPath); + actualPath, ctx.getStart().getLine()); updatePath(caseName); caseBuilder.setPath(createActualSchemaPath(actualPath, namespace, @@ -617,7 +640,8 @@ public final class YangModelParserListenerImpl extends YangParserBaseListener { QName notificationQName = new QName(namespace, revision, yangModelPrefix, notificationName); NotificationBuilder notificationBuilder = moduleBuilder - .addNotification(notificationQName, actualPath); + .addNotification(notificationQName, actualPath, ctx.getStart() + .getLine()); updatePath(notificationName); notificationBuilder.setPath(createActualSchemaPath(actualPath, @@ -634,11 +658,22 @@ public final class YangModelParserListenerImpl extends YangParserBaseListener { // Unknown types @Override public void enterIdentifier_stmt(YangParser.Identifier_stmtContext ctx) { - final String name = stringFromNode(ctx); + final String nodeParameter = stringFromNode(ctx); + QName nodeType = null; + + final String nodeTypeStr = ctx.getChild(0).getText(); + final String[] splittedElement = nodeTypeStr.split(":"); + if (splittedElement.length == 1) { + nodeType = new QName(null, null, yangModelPrefix, + splittedElement[0]); + } else { + nodeType = new QName(null, null, splittedElement[0], + splittedElement[1]); + } QName qname; - if (name != null) { - String[] splittedName = name.split(":"); + if (nodeParameter != null) { + String[] splittedName = nodeParameter.split(":"); if (splittedName.length == 2) { qname = new QName(null, null, splittedName[0], splittedName[1]); } else { @@ -646,12 +681,15 @@ public final class YangModelParserListenerImpl extends YangParserBaseListener { splittedName[0]); } } else { - qname = new QName(namespace, revision, yangModelPrefix, name); + qname = new QName(namespace, revision, yangModelPrefix, + nodeParameter); } UnknownSchemaNodeBuilder builder = moduleBuilder.addUnknownSchemaNode( - qname, actualPath); - updatePath(name); + qname, actualPath, ctx.getStart().getLine()); + builder.setNodeType(nodeType); + builder.setNodeParameter(nodeParameter); + updatePath(nodeParameter); builder.setPath(createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix)); parseSchemaNodeArgs(ctx, builder); @@ -669,7 +707,7 @@ public final class YangModelParserListenerImpl extends YangParserBaseListener { QName rpcQName = new QName(namespace, revision, yangModelPrefix, rpcName); RpcDefinitionBuilder rpcBuilder = moduleBuilder.addRpc(rpcQName, - actualPath); + actualPath, ctx.getStart().getLine()); updatePath(rpcName); rpcBuilder.setPath(createActualSchemaPath(actualPath, namespace, @@ -711,7 +749,7 @@ public final class YangModelParserListenerImpl extends YangParserBaseListener { QName featureQName = new QName(namespace, revision, yangModelPrefix, featureName); FeatureBuilder featureBuilder = moduleBuilder.addFeature(featureQName, - actualPath); + actualPath, ctx.getStart().getLine()); updatePath(featureName); featureBuilder.setPath(createActualSchemaPath(actualPath, namespace, @@ -731,7 +769,7 @@ public final class YangModelParserListenerImpl extends YangParserBaseListener { String reference = null; String deviate = null; DeviationBuilder builder = moduleBuilder.addDeviation(targetPath, - actualPath); + actualPath, ctx.getStart().getLine()); updatePath(targetPath); for (int i = 0; i < ctx.getChildCount(); i++) { @@ -769,8 +807,8 @@ public final class YangModelParserListenerImpl extends YangParserBaseListener { final String identityName = stringFromNode(ctx); final QName identityQName = new QName(namespace, revision, yangModelPrefix, identityName); - IdentitySchemaNodeBuilder builder = moduleBuilder - .addIdentity(identityQName, actualPath); + IdentitySchemaNodeBuilder builder = moduleBuilder.addIdentity( + identityQName, actualPath, ctx.getStart().getLine()); updatePath(identityName); builder.setPath(createActualSchemaPath(actualPath, namespace, revision,