Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

33 java8 #35

Merged
merged 7 commits into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ ij_continuation_indent_size = 4
ij_java_class_count_to_use_import_on_demand = 999
ij_java_names_count_to_use_import_on_demand = 20
ij_java_imports_layout = *,|,javax.**,java.**,|,$*

[*.yaml]
indent_size = 2
51 changes: 42 additions & 9 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,50 @@ jobs:
- uses: actions/cache@v4
with:
path: ~/.m2/repository
key: build_and_test_maven
key: build_maven
- name: Build
run: ./mvnw compile -e
- name: Test
run: ./mvnw test -e
- uses: actions/upload-artifact@v4
run: ./mvnw install -e
- name: Upload generated sources
uses: actions/upload-artifact@v4
with:
name: generated-sources
path: |
it/target/generated-sources/*
it/java17/target/generated-sources
if-no-files-found: error
- name: Upload jars
uses: actions/upload-artifact@v4
with:
name: jars
path: |
~/.m2/repository/org/sharedtype
if-no-files-found: error
- name: Remove jars from cache
run: rm -rf ~/.m2/repository/org/sharedtype

jdk_compatibility_test:
needs: [build_and_test]
runs-on: ubuntu-latest
strategy:
matrix:
java: [ 8, 11 ]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: ${{ matrix.java }}
- uses: actions/download-artifact@v4
with:
name: jars
path: ~/.m2/repository/org/sharedtype
# - name: Display downloaded artifact
# run: ls -lhR ~/.m2/repository/org/sharedtype
- uses: actions/cache@v4
with:
path: ~/.m2/repository
key: build_maven
- name: Test
run: ./mvnw verify -pl it/java8 -e

client_test:
needs: [build_and_test]
Expand All @@ -57,17 +90,17 @@ jobs:
- uses: actions/download-artifact@v4
with:
name: generated-sources
path: it/target/generated-sources/
path: it/java17/target/generated-sources
- name: Display downloaded artifact
run: ls -lhR it/target/generated-sources
run: ls -lhR it/java17/target/generated-sources
- name: Test Typescript
working-directory: client-test/typescript
run: |
npm i
npm run test

clean-artifact:
needs: [ client_test ]
needs: [ jdk_compatibility_test, client_test ]
runs-on: ubuntu-latest
if: always()
steps:
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[![CI](https://github.com/cuzfrog/sharedtype/actions/workflows/ci.yaml/badge.svg)](https://github.com/cuzfrog/sharedtype/actions/workflows/ci.yaml)
# SharedType - Sharing Java Types made easy

* Client Java version >= 8.
* Only client source dependency is `@SharedType`.
* SharedType annotation processor jar is <100KB, only 2 small dependencies: jsr305 annotations and mustache.
* Parsing takes milliseconds. See [Performance](doc/Performance.md).
Expand Down
3 changes: 0 additions & 3 deletions annotation/src/main/java/module-info.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
* unless the field or accessor is also ignored.
* </p>
*/
@Target({ElementType.METHOD, ElementType.FIELD, ElementType.RECORD_COMPONENT, ElementType.TYPE})
@Target({ElementType.METHOD, ElementType.FIELD, ElementType.TYPE})
@Retention(RetentionPolicy.SOURCE)
@interface Ignore {
}
Expand Down Expand Up @@ -107,25 +107,25 @@
* </pre>
*/
@Target({ElementType.FIELD, ElementType.PARAMETER})
@Retention(RetentionPolicy.SOURCE)
@Retention(RetentionPolicy.CLASS)
@interface EnumValue {
}

