1 package org.opendaylight.controller.sal.binding.generator.impl;
3 import java.util.ArrayList;
4 import java.util.Collections;
7 import org.opendaylight.controller.sal.binding.model.api.AccessModifier;
8 import org.opendaylight.controller.sal.binding.model.api.AnnotationType;
9 import org.opendaylight.controller.sal.binding.model.api.MethodSignature;
10 import org.opendaylight.controller.sal.binding.model.api.Type;
11 import org.opendaylight.controller.sal.binding.model.api.type.builder.AnnotationTypeBuilder;
12 import org.opendaylight.controller.sal.binding.model.api.type.builder.MethodSignatureBuilder;
14 final class MethodSignatureBuilderImpl implements MethodSignatureBuilder {
15 private final String name;
16 private Type returnType;
17 private final List<MethodSignature.Parameter> parameters;
18 private final List<AnnotationTypeBuilder> annotationBuilders;
19 private String comment = "";
20 private final Type parent;
22 public MethodSignatureBuilderImpl(final Type parent, final String name) {
26 this.parameters = new ArrayList<MethodSignature.Parameter>();
27 this.annotationBuilders = new ArrayList<AnnotationTypeBuilder>();
31 public AnnotationTypeBuilder addAnnotation(String packageName, String name) {
32 if (packageName != null && name != null) {
33 final AnnotationTypeBuilder builder = new AnnotationTypeBuilderImpl(
35 if (annotationBuilders.add(builder)) {
43 public void addReturnType(Type returnType) {
44 if (returnType != null) {
45 this.returnType = returnType;
50 public void addParameter(Type type, String name) {
51 parameters.add(new MethodParameterImpl(name, type));
55 public void addComment(String comment) {
56 this.comment = comment;
60 public MethodSignature toInstance(Type definingType) {
61 return new MethodSignatureImpl(definingType, name, annotationBuilders,
62 comment, returnType, parameters);
66 public int hashCode() {
69 result = prime * result + ((name == null) ? 0 : name.hashCode());
70 result = prime * result
71 + ((parameters == null) ? 0 : parameters.hashCode());
72 result = prime * result
73 + ((returnType == null) ? 0 : returnType.hashCode());
78 public boolean equals(Object obj) {
85 if (getClass() != obj.getClass()) {
88 MethodSignatureBuilderImpl other = (MethodSignatureBuilderImpl) obj;
90 if (other.name != null) {
93 } else if (!name.equals(other.name)) {
96 if (parameters == null) {
97 if (other.parameters != null) {
100 } else if (!parameters.equals(other.parameters)) {
103 if (returnType == null) {
104 if (other.returnType != null) {
107 } else if (!returnType.equals(other.returnType)) {
114 public String toString() {
115 StringBuilder builder = new StringBuilder();
116 builder.append("MethodSignatureBuilderImpl [name=");
117 builder.append(name);
118 builder.append(", returnType=");
119 builder.append(returnType);
120 builder.append(", parameters=");
121 builder.append(parameters);
122 builder.append(", annotationBuilders=");
123 builder.append(annotationBuilders);
124 builder.append(", comment=");
125 builder.append(comment);
126 if (parent != null) {
127 builder.append(", parent=");
128 builder.append(parent.getPackageName());
130 builder.append(parent.getName());
132 builder.append(", parent=null");
135 return builder.toString();
138 private static final class MethodSignatureImpl implements MethodSignature {
140 private final String name;
141 private final String comment;
142 private final Type definingType;
143 private final Type returnType;
144 private final List<Parameter> params;
145 private List<AnnotationType> annotations;
147 public MethodSignatureImpl(final Type definingType, final String name,
148 final List<AnnotationTypeBuilder> annotationBuilders,
149 final String comment, final Type returnType,
150 final List<Parameter> params) {
153 this.comment = comment;
154 this.definingType = definingType;
155 this.returnType = returnType;
156 this.params = Collections.unmodifiableList(params);
158 this.annotations = new ArrayList<AnnotationType>();
159 for (final AnnotationTypeBuilder builder : annotationBuilders) {
160 this.annotations.add(builder.toInstance());
162 this.annotations = Collections.unmodifiableList(this.annotations);
166 public List<AnnotationType> getAnnotations() {
171 public String getName() {
176 public String getComment() {
181 public Type getDefiningType() {
186 public Type getReturnType() {
191 public List<Parameter> getParameters() {
196 public AccessModifier getAccessModifier() {
197 return AccessModifier.PUBLIC;
201 public int hashCode() {
202 final int prime = 31;
204 result = prime * result + ((name == null) ? 0 : name.hashCode());
205 result = prime * result
206 + ((params == null) ? 0 : params.hashCode());
207 result = prime * result
208 + ((returnType == null) ? 0 : returnType.hashCode());
213 public boolean equals(Object obj) {
220 if (getClass() != obj.getClass()) {
223 MethodSignatureImpl other = (MethodSignatureImpl) obj;
225 if (other.name != null) {
228 } else if (!name.equals(other.name)) {
231 if (params == null) {
232 if (other.params != null) {
235 } else if (!params.equals(other.params)) {
238 if (returnType == null) {
239 if (other.returnType != null) {
242 } else if (!returnType.equals(other.returnType)) {
249 public String toString() {
250 StringBuilder builder = new StringBuilder();
251 builder.append("MethodSignatureImpl [name=");
252 builder.append(name);
253 builder.append(", comment=");
254 builder.append(comment);
255 if (definingType != null) {
256 builder.append(", definingType=");
257 builder.append(definingType.getPackageName());
259 builder.append(definingType.getName());
261 builder.append(", definingType= null");
263 builder.append(", returnType=");
264 builder.append(returnType);
265 builder.append(", params=");
266 builder.append(params);
267 builder.append(", annotations=");
268 builder.append(annotations);
270 return builder.toString();