genCtx.get(module).addTopLevelNodeType(interfaceBuilder);
}
- private static boolean isExplicitStatement(ContainerSchemaNode node) {
+ private static boolean isExplicitStatement(final ContainerSchemaNode node) {
return node instanceof EffectiveStatement
- && ((EffectiveStatement) node).getDeclared().getStatementSource() == StatementSource.DECLARATION;
+ && ((EffectiveStatement<?, ?>) node).getDeclared().getStatementSource() == StatementSource.DECLARATION;
}
/**
* GroupingDefinition which contains data about grouping
* @param module
* current module
- * @return GeneratedType which is generated from grouping (object of type
- * <code>GroupingDefinition</code>)
*/
private void groupingToGenType(final String basePackageName, final GroupingDefinition grouping, final Module module) {
final String packageName = packageNameForGeneratedType(basePackageName, grouping.getPath());
// The original node is required, but we have only the copy of
// the original node.
// Maybe this indicates a bug in Yang parser.
- throw new IllegalStateException(
- "Failed to generate code for augment in "
- + parentUsesNode);
- } else {
- return resultDataSchemaNode;
+ throw new IllegalStateException("Failed to generate code for augment in " + parentUsesNode);
}
- } else {
- throw new IllegalStateException(
- "Target node of uses-augment statement must be DataSchemaNode. Failed to generate code for augment in "
- + parentUsesNode);
+
+ return resultDataSchemaNode;
}
+
+ throw new IllegalStateException(
+ "Target node of uses-augment statement must be DataSchemaNode. Failed to generate code for augment in "
+ + parentUsesNode);
}
/**
private GeneratedTypeBuilder augSchemaNodeToMethods(final Module module, final String basePackageName,
final GeneratedTypeBuilder typeBuilder, final GeneratedTypeBuilder childOf,
final Iterable<DataSchemaNode> schemaNodes) {
- if ((schemaNodes != null) && (typeBuilder != null)) {
+ if (schemaNodes != null && typeBuilder != null) {
for (final DataSchemaNode schemaNode : schemaNodes) {
if (!schemaNode.isAugmenting()) {
addSchemaNodeToBuilderAsMethod(basePackageName, schemaNode, typeBuilder, childOf, module);
* type which represents superior <i>case</i>
* @param choiceNode
* choice case node which is mapped to generated type
- * @return list of generated types for <code>caseNodes</code>.
* @throws IllegalArgumentException
* <ul>
* <li>if <code>basePackageName</code> equals null</li>
* @param augmentedNodes
* set of choice case nodes for which is checked if are/aren't
* added to choice through augmentation
- * @return list of generated types which represents augmented cases of
- * choice <code>refChoiceType</code>
* @throws IllegalArgumentException
* <ul>
* <li>if <code>basePackageName</code> is null</li>
private static TypeDefinition<?> getBaseOrDeclaredType(final TypeDefinition<?> typeDef) {
// Returns DerivedType in case of new parser.
final TypeDefinition<?> baseType = typeDef.getBaseType();
- return (baseType != null && baseType.getBaseType() != null) ? baseType : typeDef;
+ return baseType != null && baseType.getBaseType() != null ? baseType : typeDef;
}
private void processContextRefExtension(final LeafSchemaNode leaf, final MethodSignatureBuilder getter,
*/
private static GeneratedTOBuilder resolveListKeyTOBuilder(final String packageName, final ListSchemaNode list) {
GeneratedTOBuilder genTOBuilder = null;
- if ((list.getKeyDefinition() != null) && (!list.getKeyDefinition().isEmpty())) {
+ if (list.getKeyDefinition() != null && !list.getKeyDefinition().isEmpty()) {
final String listName = list.getQName().getLocalName() + "Key";
final String genTOName = BindingMapping.getClassName(listName);
genTOBuilder = new GeneratedTOBuilderImpl(packageName, genTOName);
final String packageName = typeBuilder.getFullyQualifiedName();
if (typeDef instanceof UnionTypeDefinition) {
final List<GeneratedTOBuilder> types = ((TypeProviderImpl) typeProvider)
- .provideGeneratedTOBuildersForUnionTypeDef(packageName, ((UnionTypeDefinition) typeDef),
+ .provideGeneratedTOBuildersForUnionTypeDef(packageName, (UnionTypeDefinition) typeDef,
classNameFromLeaf, leaf);
genTOBuilders.addAll(types);
resultTOBuilder.addToStringProperty(genPropBuilder);
} else if (typeDef instanceof BitsTypeDefinition) {
- genTOBuilders.add((((TypeProviderImpl) typeProvider)).provideGeneratedTOBuilderForBitsTypeDefinition(
+ genTOBuilders.add(((TypeProviderImpl) typeProvider).provideGeneratedTOBuilderForBitsTypeDefinition(
packageName, typeDef, classNameFromLeaf, parentModule.getName()));
}
if (!genTOBuilders.isEmpty()) {
private static val SKIP = Boolean.getBoolean(SKIP_PROPERTY_NAME);
def static String generateYangSnipet(SchemaNode schemaNode) {
- if (schemaNode == null)
+ if (schemaNode === null)
return ''
if (SKIP)
return '''(Empty due to «SKIP_PROPERTY_NAME» property = true)'''
'''
«FOR moduleImport : moduleImports SEPARATOR "\n"»
- «IF moduleImport != null && !moduleImport.moduleName.nullOrEmpty»
+ «IF moduleImport !== null && !moduleImport.moduleName.nullOrEmpty»
import «moduleImport.moduleName» { prefix "«moduleImport.prefix»"; }
«ENDIF»
«ENDFOR»
«IF !module.imports.nullOrEmpty»
«writeModuleImports(module.imports)»
«ENDIF»
- «IF module.revision != null»
+ «IF module.revision !== null»
«writeRevision(module.revision, module.description)»
«ENDIF»
«IF !module.childNodes.nullOrEmpty»
def private static writeRPCs(Set<RpcDefinition> rpcDefs) {
'''
«FOR rpc : rpcDefs»
- «IF rpc != null»
+ «IF rpc !== null»
«writeRPC(rpc)»
«ENDIF»
«ENDFOR»
«IF !rpc.groupings.nullOrEmpty»
«writeGroupingDefs(rpc.groupings)»
«ENDIF»
- «IF rpc.input != null»
+ «IF rpc.input !== null»
«writeRpcInput(rpc.input)»
«ENDIF»
- «IF rpc.output != null»
+ «IF rpc.output !== null»
«writeRpcOutput(rpc.output)»
«ENDIF»
«IF !rpc.reference.nullOrEmpty»
}
def private static writeRpcInput(ContainerSchemaNode input) {
- if(input == null)
+ if (input === null)
return ''
'''
}
def private static writeRpcOutput(ContainerSchemaNode output) {
- if(output == null)
+ if (output === null)
return ''
'''
def private static writeNotifications(Set<NotificationDefinition> notifications) {
'''
«FOR notification : notifications»
- «IF notification != null»
+ «IF notification !== null»
«writeNotification(notification)»
«ENDIF»
«ENDFOR»
}
def private static writeUsesNodes(Set<UsesNode> usesNodes) {
- if (usesNodes == null) {
+ if (usesNodes === null) {
return ''
}
'''
«FOR usesNode : usesNodes»
- «IF usesNode != null»
+ «IF usesNode !== null»
«writeUsesNode(usesNode)»
«ENDIF»
«ENDFOR»
}
def private static writeIdentity(IdentitySchemaNode identity) {
- if (identity == null)
+ if (identity === null)
return ''
'''
identity «identity.QName.localName» {
- «IF identity.baseIdentity != null»
+ «IF identity.baseIdentity !== null»
base "()«identity.baseIdentity»";
«ENDIF»
«IF !identity.description.nullOrEmpty»
reference
"«identity.reference»";
«ENDIF»
- «IF identity.status != null»
+ «IF identity.status !== null»
status «identity.status»;
«ENDIF»
}
def private static writeFeatures(Set<FeatureDefinition> features) {
'''
«FOR feature : features»
- «IF feature != null»
+ «IF feature !== null»
«writeFeature(feature)»
«ENDIF»
«ENDFOR»
reference
"«featureDef.reference»";
«ENDIF»
- «IF featureDef.status != null»
+ «IF featureDef.status !== null»
status «featureDef.status»;
«ENDIF»
}
def private static writeExtensions(List<ExtensionDefinition> extensions) {
'''
«FOR anExtension : extensions»
- «IF anExtension != null»
+ «IF anExtension !== null»
«writeExtension(anExtension)»
«ENDIF»
«ENDFOR»
reference
"«extensionDef.reference»";
«ENDIF»
- «IF extensionDef.status != null»
+ «IF extensionDef.status !== null»
status «extensionDef.status»;
«ENDIF»
}
def private static writeDeviations(Set<Deviation> deviations) {
'''
«FOR deviation : deviations»
- «IF deviation != null»
+ «IF deviation !== null»
«writeDeviation(deviation)»
«ENDIF»
«ENDFOR»
"«deviation.reference»";
«ENDIF»
«FOR dev : deviation.deviates»
- «IF dev != null && dev.deviateType != null»
+ «IF dev !== null && dev.deviateType !== null»
deviation «dev.deviateType.name»;
«ENDIF»
«ENDFOR»
def private static writeAugments(Set<AugmentationSchema> augments) {
'''
«FOR augment : augments»
- «IF augment != null»
+ «IF augment !== null»
«writeAugment(augment)»
«ENDIF»
«ENDFOR»
def private static CharSequence writeGroupingDefs(Set<GroupingDefinition> groupingDefs) {
'''
«FOR groupingDef : groupingDefs»
- «IF groupingDef != null»
+ «IF groupingDef !== null»
«writeGroupingDef(groupingDef)»
«ENDIF»
«ENDFOR»
def private static writeAugment(AugmentationSchema augment) {
'''
augment «YangTextTemplate.formatToAugmentPath(augment.targetPath.pathFromRoot)» {
- «IF augment.whenCondition != null && !augment.whenCondition.toString.nullOrEmpty»
+ «IF augment.whenCondition !== null && !augment.whenCondition.toString.nullOrEmpty»
when "«augment.whenCondition.toString»";
«ENDIF»
«IF !augment.description.nullOrEmpty»
reference
"«augment.reference»";
«ENDIF»
- «IF augment.status != null»
+ «IF augment.status !== null»
status «augment.status»;
«ENDIF»
«IF !augment.childNodes.nullOrEmpty»
* @param generatedSourceDir the directory in which to put generated source files. If null,
* a default is used (see DefaultSourceCodeGenerator).
*/
- public SourceCodeGenerator getInstance(String generatedSourceDir) {
-
- boolean generateSource = Boolean.valueOf(System.getProperty( GENERATE_CODEC_SOURCE_PROP, "false"));
- if(generateSource) {
+ public SourceCodeGenerator getInstance(final String generatedSourceDir) {
+ boolean generateSource = Boolean.getBoolean(GENERATE_CODEC_SOURCE_PROP);
+ if (generateSource) {
return new DefaultSourceCodeGenerator(generatedSourceDir);
}
throw new IllegalArgumentException("Set of Type Definitions " + "cannot be NULL!");
}
- final List<GroupingDefinition> resultGroupingDefinitions = new ArrayList<GroupingDefinition>();
+ final List<GroupingDefinition> resultGroupingDefinitions = new ArrayList<>();
final Set<Node> unsorted = groupingDefinitionsToNodes(groupingDefinitions);
final List<Node> sortedNodes = TopologicalSort.sort(unsorted);
for (Node node : sortedNodes) {
NodeWrappedType nodeWrappedType = (NodeWrappedType) node;
- resultGroupingDefinitions.add((GroupingDefinition) (nodeWrappedType.getWrappedType()));
+ resultGroupingDefinitions.add((GroupingDefinition) nodeWrappedType.getWrappedType());
}
return resultGroupingDefinitions;
String packageName = BindingGeneratorUtil.packageNameForGeneratedType(basePackageName, typeDefinition.getPath());
String genTOName = BindingMapping.getClassName(typedefName);
String name = packageName + "." + genTOName;
- if (!(returnType.getFullyQualifiedName().equals(name))) {
+ if (!returnType.getFullyQualifiedName().equals(name)) {
returnType = shadedTOWithRestrictions(gto, r);
}
}
} else {
leafRefValueNode = SchemaContextUtil.findDataSchemaNode(schemaContext, parentModule, leafRefStrippedXPath);
}
- return (leafRefValueNode != null) ? leafRefValueNode.equals(parentNode) : false;
+ return leafRefValueNode != null ? leafRefValueNode.equals(parentNode) : false;
}
/**
private Type typedefToGeneratedType(final String basePackageName, final Module module, final TypeDefinition<?> typedef) {
final String moduleName = module.getName();
final Date moduleRevision = module.getRevision();
- if ((basePackageName != null) && (moduleName != null) && (typedef != null) && (typedef.getQName() != null)) {
+ if (basePackageName != null && moduleName != null && typedef != null && typedef.getQName() != null) {
final String typedefName = typedef.getQName().getLocalName();
final TypeDefinition<?> innerTypeDefinition = typedef.getBaseType();
if (!(innerTypeDefinition instanceof LeafrefTypeDefinition)
generatedTOBuilders.add(unionGenTOBuilder);
unionGenTOBuilder.setIsUnion(true);
- final List<String> regularExpressions = new ArrayList<String>();
+ final List<String> regularExpressions = new ArrayList<>();
for (final TypeDefinition<?> unionType : unionTypes) {
final String unionTypeName = unionType.getQName().getLocalName();
if (unionType.getBaseType() != null) {
final String packageName = BindingGeneratorUtil.packageNameForGeneratedType(basePackageName, typedef.getPath());
final String typeDefTOName = typedef.getQName().getLocalName();
- if ((packageName != null) && (typeDefTOName != null)) {
+ if (packageName != null && typeDefTOName != null) {
final String genTOName = BindingMapping.getClassName(typeDefTOName);
final GeneratedTOBuilderImpl newType = new GeneratedTOBuilderImpl(packageName, genTOName);
final String typedefDescription = encodeAngleBrackets(typedef.getDescription());
Map<Integer, List<TypeDefinition<?>>> typeDefinitionsDepths = new TreeMap<>();
for (TypeDefinition<?> unsortedTypeDefinition : unsortedTypeDefinitions) {
- final int depth = getTypeDefinitionDepth(unsortedTypeDefinition);
+ final Integer depth = getTypeDefinitionDepth(unsortedTypeDefinition);
List<TypeDefinition<?>> typeDefinitionsConcreteDepth = typeDefinitionsDepths.get(depth);
if (typeDefinitionsConcreteDepth == null) {
- typeDefinitionsConcreteDepth = new ArrayList<TypeDefinition<?>>();
+ typeDefinitionsConcreteDepth = new ArrayList<>();
typeDefinitionsDepths.put(depth, typeDefinitionsConcreteDepth);
}
typeDefinitionsConcreteDepth.add(unsortedTypeDefinition);
private static String provideAvailableNameForGenTOBuilder(final String name) {
Matcher mtch = NUMBERS_PATTERN.matcher(name);
if (mtch.find()) {
- final int newSuffix = Integer.valueOf(name.substring(mtch.start())) + 1;
+ final int newSuffix = Integer.parseInt(name.substring(mtch.start())) + 1;
return name.substring(0, mtch.start()) + newSuffix;
- } else {
- return name + 1;
}
+
+ return name + 1;
}
public static void addUnitsToGenTO(final GeneratedTOBuilder to, final String units) {
Module parent = getParentModule(node);
Iterator<QName> path = node.getPath().getPathFromRoot().iterator();
path.next();
- if (!(path.hasNext())) {
+ if (!path.hasNext()) {
parentName = BindingMapping.getClassName(parent.getName()) + "Data";
String basePackageName = BindingMapping.getRootPackageName(parent.getQNameModule());
className = basePackageName + "." + parentName + "." + BindingMapping.getClassName(node.getQName());
} else {
Iterator<QName> path = node.getPath().getPathFromRoot().iterator();
QName first = path.next();
- if (!(path.hasNext())) {
+ if (!path.hasNext()) {
URI namespace = first.getNamespace();
Date revision = first.getRevision();
Module parent = schemaContext.findModuleByNamespaceAndRevision(namespace, revision);
- parentName = BindingMapping.getClassName((parent).getName()) + "Data";
+ parentName = BindingMapping.getClassName(parent.getName()) + "Data";
String basePackageName = BindingMapping.getRootPackageName(parent.getQNameModule());
className = basePackageName + "." + parentName + "." + BindingMapping.getClassName(node.getQName());
} else {
@Override
public String getConstructorPropertyName(final SchemaNode node) {
- if (node instanceof TypeDefinition<?>) {
- return "value";
- } else {
- return "";
- }
+ return node instanceof TypeDefinition<?> ? "value" : "";
}
@Override
import java.lang.reflect.Constructor;
import org.junit.Test;
-import org.opendaylight.mdsal.binding.generator.impl.CodecTypeUtils;
import org.opendaylight.yangtools.yang.binding.Identifiable;
import org.opendaylight.yangtools.yang.binding.Identifier;
@Test(expected = UnsupportedOperationException.class)
public void privateConstructTest() throws Throwable {
- final Constructor constructor = CodecTypeUtils.class.getDeclaredConstructor();
+ final Constructor<?> constructor = CodecTypeUtils.class.getDeclaredConstructor();
constructor.setAccessible(true);
try {
constructor.newInstance();
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.IOException;
import java.util.List;
import org.junit.Test;
import org.opendaylight.mdsal.binding.generator.api.BindingGenerator;
-import org.opendaylight.mdsal.binding.generator.impl.BindingGeneratorImpl;
import org.opendaylight.mdsal.binding.model.api.GeneratedProperty;
import org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject;
import org.opendaylight.mdsal.binding.model.api.GeneratedType;
assertEquals(1, listKeyClassPropertyCount);
assertEquals("listKey", listKeyClassPropertyName);
assertEquals("Byte", listKeyClassPropertyTypeName);
- assertEquals(true, listKeyClassPropertyReadOnly);
+ assertTrue(listKeyClassPropertyReadOnly);
assertEquals(1, hashMethodParameterCount);
assertEquals("listKey", hashMethodParameterName);
assertEquals("Byte", hashMethodParameterReturnTypeName);
import javassist.bytecode.AccessFlag;
import javassist.bytecode.ClassFile;
import org.junit.Test;
-import org.opendaylight.mdsal.binding.generator.util.DefaultSourceCodeGenerator;
-import org.opendaylight.mdsal.binding.generator.util.NullSourceCodeGenerator;
-import org.opendaylight.mdsal.binding.generator.util.SourceCodeGenerator;
-import org.opendaylight.mdsal.binding.generator.util.SourceCodeGeneratorFactory;
public class SourceCodeGeneratorFactoryTest {
generator = new DefaultSourceCodeGenerator(dir.getName());
final CtClass ctClass = mock(CtClass.class, CALLS_REAL_METHODS);
- doReturn(false).when(ctClass).isFrozen();
+ doReturn(Boolean.FALSE).when(ctClass).isFrozen();
ctClass.setName("TestClass");
final ClassPool classPool = mock(ClassPool.class);
doReturn(ctClass).when(classPool).get((String) any());
doReturn(ctClass).when(ctClass).getSuperclass();
doReturn(new CtClass[] {ctClass,ctClass}).when(ctClass).getInterfaces();
doReturn(classPool).when(ctClass).getClassPool();
- doReturn(false).when(ctClass).isArray();
- doReturn(false).when(ctClass).isPrimitive();
+ doReturn(Boolean.FALSE).when(ctClass).isArray();
+ doReturn(Boolean.FALSE).when(ctClass).isPrimitive();
doReturn(AccessFlag.toModifier(AccessFlag.PUBLIC)).when(ctClass).getModifiers();
final ClassFile classFile = new ClassFile(false,"test", null);
doReturn(classFile).when(ctClass).getClassFile2();
- doReturn(false).when(ctClass).isFrozen();
+ doReturn(Boolean.FALSE).when(ctClass).isFrozen();
doReturn("testClass").when(ctClass).getName();
final CtField ctField = mock(CtField.class);
doReturn(AccessFlag.toModifier(AccessFlag.PUBLIC)).when(ctField).getModifiers();
assertTrue(cleanup(dir));
}
- private boolean cleanup(File dir) {
- if (!dir.exists()) return true;
+ private static boolean cleanup(final File dir) {
+ if (!dir.exists()) {
+ return true;
+ }
stream(dir.listFiles()).forEach(File::delete);
return dir.delete();
import java.util.List;
import org.junit.Before;
import org.junit.Test;
-import org.opendaylight.mdsal.binding.generator.util.YangSchemaUtils;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
final DataSchemaNode dataSchemaNode = mock(DataSchemaNode.class);
doReturn(Q_NAME).when(UNKNOWN_SCHEMA_NODE).getNodeType();
doReturn(ImmutableList.of(dataSchemaNode)).when(AUGMENTATION_SCHEMA).getChildNodes();
- doReturn(false).when(dataSchemaNode).isAugmenting();
+ doReturn(Boolean.FALSE).when(dataSchemaNode).isAugmenting();
doReturn(Q_NAME).when(dataSchemaNode).getQName();
doReturn(ImmutableList.of(dataSchemaNode)).when(AUGMENTATION_SCHEMA).getChildNodes();
assertEquals(Q_NAME, YangSchemaUtils.getAugmentationQName(AUGMENTATION_SCHEMA));
final QName qName = QName.create(context.getModules().iterator().next().getNamespace(),
context.getModules().iterator().next().getRevision(), context.getModules().iterator().next().getName());
assertNull(YangSchemaUtils.findTypeDefinition(context, SchemaPath.create(ImmutableList.of(qName), false)));
- final List qNames = new ArrayList();
+ final List<QName> qNames = new ArrayList<>();
context.getTypeDefinitions().forEach(typeDefinition -> qNames.add(typeDefinition.getQName()));
assertNull(YangSchemaUtils.findTypeDefinition(context, SchemaPath.create(qNames, false)));
final DataSchemaNode node = mock(DataSchemaNode.class);
doReturn(node).when(container).getDataChildByName((QName) any());
- final TypeDefinition typeDefinition = mock(TypeDefinition.class);
+ final TypeDefinition<?> typeDefinition = mock(TypeDefinition.class);
doReturn(Q_NAME).when(typeDefinition).getQName();
doReturn(ImmutableSet.of(typeDefinition)).when(container).getTypeDefinitions();
assertEquals(typeDefinition,