removed code duplication in translator, and addressed review comments
Change-Id: I27767a81c4bf279c80d2b98192f75f8f507b4457
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/YangContainer.java b/src/main/java/org/onosproject/yangutils/datamodel/YangContainer.java
index d251479..edd23b7 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/YangContainer.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/YangContainer.java
@@ -487,8 +487,9 @@
CachedFileHandle handle = null;
try {
FileSystemUtil.createPackage(UtilConstants.YANG_GEN_DIR + getPackage(), getName());
- handle = FileSystemUtil.createSourceFiles(getPackage(), getName(), GeneratedFileType.ALL);
- handle.setFilePath(UtilConstants.YANG_GEN_DIR + getPackage().replace(".", "/"));
+ handle = FileSystemUtil.createSourceFiles(getPackage(), getName(),
+ GeneratedFileType.GENERATE_INTERFACE_WITH_BUILDER);
+ handle.setRelativeFilePath(UtilConstants.YANG_GEN_DIR + getPackage().replace(".", "/"));
} catch (IOException e) {
throw new IOException("Failed to create the source files.");
}
@@ -504,7 +505,6 @@
*/
private void addAttributeInParent() {
if (getParent() != null) {
- getParent().getFileHandle().setChildsPackage(getPackage());
getParent().getFileHandle().addAttributeInfo(null, getName(), false);
}
}
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/YangDerivedType.java b/src/main/java/org/onosproject/yangutils/datamodel/YangDerivedType.java
index 8c9628c..e235480 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/YangDerivedType.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/YangDerivedType.java
@@ -1,16 +1,19 @@
-/*Copyright 2016.year Open Networking Laboratory
+/*
+ * Copyright 2016 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.
+ */
-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.datamodel;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
@@ -18,6 +21,8 @@
import org.onosproject.yangutils.utils.YangConstructType;
/*-
+ * Reference RFC 6020.
+ *
* The typedef Statement
*
* The "typedef" statement defines a new type that may be used locally
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/YangList.java b/src/main/java/org/onosproject/yangutils/datamodel/YangList.java
index c0b569b..4903034 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/YangList.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/YangList.java
@@ -123,6 +123,8 @@
private List<YangLeafList> listOfLeafList;
/**
+ * Reference RFC 6020.
+ *
* The "max-elements" statement, which is optional, takes as an argument a
* positive integer or the string "unbounded", which puts a constraint on
* valid list entries. A valid leaf-list or list always has at most
@@ -130,9 +132,11 @@
*
* If no "max-elements" statement is present, it defaults to "unbounded".
*/
- private int maxElelements = Integer.MAX_VALUE;
+ private int maxElements = Integer.MAX_VALUE;
/**
+ * Reference RFC 6020.
+ *
* The "min-elements" statement, which is optional, takes as an argument a
* non-negative integer that puts a constraint on valid list entries. A
* valid leaf-list or list MUST have at least min-elements entries.
@@ -162,17 +166,15 @@
private YangStatusType status = YangStatusType.CURRENT;
/**
- * package of the generated java code.
+ * Package of the generated java code.
*/
private String pkg;
/**
* Constructor.
- *
- * @param type list node
*/
- public YangList(YangNodeType type) {
- super(type);
+ public YangList() {
+ super(YangNodeType.LIST_NODE);
}
/**
@@ -341,17 +343,17 @@
*
* @return the max elements
*/
- public int getMaxElelements() {
- return maxElelements;
+ public int getMaxElements() {
+ return maxElements;
}
/**
* Set the max elements.
*
- * @param maxElelements the max elements
+ * @param max the max elements
*/
- public void setMaxElelements(int maxElelements) {
- this.maxElelements = maxElelements;
+ public void setMaxElements(int max) {
+ maxElements = max;
}
/**
@@ -447,8 +449,8 @@
validateConfig(leaves, leafLists);
/* A list must have atleast one key leaf if config is true */
- if ((isConfig)
- && ((keys == null) || ((leaves == null) && (leafLists == null)))) {
+ if (isConfig
+ && (keys == null || leaves == null && leafLists == null)) {
throw new DataModelException("A list must have atleast one key leaf if config is true;");
} else if (keys != null) {
if (leaves != null) {
@@ -508,7 +510,7 @@
* If a node has "config" set to "false", no node underneath it can have
* "config" set to "true".
*/
- if ((!isConfig) && (leaves != null)) {
+ if (!isConfig && leaves != null) {
for (YangLeaf leaf : leaves) {
if (leaf.isConfig()) {
throw new DataModelException("If a list has \"config\" set to \"false\", no node underneath " +
@@ -517,7 +519,7 @@
}
}
- if ((!isConfig) && (leafLists != null)) {
+ if (!isConfig && leafLists != null) {
for (YangLeafList leafList : leafLists) {
if (leafList.isConfig()) {
throw new DataModelException("If a list has \"config\" set to \"false\", no node underneath " +
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/YangModule.java b/src/main/java/org/onosproject/yangutils/datamodel/YangModule.java
index e56bdab..95bee5f 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/YangModule.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/YangModule.java
@@ -158,16 +158,13 @@
private byte version;
/**
- * Package of the generated java code.
- */
- private String pkg;
-
- /**
* Cached Java File Handle.
*/
private CachedFileHandle fileHandle;
/*-
+ * Reference RFC 6020.
+ *
* Nested typedefs and groupings.
* Typedefs and groupings may appear nested under many YANG statements,
* allowing these to be lexically scoped by the hierarchy under which
@@ -519,7 +516,10 @@
*/
@Override
public String getPackage() {
- return pkg;
+ if (getFileHandle() != null) {
+ return getFileHandle().getRelativeFilePath().replace("/", ".");
+ }
+ return null;
}
/**
@@ -529,7 +529,10 @@
*/
@Override
public void setPackage(String pcg) {
- pkg = pcg;
+ if (getFileHandle() != null) {
+ pcg.replace(".", "/");
+ getFileHandle().setRelativeFilePath(pcg);
+ }
}
/**
@@ -628,16 +631,16 @@
public void generateJavaCodeEntry() throws IOException {
String modPkg = JavaIdentifierSyntax.getRootPackage(getVersion(), getNameSpace().getUri(),
getRevision().getRevDate());
- setPackage(modPkg);
CachedFileHandle handle = null;
try {
- FileSystemUtil.createPackage(UtilConstants.YANG_GEN_DIR + getPackage(), getName());
- handle = FileSystemUtil.createSourceFiles(getPackage(), getName(), GeneratedFileType.ALL);
- handle.setFilePath(UtilConstants.YANG_GEN_DIR + getPackage().replace(".", "/"));
+ FileSystemUtil.createPackage(UtilConstants.YANG_GEN_DIR + modPkg, getName());
+ handle = FileSystemUtil.createSourceFiles(modPkg, getName(),
+ GeneratedFileType.GENERATE_INTERFACE_WITH_BUILDER);
} catch (IOException e) {
throw new IOException("Failed to create the source files.");
}
+
setFileHandle(handle);
addLeavesAttributes();
addLeafListAttributes();
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/YangPatternRestriction.java b/src/main/java/org/onosproject/yangutils/datamodel/YangPatternRestriction.java
index a229b9c..b06955e 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/YangPatternRestriction.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/YangPatternRestriction.java
@@ -1,16 +1,19 @@
-/*Copyright 2016.year Open Networking Laboratory
+/*
+ * Copyright 2016 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.
+ */
-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.datamodel;
import java.util.LinkedList;
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/YangRangeRestriction.java b/src/main/java/org/onosproject/yangutils/datamodel/YangRangeRestriction.java
index 88fdb42..aab79ed 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/YangRangeRestriction.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/YangRangeRestriction.java
@@ -1,16 +1,19 @@
-/*Copyright 2016.year Open Networking Laboratory
+/*
+ * Copyright 2016 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.
+ */
-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.datamodel;
import java.util.LinkedList;
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/YangStringRestriction.java b/src/main/java/org/onosproject/yangutils/datamodel/YangStringRestriction.java
index d2b6462..a583457 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/YangStringRestriction.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/YangStringRestriction.java
@@ -1,16 +1,19 @@
-/*Copyright 2016.year Open Networking Laboratory
+/*
+ * Copyright 2016 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.
+ */
-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.datamodel;
import java.math.BigInteger;
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/YangTypeDef.java b/src/main/java/org/onosproject/yangutils/datamodel/YangTypeDef.java
index a1abd8b..b1feb31 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/YangTypeDef.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/YangTypeDef.java
@@ -17,8 +17,8 @@
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
-import org.onosproject.yangutils.utils.YangConstructType;
import org.onosproject.yangutils.translator.CachedFileHandle;
+import org.onosproject.yangutils.utils.YangConstructType;
/*-
* Reference RFC 6020.
@@ -54,7 +54,6 @@
*/
public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
-
/**
* Default value in string, needs to be converted to the target object,
* based on the type.
@@ -98,8 +97,6 @@
super(YangNodeType.TYPEDEF_NODE);
}
-
-
/**
* Get the default value.
*
@@ -245,8 +242,8 @@
if (type == null) {
throw new DataModelException("Typedef does not have type info.");
}
- if ((type.getDataType() != YangDataTypes.DERIVED)
- || (type.getDataTypeName() == null)) {
+ if (type.getDataType() != YangDataTypes.DERIVED
+ || type.getDataTypeName() == null) {
throw new DataModelException("Typedef type is not derived.");
}