Skip to content

Commit 93262a1

Browse files
committed
Add javadoc for domain objects
1 parent cc8f3b1 commit 93262a1

13 files changed

+117
-22
lines changed

doc/Development.md

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
# Development Guide
22

3+
## Architecture
4+
5+
`Source code` ==Parser=> `Type definition` + `unresolved types` ==Resolver=> `Type definition` + `resolved types` ==Writer=> `target schema/language`
6+
7+
Internal types also have javadoc for more information.
8+
#### Project structure
9+
* `annotation` contains the annotation type `@SharedType` as client code compile-time dependency.
10+
* `processor` contains annotation processor logic, put on client's annotation processing path.
11+
* `internal` contains domain types used in `processor` and integration test.
12+
* `it` contains integration tests, which do metadata verification by deserializing metadata objects.
13+
* `java8` contains major types for tests.
14+
* `java17` uses symlink to reuse types in `java8` then does more type checks, e.g. for Java `record`.
15+
* `client-test` contains target languages' tests respectively against generated code.
16+
317
## Setup
418
**Linux is assumed**. If you use Windows, you can use WSL with a remotely connected IDE. Windows 11 supports GUI app inside WSL.
519

@@ -11,45 +25,40 @@ Optionally mount tmpfs to save your disk by:
1125
```bash
1226
./mount-tmpfs.sh
1327
```
14-
15-
## Style check
16-
```bash
17-
./mvnw editorconfig:check
18-
```
19-
20-
## Debug
21-
Debug annotation processor by run maven build:
22-
```bash
23-
./mvnd <your args goes here>
24-
```
25-
Then attach your debugger on it.
26-
27-
## Run test
28+
## Development
29+
### Run test
2830
If you encounter compilation problems with your IDE, delegate compilation to maven.
2931
Before run test in IDE/individual module, run `./mvnw clean install -DskipTests` to build dependency classes.
30-
3132
#### E.g. run integration test locally:
3233
```bash
3334
./mvnw clean install -DskipTests -q && ./mvnw test -pl it/java17 -pl it/java8
3435
```
35-
3636
#### Run local verification with all java tests
3737
```bash
3838
./mvnw verify
3939
```
40-
4140
#### Verify JDK8 compatibility locally
42-
Setup `JAVA8_HOME` to point to your Java8 installation.
41+
Setup `JAVA8_HOME` to point to your Java8 installation. Open a new terminal and run:
4342
```bash
4443
. setenv 8
4544
./mvnw verify -pl it/java8
4645
```
47-
4846
#### Run client tests locally
4947
Client tests are run in target languages in respective dir inside `./client-test`. They do basic type checking.
5048
* Typescript. `. setenv && npm i && npm run test`
49+
#### Misc
50+
Style check:
51+
```bash
52+
./mvnw editorconfig:check
53+
```
54+
Debug annotation processor by run maven build:
55+
```bash
56+
./mvnd <your args goes here>
57+
```
58+
Then attach your debugger on it.
5159

5260

5361
## Coding Style Guide
5462
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.
5563
2. no adding dependencies without strong justification.
64+
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.

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@
33
import lombok.EqualsAndHashCode;
44
import lombok.RequiredArgsConstructor;
55

6+
/**
7+
* Represents an array-like type.
8+
* During parsing, a predefined array-like type and its subtypes is captured as this class.
9+
* A type will be recognized as this type with higher priority than {@link ConcreteTypeInfo}.
10+
* <br>
11+
* Predefined array-like types can be configured in global properties. Default is {@link java.lang.Iterable}.
12+
*
13+
* @see ConcreteTypeInfo
14+
* @author Cause Chung
15+
*/
616
@RequiredArgsConstructor
717
@EqualsAndHashCode
818
public final class ArrayTypeInfo implements TypeInfo {

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
import java.util.stream.Collectors;
1010

1111
/**
12-
* Represents info captured from an interface, class, or record.
12+
* Represents structural info captured from an interface, class, or record.
13+
*
14+
* @author Cause Chung
1315
*/
1416
@Builder
1517
@EqualsAndHashCode(of = "qualifiedName")
@@ -77,13 +79,13 @@ public String toString() {
7779
}
7880

7981
private String typeVariablesToString() {
80-
return typeVariables.isEmpty() ? "" : "<" + String.join(",", typeVariables.stream().map(TypeVariableInfo::toString).collect(Collectors.toList())) + ">";
82+
return typeVariables.isEmpty() ? "" : "<" + typeVariables.stream().map(TypeVariableInfo::toString).collect(Collectors.joining(",")) + ">";
8183
}
8284

8385
private String supertypesToString() {
8486
if (supertypes.isEmpty()) {
8587
return "";
8688
}
87-
return " extends " + String.join(" & ", supertypes.stream().map(t -> t + (t.resolved() ? "" : "?")).collect(Collectors.toList()));
89+
return " extends " + supertypes.stream().map(t -> t + (t.resolved() ? "" : "?")).collect(Collectors.joining(" & "));
8890
}
8991
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
import java.io.Serializable;
44

5+
/**
6+
* Represents internal components in a {@link TypeDef}.
7+
*
8+
* @author Cause Chung
9+
*/
510
public interface ComponentInfo extends Serializable {
611
boolean resolved();
712
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77
import java.util.List;
88
import java.util.stream.Collectors;
99

10+
/**
11+
* Represents a primitive type or object type that requires its target representation,
12+
* and is not recognized as an array-like type.
13+
* Like {@link java.lang.String} in typescript as "string", int in typescript as "number".
14+
*
15+
* @see ArrayTypeInfo
16+
* @author Cause Chung
17+
*/
1018
@EqualsAndHashCode(of = "qualifiedName")
1119
@Builder
1220
public final class ConcreteTypeInfo implements TypeInfo {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
package org.sharedtype.domain;
22

3+
/**
4+
* Represents a constant literal.
5+
* Only literals with values resolvable at compile time are supported.
6+
*
7+
* @author Cause Chung
8+
*/
39
public final class ConstantInfo {
410

511
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
import java.util.HashMap;
77
import java.util.Map;
88

9+
/**
10+
* @author Cause Chung
11+
*/
912
public final class Constants {
1013
public static final String ANNOTATION_QUALIFIED_NAME = SharedType.class.getName();
1114

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
import java.util.List;
88
import java.util.stream.Collectors;
99

10+
/**
11+
* Represents an enum.
12+
*
13+
* @author Cause Chung
14+
*/
1015
@EqualsAndHashCode(of = "qualifiedName")
1116
@Builder
1217
public final class EnumDef implements TypeDef {

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,17 @@
22

33
import lombok.EqualsAndHashCode;
44
import lombok.RequiredArgsConstructor;
5+
import org.sharedtype.annotation.SharedType;
56

7+
/**
8+
* Represents an enum value, which is the value in the target code that corresponds to an enum constant.
9+
* <br>
10+
* By default, enum value is String value of the enum constant. It can be configured with {@link SharedType.EnumValue}.
11+
*
12+
* @see EnumDef
13+
* @see SharedType.EnumValue
14+
* @author Cause Chung
15+
*/
616
@EqualsAndHashCode
717
@RequiredArgsConstructor
818
public final class EnumValueInfo implements ComponentInfo {

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
import javax.lang.model.element.Modifier;
66
import java.util.Set;
77

8+
/**
9+
* Represents a field or accessor.
10+
*
11+
* @author Cause Chung
12+
*/
813
@Builder
914
public final class FieldComponentInfo implements ComponentInfo {
1015
private final String name;

0 commit comments

Comments
 (0)