*/
package org.opendaylight.mdsal.binding.dom.codec.impl;
-import com.google.common.base.Preconditions;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkState;
+import static java.util.Objects.requireNonNull;
+
import com.google.common.collect.ImmutableMap;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.Callable;
-import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTree;
import org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTreeNode;
import org.opendaylight.mdsal.binding.dom.codec.impl.NodeCodecContext.CodecContextFactory;
+import org.opendaylight.mdsal.binding.dom.codec.util.BindingSchemaMapping;
import org.opendaylight.mdsal.binding.generator.util.BindingRuntimeContext;
import org.opendaylight.mdsal.binding.model.api.GeneratedType;
-import org.opendaylight.mdsal.binding.spec.naming.BindingMapping;
import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections;
import org.opendaylight.yangtools.concepts.Codec;
import org.opendaylight.yangtools.concepts.Immutable;
import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
import org.opendaylight.yangtools.yang.model.api.TypedDataSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.type.BooleanTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.EmptyTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.InstanceIdentifierTypeDefinition;
private final SchemaRootCodecContext<?> root;
BindingCodecContext(final BindingRuntimeContext context, final BindingNormalizedNodeCodecRegistry registry) {
- this.context = Preconditions.checkNotNull(context, "Binding Runtime Context is required.");
+ this.context = requireNonNull(context, "Binding Runtime Context is required.");
this.root = SchemaRootCodecContext.create(this);
this.identityCodec = new IdentityCodec(context);
this.instanceIdentifierCodec = new InstanceIdentifierCodec(this);
- this.registry = Preconditions.checkNotNull(registry);
+ this.registry = requireNonNull(registry);
}
@Override
DataContainerCodecContext<?,?> currentNode = root;
for (final InstanceIdentifier.PathArgument bindingArg : binding.getPathArguments()) {
currentNode = currentNode.bindingPathArgumentChild(bindingArg, builder);
- Preconditions.checkArgument(currentNode != null, "Supplied Instance Identifier %s is not valid.", binding);
+ checkArgument(currentNode != null, "Supplied Instance Identifier %s is not valid.", binding);
}
return currentNode;
}
* binding representation (choice, case, leaf).
*
*/
- @Nullable NodeCodecContext<?> getCodecContextNode(final @Nonnull YangInstanceIdentifier dom,
+ @Nullable NodeCodecContext<?> getCodecContextNode(final @NonNull YangInstanceIdentifier dom,
final @Nullable Collection<InstanceIdentifier.PathArgument> bindingArguments) {
NodeCodecContext<?> currentNode = root;
ListNodeCodecContext<?> currentList = null;
for (final YangInstanceIdentifier.PathArgument domArg : dom.getPathArguments()) {
- Preconditions.checkArgument(currentNode instanceof DataContainerCodecContext<?,?>,
+ checkArgument(currentNode instanceof DataContainerCodecContext,
"Unexpected child of non-container node %s", currentNode);
- final DataContainerCodecContext<?,?> previous = (DataContainerCodecContext<?,?>) currentNode;
+ final DataContainerCodecContext<?,?> previous = (DataContainerCodecContext<?, ?>) currentNode;
final NodeCodecContext<?> nextNode = previous.yangPathArgumentChild(domArg);
/*
* Identifier as Item or IdentifiableItem
*/
if (currentList != null) {
- Preconditions.checkArgument(currentList == nextNode,
+ checkArgument(currentList == nextNode,
"List should be referenced two times in YANG Instance Identifier %s", dom);
// We entered list, so now we have all information to emit
// We do not add path argument for choice, since
// it is not supported by binding instance identifier.
currentNode = nextNode;
- } else if (nextNode instanceof DataContainerCodecContext<?,?>) {
+ } else if (nextNode instanceof DataContainerCodecContext) {
if (bindingArguments != null) {
- bindingArguments.add(((DataContainerCodecContext<?,?>) nextNode).getBindingPathArgument(domArg));
+ bindingArguments.add(((DataContainerCodecContext<?, ?>) nextNode).getBindingPathArgument(domArg));
}
currentNode = nextNode;
} else if (nextNode instanceof LeafNodeCodecContext) {
- LOG.debug("Instance identifier referencing a leaf is not representable (%s)", dom);
+ LOG.debug("Instance identifier referencing a leaf is not representable ({})", dom);
return null;
}
}
// Algorithm ended in list as whole representation
// we sill need to emit identifier for list
if (currentNode instanceof ChoiceNodeCodecContext) {
- LOG.debug("Instance identifier targeting a choice is not representable (%s)", dom);
+ LOG.debug("Instance identifier targeting a choice is not representable ({})", dom);
return null;
}
if (currentNode instanceof CaseNodeCodecContext) {
- LOG.debug("Instance identifier targeting a case is not representable (%s)", dom);
+ LOG.debug("Instance identifier targeting a case is not representable ({})", dom);
return null;
}
final Map<String, DataSchemaNode> getterToLeafSchema = new HashMap<>();
for (final DataSchemaNode leaf : childSchema.getChildNodes()) {
if (leaf instanceof TypedDataSchemaNode) {
- getterToLeafSchema.put(getGetterName(leaf, ((TypedDataSchemaNode) leaf).getType()), leaf);
+ getterToLeafSchema.put(BindingSchemaMapping.getGetterMethodName((TypedDataSchemaNode) leaf), leaf);
}
}
return getLeafNodesUsingReflection(parentClass, getterToLeafSchema);
}
- private static String getGetterName(final SchemaNode node, final TypeDefinition<?> typeDef) {
- final String suffix = BindingMapping.getGetterSuffix(node.getQName());
- // Bug 8903: If it is a derived type of boolean or empty, not an inner type, then the return type
- // of method would be the generated type of typedef not build-in types, so here it should be 'get'.
- if ((typeDef instanceof BooleanTypeDefinition || typeDef instanceof EmptyTypeDefinition)
- && (typeDef.getPath().equals(node.getPath()) || typeDef.getBaseType() == null)) {
- return "is" + suffix;
- }
- return "get" + suffix;
- }
-
private ImmutableMap<String, LeafNodeCodecContext<?>> getLeafNodesUsingReflection(final Class<?> parentClass,
final Map<String, DataSchemaNode> getterToLeafSchema) {
final Map<String, LeafNodeCodecContext<?>> leaves = new HashMap<>();
for (final Method method : parentClass.getMethods()) {
- if (method.getParameterTypes().length == 0) {
+ if (method.getParameterCount() == 0) {
final DataSchemaNode schema = getterToLeafSchema.get(method.getName());
final Class<?> valueType;
if (schema instanceof LeafSchemaNode) {
}
private Codec<Object, Object> getCodec(final Class<?> valueType, final DataSchemaNode schema) {
- Preconditions.checkArgument(schema instanceof TypedDataSchemaNode, "Unsupported leaf node type %s", schema);
-
+ checkArgument(schema instanceof TypedDataSchemaNode, "Unsupported leaf node type %s", schema);
return getCodec(valueType, ((TypedDataSchemaNode)schema).getType());
}
} else if (typeDef instanceof LeafrefTypeDefinition) {
final Entry<GeneratedType, WithStatus> typeWithSchema = context.getTypeWithSchema(valueType);
final WithStatus schema = typeWithSchema.getValue();
- Preconditions.checkState(schema instanceof TypeDefinition<?>);
+ checkState(schema instanceof TypeDefinition);
return getCodec(valueType, (TypeDefinition<?>) schema);
}
return ValueTypeCodec.getCodecFor(valueType, typeDef);