if (identity == null) {
return;
}
- final GeneratedTOBuilder newType = typeProvider.newGeneratedTOBuilder(JavaTypeName.create(
+ final GeneratedTypeBuilder newType = typeProvider.newGeneratedTypeBuilder(JavaTypeName.create(
packageNameForGeneratedType(context.modulePackageName(), identity.getPath()),
BindingMapping.getClassName(identity.getQName())));
final Set<IdentitySchemaNode> baseIdentities = identity.getBaseIdentities();
if (baseIdentities.isEmpty()) {
final GeneratedTOBuilder gto = typeProvider.newGeneratedTOBuilder(JavaTypeName.create(BaseIdentity.class));
- newType.setExtendsType(gto.build());
+ newType.addImplementsType(gto.build());
} else {
- final IdentitySchemaNode baseIdentity = baseIdentities.iterator().next();
- final QName qname = baseIdentity.getQName();
- final GeneratedTransferObject gto = typeProvider.newGeneratedTOBuilder(JavaTypeName.create(
- BindingMapping.getRootPackageName(qname.getModule()), BindingMapping.getClassName(qname))).build();
- newType.setExtendsType(gto);
+ for (IdentitySchemaNode baseIdentity : baseIdentities) {
+ final QName qname = baseIdentity.getQName();
+ final GeneratedTransferObject gto = typeProvider.newGeneratedTOBuilder(JavaTypeName.create(
+ BindingMapping.getRootPackageName(qname.getModule()), BindingMapping.getClassName(qname))).build();
+ newType.addImplementsType(gto);
+ }
}
- newType.setAbstract(true);
final Module module = context.module();
addCodegenInformation(newType, module, identity);
private final Map<SchemaPath, GeneratedTypeBuilder> groupings = new HashMap<>();
private final BiMap<Type, CaseSchemaNode> caseTypeToSchema = HashBiMap.create();
private final Map<SchemaPath, GeneratedTypeBuilder> cases = new HashMap<>();
+ private final Map<QName, GeneratedTypeBuilder> identities = new HashMap<>();
private final List<GeneratedTypeBuilder> augmentations = new ArrayList<>();
- private final Map<QName, GeneratedTOBuilder> identities = new HashMap<>();
private final Multimap<Type, Type> choiceToCases = HashMultimap.create();
private final Set<GeneratedTypeBuilder> topLevelNodes = new HashSet<>();
private final Map<Type, WithStatus> typeToSchema = new HashMap<>();
for (GeneratedTypeBuilder b : cases.values()) {
result.add(b.build());
}
- for (GeneratedTOBuilder b : identities.values()) {
+ for (GeneratedTypeBuilder b : identities.values()) {
result.add(b.build());
}
for (GeneratedTypeBuilder b : topLevelNodes) {
cases.put(p, b);
}
- public void addIdentityType(final QName name,final GeneratedTOBuilder b) {
- identities.put(name,b);
+ public void addIdentityType(final QName name,final GeneratedTypeBuilder b) {
+ identities.put(name, b);
}
public void addTopLevelNodeType(final GeneratedTypeBuilder b) {
return Collections.unmodifiableMap(cases);
}
- public Map<QName,GeneratedTOBuilder> getIdentities() {
+ public Map<QName, GeneratedTypeBuilder> getIdentities() {
return Collections.unmodifiableMap(identities);
}
}
/**
- *
* Returns mapping of type to its schema.
*
* Valid values are only instances of {@link DataSchemaNode} or {@link AugmentationSchemaNode}
import java.util.Set;
import org.opendaylight.mdsal.binding.generator.api.BindingRuntimeTypes;
import org.opendaylight.mdsal.binding.model.api.Type;
-import org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedTOBuilder;
import org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedTypeBuilder;
import org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedTypeBuilderBase;
import org.opendaylight.mdsal.binding.model.api.type.builder.TypeMemberBuilder;
for (Entry<Type, Type> e : ctx.getChoiceToCases().entries()) {
choiceToCases.put(builtType(builderToType, e.getKey()), builtType(builderToType, e.getValue()));
}
- for (Entry<QName, GeneratedTOBuilder> e : ctx.getIdentities().entrySet()) {
+ for (Entry<QName, GeneratedTypeBuilder> e : ctx.getIdentities().entrySet()) {
identities.put(e.getKey(), builtType(builderToType, e.getValue()));
}
}
import static org.junit.Assert.assertTrue;
import com.google.common.collect.Collections2;
+import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Range;
import java.io.File;
.forName(CompilationTestUtils.BASE_PKG + ".urn.opendaylight.bar.rev131008.IdentityClass", true, loader);
// test identity
- try {
- identityClass.getConstructor();
- final Class<?> baseIdentity = Class.forName("org.opendaylight.yangtools.yang.binding.BaseIdentity", true, loader);
- assertEquals(baseIdentity, identityClass.getSuperclass());
- } catch (final NoSuchMethodException e) {
- throw new AssertionError("IdentityClass must have no-arg constructor");
- }
+ final Class<?> baseIdentity = Class.forName("org.opendaylight.yangtools.yang.binding.BaseIdentity", true, loader);
+ assertEquals(ImmutableList.of(baseIdentity), Arrays.asList(identityClass.getInterfaces()));
// Test annotation
try {
/**
* Base Identity.
*/
-public abstract class BaseIdentity {
-
- public static final BaseIdentity INSTANCE = new BaseIdentity() { };
-
- protected BaseIdentity() {
-
- }
+public interface BaseIdentity {
}
+++ /dev/null
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. 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.yangtools.yang.binding;
-
-import static org.junit.Assert.assertNotNull;
-
-import org.junit.Test;
-
-public class BaseIdentityTest extends BaseIdentity {
-
- @Test
- public void constructTest() throws Exception {
- assertNotNull(INSTANCE);
- }
-}
\ No newline at end of file
assertFalse(BindingReflections.resolveRpcOutputClass(
TestImplementation.class.getDeclaredMethod("rpcMethodTest2")).isPresent());
- assertEquals(QName.create("test", "test"), BindingReflections.getQName(TestImplementation.class));
+ assertEquals(QName.create("test", "test"), BindingReflections.getQName(TestIdentity.class));
}
@Test(expected = UnsupportedOperationException.class)
}
}
- private static final class TestImplementation extends BaseIdentity implements Augmentation<TestImplementation>,
- RpcService {
+ private interface TestIdentity extends BaseIdentity {
+ @SuppressWarnings("unused")
+ QName QNAME = QName.create("test", "test");
+
+ }
+
+ private static final class TestImplementation implements Augmentation<TestImplementation>, RpcService {
+ @SuppressWarnings("unused")
public static final QName QNAME = QName.create("test", "test");
+ @SuppressWarnings({ "unused", "static-method" })
Future<List<Object>> rpcMethodTest() {
return null;
}
+ @SuppressWarnings({ "unused", "static-method" })
Future<?> rpcMethodTest2() {
return null;
}