Skip to content

Commit 08f0912

Browse files
committed
Fixing tests
1 parent ecc54b1 commit 08f0912

File tree

5 files changed

+52
-22
lines changed

5 files changed

+52
-22
lines changed

reflection-config-generator/acceptance-tests/src/test/java/com/acme/ReflectionConfigGenerationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void mustConfigureReflectJson() throws JsonProcessingException {
2929
final List<JsonNode> items = readReflectConfig();
3030

3131
// assert
32-
assertEquals(11, items.size());
32+
assertEquals(13, items.size());
3333
assertEquals(getResourceAsString("/reflection-config-generation-test/001.json"), objectMapper.writeValueAsString(items));
3434
}
3535

reflection-config-generator/acceptance-tests/src/test/resources/reflection-config-generation-test/001.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,22 @@
66
"allPublicMethods" : false,
77
"allPublicFields" : false,
88
"allDeclaredFields" : true
9+
}, {
10+
"name" : "com.acme.ClassWithNestedClass",
11+
"allDeclaredConstructors" : false,
12+
"allPublicConstructors" : false,
13+
"allDeclaredMethods" : false,
14+
"allPublicMethods" : false,
15+
"allPublicFields" : false,
16+
"allDeclaredFields" : false
17+
}, {
18+
"name" : "com.acme.ClassWithNestedClass$NestedClass",
19+
"allDeclaredConstructors" : false,
20+
"allPublicConstructors" : false,
21+
"allDeclaredMethods" : false,
22+
"allPublicMethods" : false,
23+
"allPublicFields" : false,
24+
"allDeclaredFields" : false
925
}, {
1026
"name" : "com.acme.Fruit",
1127
"allDeclaredConstructors" : true,
@@ -14,6 +30,14 @@
1430
"allPublicMethods" : true,
1531
"allPublicFields" : true,
1632
"allDeclaredFields" : true
33+
}, {
34+
"name" : "com.acme.Fruit$ShouldNotScan",
35+
"allDeclaredConstructors" : true,
36+
"allPublicConstructors" : true,
37+
"allDeclaredMethods" : true,
38+
"allPublicMethods" : true,
39+
"allPublicFields" : true,
40+
"allDeclaredFields" : true
1741
}, {
1842
"name" : "com.acme.Person",
1943
"allDeclaredConstructors" : true,

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

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

20+
import org.apache.commons.lang3.StringUtils;
21+
22+
import static com.mageddo.aptools.elements.ElementUtils.toClassName;
2023
import nativeimage.Reflection;
2124
import nativeimage.Reflections;
22-
import static com.mageddo.aptools.elements.ElementUtils.toClassName;
2325
import static nativeimage.core.NativeImages.solvePath;
2426
import nativeimage.core.domain.ReflectionConfig;
2527
import nativeimage.core.io.NativeImagePropertiesWriter;
@@ -135,10 +137,9 @@ void addMatchingProjectSourceElements(
135137
private Element chooseElement(
136138
Element element, Reflection reflection, RoundEnvironment roundEnv
137139
) {
138-
if (!ReflectionUtils.isVoid(reflection)) {
139-
return this.findElementAndNested(ClassUtils.getName(reflection.scanClass()), roundEnv);
140-
} else if (!reflection.scanClassName().isEmpty()) {
141-
return this.findElementAndNested(reflection.scanClassName(), roundEnv);
140+
final String className = ReflectionUtils.getClassName(reflection);
141+
if (StringUtils.isNotBlank(className)) {
142+
return this.findElementAndNested(className, roundEnv);
142143
}
143144
return element;
144145
}

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package nativeimage.core;
22

3+
import nativeimage.Reflection;
4+
5+
import org.apache.commons.lang3.StringUtils;
6+
37
import javax.lang.model.type.MirroredTypeException;
48

59
public class ReflectionUtils {
@@ -10,4 +14,20 @@ public static boolean isVoid(nativeimage.Reflection reflection) {
1014
return e.getTypeMirror().toString().startsWith(Void.class.getName());
1115
}
1216
}
17+
18+
public static String getClassName(Reflection reflectionAnn){
19+
return StringUtils.firstNonBlank(getScanClass(reflectionAnn), reflectionAnn.scanClassName());
20+
}
21+
22+
private static String getScanClass(Reflection reflectionAnn) {
23+
if (ReflectionUtils.isVoid(reflectionAnn)) {
24+
return null;
25+
}
26+
try {
27+
return reflectionAnn.scanClass().getName();
28+
} catch (MirroredTypeException e) {
29+
return e.getTypeMirror().toString();
30+
}
31+
}
32+
1333
}

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

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
import java.util.Collections;
44
import java.util.Set;
55

6-
import javax.lang.model.type.MirroredTypeException;
7-
86
import com.mageddo.aptools.ClassUtils;
97

108
import org.apache.commons.lang3.StringUtils;
@@ -18,9 +16,7 @@ private TypeBuilder() {
1816
}
1917

2018
public static Set<String> of(Reflection reflectionAnn, String clazzName) {
21-
final String expectedClassName = StringUtils.firstNonBlank(
22-
getScanClass(reflectionAnn), reflectionAnn.scanClassName()
23-
);
19+
final String expectedClassName = ReflectionUtils.getClassName(reflectionAnn);
2420
if(StringUtils.isNotBlank(expectedClassName)){
2521
if(ClassUtils.doClassOwnPossibleSubClassOrIsTheSame(expectedClassName, clazzName)){
2622
return toSet(clazzName);
@@ -35,17 +31,6 @@ public static Set<String> of(Reflection reflectionAnn, String clazzName) {
3531
return toSet(clazzName);
3632
}
3733

38-
private static String getScanClass(Reflection reflectionAnn) {
39-
if (reflectionAnn.scanClass() == Void.class) {
40-
return null;
41-
}
42-
try {
43-
return reflectionAnn.scanClass().getName();
44-
} catch (MirroredTypeException e) {
45-
return e.getTypeMirror().toString();
46-
}
47-
}
48-
4934
private static Set<String> toSet(String type) {
5035
return Collections.singleton(type);
5136
}

0 commit comments

Comments
 (0)