Gaurav Agrawal
Committed by Gerrit Code Review

[ONOS-3880, 3881] Change to static import for lesser indentation.

Change-Id: I93a39f9b0ccd019ace5900bf8ba68f7d60f228a0
Showing 17 changed files with 304 additions and 395 deletions
......@@ -19,14 +19,17 @@ package org.onosproject.yangutils.parser.impl.listeners;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangSubModule;
import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation;
import static org.onosproject.yangutils.parser.ParsableDataType.YANGBASE_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.*;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsEmpty;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
......@@ -49,9 +52,8 @@ public final class BaseFileListener {
}
/**
* It is called when parser receives an input matching the grammar
* rule (yangfile), perform validations and update the data model
* tree.
* It is called when parser receives an input matching the grammar rule
* (yangfile), perform validations and update the data model tree.
*
* @param listener Listener's object.
* @param ctx context object of the grammar rule.
......@@ -59,8 +61,7 @@ public final class BaseFileListener {
public static void processYangFileEntry(TreeWalkListener listener, GeneratedYangParser.YangfileContext ctx) {
// Check if stack is empty.
ListenerValidation.checkStackIsEmpty(listener, ListenerErrorType.INVALID_HOLDER,
ParsableDataType.YANGBASE_DATA, "", ListenerErrorLocation.ENTRY);
checkStackIsEmpty(listener, INVALID_HOLDER, YANGBASE_DATA, "", ENTRY);
}
......@@ -74,23 +75,17 @@ public final class BaseFileListener {
public static void processYangFileExit(TreeWalkListener listener, GeneratedYangParser.YangfileContext ctx) {
// Check for stack to be non empty.
ListenerValidation.checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER,
ParsableDataType.YANGBASE_DATA, "", ListenerErrorLocation.EXIT);
checkStackIsNotEmpty(listener, MISSING_HOLDER, YANGBASE_DATA, "", EXIT);
// Data Model tree root node is set.
if (listener.getParsedDataStack().peek() instanceof YangModule
| listener.getParsedDataStack().peek() instanceof YangSubModule) {
|| listener.getParsedDataStack().peek() instanceof YangSubModule) {
listener.setRootNode((YangNode) listener.getParsedDataStack().pop());
} else {
throw new ParserException(
ListenerErrorMessageConstruction
.constructListenerErrorMessage(ListenerErrorType.INVALID_CHILD,
ParsableDataType.YANGBASE_DATA, "",
ListenerErrorLocation.EXIT));
throw new ParserException(constructListenerErrorMessage(INVALID_CHILD, YANGBASE_DATA, "", EXIT));
}
// Check if stack is empty.
ListenerValidation.checkStackIsEmpty(listener, ListenerErrorType.INVALID_HOLDER,
ParsableDataType.YANGBASE_DATA, "", ListenerErrorLocation.EXIT);
checkStackIsEmpty(listener, INVALID_HOLDER, YANGBASE_DATA, "", EXIT);
}
}
\ No newline at end of file
}
......
......@@ -19,14 +19,16 @@ package org.onosproject.yangutils.parser.impl.listeners;
import org.onosproject.yangutils.datamodel.YangBelongsTo;
import org.onosproject.yangutils.datamodel.YangSubModule;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation;
import static org.onosproject.yangutils.parser.ParsableDataType.BELONGS_TO_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.*;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
......@@ -52,8 +54,9 @@ import org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation;
*/
/**
* Implements listener based call back function corresponding to the "belongs to"
* rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
* Implements listener based call back function corresponding to the
* "belongs to" rule defined in ANTLR grammar file for corresponding ABNF rule
* in RFC 6020.
*/
public final class BelongsToListener {
......@@ -64,9 +67,8 @@ public final class BelongsToListener {
}
/**
* It is called when parser receives an input matching the grammar
* rule (belongsto), perform validations and update the data model
* tree.
* It is called when parser receives an input matching the grammar rule
* (belongsto), perform validations and update the data model tree.
*
* @param listener Listener's object.
* @param ctx context object of the grammar rule.
......@@ -75,10 +77,8 @@ public final class BelongsToListener {
GeneratedYangParser.BelongstoStatementContext ctx) {
// Check for stack to be non empty.
ListenerValidation.checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER,
ParsableDataType.BELONGS_TO_DATA,
String.valueOf(ctx.IDENTIFIER().getText()),
ListenerErrorLocation.ENTRY);
checkStackIsNotEmpty(listener, MISSING_HOLDER, BELONGS_TO_DATA, String.valueOf(ctx.IDENTIFIER().getText()),
ENTRY);
YangBelongsTo belongstoNode = new YangBelongsTo();
belongstoNode.setBelongsToModuleName(String.valueOf(ctx.IDENTIFIER().getText()));
......@@ -98,20 +98,16 @@ public final class BelongsToListener {
GeneratedYangParser.BelongstoStatementContext ctx) {
// Check for stack to be non empty.
ListenerValidation.checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER,
ParsableDataType.BELONGS_TO_DATA,
String.valueOf(ctx.IDENTIFIER().getText()),
ListenerErrorLocation.EXIT);
checkStackIsNotEmpty(listener, MISSING_HOLDER, BELONGS_TO_DATA, String.valueOf(ctx.IDENTIFIER().getText()),
EXIT);
Parsable tmpBelongstoNode = listener.getParsedDataStack().peek();
if (tmpBelongstoNode instanceof YangBelongsTo) {
listener.getParsedDataStack().pop();
// Check for stack to be empty.
ListenerValidation.checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER,
ParsableDataType.BELONGS_TO_DATA,
String.valueOf(ctx.IDENTIFIER().getText()),
ListenerErrorLocation.EXIT);
checkStackIsNotEmpty(listener, MISSING_HOLDER, BELONGS_TO_DATA,
String.valueOf(ctx.IDENTIFIER().getText()), EXIT);
Parsable tmpNode = listener.getParsedDataStack().peek();
switch (tmpNode.getParsableDataType()) {
......@@ -121,22 +117,13 @@ public final class BelongsToListener {
break;
}
default:
throw new ParserException(
ListenerErrorMessageConstruction
.constructListenerErrorMessage(ListenerErrorType.INVALID_HOLDER,
ParsableDataType.BELONGS_TO_DATA,
String.valueOf(ctx.IDENTIFIER()
.getText()),
ListenerErrorLocation.EXIT));
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, BELONGS_TO_DATA,
String.valueOf(ctx.IDENTIFIER().getText()),
EXIT));
}
} else {
throw new ParserException(
ListenerErrorMessageConstruction
.constructListenerErrorMessage(ListenerErrorType.MISSING_CURRENT_HOLDER,
ParsableDataType.BELONGS_TO_DATA,
String.valueOf(ctx.IDENTIFIER()
.getText()),
ListenerErrorLocation.EXIT));
throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, BELONGS_TO_DATA,
String.valueOf(ctx.IDENTIFIER().getText()), EXIT));
}
}
}
\ No newline at end of file
}
......
......@@ -19,14 +19,16 @@ package org.onosproject.yangutils.parser.impl.listeners;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangSubModule;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation;
import static org.onosproject.yangutils.parser.ParsableDataType.CONTACT_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
......@@ -81,9 +83,8 @@ public final class ContactListener {
}
/**
* It is called when parser receives an input matching the grammar
* rule (contact), perform validations and update the data model
* tree.
* It is called when parser receives an input matching the grammar rule
* (contact), perform validations and update the data model tree.
*
* @param listener Listener's object.
* @param ctx context object of the grammar rule.
......@@ -91,9 +92,7 @@ public final class ContactListener {
public static void processContactEntry(TreeWalkListener listener, GeneratedYangParser.ContactStatementContext ctx) {
// Check for stack to be non empty.
ListenerValidation.checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER,
ParsableDataType.CONTACT_DATA,
String.valueOf(ctx.string().getText()), ListenerErrorLocation.ENTRY);
checkStackIsNotEmpty(listener, MISSING_HOLDER, CONTACT_DATA, String.valueOf(ctx.string().getText()), ENTRY);
// Obtain the node of the stack.
Parsable tmpNode = listener.getParsedDataStack().peek();
......@@ -109,12 +108,8 @@ public final class ContactListener {
break;
}
default:
throw new ParserException(
ListenerErrorMessageConstruction
.constructListenerErrorMessage(ListenerErrorType.INVALID_HOLDER,
ParsableDataType.CONTACT_DATA,
String.valueOf(ctx.string().getText()),
ListenerErrorLocation.ENTRY));
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, CONTACT_DATA,
String.valueOf(ctx.string().getText()), ENTRY));
}
}
}
\ No newline at end of file
}
......
......@@ -20,14 +20,16 @@ import org.onosproject.yangutils.datamodel.YangImport;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangSubModule;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation;
import static org.onosproject.yangutils.parser.ParsableDataType.IMPORT_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.*;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
......@@ -64,9 +66,8 @@ public final class ImportListener {
}
/**
* It is called when parser receives an input matching the grammar
* rule (import), perform validations and update the data model
* tree.
* It is called when parser receives an input matching the grammar rule
* (import), perform validations and update the data model tree.
*
* @param listener Listener's object.
* @param ctx context object of the grammar rule.
......@@ -74,10 +75,7 @@ public final class ImportListener {
public static void processImportEntry(TreeWalkListener listener, GeneratedYangParser.ImportStatementContext ctx) {
// Check for stack to be non empty.
ListenerValidation.checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER,
ParsableDataType.IMPORT_DATA,
String.valueOf(ctx.IDENTIFIER().getText()),
ListenerErrorLocation.ENTRY);
checkStackIsNotEmpty(listener, MISSING_HOLDER, IMPORT_DATA, String.valueOf(ctx.IDENTIFIER().getText()), ENTRY);
YangImport importNode = new YangImport();
importNode.setModuleName(String.valueOf(ctx.IDENTIFIER().getText()));
......@@ -96,20 +94,15 @@ public final class ImportListener {
public static void processImportExit(TreeWalkListener listener, GeneratedYangParser.ImportStatementContext ctx) {
// Check for stack to be non empty.
ListenerValidation.checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER,
ParsableDataType.IMPORT_DATA,
String.valueOf(ctx.IDENTIFIER().getText()),
ListenerErrorLocation.EXIT);
checkStackIsNotEmpty(listener, MISSING_HOLDER, IMPORT_DATA, String.valueOf(ctx.IDENTIFIER().getText()), EXIT);
Parsable tmpImportNode = listener.getParsedDataStack().peek();
if (tmpImportNode instanceof YangImport) {
listener.getParsedDataStack().pop();
// Check for stack to be non empty.
ListenerValidation.checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER,
ParsableDataType.IMPORT_DATA,
String.valueOf(ctx.IDENTIFIER().getText()),
ListenerErrorLocation.EXIT);
checkStackIsNotEmpty(listener, MISSING_HOLDER, IMPORT_DATA, String.valueOf(ctx.IDENTIFIER().getText()),
EXIT);
Parsable tmpNode = listener.getParsedDataStack().peek();
switch (tmpNode.getParsableDataType()) {
......@@ -124,22 +117,13 @@ public final class ImportListener {
break;
}
default:
throw new ParserException(
ListenerErrorMessageConstruction
.constructListenerErrorMessage(ListenerErrorType.INVALID_HOLDER,
ParsableDataType.IMPORT_DATA,
String.valueOf(ctx.IDENTIFIER()
.getText()),
ListenerErrorLocation.EXIT));
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, IMPORT_DATA,
String.valueOf(ctx.IDENTIFIER().getText()),
EXIT));
}
} else {
throw new ParserException(
ListenerErrorMessageConstruction
.constructListenerErrorMessage(ListenerErrorType.MISSING_CURRENT_HOLDER,
ParsableDataType.IMPORT_DATA, String
.valueOf(ctx.IDENTIFIER()
.getText()),
ListenerErrorLocation.EXIT));
throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, IMPORT_DATA,
String.valueOf(ctx.IDENTIFIER().getText()), EXIT));
}
}
}
\ No newline at end of file
}
......
......@@ -20,14 +20,16 @@ import org.onosproject.yangutils.datamodel.YangInclude;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangSubModule;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation;
import static org.onosproject.yangutils.parser.ParsableDataType.INCLUDE_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.*;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
......@@ -63,9 +65,8 @@ public final class IncludeListener {
}
/**
* It is called when parser receives an input matching the grammar
* rule (include), perform validations and update the data model
* tree.
* It is called when parser receives an input matching the grammar rule
* (include), perform validations and update the data model tree.
*
* @param listener Listener's object.
* @param ctx context object of the grammar rule.
......@@ -73,10 +74,8 @@ public final class IncludeListener {
public static void processIncludeEntry(TreeWalkListener listener, GeneratedYangParser.IncludeStatementContext ctx) {
// Check for stack to be non empty.
ListenerValidation.checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER,
ParsableDataType.INCLUDE_DATA,
String.valueOf(ctx.IDENTIFIER().getText()),
ListenerErrorLocation.ENTRY);
checkStackIsNotEmpty(listener, MISSING_HOLDER, INCLUDE_DATA, String.valueOf(ctx.IDENTIFIER().getText()),
ENTRY);
YangInclude includeNode = new YangInclude();
includeNode.setSubModuleName(String.valueOf(ctx.IDENTIFIER().getText()));
......@@ -94,20 +93,15 @@ public final class IncludeListener {
public static void processIncludeExit(TreeWalkListener listener, GeneratedYangParser.IncludeStatementContext ctx) {
// Check for stack to be non empty.
ListenerValidation.checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER,
ParsableDataType.INCLUDE_DATA,
String.valueOf(ctx.IDENTIFIER().getText()),
ListenerErrorLocation.EXIT);
checkStackIsNotEmpty(listener, MISSING_HOLDER, INCLUDE_DATA, String.valueOf(ctx.IDENTIFIER().getText()), EXIT);
Parsable tmpIncludeNode = listener.getParsedDataStack().peek();
if (tmpIncludeNode instanceof YangInclude) {
listener.getParsedDataStack().pop();
// Check for stack to be non empty.
ListenerValidation.checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER,
ParsableDataType.INCLUDE_DATA,
String.valueOf(ctx.IDENTIFIER().getText()),
ListenerErrorLocation.EXIT);
checkStackIsNotEmpty(listener, MISSING_HOLDER, INCLUDE_DATA, String.valueOf(ctx.IDENTIFIER().getText()),
EXIT);
Parsable tmpNode = listener.getParsedDataStack().peek();
switch (tmpNode.getParsableDataType()) {
......@@ -122,22 +116,13 @@ public final class IncludeListener {
break;
}
default:
throw new ParserException(
ListenerErrorMessageConstruction
.constructListenerErrorMessage(ListenerErrorType.INVALID_HOLDER,
ParsableDataType.INCLUDE_DATA,
String.valueOf(ctx.IDENTIFIER()
.getText()),
ListenerErrorLocation.EXIT));
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, INCLUDE_DATA,
String.valueOf(ctx.IDENTIFIER().getText()),
EXIT));
}
} else {
throw new ParserException(
ListenerErrorMessageConstruction
.constructListenerErrorMessage(ListenerErrorType.MISSING_CURRENT_HOLDER,
ParsableDataType.INCLUDE_DATA, String
.valueOf(ctx.IDENTIFIER()
.getText()),
ListenerErrorLocation.EXIT));
throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, INCLUDE_DATA,
String.valueOf(ctx.IDENTIFIER().getText()), EXIT));
}
}
}
\ No newline at end of file
}
......
......@@ -17,14 +17,17 @@
package org.onosproject.yangutils.parser.impl.listeners;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation;
import static org.onosproject.yangutils.parser.ParsableDataType.MODULE_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.*;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsEmpty;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
......@@ -57,9 +60,8 @@ public final class ModuleListener {
}
/**
* It is called when parser receives an input matching the grammar
* rule (module), perform validations and update the data model
* tree.
* It is called when parser receives an input matching the grammar rule
* (module), perform validations and update the data model tree.
*
* @param listener Listener's object.
* @param ctx context object of the grammar rule.
......@@ -67,9 +69,7 @@ public final class ModuleListener {
public static void processModuleEntry(TreeWalkListener listener, GeneratedYangParser.ModuleStatementContext ctx) {
// Check if stack is empty.
ListenerValidation
.checkStackIsEmpty(listener, ListenerErrorType.INVALID_HOLDER, ParsableDataType.MODULE_DATA,
String.valueOf(ctx.IDENTIFIER().getText()), ListenerErrorLocation.ENTRY);
checkStackIsEmpty(listener, INVALID_HOLDER, MODULE_DATA, String.valueOf(ctx.IDENTIFIER().getText()), ENTRY);
YangModule yangModule = new YangModule();
yangModule.setName(ctx.IDENTIFIER().getText());
......@@ -87,19 +87,11 @@ public final class ModuleListener {
public static void processModuleExit(TreeWalkListener listener, GeneratedYangParser.ModuleStatementContext ctx) {
// Check for stack to be non empty.
ListenerValidation.checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER,
ParsableDataType.MODULE_DATA,
String.valueOf(ctx.IDENTIFIER().getText()),
ListenerErrorLocation.EXIT);
checkStackIsNotEmpty(listener, MISSING_HOLDER, MODULE_DATA, String.valueOf(ctx.IDENTIFIER().getText()), EXIT);
if (!(listener.getParsedDataStack().peek() instanceof YangModule)) {
throw new ParserException(
ListenerErrorMessageConstruction
.constructListenerErrorMessage(ListenerErrorType.MISSING_CURRENT_HOLDER,
ParsableDataType.MODULE_DATA, String
.valueOf(ctx.IDENTIFIER()
.getText()),
ListenerErrorLocation.EXIT));
throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, MODULE_DATA,
String.valueOf(ctx.IDENTIFIER().getText()), EXIT));
}
}
}
\ No newline at end of file
}
......
......@@ -19,17 +19,19 @@ package org.onosproject.yangutils.parser.impl.listeners;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangNameSpace;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation;
import java.net.URI;
import static org.onosproject.yangutils.parser.ParsableDataType.NAMESPACE_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
*
......@@ -65,9 +67,8 @@ public final class NamespaceListener {
}
/**
* It is called when parser receives an input matching the grammar
* rule (namespace), perform validations and update the data model
* tree.
* It is called when parser receives an input matching the grammar rule
* (namespace), perform validations and update the data model tree.
*
* @param listener Listener's object.
* @param ctx context object of the grammar rule.
......@@ -76,9 +77,7 @@ public final class NamespaceListener {
GeneratedYangParser.NamespaceStatementContext ctx) {
// Check for stack to be non empty.
ListenerValidation.checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER,
ParsableDataType.NAMESPACE_DATA,
String.valueOf(ctx.string().getText()), ListenerErrorLocation.ENTRY);
checkStackIsNotEmpty(listener, MISSING_HOLDER, NAMESPACE_DATA, String.valueOf(ctx.string().getText()), ENTRY);
if (!validateUriValue(String.valueOf(ctx.string().getText()))) {
ParserException parserException = new ParserException("Invalid namespace URI");
......@@ -98,12 +97,8 @@ public final class NamespaceListener {
break;
}
default:
throw new ParserException(
ListenerErrorMessageConstruction
.constructListenerErrorMessage(ListenerErrorType.INVALID_HOLDER,
ParsableDataType.NAMESPACE_DATA,
String.valueOf(ctx.string().getText()),
ListenerErrorLocation.ENTRY));
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, NAMESPACE_DATA,
String.valueOf(ctx.string().getText()), ENTRY));
}
}
......@@ -123,4 +118,4 @@ public final class NamespaceListener {
}
return true;
}
}
\ No newline at end of file
}
......
......@@ -19,14 +19,16 @@ package org.onosproject.yangutils.parser.impl.listeners;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangSubModule;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation;
import static org.onosproject.yangutils.parser.ParsableDataType.ORGANIZATION_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
......@@ -70,8 +72,9 @@ import org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation;
*/
/**
* Implements listener based call back function corresponding to the "organization"
* rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
* Implements listener based call back function corresponding to the
* "organization" rule defined in ANTLR grammar file for corresponding ABNF rule
* in RFC 6020.
*/
public final class OrganizationListener {
......@@ -82,9 +85,8 @@ public final class OrganizationListener {
}
/**
* It is called when parser receives an input matching the grammar
* rule (organization), perform validations and update the data model
* tree.
* It is called when parser receives an input matching the grammar rule
* (organization), perform validations and update the data model tree.
*
* @param listener Listener's object.
* @param ctx context object of the grammar rule.
......@@ -93,9 +95,8 @@ public final class OrganizationListener {
GeneratedYangParser.OrganizationStatementContext ctx) {
// Check for stack to be non empty.
ListenerValidation.checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER,
ParsableDataType.ORGANIZATION_DATA,
String.valueOf(ctx.string().getText()), ListenerErrorLocation.ENTRY);
checkStackIsNotEmpty(listener, MISSING_HOLDER, ORGANIZATION_DATA, String.valueOf(ctx.string().getText()),
ENTRY);
// Obtain the node of the stack.
Parsable tmpNode = listener.getParsedDataStack().peek();
......@@ -111,12 +112,8 @@ public final class OrganizationListener {
break;
}
default:
throw new ParserException(
ListenerErrorMessageConstruction
.constructListenerErrorMessage(ListenerErrorType.INVALID_HOLDER,
ParsableDataType.ORGANIZATION_DATA,
String.valueOf(ctx.string().getText()),
ListenerErrorLocation.ENTRY));
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, ORGANIZATION_DATA,
String.valueOf(ctx.string().getText()), ENTRY));
}
}
}
\ No newline at end of file
}
......
......@@ -20,14 +20,16 @@ import org.onosproject.yangutils.datamodel.YangBelongsTo;
import org.onosproject.yangutils.datamodel.YangImport;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation;
import static org.onosproject.yangutils.parser.ParsableDataType.PREFIX_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
......@@ -65,9 +67,8 @@ public final class PrefixListener {
}
/**
* It is called when parser receives an input matching the grammar
* rule (prefix),perform validations and update the data model
* tree.
* It is called when parser receives an input matching the grammar rule
* (prefix),perform validations and update the data model tree.
*
* @param listener Listener's object.
* @param ctx context object of the grammar rule.
......@@ -75,10 +76,7 @@ public final class PrefixListener {
public static void processPrefixEntry(TreeWalkListener listener, GeneratedYangParser.PrefixStatementContext ctx) {
// Check for stack to be non empty.
ListenerValidation.checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER,
ParsableDataType.PREFIX_DATA,
String.valueOf(ctx.IDENTIFIER().getText()),
ListenerErrorLocation.ENTRY);
checkStackIsNotEmpty(listener, MISSING_HOLDER, PREFIX_DATA, String.valueOf(ctx.IDENTIFIER().getText()), ENTRY);
// Obtain the node of the stack.
Parsable tmpNode = listener.getParsedDataStack().peek();
......@@ -99,13 +97,8 @@ public final class PrefixListener {
break;
}
default:
throw new ParserException(
ListenerErrorMessageConstruction
.constructListenerErrorMessage(ListenerErrorType.INVALID_HOLDER,
ParsableDataType.PREFIX_DATA, String
.valueOf(ctx.IDENTIFIER()
.getText()),
ListenerErrorLocation.ENTRY));
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, PREFIX_DATA,
String.valueOf(ctx.IDENTIFIER().getText()), ENTRY));
}
}
}
\ No newline at end of file
}
......
......@@ -19,14 +19,16 @@ package org.onosproject.yangutils.parser.impl.listeners;
import org.onosproject.yangutils.datamodel.YangImport;
import org.onosproject.yangutils.datamodel.YangInclude;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation;
import static org.onosproject.yangutils.parser.ParsableDataType.REVISION_DATE_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
......@@ -57,8 +59,9 @@ import org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation;
*/
/**
* Implements listener based call back function corresponding to the "revision date"
* rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
* Implements listener based call back function corresponding to the
* "revision date" rule defined in ANTLR grammar file for corresponding ABNF
* rule in RFC 6020.
*/
public final class RevisionDateListener {
......@@ -69,9 +72,8 @@ public final class RevisionDateListener {
}
/**
* It is called when parser receives an input matching the grammar
* rule (revision date),perform validations and update the data model
* tree.
* It is called when parser receives an input matching the grammar rule
* (revision date),perform validations and update the data model tree.
*
* @param listener Listener's object.
* @param ctx context object of the grammar rule.
......@@ -80,10 +82,8 @@ public final class RevisionDateListener {
GeneratedYangParser.RevisionDateStatementContext ctx) {
// Check for stack to be non empty.
ListenerValidation.checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER,
ParsableDataType.REVISION_DATE_DATA,
String.valueOf(ctx.DATE_ARG().getText()),
ListenerErrorLocation.ENTRY);
checkStackIsNotEmpty(listener, MISSING_HOLDER, REVISION_DATE_DATA, String.valueOf(ctx.DATE_ARG().getText()),
ENTRY);
// Obtain the node of the stack.
Parsable tmpNode = listener.getParsedDataStack().peek();
......@@ -99,13 +99,9 @@ public final class RevisionDateListener {
break;
}
default:
throw new ParserException(
ListenerErrorMessageConstruction
.constructListenerErrorMessage(ListenerErrorType.INVALID_HOLDER,
ParsableDataType.REVISION_DATE_DATA,
String.valueOf(ctx.DATE_ARG().getText()),
ListenerErrorLocation.ENTRY));
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, REVISION_DATE_DATA,
String.valueOf(ctx.DATE_ARG().getText()), ENTRY));
}
}
// TODO Implement the DATE_ARG validation as per RFC 6020.
}
\ No newline at end of file
}
......
......@@ -20,14 +20,16 @@ import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangRevision;
import org.onosproject.yangutils.datamodel.YangSubModule;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation;
import static org.onosproject.yangutils.parser.ParsableDataType.REVISION_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.*;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
......@@ -69,16 +71,21 @@ public final class RevisionListener {
private RevisionListener() {
}
/**
* It is called when parser receives an input matching the grammar rule
* (revision),perform validations and update the data model tree.
*
* @param listener Listener's object.
* @param ctx context object of the grammar rule.
*/
public static void processRevisionEntry(TreeWalkListener listener,
GeneratedYangParser.RevisionStatementContext ctx) {
// Check for stack to be non empty.
ListenerValidation.checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER,
ParsableDataType.REVISION_DATA,
String.valueOf(ctx.DATE_ARG().getText()),
ListenerErrorLocation.ENTRY);
checkStackIsNotEmpty(listener, MISSING_HOLDER, REVISION_DATA, String.valueOf(ctx.DATE_ARG().getText()), ENTRY);
// Validate for reverse chronological order of revision & for revision value.
// Validate for reverse chronological order of revision & for revision
// value.
if (!validateRevision(listener, ctx)) {
return;
// TODO to be implemented.
......@@ -97,23 +104,19 @@ public final class RevisionListener {
* @param listener Listener's object.
* @param ctx context object of the grammar rule.
*/
public static void processRevisionExit(TreeWalkListener listener,
GeneratedYangParser.RevisionStatementContext ctx) {
public static void processRevisionExit(TreeWalkListener listener, GeneratedYangParser.RevisionStatementContext
ctx) {
// Check for stack to be non empty.
ListenerValidation
.checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER, ParsableDataType.REVISION_DATA,
String.valueOf(ctx.DATE_ARG().getText()), ListenerErrorLocation.EXIT);
checkStackIsNotEmpty(listener, MISSING_HOLDER, REVISION_DATA, String.valueOf(ctx.DATE_ARG().getText()), EXIT);
Parsable tmpRevisionNode = listener.getParsedDataStack().peek();
if (tmpRevisionNode instanceof YangRevision) {
listener.getParsedDataStack().pop();
// Check for stack to be non empty.
ListenerValidation.checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER,
ParsableDataType.REVISION_DATA,
String.valueOf(ctx.DATE_ARG().getText()),
ListenerErrorLocation.EXIT);
checkStackIsNotEmpty(listener, MISSING_HOLDER, REVISION_DATA, String.valueOf(ctx.DATE_ARG().getText()),
EXIT);
Parsable tmpNode = listener.getParsedDataStack().peek();
switch (tmpNode.getParsableDataType()) {
......@@ -128,22 +131,13 @@ public final class RevisionListener {
break;
}
default:
throw new ParserException(
ListenerErrorMessageConstruction
.constructListenerErrorMessage(ListenerErrorType.INVALID_HOLDER,
ParsableDataType.REVISION_DATA,
String.valueOf(ctx.DATE_ARG()
.getText()),
ListenerErrorLocation.EXIT));
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, REVISION_DATA,
String.valueOf(ctx.DATE_ARG().getText()),
EXIT));
}
} else {
throw new ParserException(
ListenerErrorMessageConstruction
.constructListenerErrorMessage(ListenerErrorType.MISSING_CURRENT_HOLDER,
ParsableDataType.REVISION_DATA, String
.valueOf(ctx.DATE_ARG()
.getText()),
ListenerErrorLocation.EXIT));
throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, REVISION_DATA,
String.valueOf(ctx.DATE_ARG().getText()), EXIT));
}
}
......@@ -159,4 +153,4 @@ public final class RevisionListener {
// TODO to be implemented
return true;
}
}
\ No newline at end of file
}
......
......@@ -17,14 +17,17 @@
package org.onosproject.yangutils.parser.impl.listeners;
import org.onosproject.yangutils.datamodel.YangSubModule;
import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation;
import static org.onosproject.yangutils.parser.ParsableDataType.SUB_MODULE_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.*;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsEmpty;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
......@@ -58,9 +61,8 @@ public final class SubModuleListener {
}
/**
* It is called when parser receives an input matching the grammar
* rule (sub module), perform validations and update the data model
* tree.
* It is called when parser receives an input matching the grammar rule (sub
* module), perform validations and update the data model tree.
*
* @param listener Listener's object.
* @param ctx context object of the grammar rule.
......@@ -69,9 +71,8 @@ public final class SubModuleListener {
GeneratedYangParser.SubModuleStatementContext ctx) {
// Check if stack is empty.
ListenerValidation
.checkStackIsEmpty(listener, ListenerErrorType.INVALID_HOLDER, ParsableDataType.SUB_MODULE_DATA,
String.valueOf(ctx.IDENTIFIER().getText()), ListenerErrorLocation.ENTRY);
checkStackIsEmpty(listener, INVALID_HOLDER, SUB_MODULE_DATA, String.valueOf(ctx.IDENTIFIER().getText()),
ENTRY);
YangSubModule yangSubModule = new YangSubModule();
yangSubModule.setName(ctx.IDENTIFIER().getText());
......@@ -90,19 +91,12 @@ public final class SubModuleListener {
GeneratedYangParser.SubModuleStatementContext ctx) {
// Check for stack to be non empty.
ListenerValidation.checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER,
ParsableDataType.SUB_MODULE_DATA,
String.valueOf(ctx.IDENTIFIER().getText()),
ListenerErrorLocation.EXIT);
checkStackIsNotEmpty(listener, MISSING_HOLDER, SUB_MODULE_DATA, String.valueOf(ctx.IDENTIFIER().getText()),
EXIT);
if (!(listener.getParsedDataStack().peek() instanceof YangSubModule)) {
throw new ParserException(
ListenerErrorMessageConstruction
.constructListenerErrorMessage(ListenerErrorType.MISSING_CURRENT_HOLDER,
ParsableDataType.SUB_MODULE_DATA,
String.valueOf(ctx.IDENTIFIER()
.getText()),
ListenerErrorLocation.EXIT));
throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, SUB_MODULE_DATA,
String.valueOf(ctx.IDENTIFIER().getText()), EXIT));
}
}
}
\ No newline at end of file
}
......
......@@ -19,14 +19,16 @@ package org.onosproject.yangutils.parser.impl.listeners;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangSubModule;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation;
import static org.onosproject.yangutils.parser.ParsableDataType.VERSION_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
......@@ -73,9 +75,8 @@ public final class VersionListener {
}
/**
* It is called when parser receives an input matching the grammar
* rule (version), perform validations and update the data model
* tree.
* It is called when parser receives an input matching the grammar rule
* (version), perform validations and update the data model tree.
*
* @param listener Listener's object.
* @param ctx context object of the grammar rule.
......@@ -84,9 +85,7 @@ public final class VersionListener {
GeneratedYangParser.YangVersionStatementContext ctx) {
// Check for stack to be non empty.
ListenerValidation
.checkStackIsNotEmpty(listener, ListenerErrorType.MISSING_HOLDER, ParsableDataType.VERSION_DATA,
String.valueOf(ctx.INTEGER().getText()), ListenerErrorLocation.ENTRY);
checkStackIsNotEmpty(listener, MISSING_HOLDER, VERSION_DATA, String.valueOf(ctx.INTEGER().getText()), ENTRY);
Integer version = Integer.valueOf(ctx.INTEGER().getText());
if (!isVersionValid(version)) {
......@@ -110,10 +109,8 @@ public final class VersionListener {
break;
}
default:
throw new ParserException(ListenerErrorMessageConstruction.
constructListenerErrorMessage(ListenerErrorType.INVALID_HOLDER,
ParsableDataType.VERSION_DATA, String.valueOf(ctx.INTEGER().getText()),
ListenerErrorLocation.ENTRY));
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, VERSION_DATA,
String.valueOf(ctx.INTEGER().getText()), ENTRY));
}
}
......@@ -126,4 +123,4 @@ public final class VersionListener {
private static boolean isVersionValid(Integer version) {
return version == 1;
}
}
\ No newline at end of file
}
......
......@@ -18,6 +18,10 @@ package org.onosproject.yangutils.parser.impl.parserutils;
import org.onosproject.yangutils.parser.ParsableDataType;
import static org.onosproject.yangutils.parser.ParsableDataType.getParsableDataType;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.getErrorLocationMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.getErrorType;
/**
* It's a utility to help construct detailed error message.
*/
......@@ -30,13 +34,15 @@ public final class ListenerErrorMessageConstruction {
}
/**
* Constructs message for error with extended information and returns the same.
* Constructs message for error with extended information and returns the
* same.
*
* @param errorType error type needs to be set in error message.
* @param parsableDataType type of parsable data in which error occurred.
* @param parsableDataTypeName identifier/string of parsable data type in which error occurred.
* @param errorLocation location where error occurred.
* @param extendedErrorInformation extended error information.
* @param errorType error type needs to be set in error message.
* @param parsableDataType type of parsable data in which error occurred.
* @param parsableDataTypeName identifier/string of parsable data type in
* which error occurred.
* @param errorLocation location where error occurred.
* @param extendedErrorInformation extended error information.
* @return constructed error message.
*/
public static String constructExtendedListenerErrorMessage(ListenerErrorType errorType,
......@@ -46,16 +52,21 @@ public final class ListenerErrorMessageConstruction {
String extendedErrorInformation) {
String newErrorMessage;
newErrorMessage = constructListenerErrorMessage(errorType, parsableDataType, parsableDataTypeName,
errorLocation) + "\n" + "Error Information: " + extendedErrorInformation;
errorLocation)
+ "\n"
+ "Error Information: "
+ extendedErrorInformation;
return newErrorMessage;
}
/**
* Constructs message for error during listener based tree walk and returns the same.
* Constructs message for error during listener based tree walk and returns
* the same.
*
* @param errorType error type needs to be set in error message.
* @param parsableDataType type of parsable data in which error occurred.
* @param parsableDataTypeName identifier/string of parsable data type in which error occurred.
* @param parsableDataTypeName identifier/string of parsable data type in
* which error occurred.
* @param errorLocation location where error occurred.
* @return constructed error message.
*/
......@@ -66,9 +77,8 @@ public final class ListenerErrorMessageConstruction {
String errorMessage;
errorMessage = "Internal parser error detected: " + ListenerErrorType.getErrorType(errorType) + " "
+ ParsableDataType.getParsableDataType(parsableDataType);
errorMessage = "Internal parser error detected: " + getErrorType(errorType) + " "
+ getParsableDataType(parsableDataType);
if (!parsableDataTypeName.isEmpty()) {
errorMessage = errorMessage + " \"" + parsableDataTypeName + "\" ";
......@@ -76,7 +86,7 @@ public final class ListenerErrorMessageConstruction {
errorMessage = errorMessage + " ";
}
errorMessage = errorMessage + ListenerErrorLocation.getErrorLocationMessage(errorLocation) + " processing.";
errorMessage = errorMessage + getErrorLocationMessage(errorLocation) + " processing.";
return errorMessage;
}
}
\ No newline at end of file
}
......
......@@ -19,6 +19,7 @@ package org.onosproject.yangutils.parser.impl.parserutils;
import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
/**
* It's a utility to carry out listener validation.
......@@ -37,19 +38,21 @@ public final class ListenerValidation {
* @param listener Listener's object.
* @param errorType error type needs to be set in error message.
* @param parsableDataType type of parsable data in which error occurred.
* @param parsableDataTypeName name of parsable data type in which error occurred.
* @param parsableDataTypeName name of parsable data type in which error
* occurred.
* @param errorLocation location where error occurred.
*/
public static void checkStackIsNotEmpty(TreeWalkListener listener, ListenerErrorType errorType,
ParsableDataType parsableDataType, String parsableDataTypeName,
ListenerErrorLocation errorLocation) {
ParsableDataType parsableDataType, String parsableDataTypeName,
ListenerErrorLocation errorLocation) {
if (listener.getParsedDataStack().empty()) {
/*
* If stack is empty it indicates error condition, value of parsableDataTypeName will be null in case there
* is no name attached to parsable data type.
* If stack is empty it indicates error condition, value of
* parsableDataTypeName will be null in case there is no name
* attached to parsable data type.
*/
String message = ListenerErrorMessageConstruction.constructListenerErrorMessage(errorType, parsableDataType,
parsableDataTypeName, errorLocation);
String message = constructListenerErrorMessage(errorType, parsableDataType, parsableDataTypeName,
errorLocation);
throw new ParserException(message);
}
}
......@@ -60,22 +63,24 @@ public final class ListenerValidation {
* @param listener Listener's object.
* @param errorType error type needs to be set in error message.
* @param parsableDataType type of parsable data in which error occurred.
* @param parsableDataTypeName name of parsable data type in which error occurred.
* @param parsableDataTypeName name of parsable data type in which error
* occurred.
* @param errorLocation location where error occurred.
*/
public static void checkStackIsEmpty(TreeWalkListener listener, ListenerErrorType errorType,
ParsableDataType parsableDataType, String parsableDataTypeName,
ListenerErrorLocation errorLocation) {
ParsableDataType parsableDataType, String parsableDataTypeName,
ListenerErrorLocation errorLocation) {
if (!listener.getParsedDataStack().empty()) {
/*
* If stack is empty it indicates error condition, value of parsableDataTypeName will be null in case there
* is no name attached to parsable data type.
* If stack is empty it indicates error condition, value of
* parsableDataTypeName will be null in case there is no name
* attached to parsable data type.
*/
String message = ListenerErrorMessageConstruction.constructListenerErrorMessage(errorType, parsableDataType,
parsableDataTypeName, errorLocation);
String message = constructListenerErrorMessage(errorType, parsableDataType, parsableDataTypeName,
errorLocation);
throw new ParserException(message);
}
}
}
\ No newline at end of file
}
......
......@@ -17,13 +17,14 @@
package org.onosproject.yangutils.parser.parseutils;
import org.junit.Test;
import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
import static org.onosproject.yangutils.parser.ParsableDataType.CONTACT_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructExtendedListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
/**
* Test case for testing listener error message construction util.
......@@ -37,9 +38,7 @@ public class ListenerErrorMessageConstructionTest {
public void checkErrorMsgConstructionWithName() {
// Create an test error message
String testErrorMessage = ListenerErrorMessageConstruction
.constructListenerErrorMessage(ListenerErrorType.INVALID_HOLDER, ParsableDataType.CONTACT_DATA,
"Test Instance", ListenerErrorLocation.ENTRY);
String testErrorMessage = constructListenerErrorMessage(INVALID_HOLDER, CONTACT_DATA, "Test Instance", ENTRY);
// Check message.
assertThat(testErrorMessage, is("Internal parser error detected: Invalid holder for contact "
......@@ -53,9 +52,7 @@ public class ListenerErrorMessageConstructionTest {
public void checkErrorMsgConstructionWithoutName() {
// Create an test error message
String testErrorMessage = ListenerErrorMessageConstruction
.constructListenerErrorMessage(ListenerErrorType.INVALID_HOLDER, ParsableDataType.CONTACT_DATA,
"Test Instance", ListenerErrorLocation.ENTRY);
String testErrorMessage = constructListenerErrorMessage(INVALID_HOLDER, CONTACT_DATA, "Test Instance", ENTRY);
// Check message.
assertThat(testErrorMessage,
......@@ -64,16 +61,16 @@ public class ListenerErrorMessageConstructionTest {
}
/**
* Checks for extended error message construction with parsable data type name.
* Checks for extended error message construction with parsable data type
* name.
*/
@Test
public void checkExtendedErrorMsgConstructionWithName() {
// Create an test error message
String testErrorMessage = ListenerErrorMessageConstruction
.constructExtendedListenerErrorMessage(ListenerErrorType.INVALID_HOLDER,
ParsableDataType.CONTACT_DATA, "Test Instance",
ListenerErrorLocation.ENTRY, "Extended Information");
String testErrorMessage = constructExtendedListenerErrorMessage(INVALID_HOLDER, CONTACT_DATA,
"Test Instance", ENTRY,
"Extended Information");
// Check message.
assertThat(testErrorMessage,
......@@ -82,19 +79,18 @@ public class ListenerErrorMessageConstructionTest {
}
/**
* Checks for extended error message construction without parsable data type name.
* Checks for extended error message construction without parsable data type
* name.
*/
@Test
public void checkExtendedErrorMsgConstructionWithoutName() {
// Create an test error message
String testErrorMessage = ListenerErrorMessageConstruction
.constructExtendedListenerErrorMessage(ListenerErrorType.INVALID_HOLDER,
ParsableDataType.CONTACT_DATA, "",
ListenerErrorLocation.ENTRY, "Extended Information");
String testErrorMessage = constructExtendedListenerErrorMessage(INVALID_HOLDER, CONTACT_DATA, "", ENTRY,
"Extended Information");
// Check message.
assertThat(testErrorMessage, is("Internal parser error detected: Invalid holder for contact"
+ " before processing.\n" + "Error Information: Extended Information"));
}
}
\ No newline at end of file
}
......
......@@ -20,13 +20,15 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.onosproject.yangutils.datamodel.YangRevision;
import org.onosproject.yangutils.parser.ParsableDataType;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType;
import org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation;
import static org.onosproject.yangutils.parser.ParsableDataType.YANGBASE_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsEmpty;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
/**
* Test case for testing listener validation util.
......@@ -43,9 +45,7 @@ public class ListenerValidationTest {
@Test
public void validateStackIsNotEmptyForEmptyStack() {
String expectedError = ListenerErrorMessageConstruction
.constructListenerErrorMessage(ListenerErrorType.MISSING_HOLDER, ParsableDataType.YANGBASE_DATA, "",
ListenerErrorLocation.EXIT);
String expectedError = constructListenerErrorMessage(MISSING_HOLDER, YANGBASE_DATA, "", EXIT);
// Get the exception occurred during parsing.
thrown.expect(ParserException.class);
......@@ -54,13 +54,12 @@ public class ListenerValidationTest {
// Create test walker and assign test error to it.
TreeWalkListener testWalker = new TreeWalkListener();
ListenerValidation.checkStackIsNotEmpty(testWalker, ListenerErrorType.MISSING_HOLDER,
ParsableDataType.YANGBASE_DATA, "", ListenerErrorLocation.EXIT);
checkStackIsNotEmpty(testWalker, MISSING_HOLDER, YANGBASE_DATA, "", EXIT);
}
/**
* Checks if there is no exception in case parsable stack is not empty while validating
* for not empty scenario.
* Checks if there is no exception in case parsable stack is not empty while
* validating for not empty scenario.
*/
@Test
public void validateStackIsNotEmptyForNonEmptyStack() {
......@@ -72,8 +71,7 @@ public class ListenerValidationTest {
YangRevision tmpNode = new YangRevision();
testWalker.getParsedDataStack().push(tmpNode);
ListenerValidation.checkStackIsNotEmpty(testWalker, ListenerErrorType.MISSING_HOLDER,
ParsableDataType.YANGBASE_DATA, "", ListenerErrorLocation.EXIT);
checkStackIsNotEmpty(testWalker, MISSING_HOLDER, YANGBASE_DATA, "", EXIT);
}
/**
......@@ -83,9 +81,7 @@ public class ListenerValidationTest {
@Test
public void validateStackIsEmptyForNonEmptyStack() {
String expectedError = ListenerErrorMessageConstruction
.constructListenerErrorMessage(ListenerErrorType.MISSING_HOLDER, ParsableDataType.YANGBASE_DATA, "",
ListenerErrorLocation.EXIT);
String expectedError = constructListenerErrorMessage(MISSING_HOLDER, YANGBASE_DATA, "", EXIT);
// Get the exception occurred during parsing.
thrown.expect(ParserException.class);
......@@ -98,13 +94,12 @@ public class ListenerValidationTest {
YangRevision tmpNode = new YangRevision();
testWalker.getParsedDataStack().push(tmpNode);
ListenerValidation.checkStackIsEmpty(testWalker, ListenerErrorType.MISSING_HOLDER,
ParsableDataType.YANGBASE_DATA, "", ListenerErrorLocation.EXIT);
checkStackIsEmpty(testWalker, MISSING_HOLDER, YANGBASE_DATA, "", EXIT);
}
/**
* Checks if there is no exception in case parsable stack is empty while validating
* for empty scenario.
* Checks if there is no exception in case parsable stack is empty while
* validating for empty scenario.
*/
@Test
public void validateStackIsEmptyForEmptyStack() {
......@@ -112,7 +107,6 @@ public class ListenerValidationTest {
// Create test walker and assign test error to it.
TreeWalkListener testWalker = new TreeWalkListener();
ListenerValidation.checkStackIsEmpty(testWalker, ListenerErrorType.MISSING_HOLDER,
ParsableDataType.YANGBASE_DATA, "", ListenerErrorLocation.EXIT);
checkStackIsEmpty(testWalker, MISSING_HOLDER, YANGBASE_DATA, "", EXIT);
}
}
\ No newline at end of file
}
......