11
11
import org .freedesktop .dbus .Struct ;
12
12
import org .freedesktop .dbus .annotations .Position ;
13
13
import org .freedesktop .dbus .exceptions .DBusException ;
14
+ import org .freedesktop .dbus .utils .generator .ClassBuilderInfo .ClassConstructor ;
14
15
import org .freedesktop .dbus .utils .generator .ClassBuilderInfo .ClassType ;
15
16
16
17
import com .github .hypfvieh .util .StringUtil ;
17
18
18
19
/**
19
20
* Helper to create a DBus struct class.
20
- * As Structs are regular classes (POJOs) in Java,
21
+ * As Structs are regular classes (POJOs) in Java,
21
22
* this helper also takes care about recursion (Struct in Struct/Map/List).
22
- *
23
+ *
23
24
* @author hypfvieh
24
25
* @since v3.0.1 - 2018-12-21
25
26
*/
@@ -34,13 +35,13 @@ public class StructTreeBuilder {
34
35
* <br><br>
35
36
* Structs which are inside of another struct will get the appendix 'Struct' for each iteration.
36
37
* This may lead to classes with names like FooStructStructStruct (FooStruct->(InnerStruct->InnerInnerStruct)).
37
- *
38
+ *
38
39
* @param _dbusSig dbus Type string
39
40
* @param _structName name the struct should have
40
41
* @param _clzBldr class builder with the class where the struct was first seen
41
42
* @param _generatedClasses a list, this will contain additional struct classes created, if any. Should never be null!
42
- *
43
- * @return Struct class name or Collection type name
43
+ *
44
+ * @return Struct class name or Collection type name
44
45
* @throws DBusException on DBus Error
45
46
*/
46
47
public String buildStructClasses (String _dbusSig , String _structName , ClassBuilderInfo _clzBldr , List <ClassBuilderInfo > _generatedClasses ) throws DBusException {
@@ -86,7 +87,7 @@ public String buildStructClasses(String _dbusSig, String _structName, ClassBuild
86
87
87
88
/**
88
89
* Create nested Struct class.
89
- *
90
+ *
90
91
* @param _list List of struct tree elements
91
92
* @param _info root class of this struct (maybe other struct)
92
93
* @param _classes a list, this will contain additional struct classes created, if any. Should never be null!
@@ -96,9 +97,14 @@ private void createNested(List<StructTree> _list, ClassBuilderInfo _info, List<C
96
97
97
98
ClassBuilderInfo info = _info ;
98
99
100
+ ClassConstructor classConstructor = new ClassConstructor ();
101
+
99
102
for (StructTree inTree : _list ) {
100
103
ClassBuilderInfo .ClassMember member = new ClassBuilderInfo .ClassMember ("member" + position , inTree .getDataType ().getName (), true );
101
104
member .getAnnotations ().add ("@Position(" + position + ")" );
105
+
106
+ classConstructor .getArguments ().put ("member" + position , inTree .getDataType ().getName ());
107
+
102
108
position ++;
103
109
104
110
if (Struct .class .isAssignableFrom (inTree .getDataType ())) {
@@ -120,14 +126,16 @@ private void createNested(List<StructTree> _list, ClassBuilderInfo _info, List<C
120
126
info .getImports ().add (Position .class .getName ()); // add position annotation as include
121
127
info .getImports ().add (inTree .getDataType ().getName ());
122
128
info .getMembers ().add (member );
123
-
124
129
}
130
+
131
+ info .getConstructors ().add (classConstructor );
132
+
125
133
}
126
134
127
135
128
136
/**
129
137
* Helper to print a StructTree to STDOUT (for debugging purposes).
130
- *
138
+ *
131
139
* @param _buildTree tree to print
132
140
* @param _indent indention level (usually 0)
133
141
*/
@@ -151,7 +159,7 @@ static void printTree(List<StructTree> _buildTree, int _indent) {
151
159
152
160
/**
153
161
* Builds a tree of types based on the given DBus type definition string.
154
- *
162
+ *
155
163
* @param _dbusTypeStr DBus type string
156
164
* @return List with tree structure, maybe empty - never null
157
165
* @throws DBusException on Error
@@ -162,7 +170,7 @@ private List<StructTree> buildTree(String _dbusTypeStr) throws DBusException {
162
170
if (StringUtil .isBlank (_dbusTypeStr )) {
163
171
return root ;
164
172
}
165
-
173
+
166
174
List <Type > dataType = new ArrayList <>();
167
175
Marshalling .getJavaType (_dbusTypeStr , dataType , 1 );
168
176
@@ -182,7 +190,7 @@ private List<StructTree> buildTree(String _dbusTypeStr) throws DBusException {
182
190
183
191
/**
184
192
* Create tree from {@link ParameterizedType}.
185
- *
193
+ *
186
194
* @param _pType {@link ParameterizedType} object
187
195
* @return List of tree elements, maybe empty, never null
188
196
* @throws DBusException on error
@@ -192,7 +200,7 @@ private List<StructTree> buildTree(ParameterizedType _pType) throws DBusExceptio
192
200
if (_pType == null ) {
193
201
return trees ;
194
202
}
195
-
203
+
196
204
for (Type type : _pType .getActualTypeArguments ()) {
197
205
if (type instanceof ParameterizedType ) {
198
206
StructTree tree = new StructTree (((ParameterizedType ) type ).getRawType ().getTypeName ());
@@ -208,7 +216,7 @@ private List<StructTree> buildTree(ParameterizedType _pType) throws DBusExceptio
208
216
209
217
/**
210
218
* Class to represent a tree structure.
211
- *
219
+ *
212
220
* @author hypfvieh
213
221
* @since v3.0.1 - 2018-12-22
214
222
*/
0 commit comments