001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.apache.maven.tools.plugin.extractor.annotations.datamodel;
020
021import java.lang.annotation.Annotation;
022import java.util.List;
023import java.util.Objects;
024
025import org.apache.maven.plugins.annotations.Parameter;
026
027/**
028 * @author Olivier Lamy
029 * @since 3.0
030 */
031public class ParameterAnnotationContent extends AnnotatedField implements Parameter {
032
033    private String name;
034
035    private String alias;
036
037    private String property;
038
039    private String defaultValue;
040
041    private boolean required = false;
042
043    private boolean readonly = false;
044
045    private String className;
046
047    private boolean annotationOnMethod;
048
049    private final List<String> typeParameters;
050
051    public ParameterAnnotationContent(
052            String fieldName, String className, List<String> typeParameters, boolean annotationOnMethod) {
053        super(fieldName);
054        this.className = className;
055        this.typeParameters = typeParameters;
056        this.annotationOnMethod = annotationOnMethod;
057    }
058
059    public ParameterAnnotationContent(
060            String fieldName,
061            String alias,
062            String property,
063            String defaultValue,
064            boolean required,
065            boolean readonly,
066            String className,
067            List<String> typeParameters,
068            boolean annotationOnMethod) {
069        this(fieldName, className, typeParameters, annotationOnMethod);
070        this.alias = alias;
071        this.property = property;
072        this.defaultValue = defaultValue;
073        this.required = required;
074        this.readonly = readonly;
075    }
076
077    @Override
078    public String name() {
079        return name;
080    }
081
082    public void name(String name) {
083        this.name = name;
084    }
085
086    @Override
087    public String alias() {
088        return alias;
089    }
090
091    public void alias(String alias) {
092        this.alias = alias;
093    }
094
095    @Override
096    public String property() {
097        return property;
098    }
099
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}