Vidyashree Rama
Committed by Gerrit Code Review

Whitebox issue fix

Change-Id: I856266e26d2686affb9271c460927ba3e0e07db2
......@@ -40,6 +40,6 @@ public enum ResolvableStatus {
/**
* Identifies that resolvable entity is resolved.
*/
RESOLVED;
RESOLVED
}
......
/*
* Copyright 2016 Open Networking Laboratory
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -28,28 +28,28 @@ public interface YangLeavesHolder {
/**
* Returns the list of leaves from data holder like container / list.
*
* @return the list of leaves.
* @return the list of leaves
*/
public List<YangLeaf> getListOfLeaf();
List<YangLeaf> getListOfLeaf();
/**
* Add a leaf in data holder like container / list.
* Adds leaf in data holder like container / list.
*
* @param leaf the leaf to be added.
* @param leaf the leaf to be added
*/
void addLeaf(YangLeaf leaf);
/**
* Returns the list of leaf-list from data holder like container / list.
*
* @return the list of leaf-list.
* @return the list of leaf-list
*/
List<YangLeafList> getListOfLeafList();
/**
* Add a leaf-list in data holder like container / list.
* Adds leaf-list in data holder like container / list.
*
* @param leafList the leaf-list to be added.
* @param leafList the leaf-list to be added
*/
void addLeafList(YangLeafList leafList);
}
......
......@@ -20,7 +20,7 @@ package org.onosproject.yangutils.datamodel.utils;
*/
public enum GeneratedLanguage {
/**
* Java.
* Target language is java.
*/
JAVA_GENERATION;
JAVA_GENERATION
}
......
......@@ -43,12 +43,11 @@ public class YangUtilsParserManager implements YangUtilsParser {
* Create a char stream that reads from YANG file. Throws an exception
* in case input YANG file is either null or non existent.
*/
ANTLRInputStream input = null;
ANTLRInputStream input;
try {
input = new ANTLRFileStream(yangFile);
} catch (IOException e) {
e.printStackTrace();
throw e;
throw new ParserException("YANG file error : YANG file does not exist.");
}
// Create a lexer that feeds off of input char stream.
......
......@@ -22,10 +22,10 @@ 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.utils.YangConstructType;
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_CONTENT;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.MISSING_HOLDER;
import static org.onosproject.yangutils.parser.impl.parserutils.ListenerUtil.removeQuotesAndHandleConcat;
......@@ -44,7 +44,7 @@ import static org.onosproject.yangutils.utils.YangConstructType.STATUS_DATA;
* deprecated-keyword
*
* ANTLR grammar rule
* statusStatement : STATUS_KEYWORD (CURRENT_KEYWORD | OBSOLETE_KEYWORD | DEPRECATED_KEYWORD) STMTEND;
* statusStatement : STATUS_KEYWORD status STMTEND;
*/
/**
......@@ -99,14 +99,27 @@ public final class StatusListener {
YangStatusType status;
String value = removeQuotesAndHandleConcat(ctx.status().getText());
if (value.equals(CURRENT_KEYWORD)) {
status = YangStatusType.CURRENT;
} else if (value.equals(DEPRECATED_KEYWORD)) {
status = YangStatusType.DEPRECATED;
} else if (value.equals(OBSOLETE_KEYWORD)) {
status = YangStatusType.OBSOLETE;
} else {
throw new ParserException(constructListenerErrorMessage(INVALID_CONTENT, STATUS_DATA, value, ENTRY));
switch (value) {
case CURRENT_KEYWORD: {
status = YangStatusType.CURRENT;
break;
}
case DEPRECATED_KEYWORD: {
status = YangStatusType.DEPRECATED;
break;
}
case OBSOLETE_KEYWORD: {
status = YangStatusType.OBSOLETE;
break;
}
default: {
ParserException parserException = new ParserException("YANG file error : " +
YangConstructType.getYangConstructType(STATUS_DATA) + " " + ctx.status().getText() +
" is not valid.");
parserException.setLine(ctx.getStart().getLine());
parserException.setCharPosition(ctx.getStart().getCharPositionInLine());
throw parserException;
}
}
return status;
......
......@@ -26,12 +26,12 @@ public interface HasJavaFileInfo {
*
* @return generated java file information
*/
public JavaFileInfo getJavaFileInfo();
JavaFileInfo getJavaFileInfo();
/**
* Sets the java file info object.
*
* @param javaInfo java file info object
*/
public void setJavaFileInfo(JavaFileInfo javaInfo);
void setJavaFileInfo(JavaFileInfo javaInfo);
}
......
......@@ -25,7 +25,7 @@ public interface HasJavaImportData {
*
* @return data of java imports to be included in generated file
*/
public JavaImportData getJavaImportData();
JavaImportData getJavaImportData();
/**
* Sets the data of java imports to be included in generated file.
......@@ -33,5 +33,5 @@ public interface HasJavaImportData {
* @param javaImportData data of java imports to be included in generated
* file
*/
public void setJavaImportData(JavaImportData javaImportData);
void setJavaImportData(JavaImportData javaImportData);
}
......
......@@ -29,7 +29,7 @@ import static org.onosproject.yangutils.translator.tojava.TraversalType.ROOT;
import static org.onosproject.yangutils.translator.tojava.TraversalType.SIBILING;
/**
* Representation of Java code generator based on application schema.
* Representation of java code generator based on application schema.
*/
public final class JavaCodeGeneratorUtil {
......@@ -75,7 +75,7 @@ public final class JavaCodeGeneratorUtil {
YangNode curNode = rootNode;
TraversalType curTraversal = ROOT;
while (!(curNode == null)) {
while (curNode != null) {
if (curTraversal != PARENT) {
setCurNode(curNode);
generateCodeEntry(curNode, yangPlugin);
......@@ -166,9 +166,8 @@ public final class JavaCodeGeneratorUtil {
* Free the current node.
*
* @param node YANG node
* @throws DataModelException when fails to do datamodel operations
*/
private static void free(YangNode node) throws DataModelException {
private static void free(YangNode node) {
YangNode parent = node.getParent();
parent.setChild(null);
......@@ -202,7 +201,7 @@ public final class JavaCodeGeneratorUtil {
setCurNode(curNode.getChild());
TraversalType curTraversal = ROOT;
while (!(curNode == null)) {
while (curNode != null) {
if (curTraversal != PARENT) {
close(curNode);
......@@ -220,7 +219,6 @@ public final class JavaCodeGeneratorUtil {
}
freeRestResources();
curNode = null;
}
/**
......
......@@ -19,6 +19,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.SortedSet;
import java.util.TreeSet;
import static java.util.Collections.sort;
import org.onosproject.yangutils.datamodel.YangNode;
import org.onosproject.yangutils.translator.exception.TranslatorException;
......@@ -62,7 +63,7 @@ public class JavaImportData {
/**
* Returns if the list needs to be imported.
*
* @return true if any of the attribute needs to be maintained as a list.
* @return true if any of the attribute needs to be maintained as a list
*/
public boolean getIfListImported() {
return isListToImport;
......@@ -71,7 +72,7 @@ public class JavaImportData {
/**
* Sets the status of importing list.
*
* @param isList status to mention list is bing imported.
* @param isList status to mention list is bing imported
*/
public void setIfListImported(boolean isList) {
isListToImport = isList;
......@@ -138,10 +139,9 @@ public class JavaImportData {
List<String> imports = new ArrayList<>();
for (JavaQualifiedTypeInfo importInfo : getImportSet()) {
importString = IMPORT;
if (importInfo.getPkgInfo() != EMPTY_STRING && importInfo.getClassInfo() != null
&& importInfo.getPkgInfo() != JAVA_LANG) {
importString = importString + importInfo.getPkgInfo() + PERIOD + importInfo.getClassInfo() + SEMI_COLAN
if (!importInfo.getPkgInfo().equals(EMPTY_STRING) && importInfo.getClassInfo() != null
&& !importInfo.getPkgInfo().equals(JAVA_LANG)) {
importString = IMPORT + importInfo.getPkgInfo() + PERIOD + importInfo.getClassInfo() + SEMI_COLAN
+ NEW_LINE;
imports.add(importString);
......@@ -152,7 +152,7 @@ public class JavaImportData {
imports.add(getImportForList());
}
java.util.Collections.sort(imports);
sort(imports);
return imports;
}
......
......@@ -1108,7 +1108,6 @@ public class TempJavaCodeFragmentFiles {
addToStringMethod(newAttrInfo);
}
}
return;
}
/**
......
......@@ -136,9 +136,11 @@ public class YangJavaModule extends YangModule implements JavaCodeGeneratorInfo,
YangJavaModelUtils.generateCodeOfRootNode(this, yangPlugin, modulePkg);
}
/**
* Creates a java file using the YANG module info.
*/
@Override
public void generateCodeExit() throws IOException {
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
return;
}
}
......
......@@ -53,7 +53,6 @@ public final class FileSystemUtil {
* @return existence status of package
*/
public static boolean doesPackageExist(String pkg) {
File pkgDir = new File(getPackageDirPathFromJavaJPackage(pkg));
File pkgWithFile = new File(pkgDir + SLASH + "package-info.java");
if (pkgDir.exists() && pkgWithFile.isFile()) {
......@@ -70,7 +69,6 @@ public final class FileSystemUtil {
* @throws IOException any IO exception
*/
public static void createPackage(String pkg, String pkgInfo) throws IOException {
if (!doesPackageExist(pkg)) {
try {
File pack = createDirectories(pkg);
......@@ -92,9 +90,7 @@ public final class FileSystemUtil {
* @throws IOException any IO errors
*/
public static void appendFileContents(File toAppend, File srcFile) throws IOException {
updateFileHandle(srcFile, NEW_LINE + readAppendFile(toAppend.toString(), FOUR_SPACE_INDENTATION), false);
return;
}
/**
......@@ -106,7 +102,6 @@ public final class FileSystemUtil {
* @throws IOException when fails to convert to string
*/
public static String readAppendFile(String toAppend, String spaces) throws IOException {
FileReader fileReader = new FileReader(toAppend);
BufferedReader bufferReader = new BufferedReader(fileReader);
try {
......@@ -114,8 +109,8 @@ public final class FileSystemUtil {
String line = bufferReader.readLine();
while (line != null) {
if (line.equals(SPACE) | line.equals(EMPTY_STRING) | line.equals(EIGHT_SPACE_INDENTATION)
| line.equals(MULTIPLE_NEW_LINE)) {
if (line.equals(SPACE) || line.equals(EMPTY_STRING) || line.equals(EIGHT_SPACE_INDENTATION)
|| line.equals(MULTIPLE_NEW_LINE)) {
stringBuilder.append(NEW_LINE);
} else if (line.equals(FOUR_SPACE_INDENTATION)) {
stringBuilder.append(EMPTY_STRING);
......@@ -142,7 +137,6 @@ public final class FileSystemUtil {
* does not exist but cannot be created, or cannot be opened for any other reason
*/
public static void updateFileHandle(File inputFile, String contentTobeAdded, boolean isClose) throws IOException {
FileWriter fileWriter = new FileWriter(inputFile, true);
PrintWriter outputPrintWriter = new PrintWriter(fileWriter, true);
if (!isClose) {
......
......@@ -17,7 +17,6 @@
package org.onosproject.yangutils.utils.io.impl;
import org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax;
import org.onosproject.yangutils.utils.UtilConstants;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_CLASS_JAVA_DOC;
......@@ -62,7 +61,7 @@ public final class JavaDocGen {
/**
* JavaDocs types.
*/
public static enum JavaDocType {
public enum JavaDocType {
/**
* For class.
......@@ -141,7 +140,7 @@ public final class JavaDocGen {
public static String getJavaDoc(JavaDocType type, String name, boolean isList) {
name = JavaIdentifierSyntax.getSmallCase(JavaIdentifierSyntax.getCamelCase(name, null));
String javaDoc = UtilConstants.EMPTY_STRING;
String javaDoc;
if (type.equals(JavaDocType.IMPL_CLASS)) {
javaDoc = generateForImplClass(name);
} else if (type.equals(JavaDocType.BUILDER_CLASS)) {
......
......@@ -60,7 +60,7 @@ public class YangUtilsParserManagerTest {
* This test case checks whether the io exception is generated
* when the input YANG file is non existent.
*/
@Test(expected = IOException.class)
@Test(expected = ParserException.class)
public void getDataModelNonExistentFileTest() throws IOException, ParserException {
YangUtilsParserManager manager = new YangUtilsParserManager();
......
......@@ -140,7 +140,7 @@ public class StatusListenerTest {
@Test
public void processStatusInvalidValue() throws IOException, ParserException {
thrown.expect(ParserException.class);
thrown.expectMessage("Invalid content in status \"invalid\" before processing.");
thrown.expectMessage("YANG file error : status invalid is not valid.");
YangNode node = manager.getDataModel("src/test/resources/StatusInvalidValue.yang");
}
......