enum ComponentType {
/**
* Represents:
* <ul>
* <li>Class fields.</li>
* <li>Record components</li>
* <li>Class instance fields.</li>
* <li>Record components.</li>
* </ul>
*/
FIELDS,
/**
* Represents:
* Represents 0 argument non-static methods:
* <ul>
* <li>In a class or enum, methods starting with a getter prefix and 0 arguments. By default, prefixes include 'get' or 'is'.</li>
* <li>In a record, only components' accessors.</li>
* <li>Methods annotated with {@link Accessor} in both class and records</li>
* <li>with name same as its instance field. Or fluent getter. This includes record's component accessor.</li>
* <li>starting with a getter prefix. By default, prefixes include 'get' or 'is', which can be configured via global properties.</li>
* <li>annotated with {@link Accessor}.</li>
* </ul>
*/
ACCESSORS,
Expand Down
2 changes: 1 addition & 1 deletion client-test/typescript/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export type * from "../../../it/target/generated-sources/types.d.ts";
export type * from "../../../it/java17/target/generated-sources/types.d.ts";
52 changes: 48 additions & 4 deletions client-test/typescript/tests/enum-union.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,53 @@
import type { EnumGalaxy, EnumSize, EnumTShirt } from "../src/index.js";
import type {DependencyClassA, DependencyClassB, DependencyClassC, EnumGalaxy, EnumSize, EnumTShirt, JavaRecord} from "../src/index.js";

export const list1: EnumGalaxy[] = ["Andromeda", "MilkyWay", "Triangulum"];
export const record1: Record<EnumTShirt, number> = {
S: 1,
M: 2,
L: 3,
S: 1,
M: 2,
L: 3,
}
export const size1: EnumSize = 1;

export const dependencyClassC: DependencyClassC = {} as DependencyClassC;

export const dependencyClassB: DependencyClassB = {
c: dependencyClassC
}

export const dependencyClassA: DependencyClassA = {
a: 0,
b: dependencyClassB
};
dependencyClassC.a = dependencyClassA

export const obj: Omit<JavaRecord<string, number>, "aVoid" | "genericMap"> = {
boxedBoolean: false,
boxedByte: 0,
boxedChar: "",
boxedDouble: 0,
boxedFloat: 0,
boxedInt: 0,
boxedIntArray: [],
boxedLong: 0,
boxedShort: 0,
containerStringList: [],
containerStringListCollection: [],
cyclicDependency: dependencyClassA,
duplicateAccessor: "",
enumGalaxy: "MilkyWay",
enumSize: 3,
genericList: [],
genericListSet: [],
genericSet: [],
intArray: [],
object: undefined,
primitiveBoolean: false,
primitiveByte: 0,
primitiveChar: "",
primitiveDouble: 0,
primitiveFloat: 0,
primitiveInt: 0,
primitiveLong: 0,
primitiveShort: 0,
string: "",
};
35 changes: 28 additions & 7 deletions doc/Development.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Development Guide

## Setup
Setup Java env vars (>= Java17 for development):
Linux is recommended. If you use Windows, you can use WSL with a remotely connected IDE. Windows 11 supports GUI app inside WSL.

Setup Java env vars (>= Java17 for development), configure `JAVA17_HOME` to point to your Java installation:
```bash
. setenv
```
Expand All @@ -10,8 +12,6 @@ Optionally mount tmpfs to save your disk by:
./mount-tmpfs.sh
```

If you encounter compilation problems with your IDE, delegate compilation to maven.

## Style check
```bash
./mvnw editorconfig:check
Expand All @@ -24,11 +24,32 @@ Debug annotation processor by run maven build:
```
Then attach your debugger on it.

## Run Integration test
## Run test
If you encounter compilation problems with your IDE, delegate compilation to maven.
Before run test in IDE/individual module, run `./mvnw clean install -DskipTests` to build dependency classes.

#### E.g. run integration test locally:
```bash
./mvnw clean install -DskipTests -q && ./mvnw test -pl it
./mvnw clean install -DskipTests -q && ./mvnw test -pl it/java17 -pl it/java8
```

#### Run local verification with all java tests
```bash
./mvnw verify
```

#### Verify JDK8 compatibility locally
Setup `JAVA8_HOME` to point to your Java8 installation.
```bash
. setenv 8
./mvnw verify -pl it/java8
```

#### Run client tests locally
Client tests are run in target languages in respective dir inside `./client-test`. They do basic type checking.
* Typescript. `. setenv && npm i && npm run test`


## Coding Style Guide
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.
2. no dependencies without strong justification.
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.
2. no adding dependencies without strong justification.
5 changes: 5 additions & 0 deletions doc/Usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,8 @@ See [Default Properties](../processor/src/main/resources/sharedtype-default.prop

#### Per annotation options
See Javadoc on [@SharedType](../annotation/src/main/java/org/sharedtype/annotation/SharedType.java) for details.

### Limitations
* 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.
You have to execute the annotation processing on the same classpath with source code.
For multiple module builds, a workaround is to execute on every module.
13 changes: 12 additions & 1 deletion internal/src/main/java/org/sharedtype/domain/ArrayTypeInfo.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
package org.sharedtype.domain;

public record ArrayTypeInfo(TypeInfo component) implements TypeInfo {
import lombok.EqualsAndHashCode;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
@EqualsAndHashCode
public final class ArrayTypeInfo implements TypeInfo {
private final TypeInfo component;

public TypeInfo component() {
return component;
}

@Override
public boolean resolved() {
return component.resolved();
Expand Down
9 changes: 5 additions & 4 deletions internal/src/main/java/org/sharedtype/domain/ClassDef.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
* Represents info captured from an interface, class, or record.
Expand Down Expand Up @@ -68,21 +69,21 @@ public boolean resolved() {

@Override
public String toString() {
var rows = new ArrayList<String>(components.size()+2);
List<String> rows = new ArrayList<>(components.size()+2);
rows.add(String.format("%s%s%s {", simpleName, typeVariablesToString(), supertypesToString()));
rows.addAll(components.stream().map(f -> String.format(" %s", f)).toList());
rows.addAll(components.stream().map(f -> String.format(" %s", f)).collect(Collectors.toList()));
rows.add("}");
return String.join(System.lineSeparator(), rows);
}

private String typeVariablesToString() {
return typeVariables.isEmpty() ? "" : "<" + String.join(",", typeVariables.stream().map(TypeVariableInfo::toString).toList()) + ">";
return typeVariables.isEmpty() ? "" : "<" + String.join(",", typeVariables.stream().map(TypeVariableInfo::toString).collect(Collectors.toList())) + ">";
}

private String supertypesToString() {
if (supertypes.isEmpty()) {
return "";
}
return " extends " + String.join(" & ", supertypes.stream().map(t -> t + (t.resolved() ? "" : "?")).toList());
return " extends " + String.join(" & ", supertypes.stream().map(t -> t + (t.resolved() ? "" : "?")).collect(Collectors.toList()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

import java.io.Serializable;

public sealed interface ComponentInfo extends Serializable permits EnumValueInfo, FieldComponentInfo {
public interface ComponentInfo extends Serializable {
boolean resolved();
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

@EqualsAndHashCode(of = "qualifiedName")
@Builder
Expand Down Expand Up @@ -49,7 +50,7 @@ public List<? extends TypeInfo> typeArgs() {
public String toString() {
return String.format("%s%s%s",
qualifiedName,
typeArgs.isEmpty() ? "" : "<" + String.join(",", typeArgs.stream().map(TypeInfo::toString).toList()) + ">",
typeArgs.isEmpty() ? "" : "<" + typeArgs.stream().map(TypeInfo::toString).collect(Collectors.joining(",")) + ">",
resolved ? "" : "?"
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package org.sharedtype.domain;

public record ConstantInfo() {
public final class ConstantInfo {

}
Loading