Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 0f7908b | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 17 | package org.onosproject.yangutils.translator.tojava.javamodel; |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 18 | |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 19 | import java.util.Stack; |
Bharat saraswal | e3175d3 | 2016-08-31 17:50:11 +0530 | [diff] [blame] | 20 | |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 21 | import org.onosproject.yangutils.datamodel.YangDerivedInfo; |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 22 | import org.onosproject.yangutils.datamodel.YangEnumeration; |
Shankara-Huawei | 234cd09 | 2016-07-14 11:35:34 +0530 | [diff] [blame] | 23 | import org.onosproject.yangutils.datamodel.YangIdentity; |
Shankara-Huawei | 234cd09 | 2016-07-14 11:35:34 +0530 | [diff] [blame] | 24 | import org.onosproject.yangutils.datamodel.YangIdentityRef; |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 25 | import org.onosproject.yangutils.datamodel.YangLeafRef; |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 26 | import org.onosproject.yangutils.datamodel.YangNode; |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 27 | import org.onosproject.yangutils.datamodel.YangType; |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 28 | import org.onosproject.yangutils.datamodel.YangUnion; |
janani b | 0e4e8ae | 2016-07-13 21:06:41 +0530 | [diff] [blame] | 29 | import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangDataTypes; |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 30 | import org.onosproject.yangutils.translator.exception.TranslatorException; |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 31 | import org.onosproject.yangutils.translator.tojava.JavaCodeGeneratorInfo; |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 32 | import org.onosproject.yangutils.translator.tojava.JavaFileInfoContainer; |
Gaurav Agrawal | e5057f0 | 2016-08-22 17:14:33 +0530 | [diff] [blame] | 33 | import org.onosproject.yangutils.translator.tojava.JavaFileInfoTranslator; |
| 34 | import org.onosproject.yangutils.utils.io.YangToJavaNamingConflictUtil; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 35 | |
Bharat saraswal | af413b8 | 2016-07-14 15:18:20 +0530 | [diff] [blame] | 36 | import static org.onosproject.yangutils.translator.tojava.YangJavaModelUtils.getCurNodePackage; |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 37 | import static org.onosproject.yangutils.translator.tojava.utils.JavaIdentifierSyntax.getRootPackage; |
Mahesh Poojary Huawei | 2cd4433 | 2016-07-14 12:38:17 +0530 | [diff] [blame] | 38 | import static org.onosproject.yangutils.utils.UtilConstants.BIG_DECIMAL; |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 39 | import static org.onosproject.yangutils.utils.UtilConstants.BIG_INTEGER; |
Mahesh Poojary Huawei | 2cd4433 | 2016-07-14 12:38:17 +0530 | [diff] [blame] | 40 | import static org.onosproject.yangutils.utils.UtilConstants.BIT_SET; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 41 | import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_DATA_TYPE; |
| 42 | import static org.onosproject.yangutils.utils.UtilConstants.BOOLEAN_WRAPPER; |
| 43 | import static org.onosproject.yangutils.utils.UtilConstants.BYTE; |
| 44 | import static org.onosproject.yangutils.utils.UtilConstants.BYTE_WRAPPER; |
Mahesh Poojary Huawei | 2cd4433 | 2016-07-14 12:38:17 +0530 | [diff] [blame] | 45 | import static org.onosproject.yangutils.utils.UtilConstants.COLLECTION_IMPORTS; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 46 | import static org.onosproject.yangutils.utils.UtilConstants.INT; |
| 47 | import static org.onosproject.yangutils.utils.UtilConstants.INTEGER_WRAPPER; |
| 48 | import static org.onosproject.yangutils.utils.UtilConstants.JAVA_LANG; |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 49 | import static org.onosproject.yangutils.utils.UtilConstants.JAVA_MATH; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 50 | import static org.onosproject.yangutils.utils.UtilConstants.LONG; |
| 51 | import static org.onosproject.yangutils.utils.UtilConstants.LONG_WRAPPER; |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 52 | import static org.onosproject.yangutils.utils.UtilConstants.PERIOD; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 53 | import static org.onosproject.yangutils.utils.UtilConstants.SHORT; |
| 54 | import static org.onosproject.yangutils.utils.UtilConstants.SHORT_WRAPPER; |
Mahesh Poojary Huawei | 2cd4433 | 2016-07-14 12:38:17 +0530 | [diff] [blame] | 55 | import static org.onosproject.yangutils.utils.UtilConstants.SQUARE_BRACKETS; |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 56 | import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE; |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 57 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCamelCase; |
| 58 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getCapitalCase; |
| 59 | import static org.onosproject.yangutils.utils.io.impl.YangIoUtils.getPackageDirPathFromJavaJPackage; |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 60 | |
| 61 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 62 | * Represents java data types info corresponding to YANG type. |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 63 | */ |
| 64 | public final class AttributesJavaDataType { |
| 65 | |
| 66 | /** |
Bharat saraswal | 63f26fb | 2016-04-05 15:13:44 +0530 | [diff] [blame] | 67 | * Creates an instance of attribute java data type. |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 68 | */ |
| 69 | private AttributesJavaDataType() { |
| 70 | } |
| 71 | |
| 72 | /** |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 73 | * Returns java type. |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 74 | * |
| 75 | * @param yangType YANG type |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 76 | * @return java type |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 77 | */ |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 78 | public static String getJavaDataType(YangType<?> yangType) { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 79 | |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 80 | YangDataTypes type = yangType.getDataType(); |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 81 | |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 82 | switch (type) { |
| 83 | case INT8: |
| 84 | return BYTE; |
| 85 | case INT16: |
| 86 | return SHORT; |
| 87 | case INT32: |
| 88 | return INT; |
| 89 | case INT64: |
| 90 | return LONG; |
| 91 | case UINT8: |
| 92 | return SHORT; |
| 93 | case UINT16: |
| 94 | return INT; |
| 95 | case UINT32: |
| 96 | return LONG; |
| 97 | case UINT64: |
| 98 | return BIG_INTEGER; |
Mahesh Poojary Huawei | 2cd4433 | 2016-07-14 12:38:17 +0530 | [diff] [blame] | 99 | case BITS: |
| 100 | return BIT_SET; |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 101 | case BINARY: |
Mahesh Poojary Huawei | 2cd4433 | 2016-07-14 12:38:17 +0530 | [diff] [blame] | 102 | return BYTE + SQUARE_BRACKETS; |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 103 | case DECIMAL64: |
Mahesh Poojary Huawei | 2cd4433 | 2016-07-14 12:38:17 +0530 | [diff] [blame] | 104 | return BIG_DECIMAL; |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 105 | case STRING: |
| 106 | return STRING_DATA_TYPE; |
| 107 | case BOOLEAN: |
| 108 | return BOOLEAN_DATA_TYPE; |
janani b | 0e4e8ae | 2016-07-13 21:06:41 +0530 | [diff] [blame] | 109 | case INSTANCE_IDENTIFIER: |
| 110 | return STRING_DATA_TYPE; |
| 111 | case LEAFREF: |
| 112 | return getJavaDataType(getReferredTypeFromLeafref(yangType)); |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 113 | default: |
Bharat saraswal | e3175d3 | 2016-08-31 17:50:11 +0530 | [diff] [blame] | 114 | throw new TranslatorException("given data type is not supported. " + |
| 115 | yangType.getDataTypeName() + " in " + |
| 116 | yangType.getLineNumber() + " at " + |
| 117 | yangType.getCharPosition() |
| 118 | + " in " + yangType.getFileName()); |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 119 | } |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 120 | } |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 121 | |
| 122 | /** |
| 123 | * Returns java import class. |
| 124 | * |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 125 | * @param yangType YANG type |
| 126 | * @param isListAttr if the attribute need to be a list |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 127 | * @param pluginConfig plugin configurations |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 128 | * @return java import class |
| 129 | */ |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 130 | public static String getJavaImportClass(YangType<?> yangType, boolean isListAttr, |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 131 | YangToJavaNamingConflictUtil pluginConfig) { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 132 | |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 133 | YangDataTypes type = yangType.getDataType(); |
| 134 | |
| 135 | if (isListAttr) { |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 136 | switch (type) { |
| 137 | case INT8: |
| 138 | return BYTE_WRAPPER; |
| 139 | case INT16: |
| 140 | return SHORT_WRAPPER; |
| 141 | case INT32: |
| 142 | return INTEGER_WRAPPER; |
| 143 | case INT64: |
| 144 | return LONG_WRAPPER; |
| 145 | case UINT8: |
| 146 | return SHORT_WRAPPER; |
| 147 | case UINT16: |
| 148 | return INTEGER_WRAPPER; |
| 149 | case UINT32: |
| 150 | return LONG_WRAPPER; |
| 151 | case UINT64: |
| 152 | return BIG_INTEGER; |
| 153 | case DECIMAL64: |
Mahesh Poojary Huawei | 2cd4433 | 2016-07-14 12:38:17 +0530 | [diff] [blame] | 154 | return BIG_DECIMAL; |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 155 | case STRING: |
| 156 | return STRING_DATA_TYPE; |
| 157 | case BOOLEAN: |
| 158 | return BOOLEAN_WRAPPER; |
| 159 | case ENUMERATION: |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 160 | return getCapitalCase( |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 161 | getCamelCase(((YangJavaEnumerationTranslator) yangType.getDataTypeExtendedInfo()).getName(), |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 162 | pluginConfig)); |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 163 | case BITS: |
Mahesh Poojary Huawei | 2cd4433 | 2016-07-14 12:38:17 +0530 | [diff] [blame] | 164 | return BIT_SET; |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 165 | case BINARY: |
Mahesh Poojary Huawei | 2cd4433 | 2016-07-14 12:38:17 +0530 | [diff] [blame] | 166 | return BYTE + SQUARE_BRACKETS; |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 167 | case LEAFREF: |
janani b | 0e4e8ae | 2016-07-13 21:06:41 +0530 | [diff] [blame] | 168 | YangType<?> referredType = getReferredTypeFromLeafref(yangType); |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 169 | return getJavaImportClass(referredType, true, pluginConfig); |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 170 | case IDENTITYREF: |
Shankara-Huawei | 234cd09 | 2016-07-14 11:35:34 +0530 | [diff] [blame] | 171 | YangIdentityRef identityRef = (YangIdentityRef) yangType.getDataTypeExtendedInfo(); |
| 172 | YangIdentity identity = identityRef.getReferredIdentity(); |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 173 | return getCapitalCase(getCamelCase(identity. |
| 174 | getName(), pluginConfig)); |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 175 | case EMPTY: |
| 176 | return BOOLEAN_WRAPPER; |
| 177 | case UNION: |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 178 | return getCapitalCase(getCamelCase(((YangJavaUnionTranslator) yangType |
| 179 | .getDataTypeExtendedInfo()).getName(), pluginConfig)); |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 180 | case INSTANCE_IDENTIFIER: |
janani b | 0e4e8ae | 2016-07-13 21:06:41 +0530 | [diff] [blame] | 181 | return STRING_DATA_TYPE; |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 182 | case DERIVED: |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 183 | return getCapitalCase( |
| 184 | getCamelCase(yangType.getDataTypeName(), pluginConfig)); |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 185 | default: |
Bharat saraswal | e3175d3 | 2016-08-31 17:50:11 +0530 | [diff] [blame] | 186 | throw new TranslatorException("given data type is not supported ." + |
| 187 | yangType.getDataTypeName() + " in " + |
| 188 | yangType.getLineNumber() + " at " + |
| 189 | yangType.getCharPosition() |
| 190 | + " in " + yangType.getFileName()); |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 191 | } |
| 192 | } else { |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 193 | switch (type) { |
| 194 | case UINT64: |
| 195 | return BIG_INTEGER; |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 196 | case STRING: |
| 197 | return STRING_DATA_TYPE; |
| 198 | case ENUMERATION: |
janani b | 703cfe4 | 2016-05-17 13:12:22 +0530 | [diff] [blame] | 199 | return getCapitalCase( |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 200 | getCamelCase(((YangJavaEnumerationTranslator) yangType.getDataTypeExtendedInfo()).getName(), |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 201 | pluginConfig)); |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 202 | case BITS: |
Mahesh Poojary Huawei | 2cd4433 | 2016-07-14 12:38:17 +0530 | [diff] [blame] | 203 | return BIT_SET; |
| 204 | case DECIMAL64: |
| 205 | return BIG_DECIMAL; |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 206 | case LEAFREF: |
janani b | 0e4e8ae | 2016-07-13 21:06:41 +0530 | [diff] [blame] | 207 | YangType<?> referredType = getReferredTypeFromLeafref(yangType); |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 208 | return getJavaImportClass(referredType, false, pluginConfig); |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 209 | case IDENTITYREF: |
Shankara-Huawei | 234cd09 | 2016-07-14 11:35:34 +0530 | [diff] [blame] | 210 | YangIdentityRef identityRef = (YangIdentityRef) yangType.getDataTypeExtendedInfo(); |
| 211 | YangIdentity identity = identityRef.getReferredIdentity(); |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 212 | return getCapitalCase(getCamelCase(identity.getName(), pluginConfig)); |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 213 | case EMPTY: |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 214 | return BOOLEAN_DATA_TYPE; |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 215 | case UNION: |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 216 | return getCapitalCase(getCamelCase(((YangJavaUnionTranslator) yangType |
| 217 | .getDataTypeExtendedInfo()).getName(), pluginConfig)); |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 218 | case INSTANCE_IDENTIFIER: |
janani b | 0e4e8ae | 2016-07-13 21:06:41 +0530 | [diff] [blame] | 219 | return STRING_DATA_TYPE; |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 220 | case DERIVED: |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 221 | return getCapitalCase( |
| 222 | getCamelCase(yangType.getDataTypeName(), pluginConfig)); |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 223 | default: |
| 224 | return null; |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 225 | } |
| 226 | } |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | /** |
| 230 | * Returns java import package. |
| 231 | * |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 232 | * @param yangType YANG type |
| 233 | * @param isListAttr if the attribute is of list type |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 234 | * @param conflictResolver object of YANG to java naming conflict util |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 235 | * @return java import package |
| 236 | */ |
Bharat saraswal | 5cd9e9c | 2016-05-26 23:48:38 +0530 | [diff] [blame] | 237 | public static String getJavaImportPackage(YangType<?> yangType, boolean isListAttr, |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 238 | YangToJavaNamingConflictUtil conflictResolver) { |
Bharat saraswal | 84366c5 | 2016-03-23 19:40:35 +0530 | [diff] [blame] | 239 | |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 240 | YangDataTypes type = yangType.getDataType(); |
| 241 | |
| 242 | if (isListAttr) { |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 243 | switch (type) { |
| 244 | case INT8: |
| 245 | case INT16: |
| 246 | case INT32: |
| 247 | case INT64: |
| 248 | case UINT8: |
| 249 | case UINT16: |
| 250 | case UINT32: |
Mahesh Poojary Huawei | 2cd4433 | 2016-07-14 12:38:17 +0530 | [diff] [blame] | 251 | case BINARY: |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 252 | case STRING: |
| 253 | case BOOLEAN: |
Bharat saraswal | 715d3fc | 2016-05-17 19:59:16 +0530 | [diff] [blame] | 254 | case EMPTY: |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 255 | return JAVA_LANG; |
| 256 | case UINT64: |
Mahesh Poojary Huawei | 2cd4433 | 2016-07-14 12:38:17 +0530 | [diff] [blame] | 257 | case DECIMAL64: |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 258 | return JAVA_MATH; |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 259 | case ENUMERATION: |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 260 | return getEnumsPackage(yangType, conflictResolver); |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 261 | case BITS: |
Mahesh Poojary Huawei | 2cd4433 | 2016-07-14 12:38:17 +0530 | [diff] [blame] | 262 | return COLLECTION_IMPORTS; |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 263 | case LEAFREF: |
janani b | 0e4e8ae | 2016-07-13 21:06:41 +0530 | [diff] [blame] | 264 | YangType<?> referredType = getReferredTypeFromLeafref(yangType); |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 265 | return getJavaImportPackage(referredType, true, conflictResolver); |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 266 | case IDENTITYREF: |
Shankara-Huawei | 234cd09 | 2016-07-14 11:35:34 +0530 | [diff] [blame] | 267 | return getIdentityRefPackage(yangType, conflictResolver); |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 268 | case UNION: |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 269 | return getUnionPackage(yangType, conflictResolver); |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 270 | case INSTANCE_IDENTIFIER: |
janani b | 0e4e8ae | 2016-07-13 21:06:41 +0530 | [diff] [blame] | 271 | return JAVA_LANG; |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 272 | case DERIVED: |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 273 | return getTypeDefsPackage(yangType, conflictResolver); |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 274 | default: |
Bharat saraswal | e3175d3 | 2016-08-31 17:50:11 +0530 | [diff] [blame] | 275 | throw new TranslatorException("given data type is not supported. " + |
| 276 | yangType.getDataTypeName() + " in " + |
| 277 | yangType.getLineNumber() + " at " + |
| 278 | yangType.getCharPosition() |
| 279 | + " in " + yangType.getFileName()); |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 280 | } |
| 281 | } else { |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 282 | switch (type) { |
| 283 | case UINT64: |
Mahesh Poojary Huawei | 2cd4433 | 2016-07-14 12:38:17 +0530 | [diff] [blame] | 284 | case DECIMAL64: |
Bharat saraswal | 250a747 | 2016-05-12 13:16:57 +0530 | [diff] [blame] | 285 | return JAVA_MATH; |
Mahesh Poojary Huawei | 2cd4433 | 2016-07-14 12:38:17 +0530 | [diff] [blame] | 286 | case EMPTY: |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 287 | case STRING: |
| 288 | return JAVA_LANG; |
| 289 | case ENUMERATION: |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 290 | return getEnumsPackage(yangType, conflictResolver); |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 291 | case BITS: |
Mahesh Poojary Huawei | 2cd4433 | 2016-07-14 12:38:17 +0530 | [diff] [blame] | 292 | return COLLECTION_IMPORTS; |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 293 | case LEAFREF: |
janani b | 0e4e8ae | 2016-07-13 21:06:41 +0530 | [diff] [blame] | 294 | YangType<?> referredType = getReferredTypeFromLeafref(yangType); |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 295 | return getJavaImportPackage(referredType, false, conflictResolver); |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 296 | case IDENTITYREF: |
Shankara-Huawei | 234cd09 | 2016-07-14 11:35:34 +0530 | [diff] [blame] | 297 | return getIdentityRefPackage(yangType, conflictResolver); |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 298 | case UNION: |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 299 | return getUnionPackage(yangType, conflictResolver); |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 300 | case INSTANCE_IDENTIFIER: |
janani b | 0e4e8ae | 2016-07-13 21:06:41 +0530 | [diff] [blame] | 301 | return JAVA_LANG; |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 302 | case DERIVED: |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 303 | return getTypeDefsPackage(yangType, conflictResolver); |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 304 | default: |
| 305 | return null; |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 306 | } |
| 307 | } |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | /** |
| 311 | * Returns java package for typedef node. |
| 312 | * |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 313 | * @param type YANG type |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 314 | * @param conflictResolver object of YANG to java naming conflict util |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 315 | * @return java package for typedef node |
| 316 | */ |
Bharat saraswal | 8beac34 | 2016-08-04 02:00:03 +0530 | [diff] [blame] | 317 | private static String getTypeDefsPackage(YangType<?> type, YangToJavaNamingConflictUtil conflictResolver) { |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 318 | Object var = type.getDataTypeExtendedInfo(); |
| 319 | if (!(var instanceof YangDerivedInfo)) { |
Bharat saraswal | e3175d3 | 2016-08-31 17:50:11 +0530 | [diff] [blame] | 320 | throw new TranslatorException("type should have been derived. " + |
| 321 | type.getDataTypeName() + " in " + |
| 322 | type.getLineNumber() + " at " + |
| 323 | type.getCharPosition() |
| 324 | + " in " + type.getFileName()); |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 325 | } |
| 326 | |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 327 | if (!(((YangDerivedInfo<?>) var).getReferredTypeDef() != null)) { |
Bharat saraswal | e3175d3 | 2016-08-31 17:50:11 +0530 | [diff] [blame] | 328 | throw new TranslatorException("derived info is not an instance of typedef. " + |
| 329 | type.getDataTypeName() + " in " + |
| 330 | type.getLineNumber() + " at " + |
| 331 | type.getCharPosition() |
| 332 | + " in " + type.getFileName()); |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 333 | } |
| 334 | |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 335 | YangJavaTypeDefTranslator typedef = (YangJavaTypeDefTranslator) ((YangDerivedInfo<?>) var).getReferredTypeDef(); |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 336 | if (typedef.getJavaFileInfo().getPackage() == null) { |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 337 | return getPackageFromParent(typedef.getParent(), conflictResolver); |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 338 | } |
| 339 | return typedef.getJavaFileInfo().getPackage(); |
| 340 | } |
| 341 | |
| 342 | /** |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 343 | * Returns java package for union node. |
| 344 | * |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 345 | * @param type YANG type |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 346 | * @param conflictResolver object of YANG to java naming conflict util |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 347 | * @return java package for union node |
| 348 | */ |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 349 | private static String getUnionPackage(YangType<?> type, YangToJavaNamingConflictUtil conflictResolver) { |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 350 | |
| 351 | if (!(type.getDataTypeExtendedInfo() instanceof YangUnion)) { |
Bharat saraswal | e3175d3 | 2016-08-31 17:50:11 +0530 | [diff] [blame] | 352 | throw new TranslatorException("type should have been union. " + |
| 353 | type.getDataTypeName() + " in " + |
| 354 | type.getLineNumber() + " at " + |
| 355 | type.getCharPosition() |
| 356 | + " in " + type.getFileName()); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 357 | } |
| 358 | |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 359 | YangJavaUnionTranslator union = (YangJavaUnionTranslator) type.getDataTypeExtendedInfo(); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 360 | if (union.getJavaFileInfo().getPackage() == null) { |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 361 | return getPackageFromParent(union.getParent(), conflictResolver); |
Gaurav Agrawal | 97a5e1c | 2016-04-18 18:53:11 +0530 | [diff] [blame] | 362 | } |
| 363 | return union.getJavaFileInfo().getPackage(); |
| 364 | } |
| 365 | |
| 366 | /** |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 367 | * Returns YANG enumeration's java package. |
| 368 | * |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 369 | * @param type YANG type |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 370 | * @param conflictResolver object of YANG to java naming conflict util |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 371 | * @return YANG enumeration's java package |
| 372 | */ |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 373 | private static String getEnumsPackage(YangType<?> type, YangToJavaNamingConflictUtil conflictResolver) { |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 374 | |
| 375 | if (!(type.getDataTypeExtendedInfo() instanceof YangEnumeration)) { |
Bharat saraswal | e3175d3 | 2016-08-31 17:50:11 +0530 | [diff] [blame] | 376 | throw new TranslatorException("type should have been enumeration. " + |
| 377 | type.getDataTypeName() + " in " + |
| 378 | type.getLineNumber() + " at " + |
| 379 | type.getCharPosition() |
| 380 | + " in " + type.getFileName()); |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 381 | } |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 382 | YangJavaEnumerationTranslator enumeration = (YangJavaEnumerationTranslator) type.getDataTypeExtendedInfo(); |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 383 | if (enumeration.getJavaFileInfo().getPackage() == null) { |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 384 | return getPackageFromParent(enumeration.getParent(), conflictResolver); |
Bharat saraswal | 68fa0d1 | 2016-04-19 01:00:16 +0530 | [diff] [blame] | 385 | } |
| 386 | return enumeration.getJavaFileInfo().getPackage(); |
| 387 | } |
| 388 | |
| 389 | /** |
Shankara-Huawei | 234cd09 | 2016-07-14 11:35:34 +0530 | [diff] [blame] | 390 | * Returns YANG identity's java package. |
| 391 | * |
| 392 | * @param type YANG type |
| 393 | * @param conflictResolver object of YANG to java naming conflict util |
| 394 | * @return YANG identity's java package |
| 395 | */ |
| 396 | private static String getIdentityRefPackage(YangType<?> type, YangToJavaNamingConflictUtil conflictResolver) { |
| 397 | |
| 398 | if (!(type.getDataTypeExtendedInfo() instanceof YangIdentityRef)) { |
Bharat saraswal | e3175d3 | 2016-08-31 17:50:11 +0530 | [diff] [blame] | 399 | throw new TranslatorException("type should have been identityref. " + |
| 400 | type.getDataTypeName() + " in " + |
| 401 | type.getLineNumber() + " at " + |
| 402 | type.getCharPosition() |
| 403 | + " in " + type.getFileName()); |
Shankara-Huawei | 234cd09 | 2016-07-14 11:35:34 +0530 | [diff] [blame] | 404 | } |
| 405 | YangIdentityRef identityRef = (YangIdentityRef) type.getDataTypeExtendedInfo(); |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 406 | YangJavaIdentityTranslator identity = (YangJavaIdentityTranslator) (identityRef.getReferredIdentity()); |
Shankara-Huawei | 234cd09 | 2016-07-14 11:35:34 +0530 | [diff] [blame] | 407 | if (identity.getJavaFileInfo().getPackage() == null) { |
| 408 | return getPackageFromParent(identity.getParent(), conflictResolver); |
| 409 | } |
| 410 | return identity.getJavaFileInfo().getPackage(); |
| 411 | } |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 412 | |
Shankara-Huawei | 234cd09 | 2016-07-14 11:35:34 +0530 | [diff] [blame] | 413 | /** |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 414 | * Returns package from parent node. |
| 415 | * |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 416 | * @param parent parent YANG node |
janani b | 3e357f6 | 2016-05-19 17:39:50 +0530 | [diff] [blame] | 417 | * @param conflictResolver object of YANG to java naming conflict util |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 418 | * @return java package from parent node |
| 419 | */ |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 420 | private static String getPackageFromParent(YangNode parent, |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 421 | YangToJavaNamingConflictUtil conflictResolver) { |
Vinod Kumar S | 79a374b | 2016-04-30 21:09:15 +0530 | [diff] [blame] | 422 | if (!(parent instanceof JavaFileInfoContainer)) { |
Bharat saraswal | e3175d3 | 2016-08-31 17:50:11 +0530 | [diff] [blame] | 423 | throw new TranslatorException("invalid child node is being processed. " + |
| 424 | parent.getName() + " in " + |
| 425 | parent.getLineNumber() + " at " + |
| 426 | parent.getCharPosition() |
| 427 | + " in " + parent.getFileName()); |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 428 | } |
Bharat saraswal | e50edca | 2016-08-05 01:58:25 +0530 | [diff] [blame] | 429 | JavaFileInfoTranslator parentInfo = ((JavaFileInfoContainer) parent).getJavaFileInfo(); |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 430 | if (parentInfo.getPackage() == null) { |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 431 | updateJavaFileInfo(parent, conflictResolver); |
Gaurav Agrawal | ab7c4bd | 2016-05-17 18:06:38 +0530 | [diff] [blame] | 432 | } |
Bharat saraswal | e2bc60d | 2016-04-16 02:28:25 +0530 | [diff] [blame] | 433 | return parentInfo.getPackage() + PERIOD + parentInfo.getJavaName().toLowerCase(); |
Vinod Kumar S | 0871098 | 2016-03-03 19:55:30 +0530 | [diff] [blame] | 434 | } |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 435 | |
| 436 | /** |
| 437 | * Update the referred data model nodes java file info, this will be called, |
| 438 | * when the linked node is yet to translate. Then resolve until the parent hierarchy. |
| 439 | * |
| 440 | * @param yangNode node whose java info needs to be updated |
| 441 | * @param conflictResolver yang plugin config |
| 442 | */ |
| 443 | public static void updateJavaFileInfo(YangNode yangNode, |
Gaurav Agrawal | bfce934 | 2016-06-15 13:58:01 +0530 | [diff] [blame] | 444 | YangToJavaNamingConflictUtil conflictResolver) { |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 445 | Stack<YangNode> nodesToUpdatePackage = new Stack<>(); |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 446 | |
| 447 | /* |
| 448 | * Add the nodes to be updated for package info in a stack. |
| 449 | */ |
| 450 | while (yangNode != null |
| 451 | && ((JavaFileInfoContainer) yangNode) |
| 452 | .getJavaFileInfo().getPackage() == null) { |
| 453 | nodesToUpdatePackage.push(yangNode); |
| 454 | yangNode = yangNode.getParent(); |
| 455 | } |
| 456 | |
| 457 | /* |
| 458 | * If the package is not updated till root node, then root package needs to |
| 459 | * be updated. |
| 460 | */ |
| 461 | if (yangNode == null) { |
| 462 | yangNode = nodesToUpdatePackage.pop(); |
| 463 | String pkg; |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 464 | if (yangNode instanceof YangJavaModuleTranslator) { |
| 465 | YangJavaModuleTranslator module = (YangJavaModuleTranslator) yangNode; |
Gaurav Agrawal | e5057f0 | 2016-08-22 17:14:33 +0530 | [diff] [blame] | 466 | pkg = getRootPackage(module.getVersion(), module.getNameSpace(), module |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 467 | .getRevision().getRevDate(), conflictResolver); |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 468 | } else if (yangNode instanceof YangJavaSubModuleTranslator) { |
| 469 | YangJavaSubModuleTranslator submodule = (YangJavaSubModuleTranslator) yangNode; |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 470 | pkg = getRootPackage(submodule.getVersion(), |
| 471 | submodule.getNameSpaceFromModule(submodule.getBelongsTo()), |
| 472 | submodule.getRevision().getRevDate(), conflictResolver); |
| 473 | } else { |
Bharat saraswal | e3175d3 | 2016-08-31 17:50:11 +0530 | [diff] [blame] | 474 | throw new TranslatorException("Invalid root node of data model tree " + |
| 475 | yangNode.getName() + " in " + |
| 476 | yangNode.getLineNumber() + " at " + |
| 477 | yangNode.getCharPosition() |
| 478 | + " in " + yangNode.getFileName()); |
| 479 | |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | ((JavaCodeGeneratorInfo) yangNode).getJavaFileInfo() |
| 483 | .setJavaName(getCamelCase(yangNode.getName(), conflictResolver)); |
| 484 | ((JavaCodeGeneratorInfo) yangNode).getJavaFileInfo() |
| 485 | .setPackage(pkg); |
| 486 | ((JavaCodeGeneratorInfo) yangNode).getJavaFileInfo() |
| 487 | .setPackageFilePath(getPackageDirPathFromJavaJPackage( |
| 488 | ((JavaCodeGeneratorInfo) yangNode).getJavaFileInfo() |
| 489 | .getPackage())); |
| 490 | } |
| 491 | |
Shankara-Huawei | b756477 | 2016-08-02 18:13:13 +0530 | [diff] [blame] | 492 | /* |
VinodKumarS-Huawei | d81eccb | 2016-06-01 14:30:22 +0530 | [diff] [blame] | 493 | * Parent of the node in stack is updated with java info, |
| 494 | * all the nodes can be popped and updated |
| 495 | */ |
| 496 | while (nodesToUpdatePackage.size() != 0) { |
| 497 | yangNode = nodesToUpdatePackage.pop(); |
| 498 | ((JavaCodeGeneratorInfo) yangNode).getJavaFileInfo() |
| 499 | .setJavaName(getCamelCase(yangNode.getName(), conflictResolver)); |
| 500 | ((JavaCodeGeneratorInfo) yangNode).getJavaFileInfo() |
| 501 | .setPackage(getCurNodePackage(yangNode)); |
| 502 | ((JavaCodeGeneratorInfo) yangNode).getJavaFileInfo() |
| 503 | .setPackageFilePath(getPackageDirPathFromJavaJPackage( |
| 504 | ((JavaCodeGeneratorInfo) yangNode).getJavaFileInfo() |
| 505 | .getPackage())); |
| 506 | } |
| 507 | } |
janani b | 0e4e8ae | 2016-07-13 21:06:41 +0530 | [diff] [blame] | 508 | |
| 509 | /** |
| 510 | * Returns the referred type from leaf/leaf-list. |
| 511 | * |
| 512 | * @param type current type in leaf |
| 513 | * @return type from the leafref |
| 514 | */ |
| 515 | private static YangType<?> getReferredTypeFromLeafref(YangType type) { |
| 516 | YangLeafRef<?> leafRefInfo = (YangLeafRef<?>) type.getDataTypeExtendedInfo(); |
| 517 | return leafRefInfo.getEffectiveDataType(); |
| 518 | } |
Bharat saraswal | c46ee2a | 2016-02-25 02:26:43 +0530 | [diff] [blame] | 519 | } |