package org.opendaylight.mdsal.binding2.generator.impl;
-import static com.google.common.base.Preconditions.checkArgument;
-import static com.google.common.base.Preconditions.checkState;
-import static org.opendaylight.mdsal.binding2.generator.impl.GenHelperUtil.findCaseByPath;
-import static org.opendaylight.mdsal.binding2.generator.impl.GenHelperUtil.findChildNodeByPath;
-import static org.opendaylight.mdsal.binding2.generator.impl.GenHelperUtil.processUsesAugments;
-import static org.opendaylight.mdsal.binding2.generator.impl.GenHelperUtil.resolveDataSchemaNodes;
-import static org.opendaylight.mdsal.binding2.generator.util.Binding2GeneratorUtil.packageNameForAugmentedGeneratedType;
-import static org.opendaylight.mdsal.binding2.generator.util.Binding2GeneratorUtil.packageNameForGeneratedType;
-import static org.opendaylight.mdsal.binding2.generator.util.Binding2Mapping.getRootPackageName;
-import static org.opendaylight.yangtools.yang.model.util.SchemaContextUtil.findDataSchemaNode;
-
import com.google.common.annotations.Beta;
import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import org.opendaylight.mdsal.binding2.generator.util.Binding2GeneratorUtil;
+import org.opendaylight.mdsal.binding2.generator.util.Binding2Mapping;
import org.opendaylight.mdsal.binding2.generator.util.ReferencedTypeImpl;
import org.opendaylight.mdsal.binding2.model.api.Type;
import org.opendaylight.mdsal.binding2.model.api.type.builder.GeneratedTypeBuilder;
@Beta
final class AugmentToGenType {
- private AugmentToGenType() {
- throw new UnsupportedOperationException("Utility class");
- }
-
/**
* Comparator based on augment target path.
*/
return otherIt.hasNext() ? -1 : 0;
};
+ private AugmentToGenType() {
+ throw new UnsupportedOperationException("Utility class");
+ }
+
/**
* Converts all <b>augmentation</b> of the module to the list
* <code>Type</code> objects.
* @throws IllegalStateException
* if set of augmentations from module is null
*/
- static Map<Module, ModuleContext> generate(final Module module, final SchemaContext schemaContext, Map<Module,
- ModuleContext> genCtx, Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilders,
+ static Map<Module, ModuleContext> generate(final Module module, final SchemaContext schemaContext,
+ final Map<Module, ModuleContext> genCtx, Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilders,
final boolean verboseClassComments) {
- checkArgument(module != null, "Module reference cannot be NULL.");
- checkArgument(module.getName() != null, "Module name cannot be NULL.");
- checkState(module.getAugmentations() != null, "Augmentations Set cannot be NULL.");
+ Preconditions.checkArgument(module != null, "Module reference cannot be NULL.");
+ Preconditions.checkArgument(module.getName() != null, "Module name cannot be NULL.");
+ Preconditions.checkState(module.getAugmentations() != null, "Augmentations Set cannot be NULL.");
- final String basePackageName = getRootPackageName(module);
+ final String basePackageName = Binding2Mapping.getRootPackageName(module);
final List<AugmentationSchema> augmentations = resolveAugmentations(module);
+ Map<Module, ModuleContext> resultCtx = genCtx;
for (final AugmentationSchema augment : augmentations) {
- genCtx = augmentationToGenTypes(basePackageName, augment, module, schemaContext, verboseClassComments,
- genCtx, genTypeBuilders);
+ resultCtx = augmentationToGenTypes(basePackageName, augment, module, schemaContext, verboseClassComments,
+ resultCtx, genTypeBuilders);
}
- return genCtx;
+ return resultCtx;
}
/**
* if set of module augmentations is null
*/
private static List<AugmentationSchema> resolveAugmentations(final Module module) {
- checkArgument(module != null, "Module reference cannot be NULL.");
- checkState(module.getAugmentations() != null, "Augmentations Set cannot be NULL.");
+ Preconditions.checkArgument(module != null, "Module reference cannot be NULL.");
+ Preconditions.checkState(module.getAugmentations() != null, "Augmentations Set cannot be NULL.");
final Set<AugmentationSchema> augmentations = module.getAugmentations();
final List<AugmentationSchema> sortedAugmentations = new ArrayList<>(augmentations);
Map<Module, ModuleContext> genCtx, Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilders) {
Map<Module, ModuleContext> generatedCtx;
- checkArgument(augmentPackageName != null, "Package Name cannot be NULL.");
- checkArgument(augSchema != null, "Augmentation Schema cannot be NULL.");
- checkState(augSchema.getTargetPath() != null,
+ Preconditions.checkArgument(augmentPackageName != null, "Package Name cannot be NULL.");
+ Preconditions.checkArgument(augSchema != null, "Augmentation Schema cannot be NULL.");
+ Preconditions.checkState(augSchema.getTargetPath() != null,
"Augmentation Schema does not contain Target Path (Target Path is NULL).");
- generatedCtx = processUsesAugments(schemaContext, augSchema, module, genCtx, genTypeBuilders, verboseClassComments);
+ generatedCtx = GenHelperUtil.processUsesAugments(schemaContext, augSchema, module, genCtx, genTypeBuilders,
+ verboseClassComments);
final SchemaPath targetPath = augSchema.getTargetPath();
SchemaNode targetSchemaNode;
- targetSchemaNode = findDataSchemaNode(schemaContext, targetPath);
+ targetSchemaNode = SchemaContextUtil.findDataSchemaNode(schemaContext, targetPath);
if (targetSchemaNode instanceof DataSchemaNode && ((DataSchemaNode) targetSchemaNode).isAddedByUses()) {
if (targetSchemaNode instanceof DerivableSchemaNode) {
targetSchemaNode = ((DerivableSchemaNode) targetSchemaNode).getOriginal().orNull();
throw new IllegalArgumentException("augment target not found: " + targetPath);
}
- GeneratedTypeBuilder targetTypeBuilder = findChildNodeByPath(targetSchemaNode.getPath(), generatedCtx);
+ GeneratedTypeBuilder targetTypeBuilder = GenHelperUtil.findChildNodeByPath(targetSchemaNode.getPath(),
+ generatedCtx);
if (targetTypeBuilder == null) {
- targetTypeBuilder = findCaseByPath(targetSchemaNode.getPath(), generatedCtx);
+ targetTypeBuilder = GenHelperUtil.findCaseByPath(targetSchemaNode.getPath(), generatedCtx);
}
if (targetTypeBuilder == null) {
throw new NullPointerException("Target type not yet generated: " + targetSchemaNode);
final boolean verboseClassComments) {
Map<Module, ModuleContext> generatedCtx;
- checkArgument(augmentPackageName != null, "Package Name cannot be NULL.");
- checkArgument(augSchema != null, "Augmentation Schema cannot be NULL.");
- checkState(augSchema.getTargetPath() != null,
+ Preconditions.checkArgument(augmentPackageName != null, "Package Name cannot be NULL.");
+ Preconditions.checkArgument(augSchema != null, "Augmentation Schema cannot be NULL.");
+ Preconditions.checkState(augSchema.getTargetPath() != null,
"Augmentation Schema does not contain Target Path (Target Path is NULL).");
- generatedCtx = processUsesAugments(schemaContext, augSchema, module, genCtx, genTypeBuilders, verboseClassComments);
+ generatedCtx = GenHelperUtil.processUsesAugments(schemaContext, augSchema, module, genCtx, genTypeBuilders,
+ verboseClassComments);
final SchemaPath targetPath = augSchema.getTargetPath();
final SchemaNode targetSchemaNode = findOriginalTargetFromGrouping(schemaContext, targetPath, usesNode);
if (targetSchemaNode == null) {
throw new IllegalArgumentException("augment target not found: " + targetPath);
}
- GeneratedTypeBuilder targetTypeBuilder = findChildNodeByPath(targetSchemaNode.getPath(), generatedCtx);
+ GeneratedTypeBuilder targetTypeBuilder = GenHelperUtil.findChildNodeByPath(targetSchemaNode.getPath(),
+ generatedCtx);
if (targetTypeBuilder == null) {
- targetTypeBuilder = findCaseByPath(targetSchemaNode.getPath(), generatedCtx);
+ targetTypeBuilder = GenHelperUtil.findCaseByPath(targetSchemaNode.getPath(), generatedCtx);
}
if (targetTypeBuilder == null) {
throw new NullPointerException("Target type not yet generated: " + targetSchemaNode);
if (!(targetSchemaNode instanceof ChoiceSchemaNode)) {
String packageName = augmentPackageName;
if (usesNodeParent instanceof SchemaNode) {
- packageName = packageNameForAugmentedGeneratedType(augmentPackageName, ((SchemaNode) usesNodeParent).getPath());
+ packageName = Binding2GeneratorUtil.packageNameForAugmentedGeneratedType(augmentPackageName,
+ ((SchemaNode) usesNodeParent).getPath());
}
generatedCtx = GenHelperUtil.addRawAugmentGenTypeDefinition(module, packageName, augmentPackageName,
targetTypeBuilder.toInstance(), augSchema, genTypeBuilders, generatedCtx);
final Iterable<DataSchemaNode> augmentedNodes, final DataNodeContainer usesNodeParent,
Map<Module, ModuleContext> genCtx, final boolean verboseClassComments,
Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilders) {
- checkArgument(basePackageName != null, "Base Package Name cannot be NULL.");
- checkArgument(targetType != null, "Referenced Choice Type cannot be NULL.");
- checkArgument(augmentedNodes != null, "Set of Choice Case Nodes cannot be NULL.");
+ Preconditions.checkArgument(basePackageName != null, "Base Package Name cannot be NULL.");
+ Preconditions.checkArgument(targetType != null, "Referenced Choice Type cannot be NULL.");
+ Preconditions.checkArgument(augmentedNodes != null, "Set of Choice Case Nodes cannot be NULL.");
for (final DataSchemaNode caseNode : augmentedNodes) {
if (caseNode != null) {
- final String packageName = packageNameForGeneratedType(basePackageName, caseNode.getPath());
+ final String packageName = Binding2GeneratorUtil.packageNameForGeneratedType(basePackageName,
+ caseNode.getPath());
final GeneratedTypeBuilder caseTypeBuilder = GenHelperUtil.addDefaultInterfaceDefinition(packageName,
caseNode, module, genCtx, schemaContext, verboseClassComments, genTypeBuilders);
caseTypeBuilder.addImplementsType(targetType);
SchemaNode parent;
final SchemaPath nodeSp = targetNode.getPath();
- parent = findDataSchemaNode(schemaContext, nodeSp.getParent());
+ parent = SchemaContextUtil.findDataSchemaNode(schemaContext, nodeSp.getParent());
GeneratedTypeBuilder childOfType = null;
if (parent instanceof Module) {
childOfType = genCtx.get(parent).getModuleNode();
} else if (parent instanceof ChoiceCaseNode) {
- childOfType = findCaseByPath(parent.getPath(), genCtx);
+ childOfType = GenHelperUtil.findCaseByPath(parent.getPath(), genCtx);
} else if (parent instanceof DataSchemaNode || parent instanceof NotificationDefinition) {
- childOfType = findChildNodeByPath(parent.getPath(), genCtx);
+ childOfType = GenHelperUtil.findChildNodeByPath(parent.getPath(), genCtx);
} else if (parent instanceof GroupingDefinition) {
childOfType = GenHelperUtil.findGroupingByPath(parent.getPath(), genCtx);
}
}
final Iterable<DataSchemaNode> childNodes = node.getChildNodes();
if (childNodes != null) {
- resolveDataSchemaNodes(module, basePackageName, caseTypeBuilder, childOfType, childNodes);
+ GenHelperUtil.resolveDataSchemaNodes(module, basePackageName, caseTypeBuilder, childOfType,
+ childNodes);
}
genCtx.get(module).addCaseType(caseNode.getPath(), caseTypeBuilder);
genCtx.get(module).addChoiceToCaseMapping(targetType, caseTypeBuilder, node);
* 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.binding2.generator.impl;
-import static com.google.common.base.Preconditions.checkArgument;
-import static com.google.common.base.Preconditions.checkNotNull;
-import static com.google.common.base.Preconditions.checkState;
-
import com.google.common.annotations.Beta;
+import com.google.common.base.Preconditions;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
private Map<Module, ModuleContext> genCtx = new HashMap<>();
- /**
- * Creates a new binding generator v2.
- *
- * @param verboseClassComments generate verbose comments
- */
- public BindingGeneratorImpl(final boolean verboseClassComments) {
- this.verboseClassComments = verboseClassComments;
- }
-
/**
* Provide methods for converting YANG types to JAVA types.
*/
private SchemaContext schemaContext;
/**
- * Resolves generated types from <code>context</code> schema nodes of all
- * modules.
+ * Creates a new binding generator v2.
+ *
+ * @param verboseClassComments generate verbose comments
+ */
+ public BindingGeneratorImpl(final boolean verboseClassComments) {
+ this.verboseClassComments = verboseClassComments;
+ }
+
+ /**
+ * Resolves generated types from <code>context</code> schema nodes of all modules.
*
- * Generated types are created for modules, groupings, types, containers,
- * lists, choices, augments, rpcs, notification, identities.
+ * Generated types are created for modules, groupings, types, containers, lists, choices, augments, rpcs,
+ * notification, identities.
*
- * @param context
- * schema context which contains data about all schema nodes
- * saved in modules
- * @return list of types (usually <code>GeneratedType</code>
- * <code>GeneratedTransferObject</code>which are generated from
- * <code>context</code> data.
- * @throws IllegalArgumentException
- * if arg <code>context</code> is null
- * @throws IllegalStateException
- * if <code>context</code> contain no modules
+ * @param context schema context which contains data about all schema nodes saved in modules
+ * @return list of types (usually <code>GeneratedType</code> <code>GeneratedTransferObject</code>which are generated
+ * from <code>context</code> data.
+ * @throws IllegalArgumentException if arg <code>context</code> is null
+ * @throws IllegalStateException if <code>context</code> contain no modules
*/
@Override
public List<Type> generateTypes(SchemaContext context) {
- checkArgument(context != null, "Schema Context reference cannot be NULL.");
- checkState(context.getModules() != null, "Schema Context does not contain defined modules.");
+ Preconditions.checkArgument(context != null, "Schema Context reference cannot be NULL.");
+ Preconditions.checkState(context.getModules() != null, "Schema Context does not contain defined modules.");
schemaContext = context;
typeProvider = new TypeProviderImpl(context);
final Set<Module> modules = context.getModules();
@Override
public List<Type> generateTypes(SchemaContext context, Set<Module> modules) {
- checkArgument(context != null, "Schema Context reference cannot be NULL.");
- checkState(context.getModules() != null, "Schema Context does not contain defined modules.");
- checkArgument(modules != null, "Set of Modules cannot be NULL.");
+ Preconditions.checkArgument(context != null, "Schema Context reference cannot be NULL.");
+ Preconditions.checkState(context.getModules() != null, "Schema Context does not contain defined modules.");
+ Preconditions.checkArgument(modules != null, "Set of Modules cannot be NULL.");
schemaContext = context;
typeProvider = new TypeProviderImpl(context);
final List<Type> filteredGenTypes = new ArrayList<>();
for (final Module m : modules) {
- final ModuleContext ctx = checkNotNull(genCtx.get(m), "Module context not found for module %s", m);
+ final ModuleContext ctx = Preconditions.checkNotNull(genCtx.get(m),
+ "Module context not found for module %s", m);
filteredGenTypes.addAll(ctx.getGeneratedTypes());
final Set<Type> additionalTypes = ((TypeProviderImpl) typeProvider).getAdditionalTypes().get(m);
if (additionalTypes != null) {
package org.opendaylight.mdsal.binding2.generator.impl;
-import static com.google.common.base.Preconditions.checkArgument;
-import static org.opendaylight.mdsal.binding2.generator.impl.AugmentToGenType.usesAugmentationToGenTypes;
-import static org.opendaylight.mdsal.binding2.generator.util.BindingTypes.TREE_ROOT;
-import static org.opendaylight.mdsal.binding2.generator.util.BindingTypes.augmentable;
-import static org.opendaylight.mdsal.binding2.generator.util.Types.typeForClass;
-
import com.google.common.annotations.Beta;
import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Preconditions;
import com.google.common.base.Splitter;
import com.google.common.base.Strings;
import com.google.common.collect.Iterables;
import org.opendaylight.mdsal.binding2.model.api.Type;
import org.opendaylight.mdsal.binding2.model.api.type.builder.GeneratedTypeBuilder;
import org.opendaylight.mdsal.binding2.model.api.type.builder.GeneratedTypeBuilderBase;
-import org.opendaylight.mdsal.binding2.txt.yangTemplateForModule;
-import org.opendaylight.mdsal.binding2.txt.yangTemplateForNode;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
import org.opendaylight.yangtools.yang.model.api.UsesNode;
import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
-
+import org.opendaylight.mdsal.binding2.txt.yangTemplateForModule;
+import org.opendaylight.mdsal.binding2.txt.yangTemplateForNode;
/**
* Helper util class used for generation of types in binding spec v2.
@Beta
final class GenHelperUtil {
- private GenHelperUtil() {
- throw new UnsupportedOperationException("Util class");
- }
-
private static final Pattern UNICODE_CHAR_PATTERN = Pattern.compile("\\\\+u");
private static final Splitter BSDOT_SPLITTER = Splitter.on("\\.");
private static final char NEW_LINE = '\n';
*/
private static final String YANG_EXT_NAMESPACE = "urn:opendaylight:yang:extension:yang-ext";
+ private GenHelperUtil() {
+ throw new UnsupportedOperationException("Util class");
+ }
/**
* Create GeneratedTypeBuilder object from module argument.
* if module is null
*/
static GeneratedTypeBuilder moduleToDataType(final Module module, Map<Module, ModuleContext> genCtx, final boolean verboseClassComments) {
- checkArgument(module != null, "Module reference cannot be NULL.");
+ Preconditions.checkArgument(module != null, "Module reference cannot be NULL.");
final GeneratedTypeBuilder moduleDataTypeBuilder = moduleTypeBuilder(module, "Data", verboseClassComments);
addImplementedInterfaceFromUses(module, moduleDataTypeBuilder, genCtx);
- moduleDataTypeBuilder.addImplementsType(TREE_ROOT);
+ moduleDataTypeBuilder.addImplementsType(BindingTypes.TREE_ROOT);
moduleDataTypeBuilder.addComment(module.getDescription());
moduleDataTypeBuilder.setDescription(createDescription(module, verboseClassComments));
moduleDataTypeBuilder.setReference(module.getReference());
* if <code>module</code> is null
*/
static GeneratedTypeBuilder moduleTypeBuilder(final Module module, final String postfix, final boolean verboseClassComments) {
- checkArgument(module != null, "Module reference cannot be NULL.");
+ Preconditions.checkArgument(module != null, "Module reference cannot be NULL.");
final String packageName = Binding2Mapping.getRootPackageName(module);
final String moduleName = Binding2Mapping.getClassName(module.getName()) + postfix;
final String basePackageName = Binding2Mapping.getRootPackageName(module);
for (final UsesNode usesNode : node.getUses()) {
for (final AugmentationSchema augment : usesNode.getAugmentations()) {
- genCtx = usesAugmentationToGenTypes(schemaContext, basePackageName, augment, module, usesNode,
+ genCtx = AugmentToGenType.usesAugmentationToGenTypes(schemaContext, basePackageName, augment, module,
+ usesNode,
node, genCtx, genTypeBuilders, verboseClassComments);
genCtx = processUsesAugments(schemaContext, augment, module, genCtx, genTypeBuilders, verboseClassComments);
}
it.addImplementsType(BindingTypes.treeChildNode(parent));
}
if (!(schemaNode instanceof GroupingDefinition)) {
- it.addImplementsType(augmentable(it));
+ it.addImplementsType(BindingTypes.augmentable(it));
}
if (schemaNode instanceof DataNodeContainer) {
private static GeneratedTypeBuilder addRawInterfaceDefinition(final String packageName, final SchemaNode schemaNode,
final SchemaContext schemaContext, final String prefix, final boolean verboseClassComments,
Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilders) {
- checkArgument(schemaNode != null, "Data Schema Node cannot be NULL.");
- checkArgument(packageName != null, "Package Name for Generated Type cannot be NULL.");
- checkArgument(schemaNode.getQName() != null, "QName for Data Schema Node cannot be NULL.");
+ Preconditions.checkArgument(schemaNode != null, "Data Schema Node cannot be NULL.");
+ Preconditions.checkArgument(packageName != null, "Package Name for Generated Type cannot be NULL.");
+ Preconditions.checkArgument(schemaNode.getQName() != null, "QName for Data Schema Node cannot be NULL.");
final String schemaNodeName = schemaNode.getQName().getLocalName();
- checkArgument(schemaNodeName != null, "Local Name of QName for Data Schema Node cannot be NULL.");
+ Preconditions.checkArgument(schemaNodeName != null, "Local Name of QName for Data Schema Node cannot be NULL.");
String genTypeName;
if (prefix == null) {
private static Constant qNameConstant(final GeneratedTypeBuilderBase<?> toBuilder, final String constantName,
final QName name) {
- return toBuilder.addConstant(typeForClass(QName.class), constantName, name);
+ return toBuilder.addConstant(Types.typeForClass(QName.class), constantName, name);
}
private static String createDescription(final SchemaNode schemaNode, final String fullyQualifiedName,
package org.opendaylight.mdsal.binding2.generator.impl;
-import static com.google.common.base.Preconditions.checkArgument;
-import static com.google.common.base.Preconditions.checkState;
-
import com.google.common.annotations.Beta;
+import com.google.common.base.Preconditions;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
*/
private static Map<Module, ModuleContext> allTypeDefinitionsToGenTypes(final Module module, Map<Module, ModuleContext> genCtx,
TypeProvider typeProvider) {
- checkArgument(module != null, "Module reference cannot be NULL.");
- checkArgument(module.getName() != null, "Module name cannot be NULL.");
+ Preconditions.checkArgument(module != null, "Module reference cannot be NULL.");
+ Preconditions.checkArgument(module.getName() != null, "Module name cannot be NULL.");
final DataNodeIterator it = new DataNodeIterator(module);
final List<TypeDefinition<?>> typeDefinitions = it.allTypedefs();
- checkState(typeDefinitions != null, "Type Definitions for module «module.name» cannot be NULL.");
+ Preconditions.checkState(typeDefinitions != null, "Type Definitions for module «module.name» cannot be NULL.");
typeDefinitions.stream().filter(typedef -> typedef != null).forEach(typedef -> {
final Type type = ((TypeProviderImpl) typeProvider).generatedTypeForExtendedDefinitionType(typedef,
*/
package org.opendaylight.mdsal.binding2.generator.impl.util;
-import static com.google.common.base.Preconditions.checkArgument;
-
import com.google.common.annotations.Beta;
import com.google.common.base.CharMatcher;
import com.google.common.base.Preconditions;
import com.google.common.collect.Iterables;
import java.util.Map;
import java.util.StringTokenizer;
-import java.util.regex.Pattern;
import org.opendaylight.mdsal.binding2.generator.util.Types;
import org.opendaylight.mdsal.binding2.model.api.GeneratedType;
import org.opendaylight.mdsal.binding2.model.api.ParameterizedType;
private static final CharMatcher NL_MATCHER = CharMatcher.is(NEW_LINE);
private static final CharMatcher AMP_MATCHER = CharMatcher.is('&');
private static final Splitter NL_SPLITTER = Splitter.on(NL_MATCHER);
- private static final CharMatcher TAB_MATCHER = CharMatcher.is('\t');
- private static final Pattern SPACES_PATTERN = Pattern.compile(" +");
private YangTextTemplate() {
throw new UnsupportedOperationException("Util class");
*/
public static void putTypeIntoImports(final GeneratedType parentGenType, final Type type,
final Map<String, String> imports) {
- checkArgument(parentGenType != null, "Parent Generated Type parameter MUST be specified and cannot be NULL!");
- checkArgument(type != null, "Type parameter MUST be specified and cannot be NULL!");
- checkArgument(parentGenType.getPackageName() != null,
+ Preconditions.checkArgument(parentGenType != null,
+ "Parent Generated Type parameter MUST be specified and cannot be NULL!");
+ Preconditions.checkArgument(type != null, "Type parameter MUST be specified and cannot be NULL!");
+ Preconditions.checkArgument(parentGenType.getPackageName() != null,
"Parent Generated Type cannot have Package Name referenced as NULL!");
final String typeName = Preconditions.checkNotNull(type.getName());
*/
public static String getExplicitType(final GeneratedType parentGenType, final Type type,
final Map<String, String> imports) {
- checkArgument(type != null, "Type parameter MUST be specified and cannot be NULL!");
- checkArgument(imports != null, "Imports Map cannot be NULL!");
+ Preconditions.checkArgument(type != null, "Type parameter MUST be specified and cannot be NULL!");
+ Preconditions.checkArgument(imports != null, "Imports Map cannot be NULL!");
final String typePackageName = Preconditions.checkNotNull(type.getPackageName());
final String typeName = Preconditions.checkNotNull(type.getName());
if (typePackageName.equals(importedPackageName)) {
builder = new StringBuilder(typeName);
addActualTypeParameters(builder, type, parentGenType, imports);
- if (builder.toString().equals("Void")) {
+ if ("Void".equals(builder.toString())) {
return "void";
}
} else {
package org.opendaylight.mdsal.binding2.generator.yang.types;
-import static org.opendaylight.yangtools.yang.model.util.SchemaContextUtil.findParentModule;
-
import com.google.common.annotations.Beta;
import com.google.common.base.Preconditions;
import java.util.Date;
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
@Beta
public final class TypeProviderImpl implements TypeProvider {
- private static final Logger LOG = LoggerFactory.getLogger(TypeProviderImpl.class);
-
/**
* Contains the schema data red from YANG files.
*/
final TypeDefinition<?> baseTypeDef = baseTypeDefForExtendedType(typeDefinition);
if (!(baseTypeDef instanceof LeafrefTypeDefinition) && !(baseTypeDef instanceof IdentityrefTypeDefinition)) {
- final Module module = findParentModule(schemaContext, parentNode);
+ final Module module = SchemaContextUtil.findParentModule(schemaContext, parentNode);
if (module != null) {
final Map<Date, Map<String, Type>> modulesByDate = genTypeDefsContextMap.get(module.getName());
* This class represents ancestor for other <code>Type</code>s
*/
@Beta
-abstract public class AbstractBaseType implements Type {
+public abstract class AbstractBaseType implements Type {
/**
* Name of the package to which this <code>Type</code> belongs.
import com.google.common.annotations.Beta;
import com.google.common.base.CharMatcher;
-import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
-import java.util.Comparator;
import java.util.Iterator;
-import java.util.List;
-import org.opendaylight.mdsal.binding2.model.api.Restrictions;
-import org.opendaylight.mdsal.binding2.model.api.Type;
-import org.opendaylight.mdsal.binding2.model.api.type.builder.TypeMemberBuilder;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
-import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
-import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
/**
* Standard Util class that contains various method for converting
@Beta
public final class Binding2GeneratorUtil {
- private Binding2GeneratorUtil() {
- throw new UnsupportedOperationException("Utility class");
- }
-
private static final CharMatcher GT_MATCHER = CharMatcher.is('>');
private static final CharMatcher LT_MATCHER = CharMatcher.is('<');
- private static final Restrictions EMPTY_RESTRICTIONS = new Restrictions() {
- @Override
- public List<LengthConstraint> getLengthConstraints() {
- return ImmutableList.of();
- }
-
- @Override
- public List<PatternConstraint> getPatternConstraints() {
- return ImmutableList.of();
- }
-
- @Override
- public List<RangeConstraint> getRangeConstraints() {
- return ImmutableList.of();
- }
-
- @Override
- public boolean isEmpty() {
- return true;
- }
- };
-
- private static final Comparator<TypeMemberBuilder<?>> SUID_MEMBER_COMPARATOR =
- (o1, o2) -> o1.getName().compareTo(o2.getName());
-
- private static final Comparator<Type> SUID_NAME_COMPARATOR =
- (o1, o2) -> o1.getFullyQualifiedName().compareTo(o2.getFullyQualifiedName());
+ private Binding2GeneratorUtil() {
+ throw new UnsupportedOperationException("Utility class");
+ }
/**
* Creates package name from specified <code>basePackageName</code> (package
* @return string with encoded angle brackets
*/
public static String encodeAngleBrackets(String description) {
- if (description != null) {
- description = LT_MATCHER.replaceFrom(description, "<");
- description = GT_MATCHER.replaceFrom(description, ">");
+ String newDesc = description;
+ if (newDesc != null) {
+ newDesc = LT_MATCHER.replaceFrom(newDesc, "<");
+ newDesc = GT_MATCHER.replaceFrom(newDesc, ">");
}
- return description;
+ return newDesc;
}
//TODO: further implementation of static util methods...
package org.opendaylight.mdsal.binding2.generator.util;
-import static com.google.common.base.Preconditions.checkArgument;
-
import com.google.common.annotations.Beta;
import com.google.common.base.CharMatcher;
+import com.google.common.base.Preconditions;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Interner;
@Beta
public final class Binding2Mapping {
- private Binding2Mapping() {
- throw new UnsupportedOperationException("Utility class");
- }
-
public static final Set<String> JAVA_RESERVED_WORDS = ImmutableSet.of("abstract", "assert", "boolean", "break",
"byte", "case", "catch", "char", "class", "const", "continue", "default", "double", "do", "else", "enum",
"extends", "false", "final", "finally", "float", "for", "goto", "if", "implements", "import", "instanceof",
}
};
+ private Binding2Mapping() {
+ throw new UnsupportedOperationException("Utility class");
+ }
+
public static String getRootPackageName(final Module module) {
- checkArgument(module != null, "Module must not be null");
- checkArgument(module.getRevision() != null, "Revision must not be null");
- checkArgument(module.getNamespace() != null, "Namespace must not be null");
+ Preconditions.checkArgument(module != null, "Module must not be null");
+ Preconditions.checkArgument(module.getRevision() != null, "Revision must not be null");
+ Preconditions.checkArgument(module.getNamespace() != null, "Namespace must not be null");
final StringBuilder packageNameBuilder = new StringBuilder();
packageNameBuilder.append(PACKAGE_PREFIX);
case ';':
case '=':
chars[i] = '.';
+ break;
+ default:
+ // no-op, any other character is kept as it is
}
}
}
public static String getClassName(final String localName) {
- checkArgument(localName != null, "Name should not be null.");
+ Preconditions.checkArgument(localName != null, "Name should not be null.");
return toFirstUpper(toCamelCase(localName));
}
private static String toCamelCase(final String rawString) {
- checkArgument(rawString != null, "String should not be null");
+ Preconditions.checkArgument(rawString != null, "String should not be null");
Iterable<String> components = CAMEL_SPLITTER.split(rawString);
StringBuilder builder = new StringBuilder();
for (String comp : components) {
package org.opendaylight.mdsal.binding2.generator.util;
-import static org.opendaylight.mdsal.binding2.generator.util.Types.parameterizedTypeFor;
-import static org.opendaylight.mdsal.binding2.generator.util.Types.typeForClass;
-
import javax.management.NotificationListener;
import org.opendaylight.mdsal.binding2.model.api.ConcreteType;
import org.opendaylight.mdsal.binding2.model.api.ParameterizedType;
public final class BindingTypes {
- public static final ConcreteType AUGMENTABLE = typeForClass(Augmentable.class);
- public static final ConcreteType AUGMENTATION = typeForClass(Augmentation.class);
- public static final ConcreteType TREE_NODE = typeForClass(TreeNode.class);
- public static final ConcreteType TREE_ROOT = typeForClass(TreeRoot.class);
- public static final ConcreteType IDENTIFIABLE_ITEM = typeForClass(IdentifiableItem.class);
- public static final ConcreteType IDENTIFIER = typeForClass(Identifier.class);
- public static final ConcreteType INSTANCE_IDENTIFIER = typeForClass(InstanceIdentifier.class);
- public static final ConcreteType NOTIFICATION = typeForClass(Notification.class);
- public static final ConcreteType NOTIFICATION_LISTENER = typeForClass(NotificationListener.class);
+ public static final ConcreteType AUGMENTABLE = Types.typeForClass(Augmentable.class);
+ public static final ConcreteType AUGMENTATION = Types.typeForClass(Augmentation.class);
+ public static final ConcreteType TREE_NODE = Types.typeForClass(TreeNode.class);
+ public static final ConcreteType TREE_ROOT = Types.typeForClass(TreeRoot.class);
+ public static final ConcreteType IDENTIFIABLE_ITEM = Types.typeForClass(IdentifiableItem.class);
+ public static final ConcreteType IDENTIFIER = Types.typeForClass(Identifier.class);
+ public static final ConcreteType INSTANCE_IDENTIFIER = Types.typeForClass(InstanceIdentifier.class);
+ public static final ConcreteType NOTIFICATION = Types.typeForClass(Notification.class);
+ public static final ConcreteType NOTIFICATION_LISTENER = Types.typeForClass(NotificationListener.class);
- private static final ConcreteType TREE_CHILD_NODE = typeForClass(TreeChildNode.class);
+ private static final ConcreteType TREE_CHILD_NODE = Types.typeForClass(TreeChildNode.class);
private BindingTypes() {
throw new UnsupportedOperationException("Utility class");
}
public static ParameterizedType augmentable(Type t) {
- return parameterizedTypeFor(AUGMENTABLE, t);
+ return Types.parameterizedTypeFor(AUGMENTABLE, t);
}
public static ParameterizedType treeChildNode(Type t) {
- return parameterizedTypeFor(TREE_CHILD_NODE, t);
+ return Types.parameterizedTypeFor(TREE_CHILD_NODE, t);
}
}
return parameterizedTypeFor(augmentation, valueType);
}
-
- public static @Nullable
- String getOuterClassName(final Type valueType) {
+ @Nullable
+ public static String getOuterClassName(final Type valueType) {
final String pkgName = valueType.getPackageName();
if(CharMatcher.JAVA_UPPER_CASE.indexIn(pkgName) >= 0) {
// It is inner class.
*/
private final Type rawType;
- @Override
- public Type[] getActualTypeArguments() {
-
- return actualTypes;
- }
-
- @Override
- public Type getRawType() {
- return rawType;
- }
-
/**
* Creates instance of this class with concrete rawType and array of
* actual parameters.
this.actualTypes = actTypes.clone();
}
+ @Override
+ public Type[] getActualTypeArguments() {
+
+ return actualTypes;
+ }
+
+ @Override
+ public Type getRawType() {
+ return rawType;
+ }
}
/**
}
private static final class DefaultRestrictions<T extends Number> implements Restrictions {
- private final T min;
- private final T max;
private final List<RangeConstraint> rangeConstraints;
private DefaultRestrictions(final T min, final T max) {
- this.min = Preconditions.checkNotNull(min);
- this.max = Preconditions.checkNotNull(max);
+ Preconditions.checkNotNull(min);
+ Preconditions.checkNotNull(max);
this.rangeConstraints = Collections.singletonList(BaseConstraints.newRangeConstraint(min, max, Optional
.absent(), Optional.absent()));
}
import com.google.common.annotations.Beta;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
-import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
private final String name;
private List<Pair> values = ImmutableList.of();
private List<AnnotationTypeBuilder> annotationBuilders = ImmutableList.of();
- private List<Pair> unmodifiableValues = ImmutableList.of();
private String description;
private String reference;
- private Status status;
private String moduleName;
private List<QName> schemaPath;
this.schemaPath = schemaPath;
}
- public void setStatus(final Status status) {
- this.status = status;
- }
-
@Override
public void setDescription(String description) {
this.description = description;
public void addValue(String name, int value, String description, String reference, Status status) {
final EnumPairImpl p = new EnumPairImpl(name, value, description, reference, status);
values = LazyCollections.lazyAdd(values, p);
- unmodifiableValues = Collections.unmodifiableList(values);
}
@Override
public Enumeration toInstance(Type definingType) {
return new EnumerationImpl(definingType, annotationBuilders, packageName, name, values, description,
- reference, status, moduleName, schemaPath);
+ reference, moduleName, schemaPath);
}
@Override
private final Type definingType;
private final String description;
private final String reference;
- private final Status status;
private final String moduleName;
private final List<QName> schemaPath;
private final List<Pair> values;
public EnumerationImpl(final Type definingType, final List<AnnotationTypeBuilder> annotationBuilders,
final String packageName, final String name, final List<Pair> values, final String description,
- final String reference, final Status status, final String moduleName, final
- List<QName> schemaPath) {
+ final String reference, final String moduleName, final List<QName> schemaPath) {
super(packageName, name);
this.definingType = definingType;
this.values = values;
this.description = description;
this.reference = reference;
- this.status = status;
this.moduleName = moduleName;
this.schemaPath = schemaPath;
public List<GeneratedProperty> getProperties() {
return ImmutableList.of();
}
-
- public Status getStatus() {
- return status;
- }
}
}
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
-import java.util.Collections;
import java.util.List;
import org.opendaylight.mdsal.binding2.model.api.GeneratedProperty;
import org.opendaylight.mdsal.binding2.model.api.GeneratedTransferObject;
private boolean isUnionTypeBuilder = false;
private TypeDefinition<?> baseType = null;
private Restrictions restrictions;
- private GeneratedPropertyBuilder SUID;
+ private GeneratedPropertyBuilder suid;
private String reference;
private String description;
private String moduleName;
@Override
public void setSUID(GeneratedPropertyBuilder suid) {
- this.SUID = suid;
+ this.suid = suid;
}
@Override
private final boolean isUnionType;
private final boolean isUnionTypeBuilder;
private final Restrictions restrictions;
- private final GeneratedProperty SUID;
+ private final GeneratedProperty innerSuid;
private final String reference;
private final String description;
private final String moduleName;
this.moduleName = builder.moduleName;
this.schemaPath = builder.schemaPath;
- if (builder.SUID == null) {
- this.SUID = null;
+ if (builder.suid == null) {
+ this.innerSuid = null;
} else {
- this.SUID = builder.SUID.toInstance(GeneratedTransferObjectImpl.this);
+ this.innerSuid = builder.suid.toInstance(GeneratedTransferObjectImpl.this);
}
}
@Override
public GeneratedProperty getSUID() {
- return SUID;
+ return innerSuid;
}
@Override