2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.binding.generator.util.generated.type.builder;
10 import org.opendaylight.yangtools.sal.binding.model.api.AccessModifier;
11 import org.opendaylight.yangtools.sal.binding.model.api.AnnotationType;
12 import org.opendaylight.yangtools.sal.binding.model.api.Type;
13 import org.opendaylight.yangtools.sal.binding.model.api.type.builder.AnnotationTypeBuilder;
14 import org.opendaylight.yangtools.sal.binding.model.api.type.builder.TypeMemberBuilder;
16 import java.util.ArrayList;
17 import java.util.List;
19 abstract class AbstractTypeMemberBuilder<T extends TypeMemberBuilder<T>> implements TypeMemberBuilder<T> {
20 private final String name;
21 private Type returnType;
22 private final List<AnnotationTypeBuilder> annotationBuilders;
23 private String comment = "";
24 private boolean isFinal;
25 private AccessModifier accessModifier;
27 public AbstractTypeMemberBuilder(final String name) {
29 this.annotationBuilders = new ArrayList<>();
33 public AnnotationTypeBuilder addAnnotation(String packageName, String name) {
34 if (packageName == null) {
35 throw new IllegalArgumentException("Annotation Type cannot have package name null!");
38 throw new IllegalArgumentException("Annotation Type cannot have name as null!");
40 final AnnotationTypeBuilder builder = new AnnotationTypeBuilderImpl(
42 annotationBuilders.add(builder);
46 protected Type getReturnType() {
50 protected List<AnnotationTypeBuilder> getAnnotationBuilders() {
51 return annotationBuilders;
54 protected String getComment() {
58 protected boolean isFinal() {
62 protected AccessModifier getAccessModifier() {
63 return accessModifier;
67 public String getName() {
71 protected abstract T thisInstance();
74 public T setReturnType(Type returnType) {
75 if (returnType == null) {
76 throw new IllegalArgumentException("Return Type of member cannot be null!");
78 this.returnType = returnType;
79 return thisInstance();
83 public T setAccessModifier(AccessModifier modifier) {
84 if (modifier == null) {
85 throw new IllegalArgumentException("Access Modifier for member type cannot be null!");
87 this.accessModifier = modifier;
88 return thisInstance();
92 public T setComment(String comment) {
93 if (comment == null) {
96 this.comment = comment;
97 return thisInstance();
101 public T setFinal(boolean isFinal) {
102 this.isFinal = isFinal;
103 return thisInstance();
106 protected List<AnnotationType> toAnnotationTypes() {
107 final List<AnnotationType> annotations = new ArrayList<>();
108 for (final AnnotationTypeBuilder annotBuilder : getAnnotationBuilders()) {
109 if (annotBuilder != null) {
110 annotations.add(annotBuilder.toInstance());
117 public int hashCode() {
118 final int prime = 31;
120 result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
121 result = prime * result
122 + ((getReturnType() == null) ? 0 : getReturnType().hashCode());
127 public boolean equals(Object obj) {
134 if (getClass() != obj.getClass()) {
137 MethodSignatureBuilderImpl other = (MethodSignatureBuilderImpl) obj;
138 if (getName() == null) {
139 if (other.getName() != null) {
142 } else if (!getName().equals(other.getName())) {
145 if (getReturnType() == null) {
146 if (other.getReturnType() != null) {
149 } else if (!getReturnType().equals(other.getReturnType())) {
156 public String toString() {
157 StringBuilder builder = new StringBuilder();
158 builder.append("GeneratedPropertyImpl [name=");
159 builder.append(getName());
160 builder.append(", annotations=");
161 builder.append(getAnnotationBuilders());
162 builder.append(", comment=");
163 builder.append(getComment());
164 builder.append(", returnType=");
165 builder.append(getReturnType());
166 builder.append(", isFinal=");
167 builder.append(isFinal());
168 builder.append(", modifier=");
169 builder.append(getAccessModifier());
171 return builder.toString();