From: Rashmi Pujar Date: Tue, 11 Oct 2016 16:42:48 +0000 (-0400) Subject: Bug 6859: Cleanup package names for mdsal-binding-generator-util module X-Git-Tag: release/carbon~147 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=cf3131def1de9ec593d47da634a8f735484223e2;p=mdsal.git Bug 6859: Cleanup package names for mdsal-binding-generator-util module The APIs are copied to new package. Added deprecated annotation to the old api. Change-Id: I4a9d6dd6ea78e16bdb1b86c9f9235b3db00db836 Signed-off-by: Rashmi Pujar --- diff --git a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/AbstractBaseType.java b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/AbstractBaseType.java new file mode 100644 index 0000000000..c93e8dac19 --- /dev/null +++ b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/AbstractBaseType.java @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2013 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.mdsal.binding.generator.util; + +import java.util.Objects; +import org.opendaylight.mdsal.binding.model.api.Type; + +/** + * It is used only as ancestor for other Types + * + */ +public class AbstractBaseType implements Type { + + /** + * Name of the package to which this Type belongs. + */ + private final String packageName; + + /** + * Name of this Type. + */ + private final String name; + + @Override + public String getPackageName() { + return packageName; + } + + @Override + public String getName() { + return name; + } + + @Override + public String getFullyQualifiedName() { + if (packageName.isEmpty()) { + return name; + } else { + return packageName + "." + name; + } + } + + /** + * Constructs the instance of this class with the concrete package name type + * name. + * + * @param pkName + * string with the package name to which this Type + * belongs + * @param name + * string with the name for this Type + */ + protected AbstractBaseType(final String pkName, final String name) { + if (pkName == null) { + throw new IllegalArgumentException("Package Name for Generated Type cannot be null!"); + } + if (name == null) { + throw new IllegalArgumentException("Name of Generated Type cannot be null!"); + } + this.packageName = pkName; + this.name = name; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + Objects.hashCode(name); + result = prime * result + Objects.hashCode(packageName); + return result; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (!(obj instanceof Type)) { + return false; + } + Type other = (Type) obj; + return Objects.equals(name, other.getName()) && Objects.equals(packageName, other.getPackageName()); + } + + @Override + public String toString() { + if (packageName.isEmpty()) { + return "Type (" + name + ")"; + } + return "Type (" + packageName + "." + name + ")"; + } +} diff --git a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/BindingGeneratorUtil.java b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/BindingGeneratorUtil.java new file mode 100644 index 0000000000..f79ae30cc4 --- /dev/null +++ b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/BindingGeneratorUtil.java @@ -0,0 +1,644 @@ +/* + * Copyright (c) 2014 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.mdsal.binding.generator.util; + +import com.google.common.base.CharMatcher; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableList.Builder; +import com.google.common.collect.Iterables; +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.Iterator; +import java.util.List; +import org.opendaylight.mdsal.binding.model.api.AccessModifier; +import org.opendaylight.mdsal.binding.model.api.Restrictions; +import org.opendaylight.mdsal.binding.model.api.Type; +import org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedPropertyBuilder; +import org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedTypeBuilderBase; +import org.opendaylight.mdsal.binding.model.api.type.builder.MethodSignatureBuilder; +import org.opendaylight.mdsal.binding.model.api.type.builder.TypeMemberBuilder; +import org.opendaylight.yangtools.yang.binding.BindingMapping; +import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.common.QNameModule; +import org.opendaylight.yangtools.yang.model.api.Module; +import org.opendaylight.yangtools.yang.model.api.SchemaPath; +import org.opendaylight.yangtools.yang.model.api.TypeDefinition; +import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition; +import org.opendaylight.yangtools.yang.model.api.type.DecimalTypeDefinition; +import org.opendaylight.yangtools.yang.model.api.type.IntegerTypeDefinition; +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; +import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition; +import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinition; +import org.opendaylight.yangtools.yang.model.util.type.BaseTypes; +import org.opendaylight.yangtools.yang.model.util.type.DecimalTypeBuilder; + +/** + * Contains the methods for converting strings to valid JAVA language strings + * (package names, class names, attribute names) and to valid javadoc comments. + * + * + */ +public final class BindingGeneratorUtil { + + /** + * Impossible to instantiate this class. All of the methods or attributes + * are static. + */ + private BindingGeneratorUtil() { + } + + /** + * Pre-compiled replacement pattern. + */ + private static final CharMatcher DOT_MATCHER = CharMatcher.is('.'); + private static final CharMatcher DASH_COLON_MATCHER = CharMatcher.anyOf("-:"); + 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 getLengthConstraints() { + return Collections.emptyList(); + } + + @Override + public List getPatternConstraints() { + return Collections.emptyList(); + } + + @Override + public List getRangeConstraints() { + return Collections.emptyList(); + } + + @Override + public boolean isEmpty() { + return true; + } + }; + + private static final Comparator> SUID_MEMBER_COMPARATOR = + (o1, o2) -> o1.getName().compareTo(o2.getName()); + + private static final Comparator SUID_NAME_COMPARATOR = + (o1, o2) -> o1.getFullyQualifiedName().compareTo(o2.getFullyQualifiedName()); + + /** + * Converts parameterName to valid JAVA parameter name. + * + * If the parameterName is one of the JAVA reserved words then + * it is prefixed with underscore character. + * + * @param parameterName + * string with the parameter name + * @return string with the admissible parameter name + */ + public static String resolveJavaReservedWordEquivalency(final String parameterName) { + if (parameterName != null && BindingMapping.JAVA_RESERVED_WORDS.contains(parameterName)) { + return "_" + parameterName; + } + return parameterName; + } + + /** + * Converts module name to valid JAVA package name. + * + * The package name consists of: + *
    + *
  • prefix - org.opendaylight.yang.gen.v
  • + *
  • module YANG version - org.opendaylight.yang.gen.v
  • + *
  • module namespace - invalid characters are replaced with dots
  • + *
  • revision prefix - .rev
  • + *
  • revision - YYYYMMDD (MM and DD aren't spread to the whole length)
  • + *
+ * + * @param module + * module which contains data about namespace and revision date + * @return string with the valid JAVA package name + * @throws IllegalArgumentException + * if the revision date of the module equals + * null + * @deprecated USe {@link BindingMapping#getRootPackageName(QNameModule)} with {@link Module#getQNameModule()}. + */ + @Deprecated + public static String moduleNamespaceToPackageName(final Module module) { + return BindingMapping.getRootPackageName(module.getQNameModule()); + } + + /** + * Creates package name from specified basePackageName (package + * name for module) and schemaPath. + * + * Resulting package name is concatenation of basePackageName + * and all local names of YANG nodes which are parents of some node for + * which schemaPath is specified. + * + * @param basePackageName + * string with package name of the module, MUST be normalized, + * otherwise this method may return an invalid string. + * @param schemaPath + * list of names of YANG nodes which are parents of some node + + * name of this node + * @return string with valid JAVA package name + * @throws NullPointerException if any of the arguments are null + */ + public static String packageNameForGeneratedType(final String basePackageName, final SchemaPath schemaPath) { + final int size = Iterables.size(schemaPath.getPathTowardsRoot()) - 1; + if (size <= 0) { + return basePackageName; + } + + return generateNormalizedPackageName(basePackageName, schemaPath.getPathFromRoot(), size); + } + + /** + * Creates package name from specified basePackageName (package + * name for module) and schemaPath which crosses an augmentation. + * + * Resulting package name is concatenation of basePackageName + * and all local names of YANG nodes which are parents of some node for + * which schemaPath is specified. + * + * @param basePackageName + * string with package name of the module, MUST be normalized, + * otherwise this method may return an invalid string. + * @param schemaPath + * list of names of YANG nodes which are parents of some node + + * name of this node + * @return string with valid JAVA package name + * @throws NullPointerException if any of the arguments are null + */ + public static String packageNameForAugmentedGeneratedType(final String basePackageName, final SchemaPath schemaPath) { + final int size = Iterables.size(schemaPath.getPathTowardsRoot()); + if (size == 0) { + return basePackageName; + } + + return generateNormalizedPackageName(basePackageName, schemaPath.getPathFromRoot(), size); + } + + private static String generateNormalizedPackageName(final String base, final Iterable path, final int size) { + final StringBuilder builder = new StringBuilder(base); + final Iterator iterator = path.iterator(); + for (int i = 0; i < size; ++i) { + builder.append('.'); + String nodeLocalName = iterator.next().getLocalName(); + // FIXME: Collon ":" is invalid in node local name as per RFC6020, identifier statement. + builder.append(DASH_COLON_MATCHER.replaceFrom(nodeLocalName, '.')); + } + return BindingMapping.normalizePackageName(builder.toString()); + } + + /** + * Creates package name from specified basePackageName (package + * name for module) and schemaPath. + * + * Resulting package name is concatenation of basePackageName + * and all local names of YANG nodes which are parents of some node for + * which schemaPath is specified. + * + * @param basePackageName + * string with package name of the module + * @param schemaPath + * list of names of YANG nodes which are parents of some node + + * name of this node + * @param isUsesAugment + * boolean true if using augment + * @return string with valid JAVA package name + * + * @deprecated Use {@link #packageNameForGeneratedType(String, SchemaPath)} or + * {@link #packageNameForAugmentedGeneratedType(String, SchemaPath)} instead. + */ + @Deprecated + public static String packageNameForGeneratedType(final String basePackageName, final SchemaPath schemaPath, + final boolean isUsesAugment) { + if (basePackageName == null) { + throw new IllegalArgumentException("Base Package Name cannot be NULL!"); + } + if (schemaPath == null) { + throw new IllegalArgumentException("Schema Path cannot be NULL!"); + } + + final Iterable iterable = schemaPath.getPathFromRoot(); + final int size = Iterables.size(iterable); + final int traversalSteps; + if (isUsesAugment) { + traversalSteps = size; + } else { + traversalSteps = size - 1; + } + + if (traversalSteps == 0) { + return BindingMapping.normalizePackageName(basePackageName); + } + + return generateNormalizedPackageName(basePackageName, iterable, traversalSteps); + } + + /** + * Generates the package name for type definition from + * typeDefinition and basePackageName. + * + * @param basePackageName + * string with the package name of the module + * @param typeDefinition + * type definition for which the package name will be generated * + * @return string with valid JAVA package name + * @throws IllegalArgumentException + *
    + *
  • if basePackageName equals null
  • + *
  • if typeDefinition equals null
  • + *
+ * @deprecated This method ignores typeDefinition argument and its result is only + * BindingMapping.normalizePackageName(basePackageName). + * Aside from tests, there is not a single user in OpenDaylight codebase, + * hence it can be considered buggy and defunct. It is scheduled for removal + * in Boron release. + */ + @Deprecated + public static String packageNameForTypeDefinition(final String basePackageName, + final TypeDefinition typeDefinition) { + if (basePackageName == null) { + throw new IllegalArgumentException("Base Package Name cannot be NULL!"); + } + if (typeDefinition == null) { + throw new IllegalArgumentException("Type Definition reference cannot be NULL!"); + } + + return BindingMapping.normalizePackageName(basePackageName); + } + + /** + * Converts token to string which is in accordance with best + * practices for JAVA class names. + * + * @param token + * string which contains characters which should be converted to + * JAVA class name + * @return string which is in accordance with best practices for JAVA class + * name. + * + * @deprecated Use {@link BindingMapping#getClassName(QName)} instead. + */ + @Deprecated + public static String parseToClassName(final String token) { + return parseToCamelCase(token, true); + } + + /** + * Converts token to string which is in accordance with best + * practices for JAVA parameter names. + * + * @param token + * string which contains characters which should be converted to + * JAVA parameter name + * @return string which is in accordance with best practices for JAVA + * parameter name. + * + * @deprecated Use {@link BindingMapping#getPropertyName(String)} instead. + */ + @Deprecated public static String parseToValidParamName(final String token) { + return resolveJavaReservedWordEquivalency(parseToCamelCase(token, false)); + } + + /** + * + * Converts string token to the cammel case format. + * + * @param token + * string which should be converted to the cammel case format + * @param uppercase + * boolean value which says whether the first character of the + * token should|shuldn't be uppercased + * @return string in the cammel case format + * @throws IllegalArgumentException + *
    + *
  • if token without white spaces is empty
  • + *
  • if token equals null
  • + *
+ */ + private static String parseToCamelCase(final String token, final boolean uppercase) { + if (token == null) { + throw new IllegalArgumentException("Name can not be null"); + } + + String correctStr = DOT_MATCHER.removeFrom(token.trim()); + if (correctStr.isEmpty()) { + throw new IllegalArgumentException("Name can not be empty"); + } + + correctStr = replaceWithCamelCase(correctStr, ' '); + correctStr = replaceWithCamelCase(correctStr, '-'); + correctStr = replaceWithCamelCase(correctStr, '_'); + + char firstChar = correctStr.charAt(0); + firstChar = uppercase ? Character.toUpperCase(firstChar) : Character.toLowerCase(firstChar); + + if (firstChar >= '0' && firstChar <= '9') { + return '_' + correctStr; + } else { + return firstChar + correctStr.substring(1); + } + } + + /** + * Replaces all the occurrences of the removalChar in the + * text with empty string and converts following character to + * upper case. + * + * @param text + * string with source text which should be converted + * @param removalChar + * character which is sought in the text + * @return string which doesn't contain removalChar and has + * following characters converted to upper case + * @throws IllegalArgumentException + * if the length of the returning string has length 0 + */ + private static String replaceWithCamelCase(final String text, final char removalChar) { + int toBeRemovedPos = text.indexOf(removalChar); + if (toBeRemovedPos == -1) { + return text; + } + + StringBuilder sb = new StringBuilder(text); + String toBeRemoved = String.valueOf(removalChar); + do { + sb.replace(toBeRemovedPos, toBeRemovedPos + 1, ""); + // check if 'toBeRemoved' character is not the only character in + // 'text' + if (sb.length() == 0) { + throw new IllegalArgumentException("The resulting string can not be empty"); + } + char replacement = Character.toUpperCase(sb.charAt(toBeRemovedPos)); + sb.setCharAt(toBeRemovedPos, replacement); + toBeRemovedPos = sb.indexOf(toBeRemoved); + } while (toBeRemovedPos != -1); + + return sb.toString(); + } + + private static Iterable sortedCollection(final Comparator comparator, final Collection input) { + if (input.size() > 1) { + final List ret = new ArrayList<>(input); + Collections.sort(ret, comparator); + return ret; + } else { + return input; + } + } + + private static final ThreadLocal SHA1_MD = new ThreadLocal() { + @Override + protected MessageDigest initialValue() { + try { + return MessageDigest.getInstance("SHA"); + } catch (NoSuchAlgorithmException e) { + throw new IllegalStateException("Failed to get a SHA digest provider", e); + } + } + }; + + public static long computeDefaultSUID(final GeneratedTypeBuilderBase to) { + final ByteArrayOutputStream bout = new ByteArrayOutputStream(); + try (final DataOutputStream dout = new DataOutputStream(bout)) { + dout.writeUTF(to.getName()); + dout.writeInt(to.isAbstract() ? 3 : 7); + + for (Type ifc : sortedCollection(SUID_NAME_COMPARATOR, to.getImplementsTypes())) { + dout.writeUTF(ifc.getFullyQualifiedName()); + } + + for (GeneratedPropertyBuilder gp : sortedCollection(SUID_MEMBER_COMPARATOR, to.getProperties())) { + dout.writeUTF(gp.getName()); + } + + for (MethodSignatureBuilder m : sortedCollection(SUID_MEMBER_COMPARATOR, to.getMethodDefinitions())) { + if (!(m.getAccessModifier().equals(AccessModifier.PRIVATE))) { + dout.writeUTF(m.getName()); + dout.write(m.getAccessModifier().ordinal()); + } + } + + dout.flush(); + } catch (IOException e) { + throw new IllegalStateException("Failed to hash object " + to, e); + } + + final byte[] hashBytes = SHA1_MD.get().digest(bout.toByteArray()); + long hash = 0; + for (int i = Math.min(hashBytes.length, 8) - 1; i >= 0; i--) { + hash = (hash << 8) | (hashBytes[i] & 0xFF); + } + return hash; + } + + private static List currentOrEmpty(final List current, final List base) { + return current.equals(base) ? ImmutableList.of() : current; + } + + private static boolean containsConstraint(final StringTypeDefinition type, final PatternConstraint constraint) { + for (StringTypeDefinition wlk = type; wlk != null; wlk = wlk.getBaseType()) { + if (wlk.getPatternConstraints().contains(constraint)) { + return true; + } + } + + return false; + } + + private static List uniquePatterns(final StringTypeDefinition type) { + final List constraints = type.getPatternConstraints(); + if (constraints.isEmpty()) { + return constraints; + } + + final Builder builder = ImmutableList.builder(); + boolean filtered = false; + for (PatternConstraint c : constraints) { + if (containsConstraint(type.getBaseType(), c)) { + filtered = true; + } else { + builder.add(c); + } + } + + return filtered ? builder.build() : constraints; + } + + public static Restrictions getRestrictions(final TypeDefinition type) { + // Old parser generated types which actually contained based restrictions, but our code deals with that when + // binding to core Java types. Hence we'll emit empty restrictions for base types. + if (type == null || type.getBaseType() == null) { + // Handling of decimal64 has changed in the new parser. It contains range restrictions applied to the type + // directly, without an extended type. We need to capture such constraints. In order to retain behavior we + // need to analyze the new semantics and see if the constraints have been overridden. To do that we + // instantiate a temporary unconstrained type and compare them. + // + // FIXME: looking at the generated code it looks as though we need to pass the restrictions without + // comparison + if (type instanceof DecimalTypeDefinition) { + final DecimalTypeDefinition decimal = (DecimalTypeDefinition) type; + final DecimalTypeBuilder tmpBuilder = BaseTypes.decimalTypeBuilder(decimal.getPath()); + tmpBuilder.setFractionDigits(decimal.getFractionDigits()); + final DecimalTypeDefinition tmp = tmpBuilder.build(); + + if (!tmp.getRangeConstraints().equals(decimal.getRangeConstraints())) { + return new Restrictions() { + @Override + public boolean isEmpty() { + return false; + } + + @Override + public List getRangeConstraints() { + return decimal.getRangeConstraints(); + } + + @Override + public List getPatternConstraints() { + return ImmutableList.of(); + } + + @Override + public List getLengthConstraints() { + return ImmutableList.of(); + } + }; + } + } + + return EMPTY_RESTRICTIONS; + } + + final List length; + final List pattern; + final List range; + + /* + * Take care of extended types. + * + * Other types which support constraints are check afterwards. There is a slight twist with them, as returned + * constraints are the effective view, e.g. they are inherited from base type. Since the constraint is already + * enforced by the base type, we want to skip them and not perform duplicate checks. + * + * We end up emitting ConcreteType instances for YANG base types, which leads to their constraints not being + * enforced (most notably decimal64). Therefore we need to make sure we do not strip the next-to-last + * restrictions. + * + * FIXME: this probably not the best solution and needs further analysis. + */ + if (type instanceof BinaryTypeDefinition) { + final BinaryTypeDefinition binary = (BinaryTypeDefinition)type; + final BinaryTypeDefinition base = binary.getBaseType(); + if (base != null && base.getBaseType() != null) { + length = currentOrEmpty(binary.getLengthConstraints(), base.getLengthConstraints()); + } else { + length = binary.getLengthConstraints(); + } + + pattern = ImmutableList.of(); + range = ImmutableList.of(); + } else if (type instanceof DecimalTypeDefinition) { + length = ImmutableList.of(); + pattern = ImmutableList.of(); + + final DecimalTypeDefinition decimal = (DecimalTypeDefinition)type; + final DecimalTypeDefinition base = decimal.getBaseType(); + if (base != null && base.getBaseType() != null) { + range = currentOrEmpty(decimal.getRangeConstraints(), base.getRangeConstraints()); + } else { + range = decimal.getRangeConstraints(); + } + } else if (type instanceof IntegerTypeDefinition) { + length = ImmutableList.of(); + pattern = ImmutableList.of(); + + final IntegerTypeDefinition integer = (IntegerTypeDefinition)type; + final IntegerTypeDefinition base = integer.getBaseType(); + if (base != null && base.getBaseType() != null) { + range = currentOrEmpty(integer.getRangeConstraints(), base.getRangeConstraints()); + } else { + range = integer.getRangeConstraints(); + } + } else if (type instanceof StringTypeDefinition) { + final StringTypeDefinition string = (StringTypeDefinition)type; + final StringTypeDefinition base = string.getBaseType(); + if (base != null && base.getBaseType() != null) { + length = currentOrEmpty(string.getLengthConstraints(), base.getLengthConstraints()); + } else { + length = string.getLengthConstraints(); + } + + pattern = uniquePatterns(string); + range = ImmutableList.of(); + } else if (type instanceof UnsignedIntegerTypeDefinition) { + length = ImmutableList.of(); + pattern = ImmutableList.of(); + + final UnsignedIntegerTypeDefinition unsigned = (UnsignedIntegerTypeDefinition)type; + final UnsignedIntegerTypeDefinition base = unsigned.getBaseType(); + if (base != null && base.getBaseType() != null) { + range = currentOrEmpty(unsigned.getRangeConstraints(), base.getRangeConstraints()); + } else { + range = unsigned.getRangeConstraints(); + } + } else { + length = ImmutableList.of(); + pattern = ImmutableList.of(); + range = ImmutableList.of(); + } + + // Now, this may have ended up being empty, too... + if (length.isEmpty() && pattern.isEmpty() && range.isEmpty()) { + return EMPTY_RESTRICTIONS; + } + + // Nope, not empty allocate a holder + return new Restrictions() { + @Override + public List getRangeConstraints() { + return range; + } + @Override + public List getPatternConstraints() { + return pattern; + } + @Override + public List getLengthConstraints() { + return length; + } + @Override + public boolean isEmpty() { + return false; + } + }; + } + + /** + * Encodes angle brackets in yang statement description + * @param description description of a yang statement which is used to generate javadoc comments + * @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, ">"); + } + return description; + } +} diff --git a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/BindingTypes.java b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/BindingTypes.java new file mode 100644 index 0000000000..4769234d8b --- /dev/null +++ b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/BindingTypes.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2013 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.mdsal.binding.generator.util; + +import static org.opendaylight.mdsal.binding.generator.util.Types.parameterizedTypeFor; +import static org.opendaylight.mdsal.binding.generator.util.Types.typeForClass; + +import org.opendaylight.mdsal.binding.model.api.ConcreteType; +import org.opendaylight.mdsal.binding.model.api.ParameterizedType; +import org.opendaylight.mdsal.binding.model.api.Type; +import org.opendaylight.yangtools.yang.binding.Augmentable; +import org.opendaylight.yangtools.yang.binding.Augmentation; +import org.opendaylight.yangtools.yang.binding.BaseIdentity; +import org.opendaylight.yangtools.yang.binding.ChildOf; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.DataRoot; +import org.opendaylight.yangtools.yang.binding.Identifiable; +import org.opendaylight.yangtools.yang.binding.Identifier; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.binding.Notification; +import org.opendaylight.yangtools.yang.binding.NotificationListener; +import org.opendaylight.yangtools.yang.binding.RpcService; + +public final class BindingTypes { + + public static final ConcreteType AUGMENTABLE = typeForClass(Augmentable.class); + public static final ConcreteType AUGMENTATION = typeForClass(Augmentation.class); + public static final ConcreteType BASE_IDENTITY = typeForClass(BaseIdentity.class); + public static final ConcreteType DATA_OBJECT = typeForClass(DataObject.class); + public static final ConcreteType DATA_ROOT = typeForClass(DataRoot.class); + public static final ConcreteType IDENTIFIABLE = typeForClass(Identifiable.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 RPC_SERVICE = typeForClass(RpcService.class); + + private static final ConcreteType CHILD_OF = typeForClass(ChildOf.class); + + private BindingTypes() { + + } + + public static ParameterizedType augmentable(Type t) { + return parameterizedTypeFor(AUGMENTABLE, t); + } + + public static ParameterizedType childOf(Type t) { + return parameterizedTypeFor(CHILD_OF, t); + } + +} diff --git a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/ReferencedTypeImpl.java b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/ReferencedTypeImpl.java new file mode 100644 index 0000000000..5c3585bb99 --- /dev/null +++ b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/ReferencedTypeImpl.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2013 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.mdsal.binding.generator.util; + +/** + * + * Wraps combination of packageName and name to the + * object representation + * + */ +public final class ReferencedTypeImpl extends AbstractBaseType { + + /** + * Creates instance of this class with concrete package name and type name + * + * @param packageName + * string with the package name + * @param name + * string with the name for referenced type + */ + public ReferencedTypeImpl(String packageName, String name) { + super(packageName, name); + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("ReferencedTypeImpl [packageName="); + builder.append(getPackageName()); + builder.append(", name="); + builder.append(getName()); + builder.append("]"); + return builder.toString(); + } +} diff --git a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/TypeConstants.java b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/TypeConstants.java new file mode 100644 index 0000000000..c1d1e2ded7 --- /dev/null +++ b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/TypeConstants.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2014 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.mdsal.binding.generator.util; + +/** + * + * Contains constants used in relations with Type. + */ +public final class TypeConstants { + + /** + * Name of the class constant which hold list of the regular expression + * strings. + */ + public static final String PATTERN_CONSTANT_NAME = "PATTERN_CONSTANTS"; + + /** + * Creation of new instance is prohibited. + */ + private TypeConstants() { + } +} diff --git a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/Types.java b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/Types.java new file mode 100644 index 0000000000..3e08b42cc0 --- /dev/null +++ b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/Types.java @@ -0,0 +1,390 @@ +/* + * Copyright (c) 2013 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.mdsal.binding.generator.util; + +import com.google.common.base.CharMatcher; +import com.google.common.base.Optional; +import com.google.common.base.Preconditions; +import com.google.common.base.Splitter; +import com.google.common.cache.CacheBuilder; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; +import com.google.common.collect.Iterables; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.Future; +import javax.annotation.Nullable; +import org.opendaylight.mdsal.binding.model.api.BaseTypeWithRestrictions; +import org.opendaylight.mdsal.binding.model.api.ConcreteType; +import org.opendaylight.mdsal.binding.model.api.ParameterizedType; +import org.opendaylight.mdsal.binding.model.api.Restrictions; +import org.opendaylight.mdsal.binding.model.api.Type; +import org.opendaylight.mdsal.binding.model.api.WildcardType; +import org.opendaylight.yangtools.yang.binding.Augmentable; +import org.opendaylight.yangtools.yang.binding.Augmentation; +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; +import org.opendaylight.yangtools.yang.model.util.BaseConstraints; + +public final class Types { + private static final CacheLoader, ConcreteType> TYPE_LOADER = + new CacheLoader, ConcreteType>() { + @Override + public ConcreteType load(final Class key) { + return new ConcreteTypeImpl(key.getPackage().getName(), key.getSimpleName(), null); + } + }; + private static final LoadingCache, ConcreteType> TYPE_CACHE = + CacheBuilder.newBuilder().weakKeys().build(TYPE_LOADER); + + private static final Type SET_TYPE = typeForClass(Set.class); + private static final Type LIST_TYPE = typeForClass(List.class); + private static final Type MAP_TYPE = typeForClass(Map.class); + + public static final ConcreteType BOOLEAN = typeForClass(Boolean.class); + public static final ConcreteType FUTURE = typeForClass(Future.class); + public static final ConcreteType STRING = typeForClass(String.class); + public static final ConcreteType VOID = typeForClass(Void.class); + public static final ConcreteType BYTE_ARRAY = primitiveType("byte[]", null); + public static final ConcreteType CHAR_ARRAY = primitiveType("char[]", null); + private static final Splitter DOT_SPLITTER = Splitter.on('.'); + + /** + * It is not desirable to create instance of this class + */ + private Types() { + } + + /** + * Creates the instance of type + * {@link org.opendaylight.yangtools.sal.binding.model.api.ConcreteType + * ConcreteType} which represents JAVA void type. + * + * @return ConcreteType instance which represents JAVA + * void + */ + public static ConcreteType voidType() { + return VOID; + } + + /** + * Creates the instance of type + * {@link org.opendaylight.yangtools.sal.binding.model.api.ConcreteType + * ConcreteType} which represents primitive JAVA type for which package + * doesn't exist. + * + * @param primitiveType + * string containing programmatic construction based on + * primitive type (e.g byte[]) + * @param restrictions + * restrictions object + * @return ConcreteType instance which represents programmatic + * construction with primitive JAVA type + */ + public static ConcreteType primitiveType(final String primitiveType, final Restrictions restrictions) { + return new ConcreteTypeImpl("", primitiveType, restrictions); + } + + /** + * Returns an instance of {@link ConcreteType} describing the class + * + * @param cls + * Class to describe + * @return Description of class + */ + public static ConcreteType typeForClass(final Class cls) { + return TYPE_CACHE.getUnchecked(cls); + } + + public static ConcreteType typeForClass(final Class cls, final Restrictions restrictions) { + if (restrictions != null) { + if (restrictions instanceof DefaultRestrictions) { + return new ConcreteTypeImpl(cls.getPackage().getName(), cls.getSimpleName(), restrictions); + } else { + return new BaseTypeWithRestrictionsImpl(cls.getPackage().getName(), cls.getSimpleName(), restrictions); + } + } else { + return typeForClass(cls); + } + } + + /** + * Returns an instance of {@link ParameterizedType} describing the typed + * {@link Map}<K,V> + * + * @param keyType + * Key Type + * @param valueType + * Value Type + * @return Description of generic type instance + */ + public static ParameterizedType mapTypeFor(final Type keyType, final Type valueType) { + return parameterizedTypeFor(MAP_TYPE, keyType, valueType); + } + + /** + * Returns an instance of {@link ParameterizedType} describing the typed + * {@link Set}<V> with concrete type of value. + * + * @param valueType + * Value Type + * @return Description of generic type instance of Set + */ + public static ParameterizedType setTypeFor(final Type valueType) { + return parameterizedTypeFor(SET_TYPE, valueType); + } + + /** + * Returns an instance of {@link ParameterizedType} describing the typed + * {@link List}<V> with concrete type of value. + * + * @param valueType + * Value Type + * @return Description of type instance of List + */ + public static ParameterizedType listTypeFor(final Type valueType) { + return parameterizedTypeFor(LIST_TYPE, valueType); + } + + /** + * Creates instance of type + * {@link org.opendaylight.yangtools.sal.binding.model.api.ParameterizedType + * ParameterizedType} + * + * @param type + * JAVA Type for raw type + * @param parameters + * JAVA Types for actual parameter types + * @return ParametrizedType reprezentation of type + * and its parameters parameters + */ + public static ParameterizedType parameterizedTypeFor(final Type type, final Type... parameters) { + return new ParametrizedTypeImpl(type, parameters); + } + + /** + * Creates instance of type + * {@link org.opendaylight.yangtools.sal.binding.model.api.WildcardType + * WildcardType} + * + * @param packageName + * string with the package name + * @param typeName + * string with the type name + * @return WildcardType representation of + * packageName and typeName + */ + public static WildcardType wildcardTypeFor(final String packageName, final String typeName) { + return new WildcardTypeImpl(packageName, typeName); + } + + /** + * Creates instance of + * {@link org.opendaylight.yangtools.sal.binding.model.api.ParameterizedType + * ParameterizedType} where raw type is + * {@link org.opendaylight.yangtools.yang.binding.Augmentable} and actual + * parameter is valueType. + * + * @param valueType + * JAVA Type with actual parameter + * @return ParametrizedType representation of raw type + * Augmentable with actual parameter + * valueType + */ + public static ParameterizedType augmentableTypeFor(final Type valueType) { + final Type augmentable = typeForClass(Augmentable.class); + return parameterizedTypeFor(augmentable, valueType); + } + + /** + * Creates instance of + * {@link org.opendaylight.yangtools.sal.binding.model.api.ParameterizedType + * ParameterizedType} where raw type is + * {@link org.opendaylight.yangtools.yang.binding.Augmentation} and actual + * parameter is valueType. + * + * @param valueType + * JAVA Type with actual parameter + * @return ParametrizedType reprezentation of raw type + * Augmentation with actual parameter + * valueType + */ + public static ParameterizedType augmentationTypeFor(final Type valueType) { + final Type augmentation = typeForClass(Augmentation.class); + return parameterizedTypeFor(augmentation, valueType); + } + + + public static @Nullable String getOuterClassName(final Type valueType) { + final String pkgName = valueType.getPackageName(); + if(CharMatcher.JAVA_UPPER_CASE.indexIn(pkgName) >= 0) { + // It is inner class. + return Iterables.getLast(DOT_SPLITTER.split(pkgName)); + } + return null; + } + + /** + * + * Represents concrete JAVA type. + * + */ + private static final class ConcreteTypeImpl extends AbstractBaseType implements ConcreteType { + private final Restrictions restrictions; + + /** + * Creates instance of this class with package pkName and + * with the type name name. + * + * @param pkName + * string with package name + * @param name + * string with the name of the type + */ + private ConcreteTypeImpl(final String pkName, final String name, final Restrictions restrictions) { + super(pkName, name); + this.restrictions = restrictions; + } + + @Override + public Restrictions getRestrictions() { + return restrictions; + } + } + + /** + * + * Represents concrete JAVA type with changed restriction values. + * + */ + private static final class BaseTypeWithRestrictionsImpl extends AbstractBaseType implements BaseTypeWithRestrictions { + private final Restrictions restrictions; + + /** + * Creates instance of this class with package pkName and + * with the type name name. + * + * @param pkName + * string with package name + * @param name + * string with the name of the type + */ + private BaseTypeWithRestrictionsImpl(final String pkName, final String name, final Restrictions restrictions) { + super(pkName, name); + this.restrictions = Preconditions.checkNotNull(restrictions); + } + + @Override + public Restrictions getRestrictions() { + return restrictions; + } + } + + /** + * + * Represents parametrized JAVA type. + * + */ + private static class ParametrizedTypeImpl extends AbstractBaseType implements ParameterizedType { + /** + * Array of JAVA actual type parameters. + */ + private final Type[] actualTypes; + + /** + * JAVA raw type (like List, Set, Map...) + */ + 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. + * + * @param rawType + * JAVA Type for raw type + * @param actTypes + * array of actual parameters + */ + public ParametrizedTypeImpl(final Type rawType, final Type[] actTypes) { + super(rawType.getPackageName(), rawType.getName()); + this.rawType = rawType; + this.actualTypes = actTypes.clone(); + } + + } + + /** + * + * Represents JAVA bounded wildcard type. + * + */ + private static class WildcardTypeImpl extends AbstractBaseType implements WildcardType { + /** + * Creates instance of this class with concrete package and type name. + * + * @param packageName + * string with the package name + * @param typeName + * string with the name of type + */ + public WildcardTypeImpl(final String packageName, final String typeName) { + super(packageName, typeName); + } + } + + public static DefaultRestrictions getDefaultRestrictions(final T min, final T max) { + return new DefaultRestrictions<>(min, max); + } + + private static final class DefaultRestrictions implements Restrictions { + private final T min; + private final T max; + private final List rangeConstraints; + + private DefaultRestrictions(final T min, final T max) { + this.min = Preconditions.checkNotNull(min); + this.max = Preconditions.checkNotNull(max); + this.rangeConstraints = Collections.singletonList(BaseConstraints.newRangeConstraint(min, max, Optional + .absent(), Optional.absent())); + } + + @Override + public boolean isEmpty() { + return false; + } + + @Override + public List getRangeConstraints() { + return rangeConstraints; + } + + @Override + public List getPatternConstraints() { + return Collections.emptyList(); + } + + @Override + public List getLengthConstraints() { + return Collections.emptyList(); + } + } +} \ No newline at end of file diff --git a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/generated/type/builder/AbstractGeneratedType.java b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/generated/type/builder/AbstractGeneratedType.java new file mode 100644 index 0000000000..b2df0a3c89 --- /dev/null +++ b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/generated/type/builder/AbstractGeneratedType.java @@ -0,0 +1,215 @@ +/* + * Copyright (c) 2013 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.mdsal.binding.generator.util.generated.type.builder; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.opendaylight.mdsal.binding.generator.util.AbstractBaseType; +import org.opendaylight.mdsal.binding.model.api.AnnotationType; +import org.opendaylight.mdsal.binding.model.api.Constant; +import org.opendaylight.mdsal.binding.model.api.Enumeration; +import org.opendaylight.mdsal.binding.model.api.GeneratedProperty; +import org.opendaylight.mdsal.binding.model.api.GeneratedType; +import org.opendaylight.mdsal.binding.model.api.MethodSignature; +import org.opendaylight.mdsal.binding.model.api.Type; +import org.opendaylight.mdsal.binding.model.api.type.builder.AnnotationTypeBuilder; +import org.opendaylight.mdsal.binding.model.api.type.builder.EnumBuilder; +import org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedPropertyBuilder; +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.MethodSignatureBuilder; + +abstract class AbstractGeneratedType extends AbstractBaseType implements GeneratedType { + + private final Type parent; + private final String comment; + private final List annotations; + private final List implementsTypes; + private final List enumerations; + private final List constants; + private final List methodSignatures; + private final List enclosedTypes; + private final List properties; + private final boolean isAbstract; + + public AbstractGeneratedType(final AbstractGeneratedTypeBuilder builder) { + super(builder.getPackageName(), builder.getName()); + this.parent = builder.getParent(); + this.comment = builder.getComment(); + this.annotations = toUnmodifiableAnnotations(builder.getAnnotations()); + this.implementsTypes = makeUnmodifiable(builder.getImplementsTypes()); + this.constants = makeUnmodifiable(builder.getConstants()); + this.enumerations = toUnmodifiableEnumerations(builder.getEnumerations()); + this.methodSignatures = toUnmodifiableMethods(builder.getMethodDefinitions()); + this.enclosedTypes = toUnmodifiableEnclosedTypes(builder.getEnclosedTypes(), + builder.getEnclosedTransferObjects()); + this.properties = toUnmodifiableProperties(builder.getProperties()); + this.isAbstract = builder.isAbstract(); + } + + public AbstractGeneratedType(final Type parent, final String packageName, final String name, final String comment, + final List annotationBuilders, final boolean isAbstract, + final List implementsTypes, final List enclosedGenTypeBuilders, + final List enclosedGenTOBuilders, final List enumBuilders, + final List constants, final List methodBuilders, + final List propertyBuilders) { + super(packageName, name); + this.parent = parent; + this.comment = comment; + this.annotations = toUnmodifiableAnnotations(annotationBuilders); + this.implementsTypes = makeUnmodifiable(implementsTypes); + this.constants = makeUnmodifiable(constants); + this.enumerations = toUnmodifiableEnumerations(enumBuilders); + this.methodSignatures = toUnmodifiableMethods(methodBuilders); + this.enclosedTypes = toUnmodifiableEnclosedTypes(enclosedGenTypeBuilders, enclosedGenTOBuilders); + this.properties = toUnmodifiableProperties(propertyBuilders); + this.isAbstract = isAbstract; + } + + protected static final List makeUnmodifiable(final List list) { + switch (list.size()) { + case 0: + return Collections.emptyList(); + case 1: + return Collections.singletonList(list.get(0)); + default: + return Collections.unmodifiableList(list); + } + } + + private static List toUnmodifiableEnclosedTypes(final List enclosedGenTypeBuilders, + final List enclosedGenTOBuilders) { + final ArrayList enclosedTypesList = new ArrayList<>(enclosedGenTypeBuilders.size() + enclosedGenTOBuilders.size()); + for (final GeneratedTypeBuilder builder : enclosedGenTypeBuilders) { + if (builder != null) { + enclosedTypesList.add(builder.toInstance()); + } + } + + for (final GeneratedTOBuilder builder : enclosedGenTOBuilders) { + if (builder != null) { + enclosedTypesList.add(builder.toInstance()); + } + } + + return makeUnmodifiable(enclosedTypesList); + } + + protected static final List toUnmodifiableAnnotations(final List annotationBuilders) { + final List annotationList = new ArrayList<>(annotationBuilders.size()); + for (final AnnotationTypeBuilder builder : annotationBuilders) { + annotationList.add(builder.toInstance()); + } + return makeUnmodifiable(annotationList); + } + + protected final List toUnmodifiableMethods(final List methodBuilders) { + final List methods = new ArrayList<>(methodBuilders.size()); + for (final MethodSignatureBuilder methodBuilder : methodBuilders) { + methods.add(methodBuilder.toInstance(this)); + } + return makeUnmodifiable(methods); + } + + protected final List toUnmodifiableEnumerations(final List enumBuilders) { + final List enums = new ArrayList<>(enumBuilders.size()); + for (final EnumBuilder enumBuilder : enumBuilders) { + enums.add(enumBuilder.toInstance(this)); + } + return makeUnmodifiable(enums); + } + + protected final List toUnmodifiableProperties(final List methodBuilders) { + final List methods = new ArrayList<>(methodBuilders.size()); + for (final GeneratedPropertyBuilder methodBuilder : methodBuilders) { + methods.add(methodBuilder.toInstance(this)); + } + return makeUnmodifiable(methods); + } + + @Override + public final Type getParentType() { + return parent; + } + + @Override + public final String getComment() { + return comment; + } + + @Override + public final List getAnnotations() { + return annotations; + } + + @Override + public final boolean isAbstract() { + return isAbstract; + } + + @Override + public final List getImplements() { + return implementsTypes; + } + + @Override + public final List getEnclosedTypes() { + return enclosedTypes; + } + + @Override + public final List getEnumerations() { + return enumerations; + } + + @Override + public final List getConstantDefinitions() { + return constants; + } + + @Override + public final List getMethodDefinitions() { + return methodSignatures; + } + + @Override + public final List getProperties() { + return properties; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("GeneratedType [packageName="); + builder.append(getPackageName()); + builder.append(", name="); + builder.append(getName()); + if (parent != null) { + builder.append(", parent="); + builder.append(parent.getFullyQualifiedName()); + } else { + builder.append(", parent=null"); + } + builder.append(", comment="); + builder.append(comment); + builder.append(", annotations="); + builder.append(annotations); + builder.append(", enclosedTypes="); + builder.append(enclosedTypes); + builder.append(", enumerations="); + builder.append(enumerations); + builder.append(", constants="); + builder.append(constants); + builder.append(", methodSignatures="); + builder.append(methodSignatures); + builder.append("]"); + return builder.toString(); + } +} diff --git a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/generated/type/builder/AbstractGeneratedTypeBuilder.java b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/generated/type/builder/AbstractGeneratedTypeBuilder.java new file mode 100644 index 0000000000..223faebd93 --- /dev/null +++ b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/generated/type/builder/AbstractGeneratedTypeBuilder.java @@ -0,0 +1,241 @@ +/* + * Copyright (c) 2013 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.mdsal.binding.generator.util.generated.type.builder; + +import com.google.common.base.Preconditions; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import org.opendaylight.mdsal.binding.generator.util.AbstractBaseType; +import org.opendaylight.mdsal.binding.model.api.AccessModifier; +import org.opendaylight.mdsal.binding.model.api.Constant; +import org.opendaylight.mdsal.binding.model.api.Type; +import org.opendaylight.mdsal.binding.model.api.type.builder.AnnotationTypeBuilder; +import org.opendaylight.mdsal.binding.model.api.type.builder.EnumBuilder; +import org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedPropertyBuilder; +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.MethodSignatureBuilder; +import org.opendaylight.yangtools.util.LazyCollections; + +abstract class AbstractGeneratedTypeBuilder> extends AbstractBaseType implements GeneratedTypeBuilderBase { + + private List annotationBuilders = Collections.emptyList(); + private List implementsTypes = Collections.emptyList(); + private List enumDefinitions = Collections.emptyList(); + private List constants = Collections.emptyList(); + private List methodDefinitions = Collections.emptyList(); + private final List enclosedTypes = Collections.emptyList(); + private List enclosedTransferObjects = Collections.emptyList(); + private List properties = Collections.emptyList(); + private String comment = ""; + private boolean isAbstract; + + protected AbstractGeneratedTypeBuilder(final String packageName, final String name) { + super(packageName, name); + } + + protected String getComment() { + return comment; + } + + protected List getAnnotations() { + return annotationBuilders; + } + + @Override + public boolean isAbstract() { + return isAbstract; + } + + @Override + public List getImplementsTypes() { + return implementsTypes; + } + + protected List getEnumerations() { + return enumDefinitions; + } + + protected List getConstants() { + return constants; + } + + @Override + public List getMethodDefinitions() { + return methodDefinitions; + } + + protected List getEnclosedTypes() { + return enclosedTypes; + } + + protected List getEnclosedTransferObjects() { + return enclosedTransferObjects; + } + + protected abstract T thisInstance(); + + @Override + public GeneratedTOBuilder addEnclosingTransferObject(final String name) { + Preconditions.checkArgument(name != null, "Name for Enclosing Generated Transfer Object cannot be null!"); + GeneratedTOBuilder builder = new GeneratedTOBuilderImpl(getFullyQualifiedName(), name); + + Preconditions.checkArgument(!enclosedTransferObjects.contains(builder), "This generated type already contains equal enclosing transfer object."); + enclosedTransferObjects = LazyCollections.lazyAdd(enclosedTransferObjects, builder); + return builder; + } + + @Override + public T addEnclosingTransferObject(final GeneratedTOBuilder genTOBuilder) { + Preconditions.checkArgument(genTOBuilder != null, "Parameter genTOBuilder cannot be null!"); + Preconditions.checkArgument(!enclosedTransferObjects.contains(genTOBuilder), "This generated type already contains equal enclosing transfer object."); + enclosedTransferObjects = LazyCollections.lazyAdd(enclosedTransferObjects, genTOBuilder); + return thisInstance(); + } + + @Override + public T addComment(final String comment) { + this.comment = comment; + return thisInstance(); + } + + @Override + public AnnotationTypeBuilder addAnnotation(final String packageName, final String name) { + Preconditions.checkArgument(packageName != null, "Package Name for Annotation Type cannot be null!"); + Preconditions.checkArgument(name != null, "Name of Annotation Type cannot be null!"); + + final AnnotationTypeBuilder builder = new AnnotationTypeBuilderImpl(packageName, name); + + Preconditions.checkArgument(!annotationBuilders.contains(builder), "This generated type already contains equal annotation."); + annotationBuilders = LazyCollections.lazyAdd(annotationBuilders, builder); + return builder; + } + + @Override + public T setAbstract(final boolean isAbstract) { + this.isAbstract = isAbstract; + return thisInstance(); + } + + @Override + public T addImplementsType(final Type genType) { + Preconditions.checkArgument(genType != null, "Type cannot be null"); + Preconditions.checkArgument(!implementsTypes.contains(genType), "This generated type already contains equal implements type."); + implementsTypes = LazyCollections.lazyAdd(implementsTypes, genType); + return thisInstance(); + } + + @Override + public Constant addConstant(final Type type, final String name, final Object value) { + Preconditions.checkArgument(type != null, "Returning Type for Constant cannot be null!"); + Preconditions.checkArgument(name != null, "Name of constant cannot be null!"); + Preconditions.checkArgument(!containsConstant(name), "This generated type already contains constant with the same name."); + + final Constant constant = new ConstantImpl(this, type, name, value); + constants = LazyCollections.lazyAdd(constants, constant); + return constant; + } + + public boolean containsConstant(final String name) { + Preconditions.checkArgument(name != null, "Parameter name can't be null"); + for (Constant constant : constants) { + if (name.equals(constant.getName())) { + return true; + } + } + return false; + } + + @Override + public EnumBuilder addEnumeration(final String name) { + Preconditions.checkArgument(name != null, "Name of enumeration cannot be null!"); + final EnumBuilder builder = new EnumerationBuilderImpl(getFullyQualifiedName(), name); + + Preconditions.checkArgument(!enumDefinitions.contains(builder), "This generated type already contains equal enumeration."); + enumDefinitions = LazyCollections.lazyAdd(enumDefinitions, builder); + return builder; + } + + @Override + public MethodSignatureBuilder addMethod(final String name) { + Preconditions.checkArgument(name != null, "Name of method cannot be null!"); + final MethodSignatureBuilder builder = new MethodSignatureBuilderImpl(name); + builder.setAccessModifier(AccessModifier.PUBLIC); + builder.setAbstract(true); + methodDefinitions = LazyCollections.lazyAdd(methodDefinitions, builder); + return builder; + } + + @Override + public boolean containsMethod(final String name) { + Preconditions.checkArgument(name != null, "Parameter name can't be null"); + for (MethodSignatureBuilder methodDefinition : methodDefinitions) { + if (name.equals(methodDefinition.getName())) { + return true; + } + } + return false; + } + + @Override + public GeneratedPropertyBuilder addProperty(final String name) { + Preconditions.checkArgument(name != null, "Parameter name can't be null"); + Preconditions.checkArgument(!containsProperty(name), "This generated type already contains property with the same name."); + + final GeneratedPropertyBuilder builder = new GeneratedPropertyBuilderImpl(name); + builder.setAccessModifier(AccessModifier.PUBLIC); + properties = LazyCollections.lazyAdd(properties, builder); + return builder; + } + + @Override + public boolean containsProperty(final String name) { + Preconditions.checkArgument(name != null, "Parameter name can't be null"); + for (GeneratedPropertyBuilder property : properties) { + if (name.equals(property.getName())) { + return true; + } + } + return false; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + Objects.hashCode(getName()); + result = prime * result + Objects.hashCode(getPackageName()); + return result; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + AbstractGeneratedTypeBuilder other = (AbstractGeneratedTypeBuilder) obj; + return Objects.equals(getName(), other.getName()) && Objects.equals(getPackageName(), other.getPackageName()); + } + + public Type getParent() { + return null; + } + + @Override + public List getProperties() { + return properties; + } +} diff --git a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/generated/type/builder/AbstractTypeMember.java b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/generated/type/builder/AbstractTypeMember.java new file mode 100644 index 0000000000..88347e6490 --- /dev/null +++ b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/generated/type/builder/AbstractTypeMember.java @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2013 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.mdsal.binding.generator.util.generated.type.builder; + +import java.util.List; +import java.util.Objects; +import org.opendaylight.mdsal.binding.model.api.AccessModifier; +import org.opendaylight.mdsal.binding.model.api.AnnotationType; +import org.opendaylight.mdsal.binding.model.api.Type; +import org.opendaylight.mdsal.binding.model.api.TypeMember; + +abstract class AbstractTypeMember implements TypeMember { + + private final String name; + private final String comment; + private final Type definingType; + private final Type returnType; + private final List annotations; + private final boolean isFinal; + private final boolean isStatic; + private final AccessModifier accessModifier; + + protected AbstractTypeMember(final Type definingType, final String name, final List annotations, + final String comment, final AccessModifier accessModifier, final Type returnType, + final boolean isFinal, final boolean isStatic) { + super(); + this.definingType = definingType; + this.name = name; + this.annotations = annotations; + this.comment = comment; + this.accessModifier = accessModifier; + this.returnType = returnType; + this.isFinal = isFinal; + this.isStatic = isStatic; + } + + @Override + public List getAnnotations() { + return annotations; + } + + @Override + public String getName() { + return name; + } + + @Override + public String getComment() { + return comment; + } + + @Override + public Type getDefiningType() { + return definingType; + } + + @Override + public AccessModifier getAccessModifier() { + return accessModifier; + } + + @Override + public Type getReturnType() { + return returnType; + } + + @Override + public boolean isFinal() { + return isFinal; + } + + @Override + public boolean isStatic() { + return isStatic; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + Objects.hashCode(getName()); + result = prime * result + Objects.hashCode(getReturnType()); + return result; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + AbstractTypeMember other = (AbstractTypeMember) obj; + return Objects.equals(getName(), other.getName()) && Objects.equals(getReturnType(), other.getReturnType()); + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("MethodSignatureImpl [name="); + builder.append(getName()); + builder.append(", comment="); + builder.append(getComment()); + if (getDefiningType() != null) { + builder.append(", definingType="); + builder.append(getDefiningType().getPackageName()); + builder.append("."); + builder.append(getDefiningType().getName()); + } else { + builder.append(", definingType= null"); + } + builder.append(", returnType="); + builder.append(getReturnType()); + builder.append(", annotations="); + builder.append(getAnnotations()); + builder.append("]"); + return builder.toString(); + } +} diff --git a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/generated/type/builder/AbstractTypeMemberBuilder.java b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/generated/type/builder/AbstractTypeMemberBuilder.java new file mode 100644 index 0000000000..f3cc5dc410 --- /dev/null +++ b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/generated/type/builder/AbstractTypeMemberBuilder.java @@ -0,0 +1,166 @@ +/* + * Copyright (c) 2013 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.mdsal.binding.generator.util.generated.type.builder; + +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableList; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import org.opendaylight.mdsal.binding.model.api.AccessModifier; +import org.opendaylight.mdsal.binding.model.api.AnnotationType; +import org.opendaylight.mdsal.binding.model.api.Type; +import org.opendaylight.mdsal.binding.model.api.type.builder.AnnotationTypeBuilder; +import org.opendaylight.mdsal.binding.model.api.type.builder.TypeMemberBuilder; +import org.opendaylight.yangtools.util.LazyCollections; + +abstract class AbstractTypeMemberBuilder> implements TypeMemberBuilder { + private final String name; + private Type returnType; + private List annotationBuilders = Collections.emptyList(); + private String comment = ""; + private boolean isFinal; + private boolean isStatic; + private AccessModifier accessModifier; + + public AbstractTypeMemberBuilder(final String name) { + this.name = name; + } + + @Override + public AnnotationTypeBuilder addAnnotation(final String packageName, final String name) { + Preconditions.checkArgument(packageName != null, "Annotation Type cannot have package name null!"); + Preconditions.checkArgument(name != null, "Annotation Type cannot have name as null!"); + + final AnnotationTypeBuilder builder = new AnnotationTypeBuilderImpl(packageName, name); + annotationBuilders = LazyCollections.lazyAdd(annotationBuilders, builder); + return builder; + } + + protected Type getReturnType() { + return returnType; + } + + protected Iterable getAnnotationBuilders() { + return annotationBuilders; + } + + protected String getComment() { + return comment; + } + + protected boolean isFinal() { + return isFinal; + } + + protected boolean isStatic() { + return isStatic; + } + + @Override + public AccessModifier getAccessModifier() { + return accessModifier; + } + + @Override + public String getName() { + return name; + } + + protected abstract T thisInstance(); + + @Override + public T setReturnType(final Type returnType) { + Preconditions.checkArgument(returnType != null, "Return Type of member cannot be null!"); + this.returnType = returnType; + return thisInstance(); + } + + @Override + public T setAccessModifier(final AccessModifier modifier) { + Preconditions.checkArgument(modifier != null, "Access Modifier for member type cannot be null!"); + this.accessModifier = modifier; + return thisInstance(); + } + + @Override + public T setComment(final String comment) { + if (comment == null) { + this.comment = ""; + } + this.comment = comment; + return thisInstance(); + } + + @Override + public T setFinal(final boolean isFinal) { + this.isFinal = isFinal; + return thisInstance(); + } + + @Override + public T setStatic(final boolean isStatic) { + this.isStatic = isStatic; + return thisInstance(); + } + + protected List toAnnotationTypes() { + final List annotations = new ArrayList<>(); + for (final AnnotationTypeBuilder annotBuilder : getAnnotationBuilders()) { + if (annotBuilder != null) { + annotations.add(annotBuilder.toInstance()); + } + } + + return ImmutableList.copyOf(annotations); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + Objects.hashCode(getName()); + result = prime * result + Objects.hashCode(getReturnType()); + return result; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + AbstractTypeMemberBuilder other = (AbstractTypeMemberBuilder) obj; + return Objects.equals(getName(), other.getName()) && Objects.equals(getReturnType(), other.getReturnType()); + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("GeneratedPropertyImpl [name="); + builder.append(getName()); + builder.append(", annotations="); + builder.append(getAnnotationBuilders()); + builder.append(", comment="); + builder.append(getComment()); + builder.append(", returnType="); + builder.append(getReturnType()); + builder.append(", isFinal="); + builder.append(isFinal()); + builder.append(", modifier="); + builder.append(getAccessModifier()); + builder.append("]"); + return builder.toString(); + } +} diff --git a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/generated/type/builder/AnnotationTypeBuilderImpl.java b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/generated/type/builder/AnnotationTypeBuilderImpl.java new file mode 100644 index 0000000000..f044f163ba --- /dev/null +++ b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/generated/type/builder/AnnotationTypeBuilderImpl.java @@ -0,0 +1,305 @@ +/* + * Copyright (c) 2013 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.mdsal.binding.generator.util.generated.type.builder; + +import com.google.common.collect.ImmutableList; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import org.opendaylight.mdsal.binding.generator.util.AbstractBaseType; +import org.opendaylight.mdsal.binding.model.api.AnnotationType; +import org.opendaylight.mdsal.binding.model.api.type.builder.AnnotationTypeBuilder; +import org.opendaylight.yangtools.util.LazyCollections; + +final class AnnotationTypeBuilderImpl extends AbstractBaseType implements AnnotationTypeBuilder { + + private final String packageName; + private final String name; + private List annotationBuilders = Collections.emptyList(); + private List parameters = Collections.emptyList(); + + public AnnotationTypeBuilderImpl(final String packageName, final String name) { + super(packageName, name); + this.packageName = packageName; + this.name = name; + } + + @Override + public AnnotationTypeBuilder addAnnotation(final String packageName, final String name) { + if (packageName != null && name != null) { + final AnnotationTypeBuilder builder = new AnnotationTypeBuilderImpl(packageName, name); + if (!annotationBuilders.contains(builder)) { + annotationBuilders = LazyCollections.lazyAdd(annotationBuilders, builder); + return builder; + } + } + return null; + } + + private boolean addParameter(final ParameterImpl param) { + if (!parameters.contains(param)) { + parameters = LazyCollections.lazyAdd(parameters, param); + return true; + } else { + return false; + } + } + + @Override + public boolean addParameter(final String paramName, final String value) { + if (paramName != null && value != null) { + final ParameterImpl param = new ParameterImpl(paramName, value); + return addParameter(param); + } + return false; + } + + @Override + public boolean addParameters(final String paramName, final List values) { + if (paramName != null && values != null) { + final ParameterImpl param = new ParameterImpl(paramName, values); + return addParameter(param); + } + return false; + } + + @Override + public AnnotationType toInstance() { + return new AnnotationTypeImpl(packageName, name, annotationBuilders, parameters); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + Objects.hashCode(name); + result = prime * result + Objects.hashCode(packageName); + return result; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + AnnotationTypeBuilderImpl other = (AnnotationTypeBuilderImpl) obj; + return Objects.equals(name, other.name) && Objects.equals(packageName, other.packageName); + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("AnnotationTypeBuilder [packageName="); + builder.append(packageName); + builder.append(", name="); + builder.append(name); + builder.append(", annotationBuilders="); + builder.append(annotationBuilders); + builder.append(", parameters="); + builder.append(parameters); + builder.append("]"); + return builder.toString(); + } + + private static final class AnnotationTypeImpl implements AnnotationType { + + private final String packageName; + private final String name; + private final List annotations; + private final List parameters; + private final List paramNames; + + public AnnotationTypeImpl(final String packageName, final String name, + final List annotationBuilders, + final List parameters) { + super(); + this.packageName = packageName; + this.name = name; + + final List a = new ArrayList<>(); + for (final AnnotationTypeBuilder builder : annotationBuilders) { + a.add(builder.toInstance()); + } + this.annotations = ImmutableList.copyOf(a); + + final List p = new ArrayList<>(); + for (final AnnotationType.Parameter parameter : parameters) { + p.add(parameter.getName()); + } + this.paramNames = ImmutableList.copyOf(p); + + this.parameters = parameters.isEmpty() ? Collections.emptyList() + : Collections.unmodifiableList(parameters); + } + + @Override + public String getPackageName() { + return packageName; + } + + @Override + public String getName() { + return name; + } + + @Override + public String getFullyQualifiedName() { + return packageName + "." + name; + } + + @Override + public List getAnnotations() { + return annotations; + } + + @Override + public Parameter getParameter(final String paramName) { + if (paramName != null) { + for (final AnnotationType.Parameter parameter : parameters) { + if (parameter.getName().equals(paramName)) { + return parameter; + } + } + } + return null; + } + + @Override + public List getParameters() { + return parameters; + } + + @Override + public List getParameterNames() { + return paramNames; + } + + @Override + public boolean containsParameters() { + return !parameters.isEmpty(); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + Objects.hashCode(name); + result = prime * result + Objects.hashCode(packageName); + return result; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + AnnotationTypeImpl other = (AnnotationTypeImpl) obj; + return Objects.equals(name, other.name) && Objects.equals(packageName, other.packageName); + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("AnnotationType [packageName="); + builder.append(packageName); + builder.append(", name="); + builder.append(name); + builder.append(", annotations="); + builder.append(annotations); + builder.append(", parameters="); + builder.append(parameters); + builder.append("]"); + return builder.toString(); + } + } + + private static final class ParameterImpl implements AnnotationType.Parameter { + + private final String name; + private final String value; + private final List values; + + public ParameterImpl(final String name, final String value) { + super(); + this.name = name; + this.value = value; + this.values = Collections.emptyList(); + } + + public ParameterImpl(final String name, final List values) { + super(); + this.name = name; + this.values = values; + this.value = null; + } + + @Override + public String getName() { + return name; + } + + @Override + public String getValue() { + return value; + } + + @Override + public List getValues() { + return values; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + Objects.hashCode(name); + return result; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + ParameterImpl other = (ParameterImpl) obj; + return Objects.equals(name, other.name); + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("ParameterImpl [name="); + builder.append(name); + builder.append(", value="); + builder.append(value); + builder.append(", values="); + builder.append(values); + builder.append("]"); + return builder.toString(); + } + } +} diff --git a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/generated/type/builder/ConstantImpl.java b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/generated/type/builder/ConstantImpl.java new file mode 100644 index 0000000000..92c1feaa91 --- /dev/null +++ b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/generated/type/builder/ConstantImpl.java @@ -0,0 +1,114 @@ +/* + * Copyright (c) 2013 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.mdsal.binding.generator.util.generated.type.builder; + +import java.util.Objects; +import org.opendaylight.mdsal.binding.model.api.Constant; +import org.opendaylight.mdsal.binding.model.api.Type; + +final class ConstantImpl implements Constant { + + private final Type definingType; + private final Type type; + private final String name; + private final Object value; + + public ConstantImpl(final Type definingType, final Type type, final String name, final Object value) { + super(); + this.definingType = definingType; + this.type = type; + this.name = name; + this.value = value; + } + + @Override + public Type getDefiningType() { + return definingType; + } + + @Override + public Type getType() { + return type; + } + + @Override + public String getName() { + return name; + } + + @Override + public Object getValue() { + return value; + } + + @Override + public String toFormattedString() { + StringBuilder builder = new StringBuilder(); + builder.append(type); + builder.append(" "); + builder.append(name); + builder.append(" "); + builder.append(value); + return builder.toString(); + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + Objects.hashCode(name); + result = prime * result + Objects.hashCode(type); + return result; + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + ConstantImpl other = (ConstantImpl) obj; + return Objects.equals(name, other.name) && Objects.equals(type, other.type) && Objects.equals(value, other.value); + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("Constant [type="); + builder.append(type); + builder.append(", name="); + builder.append(name); + builder.append(", value="); + builder.append(value); + if (definingType != null) { + builder.append(", definingType="); + builder.append(definingType.getPackageName()); + builder.append("."); + builder.append(definingType.getName()); + } else { + builder.append(", definingType= null"); + } + builder.append("]"); + return builder.toString(); + } +} diff --git a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/generated/type/builder/EnumerationBuilderImpl.java b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/generated/type/builder/EnumerationBuilderImpl.java new file mode 100644 index 0000000000..a4596b6513 --- /dev/null +++ b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/generated/type/builder/EnumerationBuilderImpl.java @@ -0,0 +1,381 @@ +/* + * Copyright (c) 2013 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.mdsal.binding.generator.util.generated.type.builder; + +import com.google.common.collect.ImmutableList; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import org.opendaylight.mdsal.binding.generator.util.AbstractBaseType; +import org.opendaylight.mdsal.binding.model.api.AnnotationType; +import org.opendaylight.mdsal.binding.model.api.Constant; +import org.opendaylight.mdsal.binding.model.api.Enumeration; +import org.opendaylight.mdsal.binding.model.api.Enumeration.Pair; +import org.opendaylight.mdsal.binding.model.api.GeneratedProperty; +import org.opendaylight.mdsal.binding.model.api.GeneratedType; +import org.opendaylight.mdsal.binding.model.api.MethodSignature; +import org.opendaylight.mdsal.binding.model.api.Type; +import org.opendaylight.mdsal.binding.model.api.type.builder.AnnotationTypeBuilder; +import org.opendaylight.mdsal.binding.model.api.type.builder.EnumBuilder; +import org.opendaylight.yangtools.util.LazyCollections; +import org.opendaylight.yangtools.yang.binding.BindingMapping; +import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.model.api.Status; +import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition; +import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition.EnumPair; + +public final class EnumerationBuilderImpl extends AbstractBaseType implements EnumBuilder { + private final String packageName; + private final String name; + private List values = Collections.emptyList(); + private List annotationBuilders = Collections.emptyList(); + private List unmodifiableValues = Collections.emptyList(); + private String description; + private String reference; + private String moduleName; + private Iterable schemaPath; + + public EnumerationBuilderImpl(final String packageName, final String name) { + super(packageName, name); + this.packageName = packageName; + this.name = name; + } + + public void setReference(final String reference) { + this.reference = reference; + } + + public void setModuleName(final String moduleName) { + this.moduleName = moduleName; + } + + public void setSchemaPath(final Iterable schemaPath) { + this.schemaPath = schemaPath; + } + + @Override + public void setDescription(final String description) { + this.description = description; + + } + + @Override + public AnnotationTypeBuilder addAnnotation(final String packageName, final String name) { + if (packageName != null && name != null) { + final AnnotationTypeBuilder builder = new AnnotationTypeBuilderImpl(packageName, name); + if (!annotationBuilders.contains(builder)) { + annotationBuilders = LazyCollections.lazyAdd(annotationBuilders, builder); + return builder; + } + } + return null; + } + + @Override + public void addValue(final String name, final int value, final String description) { + final EnumPairImpl p = new EnumPairImpl(name, value, description); + values = LazyCollections.lazyAdd(values, p); + unmodifiableValues = Collections.unmodifiableList(values); + } + + @Override + public Enumeration toInstance(final Type definingType) { + return new EnumerationImpl(definingType, annotationBuilders, packageName, name, unmodifiableValues, + description, reference, moduleName, schemaPath); + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("EnumerationBuilderImpl [packageName="); + builder.append(packageName); + builder.append(", name="); + builder.append(name); + builder.append(", values="); + builder.append(values); + builder.append("]"); + return builder.toString(); + } + + @Override + public void updateEnumPairsFromEnumTypeDef(final EnumTypeDefinition enumTypeDef) { + final List enums = enumTypeDef.getValues(); + if (enums != null) { + for (final EnumPair enumPair : enums) { + if (enumPair != null) { + this.addValue(enumPair.getName(), enumPair.getValue(), enumPair.getDescription()); + } + } + } + + } + + private static final class EnumPairImpl implements Enumeration.Pair { + + private final String name; + private final String mappedName; + private final int value; + private final String description; + + public EnumPairImpl(final String name, final int value, final String description) { + super(); + this.name = name; + this.mappedName = BindingMapping.getClassName(name); + this.value = value; + this.description = description; + } + + @Override + public String getName() { + return name; + } + + @Override + public String getMappedName() { + return mappedName; + } + + @Override + public int getValue() { + return value; + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + Objects.hashCode(name); + result = prime * result + Objects.hashCode(value); + return result; + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + EnumPairImpl other = (EnumPairImpl) obj; + return Objects.equals(name, other.name) && Objects.equals(value, other.value); + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("EnumPair [name="); + builder.append(name); + builder.append(", mappedName="); + builder.append(getMappedName()); + builder.append(", value="); + builder.append(value); + builder.append("]"); + return builder.toString(); + } + + @Override + public String getDescription() { + return description; + } + + @Override + public String getReference() { + return null; + } + + @Override + public Status getStatus() { + // TODO Auto-generated method stub + return null; + } + + } + + private static final class EnumerationImpl extends AbstractBaseType implements Enumeration { + + private final Type definingType; + private final String description; + private final String reference; + private final String moduleName; + private final Iterable schemaPath; + private final List values; + private final List annotations; + + public EnumerationImpl(final Type definingType, final List annotationBuilders, + final String packageName, final String name, final List values, final String description, + final String reference, final String moduleName, final Iterable schemaPath) { + super(packageName, name); + this.definingType = definingType; + this.values = values; + this.description = description; + this.moduleName = moduleName; + this.schemaPath = schemaPath; + this.reference = reference; + + final ArrayList a = new ArrayList<>(); + for (final AnnotationTypeBuilder builder : annotationBuilders) { + a.add(builder.toInstance()); + } + this.annotations = ImmutableList.copyOf(a); + } + + @Override + public Type getParentType() { + return definingType; + } + + @Override + public List getValues() { + return values; + } + + @Override + public List getAnnotations() { + return annotations; + } + + @Override + public String toFormattedString() { + StringBuilder builder = new StringBuilder(); + builder.append("public enum"); + builder.append(" "); + builder.append(getName()); + builder.append(" {"); + builder.append("\n"); + + int i = 0; + for (final Enumeration.Pair valPair : values) { + builder.append("\t"); + builder.append(" "); + builder.append(valPair.getMappedName()); + builder.append(" ("); + builder.append(valPair.getValue()); + + if (i == (values.size() - 1)) { + builder.append(" );"); + } else { + builder.append(" ),"); + } + ++i; + } + builder.append("\n}"); + return builder.toString(); + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("Enumeration [packageName="); + builder.append(getPackageName()); + if (definingType != null) { + builder.append(", definingType="); + builder.append(definingType.getPackageName()); + builder.append("."); + builder.append(definingType.getName()); + } else { + builder.append(", definingType= null"); + } + builder.append(", name="); + builder.append(getName()); + builder.append(", values="); + builder.append(values); + builder.append("]"); + return builder.toString(); + } + + @Override + public String getComment() { + return null; + } + + @Override + public boolean isAbstract() { + return false; + } + + @Override + public List getImplements() { + return Collections.emptyList(); + } + + @Override + public List getEnclosedTypes() { + return Collections.emptyList(); + } + + @Override + public List getEnumerations() { + return Collections.emptyList(); + } + + @Override + public List getConstantDefinitions() { + return Collections.emptyList(); + } + + @Override + public List getMethodDefinitions() { + return Collections.emptyList(); + } + + @Override + public List getProperties() { + return Collections.emptyList(); + } + + @Override + public String getDescription() { + return description; + } + + @Override + public String getReference() { + return reference; + } + + @Override + public Iterable getSchemaPath() { + return schemaPath; + } + + @Override + public String getModuleName() { + return moduleName; + } + } +} diff --git a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/generated/type/builder/GeneratedPropertyBuilderImpl.java b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/generated/type/builder/GeneratedPropertyBuilderImpl.java new file mode 100644 index 0000000000..e5abf441bc --- /dev/null +++ b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/generated/type/builder/GeneratedPropertyBuilderImpl.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2013 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.mdsal.binding.generator.util.generated.type.builder; + +import java.util.List; + +import org.opendaylight.mdsal.binding.model.api.AnnotationType; +import org.opendaylight.mdsal.binding.model.api.GeneratedProperty; +import org.opendaylight.mdsal.binding.model.api.Type; +import org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedPropertyBuilder; + +public final class GeneratedPropertyBuilderImpl extends AbstractTypeMemberBuilder implements GeneratedPropertyBuilder { + private String value; + private boolean isReadOnly; + + public GeneratedPropertyBuilderImpl(String name) { + super(name); + this.isReadOnly = true; + } + + @Override + public GeneratedPropertyBuilderImpl setValue(String value) { + this.value = value; + return this; + } + + @Override + public GeneratedPropertyBuilderImpl setReadOnly(boolean isReadOnly) { + this.isReadOnly = isReadOnly; + return this; + } + + @Override + protected GeneratedPropertyBuilderImpl thisInstance() { + return this; + } + + @Override + public GeneratedProperty toInstance(Type definingType) { + final List annotations = toAnnotationTypes(); + return new GeneratedPropertyImpl(definingType, getName(), annotations, getComment(), getAccessModifier(), + getReturnType(), isFinal(), isStatic(), isReadOnly, value); + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("GeneratedPropertyImpl [name="); + builder.append(getName()); + builder.append(", annotations="); + builder.append(getAnnotationBuilders()); + builder.append(", comment="); + builder.append(getComment()); + builder.append(", returnType="); + builder.append(getReturnType()); + builder.append(", isFinal="); + builder.append(isFinal()); + builder.append(", isReadOnly="); + builder.append(isReadOnly); + builder.append(", modifier="); + builder.append(getAccessModifier()); + builder.append("]"); + return builder.toString(); + } +} \ No newline at end of file diff --git a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/generated/type/builder/GeneratedPropertyImpl.java b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/generated/type/builder/GeneratedPropertyImpl.java new file mode 100644 index 0000000000..139152fb1b --- /dev/null +++ b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/generated/type/builder/GeneratedPropertyImpl.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2013 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.mdsal.binding.generator.util.generated.type.builder; + +import java.util.List; + +import org.opendaylight.mdsal.binding.model.api.AccessModifier; +import org.opendaylight.mdsal.binding.model.api.AnnotationType; +import org.opendaylight.mdsal.binding.model.api.GeneratedProperty; +import org.opendaylight.mdsal.binding.model.api.Type; + +final class GeneratedPropertyImpl extends AbstractTypeMember implements GeneratedProperty { + private String value; + private boolean isReadOnly; + + public GeneratedPropertyImpl(Type definingType, String name, List annotations, String comment, + AccessModifier accessModifier, Type returnType, boolean isFinal, boolean isStatic, boolean isReadOnly, String value) { + super(definingType, name, annotations, comment, accessModifier, returnType, isFinal, isStatic); + this.value = value; + this.isReadOnly = isReadOnly; + } + + @Override + public String getValue() { + return value; + } + + @Override + public boolean isReadOnly() { + return isReadOnly; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("GeneratedPropertyImpl [name="); + builder.append(getName()); + builder.append(", annotations="); + builder.append(getAnnotations()); + builder.append(", comment="); + builder.append(getComment()); + if (getDefiningType() != null) { + builder.append(", parent="); + builder.append(getDefiningType().getPackageName()); + builder.append("."); + builder.append(getDefiningType().getName()); + } else { + builder.append(", parent=null"); + } + builder.append(", returnType="); + builder.append(getReturnType()); + builder.append(", isFinal="); + builder.append(isFinal()); + builder.append(", isReadOnly="); + builder.append(isReadOnly); + builder.append(", modifier="); + builder.append(getAccessModifier()); + builder.append("]"); + return builder.toString(); + } +} diff --git a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/generated/type/builder/GeneratedTOBuilderImpl.java b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/generated/type/builder/GeneratedTOBuilderImpl.java new file mode 100644 index 0000000000..47a7950ce2 --- /dev/null +++ b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/generated/type/builder/GeneratedTOBuilderImpl.java @@ -0,0 +1,355 @@ +/* + * Copyright (c) 2013 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.mdsal.binding.generator.util.generated.type.builder; + +import com.google.common.base.Preconditions; +import java.util.Collections; +import java.util.List; +import org.opendaylight.mdsal.binding.model.api.GeneratedProperty; +import org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject; +import org.opendaylight.mdsal.binding.model.api.ParameterizedType; +import org.opendaylight.mdsal.binding.model.api.Restrictions; +import org.opendaylight.mdsal.binding.model.api.Type; +import org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedPropertyBuilder; +import org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedTOBuilder; +import org.opendaylight.mdsal.binding.model.api.type.builder.MethodSignatureBuilder; +import org.opendaylight.yangtools.util.LazyCollections; +import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.model.api.TypeDefinition; + +public final class GeneratedTOBuilderImpl extends AbstractGeneratedTypeBuilder implements GeneratedTOBuilder { + + private GeneratedTransferObject extendsType; + private List equalsProperties = Collections.emptyList(); + private List hashProperties = Collections.emptyList(); + private List toStringProperties = Collections.emptyList(); + private boolean isTypedef = false; + private boolean isUnionType = false; + private boolean isUnionTypeBuilder = false; + private TypeDefinition baseType = null; + private Restrictions restrictions; + private GeneratedPropertyBuilder SUID; + private String reference; + private String description; + private String moduleName; + private Iterable schemaPath; + + public GeneratedTOBuilderImpl(final String packageName, final String name) { + super(packageName, name); + setAbstract(false); + } + + @Override + public GeneratedTOBuilder setExtendsType(final GeneratedTransferObject genTransObj) { + Preconditions.checkArgument(genTransObj != null, "Generated Transfer Object cannot be null!"); + extendsType = genTransObj; + return this; + } + + /** + * Add new Method Signature definition for Generated Type Builder and + * returns Method Signature Builder for specifying all Method parameters.
+ * Name of Method cannot be null, if it is null + * the method SHOULD throw {@link IllegalArgumentException}
+ * By Default the MethodSignatureBuilder SHOULD be pre-set as + * {@link MethodSignatureBuilder#setAbstract(boolean)}, + * {TypeMemberBuilder#setFinal(boolean)} and + * {TypeMemberBuilder#setAccessModifier(boolean)} + * + * @param name + * Name of Method + * @return new instance of Method Signature Builder. + */ + @Override + public MethodSignatureBuilder addMethod(final String name) { + final MethodSignatureBuilder builder = super.addMethod(name); + builder.setAbstract(false); + return builder; + } + + @Override + public GeneratedTOBuilder addEqualsIdentity(final GeneratedPropertyBuilder property) { + equalsProperties = LazyCollections.lazyAdd(equalsProperties, property); + return this; + } + + @Override + public GeneratedTOBuilder addHashIdentity(final GeneratedPropertyBuilder property) { + hashProperties = LazyCollections.lazyAdd(hashProperties, property); + return this; + } + + @Override + public GeneratedTOBuilder addToStringProperty(final GeneratedPropertyBuilder property) { + toStringProperties = LazyCollections.lazyAdd(toStringProperties, property); + return this; + } + + @Override + protected GeneratedTOBuilder thisInstance() { + return this; + } + + @Override + public void setRestrictions(final Restrictions restrictions) { + this.restrictions = restrictions; + } + + @Override + public void setSUID(final GeneratedPropertyBuilder suid) { + this.SUID = suid; + } + + @Override + public GeneratedTransferObject toInstance() { + return new GeneratedTransferObjectImpl(this); + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("GeneratedTransferObject [packageName="); + builder.append(getPackageName()); + builder.append(", name="); + builder.append(getName()); + builder.append(", comment="); + builder.append(getComment()); + builder.append(", constants="); + builder.append(getConstants()); + builder.append(", enumerations="); + builder.append(getEnumerations()); + builder.append(", equalsProperties="); + builder.append(equalsProperties); + builder.append(", hashCodeProperties="); + builder.append(hashProperties); + builder.append(", stringProperties="); + builder.append(toStringProperties); + builder.append(", annotations="); + builder.append(getAnnotations()); + builder.append(", methods="); + builder.append(getMethodDefinitions()); + builder.append("]"); + return builder.toString(); + } + + @Override + public void setTypedef(final boolean isTypedef) { + this.isTypedef = isTypedef; + } + + @Override + public void setBaseType(final TypeDefinition typeDef) { + this.baseType = typeDef; + } + + @Override + public void setIsUnion(final boolean isUnion) { + this.isUnionType = isUnion; + } + + @Override + public void setIsUnionBuilder(final boolean isUnionTypeBuilder) { + this.isUnionTypeBuilder = isUnionTypeBuilder; + } + + @Override + public void setDescription(String description) { + this.description = description; + } + + @Override + public void setModuleName(String moduleName) { + this.moduleName = moduleName; + } + + @Override + public void setSchemaPath(Iterable schemaPath) { + this.schemaPath = schemaPath; + } + + @Override + public void setReference(String reference) { + this.reference = reference; + } + + private static final class GeneratedTransferObjectImpl extends AbstractGeneratedType implements + GeneratedTransferObject { + + private final List equalsProperties; + private final List hashCodeProperties; + private final List stringProperties; + private final GeneratedTransferObject extendsType; + private final boolean isTypedef; + private final TypeDefinition baseType; + private final boolean isUnionType; + private final boolean isUnionTypeBuilder; + private final Restrictions restrictions; + private final GeneratedProperty SUID; + private final String reference; + private final String description; + private final String moduleName; + private final Iterable schemaPath; + + public GeneratedTransferObjectImpl(final GeneratedTOBuilderImpl builder) { + super(builder); + this.extendsType = builder.extendsType; + + // FIXME: if these fields were guaranteed to be constant, we could perhaps + // cache and reuse them between instances... + this.equalsProperties = toUnmodifiableProperties(builder.equalsProperties); + this.hashCodeProperties = toUnmodifiableProperties(builder.hashProperties); + this.stringProperties = toUnmodifiableProperties(builder.toStringProperties); + + this.isTypedef = builder.isTypedef; + this.baseType = builder.baseType; + this.isUnionType = builder.isUnionType; + this.isUnionTypeBuilder = builder.isUnionTypeBuilder; + this.restrictions = builder.restrictions; + this.reference = builder.reference; + this.description = builder.description; + this.moduleName = builder.moduleName; + this.schemaPath = builder.schemaPath; + + if (builder.SUID == null) { + this.SUID = null; + } else { + this.SUID = builder.SUID.toInstance(GeneratedTransferObjectImpl.this); + } + } + + @Override + public boolean isTypedef() { + return isTypedef; + } + + @Override + public TypeDefinition getBaseType() { + return baseType; + } + + @Override + public boolean isUnionType() { + return isUnionType; + } + + @Override + public boolean isUnionTypeBuilder() { + return isUnionTypeBuilder; + } + + @Override + public GeneratedTransferObject getSuperType() { + return extendsType; + } + + @Override + public List getEqualsIdentifiers() { + return equalsProperties; + } + + @Override + public List getHashCodeIdentifiers() { + return hashCodeProperties; + } + + @Override + public List getToStringIdentifiers() { + return stringProperties; + } + + @Override + public Restrictions getRestrictions() { + return restrictions; + } + + @Override + public GeneratedProperty getSUID() { + return SUID; + } + + @Override + public String toString() { + if (isTypedef) { + return serializeTypedef(this); + } + StringBuilder builder = new StringBuilder(); + builder.append("GeneratedTransferObject [packageName="); + builder.append(getPackageName()); + builder.append(", name="); + builder.append(getName()); + builder.append(", comment="); + builder.append(", annotations="); + builder.append(getAnnotations()); + builder.append(getComment()); + builder.append(", extends="); + builder.append(getSuperType()); + builder.append(", implements="); + builder.append(getImplements()); + builder.append(", enclosedTypes="); + builder.append(getEnclosedTypes()); + builder.append(", constants="); + builder.append(getConstantDefinitions()); + builder.append(", enumerations="); + builder.append(getEnumerations()); + builder.append(", properties="); + builder.append(getProperties()); + builder.append(", equalsProperties="); + builder.append(equalsProperties); + builder.append(", hashCodeProperties="); + builder.append(hashCodeProperties); + builder.append(", stringProperties="); + builder.append(stringProperties); + builder.append(", methods="); + builder.append(getMethodDefinitions()); + builder.append("]"); + return builder.toString(); + } + + public String serializeTypedef(final Type type) { + if (type instanceof ParameterizedType) { + ParameterizedType parameterizedType = (ParameterizedType) type; + StringBuilder sb = new StringBuilder(); + sb.append(parameterizedType.getRawType().getFullyQualifiedName()); + sb.append('<'); + boolean first = true; + for (Type parameter : parameterizedType.getActualTypeArguments()) { + if (first) { + first = false; + } else { + sb.append(','); + } + sb.append(serializeTypedef(parameter)); + } + sb.append('>'); + return sb.toString(); + } else { + return type.getFullyQualifiedName(); + } + } + + @Override + public String getDescription() { + return description; + } + + @Override + public String getReference() { + return reference; + } + + @Override + public Iterable getSchemaPath() { + return schemaPath; + } + + @Override + public String getModuleName() { + return moduleName; + } + } +} diff --git a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/generated/type/builder/GeneratedTypeBuilderImpl.java b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/generated/type/builder/GeneratedTypeBuilderImpl.java new file mode 100644 index 0000000000..09057f5ac5 --- /dev/null +++ b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/generated/type/builder/GeneratedTypeBuilderImpl.java @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2013 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.mdsal.binding.generator.util.generated.type.builder; + +import org.opendaylight.mdsal.binding.model.api.GeneratedType; +import org.opendaylight.mdsal.binding.model.api.type.builder.GeneratedTypeBuilder; +import org.opendaylight.yangtools.yang.common.QName; + +public final class GeneratedTypeBuilderImpl extends AbstractGeneratedTypeBuilder implements + GeneratedTypeBuilder { + + private String description; + private String reference; + private String moduleName; + private Iterable schemaPath; + + public GeneratedTypeBuilderImpl(final String packageName, final String name) { + super(packageName, name); + setAbstract(true); + } + + @Override + public GeneratedType toInstance() { + return new GeneratedTypeImpl(this); + } + + @Override + public void setDescription(String description) { + this.description = description; + } + + @Override + public void setModuleName(String moduleName) { + this.moduleName = moduleName; + } + + @Override + public void setSchemaPath(Iterable schemaPath) { + this.schemaPath = schemaPath; + } + + @Override + public void setReference(String reference) { + this.reference = reference; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("GeneratedTransferObject [packageName="); + builder.append(getPackageName()); + builder.append(", name="); + builder.append(getName()); + builder.append(", comment="); + builder.append(getComment()); + builder.append(", annotations="); + builder.append(getAnnotations()); + builder.append(", implements="); + builder.append(getImplementsTypes()); + builder.append(", enclosedTypes="); + builder.append(getEnclosedTypes()); + builder.append(", constants="); + builder.append(getConstants()); + builder.append(", enumerations="); + builder.append(getEnumerations()); + builder.append(", properties="); + builder.append(", methods="); + builder.append(getMethodDefinitions()); + builder.append("]"); + return builder.toString(); + } + + @Override + protected GeneratedTypeBuilderImpl thisInstance() { + return this; + } + + private static final class GeneratedTypeImpl extends AbstractGeneratedType { + + private final String description; + private final String reference; + private final String moduleName; + private final Iterable schemaPath; + + public GeneratedTypeImpl(GeneratedTypeBuilderImpl builder) { + super(builder); + + this.description = builder.description; + this.reference = builder.reference; + this.moduleName = builder.moduleName; + this.schemaPath = builder.schemaPath; + } + + @Override + public String getDescription() { + return description; + } + + @Override + public String getReference() { + return reference; + } + + @Override + public Iterable getSchemaPath() { + return schemaPath; + } + + @Override + public String getModuleName() { + return moduleName; + } + } +} diff --git a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/generated/type/builder/MethodParameterImpl.java b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/generated/type/builder/MethodParameterImpl.java new file mode 100644 index 0000000000..682e0fa597 --- /dev/null +++ b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/generated/type/builder/MethodParameterImpl.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2013 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.mdsal.binding.generator.util.generated.type.builder; + +import java.util.Objects; +import org.opendaylight.mdsal.binding.model.api.MethodSignature.Parameter; +import org.opendaylight.mdsal.binding.model.api.Type; + +final class MethodParameterImpl implements Parameter { + + private final String name; + private final Type type; + + public MethodParameterImpl(final String name, final Type type) { + super(); + this.name = name; + this.type = type; + } + + @Override + public String getName() { + return name; + } + + @Override + public Type getType() { + return type; + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + Objects.hashCode(name); + result = prime * result + Objects.hashCode(type); + return result; + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + MethodParameterImpl other = (MethodParameterImpl) obj; + return Objects.equals(name, other.name) && Objects.equals(type, other.type); + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("MethodParameter [name="); + builder.append(name); + builder.append(", type="); + builder.append(type.getPackageName()); + builder.append("."); + builder.append(type.getName()); + builder.append("]"); + return builder.toString(); + } +} diff --git a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/generated/type/builder/MethodSignatureBuilderImpl.java b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/generated/type/builder/MethodSignatureBuilderImpl.java new file mode 100644 index 0000000000..aa17fc8482 --- /dev/null +++ b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/generated/type/builder/MethodSignatureBuilderImpl.java @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2013 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.mdsal.binding.generator.util.generated.type.builder; + +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import org.opendaylight.mdsal.binding.model.api.AnnotationType; +import org.opendaylight.mdsal.binding.model.api.MethodSignature; +import org.opendaylight.mdsal.binding.model.api.Type; +import org.opendaylight.mdsal.binding.model.api.type.builder.MethodSignatureBuilder; +import org.opendaylight.yangtools.util.LazyCollections; + +final class MethodSignatureBuilderImpl extends AbstractTypeMemberBuilder implements MethodSignatureBuilder { + + private List parameters = Collections.emptyList(); + private List unmodifiableParams = Collections.emptyList(); + private boolean isAbstract; + + public MethodSignatureBuilderImpl(final String name) { + super(name); + } + + @Override + public MethodSignatureBuilder setAbstract(final boolean isAbstract) { + this.isAbstract = isAbstract; + return this; + } + + @Override + public MethodSignatureBuilder addParameter(final Type type, final String name) { + parameters = LazyCollections.lazyAdd(parameters, new MethodParameterImpl(name, type)); + unmodifiableParams = Collections.unmodifiableList(parameters); + return this; + } + + @Override + protected MethodSignatureBuilder thisInstance() { + return this; + } + + @Override + public MethodSignature toInstance(final Type definingType) { + final List annotations = toAnnotationTypes(); + return new MethodSignatureImpl(definingType, getName(), annotations, getComment(), getAccessModifier(), + getReturnType(), unmodifiableParams, isFinal(), isAbstract, isStatic()); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + Objects.hashCode(getName()); + result = prime * result + Objects.hashCode(parameters); + result = prime * result + Objects.hashCode(getReturnType()); + return result; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + MethodSignatureBuilderImpl other = (MethodSignatureBuilderImpl) obj; + if (!Objects.equals(getName(), other.getName())) { + return false; + } + if (!Objects.equals(parameters, other.parameters)) { + return false; + } + if (!Objects.equals(getReturnType(), other.getReturnType())) { + return false; + } + return true; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("MethodSignatureBuilderImpl [name="); + builder.append(getName()); + builder.append(", returnType="); + builder.append(getReturnType()); + builder.append(", parameters="); + builder.append(parameters); + builder.append(", annotationBuilders="); + builder.append(getAnnotationBuilders()); + builder.append(", comment="); + builder.append(getComment()); + builder.append("]"); + return builder.toString(); + } +} diff --git a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/generated/type/builder/MethodSignatureImpl.java b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/generated/type/builder/MethodSignatureImpl.java new file mode 100644 index 0000000000..886b9d068a --- /dev/null +++ b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/generated/type/builder/MethodSignatureImpl.java @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2013 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.mdsal.binding.generator.util.generated.type.builder; + +import java.util.List; +import java.util.Objects; +import org.opendaylight.mdsal.binding.model.api.AccessModifier; +import org.opendaylight.mdsal.binding.model.api.AnnotationType; +import org.opendaylight.mdsal.binding.model.api.MethodSignature; +import org.opendaylight.mdsal.binding.model.api.Type; + +class MethodSignatureImpl extends AbstractTypeMember implements MethodSignature { + + private final List params; + private final boolean isAbstract; + + public MethodSignatureImpl(final Type definingType, final String name, + final List annotations, + final String comment, final AccessModifier accessModifier, + final Type returnType, final List params, final boolean isFinal, + final boolean isAbstract, final boolean isStatic) { + super(definingType, name, annotations, comment, accessModifier, returnType, isFinal, isStatic); + this.params = params; + this.isAbstract = isAbstract; + } + + @Override + public boolean isAbstract() { + return isAbstract; + } + + @Override + public List getParameters() { + return params; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + Objects.hashCode(getName()); + result = prime * result + Objects.hashCode(params); + result = prime * result + Objects.hashCode(getReturnType()); + return result; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + MethodSignatureImpl other = (MethodSignatureImpl) obj; + if (!Objects.equals(getName(), other.getName())) { + return false; + } + if (!Objects.equals(params, other.params)) { + return false; + } + if (!Objects.equals(getReturnType(), other.getReturnType())) { + return false; + } + return true; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("MethodSignatureImpl [name="); + builder.append(getName()); + builder.append(", comment="); + builder.append(getComment()); + if (getDefiningType() != null) { + builder.append(", definingType="); + builder.append(getDefiningType().getPackageName()); + builder.append("."); + builder.append(getDefiningType().getName()); + } else { + builder.append(", definingType= null"); + } + builder.append(", returnType="); + builder.append(getReturnType()); + builder.append(", params="); + builder.append(params); + builder.append(", annotations="); + builder.append(getAnnotations()); + builder.append("]"); + return builder.toString(); + } +} diff --git a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/package-info.java b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/package-info.java new file mode 100644 index 0000000000..f15bfa57d6 --- /dev/null +++ b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/mdsal/binding/generator/util/package-info.java @@ -0,0 +1,8 @@ +/* + * Copyright (c) 2013 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.mdsal.binding.generator.util; \ No newline at end of file diff --git a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/AbstractBaseType.java b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/AbstractBaseType.java index 0f33815408..f8cf91463b 100644 --- a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/AbstractBaseType.java +++ b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/AbstractBaseType.java @@ -13,7 +13,9 @@ import org.opendaylight.yangtools.sal.binding.model.api.Type; /** * It is used only as ancestor for other Types * + * @deprecated Use {@link org.opendaylight.mdsal.binding.generator.util.AbstractBaseType} instead. */ +@Deprecated public class AbstractBaseType implements Type { /** diff --git a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/BindingGeneratorUtil.java b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/BindingGeneratorUtil.java index 6ce7dc1c7f..6df9cdd782 100644 --- a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/BindingGeneratorUtil.java +++ b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/BindingGeneratorUtil.java @@ -50,8 +50,9 @@ import org.opendaylight.yangtools.yang.model.util.type.DecimalTypeBuilder; * Contains the methods for converting strings to valid JAVA language strings * (package names, class names, attribute names) and to valid javadoc comments. * - * + * @deprecated Use {@link org.opendaylight.mdsal.binding.generator.util.BindingGeneratorUtil} instead. */ +@Deprecated public final class BindingGeneratorUtil { /** @@ -216,6 +217,8 @@ public final class BindingGeneratorUtil { * @param schemaPath * list of names of YANG nodes which are parents of some node + * name of this node + * @param isUsesAugment + * boolean true if using augment * @return string with valid JAVA package name * * @deprecated Use {@link #packageNameForGeneratedType(String, SchemaPath)} or diff --git a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/BindingTypes.java b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/BindingTypes.java index eb310b627f..531825c4cb 100644 --- a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/BindingTypes.java +++ b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/BindingTypes.java @@ -26,6 +26,10 @@ import org.opendaylight.yangtools.yang.binding.Notification; import org.opendaylight.yangtools.yang.binding.NotificationListener; import org.opendaylight.yangtools.yang.binding.RpcService; +/** +* @deprecated Use {@link org.opendaylight.mdsal.binding.generator.util.BindingTypes} instead. +*/ +@Deprecated public final class BindingTypes { public static final ConcreteType AUGMENTABLE = typeForClass(Augmentable.class); diff --git a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/ReferencedTypeImpl.java b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/ReferencedTypeImpl.java index c3c48d850f..c0f913f77c 100644 --- a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/ReferencedTypeImpl.java +++ b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/ReferencedTypeImpl.java @@ -8,16 +8,18 @@ package org.opendaylight.yangtools.binding.generator.util; /** - * + * * Wraps combination of packageName and name to the * object representation - * + * + * @deprecated Use {@link org.opendaylight.mdsal.binding.generator.util.ReferencedTypeImpl} instead. */ +@Deprecated public final class ReferencedTypeImpl extends AbstractBaseType { /** * Creates instance of this class with concrete package name and type name - * + * * @param packageName * string with the package name * @param name diff --git a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/TypeConstants.java b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/TypeConstants.java index d5982be345..02dbd492de 100644 --- a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/TypeConstants.java +++ b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/TypeConstants.java @@ -8,9 +8,12 @@ package org.opendaylight.yangtools.binding.generator.util; /** - * + * * Contains constants used in relations with Type. + * + * @deprecated Use {@link org.opendaylight.mdsal.binding.generator.util.TypeConstants} instead. */ +@Deprecated public final class TypeConstants { /** diff --git a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/Types.java b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/Types.java index da3531aa2a..a9014bc88e 100644 --- a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/Types.java +++ b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/Types.java @@ -34,6 +34,10 @@ import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint; import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint; import org.opendaylight.yangtools.yang.model.util.BaseConstraints; +/** + * @deprecated Use {@link org.opendaylight.mdsal.binding.generator.util.Types} instead. + */ +@Deprecated public final class Types { private static final CacheLoader, ConcreteType> TYPE_LOADER = new CacheLoader, ConcreteType>() { @@ -84,6 +88,8 @@ public final class Types { * @param primitiveType * string containing programmatic construction based on * primitive type (e.g byte[]) + * @param restrictions + * restrictions object * @return ConcreteType instance which represents programmatic * construction with primitive JAVA type */ diff --git a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/AbstractGeneratedType.java b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/AbstractGeneratedType.java index a2bc6da939..950198a689 100644 --- a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/AbstractGeneratedType.java +++ b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/AbstractGeneratedType.java @@ -26,6 +26,10 @@ import org.opendaylight.yangtools.sal.binding.model.api.type.builder.GeneratedTO import org.opendaylight.yangtools.sal.binding.model.api.type.builder.GeneratedTypeBuilder; import org.opendaylight.yangtools.sal.binding.model.api.type.builder.MethodSignatureBuilder; +/** + * @deprecated Use {@link org.opendaylight.mdsal.binding.generator.util.generated.type.builder.AbstractGeneratedType} instead. + */ +@Deprecated abstract class AbstractGeneratedType extends AbstractBaseType implements GeneratedType { private final Type parent; diff --git a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/AbstractGeneratedTypeBuilder.java b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/AbstractGeneratedTypeBuilder.java index e4fc107a98..904848c645 100644 --- a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/AbstractGeneratedTypeBuilder.java +++ b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/AbstractGeneratedTypeBuilder.java @@ -24,6 +24,10 @@ import org.opendaylight.yangtools.sal.binding.model.api.type.builder.GeneratedTy import org.opendaylight.yangtools.sal.binding.model.api.type.builder.MethodSignatureBuilder; import org.opendaylight.yangtools.util.LazyCollections; +/** + * @deprecated Use {org.opendaylight.mdsal.binding.generator.util.generated.type.builder.AbstractGeneratedTypeBuilder} instead. + */ +@Deprecated abstract class AbstractGeneratedTypeBuilder> extends AbstractBaseType implements GeneratedTypeBuilderBase { private List annotationBuilders = Collections.emptyList(); diff --git a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/AbstractTypeMember.java b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/AbstractTypeMember.java index 0cb81701ef..16bdf2e1da 100644 --- a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/AbstractTypeMember.java +++ b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/AbstractTypeMember.java @@ -14,6 +14,10 @@ import org.opendaylight.yangtools.sal.binding.model.api.AnnotationType; import org.opendaylight.yangtools.sal.binding.model.api.Type; import org.opendaylight.yangtools.sal.binding.model.api.TypeMember; +/** + * @deprecated Use {@link org.opendaylight.mdsal.binding.generator.util.generated.type.builder.AbstractTypeMember} instead. + */ +@Deprecated abstract class AbstractTypeMember implements TypeMember { private final String name; diff --git a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/AbstractTypeMemberBuilder.java b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/AbstractTypeMemberBuilder.java index 58451825d8..ffe9f93f26 100644 --- a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/AbstractTypeMemberBuilder.java +++ b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/AbstractTypeMemberBuilder.java @@ -20,6 +20,10 @@ import org.opendaylight.yangtools.sal.binding.model.api.type.builder.AnnotationT import org.opendaylight.yangtools.sal.binding.model.api.type.builder.TypeMemberBuilder; import org.opendaylight.yangtools.util.LazyCollections; +/** + * @deprecated Use {org.opendaylight.mdsal.binding.generator.util.generated.type.builder.AbstractTypeMemberBuilder} instead. + */ +@Deprecated abstract class AbstractTypeMemberBuilder> implements TypeMemberBuilder { private final String name; private Type returnType; diff --git a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/AnnotationTypeBuilderImpl.java b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/AnnotationTypeBuilderImpl.java index 04c2b88401..d299c464a6 100644 --- a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/AnnotationTypeBuilderImpl.java +++ b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/AnnotationTypeBuilderImpl.java @@ -17,6 +17,10 @@ import org.opendaylight.yangtools.sal.binding.model.api.AnnotationType; import org.opendaylight.yangtools.sal.binding.model.api.type.builder.AnnotationTypeBuilder; import org.opendaylight.yangtools.util.LazyCollections; +/** + * @deprecated Use {@link org.opendaylight.mdsal.binding.generator.util.generated.type.builder.AnnotationTypeBuilderImpl} instead. + */ +@Deprecated final class AnnotationTypeBuilderImpl extends AbstractBaseType implements AnnotationTypeBuilder { private final String packageName; diff --git a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/ConstantImpl.java b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/ConstantImpl.java index 920d4eb9ac..a9dbe11e9d 100644 --- a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/ConstantImpl.java +++ b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/ConstantImpl.java @@ -11,6 +11,10 @@ import java.util.Objects; import org.opendaylight.yangtools.sal.binding.model.api.Constant; import org.opendaylight.yangtools.sal.binding.model.api.Type; +/** + * @deprecated Use {@link org.opendaylight.mdsal.binding.generator.util.generated.type.builder.ConstantImpl} instead. + */ +@Deprecated final class ConstantImpl implements Constant { private final Type definingType; diff --git a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/EnumerationBuilderImpl.java b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/EnumerationBuilderImpl.java index 198d938e2d..a0cb98a3a2 100644 --- a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/EnumerationBuilderImpl.java +++ b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/EnumerationBuilderImpl.java @@ -30,6 +30,10 @@ import org.opendaylight.yangtools.yang.model.api.Status; import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition; import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition.EnumPair; +/** + * @deprecated Use {@link org.opendaylight.mdsal.binding.generator.util.generated.type.builder.EnumerationBuilderImpl} instead. + */ +@Deprecated public final class EnumerationBuilderImpl extends AbstractBaseType implements EnumBuilder { private final String packageName; private final String name; diff --git a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/GeneratedPropertyBuilderImpl.java b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/GeneratedPropertyBuilderImpl.java index e4c8019007..764d635187 100644 --- a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/GeneratedPropertyBuilderImpl.java +++ b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/GeneratedPropertyBuilderImpl.java @@ -14,6 +14,10 @@ import org.opendaylight.yangtools.sal.binding.model.api.GeneratedProperty; import org.opendaylight.yangtools.sal.binding.model.api.Type; import org.opendaylight.yangtools.sal.binding.model.api.type.builder.GeneratedPropertyBuilder; +/** + * @deprecated Use {@link org.opendaylight.mdsal.binding.generator.util.generated.type.builder.GeneratedPropertyBuilderImpl} instead. + */ +@Deprecated public final class GeneratedPropertyBuilderImpl extends AbstractTypeMemberBuilder implements GeneratedPropertyBuilder { private String value; private boolean isReadOnly; diff --git a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/GeneratedPropertyImpl.java b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/GeneratedPropertyImpl.java index 2abe75c7d1..10885693bb 100644 --- a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/GeneratedPropertyImpl.java +++ b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/GeneratedPropertyImpl.java @@ -14,6 +14,10 @@ import org.opendaylight.yangtools.sal.binding.model.api.AnnotationType; import org.opendaylight.yangtools.sal.binding.model.api.GeneratedProperty; import org.opendaylight.yangtools.sal.binding.model.api.Type; +/** + * @deprecated Use {@link org.opendaylight.mdsal.binding.generator.util.generated.type.builder.GeneratedPropertyImpl} instead. + */ +@Deprecated final class GeneratedPropertyImpl extends AbstractTypeMember implements GeneratedProperty { private String value; private boolean isReadOnly; diff --git a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/GeneratedTOBuilderImpl.java b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/GeneratedTOBuilderImpl.java index c340d927dc..2129f14e88 100644 --- a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/GeneratedTOBuilderImpl.java +++ b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/GeneratedTOBuilderImpl.java @@ -22,6 +22,10 @@ import org.opendaylight.yangtools.util.LazyCollections; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.model.api.TypeDefinition; +/** + * @deprecated Use {@link org.opendaylight.mdsal.binding.generator.util.generated.type.builder.GeneratedTOBuilderImpl} instead. + */ +@Deprecated public final class GeneratedTOBuilderImpl extends AbstractGeneratedTypeBuilder implements GeneratedTOBuilder { private GeneratedTransferObject extendsType; diff --git a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/GeneratedTypeBuilderImpl.java b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/GeneratedTypeBuilderImpl.java index 92c5629eab..6dfe20a1a1 100644 --- a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/GeneratedTypeBuilderImpl.java +++ b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/GeneratedTypeBuilderImpl.java @@ -11,6 +11,10 @@ import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType; import org.opendaylight.yangtools.sal.binding.model.api.type.builder.GeneratedTypeBuilder; import org.opendaylight.yangtools.yang.common.QName; +/** + * @deprecated Use {@link org.opendaylight.mdsal.binding.generator.util.generated.type.builder.GeneratedTypeBuilderImpl} instead. + */ +@Deprecated public final class GeneratedTypeBuilderImpl extends AbstractGeneratedTypeBuilder implements GeneratedTypeBuilder { diff --git a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/MethodParameterImpl.java b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/MethodParameterImpl.java index 4ca84acadb..ca91f943b0 100644 --- a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/MethodParameterImpl.java +++ b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/MethodParameterImpl.java @@ -11,6 +11,10 @@ import java.util.Objects; import org.opendaylight.yangtools.sal.binding.model.api.MethodSignature.Parameter; import org.opendaylight.yangtools.sal.binding.model.api.Type; +/** + * @deprecated Use {@link org.opendaylight.mdsal.binding.generator.util.generated.type.builder.MethodParameterImpl} instead. + */ +@Deprecated final class MethodParameterImpl implements Parameter { private final String name; diff --git a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/MethodSignatureBuilderImpl.java b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/MethodSignatureBuilderImpl.java index ca711fd9d6..d73b52b5ad 100644 --- a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/MethodSignatureBuilderImpl.java +++ b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/MethodSignatureBuilderImpl.java @@ -16,6 +16,10 @@ import org.opendaylight.yangtools.sal.binding.model.api.Type; import org.opendaylight.yangtools.sal.binding.model.api.type.builder.MethodSignatureBuilder; import org.opendaylight.yangtools.util.LazyCollections; +/** + * @deprecated Use {@link org.opendaylight.mdsal.binding.generator.util.generated.type.builder.MethodSignatureBuilderImpl} instead. + */ +@Deprecated final class MethodSignatureBuilderImpl extends AbstractTypeMemberBuilder implements MethodSignatureBuilder { private List parameters = Collections.emptyList(); diff --git a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/MethodSignatureImpl.java b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/MethodSignatureImpl.java index 2b3c5fc339..184132946b 100644 --- a/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/MethodSignatureImpl.java +++ b/binding/mdsal-binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/generated/type/builder/MethodSignatureImpl.java @@ -14,6 +14,10 @@ import org.opendaylight.yangtools.sal.binding.model.api.AnnotationType; import org.opendaylight.yangtools.sal.binding.model.api.MethodSignature; import org.opendaylight.yangtools.sal.binding.model.api.Type; +/** + * @deprecated Use {@link org.opendaylight.mdsal.binding.generator.util.generated.type.builder.MethodSignatureImpl} instead. + */ +@Deprecated class MethodSignatureImpl extends AbstractTypeMember implements MethodSignature { private final List params;