1+ /*
2+ * Copyright MapStruct Authors.
3+ *
4+ * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
5+ */
16package org .mapstruct .tools .gem ;
27
38import java .util .List ;
1520 */
1621public class GemValue <T > {
1722
18-
1923 public static <V > GemValue <V > create (AnnotationValue annotationValue ,
20- AnnotationValue annotationDefaultValue , Class <V > valueClass ) {
24+ AnnotationValue annotationDefaultValue , Class <V > valueClass ) {
2125 V value = annotationValue == null ? null : valueClass .cast ( annotationValue .getValue () );
2226 V defaultValue = annotationDefaultValue == null ? null : valueClass .cast ( annotationDefaultValue .getValue () );
23- return new GemValue <>(value , defaultValue , annotationValue );
27+ return new GemValue <>( value , defaultValue , annotationValue );
2428 }
2529
2630 public static <V > GemValue <List <V >> createArray (AnnotationValue annotationValue ,
27- AnnotationValue annotationDefaultValue , Class <V > valueClass ) {
31+ AnnotationValue annotationDefaultValue , Class <V > valueClass ) {
2832 List <V > value = extractListValues ( annotationValue , valueClass , Function .identity () );
2933 List <V > defaultValue = extractListValues ( annotationDefaultValue , valueClass , Function .identity () );
3034
31- return new GemValue <>(value , defaultValue , annotationValue );
35+ return new GemValue <>( value , defaultValue , annotationValue );
3236 }
3337
3438 public static GemValue <String > createEnum (AnnotationValue annotationValue ,
35- AnnotationValue annotationDefaultValue ) {
36- String value = annotationValue == null ? null : ( (VariableElement ) annotationValue .getValue () ).getSimpleName ().toString ();
37- String defaultValue = annotationDefaultValue == null ? null : ( (VariableElement ) annotationDefaultValue .getValue () ).getSimpleName ().toString ();
38- return new GemValue <>(value , defaultValue , annotationValue );
39+ AnnotationValue annotationDefaultValue ) {
40+ String value = annotationValue == null ? null :
41+ ( (VariableElement ) annotationValue .getValue () ).getSimpleName ().toString ();
42+ String defaultValue = annotationDefaultValue == null ? null :
43+ ( (VariableElement ) annotationDefaultValue .getValue () ).getSimpleName ().toString ();
44+ return new GemValue <>( value , defaultValue , annotationValue );
3945 }
4046
4147 public static GemValue <List <String >> createEnumArray (AnnotationValue annotationValue ,
42- AnnotationValue annotationDefaultValue ) {
43- List <String > value = extractListValues ( annotationValue , VariableElement .class , variableElement -> variableElement .getSimpleName ().toString () );
44- List <String > defaultValue = extractListValues ( annotationDefaultValue , VariableElement .class , variableElement -> variableElement .getSimpleName ().toString () );
48+ AnnotationValue annotationDefaultValue ) {
49+ List <String > value = extractListValues (
50+ annotationValue ,
51+ VariableElement .class ,
52+ variableElement -> variableElement .getSimpleName ().toString ()
53+ );
54+ List <String > defaultValue = extractListValues (
55+ annotationDefaultValue ,
56+ VariableElement .class ,
57+ variableElement -> variableElement .getSimpleName ().toString ()
58+ );
4559
46- return new GemValue <>(value , defaultValue , annotationValue );
60+ return new GemValue <>( value , defaultValue , annotationValue );
4761 }
4862
4963 public static <V > GemValue <V > create (AnnotationValue annotationValue , AnnotationValue annotationDefaultValue ,
50- Function <AnnotationMirror , V > creator ) {
64+ Function <AnnotationMirror , V > creator ) {
5165 V value = annotationValue == null ? null : creator .apply ( (AnnotationMirror ) annotationValue .getValue () );
52- V defaultValue = annotationDefaultValue == null ? null : creator .apply ( (AnnotationMirror ) annotationDefaultValue .getValue () );
66+ V defaultValue = annotationDefaultValue == null ? null :
67+ creator .apply ( (AnnotationMirror ) annotationDefaultValue .getValue () );
5368 return new GemValue <>( value , defaultValue , annotationValue );
5469 }
5570
56- public static <V > GemValue <List <V >> createArray (AnnotationValue annotationValue , AnnotationValue annotationDefaultValue ,
57- Function <AnnotationMirror , V > creator ) {
71+ public static <V > GemValue <List <V >> createArray (AnnotationValue annotationValue ,
72+ AnnotationValue annotationDefaultValue ,
73+ Function <AnnotationMirror , V > creator ) {
5874 List <V > value = extractListValues ( annotationValue , AnnotationMirror .class , creator );
5975 List <V > defaultValue = extractListValues ( annotationDefaultValue , AnnotationMirror .class , creator );
6076 return new GemValue <>( value , defaultValue , annotationValue );
6177 }
6278
6379 private static <V , R > List <R > extractListValues (AnnotationValue annotationValue , Class <V > valueClass ,
64- Function <V , R > mapper ) {
80+ Function <V , R > mapper ) {
6581 List <R > value ;
6682 if ( annotationValue != null ) {
6783 Object definedValue = annotationValue .getValue ();
@@ -78,7 +94,7 @@ private static <V, R> List<R> extractListValues(AnnotationValue annotationValue,
7894 return value ;
7995 }
8096
81- private static <T > Stream <T > toStream (List <?> annotationValues , Class <T > clz ) {
97+ private static <T > Stream <T > toStream (List <?> annotationValues , Class <T > clz ) {
8298 return annotationValues .stream ()
8399 .filter ( AnnotationValue .class ::isInstance )
84100 .map ( AnnotationValue .class ::cast )
@@ -87,7 +103,6 @@ private static <T> Stream<T> toStream(List<?> annotationValues, Class<T> clz ) {
87103 .map ( clz ::cast );
88104 }
89105
90-
91106 private final T value ;
92107 private final T defaultValue ;
93108 private final AnnotationValue annotationValue ;
@@ -115,6 +130,7 @@ public T get() {
115130 public T getValue () {
116131 return value ;
117132 }
133+
118134 /**
119135 * The default value, as declared in the annotation
120136 *
@@ -123,6 +139,7 @@ public T getValue() {
123139 public T getDefaultValue () {
124140 return defaultValue ;
125141 }
142+
126143 /**
127144 * The annotation value, e.g. for printing messages {@link javax.annotation.processing.Messager#printMessage}
128145 *
@@ -131,6 +148,7 @@ public T getDefaultValue() {
131148 public AnnotationValue getAnnotationValue () {
132149 return annotationValue ;
133150 }
151+
134152 /**
135153 * @return true a value is set by user
136154 */
0 commit comments