package org.opendaylight.mdsal.binding.yang.types;
import static java.util.Objects.requireNonNull;
+import static org.opendaylight.mdsal.binding.model.util.BindingTypes.TYPE_OBJECT;
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;
genTOBuilder.addEqualsIdentity(genPropBuilder);
genTOBuilder.addHashIdentity(genPropBuilder);
genTOBuilder.addToStringProperty(genPropBuilder);
+ genTOBuilder.addImplementsType(TYPE_OBJECT);
if (typedef.getStatus() == Status.DEPRECATED) {
genTOBuilder.addAnnotation("java.lang", "Deprecated");
}
unionGenTOBuilder.setIsUnion(true);
unionGenTOBuilder.setSchemaPath(typedef.getPath());
unionGenTOBuilder.setModuleName(module.getName());
+ unionGenTOBuilder.addImplementsType(TYPE_OBJECT);
addCodegenInformation(unionGenTOBuilder, typedef);
generatedTOBuilders.add(unionGenTOBuilder);
genTOBuilder.setSchemaPath(typeDef.getPath());
genTOBuilder.setModuleName(moduleName);
genTOBuilder.setBaseType(typeDef);
+ genTOBuilder.addImplementsType(TYPE_OBJECT);
addCodegenInformation(genTOBuilder, typeDef);
final List<Bit> bitList = typeDef.getBits();
--- /dev/null
+/*
+ * Copyright (c) 2018 Pantheon Technologies, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.mdsal.binding.generator.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.opendaylight.mdsal.binding.model.util.BindingTypes.TYPE_OBJECT;
+
+import java.util.List;
+import org.junit.Test;
+import org.opendaylight.mdsal.binding.model.api.GeneratedType;
+import org.opendaylight.mdsal.binding.model.api.Type;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
+
+public class Mdsal406TypeObjectTest {
+
+ @Test
+ public void typeObjectTest() {
+ final SchemaContext context = YangParserTestUtils.parseYangResources(ExtendedTypedefTest.class,
+ "/type-provider/test.yang", "/ietf/ietf-inet-types.yang");
+
+ final List<Type> generateTypes = new BindingGeneratorImpl().generateTypes(context);
+ assertNotNull(generateTypes);
+
+ final Type typedefType = generateTypes.stream().filter(type -> type.getFullyQualifiedName()
+ .equals("org.opendaylight.yang.gen.v1.urn.opendaylight.test.rev131008.MyBinary")).findFirst().get();
+
+ assertTrue(typedefType instanceof GeneratedType);
+ assertNotNull(((GeneratedType) typedefType).getImplements());
+ Type objectType = ((GeneratedType) typedefType).getImplements().stream()
+ .filter(type -> type.getFullyQualifiedName()
+ .equals("org.opendaylight.yangtools.yang.binding.TypeObject")).findAny().get();
+ assertEquals(TYPE_OBJECT, objectType);
+ }
+
+ @Test
+ public void typeObjectForBitsTypedefTest() {
+ final SchemaContext context = YangParserTestUtils.parseYangResources(ExtendedTypedefTest.class,
+ "/type-provider/test.yang", "/ietf/ietf-inet-types.yang");
+
+ final List<Type> generateTypes = new BindingGeneratorImpl().generateTypes(context);
+ assertNotNull(generateTypes);
+
+ final Type typedefType = generateTypes.stream().filter(type -> type.getFullyQualifiedName()
+ .equals("org.opendaylight.yang.gen.v1.urn.opendaylight.test.rev131008.MyBits")).findFirst().get();
+
+ assertTrue(typedefType instanceof GeneratedType);
+ assertNotNull(((GeneratedType) typedefType).getImplements());
+ Type objectType = ((GeneratedType) typedefType).getImplements().stream()
+ .filter(type -> type.getFullyQualifiedName()
+ .equals("org.opendaylight.yangtools.yang.binding.TypeObject")).findAny().get();
+ assertEquals(TYPE_OBJECT, objectType);
+ }
+
+ @Test
+ public void typeObjectForUnionTypedefTest() {
+ final SchemaContext context = YangParserTestUtils.parseYangResources(ExtendedTypedefTest.class,
+ "/type-provider/test.yang", "/ietf/ietf-inet-types.yang");
+
+ final List<Type> generateTypes = new BindingGeneratorImpl().generateTypes(context);
+ assertNotNull(generateTypes);
+
+ final Type typedefType = generateTypes.stream().filter(type -> type.getFullyQualifiedName()
+ .equals("org.opendaylight.yang.gen.v1.urn.opendaylight.test.rev131008.MyUnion")).findFirst().get();
+
+ assertTrue(typedefType instanceof GeneratedType);
+ assertNotNull(((GeneratedType) typedefType).getImplements());
+ Type objectType = ((GeneratedType) typedefType).getImplements().stream()
+ .filter(type -> type.getFullyQualifiedName()
+ .equals("org.opendaylight.yangtools.yang.binding.TypeObject")).findAny().get();
+ assertEquals(TYPE_OBJECT, objectType);
+ }
+}
package org.opendaylight.mdsal.binding.model.util;
import com.google.common.base.CharMatcher;
+import com.google.common.collect.Collections2;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableList.Builder;
import com.google.common.collect.Iterables;
dout.writeUTF(to.getName());
dout.writeInt(to.isAbstract() ? 3 : 7);
- for (final Type ifc : sortedCollection(SUID_NAME_COMPARATOR, to.getImplementsTypes())) {
+ for (final Type ifc : sortedCollection(SUID_NAME_COMPARATOR, filteredImplementsTypes(to))) {
dout.writeUTF(ifc.getFullyQualifiedName());
}
return hash;
}
+ private static Collection<Type> filteredImplementsTypes(final GeneratedTypeBuilderBase<?> to) {
+ return Collections2.filter(to.getImplementsTypes(), item -> !BindingTypes.TYPE_OBJECT.equals(item));
+ }
+
private static <T extends Optional<?>> T currentOrEmpty(final T current, final T base) {
return current.equals(base) ? (T)Optional.empty() : current;
}
import org.opendaylight.yangtools.yang.binding.RpcInput;
import org.opendaylight.yangtools.yang.binding.RpcOutput;
import org.opendaylight.yangtools.yang.binding.RpcService;
+import org.opendaylight.yangtools.yang.binding.TypeObject;
import org.opendaylight.yangtools.yang.binding.annotations.RoutingContext;
import org.opendaylight.yangtools.yang.common.RpcResult;
public static final ConcreteType BASE_IDENTITY = typeForClass(BaseIdentity.class);
public static final ConcreteType DATA_CONTAINER = typeForClass(DataContainer.class);
public static final ConcreteType DATA_OBJECT = typeForClass(DataObject.class);
+ public static final ConcreteType TYPE_OBJECT = typeForClass(TypeObject.class);
public static final ConcreteType DATA_ROOT = typeForClass(DataRoot.class);
public static final ConcreteType NOTIFICATION = typeForClass(Notification.class);
public static final ConcreteType NOTIFICATION_LISTENER = typeForClass(NotificationListener.class);