Skip to content

Commit ecc54b1

Browse files
committed
Fixing void class check bug
1 parent f0fdb02 commit ecc54b1

File tree

6 files changed

+48
-13
lines changed

6 files changed

+48
-13
lines changed

aptools/src/main/java/com/mageddo/aptools/ClassUtils.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ private ClassUtils() {
1010

1111
public static String getClassPackage(String className) {
1212
final int lastIndexOf = className.lastIndexOf('.');
13-
if(lastIndexOf < 0){
13+
if (lastIndexOf < 0) {
1414
return className;
1515
}
1616
return className.substring(0, lastIndexOf);
@@ -20,7 +20,7 @@ public static boolean doPackageOwnClass(String packageName, String className) {
2020
return getClassPackage(className).contains(packageName);
2121
}
2222

23-
public static List<Class<?>> findNestClasses(Class<?> clazz){
23+
public static List<Class<?>> findNestClasses(Class<?> clazz) {
2424
throw new UnsupportedOperationException();
2525
}
2626

@@ -36,4 +36,12 @@ public static boolean doClassOwnPossibleSubClassOrIsTheSame(String expected, Str
3636
// todo talvez tenha que ser melhor validado
3737
return StringUtils.trimToEmpty(current).startsWith(expected);
3838
}
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+
}
3947
}

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.OTHER;
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));

reflection-config-generator/src/main/java/nativeimage/core/NativeImageReflectionConfigGenerator.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import nativeimage.core.domain.ReflectionConfig;
2525
import nativeimage.core.io.NativeImagePropertiesWriter;
2626
import nativeimage.core.io.ReflectionConfigWriter;
27-
import static nativeimage.thirdparty.ThirdPartyPackageScanner.findPackageClasses;
27+
import static nativeimage.core.thirdparty.ThirdPartyPackageScanner.findPackageClasses;
2828

2929
/**
3030
* Will generate native image reflection config to project source classes.
@@ -95,9 +95,9 @@ void addMatchingProjectLibsClasses(Reflection reflection) {
9595
}
9696

9797
static Class<?> chooseClass(Reflection reflection) {
98-
return reflection.scanClass() != Void.class
99-
? reflection.scanClass()
100-
: ClassUtils.forName(reflection.scanClassName());
98+
return ReflectionUtils.isVoid(reflection)
99+
? ClassUtils.forName(reflection.scanClassName())
100+
: reflection.scanClass();
101101
}
102102

103103
void addClassAndNested(Reflection reflection, Class<?> clazz) {
@@ -135,8 +135,8 @@ void addMatchingProjectSourceElements(
135135
private Element chooseElement(
136136
Element element, Reflection reflection, RoundEnvironment roundEnv
137137
) {
138-
if (reflection.scanClass() != Void.class) {
139-
return this.findElementAndNested(reflection.scanClass().getName(), roundEnv);
138+
if (!ReflectionUtils.isVoid(reflection)) {
139+
return this.findElementAndNested(ClassUtils.getName(reflection.scanClass()), roundEnv);
140140
} else if (!reflection.scanClassName().isEmpty()) {
141141
return this.findElementAndNested(reflection.scanClassName(), roundEnv);
142142
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package nativeimage.core;
2+
3+
import javax.lang.model.type.MirroredTypeException;
4+
5+
public class ReflectionUtils {
6+
public static boolean isVoid(nativeimage.Reflection reflection) {
7+
try {
8+
return reflection.scanClass() == Void.class;
9+
} catch (MirroredTypeException e) {
10+
return e.getTypeMirror().toString().startsWith(Void.class.getName());
11+
}
12+
}
13+
}

reflection-config-generator/src/main/java/nativeimage/thirdparty/ThirdPartyPackageScanner.java renamed to reflection-config-generator/src/main/java/nativeimage/core/thirdparty/ThirdPartyPackageScanner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package nativeimage.thirdparty;
1+
package nativeimage.core.thirdparty;
22

33
import java.lang.reflect.Modifier;
44
import java.util.LinkedHashSet;

reflection-config-generator/src/main/java/nativeimage/processor/AnnotationProcessor.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
import com.mageddo.aptools.log.Logger;
1818
import com.mageddo.aptools.log.LoggerFactory;
1919

20-
import org.apache.commons.lang3.exception.ExceptionUtils;
21-
2220
import nativeimage.core.NativeImageReflectionConfigGenerator;
2321

2422
@SupportedAnnotationTypes("*")
@@ -43,7 +41,12 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
4341
processor.process(new LinkedHashSet<>(annotations), roundEnv);
4442
}
4543
} catch (Exception e){
46-
this.logger.error("fatal: %s\n ", e.getMessage(), ExceptionUtils.getStackTrace(e));
44+
this.logger.error("fatal: %s", e.getMessage(), e);
45+
// this.logger.error("%s fatal: %s\n %s",
46+
// ClassUtils.getSimpleName(this),
47+
// e.getMessage(),
48+
// ExceptionUtils.getStackTrace(e)
49+
// );
4750
}
4851
return false;
4952
}

0 commit comments

Comments
 (0)