Skip to content

Commit f5e6bff

Browse files
authored
27 javadoc and fixes (#45)
* Adding javadoc for interal classes * Fix #43 #44 * Refine doc on SharedType
1 parent 16dcbc7 commit f5e6bff

File tree

77 files changed

+923
-358
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+923
-358
lines changed

.github/workflows/ci.yaml

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,18 @@ jobs:
4242
with:
4343
name: generated-sources
4444
path: |
45-
it/java17/target/generated-sources
45+
./it/java8/target/generated-sources
46+
./it/java17/target/generated-sources
4647
if-no-files-found: error
48+
retention-days: 3
4749
- name: Upload jars
4850
uses: actions/upload-artifact@v4
4951
with:
5052
name: jars
5153
path: |
5254
~/.m2/repository/org/sharedtype
5355
if-no-files-found: error
56+
retention-days: 3
5457
- name: Remove jars from cache
5558
run: rm -rf ~/.m2/repository/org/sharedtype
5659

@@ -90,20 +93,20 @@ jobs:
9093
- uses: actions/download-artifact@v4
9194
with:
9295
name: generated-sources
93-
path: it/java17/target/generated-sources
94-
- name: Display downloaded artifact
95-
run: ls -lhR it/java17/target/generated-sources
96+
path: ./it/
97+
# - name: Display downloaded artifact
98+
# run: ls -lhR ./it/
9699
- name: Test Typescript
97100
working-directory: client-test/typescript
98101
run: |
99102
npm i
100103
npm run test
101104
102-
clean-artifact:
103-
needs: [ jdk_compatibility_test, client_test ]
104-
runs-on: ubuntu-latest
105-
if: always()
106-
steps:
107-
- uses: geekyeggo/delete-artifact@v5
108-
with:
109-
name: dist
105+
# clean-artifact:
106+
# needs: [ jdk_compatibility_test, client_test ]
107+
# runs-on: ubuntu-latest
108+
# if: always()
109+
# steps:
110+
# - uses: geekyeggo/delete-artifact@v5
111+
# with:
112+
# name: dist

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

Lines changed: 61 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,64 @@
77
import java.lang.annotation.Target;
88

99
/**
10-
* <p>Share a type. <a href="https://github.com/cuzfrog/SharedType">Website</a></p>
10+
* <p>Mark a class, record, enum, or interface for target code generation.</p>
11+
*
12+
* <p>
13+
* <b>Annotation Processing:</b><br>
14+
* This annotation is retained only in source code.
15+
* That means it is not visible if source code is not directly participating in annotation processing.
16+
* E.g. if it is in a dependency jar in a project with multi-module build.
17+
* <br>
1118
* <br>
12-
* <b>Inner class:</b>
19+
* When used together with <b>Lombok</b>, the processing order matters.
20+
* If processed before Lombok, SharedType will see only the original source code.
21+
* E.g. if getters are handled by Lombok @Getter, SharedType will not see the getter method.
22+
* It's recommended to execute SharedType before Lombok, since Lombok does not provide extra info to SharedType.
23+
* Also you may only want a fast execution of SharedType with "-proc:only" without other annotation processors.
24+
* </p>
25+
*
1326
* <p>
27+
* <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.
30+
* </p>
31+
*
32+
* <p>
33+
* <b>Inner class:</b><br>
1434
* Declared inner and nested types will not be included by default, unless they are referenced by other types.
15-
* Non-static inner classes are not supported, see documentation for details.
16-
* TODO: doc for nested types
35+
* Non-static inner classes are not supported.
36+
* </p>
37+
*
38+
* <p>
39+
* <b>Generics:</b><br>
40+
* Generics are supported. But it's also limited to target schema's capacity.
1741
* </p>
1842
*
43+
* <p>
44+
* <b>Collections:</b><br>
45+
* Iterables and arrays are treated as arrays. Map is mapped to:
46+
* <ul>
47+
* <li>Typescript: {@code [key: string]: T} where {@code T} can be a reified type.</li>
48+
* </ul>
49+
* </p>
50+
*
51+
* <p><a href="https://github.com/cuzfrog/SharedType">SharedType Website</a></p></p>
52+
*
1953
* @author Cause Chung
54+
* @implNote generics type bounds are not supported yet, Map is not supported yet.
2055
*/
2156
@Retention(RetentionPolicy.SOURCE)
2257
@Target({java.lang.annotation.ElementType.TYPE})
2358
@Documented
2459
public @interface SharedType {
2560
/**
2661
* <p>
27-
* The name of the emitted type. If not specified, the simple name of the annotated type will be used.
28-
* This may be used to help avoid conflicting names in target output.
62+
* The name of the emitted type. If not specified, the simple name of the annotated type will be used.
63+
* This may be used to help avoid conflicting names in target code.
2964
* </p>
3065
* <br>
3166
* <p>
32-
* How possibly conflicting names are resolved:
67+
* How conflicting names are resolved:
3368
* <ul>
3469
* <li>Typescript: simple name of a class is used as type name. Duplicate names are not allowed.</li>
3570
* </ul>
@@ -38,36 +73,36 @@
3873
String name() default "";
3974

4075
/**
41-
* Includes fields, record components, accessors, or constants in a type.
4276
* <p>
43-
* To exclude a particular component, use {@link Ignore}.
77+
* Configure whether to include fields, record components, accessors, or constants in a type.
78+
* All included by default.
4479
* </p>
45-
* <br>
4680
* <p>
47-
* Fields and accessors duplicates resolution:
48-
* <ul>
49-
* <li>In classes, fields and accessors effectively with the same name will be merged.</li>
50-
* <li>In records, when accessors are included, records components are ignored.</li>
51-
* </ul>
81+
* To exclude a particular component, use {@link Ignore}.
82+
* Fields and accessors effectively with the same name will be merged.
5283
* </p>
5384
*
54-
* @see ComponentType
85+
* @see ComponentType#FIELDS
86+
* @see ComponentType#ACCESSORS
87+
* @see ComponentType#CONSTANTS
5588
*/
56-
ComponentType[] includes() default {ComponentType.FIELDS, ComponentType.ACCESSORS};
89+
ComponentType[] includes() default {ComponentType.FIELDS, ComponentType.ACCESSORS, ComponentType.CONSTANTS};
5790

5891
/**
59-
* Mark a method as an accessor regardless of its name. This annotation will be ignored if {@link #includes()} does not include {@link ComponentType#ACCESSORS}.
92+
* Mark a method as an accessor regardless of its name.
93+
* Getter prefixes are configured in global properties.
94+
* This annotation will be ignored if {@link #includes()} does not include {@link ComponentType#ACCESSORS}.
6095
*/
6196
@Target({ElementType.METHOD})
6297
@Retention(RetentionPolicy.SOURCE)
6398
@interface Accessor {
6499
}
65100

66101
/**
67-
* Exclude fields, record components, accessors in a type. Or ignore a dependent type, e.g. a supertype.
102+
* Exclude fields, record components, accessors in a type, or a dependency type, e.g. a supertype.
68103
* <p>
69-
* <b>When placed on type:</b> a subtype of this type will not include inherited members from this type.
70-
* But if this type is referenced directly as type of a field or return type of an accessor, an error will be reported,
104+
* <b>When placed on a type:</b> a subtype of this type will not extend this type in target code.
105+
* But if this type is referenced directly as type of a field or return type of an accessor, a compilation error will be reported,
71106
* unless the field or accessor is also ignored.
72107
* </p>
73108
*/
@@ -78,15 +113,13 @@
78113

79114
/**
80115
* Mark enum value. By default, enum value is the enum constant name. The enum value must be literals (e.g. 1, "a", true) in enum constant expressions.
81-
* <br>
82116
* <p>
83117
* When placed on:
84118
* <ul>
85119
* <li>Constructor parameter - the literal value served to this parameter from enum constant expressions will be used.</li>
86120
* <li>Field - the constructor parameter with the same name and type will be used as if constructor parameter is annotated.</li>
87121
* </ul>
88122
* </p>
89-
* <br>
90123
* <p>
91124
* Below are some valid examples:
92125
* </p>
@@ -134,10 +167,10 @@ enum ComponentType {
134167
*/
135168
FIELDS,
136169
/**
137-
* Represents 0 argument non-static methods:
170+
* Represents 0 argument non-static methods that:
138171
* <ul>
139-
* <li>with name same as its instance field. Or fluent getter. This includes record's component accessor.</li>
140-
* <li>starting with a getter prefix. By default, prefixes include 'get' or 'is', which can be configured via global properties.</li>
172+
* <li>have names same as respective instance fields, aka, fluent getter. This includes record's component accessor.</li>
173+
* <li>start with a getter prefix. By default, prefixes include 'get' or 'is', which can be configured via global properties.</li>
141174
* <li>annotated with {@link Accessor}.</li>
142175
* </ul>
143176
*/
@@ -148,6 +181,8 @@ enum ComponentType {
148181
* <li>Class/record static fields with static values.</li>
149182
* </ul>
150183
* Fields with values that cannot be resolved at compile time will not be included. A corresponding warning will be given.
184+
*
185+
* @implNote not implement yet.
151186
*/
152187
CONSTANTS,
153188
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export type * from "../../../it/java8/target/generated-sources/types.d.ts";

client-test/typescript/tests/enum-union.ts renamed to client-test/typescript/tests/types.java17.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type {DependencyClassA, DependencyClassB, DependencyClassC, EnumGalaxy, EnumSize, EnumTShirt, JavaRecord, AnotherJavaClass} from "../src/index.js";
1+
import type {DependencyClassA, DependencyClassB, DependencyClassC, EnumGalaxy, EnumSize, EnumTShirt, JavaRecord, AnotherJavaClass} from "../src/index.java17.js";
22

33
export const list1: EnumGalaxy[] = ["Andromeda", "MilkyWay", "Triangulum"];
44
export const record1: Record<EnumTShirt, number> = {
@@ -16,7 +16,9 @@ export const dependencyClassB: DependencyClassB = {
1616

1717
export const dependencyClassA: DependencyClassA = {
1818
a: 0,
19-
b: dependencyClassB
19+
b: dependencyClassB,
20+
notIgnoredImplementedMethod: 0,
21+
value: 0,
2022
};
2123
dependencyClassC.a = dependencyClassA
2224

@@ -50,6 +52,7 @@ export const obj: Omit<JavaRecord<string, number>, "aVoid" | "genericMap"> = {
5052
primitiveLong: 0,
5153
primitiveShort: 0,
5254
string: "",
55+
value: "",
5356
};
5457

5558
export const anotherJavaClass: AnotherJavaClass = {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type { JavaClass } from "../src/index.java8.d.ts";
2+
3+
export const javaClass: JavaClass = {
4+
string: "",
5+
size: 1,
6+
notIgnoredImplementedMethod: 0,
7+
a: 0,
8+
value: 0
9+
};

doc/Development.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,4 @@ Then attach your debugger on it.
6262
1. since annotation processing is one shot execution, JIT is not likely to optimize the code. So prefer plain loop than long calling stacks like Stream chains.
6363
2. no adding dependencies without strong justification.
6464
3. Lombok is used in this project, but do not abuse. Only use it to replace unavoidable boilerplate code, and not to increase the bytecode size.
65+
Do not use compile time heavy annotation like `lombok.val`.

internal/src/main/java/org/sharedtype/domain/ConcreteTypeInfo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* @see ArrayTypeInfo
1616
* @author Cause Chung
1717
*/
18-
@EqualsAndHashCode(of = "qualifiedName")
18+
@EqualsAndHashCode(of = {"qualifiedName", "typeArgs"})
1919
@Builder
2020
public final class ConcreteTypeInfo implements TypeInfo {
2121
private final String qualifiedName;

internal/src/main/java/org/sharedtype/domain/TypeInfo.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@
55
/**
66
* Type information.
77
*
8-
* @see TypeDef
98
* @author Cause Chung
9+
* @see TypeDef
1010
*/
1111
public interface TypeInfo extends Serializable {
1212
/**
1313
* <p>Check if this type and its dependency types are resolved.</p>
1414
* <p>
15-
* When parsing a type's structure, a dependency type is firstly captured as a {@link TypeInfo}.
16-
* At this stage, because we don't know its output structure or if it needs output at all, we mark it as unresolved.
17-
* Also due to possible cyclic dependencies, the resolution stage needs to be performed after initial parsing state.
18-
* During resolution, once a type is parsed, it's marked as resolved.
19-
* Note that a type is marked as resolved when created, if it can be determined at that time.
15+
* When parsing a type's structure, a dependency type is firstly captured as a {@link TypeInfo}.
16+
* At this stage, because we don't know its output structure or if it needs output at all, we mark it as unresolved.
17+
* Also due to possible cyclic dependencies, the resolution stage needs to be performed after initial parsing state.
18+
* During resolution, once a type is parsed, it's marked as resolved.
19+
* Note that a type is marked as resolved when created, if it can be determined at that time.
2020
* </p>
2121
* <p>Object contains resolved flag as a mutable state</p>
2222
*

internal/src/main/java/org/sharedtype/domain/TypeVariableInfo.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,25 @@
22

33
import lombok.Builder;
44
import lombok.EqualsAndHashCode;
5-
import lombok.Getter;
65

76
/**
87
* Represents a generic type variable.
8+
* <br>
9+
* A type variable refers to a generic type parameter, it has a notation like "T" or bound information like "T extends Number".
10+
* A type argument is the actual type of the type variable. E.g. {@code "Integer" in "List<Integer>"}.
911
*
12+
* @see ConcreteTypeInfo#typeArgs()
1013
* @author Cause Chung
1114
*/
12-
@Getter
1315
@EqualsAndHashCode
1416
@Builder
1517
public final class TypeVariableInfo implements TypeInfo {
1618
private final String name;
19+
// TODO: support generic bounds
20+
21+
public String name() {
22+
return name;
23+
}
1724

1825
@Override
1926
public boolean resolved() {

0 commit comments

Comments
 (0)