Generate @param for RPC invocation methods
[mdsal.git] / binding / mdsal-binding-generator-util / src / main / java / org / opendaylight / mdsal / binding / model / util / generated / type / builder / AbstractTypeMemberBuilder.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.mdsal.binding.model.util.generated.type.builder;
9
10 import static com.google.common.base.Preconditions.checkArgument;
11
12 import com.google.common.collect.ImmutableList;
13 import java.util.ArrayList;
14 import java.util.Collections;
15 import java.util.List;
16 import java.util.Objects;
17 import org.opendaylight.mdsal.binding.model.api.AccessModifier;
18 import org.opendaylight.mdsal.binding.model.api.AnnotationType;
19 import org.opendaylight.mdsal.binding.model.api.JavaTypeName;
20 import org.opendaylight.mdsal.binding.model.api.Type;
21 import org.opendaylight.mdsal.binding.model.api.TypeMemberComment;
22 import org.opendaylight.mdsal.binding.model.api.type.builder.AnnotationTypeBuilder;
23 import org.opendaylight.mdsal.binding.model.api.type.builder.TypeMemberBuilder;
24 import org.opendaylight.yangtools.util.LazyCollections;
25
26 abstract class AbstractTypeMemberBuilder<T extends TypeMemberBuilder<T>> implements TypeMemberBuilder<T> {
27     private final String name;
28     private Type returnType;
29     private List<AnnotationTypeBuilder> annotationBuilders = Collections.emptyList();
30     private TypeMemberComment comment;
31     private boolean isFinal;
32     private boolean isStatic;
33     private AccessModifier accessModifier;
34
35     AbstractTypeMemberBuilder(final String name) {
36         this.name = name;
37     }
38
39     @Override
40     public AnnotationTypeBuilder addAnnotation(final JavaTypeName identifier) {
41         final AnnotationTypeBuilder builder = new AnnotationTypeBuilderImpl(identifier);
42         this.annotationBuilders = LazyCollections.lazyAdd(this.annotationBuilders, builder);
43         return builder;
44     }
45
46     public Type getReturnType() {
47         return this.returnType;
48     }
49
50     protected Iterable<AnnotationTypeBuilder> getAnnotationBuilders() {
51         return this.annotationBuilders;
52     }
53
54     protected TypeMemberComment getComment() {
55         return this.comment;
56     }
57
58     protected boolean isFinal() {
59         return this.isFinal;
60     }
61
62     protected boolean isStatic() {
63         return this.isStatic;
64     }
65
66     @Override
67     public AccessModifier getAccessModifier() {
68         return this.accessModifier;
69     }
70
71     @Override
72     public String getName() {
73         return this.name;
74     }
75
76     protected abstract T thisInstance();
77
78     @Override
79     public T setReturnType(final Type newReturnType) {
80         checkArgument(newReturnType != null, "Return Type of member cannot be null!");
81         this.returnType = newReturnType;
82         return thisInstance();
83     }
84
85     @Override
86     public T setAccessModifier(final AccessModifier modifier) {
87         checkArgument(modifier != null, "Access Modifier for member type cannot be null!");
88         this.accessModifier = modifier;
89         return thisInstance();
90     }
91
92     @Override
93     public T setComment(final TypeMemberComment newComment) {
94         this.comment = newComment;
95         return thisInstance();
96     }
97
98     @Override
99     public T setFinal(final boolean newIsFinal) {
100         this.isFinal = newIsFinal;
101         return thisInstance();
102     }
103
104     @Override
105     public T setStatic(final boolean newIsStatic) {
106         this.isStatic = newIsStatic;
107         return thisInstance();
108     }
109
110     protected List<AnnotationType> toAnnotationTypes() {
111         final List<AnnotationType> annotations = new ArrayList<>();
112         for (final AnnotationTypeBuilder annotBuilder : getAnnotationBuilders()) {
113             if (annotBuilder != null) {
114                 annotations.add(annotBuilder.build());
115             }
116         }
117
118         return ImmutableList.copyOf(annotations);
119     }
120
121     @Override
122     public int hashCode() {
123         final int prime = 31;
124         int result = 1;
125         result = prime * result + Objects.hashCode(getName());
126         result = prime * result + Objects.hashCode(getReturnType());
127         return result;
128     }
129
130     @Override
131     public boolean equals(final Object obj) {
132         if (this == obj) {
133             return true;
134         }
135         if (obj == null || getClass() != obj.getClass()) {
136             return false;
137         }
138         final AbstractTypeMemberBuilder<?> other = (AbstractTypeMemberBuilder<?>) obj;
139         return Objects.equals(getName(), other.getName()) && Objects.equals(getReturnType(), other.getReturnType());
140     }
141
142     @Override
143     public String toString() {
144         return new StringBuilder().append("GeneratedPropertyImpl [name=").append(getName())
145                 .append(", annotations=").append(getAnnotationBuilders())
146                 .append(", comment=").append(getComment())
147                 .append(", returnType=").append(getReturnType())
148                 .append(", isFinal=").append(isFinal())
149                 .append(", modifier=").append(getAccessModifier())
150                 .append(']').toString();
151     }
152 }