-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.controller.sal.binding.generator.impl;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Arrays;\r
-import java.util.Collections;\r
-import java.util.HashSet;\r
-import java.util.List;\r
-import java.util.Set;\r
-\r
-import org.opendaylight.controller.sal.binding.model.api.AccessModifier;\r
-import org.opendaylight.controller.sal.binding.model.api.Constant;\r
-import org.opendaylight.controller.sal.binding.model.api.Enumeration;\r
-import org.opendaylight.controller.sal.binding.model.api.GeneratedType;\r
-import org.opendaylight.controller.sal.binding.model.api.MethodSignature;\r
-import org.opendaylight.controller.sal.binding.model.api.Type;\r
-import org.opendaylight.controller.sal.binding.model.api.type.builder.ConstantBuilder;\r
-import org.opendaylight.controller.sal.binding.model.api.type.builder.EnumBuilder;\r
-import org.opendaylight.controller.sal.binding.model.api.type.builder.GeneratedTypeBuilder;\r
-import org.opendaylight.controller.sal.binding.model.api.type.builder.MethodSignatureBuilder;\r
-\r
-public final class GeneratedTypeBuilderImpl implements GeneratedTypeBuilder {\r
-\r
- private static final String[] SET_VALUES = new String[] { "abstract",\r
- "assert", "boolean", "break", "byte", "case", "catch", "char",\r
- "class", "const", "continue", "default", "double", "do", "else",\r
- "enum", "extends", "false", "final", "finally", "float", "for",\r
- "goto", "if", "implements", "import", "instanceof", "int",\r
- "interface", "long", "native", "new", "null", "package", "private",\r
- "protected", "public", "return", "short", "static", "strictfp",\r
- "super", "switch", "synchronized", "this", "throw", "throws",\r
- "transient", "true", "try", "void", "volatile", "while" };\r
-\r
- public static final Set<String> JAVA_RESERVED_WORDS = new HashSet<String>(\r
- Arrays.asList(SET_VALUES));\r
-\r
- private String packageName;\r
- private String comment;\r
- private final String name;\r
- private final List<EnumBuilder> enumDefinitions = new ArrayList<EnumBuilder>();\r
- private final List<ConstantBuilder> constantDefintions = new ArrayList<ConstantBuilder>();\r
- private final List<MethodSignatureBuilder> methodDefinitions = new ArrayList<MethodSignatureBuilder>();\r
-\r
- public GeneratedTypeBuilderImpl(final String packageName, final String name) {\r
- this.packageName = validatePackage(packageName);\r
- this.name = name;\r
- }\r
-\r
- public static String validatePackage(final String packageName) {\r
- if (packageName != null) {\r
- final String[] packNameParts = packageName.split("\\.");\r
- if (packNameParts != null) {\r
- final StringBuilder builder = new StringBuilder();\r
- for (int i = 0; i < packNameParts.length; ++i) {\r
- if (JAVA_RESERVED_WORDS.contains(packNameParts[i])) {\r
- packNameParts[i] = "_" + packNameParts[i];\r
- }\r
- if (i > 0) {\r
- builder.append(".");\r
- }\r
-\r
- builder.append(packNameParts[i]);\r
- }\r
- return builder.toString();\r
- }\r
- }\r
- return packageName;\r
- }\r
-\r
- @Override\r
- public Type getParentType() {\r
- return this;\r
- }\r
-\r
- @Override\r
- public String getPackageName() {\r
- return packageName;\r
- }\r
-\r
- @Override\r
- public String getName() {\r
- return name;\r
- }\r
-\r
- @Override\r
- public void addComment(String comment) {\r
- this.comment = comment;\r
- }\r
-\r
- @Override\r
- public ConstantBuilder addConstant(Type type, String name, Object value) {\r
- final ConstantBuilder builder = new ConstantBuilderImpl(type, name,\r
- value);\r
- constantDefintions.add(builder);\r
-\r
- return builder;\r
- }\r
-\r
- @Override\r
- public EnumBuilder addEnumeration(final String name) {\r
- final EnumBuilder builder = new EnumerationBuilderImpl(packageName,\r
- name);\r
- enumDefinitions.add(builder);\r
- return builder;\r
- }\r
-\r
- @Override\r
- public MethodSignatureBuilder addMethod(final String name) {\r
- final MethodSignatureBuilder builder = new MethodSignatureBuilderImpl(\r
- this, name);\r
- methodDefinitions.add(builder);\r
- return builder;\r
- }\r
-\r
- @Override\r
- public GeneratedType toInstance() {\r
- packageName = (packageName);\r
-\r
- return new GeneratedTypeImpl(this, packageName, name, enumDefinitions,\r
- constantDefintions, methodDefinitions);\r
- }\r
-\r
- private static final class MethodSignatureBuilderImpl implements\r
- MethodSignatureBuilder {\r
- private final String name;\r
- private Type returnType;\r
- private final List<MethodSignature.Parameter> parameters;\r
- private String comment = "";\r
- private final Type parent;\r
-\r
- public MethodSignatureBuilderImpl(final Type parent, final String name) {\r
- super();\r
- this.name = name;\r
- this.parent = parent;\r
- parameters = new ArrayList<MethodSignature.Parameter>();\r
- // TODO: move implementation elsewhere!\r
-\r
- }\r
-\r
- @Override\r
- public void addReturnType(Type returnType) {\r
- if (returnType != null) {\r
- this.returnType = returnType;\r
- }\r
- }\r
-\r
- @Override\r
- public void addParameter(Type type, String name) {\r
- parameters.add(new MethodParameterImpl(name, type));\r
- }\r
-\r
- @Override\r
- public void addComment(String comment) {\r
- this.comment = comment;\r
- }\r
-\r
- @Override\r
- public MethodSignature toInstance(Type definingType) {\r
- return new MethodSignatureImpl(definingType, name, comment,\r
- returnType, parameters);\r
- }\r
-\r
- @Override\r
- public int hashCode() {\r
- final int prime = 31;\r
- int result = 1;\r
- result = prime * result + ((name == null) ? 0 : name.hashCode());\r
- return result;\r
- }\r
-\r
- @Override\r
- public boolean equals(Object obj) {\r
- if (this == obj) {\r
- return true;\r
- }\r
- if (obj == null) {\r
- return false;\r
- }\r
- if (getClass() != obj.getClass()) {\r
- return false;\r
- }\r
- MethodSignatureBuilderImpl other = (MethodSignatureBuilderImpl) obj;\r
- if (name == null) {\r
- if (other.name != null) {\r
- return false;\r
- }\r
- } else if (!name.equals(other.name)) {\r
- return false;\r
- }\r
- return true;\r
- }\r
-\r
- @Override\r
- public String toString() {\r
- StringBuilder builder = new StringBuilder();\r
- builder.append("MethodBuilderImpl [name=");\r
- builder.append(name);\r
- builder.append(", returnType=");\r
- builder.append(returnType);\r
- builder.append(", parameters=");\r
- builder.append(parameters);\r
- builder.append(", comment=");\r
- builder.append(comment);\r
- builder.append(", parent=");\r
- builder.append(parent.getName());\r
- builder.append("]");\r
- return builder.toString();\r
- }\r
-\r
- }\r
-\r
- private static final class MethodSignatureImpl implements MethodSignature {\r
-\r
- private final String name;\r
- private final String comment;\r
- private final Type definingType;\r
- private final Type returnType;\r
- private final List<Parameter> params;\r
-\r
- public MethodSignatureImpl(final Type definingType, final String name,\r
- final String comment, final Type returnType,\r
- final List<Parameter> params) {\r
- super();\r
- this.name = name;\r
- this.comment = comment;\r
- this.definingType = definingType;\r
- this.returnType = returnType;\r
- this.params = Collections.unmodifiableList(params);\r
- }\r
-\r
- @Override\r
- public String getName() {\r
- return name;\r
- }\r
-\r
- @Override\r
- public String getComment() {\r
- return comment;\r
- }\r
-\r
- @Override\r
- public Type getDefiningType() {\r
- return definingType;\r
- }\r
-\r
- @Override\r
- public Type getReturnType() {\r
- return returnType;\r
- }\r
-\r
- @Override\r
- public List<Parameter> getParameters() {\r
- return params;\r
- }\r
-\r
- @Override\r
- public AccessModifier getAccessModifier() {\r
- return AccessModifier.PUBLIC;\r
- }\r
-\r
- @Override\r
- public int hashCode() {\r
- final int prime = 31;\r
- int result = 1;\r
- result = prime * result\r
- + ((comment == null) ? 0 : comment.hashCode());\r
- result = prime * result + ((name == null) ? 0 : name.hashCode());\r
- result = prime * result\r
- + ((params == null) ? 0 : params.hashCode());\r
- result = prime * result\r
- + ((returnType == null) ? 0 : returnType.hashCode());\r
-\r
- if (definingType != null) {\r
- result = prime\r
- * result\r
- + ((definingType.getPackageName() == null) ? 0\r
- : definingType.getPackageName().hashCode());\r
- result = prime\r
- * result\r
- + ((definingType.getName() == null) ? 0 : definingType\r
- .getName().hashCode());\r
- }\r
-\r
- return result;\r
- }\r
-\r
- @Override\r
- public boolean equals(Object obj) {\r
- if (this == obj) {\r
- return true;\r
- }\r
- if (obj == null) {\r
- return false;\r
- }\r
- if (getClass() != obj.getClass()) {\r
- return false;\r
- }\r
- MethodSignatureImpl other = (MethodSignatureImpl) obj;\r
- if (comment == null) {\r
- if (other.comment != null) {\r
- return false;\r
- }\r
- } else if (!comment.equals(other.comment)) {\r
- return false;\r
- }\r
- if (name == null) {\r
- if (other.name != null) {\r
- return false;\r
- }\r
- } else if (!name.equals(other.name)) {\r
- return false;\r
- }\r
- if (params == null) {\r
- if (other.params != null) {\r
- return false;\r
- }\r
- } else if (!params.equals(other.params)) {\r
- return false;\r
- }\r
- if (definingType == null) {\r
- if (other.definingType != null) {\r
- return false;\r
- }\r
- } else if ((definingType != null) && (other.definingType != null)) {\r
- if (!definingType.getPackageName().equals(\r
- other.definingType.getPackageName())\r
- && !definingType.getName().equals(\r
- other.definingType.getName())) {\r
- return false;\r
- }\r
- }\r
- if (returnType == null) {\r
- if (other.returnType != null) {\r
- return false;\r
- }\r
- } else if (!returnType.equals(other.returnType)) {\r
- return false;\r
- }\r
- return true;\r
- }\r
-\r
- @Override\r
- public String toString() {\r
- StringBuilder builder = new StringBuilder();\r
- builder.append("MethodImpl [name=");\r
- builder.append(name);\r
- builder.append(", comment=");\r
- builder.append(comment);\r
- if (definingType != null) {\r
- builder.append(", definingType=");\r
- builder.append(definingType.getPackageName());\r
- builder.append(".");\r
- builder.append(definingType.getName());\r
- } else {\r
- builder.append(", definingType= null");\r
- }\r
- builder.append(", returnType=");\r
- builder.append(returnType);\r
- builder.append(", params=");\r
- builder.append(params);\r
- builder.append("]");\r
- return builder.toString();\r
- }\r
- }\r
-\r
- private static final class GeneratedTypeImpl implements GeneratedType {\r
-\r
- private final Type parent;\r
- private final String packageName;\r
- private final String name;\r
- private final List<Enumeration> enumDefinitions;\r
- private final List<Constant> constantDefintions;\r
- private final List<MethodSignature> methodDefinitions;\r
-\r
- public GeneratedTypeImpl(final Type parent, final String packageName,\r
- final String name, final List<EnumBuilder> enumBuilders,\r
- final List<ConstantBuilder> constantBuilders,\r
- final List<MethodSignatureBuilder> methodBuilders) {\r
- super();\r
- this.parent = parent;\r
- this.packageName = packageName;\r
- this.name = name;\r
-\r
- this.constantDefintions = toUnmodifiableConstants(constantBuilders);\r
- this.enumDefinitions = toUnmodifiableEnums(enumBuilders);\r
- this.methodDefinitions = toUnmodifiableMethods(methodBuilders);\r
- }\r
-\r
- private List<MethodSignature> toUnmodifiableMethods(\r
- List<MethodSignatureBuilder> methodBuilders) {\r
- final List<MethodSignature> methods = new ArrayList<MethodSignature>();\r
- for (final MethodSignatureBuilder methodBuilder : methodBuilders) {\r
- methods.add(methodBuilder.toInstance(this));\r
- }\r
- return Collections.unmodifiableList(methods);\r
- }\r
-\r
- private List<Enumeration> toUnmodifiableEnums(\r
- List<EnumBuilder> enumBuilders) {\r
- final List<Enumeration> enums = new ArrayList<Enumeration>();\r
- for (final EnumBuilder enumBuilder : enumBuilders) {\r
- enums.add(enumBuilder.toInstance(this));\r
- }\r
- return Collections.unmodifiableList(enums);\r
- }\r
-\r
- private List<Constant> toUnmodifiableConstants(\r
- List<ConstantBuilder> constantBuilders) {\r
- final List<Constant> constants = new ArrayList<Constant>();\r
- for (final ConstantBuilder enumBuilder : constantBuilders) {\r
- constants.add(enumBuilder.toInstance(this));\r
- }\r
- return Collections.unmodifiableList(constants);\r
- }\r
-\r
- @Override\r
- public String getPackageName() {\r
- return packageName;\r
- }\r
-\r
- @Override\r
- public String getName() {\r
- return name;\r
- }\r
-\r
- @Override\r
- public Type getParentType() {\r
- return parent;\r
- }\r
-\r
- @Override\r
- public List<Enumeration> getEnumDefintions() {\r
- return enumDefinitions;\r
- }\r
-\r
- @Override\r
- public List<Constant> getConstantDefinitions() {\r
- return constantDefintions;\r
- }\r
-\r
- @Override\r
- public List<MethodSignature> getMethodDefinitions() {\r
- return methodDefinitions;\r
- }\r
-\r
- @Override\r
- public int hashCode() {\r
- final int prime = 31;\r
- int result = 1;\r
- result = prime\r
- * result\r
- + ((constantDefintions == null) ? 0 : constantDefintions\r
- .hashCode());\r
- result = prime\r
- * result\r
- + ((enumDefinitions == null) ? 0 : enumDefinitions\r
- .hashCode());\r
- result = prime\r
- * result\r
- + ((methodDefinitions == null) ? 0 : methodDefinitions\r
- .hashCode());\r
- result = prime * result + ((name == null) ? 0 : name.hashCode());\r
- result = prime * result\r
- + ((packageName == null) ? 0 : packageName.hashCode());\r
- return result;\r
- }\r
-\r
- @Override\r
- public boolean equals(Object obj) {\r
- if (this == obj) {\r
- return true;\r
- }\r
- if (obj == null) {\r
- return false;\r
- }\r
- if (getClass() != obj.getClass()) {\r
- return false;\r
- }\r
- GeneratedTypeImpl other = (GeneratedTypeImpl) obj;\r
- if (constantDefintions == null) {\r
- if (other.constantDefintions != null) {\r
- return false;\r
- }\r
- } else if (!constantDefintions.equals(other.constantDefintions)) {\r
- return false;\r
- }\r
- if (enumDefinitions == null) {\r
- if (other.enumDefinitions != null) {\r
- return false;\r
- }\r
- } else if (!enumDefinitions.equals(other.enumDefinitions)) {\r
- return false;\r
- }\r
- if (methodDefinitions == null) {\r
- if (other.methodDefinitions != null) {\r
- return false;\r
- }\r
- } else if (!methodDefinitions.equals(other.methodDefinitions)) {\r
- return false;\r
- }\r
- if (name == null) {\r
- if (other.name != null) {\r
- return false;\r
- }\r
- } else if (!name.equals(other.name)) {\r
- return false;\r
- }\r
- if (packageName == null) {\r
- if (other.packageName != null) {\r
- return false;\r
- }\r
- } else if (!packageName.equals(other.packageName)) {\r
- return false;\r
- }\r
- return true;\r
- }\r
-\r
- @Override\r
- public String toString() {\r
- StringBuilder builder = new StringBuilder();\r
- builder.append("GeneratedTypeImpl [parent=");\r
- builder.append(parent.getName());\r
- builder.append(", packageName=");\r
- builder.append(packageName);\r
- builder.append(", name=");\r
- builder.append(name);\r
- builder.append(", enumDefinitions=");\r
- builder.append(enumDefinitions);\r
- builder.append(", constantDefintions=");\r
- builder.append(constantDefintions);\r
- builder.append(", methodDefinitions=");\r
- builder.append(methodDefinitions);\r
- builder.append("]");\r
- return builder.toString();\r
- }\r
- }\r
-}\r
+/*
+ * 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.controller.sal.binding.generator.impl;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.opendaylight.controller.sal.binding.model.api.AccessModifier;
+import org.opendaylight.controller.sal.binding.model.api.Constant;
+import org.opendaylight.controller.sal.binding.model.api.Enumeration;
+import org.opendaylight.controller.sal.binding.model.api.GeneratedType;
+import org.opendaylight.controller.sal.binding.model.api.MethodSignature;
+import org.opendaylight.controller.sal.binding.model.api.Type;
+import org.opendaylight.controller.sal.binding.model.api.type.builder.ConstantBuilder;
+import org.opendaylight.controller.sal.binding.model.api.type.builder.EnumBuilder;
+import org.opendaylight.controller.sal.binding.model.api.type.builder.GeneratedTypeBuilder;
+import org.opendaylight.controller.sal.binding.model.api.type.builder.MethodSignatureBuilder;
+
+public final class GeneratedTypeBuilderImpl implements GeneratedTypeBuilder {
+
+ private final String packageName;
+ private String comment;
+ private final String name;
+ private final List<EnumBuilder> enumDefinitions = new ArrayList<EnumBuilder>();
+ private final List<ConstantBuilder> constantDefintions = new ArrayList<ConstantBuilder>();
+ private final List<MethodSignatureBuilder> methodDefinitions = new ArrayList<MethodSignatureBuilder>();
+
+ public GeneratedTypeBuilderImpl(final String packageName, final String name) {
+ this.packageName = packageName;
+ this.name = name;
+ }
+
+ @Override
+ public Type getParentType() {
+ return this;
+ }
+
+ @Override
+ public String getPackageName() {
+ return packageName;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public void addComment(String comment) {
+ this.comment = comment;
+ }
+
+ @Override
+ public ConstantBuilder addConstant(Type type, String name, Object value) {
+ final ConstantBuilder builder = new ConstantBuilderImpl(type, name,
+ value);
+ constantDefintions.add(builder);
+
+ return builder;
+ }
+
+ @Override
+ public EnumBuilder addEnumeration(final String name) {
+ final EnumBuilder builder = new EnumerationBuilderImpl(packageName,
+ name);
+ enumDefinitions.add(builder);
+ return builder;
+ }
+
+ @Override
+ public MethodSignatureBuilder addMethod(final String name) {
+ final MethodSignatureBuilder builder = new MethodSignatureBuilderImpl(
+ this, name);
+ methodDefinitions.add(builder);
+ return builder;
+ }
+
+ @Override
+ public GeneratedType toInstance() {
+ return new GeneratedTypeImpl(this, packageName, name, enumDefinitions,
+ constantDefintions, methodDefinitions);
+ }
+
+ private static final class MethodSignatureBuilderImpl implements
+ MethodSignatureBuilder {
+ private final String name;
+ private Type returnType;
+ private final List<MethodSignature.Parameter> parameters;
+ private String comment = "";
+ private final Type parent;
+
+ public MethodSignatureBuilderImpl(final Type parent, final String name) {
+ super();
+ this.name = name;
+ this.parent = parent;
+ parameters = new ArrayList<MethodSignature.Parameter>();
+ //TODO: move implementation elsewhere!
+
+ }
+
+ @Override
+ public void addReturnType(Type returnType) {
+ if (returnType != null) {
+ this.returnType = returnType;
+ }
+ }
+
+ @Override
+ public void addParameter(Type type, String name) {
+ parameters.add(new MethodParameterImpl(name, type));
+ }
+
+ @Override
+ public void addComment(String comment) {
+ this.comment = comment;
+ }
+
+ @Override
+ public MethodSignature toInstance(Type definingType) {
+ return new MethodSignatureImpl(definingType, name, comment,
+ returnType, parameters);
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((name == null) ? 0 : name.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ MethodSignatureBuilderImpl other = (MethodSignatureBuilderImpl) obj;
+ if (name == null) {
+ if (other.name != null) {
+ return false;
+ }
+ } else if (!name.equals(other.name)) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append("MethodBuilderImpl [name=");
+ builder.append(name);
+ builder.append(", returnType=");
+ builder.append(returnType);
+ builder.append(", parameters=");
+ builder.append(parameters);
+ builder.append(", comment=");
+ builder.append(comment);
+ builder.append(", parent=");
+ builder.append(parent.getName());
+ builder.append("]");
+ return builder.toString();
+ }
+
+ }
+
+ private static final class MethodSignatureImpl implements MethodSignature {
+
+ private final String name;
+ private final String comment;
+ private final Type definingType;
+ private final Type returnType;
+ private final List<Parameter> params;
+
+ public MethodSignatureImpl(final Type definingType, final String name,
+ final String comment, final Type returnType,
+ final List<Parameter> params) {
+ super();
+ this.name = name;
+ this.comment = comment;
+ this.definingType = definingType;
+ this.returnType = returnType;
+ this.params = Collections.unmodifiableList(params);
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public String getComment() {
+ return comment;
+ }
+
+ @Override
+ public Type getDefiningType() {
+ return definingType;
+ }
+
+ @Override
+ public Type getReturnType() {
+ return returnType;
+ }
+
+ @Override
+ public List<Parameter> getParameters() {
+ return params;
+ }
+
+ @Override
+ public AccessModifier getAccessModifier() {
+ return AccessModifier.PUBLIC;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result
+ + ((comment == null) ? 0 : comment.hashCode());
+ result = prime * result + ((name == null) ? 0 : name.hashCode());
+ result = prime * result
+ + ((params == null) ? 0 : params.hashCode());
+ result = prime * result
+ + ((returnType == null) ? 0 : returnType.hashCode());
+
+ if (definingType != null) {
+ result = prime
+ * result
+ + ((definingType.getPackageName() == null) ? 0
+ : definingType.getPackageName().hashCode());
+ result = prime
+ * result
+ + ((definingType.getName() == null) ? 0 : definingType
+ .getName().hashCode());
+ }
+
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ MethodSignatureImpl other = (MethodSignatureImpl) obj;
+ if (comment == null) {
+ if (other.comment != null) {
+ return false;
+ }
+ } else if (!comment.equals(other.comment)) {
+ return false;
+ }
+ if (name == null) {
+ if (other.name != null) {
+ return false;
+ }
+ } else if (!name.equals(other.name)) {
+ return false;
+ }
+ if (params == null) {
+ if (other.params != null) {
+ return false;
+ }
+ } else if (!params.equals(other.params)) {
+ return false;
+ }
+ if (definingType == null) {
+ if (other.definingType != null) {
+ return false;
+ }
+ } else if ((definingType != null) && (other.definingType != null)) {
+ if (!definingType.getPackageName().equals(
+ other.definingType.getPackageName())
+ && !definingType.getName().equals(
+ other.definingType.getName())) {
+ return false;
+ }
+ }
+ if (returnType == null) {
+ if (other.returnType != null) {
+ return false;
+ }
+ } else if (!returnType.equals(other.returnType)) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append("MethodImpl [name=");
+ builder.append(name);
+ builder.append(", comment=");
+ builder.append(comment);
+ if (definingType != null) {
+ builder.append(", definingType=");
+ builder.append(definingType.getPackageName());
+ builder.append(".");
+ builder.append(definingType.getName());
+ } else {
+ builder.append(", definingType= null");
+ }
+ builder.append(", returnType=");
+ builder.append(returnType);
+ builder.append(", params=");
+ builder.append(params);
+ builder.append("]");
+ return builder.toString();
+ }
+ }
+
+ private static final class GeneratedTypeImpl implements GeneratedType {
+
+ private final Type parent;
+ private final String packageName;
+ private final String name;
+ private final List<Enumeration> enumDefinitions;
+ private final List<Constant> constantDefintions;
+ private final List<MethodSignature> methodDefinitions;
+
+ public GeneratedTypeImpl(final Type parent, final String packageName,
+ final String name, final List<EnumBuilder> enumBuilders,
+ final List<ConstantBuilder> constantBuilders,
+ final List<MethodSignatureBuilder> methodBuilders) {
+ super();
+ this.parent = parent;
+ this.packageName = packageName;
+ this.name = name;
+
+ this.constantDefintions = toUnmodifiableConstants(constantBuilders);
+ this.enumDefinitions = toUnmodifiableEnums(enumBuilders);
+ this.methodDefinitions = toUnmodifiableMethods(methodBuilders);
+ }
+
+ private List<MethodSignature> toUnmodifiableMethods(
+ List<MethodSignatureBuilder> methodBuilders) {
+ final List<MethodSignature> methods = new ArrayList<MethodSignature>();
+ for (final MethodSignatureBuilder methodBuilder : methodBuilders) {
+ methods.add(methodBuilder.toInstance(this));
+ }
+ return Collections.unmodifiableList(methods);
+ }
+
+ private List<Enumeration> toUnmodifiableEnums(
+ List<EnumBuilder> enumBuilders) {
+ final List<Enumeration> enums = new ArrayList<Enumeration>();
+ for (final EnumBuilder enumBuilder : enumBuilders) {
+ enums.add(enumBuilder.toInstance(this));
+ }
+ return Collections.unmodifiableList(enums);
+ }
+
+ private List<Constant> toUnmodifiableConstants(
+ List<ConstantBuilder> constantBuilders) {
+ final List<Constant> constants = new ArrayList<Constant>();
+ for (final ConstantBuilder enumBuilder : constantBuilders) {
+ constants.add(enumBuilder.toInstance(this));
+ }
+ return Collections.unmodifiableList(constants);
+ }
+
+ @Override
+ public String getPackageName() {
+ return packageName;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public Type getParentType() {
+ return parent;
+ }
+
+ @Override
+ public List<Enumeration> getEnumDefintions() {
+ return enumDefinitions;
+ }
+
+ @Override
+ public List<Constant> getConstantDefinitions() {
+ return constantDefintions;
+ }
+
+ @Override
+ public List<MethodSignature> getMethodDefinitions() {
+ return methodDefinitions;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime
+ * result
+ + ((constantDefintions == null) ? 0 : constantDefintions
+ .hashCode());
+ result = prime
+ * result
+ + ((enumDefinitions == null) ? 0 : enumDefinitions
+ .hashCode());
+ result = prime
+ * result
+ + ((methodDefinitions == null) ? 0 : methodDefinitions
+ .hashCode());
+ result = prime * result + ((name == null) ? 0 : name.hashCode());
+ result = prime * result
+ + ((packageName == null) ? 0 : packageName.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ GeneratedTypeImpl other = (GeneratedTypeImpl) obj;
+ if (constantDefintions == null) {
+ if (other.constantDefintions != null) {
+ return false;
+ }
+ } else if (!constantDefintions.equals(other.constantDefintions)) {
+ return false;
+ }
+ if (enumDefinitions == null) {
+ if (other.enumDefinitions != null) {
+ return false;
+ }
+ } else if (!enumDefinitions.equals(other.enumDefinitions)) {
+ return false;
+ }
+ if (methodDefinitions == null) {
+ if (other.methodDefinitions != null) {
+ return false;
+ }
+ } else if (!methodDefinitions.equals(other.methodDefinitions)) {
+ return false;
+ }
+ if (name == null) {
+ if (other.name != null) {
+ return false;
+ }
+ } else if (!name.equals(other.name)) {
+ return false;
+ }
+ if (packageName == null) {
+ if (other.packageName != null) {
+ return false;
+ }
+ } else if (!packageName.equals(other.packageName)) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append("GeneratedTypeImpl [parent=");
+ builder.append(parent.getName());
+ builder.append(", packageName=");
+ builder.append(packageName);
+ builder.append(", name=");
+ builder.append(name);
+ builder.append(", enumDefinitions=");
+ builder.append(enumDefinitions);
+ builder.append(", constantDefintions=");
+ builder.append(constantDefintions);
+ builder.append(", methodDefinitions=");
+ builder.append(methodDefinitions);
+ builder.append("]");
+ return builder.toString();
+ }
+ }
+}