import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
-import org.opendaylight.yangtools.yang.model.util.BaseTypes;
import org.opendaylight.yangtools.yang.model.util.DataNodeIterator;
import org.opendaylight.yangtools.yang.model.util.ExtendedType;
import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
final GeneratedTypeBuilder parent, final GeneratedTypeBuilder childOf, final ContainerSchemaNode node) {
final GeneratedTypeBuilder genType = processDataSchemaNode(module, basePackageName, childOf, node);
if (genType != null) {
- constructGetter(parent, node.getQName().getLocalName(), node.getDescription(), genType);
+ constructGetter(parent, node.getQName().getLocalName(), node.getDescription(), genType, node.getStatus());
resolveDataSchemaNodes(module, basePackageName, genType, genType, node.getChildNodes());
}
}
final GeneratedTypeBuilder genType = processDataSchemaNode(module, basePackageName, childOf, node);
if (genType != null) {
constructGetter(parent, node.getQName().getLocalName(), node.getDescription(),
- Types.listTypeFor(genType));
+ Types.listTypeFor(genType), node.getStatus());
final List<String> listKeys = listKeys(node);
final String packageName = packageNameForGeneratedType(basePackageName, node.getPath());
final String packageName = packageNameForGeneratedType(basePackageName, choiceNode.getPath());
final GeneratedTypeBuilder choiceTypeBuilder = addRawInterfaceDefinition(packageName, choiceNode);
constructGetter(parent, choiceNode.getQName().getLocalName(),
- choiceNode.getDescription(), choiceTypeBuilder);
+ choiceNode.getDescription(), choiceTypeBuilder, choiceNode.getStatus());
choiceTypeBuilder.addImplementsType(typeForClass(DataContainer.class));
annotateDeprecatedIfNecessary(choiceNode.getStatus(), choiceTypeBuilder);
genCtx.get(module).addChildNodeType(choiceNode, choiceTypeBuilder);
leafDesc = "";
}
- final MethodSignatureBuilder getter = constructGetter(typeBuilder, leafName, leafDesc, returnType);
+ final MethodSignatureBuilder getter = constructGetter(typeBuilder, leafName, leafDesc, returnType, leaf.getStatus());
processContextRefExtension(leaf, getter, parentModule);
return returnType;
}
}
final ParameterizedType listType = Types.listTypeFor(returnType);
- constructGetter(typeBuilder, nodeName.getLocalName(), node.getDescription(), listType);
+ constructGetter(typeBuilder, nodeName.getLocalName(), node.getDescription(), listType, node.getStatus());
return true;
}
* string with comment for the getter method
* @param returnType
* type which represents the return type of the getter method
+ * @param status
+ * status from yang file, for deprecated annotation
* @return method signature builder which represents the getter method of
* <code>interfaceBuilder</code>
*/
private static MethodSignatureBuilder constructGetter(final GeneratedTypeBuilder interfaceBuilder,
- final String schemaNodeName, final String comment, final Type returnType) {
+ final String schemaNodeName, final String comment, final Type returnType, final Status status) {
final MethodSignatureBuilder getMethod = interfaceBuilder
.addMethod(getterMethodName(schemaNodeName, returnType));
+ if (status == Status.DEPRECATED) {
+ getMethod.addAnnotation("", "Deprecated");
+ }
getMethod.setComment(encodeAngleBrackets(comment));
getMethod.setReturnType(returnType);
return getMethod;
if (genTOBuilder != null) {
final GeneratedTransferObject genTO = genTOBuilder.toInstance();
- constructGetter(typeBuilder, "key", "Returns Primary Key of Yang List Type", genTO);
+ constructGetter(typeBuilder, "key", "Returns Primary Key of Yang List Type", genTO, Status.CURRENT);
genCtx.get(module).addGeneratedTOBuilder(genTOBuilder);
}
}
import java.util.List
import java.util.Map
import java.util.Set
+import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil
import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode
import org.opendaylight.yangtools.yang.model.api.AugmentationSchema
import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode
import org.opendaylight.yangtools.yang.model.api.UsesNode
import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition
import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition.EnumPair
-import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil
class YangTemplate {
def private static writeRPC(RpcDefinition rpc) {
var boolean isStatusDeprecated = rpc.status == Status::DEPRECATED
'''
- «IF isStatusDeprecated»
- @deprecated - status DEPRECATED
- «ENDIF»
rpc «rpc.QName.localName» {
«IF !rpc.description.nullOrEmpty»
"«rpc.description»";
def private static writeNotification(NotificationDefinition notification) {
var boolean isStatusDeprecated = notification.status == Status::DEPRECATED
'''
- «IF isStatusDeprecated»
- @deprecated - status DEPRECATED
- «ENDIF»
notification «notification.QName.localName» {
«IF !notification.description.nullOrEmpty»
description
def private static writeTypeDefinition(TypeDefinition<?> typeDefinition) {
var boolean isStatusDeprecated = typeDefinition.status == Status::DEPRECATED
'''
- «IF isStatusDeprecated»
- @deprecated - status DEPRECATED
- «ENDIF»
type «typeDefinition.QName.localName»«IF !isStatusDeprecated»;«ELSE» {
status «typeDefinition.status»;
}
}
def private static writeExtension(ExtensionDefinition extensionDef) {
- var boolean isStatusDeprecated = extensionDef.status == Status::DEPRECATED
-
'''
- «IF isStatusDeprecated»
- @deprecated - status DEPRECATED
- «ENDIF»
extension «extensionDef.QName.localName» {
«IF !extensionDef.description.nullOrEmpty»
description
def private static writeGroupingDef(GroupingDefinition groupingDef) {
var boolean isStatusDeprecated = groupingDef.status == Status::DEPRECATED
'''
- «IF isStatusDeprecated»
- @deprecated - status DEPRECATED
- «ENDIF»
grouping «groupingDef.QName.localName» {
«IF !groupingDef.groupings.nullOrEmpty»
«writeGroupingDefs(groupingDef.groupings)»
def private static writeContSchemaNode(ContainerSchemaNode contSchemaNode) {
var boolean isStatusDeprecated = contSchemaNode.status == Status::DEPRECATED
'''
- «IF isStatusDeprecated»
- @deprecated - status DEPRECATED
- «ENDIF»
container «contSchemaNode.getQName.localName» {
«IF !contSchemaNode.childNodes.nullOrEmpty»
«writeDataSchemaNodes(contSchemaNode.childNodes)»
def private static writeAnyXmlSchemaNode(AnyXmlSchemaNode anyXmlSchemaNode) {
var boolean isStatusDeprecated = anyXmlSchemaNode.status == Status::DEPRECATED
'''
- «IF isStatusDeprecated»
- @deprecated - status DEPRECATED
- «ENDIF»
anyxml «anyXmlSchemaNode.getQName.localName»«IF !isStatusDeprecated»;«ELSE» {
status «anyXmlSchemaNode.status»;
}
def private static writeLeafSchemaNode(LeafSchemaNode leafSchemaNode) {
var boolean isStatusDeprecated = leafSchemaNode.status == Status::DEPRECATED
'''
- «IF isStatusDeprecated»
- @deprecated - status DEPRECATED
- «ENDIF»
leaf «leafSchemaNode.getQName.localName» {
type «leafSchemaNode.type.getQName.localName»;
«IF isStatusDeprecated»
def private static writeLeafListSchemaNode(LeafListSchemaNode leafListSchemaNode) {
var boolean isStatusDeprecated = leafListSchemaNode.status == Status::DEPRECATED
'''
- «IF isStatusDeprecated»
- @deprecated - status DEPRECATED
- «ENDIF»
leaf-list «leafListSchemaNode.getQName.localName» {
type «leafListSchemaNode.type.getQName.localName»;
«IF isStatusDeprecated»
def private static writeChoiceCaseNode(ChoiceCaseNode choiceCaseNode) {
var boolean isStatusDeprecated = choiceCaseNode.status == Status::DEPRECATED
'''
- «IF isStatusDeprecated»
- @deprecated - status DEPRECATED
- «ENDIF»
case «choiceCaseNode.getQName.localName» {
«FOR childNode : choiceCaseNode.childNodes»
«writeDataSchemaNode(childNode)»
def private static writeChoiceNode(ChoiceSchemaNode choiceNode) {
var boolean isStatusDeprecated = choiceNode.status == Status::DEPRECATED
'''
- «IF isStatusDeprecated»
- @deprecated - status DEPRECATED
- «ENDIF»
choice «choiceNode.getQName.localName» {
«FOR child : choiceNode.cases»
«writeDataSchemaNode(child)»
var boolean isStatusDeprecated = listSchemaNode.status == Status::DEPRECATED
'''
- «IF isStatusDeprecated»
- @deprecated - status DEPRECATED
- «ENDIF»
list «listSchemaNode.getQName.localName» {
key «FOR listKey : listSchemaNode.keyDefinition SEPARATOR " "»"«listKey.localName»"
«ENDFOR»
import static org.opendaylight.yangtools.yang.model.util.SchemaContextUtil.findDataSchemaNode;
import static org.opendaylight.yangtools.yang.model.util.SchemaContextUtil.findDataSchemaNodeForRelativeXPath;
import static org.opendaylight.yangtools.yang.model.util.SchemaContextUtil.findParentModule;
+
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.SchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.Status;
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition;
/**
* Converts <code>enumTypeDef</code> to
- * {@link org.opendaylight.yangtools.sal.binding.model.api.Enumeration
+ * {@link Enumeration
* enumeration}.
*
* @param enumTypeDef
genTOBuilder.addEqualsIdentity(genPropBuilder);
genTOBuilder.addHashIdentity(genPropBuilder);
genTOBuilder.addToStringProperty(genPropBuilder);
+ if (typedef.getStatus() == Status.DEPRECATED) {
+ genTOBuilder.addAnnotation("", "Deprecated");
+ }
if (javaType instanceof ConcreteType && "String".equals(javaType.getName()) && typedef.getBaseType() != null) {
final List<String> regExps = resolveRegExpressionsFromTypedef(typedef);
addStringRegExAsConstant(genTOBuilder, regExps);
genTOBuilder.setTypedef(true);
Restrictions r = BindingGeneratorUtil.getRestrictions(typedef);
genTOBuilder.setRestrictions(r);
+ if (typedef.getStatus() == Status.DEPRECATED) {
+ genTOBuilder.addAnnotation("", "Deprecated");
+ }
if (baseTypeDefForExtendedType(innerExtendedType) instanceof UnionTypeDefinition) {
genTOBuilder.setIsUnion(true);
import java.util.regex.Pattern
import org.opendaylight.yangtools.binding.generator.util.Types
import org.opendaylight.yangtools.sal.binding.model.api.ConcreteType
+import org.opendaylight.yangtools.sal.binding.model.api.Constant
import org.opendaylight.yangtools.sal.binding.model.api.GeneratedProperty
import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject
import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType
import org.opendaylight.yangtools.sal.binding.model.api.MethodSignature
import org.opendaylight.yangtools.sal.binding.model.api.Restrictions
import org.opendaylight.yangtools.sal.binding.model.api.Type
-import org.opendaylight.yangtools.sal.binding.model.api.Constant
import org.opendaylight.yangtools.yang.common.QName
abstract class BaseTemplate {
*/
def protected generateBody(boolean isInnerClass) '''
«wrapToDocumentation(formatDataForJavaDoc(type))»
+ «annotationDeclaration»
«generateClassDeclaration(isInnerClass)» {
«suidDeclaration»
«innerClassesDeclarations»
«ENDIF»
'''
+ def protected annotationDeclaration() '''
+ «IF genTO.getAnnotations != null»
+ «FOR e : genTO.getAnnotations»
+ @«e.getName»
+ «ENDFOR»
+ «ENDIF»
+ '''
+
/**
* Template method which generates JAVA constants.
*
package org.opendaylight.yangtools.sal.java.api.generator.test;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import com.google.common.base.Predicate;
}
@Test
- public void testBug5788() throws Exception {
- final File sourcesOutputDir = new File(CompilationTestUtils.GENERATOR_OUTPUT_PATH + CompilationTestUtils.FS + "bug5788");
+ public void testBug5882() throws Exception {
+ final File sourcesOutputDir = new File(CompilationTestUtils.GENERATOR_OUTPUT_PATH + CompilationTestUtils.FS + "bug5882");
assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir());
- final File compiledOutputDir = new File(CompilationTestUtils.COMPILER_OUTPUT_PATH + CompilationTestUtils.FS + "bug5788");
+ final File compiledOutputDir = new File(CompilationTestUtils.COMPILER_OUTPUT_PATH + CompilationTestUtils.FS + "bug5882");
assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir());
-
- generateTestSources("/compilation/bug5788", sourcesOutputDir);
+ generateTestSources("/compilation/bug5882", sourcesOutputDir);
// Test if sources are compilable
CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir);
+ final File parent = new File(sourcesOutputDir, CompilationTestUtils.NS_BUG5882);
+ assertTrue(new File(parent, "FooData.java").exists());
+ assertTrue(new File(parent, "TypedefCurrent.java").exists());
+ assertTrue(new File(parent, "TypedefDeprecated.java").exists());
+
+ final String pkg = CompilationTestUtils.BASE_PKG + ".urn.yang.foo.rev160102";
+ final ClassLoader loader = new URLClassLoader(new URL[] { compiledOutputDir.toURI().toURL() });
+ final Class cls = loader.loadClass(pkg + ".FooData");
+ final Class clsContainer = loader.loadClass(pkg + ".ContainerMain");
+ final Class clsTypedefDepr = loader.loadClass(pkg + ".TypedefDeprecated");
+ final Class clsTypedefCur = loader.loadClass(pkg + ".TypedefCurrent");
+ final Class clsGroupingDepr = loader.loadClass(pkg + ".GroupingDeprecated");
+ final Class clsGroupingCur = loader.loadClass(pkg + ".GroupingCurrent");
+ final Class clsTypeDef1 = loader.loadClass(pkg + ".Typedef1");
+ final Class clsTypeDef2 = loader.loadClass(pkg + ".Typedef2");
+ final Class clsTypeDef3 = loader.loadClass(pkg + ".Typedef3");
+ assertTrue(clsTypedefDepr.getAnnotations()[0].toString().contains("Deprecated"));
+ assertTrue(clsTypedefCur.getAnnotations().length == 0);
+ assertTrue(clsGroupingDepr.getAnnotations()[0].toString().contains("Deprecated"));
+ assertTrue(clsGroupingCur.getAnnotations().length == 0);
+ assertTrue(clsTypeDef1.getAnnotations().length == 0);
+ assertTrue(clsTypeDef3.getAnnotations().length == 0);
+ assertTrue(clsTypeDef2.getAnnotations()[0].toString().contains("Deprecated"));
+
+ /*methods inside container*/
+ assertTrue(clsContainer.getMethod("getContainerMainLeafDepr").isAnnotationPresent(Deprecated.class));
+ assertTrue(clsContainer.getMethod("getContainerMainListDepr").isAnnotationPresent(Deprecated.class));
+ assertTrue(clsContainer.getMethod("getContainerMainChoiceDepr").isAnnotationPresent(Deprecated.class));
+ assertFalse(clsContainer.getMethod("getContainerMainLeafCurrent").isAnnotationPresent(Deprecated.class));
+ assertFalse(clsContainer.getMethod("getContainerMainListCurrent").isAnnotationPresent(Deprecated.class));
+ assertFalse(clsContainer.getMethod("getContainerMainChoiceCur").isAnnotationPresent(Deprecated.class));
+
+ /*methods inside module*/
+ assertTrue(cls.getMethod("getContainerMainLeafDepr").isAnnotationPresent(Deprecated.class));
+ assertTrue(cls.getMethod("getContainerMainListDepr").isAnnotationPresent(Deprecated.class));
+ assertTrue(cls.getMethod("getContainerMainChoiceDepr").isAnnotationPresent(Deprecated.class));
+ assertFalse(cls.getMethod("getContainerMainLeafCurrent").isAnnotationPresent(Deprecated.class));
+ assertFalse(cls.getMethod("getContainerMainListCurrent").isAnnotationPresent(Deprecated.class));
+ assertFalse(cls.getMethod("getContainerMainChoiceCur").isAnnotationPresent(Deprecated.class));
+ assertTrue(cls.getMethod("getLeafDeprecated").isAnnotationPresent(Deprecated.class));
+
CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir);
}
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+
import java.io.File;
import java.io.FileNotFoundException;
import java.lang.reflect.Constructor;
static final File COMPILER_OUTPUT_DIR = new File(COMPILER_OUTPUT_PATH);
static final String AUGMENTATION = "interface org.opendaylight.yangtools.yang.binding.Augmentation";
-
static final String BASE_PATH = "org" + FS + "opendaylight" + FS + "yang" + FS + "gen" + FS + "v1";
static final String NS_TEST = BASE_PATH + FS + "urn" + FS + "opendaylight" + FS + "test" + FS + "rev131008";
static final String NS_FOO = BASE_PATH + FS + "urn" + FS + "opendaylight" + FS + "foo" + FS + "rev131008";
static final String NS_BAR = BASE_PATH + FS + "urn" + FS + "opendaylight" + FS + "bar" + FS + "rev131008";
static final String NS_BAZ = BASE_PATH + FS + "urn" + FS + "opendaylight" + FS + "baz" + FS + "rev131008";
+ static final String NS_BUG5882 = BASE_PATH + FS + "urn" + FS + "yang" + FS + "foo" + FS + "rev160102";
/**
* Method to clean resources. It is manually called at the end of each test
--- /dev/null
+module foo {
+ namespace "urn:yang.foo";
+ prefix "foo";
+
+ revision "2016-01-02" {
+ }
+
+ typedef typedef1 {
+ type typedef-deprecated;
+ description "current";
+ }
+
+ typedef typedef2 {
+ status deprecated;
+ type typedef1;
+ description "deprecated";
+ }
+
+ typedef typedef3 {
+ type typedef2;
+ description "current";
+ }
+
+ typedef typedef-deprecated {
+ status deprecated;
+ type string;
+ description "deprecated";
+ }
+
+ typedef typedef-current {
+ status current;
+ type uint8 {
+ range "0 .. 100";
+ }
+ description "current";
+ }
+
+ container container-main {
+ leaf container-main-leaf-depr {
+ status deprecated;
+ type string;
+ }
+
+ leaf container-main-leaf-current {
+ type typedef-current;
+ }
+
+ list container-main-list-depr {
+ status deprecated;
+ key "test";
+ leaf test {
+ type int8;
+ }
+ }
+
+ list container-main-list-current {
+ key "test";
+ leaf test {
+ type int8;
+ }
+ }
+
+ choice container-main-choice-depr {
+ status deprecated;
+ case depCase {
+ status deprecated;
+ leaf one {
+ type string;
+ }
+ }
+ case depLeaf {
+ leaf one {
+ status deprecated;
+ type string;
+ }
+ }
+ case cur {
+ leaf two {
+ type string;
+ }
+ }
+ }
+
+ choice container-main-choice-cur {
+ case depCase {
+ status deprecated;
+ leaf one {
+ type string;
+ }
+ }
+ case depLeaf {
+ leaf one {
+ status deprecated;
+ type string;
+ }
+ }
+ case cur {
+ leaf two {
+ type string;
+ }
+ }
+ }
+ }
+
+ leaf container-main-leaf-depr {
+ status deprecated;
+ type string;
+ }
+
+ leaf container-main-leaf-current {
+ type typedef-current;
+ }
+
+ list container-main-list-depr {
+ status deprecated;
+ key "test";
+ leaf test {
+ type int8;
+ }
+ }
+
+ list container-main-list-current {
+ key "test";
+ leaf test {
+ type int8;
+ }
+ }
+
+ choice container-main-choice-depr {
+ status deprecated;
+ case depCase {
+ status deprecated;
+ leaf one {
+ type string;
+ }
+ }
+ case depLeaf {
+ leaf one {
+ status deprecated;
+ type string;
+ }
+ }
+ case cur {
+ leaf two {
+ type string;
+ }
+ }
+ }
+
+ choice container-main-choice-cur {
+ case depCase {
+ status deprecated;
+ leaf one {
+ type string;
+ }
+ }
+ case depLeaf {
+ leaf one {
+ status deprecated;
+ type string;
+ }
+ }
+ case cur {
+ leaf two {
+ type string;
+ }
+ }
+ }
+
+ leaf leaf-deprecated {
+ status deprecated;
+ type typedef-deprecated;
+ }
+
+ leaf leaf-current {
+ type typedef-current;
+ }
+
+ grouping grouping-deprecated {
+ status deprecated;
+ leaf leaf-deprecated {
+ status deprecated;
+ type typedef-deprecated;
+ }
+
+ leaf leaf-current {
+ type typedef-current;
+ }
+ }
+
+ grouping grouping-current {
+ leaf leaf-deprecated {
+ status deprecated;
+ type typedef-deprecated;
+ }
+
+ leaf leaf-current {
+ type typedef-current;
+ }
+ }
+}
\ No newline at end of file