3
3
import com .google .common .primitives .Primitives ;
4
4
import me .zort .configurationlib .annotation .NodeName ;
5
5
import me .zort .configurationlib .util .NodeTypeToken ;
6
+ import me .zort .configurationlib .util .Placeholders ;
6
7
7
8
import java .lang .reflect .Field ;
8
9
import java .lang .reflect .InvocationTargetException ;
@@ -56,18 +57,26 @@ public void set(Object from) {
56
57
}
57
58
58
59
public <T > T map (Class <T > typeClass ) {
60
+ return map (typeClass , new Placeholders ());
61
+ }
62
+
63
+ public <T > T map (Class <T > typeClass , Placeholders placeholders ) {
59
64
try {
60
65
if (Primitives .isWrapperType (Primitives .wrap (typeClass ))) {
61
66
// We cannot map sections to primitive types since
62
67
// sections are not leaf nodes.
63
68
return null ;
64
69
}
65
- return map (typeClass .getDeclaredConstructor ().newInstance ());
70
+ return map (typeClass .getDeclaredConstructor ().newInstance (), placeholders );
66
71
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e ) {
67
72
throw new RuntimeException (e );
68
73
}
69
74
}
70
75
76
+ public <T > T map (T obj ) {
77
+ return map (obj , new Placeholders ());
78
+ }
79
+
71
80
/**
72
81
* Tries top map this section to provided object. This method assigns values to the fields
73
82
* according to the node types and rules specified by child classes.
@@ -76,7 +85,7 @@ public <T> T map(Class<T> typeClass) {
76
85
* @return The mapped object.
77
86
* @param <T> The type of the object to map to.
78
87
*/
79
- public <T > T map (T obj ) {
88
+ public <T > T map (T obj , Placeholders placeholders ) {
80
89
Class <?> typeClass = obj .getClass ();
81
90
if (Primitives .isWrapperType (Primitives .wrap (typeClass ))) {
82
91
return null ;
@@ -89,7 +98,7 @@ public <T> T map(T obj) {
89
98
continue ;
90
99
}
91
100
field .setAccessible (true );
92
- Object value = buildValue (field , node );
101
+ Object value = buildValue (field , node , placeholders );
93
102
if (value != null ) {
94
103
// Null values are skipped.
95
104
try {
@@ -119,7 +128,7 @@ public <T> T map(T obj) {
119
128
* @param node Node to build value from.
120
129
* @return Value to assign to field.
121
130
*/
122
- public Object buildValue (Field field , Node <L > node ) {
131
+ public Object buildValue (Field field , Node <L > node , Placeholders placeholders ) {
123
132
Object value = null ;
124
133
if (node instanceof SimpleNode && isPrimitive (field .getClass ())) {
125
134
value = ((SimpleNode <L >) node ).get ();
0 commit comments