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 java.util.ArrayList;
11 import java.util.List;
13 import org.opendaylight.yangtools.sal.binding.model.api.AccessModifier;
14 import org.opendaylight.yangtools.sal.binding.model.api.AnnotationType;
15 import org.opendaylight.yangtools.sal.binding.model.api.Type;
16 import org.opendaylight.yangtools.sal.binding.model.api.type.builder.AnnotationTypeBuilder;
17 import org.opendaylight.yangtools.sal.binding.model.api.type.builder.TypeMemberBuilder;
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 boolean isStatic;
26 private AccessModifier accessModifier;
28 public AbstractTypeMemberBuilder(final String name) {
30 this.annotationBuilders = new ArrayList<>();
34 public AnnotationTypeBuilder addAnnotation(String packageName, String name) {
35 if (packageName == null) {
36 throw new IllegalArgumentException("Annotation Type cannot have package name null!");
39 throw new IllegalArgumentException("Annotation Type cannot have name as null!");
41 final AnnotationTypeBuilder builder = new AnnotationTypeBuilderImpl(
43 annotationBuilders.add(builder);
47 protected Type getReturnType() {
51 protected List<AnnotationTypeBuilder> getAnnotationBuilders() {
52 return annotationBuilders;
55 protected String getComment() {
59 protected boolean isFinal() {
63 protected boolean isStatic() {
68 public AccessModifier getAccessModifier() {
69 return accessModifier;
73 public String getName() {
77 protected abstract T thisInstance();
80 public T setReturnType(Type returnType) {
81 if (returnType == null) {
82 throw new IllegalArgumentException("Return Type of member cannot be null!");
84 this.returnType = returnType;
85 return thisInstance();
89 public T setAccessModifier(AccessModifier modifier) {
90 if (modifier == null) {
91 throw new IllegalArgumentException("Access Modifier for member type cannot be null!");
93 this.accessModifier = modifier;
94 return thisInstance();
98 public T setComment(String comment) {
99 if (comment == null) {
102 this.comment = comment;
103 return thisInstance();
107 public T setFinal(boolean isFinal) {
108 this.isFinal = isFinal;
109 return thisInstance();
113 public T setStatic(boolean isStatic) {
114 this.isStatic = isStatic;
115 return thisInstance();
118 protected List<AnnotationType> toAnnotationTypes() {
119 final List<AnnotationType> annotations = new ArrayList<>();
120 for (final AnnotationTypeBuilder annotBuilder : getAnnotationBuilders()) {
121 if (annotBuilder != null) {
122 annotations.add(annotBuilder.toInstance());
129 public int hashCode() {
130 final int prime = 31;
132 result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
133 result = prime * result
134 + ((getReturnType() == null) ? 0 : getReturnType().hashCode());
139 public boolean equals(Object obj) {
146 if (getClass() != obj.getClass()) {
149 MethodSignatureBuilderImpl other = (MethodSignatureBuilderImpl) obj;
150 if (getName() == null) {
151 if (other.getName() != null) {
154 } else if (!getName().equals(other.getName())) {
157 if (getReturnType() == null) {
158 if (other.getReturnType() != null) {
161 } else if (!getReturnType().equals(other.getReturnType())) {
168 public String toString() {
169 StringBuilder builder = new StringBuilder();
170 builder.append("GeneratedPropertyImpl [name=");
171 builder.append(getName());
172 builder.append(", annotations=");
173 builder.append(getAnnotationBuilders());
174 builder.append(", comment=");
175 builder.append(getComment());
176 builder.append(", returnType=");
177 builder.append(getReturnType());
178 builder.append(", isFinal=");
179 builder.append(isFinal());
180 builder.append(", modifier=");
181 builder.append(getAccessModifier());
183 return builder.toString();