- public void enterStatement(YangStatementParser.StatementContext ctx) {
- boolean action = true;
- for (int i = 0; i < ctx.getChildCount(); i++) {
- ParseTree child = ctx.getChild(i);
- if (child instanceof YangStatementParser.KeywordContext) {
- try {
- QName identifier = new QName(YangConstants.RFC6020_YIN_NAMESPACE,
- ((YangStatementParser.KeywordContext) child).children.get(0).getText());
- if (stmtDef != null && Utils.isValidStatementDefinition(prefixes, stmtDef, identifier) && toBeSkipped.isEmpty()) {
- writer.startStatement(identifier, ref);
- } else {
- action = false;
- toBeSkipped.add(((YangStatementParser.KeywordContext) child).children.get(0).getText());
- }
- } catch (SourceException e) {
- LOG.warn(e.getMessage(), e);
+ public void enterStatement(final StatementContext ctx) {
+ final StatementSourceReference ref = DeclarationInTextSource.atPosition(sourceName, ctx
+ .getStart().getLine(), ctx.getStart().getCharPositionInLine());
+ final KeywordContext keywordCtx = Verify.verifyNotNull(ctx.getChild(KeywordContext.class, 0));
+ final ArgumentContext argumentCtx = ctx.getChild(ArgumentContext.class, 0);
+ final String keywordTxt = keywordCtx.getText();
+
+ final QName identifier = QName.create(YangConstants.RFC6020_YIN_MODULE, keywordTxt);
+ final QName validStatementDefinition = Utils.getValidStatementDefinition(prefixes, stmtDef, identifier);
+ if (stmtDef != null && validStatementDefinition != null && toBeSkipped.isEmpty()) {
+ final String argument = argumentCtx != null ? Utils.stringFromStringContext(argumentCtx) : null;
+ // FIXME: Refactor/clean up this special case
+ if (identifier.equals(Rfc6020Mapping.TYPE.getStatementName())) {
+ Preconditions.checkArgument(argument != null);
+ if (TypeUtils.isYangTypeBodyStmtString(argument)) {
+ writer.startStatement(QName.create(YangConstants.RFC6020_YIN_MODULE, argument), ref);
+ } else {
+ writer.startStatement(QName.create(YangConstants.RFC6020_YIN_MODULE, Rfc6020Mapping
+ .TYPE.getStatementName().getLocalName()), ref);