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