Skip to content

Commit fbec42d

Browse files
committed
Fix Checkstyle errors and add license files
1 parent 7e6877e commit fbec42d

16 files changed

Lines changed: 133 additions & 50 deletions

File tree

api/src/main/java/org/mapstruct/tools/gem/Gem.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
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+
*/
16
package org.mapstruct.tools.gem;
27

38
import javax.lang.model.element.AnnotationMirror;

api/src/main/java/org/mapstruct/tools/gem/GemDefinition.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919
@Repeatable(GemDefinitions.class)
2020
@Retention(RetentionPolicy.SOURCE)
21-
@Target({ ElementType.PACKAGE,ElementType.TYPE })
21+
@Target({ ElementType.PACKAGE, ElementType.TYPE })
2222
public @interface GemDefinition {
2323

2424
/**

api/src/main/java/org/mapstruct/tools/gem/GemDefinitions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* @author Sjaak Derksen
1515
*/
1616
@Retention(RetentionPolicy.CLASS)
17-
@Target({ ElementType.PACKAGE,ElementType.TYPE })
17+
@Target({ ElementType.PACKAGE, ElementType.TYPE })
1818
public @interface GemDefinitions {
1919

2020
/**

api/src/main/java/org/mapstruct/tools/gem/GemValue.java

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
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+
*/
16
package org.mapstruct.tools.gem;
27

38
import java.util.List;
@@ -15,53 +20,64 @@
1520
*/
1621
public 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
*/

processor/src/main/java/org/mapstruct/tools/gem/processor/GemInfo.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
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+
*/
16
package org.mapstruct.tools.gem.processor;
27

38
import java.util.List;
@@ -6,8 +11,8 @@
611

712
public class GemInfo {
813

9-
private final String BUILDER_NAME = "Builder";
10-
private final String BUILDER_IMPL_NAME = "BuilderImpl";
14+
private static final String BUILDER_NAME = "Builder";
15+
private static final String BUILDER_IMPL_NAME = "BuilderImpl";
1116

1217
private final String gemPackageName;
1318
private final String annotationName;
@@ -18,7 +23,8 @@ public class GemInfo {
1823

1924
private final List<GemValueInfo> gemValueInfos;
2025

21-
public GemInfo(String gemPackageName, String annotationName, String annotationFqn, List<GemValueInfo> gemValueInfos ) {
26+
public GemInfo(String gemPackageName, String annotationName, String annotationFqn,
27+
List<GemValueInfo> gemValueInfos) {
2228
this.gemPackageName = gemPackageName;
2329
this.gemName = annotationName + "Gem";
2430
this.annotationName = annotationName;

processor/src/main/java/org/mapstruct/tools/gem/processor/GemProcessor.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
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+
*/
16
package org.mapstruct.tools.gem.processor;
27

38
import java.io.IOException;
@@ -90,7 +95,7 @@ public boolean process(Set<? extends TypeElement> annotationTypes, RoundEnvironm
9095
private void addGemInfo(AnnotationMirror gemDefinitionMirror, Element definingElement) {
9196

9297
// create gem info
93-
DeclaredType gemDeclaredType = util.getAnnotationValue( gemDefinitionMirror,"value", DeclaredType.class );
98+
DeclaredType gemDeclaredType = util.getAnnotationValue( gemDefinitionMirror, "value", DeclaredType.class );
9499
PackageElement pkg = processingEnv.getElementUtils().getPackageOf( definingElement );
95100
String gemName = util.getSimpleName( gemDeclaredType );
96101
String gemFqn = util.getFullyQualifiedName( gemDeclaredType );
@@ -137,7 +142,7 @@ else if (String.class.getName().equals( fqn ) ) {
137142
}
138143
else {
139144
GemInfo usedGem = gemInfos.stream()
140-
.filter( g ->fqn.equals( g.getAnnotationFqn() ) )
145+
.filter( g -> fqn.equals( g.getAnnotationFqn() ) )
141146
.findFirst()
142147
.orElse( null );
143148
if ( usedGem != null ) {
@@ -179,9 +184,12 @@ else if (String.class.getName().equals( fqn ) ) {
179184
}
180185

181186
private void write( ) {
182-
TypeElement gemElement = processingEnv.getElementUtils().getTypeElement( "org.annotationhelper.GemDefinitions" );
187+
TypeElement gemElement = processingEnv.getElementUtils()
188+
.getTypeElement( "org.annotationhelper.GemDefinitions" );
183189
for ( GemInfo gemInfo : gemInfos ) {
184-
try (Writer writer = processingEnv.getFiler().createSourceFile( gemInfo.getGemPackageName() + "." + gemInfo.getGemName(), gemElement ).openWriter()) {
190+
try (Writer writer = processingEnv.getFiler()
191+
.createSourceFile( gemInfo.getGemPackageName() + "." + gemInfo.getGemName(), gemElement )
192+
.openWriter()) {
185193
Configuration cfg = new Configuration( new Version( "2.3.21" ) );
186194
cfg.setClassForTemplateLoading( GemProcessor.class, "/" );
187195
cfg.setDefaultEncoding( "UTF-8" );

processor/src/main/java/org/mapstruct/tools/gem/processor/GemValueInfo.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
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+
*/
16
package org.mapstruct.tools.gem.processor;
27

38
import javax.lang.model.type.TypeMirror;

processor/src/main/java/org/mapstruct/tools/gem/processor/GemValueType.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
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+
*/
16
package org.mapstruct.tools.gem.processor;
27

38
public class GemValueType {
@@ -14,7 +19,7 @@ public class GemValueType {
1419

1520
public GemValueType(GemInfo gemInfo, boolean isArray) {
1621
this.elementName = gemInfo.getGemName();
17-
this.name = isArray? "List<" + elementName + ">" : elementName;
22+
this.name = isArray ? "List<" + elementName + ">" : elementName;
1823
this.fqn = gemInfo.getGemPackageName() + "." + gemInfo.getGemName();
1924
this.gemName = gemInfo.getGemName();
2025
this.pacakage = gemInfo.getGemPackageName();
@@ -25,7 +30,7 @@ public GemValueType(GemInfo gemInfo, boolean isArray) {
2530

2631
public GemValueType(Class clazz, boolean isEnum, boolean isArray) {
2732
this.elementName = clazz.getSimpleName();
28-
this.name = isArray? "List<" + clazz.getSimpleName() + ">" : clazz.getSimpleName();
33+
this.name = isArray ? "List<" + clazz.getSimpleName() + ">" : clazz.getSimpleName();
2934
this.fqn = clazz.getName();
3035
this.pacakage = clazz.getPackage().getName();
3136
this.isEnum = isEnum;

processor/src/main/java/org/mapstruct/tools/gem/processor/Util.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
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+
*/
16
package org.mapstruct.tools.gem.processor;
27

3-
import java.util.Map;
48
import javax.lang.model.element.AnnotationMirror;
59
import javax.lang.model.element.AnnotationValue;
610
import javax.lang.model.element.Element;
711
import javax.lang.model.element.ElementKind;
812
import javax.lang.model.element.ExecutableElement;
913
import javax.lang.model.element.TypeElement;
10-
import javax.lang.model.type.ArrayType;
1114
import javax.lang.model.type.DeclaredType;
1215
import javax.lang.model.type.TypeKind;
1316
import javax.lang.model.type.TypeMirror;
@@ -24,12 +27,12 @@ public class Util {
2427
this.elements = elements;
2528
}
2629

27-
<T> T getAnnotationValue(AnnotationMirror mirror, String methodName, Class<T> clazz ) {
30+
<T> T getAnnotationValue(AnnotationMirror mirror, String methodName, Class<T> clazz) {
2831
AnnotationValue annotationValue = getAnnotationValue( mirror, methodName );
2932
return annotationValue == null ? null : clazz.cast( annotationValue.getValue() );
3033
}
3134

32-
AnnotationValue getAnnotationValue(AnnotationMirror mirror, String methodName ) {
35+
AnnotationValue getAnnotationValue(AnnotationMirror mirror, String methodName) {
3336
ExecutableElement method = mirror.getAnnotationType()
3437
.asElement()
3538
.getEnclosedElements()
@@ -42,17 +45,17 @@ AnnotationValue getAnnotationValue(AnnotationMirror mirror, String methodName )
4245
return mirror.getElementValues().get( method );
4346
}
4447

45-
private boolean isMethodWithName(Element e, String methodName ) {
46-
return ElementKind.METHOD == e.getKind() && methodName.equals(e.getSimpleName().toString() );
48+
private boolean isMethodWithName(Element e, String methodName) {
49+
return ElementKind.METHOD == e.getKind() && methodName.equals( e.getSimpleName().toString() );
4750
}
4851

4952
String getFullyQualifiedName(DeclaredType type) {
5053
return ( (TypeElement) type.asElement() ).getQualifiedName().toString();
5154
}
5255

53-
boolean isEnumeration( TypeMirror type ) {
54-
if (TypeKind.DECLARED == type.getKind() ) {
55-
DeclaredType declaredType = ( DeclaredType ) type;
56+
boolean isEnumeration(TypeMirror type) {
57+
if ( TypeKind.DECLARED == type.getKind() ) {
58+
DeclaredType declaredType = (DeclaredType) type;
5659
return ElementKind.ENUM == declaredType.asElement().getKind();
5760
}
5861
return false;

processor/src/main/resources/Gem.ftl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
<#--
2+
3+
Copyright MapStruct Authors.
4+
5+
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
6+
7+
-->
18
<#-- @ftlvariable name="gemInfo" type="org.mapstruct.tools.gem.processor.GemInfo" -->
2-
/*
3-
*
4-
*/
59
package ${gemInfo.gemPackageName};
610

711
import java.util.ArrayList;

0 commit comments

Comments
 (0)