Skip to content

Commit 3f9b509

Browse files
authored
93 type mapping (#96)
* Add property for arbitrary type mappings * Disable Ignore resolution error, be able to resolve ignored type so not to emit them * Update typescript dependencies
1 parent 89c41ff commit 3f9b509

39 files changed

Lines changed: 688 additions & 374 deletions

annotation/src/main/java/online/sharedtype/SharedType.java

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@
2525
*
2626
* <p>
2727
* <b>Configurations:</b><br>
28-
* Properties on class level (via this annotation) will take precedence over global properties.
29-
* Properties that only apply to global level will not be present on class level.
28+
* Global properties can be defined in a client provided property file or system properties.
29+
* By default, SharedType will look for file name "sharedtype.properties" on cmd current path.
30+
* The property file path can be changed via compiler option "sharedtype.propsFile", see web for details.
31+
* System properties will override property file values.
32+
* Configs on class level (via this annotation) will take precedence over global properties.
3033
* </p>
3134
*
3235
* <p>
@@ -97,6 +100,17 @@
97100
* By default, types that are recognized as date and time are emitted as strings, date/time types are configured via global properties.
98101
* The emitted target type can be configured via global properties or via this annotation.
99102
* Target type can be any type literal, but SharedType will not verify its validity in emitted code.
103+
* </p><br>
104+
*
105+
* <p>
106+
* <b>Type literal mappings:</b><br>
107+
* You dan define any 1-to-1 type mappings via global properties. This is useful when e.g. a 3rd party type is referenced.
108+
* Note, SharedType will still try to resolve the type and emit it with the mapped name.
109+
* If you don't want SharedType to auto-resolve and emit it, mark it as ignored via {@link SharedType.Ignore} or global properties.
110+
* <br>
111+
* Type mapped this way will take the highest precedence.
112+
* E.g. a date type is configured to be emitted as string, you can override the particular mapping to emit a {@code Date}.
113+
* Type mapping will override name configured in {@link SharedType#name()}.
100114
* </p>
101115
*
102116
* <br>
@@ -115,11 +129,9 @@
115129
* This may be used to help avoid conflicting names in target code.
116130
* </p>
117131
* <br>
118-
* <p>
119-
* How conflicting names are resolved:
120-
* <ul>
121-
* <li>Typescript: simple name of a class is used as type name. Duplicate names are not allowed.</li>
122-
* </ul>
132+
* This is similar to but different from type mappings configured via global properties,
133+
* which maps any Java type to a target type. When both are defined, this will be overridden by type mappings.
134+
* See {@link SharedType} for details.
123135
*/
124136
String name() default "";
125137

@@ -163,33 +175,38 @@
163175

164176
/**
165177
* Type literal to be emitted for date/time types. How a java type is considered a date/time type is defined by global properties.
178+
*
166179
* @return any literal, e.g. "String", "chrono::DateTime". When empty, fallback to global default.
167180
*/
168181
String rustTargetDatetimeTypeLiteral() default "";
169182

170183
/**
171184
* How to render optional fields in Typescript.
185+
*
172186
* @return combination of "?", "null", "undefined", the latter 2 are rendered as union types. If empty, fallback to global default.
173187
*/
174188
String[] typescriptOptionalFieldFormat() default {};
175189

176190
/**
177191
* Format of enum in Typescript.
192+
*
178193
* @return one of "const_enum" (const enum), "enum" (enum), or "union" (union types). If empty, fallback to global default.
179194
*/
180195
String typescriptEnumFormat() default "";
181196

182197
/**
183198
* Whether to mark generated type fields as readonly. Default fallback to global properties.
199+
*
184200
* @return value can be one of:
185-
* "all" - all fields are readonly
186-
* "acyclic" - only fields of not cyclic-referenced types are readonly
187-
* "none" - no fields are readonly
201+
* "all" - all fields are readonly
202+
* "acyclic" - only fields of not cyclic-referenced types are readonly
203+
* "none" - no fields are readonly
188204
*/
189205
String typescriptFieldReadonlyType() default "";
190206

191207
/**
192208
* Type literal to be emitted for date/time types. How a java type is considered a date/time type is defined by global properties.
209+
*
193210
* @return any literal, e.g. "string", "Date". When empty, fallback to global default.
194211
*/
195212
String typescriptTargetDatetimeTypeLiteral() default "";
@@ -207,9 +224,11 @@
207224
/**
208225
* Exclude fields, record components, accessors in a type, or a dependency type, e.g. a supertype.
209226
* <p>
210-
* <b>When placed on a type:</b> a subtype of this type will not extend this type in target code.
211-
* But if this type is referenced directly as type of field or return type of accessor, a compilation error will be reported,
212-
* unless the field or accessor is also ignored.
227+
* <b>When placed on a type:</b><br>
228+
* This type will not be emitted.
229+
* If this type has a subtype that is going to be emitted, the subtype will not extend this type and its members in target code.
230+
* But if this type is referenced directly as type of field or return type of accessor, and "safe-type-resolution" is enabled,
231+
* a compilation error will be reported, unless the field or accessor is also ignored.
213232
* </p>
214233
*/
215234
@Target({ElementType.METHOD, ElementType.FIELD, ElementType.TYPE})
@@ -295,7 +314,9 @@ enum ComponentType {
295314
enum OptionalBool {
296315
TRUE,
297316
FALSE,
298-
/** Fallback to global default. */
317+
/**
318+
* Fallback to global default.
319+
*/
299320
DEFAULT,
300321
}
301322
}

0 commit comments

Comments
 (0)