View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.tools.plugin.extractor.annotations.datamodel;
20  
21  import java.lang.annotation.Annotation;
22  import java.util.List;
23  import java.util.Objects;
24  
25  import org.apache.maven.plugins.annotations.Parameter;
26  
27  /**
28   * @author Olivier Lamy
29   * @since 3.0
30   */
31  public class ParameterAnnotationContent extends AnnotatedField implements Parameter {
32  
33      private String name;
34  
35      private String alias;
36  
37      private String property;
38  
39      private String defaultValue;
40  
41      private boolean required = false;
42  
43      private boolean readonly = false;
44  
45      private String className;
46  
47      private boolean annotationOnMethod;
48  
49      private final List<String> typeParameters;
50  
51      public ParameterAnnotationContent(
52              String fieldName, String className, List<String> typeParameters, boolean annotationOnMethod) {
53          super(fieldName);
54          this.className = className;
55          this.typeParameters = typeParameters;
56          this.annotationOnMethod = annotationOnMethod;
57      }
58  
59      public ParameterAnnotationContent(
60              String fieldName,
61              String alias,
62              String property,
63              String defaultValue,
64              boolean required,
65              boolean readonly,
66              String className,
67              List<String> typeParameters,
68              boolean annotationOnMethod) {
69          this(fieldName, className, typeParameters, annotationOnMethod);
70          this.alias = alias;
71          this.property = property;
72          this.defaultValue = defaultValue;
73          this.required = required;
74          this.readonly = readonly;
75      }
76  
77      @Override
78      public String name() {
79          return name;
80      }
81  
82      public void name(String name) {
83          this.name = name;
84      }
85  
86      @Override
87      public String alias() {
88          return alias;
89      }
90  
91      public void alias(String alias) {
92          this.alias = alias;
93      }
94  
95      @Override
96      public String property() {
97          return property;
98      }
99  
100     public void property(String property) {
101         this.property = property;
102     }
103 
104     @Override
105     public String defaultValue() {
106         return defaultValue;
107     }
108 
109     public void defaultValue(String defaultValue) {
110         this.defaultValue = defaultValue;
111     }
112 
113     @Override
114     public boolean required() {
115         return required;
116     }
117 
118     public void required(boolean required) {
119         this.required = required;
120     }
121 
122     @Override
123     public boolean readonly() {
124         return readonly;
125     }
126 
127     public void readonly(boolean readonly) {
128         this.readonly = readonly;
129     }
130 
131     @Override
132     public Class<? extends Annotation> annotationType() {
133         return null;
134     }
135 
136     public String getClassName() {
137         return className;
138     }
139 
140     public void setClassName(String className) {
141         this.className = className;
142     }
143 
144     public List<String> getTypeParameters() {
145         return typeParameters;
146     }
147 
148     public boolean isAnnotationOnMethod() {
149         return annotationOnMethod;
150     }
151 
152     @Override
153     public String toString() {
154         final StringBuilder sb = new StringBuilder();
155         sb.append(super.toString());
156         sb.append("ParameterAnnotationContent");
157         sb.append("{fieldName='").append(getFieldName()).append('\'');
158         sb.append(", className='").append(getClassName()).append('\'');
159         sb.append(", typeParameters='").append(getTypeParameters()).append('\'');
160         sb.append(", name='").append(name).append('\'');
161         sb.append(", alias='").append(alias).append('\'');
162         sb.append(", alias='").append(alias).append('\'');
163         sb.append(", property='").append(property).append('\'');
164         sb.append(", defaultValue='").append(defaultValue).append('\'');
165         sb.append(", required=").append(required);
166         sb.append(", readonly=").append(readonly);
167         sb.append(", methodSource=").append(annotationOnMethod);
168         sb.append('}');
169         return sb.toString();
170     }
171 
172     @Override
173     public boolean equals(Object o) {
174         if (this == o) {
175             return true;
176         }
177         if (!(o instanceof ParameterAnnotationContent)) {
178             return false;
179         }
180 
181         ParameterAnnotationContent that = (ParameterAnnotationContent) o;
182 
183         if (readonly != that.readonly) {
184             return false;
185         }
186         if (required != that.required) {
187             return false;
188         }
189 
190         if (annotationOnMethod != that.annotationOnMethod) {
191             return false;
192         }
193 
194         if (getFieldName() != null ? !getFieldName().equals(that.getFieldName()) : that.getFieldName() != null) {
195             return false;
196         }
197 
198         if (getClassName() != null ? !getClassName().equals(that.getClassName()) : that.getClassName() != null) {
199             return false;
200         }
201 
202         if (!Objects.equals(typeParameters, that.typeParameters)) {
203             return false;
204         }
205         if (!Objects.equals(alias, that.alias)) {
206             return false;
207         }
208         if (!Objects.equals(defaultValue, that.defaultValue)) {
209             return false;
210         }
211         return Objects.equals(property, that.property);
212     }
213 
214     @Override
215     public int hashCode() {
216         return Objects.hash(
217                 alias,
218                 getFieldName(),
219                 getClassName(),
220                 typeParameters,
221                 property,
222                 defaultValue,
223                 required,
224                 readonly,
225                 annotationOnMethod);
226     }
227 }