Skip to content

Commit 0f3d289

Browse files
authored
Merge pull request #15 from mageddo-projects/third-party-libs-reflection-generation
Third party libs reflection generation
2 parents 3b8f463 + 3357371 commit 0f3d289

37 files changed

+942
-240
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ end_of_line = lf
1818
insert_final_newline = true
1919
charset = utf-8
2020
indent_size = 2
21-
indent_style = space
21+
indent_style = tab
2222
trim_trailing_whitespace = true
2323
max_line_length = 100
2424
ij_formatter_off_tag = @formatter:off

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,15 @@
1-
# annotation-processing-tools
1+
## Annotation Processing Tools
22
A set of useful tools when creating annotation processing libs
3+
4+
## [Lombok-Ext][1]
5+
* Adds support to Text Blocks
6+
7+
## [Reflection Config Generator][2]
8+
* Automatically generates [json reflect config][3] for specified classes or entire packages.
9+
10+
## Requirements
11+
* Java 7+
12+
13+
[1]: lombok-ext
14+
[2]: reflection-config-generator
15+
[3]: https://www.graalvm.org/22.0/reference-manual/native-image/Reflection/#manual-configuration

aptools/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
dependencies {
22

33
compile("org.apache.commons:commons-lang3:3.9")
4+
compile("org.reflections:reflections:0.10.2")
45
compileOnly files(org.gradle.internal.jvm.Jvm.current().toolsJar)
56

67
testCompile group: 'commons-io', name: 'commons-io', version: '2.6'
Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
package com.mageddo.aptools;
22

3+
import java.util.List;
4+
5+
import org.apache.commons.lang3.StringUtils;
6+
37
public class ClassUtils {
48
private ClassUtils() {
59
}
610

711
public static String getClassPackage(String className) {
812
final int lastIndexOf = className.lastIndexOf('.');
9-
if(lastIndexOf < 0){
13+
if (lastIndexOf < 0) {
1014
return className;
1115
}
1216
return className.substring(0, lastIndexOf);
@@ -15,4 +19,29 @@ public static String getClassPackage(String className) {
1519
public static boolean doPackageOwnClass(String packageName, String className) {
1620
return getClassPackage(className).contains(packageName);
1721
}
22+
23+
public static List<Class<?>> findNestClasses(Class<?> clazz) {
24+
throw new UnsupportedOperationException("Not able to find class nested classes yet");
25+
}
26+
27+
public static Class<?> forName(String className) {
28+
try {
29+
return Class.forName(className);
30+
} catch (ClassNotFoundException e) {
31+
throw new RuntimeException(e);
32+
}
33+
}
34+
35+
public static boolean doClassOwnPossibleSubClassOrIsTheSame(String expected, String current) {
36+
// todo talvez tenha que ser melhor validado
37+
return StringUtils.trimToEmpty(current).startsWith(expected);
38+
}
39+
40+
public static boolean isAssignableFrom(Class a, Class b) {
41+
return a.isAssignableFrom(b);
42+
}
43+
44+
public static String getName(Class clazz) {
45+
return clazz.getName();
46+
}
1847
}

aptools/src/main/java/com/mageddo/aptools/elements/ElementFinder.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,7 @@ private static <T>void find(Element e, Predicate<Element> predicate, List<Elemen
4040
}
4141
}
4242

43+
public static List<Element> findNestedClasses(Element element) {
44+
return find(element, ElementKind.CLASS);
45+
}
4346
}

aptools/src/main/java/com/mageddo/aptools/elements/ElementUtils.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.util.Arrays;
44
import java.util.HashSet;
5+
import java.util.Objects;
56
import java.util.Set;
67

78
import javax.lang.model.element.Element;
@@ -41,4 +42,7 @@ private static boolean isTypeElement(Element e) {
4142
return TYPE_ELEMENTS.contains(e.getKind());
4243
}
4344

45+
public static boolean isEquals(Element element, String className) {
46+
return Objects.equals(ElementUtils.toClassName(element), className);
47+
}
4448
}

aptools/src/main/java/com/mageddo/aptools/log/ApLogger.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
import javax.annotation.processing.Messager;
44
import javax.tools.Diagnostic.Kind;
55

6+
import org.apache.commons.lang3.exception.ExceptionUtils;
7+
68
/**
79
*
810
*/
911
public class ApLogger implements Logger {
1012

13+
public static final Kind LOG_LEVEL = Kind.NOTE;
1114
private final Messager messager;
1215

1316
public ApLogger(Messager messager) {
@@ -16,6 +19,14 @@ public ApLogger(Messager messager) {
1619

1720
@Override
1821
public void error(String format, Object... args) {
22+
if (args.length > 0 && args[args.length - 1] instanceof Throwable) {
23+
args[args.length - 1] = ExceptionUtils.getStackTrace((Throwable) args[args.length - 1]);
24+
this.log(
25+
Kind.ERROR,
26+
format + "\n%s",
27+
args
28+
);
29+
}
1930
this.log(Kind.ERROR, format, args);
2031
}
2132

@@ -35,7 +46,7 @@ public void debug(String format, Object... args) {
3546
}
3647

3748
private void log(Kind level, String format, Object[] args) {
38-
if(level.ordinal() > Kind.NOTE.ordinal()){
49+
if (level.ordinal() > LOG_LEVEL.ordinal()) {
3950
return;
4051
}
4152
messager.printMessage(level, String.format(format, args));

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ if (JavaVersion.current() != JavaVersion.VERSION_1_8) {
2020

2121
subprojects {
2222

23-
apply plugin: "java"
23+
apply plugin: "java-library"
2424

2525
repositories {
2626
mavenLocal()

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
repositoryUrl=https://github.com/mageddo-projects/annotation-processing-tools.git
2-
version=2.3.4
2+
version=2.4.0
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)