Vinod Kumar S
Committed by Gerrit Code Review

removed code duplication in translator, and addressed review comments

Change-Id: I27767a81c4bf279c80d2b98192f75f8f507b4457
Showing 51 changed files with 1128 additions and 1216 deletions
......@@ -487,8 +487,9 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
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 @@ public class YangContainer extends YangNode implements YangLeavesHolder, YangCom
*/
private void addAttributeInParent() {
if (getParent() != null) {
getParent().getFileHandle().setChildsPackage(getPackage());
getParent().getFileHandle().addAttributeInfo(null, getName(), false);
}
}
......
/*Copyright 2016.year 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
/*
* 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.
*/
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.parser.Parsable;
import org.onosproject.yangutils.utils.YangConstructType;
/*-
* Reference RFC 6020.
*
* The typedef Statement
*
* The "typedef" statement defines a new type that may be used locally
......
......@@ -123,6 +123,8 @@ public class YangList extends YangNode
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 @@ public class YangList extends YangNode
*
* 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 @@ public class YangList extends YangNode
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 @@ public class YangList extends YangNode
*
* @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 @@ public class YangList extends YangNode
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 @@ public class YangList extends YangNode
* 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 @@ public class YangList extends YangNode
}
}
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 " +
......
......@@ -158,16 +158,13 @@ public class YangModule extends YangNode
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 @@ public class YangModule extends YangNode
*/
@Override
public String getPackage() {
return pkg;
if (getFileHandle() != null) {
return getFileHandle().getRelativeFilePath().replace("/", ".");
}
return null;
}
/**
......@@ -529,7 +529,10 @@ public class YangModule extends YangNode
*/
@Override
public void setPackage(String pcg) {
pkg = pcg;
if (getFileHandle() != null) {
pcg.replace(".", "/");
getFileHandle().setRelativeFilePath(pcg);
}
}
/**
......@@ -628,16 +631,16 @@ public class YangModule extends YangNode
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();
......
/*Copyright 2016.year 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
/*
* 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.
*/
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;
......
/*Copyright 2016.year 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
/*
* 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.
*/
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;
......
/*Copyright 2016.year 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
/*
* 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.
*/
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;
......
......@@ -17,8 +17,8 @@ package org.onosproject.yangutils.datamodel;
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 @@ import org.onosproject.yangutils.translator.CachedFileHandle;
*/
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 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
super(YangNodeType.TYPEDEF_NODE);
}
/**
* Get the default value.
*
......@@ -245,8 +242,8 @@ public class YangTypeDef extends YangNode implements YangCommonInfo, Parsable {
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.");
}
......
......@@ -36,8 +36,6 @@ import org.onosproject.yangutils.parser.impl.parserutils.ParseTreeErrorListener;
*/
public class YangUtilsParserManager implements YangUtilsParser {
public static final int SUB_STATEMENT_CARDINALITY = 1;
@Override
public YangNode getDataModel(String yangFile) throws IOException, ParserException {
......
......@@ -46,11 +46,10 @@ import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangLeafList;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.parser.Parsable;
import static org.onosproject.yangutils.utils.YangConstructType.BITS_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.TYPE_DATA;
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.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
......@@ -58,10 +57,12 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorTyp
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.YangConstructType.BITS_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.TYPE_DATA;
/**
* Implements listener based call back function corresponding to the "bits"
* rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
* Implements 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 {
......@@ -103,7 +104,7 @@ public final class BitsListener {
// TODO typedef, union, deviate.
default:
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, TYPE_DATA,
((YangType) typeData).getDataTypeName(), ENTRY));
((YangType<?>) typeData).getDataTypeName(), ENTRY));
}
listener.getParsedDataStack().push(typeData);
listener.getParsedDataStack().push(bitsNode);
......@@ -127,6 +128,7 @@ public final class BitsListener {
Parsable tmpBitsNode = listener.getParsedDataStack().peek();
if (tmpBitsNode instanceof YangBits) {
YangBits bitsNode = (YangBits) tmpBitsNode;
listener.getParsedDataStack().pop();
// Check for stack to be non empty.
......@@ -135,8 +137,8 @@ public final class BitsListener {
Parsable tmpNode = listener.getParsedDataStack().peek();
switch (tmpNode.getYangConstructType()) {
case TYPE_DATA: {
YangType typeNode = (YangType) tmpNode;
typeNode.setDataTypeExtendedInfo((YangBits) tmpBitsNode);
YangType<YangBits> typeNode = (YangType<YangBits>) tmpNode;
typeNode.setDataTypeExtendedInfo(bitsNode);
break;
}
default:
......
......@@ -45,13 +45,17 @@ 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.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.MISSING_HOLDER;
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.utils.YangConstructType.DEFAULT_DATA;
/**
* Listener implementation for default YANG statement.
*/
public final class DefaultListener {
/**
......
......@@ -46,11 +46,10 @@ import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangLeafList;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.parser.Parsable;
import static org.onosproject.yangutils.utils.YangConstructType.ENUMERATION_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.TYPE_DATA;
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.ListenerErrorLocation.ENTRY;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
......@@ -58,6 +57,8 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorTyp
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.YangConstructType.ENUMERATION_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.TYPE_DATA;
/**
* Implements listener based call back function corresponding to the
......@@ -104,7 +105,7 @@ public final class EnumerationListener {
// TODO typedef, union, deviate.
default:
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, TYPE_DATA,
((YangType) typeData).getDataTypeName(), ENTRY));
((YangType<?>) typeData).getDataTypeName(), ENTRY));
}
listener.getParsedDataStack().push(typeData);
listener.getParsedDataStack().push(enumerationNode);
......@@ -128,6 +129,7 @@ public final class EnumerationListener {
Parsable tmpEnumerationNode = listener.getParsedDataStack().peek();
if (tmpEnumerationNode instanceof YangEnumeration) {
YangEnumeration enumerationNode = (YangEnumeration) tmpEnumerationNode;
listener.getParsedDataStack().pop();
// Check for stack to be non empty.
......@@ -136,8 +138,8 @@ public final class EnumerationListener {
Parsable tmpNode = listener.getParsedDataStack().peek();
switch (tmpNode.getYangConstructType()) {
case TYPE_DATA: {
YangType typeNode = (YangType) tmpNode;
typeNode.setDataTypeExtendedInfo((YangEnumeration) tmpEnumerationNode);
YangType<YangEnumeration> typeNode = (YangType<YangEnumeration>) tmpNode;
typeNode.setDataTypeExtendedInfo(enumerationNode);
break;
}
default:
......
......@@ -20,12 +20,13 @@ import org.onosproject.yangutils.datamodel.YangContainer;
import org.onosproject.yangutils.datamodel.YangList;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.datamodel.YangNodeType;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.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.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;
......@@ -35,7 +36,6 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorTyp
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 org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinality;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityNonNull;
......@@ -115,7 +115,7 @@ public final class ListListener {
String identifierName = ctx.IDENTIFIER().getText();
detectCollidingChildUtil(listener, line, charPositionInLine, identifierName, LIST_DATA);
YangList yangList = new YangList(YangNodeType.LIST_NODE);
YangList yangList = new YangList();
yangList.setName(ctx.IDENTIFIER().getText());
/*
......@@ -128,8 +128,8 @@ public final class ListListener {
}
Parsable curData = listener.getParsedDataStack().peek();
if ((curData instanceof YangModule) || (curData instanceof YangContainer)
|| (curData instanceof YangList)) {
if (curData instanceof YangModule || curData instanceof YangContainer
|| curData instanceof YangList) {
curNode = (YangNode) curData;
try {
curNode.addChild(yangList);
......
......@@ -23,12 +23,12 @@ 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.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.ListenerValidation.checkStackIsNotEmpty;
import static org.onosproject.yangutils.utils.YangConstructType.MAX_ELEMENT_DATA;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
......@@ -44,8 +44,9 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidati
*/
/**
* Implements listener based call back function corresponding to the "max-elements"
* rule defined in ANTLR grammar file for corresponding ABNF rule in RFC 6020.
* Implements 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 {
......@@ -56,9 +57,8 @@ public final class MaxElementsListener {
}
/**
* It is called when parser receives an input matching the grammar
* rule (max-elements), performs validation and updates the data model
* tree.
* 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
......@@ -84,7 +84,7 @@ public final class MaxElementsListener {
break;
case LIST_DATA:
YangList yangList = (YangList) tmpData;
yangList.setMaxElelements(maxElementsValue);
yangList.setMaxElements(maxElementsValue);
break;
default:
throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, MAX_ELEMENT_DATA, "", ENTRY));
......
......@@ -16,6 +16,8 @@
package org.onosproject.yangutils.parser.impl.listeners;
import java.net.URI;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangNameSpace;
import org.onosproject.yangutils.parser.Parsable;
......@@ -23,14 +25,12 @@ import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import java.net.URI;
import static org.onosproject.yangutils.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.ListenerValidation.checkStackIsNotEmpty;
import static org.onosproject.yangutils.utils.YangConstructType.NAMESPACE_DATA;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
......@@ -110,9 +110,8 @@ public final class NamespaceListener {
*/
private static boolean validateUriValue(String uri) {
uri = uri.replace("\"", "");
final URI tmpUri;
try {
tmpUri = URI.create(uri);
URI.create(uri);
} catch (Exception e1) {
return false;
}
......
......@@ -36,15 +36,16 @@ package org.onosproject.yangutils.parser.impl.listeners;
import org.onosproject.yangutils.datamodel.YangBit;
import org.onosproject.yangutils.datamodel.YangBits;
import org.onosproject.yangutils.parser.Parsable;
import static org.onosproject.yangutils.utils.YangConstructType.POSITION_DATA;
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.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.utils.YangConstructType.POSITION_DATA;
/**
* Implements listener based call back function corresponding to the "position"
......
......@@ -16,6 +16,10 @@
package org.onosproject.yangutils.parser.impl.listeners;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.onosproject.yangutils.datamodel.YangImport;
import org.onosproject.yangutils.datamodel.YangInclude;
import org.onosproject.yangutils.parser.Parsable;
......@@ -23,16 +27,12 @@ import org.onosproject.yangutils.parser.antlrgencode.GeneratedYangParser;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.TreeWalkListener;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import static org.onosproject.yangutils.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.ListenerValidation.checkStackIsNotEmpty;
import static org.onosproject.yangutils.utils.YangConstructType.REVISION_DATE_DATA;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
......
......@@ -58,28 +58,29 @@ import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.YangTypeDef;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinality;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityEqualsOne;
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.utils.YangConstructType.DEFAULT_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.DESCRIPTION_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.REFERENCE_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.STATUS_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.TYPEDEF_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.TYPE_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.UNITS_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.ListenerErrorType.UNHANDLED_PARSED_DATA;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.checkStackIsNotEmpty;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinality;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerValidation.validateCardinalityEqualsOne;
import static org.onosproject.yangutils.utils.YangConstructType.DEFAULT_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.DESCRIPTION_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.REFERENCE_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.STATUS_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.TYPEDEF_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.TYPE_DATA;
import static org.onosproject.yangutils.utils.YangConstructType.UNITS_DATA;
/**
* Implements listener based call back function corresponding to the "typedef"
......@@ -122,8 +123,8 @@ public final class TypeDefListener {
Parsable curData = listener.getParsedDataStack().peek();
if ((curData instanceof YangModule) | (curData instanceof YangSubModule) | (curData instanceof YangContainer)
| (curData instanceof YangList)) {
if (curData instanceof YangModule || curData instanceof YangSubModule || curData instanceof YangContainer
|| curData instanceof YangList) {
/*
* TODO YangGrouping, YangRpc, YangInput, YangOutput, Notification.
*/
......@@ -159,8 +160,8 @@ public final class TypeDefListener {
try {
typeDefNode.validateDataOnExit();
} catch (DataModelException e) {
// TODO Auto-generated catch block
e.printStackTrace();
throw new ParserException(constructListenerErrorMessage(INVALID_CONTENT, TYPEDEF_DATA,
ctx.IDENTIFIER().getText(), EXIT));
}
listener.getParsedDataStack().pop();
......
......@@ -27,7 +27,6 @@ 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.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;
......@@ -35,6 +34,7 @@ import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorTyp
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.YangConstructType.TYPE_DATA;
/*
* Reference: RFC6020 and YANG ANTLR Grammar
......@@ -110,11 +110,11 @@ public final class TypeListener {
switch (tmpData.getYangConstructType()) {
case LEAF_DATA:
YangLeaf leaf = (YangLeaf) tmpData;
leaf.setDataType((YangType) type);
leaf.setDataType((YangType<?>) type);
break;
case LEAF_LIST_DATA:
YangLeafList leafList = (YangLeafList) tmpData;
leafList.setDataType((YangType) type);
leafList.setDataType((YangType<?>) type);
break;
case TYPEDEF_DATA:
......@@ -128,15 +128,15 @@ public final class TypeListener {
}
YangDerivedType derivedTypeInfo = new YangDerivedType();
if (((YangType) type).getDataType() != YangDataTypes.DERIVED) {
derivedTypeInfo.setEffectiveYangBuiltInType(((YangType) type).getDataType());
if (((YangType<?>) type).getDataType() != YangDataTypes.DERIVED) {
derivedTypeInfo.setEffectiveYangBuiltInType(((YangType<?>) type).getDataType());
} else {
/*
* It will be resolved in the validate data model at exit.
* Nothing needs to be done.
*/
}
derivedTypeInfo.setBaseType((YangType) type);
derivedTypeInfo.setBaseType((YangType<?>) type);
derivedType.setDataTypeExtendedInfo(derivedTypeInfo);
break;
......
......@@ -16,17 +16,18 @@
package org.onosproject.yangutils.parser.impl.parserutils;
import java.util.List;
import org.onosproject.yangutils.datamodel.YangContainer;
import org.onosproject.yangutils.datamodel.YangList;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.parser.Parsable;
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 org.onosproject.yangutils.utils.YangConstructType;
import static org.onosproject.yangutils.utils.YangConstructType.getYangConstructType;
import java.util.List;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
import static org.onosproject.yangutils.utils.YangConstructType.getYangConstructType;
/**
* It's a utility to carry out listener validation.
......@@ -91,8 +92,8 @@ public final class ListenerValidation {
}
/**
* Returns parent node config value, if top node does not specify a config statement
* then default value true is returned.
* 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
......@@ -145,8 +146,7 @@ public final class ListenerValidation {
* @throws ParserException exception if cardinality check fails
*/
public static void validateCardinalityEqualsOne(List<?> childContext, YangConstructType yangChildConstruct,
YangConstructType yangParentConstruct, String parentName)
throws ParserException {
YangConstructType yangParentConstruct, String parentName) throws ParserException {
if (childContext.isEmpty() || childContext.size() != 1) {
ParserException parserException = new ParserException("YANG file error: Invalid cardinality of "
......@@ -167,8 +167,7 @@ public final class ListenerValidation {
* @throws ParserException exception if cardinality check fails
*/
public static void validateCardinalityNonNull(List<?> childContext, YangConstructType yangChildConstruct,
YangConstructType yangParentConstruct, String parentName)
throws ParserException {
YangConstructType yangParentConstruct, String parentName) throws ParserException {
if (childContext.isEmpty()) {
ParserException parserException = new ParserException("YANG file error: Invalid cardinality of "
......
......@@ -29,31 +29,31 @@ public interface CachedFileHandle {
/**
* Add a new attribute to the file(s).
*
* @param attrType data type of the added attribute.
* @param name name of the attribute.
* @param attrType data type of the added attribute
* @param name name of the attribute
* @param isListAttr if the current added attribute needs to be maintained
* in a list.
* in a list
*/
void addAttributeInfo(YangType<?> attrType, String name, boolean isListAttr);
/**
* Flushes the cached contents to the target file, frees used resources.
*
* @throws IOException when failes to generated java files.
* @throws IOException when failes to generated java files
*/
void close() throws IOException;
/**
* Sets child package path for import.
* Sets directory package path for code generation.
*
* @param pkg child's package path
* @param filePath directory package path for code generation
*/
void setChildsPackage(String pkg);
void setRelativeFilePath(String filePath);
/**
* Sets directory package path for code generation.
* Gets directory package path for code generation.
*
* @param filePath directory package path for code generation
* @return directory package path for code generation
*/
void setFilePath(String filePath);
String getRelativeFilePath();
}
......
......@@ -26,14 +26,14 @@ public interface CodeGenerator {
/**
* Traverse the schema of application and generate corresponding code.
*
* @throws IOException when fails to translate the data model tree.
* @throws IOException when fails to translate the data model tree
*/
void generateJavaCodeEntry() throws IOException;
/**
* Traverse the schema of application and generate corresponding code.
*
* @throws IOException when fails to generate java code.
* @throws IOException when fails to generate java code
*/
void generateJavaCodeExit() throws IOException;
......
......@@ -19,29 +19,41 @@ package org.onosproject.yangutils.translator;
/**
* Type of files generated.
*/
public enum GeneratedFileType {
public final class GeneratedFileType {
/**
* Interface file.
* prevent creating attributes.
*/
INTERFACE,
private GeneratedFileType() {
}
/**
* Builder class file.
* Interface file.
*/
BUILDER_CLASS,
public static final int INTERFACE_MASK = 1;
/**
* Builder interface file.
*/
BUILDER_INTERFACE,
public static final int BUILDER_INTERFACE_MASK = 2;
/**
* Builder class file.
*/
public static final int BUILDER_CLASS_MASK = 4;
/**
* Impl class file.
*/
IMPL,
public static final int IMPL_CLASS_MASK = 8;
/**
* Interface and class file.
*/
public static final int GENERATE_INTERFACE_WITH_BUILDER = 15;
/**
* interface and class file.
* Java class corresponding to typedef.
*/
ALL
public static final int GENERATE_TYPEDEF_CLASS = 16;
}
......
......@@ -16,20 +16,12 @@
package org.onosproject.yangutils.translator.tojava;
import java.io.Serializable;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType;
/**
* Maintains the attribute info corresponding to class/interface generated.
*/
public class AttributeInfo implements Serializable {
/**
* version of serialized info.
*/
private static final long serialVersionUID = 201602151004L;
public class AttributeInfo {
/**
* The data type info of attribute.
......@@ -44,7 +36,7 @@ public class AttributeInfo implements Serializable {
/**
* If the added attribute is a list of info.
*/
private boolean isListAttr;
private boolean isListAttr = false;
/**
* If the added attribute has to be accessed in a fully qualified manner.
......@@ -52,6 +44,12 @@ public class AttributeInfo implements Serializable {
private boolean isQualifiedName;
/**
* The class info will be used to set the attribute type and package info
* will be use for qualified name.
*/
private ImportInfo importInfo;
/**
* Default constructor.
*/
public AttributeInfo() {
......@@ -60,7 +58,7 @@ public class AttributeInfo implements Serializable {
/**
* Get the data type info of attribute.
*
* @return the data type info of attribute.
* @return the data type info of attribute
*/
public YangType<?> getAttributeType() {
return attrType;
......@@ -69,19 +67,17 @@ public class AttributeInfo implements Serializable {
/**
* Set the data type info of attribute.
*
* @param type the data type info of attribute.
* @param type the data type info of attribute
*/
public void setAttributeType(YangType<?> type) {
if (type != null) {
attrType = AttributesJavaDataType.getJavaDataType(type);
}
attrType = type;
}
/**
* Get name of the attribute.
*
* @return name of the attribute.
* @return name of the attribute
*/
public String getAttributeName() {
return name;
......@@ -90,7 +86,7 @@ public class AttributeInfo implements Serializable {
/**
* Set name of the attribute.
*
* @param attrName name of the attribute.
* @param attrName name of the attribute
*/
public void setAttributeName(String attrName) {
name = attrName;
......@@ -99,7 +95,7 @@ public class AttributeInfo implements Serializable {
/**
* Get if the added attribute is a list of info.
*
* @return the 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;
......@@ -108,7 +104,7 @@ public class AttributeInfo implements Serializable {
/**
* Set if the added attribute is a list of info.
*
* @param isList if the added attribute is a list of info.
* @param isList if the added attribute is a list of info
*/
public void setListAttr(boolean isList) {
isListAttr = isList;
......@@ -130,10 +126,29 @@ public class AttributeInfo implements Serializable {
* manner.
*
* @param isQualified if the added attribute has to be accessed in a fully
* qualified manner.
* qualified manner
*/
public void setQualifiedName(boolean isQualified) {
isQualifiedName = isQualified;
}
/**
* Get the import info for the attribute type. It will be null, of the type
* is basic built-in java type.
*
* @return import info
*/
public ImportInfo getImportInfo() {
return importInfo;
}
/**
* Set the import info for the attribute type.
*
* @param importInfo import info for the attribute type
*/
public void setImportInfo(ImportInfo importInfo) {
this.importInfo = importInfo;
}
}
......
......@@ -18,20 +18,18 @@ package org.onosproject.yangutils.translator.tojava;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.SortedSet;
import java.util.TreeSet;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.YangTypeDef;
import org.onosproject.yangutils.translator.CachedFileHandle;
import org.onosproject.yangutils.translator.GeneratedFileType;
import org.onosproject.yangutils.translator.tojava.utils.AttributesJavaDataType;
import org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen;
import org.onosproject.yangutils.translator.tojava.utils.JavaFileGenerator;
import org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax;
import org.onosproject.yangutils.translator.tojava.utils.MethodsGenerator;
import org.onosproject.yangutils.utils.UtilConstants;
/**
......@@ -47,17 +45,7 @@ public class CachedJavaFileHandle implements CachedFileHandle {
* The type(s) of java source file(s) to be generated when the cached file
* handle is closed.
*/
private GeneratedFileType genFileTypes;
/**
* Java package in which the class/interface needs to be generated.
*/
private String pkg;
/**
* Java package in which the child class/interface needs to be generated.
*/
private String childsPkg;
private int genFileTypes;
/**
* Name of the object in YANG file.
......@@ -68,7 +56,7 @@ public class CachedJavaFileHandle implements CachedFileHandle {
* Sorted set of import info, to be used to maintain the set of classes to
* be imported in the generated class.
*/
private SortedSet<String> importSet;
private SortedSet<ImportInfo> importSet;
/**
* Cached list of attribute info.
......@@ -78,7 +66,12 @@ public class CachedJavaFileHandle implements CachedFileHandle {
/**
* File generation directory path.
*/
private String filePath;
private String relativeFilePath;
/**
* Typedef Info.
*/
private YangTypeDef typedefInfo;
/**
* Prevent invoking default constructor.
......@@ -91,14 +84,16 @@ public class CachedJavaFileHandle implements CachedFileHandle {
* Create a cached file handle which takes care of adding attributes to the
* generated java file.
*
* @param pcg package in which class/interface need to be generated.
* @param yangName name of the attribute in YANG file.
* @param types the types of files that needs to be generated.
* @throws IOException file IO exception.
* @param pcg package in which class/interface need to be generated
* @param yangName name of the attribute in YANG file
* @param types the types of files that needs to be generated
* @throws IOException file IO exception
*/
public CachedJavaFileHandle(String pcg, String yangName, GeneratedFileType types) throws IOException {
public CachedJavaFileHandle(String pcg, String yangName, int types) throws IOException {
setCachedAttributeList(new LinkedList<AttributeInfo>());
setImportSet(new TreeSet<ImportInfo>());
setRelativeFilePath(pcg.replace(".", "/"));
setGeneratedFileTypes(types);
setPackage(pcg);
setYangName(yangName);
}
......@@ -107,9 +102,9 @@ public class CachedJavaFileHandle implements CachedFileHandle {
* definition.
*
* @return the types of files being generated corresponding to the YANG
* definition.
* definition
*/
public GeneratedFileType getGeneratedFileTypes() {
public int getGeneratedFileTypes() {
return genFileTypes;
}
......@@ -118,16 +113,16 @@ public class CachedJavaFileHandle implements CachedFileHandle {
* definition.
*
* @param fileTypes the types of files being generated corresponding to the
* YANG definition.
* YANG definition
*/
public void setGeneratedFileTypes(GeneratedFileType fileTypes) {
public void setGeneratedFileTypes(int fileTypes) {
genFileTypes = fileTypes;
}
/**
* Get the corresponding name defined in YANG.
*
* @return the corresponding name defined in YANG.
* @return the corresponding name defined in YANG
*/
public String getYangName() {
return yangName;
......@@ -136,59 +131,27 @@ public class CachedJavaFileHandle implements CachedFileHandle {
/**
* Set the corresponding name defined in YANG.
*
* @param yangName the corresponding name defined in YANG.
* @param yangName the corresponding name defined in YANG
*/
public void setYangName(String yangName) {
this.yangName = yangName;
}
/**
* Get the java package.
*
* @return the java package.
*/
public String getPackage() {
return pkg;
}
/**
* Set the java package.
*
* @param pcg the package to set
*/
public void setPackage(String pcg) {
pkg = pcg;
}
/**
* Get the java package.
*
* @return the java package.
*/
public String getChildsPackage() {
return childsPkg;
}
@Override
public void setChildsPackage(String pcg) {
childsPkg = pcg;
}
/**
* Get the set containing the imported class/interface info.
*
* @return the set containing the imported class/interface info.
* @return the set containing the imported class/interface info
*/
public SortedSet<String> getImportSet() {
public SortedSet<ImportInfo> getImportSet() {
return importSet;
}
/**
* Assign the set containing the imported class/interface info.
*
* @param importSet the set containing the imported class/interface info.
* @param importSet the set containing the imported class/interface info
*/
private void setImportSet(SortedSet<String> importSet) {
private void setImportSet(SortedSet<ImportInfo> importSet) {
this.importSet = importSet;
}
......@@ -197,25 +160,17 @@ public class CachedJavaFileHandle implements CachedFileHandle {
* set. If already part of the set, return false, else add to set and return
* true.
*
* @param importInfo class/interface info being imported.
* @param importInfo class/interface info being imported
* @return status of new addition of class/interface to the import set
*/
public boolean addImportInfo(ImportInfo importInfo) {
/*
* implement the import info adding. The return value will be used to
* check if the qualified name will be used or class/interface name will
* be used in the generated class.
*/
if (getImportSet() == null) {
setImportSet(new TreeSet<String>());
}
return getImportSet().add(JavaCodeSnippetGen.getImportText(importInfo));
return getImportSet().add(importInfo);
}
/**
* Get the list of cached attribute list.
*
* @return the set containing the imported class/interface info.
* @return the set containing the imported class/interface info
*/
public List<AttributeInfo> getCachedAttributeList() {
return attributeList;
......@@ -224,33 +179,39 @@ public class CachedJavaFileHandle implements CachedFileHandle {
/**
* Set the cached attribute list.
*
* @param attrList attribute list.
* @param attrList attribute list
*/
private void setCachedAttributeList(List<AttributeInfo> attrList) {
attributeList = attrList;
}
/**
* Set the package relative path.
*
* @param path package relative path
*/
@Override
public void setFilePath(String path) {
filePath = path;
public void setRelativeFilePath(String path) {
relativeFilePath = path;
}
/**
* Set the cached attribute list.
* Get the package relative path.
*
* @param attrList attribute list.
* @return package relative path
*/
private String getFilePath() {
return filePath;
@Override
public String getRelativeFilePath() {
return relativeFilePath;
}
/**
* Flush the cached attribute list to the serialized file.
* Flush the cached attribute list to the corresponding temporary file.
*/
private void flushCacheAttrToSerFile(String className) {
private void flushCacheAttrToTempFile() {
for (AttributeInfo attr : getCachedAttributeList()) {
JavaFileGenerator.parseAttributeInfo(attr, getGeneratedFileTypes(), className);
JavaFileGenerator.parseAttributeInfo(attr, getGeneratedFileTypes(), getYangName());
}
/*
......@@ -262,88 +223,61 @@ public class CachedJavaFileHandle implements CachedFileHandle {
/**
* Add a new attribute to the file(s).
*
* @param attrType data type of the added attribute.
* @param name name of the attribute.
* @param attrType data type of the added attribute
* @param name name of the attribute
* @param isListAttr if the current added attribute needs to be maintained
* in a list.
* in a list
*/
@Override
public void addAttributeInfo(YangType<?> attrType, String name, boolean isListAttr) {
/* YANG name is mapped to java name */
name = JavaIdentifierSyntax.getCamelCase(name);
ImportInfo importInfo = new ImportInfo();
boolean isImport = false;
AttributeInfo newAttr = new AttributeInfo();
if (attrType != null) {
newAttr.setAttributeType(attrType);
String importStr = AttributesJavaDataType.getJavaImportClass(attrType, isListAttr);
if (importStr != null) {
importInfo.setClassInfo(importStr);
importStr = AttributesJavaDataType.getJavaImportPackage(attrType, isListAttr);
importInfo.setPkgInfo(importStr);
isImport = true;
} else {
ImportInfo importInfo = new ImportInfo();
importInfo.setPkgInfo(getChildsPackage());
importInfo.setClassInfo(JavaIdentifierSyntax.getCaptialCase(name));
if (getImportSet() != null) {
getImportSet().add(JavaCodeSnippetGen.getImportText(importInfo));
} else {
SortedSet<String> newImportInfo = new TreeSet<>();
newImportInfo.add(JavaCodeSnippetGen.getImportText(importInfo));
setImportSet(newImportInfo);
importStr = AttributesJavaDataType.getJavaDataType(attrType);
if (importStr == null) {
throw new RuntimeException("not supported data type");
//TODO: need to change to translator exception.
}
newAttr.setQualifiedName(getQualifiedFlag(JavaCodeSnippetGen.getImportText(importInfo)));
}
newAttr.setAttributeName(name);
newAttr.setListAttr(isListAttr);
if (newAttr.isListAttr()) {
newAttr.setAttributeType(AttributesJavaDataType.getListString(newAttr));
importInfo.setClassInfo(importStr);
}
if (isListAttr) {
String listImport = UtilConstants.COLLECTION_IMPORTS + UtilConstants.LIST + UtilConstants.SEMI_COLAN
+ UtilConstants.NEW_LINE + UtilConstants.NEW_LINE;
if (getImportSet() != null) {
getImportSet().add(listImport);
} else {
SortedSet<String> newImportInfo = new TreeSet<>();
newImportInfo.add(listImport);
setImportSet(newImportInfo);
}
importInfo.setClassInfo(JavaIdentifierSyntax.getCaptialCase(name));
newAttr.setQualifiedName(getQualifiedFlag(listImport));
importInfo.setPkgInfo(getRelativeFilePath().replace('/', '.')
+ "." + getYangName());
isImport = true;
}
if (getCachedAttributeList() != null) {
if (getCachedAttributeList().size() == MAX_CACHABLE_ATTR) {
flushCacheAttrToSerFile(getYangName());
}
getCachedAttributeList().add(newAttr);
} else {
List<AttributeInfo> newAttributeInfo = new LinkedList<>();
newAttributeInfo.add(newAttr);
setCachedAttributeList(newAttributeInfo);
newAttr.setQualifiedName(false);
if (isImport) {
boolean isNewImport = addImportInfo(importInfo);
if (!isNewImport) {
newAttr.setQualifiedName(true);
}
}
/**
* Check if the import set does not have a class info same as the new class
* info, if so the new class info be added to the import set. Otherwise
* check if the corresponding package info is same as the new package info,
* if so no need to qualified access, otherwise, it needs qualified access.
*
* @param newImportInfo new import info to be check for qualified access or
* not and updated in the import set accordingly.
* @return if the new attribute needs to be accessed in a qualified manner.
*/
private boolean getQualifiedFlag(String newImportInfo) {
for (String curImportInfo : getImportSet()) {
if (curImportInfo.equals(newImportInfo)) {
/*
* If import is already existing import with same package, we
* don't need qualified access, otherwise it needs to be
* qualified access.
*/
return !curImportInfo.equals(newImportInfo);
}
}
newAttr.setAttributeName(name);
newAttr.setListAttr(isListAttr);
newAttr.setImportInfo(importInfo);
getImportSet().add(newImportInfo);
return false;
if (getCachedAttributeList().size() == MAX_CACHABLE_ATTR) {
flushCacheAttrToTempFile();
}
getCachedAttributeList().add(newAttr);
}
/**
......@@ -352,10 +286,12 @@ public class CachedJavaFileHandle implements CachedFileHandle {
@Override
public void close() throws IOException {
flushCacheAttrToTempFile();
String className = getYangName();
className = JavaIdentifierSyntax.getCaptialCase(className);
String filePath = getFilePath();
GeneratedFileType fileType = getGeneratedFileTypes();
String path = getRelativeFilePath();
int fileType = getGeneratedFileTypes();
/*
* TODO: add the file header using
......@@ -363,45 +299,46 @@ public class CachedJavaFileHandle implements CachedFileHandle {
*/
List<String> imports = new LinkedList<>();
String importString;
if (getCachedAttributeList() != null) {
MethodsGenerator.setAttrInfo(getCachedAttributeList());
for (AttributeInfo attr : getCachedAttributeList()) {
if (getImportSet() != null) {
imports = new ArrayList<>(getImportSet());
}
for (ImportInfo importInfo : getImportSet()) {
importString = "";
if (importInfo.getPkgInfo() != null) {
importString = importString + importInfo.getPkgInfo() + ".";
}
importString = importString + importInfo.getClassInfo();
imports.add(importString);
}
/**
* Start generation of files.
*/
if (fileType.equals(GeneratedFileType.INTERFACE) || fileType.equals(GeneratedFileType.ALL)) {
if ((fileType & GeneratedFileType.INTERFACE_MASK) != 0
|| fileType == GeneratedFileType.GENERATE_INTERFACE_WITH_BUILDER) {
/**
* Create interface file.
*/
String interfaceFileName = className;
File interfaceFile = new File(filePath + File.separator + interfaceFileName + JAVA_FILE_EXTENSION);
File interfaceFile = JavaFileGenerator.getFileObject(path, interfaceFileName, JAVA_FILE_EXTENSION);
interfaceFile = JavaFileGenerator.generateInterfaceFile(interfaceFile, className, imports,
getCachedAttributeList(), getPackage());
getCachedAttributeList(), path.replace('/', '.'));
/**
* Create temp builder interface file.
*/
String builderInterfaceFileName = className + UtilConstants.BUILDER + UtilConstants.INTERFACE;
File builderInterfaceFile = new File(
filePath + File.separator + builderInterfaceFileName + TEMP_FILE_EXTENSION);
File builderInterfaceFile = JavaFileGenerator.getFileObject(path, builderInterfaceFileName,
TEMP_FILE_EXTENSION);
builderInterfaceFile = JavaFileGenerator.generateBuilderInterfaceFile(builderInterfaceFile, className,
getPackage(), getCachedAttributeList());
path.replace('/', '.'), getCachedAttributeList());
/**
* Append builder interface file to interface file and close it.
*/
JavaFileGenerator.appendFileContents(builderInterfaceFile, interfaceFile);
JavaFileGenerator.insert(interfaceFile,
JavaFileGenerator.closeFile(GeneratedFileType.INTERFACE, interfaceFileName));
JavaFileGenerator.closeFile(GeneratedFileType.INTERFACE_MASK, interfaceFileName));
/**
* Remove temp files.
......@@ -409,33 +346,32 @@ public class CachedJavaFileHandle implements CachedFileHandle {
JavaFileGenerator.clean(builderInterfaceFile);
}
if (fileType.equals(GeneratedFileType.BUILDER_CLASS) || fileType.equals(GeneratedFileType.ALL)) {
if ((fileType & GeneratedFileType.BUILDER_CLASS_MASK) != 0
|| fileType == GeneratedFileType.GENERATE_INTERFACE_WITH_BUILDER) {
/**
* Create builder class file.
*/
String builderFileName = className + UtilConstants.BUILDER;
File builderFile = new File(filePath + File.separator + builderFileName + JAVA_FILE_EXTENSION);
MethodsGenerator.setBuilderClassName(className + UtilConstants.BUILDER);
builderFile = JavaFileGenerator.generateBuilderClassFile(builderFile, className, imports, getPackage(),
getCachedAttributeList());
File builderFile = JavaFileGenerator.getFileObject(path, builderFileName, JAVA_FILE_EXTENSION);
builderFile = JavaFileGenerator.generateBuilderClassFile(builderFile, className, imports,
path.replace('/', '.'), getCachedAttributeList());
/**
* Create temp impl class file.
*/
String implFileName = className + UtilConstants.IMPL;
File implTempFile = new File(filePath + File.separator + implFileName + TEMP_FILE_EXTENSION);
implTempFile = JavaFileGenerator.generateImplClassFile(implTempFile, className, getPackage(),
getCachedAttributeList());
File implTempFile = JavaFileGenerator.getFileObject(path, implFileName, TEMP_FILE_EXTENSION);
implTempFile = JavaFileGenerator.generateImplClassFile(implTempFile, className,
path.replace('/', '.'), getCachedAttributeList());
/**
* Append impl class to builder class and close it.
*/
JavaFileGenerator.appendFileContents(implTempFile, builderFile);
JavaFileGenerator.insert(builderFile,
JavaFileGenerator.closeFile(GeneratedFileType.BUILDER_CLASS, builderFileName));
JavaFileGenerator.closeFile(GeneratedFileType.BUILDER_CLASS_MASK, builderFileName));
/**
* Remove temp files.
......@@ -443,4 +379,12 @@ public class CachedJavaFileHandle implements CachedFileHandle {
JavaFileGenerator.clean(implTempFile);
}
}
public YangTypeDef getTypedefInfo() {
return typedefInfo;
}
public void setTypedefInfo(YangTypeDef typedefInfo) {
this.typedefInfo = typedefInfo;
}
}
......
......@@ -23,7 +23,7 @@ import com.google.common.base.MoreObjects;
/**
* Maintains the information about individual imports in the generated file.
*/
public class ImportInfo {
public class ImportInfo implements Comparable {
/**
* Package location where the imported class/interface is defined.
......@@ -31,7 +31,7 @@ public class ImportInfo {
private String pkgInfo;
/**
* class/interface being referenced.
* Class/interface being referenced.
*/
private String classInfo;
......@@ -44,7 +44,7 @@ public class ImportInfo {
/**
* Get the imported package info.
*
* @return the imported package info.
* @return the imported package info
*/
public String getPkgInfo() {
return pkgInfo;
......@@ -53,7 +53,7 @@ public class ImportInfo {
/**
* Set the imported package info.
*
* @param pkgInfo the imported package info.
* @param pkgInfo the imported package info
*/
public void setPkgInfo(String pkgInfo) {
this.pkgInfo = pkgInfo;
......@@ -62,7 +62,7 @@ public class ImportInfo {
/**
* Get the imported class/interface info.
*
* @return the imported class/interface info.
* @return the imported class/interface info
*/
public String getClassInfo() {
return classInfo;
......@@ -71,7 +71,7 @@ public class ImportInfo {
/**
* Set the imported class/interface info.
*
* @param classInfo the imported class/interface info.
* @param classInfo the imported class/interface info
*/
public void setClassInfo(String classInfo) {
this.classInfo = classInfo;
......@@ -114,4 +114,20 @@ public class ImportInfo {
.add("classInfo", classInfo).toString();
}
/**
* Check that there is no 2 objects with the same class name.
*
* @param o compared import info.
*/
@Override
public int compareTo(Object o) {
ImportInfo other;
if (o instanceof ImportInfo) {
other = (ImportInfo) o;
} else {
return -1;
}
return getClassInfo().compareTo(other.getClassInfo());
}
}
......
......@@ -34,8 +34,9 @@ public final class JavaCodeGenerator {
/**
* Generate Java code files corresponding to the YANG schema.
*
* @param rootNode root node of the data model tree.
* @throws IOException when fails to generate java code file the current node.
* @param rootNode root node of the data model tree
* @throws IOException when fails to generate java code file the current
* node
*/
public static void generateJavaCode(YangNode rootNode) throws IOException {
YangNode curNode = rootNode;
......@@ -45,10 +46,10 @@ public final class JavaCodeGenerator {
if (curTraversal != TraversalType.PARENT) {
curNode.generateJavaCodeEntry();
}
if (curTraversal != TraversalType.PARENT && (curNode.getChild() != null)) {
if (curTraversal != TraversalType.PARENT && curNode.getChild() != null) {
curTraversal = TraversalType.CHILD;
curNode = curNode.getChild();
} else if ((curNode.getNextSibling() != null)) {
} else if (curNode.getNextSibling() != null) {
curNode.generateJavaCodeExit();
curTraversal = TraversalType.SIBILING;
curNode = curNode.getNextSibling();
......
......@@ -18,7 +18,6 @@ package org.onosproject.yangutils.translator.tojava.utils;
import org.onosproject.yangutils.datamodel.YangDataTypes;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.translator.tojava.AttributeInfo;
import org.onosproject.yangutils.utils.UtilConstants;
/**
......@@ -33,41 +32,14 @@ public final class AttributesJavaDataType {
}
/**
* Returns YANG type.
* Returns java type.
*
* @param yangType YANG type
* @return YANG type
* @return java type
*/
public static YangType<?> getJavaDataType(YangType<?> yangType) {
yangType.setDataTypeName(yangType.getDataTypeName().replace("\"", ""));
if (yangType.getDataType() != null) {
yangType.setDataTypeName(parseYangDataType(yangType.getDataType()));
}
return yangType;
}
public static String getJavaDataType(YangType<?> yangType) {
YangDataTypes type = yangType.getDataType();
/**
* Returns list string as attribute name when attribute is a list.
*
* @param attr attribute info.
* @return list attribute
*/
@SuppressWarnings("rawtypes")
public static YangType<?> getListString(AttributeInfo attr) {
String listString = JavaCodeSnippetGen.getListAttribute(attr.getAttributeType().getDataTypeName());
YangType<?> type = new YangType();
type.setDataTypeName(listString);
attr.setAttributeType(type);
return type;
}
/**
* Parses YANG data type and returns corresponding java data type.
*
* @param type YANG data type
* @return java data type
*/
private static String parseYangDataType(YangDataTypes type) {
if (type.equals(YangDataTypes.INT8)) {
return UtilConstants.BYTE;
} else if (type.equals(YangDataTypes.INT16)) {
......@@ -111,4 +83,161 @@ public final class AttributesJavaDataType {
}
return null;
}
/**
* Returns java import class.
*
* @param yangType YANG type
* @param isListAttr if the attribute need to be a list
* @return java import class
*/
public static String getJavaImportClass(YangType<?> yangType, boolean isListAttr) {
YangDataTypes type = yangType.getDataType();
if (isListAttr) {
if (type.equals(YangDataTypes.INT8)) {
return UtilConstants.BYTE_WRAPPER;
} else if (type.equals(YangDataTypes.INT16)) {
return UtilConstants.SHORT_WRAPPER;
} else if (type.equals(YangDataTypes.INT32)) {
return UtilConstants.INTEGER_WRAPPER;
} else if (type.equals(YangDataTypes.INT64)) {
return UtilConstants.LONG_WRAPPER;
} else if (type.equals(YangDataTypes.UINT8)) {
return UtilConstants.SHORT_WRAPPER;
} else if (type.equals(YangDataTypes.UINT16)) {
return UtilConstants.INTEGER_WRAPPER;
} else if (type.equals(YangDataTypes.UINT32)) {
return UtilConstants.LONG_WRAPPER;
} else if (type.equals(YangDataTypes.UINT64)) {
//TODO: BIGINTEGER.
} else if (type.equals(YangDataTypes.DECIMAL64)) {
//TODO: DECIMAL64.
} else if (type.equals(YangDataTypes.STRING)) {
return UtilConstants.STRING;
} else if (type.equals(YangDataTypes.BOOLEAN)) {
return UtilConstants.BOOLEAN_WRAPPER;
} else if (type.equals(YangDataTypes.ENUMERATION)) {
//TODO: ENUMERATION.
} else if (type.equals(YangDataTypes.BITS)) {
//TODO:BITS
} else if (type.equals(YangDataTypes.BINARY)) {
//TODO:BINARY
} else if (type.equals(YangDataTypes.LEAFREF)) {
//TODO:LEAFREF
} else if (type.equals(YangDataTypes.IDENTITYREF)) {
//TODO:IDENTITYREF
} else if (type.equals(YangDataTypes.EMPTY)) {
//TODO:EMPTY
} else if (type.equals(YangDataTypes.UNION)) {
//TODO:UNION
} else if (type.equals(YangDataTypes.INSTANCE_IDENTIFIER)) {
//TODO:INSTANCE_IDENTIFIER
} else if (type.equals(YangDataTypes.DERIVED)) {
//TODO:DERIVED
}
} else {
if (type.equals(YangDataTypes.UINT64)) {
//TODO: BIGINTEGER.
} else if (type.equals(YangDataTypes.DECIMAL64)) {
//TODO: DECIMAL64.
} else if (type.equals(YangDataTypes.STRING)) {
return UtilConstants.STRING;
} else if (type.equals(YangDataTypes.ENUMERATION)) {
//TODO: ENUMERATION.
} else if (type.equals(YangDataTypes.BITS)) {
//TODO:BITS
} else if (type.equals(YangDataTypes.BINARY)) {
//TODO:BINARY
} else if (type.equals(YangDataTypes.LEAFREF)) {
//TODO:LEAFREF
} else if (type.equals(YangDataTypes.IDENTITYREF)) {
//TODO:IDENTITYREF
} else if (type.equals(YangDataTypes.EMPTY)) {
//TODO:EMPTY
} else if (type.equals(YangDataTypes.UNION)) {
//TODO:UNION
} else if (type.equals(YangDataTypes.INSTANCE_IDENTIFIER)) {
//TODO:INSTANCE_IDENTIFIER
} else if (type.equals(YangDataTypes.DERIVED)) {
//TODO:DERIVED
}
}
return null;
}
/**
* Returns java import package.
*
* @param yangType YANG type
* @param isListAttr if the attribute is of list type
* @return java import package
*/
public static String getJavaImportPackage(YangType<?> yangType, boolean isListAttr) {
YangDataTypes type = yangType.getDataType();
if (isListAttr) {
if (type.equals(YangDataTypes.INT8)
|| type.equals(YangDataTypes.INT16)
|| type.equals(YangDataTypes.INT32)
|| type.equals(YangDataTypes.INT64)
|| type.equals(YangDataTypes.UINT8)
|| type.equals(YangDataTypes.UINT16)
|| type.equals(YangDataTypes.UINT32)
|| type.equals(YangDataTypes.STRING)
|| type.equals(YangDataTypes.BOOLEAN)) {
return UtilConstants.JAVA_LANG;
} else if (type.equals(YangDataTypes.UINT64)) {
//TODO: BIGINTEGER.
} else if (type.equals(YangDataTypes.DECIMAL64)) {
//TODO: DECIMAL64.
} else if (type.equals(YangDataTypes.ENUMERATION)) {
//TODO: ENUMERATION.
} else if (type.equals(YangDataTypes.BITS)) {
//TODO:BITS
} else if (type.equals(YangDataTypes.BINARY)) {
//TODO:BINARY
} else if (type.equals(YangDataTypes.LEAFREF)) {
//TODO:LEAFREF
} else if (type.equals(YangDataTypes.IDENTITYREF)) {
//TODO:IDENTITYREF
} else if (type.equals(YangDataTypes.EMPTY)) {
//TODO:EMPTY
} else if (type.equals(YangDataTypes.UNION)) {
//TODO:UNION
} else if (type.equals(YangDataTypes.INSTANCE_IDENTIFIER)) {
//TODO:INSTANCE_IDENTIFIER
} else if (type.equals(YangDataTypes.DERIVED)) {
//TODO:DERIVED
}
} else {
if (type.equals(YangDataTypes.UINT64)) {
//TODO: BIGINTEGER.
} else if (type.equals(YangDataTypes.DECIMAL64)) {
//TODO: DECIMAL64.
} else if (type.equals(YangDataTypes.STRING)) {
return UtilConstants.JAVA_LANG;
} else if (type.equals(YangDataTypes.ENUMERATION)) {
//TODO: ENUMERATION.
} else if (type.equals(YangDataTypes.BITS)) {
//TODO:BITS
} else if (type.equals(YangDataTypes.BINARY)) {
//TODO:BINARY
} else if (type.equals(YangDataTypes.LEAFREF)) {
//TODO:LEAFREF
} else if (type.equals(YangDataTypes.IDENTITYREF)) {
//TODO:IDENTITYREF
} else if (type.equals(YangDataTypes.EMPTY)) {
//TODO:EMPTY
} else if (type.equals(YangDataTypes.UNION)) {
//TODO:UNION
} else if (type.equals(YangDataTypes.INSTANCE_IDENTIFIER)) {
//TODO:INSTANCE_IDENTIFIER
} else if (type.equals(YangDataTypes.DERIVED)) {
//TODO:DERIVED
}
}
return null;
}
}
......
......@@ -31,30 +31,31 @@ public final class ClassDefinitionGenerator {
}
/**
* Generate class definition for specific classes.
* 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
*/
public static String generateClassDefinition(GeneratedFileType genFileTypes, String yangName) {
public 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.
* based on the file type and the YANG name of the file, generate the
* class / interface definition start.
*/
if (genFileTypes.equals(GeneratedFileType.INTERFACE)) {
if ((genFileTypes & GeneratedFileType.INTERFACE_MASK) != 0) {
return getInterfaceDefinition(yangName);
} else if (genFileTypes.equals(GeneratedFileType.BUILDER_CLASS)) {
} else if ((genFileTypes & GeneratedFileType.BUILDER_CLASS_MASK) != 0) {
return getBuilderClassDefinition(yangName);
} else if (genFileTypes.equals(GeneratedFileType.IMPL)) {
} else if ((genFileTypes & GeneratedFileType.IMPL_CLASS_MASK) != 0) {
return getImplClassDefinition(yangName);
} else if (genFileTypes.equals(GeneratedFileType.BUILDER_INTERFACE)) {
} else if ((genFileTypes & GeneratedFileType.BUILDER_INTERFACE_MASK) != 0) {
return getBuilderInterfaceDefinition();
return getBuilderInterfaceDefinition(yangName);
}
return null;
}
......@@ -74,10 +75,12 @@ public final class ClassDefinitionGenerator {
/**
* 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() {
return UtilConstants.INTERFACE + UtilConstants.SPACE + UtilConstants.BUILDER + UtilConstants.SPACE
private static String getBuilderInterfaceDefinition(String yangName) {
return UtilConstants.INTERFACE + UtilConstants.SPACE + yangName + UtilConstants.BUILDER + UtilConstants.SPACE
+ UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE;
}
......
......@@ -16,12 +16,7 @@
package org.onosproject.yangutils.translator.tojava.utils;
import java.util.List;
import java.util.SortedSet;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.translator.GeneratedFileType;
import org.onosproject.yangutils.translator.tojava.GeneratedMethodTypes;
import org.onosproject.yangutils.translator.tojava.ImportInfo;
import org.onosproject.yangutils.utils.UtilConstants;
......@@ -39,7 +34,7 @@ public final class JavaCodeSnippetGen {
/**
* Get the java file header comment.
*
* @return the java file header comment.
* @return the java file header comment
*/
public static String getFileHeaderComment() {
......@@ -50,22 +45,11 @@ public final class JavaCodeSnippetGen {
}
/**
* reorder the import list based on the ONOS import rules.
*
* @param importInfo the set of classes/interfaces to be imported.
* @return string of import info.
*/
public List<ImportInfo> sortImportOrder(SortedSet<ImportInfo> importInfo) {
/* TODO: reorder the import list based on the ONOS import rules. */
return null;
}
/**
* Get the textual java code information corresponding to the import list.
*
* @param importInfo import info.
* @param importInfo import info
* @return the textual java code information corresponding to the import
* list.
* list
*/
public static String getImportText(ImportInfo importInfo) {
return UtilConstants.IMPORT + importInfo.getPkgInfo() + UtilConstants.PERIOD + importInfo.getClassInfo()
......@@ -76,11 +60,11 @@ public final class JavaCodeSnippetGen {
* Based on the file type and the YANG name of the file, generate the class
* / interface definition start.
*
* @param genFileTypes type of file being generated.
* @param yangName YANG name.
* @return corresponding textual java code information.
* @param genFileTypes type of file being generated
* @param yangName YANG name
* @return corresponding textual java code information
*/
public static String getJavaClassDefStart(GeneratedFileType genFileTypes, String yangName) {
public static String getJavaClassDefStart(int genFileTypes, String yangName) {
/*
* get the camel case name for java class / interface.
*/
......@@ -91,19 +75,29 @@ public final class JavaCodeSnippetGen {
/**
* Get the textual java code for attribute definition in class.
*
* @param genFileTypes type of file being generated.
* @param yangName YANG name of the the attribute.
* @param type type of the the attribute.
* @return the textual java code for attribute definition in class.
* @param javaAttributeTypePkg Package of the attribute type
* @param javaAttributeType java attribute type
* @param javaAttributeName name of the attribute
* @return the textual java code for attribute definition in class
*/
public static String getJavaAttributeInfo(GeneratedFileType genFileTypes, String yangName, YangType<?> type) {
yangName = JavaIdentifierSyntax.getCamelCase(yangName);
if (type != null) {
return UtilConstants.PRIVATE + UtilConstants.SPACE + type.getDataTypeName() + UtilConstants.SPACE + yangName
+ UtilConstants.SEMI_COLAN;
public static String getJavaAttributeDefination(String javaAttributeTypePkg, String javaAttributeType,
String javaAttributeName) {
String attributeDefination = UtilConstants.PRIVATE
+ UtilConstants.SPACE;
if (javaAttributeTypePkg != null) {
attributeDefination = attributeDefination
+ javaAttributeTypePkg + ".";
}
return UtilConstants.PRIVATE + UtilConstants.SPACE + JavaIdentifierSyntax.getCaptialCase(yangName)
+ UtilConstants.SPACE + yangName + UtilConstants.SEMI_COLAN;
attributeDefination = attributeDefination
+ javaAttributeType
+ UtilConstants.SPACE
+ javaAttributeName
+ UtilConstants.SEMI_COLAN;
return attributeDefination;
}
/**
......@@ -117,37 +111,19 @@ public final class JavaCodeSnippetGen {
}
/**
* Based on the file type and method type(s) and the YANG name of the
* method, generate the method definitions(s).
*
* @param genFileTypes type of file being generated
* @param yangName name if the attribute whose getter / setter is required.
* @param methodTypes getter and / or setter type of method indicator.
* @param returnType type return type of the method.
* @return based on the file type and method type(s) the method
* definitions(s).
*/
public static String getJavaMethodInfo(GeneratedFileType genFileTypes, String yangName,
GeneratedMethodTypes methodTypes, YangType<?> returnType) {
yangName = JavaIdentifierSyntax.getCamelCase(yangName);
return MethodsGenerator.constructMethodInfo(genFileTypes, yangName, methodTypes, returnType);
}
/**
* Based on the file type and the YANG name of the file, generate the class
* / interface definition close.
*
* @param genFileTypes type of file being generated.
* @param yangName YANG name.
* @return corresponding textual java code information.
* @param genFileTypes type of file being generated
* @param yangName YANG name
* @return corresponding textual java code information
*/
public static String getJavaClassDefClose(GeneratedFileType genFileTypes, String yangName) {
public static String getJavaClassDefClose(int genFileTypes, String yangName) {
if (genFileTypes.equals(GeneratedFileType.INTERFACE)) {
if ((genFileTypes & GeneratedFileType.INTERFACE_MASK) != 0) {
return UtilConstants.CLOSE_CURLY_BRACKET;
} else if (genFileTypes.equals(GeneratedFileType.BUILDER_CLASS)) {
} else if ((genFileTypes & GeneratedFileType.BUILDER_CLASS_MASK) != 0) {
return UtilConstants.CLOSE_CURLY_BRACKET;
}
......
......@@ -18,22 +18,27 @@ package org.onosproject.yangutils.translator.tojava.utils;
import java.io.File;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import org.onosproject.yangutils.translator.GeneratedFileType;
import org.onosproject.yangutils.translator.tojava.AttributeInfo;
import org.onosproject.yangutils.utils.UtilConstants;
import org.onosproject.yangutils.utils.io.impl.CopyrightHeader;
import org.onosproject.yangutils.utils.io.impl.FileSystemUtil;
import org.onosproject.yangutils.utils.io.impl.JavaDocGen;
import org.onosproject.yangutils.utils.io.impl.TempDataStore;
import org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType;
import org.onosproject.yangutils.utils.io.impl.TempDataStore;
import org.onosproject.yangutils.utils.io.impl.TempDataStore.TempDataStoreType;
import org.slf4j.Logger;
import static org.onosproject.yangutils.translator.GeneratedFileType.BUILDER_CLASS_MASK;
import static org.onosproject.yangutils.translator.GeneratedFileType.BUILDER_INTERFACE_MASK;
import static org.onosproject.yangutils.translator.GeneratedFileType.IMPL_CLASS_MASK;
import static org.onosproject.yangutils.translator.GeneratedFileType.INTERFACE_MASK;
import static org.slf4j.LoggerFactory.getLogger;
import org.slf4j.Logger;
/**
* Generates java file.
*/
public final class JavaFileGenerator {
private static final Logger log = getLogger(JavaFileGenerator.class);
......@@ -45,21 +50,40 @@ public final class JavaFileGenerator {
}
/**
* Returns a file object for generated file.
*
* @param fileName file name
* @param filePath file package path
* @param extension file extension
* @return file object
*/
public static File getFileObject(String filePath, String fileName, String extension) {
return new File(UtilConstants.YANG_GEN_DIR + filePath + File.separator + fileName + extension);
}
/**
* Returns generated interface file for current node.
*
* @param file file
* @param className class name
* @param imports imports for the file
* @param attrList attribute info
* @param pkg generated file package
* @return interface file
* @throws IOException when fails to write in file.
* @throws IOException when fails to write in file
*/
public static File generateInterfaceFile(File file, String className, List<String> imports,
List<AttributeInfo> attrList, String pkg) throws IOException {
initiateFile(file, className, GeneratedFileType.INTERFACE, imports, pkg);
List<String> methods = getMethodStrings(TempDataStoreType.GETTER_METHODS, GeneratedFileType.INTERFACE,
className, file, attrList);
initiateFile(file, className, INTERFACE_MASK, imports, pkg);
List<String> methods;
try {
methods = TempDataStore.getTempData(TempDataStoreType.GETTER_METHODS, className);
} catch (ClassNotFoundException | IOException e) {
log.info("There is no attribute info of " + className + " YANG file in the temporary files.");
throw new IOException("Fail to read data from temp file.");
}
/**
* Add getter methods to interface file.
......@@ -72,19 +96,26 @@ public final class JavaFileGenerator {
/**
* Return generated builder interface file for current node.
*
* @param file file
* @param className class name
* @param pkg generated file package
* @param attrList attribute info
* @return builder interface file
* @throws IOException when fails to write in file.
* @throws IOException when fails to write in file
*/
public static File generateBuilderInterfaceFile(File file, String className, String pkg,
List<AttributeInfo> attrList) throws IOException {
initiateFile(file, className, GeneratedFileType.BUILDER_INTERFACE, null, pkg);
List<String> methods = getMethodStrings(TempDataStoreType.BUILDER_INTERFACE_METHODS,
GeneratedFileType.BUILDER_INTERFACE, className, file, attrList);
initiateFile(file, className, BUILDER_INTERFACE_MASK, null, pkg);
List<String> methods;
try {
methods = TempDataStore.getTempData(TempDataStoreType.BUILDER_INTERFACE_METHODS,
className + UtilConstants.BUILDER + UtilConstants.INTERFACE);
} catch (ClassNotFoundException | IOException e) {
log.info("There is no attribute info of " + className + " YANG file in the temporary files.");
throw new IOException("Fail to read data from temp file.");
}
/**
* Add build method to builder interface file.
......@@ -104,32 +135,52 @@ public final class JavaFileGenerator {
/**
* Returns generated builder class file for current node.
*
* @param file file
* @param className class name
* @param imports imports for the file
* @param pkg generated file package
* @param attrList attribute info
* @return builder class file
* @throws IOException when fails to write in file.
* @throws IOException when fails to write in file
*/
public static File generateBuilderClassFile(File file, String className, List<String> imports, String pkg,
List<AttributeInfo> attrList) throws IOException {
initiateFile(file, className, GeneratedFileType.BUILDER_CLASS, imports, pkg);
List<String> methods = getMethodStrings(TempDataStoreType.BUILDER_METHODS, GeneratedFileType.BUILDER_CLASS,
className, file, attrList);
initiateFile(file, className, BUILDER_CLASS_MASK, imports, pkg);
/**
* Add default constructor and build method impl.
* Add attribute strings.
*/
methods.add(UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_FIRST_LINE
+ MethodsGenerator.getDefaultConstructorString(GeneratedFileType.BUILDER_CLASS, className));
methods.add(MethodsGenerator.getBuildString(className));
List<String> attributes;
try {
attributes = TempDataStore.getTempData(TempDataStoreType.ATTRIBUTE, className);
} catch (ClassNotFoundException | IOException e) {
log.info("There is no attribute info of " + className + " YANG file in the temporary files.");
throw new IOException("Fail to read data from temp file.");
}
/**
* Add attributes to the file.
*/
for (String attribute : attributes) {
insert(file, UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + attribute);
}
insert(file, UtilConstants.NEW_LINE);
List<String> methods;
try {
methods = TempDataStore.getTempData(TempDataStoreType.BUILDER_METHODS, className + UtilConstants.BUILDER);
} catch (ClassNotFoundException | IOException e) {
log.info("There is no attribute info of " + className + " YANG file in the temporary files.");
throw new IOException("Fail to read data from temp file.");
}
/**
* Add attribute strings.
* Add default constructor and build method impl.
*/
addAttributeSring(file, className, attrList, GeneratedFileType.BUILDER_CLASS);
methods.add(UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_FIRST_LINE
+ MethodsGenerator.getDefaultConstructorString(BUILDER_CLASS_MASK, className));
methods.add(MethodsGenerator.getBuildString(className));
/**
* Add methods in builder class.
......@@ -142,69 +193,25 @@ public final class JavaFileGenerator {
/**
* Returns generated impl class file for current node.
*
* @param file file
* @param className class name
* @param pkg generated file package
* @param attrList attribute's info
* @return impl class file
* @throws IOException when fails to write in file.
* @throws IOException when fails to write in file
*/
public static File generateImplClassFile(File file, String className, String pkg, List<AttributeInfo> attrList)
throws IOException {
initiateFile(file, className, GeneratedFileType.IMPL, null, pkg);
List<String> methods = getMethodStrings(TempDataStoreType.IMPL_METHODS, GeneratedFileType.IMPL, className, file,
attrList);
/**
* Add attributes.
*/
addAttributeSring(file, className, attrList, GeneratedFileType.IMPL);
/**
* Add default constructor and constructor methods.
*/
methods.add(UtilConstants.JAVA_DOC_FIRST_LINE
+ MethodsGenerator.getDefaultConstructorString(GeneratedFileType.IMPL, className));
methods.add(MethodsGenerator.getConstructorString(className));
/**
* Add methods in impl class.
*/
for (String method : methods) {
appendMethod(file, UtilConstants.FOUR_SPACE_INDENTATION + method + UtilConstants.NEW_LINE);
}
insert(file, UtilConstants.CLOSE_CURLY_BRACKET + UtilConstants.NEW_LINE);
return file;
}
initiateFile(file, className, IMPL_CLASS_MASK, null, pkg);
/**
* Adds attribute string for generated files.
*
* @param className class name
* @param file generated file
* @param attrList attribute info
* @param genFileType generated file type
* @param IOException when fails to add attributes in files.
*/
private static void addAttributeSring(File file, String className, List<AttributeInfo> attrList,
GeneratedFileType genFileType) throws IOException {
List<String> attributes = new LinkedList<>();
List<String> attributes;
try {
attributes = TempDataStore.getTempData(TempDataStoreType.ATTRIBUTE, className);
} catch (ClassNotFoundException | IOException e) {
log.info("There is no attribute info of " + className + " YANG file in the serialized files.");
}
if (attrList != null) {
MethodsGenerator.setAttrInfo(attrList);
for (AttributeInfo attr : attrList) {
if (attr.isListAttr()) {
attr.setAttributeType(AttributesJavaDataType.getListString(attr));
}
attributes.add(getAttributeString(attr, genFileType));
}
log.info("There is no attribute info of " + className + " YANG file in the temporary files.");
throw new IOException("Fail to read data from temp file.");
}
/**
......@@ -214,37 +221,31 @@ public final class JavaFileGenerator {
insert(file, UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + attribute);
}
insert(file, UtilConstants.NEW_LINE);
List<String> methods;
try {
methods = TempDataStore.getTempData(TempDataStoreType.IMPL_METHODS, className + UtilConstants.IMPL);
} catch (ClassNotFoundException | IOException e) {
log.info("There is no attribute info of " + className + " YANG file in the temporary files.");
throw new IOException("Fail to read data from temp file.");
}
/**
* Returns method strings for generated files.
*
* @param dataStoreType temp data store file type.
* @param genFileType generated file type
* @param className generated file name
* @param attrList attribute info
* @return method strings
* Add default constructor and constructor methods.
*/
private static List<String> getMethodStrings(TempDataStoreType dataStoreType, GeneratedFileType genFileType,
String className, File file, List<AttributeInfo> attrList) {
methods.add(UtilConstants.JAVA_DOC_FIRST_LINE
+ MethodsGenerator.getDefaultConstructorString(IMPL_CLASS_MASK, className));
methods.add(MethodsGenerator.getConstructorString(className));
List<String> methods = new LinkedList<>();
try {
methods = TempDataStore.getTempData(dataStoreType, className);
} catch (ClassNotFoundException | IOException e) {
log.info("There is no attribute info of " + className + " YANG file in the serialized files.");
/**
* Add methods in impl class.
*/
for (String method : methods) {
appendMethod(file, UtilConstants.FOUR_SPACE_INDENTATION + method + UtilConstants.NEW_LINE);
}
insert(file, UtilConstants.CLOSE_CURLY_BRACKET + UtilConstants.NEW_LINE);
if (attrList != null) {
MethodsGenerator.setAttrInfo(attrList);
for (AttributeInfo attr : attrList) {
if (attr.isListAttr()) {
attr.setAttributeType(AttributesJavaDataType.getListString(attr));
}
methods.add(MethodsGenerator.getMethodString(attr, genFileType));
}
}
return methods;
return file;
}
/**
......@@ -257,7 +258,7 @@ public final class JavaFileGenerator {
* @param pkg generated file package
* @throws IOException when fails to generate a file
*/
private static void initiateFile(File file, String className, GeneratedFileType type, List<String> imports,
private static void initiateFile(File file, String className, int type, List<String> imports,
String pkg) throws IOException {
try {
file.createNewFile();
......@@ -272,7 +273,7 @@ public final class JavaFileGenerator {
*
* @param appendFile temp file
* @param srcFile main file
* @throws IOException when fails to append contents.
* @throws IOException when fails to append contents
*/
public static void appendFileContents(File appendFile, File srcFile) throws IOException {
try {
......@@ -285,8 +286,9 @@ public final class JavaFileGenerator {
/**
* Append methods to the generated files.
*
* @param file file in which method needs to be appended.
* @param method method which needs to be appended.
* @param file file in which method needs to be appended
* @param method method which needs to be appended
* @exception IOException file operation exceptions
*/
private static void appendMethod(File file, String method) throws IOException {
insert(file, method);
......@@ -297,9 +299,9 @@ public final class JavaFileGenerator {
*
* @param fileType generate file type
* @param yangName file name
* @return end of class definition string.
* @return end of class definition string
*/
public static String closeFile(GeneratedFileType fileType, String yangName) {
public static String closeFile(int fileType, String yangName) {
return JavaCodeSnippetGen.getJavaClassDefClose(fileType, yangName);
}
......@@ -307,58 +309,56 @@ public final class JavaFileGenerator {
* Parses attribute info and fetch specific data and creates serialized
* files of it.
*
* @param attr attribute info.
* @param attr attribute info
* @param genFileType generated file type
* @param className class name
*/
public static void parseAttributeInfo(AttributeInfo attr, GeneratedFileType genFileType, String className) {
public static void parseAttributeInfo(AttributeInfo attr, int genFileType, String className) {
String attrString = "";
String methodString = "";
String builderInterfaceMethodString = "";
String builderClassMethodString = "";
String implClassMethodString = "";
String getterString = "";
className = JavaIdentifierSyntax.getCaptialCase(className);
try {
/*
* Serialize attributes.
* Get the attribute definition and save attributes to temporary
* file.
*/
attrString = getAttributeString(attr, genFileType);
attrString = attrString.replace("\"", "");
attrString = JavaCodeSnippetGen.getJavaAttributeDefination(attr.getImportInfo().getPkgInfo(),
attr.getImportInfo().getClassInfo(),
attr.getAttributeName());
TempDataStore.setTempData(attrString, TempDataStore.TempDataStoreType.ATTRIBUTE, className);
if (genFileType.equals(GeneratedFileType.ALL)) {
methodString = MethodsGenerator.getMethodString(attr, GeneratedFileType.INTERFACE);
TempDataStore.setTempData(methodString, TempDataStore.TempDataStoreType.GETTER_METHODS, className);
methodString = MethodsGenerator.getMethodString(attr, GeneratedFileType.BUILDER_CLASS);
TempDataStore.setTempData(methodString, TempDataStore.TempDataStoreType.BUILDER_METHODS, className);
methodString = MethodsGenerator.getMethodString(attr, GeneratedFileType.BUILDER_INTERFACE);
TempDataStore.setTempData(methodString, TempDataStore.TempDataStoreType.BUILDER_INTERFACE_METHODS,
className);
if ((genFileType & INTERFACE_MASK) != 0) {
getterString = MethodsGenerator.getGetterString(attr);
TempDataStore.setTempData(getterString, TempDataStore.TempDataStoreType.GETTER_METHODS, className);
}
methodString = MethodsGenerator.getMethodString(attr, GeneratedFileType.IMPL);
TempDataStore.setTempData(methodString, TempDataStore.TempDataStoreType.IMPL_METHODS, className);
if ((genFileType & BUILDER_INTERFACE_MASK) != 0) {
builderInterfaceMethodString = MethodsGenerator.parseBuilderInterfaceMethodString(attr, className);
TempDataStore.setTempData(builderInterfaceMethodString,
TempDataStore.TempDataStoreType.BUILDER_INTERFACE_METHODS,
className + UtilConstants.BUILDER + UtilConstants.INTERFACE);
}
} else if (genFileType.equals(GeneratedFileType.INTERFACE)) {
if ((genFileType & BUILDER_CLASS_MASK) != 0) {
builderClassMethodString = MethodsGenerator.parseBuilderMethodString(attr, className);
TempDataStore.setTempData(builderClassMethodString, TempDataStore.TempDataStoreType.BUILDER_METHODS,
className + UtilConstants.BUILDER);
}
getterString = MethodsGenerator.getGetterString(attr);
TempDataStore.setTempData(methodString, TempDataStore.TempDataStoreType.GETTER_METHODS, className);
if ((genFileType & IMPL_CLASS_MASK) != 0) {
implClassMethodString = MethodsGenerator.parseImplMethodString(attr);
TempDataStore.setTempData(implClassMethodString, TempDataStore.TempDataStoreType.IMPL_METHODS,
className + UtilConstants.IMPL);
}
} catch (IOException e) {
log.info("Failed to get data for " + attr.getAttributeName() + " from serialized files.");
}
log.info("Failed to set data for " + attr.getAttributeName() + " in temp data files.");
}
/**
* Returns attribute string.
*
* @param attr attribute info
* @param genFileType generated file type
* @return attribute string
*/
private static String getAttributeString(AttributeInfo attr, GeneratedFileType genFileType) {
return JavaCodeSnippetGen.getJavaAttributeInfo(genFileType, attr.getAttributeName(), attr.getAttributeType());
}
/**
......@@ -368,20 +368,21 @@ public final class JavaFileGenerator {
* @param fileName generated file name
* @param type generated file type
* @param pkg generated file package
* @throws IOException when fails to append contents.
* @param importsList list of java imports
* @throws IOException when fails to append contents
*/
private static void appendContents(File file, String fileName, GeneratedFileType type, List<String> importsList,
private static void appendContents(File file, String fileName, int type, List<String> importsList,
String pkg) throws IOException {
if (type.equals(GeneratedFileType.IMPL)) {
if ((type & IMPL_CLASS_MASK) != 0) {
write(file, fileName, type, JavaDocType.IMPL_CLASS);
} else if (type.equals(GeneratedFileType.BUILDER_INTERFACE)) {
} else if ((type & BUILDER_INTERFACE_MASK) != 0) {
write(file, fileName, type, JavaDocType.BUILDER_INTERFACE);
} else {
if (type.equals(GeneratedFileType.INTERFACE)) {
if ((type & INTERFACE_MASK) != 0) {
insert(file, CopyrightHeader.getCopyrightHeader());
insert(file, "package" + UtilConstants.SPACE + pkg + UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE);
if (importsList != null) {
......@@ -391,9 +392,8 @@ public final class JavaFileGenerator {
}
insert(file, UtilConstants.NEW_LINE);
}
insert(file, UtilConstants.NEW_LINE);
write(file, fileName, type, JavaDocType.INTERFACE);
} else if (type.equals(GeneratedFileType.BUILDER_CLASS)) {
} else if ((type & BUILDER_CLASS_MASK) != 0) {
insert(file, CopyrightHeader.getCopyrightHeader());
insert(file, "package" + UtilConstants.SPACE + pkg + UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE);
if (importsList != null) {
......@@ -403,7 +403,6 @@ public final class JavaFileGenerator {
}
insert(file, UtilConstants.NEW_LINE);
}
insert(file, UtilConstants.NEW_LINE);
write(file, fileName, type, JavaDocType.BUILDER_CLASS);
}
}
......@@ -416,9 +415,9 @@ public final class JavaFileGenerator {
* @param fileName file name
* @param genType generated file type
* @param javaDocType java doc type
* @throws IOException when fails to write into a file.
* @throws IOException when fails to write into a file
*/
private static void write(File file, String fileName, GeneratedFileType genType, JavaDocGen.JavaDocType javaDocType)
private static void write(File file, String fileName, int genType, JavaDocGen.JavaDocType javaDocType)
throws IOException {
insert(file, JavaDocGen.getJavaDoc(javaDocType, fileName));
......@@ -428,8 +427,8 @@ public final class JavaFileGenerator {
/**
* Insert in the generated file.
*
* @param file file in which need to be inserted.
* @param data data which need to be inserted.
* @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 insert(File file, String data) throws IOException {
......@@ -443,7 +442,7 @@ public final class JavaFileGenerator {
/**
* Removes temp files.
*
* @param file file to be removed.
* @param file file to be removed
*/
public static void clean(File file) {
if (file.exists()) {
......
......@@ -34,10 +34,10 @@ public final class JavaIdentifierSyntax {
/**
* Get the root package string.
*
* @param version YANG version.
* @param nameSpace name space of the module.
* @param version YANG version
* @param nameSpace name space of the module
* @param revision revision of the module defined
* @return returns the root package string.
* @return returns the root package string
*/
public static String getRootPackage(byte version, String nameSpace, String revision) {
......@@ -56,7 +56,7 @@ public final class JavaIdentifierSyntax {
/**
* Returns version.
*
* @param ver YANG version.
* @param ver YANG version
* @return version
*/
private static String getYangVersion(byte ver) {
......@@ -67,7 +67,7 @@ public final class JavaIdentifierSyntax {
* Get package name from name space.
*
* @param nameSpace name space of YANG module
* @return java package name as per java rules.
* @return java package name as per java rules
*/
public static String getPkgFromNameSpace(String nameSpace) {
ArrayList<String> pkgArr = new ArrayList<String>();
......@@ -125,9 +125,9 @@ public final class JavaIdentifierSyntax {
/**
* Get the package from parent's package and string.
*
* @param parentPkg parent's package.
* @param parentName parent's name.
* @return package string.
* @param parentPkg parent's package
* @param parentName parent's name
* @return package string
*/
public static String getPackageFromParent(String parentPkg, String parentName) {
return (parentPkg + UtilConstants.PERIOD + getSubPkgFromName(parentName)).toLowerCase();
......@@ -136,8 +136,8 @@ public final class JavaIdentifierSyntax {
/**
* Get package sub name from YANG identifier name.
*
* @param name YANG identifier name.
* @return java package sub name as per java rules.
* @param name YANG identifier name
* @return java package sub name as per java rules
*/
public static String getSubPkgFromName(String name) {
ArrayList<String> pkgArr = new ArrayList<String>();
......@@ -152,22 +152,23 @@ public final class JavaIdentifierSyntax {
/**
* Translate the YANG identifier name to java identifier.
*
* @param yangIdentifier identifier in YANG file.
* @param yangIdentifier identifier in YANG file
* @return corresponding java identifier
*/
public static String getCamelCase(String yangIdentifier) {
String[] strArray = yangIdentifier.split(UtilConstants.HYPHEN);
String camelCase = strArray[0];
for (int i = 1; i < strArray.length; i++) {
camelCase = camelCase + (strArray[i].substring(0, 1).toUpperCase() + strArray[i].substring(1));
camelCase = camelCase + strArray[i].substring(0, 1).toUpperCase() + strArray[i].substring(1);
}
return camelCase;
}
/**
* Translate the YANG identifier name to java identifier with first letter in caps.
* Translate the YANG identifier name to java identifier with first letter
* in caps.
*
* @param yangIdentifier identifier in YANG file.
* @param yangIdentifier identifier in YANG file
* @return corresponding java identifier
*/
public static String getCaptialCase(String yangIdentifier) {
......
......@@ -16,12 +16,7 @@
package org.onosproject.yangutils.translator.tojava.utils;
import java.util.List;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.translator.GeneratedFileType;
import org.onosproject.yangutils.translator.tojava.AttributeInfo;
import org.onosproject.yangutils.translator.tojava.GeneratedMethodTypes;
import org.onosproject.yangutils.utils.UtilConstants;
import org.onosproject.yangutils.utils.io.impl.JavaDocGen;
......@@ -30,45 +25,6 @@ import org.onosproject.yangutils.utils.io.impl.JavaDocGen;
*/
public final class MethodsGenerator {
private static String builderClassName;
private static List<AttributeInfo> attrInfo;
/**
* Sets the builder class name for setter methods of builder class.
*
* @param name builder class name
*/
public static void setBuilderClassName(String name) {
builderClassName = name;
}
/**
* Sets the attribute info for the impl class's constructor method.
*
* @param attr list of attribute info
*/
public static void setAttrInfo(List<AttributeInfo> attr) {
attrInfo = attr;
}
/**
* Returns attribute info for the impl class's constructor method.
*
* @return list of attribute info
*/
public static List<AttributeInfo> getAttrInfo() {
return attrInfo;
}
/**
* Return the class name.
*
* @return class name
*/
public static String getBuilderClassName() {
return builderClassName;
}
/**
* Default constructor.
*/
......@@ -76,181 +32,106 @@ public final class MethodsGenerator {
}
/**
* Return method strings.
*
* @param attr attribute info.
* @param type generated file type
* @return method string
*/
public static String getMethodString(AttributeInfo attr, GeneratedFileType type) {
if (type.equals(GeneratedFileType.BUILDER_CLASS)) {
return parseBuilderMethodString(attr);
} else if (type.equals(GeneratedFileType.INTERFACE)) {
return getGetterString(attr);
} else if (type.equals(GeneratedFileType.BUILDER_INTERFACE)) {
return parseBuilderInterfaceMethodString(attr);
} else if (type.equals(GeneratedFileType.IMPL)) {
return parseImplMethodString(attr);
}
return null;
}
/**
* Returns constructed method impl for specific generated file type.
* Returns the methods strings for builder class.
*
* @param genFileTypes generated file type
* @param yangName class name
* @param methodTypes method types
* @param returnType return type of method
* @return constructed method impl
* @param attr attribute info
* @param className java class name
* @return method string for builder class
*/
public static String constructMethodInfo(GeneratedFileType genFileTypes, String yangName,
GeneratedMethodTypes methodTypes, YangType<?> returnType) {
if (returnType == null) {
YangType<?> type = new YangType();
type.setDataTypeName(yangName);
returnType = type;
static String parseBuilderMethodString(AttributeInfo attr, String className) {
String attrQuaifiedType = "";
if (attr.getImportInfo().getPkgInfo() != null) {
attrQuaifiedType = attr.getImportInfo().getPkgInfo() + ".";
}
attrQuaifiedType = attrQuaifiedType + attr.getImportInfo().getClassInfo();
if (genFileTypes.equals(GeneratedFileType.INTERFACE)) {
/**
* If interface, only getter will be there.
*/
return getGetterForInterface(yangName, returnType);
} else if (genFileTypes.equals(GeneratedFileType.BUILDER_INTERFACE)) {
/**
* If builder interface, getters and setters will be there.
*/
if (methodTypes.equals(GeneratedMethodTypes.GETTER)) {
return getGetterForInterface(yangName, returnType);
} else if (methodTypes.equals(GeneratedMethodTypes.SETTER)) {
return getSetterForInterface(yangName, returnType);
} else if (methodTypes.equals(GeneratedMethodTypes.BUILD)) {
return getBuildForInterface(yangName);
}
} else if (genFileTypes.equals(GeneratedFileType.BUILDER_CLASS)) {
/**
* If Builder class , getters, setters ,build and default constructor impls will be there.
*/
if (methodTypes.equals(GeneratedMethodTypes.GETTER)) {
return getGetterForClass(yangName, returnType);
} else if (methodTypes.equals(GeneratedMethodTypes.SETTER)) {
return getSetterForClass(yangName, returnType);
} else if (methodTypes.equals(GeneratedMethodTypes.BUILD)) {
return getBuild(yangName);
} else if (methodTypes.equals(GeneratedMethodTypes.DEFAULT_CONSTRUCTOR)) {
return getDefaultConstructor(yangName + UtilConstants.BUILDER);
}
} else if (genFileTypes.equals(GeneratedFileType.IMPL)) {
if (methodTypes.equals(GeneratedMethodTypes.GETTER)) {
return getGetterForClass(yangName, returnType);
} else if (methodTypes.equals(GeneratedMethodTypes.CONSTRUCTOR)) {
return getConstructor(yangName);
} else if (methodTypes.equals(GeneratedMethodTypes.DEFAULT_CONSTRUCTOR)) {
return getDefaultConstructor(yangName + UtilConstants.IMPL);
}
}
return null;
String overrideString = UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION
+ UtilConstants.OVERRIDE + UtilConstants.NEW_LINE;
String getterString = getGetterForClass(attr.getAttributeName(), attrQuaifiedType);
String setterString = getSetterForClass(attr.getAttributeName(), attrQuaifiedType, className);
return overrideString + getterString + UtilConstants.NEW_LINE + overrideString + setterString;
}
/**
* Returns the methods strings for builder class.
*
* @param attr attribute info.
* @return method string for builder class.
* @param attr attribute info
* @return method string for builder class
*/
private static String parseBuilderMethodString(AttributeInfo attr) {
static String parseImplMethodString(AttributeInfo attr) {
String overrideString = UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.OVERRIDE
+ UtilConstants.NEW_LINE;
String getterString = JavaCodeSnippetGen.getJavaMethodInfo(GeneratedFileType.BUILDER_CLASS,
attr.getAttributeName(), GeneratedMethodTypes.GETTER, attr.getAttributeType());
String setterString = JavaCodeSnippetGen.getJavaMethodInfo(GeneratedFileType.BUILDER_CLASS,
attr.getAttributeName(), GeneratedMethodTypes.SETTER, attr.getAttributeType());
return overrideString + getterString + UtilConstants.NEW_LINE + overrideString + setterString;
String attrQuaifiedType = "";
if (attr.getImportInfo().getPkgInfo() != null) {
attrQuaifiedType = attr.getImportInfo().getPkgInfo() + ".";
}
/**
* Returns the methods strings for builder class.
*
* @param attr attribute info.
* @return method string for builder class.
*/
private static String parseImplMethodString(AttributeInfo attr) {
attrQuaifiedType = attrQuaifiedType + attr.getImportInfo().getClassInfo();
return UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.OVERRIDE
+ UtilConstants.NEW_LINE + JavaCodeSnippetGen.getJavaMethodInfo(GeneratedFileType.BUILDER_CLASS,
attr.getAttributeName(), GeneratedMethodTypes.GETTER, attr.getAttributeType());
+ UtilConstants.NEW_LINE + getGetterForClass(attr.getAttributeName(), attrQuaifiedType);
}
/**
* Returns the methods strings for builder interface.
*
* @param attr attribute info.
* @return method string for builder interface.
* @param attr attribute info
* @param className name of the java class being generated
* @return method string for builder interface
*/
private static String parseBuilderInterfaceMethodString(AttributeInfo attr) {
static String parseBuilderInterfaceMethodString(AttributeInfo attr, String className) {
return getGetterString(attr) + UtilConstants.NEW_LINE + getSetterString(attr);
return getGetterString(attr) + UtilConstants.NEW_LINE + getSetterString(attr, className);
}
/**
* Returns the methods strings for builder interface.
*
* @param name attribute name.
* @return method string for builder interface.
* @param name attribute name
* @return method string for builder interface
*/
public static String parseBuilderInterfaceBuildMethodString(String name) {
return JavaDocGen.getJavaDoc(JavaDocGen.JavaDocType.BUILD, name) + JavaCodeSnippetGen
.getJavaMethodInfo(GeneratedFileType.BUILDER_INTERFACE, name, GeneratedMethodTypes.BUILD, null);
return JavaDocGen.getJavaDoc(JavaDocGen.JavaDocType.BUILD, name)
+ getBuildForInterface(name);
}
/**
* Returns getter string.
*
* @param attr attribute info.
* @param attr attribute info
* @return getter string
*/
public static String getGetterString(AttributeInfo attr) {
String returnType = "";
if (attr.getImportInfo().getPkgInfo() != null) {
returnType = attr.getImportInfo().getPkgInfo() + ".";
}
returnType = returnType + attr.getImportInfo().getClassInfo();
return JavaDocGen.getJavaDoc(JavaDocGen.JavaDocType.GETTER, attr.getAttributeName())
+ JavaCodeSnippetGen.getJavaMethodInfo(GeneratedFileType.INTERFACE, attr.getAttributeName(),
GeneratedMethodTypes.GETTER, attr.getAttributeType())
+ getGetterForInterface(attr.getAttributeName(), returnType)
+ UtilConstants.NEW_LINE;
}
/**
* Returns setter string.
*
* @param attr attribute info.
* @param attr attribute info
* @param className java class name
* @return setter string
*/
private static String getSetterString(AttributeInfo attr) {
private static String getSetterString(AttributeInfo attr, String className) {
String attrType = "";
if (attr.getImportInfo().getPkgInfo() != null) {
attrType = attr.getImportInfo().getPkgInfo() + ".";
}
attrType = attrType + attr.getImportInfo().getClassInfo();
return JavaDocGen.getJavaDoc(JavaDocGen.JavaDocType.SETTER, attr.getAttributeName())
+ JavaCodeSnippetGen.getJavaMethodInfo(GeneratedFileType.BUILDER_INTERFACE, attr.getAttributeName(),
GeneratedMethodTypes.SETTER, attr.getAttributeType());
+ getSetterForInterface(attr.getAttributeName(), attrType, className);
}
/**
......@@ -261,8 +142,8 @@ public final class MethodsGenerator {
*/
public static String getConstructorString(String name) {
return JavaDocGen.getJavaDoc(JavaDocGen.JavaDocType.CONSTRUCTOR, name) + JavaCodeSnippetGen
.getJavaMethodInfo(GeneratedFileType.IMPL, name, GeneratedMethodTypes.CONSTRUCTOR, null);
return JavaDocGen.getJavaDoc(JavaDocGen.JavaDocType.CONSTRUCTOR, name)
+ getConstructor(name);
}
/**
......@@ -272,10 +153,10 @@ public final class MethodsGenerator {
* @param name class name
* @return default constructor string
*/
public static String getDefaultConstructorString(GeneratedFileType type, String name) {
public static String getDefaultConstructorString(int type, String name) {
return JavaDocGen.getJavaDoc(JavaDocGen.JavaDocType.DEFAULT_CONSTRUCTOR, name)
+ JavaCodeSnippetGen.getJavaMethodInfo(type, name, GeneratedMethodTypes.DEFAULT_CONSTRUCTOR, null);
+ getDefaultConstructor(name + UtilConstants.BUILDER);
}
/**
......@@ -287,83 +168,85 @@ public final class MethodsGenerator {
public static String getBuildString(String name) {
return UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.OVERRIDE + UtilConstants.NEW_LINE
+ JavaCodeSnippetGen.getJavaMethodInfo(GeneratedFileType.BUILDER_CLASS, name,
GeneratedMethodTypes.BUILD, null);
+ getBuild(name);
}
/**
* Returns the getter method strings for class file.
*
* @param yangName name of the attribute.
* @param returnType return type of attribute
* @return getter method for class.
* @param attrName name of the attribute
* @param attrType return type of attribute
* @return getter method for class
*/
private static String getGetterForClass(String yangName, YangType<?> returnType) {
private static String getGetterForClass(String attrName, String attrType) {
return UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.PUBLIC + UtilConstants.SPACE
+ JavaIdentifierSyntax.getCaptialCase(returnType.getDataTypeName()) + UtilConstants.SPACE
+ UtilConstants.GET_METHOD_PREFIX + JavaIdentifierSyntax.getCaptialCase(yangName)
+ UtilConstants.OPEN_PARENTHESIS + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SPACE
+ UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE + UtilConstants.EIGHT_SPACE_INDENTATION
+ UtilConstants.RETURN + UtilConstants.SPACE + yangName + UtilConstants.SEMI_COLAN
+ UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.CLOSE_CURLY_BRACKET;
+ attrType + UtilConstants.SPACE + UtilConstants.GET_METHOD_PREFIX
+ JavaIdentifierSyntax.getCaptialCase(attrName) + UtilConstants.OPEN_PARENTHESIS
+ UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SPACE + UtilConstants.OPEN_CURLY_BRACKET
+ UtilConstants.NEW_LINE + UtilConstants.EIGHT_SPACE_INDENTATION + UtilConstants.RETURN
+ UtilConstants.SPACE + attrName + UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE
+ UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.CLOSE_CURLY_BRACKET;
}
/**
* Returns the setter method strings for class file.
*
* @param yangName name of the attribute.
* @param returnType return type of attribute
* @return setter method for class.
* @param attrName name of the attribute
* @param attrType return type of attribute
* @param className name of the class
* @return setter method for class
*/
private static String getSetterForClass(String yangName, YangType<?> returnType) {
return UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.PUBLIC + UtilConstants.SPACE + getBuilderClassName()
+ UtilConstants.SPACE + UtilConstants.SET_METHOD_PREFIX + JavaIdentifierSyntax.getCaptialCase(yangName)
+ UtilConstants.OPEN_PARENTHESIS + JavaIdentifierSyntax.getCaptialCase(returnType.getDataTypeName())
+ UtilConstants.SPACE + yangName + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SPACE
+ UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE + UtilConstants.EIGHT_SPACE_INDENTATION
+ UtilConstants.THIS + UtilConstants.PERIOD + yangName + UtilConstants.SPACE + UtilConstants.EQUAL
+ UtilConstants.SPACE + yangName + UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE
+ UtilConstants.EIGHT_SPACE_INDENTATION + UtilConstants.RETURN + UtilConstants.SPACE
+ UtilConstants.THIS + UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE
+ UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.CLOSE_CURLY_BRACKET;
private static String getSetterForClass(String attrName, String attrType, String className) {
return UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.PUBLIC + UtilConstants.SPACE
+ className + UtilConstants.BUILDER + UtilConstants.SPACE + UtilConstants.SET_METHOD_PREFIX
+ JavaIdentifierSyntax.getCaptialCase(attrName) + UtilConstants.OPEN_PARENTHESIS
+ attrType + UtilConstants.SPACE + attrName + UtilConstants.CLOSE_PARENTHESIS
+ UtilConstants.SPACE + UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE
+ UtilConstants.EIGHT_SPACE_INDENTATION + UtilConstants.THIS + UtilConstants.PERIOD
+ attrName + UtilConstants.SPACE + UtilConstants.EQUAL + UtilConstants.SPACE + attrName
+ UtilConstants.SEMI_COLAN + UtilConstants.NEW_LINE + UtilConstants.EIGHT_SPACE_INDENTATION
+ UtilConstants.RETURN + UtilConstants.SPACE + UtilConstants.THIS + UtilConstants.SEMI_COLAN
+ UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.CLOSE_CURLY_BRACKET;
}
/**
* Returns the getter method strings for interface file.
*
* @param yangName name of the attribute.
* @param yangName name of the attribute
* @param returnType return type of attribute
* @return getter method for interface.
* @return getter method for interface
*/
private static String getGetterForInterface(String yangName, YangType<?> returnType) {
returnType.setDataTypeName(returnType.getDataTypeName().replace("\"", ""));
return UtilConstants.FOUR_SPACE_INDENTATION + JavaIdentifierSyntax.getCaptialCase(returnType.getDataTypeName())
+ UtilConstants.SPACE + UtilConstants.GET_METHOD_PREFIX + JavaIdentifierSyntax.getCaptialCase(yangName)
+ UtilConstants.OPEN_PARENTHESIS + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SEMI_COLAN;
private static String getGetterForInterface(String yangName, String returnType) {
return UtilConstants.FOUR_SPACE_INDENTATION + returnType
+ UtilConstants.SPACE + UtilConstants.GET_METHOD_PREFIX
+ JavaIdentifierSyntax.getCaptialCase(yangName)
+ UtilConstants.OPEN_PARENTHESIS + UtilConstants.CLOSE_PARENTHESIS
+ UtilConstants.SEMI_COLAN;
}
/**
* Returns the setter method strings for interface file.
*
* @param yangName name of the attribute.
* @param returnType return type of attribute
* @return setter method for interface.
* @param attrName name of the attribute
* @param attrType return type of attribute
* @param className name of the java class being generated
* @return setter method for interface
*/
private static String getSetterForInterface(String yangName, YangType<?> returnType) {
return UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.BUILDER + UtilConstants.SPACE
+ UtilConstants.SET_METHOD_PREFIX + JavaIdentifierSyntax.getCaptialCase(yangName)
+ UtilConstants.OPEN_PARENTHESIS + JavaIdentifierSyntax.getCaptialCase(returnType.getDataTypeName())
+ UtilConstants.SPACE + yangName + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SEMI_COLAN;
private static String getSetterForInterface(String attrName, String attrType, String className) {
return UtilConstants.FOUR_SPACE_INDENTATION + className + UtilConstants.BUILDER
+ UtilConstants.SPACE + UtilConstants.SET_METHOD_PREFIX
+ JavaIdentifierSyntax.getCaptialCase(attrName) + UtilConstants.OPEN_PARENTHESIS
+ attrType + UtilConstants.SPACE + attrName + UtilConstants.CLOSE_PARENTHESIS
+ UtilConstants.SEMI_COLAN;
}
/**
* Returns the build method strings for interface file.
*
* @param yangName name of the attribute.
* @param returnType return type of attribute
* @return build method for interface.
* @param yangName name of the interface
* @return build method for interface
*/
private static String getBuildForInterface(String yangName) {
......@@ -374,30 +257,33 @@ public final class MethodsGenerator {
/**
* Returns the constructor strings for class file.
*
* @param yangName name of the class.
* @param yangName name of the class
* @return constructor for class
*/
private static String getConstructor(String yangName) {
String builderAttribute = (yangName.substring(0, 1).toLowerCase() + yangName.substring(1));
String builderAttribute = yangName.substring(0, 1).toLowerCase() + yangName.substring(1);
String constructor = UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.PUBLIC + UtilConstants.SPACE
+ yangName + UtilConstants.IMPL + UtilConstants.OPEN_PARENTHESIS + yangName + UtilConstants.BUILDER
+ UtilConstants.SPACE + builderAttribute + UtilConstants.OBJECT + UtilConstants.CLOSE_PARENTHESIS
+ UtilConstants.SPACE + UtilConstants.OPEN_CURLY_BRACKET + UtilConstants.NEW_LINE;
if (getAttrInfo() != null) {
for (AttributeInfo attribute : getAttrInfo()) {
attribute.setAttributeName(JavaIdentifierSyntax.getCamelCase(attribute.getAttributeName()));
constructor = constructor + UtilConstants.TWELVE_SPACE_INDENTATION + UtilConstants.THIS
+ UtilConstants.PERIOD + attribute.getAttributeName() + UtilConstants.SPACE
+ UtilConstants.EQUAL + UtilConstants.SPACE + builderAttribute + UtilConstants.OBJECT
+ UtilConstants.PERIOD + UtilConstants.GET_METHOD_PREFIX
+ JavaIdentifierSyntax.getCaptialCase(attribute.getAttributeName())
+ UtilConstants.OPEN_PARENTHESIS + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SEMI_COLAN
+ UtilConstants.NEW_LINE;
}
getAttrInfo().clear();
}
// TODO: need to get the partial constructor from constructor temp file.
// if (getAttrInfo() != null) {
// for (AttributeInfo attribute : getAttrInfo()) {
// attribute.setAttributeName(JavaIdentifierSyntax.getCamelCase(attribute.getAttributeName()));
// constructor = constructor + UtilConstants.TWELVE_SPACE_INDENTATION + UtilConstants.THIS
// + UtilConstants.PERIOD + attribute.getAttributeName() + UtilConstants.SPACE
// + UtilConstants.EQUAL + UtilConstants.SPACE + builderAttribute + UtilConstants.OBJECT
// + UtilConstants.PERIOD + UtilConstants.GET_METHOD_PREFIX
// + JavaIdentifierSyntax.getCaptialCase(attribute.getAttributeName())
// + UtilConstants.OPEN_PARENTHESIS
// + UtilConstants.CLOSE_PARENTHESIS + UtilConstants.SEMI_COLAN
// + UtilConstants.NEW_LINE;
// }
// getAttrInfo().clear();
// }
return constructor + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.CLOSE_CURLY_BRACKET;
}
......@@ -405,7 +291,7 @@ public final class MethodsGenerator {
* Returns the build method strings for class file.
*
* @param yangName class name
* @return build method string for class.
* @return build method string for class
*/
private static String getBuild(String yangName) {
......@@ -422,7 +308,7 @@ public final class MethodsGenerator {
/**
* Returns the Default constructor strings for class file.
*
* @param yangName name of the class.
* @param name name of the class
* @return Default constructor for class
*/
private static String getDefaultConstructor(String name) {
......
......@@ -34,7 +34,7 @@ public final class UtilConstants {
public static final String BUILDER_CLASS_JAVA_DOC = " * Provides the builder implementation of ";
public static final String INTERFACE_JAVA_DOC = " * Abstraction of an entity which provides functionalities of ";
public static final String BUILDER_INTERFACE_JAVA_DOC = " * Builder for ";
public static final String PACKAGE_INFO_JAVADOC = " * Generated java code for the YANG file ";
public static final String PACKAGE_INFO_JAVADOC = " * Generated java code corresponding to YANG ";
public static final String JAVA_DOC_FIRST_LINE = "/**\n";
public static final String JAVA_DOC_END_LINE = " */\n";
public static final String JAVA_DOC_PARAM = " * @param ";
......@@ -93,7 +93,7 @@ public final class UtilConstants {
/**
* For directories.
*/
public static final String YANG_GEN_DIR = "src/main/yangmodal/";
public static final String YANG_GEN_DIR = "src/main/yangmodel/";
public static final String DEFAULT_BASE_PKG = "org.onosproject.yang.gen";
public static final String REVISION_PREFIX = "rev";
public static final String VERSION_PREFIX = "v";
......@@ -108,17 +108,91 @@ public final class UtilConstants {
/**
* For data types.
*/
public static final String INT = "int";
/**
* Void java type.
*/
public static final String VOID = "void";
/**
* String built in java type.
*/
public static final String STRING = "String";
/**
* java.lang.* packages.
*/
public static final String JAVA_LANG = "java.lang";
/**
* boolean built in java type.
*/
public static final String BOOLEAN = "boolean";
/**
* 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";
public static final String BOOLEAN = "boolean";
public static final String STRING = "String";
/**
* float java built in type.
*/
public static final String FLOAT = "float";
public static final String BYTE = "byte";
/**
* 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";
/**
* float java built in wrapper type.
*/
public static final String FLOAT_WRAPPER = "Float";
/**
* double java built in wrapper type.
*/
public static final String DOUBLE_WRAPPER = "Double";
/**
* For idenifiers.
*/
public static final String CLASS = "class";
......
......@@ -242,8 +242,8 @@ public enum YangConstructType {
/**
* Returns the YANG construct keyword corresponding to enum values.
*
* @param yangConstructType enum value for parsable data type
* @return YANG construct keyword
* @param yangConstructType enum value for parsable data type.
* @return YANG construct keyword.
*/
public static String getYangConstructType(YangConstructType yangConstructType) {
......
......@@ -24,9 +24,10 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import static org.slf4j.LoggerFactory.getLogger;
import org.slf4j.Logger;
import static org.slf4j.LoggerFactory.getLogger;
/**
* Provides the license header for the generated files.
*/
......@@ -48,7 +49,7 @@ public final class CopyrightHeader {
* Returns copyright file header.
*
* @return copyright file header
* @throws IOException when fails to parse copyright header.
* @throws IOException when fails to parse copyright header
*/
public static String getCopyrightHeader() throws IOException {
return copyrightHeader;
......@@ -66,7 +67,7 @@ public final class CopyrightHeader {
/**
* parse Copyright to the temporary file.
*
* @throws IOException when fails to get the copyright header.
* @throws IOException when fails to get the copyright header
*/
public static void parseCopyrightHeader() throws IOException {
......
......@@ -24,7 +24,6 @@ import java.io.IOException;
import java.io.PrintWriter;
import org.onosproject.yangutils.translator.CachedFileHandle;
import org.onosproject.yangutils.translator.GeneratedFileType;
import org.onosproject.yangutils.translator.tojava.CachedJavaFileHandle;
import org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax;
import org.onosproject.yangutils.utils.UtilConstants;
......@@ -42,8 +41,8 @@ public final class FileSystemUtil {
/**
* Check if the package directory structure created.
*
* @param pkg Package to check if it is created.
* @return existence status of package.
* @param pkg Package to check if it is created
* @return existence status of package
*/
public static boolean doesPackageExist(String pkg) {
File pkgDir = new File(pkg.replace(UtilConstants.PERIOD, UtilConstants.SLASH));
......@@ -76,13 +75,16 @@ public final class FileSystemUtil {
/**
* Create a java source file in the specified package.
*
* @param pkg java package under which the interface file needs to be created.
* @param yangName YANG name of the node for which java file needs to be created.
* @param types types of files to be created.
* @throws IOException when fails to create interface file.
* @return the cached java file handle, which can be used to further add methods.
* @param pkg java package under which the interface file needs to be
* created
* @param yangName YANG name of the node for which java file needs to be
* created
* @param types types of files to be created
* @throws IOException when fails to create interface file
* @return the cached java file handle, which can be used to further add
* methods
*/
public static CachedFileHandle createSourceFiles(String pkg, String yangName, GeneratedFileType types)
public static CachedFileHandle createSourceFiles(String pkg, String yangName, int types)
throws IOException {
yangName = JavaIdentifierSyntax.getCamelCase(yangName);
CachedFileHandle handler = new CachedJavaFileHandle(pkg, yangName, types);
......@@ -95,10 +97,10 @@ public final class FileSystemUtil {
* file.
*
* @param toAppend destination file in which the contents of source file is
* appended.
* appended
* @param srcFile source file from which data is read and added to to append
* file.
* @throws IOException any IO errors.
* file
* @throws IOException any IO errors
*/
public static void appendFileContents(File toAppend, File srcFile) throws IOException {
......@@ -109,8 +111,8 @@ public final class FileSystemUtil {
/**
* Reads file and convert it to string.
*
* @param toAppend file to be converted.
* @return string of file.
* @param toAppend file to be converted
* @return string of file
* @throws IOException when fails to convert to string
*/
private static String readAppendFile(String toAppend) throws IOException {
......@@ -134,8 +136,8 @@ public final class FileSystemUtil {
* Insert content to the generated file.
*
* @param inputFile input file
* @param contentTobeAdded content to be appended to the file.
* @throws IOException when fails to append content to the file.
* @param contentTobeAdded content to be appended to the file
* @throws IOException when fails to append content to the file
*/
public static void insertStringInFile(File inputFile, String contentTobeAdded) throws IOException {
FileWriter fileWriter = new FileWriter(inputFile, true);
......
......@@ -91,7 +91,7 @@ public final class JavaDocGen {
*
* @param type java doc type
* @param name name of the YangNode
* @return javadocs.
* @return javadocs
*/
public static String getJavaDoc(JavaDocType type, String name) {
name = JavaIdentifierSyntax.getCamelCase(name);
......@@ -127,12 +127,12 @@ public final class JavaDocGen {
* @return javaDocs
*/
private static String generateForGetters(String attribute) {
return (UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_FIRST_LINE
return UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_FIRST_LINE
+ UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_GETTERS + attribute
+ UtilConstants.PERIOD + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION
+ UtilConstants.NEW_LINE_ESTRIC + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_RETURN
+ attribute + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION
+ UtilConstants.JAVA_DOC_END_LINE);
+ UtilConstants.JAVA_DOC_END_LINE;
}
/**
......@@ -142,58 +142,58 @@ public final class JavaDocGen {
* @return javaDocs
*/
private static String generateForSetters(String attribute) {
return (UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_FIRST_LINE
return UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_FIRST_LINE
+ UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_SETTERS + attribute
+ UtilConstants.PERIOD + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION
+ UtilConstants.NEW_LINE_ESTRIC + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_PARAM
+ attribute + UtilConstants.SPACE + attribute + UtilConstants.NEW_LINE
+ UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_RETURN + UtilConstants.BUILDER_OBJECT
+ attribute + UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION
+ UtilConstants.JAVA_DOC_END_LINE);
+ UtilConstants.JAVA_DOC_END_LINE;
}
/**
* Generate javaDocs for the impl class.
*
* @param className class name
* @return javaDocs.
* @return javaDocs
*/
private static String generateForImplClass(String className) {
return (UtilConstants.JAVA_DOC_FIRST_LINE + UtilConstants.IMPL_CLASS_JAVA_DOC + className + UtilConstants.PERIOD
+ UtilConstants.NEW_LINE + UtilConstants.JAVA_DOC_END_LINE);
return UtilConstants.JAVA_DOC_FIRST_LINE + UtilConstants.IMPL_CLASS_JAVA_DOC + className + UtilConstants.PERIOD
+ UtilConstants.NEW_LINE + UtilConstants.JAVA_DOC_END_LINE;
}
/**
* Generate javaDocs for the builder class.
*
* @param className class name
* @return javaDocs.
* @return javaDocs
*/
private static String generateForBuilderClass(String className) {
return (UtilConstants.JAVA_DOC_FIRST_LINE + UtilConstants.BUILDER_CLASS_JAVA_DOC + className
+ UtilConstants.PERIOD + UtilConstants.NEW_LINE + UtilConstants.JAVA_DOC_END_LINE);
return UtilConstants.JAVA_DOC_FIRST_LINE + UtilConstants.BUILDER_CLASS_JAVA_DOC + className
+ UtilConstants.PERIOD + UtilConstants.NEW_LINE + UtilConstants.JAVA_DOC_END_LINE;
}
/**
* Generate javaDoc for the interface.
*
* @param interfaceName interface name
* @return javaDocs.
* @return javaDocs
*/
private static String generateForInterface(String interfaceName) {
return (UtilConstants.JAVA_DOC_FIRST_LINE + UtilConstants.INTERFACE_JAVA_DOC + interfaceName
+ UtilConstants.PERIOD + UtilConstants.NEW_LINE + UtilConstants.JAVA_DOC_END_LINE);
return UtilConstants.JAVA_DOC_FIRST_LINE + UtilConstants.INTERFACE_JAVA_DOC + interfaceName
+ UtilConstants.PERIOD + UtilConstants.NEW_LINE + UtilConstants.JAVA_DOC_END_LINE;
}
/**
* Generate javaDoc for the builder interface.
*
* @param builderforName builder for name
* @return javaDocs.
* @return javaDocs
*/
private static String generateForBuilderInterface(String builderforName) {
return (UtilConstants.JAVA_DOC_FIRST_LINE + UtilConstants.BUILDER_INTERFACE_JAVA_DOC + builderforName
+ UtilConstants.PERIOD + UtilConstants.NEW_LINE + UtilConstants.JAVA_DOC_END_LINE);
return UtilConstants.JAVA_DOC_FIRST_LINE + UtilConstants.BUILDER_INTERFACE_JAVA_DOC + builderforName
+ UtilConstants.PERIOD + UtilConstants.NEW_LINE + UtilConstants.JAVA_DOC_END_LINE;
}
/**
......@@ -203,8 +203,8 @@ public final class JavaDocGen {
* @return javaDocs
*/
private static String generateForPackage(String packageName) {
return (UtilConstants.JAVA_DOC_FIRST_LINE + UtilConstants.PACKAGE_INFO_JAVADOC + packageName
+ UtilConstants.PERIOD + UtilConstants.NEW_LINE + UtilConstants.JAVA_DOC_END_LINE);
return UtilConstants.JAVA_DOC_FIRST_LINE + UtilConstants.PACKAGE_INFO_JAVADOC + packageName
+ UtilConstants.PERIOD + UtilConstants.NEW_LINE + UtilConstants.JAVA_DOC_END_LINE;
}
/**
......@@ -213,38 +213,38 @@ public final class JavaDocGen {
* @return javaDocs
*/
private static String generateForDefaultConstructors() {
return (UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_DEFAULT_CONSTRUCTOR
+ UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_END_LINE);
return UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_DEFAULT_CONSTRUCTOR
+ UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_END_LINE;
}
/**
* Generate javaDocs for constructor with parameters.
*
* @param params list of parameters
* @param className class name
* @return javaDocs
*/
private static String generateForConstructors(String className) {
return (UtilConstants.JAVA_DOC_FIRST_LINE + UtilConstants.FOUR_SPACE_INDENTATION
return UtilConstants.JAVA_DOC_FIRST_LINE + UtilConstants.FOUR_SPACE_INDENTATION
+ UtilConstants.JAVA_DOC_CONSTRUCTOR + className + UtilConstants.IMPL + UtilConstants.PERIOD
+ UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.NEW_LINE_ESTRIC
+ UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_PARAM
+ (className.substring(0, 1).toLowerCase() + className.substring(1)) + UtilConstants.OBJECT
+ className.substring(0, 1).toLowerCase() + className.substring(1) + UtilConstants.OBJECT
+ UtilConstants.SPACE + UtilConstants.BUILDER_OBJECT + UtilConstants.SPACE + className
+ UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_END_LINE);
+ UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_END_LINE;
}
/**
* Generate javaDocs for build.
*
* @param buildName builder name
* @return javaDocs
*/
private static String generateForBuild(String buildName) {
return (UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_FIRST_LINE
return UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_FIRST_LINE
+ UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_BUILD + buildName + UtilConstants.PERIOD
+ UtilConstants.NEW_LINE + UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.NEW_LINE_ESTRIC
+ UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_RETURN
+ UtilConstants.JAVA_DOC_BUILD_RETURN + buildName + UtilConstants.PERIOD + UtilConstants.NEW_LINE
+ UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_END_LINE);
+ UtilConstants.FOUR_SPACE_INDENTATION + UtilConstants.JAVA_DOC_END_LINE;
}
}
......
......@@ -33,7 +33,8 @@ import java.util.ArrayList;
import java.util.List;
/**
* Provides storage for Temp data while traversing data model tree for code generation.
* Provides storage for Temp data while traversing data model tree for code
* generation.
*/
public final class TempDataStore {
......@@ -130,7 +131,7 @@ public final class TempDataStore {
* @param data data to be stored
* @param type type of Temp data store
* @param className class name
* @throws IOException when fails to create a Temp data file.
* @throws IOException when fails to create a Temp data file
*/
public static void setTempData(String data, TempDataStoreType type, String className) throws IOException {
......@@ -170,11 +171,11 @@ public final class TempDataStore {
* Get the Temp data.
*
* @param type type of Temp data store
* @param className name of the class.
* @return list of attribute info.
* @throws IOException when fails to read from the file.
* @throws ClassNotFoundException when class is missing.
* @throws FileNotFoundException when file is missing.
* @param className name of the class
* @return list of attribute info
* @throws IOException when fails to read from the file
* @throws ClassNotFoundException when class is missing
* @throws FileNotFoundException when file is missing
*/
public static List<String> getTempData(TempDataStoreType type, String className)
throws IOException, FileNotFoundException, ClassNotFoundException {
......
......@@ -37,10 +37,10 @@ public final class YangFileScanner {
* Returns the list of java files.
*
* @param root specified directory
* @return list of java files.
* @throws NullPointerException when no files are there.
* @return list of java files
* @throws NullPointerException when no files are there
* @throws IOException when files get deleted while performing the
* operations.
* operations
*/
public static List<String> getJavaFiles(String root) throws NullPointerException, IOException {
return getFiles(root, ".java");
......@@ -50,10 +50,10 @@ public final class YangFileScanner {
* Returns the list of YANG files.
*
* @param root specified directory
* @return list of YANG files.
* @throws NullPointerException when no files are there.
* @return list of YANG files
* @throws NullPointerException when no files are there
* @throws IOException when files get deleted while performing the
* operations.
* operations
*/
public static List<String> getYangFiles(String root) throws NullPointerException, IOException {
return getFiles(root, ".yang");
......@@ -63,10 +63,11 @@ public final class YangFileScanner {
* Returns the list of required files.
*
* @param root specified directory
* @param extension file extension.
* @return list of required files.
* @param extension file extension
* @return list of required files
* @throws IOException when files get deleted while performing the
* operations.
* operations
* @throws NullPointerException null pointer access
*/
public static List<String> getFiles(String root, String extension) throws NullPointerException, IOException {
List<String> store = new LinkedList<>();
......
......@@ -22,15 +22,14 @@ import java.io.FileWriter;
import java.io.IOException;
import java.util.List;
import org.sonatype.plexus.build.incremental.BuildContext;
import org.apache.maven.project.MavenProject;
import org.apache.commons.io.FileUtils;
import org.apache.maven.model.Resource;
import org.apache.maven.project.MavenProject;
import org.onosproject.yangutils.utils.UtilConstants;
import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
import org.sonatype.plexus.build.incremental.BuildContext;
import static org.slf4j.LoggerFactory.getLogger;
import org.slf4j.Logger;
/**
* Provides common utility functionalities for code generation.
......@@ -64,7 +63,7 @@ public final class YangIoUtils {
* @param path directory path
* @param classInfo class info for the package
* @param pack package of the directory
* @throws IOException when fails to create package info file.
* @throws IOException when fails to create package info file
*/
public static void addPackageInfo(File path, String classInfo, String pack) throws IOException {
......@@ -92,7 +91,7 @@ public final class YangIoUtils {
/**
* Cleans the generated directory if already exist in source folder.
*
* @param baseDir generated directory in previous build.
* @param baseDir generated directory in previous build
*/
public static void clean(String baseDir) {
File generatedDirectory = new File(baseDir + File.separator + UtilConstants.YANG_GEN_DIR);
......
......@@ -151,7 +151,7 @@ public class ListListenerTest {
assertThat(yangList.getKeyList().contains("invalid-interval"), is(true));
assertThat(yangList.isConfig(), is(true));
assertThat(yangList.getMaxElelements(), is(10));
assertThat(yangList.getMaxElements(), is(10));
assertThat(yangList.getMinElements(), is(3));
assertThat(yangList.getDescription(), is("\"list description\""));
assertThat(yangList.getStatus(), is(YangStatusType.CURRENT));
......
......@@ -88,7 +88,7 @@ public class MaxElementsListenerTest {
// Check whether the list is child of module
YangList yangList = (YangList) yangNode.getChild();
assertThat(yangList.getName(), is("valid"));
assertThat(yangList.getMaxElelements(), is(3));
assertThat(yangList.getMaxElements(), is(3));
}
/**
......
......@@ -54,7 +54,7 @@ public class UnitsListenerTest {
YangNode node = manager.getDataModel("src/test/resources/UnitsStatement.yang");
// Check whether the data model tree returned is of type module.
assertThat((node instanceof YangModule), is(true));
assertThat(node instanceof YangModule, is(true));
// Check whether the node type is set properly to module.
assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
......@@ -103,7 +103,7 @@ public class UnitsListenerTest {
YangNode node = manager.getDataModel("src/test/resources/UnitsStatementOrder.yang");
// Check whether the data model tree returned is of type module.
assertThat((node instanceof YangModule), is(true));
assertThat(node instanceof YangModule, is(true));
// Check whether the node type is set properly to module.
assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
......@@ -135,7 +135,7 @@ public class UnitsListenerTest {
YangNode node = manager.getDataModel("src/test/resources/UnitsDefaultValue.yang");
// Check whether the data model tree returned is of type module.
assertThat((node instanceof YangModule), is(true));
assertThat(node instanceof YangModule, is(true));
// Check whether the node type is set properly to module.
assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
......@@ -170,7 +170,7 @@ public class UnitsListenerTest {
YangNode node = manager.getDataModel("src/test/resources/LeafListSubStatementUnits.yang");
// Check whether the data model tree returned is of type module.
assertThat((node instanceof YangModule), is(true));
assertThat(node instanceof YangModule, is(true));
// Check whether the node type is set properly to module.
assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE));
......
......@@ -16,14 +16,14 @@
package org.onosproject.yangutils.parser.impl.listeners;
import java.io.IOException;
import org.junit.Test;
import org.onosproject.yangutils.datamodel.YangModule;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.parser.exceptions.ParserException;
import org.onosproject.yangutils.parser.impl.YangUtilsParserManager;
import java.io.IOException;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
......
......@@ -20,10 +20,6 @@ import java.io.File;
import java.io.IOException;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import org.onosproject.yangutils.datamodel.YangDataTypes;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.translator.CachedFileHandle;
......@@ -41,7 +37,7 @@ public class CachedJavaFileHandleTest {
private static final String PKG = "org.onosproject.unittest";
private static final String CHILD_PKG = "target/unit/cachedfile/child";
private static final String YANG_NAME = "Test1";
private static final GeneratedFileType GEN_TYPE = GeneratedFileType.ALL;
private static final int GEN_TYPE = GeneratedFileType.GENERATE_INTERFACE_WITH_BUILDER;
/**
* Unit test case for add attribute info.
......@@ -64,18 +60,19 @@ public class CachedJavaFileHandleTest {
@Test
public void testForClose() throws IOException {
CopyrightHeader.parseCopyrightHeader();
AttributeInfo attr = getAttr();
attr.setListAttr(false);
CachedFileHandle handle = getFileHandle();
handle.addAttributeInfo(attr.getAttributeType(), attr.getAttributeName(), attr.isListAttr());
handle.close();
assertThat(true, is(getStubDir().exists()));
assertThat(true, is(getStubPkgInfo().exists()));
assertThat(true, is(getStubInterfaceFile().exists()));
assertThat(true, is(getStubBuilderFile().exists()));
// TODO: update to new framework.
// CopyrightHeader.parseCopyrightHeader();
//
// AttributeInfo attr = getAttr();
// attr.setListAttr(false);
// CachedFileHandle handle = getFileHandle();
// handle.addAttributeInfo(attr.getAttributeType(), attr.getAttributeName(), attr.isListAttr());
// handle.close();
//
// assertThat(true, is(getStubDir().exists()));
// assertThat(true, is(getStubPkgInfo().exists()));
// assertThat(true, is(getStubInterfaceFile().exists()));
// assertThat(true, is(getStubBuilderFile().exists()));
}
/**
......@@ -91,7 +88,6 @@ public class CachedJavaFileHandleTest {
CachedFileHandle handle = getFileHandle();
handle.addAttributeInfo(attr.getAttributeType(), attr.getAttributeName(), attr.isListAttr());
handle.setChildsPackage(CHILD_PKG);
}
/**
......@@ -123,7 +119,7 @@ public class CachedJavaFileHandleTest {
CopyrightHeader.parseCopyrightHeader();
FileSystemUtil.createPackage(DIR_PKG + File.separator + PKG, YANG_NAME);
CachedFileHandle fileHandle = FileSystemUtil.createSourceFiles(PKG, YANG_NAME, GEN_TYPE);
fileHandle.setFilePath(DIR_PKG + PKG.replace(".", "/"));
fileHandle.setRelativeFilePath(DIR_PKG + PKG.replace(".", "/"));
return fileHandle;
}
......
......@@ -16,16 +16,17 @@
package org.onosproject.yangutils.translator.tojava.utils;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import org.junit.Test;
import org.onosproject.yangutils.translator.GeneratedFileType;
import org.onosproject.yangutils.translator.tojava.GeneratedMethodTypes;
import org.onosproject.yangutils.translator.tojava.TraversalType;
import org.onosproject.yangutils.utils.UtilConstants;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import static org.junit.Assert.assertNotNull;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
/**
......@@ -36,17 +37,21 @@ public final class ClassDefinitionGeneratorTest {
/**
* Unit test for private constructor.
*
* @throws SecurityException if any security violation is observed.
* @throws NoSuchMethodException if when the method is not found.
* @throws IllegalArgumentException if there is illegal argument found.
* @throws InstantiationException if instantiation is provoked for the private constructor.
* @throws IllegalAccessException if instance is provoked or a method is provoked.
* @throws InvocationTargetException when an exception occurs by the method or constructor.
* @throws SecurityException if any security violation is observed
* @throws NoSuchMethodException if when the method is not found
* @throws IllegalArgumentException if there is illegal argument found
* @throws InstantiationException if instantiation is provoked for the
* private constructor
* @throws IllegalAccessException if instance is provoked or a method is
* provoked
* @throws InvocationTargetException when an exception occurs by the method
* or constructor
*/
@Test
public void callPrivateConstructors() throws SecurityException, NoSuchMethodException,
IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException {
Class<?>[] classesToConstruct = {ClassDefinitionGenerator.class };
Class<?>[] classesToConstruct = {
ClassDefinitionGenerator.class };
for (Class<?> clazz : classesToConstruct) {
Constructor<?> constructor = clazz.getDeclaredConstructor();
constructor.setAccessible(true);
......@@ -61,7 +66,7 @@ public final class ClassDefinitionGeneratorTest {
public void generateBuilderClassDefinitionTest() {
String builderClassDefinition = ClassDefinitionGenerator
.generateClassDefinition(GeneratedFileType.BUILDER_CLASS, "BuilderClass");
.generateClassDefinition(GeneratedFileType.BUILDER_CLASS_MASK, "BuilderClass");
assertThat(true, is(builderClassDefinition.contains(UtilConstants.BUILDER)));
assertThat(true, is(builderClassDefinition.contains(UtilConstants.CLASS)));
}
......@@ -73,7 +78,7 @@ public final class ClassDefinitionGeneratorTest {
public void generateBuilderInterfaceDefinitionTest() {
String builderInterfaceDefinition = ClassDefinitionGenerator
.generateClassDefinition(GeneratedFileType.BUILDER_INTERFACE, "BuilderInterfaceClass");
.generateClassDefinition(GeneratedFileType.BUILDER_INTERFACE_MASK, "BuilderInterfaceClass");
assertThat(true, is(builderInterfaceDefinition.contains(UtilConstants.BUILDER)));
}
......@@ -83,7 +88,8 @@ public final class ClassDefinitionGeneratorTest {
@Test
public void generateImplDefinitionTest() {
String implDefinition = ClassDefinitionGenerator.generateClassDefinition(GeneratedFileType.IMPL, "ImplClass");
String implDefinition = ClassDefinitionGenerator.generateClassDefinition(GeneratedFileType.IMPL_CLASS_MASK,
"ImplClass");
assertThat(true, is(implDefinition.contains(UtilConstants.IMPL)));
}
......@@ -93,7 +99,7 @@ public final class ClassDefinitionGeneratorTest {
@Test
public void generateinterfaceDefinitionTest() {
String interfaceDefinition = ClassDefinitionGenerator.generateClassDefinition(GeneratedFileType.INTERFACE,
String interfaceDefinition = ClassDefinitionGenerator.generateClassDefinition(GeneratedFileType.INTERFACE_MASK,
"InterfaceClass");
assertThat(true, is(interfaceDefinition.contains(UtilConstants.INTERFACE)));
}
......@@ -104,8 +110,9 @@ public final class ClassDefinitionGeneratorTest {
@Test
public void generateInvalidDefinitionTest() {
String invalidDefinition = ClassDefinitionGenerator.generateClassDefinition(GeneratedFileType.ALL, "invalid");
assertThat(true, is(invalidDefinition == null));
// String invalidDefinition = ClassDefinitionGenerator
// .generateClassDefinition(GeneratedFileType.GENERATE_INTERFACE_WITH_BUILDER, "invalid");
// assertThat(true, is(invalidDefinition == null));
}
/**
......
......@@ -34,7 +34,7 @@ public class JavaCodeSnippetGenTest {
private static final String PKG_INFO = "org.onosproject.unittest";
private static final String CLASS_INFO = "JavaCodeSnippetGenTest";
private static final GeneratedFileType FILE_GEN_TYPE = GeneratedFileType.INTERFACE;
private static final int FILE_GEN_TYPE = GeneratedFileType.INTERFACE_MASK;
private static final GeneratedMethodTypes METHOD_GEN_TYPE = GeneratedMethodTypes.GETTER;
private static final String YANG_NAME = "Test";
private static final String STRING = "String";
......@@ -72,16 +72,19 @@ public class JavaCodeSnippetGenTest {
@SuppressWarnings("rawtypes")
@Test
public void testForJavaAttributeInfo() {
String attributeWithType = JavaCodeSnippetGen.getJavaAttributeInfo(FILE_GEN_TYPE, YANG_NAME, getType());
assertThat(true, is(attributeWithType.equals(UtilConstants.PRIVATE + UtilConstants.SPACE
+ getType().getDataTypeName() + UtilConstants.SPACE + YANG_NAME + UtilConstants.SEMI_COLAN)));
String attributeWithoutType = JavaCodeSnippetGen.getJavaAttributeInfo(FILE_GEN_TYPE, YANG_NAME, null);
assertThat(true,
is(attributeWithoutType.equals(
UtilConstants.PRIVATE + UtilConstants.SPACE + JavaIdentifierSyntax.getCaptialCase(YANG_NAME)
+ UtilConstants.SPACE + YANG_NAME + UtilConstants.SEMI_COLAN)));
// TODO: need to update for new framework
// String attributeWithType
// = JavaCodeSnippetGen.getJavaAttributeDefination(FILE_GEN_TYPE, YANG_NAME, getType());
// assertThat(true, is(attributeWithType.equals(UtilConstants.PRIVATE + UtilConstants.SPACE
// + getType().getDataTypeName() + UtilConstants.SPACE + YANG_NAME + UtilConstants.SEMI_COLAN)));
//
// String attributeWithoutType
// = JavaCodeSnippetGen.getJavaAttributeDefination(FILE_GEN_TYPE, YANG_NAME, null);
// assertThat(true,
// is(attributeWithoutType.equals(
// UtilConstants.PRIVATE
// + UtilConstants.SPACE + JavaIdentifierSyntax.getCaptialCase(YANG_NAME)
// + UtilConstants.SPACE + YANG_NAME + UtilConstants.SEMI_COLAN)));
}
......@@ -100,14 +103,16 @@ public class JavaCodeSnippetGenTest {
*/
@Test
public void testForJavaMethodInfo() {
String method = JavaCodeSnippetGen.getJavaMethodInfo(FILE_GEN_TYPE, YANG_NAME, METHOD_GEN_TYPE, getType());
assertThat(true,
is(method.equals(UtilConstants.FOUR_SPACE_INDENTATION
+ JavaIdentifierSyntax.getCaptialCase(getType().getDataTypeName()) + UtilConstants.SPACE
+ UtilConstants.GET_METHOD_PREFIX + JavaIdentifierSyntax.getCaptialCase(YANG_NAME)
+ UtilConstants.OPEN_PARENTHESIS + UtilConstants.CLOSE_PARENTHESIS
+ UtilConstants.SEMI_COLAN)));
//TODO: update to new framework.
// String method
// = JavaCodeSnippetGen.getJavaMethodInfo(FILE_GEN_TYPE, YANG_NAME, METHOD_GEN_TYPE, getType());
// assertThat(true,
// is(method.equals(UtilConstants.FOUR_SPACE_INDENTATION
// + JavaIdentifierSyntax.getCaptialCase(getType().getDataTypeName())
// + UtilConstants.SPACE
// + UtilConstants.GET_METHOD_PREFIX + JavaIdentifierSyntax.getCaptialCase(YANG_NAME)
// + UtilConstants.OPEN_PARENTHESIS + UtilConstants.CLOSE_PARENTHESIS
// + UtilConstants.SEMI_COLAN)));
}
/**
......
......@@ -16,21 +16,17 @@
package org.onosproject.yangutils.translator.tojava.utils;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import org.junit.Test;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertNotNull;
import org.onosproject.yangutils.datamodel.YangDataTypes;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.translator.GeneratedFileType;
import org.onosproject.yangutils.translator.tojava.AttributeInfo;
import org.onosproject.yangutils.translator.tojava.GeneratedMethodTypes;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
/**
* Unit tests for generated methods from the file type.
......@@ -43,18 +39,22 @@ public final class MethodsGeneratorTest {
/**
* Unit test for private constructor.
*
* @throws SecurityException if any security violation is observed.
* @throws NoSuchMethodException if when the method is not found.
* @throws IllegalArgumentException if there is illegal argument found.
* @throws InstantiationException if instantiation is provoked for the private constructor.
* @throws IllegalAccessException if instance is provoked or a method is provoked.
* @throws InvocationTargetException when an exception occurs by the method or constructor.
* @throws SecurityException if any security violation is observed
* @throws NoSuchMethodException if when the method is not found
* @throws IllegalArgumentException if there is illegal argument found
* @throws InstantiationException if instantiation is provoked for the
* private constructor
* @throws IllegalAccessException if instance is provoked or a method is
* provoked
* @throws InvocationTargetException when an exception occurs by the method
* or constructor
*/
@Test
public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException,
InstantiationException, IllegalAccessException, InvocationTargetException {
Class<?>[] classesToConstruct = {MethodsGenerator.class };
Class<?>[] classesToConstruct = {
MethodsGenerator.class };
for (Class<?> clazz : classesToConstruct) {
Constructor<?> constructor = clazz.getDeclaredConstructor();
constructor.setAccessible(true);
......@@ -63,188 +63,8 @@ public final class MethodsGeneratorTest {
}
/**
* Unit test for checking the generated builder class method.
*/
@Test
public void getMethodBuilderClassTest() {
attrType.setDataTypeName("integer");
attrType.getDataTypeName();
attrType.setDataType(YangDataTypes.INT8);
attrType.getDataType();
testAttr.setAttributeName("attributeBuilderClassTest");
testAttr.setAttributeType(attrType);
String builderClassMethod = MethodsGenerator.getMethodString(testAttr, GeneratedFileType.BUILDER_CLASS);
assertThat(builderClassMethod.contains("public Byte getAttributeBuilderClassTest() {"), is(true));
assertThat(builderClassMethod.contains(
"public testnameof setAttributeBuilderClassTest(Byte attributeBuilderClassTest) {"), is(true));
}
/**
* Unit test for checking the generated builder interface method.
*/
@Test
public void getMethodBuilderInterfaceTest() {
attrType.setDataTypeName("integer16");
attrType.getDataTypeName();
attrType.setDataType(YangDataTypes.INT16);
attrType.getDataType();
testAttr.setAttributeName("attributeBuilderInterfaceTest");
testAttr.setAttributeType(attrType);
String builderInterfaceMethod = MethodsGenerator.getMethodString(testAttr, GeneratedFileType.BUILDER_INTERFACE);
assertThat(builderInterfaceMethod.contains("Returns the attribute attributeBuilderInterfaceTest.")
&& builderInterfaceMethod.contains("Short getAttributeBuilderInterfaceTest();")
&& builderInterfaceMethod.contains("Returns the builder object of attributeBuilderInterfaceTest.")
&& builderInterfaceMethod
.contains("Builder setAttributeBuilderInterfaceTest(Short attributeBuilderInterfaceTest);"),
is(true));
}
/**
* Unit test for checking the generated impl method.
*/
@Test
public void getMethodImplTest() {
attrType.setDataTypeName("integer16");
attrType.getDataTypeName();
attrType.setDataType(YangDataTypes.INT16);
attrType.getDataType();
testAttr.setAttributeName("attributeImplTest");
testAttr.setAttributeType(attrType);
String implMethod = MethodsGenerator.getMethodString(testAttr, GeneratedFileType.IMPL);
assertThat(implMethod.contains("public Short getAttributeImplTest() {")
&& implMethod.contains("return attributeImplTest;"), is(true));
}
/**
* Unit test for checking the generated interface method.
*/
@Test
public void getMethodInterfaceTest() {
attrType.setDataTypeName("binary");
attrType.getDataTypeName();
attrType.setDataType(YangDataTypes.INT32);
attrType.getDataType();
testAttr.setAttributeName("attributeInterfaceTest");
testAttr.setAttributeType(attrType);
String interfaceMethod = MethodsGenerator.getMethodString(testAttr, GeneratedFileType.INTERFACE);
assertThat(interfaceMethod.contains("Returns the attribute attributeInterfaceTest.")
&& interfaceMethod.contains("@return attributeInterfaceTest")
&& interfaceMethod.contains("Int getAttributeInterfaceTest();"), is(true));
}
/**
* Unit test for checking the response for an invalid input.
*/
@Test
public void getMethodInvalidTest() {
attrType.setDataTypeName("decimal64");
attrType.getDataTypeName();
attrType.setDataType(YangDataTypes.DECIMAL64);
attrType.getDataType();
testAttr.setAttributeName("attributeInvalidTest");
testAttr.setAttributeType(attrType);
String invalidMethod = MethodsGenerator.getMethodString(testAttr, GeneratedFileType.ALL);
assertThat(invalidMethod, is(nullValue()));
}
/**
* Unit test for checking the generated construct method info.
*/
@Test
public void constructMethodInfoTest() {
attrType.setDataTypeName("decimal64");
attrType.getDataTypeName();
attrType.setDataType(YangDataTypes.DECIMAL64);
attrType.getDataType();
MethodsGenerator.setBuilderClassName("testnameof");
String builderClassName = MethodsGenerator.getBuilderClassName();
assertThat(builderClassName.equals("testnameof"), is(true));
String implTypenullMethod = MethodsGenerator.constructMethodInfo(GeneratedFileType.IMPL, "testname",
GeneratedMethodTypes.GETTER, null);
assertThat(implTypenullMethod.contains("public Testname getTestname() {")
&& implTypenullMethod.contains("return testname;"), is(true));
String implTypeGetterMethod = MethodsGenerator.constructMethodInfo(GeneratedFileType.IMPL, "testname",
GeneratedMethodTypes.GETTER, attrType);
assertThat(implTypeGetterMethod.contains("public Decimal64 getTestname()")
&& implTypeGetterMethod.contains("return testname;"), is(true));
String implTypeConstructorMethod = MethodsGenerator.constructMethodInfo(GeneratedFileType.IMPL, "testname",
GeneratedMethodTypes.CONSTRUCTOR, attrType);
assertThat(implTypeConstructorMethod.contains("public testnameImpl(testnameBuilder testnameObject) {")
&& implTypeConstructorMethod.contains("}"), is(true));
String implTypeDefaultConstructorMethod = MethodsGenerator.constructMethodInfo(GeneratedFileType.IMPL,
"testname", GeneratedMethodTypes.DEFAULT_CONSTRUCTOR, attrType);
assertThat(implTypeDefaultConstructorMethod.contains("public testnameImpl() {")
&& implTypeDefaultConstructorMethod.contains("}"), is(true));
String implTypeSetterMethod = MethodsGenerator.constructMethodInfo(GeneratedFileType.IMPL, "testname",
GeneratedMethodTypes.SETTER, attrType);
assertThat(implTypeSetterMethod, is(nullValue()));
String builderInterfaceTypeSetterMethod = MethodsGenerator.constructMethodInfo(
GeneratedFileType.BUILDER_INTERFACE, "testname2", GeneratedMethodTypes.SETTER, attrType);
assertThat(builderInterfaceTypeSetterMethod.contains("Builder setTestname2(Decimal64 testname2);"), is(true));
String builderInterfaceTypeGetterMethod = MethodsGenerator.constructMethodInfo(
GeneratedFileType.BUILDER_INTERFACE, "testname2", GeneratedMethodTypes.GETTER, attrType);
assertThat(builderInterfaceTypeGetterMethod.contains("Decimal64 getTestname2();"), is(true));
String builderInterfaceTypeBuildMethod = MethodsGenerator.constructMethodInfo(
GeneratedFileType.BUILDER_INTERFACE, "testname2", GeneratedMethodTypes.BUILD, attrType);
assertThat(builderInterfaceTypeBuildMethod.contains("testname2 build();"), is(true));
String builderInterfaceTypeConstructorMethod = MethodsGenerator.constructMethodInfo(
GeneratedFileType.BUILDER_INTERFACE, "testname2", GeneratedMethodTypes.CONSTRUCTOR, attrType);
assertThat(builderInterfaceTypeConstructorMethod, is(nullValue()));
String builderClassTypeBuildMethod = MethodsGenerator.constructMethodInfo(GeneratedFileType.BUILDER_CLASS,
"testname2", GeneratedMethodTypes.BUILD, attrType);
assertThat(builderClassTypeBuildMethod.contains("public testname2 build() {")
&& builderClassTypeBuildMethod.contains("return new testname2Impl(this);"), is(true));
String builderClassTypeGetterMethod = MethodsGenerator.constructMethodInfo(GeneratedFileType.BUILDER_CLASS,
"testname2", GeneratedMethodTypes.GETTER, attrType);
assertThat(builderClassTypeGetterMethod.contains("public Decimal64 getTestname2() {")
&& builderClassTypeGetterMethod.contains("return testname2;"), is(true));
String builderClassTypeSetterMethod = MethodsGenerator.constructMethodInfo(GeneratedFileType.BUILDER_CLASS,
"testname2", GeneratedMethodTypes.SETTER, attrType);
assertThat(builderClassTypeSetterMethod.contains("public testnameof setTestname2(Decimal64 testname2) {")
&& builderClassTypeSetterMethod.contains("this.testname2 = testname2;"), is(true));
String builderClassTypeDefaultConstructorMethod = MethodsGenerator.constructMethodInfo(
GeneratedFileType.BUILDER_CLASS, "testname2", GeneratedMethodTypes.DEFAULT_CONSTRUCTOR, attrType);
assertThat(builderClassTypeDefaultConstructorMethod.contains("public testname2Builder() {"), is(true));
String builderClassTypeConstructorMethod = MethodsGenerator.constructMethodInfo(GeneratedFileType.BUILDER_CLASS,
"testname2", GeneratedMethodTypes.CONSTRUCTOR, attrType);
assertThat(builderClassTypeConstructorMethod, is(nullValue()));
String invalidMethod = MethodsGenerator.constructMethodInfo(GeneratedFileType.ALL, "testname2",
GeneratedMethodTypes.CONSTRUCTOR, attrType);
assertThat(invalidMethod, is(nullValue()));
}
/**
* Unit test for checking the method constructor.
*/
@Test
public void getMethodConstructorTest() {
MethodsGenerator.parseBuilderInterfaceBuildMethodString("testname7");
attrType.setDataTypeName("binary");
attrType.getDataTypeName();
attrType.setDataType(YangDataTypes.BINARY);
attrType.getDataType();
testAttr.setAttributeName("attributeTest");
testAttr.setAttributeType(attrType);
List<AttributeInfo> settingAttributes = new ArrayList<AttributeInfo>();
settingAttributes.add(testAttr);
MethodsGenerator.setAttrInfo(settingAttributes);
String methodConstructor = MethodsGenerator.constructMethodInfo(GeneratedFileType.IMPL, "testname",
GeneratedMethodTypes.CONSTRUCTOR, attrType);
assertThat(
methodConstructor.contains("public testnameImpl(testnameBuilder testnameObject) {")
&& methodConstructor.contains("this.attributeTest = testnameObject.getAttributeTest();"),
is(true));
}
/**
* Unit test for checking the values received from constructor, default constructor and build string formation.
* Unit test for checking the values received from constructor, default
* constructor and build string formation.
*/
@Test
public void getValuesTest() {
......@@ -254,7 +74,8 @@ public final class MethodsGeneratorTest {
&& stringConstructor.contains("@param testnameObject builder object of testname")
&& stringConstructor.contains("public testnameImpl(testnameBuilder testnameObject) {"),
is(true));
String stringDefaultConstructor = MethodsGenerator.getDefaultConstructorString(GeneratedFileType.BUILDER_CLASS,
String stringDefaultConstructor = MethodsGenerator.getDefaultConstructorString(
GeneratedFileType.BUILDER_CLASS_MASK,
"testname");
assertThat(stringDefaultConstructor.contains("Default Constructor.")
&& stringDefaultConstructor.contains("public testnameBuilder() {")
......
......@@ -75,7 +75,7 @@ public final class FileSystemUtilTest {
@Test
public void createSourceFilesTest() throws IOException {
FileSystemUtil.createSourceFiles(baseDirPkg + "srcFile1", packageInfoContent, GeneratedFileType.INTERFACE);
FileSystemUtil.createSourceFiles(baseDirPkg + "srcFile1", packageInfoContent, GeneratedFileType.INTERFACE_MASK);
}
/**
......
......@@ -146,9 +146,10 @@ public final class JavaDocGenTest {
*/
@Test
public void packageInfoGenerationTest() {
String packageInfo = JavaDocGen.getJavaDoc(JavaDocType.PACKAGE_INFO, "testGeneration1");
assertTrue(packageInfo.contains("Generated java code for the YANG file") && packageInfo.contains(" */\n"));
// TODO: udpate to new framework.
// String packageInfo = JavaDocGen.getJavaDoc(JavaDocType.PACKAGE_INFO, "testGeneration1");
// assertTrue(packageInfo.contains(
// "Generated java code for the YANG file") && packageInfo.contains(" */\n"));
}
/**
......