mirror of
https://github.com/opennetworkinglab/onos.git
synced 2025-10-21 20:31:00 +02:00
Defect Fixes and optimization for YANG translator.
Change-Id: I974a968f3c41e1abea9f2567aceb3d523645d0ae
This commit is contained in:
parent
cc9ac30af6
commit
2f11f65be6
@ -36,12 +36,12 @@ import org.sonatype.plexus.build.incremental.BuildContext;
|
|||||||
import static org.apache.maven.plugins.annotations.LifecyclePhase.GENERATE_SOURCES;
|
import static org.apache.maven.plugins.annotations.LifecyclePhase.GENERATE_SOURCES;
|
||||||
import static org.apache.maven.plugins.annotations.ResolutionScope.COMPILE;
|
import static org.apache.maven.plugins.annotations.ResolutionScope.COMPILE;
|
||||||
import static org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorUtil.generateJavaCode;
|
import static org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorUtil.generateJavaCode;
|
||||||
|
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
|
||||||
import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT_BASE_PKG;
|
import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT_BASE_PKG;
|
||||||
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
|
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
|
||||||
import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
|
import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
|
||||||
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.addToSource;
|
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.addToSource;
|
||||||
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.clean;
|
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.clean;
|
||||||
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.convertPkgToPath;
|
|
||||||
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.copyYangFilesToTarget;
|
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.copyYangFilesToTarget;
|
||||||
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getDirectory;
|
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getDirectory;
|
||||||
|
|
||||||
@ -89,7 +89,7 @@ public class YangUtilManager extends AbstractMojo {
|
|||||||
@Component
|
@Component
|
||||||
private BuildContext context;
|
private BuildContext context;
|
||||||
|
|
||||||
private static final String DEFAULT_PKG = SLASH + convertPkgToPath(DEFAULT_BASE_PKG);
|
private static final String DEFAULT_PKG = SLASH + getPackageDirPathFromJavaJPackage(DEFAULT_BASE_PKG);
|
||||||
|
|
||||||
private YangUtilsParser yangUtilsParser = new YangUtilsParserManager();
|
private YangUtilsParser yangUtilsParser = new YangUtilsParserManager();
|
||||||
private String searchDir;
|
private String searchDir;
|
||||||
|
@ -1,47 +0,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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.onosproject.yangutils.translator.tojava;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Type of method generated.
|
|
||||||
*/
|
|
||||||
public enum GeneratedMethodTypes {
|
|
||||||
/**
|
|
||||||
* getter method.
|
|
||||||
*/
|
|
||||||
GETTER,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* setter method.
|
|
||||||
*/
|
|
||||||
SETTER,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor.
|
|
||||||
*/
|
|
||||||
CONSTRUCTOR,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Build.
|
|
||||||
*/
|
|
||||||
BUILD,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Default Constructor.
|
|
||||||
*/
|
|
||||||
DEFAULT_CONSTRUCTOR
|
|
||||||
}
|
|
@ -283,6 +283,11 @@ public class TempJavaCodeFragmentFiles {
|
|||||||
*/
|
*/
|
||||||
private YangNode curYangNode;
|
private YangNode curYangNode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is attribute added.
|
||||||
|
*/
|
||||||
|
private boolean isAttributePresent = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct an object of temporary java code fragment.
|
* Construct an object of temporary java code fragment.
|
||||||
*
|
*
|
||||||
@ -684,6 +689,9 @@ public class TempJavaCodeFragmentFiles {
|
|||||||
*/
|
*/
|
||||||
public void setNewAttrInfo(JavaAttributeInfo newAttrInfo) {
|
public void setNewAttrInfo(JavaAttributeInfo newAttrInfo) {
|
||||||
|
|
||||||
|
if (newAttrInfo != null) {
|
||||||
|
isAttributePresent = true;
|
||||||
|
}
|
||||||
this.newAttrInfo = newAttrInfo;
|
this.newAttrInfo = newAttrInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -903,9 +911,6 @@ public class TempJavaCodeFragmentFiles {
|
|||||||
File file = new File(path + fileName + TEMP_FILE_EXTENSION);
|
File file = new File(path + fileName + TEMP_FILE_EXTENSION);
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
file.createNewFile();
|
file.createNewFile();
|
||||||
} else {
|
|
||||||
file.delete();
|
|
||||||
file.createNewFile();
|
|
||||||
}
|
}
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
@ -965,7 +970,7 @@ public class TempJavaCodeFragmentFiles {
|
|||||||
* TODO: check if this utility needs to be called or move to the caller
|
* TODO: check if this utility needs to be called or move to the caller
|
||||||
*/
|
*/
|
||||||
String attributeName = JavaIdentifierSyntax
|
String attributeName = JavaIdentifierSyntax
|
||||||
.getCamelCase(JavaIdentifierSyntax.getLowerCase(attr.getAttributeName()));
|
.getCamelCase(JavaIdentifierSyntax.getSmallCase(attr.getAttributeName()));
|
||||||
if (attr.isQualifiedName()) {
|
if (attr.isQualifiedName()) {
|
||||||
return getJavaAttributeDefination(attr.getImportInfo().getPkgInfo(), attr.getImportInfo().getClassInfo(),
|
return getJavaAttributeDefination(attr.getImportInfo().getPkgInfo(), attr.getImportInfo().getClassInfo(),
|
||||||
attributeName, attr.isListAttr());
|
attributeName, attr.isListAttr());
|
||||||
@ -1113,40 +1118,42 @@ public class TempJavaCodeFragmentFiles {
|
|||||||
throws IOException {
|
throws IOException {
|
||||||
|
|
||||||
setNewAttrInfo(newAttrInfo);
|
setNewAttrInfo(newAttrInfo);
|
||||||
if ((generatedTempFiles & ATTRIBUTES_MASK) != 0) {
|
if (isAttributePresent) {
|
||||||
addAttribute(newAttrInfo);
|
if ((generatedTempFiles & ATTRIBUTES_MASK) != 0) {
|
||||||
}
|
addAttribute(newAttrInfo);
|
||||||
|
}
|
||||||
|
|
||||||
if ((generatedTempFiles & GETTER_FOR_INTERFACE_MASK) != 0) {
|
if ((generatedTempFiles & GETTER_FOR_INTERFACE_MASK) != 0) {
|
||||||
addGetterForInterface(newAttrInfo);
|
addGetterForInterface(newAttrInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((generatedTempFiles & SETTER_FOR_INTERFACE_MASK) != 0) {
|
if ((generatedTempFiles & SETTER_FOR_INTERFACE_MASK) != 0) {
|
||||||
addSetterForInterface(newAttrInfo);
|
addSetterForInterface(newAttrInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((generatedTempFiles & GETTER_FOR_CLASS_MASK) != 0) {
|
if ((generatedTempFiles & GETTER_FOR_CLASS_MASK) != 0) {
|
||||||
addGetterImpl(newAttrInfo, generatedJavaFiles);
|
addGetterImpl(newAttrInfo, generatedJavaFiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((generatedTempFiles & SETTER_FOR_CLASS_MASK) != 0) {
|
if ((generatedTempFiles & SETTER_FOR_CLASS_MASK) != 0) {
|
||||||
addSetterImpl(newAttrInfo);
|
addSetterImpl(newAttrInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((generatedTempFiles & CONSTRUCTOR_IMPL_MASK) != 0) {
|
if ((generatedTempFiles & CONSTRUCTOR_IMPL_MASK) != 0) {
|
||||||
addConstructor(newAttrInfo);
|
addConstructor(newAttrInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((generatedTempFiles & HASH_CODE_IMPL_MASK) != 0) {
|
if ((generatedTempFiles & HASH_CODE_IMPL_MASK) != 0) {
|
||||||
addHashCodeMethod(newAttrInfo);
|
addHashCodeMethod(newAttrInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((generatedTempFiles & EQUALS_IMPL_MASK) != 0) {
|
if ((generatedTempFiles & EQUALS_IMPL_MASK) != 0) {
|
||||||
addEqualsMethod(newAttrInfo);
|
addEqualsMethod(newAttrInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((generatedTempFiles & TO_STRING_IMPL_MASK) != 0) {
|
if ((generatedTempFiles & TO_STRING_IMPL_MASK) != 0) {
|
||||||
addToStringMethod(newAttrInfo);
|
addToStringMethod(newAttrInfo);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1193,7 +1200,7 @@ public class TempJavaCodeFragmentFiles {
|
|||||||
|
|
||||||
setCurYangNode(curNode);
|
setCurYangNode(curNode);
|
||||||
List<String> imports = new ArrayList<>();
|
List<String> imports = new ArrayList<>();
|
||||||
if (curNode instanceof HasJavaImportData) {
|
if (curNode instanceof HasJavaImportData && isAttributePresent) {
|
||||||
imports = ((HasJavaImportData) curNode).getJavaImportData().getImports(getNewAttrInfo());
|
imports = ((HasJavaImportData) curNode).getJavaImportData().getImports(getNewAttrInfo());
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@ -1206,13 +1213,14 @@ public class TempJavaCodeFragmentFiles {
|
|||||||
* Create interface file.
|
* Create interface file.
|
||||||
*/
|
*/
|
||||||
setInterfaceJavaFileHandle(getJavaFileHandle(getJavaClassName(INTERFACE_FILE_NAME_SUFFIX)));
|
setInterfaceJavaFileHandle(getJavaFileHandle(getJavaClassName(INTERFACE_FILE_NAME_SUFFIX)));
|
||||||
setInterfaceJavaFileHandle(generateInterfaceFile(getInterfaceJavaFileHandle(), imports, curNode));
|
setInterfaceJavaFileHandle(
|
||||||
|
generateInterfaceFile(getInterfaceJavaFileHandle(), imports, curNode, isAttributePresent));
|
||||||
/**
|
/**
|
||||||
* Create builder interface file.
|
* Create builder interface file.
|
||||||
*/
|
*/
|
||||||
setBuilderInterfaceJavaFileHandle(getJavaFileHandle(getJavaClassName(BUILDER_INTERFACE_FILE_NAME_SUFFIX)));
|
setBuilderInterfaceJavaFileHandle(getJavaFileHandle(getJavaClassName(BUILDER_INTERFACE_FILE_NAME_SUFFIX)));
|
||||||
setBuilderInterfaceJavaFileHandle(
|
setBuilderInterfaceJavaFileHandle(
|
||||||
generateBuilderInterfaceFile(getBuilderInterfaceJavaFileHandle(), curNode));
|
generateBuilderInterfaceFile(getBuilderInterfaceJavaFileHandle(), curNode, isAttributePresent));
|
||||||
/**
|
/**
|
||||||
* Append builder interface file to interface file and close it.
|
* Append builder interface file to interface file and close it.
|
||||||
*/
|
*/
|
||||||
@ -1221,7 +1229,7 @@ public class TempJavaCodeFragmentFiles {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (curNode instanceof HasJavaImportData) {
|
if (curNode instanceof HasJavaImportData && isAttributePresent) {
|
||||||
imports.add(((HasJavaImportData) curNode).getJavaImportData().getImportForHashAndEquals());
|
imports.add(((HasJavaImportData) curNode).getJavaImportData().getImportForHashAndEquals());
|
||||||
imports.add(((HasJavaImportData) curNode).getJavaImportData().getImportForToString());
|
imports.add(((HasJavaImportData) curNode).getJavaImportData().getImportForToString());
|
||||||
java.util.Collections.sort(imports);
|
java.util.Collections.sort(imports);
|
||||||
@ -1234,12 +1242,14 @@ public class TempJavaCodeFragmentFiles {
|
|||||||
* Create builder class file.
|
* Create builder class file.
|
||||||
*/
|
*/
|
||||||
setBuilderClassJavaFileHandle(getJavaFileHandle(getJavaClassName(BUILDER_CLASS_FILE_NAME_SUFFIX)));
|
setBuilderClassJavaFileHandle(getJavaFileHandle(getJavaClassName(BUILDER_CLASS_FILE_NAME_SUFFIX)));
|
||||||
setBuilderClassJavaFileHandle(generateBuilderClassFile(getBuilderClassJavaFileHandle(), imports, curNode));
|
setBuilderClassJavaFileHandle(
|
||||||
|
generateBuilderClassFile(getBuilderClassJavaFileHandle(), imports, curNode, isAttributePresent));
|
||||||
/**
|
/**
|
||||||
* Create impl class file.
|
* Create impl class file.
|
||||||
*/
|
*/
|
||||||
setImplClassJavaFileHandle(getJavaFileHandle(getJavaClassName(IMPL_CLASS_FILE_NAME_SUFFIX)));
|
setImplClassJavaFileHandle(getJavaFileHandle(getJavaClassName(IMPL_CLASS_FILE_NAME_SUFFIX)));
|
||||||
setImplClassJavaFileHandle(generateImplClassFile(getImplClassJavaFileHandle(), curNode));
|
setImplClassJavaFileHandle(
|
||||||
|
generateImplClassFile(getImplClassJavaFileHandle(), curNode, isAttributePresent));
|
||||||
/**
|
/**
|
||||||
* Append impl class to builder class and close it.
|
* Append impl class to builder class and close it.
|
||||||
*/
|
*/
|
||||||
@ -1269,46 +1279,38 @@ public class TempJavaCodeFragmentFiles {
|
|||||||
*/
|
*/
|
||||||
private void close() throws IOException {
|
private void close() throws IOException {
|
||||||
|
|
||||||
closeFile(getJavaClassName(INTERFACE_FILE_NAME_SUFFIX));
|
if ((generatedJavaFiles & INTERFACE_MASK) != 0) {
|
||||||
|
closeFile(getInterfaceJavaFileHandle(), false);
|
||||||
|
}
|
||||||
|
|
||||||
closeFile(getJavaClassName(BUILDER_INTERFACE_FILE_NAME_SUFFIX));
|
if ((generatedJavaFiles & BUILDER_CLASS_MASK) != 0) {
|
||||||
getJavaFileHandle(getJavaClassName(BUILDER_INTERFACE_FILE_NAME_SUFFIX)).delete();
|
closeFile(getBuilderClassJavaFileHandle(), false);
|
||||||
|
}
|
||||||
|
|
||||||
closeFile(getJavaClassName(BUILDER_CLASS_FILE_NAME_SUFFIX));
|
if ((generatedJavaFiles & BUILDER_INTERFACE_MASK) != 0) {
|
||||||
|
closeFile(getBuilderInterfaceJavaFileHandle(), true);
|
||||||
|
}
|
||||||
|
|
||||||
closeFile(getJavaClassName(IMPL_CLASS_FILE_NAME_SUFFIX));
|
if ((generatedJavaFiles & IMPL_CLASS_MASK) != 0) {
|
||||||
getJavaFileHandle(getJavaClassName(IMPL_CLASS_FILE_NAME_SUFFIX)).delete();
|
closeFile(getImplClassJavaFileHandle(), true);
|
||||||
|
}
|
||||||
|
|
||||||
closeFile(getJavaClassName(TYPEDEF_CLASS_FILE_NAME_SUFFIX));
|
if ((generatedJavaFiles & GENERATE_TYPEDEF_CLASS) != 0) {
|
||||||
|
closeFile(getTypedefClassJavaFileHandle(), false);
|
||||||
|
}
|
||||||
|
|
||||||
closeFile(GETTER_METHOD_FILE_NAME);
|
/**
|
||||||
getTemporaryFileHandle(GETTER_METHOD_FILE_NAME).delete();
|
* Close all temporary file handles and delete the files.
|
||||||
|
*/
|
||||||
closeFile(GETTER_METHOD_IMPL_FILE_NAME);
|
closeFile(getGetterInterfaceTempFileHandle(), true);
|
||||||
getTemporaryFileHandle(GETTER_METHOD_IMPL_FILE_NAME).delete();
|
closeFile(getGetterImplTempFileHandle(), true);
|
||||||
|
closeFile(getSetterInterfaceTempFileHandle(), true);
|
||||||
closeFile(SETTER_METHOD_FILE_NAME);
|
closeFile(getSetterImplTempFileHandle(), true);
|
||||||
getTemporaryFileHandle(SETTER_METHOD_FILE_NAME).delete();
|
closeFile(getConstructorImplTempFileHandle(), true);
|
||||||
|
closeFile(getAttributesTempFileHandle(), true);
|
||||||
closeFile(SETTER_METHOD_IMPL_FILE_NAME);
|
closeFile(getHashCodeImplTempFileHandle(), true);
|
||||||
getTemporaryFileHandle(SETTER_METHOD_IMPL_FILE_NAME).delete();
|
closeFile(getToStringImplTempFileHandle(), true);
|
||||||
|
closeFile(getEqualsImplTempFileHandle(), true);
|
||||||
closeFile(CONSTRUCTOR_FILE_NAME);
|
|
||||||
getTemporaryFileHandle(CONSTRUCTOR_FILE_NAME).delete();
|
|
||||||
|
|
||||||
closeFile(ATTRIBUTE_FILE_NAME);
|
|
||||||
getTemporaryFileHandle(ATTRIBUTE_FILE_NAME).delete();
|
|
||||||
|
|
||||||
closeFile(HASH_CODE_METHOD_FILE_NAME);
|
|
||||||
getTemporaryFileHandle(HASH_CODE_METHOD_FILE_NAME).delete();
|
|
||||||
|
|
||||||
closeFile(TO_STRING_METHOD_FILE_NAME);
|
|
||||||
getTemporaryFileHandle(TO_STRING_METHOD_FILE_NAME).delete();
|
|
||||||
|
|
||||||
closeFile(EQUALS_METHOD_FILE_NAME);
|
|
||||||
getTemporaryFileHandle(EQUALS_METHOD_FILE_NAME).delete();
|
|
||||||
|
|
||||||
clean(getTempDirPath());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1317,8 +1319,14 @@ public class TempJavaCodeFragmentFiles {
|
|||||||
* @param fileName temporary file's name
|
* @param fileName temporary file's name
|
||||||
* @throws IOException when failed to close the file handle
|
* @throws IOException when failed to close the file handle
|
||||||
*/
|
*/
|
||||||
private void closeFile(String fileName) throws IOException {
|
private void closeFile(File file, boolean toBeDeleted) throws IOException {
|
||||||
|
|
||||||
FileSystemUtil.updateFileHandle(new File(fileName), null, true);
|
if (file.exists()) {
|
||||||
|
FileSystemUtil.updateFileHandle(file, null, true);
|
||||||
|
if (toBeDeleted) {
|
||||||
|
file.delete();
|
||||||
|
}
|
||||||
|
clean(getTempDirPath());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -178,7 +178,6 @@ public class YangJavaContainer extends YangContainer
|
|||||||
@Override
|
@Override
|
||||||
public void generateCodeExit() throws IOException {
|
public void generateCodeExit() throws IOException {
|
||||||
|
|
||||||
getTempJavaCodeFragmentFiles().setCurYangNode(this);
|
|
||||||
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
|
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,7 +180,6 @@ public class YangJavaInput extends YangInput
|
|||||||
@Override
|
@Override
|
||||||
public void generateCodeExit() throws IOException {
|
public void generateCodeExit() throws IOException {
|
||||||
|
|
||||||
getTempJavaCodeFragmentFiles().setCurYangNode(this);
|
|
||||||
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
|
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -181,7 +181,6 @@ public class YangJavaList extends YangList
|
|||||||
@Override
|
@Override
|
||||||
public void generateCodeExit() throws IOException {
|
public void generateCodeExit() throws IOException {
|
||||||
|
|
||||||
getTempJavaCodeFragmentFiles().setCurYangNode(this);
|
|
||||||
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
|
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,8 +37,8 @@ import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getAbsolutePac
|
|||||||
* Module information extended to support java code generation.
|
* Module information extended to support java code generation.
|
||||||
*/
|
*/
|
||||||
public class YangJavaModule extends YangModule
|
public class YangJavaModule extends YangModule
|
||||||
implements JavaCodeGenerator, HasJavaFileInfo,
|
implements JavaCodeGenerator, HasJavaFileInfo,
|
||||||
HasJavaImportData, HasTempJavaCodeFragmentFiles {
|
HasJavaImportData, HasTempJavaCodeFragmentFiles {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains the information of the java file being generated.
|
* Contains the information of the java file being generated.
|
||||||
@ -76,7 +76,7 @@ HasJavaImportData, HasTempJavaCodeFragmentFiles {
|
|||||||
public JavaFileInfo getJavaFileInfo() {
|
public JavaFileInfo getJavaFileInfo() {
|
||||||
|
|
||||||
if (javaFileInfo == null) {
|
if (javaFileInfo == null) {
|
||||||
throw new RuntimeException("Missing java info in java datamodel node.");
|
throw new RuntimeException("Missing java info in java datamodel node");
|
||||||
}
|
}
|
||||||
return javaFileInfo;
|
return javaFileInfo;
|
||||||
}
|
}
|
||||||
@ -171,7 +171,6 @@ HasJavaImportData, HasTempJavaCodeFragmentFiles {
|
|||||||
@Override
|
@Override
|
||||||
public void generateCodeExit() throws IOException {
|
public void generateCodeExit() throws IOException {
|
||||||
|
|
||||||
getTempJavaCodeFragmentFiles().setCurYangNode(this);
|
|
||||||
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
|
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -180,7 +180,6 @@ public class YangJavaOutput extends YangOutput
|
|||||||
@Override
|
@Override
|
||||||
public void generateCodeExit() throws IOException {
|
public void generateCodeExit() throws IOException {
|
||||||
|
|
||||||
getTempJavaCodeFragmentFiles().setCurYangNode(this);
|
|
||||||
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
|
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_INTERFACE_WITH_BUILDER, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -175,7 +175,6 @@ public class YangJavaTypeDef extends YangTypeDef
|
|||||||
@Override
|
@Override
|
||||||
public void generateCodeExit() throws IOException {
|
public void generateCodeExit() throws IOException {
|
||||||
|
|
||||||
getTempJavaCodeFragmentFiles().setCurYangNode(this);
|
|
||||||
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_TYPEDEF_CLASS, this);
|
getTempJavaCodeFragmentFiles().generateJavaFile(GENERATE_TYPEDEF_CLASS, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,10 +78,12 @@ public final class JavaFileGenerator {
|
|||||||
* @param file file
|
* @param file file
|
||||||
* @param imports imports for the file
|
* @param imports imports for the file
|
||||||
* @param curNode current YANG node
|
* @param curNode current YANG node
|
||||||
|
* @param isAttrPresent if any attribute is present or not
|
||||||
* @return interface file
|
* @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, List<String> imports, YangNode curNode) throws IOException {
|
public static File generateInterfaceFile(File file, List<String> imports, YangNode curNode, boolean isAttrPresent)
|
||||||
|
throws IOException {
|
||||||
|
|
||||||
JavaFileInfo javaFileInfo = ((HasJavaFileInfo) curNode).getJavaFileInfo();
|
JavaFileInfo javaFileInfo = ((HasJavaFileInfo) curNode).getJavaFileInfo();
|
||||||
|
|
||||||
@ -89,18 +91,19 @@ public final class JavaFileGenerator {
|
|||||||
String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
|
String path = javaFileInfo.getBaseCodeGenPath() + javaFileInfo.getPackageFilePath();
|
||||||
|
|
||||||
initiateJavaFileGeneration(file, className, INTERFACE_MASK, imports, path);
|
initiateJavaFileGeneration(file, className, INTERFACE_MASK, imports, path);
|
||||||
|
if (isAttrPresent) {
|
||||||
/**
|
|
||||||
* Add getter methods to interface file.
|
|
||||||
*/
|
|
||||||
try {
|
|
||||||
/**
|
/**
|
||||||
* Getter methods.
|
* Add getter methods to interface file.
|
||||||
*/
|
*/
|
||||||
insertDataIntoJavaFile(file, getDataFromTempFileHandle(GETTER_FOR_INTERFACE_MASK, curNode));
|
try {
|
||||||
} catch (IOException e) {
|
/**
|
||||||
throw new IOException("No data found in temporary java code fragment files for " + className
|
* Getter methods.
|
||||||
+ " while interface file generation");
|
*/
|
||||||
|
insertDataIntoJavaFile(file, getDataFromTempFileHandle(GETTER_FOR_INTERFACE_MASK, curNode));
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new IOException("No data found in temporary java code fragment files for " + className
|
||||||
|
+ " while interface file generation");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
@ -110,10 +113,12 @@ public final class JavaFileGenerator {
|
|||||||
*
|
*
|
||||||
* @param file file
|
* @param file file
|
||||||
* @param curNode current YANG node
|
* @param curNode current YANG node
|
||||||
|
* @param isAttrPresent if any attribute is present or not
|
||||||
* @return builder interface file
|
* @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, YangNode curNode) throws IOException {
|
public static File generateBuilderInterfaceFile(File file, YangNode curNode, boolean isAttrPresent)
|
||||||
|
throws IOException {
|
||||||
|
|
||||||
JavaFileInfo javaFileInfo = ((HasJavaFileInfo) curNode).getJavaFileInfo();
|
JavaFileInfo javaFileInfo = ((HasJavaFileInfo) curNode).getJavaFileInfo();
|
||||||
|
|
||||||
@ -122,22 +127,22 @@ public final class JavaFileGenerator {
|
|||||||
|
|
||||||
initiateJavaFileGeneration(file, className, BUILDER_INTERFACE_MASK, null, path);
|
initiateJavaFileGeneration(file, className, BUILDER_INTERFACE_MASK, null, path);
|
||||||
List<String> methods = new ArrayList<>();
|
List<String> methods = new ArrayList<>();
|
||||||
|
if (isAttrPresent) {
|
||||||
try {
|
try {
|
||||||
/**
|
/**
|
||||||
* Getter methods.
|
* Getter methods.
|
||||||
*/
|
*/
|
||||||
methods.add(FOUR_SPACE_INDENTATION + getDataFromTempFileHandle(GETTER_FOR_INTERFACE_MASK, curNode));
|
methods.add(FOUR_SPACE_INDENTATION + getDataFromTempFileHandle(GETTER_FOR_INTERFACE_MASK, curNode));
|
||||||
/**
|
/**
|
||||||
* Setter methods.
|
* Setter methods.
|
||||||
*/
|
*/
|
||||||
methods.add(NEW_LINE);
|
methods.add(NEW_LINE);
|
||||||
methods.add(FOUR_SPACE_INDENTATION + getDataFromTempFileHandle(SETTER_FOR_INTERFACE_MASK, curNode));
|
methods.add(FOUR_SPACE_INDENTATION + getDataFromTempFileHandle(SETTER_FOR_INTERFACE_MASK, curNode));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new IOException("No data found in temporary java code fragment files for " + className
|
throw new IOException("No data found in temporary java code fragment files for " + className
|
||||||
+ " while builder interface file generation");
|
+ " while builder interface file generation");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add build method to builder interface file.
|
* Add build method to builder interface file.
|
||||||
*/
|
*/
|
||||||
@ -161,10 +166,12 @@ public final class JavaFileGenerator {
|
|||||||
* @param file file
|
* @param file file
|
||||||
* @param imports imports for the file
|
* @param imports imports for the file
|
||||||
* @param curNode current YANG node
|
* @param curNode current YANG node
|
||||||
|
* @param isAttrPresent if any attribute is present or not
|
||||||
* @return builder class file
|
* @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, List<String> imports, YangNode curNode) throws IOException {
|
public static File generateBuilderClassFile(File file, List<String> imports, YangNode curNode,
|
||||||
|
boolean isAttrPresent) throws IOException {
|
||||||
|
|
||||||
JavaFileInfo javaFileInfo = ((HasJavaFileInfo) curNode).getJavaFileInfo();
|
JavaFileInfo javaFileInfo = ((HasJavaFileInfo) curNode).getJavaFileInfo();
|
||||||
|
|
||||||
@ -175,31 +182,34 @@ public final class JavaFileGenerator {
|
|||||||
|
|
||||||
List<String> methods = new ArrayList<>();
|
List<String> methods = new ArrayList<>();
|
||||||
|
|
||||||
/**
|
if (isAttrPresent) {
|
||||||
* Add attribute strings.
|
|
||||||
*/
|
|
||||||
try {
|
|
||||||
insertDataIntoJavaFile(file,
|
|
||||||
NEW_LINE + FOUR_SPACE_INDENTATION + getDataFromTempFileHandle(ATTRIBUTES_MASK, curNode));
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new IOException("No data found in temporary java code fragment files for " + className
|
|
||||||
+ " while builder class file generation");
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
/**
|
/**
|
||||||
* Getter methods.
|
* Add attribute strings.
|
||||||
*/
|
*/
|
||||||
methods.add(getDataFromTempFileHandle(GETTER_FOR_CLASS_MASK, curNode));
|
try {
|
||||||
/**
|
insertDataIntoJavaFile(file,
|
||||||
* Setter methods.
|
NEW_LINE + FOUR_SPACE_INDENTATION + getDataFromTempFileHandle(ATTRIBUTES_MASK, curNode));
|
||||||
*/
|
} catch (IOException e) {
|
||||||
methods.add(getDataFromTempFileHandle(SETTER_FOR_CLASS_MASK, curNode) + NEW_LINE);
|
throw new IOException("No data found in temporary java code fragment files for " + className
|
||||||
} catch (IOException e) {
|
+ " while builder class file generation");
|
||||||
throw new IOException("No data found in temporary java code fragment files for " + className
|
}
|
||||||
+ " while builder class file generation");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
/**
|
||||||
|
* Getter methods.
|
||||||
|
*/
|
||||||
|
methods.add(getDataFromTempFileHandle(GETTER_FOR_CLASS_MASK, curNode));
|
||||||
|
/**
|
||||||
|
* Setter methods.
|
||||||
|
*/
|
||||||
|
methods.add(getDataFromTempFileHandle(SETTER_FOR_CLASS_MASK, curNode) + NEW_LINE);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new IOException("No data found in temporary java code fragment files for " + className
|
||||||
|
+ " while builder class file generation");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
insertDataIntoJavaFile(file, NEW_LINE);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Add default constructor and build method impl.
|
* Add default constructor and build method impl.
|
||||||
*/
|
*/
|
||||||
@ -221,10 +231,11 @@ public final class JavaFileGenerator {
|
|||||||
*
|
*
|
||||||
* @param file file
|
* @param file file
|
||||||
* @param curNode current YANG node
|
* @param curNode current YANG node
|
||||||
|
* @param isAttrPresent if any attribute is present or not
|
||||||
* @return impl class file
|
* @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, YangNode curNode)
|
public static File generateImplClassFile(File file, YangNode curNode, boolean isAttrPresent)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
|
|
||||||
JavaFileInfo javaFileInfo = ((HasJavaFileInfo) curNode).getJavaFileInfo();
|
JavaFileInfo javaFileInfo = ((HasJavaFileInfo) curNode).getJavaFileInfo();
|
||||||
@ -235,45 +246,48 @@ public final class JavaFileGenerator {
|
|||||||
initiateJavaFileGeneration(file, className, IMPL_CLASS_MASK, null, path);
|
initiateJavaFileGeneration(file, className, IMPL_CLASS_MASK, null, path);
|
||||||
|
|
||||||
List<String> methods = new ArrayList<>();
|
List<String> methods = new ArrayList<>();
|
||||||
|
if (isAttrPresent) {
|
||||||
|
/**
|
||||||
|
* Add attribute strings.
|
||||||
|
*/
|
||||||
|
try {
|
||||||
|
insertDataIntoJavaFile(file,
|
||||||
|
NEW_LINE + FOUR_SPACE_INDENTATION + getDataFromTempFileHandle(ATTRIBUTES_MASK, curNode));
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new IOException("No data found in temporary java code fragment files for " + className
|
||||||
|
+ " while impl class file generation");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
insertDataIntoJavaFile(file, NEW_LINE);
|
||||||
* Add attribute strings.
|
try {
|
||||||
*/
|
/**
|
||||||
try {
|
* Getter methods.
|
||||||
insertDataIntoJavaFile(file,
|
*/
|
||||||
NEW_LINE + FOUR_SPACE_INDENTATION + getDataFromTempFileHandle(ATTRIBUTES_MASK, curNode));
|
methods.add(getDataFromTempFileHandle(GETTER_FOR_CLASS_MASK, curNode));
|
||||||
} catch (IOException e) {
|
|
||||||
throw new IOException("No data found in temporary java code fragment files for " + className
|
/**
|
||||||
+ " while impl class file generation");
|
* Hash code method.
|
||||||
|
*/
|
||||||
|
methods.add(getHashCodeMethodClose(getHashCodeMethodOpen() + partString(
|
||||||
|
getDataFromTempFileHandle(HASH_CODE_IMPL_MASK, curNode).replace(NEW_LINE, EMPTY_STRING))));
|
||||||
|
/**
|
||||||
|
* Equals method.
|
||||||
|
*/
|
||||||
|
methods.add(getEqualsMethodClose(
|
||||||
|
getEqualsMethodOpen(className + IMPL) + getDataFromTempFileHandle(EQUALS_IMPL_MASK, curNode)));
|
||||||
|
/**
|
||||||
|
* To string method.
|
||||||
|
*/
|
||||||
|
methods.add(getToStringMethodOpen() + getDataFromTempFileHandle(TO_STRING_IMPL_MASK, curNode)
|
||||||
|
+ getToStringMethodClose());
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new IOException("No data found in temporary java code fragment files for " + className
|
||||||
|
+ " while impl class file generation");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
insertDataIntoJavaFile(file, NEW_LINE);
|
||||||
}
|
}
|
||||||
|
|
||||||
insertDataIntoJavaFile(file, NEW_LINE);
|
|
||||||
try {
|
|
||||||
/**
|
|
||||||
* Getter methods.
|
|
||||||
*/
|
|
||||||
methods.add(getDataFromTempFileHandle(GETTER_FOR_CLASS_MASK, curNode));
|
|
||||||
/**
|
|
||||||
* Hash code method.
|
|
||||||
*/
|
|
||||||
methods.add(getHashCodeMethodClose(getHashCodeMethodOpen() + partString(
|
|
||||||
getDataFromTempFileHandle(HASH_CODE_IMPL_MASK, curNode).replace(NEW_LINE, EMPTY_STRING))));
|
|
||||||
/**
|
|
||||||
* Equals method.
|
|
||||||
*/
|
|
||||||
methods.add(getEqualsMethodClose(
|
|
||||||
getEqualsMethodOpen(className + IMPL) + getDataFromTempFileHandle(EQUALS_IMPL_MASK, curNode)));
|
|
||||||
/**
|
|
||||||
* To string method.
|
|
||||||
*/
|
|
||||||
methods.add(getToStringMethodOpen() + getDataFromTempFileHandle(TO_STRING_IMPL_MASK, curNode)
|
|
||||||
+ getToStringMethodClose());
|
|
||||||
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new IOException("No data found in temporary java code fragment files for " + className
|
|
||||||
+ " while impl class file generation");
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
|
@ -42,6 +42,7 @@ import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.
|
|||||||
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK;
|
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.SETTER_FOR_INTERFACE_MASK;
|
||||||
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK;
|
import static org.onosproject.yangutils.translator.tojava.GeneratedTempFileType.TO_STRING_IMPL_MASK;
|
||||||
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefStart;
|
import static org.onosproject.yangutils.translator.tojava.utils.JavaCodeSnippetGen.getJavaClassDefStart;
|
||||||
|
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getJavaPackageFromPackagePath;
|
||||||
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
|
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
|
||||||
import static org.onosproject.yangutils.utils.UtilConstants.ORG;
|
import static org.onosproject.yangutils.utils.UtilConstants.ORG;
|
||||||
import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE;
|
import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE;
|
||||||
@ -53,7 +54,6 @@ import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUI
|
|||||||
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_INTERFACE;
|
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.BUILDER_INTERFACE;
|
||||||
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.IMPL_CLASS;
|
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.IMPL_CLASS;
|
||||||
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.INTERFACE;
|
import static org.onosproject.yangutils.utils.io.impl.JavaDocGen.JavaDocType.INTERFACE;
|
||||||
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.convertPathToPkg;
|
|
||||||
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile;
|
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.insertDataIntoJavaFile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -192,7 +192,7 @@ public final class JavaFileGeneratorUtils {
|
|||||||
|
|
||||||
if (javaPkg.contains(ORG)) {
|
if (javaPkg.contains(ORG)) {
|
||||||
String[] strArray = javaPkg.split(ORG);
|
String[] strArray = javaPkg.split(ORG);
|
||||||
javaPkg = ORG + convertPathToPkg(strArray[1]);
|
javaPkg = ORG + getJavaPackageFromPackagePath(strArray[1]);
|
||||||
}
|
}
|
||||||
if (importsList != null) {
|
if (importsList != null) {
|
||||||
if (!importsList.isEmpty()) {
|
if (!importsList.isEmpty()) {
|
||||||
|
@ -32,8 +32,10 @@ import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
|
|||||||
import static org.onosproject.yangutils.utils.UtilConstants.QUOTES;
|
import static org.onosproject.yangutils.utils.UtilConstants.QUOTES;
|
||||||
import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_FIRST_DIGIT;
|
import static org.onosproject.yangutils.utils.UtilConstants.REGEX_FOR_FIRST_DIGIT;
|
||||||
import static org.onosproject.yangutils.utils.UtilConstants.REGEX_WITH_SPECIAL_CHAR;
|
import static org.onosproject.yangutils.utils.UtilConstants.REGEX_WITH_SPECIAL_CHAR;
|
||||||
|
import static org.onosproject.yangutils.utils.UtilConstants.REVISION_PREFIX;
|
||||||
import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
|
import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
|
||||||
import static org.onosproject.yangutils.utils.UtilConstants.UNDER_SCORE;
|
import static org.onosproject.yangutils.utils.UtilConstants.UNDER_SCORE;
|
||||||
|
import static org.onosproject.yangutils.utils.UtilConstants.VERSION_PREFIX;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility Class for translating the name from YANG to java convention.
|
* Utility Class for translating the name from YANG to java convention.
|
||||||
@ -121,7 +123,7 @@ public final class JavaIdentifierSyntax {
|
|||||||
*/
|
*/
|
||||||
private static String getYangVersion(byte ver) {
|
private static String getYangVersion(byte ver) {
|
||||||
|
|
||||||
return "v" + ver;
|
return VERSION_PREFIX + ver;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -154,7 +156,7 @@ public final class JavaIdentifierSyntax {
|
|||||||
|
|
||||||
String[] revisionArr = date.split(HYPHEN);
|
String[] revisionArr = date.split(HYPHEN);
|
||||||
|
|
||||||
String rev = "rev";
|
String rev = REVISION_PREFIX;
|
||||||
rev = rev + revisionArr[INDEX_ZERO];
|
rev = rev + revisionArr[INDEX_ZERO];
|
||||||
|
|
||||||
if (Integer.parseInt(revisionArr[INDEX_ONE]) <= MAX_MONTHS
|
if (Integer.parseInt(revisionArr[INDEX_ONE]) <= MAX_MONTHS
|
||||||
@ -251,7 +253,7 @@ public final class JavaIdentifierSyntax {
|
|||||||
* @param yangIdentifier identifier in YANG file.
|
* @param yangIdentifier identifier in YANG file.
|
||||||
* @return corresponding java identifier
|
* @return corresponding java identifier
|
||||||
*/
|
*/
|
||||||
public static String getLowerCase(String yangIdentifier) {
|
public static String getSmallCase(String yangIdentifier) {
|
||||||
|
|
||||||
return yangIdentifier.substring(0, 1).toLowerCase() + yangIdentifier.substring(1);
|
return yangIdentifier.substring(0, 1).toLowerCase() + yangIdentifier.substring(1);
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ import org.onosproject.yangutils.translator.tojava.JavaAttributeInfo;
|
|||||||
|
|
||||||
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
|
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
|
||||||
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
|
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
|
||||||
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getLowerCase;
|
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase;
|
||||||
import static org.onosproject.yangutils.utils.UtilConstants.ADD_STRING;
|
import static org.onosproject.yangutils.utils.UtilConstants.ADD_STRING;
|
||||||
import static org.onosproject.yangutils.utils.UtilConstants.AND;
|
import static org.onosproject.yangutils.utils.UtilConstants.AND;
|
||||||
import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_DATA_TYPE;
|
import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_DATA_TYPE;
|
||||||
@ -113,7 +113,7 @@ public final class MethodsGenerator {
|
|||||||
public static String getGetterString(JavaAttributeInfo attr) {
|
public static String getGetterString(JavaAttributeInfo attr) {
|
||||||
|
|
||||||
String returnType = getReturnType(attr);
|
String returnType = getReturnType(attr);
|
||||||
String attributeName = getLowerCase(attr.getAttributeName());
|
String attributeName = getSmallCase(attr.getAttributeName());
|
||||||
|
|
||||||
return getJavaDoc(GETTER_METHOD, attributeName, attr.isListAttr())
|
return getJavaDoc(GETTER_METHOD, attributeName, attr.isListAttr())
|
||||||
+ getGetterForInterface(attributeName, returnType, attr.isListAttr());
|
+ getGetterForInterface(attributeName, returnType, attr.isListAttr());
|
||||||
@ -129,7 +129,7 @@ public final class MethodsGenerator {
|
|||||||
public static String getSetterString(JavaAttributeInfo attr, String className) {
|
public static String getSetterString(JavaAttributeInfo attr, String className) {
|
||||||
|
|
||||||
String attrType = getReturnType(attr);
|
String attrType = getReturnType(attr);
|
||||||
String attributeName = getLowerCase(attr.getAttributeName());
|
String attributeName = getSmallCase(attr.getAttributeName());
|
||||||
|
|
||||||
return getJavaDoc(SETTER_METHOD, attributeName, attr.isListAttr())
|
return getJavaDoc(SETTER_METHOD, attributeName, attr.isListAttr())
|
||||||
+ getSetterForInterface(attributeName, attrType, className, attr.isListAttr());
|
+ getSetterForInterface(attributeName, attrType, className, attr.isListAttr());
|
||||||
@ -168,7 +168,7 @@ public final class MethodsGenerator {
|
|||||||
public static String getTypeDefConstructor(JavaAttributeInfo attr, String className) {
|
public static String getTypeDefConstructor(JavaAttributeInfo attr, String className) {
|
||||||
|
|
||||||
String attrQuaifiedType = getReturnType(attr);
|
String attrQuaifiedType = getReturnType(attr);
|
||||||
String attributeName = getLowerCase(attr.getAttributeName());
|
String attributeName = getSmallCase(attr.getAttributeName());
|
||||||
|
|
||||||
if (!attr.isListAttr()) {
|
if (!attr.isListAttr()) {
|
||||||
return getTypeDefConstructorString(attrQuaifiedType, attributeName, className);
|
return getTypeDefConstructorString(attrQuaifiedType, attributeName, className);
|
||||||
@ -225,7 +225,7 @@ public final class MethodsGenerator {
|
|||||||
public static String getGetterForClass(JavaAttributeInfo attr) {
|
public static String getGetterForClass(JavaAttributeInfo attr) {
|
||||||
|
|
||||||
String attrQuaifiedType = getReturnType(attr);
|
String attrQuaifiedType = getReturnType(attr);
|
||||||
String attributeName = getLowerCase(attr.getAttributeName());
|
String attributeName = getSmallCase(attr.getAttributeName());
|
||||||
|
|
||||||
if (!attr.isListAttr()) {
|
if (!attr.isListAttr()) {
|
||||||
return getGetter(attrQuaifiedType, attributeName);
|
return getGetter(attrQuaifiedType, attributeName);
|
||||||
@ -258,7 +258,7 @@ public final class MethodsGenerator {
|
|||||||
public static String getSetterForClass(JavaAttributeInfo attr, String className) {
|
public static String getSetterForClass(JavaAttributeInfo attr, String className) {
|
||||||
|
|
||||||
String attrQuaifiedType = getReturnType(attr);
|
String attrQuaifiedType = getReturnType(attr);
|
||||||
String attributeName = getLowerCase(attr.getAttributeName());
|
String attributeName = getSmallCase(attr.getAttributeName());
|
||||||
if (!attr.isListAttr()) {
|
if (!attr.isListAttr()) {
|
||||||
return getSetter(className, attributeName, attrQuaifiedType);
|
return getSetter(className, attributeName, attrQuaifiedType);
|
||||||
}
|
}
|
||||||
@ -292,7 +292,7 @@ public final class MethodsGenerator {
|
|||||||
public static String getSetterForTypeDefClass(JavaAttributeInfo attr) {
|
public static String getSetterForTypeDefClass(JavaAttributeInfo attr) {
|
||||||
|
|
||||||
String attrQuaifiedType = getReturnType(attr);
|
String attrQuaifiedType = getReturnType(attr);
|
||||||
String attributeName = getLowerCase(attr.getAttributeName());
|
String attributeName = getSmallCase(attr.getAttributeName());
|
||||||
return getTypeDefSetter(attrQuaifiedType, attributeName);
|
return getTypeDefSetter(attrQuaifiedType, attributeName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -445,7 +445,7 @@ public final class MethodsGenerator {
|
|||||||
*/
|
*/
|
||||||
public static String getConstructor(String yangName, JavaAttributeInfo attr) {
|
public static String getConstructor(String yangName, JavaAttributeInfo attr) {
|
||||||
|
|
||||||
String attributeName = getLowerCase(attr.getAttributeName());
|
String attributeName = getSmallCase(attr.getAttributeName());
|
||||||
|
|
||||||
String constructor = EIGHT_SPACE_INDENTATION + THIS + PERIOD + getCamelCase(attributeName) + SPACE + EQUAL
|
String constructor = EIGHT_SPACE_INDENTATION + THIS + PERIOD + getCamelCase(attributeName) + SPACE + EQUAL
|
||||||
+ SPACE + BUILDER.toLowerCase() + OBJECT + PERIOD + GET_METHOD_PREFIX
|
+ SPACE + BUILDER.toLowerCase() + OBJECT + PERIOD + GET_METHOD_PREFIX
|
||||||
@ -513,7 +513,7 @@ public final class MethodsGenerator {
|
|||||||
*/
|
*/
|
||||||
public static String getToStringMethod(JavaAttributeInfo attr) {
|
public static String getToStringMethod(JavaAttributeInfo attr) {
|
||||||
|
|
||||||
String attributeName = getLowerCase(attr.getAttributeName());
|
String attributeName = getSmallCase(attr.getAttributeName());
|
||||||
|
|
||||||
return TWELVE_SPACE_INDENTATION + PERIOD + ADD_STRING + OPEN_PARENTHESIS + QUOTES + attributeName + QUOTES
|
return TWELVE_SPACE_INDENTATION + PERIOD + ADD_STRING + OPEN_PARENTHESIS + QUOTES + attributeName + QUOTES
|
||||||
+ COMMA + SPACE + attributeName + CLOSE_PARENTHESIS;
|
+ COMMA + SPACE + attributeName + CLOSE_PARENTHESIS;
|
||||||
@ -554,7 +554,7 @@ public final class MethodsGenerator {
|
|||||||
*/
|
*/
|
||||||
public static String getHashCodeMethod(JavaAttributeInfo attr) {
|
public static String getHashCodeMethod(JavaAttributeInfo attr) {
|
||||||
|
|
||||||
return getLowerCase(attr.getAttributeName()) + COMMA + SPACE;
|
return getSmallCase(attr.getAttributeName()) + COMMA + SPACE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -621,7 +621,7 @@ public final class MethodsGenerator {
|
|||||||
*/
|
*/
|
||||||
public static String getEqualsMethod(JavaAttributeInfo attr) {
|
public static String getEqualsMethod(JavaAttributeInfo attr) {
|
||||||
|
|
||||||
String attributeName = getLowerCase(attr.getAttributeName());
|
String attributeName = getSmallCase(attr.getAttributeName());
|
||||||
|
|
||||||
return SIXTEEN_SPACE_INDENTATION + SPACE + OBJECT_STRING + SUFFIX_S + PERIOD + EQUALS_STRING + OPEN_PARENTHESIS
|
return SIXTEEN_SPACE_INDENTATION + SPACE + OBJECT_STRING + SUFFIX_S + PERIOD + EQUALS_STRING + OPEN_PARENTHESIS
|
||||||
+ attributeName + COMMA + SPACE + OTHER + PERIOD + attributeName + CLOSE_PARENTHESIS + SPACE + AND
|
+ attributeName + COMMA + SPACE + OTHER + PERIOD + attributeName + CLOSE_PARENTHESIS + SPACE + AND
|
||||||
|
@ -1,73 +0,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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.onosproject.yangutils.translator.tojava.utils;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Data Store types.
|
|
||||||
*/
|
|
||||||
public enum TempDataStoreTypes {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Getter methods for interfaces.
|
|
||||||
*/
|
|
||||||
GETTER_METHODS,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Getter methods impl for classes.
|
|
||||||
*/
|
|
||||||
GETTER_METHODS_IMPL,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Setter methods for interfaces.
|
|
||||||
*/
|
|
||||||
SETTER_METHODS,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Setter methods impl for classes.
|
|
||||||
*/
|
|
||||||
SETTER_METHODS_IMPL,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor for impl class.
|
|
||||||
*/
|
|
||||||
CONSTRUCTOR,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Attributes.
|
|
||||||
*/
|
|
||||||
ATTRIBUTE,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* TypeDef.
|
|
||||||
*/
|
|
||||||
TYPE_DEF,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ToString method.
|
|
||||||
*/
|
|
||||||
TO_STRING,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* HashCode method.
|
|
||||||
*/
|
|
||||||
HASH_CODE,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Equals method.
|
|
||||||
*/
|
|
||||||
EQUALS
|
|
||||||
}
|
|
@ -32,118 +32,405 @@ public final class UtilConstants {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For java-docs.
|
* JavaDocs for impl class.
|
||||||
*/
|
*/
|
||||||
public static final String IMPL_CLASS_JAVA_DOC = " * Provides the implementation of ";
|
public static final String IMPL_CLASS_JAVA_DOC = " * Provides the implementation of ";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JavaDocs for builder class.
|
||||||
|
*/
|
||||||
public static final String BUILDER_CLASS_JAVA_DOC = " * Provides the builder implementation of ";
|
public static final String BUILDER_CLASS_JAVA_DOC = " * Provides the builder implementation of ";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JavaDocs for interface class.
|
||||||
|
*/
|
||||||
public static final String INTERFACE_JAVA_DOC = " * Abstraction of an entity which provides functionalities of ";
|
public static final String INTERFACE_JAVA_DOC = " * Abstraction of an entity which provides functionalities of ";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JavaDocs for builder interface class.
|
||||||
|
*/
|
||||||
public static final String BUILDER_INTERFACE_JAVA_DOC = " * Builder for ";
|
public static final String BUILDER_INTERFACE_JAVA_DOC = " * Builder for ";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JavaDocs for package info class.
|
||||||
|
*/
|
||||||
public static final String PACKAGE_INFO_JAVADOC = " * Implementation of YANG file ";
|
public static final String PACKAGE_INFO_JAVADOC = " * Implementation of YANG file ";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JavaDocs's first line.
|
||||||
|
*/
|
||||||
public static final String JAVA_DOC_FIRST_LINE = "/**\n";
|
public static final String JAVA_DOC_FIRST_LINE = "/**\n";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JavaDocs's last line.
|
||||||
|
*/
|
||||||
public static final String JAVA_DOC_END_LINE = " */\n";
|
public static final String JAVA_DOC_END_LINE = " */\n";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JavaDocs's param annotation.
|
||||||
|
*/
|
||||||
public static final String JAVA_DOC_PARAM = " * @param ";
|
public static final String JAVA_DOC_PARAM = " * @param ";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JavaDocs's return annotation.
|
||||||
|
*/
|
||||||
public static final String JAVA_DOC_RETURN = " * @return ";
|
public static final String JAVA_DOC_RETURN = " * @return ";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JavaDocs's throw annotation.
|
||||||
|
*/
|
||||||
public static final String JAVA_DOC_THROWS = " * @throws ";
|
public static final String JAVA_DOC_THROWS = " * @throws ";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JavaDocs's description for setter method.
|
||||||
|
*/
|
||||||
public static final String JAVA_DOC_SETTERS = " * Returns the builder object of ";
|
public static final String JAVA_DOC_SETTERS = " * Returns the builder object of ";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JavaDocs's description for OF method.
|
||||||
|
*/
|
||||||
public static final String JAVA_DOC_OF = " * Returns the object of ";
|
public static final String JAVA_DOC_OF = " * Returns the object of ";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JavaDocs's description for typedef' setter method.
|
||||||
|
*/
|
||||||
public static final String JAVA_DOC_SETTERS_COMMON = " * Sets the value of ";
|
public static final String JAVA_DOC_SETTERS_COMMON = " * Sets the value of ";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JavaDocs's description for getter method.
|
||||||
|
*/
|
||||||
public static final String JAVA_DOC_GETTERS = " * Returns the attribute ";
|
public static final String JAVA_DOC_GETTERS = " * Returns the attribute ";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JavaDocs's description for default constructor.
|
||||||
|
*/
|
||||||
public static final String JAVA_DOC_DEFAULT_CONSTRUCTOR = " * Default Constructor.\n";
|
public static final String JAVA_DOC_DEFAULT_CONSTRUCTOR = " * Default Constructor.\n";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JavaDocs's description for constructor.
|
||||||
|
*/
|
||||||
public static final String JAVA_DOC_CONSTRUCTOR = " * Construct the object of ";
|
public static final String JAVA_DOC_CONSTRUCTOR = " * Construct the object of ";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JavaDocs's description for build method.
|
||||||
|
*/
|
||||||
public static final String JAVA_DOC_BUILD = " * Builds object of ";
|
public static final String JAVA_DOC_BUILD = " * Builds object of ";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JavaDocs's return statement for build method.
|
||||||
|
*/
|
||||||
public static final String JAVA_DOC_BUILD_RETURN = "object of ";
|
public static final String JAVA_DOC_BUILD_RETURN = "object of ";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Basic requirements.
|
* JavaDocs's statement for builder object.
|
||||||
|
*/
|
||||||
|
public static final String BUILDER_OBJECT = "builder object of ";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for new line.
|
||||||
*/
|
*/
|
||||||
public static final String NEW_LINE = "\n";
|
public static final String NEW_LINE = "\n";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for multiple new line.
|
||||||
|
*/
|
||||||
public static final String MULTIPLE_NEW_LINE = "\n\n";
|
public static final String MULTIPLE_NEW_LINE = "\n\n";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for empty line.
|
||||||
|
*/
|
||||||
public static final String EMPTY_STRING = "";
|
public static final String EMPTY_STRING = "";
|
||||||
public static final String NEW_LINE_ESTRIC = " *\n";
|
|
||||||
|
/**
|
||||||
|
* Static attribute for new line with asterisk.
|
||||||
|
*/
|
||||||
|
public static final String NEW_LINE_ASTERISK = " *\n";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for period.
|
||||||
|
*/
|
||||||
public static final String PERIOD = ".";
|
public static final String PERIOD = ".";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for colan.
|
||||||
|
*/
|
||||||
public static final String COLAN = ":";
|
public static final String COLAN = ":";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for underscore.
|
||||||
|
*/
|
||||||
public static final String UNDER_SCORE = "_";
|
public static final String UNDER_SCORE = "_";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for semi-colan.
|
||||||
|
*/
|
||||||
public static final String SEMI_COLAN = ";";
|
public static final String SEMI_COLAN = ";";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for hyphen.
|
||||||
|
*/
|
||||||
public static final String HYPHEN = "-";
|
public static final String HYPHEN = "-";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for space.
|
||||||
|
*/
|
||||||
public static final String SPACE = " ";
|
public static final String SPACE = " ";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for tab.
|
||||||
|
*/
|
||||||
public static final String TAB = "\t";
|
public static final String TAB = "\t";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for new line.
|
||||||
|
*/
|
||||||
public static final String EQUAL = "=";
|
public static final String EQUAL = "=";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for slash syntax.
|
||||||
|
*/
|
||||||
public static final String SLASH = File.separator;
|
public static final String SLASH = File.separator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for add syntax.
|
||||||
|
*/
|
||||||
public static final String ADD = "+";
|
public static final String ADD = "+";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for asterisk.
|
||||||
|
*/
|
||||||
public static final String ASTERISK = "*";
|
public static final String ASTERISK = "*";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for at.
|
||||||
|
*/
|
||||||
public static final String AT = "@";
|
public static final String AT = "@";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for quotes.
|
||||||
|
*/
|
||||||
public static final String QUOTES = "\"";
|
public static final String QUOTES = "\"";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for ampersand.
|
||||||
|
*/
|
||||||
public static final String AND = "&";
|
public static final String AND = "&";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for comma.
|
||||||
|
*/
|
||||||
public static final String COMMA = ",";
|
public static final String COMMA = ",";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for add syntax.
|
||||||
|
*/
|
||||||
public static final String ADD_STRING = "add";
|
public static final String ADD_STRING = "add";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for check not null syntax.
|
||||||
|
*/
|
||||||
public static final String CHECK_NOT_NULL_STRING = "checkNotNull";
|
public static final String CHECK_NOT_NULL_STRING = "checkNotNull";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for hash code syntax.
|
||||||
|
*/
|
||||||
public static final String HASH_CODE_STRING = "hashCode";
|
public static final String HASH_CODE_STRING = "hashCode";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for equals syntax.
|
||||||
|
*/
|
||||||
public static final String EQUALS_STRING = "equals";
|
public static final String EQUALS_STRING = "equals";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for object.
|
||||||
|
*/
|
||||||
public static final String OBJECT_STRING = "Object";
|
public static final String OBJECT_STRING = "Object";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for instance of syntax.
|
||||||
|
*/
|
||||||
public static final String INSTANCE_OF = " instanceof ";
|
public static final String INSTANCE_OF = " instanceof ";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for value syntax.
|
||||||
|
*/
|
||||||
public static final String VALUE = "value";
|
public static final String VALUE = "value";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for suffix s.
|
||||||
|
*/
|
||||||
public static final String SUFFIX_S = "s";
|
public static final String SUFFIX_S = "s";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for if.
|
||||||
|
*/
|
||||||
public static final String IF = "if";
|
public static final String IF = "if";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for for.
|
||||||
|
*/
|
||||||
public static final String FOR = "for";
|
public static final String FOR = "for";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for while.
|
||||||
|
*/
|
||||||
public static final String WHILE = "while";
|
public static final String WHILE = "while";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for of.
|
||||||
|
*/
|
||||||
public static final String OF = "of";
|
public static final String OF = "of";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for other.
|
||||||
|
*/
|
||||||
public static final String OTHER = "other";
|
public static final String OTHER = "other";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for obj syntax.
|
||||||
|
*/
|
||||||
public static final String OBJ = "obj";
|
public static final String OBJ = "obj";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for hash syntax.
|
||||||
|
*/
|
||||||
public static final String HASH = "hash";
|
public static final String HASH = "hash";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for to syntax.
|
||||||
|
*/
|
||||||
public static final String TO = "to";
|
public static final String TO = "to";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for true syntax.
|
||||||
|
*/
|
||||||
public static final String TRUE = "true";
|
public static final String TRUE = "true";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for false syntax.
|
||||||
|
*/
|
||||||
public static final String FALSE = "false";
|
public static final String FALSE = "false";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for org.
|
||||||
|
*/
|
||||||
public static final String ORG = "org";
|
public static final String ORG = "org";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for temp.
|
||||||
|
*/
|
||||||
public static final String TEMP = "temp";
|
public static final String TEMP = "temp";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for YANG file directory.
|
||||||
|
*/
|
||||||
public static final String YANG_RESOURCES = "yang/resources";
|
public static final String YANG_RESOURCES = "yang/resources";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For brackets.
|
* Static attribute for diamond close bracket syntax.
|
||||||
*/
|
*/
|
||||||
public static final String DIAMOND_OPEN_BRACKET = "<";
|
public static final String DIAMOND_OPEN_BRACKET = "<";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for diamond close bracket syntax.
|
||||||
|
*/
|
||||||
public static final String DIAMOND_CLOSE_BRACKET = ">";
|
public static final String DIAMOND_CLOSE_BRACKET = ">";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for square open bracket syntax.
|
||||||
|
*/
|
||||||
public static final String SQUARE_OPEN_BRACKET = "[";
|
public static final String SQUARE_OPEN_BRACKET = "[";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for square close bracket syntax.
|
||||||
|
*/
|
||||||
public static final String SQUARE_CLOSE_BRACKET = "]";
|
public static final String SQUARE_CLOSE_BRACKET = "]";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for open parenthesis syntax.
|
||||||
|
*/
|
||||||
public static final String OPEN_PARENTHESIS = "(";
|
public static final String OPEN_PARENTHESIS = "(";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for close parenthesis syntax.
|
||||||
|
*/
|
||||||
public static final String CLOSE_PARENTHESIS = ")";
|
public static final String CLOSE_PARENTHESIS = ")";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for open curly bracket syntax.
|
||||||
|
*/
|
||||||
public static final String OPEN_CURLY_BRACKET = "{";
|
public static final String OPEN_CURLY_BRACKET = "{";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for close curly bracket syntax.
|
||||||
|
*/
|
||||||
public static final String CLOSE_CURLY_BRACKET = "}";
|
public static final String CLOSE_CURLY_BRACKET = "}";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For methods.
|
* Static attribute for getter method prefix.
|
||||||
*/
|
*/
|
||||||
public static final String GET_METHOD_PREFIX = "get";
|
public static final String GET_METHOD_PREFIX = "get";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for setter method prefix.
|
||||||
|
*/
|
||||||
public static final String SET_METHOD_PREFIX = "set";
|
public static final String SET_METHOD_PREFIX = "set";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For indentation.
|
* Static attribute for four space indentation.
|
||||||
*/
|
*/
|
||||||
public static final String FOUR_SPACE_INDENTATION = " ";
|
public static final String FOUR_SPACE_INDENTATION = " ";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for eight space indentation.
|
||||||
|
*/
|
||||||
public static final String EIGHT_SPACE_INDENTATION = FOUR_SPACE_INDENTATION + FOUR_SPACE_INDENTATION;
|
public static final String EIGHT_SPACE_INDENTATION = FOUR_SPACE_INDENTATION + FOUR_SPACE_INDENTATION;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for twelve space indentation.
|
||||||
|
*/
|
||||||
public static final String TWELVE_SPACE_INDENTATION = FOUR_SPACE_INDENTATION + EIGHT_SPACE_INDENTATION;
|
public static final String TWELVE_SPACE_INDENTATION = FOUR_SPACE_INDENTATION + EIGHT_SPACE_INDENTATION;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for sixteen space indentation.
|
||||||
|
*/
|
||||||
public static final String SIXTEEN_SPACE_INDENTATION = EIGHT_SPACE_INDENTATION + EIGHT_SPACE_INDENTATION;
|
public static final String SIXTEEN_SPACE_INDENTATION = EIGHT_SPACE_INDENTATION + EIGHT_SPACE_INDENTATION;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For directories.
|
* Static attribute for generated code path.
|
||||||
*/
|
*/
|
||||||
public static final String YANG_GEN_DIR = "src/main/java/";
|
public static final String YANG_GEN_DIR = "src/main/java/";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for base package.
|
||||||
|
*/
|
||||||
public static final String DEFAULT_BASE_PKG = "org.onosproject.yang.gen";
|
public static final String DEFAULT_BASE_PKG = "org.onosproject.yang.gen";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for YANG date prefix.
|
||||||
|
*/
|
||||||
public static final String REVISION_PREFIX = "rev";
|
public static final String REVISION_PREFIX = "rev";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for YANG version perifx.
|
||||||
|
*/
|
||||||
public static final String VERSION_PREFIX = "v";
|
public static final String VERSION_PREFIX = "v";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For class modifiers.
|
* Static attribute for private modifier.
|
||||||
*/
|
*/
|
||||||
public static final String PRIVATE = "private";
|
public static final String PRIVATE = "private";
|
||||||
public static final String PUBLIC = "public";
|
|
||||||
public static final String PROTECTED = "protected";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For data types.
|
* Static attribute for public modifier.
|
||||||
*/
|
*/
|
||||||
|
public static final String PUBLIC = "public";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for protected modifier.
|
||||||
|
*/
|
||||||
|
public static final String PROTECTED = "protected";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Void java type.
|
* Void java type.
|
||||||
*/
|
*/
|
||||||
@ -231,71 +518,230 @@ public final class UtilConstants {
|
|||||||
/**
|
/**
|
||||||
* List of keywords in java, this is used for checking if the input does not contain these keywords.
|
* List of keywords in java, this is used for checking if the input does not contain these keywords.
|
||||||
*/
|
*/
|
||||||
public static final List JAVA_KEY_WORDS = Arrays.asList("abstract", "assert", "boolean", "break", "byte", "case",
|
public static final List<String> JAVA_KEY_WORDS = Arrays.asList(
|
||||||
"catch", "char", "class", "const", "continue", "default", "do", "double", "else", "extends", "false",
|
"abstract", "assert", "boolean", "break", "byte", "case", "catch", "char", "class", "const", "continue",
|
||||||
"final", "finally", "float", "for", "goto", "if", "implements", "import", "instanceof", "int", "interface",
|
"default", "do", "double", "else", "extends", "false", "final", "finally", "float", "for", "goto", "if",
|
||||||
"long", "native", "new", "null", "package", "private", "protected", "public", "return", "short", "static",
|
"implements", "import", "instanceof", "int", "interface", "long", "native", "new", "null", "package",
|
||||||
"strictfp", "super", "switch", "synchronized", "this", "throw", "throws", "transient", "true", "try",
|
"private", "protected", "public", "return", "short", "static", "strictfp", "super", "switch",
|
||||||
"void", "volatile", "while");
|
"synchronized", "this", "throw", "throws", "transient", "true", "try", "void", "volatile", "while");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defining regular expression.
|
* Static attribute for regex for special char.
|
||||||
*/
|
*/
|
||||||
public static final String REGEX_WITH_SPECIAL_CHAR = "[ : / - @ $ # ' * + , ; = ]+";
|
public static final String REGEX_WITH_SPECIAL_CHAR = "[ : / - @ $ # ' * + , ; = ]+";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for regex for digits.
|
||||||
|
*/
|
||||||
public static final String REGEX_FOR_FIRST_DIGIT = "\\d.*";
|
public static final String REGEX_FOR_FIRST_DIGIT = "\\d.*";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For identifiers.
|
* Static attribute for class syntax.
|
||||||
*/
|
*/
|
||||||
public static final String CLASS = "class";
|
public static final String CLASS = "class";
|
||||||
public static final String BUILDER = "Builder";
|
|
||||||
public static final String BUILDER_OBJECT = "builder object of ";
|
|
||||||
public static final String INTERFACE = "interface";
|
|
||||||
public static final String ENUM = "enum";
|
|
||||||
public static final String STATIC = "static";
|
|
||||||
public static final String FINAL = "final";
|
|
||||||
public static final String PACKAGE = "package";
|
|
||||||
public static final String IMPORT = "import ";
|
|
||||||
public static final String NULL = "null";
|
|
||||||
public static final String RETURN = "return";
|
|
||||||
public static final String NEW = "new";
|
|
||||||
public static final String THIS = "this";
|
|
||||||
public static final String IMPLEMENTS = "implements";
|
|
||||||
public static final String EXTEND = "extends";
|
|
||||||
public static final String IMPL = "Impl";
|
|
||||||
public static final String BUILD = "build";
|
|
||||||
public static final String OBJECT = "Object";
|
|
||||||
public static final String OVERRIDE = "@Override";
|
|
||||||
public static final String CHILDREN = "'s children";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For collections.
|
* Static attribute for builder syntax.
|
||||||
|
*/
|
||||||
|
public static final String BUILDER = "Builder";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for interface syntax.
|
||||||
|
*/
|
||||||
|
public static final String INTERFACE = "interface";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for enum syntax.
|
||||||
|
*/
|
||||||
|
public static final String ENUM = "enum";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for static syntax.
|
||||||
|
*/
|
||||||
|
public static final String STATIC = "static";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for final syntax.
|
||||||
|
*/
|
||||||
|
public static final String FINAL = "final";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for package syntax.
|
||||||
|
*/
|
||||||
|
public static final String PACKAGE = "package";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for import syntax.
|
||||||
|
*/
|
||||||
|
public static final String IMPORT = "import ";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for null syntax.
|
||||||
|
*/
|
||||||
|
public static final String NULL = "null";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for return syntax.
|
||||||
|
*/
|
||||||
|
public static final String RETURN = "return";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for java new syntax.
|
||||||
|
*/
|
||||||
|
public static final String NEW = "new";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for this syntax.
|
||||||
|
*/
|
||||||
|
public static final String THIS = "this";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for implements syntax.
|
||||||
|
*/
|
||||||
|
public static final String IMPLEMENTS = "implements";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for extends syntax.
|
||||||
|
*/
|
||||||
|
public static final String EXTEND = "extends";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for impl syntax.
|
||||||
|
*/
|
||||||
|
public static final String IMPL = "Impl";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for build method syntax.
|
||||||
|
*/
|
||||||
|
public static final String BUILD = "build";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for object.
|
||||||
|
*/
|
||||||
|
public static final String OBJECT = "Object";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for override annotation.
|
||||||
|
*/
|
||||||
|
public static final String OVERRIDE = "@Override";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for new line.
|
||||||
*/
|
*/
|
||||||
public static final String COLLECTION_IMPORTS = "java.util";
|
public static final String COLLECTION_IMPORTS = "java.util";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for more object import package.
|
||||||
|
*/
|
||||||
public static final String GOOGLE_MORE_OBJECT_IMPORT_PKG = "com.google.common.base";
|
public static final String GOOGLE_MORE_OBJECT_IMPORT_PKG = "com.google.common.base";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for more object import class.
|
||||||
|
*/
|
||||||
public static final String GOOGLE_MORE_OBJECT_IMPORT_CLASS = "MoreObjects;\n";
|
public static final String GOOGLE_MORE_OBJECT_IMPORT_CLASS = "MoreObjects;\n";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for to string method.
|
||||||
|
*/
|
||||||
public static final String GOOGLE_MORE_OBJECT_METHOD_STRING = " MoreObjects.toStringHelper(getClass())";
|
public static final String GOOGLE_MORE_OBJECT_METHOD_STRING = " MoreObjects.toStringHelper(getClass())";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for java utilities import package.
|
||||||
|
*/
|
||||||
public static final String JAVA_UTIL_OBJECTS_IMPORT_PKG = "java.util";
|
public static final String JAVA_UTIL_OBJECTS_IMPORT_PKG = "java.util";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for java utilities objects import class.
|
||||||
|
*/
|
||||||
public static final String JAVA_UTIL_OBJECTS_IMPORT_CLASS = "Objects;\n";
|
public static final String JAVA_UTIL_OBJECTS_IMPORT_CLASS = "Objects;\n";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for abstract collection.
|
||||||
|
*/
|
||||||
public static final String ABSTRACT_COLLECTION = "AbstractCollection";
|
public static final String ABSTRACT_COLLECTION = "AbstractCollection";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for list.
|
||||||
|
*/
|
||||||
public static final String LIST = "List";
|
public static final String LIST = "List";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for linked list.
|
||||||
|
*/
|
||||||
public static final String LINKED_LIST = "LinkedList";
|
public static final String LINKED_LIST = "LinkedList";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for array list.
|
||||||
|
*/
|
||||||
public static final String ARRAY_LIST = "ArrayList";
|
public static final String ARRAY_LIST = "ArrayList";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for abstract list.
|
||||||
|
*/
|
||||||
public static final String ABSTRACT_LIST = "AbstractList";
|
public static final String ABSTRACT_LIST = "AbstractList";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for abstract sequential list.
|
||||||
|
*/
|
||||||
public static final String ABSTRACT_SEQUENTAIL_LIST = "AbstractSequentialList";
|
public static final String ABSTRACT_SEQUENTAIL_LIST = "AbstractSequentialList";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for set.
|
||||||
|
*/
|
||||||
public static final String SET = "Set";
|
public static final String SET = "Set";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for hash set.
|
||||||
|
*/
|
||||||
public static final String HASH_SET = "HashSet";
|
public static final String HASH_SET = "HashSet";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for abstract set.
|
||||||
|
*/
|
||||||
public static final String ABSTRACT_SET = "AbstractSet";
|
public static final String ABSTRACT_SET = "AbstractSet";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for linked has set.
|
||||||
|
*/
|
||||||
public static final String LINKED_HASH_SET = "LinkedHashSet";
|
public static final String LINKED_HASH_SET = "LinkedHashSet";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for tree set.
|
||||||
|
*/
|
||||||
public static final String TREE_SET = "TreeSet";
|
public static final String TREE_SET = "TreeSet";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for map.
|
||||||
|
*/
|
||||||
public static final String MAP = "Map";
|
public static final String MAP = "Map";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for abstract map.
|
||||||
|
*/
|
||||||
public static final String ABSTRACT_MAP = "AbstractMap";
|
public static final String ABSTRACT_MAP = "AbstractMap";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for hash map.
|
||||||
|
*/
|
||||||
public static final String HASH_MAP = "HashMap";
|
public static final String HASH_MAP = "HashMap";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for tree map.
|
||||||
|
*/
|
||||||
public static final String TREE_MAP = "TreeMap";
|
public static final String TREE_MAP = "TreeMap";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for concurrent map.
|
||||||
|
*/
|
||||||
public static final String CONCURRENT_MAP = "ConcurrentMap";
|
public static final String CONCURRENT_MAP = "ConcurrentMap";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for eventually consistent map.
|
||||||
|
*/
|
||||||
public static final String EVENTUALLY_CONSISTENT_MAP = "EventuallyConsitentMap";
|
public static final String EVENTUALLY_CONSISTENT_MAP = "EventuallyConsitentMap";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static attribute for stack syntax.
|
||||||
|
*/
|
||||||
public static final String STACK = "stack";
|
public static final String STACK = "stack";
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,8 @@ import java.io.FileWriter;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
|
|
||||||
|
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getJavaPackageFromPackagePath;
|
||||||
|
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
|
||||||
import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION;
|
import static org.onosproject.yangutils.utils.UtilConstants.EIGHT_SPACE_INDENTATION;
|
||||||
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
|
import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
|
||||||
import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
|
import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
|
||||||
@ -31,8 +33,6 @@ import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
|
|||||||
import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
|
import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
|
||||||
import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
|
import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
|
||||||
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.addPackageInfo;
|
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.addPackageInfo;
|
||||||
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.convertPathToPkg;
|
|
||||||
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.convertPkgToPath;
|
|
||||||
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.createDirectories;
|
import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.createDirectories;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -54,7 +54,7 @@ public final class FileSystemUtil {
|
|||||||
*/
|
*/
|
||||||
public static boolean doesPackageExist(String pkg) {
|
public static boolean doesPackageExist(String pkg) {
|
||||||
|
|
||||||
File pkgDir = new File(convertPkgToPath(pkg));
|
File pkgDir = new File(getPackageDirPathFromJavaJPackage(pkg));
|
||||||
File pkgWithFile = new File(pkgDir + SLASH + "package-info.java");
|
File pkgWithFile = new File(pkgDir + SLASH + "package-info.java");
|
||||||
if (pkgDir.exists() && pkgWithFile.isFile()) {
|
if (pkgDir.exists() && pkgWithFile.isFile()) {
|
||||||
return true;
|
return true;
|
||||||
@ -74,7 +74,7 @@ public final class FileSystemUtil {
|
|||||||
if (!doesPackageExist(pkg)) {
|
if (!doesPackageExist(pkg)) {
|
||||||
try {
|
try {
|
||||||
File pack = createDirectories(pkg);
|
File pack = createDirectories(pkg);
|
||||||
addPackageInfo(pack, pkgInfo, convertPathToPkg(pkg));
|
addPackageInfo(pack, pkgInfo, getJavaPackageFromPackagePath(pkg));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new IOException("failed to create package-info file");
|
throw new IOException("failed to create package-info file");
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_SETTERS;
|
|||||||
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_SETTERS_COMMON;
|
import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_SETTERS_COMMON;
|
||||||
import static org.onosproject.yangutils.utils.UtilConstants.LIST;
|
import static org.onosproject.yangutils.utils.UtilConstants.LIST;
|
||||||
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
|
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
|
||||||
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE_ESTRIC;
|
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE_ASTERISK;
|
||||||
import static org.onosproject.yangutils.utils.UtilConstants.OBJECT;
|
import static org.onosproject.yangutils.utils.UtilConstants.OBJECT;
|
||||||
import static org.onosproject.yangutils.utils.UtilConstants.OF;
|
import static org.onosproject.yangutils.utils.UtilConstants.OF;
|
||||||
import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE_INFO_JAVADOC;
|
import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE_INFO_JAVADOC;
|
||||||
@ -141,7 +141,7 @@ public final class JavaDocGen {
|
|||||||
*/
|
*/
|
||||||
public static String getJavaDoc(JavaDocType type, String name, boolean isList) {
|
public static String getJavaDoc(JavaDocType type, String name, boolean isList) {
|
||||||
|
|
||||||
name = JavaIdentifierSyntax.getLowerCase(JavaIdentifierSyntax.getCamelCase(name));
|
name = JavaIdentifierSyntax.getSmallCase(JavaIdentifierSyntax.getCamelCase(name));
|
||||||
String javaDoc = UtilConstants.EMPTY_STRING;
|
String javaDoc = UtilConstants.EMPTY_STRING;
|
||||||
if (type.equals(JavaDocType.IMPL_CLASS)) {
|
if (type.equals(JavaDocType.IMPL_CLASS)) {
|
||||||
javaDoc = generateForImplClass(name);
|
javaDoc = generateForImplClass(name);
|
||||||
@ -183,7 +183,7 @@ public final class JavaDocGen {
|
|||||||
private static String generateForGetters(String attribute, boolean isList) {
|
private static String generateForGetters(String attribute, boolean isList) {
|
||||||
|
|
||||||
String getter = NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION
|
String getter = NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION
|
||||||
+ JAVA_DOC_GETTERS + attribute + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ESTRIC
|
+ JAVA_DOC_GETTERS + attribute + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK
|
||||||
+ FOUR_SPACE_INDENTATION + JAVA_DOC_RETURN;
|
+ FOUR_SPACE_INDENTATION + JAVA_DOC_RETURN;
|
||||||
if (isList) {
|
if (isList) {
|
||||||
String listAttribute = LIST.toLowerCase() + SPACE + OF + SPACE;
|
String listAttribute = LIST.toLowerCase() + SPACE + OF + SPACE;
|
||||||
@ -206,7 +206,7 @@ public final class JavaDocGen {
|
|||||||
private static String generateForSetters(String attribute, boolean isList) {
|
private static String generateForSetters(String attribute, boolean isList) {
|
||||||
|
|
||||||
String setter = NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION
|
String setter = NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION
|
||||||
+ JAVA_DOC_SETTERS + attribute + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ESTRIC
|
+ JAVA_DOC_SETTERS + attribute + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK
|
||||||
+ FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM + attribute + SPACE;
|
+ FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM + attribute + SPACE;
|
||||||
if (isList) {
|
if (isList) {
|
||||||
String listAttribute = LIST.toLowerCase() + SPACE + OF + SPACE;
|
String listAttribute = LIST.toLowerCase() + SPACE + OF + SPACE;
|
||||||
@ -228,7 +228,7 @@ public final class JavaDocGen {
|
|||||||
private static String generateForOf(String attribute) {
|
private static String generateForOf(String attribute) {
|
||||||
|
|
||||||
return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_OF
|
return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_OF
|
||||||
+ attribute + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ESTRIC + FOUR_SPACE_INDENTATION
|
+ attribute + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK + FOUR_SPACE_INDENTATION
|
||||||
+ JAVA_DOC_PARAM + VALUE + SPACE + VALUE + SPACE + OF + SPACE + attribute + NEW_LINE
|
+ JAVA_DOC_PARAM + VALUE + SPACE + VALUE + SPACE + OF + SPACE + attribute + NEW_LINE
|
||||||
+ FOUR_SPACE_INDENTATION + JAVA_DOC_RETURN + OBJECT + SPACE + OF + SPACE + attribute + NEW_LINE
|
+ FOUR_SPACE_INDENTATION + JAVA_DOC_RETURN + OBJECT + SPACE + OF + SPACE + attribute + NEW_LINE
|
||||||
+ FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
|
+ FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
|
||||||
@ -243,7 +243,7 @@ public final class JavaDocGen {
|
|||||||
private static String generateForTypeDefSetter(String attribute) {
|
private static String generateForTypeDefSetter(String attribute) {
|
||||||
|
|
||||||
return (NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION
|
return (NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION
|
||||||
+ JAVA_DOC_SETTERS_COMMON + attribute + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ESTRIC
|
+ JAVA_DOC_SETTERS_COMMON + attribute + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK
|
||||||
+ FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM + VALUE + SPACE + VALUE + SPACE + OF + SPACE + attribute
|
+ FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM + VALUE + SPACE + VALUE + SPACE + OF + SPACE + attribute
|
||||||
+ NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE);
|
+ NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE);
|
||||||
}
|
}
|
||||||
@ -257,7 +257,7 @@ public final class JavaDocGen {
|
|||||||
private static String generateForTypeDefConstructor(String attribute) {
|
private static String generateForTypeDefConstructor(String attribute) {
|
||||||
|
|
||||||
return (NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_CONSTRUCTOR
|
return (NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_CONSTRUCTOR
|
||||||
+ attribute + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ESTRIC + FOUR_SPACE_INDENTATION
|
+ attribute + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK + FOUR_SPACE_INDENTATION
|
||||||
+ JAVA_DOC_PARAM + VALUE + SPACE + VALUE + SPACE + OF + SPACE + attribute + NEW_LINE
|
+ JAVA_DOC_PARAM + VALUE + SPACE + VALUE + SPACE + OF + SPACE + attribute + NEW_LINE
|
||||||
+ FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE);
|
+ FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE);
|
||||||
}
|
}
|
||||||
@ -341,8 +341,8 @@ public final class JavaDocGen {
|
|||||||
|
|
||||||
return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE
|
return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE
|
||||||
+ FOUR_SPACE_INDENTATION + JAVA_DOC_CONSTRUCTOR + className + IMPL + PERIOD + NEW_LINE
|
+ FOUR_SPACE_INDENTATION + JAVA_DOC_CONSTRUCTOR + className + IMPL + PERIOD + NEW_LINE
|
||||||
+ FOUR_SPACE_INDENTATION + NEW_LINE_ESTRIC + FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM
|
+ FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK + FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM
|
||||||
+ BUILDER.toLowerCase() + OBJECT + SPACE + BUILDER_OBJECT + SPACE + className + NEW_LINE
|
+ BUILDER.toLowerCase() + OBJECT + SPACE + BUILDER_OBJECT + className + NEW_LINE
|
||||||
+ FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
|
+ FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -355,7 +355,7 @@ public final class JavaDocGen {
|
|||||||
private static String generateForBuild(String buildName) {
|
private static String generateForBuild(String buildName) {
|
||||||
|
|
||||||
return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_BUILD
|
return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_BUILD
|
||||||
+ buildName + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ESTRIC + FOUR_SPACE_INDENTATION
|
+ buildName + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK + FOUR_SPACE_INDENTATION
|
||||||
+ JAVA_DOC_RETURN + JAVA_DOC_BUILD_RETURN + buildName + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION
|
+ JAVA_DOC_RETURN + JAVA_DOC_BUILD_RETURN + buildName + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION
|
||||||
+ JAVA_DOC_END_LINE;
|
+ JAVA_DOC_END_LINE;
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ public final class YangFileScanner {
|
|||||||
* @throws IOException when files get deleted while performing the
|
* @throws IOException when files get deleted while performing the
|
||||||
* operations
|
* operations
|
||||||
*/
|
*/
|
||||||
public static List<String> getJavaFiles(String root) throws NullPointerException, IOException {
|
public static List<String> getJavaFiles(String root) throws IOException {
|
||||||
|
|
||||||
return getFiles(root, JAVA_FILE_EXTENTION);
|
return getFiles(root, JAVA_FILE_EXTENTION);
|
||||||
}
|
}
|
||||||
@ -59,7 +59,7 @@ public final class YangFileScanner {
|
|||||||
* @throws IOException when files get deleted while performing the
|
* @throws IOException when files get deleted while performing the
|
||||||
* operations
|
* operations
|
||||||
*/
|
*/
|
||||||
public static List<String> getYangFiles(String root) throws NullPointerException, IOException {
|
public static List<String> getYangFiles(String root) throws IOException {
|
||||||
|
|
||||||
return getFiles(root, YANG_FILE_EXTENTION);
|
return getFiles(root, YANG_FILE_EXTENTION);
|
||||||
}
|
}
|
||||||
@ -73,7 +73,7 @@ public final class YangFileScanner {
|
|||||||
* @throws NullPointerException when no file is there
|
* @throws NullPointerException when no file is there
|
||||||
* @throws IOException when files get deleted while performing the operations
|
* @throws IOException when files get deleted while performing the operations
|
||||||
*/
|
*/
|
||||||
public static List<String> getFiles(String root, String extension) throws NullPointerException, IOException {
|
public static List<String> getFiles(String root, String extension) throws IOException {
|
||||||
|
|
||||||
List<String> store = new LinkedList<>();
|
List<String> store = new LinkedList<>();
|
||||||
Stack<String> stack = new Stack<>();
|
Stack<String> stack = new Stack<>();
|
||||||
@ -100,8 +100,8 @@ public final class YangFileScanner {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return store;
|
return store;
|
||||||
} catch (NullPointerException e) {
|
} catch (IOException e) {
|
||||||
throw new IOException("NullPointerException occured");
|
throw new IOException("No File found of " + extension + " extension in " + root + " directory.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,6 @@ import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
|
|||||||
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
|
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
|
||||||
import static org.onosproject.yangutils.utils.UtilConstants.ORG;
|
import static org.onosproject.yangutils.utils.UtilConstants.ORG;
|
||||||
import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE;
|
import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE;
|
||||||
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
|
|
||||||
import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
|
import static org.onosproject.yangutils.utils.UtilConstants.SEMI_COLAN;
|
||||||
import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
|
import static org.onosproject.yangutils.utils.UtilConstants.SLASH;
|
||||||
import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
|
import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
|
||||||
@ -294,26 +293,4 @@ public final class YangIoUtils {
|
|||||||
throw new IOException("Failed to insert in " + file + "file");
|
throw new IOException("Failed to insert in " + file + "file");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert directory path in java package format.
|
|
||||||
*
|
|
||||||
* @param path directory path
|
|
||||||
* @return java package
|
|
||||||
*/
|
|
||||||
public static String convertPathToPkg(String path) {
|
|
||||||
|
|
||||||
return path.replace(SLASH, PERIOD);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert java package in directory path format.
|
|
||||||
*
|
|
||||||
* @param pkg java package
|
|
||||||
* @return directory path
|
|
||||||
*/
|
|
||||||
public static String convertPkgToPath(String pkg) {
|
|
||||||
|
|
||||||
return pkg.replace(PERIOD, SLASH);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -16,24 +16,39 @@
|
|||||||
|
|
||||||
package org.onosproject.yangutils.translator.tojava.utils;
|
package org.onosproject.yangutils.translator.tojava.utils;
|
||||||
|
|
||||||
import static org.hamcrest.core.Is.is;
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType;
|
|
||||||
import org.onosproject.yangutils.translator.tojava.GeneratedMethodTypes;
|
import static org.hamcrest.core.Is.is;
|
||||||
import org.onosproject.yangutils.translator.tojava.TraversalType;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import org.onosproject.yangutils.utils.UtilConstants;
|
import static org.junit.Assert.assertThat;
|
||||||
|
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_CLASS_MASK;
|
||||||
|
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.BUILDER_INTERFACE_MASK;
|
||||||
|
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS;
|
||||||
|
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.IMPL_CLASS_MASK;
|
||||||
|
import static org.onosproject.yangutils.translator.tojava.GeneratedJavaFileType.INTERFACE_MASK;
|
||||||
|
import static org.onosproject.yangutils.translator.tojava.utils.ClassDefinitionGenerator.generateClassDefinition;
|
||||||
|
import static org.onosproject.yangutils.utils.UtilConstants.BUILDER;
|
||||||
|
import static org.onosproject.yangutils.utils.UtilConstants.CLASS;
|
||||||
|
import static org.onosproject.yangutils.utils.UtilConstants.FINAL;
|
||||||
|
import static org.onosproject.yangutils.utils.UtilConstants.IMPL;
|
||||||
|
import static org.onosproject.yangutils.utils.UtilConstants.IMPLEMENTS;
|
||||||
|
import static org.onosproject.yangutils.utils.UtilConstants.INTERFACE;
|
||||||
|
import static org.onosproject.yangutils.utils.UtilConstants.NEW_LINE;
|
||||||
|
import static org.onosproject.yangutils.utils.UtilConstants.OPEN_CURLY_BRACKET;
|
||||||
|
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
|
||||||
|
import static org.onosproject.yangutils.utils.UtilConstants.PUBLIC;
|
||||||
|
import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for class definition generator for generated files.
|
* Unit tests for class definition generator for generated files.
|
||||||
*/
|
*/
|
||||||
public final class ClassDefinitionGeneratorTest {
|
public final class ClassDefinitionGeneratorTest {
|
||||||
|
|
||||||
|
private static final String CLASS_NAME = "testclass";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit test for private constructor.
|
* Unit test for private constructor.
|
||||||
*
|
*
|
||||||
@ -62,10 +77,10 @@ public final class ClassDefinitionGeneratorTest {
|
|||||||
@Test
|
@Test
|
||||||
public void generateBuilderClassDefinitionTest() {
|
public void generateBuilderClassDefinitionTest() {
|
||||||
|
|
||||||
String builderClassDefinition = ClassDefinitionGenerator
|
String builderClassDefinition = generateClassDefinition(BUILDER_CLASS_MASK, CLASS_NAME);
|
||||||
.generateClassDefinition(GeneratedJavaFileType.BUILDER_CLASS_MASK, "BuilderClass");
|
assertThat(true, is(builderClassDefinition.equals(
|
||||||
assertThat(true, is(builderClassDefinition.contains(UtilConstants.BUILDER)));
|
PUBLIC + SPACE + CLASS + SPACE + CLASS_NAME + BUILDER + SPACE + IMPLEMENTS + SPACE + CLASS_NAME + PERIOD
|
||||||
assertThat(true, is(builderClassDefinition.contains(UtilConstants.CLASS)));
|
+ CLASS_NAME + BUILDER + SPACE + OPEN_CURLY_BRACKET + NEW_LINE)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -74,9 +89,9 @@ public final class ClassDefinitionGeneratorTest {
|
|||||||
@Test
|
@Test
|
||||||
public void generateBuilderInterfaceDefinitionTest() {
|
public void generateBuilderInterfaceDefinitionTest() {
|
||||||
|
|
||||||
String builderInterfaceDefinition = ClassDefinitionGenerator
|
String builderInterfaceDefinition = generateClassDefinition(BUILDER_INTERFACE_MASK, CLASS_NAME);
|
||||||
.generateClassDefinition(GeneratedJavaFileType.BUILDER_INTERFACE_MASK, "BuilderInterfaceClass");
|
assertThat(true, is(builderInterfaceDefinition
|
||||||
assertThat(true, is(builderInterfaceDefinition.contains(UtilConstants.BUILDER)));
|
.equals(INTERFACE + SPACE + CLASS_NAME + BUILDER + SPACE + OPEN_CURLY_BRACKET + NEW_LINE + NEW_LINE)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -85,9 +100,10 @@ public final class ClassDefinitionGeneratorTest {
|
|||||||
@Test
|
@Test
|
||||||
public void generateImplDefinitionTest() {
|
public void generateImplDefinitionTest() {
|
||||||
|
|
||||||
String implDefinition = ClassDefinitionGenerator.generateClassDefinition(GeneratedJavaFileType.IMPL_CLASS_MASK,
|
String implDefinition = generateClassDefinition(IMPL_CLASS_MASK, CLASS_NAME);
|
||||||
"ImplClass");
|
assertThat(true, is(implDefinition.equals(
|
||||||
assertThat(true, is(implDefinition.contains(UtilConstants.IMPL)));
|
PUBLIC + SPACE + FINAL + SPACE + CLASS + SPACE + CLASS_NAME + IMPL + SPACE + IMPLEMENTS + SPACE
|
||||||
|
+ CLASS_NAME + SPACE + OPEN_CURLY_BRACKET + NEW_LINE)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -96,10 +112,9 @@ public final class ClassDefinitionGeneratorTest {
|
|||||||
@Test
|
@Test
|
||||||
public void generateinterfaceDefinitionTest() {
|
public void generateinterfaceDefinitionTest() {
|
||||||
|
|
||||||
String interfaceDefinition = ClassDefinitionGenerator.generateClassDefinition(
|
String interfaceDefinition = generateClassDefinition(INTERFACE_MASK, CLASS_NAME);
|
||||||
GeneratedJavaFileType.INTERFACE_MASK,
|
assertThat(true, is(interfaceDefinition
|
||||||
"InterfaceClass");
|
.equals(PUBLIC + SPACE + INTERFACE + SPACE + CLASS_NAME + SPACE + OPEN_CURLY_BRACKET + NEW_LINE)));
|
||||||
assertThat(true, is(interfaceDefinition.contains(UtilConstants.INTERFACE)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -108,19 +123,8 @@ public final class ClassDefinitionGeneratorTest {
|
|||||||
@Test
|
@Test
|
||||||
public void generateTypeDefTest() {
|
public void generateTypeDefTest() {
|
||||||
|
|
||||||
String typeDef = ClassDefinitionGenerator.generateClassDefinition(GeneratedJavaFileType.GENERATE_TYPEDEF_CLASS,
|
String typeDef = generateClassDefinition(GENERATE_TYPEDEF_CLASS, CLASS_NAME);
|
||||||
"invalid");
|
assertThat(true, is(typeDef.equals(
|
||||||
assertThat(true, is(typeDef.contains(UtilConstants.CLASS)));
|
PUBLIC + SPACE + FINAL + SPACE + CLASS + SPACE + CLASS_NAME + SPACE + OPEN_CURLY_BRACKET + NEW_LINE)));
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Unit test for enum data types.
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void enumDataTypesTest() {
|
|
||||||
|
|
||||||
TraversalType.valueOf(TraversalType.CHILD.toString());
|
|
||||||
GeneratedMethodTypes.valueOf(GeneratedMethodTypes.CONSTRUCTOR.toString());
|
|
||||||
TempDataStoreTypes.valueOf(TempDataStoreTypes.CONSTRUCTOR.toString());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,38 +16,47 @@
|
|||||||
|
|
||||||
package org.onosproject.yangutils.translator.tojava.utils;
|
package org.onosproject.yangutils.translator.tojava.utils;
|
||||||
|
|
||||||
import static org.hamcrest.core.Is.is;
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.onosproject.yangutils.utils.UtilConstants;
|
|
||||||
|
import static org.hamcrest.core.Is.is;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCamelCase;
|
||||||
|
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getCaptialCase;
|
||||||
|
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getJavaPackageFromPackagePath;
|
||||||
|
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getPackageDirPathFromJavaJPackage;
|
||||||
|
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage;
|
||||||
|
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getSmallCase;
|
||||||
|
import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getYangRevisionStr;
|
||||||
|
import static org.onosproject.yangutils.utils.UtilConstants.DEFAULT_BASE_PKG;
|
||||||
|
import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for java identifier syntax.
|
* Unit tests for java identifier syntax.
|
||||||
*/
|
*/
|
||||||
public final class JavaIdentifierSyntaxTest {
|
public final class JavaIdentifierSyntaxTest {
|
||||||
|
|
||||||
public static final String PARENT_PACKAGE = "test5.test6.test7";
|
private static final String PARENT_PACKAGE = "test5/test6/test7";
|
||||||
public static final String CHILD_PACKAGE = "test1:test2:test3";
|
private static final String CHILD_PACKAGE = "test1:test2:test3";
|
||||||
public static final String DATE1 = "2000-1-5";
|
private static final String DATE1 = "2000-1-5";
|
||||||
public static final String DATE2 = "1992-01-25";
|
private static final String DATE2 = "1992-01-25";
|
||||||
public static final String PARENT_WITH_PERIOD = "test5.test6.test7";
|
private static final String PARENT_WITH_PERIOD = "test5.test6.test7";
|
||||||
public static final String CHILD_WITH_PERIOD = "test1.test2.test3";
|
private static final String CHILD_WITH_PERIOD = "test1.test2.test3";
|
||||||
public static final String DATE_WITH_REV1 = "rev20000105";
|
private static final String DATE_WITH_REV1 = "rev20000105";
|
||||||
public static final String DATE_WITH_REV2 = "rev19920125";
|
private static final String DATE_WITH_REV2 = "rev19920125";
|
||||||
public static final String VERSION_NUMBER = "v1";
|
private static final String VERSION_NUMBER = "v1";
|
||||||
public static final String INVALID_NAME_SPACE1 = "byte:#test2:9test3";
|
private static final String INVALID_NAME_SPACE1 = "byte:#test2:9test3";
|
||||||
public static final String INVALID_NAME_SPACE2 = "const:#test2://9test3";
|
private static final String INVALID_NAME_SPACE2 = "const:#test2://9test3";
|
||||||
public static final String VALID_NAME_SPACE1 = "_byte.test2._9test3";
|
private static final String VALID_NAME_SPACE1 = "_byte.test2._9test3";
|
||||||
public static final String VALID_NAME_SPACE2 = "_const.test2._9test3";
|
private static final String VALID_NAME_SPACE2 = "_const.test2._9test3";
|
||||||
public static final String WITHOUT_CAMEL_CASE = "test-camel-case-identifier";
|
private static final String WITHOUT_CAMEL_CASE = "test-camel-case-identifier";
|
||||||
public static final String WITH_CAMEL_CASE = "testCamelCaseIdentifier";
|
private static final String WITH_CAMEL_CASE = "testCamelCaseIdentifier";
|
||||||
public static final String WITHOUT_CAPITAL = "test_this";
|
private static final String WITHOUT_CAPITAL = "test_this";
|
||||||
public static final String WITH_CAPITAL = "Test_this";
|
private static final String WITH_CAPITAL = "Test_this";
|
||||||
|
private static final String WITH_SMALL = "test_this";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit test for private constructor.
|
* Unit test for private constructor.
|
||||||
@ -65,6 +74,7 @@ public final class JavaIdentifierSyntaxTest {
|
|||||||
@Test
|
@Test
|
||||||
public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException,
|
public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException,
|
||||||
InstantiationException, IllegalAccessException, InvocationTargetException {
|
InstantiationException, IllegalAccessException, InvocationTargetException {
|
||||||
|
|
||||||
Class<?>[] classesToConstruct = {JavaIdentifierSyntax.class };
|
Class<?>[] classesToConstruct = {JavaIdentifierSyntax.class };
|
||||||
for (Class<?> clazz : classesToConstruct) {
|
for (Class<?> clazz : classesToConstruct) {
|
||||||
Constructor<?> constructor = clazz.getDeclaredConstructor();
|
Constructor<?> constructor = clazz.getDeclaredConstructor();
|
||||||
@ -79,9 +89,9 @@ public final class JavaIdentifierSyntaxTest {
|
|||||||
@Test
|
@Test
|
||||||
public void getRootPackageTest() {
|
public void getRootPackageTest() {
|
||||||
|
|
||||||
String rootPackage = JavaIdentifierSyntax.getRootPackage((byte) 1, CHILD_PACKAGE, DATE1);
|
String rootPackage = getRootPackage((byte) 1, CHILD_PACKAGE, DATE1);
|
||||||
assertThat(rootPackage.equals(UtilConstants.DEFAULT_BASE_PKG + UtilConstants.PERIOD + VERSION_NUMBER
|
assertThat(rootPackage.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER
|
||||||
+ UtilConstants.PERIOD + CHILD_WITH_PERIOD + UtilConstants.PERIOD + DATE_WITH_REV1), is(true));
|
+ PERIOD + CHILD_WITH_PERIOD + PERIOD + DATE_WITH_REV1), is(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -90,12 +100,12 @@ public final class JavaIdentifierSyntaxTest {
|
|||||||
@Test
|
@Test
|
||||||
public void getRootPackageWithSpecialCharactersTest() {
|
public void getRootPackageWithSpecialCharactersTest() {
|
||||||
|
|
||||||
String rootPackage = JavaIdentifierSyntax.getRootPackage((byte) 1, INVALID_NAME_SPACE1, DATE1);
|
String rootPackage = getRootPackage((byte) 1, INVALID_NAME_SPACE1, DATE1);
|
||||||
assertThat(rootPackage.equals(UtilConstants.DEFAULT_BASE_PKG + UtilConstants.PERIOD + VERSION_NUMBER
|
assertThat(rootPackage.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER
|
||||||
+ UtilConstants.PERIOD + VALID_NAME_SPACE1 + UtilConstants.PERIOD + DATE_WITH_REV1), is(true));
|
+ PERIOD + VALID_NAME_SPACE1 + PERIOD + DATE_WITH_REV1), is(true));
|
||||||
String rootPackage1 = JavaIdentifierSyntax.getRootPackage((byte) 1, INVALID_NAME_SPACE2, DATE1);
|
String rootPackage1 = getRootPackage((byte) 1, INVALID_NAME_SPACE2, DATE1);
|
||||||
assertThat(rootPackage1.equals(UtilConstants.DEFAULT_BASE_PKG + UtilConstants.PERIOD + VERSION_NUMBER
|
assertThat(rootPackage1.equals(DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER
|
||||||
+ UtilConstants.PERIOD + VALID_NAME_SPACE2 + UtilConstants.PERIOD + DATE_WITH_REV1), is(true));
|
+ PERIOD + VALID_NAME_SPACE2 + PERIOD + DATE_WITH_REV1), is(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -104,9 +114,9 @@ public final class JavaIdentifierSyntaxTest {
|
|||||||
@Test
|
@Test
|
||||||
public void getRootPackageWithRevTest() {
|
public void getRootPackageWithRevTest() {
|
||||||
|
|
||||||
String rootPkgWithRev = JavaIdentifierSyntax.getRootPackage((byte) 1, CHILD_PACKAGE, DATE2);
|
String rootPkgWithRev = getRootPackage((byte) 1, CHILD_PACKAGE, DATE2);
|
||||||
assertThat(rootPkgWithRev.equals(UtilConstants.DEFAULT_BASE_PKG + UtilConstants.PERIOD
|
assertThat(rootPkgWithRev.equals(
|
||||||
+ VERSION_NUMBER + UtilConstants.PERIOD + CHILD_WITH_PERIOD + UtilConstants.PERIOD + DATE_WITH_REV2),
|
DEFAULT_BASE_PKG + PERIOD + VERSION_NUMBER + PERIOD + CHILD_WITH_PERIOD + PERIOD + DATE_WITH_REV2),
|
||||||
is(true));
|
is(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,7 +126,7 @@ public final class JavaIdentifierSyntaxTest {
|
|||||||
@Test
|
@Test
|
||||||
public void getCapitalCaseTest() {
|
public void getCapitalCaseTest() {
|
||||||
|
|
||||||
String capitalCase = JavaIdentifierSyntax.getCaptialCase(WITHOUT_CAPITAL);
|
String capitalCase = getCaptialCase(WITHOUT_CAPITAL);
|
||||||
assertThat(capitalCase.equals(WITH_CAPITAL), is(true));
|
assertThat(capitalCase.equals(WITH_CAPITAL), is(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,7 +135,48 @@ public final class JavaIdentifierSyntaxTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void getCamelCaseTest() {
|
public void getCamelCaseTest() {
|
||||||
String camelCase = JavaIdentifierSyntax.getCamelCase(WITHOUT_CAMEL_CASE);
|
|
||||||
|
String camelCase = getCamelCase(WITHOUT_CAMEL_CASE);
|
||||||
assertThat(camelCase.equals(WITH_CAMEL_CASE), is(true));
|
assertThat(camelCase.equals(WITH_CAMEL_CASE), is(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unit test for getting the camel case for the received string.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void getSmallCaseTest() {
|
||||||
|
|
||||||
|
String smallCase = getSmallCase(WITHOUT_CAPITAL);
|
||||||
|
assertThat(smallCase.equals(WITH_SMALL), is(true));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unit test for getting the camel case for the received string.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void getPackageFromPathTest() {
|
||||||
|
|
||||||
|
String pkg = getJavaPackageFromPackagePath(PARENT_PACKAGE);
|
||||||
|
assertThat(pkg.equals(PARENT_WITH_PERIOD), is(true));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unit test for getting the camel case for the received string.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void getPathFromPackageTest() {
|
||||||
|
|
||||||
|
String path = getPackageDirPathFromJavaJPackage(PARENT_WITH_PERIOD);
|
||||||
|
assertThat(path.equals(PARENT_PACKAGE), is(true));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unit test for getting the camel case for the received string.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void getYangRevTest() {
|
||||||
|
|
||||||
|
String rev = getYangRevisionStr(DATE1);
|
||||||
|
assertThat(rev.equals(DATE_WITH_REV1), is(true));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,20 +16,20 @@
|
|||||||
|
|
||||||
package org.onosproject.yangutils.utils.io.impl;
|
package org.onosproject.yangutils.utils.io.impl;
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
|
import org.junit.Rule;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.rules.ExpectedException;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.slf4j.LoggerFactory.getLogger;
|
import static org.slf4j.LoggerFactory.getLogger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -56,7 +56,7 @@ public final class YangFileScannerTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException,
|
public void callPrivateConstructors() throws SecurityException, NoSuchMethodException, IllegalArgumentException,
|
||||||
InstantiationException, IllegalAccessException, InvocationTargetException {
|
InstantiationException, IllegalAccessException, InvocationTargetException {
|
||||||
|
|
||||||
Class<?>[] classesToConstruct = {YangFileScanner.class };
|
Class<?>[] classesToConstruct = {YangFileScanner.class };
|
||||||
for (Class<?> clazz : classesToConstruct) {
|
for (Class<?> clazz : classesToConstruct) {
|
||||||
@ -151,17 +151,16 @@ public final class YangFileScannerTest {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This test case checks with the sub directories in the given path for java files.
|
* This test case checks with the sub directories in the given path for java files.
|
||||||
*/
|
|
||||||
@Test
|
@Test
|
||||||
public void exceptionHandleTest() throws IOException {
|
public void exceptionHandleTest() throws IOException {
|
||||||
|
|
||||||
String dir = baseDir + File.separator + "scanner4";
|
String dir = baseDir + File.separator + "scanner4";
|
||||||
thrown.expect(IOException.class);
|
thrown.expect(IOException.class);
|
||||||
thrown.expectMessage("NullPointerException occured");
|
|
||||||
List<String> invalidContents = YangFileScanner.getJavaFiles(dir);
|
List<String> invalidContents = YangFileScanner.getJavaFiles(dir);
|
||||||
File path = createDirectory(dir);
|
File path = createDirectory(dir);
|
||||||
createFile(path, "except.java");
|
createFile(path, "except.java");
|
||||||
List<String> dirWithFileName = YangFileScanner
|
List<String> dirWithFileName = YangFileScanner
|
||||||
.getJavaFiles(path + File.separator + "except.java" + File.separator + "scanner5");
|
.getJavaFiles(path + File.separator + "except.java" + File.separator + "scanner5");
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user