Skip to content

Commit 9e248af

Browse files
authored
33 java8 (#35)
* Refactor syntax to java8 * Make ap source code Java8 compatible * Setup CI for Java8
1 parent 438df14 commit 9e248af

File tree

75 files changed

+792
-596
lines changed

Some content is hidden

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

75 files changed

+792
-596
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ ij_continuation_indent_size = 4
1212
ij_java_class_count_to_use_import_on_demand = 999
1313
ij_java_names_count_to_use_import_on_demand = 20
1414
ij_java_imports_layout = *,|,javax.**,java.**,|,$*
15+
16+
[*.yaml]
17+
indent_size = 2

.github/workflows/ci.yaml

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,50 @@ jobs:
3434
- uses: actions/cache@v4
3535
with:
3636
path: ~/.m2/repository
37-
key: build_and_test_maven
37+
key: build_maven
3838
- name: Build
39-
run: ./mvnw compile -e
40-
- name: Test
41-
run: ./mvnw test -e
42-
- uses: actions/upload-artifact@v4
39+
run: ./mvnw install -e
40+
- name: Upload generated sources
41+
uses: actions/upload-artifact@v4
4342
with:
4443
name: generated-sources
4544
path: |
46-
it/target/generated-sources/*
45+
it/java17/target/generated-sources
4746
if-no-files-found: error
47+
- name: Upload jars
48+
uses: actions/upload-artifact@v4
49+
with:
50+
name: jars
51+
path: |
52+
~/.m2/repository/org/sharedtype
53+
if-no-files-found: error
54+
- name: Remove jars from cache
55+
run: rm -rf ~/.m2/repository/org/sharedtype
56+
57+
jdk_compatibility_test:
58+
needs: [build_and_test]
59+
runs-on: ubuntu-latest
60+
strategy:
61+
matrix:
62+
java: [ 8, 11 ]
63+
steps:
64+
- uses: actions/checkout@v4
65+
- uses: actions/setup-java@v4
66+
with:
67+
distribution: 'temurin'
68+
java-version: ${{ matrix.java }}
69+
- uses: actions/download-artifact@v4
70+
with:
71+
name: jars
72+
path: ~/.m2/repository/org/sharedtype
73+
# - name: Display downloaded artifact
74+
# run: ls -lhR ~/.m2/repository/org/sharedtype
75+
- uses: actions/cache@v4
76+
with:
77+
path: ~/.m2/repository
78+
key: build_maven
79+
- name: Test
80+
run: ./mvnw verify -pl it/java8 -e
4881

4982
client_test:
5083
needs: [build_and_test]
@@ -57,17 +90,17 @@ jobs:
5790
- uses: actions/download-artifact@v4
5891
with:
5992
name: generated-sources
60-
path: it/target/generated-sources/
93+
path: it/java17/target/generated-sources
6194
- name: Display downloaded artifact
62-
run: ls -lhR it/target/generated-sources
95+
run: ls -lhR it/java17/target/generated-sources
6396
- name: Test Typescript
6497
working-directory: client-test/typescript
6598
run: |
6699
npm i
67100
npm run test
68101
69102
clean-artifact:
70-
needs: [ client_test ]
103+
needs: [ jdk_compatibility_test, client_test ]
71104
runs-on: ubuntu-latest
72105
if: always()
73106
steps:

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[![CI](https://github.com/cuzfrog/sharedtype/actions/workflows/ci.yaml/badge.svg)](https://github.com/cuzfrog/sharedtype/actions/workflows/ci.yaml)
22
# SharedType - Sharing Java Types made easy
33

4+
* Client Java version >= 8.
45
* Only client source dependency is `@SharedType`.
56
* SharedType annotation processor jar is <100KB, only 2 small dependencies: jsr305 annotations and mustache.
67
* Parsing takes milliseconds. See [Performance](doc/Performance.md).

annotation/src/main/java/module-info.java

Lines changed: 0 additions & 3 deletions
This file was deleted.

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
* unless the field or accessor is also ignored.
5959
* </p>
6060
*/
61-
@Target({ElementType.METHOD, ElementType.FIELD, ElementType.RECORD_COMPONENT, ElementType.TYPE})
61+
@Target({ElementType.METHOD, ElementType.FIELD, ElementType.TYPE})
6262
@Retention(RetentionPolicy.SOURCE)
6363
@interface Ignore {
6464
}
@@ -107,25 +107,25 @@
107107
* </pre>
108108
*/
109109
@Target({ElementType.FIELD, ElementType.PARAMETER})
110-
@Retention(RetentionPolicy.SOURCE)
110+
@Retention(RetentionPolicy.CLASS)
111111
@interface EnumValue {
112112
}
113113

114114
enum ComponentType {
115115
/**
116116
* Represents:
117117
* <ul>
118-
* <li>Class fields.</li>
119-
* <li>Record components</li>
118+
* <li>Class instance fields.</li>
119+
* <li>Record components.</li>
120120
* </ul>
121121
*/
122122
FIELDS,
123123
/**
124-
* Represents:
124+
* Represents 0 argument non-static methods:
125125
* <ul>
126-
* <li>In a class or enum, methods starting with a getter prefix and 0 arguments. By default, prefixes include 'get' or 'is'.</li>
127-
* <li>In a record, only components' accessors.</li>
128-
* <li>Methods annotated with {@link Accessor} in both class and records</li>
126+
* <li>with name same as its instance field. Or fluent getter. This includes record's component accessor.</li>
127+
* <li>starting with a getter prefix. By default, prefixes include 'get' or 'is', which can be configured via global properties.</li>
128+
* <li>annotated with {@link Accessor}.</li>
129129
* </ul>
130130
*/
131131
ACCESSORS,

client-test/typescript/src/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export type * from "../../../it/target/generated-sources/types.d.ts";
1+
export type * from "../../../it/java17/target/generated-sources/types.d.ts";
Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,53 @@
1-
import type { EnumGalaxy, EnumSize, EnumTShirt } from "../src/index.js";
1+
import type {DependencyClassA, DependencyClassB, DependencyClassC, EnumGalaxy, EnumSize, EnumTShirt, JavaRecord} from "../src/index.js";
22

33
export const list1: EnumGalaxy[] = ["Andromeda", "MilkyWay", "Triangulum"];
44
export const record1: Record<EnumTShirt, number> = {
5-
S: 1,
6-
M: 2,
7-
L: 3,
5+
S: 1,
6+
M: 2,
7+
L: 3,
88
}
99
export const size1: EnumSize = 1;
10+
11+
export const dependencyClassC: DependencyClassC = {} as DependencyClassC;
12+
13+
export const dependencyClassB: DependencyClassB = {
14+
c: dependencyClassC
15+
}
16+
17+
export const dependencyClassA: DependencyClassA = {
18+
a: 0,
19+
b: dependencyClassB
20+
};
21+
dependencyClassC.a = dependencyClassA
22+
23+
export const obj: Omit<JavaRecord<string, number>, "aVoid" | "genericMap"> = {
24+
boxedBoolean: false,
25+
boxedByte: 0,
26+
boxedChar: "",
27+
boxedDouble: 0,
28+
boxedFloat: 0,
29+
boxedInt: 0,
30+
boxedIntArray: [],
31+
boxedLong: 0,
32+
boxedShort: 0,
33+
containerStringList: [],
34+
containerStringListCollection: [],
35+
cyclicDependency: dependencyClassA,
36+
duplicateAccessor: "",
37+
enumGalaxy: "MilkyWay",
38+
enumSize: 3,
39+
genericList: [],
40+
genericListSet: [],
41+
genericSet: [],
42+
intArray: [],
43+
object: undefined,
44+
primitiveBoolean: false,
45+
primitiveByte: 0,
46+
primitiveChar: "",
47+
primitiveDouble: 0,
48+
primitiveFloat: 0,
49+
primitiveInt: 0,
50+
primitiveLong: 0,
51+
primitiveShort: 0,
52+
string: "",
53+
};

doc/Development.md

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

33
## Setup
4-
Setup Java env vars (>= Java17 for development):
4+
Linux is recommended. If you use Windows, you can use WSL with a remotely connected IDE. Windows 11 supports GUI app inside WSL.
5+
6+
Setup Java env vars (>= Java17 for development), configure `JAVA17_HOME` to point to your Java installation:
57
```bash
68
. setenv
79
```
@@ -10,8 +12,6 @@ Optionally mount tmpfs to save your disk by:
1012
./mount-tmpfs.sh
1113
```
1214

13-
If you encounter compilation problems with your IDE, delegate compilation to maven.
14-
1515
## Style check
1616
```bash
1717
./mvnw editorconfig:check
@@ -24,11 +24,32 @@ Debug annotation processor by run maven build:
2424
```
2525
Then attach your debugger on it.
2626

27-
## Run Integration test
27+
## Run test
28+
If you encounter compilation problems with your IDE, delegate compilation to maven.
29+
Before run test in IDE/individual module, run `./mvnw clean install -DskipTests` to build dependency classes.
30+
31+
#### E.g. run integration test locally:
2832
```bash
29-
./mvnw clean install -DskipTests -q && ./mvnw test -pl it
33+
./mvnw clean install -DskipTests -q && ./mvnw test -pl it/java17 -pl it/java8
3034
```
3135

36+
#### Run local verification with all java tests
37+
```bash
38+
./mvnw verify
39+
```
40+
41+
#### Verify JDK8 compatibility locally
42+
Setup `JAVA8_HOME` to point to your Java8 installation.
43+
```bash
44+
. setenv 8
45+
./mvnw verify -pl it/java8
46+
```
47+
48+
#### Run client tests locally
49+
Client tests are run in target languages in respective dir inside `./client-test`. They do basic type checking.
50+
* Typescript. `. setenv && npm i && npm run test`
51+
52+
3253
## Coding Style Guide
33-
1. since annotation processing is one shot execution, JIT is not likely to optimize the code. So please try to avoid long calling stacks like Stream chains.
34-
2. no dependencies without strong justification.
54+
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.
55+
2. no adding dependencies without strong justification.

doc/Usage.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,8 @@ See [Default Properties](../processor/src/main/resources/sharedtype-default.prop
8181

8282
#### Per annotation options
8383
See Javadoc on [@SharedType](../annotation/src/main/java/org/sharedtype/annotation/SharedType.java) for details.
84+
85+
### Limitations
86+
* Current design only retain `@SharedType` on source level. That means they are not visible if it is in a dependency jar during its dependent's compilation.
87+
You have to execute the annotation processing on the same classpath with source code.
88+
For multiple module builds, a workaround is to execute on every module.

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
package org.sharedtype.domain;
22

3-
public record ArrayTypeInfo(TypeInfo component) implements TypeInfo {
3+
import lombok.EqualsAndHashCode;
4+
import lombok.RequiredArgsConstructor;
5+
6+
@RequiredArgsConstructor
7+
@EqualsAndHashCode
8+
public final class ArrayTypeInfo implements TypeInfo {
9+
private final TypeInfo component;
10+
11+
public TypeInfo component() {
12+
return component;
13+
}
14+
415
@Override
516
public boolean resolved() {
617
return component.resolved();

0 commit comments

Comments
 (0)