Separate parser and generator from plugin
Change-Id: I7db134fe882c73fc6fec730f6d6e44f49ada0422
diff --git a/plugin/pom.xml b/plugin/pom.xml
index 066cb15..28839f4 100644
--- a/plugin/pom.xml
+++ b/plugin/pom.xml
@@ -24,7 +24,7 @@
<version>1.9-SNAPSHOT</version>
</parent>
- <artifactId>onos-yang-maven-plugin</artifactId>
+ <artifactId>onos-yang-utils-plugin</artifactId>
<version>1.9-SNAPSHOT</version>
<packaging>maven-plugin</packaging>
@@ -35,6 +35,16 @@
<version>${project.version}</version>
</dependency>
<dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-yang-utils-generator</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-yang-utils-parser</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>3.3.9</version>
diff --git a/plugin/src/main/java/org/onosproject/yangutils/linker/YangLinker.java b/plugin/src/main/java/org/onosproject/yangutils/linker/YangLinker.java
deleted file mode 100644
index 5f029f2..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/linker/YangLinker.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-package org.onosproject.yangutils.linker;
-
-import java.util.Set;
-import org.onosproject.yangutils.datamodel.YangNode;
-
-/**
- * Abstraction of entity which provides linking service of YANG files.
- */
-public interface YangLinker {
-
- /**
- * Resolve the import and include dependencies for a given resolution
- * information.
- *
- * @param yangNodeSet set of all dependent YANG nodes
- */
- void resolveDependencies(Set<YangNode> yangNodeSet);
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/linker/YangLinkingPhase.java b/plugin/src/main/java/org/onosproject/yangutils/linker/YangLinkingPhase.java
deleted file mode 100644
index 23020df..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/linker/YangLinkingPhase.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.linker;
-
-/**
- * Represents the phase of YANG file reference linking.
- */
-public enum YangLinkingPhase {
-
- /**
- * Linking the reference within the files.
- */
- INTRA_FILE,
-
- /**
- * Linking the reference across the files.
- */
- INTER_FILE
-
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/linker/exceptions/LinkerException.java b/plugin/src/main/java/org/onosproject/yangutils/linker/exceptions/LinkerException.java
deleted file mode 100644
index 1a36c74..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/linker/exceptions/LinkerException.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.linker.exceptions;
-
-/**
- * Represents base class for exceptions in linker operations.
- */
-public class LinkerException extends RuntimeException {
-
- private static final long serialVersionUID = 20160211L;
- private transient int lineNumber;
- private transient int charPositionInLine;
- private transient String fileName;
-
- /**
- * Creates a new linker exception.
- */
- public LinkerException() {
- super();
- }
-
- /**
- * Creates a new linker exception with given message.
- *
- * @param message the detail of exception in string
- */
- public LinkerException(String message) {
- super(message);
- }
-
- /**
- * Creates a new linker exception from given message and cause.
- *
- * @param message the detail of exception in string
- * @param cause underlying cause of the error
- */
- public LinkerException(final String message, final Throwable cause) {
- super(message, cause);
- }
-
- /**
- * Creates a new linker exception from cause.
- *
- * @param cause underlying cause of the error
- */
- public LinkerException(final Throwable cause) {
- super(cause);
- }
-
- /**
- * Returns line number of the exception.
- *
- * @return line number of the exception
- */
- public int getLineNumber() {
- return this.lineNumber;
- }
-
- /**
- * Returns YANG file name of the exception.
- *
- * @return YANG file name of the exception
- */
- public String getFileName() {
- return this.fileName;
- }
-
- /**
- * Returns position of the exception.
- *
- * @return position of the exception
- */
- public int getCharPositionInLine() {
- return this.charPositionInLine;
- }
-
- /**
- * Sets line number of YANG file.
- *
- * @param line line number of YANG file
- */
- public void setLine(int line) {
- this.lineNumber = line;
- }
-
- /**
- * Sets position of exception.
- *
- * @param charPosition position of exception
- */
- public void setCharPosition(int charPosition) {
- this.charPositionInLine = charPosition;
- }
-
- /**
- * Sets file name in parser exception.
- *
- * @param fileName YANG file name
- */
- public void setFileName(String fileName) {
- this.fileName = fileName;
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/linker/exceptions/package-info.java b/plugin/src/main/java/org/onosproject/yangutils/linker/exceptions/package-info.java
deleted file mode 100644
index 42cf3a2..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/linker/exceptions/package-info.java
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-/**
- * Custom linker exceptions.
- */
-package org.onosproject.yangutils.linker.exceptions;
diff --git a/plugin/src/main/java/org/onosproject/yangutils/linker/impl/PrefixResolverType.java b/plugin/src/main/java/org/onosproject/yangutils/linker/impl/PrefixResolverType.java
deleted file mode 100644
index 469f8cb..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/linker/impl/PrefixResolverType.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.linker.impl;
-
-/**
- * Enum for prefix resolver type when augment has come in path.
- */
-enum PrefixResolverType {
-
- /**
- * When prefix changes from inter file to intra file.
- */
- INTER_TO_INTRA,
-
- /**
- * When prefix changes from intra file to inter file.
- */
- INTRA_TO_INTER,
-
- /**
- * When prefix changes from one inter file to other inter file.
- */
- INTER_TO_INTER,
-
- /**
- * When no prefix change occurs.
- */
- NO_PREFIX_CHANGE_FOR_INTRA,
-
- /**
- * When no prefix change occurs.
- */
- NO_PREFIX_CHANGE_FOR_INTER
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerManager.java b/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerManager.java
deleted file mode 100644
index daf035e..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerManager.java
+++ /dev/null
@@ -1,209 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-package org.onosproject.yangutils.linker.impl;
-
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Set;
-
-import org.onosproject.yangutils.datamodel.ResolvableType;
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.YangReferenceResolver;
-import org.onosproject.yangutils.datamodel.YangSubModule;
-import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
-import org.onosproject.yangutils.linker.YangLinker;
-import org.onosproject.yangutils.linker.exceptions.LinkerException;
-
-import static org.onosproject.yangutils.linker.impl.YangLinkerUtils.updateFilePriority;
-import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
-
-/**
- * Representation of entity which provides linking service of YANG files.
- */
-public class YangLinkerManager
- implements YangLinker {
-
- /*
- * Set of all the YANG nodes, corresponding to the YANG files parsed by
- * parser.
- */
- private Set<YangNode> yangNodeSet = new HashSet<>();
-
- /**
- * Returns set of YANG node.
- *
- * @return set of YANG node
- */
- public Set<YangNode> getYangNodeSet() {
- return yangNodeSet;
- }
-
- /**
- * Creates YANG nodes set.
- *
- * @param yangNodeSet YANG node information set
- */
- public void createYangNodeSet(Set<YangNode> yangNodeSet) {
- getYangNodeSet().addAll(yangNodeSet);
- }
-
- @Override
- public void resolveDependencies(Set<YangNode> yangNodeSet) {
-
- // Create YANG node set.
- createYangNodeSet(yangNodeSet);
-
- // Carry out linking of sub module with module.
- linkSubModulesToParentModule(yangNodeSet);
-
- // Add references to import list.
- addRefToYangFilesImportList(yangNodeSet);
-
- // Add reference to include list.
- addRefToYangFilesIncludeList(yangNodeSet);
-
- // Update the priority for all the files.
- updateFilePriority(yangNodeSet);
-
- // TODO check for circular import/include.
-
- // Carry out inter-file linking.
- processInterFileLinking(yangNodeSet);
- }
-
- /**
- * Resolves sub-module linking by linking sub module with parent module.
- *
- * @param yangNodeSet set of YANG files info
- * @throws LinkerException fails to link sub-module to parent module
- */
- public void linkSubModulesToParentModule(Set<YangNode> yangNodeSet)
- throws LinkerException {
- for (YangNode yangNode : yangNodeSet) {
- if (yangNode instanceof YangSubModule) {
- try {
- ((YangSubModule) yangNode).linkWithModule(getYangNodeSet());
- } catch (DataModelException e) {
- String errorInfo = "Error in file: " + yangNode.getName() + " in " +
- yangNode.getFileName() + " at " +
- "line: " + e.getLineNumber() + " at position: " + e.getCharPositionInLine() + NEW_LINE
- + e.getLocalizedMessage();
- throw new LinkerException(errorInfo);
- // TODO add file path in exception message in util manager.
- }
- }
- }
- }
-
- /**
- * Adds imported node information to the import list.
- *
- * @param yangNodeSet set of YANG files info
- * @throws LinkerException fails to find imported module
- */
- public void addRefToYangFilesImportList(Set<YangNode> yangNodeSet)
- throws LinkerException {
- for (YangNode yangNode : yangNodeSet) {
- if (yangNode instanceof YangReferenceResolver) {
- try {
- ((YangReferenceResolver) yangNode).addReferencesToImportList(getYangNodeSet());
- } catch (DataModelException e) {
- String errorInfo = "Error in file: " + yangNode.getName() + " in " +
- yangNode.getFileName() + " at " +
- "line: " + e.getLineNumber() + " at position: " + e.getCharPositionInLine() + NEW_LINE
- + e.getLocalizedMessage();
- throw new LinkerException(errorInfo);
- // TODO add file path in exception message in util manager.
- }
- }
- }
- }
-
- /**
- * Adds included node information to the include list.
- *
- * @param yangNodeSet set of YANG files info
- * @throws LinkerException fails to find included sub-module
- */
- public void addRefToYangFilesIncludeList(Set<YangNode> yangNodeSet)
- throws LinkerException {
- for (YangNode yangNode : yangNodeSet) {
- if (yangNode instanceof YangReferenceResolver) {
- try {
- ((YangReferenceResolver) yangNode).addReferencesToIncludeList(getYangNodeSet());
- } catch (DataModelException e) {
- String errorInfo = "Error in file: " + yangNode.getName() + " in " +
- yangNode.getFileName() + " at " +
- "line: " + e.getLineNumber() + " at position: " + e.getCharPositionInLine() + NEW_LINE
- + e.getLocalizedMessage();
- throw new LinkerException(errorInfo);
- // TODO add file path in exception message in util manager.
- }
- }
- }
- }
-
- /**
- * Processes inter file linking for type and uses.
- *
- * @param yangNodeSet set of YANG files info
- * @throws LinkerException a violation in linker execution
- */
- public void processInterFileLinking(Set<YangNode> yangNodeSet)
- throws LinkerException {
- List<YangNode> yangNodeSortedList = new LinkedList<>();
- yangNodeSortedList.addAll(yangNodeSet);
- Collections.sort(yangNodeSortedList);
- for (YangNode yangNode : yangNodeSortedList) {
- try {
- ((YangReferenceResolver) yangNode)
- .resolveInterFileLinking(ResolvableType.YANG_IF_FEATURE);
- ((YangReferenceResolver) yangNode)
- .resolveInterFileLinking(ResolvableType.YANG_USES);
- ((YangReferenceResolver) yangNode)
- .resolveInterFileLinking(ResolvableType.YANG_AUGMENT);
- ((YangReferenceResolver) yangNode)
- .resolveInterFileLinking(ResolvableType.YANG_DERIVED_DATA_TYPE);
- ((YangReferenceResolver) yangNode)
- .resolveInterFileLinking(ResolvableType.YANG_BASE);
- ((YangReferenceResolver) yangNode)
- .resolveInterFileLinking(ResolvableType.YANG_IDENTITYREF);
- ((YangReferenceResolver) yangNode)
- .resolveInterFileLinking(ResolvableType.YANG_LEAFREF);
- ((YangReferenceResolver) yangNode)
- .resolveInterFileLinking(ResolvableType.YANG_COMPILER_ANNOTATION);
- } catch (DataModelException e) {
- String errorInfo = "Error in file: " + yangNode.getName() + " in " +
- yangNode.getFileName() + " at " +
- "line: " + e.getLineNumber() + " at position: " + e.getCharPositionInLine() + NEW_LINE
- + e.getLocalizedMessage();
- throw new LinkerException(errorInfo);
- // TODO add file path in exception message in util manager.
- } catch (LinkerException e) {
- String errorInfo = "Error in file: " + yangNode.getName() + " in " +
- yangNode.getFileName() + " at " +
- "line: " + e.getLineNumber() + " at position: " + e.getCharPositionInLine() + NEW_LINE
- + e.getLocalizedMessage();
- throw new LinkerException(errorInfo);
- // TODO add file path in exception message in util manager.
- }
- }
- }
-
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerUtils.java b/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerUtils.java
deleted file mode 100644
index 507ebf3..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangLinkerUtils.java
+++ /dev/null
@@ -1,613 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.linker.impl;
-
-import org.onosproject.yangutils.datamodel.TraversalType;
-import org.onosproject.yangutils.datamodel.YangAtomicPath;
-import org.onosproject.yangutils.datamodel.YangAugment;
-import org.onosproject.yangutils.datamodel.YangAugmentableNode;
-import org.onosproject.yangutils.datamodel.YangBase;
-import org.onosproject.yangutils.datamodel.YangCase;
-import org.onosproject.yangutils.datamodel.YangChoice;
-import org.onosproject.yangutils.datamodel.YangGrouping;
-import org.onosproject.yangutils.datamodel.YangIdentityRef;
-import org.onosproject.yangutils.datamodel.YangIfFeature;
-import org.onosproject.yangutils.datamodel.YangImport;
-import org.onosproject.yangutils.datamodel.YangInclude;
-import org.onosproject.yangutils.datamodel.YangLeaf;
-import org.onosproject.yangutils.datamodel.YangLeafList;
-import org.onosproject.yangutils.datamodel.YangLeafRef;
-import org.onosproject.yangutils.datamodel.YangLeavesHolder;
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
-import org.onosproject.yangutils.datamodel.YangReferenceResolver;
-import org.onosproject.yangutils.datamodel.YangType;
-import org.onosproject.yangutils.datamodel.YangTypeDef;
-import org.onosproject.yangutils.datamodel.YangUses;
-import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
-import org.onosproject.yangutils.datamodel.utils.ResolvableStatus;
-import org.onosproject.yangutils.datamodel.utils.YangConstructType;
-import org.onosproject.yangutils.linker.exceptions.LinkerException;
-import org.onosproject.yangutils.translator.exception.TranslatorException;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-import java.util.regex.Pattern;
-
-import static org.onosproject.yangutils.datamodel.TraversalType.CHILD;
-import static org.onosproject.yangutils.datamodel.TraversalType.PARENT;
-import static org.onosproject.yangutils.datamodel.TraversalType.ROOT;
-import static org.onosproject.yangutils.datamodel.TraversalType.SIBILING;
-import static org.onosproject.yangutils.datamodel.exceptions.ErrorMessages.CASE;
-import static org.onosproject.yangutils.datamodel.exceptions.ErrorMessages.COLLISION_DETECTION;
-import static org.onosproject.yangutils.datamodel.exceptions.ErrorMessages.FAILED_TO_ADD_CASE;
-import static org.onosproject.yangutils.datamodel.exceptions.ErrorMessages.TARGET_NODE;
-import static org.onosproject.yangutils.datamodel.exceptions.ErrorMessages.TARGET_NODE_LEAF_INFO;
-import static org.onosproject.yangutils.datamodel.exceptions.ErrorMessages.getErrorMsg;
-import static org.onosproject.yangutils.datamodel.exceptions.ErrorMessages.getErrorMsgCollision;
-import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.addResolutionInfo;
-import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.getYangConstructType;
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.DERIVED;
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.IDENTITYREF;
-import static org.onosproject.yangutils.translator.tojava.YangDataModelFactory.getYangCaseNode;
-import static org.onosproject.yangutils.utils.UtilConstants.BASE_LINKER_ERROR;
-import static org.onosproject.yangutils.utils.UtilConstants.COLON;
-import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
-import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.FEATURE_LINKER_ERROR;
-import static org.onosproject.yangutils.utils.UtilConstants.GROUPING_LINKER_ERROR;
-import static org.onosproject.yangutils.utils.UtilConstants.IDENTITYREF_LINKER_ERROR;
-import static org.onosproject.yangutils.utils.UtilConstants.IS_INVALID;
-import static org.onosproject.yangutils.utils.UtilConstants.LEAFREF_ERROR;
-import static org.onosproject.yangutils.utils.UtilConstants.LEAFREF_LINKER_ERROR;
-import static org.onosproject.yangutils.utils.UtilConstants.TYPEDEF_LINKER_ERROR;
-
-/**
- * Represent utilities for YANG linker.
- */
-public final class YangLinkerUtils {
-
- private static final int IDENTIFIER_LENGTH = 64;
- private static final Pattern IDENTIFIER_PATTERN = Pattern.compile("[a-zA-Z_][a-zA-Z0-9_.-]*");
- private static final String XML = "xml";
-
- private YangLinkerUtils() {
- }
-
- /**
- * Detects collision between target nodes leaf/leaf-list or child node with augmented leaf/leaf-list or child node.
- *
- * @param targetNode target node
- * @param augment augment node
- */
- private static void detectCollision(YangNode targetNode, YangAugment augment) {
- YangNode targetNodesChild = targetNode.getChild();
- YangNode augmentsChild = augment.getChild();
- if (targetNode instanceof YangChoice) {
- addCaseNodeToChoiceTarget(augment);
- } else {
- detectCollisionInLeaveHolders(targetNode, augment);
- while (augmentsChild != null) {
- detectCollisionInChildNodes(targetNodesChild, augmentsChild);
- augmentsChild = augmentsChild.getNextSibling();
- }
- }
- }
-
- /*Detects collision between leaves/leaf-lists*/
- private static void detectCollisionInLeaveHolders(YangNode targetNode, YangAugment augment) {
- YangLeavesHolder targetNodesLeavesHolder = (YangLeavesHolder) targetNode;
- if (augment.getListOfLeaf() != null && augment.getListOfLeaf().isEmpty() &&
- targetNodesLeavesHolder.getListOfLeaf() != null) {
- for (YangLeaf leaf : augment.getListOfLeaf()) {
- for (YangLeaf targetLeaf : targetNodesLeavesHolder.getListOfLeaf()) {
- detectCollision(targetLeaf.getName(), leaf.getName(),
- leaf.getLineNumber(),
- leaf.getCharPosition(),
- leaf.getFileName(), TARGET_NODE_LEAF_INFO);
- }
- }
- }
- if (augment.getListOfLeafList() != null &&
- augment.getListOfLeafList().isEmpty() &&
- targetNodesLeavesHolder.getListOfLeafList() != null) {
- for (YangLeafList leafList : augment.getListOfLeafList()) {
- for (YangLeafList targetLeafList : targetNodesLeavesHolder.getListOfLeafList()) {
- detectCollision(targetLeafList.getName(), leafList.getName(),
- leafList.getLineNumber(),
- leafList.getCharPosition(),
- leafList.getFileName(), TARGET_NODE_LEAF_INFO);
- }
- }
- }
- }
-
-
- private static void detectCollision(String first, String second,
- int line, int position, String
- fileName, String type) {
- if (first.equals(second)) {
- throw new LinkerException(getErrorMsgCollision(
- COLLISION_DETECTION, second, line, position, type,
- fileName));
- }
- }
-
- /*Detects collision for child nodes.*/
- private static void detectCollisionInChildNodes(YangNode targetNodesChild,
- YangNode augmentsChild) {
- while (augmentsChild != null) {
- while (targetNodesChild != null) {
- if (targetNodesChild.getName().equals(augmentsChild.getName())) {
- detectCollision(targetNodesChild.getName(), augmentsChild.getName(),
- augmentsChild.getLineNumber(),
- augmentsChild.getCharPosition(),
- augmentsChild.getFileName(), TARGET_NODE);
- }
- targetNodesChild = targetNodesChild.getNextSibling();
- }
- augmentsChild = augmentsChild.getNextSibling();
- }
- }
-
- /**
- * Adds a case node in augment when augmenting a choice node.
- *
- * @param augment augment node
- */
- private static void addCaseNodeToChoiceTarget(YangAugment augment) {
- try {
- YangNode child = augment.getChild();
- List<YangNode> childNodes = new ArrayList<>();
- while (child != null) {
- childNodes.add(child);
- child = child.getNextSibling();
- }
- augment.setChild(null);
-
- for (YangNode node : childNodes) {
- YangCase javaCase = getYangCaseNode(JAVA_GENERATION);
- javaCase.setName(node.getName());
- augment.addChild(javaCase);
- node.setParent(javaCase);
- node.setNextSibling(null);
- node.setPreviousSibling(null);
- javaCase.addChild(node);
- }
- if (augment.getListOfLeaf() != null) {
- for (YangLeaf leaf : augment.getListOfLeaf()) {
- YangCase javaCase = getYangCaseNode(JAVA_GENERATION);
- javaCase.setName(leaf.getName());
- javaCase.addLeaf(leaf);
- augment.addChild(javaCase);
-
- }
- augment.getListOfLeaf().clear();
- }
- if (augment.getListOfLeafList() != null) {
- for (YangLeafList leafList : augment.getListOfLeafList()) {
- YangCase javaCase = getYangCaseNode(JAVA_GENERATION);
- javaCase.setName(leafList.getName());
- javaCase.addLeafList(leafList);
- augment.addChild(javaCase);
- }
- augment.getListOfLeafList().clear();
- }
-
- } catch (DataModelException e) {
- throw new TranslatorException(
- getErrorMsg(FAILED_TO_ADD_CASE, augment.getName(),
- augment.getLineNumber(), augment.getCharPosition(),
- augment.getFileName()));
- }
- }
-
- /**
- * Returns error messages.
- *
- * @param resolvable resolvable entity
- * @return error message
- */
- static String getErrorInfoForLinker(Object resolvable) {
- if (resolvable instanceof YangType) {
- return TYPEDEF_LINKER_ERROR;
- }
- if (resolvable instanceof YangUses) {
- return GROUPING_LINKER_ERROR;
- }
- if (resolvable instanceof YangIfFeature) {
- return FEATURE_LINKER_ERROR;
- }
- if (resolvable instanceof YangBase) {
- return BASE_LINKER_ERROR;
- }
- if (resolvable instanceof YangIdentityRef) {
- return IDENTITYREF_LINKER_ERROR;
- }
- return LEAFREF_LINKER_ERROR;
- }
-
- /**
- * Returns leafref's error message.
- *
- * @param leafref leaf ref
- * @return error message
- */
- static String getLeafRefErrorInfo(YangLeafRef leafref) {
- return getErrorMsg(
- LEAFREF_ERROR + leafref.getPath() + COMMA + IS_INVALID, EMPTY_STRING,
- leafref.getLineNumber(), leafref.getCharPosition(), leafref
- .getFileName());
- }
-
- //Detect collision between augment and choice children.
- private void detectCollisionForChoiceNode(YangNode choice, YangNode augment) {
- YangNode choiceChild = choice.getChild();
- YangNode augmentChild = augment.getChild();
-
- List<YangNode> choiceChildren = new ArrayList<>();
- List<YangNode> augmentChildren = new ArrayList<>();
- while (choiceChild != null) {
- choiceChildren.add(choiceChild);
- }
- while (augmentChild != null) {
- augmentChildren.add(augmentChild);
- }
-
- for (YangNode cChild : choiceChildren) {
- for (YangNode aChild : augmentChildren) {
- if (cChild.getName().equals(aChild.getName())) {
- ;
- throw new LinkerException(getErrorMsgCollision(
- COLLISION_DETECTION, cChild.getName(),
- cChild.getLineNumber(), cChild.getCharPosition(),
- CASE, cChild.getFileName()));
- }
- }
- }
- }
-
- /**
- * Detects collision between target nodes and its all leaf/leaf-list or child node with augmented leaf/leaf-list or
- * child node.
- *
- * @param targetNode target node
- * @param augment augment node
- */
- static void detectCollisionForAugmentedNode(YangNode targetNode, YangAugment augment) {
- // Detect collision for target node and augment node.
- detectCollision(targetNode, augment);
- List<YangAugment> yangAugmentedInfo = ((YangAugmentableNode) targetNode).getAugmentedInfoList();
- // Detect collision for target augment node and current augment node.
- for (YangAugment info : yangAugmentedInfo) {
- detectCollision(info, augment);
- }
- }
-
- /**
- * Returns list of path names that are needed from augment.
- *
- * @param augment instance of YANG augment
- * @param remainingAncestors ancestor count to move in augment path
- * @return list of path names needed in leafref
- */
- static List<String> getPathWithAugment(YangAugment augment, int remainingAncestors) {
- List<String> listOfPathName = new ArrayList<>();
- for (YangAtomicPath atomicPath : augment.getTargetNode()) {
- if (atomicPath.getNodeIdentifier().getPrefix() != null &&
- !atomicPath.getNodeIdentifier().getPrefix().equals(EMPTY_STRING)) {
- listOfPathName.add(atomicPath.getNodeIdentifier().getPrefix()
- + COLON + atomicPath.getNodeIdentifier().getName());
- } else {
- listOfPathName.add(atomicPath.getNodeIdentifier().getName());
- }
- }
- for (int countOfAncestor = 0; countOfAncestor < remainingAncestors; countOfAncestor++) {
- listOfPathName.remove(listOfPathName.size() - 1);
- }
- return listOfPathName;
- }
-
- /**
- * Skips the invalid nodes which cannot have data from YANG.
- *
- * @param currentParent current parent node reference
- * @param leafref instance of YANG leafref
- * @return parent node which can hold data
- * @throws LinkerException a violation of linker rules
- */
- static YangNode skipInvalidDataNodes(YangNode currentParent, YangLeafRef leafref)
- throws LinkerException {
- while (currentParent instanceof YangChoice || currentParent instanceof YangCase) {
- if (currentParent.getParent() == null) {
- LinkerException ex = new LinkerException(
- LEAFREF_ERROR + leafref.getPath() + IS_INVALID);
- ex.setCharPosition(leafref.getCharPosition());
- ex.setLine(leafref.getLineNumber());
- ex.setFileName(leafref.getFileName());
- throw ex;
- }
- currentParent = currentParent.getParent();
- }
- return currentParent;
- }
-
- /**
- * Checks and return valid node identifier.
- *
- * @param nodeIdentifierString string from yang file
- * @param yangConstruct yang construct for creating error message
- * @return valid node identifier
- */
- static YangNodeIdentifier getValidNodeIdentifier(String nodeIdentifierString,
- YangConstructType yangConstruct) {
- String[] tmpData = nodeIdentifierString.split(Pattern.quote(COLON));
- if (tmpData.length == 1) {
- YangNodeIdentifier nodeIdentifier = new YangNodeIdentifier();
- nodeIdentifier.setName(getValidIdentifier(tmpData[0], yangConstruct));
- return nodeIdentifier;
- } else if (tmpData.length == 2) {
- YangNodeIdentifier nodeIdentifier = new YangNodeIdentifier();
- nodeIdentifier.setPrefix(getValidIdentifier(tmpData[0], yangConstruct));
- nodeIdentifier.setName(getValidIdentifier(tmpData[1], yangConstruct));
- return nodeIdentifier;
- } else {
- throw new LinkerException("YANG file error : " +
- getYangConstructType(yangConstruct) + " name " + nodeIdentifierString +
- " is not valid.");
- }
- }
-
- /**
- * Validates identifier and returns concatenated string if string contains plus symbol.
- *
- * @param identifier string from yang file
- * @param yangConstruct yang construct for creating error message=
- * @return concatenated string after removing double quotes
- */
- public static String getValidIdentifier(String identifier, YangConstructType yangConstruct) {
-
- if (identifier.length() > IDENTIFIER_LENGTH) {
- throw new LinkerException("YANG file error : " +
- getYangConstructType(yangConstruct) + " name " + identifier + " is " +
- "greater than 64 characters.");
- } else if (!IDENTIFIER_PATTERN.matcher(identifier).matches()) {
- throw new LinkerException("YANG file error : " +
- getYangConstructType(yangConstruct) + " name " + identifier + " is not " +
- "valid.");
- } else if (identifier.toLowerCase().startsWith(XML)) {
- throw new LinkerException("YANG file error : " +
- getYangConstructType(yangConstruct) + " identifier " + identifier +
- " must not start with (('X'|'x') ('M'|'m') ('L'|'l')).");
- } else {
- return identifier;
- }
- }
-
- /**
- * Updates the priority for all the input files.
- *
- * @param yangNodeSet set of YANG files info
- */
- public static void updateFilePriority(Set<YangNode> yangNodeSet) {
- for (YangNode yangNode : yangNodeSet) {
- updateFilePriorityOfNode(yangNode);
- }
- }
-
- /**
- * Updates priority of the node.
- *
- * @param yangNode YANG node information
- */
- private static void updateFilePriorityOfNode(YangNode yangNode) {
- int curNodePriority = yangNode.getPriority();
- if (yangNode instanceof YangReferenceResolver) {
- List<YangImport> yangImportList = ((YangReferenceResolver) yangNode).getImportList();
- Iterator<YangImport> importInfoIterator = yangImportList.iterator();
- // Run through the imported list to update priority.
- while (importInfoIterator.hasNext()) {
- YangImport yangImport = importInfoIterator.next();
- YangNode importedNode = yangImport.getImportedNode();
- if (curNodePriority >= importedNode.getPriority()) {
- importedNode.setPriority(curNodePriority + 1);
- updateFilePriorityOfNode(importedNode);
- }
- }
-
- List<YangInclude> yangIncludeList = ((YangReferenceResolver) yangNode).getIncludeList();
- Iterator<YangInclude> includeInfoIterator = yangIncludeList.iterator();
- // Run through the imported list to update priority.
- while (includeInfoIterator.hasNext()) {
- YangInclude yangInclude = includeInfoIterator.next();
- YangNode includedNode = yangInclude.getIncludedNode();
- if (curNodePriority >= includedNode.getPriority()) {
- includedNode.setPriority(curNodePriority + 1);
- updateFilePriorityOfNode(includedNode);
- }
- }
- }
- }
-
- /**
- * Add the unresolved data under the root leve grouping to be resolved, since it will be used in interfile uses.
- *
- * @param referenceResolver module / sub-module
- */
- public static void resolveGroupingInDefinationScope(YangReferenceResolver referenceResolver) {
- YangNode potentialInterFileGrouping = ((YangNode) referenceResolver).getChild();
-
- while (potentialInterFileGrouping != null) {
- if (potentialInterFileGrouping instanceof YangGrouping) {
- addGroupingResolvableEntitiesToResolutionList((YangGrouping) potentialInterFileGrouping);
- }
-
- potentialInterFileGrouping = potentialInterFileGrouping.getNextSibling();
- }
- }
-
- /**
- * Add the interfile grouping resolvable entities to reesolution list.
- *
- * @param interFileGrouping interfile grouping
- */
- private static void addGroupingResolvableEntitiesToResolutionList(YangGrouping interFileGrouping) {
- YangNode curNode = interFileGrouping;
- TraversalType curTraversal = ROOT;
- addResolvableLeavesToResolutionList((YangLeavesHolder) curNode);
- curTraversal = CHILD;
- curNode = interFileGrouping.getChild();
- if (curNode == null) {
- return;
- }
- while (curNode != interFileGrouping) {
- if (curTraversal != PARENT) {
- if (curNode instanceof YangGrouping || curNode instanceof YangUses) {
- if (curNode.getNextSibling() != null) {
- curTraversal = SIBILING;
- curNode = curNode.getNextSibling();
- } else {
- curTraversal = PARENT;
- curNode = curNode.getParent();
- }
- continue;
- }
-
- if (curNode instanceof YangLeavesHolder) {
- addResolvableLeavesToResolutionList((YangLeavesHolder) curNode);
- } else if (curNode instanceof YangTypeDef) {
- List<YangType<?>> typeList = ((YangTypeDef) curNode).getTypeList();
- if (!typeList.isEmpty()) {
- YangType<?> type = typeList.get(0);
- if (type.getDataType() == DERIVED) {
- if (type.getResolvableStatus() != ResolvableStatus.RESOLVED) {
-
- type.setTypeForInterFileGroupingResolution(true);
-
- // Add resolution information to the list
- YangResolutionInfoImpl resolutionInfo =
- new YangResolutionInfoImpl<YangType>(type, curNode, type.getLineNumber(),
- type.getCharPosition());
- try {
- addResolutionInfo(resolutionInfo);
- } catch (DataModelException e) {
- String errorInfo = "Error in file: " + curNode.getName() + " in " +
- curNode.getFileName() + " at " +
- "line: " + e.getLineNumber() +
- " at position: " + e.getCharPositionInLine()
- + e.getLocalizedMessage();
- throw new LinkerException("Failed to add type info in grouping to resolution "
- + errorInfo);
- }
- }
- }
- }
- }
-
- }
- if (curTraversal != PARENT && curNode.getChild() != null) {
- curTraversal = CHILD;
- curNode = curNode.getChild();
- } else if (curNode.getNextSibling() != null) {
-
- curTraversal = SIBILING;
- curNode = curNode.getNextSibling();
- } else {
- curTraversal = PARENT;
- curNode = curNode.getParent();
- }
- }
- }
-
- /**
- * Add resolvable leaves type info to resolution list.
- *
- * @param leavesHolder leaves holder node
- */
- private static void addResolvableLeavesToResolutionList(YangLeavesHolder leavesHolder) {
- if (leavesHolder.getListOfLeaf() != null && !leavesHolder.getListOfLeaf().isEmpty()) {
- for (YangLeaf leaf : leavesHolder.getListOfLeaf()) {
- YangType type = leaf.getDataType();
- if (type.getDataType() == DERIVED) {
-
- type.setTypeForInterFileGroupingResolution(true);
-
- // Add resolution information to the list
- YangResolutionInfoImpl resolutionInfo =
- new YangResolutionInfoImpl<>(type, (YangNode) leavesHolder,
- type.getLineNumber(), type.getCharPosition());
- try {
- addResolutionInfo(resolutionInfo);
- } catch (DataModelException e) {
- throw new LinkerException("Failed to add leaf type info in grouping, to resolution ");
- }
- } else if (type.getDataType() == IDENTITYREF) {
- YangIdentityRef identityRef = (YangIdentityRef) type.getDataTypeExtendedInfo();
-
- identityRef.setIdentityForInterFileGroupingResolution(true);
-
- // Add resolution information to the list
- YangResolutionInfoImpl resolutionInfo =
- new YangResolutionInfoImpl<YangIdentityRef>(identityRef, (YangNode) leavesHolder,
- identityRef.getLineNumber(), identityRef.getCharPosition());
- try {
- addResolutionInfo(resolutionInfo);
- } catch (DataModelException e) {
- throw new LinkerException("Failed to add leaf identity ref info in grouping, to resolution ");
- }
- }
- }
- }
-
- if (leavesHolder.getListOfLeafList() != null && !leavesHolder.getListOfLeafList().isEmpty()) {
- for (YangLeafList leafList : leavesHolder.getListOfLeafList()) {
- YangType type = leafList.getDataType();
- if (type.getDataType() == DERIVED) {
-
- type.setTypeForInterFileGroupingResolution(true);
-
- // Add resolution information to the list
- YangResolutionInfoImpl resolutionInfo =
- new YangResolutionInfoImpl<YangType>(type, (YangNode) leavesHolder,
- type.getLineNumber(), type.getCharPosition());
- try {
- addResolutionInfo(resolutionInfo);
- } catch (DataModelException e) {
- throw new LinkerException("Failed to add leaf type info in grouping, to resolution ");
- }
- } else if (type.getDataType() == IDENTITYREF) {
- YangIdentityRef identityRef = (YangIdentityRef) type.getDataTypeExtendedInfo();
-
- identityRef.setIdentityForInterFileGroupingResolution(true);
- // Add resolution information to the list
- YangResolutionInfoImpl resolutionInfo =
- new YangResolutionInfoImpl<YangIdentityRef>(identityRef, (YangNode) leavesHolder,
- identityRef.getLineNumber(), identityRef.getCharPosition());
- try {
- addResolutionInfo(resolutionInfo);
- } catch (DataModelException e) {
- throw new LinkerException("Failed to add leaf identity ref info in grouping, to resolution ");
- }
- }
- }
- }
- }
-
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangResolutionInfoImpl.java b/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangResolutionInfoImpl.java
deleted file mode 100644
index 84de876..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangResolutionInfoImpl.java
+++ /dev/null
@@ -1,1629 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.linker.impl;
-
-import org.onosproject.yangutils.datamodel.DefaultLocationInfo;
-import org.onosproject.yangutils.datamodel.Resolvable;
-import org.onosproject.yangutils.datamodel.ResolvableType;
-import org.onosproject.yangutils.datamodel.RpcNotificationContainer;
-import org.onosproject.yangutils.datamodel.TraversalType;
-import org.onosproject.yangutils.datamodel.YangAtomicPath;
-import org.onosproject.yangutils.datamodel.YangAugment;
-import org.onosproject.yangutils.datamodel.YangAugmentableNode;
-import org.onosproject.yangutils.datamodel.YangBase;
-import org.onosproject.yangutils.datamodel.YangCompilerAnnotation;
-import org.onosproject.yangutils.datamodel.YangDerivedInfo;
-import org.onosproject.yangutils.datamodel.YangEntityToResolveInfoImpl;
-import org.onosproject.yangutils.datamodel.YangFeature;
-import org.onosproject.yangutils.datamodel.YangFeatureHolder;
-import org.onosproject.yangutils.datamodel.YangGrouping;
-import org.onosproject.yangutils.datamodel.YangIdentity;
-import org.onosproject.yangutils.datamodel.YangIdentityRef;
-import org.onosproject.yangutils.datamodel.YangIfFeature;
-import org.onosproject.yangutils.datamodel.YangImport;
-import org.onosproject.yangutils.datamodel.YangInclude;
-import org.onosproject.yangutils.datamodel.YangInput;
-import org.onosproject.yangutils.datamodel.YangLeaf;
-import org.onosproject.yangutils.datamodel.YangLeafList;
-import org.onosproject.yangutils.datamodel.YangLeafRef;
-import org.onosproject.yangutils.datamodel.YangList;
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
-import org.onosproject.yangutils.datamodel.YangReferenceResolver;
-import org.onosproject.yangutils.datamodel.YangRelativePath;
-import org.onosproject.yangutils.datamodel.YangResolutionInfo;
-import org.onosproject.yangutils.datamodel.YangType;
-import org.onosproject.yangutils.datamodel.YangTypeDef;
-import org.onosproject.yangutils.datamodel.YangUses;
-import org.onosproject.yangutils.datamodel.YangXPathResolver;
-import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
-import org.onosproject.yangutils.datamodel.utils.ResolvableStatus;
-import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
-import org.onosproject.yangutils.linker.exceptions.LinkerException;
-
-import java.io.Serializable;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Stack;
-
-import static org.onosproject.yangutils.datamodel.ResolvableType.YANG_IDENTITYREF;
-import static org.onosproject.yangutils.datamodel.ResolvableType.YANG_LEAFREF;
-import static org.onosproject.yangutils.datamodel.TraversalType.CHILD;
-import static org.onosproject.yangutils.datamodel.TraversalType.PARENT;
-import static org.onosproject.yangutils.datamodel.TraversalType.ROOT;
-import static org.onosproject.yangutils.datamodel.TraversalType.SIBILING;
-import static org.onosproject.yangutils.datamodel.YangPathArgType.ABSOLUTE_PATH;
-import static org.onosproject.yangutils.datamodel.YangPathArgType.RELATIVE_PATH;
-import static org.onosproject.yangutils.datamodel.exceptions.ErrorMessages.getErrorMsg;
-import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.addResolutionInfo;
-import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.INTER_FILE_LINKED;
-import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.INTRA_FILE_RESOLVED;
-import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.LINKED;
-import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.RESOLVED;
-import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.UNDEFINED;
-import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.UNRESOLVED;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.PATH_DATA;
-import static org.onosproject.yangutils.linker.impl.YangLinkerUtils.detectCollisionForAugmentedNode;
-import static org.onosproject.yangutils.linker.impl.YangLinkerUtils.getErrorInfoForLinker;
-import static org.onosproject.yangutils.linker.impl.YangLinkerUtils.getLeafRefErrorInfo;
-import static org.onosproject.yangutils.linker.impl.YangLinkerUtils.getPathWithAugment;
-import static org.onosproject.yangutils.linker.impl.YangLinkerUtils.getValidNodeIdentifier;
-import static org.onosproject.yangutils.linker.impl.YangLinkerUtils.skipInvalidDataNodes;
-import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.FAILED_TO_FIND_ANNOTATION;
-import static org.onosproject.yangutils.utils.UtilConstants.FAILED_TO_FIND_LEAD_INFO_HOLDER;
-import static org.onosproject.yangutils.utils.UtilConstants.FAILED_TO_LINK;
-import static org.onosproject.yangutils.utils.UtilConstants.IDENTITYREF;
-import static org.onosproject.yangutils.utils.UtilConstants.INVALID_ENTITY;
-import static org.onosproject.yangutils.utils.UtilConstants.INVALID_LINKER_STATE;
-import static org.onosproject.yangutils.utils.UtilConstants.INVALID_RESOLVED_ENTITY;
-import static org.onosproject.yangutils.utils.UtilConstants.INVALID_TARGET;
-import static org.onosproject.yangutils.utils.UtilConstants.INVALID_TREE;
-import static org.onosproject.yangutils.utils.UtilConstants.LEAFREF;
-import static org.onosproject.yangutils.utils.UtilConstants.LINKER_ERROR;
-import static org.onosproject.yangutils.utils.UtilConstants.SLASH_FOR_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.UNRESOLVABLE;
-
-/**
- * Represents implementation of resolution object which will be resolved by
- * linker.
- *
- * @param <T> type of resolution entity uses / type
- */
-public class YangResolutionInfoImpl<T> extends DefaultLocationInfo
- implements YangResolutionInfo<T>, Serializable {
-
- private static final long serialVersionUID = 806201658L;
-
- /**
- * Information about the entity that needs to be resolved.
- */
- private YangEntityToResolveInfoImpl<T> entityToResolveInfo;
-
- /**
- * Current module/sub-module reference, will be used in inter-file/
- * inter-jar scenario to get the import/include list.
- */
- private YangReferenceResolver curRefResolver;
-
- /**
- * Stack for type/uses is maintained for hierarchical references, this is
- * used during resolution.
- */
- private Stack<YangEntityToResolveInfoImpl<T>> partialResolvedStack;
-
- /**
- * It is private to ensure the overloaded method be invoked to create an
- * object.
- */
- @SuppressWarnings("unused")
- private YangResolutionInfoImpl() {
- }
-
- /**
- * Creates a resolution information object with all the inputs.
- *
- * @param dataNode current parsable data node
- * @param holderNode parent YANG node
- * @param lineNumber error line number
- * @param charPositionInLine error character position in line
- */
- public YangResolutionInfoImpl(T dataNode, YangNode holderNode, int lineNumber,
- int charPositionInLine) {
- entityToResolveInfo = new YangEntityToResolveInfoImpl<>();
- entityToResolveInfo.setEntityToResolve(dataNode);
- entityToResolveInfo.setHolderOfEntityToResolve(holderNode);
- setLineNumber(lineNumber);
- setCharPosition(charPositionInLine);
- partialResolvedStack = new Stack<>();
- }
-
- @Override
- public void resolveLinkingForResolutionInfo(YangReferenceResolver dataModelRootNode)
- throws DataModelException {
-
- curRefResolver = dataModelRootNode;
- /*
- * Current node to resolve, it can be a YANG type, YANG uses or YANG if-feature or
- * YANG leafref or YANG base or YANG identityref.
- */
- T entityToResolve = entityToResolveInfo.getEntityToResolve();
-
- // Check if linking is already done
- if (entityToResolve instanceof Resolvable) {
- Resolvable resolvable = (Resolvable) entityToResolve;
- if (resolvable.getResolvableStatus() == RESOLVED) {
- /*
- * entity is already resolved, so nothing to do
- */
- return;
- }
- } else {
- throw new DataModelException(LINKER_ERROR);
- }
- // Push the initial entity to resolve in stack.
- addInPartialResolvedStack(entityToResolveInfo);
- linkAndResolvePartialResolvedStack();
- addDerivedRefTypeToRefTypeResolutionList();
- }
-
- /**
- * Resolves linking with ancestors.
- *
- * @throws DataModelException a violation of data model rules
- */
- private void linkAndResolvePartialResolvedStack()
- throws DataModelException {
-
- while (!partialResolvedStack.isEmpty()) {
- /*
- * Current node to resolve, it can be a YANG type or YANG uses or
- * YANG if-feature or YANG leafref or YANG base or YANG identityref.
- */
- T entityToResolve = getCurEntityToResolveFromStack();
- if (!(entityToResolve instanceof Resolvable)) {
- throw new DataModelException(LINKER_ERROR);
- }
- // Check if linking is already done
- Resolvable resolvable = (Resolvable) entityToResolve;
- switch (resolvable.getResolvableStatus()) {
- case RESOLVED:
- /*
- * If the entity is already resolved in the stack, then pop
- * it and continue with the remaining stack elements to
- * resolve
- */
- partialResolvedStack.pop();
- break;
-
- case LINKED:
- /*
- * If the top of the stack is already linked then resolve
- * the references and pop the entity and continue with
- * remaining stack elements to resolve.
- */
- resolveTopOfStack();
- partialResolvedStack.pop();
- break;
-
- case INTRA_FILE_RESOLVED:
- /*
- * Pop the top of the stack.
- */
- partialResolvedStack.pop();
- break;
-
- case UNRESOLVED:
- linkTopOfStackReferenceUpdateStack();
-
- if (resolvable.getResolvableStatus() == UNRESOLVED) {
- // If current entity is still not resolved, then
- // linking/resolution has failed.
- DataModelException ex =
- new DataModelException
- (getErrorInfoForLinker(resolvable));
- ex.setLine(getLineNumber());
- ex.setCharPosition(getCharPosition());
- throw ex;
- }
- break;
-
- default:
- throw new DataModelException(INVALID_LINKER_STATE);
- }
- }
- }
-
- /**
- * Adds the leafref/identityref type to the type, which has derived type referring to
- * typedef with leafref/identityref type.
- */
- private void addDerivedRefTypeToRefTypeResolutionList()
- throws DataModelException {
-
- YangNode refNode = entityToResolveInfo.getHolderOfEntityToResolve();
- YangType yangType = getValidateResolvableType();
-
- if (yangType == null) {
- return;
- }
-
- YangDerivedInfo derivedInfo = (YangDerivedInfo) yangType
- .getDataTypeExtendedInfo();
-
- YangDataTypes dataType = derivedInfo.getEffectiveBuiltInType();
- // If the derived types referred type is not leafref/identityref return
- if (dataType != YangDataTypes.LEAFREF &&
- dataType != YangDataTypes.IDENTITYREF) {
- return;
- }
-
- T extendedInfo = (T) derivedInfo.getReferredTypeDef()
- .getTypeDefBaseType().getDataTypeExtendedInfo();
-
- while (extendedInfo instanceof YangDerivedInfo) {
- YangDerivedInfo derivedInfoFromTypedef = (YangDerivedInfo) extendedInfo;
- extendedInfo = (T) derivedInfoFromTypedef.getReferredTypeDef()
- .getTypeDefBaseType().getDataTypeExtendedInfo();
- }
-
- /*
- * Backup the derived types leafref/identityref info, delete all the info in current type,
- * but for resolution status as resolved. Copy the backed up leafref/identityref to types extended info,
- * create a leafref/identityref resolution info using the current resolution info and
- * add to leafref/identityref resolution list.
- */
- if (dataType == YangDataTypes.LEAFREF) {
- YangLeafRef leafRefInTypeDef = (YangLeafRef) extendedInfo;
- addRefTypeInfo(YangDataTypes.LEAFREF, LEAFREF, extendedInfo,
- yangType, refNode, YANG_LEAFREF);
- leafRefInTypeDef.setParentNodeOfLeafref(refNode);
- } else {
- addRefTypeInfo(YangDataTypes.IDENTITYREF, IDENTITYREF, extendedInfo,
- yangType, refNode, YANG_IDENTITYREF);
- }
- }
-
- //Validates entity to resolve for YANG type and returns type
- private YangType getValidateResolvableType() {
- YangNode refNode = entityToResolveInfo.getHolderOfEntityToResolve();
- T entity = entityToResolveInfo.getEntityToResolve();
- // If holder is typedef return.
- if (!(refNode instanceof YangTypeDef) && entity instanceof YangType) {
- YangType yangType = (YangType) entity;
-
- // If type is not resolved return.
- if (yangType.getResolvableStatus() == RESOLVED) {
- return (YangType) entity;
- }
- }
- return null;
- }
-
- /**
- * Adds referred type(leafref/identityref) info to resolution list.
- *
- * @param type data type
- * @param typeName type name
- * @param info extended info
- * @param yangType YANG type
- * @param refNode referred node
- * @param resType resolution type
- * @throws DataModelException when fails to do data model operations
- */
- private void addRefTypeInfo(YangDataTypes type, String typeName, T info,
- YangType yangType, YangNode refNode,
- ResolvableType resType) throws DataModelException {
- yangType.resetYangType();
- yangType.setResolvableStatus(RESOLVED);
- yangType.setDataType(type);
- yangType.setDataTypeName(typeName);
- yangType.setDataTypeExtendedInfo(info);
- ((Resolvable) info).setResolvableStatus(UNRESOLVED);
- YangResolutionInfoImpl resolutionInfoImpl
- = new YangResolutionInfoImpl<>(info, refNode,
- getLineNumber(), getCharPosition());
- curRefResolver.addToResolutionList(resolutionInfoImpl, resType);
- curRefResolver.resolveSelfFileLinking(resType);
- }
-
- /**
- * Resolves the current entity in the stack.
- */
- private void resolveTopOfStack()
- throws DataModelException {
- T entity = getCurEntityToResolveFromStack();
- List<T> entityToResolve = (List<T>) ((Resolvable) entity).resolve();
- if (entityToResolve != null && !entityToResolve.isEmpty()) {
- for (T anEntityToResolve : entityToResolve) {
- addUnresolvedEntitiesToResolutionList(anEntityToResolve);
- }
- }
- if (((Resolvable) entity).getResolvableStatus() != INTRA_FILE_RESOLVED &&
- ((Resolvable) entity).getResolvableStatus() != UNDEFINED) {
- // Sets the resolution status in inside the type/uses/if-feature/leafref.
- ((Resolvable) entity).setResolvableStatus(RESOLVED);
- }
- }
-
- /**
- * Adds the unresolved entities to the resolution list.
- *
- * @param entityToResolve entity to resolve
- * @throws DataModelException a violation of data model rules
- */
- private void addUnresolvedEntitiesToResolutionList(T entityToResolve)
- throws DataModelException {
- if (entityToResolve instanceof YangEntityToResolveInfoImpl) {
- YangEntityToResolveInfoImpl entityToResolveInfo
- = (YangEntityToResolveInfoImpl) entityToResolve;
- if (entityToResolveInfo.getEntityToResolve() instanceof YangLeafRef) {
- YangLeafRef leafref = (YangLeafRef) entityToResolveInfo
- .getEntityToResolve();
- YangNode parentNodeOfLeafref = entityToResolveInfo
- .getHolderOfEntityToResolve();
- leafref.setParentNodeOfLeafref(parentNodeOfLeafref);
- if (leafref.getResolvableStatus() == UNRESOLVED) {
- leafref.setResolvableStatus(INTRA_FILE_RESOLVED);
- }
- }
-
- // Add resolution information to the list.
- YangResolutionInfoImpl resolutionInfoImpl = new YangResolutionInfoImpl<>(
- entityToResolveInfo.getEntityToResolve(),
- entityToResolveInfo.getHolderOfEntityToResolve(),
- entityToResolveInfo.getLineNumber(),
- entityToResolveInfo.getCharPosition());
- addResolutionInfo(resolutionInfoImpl);
- }
- }
-
- /**
- * Resolves linking for a node child and siblings.
- *
- * @throws DataModelException data model error
- */
- private void linkTopOfStackReferenceUpdateStack()
- throws DataModelException {
- T entity = getCurEntityToResolveFromStack();
- if (entity instanceof YangLeafRef) {
- ((Resolvable) entity).setResolvableStatus(INTRA_FILE_RESOLVED);
- return;
- }
- /*
- * Check if self file reference is there, this will not check for the
- * scenario when prefix is not present and type/uses is present in
- * sub-module from include list.
- */
- if (!isCandidateForSelfFileReference()) {
- ((Resolvable) entity).setResolvableStatus(INTRA_FILE_RESOLVED);
- return;
- }
-
- /*
- * Try to resolve the top of the stack and update partial resolved stack
- * if there is recursive references
- */
- YangNode ancestorRefNode = partialResolvedStack.peek()
- .getHolderOfEntityToResolve();
-
- if (entity instanceof YangIfFeature) {
- resolveSelfFileLinkingForIfFeature(ancestorRefNode);
- return;
- }
- if (entity instanceof YangIdentityRef || entity instanceof YangBase) {
- resolveSelfFileLinkingForBaseAndIdentityref();
- return;
- }
- YangType type = null;
- if (entity instanceof YangType) {
- type = (YangType) entity;
- }
- /*
- * Traverse up in the ancestor tree to check if the referred node is
- * defined
- */
- while (ancestorRefNode != null) {
- /*
- * Check for the referred node defined in a ancestor scope
- */
- YangNode curRefNode = ancestorRefNode.getChild();
- if (isReferredNodeInSiblingListProcessed(curRefNode)) {
- return;
- }
- ancestorRefNode = ancestorRefNode.getParent();
- if (type != null && ancestorRefNode != null) {
- if (ancestorRefNode.getParent() == null) {
- type.setTypeNotResolvedTillRootNode(true);
- }
- }
- }
-
- /*
- * In case prefix is not present or it's self prefix it's a candidate for inter-file
- * resolution via include list.
- */
- if (getRefPrefix() == null ||
- getRefPrefix().contentEquals(curRefResolver.getPrefix())) {
- ((Resolvable) entity).setResolvableStatus(INTRA_FILE_RESOLVED);
- }
- }
-
- /**
- * Resolves self file linking for base/identityref.
- *
- * @throws DataModelException a violation of data model rules
- */
- private void resolveSelfFileLinkingForBaseAndIdentityref()
- throws DataModelException {
-
- boolean refIdentity = false;
- String nodeName = null;
- T entity = getCurEntityToResolveFromStack();
- if (entity instanceof YangIdentityRef) {
- nodeName = ((YangIdentityRef) entity).getName();
- } else if (entity instanceof YangBase) {
- nodeName = ((YangBase) entity).getBaseIdentifier().getName();
- }
- if (curRefResolver instanceof RpcNotificationContainer) {
- // Sends list of nodes for finding the target identity.
- refIdentity = isIdentityReferenceFound(nodeName, (YangNode) curRefResolver);
- }
- if (refIdentity) {
- return;
- }
-
- /*
- * In case prefix is not present or it's self prefix it's a candidate for inter-file
- * resolution via include list.
- */
- if (getRefPrefix() == null || getRefPrefix()
- .contentEquals(curRefResolver.getPrefix())) {
- ((Resolvable) entity).setResolvableStatus(INTRA_FILE_RESOLVED);
- }
- }
-
- /**
- * Resolves self file linking for if-feature.
- *
- * @param ancestorRefNode if-feature holder node
- * @throws DataModelException DataModelException a violation of data model
- * rules
- */
- private void resolveSelfFileLinkingForIfFeature(YangNode ancestorRefNode)
- throws DataModelException {
-
- YangFeatureHolder featureHolder = getFeatureHolder(ancestorRefNode);
- YangNode curRefNode = (YangNode) featureHolder;
- if (isReferredNode(curRefNode)) {
-
- // Adds reference link of entity to the node under resolution.
- addReferredEntityLink(curRefNode, LINKED);
-
- /*
- * resolve the reference and update the partial resolution stack
- * with any further recursive references
- */
- addUnresolvedRecursiveReferenceToStack(curRefNode);
- return;
- }
-
- /*
- * In case prefix is not present or it's self prefix it's a candidate for inter-file
- * resolution via include list.
- */
- if (getRefPrefix() == null || getRefPrefix()
- .contentEquals(curRefResolver.getPrefix())) {
- ((Resolvable) getCurEntityToResolveFromStack())
- .setResolvableStatus(INTRA_FILE_RESOLVED);
- }
- }
-
- /**
- * Returns the status of the referred identity found for base/identityref.
- *
- * @param nodeName the name of the base node
- * identifier/identityref node identifier
- * @param ancestorRefNode the parent node of base/identityref
- * @return status of referred base/identityref
- * @throws DataModelException a violation of data model rules
- */
- private boolean isIdentityReferenceFound(String nodeName, YangNode ancestorRefNode)
- throws DataModelException {
-
- // When child is not present return.
- if (ancestorRefNode.getChild() == null) {
- return false;
- }
-
- ancestorRefNode = ancestorRefNode.getChild();
-
- // Checks all the siblings under the node and returns the matched node.
- YangNode nodeFound = isReferredNodeInSiblingProcessedForIdentity(ancestorRefNode,
- nodeName);
-
- if (nodeFound != null) {
- // Adds reference link of entity to the node under resolution.
- addReferredEntityLink(nodeFound, LINKED);
-
- /*
- * resolve the reference and update the partial resolution stack with any further recursive references
- */
- addUnresolvedRecursiveReferenceToStack(nodeFound);
- return true;
- }
-
- return false;
- }
-
- /**
- * Adds the unresolved constructs to stack which has to be resolved for leafref.
- *
- * @param leavesInfo YANG leaf or leaf list which holds the type
- * @param ancestorRefNode holder of the YANG leaf or leaf list
- */
- private void addUnResolvedLeafRefTypeToStack(T leavesInfo, YangNode ancestorRefNode) {
-
- YangType refType;
- T extendedInfo;
- if (leavesInfo instanceof YangLeaf) {
- YangLeaf leaf = (YangLeaf) leavesInfo;
- refType = leaf.getDataType();
- } else {
- YangLeafList leafList = (YangLeafList) leavesInfo;
- refType = leafList.getDataType();
- }
- extendedInfo = (T) refType.getDataTypeExtendedInfo();
- addUnResolvedTypeDataToStack(refType, ancestorRefNode, extendedInfo);
- }
-
- //Adds unresolved type info to stack.
- private void addUnResolvedTypeDataToStack(YangType refType, YangNode
- ancestorRefNode, T extendedInfo) {
- YangEntityToResolveInfoImpl<YangLeafRef<?>> unResolvedLeafRef =
- new YangEntityToResolveInfoImpl<>();
- YangEntityToResolveInfoImpl<YangType<?>> unResolvedTypeDef =
- new YangEntityToResolveInfoImpl<>();
- if (refType.getDataType() == YangDataTypes.LEAFREF) {
- unResolvedLeafRef.setEntityToResolve((YangLeafRef<?>) extendedInfo);
- unResolvedLeafRef.setHolderOfEntityToResolve(ancestorRefNode);
- addInPartialResolvedStack((YangEntityToResolveInfoImpl<T>) unResolvedLeafRef);
- } else if (refType.getDataType() == YangDataTypes.DERIVED) {
- unResolvedTypeDef.setEntityToResolve(refType);
- unResolvedTypeDef.setHolderOfEntityToResolve(ancestorRefNode);
- addInPartialResolvedStack((YangEntityToResolveInfoImpl<T>) unResolvedTypeDef);
- }
- }
-
- /**
- * Returns feature holder(module/sub-module node) .
- *
- * @param ancestorRefNode if-feature holder node
- */
- private YangFeatureHolder getFeatureHolder(YangNode ancestorRefNode) {
- while (ancestorRefNode != null) {
- if (ancestorRefNode instanceof YangFeatureHolder) {
- return (YangFeatureHolder) ancestorRefNode;
- }
- ancestorRefNode = ancestorRefNode.getParent();
- }
- return null;
- }
-
- /**
- * Checks if the reference in self file or in external file.
- *
- * @return true if self file reference, false otherwise
- * @throws DataModelException a violation of data model rules
- */
- private boolean isCandidateForSelfFileReference()
- throws DataModelException {
- String prefix = getRefPrefix();
- return prefix == null || prefix.contentEquals(curRefResolver.getPrefix());
- }
-
- /**
- * Checks for the referred parent node for the base/identity.
- *
- * @param refNode potential referred node
- * @return the referred parent node of base/identity.
- * @throws DataModelException data model errors
- */
- private YangNode isReferredNodeInSiblingProcessedForIdentity(YangNode refNode,
- String refName)
- throws DataModelException {
-
- while (refNode != null) {
- if (refNode instanceof YangIdentity) {
- // Check if the potential referred node is the actual referred node
- if (isReferredNodeForIdentity(refNode, refName)) {
- return refNode;
- }
- }
- refNode = refNode.getNextSibling();
- }
- return null;
- }
-
- /**
- * Checks if the current reference node name and the name in the base/identityref base are equal.
- *
- * @param curRefNode the node where the reference is pointed
- * @param name name of the base in the base/identityref base
- * @return status of the match between the name
- * @throws DataModelException a violation of data model rules
- */
- private boolean isReferredNodeForIdentity(YangNode curRefNode, String name)
- throws DataModelException {
- T entity = getCurEntityToResolveFromStack();
- if (entity instanceof YangIdentityRef || entity instanceof YangBase) {
-
- //Check if name of node name matches with the current reference node.
- return curRefNode.getName().contentEquals(name);
- } else {
- throw new DataModelException(getErrorMsg(
- INVALID_ENTITY, curRefNode.getName(), curRefNode.getLineNumber(),
- curRefNode.getCharPosition(), curRefNode.getFileName()));
- }
- }
-
- /**
- * Checks for the referred node defined in a ancestor scope.
- *
- * @param refNode potential referred node
- * @return status of resolution and updating the partial resolved stack with
- * the any recursive references
- * @throws DataModelException a violation of data model rules
- */
- private boolean isReferredNodeInSiblingListProcessed(YangNode refNode)
- throws DataModelException {
- while (refNode != null) {
-
- // Check if the potential referred node is the actual referred node
- if (isReferredNode(refNode)) {
-
- // Adds reference link of entity to the node under resolution.
- addReferredEntityLink(refNode, LINKED);
-
- /*
- * resolve the reference and update the partial resolution stack
- * with any further recursive references
- */
- addUnresolvedRecursiveReferenceToStack(refNode);
-
- /*
- * return true, since the reference is linked and any recursive
- * unresolved references is added to the stack
- */
- return true;
- }
-
- refNode = refNode.getNextSibling();
- }
- return false;
- }
-
- /**
- * Checks if the potential referred node is the actual referred node.
- *
- * @param refNode typedef/grouping node
- * @return true if node is of resolve type otherwise false
- * @throws DataModelException a violation of data model rules
- */
- private boolean isReferredNode(YangNode refNode)
- throws DataModelException {
- T entity = getCurEntityToResolveFromStack();
- if (entity instanceof YangType) {
- if (refNode instanceof YangTypeDef) {
- return isNodeNameSameAsResolutionInfoName(refNode);
- }
- } else if (entity instanceof YangUses) {
- if (refNode instanceof YangGrouping) {
- return isNodeNameSameAsResolutionInfoName(refNode);
- }
- } else if (entity instanceof YangIfFeature) {
- if (refNode instanceof YangFeatureHolder) {
- return isNodeNameSameAsResolutionInfoName(refNode);
- }
- } else if (entity instanceof YangBase || entity instanceof YangIdentityRef) {
- if (refNode instanceof YangIdentity) {
- return isNodeNameSameAsResolutionInfoName(refNode);
- }
- } else {
- throw new DataModelException(getErrorMsg(
- LINKER_ERROR, refNode.getName(), refNode.getLineNumber(),
- refNode.getCharPosition(), refNode.getFileName()));
- }
- return false;
- }
-
- /**
- * Checks if node name is same as name in resolution info, i.e. name of
- * typedef/grouping is same as name of type/uses.
- *
- * @param node typedef/grouping node
- * @return true if node name is same as name in resolution info, otherwise
- * false
- * @throws DataModelException a violation of data model rules
- */
-
- private boolean isNodeNameSameAsResolutionInfoName(YangNode node)
- throws DataModelException {
- T entity = getCurEntityToResolveFromStack();
- if (entity instanceof YangType) {
- return node.getName().contentEquals(((YangType<?>) entity)
- .getDataTypeName());
- }
- if (entity instanceof YangUses) {
- return node.getName().contentEquals(((YangUses) entity).getName());
- }
- if (entity instanceof YangIfFeature) {
- return isFeatureDefinedInNode(node);
- }
- if (entity instanceof YangBase) {
- return node.getName().contentEquals(((
- YangBase) entity).getBaseIdentifier().getName());
- }
- if (entity instanceof YangIdentityRef) {
- return node.getName().contentEquals(((YangIdentityRef) entity).getName());
- }
- throw new DataModelException(getErrorMsg(
- INVALID_RESOLVED_ENTITY, node.getName(), node.getLineNumber(),
- node.getCharPosition(), node.getFileName()));
- }
-
- private boolean isFeatureDefinedInNode(YangNode node) {
- T entity = getCurEntityToResolveFromStack();
- YangNodeIdentifier ifFeature = ((YangIfFeature) entity).getName();
- List<YangFeature> featureList = ((YangFeatureHolder) node).getFeatureList();
- if (featureList != null && !featureList.isEmpty()) {
- Iterator<YangFeature> iterator = featureList.iterator();
- while (iterator.hasNext()) {
- YangFeature feature = iterator.next();
- if (ifFeature.getName().equals(feature.getName())) {
- ((YangIfFeature) entity).setReferredFeature(feature);
- ((YangIfFeature) entity).setReferredFeatureHolder(node);
- return true;
- }
- }
- }
- return false;
- }
-
- /**
- * Adds reference of grouping/typedef in uses/type.
- *
- * @param refNode grouping/typedef node being referred
- * @param linkedStatus linked status if success.
- * @throws DataModelException a violation of data model rules
- */
- private void addReferredEntityLink(YangNode refNode, ResolvableStatus linkedStatus)
- throws DataModelException {
- T entity = getCurEntityToResolveFromStack();
- if (entity instanceof YangType) {
- YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>) ((
- YangType<?>) entity).getDataTypeExtendedInfo();
- derivedInfo.setReferredTypeDef((YangTypeDef) refNode);
- } else if (entity instanceof YangUses) {
- ((YangUses) entity).setRefGroup((YangGrouping) refNode);
- } else if (entity instanceof YangBase) {
- ((YangBase) entity).setReferredIdentity((YangIdentity) refNode);
- } else if (entity instanceof YangIdentityRef) {
- ((YangIdentityRef) entity).setReferredIdentity((YangIdentity) refNode);
- } else if (!(entity instanceof YangIfFeature) &&
- !(entity instanceof YangLeafRef)) {
- throw new DataModelException(getErrorMsg(
- LINKER_ERROR, refNode.getName(), refNode.getLineNumber(),
- refNode.getCharPosition(), refNode.getFileName()));
- }
- // Sets the resolution status in inside the type/uses.
- ((Resolvable) entity).setResolvableStatus(linkedStatus);
- }
-
- /**
- * Checks if type/grouping has further reference to typedef/ unresolved
- * uses. Add it to the partial resolve stack and return the status of
- * addition to stack.
- *
- * @param refNode grouping/typedef node
- * @throws DataModelException a violation of data model rules
- */
- private void addUnresolvedRecursiveReferenceToStack(YangNode refNode)
- throws DataModelException {
- T entity = getCurEntityToResolveFromStack();
- if (entity instanceof YangType) {
-
- //Checks if typedef type is derived
- if (((YangTypeDef) refNode).getTypeDefBaseType()
- .getDataType() == YangDataTypes.DERIVED) {
- addEntityToStack((T) ((YangTypeDef) refNode).getTypeDefBaseType(),
- refNode);
- }
- } else if (entity instanceof YangUses) {
- /*
- * Search if the grouping has any un resolved uses child, if so
- * return true, else return false.
- */
- addUnResolvedUsesToStack(refNode);
- } else if (entity instanceof YangIfFeature) {
- addUnResolvedIfFeatureToStack(refNode);
- } else if (entity instanceof YangLeafRef) {
- // do nothing , referred node is already set
- throw new DataModelException(getErrorMsg(
- INVALID_RESOLVED_ENTITY, refNode.getName(), refNode.getLineNumber(),
- refNode.getCharPosition(), refNode.getFileName()));
- } else if (entity instanceof YangBase || entity instanceof YangIdentityRef) {
-
- //Search if the identity has any un resolved base, if so return true, else return false.
- addUnResolvedBaseToStack(refNode);
- } else {
- throw new DataModelException(getErrorMsg(
- LINKER_ERROR, refNode.getName(), refNode.getLineNumber(),
- refNode.getCharPosition(), refNode.getFileName()));
-
- }
- }
-
- /**
- * Returns if there is any unresolved uses in grouping.
- *
- * @param node grouping/typedef node
- */
- private void addUnResolvedUsesToStack(YangNode node) {
-
- //Search the grouping node's children for presence of uses node.
- TraversalType curTraversal = ROOT;
- YangNode curNode = node.getChild();
- while (curNode != null) {
- if (curNode.getName().equals(node.getName())) {
- // if we have traversed all the child nodes, then exit from loop
- return;
- }
-
- // if child nodes has uses, then add it to resolution stack
- if (curNode instanceof YangUses) {
- addEntityToStack((T) curNode, node);
- }
-
- // Traversing all the child nodes of grouping
- if (curTraversal != PARENT && curNode.getChild() != null) {
- curTraversal = CHILD;
- curNode = curNode.getChild();
- } else if (curNode.getNextSibling() != null) {
- curTraversal = SIBILING;
- curNode = curNode.getNextSibling();
- } else {
- curTraversal = PARENT;
- curNode = curNode.getParent();
- }
- }
- }
-
- /**
- * Returns if there is any unresolved if-feature in feature.
- *
- * @param node module/submodule node
- */
- private void addUnResolvedIfFeatureToStack(YangNode node) {
- YangFeature refFeature = ((YangIfFeature) getCurEntityToResolveFromStack())
- .getReferredFeature();
- List<YangIfFeature> ifFeatureList = refFeature.getIfFeatureList();
- if (ifFeatureList != null && !ifFeatureList.isEmpty()) {
- Iterator<YangIfFeature> ifFeatureIterator = ifFeatureList.iterator();
- while (ifFeatureIterator.hasNext()) {
- addEntityToStack((T) ifFeatureIterator.next(), node);
- }
- }
- }
-
- /**
- * Returns if there is any unresolved base in identity.
- *
- * @param node module/submodule node
- */
- private void addUnResolvedBaseToStack(YangNode node) {
-
- YangIdentity curNode = (YangIdentity) node;
- if (curNode.getBaseNode() != null) {
- if (curNode.getBaseNode().getResolvableStatus() != RESOLVED) {
- addEntityToStack((T) curNode.getBaseNode(), node);
- }
- }
- }
-
- private void addEntityToStack(T entity, YangNode holder) {
- YangEntityToResolveInfoImpl<T> unResolvedEntityInfo =
- new YangEntityToResolveInfoImpl<>();
- unResolvedEntityInfo.setEntityToResolve(entity);
- unResolvedEntityInfo.setHolderOfEntityToResolve(holder);
- addInPartialResolvedStack(unResolvedEntityInfo);
- }
-
- /**
- * Sets stack of YANG type with partially resolved YANG construct hierarchy.
- *
- * @param partialResolvedInfo partial resolved YANG construct stack
- */
- private void addInPartialResolvedStack(YangEntityToResolveInfoImpl<T> partialResolvedInfo) {
- partialResolvedStack.push(partialResolvedInfo);
- }
-
- /**
- * Retrieves the next entity in the stack that needs to be resolved. It is
- * assumed that the caller ensures that the stack is not empty.
- *
- * @return next entity in the stack that needs to be resolved
- */
- private T getCurEntityToResolveFromStack() {
- return partialResolvedStack.peek().getEntityToResolve();
- }
-
- @Override
- public YangEntityToResolveInfoImpl<T> getEntityToResolveInfo() {
- return entityToResolveInfo;
- }
-
- @Override
- public void linkInterFile(YangReferenceResolver dataModelRootNode)
- throws DataModelException {
-
- curRefResolver = dataModelRootNode;
-
- // Current node to resolve, it can be a YANG type or YANG uses.
- T entityToResolve = entityToResolveInfo.getEntityToResolve();
-
- // Check if linking is already done
- if (entityToResolve instanceof Resolvable) {
- Resolvable resolvable = (Resolvable) entityToResolve;
- if (resolvable.getResolvableStatus() == RESOLVED) {
- return;
- }
- } else {
- throw new DataModelException(UNRESOLVABLE);
- }
-
- if (entityToResolve instanceof YangXPathResolver &&
- !(entityToResolve instanceof YangLeafRef)) {
- //Process x-path linking.
- processXPathLinking(entityToResolve, dataModelRootNode);
-
- } else {
- // Push the initial entity to resolve in stack.
- addInPartialResolvedStack(entityToResolveInfo);
- // Inter file linking and resolution.
- linkInterFileAndResolve();
- addDerivedRefTypeToRefTypeResolutionList();
- }
- }
-
- /**
- * Process x-path linking for augment and leaf-ref.
- *
- * @param entityToResolve entity to resolve
- * @param root root node
- */
- private void processXPathLinking(T entityToResolve,
- YangReferenceResolver root) {
-
- YangXpathLinker<T> xPathLinker = new YangXpathLinker<T>();
-
- if (entityToResolve instanceof YangAugment) {
- YangNode targetNode;
- YangAugment augment = (YangAugment) entityToResolve;
- targetNode = xPathLinker
- .processAugmentXpathLinking(augment.getTargetNode(), (YangNode) root);
- if (targetNode != null) {
- if (targetNode instanceof YangAugmentableNode) {
- detectCollisionForAugmentedNode(targetNode, augment);
- ((YangAugmentableNode) targetNode).addAugmentation(augment);
- augment.setAugmentedNode(targetNode);
- setAugmentedFlagInAncestors(targetNode);
- Resolvable resolvable = (Resolvable) entityToResolve;
- resolvable.setResolvableStatus(RESOLVED);
- if (targetNode instanceof YangInput) {
- xPathLinker.addInModuleIfInput(augment, (YangNode) root);
- }
- } else {
- throw new LinkerException(getErrorMsg(
- INVALID_TARGET + targetNode.getNodeType(),
- augment.getName(), augment.getLineNumber(),
- augment.getCharPosition(), augment.getFileName()));
- }
- } else {
- throw new LinkerException(getErrorMsg(
- FAILED_TO_LINK, augment.getName(), augment
- .getLineNumber(), augment.getCharPosition(),
- augment.getFileName()));
- }
- } else if (entityToResolve instanceof YangCompilerAnnotation) {
- YangNode targetNode;
- YangCompilerAnnotation ca = (YangCompilerAnnotation) entityToResolve;
- targetNode = xPathLinker.processAugmentXpathLinking(ca.getAtomicPathList(),
- (YangNode) root);
- if (targetNode != null) {
- if (targetNode instanceof YangList) {
- ((YangList) targetNode).setCompilerAnnotation(
- (YangCompilerAnnotation) entityToResolve);
- Resolvable resolvable = (Resolvable) entityToResolve;
- resolvable.setResolvableStatus(RESOLVED);
- } else {
- throw new LinkerException(getErrorMsg(
- INVALID_TARGET + targetNode.getNodeType(), ca.getPath(),
- ca.getLineNumber(), ca.getCharPosition(), ca.getFileName()));
- }
- } else {
- throw new LinkerException(getErrorMsg(
- FAILED_TO_FIND_ANNOTATION, ca.getPath(), ca.getLineNumber(),
- ca.getCharPosition(), ca.getFileName()));
- }
- } else if (entityToResolve instanceof YangLeafRef) {
- YangLeafRef leafRef = (YangLeafRef) entityToResolve;
- Object target = xPathLinker.processLeafRefXpathLinking(
- leafRef.getAtomicPath(), (YangNode) root, leafRef);
- if (target != null) {
- YangLeaf leaf;
- YangLeafList leafList;
- leafRef.setReferredLeafOrLeafList(target);
- if (target instanceof YangLeaf) {
- leaf = (YangLeaf) target;
- leafRef.setResolvableStatus(INTER_FILE_LINKED);
- addUnResolvedLeafRefTypeToStack((T) leaf, entityToResolveInfo
- .getHolderOfEntityToResolve());
- } else {
- leafList = (YangLeafList) target;
- leafRef.setResolvableStatus(INTER_FILE_LINKED);
- addUnResolvedLeafRefTypeToStack(
- (T) leafList, entityToResolveInfo.getHolderOfEntityToResolve());
- }
- //TODO: add logic for leaf-ref for path predicates.
- } else {
- LinkerException ex = new LinkerException(
- FAILED_TO_FIND_LEAD_INFO_HOLDER + leafRef.getPath());
- ex.setCharPosition(leafRef.getCharPosition());
- ex.setLine(leafRef.getLineNumber());
- ex.setFileName(leafRef.getFileName());
- throw ex;
- }
- }
- }
-
- /**
- * Returns the referenced prefix of entity under resolution.
- *
- * @return referenced prefix of entity under resolution
- * @throws DataModelException a violation in data model rule
- */
- private String getRefPrefix()
- throws DataModelException {
- T entity = getCurEntityToResolveFromStack();
- if (entity instanceof YangType) {
- return ((YangType<?>) entity).getPrefix();
- }
- if (entity instanceof YangUses) {
- return ((YangUses) entity).getPrefix();
- }
- if (entity instanceof YangIfFeature) {
- return ((YangIfFeature) entity).getPrefix();
- }
- if (entity instanceof YangBase) {
- return ((YangBase) entity).getBaseIdentifier()
- .getPrefix();
- }
- if (entity instanceof YangIdentityRef) {
- return ((YangIdentityRef) entity).getPrefix();
- }
- throw new DataModelException(LINKER_ERROR);
- }
-
- /**
- * Performs inter file linking and resolution.
- *
- * @throws DataModelException a violation in data model rule
- */
- private void linkInterFileAndResolve()
- throws DataModelException {
-
- while (!partialResolvedStack.isEmpty()) {
-
- // Current node to resolve, it can be a YANG type or YANG uses.
- T entityToResolve = getCurEntityToResolveFromStack();
- // Check if linking is already done
- if (entityToResolve instanceof Resolvable) {
-
- Resolvable resolvable = (Resolvable) entityToResolve;
- switch (resolvable.getResolvableStatus()) {
- case RESOLVED:
- /*
- * If the entity is already resolved in the stack, then pop
- * it and continue with the remaining stack elements to
- * resolve
- */
- partialResolvedStack.pop();
- break;
-
- case INTER_FILE_LINKED:
- /*
- * If the top of the stack is already linked then resolve
- * the references and pop the entity and continue with
- * remaining stack elements to resolve
- */
- resolveTopOfStack();
- partialResolvedStack.pop();
- break;
-
- case INTRA_FILE_RESOLVED:
- /*
- * If the top of the stack is intra file resolved then check
- * if top of stack is linked, if not link it using
- * import/include list and push the linked referred entity
- * to the stack, otherwise only push it to the stack.
- */
- linkInterFileTopOfStackRefUpdateStack();
- break;
-
- case UNDEFINED:
- /*
- * In case of if-feature resolution, if referred "feature" is not
- * defined then the resolvable status will be undefined.
- */
- partialResolvedStack.pop();
- break;
-
- default:
- throw new DataModelException(INVALID_LINKER_STATE);
- }
- } else {
- throw new DataModelException(INVALID_RESOLVED_ENTITY);
- }
- }
- }
-
- /**
- * Links the top of the stack if it's inter-file and update stack.
- *
- * @throws DataModelException data model error
- */
- private void linkInterFileTopOfStackRefUpdateStack()
- throws DataModelException {
- T entity = getCurEntityToResolveFromStack();
- if (entity instanceof YangLeafRef) {
- // When leafref path comes with relative path, it will be converted to absolute path.
- setAbsolutePathFromRelativePathInLeafref(entity);
- processXPathLinking(entity, curRefResolver);
- return;
- }
- /*
- * Obtain the referred node of top of stack entity under resolution
- */
- T referredNode = getRefNode();
-
- /*
- * Check for null for scenario when it's not linked and inter-file
- * linking is required.
- */
- if (referredNode == null) {
-
- /*
- * Check if prefix is null or not, to identify whether to search in
- * import list or include list.
- */
- if (getRefPrefix() != null && !getRefPrefix()
- .contentEquals(curRefResolver.getPrefix())) {
- if (resolveWithImport()) {
- return;
- }
- } else {
- if (resolveWithInclude()) {
- return;
- }
- }
-
- if (entity instanceof YangIfFeature) {
- ((YangIfFeature) entity).setResolvableStatus(UNDEFINED);
- return;
- }
- // If current entity is still not resolved, then
- // linking/resolution has failed.
-
- DataModelException ex = new DataModelException(
- getErrorInfoForLinker(entity));
- ex.setLine(getLineNumber());
- ex.setCharPosition(getCharPosition());
- throw ex;
- } else {
- ((Resolvable) entity).setResolvableStatus(INTER_FILE_LINKED);
- addUnresolvedRecursiveReferenceToStack((YangNode) referredNode);
- }
- }
-
- /**
- * Sets the leafref with absolute path from the relative path.
- *
- * @param resolutionInfo information about the YANG construct which has to be resolved
- * @throws DataModelException a violation of data model rules
- */
- private void setAbsolutePathFromRelativePathInLeafref(T resolutionInfo)
- throws DataModelException {
- if (resolutionInfo instanceof YangLeafRef) {
-
- YangNode leafParent = ((YangLeafRef) resolutionInfo)
- .getParentNodeOfLeafref();
- YangLeafRef leafref = (YangLeafRef) resolutionInfo;
-
- // Checks if the leafref has relative path in it.
- if (leafref.getPathType() == RELATIVE_PATH) {
- YangRelativePath relativePath = leafref.getRelativePath();
- List<YangAtomicPath> absoluteInRelative = relativePath.getAtomicPathList();
- int ancestorCount = relativePath.getAncestorNodeCount();
-
- // Gets the root node from the ancestor count.
- T nodeOrAugmentList =
- getRootNodeWithAncestorCountForLeafref(ancestorCount, leafParent,
- leafref);
- if (nodeOrAugmentList instanceof YangNode) {
- StringBuilder name = new StringBuilder();
- StringBuilder prefix = new StringBuilder();
- YangNode rootNode = (YangNode) nodeOrAugmentList;
- // Forms a new absolute path from the relative path
- while (!(rootNode instanceof YangReferenceResolver)) {
- name.append(rootNode.getName());
- prefix.append(SLASH_FOR_STRING).append(name.reverse());
- name.delete(0, name.length());
- rootNode = rootNode.getParent();
- if (rootNode == null) {
- throw new DataModelException(INVALID_TREE);
- }
- }
- prefix.reverse();
- fillAbsolutePathValuesInLeafref(leafref, prefix.toString(),
- absoluteInRelative);
- } else {
- List<String> listOfAugment = (List<String>) nodeOrAugmentList;
- Iterator<String> listOfAugmentIterator = listOfAugment.listIterator();
- StringBuilder augment = new StringBuilder(EMPTY_STRING);
- while (listOfAugmentIterator.hasNext()) {
- augment.append(SLASH_FOR_STRING)
- .append(listOfAugmentIterator.next());
- }
- fillAbsolutePathValuesInLeafref(leafref, augment.toString(),
- absoluteInRelative);
- }
- }
- }
- }
-
- /**
- * Fills the absolute path values in the leafref from relative path.
- *
- * @param leafref instance of YANG leafref
- * @param path path name which has to be prefixed to relative path
- * @param relative atomic paths in relative
- * @throws DataModelException a violation of data model rules
- */
- private void fillAbsolutePathValuesInLeafref(YangLeafRef leafref, String path,
- List<YangAtomicPath> relative)
- throws DataModelException {
- leafref.setPathType(ABSOLUTE_PATH);
- String[] pathName = new String[0];
- if (path != null && !path.equals(EMPTY_STRING)) {
- pathName = path.split(SLASH_FOR_STRING);
- }
- List<YangAtomicPath> finalListForAbsolute = new LinkedList<>();
- for (String value : pathName) {
- if (value != null && !value.isEmpty() && !value.equals(EMPTY_STRING)) {
- YangNodeIdentifier nodeId = getValidNodeIdentifier(value, PATH_DATA);
- YangAtomicPath atomicPath = new YangAtomicPath();
- atomicPath.setNodeIdentifier(nodeId);
- finalListForAbsolute.add(atomicPath);
- }
- }
- if (relative != null && !relative.isEmpty()) {
- Iterator<YangAtomicPath> pathIt = relative.listIterator();
- while (pathIt.hasNext()) {
- YangAtomicPath yangAtomicPath = pathIt.next();
- finalListForAbsolute.add(yangAtomicPath);
- }
- leafref.setAtomicPath(finalListForAbsolute);
- } else {
- DataModelException ex = new DataModelException(getLeafRefErrorInfo(leafref));
- ex.setCharPosition(leafref.getCharPosition());
- ex.setLine(leafref.getLineNumber());
- ex.setFileName(leafref.getFileName());
- throw ex;
- }
- }
-
- /**
- * Returns the root parent with respect to the ancestor count from leafref.
- *
- * @param ancestorCount count of node where parent node can be reached
- * @param curParent current parent node
- * @param leafref instance of YANG leafref
- * @return node where the ancestor count stops or augment path name list
- * @throws DataModelException a violation of data model rules
- */
- private T getRootNodeWithAncestorCountForLeafref(
- int ancestorCount, YangNode curParent, YangLeafRef leafref)
- throws DataModelException {
-
- int curParentCount = 1;
- curParent = skipInvalidDataNodes(curParent, leafref);
- if (curParent instanceof YangAugment) {
- YangAugment augment = (YangAugment) curParent;
- List<String> valueInAugment = getPathWithAugment(augment,
- ancestorCount - curParentCount);
- return (T) valueInAugment;
- } else {
- while (curParentCount < ancestorCount) {
- YangNode currentSkippedParent = skipInvalidDataNodes(curParent, leafref);
- if (currentSkippedParent == curParent) {
- if (curParent.getParent() == null) {
- throw new DataModelException(getLeafRefErrorInfo(leafref));
- }
- curParent = curParent.getParent();
- } else {
- curParent = currentSkippedParent;
- continue;
- }
- curParentCount = curParentCount + 1;
- if (curParent instanceof YangAugment) {
- YangAugment augment = (YangAugment) curParent;
- List<String> valueInAugment = getPathWithAugment(
- augment, ancestorCount - curParentCount);
- return (T) valueInAugment;
- }
- }
- }
- return (T) curParent;
- }
-
- /**
- * Finds and resolves with include list.
- *
- * @return true if resolved, false otherwise
- * @throws DataModelException a violation in data model rule
- */
- private boolean resolveWithInclude() throws DataModelException {
- /*
- * Run through all the nodes in include list and search for referred
- * typedef/grouping at the root level.
- */
- for (YangInclude yangInclude : curRefResolver.getIncludeList()) {
- YangNode linkedNode = getLinkedNode(yangInclude.getIncludedNode());
- if (linkedNode != null) {
- return addUnResolvedRefToStack(linkedNode);
- }
- }
- // If referred node can't be found return false.
- return false;
- }
-
- /**
- * Finds and resolves with import list.
- *
- * @return true if resolved, false otherwise
- * @throws DataModelException a violation in data model rule
- */
- private boolean resolveWithImport() throws DataModelException {
-
- // Run through import list to find the referred typedef/grouping.
- for (YangImport yangImport : curRefResolver.getImportList()) {
- /*
- * Match the prefix attached to entity under resolution with the
- * imported/included module/sub-module's prefix. If found, search
- * for the referred typedef/grouping at the root level.
- */
- if (yangImport.getPrefixId().contentEquals(getRefPrefix())) {
- YangNode linkedNode = getLinkedNode(yangImport.getImportedNode());
- if (linkedNode != null) {
- return addUnResolvedRefToStack(linkedNode);
- }
- /*
- * If referred node can't be found at root level break for loop,
- * and return false.
- */
- break;
- }
- }
- // If referred node can't be found return false.
- return false;
- }
-
- //Add unresolved constructs to stack.
- private boolean addUnResolvedRefToStack(YangNode linkedNode)
- throws DataModelException {
- // Add the link to external entity.
- addReferredEntityLink(linkedNode, INTER_FILE_LINKED);
-
- // Add the type/uses of referred typedef/grouping to the stack.
- addUnresolvedRecursiveReferenceToStack(linkedNode);
- return true;
- }
-
- //Returns linked node from entity of stack.
- private YangNode getLinkedNode(YangNode node) {
- T entity = getCurEntityToResolveFromStack();
- if (entity instanceof YangType) {
- return findRefTypedef(node);
- }
- if (entity instanceof YangUses) {
- return findRefGrouping(node);
- }
- if (entity instanceof YangIfFeature) {
- return findRefFeature(node);
- }
- if (entity instanceof YangBase) {
- return findRefIdentity(node);
- }
- if (entity instanceof YangIdentityRef) {
- return findRefIdentityRef(node);
- }
- return null;
- }
-
- /**
- * Returns referred typedef/grouping node.
- *
- * @return referred typedef/grouping node
- * @throws DataModelException a violation in data model rule
- */
- private T getRefNode() throws DataModelException {
- T entity = getCurEntityToResolveFromStack();
- if (entity instanceof YangType) {
- YangDerivedInfo<?> derivedInfo = (YangDerivedInfo<?>)
- ((YangType<?>) entity).getDataTypeExtendedInfo();
- return (T) derivedInfo.getReferredTypeDef();
- }
- if (entity instanceof YangUses) {
- return (T) ((YangUses) entity).getRefGroup();
- }
- if (entity instanceof YangIfFeature) {
- return (T) ((YangIfFeature) entity).getReferredFeatureHolder();
- }
- if (entity instanceof YangLeafRef) {
- return (T) ((YangLeafRef) entity).getReferredLeafOrLeafList();
- }
- if (entity instanceof YangBase) {
- return (T) ((YangBase) entity).getReferredIdentity();
- }
- if (entity instanceof YangIdentityRef) {
- return (T) ((YangIdentityRef) entity).getReferredIdentity();
- }
- throw new DataModelException(LINKER_ERROR);
-
- }
-
- /**
- * Finds the referred grouping node at the root level of imported/included node.
- *
- * @param refNode module/sub-module node
- * @return referred grouping
- */
- private YangNode findRefGrouping(YangNode refNode) {
- YangNode tmpNode = refNode.getChild();
- while (tmpNode != null) {
- if (tmpNode instanceof YangGrouping) {
- if (tmpNode.getName()
- .equals(((YangUses) getCurEntityToResolveFromStack())
- .getName())) {
- return tmpNode;
- }
- }
- tmpNode = tmpNode.getNextSibling();
- }
- return null;
- }
-
- /**
- * Finds the referred feature node at the root level of imported/included node.
- *
- * @param refNode module/sub-module node
- * @return referred feature
- */
- private YangNode findRefFeature(YangNode refNode) {
- T entity = getCurEntityToResolveFromStack();
- YangNodeIdentifier ifFeature = ((YangIfFeature) entity).getName();
- List<YangFeature> featureList = ((YangFeatureHolder) refNode)
- .getFeatureList();
- if (featureList != null && !featureList.isEmpty()) {
- for (YangFeature feature : featureList) {
- if (ifFeature.getName().equals(feature.getName())) {
- ((YangIfFeature) entity).setReferredFeature(feature);
- return refNode;
- }
- }
- }
- return null;
- }
-
- /**
- * Finds the referred typedef node at the root level of imported/included node.
- *
- * @param refNode module/sub-module node
- * @return referred typedef
- */
- private YangNode findRefTypedef(YangNode refNode) {
- YangNode tmpNode = refNode.getChild();
- while (tmpNode != null) {
- if (tmpNode instanceof YangTypeDef) {
- if (tmpNode.getName()
- .equals(((YangType) getCurEntityToResolveFromStack())
- .getDataTypeName())) {
- return tmpNode;
- }
- }
- tmpNode = tmpNode.getNextSibling();
- }
- return null;
- }
-
- /**
- * Finds the referred identity node at the root level of imported/included node.
- *
- * @param refNode module/sub-module node
- * @return referred identity
- */
- private YangNode findRefIdentity(YangNode refNode) {
- YangNode tmpNode = refNode.getChild();
- while (tmpNode != null) {
- if (tmpNode instanceof YangIdentity) {
- if (tmpNode.getName()
- .equals(((YangBase) getCurEntityToResolveFromStack())
- .getBaseIdentifier().getName())) {
- return tmpNode;
- }
- }
- tmpNode = tmpNode.getNextSibling();
- }
- return null;
- }
-
- /**
- * Finds the referred identity node at the root level of imported/included node.
- *
- * @param refNode module/sub-module node
- * @return referred identity
- */
- private YangNode findRefIdentityRef(YangNode refNode) {
- YangNode tmpNode = refNode.getChild();
- while (tmpNode != null) {
- if (tmpNode instanceof YangIdentity) {
- if (tmpNode.getName()
- .equals(((YangIdentityRef) getCurEntityToResolveFromStack())
- .getBaseIdentity().getName())) {
- return tmpNode;
- }
- }
- tmpNode = tmpNode.getNextSibling();
- }
- return null;
- }
-
- /**
- * Sets descendant node augmented flag in ancestors.
- *
- * @param targetNode augmented YANG node
- */
- private void setAugmentedFlagInAncestors(YangNode targetNode) {
- targetNode = targetNode.getParent();
- while (targetNode != null) {
- targetNode.setDescendantNodeAugmented(true);
- targetNode = targetNode.getParent();
- }
- }
-}
\ No newline at end of file
diff --git a/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangXpathLinker.java b/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangXpathLinker.java
deleted file mode 100644
index 83f4a1a..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/linker/impl/YangXpathLinker.java
+++ /dev/null
@@ -1,743 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.linker.impl;
-
-import org.onosproject.yangutils.datamodel.LeafRefInvalidHolder;
-import org.onosproject.yangutils.datamodel.RpcNotificationContainer;
-import org.onosproject.yangutils.datamodel.YangAtomicPath;
-import org.onosproject.yangutils.datamodel.YangAugment;
-import org.onosproject.yangutils.datamodel.YangImport;
-import org.onosproject.yangutils.datamodel.YangInclude;
-import org.onosproject.yangutils.datamodel.YangInput;
-import org.onosproject.yangutils.datamodel.YangLeaf;
-import org.onosproject.yangutils.datamodel.YangLeafList;
-import org.onosproject.yangutils.datamodel.YangLeafRef;
-import org.onosproject.yangutils.datamodel.YangLeavesHolder;
-import org.onosproject.yangutils.datamodel.YangModule;
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
-import org.onosproject.yangutils.datamodel.YangOutput;
-import org.onosproject.yangutils.datamodel.YangSubModule;
-import org.onosproject.yangutils.datamodel.YangUses;
-import org.onosproject.yangutils.linker.exceptions.LinkerException;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Stack;
-
-import static org.onosproject.yangutils.datamodel.exceptions.ErrorMessages.getErrorMsg;
-import static org.onosproject.yangutils.linker.impl.PrefixResolverType.INTER_TO_INTER;
-import static org.onosproject.yangutils.linker.impl.PrefixResolverType.INTER_TO_INTRA;
-import static org.onosproject.yangutils.linker.impl.PrefixResolverType.INTRA_TO_INTER;
-import static org.onosproject.yangutils.linker.impl.PrefixResolverType.NO_PREFIX_CHANGE_FOR_INTER;
-import static org.onosproject.yangutils.linker.impl.PrefixResolverType.NO_PREFIX_CHANGE_FOR_INTRA;
-import static org.onosproject.yangutils.utils.UtilConstants.COLON;
-import static org.onosproject.yangutils.utils.UtilConstants.FAILED_TO_FIND_LEAD_INFO_HOLDER;
-import static org.onosproject.yangutils.utils.UtilConstants.INPUT;
-import static org.onosproject.yangutils.utils.UtilConstants.IS_INVALID;
-import static org.onosproject.yangutils.utils.UtilConstants.LEAFREF_ERROR;
-import static org.onosproject.yangutils.utils.UtilConstants.LEAF_HOLDER_ERROR;
-import static org.onosproject.yangutils.utils.UtilConstants.OUTPUT;
-import static org.onosproject.yangutils.utils.UtilConstants.SLASH_FOR_STRING;
-
-/**
- * Represents x-path linking.
- *
- * @param <T> x-path linking can be done for target node or for target leaf/leaf-list
- */
-public class YangXpathLinker<T> {
-
- private List<YangAtomicPath> absPaths;
- private YangNode rootNode;
- private Map<YangAtomicPath, PrefixResolverType> prefixResolverTypes;
- private String curPrefix;
- private String constructsParentsPrefix;
-
- /**
- * Creates an instance of x-path linker.
- */
- public YangXpathLinker() {
- absPaths = new ArrayList<>();
- }
-
- /**
- * Returns list of augment nodes.
- *
- * @param node root node
- * @return list of augment nodes
- */
- public List<YangAugment> getListOfYangAugment(YangNode node) {
- node = node.getChild();
- List<YangAugment> augments = new ArrayList<>();
- while (node != null) {
- if (node instanceof YangAugment) {
- augments.add((YangAugment) node);
- }
- node = node.getNextSibling();
- }
- return augments;
- }
-
- /**
- * Process absolute node path for target leaf.
- *
- * @param atomicPaths atomic path node list
- * @param root root node
- * @param leafref instance of YANG leafref
- * @return linked target node
- */
- T processLeafRefXpathLinking(List<YangAtomicPath> atomicPaths, YangNode root,
- YangLeafRef leafref) {
-
- YangNode targetNode;
- rootNode = root;
- prefixResolverTypes = new HashMap<>();
- parsePrefixResolverList(atomicPaths);
- YangAtomicPath leafRefPath = atomicPaths.get(atomicPaths.size() - 1);
-
- // When leaf-ref path contains only one absolute path.
- if (atomicPaths.size() == 1) {
- targetNode = getTargetNodeWhenPathSizeIsOne(atomicPaths);
- } else {
- for (YangAtomicPath atomicPath : atomicPaths) {
- if (atomicPath != leafRefPath) {
- absPaths.add(atomicPath);
- }
- }
- targetNode = parseData(root);
- }
- if (targetNode == null) {
- targetNode = searchInSubModule(root);
- }
-
- // Invalid path presence in the node list is checked.
- validateInvalidNodesInThePath(leafref);
-
- if (targetNode != null) {
- YangLeaf targetLeaf = searchReferredLeaf(targetNode, leafRefPath
- .getNodeIdentifier().getName());
- if (targetLeaf == null) {
- YangLeafList targetLeafList = searchReferredLeafList(
- targetNode, leafRefPath.getNodeIdentifier().getName());
- if (targetLeafList != null) {
- return (T) targetLeafList;
- } else {
- LinkerException ex = new LinkerException(
- FAILED_TO_FIND_LEAD_INFO_HOLDER + leafref.getPath());
- ex.setCharPosition(leafref.getCharPosition());
- ex.setLine(leafref.getLineNumber());
- ex.setFileName(leafref.getFileName());
- throw ex;
- }
- }
- return (T) targetLeaf;
- }
- return null;
- }
-
- /**
- * Validates the nodes in the path for any invalid node.
- *
- * @param leafref instance of YANG leafref
- */
- private void validateInvalidNodesInThePath(YangLeafRef leafref) {
- for (YangAtomicPath absolutePath : (Iterable<YangAtomicPath>) leafref
- .getAtomicPath()) {
- YangNode nodeInPath = absolutePath.getResolvedNode();
-
- if (nodeInPath instanceof LeafRefInvalidHolder) {
- LinkerException ex = new LinkerException(
- LEAFREF_ERROR + leafref.getPath() + IS_INVALID);
- ex.setCharPosition(leafref.getCharPosition());
- ex.setLine(leafref.getLineNumber());
- ex.setFileName(leafref.getFileName());
- throw ex;
- }
- }
- }
-
- /**
- * Returns target node when leaf-ref has only one absolute path in list.
- *
- * @param paths absolute paths
- * @return target node
- */
- private YangNode getTargetNodeWhenPathSizeIsOne(List<YangAtomicPath> paths) {
- if (paths.get(0).getNodeIdentifier().getPrefix() != null
- && !paths.get(0).getNodeIdentifier().getPrefix().equals
- (getRootsPrefix(rootNode))) {
- return getImportedNode(rootNode, paths.get(0).getNodeIdentifier());
- }
- return rootNode;
- }
-
- /**
- * Process absolute node path linking for augment.
- *
- * @param paths absolute path node list
- * @param root root node
- * @return linked target node
- */
- public YangNode processAugmentXpathLinking(List<YangAtomicPath> paths,
- YangNode root) {
- absPaths = paths;
- rootNode = root;
- prefixResolverTypes = new HashMap<>();
- parsePrefixResolverList(paths);
- YangNode targetNode = parseData(root);
- if (targetNode == null) {
- targetNode = searchInSubModule(root);
- }
- return targetNode;
- }
-
- /**
- * Searches for the referred leaf in target node.
- *
- * @param targetNode target node
- * @param leafName leaf name
- * @return target leaf
- */
- private YangLeaf searchReferredLeaf(YangNode targetNode, String leafName) {
- if (!(targetNode instanceof YangLeavesHolder)) {
- throw new LinkerException(getErrorMsg(
- LEAF_HOLDER_ERROR, targetNode.getName(), targetNode
- .getLineNumber(), targetNode.getCharPosition(),
- targetNode.getFileName()));
- }
- YangLeavesHolder holder = (YangLeavesHolder) targetNode;
- List<YangLeaf> leaves = holder.getListOfLeaf();
- if (leaves != null && !leaves.isEmpty()) {
- for (YangLeaf leaf : leaves) {
- if (leaf.getName().equals(leafName)) {
- return leaf;
- }
- }
- }
- return null;
- }
-
- /**
- * Searches for the referred leaf-list in target node.
- *
- * @param targetNode target node
- * @param name leaf-list name
- * @return target leaf-list
- */
- private YangLeafList searchReferredLeafList(YangNode targetNode, String name) {
- if (!(targetNode instanceof YangLeavesHolder)) {
- throw new LinkerException(getErrorMsg(
- LEAF_HOLDER_ERROR, targetNode.getName(), targetNode
- .getLineNumber(), targetNode.getCharPosition(),
- targetNode.getFileName()));
- }
- YangLeavesHolder holder = (YangLeavesHolder) targetNode;
- List<YangLeafList> leavesList = holder.getListOfLeafList();
- if (leavesList != null && !leavesList.isEmpty()) {
- for (YangLeafList leafList : leavesList) {
- if (leafList.getName().equals(name)) {
- return leafList;
- }
- }
- }
- return null;
- }
-
- /**
- * Process linking using for node identifier for inter/intra file.
- *
- * @param root root node
- * @return linked target node
- */
- private YangNode parseData(YangNode root) {
- String rootPrefix = getRootsPrefix(root);
- constructsParentsPrefix = rootPrefix;
- Iterator<YangAtomicPath> pathIterator = absPaths.iterator();
- YangAtomicPath path = pathIterator.next();
- if (path.getNodeIdentifier().getPrefix() != null
- && !path.getNodeIdentifier().getPrefix().equals(rootPrefix)) {
- return parsePath(getImportedNode(root, path.getNodeIdentifier()));
- } else {
- return parsePath(root);
- }
- }
-
- /**
- * Process linking of target node in root node.
- *
- * @param root root node
- * @return linked target node
- */
- private YangNode parsePath(YangNode root) {
-
- YangNode tempNode = root;
- Stack<YangNode> linkerStack = new Stack<>();
- Iterator<YangAtomicPath> pathIterator = absPaths.iterator();
- YangAtomicPath tempPath = pathIterator.next();
- YangNodeIdentifier nodeId;
- curPrefix = tempPath.getNodeIdentifier().getPrefix();
- int index = 0;
- YangNode tempAugment;
- do {
- nodeId = tempPath.getNodeIdentifier();
- if (tempPath.getNodeIdentifier().getPrefix() == null) {
- tempAugment = resolveIntraFileAugment(tempPath, root);
- } else {
- tempAugment = resolveInterFileAugment(tempPath, root);
- }
- if (tempAugment != null) {
- linkerStack.push(tempNode);
- tempNode = tempAugment;
- }
-
- tempNode = searchTargetNode(tempNode, nodeId);
-
- if (tempNode == null && !linkerStack.isEmpty()) {
- tempNode = linkerStack.peek();
- linkerStack.pop();
- tempNode = searchTargetNode(tempNode, nodeId);
- }
-
- if (tempNode != null) {
- tempPath.setResolvedNode(tempNode);
- }
-
- if (index == absPaths.size() - 1) {
- break;
- }
- tempPath = pathIterator.next();
- index++;
- } while (validate(tempNode, index));
- return tempNode;
- }
-
- /**
- * Resolves intra file augment linking.
- *
- * @param tempPath temporary absolute path
- * @param root root node
- * @return linked target node
- */
- private YangNode resolveIntraFileAugment(YangAtomicPath tempPath, YangNode root) {
- YangNode tempAugment;
- if (curPrefix != tempPath.getNodeIdentifier().getPrefix()) {
- root = getIncludedNode(rootNode, tempPath.getNodeIdentifier().getName());
- if (root == null) {
- root = getIncludedNode(rootNode, getAugmentNodeIdentifier(
- tempPath.getNodeIdentifier(), absPaths, rootNode));
- if (root == null) {
- root = rootNode;
- }
- }
- } else {
- if (curPrefix != null) {
- root = getImportedNode(root, tempPath.getNodeIdentifier());
- }
- }
-
- curPrefix = tempPath.getNodeIdentifier().getPrefix();
- tempAugment = getAugment(tempPath.getNodeIdentifier(), root, absPaths);
- if (tempAugment == null) {
- tempAugment = getAugment(tempPath.getNodeIdentifier(), rootNode,
- absPaths);
- }
- return tempAugment;
- }
-
- /**
- * Resolves inter file augment linking.
- *
- * @param tempPath temporary absolute path
- * @param root root node
- * @return linked target node
- */
- private YangNode resolveInterFileAugment(YangAtomicPath tempPath, YangNode root) {
-
- YangNode tempAugment;
- if (!tempPath.getNodeIdentifier().getPrefix().equals(curPrefix)) {
- curPrefix = tempPath.getNodeIdentifier().getPrefix();
- root = getImportedNode(rootNode, tempPath.getNodeIdentifier());
- }
- tempAugment = getAugment(tempPath.getNodeIdentifier(), root, absPaths);
- if (tempAugment == null) {
- return resolveInterToInterFileAugment(root);
- }
- return tempAugment;
- }
-
- /**
- * Resolves augment when prefix changed from inter file to inter file.
- * it may be possible that the prefix used in imported module is different the
- * given list of node identifiers.
- *
- * @param root root node
- * @return target node
- */
- private YangNode resolveInterToInterFileAugment(YangNode root) {
- List<YangAugment> augments = getListOfYangAugment(root);
- int index;
- List<YangAtomicPath> paths = new ArrayList<>();
- for (YangAugment augment : augments) {
- index = 0;
-
- for (YangAtomicPath path : augment.getTargetNode()) {
-
- if (!searchForAugmentInImportedNode(path.getNodeIdentifier(), index)) {
- paths.clear();
- break;
- }
- paths.add(path);
- index++;
- }
- if (!paths.isEmpty() && paths.size() == absPaths.size() - 1) {
- return augment;
- } else {
- paths.clear();
- }
- }
- return null;
- }
-
- /**
- * Searches for the augment node in imported module when prefix has changed from
- * inter file to inter file.
- *
- * @param nodeId node id
- * @param index index
- * @return true if found
- */
- private boolean searchForAugmentInImportedNode(YangNodeIdentifier nodeId,
- int index) {
- if (index == absPaths.size()) {
- return false;
- }
- YangNodeIdentifier tempNodeId = absPaths.get(index).getNodeIdentifier();
- return nodeId.getName().equals(tempNodeId.getName());
- }
-
- /**
- * Returns augment node.
- *
- * @param tempNodeId temporary absolute path id
- * @param root root node
- * @return linked target node
- */
- private YangNode getAugment(YangNodeIdentifier tempNodeId, YangNode root,
- List<YangAtomicPath> absPaths) {
- String augmentName = getAugmentNodeIdentifier(tempNodeId, absPaths, root);
- if (augmentName != null) {
- return searchAugmentNode(root, augmentName);
- }
- return null;
- }
-
- /**
- * Process linking using import list.
- *
- * @param root root node
- * @param nodeId node identifier
- * @return linked target node
- */
- private YangNode getImportedNode(YangNode root, YangNodeIdentifier nodeId) {
-
- List<YangImport> importList;
-
- if (root instanceof YangModule) {
- importList = ((YangModule) root).getImportList();
- } else {
- importList = ((YangSubModule) root).getImportList();
- }
-
- for (YangImport imported : importList) {
- if (imported.getPrefixId().equals(nodeId.getPrefix())) {
- return imported.getImportedNode();
- }
- }
-
- if (nodeId.getName() != null && nodeId.getPrefix()
- .equals(constructsParentsPrefix)) {
- return rootNode;
- }
- return root;
- }
-
- /**
- * Searches in sub-module node.
- *
- * @param root root node
- * @return target linked node
- */
- private YangNode searchInSubModule(YangNode root) {
- List<YangInclude> includeList;
- YangNode tempNode;
- if (root instanceof YangModule) {
- includeList = ((YangModule) root).getIncludeList();
- } else {
- includeList = ((YangSubModule) root).getIncludeList();
- }
-
- for (YangInclude included : includeList) {
- tempNode = parseData(included.getIncludedNode());
- if (tempNode != null) {
- return tempNode;
- }
- }
- return null;
- }
-
- /**
- * Process linking using include list.
- *
- * @param root root node
- * @param tempPathName temporary path node name
- * @return linked target node
- */
- private YangNode getIncludedNode(YangNode root, String tempPathName) {
-
- List<YangInclude> includeList;
-
- if (root instanceof YangModule) {
- includeList = ((YangModule) root).getIncludeList();
- } else {
- includeList = ((YangSubModule) root).getIncludeList();
- }
-
- for (YangInclude included : includeList) {
- if (verifyChildNode(included.getIncludedNode(), tempPathName)) {
- return included.getIncludedNode();
- }
- }
-
- return null;
- }
-
- /**
- * Verifies for child nodes in sub module.
- *
- * @param node submodule node
- * @param name name of child node
- * @return true if child node found
- */
- private boolean verifyChildNode(YangNode node, String name) {
- node = node.getChild();
- while (node != null) {
- if (node.getName().equals(name)) {
- return true;
- }
- node = node.getNextSibling();
- }
- return false;
- }
-
-
- /**
- * Returns augment's node id.
- *
- * @param nodeId node identifier
- * @param absPaths absolute paths
- * @param root root node
- * @return augment's node id
- */
- private String getAugmentNodeIdentifier(
- YangNodeIdentifier nodeId, List<YangAtomicPath> absPaths, YangNode root) {
- Iterator<YangAtomicPath> nodeIdIterator = absPaths.iterator();
- YangAtomicPath tempNodeId;
- StringBuilder builder = new StringBuilder();
- String name;
- String prefix;
- String id;
- PrefixResolverType type;
- while (nodeIdIterator.hasNext()) {
- tempNodeId = nodeIdIterator.next();
- name = tempNodeId.getNodeIdentifier().getName();
- prefix = tempNodeId.getNodeIdentifier().getPrefix();
- if (!tempNodeId.getNodeIdentifier().equals(nodeId)) {
- type = prefixResolverTypes.get(tempNodeId);
- switch (type) {
- case INTER_TO_INTRA:
- id = SLASH_FOR_STRING + name;
- break;
- case INTRA_TO_INTER:
- if (!getRootsPrefix(root).equals(prefix)) {
- id = SLASH_FOR_STRING + prefix + COLON + name;
- } else {
- id = SLASH_FOR_STRING + name;
- }
- break;
- case INTER_TO_INTER:
- id = SLASH_FOR_STRING + prefix + COLON + name;
- break;
- case NO_PREFIX_CHANGE_FOR_INTRA:
- id = SLASH_FOR_STRING + name;
- break;
- case NO_PREFIX_CHANGE_FOR_INTER:
- if (!getRootsPrefix(root).equals(prefix)) {
- id = SLASH_FOR_STRING + prefix + COLON + name;
- } else {
- id = SLASH_FOR_STRING + name;
- }
- break;
- default:
- id = SLASH_FOR_STRING + name;
- break;
- }
- builder.append(id);
- } else {
- return builder.toString();
- }
- }
- return null;
- }
-
- /**
- * Searches augment node in root node.
- *
- * @param node root node
- * @param tempNodeId node identifier
- * @return target augment node
- */
-
- private YangNode searchAugmentNode(YangNode node, String tempNodeId) {
- node = node.getChild();
- while (node != null) {
- if (node instanceof YangAugment) {
- if (node.getName().equals(tempNodeId)) {
- return node;
- }
- }
- node = node.getNextSibling();
- }
- return null;
- }
-
- /**
- * Validates for target node if target node found or not.
- *
- * @param tempNode temporary node
- * @param index current index of list
- * @return false if target node found
- */
- private boolean validate(YangNode tempNode, int index) {
-
- int size = absPaths.size();
- if (tempNode != null && index != size) {
- return true;
- } else if (tempNode != null) {
- return false;
- // this is your target node.
- } else if (index != size) {
- return true;
- // this could be in submodule as well.
- }
- return false;
- }
-
- /**
- * Searches target node in root node.
- *
- * @param node root node
- * @param curNodeId YANG node identifier
- * @return linked target node
- */
- private YangNode searchTargetNode(YangNode node, YangNodeIdentifier curNodeId) {
-
- if (node != null) {
- node = node.getChild();
- }
- while (node != null) {
- if (node instanceof YangInput) {
- if (curNodeId.getName().equalsIgnoreCase(INPUT)) {
- return node;
- }
- } else if (node instanceof YangOutput) {
- if (curNodeId.getName().equalsIgnoreCase(OUTPUT)) {
- return node;
- }
- }
- if (node.getName().equals(curNodeId.getName()) &&
- !(node instanceof YangUses)) {
- return node;
- }
- node = node.getNextSibling();
- }
- return null;
- }
-
- /**
- * Returns root prefix.
- *
- * @param root root node
- * @return root prefix
- */
- private String getRootsPrefix(YangNode root) {
- if (root instanceof YangModule) {
- return ((YangModule) root).getPrefix();
- } else {
- return ((YangSubModule) root).getPrefix();
- }
- }
-
- /**
- * Resolves prefix and provides prefix resolver list.
- *
- * @param absolutePaths absolute paths
- */
- private void parsePrefixResolverList(List<YangAtomicPath> absolutePaths) {
- Iterator<YangAtomicPath> pathIterator = absolutePaths.iterator();
- YangAtomicPath absPath;
- String prePrefix;
- String curPrefix = null;
- while (pathIterator.hasNext()) {
- prePrefix = curPrefix;
- absPath = pathIterator.next();
- curPrefix = absPath.getNodeIdentifier().getPrefix();
- if (curPrefix != null) {
- if (!curPrefix.equals(prePrefix)) {
- if (prePrefix != null) {
- prefixResolverTypes.put(absPath, INTER_TO_INTER);
- } else {
- prefixResolverTypes.put(absPath, INTRA_TO_INTER);
- }
- } else {
- prefixResolverTypes.put(absPath, NO_PREFIX_CHANGE_FOR_INTER);
- }
- } else {
- if (prePrefix != null) {
- prefixResolverTypes.put(absPath, INTER_TO_INTRA);
- } else {
- prefixResolverTypes.put(absPath, NO_PREFIX_CHANGE_FOR_INTRA);
- }
- }
- }
-
- }
-
- /**
- * Adds augment to rpc augmented list of input.
- *
- * @param augment augment
- * @param rootNode root node
- */
- void addInModuleIfInput(YangAugment augment,
- YangNode rootNode) {
- ((RpcNotificationContainer) rootNode).addToAugmentList(augment);
- }
-
-}
\ No newline at end of file
diff --git a/plugin/src/main/java/org/onosproject/yangutils/linker/impl/package-info.java b/plugin/src/main/java/org/onosproject/yangutils/linker/impl/package-info.java
deleted file mode 100644
index 1d38e5a..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/linker/impl/package-info.java
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * Provide intra/inter file and inter jar linking implementation.
- */
-package org.onosproject.yangutils.linker.impl;
diff --git a/plugin/src/main/java/org/onosproject/yangutils/linker/package-info.java b/plugin/src/main/java/org/onosproject/yangutils/linker/package-info.java
deleted file mode 100644
index 04ce9d6..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/linker/package-info.java
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * Provide inter jar and inter file linking abstract interface.
- */
-package org.onosproject.yangutils.linker;
\ No newline at end of file
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/YangUtilsParser.java b/plugin/src/main/java/org/onosproject/yangutils/parser/YangUtilsParser.java
deleted file mode 100644
index ba119f6..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/YangUtilsParser.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser;
-
-import java.io.IOException;
-
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-
-/**
- * Abstraction of entity which provides parser service of YANG files for yangutils-maven-plugin.
- */
-public interface YangUtilsParser {
-
- /**
- * Returns the data model node. It is an entry function to initiate the YANG file parsing.
- *
- * @param file input YANG file
- * @return YangNode root node of the data model tree
- * @throws ParserException when fails to get the data model
- * @throws IOException when there is an exception in IO operation
- */
- YangNode getDataModel(String file) throws IOException, ParserException;
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/antlrgencode/GeneratedYangListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/antlrgencode/GeneratedYangListener.java
deleted file mode 100644
index 72e7995..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/antlrgencode/GeneratedYangListener.java
+++ /dev/null
@@ -1,1940 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-// Generated from GeneratedYang.g4 by ANTLR 4.5
-
-package org.onosproject.yangutils.parser.antlrgencode;
-
-import org.antlr.v4.runtime.tree.ParseTreeListener;
-
-/**
- * Represents ANTLR interfaces to be implemented by listener to traverse the parse tree.
- */
-public interface GeneratedYangListener extends ParseTreeListener {
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule yangfile.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterYangfile(GeneratedYangParser.YangfileContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule yangfile.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitYangfile(GeneratedYangParser.YangfileContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule moduleStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterModuleStatement(GeneratedYangParser.ModuleStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule moduleStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitModuleStatement(GeneratedYangParser.ModuleStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule moduleBody.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterModuleBody(GeneratedYangParser.ModuleBodyContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule moduleBody.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitModuleBody(GeneratedYangParser.ModuleBodyContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule moduleHeaderStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterModuleHeaderStatement(GeneratedYangParser.ModuleHeaderStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule moduleHeaderStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitModuleHeaderStatement(GeneratedYangParser.ModuleHeaderStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule linkageStatements.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterLinkageStatements(GeneratedYangParser.LinkageStatementsContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule linkageStatements.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitLinkageStatements(GeneratedYangParser.LinkageStatementsContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule metaStatements.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterMetaStatements(GeneratedYangParser.MetaStatementsContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule metaStatements.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitMetaStatements(GeneratedYangParser.MetaStatementsContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule revisionStatements.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterRevisionStatements(GeneratedYangParser.RevisionStatementsContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule revisionStatements.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitRevisionStatements(GeneratedYangParser.RevisionStatementsContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule bodyStatements.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterBodyStatements(GeneratedYangParser.BodyStatementsContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule bodyStatements.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitBodyStatements(GeneratedYangParser.BodyStatementsContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule yangVersionStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterYangVersionStatement(GeneratedYangParser.YangVersionStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule yangVersionStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitYangVersionStatement(GeneratedYangParser.YangVersionStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule namespaceStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterNamespaceStatement(GeneratedYangParser.NamespaceStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule namespaceStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitNamespaceStatement(GeneratedYangParser.NamespaceStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule prefixStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterPrefixStatement(GeneratedYangParser.PrefixStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule prefixStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitPrefixStatement(GeneratedYangParser.PrefixStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule importStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterImportStatement(GeneratedYangParser.ImportStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule importStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitImportStatement(GeneratedYangParser.ImportStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule importStatementBody.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterImportStatementBody(GeneratedYangParser.ImportStatementBodyContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule importStatementBody.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitImportStatementBody(GeneratedYangParser.ImportStatementBodyContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule revisionDateStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterRevisionDateStatement(GeneratedYangParser.RevisionDateStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule revisionDateStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitRevisionDateStatement(GeneratedYangParser.RevisionDateStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule includeStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterIncludeStatement(GeneratedYangParser.IncludeStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule includeStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitIncludeStatement(GeneratedYangParser.IncludeStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule organizationStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterOrganizationStatement(GeneratedYangParser.OrganizationStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule organizationStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitOrganizationStatement(GeneratedYangParser.OrganizationStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule contactStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterContactStatement(GeneratedYangParser.ContactStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule contactStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitContactStatement(GeneratedYangParser.ContactStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule descriptionStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterDescriptionStatement(GeneratedYangParser.DescriptionStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule descriptionStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitDescriptionStatement(GeneratedYangParser.DescriptionStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule referenceStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterReferenceStatement(GeneratedYangParser.ReferenceStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule referenceStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitReferenceStatement(GeneratedYangParser.ReferenceStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule revisionStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterRevisionStatement(GeneratedYangParser.RevisionStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule revisionStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitRevisionStatement(GeneratedYangParser.RevisionStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule revisionStatementBody.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterRevisionStatementBody(GeneratedYangParser.RevisionStatementBodyContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule revisionStatementBody.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitRevisionStatementBody(GeneratedYangParser.RevisionStatementBodyContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule subModuleStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterSubModuleStatement(GeneratedYangParser.SubModuleStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule subModuleStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitSubModuleStatement(GeneratedYangParser.SubModuleStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule submoduleBody.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterSubmoduleBody(GeneratedYangParser.SubmoduleBodyContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule submoduleBody.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitSubmoduleBody(GeneratedYangParser.SubmoduleBodyContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule submoduleHeaderStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterSubmoduleHeaderStatement(GeneratedYangParser.SubmoduleHeaderStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule submoduleHeaderStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitSubmoduleHeaderStatement(GeneratedYangParser.SubmoduleHeaderStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule belongstoStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterBelongstoStatement(GeneratedYangParser.BelongstoStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule belongstoStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitBelongstoStatement(GeneratedYangParser.BelongstoStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule belongstoStatementBody.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterBelongstoStatementBody(GeneratedYangParser.BelongstoStatementBodyContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule belongstoStatementBody.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitBelongstoStatementBody(GeneratedYangParser.BelongstoStatementBodyContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule extensionStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterExtensionStatement(GeneratedYangParser.ExtensionStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule extensionStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitExtensionStatement(GeneratedYangParser.ExtensionStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule extensionBody.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterExtensionBody(GeneratedYangParser.ExtensionBodyContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule extensionBody.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitExtensionBody(GeneratedYangParser.ExtensionBodyContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule argumentStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterArgumentStatement(GeneratedYangParser.ArgumentStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule argumentStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitArgumentStatement(GeneratedYangParser.ArgumentStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule argumentBody.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterArgumentBody(GeneratedYangParser.ArgumentBodyContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule argumentBody.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitArgumentBody(GeneratedYangParser.ArgumentBodyContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule yinElementStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterYinElementStatement(GeneratedYangParser.YinElementStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule yinElementStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitYinElementStatement(GeneratedYangParser.YinElementStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule identityStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterIdentityStatement(GeneratedYangParser.IdentityStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule identityStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitIdentityStatement(GeneratedYangParser.IdentityStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule identityBody.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterIdentityBody(GeneratedYangParser.IdentityBodyContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule identityBody.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitIdentityBody(GeneratedYangParser.IdentityBodyContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule baseStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterBaseStatement(GeneratedYangParser.BaseStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule baseStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitBaseStatement(GeneratedYangParser.BaseStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule featureStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterFeatureStatement(GeneratedYangParser.FeatureStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule featureStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitFeatureStatement(GeneratedYangParser.FeatureStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule featureBody.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterFeatureBody(GeneratedYangParser.FeatureBodyContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule featureBody.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitFeatureBody(GeneratedYangParser.FeatureBodyContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule dataDefStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterDataDefStatement(GeneratedYangParser.DataDefStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule dataDefStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitDataDefStatement(GeneratedYangParser.DataDefStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule ifFeatureStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterIfFeatureStatement(GeneratedYangParser.IfFeatureStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule ifFeatureStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitIfFeatureStatement(GeneratedYangParser.IfFeatureStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule unitsStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterUnitsStatement(GeneratedYangParser.UnitsStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule unitsStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitUnitsStatement(GeneratedYangParser.UnitsStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule typedefStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterTypedefStatement(GeneratedYangParser.TypedefStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule typedefStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitTypedefStatement(GeneratedYangParser.TypedefStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule typeStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterTypeStatement(GeneratedYangParser.TypeStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule typeStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitTypeStatement(GeneratedYangParser.TypeStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule typeBodyStatements.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterTypeBodyStatements(GeneratedYangParser.TypeBodyStatementsContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule typeBodyStatements.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitTypeBodyStatements(GeneratedYangParser.TypeBodyStatementsContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule numericalRestrictions.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterDecimal64Specification(GeneratedYangParser.Decimal64SpecificationContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule numericalRestrictions.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitDecimal64Specification(GeneratedYangParser.Decimal64SpecificationContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule numericalRestrictions.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterFractionDigitStatement(GeneratedYangParser.FractionDigitStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule
- * numericalRestrictions.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitFractionDigitStatement(GeneratedYangParser.FractionDigitStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule
- * numericalRestrictions.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterNumericalRestrictions(GeneratedYangParser.NumericalRestrictionsContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule numericalRestrictions.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitNumericalRestrictions(GeneratedYangParser.NumericalRestrictionsContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule rangeStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterRangeStatement(GeneratedYangParser.RangeStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule rangeStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitRangeStatement(GeneratedYangParser.RangeStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule commonStatements.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterCommonStatements(GeneratedYangParser.CommonStatementsContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule commonStatements.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitCommonStatements(GeneratedYangParser.CommonStatementsContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule stringRestrictions.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterStringRestrictions(GeneratedYangParser.StringRestrictionsContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule stringRestrictions.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitStringRestrictions(GeneratedYangParser.StringRestrictionsContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule lengthStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterLengthStatement(GeneratedYangParser.LengthStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule lengthStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitLengthStatement(GeneratedYangParser.LengthStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule patternStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterPatternStatement(GeneratedYangParser.PatternStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule patternStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitPatternStatement(GeneratedYangParser.PatternStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule defaultStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterDefaultStatement(GeneratedYangParser.DefaultStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule defaultStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitDefaultStatement(GeneratedYangParser.DefaultStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule enumSpecification.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterEnumSpecification(GeneratedYangParser.EnumSpecificationContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule enumSpecification.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitEnumSpecification(GeneratedYangParser.EnumSpecificationContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule enumStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterEnumStatement(GeneratedYangParser.EnumStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule enumStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitEnumStatement(GeneratedYangParser.EnumStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule enumStatementBody.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterEnumStatementBody(GeneratedYangParser.EnumStatementBodyContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule enumStatementBody.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitEnumStatementBody(GeneratedYangParser.EnumStatementBodyContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule leafrefSpecification.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterLeafrefSpecification(GeneratedYangParser.LeafrefSpecificationContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule leafrefSpecification.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitLeafrefSpecification(GeneratedYangParser.LeafrefSpecificationContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule pathStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterPathStatement(GeneratedYangParser.PathStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule pathStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitPathStatement(GeneratedYangParser.PathStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule requireInstanceStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterRequireInstanceStatement(GeneratedYangParser.RequireInstanceStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule requireInstanceStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitRequireInstanceStatement(GeneratedYangParser.RequireInstanceStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule instanceIdentifierSpecification.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterInstanceIdentifierSpecification(
- GeneratedYangParser.InstanceIdentifierSpecificationContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule instanceIdentifierSpecification.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitInstanceIdentifierSpecification(GeneratedYangParser.InstanceIdentifierSpecificationContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule identityrefSpecification.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterIdentityrefSpecification(GeneratedYangParser.IdentityrefSpecificationContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule identityrefSpecification.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitIdentityrefSpecification(GeneratedYangParser.IdentityrefSpecificationContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule unionSpecification.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterUnionSpecification(GeneratedYangParser.UnionSpecificationContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule unionSpecification.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitUnionSpecification(GeneratedYangParser.UnionSpecificationContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule bitsSpecification.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterBitsSpecification(GeneratedYangParser.BitsSpecificationContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule bitsSpecification.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitBitsSpecification(GeneratedYangParser.BitsSpecificationContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule bitStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterBitStatement(GeneratedYangParser.BitStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule bitStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitBitStatement(GeneratedYangParser.BitStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule bitBodyStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterBitBodyStatement(GeneratedYangParser.BitBodyStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule bitBodyStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitBitBodyStatement(GeneratedYangParser.BitBodyStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule positionStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterPositionStatement(GeneratedYangParser.PositionStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule positionStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitPositionStatement(GeneratedYangParser.PositionStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule statusStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterStatusStatement(GeneratedYangParser.StatusStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule statusStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitStatusStatement(GeneratedYangParser.StatusStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule configStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterConfigStatement(GeneratedYangParser.ConfigStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule configStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitConfigStatement(GeneratedYangParser.ConfigStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule mandatoryStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterMandatoryStatement(GeneratedYangParser.MandatoryStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule mandatoryStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitMandatoryStatement(GeneratedYangParser.MandatoryStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule presenceStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterPresenceStatement(GeneratedYangParser.PresenceStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule presenceStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitPresenceStatement(GeneratedYangParser.PresenceStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule orderedByStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterOrderedByStatement(GeneratedYangParser.OrderedByStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule orderedByStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitOrderedByStatement(GeneratedYangParser.OrderedByStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule mustStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterMustStatement(GeneratedYangParser.MustStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule mustStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitMustStatement(GeneratedYangParser.MustStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule errorMessageStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterErrorMessageStatement(GeneratedYangParser.ErrorMessageStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule errorMessageStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitErrorMessageStatement(GeneratedYangParser.ErrorMessageStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule errorAppTagStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterErrorAppTagStatement(GeneratedYangParser.ErrorAppTagStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule errorAppTagStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitErrorAppTagStatement(GeneratedYangParser.ErrorAppTagStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule minElementsStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterMinElementsStatement(GeneratedYangParser.MinElementsStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule minElementsStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitMinElementsStatement(GeneratedYangParser.MinElementsStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule maxElementsStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterMaxElementsStatement(GeneratedYangParser.MaxElementsStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule maxElementsStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitMaxElementsStatement(GeneratedYangParser.MaxElementsStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule valueStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterValueStatement(GeneratedYangParser.ValueStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule valueStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitValueStatement(GeneratedYangParser.ValueStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule groupingStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterGroupingStatement(GeneratedYangParser.GroupingStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule groupingStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitGroupingStatement(GeneratedYangParser.GroupingStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule containerStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterContainerStatement(GeneratedYangParser.ContainerStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule containerStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitContainerStatement(GeneratedYangParser.ContainerStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule leafStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterLeafStatement(GeneratedYangParser.LeafStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule leafStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitLeafStatement(GeneratedYangParser.LeafStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule leafListStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterLeafListStatement(GeneratedYangParser.LeafListStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule leafListStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitLeafListStatement(GeneratedYangParser.LeafListStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule listStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterListStatement(GeneratedYangParser.ListStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule listStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitListStatement(GeneratedYangParser.ListStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule keyStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterKeyStatement(GeneratedYangParser.KeyStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule keyStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitKeyStatement(GeneratedYangParser.KeyStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule uniqueStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterUniqueStatement(GeneratedYangParser.UniqueStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule uniqueStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitUniqueStatement(GeneratedYangParser.UniqueStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule choiceStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterChoiceStatement(GeneratedYangParser.ChoiceStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule choiceStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitChoiceStatement(GeneratedYangParser.ChoiceStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule shortCaseStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterShortCaseStatement(GeneratedYangParser.ShortCaseStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule shortCaseStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitShortCaseStatement(GeneratedYangParser.ShortCaseStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule caseStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterCaseStatement(GeneratedYangParser.CaseStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule caseStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitCaseStatement(GeneratedYangParser.CaseStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule anyxmlStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterAnyxmlStatement(GeneratedYangParser.AnyxmlStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule anyxmlStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitAnyxmlStatement(GeneratedYangParser.AnyxmlStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule usesStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterUsesStatement(GeneratedYangParser.UsesStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule usesStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitUsesStatement(GeneratedYangParser.UsesStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule refineStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterRefineStatement(GeneratedYangParser.RefineStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule refineStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitRefineStatement(GeneratedYangParser.RefineStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule refineContainerStatements.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterRefineContainerStatements(GeneratedYangParser.RefineContainerStatementsContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule refineContainerStatements.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitRefineContainerStatements(GeneratedYangParser.RefineContainerStatementsContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule refineLeafStatements.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterRefineLeafStatements(GeneratedYangParser.RefineLeafStatementsContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule refineLeafStatements.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitRefineLeafStatements(GeneratedYangParser.RefineLeafStatementsContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule refineLeafListStatements.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterRefineLeafListStatements(GeneratedYangParser.RefineLeafListStatementsContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule refineLeafListStatements.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitRefineLeafListStatements(GeneratedYangParser.RefineLeafListStatementsContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule refineListStatements.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterRefineListStatements(GeneratedYangParser.RefineListStatementsContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule refineListStatements.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitRefineListStatements(GeneratedYangParser.RefineListStatementsContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule refineChoiceStatements.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterRefineChoiceStatements(GeneratedYangParser.RefineChoiceStatementsContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule refineChoiceStatements.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitRefineChoiceStatements(GeneratedYangParser.RefineChoiceStatementsContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule refineCaseStatements.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterRefineCaseStatements(GeneratedYangParser.RefineCaseStatementsContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule refineCaseStatements.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitRefineCaseStatements(GeneratedYangParser.RefineCaseStatementsContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule refineAnyxmlStatements.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterRefineAnyxmlStatements(GeneratedYangParser.RefineAnyxmlStatementsContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule refineAnyxmlStatements.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitRefineAnyxmlStatements(GeneratedYangParser.RefineAnyxmlStatementsContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule augmentStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterAugmentStatement(GeneratedYangParser.AugmentStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule augmentStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitAugmentStatement(GeneratedYangParser.AugmentStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule whenStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterWhenStatement(GeneratedYangParser.WhenStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule whenStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitWhenStatement(GeneratedYangParser.WhenStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule rpcStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterRpcStatement(GeneratedYangParser.RpcStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule rpcStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitRpcStatement(GeneratedYangParser.RpcStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule inputStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterInputStatement(GeneratedYangParser.InputStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule inputStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitInputStatement(GeneratedYangParser.InputStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule outputStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterOutputStatement(GeneratedYangParser.OutputStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule outputStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitOutputStatement(GeneratedYangParser.OutputStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule notificationStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterNotificationStatement(GeneratedYangParser.NotificationStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule notificationStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitNotificationStatement(GeneratedYangParser.NotificationStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule deviationStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterDeviationStatement(GeneratedYangParser.DeviationStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule deviationStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitDeviationStatement(GeneratedYangParser.DeviationStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule deviateNotSupportedStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterDeviateNotSupportedStatement(GeneratedYangParser.DeviateNotSupportedStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule deviateNotSupportedStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitDeviateNotSupportedStatement(GeneratedYangParser.DeviateNotSupportedStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule deviateAddStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterDeviateAddStatement(GeneratedYangParser.DeviateAddStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule deviateAddStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitDeviateAddStatement(GeneratedYangParser.DeviateAddStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule deviateDeleteStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterDeviateDeleteStatement(GeneratedYangParser.DeviateDeleteStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule deviateDeleteStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitDeviateDeleteStatement(GeneratedYangParser.DeviateDeleteStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule deviateReplaceStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterDeviateReplaceStatement(GeneratedYangParser.DeviateReplaceStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule deviateReplaceStatement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitDeviateReplaceStatement(GeneratedYangParser.DeviateReplaceStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule string.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterString(GeneratedYangParser.StringContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule string.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitString(GeneratedYangParser.StringContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule identifier.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterIdentifier(GeneratedYangParser.IdentifierContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule identifier.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitIdentifier(GeneratedYangParser.IdentifierContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule version.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterVersion(GeneratedYangParser.VersionContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule version.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitVersion(GeneratedYangParser.VersionContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule range.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterRange(GeneratedYangParser.RangeContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule range.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitRange(GeneratedYangParser.RangeContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule dateArgumentString.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterDateArgumentString(GeneratedYangParser.DateArgumentStringContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule dateArgumentString.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitDateArgumentString(GeneratedYangParser.DateArgumentStringContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule length.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterLength(GeneratedYangParser.LengthContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule length.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitLength(GeneratedYangParser.LengthContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule path.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterPath(GeneratedYangParser.PathContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule path.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitPath(GeneratedYangParser.PathContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule position.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterPosition(GeneratedYangParser.PositionContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule position.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitPosition(GeneratedYangParser.PositionContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule status.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterStatus(GeneratedYangParser.StatusContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule status.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitStatus(GeneratedYangParser.StatusContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule config.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterConfig(GeneratedYangParser.ConfigContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule config.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitConfig(GeneratedYangParser.ConfigContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule mandatory.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterMandatory(GeneratedYangParser.MandatoryContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule mandatory.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitMandatory(GeneratedYangParser.MandatoryContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule ordered-by.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterOrderedBy(GeneratedYangParser.OrderedByContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule ordered-by.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitOrderedBy(GeneratedYangParser.OrderedByContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule min elements value.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterMinValue(GeneratedYangParser.MinValueContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule min elements value.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitMinValue(GeneratedYangParser.MinValueContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule max elements value.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterMaxValue(GeneratedYangParser.MaxValueContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule max elements value.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitMaxValue(GeneratedYangParser.MaxValueContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule key.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterKey(GeneratedYangParser.KeyContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule key.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitKey(GeneratedYangParser.KeyContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule unique.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterUnique(GeneratedYangParser.UniqueContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule unique.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitUnique(GeneratedYangParser.UniqueContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule refine.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterRefine(GeneratedYangParser.RefineContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule refine.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitRefine(GeneratedYangParser.RefineContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule augment.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterAugment(GeneratedYangParser.AugmentContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule augment.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitAugment(GeneratedYangParser.AugmentContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule augment.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterFraction(GeneratedYangParser.FractionContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule augment.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitFraction(GeneratedYangParser.FractionContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule deviation.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterDeviation(GeneratedYangParser.DeviationContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule deviation.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitDeviation(GeneratedYangParser.DeviationContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule deviation.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterValue(GeneratedYangParser.ValueContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule deviation.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitValue(GeneratedYangParser.ValueContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule yang construct.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterYangConstruct(GeneratedYangParser.YangConstructContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule yang construct.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitYangConstruct(GeneratedYangParser.YangConstructContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule compiler annotation statement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterCompilerAnnotationStatement(GeneratedYangParser.CompilerAnnotationStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule compiler annotation statement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitCompilerAnnotationStatement(GeneratedYangParser.CompilerAnnotationStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule compiler annotation body statement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterCompilerAnnotationBodyStatement(GeneratedYangParser.CompilerAnnotationBodyStatementContext
- currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule compiler annotation body statement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitCompilerAnnotationBodyStatement(GeneratedYangParser.CompilerAnnotationBodyStatementContext
- currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule app data structure statement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterAppDataStructureStatement(GeneratedYangParser.AppDataStructureStatementContext
- currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule app data structure statement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitAppDataStructureStatement(GeneratedYangParser.AppDataStructureStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule app data structure.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterAppDataStructure(GeneratedYangParser.AppDataStructureContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule app data strcuture.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitAppDataStructure(GeneratedYangParser.AppDataStructureContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule app extended statement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterAppExtendedStatement(GeneratedYangParser.AppExtendedStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule app extended statement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitAppExtendedStatement(GeneratedYangParser.AppExtendedStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule extended name.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterExtendedName(GeneratedYangParser.ExtendedNameContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule extended name.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitExtendedName(GeneratedYangParser.ExtendedNameContext currentContext);
-
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule
- * data structure key statement.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterDataStructureKeyStatement(GeneratedYangParser.DataStructureKeyStatementContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar rule
- * data structure key statement.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitDataStructureKeyStatement(GeneratedYangParser.DataStructureKeyStatementContext currentContext);
-
- /**
- * Enters a parse tree produced by GeneratedYangParser for grammar rule require instance.
- *
- * @param currentContext current context in the parsed tree
- */
- void enterRequireInstance(GeneratedYangParser.RequireInstanceContext currentContext);
-
- /**
- * Exits a parse tree produced by GeneratedYangParser for grammar require instance.
- *
- * @param currentContext current context in the parsed tree
- */
- void exitRequireInstance(GeneratedYangParser.RequireInstanceContext currentContext);
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/antlrgencode/package-info.java b/plugin/src/main/java/org/onosproject/yangutils/parser/antlrgencode/package-info.java
deleted file mode 100644
index 747974e..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/antlrgencode/package-info.java
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-/**
- * ANTLR interfaces to be implemented by listener.
- */
-package org.onosproject.yangutils.parser.antlrgencode;
\ No newline at end of file
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/exceptions/ParserException.java b/plugin/src/main/java/org/onosproject/yangutils/parser/exceptions/ParserException.java
deleted file mode 100644
index 8edff52..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/exceptions/ParserException.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.exceptions;
-
-/**
- * Represents base class for exceptions in parser operations.
- */
-public class ParserException extends RuntimeException {
-
- private static final long serialVersionUID = 20160211L;
- private transient int lineNumber;
- private transient int charPositionInLine;
- private transient String fileName;
-
- /**
- * Creates a new parser exception.
- */
- public ParserException() {
- super();
- }
-
- /**
- * Creates a new parser exception with given message.
- *
- * @param message the detail of exception in string
- */
- public ParserException(String message) {
- super(message);
- }
-
- /**
- * Creates a new parser exception from given message and cause.
- *
- * @param message the detail of exception in string
- * @param cause underlying cause of the error
- */
- public ParserException(final String message, final Throwable cause) {
- super(message, cause);
- }
-
- /**
- * Creates a new parser exception from cause.
- *
- * @param cause underlying cause of the error
- */
- public ParserException(final Throwable cause) {
- super(cause);
- }
-
- /**
- * Returns line number of the exception.
- *
- * @return line number of the exception
- */
- public int getLineNumber() {
- return this.lineNumber;
- }
-
- /**
- * Returns YANG file name of the exception.
- *
- * @return YANG file name of the exception
- */
- public String getFileName() {
- return this.fileName;
- }
-
- /**
- * Returns position of the exception.
- *
- * @return position of the exception
- */
- public int getCharPositionInLine() {
- return this.charPositionInLine;
- }
-
- /**
- * Sets line number of YANG file.
- *
- * @param line line number of YANG file
- */
- public void setLine(int line) {
- this.lineNumber = line;
- }
-
- /**
- * Sets position of exception.
- *
- * @param charPosition position of exception
- */
- public void setCharPosition(int charPosition) {
- this.charPositionInLine = charPosition;
- }
-
- /**
- * Sets file name in parser exception.
- *
- * @param fileName YANG file name
- */
- public void setFileName(String fileName) {
- this.fileName = fileName;
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/exceptions/package-info.java b/plugin/src/main/java/org/onosproject/yangutils/parser/exceptions/package-info.java
deleted file mode 100644
index ec36b0d..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/exceptions/package-info.java
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-/**
- * Custom parser exceptions.
- */
-package org.onosproject.yangutils.parser.exceptions;
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/TreeWalkListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/TreeWalkListener.java
deleted file mode 100644
index 4ca9c5a..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/TreeWalkListener.java
+++ /dev/null
@@ -1,1711 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl;
-
-import java.util.Stack;
-
-import org.antlr.v4.runtime.ParserRuleContext;
-import org.antlr.v4.runtime.tree.ErrorNode;
-import org.antlr.v4.runtime.tree.TerminalNode;
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.datamodel.utils.YangConstructType;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangListener;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.impl.listeners.AppDataStructureListener;
-import org.onosproject.yangutils.parser.impl.listeners.AppExtendedNameListener;
-import org.onosproject.yangutils.parser.impl.listeners.ArgumentListener;
-import org.onosproject.yangutils.parser.impl.listeners.AugmentListener;
-import org.onosproject.yangutils.parser.impl.listeners.BaseFileListener;
-import org.onosproject.yangutils.parser.impl.listeners.BaseListener;
-import org.onosproject.yangutils.parser.impl.listeners.BelongsToListener;
-import org.onosproject.yangutils.parser.impl.listeners.BitListener;
-import org.onosproject.yangutils.parser.impl.listeners.BitsListener;
-import org.onosproject.yangutils.parser.impl.listeners.CaseListener;
-import org.onosproject.yangutils.parser.impl.listeners.ChoiceListener;
-import org.onosproject.yangutils.parser.impl.listeners.CompilerAnnotationListener;
-import org.onosproject.yangutils.parser.impl.listeners.ConfigListener;
-import org.onosproject.yangutils.parser.impl.listeners.ContactListener;
-import org.onosproject.yangutils.parser.impl.listeners.ContainerListener;
-import org.onosproject.yangutils.parser.impl.listeners.DataStructureKeyListener;
-import org.onosproject.yangutils.parser.impl.listeners.Decimal64Listener;
-import org.onosproject.yangutils.parser.impl.listeners.DefaultListener;
-import org.onosproject.yangutils.parser.impl.listeners.DescriptionListener;
-import org.onosproject.yangutils.parser.impl.listeners.EnumListener;
-import org.onosproject.yangutils.parser.impl.listeners.EnumerationListener;
-import org.onosproject.yangutils.parser.impl.listeners.ErrorAppTagListener;
-import org.onosproject.yangutils.parser.impl.listeners.ErrorMessageListener;
-import org.onosproject.yangutils.parser.impl.listeners.ExtensionListener;
-import org.onosproject.yangutils.parser.impl.listeners.FeatureListener;
-import org.onosproject.yangutils.parser.impl.listeners.FractionDigitsListener;
-import org.onosproject.yangutils.parser.impl.listeners.GroupingListener;
-import org.onosproject.yangutils.parser.impl.listeners.IdentityListener;
-import org.onosproject.yangutils.parser.impl.listeners.IdentityrefListener;
-import org.onosproject.yangutils.parser.impl.listeners.IfFeatureListener;
-import org.onosproject.yangutils.parser.impl.listeners.ImportListener;
-import org.onosproject.yangutils.parser.impl.listeners.IncludeListener;
-import org.onosproject.yangutils.parser.impl.listeners.InputListener;
-import org.onosproject.yangutils.parser.impl.listeners.KeyListener;
-import org.onosproject.yangutils.parser.impl.listeners.LeafListListener;
-import org.onosproject.yangutils.parser.impl.listeners.LeafListener;
-import org.onosproject.yangutils.parser.impl.listeners.LeafrefListener;
-import org.onosproject.yangutils.parser.impl.listeners.LengthRestrictionListener;
-import org.onosproject.yangutils.parser.impl.listeners.ListListener;
-import org.onosproject.yangutils.parser.impl.listeners.MandatoryListener;
-import org.onosproject.yangutils.parser.impl.listeners.MaxElementsListener;
-import org.onosproject.yangutils.parser.impl.listeners.MinElementsListener;
-import org.onosproject.yangutils.parser.impl.listeners.ModuleListener;
-import org.onosproject.yangutils.parser.impl.listeners.MustListener;
-import org.onosproject.yangutils.parser.impl.listeners.NamespaceListener;
-import org.onosproject.yangutils.parser.impl.listeners.NotificationListener;
-import org.onosproject.yangutils.parser.impl.listeners.OrganizationListener;
-import org.onosproject.yangutils.parser.impl.listeners.OutputListener;
-import org.onosproject.yangutils.parser.impl.listeners.PathListener;
-import org.onosproject.yangutils.parser.impl.listeners.PatternRestrictionListener;
-import org.onosproject.yangutils.parser.impl.listeners.PositionListener;
-import org.onosproject.yangutils.parser.impl.listeners.PrefixListener;
-import org.onosproject.yangutils.parser.impl.listeners.PresenceListener;
-import org.onosproject.yangutils.parser.impl.listeners.RangeRestrictionListener;
-import org.onosproject.yangutils.parser.impl.listeners.ReferenceListener;
-import org.onosproject.yangutils.parser.impl.listeners.RequireInstanceListener;
-import org.onosproject.yangutils.parser.impl.listeners.RevisionDateListener;
-import org.onosproject.yangutils.parser.impl.listeners.RevisionListener;
-import org.onosproject.yangutils.parser.impl.listeners.RpcListener;
-import org.onosproject.yangutils.parser.impl.listeners.ShortCaseListener;
-import org.onosproject.yangutils.parser.impl.listeners.StatusListener;
-import org.onosproject.yangutils.parser.impl.listeners.SubModuleListener;
-import org.onosproject.yangutils.parser.impl.listeners.TypeDefListener;
-import org.onosproject.yangutils.parser.impl.listeners.TypeListener;
-import org.onosproject.yangutils.parser.impl.listeners.UnionListener;
-import org.onosproject.yangutils.parser.impl.listeners.UniqueListener;
-import org.onosproject.yangutils.parser.impl.listeners.UnitsListener;
-import org.onosproject.yangutils.parser.impl.listeners.UsesListener;
-import org.onosproject.yangutils.parser.impl.listeners.ValueListener;
-import org.onosproject.yangutils.parser.impl.listeners.VersionListener;
-import org.onosproject.yangutils.parser.impl.listeners.WhenListener;
-
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.handleUnsupportedYangConstruct;
-import static org.onosproject.yangutils.utils.UtilConstants.CURRENTLY_UNSUPPORTED;
-import static org.onosproject.yangutils.utils.UtilConstants.UNSUPPORTED_YANG_CONSTRUCT;
-
-/**
- * Represents ANTLR generates parse-tree. ANTLR generates a parse-tree listener interface that responds to events
- * triggered by the built-in tree walker. The methods in listener are just
- * callbacks. This class implements listener interface and generates the
- * corresponding data model tree.
- */
-public class TreeWalkListener implements GeneratedYangListener {
-
- // List of parsable node entries maintained in stack
- private Stack<Parsable> parsedDataStack = new Stack<>();
-
- // Parse tree root node
- private YangNode rootNode;
-
- // YANG file name.
- private String fileName;
-
- /**
- * Parent depth of grouping count for any node.
- */
- private int groupingDepth;
-
- /**
- * Parent depth of unsupported yang construct count for any node.
- */
- private int unsupportedYangConstructDepth;
-
- /**
- * Returns number of unsupported yang constructs parents, by a node, at any level.
- *
- * @return depth of unsupported yang constructs
- */
- public int getUnsupportedYangConstructDepth() {
- return unsupportedYangConstructDepth;
- }
-
- /**
- * Sets number of unsupported yang constructs by a node at any level.
- */
- private void increaseUnsupportedYangConstructDepth() {
- unsupportedYangConstructDepth++;
- }
-
- /**
- * Sets number of unsupported yang constructs by a node at any level.
- */
- private void decreaseUnsupportedYangConstructDepth() {
- unsupportedYangConstructDepth--;
- }
-
- /**
- * Returns number of grouping parents, by a node, at any level.
- *
- * @return depth of grouping
- */
- public int getGroupingDepth() {
- return groupingDepth;
- }
-
- /**
- * Sets number of grouping parents by a node at any level.
- */
- public void increaseGroupingDepth() {
- groupingDepth++;
- }
-
- /**
- * Sets number of grouping parents by a node at any level.
- */
- public void decreaseGroupingDepth() {
- groupingDepth--;
- }
-
- /**
- * Returns stack of parsable data.
- *
- * @return stack of parsable data
- */
- public Stack<Parsable> getParsedDataStack() {
- return parsedDataStack;
- }
-
- /**
- * Returns root node.
- *
- * @return rootNode of data model tree
- */
- public YangNode getRootNode() {
- return rootNode;
- }
-
- /**
- * Returns YANG file name.
- *
- * @return YANG file name
- */
- public String getFileName() {
- return fileName;
- }
-
- /**
- * Sets YANG file name.
- *
- * @param fileName YANG file name
- */
- public void setFileName(String fileName) {
- this.fileName = fileName;
- }
-
- /**
- * Set parsed data stack.
- *
- * @param parsedDataStack stack of parsable data objects
- */
- public void setParsedDataStack(Stack<Parsable> parsedDataStack) {
- this.parsedDataStack = parsedDataStack;
- }
-
- /**
- * Set root node.
- *
- * @param rootNode root node of data model tree
- */
- public void setRootNode(YangNode rootNode) {
- this.rootNode = rootNode;
- }
-
- @Override
- public void enterYangfile(GeneratedYangParser.YangfileContext ctx) {
- BaseFileListener.processYangFileEntry(this, ctx);
- }
-
- @Override
- public void exitYangfile(GeneratedYangParser.YangfileContext ctx) {
- BaseFileListener.processYangFileExit(this, ctx);
- }
-
- @Override
- public void enterModuleStatement(GeneratedYangParser.ModuleStatementContext ctx) {
- ModuleListener.processModuleEntry(this, ctx);
- }
-
- @Override
- public void exitModuleStatement(GeneratedYangParser.ModuleStatementContext ctx) {
- ModuleListener.processModuleExit(this, ctx);
- }
-
- @Override
- public void enterModuleBody(GeneratedYangParser.ModuleBodyContext ctx) {
- // do nothing.
- }
-
- @Override
- public void exitModuleBody(GeneratedYangParser.ModuleBodyContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterModuleHeaderStatement(GeneratedYangParser.ModuleHeaderStatementContext ctx) {
- // do nothing.
- }
-
- @Override
- public void exitModuleHeaderStatement(GeneratedYangParser.ModuleHeaderStatementContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterLinkageStatements(GeneratedYangParser.LinkageStatementsContext ctx) {
- // do nothing.
- }
-
- @Override
- public void exitLinkageStatements(GeneratedYangParser.LinkageStatementsContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterMetaStatements(GeneratedYangParser.MetaStatementsContext ctx) {
- // do nothing.
- }
-
- @Override
- public void exitMetaStatements(GeneratedYangParser.MetaStatementsContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterRevisionStatements(GeneratedYangParser.RevisionStatementsContext ctx) {
- // do nothing.
- }
-
- @Override
- public void exitRevisionStatements(GeneratedYangParser.RevisionStatementsContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterBodyStatements(GeneratedYangParser.BodyStatementsContext ctx) {
- // do nothing.
- }
-
- @Override
- public void exitBodyStatements(GeneratedYangParser.BodyStatementsContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterYangVersionStatement(GeneratedYangParser.YangVersionStatementContext ctx) {
- VersionListener.processVersionEntry(this, ctx);
- }
-
- @Override
- public void exitYangVersionStatement(GeneratedYangParser.YangVersionStatementContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterNamespaceStatement(GeneratedYangParser.NamespaceStatementContext ctx) {
- NamespaceListener.processNamespaceEntry(this, ctx);
- }
-
- @Override
- public void exitNamespaceStatement(GeneratedYangParser.NamespaceStatementContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterPrefixStatement(GeneratedYangParser.PrefixStatementContext ctx) {
- PrefixListener.processPrefixEntry(this, ctx);
- }
-
- @Override
- public void exitPrefixStatement(GeneratedYangParser.PrefixStatementContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterImportStatement(GeneratedYangParser.ImportStatementContext ctx) {
- ImportListener.processImportEntry(this, ctx);
- }
-
- @Override
- public void exitImportStatement(GeneratedYangParser.ImportStatementContext ctx) {
- ImportListener.processImportExit(this, ctx);
- }
-
- @Override
- public void enterImportStatementBody(GeneratedYangParser.ImportStatementBodyContext ctx) {
- // do nothing.
- }
-
- @Override
- public void exitImportStatementBody(GeneratedYangParser.ImportStatementBodyContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterRevisionDateStatement(GeneratedYangParser.RevisionDateStatementContext ctx) {
- RevisionDateListener.processRevisionDateEntry(this, ctx);
- }
-
- @Override
- public void exitRevisionDateStatement(GeneratedYangParser.RevisionDateStatementContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterIncludeStatement(GeneratedYangParser.IncludeStatementContext ctx) {
- IncludeListener.processIncludeEntry(this, ctx);
- }
-
- @Override
- public void exitIncludeStatement(GeneratedYangParser.IncludeStatementContext ctx) {
- IncludeListener.processIncludeExit(this, ctx);
- }
-
- @Override
- public void enterOrganizationStatement(GeneratedYangParser.OrganizationStatementContext ctx) {
- OrganizationListener.processOrganizationEntry(this, ctx);
- }
-
- @Override
- public void exitOrganizationStatement(GeneratedYangParser.OrganizationStatementContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterContactStatement(GeneratedYangParser.ContactStatementContext ctx) {
- ContactListener.processContactEntry(this, ctx);
- }
-
- @Override
- public void exitContactStatement(GeneratedYangParser.ContactStatementContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterDescriptionStatement(GeneratedYangParser.DescriptionStatementContext ctx) {
- if (getUnsupportedYangConstructDepth() == 0) {
- DescriptionListener.processDescriptionEntry(this, ctx);
- }
- }
-
- @Override
- public void exitDescriptionStatement(GeneratedYangParser.DescriptionStatementContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterReferenceStatement(GeneratedYangParser.ReferenceStatementContext ctx) {
- if (getUnsupportedYangConstructDepth() == 0) {
- ReferenceListener.processReferenceEntry(this, ctx);
- }
- }
-
- @Override
- public void exitReferenceStatement(GeneratedYangParser.ReferenceStatementContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterRevisionStatement(GeneratedYangParser.RevisionStatementContext ctx) {
- RevisionListener.processRevisionEntry(this, ctx);
- }
-
- @Override
- public void exitRevisionStatement(GeneratedYangParser.RevisionStatementContext ctx) {
- RevisionListener.processRevisionExit(this, ctx);
- }
-
- @Override
- public void enterRevisionStatementBody(GeneratedYangParser.RevisionStatementBodyContext ctx) {
- // do nothing.
- }
-
- @Override
- public void exitRevisionStatementBody(GeneratedYangParser.RevisionStatementBodyContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterSubModuleStatement(GeneratedYangParser.SubModuleStatementContext ctx) {
- SubModuleListener.processSubModuleEntry(this, ctx);
- }
-
- @Override
- public void exitSubModuleStatement(GeneratedYangParser.SubModuleStatementContext ctx) {
- SubModuleListener.processSubModuleExit(this, ctx);
- }
-
- @Override
- public void enterSubmoduleBody(GeneratedYangParser.SubmoduleBodyContext ctx) {
- // do nothing.
- }
-
- @Override
- public void exitSubmoduleBody(GeneratedYangParser.SubmoduleBodyContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterSubmoduleHeaderStatement(GeneratedYangParser.SubmoduleHeaderStatementContext ctx) {
- // do nothing.
- }
-
- @Override
- public void exitSubmoduleHeaderStatement(GeneratedYangParser.SubmoduleHeaderStatementContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterBelongstoStatement(GeneratedYangParser.BelongstoStatementContext ctx) {
- BelongsToListener.processBelongsToEntry(this, ctx);
- }
-
- @Override
- public void exitBelongstoStatement(GeneratedYangParser.BelongstoStatementContext ctx) {
- BelongsToListener.processBelongsToExit(this, ctx);
- }
-
- @Override
- public void enterBelongstoStatementBody(GeneratedYangParser.BelongstoStatementBodyContext ctx) {
- // do nothing.
- }
-
- @Override
- public void exitBelongstoStatementBody(GeneratedYangParser.BelongstoStatementBodyContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterExtensionStatement(GeneratedYangParser.ExtensionStatementContext ctx) {
- ExtensionListener.processExtensionEntry(this, ctx);
- }
-
- @Override
- public void exitExtensionStatement(GeneratedYangParser.ExtensionStatementContext ctx) {
- ExtensionListener.processExtensionExit(this, ctx);
- }
-
- @Override
- public void enterExtensionBody(GeneratedYangParser.ExtensionBodyContext ctx) {
- // do nothing.
- }
-
- @Override
- public void exitExtensionBody(GeneratedYangParser.ExtensionBodyContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterArgumentStatement(GeneratedYangParser.ArgumentStatementContext ctx) {
- ArgumentListener.processArgumentEntry(this, ctx);
- }
-
- @Override
- public void exitArgumentStatement(GeneratedYangParser.ArgumentStatementContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterArgumentBody(GeneratedYangParser.ArgumentBodyContext ctx) {
- // do nothing.
- }
-
- @Override
- public void exitArgumentBody(GeneratedYangParser.ArgumentBodyContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterYinElementStatement(GeneratedYangParser.YinElementStatementContext ctx) {
- // do nothing.
- }
-
- @Override
- public void exitYinElementStatement(GeneratedYangParser.YinElementStatementContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterIdentityStatement(GeneratedYangParser.IdentityStatementContext ctx) {
- IdentityListener.processIdentityEntry(this, ctx);
- }
-
- @Override
- public void exitIdentityStatement(GeneratedYangParser.IdentityStatementContext ctx) {
- IdentityListener.processIdentityExit(this, ctx);
- }
-
- @Override
- public void enterIdentityBody(GeneratedYangParser.IdentityBodyContext ctx) {
- // do nothing.
- }
-
- @Override
- public void exitIdentityBody(GeneratedYangParser.IdentityBodyContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterBaseStatement(GeneratedYangParser.BaseStatementContext ctx) {
- if (getUnsupportedYangConstructDepth() == 0) {
- BaseListener.processBaseEntry(this, ctx);
- }
- }
-
- @Override
- public void exitBaseStatement(GeneratedYangParser.BaseStatementContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterFeatureStatement(GeneratedYangParser.FeatureStatementContext ctx) {
- FeatureListener.processFeatureEntry(this, ctx);
- }
-
- @Override
- public void exitFeatureStatement(GeneratedYangParser.FeatureStatementContext ctx) {
- FeatureListener.processFeatureExit(this, ctx);
- }
-
- @Override
- public void enterFeatureBody(GeneratedYangParser.FeatureBodyContext ctx) {
- // do nothing
- }
-
- @Override
- public void exitFeatureBody(GeneratedYangParser.FeatureBodyContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterDataDefStatement(GeneratedYangParser.DataDefStatementContext ctx) {
- // do nothing.
- }
-
- @Override
- public void exitDataDefStatement(GeneratedYangParser.DataDefStatementContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterIfFeatureStatement(GeneratedYangParser.IfFeatureStatementContext ctx) {
- if (getUnsupportedYangConstructDepth() == 0) {
- IfFeatureListener.processIfFeatureEntry(this, ctx);
- }
- }
-
- @Override
- public void exitIfFeatureStatement(GeneratedYangParser.IfFeatureStatementContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterUnitsStatement(GeneratedYangParser.UnitsStatementContext ctx) {
- if (getUnsupportedYangConstructDepth() == 0) {
- UnitsListener.processUnitsEntry(this, ctx);
- }
- }
-
- @Override
- public void exitUnitsStatement(GeneratedYangParser.UnitsStatementContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterTypedefStatement(GeneratedYangParser.TypedefStatementContext ctx) {
- TypeDefListener.processTypeDefEntry(this, ctx);
- }
-
- @Override
- public void exitTypedefStatement(GeneratedYangParser.TypedefStatementContext ctx) {
- TypeDefListener.processTypeDefExit(this, ctx);
- }
-
- @Override
- public void enterTypeStatement(GeneratedYangParser.TypeStatementContext ctx) {
- if (getUnsupportedYangConstructDepth() == 0) {
- TypeListener.processTypeEntry(this, ctx);
- }
- }
-
- @Override
- public void exitTypeStatement(GeneratedYangParser.TypeStatementContext ctx) {
- if (getUnsupportedYangConstructDepth() == 0) {
- TypeListener.processTypeExit(this, ctx);
- }
- }
-
- @Override
- public void enterTypeBodyStatements(GeneratedYangParser.TypeBodyStatementsContext ctx) {
- // do nothing.
- }
-
- @Override
- public void exitTypeBodyStatements(GeneratedYangParser.TypeBodyStatementsContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterDecimal64Specification(GeneratedYangParser.Decimal64SpecificationContext ctx) {
- if (getUnsupportedYangConstructDepth() == 0) {
- Decimal64Listener.processDecimal64Entry(this, ctx);
- }
- }
-
- @Override
- public void exitDecimal64Specification(GeneratedYangParser.Decimal64SpecificationContext ctx) {
- if (getUnsupportedYangConstructDepth() == 0) {
- Decimal64Listener.processDecimal64Exit(this, ctx);
- }
- }
-
- @Override
- public void enterFractionDigitStatement(GeneratedYangParser.FractionDigitStatementContext ctx) {
- if (getUnsupportedYangConstructDepth() == 0) {
- FractionDigitsListener.processFractionDigitsEntry(this, ctx);
- }
- }
-
- @Override
- public void exitFractionDigitStatement(GeneratedYangParser.FractionDigitStatementContext currentContext) {
- // do nothing
- }
-
- @Override
- public void enterNumericalRestrictions(GeneratedYangParser.NumericalRestrictionsContext ctx) {
- // do nothing.
- }
-
- @Override
- public void exitNumericalRestrictions(GeneratedYangParser.NumericalRestrictionsContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterRangeStatement(GeneratedYangParser.RangeStatementContext ctx) {
- if (getUnsupportedYangConstructDepth() == 0) {
- RangeRestrictionListener.processRangeRestrictionEntry(this, ctx);
- }
- }
-
- @Override
- public void exitRangeStatement(GeneratedYangParser.RangeStatementContext ctx) {
- if (getUnsupportedYangConstructDepth() == 0) {
- RangeRestrictionListener.processRangeRestrictionExit(this, ctx);
- }
- }
-
- @Override
- public void enterCommonStatements(GeneratedYangParser.CommonStatementsContext ctx) {
- // do nothing.
- }
-
- @Override
- public void exitCommonStatements(GeneratedYangParser.CommonStatementsContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterStringRestrictions(GeneratedYangParser.StringRestrictionsContext ctx) {
- // do nothing.
- }
-
- @Override
- public void exitStringRestrictions(GeneratedYangParser.StringRestrictionsContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterLengthStatement(GeneratedYangParser.LengthStatementContext ctx) {
- if (getUnsupportedYangConstructDepth() == 0) {
- LengthRestrictionListener.processLengthRestrictionEntry(this, ctx);
- }
- }
-
- @Override
- public void exitLengthStatement(GeneratedYangParser.LengthStatementContext ctx) {
- if (getUnsupportedYangConstructDepth() == 0) {
- LengthRestrictionListener.processLengthRestrictionExit(this, ctx);
- }
- }
-
- @Override
- public void enterPatternStatement(GeneratedYangParser.PatternStatementContext ctx) {
- if (getUnsupportedYangConstructDepth() == 0) {
- PatternRestrictionListener.processPatternRestrictionEntry(this, ctx);
- }
- }
-
- @Override
- public void exitPatternStatement(GeneratedYangParser.PatternStatementContext ctx) {
- if (getUnsupportedYangConstructDepth() == 0) {
- PatternRestrictionListener.processPatternRestrictionExit(this, ctx);
- }
- }
-
- @Override
- public void enterDefaultStatement(GeneratedYangParser.DefaultStatementContext ctx) {
- if (getUnsupportedYangConstructDepth() == 0) {
- DefaultListener.processDefaultEntry(this, ctx);
- }
- }
-
- @Override
- public void exitDefaultStatement(GeneratedYangParser.DefaultStatementContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterEnumSpecification(GeneratedYangParser.EnumSpecificationContext ctx) {
- if (getUnsupportedYangConstructDepth() == 0) {
- EnumerationListener.processEnumerationEntry(this, ctx);
- }
- }
-
- @Override
- public void exitEnumSpecification(GeneratedYangParser.EnumSpecificationContext ctx) {
- if (getUnsupportedYangConstructDepth() == 0) {
- EnumerationListener.processEnumerationExit(this, ctx);
- }
- }
-
- @Override
- public void enterEnumStatement(GeneratedYangParser.EnumStatementContext ctx) {
- if (getUnsupportedYangConstructDepth() == 0) {
- EnumListener.processEnumEntry(this, ctx);
- }
- }
-
- @Override
- public void exitEnumStatement(GeneratedYangParser.EnumStatementContext ctx) {
- if (getUnsupportedYangConstructDepth() == 0) {
- EnumListener.processEnumExit(this, ctx);
- }
- }
-
- @Override
- public void enterEnumStatementBody(GeneratedYangParser.EnumStatementBodyContext ctx) {
- // do nothing.
- }
-
- @Override
- public void exitEnumStatementBody(GeneratedYangParser.EnumStatementBodyContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterLeafrefSpecification(GeneratedYangParser.LeafrefSpecificationContext ctx) {
- if (getUnsupportedYangConstructDepth() == 0) {
- LeafrefListener.processLeafrefEntry(this, ctx);
- }
- }
-
- @Override
- public void exitLeafrefSpecification(GeneratedYangParser.LeafrefSpecificationContext ctx) {
- if (getUnsupportedYangConstructDepth() == 0) {
- LeafrefListener.processLeafrefExit(this, ctx);
- }
- }
-
- @Override
- public void enterPathStatement(GeneratedYangParser.PathStatementContext ctx) {
- if (getUnsupportedYangConstructDepth() == 0) {
- PathListener.processPathEntry(this, ctx);
- }
- }
-
- @Override
- public void exitPathStatement(GeneratedYangParser.PathStatementContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterRequireInstanceStatement(GeneratedYangParser.RequireInstanceStatementContext ctx) {
- if (getUnsupportedYangConstructDepth() == 0) {
- RequireInstanceListener.processRequireInstanceEntry(this, ctx);
- }
- }
-
- @Override
- public void exitRequireInstanceStatement(GeneratedYangParser.RequireInstanceStatementContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterInstanceIdentifierSpecification(GeneratedYangParser.InstanceIdentifierSpecificationContext ctx) {
- // do nothing.
- }
-
- @Override
- public void exitInstanceIdentifierSpecification(GeneratedYangParser.InstanceIdentifierSpecificationContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterIdentityrefSpecification(GeneratedYangParser.IdentityrefSpecificationContext ctx) {
- if (getUnsupportedYangConstructDepth() == 0) {
- IdentityrefListener.processIdentityrefEntry(this, ctx);
- }
- }
-
- @Override
- public void exitIdentityrefSpecification(GeneratedYangParser.IdentityrefSpecificationContext ctx) {
- if (getUnsupportedYangConstructDepth() == 0) {
- IdentityrefListener.processIdentityrefExit(this, ctx);
- }
- }
-
- @Override
- public void enterUnionSpecification(GeneratedYangParser.UnionSpecificationContext ctx) {
- if (getUnsupportedYangConstructDepth() == 0) {
- UnionListener.processUnionEntry(this, ctx);
- }
- }
-
- @Override
- public void exitUnionSpecification(GeneratedYangParser.UnionSpecificationContext ctx) {
- if (getUnsupportedYangConstructDepth() == 0) {
- UnionListener.processUnionExit(this, ctx);
- }
- }
-
- @Override
- public void enterBitsSpecification(GeneratedYangParser.BitsSpecificationContext ctx) {
- if (getUnsupportedYangConstructDepth() == 0) {
- BitsListener.processBitsEntry(this, ctx);
- }
- }
-
- @Override
- public void exitBitsSpecification(GeneratedYangParser.BitsSpecificationContext ctx) {
- if (getUnsupportedYangConstructDepth() == 0) {
- BitsListener.processBitsExit(this, ctx);
- }
- }
-
- @Override
- public void enterBitStatement(GeneratedYangParser.BitStatementContext ctx) {
- if (getUnsupportedYangConstructDepth() == 0) {
- BitListener.processBitEntry(this, ctx);
- }
- }
-
- @Override
- public void exitBitStatement(GeneratedYangParser.BitStatementContext ctx) {
- if (getUnsupportedYangConstructDepth() == 0) {
- BitListener.processBitExit(this, ctx);
- }
- }
-
- @Override
- public void enterBitBodyStatement(GeneratedYangParser.BitBodyStatementContext ctx) {
- // do nothing.
- }
-
- @Override
- public void exitBitBodyStatement(GeneratedYangParser.BitBodyStatementContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterPositionStatement(GeneratedYangParser.PositionStatementContext ctx) {
- if (getUnsupportedYangConstructDepth() == 0) {
- PositionListener.processPositionEntry(this, ctx);
- }
- }
-
- @Override
- public void exitPositionStatement(GeneratedYangParser.PositionStatementContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterStatusStatement(GeneratedYangParser.StatusStatementContext ctx) {
- if (getUnsupportedYangConstructDepth() == 0) {
- StatusListener.processStatusEntry(this, ctx);
- }
- }
-
- @Override
- public void exitStatusStatement(GeneratedYangParser.StatusStatementContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterConfigStatement(GeneratedYangParser.ConfigStatementContext ctx) {
- if (getUnsupportedYangConstructDepth() == 0) {
- ConfigListener.processConfigEntry(this, ctx);
- }
- }
-
- @Override
- public void exitConfigStatement(GeneratedYangParser.ConfigStatementContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterMandatoryStatement(GeneratedYangParser.MandatoryStatementContext ctx) {
- if (getUnsupportedYangConstructDepth() == 0) {
- MandatoryListener.processMandatoryEntry(this, ctx);
- }
- }
-
- @Override
- public void exitMandatoryStatement(GeneratedYangParser.MandatoryStatementContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterPresenceStatement(GeneratedYangParser.PresenceStatementContext ctx) {
- if (getUnsupportedYangConstructDepth() == 0) {
- PresenceListener.processPresenceEntry(this, ctx);
- }
- }
-
- @Override
- public void exitPresenceStatement(GeneratedYangParser.PresenceStatementContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterOrderedByStatement(GeneratedYangParser.OrderedByStatementContext ctx) {
- handleUnsupportedYangConstruct(YangConstructType.ORDERED_BY_DATA, ctx, CURRENTLY_UNSUPPORTED, getFileName());
- }
-
- @Override
- public void exitOrderedByStatement(GeneratedYangParser.OrderedByStatementContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterMustStatement(GeneratedYangParser.MustStatementContext ctx) {
- if (getUnsupportedYangConstructDepth() == 0) {
- MustListener.processMustEntry(this, ctx);
- }
- }
-
- @Override
- public void exitMustStatement(GeneratedYangParser.MustStatementContext ctx) {
- if (getUnsupportedYangConstructDepth() == 0) {
- MustListener.processMustExit(this, ctx);
- }
- }
-
- @Override
- public void enterErrorMessageStatement(GeneratedYangParser.ErrorMessageStatementContext ctx) {
- if (getUnsupportedYangConstructDepth() == 0) {
- ErrorMessageListener.processErrorMessageEntry(this, ctx);
- }
- }
-
- @Override
- public void exitErrorMessageStatement(GeneratedYangParser.ErrorMessageStatementContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterErrorAppTagStatement(GeneratedYangParser.ErrorAppTagStatementContext ctx) {
- if (getUnsupportedYangConstructDepth() == 0) {
- ErrorAppTagListener.processErrorAppTagMessageEntry(this, ctx);
- }
- }
-
- @Override
- public void exitErrorAppTagStatement(GeneratedYangParser.ErrorAppTagStatementContext ctx) {
- //do nothing
- }
-
- @Override
- public void enterMinElementsStatement(GeneratedYangParser.MinElementsStatementContext ctx) {
- if (getUnsupportedYangConstructDepth() == 0) {
- MinElementsListener.processMinElementsEntry(this, ctx);
- }
- }
-
- @Override
- public void exitMinElementsStatement(GeneratedYangParser.MinElementsStatementContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterMaxElementsStatement(GeneratedYangParser.MaxElementsStatementContext ctx) {
- if (getUnsupportedYangConstructDepth() == 0) {
- MaxElementsListener.processMaxElementsEntry(this, ctx);
- }
- }
-
- @Override
- public void exitMaxElementsStatement(GeneratedYangParser.MaxElementsStatementContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterValueStatement(GeneratedYangParser.ValueStatementContext ctx) {
- if (getUnsupportedYangConstructDepth() == 0) {
- ValueListener.processValueEntry(this, ctx);
- }
- }
-
- @Override
- public void exitValueStatement(GeneratedYangParser.ValueStatementContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterGroupingStatement(GeneratedYangParser.GroupingStatementContext ctx) {
- GroupingListener.processGroupingEntry(this, ctx);
- }
-
- @Override
- public void exitGroupingStatement(GeneratedYangParser.GroupingStatementContext ctx) {
- GroupingListener.processGroupingExit(this, ctx);
- }
-
- @Override
- public void enterContainerStatement(GeneratedYangParser.ContainerStatementContext ctx) {
- ContainerListener.processContainerEntry(this, ctx);
- }
-
- @Override
- public void exitContainerStatement(GeneratedYangParser.ContainerStatementContext ctx) {
- ContainerListener.processContainerExit(this, ctx);
- }
-
- @Override
- public void enterLeafStatement(GeneratedYangParser.LeafStatementContext ctx) {
- LeafListener.processLeafEntry(this, ctx);
- }
-
- @Override
- public void exitLeafStatement(GeneratedYangParser.LeafStatementContext ctx) {
- LeafListener.processLeafExit(this, ctx);
- }
-
- @Override
- public void enterLeafListStatement(GeneratedYangParser.LeafListStatementContext ctx) {
- LeafListListener.processLeafListEntry(this, ctx);
- }
-
- @Override
- public void exitLeafListStatement(GeneratedYangParser.LeafListStatementContext ctx) {
- LeafListListener.processLeafListExit(this, ctx);
- }
-
- @Override
- public void enterListStatement(GeneratedYangParser.ListStatementContext ctx) {
- ListListener.processListEntry(this, ctx);
- }
-
- @Override
- public void exitListStatement(GeneratedYangParser.ListStatementContext ctx) {
- ListListener.processListExit(this, ctx);
- }
-
- @Override
- public void enterKeyStatement(GeneratedYangParser.KeyStatementContext ctx) {
- KeyListener.processKeyEntry(this, ctx);
- }
-
- @Override
- public void exitKeyStatement(GeneratedYangParser.KeyStatementContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterUniqueStatement(GeneratedYangParser.UniqueStatementContext ctx) {
- if (getUnsupportedYangConstructDepth() == 0) {
- UniqueListener.processUniqueEntry(this, ctx);
- }
- }
-
- @Override
- public void exitUniqueStatement(GeneratedYangParser.UniqueStatementContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterChoiceStatement(GeneratedYangParser.ChoiceStatementContext ctx) {
- ChoiceListener.processChoiceEntry(this, ctx);
- }
-
- @Override
- public void exitChoiceStatement(GeneratedYangParser.ChoiceStatementContext ctx) {
- ChoiceListener.processChoiceExit(this, ctx);
- }
-
- @Override
- public void enterShortCaseStatement(GeneratedYangParser.ShortCaseStatementContext ctx) {
- ShortCaseListener.processShortCaseEntry(this, ctx);
- }
-
- @Override
- public void exitShortCaseStatement(GeneratedYangParser.ShortCaseStatementContext ctx) {
- ShortCaseListener.processShortCaseExit(this, ctx);
- }
-
- @Override
- public void enterCaseStatement(GeneratedYangParser.CaseStatementContext ctx) {
- CaseListener.processCaseEntry(this, ctx);
- }
-
- @Override
- public void exitCaseStatement(GeneratedYangParser.CaseStatementContext ctx) {
- CaseListener.processCaseExit(this, ctx);
- }
-
- @Override
- public void enterAnyxmlStatement(GeneratedYangParser.AnyxmlStatementContext ctx) {
- increaseUnsupportedYangConstructDepth();
- handleUnsupportedYangConstruct(YangConstructType.ANYXML_DATA, ctx, UNSUPPORTED_YANG_CONSTRUCT, getFileName());
- }
-
- @Override
- public void exitAnyxmlStatement(GeneratedYangParser.AnyxmlStatementContext ctx) {
- decreaseUnsupportedYangConstructDepth();
- }
-
- @Override
- public void enterUsesStatement(GeneratedYangParser.UsesStatementContext ctx) {
- UsesListener.processUsesEntry(this, ctx);
- }
-
- @Override
- public void exitUsesStatement(GeneratedYangParser.UsesStatementContext ctx) {
- UsesListener.processUsesExit(this, ctx);
- }
-
- @Override
- public void enterRefineStatement(GeneratedYangParser.RefineStatementContext ctx) {
- increaseUnsupportedYangConstructDepth();
- handleUnsupportedYangConstruct(YangConstructType.REFINE_DATA, ctx, UNSUPPORTED_YANG_CONSTRUCT, getFileName());
- }
-
- @Override
- public void exitRefineStatement(GeneratedYangParser.RefineStatementContext ctx) {
- decreaseUnsupportedYangConstructDepth();
- }
-
- @Override
- public void enterRefineContainerStatements(GeneratedYangParser.RefineContainerStatementsContext ctx) {
- // do nothing.
- }
-
- @Override
- public void exitRefineContainerStatements(GeneratedYangParser.RefineContainerStatementsContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterRefineLeafStatements(GeneratedYangParser.RefineLeafStatementsContext ctx) {
- // do nothing.
- }
-
- @Override
- public void exitRefineLeafStatements(GeneratedYangParser.RefineLeafStatementsContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterRefineLeafListStatements(GeneratedYangParser.RefineLeafListStatementsContext ctx) {
- // do nothing.
- }
-
- @Override
- public void exitRefineLeafListStatements(GeneratedYangParser.RefineLeafListStatementsContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterRefineListStatements(GeneratedYangParser.RefineListStatementsContext ctx) {
- // do nothing.
- }
-
- @Override
- public void exitRefineListStatements(GeneratedYangParser.RefineListStatementsContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterRefineChoiceStatements(GeneratedYangParser.RefineChoiceStatementsContext ctx) {
- // do nothing.
- }
-
- @Override
- public void exitRefineChoiceStatements(GeneratedYangParser.RefineChoiceStatementsContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterRefineCaseStatements(GeneratedYangParser.RefineCaseStatementsContext ctx) {
- // do nothing.
- }
-
- @Override
- public void exitRefineCaseStatements(GeneratedYangParser.RefineCaseStatementsContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterRefineAnyxmlStatements(GeneratedYangParser.RefineAnyxmlStatementsContext ctx) {
- // do nothing.
- }
-
- @Override
- public void exitRefineAnyxmlStatements(GeneratedYangParser.RefineAnyxmlStatementsContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterAugmentStatement(GeneratedYangParser.AugmentStatementContext ctx) {
- AugmentListener.processAugmentEntry(this, ctx);
- }
-
- @Override
- public void exitAugmentStatement(GeneratedYangParser.AugmentStatementContext ctx) {
- AugmentListener.processAugmentExit(this, ctx);
- }
-
- @Override
- public void enterWhenStatement(GeneratedYangParser.WhenStatementContext ctx) {
- if (getUnsupportedYangConstructDepth() == 0) {
- WhenListener.processWhenEntry(this, ctx);
- }
- }
-
- @Override
- public void exitWhenStatement(GeneratedYangParser.WhenStatementContext ctx) {
- if (getUnsupportedYangConstructDepth() == 0) {
- WhenListener.processWhenExit(this, ctx);
- }
- }
-
- @Override
- public void enterRpcStatement(GeneratedYangParser.RpcStatementContext ctx) {
- RpcListener.processRpcEntry(this, ctx);
- }
-
- @Override
- public void exitRpcStatement(GeneratedYangParser.RpcStatementContext ctx) {
- RpcListener.processRpcExit(this, ctx);
- }
-
- @Override
- public void enterInputStatement(GeneratedYangParser.InputStatementContext ctx) {
- InputListener.processInputEntry(this, ctx);
- }
-
- @Override
- public void exitInputStatement(GeneratedYangParser.InputStatementContext ctx) {
- InputListener.processInputExit(this, ctx);
- }
-
- @Override
- public void enterOutputStatement(GeneratedYangParser.OutputStatementContext ctx) {
- OutputListener.processOutputEntry(this, ctx);
- }
-
- @Override
- public void exitOutputStatement(GeneratedYangParser.OutputStatementContext ctx) {
- OutputListener.processOutputExit(this, ctx);
- }
-
- @Override
- public void enterNotificationStatement(GeneratedYangParser.NotificationStatementContext ctx) {
- NotificationListener.processNotificationEntry(this, ctx);
- }
-
- @Override
- public void exitNotificationStatement(GeneratedYangParser.NotificationStatementContext ctx) {
- NotificationListener.processNotificationExit(this, ctx);
- }
-
- @Override
- public void enterDeviationStatement(GeneratedYangParser.DeviationStatementContext ctx) {
- increaseUnsupportedYangConstructDepth();
- handleUnsupportedYangConstruct(YangConstructType.DEVIATION_DATA, ctx, UNSUPPORTED_YANG_CONSTRUCT,
- getFileName());
- }
-
- @Override
- public void exitDeviationStatement(GeneratedYangParser.DeviationStatementContext ctx) {
- decreaseUnsupportedYangConstructDepth();
- }
-
- @Override
- public void enterDeviateNotSupportedStatement(GeneratedYangParser.DeviateNotSupportedStatementContext ctx) {
- // do nothing.
- }
-
- @Override
- public void exitDeviateNotSupportedStatement(GeneratedYangParser.DeviateNotSupportedStatementContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterDeviateAddStatement(GeneratedYangParser.DeviateAddStatementContext ctx) {
- // do nothing.
- }
-
- @Override
- public void exitDeviateAddStatement(GeneratedYangParser.DeviateAddStatementContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterDeviateDeleteStatement(GeneratedYangParser.DeviateDeleteStatementContext ctx) {
- // do nothing.
- }
-
- @Override
- public void exitDeviateDeleteStatement(GeneratedYangParser.DeviateDeleteStatementContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterDeviateReplaceStatement(GeneratedYangParser.DeviateReplaceStatementContext ctx) {
- // do nothing.
- }
-
- @Override
- public void exitDeviateReplaceStatement(GeneratedYangParser.DeviateReplaceStatementContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterString(GeneratedYangParser.StringContext ctx) {
- // do nothing.
- }
-
- @Override
- public void exitString(GeneratedYangParser.StringContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterIdentifier(GeneratedYangParser.IdentifierContext ctx) {
- // do nothing.
- }
-
- @Override
- public void exitIdentifier(GeneratedYangParser.IdentifierContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterDateArgumentString(GeneratedYangParser.DateArgumentStringContext ctx) {
- // do nothing.
- }
-
- @Override
- public void exitDateArgumentString(GeneratedYangParser.DateArgumentStringContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterRange(GeneratedYangParser.RangeContext ctx) {
- // do nothing.
- }
-
- @Override
- public void exitRange(GeneratedYangParser.RangeContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterLength(GeneratedYangParser.LengthContext ctx) {
- // do nothing.
- }
-
- @Override
- public void exitLength(GeneratedYangParser.LengthContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterPath(GeneratedYangParser.PathContext ctx) {
- // do nothing.
- }
-
- @Override
- public void exitPath(GeneratedYangParser.PathContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterPosition(GeneratedYangParser.PositionContext ctx) {
- // do nothing.
- }
-
- @Override
- public void exitPosition(GeneratedYangParser.PositionContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterStatus(GeneratedYangParser.StatusContext ctx) {
- // do nothing.
- }
-
- @Override
- public void exitStatus(GeneratedYangParser.StatusContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterConfig(GeneratedYangParser.ConfigContext ctx) {
- // do nothing.
- }
-
- @Override
- public void exitConfig(GeneratedYangParser.ConfigContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterMandatory(GeneratedYangParser.MandatoryContext ctx) {
- // do nothing.
- }
-
- @Override
- public void exitMandatory(GeneratedYangParser.MandatoryContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterOrderedBy(GeneratedYangParser.OrderedByContext ctx) {
- // do nothing.
- }
-
- @Override
- public void exitOrderedBy(GeneratedYangParser.OrderedByContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterMinValue(GeneratedYangParser.MinValueContext ctx) {
- // do nothing.
- }
-
- @Override
- public void exitMinValue(GeneratedYangParser.MinValueContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterMaxValue(GeneratedYangParser.MaxValueContext ctx) {
- // do nothing.
- }
-
- @Override
- public void exitMaxValue(GeneratedYangParser.MaxValueContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterKey(GeneratedYangParser.KeyContext ctx) {
- // do nothing.
- }
-
- @Override
- public void exitKey(GeneratedYangParser.KeyContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterUnique(GeneratedYangParser.UniqueContext ctx) {
- // do nothing.
- }
-
- @Override
- public void exitUnique(GeneratedYangParser.UniqueContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterRefine(GeneratedYangParser.RefineContext ctx) {
- // do nothing.
- }
-
- @Override
- public void exitRefine(GeneratedYangParser.RefineContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterAugment(GeneratedYangParser.AugmentContext ctx) {
- // do nothing.
- }
-
- @Override
- public void exitAugment(GeneratedYangParser.AugmentContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterDeviation(GeneratedYangParser.DeviationContext ctx) {
- // do nothing.
- }
-
- @Override
- public void exitDeviation(GeneratedYangParser.DeviationContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterYangConstruct(GeneratedYangParser.YangConstructContext ctx) {
- // do nothing.
- }
-
- @Override
- public void exitYangConstruct(GeneratedYangParser.YangConstructContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterCompilerAnnotationStatement(GeneratedYangParser.CompilerAnnotationStatementContext ctx) {
- CompilerAnnotationListener.processCompilerAnnotationEntry(this, ctx);
- }
-
- @Override
- public void exitCompilerAnnotationStatement(GeneratedYangParser.CompilerAnnotationStatementContext ctx) {
- CompilerAnnotationListener.processCompilerAnnotationExit(this, ctx);
- }
-
- @Override
- public void enterCompilerAnnotationBodyStatement(GeneratedYangParser.CompilerAnnotationBodyStatementContext ctx) {
- // do nothing
- }
-
- @Override
- public void exitCompilerAnnotationBodyStatement(GeneratedYangParser.CompilerAnnotationBodyStatementContext ctx) {
- // do nothing
- }
-
- @Override
- public void enterAppDataStructureStatement(GeneratedYangParser.AppDataStructureStatementContext ctx) {
- AppDataStructureListener.processAppDataStructureEntry(this, ctx);
- }
-
- @Override
- public void exitAppDataStructureStatement(GeneratedYangParser.AppDataStructureStatementContext ctx) {
- AppDataStructureListener.processAppDataStructureExit(this, ctx);
- }
-
- @Override
- public void enterAppDataStructure(GeneratedYangParser.AppDataStructureContext currentContext) {
- // do nothing
- }
-
- @Override
- public void exitAppDataStructure(GeneratedYangParser.AppDataStructureContext currentContext) {
- // do nothing
- }
-
- @Override
- public void enterAppExtendedStatement(GeneratedYangParser.AppExtendedStatementContext currentContext) {
- AppExtendedNameListener.processAppExtendedNameEntry(this, currentContext);
- }
-
- @Override
- public void exitAppExtendedStatement(GeneratedYangParser.AppExtendedStatementContext currentContext) {
- // TODO : to be implemented
- }
-
- @Override
- public void enterExtendedName(GeneratedYangParser.ExtendedNameContext currentContext) {
- // do nothing
- }
-
- @Override
- public void exitExtendedName(GeneratedYangParser.ExtendedNameContext currentContext) {
- // do nothing
- }
-
- @Override
- public void enterDataStructureKeyStatement(GeneratedYangParser.DataStructureKeyStatementContext ctx) {
- DataStructureKeyListener.processDataStructureKeyEntry(this, ctx);
- }
-
- @Override
- public void exitDataStructureKeyStatement(GeneratedYangParser.DataStructureKeyStatementContext ctx) {
- // do nothing
- }
-
- @Override
- public void enterVersion(GeneratedYangParser.VersionContext ctx) {
- // do nothing.
- }
-
- @Override
- public void exitVersion(GeneratedYangParser.VersionContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterValue(GeneratedYangParser.ValueContext ctx) {
- // do nothing.
- }
-
- @Override
- public void exitValue(GeneratedYangParser.ValueContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterRequireInstance(GeneratedYangParser.RequireInstanceContext ctx) {
- // do nothing.
- }
-
- @Override
- public void exitRequireInstance(GeneratedYangParser.RequireInstanceContext ctx) {
- // do nothing.
- }
-
- @Override
- public void enterFraction(GeneratedYangParser.FractionContext ctx) {
- // TODO: implement the method.
- }
-
- @Override
- public void exitFraction(GeneratedYangParser.FractionContext ctx) {
- // TODO: implement the method.
- }
-
- @Override
- public void visitTerminal(TerminalNode terminalNode) {
- // do nothing.
- }
-
- @Override
- public void visitErrorNode(ErrorNode errorNode) {
- // do nothing.
- }
-
- @Override
- public void enterEveryRule(ParserRuleContext parserRuleContext) {
- // do nothing.
- }
-
- @Override
- public void exitEveryRule(ParserRuleContext parserRuleContext) {
- // do nothing.
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/YangUtilsParserManager.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/YangUtilsParserManager.java
deleted file mode 100644
index c2b29ed..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/YangUtilsParserManager.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl;
-
-import java.io.IOException;
-
-import org.antlr.v4.runtime.ANTLRFileStream;
-import org.antlr.v4.runtime.ANTLRInputStream;
-import org.antlr.v4.runtime.CommonTokenStream;
-import org.antlr.v4.runtime.tree.ParseTree;
-import org.antlr.v4.runtime.tree.ParseTreeWalker;
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.parser.YangUtilsParser;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangLexer;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.parserutils.ParseTreeErrorListener;
-
-/**
- * Represents file parsing, parse tree creation and data model tree creation
- * corresponding to an input YANG file.
- */
-public class YangUtilsParserManager implements YangUtilsParser {
-
- @Override
- public YangNode getDataModel(String yangFile) throws IOException, ParserException {
-
- /**
- * Create a char stream that reads from YANG file. Throws an exception
- * in case input YANG file is either null or non existent.
- */
- ANTLRInputStream input;
- try {
- input = new ANTLRFileStream(yangFile);
- } catch (IOException e) {
- throw new ParserException("YANG file error : YANG file does not exist. " + yangFile);
- }
-
- // Create a lexer that feeds off of input char stream.
- GeneratedYangLexer lexer = new GeneratedYangLexer(input);
-
- // Create a buffer of tokens pulled from the lexer.
- CommonTokenStream tokens = new CommonTokenStream(lexer);
-
- // Create a parser that feeds off the tokens buffer.
- GeneratedYangParser parser = new GeneratedYangParser(tokens);
-
- // Remove console error listener.
- parser.removeErrorListeners();
-
- // Create instance of customized error listener.
- ParseTreeErrorListener parseTreeErrorListener = new ParseTreeErrorListener();
-
- // Add customized error listener to catch errors during parsing.
- parser.addErrorListener(parseTreeErrorListener);
-
- ParseTree tree;
-
- try {
- // Begin parsing YANG file and generate parse tree.
- tree = parser.yangfile();
- } catch (ParserException parserException) {
- parserException.setFileName(yangFile);
- throw parserException;
- }
-
- // Create a walker to walk the parse tree.
- ParseTreeWalker walker = new ParseTreeWalker();
-
- // Create a listener implementation class object.
- TreeWalkListener treeWalker = new TreeWalkListener();
- treeWalker.setFileName(yangFile);
- /**
- * Walk parse tree, provide call backs to methods in listener and build
- * data model tree.
- */
- try {
- walker.walk(treeWalker, tree);
- } catch (ParserException listenerException) {
- // TODO free incomplete data model tree.
- listenerException.setFileName(yangFile);
- throw listenerException;
- } finally {
- // TODO free parsable stack
- }
-
- // Returns the Root Node of the constructed data model tree.
- return treeWalker.getRootNode();
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/AppDataStructureListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/AppDataStructureListener.java
deleted file mode 100644
index e9ff96c..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/AppDataStructureListener.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-import org.onosproject.yangutils.datamodel.YangAppDataStructure;
-import org.onosproject.yangutils.datamodel.YangCompilerAnnotation;
-import org.onosproject.yangutils.datamodel.YangDataStructure;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.YangDataStructure.getDataStructureType;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.APP_DATA_STRUCTURE;
-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.INVALID_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidPrefix;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-
-/*
- * Reference: RFC6020 and YANG ANTLR Grammar
- *
- * ABNF grammar as per RFC6020
- * app-data-structure-stmt = prefix:app-data-structure-keyword string
- * (";" /
- * "{"
- * [data-structure-key-stmt stmtsep]
- * "}")
- *
- * ANTLR grammar rule
- * appDataStructureStatement : APP_DATA_STRUCTURE appDataStructure (STMTEND | (LEFT_CURLY_BRACE
- * dataStructureKeyStatement? RIGHT_CURLY_BRACE));
- */
-
-/**
- * Represents listener based call back function corresponding to the "app-data-structure"
- * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
- */
-public final class AppDataStructureListener {
-
- /**
- * Creates a new app-data-structure listener.
- */
- private AppDataStructureListener() {
- }
-
- /**
- * Performs validation and updates the data model tree. It is called when parser receives an
- * input matching the grammar rule(app-data-structure).
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processAppDataStructureEntry(TreeWalkListener listener,
- GeneratedYangParser.AppDataStructureStatementContext ctx) {
-
- checkStackIsNotEmpty(listener, MISSING_HOLDER, APP_DATA_STRUCTURE, "", ENTRY);
-
- String prefix = getValidPrefix(ctx.APP_DATA_STRUCTURE().getText(), APP_DATA_STRUCTURE, ctx);
- YangDataStructure dataStructure = getDataStructureType(ctx.appDataStructure().getText());
-
- YangAppDataStructure appDataStructure = new YangAppDataStructure();
- appDataStructure.setPrefix(prefix);
- appDataStructure.setDataStructure(dataStructure);
- appDataStructure.setLineNumber(ctx.getStart().getLine());
- appDataStructure.setCharPosition(ctx.getStart().getCharPositionInLine());
- appDataStructure.setFileName(listener.getFileName());
-
- Parsable curData = listener.getParsedDataStack().peek();
- if (curData instanceof YangCompilerAnnotation) {
- YangCompilerAnnotation compilerAnnotation = ((YangCompilerAnnotation) curData);
- compilerAnnotation.setYangAppDataStructure(appDataStructure);
- listener.getParsedDataStack().push(appDataStructure);
- } else {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, APP_DATA_STRUCTURE,
- "", ENTRY));
- }
- }
-
- /**
- * Performs validation and updates the data model tree. It is called when parser
- * exits from grammar rule (app-data-structure).
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processAppDataStructureExit(TreeWalkListener listener,
- GeneratedYangParser.AppDataStructureStatementContext ctx) {
-
- checkStackIsNotEmpty(listener, MISSING_HOLDER, APP_DATA_STRUCTURE, "", EXIT);
- if (!(listener.getParsedDataStack().peek() instanceof YangAppDataStructure)) {
- throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, APP_DATA_STRUCTURE,
- "", EXIT));
- }
- listener.getParsedDataStack().pop();
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/AppExtendedNameListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/AppExtendedNameListener.java
deleted file mode 100644
index 7ff8bbe..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/AppExtendedNameListener.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-import org.onosproject.yangutils.datamodel.YangAppExtended;
-import org.onosproject.yangutils.datamodel.YangCompilerAnnotation;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.APP_EXTENDED_NAME_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.ListenerUtil.getValidPrefix;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.removeQuotesAndHandleConcat;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-
-/*
- * Reference: RFC6020 and YANG ANTLR Grammar
- *
- * ABNF grammar as per RFC6020
- * app-extended-stmt = prefix:app-extended-name-keyword string ";"
- *
- * ANTLR grammar rule
- * appExtendedStatement : APP_EXTENDED extendedName STMTEND;
- */
-
-/**
- * Represents listener based call back function corresponding to the "app-extended-name"
- * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
- */
-public final class AppExtendedNameListener {
-
- /**
- * Creates a new app-extended-name listener.
- */
- private AppExtendedNameListener() {
- }
-
- /**
- * Performs validation and updates the data model tree. It is called when parser receives an
- * input matching the grammar rule(app-extended-name).
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processAppExtendedNameEntry(TreeWalkListener listener,
- GeneratedYangParser.AppExtendedStatementContext ctx) {
-
- checkStackIsNotEmpty(listener, MISSING_HOLDER, APP_EXTENDED_NAME_DATA, ctx.extendedName().getText(), ENTRY);
-
- String prefix = getValidPrefix(ctx.APP_EXTENDED().getText(), APP_EXTENDED_NAME_DATA, ctx);
- YangAppExtended extendedName = new YangAppExtended();
- extendedName.setPrefix(prefix);
- extendedName.setYangAppExtendedName(removeQuotesAndHandleConcat(ctx.extendedName().getText()));
-
- extendedName.setLineNumber(ctx.getStart().getLine());
- extendedName.setCharPosition(ctx.getStart().getCharPositionInLine());
- extendedName.setFileName(listener.getFileName());
- Parsable curData = listener.getParsedDataStack().peek();
- if (curData instanceof YangCompilerAnnotation) {
- YangCompilerAnnotation compilerAnnotation = ((YangCompilerAnnotation) curData);
- compilerAnnotation.setYangAppExtendedName(extendedName);
- } else {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, APP_EXTENDED_NAME_DATA,
- ctx.extendedName().getText(), ENTRY));
- }
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ArgumentListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ArgumentListener.java
deleted file mode 100644
index 797da12..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ArgumentListener.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-import org.onosproject.yangutils.datamodel.YangExtension;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.ARGUMENT_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.ListenerUtil.getValidIdentifier;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-
-/*
- * Reference: RFC6020 and YANG ANTLR Grammar
- *
- * ABNF grammar as per RFC6020
- * argument-stmt = argument-keyword sep identifier-arg-str optsep
- * (";" /
- * "{" stmtsep
- * [yin-element-stmt stmtsep]
- * "}")
- * *
- * ANTLR grammar rule
- * argumentStatement : ARGUMENT_KEYWORD identifier (STMTEND | LEFT_CURLY_BRACE argumentBody RIGHT_CURLY_BRACE);
- * argumentBody : yinElementStatement?;
- */
-
-/**
- * Represents listener based call back function corresponding to the "argument"
- * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
- */
-public final class ArgumentListener {
-
- /**
- * Creates a new argument listener.
- */
- private ArgumentListener() {
- }
-
- /**
- * It is called when parser receives an input matching the grammar rule
- * (argument), performs validation and updates the data model tree.
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processArgumentEntry(TreeWalkListener listener,
- GeneratedYangParser.ArgumentStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, ARGUMENT_DATA, ctx.identifier().getText(), ENTRY);
-
- String identifier = getValidIdentifier(ctx.identifier().getText(), ARGUMENT_DATA, ctx);
-
- Parsable curData = listener.getParsedDataStack().peek();
- if (curData instanceof YangExtension) {
- YangExtension extension = ((YangExtension) curData);
-
- extension.setLineNumber(ctx.getStart().getLine());
- extension.setCharPosition(ctx.getStart().getCharPositionInLine());
- extension.setFileName(listener.getFileName());
- extension.setArgumentName(identifier);
- } else {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, ARGUMENT_DATA,
- ctx.identifier().getText(), ENTRY));
- }
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/AugmentListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/AugmentListener.java
deleted file mode 100644
index 124f275..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/AugmentListener.java
+++ /dev/null
@@ -1,205 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-import java.util.List;
-
-import org.onosproject.yangutils.datamodel.YangAtomicPath;
-import org.onosproject.yangutils.datamodel.YangAugment;
-import org.onosproject.yangutils.datamodel.YangModule;
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.YangSubModule;
-import org.onosproject.yangutils.datamodel.YangUses;
-import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.linker.impl.YangResolutionInfoImpl;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.addResolutionInfo;
-import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.AUGMENT_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.CASE_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.DATA_DEF_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.DESCRIPTION_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.REFERENCE_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.STATUS_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.WHEN_DATA;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil;
-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.constructExtendedListenerErrorMessage;
-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_CURRENT_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidAbsoluteSchemaNodeId;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.removeQuotesAndHandleConcat;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityEitherOne;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne;
-import static org.onosproject.yangutils.translator.tojava.YangDataModelFactory.getYangAugmentNode;
-
-/*
- * Reference: RFC6020 and YANG ANTLR Grammar
- *
- * ABNF grammar as per RFC6020
- * augment-stmt = augment-keyword sep augment-arg-str optsep
- * "{" stmtsep
- * ;; these stmts can appear in any order
- * [when-stmt stmtsep]
- * *(if-feature-stmt stmtsep)
- * [status-stmt stmtsep]
- * [description-stmt stmtsep]
- * [reference-stmt stmtsep]
- * 1*((data-def-stmt stmtsep) /
- * (case-stmt stmtsep))
- * "}"
- *
- * ANTLR grammar rule
- * augmentStatement : AUGMENT_KEYWORD augment LEFT_CURLY_BRACE (whenStatement | ifFeatureStatement | statusStatement
- * | descriptionStatement | referenceStatement | dataDefStatement | caseStatement)* RIGHT_CURLY_BRACE;
- */
-
-/**
- * Represents listener based call back function corresponding to the "augment"
- * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
- */
-public final class AugmentListener {
-
- /**
- * Creates a new augment listener.
- */
- private AugmentListener() {
- }
-
- /**
- * It is called when parser receives an input matching the grammar rule
- * (augment), performs validation and updates the data model tree.
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processAugmentEntry(TreeWalkListener listener,
- GeneratedYangParser.AugmentStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, AUGMENT_DATA, ctx.augment().getText(), ENTRY);
-
- // Validate augment argument string
- List<YangAtomicPath> targetNodes = getValidAbsoluteSchemaNodeId(ctx.augment().getText(),
- AUGMENT_DATA, ctx);
-
- // Validate sub statement cardinality.
- validateSubStatementsCardinality(ctx);
-
- // Check for identifier collision
- int line = ctx.getStart().getLine();
- int charPositionInLine = ctx.getStart().getCharPositionInLine();
- detectCollidingChildUtil(listener, line, charPositionInLine, "", AUGMENT_DATA);
-
- Parsable curData = listener.getParsedDataStack().peek();
- if (curData instanceof YangModule || curData instanceof YangSubModule) {
- YangNode curNode = (YangNode) curData;
- YangAugment yangAugment = getYangAugmentNode(JAVA_GENERATION);
- yangAugment.setLineNumber(line);
- yangAugment.setCharPosition(charPositionInLine);
- yangAugment.setFileName(listener.getFileName());
- //validateTargetNodePath(targetNodes, curNode, ctx);
- // TODO: handle in linker.
-
- yangAugment.setTargetNode(targetNodes);
- yangAugment.setName(removeQuotesAndHandleConcat(ctx.augment().getText()));
-
- try {
- curNode.addChild(yangAugment);
- } catch (DataModelException e) {
- throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
- AUGMENT_DATA, ctx.augment().getText(), ENTRY, e.getMessage()));
- }
- listener.getParsedDataStack().push(yangAugment);
-
- // Add resolution information to the list
- YangResolutionInfoImpl resolutionInfo = new YangResolutionInfoImpl<YangAugment>(yangAugment,
- curNode, line,
- charPositionInLine);
- addToResolutionList(resolutionInfo, ctx);
-
- } else if (curData instanceof YangUses) {
- throw new ParserException(constructListenerErrorMessage(UNHANDLED_PARSED_DATA, AUGMENT_DATA,
- ctx.augment().getText(), ENTRY));
- }
- else {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, AUGMENT_DATA,
- ctx.augment().getText(), ENTRY));
- }
-
- }
-
- /**
- * It is called when parser exits from grammar rule (augment), it perform
- * validations and updates the data model tree.
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processAugmentExit(TreeWalkListener listener,
- GeneratedYangParser.AugmentStatementContext ctx) {
-
- //Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, AUGMENT_DATA, ctx.augment().getText(), EXIT);
-
- if (!(listener.getParsedDataStack().peek() instanceof YangAugment)) {
- throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, AUGMENT_DATA,
- ctx.augment().getText(), EXIT));
- }
- listener.getParsedDataStack().pop();
- }
-
- /**
- * Validates the cardinality of augment sub-statements as per grammar.
- *
- * @param ctx context object of the grammar rule
- */
- private static void validateSubStatementsCardinality(GeneratedYangParser.AugmentStatementContext ctx) {
- validateCardinalityMaxOne(ctx.statusStatement(), STATUS_DATA, AUGMENT_DATA, ctx.augment().getText());
- validateCardinalityMaxOne(ctx.descriptionStatement(), DESCRIPTION_DATA, AUGMENT_DATA, ctx.augment().getText());
- validateCardinalityMaxOne(ctx.referenceStatement(), REFERENCE_DATA, AUGMENT_DATA, ctx.augment().getText());
- validateCardinalityMaxOne(ctx.whenStatement(), WHEN_DATA, AUGMENT_DATA, ctx.augment().getText());
- validateCardinalityEitherOne(ctx.dataDefStatement(), DATA_DEF_DATA, ctx.caseStatement(),
- CASE_DATA, AUGMENT_DATA, ctx.augment().getText(), ctx);
- }
-
- /**
- * Add to resolution list.
- *
- * @param resolutionInfo resolution information.
- * @param ctx context object of the grammar rule
- */
- private static void addToResolutionList(YangResolutionInfoImpl<YangAugment> resolutionInfo,
- GeneratedYangParser.AugmentStatementContext ctx) {
-
- try {
- addResolutionInfo(resolutionInfo);
- } catch (DataModelException e) {
- throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
- AUGMENT_DATA, ctx.augment().getText(), EXIT, e.getMessage()));
- }
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/BaseFileListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/BaseFileListener.java
deleted file mode 100644
index 8ba4d02..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/BaseFileListener.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-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.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.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.INVALID_CHILD;
-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.checkStackIsEmpty;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-
-/*
- * Reference: RFC6020 and YANG ANTLR Grammar
- *
- * ANTLR grammar rule
- * yangfile : module_stmt
- * | submodule_stmt;
- */
-
-/**
- * Representation of call back function corresponding to the "base rule" defined in
- * ANTLR grammar file.
- */
-public final class BaseFileListener {
-
- /**
- * Creates a new base listener.
- */
- private BaseFileListener() {
- }
-
- /**
- * 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
- */
- public static void processYangFileEntry(TreeWalkListener listener, GeneratedYangParser.YangfileContext ctx) {
-
- // Check if stack is empty.
- checkStackIsEmpty(listener, INVALID_HOLDER, YANGBASE_DATA, "", ENTRY);
-
- }
-
- /**
- * It is called when parser exits from grammar rule (yangfile), it perform
- * validations and update the data model tree.
- *
- * @param listener Listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processYangFileExit(TreeWalkListener listener, GeneratedYangParser.YangfileContext ctx) {
-
- // Check for stack to be non empty.
- 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.setRootNode((YangNode) listener.getParsedDataStack().pop());
- } else {
- throw new ParserException(constructListenerErrorMessage(INVALID_CHILD, YANGBASE_DATA, "", EXIT));
- }
-
- // Check if stack is empty.
- checkStackIsEmpty(listener, INVALID_HOLDER, YANGBASE_DATA, "", EXIT);
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/BaseListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/BaseListener.java
deleted file mode 100644
index ebf85a7..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/BaseListener.java
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.yangutils.parser.impl.listeners;
-
-import org.onosproject.yangutils.datamodel.YangBase;
-import org.onosproject.yangutils.datamodel.YangIdentity;
-import org.onosproject.yangutils.datamodel.YangIdentityRef;
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
-import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
-import org.onosproject.yangutils.linker.impl.YangResolutionInfoImpl;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.addResolutionInfo;
-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.constructExtendedListenerErrorMessage;
-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.ListenerUtil.getValidNodeIdentifier;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.BASE_DATA;
-
-/**
- * base-stmt = base-keyword sep identifier-ref-arg-str
- * optsep stmtend*
- * identifier-ref-arg = [prefix ":"] identifier
- */
-
-/**
- * Represents listener based call back function corresponding to the "base"
- * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
- */
-public final class BaseListener {
-
- //Creates a new base listener.
- private BaseListener() {
- }
-
- /**
- * Performs validation and updates the data model tree when parser receives an
- * input matching the grammar rule (base).
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processBaseEntry(TreeWalkListener listener,
- GeneratedYangParser.BaseStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, BASE_DATA, ctx.string().getText(), ENTRY);
-
- YangNodeIdentifier nodeIdentifier = getValidNodeIdentifier(ctx.string().getText(), BASE_DATA, ctx);
-
- Parsable tmpData = listener.getParsedDataStack().peek();
-
- /**
- * For identityref base node identifier is copied in identity listener itself, so no need to process
- * base statement for indentityref
- */
- if (tmpData instanceof YangIdentityRef) {
- return;
- }
-
- if (!(tmpData instanceof YangIdentity)) {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, BASE_DATA,
- ctx.string().getText(), ENTRY));
- }
-
- YangBase yangBase = new YangBase();
- yangBase.setBaseIdentifier(nodeIdentifier);
- ((YangIdentity) tmpData).setBaseNode(yangBase);
-
- int errorLine = ctx.getStart().getLine();
- int errorPosition = ctx.getStart().getCharPositionInLine();
-
- yangBase.setLineNumber(errorLine);
- yangBase.setCharPosition(errorPosition);
- yangBase.setFileName(listener.getFileName());
-
- // Add resolution information to the list
- YangResolutionInfoImpl resolutionInfo =
- new YangResolutionInfoImpl<YangBase>(yangBase, (YangNode) tmpData, errorLine, errorPosition);
- addToResolutionList(resolutionInfo, ctx);
- }
-
- /**
- * Add to resolution list.
- *
- * @param resolutionInfo resolution information
- * @param ctx context object of the grammar rule
- */
- private static void addToResolutionList(YangResolutionInfoImpl<YangBase> resolutionInfo,
- GeneratedYangParser.BaseStatementContext ctx) {
-
- try {
- addResolutionInfo(resolutionInfo);
- } catch (DataModelException e) {
- throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
- BASE_DATA, ctx.string().getText(), EXIT, e.getMessage()));
- }
- }
-
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/BelongsToListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/BelongsToListener.java
deleted file mode 100644
index 4f7ecf8..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/BelongsToListener.java
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-import org.onosproject.yangutils.datamodel.YangBelongsTo;
-import org.onosproject.yangutils.datamodel.YangSubModule;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.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.INVALID_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-
-/*
- * Reference: RFC6020 and YANG ANTLR Grammar
- *
- * ABNF grammar as per RFC6020
- * submodule-header-stmts =
- * ;; these stmts can appear in any order
- * [yang-version-stmt stmtsep]
- * belongs-to-stmt stmtsep
- *
- * belongs-to-stmt = belongs-to-keyword sep identifier-arg-str
- * optsep
- * "{" stmtsep
- * prefix-stmt stmtsep
- * "}"
- *
- * ANTLR grammar rule
- * submodule_header_statement : yang_version_stmt? belongs_to_stmt
- * | belongs_to_stmt yang_version_stmt?
- * ;
- * belongs_to_stmt : BELONGS_TO_KEYWORD identifier LEFT_CURLY_BRACE belongs_to_stmt_body RIGHT_CURLY_BRACE;
- * belongs_to_stmt_body : prefix_stmt;
- */
-
-/**
- * Represents 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 {
-
- /**
- * Creates a new belongto listener.
- */
- private BelongsToListener() {
- }
-
- /**
- * 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
- */
- public static void processBelongsToEntry(TreeWalkListener listener,
- GeneratedYangParser.BelongstoStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, BELONGS_TO_DATA, ctx.identifier().getText(),
- ENTRY);
-
- String identifier = getValidIdentifier(ctx.identifier().getText(), BELONGS_TO_DATA, ctx);
-
- YangBelongsTo belongstoNode = new YangBelongsTo();
- belongstoNode.setBelongsToModuleName(identifier);
-
- // Set the line number and character position in line for the belongs to.
- int errorLine = ctx.getStart().getLine();
- int errorPosition = ctx.getStart().getCharPositionInLine();
- belongstoNode.setLineNumber(errorLine);
- belongstoNode.setCharPosition(errorPosition);
- belongstoNode.setFileName(listener.getFileName());
-
- // Push belongsto into the stack.
- listener.getParsedDataStack().push(belongstoNode);
- }
-
- /**
- * It is called when parser exits from grammar rule (belongsto), it perform
- * validations and update the data model tree.
- *
- * @param listener Listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processBelongsToExit(TreeWalkListener listener,
- GeneratedYangParser.BelongstoStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, BELONGS_TO_DATA, ctx.identifier().getText(),
- EXIT);
-
- Parsable tmpBelongstoNode = listener.getParsedDataStack().peek();
- if (tmpBelongstoNode instanceof YangBelongsTo) {
- listener.getParsedDataStack().pop();
-
- // Check for stack to be empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, BELONGS_TO_DATA,
- ctx.identifier().getText(), EXIT);
-
- Parsable tmpNode = listener.getParsedDataStack().peek();
- switch (tmpNode.getYangConstructType()) {
- case SUB_MODULE_DATA: {
- YangSubModule subModule = (YangSubModule) tmpNode;
- subModule.setBelongsTo((YangBelongsTo) tmpBelongstoNode);
- subModule.setPrefix(subModule.getBelongsTo().getPrefix());
- break;
- }
- default:
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, BELONGS_TO_DATA,
- ctx.identifier().getText(),
- EXIT));
- }
- } else {
- throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, BELONGS_TO_DATA,
- ctx.identifier().getText(), EXIT));
- }
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/BitListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/BitListener.java
deleted file mode 100644
index bd60910..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/BitListener.java
+++ /dev/null
@@ -1,182 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-/*
- * Reference: RFC6020 and YANG ANTLR Grammar
- *
- * ABNF grammar as per RFC6020
- * bit-stmt = bit-keyword sep identifier-arg-str optsep
- * (";" /
- * "{" stmtsep
- * ;; these stmts can appear in any order
- * [position-stmt stmtsep]
- * [status-stmt stmtsep]
- * [description-stmt stmtsep]
- * [reference-stmt stmtsep]
- * "}"
- * "}")
- *
- * ANTLR grammar rule
- * bitStatement : BIT_KEYWORD identifier (STMTEND | LEFT_CURLY_BRACE bitBodyStatement RIGHT_CURLY_BRACE);
- *
- * bitBodyStatement : positionStatement? statusStatement? descriptionStatement? referenceStatement?
- * | positionStatement? statusStatement? referenceStatement? descriptionStatement?
- * | positionStatement? descriptionStatement? statusStatement? referenceStatement?
- * | positionStatement? descriptionStatement? referenceStatement? statusStatement?
- * | positionStatement? referenceStatement? statusStatement? descriptionStatement?
- * | positionStatement? referenceStatement? descriptionStatement? statusStatement?
- * | statusStatement? positionStatement? descriptionStatement? referenceStatement?
- * | statusStatement? positionStatement? referenceStatement? descriptionStatement?
- * | statusStatement? descriptionStatement? descriptionStatement? positionStatement?
- * | statusStatement? descriptionStatement? positionStatement? descriptionStatement?
- * | statusStatement? referenceStatement? positionStatement? descriptionStatement?
- * | statusStatement? referenceStatement? descriptionStatement? positionStatement?
- * | descriptionStatement? positionStatement? statusStatement? referenceStatement?
- * | descriptionStatement? positionStatement? referenceStatement? statusStatement?
- * | descriptionStatement? statusStatement? positionStatement? referenceStatement?
- * | descriptionStatement? statusStatement? referenceStatement? positionStatement?
- * | descriptionStatement? referenceStatement? positionStatement? statusStatement?
- * | descriptionStatement? referenceStatement? statusStatement? positionStatement?
- * | referenceStatement? positionStatement? descriptionStatement? statusStatement?
- * | referenceStatement? positionStatement? statusStatement? descriptionStatement?
- * | referenceStatement? statusStatement? descriptionStatement? positionStatement?
- * | referenceStatement? statusStatement? positionStatement? descriptionStatement?
- * | referenceStatement? descriptionStatement? positionStatement? statusStatement?
- * | referenceStatement? descriptionStatement? statusStatement? positionStatement?
- * ;
- */
-
-import java.util.Map;
-
-import org.onosproject.yangutils.datamodel.YangBit;
-import org.onosproject.yangutils.datamodel.YangBits;
-import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.BIT_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.constructExtendedListenerErrorMessage;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_CONTENT;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-
-/**
- * Represents listener based call back function corresponding to the "bit"
- * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
- */
-public final class BitListener {
-
- /**
- * Creates a new bit listener.
- */
- private BitListener() {
- }
-
- /**
- * It is called when parser enters grammar rule (bit), it perform
- * validations and updates the data model tree.
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processBitEntry(TreeWalkListener listener,
- GeneratedYangParser.BitStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, BIT_DATA, ctx.identifier().getText(), ENTRY);
-
- String identifier = getValidIdentifier(ctx.identifier().getText(), BIT_DATA, ctx);
-
- YangBit bitNode = new YangBit();
- bitNode.setBitName(identifier);
-
- bitNode.setLineNumber(ctx.getStart().getLine());
- bitNode.setCharPosition(ctx.getStart().getCharPositionInLine());
- bitNode.setFileName(listener.getFileName());
- listener.getParsedDataStack().push(bitNode);
- }
-
- /**
- * It is called when parser exits from grammar rule (bit), it perform
- * validations and update the data model tree.
- *
- * @param listener Listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processBitExit(TreeWalkListener listener,
- GeneratedYangParser.BitStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, BIT_DATA, ctx.identifier().getText(), EXIT);
-
- Parsable tmpBitNode = listener.getParsedDataStack().peek();
- if (tmpBitNode instanceof YangBit) {
- listener.getParsedDataStack().pop();
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, BIT_DATA, ctx.identifier().getText(), EXIT);
-
- Parsable tmpNode = listener.getParsedDataStack().peek();
- switch (tmpNode.getYangConstructType()) {
- case BITS_DATA: {
- YangBits yangBits = (YangBits) tmpNode;
- if (ctx.bitBodyStatement() == null || ctx.bitBodyStatement().positionStatement() == null) {
- int maxPosition = 0;
- boolean isPositionPresent = false;
-
- for (Map.Entry<Integer, YangBit> element : yangBits.getBitPositionMap().entrySet()) {
- if (maxPosition <= element.getKey()) {
- maxPosition = element.getKey();
- isPositionPresent = true;
- }
- }
-
- if (isPositionPresent) {
- maxPosition++;
- }
- ((YangBit) tmpBitNode).setPosition(maxPosition);
- }
- try {
- yangBits.addBitInfo((YangBit) tmpBitNode);
- } catch (DataModelException e) {
- ParserException parserException = new ParserException(constructExtendedListenerErrorMessage(
- INVALID_CONTENT, BIT_DATA, ctx.identifier().getText(), EXIT, e.getMessage()));
- parserException.setLine(ctx.getStart().getLine());
- parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
- throw parserException;
- }
- break;
- }
- default:
- throw new ParserException(
- constructListenerErrorMessage(INVALID_HOLDER, BIT_DATA, ctx.identifier().getText(), EXIT));
- }
- } else {
- throw new ParserException(
- constructListenerErrorMessage(MISSING_CURRENT_HOLDER, BIT_DATA, ctx.identifier().getText(), EXIT));
- }
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/BitsListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/BitsListener.java
deleted file mode 100644
index a476902..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/BitsListener.java
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-/*
- * Reference: RFC6020 and YANG ANTLR Grammar
- *
- * ABNF grammar as per RFC6020
- * type-body-stmts = numerical-restrictions /
- * decimal64-specification /
- * string-restrictions /
- * enum-specification /
- * leafref-specification /
- * identityref-specification /
- * instance-identifier-specification /
- * bits-specification /
- * union-specification
- *
- * bits-specification = 1*(bit-stmt stmtsep)
- *
- * ANTLR grammar rule
- *
- * typeBodyStatements : numericalRestrictions | stringRestrictions | enumSpecification
- * | leafrefSpecification | identityrefSpecification | instanceIdentifierSpecification
- * | bitsSpecification | unionSpecification;
- *
- * bitsSpecification : bitStatement+;
- */
-
-import org.onosproject.yangutils.datamodel.YangBits;
-import org.onosproject.yangutils.datamodel.YangLeaf;
-import org.onosproject.yangutils.datamodel.YangLeafList;
-import org.onosproject.yangutils.datamodel.YangType;
-import org.onosproject.yangutils.datamodel.YangTypeDef;
-import org.onosproject.yangutils.datamodel.YangUnion;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.BITS_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.TYPE_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.INVALID_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-
-/**
- * Represents listener based call back function corresponding to the "bits" rule
- * defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
- */
-public final class BitsListener {
-
- /**
- * Creates a new bits listener.
- */
- private BitsListener() {
- }
-
- /**
- * It is called when parser enters grammar rule (bits), it perform
- * validations and updates the data model tree.
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processBitsEntry(TreeWalkListener listener,
- GeneratedYangParser.BitsSpecificationContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, BITS_DATA, "", ENTRY);
-
- if (listener.getParsedDataStack().peek() instanceof YangType) {
- YangBits bitsNode = new YangBits();
-
- bitsNode.setLineNumber(ctx.getStart().getLine());
- bitsNode.setCharPosition(ctx.getStart().getCharPositionInLine());
- bitsNode.setFileName(listener.getFileName());
- Parsable typeData = listener.getParsedDataStack().pop();
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, BITS_DATA, "", ENTRY);
-
- Parsable tmpData = listener.getParsedDataStack().peek();
-
- switch (tmpData.getYangConstructType()) {
- case LEAF_DATA:
- bitsNode.setBitsName(((YangLeaf) tmpData).getName());
- break;
- case LEAF_LIST_DATA:
- bitsNode.setBitsName(((YangLeafList) tmpData).getName());
- break;
- case TYPEDEF_DATA:
- bitsNode.setBitsName(((YangTypeDef) tmpData).getName());
- break;
- case UNION_DATA:
- bitsNode.setBitsName(((YangUnion) tmpData).getName());
- break;
- // TODO typedef, union, deviate.
- default:
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, TYPE_DATA,
- ((YangType<?>) typeData).getDataTypeName(), ENTRY));
- }
- listener.getParsedDataStack().push(typeData);
- listener.getParsedDataStack().push(bitsNode);
- } else {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, BITS_DATA, "", ENTRY));
- }
- }
-
- /**
- * It is called when parser exits from grammar rule (bits), it perform
- * validations and update the data model tree.
- *
- * @param listener Listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processBitsExit(TreeWalkListener listener,
- GeneratedYangParser.BitsSpecificationContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, BITS_DATA, "", EXIT);
-
- Parsable tmpBitsNode = listener.getParsedDataStack().peek();
- if (tmpBitsNode instanceof YangBits) {
- YangBits bitsNode = (YangBits) tmpBitsNode;
- listener.getParsedDataStack().pop();
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, BITS_DATA, "", EXIT);
-
- Parsable tmpNode = listener.getParsedDataStack().peek();
- switch (tmpNode.getYangConstructType()) {
- case TYPE_DATA: {
- YangType<YangBits> typeNode = (YangType<YangBits>) tmpNode;
- typeNode.setDataTypeExtendedInfo(bitsNode);
- break;
- }
- default:
- throw new ParserException(
- constructListenerErrorMessage(INVALID_HOLDER, BITS_DATA, "", EXIT));
- }
- } else {
- throw new ParserException(
- constructListenerErrorMessage(MISSING_CURRENT_HOLDER, BITS_DATA, "", EXIT));
- }
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/CaseListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/CaseListener.java
deleted file mode 100644
index f3803da..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/CaseListener.java
+++ /dev/null
@@ -1,161 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-import org.onosproject.yangutils.datamodel.YangAugment;
-import org.onosproject.yangutils.datamodel.YangCase;
-import org.onosproject.yangutils.datamodel.YangChoice;
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.CASE_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.DESCRIPTION_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.REFERENCE_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.STATUS_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.WHEN_DATA;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil;
-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.constructExtendedListenerErrorMessage;
-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_CURRENT_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne;
-import static org.onosproject.yangutils.translator.tojava.YangDataModelFactory.getYangCaseNode;
-
-/*
- * Reference: RFC6020 and YANG ANTLR Grammar
- *
- * ABNF grammar as per RFC6020
- * case-stmt = case-keyword sep identifier-arg-str optsep
- * (";" /
- * "{" stmtsep
- * ;; these stmts can appear in any order
- * [when-stmt stmtsep]
- * *(if-feature-stmt stmtsep)
- * [status-stmt stmtsep]
- * [description-stmt stmtsep]
- * [reference-stmt stmtsep]
- * *(data-def-stmt stmtsep)
- * "}")
- *
- * ANTLR grammar rule
- * caseStatement : CASE_KEYWORD identifier (STMTEND | LEFT_CURLY_BRACE (whenStatement | ifFeatureStatement
- * | statusStatement | descriptionStatement | referenceStatement | dataDefStatement)* RIGHT_CURLY_BRACE);
- */
-
-/**
- * Represents listener based call back function corresponding to the "case" rule
- * defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
- */
-public final class CaseListener {
-
- /**
- * Create a new case listener.
- */
- private CaseListener() {
- }
-
- /**
- * It is called when parser enters grammar rule (case), it perform
- * validations and updates the data model tree.
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processCaseEntry(TreeWalkListener listener,
- GeneratedYangParser.CaseStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, CASE_DATA, ctx.identifier().getText(), ENTRY);
-
- // Check validity of identifier and remove double quotes.
- String identifier = getValidIdentifier(ctx.identifier().getText(), CASE_DATA, ctx);
-
- // Validate sub statement cardinality.
- validateSubStatementsCardinality(ctx);
-
- Parsable curData = listener.getParsedDataStack().peek();
-
- // Check for identifier collision
- int line = ctx.getStart().getLine();
- int charPositionInLine = ctx.getStart().getCharPositionInLine();
- detectCollidingChildUtil(listener, line, charPositionInLine, identifier, CASE_DATA);
-
- if (curData instanceof YangChoice || curData instanceof YangAugment) {
- YangCase caseNode = getYangCaseNode(JAVA_GENERATION);
- caseNode.setName(identifier);
- caseNode.setLineNumber(line);
- caseNode.setCharPosition(charPositionInLine);
- caseNode.setFileName(listener.getFileName());
- YangNode curNode = (YangNode) curData;
- try {
- curNode.addChild(caseNode);
- } catch (DataModelException e) {
- throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
- CASE_DATA, ctx.identifier().getText(), ENTRY, e.getMessage()));
- }
- listener.getParsedDataStack().push(caseNode);
- } else {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, CASE_DATA,
- ctx.identifier().getText(), ENTRY));
- }
- }
-
- /**
- * It is called when parser exits from grammar rule (case), it perform
- * validations and update the data model tree.
- *
- * @param listener Listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processCaseExit(TreeWalkListener listener,
- GeneratedYangParser.CaseStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, CASE_DATA, ctx.identifier().getText(), EXIT);
-
- if (listener.getParsedDataStack().peek() instanceof YangCase) {
- listener.getParsedDataStack().pop();
- } else {
- throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, CASE_DATA,
- ctx.identifier().getText(), EXIT));
- }
- }
-
- /**
- * Validates the cardinality of case sub-statements as per grammar.
- *
- * @param ctx context object of the grammar rule
- */
- private static void validateSubStatementsCardinality(GeneratedYangParser.CaseStatementContext ctx) {
-
- validateCardinalityMaxOne(ctx.whenStatement(), WHEN_DATA, CASE_DATA, ctx.identifier().getText());
- validateCardinalityMaxOne(ctx.statusStatement(), STATUS_DATA, CASE_DATA, ctx.identifier().getText());
- validateCardinalityMaxOne(ctx.descriptionStatement(), DESCRIPTION_DATA, CASE_DATA, ctx.identifier().getText());
- validateCardinalityMaxOne(ctx.referenceStatement(), REFERENCE_DATA, CASE_DATA, ctx.identifier().getText());
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ChoiceListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ChoiceListener.java
deleted file mode 100644
index 00b9973..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ChoiceListener.java
+++ /dev/null
@@ -1,202 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-import org.onosproject.yangutils.datamodel.YangAugment;
-import org.onosproject.yangutils.datamodel.YangCase;
-import org.onosproject.yangutils.datamodel.YangChoice;
-import org.onosproject.yangutils.datamodel.YangContainer;
-import org.onosproject.yangutils.datamodel.YangGrouping;
-import org.onosproject.yangutils.datamodel.YangInput;
-import org.onosproject.yangutils.datamodel.YangList;
-import org.onosproject.yangutils.datamodel.YangModule;
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.YangNotification;
-import org.onosproject.yangutils.datamodel.YangOutput;
-import org.onosproject.yangutils.datamodel.YangSubModule;
-import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-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.ListenerValidation;
-
-import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.CHOICE_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.CONFIG_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.DEFAULT_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.DESCRIPTION_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.MANDATORY_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.REFERENCE_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.STATUS_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.WHEN_DATA;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil;
-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.constructExtendedListenerErrorMessage;
-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.INVALID_CONTENT;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne;
-import static org.onosproject.yangutils.translator.tojava.YangDataModelFactory.getYangChoiceNode;
-
-/*
- * Reference: RFC6020 and YANG ANTLR Grammar
- *
- * ABNF grammar as per RFC6020
- * choice-stmt = choice-keyword sep identifier-arg-str optsep
- * (";" /
- * "{" stmtsep
- * ;; these stmts can appear in any order
- * [when-stmt stmtsep]
- * *(if-feature-stmt stmtsep)
- * [default-stmt stmtsep]
- * [config-stmt stmtsep]
- * [mandatory-stmt stmtsep]
- * [status-stmt stmtsep]
- * [description-stmt stmtsep]
- * [reference-stmt stmtsep]
- * *((short-case-stmt / case-stmt) stmtsep)
- * "}")
- *
- * ANTLR grammar rule
- * choiceStatement : CHOICE_KEYWORD identifier (STMTEND | LEFT_CURLY_BRACE (whenStatement | ifFeatureStatement
- * | defaultStatement | configStatement | mandatoryStatement | statusStatement | descriptionStatement
- * | referenceStatement | shortCaseStatement | caseStatement)* RIGHT_CURLY_BRACE);
- */
-
-/**
- * Represents listener based call back function corresponding to the "choice"
- * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
- */
-public final class ChoiceListener {
-
- /**
- * Create a new choice listener.
- */
- private ChoiceListener() {
- }
-
- /**
- * It is called when parser receives an input matching the grammar rule
- * (choice), perform validations and update the data model tree.
- *
- * @param listener Listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processChoiceEntry(TreeWalkListener listener,
- GeneratedYangParser.ChoiceStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, CHOICE_DATA, ctx.identifier().getText(), ENTRY);
-
- // Check validity of identifier and remove double quotes.
- String identifier = getValidIdentifier(ctx.identifier().getText(), CHOICE_DATA, ctx);
-
- // Validate sub statement cardinality.
- validateSubStatementsCardinality(ctx);
-
- Parsable curData = listener.getParsedDataStack().peek();
-
- // Check for identifier collision
- int line = ctx.getStart().getLine();
- int charPositionInLine = ctx.getStart().getCharPositionInLine();
- detectCollidingChildUtil(listener, line, charPositionInLine, identifier, CHOICE_DATA);
-
- if (curData instanceof YangModule || curData instanceof YangSubModule || curData instanceof YangContainer
- || curData instanceof YangList || curData instanceof YangCase || curData instanceof YangGrouping
- || curData instanceof YangAugment || curData instanceof YangInput || curData instanceof YangOutput
- || curData instanceof YangNotification) {
-
- YangChoice choiceNode = getYangChoiceNode(JAVA_GENERATION);
- choiceNode.setName(identifier);
- choiceNode.setLineNumber(line);
- choiceNode.setCharPosition(charPositionInLine);
- choiceNode.setFileName(listener.getFileName());
- /*
- * If "config" is not specified, the default is the same as the parent
- * schema node's "config" value.
- */
- if (ctx.configStatement().isEmpty()) {
- boolean parentConfig = ListenerValidation.getParentNodeConfig(listener);
- choiceNode.setConfig(parentConfig);
- }
-
- YangNode curNode = (YangNode) curData;
- try {
- curNode.addChild(choiceNode);
- } catch (DataModelException e) {
- throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
- CHOICE_DATA, ctx.identifier().getText(), ENTRY, e.getMessage()));
- }
- listener.getParsedDataStack().push(choiceNode);
- } else {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER,
- CHOICE_DATA, ctx.identifier().getText(), ENTRY));
- }
- }
-
- /**
- * It is called when parser exits from grammar rule (choice), it perform
- * validations and update the data model tree.
- *
- * @param listener Listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processChoiceExit(TreeWalkListener listener,
- GeneratedYangParser.ChoiceStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, CHOICE_DATA, ctx.identifier().getText(), EXIT);
-
- if (listener.getParsedDataStack().peek() instanceof YangChoice) {
- YangChoice choiceNode = (YangChoice) listener.getParsedDataStack().peek();
- try {
- choiceNode.validateDataOnExit();
- } catch (DataModelException e) {
- throw new ParserException(constructListenerErrorMessage(INVALID_CONTENT, CHOICE_DATA,
- ctx.identifier().getText(), EXIT));
- }
- listener.getParsedDataStack().pop();
- } else {
- throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, CHOICE_DATA,
- ctx.identifier().getText(), EXIT));
- }
- }
-
- /**
- * Validates the cardinality of choice sub-statements as per grammar.
- *
- * @param ctx context object of the grammar rule.
- */
- private static void validateSubStatementsCardinality(GeneratedYangParser.ChoiceStatementContext ctx) {
-
- validateCardinalityMaxOne(ctx.whenStatement(), WHEN_DATA, CHOICE_DATA, ctx.identifier().getText());
- validateCardinalityMaxOne(ctx.defaultStatement(), DEFAULT_DATA, CHOICE_DATA, ctx.identifier().getText());
- validateCardinalityMaxOne(ctx.configStatement(), CONFIG_DATA, CHOICE_DATA, ctx.identifier().getText());
- validateCardinalityMaxOne(ctx.mandatoryStatement(), MANDATORY_DATA, CHOICE_DATA, ctx.identifier().getText());
- validateCardinalityMaxOne(ctx.statusStatement(), STATUS_DATA, CHOICE_DATA, ctx.identifier().getText());
- validateCardinalityMaxOne(ctx.descriptionStatement(), DESCRIPTION_DATA, CHOICE_DATA,
- ctx.identifier().getText());
- validateCardinalityMaxOne(ctx.referenceStatement(), REFERENCE_DATA, CHOICE_DATA, ctx.identifier().getText());
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/CompilerAnnotationListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/CompilerAnnotationListener.java
deleted file mode 100644
index ed892b3..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/CompilerAnnotationListener.java
+++ /dev/null
@@ -1,154 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-import java.util.List;
-
-import org.onosproject.yangutils.datamodel.YangAtomicPath;
-import org.onosproject.yangutils.datamodel.YangCompilerAnnotation;
-import org.onosproject.yangutils.datamodel.YangModule;
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.YangSubModule;
-import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.linker.impl.YangResolutionInfoImpl;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.addResolutionInfo;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.COMPILER_ANNOTATION_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.constructExtendedListenerErrorMessage;
-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.ListenerErrorType.MISSING_CURRENT_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidAbsoluteSchemaNodeId;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidPrefix;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.removeQuotesAndHandleConcat;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-
-/*
- * Reference: RFC6020 and YANG ANTLR Grammar
- *
- * ABNF grammar as per RFC6020
- * compiler-annotation-stmt = prefix:compiler-annotation-keyword string
- * "{"
- * [app-data-structure-stmt stmtsep]
- * [app-extended-stmt stmtsep]
- * "}"
- *
- * ANTLR grammar rule
- * compilerAnnotationStatement : COMPILER_ANNOTATION string LEFT_CURLY_BRACE
- * compilerAnnotationBodyStatement RIGHT_CURLY_BRACE;
- *
- * compilerAnnotationBodyStatement : appDataStructureStatement? appExtendedStatement? ;
- */
-
-/**
- * Represents listener based call back function corresponding to the "compiler-annotation"
- * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
- */
-public final class CompilerAnnotationListener {
-
- /**
- * Creates a new compiler-annotation listener.
- */
- private CompilerAnnotationListener() {
- }
-
- /**
- * Performs validation and updates the data model tree. It is called when parser receives an
- * input matching the grammar rule(compiler-annotation).
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processCompilerAnnotationEntry(TreeWalkListener listener,
- GeneratedYangParser.CompilerAnnotationStatementContext ctx) {
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, COMPILER_ANNOTATION_DATA, ctx.string().getText(), ENTRY);
- String prefix = getValidPrefix(ctx.COMPILER_ANNOTATION().getText(), COMPILER_ANNOTATION_DATA, ctx);
-
- YangCompilerAnnotation compilerAnnotation = new YangCompilerAnnotation();
- compilerAnnotation.setPrefix(prefix);
- compilerAnnotation.setPath(removeQuotesAndHandleConcat(ctx.string().getText()));
-
- compilerAnnotation.setLineNumber(ctx.getStart().getLine());
- compilerAnnotation.setCharPosition(ctx.getStart().getCharPositionInLine());
- compilerAnnotation.setFileName(listener.getFileName());
- // Validate augment argument string
- List<YangAtomicPath> targetNodes = getValidAbsoluteSchemaNodeId(ctx.string().getText(),
- COMPILER_ANNOTATION_DATA, ctx);
-
- compilerAnnotation.setAtomicPathList(targetNodes);
-
- int line = ctx.getStart().getLine();
- int charPositionInLine = ctx.getStart().getCharPositionInLine();
-
- Parsable curData = listener.getParsedDataStack().peek();
- if (!(curData instanceof YangModule || curData instanceof YangSubModule)) {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, COMPILER_ANNOTATION_DATA,
- ctx.string().getText(), ENTRY));
- }
-
- // Add resolution information to the list
- YangResolutionInfoImpl resolutionInfo = new YangResolutionInfoImpl<YangCompilerAnnotation>(
- compilerAnnotation, (YangNode) curData, line, charPositionInLine);
- addToResolutionList(resolutionInfo, ctx);
-
- listener.getParsedDataStack().push(compilerAnnotation);
- }
-
- /**
- * Performs validation and updates the data model tree. It is called when parser
- * exits from grammar rule (compiler-annotation).
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processCompilerAnnotationExit(TreeWalkListener listener,
- GeneratedYangParser.CompilerAnnotationStatementContext ctx) {
-
- checkStackIsNotEmpty(listener, MISSING_HOLDER, COMPILER_ANNOTATION_DATA, ctx.string().getText(), EXIT);
- if (!(listener.getParsedDataStack().peek() instanceof YangCompilerAnnotation)) {
- throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, COMPILER_ANNOTATION_DATA,
- ctx.string().getText(), EXIT));
- }
- listener.getParsedDataStack().pop();
- }
-
- /**
- * Adds to resolution list.
- *
- * @param resolutionInfo resolution information.
- * @param ctx context object of the grammar rule
- */
- private static void addToResolutionList(YangResolutionInfoImpl<YangCompilerAnnotation> resolutionInfo,
- GeneratedYangParser.CompilerAnnotationStatementContext ctx) {
-
- try {
- addResolutionInfo(resolutionInfo);
- } catch (DataModelException e) {
- throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
- COMPILER_ANNOTATION_DATA, ctx.COMPILER_ANNOTATION().getText(), ENTRY, e.getMessage()));
- }
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ConfigListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ConfigListener.java
deleted file mode 100644
index d595cb0..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ConfigListener.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-import org.onosproject.yangutils.datamodel.YangContainer;
-import org.onosproject.yangutils.datamodel.YangLeaf;
-import org.onosproject.yangutils.datamodel.YangLeafList;
-import org.onosproject.yangutils.datamodel.YangList;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.CONFIG_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.ListenerUtil.getValidBooleanValue;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-
-/*
- * Reference: RFC6020 and YANG ANTLR Grammar
- *
- * ABNF grammar as per RFC6020
- * config-stmt = config-keyword sep
- * config-arg-str stmtend
- * config-arg-str = < a string that matches the rule
- * config-arg >
- * config-arg = true-keyword / false-keyword
- *
- * ANTLR grammar rule
- * configStatement : CONFIG_KEYWORD config STMTEND;
- * config : string;
- */
-
-/**
- * Represents listener based call back function corresponding to the "config"
- * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
- */
-public final class ConfigListener {
-
- /**
- * Creates a new config listener.
- */
- private ConfigListener() {
- }
-
- /**
- * It is called when parser receives an input matching the grammar rule
- * (config), performs validation and updates the data model tree.
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processConfigEntry(TreeWalkListener listener,
- GeneratedYangParser.ConfigStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, CONFIG_DATA, "", ENTRY);
-
- boolean isConfig = getValidBooleanValue(ctx.config().getText(), CONFIG_DATA, ctx);
-
- Parsable tmpData = listener.getParsedDataStack().peek();
- switch (tmpData.getYangConstructType()) {
- case LEAF_DATA:
- YangLeaf leaf = (YangLeaf) tmpData;
- leaf.setConfig(isConfig);
- break;
- case CONTAINER_DATA:
- YangContainer container = (YangContainer) tmpData;
- container.setConfig(isConfig);
- break;
- case LEAF_LIST_DATA:
- YangLeafList leafList = (YangLeafList) tmpData;
- leafList.setConfig(isConfig);
- break;
- case LIST_DATA:
- YangList yangList = (YangList) tmpData;
- yangList.setConfig(isConfig);
- break;
- case CHOICE_DATA: // TODO
- break;
- default:
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, CONFIG_DATA, "", ENTRY));
- }
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ContactListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ContactListener.java
deleted file mode 100644
index 4cab95d..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ContactListener.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-import org.onosproject.yangutils.datamodel.YangModule;
-import org.onosproject.yangutils.datamodel.YangSubModule;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.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
- *
- * ABNF grammar as per RFC6020
- * meta-stmts = ;; these stmts can appear in any order
- * [organization-stmt stmtsep]
- * [contact-stmt stmtsep]
- * [description-stmt stmtsep]
- * [reference-stmt stmtsep]
- * contact-stmt = contact-keyword sep string optsep stmtend
- *
- * ANTLR grammar rule
- * meta_stmts : organization_stmt? contact_stmt? description_stmt? reference_stmt?
- * | organization_stmt? contact_stmt? reference_stmt? description_stmt?
- * | organization_stmt? description_stmt? contact_stmt? reference_stmt?
- * | organization_stmt? description_stmt? reference_stmt? contact_stmt?
- * | organization_stmt? reference_stmt? contact_stmt? description_stmt?
- * | organization_stmt? reference_stmt? description_stmt? contact_stmt?
- * | contact_stmt? organization_stmt? description_stmt? reference_stmt?
- * | contact_stmt? organization_stmt? reference_stmt? description_stmt?
- * | contact_stmt? reference_stmt? organization_stmt? description_stmt?
- * | contact_stmt? reference_stmt? description_stmt? organization_stmt?
- * | contact_stmt? description_stmt? reference_stmt? organization_stmt?
- * | contact_stmt? description_stmt? organization_stmt? reference_stmt?
- * | reference_stmt? contact_stmt? organization_stmt? description_stmt?
- * | reference_stmt? contact_stmt? description_stmt? organization_stmt?
- * | reference_stmt? organization_stmt? contact_stmt? description_stmt?
- * | reference_stmt? organization_stmt? description_stmt? contact_stmt?
- * | reference_stmt? description_stmt? organization_stmt? contact_stmt?
- * | reference_stmt? description_stmt? contact_stmt? organization_stmt?
- * | description_stmt? reference_stmt? contact_stmt? organization_stmt?
- * | description_stmt? reference_stmt? organization_stmt? contact_stmt?
- * | description_stmt? contact_stmt? reference_stmt? organization_stmt?
- * | description_stmt? contact_stmt? organization_stmt? reference_stmt?
- * | description_stmt? organization_stmt? contact_stmt? reference_stmt?
- * | description_stmt? organization_stmt? reference_stmt? contact_stmt?
- * ;
- * contact_stmt : CONTACT_KEYWORD string STMTEND;
- */
-
-/**
- * Represents listener based call back function corresponding to the "contact"
- * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
- */
-public final class ContactListener {
-
- /**
- * Creates a new contact listener.
- */
- private ContactListener() {
- }
-
- /**
- * 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
- */
- public static void processContactEntry(TreeWalkListener listener, GeneratedYangParser.ContactStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, CONTACT_DATA, ctx.string().getText(), ENTRY);
-
- // Obtain the node of the stack.
- Parsable tmpNode = listener.getParsedDataStack().peek();
- switch (tmpNode.getYangConstructType()) {
- case MODULE_DATA: {
- YangModule module = (YangModule) tmpNode;
- module.setContact(ctx.string().getText());
- break;
- }
- case SUB_MODULE_DATA: {
- YangSubModule subModule = (YangSubModule) tmpNode;
- subModule.setContact(ctx.string().getText());
- break;
- }
- default:
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, CONTACT_DATA,
- ctx.string().getText(), ENTRY));
- }
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ContainerListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ContainerListener.java
deleted file mode 100644
index 7ea261b..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ContainerListener.java
+++ /dev/null
@@ -1,205 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-import org.onosproject.yangutils.datamodel.YangAugment;
-import org.onosproject.yangutils.datamodel.YangCase;
-import org.onosproject.yangutils.datamodel.YangContainer;
-import org.onosproject.yangutils.datamodel.YangGrouping;
-import org.onosproject.yangutils.datamodel.YangInput;
-import org.onosproject.yangutils.datamodel.YangList;
-import org.onosproject.yangutils.datamodel.YangModule;
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.YangNotification;
-import org.onosproject.yangutils.datamodel.YangOutput;
-import org.onosproject.yangutils.datamodel.YangSubModule;
-import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-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.ListenerValidation;
-
-import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.CONFIG_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.CONTAINER_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.DESCRIPTION_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.PRESENCE_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.REFERENCE_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.STATUS_DATA;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil;
-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
- .constructExtendedListenerErrorMessage;
-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_CURRENT_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne;
-import static org.onosproject.yangutils.translator.tojava.YangDataModelFactory.getYangContainerNode;
-
-/*
- * Reference: RFC6020 and YANG ANTLR Grammar
- *
- * ABNF grammar as per RFC6020
- * container-stmt = container-keyword sep identifier-arg-str optsep
- * (";" /
- * "{" stmtsep
- * ;; these stmts can appear in any order
- * [when-stmt stmtsep]
- * *(if-feature-stmt stmtsep)
- * *(must-stmt stmtsep)
- * [presence-stmt stmtsep]
- * [config-stmt stmtsep]
- * [status-stmt stmtsep]
- * [description-stmt stmtsep]
- * [reference-stmt stmtsep]
- * *((typedef-stmt /
- * grouping-stmt) stmtsep)
- * *(data-def-stmt stmtsep)
- * "}")
- *
- * ANTLR grammar rule
- * containerStatement : CONTAINER_KEYWORD identifier
- * (STMTEND | LEFT_CURLY_BRACE (whenStatement | ifFeatureStatement | mustStatement |
- * presenceStatement | configStatement | statusStatement | descriptionStatement |
- * referenceStatement | typedefStatement | groupingStatement
- * | dataDefStatement)* RIGHT_CURLY_BRACE);
- */
-
-/**
- * Represents listener based call back function corresponding to the "container"
- * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
- */
-public final class ContainerListener {
-
- /**
- * Creates a new container listener.
- */
- private ContainerListener() {
- }
-
- /**
- * It is called when parser receives an input matching the grammar rule
- * (container), performs validation and updates the data model tree.
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processContainerEntry(TreeWalkListener listener,
- GeneratedYangParser.ContainerStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, CONTAINER_DATA, ctx.identifier().getText(), ENTRY);
-
- String identifier = getValidIdentifier(ctx.identifier().getText(), CONTAINER_DATA, ctx);
-
- // Validate sub statement cardinality.
- validateSubStatementsCardinality(ctx);
-
- // Check for identifier collision
- int line = ctx.getStart().getLine();
- int charPositionInLine = ctx.getStart().getCharPositionInLine();
- detectCollidingChildUtil(listener, line, charPositionInLine, identifier, CONTAINER_DATA);
-
- YangContainer container = getYangContainerNode(JAVA_GENERATION);
- container.setName(identifier);
-
- container.setLineNumber(line);
- container.setCharPosition(charPositionInLine);
- container.setFileName(listener.getFileName());
- /*
- * If "config" is not specified, the default is the same as the parent
- * schema node's "config" value.
- */
- if (ctx.configStatement().isEmpty()) {
- boolean parentConfig = ListenerValidation.getParentNodeConfig(listener);
- container.setConfig(parentConfig);
- }
-
- Parsable curData = listener.getParsedDataStack().peek();
- if (curData instanceof YangModule || curData instanceof YangSubModule
- || curData instanceof YangContainer || curData instanceof YangList
- || curData instanceof YangCase || curData instanceof YangNotification
- || curData instanceof YangInput || curData instanceof YangOutput
- || curData instanceof YangAugment || curData instanceof YangGrouping) {
- YangNode curNode = (YangNode) curData;
- try {
- curNode.addChild(container);
- } catch (DataModelException e) {
- throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
- CONTAINER_DATA, ctx.identifier().getText(), ENTRY, e.getMessage()));
- }
- listener.getParsedDataStack().push(container);
- } else {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, CONTAINER_DATA,
- ctx.identifier().getText(), ENTRY));
- }
- }
-
- /**
- * It is called when parser exits from grammar rule (container), it perform
- * validations and updates the data model tree.
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processContainerExit(TreeWalkListener listener,
- GeneratedYangParser.ContainerStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, CONTAINER_DATA, ctx.identifier().getText(), EXIT);
-
- if (listener.getParsedDataStack().peek() instanceof YangContainer) {
- YangContainer yangContainer = (YangContainer) listener.getParsedDataStack().peek();
- try {
- yangContainer.validateDataOnExit();
- } catch (DataModelException e) {
- ParserException parserException = new ParserException(constructExtendedListenerErrorMessage(
- UNHANDLED_PARSED_DATA, CONTAINER_DATA, ctx.identifier().getText(), EXIT, e.getMessage()));
- parserException.setLine(ctx.getStart().getLine());
- parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
- throw parserException;
- }
- listener.getParsedDataStack().pop();
- } else {
- throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, CONTAINER_DATA,
- ctx.identifier().getText(), EXIT));
- }
- }
-
- /**
- * Validates the cardinality of container sub-statements as per grammar.
- *
- * @param ctx context object of the grammar rule
- */
- private static void validateSubStatementsCardinality(GeneratedYangParser.ContainerStatementContext ctx) {
-
- validateCardinalityMaxOne(ctx.presenceStatement(), PRESENCE_DATA, CONTAINER_DATA, ctx.identifier().getText());
- validateCardinalityMaxOne(ctx.configStatement(), CONFIG_DATA, CONTAINER_DATA, ctx.identifier().getText());
- validateCardinalityMaxOne(ctx.descriptionStatement(), DESCRIPTION_DATA, CONTAINER_DATA,
- ctx.identifier().getText());
- validateCardinalityMaxOne(ctx.referenceStatement(), REFERENCE_DATA, CONTAINER_DATA, ctx.identifier().getText());
- validateCardinalityMaxOne(ctx.statusStatement(), STATUS_DATA, CONTAINER_DATA, ctx.identifier().getText());
- // TODO validate 'when' cardinality
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/DataStructureKeyListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/DataStructureKeyListener.java
deleted file mode 100644
index 9cee91f..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/DataStructureKeyListener.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-import org.onosproject.yangutils.datamodel.YangAppDataStructure;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.KEY_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.ListenerUtil.removeQuotesAndHandleConcat;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
-
-/*
- * Reference: RFC6020 and YANG ANTLR Grammar
- *
- * ABNF grammar as per RFC6020
- * data-structure-key-stmt = prefix:key-keyword string ";"
- *
- * ANTLR grammar rule
- * dataStructureKeyStatement : DATA_STRUCTURE_KEY string STMTEND;
- */
-
-/**
- * Represents listener based call back function corresponding to the "key"
- * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
- */
-public final class DataStructureKeyListener {
-
- /**
- * Creates a new data-structure-key listener.
- */
- private DataStructureKeyListener() {
- }
-
- /**
- * Performs validation and updates the data model tree. It is called when parser receives an
- * input matching the grammar rule(key).
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processDataStructureKeyEntry(TreeWalkListener listener,
- GeneratedYangParser.DataStructureKeyStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, KEY_DATA, ctx.string().getText(), ENTRY);
-
- Parsable tmpData = listener.getParsedDataStack().peek();
- if (listener.getParsedDataStack().peek() instanceof YangAppDataStructure) {
- YangAppDataStructure dataStructure = (YangAppDataStructure) tmpData;
-
- dataStructure.setLineNumber(ctx.getStart().getLine());
- dataStructure.setCharPosition(ctx.getStart().getCharPositionInLine());
- dataStructure.setFileName(listener.getFileName());
- String tmpKeyValue = removeQuotesAndHandleConcat(ctx.string().getText());
- if (tmpKeyValue.contains(SPACE)) {
- String[] keyValues = tmpKeyValue.split(SPACE);
- for (String keyValue : keyValues) {
- dataStructure.addKey(keyValue);
- }
- } else {
- dataStructure.addKey(tmpKeyValue);
- }
- } else {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, KEY_DATA, ctx.string().getText(),
- ENTRY));
- }
- }
-}
-
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/Decimal64Listener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/Decimal64Listener.java
deleted file mode 100644
index 14ae935..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/Decimal64Listener.java
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-/*
- * Reference: RFC6020 and YANG ANTLR Grammar
- *
- * ABNF grammar as per RFC6020
- * type-body-stmts = numerical-restrictions /
- * decimal64-specification /
- * string-restrictions /
- * enum-specification /
- * leafref-specification /
- * identityref-specification /
- * instance-identifier-specification /
- * bits-specification /
- * union-specification
- *
- * decimal64-specification = fraction-digits-stmt [range-stmt stmtsep]
- *
- * fraction-digits-stmt = fraction-digits-keyword sep
- * fraction-digits-arg-str stmtend
- *
- * fraction-digits-arg-str = < a string that matches the rule
- * fraction-digits-arg >
- *
- * fraction-digits-arg = ("1" ["0" / "1" / "2" / "3" / "4" /
- * "5" / "6" / "7" / "8"])
- * / "2" / "3" / "4" / "5" / "6" / "7" / "8" / "9"
- *
- * range-stmt = range-keyword sep range-arg-str optsep
- * (";" /
- * "{" stmtsep
- * ;; these stmts can appear in any order
- * [error-message-stmt stmtsep]
- * [error-app-tag-stmt stmtsep]
- * [description-stmt stmtsep]
- * [reference-stmt stmtsep]
- * "}")
- * ANTLR grammar rule
- *
- * typeBodyStatements : numericalRestrictions | decimal64Specification | stringRestrictions | enumSpecification
- * | leafrefSpecification | identityrefSpecification | instanceIdentifierSpecification
- * | bitsSpecification | unionSpecification;
- *
- * decimal64Specification : fractionDigitStatement rangeStatement?;
- *
- * fractionDigitStatement : FRACTION_DIGITS_KEYWORD fraction STMTEND;
- *
- * fraction : string;
- */
-
-import org.onosproject.yangutils.datamodel.YangDecimal64;
-import org.onosproject.yangutils.datamodel.YangRangeRestriction;
-import org.onosproject.yangutils.datamodel.YangType;
-import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.DECIMAL64_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.INVALID_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-
-/**
- * Represents listener based call back function corresponding to the "decimal64" rule
- * defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
- */
-public final class Decimal64Listener {
-
- /**
- * Creates a new Decimal64 listener.
- */
- private Decimal64Listener() {
- }
-
- /**
- * It is called when parser enters grammar rule (decimal64), it perform
- * validations and updates the data model tree.
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processDecimal64Entry(TreeWalkListener listener,
- GeneratedYangParser.Decimal64SpecificationContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, DECIMAL64_DATA, "", ENTRY);
-
- Parsable tmpNode = listener.getParsedDataStack().peek();
- if (tmpNode instanceof YangType) {
- YangType<YangDecimal64<YangRangeRestriction>> typeNode =
- (YangType<YangDecimal64<YangRangeRestriction>>) tmpNode;
- YangDecimal64 decimal64Node = new YangDecimal64();
- typeNode.setDataTypeExtendedInfo(decimal64Node);
-
- decimal64Node.setLineNumber(ctx.getStart().getLine());
- decimal64Node.setCharPosition(ctx.getStart().getCharPositionInLine());
- decimal64Node.setFileName(listener.getFileName());
- } else {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, DECIMAL64_DATA, "", ENTRY));
- }
- }
-
- /**
- * Performs validation and updates the data model tree.
- * It is called when parser exits from grammar rule (decimal64).
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processDecimal64Exit(TreeWalkListener listener,
- GeneratedYangParser.Decimal64SpecificationContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, DECIMAL64_DATA, "", EXIT);
-
- Parsable tmpNode = listener.getParsedDataStack().peek();
- if (tmpNode instanceof YangType) {
- YangType<YangDecimal64<YangRangeRestriction>> typeNode =
- (YangType<YangDecimal64<YangRangeRestriction>>) tmpNode;
- YangDecimal64<YangRangeRestriction> decimal64Node = typeNode.getDataTypeExtendedInfo();
- try {
- decimal64Node.validateRange();
- } catch (DataModelException e) {
- throw new ParserException(e);
- }
- } else {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, DECIMAL64_DATA, "", EXIT));
- }
- }
-}
\ No newline at end of file
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/DefaultListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/DefaultListener.java
deleted file mode 100644
index b93fe52..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/DefaultListener.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-/*
- * Reference: RFC6020 and YANG ANTLR Grammar
- *
- * typedef-stmt = typedef-keyword sep identifier-arg-str optsep
- * "{" stmtsep
- * ;; these stmts can appear in any order
- * type-stmt stmtsep
- * [units-stmt stmtsep]
- * [default-stmt stmtsep]
- * [status-stmt stmtsep]
- * [description-stmt stmtsep]
- * [reference-stmt stmtsep]
- * "}"
- * default-stmt = default-keyword sep string stmtend
-
- *
- * ANTLR grammar rule
- * typedefStatement : TYPEDEF_KEYWORD IDENTIFIER LEFT_CURLY_BRACE
- * (typeStatement | unitsStatement | defaultStatement | statusStatement
- * | descriptionStatement | referenceStatement)* RIGHT_CURLY_BRACE;
- * defaultStatement : DEFAULT_KEYWORD string STMTEND;
- */
-
-import org.onosproject.yangutils.datamodel.YangChoice;
-import org.onosproject.yangutils.datamodel.YangLeaf;
-import org.onosproject.yangutils.datamodel.YangTypeDef;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.DEFAULT_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.ListenerUtil.removeQuotesAndHandleConcat;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-
-/**
- * Represents listener for default YANG statement.
- */
-public final class DefaultListener {
-
- /**
- * Creates a new default listener.
- */
- private DefaultListener() {
- }
-
- /**
- * It is called when parser enters grammar rule (default), it perform
- * validations and updates the data model tree.
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processDefaultEntry(TreeWalkListener listener,
- GeneratedYangParser.DefaultStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, DEFAULT_DATA, ctx.string().getText(), ENTRY);
-
- Parsable tmpNode = listener.getParsedDataStack().peek();
- switch (tmpNode.getYangConstructType()) {
- case TYPEDEF_DATA: {
- YangTypeDef typeDef = (YangTypeDef) tmpNode;
- typeDef.setDefaultValueInString(removeQuotesAndHandleConcat(ctx.string().getText()));
- break;
- }
- case LEAF_DATA: {
- YangLeaf leaf = (YangLeaf) tmpNode;
- leaf.setDefaultValueInString(removeQuotesAndHandleConcat(ctx.string().getText()));
- break;
- }
- case CHOICE_DATA: {
- YangChoice choice = (YangChoice) tmpNode;
- choice.setDefaultValueInString(removeQuotesAndHandleConcat(ctx.string().getText()));
- break;
- }
- default:
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER,
- DEFAULT_DATA, ctx.string().getText(), ENTRY));
- }
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/DescriptionListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/DescriptionListener.java
deleted file mode 100644
index c7988a8..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/DescriptionListener.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-import org.onosproject.yangutils.datamodel.YangDesc;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.DESCRIPTION_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
- *
- * ABNF grammar as per RFC6020
- * description-stmt = description-keyword sep string optsep stmtend
- *
- * ANTLR grammar rule
- * descriptionStatement : DESCRIPTION_KEYWORD string STMTEND;
- */
-
-/**
- * Represents listener based call back function corresponding to the
- * "description" rule defined in ANTLR grammar file for corresponding ABNF rule
- * in RFC 6020.
- */
-public final class DescriptionListener {
-
- /**
- * Creates a new description listener.
- */
- private DescriptionListener() {
- }
-
- /**
- * It is called when parser receives an input matching the grammar rule
- * (description), perform validations and updates the data model tree.
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processDescriptionEntry(TreeWalkListener listener,
- GeneratedYangParser.DescriptionStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, DESCRIPTION_DATA, ctx.string().getText(), ENTRY);
-
- Parsable tmpData = listener.getParsedDataStack().peek();
- if (tmpData instanceof YangDesc) {
- YangDesc description = (YangDesc) tmpData;
- description.setDescription(ctx.string().getText());
- } else {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, DESCRIPTION_DATA,
- ctx.string().getText(), ENTRY));
- }
- }
-}
\ No newline at end of file
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/EnumListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/EnumListener.java
deleted file mode 100644
index b0beef5..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/EnumListener.java
+++ /dev/null
@@ -1,190 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-/*
- * Reference: RFC6020 and YANG ANTLR Grammar
- *
- * ABNF grammar as per RFC6020
- * enum-stmt = enum-keyword sep string optsep
- * (";" /
- * "{" stmtsep
- * ;; these stmts can appear in any order
- * [value-stmt stmtsep]
- * [status-stmt stmtsep]
- * [description-stmt stmtsep]
- * [reference-stmt stmtsep]
- * "}")
- *
- * ANTLR grammar rule
- * enumStatement : ENUM_KEYWORD string (STMTEND | LEFT_CURLY_BRACE enumStatementBody RIGHT_CURLY_BRACE);
- *
- * enumStatementBody : valueStatement? statusStatement? descriptionStatement? referenceStatement?
- * | valueStatement? statusStatement? referenceStatement? descriptionStatement?
- * | valueStatement? descriptionStatement? statusStatement? referenceStatement?
- * | valueStatement? descriptionStatement? referenceStatement? statusStatement?
- * | valueStatement? referenceStatement? statusStatement? descriptionStatement?
- * | valueStatement? referenceStatement? descriptionStatement? statusStatement?
- * | statusStatement? valueStatement? descriptionStatement? referenceStatement?
- * | statusStatement? valueStatement? referenceStatement? descriptionStatement?
- * | statusStatement? descriptionStatement? descriptionStatement? valueStatement?
- * | statusStatement? descriptionStatement? valueStatement? descriptionStatement?
- * | statusStatement? referenceStatement? valueStatement? descriptionStatement?
- * | statusStatement? referenceStatement? descriptionStatement? valueStatement?
- * | descriptionStatement? valueStatement? statusStatement? referenceStatement?
- * | descriptionStatement? valueStatement? referenceStatement? statusStatement?
- * | descriptionStatement? statusStatement? valueStatement? referenceStatement?
- * | descriptionStatement? statusStatement? referenceStatement? valueStatement?
- * | descriptionStatement? referenceStatement? valueStatement? statusStatement?
- * | descriptionStatement? referenceStatement? statusStatement? valueStatement?
- * | referenceStatement? valueStatement? descriptionStatement? statusStatement?
- * | referenceStatement? valueStatement? statusStatement? descriptionStatement?
- * | referenceStatement? statusStatement? descriptionStatement? valueStatement?
- * | referenceStatement? statusStatement? valueStatement? descriptionStatement?
- * | referenceStatement? descriptionStatement? valueStatement? statusStatement?
- * | referenceStatement? descriptionStatement? statusStatement? valueStatement?
- * ;
- */
-
-import org.onosproject.yangutils.datamodel.YangEnum;
-import org.onosproject.yangutils.datamodel.YangEnumeration;
-import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.ENUM_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.constructExtendedListenerErrorMessage;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.DUPLICATE_ENTRY;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-import static org.onosproject.yangutils.utils.UtilConstants.QUOTES;
-import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
-
-/**
- * Represents listener based call back function corresponding to the "enum" rule
- * defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
- */
-public final class EnumListener {
-
- /**
- * Creates a new enum listener.
- */
- private EnumListener() {
- }
-
- /**
- * It is called when parser enters grammar rule (enum), it perform
- * validations and updates the data model tree.
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processEnumEntry(TreeWalkListener listener, GeneratedYangParser.EnumStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, ENUM_DATA, ctx.string().getText(), ENTRY);
-
- YangEnum enumNode = new YangEnum();
- enumNode.setNamedValue(getValidNamedValue(ctx.string().getText()));
-
- enumNode.setLineNumber(ctx.getStart().getLine());
- enumNode.setCharPosition(ctx.getStart().getCharPositionInLine());
- enumNode.setFileName(listener.getFileName());
- listener.getParsedDataStack().push(enumNode);
- }
-
- /*Removes quotes from the enum name if present.*/
- private static String getValidNamedValue(String name) {
- if (name.contains(QUOTES)) {
- name = name.replace(QUOTES, EMPTY_STRING);
- }
- return name;
- }
-
- /**
- * It is called when parser exits from grammar rule (enum), it perform
- * validations and update the data model tree.
- *
- * @param listener Listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processEnumExit(TreeWalkListener listener, GeneratedYangParser.EnumStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, ENUM_DATA, ctx.string().getText(), EXIT);
-
- Parsable tmpEnumNode = listener.getParsedDataStack().peek();
- if (tmpEnumNode instanceof YangEnum) {
- listener.getParsedDataStack().pop();
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, ENUM_DATA, ctx.string().getText(), EXIT);
-
- Parsable tmpNode = listener.getParsedDataStack().peek();
- switch (tmpNode.getYangConstructType()) {
- case ENUMERATION_DATA: {
- YangEnumeration yangEnumeration = (YangEnumeration) tmpNode;
- if (ctx.enumStatementBody() == null || ctx.enumStatementBody().valueStatement() == null) {
- int maxValue = 0;
- boolean isValuePresent = false;
-
- for (YangEnum curEnum : yangEnumeration.getEnumSet()) {
- if (curEnum.getValue() == Integer.MAX_VALUE) {
- ParserException parserException = new ParserException("YANG file error : "
- + "An enum value MUST be specified for enum substatements following the one"
- + "with the current highest value");
- parserException.setLine(ctx.getStart().getLine());
- parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
- throw parserException;
- } else if (maxValue <= curEnum.getValue()) {
- maxValue = curEnum.getValue();
- isValuePresent = true;
- }
- }
- if (isValuePresent) {
- maxValue++;
- }
- ((YangEnum) tmpEnumNode).setValue(maxValue);
- }
- try {
- yangEnumeration.addEnumInfo((YangEnum) tmpEnumNode);
- } catch (DataModelException e) {
- ParserException parserException = new ParserException(constructExtendedListenerErrorMessage(
- DUPLICATE_ENTRY, ENUM_DATA, ctx.string().getText(), EXIT, e.getMessage()));
- parserException.setLine(ctx.getStart().getLine());
- parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
- throw parserException;
- }
- break;
- }
- default:
- throw new ParserException(
- constructListenerErrorMessage(INVALID_HOLDER, ENUM_DATA, ctx.string().getText(), EXIT));
- }
- } else {
- throw new ParserException(
- constructListenerErrorMessage(MISSING_CURRENT_HOLDER, ENUM_DATA, ctx.string().getText(), EXIT));
- }
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/EnumerationListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/EnumerationListener.java
deleted file mode 100644
index 5eff217..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/EnumerationListener.java
+++ /dev/null
@@ -1,228 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-/*
- * Reference: RFC6020 and YANG ANTLR Grammar
- *
- * ABNF grammar as per RFC6020
- * type-body-stmts = numerical-restrictions /
- * decimal64-specification /
- * string-restrictions /
- * enum-specification /
- * leafref-specification /
- * identityref-specification /
- * instance-identifier-specification /
- * bits-specification /
- * union-specification
- *
- * enum-specification = 1*(enum-stmt stmtsep)
- *
- * ANTLR grammar rule
- *
- * typeBodyStatements : numericalRestrictions | stringRestrictions | enumSpecification
- * | leafrefSpecification | identityrefSpecification | instanceIdentifierSpecification
- * | bitsSpecification | unionSpecification;
- *
- * enumSpecification : enumStatement+;
- */
-
-import org.onosproject.yangutils.datamodel.YangEnumeration;
-import org.onosproject.yangutils.datamodel.YangLeaf;
-import org.onosproject.yangutils.datamodel.YangLeafList;
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.YangType;
-import org.onosproject.yangutils.datamodel.YangTypeDef;
-import org.onosproject.yangutils.datamodel.YangUnion;
-import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.datamodel.utils.YangConstructType;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.ENUMERATION_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.TYPE_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.constructExtendedListenerErrorMessage;
-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_CURRENT_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-import static org.onosproject.yangutils.translator.tojava.YangDataModelFactory.getYangEnumerationNode;
-
-/**
- * Represents listener based call back function corresponding to the
- * "enumeration" rule defined in ANTLR grammar file for corresponding ABNF rule
- * in RFC 6020.
- */
-public final class EnumerationListener {
-
- /**
- * Suffix to be used while creating enumeration class.
- */
- private static final String ENUMERATION_CLASS_SUFFIX = "_enum";
-
- /**
- * Creates a new enumeration listener.
- */
- private EnumerationListener() {
- }
-
- /**
- * It is called when parser enters grammar rule (enumeration), it perform
- * validations and updates the data model tree.
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processEnumerationEntry(TreeWalkListener listener,
- GeneratedYangParser.EnumSpecificationContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, ENUMERATION_DATA, "", ENTRY);
-
- if (listener.getParsedDataStack().peek() instanceof YangType) {
- YangEnumeration enumerationNode = getYangEnumerationNode(JAVA_GENERATION);
- enumerationNode.setLineNumber(ctx.getStart().getLine());
- enumerationNode.setCharPosition(ctx.getStart().getCharPositionInLine());
- enumerationNode.setFileName(listener.getFileName());
- Parsable typeData = listener.getParsedDataStack().pop();
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, ENUMERATION_DATA, "", ENTRY);
-
- Parsable tmpData = listener.getParsedDataStack().peek();
-
- switch (tmpData.getYangConstructType()) {
- case LEAF_DATA:
- // Set the name of enumeration same as leaf.
- enumerationNode.setName(((YangLeaf) tmpData).getName() + ENUMERATION_CLASS_SUFFIX);
- // Pop the stack entry to obtain the parent YANG node.
- Parsable leaf = listener.getParsedDataStack().pop();
- // Add the enumeration node to the parent holder of leaf.
- addChildToParentNode(listener, enumerationNode);
- // Push the popped entry back to the stack.
- listener.getParsedDataStack().push(leaf);
- break;
- case LEAF_LIST_DATA:
- // Set the name of enumeration same as leaf list.
- enumerationNode.setName(((YangLeafList) tmpData).getName() + ENUMERATION_CLASS_SUFFIX);
- // Pop the stack entry to obtain the parent YANG node.
- Parsable leafList = listener.getParsedDataStack().pop();
- // Add the enumeration node to the parent holder of leaf.
- addChildToParentNode(listener, enumerationNode);
- // Push the popped entry back to the stack.
- listener.getParsedDataStack().push(leafList);
- break;
- case UNION_DATA:
- YangUnion yangUnion = (YangUnion) tmpData;
- /*
- * In case parent of enumeration is a union, name of the
- * enumeration is parent union name suffixed with running
- * integer number, this is done because under union there
- * could be multiple child union types.
- */
- enumerationNode.setName(yangUnion.getName() + ENUMERATION_CLASS_SUFFIX
- + yangUnion.getChildUnionNumber());
- // Increment the running number.
- yangUnion.setChildUnionNumber(yangUnion.getChildUnionNumber() + 1);
- // Add union as a child to parent union.
- addChildToParentNode(listener, enumerationNode);
- break;
- case TYPEDEF_DATA:
- YangTypeDef typeDef = (YangTypeDef) tmpData;
- // Set the name of enumeration same as typedef name.
- enumerationNode.setName(typeDef.getName() + ENUMERATION_CLASS_SUFFIX);
- // Add enumeration as a child to parent type def.
- addChildToParentNode(listener, enumerationNode);
- break;
- // TODO deviate.
- default:
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, TYPE_DATA,
- ((YangType<?>) typeData).getDataTypeName(), ENTRY));
- }
- listener.getParsedDataStack().push(typeData);
- listener.getParsedDataStack().push(enumerationNode);
- } else {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, ENUMERATION_DATA, "", ENTRY));
- }
- }
-
- /**
- * It is called when parser exits from grammar rule (enumeration), it
- * perform validations and update the data model tree.
- *
- * @param listener Listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processEnumerationExit(TreeWalkListener listener,
- GeneratedYangParser.EnumSpecificationContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, ENUMERATION_DATA, "", EXIT);
-
- Parsable tmpEnumerationNode = listener.getParsedDataStack().peek();
- if (tmpEnumerationNode instanceof YangEnumeration) {
- YangEnumeration enumerationNode = (YangEnumeration) tmpEnumerationNode;
- listener.getParsedDataStack().pop();
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, ENUMERATION_DATA, "", EXIT);
-
- Parsable tmpNode = listener.getParsedDataStack().peek();
- switch (tmpNode.getYangConstructType()) {
- case TYPE_DATA: {
- YangType<YangEnumeration> typeNode = (YangType<YangEnumeration>) tmpNode;
- typeNode.setDataTypeExtendedInfo(enumerationNode);
- break;
- }
- default:
- throw new ParserException(
- constructListenerErrorMessage(INVALID_HOLDER, ENUMERATION_DATA, "", EXIT));
- }
- } else {
- throw new ParserException(
- constructListenerErrorMessage(MISSING_CURRENT_HOLDER, ENUMERATION_DATA, "", EXIT));
- }
- }
-
- /**
- * Adds the enumeration node to the parent holder.
- *
- * @param listener listener's object
- * @param enumerationNode enumeration node which needs to be added to parent
- */
- private static void addChildToParentNode(TreeWalkListener listener, YangEnumeration enumerationNode) {
- if (!(listener.getParsedDataStack().peek() instanceof YangNode)) {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, ENUMERATION_DATA,
- "", ENTRY));
- } else {
- YangNode curNode = (YangNode) listener.getParsedDataStack().peek();
- try {
- curNode.addChild(enumerationNode);
- } catch (DataModelException e) {
- throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
- YangConstructType.ENUMERATION_DATA, "", ENTRY, e.getMessage()));
- }
- }
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ErrorAppTagListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ErrorAppTagListener.java
deleted file mode 100644
index 64f718b..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ErrorAppTagListener.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-import org.onosproject.yangutils.datamodel.YangAppErrorHolder;
-import org.onosproject.yangutils.datamodel.YangAppErrorInfo;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.ERROR_APP_TAG_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.ListenerUtil.removeQuotesAndHandleConcat;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-
-/*
- * Reference: RFC 6020 and YANG ANTLR Grammar
- *
- * ABNF grammar as per RFC 6020
- *
- * error-app-tag-stmt = error-app-tag-keyword sep string stmtend
- *
- * ANTLR grammar rule
- * errorAppTagStatement : ERROR_APP_TAG_KEYWORD string STMTEND;
- */
-
-/**
- * Represents listener based call back function corresponding to the
- * error app tag defined in ANTLR grammar file for corresponding ABNF rule
- * in RFC 6020.
- */
-public final class ErrorAppTagListener {
-
- /**
- * Creates a new error app tag listener.
- */
- private ErrorAppTagListener() {
- }
-
- /**
- * Performs validations and updates the data model tree. It is called when parser
- * receives an input matching the grammar rule error app tag.
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processErrorAppTagMessageEntry(TreeWalkListener listener,
- GeneratedYangParser.ErrorAppTagStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, ERROR_APP_TAG_DATA, ctx.string().getText(), ENTRY);
- String errorMessage = removeQuotesAndHandleConcat(ctx.string().getText());
- // Obtain the node of the stack.
- Parsable tmpNode = listener.getParsedDataStack().peek();
- if (tmpNode instanceof YangAppErrorHolder) {
- YangAppErrorInfo yangAppErrorInfo = ((YangAppErrorHolder) tmpNode).getAppErrorInfo();
- yangAppErrorInfo.setErrorAppTag(errorMessage);
-
- yangAppErrorInfo.setLineNumber(ctx.getStart().getLine());
- yangAppErrorInfo.setCharPosition(ctx.getStart().getCharPositionInLine());
- yangAppErrorInfo.setFileName(listener.getFileName());
- } else {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, ERROR_APP_TAG_DATA,
- ctx.string().getText(), ENTRY));
- }
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ErrorMessageListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ErrorMessageListener.java
deleted file mode 100644
index ead1746..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ErrorMessageListener.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-import org.onosproject.yangutils.datamodel.YangAppErrorHolder;
-import org.onosproject.yangutils.datamodel.YangAppErrorInfo;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.ERROR_MESSAGE_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.ListenerUtil.removeQuotesAndHandleConcat;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-
-/*
- * Reference: RFC6020 and YANG ANTLR Grammar
- *
- * ABNF grammar as per RFC6020
- *
- * error-message-stmt = error-message-keyword sep string stmtend
- *
- * ANTLR grammar rule
- * errorMessageStatement : ERROR_MESSAGE_KEYWORD string STMTEND;
- */
-
-/**
- * Represents listener based call back function corresponding to the
- * app error message defined in ANTLR grammar file for corresponding ABNF rule
- * in RFC 6020.
- */
-public final class ErrorMessageListener {
-
- /**
- * Creates a new must listener.
- */
- private ErrorMessageListener() {
- }
-
- /**
- * Performs validations and updates the data model tree. It is called when parser
- * receives an input matching the grammar rule (app error message).
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processErrorMessageEntry(TreeWalkListener listener,
- GeneratedYangParser.ErrorMessageStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, ERROR_MESSAGE_DATA, ctx.string().getText(), ENTRY);
- String errorMessage = removeQuotesAndHandleConcat(ctx.string().getText());
-
- // Obtain the node of the stack.
- Parsable tmpNode = listener.getParsedDataStack().peek();
- if (tmpNode instanceof YangAppErrorHolder) {
- YangAppErrorInfo yangAppErrorInfo = ((YangAppErrorHolder) tmpNode).getAppErrorInfo();
- yangAppErrorInfo.setErrorMessage(errorMessage);
-
- yangAppErrorInfo.setLineNumber(ctx.getStart().getLine());
- yangAppErrorInfo.setCharPosition(ctx.getStart().getCharPositionInLine());
- yangAppErrorInfo.setFileName(listener.getFileName());
- } else {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, ERROR_MESSAGE_DATA,
- ctx.string().getText(), ENTRY));
- }
- }
-}
\ No newline at end of file
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ExtensionListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ExtensionListener.java
deleted file mode 100644
index 9a1180f..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ExtensionListener.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-import org.onosproject.yangutils.datamodel.YangExtension;
-import org.onosproject.yangutils.datamodel.YangModule;
-import org.onosproject.yangutils.datamodel.YangSubModule;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.EXTENSION_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.INVALID_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-
-/*
- * Reference: RFC6020 and YANG ANTLR Grammar
- *
- * ABNF grammar as per RFC6020
- * extension-stmt = extension-keyword sep identifier-arg-str optsep
- * (";" /
- * "{" stmtsep
- * ;; these stmts can appear in any order
- * [argument-stmt stmtsep]
- * [status-stmt stmtsep]
- * [description-stmt stmtsep]
- * [reference-stmt stmtsep]
- * "}")
- *
- * ANTLR grammar rule
- * extensionStatement : EXTENSION_KEYWORD identifier (STMTEND | LEFT_CURLY_BRACE extensionBody RIGHT_CURLY_BRACE);
- */
-
-/**
- * Represents listener based call back function corresponding to the "extension"
- * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
- */
-public final class ExtensionListener {
-
- /**
- * Creates a new extension listener.
- */
- private ExtensionListener() {
- }
-
- /**
- * Performs validation and updates the data model tree. It is called when parser
- * receives an input matching the grammar rule (extension).
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processExtensionEntry(TreeWalkListener listener,
- GeneratedYangParser.ExtensionStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, EXTENSION_DATA, ctx.identifier().getText(), ENTRY);
-
- String identifier = getValidIdentifier(ctx.identifier().getText(), EXTENSION_DATA, ctx);
-
- YangExtension extension = new YangExtension();
-
- extension.setLineNumber(ctx.getStart().getLine());
- extension.setCharPosition(ctx.getStart().getCharPositionInLine());
- extension.setFileName(listener.getFileName());
- extension.setName(identifier);
-
- Parsable curData = listener.getParsedDataStack().peek();
- switch (curData.getYangConstructType()) {
- case MODULE_DATA:
- YangModule module = ((YangModule) curData);
- module.addExtension(extension);
- break;
- case SUB_MODULE_DATA:
- YangSubModule subModule = ((YangSubModule) curData);
- subModule.addExtension(extension);
- break;
- default:
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, EXTENSION_DATA,
- ctx.identifier().getText(), ENTRY));
- }
- listener.getParsedDataStack().push(extension);
- }
-
- /**
- * Performs validation and updates the data model tree. It is called when parser exits
- * from grammar rule(extension).
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processExtensionExit(TreeWalkListener listener,
- GeneratedYangParser.ExtensionStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, EXTENSION_DATA, ctx.identifier().getText(), EXIT);
-
- if (!(listener.getParsedDataStack().peek() instanceof YangExtension)) {
- throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, EXTENSION_DATA,
- ctx.identifier().getText(), EXIT));
- }
- listener.getParsedDataStack().pop();
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/FeatureListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/FeatureListener.java
deleted file mode 100644
index 12e83b1..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/FeatureListener.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-/*
- * Reference: RFC6020 and YANG ANTLR Grammar
- *
- * ABNF grammar as per RFC6020
- * feature-stmt = feature-keyword sep identifier-arg-str optsep
- * (";" /
- * "{" stmtsep
- * ;; these stmts can appear in any order
- * *(if-feature-stmt stmtsep)
- * [status-stmt stmtsep]
- * [description-stmt stmtsep]
- * [reference-stmt stmtsep]
- * "}")
- *
- *
- *
- * ANTLR grammar rule
- * featureStatement : FEATURE_KEYWORD string (STMTEND | LEFT_CURLY_BRACE featureBody RIGHT_CURLY_BRACE);
- */
-
-import org.onosproject.yangutils.datamodel.YangFeature;
-import org.onosproject.yangutils.datamodel.YangFeatureHolder;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.FEATURE_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.INVALID_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-
-/**
- * Represents listener based call back function corresponding to the "feature"
- * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
- */
-public final class FeatureListener {
-
- /**
- * Creates a new feature listener.
- */
- private FeatureListener() {
- }
-
- /**
- * Performs validation and updates the data model tree.It is called when parser receives
- * an input matching the grammar rule (feature).
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processFeatureEntry(TreeWalkListener listener,
- GeneratedYangParser.FeatureStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, FEATURE_DATA, ctx.string().getText(), ENTRY);
-
- String identifier = getValidIdentifier(ctx.string().getText(), FEATURE_DATA, ctx);
-
- // Obtain the node of the stack.
- Parsable tmpNode = listener.getParsedDataStack().peek();
- if (tmpNode instanceof YangFeatureHolder) {
- YangFeatureHolder featureHolder = (YangFeatureHolder) tmpNode;
-
- YangFeature feature = new YangFeature();
- feature.setName(identifier);
-
- feature.setLineNumber(ctx.getStart().getLine());
- feature.setCharPosition(ctx.getStart().getCharPositionInLine());
- feature.setFileName(listener.getFileName());
- featureHolder.addFeatureList(feature);
- listener.getParsedDataStack().push(feature);
- } else {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, FEATURE_DATA,
- ctx.string().getText(), ENTRY));
- }
- }
-
- /**
- * Perform validations and updates the data model tree.It is called when parser exits from
- * grammar rule(feature).
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processFeatureExit(TreeWalkListener listener,
- GeneratedYangParser.FeatureStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, FEATURE_DATA, ctx.string().getText(), EXIT);
-
- if (listener.getParsedDataStack().peek() instanceof YangFeature) {
- listener.getParsedDataStack().pop();
- } else {
- throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, FEATURE_DATA,
- ctx.string().getText(), EXIT));
- }
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/FractionDigitsListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/FractionDigitsListener.java
deleted file mode 100644
index baeb252..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/FractionDigitsListener.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-/*
- * Reference: RFC6020 and YANG ANTLR Grammar
- *
- * ABNF grammar as per RFC6020
- * decimal64-specification = fraction-digits-stmt
- *
- * fraction-digits-stmt = fraction-digits-keyword sep
- * fraction-digits-arg-str stmtend
- *
- * fraction-digits-arg-str = < a string that matches the rule
- * fraction-digits-arg >
- *
- * fraction-digits-arg = ("1" ["0" / "1" / "2" / "3" / "4" /
- * "5" / "6" / "7" / "8"])
- * / "2" / "3" / "4" / "5" / "6" / "7" / "8" / "9"
- *
- * ANTLR grammar rule
- * decimal64Specification : FRACTION_DIGITS_KEYWORD fraction STMTEND;
- *
- * fraction : string;
- */
-
-import org.onosproject.yangutils.datamodel.YangDecimal64;
-import org.onosproject.yangutils.datamodel.YangRangeRestriction;
-import org.onosproject.yangutils.datamodel.YangType;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.FRACTION_DIGITS_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;
-
-/**
- * Represents listener based call back function corresponding to the "fraction-digits"
- * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
- */
-public final class FractionDigitsListener {
-
- /**
- * Creates a new bit listener.
- */
- private FractionDigitsListener() {
- }
-
- /**
- * It is called when parser enters grammar rule (fraction-digits), it perform
- * validations and updates the data model tree.
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processFractionDigitsEntry(TreeWalkListener listener,
- GeneratedYangParser.FractionDigitStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, FRACTION_DIGITS_DATA, ctx.fraction().getText(), ENTRY);
-
- int value = getValidFractionDigits(ctx);
-
- Parsable tmpNode = listener.getParsedDataStack().peek();
- if (tmpNode instanceof YangType) {
- YangType<YangDecimal64<YangRangeRestriction>> typeNode =
- (YangType<YangDecimal64<YangRangeRestriction>>) tmpNode;
- YangDecimal64 decimal64Node = typeNode.getDataTypeExtendedInfo();
- decimal64Node.setFractionDigit(value);
- } else {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, FRACTION_DIGITS_DATA,
- ctx.fraction().getText(), ENTRY));
- }
- }
-
- /**
- * Validate fraction digits.
- *
- * @param ctx context object of the grammar rule
- * @return validated fraction-digits
- */
- public static int getValidFractionDigits(GeneratedYangParser.FractionDigitStatementContext ctx) {
- String value = ctx.fraction().getText().trim();
- ParserException parserException;
-
- int fractionDigits = Integer.parseInt(value);
- if ((fractionDigits >= YangDecimal64.MIN_FRACTION_DIGITS_VALUE) &&
- (fractionDigits <= YangDecimal64.MAX_FRACTION_DIGITS_VALUE)) {
- return fractionDigits;
- } else {
- parserException =
- new ParserException("YANG file error : fraction-digits value should be between 1 and 18.");
- parserException.setLine(ctx.getStart().getLine());
- parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
- throw parserException;
- }
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/GroupingListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/GroupingListener.java
deleted file mode 100644
index 46ca2e0..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/GroupingListener.java
+++ /dev/null
@@ -1,178 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-import org.onosproject.yangutils.datamodel.YangContainer;
-import org.onosproject.yangutils.datamodel.YangGrouping;
-import org.onosproject.yangutils.datamodel.YangInput;
-import org.onosproject.yangutils.datamodel.YangList;
-import org.onosproject.yangutils.datamodel.YangModule;
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.YangNotification;
-import org.onosproject.yangutils.datamodel.YangOutput;
-import org.onosproject.yangutils.datamodel.YangRpc;
-import org.onosproject.yangutils.datamodel.YangSubModule;
-import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.DESCRIPTION_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.GROUPING_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.REFERENCE_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.STATUS_DATA;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil;
-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.constructExtendedListenerErrorMessage;
-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_CURRENT_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne;
-import static org.onosproject.yangutils.translator.tojava.YangDataModelFactory.getYangGroupingNode;
-
-/*
- * Reference: RFC6020 and YANG ANTLR Grammar
- *
- * ABNF grammar as per RFC6020
- * grouping-stmt = grouping-keyword sep identifier-arg-str optsep
- * (";" /
- * "{" stmtsep
- * ;; these stmts can appear in any order
- * [status-stmt stmtsep]
- * [description-stmt stmtsep]
- * [reference-stmt stmtsep]
- * *((typedef-stmt /
- * grouping-stmt) stmtsep)
- * *(data-def-stmt stmtsep)
- * "}")
- *
- * ANTLR grammar rule
- * groupingStatement : GROUPING_KEYWORD identifier (STMTEND | LEFT_CURLY_BRACE
- * (statusStatement | descriptionStatement | referenceStatement | typedefStatement | groupingStatement
- * | dataDefStatement)* RIGHT_CURLY_BRACE);
- */
-
-/**
- * Represents listener based call back function corresponding to the "grouping"
- * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
- */
-public final class GroupingListener {
-
- /**
- * Creates a new grouping listener.
- */
- private GroupingListener() {
- }
-
- /**
- * It is called when parser enters grammar rule (grouping), it perform
- * validations and updates the data model tree.
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processGroupingEntry(TreeWalkListener listener,
- GeneratedYangParser.GroupingStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, GROUPING_DATA, ctx.identifier().getText(), ENTRY);
-
- // Check validity of identifier and remove double quotes.
- String identifier = getValidIdentifier(ctx.identifier().getText(), GROUPING_DATA, ctx);
-
- // Validate sub statement cardinality.
- validateSubStatementsCardinality(ctx);
-
- // Increase the grouping count by one.
- listener.increaseGroupingDepth();
- Parsable curData = listener.getParsedDataStack().peek();
-
- // Check for identifier collision
- int line = ctx.getStart().getLine();
- int charPositionInLine = ctx.getStart().getCharPositionInLine();
- detectCollidingChildUtil(listener, line, charPositionInLine, identifier, GROUPING_DATA);
-
- if (curData instanceof YangModule || curData instanceof YangSubModule
- || curData instanceof YangContainer || curData instanceof YangNotification
- || curData instanceof YangList || curData instanceof YangGrouping
- || curData instanceof YangRpc || curData instanceof YangInput
- || curData instanceof YangOutput) {
-
- YangGrouping groupingNode = getYangGroupingNode(JAVA_GENERATION);
- groupingNode.setName(identifier);
- groupingNode.setGroupingDepth(listener.getGroupingDepth());
-
- groupingNode.setLineNumber(line);
- groupingNode.setCharPosition(charPositionInLine);
- groupingNode.setFileName(listener.getFileName());
- YangNode curNode = (YangNode) curData;
- try {
- curNode.addChild(groupingNode);
- } catch (DataModelException e) {
- throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
- GROUPING_DATA, ctx.identifier().getText(), ENTRY, e.getMessage()));
- }
- listener.getParsedDataStack().push(groupingNode);
- } else {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER,
- GROUPING_DATA, ctx.identifier().getText(), ENTRY));
- }
- }
-
- /**
- * It is called when parser exits from grammar rule (grouping), it perform
- * validations and update the data model tree.
- *
- * @param listener Listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processGroupingExit(TreeWalkListener listener,
- GeneratedYangParser.GroupingStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, GROUPING_DATA, ctx.identifier().getText(), EXIT);
-
- // Decrease the grouping count by one.
- listener.decreaseGroupingDepth();
- if (listener.getParsedDataStack().peek() instanceof YangGrouping) {
- listener.getParsedDataStack().pop();
- } else {
- throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, GROUPING_DATA,
- ctx.identifier().getText(), EXIT));
- }
- }
-
- /**
- * Validates the cardinality of case sub-statements as per grammar.
- *
- * @param ctx context object of the grammar rule
- */
- private static void validateSubStatementsCardinality(GeneratedYangParser.GroupingStatementContext ctx) {
-
- validateCardinalityMaxOne(ctx.statusStatement(), STATUS_DATA, GROUPING_DATA, ctx.identifier().getText());
- validateCardinalityMaxOne(ctx.descriptionStatement(), DESCRIPTION_DATA, GROUPING_DATA,
- ctx.identifier().getText());
- validateCardinalityMaxOne(ctx.referenceStatement(), REFERENCE_DATA, GROUPING_DATA, ctx.identifier().getText());
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/IdentityListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/IdentityListener.java
deleted file mode 100644
index 332ae4f..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/IdentityListener.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.yangutils.parser.impl.listeners;
-
-import org.onosproject.yangutils.datamodel.YangIdentity;
-import org.onosproject.yangutils.datamodel.YangModule;
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.YangSubModule;
-import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
-import static org.onosproject.yangutils.translator.tojava.YangDataModelFactory.getYangIdentityNode;
-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.constructExtendedListenerErrorMessage;
-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.ListenerErrorType.UNHANDLED_PARSED_DATA;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.IDENTITY_DATA;
-
-/**
- * Reference: RFC6020 and YANG ANTLR Grammar.
- *
- * ABNF grammar as per RFC6020
- * identity-stmt = identity-keyword sep identifier-arg-str optsep
- * (";" /
- * "{" stmtsep
- * ;; these stmts can appear in any order
- * [base-stmt stmtsep]
- * [status-stmt stmtsep]
- * [description-stmt stmtsep]
- * [reference-stmt stmtsep]
- * "}")
- */
-
-/**
- * Represents listener based call back function corresponding to the "identity"
- * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
- */
-public final class IdentityListener {
-
- //Creates a identity listener.
- private IdentityListener() {
- }
-
- /**
- * Performs validations and update the data model tree when parser receives an input
- * matching the grammar rule (identity).
- *
- * @param listener Listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processIdentityEntry(TreeWalkListener listener,
- GeneratedYangParser.IdentityStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, IDENTITY_DATA, ctx.identifier().getText(), ENTRY);
-
- String identifier = getValidIdentifier(ctx.identifier().getText(), IDENTITY_DATA, ctx);
-
- YangIdentity identity = getYangIdentityNode(JAVA_GENERATION);
- identity.setName(identifier);
-
- identity.setLineNumber(ctx.getStart().getLine());
- identity.setCharPosition(ctx.getStart().getCharPositionInLine());
- identity.setFileName(listener.getFileName());
- Parsable curData = listener.getParsedDataStack().peek();
- if (curData instanceof YangModule || curData instanceof YangSubModule) {
- YangNode curNode = (YangNode) curData;
- try {
- curNode.addChild(identity);
- } catch (DataModelException e) {
- throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
- IDENTITY_DATA, ctx.identifier().getText(), ENTRY, e.getMessage()));
- }
- // Push identity node to the stack.
- listener.getParsedDataStack().push(identity);
- } else {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, IDENTITY_DATA,
- ctx.identifier().getText(), ENTRY));
- }
-
- }
-
- /**
- * Performs validations and update the data model tree when parser exits from grammar
- * rule (identity).
- *
- * @param listener Listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processIdentityExit(TreeWalkListener listener,
- GeneratedYangParser.IdentityStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_CURRENT_HOLDER, IDENTITY_DATA, ctx.identifier().getText(), EXIT);
-
- Parsable parsableType = listener.getParsedDataStack().pop();
- if (!(parsableType instanceof YangIdentity)) {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, IDENTITY_DATA,
- ctx.identifier().getText(), EXIT));
- }
- }
-
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/IdentityrefListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/IdentityrefListener.java
deleted file mode 100644
index 17f197a..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/IdentityrefListener.java
+++ /dev/null
@@ -1,232 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.yangutils.parser.impl.listeners;
-
-import org.onosproject.yangutils.datamodel.YangIdentityRef;
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
-import org.onosproject.yangutils.datamodel.YangType;
-import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
-import org.onosproject.yangutils.linker.impl.YangResolutionInfoImpl;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.addResolutionInfo;
-import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.UNRESOLVED;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.BASE_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.IDENTITYREF_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
- .constructExtendedListenerErrorMessage;
-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_CURRENT_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidNodeIdentifier;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-
-/**
- * Reference: RFC6020 and YANG ANTLR Grammar
- *
- * ABNF grammar as per RFC6020
- * identityref-specification =
- * base-stmt stmtsep
- * base-stmt = base-keyword sep identifier-ref-arg-str
- * optsep stmtend*
- * identifier-ref-arg = [prefix ":"] identifier
- */
-
-/**
- * Represents listener based call back function corresponding to the "identityref"
- * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
- */
-public final class IdentityrefListener {
-
- //Creates a new type listener.
- private IdentityrefListener() {
- }
-
- /**
- * Performs validation and updates the data model tree when parser receives an input
- * matching the grammar rule (identityref).
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processIdentityrefEntry(TreeWalkListener listener,
- GeneratedYangParser.IdentityrefSpecificationContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, IDENTITYREF_DATA, "", ENTRY);
-
- if (listener.getParsedDataStack().peek() instanceof YangType) {
-
- YangIdentityRef identityRef = new YangIdentityRef();
- Parsable typeData = listener.getParsedDataStack().pop();
- YangDataTypes yangDataTypes = ((YangType) typeData).getDataType();
- YangResolutionInfoImpl resolutionInfo;
-
- // Validate node identifier.
- YangNodeIdentifier nodeIdentifier = getValidNodeIdentifier(ctx.baseStatement().string().getText(),
- BASE_DATA, ctx);
- identityRef.setBaseIdentity(nodeIdentifier);
- ((YangType) typeData).setDataTypeExtendedInfo(identityRef);
-
- int errorLine = ctx.getStart().getLine();
- int errorPosition = ctx.getStart().getCharPositionInLine();
-
- identityRef.setLineNumber(errorLine);
- identityRef.setCharPosition(errorPosition);
- identityRef.setFileName(listener.getFileName());
- Parsable tmpData = listener.getParsedDataStack().peek();
- switch (tmpData.getYangConstructType()) {
- case LEAF_DATA:
-
- // Pop the stack entry to obtain the parent YANG node.
- Parsable leaf = listener.getParsedDataStack().pop();
- Parsable parentNodeOfLeaf = listener.getParsedDataStack().peek();
-
- // Push the popped entry back to the stack.
- listener.getParsedDataStack().push(leaf);
-
- // Verify parent node of leaf
- if (!(parentNodeOfLeaf instanceof YangNode)) {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER,
- IDENTITYREF_DATA, ctx.getText(), EXIT));
- }
-
- identityRef.setResolvableStatus(UNRESOLVED);
-
- if (listener.getGroupingDepth() == 0) {
- // Add resolution information to the list
- resolutionInfo = new YangResolutionInfoImpl<YangIdentityRef>(identityRef,
- (YangNode) parentNodeOfLeaf, errorLine, errorPosition);
- addToResolutionList(resolutionInfo, ctx);
- } else {
- identityRef.setInGrouping(true);
- }
- break;
- case LEAF_LIST_DATA:
-
- // Pop the stack entry to obtain the parent YANG node.
- Parsable leafList = listener.getParsedDataStack().pop();
- Parsable parentNodeOfLeafList = listener.getParsedDataStack().peek();
-
- // Push the popped entry back to the stack.
- listener.getParsedDataStack().push(leafList);
-
- // Verify parent node of leaf
- if (!(parentNodeOfLeafList instanceof YangNode)) {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER,
- IDENTITYREF_DATA, ctx.getText(), EXIT));
- }
-
- identityRef.setResolvableStatus(UNRESOLVED);
-
- if (listener.getGroupingDepth() == 0) {
- // Add resolution information to the list
- resolutionInfo = new YangResolutionInfoImpl<YangIdentityRef>(identityRef,
- (YangNode) parentNodeOfLeafList, errorLine, errorPosition);
- addToResolutionList(resolutionInfo, ctx);
- } else {
- identityRef.setInGrouping(true);
- }
- break;
- case UNION_DATA:
-
- Parsable parentNodeOfUnionNode = listener.getParsedDataStack().peek();
-
- // Verify parent node of leaf
- if (!(parentNodeOfUnionNode instanceof YangNode)) {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER,
- IDENTITYREF_DATA, ctx.getText(), EXIT));
- }
-
- identityRef.setResolvableStatus(UNRESOLVED);
-
- if (listener.getGroupingDepth() == 0) {
- // Add resolution information to the list
- resolutionInfo = new YangResolutionInfoImpl<YangIdentityRef>(identityRef,
- (YangNode) parentNodeOfUnionNode, errorLine, errorPosition);
- addToResolutionList(resolutionInfo, ctx);
- } else {
- identityRef.setInGrouping(true);
- }
- break;
- case TYPEDEF_DATA:
- if (listener.getGroupingDepth() != 0) {
- identityRef.setInGrouping(true);
- }
- /**
- * Do not add the identity ref to resolution list. It needs to be
- * added to resolution list, when leaf/leaf list references to
- * this typedef. At this time that leaf/leaf-list becomes the
- * parent for the identityref.
- */
- break;
- default:
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, IDENTITYREF_DATA,
- ctx.getText(), EXIT));
- }
- listener.getParsedDataStack().push(typeData);
- listener.getParsedDataStack().push(identityRef);
- } else {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, IDENTITYREF_DATA, "", ENTRY));
- }
- }
-
- /**
- * Performs validations and update the data model tree when parser exits from grammar
- * rule (identityref).
- *
- * @param listener Listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processIdentityrefExit(TreeWalkListener listener,
- GeneratedYangParser.IdentityrefSpecificationContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_CURRENT_HOLDER, IDENTITYREF_DATA, ctx.getText(), EXIT);
-
- Parsable parsableType = listener.getParsedDataStack().pop();
- if (!(parsableType instanceof YangIdentityRef)) {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, IDENTITYREF_DATA,
- ctx.getText(), EXIT));
- }
- }
-
- /**
- * Adds to resolution list.
- *
- * @param resolutionInfo resolution information
- * @param ctx context object of the grammar rule
- */
- private static void addToResolutionList(YangResolutionInfoImpl<YangIdentityRef> resolutionInfo,
- GeneratedYangParser.IdentityrefSpecificationContext ctx) {
- try {
- addResolutionInfo(resolutionInfo);
- } catch (DataModelException e) {
- throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
- IDENTITYREF_DATA, ctx.getText(), ENTRY, e.getMessage()));
- }
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/IfFeatureListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/IfFeatureListener.java
deleted file mode 100644
index ab11780..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/IfFeatureListener.java
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-/*
- * Reference: RFC6020 and YANG ANTLR Grammar
- *
- * ABNF grammar as per RFC6020
- *
- * if-feature-stmt = if-feature-keyword sep identifier-ref-arg-str
- * optsep stmtend
- *
- * ANTLR grammar rule
- * ifFeatureStatement : IF_FEATURE_KEYWORD string STMTEND;
- */
-
-import org.onosproject.yangutils.datamodel.YangFeature;
-import org.onosproject.yangutils.datamodel.YangIfFeature;
-import org.onosproject.yangutils.datamodel.YangIfFeatureHolder;
-import org.onosproject.yangutils.datamodel.YangLeaf;
-import org.onosproject.yangutils.datamodel.YangLeafList;
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
-import org.onosproject.yangutils.datamodel.YangResolutionInfo;
-import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.linker.impl.YangResolutionInfoImpl;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.addResolutionInfo;
-import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.UNRESOLVED;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.IF_FEATURE_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.constructExtendedListenerErrorMessage;
-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.ListenerErrorType.UNHANDLED_PARSED_DATA;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidNodeIdentifier;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-
-/**
- * Represents listener based call back function corresponding to the "if-feature"
- * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
- */
-public final class IfFeatureListener {
-
- /**
- * Creates a new IfFeature listener.
- */
- private IfFeatureListener() {
- }
-
- /**
- * Performs validation and updates the data model tree.It is called when parser receives
- * an input matching the grammar rule (if-feature).
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processIfFeatureEntry(TreeWalkListener listener,
- GeneratedYangParser.IfFeatureStatementContext ctx) {
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, IF_FEATURE_DATA, ctx.string().getText(), ENTRY);
-
- // Validate if-feature argument string
- YangNodeIdentifier nodeIdentifier = getValidNodeIdentifier(ctx.string().getText(),
- IF_FEATURE_DATA, ctx);
-
- YangIfFeature ifFeature = new YangIfFeature();
- ifFeature.setName(nodeIdentifier);
- ifFeature.setResolvableStatus(UNRESOLVED);
-
- ifFeature.setLineNumber(ctx.getStart().getLine());
- ifFeature.setCharPosition(ctx.getStart().getCharPositionInLine());
- ifFeature.setFileName(listener.getFileName());
- YangIfFeatureHolder ifFeatureHolder;
-
- // Obtain the node of the stack.
- Parsable tmpNode = listener.getParsedDataStack().peek();
- if (tmpNode instanceof YangIfFeatureHolder) {
- ifFeatureHolder = (YangIfFeatureHolder) tmpNode;
- ifFeatureHolder.addIfFeatureList(ifFeature);
- } else {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, IF_FEATURE_DATA,
- ctx.string().getText(), ENTRY));
- }
-
- // Add resolution information to the list
- Parsable parentNode;
- if (tmpNode instanceof YangLeafList || tmpNode instanceof YangLeaf
- || tmpNode instanceof YangFeature) {
- Parsable leafData = listener.getParsedDataStack().pop();
- parentNode = listener.getParsedDataStack().peek();
- listener.getParsedDataStack().push(leafData);
- } else {
- parentNode = tmpNode;
- }
-
- // Verify parent node of leaf
- if (!(parentNode instanceof YangNode)) {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, IF_FEATURE_DATA,
- ctx.string().getText(), EXIT));
- }
-
- int errorLine = ctx.getStart().getLine();
- int errorPosition = ctx.getStart().getCharPositionInLine();
- YangResolutionInfoImpl resolutionInfo = new YangResolutionInfoImpl<YangIfFeature>(ifFeature,
- (YangNode) parentNode, errorLine,
- errorPosition);
- addToResolutionList(resolutionInfo, ctx);
- }
-
- /**
- * Add to resolution list.
- *
- * @param resolutionInfo resolution information.
- * @param ctx context object of the grammar rule
- */
- private static void addToResolutionList(YangResolutionInfo<YangIfFeature> resolutionInfo,
- GeneratedYangParser.IfFeatureStatementContext ctx) {
-
- try {
- addResolutionInfo(resolutionInfo);
- } catch (DataModelException e) {
- throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
- IF_FEATURE_DATA, ctx.string().getText(), EXIT, e.getMessage()));
- }
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ImportListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ImportListener.java
deleted file mode 100644
index 1f7a7d7..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ImportListener.java
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-import org.onosproject.yangutils.datamodel.YangImport;
-import org.onosproject.yangutils.datamodel.YangModule;
-import org.onosproject.yangutils.datamodel.YangSubModule;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.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.INVALID_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-
-/*
- * Reference: RFC6020 and YANG ANTLR Grammar
- *
- * ABNF grammar as per RFC6020
- * linkage-stmts = ;; these stmts can appear in any order
- * *(import-stmt stmtsep)
- * *(include-stmt stmtsep)
- *
- * import-stmt = import-keyword sep identifier-arg-str optsep
- * "{" stmtsep
- * prefix-stmt stmtsep
- * [revision-date-stmt stmtsep]
- * "}"
- *
- * ANTLR grammar rule
- * linkage_stmts : (import_stmt
- * | include_stmt)*;
- * import_stmt : IMPORT_KEYWORD identifier LEFT_CURLY_BRACE import_stmt_body
- * RIGHT_CURLY_BRACE;
- * import_stmt_body : prefix_stmt revision_date_stmt?;
- */
-
-/**
- * Represents listener based call back function corresponding to the "import"
- * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
- */
-public final class ImportListener {
-
- /**
- * Creates a new import listener.
- */
- private ImportListener() {
- }
-
- /**
- * 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
- */
- public static void processImportEntry(TreeWalkListener listener, GeneratedYangParser.ImportStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, IMPORT_DATA, ctx.identifier().getText(), ENTRY);
-
- String identifier = getValidIdentifier(ctx.identifier().getText(), IMPORT_DATA, ctx);
-
- YangImport importNode = new YangImport();
- importNode.setModuleName(identifier);
-
- // Set the line number and character position in line for the belongs to.
- int errorLine = ctx.getStart().getLine();
- int errorPosition = ctx.getStart().getCharPositionInLine();
- importNode.setLineNumber(errorLine);
- importNode.setCharPosition(errorPosition);
- importNode.setFileName(listener.getFileName());
-
- // Push import node to the stack.
- listener.getParsedDataStack().push(importNode);
- }
-
- /**
- * It is called when parser exits from grammar rule (import), it perform
- * validations and update the data model tree.
- *
- * @param listener Listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processImportExit(TreeWalkListener listener, GeneratedYangParser.ImportStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, IMPORT_DATA, ctx.identifier().getText(), EXIT);
-
- Parsable tmpImportNode = listener.getParsedDataStack().peek();
- if (tmpImportNode instanceof YangImport) {
- listener.getParsedDataStack().pop();
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, IMPORT_DATA, ctx.identifier().getText(),
- EXIT);
-
- Parsable tmpNode = listener.getParsedDataStack().peek();
- switch (tmpNode.getYangConstructType()) {
- case MODULE_DATA: {
- YangModule module = (YangModule) tmpNode;
- module.addToImportList((YangImport) tmpImportNode);
- break;
- }
- case SUB_MODULE_DATA: {
- YangSubModule subModule = (YangSubModule) tmpNode;
- subModule.addToImportList((YangImport) tmpImportNode);
- break;
- }
- default:
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, IMPORT_DATA,
- ctx.identifier().getText(),
- EXIT));
- }
- } else {
- throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, IMPORT_DATA,
- ctx.identifier().getText(), EXIT));
- }
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/IncludeListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/IncludeListener.java
deleted file mode 100644
index 5842a7e..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/IncludeListener.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-import org.onosproject.yangutils.datamodel.YangInclude;
-import org.onosproject.yangutils.datamodel.YangModule;
-import org.onosproject.yangutils.datamodel.YangSubModule;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.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.INVALID_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-
-/*
- * Reference: RFC6020 and YANG ANTLR Grammar
- *
- * ABNF grammar as per RFC6020
- * linkage-stmts = ;; these stmts can appear in any order
- * *(import-stmt stmtsep)
- * *(include-stmt stmtsep)
- *
- * include-stmt = include-keyword sep identifier-arg-str optsep
- * (";" /
- * "{" stmtsep
- * [revision-date-stmt stmtsep]
- * "}")
- *
- * ANTLR grammar rule
- * linkage_stmts : (import_stmt
- * | include_stmt)*;
- * include_stmt : INCLUDE_KEYWORD identifier (STMTEND | LEFT_CURLY_BRACE
- * revision_date_stmt? RIGHT_CURLY_BRACE);
- */
-
-/**
- * Represents listener based call back function corresponding to the "include"
- * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
- */
-public final class IncludeListener {
-
- /**
- * Creates a new include listener.
- */
- private IncludeListener() {
- }
-
- /**
- * 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
- */
- public static void processIncludeEntry(TreeWalkListener listener, GeneratedYangParser.IncludeStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, INCLUDE_DATA, ctx.identifier().getText(),
- ENTRY);
-
- String identifier = getValidIdentifier(ctx.identifier().getText(), INCLUDE_DATA, ctx);
-
- YangInclude includeNode = new YangInclude();
- includeNode.setSubModuleName(identifier);
-
- // Set the line number and character position in line for the belongs to.
- int errorLine = ctx.getStart().getLine();
- int errorPosition = ctx.getStart().getCharPositionInLine();
- includeNode.setLineNumber(errorLine);
- includeNode.setCharPosition(errorPosition);
- includeNode.setFileName(listener.getFileName());
-
- listener.getParsedDataStack().push(includeNode);
- }
-
- /**
- * It is called when parser exits from grammar rule (include), it perform
- * validations and update the data model tree.
- *
- * @param listener Listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processIncludeExit(TreeWalkListener listener, GeneratedYangParser.IncludeStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, INCLUDE_DATA, ctx.identifier().getText(), EXIT);
-
- Parsable tmpIncludeNode = listener.getParsedDataStack().peek();
- if (tmpIncludeNode instanceof YangInclude) {
- listener.getParsedDataStack().pop();
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, INCLUDE_DATA, ctx.identifier().getText(),
- EXIT);
-
- Parsable tmpNode = listener.getParsedDataStack().peek();
- switch (tmpNode.getYangConstructType()) {
- case MODULE_DATA: {
- YangModule module = (YangModule) tmpNode;
- module.addToIncludeList((YangInclude) tmpIncludeNode);
- break;
- }
- case SUB_MODULE_DATA: {
- YangSubModule subModule = (YangSubModule) tmpNode;
- subModule.addToIncludeList((YangInclude) tmpIncludeNode);
- break;
- }
- default:
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, INCLUDE_DATA,
- ctx.identifier().getText(),
- EXIT));
- }
- } else {
- throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, INCLUDE_DATA,
- ctx.identifier().getText(), EXIT));
- }
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/InputListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/InputListener.java
deleted file mode 100644
index 0b7e116..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/InputListener.java
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-import org.onosproject.yangutils.datamodel.YangInput;
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.YangRpc;
-import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.INPUT_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
- .constructExtendedListenerErrorMessage;
-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_CURRENT_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-import static org.onosproject.yangutils.translator.tojava.YangDataModelFactory.getYangInputNode;
-import static org.onosproject.yangutils.utils.UtilConstants.INPUT;
-
-/*
- * Reference: RFC6020 and YANG ANTLR Grammar
- *
- * ABNF grammar as per RFC6020
- *
- * input-stmt = input-keyword optsep
- * "{" stmtsep
- * ;; these stmts can appear in any order
- * *((typedef-stmt /
- * grouping-stmt) stmtsep)
- * 1*(data-def-stmt stmtsep)
- * "}"
- *
- * inputStatement : INPUT_KEYWORD LEFT_CURLY_BRACE inputStatementBody RIGHT_CURLY_BRACE;
-
- * inputStatementBody : typedefStatement* dataDefStatement+
- * | dataDefStatement+ typedefStatement*
- * | groupingStatement* dataDefStatement+
- * | dataDefStatement+ groupingStatement*;
- */
-
-/**
- * Represents listener based call back function corresponding to the "input"
- * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
- */
-public final class InputListener {
-
- /**
- * Creates a new input listener.
- */
- private InputListener() {
- }
-
- /**
- * It is called when parser receives an input matching the grammar rule
- * (input), performs validation and updates the data model tree.
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processInputEntry(TreeWalkListener listener,
- GeneratedYangParser.InputStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, INPUT_DATA, "", ENTRY);
-
- Parsable curData = listener.getParsedDataStack().peek();
- if (curData instanceof YangRpc) {
-
- YangInput yangInput = getYangInputNode(JAVA_GENERATION);
- yangInput.setName(INPUT);
- yangInput.setLineNumber(ctx.getStart().getLine());
- yangInput.setCharPosition(ctx.getStart().getCharPositionInLine());
- yangInput.setFileName(listener.getFileName());
- YangNode curNode = (YangNode) curData;
- try {
- curNode.addChild(yangInput);
- } catch (DataModelException e) {
- throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
- INPUT_DATA, "", ENTRY, e.getMessage()));
- }
- listener.getParsedDataStack().push(yangInput);
- } else {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, INPUT_DATA,
- "", ENTRY));
- }
- }
-
- /**
- * It is called when parser exits from grammar rule (input), it perform
- * validations and updates the data model tree.
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processInputExit(TreeWalkListener listener,
- GeneratedYangParser.InputStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, INPUT_DATA, "", EXIT);
-
- if (!(listener.getParsedDataStack().peek() instanceof YangInput)) {
- throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, INPUT_DATA,
- "", EXIT));
- }
- listener.getParsedDataStack().pop();
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/KeyListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/KeyListener.java
deleted file mode 100644
index 889de0a..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/KeyListener.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-import org.onosproject.yangutils.datamodel.YangList;
-import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.KEY_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;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.removeQuotesAndHandleConcat;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-
-/*
- * Reference: RFC6020 and YANG ANTLR Grammar
- *
- * ABNF grammar as per RFC6020
- * key-stmt = key-keyword sep key-arg-str stmtend
- *
- * ANTLR grammar rule
- * keyStatement : KEY_KEYWORD key STMTEND;
- * key : string;
- */
-
-/**
- * Represesnts listener based call back function corresponding to the "key" rule
- * defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
- */
-public final class KeyListener {
-
- /**
- * Creates a new key listener.
- */
- private KeyListener() {
- }
-
- /**
- * It is called when parser receives an input matching the grammar rule
- * (key), perform validations and updates the data model tree.
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processKeyEntry(TreeWalkListener listener,
- GeneratedYangParser.KeyStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, KEY_DATA, ctx.key().getText(), ENTRY);
-
- Parsable tmpData = listener.getParsedDataStack().peek();
- if (listener.getParsedDataStack().peek() instanceof YangList) {
- YangList yangList = (YangList) tmpData;
- String tmpKeyValue = removeQuotesAndHandleConcat(ctx.key().getText());
- if (tmpKeyValue.contains(" ")) {
- String[] keyValues = tmpKeyValue.split(" ");
- for (String keyValue : keyValues) {
- try {
- yangList.addKey(keyValue);
- } catch (DataModelException e) {
- throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA, KEY_DATA,
- ctx.key().getText(), ENTRY, e.getMessage()));
- }
- }
- } else {
- try {
- yangList.addKey(tmpKeyValue);
- } catch (DataModelException e) {
- throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA, KEY_DATA,
- ctx.key().getText(), ENTRY, e.getMessage()));
- }
- }
- } else {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, KEY_DATA, ctx.key().getText(),
- ENTRY));
- }
- }
-}
\ No newline at end of file
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/LeafListListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/LeafListListener.java
deleted file mode 100644
index 8dd33b8..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/LeafListListener.java
+++ /dev/null
@@ -1,181 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-import org.onosproject.yangutils.datamodel.YangLeafList;
-import org.onosproject.yangutils.datamodel.YangLeavesHolder;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-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.ListenerValidation;
-
-import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.CONFIG_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.DESCRIPTION_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.LEAF_LIST_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.MAX_ELEMENT_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.MIN_ELEMENT_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.REFERENCE_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.STATUS_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.TYPE_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.UNITS_DATA;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil;
-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.INVALID_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityEqualsOne;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne;
-import static org.onosproject.yangutils.translator.tojava.YangDataModelFactory.getYangLeafList;
-
-/*
- * Reference: RFC6020 and YANG ANTLR Grammar
- *
- * ABNF grammar as per RFC6020
- * leaf-list-stmt = leaf-list-keyword sep identifier-arg-str optsep
- * "{" stmtsep
- * ;; these stmts can appear in any order
- * [when-stmt stmtsep]
- * *(if-feature-stmt stmtsep)
- * type-stmt stmtsep
- * [units-stmt stmtsep]
- * *(must-stmt stmtsep)
- * [config-stmt stmtsep]
- * [min-elements-stmt stmtsep]
- * [max-elements-stmt stmtsep]
- * [ordered-by-stmt stmtsep]
- * [status-stmt stmtsep]
- * [description-stmt stmtsep]
- * [reference-stmt stmtsep]
- * "}"
- *
- * ANTLR grammar rule
- * leafListStatement : LEAF_LIST_KEYWORD identifier LEFT_CURLY_BRACE (whenStatement | ifFeatureStatement |
- * typeStatement | unitsStatement | mustStatement | configStatement | minElementsStatement | maxElementsStatement |
- * orderedByStatement | statusStatement | descriptionStatement | referenceStatement)* RIGHT_CURLY_BRACE;
- */
-
-/**
- * Represents listener based call back function corresponding to the "leaf-list"
- * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
- */
-public final class LeafListListener {
-
- /**
- * Creates a new leaf list listener.
- */
- private LeafListListener() {
- }
-
- /**
- * It is called when parser receives an input matching the grammar rule
- * (leaf-list), performs validation and updates the data model tree.
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processLeafListEntry(TreeWalkListener listener,
- GeneratedYangParser.LeafListStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, LEAF_LIST_DATA, ctx.identifier().getText(), ENTRY);
-
- String identifier = getValidIdentifier(ctx.identifier().getText(), LEAF_LIST_DATA, ctx);
-
- // Validate sub statement cardinality.
- validateSubStatementsCardinality(ctx);
-
- // Check for identifier collision
- int line = ctx.getStart().getLine();
- int charPositionInLine = ctx.getStart().getCharPositionInLine();
- detectCollidingChildUtil(listener, line, charPositionInLine, identifier, LEAF_LIST_DATA);
-
- YangLeafList leafList = getYangLeafList(JAVA_GENERATION);
- leafList.setName(identifier);
- leafList.setLineNumber(line);
- leafList.setCharPosition(charPositionInLine);
- leafList.setFileName(listener.getFileName());
- /*
- * If "config" is not specified, the default is the same as the parent
- * schema node's "config" value.
- */
- if (ctx.configStatement().isEmpty()) {
- boolean parentConfig = ListenerValidation.getParentNodeConfig(listener);
- leafList.setConfig(parentConfig);
- }
-
- Parsable tmpData = listener.getParsedDataStack().peek();
- YangLeavesHolder leavesHolder;
-
- if (tmpData instanceof YangLeavesHolder) {
- leavesHolder = (YangLeavesHolder) tmpData;
- leavesHolder.addLeafList(leafList);
- leafList.setContainedIn(leavesHolder);
- } else {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, LEAF_LIST_DATA,
- ctx.identifier().getText(), ENTRY));
- }
- listener.getParsedDataStack().push(leafList);
- }
-
- /**
- * It is called when parser exits from grammar rule (leaf-list), it performs
- * validation and updates the data model tree.
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processLeafListExit(TreeWalkListener listener,
- GeneratedYangParser.LeafListStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, LEAF_LIST_DATA, ctx.identifier().getText(), EXIT);
-
- if (listener.getParsedDataStack().peek() instanceof YangLeafList) {
- listener.getParsedDataStack().pop();
- } else {
- throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, LEAF_LIST_DATA,
- ctx.identifier().getText(), EXIT));
- }
- }
-
- /**
- * Validates the cardinality of leaf-list sub-statements as per grammar.
- *
- * @param ctx context object of the grammar rule
- */
- private static void validateSubStatementsCardinality(GeneratedYangParser.LeafListStatementContext ctx) {
-
- validateCardinalityEqualsOne(ctx.typeStatement(), TYPE_DATA, LEAF_LIST_DATA, ctx.identifier().getText(), ctx);
- validateCardinalityMaxOne(ctx.unitsStatement(), UNITS_DATA, LEAF_LIST_DATA, ctx.identifier().getText());
- validateCardinalityMaxOne(ctx.configStatement(), CONFIG_DATA, LEAF_LIST_DATA, ctx.identifier().getText());
- validateCardinalityMaxOne(ctx.maxElementsStatement(), MAX_ELEMENT_DATA, LEAF_LIST_DATA,
- ctx.identifier().getText());
- validateCardinalityMaxOne(ctx.minElementsStatement(), MIN_ELEMENT_DATA, LEAF_LIST_DATA,
- ctx.identifier().getText());
- validateCardinalityMaxOne(ctx.descriptionStatement(), DESCRIPTION_DATA, LEAF_LIST_DATA,
- ctx.identifier().getText());
- validateCardinalityMaxOne(ctx.referenceStatement(), REFERENCE_DATA, LEAF_LIST_DATA, ctx.identifier().getText());
- validateCardinalityMaxOne(ctx.statusStatement(), STATUS_DATA, LEAF_LIST_DATA, ctx.identifier().getText());
- //TODO ordered by
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/LeafListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/LeafListener.java
deleted file mode 100644
index d6f06ff..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/LeafListener.java
+++ /dev/null
@@ -1,190 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * Implements listener based call back function corresponding to the "leaf"
- * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
- */
-package org.onosproject.yangutils.parser.impl.listeners;
-
-import org.onosproject.yangutils.datamodel.YangLeaf;
-import org.onosproject.yangutils.datamodel.YangLeavesHolder;
-import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-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.ListenerValidation;
-
-import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.CONFIG_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.DESCRIPTION_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.LEAF_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.MANDATORY_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.REFERENCE_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.STATUS_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.TYPE_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.UNITS_DATA;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil;
-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.INVALID_CONTENT;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityEqualsOne;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne;
-import static org.onosproject.yangutils.translator.tojava.YangDataModelFactory.getYangLeaf;
-
-/*
- * Reference: RFC6020 and YANG ANTLR Grammar
- *
- * ABNF grammar as per RFC6020
- * leaf-stmt = leaf-keyword sep identifier-arg-str optsep
- * "{" stmtsep
- * ;; these stmts can appear in any order
- * [when-stmt stmtsep]
- * *(if-feature-stmt stmtsep)
- * type-stmt stmtsep
- * [units-stmt stmtsep]
- * *(must-stmt stmtsep)
- * [default-stmt stmtsep]
- * [config-stmt stmtsep]
- * [mandatory-stmt stmtsep]
- * [status-stmt stmtsep]
- * [description-stmt stmtsep]
- * [reference-stmt stmtsep]
- * "}"
- *
- * ANTLR grammar rule
- * leafStatement : LEAF_KEYWORD identifier LEFT_CURLY_BRACE (whenStatement | ifFeatureStatement | typeStatement |
- * unitsStatement | mustStatement | defaultStatement | configStatement | mandatoryStatement | statusStatement |
- * descriptionStatement | referenceStatement)* RIGHT_CURLY_BRACE;
- */
-
-/**
- * Represents listener based call back function corresponding to the "leaf" rule
- * defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
- */
-public final class LeafListener {
-
- /**
- * Creates a new leaf listener.
- */
- private LeafListener() {
- }
-
- /**
- * It is called when parser receives an input matching the grammar rule
- * (leaf), performs validation and updates the data model tree.
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processLeafEntry(TreeWalkListener listener,
- GeneratedYangParser.LeafStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, LEAF_DATA, ctx.identifier().getText(), ENTRY);
-
- String identifier = getValidIdentifier(ctx.identifier().getText(), LEAF_DATA, ctx);
-
- // Validate sub statement cardinality.
- validateSubStatementsCardinality(ctx);
-
- // Check for identifier collision
- int line = ctx.getStart().getLine();
- int charPositionInLine = ctx.getStart().getCharPositionInLine();
- detectCollidingChildUtil(listener, line, charPositionInLine, identifier, LEAF_DATA);
-
- YangLeaf leaf = getYangLeaf(JAVA_GENERATION);
- leaf.setName(identifier);
- leaf.setLineNumber(line);
- leaf.setCharPosition(charPositionInLine);
- leaf.setFileName(listener.getFileName());
-
- /*
- * If "config" is not specified, the default is the same as the parent
- * schema node's "config" value.
- */
- if (ctx.configStatement().isEmpty()) {
- boolean parentConfig = ListenerValidation.getParentNodeConfig(listener);
- leaf.setConfig(parentConfig);
- }
-
- Parsable tmpData = listener.getParsedDataStack().peek();
- YangLeavesHolder leavesHolder;
-
- if (tmpData instanceof YangLeavesHolder) {
- leavesHolder = (YangLeavesHolder) tmpData;
- leavesHolder.addLeaf(leaf);
- leaf.setContainedIn(leavesHolder);
- } else {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, LEAF_DATA,
- ctx.identifier().getText(), ENTRY));
- }
-
- listener.getParsedDataStack().push(leaf);
- }
-
- /**
- * It is called when parser exits from grammar rule (leaf), performs
- * validation and updates the data model tree.
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processLeafExit(TreeWalkListener listener,
- GeneratedYangParser.LeafStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, LEAF_DATA, ctx.identifier().getText(), EXIT);
-
- if (listener.getParsedDataStack().peek() instanceof YangLeaf) {
- YangLeaf leafNode = (YangLeaf) listener.getParsedDataStack().peek();
- try {
- leafNode.validateDataOnExit();
- } catch (DataModelException e) {
- throw new ParserException(constructListenerErrorMessage(INVALID_CONTENT, LEAF_DATA,
- ctx.identifier().getText(), EXIT));
- }
- listener.getParsedDataStack().pop();
- } else {
- throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, LEAF_DATA,
- ctx.identifier().getText(), EXIT));
- }
- }
-
- /**
- * Validates the cardinality of leaf sub-statements as per grammar.
- *
- * @param ctx context object of the grammar rule
- */
- private static void validateSubStatementsCardinality(GeneratedYangParser.LeafStatementContext ctx) {
-
- validateCardinalityEqualsOne(ctx.typeStatement(), TYPE_DATA, LEAF_DATA, ctx.identifier().getText(), ctx);
- validateCardinalityMaxOne(ctx.unitsStatement(), UNITS_DATA, LEAF_DATA, ctx.identifier().getText());
- validateCardinalityMaxOne(ctx.configStatement(), CONFIG_DATA, LEAF_DATA, ctx.identifier().getText());
- validateCardinalityMaxOne(ctx.mandatoryStatement(), MANDATORY_DATA, LEAF_DATA, ctx.identifier().getText());
- validateCardinalityMaxOne(ctx.descriptionStatement(), DESCRIPTION_DATA, LEAF_DATA, ctx.identifier().getText());
- validateCardinalityMaxOne(ctx.referenceStatement(), REFERENCE_DATA, LEAF_DATA, ctx.identifier().getText());
- validateCardinalityMaxOne(ctx.statusStatement(), STATUS_DATA, LEAF_DATA, ctx.identifier().getText());
- //TODO when.
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/LeafrefListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/LeafrefListener.java
deleted file mode 100644
index 25ac31c..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/LeafrefListener.java
+++ /dev/null
@@ -1,229 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-import org.onosproject.yangutils.datamodel.YangLeaf;
-import org.onosproject.yangutils.datamodel.YangLeafList;
-import org.onosproject.yangutils.datamodel.YangLeafRef;
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.YangType;
-import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.linker.impl.YangResolutionInfoImpl;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.addResolutionInfo;
-import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.UNRESOLVED;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.LEAFREF_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.constructExtendedListenerErrorMessage;
-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_CURRENT_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-
-/*
- * Reference: RFC6020 and YANG ANTLR Grammar
- *
- * ABNF grammar as per RFC6020
- * type-body-stmts = numerical-restrictions /
- * decimal64-specification /
- * string-restrictions /
- * enum-specification /
- * leafref-specification /
- * identityref-specification /
- * instance-identifier-specification /
- * bits-specification /
- * union-specification
- *
- * leafref-specification =
- * ;; these stmts can appear in any order
- * path-stmt stmtsep
- * [require-instance-stmt stmtsep]
- *
- * ANTLR grammar rule
- *
- * typeBodyStatements : numericalRestrictions | stringRestrictions | enumSpecification
- * | leafrefSpecification | identityrefSpecification | instanceIdentifierSpecification
- * | bitsSpecification | unionSpecification;
- *
- * leafrefSpecification : (pathStatement (requireInstanceStatement)?) | ((requireInstanceStatement)? pathStatement);
- */
-
-/**
- * Represents listener based call back function corresponding to the
- * "leafref" rule defined in ANTLR grammar file for corresponding ABNF rule
- * in RFC 6020.
- */
-public final class LeafrefListener {
-
- /**
- * Creates a new leafref listener.
- */
- private LeafrefListener() {
- }
-
- /**
- * It is called when parser receives an input matching the grammar rule
- * (leafref), perform validations and updates the data model tree.
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processLeafrefEntry(TreeWalkListener listener,
- GeneratedYangParser.LeafrefSpecificationContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, LEAFREF_DATA, "", ENTRY);
-
- int errorLine = ctx.getStart().getLine();
- int errorPosition = ctx.getStart().getCharPositionInLine();
-
- YangLeafRef<?> leafRef = new YangLeafRef<>();
-
- leafRef.setLineNumber(errorLine);
- leafRef.setCharPosition(errorPosition);
- leafRef.setFileName(listener.getFileName());
- Parsable typeData = listener.getParsedDataStack().pop();
-
- if (!(typeData instanceof YangType)) {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, LEAFREF_DATA,
- "", ENTRY));
- }
-
- YangType type = (YangType) typeData;
- type.setDataTypeExtendedInfo(leafRef);
-
- // Setting by default the value of require-instance as true.
- leafRef.setRequireInstance(true);
- Parsable tmpData = listener.getParsedDataStack().peek();
-
- switch (tmpData.getYangConstructType()) {
-
- case LEAF_DATA:
-
- // Parent YANG node of leaf to be added in resolution information.
- YangLeaf leaf = (YangLeaf) listener.getParsedDataStack().pop();
- Parsable parentNodeOfLeaf = listener.getParsedDataStack().peek();
- listener.getParsedDataStack().push(leaf);
-
- // Verify parent node of leaf.
- if (!(parentNodeOfLeaf instanceof YangNode)) {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, LEAFREF_DATA,
- "", ENTRY));
- }
-
- leafRef.setResolvableStatus(UNRESOLVED);
- leafRef.setParentNodeOfLeafref((YangNode) parentNodeOfLeaf);
- if (listener.getGroupingDepth() == 0) {
- // Add resolution information to the list.
- YangResolutionInfoImpl resolutionInfo = new YangResolutionInfoImpl<YangLeafRef>(leafRef,
- (YangNode) parentNodeOfLeaf, errorLine, errorPosition);
- addToResolutionList(resolutionInfo);
- } else {
- leafRef.setInGrouping(true);
- }
- break;
-
- case LEAF_LIST_DATA:
-
- // Parent YANG node of leaf-list to be added in resolution information.
- YangLeafList leafList = (YangLeafList) listener.getParsedDataStack().pop();
- Parsable parentNodeOfLeafList = listener.getParsedDataStack().peek();
- listener.getParsedDataStack().push(leafList);
-
- // Verify parent node of leaf-list.
- if (!(parentNodeOfLeafList instanceof YangNode)) {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, LEAFREF_DATA,
- "", ENTRY));
- }
-
- leafRef.setResolvableStatus(UNRESOLVED);
- leafRef.setParentNodeOfLeafref((YangNode) parentNodeOfLeafList);
-
- if (listener.getGroupingDepth() == 0) {
- // Add resolution information to the list.
- YangResolutionInfoImpl resolutionInfoImpl = new YangResolutionInfoImpl<YangLeafRef>(leafRef,
- (YangNode) parentNodeOfLeafList, errorLine, errorPosition);
- addToResolutionList(resolutionInfoImpl);
- } else {
- leafRef.setInGrouping(true);
- }
- break;
-
- case TYPEDEF_DATA:
- Parsable parentNodeOfLeafref = listener.getParsedDataStack().peek();
- leafRef.setParentNodeOfLeafref((YangNode) parentNodeOfLeafref);
- if (listener.getGroupingDepth() != 0) {
- leafRef.setInGrouping(true);
- }
- /*
- * Do not add the leaf ref to resolution list. It needs to be
- * added to resolution list, when leaf/leaf list references to
- * this typedef. At this time that leaf/leaf-list becomes the
- * parent for the leafref.
- */
- break;
-
- default:
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, LEAFREF_DATA,
- "", ENTRY));
- }
- listener.getParsedDataStack().push(typeData);
- listener.getParsedDataStack().push(leafRef);
- }
-
- /**
- * It is called when parser exits from grammar rule (leafref), it performs
- * validation and updates the data model tree.
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processLeafrefExit(TreeWalkListener listener,
- GeneratedYangParser.LeafrefSpecificationContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_CURRENT_HOLDER, LEAFREF_DATA, "", EXIT);
-
- Parsable parsableType = listener.getParsedDataStack().pop();
- if (!(parsableType instanceof YangLeafRef)) {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, LEAFREF_DATA,
- "", EXIT));
- }
- }
-
- /**
- * Adds to resolution list.
- *
- * @param resolutionInfo resolution information
- */
- private static void addToResolutionList(YangResolutionInfoImpl resolutionInfo) {
-
- try {
- addResolutionInfo(resolutionInfo);
- } catch (DataModelException e) {
- throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
- LEAFREF_DATA, "", ENTRY, e.getMessage()));
- }
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/LengthRestrictionListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/LengthRestrictionListener.java
deleted file mode 100644
index 52b7143..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/LengthRestrictionListener.java
+++ /dev/null
@@ -1,179 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-import org.onosproject.yangutils.datamodel.YangDerivedInfo;
-import org.onosproject.yangutils.datamodel.YangRangeRestriction;
-import org.onosproject.yangutils.datamodel.YangStringRestriction;
-import org.onosproject.yangutils.datamodel.YangType;
-import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.datamodel.utils.YangConstructType;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BINARY;
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.DERIVED;
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.STRING;
-import static org.onosproject.yangutils.datamodel.utils.RestrictionResolver.processLengthRestriction;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.LENGTH_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.TYPE_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.INVALID_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_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
- *
- * ABNF grammar as per RFC6020
- * length-stmt = length-keyword sep length-arg-str optsep
- * (";" /
- * "{" stmtsep
- * ;; these stmts can appear in any order
- * [error-message-stmt stmtsep]
- * [error-app-tag-stmt stmtsep]
- * [description-stmt stmtsep]
- * [reference-stmt stmtsep]
- * "}")
- *
- *
- * ANTLR grammar rule
- * lengthStatement : LENGTH_KEYWORD length
- * (STMTEND | LEFT_CURLY_BRACE commonStatements RIGHT_CURLY_BRACE);
- */
-
-/**
- * Represents listener based call back function corresponding to the "length"
- * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
- */
-public final class LengthRestrictionListener {
-
- /**
- * Creates a new length restriction listener.
- */
- private LengthRestrictionListener() {
- }
-
- /**
- * It is called when parser receives an input matching the grammar
- * rule (length), performs validation and updates the data model
- * tree.
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processLengthRestrictionEntry(TreeWalkListener listener,
- GeneratedYangParser.LengthStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, LENGTH_DATA, ctx.length().getText(), ENTRY);
-
- Parsable tmpData = listener.getParsedDataStack().peek();
- if (tmpData.getYangConstructType() == TYPE_DATA) {
- YangType type = (YangType) tmpData;
- setLengthRestriction(listener, type, ctx);
- } else {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, LENGTH_DATA,
- ctx.length().getText(), ENTRY));
- }
- }
-
- /**
- * Sets the length restriction to type.
- *
- * @param listener listener's object
- * @param type Yang type for which length restriction to be set
- * @param ctx context object of the grammar rule
- */
- private static void setLengthRestriction(TreeWalkListener listener, YangType type,
- GeneratedYangParser.LengthStatementContext ctx) {
-
- if (type.getDataType() == DERIVED) {
- ((YangDerivedInfo<YangRangeRestriction>) type.getDataTypeExtendedInfo())
- .setLengthRestrictionString(ctx.length().getText());
- ((YangDerivedInfo<YangRangeRestriction>) type.getDataTypeExtendedInfo())
- .setLineNumber(ctx.getStart().getLine());
- ((YangDerivedInfo<YangRangeRestriction>) type.getDataTypeExtendedInfo())
- .setCharPosition(ctx.getStart().getCharPositionInLine());
- return;
- }
-
- if (type.getDataType() != STRING && type.getDataType() != BINARY) {
- ParserException parserException = new ParserException("YANG file error : " +
- YangConstructType.getYangConstructType(LENGTH_DATA) + " name " + ctx.length().getText() +
- " can be used to restrict the built-in type string/binary or types derived from string/binary.");
- parserException.setLine(ctx.getStart().getLine());
- parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
- throw parserException;
- }
-
- YangRangeRestriction lengthRestriction = null;
- try {
- lengthRestriction = processLengthRestriction(null, ctx.getStart().getLine(),
- ctx.getStart().getCharPositionInLine(), false, ctx.length().getText());
- } catch (DataModelException e) {
- ParserException parserException = new ParserException(e.getMessage());
- parserException.setCharPosition(e.getCharPositionInLine());
- parserException.setLine(e.getLineNumber());
- throw parserException;
- }
-
- if (type.getDataType() == STRING) {
- YangStringRestriction stringRestriction = (YangStringRestriction) type.getDataTypeExtendedInfo();
- if (stringRestriction == null) {
- stringRestriction = new YangStringRestriction();
- type.setDataTypeExtendedInfo(stringRestriction);
- }
-
- stringRestriction.setLengthRestriction(lengthRestriction);
- } else {
- type.setDataTypeExtendedInfo(lengthRestriction);
- }
-
- listener.getParsedDataStack().push(lengthRestriction);
- }
-
- /**
- * Performs validation and updates the data model tree.
- * It is called when parser exits from grammar rule (length).
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processLengthRestrictionExit(TreeWalkListener listener,
- GeneratedYangParser.LengthStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, LENGTH_DATA, ctx.length().getText(), EXIT);
-
- Parsable tmpData = listener.getParsedDataStack().peek();
- if (tmpData instanceof YangRangeRestriction) {
- listener.getParsedDataStack().pop();
- } else if (tmpData instanceof YangType
- && ((YangType) tmpData).getDataType() == DERIVED) {
- // TODO : need to handle in linker
- } else {
- throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, LENGTH_DATA,
- ctx.length().getText(), EXIT));
- }
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ListListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ListListener.java
deleted file mode 100644
index ab91675..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ListListener.java
+++ /dev/null
@@ -1,212 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-import org.onosproject.yangutils.datamodel.YangAugment;
-import org.onosproject.yangutils.datamodel.YangCase;
-import org.onosproject.yangutils.datamodel.YangContainer;
-import org.onosproject.yangutils.datamodel.YangGrouping;
-import org.onosproject.yangutils.datamodel.YangInput;
-import org.onosproject.yangutils.datamodel.YangList;
-import org.onosproject.yangutils.datamodel.YangModule;
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.YangNotification;
-import org.onosproject.yangutils.datamodel.YangOutput;
-import org.onosproject.yangutils.datamodel.YangSubModule;
-import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-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.ListenerValidation;
-
-import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.CONFIG_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.DATA_DEF_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.DESCRIPTION_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.KEY_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.LIST_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.MAX_ELEMENT_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.MIN_ELEMENT_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.REFERENCE_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.STATUS_DATA;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil;
-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.constructExtendedListenerErrorMessage;
-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_CURRENT_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.validateUniqueInList;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityNonZero;
-import static org.onosproject.yangutils.translator.tojava.YangDataModelFactory.getYangListNode;
-
-/*
- * Reference: RFC6020 and YANG ANTLR Grammar
- *
- * ABNF grammar as per RFC6020
- * list-stmt = list-keyword sep identifier-arg-str optsep
- * "{" stmtsep
- * ;; these stmts can appear in any order
- * [when-stmt stmtsep]
- * *(if-feature-stmt stmtsep)
- * *(must-stmt stmtsep)
- * [key-stmt stmtsep]
- * *(unique-stmt stmtsep)
- * [config-stmt stmtsep]
- * [min-elements-stmt stmtsep]
- * [max-elements-stmt stmtsep]
- * [ordered-by-stmt stmtsep]
- * [status-stmt stmtsep]
- * [description-stmt stmtsep]
- * [reference-stmt stmtsep]
- * *((typedef-stmt /
- * grouping-stmt) stmtsep)
- * 1*(data-def-stmt stmtsep)
- * "}"
- *
- * ANTLR grammar rule
- * listStatement : LIST_KEYWORD identifier LEFT_CURLY_BRACE (whenStatement | ifFeatureStatement | mustStatement |
- * keyStatement | uniqueStatement | configStatement | minElementsStatement | maxElementsStatement |
- * orderedByStatement | statusStatement | descriptionStatement | referenceStatement | typedefStatement |
- * groupingStatement| dataDefStatement)* RIGHT_CURLY_BRACE;
- */
-
-/**
- * Represents listener based call back function corresponding to the "list" rule
- * defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
- */
-public final class ListListener {
-
- /**
- * Creates a new list listener.
- */
- private ListListener() {
- }
-
- /**
- * It is called when parser receives an input matching the grammar rule
- * (list), performs validation and updates the data model tree.
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processListEntry(TreeWalkListener listener,
- GeneratedYangParser.ListStatementContext ctx) {
-
- YangNode curNode;
-
- checkStackIsNotEmpty(listener, MISSING_HOLDER, LIST_DATA, ctx.identifier().getText(), ENTRY);
-
- String identifier = getValidIdentifier(ctx.identifier().getText(), LIST_DATA, ctx);
-
- // Validate sub statement cardinality.
- validateSubStatementsCardinality(ctx);
-
- // Check for identifier collision
- int line = ctx.getStart().getLine();
- int charPositionInLine = ctx.getStart().getCharPositionInLine();
- detectCollidingChildUtil(listener, line, charPositionInLine, identifier, LIST_DATA);
-
- YangList yangList = getYangListNode(JAVA_GENERATION);
- yangList.setName(identifier);
- yangList.setLineNumber(line);
- yangList.setCharPosition(charPositionInLine);
- yangList.setFileName(listener.getFileName());
- /*
- * If "config" is not specified, the default is the same as the parent
- * schema node's "config" value.
- */
- if (ctx.configStatement().isEmpty()) {
- boolean parentConfig = ListenerValidation.getParentNodeConfig(listener);
- yangList.setConfig(parentConfig);
- }
-
- Parsable curData = listener.getParsedDataStack().peek();
- if (curData instanceof YangModule || curData instanceof YangContainer
- || curData instanceof YangList || curData instanceof YangCase
- || curData instanceof YangNotification || curData instanceof YangInput
- || curData instanceof YangOutput || curData instanceof YangAugment
- || curData instanceof YangGrouping || curData instanceof YangSubModule) {
- curNode = (YangNode) curData;
- try {
- curNode.addChild(yangList);
- } catch (DataModelException e) {
- throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
- LIST_DATA, ctx.identifier().getText(), ENTRY, e.getMessage()));
- }
- listener.getParsedDataStack().push(yangList);
- } else {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, LIST_DATA,
- ctx.identifier().getText(), ENTRY));
- }
- }
-
- /**
- * It is called when parser exits from grammar rule (list), it performs
- * validation and updates the data model tree.
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processListExit(TreeWalkListener listener,
- GeneratedYangParser.ListStatementContext ctx) {
-
- checkStackIsNotEmpty(listener, MISSING_HOLDER, LIST_DATA, ctx.identifier().getText(), EXIT);
-
- if (listener.getParsedDataStack().peek() instanceof YangList) {
- YangList yangList = (YangList) listener.getParsedDataStack().peek();
- try {
- yangList.validateDataOnExit();
- validateUniqueInList(yangList, ctx);
- } catch (DataModelException e) {
- ParserException parserException = new ParserException(constructExtendedListenerErrorMessage(
- UNHANDLED_PARSED_DATA, LIST_DATA, ctx.identifier().getText(), EXIT, e.getMessage()));
- parserException.setLine(ctx.getStart().getLine());
- parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
- throw parserException;
- }
- listener.getParsedDataStack().pop();
- } else {
- throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, LIST_DATA,
- ctx.identifier().getText(), EXIT));
- }
- }
-
- /**
- * Validates the cardinality of list sub-statements as per grammar.
- *
- * @param ctx context object of the grammar rule
- */
- private static void validateSubStatementsCardinality(GeneratedYangParser.ListStatementContext ctx) {
-
- validateCardinalityMaxOne(ctx.keyStatement(), KEY_DATA, LIST_DATA, ctx.identifier().getText());
- validateCardinalityMaxOne(ctx.configStatement(), CONFIG_DATA, LIST_DATA, ctx.identifier().getText());
- validateCardinalityMaxOne(ctx.maxElementsStatement(), MAX_ELEMENT_DATA, LIST_DATA, ctx.identifier().getText());
- validateCardinalityMaxOne(ctx.minElementsStatement(), MIN_ELEMENT_DATA, LIST_DATA, ctx.identifier().getText());
- validateCardinalityMaxOne(ctx.descriptionStatement(), DESCRIPTION_DATA, LIST_DATA, ctx.identifier().getText());
- validateCardinalityMaxOne(ctx.referenceStatement(), REFERENCE_DATA, LIST_DATA, ctx.identifier().getText());
- validateCardinalityMaxOne(ctx.statusStatement(), STATUS_DATA, LIST_DATA, ctx.identifier().getText());
- validateCardinalityNonZero(ctx.dataDefStatement(), DATA_DEF_DATA, LIST_DATA, ctx.identifier().getText(), ctx);
- //TODO when, typedef, grouping, unique
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/MandatoryListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/MandatoryListener.java
deleted file mode 100644
index b945f81..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/MandatoryListener.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-import org.onosproject.yangutils.datamodel.YangLeaf;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.MANDATORY_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.ListenerUtil.getValidBooleanValue;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-
-/*
- * Reference: RFC6020 and YANG ANTLR Grammar
- *
- * ABNF grammar as per RFC6020
- * mandatory-stmt = mandatory-keyword sep
- * mandatory-arg-str stmtend
- *
- * mandatory-arg-str = < a string that matches the rule
- * mandatory-arg >
- *
- * mandatory-arg = true-keyword / false-keyword
- *
- * ANTLR grammar rule
- * mandatoryStatement : MANDATORY_KEYWORD mandatory STMTEND;
- * mandatory : string;
- */
-
-/**
- * Represents listener based call back function corresponding to the "mandatory"
- * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
- */
-public final class MandatoryListener {
-
- /**
- * Creates a new mandatory listener.
- */
- private MandatoryListener() {
- }
-
- /**
- * It is called when parser receives an input matching the grammar
- * rule (mandatory), performs validation and updates the data model
- * tree.
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processMandatoryEntry(TreeWalkListener listener,
- GeneratedYangParser.MandatoryStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, MANDATORY_DATA, "", ENTRY);
-
- boolean isMandatory = getValidBooleanValue(ctx.mandatory().getText(), MANDATORY_DATA, ctx);
-
- Parsable tmpNode = listener.getParsedDataStack().peek();
- switch (tmpNode.getYangConstructType()) {
- case LEAF_DATA:
- YangLeaf leaf = (YangLeaf) tmpNode;
- leaf.setMandatory(isMandatory);
- break;
- case CHOICE_DATA: // TODO
- break;
- default:
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, MANDATORY_DATA, "", ENTRY));
- }
- }
-}
\ No newline at end of file
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/MaxElementsListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/MaxElementsListener.java
deleted file mode 100644
index 2f06387..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/MaxElementsListener.java
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-import org.onosproject.yangutils.datamodel.YangLeafList;
-import org.onosproject.yangutils.datamodel.YangList;
-import org.onosproject.yangutils.datamodel.YangMaxElement;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.datamodel.utils.YangConstructType;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.MAX_ELEMENT_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.ListenerUtil.removeQuotesAndHandleConcat;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-
-/*
- * Reference: RFC6020 and YANG ANTLR Grammar
- *
- * ABNF grammar as per RFC6020
- * max-elements-stmt = max-elements-keyword sep
- * max-value-arg-str stmtend
- * max-value-arg-str = < a string that matches the rule
- * max-value-arg >
- *
- * ANTLR grammar rule
- * maxElementsStatement : MAX_ELEMENTS_KEYWORD maxValue STMTEND;
- * maxValue : string;
- */
-
-/**
- * Represents listener based call back function corresponding to the
- * "max-elements" rule defined in ANTLR grammar file for corresponding ABNF rule
- * in RFC 6020.
- */
-public final class MaxElementsListener {
-
- private static final String POSITIVE_INTEGER_PATTERN = "[1-9][0-9]*";
- private static final String UNBOUNDED_KEYWORD = "unbounded";
-
- /**
- * Creates a new max-elements listener.
- */
- private MaxElementsListener() {
- }
-
- /**
- * It is called when parser receives an input matching the grammar rule
- * (max-elements), performs validation and updates the data model tree.
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processMaxElementsEntry(TreeWalkListener listener,
- GeneratedYangParser.MaxElementsStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, MAX_ELEMENT_DATA, "", ENTRY);
-
- int maxElementsValue = getValidMaxElementValue(ctx);
-
- YangMaxElement maxElement = new YangMaxElement();
- maxElement.setMaxElement(maxElementsValue);
-
- maxElement.setLineNumber(ctx.getStart().getLine());
- maxElement.setCharPosition(ctx.getStart().getCharPositionInLine());
- maxElement.setFileName(listener.getFileName());
- Parsable tmpData = listener.getParsedDataStack().peek();
- switch (tmpData.getYangConstructType()) {
- case LEAF_LIST_DATA:
- YangLeafList leafList = (YangLeafList) tmpData;
- leafList.setMaxElements(maxElement);
- break;
- case LIST_DATA:
- YangList yangList = (YangList) tmpData;
- yangList.setMaxElements(maxElement);
- break;
- default:
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, MAX_ELEMENT_DATA, "", ENTRY));
- }
- }
-
- /**
- * Validates max element value and returns the value from context.
- *
- * @param ctx context object of the grammar rule
- * @return max element's value
- */
- private static int getValidMaxElementValue(GeneratedYangParser.MaxElementsStatementContext ctx) {
-
- int maxElementsValue;
-
- String value = removeQuotesAndHandleConcat(ctx.maxValue().getText());
- if (value.equals(UNBOUNDED_KEYWORD)) {
- maxElementsValue = Integer.MAX_VALUE;
- } else if (value.matches(POSITIVE_INTEGER_PATTERN)) {
- try {
- maxElementsValue = Integer.parseInt(value);
- } catch (NumberFormatException e) {
- ParserException parserException = new ParserException("YANG file error : " +
- YangConstructType.getYangConstructType(
- MAX_ELEMENT_DATA) + " value " +
- value + " is not " +
- "valid.");
- parserException.setLine(ctx.getStart().getLine());
- parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
- throw parserException;
- }
- } else {
- ParserException parserException = new ParserException("YANG file error : " +
- YangConstructType.getYangConstructType(
- MAX_ELEMENT_DATA) + " value " +
- value + " is not " +
- "valid.");
- parserException.setLine(ctx.getStart().getLine());
- parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
- throw parserException;
- }
-
- return maxElementsValue;
- }
-
-}
\ No newline at end of file
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/MinElementsListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/MinElementsListener.java
deleted file mode 100644
index 27cd100..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/MinElementsListener.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-import org.onosproject.yangutils.datamodel.YangLeafList;
-import org.onosproject.yangutils.datamodel.YangList;
-import org.onosproject.yangutils.datamodel.YangMinElement;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.MIN_ELEMENT_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.ListenerUtil.getValidNonNegativeIntegerValue;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-
-/*
- * Reference: RFC6020 and YANG ANTLR Grammar
- *
- * ABNF grammar as per RFC6020
- * min-elements-stmt = min-elements-keyword sep
- * min-value-arg-str stmtend
- * min-value-arg-str = < a string that matches the rule
- * min-value-arg >
- * min-value-arg = non-negative-integer-value
- *
- * ANTLR grammar rule
- * minElementsStatement : MIN_ELEMENTS_KEYWORD minValue STMTEND;
- * minValue : string;
- */
-
-/**
- * Represents listener based call back function corresponding to the "min-elements"
- * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
- */
-public final class MinElementsListener {
-
- /**
- * Creates a new min-elements listener.
- */
- private MinElementsListener() {
- }
-
- /**
- * It is called when parser receives an input matching the grammar
- * rule (min-elements), performs validation and updates the data model
- * tree.
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processMinElementsEntry(TreeWalkListener listener,
- GeneratedYangParser.MinElementsStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, MIN_ELEMENT_DATA, ctx.minValue().getText(), ENTRY);
-
- int minElementValue = getValidNonNegativeIntegerValue(ctx.minValue().getText(), MIN_ELEMENT_DATA, ctx);
-
- YangMinElement minElement = new YangMinElement();
-
- minElement.setMinElement(minElementValue);
- minElement.setLineNumber(ctx.getStart().getLine());
- minElement.setCharPosition(ctx.getStart().getCharPositionInLine());
- minElement.setFileName(listener.getFileName());
- Parsable tmpData = listener.getParsedDataStack().peek();
- switch (tmpData.getYangConstructType()) {
- case LEAF_LIST_DATA:
- YangLeafList leafList = (YangLeafList) tmpData;
- leafList.setMinElements(minElement);
- break;
- case LIST_DATA:
- YangList yangList = (YangList) tmpData;
- yangList.setMinElements(minElement);
- break;
- default:
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, MIN_ELEMENT_DATA,
- ctx.minValue().getText(), ENTRY));
- }
- }
-
-}
\ No newline at end of file
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ModuleListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ModuleListener.java
deleted file mode 100644
index 02389a1..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ModuleListener.java
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-import org.onosproject.yangutils.datamodel.ResolvableType;
-import org.onosproject.yangutils.datamodel.YangModule;
-import org.onosproject.yangutils.datamodel.YangReferenceResolver;
-import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.linker.exceptions.LinkerException;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.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.INVALID_CHILD;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsEmpty;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-import static org.onosproject.yangutils.translator.tojava.YangDataModelFactory.getYangModuleNode;
-
-/*
- * Reference: RFC6020 and YANG ANTLR Grammar
- *
- * ABNF grammar as per RFC6020
- * module-stmt = optsep module-keyword sep identifier-arg-str
- * optsep
- * "{" stmtsep
- * module-header-stmts
- * linkage-stmts
- * meta-stmts
- * revision-stmts
- * body-stmts
- * "}" optsep
- *
- * ANTLR grammar rule
- * module_stmt : MODULE_KEYWORD identifier LEFT_CURLY_BRACE module_body* RIGHT_CURLY_BRACE;
- */
-
-/**
- * Represents listener based call back function corresponding to the "module"
- * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
- */
-public final class ModuleListener {
-
- /**
- * Creates a new module listener.
- */
- private ModuleListener() {
- }
-
- /**
- * 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
- */
- public static void processModuleEntry(TreeWalkListener listener, GeneratedYangParser.ModuleStatementContext ctx) {
-
- // Check if stack is empty.
- checkStackIsEmpty(listener, INVALID_HOLDER, MODULE_DATA, ctx.identifier().getText(), ENTRY);
-
- String identifier = getValidIdentifier(ctx.identifier().getText(), MODULE_DATA, ctx);
-
- YangModule yangModule = getYangModuleNode(JAVA_GENERATION);
- yangModule.setName(identifier);
- yangModule.setLineNumber(ctx.getStart().getLine());
- yangModule.setCharPosition(ctx.getStart().getCharPositionInLine());
- yangModule.setFileName(listener.getFileName());
-
- if (ctx.moduleBody().moduleHeaderStatement().yangVersionStatement() == null) {
- yangModule.setVersion((byte) 1);
- }
-
- listener.getParsedDataStack().push(yangModule);
- }
-
- /**
- * It is called when parser exits from grammar rule (module), it perform
- * validations and update the data model tree.
- *
- * @param listener Listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processModuleExit(TreeWalkListener listener, GeneratedYangParser.ModuleStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, MODULE_DATA, ctx.identifier().getText(), EXIT);
-
- Parsable tmpNode = listener.getParsedDataStack().peek();
- if (!(tmpNode instanceof YangModule)) {
- throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, MODULE_DATA,
- ctx.identifier().getText(), EXIT));
- }
-
- YangModule module = (YangModule) tmpNode;
- if (module.getUnresolvedResolutionList(ResolvableType.YANG_COMPILER_ANNOTATION) != null
- && module.getUnresolvedResolutionList(ResolvableType.YANG_COMPILER_ANNOTATION).size() != 0
- && module.getChild() != null) {
- throw new ParserException(constructListenerErrorMessage(INVALID_CHILD, MODULE_DATA,
- ctx.identifier().getText(), EXIT));
- }
-
- try {
- ((YangReferenceResolver) listener.getParsedDataStack()
- .peek()).resolveSelfFileLinking(ResolvableType.YANG_IF_FEATURE);
- ((YangReferenceResolver) listener.getParsedDataStack()
- .peek()).resolveSelfFileLinking(ResolvableType.YANG_USES);
- ((YangReferenceResolver) listener.getParsedDataStack()
- .peek()).resolveSelfFileLinking(ResolvableType.YANG_DERIVED_DATA_TYPE);
- ((YangReferenceResolver) listener.getParsedDataStack()
- .peek()).resolveSelfFileLinking(ResolvableType.YANG_LEAFREF);
- ((YangReferenceResolver) listener.getParsedDataStack()
- .peek()).resolveSelfFileLinking(ResolvableType.YANG_BASE);
- ((YangReferenceResolver) listener.getParsedDataStack()
- .peek()).resolveSelfFileLinking(ResolvableType.YANG_IDENTITYREF);
- } catch (DataModelException e) {
- LinkerException linkerException = new LinkerException(e.getMessage());
- linkerException.setLine(e.getLineNumber());
- linkerException.setCharPosition(e.getCharPositionInLine());
- linkerException.setFileName(listener.getFileName());
- throw linkerException;
- }
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/MustListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/MustListener.java
deleted file mode 100644
index 421ede1..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/MustListener.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-import org.onosproject.yangutils.datamodel.YangMust;
-import org.onosproject.yangutils.datamodel.YangMustHolder;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.MUST_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.INVALID_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.removeQuotesAndHandleConcat;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-
-/*
- * Reference: RFC6020 and YANG ANTLR Grammar
- *
- * ABNF grammar as per RFC6020
- *
- * must-stmt = must-keyword sep string optsep
- * (";" /
- * "{" stmtsep
- * ;; these stmts can appear in any order
- * [error-message-stmt stmtsep]
- * [error-app-tag-stmt stmtsep]
- * [description-stmt stmtsep]
- * [reference-stmt stmtsep]
- * "}")
- *
- * ANTLR grammar rule
- * mustStatement : MUST_KEYWORD string (STMTEND | LEFT_CURLY_BRACE commonStatements RIGHT_CURLY_BRACE);
- */
-
-/**
- * Represents listener based call back function corresponding to the
- * "must" rule defined in ANTLR grammar file for corresponding ABNF rule
- * in RFC 6020.
- */
-public final class MustListener {
-
- /**
- * Creates a new must listener.
- */
- private MustListener() {
- }
-
- /**
- * Perform validations and updates the data model tree.It is called when parser
- * receives an input matching the grammar rule (must).
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processMustEntry(TreeWalkListener listener,
- GeneratedYangParser.MustStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, MUST_DATA, ctx.string().getText(), ENTRY);
- String constraint = removeQuotesAndHandleConcat(ctx.string().getText());
-
- // Obtain the node of the stack.
- Parsable tmpNode = listener.getParsedDataStack().peek();
- if (tmpNode instanceof YangMustHolder) {
-
- YangMust must = new YangMust();
- must.setConstraint(constraint);
-
- must.setLineNumber(ctx.getStart().getLine());
- must.setCharPosition(ctx.getStart().getCharPositionInLine());
- must.setFileName(listener.getFileName());
- YangMustHolder mustHolder = (YangMustHolder) tmpNode;
- mustHolder.addMust(must);
-
- listener.getParsedDataStack().push(must);
- } else {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, MUST_DATA,
- ctx.string().getText(), ENTRY));
- }
-
- }
-
- /**
- * Performs validation and updates the data model tree.It is called when parser
- * exits from grammar rule (must).
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processMustExit(TreeWalkListener listener,
- GeneratedYangParser.MustStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, MUST_DATA, ctx.string().getText(), EXIT);
-
- if (listener.getParsedDataStack().peek() instanceof YangMust) {
- listener.getParsedDataStack().pop();
- } else {
- throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, MUST_DATA,
- ctx.string().getText(), EXIT));
- }
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/NamespaceListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/NamespaceListener.java
deleted file mode 100644
index 6bfaf50..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/NamespaceListener.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-import java.net.URI;
-import org.onosproject.yangutils.datamodel.YangModule;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.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.ListenerUtil.removeQuotesAndHandleConcat;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-
-/*
- * Reference: RFC6020 and YANG ANTLR Grammar
- *
- * ABNF grammar as per RFC6020
- * module-header-stmts = ;; these stmts can appear in any order
- * [yang-version-stmt stmtsep]
- * namespace-stmt stmtsep
- * prefix-stmt stmtsep
- *
- * namespace-stmt = namespace-keyword sep uri-str optsep stmtend
- *
- * ANTLR grammar rule
- * module_header_statement : yang_version_stmt? namespace_stmt prefix_stmt
- * | yang_version_stmt? prefix_stmt namespace_stmt
- * | namespace_stmt yang_version_stmt? prefix_stmt
- * | namespace_stmt prefix_stmt yang_version_stmt?
- * | prefix_stmt namespace_stmt yang_version_stmt?
- * | prefix_stmt yang_version_stmt? namespace_stmt
- * ;
- * namespace_stmt : NAMESPACE_KEYWORD string STMTEND;
- */
-
-/**
- * Represents listener based call back function corresponding to the "namespace"
- * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
- */
-public final class NamespaceListener {
-
- /**
- * Creates a new namespace listener.
- */
- private NamespaceListener() {
- }
-
- /**
- * 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
- */
- public static void processNamespaceEntry(TreeWalkListener listener,
- GeneratedYangParser.NamespaceStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, NAMESPACE_DATA, ctx.string().getText(), ENTRY);
-
- if (!validateUriValue(ctx.string().getText())) {
- ParserException parserException = new ParserException("YANG file error: Invalid namespace URI");
- parserException.setLine(ctx.string().STRING(0).getSymbol().getLine());
- parserException.setCharPosition(ctx.string().STRING(0).getSymbol().getCharPositionInLine());
- throw parserException;
- }
-
- // Obtain the node of the stack.
- Parsable tmpNode = listener.getParsedDataStack().peek();
- switch (tmpNode.getYangConstructType()) {
- case MODULE_DATA: {
- YangModule module = (YangModule) tmpNode;
- module.setModuleNamespace(removeQuotesAndHandleConcat(ctx.string().getText()));
- break;
- }
- default:
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, NAMESPACE_DATA,
- ctx.string().getText(), ENTRY));
- }
- }
-
- /**
- * Validate input URI.
- *
- * @param uri input namespace URI
- * @return validation result
- */
- private static boolean validateUriValue(String uri) {
- uri = uri.replace("\"", "");
- try {
- URI.create(uri);
- } catch (Exception e1) {
- return false;
- }
- return true;
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/NotificationListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/NotificationListener.java
deleted file mode 100644
index 6109518..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/NotificationListener.java
+++ /dev/null
@@ -1,173 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-import org.onosproject.yangutils.datamodel.RpcNotificationContainer;
-import org.onosproject.yangutils.datamodel.YangModule;
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.YangNotification;
-import org.onosproject.yangutils.datamodel.YangSubModule;
-import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.DESCRIPTION_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.NOTIFICATION_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.REFERENCE_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.STATUS_DATA;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil;
-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.constructExtendedListenerErrorMessage;
-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_CURRENT_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne;
-import static org.onosproject.yangutils.translator.tojava.YangDataModelFactory.getYangNotificationNode;
-
-/*
- * Reference: RFC6020 and YANG ANTLR Grammar
- *
- * ABNF grammar as per RFC6020
- * notification-stmt = notification-keyword sep
- * identifier-arg-str optsep
- * (";" /
- * "{" stmtsep
- * ;; these stmts can appear in any order
- * *(if-feature-stmt stmtsep)
- * [status-stmt stmtsep]
- * [description-stmt stmtsep]
- * [reference-stmt stmtsep]
- * *((typedef-stmt /
- * grouping-stmt) stmtsep)
- * *(data-def-stmt stmtsep)
- * "}")
- *
- * ANTLR grammar rule
- * notificationStatement : NOTIFICATION_KEYWORD identifier (STMTEND | LEFT_CURLY_BRACE (ifFeatureStatement
- * | statusStatement | descriptionStatement | referenceStatement | typedefStatement
- * | groupingStatement | dataDefStatement)* RIGHT_CURLY_BRACE);
- */
-
-/**
- * Represents listener based call back function corresponding to the "notification"
- * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
- */
-public final class NotificationListener {
-
- /**
- * Creates a new notification listener.
- */
- private NotificationListener() {
- }
-
- /**
- * It is called when parser receives an input matching the grammar rule
- * (notification), performs validation and updates the data model tree.
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processNotificationEntry(TreeWalkListener listener,
- GeneratedYangParser.NotificationStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, NOTIFICATION_DATA,
- ctx.identifier().getText(), ENTRY);
-
- String identifier = getValidIdentifier(ctx.identifier().getText(),
- NOTIFICATION_DATA, ctx);
-
- // Validate sub statement cardinality.
- validateSubStatementsCardinality(ctx);
-
- // Check for identifier collision
- int line = ctx.getStart().getLine();
- int charPositionInLine = ctx.getStart().getCharPositionInLine();
- detectCollidingChildUtil(listener, line, charPositionInLine, identifier,
- NOTIFICATION_DATA);
-
- Parsable curData = listener.getParsedDataStack().peek();
- if (curData instanceof YangModule || curData instanceof YangSubModule) {
-
- YangNotification notification = getYangNotificationNode(JAVA_GENERATION);
- notification.setName(identifier);
-
- notification.setLineNumber(ctx.getStart().getLine());
- notification.setCharPosition(ctx.getStart().getCharPositionInLine());
- notification.setFileName(listener.getFileName());
- ((RpcNotificationContainer) curData).setNotificationPresenceFlag(true);
- YangNode curNode = (YangNode) curData;
- try {
- curNode.addChild(notification);
- } catch (DataModelException e) {
- throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
- NOTIFICATION_DATA, ctx.identifier().getText(), ENTRY, e.getMessage()));
- }
- listener.getParsedDataStack().push(notification);
- } else {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, NOTIFICATION_DATA,
- ctx.identifier().getText(), ENTRY));
- }
- }
-
- /**
- * It is called when parser exits from grammar rule (notification), it perform
- * validations and updates the data model tree.
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processNotificationExit(TreeWalkListener listener,
- GeneratedYangParser.NotificationStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, NOTIFICATION_DATA,
- ctx.identifier().getText(), EXIT);
-
- if (listener.getParsedDataStack().peek() instanceof YangNotification) {
- listener.getParsedDataStack().pop();
- } else {
- throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, NOTIFICATION_DATA,
- ctx.identifier().getText(), EXIT));
- }
- }
-
- /**
- * Validates the cardinality of notification sub-statements as per grammar.
- *
- * @param ctx context object of the grammar rule
- */
- private static void validateSubStatementsCardinality(GeneratedYangParser.NotificationStatementContext ctx) {
-
- validateCardinalityMaxOne(ctx.statusStatement(), STATUS_DATA,
- NOTIFICATION_DATA, ctx.identifier().getText());
- validateCardinalityMaxOne(ctx.descriptionStatement(),
- DESCRIPTION_DATA, NOTIFICATION_DATA,
- ctx.identifier().getText());
- validateCardinalityMaxOne(ctx.referenceStatement(), REFERENCE_DATA,
- NOTIFICATION_DATA,
- ctx.identifier().getText());
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/OrganizationListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/OrganizationListener.java
deleted file mode 100644
index 20a42c1..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/OrganizationListener.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-import org.onosproject.yangutils.datamodel.YangModule;
-import org.onosproject.yangutils.datamodel.YangSubModule;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.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
- *
- * ABNF grammar as per RFC6020
- * meta-stmts = ;; these stmts can appear in any order
- * [organization-stmt stmtsep]
- * [contact-stmt stmtsep]
- * [description-stmt stmtsep]
- * [reference-stmt stmtsep]
- * organization-stmt = organization-keyword sep string
- * optsep stmtend
- *
- * ANTLR grammar rule
- * meta_stmts : organization_stmt? contact_stmt? description_stmt? reference_stmt?
- * | organization_stmt? contact_stmt? reference_stmt? description_stmt?
- * | organization_stmt? description_stmt? contact_stmt? reference_stmt?
- * | organization_stmt? description_stmt? reference_stmt? contact_stmt?
- * | organization_stmt? reference_stmt? contact_stmt? description_stmt?
- * | organization_stmt? reference_stmt? description_stmt? contact_stmt?
- * | contact_stmt? organization_stmt? description_stmt? reference_stmt?
- * | contact_stmt? organization_stmt? reference_stmt? description_stmt?
- * | contact_stmt? reference_stmt? organization_stmt? description_stmt?
- * | contact_stmt? reference_stmt? description_stmt? organization_stmt?
- * | contact_stmt? description_stmt? reference_stmt? organization_stmt?
- * | contact_stmt? description_stmt? organization_stmt? reference_stmt?
- * | reference_stmt? contact_stmt? organization_stmt? description_stmt?
- * | reference_stmt? contact_stmt? description_stmt? organization_stmt?
- * | reference_stmt? organization_stmt? contact_stmt? description_stmt?
- * | reference_stmt? organization_stmt? description_stmt? contact_stmt?
- * | reference_stmt? description_stmt? organization_stmt? contact_stmt?
- * | reference_stmt? description_stmt? contact_stmt? organization_stmt?
- * | description_stmt? reference_stmt? contact_stmt? organization_stmt?
- * | description_stmt? reference_stmt? organization_stmt? contact_stmt?
- * | description_stmt? contact_stmt? reference_stmt? organization_stmt?
- * | description_stmt? contact_stmt? organization_stmt? reference_stmt?
- * | description_stmt? organization_stmt? contact_stmt? reference_stmt?
- * | description_stmt? organization_stmt? reference_stmt? contact_stmt?
- * ;
- * organization_stmt : ORGANIZATION_KEYWORD string STMTEND;
- */
-
-/**
- * Represents 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 {
-
- /**
- * Creates a new organization listener.
- */
- private OrganizationListener() {
- }
-
- /**
- * 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
- */
- public static void processOrganizationEntry(TreeWalkListener listener,
- GeneratedYangParser.OrganizationStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, ORGANIZATION_DATA, ctx.string().getText(),
- ENTRY);
-
- // Obtain the node of the stack.
- Parsable tmpNode = listener.getParsedDataStack().peek();
- switch (tmpNode.getYangConstructType()) {
- case MODULE_DATA: {
- YangModule module = (YangModule) tmpNode;
- module.setOrganization(ctx.string().getText());
- break;
- }
- case SUB_MODULE_DATA: {
- YangSubModule subModule = (YangSubModule) tmpNode;
- subModule.setOrganization(ctx.string().getText());
- break;
- }
- default:
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, ORGANIZATION_DATA,
- ctx.string().getText(), ENTRY));
- }
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/OutputListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/OutputListener.java
deleted file mode 100644
index 6ae74b8..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/OutputListener.java
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.YangOutput;
-import org.onosproject.yangutils.datamodel.YangRpc;
-import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.OUTPUT_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
- .constructExtendedListenerErrorMessage;
-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_CURRENT_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-import static org.onosproject.yangutils.translator.tojava.YangDataModelFactory.getYangOutputNode;
-import static org.onosproject.yangutils.utils.UtilConstants.OUTPUT;
-
-/*
- * Reference: RFC6020 and YANG ANTLR Grammar
- *
- * ABNF grammar as per RFC6020
- *
- * output-stmt = output-keyword optsep
- * "{" stmtsep
- * ;; these stmts can appear in any order
- * *((typedef-stmt /
- * grouping-stmt) stmtsep)
- * 1*(data-def-stmt stmtsep)
- * "}"
- *
- * outputStatement : OUTPUT_KEYWORD LEFT_CURLY_BRACE outputStatementBody RIGHT_CURLY_BRACE;
-
- * outputStatementBody : typedefStatement* dataDefStatement+
- * | dataDefStatement+ typedefStatement*
- * | groupingStatement* dataDefStatement+
- * | dataDefStatement+ groupingStatement*;
- */
-
-/**
- * Represents listener based call back function corresponding to the "output"
- * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
- */
-public final class OutputListener {
-
- /**
- * Creates a new output listener.
- */
- private OutputListener() {
- }
-
- /**
- * It is called when parser receives an input matching the grammar rule
- * (output), performs validation and updates the data model tree.
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processOutputEntry(TreeWalkListener listener,
- GeneratedYangParser.OutputStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, OUTPUT_DATA, "", ENTRY);
-
- Parsable curData = listener.getParsedDataStack().peek();
- if (curData instanceof YangRpc) {
-
- YangOutput yangOutput = getYangOutputNode(JAVA_GENERATION);
- yangOutput.setName(OUTPUT);
- yangOutput.setLineNumber(ctx.getStart().getLine());
- yangOutput.setCharPosition(ctx.getStart().getCharPositionInLine());
- yangOutput.setFileName(listener.getFileName());
- YangNode curNode = (YangNode) curData;
- try {
- curNode.addChild(yangOutput);
- } catch (DataModelException e) {
- throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
- OUTPUT_DATA, "", ENTRY, e.getMessage()));
- }
- listener.getParsedDataStack().push(yangOutput);
- } else {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, OUTPUT_DATA,
- "", ENTRY));
- }
- }
-
- /**
- * It is called when parser exits from grammar rule (output), it perform
- * validations and updates the data model tree.
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processOutputExit(TreeWalkListener listener,
- GeneratedYangParser.OutputStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, OUTPUT_DATA, "", EXIT);
-
- if (!(listener.getParsedDataStack().peek() instanceof YangOutput)) {
- throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, OUTPUT_DATA,
- "", EXIT));
- }
- listener.getParsedDataStack().pop();
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/PathListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/PathListener.java
deleted file mode 100644
index b02c6f4..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/PathListener.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-import org.onosproject.yangutils.datamodel.YangLeafRef;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.validatePathArgument;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.PATH_DATA;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
-
-/*
- * Reference: RFC6020 and YANG ANTLR Grammar
- *
- * ABNF grammar as per RFC6020
- * leafref-specification =
- * ;; these stmts can appear in any order
- * path-stmt stmtsep
- * [require-instance-stmt stmtsep]
- *
- * path-stmt = path-keyword sep path-arg-str stmtend
- *
- * ANTLR grammar rule
- *
- * leafrefSpecification : (pathStatement (requireInstanceStatement)?) | ((requireInstanceStatement)? pathStatement);
- *
- * pathStatement : PATH_KEYWORD path STMTEND;
- */
-
-/**
- * Represents listener based call back function corresponding to the
- * "path" rule defined in ANTLR grammar file for corresponding ABNF rule
- * in RFC 6020.
- */
-public final class PathListener {
-
- /**
- * Creates a new path listener.
- */
- private PathListener() {
- }
-
- /**
- * It is called when parser receives an input matching the grammar rule
- * (path), performs validation and updates the data model tree.
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processPathEntry(TreeWalkListener listener,
- GeneratedYangParser.PathStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, PATH_DATA, ctx.path().getText(), ENTRY);
-
- Parsable curData = listener.getParsedDataStack().peek();
-
- // Checks the holder of path as leafref, else throws error.
- if (curData instanceof YangLeafRef) {
-
- // Splitting the path argument and updating it in the datamodel tree.
- validatePathArgument(ctx.path().getText(), PATH_DATA, ctx, (YangLeafRef) curData);
- } else {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, PATH_DATA,
- ctx.path().getText(), ENTRY));
- }
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/PatternRestrictionListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/PatternRestrictionListener.java
deleted file mode 100644
index 0d6d1f4..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/PatternRestrictionListener.java
+++ /dev/null
@@ -1,191 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-import java.util.regex.Pattern;
-import java.util.regex.PatternSyntaxException;
-import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
-import org.onosproject.yangutils.datamodel.YangDerivedInfo;
-import org.onosproject.yangutils.datamodel.YangPatternRestriction;
-import org.onosproject.yangutils.datamodel.YangStringRestriction;
-import org.onosproject.yangutils.datamodel.YangType;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.datamodel.utils.YangConstructType;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.DERIVED;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.PATTERN_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.TYPE_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.INVALID_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_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
- *
- * ABNF grammar as per RFC6020
- * pattern-stmt = pattern-keyword sep string optsep
- * (";" /
- * "{" stmtsep
- * ;; these stmts can appear in any order
- * [error-message-stmt stmtsep]
- * [error-app-tag-stmt stmtsep]
- * [description-stmt stmtsep]
- * [reference-stmt stmtsep]
- * "}")
- *
- * ANTLR grammar rule
- * patternStatement : PATTERN_KEYWORD string (STMTEND | LEFT_CURLY_BRACE commonStatements RIGHT_CURLY_BRACE);
- */
-
-/**
- * Represents listener based call back function corresponding to the "pattern"
- * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
- */
-public final class PatternRestrictionListener {
-
- private static final String EMPTY_STRING = "";
-
- /**
- * Creates a new pattern restriction listener.
- */
- private PatternRestrictionListener() {
- }
-
- /**
- * It is called when parser receives an input matching the grammar
- * rule (pattern), performs validation and updates the data model
- * tree.
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processPatternRestrictionEntry(TreeWalkListener listener,
- GeneratedYangParser.PatternStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, PATTERN_DATA, ctx.string().getText(), ENTRY);
-
- Parsable tmpData = listener.getParsedDataStack().peek();
- if (tmpData.getYangConstructType() == TYPE_DATA) {
- YangType type = (YangType) tmpData;
- setPatternRestriction(listener, type, ctx);
- } else {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, PATTERN_DATA,
- ctx.string().getText(), ENTRY));
- }
- }
-
- /**
- * Sets the pattern restriction to type.
- *
- * @param listener listener's object
- * @param type Yang type for which pattern restriction to be set
- * @param ctx context object of the grammar rule
- */
- private static void setPatternRestriction(TreeWalkListener listener, YangType type,
- GeneratedYangParser.PatternStatementContext ctx) {
-
- if (type.getDataType() != YangDataTypes.STRING && type.getDataType() != YangDataTypes.DERIVED) {
-
- ParserException parserException = new ParserException("YANG file error : " +
- YangConstructType.getYangConstructType(PATTERN_DATA) + " name " + ctx.string().getText() +
- " can be used to restrict the built-in type string or types derived from string.");
- parserException.setLine(ctx.getStart().getLine());
- parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
- throw parserException;
- }
-
- // Validate and get valid pattern restriction string.
- String patternArgument = getValidPattern(ctx);
-
- if (type.getDataType() == YangDataTypes.STRING) {
- YangStringRestriction stringRestriction = (YangStringRestriction) type.getDataTypeExtendedInfo();
- if (stringRestriction == null) {
- stringRestriction = new YangStringRestriction();
- type.setDataTypeExtendedInfo(stringRestriction);
- stringRestriction.addPattern(patternArgument);
- } else {
- stringRestriction.addPattern(patternArgument);
- }
- listener.getParsedDataStack().push(stringRestriction);
- } else {
- YangPatternRestriction patternRestriction = (YangPatternRestriction) ((YangDerivedInfo<?>) type
- .getDataTypeExtendedInfo()).getPatternRestriction();
- if (patternRestriction == null) {
- patternRestriction = new YangPatternRestriction();
- ((YangDerivedInfo<?>) type.getDataTypeExtendedInfo()).setPatternRestriction(patternRestriction);
- patternRestriction.addPattern(patternArgument);
- } else {
- ((YangDerivedInfo<?>) type.getDataTypeExtendedInfo()).setPatternRestriction(patternRestriction);
- patternRestriction.addPattern(patternArgument);
- }
- }
- }
-
- /**
- * Performs validation and updates the data model tree.
- * It is called when parser exits from grammar rule (pattern).
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processPatternRestrictionExit(TreeWalkListener listener,
- GeneratedYangParser.PatternStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, PATTERN_DATA, ctx.string().getText(), EXIT);
-
- Parsable tmpData = listener.getParsedDataStack().peek();
- if (tmpData instanceof YangStringRestriction) {
- listener.getParsedDataStack().pop();
- } else if (tmpData instanceof YangType
- && ((YangType) tmpData).getDataType() == DERIVED) {
- // TODO : need to handle in linker
- } else {
- throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, PATTERN_DATA,
- ctx.string().getText(), EXIT));
- }
- }
-
- /**
- * Validates and return the valid pattern.
- *
- * @param ctx context object of the grammar rule
- * @return validated string
- */
- private static String getValidPattern(GeneratedYangParser.PatternStatementContext ctx) {
- String userInputPattern = ctx.string().getText().replace("\"", EMPTY_STRING);
- try {
- Pattern.compile(userInputPattern);
- } catch (PatternSyntaxException exception) {
- ParserException parserException = new ParserException("YANG file error : " +
- YangConstructType.getYangConstructType(PATTERN_DATA) + " name " + ctx.string().getText() +
- " is not a valid regular expression");
- parserException.setLine(ctx.getStart().getLine());
- parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
- throw parserException;
- }
- return userInputPattern;
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/PositionListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/PositionListener.java
deleted file mode 100644
index 3a14927..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/PositionListener.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-/*
- * Reference: RFC6020 and YANG ANTLR Grammar
- *
- * ABNF grammar as per RFC6020
- * position-stmt = position-keyword sep
- * position-value-arg-str stmtend
- * position-value-arg-str = < a string that matches the rule
- * position-value-arg >
- * position-value-arg = non-negative-integer-value
- * non-negative-integer-value = "0" / positive-integer-value
- * positive-integer-value = (non-zero-digit *DIGIT)
- * zero-integer-value = 1*DIGIT
- *
- * ANTLR grammar rule
- * positionStatement : POSITION_KEYWORD position STMTEND;
- * position : string;
- */
-
-import org.onosproject.yangutils.datamodel.YangBit;
-import org.onosproject.yangutils.datamodel.YangBits;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.POSITION_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.ListenerUtil.getValidNonNegativeIntegerValue;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-
-/**
- * Represents listener based call back function corresponding to the "position"
- * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
- */
-public final class PositionListener {
-
- /**
- * Creates a new position listener.
- */
- private PositionListener() {
- }
-
- /**
- * It is called when parser receives an input matching the grammar rule
- * (position), perform validations and update the data model tree.
- *
- * @param listener Listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processPositionEntry(TreeWalkListener listener,
- GeneratedYangParser.PositionStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, POSITION_DATA, ctx.position().getText(), ENTRY);
-
- // Obtain the node of the stack.
- Parsable tmpNode = listener.getParsedDataStack().peek();
- switch (tmpNode.getYangConstructType()) {
- case BIT_DATA: {
- YangBit bitNode = (YangBit) tmpNode;
- int positionValue = getValidBitPosition(listener, ctx);
- bitNode.setPosition(positionValue);
- break;
- }
- default:
- throw new ParserException(
- constructListenerErrorMessage(INVALID_HOLDER, POSITION_DATA, ctx.position().getText(), ENTRY));
- }
- }
-
- /**
- * Validates BITS position value correctness and uniqueness.
- *
- * @param listener Listener's object
- * @param ctx context object of the grammar rule
- * @return position value
- */
- private static int getValidBitPosition(TreeWalkListener listener,
- GeneratedYangParser.PositionStatementContext ctx) {
- Parsable bitNode = listener.getParsedDataStack().pop();
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, POSITION_DATA, ctx.position().getText(), ENTRY);
-
- int positionValue = getValidNonNegativeIntegerValue(ctx.position().getText(), POSITION_DATA, ctx);
-
- Parsable tmpNode = listener.getParsedDataStack().peek();
- switch (tmpNode.getYangConstructType()) {
- case BITS_DATA: {
- YangBits yangBits = (YangBits) tmpNode;
- listener.getParsedDataStack().push(bitNode);
- if (yangBits.isBitPositionExists(positionValue)) {
- ParserException parserException = new ParserException("YANG file error: Duplicate value of " +
- "position is invalid.");
- parserException.setLine(ctx.getStart().getLine());
- parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
- throw parserException;
- }
- return positionValue;
- }
- default:
- listener.getParsedDataStack().push(bitNode);
- throw new ParserException(
- constructListenerErrorMessage(INVALID_HOLDER, POSITION_DATA, ctx.position().getText(), ENTRY));
- }
- }
-}
\ No newline at end of file
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/PrefixListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/PrefixListener.java
deleted file mode 100644
index b75f77c..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/PrefixListener.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-import org.onosproject.yangutils.datamodel.YangBelongsTo;
-import org.onosproject.yangutils.datamodel.YangImport;
-import org.onosproject.yangutils.datamodel.YangModule;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.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.ListenerUtil.getValidIdentifier;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-
-/*
- * Reference: RFC6020 and YANG ANTLR Grammar
- *
- * ABNF grammar as per RFC6020
- * module-header-stmts = ;; these stmts can appear in any order
- * [yang-version-stmt stmtsep]
- * namespace-stmt stmtsep
- * prefix-stmt stmtsep
- *
- * prefix-stmt = prefix-keyword sep prefix-arg-str
- * optsep stmtend
- *
- * ANTLR grammar rule
- * module_header_statement : yang_version_stmt? namespace_stmt prefix_stmt
- * | yang_version_stmt? prefix_stmt namespace_stmt
- * | namespace_stmt yang_version_stmt? prefix_stmt
- * | namespace_stmt prefix_stmt yang_version_stmt?
- * | prefix_stmt namespace_stmt yang_version_stmt?
- * | prefix_stmt yang_version_stmt? namespace_stmt
- * ;
- * prefix_stmt : PREFIX_KEYWORD identifier STMTEND;
- */
-
-/**
- * Represents listener based call back function corresponding to the "prefix"
- * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
- */
-public final class PrefixListener {
-
- /**
- * Creates a new prefix listener.
- */
- private PrefixListener() {
- }
-
- /**
- * 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
- */
- public static void processPrefixEntry(TreeWalkListener listener, GeneratedYangParser.PrefixStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, PREFIX_DATA, ctx.identifier().getText(), ENTRY);
-
- String identifier = getValidIdentifier(ctx.identifier().getText(), PREFIX_DATA, ctx);
-
- // Obtain the node of the stack.
- Parsable tmpNode = listener.getParsedDataStack().peek();
- switch (tmpNode.getYangConstructType()) {
- case MODULE_DATA: {
- YangModule module = (YangModule) tmpNode;
- module.setPrefix(identifier);
- break;
- }
- case IMPORT_DATA: {
- YangImport importNode = (YangImport) tmpNode;
- importNode.setPrefixId(identifier);
- break;
- }
- case BELONGS_TO_DATA: {
- YangBelongsTo belongstoNode = (YangBelongsTo) tmpNode;
- belongstoNode.setPrefix(identifier);
- break;
- }
- default:
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, PREFIX_DATA,
- ctx.identifier().getText(), ENTRY));
- }
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/PresenceListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/PresenceListener.java
deleted file mode 100644
index ef744d5..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/PresenceListener.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-import org.onosproject.yangutils.datamodel.YangContainer;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.CONTAINER_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.PRESENCE_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
- *
- * ABNF grammar as per RFC6020
- * presence-stmt = presence-keyword sep string stmtend
- *
- * ANTLR grammar rule
- * presenceStatement : PRESENCE_KEYWORD string STMTEND;
- */
-
-/**
- * Represents listener based call back function corresponding to the "presence"
- * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
- */
-public final class PresenceListener {
-
- /**
- * Creates a new presence listener.
- */
- private PresenceListener() {
- }
-
- /**
- * It is called when parser receives an input matching the grammar
- * rule (presence), performs validation and updates the data model
- * tree.
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processPresenceEntry(TreeWalkListener listener,
- GeneratedYangParser.PresenceStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, PRESENCE_DATA, ctx.string().getText(), ENTRY);
-
- Parsable tmpData = listener.getParsedDataStack().peek();
- if (tmpData.getYangConstructType() == CONTAINER_DATA) {
- YangContainer container = (YangContainer) tmpData;
- container.setPresence(ctx.string().getText());
- } else {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, PRESENCE_DATA,
- ctx.string().getText(), ENTRY));
- }
- }
-}
\ No newline at end of file
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/RangeRestrictionListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/RangeRestrictionListener.java
deleted file mode 100644
index 3b4ae43..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/RangeRestrictionListener.java
+++ /dev/null
@@ -1,180 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-import org.onosproject.yangutils.datamodel.YangDecimal64;
-import org.onosproject.yangutils.datamodel.YangDerivedInfo;
-import org.onosproject.yangutils.datamodel.YangRangeRestriction;
-import org.onosproject.yangutils.datamodel.YangType;
-import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.DECIMAL64;
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.DERIVED;
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypeUtils.isOfRangeRestrictedType;
-import static org.onosproject.yangutils.datamodel.utils.RestrictionResolver.processRangeRestriction;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.RANGE_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.TYPE_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.INVALID_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_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
- *
- * ABNF grammar as per RFC6020
- * range-stmt = range-keyword sep range-arg-str optsep
- * (";" /
- * "{" stmtsep
- * ;; these stmts can appear in any order
- * [error-message-stmt stmtsep]
- * [error-app-tag-stmt stmtsep]
- * [description-stmt stmtsep]
- * [reference-stmt stmtsep]
- * "}")
- *
- * ANTLR grammar rule
- * rangeStatement : RANGE_KEYWORD range (STMTEND | LEFT_CURLY_BRACE commonStatements RIGHT_CURLY_BRACE);
- */
-
-/**
- * Represents listener based call back function corresponding to the "range"
- * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
- */
-public final class RangeRestrictionListener {
-
- /**
- * Creates a new range restriction listener.
- */
- private RangeRestrictionListener() {
- }
-
- /**
- * It is called when parser receives an input matching the grammar
- * rule (range), performs validation and updates the data model
- * tree.
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processRangeRestrictionEntry(TreeWalkListener listener,
- GeneratedYangParser.RangeStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, RANGE_DATA, ctx.range().getText(), ENTRY);
-
- Parsable tmpData = listener.getParsedDataStack().peek();
- if (tmpData.getYangConstructType() == TYPE_DATA) {
- YangType type = (YangType) tmpData;
- setRangeRestriction(listener, type, ctx);
- } else {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, RANGE_DATA,
- ctx.range().getText(), ENTRY));
- }
- }
-
- /**
- * Sets the range restriction to type.
- *
- * @param listener listener's object
- * @param type YANG type for which range restriction to be added
- * @param ctx context object of the grammar rule
- */
- private static void setRangeRestriction(TreeWalkListener listener, YangType type,
- GeneratedYangParser.RangeStatementContext ctx) {
-
- if (type.getDataType() == DERIVED) {
- ((YangDerivedInfo<YangRangeRestriction>) type.getDataTypeExtendedInfo())
- .setRangeRestrictionString(ctx.range().getText());
- ((YangDerivedInfo<YangRangeRestriction>) type.getDataTypeExtendedInfo())
- .setLineNumber(ctx.getStart().getLine());
- ((YangDerivedInfo<YangRangeRestriction>) type.getDataTypeExtendedInfo())
- .setCharPosition(ctx.getStart().getCharPositionInLine());
- return;
- }
-
- if (!(isOfRangeRestrictedType(type.getDataType())) && (type.getDataType() != DECIMAL64)) {
- ParserException parserException = new ParserException("YANG file error: Range restriction can't be " +
- "applied to a given type");
- parserException.setLine(ctx.getStart().getLine());
- parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
- throw parserException;
- }
-
- YangRangeRestriction rangeRestriction = null;
- try {
- if (type.getDataType() == DECIMAL64) {
- YangDecimal64 yangDecimal64 = (YangDecimal64) type.getDataTypeExtendedInfo();
- rangeRestriction = processRangeRestriction(yangDecimal64.getDefaultRangeRestriction(),
- ctx.getStart().getLine(),
- ctx.getStart().getCharPositionInLine(),
- true, ctx.range().getText(), type.getDataType());
- } else {
- rangeRestriction = processRangeRestriction(null, ctx.getStart().getLine(),
- ctx.getStart().getCharPositionInLine(),
- false, ctx.range().getText(), type.getDataType());
- }
- } catch (DataModelException e) {
- ParserException parserException = new ParserException(e.getMessage());
- parserException.setCharPosition(e.getCharPositionInLine());
- parserException.setLine(e.getLineNumber());
- throw parserException;
- }
-
- if (rangeRestriction != null) {
- if (type.getDataType() == DECIMAL64) {
- ((YangDecimal64<YangRangeRestriction>) type.getDataTypeExtendedInfo())
- .setRangeRestrictedExtendedInfo(rangeRestriction);
- } else {
- type.setDataTypeExtendedInfo(rangeRestriction);
- }
- }
- listener.getParsedDataStack().push(rangeRestriction);
- }
-
- /**
- * Performs validation and updates the data model tree.
- * It is called when parser exits from grammar rule (range).
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processRangeRestrictionExit(TreeWalkListener listener,
- GeneratedYangParser.RangeStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, RANGE_DATA, ctx.range().getText(), EXIT);
-
- Parsable tmpData = listener.getParsedDataStack().peek();
- if (tmpData instanceof YangRangeRestriction) {
- listener.getParsedDataStack().pop();
- } else if (tmpData instanceof YangType
- && ((YangType) tmpData).getDataType() == DERIVED) {
- // TODO : need to handle in linker
- } else {
- throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, RANGE_DATA,
- ctx.range().getText(), EXIT));
- }
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ReferenceListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ReferenceListener.java
deleted file mode 100644
index 02cdf62..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ReferenceListener.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-import org.onosproject.yangutils.datamodel.YangReference;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.REFERENCE_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
- *
- * ABNF grammar as per RFC6020
- * reference-stmt = reference-keyword sep string optsep stmtend
- *
- * ANTLR grammar rule
- * referenceStatement : REFERENCE_KEYWORD string STMTEND;
- */
-
-/**
- * Represents listener based call back function corresponding to the "reference"
- * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
- */
-public final class ReferenceListener {
-
- /**
- * Creates a new reference listener.
- */
- private ReferenceListener() {
- }
-
- /**
- * It is called when parser receives an input matching the grammar
- * rule (reference), performs validation and updates the data model
- * tree.
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processReferenceEntry(TreeWalkListener listener,
- GeneratedYangParser.ReferenceStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, REFERENCE_DATA, ctx.string().getText(), ENTRY);
-
- Parsable tmpData = listener.getParsedDataStack().peek();
- if (tmpData instanceof YangReference) {
- YangReference reference = (YangReference) tmpData;
- reference.setReference(ctx.string().getText());
- } else {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, REFERENCE_DATA,
- ctx.string().getText(), ENTRY));
- }
- }
-}
\ No newline at end of file
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/RequireInstanceListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/RequireInstanceListener.java
deleted file mode 100644
index 21c7533..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/RequireInstanceListener.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-import org.onosproject.yangutils.datamodel.YangLeafRef;
-import org.onosproject.yangutils.datamodel.YangType;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.REQUIRE_INSTANCE_DATA;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidBooleanValue;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.ENTRY;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
-
-/*
- * Reference: RFC6020 and YANG ANTLR Grammar
- *
- * ABNF grammar as per RFC6020
- * require-instance-stmt = require-instance-keyword sep
- * require-instance-arg-str stmtend
- *
- * require-instance-arg-str = < a string that matches the rule
- * require-instance-arg >
- *
- * require-instance-arg = true-keyword / false-keyword
- *
- * ANTLR grammar rule
- *
- * requireInstanceStatement : REQUIRE_INSTANCE_KEYWORD requireInstance STMTEND;
- *
- * requireInstance : string;
- */
-
-/**
- * Represents listener based call back function corresponding to the
- * "require-instance" rule defined in ANTLR grammar file for corresponding ABNF rule
- * in RFC 6020.
- */
-public final class RequireInstanceListener {
-
- /**
- * Creates a new require instance listener.
- */
- private RequireInstanceListener() {
- }
-
- /**
- * It is called when parser receives an input matching the grammar rule
- * (require-instance), performs validation and updates the data model tree.
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processRequireInstanceEntry(TreeWalkListener listener,
- GeneratedYangParser.RequireInstanceStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, REQUIRE_INSTANCE_DATA, "", ENTRY);
-
- Parsable curData = listener.getParsedDataStack().peek();
-
- // Gets the status of require instance
- boolean isRequireInstance = getValidBooleanValue(ctx.requireInstance().getText(), REQUIRE_INSTANCE_DATA, ctx);
-
- // Checks the holder of require-instance as leafref or type, else throws error.
- if (curData instanceof YangLeafRef) {
-
- // Sets the require-instance status to leafref.
- ((YangLeafRef) curData).setRequireInstance(isRequireInstance);
- } else if (curData instanceof YangType) {
-
- // Checks type should be instance-identifier, else throw error.
- if (((YangType) curData).getDataType() == YangDataTypes.INSTANCE_IDENTIFIER) {
-
- // Sets the require-instance status to instance-identifier type.
- ((YangType) curData).setDataTypeExtendedInfo(isRequireInstance);
- } else {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, REQUIRE_INSTANCE_DATA,
- ctx.getText(), ENTRY));
- }
- } else {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, REQUIRE_INSTANCE_DATA,
- ctx.getText(), ENTRY));
- }
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/RevisionDateListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/RevisionDateListener.java
deleted file mode 100644
index 3ff67fe..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/RevisionDateListener.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-import java.util.Date;
-import org.onosproject.yangutils.datamodel.YangImport;
-import org.onosproject.yangutils.datamodel.YangInclude;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.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.ListenerUtil.getValidDateFromString;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-
-/*
- * Reference: RFC6020 and YANG ANTLR Grammar
- *
- * ABNF grammar as per RFC6020
- * import-stmt = import-keyword sep identifier-arg-str optsep
- * "{" stmtsep
- * prefix-stmt stmtsep
- * [revision-date-stmt stmtsep]
- * "}"
- * include-stmt = include-keyword sep identifier-arg-str optsep
- * (";" /
- * "{" stmtsep
- * [revision-date-stmt stmtsep]
- * "}")
- * revision-date-stmt = revision-date-keyword sep revision-date stmtend
- *
- * ANTLR grammar rule
- * import_stmt : IMPORT_KEYWORD IDENTIFIER LEFT_CURLY_BRACE import_stmt_body
- * RIGHT_CURLY_BRACE;
- * import_stmt_body : prefix_stmt revision_date_stmt?;
- *
- * include_stmt : INCLUDE_KEYWORD IDENTIFIER (STMTEND | LEFT_CURLY_BRACE
- * revision_date_stmt_body? RIGHT_CURLY_BRACE);
- *
- * revision_date_stmt : REVISION_DATE_KEYWORD DATE_ARG STMTEND;
- *
- */
-
-/**
- * Represents 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 {
-
- /**
- * Creates a new revision date listener.
- */
- private RevisionDateListener() {
- }
-
- /**
- * 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
- */
- public static void processRevisionDateEntry(TreeWalkListener listener,
- GeneratedYangParser.RevisionDateStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, REVISION_DATE_DATA, ctx.dateArgumentString().getText(),
- ENTRY);
-
- Date date = getValidDateFromString(ctx.dateArgumentString().getText(), ctx);
-
- // Obtain the node of the stack.
- Parsable tmpNode = listener.getParsedDataStack().peek();
- switch (tmpNode.getYangConstructType()) {
- case IMPORT_DATA: {
- YangImport importNode = (YangImport) tmpNode;
- importNode.setRevision(date);
- break;
- }
- case INCLUDE_DATA: {
- YangInclude includeNode = (YangInclude) tmpNode;
- includeNode.setRevision(date);
- break;
- }
- default:
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, REVISION_DATE_DATA,
- ctx.dateArgumentString().getText(), ENTRY));
- }
- }
-}
\ No newline at end of file
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/RevisionListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/RevisionListener.java
deleted file mode 100644
index cb633b8..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/RevisionListener.java
+++ /dev/null
@@ -1,169 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-import java.util.Date;
-import org.onosproject.yangutils.datamodel.YangModule;
-import org.onosproject.yangutils.datamodel.YangRevision;
-import org.onosproject.yangutils.datamodel.YangSubModule;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.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.INVALID_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidDateFromString;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-
-/*
- * Reference: RFC6020 and YANG ANTLR Grammar
- *
- * ABNF grammar as per RFC6020
- * module-stmt = optsep module-keyword sep identifier-arg-str
- * optsep
- * "{" stmtsep
- * module-header-stmts
- * linkage-stmts
- * meta-stmts
- * revision-stmts
- * body-stmts
- * "}" optsep
- *
- * revision-stmt = revision-keyword sep revision-date optsep
- * (";" /
- * "{" stmtsep
- * [description-stmt stmtsep]
- * [reference-stmt stmtsep]
- * "}")
- *
- * ANTLR grammar rule
- * module_stmt : MODULE_KEYWORD IDENTIFIER LEFT_CURLY_BRACE module_body* RIGHT_CURLY_BRACE;
- *
- * revision_stmt : REVISION_KEYWORD DATE_ARG (STMTEND | LEFT_CURLY_BRACE revision_stmt_body RIGHT_CURLY_BRACE);
- * revision_stmt_body : description_stmt? reference_stmt?;
- */
-
-/**
- * Represents listener based call back function corresponding to the "revision"
- * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
- */
-public final class RevisionListener {
-
- /**
- * Creates a new revision listener.
- */
- 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.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, REVISION_DATA, ctx.dateArgumentString().getText(), ENTRY);
-
- Date date = getValidDateFromString(ctx.dateArgumentString().getText(), ctx);
-
- YangRevision revisionNode = new YangRevision();
- revisionNode.setRevDate(date);
-
- listener.getParsedDataStack().push(revisionNode);
- }
-
- /**
- * It is called when parser exits from grammar rule (revision), it perform
- * validations and update the data model tree.
- *
- * @param listener Listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processRevisionExit(TreeWalkListener listener, GeneratedYangParser.RevisionStatementContext
- ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, REVISION_DATA, ctx.dateArgumentString().getText(), EXIT);
-
- Parsable tmpRevisionNode = listener.getParsedDataStack().peek();
- if (tmpRevisionNode instanceof YangRevision) {
- listener.getParsedDataStack().pop();
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, REVISION_DATA, ctx.dateArgumentString().getText(),
- EXIT);
-
- Parsable tmpNode = listener.getParsedDataStack().peek();
- switch (tmpNode.getYangConstructType()) {
- case MODULE_DATA: {
- YangModule module = (YangModule) tmpNode;
- if (module.getRevision() != null) {
- Date curRevisionDate = module.getRevision().getRevDate();
- if (curRevisionDate.before(((YangRevision) tmpRevisionNode).getRevDate())) {
- module.setRevision((YangRevision) tmpRevisionNode);
- }
- } else {
- module.setRevision((YangRevision) tmpRevisionNode);
- }
- break;
- }
- case SUB_MODULE_DATA: {
- YangSubModule subModule = (YangSubModule) tmpNode;
- if (subModule.getRevision() != null) {
- Date curRevisionDate = subModule.getRevision().getRevDate();
- if (curRevisionDate.before(((YangRevision) tmpRevisionNode).getRevDate())) {
- subModule.setRevision((YangRevision) tmpRevisionNode);
- }
- } else {
- subModule.setRevision((YangRevision) tmpRevisionNode);
- }
- break;
- }
- default:
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, REVISION_DATA,
- ctx.dateArgumentString().getText(),
- EXIT));
- }
- } else {
- throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, REVISION_DATA,
- ctx.dateArgumentString().getText(), EXIT));
- }
- }
-
- /**
- * Validate revision.
- *
- * @param listener Listener's object
- * @param ctx context object of the grammar rule
- * @return validation result
- */
- private static boolean validateRevision(TreeWalkListener listener,
- GeneratedYangParser.RevisionStatementContext ctx) {
- // TODO to be implemented
- return true;
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/RpcListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/RpcListener.java
deleted file mode 100644
index e037e52..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/RpcListener.java
+++ /dev/null
@@ -1,166 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-import org.onosproject.yangutils.datamodel.YangModule;
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.YangRpc;
-import org.onosproject.yangutils.datamodel.YangSubModule;
-import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.DESCRIPTION_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.INPUT_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.OUTPUT_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.REFERENCE_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.RPC_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.STATUS_DATA;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil;
-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.constructExtendedListenerErrorMessage;
-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_CURRENT_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne;
-import static org.onosproject.yangutils.translator.tojava.YangDataModelFactory.getYangRpcNode;
-
-/*
- * Reference: RFC6020 and YANG ANTLR Grammar
- *
- * ABNF grammar as per RFC6020
- * rpc-stmt = rpc-keyword sep identifier-arg-str optsep
- * (";" /
- * "{" stmtsep
- * ;; these stmts can appear in any order
- * *(if-feature-stmt stmtsep)
- * [status-stmt stmtsep]
- * [description-stmt stmtsep]
- * [reference-stmt stmtsep]
- * *((typedef-stmt /
- * grouping-stmt) stmtsep)
- * [input-stmt stmtsep]
- * [output-stmt stmtsep]
- * "}")
- *
- * ANTLR grammar rule
- * rpcStatement : RPC_KEYWORD identifier (STMTEND | LEFT_CURLY_BRACE (ifFeatureStatement | statusStatement
- * | descriptionStatement | referenceStatement | typedefStatement | groupingStatement | inputStatement
- * | outputStatement)* RIGHT_CURLY_BRACE);
- */
-
-/**
- * Represents listener based call back function corresponding to the "rpc"
- * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
- */
-public final class RpcListener {
-
- /**
- * Creates a new rpc listener.
- */
- private RpcListener() {
- }
-
- /**
- * It is called when parser receives an input matching the grammar rule
- * (rpc), performs validation and updates the data model tree.
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processRpcEntry(TreeWalkListener listener,
- GeneratedYangParser.RpcStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, RPC_DATA, ctx.identifier().getText(), ENTRY);
-
- String identifier = getValidIdentifier(ctx.identifier().getText(), RPC_DATA, ctx);
-
- // Validate sub statement cardinality.
- validateSubStatementsCardinality(ctx);
-
- // Check for identifier collision
- int line = ctx.getStart().getLine();
- int charPositionInLine = ctx.getStart().getCharPositionInLine();
- detectCollidingChildUtil(listener, line, charPositionInLine, identifier, RPC_DATA);
-
- Parsable curData = listener.getParsedDataStack().peek();
- if (curData instanceof YangModule || curData instanceof YangSubModule) {
-
- YangNode curNode = (YangNode) curData;
- YangRpc yangRpc = getYangRpcNode(JAVA_GENERATION);
-
- yangRpc.setLineNumber(ctx.getStart().getLine());
- yangRpc.setCharPosition(ctx.getStart().getCharPositionInLine());
- yangRpc.setFileName(listener.getFileName());
- yangRpc.setName(identifier);
- try {
- curNode.addChild(yangRpc);
- } catch (DataModelException e) {
- throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
- RPC_DATA, ctx.identifier().getText(), ENTRY, e.getMessage()));
- }
- listener.getParsedDataStack().push(yangRpc);
- } else {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, RPC_DATA,
- ctx.identifier().getText(), ENTRY));
- }
- }
-
- /**
- * It is called when parser exits from grammar rule (rpc), it perform
- * validations and updates the data model tree.
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processRpcExit(TreeWalkListener listener,
- GeneratedYangParser.RpcStatementContext ctx) {
-
- //Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, RPC_DATA, ctx.identifier().getText(), EXIT);
-
- if (!(listener.getParsedDataStack().peek() instanceof YangRpc)) {
- throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, RPC_DATA,
- ctx.identifier().getText(), EXIT));
- }
- listener.getParsedDataStack().pop();
- }
-
- /**
- * Validates the cardinality of rpc sub-statements as per grammar.
- *
- * @param ctx context object of the grammar rule
- */
- private static void validateSubStatementsCardinality(GeneratedYangParser.RpcStatementContext ctx) {
-
- validateCardinalityMaxOne(ctx.statusStatement(), STATUS_DATA, RPC_DATA, ctx.identifier().getText());
- validateCardinalityMaxOne(ctx.descriptionStatement(), DESCRIPTION_DATA, RPC_DATA, ctx.identifier().getText());
- validateCardinalityMaxOne(ctx.referenceStatement(), REFERENCE_DATA, RPC_DATA, ctx.identifier().getText());
- validateCardinalityMaxOne(ctx.inputStatement(), INPUT_DATA, RPC_DATA, ctx.identifier().getText());
- validateCardinalityMaxOne(ctx.outputStatement(), OUTPUT_DATA, RPC_DATA, ctx.identifier().getText());
- }
-
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ShortCaseListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ShortCaseListener.java
deleted file mode 100644
index 6963a98..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ShortCaseListener.java
+++ /dev/null
@@ -1,149 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-import org.antlr.v4.runtime.ParserRuleContext;
-import org.antlr.v4.runtime.tree.ParseTree;
-import org.onosproject.yangutils.datamodel.YangCase;
-import org.onosproject.yangutils.datamodel.YangChoice;
-import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.CASE_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.SHORT_CASE_DATA;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil;
-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.constructExtendedListenerErrorMessage;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_CHILD;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-import static org.onosproject.yangutils.translator.tojava.YangDataModelFactory.getYangCaseNode;
-
-/*
- * Reference: RFC6020 and YANG ANTLR Grammar
- *
- * ABNF grammar as per RFC6020
- * short-case-stmt = container-stmt /
- * leaf-stmt /
- * leaf-list-stmt /
- * list-stmt /
- * anyxml-stmt
- *
- * ANTLR grammar rule
- * shortCaseStatement : containerStatement | leafStatement | leafListStatement | listStatement;
- */
-
-/**
- * Represents listener based call back function corresponding to the "short
- * case" rule defined in ANTLR grammar file for corresponding ABNF rule in RFC
- * 6020.
- */
-public final class ShortCaseListener {
-
- /**
- * Create a new short case listener.
- */
- private ShortCaseListener() {
- }
-
- /**
- * It is called when parser enters grammar rule (short case), it perform
- * validations and updates the data model tree.
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processShortCaseEntry(TreeWalkListener listener,
- GeneratedYangParser.ShortCaseStatementContext ctx) {
-
- ParseTree errorConstructContext;
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, SHORT_CASE_DATA, "", ENTRY);
-
- YangCase caseNode = getYangCaseNode(JAVA_GENERATION);
-
- caseNode.setLineNumber(ctx.getStart().getLine());
- caseNode.setCharPosition(ctx.getStart().getCharPositionInLine());
- caseNode.setFileName(listener.getFileName());
- if (ctx.containerStatement() != null) {
- caseNode.setName(getValidIdentifier(ctx.containerStatement().identifier().getText(), CASE_DATA, ctx));
- errorConstructContext = ctx.containerStatement();
- } else if (ctx.listStatement() != null) {
- caseNode.setName(getValidIdentifier(ctx.listStatement().identifier().getText(), CASE_DATA, ctx));
- errorConstructContext = ctx.listStatement();
- } else if (ctx.leafListStatement() != null) {
- caseNode.setName(getValidIdentifier(ctx.leafListStatement().identifier().getText(), CASE_DATA, ctx));
- errorConstructContext = ctx.leafListStatement();
- } else if (ctx.leafStatement() != null) {
- caseNode.setName(getValidIdentifier(ctx.leafStatement().identifier().getText(), CASE_DATA, ctx));
- errorConstructContext = ctx.leafStatement();
- } else {
- throw new ParserException(constructListenerErrorMessage(INVALID_CHILD, SHORT_CASE_DATA, "", ENTRY));
- }
- // TODO implement for augment.
-
- int line = ((ParserRuleContext) errorConstructContext).getStart().getLine();
- int charPositionInLine = ((ParserRuleContext) errorConstructContext).getStart().getCharPositionInLine();
-
- // Check for identifier collision
- detectCollidingChildUtil(listener, line, charPositionInLine, caseNode.getName(), CASE_DATA);
-
- if ((listener.getParsedDataStack().peek()) instanceof YangChoice) {
- try {
- ((YangChoice) listener.getParsedDataStack().peek()).addChild(caseNode);
- } catch (DataModelException e) {
- throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
- SHORT_CASE_DATA, caseNode.getName(), ENTRY, e.getMessage()));
- }
- listener.getParsedDataStack().push(caseNode);
- } else {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, SHORT_CASE_DATA,
- caseNode.getName(), ENTRY));
- }
- }
-
- /**
- * It is called when parser exits from grammar rule (short case), it perform
- * validations and update the data model tree.
- *
- * @param listener Listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processShortCaseExit(TreeWalkListener listener,
- GeneratedYangParser.ShortCaseStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, SHORT_CASE_DATA, "", EXIT);
-
- if (listener.getParsedDataStack().peek() instanceof YangCase) {
- listener.getParsedDataStack().pop();
- } else {
- throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, SHORT_CASE_DATA,
- "", EXIT));
- }
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/StatusListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/StatusListener.java
deleted file mode 100644
index 81d6b61..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/StatusListener.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-import org.onosproject.yangutils.datamodel.YangStatus;
-import org.onosproject.yangutils.datamodel.YangStatusType;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.datamodel.utils.YangConstructType;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.STATUS_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.ListenerUtil.removeQuotesAndHandleConcat;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-
-/*
- * Reference: RFC6020 and YANG ANTLR Grammar
- *
- * ABNF grammar as per RFC6020
- * status-stmt = status-keyword sep status-arg-str stmtend
- * status-arg-str = < a string that matches the rule
- * status-arg >
- * status-arg = current-keyword /
- * obsolete-keyword /
- * deprecated-keyword
- *
- * ANTLR grammar rule
- * statusStatement : STATUS_KEYWORD status STMTEND;
- */
-
-/**
- * Represents listener based call back function corresponding to the "status"
- * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
- */
-public final class StatusListener {
-
- private static final String CURRENT_KEYWORD = "current";
- private static final String DEPRECATED_KEYWORD = "deprecated";
- private static final String OBSOLETE_KEYWORD = "obsolete";
-
- /**
- * Creates a new status listener.
- */
- private StatusListener() {
- }
-
- /**
- * It is called when parser receives an input matching the grammar
- * rule (status), performs validation and updates the data model
- * tree.
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processStatusEntry(TreeWalkListener listener,
- GeneratedYangParser.StatusStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, STATUS_DATA, "", ENTRY);
-
- YangStatusType status = getValidStatus(ctx);
-
- Parsable tmpData = listener.getParsedDataStack().peek();
- if (tmpData instanceof YangStatus) {
- YangStatus yangStatus = (YangStatus) tmpData;
- yangStatus.setStatus(status);
- } else {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, STATUS_DATA, "", ENTRY));
- }
- }
-
- /**
- * Validates status value and returns the value from context.
- *
- * @param ctx context object of the grammar rule
- * @return status current/deprecated/obsolete
- */
- private static YangStatusType getValidStatus(GeneratedYangParser.StatusStatementContext ctx) {
-
- YangStatusType status;
-
- String value = removeQuotesAndHandleConcat(ctx.status().getText());
- switch (value) {
- case CURRENT_KEYWORD: {
- status = YangStatusType.CURRENT;
- break;
- }
- case DEPRECATED_KEYWORD: {
- status = YangStatusType.DEPRECATED;
- break;
- }
- case OBSOLETE_KEYWORD: {
- status = YangStatusType.OBSOLETE;
- break;
- }
- default: {
- ParserException parserException = new ParserException("YANG file error : " +
- YangConstructType.getYangConstructType(STATUS_DATA) + " " + ctx.status().getText() +
- " is not valid.");
- parserException.setLine(ctx.getStart().getLine());
- parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
- throw parserException;
- }
- }
-
- return status;
- }
-}
\ No newline at end of file
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/SubModuleListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/SubModuleListener.java
deleted file mode 100644
index d2c7347..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/SubModuleListener.java
+++ /dev/null
@@ -1,154 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-import org.onosproject.yangutils.datamodel.ResolvableType;
-import org.onosproject.yangutils.datamodel.YangReferenceResolver;
-import org.onosproject.yangutils.datamodel.YangSubModule;
-import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.linker.exceptions.LinkerException;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.MODULE_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.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.INVALID_CHILD;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsEmpty;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-import static org.onosproject.yangutils.translator.tojava.YangDataModelFactory.getYangSubModuleNode;
-
-/*
- * Reference: RFC6020 and YANG ANTLR Grammar
- *
- * ABNF grammar as per RFC6020
- * submodule-stmt = optsep submodule-keyword sep identifier-arg-str
- * optsep
- * "{" stmtsep
- * submodule-header-stmts
- * linkage-stmts
- * meta-stmts
- * revision-stmts
- * body-stmts
- * "}" optsep
- *
- * ANTLR grammar rule
- * submodule_stmt : SUBMODULE_KEYWORD identifier LEFT_CURLY_BRACE submodule_body* RIGHT_CURLY_BRACE;
- * submodule_body : submodule_header_statement linkage_stmts meta_stmts revision_stmts body_stmts;
- */
-
-/**
- * Represents listener based call back function corresponding to the "submodule"
- * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
- */
-public final class SubModuleListener {
-
- /**
- * Creates a new sub module listener.
- */
- private SubModuleListener() {
- }
-
- /**
- * 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
- */
- public static void processSubModuleEntry(TreeWalkListener listener,
- GeneratedYangParser.SubModuleStatementContext ctx) {
-
- // Check if stack is empty.
- checkStackIsEmpty(listener, INVALID_HOLDER, SUB_MODULE_DATA, ctx.identifier().getText(),
- ENTRY);
-
- String identifier = getValidIdentifier(ctx.identifier().getText(), SUB_MODULE_DATA, ctx);
-
- YangSubModule yangSubModule = getYangSubModuleNode(JAVA_GENERATION);
- yangSubModule.setName(identifier);
-
- yangSubModule.setLineNumber(ctx.getStart().getLine());
- yangSubModule.setCharPosition(ctx.getStart().getCharPositionInLine());
- yangSubModule.setFileName(listener.getFileName());
- if (ctx.submoduleBody().submoduleHeaderStatement().yangVersionStatement() == null) {
- yangSubModule.setVersion((byte) 1);
- }
-
- listener.getParsedDataStack().push(yangSubModule);
- }
-
- /**
- * It is called when parser exits from grammar rule (submodule), it perform
- * validations and update the data model tree.
- *
- * @param listener Listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processSubModuleExit(TreeWalkListener listener,
- GeneratedYangParser.SubModuleStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, SUB_MODULE_DATA, ctx.identifier().getText(),
- EXIT);
-
- Parsable tmpNode = listener.getParsedDataStack().peek();
- if (!(tmpNode instanceof YangSubModule)) {
- throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, SUB_MODULE_DATA,
- ctx.identifier().getText(), EXIT));
- }
-
- YangSubModule subModule = (YangSubModule) tmpNode;
- if (subModule.getUnresolvedResolutionList(ResolvableType.YANG_COMPILER_ANNOTATION) != null
- && subModule.getUnresolvedResolutionList(ResolvableType.YANG_COMPILER_ANNOTATION).size() != 0
- && subModule.getChild() != null) {
- throw new ParserException(constructListenerErrorMessage(INVALID_CHILD, MODULE_DATA,
- ctx.identifier().getText(), EXIT));
- }
-
- try {
- ((YangReferenceResolver) listener.getParsedDataStack().peek())
- .resolveSelfFileLinking(ResolvableType.YANG_IF_FEATURE);
- ((YangReferenceResolver) listener.getParsedDataStack().peek())
- .resolveSelfFileLinking(ResolvableType.YANG_USES);
- ((YangReferenceResolver) listener.getParsedDataStack().peek())
- .resolveSelfFileLinking(ResolvableType.YANG_DERIVED_DATA_TYPE);
- ((YangReferenceResolver) listener.getParsedDataStack().peek())
- .resolveSelfFileLinking(ResolvableType.YANG_LEAFREF);
- ((YangReferenceResolver) listener.getParsedDataStack().peek())
- .resolveSelfFileLinking(ResolvableType.YANG_BASE);
- ((YangReferenceResolver) listener.getParsedDataStack().peek())
- .resolveSelfFileLinking(ResolvableType.YANG_IDENTITYREF);
- } catch (DataModelException e) {
- LinkerException linkerException = new LinkerException(e.getMessage());
- linkerException.setLine(e.getLineNumber());
- linkerException.setCharPosition(e.getCharPositionInLine());
- linkerException.setFileName(listener.getFileName());
- throw linkerException;
- }
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/TypeDefListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/TypeDefListener.java
deleted file mode 100644
index 4821cfa..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/TypeDefListener.java
+++ /dev/null
@@ -1,200 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-import org.onosproject.yangutils.datamodel.YangContainer;
-import org.onosproject.yangutils.datamodel.YangGrouping;
-import org.onosproject.yangutils.datamodel.YangInput;
-import org.onosproject.yangutils.datamodel.YangList;
-import org.onosproject.yangutils.datamodel.YangModule;
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.YangNotification;
-import org.onosproject.yangutils.datamodel.YangOutput;
-import org.onosproject.yangutils.datamodel.YangRpc;
-import org.onosproject.yangutils.datamodel.YangSubModule;
-import org.onosproject.yangutils.datamodel.YangTypeDef;
-import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.DEFAULT_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.DESCRIPTION_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.REFERENCE_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.STATUS_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.TYPEDEF_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.TYPE_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.UNITS_DATA;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil;
-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.constructExtendedListenerErrorMessage;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_CONTENT;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIdentifier;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityEqualsOne;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne;
-import static org.onosproject.yangutils.translator.tojava.YangDataModelFactory.getYangTypeDefNode;
-
-/*
- * Reference: RFC6020 and YANG ANTLR Grammar
- *
- * body-stmts = *((extension-stmt /
- * feature-stmt /
- * identity-stmt /
- * typedef-stmt /
- * grouping-stmt /
- * data-def-stmt /
- * augment-stmt /
- * rpc-stmt /
- * notification-stmt /
- * deviation-stmt) stmtsep)
- *
- * typedef-stmt = typedef-keyword sep identifier-arg-str optsep
- * "{" stmtsep
- * ;; these stmts can appear in any order
- * type-stmt stmtsep
- * [units-stmt stmtsep]
- * [default-stmt stmtsep]
- * [status-stmt stmtsep]
- * [description-stmt stmtsep]
- * [reference-stmt stmtsep]
- * "}"
- *
- * ANTLR grammar rule
- * typedefStatement : TYPEDEF_KEYWORD identifier LEFT_CURLY_BRACE
- * (typeStatement | unitsStatement | defaultStatement | statusStatement
- * | descriptionStatement | referenceStatement)* RIGHT_CURLY_BRACE;
- */
-
-/**
- * Represents listener based call back function corresponding to the "typedef"
- * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
- */
-public final class TypeDefListener {
-
- /**
- * Creates a new typedef listener.
- */
- private TypeDefListener() {
- }
-
- /**
- * It is called when parser enters grammar rule (typedef), it perform
- * validations and updates the data model tree.
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processTypeDefEntry(TreeWalkListener listener,
- GeneratedYangParser.TypedefStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, TYPEDEF_DATA, ctx.identifier().getText(), ENTRY);
-
- String identifier = getValidIdentifier(ctx.identifier().getText(), TYPEDEF_DATA, ctx);
-
- // Validate sub statement cardinality.
- validateSubStatementsCardinality(ctx);
-
- // Check for identifier collision
- int line = ctx.getStart().getLine();
- int charPositionInLine = ctx.getStart().getCharPositionInLine();
- detectCollidingChildUtil(listener, line, charPositionInLine, identifier, TYPEDEF_DATA);
-
- /*
- * Create a derived type information, the base type must be set in type
- * listener.
- */
- YangTypeDef typeDefNode = getYangTypeDefNode(JAVA_GENERATION);
- typeDefNode.setName(identifier);
-
- typeDefNode.setLineNumber(ctx.getStart().getLine());
- typeDefNode.setCharPosition(ctx.getStart().getCharPositionInLine());
- typeDefNode.setFileName(listener.getFileName());
- Parsable curData = listener.getParsedDataStack().peek();
-
- if (curData instanceof YangModule || curData instanceof YangSubModule || curData instanceof YangContainer
- || curData instanceof YangList || curData instanceof YangNotification || curData instanceof YangRpc
- || curData instanceof YangInput || curData instanceof YangOutput || curData instanceof YangGrouping) {
-
- YangNode curNode = (YangNode) curData;
- try {
- curNode.addChild(typeDefNode);
- } catch (DataModelException e) {
- throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
- TYPEDEF_DATA, ctx.identifier().getText(), ENTRY, e.getMessage()));
- }
- listener.getParsedDataStack().push(typeDefNode);
- } else {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER,
- TYPEDEF_DATA, ctx.identifier().getText(), ENTRY));
- }
- }
-
- /**
- * It is called when parser exits from grammar rule (typedef), it perform
- * validations and updates the data model tree.
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processTypeDefExit(TreeWalkListener listener,
- GeneratedYangParser.TypedefStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, TYPEDEF_DATA, ctx.identifier().getText(), EXIT);
-
- if (listener.getParsedDataStack().peek() instanceof YangTypeDef) {
- YangTypeDef typeDefNode = (YangTypeDef) listener.getParsedDataStack().peek();
- try {
- typeDefNode.validateDataOnExit();
- } catch (DataModelException e) {
- throw new ParserException(constructListenerErrorMessage(INVALID_CONTENT, TYPEDEF_DATA,
- ctx.identifier().getText(), EXIT));
- }
-
- listener.getParsedDataStack().pop();
- } else {
- throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, TYPEDEF_DATA,
- ctx.identifier().getText(), EXIT));
- }
- }
-
- /**
- * Validates the cardinality of typedef sub-statements as per grammar.
- *
- * @param ctx context object of the grammar rule
- */
- private static void validateSubStatementsCardinality(GeneratedYangParser.TypedefStatementContext ctx) {
-
- validateCardinalityMaxOne(ctx.unitsStatement(), UNITS_DATA, TYPEDEF_DATA, ctx.identifier().getText());
- validateCardinalityMaxOne(ctx.defaultStatement(), DEFAULT_DATA, TYPEDEF_DATA, ctx.identifier().getText());
- validateCardinalityEqualsOne(ctx.typeStatement(), TYPE_DATA, TYPEDEF_DATA, ctx.identifier().getText(), ctx);
- validateCardinalityMaxOne(ctx.descriptionStatement(), DESCRIPTION_DATA, TYPEDEF_DATA,
- ctx.identifier().getText());
- validateCardinalityMaxOne(ctx.referenceStatement(), REFERENCE_DATA, TYPEDEF_DATA, ctx.identifier().getText());
- validateCardinalityMaxOne(ctx.statusStatement(), STATUS_DATA, TYPEDEF_DATA, ctx.identifier().getText());
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/TypeListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/TypeListener.java
deleted file mode 100644
index 8ed701e..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/TypeListener.java
+++ /dev/null
@@ -1,339 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-import org.onosproject.yangutils.datamodel.YangDerivedInfo;
-import org.onosproject.yangutils.datamodel.YangLeaf;
-import org.onosproject.yangutils.datamodel.YangLeafList;
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
-import org.onosproject.yangutils.datamodel.YangType;
-import org.onosproject.yangutils.datamodel.YangTypeDef;
-import org.onosproject.yangutils.datamodel.YangUnion;
-import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
-import org.onosproject.yangutils.linker.impl.YangResolutionInfoImpl;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.addResolutionInfo;
-import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
-import static org.onosproject.yangutils.datamodel.utils.ResolvableStatus.UNRESOLVED;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.TYPEDEF_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.TYPE_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.UNION_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.constructExtendedListenerErrorMessage;
-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_CURRENT_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidNodeIdentifier;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-import static org.onosproject.yangutils.translator.tojava.YangDataModelFactory.getYangType;
-
-/*
- * Reference: RFC6020 and YANG ANTLR Grammar
- *
- * ABNF grammar as per RFC6020
- * type-stmt = type-keyword sep identifier-ref-arg-str optsep
- * (";" /
- * "{" stmtsep
- * type-body-stmts
- * "}")
- *
- * ANTLR grammar rule
- * typeStatement : TYPE_KEYWORD string (STMTEND | LEFT_CURLY_BRACE typeBodyStatements RIGHT_CURLY_BRACE);
- */
-
-/**
- * Represents listener based call back function corresponding to the "type" rule
- * defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
- */
-public final class TypeListener {
-
- /**
- * Creates a new type listener.
- */
- private TypeListener() {
- }
-
- /**
- * It is called when parser receives an input matching the grammar rule
- * (type), performs validation and updates the data model tree.
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processTypeEntry(TreeWalkListener listener,
- GeneratedYangParser.TypeStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, TYPE_DATA, ctx.string().getText(), ENTRY);
-
- // Validate node identifier.
- YangNodeIdentifier nodeIdentifier = getValidNodeIdentifier(ctx.string().getText(), TYPE_DATA,
- ctx);
-
- // Obtain the YANG data type.
- YangDataTypes yangDataTypes = YangDataTypes.getType(ctx.string().getText());
-
- // validate type sub-statement cardinality
- validateTypeSubStatementCardinality(ctx, yangDataTypes);
-
- // Create YANG type object and fill the values.
- YangType<?> type = getYangType(JAVA_GENERATION);
- type.setNodeIdentifier(nodeIdentifier);
- type.setDataType(yangDataTypes);
-
- type.setLineNumber(ctx.getStart().getLine());
- type.setCharPosition(ctx.getStart().getCharPositionInLine());
- type.setFileName(listener.getFileName());
- // Set default require instance value as true for instance identifier.
- setDefaultRequireInstanceForInstanceIdentifier(type);
-
- int errorLine = ctx.getStart().getLine();
- int errorPosition = ctx.getStart().getCharPositionInLine();
-
- Parsable tmpData = listener.getParsedDataStack().peek();
- switch (tmpData.getYangConstructType()) {
- case LEAF_DATA:
- YangLeaf leaf = (YangLeaf) tmpData;
- leaf.setDataType(type);
-
- /*
- * If data type is derived, resolution information to be added
- * in resolution list.
- */
- if (yangDataTypes == YangDataTypes.DERIVED) {
- // Parent YANG node of leaf to be added in resolution information.
- Parsable leafData = listener.getParsedDataStack().pop();
- Parsable parentNodeOfLeaf = listener.getParsedDataStack().peek();
- listener.getParsedDataStack().push(leafData);
-
- // Verify parent node of leaf
- if (!(parentNodeOfLeaf instanceof YangNode)) {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, TYPE_DATA,
- ctx.string().getText(), EXIT));
- }
-
- // Create empty derived info and attach it to type extended info.
- YangDerivedInfo<?> yangDerivedInfo = new YangDerivedInfo<>();
- ((YangType<YangDerivedInfo>) type).setDataTypeExtendedInfo(yangDerivedInfo);
-
- type.setResolvableStatus(UNRESOLVED);
-
- // Add resolution information to the list
- YangResolutionInfoImpl resolutionInfo =
- new YangResolutionInfoImpl<YangType>(
- type,(YangNode) parentNodeOfLeaf, errorLine,
- errorPosition);
- addToResolutionList(resolutionInfo, ctx);
- }
- break;
- case LEAF_LIST_DATA:
- YangLeafList leafList = (YangLeafList) tmpData;
- leafList.setDataType(type);
-
- /*
- * If data type is derived, resolution information to be added
- * in resolution list.
- */
- if (yangDataTypes == YangDataTypes.DERIVED) {
- // Parent YANG node of leaf list to be added in resolution information.
- Parsable leafListData = listener.getParsedDataStack().pop();
- Parsable parentNodeOfLeafList = listener.getParsedDataStack().peek();
- listener.getParsedDataStack().push(leafListData);
-
- // Verify parent node of leaf
- if (!(parentNodeOfLeafList instanceof YangNode)) {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, TYPE_DATA,
- ctx.string().getText(), EXIT));
- }
-
- // Create empty derived info and attach it to type extended info.
- YangDerivedInfo<?> yangDerivedInfo = new YangDerivedInfo<>();
- ((YangType<YangDerivedInfo>) type).setDataTypeExtendedInfo(yangDerivedInfo);
-
- // Add resolution information to the list
- YangResolutionInfoImpl resolutionInfo =
- new YangResolutionInfoImpl<YangType>(
- type, (YangNode) parentNodeOfLeafList,
- errorLine, errorPosition);
- addToResolutionList(resolutionInfo, ctx);
- }
- break;
- case UNION_DATA:
- YangUnion unionNode = (YangUnion) tmpData;
- try {
- unionNode.addType(type);
- } catch (DataModelException e) {
- ParserException parserException = new ParserException(e.getMessage());
- parserException.setLine(ctx.getStart().getLine());
- parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
- throw parserException;
- }
-
- /*
- * If data type is derived, resolution information to be added
- * in resolution list.
- */
- if (yangDataTypes == YangDataTypes.DERIVED) {
-
- // Create empty derived info and attach it to type extended info.
- YangDerivedInfo<?> yangDerivedInfo = new YangDerivedInfo<>();
- ((YangType<YangDerivedInfo>) type).setDataTypeExtendedInfo(yangDerivedInfo);
-
- type.setResolvableStatus(UNRESOLVED);
-
- // Add resolution information to the list
- YangResolutionInfoImpl resolutionInfo =
- new YangResolutionInfoImpl<YangType>(
- type, unionNode, errorLine, errorPosition);
- addToResolutionList(resolutionInfo, ctx);
- }
-
- break;
- case TYPEDEF_DATA:
- /* Prepare the base type info and set in derived type */
- YangTypeDef typeDef = (YangTypeDef) tmpData;
- typeDef.setDataType(type);
-
- /*
- * If data type is derived, resolution information to be added
- * in resolution list.
- */
- if (yangDataTypes == YangDataTypes.DERIVED) {
- // Create empty derived info and attach it to type extended info.
- YangDerivedInfo<?> yangDerivedInfo = new YangDerivedInfo<>();
- ((YangType<YangDerivedInfo>) type).setDataTypeExtendedInfo(yangDerivedInfo);
-
- type.setResolvableStatus(UNRESOLVED);
- // Add resolution information to the list
- YangResolutionInfoImpl resolutionInfo =
- new YangResolutionInfoImpl<YangType>(
- type, typeDef, errorLine, errorPosition);
- addToResolutionList(resolutionInfo, ctx);
- }
- break;
- //TODO: deviate replacement statement.
-
- default:
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, TYPE_DATA,
- ctx.string().getText(), EXIT));
- }
-
- // Push the type to the stack.
- listener.getParsedDataStack().push(type);
- }
-
- /**
- * Sets the default require instance value as true when the type is instance identifier.
- *
- * @param type type to which the value has to be set
- */
- private static void setDefaultRequireInstanceForInstanceIdentifier(YangType<?> type) {
-
- if (type.getDataType() == YangDataTypes.INSTANCE_IDENTIFIER) {
- ((YangType<Boolean>) type).setDataTypeExtendedInfo(true);
- }
- }
-
- /**
- * It is called when parser exits from grammar rule (type), it perform
- * validations and update the data model tree.
- *
- * @param listener Listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processTypeExit(TreeWalkListener listener,
- GeneratedYangParser.TypeStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_CURRENT_HOLDER, TYPE_DATA, ctx.string().getText(), EXIT);
-
- Parsable parsableType = listener.getParsedDataStack().pop();
- if (!(parsableType instanceof YangType)) {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, TYPE_DATA,
- ctx.string().getText(), EXIT));
- }
- }
-
- /**
- * Adds to resolution list.
- *
- * @param resolutionInfo resolution information
- * @param ctx context object of the grammar rule
- */
- private static void addToResolutionList(YangResolutionInfoImpl<YangType> resolutionInfo,
- GeneratedYangParser.TypeStatementContext ctx) {
- try {
- addResolutionInfo(resolutionInfo);
- } catch (DataModelException e) {
- throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
- TYPE_DATA, ctx.string().getText(), ENTRY, e.getMessage()));
- }
- }
-
- /**
- * Validates type body statements cardinality.
- *
- * @param ctx context object of the grammar rule
- * @param yangDataType yang data type
- */
- private static void validateTypeSubStatementCardinality(GeneratedYangParser.TypeStatementContext ctx,
- YangDataTypes yangDataType) {
- if (ctx.typeBodyStatements() == null || ctx.typeBodyStatements().isEmpty()) {
- ParserException parserException;
- switch (yangDataType) {
- case UNION:
- parserException = new ParserException("YANG file error : a type union" +
- " must have atleast one type statement.");
- break;
- case ENUMERATION:
- parserException = new ParserException("YANG file error : a type enumeration" +
- " must have atleast one enum statement.");
- break;
- case BITS:
- parserException = new ParserException("YANG file error : a type bits" +
- " must have atleast one bit statement.");
- break;
- case DECIMAL64:
- parserException = new ParserException("YANG file error : a type decimal64" +
- " must have fraction-digits statement.");
- break;
- case LEAFREF:
- parserException = new ParserException("YANG file error : a type leafref" +
- " must have one path statement.");
- break;
- case IDENTITYREF:
- parserException = new ParserException("YANG file error : a type identityref" +
- " must have base statement.");
- break;
- default:
- return;
- }
- parserException.setLine(ctx.getStart().getLine());
- parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
- throw parserException;
- }
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/UnionListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/UnionListener.java
deleted file mode 100644
index 9653e40..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/UnionListener.java
+++ /dev/null
@@ -1,223 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-/*
- * Reference: RFC6020 and YANG ANTLR Grammar
- *
- * ABNF grammar as per RFC6020
- * type-body-stmts = numerical-restrictions /
- * decimal64-specification /
- * string-restrictions /
- * enum-specification /
- * leafref-specification /
- * identityref-specification /
- * instance-identifier-specification /
- * bits-specification /
- * union-specification
- *
- * union-specification = 1*(type-stmt stmtsep)
- *
- * ANTLR grammar rule
- * typeBodyStatements : numericalRestrictions | stringRestrictions | enumSpecification
- * | leafrefSpecification | identityrefSpecification | instanceIdentifierSpecification
- * | bitsSpecification | unionSpecification;
- *
- * unionSpecification : typeStatement+;
- */
-
-import org.onosproject.yangutils.datamodel.YangLeaf;
-import org.onosproject.yangutils.datamodel.YangLeafList;
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.YangType;
-import org.onosproject.yangutils.datamodel.YangTypeDef;
-import org.onosproject.yangutils.datamodel.YangUnion;
-import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.TYPE_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.UNION_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.constructExtendedListenerErrorMessage;
-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_CURRENT_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-import static org.onosproject.yangutils.translator.tojava.YangDataModelFactory.getYangUnionNode;
-
-/**
- * Represents listener based call back function corresponding to the "union" rule
- * defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
- */
-public final class UnionListener {
-
- /**
- * Suffix to be used while creating union class.
- */
- private static final String UNION_CLASS_SUFFIX = "_union";
-
- /**
- * Creates a new union listener.
- */
- private UnionListener() {
- }
-
- /**
- * It is called when parser enters grammar rule (union), it perform
- * validations and updates the data model tree.
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processUnionEntry(TreeWalkListener listener,
- GeneratedYangParser.UnionSpecificationContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, UNION_DATA, "", ENTRY);
-
- if (listener.getParsedDataStack().peek() instanceof YangType) {
- YangUnion unionNode = getYangUnionNode(JAVA_GENERATION);
- Parsable typeData = listener.getParsedDataStack().pop();
-
- unionNode.setLineNumber(ctx.getStart().getLine());
- unionNode.setCharPosition(ctx.getStart().getCharPositionInLine());
- unionNode.setFileName(listener.getFileName());
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, UNION_DATA, "", ENTRY);
-
- Parsable tmpData = listener.getParsedDataStack().peek();
-
- switch (tmpData.getYangConstructType()) {
- case LEAF_DATA:
- // Set the name of union same as leaf.
- unionNode.setName(((YangLeaf) tmpData).getName() + UNION_CLASS_SUFFIX);
- // Pop the stack entry to obtain the parent YANG node.
- Parsable leaf = listener.getParsedDataStack().pop();
- // Add the union node to the parent holder of leaf.
- addChildToParentNode(listener, unionNode);
- // Push the popped entry back to the stack.
- listener.getParsedDataStack().push(leaf);
- break;
- case LEAF_LIST_DATA:
- // Set the name of union same as leaf list.
- unionNode.setName(((YangLeafList) tmpData).getName() + UNION_CLASS_SUFFIX);
- // Pop the stack entry to obtain the parent YANG node.
- Parsable leafList = listener.getParsedDataStack().pop();
- // Add the union node to the parent holder of leaf.
- addChildToParentNode(listener, unionNode);
- // Push the popped entry back to the stack.
- listener.getParsedDataStack().push(leafList);
- break;
- case UNION_DATA:
- YangUnion parentUnion = (YangUnion) tmpData;
- /*
- * In case parent of union is again a union, name of the
- * child union is parent union name suffixed with running
- * integer number, this is done because under union there
- * could be multiple child union types.
- */
- unionNode.setName(parentUnion.getName() + UNION_CLASS_SUFFIX + parentUnion.getChildUnionNumber());
- // Increment the running number.
- parentUnion.setChildUnionNumber(parentUnion.getChildUnionNumber() + 1);
- // Add union as a child to parent union.
- addChildToParentNode(listener, unionNode);
- break;
- case TYPEDEF_DATA:
- YangTypeDef typeDef = (YangTypeDef) tmpData;
- // Set the name of union same as typedef name.
- unionNode.setName(typeDef.getName() + UNION_CLASS_SUFFIX);
- // Add union as a child to parent type def.
- addChildToParentNode(listener, unionNode);
- break;
- // TODO deviate.
- default:
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, TYPE_DATA,
- ((YangType<?>) typeData).getDataTypeName(), ENTRY));
- }
- listener.getParsedDataStack().push(typeData);
- listener.getParsedDataStack().push(unionNode);
- } else {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, UNION_DATA, "", ENTRY));
- }
- }
-
- /**
- * It is called when parser exits from grammar rule (union), it perform
- * validations and update the data model tree.
- *
- * @param listener Listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processUnionExit(TreeWalkListener listener,
- GeneratedYangParser.UnionSpecificationContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, UNION_DATA, "", EXIT);
-
- Parsable tmpUnionNode = listener.getParsedDataStack().peek();
- if (tmpUnionNode instanceof YangUnion) {
- YangUnion unionNode = (YangUnion) tmpUnionNode;
- listener.getParsedDataStack().pop();
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, UNION_DATA, "", EXIT);
-
- Parsable tmpNode = listener.getParsedDataStack().peek();
- switch (tmpNode.getYangConstructType()) {
- case TYPE_DATA: {
- YangType<YangUnion> typeNode = (YangType<YangUnion>) tmpNode;
- typeNode.setDataTypeExtendedInfo(unionNode);
- break;
- }
- default:
- throw new ParserException(
- constructListenerErrorMessage(INVALID_HOLDER, UNION_DATA, "", EXIT));
- }
- } else {
- throw new ParserException(
- constructListenerErrorMessage(MISSING_CURRENT_HOLDER, UNION_DATA, "", EXIT));
- }
- }
-
- /**
- * Adds the union node to the parent holder.
- *
- * @param listener listener's object
- * @param unionNode union node which needs to be added to parent
- */
- private static void addChildToParentNode(TreeWalkListener listener, YangUnion unionNode) {
- if (!(listener.getParsedDataStack().peek() instanceof YangNode)) {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, UNION_DATA,
- "", ENTRY));
- } else {
- YangNode curNode = (YangNode) listener.getParsedDataStack().peek();
- try {
- curNode.addChild(unionNode);
- } catch (DataModelException e) {
- throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
- UNION_DATA, "", ENTRY, e.getMessage()));
- }
- }
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/UniqueListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/UniqueListener.java
deleted file mode 100644
index 59920fe..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/UniqueListener.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-import org.onosproject.yangutils.datamodel.YangList;
-import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.UNIQUE_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;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.UNHANDLED_PARSED_DATA;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.removeQuotesAndHandleConcat;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-
-/*
- * Reference: RFC6020 and YANG ANTLR Grammar
- *
- * ABNF grammar as per RFC6020
- * unique-stmt = unique-keyword sep unique-arg-str stmtend
- *
- * ANTLR grammar rule
- * uniqueStatement: UNIQUE_KEYWORD unique STMTEND;
- * unique : string;
- */
-
-/**
- * Represesnts listener based call back function corresponding to the "unique" rule
- * defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
- */
-public final class UniqueListener {
-
- /**
- * Creates a new unique listener.
- */
- private UniqueListener() {
- }
-
- /**
- * It is called when parser receives an input matching the grammar rule
- * (unique), perform validations and updates the data model tree.
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processUniqueEntry(TreeWalkListener listener,
- GeneratedYangParser.UniqueStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, UNIQUE_DATA, ctx.unique().getText(), ENTRY);
-
- Parsable tmpData = listener.getParsedDataStack().peek();
- if (listener.getParsedDataStack().peek() instanceof YangList) {
- YangList yangList = (YangList) tmpData;
- String tmpUniqueValue = removeQuotesAndHandleConcat(ctx.unique().getText());
-
- if (tmpUniqueValue.contains(" ")) {
- String[] uniqueValues = tmpUniqueValue.split(" ");
- for (String uniqueValue : uniqueValues) {
- try {
- yangList.addUnique(uniqueValue);
- } catch (DataModelException e) {
- throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
- UNIQUE_DATA,
- ctx.unique().getText(), ENTRY, e.getMessage()));
- }
- }
- } else {
- try {
- yangList.addUnique(tmpUniqueValue);
- } catch (DataModelException e) {
- throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA, UNIQUE_DATA,
- ctx.unique().getText(), ENTRY, e.getMessage()));
- }
- }
- } else {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, UNIQUE_DATA, ctx.unique().getText(),
- ENTRY));
- }
- }
-}
\ No newline at end of file
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/UnitsListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/UnitsListener.java
deleted file mode 100644
index e7acccf..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/UnitsListener.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-import org.onosproject.yangutils.datamodel.YangLeaf;
-import org.onosproject.yangutils.datamodel.YangLeafList;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.UNITS_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
- *
- * ABNF grammar as per RFC6020
- * units-stmt = units-keyword sep string optsep stmtend
- *
- * ANTLR grammar rule
- * unitsStatement : UNITS_KEYWORD string STMTEND;
- */
-
-/**
- * Represents listener based call back function corresponding to the "units"
- * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
- */
-public final class UnitsListener {
-
- /**
- * Creates a new units listener.
- */
- private UnitsListener() {
- }
-
- /**
- * It is called when parser receives an input matching the grammar
- * rule (units), performs validation and updates the data model
- * tree.
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processUnitsEntry(TreeWalkListener listener,
- GeneratedYangParser.UnitsStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, UNITS_DATA, ctx.string().getText(), ENTRY);
-
- Parsable tmpData = listener.getParsedDataStack().peek();
- switch (tmpData.getYangConstructType()) {
- case LEAF_DATA:
- YangLeaf leaf = (YangLeaf) tmpData;
- leaf.setUnits(ctx.string().getText());
- break;
- case LEAF_LIST_DATA:
- YangLeafList leafList = (YangLeafList) tmpData;
- leafList.setUnits(ctx.string().getText());
- break;
- case TYPEDEF_DATA:
- // TODO
- break;
- default:
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, UNITS_DATA,
- ctx.string().getText(), ENTRY));
- }
- }
-}
\ No newline at end of file
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/UsesListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/UsesListener.java
deleted file mode 100644
index 2609d44..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/UsesListener.java
+++ /dev/null
@@ -1,228 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.yangutils.parser.impl.listeners;
-
-import org.onosproject.yangutils.datamodel.YangAugment;
-import org.onosproject.yangutils.datamodel.YangCase;
-import org.onosproject.yangutils.datamodel.YangContainer;
-import org.onosproject.yangutils.datamodel.YangGrouping;
-import org.onosproject.yangutils.datamodel.YangInput;
-import org.onosproject.yangutils.datamodel.YangList;
-import org.onosproject.yangutils.datamodel.YangModule;
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
-import org.onosproject.yangutils.datamodel.YangNotification;
-import org.onosproject.yangutils.datamodel.YangOutput;
-import org.onosproject.yangutils.datamodel.YangSubModule;
-import org.onosproject.yangutils.datamodel.YangUses;
-import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.linker.impl.YangResolutionInfoImpl;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.addResolutionInfo;
-import static org.onosproject.yangutils.datamodel.utils.GeneratedLanguage.JAVA_GENERATION;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.DESCRIPTION_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.REFERENCE_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.STATUS_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.USES_DATA;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.WHEN_DATA;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerCollisionDetector.detectCollidingChildUtil;
-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.constructExtendedListenerErrorMessage;
-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.ListenerErrorType.UNHANDLED_PARSED_DATA;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidNodeIdentifier;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityMaxOne;
-import static org.onosproject.yangutils.translator.tojava.YangDataModelFactory.getYangUsesNode;
-
-/*
- * Reference: RFC6020 and YANG ANTLR Grammar
- *
- * ABNF grammar as per RFC6020
- * data-def-stmt = container-stmt /
- * leaf-stmt /
- * leaf-list-stmt /
- * list-stmt /
- * choice-stmt /
- * anyxml-stmt /
- * uses-stmt
- *
- * uses-stmt = uses-keyword sep identifier-ref-arg-str optsep
- * (";" /
- * "{" stmtsep
- * ;; these stmts can appear in any order
- * [when-stmt stmtsep]
- * *(if-feature-stmt stmtsep)
- * [status-stmt stmtsep]
- * [description-stmt stmtsep]
- * [reference-stmt stmtsep]
- * *(refine-stmt stmtsep)
- * *(uses-augment-stmt stmtsep)
- * "}")
- *
- * ANTLR grammar rule
- * dataDefStatement : containerStatement
- * | leafStatement
- * | leafListStatement
- * | listStatement
- * | choiceStatement
- * | usesStatement;
- *
- * usesStatement : USES_KEYWORD string (STMTEND | LEFT_CURLY_BRACE (whenStatement | ifFeatureStatement
- * | statusStatement | descriptionStatement | referenceStatement | refineStatement
- * | usesAugmentStatement)* RIGHT_CURLY_BRACE);
- */
-
-/**
- * Represents listener based call back function corresponding to the "uses"
- * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
- */
-public final class UsesListener {
-
- /**
- * Creates a new uses listener.
- */
- private UsesListener() {
- }
-
- /**
- * It is called when parser enters grammar rule (uses), it perform
- * validations and updates the data model tree.
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processUsesEntry(TreeWalkListener listener, GeneratedYangParser.UsesStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, USES_DATA, ctx.string().getText(), ENTRY);
-
- // Validate sub statement cardinality.
- validateSubStatementsCardinality(ctx);
-
- // Check for identifier collision
- int line = ctx.getStart().getLine();
- int charPositionInLine = ctx.getStart().getCharPositionInLine();
-
- detectCollidingChildUtil(listener, line, charPositionInLine, ctx.string().getText(), USES_DATA);
- Parsable curData = listener.getParsedDataStack().peek();
-
- if (curData instanceof YangModule || curData instanceof YangSubModule
- || curData instanceof YangContainer || curData instanceof YangList
- || curData instanceof YangUses || curData instanceof YangAugment
- || curData instanceof YangCase || curData instanceof YangGrouping
- || curData instanceof YangInput || curData instanceof YangOutput
- || curData instanceof YangNotification) {
-
- YangUses usesNode = getYangUsesNode(JAVA_GENERATION);
-
- usesNode.setLineNumber(ctx.getStart().getLine());
- usesNode.setCharPosition(ctx.getStart().getCharPositionInLine());
- usesNode.setFileName(listener.getFileName());
- YangNodeIdentifier nodeIdentifier = getValidNodeIdentifier(ctx.string().getText(), USES_DATA, ctx);
- usesNode.setNodeIdentifier(nodeIdentifier);
- usesNode.setCurrentGroupingDepth(listener.getGroupingDepth());
- YangNode curNode = (YangNode) curData;
-
- try {
- curNode.addChild(usesNode);
- } catch (DataModelException e) {
- throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
- USES_DATA, ctx.string().getText(), ENTRY, e.getMessage()));
- }
- listener.getParsedDataStack().push(usesNode);
- } else {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER,
- USES_DATA, ctx.string().getText(), ENTRY));
- }
- }
-
- /**
- * It is called when parser exits from grammar rule (uses), it perform
- * validations and update the data model tree.
- *
- * @param listener Listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processUsesExit(TreeWalkListener listener,
- GeneratedYangParser.UsesStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, USES_DATA, ctx.string().getText(), EXIT);
-
- Parsable parsableUses = listener.getParsedDataStack().pop();
- if (!(parsableUses instanceof YangUses)) {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, USES_DATA,
- ctx.string().getText(), EXIT));
- }
- YangUses uses = (YangUses) parsableUses;
- int errorLine = ctx.getStart().getLine();
- int errorPosition = ctx.getStart().getCharPositionInLine();
-
- // Parent YANG node of uses to be added in resolution information.
- Parsable parentNode = listener.getParsedDataStack().peek();
-
- // Verify parent node of leaf
- if (!(parentNode instanceof YangNode)) {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, USES_DATA,
- ctx.string().getText(), EXIT));
- }
-
- // Add resolution information to the list
- YangResolutionInfoImpl resolutionInfo = new YangResolutionInfoImpl<YangUses>(uses,
- (YangNode) parentNode, errorLine,
- errorPosition);
- addToResolutionList(resolutionInfo, ctx);
- }
-
- // TODO linker to handle collision scenarios like leaf obtained by uses, conflicts with some existing leaf.
-
- /**
- * Validates the cardinality of case sub-statements as per grammar.
- *
- * @param ctx context object of the grammar rule
- */
- private static void validateSubStatementsCardinality(GeneratedYangParser.UsesStatementContext ctx) {
- validateCardinalityMaxOne(ctx.whenStatement(), WHEN_DATA, USES_DATA, ctx.string().getText());
- validateCardinalityMaxOne(ctx.statusStatement(), STATUS_DATA, USES_DATA, ctx.string().getText());
- validateCardinalityMaxOne(ctx.descriptionStatement(), DESCRIPTION_DATA, USES_DATA, ctx.string().getText());
- validateCardinalityMaxOne(ctx.referenceStatement(), REFERENCE_DATA, USES_DATA, ctx.string().getText());
- }
-
- /**
- * Add to resolution list.
- *
- * @param resolutionInfo resolution information.
- * @param ctx context object of the grammar rule
- */
- private static void addToResolutionList(YangResolutionInfoImpl<YangUses> resolutionInfo,
- GeneratedYangParser.UsesStatementContext ctx) {
-
- try {
- addResolutionInfo(resolutionInfo);
- } catch (DataModelException e) {
- throw new ParserException(constructExtendedListenerErrorMessage(UNHANDLED_PARSED_DATA,
- USES_DATA, ctx.string().getText(), EXIT, e.getMessage()));
- }
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ValueListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ValueListener.java
deleted file mode 100644
index 39efa6b..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/ValueListener.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-/*
- * Reference: RFC6020 and YANG ANTLR Grammar
- *
- * ABNF grammar as per RFC6020
- * value-stmt = value-keyword sep integer-value stmtend
- *
- * ANTLR grammar rule
- * valueStatement : VALUE_KEYWORD ((MINUS INTEGER) | INTEGER) STMTEND;
- */
-
-import org.onosproject.yangutils.datamodel.YangEnum;
-import org.onosproject.yangutils.datamodel.YangEnumeration;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.VALUE_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;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidIntegerValue;
-
-/**
- * Represents listener based call back function corresponding to the "value"
- * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
- */
-public final class ValueListener {
-
- /**
- * Creates a new value listener.
- */
- private ValueListener() {
- }
-
- /**
- * It is called when parser receives an input matching the grammar rule
- * (value), perform validations and update the data model tree.
- *
- * @param listener Listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processValueEntry(TreeWalkListener listener, GeneratedYangParser.ValueStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, VALUE_DATA, ctx.value().getText(), ENTRY);
-
- // Validate value
- int value = getValidIntegerValue(ctx.value().getText(), VALUE_DATA, ctx);
-
- // Obtain the node of the stack.
- Parsable tmpNode = listener.getParsedDataStack().peek();
- switch (tmpNode.getYangConstructType()) {
- case ENUM_DATA: {
- YangEnum enumNode = (YangEnum) tmpNode;
- if (!isEnumValueValid(listener, ctx, value)) {
- ParserException parserException = new ParserException("Duplicate Value Entry");
- parserException.setLine(ctx.getStart().getLine());
- parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
- throw parserException;
- }
- enumNode.setValue(value);
- break;
- }
- default:
- throw new ParserException(
- constructListenerErrorMessage(INVALID_HOLDER, VALUE_DATA, ctx.value().getText(), ENTRY));
- }
- }
-
- /**
- * Validates ENUM value uniqueness.
- *
- * @param listener Listener's object
- * @param ctx context object of the grammar rule
- * @param value enum value
- * @return validation result
- */
- private static boolean isEnumValueValid(TreeWalkListener listener, GeneratedYangParser.ValueStatementContext ctx,
- int value) {
- Parsable enumNode = listener.getParsedDataStack().pop();
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, VALUE_DATA, ctx.value().getText(), ENTRY);
-
- Parsable tmpNode = listener.getParsedDataStack().peek();
- switch (tmpNode.getYangConstructType()) {
- case ENUMERATION_DATA: {
- YangEnumeration yangEnumeration = (YangEnumeration) tmpNode;
- for (YangEnum curEnum : yangEnumeration.getEnumSet()) {
- if (value == curEnum.getValue()) {
- listener.getParsedDataStack().push(enumNode);
- return false;
- }
- }
- listener.getParsedDataStack().push(enumNode);
- return true;
- }
- default:
- listener.getParsedDataStack().push(enumNode);
- throw new ParserException(
- constructListenerErrorMessage(INVALID_HOLDER, VALUE_DATA, ctx.value().getText(), ENTRY));
- }
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/VersionListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/VersionListener.java
deleted file mode 100644
index 80caaa2..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/VersionListener.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-import org.onosproject.yangutils.datamodel.YangModule;
-import org.onosproject.yangutils.datamodel.YangSubModule;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.getValidVersion;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.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
- *
- * ABNF grammar as per RFC6020
- * module-header-stmts = ;; these stmts can appear in any order
- * [yang-version-stmt stmtsep]
- * namespace-stmt stmtsep
- * prefix-stmt stmtsep
- *
- * submodule-header-stmts =
- * ;; these stmts can appear in any order
- * [yang-version-stmt stmtsep]
- * belongs-to-stmt stmtsep
- *
- * yang-version-stmt = yang-version-keyword sep yang-version-arg-str
- * optsep stmtend
- *
- *
- * ANTLR grammar rule
- * module_header_statement : yang_version_stmt? namespace_stmt prefix_stmt
- * | yang_version_stmt? prefix_stmt namespace_stmt
- * | namespace_stmt yang_version_stmt? prefix_stmt
- * | namespace_stmt prefix_stmt yang_version_stmt?
- * | prefix_stmt namespace_stmt yang_version_stmt?
- * | prefix_stmt yang_version_stmt? namespace_stmt?
- * ;
- * submodule_header_statement : yang_version_stmt? belongs_to_stmt
- * | belongs_to_stmt yang_version_stmt?
- * ;
- * yang_version_stmt : YANG_VERSION_KEYWORD version STMTEND;
- * version : string;
- */
-
-/**
- * Represents listener based call back function corresponding to the "version"
- * rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
- */
-public final class VersionListener {
-
- /**
- * Creates a new version listener.
- */
- private VersionListener() {
- }
-
- /**
- * 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
- */
- public static void processVersionEntry(TreeWalkListener listener,
- GeneratedYangParser.YangVersionStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, VERSION_DATA, ctx.version().getText(), ENTRY);
-
- byte version = getValidVersion(ctx);
-
- // Obtain the node of the stack.
- Parsable tmpNode = listener.getParsedDataStack().peek();
- switch (tmpNode.getYangConstructType()) {
- case MODULE_DATA: {
- YangModule module = (YangModule) tmpNode;
- module.setVersion(version);
- break;
- }
- case SUB_MODULE_DATA: {
- YangSubModule subModule = (YangSubModule) tmpNode;
- subModule.setVersion(version);
- break;
- }
- default:
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, VERSION_DATA,
- ctx.version().getText(), ENTRY));
- }
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/WhenListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/WhenListener.java
deleted file mode 100644
index 218440f..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/WhenListener.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.listeners;
-
-import org.onosproject.yangutils.datamodel.YangWhen;
-import org.onosproject.yangutils.datamodel.YangWhenHolder;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.WHEN_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.INVALID_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_CURRENT_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.removeQuotesAndHandleConcat;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
-
-/*
- * Reference: RFC6020 and YANG ANTLR Grammar
- *
- * ABNF grammar as per RFC6020
- *
- * when-stmt = when-keyword sep string optsep
- * (";" /
- * "{" stmtsep
- * ;; these stmts can appear in any order
- * [description-stmt stmtsep]
- * [reference-stmt stmtsep]
- * "}")
- *
- * ANTLR grammar rule
- * whenStatement : WHEN_KEYWORD string (STMTEND | LEFT_CURLY_BRACE ((descriptionStatement? referenceStatement?)
- * | (referenceStatement? descriptionStatement?)) RIGHT_CURLY_BRACE);
- */
-
-/**
- * Represents listener based call back function corresponding to the
- * "when" rule defined in ANTLR grammar file for corresponding ABNF rule
- * in RFC 6020.
- */
-public final class WhenListener {
-
- /**
- * Creates a new when listener.
- */
- private WhenListener() {
- }
-
- /**
- * Perform validations and updates the data model tree.It is called when parser
- * receives an input matching the grammar rule (when).
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processWhenEntry(TreeWalkListener listener,
- GeneratedYangParser.WhenStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, WHEN_DATA, ctx.string().getText(), ENTRY);
- String condition = removeQuotesAndHandleConcat(ctx.string().getText());
-
- YangWhenHolder whenHolder;
-
- // Obtain the node of the stack.
- Parsable tmpNode = listener.getParsedDataStack().peek();
- if (tmpNode instanceof YangWhenHolder) {
- whenHolder = (YangWhenHolder) tmpNode;
-
- YangWhen when = new YangWhen();
- when.setCondition(condition);
-
- when.setLineNumber(ctx.getStart().getLine());
- when.setCharPosition(ctx.getStart().getCharPositionInLine());
- when.setFileName(listener.getFileName());
-
- whenHolder.setWhen(when);
- listener.getParsedDataStack().push(when);
- } else {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER,
- WHEN_DATA, ctx.string().getText(), ENTRY));
- }
- }
-
- /**
- * Performs validation and updates the data model tree.It is called when parser
- * exits from grammar rule (when).
- *
- * @param listener listener's object
- * @param ctx context object of the grammar rule
- */
- public static void processWhenExit(TreeWalkListener listener,
- GeneratedYangParser.WhenStatementContext ctx) {
-
- // Check for stack to be non empty.
- checkStackIsNotEmpty(listener, MISSING_HOLDER, WHEN_DATA, ctx.string().getText(), EXIT);
-
- if (listener.getParsedDataStack().peek() instanceof YangWhen) {
- listener.getParsedDataStack().pop();
- } else {
- throw new ParserException(constructListenerErrorMessage(MISSING_CURRENT_HOLDER, WHEN_DATA,
- ctx.string().getText(), EXIT));
- }
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/package-info.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/package-info.java
deleted file mode 100644
index 240cd55..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/listeners/package-info.java
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * Provide call back functions for listeners based tree walk.
- */
-package org.onosproject.yangutils.parser.impl.listeners;
\ No newline at end of file
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/package-info.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/package-info.java
deleted file mode 100644
index d935f7b..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/package-info.java
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-/**
- * Parse the YANG information from ANTLR generated parse tree.
- */
-package org.onosproject.yangutils.parser.impl;
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerCollisionDetector.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerCollisionDetector.java
deleted file mode 100644
index 632f50d..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerCollisionDetector.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.parserutils;
-
-import org.onosproject.yangutils.datamodel.CollisionDetector;
-import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
-import org.onosproject.yangutils.datamodel.utils.YangConstructType;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-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.INVALID_HOLDER;
-
-/**
- * Represents the detector of YANG construct collision in a YANG file.
- */
-public final class ListenerCollisionDetector {
-
- /**
- * Creates a new listener collision.
- */
- private ListenerCollisionDetector() {
- }
-
- /**
- * Detects that the identifiers of all these child nodes must be unique
- * within all cases in a choice.
- *
- * @param listener listener's object
- * @param line line of identifier in YANG file, required for error
- * reporting
- * @param charPosition character position of identifier in YANG file,
- * required for error reporting
- * @param identifierName name for which uniqueness is to be detected
- * @param constructType type of YANG construct for which collision check is
- * to be performed
- * @throws ParserException if identifier is not unique
- */
- public static void detectCollidingChildUtil(TreeWalkListener listener, int line, int charPosition,
- String identifierName, YangConstructType constructType)
- throws ParserException {
-
- if (listener.getParsedDataStack().peek() instanceof CollisionDetector) {
- try {
- ((CollisionDetector) listener.getParsedDataStack().peek()).detectCollidingChild(
- identifierName, constructType);
- } catch (DataModelException e) {
- ParserException parserException = new ParserException(e.getMessage());
- parserException.setLine(line);
- parserException.setCharPosition(charPosition);
- throw parserException;
- }
- } else {
- throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, constructType, identifierName,
- EXIT));
- }
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerErrorLocation.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerErrorLocation.java
deleted file mode 100644
index c1c2888..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerErrorLocation.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.parserutils;
-
-/**
- * Represents listener error location.
- */
-public enum ListenerErrorLocation {
- /**
- * Represents that the error location is before processing.
- */
- ENTRY(),
-
- /**
- * Represents that the error location is before processing.
- */
- EXIT();
-
- /**
- * Returns the message corresponding to listener error location.
- *
- * @param errorLocation enum value for type of error
- * @return message corresponding to listener error location
- */
- public static String getErrorLocationMessage(ListenerErrorLocation errorLocation) {
-
- switch (errorLocation) {
- case ENTRY:
- return "before";
- case EXIT:
- return "after";
- default:
- return "during";
- }
- }
-}
\ No newline at end of file
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerErrorMessageConstruction.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerErrorMessageConstruction.java
deleted file mode 100644
index 15b2170..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerErrorMessageConstruction.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.parserutils;
-
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.getYangConstructType;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.getErrorLocationMessage;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.getErrorType;
-
-import org.onosproject.yangutils.datamodel.utils.YangConstructType;
-
-/**
- * Represents a utility to help construct detailed error message.
- */
-public final class ListenerErrorMessageConstruction {
-
- /**
- * Creates a object of listen error message.
- */
- private ListenerErrorMessageConstruction() {
- }
-
- /**
- * Constructs message for error with extended information and returns the
- * same.
- *
- * @param errorType error type needs to be set in error message
- * @param yangConstructType 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,
- YangConstructType yangConstructType,
- String parsableDataTypeName,
- ListenerErrorLocation errorLocation,
- String extendedErrorInformation) {
- String newErrorMessage;
- newErrorMessage = constructListenerErrorMessage(errorType, yangConstructType, parsableDataTypeName,
- errorLocation)
- + "\n"
- + "Error Information: "
- + extendedErrorInformation;
- return newErrorMessage;
- }
-
- /**
- * 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 yangConstructType 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
- * @return constructed error message
- */
- public static String constructListenerErrorMessage(ListenerErrorType errorType,
- YangConstructType yangConstructType,
- String parsableDataTypeName,
- ListenerErrorLocation errorLocation) {
-
- String errorMessage;
-
- errorMessage = "Internal parser error detected: " + getErrorType(errorType) + " "
- + getYangConstructType(yangConstructType);
-
- if (!parsableDataTypeName.isEmpty()) {
- errorMessage = errorMessage + " \"" + parsableDataTypeName + "\" ";
- } else {
- errorMessage = errorMessage + " ";
-
- }
- errorMessage = errorMessage + getErrorLocationMessage(errorLocation) + " processing.";
- return errorMessage;
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerErrorType.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerErrorType.java
deleted file mode 100644
index f1cb284..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerErrorType.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.parserutils;
-
-/**
- * Represents listener error type.
- */
-public enum ListenerErrorType {
- /**
- * Represents the parent holder in parsable stack for given YANG construct
- * is invalid.
- */
- INVALID_HOLDER(),
-
- /**
- * Represents the parent holder in parsable stack for given YANG construct
- * is missing.
- */
- MISSING_HOLDER(),
-
- /**
- * Represents the current holder in parsable stack for given YANG construct
- * is missing.
- */
- MISSING_CURRENT_HOLDER(),
-
- /**
- * Represents that the child in parsable stack for given YANG construct is
- * invalid.
- */
- INVALID_CHILD(),
-
- /**
- * Represents that the cardinality for given YANG construct is invalid.
- */
- INVALID_CARDINALITY(),
-
- /**
- * Represents that the entry is duplicate.
- */
- DUPLICATE_ENTRY(),
-
- /**
- * Represents that the content is invalid.
- */
- INVALID_CONTENT(),
-
- /**
- * Represents that the identifier collision is detected.
- */
- IDENTIFIER_COLLISION(),
-
- /**
- * Represents that some of earlier parsed data is not handled correctly.
- */
- UNHANDLED_PARSED_DATA();
-
- /**
- * Returns the message corresponding to listener error type.
- *
- * @param errorType enum value for type of error
- * @return message corresponding to listener error type
- */
- public static String getErrorType(ListenerErrorType errorType) {
-
- switch (errorType) {
- case INVALID_HOLDER:
- return "Invalid holder for";
- case MISSING_HOLDER:
- return "Missing holder at";
- case MISSING_CURRENT_HOLDER:
- return "Missing";
- case INVALID_CHILD:
- return "Invalid child in";
- case INVALID_CARDINALITY:
- return "Invalid cardinality in";
- case DUPLICATE_ENTRY:
- return "Duplicate";
- case INVALID_CONTENT:
- return "Invalid content in";
- case IDENTIFIER_COLLISION:
- return "Identifier collision detected for";
- case UNHANDLED_PARSED_DATA:
- return "Unhandled parsed data at";
- default:
- return "Problem in";
- }
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerUtil.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerUtil.java
deleted file mode 100644
index df1dcad..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerUtil.java
+++ /dev/null
@@ -1,1058 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.parserutils;
-
-import org.antlr.v4.runtime.ParserRuleContext;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.onosproject.yangutils.datamodel.YangAtomicPath;
-import org.onosproject.yangutils.datamodel.YangImport;
-import org.onosproject.yangutils.datamodel.YangLeaf;
-import org.onosproject.yangutils.datamodel.YangLeafRef;
-import org.onosproject.yangutils.datamodel.YangLeavesHolder;
-import org.onosproject.yangutils.datamodel.YangList;
-import org.onosproject.yangutils.datamodel.YangModule;
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
-import org.onosproject.yangutils.datamodel.YangPathPredicate;
-import org.onosproject.yangutils.datamodel.YangReferenceResolver;
-import org.onosproject.yangutils.datamodel.YangRelativePath;
-import org.onosproject.yangutils.datamodel.YangSubModule;
-import org.onosproject.yangutils.datamodel.utils.YangConstructType;
-import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.regex.Pattern;
-
-import static org.onosproject.yangutils.datamodel.YangPathArgType.ABSOLUTE_PATH;
-import static org.onosproject.yangutils.datamodel.YangPathArgType.RELATIVE_PATH;
-import static org.onosproject.yangutils.datamodel.YangPathOperator.EQUALTO;
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.getYangConstructType;
-import static org.onosproject.yangutils.utils.UtilConstants.ADD;
-import static org.onosproject.yangutils.utils.UtilConstants.ANCESTOR_ACCESSOR;
-import static org.onosproject.yangutils.utils.UtilConstants.ANCESTOR_ACCESSOR_IN_PATH;
-import static org.onosproject.yangutils.utils.UtilConstants.CARET;
-import static org.onosproject.yangutils.utils.UtilConstants.CHAR_OF_CLOSE_SQUARE_BRACKET;
-import static org.onosproject.yangutils.utils.UtilConstants.CHAR_OF_OPEN_SQUARE_BRACKET;
-import static org.onosproject.yangutils.utils.UtilConstants.CHAR_OF_SLASH;
-import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS;
-import static org.onosproject.yangutils.utils.UtilConstants.COLON;
-import static org.onosproject.yangutils.utils.UtilConstants.CURRENT;
-import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.FALSE;
-import static org.onosproject.yangutils.utils.UtilConstants.OPEN_SQUARE_BRACKET;
-import static org.onosproject.yangutils.utils.UtilConstants.QUOTES;
-import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
-import static org.onosproject.yangutils.utils.UtilConstants.SLASH_FOR_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.TRUE;
-import static org.onosproject.yangutils.utils.UtilConstants.YANG_FILE_ERROR;
-
-/**
- * Represents an utility for listener.
- */
-public final class ListenerUtil {
-
- private static final Pattern IDENTIFIER_PATTERN = Pattern.compile("[a-zA-Z_][a-zA-Z0-9_.-]*");
- private static final String DATE_PATTERN = "[0-9]{4}-([0-9]{2}|[0-9])-([0-9]{2}|[0-9])";
- private static final String NON_NEGATIVE_INTEGER_PATTERN = "[0-9]+";
- private static final Pattern INTEGER_PATTERN = Pattern.compile("[-][0-9]+|[0-9]+");
- private static final Pattern PATH_PREDICATE_PATTERN = Pattern.compile("\\[(.*?)\\]");
- private static final String XML = "xml";
- private static final String ONE = "1";
- private static final int IDENTIFIER_LENGTH = 64;
- private static final String DATE_FORMAT = "yyyy-MM-dd";
- private static final Log log = LogFactory.getLog(ListenerUtil.class);
-
- /**
- * Creates a new listener util.
- */
- private ListenerUtil() {
- }
-
- /**
- * Removes doubles quotes and concatenates if string has plus symbol.
- *
- * @param yangStringData string from yang file
- * @return concatenated string after removing double quotes
- */
- public static String removeQuotesAndHandleConcat(String yangStringData) {
-
- yangStringData = yangStringData.replace("\"", EMPTY_STRING);
- String[] tmpData = yangStringData.split(Pattern.quote(ADD));
- StringBuilder builder = new StringBuilder();
- for (String yangString : tmpData) {
- builder.append(yangString);
- }
- return builder.toString();
- }
-
- /**
- * Validates identifier and returns concatenated string if string contains plus symbol.
- *
- * @param identifier string from yang file
- * @param yangConstruct yang construct for creating error message
- * @param ctx yang construct's context to get the line number and character position
- * @return concatenated string after removing double quotes
- */
- public static String getValidIdentifier(String identifier, YangConstructType yangConstruct, ParserRuleContext ctx) {
-
- String identifierString = removeQuotesAndHandleConcat(identifier);
- ParserException parserException;
-
- if (identifierString.length() > IDENTIFIER_LENGTH) {
- parserException = new ParserException("YANG file error : " +
- getYangConstructType(yangConstruct) + " name " + identifierString + " is " +
- "greater than 64 characters.");
- } else if (!IDENTIFIER_PATTERN.matcher(identifierString).matches()) {
- parserException = new ParserException("YANG file error : " +
- getYangConstructType(yangConstruct) + " name " + identifierString + " is not " +
- "valid.");
- } else if (identifierString.toLowerCase().startsWith(XML)) {
- parserException = new ParserException("YANG file error : " +
- getYangConstructType(yangConstruct) + " identifier " + identifierString +
- " must not start with (('X'|'x') ('M'|'m') ('L'|'l')).");
- } else {
- return identifierString;
- }
-
- parserException.setLine(ctx.getStart().getLine());
- parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
- throw parserException;
- }
-
- /**
- * Validates identifier and returns concatenated string if string contains plus symbol.
- *
- * @param identifier string from yang file
- * @param yangConstruct yang construct for creating error message
- * @param ctx yang construct's context to get the line number and character position
- * @param yangLeafRef instance of leafref where the path argument has to be set
- * @return concatenated string after removing double quotes
- */
- public static String getValidIdentifierForLeafref(String identifier, YangConstructType yangConstruct,
- ParserRuleContext ctx, YangLeafRef yangLeafRef) {
-
- String identifierString = removeQuotesAndHandleConcat(identifier);
- ParserException parserException;
-
- if (identifierString.length() > IDENTIFIER_LENGTH) {
- parserException = new ParserException("YANG file error : " + " identifier " + identifierString + " in " +
- getYangConstructType(yangConstruct) + " " + yangLeafRef.getPath() + " is " +
- "greater than 64 characters.");
- } else if (!IDENTIFIER_PATTERN.matcher(identifierString).matches()) {
- parserException = new ParserException("YANG file error : " + " identifier " + identifierString + " in " +
- getYangConstructType(yangConstruct) + " " + yangLeafRef.getPath() + " is not " +
- "valid.");
- } else if (identifierString.toLowerCase().startsWith(XML)) {
- parserException = new ParserException("YANG file error : " + " identifier " + identifierString + " in " +
- getYangConstructType(yangConstruct) + " " + yangLeafRef.getPath() +
- " must not start with (('X'|'x') ('M'|'m') ('L'|'l')).");
- } else {
- return identifierString;
- }
-
- parserException.setLine(ctx.getStart().getLine());
- parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
- throw parserException;
- }
-
- /**
- * Validates the revision date.
- *
- * @param dateToValidate input revision date
- * @return validation result, true for success, false for failure
- */
- public static boolean isDateValid(String dateToValidate) {
- if (dateToValidate == null || !dateToValidate.matches(DATE_PATTERN)) {
- return false;
- }
-
- SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
- sdf.setLenient(false);
-
- try {
- //if not valid, it will throw ParseException
- sdf.parse(dateToValidate);
- } catch (ParseException e) {
- return false;
- }
-
- return true;
- }
-
- /**
- * Validates YANG version.
- *
- * @param ctx version context object of the grammar rule
- * @return valid version
- */
- public static byte getValidVersion(GeneratedYangParser.YangVersionStatementContext ctx) {
-
- String value = removeQuotesAndHandleConcat(ctx.version().getText());
- if (!value.equals(ONE)) {
- ParserException parserException = new ParserException("YANG file error: Input version not supported");
- parserException.setLine(ctx.getStart().getLine());
- parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
- throw parserException;
- }
-
- return Byte.valueOf(value);
- }
-
- /**
- * Validates non negative integer value.
- *
- * @param integerValue integer to be validated
- * @param yangConstruct yang construct for creating error message
- * @param ctx context object of the grammar rule
- * @return valid non negative integer value
- */
- public static int getValidNonNegativeIntegerValue(String integerValue, YangConstructType yangConstruct,
- ParserRuleContext ctx) {
-
- String value = removeQuotesAndHandleConcat(integerValue);
- if (!value.matches(NON_NEGATIVE_INTEGER_PATTERN)) {
- ParserException parserException = new ParserException("YANG file error : " +
- getYangConstructType(yangConstruct) + " value " + value + " is not " +
- "valid.");
- parserException.setLine(ctx.getStart().getLine());
- parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
- throw parserException;
- }
-
- int valueInInteger;
- try {
- valueInInteger = Integer.parseInt(value);
- } catch (NumberFormatException e) {
- ParserException parserException = new ParserException("YANG file error : " +
- getYangConstructType(yangConstruct) + " value " + value + " is not " +
- "valid.");
- parserException.setLine(ctx.getStart().getLine());
- parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
- throw parserException;
- }
- return valueInInteger;
- }
-
- /**
- * Validates integer value.
- *
- * @param integerValue integer to be validated
- * @param yangConstruct yang construct for creating error message
- * @param ctx context object of the grammar rule
- * @return valid integer value
- */
- public static int getValidIntegerValue(String integerValue, YangConstructType yangConstruct,
- ParserRuleContext ctx) {
-
- String value = removeQuotesAndHandleConcat(integerValue);
- if (!INTEGER_PATTERN.matcher(value).matches()) {
- ParserException parserException = new ParserException("YANG file error : " +
- getYangConstructType(yangConstruct) + " value " + value + " is not " +
- "valid.");
- parserException.setLine(ctx.getStart().getLine());
- parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
- throw parserException;
- }
-
- int valueInInteger;
- try {
- valueInInteger = Integer.parseInt(value);
- } catch (NumberFormatException e) {
- ParserException parserException = new ParserException("YANG file error : " +
- getYangConstructType(yangConstruct) + " value " + value + " is not " +
- "valid.");
- parserException.setLine(ctx.getStart().getLine());
- parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
- throw parserException;
- }
- return valueInInteger;
- }
-
- /**
- * Validates boolean value.
- *
- * @param booleanValue value to be validated
- * @param yangConstruct yang construct for creating error message
- * @param ctx context object of the grammar rule
- * @return boolean value either true or false
- */
- public static boolean getValidBooleanValue(String booleanValue, YangConstructType yangConstruct,
- ParserRuleContext ctx) {
-
- String value = removeQuotesAndHandleConcat(booleanValue);
- if (value.equals(TRUE)) {
- return true;
- } else if (value.equals(FALSE)) {
- return false;
- } else {
- ParserException parserException = new ParserException("YANG file error : " +
- getYangConstructType(yangConstruct) + " value " + value + " is not " +
- "valid.");
- parserException.setLine(ctx.getStart().getLine());
- parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
- throw parserException;
- }
- }
-
- /**
- * Returns current date and makes it in usable format for revision.
- *
- * @return usable current date format for revision
- */
- public static Date getCurrentDateForRevision() {
-
- SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
-
- Date date = new Date();
- String dateInString = dateFormat.format(date);
- try {
- //if not valid, it will throw ParseException
- Date now = dateFormat.parse(dateInString);
- return date;
- } catch (ParseException e) {
- ParserException parserException = new ParserException("YANG file error: Input date is not correct");
- throw parserException;
- }
- }
-
- /**
- * Checks and return valid node identifier.
- *
- * @param nodeIdentifierString string from yang file
- * @param yangConstruct yang construct for creating error message
- * @param ctx yang construct's context to get the line number and character position
- * @return valid node identifier
- */
- public static YangNodeIdentifier getValidNodeIdentifier(String nodeIdentifierString,
- YangConstructType yangConstruct, ParserRuleContext ctx) {
- String tmpIdentifierString = removeQuotesAndHandleConcat(nodeIdentifierString);
- String[] tmpData = tmpIdentifierString.split(Pattern.quote(COLON));
- if (tmpData.length == 1) {
- YangNodeIdentifier nodeIdentifier = new YangNodeIdentifier();
- nodeIdentifier.setName(getValidIdentifier(tmpData[0], yangConstruct, ctx));
- return nodeIdentifier;
- } else if (tmpData.length == 2) {
- YangNodeIdentifier nodeIdentifier = new YangNodeIdentifier();
- nodeIdentifier.setPrefix(getValidIdentifier(tmpData[0], yangConstruct, ctx));
- nodeIdentifier.setName(getValidIdentifier(tmpData[1], yangConstruct, ctx));
- return nodeIdentifier;
- } else {
- ParserException parserException = new ParserException("YANG file error : " +
- getYangConstructType(yangConstruct) + " name " + nodeIdentifierString +
- " is not valid.");
- parserException.setLine(ctx.getStart().getLine());
- parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
- throw parserException;
- }
- }
-
- /**
- * Checks and return valid node identifier specific to nodes in leafref path.
- *
- * @param nodeIdentifierString string from yang file
- * @param yangConstruct yang construct for creating error message
- * @param ctx yang construct's context to get the line number and character position
- * @param yangLeafRef instance of leafref where the path argument has to be set
- * @return valid node identifier
- */
- public static YangNodeIdentifier getValidNodeIdentifierForLeafref(String nodeIdentifierString,
- YangConstructType yangConstruct,
- ParserRuleContext ctx, YangLeafRef yangLeafRef) {
-
- String tmpIdentifierString = removeQuotesAndHandleConcat(nodeIdentifierString);
- String[] tmpData = tmpIdentifierString.split(Pattern.quote(COLON));
- if (tmpData.length == 1) {
- YangNodeIdentifier nodeIdentifier = new YangNodeIdentifier();
- nodeIdentifier.setName(getValidIdentifierForLeafref(tmpData[0], yangConstruct, ctx, yangLeafRef));
- return nodeIdentifier;
- } else if (tmpData.length == 2) {
- YangNodeIdentifier nodeIdentifier = new YangNodeIdentifier();
- nodeIdentifier.setPrefix(getValidIdentifierForLeafref(tmpData[0], yangConstruct, ctx, yangLeafRef));
- nodeIdentifier.setName(getValidIdentifierForLeafref(tmpData[1], yangConstruct, ctx, yangLeafRef));
- return nodeIdentifier;
- } else {
- ParserException parserException = new ParserException("YANG file error : " +
- getYangConstructType(yangConstruct) + yangLeafRef.getPath() +
- " is not valid.");
- parserException.setLine(ctx.getStart().getLine());
- parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
- throw parserException;
- }
- }
-
- /**
- * Validates the path argument. It can be either absolute or relative path.
- *
- * @param pathString the path string from the path type
- * @param yangConstruct yang construct for creating error message
- * @param ctx yang construct's context to get the line number and character position
- * @param yangLeafRef instance of leafref where the path argument has to be set
- */
- public static void validatePathArgument(String pathString, YangConstructType yangConstruct,
- ParserRuleContext ctx, YangLeafRef yangLeafRef) {
-
- String completePathString = removeQuotesAndHandleConcat(pathString);
- yangLeafRef.setPath(completePathString);
- if (completePathString.startsWith(SLASH)) {
- yangLeafRef.setPathType(ABSOLUTE_PATH);
- List<YangAtomicPath> yangAtomicPathListList = validateAbsolutePath(completePathString, yangConstruct, ctx,
- yangLeafRef);
- validatePrefixAndYangNode(yangAtomicPathListList, yangLeafRef);
- yangLeafRef.setAtomicPath(yangAtomicPathListList);
- } else if (completePathString.startsWith(ANCESTOR_ACCESSOR)) {
- yangLeafRef.setPathType(RELATIVE_PATH);
- validateRelativePath(completePathString, yangConstruct, ctx, yangLeafRef);
- } else {
- ParserException parserException = new ParserException("YANG file error : " +
- getYangConstructType(yangConstruct) + yangLeafRef.getPath() +
- " does not follow valid path syntax");
- parserException.setLine(ctx.getStart().getLine());
- parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
- throw parserException;
- }
- }
-
- /**
- * Validates the prefixes in the leafref and assigns them to the respective imported name in map.
- *
- * @param yangAtomicPathList list of atomic poth
- * @param yangLeafRef instance YANG leafref
- */
- private static void validatePrefixAndYangNode(List<YangAtomicPath> yangAtomicPathList, YangLeafRef yangLeafRef) {
- Iterator<YangAtomicPath> yangAtomicPathIterator = yangAtomicPathList.listIterator();
- while (yangAtomicPathIterator.hasNext()) {
- YangAtomicPath atomicPath = yangAtomicPathIterator.next();
- String prefix = atomicPath.getNodeIdentifier().getPrefix();
- YangNode parentNodeOfLeafref = yangLeafRef.getParentNodeOfLeafref();
- YangNode moduleOrSubModule = getModuleOrSubmoduleInFileOfTheCurrentNode(parentNodeOfLeafref);
- YangModule moduleNode = null;
- if (moduleOrSubModule instanceof YangModule) {
- moduleNode = (YangModule) moduleOrSubModule;
- }
- if (moduleNode != null) {
- updatePrefixWithTheImportedList(moduleNode, prefix, yangLeafRef);
- }
- }
- }
-
- /**
- * Updates the prefix with the imported list in the module.
- *
- * @param moduleNode root node of the leafref
- * @param prefixInPath prefix in the path
- * @param yangLeafRef instance YANG leafref
- */
- private static void updatePrefixWithTheImportedList(YangModule moduleNode, String prefixInPath, YangLeafRef
- yangLeafRef) {
- if (prefixInPath != null && prefixInPath != EMPTY_STRING && !prefixInPath.equals(moduleNode.getPrefix())) {
- List<YangImport> moduleImportList = moduleNode.getImportList();
- if (moduleImportList != null && !moduleImportList.isEmpty()) {
- Iterator<YangImport> yangImportIterator = moduleImportList.listIterator();
- while (yangImportIterator.hasNext()) {
- YangImport yangImport = yangImportIterator.next();
- if (yangImport.getPrefixId().equals(prefixInPath)) {
- HashMap prefixMap = new HashMap();
- prefixMap.put(prefixInPath, yangImport.getModuleName());
- yangLeafRef.setPrefixAndItsImportedModule(prefixMap);
- }
- }
- }
- } else {
- HashMap prefixMap = new HashMap();
- prefixMap.put(prefixInPath, moduleNode.getName());
- yangLeafRef.setPrefixAndItsImportedModule(prefixMap);
- }
- }
-
- /**
- * Returns module or submodule node from the current node.
- *
- * @param node current node
- * @return root node
- */
- private static YangNode getModuleOrSubmoduleInFileOfTheCurrentNode(YangNode node) {
- while (!(node instanceof YangModule) && !(node instanceof YangSubModule)) {
- if (node == null) {
- throw new ParserException("Internal datamodel error: Datamodel tree is not correct");
- }
- node = node.getParent();
- }
- return node;
- }
-
- /**
- * Validates the unique syntax from the reference path.
- *
- * @param uniquePath path of unique
- * @param prefixOfFile current file's prefix
- * @param ctx yang construct's context to get the line number and character position
- * @return list of absolute path
- */
- private static List<YangAtomicPath> validateUniqueValues(String uniquePath, String prefixOfFile,
- ParserRuleContext ctx) {
- List<YangAtomicPath> atomicPath = new LinkedList<>();
- String[] pathInUnique = uniquePath.split(SLASH_FOR_STRING);
- for (String uniqueValue : pathInUnique) {
- YangAtomicPath yangAtomicPathPath = new YangAtomicPath();
- YangNodeIdentifier nodeIdentifier = getValidNodeIdentifier(uniqueValue, YangConstructType.UNIQUE_DATA, ctx);
- yangAtomicPathPath.setNodeIdentifier(nodeIdentifier);
- atomicPath.add(yangAtomicPathPath);
- if (nodeIdentifier.getPrefix() != null && nodeIdentifier.getPrefix() != prefixOfFile) {
- ParserException parserException = new ParserException("YANG file error : A leaf reference, in unique," +
- " must refer to a leaf in the list");
- parserException.setLine(ctx.getStart().getLine());
- parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
- throw parserException;
- }
- }
- return atomicPath;
- }
-
- /**
- * Validates unique field from the list.
- *
- * @param yangList instance of YANG list
- * @param ctx yang construct's context to get the line number and character position
- */
- public static void validateUniqueInList(YangList yangList, ParserRuleContext ctx) {
- YangLeaf leaf;
- // Returns the prefix for the file where unique is present.
- String prefixOfTheFile = getPrefixInFileOfTheCurrentNode(yangList);
- List<String> uniques = yangList.getUniqueList();
- if (uniques != null && !uniques.isEmpty()) {
- Iterator<String> uniqueList = uniques.listIterator();
- while (uniqueList.hasNext()) {
- String pathInUnique = uniqueList.next();
- List<YangAtomicPath> atomicPathInUnique = validateUniqueValues(pathInUnique, prefixOfTheFile, ctx);
- YangAtomicPath leafInPath = atomicPathInUnique.get(atomicPathInUnique.size() - 1);
- if (atomicPathInUnique.size() == 1) {
- leaf = getReferenceLeafFromUnique(yangList, leafInPath);
- } else {
- atomicPathInUnique.remove(atomicPathInUnique.size() - 1);
- YangNode holderOfLeaf = getNodeUnderListFromPath(atomicPathInUnique, yangList, ctx);
- leaf = getReferenceLeafFromUnique(holderOfLeaf, leafInPath);
- }
- if (leaf == null) {
- ParserException parserException = new ParserException("YANG file error : A leaf reference, in " +
- "unique," +
- " must refer to a leaf under the list");
- parserException.setLine(ctx.getStart().getLine());
- parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
- throw parserException;
- }
- }
- }
- }
-
- /**
- * Returns the last node under the unique path.
- *
- * @param uniquePath atomic path list
- * @param node root node from where it starts searching
- * @param ctx yang construct's context to get the line number and character position
- * @return last node in the list
- */
- private static YangNode getNodeUnderListFromPath(List<YangAtomicPath> uniquePath, YangNode node,
- ParserRuleContext ctx) {
- Iterator<YangAtomicPath> nodesInReference = uniquePath.listIterator();
- YangNode potentialReferredNode = node.getChild();
- while (nodesInReference.hasNext()) {
- YangAtomicPath nodeInUnique = nodesInReference.next();
- YangNode referredNode = getReferredNodeFromTheUniqueNodes(nodeInUnique.getNodeIdentifier(),
- potentialReferredNode);
- if (referredNode == null) {
- ParserException parserException = new ParserException("YANG file error : The target node in unique " +
- "reference path is invalid");
- parserException.setLine(ctx.getStart().getLine());
- parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
- throw parserException;
- } else {
- potentialReferredNode = referredNode.getChild();
- }
- }
- return potentialReferredNode;
- }
-
- /**
- * Returns the node that matches with the name of the node in path.
- *
- * @param nodeInUnique node name in path
- * @param potentialReferredNode node under which it has to match
- * @return referred node
- */
- private static YangNode getReferredNodeFromTheUniqueNodes(YangNodeIdentifier nodeInUnique, YangNode
- potentialReferredNode) {
- while (potentialReferredNode != null) {
- // Check if the potential referred node is the actual referred node
- if (potentialReferredNode.getName().equals(nodeInUnique.getName())) {
- return potentialReferredNode;
- }
- potentialReferredNode = potentialReferredNode.getNextSibling();
- }
- return null;
- }
-
- /**
- * Returns the leaf which unique refers.
- *
- * @param nodeForLeaf last node where leaf is referred
- * @param leafInUnique leaf in unique path
- * @return YANG leaf
- */
- private static YangLeaf getReferenceLeafFromUnique(YangNode nodeForLeaf, YangAtomicPath leafInUnique) {
- YangLeavesHolder leavesHolder = (YangLeavesHolder) nodeForLeaf;
- List<YangLeaf> leaves = leavesHolder.getListOfLeaf();
- if (leaves != null && !leaves.isEmpty()) {
- for (YangLeaf leaf : leaves) {
- if (leafInUnique.getNodeIdentifier().getName().equals(leaf.getName())) {
- return leaf;
- }
- }
- }
- return null;
- }
-
- /**
- * Returns the prefix of the current file.
- *
- * @param node node where it needs to find the root node
- * @return prefix of root node
- */
- public static String getPrefixInFileOfTheCurrentNode(YangNode node) {
- String prefixInFile;
- while (!(node instanceof YangReferenceResolver)) {
- node = node.getParent();
- if (node == null) {
- throw new ParserException("Internal datamodel error: Datamodel tree is not correct");
- }
- }
- if (node instanceof YangModule) {
- YangModule yangModule = (YangModule) node;
- prefixInFile = yangModule.getPrefix();
- } else {
- YangSubModule yangSubModule = (YangSubModule) node;
- prefixInFile = yangSubModule.getPrefix();
- }
- return prefixInFile;
- }
-
- /**
- * Validates the relative path.
- *
- * @param completePathString the path string of relative path
- * @param yangConstruct yang construct for creating error message
- * @param ctx yang construct's context to get the line number and character position
- * @param yangLeafRef instance of leafref where the path argument has to be set
- */
- private static void validateRelativePath(String completePathString, YangConstructType yangConstruct,
- ParserRuleContext ctx, YangLeafRef yangLeafRef) {
-
- YangRelativePath relativePath = new YangRelativePath();
- int numberOfAncestors = 0;
- while (completePathString.startsWith(ANCESTOR_ACCESSOR_IN_PATH)) {
- completePathString = completePathString.replaceFirst(ANCESTOR_ACCESSOR_IN_PATH, EMPTY_STRING);
- numberOfAncestors = numberOfAncestors + 1;
- }
- if (completePathString == null || completePathString.length() == 0) {
- ParserException parserException = new ParserException("YANG file error : "
- + getYangConstructType(yangConstruct) + yangLeafRef.getPath() +
- " does not follow valid path syntax");
- parserException.setLine(ctx.getStart().getLine());
- parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
- throw parserException;
- }
- relativePath.setAncestorNodeCount(numberOfAncestors);
- List<YangAtomicPath> atomicPath = validateAbsolutePath(SLASH_FOR_STRING + completePathString,
- yangConstruct,
- ctx, yangLeafRef);
- validatePrefixAndYangNode(atomicPath, yangLeafRef);
- relativePath.setAtomicPathList(atomicPath);
- yangLeafRef.setRelativePath(relativePath);
- }
-
- /**
- * Validates the absolute path.
- *
- * @param completePathString the path string of absolute path
- * @param yangConstruct yang construct for creating error message
- * @param ctx yang construct's context to get the line number and character position
- * @param yangLeafRef instance of leafref where the path argument has to be set
- * @return list of object of node in absolute path
- */
- private static List<YangAtomicPath> validateAbsolutePath(String completePathString,
- YangConstructType yangConstruct, ParserRuleContext
- ctx, YangLeafRef yangLeafRef) {
-
- List<YangAtomicPath> absolutePathList = new LinkedList<>();
- YangPathPredicate yangPathPredicate = new YangPathPredicate();
- YangNodeIdentifier yangNodeIdentifier;
-
- while (completePathString != null) {
- String path = completePathString.replaceFirst(SLASH_FOR_STRING, EMPTY_STRING);
- if (path == null || path.length() == 0) {
- ParserException parserException = new ParserException("YANG file error : "
- + getYangConstructType(yangConstruct) + " " + yangLeafRef.getPath() +
- " does not follow valid path syntax");
- parserException.setLine(ctx.getStart().getLine());
- parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
- throw parserException;
- }
- String matchedPathPredicate;
- String nodeIdentifier;
- String[] differentiate = new String[2];
- int forNodeIdentifier = path.indexOf(CHAR_OF_SLASH);
- int forPathPredicate = path.indexOf(CHAR_OF_OPEN_SQUARE_BRACKET);
-
- // Checks if path predicate is present for the node.
- if ((forPathPredicate < forNodeIdentifier) && (forPathPredicate != -1)) {
- List<String> pathPredicate = new ArrayList<>();
- matchedPathPredicate = matchForPathPredicate(path);
-
- if (matchedPathPredicate == null || matchedPathPredicate.length() == 0) {
- ParserException parserException = new ParserException("YANG file error : "
- + getYangConstructType(yangConstruct) + " " + yangLeafRef.getPath() +
- " does not follow valid path syntax");
- parserException.setLine(ctx.getStart().getLine());
- parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
- throw parserException;
- }
- int indexOfMatchedFirstOpenBrace = path.indexOf(CHAR_OF_OPEN_SQUARE_BRACKET);
- differentiate[0] = path.substring(0, indexOfMatchedFirstOpenBrace);
- differentiate[1] = path.substring(indexOfMatchedFirstOpenBrace);
- pathPredicate.add(matchedPathPredicate);
- nodeIdentifier = differentiate[0];
- // Starts adding all path predicates of a node into the list.
- if (!differentiate[1].isEmpty()) {
- while (differentiate[1].startsWith(OPEN_SQUARE_BRACKET)) {
- matchedPathPredicate = matchForPathPredicate(differentiate[1]);
- if (matchedPathPredicate == null || matchedPathPredicate.length() == 0) {
- ParserException parserException = new ParserException(
- "YANG file error : " + getYangConstructType(yangConstruct) + " "
- + yangLeafRef.getPath() +
- " does not follow valid path syntax");
- parserException.setLine(ctx.getStart().getLine());
- parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
- throw parserException;
- }
- pathPredicate.add(matchedPathPredicate);
- differentiate[1] = differentiate[1].substring(matchedPathPredicate.length());
- }
- }
-
- List<YangPathPredicate> pathPredicateList = validatePathPredicate(pathPredicate, yangConstruct, ctx,
- yangPathPredicate, yangLeafRef);
- YangAtomicPath atomicPath = new YangAtomicPath();
- yangNodeIdentifier = getValidNodeIdentifierForLeafref(nodeIdentifier, yangConstruct, ctx, yangLeafRef);
- atomicPath.setNodeIdentifier(yangNodeIdentifier);
- atomicPath.setPathPredicatesList(pathPredicateList);
- absolutePathList.add(atomicPath);
- } else {
- if (path.contains(SLASH_FOR_STRING)) {
- nodeIdentifier = path.substring(0, path.indexOf(CHAR_OF_SLASH));
- differentiate[1] = path.substring(path.indexOf(CHAR_OF_SLASH));
- } else {
- nodeIdentifier = path;
- differentiate[1] = null;
- }
- yangNodeIdentifier = getValidNodeIdentifierForLeafref(nodeIdentifier, yangConstruct, ctx, yangLeafRef);
-
- YangAtomicPath atomicPath = new YangAtomicPath();
- atomicPath.setNodeIdentifier(yangNodeIdentifier);
- atomicPath.setPathPredicatesList(null);
- absolutePathList.add(atomicPath);
- }
- if (differentiate[1] == null || differentiate[1].length() == 0) {
- completePathString = null;
- } else {
- completePathString = differentiate[1];
- }
- }
- return absolutePathList;
- }
-
- /**
- * Validates path predicate in the absolute path's node.
- *
- * @param pathPredicate list of path predicates in the node of absolute path
- * @param yangConstruct yang construct for creating error message
- * @param ctx yang construct's context to get the line number and character position
- * @param yangPathPredicate instance of path predicate where it has to be set
- * @param yangLeafRef instance of leafref where the path argument has to be set
- * @return list of object of path predicates in absolute path's node
- */
- private static List<YangPathPredicate> validatePathPredicate(List<String> pathPredicate,
- YangConstructType yangConstruct, ParserRuleContext
- ctx, YangPathPredicate yangPathPredicate,
- YangLeafRef yangLeafRef) {
-
- Iterator<String> pathPredicateString = pathPredicate.iterator();
- List<String> pathEqualityExpression = new ArrayList<>();
-
- while (pathPredicateString.hasNext()) {
- String pathPredicateForNode = pathPredicateString.next();
- pathPredicateForNode = (pathPredicateForNode.substring(1)).trim();
- pathPredicateForNode = pathPredicateForNode.substring(0,
- pathPredicateForNode.indexOf(CHAR_OF_CLOSE_SQUARE_BRACKET));
- pathEqualityExpression.add(pathPredicateForNode);
- }
- List<YangPathPredicate> validatedPathPredicateList = validatePathEqualityExpression(pathEqualityExpression,
- yangConstruct, ctx, yangPathPredicate, yangLeafRef);
- return validatedPathPredicateList;
- }
-
- /**
- * Validates the path equality expression.
- *
- * @param pathEqualityExpression list of path equality expression in the path predicates of the node
- * @param yangConstruct yang construct for creating error message
- * @param ctx yang construct's context to get the line number and character position
- * @param yangPathPredicate instance of path predicate where it has to be set
- * @param yangLeafRef instance of leafref where the path argument has to be set
- * @return list of object of path predicates in absolute path's node
- */
- private static List<YangPathPredicate> validatePathEqualityExpression(List<String> pathEqualityExpression,
- YangConstructType yangConstruct,
- ParserRuleContext ctx, YangPathPredicate
- yangPathPredicate,
- YangLeafRef yangLeafRef) {
-
- Iterator<String> pathEqualityExpressionString = pathEqualityExpression.iterator();
- List<YangPathPredicate> yangPathPredicateList = new ArrayList<>();
-
- while (pathEqualityExpressionString.hasNext()) {
- String pathEqualityExpressionForNode = pathEqualityExpressionString.next();
- String[] pathEqualityExpressionArray = pathEqualityExpressionForNode.split("[=]");
-
- YangNodeIdentifier yangNodeIdentifierForPredicate;
- YangRelativePath yangRelativePath;
- yangNodeIdentifierForPredicate = getValidNodeIdentifierForLeafref(pathEqualityExpressionArray[0].trim(),
- yangConstruct, ctx, yangLeafRef);
- yangRelativePath = validatePathKeyExpression(pathEqualityExpressionArray[1].trim(), yangConstruct, ctx,
- yangLeafRef);
- yangPathPredicate.setNodeIdentifier(yangNodeIdentifierForPredicate);
- yangPathPredicate.setPathOperator(EQUALTO);
- yangPathPredicate.setRightRelativePath(yangRelativePath);
- yangPathPredicateList.add(yangPathPredicate);
- }
- return yangPathPredicateList;
- }
-
- /**
- * Validate the path key expression.
- *
- * @param rightRelativePath relative path in the path predicate
- * @param yangConstruct yang construct for creating error message
- * @param ctx yang construct's context to get the line number and character position
- * @param yangLeafRef instance of leafref where the path argument has to be set
- * @return object of right relative path in path predicate
- */
- private static YangRelativePath validatePathKeyExpression(String rightRelativePath,
- YangConstructType yangConstruct, ParserRuleContext ctx,
- YangLeafRef yangLeafRef) {
-
- YangRelativePath yangRelativePath = new YangRelativePath();
- String[] relativePath = rightRelativePath.split(SLASH_FOR_STRING);
- List<String> rightAbsolutePath = new ArrayList<>();
- int accessAncestor = 0;
- for (String path : relativePath) {
- if (path.trim().equals(ANCESTOR_ACCESSOR)) {
- accessAncestor = accessAncestor + 1;
- } else {
- rightAbsolutePath.add(path);
- }
- }
- List<YangAtomicPath> atomicPathInRelativePath = validateRelativePathKeyExpression(rightAbsolutePath,
- yangConstruct, ctx, yangLeafRef);
- yangRelativePath.setAtomicPathList(atomicPathInRelativePath);
- yangRelativePath.setAncestorNodeCount(accessAncestor);
- return yangRelativePath;
- }
-
- /**
- * Validates the relative path key expression.
- *
- * @param rightAbsolutePath absolute path nodes present in the relative path
- * @param yangConstruct yang construct for creating error message
- * @param ctx yang construct's context to get the line number and character position
- * @param yangLeafRef instance of leafref where the path argument has to be set
- * @return list of object of absolute path nodes present in the relative path
- */
- private static List<YangAtomicPath> validateRelativePathKeyExpression(List<String> rightAbsolutePath,
- YangConstructType yangConstruct,
- ParserRuleContext ctx, YangLeafRef
- yangLeafRef) {
-
- List<YangAtomicPath> atomicPathList = new ArrayList<>();
- YangNodeIdentifier yangNodeIdentifier;
-
- Iterator<String> nodes = rightAbsolutePath.iterator();
- String currentInvocationFunction = nodes.next();
- currentInvocationFunction = currentInvocationFunction.trim();
- String[] currentFunction = currentInvocationFunction.split("[(]");
-
- if (!(currentFunction[0].trim().equals(CURRENT)) || !(currentFunction[1].trim().equals(CLOSE_PARENTHESIS))) {
- ParserException parserException = new ParserException("YANG file error : "
- + getYangConstructType(yangConstruct) + " " + yangLeafRef.getPath() +
- " does not follow valid path syntax");
- parserException.setLine(ctx.getStart().getLine());
- parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
- throw parserException;
- }
-
- while (nodes.hasNext()) {
- YangAtomicPath atomicPath = new YangAtomicPath();
- String node = nodes.next();
- yangNodeIdentifier = getValidNodeIdentifierForLeafref(node.trim(), yangConstruct, ctx, yangLeafRef);
- atomicPath.setNodeIdentifier(yangNodeIdentifier);
- atomicPathList.add(atomicPath);
- }
- return atomicPathList;
- }
-
- /**
- * Validates the match for first path predicate in a given string.
- *
- * @param matchRequiredString string for which match has to be done
- * @return the matched string
- */
- private static String matchForPathPredicate(String matchRequiredString) {
-
- String matchedString = null;
- java.util.regex.Matcher matcher = PATH_PREDICATE_PATTERN.matcher(matchRequiredString);
- if (matcher.find()) {
- matchedString = matcher.group(0);
- }
- return matchedString;
- }
-
- /**
- * Checks and return valid absolute schema node id.
- *
- * @param argumentString string from yang file
- * @param yangConstructType yang construct for creating error message
- * @param ctx yang construct's context to get the line number and character position
- * @return target nodes list of absolute schema node id
- */
- public static List<YangAtomicPath> getValidAbsoluteSchemaNodeId(String argumentString,
- YangConstructType yangConstructType,
- ParserRuleContext ctx) {
-
- List<YangAtomicPath> targetNodes = new ArrayList<>();
- YangNodeIdentifier yangNodeIdentifier;
- String tmpSchemaNodeId = removeQuotesAndHandleConcat(argumentString);
-
- // absolute-schema-nodeid = 1*("/" node-identifier)
- if (!tmpSchemaNodeId.startsWith(SLASH)) {
- ParserException parserException = new ParserException("YANG file error : " +
- getYangConstructType(yangConstructType) + " name " + argumentString +
- "is not valid");
- parserException.setLine(ctx.getStart().getLine());
- parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
- throw parserException;
- }
- String[] tmpData = tmpSchemaNodeId.replaceFirst(CARET + SLASH, EMPTY_STRING).split(SLASH);
- for (String nodeIdentifiers : tmpData) {
- yangNodeIdentifier = getValidNodeIdentifier(nodeIdentifiers, yangConstructType, ctx);
- YangAtomicPath yangAbsPath = new YangAtomicPath();
- yangAbsPath.setNodeIdentifier(yangNodeIdentifier);
- targetNodes.add(yangAbsPath);
- }
- return targetNodes;
- }
-
- /**
- * Throws parser exception for unsupported YANG constructs.
- *
- * @param yangConstructType yang construct for creating error message
- * @param ctx yang construct's context to get the line number and character position
- * @param errorInfo error information
- * @param fileName YANG file name
- */
- public static void handleUnsupportedYangConstruct(YangConstructType yangConstructType,
- ParserRuleContext ctx, String errorInfo, String fileName) {
- ParserException parserException = new ParserException(YANG_FILE_ERROR
- + QUOTES + getYangConstructType(yangConstructType) + QUOTES
- + errorInfo);
- parserException.setLine(ctx.getStart().getLine());
- parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
- log.info(parserException.getMessage() + " at position " + parserException.getCharPositionInLine() +
- " in line " + parserException.getLineNumber() + " of yang file " + fileName);
- }
-
- /**
- * Returns date and makes it in usable format for revision.
- *
- * @param dateInString date argument string from yang file
- * @param ctx yang construct's context to get the line number and character position
- * @return date format for revision
- */
- public static Date getValidDateFromString(String dateInString, ParserRuleContext ctx) {
- String dateArgument = removeQuotesAndHandleConcat(dateInString);
- if (!dateArgument.matches(DATE_PATTERN)) {
- ParserException parserException = new ParserException("YANG file error: Input date is not correct");
- parserException.setLine(ctx.getStart().getLine());
- parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
- throw parserException;
- }
-
- SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
- sdf.setLenient(false);
-
- try {
- //if not valid, it will throw ParseException
- return sdf.parse(dateArgument);
- } catch (ParseException e) {
- ParserException parserException = new ParserException("YANG file error: Input date is not correct");
- parserException.setLine(ctx.getStart().getLine());
- parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
- throw parserException;
- }
- }
-
- /**
- * Checks and return valid prefix.
- *
- * @param inputString string from yang file
- * @param yangConstruct yang construct for creating error message
- * @param ctx yang construct's context to get the line number and character position
- * @return valid prefix
- */
- public static String getValidPrefix(String inputString,
- YangConstructType yangConstruct, ParserRuleContext ctx) {
- String tmpPrefixString = removeQuotesAndHandleConcat(inputString);
- String[] tmpData = tmpPrefixString.split(Pattern.quote(COLON));
- if (tmpData.length == 2) {
- return tmpData[0];
- } else {
- ParserException parserException = new ParserException("YANG file error : " +
- getYangConstructType(yangConstruct) + " name " + inputString +
- " is not valid.");
- parserException.setLine(ctx.getStart().getLine());
- parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
- throw parserException;
- }
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerValidation.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerValidation.java
deleted file mode 100644
index fa3b200..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerValidation.java
+++ /dev/null
@@ -1,243 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.parserutils;
-
-import java.util.Iterator;
-import java.util.List;
-
-import org.antlr.v4.runtime.ParserRuleContext;
-import org.onosproject.yangutils.datamodel.YangCase;
-import org.onosproject.yangutils.datamodel.YangChoice;
-import org.onosproject.yangutils.datamodel.YangConfig;
-import org.onosproject.yangutils.datamodel.YangInput;
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.YangNotification;
-import org.onosproject.yangutils.datamodel.YangOutput;
-import org.onosproject.yangutils.datamodel.YangRpc;
-import org.onosproject.yangutils.datamodel.utils.Parsable;
-import org.onosproject.yangutils.datamodel.utils.YangConstructType;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-import org.onosproject.yangutils.parser.impl.TreeWalkListener;
-
-import static org.onosproject.yangutils.datamodel.utils.YangConstructType.getYangConstructType;
-import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
-
-/**
- * Represents a utility to carry out listener validation.
- */
-public final class ListenerValidation {
-
- /**
- * Creates a new listener validation.
- */
- private ListenerValidation() {
- }
-
- /**
- * Checks parsed data stack is not empty.
- *
- * @param listener Listener's object
- * @param errorType error type needs to be set in error message
- * @param yangConstructType type of parsable data 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,
- YangConstructType yangConstructType, 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.
- */
- String message = constructListenerErrorMessage(errorType, yangConstructType, parsableDataTypeName,
- errorLocation);
- throw new ParserException(message);
- }
- }
-
- /**
- * Checks parsed data stack is empty.
- *
- * @param listener Listener's object
- * @param errorType error type needs to be set in error message
- * @param yangConstructType type of parsable data 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,
- YangConstructType yangConstructType, 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.
- */
- String message = constructListenerErrorMessage(errorType, yangConstructType, parsableDataTypeName,
- errorLocation);
- throw new ParserException(message);
- }
- }
-
- /**
- * Returns parent node config value, if top node does not specify a config
- * statement then default value true is returned.
- *
- * @param listener listener's object
- * @return true/false parent's config value
- */
- public static boolean getParentNodeConfig(TreeWalkListener listener) {
- Parsable curData = listener.getParsedDataStack().peek();
- YangNode parentNode = ((YangNode) curData).getParent();
- if (curData instanceof YangConfig) {
- return ((YangConfig) curData).isConfig();
- } else if (curData instanceof YangRpc || curData instanceof YangOutput
- || curData instanceof YangInput || curData instanceof YangNotification) {
- return false;
- } else if (curData instanceof YangCase && parentNode instanceof YangChoice) {
- return ((YangChoice) parentNode).isConfig();
- } else {
- return true;
- }
- }
-
- /**
- * Checks if a rule occurrences is as per the expected YANG grammar's
- * cardinality.
- *
- * @param childContext child's context
- * @param yangChildConstruct child construct for whom cardinality is to be
- * validated
- * @param yangParentConstruct parent construct
- * @param parentName parent name
- * @throws ParserException exception if cardinality check fails
- */
- public static void validateCardinalityMaxOne(List<?> childContext, YangConstructType yangChildConstruct,
- YangConstructType yangParentConstruct, String parentName)
- throws ParserException {
-
- if (!childContext.isEmpty() && childContext.size() != 1) {
- ParserException parserException = new ParserException("YANG file error: \""
- + getYangConstructType(yangChildConstruct) + "\" is defined more than once in \""
- + getYangConstructType(yangParentConstruct) + " " + parentName + "\".");
-
- Iterator<?> context = childContext.iterator();
- parserException.setLine(((ParserRuleContext) context.next()).getStart().getLine());
- parserException.setCharPosition(((ParserRuleContext) context.next()).getStart().getCharPositionInLine());
- throw parserException;
- }
- }
-
- /**
- * Checks if a rule occurrences is exactly 1.
- *
- * @param childContext child's context
- * @param yangChildConstruct child construct for whom cardinality is to be
- * validated
- * @param yangParentConstruct parent construct
- * @param parentName parent name
- * @param parentContext parents's context
- * @throws ParserException exception if cardinality check fails
- */
- public static void validateCardinalityEqualsOne(List<?> childContext, YangConstructType yangChildConstruct,
- YangConstructType yangParentConstruct, String parentName,
- ParserRuleContext parentContext)
- throws ParserException {
-
- if (childContext.isEmpty()) {
- ParserException parserException = new ParserException("YANG file error: Missing \""
- + getYangConstructType(yangChildConstruct) + "\" in \"" + getYangConstructType(yangParentConstruct)
- + " " + parentName + "\".");
- parserException.setLine(parentContext.getStart().getLine());
- parserException.setCharPosition(parentContext.getStart().getCharPositionInLine());
- throw parserException;
- } else if (!childContext.isEmpty() && childContext.size() != 1) {
- Iterator<?> childcontext = childContext.iterator();
- ParserException parserException = new ParserException("YANG file error: \""
- + getYangConstructType(yangChildConstruct) + "\" is present more than once in \""
- + getYangConstructType(yangParentConstruct) + " " + parentName + "\".");
- parserException.setLine(((ParserRuleContext) childcontext.next()).getStart().getLine());
- parserException.setCharPosition(((ParserRuleContext) childcontext.next()).getStart()
- .getCharPositionInLine());
- throw parserException;
- }
- }
-
- /**
- * Checks if a rule occurrences is minimum 1.
- *
- * @param childContext child's context
- * @param yangChildConstruct child construct for whom cardinality is to be
- * validated
- * @param yangParentConstruct parent construct
- * @param parentName parent name
- * @param parentContext parents's context
- * @throws ParserException exception if cardinality check fails
- */
- public static void validateCardinalityNonZero(List<?> childContext, YangConstructType yangChildConstruct,
- YangConstructType yangParentConstruct, String parentName,
- ParserRuleContext parentContext)
- throws ParserException {
-
- if (childContext.isEmpty()) {
- ParserException parserException = new ParserException("YANG file error: Missing \""
- + getYangConstructType(yangChildConstruct) + "\" in \"" + getYangConstructType(yangParentConstruct)
- + " " + parentName + "\".");
-
- parserException.setLine(parentContext.getStart().getLine());
- parserException.setCharPosition(parentContext.getStart().getCharPositionInLine());
- throw parserException;
- }
- }
-
- /**
- * Checks if a either of one construct occurrence.
- *
- * @param child1Context first optional child's context
- * @param yangChild1Construct first child construct for whom cardinality is
- * to be validated
- * @param child2Context second optional child's context
- * @param yangChild2Construct second child construct for whom cardinality is
- * to be validated
- * @param yangParentConstruct parent construct
- * @param parentName parent name
- * @param parentContext parents's context
- * @throws ParserException exception if cardinality check fails
- */
- public static void validateCardinalityEitherOne(List<?> child1Context, YangConstructType yangChild1Construct,
- List<?> child2Context, YangConstructType yangChild2Construct,
- YangConstructType yangParentConstruct, String parentName,
- ParserRuleContext parentContext)
- throws ParserException {
-
- if (child1Context.isEmpty() && child2Context.isEmpty()) {
- ParserException parserException = new ParserException("YANG file error: Either \""
- + getYangConstructType(yangChild1Construct) + "\" or \"" + getYangConstructType(yangChild2Construct)
- + "\" should be present in \"" + getYangConstructType(yangParentConstruct) + " "
- + parentName + "\".");
- parserException.setLine(parentContext.getStart().getLine());
- parserException.setCharPosition(parentContext.getStart().getCharPositionInLine());
- throw parserException;
- }
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ParseTreeErrorListener.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ParseTreeErrorListener.java
deleted file mode 100644
index af81d6f..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ParseTreeErrorListener.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.parser.impl.parserutils;
-
-import org.antlr.v4.runtime.BaseErrorListener;
-import org.antlr.v4.runtime.RecognitionException;
-import org.antlr.v4.runtime.Recognizer;
-import org.onosproject.yangutils.parser.exceptions.ParserException;
-
-/**
- * Represent the parse tree error listener.
- * By default, ANTLR sends all errors to standard error, this is changed by
- * providing this new implementation of interface ANTLRErrorListener. The
- * interface has a syntaxError() method that applies to both lexer and parser.
- */
-public class ParseTreeErrorListener extends BaseErrorListener {
-
- @Override
- public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine,
- String msg, RecognitionException e) {
-
- ParserException parserException = new ParserException(msg);
- parserException.setLine(line);
- parserException.setCharPosition(charPositionInLine);
- throw parserException;
- }
-}
\ No newline at end of file
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/package-info.java b/plugin/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/package-info.java
deleted file mode 100644
index 9eafb00..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/package-info.java
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * Provide common utils for parser implementation.
- */
-package org.onosproject.yangutils.parser.impl.parserutils;
\ No newline at end of file
diff --git a/plugin/src/main/java/org/onosproject/yangutils/parser/package-info.java b/plugin/src/main/java/org/onosproject/yangutils/parser/package-info.java
deleted file mode 100644
index f039e68..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/parser/package-info.java
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-/**
- * Interfaces to process YANG information from ANTLR generated listeners.
- */
-package org.onosproject.yangutils.parser;
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/exception/InvalidNodeForTranslatorException.java b/plugin/src/main/java/org/onosproject/yangutils/translator/exception/InvalidNodeForTranslatorException.java
deleted file mode 100644
index 935f6b6..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/exception/InvalidNodeForTranslatorException.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.translator.exception;
-
-/**
- * Represents custom translator exception for translator's operations.
- */
-public class InvalidNodeForTranslatorException extends RuntimeException {
-
- private static final long serialVersionUID = 20160311L;
- private transient String fileName;
- private transient int lineNumber;
- private transient int charPosition;
-
- /**
- * Creates a new exception.
- */
- public InvalidNodeForTranslatorException() {
- super();
- }
-
- /**
- * Creates a new exception with given message.
- *
- * @param message the detail of exception in string
- */
- public InvalidNodeForTranslatorException(String message) {
- super(message);
- }
-
- /**
- * Creates a new exception from given message and cause.
- *
- * @param message the detail of exception in string
- * @param cause underlying cause of the error
- */
- public InvalidNodeForTranslatorException(final String message, final Throwable cause) {
- super(message, cause);
- }
-
- /**
- * Creates a new exception from cause.
- *
- * @param cause underlying cause of the error
- */
- public InvalidNodeForTranslatorException(final Throwable cause) {
- super(cause);
- }
-
- /**
- * Returns generated file name for the exception.
- *
- * @return generated file name for the exception
- */
- public String getFileName() {
- return this.fileName;
- }
-
- /**
- * Returns line number of the exception.
- *
- * @return line number of the exception
- */
- public int getLineNumber() {
- return this.lineNumber;
- }
-
- /**
- * Returns position of the exception.
- *
- * @return position of the exception
- */
- public int getCharPositionInLine() {
- return this.charPosition;
- }
-
- /**
- * Sets line number of YANG file.
- *
- * @param line line number of YANG file
- */
- public void setLine(int line) {
- this.lineNumber = line;
- }
-
- /**
- * Sets position of exception.
- *
- * @param charPosition position of exception
- */
- public void setCharPosition(int charPosition) {
- this.charPosition = charPosition;
- }
-
- /**
- * Sets file name in exception.
- *
- * @param fileName YANG file name
- */
- public void setFileName(String fileName) {
- this.fileName = fileName;
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/exception/TranslatorException.java b/plugin/src/main/java/org/onosproject/yangutils/translator/exception/TranslatorException.java
deleted file mode 100644
index 0f68e97..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/exception/TranslatorException.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.translator.exception;
-
-/**
- * Represents custom translator exception for translator's operations.
- */
-public class TranslatorException extends RuntimeException {
-
- private static final long serialVersionUID = 20160311L;
- private transient String fileName;
- private transient int lineNumber;
- private transient int charPosition;
-
- /**
- * Create a new translator exception.
- */
- public TranslatorException() {
- super();
- }
-
- /**
- * Creates a new translator exception with given message.
- *
- * @param message the detail of exception in string
- */
- public TranslatorException(String message) {
- super(message);
- }
-
- /**
- * Creates a new translator exception from given message and cause.
- *
- * @param message the detail of exception in string
- * @param cause underlying cause of the error
- */
- public TranslatorException(final String message, final Throwable cause) {
- super(message, cause);
- }
-
- /**
- * Creates a new translator exception from cause.
- *
- * @param cause underlying cause of the error
- */
- public TranslatorException(final Throwable cause) {
- super(cause);
- }
-
- /**
- * Returns line number of the exception.
- *
- * @return line number of the exception
- */
- public int getLineNumber() {
- return this.lineNumber;
- }
-
- /**
- * Returns YANG file name of the exception.
- *
- * @return YANG file name of the exception
- */
- public String getFileName() {
- return this.fileName;
- }
-
- /**
- * Returns position of the exception.
- *
- * @return position of the exception
- */
- public int getCharPositionInLine() {
- return this.charPosition;
- }
-
- /**
- * Sets line number of YANG file.
- *
- * @param line line number of YANG file
- */
- public void setLine(int line) {
- this.lineNumber = line;
- }
-
- /**
- * Sets position of exception.
- *
- * @param charPosition position of exception
- */
- public void setCharPosition(int charPosition) {
- this.charPosition = charPosition;
- }
-
- /**
- * Sets file name in translator exception.
- *
- * @param fileName YANG file name
- */
- public void setFileName(String fileName) {
- this.fileName = fileName;
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/exception/package-info.java b/plugin/src/main/java/org/onosproject/yangutils/translator/exception/package-info.java
deleted file mode 100644
index b88a8a3..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/exception/package-info.java
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * Custom exception for translator.
- */
-package org.onosproject.yangutils.translator.exception;
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/package-info.java b/plugin/src/main/java/org/onosproject/yangutils/translator/package-info.java
deleted file mode 100644
index 72ba2e4..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/package-info.java
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * Translator to generate class definition corresponding to YANG definition.
- */
-package org.onosproject.yangutils.translator;
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/GeneratedJavaFileType.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/GeneratedJavaFileType.java
deleted file mode 100644
index d05320a..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/GeneratedJavaFileType.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.translator.tojava;
-
-/**
- * Represents type of java files generated.
- */
-public final class GeneratedJavaFileType {
-
- /**
- * Interface file.
- */
- public static final int INTERFACE_MASK = 1;
-
- /**
- * Builder interface file.
- */
- public static final int BUILDER_INTERFACE_MASK = 2;
-
- /**
- * Builder class file.
- */
- public static final int BUILDER_CLASS_MASK = 4;
-
- /**
- * Impl class file.
- */
- public static final int DEFAULT_CLASS_MASK = 8;
-
- /**
- * Interface and class file.
- */
- public static final int GENERATE_INTERFACE_WITH_BUILDER = 8207;
-
- /**
- * Java interface corresponding to rpc.
- */
- public static final int GENERATE_SERVICE_AND_MANAGER = 16;
-
- /**
- * Java class corresponding to YANG enumeration.
- */
- public static final int GENERATE_ENUM_CLASS = 32;
-
- /**
- * Java class corresponding to typedef.
- */
- public static final int GENERATE_TYPEDEF_CLASS = 64;
-
- /**
- * Java class corresponding to union.
- */
- public static final int GENERATE_UNION_CLASS = 128;
-
- /**
- * Java class corresponding to typedef.
- */
- static final int GENERATE_TYPE_CLASS = GENERATE_TYPEDEF_CLASS
- | GENERATE_UNION_CLASS;
-
- /**
- * Event class.
- */
- public static final int GENERATE_EVENT_CLASS = 256;
-
- /**
- * Event listener class.
- */
- public static final int GENERATE_EVENT_LISTENER_INTERFACE = 512;
-
- /**
- * Event listener class.
- */
- public static final int GENERATE_EVENT_SUBJECT_CLASS = 1024;
-
- /**
- * Java classes for events.
- */
- public static final int GENERATE_ALL_EVENT_CLASS_MASK = GENERATE_EVENT_CLASS | GENERATE_EVENT_LISTENER_INTERFACE
- | GENERATE_EVENT_SUBJECT_CLASS;
-
- /**
- * Identity listener class.
- */
- public static final int GENERATE_IDENTITY_CLASS = 2048;
-
- /**
- * Creates an instance of generate java file type.
- */
- private GeneratedJavaFileType() {
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/GeneratedTempFileType.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/GeneratedTempFileType.java
deleted file mode 100644
index 6f61e10..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/GeneratedTempFileType.java
+++ /dev/null
@@ -1,162 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.translator.tojava;
-
-/**
- * Represents type of temporary files generated.
- */
-public final class GeneratedTempFileType {
-
- /**
- * Attributes definition temporary file.
- */
- public static final int ATTRIBUTES_MASK = 1; // 1 << 0
-
- /**
- * Getter methods for interface.
- */
- public static final int GETTER_FOR_INTERFACE_MASK = 1 << 1;
-
- /**
- * Getter methods for class.
- */
- public static final int GETTER_FOR_CLASS_MASK = 1 << 2;
-
- /**
- * Setter methods for interface.
- */
- public static final int SETTER_FOR_INTERFACE_MASK = 1 << 3;
-
- /**
- * Setter methods for class.
- */
- public static final int SETTER_FOR_CLASS_MASK = 1 << 4;
-
- /**
- * Constructor method of class.
- */
- public static final int CONSTRUCTOR_IMPL_MASK = 1 << 5;
-
- /**
- * Hash code implementation of class.
- */
- public static final int HASH_CODE_IMPL_MASK = 1 << 6;
-
- /**
- * Equals implementation of class.
- */
- public static final int EQUALS_IMPL_MASK = 1 << 7;
-
- /**
- * To string implementation of class.
- */
- public static final int TO_STRING_IMPL_MASK = 1 << 8;
-
- /**
- * Of string implementation of class.
- */
- public static final int OF_STRING_IMPL_MASK = 1 << 9;
-
- /**
- * Constructor for type class like typedef, union.
- */
- public static final int CONSTRUCTOR_FOR_TYPE_MASK = 1 << 10;
-
- /**
- * From string implementation of class.
- */
- public static final int FROM_STRING_IMPL_MASK = 1 << 11;
-
- /**
- * Enum implementation of class.
- */
- public static final int ENUM_IMPL_MASK = 1 << 12;
-
- /**
- * Rpc interface of module / sub module.
- */
- public static final int RPC_INTERFACE_MASK = 1 << 13;
-
- /**
- * Rpc implementation of module / sub module.
- */
- public static final int RPC_IMPL_MASK = 1 << 14;
-
- /**
- * Event enum implementation of class.
- */
- public static final int EVENT_ENUM_MASK = 1 << 15;
-
- /**
- * Event method implementation of class.
- */
- public static final int EVENT_METHOD_MASK = 1 << 16;
-
- /**
- * Event subject attribute implementation of class.
- */
- public static final int EVENT_SUBJECT_ATTRIBUTE_MASK = 1 << 17;
-
- /**
- * Event subject getter implementation of class.
- */
- public static final int EVENT_SUBJECT_GETTER_MASK = 1 << 18;
-
- /**
- * Event subject setter implementation of class.
- */
- public static final int EVENT_SUBJECT_SETTER_MASK = 1 << 19;
-
- /**
- * Add to list method interface for class.
- */
- public static final int ADD_TO_LIST_INTERFACE_MASK = 1 << 20;
-
- /**
- * Add to list method implementation for class.
- */
- public static final int ADD_TO_LIST_IMPL_MASK = 1 << 21;
-
- /**
- * Leaf identifier enum attributes for class.
- */
- public static final int LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK = 1 << 22;
-
- /**
- * Is filter content match for leaves class.
- */
- public static final int FILTER_CONTENT_MATCH_FOR_LEAF_MASK = 1 << 23;
-
- /**
- * Is filter content match for leaf lists class.
- */
- public static final int FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK = 1 << 24;
-
- /**
- * Is filter content match for nodes class.
- */
- public static final int FILTER_CONTENT_MATCH_FOR_NODES_MASK = 1 << 25;
-
- /**
- * Edit config class content for class.
- */
- public static final int EDIT_CONTENT_MASK = 1 << 26;
-
- // No instantiation.
- private GeneratedTempFileType() {
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaAttributeInfo.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaAttributeInfo.java
deleted file mode 100644
index a5a644a..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaAttributeInfo.java
+++ /dev/null
@@ -1,321 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.translator.tojava;
-
-import org.onosproject.yangutils.datamodel.YangCompilerAnnotation;
-import org.onosproject.yangutils.datamodel.YangType;
-import org.onosproject.yangutils.datamodel.javadatamodel.JavaQualifiedTypeInfo;
-import org.onosproject.yangutils.translator.exception.TranslatorException;
-
-import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.isTypeLeafref;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.isTypeNameLeafref;
-
-/**
- * Represents the attribute info corresponding to class/interface generated.
- */
-public final class JavaAttributeInfo {
-
- /**
- * The data type info of attribute.
- */
- private YangType<?> attrType;
-
- /**
- * Name of the attribute.
- */
- private String name;
-
- /**
- * If the added attribute is a list of info.
- */
- private boolean isListAttr;
-
- /**
- * If the added attribute has to be accessed in a fully qualified manner.
- */
- private boolean isQualifiedName;
-
- /**
- * The class info will be used to set the attribute type and package info
- * will be use for qualified name.
- */
- private JavaQualifiedTypeInfoTranslator importInfo;
-
- /**
- * Compiler annotation attribute info.
- */
- private YangCompilerAnnotation compilerAnnotation;
-
- /**
- * If conflict occurs.
- */
- private boolean isIntConflict;
-
- /**
- * If conflict occurs.
- */
- private boolean isLongConflict;
-
- /**
- * If conflict occurs.
- */
- private boolean isShortConflict;
-
- /**
- * Creates a java attribute info object.
- */
- private JavaAttributeInfo() {
- }
-
- /**
- * Creates object of java attribute info.
- *
- * @param attrType YANG type
- * @param name attribute name
- * @param isListAttr is list attribute
- * @param isQualifiedName is qualified name
- */
- public JavaAttributeInfo(YangType<?> attrType, String name, boolean isListAttr, boolean isQualifiedName) {
- this.attrType = attrType;
- this.name = name;
- this.isListAttr = isListAttr;
- this.isQualifiedName = isQualifiedName;
- }
-
- /**
- * Returns the data type info of attribute.
- *
- * @return the data type info of attribute
- */
- public YangType<?> getAttributeType() {
- return attrType;
- }
-
- /**
- * Sets the data type info of attribute.
- *
- * @param type the data type info of attribute
- */
- public void setAttributeType(YangType<?> type) {
- attrType = type;
- }
-
- /**
- * Returns name of the attribute.
- *
- * @return name of the attribute
- */
- public String getAttributeName() {
-
- if (name == null) {
- throw new TranslatorException("Expected java attribute name is null");
- }
- return name;
- }
-
- /**
- * Sets name of the attribute.
- *
- * @param attrName name of the attribute
- */
- public void setAttributeName(String attrName) {
- name = attrName;
- }
-
- /**
- * Returns if the added attribute is a list of info.
- *
- * @return the if the added attribute is a list of info
- */
- public boolean isListAttr() {
- return isListAttr;
- }
-
- /**
- * Sets if the added attribute is a list of info.
- *
- * @param isList if the added attribute is a list of info
- */
- private void setListAttr(boolean isList) {
- isListAttr = isList;
- }
-
- /**
- * Returns if the added attribute has to be accessed in a fully qualified
- * manner.
- *
- * @return the if the added attribute has to be accessed in a fully
- * qualified manner.
- */
- public boolean isQualifiedName() {
- return isQualifiedName;
- }
-
- /**
- * Sets if the added attribute has to be accessed in a fully qualified
- * manner.
- *
- * @param isQualified if the added attribute has to be accessed in a fully
- * qualified manner
- */
- private void setIsQualifiedAccess(boolean isQualified) {
- isQualifiedName = isQualified;
- }
-
- /**
- * Returns the import info for the attribute type. It will be null, if the type
- * is basic built-in java type.
- *
- * @return import info
- */
- public JavaQualifiedTypeInfoTranslator getImportInfo() {
- return importInfo;
- }
-
- /**
- * Sets the import info for the attribute type.
- *
- * @param importInfo import info for the attribute type
- */
- public void setImportInfo(JavaQualifiedTypeInfoTranslator importInfo) {
- this.importInfo = importInfo;
- }
-
- /**
- * Returns the compiler annotation.
- *
- * @return compiler annotation info
- */
- public YangCompilerAnnotation getCompilerAnnotation() {
- return compilerAnnotation;
- }
-
- /**
- * Sets the compiler annotation.
- *
- * @param compilerAnnotation the compiler annotation to set
- */
- public void setCompilerAnnotation(YangCompilerAnnotation compilerAnnotation) {
- this.compilerAnnotation = compilerAnnotation;
- }
-
- /**
- * Returns true if conflict between int and uint.
- *
- * @return true if conflict between int and uInt
- */
- public boolean isIntConflict() {
- return isIntConflict;
- }
-
- /**
- * Sets true if conflict between int and uInt.
- *
- * @param intConflict true if conflict between int and uInt
- */
- void setIntConflict(boolean intConflict) {
- isIntConflict = intConflict;
- }
-
- /**
- * Returns true if conflict between long and uLong.
- *
- * @return true if conflict between long and uLong
- */
- public boolean isLongConflict() {
- return isLongConflict;
- }
-
- /**
- * Sets true if conflict between long and uLong.
- *
- * @param longConflict true if conflict between long and uLong
- */
- void setLongConflict(boolean longConflict) {
- isLongConflict = longConflict;
- }
-
- /**
- * Returns true if conflict between short and uint8.
- *
- * @return true if conflict between short and uint8
- */
- public boolean isShortConflict() {
- return isShortConflict;
- }
-
- /**
- * Sets true if conflict between short and uint8.
- *
- * @param shortConflict true if conflict between short and uint8
- */
- public void setShortConflict(boolean shortConflict) {
- isShortConflict = shortConflict;
- }
-
- /**
- * Returns java attribute info.
- *
- * @param importInfo java qualified type info
- * @param attributeName attribute name
- * @param attributeType attribute type
- * @param isQualifiedAccess is the attribute a qualified access
- * @param isListAttribute is list attribute
- * @return java attribute info.
- */
- public static JavaAttributeInfo getAttributeInfoForTheData(JavaQualifiedTypeInfo importInfo,
- String attributeName,
- YangType<?> attributeType, boolean isQualifiedAccess,
- boolean isListAttribute) {
-
- if (attributeType != null) {
- attributeType = isTypeLeafref(attributeType);
- }
- attributeName = isTypeNameLeafref(attributeName, attributeType);
- JavaAttributeInfo newAttr = new JavaAttributeInfo();
- newAttr.setImportInfo((JavaQualifiedTypeInfoTranslator) importInfo);
- newAttr.setAttributeName(attributeName);
- newAttr.setAttributeType(attributeType);
- newAttr.setIsQualifiedAccess(isQualifiedAccess);
- newAttr.setListAttr(isListAttribute);
-
- return newAttr;
- }
-
- /**
- * Returns java attribute info.
- *
- * @param importInfo java qualified type info
- * @param attributeName attribute name
- * @param attributeType attribute type
- * @param isQualifiedAccess is the attribute a qualified access
- * @param isListAttribute is list attribute
- * @param compilerAnnotation compiler annotation
- * @return java attribute info.
- */
- public static JavaAttributeInfo getAttributeInfoForTheData(JavaQualifiedTypeInfoTranslator importInfo,
- String attributeName, YangType<?> attributeType,
- boolean isQualifiedAccess, boolean isListAttribute,
- YangCompilerAnnotation compilerAnnotation) {
- JavaAttributeInfo newAttr = getAttributeInfoForTheData(importInfo, attributeName, attributeType,
- isQualifiedAccess, isListAttribute);
-
- newAttr.setCompilerAnnotation(compilerAnnotation);
-
- return newAttr;
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaCodeGenerator.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaCodeGenerator.java
deleted file mode 100644
index 49beff0..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaCodeGenerator.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.translator.tojava;
-
-import org.onosproject.yangutils.translator.exception.TranslatorException;
-import org.onosproject.yangutils.utils.io.YangPluginConfig;
-
-import java.io.IOException;
-
-/**
- * Abstraction of an entity which provides Code generator functionalities.
- */
-public interface JavaCodeGenerator {
-
- /**
- * Traverse the schema of application and generate corresponding code.
- *
- * @param yangPlugin YANG plugin config
- * @throws TranslatorException when fails to translate the data model tree
- */
- void generateCodeEntry(YangPluginConfig yangPlugin)
- throws TranslatorException;
-
- /**
- * Traverse the schema of application and generate corresponding code.
- *
- * @throws TranslatorException when fails to generate java code
- * @throws IOException a violation in IO rule
- */
- void generateCodeExit()
- throws TranslatorException, IOException;
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaCodeGeneratorInfo.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaCodeGeneratorInfo.java
deleted file mode 100644
index 4ddde17..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaCodeGeneratorInfo.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.translator.tojava;
-
-import org.onosproject.yangutils.datamodel.LocationInfo;
-
-/**
- * Represents YANG java info containing interface for java code generator, java
- * file information, java import data and temp java code fragment files. This
- * interface serves as a generic interface and help to unify the generate code
- * entry function.
- */
-public interface JavaCodeGeneratorInfo
- extends JavaFileInfoContainer, TempJavaCodeFragmentFilesContainer, LocationInfo {
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaCodeGeneratorUtil.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaCodeGeneratorUtil.java
deleted file mode 100644
index 724c9cf..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaCodeGeneratorUtil.java
+++ /dev/null
@@ -1,360 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.translator.tojava;
-
-import java.io.IOException;
-
-import org.onosproject.yangutils.datamodel.TraversalType;
-import org.onosproject.yangutils.datamodel.YangInput;
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.YangNodeType;
-import org.onosproject.yangutils.datamodel.YangOutput;
-import org.onosproject.yangutils.translator.exception.InvalidNodeForTranslatorException;
-import org.onosproject.yangutils.translator.exception.TranslatorException;
-import org.onosproject.yangutils.utils.io.YangPluginConfig;
-
-import static org.onosproject.yangutils.datamodel.TraversalType.CHILD;
-import static org.onosproject.yangutils.datamodel.TraversalType.PARENT;
-import static org.onosproject.yangutils.datamodel.TraversalType.ROOT;
-import static org.onosproject.yangutils.datamodel.TraversalType.SIBILING;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.searchAndDeleteTempDir;
-
-/**
- * Representation of java code generator based on application schema.
- */
-public final class JavaCodeGeneratorUtil {
-
- /**
- * Current YANG node.
- */
- private static YangNode curNode;
-
- /**
- * Root node.
- */
- private static YangNode rootNode;
-
- /**
- * Creates a java code generator utility object.
- */
- private JavaCodeGeneratorUtil() {
- }
-
- /**
- * Returns current YANG node.
- *
- * @return current YANG node
- */
- public static YangNode getCurNode() {
- return curNode;
- }
-
- /**
- * Sets current YANG node.
- *
- * @param node current YANG node
- */
- public static void setCurNode(YangNode node) {
- curNode = node;
- }
-
- /**
- * Generates Java code files corresponding to the YANG schema.
- *
- * @param rootNode root node of the data model tree
- * @param yangPlugin YANG plugin config
- * @throws TranslatorException when fails to generate java code file the current node
- * @throws IOException when fails to do IO operations
- */
- public static void generateJavaCode(YangNode rootNode, YangPluginConfig yangPlugin)
- throws TranslatorException, IOException {
-
- YangNode codeGenNode = rootNode;
- setRootNode(rootNode);
- TraversalType curTraversal = ROOT;
-
- while (codeGenNode != null) {
- if (curTraversal != PARENT) {
- if (!(codeGenNode instanceof JavaCodeGenerator)) {
- throw new TranslatorException("Unsupported node to generate code " +
- codeGenNode.getName() + " in " + codeGenNode.getLineNumber() + " at "
- + codeGenNode.getCharPosition() + " in " + codeGenNode.getFileName());
- }
- setCurNode(codeGenNode);
- try {
- generateCodeEntry(codeGenNode, yangPlugin);
- codeGenNode.setNameSpaceAndAddToParentSchemaMap();
- } catch (InvalidNodeForTranslatorException e) {
- if (codeGenNode.getNextSibling() != null) {
- curTraversal = SIBILING;
- codeGenNode = codeGenNode.getNextSibling();
- } else {
- curTraversal = PARENT;
- codeGenNode = codeGenNode.getParent();
- }
- continue;
- } catch (Exception e) {
- e.printStackTrace();
- close(codeGenNode, yangPlugin);
- throw new TranslatorException(e.getMessage());
- }
-
- }
- if (curTraversal != PARENT && codeGenNode.getChild() != null) {
- curTraversal = CHILD;
- codeGenNode = codeGenNode.getChild();
- } else if (codeGenNode.getNextSibling() != null) {
- try {
- generateCodeExit(codeGenNode, yangPlugin);
- } catch (Exception e) {
- e.printStackTrace();
- close(codeGenNode, yangPlugin);
- throw new TranslatorException(e.getMessage());
- }
- curTraversal = SIBILING;
- codeGenNode = codeGenNode.getNextSibling();
- } else {
- try {
- generateCodeExit(codeGenNode, yangPlugin);
- } catch (Exception e) {
- e.printStackTrace();
- close(codeGenNode, yangPlugin);
- throw new TranslatorException(e.getMessage());
- }
- curTraversal = PARENT;
- codeGenNode = codeGenNode.getParent();
- }
- }
- }
-
- /**
- * Generates the current nodes code snippet.
- *
- * @param codeGenNode current data model node for which the code needs to be generated
- * @param yangPlugin YANG plugin config
- * @throws TranslatorException when fails to generate java code file the current node
- * @throws IOException when fails to do IO operations
- */
- private static void generateCodeEntry(YangNode codeGenNode, YangPluginConfig yangPlugin)
- throws TranslatorException, IOException {
-
- if (codeGenNode instanceof JavaCodeGenerator) {
- ((JavaCodeGenerator) codeGenNode).generateCodeEntry(yangPlugin);
- } else {
- close(codeGenNode, yangPlugin);
- throw new TranslatorException(
- "Generated data model node cannot be translated to target language code for " +
- codeGenNode.getName() + " in " + codeGenNode.getLineNumber()
- + " at " + codeGenNode.getCharPosition() + " in " + codeGenNode.getFileName());
- }
- }
-
- /**
- * Generates the current nodes code target code from the snippet.
- *
- * @param codeGenNode current data model node for which the code needs to be generated
- * @param pluginConfig plugin configurations
- * @throws TranslatorException when fails to generate java code file the current node
- * @throws IOException when fails to do IO operations
- */
- private static void generateCodeExit(YangNode codeGenNode, YangPluginConfig pluginConfig)
- throws TranslatorException, IOException {
-
- if (codeGenNode instanceof JavaCodeGenerator) {
- ((JavaCodeGenerator) codeGenNode).generateCodeExit();
- } else {
- close(codeGenNode, pluginConfig);
- throw new TranslatorException(
- "Generated data model node cannot be translated to target language code for " +
- codeGenNode.getName() + " in " + codeGenNode.getLineNumber()
- + " at " + codeGenNode.getCharPosition() + " in " + codeGenNode.getFileName());
- }
- }
-
- /**
- * Free other YANG nodes of data-model tree when error occurs while file generation of current node.
- */
- private static void freeRestResources() {
-
- YangNode freedNode = getCurNode();
- if (getCurNode() != null) {
- YangNode tempNode = freedNode;
- TraversalType curTraversal = ROOT;
-
- while (freedNode != tempNode.getParent()) {
-
- if (curTraversal != PARENT && freedNode.getChild() != null) {
- curTraversal = CHILD;
- freedNode = freedNode.getChild();
- } else if (freedNode.getNextSibling() != null) {
- curTraversal = SIBILING;
- if (freedNode != tempNode) {
- free(freedNode);
- }
- freedNode = freedNode.getNextSibling();
- } else {
- curTraversal = PARENT;
- if (freedNode != tempNode) {
- free(freedNode);
- }
- freedNode = freedNode.getParent();
- }
- }
- }
- }
-
- /**
- * Free the current node.
- *
- * @param node YANG node
- */
- private static void free(YangNode node) {
-
- YangNode parent = node.getParent();
- parent.setChild(null);
-
- if (node.getNextSibling() != null) {
- parent.setChild(node.getNextSibling());
- } else if (node.getPreviousSibling() != null) {
- parent.setChild(node.getPreviousSibling());
- }
- node = null;
- }
-
- /**
- * Delete Java code files corresponding to the YANG schema.
- *
- * @param rootNode root node of data-model tree
- * @param yangPluginConfig plugin configurations
- * @throws IOException when fails to delete java code file the current node
- */
- public static void translatorErrorHandler(YangNode rootNode, YangPluginConfig yangPluginConfig)
- throws IOException {
-
- if (rootNode != null) {
- //Free other resources where translator has failed.
- freeRestResources();
-
- // Start removing all open files.
- YangNode tempNode = rootNode;
- setCurNode(tempNode.getChild());
- TraversalType curTraversal = ROOT;
-
- while (tempNode != null) {
-
- if (curTraversal != PARENT) {
- close(tempNode, yangPluginConfig);
- }
- if (curTraversal != PARENT && tempNode.getChild() != null) {
- curTraversal = CHILD;
- tempNode = tempNode.getChild();
- } else if (tempNode.getNextSibling() != null) {
- curTraversal = SIBILING;
- tempNode = tempNode.getNextSibling();
- } else {
- curTraversal = PARENT;
- tempNode = tempNode.getParent();
- }
- }
-
- freeRestResources();
- }
- }
-
- /**
- * Closes all the current open file handles of node and delete all generated files.
- *
- * @param node current YANG node
- * @param yangPlugin plugin configurations
- * @throws IOException when fails to do IO operations
- */
- private static void close(YangNode node, YangPluginConfig yangPlugin)
- throws IOException {
- if (node instanceof JavaCodeGenerator && ((TempJavaCodeFragmentFilesContainer) node)
- .getTempJavaCodeFragmentFiles() != null) {
- ((TempJavaCodeFragmentFilesContainer) node).getTempJavaCodeFragmentFiles().freeTemporaryResources(true);
- }
- if (getRootNode() != null) {
- JavaFileInfoTranslator javaFileInfo = ((JavaFileInfoContainer) getRootNode()).getJavaFileInfo();
- if (javaFileInfo.getPackage() != null) {
- searchAndDeleteTempDir(javaFileInfo.getBaseCodeGenPath() +
- javaFileInfo.getPackageFilePath());
- } else {
- searchAndDeleteTempDir(yangPlugin.getCodeGenDir());
- }
- }
-
- }
-
- /**
- * Returns root node.
- *
- * @return root node
- */
- private static YangNode getRootNode() {
- return rootNode;
- }
-
- /**
- * Sets root node.
- *
- * @param rootNode root node
- */
- private static void setRootNode(YangNode rootNode) {
- JavaCodeGeneratorUtil.rootNode = rootNode;
- }
-
- /**
- * Searches child node in data model tree.
- *
- * @param parentNode parent node
- * @param nodeType node type
- * @param nodeName node name
- * @return child node
- */
- public static YangNode searchYangNode(YangNode parentNode, YangNodeType nodeType, String nodeName) {
- YangNode child = parentNode.getChild();
- TraversalType curTraversal = ROOT;
- if (child == null) {
- throw new IllegalArgumentException("Given parent node does not contain any child nodes");
- }
-
- while (child != null) {
- if (curTraversal != PARENT) {
- if (child instanceof YangInput || child instanceof YangOutput) {
- if (child.getNodeType().equals(nodeType)) {
- return child;
- }
- } else if (child.getName().equals(nodeName) && child.getNodeType().equals(nodeType)) {
- return child;
- }
- }
- if (curTraversal != PARENT && child.getChild() != null) {
- curTraversal = CHILD;
- child = child.getChild();
- } else if (child.getNextSibling() != null) {
- curTraversal = SIBILING;
- child = child.getNextSibling();
- } else {
- curTraversal = PARENT;
- child = child.getParent();
- }
- }
- return null;
- }
-
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaFileInfoContainer.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaFileInfoContainer.java
deleted file mode 100644
index 7fdaf6f..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaFileInfoContainer.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.yangutils.translator.tojava;
-
-/**
- * Represents data model nodes which are required to generate java classes, need to support
- * java file info.
- */
-public interface JavaFileInfoContainer {
-
- /**
- * Returns the generated java file information.
- *
- * @return generated java file information
- */
- JavaFileInfoTranslator getJavaFileInfo();
-
- /**
- * Sets the java file info object.
- *
- * @param javaInfo java file info object
- */
- void setJavaFileInfo(JavaFileInfoTranslator javaInfo);
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaFileInfoTranslator.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaFileInfoTranslator.java
deleted file mode 100644
index 781acb6..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaFileInfoTranslator.java
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.translator.tojava;
-
-import org.onosproject.yangutils.datamodel.javadatamodel.JavaFileInfo;
-import org.onosproject.yangutils.utils.io.YangPluginConfig;
-
-/**
- * Represents cached java file handle, which supports the addition of member attributes and
- * methods.
- */
-public class JavaFileInfoTranslator extends JavaFileInfo {
-
- private static final long serialVersionUID = 806102633L;
-
- /**
- * The type(s) of java source file(s) to be generated when the cached file
- * handle is closed.
- */
- private transient int genFileTypes;
-
- /**
- * File generation directory path.
- */
- private transient String relativeFilePath;
-
- /**
- * File generation base directory path.
- */
- private transient String codeGenDirFilePath;
-
- /**
- * Plugin configuration for naming convention.
- */
- private transient YangPluginConfig pluginConfig;
-
- /**
- * Returns the types of files being generated corresponding to the YANG
- * definition.
- *
- * @return the types of files being generated corresponding to the YANG
- * definition
- */
- public int getGeneratedFileTypes() {
- return genFileTypes;
- }
-
- /**
- * Sets the types of files being generated corresponding to the YANG
- * definition.
- *
- * @param fileTypes the types of files being generated corresponding to the
- * YANG definition
- */
- public void setGeneratedFileTypes(int fileTypes) {
- genFileTypes = fileTypes;
- }
-
- /**
- * Adds the types of files being generated corresponding to the YANG
- * definition.
- *
- * @param fileTypes the types of files being generated corresponding to the
- * YANG definition
- */
- public void addGeneratedFileTypes(int fileTypes) {
- genFileTypes |= fileTypes;
- }
-
- /**
- * Sets directory package path for code generation.
- *
- * @param path directory package path for code generation
- */
- public void setPackageFilePath(String path) {
- relativeFilePath = path;
- }
-
- /**
- * Returns directory package path for code generation.
- *
- * @return directory package path for code generation
- */
- public String getPackageFilePath() {
- return relativeFilePath;
- }
-
- /**
- * Returns base directory package path for code generation.
- *
- * @return directory package path for code generation
- */
- public String getBaseCodeGenPath() {
- return codeGenDirFilePath;
- }
-
- /**
- * Sets base directory package path for code generation.
- *
- * @param path base directory path
- */
- public void setBaseCodeGenPath(String path) {
- codeGenDirFilePath = path;
- }
-
- /**
- * Returns plugin configurations.
- *
- * @return the pluginConfig
- */
- public YangPluginConfig getPluginConfig() {
- return pluginConfig;
- }
-
- /**
- * Sets plugin configurations.
- *
- * @param pluginConfig the pluginConfig to set
- */
- public void setPluginConfig(YangPluginConfig pluginConfig) {
- this.pluginConfig = pluginConfig;
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaImportData.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaImportData.java
deleted file mode 100644
index a2e78f3..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaImportData.java
+++ /dev/null
@@ -1,333 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.yangutils.translator.tojava;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.SortedSet;
-import java.util.TreeSet;
-
-import static java.util.Collections.sort;
-import static java.util.Collections.unmodifiableSortedSet;
-import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getImportString;
-import static org.onosproject.yangutils.utils.UtilConstants.ABSTRACT_EVENT;
-import static org.onosproject.yangutils.utils.UtilConstants.BIG_INTEGER;
-import static org.onosproject.yangutils.utils.UtilConstants.BITSET;
-import static org.onosproject.yangutils.utils.UtilConstants.COLLECTION_IMPORTS;
-import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.EVENT_LISTENER;
-import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_IMPORT_CLASS;
-import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_IMPORT_PKG;
-import static org.onosproject.yangutils.utils.UtilConstants.HASH_MAP;
-import static org.onosproject.yangutils.utils.UtilConstants.JAVA_LANG;
-import static org.onosproject.yangutils.utils.UtilConstants.JAVA_MATH;
-import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_OBJECTS_IMPORT_CLASS;
-import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_PKG;
-import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_REGEX_PKG;
-import static org.onosproject.yangutils.utils.UtilConstants.LIST;
-import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_SERVICE;
-import static org.onosproject.yangutils.utils.UtilConstants.MAP;
-import static org.onosproject.yangutils.utils.UtilConstants.ONOS_EVENT_PKG;
-import static org.onosproject.yangutils.utils.UtilConstants.PATTERN;
-import static org.onosproject.yangutils.utils.UtilConstants.QUEUE;
-import static org.onosproject.yangutils.utils.UtilConstants.SET;
-
-/**
- * Represents that generated Java file can contain imports.
- */
-public class JavaImportData {
-
- /**
- * Flag to denote if any list in imported.
- */
- private boolean isListToImport;
-
- /**
- * Flag to denote if any queue is imported due to compiler annotation.
- */
- private boolean isQueueToImport;
-
- /**
- * Flag to denote if any set is imported due to compiler annotation.
- */
- private boolean isSetToImport;
-
- /**
- * Sorted set of import info, to be used to maintain the set of classes to
- * be imported in the generated class.
- */
- private final SortedSet<JavaQualifiedTypeInfoTranslator> importSet;
-
- /**
- * Creates java import data object.
- */
- public JavaImportData() {
- importSet = new TreeSet<>();
- }
-
-
- /**
- * Sets the status of importing list.
- *
- * @param isList status to mention list is bing imported
- */
- void setIfListImported(boolean isList) {
- isListToImport = isList;
- }
-
-
- /**
- * Sets the status of the queue to be imported due to compiler annotations.
- *
- * @param queueToImport status of queue to import
- */
- void setQueueToImport(boolean queueToImport) {
- isQueueToImport = queueToImport;
- }
-
- /**
- * Sets the status of the set to be imported due to compiler annotations.
- *
- * @param setToImport status of set to import
- */
- void setSetToImport(boolean setToImport) {
- isSetToImport = setToImport;
- }
-
- /**
- * Returns the set containing the imported class/interface info.
- *
- * @return the set containing the imported class/interface info
- */
- public SortedSet<JavaQualifiedTypeInfoTranslator> getImportSet() {
- return unmodifiableSortedSet(importSet);
- }
-
- /**
- * Adds an imported class/interface info if it is not already part of the
- * collection.
- * <p>
- * If already part of the collection, check if the packages are same, if so
- * then return true, to denote it is already in the import collection, and
- * it can be accessed without qualified access. If the packages do not
- * match, then do not add to the import collection, and return false to
- * denote, it is not added to import collection and needs to be accessed in
- * a qualified manner.
- *
- * @param newImportInfo class/interface info being imported
- * @param className name of the call being generated
- * @param classPkg generated class package
- * @return qualified access status of the import node being added
- */
- public boolean addImportInfo(JavaQualifiedTypeInfoTranslator newImportInfo,
- String className, String classPkg) {
-
- if (newImportInfo.getClassInfo().contentEquals(className)) {
- /*
- * If the current class name is same as the attribute class name,
- * then the attribute must be accessed in a qualified manner.
- */
- return true;
- } else if (newImportInfo.getPkgInfo() == null) {
- /*
- * If the package info is null, then it is not a candidate for import
- * / qualified access
- */
- return false;
- }
-
- /*
- * If the attribute type is having the package info, it is contender
- * for import list and also need to check if it needs to be a
- * qualified access.
- */
- if (newImportInfo.getPkgInfo().contentEquals(classPkg)) {
- /*
- * Package of the referred attribute and the generated class is same,
- * so no need import
- * or qualified access.
- */
- return false;
- }
-
- for (JavaQualifiedTypeInfoTranslator curImportInfo : getImportSet()) {
- if (curImportInfo.getClassInfo()
- .contentEquals(newImportInfo.getClassInfo())) {
- return !curImportInfo.getPkgInfo()
- .contentEquals(newImportInfo.getPkgInfo());
- }
- }
-
- /*
- * Import is added, so it is a member for non qualified access
- */
- importSet.add(newImportInfo);
- return false;
- }
-
- /**
- * Returns import for class.
- *
- * @return imports for class
- */
- public List<String> getImports() {
-
- String importString;
- List<String> imports = new ArrayList<>();
-
- for (JavaQualifiedTypeInfoTranslator importInfo : getImportSet()) {
- if (!importInfo.getPkgInfo().equals(EMPTY_STRING) &&
- importInfo.getClassInfo() != null &&
- !importInfo.getPkgInfo().equals(JAVA_LANG)) {
- importString = getImportString(importInfo.getPkgInfo(), importInfo
- .getClassInfo());
- imports.add(importString);
- }
- }
- if (isListToImport) {
- imports.add(getImportForList());
- }
- if (isQueueToImport) {
- imports.add(getImportForQueue());
- }
- if (isSetToImport) {
- imports.add(getImportForSet());
- }
-
- sort(imports);
- return imports;
- }
-
- /**
- * Returns import for hash and equals method.
- *
- * @return import for hash and equals method
- */
- String getImportForHashAndEquals() {
- return getImportString(JAVA_UTIL_PKG,
- JAVA_UTIL_OBJECTS_IMPORT_CLASS);
- }
-
- /**
- * Returns import for to string method.
- *
- * @return import for to string method
- */
- public String getImportForToString() {
- return getImportString(GOOGLE_MORE_OBJECT_IMPORT_PKG,
- GOOGLE_MORE_OBJECT_IMPORT_CLASS);
- }
-
- /**
- * Returns import for to bitset method.
- *
- * @return import for to bitset method
- */
- public String getImportForToBitSet() {
- return getImportString(JAVA_UTIL_PKG, BITSET);
- }
-
- /**
- * Returns import for to bitset method.
- *
- * @return import for to bitset method
- */
- public String getImportForPattern() {
- return getImportString(JAVA_UTIL_REGEX_PKG, PATTERN);
- }
-
- /**
- * Returns import for list attribute.
- *
- * @return import for list attribute
- */
- String getImportForList() {
- return getImportString(COLLECTION_IMPORTS, LIST);
- }
-
- /**
- * Returns import for queue attribute.
- *
- * @return import for queue attribute
- */
- private String getImportForQueue() {
- return getImportString(COLLECTION_IMPORTS, QUEUE);
- }
-
- /**
- * Returns import for set attribute.
- *
- * @return import for set attribute
- */
- private String getImportForSet() {
- return getImportString(COLLECTION_IMPORTS, SET);
- }
-
- /**
- * Returns import string for ListenerService class.
- *
- * @return import string for ListenerService class
- */
- public String getListenerServiceImport() {
- return getImportString(ONOS_EVENT_PKG, LISTENER_SERVICE);
- }
-
- /**
- * Returns import string for AbstractEvent class.
- *
- * @return import string for AbstractEvent class
- */
- String getAbstractEventsImport() {
- return getImportString(ONOS_EVENT_PKG, ABSTRACT_EVENT);
- }
-
- /**
- * Returns import string for EventListener class.
- *
- * @return import string for EventListener class
- */
- String getEventListenerImport() {
- return getImportString(ONOS_EVENT_PKG, EVENT_LISTENER);
- }
-
- /**
- * Returns import string for map class.
- *
- * @return import string for map class
- */
- String getMapImport() {
- return getImportString(COLLECTION_IMPORTS, MAP);
- }
-
- /**
- * Returns import string for hash map class.
- *
- * @return import string for hash map class
- */
- String getHashMapImport() {
- return getImportString(COLLECTION_IMPORTS, HASH_MAP);
- }
-
- /**
- * Returns import for big integer.
- *
- * @return import for big integer
- */
- public String getBigIntegerImport() {
- return getImportString(JAVA_MATH, BIG_INTEGER);
- }
-
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaQualifiedTypeInfoTranslator.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaQualifiedTypeInfoTranslator.java
deleted file mode 100644
index cfe507b..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/JavaQualifiedTypeInfoTranslator.java
+++ /dev/null
@@ -1,279 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.translator.tojava;
-
-import java.io.Serializable;
-import java.util.Objects;
-
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.javadatamodel.JavaQualifiedTypeInfo;
-import org.onosproject.yangutils.translator.exception.TranslatorException;
-import org.onosproject.yangutils.translator.tojava.javamodel
- .AttributesJavaDataType;
-import org.onosproject.yangutils.translator.tojava.javamodel
- .JavaLeafInfoContainer;
-import org.onosproject.yangutils.utils.io.YangToJavaNamingConflictUtil;
-
-import com.google.common.base.MoreObjects;
-
-import static org.onosproject.yangutils.utils.UtilConstants.BASE64;
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype
- .YangDataTypes.BINARY;
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BITS;
-import static org.onosproject.yangutils.translator.tojava.javamodel
- .AttributesJavaDataType.getJavaImportClass;
-import static org.onosproject.yangutils.translator.tojava.javamodel
- .AttributesJavaDataType.getJavaImportPackage;
-import static org.onosproject.yangutils.utils.UtilConstants.COLLECTION_IMPORTS;
-
-/**
- * Represents the information about individual imports in the generated file.
- */
-public class JavaQualifiedTypeInfoTranslator
- extends JavaQualifiedTypeInfo
- implements Comparable<JavaQualifiedTypeInfoTranslator>, Serializable {
- private static final long serialVersionUID = 806201634L;
-
- /**
- * Creates a java qualified type info object.
- */
- public JavaQualifiedTypeInfoTranslator() {
- super();
- }
-
- /**
- * Returns the imported package info.
- *
- * @return the imported package info
- */
- public String getPkgInfo() {
- return pkgInfo;
- }
-
- /**
- * Sets the imported package info.
- *
- * @param pkgInfo the imported package info
- */
- public void setPkgInfo(String pkgInfo) {
- this.pkgInfo = pkgInfo;
- }
-
- /**
- * Returns the imported class/interface info.
- *
- * @return the imported class/interface info
- */
- public String getClassInfo() {
- return classInfo;
- }
-
- /**
- * Sets the imported class/interface info.
- *
- * @param classInfo the imported class/interface info
- */
- public void setClassInfo(String classInfo) {
- this.classInfo = classInfo;
- }
-
- /**
- * Updates the leaf's java information.
- *
- * @param leaf leaf whose java information is being updated
- */
- public static void updateLeavesJavaQualifiedInfo(
- JavaLeafInfoContainer leaf) {
-
- JavaQualifiedTypeInfoTranslator importInfo =
- (JavaQualifiedTypeInfoTranslator) leaf.getJavaQualifiedInfo();
-
- if (leaf.getDataType() == null) {
- throw new TranslatorException(
- "missing data type of leaf " + leaf.getName()
- + " in " + leaf.getLineNumber() + " at" +
- leaf.getCharPosition() + " in " +
- leaf.getFileName());
- }
-
- /*
- * Current leaves holder is adding a leaf info as a attribute to the
- * current class.
- */
- String className =
- getJavaImportClass(leaf.getDataType(), leaf.isLeafList(),
- leaf.getConflictResolveConfig());
- if (className != null) {
- /*
- * Corresponding to the attribute type a class needs to be imported,
- * since it can be a derived type or a usage of wrapper classes.
- */
- importInfo.setClassInfo(className);
- String classPkg = getJavaImportPackage(leaf.getDataType(),
- leaf.isLeafList(),
- leaf.getConflictResolveConfig());
- if (classPkg == null) {
- throw new TranslatorException(
- "import package cannot be null when the class is used" +
- " for "
- + leaf.getName()
- + " in " + leaf.getLineNumber() + " at" +
- leaf.getCharPosition() + " in " +
- leaf.getFileName());
- }
- importInfo.setPkgInfo(classPkg);
- } else {
- /*
- * The attribute does not need a class to be imported, for example
- * built in java types.
- */
- String dataTypeName =
- AttributesJavaDataType.getJavaDataType(leaf.getDataType());
- if (dataTypeName == null) {
- throw new TranslatorException("not supported data type for "
- + leaf.getName()
- + " in " +
- leaf.getLineNumber() +
- " at" +
- leaf.getCharPosition() +
- " in " +
- leaf.getFileName());
- }
- importInfo.setClassInfo(dataTypeName);
- }
-
- leaf.getJavaQualifiedInfo().setJavaAttributeName(leaf.getJavaName(
- leaf.getConflictResolveConfig()));
- }
-
- /**
- * Returns the import info for an attribute, which needs to be used for code
- * generation for import or for qualified access.
- *
- * @param curNode current data model node for which the java file
- * is being
- * generated
- * @param attributeName name of the attribute being added, it will used in
- * import info for child class
- * @return return the import info for this attribute
- */
- public static JavaQualifiedTypeInfoTranslator getQualifiedTypeInfoOfCurNode(
- YangNode curNode,
- String attributeName) {
-
- JavaQualifiedTypeInfoTranslator importInfo =
- new JavaQualifiedTypeInfoTranslator();
-
- if (!(curNode instanceof JavaFileInfoContainer)) {
- throw new TranslatorException(
- "missing java file information to get the package details "
- + "of attribute corresponding to child node " +
- curNode.getName() +
- " in " + curNode.getLineNumber() + " at " +
- curNode.getCharPosition() + " in " +
- curNode.getFileName());
- }
-
- importInfo.setClassInfo(attributeName);
- importInfo.setPkgInfo(((JavaFileInfoContainer) curNode)
- .getJavaFileInfo().getPackage());
-
- return importInfo;
- }
-
- /**
- * Returns the java qualified type information for the wrapper classes.
- *
- * @param referredTypesAttrInfo attribute of referred type
- * @param conflictResolver plugin configurations
- * @return return the import info for this attribute
- */
- static JavaQualifiedTypeInfoTranslator getQualifiedInfoOfFromString(
- JavaAttributeInfo referredTypesAttrInfo,
- YangToJavaNamingConflictUtil conflictResolver) {
-
- /*
- * Get the java qualified type information for the wrapper classes and
- * set it in new java attribute information.
- */
- JavaQualifiedTypeInfoTranslator qualifiedInfoOfFromString =
- new JavaQualifiedTypeInfoTranslator();
-
- if (referredTypesAttrInfo.getAttributeType().getDataType() == BINARY) {
- qualifiedInfoOfFromString.setClassInfo(BASE64);
- qualifiedInfoOfFromString.setPkgInfo(COLLECTION_IMPORTS);
- } else {
- qualifiedInfoOfFromString.setClassInfo(
- getJavaImportClass(referredTypesAttrInfo.getAttributeType(),
- true, conflictResolver));
- qualifiedInfoOfFromString.setPkgInfo(
- getJavaImportPackage(
- referredTypesAttrInfo.getAttributeType(), true,
- conflictResolver));
- }
- return qualifiedInfoOfFromString;
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(pkgInfo, classInfo);
- }
-
- @Override
- public boolean equals(Object obj) {
-
- if (this == obj) {
- return true;
- }
- if (obj instanceof JavaQualifiedTypeInfoTranslator) {
- JavaQualifiedTypeInfoTranslator other =
- (JavaQualifiedTypeInfoTranslator) obj;
- return Objects.equals(pkgInfo, other.pkgInfo) &&
- Objects.equals(classInfo, other.classInfo);
- }
- return false;
- }
-
- /**
- * Checks if the import info matches.
- *
- * @param importInfo matched import
- * @return if equal or not
- */
- public boolean exactMatch(JavaQualifiedTypeInfoTranslator importInfo) {
- return equals(importInfo)
- && Objects.equals(pkgInfo, importInfo.getPkgInfo())
- && Objects.equals(classInfo, importInfo.getClassInfo());
- }
-
- @Override
- public String toString() {
- return MoreObjects.toStringHelper(getClass())
- .add("pkgInfo", pkgInfo)
- .add("classInfo", classInfo).toString();
- }
-
- /**
- * Checks that there is no 2 objects with the same class name.
- *
- * @param other compared import info.
- */
- @Override
- public int compareTo(JavaQualifiedTypeInfoTranslator other) {
- return getClassInfo().compareTo(other.getClassInfo());
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaBeanFragmentFiles.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaBeanFragmentFiles.java
deleted file mode 100644
index 7f15bc3..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaBeanFragmentFiles.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.translator.tojava;
-
-import org.onosproject.yangutils.utils.io.YangPluginConfig;
-
-import java.io.File;
-import java.io.IOException;
-
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getConstructor;
-import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.closeFile;
-
-/**
- * Represents implementation of java bean code fragments temporary implementations.
- * Maintains the temp files required specific for bean java snippet generation.
- */
-public class TempJavaBeanFragmentFiles
- extends TempJavaFragmentFiles {
-
- /**
- * File name for constructor.
- */
- private static final String CONSTRUCTOR_FILE_NAME = "Constructor";
-
- /**
- * Temporary file handle for constructor of class.
- */
- private final File constructorImplTempFileHandle;
-
- /**
- * Creates an instance of temporary java code fragment.
- *
- * @param javaFileInfo generated java file info
- * @throws IOException when fails to create new file handle
- */
- TempJavaBeanFragmentFiles(JavaFileInfoTranslator javaFileInfo)
- throws IOException {
-
- super(javaFileInfo);
-
- /*
- * Initialize getterImpl, attributes, constructor, hash code, equals and
- * to strings when generation file type matches to impl class mask.
- */
- addGeneratedTempFile(CONSTRUCTOR_IMPL_MASK);
- constructorImplTempFileHandle = getTemporaryFileHandle(CONSTRUCTOR_FILE_NAME);
- }
-
- /**
- * Returns constructor's temporary file handle.
- *
- * @return temporary file handle
- */
- public File getConstructorImplTempFileHandle() {
- return constructorImplTempFileHandle;
- }
-
- /**
- * Adds constructor for class.
- *
- * @param attr attribute info
- * @throws IOException when fails to append to temporary file
- */
- private void addConstructor(JavaAttributeInfo attr)
- throws IOException {
- appendToFile(constructorImplTempFileHandle,
- getConstructor(attr, getGeneratedJavaFiles()));
- }
-
- /**
- * Adds the new attribute info to the target generated temporary files.
- *
- * @param newAttrInfo the attribute info that needs to be added to temporary
- * files
- * @throws IOException IO operation fail
- */
- @Override
- void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo newAttrInfo,
- YangPluginConfig pluginConfig)
- throws IOException {
- super.addJavaSnippetInfoToApplicableTempFiles(newAttrInfo, pluginConfig);
- addConstructor(newAttrInfo);
- }
-
- /**
- * Removes all temporary file handles.
- *
- * @param isErrorOccurred flag to tell translator that error has occurred
- * while code generation
- * @throws IOException when failed to delete the temporary files
- */
- @Override
- public void freeTemporaryResources(boolean isErrorOccurred)
- throws IOException {
-
- /*
- * Close constructor temporary file handle and delete the file.
- */
- closeFile(constructorImplTempFileHandle, true);
- super.freeTemporaryResources(isErrorOccurred);
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaCodeFragmentFiles.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaCodeFragmentFiles.java
deleted file mode 100644
index dee7b1d..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaCodeFragmentFiles.java
+++ /dev/null
@@ -1,283 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.translator.tojava;
-
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.YangTypeHolder;
-import org.onosproject.yangutils.translator.exception.TranslatorException;
-import org.onosproject.yangutils.utils.io.YangPluginConfig;
-
-import java.io.IOException;
-
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ALL_EVENT_CLASS_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPE_CLASS;
-import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
-
-/**
- * Represents implementation of java code fragments temporary implementations.
- * Contains fragment file object of different types of java file.
- * Uses required object(s) to generate the target java file(s).
- */
-public class TempJavaCodeFragmentFiles {
-
- /**
- * Has the temporary files required for bean generated classes.
- */
- private TempJavaBeanFragmentFiles beanTempFiles;
-
- /**
- * Has the temporary files required for bean generated classes.
- */
- private TempJavaTypeFragmentFiles typeTempFiles;
-
- /**
- * Has the temporary files required for service generated classes.
- */
- private TempJavaServiceFragmentFiles serviceTempFiles;
-
- /**
- * Has the temporary files required for enumeration generated classes.
- */
- private TempJavaEnumerationFragmentFiles enumTempFiles;
-
- /**
- * Has the temporary files required for enumeration generated classes.
- */
- private TempJavaEventFragmentFiles eventTempFiles;
-
- /**
- * Creates an instance of temporary java code fragment.
- *
- * @param javaFileInfo generated java file info
- * @throws IOException when fails to create new file handle
- */
- public TempJavaCodeFragmentFiles(JavaFileInfoTranslator javaFileInfo)
- throws IOException {
-
- int genType = javaFileInfo.getGeneratedFileTypes();
- if ((genType & GENERATE_INTERFACE_WITH_BUILDER) != 0) {
- beanTempFiles = new TempJavaBeanFragmentFiles(javaFileInfo);
- }
-
- if ((genType & GENERATE_TYPE_CLASS) != 0) {
- typeTempFiles = new TempJavaTypeFragmentFiles(javaFileInfo);
- }
-
- if ((genType & GENERATE_ENUM_CLASS) != 0) {
- enumTempFiles = new TempJavaEnumerationFragmentFiles(javaFileInfo);
- }
-
- if ((genType & GENERATE_SERVICE_AND_MANAGER) != 0) {
- serviceTempFiles = new TempJavaServiceFragmentFiles(javaFileInfo);
- }
-
- if ((genType & GENERATE_ALL_EVENT_CLASS_MASK) != 0) {
- eventTempFiles = new TempJavaEventFragmentFiles(javaFileInfo);
- }
- }
-
- /**
- * Retrieves the temp file handle for bean file generation.
- *
- * @return temp file handle for bean file generation
- */
- public TempJavaBeanFragmentFiles getBeanTempFiles() {
- return beanTempFiles;
- }
-
- /**
- * Retrieves the temp file handle for data type file generation.
- *
- * @return temp file handle for data type file generation
- */
- public TempJavaTypeFragmentFiles getTypeTempFiles() {
- return typeTempFiles;
- }
-
-
- /**
- * Retrieves the temp file handle for service file generation.
- *
- * @return temp file handle for service file generation
- */
- public TempJavaServiceFragmentFiles getServiceTempFiles() {
- return serviceTempFiles;
- }
-
- /**
- * Retrieves the temp file handle for enumeration file generation.
- *
- * @return temp file handle for enumeration file generation
- */
- public TempJavaEnumerationFragmentFiles getEnumTempFiles() {
- return enumTempFiles;
- }
-
- /**
- * Retrieves the temp file handle for event file generation.
- *
- * @return temp file handle for enumeration file generation
- */
- public TempJavaEventFragmentFiles getEventFragmentFiles() {
- return eventTempFiles;
- }
-
- /**
- * Constructs java code exit.
- *
- * @param fileType generated file type
- * @param curNode current YANG node
- * @throws IOException when fails to generate java files
- */
- public void generateJavaFile(int fileType, YangNode curNode)
- throws IOException {
-
- if ((fileType & GENERATE_INTERFACE_WITH_BUILDER) != 0) {
- beanTempFiles.generateJavaFile(fileType, curNode);
- }
-
- /*
- * Creates user defined data type class file.
- */
- if ((fileType & GENERATE_TYPE_CLASS) != 0) {
- typeTempFiles.generateJavaFile(fileType, curNode);
- }
-
- /*
- * Creates service and manager class file.
- */
- if (fileType == GENERATE_SERVICE_AND_MANAGER) {
- serviceTempFiles.generateJavaFile(GENERATE_SERVICE_AND_MANAGER, curNode);
- }
-
- /*
- * Creates event, event listener and event subject files.
- */
- if (fileType == GENERATE_ALL_EVENT_CLASS_MASK) {
- eventTempFiles.generateJavaFile(GENERATE_ALL_EVENT_CLASS_MASK, curNode);
- }
-
- /*
- * Creates enumeration class file.
- */
- if (fileType == GENERATE_ENUM_CLASS) {
- enumTempFiles.generateJavaFile(GENERATE_ENUM_CLASS, curNode);
- }
- }
-
- /**
- * Add all the type in the current data model node as part of the
- * generated temporary file.
- *
- * @param typeHolder YANG java data model node which has type info, eg union / typedef
- * @param config plugin configurations for naming convention
- * @throws IOException IO operation fail
- */
- void addTypeInfoToTempFiles(YangTypeHolder typeHolder, YangPluginConfig config)
- throws IOException {
- typeTempFiles.addTypeInfoToTempFiles(typeHolder, config);
- }
-
- /**
- * Adds build method for interface.
- *
- * @return build method for interface
- * @throws IOException when fails to append to temporary file
- */
- public String addBuildMethodForInterface()
- throws IOException {
- if (beanTempFiles != null) {
- return beanTempFiles.addBuildMethodForInterface();
- }
- throw new TranslatorException("build method only supported for bean class");
- }
-
- /**
- * Adds default constructor for class.
- *
- * @param modifier modifier for constructor.
- * @param toAppend string which need to be appended with the class name
- * @return default constructor for class
- * @throws IOException when fails to append to file
- */
- public String addDefaultConstructor(String modifier, String toAppend)
- throws IOException {
- boolean isSuffix = false;
- if (toAppend.equals(BUILDER)) {
- isSuffix = true;
- }
- if (typeTempFiles != null) {
- return typeTempFiles.addDefaultConstructor(modifier, toAppend,
- isSuffix);
- }
- if (beanTempFiles != null) {
- return beanTempFiles.addDefaultConstructor(modifier, toAppend,
- isSuffix);
- }
-
- throw new TranslatorException("default constructor should not be added");
- }
-
- /**
- * Adds build method's implementation for class.
- *
- * @return build method implementation for class
- * @throws IOException when fails to append to temporary file
- */
- public String addBuildMethodImpl()
- throws IOException {
- if (beanTempFiles != null) {
- return beanTempFiles.addBuildMethodImpl();
- }
- throw new TranslatorException("build should not be added");
- }
-
- /**
- * Removes all temporary file handles.
- * when translator fails to generate java files we need to close
- * all open file handles include temporary files and java files
- *
- * @param isErrorOccurred if error occurred
- * @throws IOException when failed to delete the temporary files
- */
- public void freeTemporaryResources(boolean isErrorOccurred)
- throws IOException {
-
- if (beanTempFiles != null) {
- beanTempFiles.freeTemporaryResources(isErrorOccurred);
- }
-
- if (typeTempFiles != null) {
- typeTempFiles.freeTemporaryResources(isErrorOccurred);
- }
-
- if (enumTempFiles != null) {
- enumTempFiles.freeTemporaryResources(isErrorOccurred);
- }
-
- if (serviceTempFiles != null) {
- serviceTempFiles.freeTemporaryResources(isErrorOccurred);
- }
-
- if (eventTempFiles != null) {
- eventTempFiles.freeTemporaryResources(isErrorOccurred);
- }
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaCodeFragmentFilesContainer.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaCodeFragmentFilesContainer.java
deleted file mode 100644
index 1bbf349..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaCodeFragmentFilesContainer.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.yangutils.translator.tojava;
-
-/**
- * Represents Has temporary file handle.
- */
-public interface TempJavaCodeFragmentFilesContainer {
-
- /**
- * Returns the temporary file handle.
- *
- * @return temporary file handle
- */
- TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles();
-
- /**
- * Sets temporary file handle.
- *
- * @param fileHandle temporary file handle
- */
- void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle);
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaEnumerationFragmentFiles.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaEnumerationFragmentFiles.java
deleted file mode 100644
index 97feb1b..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaEnumerationFragmentFiles.java
+++ /dev/null
@@ -1,216 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.yangutils.translator.tojava;
-
-import org.onosproject.yangutils.datamodel.YangEnum;
-import org.onosproject.yangutils.datamodel.YangEnumeration;
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.translator.exception.TranslatorException;
-import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaTypeTranslator;
-import org.onosproject.yangutils.utils.io.YangPluginConfig;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.List;
-
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT32;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ENUM_IMPL_MASK;
-import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.generateEnumAttributeStringWithSchemaName;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEnumClassFile;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.createPackage;
-import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.INT;
-import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_FIRST_DIGIT;
-import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUTO_PREFIX;
-import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.closeFile;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getPrefixForIdentifier;
-
-/**
- * Represents implementation of java code fragments temporary implementations. Maintains the temp files required
- * specific for enumeration java snippet generation.
- */
-public class TempJavaEnumerationFragmentFiles
- extends TempJavaFragmentFiles {
-
- /**
- * File name for temporary enum class.
- */
- private static final String ENUM_CLASS_TEMP_FILE_NAME = "EnumClass";
-
- /**
- * Temporary file handle for enum class file.
- */
- private final File enumClassTempFileHandle;
-
- /**
- * Java file handle for enum class.
- */
- private File enumClassJavaFileHandle;
- private boolean isEnumClass;
-
- /**
- * Creates an instance of temporary java code fragment.
- *
- * @param javaFileInfo generated java file info
- * @throws IOException when fails to create new file handle
- */
- public TempJavaEnumerationFragmentFiles(JavaFileInfoTranslator javaFileInfo)
- throws IOException {
-
- super(javaFileInfo);
- /*
- * Initialize enum when generation file type matches to enum class mask.
- */
- addGeneratedTempFile(ENUM_IMPL_MASK);
- enumClassTempFileHandle = getTemporaryFileHandle(ENUM_CLASS_TEMP_FILE_NAME);
- }
-
- /**
- * Returns temporary file handle for enum class file.
- *
- * @return temporary file handle for enum class file
- */
- public File getEnumClassTempFileHandle() {
- return enumClassTempFileHandle;
- }
-
- /**
- * Adds enum class attributes to temporary file.
- *
- * @param yangEnum YANG enum
- * @throws IOException when fails to do IO operations.
- */
- private void addAttributesForEnumClass(YangEnum yangEnum)
- throws IOException {
- appendToFile(enumClassTempFileHandle,
- generateEnumAttributeStringWithSchemaName(yangEnum.getNamedValue(),
- yangEnum.getValue()));
- }
-
- /**
- * Adds enum attributes to temporary files.
- *
- * @param curNode current YANG node
- * @param config plugin configurations
- * @throws IOException when fails to do IO operations
- */
- public void addEnumAttributeToTempFiles(YangNode curNode,
- YangPluginConfig config)
- throws IOException {
-
- addJavaSnippetInfoToApplicableTempFiles(getJavaAttributeForEnum(config),
- config);
- if (curNode instanceof YangEnumeration) {
- YangEnumeration enumeration = (YangEnumeration) curNode;
- for (YangEnum curEnum : enumeration.getEnumSet()) {
- String enumName = curEnum.getNamedValue();
- String prefix;
- if (enumName.matches(REGEX_FOR_FIRST_DIGIT)) {
- prefix = getPrefixForIdentifier(
- config.getConflictResolver());
- if (prefix != null) {
- curEnum.setNamedValue(prefix + enumName);
- } else {
- curEnum.setNamedValue(YANG_AUTO_PREFIX + enumName);
- }
- }
- addJavaSnippetInfoToApplicableTempFiles(curEnum);
- }
- } else {
- throw new TranslatorException(
- "current node should be of enumeration type. " +
- curNode.getName() + " in " + curNode.getLineNumber() +
- " at " + curNode.getCharPosition() + " in " + curNode
- .getFileName());
- }
- }
-
- /**
- * Returns java attribute for enum class.
- *
- * @param config plugin configurations
- * @return java attribute
- */
- private JavaAttributeInfo getJavaAttributeForEnum(YangPluginConfig config) {
- YangJavaTypeTranslator javaType = new YangJavaTypeTranslator();
- javaType.setDataType(INT32);
- javaType.setDataTypeName(INT);
- javaType.updateJavaQualifiedInfo(config.getConflictResolver());
- return getAttributeInfoForTheData(
- javaType.getJavaQualifiedInfo(),
- javaType.getDataTypeName(), javaType,
- getIsQualifiedAccessOrAddToImportList(javaType.getJavaQualifiedInfo()),
- false);
- }
-
- /**
- * Adds the new attribute info to the target generated temporary files.
- *
- * @param yangEnum @throws IOException IO operation fail
- */
- private void addJavaSnippetInfoToApplicableTempFiles(YangEnum yangEnum)
- throws IOException {
- addAttributesForEnumClass(yangEnum);
- }
-
- /**
- * Constructs java code exit.
- *
- * @param fileType generated file type
- * @param curNode current YANG node
- * @throws IOException when fails to generate java files
- */
- @Override
- public void generateJavaFile(int fileType, YangNode curNode)
- throws IOException {
-
- List<String> imports = this.getJavaImportData().getImports();
- createPackage(curNode);
- enumClassJavaFileHandle = getJavaFileHandle(getJavaClassName(EMPTY_STRING));
- generateEnumClassFile(enumClassJavaFileHandle, curNode, imports);
- freeTemporaryResources(false);
- }
-
- /**
- * Removes all temporary file handles.
- *
- * @param isErrorOccurred flag to tell translator that error has occurred while file generation
- * @throws IOException when failed to delete the temporary files
- */
- @Override
- public void freeTemporaryResources(boolean isErrorOccurred)
- throws IOException {
- closeFile(enumClassJavaFileHandle, isErrorOccurred);
- closeFile(enumClassTempFileHandle, true);
- if (isEnumClass) {
- super.freeTemporaryResources(isErrorOccurred);
- }
- }
-
- public boolean isEnumClass() {
- return isEnumClass;
- }
-
- /**
- * Sets true if free super resources is required.
- *
- * @param enumClass true if free super resources is required
- */
- public void setEnumClass(boolean enumClass) {
- isEnumClass = enumClass;
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaEventFragmentFiles.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaEventFragmentFiles.java
deleted file mode 100644
index 4c5d69b..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaEventFragmentFiles.java
+++ /dev/null
@@ -1,442 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.translator.tojava;
-
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder;
-import org.onosproject.yangutils.utils.io.YangPluginConfig;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_ENUM_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_METHOD_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_SUBJECT_ATTRIBUTE_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_SUBJECT_GETTER_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_SUBJECT_SETTER_MASK;
-import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData;
-import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator.getQualifiedTypeInfoOfCurNode;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEventFile;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEventListenerFile;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateEventSubjectFile;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getFileObject;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getEnumJavaAttribute;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterForClass;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForClass;
-import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
-import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION;
-import static org.onosproject.yangutils.utils.UtilConstants.EVENT_LISTENER;
-import static org.onosproject.yangutils.utils.UtilConstants.EVENT_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
-import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
-import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.closeFile;
-import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD;
-import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.MANAGER_SETTER_METHOD;
-import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.enumJavaDocForInnerClass;
-import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
-
-/**
- * Represent temporary java fragments for event files.
- */
-public class TempJavaEventFragmentFiles
- extends TempJavaFragmentFiles {
- /**
- * File name for generated class file for special type like union, typedef suffix.
- */
- private static final String EVENT_SUBJECT_NAME_SUFFIX = "EventSubject";
-
- /**
- * File name for event enum temp file.
- */
- private static final String EVENT_ENUM_FILE_NAME = "EventEnum";
-
- /**
- * File name for event method temp file.
- */
- private static final String EVENT_METHOD_FILE_NAME = "EventMethod";
-
- /**
- * File name for event subject attribute temp file.
- */
- private static final String EVENT_SUBJECT_ATTRIBUTE_FILE_NAME
- = "EventSubjectAttribute";
-
- /**
- * File name for event subject getter temp file.
- */
- private static final String EVENT_SUBJECT_GETTER_FILE_NAME
- = "EventSubjectGetter";
-
- /**
- * File name for event subject setter temp file.
- */
- private static final String EVENT_SUBJECT_SETTER_FILE_NAME
- = "EventSubjectSetter";
-
- private static final String JAVA_FILE_EXTENSION = ".java";
-
- /**
- * Java file handle for event subject file.
- */
- private File eventSubjectJavaFileHandle;
-
- /**
- * Java file handle for event listener file.
- */
- private File eventListenerJavaFileHandle;
-
- /**
- * Java file handle for event file.
- */
- private File eventJavaFileHandle;
-
- /**
- * Java file handle for event enum impl file.
- */
- private final File eventEnumTempFileHandle;
-
- /**
- * Java file handle for event method impl file.
- */
- private final File eventMethodTempFileHandle;
-
- /**
- * Java file handle for event subject attribute file.
- */
- private final File eventSubjectAttributeTempFileHandle;
-
- /**
- * Java file handle for event subject getter impl file.
- */
- private final File eventSubjectGetterTempFileHandle;
-
- /**
- * Java file handle for event subject setter impl file.
- */
- private final File eventSubjectSetterTempFileHandle;
-
- /**
- * Creates an instance of temporary java code fragment.
- *
- * @param javaFileInfo generated file information
- * @throws IOException when fails to create new file handle
- */
- TempJavaEventFragmentFiles(JavaFileInfoTranslator javaFileInfo)
- throws IOException {
- setJavaExtendsListHolder(new JavaExtendsListHolder());
- setJavaImportData(new JavaImportData());
- setJavaFileInfo(javaFileInfo);
- setAbsoluteDirPath(getAbsolutePackagePath(
- getJavaFileInfo().getBaseCodeGenPath(),
- getJavaFileInfo().getPackageFilePath()));
-
- addGeneratedTempFile(EVENT_ENUM_MASK);
- addGeneratedTempFile(EVENT_METHOD_MASK);
- addGeneratedTempFile(EVENT_SUBJECT_ATTRIBUTE_MASK);
- addGeneratedTempFile(EVENT_SUBJECT_GETTER_MASK);
- addGeneratedTempFile(EVENT_SUBJECT_SETTER_MASK);
-
- eventEnumTempFileHandle = getTemporaryFileHandle(EVENT_ENUM_FILE_NAME);
- eventMethodTempFileHandle = getTemporaryFileHandle(
- EVENT_METHOD_FILE_NAME);
- eventSubjectAttributeTempFileHandle = getTemporaryFileHandle
- (EVENT_SUBJECT_ATTRIBUTE_FILE_NAME);
- eventSubjectGetterTempFileHandle = getTemporaryFileHandle(
- EVENT_SUBJECT_GETTER_FILE_NAME);
- eventSubjectSetterTempFileHandle = getTemporaryFileHandle(
- EVENT_SUBJECT_SETTER_FILE_NAME);
- }
-
- /**
- * Returns event enum temp file.
- *
- * @return event enum temp file
- */
- public File getEventEnumTempFileHandle() {
- return eventEnumTempFileHandle;
- }
-
- /**
- * Returns event method temp file.
- *
- * @return event method temp file
- */
- public File getEventMethodTempFileHandle() {
- return eventMethodTempFileHandle;
- }
-
- /**
- * Returns event subject attribute temp file.
- *
- * @return event subject attribute temp file
- */
- public File getEventSubjectAttributeTempFileHandle() {
- return eventSubjectAttributeTempFileHandle;
- }
-
- /**
- * Returns event subject getter temp file.
- *
- * @return event subject getter temp file
- */
- public File getEventSubjectGetterTempFileHandle() {
- return eventSubjectGetterTempFileHandle;
- }
-
- /**
- * Returns event subject setter temp file.
- *
- * @return event subject setter temp file
- */
- public File getEventSubjectSetterTempFileHandle() {
- return eventSubjectSetterTempFileHandle;
- }
-
- /*Adds event method contents to event file.*/
- private static String getEventFileContents(String eventClassname, String classname) {
- return "\n" +
- " /**\n" +
- " * Creates " + classname + " event with type and subject.\n" +
- " *\n" +
- " * @param type event type\n" +
- " * @param subject subject " + classname + "\n" +
- " */\n" +
- " public " + eventClassname + "(Type type, " +
- getCapitalCase(classname) + " subject) {\n" +
- " super(type, subject);\n" +
- " }\n" +
- "\n" +
- " /**\n" +
- " * Creates " + classname + " event with type, subject and time.\n" +
- " *\n" +
- " * @param type event type\n" +
- " * @param subject subject " + classname + "\n" +
- " * @param time time of event\n" +
- " */\n" +
- " public " + eventClassname + "(Type type, " + getCapitalCase(classname)
- + " subject, long time) {\n" +
- " super(type, subject, time);\n" +
- " }\n" +
- "\n";
- }
-
- public void generateJavaFile(int fileType, YangNode curNode)
- throws IOException {
- generateEventJavaFile(curNode);
- generateEventListenerJavaFile(curNode);
- generateEventSubjectJavaFile(curNode);
-
- // Close all the file handles.
- freeTemporaryResources(false);
- }
-
- /**
- * Constructs java code exit.
- *
- * @param curNode current YANG node
- * @throws IOException when fails to generate java files
- */
- private void generateEventJavaFile(YangNode curNode)
- throws IOException {
-
- List<String> imports = new ArrayList<>();
-
- imports.add(getJavaImportData().getAbstractEventsImport());
- String curNodeInfo = getCapitalCase(((JavaFileInfoContainer) curNode)
- .getJavaFileInfo().getJavaName());
- String nodeName = curNodeInfo + EVENT_STRING;
-
- addEnumMethod(nodeName, curNodeInfo + EVENT_SUBJECT_NAME_SUFFIX);
-
- //Creates event interface file.
- eventJavaFileHandle = getJavaFileHandle(curNode, curNodeInfo +
- EVENT_STRING);
- generateEventFile(eventJavaFileHandle, curNode, imports);
- }
-
- /**
- * Constructs java code exit.
- *
- * @param curNode current YANG node
- * @throws IOException when fails to generate java files
- */
- private void generateEventListenerJavaFile(YangNode curNode)
- throws IOException {
-
- List<String> imports = new ArrayList<>();
-
- imports.add(getJavaImportData().getEventListenerImport());
- String curNodeInfo = getCapitalCase(((JavaFileInfoContainer) curNode)
- .getJavaFileInfo().getJavaName());
-
- // Creates event listener interface file.
- eventListenerJavaFileHandle =
- getJavaFileHandle(curNode, curNodeInfo + EVENT_LISTENER);
- generateEventListenerFile(eventListenerJavaFileHandle, curNode, imports);
- }
-
- /**
- * Constructs java code exit.
- *
- * @param curNode current YANG node
- * @throws IOException when fails to generate java files
- */
- private void generateEventSubjectJavaFile(YangNode curNode)
- throws IOException {
-
- String curNodeInfo = getCapitalCase(((JavaFileInfoContainer) curNode)
- .getJavaFileInfo().getJavaName());
-
- //Creates event interface file.
- eventSubjectJavaFileHandle = getJavaFileHandle(curNode, curNodeInfo +
- EVENT_SUBJECT_NAME_SUFFIX);
- generateEventSubjectFile(eventSubjectJavaFileHandle, curNode);
- }
-
- /**
- * Adds java snippet for events to event subject file.
- *
- * @param curNode current node
- * @param pluginConfig plugin configurations
- * @throws IOException when fails to do IO operations
- */
- void addJavaSnippetOfEvent(YangNode curNode, YangPluginConfig pluginConfig)
- throws IOException {
-
- String currentInfo = getCamelCase(curNode.getName(), pluginConfig
- .getConflictResolver());
- String notificationName = curNode.getName();
-
- JavaQualifiedTypeInfoTranslator qualifiedTypeInfo
- = getQualifiedTypeInfoOfCurNode(curNode, getCapitalCase(currentInfo));
-
- JavaAttributeInfo javaAttributeInfo
- = getAttributeInfoForTheData(qualifiedTypeInfo, currentInfo,
- null, false, false);
-
- /*Adds java info for event in respective temp files.*/
- addEventEnum(notificationName);
- addEventSubjectAttribute(javaAttributeInfo);
- addEventSubjectGetter(javaAttributeInfo);
- addEventSubjectSetter(javaAttributeInfo, currentInfo);
- }
-
- /*Adds event to enum temp file.*/
- private void addEventEnum(String notificationName)
- throws IOException {
- appendToFile(getEventEnumTempFileHandle(), enumJavaDocForInnerClass(
- notificationName) + EIGHT_SPACE_INDENTATION
- + getEnumJavaAttribute(notificationName).toUpperCase() +
- COMMA + NEW_LINE);
- }
-
- /*Adds event method in event class*/
- private void addEnumMethod(String eventClassname, String className)
- throws IOException {
- appendToFile(getEventMethodTempFileHandle(),
- getEventFileContents(eventClassname, className));
- }
-
- /*Adds events to event subject file.*/
- private void addEventSubjectAttribute(JavaAttributeInfo attr)
- throws IOException {
- appendToFile(getEventSubjectAttributeTempFileHandle(),
- parseAttribute(attr));
- }
-
- /*Adds getter method for event in event subject class.*/
- private void addEventSubjectGetter(JavaAttributeInfo attr)
- throws IOException {
- String appDataStructure = null;
- if (attr.getCompilerAnnotation() != null) {
- appDataStructure = attr.getCompilerAnnotation()
- .getYangAppDataStructure().getDataStructure().name();
- }
- appendToFile(getEventSubjectGetterTempFileHandle(), getJavaDoc(
- GETTER_METHOD, attr.getAttributeName(), false,
- appDataStructure) + getGetterForClass(
- attr, GENERATE_EVENT_SUBJECT_CLASS) + NEW_LINE);
- }
-
- /*Adds setter method for event in event subject class.*/
- private void addEventSubjectSetter(JavaAttributeInfo attr,
- String className)
- throws IOException {
- String appDataStructure = null;
- if (attr.getCompilerAnnotation() != null) {
- appDataStructure = attr.getCompilerAnnotation()
- .getYangAppDataStructure().getDataStructure().name();
- }
- appendToFile(getEventSubjectSetterTempFileHandle(), getJavaDoc(
- MANAGER_SETTER_METHOD, attr.getAttributeName(),
- false, appDataStructure) + getSetterForClass(
- attr, className, GENERATE_EVENT_SUBJECT_CLASS) + NEW_LINE);
- }
-
- /**
- * Returns a temporary file handle for the event's file type.
- *
- * @param name file name
- * @return temporary file handle
- */
- private File getJavaFileHandle(YangNode curNode, String name) {
-
- JavaFileInfoTranslator parentInfo = ((JavaFileInfoContainer) curNode)
- .getJavaFileInfo();
- return getFileObject(getDirPath(parentInfo), name, JAVA_FILE_EXTENSION,
- parentInfo);
- }
-
- /**
- * Returns the directory path.
- *
- * @return directory path
- */
- private String getDirPath(JavaFileInfoTranslator parentInfo) {
- return (parentInfo.getPackageFilePath() + SLASH +
- parentInfo.getJavaName()).toLowerCase();
- }
-
- /**
- * Removes all temporary file handles.
- *
- * @param isErrorOccurred flag to tell translator that error has occurred while file generation
- * @throws IOException when failed to delete the temporary files
- */
- @Override
- public void freeTemporaryResources(boolean isErrorOccurred)
- throws IOException {
-
- closeFile(eventJavaFileHandle, isErrorOccurred);
- closeFile(eventListenerJavaFileHandle, isErrorOccurred);
- closeFile(eventSubjectJavaFileHandle, isErrorOccurred);
-
- closeFile(eventEnumTempFileHandle, true);
- closeFile(eventSubjectAttributeTempFileHandle, true);
- closeFile(eventMethodTempFileHandle, true);
- closeFile(eventSubjectGetterTempFileHandle, true);
- closeFile(eventSubjectSetterTempFileHandle, true);
-
- super.freeTemporaryResources(isErrorOccurred);
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaFragmentFiles.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaFragmentFiles.java
deleted file mode 100644
index ec97d8e..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaFragmentFiles.java
+++ /dev/null
@@ -1,1942 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.yangutils.translator.tojava;
-
-import org.onosproject.yangutils.datamodel.RpcNotificationContainer;
-import org.onosproject.yangutils.datamodel.YangAugment;
-import org.onosproject.yangutils.datamodel.YangAugmentableNode;
-import org.onosproject.yangutils.datamodel.YangCase;
-import org.onosproject.yangutils.datamodel.YangChoice;
-import org.onosproject.yangutils.datamodel.YangLeaf;
-import org.onosproject.yangutils.datamodel.YangLeafList;
-import org.onosproject.yangutils.datamodel.YangLeavesHolder;
-import org.onosproject.yangutils.datamodel.YangList;
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.YangType;
-import org.onosproject.yangutils.datamodel.javadatamodel.JavaQualifiedTypeInfo;
-import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
-import org.onosproject.yangutils.translator.exception.TranslatorException;
-import org.onosproject.yangutils.translator.tojava.javamodel.JavaLeafInfoContainer;
-import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaGroupingTranslator;
-import org.onosproject.yangutils.translator.tojava.utils.BitsJavaInfoHandler;
-import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder;
-import org.onosproject.yangutils.utils.io.YangPluginConfig;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.getParentNodeInGenCode;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.DEFAULT_CLASS_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPE_CLASS;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ADD_TO_LIST_IMPL_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ADD_TO_LIST_INTERFACE_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EDIT_CONTENT_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EQUALS_IMPL_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FILTER_CONTENT_MATCH_FOR_LEAF_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FILTER_CONTENT_MATCH_FOR_NODES_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FROM_STRING_IMPL_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_CLASS_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.HASH_CODE_IMPL_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_CLASS_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK;
-import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData;
-import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator.getQualifiedInfoOfFromString;
-import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator.getQualifiedTypeInfoOfCurNode;
-import static org.onosproject.yangutils.translator.tojava.javamodel.AttributesJavaDataType.updateJavaFileInfo;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.generateEnumAttributeString;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaAttributeDefinition;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.sortImports;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateBuilderClassFile;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateBuilderInterfaceFile;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateDefaultClassFile;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateInterfaceFile;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getFileObject;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.createPackage;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAddToListMethodImpl;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAddToListMethodInterface;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBuildString;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getDefaultConstructorString;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethod;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getFromStringMethod;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterForClass;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterString;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethod;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForClass;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterString;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethod;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.parseBuilderInterfaceBuildMethodString;
-import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getOverRideString;
-import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator.getSubtreeFilteringForLeaf;
-import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator.getSubtreeFilteringForLeafList;
-import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator.getSubtreeFilteringForNode;
-import static org.onosproject.yangutils.translator.tojava.utils.TranslatorErrorType.INVALID_LEAF_HOLDER;
-import static org.onosproject.yangutils.translator.tojava.utils.TranslatorErrorType.INVALID_NODE;
-import static org.onosproject.yangutils.translator.tojava.utils.TranslatorErrorType.INVALID_PARENT_NODE;
-import static org.onosproject.yangutils.translator.tojava.utils.TranslatorErrorType.MISSING_PARENT_NODE;
-import static org.onosproject.yangutils.translator.tojava.utils.TranslatorUtils.getBeanFiles;
-import static org.onosproject.yangutils.translator.tojava.utils.TranslatorUtils.getErrorMsg;
-import static org.onosproject.yangutils.utils.UtilConstants.ARRAY_LIST_IMPORT;
-import static org.onosproject.yangutils.utils.UtilConstants.BIT_SET;
-import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
-import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET;
-import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT;
-import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT_CAPS;
-import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
-import static org.onosproject.yangutils.utils.UtilConstants.INTERFACE;
-import static org.onosproject.yangutils.utils.UtilConstants.INVOCATION_TARGET_EXCEPTION_IMPORT;
-import static org.onosproject.yangutils.utils.UtilConstants.JAVA_UTIL_PKG;
-import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
-import static org.onosproject.yangutils.utils.UtilConstants.OPERATION_TYPE_ATTRIBUTE;
-import static org.onosproject.yangutils.utils.UtilConstants.OPERATION_TYPE_CLASS;
-import static org.onosproject.yangutils.utils.UtilConstants.OP_PARAM;
-import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
-import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE;
-import static org.onosproject.yangutils.utils.UtilConstants.PROTECTED;
-import static org.onosproject.yangutils.utils.UtilConstants.SERVICE;
-import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
-import static org.onosproject.yangutils.utils.UtilConstants.YANG;
-import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.closeFile;
-import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.readAppendFile;
-import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.ADD_TO_LIST;
-import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD;
-import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.SETTER_METHOD;
-import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getPackageDirPathFromJavaJPackage;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.mergeJavaFiles;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.validateLineLength;
-
-/**
- * Represents implementation of java code fragments temporary implementations.
- * Manages the common temp file required for Java file(s) generated.
- */
-public class TempJavaFragmentFiles {
-
- /**
- * File type extension for java classes.
- */
- private static final String JAVA_FILE_EXTENSION = ".java";
-
- /**
- * File type extension for temporary classes.
- */
- private static final String TEMP_FILE_EXTENSION = ".tmp";
-
- /**
- * Folder suffix for temporary files folder.
- */
- private static final String TEMP_FOLDER_NAME_SUFFIX = "-Temp";
-
- /**
- * File name for getter method.
- */
- private static final String GETTER_METHOD_FILE_NAME = "GetterMethod";
-
- /**
- * File name for setter method.
- */
- private static final String SETTER_METHOD_FILE_NAME = "SetterMethod";
-
- /**
- * File name for getter method implementation.
- */
- private static final String GETTER_METHOD_IMPL_FILE_NAME =
- "GetterMethodImpl";
-
- /**
- * File name for setter method implementation.
- */
- private static final String SETTER_METHOD_IMPL_FILE_NAME =
- "SetterMethodImpl";
-
- /**
- * File name for attributes.
- */
- private static final String ATTRIBUTE_FILE_NAME = "Attributes";
-
- /**
- * File name for to string method.
- */
- private static final String TO_STRING_METHOD_FILE_NAME = "ToString";
-
- /**
- * File name for hash code method.
- */
- private static final String HASH_CODE_METHOD_FILE_NAME = "HashCode";
-
- /**
- * File name for equals method.
- */
- private static final String EQUALS_METHOD_FILE_NAME = "Equals";
-
- /**
- * File name for from string method.
- */
- private static final String FROM_STRING_METHOD_FILE_NAME = "FromString";
-
- /**
- * File name for from add to list interface method.
- */
- private static final String ADD_TO_LIST_INTERFACE_METHOD_FILE_NAME =
- "addToList";
-
- /**
- * File name for from add to list impl method.
- */
- private static final String ADD_TO_LIST_IMPL_METHOD_FILE_NAME =
- "addToListImpl";
-
- /**
- * File name for from leaf identifier attributes.
- */
- private static final String LEAF_IDENTIFIER_ATTRIBUTES_FILE_NAME =
- "leafIdentifierAtr";
-
- /**
- * File name for is filter content leaf match.
- */
- private static final String FILTER_CONTENT_MATCH_LEAF_FILE_NAME =
- "isFilterContentMatchLeafMask";
-
- /**
- * File name for is filter content leaf-list match.
- */
- private static final String FILTER_CONTENT_MATCH_LEAF_LIST_FILE_NAME =
- "isFilterContentMatchLeafListMask";
-
- /**
- * File name for is filter content node match.
- */
- private static final String FILTER_CONTENT_MATCH_NODE_FILE_NAME =
- "isFilterContentMatchNodeMask";
-
- /**
- * File name for edit content file.
- */
- private static final String EDIT_CONTENT_FILE_NAME = "editContentFile";
-
- /**
- * File name for interface java file name suffix.
- */
- private static final String INTERFACE_FILE_NAME_SUFFIX = EMPTY_STRING;
-
- /**
- * File name for builder interface file name suffix.
- */
- private static final String BUILDER_INTERFACE_FILE_NAME_SUFFIX =
- BUILDER + INTERFACE;
-
- /**
- * File name for builder class file name suffix.
- */
- private static final String BUILDER_CLASS_FILE_NAME_SUFFIX = BUILDER;
-
- /**
- * Information about the java files being generated.
- */
- private JavaFileInfoTranslator javaFileInfo;
-
- /**
- * Imported class info.
- */
- private JavaImportData javaImportData;
-
- /**
- * The variable which guides the types of temporary files generated using
- * the temporary generated file types mask.
- */
- private int tempFilesFlagSet;
-
- /**
- * Absolute path where the target java file needs to be generated.
- */
- private String absoluteDirPath;
-
- /**
- * Contains all the interface(s)/class name which will be extended by
- * generated files.
- */
- private JavaExtendsListHolder javaExtendsListHolder;
-
- /**
- * Java file handle for interface file.
- */
- private File interfaceJavaFileHandle;
-
- /**
- * Java file handle for builder interface file.
- */
- private File builderInterfaceJavaFileHandle;
-
- /**
- * Java file handle for builder class file.
- */
- private File builderClassJavaFileHandle;
-
- /**
- * Java file handle for impl class file.
- */
- private File implClassJavaFileHandle;
-
- /**
- * Temporary file handle for attribute.
- */
- private File attributesTempFileHandle;
-
- /**
- * Temporary file handle for getter of interface.
- */
- private File getterInterfaceTempFileHandle;
-
- /**
- * Temporary file handle for setter of interface.
- */
- private File setterInterfaceTempFileHandle;
-
- /**
- * Temporary file handle for getter of class.
- */
- private File getterImplTempFileHandle;
-
- /**
- * Temporary file handle for setter of class.
- */
- private File setterImplTempFileHandle;
-
- /**
- * Temporary file handle for hash code method of class.
- */
- private File hashCodeImplTempFileHandle;
-
- /**
- * Temporary file handle for equals method of class.
- */
- private File equalsImplTempFileHandle;
-
- /**
- * Temporary file handle for to string method of class.
- */
- private File toStringImplTempFileHandle;
-
- /**
- * Temporary file handle for from string method of class.
- */
- private File fromStringImplTempFileHandle;
-
- /**
- * Temporary file handle for add to list interface method of class.
- */
- private File addToListInterfaceTempFileHandle;
-
- /**
- * Temporary file handle for add to list impl method of class.
- */
- private File addToListImplTempFileHandle;
-
- /**
- * Temporary file handle for leaf id attributes of enum.
- */
- private File leafIdAttributeTempFileHandle;
-
- /**
- * Temporary file handle for is content match method for leaf-list.
- */
- private File getSubtreeFilteringForListTempFileHandle;
-
- /**
- * Temporary file handle for is content match method for node.
- */
- private File getSubtreeFilteringForChildNodeTempFileHandle;
-
- /**
- * Temporary file handle for is content match method for leaf.
- */
- private File subtreeFilteringForLeafTempFileHandle;
-
- /**
- * Temporary file handle for edit content file.
- */
- private File editContentTempFileHandle;
-
- /**
- * Leaf count.
- */
- private int leafCount;
-
- /**
- * If current node is root node.
- */
- private boolean rootNode;
-
- /**
- * Is attribute added.
- */
- private boolean isAttributePresent;
-
- /**
- * List of bits attributes.
- */
- private List<BitsJavaInfoHandler> bitsHandler = new ArrayList<>();
-
- /**
- * Creates an instance of temp JAVA fragment files.
- */
- TempJavaFragmentFiles() {
- }
-
- /**
- * Creates an instance of temporary java code fragment.
- *
- * @param fileInfo generated java file information
- * @throws IOException when fails to create new file handle
- */
- protected TempJavaFragmentFiles(JavaFileInfoTranslator fileInfo)
- throws IOException {
- javaExtendsListHolder = new JavaExtendsListHolder();
- javaImportData = new JavaImportData();
- javaFileInfo = fileInfo;
- absoluteDirPath = getAbsolutePackagePath(fileInfo.getBaseCodeGenPath(),
- fileInfo.getPackageFilePath());
- /*
- * Initialize getter when generation file type matches to interface
- * mask.
- */
- if (javaFlagSet(INTERFACE_MASK)) {
- addGeneratedTempFile(GETTER_FOR_INTERFACE_MASK |
- ADD_TO_LIST_INTERFACE_MASK |
- LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK);
- }
- /*
- * Initialize getter and setter when generation file type matches to
- * builder interface mask.
- */
- if (javaFlagSet(BUILDER_INTERFACE_MASK)) {
- addGeneratedTempFile(GETTER_FOR_INTERFACE_MASK |
- SETTER_FOR_INTERFACE_MASK);
- }
- /*
- * Initialize getterImpl, setterImpl and attributes when generation file
- * type matches to builder class mask.
- */
- if (javaFlagSet(BUILDER_CLASS_MASK)) {
- addGeneratedTempFile(ATTRIBUTES_MASK | GETTER_FOR_CLASS_MASK |
- SETTER_FOR_CLASS_MASK);
- }
- /*
- * Initialize getterImpl, attributes, constructor, hash code, equals and
- * to strings when generation file type matches to impl class mask.
- */
- if (javaFlagSet(DEFAULT_CLASS_MASK)) {
- addGeneratedTempFile(
- ATTRIBUTES_MASK | GETTER_FOR_CLASS_MASK |
- HASH_CODE_IMPL_MASK | EQUALS_IMPL_MASK |
- TO_STRING_IMPL_MASK | ADD_TO_LIST_IMPL_MASK |
- FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK |
- FILTER_CONTENT_MATCH_FOR_LEAF_MASK |
- FILTER_CONTENT_MATCH_FOR_NODES_MASK);
- }
- /*
- * Initialize temp files to generate type class.
- */
- if (javaFlagSet(GENERATE_TYPE_CLASS)) {
- addGeneratedTempFile(ATTRIBUTES_MASK | GETTER_FOR_CLASS_MASK |
- HASH_CODE_IMPL_MASK | EQUALS_IMPL_MASK |
- FROM_STRING_IMPL_MASK);
-
- if (getGeneratedJavaFiles() != GENERATE_UNION_CLASS) {
- addGeneratedTempFile(TO_STRING_IMPL_MASK);
- }
- }
-
- //Set temporary file handles
- if (tempFlagSet(ATTRIBUTES_MASK)) {
- attributesTempFileHandle =
- getTemporaryFileHandle(ATTRIBUTE_FILE_NAME);
- }
- if (tempFlagSet(GETTER_FOR_INTERFACE_MASK)) {
- getterInterfaceTempFileHandle =
- getTemporaryFileHandle(GETTER_METHOD_FILE_NAME);
- }
- if (tempFlagSet(SETTER_FOR_INTERFACE_MASK)) {
- setterInterfaceTempFileHandle =
- getTemporaryFileHandle(SETTER_METHOD_FILE_NAME);
- }
- if (tempFlagSet(GETTER_FOR_CLASS_MASK)) {
- getterImplTempFileHandle =
- getTemporaryFileHandle(GETTER_METHOD_IMPL_FILE_NAME);
- }
- if (tempFlagSet(SETTER_FOR_CLASS_MASK)) {
- setterImplTempFileHandle =
- getTemporaryFileHandle(SETTER_METHOD_IMPL_FILE_NAME);
- }
- if (tempFlagSet(HASH_CODE_IMPL_MASK)) {
- hashCodeImplTempFileHandle =
- getTemporaryFileHandle(HASH_CODE_METHOD_FILE_NAME);
- }
- if (tempFlagSet(EQUALS_IMPL_MASK)) {
- equalsImplTempFileHandle =
- getTemporaryFileHandle(EQUALS_METHOD_FILE_NAME);
- }
- if (tempFlagSet(TO_STRING_IMPL_MASK)) {
- toStringImplTempFileHandle =
- getTemporaryFileHandle(TO_STRING_METHOD_FILE_NAME);
- }
- if (tempFlagSet(FROM_STRING_IMPL_MASK)) {
- fromStringImplTempFileHandle =
- getTemporaryFileHandle(FROM_STRING_METHOD_FILE_NAME);
- }
- if (tempFlagSet(ADD_TO_LIST_INTERFACE_MASK)) {
- addToListInterfaceTempFileHandle =
- getTemporaryFileHandle(ADD_TO_LIST_INTERFACE_METHOD_FILE_NAME);
- }
- if (tempFlagSet(ADD_TO_LIST_IMPL_MASK)) {
- addToListImplTempFileHandle =
- getTemporaryFileHandle(ADD_TO_LIST_IMPL_METHOD_FILE_NAME);
- }
- if (tempFlagSet(LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK)) {
- leafIdAttributeTempFileHandle =
- getTemporaryFileHandle(LEAF_IDENTIFIER_ATTRIBUTES_FILE_NAME);
- }
- if (tempFlagSet(FILTER_CONTENT_MATCH_FOR_LEAF_MASK)) {
- subtreeFilteringForLeafTempFileHandle =
- getTemporaryFileHandle(FILTER_CONTENT_MATCH_LEAF_FILE_NAME);
- }
- if (tempFlagSet(FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK)) {
- getSubtreeFilteringForListTempFileHandle =
- getTemporaryFileHandle(FILTER_CONTENT_MATCH_LEAF_LIST_FILE_NAME);
- }
- if (tempFlagSet(FILTER_CONTENT_MATCH_FOR_NODES_MASK)) {
- getSubtreeFilteringForChildNodeTempFileHandle =
- getTemporaryFileHandle(FILTER_CONTENT_MATCH_NODE_FILE_NAME);
- }
- if (tempFlagSet(EDIT_CONTENT_MASK)) {
- editContentTempFileHandle =
- getTemporaryFileHandle(EDIT_CONTENT_FILE_NAME);
- }
- }
-
- /**
- * Adds current node info as and attribute to the parent generated file.
- *
- * @param curNode current node
- * @param isList is list construct
- * @param config plugin configurations
- * @throws IOException IO operation exception
- */
- protected static void addCurNodeInfoInParentTempFile(YangNode curNode,
- boolean isList,
- YangPluginConfig config)
- throws IOException {
- YangNode parent = getParentNodeInGenCode(curNode);
- if (!(parent instanceof JavaCodeGenerator)) {
- throw new TranslatorException(getErrorMsg(MISSING_PARENT_NODE,
- curNode));
- }
- if (parent instanceof YangJavaGroupingTranslator) {
- /*
- * In case of grouping, there is no need to add the information, it
- * will be taken care in uses.
- */
- return;
- }
- addCurNodeInfoInParentTempFile(curNode, isList, config, parent);
- }
-
- /**
- * Adds current node info as and attribute to a specified parent generated
- * file. In case of grouping parent will be referred grouping node or
- * referred node in grouping.
- *
- * @param curNode current node
- * @param isList is list construct
- * @param config plugin configurations
- * @param parent parent node
- * @throws IOException IO operation exception
- */
- protected static void addCurNodeInfoInParentTempFile(
- YangNode curNode, boolean isList, YangPluginConfig config,
- YangNode parent)
- throws IOException {
- TempJavaBeanFragmentFiles tempFiles =
- getBeanFiles((JavaCodeGeneratorInfo) parent);
- JavaAttributeInfo attr =
- getCurNodeAsAttributeInTarget(curNode, parent, isList,
- tempFiles);
- tempFiles.addJavaSnippetInfoToApplicableTempFiles(attr, config);
- }
-
- /**
- * Creates an attribute info object corresponding to a data model node
- * and return it.
- *
- * @param curNode current node
- * @param targetNode target node
- * @param listNode flag indicating if a node is a list node
- * @param tempFiles temp java fragment files
- * @return java attribute info
- */
- public static JavaAttributeInfo
- getCurNodeAsAttributeInTarget(YangNode curNode, YangNode targetNode,
- boolean listNode,
- TempJavaFragmentFiles tempFiles) {
- JavaFileInfoTranslator translator =
- ((JavaFileInfoContainer) curNode).getJavaFileInfo();
- String curNodeName = translator.getJavaName();
- if (curNodeName == null) {
- updateJavaFileInfo(curNode, null);
- curNodeName = translator.getJavaName();
- }
- /*
- * Get the import info corresponding to the attribute for import in
- * generated java files or qualified access.
- */
- JavaQualifiedTypeInfoTranslator typeInfo =
- getQualifiedTypeInfoOfCurNode(curNode,
- getCapitalCase(curNodeName));
- if (!(targetNode instanceof TempJavaCodeFragmentFilesContainer)) {
- throw new TranslatorException(getErrorMsg(INVALID_PARENT_NODE,
- curNode));
- }
- JavaImportData parentImportData = tempFiles.getJavaImportData();
- JavaFileInfoTranslator fileInfo =
- ((JavaFileInfoContainer) targetNode).getJavaFileInfo();
-
- boolean qualified;
- if (tempFiles instanceof TempJavaServiceFragmentFiles &&
- typeInfo.getClassInfo().contentEquals(SERVICE) ||
- typeInfo.getClassInfo()
- .contentEquals(getCapitalCase(fileInfo.getJavaName() +
- SERVICE))) {
- qualified = true;
- } else {
- String className;
- if (tempFiles instanceof TempJavaServiceFragmentFiles) {
- className = getCapitalCase(fileInfo.getJavaName()) + SERVICE;
- } else {
- className = getCapitalCase(fileInfo.getJavaName());
- }
- qualified = parentImportData.addImportInfo(typeInfo, className,
- fileInfo.getPackage());
- }
- boolean collectionSet = false;
- if (curNode instanceof YangList) {
- YangList yangList = (YangList) curNode;
- if (yangList.getCompilerAnnotation() != null &&
- yangList.getCompilerAnnotation()
- .getYangAppDataStructure() != null) {
- switch (yangList.getCompilerAnnotation()
- .getYangAppDataStructure().getDataStructure()) {
- case QUEUE: {
- parentImportData.setQueueToImport(true);
- collectionSet = true;
- break;
- }
- case SET: {
- parentImportData.setSetToImport(true);
- collectionSet = true;
- break;
- }
- default: {
- // TODO : to be implemented
- }
- }
- }
- }
- if (listNode && !collectionSet) {
- parentImportData.setIfListImported(true);
- }
- if (curNode instanceof YangList) {
- return getAttributeInfoForTheData(typeInfo, curNodeName,
- null, qualified, listNode,
- ((YangList) curNode)
- .getCompilerAnnotation());
- }
- return getAttributeInfoForTheData(typeInfo, curNodeName, null,
- qualified, listNode);
- }
-
- /**
- * Returns java attribute for leaf.
- *
- * @param tempFiles temporary generated file
- * @param container JAVA leaf info container
- * @param config plugin configurations
- * @param leafList flag indicating if it's leaf list
- * @return java attribute info
- */
- private static JavaAttributeInfo
- getJavaAttributeOfLeaf(TempJavaFragmentFiles tempFiles,
- JavaLeafInfoContainer container,
- YangPluginConfig config, boolean leafList) {
- if (leafList) {
- tempFiles.getJavaImportData().setIfListImported(true);
- return getAttributeOfLeafInfoContainer(tempFiles, container, config,
- true);
- }
- return getAttributeOfLeafInfoContainer(tempFiles, container, config,
- false);
- }
-
- /**
- * Returns java attribute for leaf container.
- *
- * @param tempFiles temporary generated file
- * @param container JAVA leaf info container
- * @param config plugin configurations
- * @param listAttribute flag indicating if list attribute
- * @return JAVA attribute information
- */
- private static JavaAttributeInfo
- getAttributeOfLeafInfoContainer(TempJavaFragmentFiles tempFiles,
- JavaLeafInfoContainer container,
- YangPluginConfig config,
- boolean listAttribute) {
- container.setConflictResolveConfig(config.getConflictResolver());
- container.updateJavaQualifiedInfo();
- addImportForLeafInfo(tempFiles, container);
- JavaAttributeInfo attr = getAttributeInfoForTheData(
- container.getJavaQualifiedInfo(),
- container.getJavaName(config.getConflictResolver()),
- container.getDataType(),
- tempFiles.getIsQualifiedAccessOrAddToImportList(
- container.getJavaQualifiedInfo()), listAttribute);
- if (container.getDataType().getDataType() == YangDataTypes.BITS) {
- addBitsHandler(attr, container.getDataType(), tempFiles);
- }
- return attr;
- }
-
- /**
- * Adds bits handler attribute for bits to string method.
- *
- * @param attr attribute
- * @param type type
- * @param tempFiles temp fragment file
- */
- static void addBitsHandler(JavaAttributeInfo attr, YangType type,
- TempJavaFragmentFiles tempFiles) {
- BitsJavaInfoHandler handler
- = new BitsJavaInfoHandler(attr, type);
- tempFiles.getBitsHandler().add(handler);
- }
-
- /**
- * Adds attribute types import to leaf info container's parent.
- *
- * @param tempFiles temp java file
- * @param container leaf info container
- */
- private static void addImportForLeafInfo(TempJavaFragmentFiles tempFiles,
- JavaLeafInfoContainer container) {
- String containedInCls = getCapitalCase(tempFiles.getJavaFileInfo()
- .getJavaName());
- String containedInPkg = tempFiles.getJavaFileInfo().getPackage();
- JavaQualifiedTypeInfoTranslator info = new JavaQualifiedTypeInfoTranslator();
- if (container.getDataType().getDataType() == YangDataTypes.BITS) {
- //Add bitset import for type and leaf value flags.
- info = new JavaQualifiedTypeInfoTranslator();
- info.setClassInfo(BIT_SET);
- info.setPkgInfo(JAVA_UTIL_PKG);
- tempFiles.getJavaImportData().addImportInfo(info, containedInCls,
- containedInPkg);
- }
- tempFiles.getJavaImportData().addImportInfo(
- (JavaQualifiedTypeInfoTranslator) container
- .getJavaQualifiedInfo(), containedInCls, containedInPkg);
-
- }
-
- /**
- * Sets absolute path where the file needs to be generated.
- *
- * @param absoluteDirPath absolute path where the file needs to be
- * generated
- */
- protected void setAbsoluteDirPath(String absoluteDirPath) {
- this.absoluteDirPath = absoluteDirPath;
- }
-
- /**
- * Returns the generated java file information.
- *
- * @return generated java file information
- */
- protected JavaFileInfoTranslator getJavaFileInfo() {
- return javaFileInfo;
- }
-
- /**
- * Sets the generated java file information.
- *
- * @param javaFileInfo generated java file information
- */
- protected void setJavaFileInfo(JavaFileInfoTranslator javaFileInfo) {
- this.javaFileInfo = javaFileInfo;
- }
-
- /**
- * Returns the flag-set for generated temp files.
- *
- * @return flag-set
- */
- protected int getGeneratedTempFiles() {
- return tempFilesFlagSet;
- }
-
- /**
- * Adds to the flag-set for generated temp files.
- *
- * @param flags generated temp files flag-set
- */
- protected void addGeneratedTempFile(int flags) {
- tempFilesFlagSet |= flags;
- }
-
- /**
- * Returns the generated Java files.
- *
- * @return generated Java files
- */
- protected int getGeneratedJavaFiles() {
- return javaFileInfo.getGeneratedFileTypes();
- }
-
- /**
- * Retrieves the mapped Java class name.
- *
- * @return mapped Java class name
- */
- protected String getGeneratedJavaClassName() {
- return getCapitalCase(javaFileInfo.getJavaName());
- }
-
- /**
- * Retrieves the import data for the generated Java file.
- *
- * @return import data for the generated Java file
- */
- public JavaImportData getJavaImportData() {
- return javaImportData;
- }
-
- /**
- * Sets import data for the generated Java file.
- *
- * @param data import data for the generated Java file
- */
- protected void setJavaImportData(JavaImportData data) {
- javaImportData = data;
- }
-
- /**
- * Retrieves the status of any attributes added.
- *
- * @return status of any attributes added
- */
- protected boolean isAttributePresent() {
- return isAttributePresent;
- }
-
- /**
- * Returns getter methods's temporary file handle.
- *
- * @return temporary file handle
- */
- public File getGetterInterfaceTempFileHandle() {
- return getterInterfaceTempFileHandle;
- }
-
- /**
- * Returns setter method's temporary file handle.
- *
- * @return temporary file handle
- */
- public File getSetterInterfaceTempFileHandle() {
- return setterInterfaceTempFileHandle;
- }
-
- /**
- * Returns setter method's impl's temporary file handle.
- *
- * @return temporary file handle
- */
- public File getSetterImplTempFileHandle() {
- return setterImplTempFileHandle;
- }
-
- /**
- * Returns from string method's temporary file handle.
- *
- * @return from string method's temporary file handle
- */
- public File getFromStringImplTempFileHandle() {
- return fromStringImplTempFileHandle;
- }
-
- /**
- * Returns attribute's temporary file handle.
- *
- * @return temporary file handle
- */
- public File getAttributesTempFileHandle() {
- return attributesTempFileHandle;
- }
-
- /**
- * Returns getter method's impl's temporary file handle.
- *
- * @return temporary file handle
- */
- public File getGetterImplTempFileHandle() {
- return getterImplTempFileHandle;
- }
-
- /**
- * Returns hash code method's temporary file handle.
- *
- * @return temporary file handle
- */
- public File getHashCodeImplTempFileHandle() {
- return hashCodeImplTempFileHandle;
- }
-
- /**
- * Returns equals method's temporary file handle.
- *
- * @return temporary file handle
- */
- public File getEqualsImplTempFileHandle() {
- return equalsImplTempFileHandle;
- }
-
- /**
- * Returns to string method's temporary file handle.
- *
- * @return temporary file handle
- */
- public File getToStringImplTempFileHandle() {
- return toStringImplTempFileHandle;
- }
-
- /**
- * Returns java extends list holder.
- *
- * @return java extends list holder
- */
- public JavaExtendsListHolder getJavaExtendsListHolder() {
- return javaExtendsListHolder;
- }
-
- /**
- * Sets java extends list holder.
- *
- * @param holder java extends list holder
- */
- protected void setJavaExtendsListHolder(
- JavaExtendsListHolder holder) {
- javaExtendsListHolder = holder;
- }
-
- /**
- * Adds is filter content match for leaf.
- *
- * @param attr java attribute
- * @throws IOException when fails to do IO operations
- */
- private void addSubTreeFilteringForLeaf(JavaAttributeInfo attr)
- throws IOException {
- appendToFile(subtreeFilteringForLeafTempFileHandle,
- getSubtreeFilteringForLeaf(attr, attr.getAttributeType()) +
- NEW_LINE);
- }
-
- /**
- * Adds is filter content match for leaf-list.
- *
- * @param attr java attribute
- * @throws IOException when fails to do IO operations
- */
- private void addSubtreeFilteringForLeafList(JavaAttributeInfo attr)
- throws IOException {
- appendToFile(getSubtreeFilteringForListTempFileHandle,
- getSubtreeFilteringForLeafList(attr) + NEW_LINE);
- }
-
- /**
- * Adds is filter content match for nodes.
- *
- * @param attr java attribute
- * @throws IOException when fails to do IO operations
- */
- private void addSubtreeFilteringForChildNode(JavaAttributeInfo attr)
- throws IOException {
- appendToFile(getSubtreeFilteringForChildNodeTempFileHandle,
- getSubtreeFilteringForNode(attr) + NEW_LINE);
- }
-
- /**
- * Adds attribute for class.
- *
- * @param attr attribute info
- * @throws IOException when fails to append to temporary file
- */
- private void addAttribute(JavaAttributeInfo attr)
- throws IOException {
- appendToFile(attributesTempFileHandle, parseAttribute(attr));
- }
-
- /**
- * Adds getter for interface.
- *
- * @param attr attribute info
- * @throws IOException when fails to append to temporary file
- */
- private void addGetterForInterface(JavaAttributeInfo attr)
- throws IOException {
- appendToFile(getterInterfaceTempFileHandle,
- getGetterString(attr, getGeneratedJavaFiles()) +
- NEW_LINE);
- }
-
- /**
- * Adds setter for interface.
- *
- * @param attr attribute info
- * @throws IOException when fails to append to temporary file
- */
- private void addSetterForInterface(JavaAttributeInfo attr)
- throws IOException {
- appendToFile(setterInterfaceTempFileHandle,
- getSetterString(attr, getGeneratedJavaClassName(),
- getGeneratedJavaFiles()) +
- NEW_LINE);
- }
-
- /**
- * Adds setter's implementation for class.
- *
- * @param attr attribute info
- * @throws IOException when fails to append to temporary file
- */
- private void addSetterImpl(JavaAttributeInfo attr)
- throws IOException {
- String setter = getSetterForClass(attr, getGeneratedJavaClassName(),
- getGeneratedJavaFiles());
- if (rootNode) {
- appendToFile(setterImplTempFileHandle,
- getJavaDoc(SETTER_METHOD, attr.getAttributeName(),
- attr.isListAttr(), null) + setter);
- } else {
- appendToFile(setterImplTempFileHandle, getOverRideString() + setter);
- }
- }
-
- /**
- * Adds getter method's impl for class.
- *
- * @param attr attribute info
- * @throws IOException when fails to append to temporary file
- */
- protected void addGetterImpl(JavaAttributeInfo attr)
- throws IOException {
- String getter = getGetterForClass(attr, getGeneratedJavaFiles());
- if (javaFlagSet(BUILDER_CLASS_MASK)) {
- if (!rootNode) {
- appendToFile(getterImplTempFileHandle, getOverRideString() +
- getter);
- } else {
- appendToFile(getterImplTempFileHandle, getter);
- }
- } else {
- String appDataStructure = null;
- if (attr.getCompilerAnnotation() != null) {
- appDataStructure = attr.getCompilerAnnotation()
- .getYangAppDataStructure().getDataStructure().name();
- }
- appendToFile(getterImplTempFileHandle,
- getJavaDoc(GETTER_METHOD, attr.getAttributeName(),
- false, appDataStructure) + getter);
- }
- }
-
- /**
- * Adds add to list interface method.
- *
- * @param attr attribute
- * @throws IOException when fails to do IO operations
- */
- private void addAddToListInterface(JavaAttributeInfo attr)
- throws IOException {
- appendToFile(addToListInterfaceTempFileHandle,
- getJavaDoc(ADD_TO_LIST, attr.getAttributeName(), false,
- null) + getAddToListMethodInterface(
- attr, getGeneratedJavaClassName()) + NEW_LINE);
- }
-
- /**
- * Adds add to list interface method.
- *
- * @param attr attribute
- * @throws IOException when fails to do IO operations
- */
- private void addAddToListImpl(JavaAttributeInfo attr)
- throws IOException {
- appendToFile(addToListImplTempFileHandle,
- getAddToListMethodImpl(attr, getGeneratedJavaClassName(),
- rootNode) + NEW_LINE);
- }
-
- /**
- * Adds leaf identifier enum attributes.
- *
- * @param attr attribute
- * @param value value
- * @throws IOException when fails to do IO operations
- */
- private void addLeafIdAttributes(JavaAttributeInfo attr, int value)
- throws IOException {
- appendToFile(leafIdAttributeTempFileHandle, FOUR_SPACE_INDENTATION +
- generateEnumAttributeString(attr.getAttributeName(), value));
- }
-
- /**
- * Adds build method for interface.
- *
- * @return build method for interface
- * @throws IOException when fails to append to temporary file
- */
- protected String addBuildMethodForInterface()
- throws IOException {
- return parseBuilderInterfaceBuildMethodString(
- getGeneratedJavaClassName());
- }
-
- /**
- * Adds build method's implementation for class.
- *
- * @return build method implementation for class
- * @throws IOException when fails to append to temporary file
- */
- protected String addBuildMethodImpl()
- throws IOException {
- return getBuildString(getGeneratedJavaClassName(), rootNode) + NEW_LINE;
- }
-
- /**
- * Adds default constructor for class.
- *
- * @param modifier modifier for constructor
- * @param toAppend string which need to be appended with the class name
- * @param suffix is value need to be appended as suffix
- * @return default constructor for class
- * @throws IOException when fails to append to file
- */
- protected String addDefaultConstructor(String modifier, String toAppend,
- boolean suffix)
- throws IOException {
- StringBuilder name = new StringBuilder();
- name.append(getGeneratedJavaClassName());
- if (rootNode && !toAppend.equals(BUILDER)) {
- name.append(OP_PARAM);
- return getDefaultConstructorString(name.toString(), modifier);
- }
- if (suffix) {
- name.append(toAppend);
- return getDefaultConstructorString(name.toString(), modifier);
- }
- StringBuilder appended = new StringBuilder();
- if (toAppend.equals(DEFAULT)) {
- appended.append(getCapitalCase(toAppend));
- } else {
- appended.append(toAppend);
- }
- return NEW_LINE + getDefaultConstructorString(appended.append(
- name).toString(), modifier);
- // TODO getDefaultConstructorString to handle new line.
- }
-
- /**
- * Adds hash code method for class.
- *
- * @param attr attribute info
- * @throws IOException when fails to append to temporary file
- */
- private void addHashCodeMethod(JavaAttributeInfo attr)
- throws IOException {
- appendToFile(hashCodeImplTempFileHandle,
- getHashCodeMethod(attr) + NEW_LINE);
- }
-
- /**
- * Adds equals method for class.
- *
- * @param attr attribute info
- * @throws IOException when fails to append to temporary file
- */
- private void addEqualsMethod(JavaAttributeInfo attr)
- throws IOException {
- appendToFile(equalsImplTempFileHandle,
- getEqualsMethod(attr) + NEW_LINE);
- }
-
- /**
- * Adds ToString method for class.
- *
- * @param attr attribute info
- * @throws IOException when fails to append to temporary file
- */
- private void addToStringMethod(JavaAttributeInfo attr)
- throws IOException {
- appendToFile(toStringImplTempFileHandle,
- getToStringMethod(attr) + NEW_LINE);
- }
-
- /**
- * Adds from string method for union class.
- *
- * @param attr type attribute info
- * @param fromStringAttr from string attribute info
- * @param genClassName generated class name
- * @throws IOException when fails to append to temporary file
- */
- void addFromStringMethod(JavaAttributeInfo attr,
- JavaAttributeInfo fromStringAttr, String genClassName)
- throws IOException {
- appendToFile(fromStringImplTempFileHandle,
- getFromStringMethod(attr, fromStringAttr, genClassName) + NEW_LINE);
- }
-
- /**
- * Returns a temporary file handle for the specific file type.
- *
- * @param fileName file name
- * @return temporary file handle
- * @throws IOException when fails to create new file handle
- */
- protected File getTemporaryFileHandle(String fileName)
- throws IOException {
- String path = getTempDirPath(absoluteDirPath);
- File dir = new File(path);
- boolean isCreated;
- if (!dir.exists()) {
- isCreated = dir.mkdirs();
- if (!isCreated) {
- throw new IOException("failed to create temporary directory " +
- "for " + fileName);
- }
- }
- File file = new File(path + fileName + TEMP_FILE_EXTENSION);
- if (!file.exists()) {
- isCreated = file.createNewFile();
- if (!isCreated) {
- throw new IOException("failed to create temporary file for " +
- fileName);
- }
- } else {
- throw new IOException(fileName + " is reused due to YANG naming. " +
- "probably your previous build " +
- "would have failed");
- }
- return file;
- }
-
- /**
- * Returns a temporary file handle for the specific file type.
- *
- * @param fileName file name
- * @return temporary file handle
- * @throws IOException when fails to create new file handle
- */
- protected File getJavaFileHandle(String fileName)
- throws IOException {
- return getFileObject(getDirPath(), fileName, JAVA_FILE_EXTENSION,
- javaFileInfo);
- }
-
- /**
- * Returns data from the temporary files.
- *
- * @param file temporary file handle
- * @param absolutePath absolute path
- * @return stored data from temporary files
- * @throws IOException when failed to get data from the given file
- */
- public String getTemporaryDataFromFileHandle(File file, String absolutePath)
- throws IOException {
- String path = getTempDirPath(absolutePath);
- if (new File(path + file.getName()).exists()) {
- return readAppendFile(path + file.getName(), EMPTY_STRING);
- }
- throw new IOException("Unable to get data from the given " +
- file.getName() + " file for " +
- getGeneratedJavaClassName() + PERIOD);
- }
-
- /**
- * Returns temporary directory path.
- *
- * @param path absolute path
- * @return directory path
- */
- private String getTempDirPath(String path) {
- return getPackageDirPathFromJavaJPackage(path) + SLASH +
- getGeneratedJavaClassName() + TEMP_FOLDER_NAME_SUFFIX + SLASH;
- }
-
- /**
- * Parses attribute to get the attribute string.
- *
- * @param attr attribute info
- * @return attribute string
- */
- protected String parseAttribute(JavaAttributeInfo attr) {
- /*
- * TODO: check if this utility needs to be called or move to the caller
- */
- String attrName = attr.getAttributeName();
- String attrAccessType = PRIVATE;
- if ((getGeneratedJavaFiles() & GENERATE_INTERFACE_WITH_BUILDER) != 0) {
- attrAccessType = PROTECTED;
- }
- String pkg = null;
- if (attr.isQualifiedName()) {
- pkg = attr.getImportInfo().getPkgInfo();
- }
- return getJavaAttributeDefinition(
- pkg, attr.getImportInfo().getClassInfo(), attrName,
- attr.isListAttr(), attrAccessType, attr.getCompilerAnnotation());
- }
-
- /**
- * Appends content to temporary file.
- *
- * @param file temporary file
- * @param data data to be appended
- * @throws IOException when fails to append to file
- */
- protected void appendToFile(File file, String data)
- throws IOException {
- try {
- insertDataIntoJavaFile(file, data);
- } catch (IOException ex) {
- throw new IOException("failed to write in temp file.");
- }
- }
-
- /**
- * Adds parent's info to current node import list.
- *
- * @param curNode current node
- * @param config plugin configurations
- */
- protected void addParentInfoInCurNodeTempFile(YangNode curNode,
- YangPluginConfig config) {
- JavaQualifiedTypeInfoTranslator caseImportInfo =
- new JavaQualifiedTypeInfoTranslator();
- YangNode parent = getParentNodeInGenCode(curNode);
- if (curNode instanceof YangCase && parent instanceof YangAugment) {
- return;
- }
- if (!(parent instanceof JavaCodeGenerator)) {
- throw new TranslatorException(getErrorMsg(INVALID_PARENT_NODE, curNode));
- }
- if (!(curNode instanceof JavaFileInfoContainer)) {
- throw new TranslatorException(getErrorMsg(INVALID_NODE, curNode));
- }
- caseImportInfo.setClassInfo(
- getCapitalCase(getCamelCase(parent.getName(),
- config.getConflictResolver())));
- caseImportInfo.setPkgInfo(((JavaFileInfoContainer) parent).getJavaFileInfo()
- .getPackage());
-
- JavaFileInfoTranslator fileInfo =
- ((JavaFileInfoContainer) curNode).getJavaFileInfo();
-
- getBeanFiles(curNode).getJavaImportData().addImportInfo(
- caseImportInfo, getCapitalCase(fileInfo.getJavaName()),
- fileInfo.getPackage());
- }
-
- /**
- * Adds leaf attributes in generated files.
- *
- * @param entry JAVA leaf info container
- * @param config plugin config
- * @param curNode current node
- * @param leafList flag indicating whether leaf container is leafList
- * @throws IOException IO operation fail
- */
- private void addLeafInfoToTempFiles(JavaLeafInfoContainer entry,
- YangPluginConfig config,
- YangNode curNode,
- boolean leafList)
- throws IOException {
- if (entry != null) {
- if (curNode instanceof RpcNotificationContainer) {
- TempJavaBeanFragmentFiles tempFiles = getBeanFiles(curNode);
- addJavaSnippetInfoToApplicableTempFiles(
- getJavaAttributeOfLeaf(tempFiles, entry,
- config, leafList), config);
- } else {
- addJavaSnippetInfoToApplicableTempFiles(
- getJavaAttributeOfLeaf(this, entry,
- config, leafList), config);
- }
- }
- }
-
- /**
- * Adds all the leaves in the current data model node as part of the
- * generated temporary file.
- *
- * @param curNode current node
- * @param config plugin config
- * @throws IOException IO operation fail
- */
- protected void addCurNodeLeavesInfoToTempFiles(YangNode curNode,
- YangPluginConfig config)
- throws IOException {
- if (!(curNode instanceof YangLeavesHolder)) {
- throw new TranslatorException(getErrorMsg(INVALID_LEAF_HOLDER,
- curNode));
- }
- YangLeavesHolder leavesHolder = (YangLeavesHolder) curNode;
-
- for (YangLeaf leaf : leavesHolder.getListOfLeaf()) {
- addLeafInfoToTempFiles((JavaLeafInfoContainer) leaf, config,
- curNode, false);
- }
-
- for (YangLeafList leafList : leavesHolder.getListOfLeafList()) {
- addLeafInfoToTempFiles((JavaLeafInfoContainer) leafList, config,
- curNode, true);
- }
- }
-
- /**
- * Adds operation type to temp files.
- *
- * @param curNode current YANG node
- * @param config YANG plugin config
- * @throws IOException IO exception
- */
- protected void addOperationTypeToTempFiles(YangNode curNode,
- YangPluginConfig config)
- throws IOException {
- JavaQualifiedTypeInfoTranslator typeInfo =
- new JavaQualifiedTypeInfoTranslator();
- typeInfo.setClassInfo(OPERATION_TYPE_CLASS);
- typeInfo.setPkgInfo(((JavaFileInfoContainer) curNode).getJavaFileInfo()
- .getPackage());
- JavaAttributeInfo attributeInfo =
- getAttributeInfoForTheData(typeInfo, YANG + getCapitalCase(
- curNode.getJavaClassNameOrBuiltInType()) +
- OPERATION_TYPE_ATTRIBUTE, null, false, false);
- addJavaSnippetInfoToApplicableTempFiles(attributeInfo, config);
- }
-
- /**
- * Adds the new attribute info to the target generated temporary files.
- *
- * @param newAttrInfo new attribute info
- * @param pluginConfig plugin configurations
- * @throws IOException IO operation fail
- */
- void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo newAttrInfo,
- YangPluginConfig pluginConfig)
- throws IOException {
- isAttributePresent = true;
- if (tempFlagSet(ATTRIBUTES_MASK)) {
- addAttribute(newAttrInfo);
- }
- if (tempFlagSet(GETTER_FOR_INTERFACE_MASK)) {
- addGetterForInterface(newAttrInfo);
- }
- if (tempFlagSet(SETTER_FOR_INTERFACE_MASK)) {
- addSetterForInterface(newAttrInfo);
- }
- if (tempFlagSet(SETTER_FOR_CLASS_MASK)) {
- addSetterImpl(newAttrInfo);
- }
- if (tempFlagSet(HASH_CODE_IMPL_MASK)) {
- addHashCodeMethod(newAttrInfo);
- }
- if (tempFlagSet(EQUALS_IMPL_MASK)) {
- addEqualsMethod(newAttrInfo);
- }
- if (tempFlagSet(TO_STRING_IMPL_MASK)) {
- addToStringMethod(newAttrInfo);
- }
- if (tempFlagSet(EDIT_CONTENT_MASK)) {
- //TODO: add implementation for edit content match.
- }
- boolean listAttr = newAttrInfo.isListAttr();
- if (tempFlagSet(ADD_TO_LIST_IMPL_MASK) && listAttr) {
- addAddToListImpl(newAttrInfo);
- }
- if (tempFlagSet(ADD_TO_LIST_INTERFACE_MASK) && listAttr) {
- addAddToListInterface(newAttrInfo);
- }
- YangType attrType = newAttrInfo.getAttributeType();
- if (tempFlagSet(FILTER_CONTENT_MATCH_FOR_NODES_MASK) &&
- attrType == null && !newAttrInfo.getAttributeName()
- .contains(OPERATION_TYPE_ATTRIBUTE)) {
- addSubtreeFilteringForChildNode(newAttrInfo);
- }
- if (tempFlagSet(FILTER_CONTENT_MATCH_FOR_LEAF_MASK) &&
- !listAttr && attrType != null) {
- addSubTreeFilteringForLeaf(newAttrInfo);
- }
- if (tempFlagSet(FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK) &&
- listAttr && attrType != null) {
- addSubtreeFilteringForLeafList(newAttrInfo);
- }
- if (tempFlagSet(LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK) &&
- !listAttr && attrType != null) {
- leafCount++;
- addLeafIdAttributes(newAttrInfo, leafCount);
- }
- if (!newAttrInfo.isIntConflict() && !newAttrInfo.isLongConflict() &&
- !newAttrInfo.isShortConflict()) {
- if (tempFlagSet(GETTER_FOR_CLASS_MASK)) {
- addGetterImpl(newAttrInfo);
- }
- if (tempFlagSet(FROM_STRING_IMPL_MASK)) {
- JavaQualifiedTypeInfoTranslator typeInfo =
- getQualifiedInfoOfFromString(newAttrInfo,
- pluginConfig.getConflictResolver());
- /*
- * Create a new java attribute info with qualified information of
- * wrapper classes.
- */
- JavaAttributeInfo fromStringAttributeInfo =
- getAttributeInfoForTheData(
- typeInfo, newAttrInfo.getAttributeName(),
- attrType, getIsQualifiedAccessOrAddToImportList(
- typeInfo), false);
- addFromStringMethod(newAttrInfo, fromStringAttributeInfo,
- getGeneratedJavaClassName());
- }
- }
- }
-
- /**
- * Returns JAVA class name for non implementation classes.
- *
- * @param suffix for the class name based on the file type
- * @return java class name
- */
- protected String getJavaClassName(String suffix) {
- return getCapitalCase(javaFileInfo.getJavaName()) + suffix;
- }
-
- /**
- * Returns class name for implementation classes.
- *
- * @param node YANG node
- * @return java class name
- */
- private String getImplClassName(YangNode node) {
- if (node instanceof RpcNotificationContainer) {
- return getGeneratedJavaClassName() + OP_PARAM;
- }
- return DEFAULT_CAPS + getGeneratedJavaClassName();
- }
-
- /**
- * Returns the directory path.
- *
- * @return directory path
- */
- private String getDirPath() {
- return javaFileInfo.getPackageFilePath();
- }
-
- /**
- * Constructs java code exit.
- *
- * @param fileType generated file type
- * @param curNode current YANG node
- * @throws IOException when fails to generate java files
- */
- public void generateJavaFile(int fileType, YangNode curNode)
- throws IOException {
- List<String> imports =
- getBeanFiles(curNode).getJavaImportData().getImports();
- if (curNode instanceof YangAugmentableNode) {
- addImportsForAugmentableClass(imports, true, true, curNode);
- }
- createPackage(curNode);
-
- //Generate java code.
- if ((fileType & INTERFACE_MASK) != 0 ||
- (fileType & BUILDER_INTERFACE_MASK) != 0) {
-
- //Create interface file.
- interfaceJavaFileHandle =
- getJavaFileHandle(getJavaClassName(INTERFACE_FILE_NAME_SUFFIX));
- interfaceJavaFileHandle =
- generateInterfaceFile(interfaceJavaFileHandle, imports,
- curNode, isAttributePresent);
- if (!(curNode instanceof RpcNotificationContainer)) {
-
- //Create builder interface file.
- if ((fileType & BUILDER_INTERFACE_MASK) != 0) {
- builderInterfaceJavaFileHandle =
- getJavaFileHandle(getJavaClassName(
- BUILDER_INTERFACE_FILE_NAME_SUFFIX));
- builderInterfaceJavaFileHandle =
- generateBuilderInterfaceFile(
- builderInterfaceJavaFileHandle,
- curNode, isAttributePresent);
- /*
- * Append builder interface file to interface file and
- * close it.
- */
- mergeJavaFiles(builderInterfaceJavaFileHandle,
- interfaceJavaFileHandle);
- }
- }
- insertDataIntoJavaFile(interfaceJavaFileHandle, CLOSE_CURLY_BRACKET);
- validateLineLength(interfaceJavaFileHandle);
- if (curNode instanceof YangAugmentableNode) {
- addImportsForAugmentableClass(imports, false, true, curNode);
- }
- }
- if ((fileType & BUILDER_CLASS_MASK) != 0 ||
- (fileType & DEFAULT_CLASS_MASK) != 0) {
- if (isAttributePresent) {
- addImportsToStringAndHasCodeMethods(imports, true);
- addArrayListImport(imports);
- }
-
- addBitsAndBase64Imports(curNode, imports);
- if (curNode instanceof YangAugmentableNode) {
- addImportsForAugmentableClass(imports, true, false, curNode);
- addInvocationExceptionImport(imports);
- }
- sortImports(imports);
-
- //Create impl class file.
- implClassJavaFileHandle =
- getJavaFileHandle(getImplClassName(curNode));
- implClassJavaFileHandle =
- generateDefaultClassFile(implClassJavaFileHandle,
- curNode, isAttributePresent,
- imports);
-
- //Create builder class file.
- if ((fileType & BUILDER_CLASS_MASK) != 0) {
- builderClassJavaFileHandle =
- getJavaFileHandle(getJavaClassName(
- BUILDER_CLASS_FILE_NAME_SUFFIX));
- builderClassJavaFileHandle =
- generateBuilderClassFile(builderClassJavaFileHandle,
- curNode,
- isAttributePresent);
-
- //Append impl class to builder class and close it.
- mergeJavaFiles(builderClassJavaFileHandle,
- implClassJavaFileHandle);
- }
- insertDataIntoJavaFile(implClassJavaFileHandle, CLOSE_CURLY_BRACKET);
- validateLineLength(implClassJavaFileHandle);
- }
- //Close all the file handles.
- freeTemporaryResources(false);
- }
-
- //Adds import for array list.
- private void addArrayListImport(List<String> imports) {
- if (imports.contains(javaImportData.getImportForList())) {
- imports.add(ARRAY_LIST_IMPORT);
- }
- }
-
- //Adds import for bitset and base64 list.
- private void addBitsAndBase64Imports(YangNode curNode, List<String> imports) {
- if (curNode instanceof YangLeavesHolder) {
- YangLeavesHolder holder = (YangLeavesHolder) curNode;
- String impt = this.getJavaImportData()
- .getImportForToBitSet();
- if (!holder.getListOfLeaf().isEmpty() &&
- !imports.contains(impt)) {
- imports.add(impt);
- }
- }
- }
-
- /**
- * Adds imports for ToString and HashCodeMethod.
- *
- * @param imports import list
- * @param operation add or remove
- */
- protected void addImportsToStringAndHasCodeMethods(List<String> imports,
- boolean operation) {
- if (operation) {
- imports.add(javaImportData.getImportForHashAndEquals());
- imports.add(javaImportData.getImportForToString());
- } else {
- imports.remove(javaImportData.getImportForHashAndEquals());
- imports.remove(javaImportData.getImportForToString());
- }
- // TODO change boolean to OPERATION, in all related places.
- }
-
- /**
- * Adds import for map and hash map.
- *
- * @param imports import list
- * @param operations true for adding and false for deletion
- * @param isInterfaceFile if need to add in interface file
- * @param curNode current node
- */
- private void addImportsForAugmentableClass(List<String> imports,
- boolean operations,
- boolean isInterfaceFile,
- YangNode curNode) {
- if (operations) {
- if (!isInterfaceFile) {
- imports.add(javaImportData.getHashMapImport());
- }
- // Add import for hash map only if node is not a YANG choice.
- if (!(curNode instanceof YangChoice)) {
- imports.add(javaImportData.getMapImport());
- }
- } else {
- if (!isInterfaceFile) {
- imports.remove(javaImportData.getHashMapImport());
- }
- imports.remove(javaImportData.getMapImport());
- }
- sortImports(imports);
- }
-
- /**
- * Adds invocation exception import.
- *
- * @param imports list of imports
- */
- private void addInvocationExceptionImport(List<String> imports) {
- imports.add(INVOCATION_TARGET_EXCEPTION_IMPORT);
- }
-
- /**
- * Removes all temporary file handles.
- *
- * @param errorOccurred flag indicating if error occurred
- * @throws IOException when failed to delete the temporary files
- */
- public void freeTemporaryResources(boolean errorOccurred)
- throws IOException {
- /*
- * Close all java file handles and when error occurs delete the files.
- */
- if (javaFlagSet(INTERFACE_MASK)) {
- closeFile(interfaceJavaFileHandle, errorOccurred);
- }
- if (javaFlagSet(BUILDER_CLASS_MASK)) {
- closeFile(builderClassJavaFileHandle);
- }
- if (javaFlagSet(BUILDER_INTERFACE_MASK)) {
- closeFile(builderInterfaceJavaFileHandle);
- }
- if (javaFlagSet(DEFAULT_CLASS_MASK)) {
- closeFile(implClassJavaFileHandle, errorOccurred);
- }
- /*
- * Close all temporary file handles and delete the files.
- */
- if (tempFlagSet(GETTER_FOR_CLASS_MASK)) {
- closeFile(getterImplTempFileHandle);
- }
- if (tempFlagSet(ATTRIBUTES_MASK)) {
- closeFile(attributesTempFileHandle);
- }
- if (tempFlagSet(HASH_CODE_IMPL_MASK)) {
- closeFile(hashCodeImplTempFileHandle);
- }
- if (tempFlagSet(TO_STRING_IMPL_MASK)) {
- closeFile(toStringImplTempFileHandle);
- }
- if (tempFlagSet(EQUALS_IMPL_MASK)) {
- closeFile(equalsImplTempFileHandle);
- }
- if (tempFlagSet(FROM_STRING_IMPL_MASK)) {
- closeFile(fromStringImplTempFileHandle);
- }
- if (tempFlagSet(ADD_TO_LIST_IMPL_MASK)) {
- closeFile(addToListImplTempFileHandle);
- }
- if (tempFlagSet(ADD_TO_LIST_INTERFACE_MASK)) {
- closeFile(addToListInterfaceTempFileHandle);
- }
- if (tempFlagSet(LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK)) {
- closeFile(leafIdAttributeTempFileHandle);
- }
- if (tempFlagSet(FILTER_CONTENT_MATCH_FOR_LEAF_MASK)) {
- closeFile(subtreeFilteringForLeafTempFileHandle);
- }
- if (tempFlagSet(FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK)) {
- closeFile(getSubtreeFilteringForListTempFileHandle);
- }
- if (tempFlagSet(FILTER_CONTENT_MATCH_FOR_NODES_MASK)) {
- closeFile(getSubtreeFilteringForChildNodeTempFileHandle);
- }
- if (tempFlagSet(EDIT_CONTENT_MASK)) {
- closeFile(editContentTempFileHandle);
- }
- }
-
- /**
- * Returns if the attribute needs to be accessed in a qualified manner or
- * not, if it needs to be imported, then the same needs to be done.
- *
- * @param importInfo import info
- * @return status of the qualified access to the attribute
- */
- protected boolean getIsQualifiedAccessOrAddToImportList(
- JavaQualifiedTypeInfo importInfo) {
- return javaImportData
- .addImportInfo((JavaQualifiedTypeInfoTranslator) importInfo,
- getGeneratedJavaClassName(),
- javaFileInfo.getPackage());
- }
-
- /**
- * Returns temp file handle for add to list interface.
- *
- * @return temp file handle for add to list interface
- */
- public File getAddToListInterfaceTempFileHandle() {
- return addToListInterfaceTempFileHandle;
- }
-
- /**
- * Returns temp file handle for add to list impl.
- *
- * @return temp file handle for add to list impl
- */
- public File getAddToListImplTempFileHandle() {
- return addToListImplTempFileHandle;
- }
-
- /**
- * Returns temp file handle for leaf identifier attributes.
- *
- * @return temp file handle for leaf identifier attributes
- */
- public File getLeafIdAttributeTempFileHandle() {
- return leafIdAttributeTempFileHandle;
- }
-
- /**
- * Sets true if root node.
- *
- * @param rootNode true if root node
- */
- void setRootNode(boolean rootNode) {
- this.rootNode = rootNode;
- }
-
- /**
- * Returns temp file for is content match.
- *
- * @return temp file for is content match
- */
- public File getSubtreeFilteringForLeafTempFileHandle() {
- return subtreeFilteringForLeafTempFileHandle;
- }
-
- /**
- * Returns temp file for edit content file.
- *
- * @return temp file for edit content file
- */
- public File getEditContentTempFileHandle() {
- return editContentTempFileHandle;
- }
-
- /**
- * Returns temp file for is content match.
- *
- * @return temp file for is content match
- */
- public File getGetSubtreeFilteringForListTempFileHandle() {
- return getSubtreeFilteringForListTempFileHandle;
- }
-
- /**
- * Returns temp file for is content match.
- *
- * @return temp file for is content match
- */
- public File getGetSubtreeFilteringForChildNodeTempFileHandle() {
- return getSubtreeFilteringForChildNodeTempFileHandle;
- }
-
- /**
- * Checks if a given flag is set in generated java files.
- * Returns true if ANY flag is set in a bitwise-ORed argument, e.g.
- * <pre>
- * javaFlagSet(FOO | BAR)
- * </pre>
- * returns true if either FOO flag or BAR flag is set.
- *
- * @param flag input flag mask value
- * @return true if set, else false
- */
- private boolean javaFlagSet(int flag) {
- return (getGeneratedJavaFiles() & flag) != 0;
- }
-
- /**
- * Checks if a given flag is set in temp files.
- *
- * @param flag input flag mask value
- * @return true if set, else false
- */
- private boolean tempFlagSet(int flag) {
- return (tempFilesFlagSet & flag) != 0;
- }
-
- /**
- * Returns list of bits attributes.
- *
- * @return list of bits attributes
- */
- public List<BitsJavaInfoHandler> getBitsHandler() {
- return bitsHandler;
- }
-
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaServiceFragmentFiles.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaServiceFragmentFiles.java
deleted file mode 100644
index 1751ab5..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaServiceFragmentFiles.java
+++ /dev/null
@@ -1,287 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.translator.tojava;
-
-import org.onosproject.yangutils.datamodel.RpcNotificationContainer;
-import org.onosproject.yangutils.datamodel.YangAugment;
-import org.onosproject.yangutils.datamodel.YangInput;
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.YangOutput;
-import org.onosproject.yangutils.datamodel.YangRpc;
-import org.onosproject.yangutils.translator.exception.TranslatorException;
-import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModuleTranslator;
-import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaSubModuleTranslator;
-import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.List;
-
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_INTERFACE_MASK;
-import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData;
-import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator.getQualifiedTypeInfoOfCurNode;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.addListenersImport;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateServiceInterfaceFile;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.addResolvedAugmentedDataNodeImports;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.createPackage;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRpcServiceMethod;
-import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.Operation.ADD;
-import static org.onosproject.yangutils.utils.UtilConstants.RPC_INPUT_VAR_NAME;
-import static org.onosproject.yangutils.utils.UtilConstants.SERVICE;
-import static org.onosproject.yangutils.utils.UtilConstants.VOID;
-import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.closeFile;
-import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateJavaDocForRpc;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
-
-/**
- * Represents implementation of java service code fragments temporary
- * implementations. Maintains the temp files required specific for service
- * and manager java snippet generation.
- */
-public class TempJavaServiceFragmentFiles extends TempJavaFragmentFiles {
-
- /**
- * File name for rpc method.
- */
- private static final String RPC_INTERFACE_FILE_NAME = "Rpc";
-
- /**
- * Temporary file handle for rpc interface.
- */
- private final File rpcInterfaceTempFileHandle;
-
- /**
- * Java file handle for rpc interface file.
- */
- private File serviceJavaFileHandle;
-
- /**
- * Creates an instance of temporary java code fragment.
- *
- * @param javaFileInfo generated file information
- * @throws IOException when fails to create new file handle
- */
- TempJavaServiceFragmentFiles(JavaFileInfoTranslator javaFileInfo)
- throws IOException {
- setJavaExtendsListHolder(new JavaExtendsListHolder());
- setJavaImportData(new JavaImportData());
- setJavaFileInfo(javaFileInfo);
- setAbsoluteDirPath(getAbsolutePackagePath(
- getJavaFileInfo().getBaseCodeGenPath(),
- getJavaFileInfo().getPackageFilePath()));
- addGeneratedTempFile(RPC_INTERFACE_MASK);
- rpcInterfaceTempFileHandle = getTemporaryFileHandle(RPC_INTERFACE_FILE_NAME);
- }
-
- /**
- * Returns rpc method's temporary file handle.
- *
- * @return temporary file handle
- */
- public File getRpcInterfaceTempFileHandle() {
- return rpcInterfaceTempFileHandle;
- }
-
- /**
- * Constructs java code exit.
- *
- * @param fileType generated file type
- * @param curNode current YANG node
- * @throws IOException when fails to generate java files
- */
- @Override
- public void generateJavaFile(int fileType, YangNode curNode)
- throws IOException {
-
- addResolvedAugmentedDataNodeImports(curNode);
- List<String> imports = ((JavaCodeGeneratorInfo) curNode)
- .getTempJavaCodeFragmentFiles().getServiceTempFiles()
- .getJavaImportData().getImports();
- createPackage(curNode);
- boolean notification = false;
- if (curNode instanceof YangJavaModuleTranslator) {
- if (!((YangJavaModuleTranslator) curNode).getNotificationNodes()
- .isEmpty()) {
- notification = true;
- }
- } else if (curNode instanceof YangJavaSubModuleTranslator) {
- if (!((YangJavaSubModuleTranslator) curNode).getNotificationNodes()
- .isEmpty()) {
- notification = true;
- }
- }
-
- if (notification) {
- addListenersImport(curNode, imports, ADD);
- }
-
- serviceJavaFileHandle = getJavaFileHandle(getJavaClassName(SERVICE));
- generateServiceInterfaceFile(serviceJavaFileHandle, curNode, imports);
-
- // Close all the file handles.
- freeTemporaryResources(false);
- }
-
- /**
- * Adds rpc string information to applicable temp file.
- *
- * @param inAttr RPCs input node attribute info
- * @param outAttr RPCs output node attribute info
- * @param rpcName name of the rpc function
- * @throws IOException IO operation fail
- */
- private void addRpcString(JavaAttributeInfo inAttr, JavaAttributeInfo outAttr,
- String rpcName) throws IOException {
- String rpcInput = EMPTY_STRING;
- String rpcOutput = VOID;
- String rpcIn = EMPTY_STRING;
- if (inAttr != null) {
- rpcInput = getCapitalCase(inAttr.getAttributeName());
- }
- if (outAttr != null) {
- rpcOutput = getCapitalCase(outAttr.getAttributeName());
- }
- if (!rpcInput.equals(EMPTY_STRING)) {
- rpcIn = RPC_INPUT_VAR_NAME;
- }
- appendToFile(rpcInterfaceTempFileHandle,
- generateJavaDocForRpc(rpcName, rpcIn, rpcOutput) +
- getRpcServiceMethod(rpcName, rpcInput, rpcOutput));
- }
-
- /**
- * Adds the JAVA rpc snippet information.
- *
- * @param inAttr RPCs input node attribute info
- * @param outAttr RPCs output node attribute info
- * @param rpcName name of the rpc function
- * @throws IOException IO operation fail
- */
- public void addJavaSnippetInfoToApplicableTempFiles(JavaAttributeInfo inAttr,
- JavaAttributeInfo outAttr,
- String rpcName)
- throws IOException {
- addRpcString(inAttr, outAttr, rpcName);
- }
-
- /**
- * Creates an attribute info object corresponding to a data model node and
- * return it.
- *
- * @param childNode child data model node(input / output) for which the java code generation
- * is being handled
- * @param parentNode parent node (module / sub-module) in which the child node is an attribute
- * @return AttributeInfo attribute details required to add in temporary
- * files
- */
- public JavaAttributeInfo getChildNodeAsAttributeInParentService(
- YangNode childNode, YangNode parentNode) {
-
- String childNodeName = ((JavaFileInfoContainer) childNode)
- .getJavaFileInfo().getJavaName();
- /*
- * Get the import info corresponding to the attribute for import in
- * generated java files or qualified access
- */
- JavaQualifiedTypeInfoTranslator qualifiedTypeInfo =
- getQualifiedTypeInfoOfCurNode(childNode,
- getCapitalCase(childNodeName));
- if (!(parentNode instanceof TempJavaCodeFragmentFilesContainer)) {
- throw new TranslatorException("Parent node does not have file info");
- }
-
- boolean isQualified = addImportToService(qualifiedTypeInfo, parentNode);
- return getAttributeInfoForTheData(qualifiedTypeInfo, childNodeName,
- null, isQualified, false);
- }
-
- /**
- * Adds to service class import list.
- *
- * @param importInfo import info
- * @return true or false
- */
- private boolean addImportToService(
- JavaQualifiedTypeInfoTranslator importInfo, YangNode curNode) {
- JavaFileInfoTranslator fileInfo = ((JavaFileInfoContainer) curNode)
- .getJavaFileInfo();
- String name = fileInfo.getJavaName();
- String clsInfo = importInfo.getClassInfo();
-
- StringBuilder className = new StringBuilder()
- .append(getCapitalCase(name))
- .append(SERVICE);
- return clsInfo.contentEquals(SERVICE) || clsInfo.contentEquals(className) ||
- getJavaImportData().addImportInfo(importInfo, className.toString(),
- fileInfo.getPackage());
- }
-
- /**
- * Adds augmented rpc methods to service temp file.
- *
- * @param module root node
- * @throws IOException when fails to do IO operations
- */
- public void addAugmentedRpcMethod(RpcNotificationContainer module)
- throws IOException {
- JavaAttributeInfo in = null;
- JavaAttributeInfo out = null;
- YangNode rpcChild;
- YangRpc rpc;
- YangInput input;
- for (YangAugment info : module.getAugmentList()) {
- input = (YangInput) info.getAugmentedNode();
-
- if (input != null) {
- rpc = (YangRpc) input.getParent();
- rpcChild = rpc.getChild();
- while (rpcChild != null) {
- if (rpcChild instanceof YangInput) {
- in = getChildNodeAsAttributeInParentService(
- rpcChild, (YangNode) module);
- }
- if (rpcChild instanceof YangOutput) {
- out = getChildNodeAsAttributeInParentService(
- rpcChild, (YangNode) module);
- }
- rpcChild = rpcChild.getChild();
- }
- addJavaSnippetInfoToApplicableTempFiles(in, out, rpc
- .getJavaClassNameOrBuiltInType());
- }
- }
- }
-
- /**
- * Removes all temporary file handles.
- *
- * @param errorOccurred flag indicating error
- * @throws IOException when failed to delete the temporary files
- */
- @Override
- public void freeTemporaryResources(boolean errorOccurred)
- throws IOException {
- closeFile(serviceJavaFileHandle, errorOccurred);
- closeFile(rpcInterfaceTempFileHandle);
- closeFile(getGetterInterfaceTempFileHandle());
- closeFile(getSetterInterfaceTempFileHandle());
- closeFile(getSetterImplTempFileHandle());
- super.freeTemporaryResources(errorOccurred);
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaTypeFragmentFiles.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaTypeFragmentFiles.java
deleted file mode 100644
index a30ed4b..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/TempJavaTypeFragmentFiles.java
+++ /dev/null
@@ -1,953 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.translator.tojava;
-
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.YangType;
-import org.onosproject.yangutils.datamodel.YangTypeHolder;
-import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
-import org.onosproject.yangutils.translator.exception.TranslatorException;
-import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaTypeTranslator;
-import org.onosproject.yangutils.utils.io.YangPluginConfig;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BITS;
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT16;
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT32;
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT64;
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.UINT16;
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.UINT32;
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.UINT8;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_FOR_TYPE_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FROM_STRING_IMPL_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.OF_STRING_IMPL_MASK;
-import static org.onosproject.yangutils.translator.tojava.JavaAttributeInfo.getAttributeInfoForTheData;
-import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator.getQualifiedInfoOfFromString;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateTypeDefClassFile;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator.generateUnionClassFile;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.createPackage;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getOfMethodStringAndJavaDoc;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getTypeConstructorStringAndJavaDoc;
-import static org.onosproject.yangutils.translator.tojava.utils.ValidatorTypeForUnionTypes.INT_TYPE_CONFLICT;
-import static org.onosproject.yangutils.translator.tojava.utils.ValidatorTypeForUnionTypes.LONG_TYPE_CONFLICT;
-import static org.onosproject.yangutils.translator.tojava.utils.ValidatorTypeForUnionTypes.SHORT_TYPE_CONFLICT;
-import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
-import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.closeFile;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
-
-/**
- * Represents implementation of java data type code fragments temporary implementations. Maintains the temp files
- * required specific for user defined data type java snippet generation.
- */
-//TODO: Update with multi type handler framework.
-public class TempJavaTypeFragmentFiles
- extends TempJavaFragmentFiles {
-
- /**
- * File name for of string method.
- */
- private static final String OF_STRING_METHOD_FILE_NAME = "OfString";
-
- /**
- * File name for construction for special type like union, typedef.
- */
- private static final String CONSTRUCTOR_FOR_TYPE_FILE_NAME = "ConstructorForType";
-
- /**
- * Integer index in type list.
- */
- private int intIndex = 0;
-
- /**
- * UInt index in type list.
- */
- private int uIntIndex = 0;
-
- /**
- * long index in type list.
- */
- private int longIndex = 0;
-
- /**
- * ULong index in type list.
- */
- private int uLongIndex = 0;
-
- /**
- * short index in type list.
- */
- private int shortIndex = 0;
-
- /**
- * Uint8 index in type list.
- */
- private int uInt8Index = 0;
-
- /**
- * Temporary file handle for of string method of class.
- */
- private File ofStringImplTempFileHandle;
-
- /**
- * Temporary file handle for constructor for type class.
- */
- private File constructorForTypeTempFileHandle;
-
- /**
- * Java file handle for typedef class file.
- */
- private File typedefClassJavaFileHandle;
-
- /**
- * Java file handle for type class like union, typedef file.
- */
- private File typeClassJavaFileHandle;
-
- /**
- * Java attribute for int.
- */
- private JavaAttributeInfo intAttribute;
-
- /**
- * Java attribute for long.
- */
- private JavaAttributeInfo longAttribute;
-
- /**
- * Java attribute for short.
- */
- private JavaAttributeInfo shortAttribute;
-
- /**
- * Java attribute for uint8.
- */
- private JavaAttributeInfo uInt8Attribute;
-
- /**
- * Java attribute for uInt.
- */
- private JavaAttributeInfo uIntAttribute;
-
- /**
- * Java attribute for uLong.
- */
- private JavaAttributeInfo uLongAttribute;
-
- private List<YangType<?>> local = new ArrayList<>();
-
- /**
- * Creates an instance of temporary java code fragment.
- *
- * @param javaFileInfo generated java file info
- * @throws IOException when fails to create new file handle
- */
- TempJavaTypeFragmentFiles(JavaFileInfoTranslator javaFileInfo)
- throws IOException {
-
- super(javaFileInfo);
-
- /*
- * Initialize getterImpl, attributes, hash code, equals and to strings
- * when generation file type matches to typeDef class mask.
- */
- addGeneratedTempFile(OF_STRING_IMPL_MASK | CONSTRUCTOR_FOR_TYPE_MASK |
- FROM_STRING_IMPL_MASK);
-
- ofStringImplTempFileHandle = getTemporaryFileHandle(
- OF_STRING_METHOD_FILE_NAME);
- constructorForTypeTempFileHandle = getTemporaryFileHandle(
- CONSTRUCTOR_FOR_TYPE_FILE_NAME);
-
- }
-
- /**
- * Returns type class constructor method's temporary file handle.
- *
- * @return type class constructor method's temporary file handle
- */
-
- public File getConstructorForTypeTempFileHandle() {
- return constructorForTypeTempFileHandle;
- }
-
- /**
- * Returns java file handle for typedef class file.
- *
- * @return java file handle for typedef class file
- */
- private File getTypedefClassJavaFileHandle() {
- return typedefClassJavaFileHandle;
- }
-
- /**
- * Sets the java file handle for typedef class file.
- *
- * @param typedefClassJavaFileHandle java file handle
- */
- private void setTypedefClassJavaFileHandle(File typedefClassJavaFileHandle) {
- this.typedefClassJavaFileHandle = typedefClassJavaFileHandle;
- }
-
- /**
- * Returns java file handle for type class file.
- *
- * @return java file handle for type class file
- */
- private File getTypeClassJavaFileHandle() {
- return typeClassJavaFileHandle;
- }
-
- /**
- * Sets the java file handle for type class file.
- *
- * @param typeClassJavaFileHandle type file handle
- */
- private void setTypeClassJavaFileHandle(File typeClassJavaFileHandle) {
- this.typeClassJavaFileHandle = typeClassJavaFileHandle;
- }
-
- /**
- * Returns of string method's temporary file handle.
- *
- * @return of string method's temporary file handle
- */
-
- public File getOfStringImplTempFileHandle() {
- return ofStringImplTempFileHandle;
- }
-
- /**
- * Adds all the type in the current data model node as part of the generated temporary file.
- *
- * @param yangTypeHolder YANG java data model node which has type info, eg union / typedef
- * @param config plugin configurations for naming conventions
- * @throws IOException IO operation fail
- */
- void addTypeInfoToTempFiles(YangTypeHolder yangTypeHolder, YangPluginConfig config)
- throws IOException {
-
- List<YangType<?>> typeList = yangTypeHolder.getTypeList();
- if (typeList != null) {
- List<YangType<?>> types = validateTypes(typeList);
- for (YangType<?> type : types) {
- if (!(type instanceof YangJavaTypeTranslator)) {
- throw new TranslatorException(
- "Type does not have Java info " + type
- .getDataTypeName() + " in " + type
- .getLineNumber() + " at " + type
- .getCharPosition() + " in " +
- type.getFileName());
- }
- JavaAttributeInfo javaAttributeInfo = getAttributeForType(type,
- config);
- if (type.getDataType() == BITS) {
- addBitsHandler(javaAttributeInfo, type, this);
- }
- addJavaSnippetInfoToApplicableTempFiles(javaAttributeInfo,
- config, types);
- }
- addTypeConstructor();
- addMethodsInConflictCase(config);
- }
- }
-
- /**
- * Returns java attribute.
- *
- * @param type YANG type
- * @param config plugin configurations
- * @return java attribute
- */
- private JavaAttributeInfo getAttributeForType(YangType type,
- YangPluginConfig config) {
- YangJavaTypeTranslator javaType = (YangJavaTypeTranslator) type;
- javaType.updateJavaQualifiedInfo(config.getConflictResolver());
- String typeName = getCamelCase(javaType.getDataTypeName(), config
- .getConflictResolver());
- return getAttributeInfoForTheData(
- javaType.getJavaQualifiedInfo(), typeName, javaType,
- getIsQualifiedAccessOrAddToImportList(
- javaType.getJavaQualifiedInfo()), false);
- }
-
- /**
- * Adds the new attribute info to the target generated temporary files for union class.
- *
- * @param attr the attribute info that needs to be added to temporary files
- * @param config plugin configurations
- * @param types type list
- * @throws IOException IO operation fail
- */
- private void addJavaSnippetInfoToApplicableTempFiles(
- JavaAttributeInfo attr, YangPluginConfig config, List<YangType<?>> types)
- throws IOException {
-
- YangDataTypes attrType = attr.getAttributeType().getDataType();
-
- if (attrType == INT16 || attrType == UINT8) {
- boolean isShortConflict = validateForConflictingShortTypes(types);
- attr.setShortConflict(isShortConflict);
- updateAttributeCondition(attr);
- if (!isShortConflict) {
- addMethodsWhenNoConflictingTypes(attr, config, types);
- }
- } else if (attrType == INT32 || attrType == UINT16) {
- boolean isIntConflict = validateForConflictingIntTypes(types);
- attr.setIntConflict(isIntConflict);
- updateAttributeCondition(attr);
- if (!isIntConflict) {
- addMethodsWhenNoConflictingTypes(attr, config, types);
- }
- } else if (attrType == INT64 || attrType == UINT32) {
- boolean isLongConflict = validateForConflictingLongTypes(types);
- attr.setLongConflict(isLongConflict);
- updateAttributeCondition(attr);
- if (!isLongConflict) {
- addMethodsWhenNoConflictingTypes(attr, config, types);
- }
- } else {
- addMethodsWhenNoConflictingTypes(attr, config, types);
- }
- super.addJavaSnippetInfoToApplicableTempFiles(attr, config);
-
- }
-
- private List<YangType<?>> validateTypes(List<YangType<?>> types) {
- String curType;
- List<String> preType = new ArrayList<>();
- for (YangType type : types) {
- curType = type.getDataTypeName();
- if (!preType.contains(curType)) {
- preType.add(curType);
- local.add(type);
- }
- }
- return local;
- }
-
- /**
- * Adds of method and constructor when there is no conflicting types.
- *
- * @param javaAttributeInfo java attribute info
- * @param pluginConfig plugin configurations
- * @param types YANG type
- * @throws IOException when fails to do IO operations
- */
- private void addMethodsWhenNoConflictingTypes(JavaAttributeInfo javaAttributeInfo,
- YangPluginConfig pluginConfig, List<YangType<?>> types)
- throws IOException {
- if ((getGeneratedTempFiles() & OF_STRING_IMPL_MASK) != 0) {
- addOfStringMethod(javaAttributeInfo, pluginConfig);
- }
-
- if ((getGeneratedTempFiles() & CONSTRUCTOR_FOR_TYPE_MASK) != 0) {
- addTypeConstructor(javaAttributeInfo, types.indexOf
- (javaAttributeInfo.getAttributeType()));
- }
- }
-
- /**
- * Adds of, getter and from string method in conflict cases.
- *
- * @param pluginConfig plugin configurations
- * @throws IOException when fails to do IO operations
- */
- private void addMethodsInConflictCase(YangPluginConfig pluginConfig)
- throws IOException {
- JavaAttributeInfo attr = getIntAttribute();
- if (attr != null) {
- attr = getUIntAttribute();
- }
- if (attr != null) {
- if (attr.isIntConflict()) {
- if (getIntIndex() < getUIntIndex()) {
- appendToFile(getOfStringImplTempFileHandle(), getOfMethodStringAndJavaDoc(getIntAttribute(),
- getGeneratedJavaClassName())
- + NEW_LINE);
- addGetterImpl(getIntAttribute());
- addFromStringMethod(getIntAttribute(), pluginConfig);
- } else {
- appendToFile(getOfStringImplTempFileHandle(), getOfMethodStringAndJavaDoc(getUIntAttribute(),
- getGeneratedJavaClassName())
- + NEW_LINE);
- addGetterImpl(getUIntAttribute());
- addFromStringMethod(getUIntAttribute(), pluginConfig);
- }
- }
- }
- attr = getLongAttribute();
- if (attr != null) {
- attr = getULongAttribute();
- }
- if (attr != null) {
- if (attr.isLongConflict()) {
- if (getLongIndex() < getULongIndex()) {
- appendToFile(getOfStringImplTempFileHandle(), getOfMethodStringAndJavaDoc(getLongAttribute(),
- getGeneratedJavaClassName())
- + NEW_LINE);
- addGetterImpl(getLongAttribute());
- addFromStringMethod(getLongAttribute(), pluginConfig);
- } else {
- appendToFile(getOfStringImplTempFileHandle(), getOfMethodStringAndJavaDoc(getULongAttribute(),
- getGeneratedJavaClassName())
- + NEW_LINE);
- addGetterImpl(getULongAttribute());
- addFromStringMethod(getULongAttribute(), pluginConfig);
- }
- }
- }
-
- attr = getShortAttribute();
- if (attr != null) {
- attr = getUInt8Attribute();
- }
- if (attr != null) {
- if (attr.isShortConflict()) {
- if (getShortIndex() < getUInt8Index()) {
- appendToFile(getOfStringImplTempFileHandle(), getOfMethodStringAndJavaDoc(getShortAttribute(),
- getGeneratedJavaClassName())
- + NEW_LINE);
- addGetterImpl(getShortAttribute());
- addFromStringMethod(getShortAttribute(), pluginConfig);
- } else {
- appendToFile(getOfStringImplTempFileHandle(), getOfMethodStringAndJavaDoc(getUInt8Attribute(),
- getGeneratedJavaClassName())
- + NEW_LINE);
- addGetterImpl(getUInt8Attribute());
- addFromStringMethod(getUInt8Attribute(), pluginConfig);
- }
- }
- }
- }
-
- /**
- * Adds from string method for conflict case.
- *
- * @param newAttrInfo new attribute
- * @param pluginConfig plugin configurations
- * @throws IOException when fails to do IO operations
- */
- private void addFromStringMethod(JavaAttributeInfo newAttrInfo, YangPluginConfig pluginConfig)
- throws IOException {
-
- JavaQualifiedTypeInfoTranslator qualifiedInfoOfFromString = getQualifiedInfoOfFromString(newAttrInfo,
- pluginConfig.getConflictResolver());
- /*
- * Create a new java attribute info with qualified information of
- * wrapper classes.
- */
- JavaAttributeInfo fromStringAttributeInfo = getAttributeInfoForTheData(qualifiedInfoOfFromString,
- newAttrInfo.getAttributeName(),
- newAttrInfo.getAttributeType(),
- getIsQualifiedAccessOrAddToImportList(qualifiedInfoOfFromString), false);
-
- addFromStringMethod(newAttrInfo, fromStringAttributeInfo, getGeneratedJavaClassName());
- }
-
- /**
- * Adds type constructor.
- *
- * @param attr attribute info
- * @param count count of types
- * @throws IOException when fails to append to temporary file
- */
- private void addTypeConstructor(JavaAttributeInfo attr, int count)
- throws IOException {
- appendToFile(getConstructorForTypeTempFileHandle(),
- getTypeConstructorStringAndJavaDoc(
- attr, getGeneratedJavaClassName(), getGeneratedJavaFiles(), count)
- + NEW_LINE);
- }
-
- /**
- * Adds type constructor.
- *
- * @throws IOException when fails to append to temporary file
- */
- private void addTypeConstructor()
- throws IOException {
- JavaAttributeInfo attr = getIntAttribute();
- if (attr != null) {
- attr = getUIntAttribute();
- }
- boolean index = getIntIndex() < getUIntIndex();
- int count;
- if (index) {
- count = getIntIndex();
- } else {
- count = getUIntIndex();
- }
- if (attr != null) {
- if (attr.isIntConflict()) {
- appendToFile(getConstructorForTypeTempFileHandle(), getTypeConstructorStringAndJavaDoc(
- getIntAttribute(),
- getUIntAttribute(), getGeneratedJavaClassName(), INT_TYPE_CONFLICT,
- index, count) + NEW_LINE);
- }
- }
- attr = getLongAttribute();
- if (attr != null) {
- attr = getULongAttribute();
- }
- index = getLongIndex() < getULongIndex();
- if (index) {
- count = getLongIndex();
- } else {
- count = getULongIndex();
- }
- if (attr != null) {
- if (attr.isLongConflict()) {
- appendToFile(getConstructorForTypeTempFileHandle(), getTypeConstructorStringAndJavaDoc(
- getLongAttribute(),
- getULongAttribute(), getGeneratedJavaClassName(), LONG_TYPE_CONFLICT,
- index, count) + NEW_LINE);
- }
- }
- attr = getShortAttribute();
- if (attr != null) {
- attr = getUInt8Attribute();
- }
- index = getShortIndex() < getUInt8Index();
- if (index) {
- count = getShortIndex();
- } else {
- count = getUInt8Index();
- }
- if (attr != null) {
- if (attr.isShortConflict()) {
- appendToFile(getConstructorForTypeTempFileHandle(), getTypeConstructorStringAndJavaDoc(
- getShortAttribute(),
- getUInt8Attribute(), getGeneratedJavaClassName(), SHORT_TYPE_CONFLICT,
- index, count) + NEW_LINE);
- }
- }
- }
-
- /**
- * Adds of string for type.
- *
- * @param attr attribute info
- * @param pluginConfig plugin configurations
- * @throws IOException when fails to append to temporary file
- */
- private void addOfStringMethod(JavaAttributeInfo attr, YangPluginConfig pluginConfig)
- throws IOException {
- appendToFile(getOfStringImplTempFileHandle(), getOfMethodStringAndJavaDoc(attr,
- getGeneratedJavaClassName())
- + NEW_LINE);
- }
-
- /**
- * Removes all temporary file handles.
- *
- * @param isErrorOccurred flag to tell translator that error has occurred while file generation
- * @throws IOException when failed to delete the temporary files
- */
- @Override
- public void freeTemporaryResources(boolean isErrorOccurred)
- throws IOException {
-
- if ((getGeneratedJavaFiles() & GENERATE_TYPEDEF_CLASS) != 0 ||
- (getGeneratedJavaFiles() & GENERATE_UNION_CLASS) != 0) {
- closeFile(typeClassJavaFileHandle, isErrorOccurred);
- }
-
- if ((getGeneratedTempFiles() & CONSTRUCTOR_FOR_TYPE_MASK) != 0) {
- closeFile(constructorForTypeTempFileHandle, true);
- }
- if ((getGeneratedTempFiles() & OF_STRING_IMPL_MASK) != 0) {
- closeFile(ofStringImplTempFileHandle, true);
- }
- if ((getGeneratedTempFiles() & FROM_STRING_IMPL_MASK) != 0) {
- closeFile(getFromStringImplTempFileHandle(), true);
- }
-
- super.freeTemporaryResources(isErrorOccurred);
-
- }
-
- /**
- * Constructs java code exit.
- *
- * @param fileType generated file type
- * @param curNode current YANG node
- * @throws IOException when fails to generate java files
- */
- @Override
- public void generateJavaFile(int fileType, YangNode curNode)
- throws IOException {
- List<String> imports = new ArrayList<>();
- if (isAttributePresent()) {
- imports = getJavaImportData().getImports();
- }
-
- createPackage(curNode);
- addImportsToStringAndHasCodeMethods(imports, true);
-
- /*
- * Creates type def class file.
- */
- if ((fileType & GENERATE_TYPEDEF_CLASS) != 0) {
- setTypedefClassJavaFileHandle(getJavaFileHandle(
- getJavaClassName(EMPTY_STRING)));
- generateTypeDefClassFile(getTypedefClassJavaFileHandle(), curNode, imports);
- }
- String bit = getJavaImportData().getImportForToBitSet();
- if (!imports.contains(bit)) {
- imports.add(bit);
- }
- /*
- * Creates type class file.
- */
- if ((fileType & GENERATE_UNION_CLASS) != 0) {
- setTypeClassJavaFileHandle(getJavaFileHandle(
- getJavaClassName(EMPTY_STRING)));
- generateUnionClassFile(getTypeClassJavaFileHandle(), curNode, imports);
- }
-
- /*
- * Close all the file handles.
- */
- freeTemporaryResources(false);
- }
-
- /**
- * Returns short type index from type list.
- *
- * @return short type index from type list
- */
- public int getShortIndex() {
- return shortIndex;
- }
-
- /**
- * Sets short type index from type list.
- *
- * @param shortIndex short type index from type list.
- */
- private void setShortIndex(int shortIndex) {
- this.shortIndex = shortIndex;
- }
-
- /**
- * Returns uInt type index from type list.
- *
- * @return uInt type index from type list
- */
- public int getUInt8Index() {
- return uInt8Index;
- }
-
- /**
- * Sets uInt8 type index from type list.
- *
- * @param uInt8Index uInt8 type index from type list.
- */
- private void setUInt8Index(int uInt8Index) {
- this.uInt8Index = uInt8Index;
- }
-
- /**
- * Returns int type index from type list.
- *
- * @return int type index from type list
- */
- public int getIntIndex() {
- return intIndex;
- }
-
- /**
- * Sets int type index from type list.
- *
- * @param intIndex int type index from type list.
- */
- private void setIntIndex(int intIndex) {
- this.intIndex = intIndex;
- }
-
- /**
- * Returns uInt type index from type list.
- *
- * @return uInt type index from type list
- */
- public int getUIntIndex() {
- return uIntIndex;
- }
-
- /**
- * Sets uInt type index from type list.
- *
- * @param uIntIndex uInt type index from type list.
- */
- private void setUIntIndex(int uIntIndex) {
- this.uIntIndex = uIntIndex;
- }
-
- /**
- * Returns long type index from type list.
- *
- * @return long type index from type list
- */
- public int getLongIndex() {
- return longIndex;
- }
-
- /**
- * Sets long type index from type list.
- *
- * @param longIndex long type index from type list.
- */
- private void setLongIndex(int longIndex) {
- this.longIndex = longIndex;
- }
-
- /**
- * Returns uLong type index from type list.
- *
- * @return uLong type index from type list
- */
- public int getULongIndex() {
- return uLongIndex;
- }
-
- /**
- * Sets uLong type index from type list.
- *
- * @param uLongIndex uLong type index from type list.
- */
- private void setULongIndex(int uLongIndex) {
- this.uLongIndex = uLongIndex;
- }
-
- /**
- * Validates conflict for int and uInt.
- *
- * @param typeList type list
- * @return true if conflict is there
- */
- private boolean validateForConflictingIntTypes(List<YangType<?>> typeList) {
- boolean isIntPresent = false;
- boolean isUIntPresent = false;
- for (YangType type : typeList) {
- if (type.getDataType().equals(INT32)) {
- setIntIndex(typeList.indexOf(type));
- isIntPresent = true;
- }
- if (type.getDataType().equals(UINT16)) {
- setUIntIndex(typeList.indexOf(type));
- isUIntPresent = true;
- }
- }
-
- return isIntPresent && isUIntPresent;
- }
-
- /**
- * Validates conflict for int and uInt.
- *
- * @param typeList type list
- * @return true if conflict is there
- */
- private boolean validateForConflictingShortTypes(List<YangType<?>> typeList) {
- boolean isShortPresent = false;
- boolean isUInt8Present = false;
- for (YangType type : typeList) {
- if (type.getDataType().equals(INT16)) {
- setShortIndex(typeList.indexOf(type));
- isShortPresent = true;
- }
- if (type.getDataType().equals(UINT8)) {
- setUInt8Index(typeList.indexOf(type));
- isUInt8Present = true;
- }
- }
-
- return isShortPresent && isUInt8Present;
- }
-
- /**
- * Validates conflict for long and uLong.
- *
- * @param typeList type list
- * @return true if conflict is there
- */
- private boolean validateForConflictingLongTypes(List<YangType<?>> typeList) {
- boolean isLongPresent = false;
- boolean isULongPresent = false;
- for (YangType type : typeList) {
- if (type.getDataType().equals(INT64)) {
- setLongIndex(typeList.indexOf(type));
- isLongPresent = true;
- }
- if (type.getDataType().equals(UINT32)) {
- setULongIndex(typeList.indexOf(type));
- isULongPresent = true;
- }
- }
-
- return isLongPresent && isULongPresent;
- }
-
- /**
- * Updates attribute info in case of conflicts.
- *
- * @param javaAttributeInfo java attribute info
- */
- private void updateAttributeCondition(JavaAttributeInfo javaAttributeInfo) {
-
- if (javaAttributeInfo.isIntConflict()) {
- if (javaAttributeInfo.getAttributeType().getDataType() == UINT16) {
- setUIntAttribute(javaAttributeInfo);
- } else if (javaAttributeInfo.getAttributeType().getDataType() == INT32) {
- setIntAttribute(javaAttributeInfo);
- }
-
- }
- if (javaAttributeInfo.isLongConflict()) {
- if (javaAttributeInfo.getAttributeType().getDataType() == UINT32) {
- setULongAttribute(javaAttributeInfo);
- } else if (javaAttributeInfo.getAttributeType().getDataType() == INT64) {
- setLongAttribute(javaAttributeInfo);
- }
-
- }
- if (javaAttributeInfo.isShortConflict()) {
- if (javaAttributeInfo.getAttributeType().getDataType() == UINT8) {
- setUInt8Attribute(javaAttributeInfo);
- } else if (javaAttributeInfo.getAttributeType().getDataType() == INT16) {
- setShortAttribute(javaAttributeInfo);
- }
-
- }
- }
-
- /**
- * Returns attribute for int.
- *
- * @return attribute for int
- */
- public JavaAttributeInfo getIntAttribute() {
- return intAttribute;
- }
-
- /**
- * Sets attribute for int.
- *
- * @param intAttribute attribute for int
- */
- private void setIntAttribute(JavaAttributeInfo intAttribute) {
- this.intAttribute = intAttribute;
- }
-
- /**
- * Returns attribute for long.
- *
- * @return attribute for long
- */
- public JavaAttributeInfo getLongAttribute() {
- return longAttribute;
- }
-
- /**
- * Sets attribute for long.
- *
- * @param longAttribute attribute for long
- */
- private void setLongAttribute(JavaAttributeInfo longAttribute) {
- this.longAttribute = longAttribute;
- }
-
- /**
- * Returns attribute for uInt.
- *
- * @return attribute for uInt
- */
- public JavaAttributeInfo getUIntAttribute() {
- return uIntAttribute;
- }
-
- /**
- * Sets attribute for uInt.
- *
- * @param uIntAttribute attribute for uInt
- */
- private void setUIntAttribute(JavaAttributeInfo uIntAttribute) {
- this.uIntAttribute = uIntAttribute;
- }
-
- /**
- * Returns attribute for uLong.
- *
- * @return attribute for uLong
- */
- public JavaAttributeInfo getULongAttribute() {
- return uLongAttribute;
- }
-
- /**
- * Sets attribute for uLong.
- *
- * @param uLongAttribute attribute for uLong
- */
- private void setULongAttribute(JavaAttributeInfo uLongAttribute) {
- this.uLongAttribute = uLongAttribute;
- }
-
- /**
- * Returns attribute for uInt8.
- *
- * @return attribute for uInt8
- */
- public JavaAttributeInfo getUInt8Attribute() {
- return uInt8Attribute;
- }
-
- /**
- * Sets attribute for uInt8.
- *
- * @param uInt8Attribute attribute for uInt8
- */
- private void setUInt8Attribute(JavaAttributeInfo uInt8Attribute) {
- this.uInt8Attribute = uInt8Attribute;
- }
-
- /**
- * Returns attribute for short.
- *
- * @return attribute for short
- */
- public JavaAttributeInfo getShortAttribute() {
- return shortAttribute;
- }
-
- /**
- * Sets attribute for short.
- *
- * @param shortAttribute attribute for short
- */
- private void setShortAttribute(JavaAttributeInfo shortAttribute) {
- this.shortAttribute = shortAttribute;
- }
-
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/YangDataModelFactory.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/YangDataModelFactory.java
deleted file mode 100644
index 9af1352..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/YangDataModelFactory.java
+++ /dev/null
@@ -1,429 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.yangutils.translator.tojava;
-
-import org.onosproject.yangutils.datamodel.YangAugment;
-import org.onosproject.yangutils.datamodel.YangCase;
-import org.onosproject.yangutils.datamodel.YangChoice;
-import org.onosproject.yangutils.datamodel.YangContainer;
-import org.onosproject.yangutils.datamodel.YangGrouping;
-import org.onosproject.yangutils.datamodel.YangIdentity;
-import org.onosproject.yangutils.datamodel.YangInput;
-import org.onosproject.yangutils.datamodel.YangLeaf;
-import org.onosproject.yangutils.datamodel.YangLeafList;
-import org.onosproject.yangutils.datamodel.YangList;
-import org.onosproject.yangutils.datamodel.YangModule;
-import org.onosproject.yangutils.datamodel.YangNotification;
-import org.onosproject.yangutils.datamodel.YangOutput;
-import org.onosproject.yangutils.datamodel.YangRpc;
-import org.onosproject.yangutils.datamodel.YangSubModule;
-import org.onosproject.yangutils.datamodel.YangType;
-import org.onosproject.yangutils.datamodel.YangTypeDef;
-import org.onosproject.yangutils.datamodel.YangUnion;
-import org.onosproject.yangutils.datamodel.YangUses;
-import org.onosproject.yangutils.datamodel.utils.GeneratedLanguage;
-import org.onosproject.yangutils.translator.exception.TranslatorException;
-import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaChoiceTranslator;
-import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaContainerTranslator;
-import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaEnumerationTranslator;
-import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaListTranslator;
-import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModuleTranslator;
-import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaNotificationTranslator;
-import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaOutputTranslator;
-import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaRpcTranslator;
-import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaSubModuleTranslator;
-import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaTypeTranslator;
-import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaTypeDefTranslator;
-import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaUnionTranslator;
-import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaUsesTranslator;
-import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaAugmentTranslator;
-import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaCaseTranslator;
-import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaGroupingTranslator;
-import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaIdentityTranslator;
-import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaInputTranslator;
-import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaLeafTranslator;
-import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaLeafListTranslator;
-
-/**
- * Represents factory to create data model objects based on the target file type.
- */
-public final class YangDataModelFactory {
-
- /**
- * Creates a YANG data model factory object.
- */
- private YangDataModelFactory() {
- }
-
- /**
- * Based on the target language generate the inherited data model node.
- *
- * @param targetLanguage target language in which YANG mapping needs to be
- * generated
- * @return the corresponding inherited node based on the target language
- */
- public static YangModule getYangModuleNode(GeneratedLanguage targetLanguage) {
- switch (targetLanguage) {
- case JAVA_GENERATION: {
- return new YangJavaModuleTranslator();
- }
- default: {
- throw new TranslatorException("Only YANG to Java is supported.");
- }
- }
- }
-
- /**
- * Returns based on the target language generate the inherited data model node.
- *
- * @param targetLanguage target language in which YANG mapping needs to be
- * generated
- * @return the corresponding inherited node based on the target language
- */
- public static YangAugment getYangAugmentNode(GeneratedLanguage targetLanguage) {
- switch (targetLanguage) {
- case JAVA_GENERATION: {
- return new YangJavaAugmentTranslator();
- }
- default: {
- throw new TranslatorException("Only YANG to Java is supported.");
- }
- }
- }
-
- /**
- * Returns based on the target language generate the inherited data model node.
- *
- * @param targetLanguage target language in which YANG mapping needs to be
- * generated
- * @return the corresponding inherited node based on the target language
- */
- public static YangCase getYangCaseNode(GeneratedLanguage targetLanguage) {
- switch (targetLanguage) {
- case JAVA_GENERATION: {
- return new YangJavaCaseTranslator();
- }
- default: {
- throw new TranslatorException("Only YANG to Java is supported.");
- }
- }
- }
-
- /**
- * Returns based on the target language generate the inherited data model node.
- *
- * @param targetLanguage target language in which YANG mapping needs to be
- * generated
- * @return the corresponding inherited node based on the target language
- */
- public static YangChoice getYangChoiceNode(GeneratedLanguage targetLanguage) {
- switch (targetLanguage) {
- case JAVA_GENERATION: {
- return new YangJavaChoiceTranslator();
- }
- default: {
- throw new TranslatorException("Only YANG to Java is supported.");
- }
- }
- }
-
- /**
- * Returns based on the target language generate the inherited data model node.
- *
- * @param targetLanguage target language in which YANG mapping needs to be
- * generated
- * @return the corresponding inherited node based on the target language
- */
- public static YangContainer getYangContainerNode(GeneratedLanguage targetLanguage) {
- switch (targetLanguage) {
- case JAVA_GENERATION: {
- return new YangJavaContainerTranslator();
- }
- default: {
- throw new TranslatorException("Only YANG to Java is supported.");
- }
- }
- }
-
- /**
- * Returns based on the target language generate the inherited data model node.
- *
- * @param targetLanguage target language in which YANG mapping needs to be
- * generated
- * @return the corresponding inherited node based on the target language
- */
- public static YangIdentity getYangIdentityNode(GeneratedLanguage targetLanguage) {
- switch (targetLanguage) {
- case JAVA_GENERATION: {
- return new YangJavaIdentityTranslator();
- }
- default: {
- throw new TranslatorException("Only YANG to Java is supported.");
- }
- }
- }
-
- /**
- * Returns based on the target language generate the inherited data model node.
- *
- * @param targetLanguage target language in which YANG mapping needs to be
- * generated
- * @return the corresponding inherited node based on the target language
- */
- public static YangGrouping getYangGroupingNode(GeneratedLanguage targetLanguage) {
- switch (targetLanguage) {
- case JAVA_GENERATION: {
- return new YangJavaGroupingTranslator();
- }
- default: {
- throw new TranslatorException("Only YANG to Java is supported.");
- }
- }
- }
-
- /**
- * Returns based on the target language generate the inherited data model node.
- *
- * @param targetLanguage target language in which YANG mapping needs to be
- * generated
- * @return the corresponding inherited node based on the target language
- */
- public static YangList getYangListNode(GeneratedLanguage targetLanguage) {
- switch (targetLanguage) {
- case JAVA_GENERATION: {
- return new YangJavaListTranslator();
- }
- default: {
- throw new TranslatorException("Only YANG to Java is supported.");
- }
- }
- }
-
- /**
- * Returns based on the target language generate the inherited data model node.
- *
- * @param targetLanguage target language in which YANG mapping needs to be
- * generated
- * @return the corresponding inherited node based on the target language
- */
- public static YangSubModule getYangSubModuleNode(GeneratedLanguage targetLanguage) {
- switch (targetLanguage) {
- case JAVA_GENERATION: {
- return new YangJavaSubModuleTranslator();
- }
- default: {
- throw new TranslatorException("Only YANG to Java is supported.");
- }
- }
- }
-
- /**
- * Returns based on the target language generate the inherited data model node.
- *
- * @param targetLanguage target language in which YANG mapping needs to be
- * generated
- * @return the corresponding inherited node based on the target language
- */
- public static YangTypeDef getYangTypeDefNode(GeneratedLanguage targetLanguage) {
- switch (targetLanguage) {
- case JAVA_GENERATION: {
- return new YangJavaTypeDefTranslator();
- }
- default: {
- throw new TranslatorException("Only YANG to Java is supported.");
- }
- }
- }
-
- /**
- * Returns based on the target language generate the inherited data model node.
- *
- * @param targetLanguage target language in which YANG mapping needs to be
- * generated
- * @return the corresponding inherited node based on the target language
- */
- public static YangUnion getYangUnionNode(GeneratedLanguage targetLanguage) {
- switch (targetLanguage) {
- case JAVA_GENERATION: {
- return new YangJavaUnionTranslator();
- }
- default: {
- throw new TranslatorException("Only YANG to Java is supported.");
- }
- }
- }
-
- /**
- * Returns based on the target language generate the inherited data model node.
- *
- * @param targetLanguage target language in which YANG mapping needs to be
- * generated
- * @return the corresponding inherited node based on the target language
- */
- public static YangUses getYangUsesNode(GeneratedLanguage targetLanguage) {
- switch (targetLanguage) {
- case JAVA_GENERATION: {
- return new YangJavaUsesTranslator();
- }
- default: {
- throw new TranslatorException("Only YANG to Java is supported.");
- }
- }
- }
-
- /**
- * Returns based on the target language generate the inherited data model node.
- *
- * @param targetLanguage target language in which YANG mapping needs to be
- * generated
- * @return the corresponding inherited node based on the target language
- */
- public static YangNotification getYangNotificationNode(GeneratedLanguage targetLanguage) {
- switch (targetLanguage) {
- case JAVA_GENERATION: {
- return new YangJavaNotificationTranslator();
- }
- default: {
- throw new TranslatorException("Only YANG to Java is supported.");
- }
- }
- }
-
- /**
- * Returns based on the target language generate the inherited data model node.
- *
- * @param targetLanguage target language in which YANG mapping needs to be
- * generated
- * @return the corresponding inherited node based on the target language
- */
- public static YangLeaf getYangLeaf(GeneratedLanguage targetLanguage) {
- switch (targetLanguage) {
- case JAVA_GENERATION: {
- return new YangJavaLeafTranslator();
- }
- default: {
- throw new RuntimeException("Only YANG to Java is supported.");
- }
- }
- }
-
- /**
- * Returns based on the target language generate the inherited data model node.
- *
- * @param targetLanguage target language in which YANG mapping needs to be
- * generated
- * @return the corresponding inherited node based on the target language
- */
- public static YangLeafList getYangLeafList(GeneratedLanguage targetLanguage) {
- switch (targetLanguage) {
- case JAVA_GENERATION: {
- return new YangJavaLeafListTranslator();
- }
- default: {
- throw new RuntimeException("Only YANG to Java is supported.");
- }
- }
- }
-
- /**
- * Returns based on the target language generate the inherited data model node.
- *
- * @param targetLanguage target language in which YANG mapping needs to be
- * generated
- * @return the corresponding inherited node based on the target language
- */
- public static YangRpc getYangRpcNode(GeneratedLanguage targetLanguage) {
- switch (targetLanguage) {
- case JAVA_GENERATION: {
- return new YangJavaRpcTranslator();
- }
- default: {
- throw new TranslatorException("Only YANG to Java is supported.");
- }
- }
- }
-
- /**
- * Returns based on the target language generate the inherited data model node.
- *
- * @param targetLanguage target language in which YANG mapping needs to be
- * generated
- * @return the corresponding inherited node based on the target language
- */
- public static YangInput getYangInputNode(GeneratedLanguage targetLanguage) {
- switch (targetLanguage) {
- case JAVA_GENERATION: {
- return new YangJavaInputTranslator();
- }
- default: {
- throw new TranslatorException("Only YANG to Java is supported.");
- }
- }
- }
-
- /**
- * Returns based on the target language generate the inherited data model node.
- *
- * @param targetLanguage target language in which YANG mapping needs to be
- * generated
- * @return the corresponding inherited node based on the target language
- */
- public static YangOutput getYangOutputNode(GeneratedLanguage targetLanguage) {
- switch (targetLanguage) {
- case JAVA_GENERATION: {
- return new YangJavaOutputTranslator();
- }
- default: {
- throw new TranslatorException("Only YANG to Java is supported.");
- }
- }
- }
-
- /**
- * Returns based on the target language generate the inherited data model node.
- *
- * @param targetLanguage target language in which YANG mapping needs to be
- * generated
- * @return the corresponding inherited node based on the target language
- */
- public static YangJavaEnumerationTranslator getYangEnumerationNode(GeneratedLanguage targetLanguage) {
- switch (targetLanguage) {
- case JAVA_GENERATION: {
- return new YangJavaEnumerationTranslator();
- }
- default: {
- throw new TranslatorException("Only YANG to Java is supported.");
- }
- }
- }
- /**
- * Returns based on the target language generate the inherited data model node.
- *
- * @param targetLanguage target language in which YANG mapping needs to be
- * generated
- * @return the corresponding inherited node based on the target language
- */
- public static YangType getYangType(GeneratedLanguage targetLanguage) {
- switch (targetLanguage) {
- case JAVA_GENERATION: {
- return new YangJavaTypeTranslator();
- }
- default: {
- throw new RuntimeException("Only YANG to Java is supported.");
- }
- }
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/YangJavaModelUtils.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/YangJavaModelUtils.java
deleted file mode 100644
index 2c019f6..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/YangJavaModelUtils.java
+++ /dev/null
@@ -1,685 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.translator.tojava;
-
-import org.onosproject.yangutils.datamodel.RpcNotificationContainer;
-import org.onosproject.yangutils.datamodel.YangAtomicPath;
-import org.onosproject.yangutils.datamodel.YangAugment;
-import org.onosproject.yangutils.datamodel.YangCase;
-import org.onosproject.yangutils.datamodel.YangChoice;
-import org.onosproject.yangutils.datamodel.YangGrouping;
-import org.onosproject.yangutils.datamodel.YangLeavesHolder;
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
-import org.onosproject.yangutils.datamodel.YangSchemaNode;
-import org.onosproject.yangutils.datamodel.YangTranslatorOperatorNode;
-import org.onosproject.yangutils.datamodel.YangTypeHolder;
-import org.onosproject.yangutils.datamodel.utils.DataModelUtils;
-import org.onosproject.yangutils.translator.exception.TranslatorException;
-import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaAugmentTranslator;
-import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaEnumerationTranslator;
-import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaInputTranslator;
-import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaModuleTranslator;
-import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaOutputTranslator;
-import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaSubModuleTranslator;
-import org.onosproject.yangutils.utils.io.YangPluginConfig;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.isRpcChildNodePresent;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
-import static org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles.addCurNodeInfoInParentTempFile;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
-import static org.onosproject.yangutils.translator.tojava.utils.TranslatorErrorType.INVALID_NODE;
-import static org.onosproject.yangutils.translator.tojava.utils.TranslatorErrorType.INVALID_PARENT_NODE;
-import static org.onosproject.yangutils.translator.tojava.utils.TranslatorErrorType.INVALID_TRANSLATION_NODE;
-import static org.onosproject.yangutils.translator.tojava.utils.TranslatorUtils.getBeanFiles;
-import static org.onosproject.yangutils.translator.tojava.utils.TranslatorUtils.getErrorMsg;
-import static org.onosproject.yangutils.translator.tojava.utils.TranslatorUtils.getErrorMsgForCodeGenerator;
-import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED;
-import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.INPUT_KEYWORD;
-import static org.onosproject.yangutils.utils.UtilConstants.OUTPUT_KEYWORD;
-import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getPackageDirPathFromJavaJPackage;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast;
-
-/**
- * Represents utility class for YANG java model.
- */
-public final class YangJavaModelUtils {
-
- // No instantiation.
- private YangJavaModelUtils() {
- }
-
- /**
- * Updates YANG java file package information.
- *
- * @param info YANG java file info node
- * @param config YANG plugin config
- */
- public static void updatePackageInfo(JavaCodeGeneratorInfo info,
- YangPluginConfig config) {
-
- JavaFileInfoTranslator translator = info.getJavaFileInfo();
-
- if (info instanceof YangJavaAugmentTranslator) {
- updatePackageForAugmentInfo(info, config);
- } else {
- setNodeJavaName(info, config);
- translator.setJavaAttributeName(info.getJavaFileInfo()
- .getJavaName());
- translator.setPackage(getCurNodePackage((YangNode) info));
- }
- updateCommonPackageInfo(translator, info, config);
- }
-
- /**
- * The java name for input, output is prefixed with rpc name and other
- * nodes are set by taking its own name from YANG.
- *
- * @param info YANG java file info node
- * @param config YANG plugin config
- */
- private static void setNodeJavaName(JavaCodeGeneratorInfo info,
- YangPluginConfig config) {
- String javaGenName;
- if (info instanceof YangJavaInputTranslator) {
- javaGenName = ((YangJavaInputTranslator) info).getParent().getName() +
- INPUT_KEYWORD;
- } else if (info instanceof YangJavaOutputTranslator) {
- javaGenName = ((YangJavaOutputTranslator) info).getParent().getName() +
- OUTPUT_KEYWORD;
- } else {
- javaGenName = ((YangNode) info).getName();
- }
- info.getJavaFileInfo().setJavaName(getCamelCase(
- javaGenName, config.getConflictResolver()));
- }
-
- /**
- * Updates YANG java file package information.
- *
- * @param info YANG java file info node
- * @param config YANG plugin config
- */
- private static void updatePackageForAugmentInfo(JavaCodeGeneratorInfo info,
- YangPluginConfig config) {
-
- JavaFileInfoTranslator translator = info.getJavaFileInfo();
-
- translator.setJavaName(getAugmentClassName(
- (YangJavaAugmentTranslator) info, config));
- translator.setPackage(getAugmentsNodePackage((YangNode) info, config));
- updateCommonPackageInfo(translator, info, config);
- }
-
- /**
- * Returns package for augment node.
- *
- * @param yangNode augment node
- * @param config plugin configurations
- * @return package for augment node
- */
- private static String getAugmentsNodePackage(YangNode yangNode,
- YangPluginConfig config) {
- YangAugment augment = (YangAugment) yangNode;
- StringBuilder augmentPkg = new StringBuilder();
- augmentPkg.append(getCurNodePackage(augment));
-
- StringBuilder pkg = new StringBuilder();
- pkg.append(PERIOD);
- for (YangAtomicPath atomicPath : augment.getTargetNode()) {
- pkg.append(getCamelCase(atomicPath.getNodeIdentifier().getName(),
- config.getConflictResolver()))
- .append(PERIOD);
- }
- augmentPkg.append(trimAtLast(pkg.toString(), PERIOD).toLowerCase());
- return augmentPkg.toString();
- }
-
- /**
- * Updates YANG java file package information for specified package.
- *
- * @param info YANG java file info node
- * @param config YANG plugin config
- */
- private static void updatePackageInfo(JavaCodeGeneratorInfo info,
- YangPluginConfig config,
- String pkg) {
-
- JavaFileInfoTranslator translator = info.getJavaFileInfo();
- translator.setJavaName(getCamelCase(((YangNode) info).getName(),
- config.getConflictResolver()));
- translator.setPackage(pkg);
- updateCommonPackageInfo(translator, info, config);
- }
-
- /**
- * Updates common package information.
- *
- * @param translator JAVA file info translator
- * @param info YANG java file info node
- * @param config YANG plugin config
- */
- private static void updateCommonPackageInfo(JavaFileInfoTranslator translator,
- JavaCodeGeneratorInfo info,
- YangPluginConfig config) {
- translator.setPackageFilePath(getPackageDirPathFromJavaJPackage(
- info.getJavaFileInfo().getPackage()));
- translator.setBaseCodeGenPath(config.getCodeGenDir());
- translator.setPluginConfig(config);
- }
-
- /**
- * Updates temporary java code fragment files.
- *
- * @param info YANG java file info node
- * @throws IOException IO operations fails
- */
- private static void createTempFragmentFile(JavaCodeGeneratorInfo info)
- throws IOException {
- info.setTempJavaCodeFragmentFiles(
- new TempJavaCodeFragmentFiles(info.getJavaFileInfo()));
- }
-
- /**
- * Updates leaf information in temporary java code fragment files.
- *
- * @param info YANG java file info node
- * @throws IOException IO operations fails
- */
- private static void updateTempFragmentFiles(JavaCodeGeneratorInfo info,
- YangPluginConfig config)
- throws IOException {
-
- TempJavaCodeFragmentFiles translator =
- info.getTempJavaCodeFragmentFiles();
-
- if (info instanceof RpcNotificationContainer) {
- getBeanFiles(info).setRootNode(true);
- /*
- * Module / sub module node code generation.
- */
- if (info instanceof YangJavaModuleTranslator) {
- if (!((YangJavaModuleTranslator) info).getNotificationNodes()
- .isEmpty()) {
- updateNotificationNodeInfo(info, config);
- }
- } else if (info instanceof YangJavaSubModuleTranslator) {
- if (!((YangJavaSubModuleTranslator) info).getNotificationNodes()
- .isEmpty()) {
- updateNotificationNodeInfo(info, config);
- }
- }
- }
- if (info instanceof YangLeavesHolder) {
- /*
- * Container
- * Case
- * Grouping
- * Input
- * List
- * Notification
- * Output
- */
- getBeanFiles(info).addCurNodeLeavesInfoToTempFiles((YangNode) info,
- config);
-
- // Add operation type as an attribute.
- getBeanFiles(info).addOperationTypeToTempFiles((YangNode) info,
- config);
- } else if (info instanceof YangTypeHolder) {
- /*
- * Typedef
- * Union
- */
- translator.addTypeInfoToTempFiles((YangTypeHolder) info, config);
- } else if (info instanceof YangJavaEnumerationTranslator) {
- /*
- * Enumeration
- */
- translator.getEnumTempFiles()
- .addEnumAttributeToTempFiles((YangNode) info, config);
- } else if (!(info instanceof YangChoice)) {
- /*Do nothing, only the interface needs to be generated for choice*/
- throw new TranslatorException(
- getErrorMsgForCodeGenerator(INVALID_TRANSLATION_NODE,
- info));
- }
- }
-
- /**
- * Process generate code entry of YANG node.
- *
- * @param info YANG java file info node
- * @param config plugin configurations
- * @throws IOException IO operations fails
- */
- private static void generateTempFiles(JavaCodeGeneratorInfo info,
- YangPluginConfig config)
- throws IOException {
- if (!(info instanceof YangNode)) {
- throw new TranslatorException(
- getErrorMsgForCodeGenerator(INVALID_TRANSLATION_NODE,
- info));
- }
- createTempFragmentFile(info);
- updateTempFragmentFiles(info, config);
- }
-
- /**
- * Updates notification node info in service temporary file.
- *
- * @param info java code generator info
- * @param config plugin configurations
- * @throws IOException when fails to do IO operations
- */
- private static void updateNotificationNodeInfo(JavaCodeGeneratorInfo info,
- YangPluginConfig config)
- throws IOException {
- TempJavaCodeFragmentFiles translator =
- info.getTempJavaCodeFragmentFiles();
- if (info instanceof YangJavaModuleTranslator) {
- for (YangNode notification : ((YangJavaModuleTranslator) info)
- .getNotificationNodes()) {
- translator.getEventFragmentFiles()
- .addJavaSnippetOfEvent(notification, config);
- }
- }
- if (info instanceof YangJavaSubModuleTranslator) {
- for (YangNode notification : ((YangJavaSubModuleTranslator) info)
- .getNotificationNodes()) {
- translator.getEventFragmentFiles()
- .addJavaSnippetOfEvent(notification, config);
- }
- }
- }
-
- /**
- * Generates code for the current ata model node and adds itself as an
- * attribute in the parent.
- *
- * @param info YANG java file info node
- * @param config YANG plugin config
- * @param isMultiInstance flag to indicate whether it's a list
- * @throws IOException IO operations fails
- */
- public static void generateCodeAndUpdateInParent(JavaCodeGeneratorInfo info,
- YangPluginConfig config,
- boolean isMultiInstance)
- throws IOException {
- if (!(info instanceof YangNode)) {
- throw new TranslatorException(
- getErrorMsgForCodeGenerator(INVALID_TRANSLATION_NODE,
- info));
- }
-
- /*
- * For second level and below cloned nodes code shouldn't be
- * generated also they needn't be added in parent, since
- * generated code will be under grouping, cloned node is only
- * used for YANG namespace.
- */
- YangNode n = (YangNode) info;
- if (n.getReferredSchema() != null &&
- !(((YangNode) n.getReferredSchema()).getParent() instanceof
- YangGrouping)) {
- return;
- }
- /*
- * If first level cloned node, then it needs to be imported in the
- * generated code. In case uses under grouping, it would further have
- * second level uses, hence needn't add in parent grouping.
- */
- YangSchemaNode rn = getRefSchema(info);
- if (rn != null) {
- YangNode parent = ((YangNode) info).getParent();
- if (!(parent instanceof YangGrouping)) {
- addCurNodeInfoInParentTempFile((YangNode) rn, isMultiInstance,
- config, parent);
- }
- return;
- }
-
- /*
- * Generate the Java files corresponding to the current node.
- */
- generateCodeOfAugmentableNode(info, config);
-
- /*
- * Update the current nodes info in its parent nodes generated files.
- */
- addCurNodeInfoInParentTempFile((YangNode) info, isMultiInstance,
- config);
- }
-
- /**
- * Returns referred schema node in case of grouping uses.
- *
- * @param info YANG java file info node
- * @return referred schema node
- */
- private static YangSchemaNode getRefSchema(JavaCodeGeneratorInfo info) {
-
- YangSchemaNode node = ((YangSchemaNode) info);
- if (node.getReferredSchema() == null) {
- return null;
- }
-
- /*
- * Obtain last referred node in case grouping is embedded inside
- * another grouping.
- */
- while (node.getReferredSchema() != null) {
- node = node.getReferredSchema();
- }
- return node;
- }
-
- /**
- * Generates code for the current data model node and adds support for it to
- * be augmented.
- *
- * @param info YANG java file info node
- * @param config YANG plugin config
- * @throws IOException IO operations fails
- */
- public static void generateCodeOfAugmentableNode(JavaCodeGeneratorInfo info,
- YangPluginConfig config)
- throws IOException {
- if (!(info instanceof YangNode)) {
- throw new TranslatorException(
- getErrorMsgForCodeGenerator(INVALID_TRANSLATION_NODE,
- info));
- }
-
- generateCodeOfNode(info, config);
- TempJavaCodeFragmentFiles tempFiles =
- info.getTempJavaCodeFragmentFiles();
-
- if (info instanceof YangCase) {
- YangNode parent = ((YangCase) info).getParent();
- JavaQualifiedTypeInfoTranslator typeInfo =
- getQualifierInfoForCasesParent(parent, config);
- getBeanFiles(info).getJavaExtendsListHolder()
- .addToExtendsList(typeInfo, (YangNode) info,
- tempFiles.getBeanTempFiles());
-
- getBeanFiles(info).addParentInfoInCurNodeTempFile((YangNode) info,
- config);
- }
- }
-
- /**
- * Returns cases parent's qualified info.
- *
- * @param parent parent node
- * @param config plugin configuration
- * @return cases parent's qualified info
- */
- public static JavaQualifiedTypeInfoTranslator
- getQualifierInfoForCasesParent(YangNode parent,
- YangPluginConfig config) {
- String parentName;
- String parentPkg;
- JavaFileInfoTranslator parentInfo;
- if (parent instanceof YangChoice) {
- parentInfo = ((JavaFileInfoContainer) parent).getJavaFileInfo();
- } else {
- parent = ((YangAugment) parent).getAugmentedNode();
- parentInfo = ((JavaFileInfoContainer) parent).getJavaFileInfo();
- }
- if (parentInfo.getPackage() != null) {
- parentName = getCapitalCase(parentInfo.getJavaName());
- parentPkg = parentInfo.getPackage();
- } else {
- parentName = getCapitalCase(getCamelCase(parent.getName(),
- config.getConflictResolver()));
- parentPkg = getNodesPackage(parent, config);
- }
- JavaQualifiedTypeInfoTranslator qualifiedTypeInfo =
- new JavaQualifiedTypeInfoTranslator();
- qualifiedTypeInfo.setClassInfo(parentName);
- qualifiedTypeInfo.setPkgInfo(parentPkg);
- return qualifiedTypeInfo;
- }
-
- /**
- * Generates code for the current data model node.
- *
- * @param info YANG java file info node
- * @param config YANG plugin config
- * @throws IOException IO operations fails
- */
- public static void generateCodeOfNode(JavaCodeGeneratorInfo info,
- YangPluginConfig config)
- throws IOException {
- if (!(info instanceof YangNode)) {
- throw new TranslatorException(
- getErrorMsgForCodeGenerator(INVALID_TRANSLATION_NODE,
- info));
- }
- updatePackageInfo(info, config);
- generateTempFiles(info, config);
- }
-
- /**
- * Generates code for the root module/sub-module node.
- *
- * @param info YANG java file info node
- * @param config YANG plugin config
- * @param rootPkg package of the root node
- * @throws IOException IO operations fails
- */
- public static void generateCodeOfRootNode(JavaCodeGeneratorInfo info,
- YangPluginConfig config,
- String rootPkg)
- throws IOException {
- if (!(info instanceof YangNode)) {
- throw new TranslatorException(
- getErrorMsgForCodeGenerator(INVALID_TRANSLATION_NODE,
- info));
- }
- updatePackageInfo(info, config, rootPkg);
-
- if (isRpcChildNodePresent((YangNode) info)) {
- info.getJavaFileInfo()
- .addGeneratedFileTypes(GENERATE_SERVICE_AND_MANAGER);
- }
- generateTempFiles(info, config);
- }
-
- /**
- * Returns the node package string.
- *
- * @param curNode current java node whose package string needs to be set
- * @return returns the root package string
- */
- public static String getCurNodePackage(YangNode curNode)
- throws TranslatorException {
-
- String pkg;
- if (!(curNode instanceof JavaFileInfoContainer) ||
- curNode.getParent() == null) {
- throw new TranslatorException(getErrorMsg(INVALID_NODE, curNode));
- }
-
- YangNode parentNode = DataModelUtils.getParentNodeInGenCode(curNode);
- if (!(parentNode instanceof JavaFileInfoContainer)) {
- throw new TranslatorException(getErrorMsg(INVALID_PARENT_NODE,
- curNode));
- }
- JavaFileInfoTranslator handle =
- ((JavaFileInfoContainer) parentNode).getJavaFileInfo();
- pkg = handle.getPackage() + PERIOD + handle.getJavaName();
- return pkg.toLowerCase();
- }
-
- /**
- * Returns true if root node contains any data node.
- *
- * @param node root YANG node
- * @return true if root node contains any data node
- */
- public static boolean isRootNodesCodeGenRequired(YangNode node) {
- return isNodeCodeGenRequired(node, true);
- }
-
- /**
- * Returns true if get/set method of root node are required.
- *
- * @param node root node
- * @return true if get/set method of root node are required
- */
- public static boolean isGetSetOfRootNodeRequired(YangNode node) {
- return isNodeCodeGenRequired(node, false);
- }
-
- /**
- * Returns true if either get/set method of root node are required or root
- * node contains any data node. This check is done depending on the
- * boolean parameter indicating whether check to be performed for root
- * node code generation or get/set method generation.
- *
- * @param node root node
- * @param rootNodeGen flag indicating check type
- * @return true if check pass, false otherwise
- */
- private static boolean isNodeCodeGenRequired(YangNode node,
- boolean rootNodeGen) {
- YangLeavesHolder holder = (YangLeavesHolder) node;
-
- if (!holder.getListOfLeaf().isEmpty()) {
- return true;
- }
- if (!holder.getListOfLeafList().isEmpty()) {
- return true;
- }
- node = node.getChild();
- if (node == null) {
- return false;
- }
-
- if (rootNodeGen) {
- while (node != null) {
- if (!(node instanceof YangTranslatorOperatorNode)) {
- return true;
- }
- node = node.getNextSibling();
- }
- return false;
- }
- while (node != null) {
- if (!(node instanceof YangAugment)) {
- return true;
- }
- node = node.getNextSibling();
- }
- return false;
- }
-
- /**
- * Returns nodes package.
- *
- * @param node YANG node
- * @param config plugin config
- * @return java package
- */
- public static String getNodesPackage(YangNode node,
- YangPluginConfig config) {
-
- List<String> clsInfo = new ArrayList<>();
- while (node.getParent() != null) {
- if (node instanceof YangJavaAugmentTranslator) {
- clsInfo.add(getAugmentClassName((YangAugment) node,
- config));
- } else {
- clsInfo.add(getCamelCase(node.getName(), config
- .getConflictResolver()));
- }
- node = node.getParent();
- }
-
- StringBuilder pkg = new StringBuilder();
- if (node instanceof YangJavaModuleTranslator) {
- YangJavaModuleTranslator module = (YangJavaModuleTranslator) node;
- pkg.append(getRootPackage(module.getVersion(),
- module.getModuleNamespace(),
- module.getRevision(),
- config.getConflictResolver()));
- } else if (node instanceof YangJavaSubModuleTranslator) {
- YangJavaSubModuleTranslator subModule =
- (YangJavaSubModuleTranslator) node;
- pkg.append(getRootPackage(subModule.getVersion(),
- subModule.getNameSpaceFromModule(),
- subModule.getRevision(),
- config.getConflictResolver()));
- }
- pkg.append(EMPTY_STRING);
- int size = clsInfo.size();
- for (int i = size - 1; i >= 0; i--) {
- pkg.append(PERIOD).append(clsInfo.get(i));
- }
- return pkg.toString().toLowerCase();
- }
-
- /**
- * Returns augment class name.
- *
- * @param augment YANG augment
- * @param config plugin configurations
- * @return augment class name
- */
- private static String getAugmentClassName(YangAugment augment,
- YangPluginConfig config) {
- YangNodeIdentifier identifier =
- augment.getTargetNode().get(augment.getTargetNode().size() - 1)
- .getNodeIdentifier();
- String name = getCapitalCase(getCamelCase(identifier.getName(),
- config.getConflictResolver()));
- if (identifier.getPrefix() != null) {
- return AUGMENTED + getCapitalCase(
- getCamelCase(identifier.getPrefix(),
- config.getConflictResolver())) + name;
- }
- return AUGMENTED + name;
- }
-
- /**
- * Generated java code during exit.
- *
- * @param type generated file type
- * @param node current YANG node
- * @throws IOException when fails to generate java files
- */
- public static void generateJava(int type, YangNode node)
- throws IOException {
- /*
- * Call for file generation if node is not under uses.
- */
- if(node.getReferredSchema() == null) {
- ((TempJavaCodeFragmentFilesContainer) node)
- .getTempJavaCodeFragmentFiles().generateJavaFile(type, node);
- }
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/AttributesJavaDataType.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/AttributesJavaDataType.java
deleted file mode 100644
index 2d70219..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/AttributesJavaDataType.java
+++ /dev/null
@@ -1,572 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.translator.tojava.javamodel;
-
-import org.onosproject.yangutils.datamodel.YangDerivedInfo;
-import org.onosproject.yangutils.datamodel.YangEnumeration;
-import org.onosproject.yangutils.datamodel.YangIdentity;
-import org.onosproject.yangutils.datamodel.YangIdentityRef;
-import org.onosproject.yangutils.datamodel.YangLeafRef;
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.YangType;
-import org.onosproject.yangutils.datamodel.YangUnion;
-import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
-import org.onosproject.yangutils.translator.exception.TranslatorException;
-import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
-import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
-import org.onosproject.yangutils.translator.tojava.JavaFileInfoTranslator;
-import org.onosproject.yangutils.utils.io.YangToJavaNamingConflictUtil;
-
-import java.util.Stack;
-
-import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.getCurNodePackage;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
-import static org.onosproject.yangutils.utils.UtilConstants.BIG_DECIMAL;
-import static org.onosproject.yangutils.utils.UtilConstants.BIG_INTEGER;
-import static org.onosproject.yangutils.utils.UtilConstants.BIT_SET;
-import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_DATA_TYPE;
-import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_WRAPPER;
-import static org.onosproject.yangutils.utils.UtilConstants.BYTE;
-import static org.onosproject.yangutils.utils.UtilConstants.BYTE_WRAPPER;
-import static org.onosproject.yangutils.utils.UtilConstants.COLLECTION_IMPORTS;
-import static org.onosproject.yangutils.utils.UtilConstants.INT;
-import static org.onosproject.yangutils.utils.UtilConstants.INTEGER_WRAPPER;
-import static org.onosproject.yangutils.utils.UtilConstants.JAVA_LANG;
-import static org.onosproject.yangutils.utils.UtilConstants.JAVA_MATH;
-import static org.onosproject.yangutils.utils.UtilConstants.LONG;
-import static org.onosproject.yangutils.utils.UtilConstants.LONG_WRAPPER;
-import static org.onosproject.yangutils.utils.UtilConstants.OBJECT_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
-import static org.onosproject.yangutils.utils.UtilConstants.SHORT;
-import static org.onosproject.yangutils.utils.UtilConstants.SHORT_WRAPPER;
-import static org.onosproject.yangutils.utils.UtilConstants.SQUARE_BRACKETS;
-import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getPackageDirPathFromJavaJPackage;
-
-/**
- * Represents java data types info corresponding to YANG type.
- */
-public final class AttributesJavaDataType {
-
- /**
- * Creates an instance of attribute java data type.
- */
- private AttributesJavaDataType() {
- }
-
- /**
- * Returns java type.
- *
- * @param yangType YANG type
- * @return java type
- */
- public static String getJavaDataType(YangType<?> yangType) {
-
- YangDataTypes type = yangType.getDataType();
-
- switch (type) {
- case INT8:
- return BYTE;
- case INT16:
- return SHORT;
- case INT32:
- return INT;
- case INT64:
- return LONG;
- case UINT8:
- return SHORT;
- case UINT16:
- return INT;
- case UINT32:
- return LONG;
- case UINT64:
- return BIG_INTEGER;
- case BITS:
- return BIT_SET;
- case BINARY:
- return BYTE + SQUARE_BRACKETS;
- case DECIMAL64:
- return BIG_DECIMAL;
- case STRING:
- return STRING_DATA_TYPE;
- case BOOLEAN:
- return BOOLEAN_DATA_TYPE;
- case INSTANCE_IDENTIFIER:
- return STRING_DATA_TYPE;
- case LEAFREF:
- YangType refType = getReferredTypeFromLeafref(yangType);
- if (refType == null) {
- return OBJECT_STRING;
- }
- return getJavaDataType(getReferredTypeFromLeafref(yangType));
- default:
- throw new TranslatorException("given data type is not supported. " +
- yangType.getDataTypeName() + " in " +
- yangType.getLineNumber() + " at " +
- yangType.getCharPosition()
- + " in " + yangType.getFileName());
- }
- }
-
- /**
- * Returns java import class.
- *
- * @param yangType YANG type
- * @param isListAttr if the attribute need to be a list
- * @param pluginConfig plugin configurations
- * @return java import class
- */
- public static String getJavaImportClass(YangType<?> yangType, boolean isListAttr,
- YangToJavaNamingConflictUtil pluginConfig) {
-
- YangDataTypes type = yangType.getDataType();
-
- if (isListAttr) {
- switch (type) {
- case INT8:
- return BYTE_WRAPPER;
- case INT16:
- return SHORT_WRAPPER;
- case INT32:
- return INTEGER_WRAPPER;
- case INT64:
- return LONG_WRAPPER;
- case UINT8:
- return SHORT_WRAPPER;
- case UINT16:
- return INTEGER_WRAPPER;
- case UINT32:
- return LONG_WRAPPER;
- case UINT64:
- return BIG_INTEGER;
- case DECIMAL64:
- return BIG_DECIMAL;
- case STRING:
- return STRING_DATA_TYPE;
- case BOOLEAN:
- return BOOLEAN_WRAPPER;
- case ENUMERATION:
- return getCapitalCase(
- getCamelCase(((YangJavaEnumerationTranslator) yangType.getDataTypeExtendedInfo()).getName(),
- pluginConfig));
- case BITS:
- return BIT_SET;
- case BINARY:
- return BYTE + SQUARE_BRACKETS;
- case LEAFREF:
- return getLeafRefImpClass(yangType, pluginConfig, true);
- case IDENTITYREF:
- return getIdentityRefImpClass(yangType, pluginConfig);
- case EMPTY:
- return BOOLEAN_WRAPPER;
- case UNION:
- return getCapitalCase(getCamelCase(((YangJavaUnionTranslator) yangType
- .getDataTypeExtendedInfo()).getName(), pluginConfig));
- case INSTANCE_IDENTIFIER:
- return STRING_DATA_TYPE;
- case DERIVED:
- return getCapitalCase(
- getCamelCase(yangType.getDataTypeName(), pluginConfig));
- default:
- throw new TranslatorException("given data type is not supported ." +
- yangType.getDataTypeName() + " in " +
- yangType.getLineNumber() + " at " +
- yangType.getCharPosition()
- + " in " + yangType.getFileName());
- }
- } else {
- switch (type) {
- case UINT64:
- return BIG_INTEGER;
- case STRING:
- return STRING_DATA_TYPE;
- case ENUMERATION:
- return getCapitalCase(
- getCamelCase(((YangJavaEnumerationTranslator) yangType.getDataTypeExtendedInfo()).getName(),
- pluginConfig));
- case BITS:
- return BIT_SET;
- case DECIMAL64:
- return BIG_DECIMAL;
- case LEAFREF:
- return getLeafRefImpClass(yangType, pluginConfig, false);
- case IDENTITYREF:
- return getIdentityRefImpClass(yangType, pluginConfig);
- case EMPTY:
- return BOOLEAN_DATA_TYPE;
- case UNION:
- return getCapitalCase(getCamelCase(((YangJavaUnionTranslator) yangType
- .getDataTypeExtendedInfo()).getName(), pluginConfig));
- case INSTANCE_IDENTIFIER:
- return STRING_DATA_TYPE;
- case DERIVED:
- return getCapitalCase(
- getCamelCase(yangType.getDataTypeName(), pluginConfig));
- default:
- return null;
- }
- }
- }
-
- /**
- * Returns java import package.
- *
- * @param yangType YANG type
- * @param isListAttr if the attribute is of list type
- * @param conflictResolver object of YANG to java naming conflict util
- * @return java import package
- */
- public static String getJavaImportPackage(YangType<?> yangType, boolean isListAttr,
- YangToJavaNamingConflictUtil conflictResolver) {
-
- YangDataTypes type = yangType.getDataType();
-
- if (isListAttr) {
- switch (type) {
- case INT8:
- case INT16:
- case INT32:
- case INT64:
- case UINT8:
- case UINT16:
- case UINT32:
- case BINARY:
- case STRING:
- case BOOLEAN:
- case EMPTY:
- return JAVA_LANG;
- case UINT64:
- case DECIMAL64:
- return JAVA_MATH;
- case ENUMERATION:
- return getEnumsPackage(yangType, conflictResolver);
- case BITS:
- return COLLECTION_IMPORTS;
- case LEAFREF:
- return getLeafRefImpPkg(yangType, conflictResolver, true);
- case IDENTITYREF:
- return getIdentityRefPackage(yangType, conflictResolver);
- case UNION:
- return getUnionPackage(yangType, conflictResolver);
- case INSTANCE_IDENTIFIER:
- return JAVA_LANG;
- case DERIVED:
- return getTypeDefsPackage(yangType, conflictResolver);
- default:
- throw new TranslatorException("given data type is not supported. " +
- yangType.getDataTypeName() + " in " +
- yangType.getLineNumber() + " at " +
- yangType.getCharPosition()
- + " in " + yangType.getFileName());
- }
- } else {
- switch (type) {
- case UINT64:
- case DECIMAL64:
- return JAVA_MATH;
- case EMPTY:
- case STRING:
- return JAVA_LANG;
- case ENUMERATION:
- return getEnumsPackage(yangType, conflictResolver);
- case BITS:
- return COLLECTION_IMPORTS;
- case LEAFREF:
- return getLeafRefImpPkg(yangType, conflictResolver, false);
- case IDENTITYREF:
- return getIdentityRefPackage(yangType, conflictResolver);
- case UNION:
- return getUnionPackage(yangType, conflictResolver);
- case INSTANCE_IDENTIFIER:
- return JAVA_LANG;
- case DERIVED:
- return getTypeDefsPackage(yangType, conflictResolver);
- default:
- return null;
- }
- }
- }
-
- /**
- * Returns java package for typedef node.
- *
- * @param type YANG type
- * @param conflictResolver object of YANG to java naming conflict util
- * @return java package for typedef node
- */
- private static String getTypeDefsPackage(YangType<?> type, YangToJavaNamingConflictUtil conflictResolver) {
- Object var = type.getDataTypeExtendedInfo();
- if (!(var instanceof YangDerivedInfo)) {
- throw new TranslatorException("type should have been derived. " +
- type.getDataTypeName() + " in " +
- type.getLineNumber() + " at " +
- type.getCharPosition()
- + " in " + type.getFileName());
- }
-
- if (!(((YangDerivedInfo<?>) var).getReferredTypeDef() != null)) {
- throw new TranslatorException("derived info is not an instance of typedef. " +
- type.getDataTypeName() + " in " +
- type.getLineNumber() + " at " +
- type.getCharPosition()
- + " in " + type.getFileName());
- }
-
- YangJavaTypeDefTranslator typedef = (YangJavaTypeDefTranslator) ((YangDerivedInfo<?>) var).getReferredTypeDef();
- return getTypePackage(typedef, conflictResolver);
- }
-
- /**
- * Returns java package for union node.
- *
- * @param type YANG type
- * @param conflictResolver object of YANG to java naming conflict util
- * @return java package for union node
- */
- private static String getUnionPackage(YangType<?> type, YangToJavaNamingConflictUtil conflictResolver) {
-
- if (!(type.getDataTypeExtendedInfo() instanceof YangUnion)) {
- throw new TranslatorException("type should have been union. " +
- type.getDataTypeName() + " in " +
- type.getLineNumber() + " at " +
- type.getCharPosition()
- + " in " + type.getFileName());
- }
-
- YangJavaUnionTranslator union = (YangJavaUnionTranslator) type.getDataTypeExtendedInfo();
- return getTypePackage(union, conflictResolver);
- }
-
- /**
- * Returns YANG enumeration's java package.
- *
- * @param type YANG type
- * @param conflictResolver object of YANG to java naming conflict util
- * @return YANG enumeration's java package
- */
- private static String getEnumsPackage(YangType<?> type, YangToJavaNamingConflictUtil conflictResolver) {
-
- if (!(type.getDataTypeExtendedInfo() instanceof YangEnumeration)) {
- throw new TranslatorException("type should have been enumeration. " +
- type.getDataTypeName() + " in " +
- type.getLineNumber() + " at " +
- type.getCharPosition()
- + " in " + type.getFileName());
- }
- YangJavaEnumerationTranslator enumeration = (YangJavaEnumerationTranslator) type.getDataTypeExtendedInfo();
- return getTypePackage(enumeration, conflictResolver);
- }
-
- /**
- * Returns YANG identity's java package.
- *
- * @param type YANG type
- * @param conflictResolver object of YANG to java naming conflict util
- * @return YANG identity's java package
- */
- private static String getIdentityRefPackage(YangType<?> type, YangToJavaNamingConflictUtil conflictResolver) {
-
- if (!(type.getDataTypeExtendedInfo() instanceof YangIdentityRef)) {
- throw new TranslatorException("type should have been identityref. " +
- type.getDataTypeName() + " in " +
- type.getLineNumber() + " at " +
- type.getCharPosition()
- + " in " + type.getFileName());
- }
- YangIdentityRef identityRef = (YangIdentityRef) type.getDataTypeExtendedInfo();
- if (identityRef.isInGrouping()) {
- return JAVA_LANG;
- }
- YangJavaIdentityTranslator identity = (YangJavaIdentityTranslator) (identityRef.getReferredIdentity());
- return getTypePackage(identity, conflictResolver);
- }
-
- /**
- * Returns type package.
- *
- * @param info YANG code generator info
- * @param conflictResolver object of YANG to java naming conflict util
- * @return type java package
- */
- private static String getTypePackage(JavaCodeGeneratorInfo info,
- YangToJavaNamingConflictUtil conflictResolver) {
- YangNode node = (YangNode) info;
- // Check for referred schema type node for grouping scenario.
- while (node.getReferredSchema() != null) {
- node = (YangNode) node.getReferredSchema();
- }
- info = (JavaCodeGeneratorInfo) node;
- if (info.getJavaFileInfo().getPackage() == null) {
- return getPackageFromParent(node.getParent(), conflictResolver);
- }
- return info.getJavaFileInfo().getPackage();
- }
-
- /**
- * Returns package from parent node.
- *
- * @param parent parent YANG node
- * @param conflictResolver object of YANG to java naming conflict util
- * @return java package from parent node
- */
- private static String getPackageFromParent(YangNode parent,
- YangToJavaNamingConflictUtil conflictResolver) {
- if (!(parent instanceof JavaFileInfoContainer)) {
- throw new TranslatorException("invalid child node is being processed. " +
- parent.getName() + " in " +
- parent.getLineNumber() + " at " +
- parent.getCharPosition()
- + " in " + parent.getFileName());
- }
- JavaFileInfoTranslator parentInfo = ((JavaFileInfoContainer) parent).getJavaFileInfo();
- if (parentInfo.getPackage() == null) {
- updateJavaFileInfo(parent, conflictResolver);
- }
- return parentInfo.getPackage() + PERIOD + parentInfo.getJavaName().toLowerCase();
- }
-
- /**
- * Update the referred data model nodes java file info, this will be called,
- * when the linked node is yet to translate. Then resolve until the parent hierarchy.
- *
- * @param yangNode node whose java info needs to be updated
- * @param conflictResolver yang plugin config
- */
- public static void updateJavaFileInfo(YangNode yangNode,
- YangToJavaNamingConflictUtil conflictResolver) {
- Stack<YangNode> nodesToUpdatePackage = new Stack<>();
-
- /*
- * Add the nodes to be updated for package info in a stack.
- */
- while (yangNode != null
- && ((JavaFileInfoContainer) yangNode)
- .getJavaFileInfo().getPackage() == null) {
- nodesToUpdatePackage.push(yangNode);
- yangNode = yangNode.getParent();
- }
-
- /*
- * If the package is not updated till root node, then root package needs to
- * be updated.
- */
- if (yangNode == null) {
- yangNode = nodesToUpdatePackage.pop();
- String pkg;
- if (yangNode instanceof YangJavaModuleTranslator) {
- YangJavaModuleTranslator module = (YangJavaModuleTranslator) yangNode;
- pkg = getRootPackage(module.getVersion(), module.getModuleNamespace(),
- module.getRevision(), conflictResolver);
- } else if (yangNode instanceof YangJavaSubModuleTranslator) {
- YangJavaSubModuleTranslator submodule = (YangJavaSubModuleTranslator) yangNode;
- pkg = getRootPackage(submodule.getVersion(),
- submodule.getNameSpaceFromModule(),
- submodule.getRevision(), conflictResolver);
- } else {
- throw new TranslatorException("Invalid root node of data model tree " +
- yangNode.getName() + " in " +
- yangNode.getLineNumber() + " at " +
- yangNode.getCharPosition()
- + " in " + yangNode.getFileName());
- }
-
- ((JavaCodeGeneratorInfo) yangNode).getJavaFileInfo()
- .setJavaName(getCamelCase(yangNode.getName(), conflictResolver));
- ((JavaCodeGeneratorInfo) yangNode).getJavaFileInfo()
- .setPackage(pkg);
- ((JavaCodeGeneratorInfo) yangNode).getJavaFileInfo()
- .setPackageFilePath(getPackageDirPathFromJavaJPackage(
- ((JavaCodeGeneratorInfo) yangNode).getJavaFileInfo()
- .getPackage()));
- }
-
- /*
- * Parent of the node in stack is updated with java info,
- * all the nodes can be popped and updated
- */
- while (nodesToUpdatePackage.size() != 0) {
- yangNode = nodesToUpdatePackage.pop();
- ((JavaCodeGeneratorInfo) yangNode).getJavaFileInfo()
- .setJavaName(getCamelCase(yangNode.getName(), conflictResolver));
- ((JavaCodeGeneratorInfo) yangNode).getJavaFileInfo()
- .setPackage(getCurNodePackage(yangNode));
- ((JavaCodeGeneratorInfo) yangNode).getJavaFileInfo()
- .setPackageFilePath(getPackageDirPathFromJavaJPackage(
- ((JavaCodeGeneratorInfo) yangNode).getJavaFileInfo()
- .getPackage()));
- }
- }
-
- /**
- * Returns the referred type from leaf/leaf-list.
- *
- * @param type current type in leaf
- * @return type from the leafref
- */
- private static YangType<?> getReferredTypeFromLeafref(YangType type) {
- YangLeafRef<?> lri = (YangLeafRef<?>) type.getDataTypeExtendedInfo();
- return lri.isInGrouping() ? null : lri.getEffectiveDataType();
- }
-
- /**
- * Returns leaf ref import string.
- *
- * @param type YANG type
- * @param cnfg YANG to java naming conflict util
- * @param isList true if list, false otherwise
- * @return import class
- */
- private static String getLeafRefImpClass(
- YangType type, YangToJavaNamingConflictUtil cnfg, boolean isList) {
- YangType<?> rt = getReferredTypeFromLeafref(type);
- return rt == null ? OBJECT_STRING : getJavaImportClass(rt, isList,
- cnfg);
- }
-
- /**
- * Returns identity ref import class.
- *
- * @param type YANG type
- * @param cnfg YANG to java naming conflict util
- * @return import class
- */
- private static String getIdentityRefImpClass(
- YangType type, YangToJavaNamingConflictUtil cnfg) {
- YangIdentityRef ir = (YangIdentityRef) type.getDataTypeExtendedInfo();
- if (ir.isInGrouping()) {
- return OBJECT_STRING;
- }
- YangIdentity identity = ir.getReferredIdentity();
- return getCapitalCase(getCamelCase(identity.getName(), cnfg));
- }
-
- /**
- * Returns leaf ref import package.
- *
- * @param type YANG type
- * @param cnfg YANG to java naming conflict util
- * @param isList true if list, false otherwise
- * @return import package
- */
- private static String getLeafRefImpPkg(
- YangType type, YangToJavaNamingConflictUtil cnfg, boolean isList) {
- YangType<?> rt = getReferredTypeFromLeafref(type);
- return rt == null ? JAVA_LANG : getJavaImportPackage(rt, isList, cnfg);
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/JavaLeafInfoContainer.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/JavaLeafInfoContainer.java
deleted file mode 100644
index c1c6e60..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/JavaLeafInfoContainer.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.yangutils.translator.tojava.javamodel;
-
-import org.onosproject.yangutils.datamodel.LocationInfo;
-import org.onosproject.yangutils.datamodel.YangType;
-import org.onosproject.yangutils.datamodel.javadatamodel.JavaQualifiedTypeInfoContainer;
-import org.onosproject.yangutils.utils.io.YangToJavaNamingConflictUtil;
-
-/**
- * Represent java based identification of the YANG leaves.
- */
-public interface JavaLeafInfoContainer
- extends JavaQualifiedTypeInfoContainer, LocationInfo {
- /**
- * Retrieves the data type of the leaf.
- *
- * @return data type of the leaf
- */
- YangType<?> getDataType();
-
- /**
- * Retrieves the name of the leaf.
- *
- * @return name of the leaf
- */
- String getName();
-
- /**
- * Retrieves the java name of the leaf.
- *
- * @param conflictResolveConfig user config to resolve conflicts
- * @return name of the leaf
- */
- String getJavaName(YangToJavaNamingConflictUtil conflictResolveConfig);
-
- /**
- * Identifies if object is a leaf-list.
- *
- * @return true if leaf-list false otherwise
- */
- boolean isLeafList();
-
- /**
- * updates the qualified info.
- */
- void updateJavaQualifiedInfo();
-
- /**
- * Returns java naming conflict resolver.
- *
- * @return java naming conflict resolver
- */
- YangToJavaNamingConflictUtil getConflictResolveConfig();
-
- /**
- * Sets java naming conflict resolver.
- *
- * @param conflictResolveConfig java naming conflict resolver
- */
- void setConflictResolveConfig(YangToJavaNamingConflictUtil conflictResolveConfig);
-
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/JavaQualifiedTypeResolver.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/JavaQualifiedTypeResolver.java
deleted file mode 100644
index 909c6f4..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/JavaQualifiedTypeResolver.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.yangutils.translator.tojava.javamodel;
-
-import org.onosproject.yangutils.utils.io.YangToJavaNamingConflictUtil;
-
-/**
- * Represent java based identification of the YANG leaves.
- */
-interface JavaQualifiedTypeResolver {
-
- /**
- * updates the qualified access details of the type.
- *
- * @param conflictResolver plugin configurations
- */
- void updateJavaQualifiedInfo(YangToJavaNamingConflictUtil conflictResolver);
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaAugmentTranslator.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaAugmentTranslator.java
deleted file mode 100644
index 1607b9f..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaAugmentTranslator.java
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.yangutils.translator.tojava.javamodel;
-
-import java.io.IOException;
-
-import org.onosproject.yangutils.datamodel.YangChoice;
-import org.onosproject.yangutils.datamodel.javadatamodel.YangJavaAugment;
-import org.onosproject.yangutils.translator.exception.TranslatorException;
-import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
-import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
-import org.onosproject.yangutils.translator.tojava.JavaFileInfoTranslator;
-import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
-import org.onosproject.yangutils.utils.io.YangPluginConfig;
-
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
-import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateCodeOfAugmentableNode;
-
-/**
- * Represents augment information extended to support java code generation.
- */
-public class YangJavaAugmentTranslator
- extends YangJavaAugment
- implements JavaCodeGeneratorInfo, JavaCodeGenerator {
-
- private static final long serialVersionUID = 806201632L;
-
- /**
- * File handle to maintain temporary java code fragments as per the code snippet types.
- */
- private transient TempJavaCodeFragmentFiles tempFileHandle;
-
- /**
- * Creates a YANG java augment object.
- */
- public YangJavaAugmentTranslator() {
- super();
- setJavaFileInfo(new JavaFileInfoTranslator());
- getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER);
- }
-
- /**
- * Returns the generated java file information.
- *
- * @return generated java file information
- */
- @Override
- public JavaFileInfoTranslator getJavaFileInfo() {
-
- if (javaFileInfo == null) {
- throw new TranslatorException("Missing java info in java datamodel node " +
- getName() + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName());
- }
- return (JavaFileInfoTranslator) javaFileInfo;
- }
-
- /**
- * Sets the java file info object.
- *
- * @param javaInfo java file info object
- */
- @Override
- public void setJavaFileInfo(JavaFileInfoTranslator javaInfo) {
- javaFileInfo = javaInfo;
- }
-
- /**
- * Returns the temporary file handle.
- *
- * @return temporary file handle
- */
- @Override
- public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
- return tempFileHandle;
- }
-
- /**
- * Sets temporary file handle.
- *
- * @param fileHandle temporary file handle
- */
- @Override
- public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
- tempFileHandle = fileHandle;
- }
-
- /**
- * Prepare the information for java code generation corresponding to YANG augment info.
- *
- * @param yangPlugin YANG plugin config
- * @throws TranslatorException translator operation fail
- */
- @Override
- public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
- try {
- generateCodeOfAugmentableNode(this, yangPlugin);
- } catch (IOException e) {
- throw new TranslatorException("Failed to generate code for augmentable node " +
- getName() + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + " " + e.getLocalizedMessage());
- }
- }
-
- /**
- * Create a java file using the YANG augment info.
- *
- * @throws TranslatorException when failed to do translator operations
- */
- @Override
- public void generateCodeExit() throws TranslatorException {
- try {
- if (validateAugmentNode()) {
- getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
- }
- } catch (IOException e) {
- throw new TranslatorException("Failed to generate code for augmentable node " +
- getName() + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + " " + e.getLocalizedMessage());
- }
- }
-
- /**
- * Returns true if augment does not have choice as target node.
- *
- * @return true if augment does not have choice as target node
- */
- private boolean validateAugmentNode() {
- return !(getAugmentedNode() instanceof YangChoice);
- }
-
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaCaseTranslator.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaCaseTranslator.java
deleted file mode 100644
index eccbf1c..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaCaseTranslator.java
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.yangutils.translator.tojava.javamodel;
-
-import java.io.IOException;
-
-import org.onosproject.yangutils.datamodel.javadatamodel.YangJavaCase;
-import org.onosproject.yangutils.translator.exception.TranslatorException;
-import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
-import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
-import org.onosproject.yangutils.translator.tojava.JavaFileInfoTranslator;
-import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
-import org.onosproject.yangutils.utils.io.YangPluginConfig;
-
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
-import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateCodeOfAugmentableNode;
-import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateJava;
-
-/**
- * Represents case information extended to support java code generation.
- */
-public class YangJavaCaseTranslator
- extends YangJavaCase
- implements JavaCodeGeneratorInfo, JavaCodeGenerator {
-
- private static final long serialVersionUID = 806201631L;
-
- /**
- * File handle to maintain temporary java code fragments as per the code
- * snippet types.
- */
- private transient TempJavaCodeFragmentFiles tempFileHandle;
-
- /**
- * Creates YANG java case object.
- */
- public YangJavaCaseTranslator() {
- super();
- setJavaFileInfo(new JavaFileInfoTranslator());
- getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER);
- }
-
- /**
- * Returns the generated java file information.
- *
- * @return generated java file information
- */
- @Override
- public JavaFileInfoTranslator getJavaFileInfo() {
- if (javaFileInfo == null) {
- throw new TranslatorException("Missing java info in java datamodel node" +
- getName() + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName());
- }
- return (JavaFileInfoTranslator) javaFileInfo;
- }
-
- /**
- * Sets the java file info object.
- *
- * @param javaInfo java file info object
- */
- @Override
- public void setJavaFileInfo(JavaFileInfoTranslator javaInfo) {
- javaFileInfo = javaInfo;
- }
-
- /**
- * Returns the temporary file handle.
- *
- * @return temporary file handle
- */
- @Override
- public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
- return tempFileHandle;
- }
-
- /**
- * Sets temporary file handle.
- *
- * @param fileHandle temporary file handle
- */
- @Override
- public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
- tempFileHandle = fileHandle;
- }
-
- /**
- * Prepare the information for java code generation corresponding to YANG
- * case info.
- *
- * @param yangPlugin YANG plugin config
- * @throws TranslatorException translator operation fail
- */
- @Override
- public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
- try {
- if (getReferredSchema() != null) {
- return;
- }
- generateCodeOfAugmentableNode(this, yangPlugin);
- } catch (IOException e) {
- throw new TranslatorException(
- "Failed to prepare generate code entry for case node " +
- getName() + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + " " + e.getLocalizedMessage());
- }
- }
-
- /**
- * Creates a java file using the YANG case info.
- */
- @Override
- public void generateCodeExit() throws TranslatorException {
- try {
- generateJava(GENERATE_INTERFACE_WITH_BUILDER, this);
- } catch (IOException e) {
- throw new TranslatorException("Failed to generate code for case node " +
- getName() + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + " " + e.getLocalizedMessage());
- }
- }
-
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaChoiceTranslator.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaChoiceTranslator.java
deleted file mode 100644
index 0caf8cc..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaChoiceTranslator.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.yangutils.translator.tojava.javamodel;
-
-import java.io.IOException;
-
-import org.onosproject.yangutils.datamodel.javadatamodel.YangJavaChoice;
-import org.onosproject.yangutils.translator.exception.InvalidNodeForTranslatorException;
-import org.onosproject.yangutils.translator.exception.TranslatorException;
-import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
-import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
-import org.onosproject.yangutils.translator.tojava.JavaFileInfoTranslator;
-import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
-import org.onosproject.yangutils.utils.io.YangPluginConfig;
-
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
-import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateCodeAndUpdateInParent;
-import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateJava;
-
-/**
- * Represents choice information extended to support java code generation.
- */
-public class YangJavaChoiceTranslator
- extends YangJavaChoice
- implements JavaCodeGeneratorInfo, JavaCodeGenerator {
-
- private static final long serialVersionUID = 806201631L;
-
- /**
- * File handle to maintain temporary java code fragments as per the code
- * snippet types.
- */
- private transient TempJavaCodeFragmentFiles tempFileHandle;
-
- /**
- * Creates YANG java choice object.
- */
- public YangJavaChoiceTranslator() {
- super();
- setJavaFileInfo(new JavaFileInfoTranslator());
- getJavaFileInfo().setGeneratedFileTypes(INTERFACE_MASK);
- }
-
- /**
- * Returns the generated java file information.
- *
- * @return generated java file information
- */
- @Override
- public JavaFileInfoTranslator getJavaFileInfo() {
- if (javaFileInfo == null) {
- throw new TranslatorException("Missing java info in java datamodel node" +
- getName() + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName());
- }
- return (JavaFileInfoTranslator) javaFileInfo;
- }
-
- /**
- * Sets the java file info object.
- *
- * @param javaInfo java file info object
- */
- @Override
- public void setJavaFileInfo(JavaFileInfoTranslator javaInfo) {
- javaFileInfo = javaInfo;
- }
-
- /**
- * Returns the temporary file handle.
- *
- * @return temporary file handle
- */
- @Override
- public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
- return tempFileHandle;
- }
-
- /**
- * Sets temporary file handle.
- *
- * @param fileHandle temporary file handle
- */
- @Override
- public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
- tempFileHandle = fileHandle;
- }
-
- /**
- * Prepare the information for java code generation corresponding to YANG
- * choice info.
- *
- * @param yangPlugin YANG plugin config
- * @throws TranslatorException translator operation fail
- */
- @Override
- public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
- try {
- generateCodeAndUpdateInParent(this, yangPlugin, false);
- } catch (IOException e) {
- throw new TranslatorException(
- "Failed to prepare generate code entry for choice node " +
- getName() + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + " " + e.getLocalizedMessage());
- }
- }
-
- /**
- * Creates a java file using the YANG choice info.
- */
- @Override
- public void generateCodeExit() throws TranslatorException {
- try {
- generateJava(INTERFACE_MASK, this);
- } catch (IOException e) {
- throw new TranslatorException("Failed to generate code for choice node " +
- getName() + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + " " + e.getLocalizedMessage());
- }
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaContainerTranslator.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaContainerTranslator.java
deleted file mode 100644
index 6f9fd51..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaContainerTranslator.java
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.yangutils.translator.tojava.javamodel;
-
-import java.io.IOException;
-
-import org.onosproject.yangutils.datamodel.javadatamodel.YangJavaContainer;
-import org.onosproject.yangutils.translator.exception.InvalidNodeForTranslatorException;
-import org.onosproject.yangutils.translator.exception.TranslatorException;
-import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
-import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
-import org.onosproject.yangutils.translator.tojava.JavaFileInfoTranslator;
-import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
-import org.onosproject.yangutils.utils.io.YangPluginConfig;
-
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
-import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateCodeAndUpdateInParent;
-import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateJava;
-
-/**
- * Represents container information extended to support java code generation.
- */
-public class YangJavaContainerTranslator
- extends YangJavaContainer
- implements JavaCodeGeneratorInfo, JavaCodeGenerator {
-
- private static final long serialVersionUID = 806201630L;
-
- /**
- * File handle to maintain temporary java code fragments as per the code
- * snippet types.
- */
- private transient TempJavaCodeFragmentFiles tempFileHandle;
-
- /**
- * Creates YANG java container object.
- */
- public YangJavaContainerTranslator() {
- super();
- setJavaFileInfo(new JavaFileInfoTranslator());
- getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER);
- }
-
- /**
- * Returns the generated java file information.
- *
- * @return generated java file information
- */
- @Override
- public JavaFileInfoTranslator getJavaFileInfo() {
- if (javaFileInfo == null) {
- throw new TranslatorException("Missing java info in java datamodel node " +
- getName() + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName());
- }
- return (JavaFileInfoTranslator) javaFileInfo;
- }
-
- /**
- * Sets the java file info object.
- *
- * @param javaInfo java file info object
- */
- @Override
- public void setJavaFileInfo(JavaFileInfoTranslator javaInfo) {
- javaFileInfo = javaInfo;
- }
-
- /**
- * Returns the temporary file handle.
- *
- * @return temporary file handle
- */
- @Override
- public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
- return tempFileHandle;
- }
-
- /**
- * Sets temporary file handle.
- *
- * @param fileHandle temporary file handle
- */
- @Override
- public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
- tempFileHandle = fileHandle;
- }
-
- /**
- * Prepare the information for java code generation corresponding to YANG
- * container info.
- *
- * @param yangPlugin YANG plugin config
- * @throws TranslatorException translator operation fail
- */
- @Override
- public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
- try {
- generateCodeAndUpdateInParent(this, yangPlugin, false);
- } catch (IOException e) {
- throw new TranslatorException(
- "Failed to prepare generate code entry for container node " +
- getName() + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + " " + e.getLocalizedMessage());
- }
- }
-
- /**
- * Create a java file using the YANG container info.
- *
- * @throws TranslatorException translator operation fail
- */
- @Override
- public void generateCodeExit() throws TranslatorException {
- try {
- generateJava(GENERATE_INTERFACE_WITH_BUILDER, this);
- } catch (IOException e) {
- throw new TranslatorException("Failed to generate code for container node " +
- getName() + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + " " + e.getLocalizedMessage());
- }
- }
-
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaEnumerationTranslator.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaEnumerationTranslator.java
deleted file mode 100644
index ac00154..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaEnumerationTranslator.java
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.translator.tojava.javamodel;
-
-import org.onosproject.yangutils.datamodel.javadatamodel.YangJavaEnumeration;
-import org.onosproject.yangutils.translator.exception.InvalidNodeForTranslatorException;
-import org.onosproject.yangutils.translator.exception.TranslatorException;
-import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
-import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
-import org.onosproject.yangutils.translator.tojava.JavaFileInfoTranslator;
-import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
-import org.onosproject.yangutils.utils.io.YangPluginConfig;
-
-import java.io.IOException;
-
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
-import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateCodeOfNode;
-import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateJava;
-import static org.onosproject.yangutils.translator.tojava.utils.TranslatorErrorType.FAIL_AT_ENTRY;
-import static org.onosproject.yangutils.translator.tojava.utils.TranslatorErrorType.FAIL_AT_EXIT;
-import static org.onosproject.yangutils.translator.tojava.utils.TranslatorUtils.getErrorMsg;
-
-/**
- * Represents YANG java enumeration information extended to support java code generation.
- */
-public class YangJavaEnumerationTranslator
- extends YangJavaEnumeration
- implements JavaCodeGenerator, JavaCodeGeneratorInfo {
-
- private static final long serialVersionUID = 806201629L;
-
- /**
- * File handle to maintain temporary java code fragments as per the code
- * snippet types.
- */
- private transient TempJavaCodeFragmentFiles tempFileHandle;
-
- /**
- * Creates YANG java enumeration object.
- */
- public YangJavaEnumerationTranslator() {
- setJavaFileInfo(new JavaFileInfoTranslator());
- getJavaFileInfo().setGeneratedFileTypes(GENERATE_ENUM_CLASS);
- }
-
- /**
- * Returns the generated java file information.
- *
- * @return generated java file information
- */
- @Override
- public JavaFileInfoTranslator getJavaFileInfo() {
-
- if (javaFileInfo == null) {
- throw new TranslatorException("Missing java info in java datamodel node " +
- getName());
- }
- return (JavaFileInfoTranslator) javaFileInfo;
- }
-
- /**
- * Sets the java file info object.
- *
- * @param javaInfo java file info object
- */
- @Override
- public void setJavaFileInfo(JavaFileInfoTranslator javaInfo) {
- javaFileInfo = javaInfo;
- }
-
- /**
- * Returns the temporary file handle.
- *
- * @return temporary file handle
- */
- @Override
- public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
- return tempFileHandle;
- }
-
- /**
- * Sets temporary file handle.
- *
- * @param fileHandle temporary file handle
- */
- @Override
- public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
- tempFileHandle = fileHandle;
- }
-
- /**
- * Prepare the information for java code generation corresponding to YANG
- * enumeration info.
- *
- * @param yangPlugin YANG plugin config
- * @throws TranslatorException translator operations fails
- */
- @Override
- public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
- try {
- if (getReferredSchema() != null) {
- throw new InvalidNodeForTranslatorException();
- }
- generateCodeOfNode(this, yangPlugin);
- tempFileHandle.getEnumTempFiles().setEnumClass(true);
- } catch (IOException e) {
- throw new TranslatorException(getErrorMsg(FAIL_AT_ENTRY, this,
- e.getLocalizedMessage()));
- }
- }
-
- /**
- * Creates a java file using the YANG enumeration info.
- *
- * @throws TranslatorException translator operation fail
- */
- @Override
- public void generateCodeExit() throws TranslatorException {
- try {
- generateJava(GENERATE_ENUM_CLASS, this);
- } catch (IOException e) {
- throw new TranslatorException(getErrorMsg(FAIL_AT_EXIT, this,
- e.getLocalizedMessage()));
- }
- }
-
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaGroupingTranslator.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaGroupingTranslator.java
deleted file mode 100644
index b36de60..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaGroupingTranslator.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.yangutils.translator.tojava.javamodel;
-
-import org.onosproject.yangutils.datamodel.javadatamodel.YangJavaGrouping;
-import org.onosproject.yangutils.translator.exception.InvalidNodeForTranslatorException;
-import org.onosproject.yangutils.translator.exception.TranslatorException;
-import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
-import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
-import org.onosproject.yangutils.translator.tojava.JavaFileInfoTranslator;
-import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
-import org.onosproject.yangutils.utils.io.YangPluginConfig;
-
-import java.io.IOException;
-
-import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.updatePackageInfo;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.createPackage;
-
-/**
- * Represents grouping information extended to support java code generation.
- */
-public class YangJavaGroupingTranslator
- extends YangJavaGrouping
- implements JavaCodeGeneratorInfo, JavaCodeGenerator {
-
- private static final long serialVersionUID = 806201628L;
-
- /**
- * File handle to maintain temporary java code fragments as per the code
- * snippet types.
- */
- private transient TempJavaCodeFragmentFiles tempFileHandle;
-
- /**
- * Creates YANG Java grouping object.
- */
- public YangJavaGroupingTranslator() {
- super();
- setJavaFileInfo(new JavaFileInfoTranslator());
- }
-
- /**
- * Returns the generated java file information.
- *
- * @return generated java file information
- */
- @Override
- public JavaFileInfoTranslator getJavaFileInfo() {
- if (javaFileInfo == null) {
- throw new TranslatorException("Missing java info in java datamodel node " +
- getName() + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName());
- }
- return (JavaFileInfoTranslator) javaFileInfo;
- }
-
- /**
- * Sets the java file info object.
- *
- * @param javaInfo java file info object
- */
- @Override
- public void setJavaFileInfo(JavaFileInfoTranslator javaInfo) {
- javaFileInfo = javaInfo;
- }
-
- /**
- * Returns the temporary file handle.
- *
- * @return temporary file handle
- */
- @Override
- public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
- return tempFileHandle;
- }
-
- /**
- * Sets temporary file handle.
- *
- * @param fileHandle temporary file handle
- */
- @Override
- public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
- tempFileHandle = fileHandle;
- }
-
-
- @Override
- public void generateCodeEntry(YangPluginConfig yangPlugin)
- throws TranslatorException {
- updatePackageInfo(this, yangPlugin);
- }
-
- @Override
- public void generateCodeExit()
- throws TranslatorException, IOException {
- createPackage(this);
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaIdentityTranslator.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaIdentityTranslator.java
deleted file mode 100644
index a63bca0..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaIdentityTranslator.java
+++ /dev/null
@@ -1,180 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.yangutils.translator.tojava.javamodel;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.List;
-
-import org.onosproject.yangutils.datamodel.javadatamodel.YangJavaIdentity;
-import org.onosproject.yangutils.translator.exception.TranslatorException;
-import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
-import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
-import org.onosproject.yangutils.translator.tojava.JavaFileInfoTranslator;
-import org.onosproject.yangutils.translator.tojava.JavaImportData;
-import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator;
-import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
-import org.onosproject.yangutils.utils.io.YangPluginConfig;
-
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_IDENTITY_CLASS;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
-import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.updatePackageInfo;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getFileObject;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.initiateJavaFileGeneration;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.createPackage;
-import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.closeFile;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.validateLineLength;
-
-/**
- * Represents input information extended to support java code generation.
- */
-public class YangJavaIdentityTranslator extends YangJavaIdentity
- implements JavaCodeGeneratorInfo, JavaCodeGenerator {
-
- //File type extension for java classes.
- private static final String JAVA_FILE_EXTENSION = ".java";
-
- //Contains the information of the imported.
- private transient JavaImportData importData;
-
- /**
- * File handle to maintain temporary java code fragments as per the code
- * snippet types.
- */
- private transient TempJavaCodeFragmentFiles tempFileHandle;
-
- /**
- * Creates YANG java container object.
- */
- public YangJavaIdentityTranslator() {
- setJavaFileInfo(new JavaFileInfoTranslator());
- getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER);
- importData = new JavaImportData();
- }
-
- /**
- * Returns the generated java file information.
- *
- * @return generated java file information
- */
- @Override
- public JavaFileInfoTranslator getJavaFileInfo() {
- if (javaFileInfo == null) {
- throw new TranslatorException("Missing java info in java datamodel node " +
- getName() + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName());
- }
- return (JavaFileInfoTranslator) javaFileInfo;
- }
-
- /**
- * Sets the java file info object.
- *
- * @param javaInfo java file info object
- */
- @Override
- public void setJavaFileInfo(JavaFileInfoTranslator javaInfo) {
- javaFileInfo = javaInfo;
- }
-
- /**
- * Returns the temporary file handle.
- *
- * @return temporary file handle
- */
- @Override
- public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
- return tempFileHandle;
- }
-
- /**
- * Sets temporary file handle.
- *
- * @param fileHandle temporary file handle
- */
- @Override
- public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
- tempFileHandle = fileHandle;
- }
-
- /**
- * Prepare the information for java code generation corresponding to YANG
- * container info.
- *
- * @param yangPlugin YANG plugin config
- * @throws TranslatorException translator operation fail
- */
- @Override
- public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
- try {
-
- updatePackageInfo(this, yangPlugin);
- JavaQualifiedTypeInfoTranslator basePkgInfo = new JavaQualifiedTypeInfoTranslator();
- String className = getCapitalCase(getJavaFileInfo().getJavaName());
- String path = getJavaFileInfo().getPackageFilePath();
- createPackage(this);
- List<String> imports = null;
- boolean isQualified;
-
- if (getBaseNode() != null && getBaseNode().getReferredIdentity() != null) {
- if (!(getBaseNode().getReferredIdentity() instanceof YangJavaIdentityTranslator)) {
- throw new TranslatorException("Failed to prepare generate code entry for base node "
- + getName() + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName());
- }
- YangJavaIdentityTranslator baseIdentity = (YangJavaIdentityTranslator) getBaseNode()
- .getReferredIdentity();
- String baseClassName = getCapitalCase(baseIdentity.getJavaFileInfo().getJavaName());
- String basePkg = baseIdentity.getJavaFileInfo().getPackage();
- basePkgInfo.setClassInfo(baseClassName);
- basePkgInfo.setPkgInfo(basePkg);
- isQualified = importData.addImportInfo(basePkgInfo, className, getJavaFileInfo().getPackage());
- if (!isQualified) {
- imports = importData.getImports();
- }
- }
-
- File file = getFileObject(path, className, JAVA_FILE_EXTENSION, getJavaFileInfo());
-
- initiateJavaFileGeneration(file, GENERATE_IDENTITY_CLASS, imports, this, className);
- file = validateLineLength(file);
- closeFile(file, false);
- } catch (IOException e) {
- throw new TranslatorException(
- "Failed to prepare generate code entry for identity node " +
- getName() + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName());
- }
- }
-
- /**
- * Create a java file using the YANG container info.
- *
- * @throws TranslatorException translator operation fail
- */
- @Override
- public void generateCodeExit() throws TranslatorException {
- /* Do nothing, file is already generated in entry*/
- }
-}
-
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaInputTranslator.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaInputTranslator.java
deleted file mode 100644
index 878a591..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaInputTranslator.java
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.translator.tojava.javamodel;
-
-import java.io.IOException;
-
-import org.onosproject.yangutils.datamodel.javadatamodel.YangJavaInput;
-import org.onosproject.yangutils.translator.exception.TranslatorException;
-import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
-import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
-import org.onosproject.yangutils.translator.tojava.JavaFileInfoTranslator;
-import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
-import org.onosproject.yangutils.utils.io.YangPluginConfig;
-
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
-import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateCodeOfAugmentableNode;
-
-/**
- * Represents input information extended to support java code generation.
- */
-public class YangJavaInputTranslator
- extends YangJavaInput
- implements JavaCodeGeneratorInfo, JavaCodeGenerator {
-
- private static final long serialVersionUID = 806201627L;
-
- /**
- * File handle to maintain temporary java code fragments as per the code
- * snippet types.
- */
- private transient TempJavaCodeFragmentFiles tempFileHandle;
-
- /**
- * Creates an instance of java input.
- */
- public YangJavaInputTranslator() {
- super();
- setJavaFileInfo(new JavaFileInfoTranslator());
- getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER);
- }
-
- /**
- * Returns the generated java file information.
- *
- * @return generated java file information
- */
- @Override
- public JavaFileInfoTranslator getJavaFileInfo() {
- if (javaFileInfo == null) {
- throw new TranslatorException("missing java info in java datamodel node " +
- getName() + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName());
- }
- return (JavaFileInfoTranslator) javaFileInfo;
- }
-
- /**
- * Sets the java file info object.
- *
- * @param javaInfo java file info object
- */
- @Override
- public void setJavaFileInfo(JavaFileInfoTranslator javaInfo) {
- javaFileInfo = javaInfo;
- }
-
- /**
- * Returns the temporary file handle.
- *
- * @return temporary file handle
- */
- @Override
- public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
- return tempFileHandle;
- }
-
- /**
- * Sets temporary file handle.
- *
- * @param fileHandle temporary file handle
- */
- @Override
- public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
- tempFileHandle = fileHandle;
- }
-
- /**
- * Prepare the information for java code generation corresponding to YANG
- * input info.
- *
- * @param yangPlugin YANG plugin config
- * @throws TranslatorException translator operation fail
- */
- @Override
- public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
- try {
- generateCodeOfAugmentableNode(this, yangPlugin);
- } catch (IOException e) {
- throw new TranslatorException(
- "Failed to prepare generate code entry for input node " +
- getName() + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + " " + e.getLocalizedMessage());
- }
- }
-
- /**
- * Creates a java file using the YANG input info.
- *
- * @throws TranslatorException translator operation fail
- */
- @Override
- public void generateCodeExit() throws TranslatorException {
- try {
- getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
- } catch (IOException e) {
- throw new TranslatorException("Failed to generate code for input node " +
- getName() + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + " " + e.getLocalizedMessage());
- }
- }
-
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaLeafListTranslator.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaLeafListTranslator.java
deleted file mode 100644
index c79d86b..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaLeafListTranslator.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.yangutils.translator.tojava.javamodel;
-
-import org.onosproject.yangutils.datamodel.javadatamodel.YangJavaLeafList;
-import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator;
-import org.onosproject.yangutils.utils.io.YangToJavaNamingConflictUtil;
-
-import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator.updateLeavesJavaQualifiedInfo;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
-
-/**
- * Represents java information corresponding to the YANG leaf-list.
- */
-public class YangJavaLeafListTranslator
- extends YangJavaLeafList
- implements JavaLeafInfoContainer {
-
- private static final long serialVersionUID = 806201638L;
-
- private transient YangToJavaNamingConflictUtil conflictResolveConfig;
-
- /**
- * Returns a new YANG leaf object with java qualified access details.
- */
- public YangJavaLeafListTranslator() {
- super();
- setJavaQualifiedInfo(new JavaQualifiedTypeInfoTranslator());
- }
-
- @Override
- public String getJavaName(YangToJavaNamingConflictUtil conflictResolveConfig) {
- return getCamelCase(getName(), conflictResolveConfig);
- }
-
- @Override
- public boolean isLeafList() {
- return true;
- }
-
- @Override
- public void updateJavaQualifiedInfo() {
- updateLeavesJavaQualifiedInfo(this);
- }
-
- /**
- * Returns java naming conflict resolve configurations.
- *
- * @return java naming conflict resolve configurations
- */
- @Override
- public YangToJavaNamingConflictUtil getConflictResolveConfig() {
- return conflictResolveConfig;
- }
-
- /**
- * Sets java naming conflict resolve configurations.
- *
- * @param conflictResolveConfig java naming conflict resolve configurations
- */
- @Override
- public void setConflictResolveConfig(YangToJavaNamingConflictUtil conflictResolveConfig) {
- this.conflictResolveConfig = conflictResolveConfig;
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaLeafTranslator.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaLeafTranslator.java
deleted file mode 100644
index a846e59..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaLeafTranslator.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.yangutils.translator.tojava.javamodel;
-
-import org.onosproject.yangutils.datamodel.javadatamodel.YangJavaLeaf;
-import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator;
-import org.onosproject.yangutils.utils.io.YangToJavaNamingConflictUtil;
-
-import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator.updateLeavesJavaQualifiedInfo;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
-
-/**
- * Represents java information corresponding to the YANG leaf.
- */
-public class YangJavaLeafTranslator
- extends YangJavaLeaf
- implements JavaLeafInfoContainer {
-
- private static final long serialVersionUID = 806201636L;
-
- private transient YangToJavaNamingConflictUtil conflictResolveConfig;
-
- /**
- * Returns a new YANG leaf object with java qualified access details.
- */
- public YangJavaLeafTranslator() {
- super();
- setJavaQualifiedInfo(new JavaQualifiedTypeInfoTranslator());
- }
-
- @Override
- public String getJavaName(YangToJavaNamingConflictUtil conflictResolveConfig) {
- return getCamelCase(getName(), conflictResolveConfig);
- }
-
- @Override
- public boolean isLeafList() {
- return false;
- }
-
- @Override
- public void updateJavaQualifiedInfo() {
- updateLeavesJavaQualifiedInfo(this);
- }
-
- /**
- * Returns java naming conflict resolve configurations.
- *
- * @return java naming conflict resolve configurations
- */
- @Override
- public YangToJavaNamingConflictUtil getConflictResolveConfig() {
- return conflictResolveConfig;
- }
-
- /**
- * Sets java naming conflict resolve configurations.
- *
- * @param conflictResolveConfig java naming conflict resolve configurations
- */
- @Override
- public void setConflictResolveConfig(YangToJavaNamingConflictUtil conflictResolveConfig) {
- this.conflictResolveConfig = conflictResolveConfig;
- }
-
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaListTranslator.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaListTranslator.java
deleted file mode 100644
index d8f26bd..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaListTranslator.java
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.yangutils.translator.tojava.javamodel;
-
-import java.io.IOException;
-
-import org.onosproject.yangutils.datamodel.javadatamodel.YangJavaList;
-import org.onosproject.yangutils.translator.exception.InvalidNodeForTranslatorException;
-import org.onosproject.yangutils.translator.exception.TranslatorException;
-import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
-import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
-import org.onosproject.yangutils.translator.tojava.JavaFileInfoTranslator;
-import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
-import org.onosproject.yangutils.utils.io.YangPluginConfig;
-
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
-import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateCodeAndUpdateInParent;
-import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateJava;
-
-/**
- * Represents YANG list information extended to support java code generation.
- */
-public class YangJavaListTranslator
- extends YangJavaList
- implements JavaCodeGeneratorInfo, JavaCodeGenerator {
-
- private static final long serialVersionUID = 806201626L;
-
- /**
- * File handle to maintain temporary java code fragments as per the code
- * snippet types.
- */
- private transient TempJavaCodeFragmentFiles tempFileHandle;
-
- /**
- * Creates YANG java list object.
- */
- public YangJavaListTranslator() {
- super();
- setJavaFileInfo(new JavaFileInfoTranslator());
- getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER);
- }
-
- /**
- * Returns the generated java file information.
- *
- * @return generated java file information
- */
- @Override
- public JavaFileInfoTranslator getJavaFileInfo() {
- if (javaFileInfo == null) {
- throw new TranslatorException("Missing java info in java datamodel node " +
- getName() + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName());
- }
- return (JavaFileInfoTranslator) javaFileInfo;
- }
-
- /**
- * Sets the java file info object.
- *
- * @param javaInfo java file info object
- */
- @Override
- public void setJavaFileInfo(JavaFileInfoTranslator javaInfo) {
- javaFileInfo = javaInfo;
- }
-
- /**
- * Returns the temporary file handle.
- *
- * @return temporary file handle
- */
- @Override
- public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
- return tempFileHandle;
- }
-
- /**
- * Sets temporary file handle.
- *
- * @param fileHandle temporary file handle
- */
- @Override
- public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
- tempFileHandle = fileHandle;
- }
-
- /**
- * Prepare the information for java code generation corresponding to YANG
- * list info.
- *
- * @param yangPlugin YANG plugin config
- * @throws TranslatorException translator operation fail
- */
- @Override
- public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
- try {
- generateCodeAndUpdateInParent(this, yangPlugin, true);
- } catch (IOException e) {
- throw new TranslatorException(
- "Failed to prepare generate code entry for list node " +
- getName() + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + " " + e.getLocalizedMessage());
- }
- }
-
- /**
- * Creates a java file using the YANG list info.
- *
- * @throws TranslatorException translator operation fail
- */
- @Override
- public void generateCodeExit() throws TranslatorException {
- try {
- generateJava(GENERATE_INTERFACE_WITH_BUILDER, this);
- } catch (IOException e) {
- throw new TranslatorException("Failed to generate code for list node " +
- getName() + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + " " + e.getLocalizedMessage());
- }
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaModuleTranslator.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaModuleTranslator.java
deleted file mode 100644
index e0b0dad..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaModuleTranslator.java
+++ /dev/null
@@ -1,229 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.yangutils.translator.tojava.javamodel;
-
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.YangNotification;
-import org.onosproject.yangutils.datamodel.javadatamodel.YangJavaModule;
-import org.onosproject.yangutils.translator.exception.TranslatorException;
-import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
-import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
-import org.onosproject.yangutils.translator.tojava.JavaFileInfoTranslator;
-import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
-import org.onosproject.yangutils.utils.io.YangPluginConfig;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-import static java.util.Collections.unmodifiableList;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ALL_EVENT_CLASS_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
-import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateCodeOfRootNode;
-import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isRootNodesCodeGenRequired;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
-import static org.onosproject.yangutils.translator.tojava.utils.TranslatorErrorType.FAIL_AT_ENTRY;
-import static org.onosproject.yangutils.translator.tojava.utils.TranslatorErrorType.FAIL_AT_EXIT;
-import static org.onosproject.yangutils.translator.tojava.utils.TranslatorUtils.getErrorMsg;
-import static org.onosproject.yangutils.utils.UtilConstants.SBI;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.removeEmptyDirectory;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.searchAndDeleteTempDir;
-
-/**
- * Represents module information extended to support java code generation.
- */
-public class YangJavaModuleTranslator
- extends YangJavaModule
- implements JavaCodeGeneratorInfo, JavaCodeGenerator {
-
- private static final long serialVersionUID = 806201625L;
-
- /**
- * File handle to maintain temporary java code fragments as per the code
- * snippet types.
- */
- private transient TempJavaCodeFragmentFiles tempFileHandle;
-
- /**
- * List of notifications nodes.
- */
- private final transient List<YangNode> notificationNodes;
-
- /**
- * Creates a YANG node of module type.
- */
- public YangJavaModuleTranslator() {
- setJavaFileInfo(new JavaFileInfoTranslator());
- notificationNodes = new ArrayList<>();
- getJavaFileInfo().setGeneratedFileTypes(
- GENERATE_SERVICE_AND_MANAGER | GENERATE_INTERFACE_WITH_BUILDER);
- }
-
- /**
- * Returns the generated java file information.
- *
- * @return generated java file information
- */
- @Override
- public JavaFileInfoTranslator getJavaFileInfo() {
- if (javaFileInfo == null) {
- throw new TranslatorException(
- "Missing java info in java datamodel node " + getName());
- }
- return (JavaFileInfoTranslator) javaFileInfo;
- }
-
- /**
- * Sets the java file info object.
- *
- * @param javaInfo java file info object
- */
- @Override
- public void setJavaFileInfo(JavaFileInfoTranslator javaInfo) {
- javaFileInfo = javaInfo;
- }
-
- /**
- * Returns the temporary file handle.
- *
- * @return temporary file handle
- */
- @Override
- public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
- return tempFileHandle;
- }
-
- /**
- * Sets temporary file handle.
- *
- * @param fileHandle temporary file handle
- */
- @Override
- public void setTempJavaCodeFragmentFiles(
- TempJavaCodeFragmentFiles fileHandle) {
- tempFileHandle = fileHandle;
- }
-
- /**
- * Generates java code for module.
- *
- * @param yangPlugin YANG plugin config
- * @throws TranslatorException when fails to generate the source files
- */
- @Override
- public void generateCodeEntry(YangPluginConfig yangPlugin)
- throws TranslatorException {
- String modulePkg = getRootPackage(getVersion(), getModuleNamespace(),
- getRevision(),
- yangPlugin.getConflictResolver());
-
- if (isNotificationChildNodePresent(this)) {
- getJavaFileInfo().setGeneratedFileTypes(
- getJavaFileInfo().getGeneratedFileTypes()
- | GENERATE_ALL_EVENT_CLASS_MASK);
- }
- try {
- generateCodeOfRootNode(this, yangPlugin, modulePkg);
- //Add augmented rpc name
- tempFileHandle.getServiceTempFiles().addAugmentedRpcMethod(this);
- } catch (IOException e) {
- throw new TranslatorException(getErrorMsg(FAIL_AT_ENTRY, this,
- e.getLocalizedMessage()));
- }
- }
-
- /**
- * Creates a java file using the YANG module info.
- */
- @Override
- public void generateCodeExit()
- throws TranslatorException {
- /*
- * As part of the notification support the following files needs to be generated.
- * 1) Subject of the notification(event), this is simple interface with builder class.
- * 2) Event class extending "AbstractEvent" and defining event type enum.
- * 3) Event listener interface extending "EventListener".
- * 4) Event subject class.
- *
- * The manager class needs to extend the "ListenerRegistry".
- */
- try {
- if ((getJavaFileInfo().getGeneratedFileTypes() &
- GENERATE_ALL_EVENT_CLASS_MASK) != 0) {
- getTempJavaCodeFragmentFiles().generateJavaFile(
- GENERATE_ALL_EVENT_CLASS_MASK, this);
- }
-
- if (isRootNodesCodeGenRequired(this)) {
- getTempJavaCodeFragmentFiles()
- .generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
- if (getJavaFileInfo().getPluginConfig()
- .getCodeGenerateForSbi() == null ||
- !getJavaFileInfo().getPluginConfig()
- .getCodeGenerateForSbi().equals(SBI)) {
- getTempJavaCodeFragmentFiles()
- .generateJavaFile(GENERATE_SERVICE_AND_MANAGER, this);
- }
- }
-
- searchAndDeleteTempDir(getJavaFileInfo().getBaseCodeGenPath() +
- getJavaFileInfo().getPackageFilePath());
- removeEmptyDirectory(getJavaFileInfo().getBaseCodeGenPath() +
- getJavaFileInfo().getPackageFilePath());
- } catch (IOException e) {
- throw new TranslatorException(getErrorMsg(FAIL_AT_EXIT, this,
- e.getLocalizedMessage()));
- }
- }
-
- /**
- * Returns notifications node list.
- *
- * @return notification nodes
- */
- public List<YangNode> getNotificationNodes() {
- return unmodifiableList(notificationNodes);
- }
-
- /**
- * Adds to notification node list.
- *
- * @param curNode notification node
- */
- private void addToNotificationList(YangNode curNode) {
- notificationNodes.add(curNode);
- }
-
- /**
- * Checks if there is any notification node present.
- *
- * @param rootNode root node of the data model
- * @return status of notification's existence
- */
- private boolean isNotificationChildNodePresent(YangNode rootNode) {
- YangNode childNode = rootNode.getChild();
-
- while (childNode != null) {
- if (childNode instanceof YangNotification) {
- addToNotificationList(childNode);
- }
- childNode = childNode.getNextSibling();
- }
-
- return !notificationNodes.isEmpty();
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaNotificationTranslator.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaNotificationTranslator.java
deleted file mode 100644
index 5d6f45d..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaNotificationTranslator.java
+++ /dev/null
@@ -1,192 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.translator.tojava.javamodel;
-
-import org.onosproject.yangutils.datamodel.RpcNotificationContainer;
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.javadatamodel.YangJavaNotification;
-import org.onosproject.yangutils.translator.exception.TranslatorException;
-import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
-import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
-import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
-import org.onosproject.yangutils.translator.tojava.JavaFileInfoTranslator;
-import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator;
-import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
-import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer;
-import org.onosproject.yangutils.translator.tojava.TempJavaServiceFragmentFiles;
-import org.onosproject.yangutils.translator.tojava.utils.JavaExtendsListHolder;
-import org.onosproject.yangutils.utils.io.YangPluginConfig;
-
-import java.io.IOException;
-
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
-import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateCodeOfAugmentableNode;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getEnumJavaAttribute;
-import static org.onosproject.yangutils.translator.tojava.utils.TranslatorErrorType.FAIL_AT_ENTRY;
-import static org.onosproject.yangutils.translator.tojava.utils.TranslatorErrorType.FAIL_AT_EXIT;
-import static org.onosproject.yangutils.translator.tojava.utils.TranslatorErrorType.INVALID_NODE;
-import static org.onosproject.yangutils.translator.tojava.utils.TranslatorUtils.getErrorMsg;
-import static org.onosproject.yangutils.utils.UtilConstants.EVENT_LISTENER_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.EVENT_STRING;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
-
-/**
- * Represents notification information extended to support java code generation.
- */
-public class YangJavaNotificationTranslator
- extends YangJavaNotification
- implements JavaCodeGenerator, JavaCodeGeneratorInfo {
-
- private static final long serialVersionUID = 806201624L;
-
- /**
- * File handle to maintain temporary java code fragments as per the code
- * snippet types.
- */
- private transient TempJavaCodeFragmentFiles tempFileHandle;
-
- /**
- * Creates an instance of java Notification.
- */
- public YangJavaNotificationTranslator() {
- setJavaFileInfo(new JavaFileInfoTranslator());
- getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER);
- }
-
- /**
- * Returns the generated java file information.
- *
- * @return generated java file information
- */
- @Override
- public JavaFileInfoTranslator getJavaFileInfo() {
-
- if (javaFileInfo == null) {
- throw new TranslatorException(getErrorMsg(INVALID_NODE, this));
- }
- return (JavaFileInfoTranslator) javaFileInfo;
- }
-
- /**
- * Sets the java file info object.
- *
- * @param javaInfo java file info object
- */
- @Override
- public void setJavaFileInfo(JavaFileInfoTranslator javaInfo) {
- javaFileInfo = javaInfo;
- }
-
- /**
- * Returns the temporary file handle.
- *
- * @return temporary file handle
- */
- @Override
- public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
- return tempFileHandle;
- }
-
- /**
- * Sets temporary file handle.
- *
- * @param fileHandle temporary file handle
- */
- @Override
- public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
- tempFileHandle = fileHandle;
- }
-
- /**
- * Prepare the information for java code generation corresponding to YANG
- * notification info.
- *
- * @param yangPlugin YANG plugin config
- * @throws TranslatorException translator operation fail
- */
- @Override
- public void generateCodeEntry(YangPluginConfig yangPlugin)
- throws TranslatorException {
-
- // Obtain the notification name as per enum in notification.
- String enumName = getEnumJavaAttribute(getName().toUpperCase());
- ((RpcNotificationContainer) getParent())
- .addToNotificationEnumMap(enumName, this);
-
- /*
- * As part of the notification support the following files needs to be
- * generated.
- * 1) Subject of the notification(event), this is simple interface with
- * builder class.
- * 2) Event class extending "AbstractEvent" and defining event type
- * enum.
- * 3) Event listener interface extending "EventListener".
- *
- * The manager class needs to extend the ListenerRegistry.
- */
-
- // Generate subject of the notification(event), this is simple interface
- // with builder class.
- try {
- generateCodeOfAugmentableNode(this, yangPlugin);
- addNotificationToExtendsList();
- } catch (IOException e) {
- throw new TranslatorException(getErrorMsg(FAIL_AT_ENTRY, this,
- e.getLocalizedMessage()));
- }
- }
-
- /*Adds current notification info to the extends list so its parents service*/
- private void addNotificationToExtendsList() {
- YangNode parent = getParent();
- TempJavaServiceFragmentFiles tempFiles =
- ((TempJavaCodeFragmentFilesContainer) parent).getTempJavaCodeFragmentFiles()
- .getServiceTempFiles();
- JavaExtendsListHolder holder = tempFiles.getJavaExtendsListHolder();
- JavaQualifiedTypeInfoTranslator event =
- new JavaQualifiedTypeInfoTranslator();
-
- String parentInfo = getCapitalCase(((JavaFileInfoContainer) parent)
- .getJavaFileInfo()
- .getJavaName());
- event.setClassInfo(parentInfo + EVENT_STRING);
- event.setPkgInfo(getJavaFileInfo().getPackage());
- holder.addToExtendsList(event, parent, tempFiles);
-
- JavaQualifiedTypeInfoTranslator eventListener =
- new JavaQualifiedTypeInfoTranslator();
-
- eventListener.setClassInfo(parentInfo + EVENT_LISTENER_STRING);
- eventListener.setPkgInfo(getJavaFileInfo().getPackage());
- holder.addToExtendsList(eventListener, parent, tempFiles);
- }
-
- /**
- * Creates a java file using the YANG notification info.
- */
- @Override
- public void generateCodeExit()
- throws TranslatorException {
- try {
- getTempJavaCodeFragmentFiles().generateJavaFile(
- GENERATE_INTERFACE_WITH_BUILDER, this);
- } catch (IOException e) {
- throw new TranslatorException(getErrorMsg(FAIL_AT_EXIT, this,
- e.getLocalizedMessage()));
- }
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaOutputTranslator.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaOutputTranslator.java
deleted file mode 100644
index fe640ea..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaOutputTranslator.java
+++ /dev/null
@@ -1,144 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.translator.tojava.javamodel;
-
-import java.io.IOException;
-
-import org.onosproject.yangutils.datamodel.javadatamodel.YangJavaOutput;
-import org.onosproject.yangutils.translator.exception.TranslatorException;
-import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
-import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
-import org.onosproject.yangutils.translator.tojava.JavaFileInfoTranslator;
-import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
-import org.onosproject.yangutils.utils.io.YangPluginConfig;
-
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
-import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateCodeOfAugmentableNode;
-
-/**
- * Represents output information extended to support java code generation.
- */
-public class YangJavaOutputTranslator
- extends YangJavaOutput
- implements JavaCodeGeneratorInfo, JavaCodeGenerator {
-
- private static final long serialVersionUID = 806201623L;
-
- /**
- * File handle to maintain temporary java code fragments as per the code
- * snippet types.
- */
- private transient TempJavaCodeFragmentFiles tempFileHandle;
-
- /**
- * Creates an instance of java output.
- */
- public YangJavaOutputTranslator() {
- super();
- setJavaFileInfo(new JavaFileInfoTranslator());
- getJavaFileInfo().setGeneratedFileTypes(GENERATE_INTERFACE_WITH_BUILDER);
- }
-
- /**
- * Returns the generated java file information.
- *
- * @return generated java file information
- */
- @Override
- public JavaFileInfoTranslator getJavaFileInfo() {
- if (javaFileInfo == null) {
- throw new TranslatorException("missing java info in java datamodel node " +
- getName() + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName());
- }
- return (JavaFileInfoTranslator) javaFileInfo;
- }
-
- /**
- * Sets the java file info object.
- *
- * @param javaInfo java file info object
- */
- @Override
- public void setJavaFileInfo(JavaFileInfoTranslator javaInfo) {
- javaFileInfo = javaInfo;
- }
-
- /**
- * Returns the temporary file handle.
- *
- * @return temporary file handle
- */
- @Override
- public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
- return tempFileHandle;
- }
-
- /**
- * Sets temporary file handle.
- *
- * @param fileHandle temporary file handle
- */
- @Override
- public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
- tempFileHandle = fileHandle;
- }
-
- /**
- * Prepare the information for java code generation corresponding to YANG
- * output info.
- *
- * @param yangPlugin YANG plugin config
- * @throws TranslatorException translator operation fail
- */
- @Override
- public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
- try {
- generateCodeOfAugmentableNode(this, yangPlugin);
- } catch (IOException e) {
- throw new TranslatorException(
- "Failed to prepare generate code entry for output node " +
- getName() + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + " " + e.getLocalizedMessage());
- }
-
- }
-
- /**
- * Creates a java file using the YANG output info.
- *
- * @throws TranslatorException translator operation fail
- */
- @Override
- public void generateCodeExit() throws TranslatorException {
- try {
- getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
- } catch (IOException e) {
- throw new TranslatorException(
- "Failed to prepare generate code exit for output node " +
- getName() + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + " " + e.getLocalizedMessage());
- }
- }
-
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaRpcTranslator.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaRpcTranslator.java
deleted file mode 100644
index f3b4416..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaRpcTranslator.java
+++ /dev/null
@@ -1,177 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.translator.tojava.javamodel;
-
-import org.onosproject.yangutils.datamodel.RpcNotificationContainer;
-import org.onosproject.yangutils.datamodel.YangInput;
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.YangOutput;
-import org.onosproject.yangutils.datamodel.javadatamodel.YangJavaRpc;
-import org.onosproject.yangutils.translator.exception.TranslatorException;
-import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo;
-import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
-import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
-import org.onosproject.yangutils.translator.tojava.JavaFileInfoTranslator;
-import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
-import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer;
-import org.onosproject.yangutils.translator.tojava.TempJavaServiceFragmentFiles;
-import org.onosproject.yangutils.utils.io.YangPluginConfig;
-
-import java.io.IOException;
-
-import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.getParentNodeInGenCode;
-import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.updatePackageInfo;
-import static org.onosproject.yangutils.translator.tojava.utils.TranslatorErrorType.FAIL_AT_EXIT;
-import static org.onosproject.yangutils.translator.tojava.utils.TranslatorErrorType.INVALID_CHILD_NODE;
-import static org.onosproject.yangutils.translator.tojava.utils.TranslatorErrorType.INVALID_PARENT_NODE;
-import static org.onosproject.yangutils.translator.tojava.utils.TranslatorUtils.getErrorMsg;
-
-/**
- * Represents rpc information extended to support java code generation.
- */
-public class YangJavaRpcTranslator
- extends YangJavaRpc
- implements JavaCodeGenerator, JavaCodeGeneratorInfo {
-
- private static final long serialVersionUID = 806201622L;
-
- /**
- * Temporary file for code generation.
- */
- private transient TempJavaCodeFragmentFiles tempJavaCodeFragmentFiles;
-
- /**
- * Creates an instance of YANG java rpc.
- */
- public YangJavaRpcTranslator() {
- setJavaFileInfo(new JavaFileInfoTranslator());
- }
-
- /**
- * Returns the generated java file information.
- *
- * @return generated java file information
- */
- @Override
- public JavaFileInfoTranslator getJavaFileInfo() {
-
- if (javaFileInfo == null) {
- throw new TranslatorException("missing java info in java datamodel node " +
- getName());
- }
- return (JavaFileInfoTranslator) javaFileInfo;
- }
-
- /**
- * Sets the java file info object.
- *
- * @param javaInfo java file info object
- */
- @Override
- public void setJavaFileInfo(JavaFileInfoTranslator javaInfo) {
- javaFileInfo = javaInfo;
- }
-
- @Override
- public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
- return tempJavaCodeFragmentFiles;
- }
-
- @Override
- public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
- tempJavaCodeFragmentFiles = fileHandle;
- }
-
- /**
- * Prepares the information for java code generation corresponding to YANG
- * RPC info.
- *
- * @param yangPlugin YANG plugin config
- * @throws TranslatorException translator operations fails
- */
- @Override
- public void generateCodeEntry(YangPluginConfig yangPlugin)
- throws TranslatorException {
-
- // Add package information for rpc and create corresponding folder.
- updatePackageInfo(this, yangPlugin);
- }
-
- /**
- * Creates a java file using the YANG RPC info.
- *
- * @throws TranslatorException translator operations fails
- */
- @Override
- public void generateCodeExit()
- throws TranslatorException {
- // Get the parent module/sub-module.
- YangNode parent = getParentNodeInGenCode(this);
-
- // Parent should be holder of rpc or notification.
- if (!(parent instanceof RpcNotificationContainer)) {
- throw new TranslatorException(getErrorMsg(INVALID_PARENT_NODE,
- this));
- }
-
- /*
- * Create attribute info for input and output of rpc and add it to the
- * parent import list.
- */
- TempJavaServiceFragmentFiles tempJavaFragmentFiles =
- ((TempJavaCodeFragmentFilesContainer) getParent())
- .getTempJavaCodeFragmentFiles()
- .getServiceTempFiles();
- JavaAttributeInfo javaAttributeInfoOfInput = null;
- JavaAttributeInfo javaAttributeInfoOfOutput = null;
-
- // Get the child input and output node and obtain create java attribute
- // info.
- YangNode yangNode = getChild();
- while (yangNode != null) {
- if (yangNode instanceof YangInput) {
- javaAttributeInfoOfInput = tempJavaFragmentFiles
- .getChildNodeAsAttributeInParentService(yangNode,
- getParent());
- } else if (yangNode instanceof YangOutput) {
- javaAttributeInfoOfOutput = tempJavaFragmentFiles
- .getChildNodeAsAttributeInParentService(yangNode,
- getParent());
- } else {
- throw new TranslatorException(getErrorMsg(INVALID_CHILD_NODE,
- this));
- }
- yangNode = yangNode.getNextSibling();
- }
-
- /*
- * Add the rpc information to the parent's service temp file.
- */
- try {
-
- ((TempJavaCodeFragmentFilesContainer) parent)
- .getTempJavaCodeFragmentFiles().getServiceTempFiles()
- .addJavaSnippetInfoToApplicableTempFiles(
- javaAttributeInfoOfInput, javaAttributeInfoOfOutput,
- getJavaClassNameOrBuiltInType());
- } catch (IOException e) {
- throw new TranslatorException(getErrorMsg(FAIL_AT_EXIT, this,
- e.getLocalizedMessage()));
- }
- // No file will be generated during RPC exit.
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaSubModuleTranslator.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaSubModuleTranslator.java
deleted file mode 100644
index 20fa8d2..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaSubModuleTranslator.java
+++ /dev/null
@@ -1,241 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.yangutils.translator.tojava.javamodel;
-
-import org.onosproject.yangutils.datamodel.YangModule;
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.YangNotification;
-import org.onosproject.yangutils.datamodel.javadatamodel.YangJavaSubModule;
-import org.onosproject.yangutils.translator.exception.TranslatorException;
-import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
-import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
-import org.onosproject.yangutils.translator.tojava.JavaFileInfoTranslator;
-import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
-import org.onosproject.yangutils.utils.io.YangPluginConfig;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-import static java.util.Collections.unmodifiableList;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ALL_EVENT_CLASS_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_INTERFACE_WITH_BUILDER;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
-import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateCodeOfRootNode;
-import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isRootNodesCodeGenRequired;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
-import static org.onosproject.yangutils.translator.tojava.utils.TranslatorErrorType.FAIL_AT_ENTRY;
-import static org.onosproject.yangutils.translator.tojava.utils.TranslatorErrorType.FAIL_AT_EXIT;
-import static org.onosproject.yangutils.translator.tojava.utils.TranslatorUtils.getErrorMsg;
-import static org.onosproject.yangutils.utils.UtilConstants.SBI;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.removeEmptyDirectory;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.searchAndDeleteTempDir;
-
-/**
- * Represents sub module information extended to support java code generation.
- */
-public class YangJavaSubModuleTranslator
- extends YangJavaSubModule
- implements JavaCodeGeneratorInfo, JavaCodeGenerator {
-
- private static final long serialVersionUID = 806201621L;
-
- /**
- * File handle to maintain temporary java code fragments as per the code snippet types.
- */
- private transient TempJavaCodeFragmentFiles tempFileHandle;
-
- /**
- * List of notifications nodes.
- */
- private final transient List<YangNode> notificationNodes;
-
- /**
- * Creates YANG java sub module object.
- */
- public YangJavaSubModuleTranslator() {
- setJavaFileInfo(new JavaFileInfoTranslator());
- notificationNodes = new ArrayList<>();
- int genType =
- GENERATE_SERVICE_AND_MANAGER | GENERATE_INTERFACE_WITH_BUILDER;
- if (isNotificationChildNodePresent(this)) {
- genType = GENERATE_SERVICE_AND_MANAGER | GENERATE_ALL_EVENT_CLASS_MASK;
- }
- getJavaFileInfo().setGeneratedFileTypes(genType);
- }
-
- /**
- * Returns the generated java file information.
- *
- * @return generated java file information
- */
- @Override
- public JavaFileInfoTranslator getJavaFileInfo() {
- if (javaFileInfo == null) {
- throw new TranslatorException("Missing java info in java datamodel node " +
- getName());
- }
- return (JavaFileInfoTranslator) javaFileInfo;
- }
-
- /**
- * Sets the java file info object.
- *
- * @param javaInfo java file info object
- */
- @Override
- public void setJavaFileInfo(JavaFileInfoTranslator javaInfo) {
- javaFileInfo = javaInfo;
- }
-
- /**
- * Returns the temporary file handle.
- *
- * @return temporary file handle
- */
- @Override
- public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
- return tempFileHandle;
- }
-
- /**
- * Sets temporary file handle.
- *
- * @param fileHandle temporary file handle
- */
- @Override
- public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
- tempFileHandle = fileHandle;
- }
-
- /**
- * Returns the name space of the module to which the sub module belongs to.
- *
- * @return the name space string of the module.
- */
- public String getNameSpaceFromModule() {
- return ((YangModule) (getBelongsTo().getModuleNode())).getModuleNamespace();
- }
-
- /**
- * Prepares the information for java code generation corresponding to
- * YANG submodule info.
- *
- * @param yangPlugin YANG plugin config
- * @throws TranslatorException when fails to translate
- */
- @Override
- public void generateCodeEntry(YangPluginConfig yangPlugin)
- throws TranslatorException {
- String subModulePkg = getRootPackage(
- getVersion(), getNameSpaceFromModule(), getRevision(),
- yangPlugin.getConflictResolver());
-
- if (isNotificationChildNodePresent(this)) {
- getJavaFileInfo().setGeneratedFileTypes(
- getJavaFileInfo().getGeneratedFileTypes()
- | GENERATE_ALL_EVENT_CLASS_MASK);
- }
- try {
- generateCodeOfRootNode(this, yangPlugin, subModulePkg);
- tempFileHandle.getServiceTempFiles().addAugmentedRpcMethod(
- this);
- } catch (IOException e) {
- throw new TranslatorException(getErrorMsg(FAIL_AT_ENTRY, this,
- e.getLocalizedMessage()));
- }
- }
-
- /**
- * Creates a java file using the YANG submodule info.
- */
- @Override
- public void generateCodeExit()
- throws TranslatorException {
- /*
- * As part of the notification support the following files needs to be generated.
- * 1) Subject of the notification(event), this is simple interface with builder class.
- * 2) Event class extending "AbstractEvent" and defining event type enum.
- * 3) Event listener interface extending "EventListener".
- * 4) Event subject class.
- *
- * The manager class needs to extend the "ListenerRegistry".
- */
- try {
- if ((getJavaFileInfo().getGeneratedFileTypes() &
- GENERATE_ALL_EVENT_CLASS_MASK) != 0) {
- getTempJavaCodeFragmentFiles().generateJavaFile(
- GENERATE_ALL_EVENT_CLASS_MASK, this);
- }
- if (isRootNodesCodeGenRequired(this)) {
- getTempJavaCodeFragmentFiles()
- .generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
- if (getJavaFileInfo().getPluginConfig()
- .getCodeGenerateForSbi() == null ||
- !getJavaFileInfo().getPluginConfig()
- .getCodeGenerateForSbi().equals(SBI)) {
- getTempJavaCodeFragmentFiles().generateJavaFile(
- GENERATE_SERVICE_AND_MANAGER, this);
- }
- }
-
- searchAndDeleteTempDir(getJavaFileInfo().getBaseCodeGenPath() +
- getJavaFileInfo().getPackageFilePath());
- removeEmptyDirectory(getJavaFileInfo().getBaseCodeGenPath() +
- getJavaFileInfo().getPackageFilePath());
- } catch (IOException e) {
- throw new TranslatorException(getErrorMsg(FAIL_AT_EXIT, this,
- e.getLocalizedMessage()));
- }
- }
-
- /**
- * Returns notifications node list.
- *
- * @return notification nodes
- */
- public List<YangNode> getNotificationNodes() {
- return unmodifiableList(notificationNodes);
- }
-
- /**
- * Adds to notification node list.
- *
- * @param curNode notification node
- */
- private void addToNotificationList(YangNode curNode) {
- notificationNodes.add(curNode);
- }
-
- /**
- * Checks if there is any notification node present.
- *
- * @param rootNode root node of the data model
- * @return status of notification's existence
- */
- private boolean isNotificationChildNodePresent(YangNode rootNode) {
- YangNode childNode = rootNode.getChild();
-
- while (childNode != null) {
- if (childNode instanceof YangNotification) {
- addToNotificationList(childNode);
- }
- childNode = childNode.getNextSibling();
- }
-
- return !notificationNodes.isEmpty();
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaTypeDefTranslator.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaTypeDefTranslator.java
deleted file mode 100644
index 4605c52..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaTypeDefTranslator.java
+++ /dev/null
@@ -1,162 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.yangutils.translator.tojava.javamodel;
-
-import org.onosproject.yangutils.datamodel.YangDerivedInfo;
-import org.onosproject.yangutils.datamodel.YangType;
-import org.onosproject.yangutils.datamodel.javadatamodel.YangJavaTypeDef;
-import org.onosproject.yangutils.translator.exception.InvalidNodeForTranslatorException;
-import org.onosproject.yangutils.translator.exception.TranslatorException;
-import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
-import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
-import org.onosproject.yangutils.translator.tojava.JavaFileInfoTranslator;
-import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
-import org.onosproject.yangutils.utils.io.YangPluginConfig;
-
-import java.io.IOException;
-
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.DERIVED;
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.LEAFREF;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
-import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateCodeOfNode;
-import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateJava;
-
-/**
- * Represents type define information extended to support java code generation.
- */
-public class YangJavaTypeDefTranslator
- extends YangJavaTypeDef
- implements JavaCodeGeneratorInfo, JavaCodeGenerator {
-
- private static final long serialVersionUID = 806201620L;
-
- /**
- * File handle to maintain temporary java code fragments as per the code
- * snippet types.
- */
- private transient TempJavaCodeFragmentFiles tempFileHandle;
-
- /**
- * Creates a YANG java typedef object.
- */
- public YangJavaTypeDefTranslator() {
- super();
- setJavaFileInfo(new JavaFileInfoTranslator());
- getJavaFileInfo().setGeneratedFileTypes(GENERATE_TYPEDEF_CLASS);
- }
-
- /**
- * Returns the generated java file information.
- *
- * @return generated java file information
- */
- @Override
- public JavaFileInfoTranslator getJavaFileInfo() {
-
- if (javaFileInfo == null) {
- throw new TranslatorException("Missing java info in java datamodel node " +
- getName() + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName());
- }
- return (JavaFileInfoTranslator) javaFileInfo;
- }
-
- /**
- * Sets the java file info object.
- *
- * @param javaInfo java file info object
- */
- @Override
- public void setJavaFileInfo(JavaFileInfoTranslator javaInfo) {
- javaFileInfo = javaInfo;
- }
-
- /**
- * Returns the temporary file handle.
- *
- * @return temporary file handle
- */
- @Override
- public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
- return tempFileHandle;
- }
-
- /**
- * Sets temporary file handle.
- *
- * @param fileHandle temporary file handle
- */
- @Override
- public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
- tempFileHandle = fileHandle;
- }
-
- /**
- * Prepare the information for java code generation corresponding to YANG
- * typedef info.
- *
- * @param yangPlugin YANG plugin config
- * @throws TranslatorException when fails to translate
- */
- @Override
- public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
- if (getReferredSchema() != null) {
- throw new InvalidNodeForTranslatorException();
- }
- // TODO update the below exception in all related places, remove file
- // name and other information.
- YangType typeInTypeDef = this.getTypeDefBaseType();
- InvalidNodeForTranslatorException exception = new InvalidNodeForTranslatorException();
- exception.setFileName(this.getFileName());
- exception.setCharPosition(this.getCharPosition());
- exception.setLine(this.getLineNumber());
- if (typeInTypeDef.getDataType() == DERIVED) {
- YangDerivedInfo derivedInfo = (YangDerivedInfo) typeInTypeDef.getDataTypeExtendedInfo();
- if (derivedInfo.getEffectiveBuiltInType() == LEAFREF) {
- throw exception;
- }
- } else if (typeInTypeDef.getDataType() == LEAFREF) {
- throw exception;
- }
- try {
- generateCodeOfNode(this, yangPlugin);
- } catch (IOException e) {
- throw new TranslatorException(
- "Failed to prepare generate code entry for typedef node " + getName()
- + "in " + getLineNumber() + " at " + getCharPosition() + " in " + getFileName()
- + " " + e.getLocalizedMessage());
- }
- }
-
- /**
- * Create a java file using the YANG typedef info.
- *
- * @throws TranslatorException when fails to translate
- */
- @Override
- public void generateCodeExit() throws TranslatorException {
- try {
- generateJava(GENERATE_TYPEDEF_CLASS, this);
- } catch (IOException e) {
- throw new TranslatorException(
- "Failed to prepare generate code for typedef node " + getName()
- + "in " + getLineNumber() + " at " + getCharPosition() + " in " + getFileName()
- + " " + e.getLocalizedMessage());
- }
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaTypeTranslator.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaTypeTranslator.java
deleted file mode 100644
index 93e4858..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaTypeTranslator.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.yangutils.translator.tojava.javamodel;
-
-import org.onosproject.yangutils.datamodel.javadatamodel.YangJavaType;
-import org.onosproject.yangutils.translator.exception.TranslatorException;
-import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator;
-import org.onosproject.yangutils.utils.io.YangToJavaNamingConflictUtil;
-
-import static org.onosproject.yangutils.translator.tojava.javamodel.AttributesJavaDataType.getJavaDataType;
-import static org.onosproject.yangutils.translator.tojava.javamodel.AttributesJavaDataType.getJavaImportClass;
-import static org.onosproject.yangutils.translator.tojava.javamodel.AttributesJavaDataType.getJavaImportPackage;
-
-/**
- * Represents java information corresponding to the YANG type.
- */
-public class YangJavaTypeTranslator
- extends YangJavaType
- implements JavaQualifiedTypeResolver {
-
- /**
- * Create a YANG leaf object with java qualified access details.
- */
- public YangJavaTypeTranslator() {
- super();
- setJavaQualifiedInfo(new JavaQualifiedTypeInfoTranslator());
- }
-
- @Override
- public void updateJavaQualifiedInfo(YangToJavaNamingConflictUtil conflictResolver) {
- JavaQualifiedTypeInfoTranslator importInfo = (JavaQualifiedTypeInfoTranslator) getJavaQualifiedInfo();
-
- /*
- * Type is added as an attribute in the class.
- */
- String className = getJavaImportClass(this, false, conflictResolver);
- if (className != null) {
- /*
- * Corresponding to the attribute type a class needs to be imported,
- * since it can be a derived type or a usage of wrapper classes.
- */
- importInfo.setClassInfo(className);
- String classPkg = getJavaImportPackage(this,
- false, conflictResolver);
- if (classPkg == null) {
- throw new TranslatorException("import package cannot be null when the class is used " +
- getDataTypeName() + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName());
- }
- importInfo.setPkgInfo(classPkg);
- } else {
- /*
- * The attribute does not need a class to be imported, for example
- * built in java types.
- */
- String dataTypeName = getJavaDataType(this);
- if (dataTypeName == null) {
- throw new TranslatorException("not supported data type " +
- getDataTypeName() + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName());
- }
- importInfo.setClassInfo(dataTypeName);
- }
- setJavaQualifiedInfo(importInfo);
- }
-
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaUnionTranslator.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaUnionTranslator.java
deleted file mode 100644
index ce04f68..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaUnionTranslator.java
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.yangutils.translator.tojava.javamodel;
-
-import java.io.IOException;
-
-import org.onosproject.yangutils.datamodel.javadatamodel.YangJavaUnion;
-import org.onosproject.yangutils.translator.exception.InvalidNodeForTranslatorException;
-import org.onosproject.yangutils.translator.exception.TranslatorException;
-import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
-import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
-import org.onosproject.yangutils.translator.tojava.JavaFileInfoTranslator;
-import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
-import org.onosproject.yangutils.utils.io.YangPluginConfig;
-
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
-import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateCodeOfNode;
-import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.generateJava;
-
-/**
- * Represents union information extended to support java code generation.
- */
-public class YangJavaUnionTranslator
- extends YangJavaUnion
- implements JavaCodeGeneratorInfo, JavaCodeGenerator {
-
- private static final long serialVersionUID = 806201619L;
-
- /**
- * File handle to maintain temporary java code fragments as per the code
- * snippet types.
- */
- private transient TempJavaCodeFragmentFiles tempFileHandle;
-
- /**
- * Creates an instance of YANG java union.
- */
- public YangJavaUnionTranslator() {
- super();
- setJavaFileInfo(new JavaFileInfoTranslator());
- getJavaFileInfo().setGeneratedFileTypes(GENERATE_UNION_CLASS);
- }
-
- /**
- * Returns the generated java file information.
- *
- * @return generated java file information
- */
- @Override
- public JavaFileInfoTranslator getJavaFileInfo() {
- if (javaFileInfo == null) {
- throw new RuntimeException("Missing java info in java datamodel node " + getName() + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName());
- }
- return (JavaFileInfoTranslator) javaFileInfo;
- }
-
- /**
- * Sets the java file info object.
- *
- * @param javaInfo java file info object
- */
- @Override
- public void setJavaFileInfo(JavaFileInfoTranslator javaInfo) {
- javaFileInfo = javaInfo;
- }
-
- /**
- * Returns the temporary file handle.
- *
- * @return temporary file handle
- */
- @Override
- public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
- return tempFileHandle;
- }
-
- /**
- * Sets temporary file handle.
- *
- * @param fileHandle temporary file handle
- */
- @Override
- public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
- tempFileHandle = fileHandle;
- }
-
- /**
- * Prepare the information for java code generation corresponding to YANG
- * union info.
- *
- * @param yangPlugin YANG plugin config
- * @throws TranslatorException when fails to translate
- */
- @Override
- public void generateCodeEntry(YangPluginConfig yangPlugin) throws TranslatorException {
- try {
- if (getReferredSchema() != null) {
- throw new InvalidNodeForTranslatorException();
- }
- generateCodeOfNode(this, yangPlugin);
- } catch (IOException e) {
- throw new TranslatorException(
- "Failed to prepare generate code entry for union node " + getName() + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + " " + e.getLocalizedMessage());
- }
-
- }
-
- /**
- * Creates a java file using the YANG union info.
- *
- * @throws TranslatorException when fails to translate
- */
- @Override
- public void generateCodeExit() throws TranslatorException {
- try {
- generateJava(GENERATE_UNION_CLASS, this);
- } catch (IOException e) {
- throw new TranslatorException("Failed to generate code for union node " + getName() + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName() + " " + e.getLocalizedMessage());
- }
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaUsesTranslator.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaUsesTranslator.java
deleted file mode 100644
index a213faf..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/YangJavaUsesTranslator.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.yangutils.translator.tojava.javamodel;
-
-import org.onosproject.yangutils.datamodel.javadatamodel.YangJavaUses;
-import org.onosproject.yangutils.translator.exception.InvalidNodeForTranslatorException;
-import org.onosproject.yangutils.translator.exception.TranslatorException;
-import org.onosproject.yangutils.translator.tojava.JavaCodeGenerator;
-import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
-import org.onosproject.yangutils.translator.tojava.JavaFileInfoTranslator;
-import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
-import org.onosproject.yangutils.utils.io.YangPluginConfig;
-
-/**
- * Represents uses information extended to support java code generation.
- */
-public class YangJavaUsesTranslator
- extends YangJavaUses
- implements JavaCodeGeneratorInfo, JavaCodeGenerator {
-
- private static final long serialVersionUID = 806201618L;
-
- /**
- * File handle to maintain temporary java code fragments as per the code
- * snippet types.
- */
- private transient TempJavaCodeFragmentFiles tempFileHandle;
-
- /**
- * Creates YANG java uses object.
- */
- public YangJavaUsesTranslator() {
- super();
- setJavaFileInfo(new JavaFileInfoTranslator());
- }
-
- /**
- * Returns the generated java file information.
- *
- * @return generated java file information
- */
- @Override
- public JavaFileInfoTranslator getJavaFileInfo() {
- if (javaFileInfo == null) {
- throw new TranslatorException("Missing java info in java datamodel node " + getName() + " in " +
- getLineNumber() + " at " +
- getCharPosition()
- + " in " + getFileName());
- }
- return (JavaFileInfoTranslator) javaFileInfo;
- }
-
- /**
- * Sets the java file info object.
- *
- * @param javaInfo java file info object
- */
- @Override
- public void setJavaFileInfo(JavaFileInfoTranslator javaInfo) {
- javaFileInfo = javaInfo;
- }
-
- /**
- * Returns the temporary file handle.
- *
- * @return temporary file handle
- */
- @Override
- public TempJavaCodeFragmentFiles getTempJavaCodeFragmentFiles() {
- return tempFileHandle;
- }
-
- /**
- * Sets temporary file handle.
- *
- * @param fileHandle temporary file handle
- */
- @Override
- public void setTempJavaCodeFragmentFiles(TempJavaCodeFragmentFiles fileHandle) {
- tempFileHandle = fileHandle;
- }
-
- @Override
- public void generateCodeEntry(YangPluginConfig yangPlugin)
- throws TranslatorException {
- InvalidNodeForTranslatorException exception = new InvalidNodeForTranslatorException();
- exception.setFileName(this.getFileName());
- exception.setCharPosition(this.getCharPosition());
- exception.setLine(this.getLineNumber());
- throw exception;
- }
-
- @Override
- public void generateCodeExit()
- throws TranslatorException {
- /*
- * Do nothing.
- */
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/package-info.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/package-info.java
deleted file mode 100644
index 3257922..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/javamodel/package-info.java
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
-/**
- * Maintains application's schema mapped to java classes / interfaces.
- */
-package org.onosproject.yangutils.translator.tojava.javamodel;
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/package-info.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/package-info.java
deleted file mode 100644
index 1aac09e..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/package-info.java
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * Generates java class definition from data model.
- */
-package org.onosproject.yangutils.translator.tojava;
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/BitsJavaInfoHandler.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/BitsJavaInfoHandler.java
deleted file mode 100644
index b0ce250..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/BitsJavaInfoHandler.java
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.translator.tojava.utils;
-
-import org.onosproject.yangutils.datamodel.YangBit;
-import org.onosproject.yangutils.datamodel.YangBits;
-import org.onosproject.yangutils.datamodel.YangEnum;
-import org.onosproject.yangutils.datamodel.YangEnumeration;
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.YangType;
-import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
-import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo;
-import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
-import org.onosproject.yangutils.translator.tojava.JavaFileInfoTranslator;
-import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
-import org.onosproject.yangutils.translator.tojava.javamodel.YangJavaEnumerationTranslator;
-
-import java.io.IOException;
-import java.util.Map;
-
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
-
-/**
- * Represents bits YANG type info.
- */
-public class BitsJavaInfoHandler {
-
- private JavaAttributeInfo attr;
- private YangType<?> yangType;
-
- /**
- * Creates an instance of bits java info handler.
- *
- * @param attr java attribute
- * @param yangType YANG type
- */
- public BitsJavaInfoHandler(JavaAttributeInfo attr, YangType<?> yangType) {
- this.attr = attr;
- this.yangType = yangType;
- }
-
- /**
- * Returns bits type enum file.
- *
- * @param attr attribute
- * @param type data type
- * @param curNode current node
- * @throws IOException when fails to do IO operations
- */
- static void generateBitsFile(JavaAttributeInfo attr, YangType type,
- YangNode curNode) throws IOException {
- JavaFileInfoTranslator fileInfo = ((JavaFileInfoContainer) curNode)
- .getJavaFileInfo();
- String className = fileInfo.getJavaName() +
- getCapitalCase(attr.getAttributeName());
- JavaFileInfoTranslator attrInfo = new JavaFileInfoTranslator();
- attrInfo.setJavaName(className);
- attrInfo.setPackage(fileInfo.getPackage());
- attrInfo.setBaseCodeGenPath(fileInfo.getBaseCodeGenPath());
- attrInfo.setGeneratedFileTypes(GENERATE_ENUM_CLASS);
- attrInfo.setPackageFilePath(fileInfo.getPackageFilePath());
- attrInfo.setPluginConfig(fileInfo.getPluginConfig());
- TempJavaCodeFragmentFiles codeFile = new TempJavaCodeFragmentFiles(attrInfo);
- YangJavaEnumerationTranslator enumeration = new YangJavaEnumerationTranslator() {
- @Override
- public String getJavaPackage() {
- return attr.getImportInfo().getPkgInfo();
- }
-
- @Override
- public String getJavaClassNameOrBuiltInType() {
- return className;
- }
-
- @Override
- public String getJavaAttributeName() {
- return className;
- }
- };
-
- enumeration.setName(className);
- enumeration.setJavaFileInfo(attrInfo);
- enumeration.setTempJavaCodeFragmentFiles(codeFile);
- YangBits yangBits = (YangBits) type.getDataTypeExtendedInfo();
- Integer key;
- YangBit bit;
- String bitName;
- for (Map.Entry<Integer, YangBit> entry : yangBits.getBitPositionMap()
- .entrySet()) {
- key = entry.getKey();
- bit = entry.getValue();
- if (bit != null) {
- bitName = bit.getBitName();
- createAndAddEnum(bitName, key, enumeration);
- }
- }
-
- codeFile.getEnumTempFiles()
- .addEnumAttributeToTempFiles(enumeration, fileInfo.getPluginConfig());
- codeFile.getEnumTempFiles().setEnumClass(false);
- codeFile.generateJavaFile(GENERATE_ENUM_CLASS, enumeration);
- }
-
- private static void createAndAddEnum(String name, int value,
- YangEnumeration enumeration) {
- YangEnum yangEnum = new YangEnum();
- yangEnum.setNamedValue(name);
- yangEnum.setValue(value);
- try {
- enumeration.addEnumInfo(yangEnum);
- } catch (DataModelException e) {
- e.printStackTrace();
- }
- }
-
- /**
- * Returns java attribute for bits.
- *
- * @return java attribute for bits
- */
- public JavaAttributeInfo getAttr() {
- return attr;
- }
-
- /**
- * Returns YANG type for bits.
- *
- * @return yang type for bits
- */
- public YangType<?> getYangType() {
- return yangType;
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/BracketType.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/BracketType.java
deleted file mode 100644
index 67fa9a5..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/BracketType.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.translator.tojava.utils;
-
-/**
- * Represents different bracket types.
- */
-enum BracketType {
-
- //Open close bracket '()'.
- OPEN_CLOSE_BRACKET,
-
- //Open close bracket with value '(value)).
- OPEN_CLOSE_BRACKET_WITH_VALUE,
-
- //Open close bracket with value '(String value)).
- OPEN_CLOSE_BRACKET_WITH_VALUE_AND_RETURN_TYPE,
-
- //Open close bracket with value '(String value,.
- OPEN_BRACKET_WITH_VALUE,
-
- //Open close bracket with value ',String value)).
- CLOSE_BRACKET_WITH_VALUE,
-
- //Open close diamond bracket '<>'.
- OPEN_CLOSE_DIAMOND,
-
- //Open close diamond bracket with value '<String>'
- OPEN_CLOSE_DIAMOND_WITH_VALUE
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/ClassDefinitionGenerator.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/ClassDefinitionGenerator.java
deleted file mode 100644
index 4c711bf..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/ClassDefinitionGenerator.java
+++ /dev/null
@@ -1,465 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.translator.tojava.utils;
-
-import org.onosproject.yangutils.datamodel.RpcNotificationContainer;
-import org.onosproject.yangutils.datamodel.YangAugment;
-import org.onosproject.yangutils.datamodel.YangCase;
-import org.onosproject.yangutils.datamodel.YangIdentity;
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.YangNotification;
-import org.onosproject.yangutils.translator.exception.TranslatorException;
-import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
-import org.onosproject.yangutils.translator.tojava.JavaFileInfoTranslator;
-import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator;
-import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer;
-
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.DEFAULT_CLASS_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_IDENTITY_CLASS;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
-import static org.onosproject.yangutils.translator.tojava.utils.BracketType.OPEN_CLOSE_DIAMOND_WITH_VALUE;
-import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.brackets;
-import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getBuilderImplStringClassDef;
-import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getDefaultDefinition;
-import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getDefaultDefinitionWithExtends;
-import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getDefaultDefinitionWithImpl;
-import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getDefaultName;
-import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getErrorMsg;
-import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getEventExtendsString;
-import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getSpecificModifier;
-import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getSuffixedName;
-import static org.onosproject.yangutils.utils.UtilConstants.ABSTRACT;
-import static org.onosproject.yangutils.utils.UtilConstants.ABSTRACT_EVENT;
-import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
-import static org.onosproject.yangutils.utils.UtilConstants.CLASS;
-import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
-import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT_CAPS;
-import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.ENUM;
-import static org.onosproject.yangutils.utils.UtilConstants.ERROR_MSG_JAVA_IDENTITY;
-import static org.onosproject.yangutils.utils.UtilConstants.EVENT_LISTENER_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.EVENT_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.EVENT_TYPE;
-import static org.onosproject.yangutils.utils.UtilConstants.EXTEND;
-import static org.onosproject.yangutils.utils.UtilConstants.FINAL;
-import static org.onosproject.yangutils.utils.UtilConstants.IMPLEMENTS;
-import static org.onosproject.yangutils.utils.UtilConstants.INTERFACE;
-import static org.onosproject.yangutils.utils.UtilConstants.LISTENER_SERVICE;
-import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
-import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET;
-import static org.onosproject.yangutils.utils.UtilConstants.OP_PARAM;
-import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
-import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC;
-import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_ANY_STRING_ENDING_WITH_SERVICE;
-import static org.onosproject.yangutils.utils.UtilConstants.SERVICE;
-import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
-import static org.onosproject.yangutils.utils.UtilConstants.STATIC;
-import static org.onosproject.yangutils.utils.UtilConstants.SUBJECT;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast;
-
-/**
- * Represents generator for class definition of generated files.
- */
-final class ClassDefinitionGenerator {
-
- /**
- * Creates an instance of class definition generator.
- */
- private ClassDefinitionGenerator() {
- }
-
- /**
- * Based on the file type and the YANG name of the file, generate the class
- * / interface definition start.
- *
- * @param genFileTypes generated file type
- * @param yangName class name
- * @return class definition
- */
- static String generateClassDefinition(int genFileTypes, String yangName) {
-
- /*
- * Based on the file type and the YANG name of the file, generate the
- * class / interface definition start.
- */
- switch (genFileTypes) {
- case GENERATE_TYPEDEF_CLASS:
- case GENERATE_UNION_CLASS:
- return getTypeClassDefinition(yangName);
- case GENERATE_ENUM_CLASS:
- return getEnumClassDefinition(yangName);
- default:
- return null;
- }
- }
-
- /**
- * Based on the file type and the YANG name of the file, generate the class
- * / interface definition start.
- *
- * @param genFileTypes generated file type
- * @param yangName class name
- * @param curNode current YANG node
- * @return class definition
- */
- static String generateClassDefinition(int genFileTypes, String yangName,
- YangNode curNode) {
- /*
- * Based on the file type and the YANG name of the file, generate the
- * class / interface definition start.
- */
- switch (genFileTypes) {
- case INTERFACE_MASK:
- return getInterfaceDefinition(yangName, curNode);
- case BUILDER_CLASS_MASK:
- return getBuilderClassDefinition(yangName, curNode);
- case DEFAULT_CLASS_MASK:
- return getImplClassDefinition(yangName, curNode);
- case BUILDER_INTERFACE_MASK:
- return getBuilderInterfaceDefinition(yangName, curNode);
- case GENERATE_SERVICE_AND_MANAGER:
- return getRpcInterfaceDefinition(yangName, curNode);
- case GENERATE_EVENT_CLASS:
- String eventName = yangName + SUBJECT;
- return getEventDefinition(yangName, eventName);
- case GENERATE_EVENT_LISTENER_INTERFACE:
- return getEventListenerDefinition(yangName);
- case GENERATE_EVENT_SUBJECT_CLASS:
- return getClassDefinition(yangName);
- case GENERATE_IDENTITY_CLASS:
- return getIdentityClassDefinition(yangName, curNode);
- default:
- return null;
- }
- }
-
- /**
- * Returns enum file class definition.
- *
- * @param yangName class name
- * @return enum file class definition
- */
- private static String getEnumClassDefinition(String yangName) {
- return trimAtLast(getDefaultDefinition(ENUM, yangName, PUBLIC),
- NEW_LINE);
- }
-
- /**
- * Returns interface file class definition.
- *
- * @param yangName file name
- * @return definition
- */
- private static String getInterfaceDefinition(String yangName,
- YangNode curNode) {
-
- String clsDef = getClassDefinitionForWhenExtended(curNode, yangName,
- INTERFACE_MASK);
- if (clsDef != null) {
- return clsDef;
- }
- return getDefaultDefinition(INTERFACE, yangName, PUBLIC);
- }
-
- /**
- * Returns builder interface file class definition.
- *
- * @param yangName java class name, corresponding to which the builder
- * class is being generated
- * @return definition
- */
- private static String getBuilderInterfaceDefinition(String yangName,
- YangNode curNode) {
- if (!(curNode instanceof YangCase) &&
- !(curNode instanceof YangAugment)) {
- String clsDef = getClassDefinitionForWhenExtended(
- curNode, yangName, BUILDER_INTERFACE_MASK);
- if (clsDef != null) {
- return clsDef;
- }
- }
- return getDefaultDefinition(INTERFACE, getSuffixedName(yangName, BUILDER),
- null);
- }
-
- /**
- * Returns builder file class definition.
- *
- * @param yangName file name
- * @return definition
- */
- private static String getBuilderClassDefinition(String yangName,
- YangNode curNode) {
- String mod = getSpecificModifier(PUBLIC, STATIC);
- String bName = getSuffixedName(yangName, BUILDER);
- if (!(curNode instanceof YangCase)) {
- String clsDef = getClassDefinitionForWhenExtended(curNode, yangName,
- BUILDER_CLASS_MASK);
- if (clsDef != null) {
- return clsDef;
- }
- }
- if (curNode instanceof RpcNotificationContainer) {
- return getDefaultDefinition(CLASS, bName, mod);
- }
- return getDefaultDefinitionWithImpl(CLASS, bName, mod,
- getBuilderImplStringClassDef(yangName));
- }
-
- /**
- * Returns impl file class definition.
- *
- * @param yangName file name
- * @return definition
- */
- private static String getImplClassDefinition(String yangName,
- YangNode curNode) {
- if (!(curNode instanceof YangCase)) {
- String clsDef = getClassDefinitionForWhenExtended(
- curNode, yangName, DEFAULT_CLASS_MASK);
- if (clsDef != null) {
- return clsDef;
- }
- }
- if (curNode instanceof RpcNotificationContainer) {
- return getDefaultDefinitionWithImpl(
- CLASS, getSuffixedName(yangName, OP_PARAM), PUBLIC, yangName);
- }
- return getDefaultDefinitionWithImpl(CLASS, getDefaultName(yangName),
- PUBLIC, yangName);
- }
-
- /**
- * Returns impl file class definition.
- *
- * @param yangName file name
- * @return definition
- */
- private static String getClassDefinition(String yangName) {
- return getDefaultDefinition(CLASS, yangName, PUBLIC);
- }
-
- /**
- * Returns implementation file identity class definition.
- *
- * @param yangName file name
- * @return identity class definition
- */
- private static String getIdentityClassDefinition(String yangName, YangNode curNode) {
- String error = getErrorMsg(ERROR_MSG_JAVA_IDENTITY, curNode.getName(),
- curNode.getLineNumber(), curNode
- .getCharPosition(), curNode
- .getFileName());
- if (!(curNode instanceof YangIdentity)) {
- throw new TranslatorException(error);
- }
- YangIdentity identity = (YangIdentity) curNode;
- String mod = getSpecificModifier(PUBLIC, ABSTRACT);
- if (identity.getBaseNode() != null) {
- YangIdentity baseIdentity = identity.getBaseNode().getReferredIdentity();
- if (baseIdentity == null) {
- throw new TranslatorException(error);
- }
-
- JavaFileInfoTranslator fileInfo = ((JavaFileInfoContainer) baseIdentity)
- .getJavaFileInfo();
- return getDefaultDefinitionWithExtends(
- CLASS, yangName, mod, getCapitalCase(fileInfo.getJavaName()));
- }
- return getDefaultDefinition(CLASS, yangName, mod);
- }
-
- /**
- * Returns type file class definition.
- *
- * @param yangName file name
- * @return definition
- */
- private static String getTypeClassDefinition(String yangName) {
- return getDefaultDefinition(CLASS, yangName,
- getSpecificModifier(PUBLIC, FINAL));
- }
-
- /**
- * Returns RPC file interface definition.
- *
- * @param yangName file name
- * @param curNode current YANG node
- * @return definition
- */
- private static String getRpcInterfaceDefinition(String yangName, YangNode curNode) {
- JavaExtendsListHolder holder = ((TempJavaCodeFragmentFilesContainer) curNode)
- .getTempJavaCodeFragmentFiles().getServiceTempFiles()
- .getJavaExtendsListHolder();
- if (holder.getExtendsList() != null && !holder.getExtendsList().isEmpty()) {
- curNode = curNode.getChild();
- while (curNode != null) {
- if (curNode instanceof YangNotification) {
- return getRpcInterfaceDefinitionWhenItExtends(yangName);
- }
- curNode = curNode.getNextSibling();
- }
- }
- if (yangName.matches(REGEX_FOR_ANY_STRING_ENDING_WITH_SERVICE)) {
- return getDefaultDefinition(INTERFACE, yangName, PUBLIC);
- }
- String name = getSuffixedName(
- yangName.substring(0, yangName.length() - 7), SERVICE);
- return getDefaultDefinitionWithImpl(CLASS, yangName, PUBLIC, name);
- }
-
- /* Provides class definition when RPC interface needs to extends any event.*/
- private static String getRpcInterfaceDefinitionWhenItExtends(String yangName) {
-
- StringBuilder newString = new StringBuilder(yangName);
- newString.replace(yangName.lastIndexOf(SERVICE), yangName
- .lastIndexOf(SERVICE) + 7, EMPTY_STRING);
- return getDefaultDefinitionWithExtends(
- INTERFACE, yangName, PUBLIC, getEventExtendsString(
- getSuffixedName(newString.toString(), EVENT_STRING),
- LISTENER_SERVICE, getSuffixedName(newString.toString(),
- EVENT_LISTENER_STRING)));
- }
-
- /**
- * Returns event class definition.
- *
- * @param javaName file name
- * @return definition
- */
- private static String getEventDefinition(String javaName, String eventName) {
- return getDefaultDefinitionWithExtends(
- CLASS, javaName, PUBLIC, getEventExtendsString(
- getSuffixedName(javaName, EVENT_TYPE), ABSTRACT_EVENT,
- eventName));
-
- }
-
- /**
- * Returns event listener interface definition.
- *
- * @param javaName file name
- * @return definition
- */
- private static String getEventListenerDefinition(String javaName) {
-
- String name = javaName.substring(0, javaName.length() - 8);
- return getDefaultDefinitionWithExtends(
- INTERFACE, javaName, PUBLIC, EVENT_LISTENER_STRING +
- brackets(OPEN_CLOSE_DIAMOND_WITH_VALUE, name, null));
- }
-
- /**
- * Returns class definition when class is extending another class.
- *
- * @param curNode current node
- * @param yangName name
- * @param genFileTypes gen file type
- * @return class definition
- */
- private static String getClassDefinitionForWhenExtended(
- YangNode curNode, String yangName, int genFileTypes) {
- JavaExtendsListHolder holder = ((TempJavaCodeFragmentFilesContainer) curNode)
- .getTempJavaCodeFragmentFiles().getBeanTempFiles()
- .getJavaExtendsListHolder();
- StringBuilder def = new StringBuilder();
- if (holder.getExtendsList() != null && !holder.getExtendsList().isEmpty()) {
- def.append(PUBLIC).append(SPACE);
- switch (genFileTypes) {
- case INTERFACE_MASK:
- def.append(INTERFACE).append(SPACE).append(yangName)
- .append(SPACE).append(EXTEND).append(SPACE);
- def = new StringBuilder(getDefinitionString(def.toString(),
- holder));
- break;
- case BUILDER_INTERFACE_MASK:
- def.append(INTERFACE)
- .append(SPACE).append(yangName).append(BUILDER)
- .append(SPACE).append(EXTEND).append(SPACE);
- def = new StringBuilder(getDefinitionString(
- def.toString(), holder));
- break;
- case BUILDER_CLASS_MASK:
- def.append(STATIC).append(SPACE).append(CLASS)
- .append(SPACE).append(yangName).append(BUILDER)
- .append(SPACE).append(EXTEND).append(SPACE);
- def = new StringBuilder(getDefinitionString(def.toString(),
- holder));
- if (!(curNode instanceof RpcNotificationContainer)) {
- def.append(SPACE).append(IMPLEMENTS).append(SPACE)
- .append(yangName).append(PERIOD)
- .append(yangName).append(BUILDER);
- }
- break;
- case DEFAULT_CLASS_MASK:
- if (curNode instanceof RpcNotificationContainer) {
- def.append(CLASS).append(SPACE).append(yangName)
- .append(OP_PARAM).append(SPACE).append(EXTEND)
- .append(SPACE);
- } else {
- def.append(CLASS).append(SPACE).append(DEFAULT_CAPS)
- .append(yangName).append(SPACE).append(EXTEND)
- .append(SPACE);
- }
- def = new StringBuilder(getDefinitionString(def.toString(),
- holder));
- def.append(SPACE).append(IMPLEMENTS).append(SPACE)
- .append(yangName);
- break;
- default:
- return null;
- }
- return def.append(SPACE).append(OPEN_CURLY_BRACKET)
- .append(NEW_LINE).toString();
- }
- return null;
- }
-
- /**
- * Returns updated class definition.
- *
- * @param def current definition
- * @param holder extend list holder
- * @return updated class definition
- */
- private static String getDefinitionString(String def,
- JavaExtendsListHolder holder) {
- StringBuilder builder = new StringBuilder(def);
- String str;
- for (JavaQualifiedTypeInfoTranslator info : holder.getExtendsList()) {
- if (!holder.getExtendedClassStore().get(info)) {
- str = info.getClassInfo() + COMMA + SPACE;
- } else {
- str = info.getPkgInfo() + PERIOD + info.getClassInfo() +
- COMMA + SPACE;
- }
- builder.append(str);
- }
- def = builder.toString();
- return trimAtLast(def, COMMA);
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/IndentationType.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/IndentationType.java
deleted file mode 100644
index 3b7b09c..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/IndentationType.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.translator.tojava.utils;
-
-/**
- * Represents indentation type.
- */
-enum IndentationType {
-
- //Four space indentation.
- FOUR_SPACE,
-
- //Eight space indentation.
- EIGHT_SPACE,
-
- //Twelve space indentation.
- TWELVE_SPACE,
-
- //Sixteen space indentation.
- SIXTEEN_SPACE,
-
- //Twenty space indentation.
- TWENTY_SPACE,
-
- //Twenty four space indentation.
- TWENTY_FOUR_SPACE,
-
- //Twenty eight space indentation.
- TWENTY_EIGHT_SPACE
-
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGen.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGen.java
deleted file mode 100644
index 916dd42..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaCodeSnippetGen.java
+++ /dev/null
@@ -1,504 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.translator.tojava.utils;
-
-import org.onosproject.yangutils.datamodel.YangCompilerAnnotation;
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.translator.exception.TranslatorException;
-import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
-import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator;
-import org.onosproject.yangutils.translator.tojava.TempJavaServiceFragmentFiles;
-import org.onosproject.yangutils.utils.UtilConstants.Operation;
-
-import java.util.List;
-
-import static java.util.Collections.sort;
-import static org.onosproject.yangutils.translator.tojava.utils.BracketType.OPEN_CLOSE_BRACKET;
-import static org.onosproject.yangutils.translator.tojava.utils.BracketType.OPEN_CLOSE_BRACKET_WITH_VALUE;
-import static org.onosproject.yangutils.translator.tojava.utils.BracketType.OPEN_CLOSE_DIAMOND;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getEnumJavaAttribute;
-import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.brackets;
-import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getDefaultDefinition;
-import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getImportString;
-import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.signatureClose;
-import static org.onosproject.yangutils.utils.UtilConstants.ARRAY_LIST;
-import static org.onosproject.yangutils.utils.UtilConstants.BIT_SET;
-import static org.onosproject.yangutils.utils.UtilConstants.CLASS_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
-import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_CLOSE_BRACKET;
-import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_OPEN_BRACKET;
-import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION;
-import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.ENUM;
-import static org.onosproject.yangutils.utils.UtilConstants.EQUAL;
-import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
-import static org.onosproject.yangutils.utils.UtilConstants.HASH_MAP;
-import static org.onosproject.yangutils.utils.UtilConstants.INT;
-import static org.onosproject.yangutils.utils.UtilConstants.INT_MAX_RANGE_ATTR;
-import static org.onosproject.yangutils.utils.UtilConstants.INT_MIN_RANGE_ATTR;
-import static org.onosproject.yangutils.utils.UtilConstants.LIST;
-import static org.onosproject.yangutils.utils.UtilConstants.LONG_MAX_RANGE_ATTR;
-import static org.onosproject.yangutils.utils.UtilConstants.LONG_MIN_RANGE_ATTR;
-import static org.onosproject.yangutils.utils.UtilConstants.MAP;
-import static org.onosproject.yangutils.utils.UtilConstants.NEW;
-import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
-import static org.onosproject.yangutils.utils.UtilConstants.OBJECT_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CLOSE_BRACKET_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
-import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE;
-import static org.onosproject.yangutils.utils.UtilConstants.PROTECTED;
-import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC;
-import static org.onosproject.yangutils.utils.UtilConstants.QUESTION_MARK;
-import static org.onosproject.yangutils.utils.UtilConstants.QUEUE;
-import static org.onosproject.yangutils.utils.UtilConstants.QUOTES;
-import static org.onosproject.yangutils.utils.UtilConstants.SCHEMA_NAME;
-import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLON;
-import static org.onosproject.yangutils.utils.UtilConstants.SET;
-import static org.onosproject.yangutils.utils.UtilConstants.SET_VALUE_PARA;
-import static org.onosproject.yangutils.utils.UtilConstants.SHORT_MAX_RANGE_ATTR;
-import static org.onosproject.yangutils.utils.UtilConstants.SHORT_MIN_RANGE_ATTR;
-import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
-import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE;
-import static org.onosproject.yangutils.utils.UtilConstants.TYPE;
-import static org.onosproject.yangutils.utils.UtilConstants.UINT8_MAX_RANGE_ATTR;
-import static org.onosproject.yangutils.utils.UtilConstants.UINT8_MIN_RANGE_ATTR;
-import static org.onosproject.yangutils.utils.UtilConstants.UINT_MAX_RANGE_ATTR;
-import static org.onosproject.yangutils.utils.UtilConstants.UINT_MIN_RANGE_ATTR;
-import static org.onosproject.yangutils.utils.UtilConstants.ULONG_MAX_RANGE_ATTR;
-import static org.onosproject.yangutils.utils.UtilConstants.ULONG_MIN_RANGE_ATTR;
-import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO_LOWER_CASE;
-import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.ENUM_ATTRIBUTE;
-import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.enumJavaDocForInnerClass;
-import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast;
-
-/**
- * Represents utility class to generate the java snippet.
- */
-public final class JavaCodeSnippetGen {
-
- // No instantiation.
- private JavaCodeSnippetGen() {
- }
-
- /**
- * Returns the java file header comment.
- *
- * @return the java file header comment
- */
- public static String getFileHeaderComment() {
-
- /*
- * TODO return the file header.
- */
- return null;
- }
-
- /**
- * Returns the textual java code information corresponding to the import
- * list.
- *
- * @param importInfo import info
- * @return the textual java code information corresponding to the import
- * list
- */
- static String getImportText(JavaQualifiedTypeInfoTranslator importInfo) {
- return getImportString(importInfo.getPkgInfo(), importInfo
- .getClassInfo());
- }
-
- /**
- * Returns the textual java code for attribute definition in class.
- *
- * @param typePkg Package of the attribute type
- * @param attrType java attribute type
- * @param attrName name of the attribute
- * @param isList is list attribute
- * @param accessType attribute access type
- * @param annotation compiler annotation
- * @return the textual java code for attribute definition in class
- */
- public static String getJavaAttributeDefinition(String typePkg,
- String attrType,
- String attrName,
- boolean isList,
- String accessType,
- YangCompilerAnnotation annotation) {
- StringBuilder attrDef = new StringBuilder(FOUR_SPACE_INDENTATION);
- attrDef.append(accessType).append(SPACE);
-
- if (!isList) {
- if (typePkg != null) {
- attrDef.append(typePkg).append(PERIOD);
- }
-
- attrDef.append(attrType).append(SPACE)
- .append(attrName).append(SEMI_COLON)
- .append(NEW_LINE);
- } else {
- // Add starting definition.
- addAttrStartDef(annotation, attrDef);
-
- if (typePkg != null) {
- attrDef.append(typePkg).append(PERIOD);
- }
-
- attrDef.append(attrType);
-
- // Add ending definition.
- addAttrEndDef(annotation, attrDef, attrName);
- }
- return attrDef.toString();
- }
-
- /**
- * Adds starting attribute definition.
- *
- * @param annotation compiler annotation
- * @param attrDef JAVA attribute definition
- */
- private static void addAttrStartDef(YangCompilerAnnotation annotation,
- StringBuilder attrDef) {
- if (annotation != null &&
- annotation.getYangAppDataStructure() != null) {
- switch (annotation.getYangAppDataStructure().getDataStructure()) {
- case QUEUE: {
- attrDef.append(QUEUE)
- .append(DIAMOND_OPEN_BRACKET);
- break;
- }
- case SET: {
- attrDef.append(SET)
- .append(DIAMOND_OPEN_BRACKET);
- break;
- }
- default: {
- attrDef.append(LIST)
- .append(DIAMOND_OPEN_BRACKET);
- }
- }
- } else {
- attrDef.append(LIST).append(DIAMOND_OPEN_BRACKET);
- }
- }
-
- /**
- * Adds ending attribute definition.
- *
- * @param annotation compiler annotation
- * @param attrDef JAVA attribute definition
- * @param attrName name of attribute
- */
- private static void addAttrEndDef(YangCompilerAnnotation annotation,
- StringBuilder attrDef, String attrName) {
- if (annotation != null &&
- annotation.getYangAppDataStructure() != null) {
- attrDef.append(DIAMOND_CLOSE_BRACKET).append(SPACE)
- .append(attrName).append(SEMI_COLON)
- .append(NEW_LINE);
- } else {
- attrDef.append(DIAMOND_CLOSE_BRACKET).append(SPACE).append(attrName)
- .append(SPACE).append(EQUAL).append(SPACE).append(NEW)
- .append(SPACE).append(ARRAY_LIST).append(SEMI_COLON)
- .append(NEW_LINE);
- }
- }
-
- /**
- * Returns string for enum's attribute.
- *
- * @param name name of attribute
- * @param value value of the enum
- * @return string for enum's attribute
- */
- public static String generateEnumAttributeString(String name, int value) {
- String enumName = getEnumJavaAttribute(name);
- return enumJavaDocForInnerClass(name) + EIGHT_SPACE_INDENTATION +
- enumName.toUpperCase() + brackets(OPEN_CLOSE_BRACKET_WITH_VALUE,
- value + EMPTY_STRING, null) +
- COMMA + NEW_LINE;
- }
-
- /**
- * Returns string for enum's attribute for enum class.
- *
- * @param name name of attribute
- * @param value value of the enum
- * @return string for enum's attribute
- */
- public static String generateEnumAttributeStringWithSchemaName(
- String name, int value) {
- String enumName = getEnumJavaAttribute(name);
- String str = value + COMMA + SPACE + QUOTES + name + QUOTES;
- return getJavaDoc(ENUM_ATTRIBUTE, name, false, null) +
- FOUR_SPACE_INDENTATION + enumName.toUpperCase() + brackets(
- OPEN_CLOSE_BRACKET_WITH_VALUE, str, null) + COMMA + NEW_LINE;
- }
-
- /**
- * Returns sorted import list.
- *
- * @param imports import list
- * @return sorted import list
- */
- public static List<String> sortImports(List<String> imports) {
- sort(imports);
- return imports;
- }
-
- /**
- * Returns event enum start.
- *
- * @return event enum start
- */
- static String getEventEnumTypeStart() {
- return NEW_LINE + FOUR_SPACE_INDENTATION +
- getDefaultDefinition(ENUM, TYPE, PUBLIC);
- }
-
- /**
- * Adds listener's imports.
- *
- * @param curNode currentYangNode.
- * @param imports import list
- * @param operation add or remove
- */
- public static void addListenersImport(YangNode curNode,
- List<String> imports,
- Operation operation) {
- String thisImport;
- TempJavaServiceFragmentFiles tempFiles =
- ((JavaCodeGeneratorInfo) curNode).getTempJavaCodeFragmentFiles()
- .getServiceTempFiles();
- thisImport = tempFiles.getJavaImportData().getListenerServiceImport();
- performOperationOnImports(imports, thisImport, operation);
- }
-
- /**
- * Performs given operations on import list.
- *
- * @param imports list of imports
- * @param curImport current import
- * @param operation ADD or REMOVE
- * @return import list
- */
- private static List<String> performOperationOnImports(List<String> imports,
- String curImport,
- Operation operation) {
- switch (operation) {
- case ADD:
- imports.add(curImport);
- break;
- case REMOVE:
- imports.remove(curImport);
- break;
- default:
- throw new TranslatorException("Invalid operation type");
- }
- sortImports(imports);
- return imports;
- }
-
- /**
- * Returns integer attribute for enum's class to get the values.
- *
- * @param className enum's class name
- * @return enum's attribute
- */
- static String getEnumsValueAttribute(String className) {
- return getJavaAttributeDefinition(null, INT, className,
- false, PRIVATE, null) +
- getJavaAttributeDefinition(null, STRING_DATA_TYPE, SCHEMA_NAME,
- false, PRIVATE, null) + NEW_LINE;
- }
-
- /**
- * Returns attribute for augmentation.
- *
- * @return attribute for augmentation
- */
- static String addAugmentationAttribute() {
- String[] array = {NEW_LINE, SEMI_COLON};
- return trimAtLast(getJavaAttributeDefinition(
- null, getAugmentMapTypeString(),
- YANG_AUGMENTED_INFO_LOWER_CASE + MAP, false, PROTECTED,
- null), array) + SPACE + EQUAL + SPACE + NEW + SPACE +
- HASH_MAP + brackets(OPEN_CLOSE_DIAMOND, null, null) + brackets(
- OPEN_CLOSE_BRACKET, null, null) + signatureClose();
- }
-
- /**
- * Returns augment map return type.
- *
- * @return augment map return type
- */
- static String getAugmentMapTypeString() {
- return MAP + DIAMOND_OPEN_BRACKET + CLASS_STRING + DIAMOND_OPEN_BRACKET +
- QUESTION_MARK + DIAMOND_CLOSE_BRACKET + COMMA + SPACE +
- OBJECT_STRING + DIAMOND_CLOSE_BRACKET;
- }
-
- /**
- * Adds attribute for int ranges.
- *
- * @param modifier modifier for attribute
- * @param addFirst true if int need to be added fist.
- * @return attribute for int ranges
- */
- static String addStaticAttributeIntRange(String modifier,
- boolean addFirst) {
- if (addFirst) {
- return getTypeConflictAttributeStrings(modifier,
- INT_MIN_RANGE_ATTR,
- INT_MAX_RANGE_ATTR);
- }
- return getTypeConflictAttributeStrings(modifier,
- UINT_MIN_RANGE_ATTR,
- UINT_MAX_RANGE_ATTR);
- }
-
- /**
- * Adds attribute for long ranges.
- *
- * @param modifier modifier for attribute
- * @param addFirst if need to be added first
- * @return attribute for long ranges
- */
- static String addStaticAttributeLongRange(String modifier,
- boolean addFirst) {
- if (addFirst) {
- return getTypeConflictAttributeStrings(modifier,
- LONG_MIN_RANGE_ATTR,
- LONG_MAX_RANGE_ATTR);
- }
- return getTypeConflictAttributeStrings(modifier,
- ULONG_MIN_RANGE_ATTR,
- ULONG_MAX_RANGE_ATTR);
- }
-
- /**
- * Adds attribute for long ranges.
- *
- * @param modifier modifier for attribute
- * @param addFirst if need to be added first
- * @return attribute for long ranges
- */
- static String addStaticAttributeShortRange(String modifier,
- boolean addFirst) {
- if (addFirst) {
- return getTypeConflictAttributeStrings(modifier,
- SHORT_MIN_RANGE_ATTR,
- SHORT_MAX_RANGE_ATTR);
- }
- return getTypeConflictAttributeStrings(modifier,
- UINT8_MIN_RANGE_ATTR,
- UINT8_MAX_RANGE_ATTR);
- }
-
- /**
- * Returns attribute for conflicting type in union.
- *
- * @param modifier modifier
- * @param attr1 attribute one
- * @param att2 attribute two
- * @return attribute for conflicting type in union
- */
- private static String getTypeConflictAttributeStrings(String modifier,
- String attr1,
- String att2) {
- return FOUR_SPACE_INDENTATION + modifier + SPACE +
- attr1 + FOUR_SPACE_INDENTATION + modifier +
- SPACE + att2 + NEW_LINE;
- }
-
- /**
- * Returns operation type enum.
- *
- * @return operation type enum
- */
- static String getOperationTypeEnum() {
- return " /**\n" +
- " * Specify the node specific operation in protocols " +
- "like NETCONF.\n" +
- " * Applicable in protocol edit operation, not applicable" +
- " in query operation\n" +
- " */\n" +
- " public enum OnosYangNodeOperationType {\n" +
- " MERGE,\n" +
- " REPLACE,\n" +
- " CREATE,\n" +
- " DELETE,\n" +
- " REMOVE,\n" +
- " NONE\n" +
- " }\n";
- }
-
- /**
- * Returns operation type enum, leaf value set attribute and select leaf
- * attribute.
- *
- * @return operation attributes for value and select leaf flags
- */
- static String getOperationAttributes() {
- return " /**\n" +
- " * Identify the leafs whose value are explicitly set\n" +
- " * Applicable in protocol edit and query operation\n" +
- " */\n" +
- " private BitSet valueLeafFlags = new BitSet();\n" +
- "\n" +
- " /**\n" +
- " * Identify the leafs to be selected, in a query operation\n" +
- " */\n" +
- " private BitSet selectLeafFlags = new BitSet();\n";
- }
-
- /**
- * Returns operation type enum, leaf value set attribute and select leaf
- * attribute for constructor.
- *
- * @return operation attributes for constructor
- */
- static String getOperationAttributeForConstructor() {
- return " this.valueLeafFlags = builderObject.getValueLeafFlags();\n" +
- " this.selectLeafFlags = builderObject.getSelectLeafFlags();\n";
- }
-
- /**
- * Returns attribute in constructor for yang augmented info map.
- *
- * @return augment info map
- */
- static String getYangAugmentedMapObjectForConstruct() {
- return " this.yangAugmentedInfoMap = builderObject" +
- ".yangAugmentedInfoMap();\n";
- }
-
- /**
- * Returns set value parameter for union class.
- *
- * @return set value parameter for union class.
- */
- static String getSetValueParaForUnionClass() {
- String[] array = {NEW_LINE, SEMI_COLON};
- return new StringBuilder().append(trimAtLast(
- getJavaAttributeDefinition(null, BIT_SET, SET_VALUE_PARA,
- false, PRIVATE, null), array))
- .append(SPACE).append(EQUAL).append(SPACE).append(NEW)
- .append(SPACE).append(BIT_SET).append(OPEN_CLOSE_BRACKET_STRING)
- .append(signatureClose()).toString();
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaExtendsListHolder.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaExtendsListHolder.java
deleted file mode 100644
index f3c8829..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaExtendsListHolder.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.translator.tojava.utils;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.translator.tojava.JavaFileInfoTranslator;
-import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
-import org.onosproject.yangutils.translator.tojava.JavaImportData;
-import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator;
-import org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles;
-
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
-
-/**
- * Represent the extends list for generated java classes. It holds the class details which needs to be extended by the
- * generated java code.
- */
-public class JavaExtendsListHolder {
-
- private Map<JavaQualifiedTypeInfoTranslator, Boolean> extendedClassStore;
- private List<JavaQualifiedTypeInfoTranslator> extendsList;
-
- /**
- * Creates an instance of JavaExtendsListHolder.
- */
- public JavaExtendsListHolder() {
- setExtendedClassStore(new HashMap<>());
- setExtendsList(new ArrayList<>());
- }
-
- /**
- * Returns extends list.
- *
- * @return extends list
- */
- Map<JavaQualifiedTypeInfoTranslator, Boolean> getExtendedClassStore() {
- return extendedClassStore;
- }
-
- /**
- * Sets extends list.
- *
- * @param extendedClass map of classes need to be extended
- */
- private void setExtendedClassStore(Map<JavaQualifiedTypeInfoTranslator, Boolean> extendedClass) {
- extendedClassStore = extendedClass;
- }
-
- /**
- * Adds to the extends list.
- *
- * @param info java file info
- * @param node YANG node
- * @param tempJavaFragmentFiles temp java fragment files
- */
- public void addToExtendsList(JavaQualifiedTypeInfoTranslator info, YangNode node,
- TempJavaFragmentFiles tempJavaFragmentFiles) {
- JavaFileInfoTranslator fileInfo = ((JavaFileInfoContainer) node).getJavaFileInfo();
-
- JavaImportData importData = tempJavaFragmentFiles.getJavaImportData();
- boolean qualified = importData.addImportInfo(info,
- getCapitalCase(fileInfo.getJavaName()), fileInfo.getPackage());
-
- /*true means import should be added*/
- getExtendedClassStore().put(info, qualified);
-
- addToExtendsList(info);
- }
-
- /**
- * Returns extends list.
- *
- * @return the extendsList
- */
- public List<JavaQualifiedTypeInfoTranslator> getExtendsList() {
- return extendsList;
- }
-
- /**
- * Sets extends info list.
- *
- * @param classInfoList the extends List to set
- */
- private void setExtendsList(List<JavaQualifiedTypeInfoTranslator> classInfoList) {
- extendsList = classInfoList;
- }
-
- /**
- * Adds extends info to list.
- *
- * @param classInfo class info
- */
- private void addToExtendsList(JavaQualifiedTypeInfoTranslator classInfo) {
- getExtendsList().add(classInfo);
- }
-
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGenerator.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGenerator.java
deleted file mode 100644
index 979df3a..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGenerator.java
+++ /dev/null
@@ -1,1276 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.translator.tojava.utils;
-
-import org.onosproject.yangutils.datamodel.RpcNotificationContainer;
-import org.onosproject.yangutils.datamodel.YangAugmentableNode;
-import org.onosproject.yangutils.datamodel.YangCase;
-import org.onosproject.yangutils.datamodel.YangChoice;
-import org.onosproject.yangutils.datamodel.YangDerivedInfo;
-import org.onosproject.yangutils.datamodel.YangEnumeration;
-import org.onosproject.yangutils.datamodel.YangLeavesHolder;
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.YangType;
-import org.onosproject.yangutils.datamodel.YangTypeDef;
-import org.onosproject.yangutils.datamodel.YangUnion;
-import org.onosproject.yangutils.datamodel.javadatamodel.JavaQualifiedTypeInfo;
-import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
-import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo;
-import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
-import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
-import org.onosproject.yangutils.translator.tojava.JavaFileInfoTranslator;
-import org.onosproject.yangutils.translator.tojava.JavaImportData;
-import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer;
-import org.onosproject.yangutils.translator.tojava.TempJavaEnumerationFragmentFiles;
-import org.onosproject.yangutils.translator.tojava.TempJavaEventFragmentFiles;
-import org.onosproject.yangutils.translator.tojava.TempJavaServiceFragmentFiles;
-import org.onosproject.yangutils.translator.tojava.TempJavaTypeFragmentFiles;
-import org.onosproject.yangutils.utils.io.YangPluginConfig;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-import static java.util.Collections.sort;
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.DERIVED;
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.IDENTITYREF;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.DEFAULT_CLASS_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ADD_TO_LIST_IMPL_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ADD_TO_LIST_INTERFACE_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_FOR_TYPE_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ENUM_IMPL_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EQUALS_IMPL_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_ENUM_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_METHOD_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_SUBJECT_ATTRIBUTE_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_SUBJECT_GETTER_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_SUBJECT_SETTER_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FROM_STRING_IMPL_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_CLASS_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.HASH_CODE_IMPL_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.OF_STRING_IMPL_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_INTERFACE_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_CLASS_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK;
-import static org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles.getCurNodeAsAttributeInTarget;
-import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.getQualifierInfoForCasesParent;
-import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.isGetSetOfRootNodeRequired;
-import static org.onosproject.yangutils.translator.tojava.utils.IndentationType.FOUR_SPACE;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.addAugmentationAttribute;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getEnumsValueAttribute;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getEventEnumTypeStart;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getOperationAttributeForConstructor;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getOperationAttributes;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getOperationTypeEnum;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getSetValueParaForUnionClass;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getYangAugmentedMapObjectForConstruct;
-import static org.onosproject.yangutils.translator.tojava.utils.BitsJavaInfoHandler.generateBitsFile;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getDataFromTempFileHandle;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.initiateJavaFileGeneration;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodBodyTypes.ENUM_METHOD_INT_VALUE;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodBodyTypes.ENUM_METHOD_STRING_VALUE;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.builderMethod;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAddAugmentInfoMethodImpl;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAddAugmentInfoMethodInterface;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getAugmentsDataMethodForService;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBitSetEnumClassFromString;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getBitSetEnumClassToString;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getConstructorStart;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEnumsConstructor;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEnumsOfValueMethod;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethodClose;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getEqualsMethodOpen;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getFromStringMethodClose;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getFromStringMethodSignature;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetter;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getGetterString;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethodClose;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getHashCodeMethodOpen;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getInterfaceLeafIdEnumSignature;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getRangeValidatorMethodForUnion;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterForSelectLeaf;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getSetterString;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethodClose;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getToStringMethodOpen;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getUnionToStringMethod;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getYangAugmentInfoImpl;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getYangAugmentInfoInterface;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getYangAugmentInfoMapImpl;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getYangAugmentInfoMapInterface;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.isLeafValueSetInterface;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.isSelectLeafSetInterface;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.processSubtreeFilteringInterface;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.setSelectLeafSetInterface;
-import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getGettersForValueAndSelectLeaf;
-import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getInterfaceLeafIdEnumMethods;
-import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getOperationAttributesGetters;
-import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.methodClose;
-import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.signatureClose;
-import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator.getAugmentableSubTreeFiltering;
-import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator.getProcessChildNodeSubtreeFiltering;
-import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator.getProcessLeafListSubtreeFiltering;
-import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator.getProcessLeafSubtreeFiltering;
-import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator.getProcessSubTreeFilteringEnd;
-import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator.getProcessSubtreeFilteringStart;
-import static org.onosproject.yangutils.translator.tojava.utils.SubtreeFilteringMethodsGenerator.getProcessSubtreeFunctionBody;
-import static org.onosproject.yangutils.translator.tojava.utils.TranslatorUtils.addDefaultConstructor;
-import static org.onosproject.yangutils.translator.tojava.utils.TranslatorUtils.getBeanFiles;
-import static org.onosproject.yangutils.translator.tojava.utils.TranslatorUtils.getTypeFiles;
-import static org.onosproject.yangutils.utils.UtilConstants.BIG_INTEGER;
-import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
-import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_CLASS;
-import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_INTERFACE;
-import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET;
-import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
-import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT;
-import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT_CAPS;
-import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.ENUM_CLASS;
-import static org.onosproject.yangutils.utils.UtilConstants.EVENT_CLASS;
-import static org.onosproject.yangutils.utils.UtilConstants.EVENT_LISTENER_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.EVENT_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.EVENT_SUBJECT_NAME_SUFFIX;
-import static org.onosproject.yangutils.utils.UtilConstants.IMPL_CLASS;
-import static org.onosproject.yangutils.utils.UtilConstants.INT;
-import static org.onosproject.yangutils.utils.UtilConstants.INTERFACE;
-import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
-import static org.onosproject.yangutils.utils.UtilConstants.OP_PARAM;
-import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE;
-import static org.onosproject.yangutils.utils.UtilConstants.PROTECTED;
-import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC;
-import static org.onosproject.yangutils.utils.UtilConstants.RPC_CLASS;
-import static org.onosproject.yangutils.utils.UtilConstants.SCHEMA_NAME;
-import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLON;
-import static org.onosproject.yangutils.utils.UtilConstants.SERVICE_METHOD_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE;
-import static org.onosproject.yangutils.utils.UtilConstants.TYPEDEF_CLASS;
-import static org.onosproject.yangutils.utils.UtilConstants.UNION_CLASS;
-import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD;
-import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.replaceLast;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.validateLineLength;
-
-/**
- * Representation of java file generator.
- */
-public final class JavaFileGenerator {
-
- // No instantiation
- private JavaFileGenerator() {
- }
-
- /**
- * Returns generated interface file for current node.
- *
- * @param file file
- * @param imports imports for the file
- * @param curNode current YANG node
- * @param attrPresent if any attribute is present or not
- * @return interface file
- * @throws IOException when fails to write in file
- */
- public static File generateInterfaceFile(File file, List<String> imports,
- YangNode curNode,
- boolean attrPresent)
- throws IOException {
-
- JavaFileInfoTranslator fileInfo =
- ((JavaFileInfoContainer) curNode).getJavaFileInfo();
-
- String path;
- if (curNode instanceof RpcNotificationContainer) {
- path = fileInfo.getPluginConfig().getCodeGenDir() +
- fileInfo.getPackageFilePath();
- } else {
- path = fileInfo.getBaseCodeGenPath() +
- fileInfo.getPackageFilePath();
- }
-
- String className = getCapitalCase(fileInfo.getJavaName());
-
- boolean leavesPresent;
- YangLeavesHolder leavesHolder;
- if (curNode instanceof YangLeavesHolder) {
- leavesHolder = (YangLeavesHolder) curNode;
- leavesPresent = leavesPresent(leavesHolder);
- } else {
- leavesPresent = false;
- }
-
- initiateJavaFileGeneration(file, INTERFACE_MASK, imports, curNode,
- className);
-
- // Generate ENUM interface
- insertDataIntoJavaFile(file, getOperationTypeEnum());
-
- List<String> methods = new ArrayList<>();
- if (attrPresent) {
- // Add getter methods to interface file.
- try {
- //Leaf identifier enum.
- if (leavesPresent) {
- insertDataIntoJavaFile(file, getInterfaceLeafIdEnumSignature(
- className) + trimAtLast(replaceLast(
- getDataFromTempFileHandle(
- LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK,
- getBeanFiles(curNode), path),
- COMMA, SEMI_COLON), NEW_LINE) +
- getInterfaceLeafIdEnumMethods());
- }
-
- insertDataIntoJavaFile(file, NEW_LINE);
- //Getter methods.
- insertDataIntoJavaFile(file, getDataFromTempFileHandle(
- GETTER_FOR_INTERFACE_MASK, getBeanFiles(curNode), path));
- } catch (IOException e) {
- throw new IOException(getErrorMsg(className, INTERFACE));
- }
- }
-
- if (curNode instanceof YangAugmentableNode &&
- !(curNode instanceof YangChoice)) {
- methods.add(getYangAugmentInfoInterface());
- methods.add(getYangAugmentInfoMapInterface());
- }
-
- if (curNode instanceof YangCase) {
- YangNode caseParent = curNode.getParent();
- JavaQualifiedTypeInfo qualifiedTypeInfo =
- getQualifierInfoForCasesParent(caseParent,
- fileInfo.getPluginConfig());
- methods.add(processSubtreeFilteringInterface(
- qualifiedTypeInfo.getClassInfo()));
- } else {
- methods.add(processSubtreeFilteringInterface(className));
- }
-
- if (leavesPresent) {
- methods.add(isLeafValueSetInterface());
- methods.add(isSelectLeafSetInterface());
- }
- for (String method : methods) {
- insertDataIntoJavaFile(file, method);
- }
- return file;
- }
-
- /**
- * Returns generated builder interface file for current node.
- *
- * @param file file
- * @param curNode current YANG node
- * @param attrPresent if any attribute is present or not
- * @return builder interface file
- * @throws IOException when fails to write in file
- */
- public static File generateBuilderInterfaceFile(File file, YangNode curNode,
- boolean attrPresent)
- throws IOException {
-
- JavaFileInfoTranslator fileInfo =
- ((JavaFileInfoContainer) curNode).getJavaFileInfo();
-
- boolean leavesPresent;
- YangLeavesHolder leavesHolder;
- if (curNode instanceof YangLeavesHolder) {
- leavesHolder = (YangLeavesHolder) curNode;
- leavesPresent = leavesPresent(leavesHolder);
- } else {
- leavesPresent = false;
- }
-
- String className = getCapitalCase(fileInfo.getJavaName());
- String path;
- if (curNode instanceof RpcNotificationContainer) {
- path = fileInfo.getPluginConfig().getCodeGenDir() +
- fileInfo.getPackageFilePath();
- } else {
- path = fileInfo.getBaseCodeGenPath() +
- fileInfo.getPackageFilePath();
- }
-
- initiateJavaFileGeneration(file, BUILDER_INTERFACE_MASK, null, curNode,
- className);
- List<String> methods = new ArrayList<>();
- if (attrPresent) {
- try {
- //Getter methods.
- methods.add(getDataFromTempFileHandle(
- GETTER_FOR_INTERFACE_MASK,
- getBeanFiles(curNode), path));
-
- //Setter methods.
- methods.add(getDataFromTempFileHandle(
- SETTER_FOR_INTERFACE_MASK,
- getBeanFiles(curNode), path));
-
- //Add to list method.
- insertDataIntoJavaFile(file, getDataFromTempFileHandle(
- ADD_TO_LIST_INTERFACE_MASK, getBeanFiles(curNode), path));
- } catch (IOException e) {
- throw new IOException(getErrorMsg(className, BUILDER_INTERFACE));
- }
- }
-
- if (curNode instanceof YangAugmentableNode &&
- !(curNode instanceof YangChoice)) {
- methods.add(getAddAugmentInfoMethodInterface());
- methods.add(getYangAugmentInfoInterface());
- methods.add(getYangAugmentInfoMapInterface());
- }
-
- if (leavesPresent) {
- methods.add(setSelectLeafSetInterface(className));
- }
- //Add build method to builder interface file.
- methods.add(((TempJavaCodeFragmentFilesContainer) curNode)
- .getTempJavaCodeFragmentFiles()
- .addBuildMethodForInterface());
-
- //Add getters and setters in builder interface.
- for (String method : methods) {
- insertDataIntoJavaFile(file, method);
- }
-
- insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE);
- return file;
- }
-
- /**
- * Returns generated builder class file for current node.
- *
- * @param file file
- * @param curNode current YANG node
- * @param attrPresent if any attribute is present or not
- * @return builder class file
- * @throws IOException when fails to write in file
- */
- public static File generateBuilderClassFile(File file, YangNode curNode,
- boolean attrPresent)
- throws IOException {
-
- JavaFileInfoTranslator fileInfo =
- ((JavaFileInfoContainer) curNode).getJavaFileInfo();
-
- boolean leavesPresent;
- YangLeavesHolder leavesHolder;
- if (curNode instanceof YangLeavesHolder) {
- leavesHolder = (YangLeavesHolder) curNode;
- leavesPresent = leavesPresent(leavesHolder);
- } else {
- leavesPresent = false;
- }
-
- String className = getCapitalCase(fileInfo.getJavaName());
- boolean isRootNode = false;
- String path;
- if (curNode instanceof RpcNotificationContainer) {
- isRootNode = true;
- path = fileInfo.getPluginConfig().getCodeGenDir() +
- fileInfo.getPackageFilePath();
- } else {
- path = fileInfo.getBaseCodeGenPath() +
- fileInfo.getPackageFilePath();
- }
-
- initiateJavaFileGeneration(file, BUILDER_CLASS_MASK, null, curNode,
- className);
- List<String> methods = new ArrayList<>();
-
- if (curNode instanceof YangAugmentableNode) {
- insertDataIntoJavaFile(file, addAugmentationAttribute());
- }
- if (attrPresent) {
-
- //Add attribute strings.
- try {
- insertDataIntoJavaFile(file, getDataFromTempFileHandle(
- ATTRIBUTES_MASK, getBeanFiles(curNode), path));
- } catch (IOException e) {
- throw new IOException(getErrorMsg(className, BUILDER_CLASS));
- }
-
- if (leavesPresent) {
- insertDataIntoJavaFile(file, getOperationAttributes());
- }
- try {
- //Getter methods.
- methods.add(getDataFromTempFileHandle(
- GETTER_FOR_CLASS_MASK, getBeanFiles(curNode), path));
- // Setter methods.
- methods.add(getDataFromTempFileHandle(
- SETTER_FOR_CLASS_MASK, getBeanFiles(curNode), path));
-
- //Add to list impl method.
- methods.add(getDataFromTempFileHandle(
- ADD_TO_LIST_IMPL_MASK, getBeanFiles(curNode), path));
-
- insertDataIntoJavaFile(file, NEW_LINE);
-
- //Add operation attribute methods.
- if (leavesPresent) {
- methods.add(getOperationAttributesGetters());
- insertDataIntoJavaFile(file, NEW_LINE);
- methods.add(getSetterForSelectLeaf(className, isRootNode));
- }
- } catch (IOException e) {
- throw new IOException(getErrorMsg(className, BUILDER_CLASS));
- }
- } else {
- insertDataIntoJavaFile(file, NEW_LINE);
- }
-
- if (curNode instanceof YangAugmentableNode) {
- methods.add(getAddAugmentInfoMethodImpl());
- methods.add(getYangAugmentInfoImpl());
- methods.add(getYangAugmentInfoMapImpl());
- }
-
- // Add default constructor and build method impl.
- methods.add(((TempJavaCodeFragmentFilesContainer) curNode)
- .getTempJavaCodeFragmentFiles()
- .addBuildMethodImpl());
- methods.add(addDefaultConstructor(curNode, PUBLIC, BUILDER));
-
- //Add methods in builder class.
- for (String method : methods) {
- insertDataIntoJavaFile(file, method);
- }
- insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET);
- return file;
- }
-
- /**
- * Returns generated default class file for current node.
- *
- * @param file file
- * @param curNode current YANG node
- * @param attrPresent if any attribute is present or not
- * @param imports list of imports
- * @return impl class file
- * @throws IOException when fails to write in file
- */
- public static File generateDefaultClassFile(File file, YangNode curNode,
- boolean attrPresent,
- List<String> imports)
- throws IOException {
-
- JavaFileInfoTranslator fileInfo =
- ((JavaFileInfoContainer) curNode).getJavaFileInfo();
- YangPluginConfig config = fileInfo.getPluginConfig();
-
- boolean leavesPresent;
- YangLeavesHolder leavesHolder;
- if (curNode instanceof YangLeavesHolder) {
- leavesHolder = (YangLeavesHolder) curNode;
- leavesPresent = leavesPresent(leavesHolder);
- } else {
- leavesPresent = false;
- }
-
- boolean rootNode = false;
-
- String className = getCapitalCase(fileInfo.getJavaName());
- String opParamClassName = className;
- String path;
- if (curNode instanceof RpcNotificationContainer) {
- opParamClassName = className + OP_PARAM;
- rootNode = true;
- path = fileInfo.getPluginConfig().getCodeGenDir() +
- fileInfo.getPackageFilePath();
- } else {
- path = fileInfo.getBaseCodeGenPath() +
- fileInfo.getPackageFilePath();
- }
-
- initiateJavaFileGeneration(file, DEFAULT_CLASS_MASK, imports, curNode,
- className);
-
- List<String> methods = new ArrayList<>();
- if (curNode instanceof YangAugmentableNode) {
- insertDataIntoJavaFile(file, addAugmentationAttribute());
- }
- if (attrPresent) {
- addDefaultClassAttributeInfo(file, curNode, className,
- opParamClassName, path, methods,
- leavesPresent, rootNode);
- } else {
- insertDataIntoJavaFile(file, NEW_LINE);
- }
-
- if (curNode instanceof YangAugmentableNode) {
- methods.add(getYangAugmentInfoImpl());
- methods.add(getYangAugmentInfoMapImpl());
- }
- try {
- //Constructor.
- String constructor =
- getConstructorStart(className, rootNode);
- constructor = constructor +
- getDataFromTempFileHandle(
- CONSTRUCTOR_IMPL_MASK, getBeanFiles(curNode), path);
-
- if (leavesPresent) {
- constructor = constructor +
- getOperationAttributeForConstructor();
- }
- String augmentableSubTreeFiltering = EMPTY_STRING;
- if (curNode instanceof YangAugmentableNode) {
- constructor = constructor +
- getYangAugmentedMapObjectForConstruct();
-
- // add is filter content match.
- augmentableSubTreeFiltering = getAugmentableSubTreeFiltering();
- }
- methods.add(constructor + methodClose(FOUR_SPACE));
-
- methods.add(getProcessSubtreeFilteringStart(curNode, config) +
- getProcessSubtreeFunctionBody(curNode) +
- augmentableSubTreeFiltering +
- getProcessSubTreeFilteringEnd());
-
- if (curNode instanceof YangLeavesHolder) {
- if (((YangLeavesHolder) curNode).getListOfLeaf() != null &&
- !((YangLeavesHolder) curNode).getListOfLeaf().isEmpty()) {
- methods.add(getProcessLeafSubtreeFiltering(curNode, config,
- path));
- }
- if (((YangLeavesHolder) curNode).getListOfLeafList() != null &&
- !((YangLeavesHolder) curNode).getListOfLeafList().isEmpty()) {
- methods.add(getProcessLeafListSubtreeFiltering(curNode, config,
- path));
- }
- }
-
- if (curNode.getChild() != null) {
- methods.add(getProcessChildNodeSubtreeFiltering(curNode, config,
- path));
- }
- } catch (IOException e) {
- throw new IOException(getErrorMsg(className, IMPL_CLASS));
- }
-
- methods.add(addDefaultConstructor(curNode, PROTECTED, DEFAULT));
-
- methods.add(builderMethod(className));
- if (leavesPresent) {
- methods.add(getOperationAttributesGetters());
- methods.add(getGettersForValueAndSelectLeaf());
- }
- // Add methods in impl class.
- for (String method : methods) {
- insertDataIntoJavaFile(file, method);
- }
-
- return file;
- }
-
- /**
- * Add methods related to attributes.
- *
- * @param file file
- * @param curNode current YANG node
- * @param className name of the class
- * @param opParamClassName op param class name
- * @param path file path
- * @param methods list of methods string
- * @param leavesPresent flag indicating presence of leaves
- * @param rootNode flag indicating whether node is root node
- * @throws IOException a violation in IO rule
- */
- private static void addDefaultClassAttributeInfo(File file, YangNode curNode,
- String className,
- String opParamClassName,
- String path, List<String> methods,
- boolean leavesPresent,
- boolean rootNode)
- throws IOException {
-
- //Add attribute strings.
- try {
- insertDataIntoJavaFile(file, getDataFromTempFileHandle(
- ATTRIBUTES_MASK, getBeanFiles(curNode), path));
- } catch (IOException e) {
- throw new IOException(getErrorMsg(className, IMPL_CLASS));
- }
-
- //Add operation attributes
- if (leavesPresent) {
- insertDataIntoJavaFile(file, getOperationAttributes());
- }
-
- try {
- //Getter methods.
- methods.add(getDataFromTempFileHandle(
- GETTER_FOR_CLASS_MASK, getBeanFiles(curNode), path));
-
- // Hash code method.
- methods.add(getHashCodeMethodClose(
- getHashCodeMethodOpen() + getDataFromTempFileHandle(
- HASH_CODE_IMPL_MASK, getBeanFiles(curNode), path)
- .replace(NEW_LINE, EMPTY_STRING)));
-
- //Equals method.
- if (rootNode) {
- methods.add(getEqualsMethodClose(
- getEqualsMethodOpen(opParamClassName) +
- getDataFromTempFileHandle(
- EQUALS_IMPL_MASK,
- getBeanFiles(curNode), path)));
- } else {
- methods.add(getEqualsMethodClose(
- getEqualsMethodOpen(DEFAULT_CAPS + className) +
- getDataFromTempFileHandle(EQUALS_IMPL_MASK,
- getBeanFiles(curNode),
- path)));
- }
- // To string method.
- methods.add(getToStringMethodOpen() + getDataFromTempFileHandle(
- TO_STRING_IMPL_MASK, getBeanFiles(curNode), path) +
- getToStringMethodClose());
-
- for (BitsJavaInfoHandler handler : getBeanFiles(curNode)
- .getBitsHandler()) {
- generateBitsFile(handler.getAttr(), handler.getYangType(), curNode);
- }
- } catch (IOException e) {
- throw new IOException(getErrorMsg(className, IMPL_CLASS));
- }
- }
-
- /**
- * Generates class file for type def.
- *
- * @param file generated file
- * @param curNode current YANG node
- * @param imports imports for file
- * @return type def class file
- * @throws IOException when fails to generate class file
- */
- public static File generateTypeDefClassFile(File file, YangNode curNode,
- List<String> imports)
- throws IOException {
-
- JavaFileInfoTranslator fileInfo =
- ((JavaFileInfoContainer) curNode).getJavaFileInfo();
- // import
- String className = getCapitalCase(fileInfo.getJavaName());
- String path = fileInfo.getBaseCodeGenPath() +
- fileInfo.getPackageFilePath();
- YangTypeDef typeDef = (YangTypeDef) curNode;
- List<YangType<?>> types = typeDef.getTypeList();
- YangType type = types.get(0);
- YangDataTypes yangDataTypes = type.getDataType();
-
- initiateJavaFileGeneration(file, className, GENERATE_TYPEDEF_CLASS,
- imports, path);
-
- List<String> methods = new ArrayList<>();
-
- //Add attribute strings.
- try {
- insertDataIntoJavaFile(file, getDataFromTempFileHandle(
- ATTRIBUTES_MASK, getTypeFiles(curNode), path));
- } catch (IOException e) {
- throw new IOException(getErrorMsg(className, TYPEDEF_CLASS));
- }
-
- //Default constructor.
- methods.add(addDefaultConstructor(curNode, PRIVATE, EMPTY_STRING));
-
- try {
-
- //Type constructor.
- methods.add(getDataFromTempFileHandle(
- CONSTRUCTOR_FOR_TYPE_MASK, getTypeFiles(curNode), path));
-
- //Of method.
- methods.add(getDataFromTempFileHandle(
- OF_STRING_IMPL_MASK, getTypeFiles(curNode), path));
-
- //Getter methods.
- methods.add(getDataFromTempFileHandle(
- GETTER_FOR_CLASS_MASK, getTypeFiles(curNode), path));
-
- // Hash code method.
- methods.add(getHashCodeMethodClose(
- getHashCodeMethodOpen() + getDataFromTempFileHandle(
- HASH_CODE_IMPL_MASK, getTypeFiles(curNode), path)
- .replace(NEW_LINE, EMPTY_STRING)));
-
- //Equals method.
- methods.add(getEqualsMethodClose(
- getEqualsMethodOpen(className + EMPTY_STRING) +
- getDataFromTempFileHandle(EQUALS_IMPL_MASK,
- getTypeFiles(curNode), path)));
-
- // To string method.
- addTypedefToString(curNode, methods, path);
-
- JavaCodeGeneratorInfo javaGenInfo = (JavaCodeGeneratorInfo) curNode;
-
- //From string method.
- if (type.getDataType() == DERIVED &&
- ((YangDerivedInfo) type.getDataTypeExtendedInfo())
- .getEffectiveBuiltInType()
- == IDENTITYREF) {
- yangDataTypes = IDENTITYREF;
- }
-
- if (type.getDataType() == IDENTITYREF) {
- yangDataTypes = IDENTITYREF;
- }
-
- if (yangDataTypes != IDENTITYREF) {
- methods.add(getFromStringMethodSignature(className) +
- getDataFromTempFileHandle(
- FROM_STRING_IMPL_MASK,
- javaGenInfo.getTempJavaCodeFragmentFiles()
- .getTypeTempFiles(), path) +
- getFromStringMethodClose());
- }
- } catch (IOException e) {
- throw new IOException(getErrorMsg(className, TYPEDEF_CLASS));
- }
-
- for (String method : methods) {
- insertDataIntoJavaFile(file, method);
- }
- insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE);
-
- return validateLineLength(file);
- }
-
- /**
- * Adds typedef to string method.
- *
- * @param curNode current node
- * @param methods list of methods string
- * @param path file path
- * @throws IOException a violation in IO rule
- */
- private static void addTypedefToString(YangNode curNode,
- List<String> methods, String path)
- throws IOException {
- //To string method.
- methods.add(getToStringMethodOpen() +
- getDataFromTempFileHandle(
- TO_STRING_IMPL_MASK, getTypeFiles(curNode), path) +
- getToStringMethodClose());
- for (BitsJavaInfoHandler handler : getTypeFiles(curNode)
- .getBitsHandler()) {
- generateBitsFile(handler.getAttr(), handler.getYangType(), curNode);
- }
-
- }
-
- /**
- * Generates class file for union type.
- *
- * @param file generated file
- * @param curNode current YANG node
- * @param imports imports for file
- * @return type def class file
- * @throws IOException when fails to generate class file
- */
- public static File generateUnionClassFile(File file, YangNode curNode,
- List<String> imports)
- throws IOException {
-
- JavaFileInfoTranslator fileInfo =
- ((JavaFileInfoContainer) curNode).getJavaFileInfo();
-
- String className = getCapitalCase(fileInfo.getJavaName());
- String path = fileInfo.getBaseCodeGenPath() +
- fileInfo.getPackageFilePath();
-
- TempJavaTypeFragmentFiles tempFiles =
- ((JavaCodeGeneratorInfo) curNode).getTempJavaCodeFragmentFiles()
- .getTypeTempFiles();
-
- boolean intConflict = false;
- boolean longConflict = false;
- boolean shortConflict = false;
- JavaAttributeInfo intAttr = tempFiles.getIntAttribute();
- if (intAttr == null) {
- intAttr = tempFiles.getUIntAttribute();
- }
-
- JavaAttributeInfo longAttr =
- tempFiles.getLongAttribute();
- if (longAttr == null) {
- longAttr = tempFiles.getULongAttribute();
- }
-
- JavaAttributeInfo shortAttr =
- tempFiles.getShortAttribute();
- if (shortAttr == null) {
- shortAttr = tempFiles.getUInt8Attribute();
- }
-
- if (intAttr != null) {
- intConflict = intAttr.isIntConflict();
- }
- if (longAttr != null) {
- longConflict = longAttr.isLongConflict();
- }
- if (shortAttr != null) {
- shortConflict = shortAttr.isShortConflict();
- }
- if (longConflict) {
- String impt = tempFiles.getJavaImportData().getBigIntegerImport();
- if (!imports.contains(impt)) {
- imports.add(impt);
- sort(imports);
- }
- }
-
- initiateJavaFileGeneration(file, className, GENERATE_UNION_CLASS,
- imports, path);
-
- List<String> methods = new ArrayList<>();
-
- // Add attribute strings.
- try {
- addUnionClassAttributeInfo(file, curNode, intConflict,
- longConflict, shortConflict, path, tempFiles);
- } catch (IOException e) {
- throw new IOException(getErrorMsg(className, UNION_CLASS));
- }
-
- //Default constructor.
- methods.add(addDefaultConstructor(curNode, PRIVATE, EMPTY_STRING));
-
- try {
-
- //Type constructor.
- methods.add(getDataFromTempFileHandle(
- CONSTRUCTOR_FOR_TYPE_MASK, getTypeFiles(curNode), path));
-
- // Of string method.
- methods.add(getDataFromTempFileHandle(
- OF_STRING_IMPL_MASK, getTypeFiles(curNode), path));
-
- //Getter methods.
- methods.add(getDataFromTempFileHandle(
- GETTER_FOR_CLASS_MASK, getTypeFiles(curNode), path));
-
- //Hash code method.
- methods.add(getHashCodeMethodClose(
- getHashCodeMethodOpen() +
- getDataFromTempFileHandle(
- HASH_CODE_IMPL_MASK, getTypeFiles(curNode),
- path).replace(NEW_LINE, EMPTY_STRING)));
-
- //Equals method.
- methods.add(getEqualsMethodClose(
- getEqualsMethodOpen(className) +
- getDataFromTempFileHandle(
- EQUALS_IMPL_MASK, getTypeFiles(curNode),
- path)));
-
- //To string method.
- methods.add(getUnionToStringMethod(
- ((YangUnion) curNode).getTypeList()));
-
- for (BitsJavaInfoHandler handler : getTypeFiles(curNode)
- .getBitsHandler()) {
- generateBitsFile(handler.getAttr(), handler.getYangType(), curNode);
- }
-
- //From string method.
- methods.add(getFromStringMethodSignature(className) +
- getDataFromTempFileHandle(
- FROM_STRING_IMPL_MASK,
- getTypeFiles(curNode), path) +
- getFromStringMethodClose());
-
- if (intConflict) {
- methods.add(getRangeValidatorMethodForUnion(INT));
- }
- if (longConflict) {
- methods.add(getRangeValidatorMethodForUnion(BIG_INTEGER));
- }
- if (shortConflict && !intConflict) {
- methods.add(getRangeValidatorMethodForUnion(INT));
- }
- } catch (IOException e) {
- throw new IOException(getErrorMsg(className, UNION_CLASS));
- }
-
- for (String method : methods) {
- insertDataIntoJavaFile(file, method);
- }
- insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE);
-
- return validateLineLength(file);
- }
-
- /**
- * Adds union class attribute information.
- *
- * @param file generated file
- * @param curNode current YANG node
- * @param intConflict flag to indicate if there is a conflict in int
- * @param longConflict flag to indicate if there is a conflict in long
- * @param shortConflict flag to indicate if there is a conflict in short
- * @param path file path
- * @param tempFiles temp java type fragment files
- * @throws IOException a violation in IO rule
- */
- private static void addUnionClassAttributeInfo(File file,
- YangNode curNode,
- boolean intConflict,
- boolean longConflict,
- boolean shortConflict,
- String path,
- TempJavaTypeFragmentFiles tempFiles)
- throws IOException {
- if (intConflict) {
- insertDataIntoJavaFile(file, JavaCodeSnippetGen
- .addStaticAttributeIntRange(PRIVATE,
- tempFiles.getIntIndex() <
- tempFiles.getUIntIndex()));
- }
-
- if (longConflict) {
- insertDataIntoJavaFile(file, JavaCodeSnippetGen
- .addStaticAttributeLongRange(PRIVATE,
- tempFiles.getLongIndex() <
- tempFiles.getULongIndex()));
- }
-
- if (shortConflict) {
- insertDataIntoJavaFile(file, JavaCodeSnippetGen
- .addStaticAttributeShortRange(PRIVATE,
- tempFiles.getShortIndex() <
- tempFiles.getUInt8Index()));
- }
-
- insertDataIntoJavaFile(file, getDataFromTempFileHandle(
- ATTRIBUTES_MASK, getTypeFiles(curNode), path));
- insertDataIntoJavaFile(file, getSetValueParaForUnionClass());
- }
-
- /**
- * Generates class file for type enum.
- *
- * @param file generated file
- * @param curNode current YANG node
- * @param imports import list
- * @return class file for type enum
- * @throws IOException when fails to generate class file
- */
- public static File generateEnumClassFile(File file, YangNode curNode, List<String> imports)
- throws IOException {
-
- JavaFileInfoTranslator fileInfo =
- ((JavaFileInfoContainer) curNode).getJavaFileInfo();
-
- String className = fileInfo.getJavaName();
- String path = fileInfo.getBaseCodeGenPath() +
- fileInfo.getPackageFilePath();
- TempJavaEnumerationFragmentFiles enumFile = ((JavaCodeGeneratorInfo)
- curNode).getTempJavaCodeFragmentFiles().getEnumTempFiles();
- JavaImportData data = enumFile.getJavaImportData();
- if (!enumFile.isEnumClass()) {
- imports.add(data.getImportForToBitSet());
- imports.add(data.getImportForPattern());
- imports.add(data.getImportForToString());
-
- }
-
- initiateJavaFileGeneration(file, getCapitalCase(className),
- GENERATE_ENUM_CLASS, imports, path);
-
- //Add attribute strings.
- try {
- JavaCodeGeneratorInfo javaGenInfo = (JavaCodeGeneratorInfo) curNode;
- String[] remove = {COMMA, NEW_LINE};
- insertDataIntoJavaFile(file, trimAtLast(getDataFromTempFileHandle(
- ENUM_IMPL_MASK, javaGenInfo.getTempJavaCodeFragmentFiles()
- .getEnumTempFiles(), path), remove) +
- signatureClose());
- } catch (IOException e) {
- throw new IOException(getErrorMsg(getCapitalCase(className),
- ENUM_CLASS));
- }
-
- insertDataIntoJavaFile(file, NEW_LINE);
- // Add an attribute to get the enum's values.
- insertDataIntoJavaFile(file, getEnumsValueAttribute(className));
-
- // Add a constructor for enum.
- //TODO: generate javadoc for method.
- insertDataIntoJavaFile(file, getEnumsConstructor(getCapitalCase(className)) +
- NEW_LINE);
-
- insertDataIntoJavaFile(file,
- getEnumsOfValueMethod(className,
- (YangEnumeration) curNode,
- ENUM_METHOD_INT_VALUE));
- insertDataIntoJavaFile(file,
- getEnumsOfValueMethod(className,
- (YangEnumeration) curNode,
- ENUM_METHOD_STRING_VALUE));
-
- // Add a getter method for enum.
- insertDataIntoJavaFile(file, getJavaDoc(GETTER_METHOD, className, false,
- null) +
- getGetter(INT, className, GENERATE_ENUM_CLASS) + NEW_LINE);
-
- insertDataIntoJavaFile(file, getJavaDoc(GETTER_METHOD, SCHEMA_NAME, false,
- null) +
- getGetter(STRING_DATA_TYPE, SCHEMA_NAME, GENERATE_ENUM_CLASS) +
- NEW_LINE);
-
- if (!enumFile.isEnumClass()) {
- insertDataIntoJavaFile(file, getBitSetEnumClassFromString
- (getCapitalCase(className)));
- insertDataIntoJavaFile(file, getBitSetEnumClassToString(
- getCapitalCase(className), (YangEnumeration) curNode));
- }
-
- insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE);
-
- return validateLineLength(file);
- }
-
- /**
- * Generates interface file for rpc.
- *
- * @param file generated file
- * @param curNode current YANG node
- * @param imports imports for file
- * @return rpc class file
- * @throws IOException when fails to generate class file
- */
- public static File generateServiceInterfaceFile(File file, YangNode curNode,
- List<String> imports)
- throws IOException {
-
- JavaFileInfoTranslator fileInfo =
- ((JavaFileInfoContainer) curNode).getJavaFileInfo();
-
- TempJavaServiceFragmentFiles tempFiles =
- ((JavaCodeGeneratorInfo) curNode)
- .getTempJavaCodeFragmentFiles().getServiceTempFiles();
- String className = getCapitalCase(fileInfo.getJavaName()) +
- SERVICE_METHOD_STRING;
- String path = fileInfo.getBaseCodeGenPath() +
- fileInfo.getPackageFilePath();
- initiateJavaFileGeneration(file, GENERATE_SERVICE_AND_MANAGER, imports,
- curNode, className);
-
- List<String> methods = new ArrayList<>();
- JavaAttributeInfo rootAttribute =
- getCurNodeAsAttributeInTarget(curNode, curNode, false,
- tempFiles);
-
- try {
-
- if (isGetSetOfRootNodeRequired(curNode)) {
- //Getter methods.
- methods.add(getGetterString(rootAttribute,
- GENERATE_SERVICE_AND_MANAGER) +
- NEW_LINE);
- // Setter methods.
- methods.add(getSetterString(rootAttribute, className,
- GENERATE_SERVICE_AND_MANAGER) +
- NEW_LINE);
- }
-
- methods.add(getAugmentsDataMethodForService(curNode));
-
- if (((JavaCodeGeneratorInfo) curNode).getTempJavaCodeFragmentFiles()
- .getServiceTempFiles() != null) {
- JavaCodeGeneratorInfo javaGenInfo =
- (JavaCodeGeneratorInfo) curNode;
-
- // Rpc methods
- methods.add(getDataFromTempFileHandle(
- RPC_INTERFACE_MASK,
- javaGenInfo.getTempJavaCodeFragmentFiles()
- .getServiceTempFiles(), path));
- }
- } catch (IOException e) {
- throw new IOException(getErrorMsg(className, RPC_CLASS));
- }
-
- for (String method : methods) {
- insertDataIntoJavaFile(file, method);
- }
- insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE);
-
- return validateLineLength(file);
- }
-
- /**
- * Generates event file.
- *
- * @param file generated file
- * @param curNode current YANG node
- * @param imports imports for file
- * @throws IOException when fails to generate class file
- */
- public static void generateEventFile(File file, YangNode curNode,
- List<String> imports)
- throws IOException {
-
- String className =
- getCapitalCase(((JavaFileInfoContainer) curNode).getJavaFileInfo()
- .getJavaName()) + EVENT_STRING;
-
- TempJavaEventFragmentFiles tempFiles =
- ((TempJavaCodeFragmentFilesContainer) curNode)
- .getTempJavaCodeFragmentFiles().getEventFragmentFiles();
-
- String path = ((JavaFileInfoContainer) curNode).getJavaFileInfo()
- .getBaseCodeGenPath() +
- ((JavaFileInfoContainer) curNode).getJavaFileInfo()
- .getPackageFilePath();
- initiateJavaFileGeneration(file, GENERATE_EVENT_CLASS, imports, curNode,
- className);
- try {
- insertDataIntoJavaFile(file, getEventEnumTypeStart() +
- trimAtLast(getDataFromTempFileHandle(EVENT_ENUM_MASK,
- tempFiles, path),
- COMMA) + methodClose(FOUR_SPACE));
-
- insertDataIntoJavaFile(file,
- getDataFromTempFileHandle(EVENT_METHOD_MASK,
- tempFiles, path));
- } catch (IOException e) {
- throw new IOException(getErrorMsg(className, EVENT_CLASS));
- }
-
- insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE);
- validateLineLength(file);
- }
-
- /**
- * Generates event listener file.
- *
- * @param file generated file
- * @param curNode current YANG node
- * @param imports imports for file
- * @throws IOException when fails to generate class file
- */
- public static void generateEventListenerFile(File file, YangNode curNode,
- List<String> imports)
- throws IOException {
-
- String className =
- getCapitalCase(((JavaFileInfoContainer) curNode).getJavaFileInfo()
- .getJavaName()) + EVENT_LISTENER_STRING;
-
- initiateJavaFileGeneration(file, GENERATE_EVENT_LISTENER_INTERFACE,
- imports, curNode, className);
- insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE);
- validateLineLength(file);
- }
-
- /**
- * Generates event subject's file.
- *
- * @param file file handle
- * @param curNode current YANG node
- * @throws IOException when fails to do IO exceptions
- */
- public static void generateEventSubjectFile(File file, YangNode curNode)
- throws IOException {
-
- String className =
- getCapitalCase(((JavaFileInfoContainer) curNode).getJavaFileInfo()
- .getJavaName()) + EVENT_SUBJECT_NAME_SUFFIX;
-
- initiateJavaFileGeneration(file, GENERATE_EVENT_SUBJECT_CLASS, null,
- curNode, className);
-
- String path = ((JavaFileInfoContainer) curNode).getJavaFileInfo()
- .getBaseCodeGenPath() +
- ((JavaFileInfoContainer) curNode).getJavaFileInfo()
- .getPackageFilePath();
-
- TempJavaEventFragmentFiles tempFiles =
- ((TempJavaCodeFragmentFilesContainer) curNode)
- .getTempJavaCodeFragmentFiles().getEventFragmentFiles();
-
- insertDataIntoJavaFile(file, NEW_LINE);
- try {
- insertDataIntoJavaFile(
- file, getDataFromTempFileHandle(EVENT_SUBJECT_ATTRIBUTE_MASK,
- tempFiles, path));
-
- insertDataIntoJavaFile(
- file, getDataFromTempFileHandle(EVENT_SUBJECT_GETTER_MASK,
- tempFiles, path));
-
- insertDataIntoJavaFile(
- file, getDataFromTempFileHandle(EVENT_SUBJECT_SETTER_MASK,
- tempFiles, path));
- } catch (IOException e) {
- throw new IOException(getErrorMsg(className, EVENT_CLASS));
- }
-
- insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET + NEW_LINE);
- validateLineLength(file);
- }
-
- /**
- * Returns error message string.
- *
- * @param className name of the class
- * @param fileType type of file
- * @return error message string
- */
- private static String getErrorMsg(String className, String fileType) {
- return "No data found in temporary java code fragment files for " +
- className + " while " + fileType + " file generation.";
- }
-
- /**
- * Checks whether leaf is present in YANG leaves holder.
- *
- * @param holder holder of YANG leaves
- * @return true if leaves are present, false otherwise
- */
- private static boolean leavesPresent(YangLeavesHolder holder) {
- return holder.getListOfLeaf() != null &&
- !holder.getListOfLeaf().isEmpty();
- }
-
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGeneratorUtils.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGeneratorUtils.java
deleted file mode 100644
index e22465c..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaFileGeneratorUtils.java
+++ /dev/null
@@ -1,822 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.translator.tojava.utils;
-
-import org.onosproject.yangutils.datamodel.YangAtomicPath;
-import org.onosproject.yangutils.datamodel.YangAugment;
-import org.onosproject.yangutils.datamodel.YangLeafRef;
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.YangNodeIdentifier;
-import org.onosproject.yangutils.datamodel.YangType;
-import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
-import org.onosproject.yangutils.translator.exception.TranslatorException;
-import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
-import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
-import org.onosproject.yangutils.translator.tojava.JavaFileInfoTranslator;
-import org.onosproject.yangutils.translator.tojava.JavaImportData;
-import org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator;
-import org.onosproject.yangutils.translator.tojava.TempJavaBeanFragmentFiles;
-import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFiles;
-import org.onosproject.yangutils.translator.tojava.TempJavaEnumerationFragmentFiles;
-import org.onosproject.yangutils.translator.tojava.TempJavaEventFragmentFiles;
-import org.onosproject.yangutils.translator.tojava.TempJavaFragmentFiles;
-import org.onosproject.yangutils.translator.tojava.TempJavaServiceFragmentFiles;
-import org.onosproject.yangutils.translator.tojava.TempJavaTypeFragmentFiles;
-import org.onosproject.yangutils.utils.io.YangPluginConfig;
-import org.onosproject.yangutils.utils.io.impl.CopyrightHeader;
-import org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.DEFAULT_CLASS_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_ENUM_CLASS;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_CLASS;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_LISTENER_INTERFACE;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_IDENTITY_CLASS;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ADD_TO_LIST_IMPL_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ADD_TO_LIST_INTERFACE_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ATTRIBUTES_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_FOR_TYPE_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.CONSTRUCTOR_IMPL_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EDIT_CONTENT_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.ENUM_IMPL_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EQUALS_IMPL_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_ENUM_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_METHOD_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_SUBJECT_ATTRIBUTE_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_SUBJECT_GETTER_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.EVENT_SUBJECT_SETTER_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FILTER_CONTENT_MATCH_FOR_LEAF_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FILTER_CONTENT_MATCH_FOR_NODES_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FROM_STRING_IMPL_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_CLASS_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.GETTER_FOR_INTERFACE_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.HASH_CODE_IMPL_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.OF_STRING_IMPL_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.RPC_INTERFACE_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_CLASS_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK;
-import static org.onosproject.yangutils.translator.tojava.JavaQualifiedTypeInfoTranslator.getQualifiedTypeInfoOfCurNode;
-import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.getNodesPackage;
-import static org.onosproject.yangutils.translator.tojava.utils.ClassDefinitionGenerator.generateClassDefinition;
-import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET;
-import static org.onosproject.yangutils.utils.UtilConstants.ERROR_MSG_FOR_GEN_CODE;
-import static org.onosproject.yangutils.utils.UtilConstants.LEAFREF;
-import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
-import static org.onosproject.yangutils.utils.UtilConstants.OP_PARAM;
-import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE;
-import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
-import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLON;
-import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
-import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
-import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_CLASS;
-import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_INTERFACE;
-import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.ENUM_CLASS;
-import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.EVENT;
-import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.EVENT_LISTENER;
-import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.EVENT_SUBJECT_CLASS;
-import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.IMPL_CLASS;
-import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.INTERFACE;
-import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.RPC_INTERFACE;
-import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getJavaPackageFromPackagePath;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.parsePkg;
-
-/**
- * Represents utilities for java file generator.
- */
-public final class JavaFileGeneratorUtils {
-
- /**
- * Creates an instance of java file generator util.
- */
- private JavaFileGeneratorUtils() {
- }
-
- /**
- * Returns a file object for generated file.
- *
- * @param filePath file package path
- * @param fileName file name
- * @param extension file extension
- * @param handler cached file handle
- * @return file object
- */
- public static File getFileObject(String filePath, String fileName,
- String extension,
- JavaFileInfoTranslator handler) {
- return new File(handler.getBaseCodeGenPath() + filePath + SLASH +
- fileName + extension);
- }
-
- /**
- * Returns data stored in temporary files.
- *
- * @param tempFiles temporary file types
- * @param tempHandle temp java fragment files
- * @param path absolute path
- * @return data stored in temporary files
- * @throws IOException when failed to get the data from temporary file handle
- */
- static String getDataFromTempFileHandle(
- int tempFiles, TempJavaFragmentFiles tempHandle, String path)
- throws IOException {
-
- TempJavaTypeFragmentFiles typeHandle = null;
- if (tempHandle instanceof TempJavaTypeFragmentFiles) {
- typeHandle = (TempJavaTypeFragmentFiles) tempHandle;
- }
-
- TempJavaBeanFragmentFiles beanHandle = null;
- if (tempHandle instanceof TempJavaBeanFragmentFiles) {
- beanHandle = (TempJavaBeanFragmentFiles) tempHandle;
- }
-
- TempJavaServiceFragmentFiles serviceHandle = null;
- if (tempHandle instanceof TempJavaServiceFragmentFiles) {
- serviceHandle = (TempJavaServiceFragmentFiles) tempHandle;
- }
-
- TempJavaEventFragmentFiles eventHandle = null;
- if (tempHandle instanceof TempJavaEventFragmentFiles) {
- eventHandle = (TempJavaEventFragmentFiles) tempHandle;
- }
-
- if ((tempFiles & ATTRIBUTES_MASK) != 0) {
- return tempHandle.getTemporaryDataFromFileHandle(
- tempHandle.getAttributesTempFileHandle(),
- path);
- }
- if ((tempFiles & GETTER_FOR_INTERFACE_MASK) != 0) {
- return tempHandle.getTemporaryDataFromFileHandle(
- tempHandle.getGetterInterfaceTempFileHandle(),
- path);
- }
- if ((tempFiles & SETTER_FOR_INTERFACE_MASK) != 0) {
- return tempHandle.getTemporaryDataFromFileHandle(
- tempHandle.getSetterInterfaceTempFileHandle(),
- path);
- }
- if ((tempFiles & GETTER_FOR_CLASS_MASK) != 0) {
- return tempHandle.getTemporaryDataFromFileHandle(
- tempHandle.getGetterImplTempFileHandle(),
- path);
- }
- if ((tempFiles & SETTER_FOR_CLASS_MASK) != 0) {
- return tempHandle.getTemporaryDataFromFileHandle(
- tempHandle.getSetterImplTempFileHandle(),
- path);
- }
- if ((tempFiles & ADD_TO_LIST_INTERFACE_MASK) != 0) {
- return tempHandle.getTemporaryDataFromFileHandle(
- tempHandle.getAddToListInterfaceTempFileHandle(),
- path);
- }
- if ((tempFiles & ADD_TO_LIST_IMPL_MASK) != 0) {
- return tempHandle.getTemporaryDataFromFileHandle(
- tempHandle.getAddToListImplTempFileHandle(),
- path);
- }
- if ((tempFiles & FILTER_CONTENT_MATCH_FOR_LEAF_MASK) != 0) {
- return tempHandle.getTemporaryDataFromFileHandle(
- tempHandle.getSubtreeFilteringForLeafTempFileHandle(),
- path);
- }
- if ((tempFiles & FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK) != 0) {
- return tempHandle.getTemporaryDataFromFileHandle(
- tempHandle.getGetSubtreeFilteringForListTempFileHandle(),
- path);
- }
- if ((tempFiles & FILTER_CONTENT_MATCH_FOR_NODES_MASK) != 0) {
- return tempHandle.getTemporaryDataFromFileHandle(
- tempHandle.getGetSubtreeFilteringForChildNodeTempFileHandle(),
- path);
- }
- if ((tempFiles & EDIT_CONTENT_MASK) != 0) {
- return tempHandle.getTemporaryDataFromFileHandle(
- tempHandle.getEditContentTempFileHandle(),
- path);
- }
- if ((tempFiles & LEAF_IDENTIFIER_ENUM_ATTRIBUTES_MASK) != 0) {
- return tempHandle.getTemporaryDataFromFileHandle(
- tempHandle.getLeafIdAttributeTempFileHandle(),
- path);
- }
- if ((tempFiles & CONSTRUCTOR_IMPL_MASK) != 0) {
- if (beanHandle == null) {
- throw new TranslatorException("Required constructor info is" +
- " missing.");
- }
- return beanHandle.getTemporaryDataFromFileHandle(
- beanHandle.getConstructorImplTempFileHandle(),
- path);
- }
- if ((tempFiles & HASH_CODE_IMPL_MASK) != 0) {
- return tempHandle.getTemporaryDataFromFileHandle(
- tempHandle.getHashCodeImplTempFileHandle(),
- path);
- }
- if ((tempFiles & EQUALS_IMPL_MASK) != 0) {
- return tempHandle.getTemporaryDataFromFileHandle(
- tempHandle.getEqualsImplTempFileHandle(),
- path);
- }
- if ((tempFiles & TO_STRING_IMPL_MASK) != 0) {
- return tempHandle.getTemporaryDataFromFileHandle(
- tempHandle.getToStringImplTempFileHandle(),
- path);
- }
- if ((tempFiles & OF_STRING_IMPL_MASK) != 0) {
- if (typeHandle == null) {
- throw new TranslatorException("Required of string implementation" +
- " info is missing.");
- }
- return typeHandle.getTemporaryDataFromFileHandle(
- typeHandle.getOfStringImplTempFileHandle(), path);
- }
- if ((tempFiles & CONSTRUCTOR_FOR_TYPE_MASK) != 0) {
- if (typeHandle == null) {
- throw new TranslatorException("Required constructor implementation" +
- " info is missing.");
- }
- return typeHandle.getTemporaryDataFromFileHandle(
- typeHandle.getConstructorForTypeTempFileHandle(),
- path);
- }
- if ((tempFiles & FROM_STRING_IMPL_MASK) != 0) {
- return tempHandle.getTemporaryDataFromFileHandle(
- tempHandle.getFromStringImplTempFileHandle(),
- path);
- }
- if ((tempFiles & ENUM_IMPL_MASK) != 0) {
- if (!(tempHandle instanceof TempJavaEnumerationFragmentFiles)) {
- throw new TranslatorException("Required enum info is missing.");
- }
- TempJavaEnumerationFragmentFiles enumHandle =
- (TempJavaEnumerationFragmentFiles) tempHandle;
- return enumHandle.getTemporaryDataFromFileHandle(
- enumHandle.getEnumClassTempFileHandle(), path);
- }
- if ((tempFiles & RPC_INTERFACE_MASK) != 0) {
- if (serviceHandle == null) {
- throw new TranslatorException("Required rpc interface info is" +
- " missing.");
- }
- return serviceHandle.getTemporaryDataFromFileHandle(
- serviceHandle.getRpcInterfaceTempFileHandle(),
- path);
- }
- if ((tempFiles & EVENT_ENUM_MASK) != 0) {
- if (eventHandle == null) {
- throw new TranslatorException(
- "Required event enum implementation info is missing.");
- }
- return eventHandle.getTemporaryDataFromFileHandle(
- eventHandle.getEventEnumTempFileHandle(),
- path);
- }
- if ((tempFiles & EVENT_METHOD_MASK) != 0) {
- if (eventHandle == null) {
- throw new TranslatorException(
- "Required event method implementation info is missing.");
- }
- return eventHandle.getTemporaryDataFromFileHandle(
- eventHandle.getEventMethodTempFileHandle(),
- path);
- }
- if ((tempFiles & EVENT_SUBJECT_GETTER_MASK) != 0) {
- if (eventHandle == null) {
- throw new TranslatorException(
- "Required event subject getter implementation info is" +
- " missing.");
- }
- return eventHandle.getTemporaryDataFromFileHandle(
- eventHandle.getEventSubjectGetterTempFileHandle(),
- path);
- }
- if ((tempFiles & EVENT_SUBJECT_SETTER_MASK) != 0) {
- if (eventHandle == null) {
- throw new TranslatorException(
- "Required event subject setter implementation info is" +
- " missing.");
- }
- return eventHandle.getTemporaryDataFromFileHandle(
- eventHandle.getEventSubjectSetterTempFileHandle(),
- path);
- }
- if ((tempFiles & EVENT_SUBJECT_ATTRIBUTE_MASK) != 0) {
- if (eventHandle == null) {
- throw new TranslatorException(
- "Required event subject attribute implementation info is" +
- " missing.");
- }
- return eventHandle.getTemporaryDataFromFileHandle(
- eventHandle.getEventSubjectAttributeTempFileHandle(),
- path);
- }
- return null;
- }
-
- /**
- * Initiates generation of file based on generated file type.
- *
- * @param file generated file
- * @param className generated file class name
- * @param genType generated file type
- * @param imports imports for the file
- * @param pkg generated file package
- * @throws IOException when fails to generate a file
- */
- public static void initiateJavaFileGeneration(File file, String className,
- int genType, List<String> imports,
- String pkg)
- throws IOException {
-
- if (file.exists()) {
- throw new IOException(" file " + file.getName() + " is already generated." +
- ERROR_MSG_FOR_GEN_CODE);
- }
-
- boolean isFileCreated;
- try {
- isFileCreated = file.createNewFile();
- if (!isFileCreated) {
- throw new IOException("Failed to create " + file.getName() +
- " class file.");
- }
- appendContents(file, className, genType, imports, pkg);
- } catch (IOException e) {
- throw new IOException("Failed to append contents in " + file.getName() +
- " class file.");
- }
- }
-
- /**
- * Initiates generation of file based on generated file type.
- *
- * @param file generated file
- * @param genType generated file type
- * @param imports imports for the file
- * @param curNode current YANG node
- * @param name class name
- * @throws IOException when fails to generate a file
- */
- public static void initiateJavaFileGeneration(File file, int genType,
- List<String> imports,
- YangNode curNode, String name)
- throws IOException {
-
- if (file.exists()) {
- throw new IOException(" file " + file.getName() + " is already generated." +
- ERROR_MSG_FOR_GEN_CODE);
- }
- boolean isFileCreated;
- try {
- isFileCreated = file.createNewFile();
- if (!isFileCreated) {
- throw new IOException("Failed to create " + file.getName() +
- " class file.");
- }
- appendContents(file, genType, imports, curNode, name);
- } catch (IOException e) {
- throw new IOException("Failed to append contents in " + file.getName() +
- " class file.");
- }
- }
-
- /**
- * Appends all the contents into a generated java file.
- *
- * @param file generated file
- * @param genType generated file type
- * @param importsList list of java imports
- * @param curNode current YANG node
- * @param className class name
- * @throws IOException when fails to do IO operations
- */
- private static void appendContents(File file, int genType,
- List<String> importsList, YangNode curNode,
- String className)
- throws IOException {
-
- JavaFileInfoTranslator javaFileInfo = ((JavaFileInfoContainer) curNode)
- .getJavaFileInfo();
-
- String name = javaFileInfo.getJavaName();
- String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo
- .getPackageFilePath();
-
- String pkgString;
- if (genType == GENERATE_EVENT_CLASS ||
- genType == GENERATE_EVENT_LISTENER_INTERFACE ||
- genType == GENERATE_EVENT_SUBJECT_CLASS) {
- pkgString = parsePackageString((path + PERIOD + name)
- .toLowerCase(), importsList);
- } else {
- pkgString = parsePackageString(path, importsList);
- }
- switch (genType) {
- case INTERFACE_MASK:
- appendHeaderContents(file, pkgString, importsList);
- write(file, genType, INTERFACE, curNode, className);
- break;
- case DEFAULT_CLASS_MASK:
- appendHeaderContents(file, pkgString, importsList);
- write(file, genType, IMPL_CLASS, curNode, className);
- break;
- case BUILDER_CLASS_MASK:
- write(file, genType, BUILDER_CLASS, curNode, className);
- break;
- case BUILDER_INTERFACE_MASK:
- write(file, genType, BUILDER_INTERFACE, curNode, className);
- break;
- case GENERATE_SERVICE_AND_MANAGER:
- appendHeaderContents(file, pkgString, importsList);
- write(file, genType, RPC_INTERFACE, curNode, className);
- break;
- case GENERATE_EVENT_CLASS:
- appendHeaderContents(file, pkgString, importsList);
- write(file, genType, EVENT, curNode, className);
- break;
- case GENERATE_EVENT_LISTENER_INTERFACE:
- appendHeaderContents(file, pkgString, importsList);
- write(file, genType, EVENT_LISTENER, curNode, className);
- break;
- case GENERATE_EVENT_SUBJECT_CLASS:
- appendHeaderContents(file, pkgString, importsList);
- write(file, genType, EVENT_SUBJECT_CLASS, curNode, className);
- break;
- case GENERATE_IDENTITY_CLASS:
- appendHeaderContents(file, pkgString, importsList);
- write(file, genType, EVENT_SUBJECT_CLASS, curNode, className);
- insertDataIntoJavaFile(file, CLOSE_CURLY_BRACKET);
- break;
- default:
- break;
- }
- }
-
- /**
- * Appends all the contents into a generated java file.
- *
- * @param file generated file
- * @param fileName generated file name
- * @param genType generated file type
- * @param importsList list of java imports
- * @param pkg generated file package
- * @throws IOException when fails to append contents
- */
- private static void appendContents(File file, String fileName, int genType,
- List<String> importsList, String pkg)
- throws IOException {
-
- String pkgString = parsePackageString(pkg, importsList);
-
- switch (genType) {
- case GENERATE_TYPEDEF_CLASS:
- appendHeaderContents(file, pkgString, importsList);
- write(file, fileName, genType, IMPL_CLASS);
- break;
- case GENERATE_UNION_CLASS:
- appendHeaderContents(file, pkgString, importsList);
- write(file, fileName, genType, IMPL_CLASS);
- break;
- case GENERATE_ENUM_CLASS:
- appendHeaderContents(file, pkgString, importsList);
- write(file, fileName, genType, ENUM_CLASS);
- break;
- default:
- break;
- }
- }
-
- /**
- * Removes base directory path from package and generates package string for file.
- *
- * @param javaPkg generated java package
- * @param importsList list of imports
- * @return package string
- */
- private static String parsePackageString(String javaPkg,
- List<String> importsList) {
-
- javaPkg = parsePkg(getJavaPackageFromPackagePath(javaPkg));
- if (importsList != null) {
- if (!importsList.isEmpty()) {
- return PACKAGE + SPACE + javaPkg + SEMI_COLON + NEW_LINE;
- } else {
- return PACKAGE + SPACE + javaPkg + SEMI_COLON;
- }
- } else {
- return PACKAGE + SPACE + javaPkg + SEMI_COLON;
- }
- }
-
- /**
- * Appends other contents to interface, impl and typedef classes.
- * for example : ONOS copyright, imports and package.
- *
- * @param file generated file
- * @param pkg generated package
- * @param importsList list of imports
- * @throws IOException when fails to append contents
- */
- private static void appendHeaderContents(File file, String pkg,
- List<String> importsList)
- throws IOException {
-
- insertDataIntoJavaFile(file, CopyrightHeader.getCopyrightHeader());
- insertDataIntoJavaFile(file, pkg);
-
- /*
- * TODO: add the file header using comments for snippet of yang file.
- * JavaCodeSnippetGen.getFileHeaderComment
- */
-
- if (importsList != null) {
- insertDataIntoJavaFile(file, NEW_LINE);
- for (String imports : importsList) {
- insertDataIntoJavaFile(file, imports);
- }
- }
- }
-
- /**
- * Writes data to the specific generated file.
- *
- * @param file generated file
- * @param genType generated file type
- * @param javaDocType java doc type
- * @param curNode current YANG node
- * @param fileName file name
- * @throws IOException when fails to write into a file
- */
- private static void write(File file, int genType, JavaDocType javaDocType,
- YangNode curNode, String fileName)
- throws IOException {
- insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName,
- false, null));
- insertDataIntoJavaFile(file, generateClassDefinition(genType,
- fileName, curNode));
- }
-
- /**
- * Writes data to the specific generated file.
- *
- * @param file generated file
- * @param fileName file name
- * @param genType generated file type
- * @param javaDocType java doc type
- * @throws IOException when fails to write into a file
- */
- private static void write(File file, String fileName, int genType,
- JavaDocType javaDocType) throws IOException {
- insertDataIntoJavaFile(file, getJavaDoc(javaDocType, fileName, false,
- null));
- insertDataIntoJavaFile(file, generateClassDefinition(genType, fileName));
- }
-
- /**
- * Returns set of node identifiers.
- *
- * @param parent parent node
- * @return set of node identifiers
- */
- static List<YangAtomicPath> getSetOfNodeIdentifiers(YangNode parent) {
-
- List<YangAtomicPath> targets = new ArrayList<>();
- YangNodeIdentifier nodeId;
- List<YangAugment> augments = getListOfAugments(parent);
- for (YangAugment augment : augments) {
- nodeId = augment.getTargetNode().get(0).getNodeIdentifier();
-
- if (validateNodeIdentifierInSet(nodeId, targets)) {
- targets.add(augment.getTargetNode().get(0));
- }
- }
- return targets;
- }
-
- /* Returns list of augments.*/
- private static List<YangAugment> getListOfAugments(YangNode parent) {
- List<YangAugment> augments = new ArrayList<>();
- YangNode child = parent.getChild();
- while (child != null) {
- if (child instanceof YangAugment) {
- augments.add((YangAugment) child);
- }
- child = child.getNextSibling();
- }
- return augments;
- }
-
- /*Validates the set for duplicate names of node identifiers.*/
- private static boolean validateNodeIdentifierInSet(
- YangNodeIdentifier nodeId, List<YangAtomicPath> targets) {
- boolean isPresent = true;
- for (YangAtomicPath target : targets) {
- if (target.getNodeIdentifier().getName().equals(nodeId.getName())) {
- if (target.getNodeIdentifier().getPrefix() != null) {
- isPresent = !target.getNodeIdentifier().getPrefix()
- .equals(nodeId.getPrefix());
- } else {
- isPresent = nodeId.getPrefix() != null;
- }
- }
- }
- return isPresent;
- }
-
- /**
- * Adds resolved augmented node imports to manager class.
- *
- * @param parent parent node
- */
- public static void addResolvedAugmentedDataNodeImports(YangNode parent) {
- List<YangAtomicPath> targets = getSetOfNodeIdentifiers(parent);
- TempJavaCodeFragmentFiles tempJavaCodeFragmentFiles = (
- (JavaCodeGeneratorInfo) parent)
- .getTempJavaCodeFragmentFiles();
- YangNode augmentedNode;
- JavaQualifiedTypeInfoTranslator typeInfo;
- String curNodeName;
- JavaFileInfoTranslator parentInfo = ((JavaFileInfoContainer) parent)
- .getJavaFileInfo();
- for (YangAtomicPath nodeId : targets) {
- augmentedNode = nodeId.getResolvedNode().getParent();
- curNodeName = getCurNodeName(augmentedNode, parentInfo
- .getPluginConfig());
-
- typeInfo =
- getQTypeInfoOfNode(
- augmentedNode, curNodeName + OP_PARAM,
- parentInfo.getPluginConfig());
-
- tempJavaCodeFragmentFiles.getServiceTempFiles()
- .getJavaImportData().addImportInfo(
- typeInfo, parentInfo.getJavaName(),
- parentInfo.getPackage());
- typeInfo =
- getQTypeInfoOfNode(
- augmentedNode, curNodeName, parentInfo
- .getPluginConfig());
-
- tempJavaCodeFragmentFiles.getServiceTempFiles()
- .getJavaImportData().addImportInfo(
- typeInfo, parentInfo.getJavaName(),
- parentInfo.getPackage());
- }
- }
-
- /**
- * Returns qualified type info of augmented node.
- *
- * @param augmentedNode augmented node
- * @param curNodeName current node name
- * @param pluginConfig plugin configurations
- * @return qualified type info of augmented node
- */
- private static JavaQualifiedTypeInfoTranslator getQTypeInfoOfNode(
- YangNode augmentedNode, String curNodeName, YangPluginConfig pluginConfig) {
- JavaQualifiedTypeInfoTranslator javaQualifiedTypeInfo =
- getQualifiedTypeInfoOfCurNode(augmentedNode,
- curNodeName);
- if (javaQualifiedTypeInfo.getPkgInfo() == null) {
- javaQualifiedTypeInfo.setPkgInfo(getNodesPackage(augmentedNode,
- pluginConfig));
- }
- return javaQualifiedTypeInfo;
- }
-
- /**
- * Validates if augmented node is imported in parent node.
- *
- * @param javaQualifiedTypeInfo qualified type info
- * @param importData import data
- * @return true if present in imports
- */
- private static boolean validateQualifiedInfoOfAugmentedNode(
- JavaQualifiedTypeInfoTranslator javaQualifiedTypeInfo,
- JavaImportData importData) {
- for (JavaQualifiedTypeInfoTranslator curImportInfo : importData
- .getImportSet()) {
- if (curImportInfo.getClassInfo()
- .contentEquals(javaQualifiedTypeInfo.getClassInfo())) {
- return curImportInfo.getPkgInfo()
- .contentEquals(javaQualifiedTypeInfo.getPkgInfo());
- }
- }
- return true;
- }
-
- /**
- * Return augmented class name for data methods in manager and service.
- *
- * @param augmentedNode augmented node
- * @param parent parent node
- * @return augmented class name for data methods in manager and service
- */
- static String getAugmentedClassNameForDataMethods(YangNode augmentedNode,
- YangNode parent) {
- String curNodeName;
- JavaQualifiedTypeInfoTranslator javaQualifiedTypeInfo;
- JavaFileInfoTranslator parentInfo = ((JavaFileInfoContainer) parent)
- .getJavaFileInfo();
- YangPluginConfig pluginConfig = parentInfo.getPluginConfig();
- TempJavaServiceFragmentFiles tempJavaServiceFragmentFiles = (
- (JavaCodeGeneratorInfo) parent).getTempJavaCodeFragmentFiles()
- .getServiceTempFiles();
- curNodeName = getCurNodeName(augmentedNode, pluginConfig);
-
- javaQualifiedTypeInfo = getQTypeInfoOfNode(augmentedNode,
- getCapitalCase(curNodeName),
- parentInfo.getPluginConfig());
- if (validateQualifiedInfoOfAugmentedNode(javaQualifiedTypeInfo,
- tempJavaServiceFragmentFiles
- .getJavaImportData())) {
- return javaQualifiedTypeInfo.getClassInfo();
- } else {
- return javaQualifiedTypeInfo.getPkgInfo() + PERIOD +
- javaQualifiedTypeInfo.getClassInfo();
- }
- }
-
- //Returns class name of current node
- static String getCurNodeName(YangNode node, YangPluginConfig config) {
- if (((JavaFileInfoContainer) node).getJavaFileInfo()
- .getJavaName() != null) {
- return getCapitalCase(((JavaFileInfoContainer) node)
- .getJavaFileInfo()
- .getJavaName());
- } else {
- return getCapitalCase(getCamelCase(node.getName(), config
- .getConflictResolver()));
- }
- }
-
- /**
- * Checks if the type name is leafref and returns the effective type name.
- *
- * @param attributeName name of the current type
- * @param attributeType effective type
- * @return name of the effective type
- */
- public static String isTypeNameLeafref(String attributeName,
- YangType<?> attributeType) {
- if (attributeName.equalsIgnoreCase(LEAFREF)) {
- YangLeafRef leafRef = (YangLeafRef) attributeType.getDataTypeExtendedInfo();
- if (!leafRef.isInGrouping()) {
- return attributeType.getDataTypeName();
- }
- }
- return attributeName;
- // TODO handle union scenario, having multiple leafref.
- }
-
- /**
- * Checks if the type is leafref and returns the effective type.
- *
- * @param attributeType current type
- * @return effective type
- */
- public static YangType isTypeLeafref(YangType<?> attributeType) {
- if (attributeType.getDataType() == YangDataTypes.LEAFREF) {
- YangLeafRef leafRef = (YangLeafRef) attributeType
- .getDataTypeExtendedInfo();
- if (!leafRef.isInGrouping()) {
- return leafRef.getEffectiveDataType();
- }
- }
- return attributeType;
- }
-}
\ No newline at end of file
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaIdentifierSyntax.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaIdentifierSyntax.java
deleted file mode 100644
index 5bf97f3..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/JavaIdentifierSyntax.java
+++ /dev/null
@@ -1,257 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.translator.tojava.utils;
-
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.YangRevision;
-import org.onosproject.yangutils.translator.exception.TranslatorException;
-import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
-import org.onosproject.yangutils.translator.tojava.JavaFileInfoTranslator;
-import org.onosproject.yangutils.utils.io.YangToJavaNamingConflictUtil;
-
-import java.io.File;
-import java.io.IOException;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Date;
-import java.util.List;
-
-import static org.onosproject.yangutils.datamodel.utils.DataModelUtils.getParentNodeInGenCode;
-import static org.onosproject.yangutils.utils.UtilConstants.COLON;
-import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT_BASE_PKG;
-import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.HYPHEN;
-import static org.onosproject.yangutils.utils.UtilConstants.JAVA_KEY_WORDS;
-import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
-import static org.onosproject.yangutils.utils.UtilConstants.QUOTES;
-import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_FIRST_DIGIT;
-import static org.onosproject.yangutils.utils.UtilConstants.REGEX_WITH_ALL_SPECIAL_CHAR;
-import static org.onosproject.yangutils.utils.UtilConstants.REVISION_PREFIX;
-import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
-import static org.onosproject.yangutils.utils.UtilConstants.UNDER_SCORE;
-import static org.onosproject.yangutils.utils.UtilConstants.VERSION_PREFIX;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.addPackageInfo;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.createDirectories;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePackagePath;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getJavaPackageFromPackagePath;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getPackageDirPathFromJavaJPackage;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getPrefixForIdentifier;
-
-/**
- * Represents an utility Class for translating the name from YANG to java convention.
- */
-public final class JavaIdentifierSyntax {
-
- private static final int INDEX_ZERO = 0;
- private static final int INDEX_ONE = 1;
- private static final int VALUE_CHECK = 10;
- private static final String ZERO = "0";
- private static final String DATE_FORMAT = "yyyy-MM-dd";
-
- /**
- * Create instance of java identifier syntax.
- */
- private JavaIdentifierSyntax() {
- }
-
- /**
- * Returns the root package string.
- *
- * @param version YANG version
- * @param nameSpace name space of the module
- * @param revision revision of the module defined
- * @param resolver object of YANG to java naming conflict util
- * @return the root package string
- */
- public static String getRootPackage(byte version, String nameSpace,
- YangRevision revision,
- YangToJavaNamingConflictUtil resolver) {
-
- StringBuilder pkg = new StringBuilder(DEFAULT_BASE_PKG)
- .append(PERIOD)
- .append(getYangVersion(version))
- .append(PERIOD)
- .append(getPkgFromNameSpace(nameSpace, resolver));
- if (revision != null) {
- pkg.append(PERIOD)
- .append(getYangRevisionStr(revision.getRevDate()));
- }
- return pkg.toString().toLowerCase();
- }
-
-
- /**
- * Returns version.
- *
- * @param ver YANG version
- * @return version
- */
- private static String getYangVersion(byte ver) {
- return VERSION_PREFIX + ver;
- }
-
- /**
- * Returns package name from name space.
- *
- * @param nameSpace name space of YANG module
- * @param resolver object of YANG to java naming conflict util
- * @return java package name as per java rules
- */
- private static String getPkgFromNameSpace(String nameSpace,
- YangToJavaNamingConflictUtil resolver) {
-
- ArrayList<String> pkgArr = new ArrayList<>();
- nameSpace = nameSpace.replace(QUOTES, EMPTY_STRING);
- String properNameSpace = nameSpace.replaceAll
- (REGEX_WITH_ALL_SPECIAL_CHAR, COLON);
- String[] nameSpaceArr = properNameSpace.split(COLON);
-
- Collections.addAll(pkgArr, nameSpaceArr);
- return getPkgFrmArr(pkgArr, resolver);
- }
-
- /**
- * Returns revision string array.
- *
- * @param date YANG module revision
- * @return revision string
- */
- private static String getYangRevisionStr(Date date) {
- SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT);
- String dateInString = sdf.format(date);
- String[] revisionArr = dateInString.split(HYPHEN);
-
- StringBuilder rev = new StringBuilder(REVISION_PREFIX)
- .append(revisionArr[INDEX_ZERO]);
-
- for (int i = INDEX_ONE; i < revisionArr.length; i++) {
- Integer val = Integer.parseInt(revisionArr[i]);
- if (val < VALUE_CHECK) {
- rev.append(ZERO);
- }
- rev.append(val);
- }
- return rev.toString();
- }
-
- /**
- * Returns the package string.
- *
- * @param pkgArr package array
- * @param conflictResolver object of YANG to java naming conflict util
- * @return package string
- */
- private static String getPkgFrmArr(ArrayList<String> pkgArr, YangToJavaNamingConflictUtil conflictResolver) {
-
- StringBuilder pkg = new StringBuilder();
- int size = pkgArr.size();
- int i = 0;
- for (String member : pkgArr) {
- boolean presenceOfKeyword = JAVA_KEY_WORDS.contains(member.toLowerCase());
- if (presenceOfKeyword || member.matches(REGEX_FOR_FIRST_DIGIT)) {
- String prefix = getPrefixForIdentifier(conflictResolver);
- member = prefix + member;
- }
- pkg.append(member);
- if (i != size - 1) {
- pkg.append(PERIOD);
- }
- i++;
- }
- return pkg.toString();
- }
-
- /**
- * Returns enum's java name.
- *
- * @param name enum's name
- * @return enum's java name
- */
- public static String getEnumJavaAttribute(String name) {
-
- name = name.replaceAll(REGEX_WITH_ALL_SPECIAL_CHAR, COLON);
- String[] strArray = name.split(COLON);
- StringBuilder output = new StringBuilder();
- if (strArray[0].isEmpty()) {
- List<String> stringArrangement = new ArrayList<>();
- stringArrangement.addAll(Arrays.asList(strArray).subList(1, strArray.length));
- strArray = stringArrangement.toArray(new String[stringArrangement.size()]);
- }
- for (int i = 0; i < strArray.length; i++) {
- if (i > 0 && i < strArray.length) {
- output.append(UNDER_SCORE);
- }
- output.append(strArray[i]);
- }
- return output.toString();
- }
-
- /**
- * Creates a package structure with package info java file if not present.
- *
- * @param yangNode YANG node for which code is being generated
- * @throws IOException any IO exception
- */
- public static void createPackage(YangNode yangNode)
- throws IOException {
- if (!(yangNode instanceof JavaFileInfoContainer)) {
- throw new TranslatorException("current node must have java file info " +
- yangNode.getName() + " in " +
- yangNode.getLineNumber() + " at " +
- yangNode.getCharPosition() +
- " in " + yangNode.getFileName());
- }
- String pkgInfo;
- JavaFileInfoTranslator javaFileInfo = ((JavaFileInfoContainer) yangNode)
- .getJavaFileInfo();
- String pkg = getAbsolutePackagePath(javaFileInfo.getBaseCodeGenPath(),
- javaFileInfo.getPackageFilePath());
- JavaFileInfoTranslator parentInfo;
- if (!doesPackageExist(pkg)) {
- try {
- File pack = createDirectories(pkg);
- YangNode parent = getParentNodeInGenCode(yangNode);
- if (parent != null) {
- parentInfo = ((JavaFileInfoContainer) parent).getJavaFileInfo();
- pkgInfo = parentInfo.getJavaName();
- addPackageInfo(pack, pkgInfo, getJavaPackageFromPackagePath(pkg),
- true);
- } else {
- pkgInfo = javaFileInfo.getJavaName();
- addPackageInfo(pack, pkgInfo, getJavaPackageFromPackagePath(pkg),
- false);
- }
- } catch (IOException e) {
- throw new IOException("failed to create package-info file");
- }
- }
- }
-
- /**
- * Checks if the package directory structure created.
- *
- * @param pkg Package to check if it is created
- * @return existence status of package
- */
- static boolean doesPackageExist(String pkg) {
- File pkgDir = new File(getPackageDirPathFromJavaJPackage(pkg));
- File pkgWithFile = new File(pkgDir + SLASH + "package-info.java");
- return pkgDir.exists() && pkgWithFile.isFile();
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodBodyTypes.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodBodyTypes.java
deleted file mode 100644
index 8df3345..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodBodyTypes.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.translator.tojava.utils;
-
-/**
- * Represents method body types.
- */
-enum MethodBodyTypes {
-
- //Getter method body.
- GETTER,
-
- //Setter method body.
- SETTER,
-
- //Build method body.
- BUILD,
-
- //Constructor method body.
- CONSTRUCTOR,
-
- //Default constructor method body.
- DEFAULT_CONSTRUCTOR,
-
- //Hash code method body.
- HASH_CODE,
-
- //To string method body.
- TO_STRING,
-
- //Equals method body.
- EQUALS,
-
- //add to list method body.
- ADD_TO_LIST,
-
- //Augment map getter for full map.
- AUGMENTED_MAP_GETTER,
-
- //Augment map getter for value.
- AUGMENTED_MAP_GET_VALUE,
-
- //Augment map add
- AUGMENTED_MAP_ADD,
-
- //Manager methods
- MANAGER_METHODS,
-
- //Of method.
- OF_METHOD,
-
- //Hash code method
- HASH_CODE_METHOD,
-
- //Equals method.
- EQUALS_METHOD,
-
- //To string method
- TO_STRING_METHOD,
-
- //Enum method int value.
- ENUM_METHOD_INT_VALUE,
-
- //Enum method string value.
- ENUM_METHOD_STRING_VALUE
-
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodClassTypes.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodClassTypes.java
deleted file mode 100644
index 0e19388..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodClassTypes.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.translator.tojava.utils;
-
-/**
- * Represents java method types for classes.
- */
-enum MethodClassTypes {
-
- //Method for interface files.
- INTERFACE_TYPE,
-
- //Method for implementation classes.
- CLASS_TYPE
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGenerator.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGenerator.java
deleted file mode 100644
index a35ea24..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/MethodsGenerator.java
+++ /dev/null
@@ -1,1760 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.translator.tojava.utils;
-
-import org.onosproject.yangutils.datamodel.YangAtomicPath;
-import org.onosproject.yangutils.datamodel.YangCompilerAnnotation;
-import org.onosproject.yangutils.datamodel.YangEnum;
-import org.onosproject.yangutils.datamodel.YangEnumeration;
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.YangType;
-import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
-import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo;
-import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
-import org.onosproject.yangutils.utils.io.YangPluginConfig;
-import org.onosproject.yangutils.utils.io.impl.JavaDocGen;
-
-import java.util.LinkedHashMap;
-import java.util.List;
-
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_EVENT_SUBJECT_CLASS;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_SERVICE_AND_MANAGER;
-import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_UNION_CLASS;
-import static org.onosproject.yangutils.translator.tojava.utils.BracketType.OPEN_CLOSE_BRACKET;
-import static org.onosproject.yangutils.translator.tojava.utils.BracketType.OPEN_CLOSE_BRACKET_WITH_VALUE;
-import static org.onosproject.yangutils.translator.tojava.utils.IndentationType.EIGHT_SPACE;
-import static org.onosproject.yangutils.translator.tojava.utils.IndentationType.FOUR_SPACE;
-import static org.onosproject.yangutils.translator.tojava.utils.IndentationType.TWELVE_SPACE;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getAugmentMapTypeString;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getAugmentedClassNameForDataMethods;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getCurNodeName;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getSetOfNodeIdentifiers;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getEnumJavaAttribute;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodBodyTypes.AUGMENTED_MAP_ADD;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodBodyTypes.AUGMENTED_MAP_GETTER;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodBodyTypes.AUGMENTED_MAP_GET_VALUE;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodBodyTypes.GETTER;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodBodyTypes.MANAGER_METHODS;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodBodyTypes.SETTER;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodBodyTypes.TO_STRING;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodClassTypes.CLASS_TYPE;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodClassTypes.INTERFACE_TYPE;
-import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.brackets;
-import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getBitSetAttr;
-import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getCatchSubString;
-import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getCompareToString;
-import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getForLoopString;
-import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getGreaterThanCondition;
-import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getIfConditionBegin;
-import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getLesserThanCondition;
-import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getListAttribute;
-import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getMoreObjectAttr;
-import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getNewInstance;
-import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getNewLineAndSpace;
-import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getOmitNullValueString;
-import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getOverRideString;
-import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getParseFromStringMethod;
-import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getPatternQuoteString;
-import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getQuotedString;
-import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getReturnOfSubString;
-import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getReturnString;
-import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getSetValueParaCondition;
-import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getTrySubString;
-import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.getValueLeafSetString;
-import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.ifAndAndCondition;
-import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.ifConditionForIntInTypeDefConstructor;
-import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.ifEqualEqualCondition;
-import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.methodBody;
-import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.methodClose;
-import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.methodSignature;
-import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.methodSignatureClose;
-import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.multiAttrMethodSignature;
-import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.signatureClose;
-import static org.onosproject.yangutils.utils.UtilConstants.ADD;
-import static org.onosproject.yangutils.utils.UtilConstants.ADD_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.AND;
-import static org.onosproject.yangutils.utils.UtilConstants.ARRAY_LIST;
-import static org.onosproject.yangutils.utils.UtilConstants.AUGMENTED;
-import static org.onosproject.yangutils.utils.UtilConstants.BASE64;
-import static org.onosproject.yangutils.utils.UtilConstants.BIG_INTEGER;
-import static org.onosproject.yangutils.utils.UtilConstants.BITS;
-import static org.onosproject.yangutils.utils.UtilConstants.BIT_SET;
-import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_DATA_TYPE;
-import static org.onosproject.yangutils.utils.UtilConstants.BUILD;
-import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
-import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_LOWER_CASE;
-import static org.onosproject.yangutils.utils.UtilConstants.CASE;
-import static org.onosproject.yangutils.utils.UtilConstants.CLASS;
-import static org.onosproject.yangutils.utils.UtilConstants.CLASS_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET;
-import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS;
-import static org.onosproject.yangutils.utils.UtilConstants.COLON;
-import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
-import static org.onosproject.yangutils.utils.UtilConstants.DECODE;
-import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT;
-import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT_CAPS;
-import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION;
-import static org.onosproject.yangutils.utils.UtilConstants.ELSE;
-import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.ENUM;
-import static org.onosproject.yangutils.utils.UtilConstants.EQUAL;
-import static org.onosproject.yangutils.utils.UtilConstants.EQUALS_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.FALSE;
-import static org.onosproject.yangutils.utils.UtilConstants.FOR;
-import static org.onosproject.yangutils.utils.UtilConstants.FOR_TYPE_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
-import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_METHOD_NAME;
-import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_PARAM_NAME;
-import static org.onosproject.yangutils.utils.UtilConstants.GET;
-import static org.onosproject.yangutils.utils.UtilConstants.GET_DECODER;
-import static org.onosproject.yangutils.utils.UtilConstants.GET_METHOD_PREFIX;
-import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_METHOD_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.HASH;
-import static org.onosproject.yangutils.utils.UtilConstants.HASH_CODE_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.HELPER;
-import static org.onosproject.yangutils.utils.UtilConstants.IF;
-import static org.onosproject.yangutils.utils.UtilConstants.INSTANCE_OF;
-import static org.onosproject.yangutils.utils.UtilConstants.INT;
-import static org.onosproject.yangutils.utils.UtilConstants.IS_SELECT_LEAF;
-import static org.onosproject.yangutils.utils.UtilConstants.LEAF;
-import static org.onosproject.yangutils.utils.UtilConstants.LEAF_IDENTIFIER;
-import static org.onosproject.yangutils.utils.UtilConstants.LONG;
-import static org.onosproject.yangutils.utils.UtilConstants.MAP;
-import static org.onosproject.yangutils.utils.UtilConstants.MAX_RANGE;
-import static org.onosproject.yangutils.utils.UtilConstants.MIN_RANGE;
-import static org.onosproject.yangutils.utils.UtilConstants.NEW;
-import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
-import static org.onosproject.yangutils.utils.UtilConstants.NOT;
-import static org.onosproject.yangutils.utils.UtilConstants.NULL;
-import static org.onosproject.yangutils.utils.UtilConstants.OBJ;
-import static org.onosproject.yangutils.utils.UtilConstants.OBJECT;
-import static org.onosproject.yangutils.utils.UtilConstants.OBJECT_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.OF;
-import static org.onosproject.yangutils.utils.UtilConstants.ONE;
-import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CLOSE_BRACKET_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET;
-import static org.onosproject.yangutils.utils.UtilConstants.OPEN_PARENTHESIS;
-import static org.onosproject.yangutils.utils.UtilConstants.OP_PARAM;
-import static org.onosproject.yangutils.utils.UtilConstants.OTHER;
-import static org.onosproject.yangutils.utils.UtilConstants.OVERRIDE;
-import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
-import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE;
-import static org.onosproject.yangutils.utils.UtilConstants.PROCESS_SUBTREE_FILTERING;
-import static org.onosproject.yangutils.utils.UtilConstants.PROTECTED;
-import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC;
-import static org.onosproject.yangutils.utils.UtilConstants.QUOTES;
-import static org.onosproject.yangutils.utils.UtilConstants.RETURN;
-import static org.onosproject.yangutils.utils.UtilConstants.RPC_INPUT_VAR_NAME;
-import static org.onosproject.yangutils.utils.UtilConstants.SCHEMA_NAME;
-import static org.onosproject.yangutils.utils.UtilConstants.SELECT_ALL_CHILD;
-import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLON;
-import static org.onosproject.yangutils.utils.UtilConstants.SET_METHOD_PREFIX;
-import static org.onosproject.yangutils.utils.UtilConstants.SET_SELECT_LEAF;
-import static org.onosproject.yangutils.utils.UtilConstants.SET_VALUE_PARA;
-import static org.onosproject.yangutils.utils.UtilConstants.SIXTEEN_SPACE_INDENTATION;
-import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
-import static org.onosproject.yangutils.utils.UtilConstants.SPLIT_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.SQUARE_BRACKETS;
-import static org.onosproject.yangutils.utils.UtilConstants.STATIC;
-import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE;
-import static org.onosproject.yangutils.utils.UtilConstants.SUFFIX_S;
-import static org.onosproject.yangutils.utils.UtilConstants.SWITCH;
-import static org.onosproject.yangutils.utils.UtilConstants.THIS;
-import static org.onosproject.yangutils.utils.UtilConstants.TMP_VAL;
-import static org.onosproject.yangutils.utils.UtilConstants.TO_CAPS;
-import static org.onosproject.yangutils.utils.UtilConstants.TO_STRING_METHOD;
-import static org.onosproject.yangutils.utils.UtilConstants.TRIM_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.TRUE;
-import static org.onosproject.yangutils.utils.UtilConstants.TWELVE_SPACE_INDENTATION;
-import static org.onosproject.yangutils.utils.UtilConstants.VALIDATE_RANGE;
-import static org.onosproject.yangutils.utils.UtilConstants.VALUE;
-import static org.onosproject.yangutils.utils.UtilConstants.VALUE_LEAF_SET;
-import static org.onosproject.yangutils.utils.UtilConstants.VOID;
-import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO;
-import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO_LOWER_CASE;
-import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILD_METHOD;
-import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.CONSTRUCTOR;
-import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.DEFAULT_CONSTRUCTOR;
-import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.FROM_METHOD;
-import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.GETTER_METHOD;
-import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.MANAGER_SETTER_METHOD;
-import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.OF_METHOD;
-import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.SETTER_METHOD;
-import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.TYPE_CONSTRUCTOR;
-import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateForAddAugmentation;
-import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateForBuilderMethod;
-import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateForGetAugmentation;
-import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateForGetMethodWithAttribute;
-import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.generateForValidatorMethod;
-import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getSmallCase;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast;
-
-/**
- * Represents generator for methods of generated files based on the file type.
- */
-public final class MethodsGenerator {
- private static final String BIT_NAMES_VAR = "bitNames";
- private static final String BIT_NAME_VAR = "bitName";
-
- /**
- * Creates an instance of method generator.
- */
- private MethodsGenerator() {
- }
-
- /**
- * Returns the methods strings for builder interface.
- *
- * @param name attribute name
- * @return method string for builder interface
- */
- public static String parseBuilderInterfaceBuildMethodString(String name) {
- return getJavaDoc(BUILD_METHOD, name, false, null) +
- getBuildForInterface(name);
- }
-
- /**
- * Returns getter string.
- *
- * @param attr attribute info
- * @param genType generated java files
- * @return getter string
- */
- public static String getGetterString(JavaAttributeInfo attr, int genType) {
-
- String returnType = getReturnType(attr);
- String attributeName = attr.getAttributeName();
- String appDataStructure = null;
- StringBuilder builder = new StringBuilder();
- if (attr.getCompilerAnnotation() != null) {
- appDataStructure =
- attr.getCompilerAnnotation().getYangAppDataStructure()
- .getDataStructure().name();
- }
- if (genType == GENERATE_SERVICE_AND_MANAGER) {
- builder.append(generateForGetMethodWithAttribute(returnType))
- .append(getGetterForInterface(
- attributeName, returnType, attr.isListAttr(),
- genType, attr.getCompilerAnnotation()));
-
- return builder.toString();
- }
-
- builder.append(getJavaDoc(GETTER_METHOD, attributeName, attr
- .isListAttr(), appDataStructure))
- .append(getGetterForInterface(
- attributeName, returnType, attr.isListAttr(),
- genType, attr.getCompilerAnnotation()));
-
- return builder.toString();
- }
-
- /**
- * Returns setter string.
- *
- * @param attr attribute info
- * @param className java class name
- * @param genType generated java files
- * @return setter string
- */
- public static String getSetterString(JavaAttributeInfo attr,
- String className, int genType) {
-
- String attrType = getReturnType(attr);
- String attributeName = attr.getAttributeName();
- JavaDocGen.JavaDocType type;
- StringBuilder builder = new StringBuilder();
- if (genType == GENERATE_SERVICE_AND_MANAGER) {
- type = MANAGER_SETTER_METHOD;
- } else {
- type = SETTER_METHOD;
- }
-
- String appDataStructure = null;
- if (attr.getCompilerAnnotation() != null) {
- appDataStructure =
- attr.getCompilerAnnotation().getYangAppDataStructure()
- .getDataStructure().name();
- }
- builder.append(getJavaDoc(type, attributeName, attr.isListAttr(),
- appDataStructure))
- .append(getSetterForInterface(attributeName, attrType, className,
- attr.isListAttr(), genType,
- attr.getCompilerAnnotation()));
- return builder.toString();
- }
-
- /**
- * Returns constructor method string.
- *
- * @param name class name
- * @return constructor string
- */
- private static String getConstructorString(String name) {
- return getJavaDoc(CONSTRUCTOR, name, false, null);
- }
-
- /**
- * Returns default constructor method string.
- *
- * @param name class name
- * @param modifierType modifier type
- * @return default constructor string
- */
- public static String getDefaultConstructorString(String name,
- String modifierType) {
- return getJavaDoc(DEFAULT_CONSTRUCTOR, name, false, null)
- + getDefaultConstructor(name, modifierType) + NEW_LINE;
- }
-
- /**
- * Returns build method string.
- *
- * @param name class name
- * @param isRootNode if root node
- * @return build string
- */
- public static String getBuildString(String name, boolean isRootNode) {
- if (isRootNode) {
- return NEW_LINE + getBuild(name, true);
- }
- return FOUR_SPACE_INDENTATION + OVERRIDE + NEW_LINE +
- getBuild(name, false);
- }
-
- /**
- * Returns the getter method strings for class file.
- *
- * @param attr attribute info
- * @param generatedJavaFiles for the type of java file being generated
- * @return getter method for class
- */
- public static String getGetterForClass(JavaAttributeInfo attr,
- int generatedJavaFiles) {
-
- String attrQualifiedType = getReturnType(attr);
- String attributeName = attr.getAttributeName();
-
- if (!attr.isListAttr()) {
- return getGetter(attrQualifiedType, attributeName,
- generatedJavaFiles);
- }
- String attrParam = getListAttribute(attrQualifiedType,
- attr.getCompilerAnnotation());
- return getGetter(attrParam, attributeName, generatedJavaFiles);
- }
-
- /**
- * Returns getter for attribute.
- *
- * @param type return type
- * @param name attribute name
- * @param genType generated java files
- * @return getter for attribute
- */
- static String getGetter(String type, String name, int genType) {
- StringBuilder builder = new StringBuilder();
- if (genType == GENERATE_SERVICE_AND_MANAGER) {
- //Append method signature.
- builder.append(methodSignature(getCapitalCase(name), GET,
- PUBLIC, null, type, null,
- CLASS_TYPE))
- //Append method body.
- .append(methodBody(MANAGER_METHODS, null, null,
- EIGHT_SPACE_INDENTATION, null,
- type, false, null))
- .append(signatureClose())
- //Append method close.
- .append(methodClose(FOUR_SPACE));
- return builder.toString();
- }
- builder.append(methodSignature(name, EMPTY_STRING,
- PUBLIC, null, type, null,
- CLASS_TYPE))
- //Append method body.
- .append(methodBody(GETTER, name, name,
- EIGHT_SPACE_INDENTATION, null,
- type, false, null))
- .append(signatureClose())
- //Append method close.
- .append(methodClose(FOUR_SPACE));
- return builder.toString();
- }
-
- /**
- * Returns the setter method strings for class file.
- *
- * @param attr attribute info
- * @param className name of the class
- * @param generatedJavaFiles generated java files
- * @return setter method for class
- */
- public static String getSetterForClass(JavaAttributeInfo attr,
- String className,
- int generatedJavaFiles) {
- String attrQualifiedType = getReturnType(attr);
- String attributeName = attr.getAttributeName();
- boolean isTypeNull = false;
- if (attr.getAttributeType() == null) {
- isTypeNull = true;
- }
- if (!attr.isListAttr()) {
- return getSetter(className, attributeName, attrQualifiedType,
- generatedJavaFiles, isTypeNull, false);
- }
- String attrParam = getListAttribute(attrQualifiedType,
- attr.getCompilerAnnotation());
- return getSetter(className, attributeName, attrParam,
- generatedJavaFiles, isTypeNull, true);
- }
-
- /**
- * Returns setter for attribute.
- *
- * @param className class name
- * @param name attribute name
- * @param type return type
- * @param isTypeNull if attribute type is null
- * @param isList true if leaf-list
- * @return setter for attribute
- */
- private static String getSetter(String className, String name, String type,
- int genType,
- boolean isTypeNull, boolean isList) {
- StringBuilder builder = new StringBuilder();
- if (genType == GENERATE_SERVICE_AND_MANAGER) {
- //Append method signature.
- builder.append(methodSignature(getCapitalCase(name),
- SET_METHOD_PREFIX,
- PUBLIC, name, VOID, type,
- CLASS_TYPE))
- //Append method body.
- .append(methodBody(MANAGER_METHODS, null, null,
- EIGHT_SPACE_INDENTATION, null, null,
- false, null))
- .append(methodClose(FOUR_SPACE));
- return builder.toString();
- }
- if (genType == GENERATE_EVENT_SUBJECT_CLASS) {
- builder.append(methodSignature(name, EMPTY_STRING, PUBLIC, name, VOID,
- type, CLASS_TYPE))
-
- //Append method body.
- .append(methodBody(SETTER, name, name,
- EIGHT_SPACE_INDENTATION, null, null,
- false, null))
- .append(methodClose(FOUR_SPACE));
- return builder.toString();
- }
- builder.append(methodSignature(name, EMPTY_STRING,
- PUBLIC, name, getCapitalCase(className) +
- BUILDER, type, CLASS_TYPE));
- if (!isTypeNull && !isList) {
- builder.append(getValueLeafSetString(name));
- } else {
- builder.append(EMPTY_STRING);
- }
- //Append method body.
- builder.append(methodBody(SETTER, name, name,
- EIGHT_SPACE_INDENTATION, null, null,
- true, null))
- //Append method close.
- .append(methodClose(FOUR_SPACE));
- return builder.toString();
- }
-
- /**
- * Returns the setter method strings for class file.
- *
- * @param attr attribute info
- * @return setter method for class
- */
- static String getSetterForTypeDefClass(JavaAttributeInfo attr) {
-
- String attrQualifiedType = getReturnType(attr);
- String attributeName = attr.getAttributeName();
- return getTypeDefSetter(attrQualifiedType, attributeName);
- }
-
- /**
- * Returns type def's setter for attribute.
- *
- * @param type data type
- * @param name attribute name
- * @return setter for type def's attribute
- */
- private static String getTypeDefSetter(String type, String name) {
- return methodSignature(getCapitalCase(name), SET_METHOD_PREFIX, PUBLIC,
- name, VOID, type, CLASS_TYPE) +
- methodBody(SETTER, name, name, EIGHT_SPACE_INDENTATION, null,
- null, false, null) + methodClose(FOUR_SPACE);
- }
-
- /**
- * Returns the getter method strings for interface file.
- *
- * @param yangName name of the attribute
- * @param returnType return type of attribute
- * @param isList is list attribute
- * @param genType generated java files
- * @param annotation compiler annotation
- * @return getter method for interface
- */
- static String getGetterForInterface(String yangName, String returnType,
- boolean isList,
- int genType,
- YangCompilerAnnotation annotation) {
- if (!isList) {
- return getGetterInterfaceString(returnType, yangName,
- genType);
- }
- String listAttr = getListAttribute(returnType, annotation);
- return getGetterInterfaceString(listAttr, yangName, genType);
- }
-
- /**
- * Returns getter for attribute in interface.
- *
- * @param returnType return type
- * @param yangName attribute name
- * @return getter for interface
- */
- private static String getGetterInterfaceString(String returnType,
- String yangName,
- int genType) {
- switch (genType) {
- case GENERATE_SERVICE_AND_MANAGER:
- return getGetMethodWithArgument(returnType, yangName);
- default:
- return methodSignature(yangName, EMPTY_STRING, null,
- null, returnType, null, INTERFACE_TYPE);
- }
- }
-
- /**
- * Returns the setter method strings for interface file.
- *
- * @param attrName name of the attribute
- * @param attrType return type of attribute
- * @param className name of the java class being generated
- * @param isList is list attribute
- * @param genType generated java files
- * @param annotation compiler annotations
- * @return setter method for interface
- */
- static String getSetterForInterface(String attrName, String attrType,
- String className,
- boolean isList, int genType,
- YangCompilerAnnotation annotation) {
- if (!isList) {
- return getSetterInterfaceString(className, attrName, attrType,
- genType);
- }
-
- String listAttr = getListAttribute(attrType, annotation);
- return getSetterInterfaceString(className, attrName, listAttr, genType);
- }
-
- /**
- * Returns setter string for interface.
- *
- * @param name class name
- * @param attrName attribute name
- * @param attrType attribute type
- * @return setter string
- */
- private static String getSetterInterfaceString(String name,
- String attrName,
- String attrType,
- int genType) {
- if (genType == GENERATE_SERVICE_AND_MANAGER) {
- return methodSignature(getCapitalCase(attrName),
- SET_METHOD_PREFIX,
- null, attrName, VOID, attrType +
- OP_PARAM, INTERFACE_TYPE);
- }
- return methodSignature(attrName, EMPTY_STRING, null,
- attrName, name + BUILDER, attrType, INTERFACE_TYPE);
- }
-
- /**
- * Returns return type for attribute.
- *
- * @param attr attribute info
- * @return return type
- */
- private static String getReturnType(JavaAttributeInfo attr) {
- String returnType;
- StringBuilder builder = new StringBuilder();
- if (attr.isQualifiedName() &&
- attr.getImportInfo().getPkgInfo() != null) {
- returnType = attr.getImportInfo().getPkgInfo() + PERIOD;
- builder.append(returnType);
- }
- returnType = attr.getImportInfo().getClassInfo();
- builder.append(returnType);
- return builder.toString();
- }
-
- /**
- * Returns the build method strings for interface file.
- *
- * @param yangName name of the interface
- * @return build method for interface
- */
- static String getBuildForInterface(String yangName) {
- return methodSignature(BUILD, EMPTY_STRING, null, null,
- yangName, null, INTERFACE_TYPE);
- }
-
- /**
- * Returns constructor string for impl class.
- *
- * @param yangName class name
- * @param isRootNode if root node
- * @return constructor string
- */
- static String getConstructorStart(String yangName,
- boolean isRootNode) {
- StringBuilder builder = new StringBuilder(
- getConstructorString(yangName));
-
- String name = getCapitalCase(yangName);
- String returnType = DEFAULT_CAPS + name;
- if (isRootNode) {
- returnType = name + OP_PARAM;
- }
- builder.append(methodSignature(
- returnType, EMPTY_STRING, PROTECTED, BUILDER_LOWER_CASE + OBJECT,
- null, name + BUILDER, CLASS_TYPE));
- return builder.toString();
- }
-
- /**
- * Returns the constructor strings for class file.
- *
- * @param attr attribute info
- * @param genType generated java files
- * @return constructor for class
- */
- public static String getConstructor(JavaAttributeInfo attr, int genType) {
- String attrName = attr.getAttributeName();
- String attrCaps = getCapitalCase(attrName);
- switch (genType) {
- case GENERATE_SERVICE_AND_MANAGER:
- return methodBody(MethodBodyTypes.CONSTRUCTOR, attrName,
- attrCaps, EIGHT_SPACE_INDENTATION, GET, null,
- false, null);
- default:
- return methodBody(MethodBodyTypes.CONSTRUCTOR, attrName,
- attrName, EIGHT_SPACE_INDENTATION, EMPTY_STRING,
- null, false, null);
- }
- }
-
- /**
- * Returns the rpc strings for service interface.
- *
- * @param rpcName name of the rpc
- * @param input name of input
- * @param output name of output
- * @return rpc method string
- */
- public static String getRpcServiceMethod(String rpcName, String input,
- String output) {
- String inputVal = EMPTY_STRING;
- if (!input.equals(EMPTY_STRING)) {
- inputVal = RPC_INPUT_VAR_NAME;
- }
- return methodSignature(rpcName, EMPTY_STRING, null,
- inputVal, output, input, INTERFACE_TYPE) +
- NEW_LINE;
- }
-
- /**
- * Returns the build method strings for class file.
- *
- * @param yangName class name
- * @param isRootNode if root node
- * @return build method string for class
- */
- static String getBuild(String yangName, boolean isRootNode) {
- String type = DEFAULT_CAPS + yangName;
- if (isRootNode) {
- type = yangName + OP_PARAM;
- }
- return methodSignature(BUILD, EMPTY_STRING, PUBLIC, null,
- yangName, null,
- CLASS_TYPE) +
- methodBody(MethodBodyTypes.BUILD, type, BUILD,
- EIGHT_SPACE_INDENTATION, EMPTY_STRING,
- null, false, null) +
- methodClose(FOUR_SPACE);
- }
-
- /**
- * Returns the Default constructor strings for class file.
- *
- * @param name name of the class
- * @param modifierType modifier type for default constructor
- * @return Default constructor for class
- */
- private static String getDefaultConstructor(String name,
- String modifierType) {
- return methodSignature(name, EMPTY_STRING, modifierType, null,
- null, null, CLASS_TYPE) +
- methodClose(FOUR_SPACE);
- }
-
- /**
- * Returns to string method's open strings.
- *
- * @return string method's open string
- */
- static String getToStringMethodOpen() {
- StringBuilder builder = new StringBuilder(getOverRideString());
- builder.append(methodSignature(TO_STRING_METHOD, EMPTY_STRING,
- PUBLIC, null, STRING_DATA_TYPE, null,
- CLASS_TYPE));
- builder.append(getReturnString(GOOGLE_MORE_OBJECT_METHOD_STRING,
- EIGHT_SPACE_INDENTATION)).append(NEW_LINE)
- .append(getOmitNullValueString());
- return builder.toString();
- }
-
- /**
- * Returns to string method's close string.
- *
- * @return to string method close string
- */
- static String getToStringMethodClose() {
- return TWELVE_SPACE_INDENTATION + PERIOD + TO_STRING_METHOD +
- brackets(OPEN_CLOSE_BRACKET, null, null) + signatureClose() +
- methodClose(FOUR_SPACE);
- }
-
- /**
- * Returns to string method for class.
- *
- * @param attr java attribute
- * @return to string method for class
- */
- public static String getToStringMethod(JavaAttributeInfo attr) {
- return methodBody(TO_STRING, attr.getAttributeName(), null,
- TWELVE_SPACE_INDENTATION, null, null, false, null);
- }
-
- /**
- * Returns from string method's open string.
- *
- * @param className name of the class
- * @return from string method's open string
- */
- static String getFromStringMethodSignature(String className) {
- return getJavaDoc(FROM_METHOD, className, false, null) +
- methodSignature(FROM_STRING_METHOD_NAME, EMPTY_STRING, PUBLIC +
- SPACE + STATIC, FROM_STRING_PARAM_NAME,
- className, STRING_DATA_TYPE,
- CLASS_TYPE);
- }
-
- /**
- * Return from string method's close string.
- *
- * @return from string method's close string
- */
- static String getFromStringMethodClose() {
- return getReturnString(NULL, EIGHT_SPACE_INDENTATION) +
- signatureClose() + methodClose(FOUR_SPACE);
- }
-
- /**
- * Return from string method's body string.
- *
- * @param attr attribute info
- * @param fromAttr attribute info for the from string wrapper
- * type
- * @param name class name
- * @return from string method's body string
- */
- public static String getFromStringMethod(JavaAttributeInfo attr,
- JavaAttributeInfo fromAttr, String name) {
-
- return EIGHT_SPACE_INDENTATION + getTrySubString() +
- getNewLineAndSpace(TWELVE_SPACE_INDENTATION) +
- getParsedSubString(attr, fromAttr, name) +
- getReturnOfSubString() + EIGHT_SPACE_INDENTATION +
- getCatchSubString() +
- getNewLineAndSpace(EIGHT_SPACE_INDENTATION) +
- CLOSE_CURLY_BRACKET;
- }
-
- /**
- * Returns sub string with parsed statement for union's from string method.
- *
- * @param attr attribute info
- * @param name class name
- * @return sub string with parsed statement for union's from string method
- */
- private static String getParsedSubString(JavaAttributeInfo attr,
- JavaAttributeInfo fromStringAttr, String name) {
-
- String targetDataType = getReturnType(attr);
- YangDataTypes types = fromStringAttr.getAttributeType()
- .getDataType();
- StringBuilder method = new StringBuilder();
- switch (types) {
- case BITS:
- return targetDataType + SPACE + TMP_VAL + SPACE + EQUAL +
- SPACE + getCapitalCase(name) + getCapitalCase(attr.getAttributeName()) +
- PERIOD + FROM_STRING_METHOD_NAME +
- brackets(OPEN_CLOSE_BRACKET_WITH_VALUE,
- FROM_STRING_PARAM_NAME, null) + signatureClose();
- case BINARY:
- return method.append(targetDataType).append(SPACE).append(TMP_VAL)
- .append(SPACE).append(EQUAL).append(SPACE).append(
- geStringConverterForBinary(FROM_STRING_PARAM_NAME))
- .append(signatureClose()).toString();
- default:
- return targetDataType + SPACE + TMP_VAL + SPACE + EQUAL +
- SPACE + getParseFromStringMethod(
- targetDataType, fromStringAttr.getAttributeType()) +
- brackets(OPEN_CLOSE_BRACKET_WITH_VALUE,
- FROM_STRING_PARAM_NAME, null) + signatureClose();
- }
- }
-
- /**
- * Returns to string converter for binary type.
- *
- * @param var variable name
- * @return to string method body
- */
- private static String geStringConverterForBinary(String var) {
- StringBuilder builder = new StringBuilder();
- return builder.append(BASE64).append(PERIOD)
- .append(GET_DECODER).append(OPEN_CLOSE_BRACKET_STRING).append(PERIOD)
- .append(DECODE).append(brackets(OPEN_CLOSE_BRACKET_WITH_VALUE,
- var, null)).toString();
- }
-
- /**
- * Returns hash code method open strings.
- *
- * @return hash code method open string
- */
- static String getHashCodeMethodOpen() {
- String line;
- StringBuilder builder = new StringBuilder(getOverRideString());
- builder.append(methodSignature(HASH_CODE_STRING, EMPTY_STRING, PUBLIC,
- null, INT, null, CLASS_TYPE));
- line = getReturnString(OBJECT_STRING + SUFFIX_S + PERIOD + HASH +
- OPEN_PARENTHESIS, EIGHT_SPACE_INDENTATION);
- builder.append(line);
- return builder.toString();
- }
-
- /**
- * Returns hash code methods close string.
- *
- * @param hashcodeString hash code string
- * @return to hash code method close string
- */
- static String getHashCodeMethodClose(String hashcodeString) {
- String[] array = {SPACE, COMMA};
- hashcodeString = trimAtLast(hashcodeString, array);
- return hashcodeString + CLOSE_PARENTHESIS + signatureClose() +
- methodClose(FOUR_SPACE);
- }
-
- /**
- * Returns hash code method for class.
- *
- * @param attr attribute info
- * @return hash code method
- */
- public static String getHashCodeMethod(JavaAttributeInfo attr) {
- return attr.getAttributeName() + COMMA + SPACE;
- }
-
- /**
- * Returns equals method open strings.
- *
- * @param className class name
- * @return equals method open string
- */
- static String getEqualsMethodOpen(String className) {
- return getOverRideString() +
- methodSignature(EQUALS_STRING, EMPTY_STRING, PUBLIC, OBJ,
- BOOLEAN_DATA_TYPE, OBJECT_STRING,
- CLASS_TYPE) +
- getEqualsMethodsCommonIfCondition() +
- getEqualsMethodsSpecificIfCondition(className);
- }
-
- /**
- * Returns equal methods if condition string.
- *
- * @return if condition string
- */
- private static String getEqualsMethodsCommonIfCondition() {
- return getIfConditionBegin(EIGHT_SPACE_INDENTATION, THIS + SPACE +
- EQUAL + EQUAL + SPACE + OBJ) + getReturnString(
- TRUE, TWELVE_SPACE_INDENTATION) + signatureClose()
- + methodClose(EIGHT_SPACE);
- }
-
- /**
- * Returns if condition for specific class object in equals method.
- *
- * @param className class name
- * @return if condition string
- */
- private static String getEqualsMethodsSpecificIfCondition(String className) {
- return EIGHT_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS + OBJ +
- INSTANCE_OF + className + CLOSE_PARENTHESIS + SPACE +
- OPEN_CURLY_BRACKET + NEW_LINE + TWELVE_SPACE_INDENTATION +
- className + SPACE + OTHER + SPACE + EQUAL + SPACE +
- OPEN_PARENTHESIS + className + CLOSE_PARENTHESIS + SPACE + OBJ +
- SEMI_COLON + NEW_LINE + TWELVE_SPACE_INDENTATION + RETURN +
- NEW_LINE;
- }
-
- /**
- * Returns equals methods close string.
- *
- * @param equalMethodString equal method string
- * @return equals method close string
- */
- static String getEqualsMethodClose(String equalMethodString) {
- String[] array = {NEW_LINE, AND, AND, SPACE};
- equalMethodString = trimAtLast(equalMethodString, array) +
- signatureClose();
- return equalMethodString + methodClose(EIGHT_SPACE) +
- getReturnString(FALSE, EIGHT_SPACE_INDENTATION) +
- signatureClose() + methodClose(FOUR_SPACE);
- }
-
- /**
- * Returns equals method for class.
- *
- * @param attr attribute info
- * @return equals method
- */
- public static String getEqualsMethod(JavaAttributeInfo attr) {
- String attributeName = attr.getAttributeName();
- return SIXTEEN_SPACE_INDENTATION + OBJECT_STRING + SUFFIX_S +
- PERIOD + EQUALS_STRING + OPEN_PARENTHESIS + attributeName +
- COMMA + SPACE + OTHER + PERIOD + attributeName +
- CLOSE_PARENTHESIS + SPACE + AND + AND;
- }
-
- /**
- * Returns of method's string and java doc for special type.
- *
- * @param attr attribute info
- * @param className class name
- * @return of method's string and java doc for special type
- */
- public static String getOfMethodStringAndJavaDoc(JavaAttributeInfo attr,
- String className) {
- String attrType = getReturnType(attr);
- String attrName = attr.getAttributeName();
-
- return getJavaDoc(OF_METHOD, className + FOR_TYPE_STRING + attrName,
- false, null) + getOfMethodString(attrType, className);
- }
-
- /**
- * Returns of method's string.
- *
- * @param type data type
- * @param name class name
- * @return of method's string
- */
- private static String getOfMethodString(String type, String name) {
- return methodSignature(OF, EMPTY_STRING, PUBLIC + SPACE + STATIC,
- VALUE, name, type, CLASS_TYPE) +
- methodBody(MethodBodyTypes.OF_METHOD, name, null,
- EIGHT_SPACE_INDENTATION, EMPTY_STRING, null, false, null) +
- methodClose(FOUR_SPACE);
- }
-
- /**
- * Returns string and java doc for constructor of type class.
- *
- * @param attr attribute info
- * @param className class name
- * @param genType generate file type
- * @param count type count
- * @return string and java doc for constructor of type class
- */
- public static String getTypeConstructorStringAndJavaDoc(
- JavaAttributeInfo attr, String className, int genType, int count) {
- String attrType = getReturnType(attr);
- String attrName = attr.getAttributeName();
- return getJavaDoc(TYPE_CONSTRUCTOR, attrName, false, null) +
- getTypeConstructorString(attrType, attrName, className,
- genType, count);
- }
-
- /**
- * Returns string and java doc for constructor of type class.
- *
- * @param attr1 first attribute info
- * @param attr2 second attribute info
- * @param genType class name
- * @param type conflict validate type
- * @param addFirst whether int came first or uInt came first
- * @param count type count
- * @return string and java doc for constructor of type class
- */
- public static String getTypeConstructorStringAndJavaDoc(
- JavaAttributeInfo attr1, JavaAttributeInfo attr2, String genType,
- ValidatorTypeForUnionTypes type, boolean addFirst, int count) {
-
- String attrType = getReturnType(attr1);
- String attrName1 = "";
- String attrName2 = "";
- if (attr1 != null) {
- if (addFirst) {
- attrName1 = attr1.getAttributeName();
- } else {
- attrName2 = attr1.getAttributeName();
- }
- }
- if (attr2 != null) {
- if (addFirst) {
- attrName2 = attr2.getAttributeName();
- } else {
- attrName1 = attr2.getAttributeName();
- }
- }
-
- String appDataStructure = null;
- if (attr1 != null && attr1.getCompilerAnnotation() != null) {
- appDataStructure =
- attr1.getCompilerAnnotation().getYangAppDataStructure()
- .getDataStructure().name();
- }
- String doc;
- if (attrName1.isEmpty()) {
- doc = attrName2;
- } else {
- doc = attrName1;
- }
- return getJavaDoc(TYPE_CONSTRUCTOR, doc, false, appDataStructure) +
- getTypeConstructorString(attrType, attrName1,
- attrName2, genType,
- type, addFirst, count);
- }
-
- /**
- * Returns type constructor string.
- *
- * @param type data type
- * @param name attribute name
- * @param className class name
- * @param genType generated file type
- * @param count type count
- * @return type constructor string
- */
- private static String getTypeConstructorString(String type, String name,
- String className, int genType, int count) {
- StringBuilder builder = new StringBuilder();
- builder.append(
- methodSignature(className, EMPTY_STRING, PUBLIC, name,
- null, type, CLASS_TYPE));
- if (genType == GENERATE_UNION_CLASS) {
- builder.append(EIGHT_SPACE_INDENTATION).append(SET_VALUE_PARA)
- .append(PERIOD).append(SET_METHOD_PREFIX).append(
- brackets(OPEN_CLOSE_BRACKET_WITH_VALUE, count + EMPTY_STRING,
- null)).append(signatureClose());
- }
- builder.append(methodBody(SETTER, name, null, EIGHT_SPACE_INDENTATION,
- EMPTY_STRING, null, false, null))
- .append(methodClose(FOUR_SPACE));
- return builder.toString();
- }
-
- /**
- * Returns type constructor string.
- *
- * @param type data type
- * @param attr1 attribute attr1
- * @param className class attr1
- * @param count type count
- * @return type constructor string
- */
- private static String getTypeConstructorString(
- String type, String attr1, String attr2, String className,
- ValidatorTypeForUnionTypes validatorType, boolean addInt, int count) {
- StringBuilder constructor = new StringBuilder(
- methodSignature(className, EMPTY_STRING, PUBLIC, attr1,
- null, type, CLASS_TYPE))
- .append(EIGHT_SPACE_INDENTATION).append(SET_VALUE_PARA)
- .append(PERIOD).append(SET_METHOD_PREFIX).append(
- brackets(OPEN_CLOSE_BRACKET_WITH_VALUE, count + EMPTY_STRING,
- null)).append(signatureClose())
- .append(ifConditionForIntInTypeDefConstructor(validatorType,
- addInt, attr1))
- .append(methodBody(SETTER, attr1, null,
- TWELVE_SPACE_INDENTATION, EMPTY_STRING,
- null, false, attr1));
- String str = EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + SPACE +
- ELSE + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
- constructor.append(str)
- .append(methodBody(SETTER, attr2, null,
- TWELVE_SPACE_INDENTATION, EMPTY_STRING,
- null, false, attr1))
- .append(methodClose(FOUR_SPACE))
- .append(methodClose(EIGHT_SPACE));
-
- return constructor.toString();
- }
-
- /**
- * Returns interface of add augmentation.
- *
- * @return interface of add augmentation
- */
- static String getAddAugmentInfoMethodInterface() {
- StringBuilder builder = new StringBuilder(generateForAddAugmentation());
- LinkedHashMap<String, String> map = new LinkedHashMap<>();
- map.put(VALUE, OBJECT_STRING);
- map.put(CLASS + OBJECT_STRING, CLASS_STRING);
- builder.append(multiAttrMethodSignature(ADD_STRING + YANG_AUGMENTED_INFO,
- EMPTY_STRING, EMPTY_STRING,
- VOID, map, INTERFACE_TYPE));
- return builder.toString();
- }
-
- /**
- * Returns implementation of add augmentation.
- *
- * @return implementation of add augmentation
- */
- static String getAddAugmentInfoMethodImpl() {
- StringBuilder builder = new StringBuilder(getOverRideString());
- LinkedHashMap<String, String> map = new LinkedHashMap<>();
- map.put(VALUE, OBJECT_STRING);
- map.put(CLASS + OBJECT_STRING, CLASS_STRING);
- builder.append(multiAttrMethodSignature(ADD_STRING + YANG_AUGMENTED_INFO,
- EMPTY_STRING, PUBLIC,
- VOID, map, CLASS_TYPE))
- .append(methodBody(AUGMENTED_MAP_ADD, null, null,
- EIGHT_SPACE_INDENTATION, null, null, false, null))
- .append(methodClose(FOUR_SPACE))
- .append(NEW_LINE);
- return builder.toString();
- }
-
- /**
- * Returns interface of get YANG augment info.
- *
- * @return interface of get YANG augment info
- */
- static String getYangAugmentInfoInterface() {
- return generateForGetAugmentation() +
- methodSignature(YANG_AUGMENTED_INFO_LOWER_CASE, EMPTY_STRING,
- null, CLASS + OBJECT_STRING,
- OBJECT_STRING, CLASS_STRING, INTERFACE_TYPE);
- }
-
- /**
- * Returns implementation of get YANG augment info.
- *
- * @return implementation of get YANG augment info
- */
- static String getYangAugmentInfoImpl() {
- return getOverRideString() +
- methodSignature(YANG_AUGMENTED_INFO_LOWER_CASE, EMPTY_STRING,
- PUBLIC, CLASS + OBJECT_STRING, OBJECT_STRING,
- CLASS_STRING, CLASS_TYPE) +
- methodBody(AUGMENTED_MAP_GET_VALUE, null, null,
- EIGHT_SPACE_INDENTATION, null, null, false, null) +
- methodClose(FOUR_SPACE);
- }
-
- /**
- * Returns implementation of get YANG augment info.
- *
- * @return implementation of get YANG augment info
- */
- static String getYangAugmentInfoMapInterface() {
- return NEW_LINE +
- getJavaDoc(GETTER_METHOD, YANG_AUGMENTED_INFO_LOWER_CASE + MAP,
- false, null) +
- methodSignature(YANG_AUGMENTED_INFO_LOWER_CASE + MAP,
- EMPTY_STRING, null, null,
- getAugmentMapTypeString(), null, INTERFACE_TYPE);
- }
-
- /**
- * Returns implementation of get YANG augment info.
- *
- * @return implementation of get YANG augment info
- */
- static String getYangAugmentInfoMapImpl() {
- return getOverRideString() + methodSignature(
- YANG_AUGMENTED_INFO_LOWER_CASE + MAP, EMPTY_STRING, PUBLIC, null,
- getAugmentMapTypeString(), null, CLASS_TYPE) +
- methodBody(AUGMENTED_MAP_GETTER, null, null,
- EIGHT_SPACE_INDENTATION, null, null, false, null) +
- methodClose(FOUR_SPACE);
- }
-
- /**
- * Returns enum's constructor.
- *
- * @param className enum's class name
- * @return enum's constructor
- */
- static String getEnumsConstructor(String className) {
- StringBuilder builder = new StringBuilder();
- String clsName = getSmallCase(className);
- LinkedHashMap<String, String> map = new LinkedHashMap<>();
- map.put(clsName, INT);
- map.put(SCHEMA_NAME, STRING_DATA_TYPE);
- builder.append(multiAttrMethodSignature(className, EMPTY_STRING,
- EMPTY_STRING, null,
- map, CLASS_TYPE))
- .append(methodBody(SETTER, clsName, EMPTY_STRING,
- EIGHT_SPACE_INDENTATION, EMPTY_STRING,
- EMPTY_STRING, false, null))
- .append(methodBody(SETTER, SCHEMA_NAME, EMPTY_STRING,
- EIGHT_SPACE_INDENTATION, EMPTY_STRING,
- EMPTY_STRING, false, null))
- .append(methodClose(FOUR_SPACE));
-
- return builder.toString();
- }
-
- /**
- * Returns of method for enum class.
- *
- * @param className class name
- * @param type method body type
- * @return of method
- */
- static String getEnumsOfValueMethod(String className,
- YangEnumeration enumeration,
- MethodBodyTypes type) {
- String name = getCapitalCase(className);
- StringBuilder builder = new StringBuilder(getJavaDoc(
- OF_METHOD, name + SPACE + FOR,
- false, null));
- //Switch statement.
- String sw = EIGHT_SPACE_INDENTATION + SWITCH + SPACE + brackets(
- OPEN_CLOSE_BRACKET_WITH_VALUE, VALUE, null) +
- methodSignatureClose(CLASS_TYPE);
- String str;
- switch (type) {
- case ENUM_METHOD_INT_VALUE:
- builder.append(getEnumValueMethodSignature(name, INT))
- .append(sw);
- for (YangEnum yangEnum : enumeration.getEnumSet()) {
- str = getEnumJavaAttribute(yangEnum.getNamedValue())
- .toUpperCase();
- builder.append(getEnumValueMethodCases(
- EMPTY_STRING + yangEnum.getValue(), str, name));
- }
- break;
- case ENUM_METHOD_STRING_VALUE:
- builder.append(getEnumValueMethodSignature(name,
- STRING_DATA_TYPE))
- .append(sw);
- for (YangEnum yangEnum : enumeration.getEnumSet()) {
- str = getEnumJavaAttribute(yangEnum.getNamedValue())
- .toUpperCase();
- builder.append(getEnumValueMethodCases(
- QUOTES + yangEnum.getNamedValue() + QUOTES, str,
- name));
- }
- break;
- default:
- return null;
- }
-
- String method = TWELVE_SPACE_INDENTATION + DEFAULT + SPACE + COLON +
- NEW_LINE;
- builder.append(method)
- .append(getReturnString(NULL, SIXTEEN_SPACE_INDENTATION))
- .append(signatureClose())
- .append(methodClose(EIGHT_SPACE))
- .append(methodClose(FOUR_SPACE));
-
- return builder.toString();
- }
-
- /**
- * Returns enum value method signature.
- *
- * @param name method name
- * @param type param type
- * @return enum value method signature
- */
- private static String getEnumValueMethodSignature(String name, String type) {
- return methodSignature(OF, EMPTY_STRING, PUBLIC + SPACE +
- STATIC, VALUE, name, type, CLASS_TYPE);
- }
-
- /**
- * Returns enum value method's cases.
- *
- * @param caseType case type
- * @param value return value
- * @param name name of class
- * @return enum value method's cases
- */
- private static String getEnumValueMethodCases(String caseType, String value,
- String name) {
- return TWELVE_SPACE_INDENTATION + CASE + SPACE + caseType +
- COLON + NEW_LINE + getReturnString(name,
- SIXTEEN_SPACE_INDENTATION) +
- PERIOD + value + signatureClose();
- }
-
- /**
- * Returns augmented data getter and setter methods for service class.
- *
- * @param parent parent node
- * @return augmented data getter and setter methods for service class
- */
- static String getAugmentsDataMethodForService(YangNode parent) {
- List<YangAtomicPath> targets = getSetOfNodeIdentifiers(parent);
- YangNode augmentedNode;
- String curNodeName;
- String method;
- StringBuilder methods = new StringBuilder();
- String parentName;
- String returnType;
- YangNode methodNode;
- YangPluginConfig pluginConfig =
- ((JavaFileInfoContainer) parent).getJavaFileInfo()
- .getPluginConfig();
- for (YangAtomicPath nodeId : targets) {
- augmentedNode = nodeId.getResolvedNode().getParent();
- methodNode = nodeId.getResolvedNode();
- if (((JavaFileInfoContainer) methodNode).getJavaFileInfo()
- .getJavaName() != null) {
- curNodeName =
- ((JavaFileInfoContainer) methodNode).getJavaFileInfo()
- .getJavaName();
- } else {
- curNodeName = getCapitalCase(
- getCamelCase(methodNode.getName(),
- pluginConfig.getConflictResolver()));
- }
- returnType =
- getAugmentedClassNameForDataMethods(augmentedNode, parent);
- parentName = getCurNodeName(augmentedNode,
- pluginConfig);
- method = generateForGetMethodWithAttribute(returnType) +
- getGetMethodWithArgument(returnType, AUGMENTED +
- parentName + getCapitalCase(curNodeName)) + NEW_LINE;
- methods.append(method);
-
- method = getJavaDoc(MANAGER_SETTER_METHOD,
- AUGMENTED + getCapitalCase(parentName) +
- getCapitalCase(curNodeName), false,
- null) +
- getSetterForInterface(getSmallCase(AUGMENTED) + parentName +
- getCapitalCase(curNodeName),
- returnType, parentName, false,
- GENERATE_SERVICE_AND_MANAGER, null) +
- NEW_LINE;
- methods.append(method);
- }
- return methods.toString();
- }
-
- /**
- * Returns validator method for range in union class.
- *
- * @param type type
- * @return validator method for range in union class
- */
- static String getRangeValidatorMethodForUnion(String type) {
- String newType;
- if (type.contentEquals(BIG_INTEGER)) {
- newType = LONG;
- } else {
- newType = INT;
- }
- StringBuilder builder = new StringBuilder(generateForValidatorMethod());
- String var = getSmallCase(BIG_INTEGER);
- LinkedHashMap<String, String> map = new LinkedHashMap<>();
- map.put(MIN_RANGE, type);
- map.put(MAX_RANGE, type);
- map.put(VALUE, newType);
- builder.append(multiAttrMethodSignature(VALIDATE_RANGE, EMPTY_STRING,
- PRIVATE, BOOLEAN_DATA_TYPE, map,
- CLASS_TYPE));
- if (type.contentEquals(BIG_INTEGER)) {
- //Create new instance of big integer.
- builder.append(getNewInstance(BIG_INTEGER, var, EIGHT_SPACE_INDENTATION,
- QUOTES + SPACE + QUOTES + SPACE +
- ADD + SPACE + VALUE))
- //Add return string.
- .append(getReturnString(var, EIGHT_SPACE_INDENTATION))
- //Add compareTo string
- .append(getCompareToString())
- //Add && condition.
- .append(ifAndAndCondition(
- //Add == condition
- ifEqualEqualCondition(
- brackets(OPEN_CLOSE_BRACKET_WITH_VALUE,
- MIN_RANGE, null), ONE),
- var))
- //Add compareTo string.
- .append(getCompareToString())
- //Add == condition.
- .append(ifEqualEqualCondition(
- brackets(OPEN_CLOSE_BRACKET_WITH_VALUE,
- MAX_RANGE, null), ONE))
- .append(signatureClose());
- } else {
- builder.append(getReturnString(VALUE, EIGHT_SPACE_INDENTATION))
- .append(getGreaterThanCondition())
- .append(ifAndAndCondition(MIN_RANGE, VALUE))
- .append(getLesserThanCondition())
- .append(MAX_RANGE)
- .append(signatureClose());
- }
- builder.append(methodClose(FOUR_SPACE));
- return builder.toString();
- }
-
- //Get method with arguments.
- private static String getGetMethodWithArgument(String returnType,
- String yangName) {
- return methodSignature(getCapitalCase(yangName), GET_METHOD_PREFIX,
- null, getSmallCase(returnType),
- returnType, returnType + OP_PARAM,
- INTERFACE_TYPE);
- }
-
- /**
- * Returns add to list method interface.
- *
- * @param attr java attribute
- * @param className name of the class
- * @return add to list method interface
- */
- public static String getAddToListMethodInterface(JavaAttributeInfo attr,
- String className) {
-
- return methodSignature(ADD_STRING + TO_CAPS + getCapitalCase(
- attr.getAttributeName()), EMPTY_STRING, EMPTY_STRING,
- ADD_STRING + TO_CAPS,
- className + BUILDER, getReturnType(attr),
- INTERFACE_TYPE);
- }
-
- /**
- * Returns add to list method impl.
- *
- * @param attr java attribute
- * @param name class name
- * @param isRoot is root
- * @return add to list method impl
- */
- public static String getAddToListMethodImpl(JavaAttributeInfo attr,
- String name,
- boolean isRoot) {
- String attrName = attr.getAttributeName();
- String retString = EMPTY_STRING;
- if (!isRoot) {
- retString = getOverRideString();
- }
- StringBuilder builder = new StringBuilder(retString);
- builder.append(methodSignature(ADD_STRING + TO_CAPS +
- getCapitalCase(attrName),
- EMPTY_STRING, PUBLIC, ADD_STRING + TO_CAPS,
- name + BUILDER, getReturnType(attr),
- CLASS_TYPE))
- .append(getIfConditionForAddToListMethod(attrName));
- retString = EIGHT_SPACE_INDENTATION + attrName + PERIOD + ADD_STRING +
- OPEN_PARENTHESIS + ADD_STRING + TO_CAPS + CLOSE_PARENTHESIS;
- builder.append(retString)
- .append(signatureClose())
- .append(getReturnString(THIS, EIGHT_SPACE_INDENTATION))
- .append(signatureClose())
- .append(methodClose(FOUR_SPACE));
- return builder.toString();
- }
-
- // Returns if condition for add to list method.
- static String getIfConditionForAddToListMethod(String name) {
- return getIfConditionBegin(EIGHT_SPACE_INDENTATION, name + SPACE + EQUAL +
- EQUAL + SPACE + NULL) + TWELVE_SPACE_INDENTATION +
- name + SPACE + EQUAL + SPACE +
- NEW + SPACE + ARRAY_LIST + signatureClose() + methodClose(
- EIGHT_SPACE);
- }
-
- /**
- * Returns builder method for class.
- *
- * @param name name of class
- * @return builder method for class
- */
- static String builderMethod(String name) {
- return generateForBuilderMethod(name) +
- methodSignature(BUILDER_LOWER_CASE,
- EMPTY_STRING, PUBLIC + SPACE +
- STATIC, null, name + BUILDER, null, CLASS_TYPE) +
- getReturnString(NEW + SPACE + name + BUILDER,
- EIGHT_SPACE_INDENTATION) +
- brackets(OPEN_CLOSE_BRACKET, null, null) + signatureClose() +
- methodClose(FOUR_SPACE);
- }
-
- /**
- * Returns is filter content match interface.
- *
- * @param name name of node
- * @return is filter content match interface
- */
- static String processSubtreeFilteringInterface(String name) {
- String method = " /**\n" +
- " * Checks if the passed " + name +
- " maps the content match query condition.\n" +
- " *\n" +
- " * @param " + getSmallCase(name) + SPACE +
- getSmallCase(name) + SPACE + "being passed to check" +
- " for" +
- " content match\n" +
- " * @param isSelectAllSchemaChild is select all schema child\n" +
- " * @return match result\n" +
- " */\n";
- LinkedHashMap<String, String> map = new LinkedHashMap<>();
- map.put(getSmallCase(name), name);
- map.put(SELECT_ALL_CHILD, BOOLEAN_DATA_TYPE);
-
- return method + multiAttrMethodSignature(PROCESS_SUBTREE_FILTERING,
- EMPTY_STRING, EMPTY_STRING,
- name, map, INTERFACE_TYPE);
- }
-
- /**
- * Returns is value set interface.
- *
- * @return is value set interface
- */
- static String isLeafValueSetInterface() {
- String method = "\n /**\n" +
- " * Checks if the leaf value is set.\n" +
- " *\n" +
- " * @param leaf leaf whose value status needs to checked\n" +
- " * @return result of leaf value set in object\n" +
- " */\n";
- return method + methodSignature(VALUE_LEAF_SET, EMPTY_STRING, null,
- LEAF, BOOLEAN_DATA_TYPE,
- LEAF_IDENTIFIER, INTERFACE_TYPE);
- }
-
- /**
- * Returns is select leaf set interface.
- *
- * @return is select leaf set interface
- */
- static String isSelectLeafSetInterface() {
- String method = "\n /**\n" +
- " * Checks if the leaf is set to be a selected leaf.\n" +
- " *\n" +
- " * @param leaf if leaf needs to be selected\n" +
- " * @return result of leaf value set in object\n" +
- " */\n";
- return method + methodSignature(IS_SELECT_LEAF, EMPTY_STRING, null,
- LEAF, BOOLEAN_DATA_TYPE, LEAF_IDENTIFIER,
- INTERFACE_TYPE);
- }
-
- /**
- * Returns set select leaf set interface.
- *
- * @param name node name
- * @return set select leaf set interface
- */
- static String setSelectLeafSetInterface(String name) {
- String method = " /**\n" +
- " * Set a leaf to be selected.\n" +
- " *\n" +
- " * @param leaf leaf needs to be selected\n" +
- " * @return builder object for select leaf\n" +
- " */\n";
- return method + methodSignature(SET_SELECT_LEAF, EMPTY_STRING,
- null, LEAF, name +
- BUILDER, LEAF_IDENTIFIER,
- INTERFACE_TYPE) + NEW_LINE;
- }
-
- /**
- * Returns leaf identifier interface enum signature.
- *
- * @param name name of node
- * @return leaf identifier interface enum signature
- */
- static String getInterfaceLeafIdEnumSignature(String name) {
- String start = "\n /**\n" +
- " * Identify the leaf of " + name + PERIOD + NEW_LINE +
- " */\n";
- return start + FOUR_SPACE_INDENTATION + PUBLIC + SPACE + ENUM + SPACE +
- LEAF_IDENTIFIER + SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
- }
-
- /**
- * Returns setter for select leaf.
- *
- * @param name name of node
- * @param isRootNode if root node
- * @return setter for select leaf
- */
- static String getSetterForSelectLeaf(String name, boolean isRootNode) {
- String append = OVERRIDE;
- if (isRootNode) {
- append = EMPTY_STRING;
- }
- return "\n" +
- " " + append + "\n" +
- " public " + name + BUILDER +
- " selectLeaf(LeafIdentifier leaf) {\n" +
- " getSelectLeafFlags().set(leaf.getLeafIndex());\n" +
- " return this;\n" +
- " }\n";
- }
-
- /**
- * Generates fromString code for bits.
- *
- * @return generated fromString code for bits.
- */
- private static String getFromStringForBits(String bitClassName) {
- StringBuilder sBuild = new StringBuilder();
- sBuild.append(methodSignature(FROM_STRING_METHOD_NAME, null,
- PUBLIC + SPACE + STATIC,
- FROM_STRING_PARAM_NAME,
- BIT_SET, STRING_DATA_TYPE, CLASS_TYPE))
- .append(EIGHT_SPACE_INDENTATION)
- .append(getBitSetAttr(EMPTY_STRING));
- // Split the input string and check each bit name falls in configured yang file
- sBuild.append(EIGHT_SPACE_INDENTATION).append(STRING_DATA_TYPE)
- .append(SQUARE_BRACKETS).append(SPACE).append(BIT_NAMES_VAR)
- .append(SPACE).append(EQUAL).append(SPACE).append(FROM_STRING_PARAM_NAME)
- .append(PERIOD).append(TRIM_STRING).append(OPEN_CLOSE_BRACKET_STRING)
- .append(PERIOD).append(SPLIT_STRING).append(brackets(
- OPEN_CLOSE_BRACKET_WITH_VALUE, getPatternQuoteString(SPACE),
- null)).append(signatureClose()).append(getForLoopString(
- EIGHT_SPACE_INDENTATION, STRING_DATA_TYPE, BIT_NAME_VAR,
- BIT_NAMES_VAR));
-
- String small = getSmallCase(bitClassName);
- sBuild.append(TWELVE_SPACE_INDENTATION).append(bitClassName).append
- (SPACE).append(small).append(SPACE).append(EQUAL).append
- (SPACE).append(bitClassName).append(PERIOD).append(OF).append
- (brackets(OPEN_CLOSE_BRACKET_WITH_VALUE, BIT_NAME_VAR, null))
- .append(signatureClose());
- String condition = small + SPACE + NOT + EQUAL + SPACE + NULL;
- sBuild.append(getIfConditionBegin(TWELVE_SPACE_INDENTATION, condition))
- .append(TWELVE_SPACE_INDENTATION)
- .append(TMP_VAL).append(PERIOD).append(SET_METHOD_PREFIX)
- .append(OPEN_PARENTHESIS)
- .append(small).append(PERIOD).append(small).append(
- OPEN_CLOSE_BRACKET_STRING).append(CLOSE_PARENTHESIS)
- .append(signatureClose()).append(methodClose(TWELVE_SPACE))
- .append(methodClose(EIGHT_SPACE));
- sBuild.append(getReturnString(TMP_VAL, EIGHT_SPACE_INDENTATION))
- .append(signatureClose()).append(methodClose(FOUR_SPACE));
- return sBuild.toString();
- }
-
- /**
- * Returns union class's to string method.
- *
- * @param types list of types
- * @return union class's to string method
- */
- static String getUnionToStringMethod(List<YangType<?>> types) {
-
- StringBuilder builder = new StringBuilder(getOverRideString());
- builder.append(methodSignature(TO_STRING_METHOD, null, PUBLIC, null,
- STRING_DATA_TYPE, null, CLASS_TYPE))
- .append(getMoreObjectAttr());
- for (YangType type : types) {
- builder.append(getIfConditionBegin(
- EIGHT_SPACE_INDENTATION, getSetValueParaCondition(
- types.indexOf(type))))
- .append(TWELVE_SPACE_INDENTATION).append(HELPER).append(
- methodBody(TO_STRING, getCamelCase(type.getDataTypeName()
- , null), null, EMPTY_STRING, null, null, false, null))
- .append(signatureClose()).append(methodClose(EIGHT_SPACE));
- }
- builder.append(getReturnString(HELPER, EIGHT_SPACE_INDENTATION))
- .append(PERIOD).append(TO_STRING_METHOD)
- .append(OPEN_CLOSE_BRACKET_STRING).append(signatureClose())
- .append(methodClose(FOUR_SPACE));
- return builder.toString();
- }
-
- /**
- * Returns from string method for bits class.
- *
- * @param className bits class name
- * @return from string method for bits class
- */
- static String getBitSetEnumClassFromString(String className) {
- return getJavaDoc(FROM_METHOD, className, false, null) +
- getFromStringForBits(className);
- }
-
- static String getBitSetEnumClassToString(String className,
- YangEnumeration enumeration) {
-
- StringBuilder builder = new StringBuilder();
- builder.append(methodSignature(TO_STRING_METHOD, null, PUBLIC, BITS,
- STRING_DATA_TYPE, BIT_SET, CLASS_TYPE))
- .append(getMoreObjectAttr());
- String condition;
- String name;
- for (YangEnum yangEnum : enumeration.getEnumSet()) {
- name = yangEnum.getNamedValue();
- condition = BITS + PERIOD + GET + OPEN_PARENTHESIS +
- className + PERIOD + getEnumJavaAttribute(name).toUpperCase()
- + PERIOD + getSmallCase(className)
- + OPEN_CLOSE_BRACKET_STRING + CLOSE_PARENTHESIS;
-
-
- builder.append(getIfConditionBegin(
- EIGHT_SPACE_INDENTATION, condition))
- .append(TWELVE_SPACE_INDENTATION).append(HELPER).append(
- PERIOD).append(ADD_STRING).append(OPEN_PARENTHESIS)
- .append(getQuotedString(name)).append(COMMA).append(SPACE)
- .append(getQuotedString(name)).append(CLOSE_PARENTHESIS)
- .append(signatureClose()).append(methodClose(EIGHT_SPACE));
- }
- builder.append(getReturnString(HELPER, EIGHT_SPACE_INDENTATION))
- .append(PERIOD).append(TO_STRING_METHOD)
- .append(OPEN_CLOSE_BRACKET_STRING).append(signatureClose())
- .append(methodClose(FOUR_SPACE));
- return builder.toString();
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/StringGenerator.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/StringGenerator.java
deleted file mode 100644
index c0d05b0..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/StringGenerator.java
+++ /dev/null
@@ -1,1193 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.translator.tojava.utils;
-
-import org.onosproject.yangutils.datamodel.YangCompilerAnnotation;
-import org.onosproject.yangutils.datamodel.YangType;
-import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes;
-import org.onosproject.yangutils.translator.exception.TranslatorException;
-
-import java.util.Map;
-
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.BOOLEAN;
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.DECIMAL64;
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.EMPTY;
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT16;
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT32;
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT64;
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.INT8;
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.UINT16;
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.UINT32;
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.UINT64;
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.UINT8;
-import static org.onosproject.yangutils.translator.tojava.utils.BracketType.OPEN_CLOSE_BRACKET;
-import static org.onosproject.yangutils.translator.tojava.utils.BracketType.OPEN_CLOSE_BRACKET_WITH_VALUE;
-import static org.onosproject.yangutils.translator.tojava.utils.BracketType.OPEN_CLOSE_BRACKET_WITH_VALUE_AND_RETURN_TYPE;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodClassTypes.CLASS_TYPE;
-import static org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator.getIfConditionForAddToListMethod;
-import static org.onosproject.yangutils.utils.UtilConstants.ADD_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.AND;
-import static org.onosproject.yangutils.utils.UtilConstants.APPEND;
-import static org.onosproject.yangutils.utils.UtilConstants.AT;
-import static org.onosproject.yangutils.utils.UtilConstants.BIG_DECIMAL;
-import static org.onosproject.yangutils.utils.UtilConstants.BIG_INTEGER;
-import static org.onosproject.yangutils.utils.UtilConstants.BITSET;
-import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_DATA_TYPE;
-import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_WRAPPER;
-import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
-import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_LOWER_CASE;
-import static org.onosproject.yangutils.utils.UtilConstants.BYTE;
-import static org.onosproject.yangutils.utils.UtilConstants.BYTE_WRAPPER;
-import static org.onosproject.yangutils.utils.UtilConstants.CATCH;
-import static org.onosproject.yangutils.utils.UtilConstants.CHECK_NOT_NULL_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.CLASS;
-import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET;
-import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS;
-import static org.onosproject.yangutils.utils.UtilConstants.COLON;
-import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
-import static org.onosproject.yangutils.utils.UtilConstants.COMPARE_TO;
-import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT_CAPS;
-import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_CLOSE_BRACKET;
-import static org.onosproject.yangutils.utils.UtilConstants.DIAMOND_OPEN_BRACKET;
-import static org.onosproject.yangutils.utils.UtilConstants.DOUBLE;
-import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION;
-import static org.onosproject.yangutils.utils.UtilConstants.ELSE;
-import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.EQUAL;
-import static org.onosproject.yangutils.utils.UtilConstants.EXCEPTION;
-import static org.onosproject.yangutils.utils.UtilConstants.EXCEPTION_VAR;
-import static org.onosproject.yangutils.utils.UtilConstants.EXTEND;
-import static org.onosproject.yangutils.utils.UtilConstants.FALSE;
-import static org.onosproject.yangutils.utils.UtilConstants.FOR;
-import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
-import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_METHOD_NAME;
-import static org.onosproject.yangutils.utils.UtilConstants.GET;
-import static org.onosproject.yangutils.utils.UtilConstants.GOOGLE_MORE_OBJECT_METHOD_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.IF;
-import static org.onosproject.yangutils.utils.UtilConstants.IMPLEMENTS;
-import static org.onosproject.yangutils.utils.UtilConstants.IMPORT;
-import static org.onosproject.yangutils.utils.UtilConstants.IN;
-import static org.onosproject.yangutils.utils.UtilConstants.INT;
-import static org.onosproject.yangutils.utils.UtilConstants.INTEGER_WRAPPER;
-import static org.onosproject.yangutils.utils.UtilConstants.INT_MAX_RANGE;
-import static org.onosproject.yangutils.utils.UtilConstants.INT_MIN_RANGE;
-import static org.onosproject.yangutils.utils.UtilConstants.LIST;
-import static org.onosproject.yangutils.utils.UtilConstants.LONG;
-import static org.onosproject.yangutils.utils.UtilConstants.LONG_MAX_RANGE;
-import static org.onosproject.yangutils.utils.UtilConstants.LONG_MIN_RANGE;
-import static org.onosproject.yangutils.utils.UtilConstants.LONG_WRAPPER;
-import static org.onosproject.yangutils.utils.UtilConstants.MAP;
-import static org.onosproject.yangutils.utils.UtilConstants.MORE_OBJ_ATTR;
-import static org.onosproject.yangutils.utils.UtilConstants.NEW;
-import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
-import static org.onosproject.yangutils.utils.UtilConstants.OBJECT;
-import static org.onosproject.yangutils.utils.UtilConstants.OBJECT_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.OF;
-import static org.onosproject.yangutils.utils.UtilConstants.OMIT_NULL_VALUE_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CLOSE_BRACKET_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET;
-import static org.onosproject.yangutils.utils.UtilConstants.OPEN_PARENTHESIS;
-import static org.onosproject.yangutils.utils.UtilConstants.OVERRIDE;
-import static org.onosproject.yangutils.utils.UtilConstants.PARSE_BOOLEAN;
-import static org.onosproject.yangutils.utils.UtilConstants.PARSE_BYTE;
-import static org.onosproject.yangutils.utils.UtilConstants.PARSE_INT;
-import static org.onosproject.yangutils.utils.UtilConstants.PARSE_LONG;
-import static org.onosproject.yangutils.utils.UtilConstants.PARSE_SHORT;
-import static org.onosproject.yangutils.utils.UtilConstants.PATTERN;
-import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
-import static org.onosproject.yangutils.utils.UtilConstants.PUT;
-import static org.onosproject.yangutils.utils.UtilConstants.QUEUE;
-import static org.onosproject.yangutils.utils.UtilConstants.QUOTES;
-import static org.onosproject.yangutils.utils.UtilConstants.QUOTE_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.RETURN;
-import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLON;
-import static org.onosproject.yangutils.utils.UtilConstants.SET;
-import static org.onosproject.yangutils.utils.UtilConstants.SET_VALUE_PARA;
-import static org.onosproject.yangutils.utils.UtilConstants.SHORT;
-import static org.onosproject.yangutils.utils.UtilConstants.SHORT_MAX_RANGE;
-import static org.onosproject.yangutils.utils.UtilConstants.SHORT_MIN_RANGE;
-import static org.onosproject.yangutils.utils.UtilConstants.SHORT_WRAPPER;
-import static org.onosproject.yangutils.utils.UtilConstants.SIXTEEN_SPACE_INDENTATION;
-import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
-import static org.onosproject.yangutils.utils.UtilConstants.STRING_BUILDER;
-import static org.onosproject.yangutils.utils.UtilConstants.STRING_BUILDER_VAR;
-import static org.onosproject.yangutils.utils.UtilConstants.THIS;
-import static org.onosproject.yangutils.utils.UtilConstants.TMP_VAL;
-import static org.onosproject.yangutils.utils.UtilConstants.TRY;
-import static org.onosproject.yangutils.utils.UtilConstants.TWELVE_SPACE_INDENTATION;
-import static org.onosproject.yangutils.utils.UtilConstants.TWENTY_SPACE_INDENTATION;
-import static org.onosproject.yangutils.utils.UtilConstants.UINT8_MAX_RANGE;
-import static org.onosproject.yangutils.utils.UtilConstants.UINT8_MIN_RANGE;
-import static org.onosproject.yangutils.utils.UtilConstants.UINT_MAX_RANGE;
-import static org.onosproject.yangutils.utils.UtilConstants.UINT_MIN_RANGE;
-import static org.onosproject.yangutils.utils.UtilConstants.ULONG_MAX_RANGE;
-import static org.onosproject.yangutils.utils.UtilConstants.ULONG_MIN_RANGE;
-import static org.onosproject.yangutils.utils.UtilConstants.VALIDATE_RANGE;
-import static org.onosproject.yangutils.utils.UtilConstants.VALUE;
-import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO_LOWER_CASE;
-import static org.onosproject.yangutils.utils.UtilConstants.YANG_UTILS_TODO;
-import static org.onosproject.yangutils.utils.UtilConstants.ZERO;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.trimAtLast;
-
-/**
- * Represents string generator for translator.
- */
-public final class StringGenerator {
-
- private StringGenerator() {
- }
-
- /**
- * Returns compare to string.
- *
- * @return compare to string
- */
- static String getCompareToString() {
- return PERIOD + COMPARE_TO;
- }
-
- /**
- * Returns lesser than and equals condition.
- *
- * @return lesser than and equals condition
- */
- static String getLesserThanCondition() {
- return SPACE + DIAMOND_OPEN_BRACKET + EQUAL + SPACE;
- }
-
- /**
- * Returns greater than and equals condition.
- *
- * @return greater than and equals condition
- */
- static String getGreaterThanCondition() {
- return SPACE + DIAMOND_CLOSE_BRACKET + EQUAL + SPACE;
- }
-
- /**
- * Returns && conditional string.
- *
- * @param cond1 condition one
- * @param cond2 condition two
- * @return && conditional string
- */
- static String ifAndAndCondition(String cond1, String cond2) {
- return cond1 + SPACE + AND + AND + SPACE + cond2;
- }
-
- /**
- * Returns equal equal conditional string.
- *
- * @param cond1 condition one
- * @param cond2 condition two
- * @return equal equal conditional string
- */
- static String ifEqualEqualCondition(String cond1, String cond2) {
- return cond1 + SPACE + EQUAL + EQUAL + SPACE + cond2;
- }
-
- /**
- * Returns new instance string.
- *
- * @param returnType return type
- * @param varName variable name
- * @param space spaces
- * @param value value
- * @return new instance string
- */
- static String getNewInstance(String returnType, String varName,
- String space, String value) {
- return space + returnType + SPACE + varName + SPACE + EQUAL + SPACE +
- NEW + SPACE + returnType + brackets(
- OPEN_CLOSE_BRACKET_WITH_VALUE, value, null) + signatureClose();
- }
-
- /**
- * Returns return string.
- *
- * @param value value to be returned
- * @param space spaces
- * @return return string
- */
- static String getReturnString(String value, String space) {
- return space + RETURN + SPACE + value;
- }
-
- /**
- * Returns new line string with spaces.
- *
- * @param space spaces
- * @return new line string with spaces
- */
- static String getNewLineAndSpace(String space) {
- return NEW_LINE + space;
- }
-
- /**
- * Returns method close string.
- *
- * @param type indentation type
- * @return method close string
- */
- static String methodClose(IndentationType type) {
- switch (type) {
- case EIGHT_SPACE:
- return EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET +
- NEW_LINE;
- case TWELVE_SPACE:
- return TWELVE_SPACE_INDENTATION + CLOSE_CURLY_BRACKET +
- NEW_LINE;
- case SIXTEEN_SPACE:
- return SIXTEEN_SPACE_INDENTATION + CLOSE_CURLY_BRACKET +
- NEW_LINE;
- case TWENTY_SPACE:
- return TWENTY_SPACE_INDENTATION + CLOSE_CURLY_BRACKET +
- NEW_LINE;
- case TWENTY_EIGHT_SPACE:
- return FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET +
- NEW_LINE;
- case TWENTY_FOUR_SPACE:
- return FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET +
- NEW_LINE;
- default:
- return FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET +
- NEW_LINE;
- }
- }
-
- /**
- * Returns body of the method.
- *
- * @param type type of method body
- * @param paraName parameter name
- * @param methodName method name
- * @param space space to be given before body
- * @param prefix prefix for internal method
- * @param paramType parameter type
- * @param isBuilderSetter is for builder setter
- * @param setterVal value to set in setter
- * @return body of the method
- */
- static String methodBody(MethodBodyTypes type, String paraName,
- String methodName,
- String space, String prefix,
- String paramType, boolean isBuilderSetter, String setterVal) {
- StringBuilder builder = new StringBuilder();
- String body;
- switch (type) {
- case GETTER:
- return getReturnString(paraName, space);
- case SETTER:
- if (setterVal == null) {
- setterVal = paraName;
- }
- body = space + THIS + PERIOD + paraName + SPACE + EQUAL + SPACE +
- setterVal + signatureClose();
- builder.append(body);
- if (isBuilderSetter) {
- body = getReturnString(THIS + signatureClose(), space);
- builder.append(body);
- }
- return builder.toString();
- case BUILD:
- return getReturnString(
- NEW + SPACE + paraName + brackets(
- OPEN_CLOSE_BRACKET_WITH_VALUE, THIS, null) +
- signatureClose(), space);
- case CONSTRUCTOR:
- return space + THIS + PERIOD + paraName + SPACE +
- EQUAL + SPACE + BUILDER_LOWER_CASE + OBJECT + PERIOD +
- prefix + methodName +
- brackets(OPEN_CLOSE_BRACKET, null, null) +
- signatureClose();
- case DEFAULT_CONSTRUCTOR:
- return EMPTY_STRING;
- case ADD_TO_LIST:
- return space + getIfConditionForAddToListMethod(paraName) +
- space + paraName +
- brackets(OPEN_CLOSE_BRACKET, null, null) + PERIOD +
- ADD_STRING +
- brackets(OPEN_CLOSE_BRACKET_WITH_VALUE, VALUE, null) +
- signatureClose() + getReturnString(
- THIS + signatureClose(), space);
- case AUGMENTED_MAP_ADD:
- return space + YANG_AUGMENTED_INFO_LOWER_CASE + MAP +
- PERIOD + PUT + OPEN_PARENTHESIS + CLASS +
- OBJECT_STRING + COMMA + SPACE + VALUE +
- CLOSE_PARENTHESIS + signatureClose();
- case AUGMENTED_MAP_GET_VALUE:
- return getReturnString(
- YANG_AUGMENTED_INFO_LOWER_CASE + MAP + PERIOD + GET +
- brackets(OPEN_CLOSE_BRACKET_WITH_VALUE, CLASS +
- OBJECT_STRING, null) + signatureClose(),
- space);
- case AUGMENTED_MAP_GETTER:
- return getReturnString(YANG_AUGMENTED_INFO_LOWER_CASE + MAP +
- signatureClose(), space);
- case MANAGER_METHODS:
- body = space + YANG_UTILS_TODO + NEW_LINE;
- builder.append(body);
- if (paramType != null) {
- body = getReturnString(parseTypeForReturnValue(paramType),
- space);
- builder.append(body)
- .append(signatureClose());
- }
- return builder.toString();
- case OF_METHOD:
- return getReturnString(
- NEW + SPACE + paraName + brackets(
- OPEN_CLOSE_BRACKET_WITH_VALUE, VALUE, null)
- + signatureClose(), space);
- case TO_STRING:
- return getToStringMethodsAddString(space, paraName) + paraName +
- CLOSE_PARENTHESIS;
- case EQUALS_METHOD:
- default:
- return null;
- }
- }
-
- /**
- * Returns to string method's add string.
- *
- * @param space indentation
- * @param paraName parameter name
- * @return to string method's add string
- */
- static String getToStringMethodsAddString(String space, String paraName) {
- return space + PERIOD + ADD_STRING + OPEN_PARENTHESIS +
- getQuotedString(paraName) + COMMA + SPACE;
- }
-
- /**
- * Returns end of line.
- *
- * @return end of line
- */
- static String signatureClose() {
- return SEMI_COLON + NEW_LINE;
- }
-
- /**
- * Returns method signature close for method class type.
- *
- * @param type method class type
- * @return method signature close for method class type
- */
- static String methodSignatureClose(MethodClassTypes type) {
- switch (type) {
- case INTERFACE_TYPE:
- return signatureClose();
- case CLASS_TYPE:
- return SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
- default:
- return null;
- }
- }
-
- /**
- * Returns method param.
- *
- * @param type type of param
- * @param name name of param
- * @return method param
- */
- private static String methodParam(String type, String name) {
- return type + SPACE + name;
- }
-
- /**
- * Returns comma followed by a space.
- *
- * @return comma followed by a space
- */
- private static String commaWithSpace() {
- return COMMA + SPACE;
- }
-
- /**
- * Returns bracket string for the given type.
- *
- * @param type bracket type
- * @param value value to be added in brackets
- * @param returnType returns type to be added for value
- * @return bracket for the given type.
- */
- static String brackets(BracketType type, String value,
- String returnType) {
- String ret = EMPTY_STRING;
- switch (type) {
- case OPEN_CLOSE_BRACKET:
- return OPEN_PARENTHESIS + CLOSE_PARENTHESIS;
- case OPEN_CLOSE_BRACKET_WITH_VALUE:
- return OPEN_PARENTHESIS + value + CLOSE_PARENTHESIS;
- case OPEN_CLOSE_BRACKET_WITH_VALUE_AND_RETURN_TYPE:
- if (returnType != null) {
- ret = returnType + SPACE;
- }
- return OPEN_PARENTHESIS + ret + value +
- CLOSE_PARENTHESIS;
- case OPEN_BRACKET_WITH_VALUE:
- ret = EMPTY_STRING;
- if (returnType != null) {
- ret = returnType + SPACE;
- }
- return OPEN_PARENTHESIS + ret + value +
- COMMA;
- case CLOSE_BRACKET_WITH_VALUE:
- ret = EMPTY_STRING;
- if (returnType != null) {
- ret = returnType + SPACE;
- }
- return SPACE + ret + value +
- CLOSE_PARENTHESIS;
- case OPEN_CLOSE_DIAMOND:
- return DIAMOND_OPEN_BRACKET + DIAMOND_CLOSE_BRACKET;
- case OPEN_CLOSE_DIAMOND_WITH_VALUE:
- return DIAMOND_OPEN_BRACKET + value + DIAMOND_CLOSE_BRACKET;
- default:
- return null;
- }
- }
-
- /**
- * Returns method signature for multi attribute methods.
- *
- * @param methodName method name
- * @param prefix prefix for method
- * @param modifier modifier for method
- * @param methodReturnType method's return type
- * @param params parameters
- * @param type type of method
- * @return method signature for multi attribute methods
- */
- static String multiAttrMethodSignature(String methodName, String
- prefix, String modifier, String methodReturnType,
- Map<String, String> params,
- MethodClassTypes type) {
- StringBuilder methodBuilder = new StringBuilder(FOUR_SPACE_INDENTATION);
- String method = EMPTY_STRING;
- if (modifier != null) {
- method = modifier + SPACE;
- }
- methodBuilder.append(method);
- if (prefix == null) {
- prefix = EMPTY_STRING;
- }
- if (methodReturnType != null) {
- method = methodReturnType + SPACE + prefix + methodName;
- } else {
- method = prefix + methodName;
- }
- //Append method beginning.
- methodBuilder.append(method)
- .append(OPEN_PARENTHESIS);
- for (Map.Entry<String, String> param : params.entrySet()) {
- methodBuilder.append(methodParam(param.getValue(), param.getKey()));
- methodBuilder.append(commaWithSpace());
- }
- String para = methodBuilder.toString();
- String[] array = {SPACE, COMMA};
- para = trimAtLast(para, array);
- methodBuilder = new StringBuilder(para)
- .append(CLOSE_PARENTHESIS)
- .append(methodSignatureClose(type));
-
- return methodBuilder.toString();
- }
-
- /**
- * Returns method signature for interface and implementation classes.
- *
- * @param methodName name of the method
- * @param prefix prefix which needs to be added for method
- * @param modifier modifier which needs to be added for method
- * @param paraVal value which needs to be added as parameter
- * @param methodReturnType returns type to be added for method
- * @param paraReturnType return type to be added for parameter
- * @param type method class type
- * @return method signature for interface and implementation classes
- */
- static String methodSignature(
- String methodName, String prefix, String modifier, String paraVal,
- String methodReturnType, String paraReturnType,
- MethodClassTypes type) {
- StringBuilder methodBuilder = new StringBuilder(FOUR_SPACE_INDENTATION);
- String method = EMPTY_STRING;
- if (modifier != null) {
- method = modifier + SPACE;
- }
- if (prefix == null) {
- prefix = EMPTY_STRING;
- }
- methodBuilder.append(method);
- if (methodReturnType != null) {
- method = methodReturnType + SPACE + prefix + methodName;
- } else {
- method = prefix + methodName;
- }
- //Append method beginning.
- methodBuilder.append(method);
-
- if (paraVal != null) {
- methodBuilder.append(brackets(
- OPEN_CLOSE_BRACKET_WITH_VALUE_AND_RETURN_TYPE,
- paraVal, paraReturnType));
- } else {
- methodBuilder.append(brackets(OPEN_CLOSE_BRACKET, null,
- null));
- }
-
- methodBuilder.append(methodSignatureClose(type));
-
- return methodBuilder.toString();
- }
-
- /**
- * Returns list attribute.
- *
- * @param attrType attribute type
- * @param compilerAnnotation compiler annotations
- * @return list attribute
- */
-
- static String getListAttribute(String attrType,
- YangCompilerAnnotation compilerAnnotation) {
- String listAttr;
- if (compilerAnnotation != null &&
- compilerAnnotation.getYangAppDataStructure() != null) {
- switch (compilerAnnotation.getYangAppDataStructure()
- .getDataStructure()) {
- case QUEUE: {
- listAttr = QUEUE + DIAMOND_OPEN_BRACKET + attrType +
- DIAMOND_CLOSE_BRACKET;
- break;
- }
- case SET: {
- listAttr = SET + DIAMOND_OPEN_BRACKET + attrType +
- DIAMOND_CLOSE_BRACKET;
- break;
- }
- case LIST: {
- listAttr = getListString() + attrType +
- DIAMOND_CLOSE_BRACKET;
- break;
- }
- default: {
- listAttr = getListString() + attrType +
- DIAMOND_CLOSE_BRACKET;
- }
- }
- } else {
- listAttr = getListString() + attrType + DIAMOND_CLOSE_BRACKET;
- }
- return listAttr;
- }
-
- /**
- * Returns getters for value and select leaf.
- *
- * @return getters for value and select leaf
- */
- static String getGettersForValueAndSelectLeaf() {
- return "\n" +
- " @Override\n" +
- " public boolean isLeafValueSet(LeafIdentifier leaf) {\n" +
- " return getValueLeafFlags().get(leaf.getLeafIndex());\n" +
- " }\n" +
- "\n" +
- " @Override\n" +
- " public boolean isSelectLeaf(LeafIdentifier leaf) {\n" +
- " return getSelectLeafFlags().get(leaf.getLeafIndex());\n" +
- " }\n";
- }
-
- /**
- * Returns getter methods for operation attributes.
- *
- * @return getter methods for operation attributes
- */
- static String getOperationAttributesGetters() {
- return "\n" +
- " /**\n" +
- " * Returns the valueLeafFlags.\n" +
- " *\n" +
- " * @return value of valueLeafFlags\n" +
- " */\n" +
- " public BitSet getValueLeafFlags() {\n" +
- " return valueLeafFlags;\n" +
- " }\n" +
- "\n" +
- " /**\n" +
- " * Returns the selectLeafFlags.\n" +
- " *\n" +
- " * @return value of selectLeafFlags\n" +
- " */\n" +
- " public BitSet getSelectLeafFlags() {\n" +
- " return selectLeafFlags;\n" +
- " }\n" +
- "\n";
- }
-
- /**
- * Returns interface leaf identifier enum method.
- *
- * @return interface leaf identifier enum method
- */
- static String getInterfaceLeafIdEnumMethods() {
- return "\n\n private int leafIndex;\n" +
- "\n" +
- " public int getLeafIndex() {\n" +
- " return leafIndex;\n" +
- " }\n" +
- "\n" +
- " LeafIdentifier(int value) {\n" +
- " this.leafIndex = value;\n" +
- " }\n" +
- " }\n";
- }
-
- /**
- * Returns if condition string for typedef constructor.
- *
- * @param type type of conflict
- * @param addFirst true int/long need to be added first
- * @param val value to set
- * @return if condition string for typedef constructor
- */
- static String ifConditionForIntInTypeDefConstructor(ValidatorTypeForUnionTypes type,
- boolean addFirst, String val) {
- String condition =
- EIGHT_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS +
- VALIDATE_RANGE + OPEN_PARENTHESIS;
-
- switch (type) {
- case INT_TYPE_CONFLICT:
- if (addFirst) {
- condition = condition + INT_MIN_RANGE + COMMA + SPACE +
- INT_MAX_RANGE + COMMA + SPACE + val;
- } else {
- condition = condition + UINT_MIN_RANGE + COMMA + SPACE +
- UINT_MAX_RANGE + COMMA + SPACE + val;
- }
- break;
- case LONG_TYPE_CONFLICT:
- if (addFirst) {
- condition = condition + LONG_MIN_RANGE + COMMA + SPACE +
- LONG_MAX_RANGE + COMMA + SPACE + val;
- } else {
- condition = condition + ULONG_MIN_RANGE + COMMA + SPACE +
- ULONG_MAX_RANGE + COMMA + SPACE + val;
- }
- break;
- case SHORT_TYPE_CONFLICT:
- if (addFirst) {
- condition = condition + SHORT_MIN_RANGE + COMMA + SPACE +
- SHORT_MAX_RANGE + COMMA + SPACE + val;
- } else {
- condition = condition + UINT8_MIN_RANGE + COMMA + SPACE +
- UINT8_MAX_RANGE + COMMA + SPACE + val;
- }
- break;
- default:
- return null;
- }
-
- return condition + CLOSE_PARENTHESIS + CLOSE_PARENTHESIS + SPACE +
- OPEN_CURLY_BRACKET + NEW_LINE;
- }
-
- /**
- * Returns from string method parsed string.
- *
- * @param targetDataType target data type
- * @param yangType YANG type
- * @return parsed string
- */
- static String getParseFromStringMethod(String targetDataType,
- YangType<?> yangType) {
- YangDataTypes type = yangType.getDataType();
-
- switch (type) {
- case INT8:
- return BYTE_WRAPPER + PERIOD + PARSE_BYTE;
- case INT16:
- return SHORT_WRAPPER + PERIOD + PARSE_SHORT;
- case INT32:
- return INTEGER_WRAPPER + PERIOD + PARSE_INT;
- case INT64:
- return LONG_WRAPPER + PERIOD + PARSE_LONG;
- case UINT8:
- return SHORT_WRAPPER + PERIOD + PARSE_SHORT;
- case UINT16:
- return INTEGER_WRAPPER + PERIOD + PARSE_INT;
- case UINT32:
- return LONG_WRAPPER + PERIOD + PARSE_LONG;
- case UINT64:
- return NEW + SPACE + BIG_INTEGER;
- case DECIMAL64:
- return NEW + SPACE + BIG_DECIMAL;
- case STRING:
- case IDENTITYREF:
- return EMPTY_STRING;
- case EMPTY:
- case BOOLEAN:
- return BOOLEAN_WRAPPER + PERIOD + PARSE_BOOLEAN;
- case ENUMERATION:
- return targetDataType + PERIOD + OF;
- case DERIVED:
- case UNION:
- return targetDataType + PERIOD + FROM_STRING_METHOD_NAME;
- default:
- throw new TranslatorException("given data type is not " +
- "supported. " +
- yangType.getDataTypeName() +
- " in " +
- yangType.getLineNumber() +
- " at " +
- yangType.getCharPosition() +
- " in " +
- yangType.getFileName());
- }
- }
-
- /**
- * Returns sub string with catch statement for union's from string method.
- *
- * @return sub string with catch statement for union's from string method
- */
- static String getCatchSubString() {
- return CLOSE_CURLY_BRACKET + SPACE + CATCH + SPACE +
- brackets(OPEN_CLOSE_BRACKET_WITH_VALUE_AND_RETURN_TYPE, EXCEPTION_VAR,
- EXCEPTION) + SPACE + OPEN_CURLY_BRACKET;
- }
-
- /**
- * Returns sub string with return statement for union's from string method.
- *
- * @return sub string with return statement for union's from string method
- */
- static String getReturnOfSubString() {
- return getReturnString(OF, TWELVE_SPACE_INDENTATION) +
- brackets(OPEN_CLOSE_BRACKET_WITH_VALUE, TMP_VAL, null) +
- signatureClose();
- }
-
- /**
- * Returns sub string with try statement for union's from string method.
- *
- * @return sub string with try statement for union's from string method
- */
- static String getTrySubString() {
- return TRY + SPACE + OPEN_CURLY_BRACKET;
- }
-
- /*
- * Returns omit null value string.
- *
- * @return omit null value string
- */
- static String getOmitNullValueString() {
- return TWELVE_SPACE_INDENTATION + PERIOD + OMIT_NULL_VALUE_STRING +
- NEW_LINE;
- }
-
- /**
- * Returns collection's iterator method.
- *
- * @param indentation indentation
- * @param loopVar loop variable
- * @param collection collection
- * @return collection's iterator method
- */
- static String getCollectionIteratorForLoopBegin(String indentation,
- String loopVar,
- String collection) {
- return indentation + FOR + SPACE + OPEN_PARENTHESIS + loopVar + SPACE +
- COLON + SPACE + collection + CLOSE_PARENTHESIS + SPACE +
- OPEN_CURLY_BRACKET + NEW_LINE;
- }
-
- /**
- * Returns if else condition's signature.
- *
- * @param indentation indentation
- * @param condition conditions
- * @return if else condition's signature
- */
- static String getElseIfConditionBegin(String indentation,
- String condition) {
- return indentation + CLOSE_CURLY_BRACKET + SPACE + ELSE + SPACE +
- getIfConditionBegin(EMPTY_STRING, condition);
- }
-
- /**
- * Returns if condition's signature.
- *
- * @param indentation indentation
- * @param condition conditions
- * @return if condition's signature
- */
- static String getIfConditionBegin(String indentation, String condition) {
- return indentation + IF + SPACE + brackets(
- OPEN_CLOSE_BRACKET_WITH_VALUE, condition, EMPTY_STRING) +
- methodSignatureClose(CLASS_TYPE);
- }
-
- /**
- * Returns whether the data type is of primitive data type.
- *
- * @param dataType data type to be checked
- * @return true, if data type can have primitive data type, false otherwise
- */
- static boolean isPrimitiveDataType(YangDataTypes dataType) {
- return dataType == INT8 ||
- dataType == INT16 ||
- dataType == INT32 ||
- dataType == INT64 ||
- dataType == UINT8 ||
- dataType == UINT16 ||
- dataType == UINT32 ||
- dataType == UINT64 ||
- dataType == DECIMAL64 ||
- dataType == BOOLEAN ||
- dataType == EMPTY;
- }
-
- /**
- * Returns list string.
- *
- * @return list string
- */
- private static String getListString() {
- return LIST + DIAMOND_OPEN_BRACKET;
- }
-
- /**
- * Returns override string.
- *
- * @return override string
- */
- public static String getOverRideString() {
- return NEW_LINE + FOUR_SPACE_INDENTATION + OVERRIDE + NEW_LINE;
- }
-
- /**
- * Returns value leaf flag setter.
- *
- * @param name name of leaf
- * @return value leaf flag setter
- */
- static String getValueLeafSetString(String name) {
- return "\n valueLeafFlags.set(LeafIdentifier." +
- name.toUpperCase() + ".getLeafIndex());\n";
- }
-
- /*Provides string to return for type.*/
- private static String parseTypeForReturnValue(String type) {
- switch (type) {
- case BYTE:
- case INT:
- case SHORT:
- case LONG:
- case DOUBLE:
- return ZERO;
- case BOOLEAN_DATA_TYPE:
- return FALSE;
- default:
- return null;
- }
- }
-
- /**
- * Returns check not null string.
- *
- * @param name attribute name
- * @return check not null string
- */
- static String getCheckNotNull(String name) {
- return EIGHT_SPACE_INDENTATION + CHECK_NOT_NULL_STRING +
- OPEN_PARENTHESIS + name + COMMA + SPACE + name +
- CLOSE_PARENTHESIS + SEMI_COLON + NEW_LINE;
- }
-
- /**
- * Returns definition close string.
- *
- * @return definition close string
- */
- private static String defCloseString() {
- return SPACE + OPEN_CURLY_BRACKET + NEW_LINE + NEW_LINE;
- }
-
- /**
- * Returns default class definition for java file when extends a
- * interface.
- *
- * @param classType class type
- * @param name name of class
- * @param modifier modifier for class
- * @param extend extends class name
- * @return class definition
- */
- static String getDefaultDefinitionWithExtends(String classType,
- String name, String
- modifier,
- String extend) {
- String mod = EMPTY_STRING;
- if (modifier != null) {
- mod = modifier + SPACE;
- }
- return mod + classType + SPACE + name + SPACE + EXTEND + SPACE
- + extend + defCloseString();
- }
-
- /**
- * Returns default class definition for java file when implements a
- * interface.
- *
- * @param classType class type
- * @param name name of class
- * @param modifier modifier for class
- * @param impl implements class name
- * @return class definition
- */
- static String getDefaultDefinitionWithImpl(String classType,
- String name, String
- modifier,
- String impl) {
- String mod = EMPTY_STRING;
- if (modifier != null) {
- mod = modifier + SPACE;
- }
- return mod + classType + SPACE + name + SPACE + IMPLEMENTS +
- SPACE + impl + defCloseString();
- }
-
- /**
- * Returns default class definition for java file.
- *
- * @param classType class type
- * @param name name of class
- * @param modifier modifier for class
- * @return class definition
- */
- static String getDefaultDefinition(String classType,
- String name, String modifier) {
- String mod = EMPTY_STRING;
- if (modifier != null) {
- mod = modifier + SPACE;
- }
- return mod + classType + SPACE + name + defCloseString();
- }
-
- /**
- * Returns string for service class.
- *
- * @param name1 name of even listener class
- * @param name2 name of even class
- * @return listener service string for service class
- */
- static String getEventExtendsString(String name1, String type,
- String name2) {
- StringBuilder builder = new StringBuilder();
- builder.append(type).append(DIAMOND_OPEN_BRACKET).append(name1)
- .append(COMMA).append(SPACE).append(name2).append
- (DIAMOND_CLOSE_BRACKET);
- return builder.toString();
- }
-
- /**
- * Returns import string.
- *
- * @param pkg package
- * @param cls class
- * @return import string
- */
- public static String getImportString(String pkg, String cls) {
- StringBuilder builder = new StringBuilder()
- .append(IMPORT).append(pkg).append(PERIOD).append(cls)
- .append(signatureClose());
- return builder.toString();
- }
-
- /**
- * Returns static modifier string.
- *
- * @param modifier modifier
- * @return static modifier string
- */
- static String getSpecificModifier(String modifier, String keyWord) {
- return new StringBuilder(modifier).append(SPACE).append(keyWord)
- .toString();
- }
-
- /**
- * Returns builder string for class definition.
- *
- * @param yangName class name
- * @return builder string for class definition
- */
- static String getBuilderImplStringClassDef(String yangName) {
- return new StringBuilder(yangName).append(PERIOD).append(yangName)
- .append(BUILDER).toString();
- }
-
- /**
- * Returns default name string.
- *
- * @param yangName class name
- * @return default name string
- */
- static String getDefaultName(String yangName) {
- return new StringBuilder(DEFAULT_CAPS).append(yangName).toString();
- }
-
- /**
- * Returns suffixed name string.
- *
- * @param yangName class name
- * @param suffix suffix to append to name
- * @return suffixed name string
- */
- static String getSuffixedName(String yangName, String suffix) {
- return new StringBuilder(yangName).append(suffix).toString();
- }
-
- /**
- * Returns error msg string.
- *
- * @param msg message
- * @param name name of node
- * @param line line number
- * @param position char position
- * @param fileName file name
- * @return error message string
- */
- static String getErrorMsg(String msg, String name, int line, int position,
- String fileName) {
- return new StringBuilder().append(msg).append(name).append(IN)
- .append(line).append(AT).append(position).append(IN)
- .append(fileName).toString();
- }
-
- /**
- * Returns string builder attribute string;
- *
- * @param init first param to be appended to string builder
- * @param space indentation space
- * @return string builder attribute
- */
- static String getStringBuilderAttr(String init, String space) {
- StringBuilder builder = new StringBuilder(space);
- builder.append(STRING_BUILDER).append(SPACE).append(STRING_BUILDER_VAR)
- .append(SPACE).append(EQUAL).append(SPACE).append(NEW)
- .append(SPACE).append(STRING_BUILDER).append(
- brackets(OPEN_CLOSE_BRACKET_WITH_VALUE, getQuotedString(init), null))
- .append(signatureClose());
- return builder.toString();
- }
-
- /**
- * Returns quoted string.
- *
- * @param name name to be quoted
- * @return quoted string
- */
- static String getQuotedString(String name) {
- return QUOTES + name + QUOTES;
- }
-
- /**
- * Returns string builder's append string.
- *
- * @param append data to be append
- * @param space indentation
- * @return string builder's append string
- */
- static String getStringBuilderAppendString(String append, String space) {
- return space + STRING_BUILDER_VAR + PERIOD + APPEND + OPEN_PARENTHESIS +
- append + CLOSE_PARENTHESIS + signatureClose();
- }
-
- /**
- * Returns pattern quote string.
- *
- * @param type type for pattern is needed
- * @return pattern quote string
- */
- static String getPatternQuoteString(String type) {
- return PATTERN + PERIOD + QUOTE_STRING + brackets(
- OPEN_CLOSE_BRACKET_WITH_VALUE, getQuotedString(type), null);
- }
-
- /**
- * Returns bitset attribute.
- *
- * @param indentation indentation
- * @return bitset attribute
- */
- static String getBitSetAttr(String indentation) {
- StringBuilder builder = new StringBuilder(indentation);
- return builder.append(BITSET).append(SPACE).append(TMP_VAL)
- .append(SPACE).append(EQUAL).append(SPACE).append(NEW)
- .append(SPACE).append(BITSET).append(OPEN_CLOSE_BRACKET_STRING)
- .append(signatureClose()).toString();
- }
-
- /**
- * Returns for loop string
- *
- * @param space indentation
- * @param type data type
- * @param var variable
- * @param data data variable/collection
- * @return for loop string
- */
- static String getForLoopString(String space, String type, String var,
- String data) {
- return space + FOR + SPACE + OPEN_PARENTHESIS + type + SPACE + var +
- SPACE + COLON + SPACE + data + CLOSE_PARENTHESIS +
- methodSignatureClose(CLASS_TYPE);
- }
-
- /**
- * Returns set value parameter's get string for union to string method.
- *
- * @param count count of type
- * @return get string
- */
- static String getSetValueParaCondition(int count) {
- return SET_VALUE_PARA + PERIOD + GET + brackets(OPEN_CLOSE_BRACKET_WITH_VALUE,
- count + EMPTY_STRING, null);
- }
-
- /**
- * Returns more object attr for union to string method.
- *
- * @return more object attr for union to string method
- */
- static String getMoreObjectAttr() {
- StringBuilder attr = new StringBuilder(EIGHT_SPACE_INDENTATION);
- String[] array = {NEW_LINE};
- attr.append(MORE_OBJ_ATTR).append(GOOGLE_MORE_OBJECT_METHOD_STRING)
- .append(NEW_LINE).append(FOUR_SPACE_INDENTATION).append(trimAtLast(
- getOmitNullValueString(), array)).append(signatureClose());
- return attr.toString();
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/SubtreeFilteringMethodsGenerator.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/SubtreeFilteringMethodsGenerator.java
deleted file mode 100644
index f7229a2..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/SubtreeFilteringMethodsGenerator.java
+++ /dev/null
@@ -1,992 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.translator.tojava.utils;
-
-import org.onosproject.yangutils.datamodel.YangAugment;
-import org.onosproject.yangutils.datamodel.YangCase;
-import org.onosproject.yangutils.datamodel.YangChoice;
-import org.onosproject.yangutils.datamodel.YangLeafRef;
-import org.onosproject.yangutils.datamodel.YangLeavesHolder;
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.YangType;
-import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo;
-import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer;
-import org.onosproject.yangutils.translator.tojava.JavaFileInfoTranslator;
-import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer;
-import org.onosproject.yangutils.utils.io.YangPluginConfig;
-
-import java.io.IOException;
-
-import static org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes.LEAFREF;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FILTER_CONTENT_MATCH_FOR_LEAF_MASK;
-import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.FILTER_CONTENT_MATCH_FOR_NODES_MASK;
-import static org.onosproject.yangutils.translator.tojava.utils.IndentationType.EIGHT_SPACE;
-import static org.onosproject.yangutils.translator.tojava.utils.IndentationType.SIXTEEN_SPACE;
-import static org.onosproject.yangutils.translator.tojava.utils.IndentationType.TWELVE_SPACE;
-import static org.onosproject.yangutils.translator.tojava.utils.IndentationType.TWENTY_FOUR_SPACE;
-import static org.onosproject.yangutils.translator.tojava.utils.IndentationType.TWENTY_SPACE;
-import static org.onosproject.yangutils.translator.tojava.utils.JavaFileGeneratorUtils.getDataFromTempFileHandle;
-import static org.onosproject.yangutils.translator.tojava.utils.StringGenerator.methodClose;
-import static org.onosproject.yangutils.utils.UtilConstants.ADD_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.AND_OPERATION;
-import static org.onosproject.yangutils.utils.UtilConstants.APP_INSTANCE;
-import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_DATA_TYPE;
-import static org.onosproject.yangutils.utils.UtilConstants.BREAK;
-import static org.onosproject.yangutils.utils.UtilConstants.BUILD;
-import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
-import static org.onosproject.yangutils.utils.UtilConstants.CATCH;
-import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_CURLY_BRACKET;
-import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS;
-import static org.onosproject.yangutils.utils.UtilConstants.COLON;
-import static org.onosproject.yangutils.utils.UtilConstants.COMMA;
-import static org.onosproject.yangutils.utils.UtilConstants.CONTINUE;
-import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION;
-import static org.onosproject.yangutils.utils.UtilConstants.ELSE;
-import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CLOSE_BRACKET_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.EQUAL;
-import static org.onosproject.yangutils.utils.UtilConstants.EQUALS_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.EXCEPTION_VAR;
-import static org.onosproject.yangutils.utils.UtilConstants.FALSE;
-import static org.onosproject.yangutils.utils.UtilConstants.FOR;
-import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
-import static org.onosproject.yangutils.utils.UtilConstants.GET_CLASS;
-import static org.onosproject.yangutils.utils.UtilConstants.GET_LEAF_INDEX;
-import static org.onosproject.yangutils.utils.UtilConstants.GET_METHOD;
-import static org.onosproject.yangutils.utils.UtilConstants.GET_METHOD_PREFIX;
-import static org.onosproject.yangutils.utils.UtilConstants.GET_SELECT_LEAF_FLAGS;
-import static org.onosproject.yangutils.utils.UtilConstants.GET_VALUE_LEAF_FLAGS;
-import static org.onosproject.yangutils.utils.UtilConstants.IF;
-import static org.onosproject.yangutils.utils.UtilConstants.ILLEGAL_ACCESS_EXCEPTION;
-import static org.onosproject.yangutils.utils.UtilConstants.INSTANCE;
-import static org.onosproject.yangutils.utils.UtilConstants.INVOCATION_TARGET_EXCEPTION;
-import static org.onosproject.yangutils.utils.UtilConstants.INVOKE;
-import static org.onosproject.yangutils.utils.UtilConstants.IS_ANY_SELECT_OR_CONTAINMENT_NODE_FLAG;
-import static org.onosproject.yangutils.utils.UtilConstants.IS_EMPTY;
-import static org.onosproject.yangutils.utils.UtilConstants.IS_SELECT_ALL_SCHEMA_CHILD_FLAG;
-import static org.onosproject.yangutils.utils.UtilConstants.LEAF_IDENTIFIER;
-import static org.onosproject.yangutils.utils.UtilConstants.MAP;
-import static org.onosproject.yangutils.utils.UtilConstants.NEW;
-import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
-import static org.onosproject.yangutils.utils.UtilConstants.NOT;
-import static org.onosproject.yangutils.utils.UtilConstants.NO_SUCH_METHOD_EXCEPTION;
-import static org.onosproject.yangutils.utils.UtilConstants.NULL;
-import static org.onosproject.yangutils.utils.UtilConstants.OBJECT;
-import static org.onosproject.yangutils.utils.UtilConstants.OBJECT_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET;
-import static org.onosproject.yangutils.utils.UtilConstants.OPEN_PARENTHESIS;
-import static org.onosproject.yangutils.utils.UtilConstants.OR_OPERATION;
-import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
-import static org.onosproject.yangutils.utils.UtilConstants.PRIVATE;
-import static org.onosproject.yangutils.utils.UtilConstants.PROCESS_SUBTREE_FILTERING;
-import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC;
-import static org.onosproject.yangutils.utils.UtilConstants.QUOTES;
-import static org.onosproject.yangutils.utils.UtilConstants.RETURN;
-import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLON;
-import static org.onosproject.yangutils.utils.UtilConstants.SIXTEEN_SPACE_INDENTATION;
-import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
-import static org.onosproject.yangutils.utils.UtilConstants.SUBTREE_FILTERING_RESULT_BUILDER;
-import static org.onosproject.yangutils.utils.UtilConstants.THIRTY_TWO_SPACE_INDENTATION;
-import static org.onosproject.yangutils.utils.UtilConstants.THIS;
-import static org.onosproject.yangutils.utils.UtilConstants.TO;
-import static org.onosproject.yangutils.utils.UtilConstants.TRUE;
-import static org.onosproject.yangutils.utils.UtilConstants.TRY;
-import static org.onosproject.yangutils.utils.UtilConstants.TWELVE_SPACE_INDENTATION;
-import static org.onosproject.yangutils.utils.UtilConstants.TWENTY_EIGHT_SPACE_INDENTATION;
-import static org.onosproject.yangutils.utils.UtilConstants.TWENTY_FOUR_SPACE_INDENTATION;
-import static org.onosproject.yangutils.utils.UtilConstants.TWENTY_SPACE_INDENTATION;
-import static org.onosproject.yangutils.utils.UtilConstants.VALUE;
-import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO;
-import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO_LOWER_CASE;
-import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_OP_PARAM_INFO;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getSmallCase;
-
-/**
- * Represents generator for subtree filtering methods of generated files
- * based on the file type.
- */
-//TODO: improve class to use string generator.
-public final class SubtreeFilteringMethodsGenerator {
-
- /**
- * private to make it a util.
- */
- private SubtreeFilteringMethodsGenerator() {
- }
-
- /**
- * Returns is filter content match for leaf.
- *
- * @param javaAttributeInfo java attribute
- * @param type data type
- * @return is filter content match for leaf
- */
- public static String getSubtreeFilteringForLeaf(
- JavaAttributeInfo javaAttributeInfo, YangType<?> type) {
- String attrQualifiedType;
- String attributeName = javaAttributeInfo.getAttributeName();
- attrQualifiedType = getIfFilterContentMatchMethodImpl(attributeName,
- type);
- return EIGHT_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS
- + GET_VALUE_LEAF_FLAGS + OPEN_CLOSE_BRACKET_STRING +
- PERIOD + GET_METHOD_PREFIX + OPEN_PARENTHESIS +
- LEAF_IDENTIFIER + PERIOD + attributeName.toUpperCase() +
- PERIOD + GET_LEAF_INDEX + CLOSE_PARENTHESIS +
- CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE +
- TWELVE_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS +
- attrQualifiedType + CLOSE_PARENTHESIS + SPACE +
- OPEN_CURLY_BRACKET + NEW_LINE + SIXTEEN_SPACE_INDENTATION +
- RETURN + SPACE + FALSE + SEMI_COLON + NEW_LINE +
- TWELVE_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + SPACE +
- ELSE + SPACE + OPEN_CURLY_BRACKET + NEW_LINE +
- SIXTEEN_SPACE_INDENTATION +
- SUBTREE_FILTERING_RESULT_BUILDER + PERIOD + attributeName +
- OPEN_PARENTHESIS + APP_INSTANCE + PERIOD + attributeName +
- OPEN_PARENTHESIS + CLOSE_PARENTHESIS +
- CLOSE_PARENTHESIS + SEMI_COLON + NEW_LINE +
- TWELVE_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE +
- EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + SPACE + ELSE +
- SPACE + IF + SPACE + OPEN_PARENTHESIS +
- GET_SELECT_LEAF_FLAGS + OPEN_CLOSE_BRACKET_STRING +
- PERIOD + GET_METHOD_PREFIX + OPEN_PARENTHESIS +
- LEAF_IDENTIFIER + PERIOD + attributeName.toUpperCase() +
- PERIOD + GET_LEAF_INDEX + CLOSE_PARENTHESIS + SPACE +
- OR_OPERATION + SPACE + IS_SELECT_ALL_SCHEMA_CHILD_FLAG +
- CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET + NEW_LINE +
- TWELVE_SPACE_INDENTATION +
- IS_ANY_SELECT_OR_CONTAINMENT_NODE_FLAG + SPACE + EQUAL +
- SPACE + TRUE + SEMI_COLON + NEW_LINE +
- TWELVE_SPACE_INDENTATION + SUBTREE_FILTERING_RESULT_BUILDER +
- PERIOD + attributeName + OPEN_PARENTHESIS + APP_INSTANCE +
- PERIOD + attributeName + OPEN_CLOSE_BRACKET_STRING +
- CLOSE_PARENTHESIS + SEMI_COLON + NEW_LINE +
- EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
- }
-
- private static String getAttrTypeForFilterContentMatchWhenPrimitiveDataType(
- String attributeName) {
- return/* TODO: Need to check if we can expose the value leaf flag in
- interface.
- NOT + APP_INSTANCE + PERIOD + GET_VALUE_LEAF_FLAGS +
- OPEN_PARENTHESIS + CLOSE_PARENTHESIS +
- GET_METHOD_PREFIX + OPEN_PARENTHESIS + LEAF_IDENTIFIER +
- PERIOD + attributeName.toUpperCase() + PERIOD
- + GET_LEAF_INDEX + OR_OPERATION +*/
- APP_INSTANCE + PERIOD + attributeName + OPEN_PARENTHESIS +
- CLOSE_PARENTHESIS + SPACE + NOT + EQUAL + SPACE +
- attributeName + OPEN_PARENTHESIS +
- CLOSE_PARENTHESIS;
- }
-
- private static String
- getAttrTypeForFilterContentMatchWhenNonPrimitiveDataTypes(
- String attributeName) {
- return APP_INSTANCE + PERIOD + attributeName + OPEN_PARENTHESIS +
- CLOSE_PARENTHESIS + SPACE + EQUAL + EQUAL + SPACE + NULL +
- SPACE + OR_OPERATION + SPACE + NOT + OPEN_PARENTHESIS +
- attributeName + OPEN_PARENTHESIS + CLOSE_PARENTHESIS +
- PERIOD + EQUALS_STRING + OPEN_PARENTHESIS + APP_INSTANCE +
- PERIOD + attributeName + OPEN_PARENTHESIS +
- CLOSE_PARENTHESIS + CLOSE_PARENTHESIS + CLOSE_PARENTHESIS;
- }
-
- private static String getIfFilterContentMatchMethodImpl(
- String attributeName,
- YangType dataType) {
- String attrQualifiedType;
-
- if (StringGenerator.isPrimitiveDataType(dataType.getDataType())) {
- attrQualifiedType =
- getAttrTypeForFilterContentMatchWhenPrimitiveDataType(
- attributeName);
- } else if (dataType.getDataType() == LEAFREF) {
-
- // When leafref in grouping.
- if (((YangLeafRef) dataType.getDataTypeExtendedInfo())
- .isInGrouping()) {
- attrQualifiedType =
- getAttrTypeForFilterContentMatchWhenNonPrimitiveDataTypes(
- attributeName);
- } else {
-
- YangType type = ((YangLeafRef) dataType.getDataTypeExtendedInfo())
- .getEffectiveDataType();
-
- if (StringGenerator.isPrimitiveDataType(type.getDataType())) {
- attrQualifiedType =
- getAttrTypeForFilterContentMatchWhenPrimitiveDataType(
- attributeName);
- } else {
- attrQualifiedType =
- getAttrTypeForFilterContentMatchWhenNonPrimitiveDataTypes(
- attributeName);
- }
- }
- } else {
- attrQualifiedType =
- getAttrTypeForFilterContentMatchWhenNonPrimitiveDataTypes(
- attributeName);
- }
-
- return attrQualifiedType;
- }
-
- /**
- * Returns is filter content match for leaf.
- *
- * @param javaAttributeInfo java attribute
- * @return is filter content match for leaf
- */
- public static String getSubtreeFilteringForLeafList(
- JavaAttributeInfo javaAttributeInfo) {
- return getSubtreeFilteringForList(javaAttributeInfo, true);
- }
-
- /**
- * Returns is filter content match for child node.
- *
- * @param curNode current node
- * @param pluginConfig plugin configurations
- * @param path path of temp file
- * @return is filter content match for child node
- */
- static String getProcessChildNodeSubtreeFiltering(YangNode curNode,
- YangPluginConfig
- pluginConfig,
- String path)
- throws IOException {
- JavaFileInfoTranslator javaFileInfo =
- ((JavaFileInfoContainer) curNode).getJavaFileInfo();
- JavaFileInfoTranslator parentInfo;
-
- String instance = APP_INSTANCE;
- String name = getCapitalCase(javaFileInfo.getJavaName());
- String builderNamePrefix = getCapitalCase(javaFileInfo.getJavaName());
- if (curNode instanceof YangCase) {
- instance = INSTANCE;
- YangNode parent = curNode.getParent();
- if (parent instanceof YangChoice) {
- parentInfo = ((JavaFileInfoContainer) parent).getJavaFileInfo();
- name = getCapitalCase(parentInfo.getJavaName());
- } else if (parent instanceof YangAugment) {
- parentInfo = ((JavaFileInfoContainer) ((YangAugment) parent)
- .getAugmentedNode()).getJavaFileInfo();
- if (parentInfo != null) {
- name = getCapitalCase(parentInfo.getJavaName());
- } else {
- name = getCapitalCase(getCamelCase(
- ((YangAugment) parent).getAugmentedNode().getName(),
- pluginConfig.getConflictResolver()));
- }
- }
- }
-
- String processSubtreeFilteringMethod =
- FOUR_SPACE_INDENTATION + PRIVATE + SPACE + BOOLEAN_DATA_TYPE +
- SPACE + "processChildNodesSubTreeFiltering" +
- OPEN_PARENTHESIS + name + SPACE + instance + COMMA +
- SPACE + builderNamePrefix + BUILDER + SPACE +
- "subTreeFilteringResultBuilder" + COMMA + NEW_LINE +
- TWELVE_SPACE_INDENTATION + "Boolean " +
- "isAnySelectOrContainmentNode, " + "boolean " +
- "isSelectAllSchemaChild" + CLOSE_PARENTHESIS +
- SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
-
- if (curNode instanceof YangCase) {
- String caseName = getCapitalCase(javaFileInfo.getJavaName());
- processSubtreeFilteringMethod =
- processSubtreeFilteringMethod + EIGHT_SPACE_INDENTATION +
- caseName + SPACE + APP_INSTANCE + SPACE +
- EQUAL + SPACE + OPEN_PARENTHESIS + caseName +
- CLOSE_PARENTHESIS + SPACE + instance +
- SEMI_COLON + NEW_LINE;
- }
-
- processSubtreeFilteringMethod +=
- getDataFromTempFileHandle(FILTER_CONTENT_MATCH_FOR_NODES_MASK,
- ((TempJavaCodeFragmentFilesContainer) curNode)
- .getTempJavaCodeFragmentFiles()
- .getBeanTempFiles(), path);
-
- processSubtreeFilteringMethod +=
- EIGHT_SPACE_INDENTATION + RETURN + SPACE + TRUE + SEMI_COLON +
- NEW_LINE + FOUR_SPACE_INDENTATION +
- CLOSE_CURLY_BRACKET + NEW_LINE + NEW_LINE;
-
- return processSubtreeFilteringMethod;
- }
-
- /**
- * Returns is filter content match for leaf list.
- *
- * @param curNode current node
- * @param pluginConfig plugin configurations
- * @param path path of temp file
- * @return is filter content match for leaf list
- */
- static String getProcessLeafListSubtreeFiltering(YangNode curNode,
- YangPluginConfig
- pluginConfig,
- String path)
- throws IOException {
- JavaFileInfoTranslator javaFileInfo =
- ((JavaFileInfoContainer) curNode).getJavaFileInfo();
- JavaFileInfoTranslator parentInfo;
-
- String instance = APP_INSTANCE;
- String name = getCapitalCase(javaFileInfo.getJavaName());
- String builderNamePrefix = getCapitalCase(javaFileInfo.getJavaName());
- if (curNode instanceof YangCase) {
- instance = INSTANCE;
- YangNode parent = curNode.getParent();
- if (parent instanceof YangChoice) {
- parentInfo = ((JavaFileInfoContainer) parent).getJavaFileInfo();
- name = getCapitalCase(parentInfo.getJavaName());
- } else if (parent instanceof YangAugment) {
- parentInfo = ((JavaFileInfoContainer) ((YangAugment) parent)
- .getAugmentedNode()).getJavaFileInfo();
- if (parentInfo != null) {
- name = getCapitalCase(parentInfo.getJavaName());
- } else {
- name = getCapitalCase(getCamelCase(
- ((YangAugment) parent).getAugmentedNode().getName(),
- pluginConfig.getConflictResolver()));
- }
- }
- }
-
- String processSubtreeFilteringMethod =
- FOUR_SPACE_INDENTATION + PRIVATE + SPACE + BOOLEAN_DATA_TYPE +
- SPACE + "processLeafListSubTreeFiltering" +
- OPEN_PARENTHESIS + name + SPACE + instance + COMMA +
- SPACE + builderNamePrefix + BUILDER + SPACE +
- "subTreeFilteringResultBuilder" + COMMA + NEW_LINE +
- TWELVE_SPACE_INDENTATION + "Boolean " +
- "isAnySelectOrContainmentNode, " + "boolean " +
- "isSelectAllSchemaChild" + CLOSE_PARENTHESIS +
- SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
-
- if (curNode instanceof YangCase) {
- String caseName = getCapitalCase(javaFileInfo.getJavaName());
- processSubtreeFilteringMethod =
- processSubtreeFilteringMethod + EIGHT_SPACE_INDENTATION +
- caseName + SPACE + APP_INSTANCE + SPACE +
- EQUAL + SPACE + OPEN_PARENTHESIS + caseName +
- CLOSE_PARENTHESIS + SPACE + instance +
- SEMI_COLON + NEW_LINE;
- }
-
- processSubtreeFilteringMethod += getDataFromTempFileHandle(
- FILTER_CONTENT_MATCH_FOR_LEAF_LIST_MASK,
- ((TempJavaCodeFragmentFilesContainer) curNode)
- .getTempJavaCodeFragmentFiles()
- .getBeanTempFiles(), path);
-
- processSubtreeFilteringMethod +=
- EIGHT_SPACE_INDENTATION + RETURN + SPACE + TRUE + SEMI_COLON +
- NEW_LINE + FOUR_SPACE_INDENTATION +
- CLOSE_CURLY_BRACKET + NEW_LINE + NEW_LINE;
-
- return processSubtreeFilteringMethod;
- }
-
- /**
- * Returns is filter content match for leaf.
- *
- * @param curNode current node
- * @param pluginConfig plugin configurations
- * @param path path of temp file
- * @return is filter content match for leaf
- */
- static String getProcessLeafSubtreeFiltering(YangNode curNode,
- YangPluginConfig pluginConfig,
- String path)
- throws IOException {
- JavaFileInfoTranslator javaFileInfo =
- ((JavaFileInfoContainer) curNode).getJavaFileInfo();
- JavaFileInfoTranslator parentInfo;
-
- String instance = APP_INSTANCE;
- String name = getCapitalCase(javaFileInfo.getJavaName());
- String builderNamePrefix = getCapitalCase(javaFileInfo.getJavaName());
- if (curNode instanceof YangCase) {
- instance = INSTANCE;
- YangNode parent = curNode.getParent();
- if (parent instanceof YangChoice) {
- parentInfo = ((JavaFileInfoContainer) parent).getJavaFileInfo();
- name = getCapitalCase(parentInfo.getJavaName());
- } else if (parent instanceof YangAugment) {
- parentInfo = ((JavaFileInfoContainer) ((YangAugment) parent)
- .getAugmentedNode()).getJavaFileInfo();
- if (parentInfo != null) {
- name = getCapitalCase(parentInfo.getJavaName());
- } else {
- name = getCapitalCase(getCamelCase(
- ((YangAugment) parent).getAugmentedNode().getName(),
- pluginConfig.getConflictResolver()));
- }
- }
- }
-
- String processSubtreeFilteringMethod =
- FOUR_SPACE_INDENTATION + PRIVATE + SPACE + BOOLEAN_DATA_TYPE +
- SPACE + "processLeafSubtreeFiltering" +
- OPEN_PARENTHESIS + name + SPACE + instance + COMMA +
- SPACE + builderNamePrefix + BUILDER + SPACE +
- "subTreeFilteringResultBuilder" + COMMA + NEW_LINE
- + TWELVE_SPACE_INDENTATION + "Boolean " +
- "isAnySelectOrContainmentNode, " + "boolean " +
- "isSelectAllSchemaChild" + CLOSE_PARENTHESIS +
- SPACE + OPEN_CURLY_BRACKET + NEW_LINE;
-
- if (curNode instanceof YangCase) {
- String caseName = getCapitalCase(javaFileInfo.getJavaName());
- processSubtreeFilteringMethod =
- processSubtreeFilteringMethod + EIGHT_SPACE_INDENTATION +
- caseName + SPACE + APP_INSTANCE + SPACE +
- EQUAL + SPACE + OPEN_PARENTHESIS + caseName +
- CLOSE_PARENTHESIS + SPACE + instance +
- SEMI_COLON + NEW_LINE;
- }
-
- processSubtreeFilteringMethod +=
- getDataFromTempFileHandle(FILTER_CONTENT_MATCH_FOR_LEAF_MASK,
- ((TempJavaCodeFragmentFilesContainer) curNode)
- .getTempJavaCodeFragmentFiles()
- .getBeanTempFiles(), path);
-
- processSubtreeFilteringMethod +=
- EIGHT_SPACE_INDENTATION + RETURN + SPACE + TRUE + SEMI_COLON +
- NEW_LINE + FOUR_SPACE_INDENTATION +
- CLOSE_CURLY_BRACKET + NEW_LINE + NEW_LINE;
-
- return processSubtreeFilteringMethod;
- }
-
- /**
- * Returns is filter content match for leaf.
- *
- * @param curNode current node
- * @param pluginConfig plugin configurations
- * @return is filter content match for leaf
- */
- static String getProcessSubtreeFilteringStart(YangNode curNode,
- YangPluginConfig
- pluginConfig) {
- JavaFileInfoTranslator javaFileInfo =
- ((JavaFileInfoContainer) curNode).getJavaFileInfo();
- JavaFileInfoTranslator parentInfo;
-
- String instance = APP_INSTANCE;
- String name = getCapitalCase(javaFileInfo.getJavaName());
- String builderNamePrefix = getCapitalCase(javaFileInfo.getJavaName());
- if (curNode instanceof YangCase) {
- instance = INSTANCE;
- YangNode parent = curNode.getParent();
- if (parent instanceof YangChoice) {
- parentInfo = ((JavaFileInfoContainer) parent).getJavaFileInfo();
- name = getCapitalCase(parentInfo.getJavaName());
- } else if (parent instanceof YangAugment) {
- parentInfo = ((JavaFileInfoContainer) ((YangAugment) parent)
- .getAugmentedNode()).getJavaFileInfo();
- if (parentInfo != null) {
- name = getCapitalCase(parentInfo.getJavaName());
- } else {
- name = getCapitalCase(getCamelCase(
- ((YangAugment) parent).getAugmentedNode().getName(),
- pluginConfig.getConflictResolver()));
- }
- }
- }
- String processSubtreeFilteringMethod =
- StringGenerator.getOverRideString() + FOUR_SPACE_INDENTATION +
- PUBLIC + SPACE + name + SPACE +
- PROCESS_SUBTREE_FILTERING + OPEN_PARENTHESIS + name +
- SPACE + instance + COMMA + SPACE + BOOLEAN_DATA_TYPE +
- SPACE + "isSelectAllSchemaChild" +
- CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET +
- NEW_LINE + EIGHT_SPACE_INDENTATION +
- builderNamePrefix + BUILDER + SPACE +
- SUBTREE_FILTERING_RESULT_BUILDER + SPACE + EQUAL +
- SPACE + NEW + SPACE + builderNamePrefix + BUILDER +
- OPEN_PARENTHESIS + CLOSE_PARENTHESIS + SEMI_COLON +
- NEW_LINE + EIGHT_SPACE_INDENTATION + "Boolean" + SPACE +
- IS_ANY_SELECT_OR_CONTAINMENT_NODE_FLAG + SPACE +
- EQUAL + SPACE + FALSE + SEMI_COLON + NEW_LINE;
-
- if (curNode instanceof YangCase) {
- String caseName = getCapitalCase(javaFileInfo.getJavaName());
- processSubtreeFilteringMethod =
- processSubtreeFilteringMethod + EIGHT_SPACE_INDENTATION +
- caseName + SPACE + APP_INSTANCE + SPACE +
- EQUAL + SPACE + OPEN_PARENTHESIS + caseName +
- CLOSE_PARENTHESIS + SPACE + instance +
- SEMI_COLON + NEW_LINE;
- }
-
- return processSubtreeFilteringMethod;
- }
-
- /**
- * Get the body for process subtree filtering.
- *
- * @param curNode node for which the code is being generated
- * @return body of subtree filtering
- */
- static String getProcessSubtreeFunctionBody(YangNode curNode) {
-
- String method = "";
-
- if (curNode instanceof YangLeavesHolder) {
- if (((YangLeavesHolder) curNode).getListOfLeaf() != null
- &&
- !((YangLeavesHolder) curNode).getListOfLeaf().isEmpty()) {
- method += StringGenerator
- .getIfConditionBegin(EIGHT_SPACE_INDENTATION, NOT +
- "processLeafSubtreeFiltering(appInstance, " +
- "subTreeFilteringResultBuilder," + NEW_LINE +
- TWELVE_SPACE_INDENTATION +
- "isAnySelectOrContainmentNode, " +
- "isSelectAllSchemaChild)");
-
- method += TWELVE_SPACE_INDENTATION + RETURN + SPACE + NULL +
- SEMI_COLON + NEW_LINE;
-
- method += methodClose(EIGHT_SPACE);
- }
- }
-
- if (curNode instanceof YangLeavesHolder) {
- if (((YangLeavesHolder) curNode).getListOfLeafList() != null
- &&
- !((YangLeavesHolder) curNode).getListOfLeafList()
- .isEmpty()) {
- method += StringGenerator
- .getIfConditionBegin(EIGHT_SPACE_INDENTATION, NOT +
- "processLeafListSubTreeFiltering(appInstance," +
- " subTreeFilteringResultBuilder," + NEW_LINE
- + TWELVE_SPACE_INDENTATION +
- "isAnySelectOrContainmentNode, " +
- "isSelectAllSchemaChild)");
-
- method += TWELVE_SPACE_INDENTATION + RETURN + SPACE + NULL +
- SEMI_COLON + NEW_LINE;
-
- method += methodClose(EIGHT_SPACE);
- }
- }
-
- if (curNode.getChild() != null) {
-
- method += StringGenerator
- .getIfConditionBegin(EIGHT_SPACE_INDENTATION, NOT +
- "processChildNodesSubTreeFiltering(appInstance, " +
- "subTreeFilteringResultBuilder," + NEW_LINE +
- TWELVE_SPACE_INDENTATION +
- "isAnySelectOrContainmentNode, " +
- "isSelectAllSchemaChild)");
-
- method += TWELVE_SPACE_INDENTATION + RETURN + SPACE + NULL +
- SEMI_COLON + NEW_LINE;
-
- method += methodClose(EIGHT_SPACE);
- }
-
- return method;
- }
-
- /**
- * Returns is filter content match for node.
- *
- * @param attr attribute info
- * @return is filter content match for node
- */
- public static String getSubtreeFilteringForNode(JavaAttributeInfo attr) {
- boolean isList = attr.isListAttr();
- if (isList) {
- return getSubtreeFilteringForList(attr, false);
- } else {
- return getSubtreeFilteringForChildNode(attr);
- }
- }
-
- /**
- * Returns is filter content match close.
- *
- * @return is filter content match close
- */
- static String getProcessSubTreeFilteringEnd() {
- String method = StringGenerator
- .getIfConditionBegin(EIGHT_SPACE_INDENTATION,
- NOT + IS_SELECT_ALL_SCHEMA_CHILD_FLAG +
- SPACE + AND_OPERATION + SPACE +
- NOT +
- IS_ANY_SELECT_OR_CONTAINMENT_NODE_FLAG);
-
- method += TWELVE_SPACE_INDENTATION + RETURN + SPACE +
- PROCESS_SUBTREE_FILTERING + OPEN_PARENTHESIS + APP_INSTANCE +
- COMMA + SPACE + TRUE + CLOSE_PARENTHESIS + SEMI_COLON +
- NEW_LINE;
-
- method += methodClose(EIGHT_SPACE);
-
- method += EIGHT_SPACE_INDENTATION + RETURN + SPACE +
- SUBTREE_FILTERING_RESULT_BUILDER + PERIOD + BUILD +
- OPEN_CLOSE_BRACKET_STRING + SEMI_COLON + NEW_LINE +
- FOUR_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
-
- return method;
- }
-
- /**
- * Returns filter content match for child nodes.
- *
- * @param javaAttributeInfo attribute to be added
- * @return filter content match for child nodes
- */
- private static String getSubtreeFilteringForChildNode(
- JavaAttributeInfo javaAttributeInfo) {
- String name = javaAttributeInfo.getAttributeName();
- name = getSmallCase(name);
- String type = javaAttributeInfo.getImportInfo().getClassInfo();
- if (javaAttributeInfo.isQualifiedName()) {
- type = javaAttributeInfo.getImportInfo().getPkgInfo() + PERIOD +
- type;
- }
-
- String method = StringGenerator
- .getIfConditionBegin(EIGHT_SPACE_INDENTATION, name + "() != " +
- "null");
-
- method += TWELVE_SPACE_INDENTATION +
- IS_ANY_SELECT_OR_CONTAINMENT_NODE_FLAG + SPACE + EQUAL + SPACE +
- TRUE + SEMI_COLON + NEW_LINE;
-
- method += TWELVE_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS +
- APP_INSTANCE + PERIOD + name + OPEN_PARENTHESIS +
- CLOSE_PARENTHESIS + SPACE + NOT
- + EQUAL + SPACE + NULL + CLOSE_PARENTHESIS + SPACE +
- OPEN_CURLY_BRACKET + NEW_LINE;
-
- method += SIXTEEN_SPACE_INDENTATION + type + SPACE + "result = " +
- name + PERIOD + PROCESS_SUBTREE_FILTERING + OPEN_PARENTHESIS +
- APP_INSTANCE + PERIOD + name + OPEN_CLOSE_BRACKET_STRING
- + COMMA + SPACE + FALSE + CLOSE_PARENTHESIS + SEMI_COLON +
- NEW_LINE;
-
- method += SIXTEEN_SPACE_INDENTATION + "if (result != null) {" +
- NEW_LINE;
-
- method += TWENTY_SPACE_INDENTATION + SUBTREE_FILTERING_RESULT_BUILDER +
- PERIOD + name + OPEN_PARENTHESIS + "result" +
- CLOSE_PARENTHESIS + SEMI_COLON + NEW_LINE +
- SIXTEEN_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
-
- //if app instance is not null
- method += methodClose(TWELVE_SPACE);
-
- //if query instance is not null
- method += methodClose(TWELVE_SPACE);
-
- return method;
- }
-
- /**
- * Returns filter content match for list types.
- *
- * @param javaAttributeInfo attribute information
- * @param isLeafList if for leaf list
- * @return filter content match for list types
- */
- private static String getSubtreeFilteringForList(
- JavaAttributeInfo javaAttributeInfo, boolean isLeafList) {
- String capitalCaseName =
- getCapitalCase(javaAttributeInfo.getAttributeName());
- String name = javaAttributeInfo.getAttributeName();
- String type = javaAttributeInfo.getImportInfo().getClassInfo();
- if (javaAttributeInfo.isQualifiedName()) {
- type = javaAttributeInfo.getImportInfo().getPkgInfo() + PERIOD +
- type;
- }
-
- /*
- * If select all schema child
- */
- String method = StringGenerator
- .getIfConditionBegin(EIGHT_SPACE_INDENTATION,
- IS_SELECT_ALL_SCHEMA_CHILD_FLAG);
-
- method = method + StringGenerator
- .getCollectionIteratorForLoopBegin(TWELVE_SPACE_INDENTATION,
- type + SPACE + name,
- APP_INSTANCE + PERIOD +
- name +
- OPEN_CLOSE_BRACKET_STRING);
-
- method = method + SIXTEEN_SPACE_INDENTATION +
- SUBTREE_FILTERING_RESULT_BUILDER + PERIOD + ADD_STRING +
- getCapitalCase(TO) + capitalCaseName + OPEN_PARENTHESIS +
- name + CLOSE_PARENTHESIS + SEMI_COLON + NEW_LINE;
-
- method += methodClose(TWELVE_SPACE); // Close collection Iteration loop
-
- //If need to explicitly participate in query
- method += StringGenerator
- .getElseIfConditionBegin(EIGHT_SPACE_INDENTATION,
- name + OPEN_CLOSE_BRACKET_STRING +
- SPACE + NOT + EQUAL +
- SPACE + NULL);
-
- if (!isLeafList) {
- method += TWELVE_SPACE_INDENTATION +
- IS_ANY_SELECT_OR_CONTAINMENT_NODE_FLAG + SPACE + EQUAL +
- SPACE + TRUE + SEMI_COLON + NEW_LINE;
- }
-
- //If there is any parameter in the query condition
- method += StringGenerator
- .getIfConditionBegin(TWELVE_SPACE_INDENTATION, NOT + name +
- OPEN_CLOSE_BRACKET_STRING + PERIOD + IS_EMPTY);
-
- if (isLeafList) {
- /*
- * If there is no app instance to perform content match
- */
- method += StringGenerator
- .getIfConditionBegin(SIXTEEN_SPACE_INDENTATION,
- APP_INSTANCE + PERIOD + name +
- OPEN_CLOSE_BRACKET_STRING +
- SPACE + EQUAL + EQUAL + SPACE +
- NULL + SPACE + OR_OPERATION
- + SPACE + APP_INSTANCE +
- PERIOD + name +
- OPEN_CLOSE_BRACKET_STRING +
- PERIOD + IS_EMPTY);
-
- method += TWENTY_SPACE_INDENTATION + RETURN + SPACE + FALSE +
- SEMI_COLON + NEW_LINE;
-
- method += methodClose(SIXTEEN_SPACE);
-
- // for instance iterator
- method += StringGenerator.getCollectionIteratorForLoopBegin(
- SIXTEEN_SPACE_INDENTATION, type + SPACE + name,
- name + OPEN_CLOSE_BRACKET_STRING);
-
- method += TWENTY_SPACE_INDENTATION + BOOLEAN_DATA_TYPE + SPACE +
- "flag" + SPACE + EQUAL + SPACE + FALSE + SEMI_COLON +
- NEW_LINE;
-
- // for app instance iterator
- method += StringGenerator
- .getCollectionIteratorForLoopBegin(TWENTY_SPACE_INDENTATION,
- type + SPACE + name +
- "2",
- APP_INSTANCE + PERIOD +
- name +
- OPEN_CLOSE_BRACKET_STRING);
-
- //the content match leaf list attribute value matches
- method += StringGenerator
- .getIfConditionBegin(TWENTY_FOUR_SPACE_INDENTATION,
- name + PERIOD + EQUALS_STRING
- + OPEN_PARENTHESIS + name +
- "2" + CLOSE_PARENTHESIS);
-
- method += TWENTY_EIGHT_SPACE_INDENTATION + "flag" + SPACE + EQUAL +
- SPACE + TRUE + SEMI_COLON + NEW_LINE;
-
- method += TWENTY_EIGHT_SPACE_INDENTATION +
- SUBTREE_FILTERING_RESULT_BUILDER + PERIOD + ADD_STRING +
- getCapitalCase(TO) + capitalCaseName + OPEN_PARENTHESIS +
- name + "2" + CLOSE_PARENTHESIS +
- SEMI_COLON + NEW_LINE + TWENTY_EIGHT_SPACE_INDENTATION +
- BREAK + SEMI_COLON + NEW_LINE;
-
- //the content match leaf list attribute value matches
- method += methodClose(TWENTY_FOUR_SPACE);
-
- // for app instance iterator
- method += methodClose(TWENTY_SPACE);
-
- //if the content match failed
- method += StringGenerator
- .getIfConditionBegin(TWENTY_SPACE_INDENTATION, "!flag");
-
- method += TWENTY_FOUR_SPACE_INDENTATION + RETURN + SPACE + FALSE +
- SEMI_COLON + NEW_LINE;
-
- method +=
- methodClose(TWENTY_SPACE); // if flag == false
-
- method += methodClose(SIXTEEN_SPACE); // for instance iterator
- } else {
-
- /*if there is any app instance entry*/
- method += StringGenerator
- .getIfConditionBegin(SIXTEEN_SPACE_INDENTATION,
- APP_INSTANCE + PERIOD + name +
- OPEN_CLOSE_BRACKET_STRING +
- SPACE + NOT + EQUAL + SPACE +
- NULL + SPACE + AND_OPERATION +
- SPACE + NOT + APP_INSTANCE +
- PERIOD + name +
- OPEN_CLOSE_BRACKET_STRING +
- PERIOD + IS_EMPTY);
-
- /*
- * loop all the query condition instance(s)
- */
- method += StringGenerator
- .getCollectionIteratorForLoopBegin(TWENTY_SPACE_INDENTATION,
- type + SPACE + name,
- name +
- OPEN_CLOSE_BRACKET_STRING);
-
- //loop all the app instance(s)
- method += StringGenerator.getCollectionIteratorForLoopBegin(
- TWENTY_FOUR_SPACE_INDENTATION, type + SPACE + name + "2",
- APP_INSTANCE + PERIOD + name +
- OPEN_CLOSE_BRACKET_STRING);
-
- method += TWENTY_EIGHT_SPACE_INDENTATION + type + SPACE +
- "result = " + name + PERIOD +
- PROCESS_SUBTREE_FILTERING + OPEN_PARENTHESIS + name + "2" +
- COMMA + SPACE + FALSE + CLOSE_PARENTHESIS + SEMI_COLON +
- NEW_LINE;
-
- method += TWENTY_EIGHT_SPACE_INDENTATION + "if (result != null) {" +
- NEW_LINE;
-
- method += THIRTY_TWO_SPACE_INDENTATION +
- SUBTREE_FILTERING_RESULT_BUILDER + PERIOD + ADD_STRING +
- getCapitalCase(TO) + capitalCaseName + OPEN_PARENTHESIS +
- "result" + CLOSE_PARENTHESIS +
- SEMI_COLON + NEW_LINE + TWENTY_EIGHT_SPACE_INDENTATION +
- CLOSE_CURLY_BRACKET + NEW_LINE;
-
- //loop all the app instance(s)
- method +=
- methodClose(TWENTY_FOUR_SPACE);
-
- //loop all the query condition instance(s)
- method += methodClose(TWENTY_SPACE);
-
- //if there is any app instance entry
- method += methodClose(SIXTEEN_SPACE);
- }
-
- method += TWELVE_SPACE_INDENTATION + "} else {" + NEW_LINE;
-
- if (isLeafList) {
- method += SIXTEEN_SPACE_INDENTATION +
- IS_ANY_SELECT_OR_CONTAINMENT_NODE_FLAG + SPACE +
- EQUAL + SPACE + TRUE + SEMI_COLON + NEW_LINE;
- }
-
- method += StringGenerator
- .getIfConditionBegin(SIXTEEN_SPACE_INDENTATION,
- APP_INSTANCE + PERIOD + name
- + OPEN_CLOSE_BRACKET_STRING +
- SPACE + NOT + EQUAL + SPACE +
- NULL + SPACE + AND_OPERATION +
- SPACE + NOT + APP_INSTANCE +
- PERIOD + name +
- OPEN_CLOSE_BRACKET_STRING +
- PERIOD + IS_EMPTY);
-
- method = method + StringGenerator
- .getCollectionIteratorForLoopBegin(TWENTY_SPACE_INDENTATION,
- type + SPACE + name,
- APP_INSTANCE + PERIOD +
- name +
- OPEN_CLOSE_BRACKET_STRING);
-
- method = method + TWENTY_FOUR_SPACE_INDENTATION +
- SUBTREE_FILTERING_RESULT_BUILDER + PERIOD + ADD_STRING
- + getCapitalCase(TO) + capitalCaseName + OPEN_PARENTHESIS +
- name + CLOSE_PARENTHESIS + SEMI_COLON + NEW_LINE;
-
- method += methodClose(TWENTY_SPACE);// Close collection Iteration loop
-
- method +=
- methodClose(SIXTEEN_SPACE); // close if condition
-
- method +=
- methodClose(TWELVE_SPACE); // close else condition
-
- method += methodClose(EIGHT_SPACE); // close else if condition
-
- return method;
- }
-
- //Returns method string for op params augmented syntax
- static String getAugmentableSubTreeFiltering() {
- return EIGHT_SPACE_INDENTATION + FOR + SPACE + OPEN_PARENTHESIS +
- OBJECT_STRING + SPACE + YANG_AUGMENTED_INFO_LOWER_CASE +
- SPACE + COLON + SPACE + THIS + PERIOD +
- YANG_AUGMENTED_INFO_LOWER_CASE + MAP +
- OPEN_PARENTHESIS + CLOSE_PARENTHESIS + PERIOD
- + VALUE + "s" + OPEN_PARENTHESIS + CLOSE_PARENTHESIS +
- CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET +
- NEW_LINE + TWELVE_SPACE_INDENTATION + OBJECT_STRING + SPACE +
- getSmallCase(YANG_AUGMENTED_OP_PARAM_INFO) + SPACE + EQUAL +
- SPACE + APP_INSTANCE + PERIOD +
- YANG_AUGMENTED_INFO_LOWER_CASE + OPEN_PARENTHESIS +
- YANG_AUGMENTED_INFO_LOWER_CASE + PERIOD +
- GET_CLASS + CLOSE_PARENTHESIS + SEMI_COLON + NEW_LINE +
- TWELVE_SPACE_INDENTATION + OBJECT + SPACE +
- PROCESS_SUBTREE_FILTERING + SEMI_COLON
- + NEW_LINE + TWELVE_SPACE_INDENTATION + TRY + SPACE +
- OPEN_CURLY_BRACKET + NEW_LINE +
- SIXTEEN_SPACE_INDENTATION +
- "Class<?>[] interfaces = " + YANG_AUGMENTED_INFO_LOWER_CASE +
- ".getClass().getInterfaces();" +
- NEW_LINE + SIXTEEN_SPACE_INDENTATION +
- PROCESS_SUBTREE_FILTERING + SPACE + EQUAL + SPACE +
- YANG_AUGMENTED_INFO_LOWER_CASE + PERIOD + GET_CLASS +
- NEW_LINE + TWENTY_SPACE_INDENTATION + PERIOD +
- GET_METHOD + OPEN_PARENTHESIS + QUOTES +
- PROCESS_SUBTREE_FILTERING + QUOTES + COMMA + SPACE +
- "interfaces[0]" + CLOSE_PARENTHESIS + PERIOD + INVOKE +
- OPEN_PARENTHESIS + YANG_AUGMENTED_INFO_LOWER_CASE +
- COMMA + NEW_LINE + TWENTY_FOUR_SPACE_INDENTATION +
- getSmallCase(YANG_AUGMENTED_OP_PARAM_INFO) +
- CLOSE_PARENTHESIS + SEMI_COLON + NEW_LINE +
- SIXTEEN_SPACE_INDENTATION + IF + SPACE + OPEN_PARENTHESIS +
- PROCESS_SUBTREE_FILTERING + SPACE + NOT + EQUAL + SPACE +
- NULL + CLOSE_PARENTHESIS + SPACE + OPEN_CURLY_BRACKET +
- NEW_LINE + TWENTY_SPACE_INDENTATION +
- SUBTREE_FILTERING_RESULT_BUILDER + PERIOD + "add" +
- YANG_AUGMENTED_INFO + OPEN_PARENTHESIS +
- PROCESS_SUBTREE_FILTERING + COMMA + SPACE +
- PROCESS_SUBTREE_FILTERING + PERIOD + GET_CLASS +
- CLOSE_PARENTHESIS + SEMI_COLON + NEW_LINE +
- SIXTEEN_SPACE_INDENTATION + CLOSE_CURLY_BRACKET +
- NEW_LINE + TWELVE_SPACE_INDENTATION + CLOSE_CURLY_BRACKET +
- SPACE + CATCH + SPACE + OPEN_PARENTHESIS +
- NO_SUCH_METHOD_EXCEPTION + " | " +
- INVOCATION_TARGET_EXCEPTION + " | " + ILLEGAL_ACCESS_EXCEPTION +
- SPACE + EXCEPTION_VAR + CLOSE_PARENTHESIS + SPACE +
- OPEN_CURLY_BRACKET + NEW_LINE + SIXTEEN_SPACE_INDENTATION +
- CONTINUE + SEMI_COLON + NEW_LINE +
- TWELVE_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE +
- EIGHT_SPACE_INDENTATION + CLOSE_CURLY_BRACKET + NEW_LINE;
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/TranslatorErrorType.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/TranslatorErrorType.java
deleted file mode 100644
index 2871f16..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/TranslatorErrorType.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.translator.tojava.utils;
-
-/**
- * Represents translator error type.
- */
-public enum TranslatorErrorType {
- /**
- * Represents the invalid node for translation.
- */
- INVALID_TRANSLATION_NODE("Invalid node for translation"),
-
- /**
- * Represents the missing parent node.
- */
- MISSING_PARENT_NODE("Missing parent node to get current node's java " +
- "information"),
-
- /**
- * Represents the invalid parent node.
- */
- INVALID_PARENT_NODE("Invalid parent node to get current node's java " +
- "information"),
-
- /**
- * Represents the invalid holder of leaf.
- */
- INVALID_LEAF_HOLDER("Invalid holder of leaf"),
-
- /**
- * Represents the invalid child node.
- */
- INVALID_CHILD_NODE("Invalid child of node "),
-
- /**
- * Represents the invalid leaf list without JAVA information.
- */
- INVALID_LEAF_LIST("Leaf-list does not have java information"),
-
- /**
- * Represents the invalid leaf without JAVA information.
- */
- INVALID_LEAF("Leaf does not have java information"),
-
- /**
- * Represents the invalid node without JAVA information.
- */
- INVALID_NODE("Missing java file information to get the package details " +
- "of attribute corresponding to child node"),
-
- /**
- * Represents that code generation failed for a node at exit.
- */
- FAIL_AT_EXIT("Failed to generate code for "),
-
- /**
- * Represents that code generation preparation failed for a node at entry.
- */
- FAIL_AT_ENTRY("Failed to prepare generate code entry for ");
-
- // Prefix of an error type.
- private final String prefix;
-
- /**
- * Creates translator error type.
- *
- * @param p prefix string
- */
- TranslatorErrorType(String p) {
- prefix = p;
- }
-
- /**
- * Returns prefix for a given enum type.
- *
- * @return prefix
- */
- public String prefix() {
- return prefix;
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/TranslatorUtils.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/TranslatorUtils.java
deleted file mode 100644
index f854f99..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/TranslatorUtils.java
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.translator.tojava.utils;
-
-import org.onosproject.yangutils.datamodel.LocationInfo;
-import org.onosproject.yangutils.datamodel.YangNode;
-import org.onosproject.yangutils.datamodel.YangSchemaNode;
-import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo;
-import org.onosproject.yangutils.translator.tojava.TempJavaBeanFragmentFiles;
-import org.onosproject.yangutils.translator.tojava.TempJavaCodeFragmentFilesContainer;
-import org.onosproject.yangutils.translator.tojava.TempJavaTypeFragmentFiles;
-
-import java.io.IOException;
-
-import static org.onosproject.yangutils.utils.UtilConstants.AT;
-import static org.onosproject.yangutils.utils.UtilConstants.IN;
-
-/**
- * Represents common translator utilities.
- */
-public final class TranslatorUtils {
-
- // No instantiation
- private TranslatorUtils() {
- }
-
- /**
- * Returns translator error message string with location information for
- * YANG schema node with localized message.
- *
- * @param errorType type of translator error
- * @param node YANG schema node
- * @param localizedMsg localized message
- * @return translator error message
- */
- public static String getErrorMsg(TranslatorErrorType errorType,
- YangSchemaNode node,
- String localizedMsg) {
- return getErrorMsg(errorType, node) + localizedMsg;
- }
-
- /**
- * Returns translator error message string with location information for
- * YANG schema node.
- *
- * @param errorType type of translator error
- * @param node YANG schema node
- * @return translator error message
- */
- public static String getErrorMsg(TranslatorErrorType errorType,
- YangSchemaNode node) {
- return errorType.prefix() + IN + node.getName() + getLocationMsg(node);
- }
-
- /**
- * Returns translator error message string with location information for
- * JAVA code generator info.
- *
- * @param errorType type of translator error
- * @param location node with location info
- * @return translator error message
- */
- public static String getErrorMsgForCodeGenerator(TranslatorErrorType errorType,
- LocationInfo location) {
- return errorType.prefix() + getLocationMsg(location);
- }
-
- /**
- * Returns location message string.
- *
- * @param location location info node
- * @return location message string
- */
- private static String getLocationMsg(LocationInfo location) {
- return AT + location.getLineNumber() + AT +
- location.getCharPosition() + IN + location.getFileName();
- }
-
- /**
- * Returns bean temp files for YANG node.
- *
- * @param curNode current YANG node
- * @return bean files
- */
- public static TempJavaBeanFragmentFiles getBeanFiles(YangNode curNode) {
- return ((TempJavaCodeFragmentFilesContainer) curNode)
- .getTempJavaCodeFragmentFiles().getBeanTempFiles();
- }
-
- /**
- * Returns bean temp files for JAVA code generator info.
- *
- * @param info JAVA code generator info
- * @return bean files
- */
- public static TempJavaBeanFragmentFiles getBeanFiles(JavaCodeGeneratorInfo
- info) {
- return info.getTempJavaCodeFragmentFiles().getBeanTempFiles();
- }
-
- /**
- * Returns type temp files for YANG node.
- *
- * @param curNode current YANG node
- * @return type files
- */
- public static TempJavaTypeFragmentFiles getTypeFiles(YangNode curNode) {
- return ((TempJavaCodeFragmentFilesContainer) curNode)
- .getTempJavaCodeFragmentFiles().getTypeTempFiles();
- }
-
- /**
- * Adds default constructor to a given YANG node.
- *
- * @param node YANG node
- * @param modifier modifier for constructor.
- * @param toAppend string which need to be appended with the class name
- * @return default constructor for class
- * @throws IOException when fails to append to file
- */
- static String addDefaultConstructor(YangNode node, String modifier,
- String toAppend)
- throws IOException {
- return ((TempJavaCodeFragmentFilesContainer) node)
- .getTempJavaCodeFragmentFiles()
- .addDefaultConstructor(modifier, toAppend);
- /*
- * TODO update addDefaultConstructor, it doesn't need YANG node as an
- * input.
- */
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/ValidatorTypeForUnionTypes.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/ValidatorTypeForUnionTypes.java
deleted file mode 100644
index 9ccceb1..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/ValidatorTypeForUnionTypes.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.translator.tojava.utils;
-
-/**
- * Validator types for union when there is conflict between two types.
- */
-public enum ValidatorTypeForUnionTypes {
-
- /**
- * When conflict is there for int32 and uInt16.
- */
- INT_TYPE_CONFLICT,
-
- /**
- * When conflict is there for int16 and uInt8.
- */
- SHORT_TYPE_CONFLICT,
-
- /**
- * When conflict is there for int64 and uInt32.
- */
- LONG_TYPE_CONFLICT
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/package-info.java b/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/package-info.java
deleted file mode 100644
index 709e704..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/translator/tojava/utils/package-info.java
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * Translator's utils for YANG plugin.
- */
-package org.onosproject.yangutils.translator.tojava.utils;
diff --git a/plugin/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java b/plugin/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
deleted file mode 100644
index 6bfd9a8..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
+++ /dev/null
@@ -1,1854 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.utils;
-
-import java.io.File;
-import java.util.Arrays;
-import java.util.List;
-
-/**
- * Represents utilities constants which are used while generating java files.
- */
-public final class UtilConstants {
-
- /**
- * JavaDocs for impl class.
- */
- public static final String IMPL_CLASS_JAVA_DOC =
- " * Represents the implementation of ";
-
- /**
- * JavaDocs for builder class.
- */
- public static final String BUILDER_CLASS_JAVA_DOC =
- " * Represents the builder implementation of ";
-
- /**
- * JavaDocs for interface class.
- */
- public static final String INTERFACE_JAVA_DOC =
- " * Abstraction of an entity which represents the functionality " +
- "of ";
-
- /**
- * JavaDocs for event.
- */
- public static final String EVENT_JAVA_DOC =
- " * Represents event implementation of ";
-
- /**
- * JavaDocs for op param class.
- */
- public static final String OP_PARAM_JAVA_DOC =
- " * Represents operation parameter implementation of ";
-
- /**
- * JavaDocs for event listener.
- */
- public static final String EVENT_LISTENER_JAVA_DOC =
- " * Abstraction for event listener of ";
-
- /**
- * JavaDocs for builder interface class.
- */
- public static final String BUILDER_INTERFACE_JAVA_DOC = " * Builder for ";
-
- /**
- * JavaDocs for enum class.
- */
- public static final String ENUM_CLASS_JAVADOC =
- " * Represents ENUM data of ";
-
- /**
- * JavaDocs for enum attribute.
- */
- public static final String ENUM_ATTRIBUTE_JAVADOC = " * Represents ";
-
- /**
- * JavaDocs for package info class.
- */
- public static final String PACKAGE_INFO_JAVADOC =
- " * Implementation of YANG node ";
-
- /**
- * JavaDocs for package info class.
- */
- public static final String PACKAGE_INFO_JAVADOC_OF_CHILD =
- "'s children nodes";
-
- /**
- * JavaDocs's first line.
- */
- public static final String JAVA_DOC_FIRST_LINE = "/**\n";
-
- /**
- * JavaDocs's last line.
- */
- public static final String JAVA_DOC_END_LINE = " */\n";
-
- /**
- * JavaDocs's param annotation.
- */
- public static final String JAVA_DOC_PARAM = " * @param ";
-
- /**
- * JavaDocs's return annotation.
- */
- public static final String JAVA_DOC_RETURN = " * @return ";
-
- /**
- * JavaDocs's description for setter method.
- */
- public static final String JAVA_DOC_SETTERS =
- " * Returns the builder object of ";
-
- /**
- * JavaDocs's description for add to list method.
- */
- public static final String JAVA_DOC_ADD_TO_LIST = " * Adds to the list of ";
-
- /**
- * JavaDocs's description for setter method.
- */
- public static final String JAVA_DOC_MANAGER_SETTERS =
- " * Sets the value to attribute ";
-
- /**
- * JavaDocs's description for OF method.
- */
- public static final String JAVA_DOC_OF = " * Returns the object of ";
-
- /**
- * JavaDocs's description for typedef' setter method.
- */
- public static final String JAVA_DOC_SETTERS_COMMON =
- " * Sets the value of ";
-
- /**
- * JavaDocs's description for getter method.
- */
- public static final String JAVA_DOC_GETTERS = " * Returns the attribute ";
-
- /**
- * JavaDocs's description for getter method.
- */
- public static final String JAVA_DOC_FOR_VALIDATOR =
- " * Validates if value is in given range.";
-
- /**
- * JavaDocs's description for getter method.
- */
- public static final String JAVA_DOC_FOR_VALIDATOR_RETURN =
- " true if value is in range";
-
- /**
- * JavaDocs's description for constructor.
- */
- public static final String JAVA_DOC_CONSTRUCTOR =
- " * Creates an instance of ";
-
- /**
- * JavaDocs's description for build method.
- */
- public static final String JAVA_DOC_BUILD = " * Builds object of ";
-
- /**
- * JavaDocs's return statement for build method.
- */
- public static final String JAVA_DOC_BUILD_RETURN = "object of ";
-
- /**
- * JavaDocs's statement for builder object.
- */
- public static final String BUILDER_OBJECT = "builder object of ";
-
- /**
- * JavaDocs's statement for rpc method.
- */
- public static final String JAVA_DOC_RPC = " * Service interface of ";
-
- /**
- * JavaDocs's statement for rpc's input string.
- */
- public static final String RPC_INPUT_STRING = "input of service interface ";
-
- /**
- * JavaDocs's statement for rpc's output string.
- */
- public static final String RPC_OUTPUT_STRING =
- "output of service interface ";
-
- /**
- * Static attribute for new line.
- */
- public static final String NEW_LINE = "\n";
-
- /**
- * Static attribute for default.
- */
- public static final String DEFAULT = "default";
-
- /**
- * Static attribute for default.
- */
- public static final String DEFAULT_CAPS = "Default";
-
- /**
- * Static attribute for java code generation for sbi.
- */
- public static final String SBI = "sbi";
-
- /**
- * Static attribute for multiple new line.
- */
- public static final String MULTIPLE_NEW_LINE = "\n\n";
-
- /**
- * Static attribute for empty line.
- */
- public static final String EMPTY_STRING = "";
-
- /**
- * Static attribute for new line with asterisk.
- */
- public static final String NEW_LINE_ASTERISK = " *\n";
-
- /**
- * Static attribute for period.
- */
- public static final String PERIOD = ".";
-
- /**
- * Static attribute for compare to.
- */
- public static final String COMPARE_TO = "compareTo";
-
- /**
- * Static attribute for period.
- */
- public static final String INVOKE = "invoke";
-
- /**
- * Static attribute for parse byte.
- */
- public static final String PARSE_BYTE = "parseByte";
-
- /**
- * Static attribute for parse boolean.
- */
- public static final String PARSE_BOOLEAN = "parseBoolean";
-
- /**
- * Static attribute for parse short.
- */
- public static final String PARSE_SHORT = "parseShort";
-
- /**
- * Static attribute for parse int.
- */
- public static final String PARSE_INT = "parseInt";
-
- /**
- * Static attribute for parse long.
- */
- public static final String PARSE_LONG = "parseLong";
-
- /**
- * Static attribute for base64.
- */
- public static final String BASE64 = "Base64";
-
- /**
- * Static attribute for getEncoder.
- */
- public static final String GET_ENCODER = "getEncoder";
-
- /**
- * Static attribute for encodeToString.
- */
- public static final String ENCODE_TO_STRING = "encodeToString";
-
- /**
- * Static attribute for getDecoder.
- */
- public static final String GET_DECODER = "getDecoder";
-
- /**
- * Static attribute for decode.
- */
- public static final String DECODE = "decode";
-
- /**
- * Static attribute for omit null value.
- */
- public static final String OMIT_NULL_VALUE_STRING = "omitNullValues()";
-
- /**
- * Static attribute for underscore.
- */
- public static final String UNDER_SCORE = "_";
-
- /**
- * Static attribute for semi-colan.
- */
- public static final String SEMI_COLON = ";";
-
- /**
- * Static attribute for hyphen.
- */
- public static final String HYPHEN = "-";
-
- /**
- * Static attribute for space.
- */
- public static final String SPACE = " ";
-
- /**
- * Static attribute for isSelectAllSchemaChild.
- */
- public static final String SELECT_ALL_CHILD = "isSelectAllSchemaChild";
-
- /**
- * Static attribute for schema name.
- */
- public static final String SCHEMA_NAME = "schemaName";
-
- /**
- * Static attribute for schema name value.
- */
- public static final String STR_VAL = "stringValue";
-
- /**
- * Static attribute for validateRange.
- */
- public static final String VALIDATE_RANGE = "validateRange";
-
- /**
- * Static attribute for minRange.
- */
- public static final String MIN_RANGE = "minRange";
-
- /**
- * Static attribute for maxRange.
- */
- public static final String MAX_RANGE = "maxRange";
-
- /**
- * Static attribute for minRange.
- */
- public static final String SHORT_MIN_RANGE_ATTR =
- "static final int INT16_MIN_RANGE = -32768;\n";
-
- /**
- * Static attribute for minRange.
- */
- public static final String SHORT_MIN_RANGE = "INT16_MIN_RANGE";
-
- /**
- * Static attribute for minRange.
- */
- public static final String SHORT_MAX_RANGE = "INT16_MAX_RANGE";
-
- /**
- * Static attribute for maxRange.
- */
- public static final String SHORT_MAX_RANGE_ATTR =
- "static final int INT16_MAX_RANGE = 32767;";
-
-
- /**
- * Static attribute for minRange.
- */
- public static final String UINT8_MIN_RANGE_ATTR =
- "static final int UINT8_MIN_RANGE = 0;\n";
-
- /**
- * Static attribute for maxRange.
- */
- public static final String UINT8_MAX_RANGE_ATTR =
- "static final int UINT8_MAX_RANGE = 32767;";
-
-
- /**
- * Static attribute for minRange.
- */
- public static final String UINT8_MIN_RANGE = "UINT8_MIN_RANGE";
-
- /**
- * Static attribute for maxRange.
- */
- public static final String UINT8_MAX_RANGE = "UINT8_MAX_RANGE";
-
- /**
- * Static attribute for minRange.
- */
- public static final String INT_MIN_RANGE_ATTR =
- "static final int INT32_MIN_RANGE = -2147483648;\n";
-
- /**
- * Static attribute for minRange.
- */
- public static final String INT_MIN_RANGE = "INT32_MIN_RANGE";
-
- /**
- * Static attribute for minRange.
- */
- public static final String INT_MAX_RANGE = "INT32_MAX_RANGE";
-
- /**
- * Static attribute for maxRange.
- */
- public static final String INT_MAX_RANGE_ATTR =
- "static final int INT32_MAX_RANGE = 2147483647;";
-
-
- /**
- * Static attribute for minRange.
- */
- public static final String UINT_MIN_RANGE_ATTR =
- "static final int UINT16_MIN_RANGE = 0;\n";
-
- /**
- * Static attribute for maxRange.
- */
- public static final String UINT_MAX_RANGE_ATTR =
- "static final int UINT16_MAX_RANGE = 2147483647;";
-
-
- /**
- * Static attribute for minRange.
- */
- public static final String UINT_MIN_RANGE = "UINT16_MIN_RANGE";
-
- /**
- * Static attribute for maxRange.
- */
- public static final String UINT_MAX_RANGE = "UINT16_MAX_RANGE";
-
- /**
- * Static attribute for minRange.
- */
- public static final String LONG_MIN_RANGE_ATTR =
- "static final BigInteger INT64_MIN_RANGE =" +
- " new BigInteger(\"-9223372036854775808\");\n";
-
- /**
- * Static attribute for maxRange.
- */
- public static final String LONG_MAX_RANGE_ATTR =
- "static final BigInteger INT64_MAX_RANGE =" +
- " new BigInteger(\"9223372036854775807\");";
-
- /**
- * Static attribute for minRange.
- */
- public static final String LONG_MIN_RANGE = "INT64_MIN_RANGE";
-
- /**
- * Static attribute for maxRange.
- */
- public static final String LONG_MAX_RANGE = "INT64_MAX_RANGE";
-
- /**
- * Static attribute for minRange.
- */
- public static final String ULONG_MIN_RANGE_ATTR =
- "static final BigInteger UINT32_MIN_RANGE =" +
- " new BigInteger(\"0\");\n";
-
- /**
- * Static attribute for maxRange.
- */
- public static final String ULONG_MAX_RANGE_ATTR =
- "static final BigInteger UINT32_MAX_RANGE =" +
- " new BigInteger(\"9223372036854775807\");";
-
-
- /**
- * Static attribute for minRange.
- */
- public static final String ULONG_MIN_RANGE = "UINT32_MIN_RANGE";
-
- /**
- * Static attribute for maxRange.
- */
- public static final String ULONG_MAX_RANGE = "UINT32_MAX_RANGE";
-
- /**
- * Static attribute for subject.
- */
- public static final String SUBJECT = "Subject";
-
- /**
- * Static attribute for ListenerRegistry.
- */
- public static final String LISTENER_REG = "ListenerRegistry";
-
- /**
- * Static attribute for ListenerService.
- */
- public static final String LISTENER_SERVICE = "ListenerService";
-
- /**
- * Static attribute for listener package.
- */
- public static final String ONOS_EVENT_PKG = "org.onosproject.event";
-
- /**
- * Static attribute for colon.
- */
- public static final String COLON = ":";
-
- /**
- * Static attribute for caret.
- */
- public static final String CARET = "^";
-
- /**
- * Static attribute for input string.
- */
- public static final String INPUT = "input";
-
- /**
- * Static attribute for output string.
- */
- public static final String OUTPUT = "output";
-
- /**
- * Static attribute for current string.
- */
- public static final String CURRENT = "current";
-
- /**
- * Static attribute for leafref string.
- */
- public static final String LEAFREF = "leafref";
-
- /**
- * Static attribute for identityref string.
- */
- public static final String IDENTITYREF = "identityref";
-
- /**
- * Static attribute for output variable of rpc.
- */
- public static final String RPC_INPUT_VAR_NAME = "inputVar";
-
- /**
- * Static attribute for new line.
- */
- public static final String EQUAL = "=";
-
- /**
- * Static attribute for slash syntax.
- */
- public static final String SLASH = File.separator;
-
- /**
- * Static attribute for add syntax.
- */
- public static final String ADD = "+";
-
- /**
- * Static attribute for single quote.
- */
- public static final String SINGLE_QUOTE = "\'";
-
- /**
- * Static attribute for quotes.
- */
- public static final String QUOTES = "\"";
-
- /**
- * Static attribute for zero.
- */
- public static final String ZERO = "0";
-
- /**
- * Static attribute for ampersand.
- */
- public static final String AND = "&";
-
- /**
- * Static attribute for comma.
- */
- public static final String COMMA = ",";
-
- /**
- * Static attribute for class.
- */
- public static final String CLASS_STRING = "Class";
-
- /**
- * Static attribute for put.
- */
- public static final String PUT = "put";
-
- /**
- * Static attribute for get.
- */
- public static final String GET = "get";
-
- /**
- * Static attribute for slash character.
- */
- public static final char CHAR_OF_SLASH = '/';
-
- /**
- * Static attribute for open square bracket character.
- */
- public static final char CHAR_OF_OPEN_SQUARE_BRACKET = '[';
-
- /**
- * Static attribute for close square bracket character.
- */
- public static final char CHAR_OF_CLOSE_SQUARE_BRACKET = ']';
-
- /**
- * Static attribute for slash string.
- */
- public static final String SLASH_FOR_STRING = "/";
-
- /**
- * Static attribute for open square bracket.
- */
- public static final String OPEN_SQUARE_BRACKET = "[";
-
- /**
- * Static attribute for ancestor accessor.
- */
- public static final String ANCESTOR_ACCESSOR = "..";
-
- /**
- * Static attribute for ancestor accessor along with path.
- */
- public static final String ANCESTOR_ACCESSOR_IN_PATH = "../";
-
- /**
- * Static attribute for add syntax.
- */
- public static final String ADD_STRING = "add";
-
- /**
- * Static attribute for string replace syntax.
- */
- public static final String REPLACE_STRING = "replace";
-
- /**
- * Static attribute for string trim syntax.
- */
- public static final String TRIM_STRING = "trim";
-
- /**
- * Static attribute for string split syntax.
- */
- public static final String SPLIT_STRING = "split";
-
- /**
- * Static attribute for Pattern.
- */
- public static final String PATTERN = "Pattern";
-
- /**
- * Static attribute for Quote.
- */
- public static final String QUOTE_STRING = "quote";
-
- /**
- * Static attribute for from syntax.
- */
- public static final String FROM_STRING_METHOD_NAME = "fromString";
-
- /**
- * Static attribute for check not null syntax.
- */
- public static final String CHECK_NOT_NULL_STRING = "checkNotNull";
-
- /**
- * Static attribute for hash code syntax.
- */
- public static final String HASH_CODE_STRING = "hashCode";
-
- /**
- * Static attribute for equals syntax.
- */
- public static final String EQUALS_STRING = "equals";
-
- /**
- * Static attribute for object.
- */
- public static final String OBJECT_STRING = "Object";
-
- /**
- * Static attribute for instance of syntax.
- */
- public static final String INSTANCE_OF = " instanceof ";
-
- /**
- * Static attribute for value syntax.
- */
- public static final String VALUE = "value";
-
- /**
- * Static attribute for suffix s.
- */
- public static final String SUFFIX_S = "s";
-
- /**
- * Static attribute for string builder var.
- */
- public static final String STRING_BUILDER_VAR = "sBuild";
- /**
- * Static attribute for string builder var.
- */
- public static final String APPEND = "append";
-
- /**
- * Static attribute for if.
- */
- public static final String IF = "if";
-
- /**
- * Static attribute for else-if.
- */
- public static final String ELSE_IF = "else if";
-
- /**
- * Static attribute for of.
- */
- public static final String OF = "of";
-
- /**
- * Static attribute for other.
- */
- public static final String OTHER = "other";
-
- /**
- * Static attribute for obj syntax.
- */
- public static final String OBJ = "obj";
-
- /**
- * Static attribute for hash syntax.
- */
- public static final String HASH = "hash";
-
- /**
- * Static attribute for to syntax.
- */
- public static final String TO = "to";
-
- /**
- * Static attribute for to syntax.
- */
- public static final String TO_CAPS = "To";
-
- /**
- * Static attribute for true syntax.
- */
- public static final String TRUE = "true";
-
- /**
- * Static attribute for false syntax.
- */
- public static final String FALSE = "false";
-
- /**
- * Static attribute for org.
- */
- public static final String ORG = "org";
-
- /**
- * Static attribute for temp.
- */
- public static final String TEMP = "Temp";
-
- /**
- * Static attribute for YANG file directory.
- */
- public static final String YANG_RESOURCES = "yang/resources";
-
- /**
- * Static attribute for diamond close bracket syntax.
- */
- public static final String DIAMOND_OPEN_BRACKET = "<";
-
- /**
- * Static attribute for diamond close bracket syntax.
- */
- public static final String DIAMOND_CLOSE_BRACKET = ">";
-
- /**
- * Static attribute for event type.
- */
- public static final String EVENT_TYPE = ".Type";
-
- /**
- * Static attribute for exception syntax.
- */
- public static final String EXCEPTION = "Exception";
-
- /**
- * Static attribute for exception variable syntax.
- */
- public static final String EXCEPTION_VAR = "e";
-
- /**
- * Static attribute for open parenthesis syntax.
- */
- public static final String OPEN_PARENTHESIS = "(";
-
- /**
- * Static attribute for switch syntax.
- */
- public static final String SWITCH = "switch";
-
- /**
- * Static attribute for case syntax.
- */
- public static final String CASE = "case";
-
- /**
- * Static attribute for temp val syntax.
- */
- public static final String TMP_VAL = "tmpVal";
-
- /**
- * Static attribute for close curly bracket syntax.
- */
- public static final String ELSE = "else";
-
- /**
- * From string parameter name.
- */
- public static final String FROM_STRING_PARAM_NAME = "valInString";
-
- /**
- * Static attribute for close parenthesis syntax.
- */
- public static final String CLOSE_PARENTHESIS = ")";
-
- /**
- * Static attribute for empty parameter function call.
- */
- public static final String OPEN_CLOSE_BRACKET_STRING = "()";
-
- /**
- * Static attribute for open curly bracket syntax.
- */
- public static final String OPEN_CURLY_BRACKET = "{";
-
- /**
- * Static attribute for close curly bracket syntax.
- */
- public static final String CLOSE_CURLY_BRACKET = "}";
-
- /**
- * Static attribute for square brackets syntax.
- */
- public static final String SQUARE_BRACKETS = "[]";
-
- /**
- * Static attribute for getter method prefix.
- */
- public static final String GET_METHOD_PREFIX = "get";
-
- /**
- * Static attribute for getter method prefix.
- */
- public static final String GET_METHOD = "getMethod";
-
- /**
- * Static attribute for getter method prefix.
- */
- public static final String GET_CLASS = "getClass()";
-
- /**
- * Static attribute for setter method prefix.
- */
- public static final String SET_METHOD_PREFIX = "set";
-
- /**
- * Static attribute for get filter leaf flags.
- */
- public static final String GET_VALUE_LEAF_FLAGS = "getValueLeafFlags";
-
- /**
- * Static attribute for get select filter leaf flags.
- */
- public static final String GET_SELECT_LEAF_FLAGS = "getSelectLeafFlags";
-
-
- /**
- * Static attribute for getLeafIndex.
- */
- public static final String GET_LEAF_INDEX = "getLeafIndex()";
-
- /**
- * Static attribute for op param.
- */
- public static final String OP_PARAM = "OpParam";
-
-
- /**
- * Static attribute for is filter content match method prefix.
- */
- public static final String PROCESS_SUBTREE_FILTERING =
- "processSubtreeFiltering";
-
- /**
- * variable name of the subtree filtering result builder.
- */
- public static final String SUBTREE_FILTERING_RESULT_BUILDER =
- "subTreeFilteringResultBuilder";
-
- /**
- * variable name of the subtree filtering result flag.
- */
- public static final String IS_ANY_SELECT_OR_CONTAINMENT_NODE_FLAG =
- "isAnySelectOrContainmentNode";
-
- /**
- * variable name of the subtree filtering to select all child.
- */
- public static final String IS_SELECT_ALL_SCHEMA_CHILD_FLAG =
- "isSelectAllSchemaChild";
-
- /**
- * Static attribute for break prefix.
- */
- public static final String BREAK = "break";
-
- /**
- * Static attribute for break prefix.
- */
- public static final String IS_EMPTY = "isEmpty()";
-
- /**
- * Static attribute for is isLeafValueSet method prefix.
- */
- public static final String VALUE_LEAF_SET = "isLeafValueSet";
-
- /**
- * Static attribute for is isSelectLeaf method prefix.
- */
- public static final String IS_SELECT_LEAF = "isSelectLeaf";
-
- /**
- * Static attribute for is selectLeaf method prefix.
- */
- public static final String SET_SELECT_LEAF = "selectLeaf";
-
- /**
- * Static attribute for is LeafIdentifier enum prefix.
- */
- public static final String LEAF_IDENTIFIER = "LeafIdentifier";
- /**
- * Static attribute for is leaf.
- */
- public static final String LEAF = "leaf";
-
- /**
- * Static attribute for four space indentation.
- */
- public static final String FOUR_SPACE_INDENTATION = " ";
-
- /**
- * Static attribute for not syntax.
- */
- public static final String NOT = "!";
-
- /**
- * Static attribute for try syntax.
- */
- public static final String TRY = "try";
-
- /**
- * Static attribute for catch syntax.
- */
- public static final String CATCH = "catch";
-
- /**
- * Static attribute for eight space indentation.
- */
- public static final String EIGHT_SPACE_INDENTATION =
- FOUR_SPACE_INDENTATION + FOUR_SPACE_INDENTATION;
-
- /**
- * Static attribute for twelve space indentation.
- */
- public static final String TWELVE_SPACE_INDENTATION =
- EIGHT_SPACE_INDENTATION + FOUR_SPACE_INDENTATION;
-
- /**
- * Static attribute for sixteen space indentation.
- */
- public static final String SIXTEEN_SPACE_INDENTATION =
- TWELVE_SPACE_INDENTATION + FOUR_SPACE_INDENTATION;
-
- /**
- * Static attribute for twenty space indentation.
- */
- public static final String TWENTY_SPACE_INDENTATION =
- SIXTEEN_SPACE_INDENTATION + FOUR_SPACE_INDENTATION;
-
- /**
- * Static attribute for twenty four space indentation.
- */
- public static final String TWENTY_FOUR_SPACE_INDENTATION =
- TWENTY_SPACE_INDENTATION + FOUR_SPACE_INDENTATION;
-
- /**
- * Static attribute for twenty eight space indentation.
- */
- public static final String TWENTY_EIGHT_SPACE_INDENTATION =
- TWENTY_FOUR_SPACE_INDENTATION + FOUR_SPACE_INDENTATION;
-
- /**
- * Static attribute for thirty two space indentation.
- */
- public static final String THIRTY_TWO_SPACE_INDENTATION =
- TWENTY_EIGHT_SPACE_INDENTATION + FOUR_SPACE_INDENTATION;
-
- /**
- * continue.
- */
- public static final String CONTINUE = "continue";
-
- /**
- * Static attribute for generated code path.
- */
- public static final String YANG_GEN_DIR = "src/main/java/";
-
- /**
- * Static attribute for base package.
- */
- public static final String DEFAULT_BASE_PKG = "org.onosproject.yang.gen";
-
- /**
- * Static attribute for YANG date prefix.
- */
- public static final String REVISION_PREFIX = "rev";
-
- /**
- * Static attribute for YANG automatic prefix for identifiers with keywords
- * and beginning with digits.
- */
- public static final String YANG_AUTO_PREFIX = "yangAutoPrefix";
-
- /**
- * Static attribute for YANG version prefix.
- */
- public static final String VERSION_PREFIX = "v";
-
- /**
- * Static attribute for private modifier.
- */
- public static final String PRIVATE = "private";
-
- /**
- * Static attribute for public modifier.
- */
- public static final String PUBLIC = "public";
-
- /**
- * Static attribute for abstract modifier.
- */
- public static final String ABSTRACT = "abstract";
-
- /**
- * Static attribute for protected modifier.
- */
- public static final String PROTECTED = "protected";
-
- /**
- * Void java type.
- */
- public static final String VOID = "void";
-
- /**
- * String built in java type.
- */
- public static final String STRING_DATA_TYPE = "String";
-
- /**
- * String built in java type.
- */
- public static final String STRING_BUILDER = "StringBuilder";
- /**
- * Java.lang.* packages.
- */
- public static final String JAVA_LANG = "java.lang";
-
- /**
- * Java.math.* packages.
- */
- public static final String JAVA_MATH = "java.math";
-
- /**
- * Boolean built in java type.
- */
- public static final String BOOLEAN_DATA_TYPE = "boolean";
-
- /**
- * BigInteger built in java type.
- */
- public static final String BIG_INTEGER = "BigInteger";
-
- /**
- * BigDecimal built in java type.
- */
- public static final String BIG_DECIMAL = "BigDecimal";
-
- /**
- * BitSet built in java type.
- */
- public static final String BIT_SET = "BitSet";
-
- /**
- * Byte java built in type.
- */
- public static final String BYTE = "byte";
-
- /**
- * Short java built in type.
- */
- public static final String SHORT = "short";
-
- /**
- * Int java built in type.
- */
- public static final String INT = "int";
-
- /**
- * Long java built in type.
- */
- public static final String LONG = "long";
-
- /**
- * Double java built in type.
- */
- public static final String DOUBLE = "double";
-
- /**
- * Boolean built in java wrapper type.
- */
- public static final String BOOLEAN_WRAPPER = "Boolean";
-
- /**
- * Byte java built in wrapper type.
- */
- public static final String BYTE_WRAPPER = "Byte";
-
- /**
- * Short java built in wrapper type.
- */
- public static final String SHORT_WRAPPER = "Short";
-
- /**
- * Integer java built in wrapper type.
- */
- public static final String INTEGER_WRAPPER = "Integer";
-
- /**
- * Long java built in wrapper type.
- */
- public static final String LONG_WRAPPER = "Long";
-
- /**
- * Static variable for question mark.
- */
- public static final String QUESTION_MARK = "?";
-
- /**
- * Static variable for forType string.
- */
- public static final String FOR_TYPE_STRING = " for type ";
-
- /**
- * List of keywords in java, this is used for checking if the input does not
- * contain these keywords.
- */
- public static final List<String> JAVA_KEY_WORDS =
- Arrays.asList("abstract", "assert", "boolean", "break", "byte",
- "case", "catch", "char", "class", "const", "continue",
- "default", "do", "double", "else", "extends", "false",
- "final", "finally", "float", "for", "goto", "if",
- "implements", "import", "instanceof", "enum", "int",
- "interface", "long", "native", "new", "null",
- "package", "private", "protected", "public", "return",
- "short", "static", "strictfp", "super", "switch",
- "synchronized", "this", "throw", "throws", "transient",
- "true", "try", "void", "volatile", "while");
-
- /**
- * Static attribute for regex for all the special characters.
- */
- public static final String REGEX_WITH_ALL_SPECIAL_CHAR = "\\p{Punct}+";
-
- /**
- * Static attribute for regex for three special characters used in
- * identifier.
- */
- public static final String REGEX_FOR_IDENTIFIER_SPECIAL_CHAR = "[. _ -]+";
-
- /**
- * Static attribute for regex for period.
- */
- public static final String REGEX_FOR_PERIOD = "[.]";
-
- /**
- * Static attribute for regex for underscore.
- */
- public static final String REGEX_FOR_UNDERSCORE = "[_]";
-
- /**
- * Static attribute for regex for hyphen.
- */
- public static final String REGEX_FOR_HYPHEN = "[-]";
-
- /**
- * Static attribute for regex for digits.
- */
- public static final String REGEX_FOR_FIRST_DIGIT = "\\d.*";
-
- /**
- * Static attribute for regex with digits.
- */
- public static final String REGEX_WITH_DIGITS = "(?=\\d+)";
-
- /**
- * Static attribute for regex for single letter.
- */
- public static final String REGEX_FOR_SINGLE_LETTER = "[a-zA-Z]";
-
- /**
- * Static attribute for regex for digits with single letter.
- */
- public static final String REGEX_FOR_DIGITS_WITH_SINGLE_LETTER =
- "[0-9]+[a-zA-Z]";
-
- /**
- * Static attribute for regex with uppercase.
- */
- public static final String REGEX_WITH_UPPERCASE = "(?=\\p{Upper})";
-
- /**
- * Static attribute for regex for single capital case letter.
- */
- public static final String REGEX_WITH_SINGLE_CAPITAL_CASE = "[A-Z]";
-
- /**
- * Static attribute for regex for capital case letter with any number of
- * digits and small case letters.
- */
- public static final String
- REGEX_WITH_SINGLE_CAPITAL_CASE_AND_DIGITS_SMALL_CASES =
- "[A-Z][0-9a-z]+";
-
- /**
- * Static attribute for regex for any string ending with service.
- */
- public static final String REGEX_FOR_ANY_STRING_ENDING_WITH_SERVICE =
- ".+Service";
-
- /**
- * Static attribute for class syntax.
- */
- public static final String CLASS = "class";
-
- /**
- * Static attribute for builder syntax.
- */
- public static final String BUILDER = "Builder";
-
- /**
- * Static attribute for builder syntax.
- */
- public static final String BUILDER_LOWER_CASE = "builder";
-
- /**
- * Static attribute for manager syntax.
- */
- public static final String MANAGER = "Manager";
-
- /**
- * Static attribute for service syntax.
- */
- public static final String SERVICE = "Service";
-
- /**
- * Static attribute for interface syntax.
- */
- public static final String INTERFACE = "interface";
-
- /**
- * Static attribute for enum syntax.
- */
- public static final String ENUM = "enum";
-
- /**
- * Static attribute for type syntax.
- */
- public static final String TYPE = "Type";
-
- /**
- * Static attribute for static syntax.
- */
- public static final String STATIC = "static";
-
- /**
- * Static attribute for final syntax.
- */
- public static final String FINAL = "final";
-
- /**
- * Static attribute for package syntax.
- */
- public static final String PACKAGE = "package";
-
- /**
- * Static attribute for import syntax.
- */
- public static final String IMPORT = "import ";
-
- /**
- * Static attribute for null syntax.
- */
- public static final String NULL = "null";
-
- /**
- * Static attribute for return syntax.
- */
- public static final String RETURN = "return";
-
- /**
- * Static attribute for java new syntax.
- */
- public static final String NEW = "new";
-
- /**
- * Static attribute for java new syntax.
- */
- public static final String TO_STRING_METHOD = "toString";
-
- /**
- * Static attribute for this syntax.
- */
- public static final String THIS = "this";
-
- /**
- * Static attribute for implements syntax.
- */
- public static final String IMPLEMENTS = "implements";
-
- /**
- * Static attribute for extends syntax.
- */
- public static final String EXTEND = "extends";
-
- /**
- * Static attribute for service interface suffix syntax.
- */
- public static final String SERVICE_METHOD_STRING = "Service";
-
- /**
- * For event file generation.
- */
- public static final String EVENT_STRING = "Event";
-
- /**
- * For event listener file generation.
- */
- public static final String EVENT_LISTENER_STRING = "EventListener";
-
- /**
- * For event subject file generation.
- */
- public static final String EVENT_SUBJECT_NAME_SUFFIX = "EventSubject";
-
- /**
- * Static attribute for build method syntax.
- */
- public static final String BUILD = "build";
-
- /**
- * Static attribute for object.
- */
- public static final String OBJECT = "Object";
-
- /**
- * Static attribute for app instance.
- */
- public static final String APP_INSTANCE = "appInstance";
-
- /**
- * Static attribute for instance.
- */
- public static final String INSTANCE = "instance";
-
- /**
- * Static attribute for override annotation.
- */
- public static final String OVERRIDE = "@Override";
-
- /**
- * Static attribute for collections.
- */
- public static final String COLLECTION_IMPORTS = "java.util";
-
- /**
- * Static attribute for regex.
- */
- public static final String REGEX_IMPORTS = "java.util.regex";
-
- /**
- * Static attribute for map.
- */
- public static final String MAP = "Map";
-
- /**
- * Static attribute for hash map.
- */
- public static final String HASH_MAP = "HashMap";
-
-
- /**
- * Static attribute for more object import package.
- */
- public static final String GOOGLE_MORE_OBJECT_IMPORT_PKG =
- "com.google.common.base";
-
- /**
- * Static attribute for more object import class.
- */
- public static final String GOOGLE_MORE_OBJECT_IMPORT_CLASS =
- "MoreObjects";
-
- /**
- * Static attribute for more object import class.
- */
- public static final String MORE_OBJ_ATTR =
- "MoreObjects.ToStringHelper helper = ";
-
- /**
- * Static attribute for to string method.
- */
- public static final String GOOGLE_MORE_OBJECT_METHOD_STRING =
- "MoreObjects.toStringHelper(getClass())";
-
- /**
- * Static attribute for java utilities import package.
- */
- public static final String JAVA_UTIL_PKG = "java.util";
-
- /**
- * Static attribute for java utilities import package.
- */
- public static final String JAVA_UTIL_REGEX_PKG = "java.util.regex";
-
- /**
- * Static attribute for java utilities import package.
- */
- public static final String SET_VALUE_PARA = "setValue";
-
- /**
- * Static attribute for java utilities import package.
- */
- public static final String HELPER = "helper";
-
- /**
- * Static attribute for bitset.
- */
- public static final String BITSET = "BitSet";
-
- /**
- * Static attribute for java utilities objects import class.
- */
- public static final String JAVA_UTIL_OBJECTS_IMPORT_CLASS = "Objects";
-
- /**
- * Static attribute for AugmentedInfo class.
- */
- public static final String YANG_AUGMENTED_INFO = "YangAugmentedInfo";
-
- /**
- * Static attribute for AugmentedInfo class.
- */
- public static final String YANG_AUGMENTED_INFO_LOWER_CASE =
- "yangAugmentedInfo";
-
- /**
- * Static attribute for augmented.
- */
- public static final String AUGMENTED = "Augmented";
-
- /**
- * Static attribute for list.
- */
- public static final String LIST = "List";
-
- /**
- * Static attribute for queue.
- */
- public static final String QUEUE = "Queue";
-
- /**
- * Static attribute for set.
- */
- public static final String SET = "Set";
-
- /**
- * Comment to be added for autogenerated impl methods.
- */
- public static final String YANG_UTILS_TODO =
- "//TODO: YANG utils generated code";
-
- /**
- * Static attribute for AbstractEvent.
- */
- public static final String ABSTRACT_EVENT = "AbstractEvent";
-
- /**
- * Static attribute for EventListener.
- */
- public static final String EVENT_LISTENER = "EventListener";
-
- /**
- * Static attribute for or operator.
- */
- public static final String OR_OPERATION = "||";
-
- /**
- * Static attribute for or operator.
- */
- public static final String AND_OPERATION = "&&";
-
- /**
- * Static attribute for YANG file error.
- */
- public static final String YANG_FILE_ERROR = "YANG file error : ";
-
- /**
- * Static attribute for unsupported error information.
- */
- public static final String UNSUPPORTED_YANG_CONSTRUCT =
- " is not supported.";
-
- /**
- * Static attribute for "is invalid" information.
- */
- public static final String IS_INVALID = " is invalid.";
-
- /**
- * Static attribute for data model tree error information.
- */
- public static final String INVALID_TREE = "Internal datamodel error: " +
- "Datamodel tree is not correct";
-
- /**
- * Static attribute for currently unsupported error information.
- */
- public static final String CURRENTLY_UNSUPPORTED =
- " is not supported in current version, please check wiki" +
- " for YANG utils road map.";
-
- /**
- * Static attribute for leaf ref target node error information.
- */
- public static final String LEAFREF_ERROR = "YANG file error: The target" +
- " node, in the leafref path ";
-
- /**
- * Static attribute for leaf holder error information.
- */
- public static final String LEAF_HOLDER_ERROR = "Referred node should be of" +
- " type leaves holder in ";
-
- /**
- * Static attribute for invalid resolve entity error information.
- */
- public static final String INVALID_RESOLVED_ENTITY = "Data Model " +
- "Exception: Entity to resolved is other than type/uses";
-
- /**
- * Static attribute for invalid resolve entity error information.
- */
- public static final String INVALID_ENTITY = "Data Model Exception: Entity " +
- "to resolved is other than identityref";
-
- /**
- * Static attribute for invalid state error information.
- */
- public static final String INVALID_LINKER_STATE = "Data Model Exception: " +
- "Unsupported, linker state";
-
- /**
- * Static attribute for leaf ref resolve entity error information.
- */
- public static final String FAILED_TO_FIND_LEAD_INFO_HOLDER = "YANG file " +
- "error: Unable to find base leaf/leaf-list for given leafref path ";
-
- /**
- * Static attribute for compiler annotation resolve entity error
- * information.
- */
- public static final String FAILED_TO_FIND_ANNOTATION = "Failed to link " +
- "compiler annotation ";
-
- /**
- * Static attribute for failed to link entity error information.
- */
- public static final String FAILED_TO_LINK = "Failed to link ";
-
- /**
- * Static attribute for un-resolve entity error information.
- */
- public static final String UNRESOLVABLE = "Data Model Exception: Entity " +
- "to resolved is not Resolvable";
-
- /**
- * Static attribute for invalid resolve entity error information.
- */
- public static final String LINKER_ERROR = "Data Model Exception: Entity" +
- " to resolved is other than type/uses/if-feature/leafref/base/identityref";
-
- /**
- * Static attribute for invalid resolve entity error information.
- */
- public static final String INVALID_TARGET = "Invalid target node type ";
- /**
- * Static attribute for typedef linker error information.
- */
- public static final String TYPEDEF_LINKER_ERROR =
- "YANG file error: Unable to find base typedef for given type";
-
- /**
- * Static attribute for grouping linker error information.
- */
- public static final String GROUPING_LINKER_ERROR =
- "YANG file error: Unable to find base grouping for given uses";
-
- /**
- * Static attribute for if-feature linker error information.
- */
- public static final String FEATURE_LINKER_ERROR =
- "YANG file error: Unable to find feature for given if-feature";
-
- /**
- * Static attribute for leafref linker error information.
- */
- public static final String LEAFREF_LINKER_ERROR =
- "YANG file error: Unable to find base leaf/leaf-list for given " +
- "leafref";
-
- /**
- * Static attribute for base linker error information.
- */
- public static final String BASE_LINKER_ERROR =
- "YANG file error: Unable to find base identity for given base";
-
- /**
- * Static attribute for identityref linker error information.
- */
- public static final String IDENTITYREF_LINKER_ERROR =
- "YANG file error: Unable to find base identity for given base";
-
- /**
- * Static attribute for jar.
- */
- public static final String JAR = "jar";
-
- /**
- * Static attribute for for.
- */
- public static final String FOR = "for";
-
- /**
- * Static attribute for YangAugmentedOpParamInfo.
- */
- public static final String YANG_AUGMENTED_OP_PARAM_INFO =
- "YangAugmentedOpParamInfo";
-
- /**
- * Static attribute for NoSuchMethodException.
- */
- public static final String NO_SUCH_METHOD_EXCEPTION =
- "NoSuchMethodException";
-
- /**
- * Static attribute for InvocationTargetException.
- */
- public static final String INVOCATION_TARGET_EXCEPTION =
- "InvocationTargetException";
-
- /**
- * Static attribute for InvocationTargetException.
- */
- public static final String INVOCATION_TARGET_EXCEPTION_IMPORT = "import" +
- " java.lang.reflect.InvocationTargetException;\n";
- /**
- * Static attribute for IllegalAccessException.
- */
- public static final String ILLEGAL_ACCESS_EXCEPTION =
- "IllegalAccessException";
-
- /**
- * Static attribute for arrayList.
- */
- public static final String ARRAY_LIST = "ArrayList<>()";
-
- /**
- * Static attribute for arrayList import.
- */
- public static final String ARRAY_LIST_IMPORT =
- IMPORT + COLLECTION_IMPORTS + ".ArrayList;\n";
-
- /**
- * Static attribute for unused keyword.
- */
- public static final String UNUSED = "UNUSED";
-
- /**
- * Static attribute for 1 keyword.
- */
- public static final String ONE = "1";
-
- /**
- * Static attribute for YANG node operation type class.
- */
- public static final String OPERATION_TYPE_CLASS =
- "OnosYangNodeOperationType";
-
- /**
- * Static attribute for YANG node operation type attribute.
- */
- public static final String OPERATION_TYPE_ATTRIBUTE =
- "OpType";
-
- /**
- * Static attribute for input keyword to be suffixed with rpc name.
- */
- public static final String INPUT_KEYWORD = "_input";
-
- /**
- * Static attribute for output keyword to be suffixed with rpc name.
- */
- public static final String OUTPUT_KEYWORD = "_output";
-
- /**
- * Static attribute for event class.
- */
- public static final String EVENT_CLASS = "event class";
-
- /**
- * Static attribute for typedef class.
- */
- public static final String TYPEDEF_CLASS = "typedef class";
-
- /**
- * Static attribute for impl class.
- */
- public static final String IMPL_CLASS = "impl class";
-
- /**
- * Static attribute for union class.
- */
- public static final String UNION_CLASS = "union class";
-
- /**
- * Static attribute for enum class.
- */
- public static final String ENUM_CLASS = "enum class";
-
- /**
- * Static attribute for rpc class.
- */
- public static final String RPC_CLASS = "rpc class";
-
- /**
- * Static attribute for builder class.
- */
- public static final String BUILDER_CLASS = "builder class";
-
- /**
- * Static attribute for builder interface.
- */
- public static final String BUILDER_INTERFACE = "builder interface";
-
- /**
- * Static attribute for binary.
- */
- public static final String BINARY = "binary";
-
- /**
- * Static attribute for bits.
- */
- public static final String BITS = "bits";
-
- /**
- * Static attribute for bits.
- */
- public static final String BITS_CAPS = "Bits";
-
- /**
- * Static attribute for YANG.
- */
- public static final String YANG = "yang";
-
- /**
- * Static attribute for error msg.
- */
- public static final String ERROR_MSG_FOR_GEN_CODE = "please check whether " +
- "multiple yang" + " files has same module/submodule" +
- " \"name\" and \"namespace\"" + "or You may have generated code of" +
- " previous build present in your directory.";
-
- /**
- * Static attribute for error msg.
- */
- public static final String ERROR_MSG_JAVA_IDENTITY = "Expected java " +
- "identity instance node ";
- /**
- * Static attribute for in.
- */
- public static final String IN = " in ";
-
- /**
- * Static attribute for at.
- */
- public static final String AT = " at ";
-
- // No instantiation.
- private UtilConstants() {
- }
-
- /**
- * Represents operation type.
- */
- public enum Operation {
- /**
- * Represents add operation.
- */
- ADD,
-
- /**
- * Represents remove operation.
- */
- REMOVE
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/utils/io/YangPluginConfig.java b/plugin/src/main/java/org/onosproject/yangutils/utils/io/YangPluginConfig.java
deleted file mode 100644
index e212832..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/utils/io/YangPluginConfig.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.utils.io;
-
-/**
- * Representation of plugin configurations required for YANG utils.
- */
-public final class YangPluginConfig {
-
- /**
- * Contains the code generation directory.
- */
- private String codeGenDir;
-
- /**
- * Contains information of naming conflicts that can be resolved.
- */
- private YangToJavaNamingConflictUtil conflictResolver;
-
- /**
- * Java code generation is for sbi.
- */
- private String codeGenerateForSbi;
-
- /**
- * Creates an object for YANG plugin config.
- */
- public YangPluginConfig() {
- }
-
- /**
- * Returns the string for code generation.
- *
- * @return returns the string for code generation.
- */
- public String getCodeGenerateForSbi() {
- return codeGenerateForSbi;
- }
-
- /**
- * Sets the string sbi or nbi for code generation.
- *
- * @param codeGenerateForSbi generation is for sbi
- */
- public void setCodeGenerateForSbi(String codeGenerateForSbi) {
- this.codeGenerateForSbi = codeGenerateForSbi;
- }
-
- /**
- * Sets the path of the java code where it has to be generated.
- *
- * @param codeGenDir path of the directory
- */
- public void setCodeGenDir(String codeGenDir) {
- this.codeGenDir = codeGenDir;
- }
-
- /**
- * Returns the code generation directory path.
- *
- * @return code generation directory
- */
- public String getCodeGenDir() {
- return codeGenDir;
- }
-
- /**
- * Sets the object.
- *
- * @param conflictResolver object of the class
- */
- public void setConflictResolver(YangToJavaNamingConflictUtil conflictResolver) {
- this.conflictResolver = conflictResolver;
- }
-
- /**
- * Returns the object.
- *
- * @return object of the class
- */
- public YangToJavaNamingConflictUtil getConflictResolver() {
- return conflictResolver;
- }
-
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/utils/io/YangToJavaNamingConflictUtil.java b/plugin/src/main/java/org/onosproject/yangutils/utils/io/YangToJavaNamingConflictUtil.java
deleted file mode 100644
index 4ae6b0d..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/utils/io/YangToJavaNamingConflictUtil.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.utils.io;
-
-/**
- * Representation of YANG to java naming conflict resolver util.
- */
-public final class YangToJavaNamingConflictUtil {
-
- /**
- * Contains the replacement value for a period.
- */
- private String replacementForPeriodInIdentifier;
-
- /**
- * Contains the replacement value for an underscore.
- */
- private String replacementForUnderscoreInIdentifier;
-
- /**
- * Contains the replacement value for a hyphen.
- */
- private String replacementForHyphenInIdentifier;
-
- /**
- * Contains the prefix value for adding with the identifier.
- */
- private String prefixForIdentifier;
-
- /**
- * Creates an object for YANG to java naming conflict util.
- */
- public YangToJavaNamingConflictUtil() {
- }
-
- /**
- * Sets the replacement value for a period.
- *
- * @param periodReplacement replacement value for period
- */
- public void setReplacementForPeriod(String periodReplacement) {
- replacementForPeriodInIdentifier = periodReplacement;
- }
-
- /**
- * Returns the replaced period value.
- *
- * @return replaced period
- */
- public String getReplacementForPeriod() {
- return replacementForPeriodInIdentifier;
- }
-
- /**
- * Sets the replacement value for a hyphen.
- *
- * @param hyphenReplacement replacement value for hyphen
- */
- public void setReplacementForHyphen(String hyphenReplacement) {
- replacementForHyphenInIdentifier = hyphenReplacement;
- }
-
- /**
- * Returns the replaced hyphen value.
- *
- * @return replaced hyphen
- */
- public String getReplacementForHyphen() {
- return replacementForHyphenInIdentifier;
- }
-
- /**
- * Sets the replacement value for an underscore.
- *
- * @param underscoreReplacement replacement value for underscore
- */
- public void setReplacementForUnderscore(String underscoreReplacement) {
- replacementForUnderscoreInIdentifier = underscoreReplacement;
- }
-
- /**
- * Returns the replaced underscore value.
- *
- * @return replaced underscore
- */
- public String getReplacementForUnderscore() {
- return replacementForUnderscoreInIdentifier;
- }
-
- /**
- * Sets the prefix value for adding with the identifier.
- *
- * @param prefix prefix for identifier
- */
- public void setPrefixForIdentifier(String prefix) {
- prefixForIdentifier = prefix;
- }
-
- /**
- * Returns the prefix for identifier.
- *
- * @return prefix for identifier
- */
- public String getPrefixForIdentifier() {
- return prefixForIdentifier;
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/utils/io/impl/CopyrightHeader.java b/plugin/src/main/java/org/onosproject/yangutils/utils/io/impl/CopyrightHeader.java
deleted file mode 100644
index 5833de2..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/utils/io/impl/CopyrightHeader.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.utils.io.impl;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.Calendar;
-
-import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
-
-/**
- * Represents the license header for the generated files.
- */
-public final class CopyrightHeader {
-
- private static final int EOF = -1;
- private static final String COPYRIGHT_HEADER_FILE = "CopyrightHeader.txt";
- private static final String COPYRIGHTS_FIRST_LINE = "/*\n * Copyright " + Calendar.getInstance().get(Calendar.YEAR)
- + "-present Open Networking Laboratory\n";
- private static final String TEMP_FILE = "temp.txt";
- private static ClassLoader classLoader = CopyrightHeader.class.getClassLoader();
-
- private static String copyrightHeader;
-
- /**
- * Creates an instance of copyright header.
- */
- private CopyrightHeader() {
- }
-
- /**
- * Returns copyright file header.
- *
- * @return copyright file header
- * @throws IOException when fails to parse copyright header
- */
- public static String getCopyrightHeader() throws IOException {
-
- if (copyrightHeader == null) {
- parseCopyrightHeader();
- }
- return copyrightHeader;
- }
-
- /**
- * Sets the copyright header.
- *
- * @param header copyright header
- */
- private static void setCopyrightHeader(String header) {
-
- copyrightHeader = header;
- }
-
- /**
- * parses Copyright to the temporary file.
- *
- * @throws IOException when fails to get the copyright header
- */
- private static void parseCopyrightHeader() throws IOException {
-
- File temp = new File(TEMP_FILE);
-
- try {
- InputStream stream = classLoader.getResourceAsStream(COPYRIGHT_HEADER_FILE);
- OutputStream out = new FileOutputStream(temp);
-
- int index;
- out.write(COPYRIGHTS_FIRST_LINE.getBytes());
- while ((index = stream.read()) != EOF) {
- out.write(index);
- }
- out.close();
- stream.close();
- getStringFileContent(temp);
- setCopyrightHeader(getStringFileContent(temp));
- } catch (IOException e) {
- throw new IOException("failed to parse the Copyright header");
- } finally {
- temp.delete();
- }
- }
-
- /**
- * Converts it to string.
- *
- * @param toAppend file to be converted.
- * @return string of file.
- * @throws IOException when fails to convert to string
- */
- private static String getStringFileContent(File toAppend) throws IOException {
-
- FileReader fileReader = new FileReader(toAppend);
- BufferedReader bufferReader = new BufferedReader(fileReader);
- try {
- StringBuilder stringBuilder = new StringBuilder();
- String line = bufferReader.readLine();
-
- while (line != null) {
- stringBuilder.append(line);
- stringBuilder.append(NEW_LINE);
- line = bufferReader.readLine();
- }
- return stringBuilder.toString();
- } finally {
- fileReader.close();
- bufferReader.close();
- }
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/utils/io/impl/FileSystemUtil.java b/plugin/src/main/java/org/onosproject/yangutils/utils/io/impl/FileSystemUtil.java
deleted file mode 100644
index cc721ed..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/utils/io/impl/FileSystemUtil.java
+++ /dev/null
@@ -1,170 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.utils.io.impl;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.util.ArrayList;
-import java.util.List;
-
-import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION;
-import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
-import static org.onosproject.yangutils.utils.UtilConstants.MULTIPLE_NEW_LINE;
-import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
-import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
-
-/**
- * Represents utility to handle file system operations.
- */
-public final class FileSystemUtil {
-
- /**
- * Creates an instance of file system util.
- */
- private FileSystemUtil() {
- }
-
- /**
- * Reads the contents from source file and append its contents to append file.
- *
- * @param toAppend destination file in which the contents of source file is appended
- * @param srcFile source file from which data is read and added to to append file
- * @throws IOException any IO errors
- */
- static void appendFileContents(File toAppend, File srcFile)
- throws IOException {
- updateFileHandle(srcFile, readAppendFile(toAppend.toString(),
- FOUR_SPACE_INDENTATION), false);
- }
-
- /**
- * Reads file and convert it to string.
- *
- * @param toAppend file to be converted
- * @param spaces spaces to be appended
- * @return string of file
- * @throws IOException when fails to convert to string
- */
- public static String readAppendFile(String toAppend, String spaces)
- throws IOException {
-
- FileReader fileReader = new FileReader(toAppend);
- BufferedReader bufferReader = new BufferedReader(fileReader);
- try {
- StringBuilder stringBuilder = new StringBuilder();
- String line = bufferReader.readLine();
-
- while (line != null) {
- switch (line) {
- case SPACE:
- case EMPTY_STRING:
- case EIGHT_SPACE_INDENTATION:
- case MULTIPLE_NEW_LINE:
- stringBuilder.append(NEW_LINE);
- break;
- case FOUR_SPACE_INDENTATION:
- stringBuilder.append(EMPTY_STRING);
- break;
- default:
- String append = spaces + line;
- stringBuilder.append(append);
- stringBuilder.append(NEW_LINE);
- break;
- }
- line = bufferReader.readLine();
- }
- return stringBuilder.toString();
- } finally {
- fileReader.close();
- bufferReader.close();
- }
- }
-
- /**
- * Updates the generated file handle.
- *
- * @param inputFile input file
- * @param contentTobeAdded content to be appended to the file
- * @param isClose when close of file is called.
- * @throws IOException if the named file exists but is a directory rather than a regular file, does not exist but
- * cannot be created, or cannot be opened for any other reason
- */
- static void updateFileHandle(File inputFile, String contentTobeAdded, boolean isClose)
- throws IOException {
-
- List<FileWriter> fileWriterStore = new ArrayList<>();
-
- FileWriter fileWriter = new FileWriter(inputFile, true);
- fileWriterStore.add(fileWriter);
- PrintWriter outputPrintWriter = new PrintWriter(fileWriter, true);
- if (!isClose) {
- outputPrintWriter.write(contentTobeAdded);
- outputPrintWriter.flush();
- outputPrintWriter.close();
- } else {
- for (FileWriter curWriter : fileWriterStore) {
- curWriter.flush();
- curWriter.close();
- }
- }
- }
-
- /**
- * Closes the file handle for temporary file.
- *
- * @param file file to be closed
- * @param toBeDeleted flag to indicate if file needs to be deleted
- * @throws IOException when failed to close the file handle
- */
- public static void closeFile(File file, boolean toBeDeleted)
- throws IOException {
-
- if (file != null) {
- updateFileHandle(file, null, true);
- if (toBeDeleted) {
- boolean deleted = file.delete();
- if (!deleted) {
- throw new IOException("Failed to delete temporary file " + file.getName());
- }
- }
- }
- }
-
- /**
- * Closes the file handle for temporary file with file deletion.
- *
- * @param file file to be closed
- * @throws IOException when failed to close the file handle
- */
- public static void closeFile(File file) throws IOException {
-
- if (file != null) {
- updateFileHandle(file, null, true);
- boolean deleted = file.delete();
- if (!deleted) {
- throw new IOException("Failed to delete temporary file " +
- file.getName());
- }
- }
- }
- // TODO follow coding guidelines in remaining of this file.
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/utils/io/impl/JavaDocGen.java b/plugin/src/main/java/org/onosproject/yangutils/utils/io/impl/JavaDocGen.java
deleted file mode 100644
index 7698d89..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/utils/io/impl/JavaDocGen.java
+++ /dev/null
@@ -1,837 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.utils.io.impl;
-
-import static org.onosproject.yangutils.utils.UtilConstants.ADD_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
-import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_CLASS_JAVA_DOC;
-import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_INTERFACE_JAVA_DOC;
-import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_LOWER_CASE;
-import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_OBJECT;
-import static org.onosproject.yangutils.utils.UtilConstants.CLASS;
-import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION;
-import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.ENUM_ATTRIBUTE_JAVADOC;
-import static org.onosproject.yangutils.utils.UtilConstants.ENUM_CLASS_JAVADOC;
-import static org.onosproject.yangutils.utils.UtilConstants.EVENT_JAVA_DOC;
-import static org.onosproject.yangutils.utils.UtilConstants.EVENT_LISTENER_JAVA_DOC;
-import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
-import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_METHOD_NAME;
-import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_PARAM_NAME;
-import static org.onosproject.yangutils.utils.UtilConstants.IMPL_CLASS_JAVA_DOC;
-import static org.onosproject.yangutils.utils.UtilConstants.INPUT;
-import static org.onosproject.yangutils.utils.UtilConstants.INTERFACE_JAVA_DOC;
-import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_ADD_TO_LIST;
-import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_BUILD;
-import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_CONSTRUCTOR;
-import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_END_LINE;
-import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_FIRST_LINE;
-import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_FOR_VALIDATOR;
-import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_FOR_VALIDATOR_RETURN;
-import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_GETTERS;
-import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_MANAGER_SETTERS;
-import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_OF;
-import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_PARAM;
-import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_RETURN;
-import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_RPC;
-import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_SETTERS;
-import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_SETTERS_COMMON;
-import static org.onosproject.yangutils.utils.UtilConstants.LIST;
-import static org.onosproject.yangutils.utils.UtilConstants.MAX_RANGE;
-import static org.onosproject.yangutils.utils.UtilConstants.MIN_RANGE;
-import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
-import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE_ASTERISK;
-import static org.onosproject.yangutils.utils.UtilConstants.OBJECT;
-import static org.onosproject.yangutils.utils.UtilConstants.OBJECT_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.OF;
-import static org.onosproject.yangutils.utils.UtilConstants.OP_PARAM_JAVA_DOC;
-import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE_INFO_JAVADOC;
-import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE_INFO_JAVADOC_OF_CHILD;
-import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
-import static org.onosproject.yangutils.utils.UtilConstants.QUEUE;
-import static org.onosproject.yangutils.utils.UtilConstants.RPC_INPUT_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.RPC_OUTPUT_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.SET;
-import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
-import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE;
-import static org.onosproject.yangutils.utils.UtilConstants.TO_CAPS;
-import static org.onosproject.yangutils.utils.UtilConstants.VALIDATE_RANGE;
-import static org.onosproject.yangutils.utils.UtilConstants.VALUE;
-import static org.onosproject.yangutils.utils.UtilConstants.VOID;
-import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO;
-import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUGMENTED_INFO_LOWER_CASE;
-import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getSmallCase;
-
-/**
- * Represents javadoc for the generated classes.
- */
-public final class JavaDocGen {
-
- /**
- * Creates an instance of java doc gen.
- */
- private JavaDocGen() {
- }
-
- /**
- * Returns java docs.
- *
- * @param type java doc type
- * @param name name of the YangNode
- * @param isList is list attribute
- * @param compilerAnnotation compiler annotations for user defined data type
- * @return javaDocs.
- */
- public static String getJavaDoc(JavaDocType type, String name, boolean isList,
- String compilerAnnotation) {
-
- name = YangIoUtils.getSmallCase(name);
- switch (type) {
- case IMPL_CLASS: {
- return generateForClass(name);
- }
- case BUILDER_CLASS: {
- return generateForBuilderClass(name);
- }
- case OPERATION_CLASS: {
- return generateForOpParamClass(name);
- }
- case OPERATION_BUILDER_CLASS: {
- return generateForOpParamClass(name);
- }
- case INTERFACE: {
- return generateForInterface(name);
- }
- case BUILDER_INTERFACE: {
- return generateForBuilderInterface(name);
- }
- case PACKAGE_INFO: {
- return generateForPackage(name, isList);
- }
- case GETTER_METHOD: {
- return generateForGetters(name, isList, compilerAnnotation);
- }
- case TYPE_DEF_SETTER_METHOD: {
- return generateForTypeDefSetter(name);
- }
- case SETTER_METHOD: {
- return generateForSetters(name, isList, compilerAnnotation);
- }
- case MANAGER_SETTER_METHOD: {
- return generateForManagerSetters(name, isList, compilerAnnotation);
- }
- case OF_METHOD: {
- return generateForOf(name);
- }
- case DEFAULT_CONSTRUCTOR: {
- return generateForDefaultConstructors(name);
- }
- case BUILD_METHOD: {
- return generateForBuild(name);
- }
- case TYPE_CONSTRUCTOR: {
- return generateForTypeConstructor(name);
- }
- case FROM_METHOD: {
- return generateForFromString(name);
- }
- case ENUM_CLASS: {
- return generateForEnum(name);
- }
- case ENUM_ATTRIBUTE: {
- return generateForEnumAttr(name);
- }
- case RPC_INTERFACE: {
- return generateForRpcService(name);
- }
- case RPC_MANAGER: {
- return generateForClass(name);
- }
- case EVENT: {
- return generateForEvent(name);
- }
- case EVENT_LISTENER: {
- return generateForEventListener(name);
- }
- case EVENT_SUBJECT_CLASS: {
- return generateForClass(name);
- }
- case ADD_TO_LIST: {
- return generateForAddToList(name);
- }
- default: {
- return generateForConstructors(name);
- }
- }
- }
-
- /**
- * Generates javaDocs for enum's attributes.
- *
- * @param name attribute name
- * @return javaDocs
- */
- private static String generateForEnumAttr(String name) {
- return getJavaDocForClass(name, ENUM_ATTRIBUTE_JAVADOC,
- FOUR_SPACE_INDENTATION);
- }
-
- /**
- * Generates javaDocs for inner class enum's attributes.
- *
- * @param name attribute name
- * @return javaDocs
- */
- public static String enumJavaDocForInnerClass(String name) {
- return getJavaDocForClass(name, ENUM_ATTRIBUTE_JAVADOC,
- EIGHT_SPACE_INDENTATION);
- }
-
- /**
- * Generates javaDocs for rpc method.
- *
- * @param rpcName name of the rpc
- * @param inputName name of input
- * @param outputName name of output
- * @return javaDocs of rpc method
- */
- public static String generateJavaDocForRpc(String rpcName, String inputName,
- String outputName) {
-
- String javadoc = getJavaDocStartLine(rpcName, JAVA_DOC_RPC) +
- getJavaDocEmptyAsteriskLine();
- if (!inputName.equals(EMPTY_STRING)) {
- javadoc = javadoc + getInputString(inputName, rpcName);
- }
- if (!outputName.equals(VOID)) {
- javadoc = javadoc + getOutputString(getSmallCase(outputName),
- rpcName);
- }
- return javadoc + getJavaDocEndLine();
- }
-
- /**
- * Returns output string of rpc.
- *
- * @param outputName name of output
- * @param rpcName name of rpc
- * @return javaDocs for output string of rpc
- */
- private static String getOutputString(String outputName, String rpcName) {
- return FOUR_SPACE_INDENTATION + JAVA_DOC_RETURN + outputName + SPACE +
- RPC_OUTPUT_STRING + rpcName + NEW_LINE;
- }
-
- /**
- * Returns input string of rpc.
- *
- * @param inputName name of input
- * @param rpcName name of rpc
- * @return javaDocs for input string of rpc
- */
- private static String getInputString(String inputName, String rpcName) {
- if (inputName.isEmpty()) {
- return null;
- } else {
- return FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM + inputName +
- SPACE + RPC_INPUT_STRING + rpcName + NEW_LINE;
- }
- }
-
- /**
- * Generates javaDoc for the interface.
- *
- * @param interfaceName interface name
- * @return javaDocs
- */
- private static String generateForRpcService(String interfaceName) {
- return getJavaDocForClass(interfaceName, INTERFACE_JAVA_DOC, EMPTY_STRING);
- }
-
- /**
- * Generates javaDoc for the event.
- *
- * @param name event class name
- * @return javaDocs
- */
- private static String generateForEvent(String name) {
- return getJavaDocForClass(name, EVENT_JAVA_DOC, EMPTY_STRING);
- }
-
- /**
- * Generates javaDoc for the event listener.
- *
- * @param name event class name
- * @return javaDocs
- */
- private static String generateForEventListener(String name) {
- return getJavaDocForClass(name, EVENT_LISTENER_JAVA_DOC, EMPTY_STRING);
- }
-
- /**
- * Generates javaDocs for getter method.
- *
- * @param attribute attribute
- * @param isList is list attribute
- * @param compilerAnnotation compiler annotation
- * @return javaDocs
- */
- private static String generateForGetters(String attribute, boolean isList,
- String compilerAnnotation) {
-
- String getter = getJavaDocStartLine(attribute, JAVA_DOC_GETTERS) +
- getJavaDocEmptyAsteriskLine() +
- FOUR_SPACE_INDENTATION + JAVA_DOC_RETURN + attribute + SPACE;
-
- getter = getParamForAnnotation(getter, compilerAnnotation, isList) +
- attribute + NEW_LINE + getJavaDocEndLine();
- return getter;
- }
-
- /**
- * Generates javaDocs for setter method.
- *
- * @param attribute attribute
- * @param isList is list attribute
- * @param compilerAnnotation compiler annotation
- * @return javaDocs
- */
- private static String generateForSetters(String attribute, boolean isList,
- String compilerAnnotation) {
-
- String setter = getJavaDocStartLine(attribute, JAVA_DOC_SETTERS) +
- getJavaDocEmptyAsteriskLine() +
- FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM + attribute + SPACE;
- setter = getParamForAnnotation(setter, compilerAnnotation, isList) +
- attribute + NEW_LINE + getJavaDocReturnLine(attribute)
- + getJavaDocEndLine();
- return setter;
- }
-
- /**
- * Generates javaDocs for setter method.
- *
- * @param attribute attribute
- * @param isList is list attribute
- * @param compilerAnnotation compiler annotation
- * @return javaDocs
- */
- private static String generateForManagerSetters(String attribute, boolean isList,
- String compilerAnnotation) {
- String setter = getJavaDocStartLine(attribute, JAVA_DOC_MANAGER_SETTERS) +
- getJavaDocEmptyAsteriskLine() +
- FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM + attribute + SPACE;
- setter = getParamForAnnotation(setter, compilerAnnotation, isList) +
- attribute + NEW_LINE + getJavaDocEndLine();
- return setter;
- }
-
- private static String getParamForAnnotation(
- String setter, String compilerAnnotation, boolean isList) {
- String attributeParam;
- if (compilerAnnotation != null) {
- switch (compilerAnnotation) {
- case QUEUE: {
- attributeParam = QUEUE.toLowerCase() + SPACE + OF + SPACE;
- setter = setter + attributeParam;
- break;
- }
- case SET: {
- attributeParam = SET.toLowerCase() + SPACE + OF + SPACE;
- setter = setter + attributeParam;
- break;
- }
- case LIST: {
- attributeParam = LIST.toLowerCase() + SPACE + OF + SPACE;
- setter = setter + attributeParam;
- break;
- }
- default: {
-
- }
- }
- } else if (isList) {
- attributeParam = LIST.toLowerCase() + SPACE + OF + SPACE;
- setter = setter + attributeParam;
- } else {
- setter = setter + VALUE + SPACE + OF + SPACE;
- }
- return setter;
- }
-
- /**
- * Generates javaDocs for of method.
- *
- * @param attribute attribute
- * @return javaDocs
- */
- private static String generateForOf(String attribute) {
- return getJavaDocStartLine(attribute, JAVA_DOC_OF) +
- getJavaDocEmptyAsteriskLine() +
- getJavaDocParamLine(attribute, VALUE) +
- getJavaDocReturnLine(attribute) +
- getJavaDocEndLine();
- }
-
- /**
- * Generates javaDocs for from method.
- *
- * @param attribute attribute
- * @return javaDocs
- */
- private static String generateForFromString(String attribute) {
- return getJavaDocStartLine(attribute, JAVA_DOC_OF
- + attribute + SPACE + FROM_STRING_METHOD_NAME + SPACE + INPUT +
- SPACE + STRING_DATA_TYPE) +
- getJavaDocEmptyAsteriskLine() +
- getJavaDocParamLine(INPUT + SPACE + STRING_DATA_TYPE,
- FROM_STRING_PARAM_NAME) +
- getJavaDocReturnLine(attribute) +
- getJavaDocEndLine();
- }
-
- /**
- * Generates javaDocs for typedef setter method.
- *
- * @param attribute attribute
- * @return javaDocs
- */
- private static String generateForTypeDefSetter(String attribute) {
- return getJavaDocStartLine(attribute, JAVA_DOC_SETTERS_COMMON) +
- getJavaDocEmptyAsteriskLine() +
- getJavaDocParamLine(attribute, VALUE) +
- getJavaDocEndLine();
- }
-
- /**
- * Generates javaDocs for the impl class.
- *
- * @param className class name
- * @return javaDocs
- */
- private static String generateForClass(String className) {
- return getJavaDocForClass(className, IMPL_CLASS_JAVA_DOC, EMPTY_STRING);
- }
-
- /**
- * Generates javaDocs for enum.
- *
- * @param className enum class name
- * @return javaDocs
- */
- private static String generateForEnum(String className) {
- return getJavaDocForClass(className, ENUM_CLASS_JAVADOC, EMPTY_STRING);
- }
-
- /**
- * Generates javaDocs for the builder class.
- *
- * @param className class name
- * @return javaDocs
- */
- private static String generateForBuilderClass(String className) {
- return getJavaDocForClass(className, BUILDER_CLASS_JAVA_DOC,
- EMPTY_STRING);
- }
-
- /**
- * Generates javaDocs for the op param class.
- *
- * @param className class name
- * @return javaDocs
- */
- private static String generateForOpParamClass(String className) {
- return getJavaDocForClass(className, OP_PARAM_JAVA_DOC,
- EMPTY_STRING);
- }
-
- /**
- * Generates javaDoc for the interface.
- *
- * @param interfaceName interface name
- * @return javaDocs
- */
- private static String generateForInterface(String interfaceName) {
- return getJavaDocForClass(interfaceName, INTERFACE_JAVA_DOC,
- EMPTY_STRING);
- }
-
- /**
- * Generates javaDoc for the builder interface.
- *
- * @param builderForName builder for name
- * @return javaDocs
- */
- private static String generateForBuilderInterface(String builderForName) {
- return getJavaDocForClass(builderForName, BUILDER_INTERFACE_JAVA_DOC,
- EMPTY_STRING);
- }
-
- /**
- * Generates javaDocs for package-info.
- *
- * @param packageName package name
- * @param isChildNode is it child node
- * @return javaDocs
- */
- private static String generateForPackage(String packageName, boolean isChildNode) {
- if (isChildNode) {
- return getJavaDocForClass(
- packageName + PACKAGE_INFO_JAVADOC_OF_CHILD,
- PACKAGE_INFO_JAVADOC, EMPTY_STRING);
- }
- return getJavaDocForClass(packageName, PACKAGE_INFO_JAVADOC, EMPTY_STRING);
- }
-
- /**
- * Generates javaDocs for default constructor.
- *
- * @param className class name
- * @return javaDocs
- */
- private static String generateForDefaultConstructors(String className) {
- return getJavaDocStartLine(className, JAVA_DOC_CONSTRUCTOR) +
- getJavaDocEndLine();
- }
-
- /**
- * Generates javaDocs for constructor with parameters.
- *
- * @param className class name
- * @return javaDocs
- */
- private static String generateForConstructors(String className) {
- return getJavaDocStartLine(className, JAVA_DOC_CONSTRUCTOR) +
- getJavaDocEmptyAsteriskLine() +
- getJavaDocParamLine(BUILDER_OBJECT + className,
- BUILDER_LOWER_CASE + OBJECT) +
- getJavaDocEndLine();
- }
-
- /**
- * Generates javaDocs for build.
- *
- * @param buildName builder name
- * @return javaDocs
- */
- private static String generateForBuild(String buildName) {
- return getJavaDocStartLine(buildName, JAVA_DOC_BUILD) +
- getJavaDocEmptyAsteriskLine() +
- getJavaDocReturnLine(buildName) +
- getJavaDocEndLine();
- }
-
- /**
- * Generates javaDocs for type constructor.
- *
- * @param attribute attribute string
- * @return javaDocs for type constructor
- */
- private static String generateForTypeConstructor(String attribute) {
- return getJavaDocStartLine(attribute,
- JAVA_DOC_CONSTRUCTOR) +
- getJavaDocEmptyAsteriskLine() +
- getJavaDocParamLine(attribute, attribute) +
- getJavaDocEndLine();
- }
-
- /**
- * Generates javaDocs for add augmentation method.
- *
- * @return javaDocs
- */
- public static String generateForAddAugmentation() {
- return getJavaDocStartLine(YANG_AUGMENTED_INFO_LOWER_CASE,
- JAVA_DOC_SETTERS_COMMON) +
- getJavaDocEmptyAsteriskLine() +
- getJavaDocParamLine(YANG_AUGMENTED_INFO_LOWER_CASE, VALUE) +
- getJavaDocParamLine(YANG_AUGMENTED_INFO_LOWER_CASE, CLASS +
- OBJECT_STRING) +
- getJavaDocEndLine();
- }
-
- /**
- * Returns javadoc for get augmentation method.
- *
- * @return javadoc for get augmentation method
- */
- public static String generateForGetAugmentation() {
- return NEW_LINE + getJavaDocStartLine(YANG_AUGMENTED_INFO_LOWER_CASE,
- JAVA_DOC_GETTERS) +
- getJavaDocEmptyAsteriskLine() +
- getJavaDocParamLine(YANG_AUGMENTED_INFO_LOWER_CASE, CLASS +
- OBJECT_STRING) +
- getJavaDocReturnLine(YANG_AUGMENTED_INFO) +
- getJavaDocEndLine();
- }
-
- /**
- * Returns javadoc for validator method.
- *
- * @return javadoc for validator method
- */
- public static String generateForValidatorMethod() {
- return getJavaDocStartLine(VALIDATE_RANGE, JAVA_DOC_FOR_VALIDATOR) +
- getJavaDocEmptyAsteriskLine() +
- getJavaDocParamLine(MIN_RANGE, MIN_RANGE) +
- getJavaDocParamLine(MAX_RANGE, MIN_RANGE) +
- getJavaDocReturnLine(JAVA_DOC_FOR_VALIDATOR_RETURN) +
- getJavaDocEndLine();
- }
-
- /**
- * Generates javaDocs for type constructor.
- *
- * @param attribute attribute string
- * @return javaDocs for type constructor
- */
- public static String generateForGetMethodWithAttribute(String attribute) {
- attribute = getSmallCase(attribute);
- return getJavaDocStartLine(attribute, JAVA_DOC_GETTERS) +
- getJavaDocEmptyAsteriskLine() +
- getJavaDocParamLine(attribute, attribute) +
- getJavaDocReturnLine(attribute) +
- getJavaDocEndLine();
- }
-
- /**
- * Returns javaDocs for add to list method.
- *
- * @param attribute attribute
- * @return javaDocs
- */
- private static String generateForAddToList(String attribute) {
- return getJavaDocStartLine(attribute, JAVA_DOC_ADD_TO_LIST) +
- getJavaDocEmptyAsteriskLine() +
- getJavaDocParamLine(attribute, ADD_STRING + TO_CAPS) +
- getJavaDocReturnLine(BUILDER_OBJECT + attribute) +
- getJavaDocEndLine();
- }
-
- /**
- * Generates for builder method.
- *
- * @param attribute attribute
- * @return javaDocs
- */
- public static String generateForBuilderMethod(String attribute) {
- return getJavaDocStartLine(attribute + BUILDER, JAVA_DOC_GETTERS) +
- getJavaDocEmptyAsteriskLine() +
- getJavaDocReturnLine(attribute + BUILDER) +
- getJavaDocEndLine();
- }
-
- /**
- * Returns class javadoc.
- *
- * @param name name of class
- * @param type type of javadoc
- * @param indent indentation
- * @return class javadoc
- */
- private static String getJavaDocForClass(String name, String type,
- String indent) {
- return NEW_LINE + indent + JAVA_DOC_FIRST_LINE + indent + type +
- getSmallCase(name) + PERIOD + NEW_LINE + indent + JAVA_DOC_END_LINE;
- }
-
- /**
- * Returns javadoc start line.
- *
- * @param name name of attribute
- * @param javaDoc type of javadoc
- * @return javadoc start line
- */
- private static String getJavaDocStartLine(String name, String javaDoc) {
- return FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE +
- FOUR_SPACE_INDENTATION + javaDoc + getSmallCase(name) +
- PERIOD + NEW_LINE;
- }
-
- /**
- * Returns asterisk line.
- *
- * @return asterisk line
- */
- private static String getJavaDocEmptyAsteriskLine() {
- return FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK;
- }
-
- /**
- * Returns javadoc param line.
- *
- * @param name name of attribute
- * @return javadoc param line
- */
- private static String getJavaDocParamLine(String name, String paraName) {
- return FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM +
- getSmallCase(paraName) + SPACE + VALUE + SPACE + OF + SPACE +
- getSmallCase(name) + NEW_LINE;
- }
-
- /**
- * Returns javadoc return line.
- *
- * @param name name of attribute
- * @return javadoc return line
- */
- private static String getJavaDocReturnLine(String name) {
- return FOUR_SPACE_INDENTATION + JAVA_DOC_RETURN + getSmallCase(name)
- + NEW_LINE;
- }
-
- /**
- * Returns javadoc end line.
- *
- * @return javadoc end line
- */
- private static String getJavaDocEndLine() {
- return FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
- }
-
-
- /**
- * JavaDocs types.
- */
- public enum JavaDocType {
-
- /**
- * For class.
- */
- IMPL_CLASS,
-
- /**
- * For builder class.
- */
- BUILDER_CLASS,
-
- /**
- * For interface.
- */
- INTERFACE,
-
- /**
- * For builder interface.
- */
- BUILDER_INTERFACE,
-
- /**
- * For package-info.
- */
- PACKAGE_INFO,
-
- /**
- * For getters.
- */
- GETTER_METHOD,
-
- /**
- * For rpc service.
- */
- RPC_INTERFACE,
-
- /**
- * For rpc manager.
- */
- RPC_MANAGER,
-
- /**
- * For event.
- */
- EVENT,
-
- /**
- * For event listener.
- */
- EVENT_LISTENER,
-
- /**
- * For setters.
- */
- SETTER_METHOD,
-
- /**
- * For type def's setters.
- */
- TYPE_DEF_SETTER_METHOD,
-
- /**
- * For of method.
- */
- OF_METHOD,
-
- /**
- * For default constructor.
- */
- DEFAULT_CONSTRUCTOR,
-
- /**
- * For constructor.
- */
- CONSTRUCTOR,
-
- /**
- * For from method.
- */
- FROM_METHOD,
-
- /**
- * For type constructor.
- */
- TYPE_CONSTRUCTOR,
-
- /**
- * For build.
- */
- BUILD_METHOD,
-
- /**
- * For enum.
- */
- ENUM_CLASS,
-
- /**
- * For enum's attributes.
- */
- ENUM_ATTRIBUTE,
-
- /**
- * For manager setters.
- */
- MANAGER_SETTER_METHOD,
-
- /**
- * For event subject.
- */
- EVENT_SUBJECT_CLASS,
-
- /**
- * For operation.
- */
- OPERATION_CLASS,
-
- /**
- * For operation builder.
- */
- OPERATION_BUILDER_CLASS,
-
- /**
- * For add to list.
- */
- ADD_TO_LIST,
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/utils/io/impl/YangFileScanner.java b/plugin/src/main/java/org/onosproject/yangutils/utils/io/impl/YangFileScanner.java
deleted file mode 100644
index 9c994a8..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/utils/io/impl/YangFileScanner.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.utils.io.impl;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Stack;
-
-/**
- * Represents utility for searching the files in a directory.
- */
-public final class YangFileScanner {
-
- private static final String JAVA_FILE_EXTENSION = ".java";
- private static final String YANG_FILE_EXTENSION = ".yang";
-
- /**
- * Creates an instance of YANG file scanner.
- */
- private YangFileScanner() {
- }
-
- /**
- * Returns the list of java files.
- *
- * @param root specified directory
- * @return list of java files
- * @throws NullPointerException when no files are there.
- * @throws IOException when files get deleted while performing the
- * operations
- */
- public static List<String> getJavaFiles(String root) throws IOException {
- return getFiles(root, JAVA_FILE_EXTENSION);
- }
-
- /**
- * Returns the list of YANG file.
- *
- * @param root specified directory
- * @return list of YANG file information
- * @throws NullPointerException when no files are there
- * @throws IOException when files get deleted while performing the
- * operations
- */
- public static List<String> getYangFiles(String root) throws IOException {
- return getFiles(root, YANG_FILE_EXTENSION);
- }
-
- /**
- * Returns the list of required files.
- *
- * @param root specified directory
- * @param extension file extension
- * @return list of required files
- * @throws NullPointerException when no file is there
- * @throws IOException when files get deleted while performing the operations
- */
- private static List<String> getFiles(String root, String extension) throws IOException {
-
- List<String> store = new LinkedList<>();
- Stack<String> stack = new Stack<>();
- stack.push(root);
- File file;
- File[] fileList;
- try {
- while (!stack.empty()) {
- root = stack.pop();
- file = new File(root);
- fileList = file.listFiles();
- if ((fileList == null) || (fileList.length == 0)) {
- continue;
- }
- for (File current : fileList) {
- if (current.isDirectory()) {
- stack.push(current.toString());
- } else {
- String yangFile = current.getCanonicalPath();
- if (yangFile.endsWith(extension)) {
- store.add(yangFile);
- }
- }
- }
- }
- return store;
- } catch (IOException e) {
- throw new IOException("No File found of " + extension + " extension in " + root + " directory.");
- }
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/utils/io/impl/YangIoUtils.java b/plugin/src/main/java/org/onosproject/yangutils/utils/io/impl/YangIoUtils.java
deleted file mode 100644
index e1020a1..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/utils/io/impl/YangIoUtils.java
+++ /dev/null
@@ -1,884 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.yangutils.utils.io.impl;
-
-import org.apache.commons.io.FileUtils;
-import org.onosproject.yangutils.translator.exception.TranslatorException;
-import org.onosproject.yangutils.utils.io.YangToJavaNamingConflictUtil;
-
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Stack;
-import java.util.regex.Pattern;
-
-import static org.onosproject.yangutils.utils.UtilConstants.CLOSE_PARENTHESIS;
-import static org.onosproject.yangutils.utils.UtilConstants.COLON;
-import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION;
-import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
-import static org.onosproject.yangutils.utils.UtilConstants.HYPHEN;
-import static org.onosproject.yangutils.utils.UtilConstants.JAVA_KEY_WORDS;
-import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
-import static org.onosproject.yangutils.utils.UtilConstants.ONE;
-import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET;
-import static org.onosproject.yangutils.utils.UtilConstants.OPEN_PARENTHESIS;
-import static org.onosproject.yangutils.utils.UtilConstants.ORG;
-import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE;
-import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
-import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_DIGITS_WITH_SINGLE_LETTER;
-import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_FIRST_DIGIT;
-import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_HYPHEN;
-import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_IDENTIFIER_SPECIAL_CHAR;
-import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_PERIOD;
-import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_SINGLE_LETTER;
-import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_UNDERSCORE;
-import static org.onosproject.yangutils.utils.UtilConstants.REGEX_WITH_ALL_SPECIAL_CHAR;
-import static org.onosproject.yangutils.utils.UtilConstants.REGEX_WITH_DIGITS;
-import static org.onosproject.yangutils.utils.UtilConstants.REGEX_WITH_SINGLE_CAPITAL_CASE;
-import static org.onosproject.yangutils.utils.UtilConstants.REGEX_WITH_SINGLE_CAPITAL_CASE_AND_DIGITS_SMALL_CASES;
-import static org.onosproject.yangutils.utils.UtilConstants.REGEX_WITH_UPPERCASE;
-import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLON;
-import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
-import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
-import static org.onosproject.yangutils.utils.UtilConstants.TEMP;
-import static org.onosproject.yangutils.utils.UtilConstants.TWELVE_SPACE_INDENTATION;
-import static org.onosproject.yangutils.utils.UtilConstants.UNDER_SCORE;
-import static org.onosproject.yangutils.utils.UtilConstants.UNUSED;
-import static org.onosproject.yangutils.utils.UtilConstants.YANG_AUTO_PREFIX;
-import static org.onosproject.yangutils.utils.io.impl.CopyrightHeader.getCopyrightHeader;
-import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.appendFileContents;
-import static org.onosproject.yangutils.utils.io.impl.FileSystemUtil.updateFileHandle;
-import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.PACKAGE_INFO;
-import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.getJavaDoc;
-
-/**
- * Represents common utility functionalities for code generation.
- */
-public final class YangIoUtils {
-
- private static final int LINE_SIZE = 118;
- private static final int SUB_LINE_SIZE = 116;
- private static final int SUB_SIZE = 60;
-
- /**
- * Creates an instance of YANG io utils.
- */
- private YangIoUtils() {
- }
-
- /**
- * Creates the directory structure.
- *
- * @param path directory path
- * @return directory structure
- * @throws IOException when fails to do IO operations
- */
- public static File createDirectories(String path)
- throws IOException {
- File generatedDir = new File(path);
- if (!generatedDir.exists()) {
- boolean isGenerated = generatedDir.mkdirs();
- if (!isGenerated) {
- throw new IOException("failed to generated directory " + path);
- }
- }
- return generatedDir;
- }
-
- /**
- * Adds package info file for the created directory.
- *
- * @param path directory path
- * @param classInfo class info for the package
- * @param pack package of the directory
- * @param isChildNode is it a child node
- * @throws IOException when fails to create package info file
- */
- public static void addPackageInfo(File path, String classInfo, String pack,
- boolean isChildNode) throws IOException {
-
- pack = parsePkg(pack);
- try {
-
- File packageInfo = new File(path + SLASH + "package-info.java");
- if (!packageInfo.exists()) {
- boolean isGenerated = packageInfo.createNewFile();
- if (!isGenerated) {
- throw new IOException("failed to generated package-info " +
- path);
- }
- }
- FileWriter fileWriter = new FileWriter(packageInfo);
- BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
-
- bufferedWriter.write(getCopyrightHeader());
- //TODO: get the compiler annotations and pass the info
- bufferedWriter.write(getJavaDoc(PACKAGE_INFO, classInfo, isChildNode,
- null));
- String pkg = PACKAGE + SPACE + pack + SEMI_COLON;
- if (pkg.length() > LINE_SIZE) {
- pkg = processModifications(pkg, LINE_SIZE);
- }
- bufferedWriter.write(pkg);
- bufferedWriter.close();
- fileWriter.close();
- } catch (IOException e) {
- throw new IOException("Exception occurred while creating package info" +
- " file.");
- }
- }
-
- /**
- * Parses package and returns updated package.
- *
- * @param pack package needs to be updated
- * @return updated package
- */
- public static String parsePkg(String pack) {
-
- if (pack.contains(ORG)) {
- String[] strArray = pack.split(ORG);
- if (strArray.length >= 3) {
- for (int i = 1; i < strArray.length; i++) {
- if (i == 1) {
- pack = ORG + strArray[1];
- } else {
- pack = pack + ORG + strArray[i];
- }
- }
- } else {
- pack = ORG + strArray[1];
- }
- }
-
- return pack;
- }
-
- /**
- * Cleans the generated directory if already exist in source folder.
- *
- * @param dir generated directory in previous build
- * @throws IOException when failed to delete directory
- */
- public static void deleteDirectory(String dir)
- throws IOException {
- File generatedDirectory = new File(dir);
- if (generatedDirectory.exists()) {
- try {
- FileUtils.deleteDirectory(generatedDirectory);
- } catch (IOException e) {
- throw new IOException(
- "Failed to delete the generated files in " +
- generatedDirectory + " directory");
- }
- }
- }
-
- /**
- * Searches and deletes generated temporary directories.
- *
- * @param root root directory
- * @throws IOException when fails to do IO operations.
- */
- public static void searchAndDeleteTempDir(String root)
- throws IOException {
- List<File> store = new LinkedList<>();
- Stack<String> stack = new Stack<>();
- stack.push(root);
-
- while (!stack.empty()) {
- root = stack.pop();
- File file = new File(root);
- File[] fileList = file.listFiles();
- if (fileList == null || fileList.length == 0) {
- continue;
- }
- for (File current : fileList) {
- if (current.isDirectory()) {
- stack.push(current.toString());
- if (current.getName().endsWith(HYPHEN + TEMP)) {
- store.add(current);
- }
- }
- }
- }
-
- for (File dir : store) {
- FileUtils.deleteDirectory(dir);
- }
- }
-
- /**
- * Removes extra char from the string.
- *
- * @param valueString string to be trimmed
- * @param removalString extra chars
- * @return new string
- */
- public static String trimAtLast(String valueString, String...
- removalString) {
- StringBuilder stringBuilder = new StringBuilder(valueString);
- String midString;
- int index;
- for (String remove : removalString) {
- midString = stringBuilder.toString();
- index = midString.lastIndexOf(remove);
- if (index != -1) {
- stringBuilder.deleteCharAt(index);
- }
- }
- return stringBuilder.toString();
- }
-
- /**
- * Replaces the last occurrence of a string with a given string.
- *
- * @param valueString string under operation
- * @param removalString string to be replaced
- * @param replacingString string with which replacement is to be done
- * @return new string
- */
- public static String replaceLast(String valueString, String removalString,
- String replacingString) {
- StringBuilder stringBuilder = new StringBuilder(valueString);
- int index = valueString.lastIndexOf(removalString);
- if (index != -1) {
- stringBuilder.replace(index, index + 1, replacingString);
- } else {
- stringBuilder.append(NEW_LINE + EIGHT_SPACE_INDENTATION + UNUSED +
- OPEN_PARENTHESIS + ONE +
- CLOSE_PARENTHESIS + SEMI_COLON);
- }
- return stringBuilder.toString();
-
- // TODO remove generation of ENUM if there is no leaf node.
- }
-
-
- /**
- * Returns the directory path of the package in canonical form.
- *
- * @param baseCodeGenPath base path where the generated files needs to be
- * put
- * @param pathOfJavaPkg java package of the file being generated
- * @return absolute path of the package in canonical form
- */
- public static String getDirectory(String baseCodeGenPath, String pathOfJavaPkg) {
-
- if (pathOfJavaPkg.charAt(pathOfJavaPkg.length() - 1) == File.separatorChar) {
- pathOfJavaPkg = trimAtLast(pathOfJavaPkg, SLASH);
- }
- String[] strArray = pathOfJavaPkg.split(SLASH);
- if (strArray[0].equals(EMPTY_STRING)) {
- return pathOfJavaPkg;
- } else {
- return baseCodeGenPath + SLASH + pathOfJavaPkg;
- }
- }
-
- /**
- * Returns the absolute path of the package in canonical form.
- *
- * @param baseCodeGenPath base path where the generated files needs to be
- * put
- * @param pathOfJavaPkg java package of the file being generated
- * @return absolute path of the package in canonical form
- */
- public static String getAbsolutePackagePath(String baseCodeGenPath,
- String pathOfJavaPkg) {
- return baseCodeGenPath + pathOfJavaPkg;
- }
-
- /**
- * Merges the temp java files to main java files.
- *
- * @param appendFile temp file
- * @param srcFile main file
- * @throws IOException when fails to append contents
- */
- public static void mergeJavaFiles(File appendFile, File srcFile)
- throws IOException {
- try {
- appendFileContents(appendFile, srcFile);
- } catch (IOException e) {
- throw new IOException("Failed to merge " + appendFile + " in " +
- srcFile);
- }
- }
-
- /**
- * Inserts data in the generated file.
- *
- * @param file file in which need to be inserted
- * @param data data which need to be inserted
- * @throws IOException when fails to insert into file
- */
- public static void insertDataIntoJavaFile(File file, String data)
- throws IOException {
- try {
- updateFileHandle(file, data, false);
- } catch (IOException e) {
- throw new IOException("Failed to insert in " + file + "file");
- }
- }
-
- /**
- * Validates a line size in given file whether it is having more then 120 characters.
- * If yes it will update and give a new file.
- *
- * @param dataFile file in which need to verify all lines.
- * @return updated file
- * @throws IOException when fails to do IO operations.
- */
- public static File validateLineLength(File dataFile)
- throws IOException {
- FileReader fileReader = new FileReader(dataFile);
- BufferedReader bufferReader = new BufferedReader(fileReader);
- try {
- StringBuilder stringBuilder = new StringBuilder();
- String line = bufferReader.readLine();
-
- while (line != null) {
- if (line.length() > LINE_SIZE) {
- line = processModifications(line, LINE_SIZE);
- }
- stringBuilder.append(line);
- stringBuilder.append(NEW_LINE);
- line = bufferReader.readLine();
- }
- FileWriter writer = new FileWriter(dataFile);
- writer.write(stringBuilder.toString());
- writer.close();
- return dataFile;
- } finally {
- fileReader.close();
- bufferReader.close();
- }
- }
-
- /**
- * Resolves validation of line length by modifying the string.
- *
- * @param line current line string
- * @param lineSize line size for change
- * @return modified line string
- */
- private static String processModifications(String line, int lineSize) {
- int period = getArrayLength(line, PERIOD);
- int space = getArrayLength(line, SPACE);
- if (period > space) {
- return merge(getForPeriod(line), PERIOD, lineSize);
- }
- return merge(getForSpace(line), SPACE, lineSize);
- }
-
- /**
- * Returns count of pattern in line.
- *
- * @param line line string
- * @param pattern pattern followed in line
- * @return count of pattern in line
- */
- private static int getArrayLength(String line, String pattern) {
- String[] array = line.split(Pattern.quote(pattern));
- int len = array.length;
- if (pattern.equals(SPACE)) {
- for (String str : array) {
- if (str.equals(EMPTY_STRING)) {
- len--;
- }
- }
- }
- return len - 1;
- }
-
- /**
- * Returns array list of string in case of period.
- *
- * @param line line string
- * @return array list of string in case of period
- */
- private static ArrayList<String> getForPeriod(String line) {
- String[] array = line.split(Pattern.quote(PERIOD));
- return getSplitArray(array, PERIOD);
- }
-
- /**
- * Returns array list of string in case of space.
- *
- * @param line line string
- * @return array list of string in case of space
- */
- private static ArrayList<String> getForSpace(String line) {
- String[] array = line.split(SPACE);
- return getSplitArray(array, SPACE);
- }
-
- /**
- * Merges strings to form a new string.
- *
- * @param list list of strings
- * @param pattern pattern
- * @param lineSize line size
- * @return merged string
- */
- private static String merge(ArrayList<String> list, String pattern, int lineSize) {
- StringBuilder builder = new StringBuilder();
- StringBuilder fine = new StringBuilder();
- String append;
- String pre;
- String present = EMPTY_STRING;
- //Add one blank string in list to handle border limit cases.
- list.add(EMPTY_STRING);
- Iterator<String> listIt = list.iterator();
- ArrayList<String> arrayList = new ArrayList<>();
- int length;
- StringBuilder spaces = new StringBuilder();
- while (listIt.hasNext()) {
- pre = present;
- present = listIt.next();
- //check is present string is more than 80 char.
- if (present.length() > SUB_SIZE) {
- int period = getArrayLength(present, PERIOD);
- int space = getArrayLength(present, SPACE);
- if (period > space) {
- // in such case present string should be resolved.
- present = processModifications(present, SUB_SIZE);
- builder.append(present);
- }
- }
- length = builder.length();
- //If length of builder is less than the given length then append
- // it to builder.
- if (length <= lineSize) {
- //fill the space builder to provide proper indentation.
- if (present.equals(EMPTY_STRING)) {
- spaces.append(SPACE);
- }
- //append to builder
- builder.append(present);
- builder.append(pattern);
- fine.append(pre);
- //do not append pattern in case of empty strings.
- if (!pre.equals(EMPTY_STRING)) {
- fine.append(pattern);
- }
- } else {
- // now the length is more than given size so trim the pattern
- // for the string and add it to list,
- fine = getReplacedString(fine, pattern);
- arrayList.add(fine.toString());
- // clear all.
- builder.delete(0, length);
- fine.delete(0, fine.length());
- // append indentation
- if (pattern.contains(PERIOD)) {
- append = NEW_LINE + spaces +
- TWELVE_SPACE_INDENTATION +
- PERIOD;
- } else {
- append = NEW_LINE + spaces + TWELVE_SPACE_INDENTATION;
- }
- // builder needs to move one step forward to fine builder so
- // append present and pre strings to builder with pattern.
- builder.append(append);
- builder.append(pre);
- builder.append(pattern);
- builder.append(present);
- builder.append(pattern);
- fine.append(append);
- fine.append(pre);
- if (!pre.equals(EMPTY_STRING)) {
- fine.append(pattern);
- }
- }
- }
-
- builder = getReplacedString(builder, pattern);
-
- //need to remove extra string added from the builder.
- if (builder.toString().lastIndexOf(pattern) == builder.length() - 1) {
- builder = getReplacedString(builder, pattern);
- }
- arrayList.add(builder.toString());
- fine.delete(0, fine.length());
- for (String str : arrayList) {
- fine.append(str);
- }
- //No need to append extra spaces.
- if (pattern.equals(PERIOD)) {
- return fine.toString();
- }
- return spaces + fine.toString();
- }
-
- /**
- * Trims extra pattern strings for builder string.
- *
- * @param builder builder
- * @param pattern pattern
- * @return modified string
- */
- private static StringBuilder getReplacedString(StringBuilder builder, String
- pattern) {
- String temp = builder.toString();
- temp = trimAtLast(temp, pattern);
- int length = builder.length();
- builder.delete(0, length);
- builder.append(temp);
- return builder;
- }
-
- /**
- * Creates array list to process line string modification.
- *
- * @param array array of strings
- * @param pattern pattern
- * @return list to process line string modification
- */
- private static ArrayList<String> getSplitArray(String[] array, String pattern) {
- ArrayList<String> newArray = new ArrayList<>();
- int count = 0;
- String temp;
- for (String str : array) {
- if (!str.contains(OPEN_CURLY_BRACKET)) {
- if (str.length() > SUB_LINE_SIZE) {
- count = getSplitString(str, newArray, count);
- } else {
- newArray.add(str);
- count++;
- }
- } else {
- if (newArray.isEmpty()) {
- newArray.add(str);
- } else {
- temp = newArray.get(count - 1);
- newArray.remove(count - 1);
- newArray.add(count - 1, temp + pattern + str);
- }
- }
- }
-
- return newArray;
- }
-
- private static int getSplitString(String str,
- ArrayList<String> newArray, int count) {
- String[] array = str.split(SPACE);
- for (String st : array) {
- newArray.add(st + SPACE);
- count++;
- }
- return count;
- }
-
- /**
- * Returns the java Package from package path.
- *
- * @param packagePath package path
- * @return java package
- */
- public static String getJavaPackageFromPackagePath(String packagePath) {
- return packagePath.replace(SLASH, PERIOD);
- }
-
- /**
- * Returns the directory path corresponding to java package.
- *
- * @param packagePath package path
- * @return java package
- */
- public static String getPackageDirPathFromJavaJPackage(String packagePath) {
- return packagePath.replace(PERIOD, SLASH);
- }
-
- /**
- * Returns the YANG identifier name as java identifier with first letter
- * in small.
- *
- * @param yangIdentifier identifier in YANG file.
- * @return corresponding java identifier
- */
- public static String getSmallCase(String yangIdentifier) {
- return yangIdentifier.substring(0, 1).toLowerCase() + yangIdentifier.substring(1);
- }
-
- /**
- * Returns the YANG identifier name as java identifier with first letter
- * in capital.
- *
- * @param yangIdentifier identifier in YANG file
- * @return corresponding java identifier
- */
- public static String getCapitalCase(String yangIdentifier) {
- yangIdentifier = yangIdentifier.substring(0, 1).toUpperCase() + yangIdentifier.substring(1);
- return restrictConsecutiveCapitalCase(yangIdentifier);
- }
-
- /**
- * Restricts consecutive capital cased string as a rule in camel case.
- *
- * @param consecCapitalCaseRemover which requires the restriction of consecutive capital case
- * @return string without consecutive capital case
- */
- private static String restrictConsecutiveCapitalCase(String consecCapitalCaseRemover) {
-
- for (int k = 0; k < consecCapitalCaseRemover.length(); k++) {
- if (k + 1 < consecCapitalCaseRemover.length()) {
- if (Character.isUpperCase(consecCapitalCaseRemover.charAt(k))) {
- if (Character.isUpperCase(consecCapitalCaseRemover.charAt(k + 1))) {
- consecCapitalCaseRemover = consecCapitalCaseRemover.substring(0, k + 1)
- + consecCapitalCaseRemover.substring(k + 1, k + 2).toLowerCase()
- + consecCapitalCaseRemover.substring(k + 2);
- }
- }
- }
- }
- return consecCapitalCaseRemover;
- }
-
- /**
- * Adds prefix, if the string begins with digit or is a java key word.
- *
- * @param camelCasePrefix string for adding prefix
- * @param conflictResolver object of YANG to java naming conflict util
- * @return prefixed camel case string
- */
- private static String addPrefix(String camelCasePrefix, YangToJavaNamingConflictUtil conflictResolver) {
-
- String prefix = getPrefixForIdentifier(conflictResolver);
- if (camelCasePrefix.matches(REGEX_FOR_FIRST_DIGIT)) {
- camelCasePrefix = prefix + camelCasePrefix;
- }
- if (JAVA_KEY_WORDS.contains(camelCasePrefix)) {
- camelCasePrefix = prefix + camelCasePrefix.substring(0, 1).toUpperCase()
- + camelCasePrefix.substring(1);
- }
- return camelCasePrefix;
- }
-
- /**
- * Applies the rule that a string does not end with a capitalized letter and capitalizes
- * the letter next to a number in an array.
- *
- * @param stringArray containing strings for camel case separation
- * @param conflictResolver object of YANG to java naming conflict util
- * @return camel case rule checked string
- */
- private static String applyCamelCaseRule(String[] stringArray, YangToJavaNamingConflictUtil conflictResolver) {
-
- String ruleChecker = stringArray[0].toLowerCase();
- int i;
- if (ruleChecker.matches(REGEX_FOR_FIRST_DIGIT)) {
- i = 0;
- ruleChecker = EMPTY_STRING;
- } else {
- i = 1;
- }
- for (; i < stringArray.length; i++) {
- if (i + 1 == stringArray.length) {
- if (stringArray[i].matches(REGEX_FOR_SINGLE_LETTER)
- || stringArray[i].matches(REGEX_FOR_DIGITS_WITH_SINGLE_LETTER)) {
- ruleChecker = ruleChecker + stringArray[i].toLowerCase();
- break;
- }
- }
- if (stringArray[i].matches(REGEX_FOR_FIRST_DIGIT)) {
- for (int j = 0; j < stringArray[i].length(); j++) {
- char letterCheck = stringArray[i].charAt(j);
- if (Character.isLetter(letterCheck)) {
- stringArray[i] = stringArray[i].substring(0, j)
- + stringArray[i].substring(j, j + 1).toUpperCase() + stringArray[i].substring(j + 1);
- break;
- }
- }
- ruleChecker = ruleChecker + stringArray[i];
- } else {
- ruleChecker = ruleChecker + stringArray[i].substring(0, 1).toUpperCase() + stringArray[i].substring(1);
- }
- }
- String ruleCheckerWithPrefix = addPrefix(ruleChecker, conflictResolver);
- return restrictConsecutiveCapitalCase(ruleCheckerWithPrefix);
- }
-
- /**
- * Resolves the conflict when input has upper case.
- *
- * @param stringArray containing strings for upper case conflict resolver
- * @param conflictResolver object of YANG to java naming conflict util
- * @return camel cased string
- */
- private static String upperCaseConflictResolver(String[] stringArray,
- YangToJavaNamingConflictUtil conflictResolver) {
-
- for (int l = 0; l < stringArray.length; l++) {
- String[] upperCaseSplitArray = stringArray[l].split(REGEX_WITH_UPPERCASE);
- for (int m = 0; m < upperCaseSplitArray.length; m++) {
- if (upperCaseSplitArray[m].matches(REGEX_WITH_SINGLE_CAPITAL_CASE)) {
- int check = m;
- while (check + 1 < upperCaseSplitArray.length) {
- if (upperCaseSplitArray[check + 1].matches(REGEX_WITH_SINGLE_CAPITAL_CASE)) {
- upperCaseSplitArray[check + 1] = upperCaseSplitArray[check + 1].toLowerCase();
- check = check + 1;
- } else if (upperCaseSplitArray[check + 1]
- .matches(REGEX_WITH_SINGLE_CAPITAL_CASE_AND_DIGITS_SMALL_CASES)) {
- upperCaseSplitArray[check + 1] = upperCaseSplitArray[check + 1].toLowerCase();
- break;
- } else {
- break;
- }
- }
- }
- }
- StringBuilder strBuilder = new StringBuilder();
- for (String element : upperCaseSplitArray) {
- strBuilder.append(element);
- }
- stringArray[l] = strBuilder.toString();
- }
- List<String> result = new ArrayList<>();
- for (String element : stringArray) {
- String[] capitalCaseSplitArray = element.split(REGEX_WITH_UPPERCASE);
- for (String letter : capitalCaseSplitArray) {
- String[] arrayForAddition = letter.split(REGEX_WITH_DIGITS);
- List<String> list = Arrays.asList(arrayForAddition);
- for (String str : list) {
- if (str != null && !str.isEmpty()) {
- result.add(str);
- }
- }
- }
- }
- stringArray = result.toArray(new String[result.size()]);
- return applyCamelCaseRule(stringArray, conflictResolver);
- }
-
- /**
- * Returns the YANG identifier name as java identifier.
- *
- * @param yangIdentifier identifier in YANG file
- * @param conflictResolver object of YANG to java naming conflict util
- * @return corresponding java identifier
- */
- public static String getCamelCase(String yangIdentifier, YangToJavaNamingConflictUtil conflictResolver) {
-
- if (conflictResolver != null) {
- String replacementForHyphen = conflictResolver.getReplacementForHyphen();
- String replacementForPeriod = conflictResolver.getReplacementForPeriod();
- String replacementForUnderscore = conflictResolver.getReplacementForUnderscore();
- if (replacementForPeriod != null) {
- yangIdentifier = yangIdentifier.replaceAll(REGEX_FOR_PERIOD,
- PERIOD + replacementForPeriod.toLowerCase() + PERIOD);
- }
- if (replacementForUnderscore != null) {
- yangIdentifier = yangIdentifier.replaceAll(REGEX_FOR_UNDERSCORE,
- UNDER_SCORE + replacementForUnderscore.toLowerCase() +
- UNDER_SCORE);
- }
- if (replacementForHyphen != null) {
- yangIdentifier = yangIdentifier.replaceAll(REGEX_FOR_HYPHEN,
- HYPHEN + replacementForHyphen.toLowerCase() + HYPHEN);
- }
- }
- yangIdentifier = yangIdentifier.replaceAll(REGEX_FOR_IDENTIFIER_SPECIAL_CHAR, COLON);
- String[] strArray = yangIdentifier.split(COLON);
- if (strArray[0].isEmpty()) {
- List<String> stringArrangement = new ArrayList<>();
- stringArrangement.addAll(Arrays.asList(strArray).subList(1, strArray.length));
- strArray = stringArrangement.toArray(new String[stringArrangement.size()]);
- }
- return upperCaseConflictResolver(strArray, conflictResolver);
- }
-
- /**
- * Prefix for adding with identifier and namespace, when it is a java keyword or starting with digits.
- *
- * @param conflictResolver object of YANG to java naming conflict util
- * @return prefix which needs to be added
- */
- public static String getPrefixForIdentifier(YangToJavaNamingConflictUtil conflictResolver) {
-
- String prefixForIdentifier = null;
- if (conflictResolver != null) {
- prefixForIdentifier = conflictResolver.getPrefixForIdentifier();
- }
- if (prefixForIdentifier != null) {
- prefixForIdentifier = prefixForIdentifier.replaceAll
- (REGEX_WITH_ALL_SPECIAL_CHAR, COLON);
- String[] strArray = prefixForIdentifier.split(COLON);
- try {
- if (strArray[0].isEmpty()) {
- List<String> stringArrangement = new ArrayList<>();
- stringArrangement.addAll(Arrays.asList(strArray).subList(1, strArray.length));
- strArray = stringArrangement.toArray(new String[stringArrangement.size()]);
- }
- prefixForIdentifier = strArray[0];
- for (int j = 1; j < strArray.length; j++) {
- prefixForIdentifier = prefixForIdentifier + strArray[j].substring(0, 1).toUpperCase() +
- strArray[j].substring(1);
- }
- } catch (ArrayIndexOutOfBoundsException outOfBoundsException) {
- throw new TranslatorException("The given prefix in pom.xml is invalid.");
- }
- } else {
- prefixForIdentifier = YANG_AUTO_PREFIX;
- }
- return prefixForIdentifier;
- }
-
- /**
- * Removes empty directory.
- *
- * @param path path to be checked
- */
- public static void removeEmptyDirectory(String path) {
- int index;
- while (path != null && !path.isEmpty()) {
- if (!removeDirectory(path)) {
- break;
- } else {
- index = path.lastIndexOf(SLASH);
- path = path.substring(0, index);
- }
- }
- }
-
- private static boolean removeDirectory(String path) {
- File dir = new File(path);
- boolean isDeleted = false;
- if (dir.isDirectory()) {
- File[] files = dir.listFiles();
- if (files != null && files.length == 0) {
- isDeleted = dir.delete();
- } else if (files != null && files.length == 1) {
- if ("package-info.java".equals(files[0].getName())
- || files[0].getName().endsWith("-temp")) {
- isDeleted = dir.delete();
- }
- }
- }
- return isDeleted;
- }
-}
diff --git a/plugin/src/main/java/org/onosproject/yangutils/utils/io/impl/package-info.java b/plugin/src/main/java/org/onosproject/yangutils/utils/io/impl/package-info.java
deleted file mode 100644
index a128fa2..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/utils/io/impl/package-info.java
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * File system utilities implementation.
- */
-package org.onosproject.yangutils.utils.io.impl;
diff --git a/plugin/src/main/java/org/onosproject/yangutils/utils/io/package-info.java b/plugin/src/main/java/org/onosproject/yangutils/utils/io/package-info.java
deleted file mode 100644
index 856653e..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/utils/io/package-info.java
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * File system utilities.
- */
-package org.onosproject.yangutils.utils.io;
diff --git a/plugin/src/main/java/org/onosproject/yangutils/utils/package-info.java b/plugin/src/main/java/org/onosproject/yangutils/utils/package-info.java
deleted file mode 100644
index 2123da0..0000000
--- a/plugin/src/main/java/org/onosproject/yangutils/utils/package-info.java
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * Utilities for YANG maven plugin.
- */
-package org.onosproject.yangutils.utils;
diff --git a/plugin/src/main/resources/GeneratedYang.g4 b/plugin/src/main/resources/GeneratedYang.g4
deleted file mode 100644
index 0362cb0..0000000
--- a/plugin/src/main/resources/GeneratedYang.g4
+++ /dev/null
@@ -1,1347 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * This is a YANG grammar for parser based on which ANTLR will generate YANG parser.
- */
-
-grammar GeneratedYang;
-import YangLexer;
-
-@header {
-package org.onosproject.yangutils.parser.antlrgencode;
-}
-
- yangfile : moduleStatement EOF
- | subModuleStatement EOF;
-
- /**
- * module-stmt = optsep module-keyword sep identifier-arg-str
- * optsep
- * "{" stmtsep
- * module-header-stmts
- * linkage-stmts
- * meta-stmts
- * revision-stmts
- * body-stmts
- * "}" optsep
- */
-
- moduleStatement : MODULE_KEYWORD identifier LEFT_CURLY_BRACE moduleBody RIGHT_CURLY_BRACE;
-
- moduleBody : moduleHeaderStatement linkageStatements metaStatements revisionStatements bodyStatements;
-
- /**
- * module-header-stmts = ;; these stmts can appear in any order
- * [yang-version-stmt stmtsep]
- * namespace-stmt stmtsep
- * prefix-stmt stmtsep
- */
-
- moduleHeaderStatement : yangVersionStatement? namespaceStatement prefixStatement
- | yangVersionStatement? prefixStatement namespaceStatement
- | namespaceStatement yangVersionStatement? prefixStatement
- | namespaceStatement prefixStatement yangVersionStatement?
- | prefixStatement namespaceStatement yangVersionStatement?
- | prefixStatement yangVersionStatement? namespaceStatement
- ;
-
- /**
- * linkage-stmts = ;; these stmts can appear in any order
- * *(import-stmt stmtsep)
- * *(include-stmt stmtsep)
- */
- linkageStatements : (importStatement
- | includeStatement)*;
-
- /**
- * meta-stmts = ;; these stmts can appear in any order
- * [organization-stmt stmtsep]
- * [contact-stmt stmtsep]
- * [description-stmt stmtsep]
- * [reference-stmt stmtsep]
- */
- metaStatements : organizationStatement? contactStatement? descriptionStatement? referenceStatement?
- | organizationStatement? contactStatement? referenceStatement? descriptionStatement?
- | organizationStatement? descriptionStatement? contactStatement? referenceStatement?
- | organizationStatement? descriptionStatement? referenceStatement? contactStatement?
- | organizationStatement? referenceStatement? contactStatement? descriptionStatement?
- | organizationStatement? referenceStatement? descriptionStatement? contactStatement?
- | contactStatement? organizationStatement? descriptionStatement? referenceStatement?
- | contactStatement? organizationStatement? referenceStatement? descriptionStatement?
- | contactStatement? referenceStatement? organizationStatement? descriptionStatement?
- | contactStatement? referenceStatement? descriptionStatement? organizationStatement?
- | contactStatement? descriptionStatement? referenceStatement? organizationStatement?
- | contactStatement? descriptionStatement? organizationStatement? referenceStatement?
- | referenceStatement? contactStatement? organizationStatement? descriptionStatement?
- | referenceStatement? contactStatement? descriptionStatement? organizationStatement?
- | referenceStatement? organizationStatement? contactStatement? descriptionStatement?
- | referenceStatement? organizationStatement? descriptionStatement? contactStatement?
- | referenceStatement? descriptionStatement? organizationStatement? contactStatement?
- | referenceStatement? descriptionStatement? contactStatement? organizationStatement?
- | descriptionStatement? referenceStatement? contactStatement? organizationStatement?
- | descriptionStatement? referenceStatement? organizationStatement? contactStatement?
- | descriptionStatement? contactStatement? referenceStatement? organizationStatement?
- | descriptionStatement? contactStatement? organizationStatement? referenceStatement?
- | descriptionStatement? organizationStatement? contactStatement? referenceStatement?
- | descriptionStatement? organizationStatement? referenceStatement? contactStatement?
- ;
-
- // revision-stmts = *(revision-stmt stmtsep)
- revisionStatements : revisionStatement*;
-
- /**
- * body-stmts = *((extension-stmt /
- * feature-stmt /
- * identity-stmt /
- * typedef-stmt /
- * grouping-stmt /
- * data-def-stmt /
- * augment-stmt /
- * rpc-stmt /
- * notification-stmt /
- * deviation-stmt) stmtsep)
- */
- bodyStatements : (extensionStatement
- | featureStatement
- | identityStatement
- | typedefStatement
- | groupingStatement
- | dataDefStatement
- | augmentStatement
- | rpcStatement
- | notificationStatement
- | deviationStatement
- | compilerAnnotationStatement)*
- ;
-
- /**
- * yang-version-stmt = yang-version-keyword sep yang-version-arg-str
- * optsep stmtend
- */
- yangVersionStatement : YANG_VERSION_KEYWORD version STMTEND;
-
-
- /**
- * namespace-stmt = namespace-keyword sep uri-str optsep stmtend
- * For namespace validation TODO in Listener
- */
- namespaceStatement : NAMESPACE_KEYWORD string STMTEND;
-
- /**
- * prefix-stmt = prefix-keyword sep prefix-arg-str
- * optsep stmtend
- */
- prefixStatement : PREFIX_KEYWORD identifier STMTEND;
-
- /**
- * import-stmt = import-keyword sep identifier-arg-str optsep
- * "{" stmtsep
- * prefix-stmt stmtsep
- * [revision-date-stmt stmtsep]
- * "}"
- */
- importStatement : IMPORT_KEYWORD identifier LEFT_CURLY_BRACE importStatementBody RIGHT_CURLY_BRACE;
-
- importStatementBody : prefixStatement revisionDateStatement?;
-
- // revision-date-stmt = revision-date-keyword sep revision-date stmtend
- revisionDateStatement : REVISION_DATE_KEYWORD dateArgumentString STMTEND;
-
- /**
- * include-stmt = include-keyword sep identifier-arg-str optsep
- * (";" /
- * "{" stmtsep
- * [revision-date-stmt stmtsep]
- * "}")
- */
- includeStatement : INCLUDE_KEYWORD identifier (STMTEND | LEFT_CURLY_BRACE revisionDateStatement? RIGHT_CURLY_BRACE);
-
- /**
- * organization-stmt = organization-keyword sep string
- * optsep stmtend
- */
- organizationStatement : ORGANIZATION_KEYWORD string STMTEND;
-
- // contact-stmt = contact-keyword sep string optsep stmtend
- contactStatement : CONTACT_KEYWORD string STMTEND;
-
- // description-stmt = description-keyword sep string optsep stmtend
- descriptionStatement : DESCRIPTION_KEYWORD string STMTEND;
-
- // reference-stmt = reference-keyword sep string optsep stmtend
- referenceStatement : REFERENCE_KEYWORD string STMTEND;
-
- /**
- * revision-stmt = revision-keyword sep revision-date optsep
- * (";" /
- * "{" stmtsep
- * [description-stmt stmtsep]
- * [reference-stmt stmtsep]
- * "}")
- */
- revisionStatement : REVISION_KEYWORD dateArgumentString (STMTEND | LEFT_CURLY_BRACE revisionStatementBody RIGHT_CURLY_BRACE);
- revisionStatementBody : descriptionStatement? referenceStatement?;
-
- /**
- * submodule-stmt = optsep submodule-keyword sep identifier-arg-str
- * optsep
- * "{" stmtsep
- * submodule-header-stmts
- * linkage-stmts
- * meta-stmts
- * revision-stmts
- * body-stmts
- * "}" optsep
- */
- subModuleStatement : SUBMODULE_KEYWORD identifier LEFT_CURLY_BRACE submoduleBody RIGHT_CURLY_BRACE;
- submoduleBody : submoduleHeaderStatement linkageStatements metaStatements revisionStatements bodyStatements;
-
- /** submodule-header-stmts =
- * ;; these stmts can appear in any order
- * [yang-version-stmt stmtsep]
- * belongs-to-stmt stmtsep
- */
- submoduleHeaderStatement : yangVersionStatement? belongstoStatement
- | belongstoStatement yangVersionStatement?
- ;
-
- /**
- * belongs-to-stmt = belongs-to-keyword sep identifier-arg-str
- * optsep
- * "{" stmtsep
- * prefix-stmt stmtsep
- * "}"
- */
- belongstoStatement : BELONGS_TO_KEYWORD identifier LEFT_CURLY_BRACE belongstoStatementBody RIGHT_CURLY_BRACE;
- belongstoStatementBody : prefixStatement;
-
- /**
- * extension-stmt = extension-keyword sep identifier-arg-str optsep
- * (";" /
- * "{" stmtsep
- * ;; these stmts can appear in any order
- * [argument-stmt stmtsep]
- * [status-stmt stmtsep]
- * [description-stmt stmtsep]
- * [reference-stmt stmtsep]
- * "}")
- */
- extensionStatement : EXTENSION_KEYWORD identifier (STMTEND | LEFT_CURLY_BRACE extensionBody RIGHT_CURLY_BRACE);
- extensionBody : argumentStatement? statusStatement? descriptionStatement? referenceStatement?
- | argumentStatement? statusStatement? referenceStatement? descriptionStatement?
- | argumentStatement? descriptionStatement? statusStatement? referenceStatement?
- | argumentStatement? descriptionStatement? referenceStatement? statusStatement?
- | argumentStatement? referenceStatement? descriptionStatement? statusStatement?
- | argumentStatement? referenceStatement? statusStatement? descriptionStatement?
- | statusStatement? referenceStatement? argumentStatement? descriptionStatement?
- | statusStatement? referenceStatement? descriptionStatement? argumentStatement?
- | statusStatement? descriptionStatement? referenceStatement? argumentStatement?
- | statusStatement? descriptionStatement? argumentStatement? referenceStatement?
- | statusStatement? argumentStatement? referenceStatement? descriptionStatement?
- | statusStatement? argumentStatement? descriptionStatement? referenceStatement?
- | descriptionStatement? argumentStatement? statusStatement? referenceStatement?
- | descriptionStatement? argumentStatement? referenceStatement? statusStatement?
- | descriptionStatement? statusStatement? argumentStatement? referenceStatement?
- | descriptionStatement? statusStatement? referenceStatement? argumentStatement?
- | descriptionStatement? referenceStatement? statusStatement? argumentStatement?
- | descriptionStatement? referenceStatement? argumentStatement? statusStatement?
- | referenceStatement? descriptionStatement? argumentStatement? statusStatement?
- | referenceStatement? descriptionStatement? statusStatement? argumentStatement?
- | referenceStatement? statusStatement? argumentStatement? descriptionStatement?
- | referenceStatement? statusStatement? descriptionStatement? argumentStatement?
- | referenceStatement? argumentStatement? descriptionStatement? statusStatement?
- | referenceStatement? argumentStatement? statusStatement? descriptionStatement?
- ;
-
- /**
- * argument-stmt = argument-keyword sep identifier-arg-str optsep
- * (";" /
- * "{" stmtsep
- * [yin-element-stmt stmtsep]
- * "}")
- */
- argumentStatement : ARGUMENT_KEYWORD identifier (STMTEND | LEFT_CURLY_BRACE argumentBody RIGHT_CURLY_BRACE);
- argumentBody : yinElementStatement?;
-
- /**
- * yin-element-stmt = yin-element-keyword sep yin-element-arg-str
- * stmtend
- */
- yinElementStatement : YIN_ELEMENT_KEYWORD (TRUE_KEYWORD | FALSE_KEYWORD) STMTEND;
-
- /**
- * identity-stmt = identity-keyword sep identifier-arg-str optsep
- * (";" /
- * "{" stmtsep
- * ;; these stmts can appear in any order
- * [base-stmt stmtsep]
- * [status-stmt stmtsep]
- * [description-stmt stmtsep]
- * [reference-stmt stmtsep]
- * "}")
- */
- identityStatement : IDENTITY_KEYWORD identifier (STMTEND | LEFT_CURLY_BRACE identityBody RIGHT_CURLY_BRACE);
- identityBody : baseStatement? statusStatement? descriptionStatement? referenceStatement?
- | baseStatement? statusStatement? referenceStatement? descriptionStatement?
- | baseStatement? descriptionStatement? statusStatement? referenceStatement?
- | baseStatement? descriptionStatement? referenceStatement? statusStatement?
- | baseStatement? referenceStatement? descriptionStatement? statusStatement?
- | baseStatement? referenceStatement? statusStatement? descriptionStatement?
- | referenceStatement? baseStatement? statusStatement? descriptionStatement?
- | referenceStatement? baseStatement? descriptionStatement? statusStatement?
- | referenceStatement? statusStatement? baseStatement? descriptionStatement?
- | referenceStatement? statusStatement? descriptionStatement? baseStatement?
- | referenceStatement? descriptionStatement? statusStatement? baseStatement?
- | referenceStatement? descriptionStatement? baseStatement? statusStatement?
- | descriptionStatement? referenceStatement? statusStatement? baseStatement?
- | descriptionStatement? referenceStatement? statusStatement? baseStatement?
- | descriptionStatement? referenceStatement? baseStatement? statusStatement?
- | descriptionStatement? statusStatement? baseStatement? referenceStatement?
- | descriptionStatement? statusStatement? referenceStatement? baseStatement?
- | descriptionStatement? baseStatement? referenceStatement? statusStatement?
- | descriptionStatement? baseStatement? statusStatement? referenceStatement?
- | statusStatement? baseStatement? descriptionStatement? referenceStatement?
- | statusStatement? baseStatement? referenceStatement? descriptionStatement?
- | statusStatement? descriptionStatement? baseStatement? referenceStatement?
- | statusStatement? descriptionStatement? referenceStatement? baseStatement?
- | statusStatement? referenceStatement? descriptionStatement? baseStatement?
- | statusStatement? referenceStatement? baseStatement? descriptionStatement?
- ;
-
- /**
- * base-stmt = base-keyword sep identifier-ref-arg-str
- * optsep stmtend*
- * identifier-ref-arg = [prefix ":"] identifier
- */
- baseStatement : BASE_KEYWORD string STMTEND;
-
- /**
- * feature-stmt = feature-keyword sep identifier-arg-str optsep
- * (";" /
- * "{" stmtsep
- * ;; these stmts can appear in any order
- * *(if-feature-stmt stmtsep)
- * [status-stmt stmtsep]
- * [description-stmt stmtsep]
- * [reference-stmt stmtsep]
- * "}")
- */
- featureStatement : FEATURE_KEYWORD string (STMTEND | LEFT_CURLY_BRACE featureBody RIGHT_CURLY_BRACE);
- featureBody : ifFeatureStatement* statusStatement? descriptionStatement? referenceStatement?
- | ifFeatureStatement* statusStatement? referenceStatement? descriptionStatement?
- | ifFeatureStatement* descriptionStatement? statusStatement? referenceStatement?
- | ifFeatureStatement* descriptionStatement? referenceStatement? statusStatement?
- | ifFeatureStatement* referenceStatement? statusStatement? descriptionStatement?
- | ifFeatureStatement* referenceStatement? descriptionStatement? statusStatement?
- | statusStatement? ifFeatureStatement* descriptionStatement? referenceStatement?
- | statusStatement? ifFeatureStatement* referenceStatement? descriptionStatement?
- | statusStatement? descriptionStatement? ifFeatureStatement* referenceStatement?
- | statusStatement? descriptionStatement? referenceStatement? ifFeatureStatement*
- | statusStatement? referenceStatement? ifFeatureStatement* descriptionStatement?
- | statusStatement? referenceStatement? descriptionStatement? ifFeatureStatement*
- | descriptionStatement? ifFeatureStatement* statusStatement? referenceStatement?
- | descriptionStatement? ifFeatureStatement* referenceStatement? statusStatement?
- | descriptionStatement? statusStatement? ifFeatureStatement* referenceStatement?
- | descriptionStatement? statusStatement? referenceStatement? ifFeatureStatement*
- | descriptionStatement? referenceStatement* statusStatement? ifFeatureStatement*
- | descriptionStatement? referenceStatement* ifFeatureStatement? statusStatement?
- | referenceStatement? ifFeatureStatement* statusStatement? descriptionStatement?
- | referenceStatement? ifFeatureStatement* descriptionStatement? statusStatement?
- | referenceStatement? descriptionStatement? statusStatement? ifFeatureStatement*
- | referenceStatement? descriptionStatement? ifFeatureStatement* statusStatement?
- | referenceStatement? statusStatement? descriptionStatement? ifFeatureStatement*
- | referenceStatement? statusStatement? ifFeatureStatement* descriptionStatement?
- ;
-
- /**
- * data-def-stmt = container-stmt /
- * leaf-stmt /
- * leaf-list-stmt /
- * list-stmt /
- * choice-stmt /
- * anyxml-stmt /
- * uses-stmt
- */
- dataDefStatement : containerStatement
- | leafStatement
- | leafListStatement
- | listStatement
- | choiceStatement
- | anyxmlStatement
- | usesStatement;
-
- /**
- * if-feature-stmt = if-feature-keyword sep identifier-ref-arg-str
- * optsep stmtend
- */
- ifFeatureStatement : IF_FEATURE_KEYWORD string STMTEND;
-
- /**
- * units-stmt = units-keyword sep string optsep stmtend
- */
- unitsStatement : UNITS_KEYWORD string STMTEND;
-
- /**
- * typedef-stmt = typedef-keyword sep identifier-arg-str optsep
- * "{" stmtsep
- * ;; these stmts can appear in any order
- * type-stmt stmtsep
- * [units-stmt stmtsep]
- * [default-stmt stmtsep]
- * [status-stmt stmtsep]
- * [description-stmt stmtsep]
- * [reference-stmt stmtsep]
- * "}"
- * TODO : 0..1 occurance to be validated in listener
- */
- typedefStatement : TYPEDEF_KEYWORD identifier LEFT_CURLY_BRACE
- (typeStatement | unitsStatement | defaultStatement | statusStatement | descriptionStatement | referenceStatement)*
- RIGHT_CURLY_BRACE;
-
- /**
- * type-stmt = type-keyword sep identifier-ref-arg-str optsep
- * (";" /
- * "{" stmtsep
- * type-body-stmts
- * "}")
- */
- typeStatement : TYPE_KEYWORD string (STMTEND | LEFT_CURLY_BRACE typeBodyStatements RIGHT_CURLY_BRACE);
-
- /**
- * type-body-stmts = numerical-restrictions /
- * decimal64-specification /
- * string-restrictions /
- * enum-specification /
- * leafref-specification /
- * identityref-specification /
- * instance-identifier-specification /
- * bits-specification /
- * union-specification
- *
- */
- typeBodyStatements : numericalRestrictions | decimal64Specification | stringRestrictions | enumSpecification
- | leafrefSpecification | identityrefSpecification | instanceIdentifierSpecification
- | bitsSpecification | unionSpecification;
-
- /**
- * decimal64-specification = ;; these stmts can appear in any order
- * fraction-digits-stmt
- * [range-stmt]
- */
- decimal64Specification : fractionDigitStatement rangeStatement?;
-
- /**
- * fraction-digits-stmt = fraction-digits-keyword sep
- * fraction-digits-arg-str stmtend
- *
- * fraction-digits-arg-str = < a string that matches the rule
- * fraction-digits-arg >
- *
- * fraction-digits-arg = ("1" ["0" / "1" / "2" / "3" / "4" /
- * "5" / "6" / "7" / "8"])
- * / "2" / "3" / "4" / "5" / "6" / "7" / "8" / "9"
- */
- fractionDigitStatement : FRACTION_DIGITS_KEYWORD fraction STMTEND;
-
- /**
- * numerical-restrictions = range-stmt stmtsep
- */
- numericalRestrictions : rangeStatement;
-
- /**
- * range-stmt = range-keyword sep range-arg-str optsep
- * (";" /
- * "{" stmtsep
- * ;; these stmts can appear in any order
- * [error-message-stmt stmtsep]
- * [error-app-tag-stmt stmtsep]
- * [description-stmt stmtsep]
- * [reference-stmt stmtsep]
- * "}")
- */
- rangeStatement : RANGE_KEYWORD range (STMTEND | LEFT_CURLY_BRACE commonStatements RIGHT_CURLY_BRACE);
-
- commonStatements : errorMessageStatement? errorAppTagStatement? descriptionStatement? referenceStatement?
- | errorMessageStatement? errorAppTagStatement? referenceStatement? descriptionStatement?
- | errorMessageStatement? descriptionStatement? errorAppTagStatement? referenceStatement?
- | errorMessageStatement? descriptionStatement? referenceStatement? errorAppTagStatement?
- | errorMessageStatement? referenceStatement? errorAppTagStatement? descriptionStatement?
- | errorMessageStatement? referenceStatement? descriptionStatement? errorAppTagStatement?
- | errorAppTagStatement? errorMessageStatement? descriptionStatement? referenceStatement?
- | errorAppTagStatement? errorMessageStatement? referenceStatement? descriptionStatement?
- | errorAppTagStatement? descriptionStatement? descriptionStatement? errorMessageStatement?
- | errorAppTagStatement? descriptionStatement? errorMessageStatement? descriptionStatement?
- | errorAppTagStatement? referenceStatement? errorMessageStatement? descriptionStatement?
- | errorAppTagStatement? referenceStatement? descriptionStatement? errorMessageStatement?
- | descriptionStatement? errorMessageStatement? errorAppTagStatement? referenceStatement?
- | descriptionStatement? errorMessageStatement? referenceStatement? errorAppTagStatement?
- | descriptionStatement? errorAppTagStatement? errorMessageStatement? referenceStatement?
- | descriptionStatement? errorAppTagStatement? referenceStatement? errorMessageStatement?
- | descriptionStatement? referenceStatement? errorMessageStatement? errorAppTagStatement?
- | descriptionStatement? referenceStatement? errorAppTagStatement? errorMessageStatement?
- | referenceStatement? errorMessageStatement? descriptionStatement? errorAppTagStatement?
- | referenceStatement? errorMessageStatement? errorAppTagStatement? descriptionStatement?
- | referenceStatement? errorAppTagStatement? descriptionStatement? errorMessageStatement?
- | referenceStatement? errorAppTagStatement? errorMessageStatement? descriptionStatement?
- | referenceStatement? descriptionStatement? errorMessageStatement? errorAppTagStatement?
- | referenceStatement? descriptionStatement? errorAppTagStatement? errorMessageStatement?
- ;
-
- /**
- * string-restrictions = ;; these stmts can appear in any order
- * [length-stmt stmtsep]
- * *(pattern-stmt stmtsep)
- */
- stringRestrictions : ((lengthStatement)? (patternStatement)*) | ((patternStatement)* (lengthStatement)?);
-
- /**
- * length-stmt = length-keyword sep length-arg-str optsep
- * (";" /
- * "{" stmtsep
- * ;; these stmts can appear in any order
- * [error-message-stmt stmtsep]
- * [error-app-tag-stmt stmtsep]
- * [description-stmt stmtsep]
- * [reference-stmt stmtsep]
- * "}")
- */
- lengthStatement : LENGTH_KEYWORD length
- (STMTEND | LEFT_CURLY_BRACE commonStatements RIGHT_CURLY_BRACE);
-
- /**
- * pattern-stmt = pattern-keyword sep string optsep
- * (";" /
- * "{" stmtsep
- * ;; these stmts can appear in any order
- * [error-message-stmt stmtsep]
- * [error-app-tag-stmt stmtsep]
- * [description-stmt stmtsep]
- * [reference-stmt stmtsep]
- * "}")
- */
- patternStatement : PATTERN_KEYWORD string (STMTEND | LEFT_CURLY_BRACE commonStatements RIGHT_CURLY_BRACE);
-
- /**
- * default-stmt = default-keyword sep string stmtend
- */
- defaultStatement : DEFAULT_KEYWORD string STMTEND;
-
- /**
- * enum-specification = 1*(enum-stmt stmtsep)
- */
- enumSpecification : enumStatement+;
-
- /**
- * enum-stmt = enum-keyword sep string optsep
- * (";" /
- * "{" stmtsep
- * ;; these stmts can appear in any order
- * [value-stmt stmtsep]
- * [status-stmt stmtsep]
- * [description-stmt stmtsep]
- * [reference-stmt stmtsep]
- * "}")
- */
- enumStatement : ENUM_KEYWORD string (STMTEND | LEFT_CURLY_BRACE enumStatementBody RIGHT_CURLY_BRACE);
-
- enumStatementBody : valueStatement? statusStatement? descriptionStatement? referenceStatement?
- | valueStatement? statusStatement? referenceStatement? descriptionStatement?
- | valueStatement? descriptionStatement? statusStatement? referenceStatement?
- | valueStatement? descriptionStatement? referenceStatement? statusStatement?
- | valueStatement? referenceStatement? statusStatement? descriptionStatement?
- | valueStatement? referenceStatement? descriptionStatement? statusStatement?
- | statusStatement? valueStatement? descriptionStatement? referenceStatement?
- | statusStatement? valueStatement? referenceStatement? descriptionStatement?
- | statusStatement? descriptionStatement? descriptionStatement? valueStatement?
- | statusStatement? descriptionStatement? valueStatement? descriptionStatement?
- | statusStatement? referenceStatement? valueStatement? descriptionStatement?
- | statusStatement? referenceStatement? descriptionStatement? valueStatement?
- | descriptionStatement? valueStatement? statusStatement? referenceStatement?
- | descriptionStatement? valueStatement? referenceStatement? statusStatement?
- | descriptionStatement? statusStatement? valueStatement? referenceStatement?
- | descriptionStatement? statusStatement? referenceStatement? valueStatement?
- | descriptionStatement? referenceStatement? valueStatement? statusStatement?
- | descriptionStatement? referenceStatement? statusStatement? valueStatement?
- | referenceStatement? valueStatement? descriptionStatement? statusStatement?
- | referenceStatement? valueStatement? statusStatement? descriptionStatement?
- | referenceStatement? statusStatement? descriptionStatement? valueStatement?
- | referenceStatement? statusStatement? valueStatement? descriptionStatement?
- | referenceStatement? descriptionStatement? valueStatement? statusStatement?
- | referenceStatement? descriptionStatement? statusStatement? valueStatement?
- ;
-
- /**
- * leafref-specification =
- * ;; these stmts can appear in any order
- * path-stmt stmtsep
- * [require-instance-stmt stmtsep]
- */
- leafrefSpecification : (pathStatement (requireInstanceStatement)?) | ((requireInstanceStatement)? pathStatement);
-
- /**
- * path-stmt = path-keyword sep path-arg-str stmtend
- */
- pathStatement : PATH_KEYWORD path STMTEND;
-
- /**
- * require-instance-stmt = require-instance-keyword sep
- * require-instance-arg-str stmtend
- * require-instance-arg-str = < a string that matches the rule
- * require-instance-arg >
- * require-instance-arg = true-keyword / false-keyword
- */
- requireInstanceStatement : REQUIRE_INSTANCE_KEYWORD requireInstance STMTEND;
-
- /**
- * instance-identifier-specification =
- * [require-instance-stmt stmtsep]
- */
- instanceIdentifierSpecification : requireInstanceStatement?;
-
- /**
- * identityref-specification =
- * base-stmt stmtsep
- */
- identityrefSpecification : baseStatement;
-
- /**
- * union-specification = 1*(type-stmt stmtsep)
- */
- unionSpecification : typeStatement+;
-
- /**
- * bits-specification = 1*(bit-stmt stmtsep)
- */
- bitsSpecification : bitStatement+;
-
- /**
- * bit-stmt = bit-keyword sep identifier-arg-str optsep
- * (";" /
- * "{" stmtsep
- * ;; these stmts can appear in any order
- * [position-stmt stmtsep]
- * [status-stmt stmtsep]
- * [description-stmt stmtsep]
- * [reference-stmt stmtsep]
- * "}"
- * "}")
- */
- bitStatement : BIT_KEYWORD identifier (STMTEND | LEFT_CURLY_BRACE bitBodyStatement RIGHT_CURLY_BRACE);
-
- bitBodyStatement : positionStatement? statusStatement? descriptionStatement? referenceStatement?
- | positionStatement? statusStatement? referenceStatement? descriptionStatement?
- | positionStatement? descriptionStatement? statusStatement? referenceStatement?
- | positionStatement? descriptionStatement? referenceStatement? statusStatement?
- | positionStatement? referenceStatement? statusStatement? descriptionStatement?
- | positionStatement? referenceStatement? descriptionStatement? statusStatement?
- | statusStatement? positionStatement? descriptionStatement? referenceStatement?
- | statusStatement? positionStatement? referenceStatement? descriptionStatement?
- | statusStatement? descriptionStatement? descriptionStatement? positionStatement?
- | statusStatement? descriptionStatement? positionStatement? descriptionStatement?
- | statusStatement? referenceStatement? positionStatement? descriptionStatement?
- | statusStatement? referenceStatement? descriptionStatement? positionStatement?
- | descriptionStatement? positionStatement? statusStatement? referenceStatement?
- | descriptionStatement? positionStatement? referenceStatement? statusStatement?
- | descriptionStatement? statusStatement? positionStatement? referenceStatement?
- | descriptionStatement? statusStatement? referenceStatement? positionStatement?
- | descriptionStatement? referenceStatement? positionStatement? statusStatement?
- | descriptionStatement? referenceStatement? statusStatement? positionStatement?
- | referenceStatement? positionStatement? descriptionStatement? statusStatement?
- | referenceStatement? positionStatement? statusStatement? descriptionStatement?
- | referenceStatement? statusStatement? descriptionStatement? positionStatement?
- | referenceStatement? statusStatement? positionStatement? descriptionStatement?
- | referenceStatement? descriptionStatement? positionStatement? statusStatement?
- | referenceStatement? descriptionStatement? statusStatement? positionStatement?
- ;
-
- /**
- * position-stmt = position-keyword sep
- * position-value-arg-str stmtend
- * position-value-arg-str = < a string that matches the rule
- * position-value-arg >
- * position-value-arg = non-negative-integer-value
- */
- positionStatement : POSITION_KEYWORD position STMTEND;
-
- /**
- * status-stmt = status-keyword sep status-arg-str stmtend
- * status-arg-str = < a string that matches the rule
- * status-arg >
- * status-arg = current-keyword /
- * obsolete-keyword /
- * deprecated-keyword
- */
- statusStatement : STATUS_KEYWORD status STMTEND;
-
- /**
- * config-stmt = config-keyword sep
- * config-arg-str stmtend
- * config-arg-str = < a string that matches the rule
- * config-arg >
- * config-arg = true-keyword / false-keyword
- */
- configStatement : CONFIG_KEYWORD config STMTEND;
-
- /**
- * mandatory-stmt = mandatory-keyword sep
- * mandatory-arg-str stmtend
- *
- * mandatory-arg-str = < a string that matches the rule
- * mandatory-arg >
- *
- * mandatory-arg = true-keyword / false-keyword
- */
- mandatoryStatement : MANDATORY_KEYWORD mandatory STMTEND;
-
- /**
- * presence-stmt = presence-keyword sep string stmtend
- */
- presenceStatement : PRESENCE_KEYWORD string STMTEND;
-
- /**
- * ordered-by-stmt = ordered-by-keyword sep
- * ordered-by-arg-str stmtend
- *
- * ordered-by-arg-str = < a string that matches the rule
- * ordered-by-arg >
- *
- * ordered-by-arg = user-keyword / system-keyword
- */
- orderedByStatement : ORDERED_BY_KEYWORD orderedBy STMTEND;
-
- /**
- * must-stmt = must-keyword sep string optsep
- * (";" /
- * "{" stmtsep
- * ;; these stmts can appear in any order
- * [error-message-stmt stmtsep]
- * [error-app-tag-stmt stmtsep]
- * [description-stmt stmtsep]
- * [reference-stmt stmtsep]
- * "}")
- */
- mustStatement : MUST_KEYWORD string (STMTEND | LEFT_CURLY_BRACE commonStatements RIGHT_CURLY_BRACE);
-
- /**
- * error-message-stmt = error-message-keyword sep string stmtend
- */
- errorMessageStatement : ERROR_MESSAGE_KEYWORD string STMTEND;
-
- /**
- * error-app-tag-stmt = error-app-tag-keyword sep string stmtend
- */
- errorAppTagStatement : ERROR_APP_TAG_KEYWORD string STMTEND;
-
- /**
- * min-elements-stmt = min-elements-keyword sep
- * min-value-arg-str stmtend
- * min-value-arg-str = < a string that matches the rule
- * min-value-arg >
- * min-value-arg = non-negative-integer-value
- */
- minElementsStatement : MIN_ELEMENTS_KEYWORD minValue STMTEND;
-
- /**
- * max-elements-stmt = max-elements-keyword sep
- * max-value-arg-str stmtend
- * max-value-arg-str = < a string that matches the rule
- * max-value-arg >
- * max-value-arg = unbounded-keyword /
- * positive-integer-value
- */
- maxElementsStatement : MAX_ELEMENTS_KEYWORD maxValue STMTEND;
-
- /**
- * value-stmt = value-keyword sep integer-value stmtend
- */
- valueStatement : VALUE_KEYWORD value STMTEND;
-
- /**
- * grouping-stmt = grouping-keyword sep identifier-arg-str optsep
- * (";" /
- * "{" stmtsep
- * ;; these stmts can appear in any order
- * [status-stmt stmtsep]
- * [description-stmt stmtsep]
- * [reference-stmt stmtsep]
- * *((typedef-stmt /
- * grouping-stmt) stmtsep)
- * *(data-def-stmt stmtsep)
- * "}")
- * TODO : 0..1 occurance to be checked in listener
- */
- groupingStatement : GROUPING_KEYWORD identifier (STMTEND | LEFT_CURLY_BRACE
- (statusStatement | descriptionStatement | referenceStatement | typedefStatement | groupingStatement
- | dataDefStatement)* RIGHT_CURLY_BRACE);
-
- /**
- * container-stmt = container-keyword sep identifier-arg-str optsep
- * (";" /
- * "{" stmtsep
- * ;; these stmts can appear in any order
- * [when-stmt stmtsep]
- * *(if-feature-stmt stmtsep)
- * *(must-stmt stmtsep)
- * [presence-stmt stmtsep]
- * [config-stmt stmtsep]
- * [status-stmt stmtsep]
- * [description-stmt stmtsep]
- * [reference-stmt stmtsep]
- * *((typedef-stmt /
- * grouping-stmt) stmtsep)
- * *(data-def-stmt stmtsep)
- * "}")
- * TODO : 0..1 occurance to be checked in listener
- */
- containerStatement : CONTAINER_KEYWORD identifier
- (STMTEND | LEFT_CURLY_BRACE (whenStatement | ifFeatureStatement | mustStatement | presenceStatement | configStatement
- | statusStatement | descriptionStatement | referenceStatement | typedefStatement | groupingStatement
- | dataDefStatement)* RIGHT_CURLY_BRACE);
-
- /**
- * leaf-stmt = leaf-keyword sep identifier-arg-str optsep
- * "{" stmtsep
- * ;; these stmts can appear in any order
- * [when-stmt stmtsep]
- * *(if-feature-stmt stmtsep)
- * type-stmt stmtsep
- * [units-stmt stmtsep]
- * *(must-stmt stmtsep)
- * [default-stmt stmtsep]
- * [config-stmt stmtsep]
- * [mandatory-stmt stmtsep]
- * [status-stmt stmtsep]
- * [description-stmt stmtsep]
- * [reference-stmt stmtsep]
- * "}"
- * TODO : 0..1 occurance to be checked in listener
- */
- leafStatement : LEAF_KEYWORD identifier LEFT_CURLY_BRACE (whenStatement | ifFeatureStatement | typeStatement | unitsStatement
- | mustStatement | defaultStatement | configStatement | mandatoryStatement | statusStatement | descriptionStatement
- | referenceStatement)* RIGHT_CURLY_BRACE;
-
- /**
- * leaf-list-stmt = leaf-list-keyword sep identifier-arg-str optsep
- * "{" stmtsep
- * ;; these stmts can appear in any order
- * [when-stmt stmtsep]
- * *(if-feature-stmt stmtsep)
- * type-stmt stmtsep
- * [units-stmt stmtsep]
- * *(must-stmt stmtsep)
- * [config-stmt stmtsep]
- * [min-elements-stmt stmtsep]
- * [max-elements-stmt stmtsep]
- * [ordered-by-stmt stmtsep]
- * [status-stmt stmtsep]
- * [description-stmt stmtsep]
- * [reference-stmt stmtsep]
- * "}"
- * TODO : 0..1 occurance to be checked in listener
- */
- leafListStatement : LEAF_LIST_KEYWORD identifier LEFT_CURLY_BRACE (whenStatement | ifFeatureStatement | typeStatement
- | unitsStatement | mustStatement | configStatement | minElementsStatement | maxElementsStatement | orderedByStatement
- | statusStatement | descriptionStatement | referenceStatement)* RIGHT_CURLY_BRACE;
-
- /**
- * list-stmt = list-keyword sep identifier-arg-str optsep
- * "{" stmtsep
- * ;; these stmts can appear in any order
- * [when-stmt stmtsep]
- * *(if-feature-stmt stmtsep)
- * *(must-stmt stmtsep)
- * [key-stmt stmtsep]
- * *(unique-stmt stmtsep)
- * [config-stmt stmtsep]
- * [min-elements-stmt stmtsep]
- * [max-elements-stmt stmtsep]
- * [ordered-by-stmt stmtsep]
- * [status-stmt stmtsep]
- * [description-stmt stmtsep]
- * [reference-stmt stmtsep]
- * *((typedef-stmt /
- * grouping-stmt) stmtsep)
- * 1*(data-def-stmt stmtsep)
- * "}"
- * TODO : 0..1 occurance to be checked in listener
- */
- listStatement : LIST_KEYWORD identifier LEFT_CURLY_BRACE (whenStatement | ifFeatureStatement | mustStatement | keyStatement
- | uniqueStatement | configStatement | minElementsStatement | maxElementsStatement | orderedByStatement | statusStatement
- | descriptionStatement | referenceStatement | typedefStatement | groupingStatement| dataDefStatement)* RIGHT_CURLY_BRACE;
-
- /**
- * key-stmt = key-keyword sep key-arg-str stmtend
- */
- keyStatement : KEY_KEYWORD key STMTEND;
-
- /**
- * unique-stmt = unique-keyword sep unique-arg-str stmtend
- */
- uniqueStatement: UNIQUE_KEYWORD unique STMTEND;
-
- /**
- * choice-stmt = choice-keyword sep identifier-arg-str optsep
- * (";" /
- * "{" stmtsep
- * ;; these stmts can appear in any order
- * [when-stmt stmtsep]
- * *(if-feature-stmt stmtsep)
- * [default-stmt stmtsep]
- * [config-stmt stmtsep]
- * [mandatory-stmt stmtsep]
- * [status-stmt stmtsep]
- * [description-stmt stmtsep]
- * [reference-stmt stmtsep]
- * *((short-case-stmt / case-stmt) stmtsep)
- * "}")
- * TODO : 0..1 occurance to be checked in listener
- */
- choiceStatement : CHOICE_KEYWORD identifier (STMTEND | LEFT_CURLY_BRACE (whenStatement | ifFeatureStatement | defaultStatement
- | configStatement | mandatoryStatement | statusStatement | descriptionStatement | referenceStatement | shortCaseStatement
- | caseStatement)* RIGHT_CURLY_BRACE);
-
- /**
- * short-case-stmt = container-stmt /
- * leaf-stmt /
- * leaf-list-stmt /
- * list-stmt /
- * anyxml-stmt
- */
- shortCaseStatement : containerStatement | leafStatement | leafListStatement | listStatement | anyxmlStatement;
-
- /**
- * case-stmt = case-keyword sep identifier-arg-str optsep
- * (";" /
- * "{" stmtsep
- * ;; these stmts can appear in any order
- * [when-stmt stmtsep]
- * *(if-feature-stmt stmtsep)
- * [status-stmt stmtsep]
- * [description-stmt stmtsep]
- * [reference-stmt stmtsep]
- * *(data-def-stmt stmtsep)
- * "}")
- * TODO : 0..1 occurance to be checked in listener
- */
- caseStatement : CASE_KEYWORD identifier (STMTEND | LEFT_CURLY_BRACE (whenStatement | ifFeatureStatement | statusStatement
- | descriptionStatement | referenceStatement | dataDefStatement)* RIGHT_CURLY_BRACE);
-
- /**
- * anyxml-stmt = anyxml-keyword sep identifier-arg-str optsep
- * (";" /
- * "{" stmtsep
- * ;; these stmts can appear in any order
- * [when-stmt stmtsep]
- * *(if-feature-stmt stmtsep)
- * *(must-stmt stmtsep)
- * [config-stmt stmtsep]
- * [mandatory-stmt stmtsep]
- * [status-stmt stmtsep]
- * [description-stmt stmtsep]
- * [reference-stmt stmtsep]
- * "}")
- */
- anyxmlStatement : ANYXML_KEYWORD identifier (STMTEND | LEFT_CURLY_BRACE (whenStatement | ifFeatureStatement
- | mustStatement | configStatement | mandatoryStatement | statusStatement | descriptionStatement
- | referenceStatement)* RIGHT_CURLY_BRACE);
-
- /**
- * uses-stmt = uses-keyword sep identifier-ref-arg-str optsep
- * (";" /
- * "{" stmtsep
- * ;; these stmts can appear in any order
- * [when-stmt stmtsep]
- * *(if-feature-stmt stmtsep)
- * [status-stmt stmtsep]
- * [description-stmt stmtsep]
- * [reference-stmt stmtsep]
- * *(refine-stmt stmtsep)
- * *(uses-augment-stmt stmtsep)
- * "}")
- * TODO : 0..1 occurance to be checked in listener
- */
- usesStatement : USES_KEYWORD string (STMTEND | LEFT_CURLY_BRACE (whenStatement | ifFeatureStatement | statusStatement
- | descriptionStatement | referenceStatement | refineStatement | augmentStatement)* RIGHT_CURLY_BRACE);
-
- /**
- * refine-stmt = refine-keyword sep refine-arg-str optsep
- * (";" /
- * "{" stmtsep
- * (refine-container-stmts /
- * refine-leaf-stmts /
- * refine-leaf-list-stmts /
- * refine-list-stmts /
- * refine-choice-stmts /
- * refine-case-stmts /
- * refine-anyxml-stmts)
- * "}")
- */
- refineStatement : REFINE_KEYWORD refine (STMTEND | LEFT_CURLY_BRACE (refineContainerStatements
- | refineLeafStatements | refineLeafListStatements | refineListStatements | refineChoiceStatements
- | refineCaseStatements | refineAnyxmlStatements) RIGHT_CURLY_BRACE);
-
- /**
- * refine-container-stmts =
- * ;; these stmts can appear in any order
- * *(must-stmt stmtsep)
- * [presence-stmt stmtsep]
- * [config-stmt stmtsep]
- * [description-stmt stmtsep]
- * [reference-stmt stmtsep]
- * TODO : 0..1 occurance to be checked in listener
- */
- refineContainerStatements : (mustStatement | presenceStatement | configStatement | descriptionStatement | referenceStatement)* ;
-
- /**
- * refine-leaf-stmts = ;; these stmts can appear in any order
- * *(must-stmt stmtsep)
- * [default-stmt stmtsep]
- * [config-stmt stmtsep]
- * [mandatory-stmt stmtsep]
- * [description-stmt stmtsep]
- * [reference-stmt stmtsep]
- * TODO : 0..1 occurance to be checked in listener
- */
- refineLeafStatements : (mustStatement | defaultStatement | configStatement | mandatoryStatement | descriptionStatement | referenceStatement)*;
-
- /**
- * refine-leaf-list-stmts =
- * ;; these stmts can appear in any order
- * *(must-stmt stmtsep)
- * [config-stmt stmtsep]
- * [min-elements-stmt stmtsep]
- * [max-elements-stmt stmtsep]
- * [description-stmt stmtsep]
- * [reference-stmt stmtsep]
- * TODO : 0..1 occurance to be checked in listener
- */
- refineLeafListStatements : (mustStatement | configStatement | minElementsStatement | maxElementsStatement | descriptionStatement
- | referenceStatement)*;
-
- /**
- * refine-list-stmts = ;; these stmts can appear in any order
- * *(must-stmt stmtsep)
- * [config-stmt stmtsep]
- * [min-elements-stmt stmtsep]
- * [max-elements-stmt stmtsep]
- * [description-stmt stmtsep]
- * [reference-stmt stmtsep]
- * TODO : 0..1 occurance to be checked in listener
- */
- refineListStatements : (mustStatement | configStatement | minElementsStatement | maxElementsStatement | descriptionStatement
- | referenceStatement)*;
-
- /**
- * refine-choice-stmts = ;; these stmts can appear in any order
- * [default-stmt stmtsep]
- * [config-stmt stmtsep]
- * [mandatory-stmt stmtsep]
- * [description-stmt stmtsep]
- * [reference-stmt stmtsep]
- * TODO : 0..1 occurance to be checked in listener
- */
- refineChoiceStatements : (defaultStatement | configStatement | mandatoryStatement | descriptionStatement | referenceStatement)*;
-
- /**
- * refine-case-stmts = ;; these stmts can appear in any order
- * [description-stmt stmtsep]
- * [reference-stmt stmtsep]
- *
- */
- refineCaseStatements : (descriptionStatement | referenceStatement)? | (referenceStatement | descriptionStatement)?;
-
- /**
- * refine-anyxml-stmts = ;; these stmts can appear in any order
- * *(must-stmt stmtsep)
- * [config-stmt stmtsep]
- * [mandatory-stmt stmtsep]
- * [description-stmt stmtsep]
- * [reference-stmt stmtsep]
- */
- refineAnyxmlStatements : (mustStatement | configStatement | mandatoryStatement | descriptionStatement
- | referenceStatement)*;
-
- /**
- * augment-stmt = augment-keyword sep augment-arg-str optsep
- * "{" stmtsep
- * ;; these stmts can appear in any order
- * [when-stmt stmtsep]
- * *(if-feature-stmt stmtsep)
- * [status-stmt stmtsep]
- * [description-stmt stmtsep]
- * [reference-stmt stmtsep]
- * 1*((data-def-stmt stmtsep) /
- * (case-stmt stmtsep))
- * "}"
- * TODO : 0..1 occurance to be checked in listener
- */
- augmentStatement : AUGMENT_KEYWORD augment LEFT_CURLY_BRACE (whenStatement | ifFeatureStatement | statusStatement
- | descriptionStatement | referenceStatement | dataDefStatement | caseStatement)* RIGHT_CURLY_BRACE;
-
- /**
- * when-stmt = when-keyword sep string optsep
- * (";" /
- * "{" stmtsep
- * ;; these stmts can appear in any order
- * [description-stmt stmtsep]
- * [reference-stmt stmtsep]
- * "}")
- *
- */
- whenStatement : WHEN_KEYWORD string (STMTEND | LEFT_CURLY_BRACE ((descriptionStatement? referenceStatement?)
- | (referenceStatement? descriptionStatement?)) RIGHT_CURLY_BRACE);
-
- /**
- * rpc-stmt = rpc-keyword sep identifier-arg-str optsep
- * (";" /
- * "{" stmtsep
- * ;; these stmts can appear in any order
- * *(if-feature-stmt stmtsep)
- * [status-stmt stmtsep]
- * [description-stmt stmtsep]
- * [reference-stmt stmtsep]
- * *((typedef-stmt /
- * grouping-stmt) stmtsep)
- * [input-stmt stmtsep]
- * [output-stmt stmtsep]
- * "}")
- */
- rpcStatement : RPC_KEYWORD identifier (STMTEND | LEFT_CURLY_BRACE (ifFeatureStatement | statusStatement | descriptionStatement
- | referenceStatement | typedefStatement | groupingStatement | inputStatement | outputStatement)* RIGHT_CURLY_BRACE);
-
- /**
- * input-stmt = input-keyword optsep
- * "{" stmtsep
- * ;; these stmts can appear in any order
- * *((typedef-stmt /
- * grouping-stmt) stmtsep)
- * 1*(data-def-stmt stmtsep)
- * "}"
- */
- inputStatement : INPUT_KEYWORD LEFT_CURLY_BRACE (typedefStatement | groupingStatement | dataDefStatement)* RIGHT_CURLY_BRACE;
-
- /**
- * output-stmt = output-keyword optsep
- * "{" stmtsep
- * ;; these stmts can appear in any order
- * *((typedef-stmt /
- * grouping-stmt) stmtsep)
- * 1*(data-def-stmt stmtsep)
- * "}"
- */
- outputStatement : OUTPUT_KEYWORD LEFT_CURLY_BRACE (typedefStatement | groupingStatement | dataDefStatement)* RIGHT_CURLY_BRACE;
-
- /**
- * notification-stmt = notification-keyword sep
- * identifier-arg-str optsep
- * (";" /
- * "{" stmtsep
- * ;; these stmts can appear in any order
- * *(if-feature-stmt stmtsep)
- * [status-stmt stmtsep]
- * [description-stmt stmtsep]
- * [reference-stmt stmtsep]
- * *((typedef-stmt /
- * grouping-stmt) stmtsep)
- * *(data-def-stmt stmtsep)
- * "}")
- * TODO : 0..1 occurance to be checked in listener
- */
- notificationStatement : NOTIFICATION_KEYWORD identifier (STMTEND | LEFT_CURLY_BRACE (ifFeatureStatement
- | statusStatement | descriptionStatement | referenceStatement | typedefStatement
- | groupingStatement | dataDefStatement)* RIGHT_CURLY_BRACE);
-
- /**
- * deviation-stmt = deviation-keyword sep
- * deviation-arg-str optsep
- * "{" stmtsep
- * ;; these stmts can appear in any order
- * [description-stmt stmtsep]
- * [reference-stmt stmtsep]
- * (deviate-not-supported-stmt /
- * 1*(deviate-add-stmt /
- * deviate-replace-stmt /
- * deviate-delete-stmt))
- * "}"
- * TODO : 0..1 occurance to be checked in listener
- */
- deviationStatement: DEVIATION_KEYWORD deviation LEFT_CURLY_BRACE (descriptionStatement | referenceStatement
- | deviateNotSupportedStatement | deviateAddStatement | deviateReplaceStatement
- | deviateDeleteStatement)* RIGHT_CURLY_BRACE;
-
- /**
- * deviate-not-supported-stmt =
- * deviate-keyword sep
- * not-supported-keyword optsep
- * (";" /
- * "{" stmtsep
- * "}")
- */
- deviateNotSupportedStatement: DEVIATE_KEYWORD NOT_SUPPORTED_KEYWORD (STMTEND | LEFT_CURLY_BRACE RIGHT_CURLY_BRACE);
-
- /**
- * deviate-add-stmt = deviate-keyword sep add-keyword optsep
- * (";" /
- * "{" stmtsep
- * [units-stmt stmtsep]
- * *(must-stmt stmtsep)
- * *(unique-stmt stmtsep)
- * [default-stmt stmtsep]
- * [config-stmt stmtsep]
- * [mandatory-stmt stmtsep]
- * [min-elements-stmt stmtsep]
- * [max-elements-stmt stmtsep]
- * "}")
- */
- deviateAddStatement: DEVIATE_KEYWORD ADD_KEYWORD (STMTEND | (LEFT_CURLY_BRACE unitsStatement? mustStatement* uniqueStatement*
- defaultStatement? configStatement? mandatoryStatement? minElementsStatement? maxElementsStatement?
- RIGHT_CURLY_BRACE));
-
- /**
- * deviate-delete-stmt = deviate-keyword sep delete-keyword optsep
- * (";" /
- * "{" stmtsep
- * [units-stmt stmtsep]
- * *(must-stmt stmtsep)
- * *(unique-stmt stmtsep)
- * [default-stmt stmtsep]
- * "}")
- */
- deviateDeleteStatement: DEVIATE_KEYWORD DELETE_KEYWORD (STMTEND
- | (LEFT_CURLY_BRACE unitsStatement? mustStatement* uniqueStatement* defaultStatement? RIGHT_CURLY_BRACE));
-
- /**
- * deviate-replace-stmt = deviate-keyword sep replace-keyword optsep
- * (";" /
- * "{" stmtsep
- * [type-stmt stmtsep]
- * [units-stmt stmtsep]
- * [default-stmt stmtsep]
- * [config-stmt stmtsep]
- * [mandatory-stmt stmtsep]
- * [min-elements-stmt stmtsep]
- * [max-elements-stmt stmtsep]
- * "}")
- */
- deviateReplaceStatement: DEVIATE_KEYWORD REPLACE_KEYWORD (STMTEND | (LEFT_CURLY_BRACE typeStatement? unitsStatement?
- defaultStatement? configStatement? mandatoryStatement? minElementsStatement?
- maxElementsStatement? RIGHT_CURLY_BRACE));
-
- /**
- * compiler-annotation-stmt = prefix:compiler-annotation-keyword string
- * "{"
- * [app-data-structure-stmt stmtsep]
- * [app-extended-stmt stmtsep]
- * "}"
- */
- compilerAnnotationStatement : COMPILER_ANNOTATION string LEFT_CURLY_BRACE
- compilerAnnotationBodyStatement RIGHT_CURLY_BRACE;
-
- compilerAnnotationBodyStatement : appDataStructureStatement? appExtendedStatement? ;
-
- /**
- * app-data-structure-stmt = prefix:app-data-structure-keyword string
- * (";" /
- * "{"
- * [data-structure-key-stmt stmtsep]
- * "}")
- */
- appDataStructureStatement : APP_DATA_STRUCTURE appDataStructure (STMTEND | (LEFT_CURLY_BRACE
- dataStructureKeyStatement? RIGHT_CURLY_BRACE));
-
- /**
- * data-structure-key-stmt = prefix:key-keyword string ";"
- */
- dataStructureKeyStatement : DATA_STRUCTURE_KEY string STMTEND;
-
- /**
- * app-extended-stmt = prefix:app-extended-name-keyword string ";"
- */
- appExtendedStatement : APP_EXTENDED extendedName STMTEND;
-
- string : STRING (PLUS STRING)*
- | IDENTIFIER
- | INTEGER
- | yangConstruct;
-
- identifier : STRING (PLUS STRING)*
- | IDENTIFIER
- | yangConstruct;
-
- dateArgumentString : DATE_ARG
- | STRING (PLUS STRING)*;
-
- version : string;
-
- range : string;
-
- length : string;
-
- path : string;
-
- position : string;
-
- status : string;
-
- config : string;
-
- mandatory : string;
-
- orderedBy : string;
-
- minValue : string;
-
- maxValue : string;
-
- key : string;
-
- unique : string;
-
- refine : string;
-
- requireInstance : string;
-
- augment : string;
-
- deviation : string;
-
- value : string;
-
- fraction : string;
-
- appDataStructure : string;
-
- extendedName : string;
-
- yangConstruct : ANYXML_KEYWORD | ARGUMENT_KEYWORD | AUGMENT_KEYWORD | BASE_KEYWORD | BELONGS_TO_KEYWORD
- | BIT_KEYWORD | CASE_KEYWORD | CHOICE_KEYWORD | CONFIG_KEYWORD | CONTACT_KEYWORD | CONTAINER_KEYWORD
- | DEFAULT_KEYWORD | DESCRIPTION_KEYWORD | ENUM_KEYWORD | ERROR_APP_TAG_KEYWORD | ERROR_MESSAGE_KEYWORD
- | EXTENSION_KEYWORD | DEVIATION_KEYWORD | DEVIATE_KEYWORD | FEATURE_KEYWORD
- | FRACTION_DIGITS_KEYWORD | GROUPING_KEYWORD | IDENTITY_KEYWORD | IF_FEATURE_KEYWORD
- | IMPORT_KEYWORD | INCLUDE_KEYWORD | INPUT_KEYWORD | KEY_KEYWORD | LEAF_KEYWORD | LEAF_LIST_KEYWORD
- | LENGTH_KEYWORD | LIST_KEYWORD | MANDATORY_KEYWORD | MAX_ELEMENTS_KEYWORD | MIN_ELEMENTS_KEYWORD
- | MODULE_KEYWORD | MUST_KEYWORD | NAMESPACE_KEYWORD | NOTIFICATION_KEYWORD | ORDERED_BY_KEYWORD
- | ORGANIZATION_KEYWORD | OUTPUT_KEYWORD | PATH_KEYWORD | PATTERN_KEYWORD | POSITION_KEYWORD
- | PREFIX_KEYWORD | PRESENCE_KEYWORD | RANGE_KEYWORD | REFERENCE_KEYWORD | REFINE_KEYWORD
- | REQUIRE_INSTANCE_KEYWORD | REVISION_KEYWORD | REVISION_DATE_KEYWORD | RPC_KEYWORD
- | STATUS_KEYWORD | SUBMODULE_KEYWORD | TYPE_KEYWORD | TYPEDEF_KEYWORD | UNIQUE_KEYWORD
- | UNITS_KEYWORD | USES_KEYWORD | VALUE_KEYWORD | WHEN_KEYWORD | YANG_VERSION_KEYWORD
- | YIN_ELEMENT_KEYWORD | ADD_KEYWORD | CURRENT_KEYWORD | DELETE_KEYWORD | DEPRECATED_KEYWORD
- | FALSE_KEYWORD | MAX_KEYWORD | MIN_KEYWORD | NOT_SUPPORTED_KEYWORD | OBSOLETE_KEYWORD
- | REPLACE_KEYWORD | SYSTEM_KEYWORD | TRUE_KEYWORD | UNBOUNDED_KEYWORD | USER_KEYWORD
- | COMPILER_ANNOTATION_KEYWORD | APP_DATA_STRUCTURE_KEYWORD | DATA_STRUCTURE_KEYWORD
- | APP_EXTENDED_KEYWORD;
diff --git a/plugin/src/main/resources/YangLexer.g4 b/plugin/src/main/resources/YangLexer.g4
deleted file mode 100644
index 51a9231..0000000
--- a/plugin/src/main/resources/YangLexer.g4
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- * Copyright 2016-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * This is a YANG grammar for lexer based on which ANTLR will generate YANG lexer.
- */
-
-lexer grammar YangLexer;
-
- // Statements keywords
- ANYXML_KEYWORD : 'anyxml';
- ARGUMENT_KEYWORD : 'argument';
- AUGMENT_KEYWORD : 'augment';
- BASE_KEYWORD : 'base';
- BELONGS_TO_KEYWORD : 'belongs-to';
- BIT_KEYWORD : 'bit';
- CASE_KEYWORD : 'case';
- CHOICE_KEYWORD : 'choice';
- CONFIG_KEYWORD : 'config';
- CONTACT_KEYWORD : 'contact';
- CONTAINER_KEYWORD : 'container';
- DEFAULT_KEYWORD : 'default';
- DESCRIPTION_KEYWORD : 'description';
- ENUM_KEYWORD : 'enum';
- ERROR_APP_TAG_KEYWORD : 'error-app-tag';
- ERROR_MESSAGE_KEYWORD : 'error-message';
- EXTENSION_KEYWORD : 'extension';
- DEVIATION_KEYWORD : 'deviation';
- DEVIATE_KEYWORD : 'deviate';
- FEATURE_KEYWORD : 'feature';
- FRACTION_DIGITS_KEYWORD : 'fraction-digits';
- GROUPING_KEYWORD : 'grouping';
- IDENTITY_KEYWORD : 'identity';
- IF_FEATURE_KEYWORD : 'if-feature';
- IMPORT_KEYWORD : 'import';
- INCLUDE_KEYWORD : 'include';
- INPUT_KEYWORD : 'input';
- KEY_KEYWORD : 'key';
- LEAF_KEYWORD : 'leaf';
- LEAF_LIST_KEYWORD : 'leaf-list';
- LENGTH_KEYWORD : 'length';
- LIST_KEYWORD : 'list';
- MANDATORY_KEYWORD : 'mandatory';
- MAX_ELEMENTS_KEYWORD : 'max-elements';
- MIN_ELEMENTS_KEYWORD : 'min-elements';
- MODULE_KEYWORD : 'module';
- MUST_KEYWORD : 'must';
- NAMESPACE_KEYWORD : 'namespace';
- NOTIFICATION_KEYWORD: 'notification';
- ORDERED_BY_KEYWORD : 'ordered-by';
- ORGANIZATION_KEYWORD: 'organization';
- OUTPUT_KEYWORD : 'output';
- PATH_KEYWORD : 'path';
- PATTERN_KEYWORD : 'pattern';
- POSITION_KEYWORD : 'position';
- PREFIX_KEYWORD : 'prefix';
- PRESENCE_KEYWORD : 'presence';
- RANGE_KEYWORD : 'range';
- REFERENCE_KEYWORD : 'reference';
- REFINE_KEYWORD : 'refine';
- REQUIRE_INSTANCE_KEYWORD : 'require-instance';
- REVISION_KEYWORD : 'revision';
- REVISION_DATE_KEYWORD : 'revision-date';
- RPC_KEYWORD : 'rpc';
- STATUS_KEYWORD : 'status';
- SUBMODULE_KEYWORD : 'submodule';
- TYPE_KEYWORD : 'type';
- TYPEDEF_KEYWORD : 'typedef';
- UNIQUE_KEYWORD : 'unique';
- UNITS_KEYWORD : 'units';
- USES_KEYWORD : 'uses';
- VALUE_KEYWORD : 'value';
- WHEN_KEYWORD : 'when';
- YANG_VERSION_KEYWORD: 'yang-version';
- YIN_ELEMENT_KEYWORD : 'yin-element';
- ADD_KEYWORD : 'add';
- CURRENT_KEYWORD : 'current';
- DELETE_KEYWORD : 'delete';
- DEPRECATED_KEYWORD : 'deprecated';
- FALSE_KEYWORD : 'false';
- MAX_KEYWORD : 'max';
- MIN_KEYWORD : 'min';
- NOT_SUPPORTED_KEYWORD : 'not-supported';
- OBSOLETE_KEYWORD : 'obsolete';
- REPLACE_KEYWORD : 'replace';
- SYSTEM_KEYWORD : 'system';
- TRUE_KEYWORD : 'true';
- UNBOUNDED_KEYWORD : 'unbounded';
- USER_KEYWORD : 'user';
- COMPILER_ANNOTATION_KEYWORD : 'compiler-annotation';
- COMPILER_ANNOTATION : IDENTIFIER COLON COMPILER_ANNOTATION_KEYWORD;
- APP_DATA_STRUCTURE_KEYWORD : 'app-data-structure';
- APP_DATA_STRUCTURE : IDENTIFIER COLON APP_DATA_STRUCTURE_KEYWORD;
- DATA_STRUCTURE_KEYWORD : 'data-structure';
- DATA_STRUCTURE : IDENTIFIER COLON DATA_STRUCTURE_KEYWORD;
- DATA_STRUCTURE_KEY : IDENTIFIER COLON KEY_KEYWORD;
- APP_EXTENDED_KEYWORD : 'app-extended-name';
- APP_EXTENDED : IDENTIFIER COLON APP_EXTENDED_KEYWORD;
-
- // Lexer tokens to be skipped
- COMMENT
- : '/*' .*? '*/' -> channel(HIDDEN)
- ;
- WS : [ \r\t\u000C\n]+ -> channel(HIDDEN)
- ;
- LINE_COMMENT
- : '//' ~[\r\n]* '\r'? '\n' -> channel(HIDDEN)
- ;
-
- // Additional rules
- INTEGER : DIGIT+;
- DATE_ARG : DIGIT DIGIT DIGIT DIGIT '-' DIGIT DIGIT '-' DIGIT DIGIT;
- LEFT_CURLY_BRACE : '{';
- RIGHT_CURLY_BRACE : '}';
- IDENTIFIER : (ALPHA | '_')
- (ALPHA | DIGIT | '_' | '-' | '.')*;
- STMTEND : ';';
- DQUOTE : '"';
- COLON : ':';
- PLUS : '+';
- MINUS: '-';
-
- STRING : ((~( '\r' | '\n' | '\t' | ' ' | ';' | '{' | '"' | '+' | '\'')~( '\r' | '\n' | '\t' | ' ' | ';' | '{' | '+')* ) | SUB_STRING );
-
- //Fragment rules
- fragment SUB_STRING : ('"' (ESC | ~["])*'"') | ('\'' (ESC | ~['])*'\'') ;
- fragment ESC : '\\' (["\\/bfnrt] | UNICODE) ;
- fragment UNICODE : 'u' HEX HEX HEX HEX ;
- fragment HEX : [0-9a-fA-F] ;
- fragment ALPHA : [A-Za-z];
- fragment DIGIT : [0-9];
- fragment URN : [u][r][n];
- fragment HTTP : [h][t][t][p];
\ No newline at end of file