Skip to content

Commit b6428e3

Browse files
author
sjaakd
committed
initial
1 parent 86ca43d commit b6428e3

File tree

22 files changed

+1329
-0
lines changed

22 files changed

+1329
-0
lines changed

.gitattributes

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Repository specific GIT options
2+
3+
# Set default handling of line endings
4+
* text=auto
5+
6+
# Explicitly declare text files we want to always be normalized and converted
7+
# to native line endings on checkout.
8+
*.java text
9+
*.xml text
10+
*.txt text
11+
*.md text
12+
13+
# Java-friendly readable chunk headers
14+
15+
*.java diff=java

.gitignore

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Eclipse
2+
.metadata
3+
.recommenders
4+
.classpath
5+
.project
6+
.settings
7+
.factorypath
8+
.checkstyle
9+
.externalToolBuilders
10+
11+
# IntelliJ
12+
*.iml
13+
*.ipr
14+
*.iws
15+
.idea
16+
17+
# Netbeans
18+
nb-configuration.xml
19+
20+
# Build
21+
/**/target/
22+
test-output
23+
24+
# Misc.
25+
.DS_Store

api/pom.xml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Copyright MapStruct Authors.
5+
6+
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
7+
8+
-->
9+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
10+
<modelVersion>4.0.0</modelVersion>
11+
<build>
12+
<plugins>
13+
<plugin>
14+
<groupId>org.apache.maven.plugins</groupId>
15+
<artifactId>maven-compiler-plugin</artifactId>
16+
<configuration>
17+
<source>8</source>
18+
<target>8</target>
19+
</configuration>
20+
</plugin>
21+
</plugins>
22+
</build>
23+
24+
<parent>
25+
<groupId>org.annotationhelper</groupId>
26+
<version>1.0.0-SNAPSHOT</version>
27+
<artifactId>annotationhelper-aggregator</artifactId>
28+
<relativePath>../pom.xml</relativePath>
29+
</parent>
30+
31+
<artifactId>annotationhelper-api</artifactId>
32+
<packaging>jar</packaging>
33+
<name>Annotation Helper API</name>
34+
35+
</project>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
*/
6+
package org.annotationhelper;
7+
8+
import java.lang.annotation.ElementType;
9+
import java.lang.annotation.Repeatable;
10+
import java.lang.annotation.Retention;
11+
import java.lang.annotation.RetentionPolicy;
12+
import java.lang.annotation.Target;
13+
14+
/**
15+
* @author Sjaak Derksen
16+
*
17+
* Defining a GemDefinion will generate a Gem representing the annotation in the {@link GemDefinition#value()}
18+
*/
19+
@Repeatable(GemDefinitions.class)
20+
@Retention(RetentionPolicy.SOURCE)
21+
@Target({ ElementType.PACKAGE,ElementType.TYPE })
22+
public @interface GemDefinition {
23+
24+
/**
25+
* @return the annotation for which a Gem should be generated
26+
*/
27+
Class<?> value();
28+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
*/
6+
package org.annotationhelper;
7+
8+
import java.lang.annotation.ElementType;
9+
import java.lang.annotation.Retention;
10+
import java.lang.annotation.RetentionPolicy;
11+
import java.lang.annotation.Target;
12+
13+
/**
14+
* @author Sjaak Derksen
15+
*/
16+
@Retention(RetentionPolicy.CLASS)
17+
@Target({ ElementType.PACKAGE,ElementType.TYPE })
18+
public @interface GemDefinitions {
19+
20+
/**
21+
* @return The gem definitions
22+
*/
23+
GemDefinition[] value();
24+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package org.annotationhelper;
2+
3+
import javax.lang.model.element.AnnotationValue;
4+
import javax.tools.Diagnostic;
5+
6+
/**
7+
* Class representing a annotation value
8+
*
9+
* @param <T> the type represented by this annotation value
10+
*/
11+
public interface GemValue<T> {
12+
13+
/**
14+
* @return the value, null when not set
15+
*/
16+
T getValue();
17+
18+
/**
19+
* @return the default value for the annotation value
20+
*/
21+
T getDefaultValue();
22+
23+
/**
24+
* The annotation value, e.g. for printing messages {@link javax.annotation.processing.Messager#printMessage}
25+
*
26+
* @return the annotation value (null when not set)
27+
*/
28+
AnnotationValue getAnnotationValue();
29+
30+
/**
31+
* @return true a value is set
32+
*/
33+
boolean hasValue();
34+
35+
/**
36+
* An annotation is valid when set or when not set and default value is present.
37+
*
38+
* @return true when valid
39+
*/
40+
boolean isValid();
41+
}

pom.xml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Copyright MapStruct Authors.
5+
6+
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
7+
8+
-->
9+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
10+
11+
<modelVersion>4.0.0</modelVersion>
12+
<groupId>org.annotationhelper</groupId>
13+
<version>1.0.0-SNAPSHOT</version>
14+
<artifactId>annotationhelper-aggregator</artifactId>
15+
<packaging>pom</packaging>
16+
<name>Annotation Helper Aggregator</name>
17+
18+
<modules>
19+
<module>api</module>
20+
<module>processor</module>
21+
<module>test</module>
22+
</modules>
23+
24+
<!-- Required here as the maven-release-plugin will otherwise get the URL wrong -->
25+
<scm>
26+
<connection>scm:git:git://github.com/mapstruct/annotationhelper.git</connection>
27+
<developerConnection>scm:git:git@github.com:mapstruct/annotationhelper.git</developerConnection>
28+
<url>https://github.com/mapstruct/annotationhelper/</url>
29+
<tag>HEAD</tag>
30+
</scm>
31+
32+
<properties>
33+
<maven.deploy.skip>true</maven.deploy.skip>
34+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
35+
<maven.compiler.source>1.8</maven.compiler.source>
36+
<maven.compiler.target>1.8</maven.compiler.target>
37+
<assertj.version>3.11.1</assertj.version>
38+
<junit.version>5.5.2</junit.version>
39+
</properties>
40+
41+
<dependencyManagement>
42+
<dependencies>
43+
<dependency>
44+
<groupId>org.freemarker</groupId>
45+
<artifactId>freemarker</artifactId>
46+
<version>2.3.29</version>
47+
</dependency>
48+
<dependency>
49+
<groupId>org.assertj</groupId>
50+
<artifactId>assertj-core</artifactId>
51+
<version>${assertj.version}</version>
52+
</dependency>
53+
<dependency>
54+
<groupId>org.junit.jupiter</groupId>
55+
<artifactId>junit-jupiter-engine</artifactId>
56+
<version>${junit.version}</version>
57+
</dependency>
58+
</dependencies>
59+
</dependencyManagement>
60+
</project>

processor/pom.xml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Copyright MapStruct Authors.
5+
6+
Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
7+
8+
-->
9+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
10+
<modelVersion>4.0.0</modelVersion>
11+
<parent>
12+
<groupId>org.annotationhelper</groupId>
13+
<version>1.0.0-SNAPSHOT</version>
14+
<artifactId>annotationhelper-aggregator</artifactId>
15+
<relativePath>../pom.xml</relativePath>
16+
</parent>
17+
18+
<artifactId>annotationhelper-processor</artifactId>
19+
<packaging>jar</packaging>
20+
<name>Annotation Helper Processor</name>
21+
22+
<dependencies>
23+
24+
<dependency>
25+
<groupId>${project.parent.groupId}</groupId>
26+
<artifactId>annotationhelper-api</artifactId>
27+
<version>${project.parent.version}</version>
28+
</dependency>
29+
30+
<dependency>
31+
<groupId>org.freemarker</groupId>
32+
<artifactId>freemarker</artifactId>
33+
</dependency>
34+
35+
<dependency>
36+
<groupId>org.junit.jupiter</groupId>
37+
<artifactId>junit-jupiter-engine</artifactId>
38+
<scope>test</scope>
39+
</dependency>
40+
41+
<dependency>
42+
<groupId>org.assertj</groupId>
43+
<artifactId>assertj-core</artifactId>
44+
<scope>test</scope>
45+
</dependency>
46+
47+
</dependencies>
48+
49+
<build>
50+
<plugins>
51+
<plugin>
52+
<groupId>org.apache.maven.plugins</groupId>
53+
<artifactId>maven-compiler-plugin</artifactId>
54+
<executions>
55+
<execution>
56+
<id>default-compile</id>
57+
<configuration>
58+
<compilerArgument>-proc:none</compilerArgument>
59+
</configuration>
60+
</execution>
61+
</executions>
62+
</plugin>
63+
</plugins>
64+
</build>
65+
</project>
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package org.annotationhelper.impl;
2+
3+
import java.util.List;
4+
import java.util.Objects;
5+
import java.util.Set;
6+
import java.util.stream.Collectors;
7+
8+
public class GemInfo {
9+
10+
private final String gemPackageName;
11+
private final String annotationName;
12+
private final String annotationFqn;
13+
private final String gemName;
14+
15+
private final List<GemValueInfo> gemValueInfos;
16+
17+
public GemInfo(String gemPackageName, String annotationName, String annotationFqn, List<GemValueInfo> gemValueInfos ) {
18+
this.gemPackageName = gemPackageName;
19+
this.gemName = annotationName + "Gem";
20+
this.annotationName = annotationName;
21+
this.annotationFqn = annotationFqn;
22+
this.gemValueInfos = gemValueInfos;
23+
}
24+
25+
public String getGemName() {
26+
return gemName;
27+
}
28+
29+
public String getAnnotationName() {
30+
return annotationName;
31+
}
32+
33+
public String getAnnotationFqn() {
34+
return annotationFqn;
35+
}
36+
37+
public String getGemPackageName() {
38+
return gemPackageName;
39+
}
40+
41+
public List<GemValueInfo> getGemValueInfos() {
42+
return gemValueInfos;
43+
}
44+
45+
public Set<String> getImports() {
46+
return gemValueInfos.stream()
47+
.map( GemValueInfo::getValueType )
48+
.filter( this::isNotJavaLang )
49+
.filter( this::isNotSamePackage )
50+
.map( GemValueType::getFqn )
51+
.collect( Collectors.toSet() );
52+
}
53+
54+
public boolean isContainingArrays() {
55+
return gemValueInfos.stream()
56+
.map( GemValueInfo::getValueType )
57+
.filter( GemValueType::isArray )
58+
.findAny()
59+
.map( Objects::nonNull )
60+
.orElse( false );
61+
}
62+
63+
public Set<GemValueType> getUsedGemValueTypes() {
64+
return gemValueInfos.stream().map( GemValueInfo::getValueType ).collect( Collectors.toSet() );
65+
}
66+
67+
private boolean isNotSamePackage( GemValueType valueType ) {
68+
return !valueType.getPacakage().equals( gemPackageName );
69+
}
70+
71+
private boolean isNotJavaLang( GemValueType valueType ) {
72+
return !"java.lang".equals( valueType.getPacakage() );
73+
}
74+
}

0 commit comments

Comments
 (0)