@alloy-js/java 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +7 -0
- package/api-extractor.json +4 -0
- package/babel.config.cjs +4 -0
- package/dist/src/arguments.d.ts +15 -0
- package/dist/src/arguments.d.ts.map +1 -0
- package/dist/src/arguments.js +27 -0
- package/dist/src/arguments.js.map +1 -0
- package/dist/src/builtins/index.d.ts +2 -0
- package/dist/src/builtins/index.d.ts.map +1 -0
- package/dist/src/builtins/index.js +1 -0
- package/dist/src/builtins/index.js.map +1 -0
- package/dist/src/builtins/util.d.ts +4 -0
- package/dist/src/builtins/util.d.ts.map +1 -0
- package/dist/src/builtins/util.js +10 -0
- package/dist/src/builtins/util.js.map +1 -0
- package/dist/src/components/Annotation.d.ts +11 -0
- package/dist/src/components/Annotation.d.ts.map +1 -0
- package/dist/src/components/Annotation.js +12 -0
- package/dist/src/components/Annotation.js.map +1 -0
- package/dist/src/components/Block.d.ts +6 -0
- package/dist/src/components/Block.d.ts.map +1 -0
- package/dist/src/components/Block.js +4 -0
- package/dist/src/components/Block.js.map +1 -0
- package/dist/src/components/Class.d.ts +10 -0
- package/dist/src/components/Class.d.ts.map +1 -0
- package/dist/src/components/Class.js +36 -0
- package/dist/src/components/Class.js.map +1 -0
- package/dist/src/components/Constructor.d.ts +13 -0
- package/dist/src/components/Constructor.d.ts.map +1 -0
- package/dist/src/components/Constructor.js +23 -0
- package/dist/src/components/Constructor.js.map +1 -0
- package/dist/src/components/Declaration.d.ts +12 -0
- package/dist/src/components/Declaration.d.ts.map +1 -0
- package/dist/src/components/Declaration.js +18 -0
- package/dist/src/components/Declaration.js.map +1 -0
- package/dist/src/components/Enum.d.ts +13 -0
- package/dist/src/components/Enum.d.ts.map +1 -0
- package/dist/src/components/Enum.js +38 -0
- package/dist/src/components/Enum.js.map +1 -0
- package/dist/src/components/Generics.d.ts +6 -0
- package/dist/src/components/Generics.d.ts.map +1 -0
- package/dist/src/components/Generics.js +8 -0
- package/dist/src/components/Generics.js.map +1 -0
- package/dist/src/components/ImportStatement.d.ts +11 -0
- package/dist/src/components/ImportStatement.d.ts.map +1 -0
- package/dist/src/components/ImportStatement.js +9 -0
- package/dist/src/components/ImportStatement.js.map +1 -0
- package/dist/src/components/Interface.d.ts +9 -0
- package/dist/src/components/Interface.d.ts.map +1 -0
- package/dist/src/components/Interface.js +35 -0
- package/dist/src/components/Interface.js.map +1 -0
- package/dist/src/components/MavenProject.d.ts +13 -0
- package/dist/src/components/MavenProject.d.ts.map +1 -0
- package/dist/src/components/MavenProject.js +159 -0
- package/dist/src/components/MavenProject.js.map +1 -0
- package/dist/src/components/Method.d.ts +11 -0
- package/dist/src/components/Method.d.ts.map +1 -0
- package/dist/src/components/Method.js +25 -0
- package/dist/src/components/Method.js.map +1 -0
- package/dist/src/components/Name.d.ts +2 -0
- package/dist/src/components/Name.d.ts.map +1 -0
- package/dist/src/components/Name.js +10 -0
- package/dist/src/components/Name.js.map +1 -0
- package/dist/src/components/ObjectDeclaration.d.ts +13 -0
- package/dist/src/components/ObjectDeclaration.d.ts.map +1 -0
- package/dist/src/components/ObjectDeclaration.js +17 -0
- package/dist/src/components/ObjectDeclaration.js.map +1 -0
- package/dist/src/components/PackageDirectory.d.ts +16 -0
- package/dist/src/components/PackageDirectory.d.ts.map +1 -0
- package/dist/src/components/PackageDirectory.js +58 -0
- package/dist/src/components/PackageDirectory.js.map +1 -0
- package/dist/src/components/Parameters.d.ts +11 -0
- package/dist/src/components/Parameters.d.ts.map +1 -0
- package/dist/src/components/Parameters.js +17 -0
- package/dist/src/components/Parameters.js.map +1 -0
- package/dist/src/components/ProjectDirectory.d.ts +23 -0
- package/dist/src/components/ProjectDirectory.d.ts.map +1 -0
- package/dist/src/components/ProjectDirectory.js +42 -0
- package/dist/src/components/ProjectDirectory.js.map +1 -0
- package/dist/src/components/Reference.d.ts +6 -0
- package/dist/src/components/Reference.d.ts.map +1 -0
- package/dist/src/components/Reference.js +6 -0
- package/dist/src/components/Reference.js.map +1 -0
- package/dist/src/components/SourceFile.d.ts +17 -0
- package/dist/src/components/SourceFile.d.ts.map +1 -0
- package/dist/src/components/SourceFile.js +70 -0
- package/dist/src/components/SourceFile.js.map +1 -0
- package/dist/src/components/Value.d.ts +5 -0
- package/dist/src/components/Value.d.ts.map +1 -0
- package/dist/src/components/Value.js +17 -0
- package/dist/src/components/Value.js.map +1 -0
- package/dist/src/components/Variable.d.ts +9 -0
- package/dist/src/components/Variable.d.ts.map +1 -0
- package/dist/src/components/Variable.js +9 -0
- package/dist/src/components/Variable.js.map +1 -0
- package/dist/src/components/index.d.ts +21 -0
- package/dist/src/components/index.d.ts.map +1 -0
- package/dist/src/components/index.js +21 -0
- package/dist/src/components/index.js.map +1 -0
- package/dist/src/components/stc/index.d.ts +86 -0
- package/dist/src/components/stc/index.d.ts.map +1 -0
- package/dist/src/components/stc/index.js +24 -0
- package/dist/src/components/stc/index.js.map +1 -0
- package/dist/src/create-library.d.ts +15 -0
- package/dist/src/create-library.d.ts.map +1 -0
- package/dist/src/create-library.js +34 -0
- package/dist/src/create-library.js.map +1 -0
- package/dist/src/generics.d.ts +28 -0
- package/dist/src/generics.d.ts.map +1 -0
- package/dist/src/generics.js +51 -0
- package/dist/src/generics.js.map +1 -0
- package/dist/src/index.d.ts +9 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +9 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/name-policy.d.ts +5 -0
- package/dist/src/name-policy.d.ts.map +1 -0
- package/dist/src/name-policy.js +21 -0
- package/dist/src/name-policy.js.map +1 -0
- package/dist/src/object-modifiers.d.ts +24 -0
- package/dist/src/object-modifiers.d.ts.map +1 -0
- package/dist/src/object-modifiers.js +31 -0
- package/dist/src/object-modifiers.js.map +1 -0
- package/dist/src/symbols/index.d.ts +6 -0
- package/dist/src/symbols/index.d.ts.map +1 -0
- package/dist/src/symbols/index.js +6 -0
- package/dist/src/symbols/index.js.map +1 -0
- package/dist/src/symbols/java-output-symbol.d.ts +14 -0
- package/dist/src/symbols/java-output-symbol.d.ts.map +1 -0
- package/dist/src/symbols/java-output-symbol.js +21 -0
- package/dist/src/symbols/java-output-symbol.js.map +1 -0
- package/dist/src/symbols/java-package-scope.d.ts +6 -0
- package/dist/src/symbols/java-package-scope.d.ts.map +1 -0
- package/dist/src/symbols/java-package-scope.js +8 -0
- package/dist/src/symbols/java-package-scope.js.map +1 -0
- package/dist/src/symbols/java-project-scope.d.ts +67 -0
- package/dist/src/symbols/java-project-scope.d.ts.map +1 -0
- package/dist/src/symbols/java-project-scope.js +29 -0
- package/dist/src/symbols/java-project-scope.js.map +1 -0
- package/dist/src/symbols/reference.d.ts +8 -0
- package/dist/src/symbols/reference.d.ts.map +1 -0
- package/dist/src/symbols/reference.js +21 -0
- package/dist/src/symbols/reference.js.map +1 -0
- package/dist/src/symbols/scopes.d.ts +4 -0
- package/dist/src/symbols/scopes.d.ts.map +1 -0
- package/dist/src/symbols/scopes.js +1 -0
- package/dist/src/symbols/scopes.js.map +1 -0
- package/dist/test/annotation.test.d.ts +2 -0
- package/dist/test/annotation.test.d.ts.map +1 -0
- package/dist/test/class.test.d.ts +2 -0
- package/dist/test/class.test.d.ts.map +1 -0
- package/dist/test/constructor.test.d.ts +2 -0
- package/dist/test/constructor.test.d.ts.map +1 -0
- package/dist/test/enum.test.d.ts +2 -0
- package/dist/test/enum.test.d.ts.map +1 -0
- package/dist/test/externals.test.d.ts +2 -0
- package/dist/test/externals.test.d.ts.map +1 -0
- package/dist/test/generics.d.ts +2 -0
- package/dist/test/generics.d.ts.map +1 -0
- package/dist/test/interface.test.d.ts +2 -0
- package/dist/test/interface.test.d.ts.map +1 -0
- package/dist/test/maven.d.ts +2 -0
- package/dist/test/maven.d.ts.map +1 -0
- package/dist/test/method.test.d.ts +2 -0
- package/dist/test/method.test.d.ts.map +1 -0
- package/dist/test/package.test.d.ts +2 -0
- package/dist/test/package.test.d.ts.map +1 -0
- package/dist/test/reference.test.d.ts +2 -0
- package/dist/test/reference.test.d.ts.map +1 -0
- package/dist/test/utils.d.ts +6 -0
- package/dist/test/utils.d.ts.map +1 -0
- package/dist/test/values.test.d.ts +2 -0
- package/dist/test/values.test.d.ts.map +1 -0
- package/dist/test/variables.test.d.ts +2 -0
- package/dist/test/variables.test.d.ts.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +49 -0
- package/src/arguments.ts +30 -0
- package/src/builtins/index.ts +1 -0
- package/src/builtins/util.ts +117 -0
- package/src/components/Annotation.tsx +23 -0
- package/src/components/Block.tsx +8 -0
- package/src/components/Class.tsx +33 -0
- package/src/components/Constructor.tsx +25 -0
- package/src/components/Declaration.tsx +24 -0
- package/src/components/Enum.tsx +40 -0
- package/src/components/Generics.tsx +12 -0
- package/src/components/ImportStatement.tsx +21 -0
- package/src/components/Interface.tsx +31 -0
- package/src/components/MavenProject.tsx +151 -0
- package/src/components/Method.tsx +31 -0
- package/src/components/Name.tsx +10 -0
- package/src/components/ObjectDeclaration.tsx +22 -0
- package/src/components/PackageDirectory.tsx +84 -0
- package/src/components/Parameters.tsx +21 -0
- package/src/components/ProjectDirectory.tsx +76 -0
- package/src/components/Reference.tsx +12 -0
- package/src/components/SourceFile.tsx +84 -0
- package/src/components/Value.tsx +22 -0
- package/src/components/Variable.tsx +16 -0
- package/src/components/index.ts +20 -0
- package/src/components/stc/index.ts +24 -0
- package/src/create-library.ts +67 -0
- package/src/generics.ts +59 -0
- package/src/index.ts +8 -0
- package/src/name-policy.ts +33 -0
- package/src/object-modifiers.ts +48 -0
- package/src/symbols/index.ts +5 -0
- package/src/symbols/java-output-symbol.ts +30 -0
- package/src/symbols/java-package-scope.ts +17 -0
- package/src/symbols/java-project-scope.ts +104 -0
- package/src/symbols/reference.ts +24 -0
- package/src/symbols/scopes.ts +4 -0
- package/temp/api.json +5805 -0
- package/test/annotation.test.tsx +56 -0
- package/test/class.test.tsx +133 -0
- package/test/constructor.test.tsx +96 -0
- package/test/enum.test.tsx +105 -0
- package/test/externals.test.tsx +46 -0
- package/test/generics.tsx +58 -0
- package/test/interface.test.tsx +84 -0
- package/test/maven.tsx +261 -0
- package/test/method.test.tsx +162 -0
- package/test/package.test.tsx +18 -0
- package/test/reference.test.tsx +88 -0
- package/test/utils.tsx +72 -0
- package/test/values.test.tsx +29 -0
- package/test/variables.test.tsx +101 -0
- package/test/vitest.d.ts +10 -0
- package/tsconfig.json +11 -0
- package/tsdoc-metadata.json +11 -0
- package/vitest.config.ts +18 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { code } from "@alloy-js/core";
|
|
2
|
+
import { d } from "@alloy-js/core/testing";
|
|
3
|
+
import { expect, it } from "vitest";
|
|
4
|
+
import * as jv from "../src/components/index.js";
|
|
5
|
+
import { toSourceText } from "./utils.js";
|
|
6
|
+
|
|
7
|
+
it("Annotates object", () => {
|
|
8
|
+
const res = toSourceText(code`
|
|
9
|
+
${<jv.Annotation type="Getter" />}
|
|
10
|
+
class TestClass {
|
|
11
|
+
}
|
|
12
|
+
`);
|
|
13
|
+
|
|
14
|
+
expect(res).toBe(d`
|
|
15
|
+
package me.test.code;
|
|
16
|
+
|
|
17
|
+
@Getter
|
|
18
|
+
class TestClass {
|
|
19
|
+
}
|
|
20
|
+
`);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("Takes single parameter", () => {
|
|
24
|
+
const res = toSourceText(code`
|
|
25
|
+
${<jv.Annotation type="Getter" value={{ value: <jv.Value value='Test' /> }} />}
|
|
26
|
+
class TestClass {
|
|
27
|
+
}
|
|
28
|
+
`);
|
|
29
|
+
|
|
30
|
+
expect(res).toBe(d`
|
|
31
|
+
package me.test.code;
|
|
32
|
+
|
|
33
|
+
@Getter("Test")
|
|
34
|
+
class TestClass {
|
|
35
|
+
}
|
|
36
|
+
`);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("Takes named parameters", () => {
|
|
40
|
+
const res = toSourceText(code`
|
|
41
|
+
${<jv.Annotation type="Getter" value={{
|
|
42
|
+
value1: <jv.Value value='Tester' />,
|
|
43
|
+
value2: <jv.Value value='Tested' />
|
|
44
|
+
}} />}
|
|
45
|
+
class TestClass {
|
|
46
|
+
}
|
|
47
|
+
`);
|
|
48
|
+
|
|
49
|
+
expect(res).toBe(d`
|
|
50
|
+
package me.test.code;
|
|
51
|
+
|
|
52
|
+
@Getter(value1 = "Tester", value2 = "Tested")
|
|
53
|
+
class TestClass {
|
|
54
|
+
}
|
|
55
|
+
`);
|
|
56
|
+
});
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { code, refkey } from "@alloy-js/core";
|
|
2
|
+
import { d } from "@alloy-js/core/testing";
|
|
3
|
+
import { expect, it } from "vitest";
|
|
4
|
+
import * as jv from "../src/components/index.js";
|
|
5
|
+
import { assertFileContents, testRender, toSourceText } from "./utils.js";
|
|
6
|
+
|
|
7
|
+
it("works", () => {
|
|
8
|
+
const res = toSourceText(
|
|
9
|
+
<jv.Class public abstract final name='TestClass'>
|
|
10
|
+
</jv.Class>,
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
expect(res).toBe(d`
|
|
14
|
+
package me.test.code;
|
|
15
|
+
|
|
16
|
+
public abstract final class TestClass {
|
|
17
|
+
|
|
18
|
+
}
|
|
19
|
+
`);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("extends class", () => {
|
|
23
|
+
const res = testRender(
|
|
24
|
+
<>
|
|
25
|
+
<jv.SourceFile path="TestSuperclass.java">
|
|
26
|
+
<jv.Class public name='TestSuperclass'>
|
|
27
|
+
</jv.Class>
|
|
28
|
+
</jv.SourceFile>
|
|
29
|
+
<jv.PackageDirectory package='import'>
|
|
30
|
+
<jv.SourceFile path="TestSubclass.java">
|
|
31
|
+
<jv.Class public name='TestSubclass' extends={refkey("TestSuperclass")}>
|
|
32
|
+
</jv.Class>
|
|
33
|
+
</jv.SourceFile>
|
|
34
|
+
</jv.PackageDirectory>
|
|
35
|
+
</>,
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
assertFileContents(res, {
|
|
39
|
+
"TestSubclass.java": d`
|
|
40
|
+
package me.test.code.import;
|
|
41
|
+
|
|
42
|
+
import me.test.code.TestSuperclass;
|
|
43
|
+
|
|
44
|
+
public class TestSubclass extends TestSuperclass {
|
|
45
|
+
|
|
46
|
+
}
|
|
47
|
+
`,
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("implements interfaces", () => {
|
|
52
|
+
const res = testRender(
|
|
53
|
+
<>
|
|
54
|
+
<jv.SourceFile path="InterfaceOne.java">
|
|
55
|
+
<jv.Declaration name='InterfaceOne'>
|
|
56
|
+
{code`
|
|
57
|
+
public interface InterfaceOne {
|
|
58
|
+
}
|
|
59
|
+
`}
|
|
60
|
+
</jv.Declaration>
|
|
61
|
+
</jv.SourceFile>
|
|
62
|
+
<jv.SourceFile path="InterfaceTwo.java">
|
|
63
|
+
<jv.Declaration name='InterfaceTwo'>
|
|
64
|
+
{code`
|
|
65
|
+
public interface InterfaceTwo {
|
|
66
|
+
}
|
|
67
|
+
`}
|
|
68
|
+
</jv.Declaration>
|
|
69
|
+
</jv.SourceFile>
|
|
70
|
+
<jv.PackageDirectory package="import">
|
|
71
|
+
<jv.SourceFile path="TestSubclass.java">
|
|
72
|
+
<jv.Class public name="TestSubclass" implements={[refkey("InterfaceOne"), refkey("InterfaceTwo")]}>
|
|
73
|
+
</jv.Class>
|
|
74
|
+
</jv.SourceFile>
|
|
75
|
+
</jv.PackageDirectory>
|
|
76
|
+
</>,
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
assertFileContents(res, {
|
|
80
|
+
"TestSubclass.java": d`
|
|
81
|
+
package me.test.code.import;
|
|
82
|
+
|
|
83
|
+
import me.test.code.InterfaceOne;
|
|
84
|
+
import me.test.code.InterfaceTwo;
|
|
85
|
+
|
|
86
|
+
public class TestSubclass implements InterfaceOne, InterfaceTwo {
|
|
87
|
+
|
|
88
|
+
}
|
|
89
|
+
`,
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("defines generics", () => {
|
|
94
|
+
const res = testRender(
|
|
95
|
+
<>
|
|
96
|
+
<jv.SourceFile path="TypeOne.java">
|
|
97
|
+
<jv.Declaration name='TypeOne'>
|
|
98
|
+
{code`
|
|
99
|
+
public interface TypeOne {
|
|
100
|
+
}
|
|
101
|
+
`}
|
|
102
|
+
</jv.Declaration>
|
|
103
|
+
</jv.SourceFile>
|
|
104
|
+
<jv.SourceFile path="TypeTwo.java">
|
|
105
|
+
<jv.Declaration name='TypeTwo'>
|
|
106
|
+
{code`
|
|
107
|
+
public interface TypeTwo {
|
|
108
|
+
}
|
|
109
|
+
`}
|
|
110
|
+
</jv.Declaration>
|
|
111
|
+
</jv.SourceFile>
|
|
112
|
+
<jv.PackageDirectory package="import">
|
|
113
|
+
<jv.SourceFile path="TestGenerics.java">
|
|
114
|
+
<jv.Class public name="TestGenerics" generics={{ T: refkey("TypeOne"), N: refkey("TypeTwo"), J: 'String', K: ''}}>
|
|
115
|
+
</jv.Class>
|
|
116
|
+
</jv.SourceFile>
|
|
117
|
+
</jv.PackageDirectory>
|
|
118
|
+
</>,
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
assertFileContents(res, {
|
|
122
|
+
"TestGenerics.java": d`
|
|
123
|
+
package me.test.code.import;
|
|
124
|
+
|
|
125
|
+
import me.test.code.TypeOne;
|
|
126
|
+
import me.test.code.TypeTwo;
|
|
127
|
+
|
|
128
|
+
public class TestGenerics<T extends TypeOne, N extends TypeTwo, J extends String, K> {
|
|
129
|
+
|
|
130
|
+
}
|
|
131
|
+
`,
|
|
132
|
+
});
|
|
133
|
+
});
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { code, Declaration, refkey } from "@alloy-js/core";
|
|
2
|
+
import { d } from "@alloy-js/core/testing";
|
|
3
|
+
import { expect, it } from "vitest";
|
|
4
|
+
import * as jv from "../src/components/index.js";
|
|
5
|
+
import { assertFileContents, testRender, toSourceText } from "./utils.js";
|
|
6
|
+
|
|
7
|
+
it("works", () => {
|
|
8
|
+
const res = toSourceText(
|
|
9
|
+
<>
|
|
10
|
+
<Declaration name="TestClass">
|
|
11
|
+
{code`
|
|
12
|
+
public class TestClass {
|
|
13
|
+
${<jv.Constructor public name="TestClass" />}
|
|
14
|
+
}
|
|
15
|
+
`}
|
|
16
|
+
</Declaration>
|
|
17
|
+
</>,
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
expect(res).toBe(d`
|
|
21
|
+
package me.test.code;
|
|
22
|
+
|
|
23
|
+
public class TestClass {
|
|
24
|
+
public TestClass() {
|
|
25
|
+
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
`);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("takes name from class", () => {
|
|
32
|
+
const res = toSourceText(
|
|
33
|
+
<>
|
|
34
|
+
<Declaration name="TestClass">
|
|
35
|
+
{code`
|
|
36
|
+
public class TestClass {
|
|
37
|
+
${<jv.Constructor public />}
|
|
38
|
+
}
|
|
39
|
+
`}
|
|
40
|
+
</Declaration>
|
|
41
|
+
</>,
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
expect(res).toBe(d`
|
|
45
|
+
package me.test.code;
|
|
46
|
+
|
|
47
|
+
public class TestClass {
|
|
48
|
+
public TestClass() {
|
|
49
|
+
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
`);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("declares parameters", () => {
|
|
56
|
+
const res = testRender(
|
|
57
|
+
<>
|
|
58
|
+
<jv.SourceFile path="Model.java">
|
|
59
|
+
<jv.Declaration name='Model'>
|
|
60
|
+
{code`
|
|
61
|
+
public class Model {
|
|
62
|
+
}
|
|
63
|
+
`}
|
|
64
|
+
</jv.Declaration>
|
|
65
|
+
</jv.SourceFile>
|
|
66
|
+
<jv.PackageDirectory package='imports'>
|
|
67
|
+
<jv.SourceFile path="TestClass.java">
|
|
68
|
+
<Declaration name="TestClass">
|
|
69
|
+
{code`
|
|
70
|
+
public class TestClass {
|
|
71
|
+
${<jv.Constructor public parameters={{
|
|
72
|
+
type: refkey("Model"),
|
|
73
|
+
age: "int"
|
|
74
|
+
}} />}
|
|
75
|
+
}
|
|
76
|
+
`}
|
|
77
|
+
</Declaration>
|
|
78
|
+
</jv.SourceFile>
|
|
79
|
+
</jv.PackageDirectory>
|
|
80
|
+
</>,
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
assertFileContents(res, {
|
|
84
|
+
"TestClass.java": d`
|
|
85
|
+
package me.test.code.imports;
|
|
86
|
+
|
|
87
|
+
import me.test.code.Model;
|
|
88
|
+
|
|
89
|
+
public class TestClass {
|
|
90
|
+
public TestClass(Model type, int age) {
|
|
91
|
+
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
`,
|
|
95
|
+
});
|
|
96
|
+
});
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { code, refkey } from "@alloy-js/core";
|
|
2
|
+
import { d } from "@alloy-js/core/testing";
|
|
3
|
+
import { expect, it } from "vitest";
|
|
4
|
+
import * as jv from "../src/components/index.js";
|
|
5
|
+
import { assertFileContents, testRender, toSourceText } from "./utils.js";
|
|
6
|
+
|
|
7
|
+
it("works", () => {
|
|
8
|
+
const res = toSourceText(<jv.Enum public name="TestEnum">
|
|
9
|
+
</jv.Enum>);
|
|
10
|
+
|
|
11
|
+
expect(res).toBe(d`
|
|
12
|
+
package me.test.code;
|
|
13
|
+
|
|
14
|
+
public enum TestEnum {
|
|
15
|
+
|
|
16
|
+
}
|
|
17
|
+
`);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("implements interfaces", () => {
|
|
21
|
+
const res = testRender(
|
|
22
|
+
<>
|
|
23
|
+
<jv.SourceFile path="InterfaceOne.java">
|
|
24
|
+
<jv.Declaration name='InterfaceOne'>
|
|
25
|
+
{code`
|
|
26
|
+
public interface InterfaceOne {
|
|
27
|
+
}
|
|
28
|
+
`}
|
|
29
|
+
</jv.Declaration>
|
|
30
|
+
</jv.SourceFile>
|
|
31
|
+
<jv.SourceFile path="InterfaceTwo.java">
|
|
32
|
+
<jv.Declaration name='InterfaceTwo'>
|
|
33
|
+
{code`
|
|
34
|
+
public interface InterfaceTwo {
|
|
35
|
+
}
|
|
36
|
+
`}
|
|
37
|
+
</jv.Declaration>
|
|
38
|
+
</jv.SourceFile>
|
|
39
|
+
<jv.PackageDirectory package="import">
|
|
40
|
+
<jv.SourceFile path="TestEnum.java">
|
|
41
|
+
<jv.Enum public name="TestEnum" implements={[refkey("InterfaceOne"), refkey("InterfaceTwo")]}>
|
|
42
|
+
</jv.Enum>
|
|
43
|
+
</jv.SourceFile>
|
|
44
|
+
</jv.PackageDirectory>
|
|
45
|
+
</>,
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
assertFileContents(res, {
|
|
49
|
+
"TestEnum.java": d`
|
|
50
|
+
package me.test.code.import;
|
|
51
|
+
|
|
52
|
+
import me.test.code.InterfaceOne;
|
|
53
|
+
import me.test.code.InterfaceTwo;
|
|
54
|
+
|
|
55
|
+
public enum TestEnum implements InterfaceOne, InterfaceTwo {
|
|
56
|
+
|
|
57
|
+
}
|
|
58
|
+
`,
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("declares members", () => {
|
|
63
|
+
const res = toSourceText(
|
|
64
|
+
<jv.Enum public name="TestEnum">
|
|
65
|
+
<jv.EnumMember name="ONE" />,
|
|
66
|
+
<jv.EnumMember name="TWO" />;
|
|
67
|
+
</jv.Enum>,
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
expect(res).toBe(d`
|
|
71
|
+
package me.test.code;
|
|
72
|
+
|
|
73
|
+
public enum TestEnum {
|
|
74
|
+
ONE,
|
|
75
|
+
TWO;
|
|
76
|
+
}
|
|
77
|
+
`);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("declares members with arguments", () => {
|
|
81
|
+
const res = toSourceText(
|
|
82
|
+
<jv.Enum public name="TestEnum">
|
|
83
|
+
<jv.EnumMember name="ONE" arguments={[<jv.Value value="One" />]} />,
|
|
84
|
+
<jv.EnumMember name="TWO" arguments={[<jv.Value value="Two" />]} />;
|
|
85
|
+
|
|
86
|
+
<jv.Constructor parameters={{
|
|
87
|
+
value: "String"
|
|
88
|
+
}}>
|
|
89
|
+
</jv.Constructor>
|
|
90
|
+
</jv.Enum>,
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
expect(res).toBe(d`
|
|
94
|
+
package me.test.code;
|
|
95
|
+
|
|
96
|
+
public enum TestEnum {
|
|
97
|
+
ONE("One"),
|
|
98
|
+
TWO("Two");
|
|
99
|
+
|
|
100
|
+
TestEnum(String value) {
|
|
101
|
+
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
`);
|
|
105
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Output, render } from "@alloy-js/core";
|
|
2
|
+
import { d } from "@alloy-js/core/testing";
|
|
3
|
+
import { expect, it } from "vitest";
|
|
4
|
+
import * as jv from "../src/components/index.js";
|
|
5
|
+
import { createLibrary } from "../src/index.js";
|
|
6
|
+
import { findFile } from "./utils.js";
|
|
7
|
+
|
|
8
|
+
it("uses import from external library", () => {
|
|
9
|
+
const testLib = createLibrary({
|
|
10
|
+
groupId: "me.test",
|
|
11
|
+
artifactId: "test-lib",
|
|
12
|
+
version: "1.0.0",
|
|
13
|
+
descriptor: {
|
|
14
|
+
"me.test.testlib": ["TestClass", "Tester"],
|
|
15
|
+
"me.test.testlib.models": ["TestModel"],
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const res = render(
|
|
20
|
+
<Output externals={[testLib]}>
|
|
21
|
+
<jv.PackageDirectory package="me.test.code">
|
|
22
|
+
<jv.SourceFile path='TestImport.java'>
|
|
23
|
+
<jv.Class public name="TestImport">
|
|
24
|
+
<jv.ObjectDeclaration type={testLib["TestModel"]} name="myTestModel" />
|
|
25
|
+
<jv.ObjectDeclaration type={testLib["TestClass"]} name="myTestClass" />
|
|
26
|
+
<jv.ObjectDeclaration type={testLib["Tester"]} name="myTester" />
|
|
27
|
+
</jv.Class>
|
|
28
|
+
</jv.SourceFile>
|
|
29
|
+
</jv.PackageDirectory>
|
|
30
|
+
</Output>,
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
expect(findFile(res, "TestImport.java").contents).toBe(d`
|
|
34
|
+
package me.test.code;
|
|
35
|
+
|
|
36
|
+
import me.test.testlib.models.TestModel;
|
|
37
|
+
import me.test.testlib.TestClass;
|
|
38
|
+
import me.test.testlib.Tester;
|
|
39
|
+
|
|
40
|
+
public class TestImport {
|
|
41
|
+
TestModel myTestModel = new TestModel();
|
|
42
|
+
TestClass myTestClass = new TestClass();
|
|
43
|
+
Tester myTester = new Tester();
|
|
44
|
+
}
|
|
45
|
+
`);
|
|
46
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { code, refkey } from "@alloy-js/core";
|
|
2
|
+
import { d } from "@alloy-js/core/testing";
|
|
3
|
+
import { it } from "vitest";
|
|
4
|
+
import * as jv from "../src/components/index.js";
|
|
5
|
+
import { assertFileContents, testRender } from "./utils.js";
|
|
6
|
+
|
|
7
|
+
it("passes types", () => {
|
|
8
|
+
const res = testRender(
|
|
9
|
+
<>
|
|
10
|
+
<jv.SourceFile path="TypeOne.java">
|
|
11
|
+
<jv.Declaration name='TypeOne'>
|
|
12
|
+
{code`
|
|
13
|
+
public interface TypeOne {
|
|
14
|
+
}
|
|
15
|
+
`}
|
|
16
|
+
</jv.Declaration>
|
|
17
|
+
</jv.SourceFile>
|
|
18
|
+
<jv.SourceFile path="TypeTwo.java">
|
|
19
|
+
<jv.Declaration name='TypeTwo'>
|
|
20
|
+
{code`
|
|
21
|
+
public interface TypeTwo {
|
|
22
|
+
}
|
|
23
|
+
`}
|
|
24
|
+
</jv.Declaration>
|
|
25
|
+
</jv.SourceFile>
|
|
26
|
+
<jv.PackageDirectory package="import">
|
|
27
|
+
<jv.SourceFile path="TestGenerics.java">
|
|
28
|
+
<jv.Class public name="TestGenerics">
|
|
29
|
+
{code`
|
|
30
|
+
public TestGenerics() {
|
|
31
|
+
List${<jv.Generics types={[refkey("TypeOne")]} />} list = new ArrayList${<jv.Generics />}();
|
|
32
|
+
List${<jv.Generics types={[{'?': refkey("TypeTwo")}]} />} list2 = new ArrayList${<jv.Generics />}();
|
|
33
|
+
List${<jv.Generics types={[{'?': ''}]} />} list3 = new ArrayList${<jv.Generics />}();
|
|
34
|
+
}
|
|
35
|
+
`}
|
|
36
|
+
</jv.Class>
|
|
37
|
+
</jv.SourceFile>
|
|
38
|
+
</jv.PackageDirectory>
|
|
39
|
+
</>,
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
assertFileContents(res, {
|
|
43
|
+
"TestGenerics.java": d`
|
|
44
|
+
package me.test.code.import;
|
|
45
|
+
|
|
46
|
+
import me.test.code.TypeOne;
|
|
47
|
+
import me.test.code.TypeTwo;
|
|
48
|
+
|
|
49
|
+
public class TestGenerics {
|
|
50
|
+
public TestGenerics() {
|
|
51
|
+
List<TypeOne> list = new ArrayList<>();
|
|
52
|
+
List<? extends TypeTwo> list2 = new ArrayList<>();
|
|
53
|
+
List<?> list3 = new ArrayList<>();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
`,
|
|
57
|
+
});
|
|
58
|
+
});
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { refkey } from "@alloy-js/core";
|
|
2
|
+
import { d } from "@alloy-js/core/testing";
|
|
3
|
+
import { expect, it } from "vitest";
|
|
4
|
+
import * as jv from "../src/components/index.js";
|
|
5
|
+
import { assertFileContents, testRender, toSourceText } from "./utils.js";
|
|
6
|
+
|
|
7
|
+
it("works", () => {
|
|
8
|
+
const res = toSourceText(
|
|
9
|
+
<jv.Interface public name="TestInterface">
|
|
10
|
+
</jv.Interface>,
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
expect(res).toBe(d`
|
|
14
|
+
package me.test.code;
|
|
15
|
+
|
|
16
|
+
public interface TestInterface {
|
|
17
|
+
|
|
18
|
+
}
|
|
19
|
+
`);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("extends other interfaces", () => {
|
|
23
|
+
const res = testRender(
|
|
24
|
+
<>
|
|
25
|
+
<jv.SourceFile path="InterfaceOne.java">
|
|
26
|
+
<jv.Interface name="InterfaceOne" />
|
|
27
|
+
</jv.SourceFile>
|
|
28
|
+
<jv.SourceFile path="InterfaceTwo.java">
|
|
29
|
+
<jv.Interface name="InterfaceTwo" />
|
|
30
|
+
</jv.SourceFile>
|
|
31
|
+
<jv.PackageDirectory package="import">
|
|
32
|
+
<jv.SourceFile path="TestInterface.java">
|
|
33
|
+
<jv.Interface public name="TestInterface" extends={[refkey("InterfaceOne"), refkey("InterfaceTwo")]}>
|
|
34
|
+
</jv.Interface>
|
|
35
|
+
</jv.SourceFile>
|
|
36
|
+
</jv.PackageDirectory>
|
|
37
|
+
</>,
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
assertFileContents(res, {
|
|
41
|
+
"TestInterface.java": `
|
|
42
|
+
package me.test.code.import;
|
|
43
|
+
|
|
44
|
+
import me.test.code.InterfaceOne;
|
|
45
|
+
import me.test.code.InterfaceTwo;
|
|
46
|
+
|
|
47
|
+
public interface TestInterface extends InterfaceOne, InterfaceTwo {
|
|
48
|
+
|
|
49
|
+
}
|
|
50
|
+
`,
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("defines generics", () => {
|
|
55
|
+
const res = testRender(
|
|
56
|
+
<>
|
|
57
|
+
<jv.SourceFile path="TypeOne.java">
|
|
58
|
+
<jv.Interface name="TypeOne" />
|
|
59
|
+
</jv.SourceFile>
|
|
60
|
+
<jv.SourceFile path="TypeTwo.java">
|
|
61
|
+
<jv.Interface name="TypeTwo" />
|
|
62
|
+
</jv.SourceFile>
|
|
63
|
+
<jv.PackageDirectory package="import">
|
|
64
|
+
<jv.SourceFile path="TestGenerics.java">
|
|
65
|
+
<jv.Interface public name="TestGenerics" generics={{ T: refkey("TypeOne"), N: refkey("TypeTwo"), J: 'String', K: ''}}>
|
|
66
|
+
</jv.Interface>
|
|
67
|
+
</jv.SourceFile>
|
|
68
|
+
</jv.PackageDirectory>
|
|
69
|
+
</>,
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
assertFileContents(res, {
|
|
73
|
+
"TestGenerics.java": d`
|
|
74
|
+
package me.test.code.import;
|
|
75
|
+
|
|
76
|
+
import me.test.code.TypeOne;
|
|
77
|
+
import me.test.code.TypeTwo;
|
|
78
|
+
|
|
79
|
+
public interface TestGenerics<T extends TypeOne, N extends TypeTwo, J extends String, K> {
|
|
80
|
+
|
|
81
|
+
}
|
|
82
|
+
`,
|
|
83
|
+
});
|
|
84
|
+
});
|