Skip to content

Commit 16dcbc7

Browse files
authored
26 conflict name (#40)
* Write to qualified name in JavaSerializationFileWriter * Error on name conflict for typescript * Add javadoc for domain objects
1 parent f1fd264 commit 16dcbc7

File tree

28 files changed

+213
-41
lines changed

28 files changed

+213
-41
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,6 @@ ij_java_imports_layout = *,|,javax.**,java.**,|,$*
1515

1616
[*.yaml]
1717
indent_size = 2
18+
19+
[*.ts]
20+
ij_javascript_enforce_trailing_comma = whenmultiline

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
* [vojtechhabarta/typescript-generator](https://github.com/vojtechhabarta/typescript-generator)
1717

1818
## Documentation
19-
[User Guide](doc/Usage.md)
20-
[Development Guide](doc/Development.md)
19+
* [User Guide](doc/Usage.md)
20+
* [Development Guide](doc/Development.md)
2121

2222
## Authors
2323
Cause Chung ([email protected])

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77
import java.lang.annotation.Target;
88

99
/**
10+
* <p>Share a type. <a href="https://github.com/cuzfrog/SharedType">Website</a></p>
11+
* <br>
1012
* <b>Inner class:</b>
1113
* <p>
1214
* 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.
1316
* TODO: doc for nested types
1417
* </p>
1518
*
@@ -20,7 +23,17 @@
2023
@Documented
2124
public @interface SharedType {
2225
/**
23-
* The name of the emitted type. If not specified, the simple name of the annotated type will be used.
26+
* <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.
29+
* </p>
30+
* <br>
31+
* <p>
32+
* How possibly conflicting names are resolved:
33+
* <ul>
34+
* <li>Typescript: simple name of a class is used as type name. Duplicate names are not allowed.</li>
35+
* </ul>
36+
* </p>
2437
*/
2538
String name() default "";
2639

client-test/typescript/tests/enum-union.ts

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

33
export const list1: EnumGalaxy[] = ["Andromeda", "MilkyWay", "Triangulum"];
44
export const record1: Record<EnumTShirt, number> = {
@@ -51,3 +51,7 @@ export const obj: Omit<JavaRecord<string, number>, "aVoid" | "genericMap"> = {
5151
primitiveShort: 0,
5252
string: "",
5353
};
54+
55+
export const anotherJavaClass: AnotherJavaClass = {
56+
value: 333,
57+
}

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
}

0 commit comments

Comments
 (0)