@alloy-js/java 0.10.0 → 0.11.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/CHANGELOG.md +7 -0
- package/dist/src/builtins/util.js +1 -2
- package/dist/src/components/Annotation.js +2 -4
- package/dist/src/components/ArgumentList.js +2 -5
- package/dist/src/components/Class.js +2 -6
- package/dist/src/components/Constructor.js +2 -4
- package/dist/src/components/Declaration.js +1 -2
- package/dist/src/components/Enum.js +2 -5
- package/dist/src/components/ExtendsClause.js +2 -5
- package/dist/src/components/ImplementsClause.js +2 -5
- package/dist/src/components/ImportStatement.js +1 -2
- package/dist/src/components/Interface.js +2 -5
- package/dist/src/components/MavenProject.js +2 -6
- package/dist/src/components/Method.js +1 -2
- package/dist/src/components/Modifiers.js +1 -2
- package/dist/src/components/Name.js +1 -2
- package/dist/src/components/NamedArgumentList.js +2 -4
- package/dist/src/components/ObjectDeclaration.js +2 -4
- package/dist/src/components/PackageDirectory.js +2 -4
- package/dist/src/components/Parameters.js +1 -2
- package/dist/src/components/ProjectDirectory.js +2 -4
- package/dist/src/components/Reference.js +1 -2
- package/dist/src/components/SourceFile.js +2 -5
- package/dist/src/components/TypeArguments.js +2 -5
- package/dist/src/components/TypeParameters.js +2 -5
- package/dist/src/components/Value.js +1 -2
- package/dist/src/components/Variable.js +1 -2
- package/dist/src/components/index.js +1 -2
- package/dist/src/components/stc/index.js +1 -2
- package/dist/src/create-library.js +1 -2
- package/dist/src/index.js +1 -2
- package/dist/src/name-policy.js +1 -2
- package/dist/src/symbols/index.js +1 -2
- package/dist/src/symbols/java-output-symbol.js +1 -2
- package/dist/src/symbols/java-package-scope.js +1 -2
- package/dist/src/symbols/java-project-scope.js +1 -2
- package/dist/src/symbols/reference.js +1 -2
- package/dist/test/annotation.test.js +77 -0
- package/dist/test/class.test.js +164 -0
- package/dist/test/constructor.test.js +101 -0
- package/dist/test/enum.test.js +136 -0
- package/dist/test/externals.test.js +72 -0
- package/dist/test/interface.test.js +110 -0
- package/dist/test/maven.test.js +251 -0
- package/dist/test/method.test.js +270 -0
- package/dist/test/package.test.js +18 -0
- package/dist/test/reference.test.js +108 -0
- package/dist/test/type-arguments.test.js +83 -0
- package/dist/test/utils.js +61 -0
- package/dist/test/values.test.js +32 -0
- package/dist/test/variables.test.js +143 -0
- package/dist/test/vitest.d.js +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +12 -17
- package/temp/api.json +1 -1
- package/tsdoc-metadata.json +1 -1
- package/babel.config.cjs +0 -4
- package/dist/src/builtins/index.js.map +0 -1
- package/dist/src/builtins/util.js.map +0 -1
- package/dist/src/components/Annotation.js.map +0 -1
- package/dist/src/components/ArgumentList.js.map +0 -1
- package/dist/src/components/Class.js.map +0 -1
- package/dist/src/components/Constructor.js.map +0 -1
- package/dist/src/components/Declaration.js.map +0 -1
- package/dist/src/components/Enum.js.map +0 -1
- package/dist/src/components/ExtendsClause.js.map +0 -1
- package/dist/src/components/ImplementsClause.js.map +0 -1
- package/dist/src/components/ImportStatement.js.map +0 -1
- package/dist/src/components/Interface.js.map +0 -1
- package/dist/src/components/MavenProject.js.map +0 -1
- package/dist/src/components/Method.js.map +0 -1
- package/dist/src/components/Modifiers.js.map +0 -1
- package/dist/src/components/Name.js.map +0 -1
- package/dist/src/components/NamedArgumentList.js.map +0 -1
- package/dist/src/components/ObjectDeclaration.js.map +0 -1
- package/dist/src/components/PackageDirectory.js.map +0 -1
- package/dist/src/components/Parameters.js.map +0 -1
- package/dist/src/components/ProjectDirectory.js.map +0 -1
- package/dist/src/components/Reference.js.map +0 -1
- package/dist/src/components/SourceFile.js.map +0 -1
- package/dist/src/components/TypeArguments.js.map +0 -1
- package/dist/src/components/TypeParameters.js.map +0 -1
- package/dist/src/components/Value.js.map +0 -1
- package/dist/src/components/Variable.js.map +0 -1
- package/dist/src/components/index.js.map +0 -1
- package/dist/src/components/stc/index.js.map +0 -1
- package/dist/src/create-library.js.map +0 -1
- package/dist/src/index.js.map +0 -1
- package/dist/src/name-policy.js.map +0 -1
- package/dist/src/symbols/index.js.map +0 -1
- package/dist/src/symbols/java-output-symbol.js.map +0 -1
- package/dist/src/symbols/java-package-scope.js.map +0 -1
- package/dist/src/symbols/java-project-scope.js.map +0 -1
- package/dist/src/symbols/reference.js.map +0 -1
- package/dist/src/symbols/scopes.js.map +0 -1
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { code, refkey } from "@alloy-js/core";
|
|
3
|
+
import { d } from "@alloy-js/core/testing";
|
|
4
|
+
import { expect, it } from "vitest";
|
|
5
|
+
import * as jv from "../src/components/index.js";
|
|
6
|
+
import { assertFileContents, testRender, toSourceText } from "./utils.js";
|
|
7
|
+
it("works", () => {
|
|
8
|
+
const res = toSourceText(_$createComponent(jv.Class, {
|
|
9
|
+
"public": true,
|
|
10
|
+
abstract: true,
|
|
11
|
+
final: true,
|
|
12
|
+
name: "TestClass"
|
|
13
|
+
}));
|
|
14
|
+
expect(res).toBe(d`
|
|
15
|
+
package me.test.code;
|
|
16
|
+
|
|
17
|
+
public abstract final class TestClass {}
|
|
18
|
+
`);
|
|
19
|
+
});
|
|
20
|
+
it("extends class", () => {
|
|
21
|
+
const res = testRender([_$createComponent(jv.SourceFile, {
|
|
22
|
+
path: "TestSuperclass.java",
|
|
23
|
+
get children() {
|
|
24
|
+
return _$createComponent(jv.Class, {
|
|
25
|
+
"public": true,
|
|
26
|
+
name: "TestSuperclass"
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}), _$createComponent(jv.PackageDirectory, {
|
|
30
|
+
"package": "import",
|
|
31
|
+
get children() {
|
|
32
|
+
return _$createComponent(jv.SourceFile, {
|
|
33
|
+
path: "TestSubclass.java",
|
|
34
|
+
get children() {
|
|
35
|
+
return _$createComponent(jv.Class, {
|
|
36
|
+
"public": true,
|
|
37
|
+
name: "TestSubclass",
|
|
38
|
+
get ["extends"]() {
|
|
39
|
+
return refkey("TestSuperclass");
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
})]);
|
|
46
|
+
assertFileContents(res, {
|
|
47
|
+
"TestSubclass.java": d`
|
|
48
|
+
package me.test.code.import;
|
|
49
|
+
|
|
50
|
+
import me.test.code.TestSuperclass;
|
|
51
|
+
|
|
52
|
+
public class TestSubclass extends TestSuperclass {}
|
|
53
|
+
`
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
it("implements interfaces", () => {
|
|
57
|
+
const res = testRender([_$createComponent(jv.SourceFile, {
|
|
58
|
+
path: "InterfaceOne.java",
|
|
59
|
+
get children() {
|
|
60
|
+
return _$createComponent(jv.Declaration, {
|
|
61
|
+
name: "InterfaceOne",
|
|
62
|
+
children: code`
|
|
63
|
+
public interface InterfaceOne {
|
|
64
|
+
}
|
|
65
|
+
`
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}), _$createComponent(jv.SourceFile, {
|
|
69
|
+
path: "InterfaceTwo.java",
|
|
70
|
+
get children() {
|
|
71
|
+
return _$createComponent(jv.Declaration, {
|
|
72
|
+
name: "InterfaceTwo",
|
|
73
|
+
children: code`
|
|
74
|
+
public interface InterfaceTwo {
|
|
75
|
+
}
|
|
76
|
+
`
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}), _$createComponent(jv.PackageDirectory, {
|
|
80
|
+
"package": "import",
|
|
81
|
+
get children() {
|
|
82
|
+
return _$createComponent(jv.SourceFile, {
|
|
83
|
+
path: "TestSubclass.java",
|
|
84
|
+
get children() {
|
|
85
|
+
return _$createComponent(jv.Class, {
|
|
86
|
+
"public": true,
|
|
87
|
+
name: "TestSubclass",
|
|
88
|
+
get ["implements"]() {
|
|
89
|
+
return [refkey("InterfaceOne"), refkey("InterfaceTwo")];
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
})]);
|
|
96
|
+
assertFileContents(res, {
|
|
97
|
+
"TestSubclass.java": d`
|
|
98
|
+
package me.test.code.import;
|
|
99
|
+
|
|
100
|
+
import me.test.code.InterfaceOne;
|
|
101
|
+
import me.test.code.InterfaceTwo;
|
|
102
|
+
|
|
103
|
+
public class TestSubclass implements InterfaceOne, InterfaceTwo {}
|
|
104
|
+
`
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
it("defines generics", () => {
|
|
108
|
+
const res = testRender([_$createComponent(jv.SourceFile, {
|
|
109
|
+
path: "TypeOne.java",
|
|
110
|
+
get children() {
|
|
111
|
+
return _$createComponent(jv.Declaration, {
|
|
112
|
+
name: "TypeOne",
|
|
113
|
+
children: code`
|
|
114
|
+
public interface TypeOne {
|
|
115
|
+
}
|
|
116
|
+
`
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}), _$createComponent(jv.SourceFile, {
|
|
120
|
+
path: "TypeTwo.java",
|
|
121
|
+
get children() {
|
|
122
|
+
return _$createComponent(jv.Declaration, {
|
|
123
|
+
name: "TypeTwo",
|
|
124
|
+
children: code`
|
|
125
|
+
public interface TypeTwo {
|
|
126
|
+
}
|
|
127
|
+
`
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}), _$createComponent(jv.PackageDirectory, {
|
|
131
|
+
"package": "import",
|
|
132
|
+
get children() {
|
|
133
|
+
return _$createComponent(jv.SourceFile, {
|
|
134
|
+
path: "TestGenerics.java",
|
|
135
|
+
get children() {
|
|
136
|
+
return _$createComponent(jv.Class, {
|
|
137
|
+
"public": true,
|
|
138
|
+
name: "TestGenerics",
|
|
139
|
+
get generics() {
|
|
140
|
+
return {
|
|
141
|
+
T: refkey("TypeOne"),
|
|
142
|
+
N: refkey("TypeTwo"),
|
|
143
|
+
J: "String",
|
|
144
|
+
K: ""
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
})], {
|
|
152
|
+
printWidth: 100
|
|
153
|
+
});
|
|
154
|
+
assertFileContents(res, {
|
|
155
|
+
"TestGenerics.java": d`
|
|
156
|
+
package me.test.code.import;
|
|
157
|
+
|
|
158
|
+
import me.test.code.TypeOne;
|
|
159
|
+
import me.test.code.TypeTwo;
|
|
160
|
+
|
|
161
|
+
public class TestGenerics<T extends TypeOne, N extends TypeTwo, J extends String, K> {}
|
|
162
|
+
`
|
|
163
|
+
});
|
|
164
|
+
});
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { memo as _$memo, createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { code, Declaration, refkey } from "@alloy-js/core";
|
|
3
|
+
import { d } from "@alloy-js/core/testing";
|
|
4
|
+
import { expect, it } from "vitest";
|
|
5
|
+
import * as jv from "../src/components/index.js";
|
|
6
|
+
import { assertFileContents, testRender, toSourceText } from "./utils.js";
|
|
7
|
+
it("works", () => {
|
|
8
|
+
const res = toSourceText([_$createComponent(Declaration, {
|
|
9
|
+
name: "TestClass",
|
|
10
|
+
get children() {
|
|
11
|
+
return code`
|
|
12
|
+
public class TestClass {
|
|
13
|
+
${_$createComponent(jv.Constructor, {
|
|
14
|
+
"public": true,
|
|
15
|
+
name: "TestClass"
|
|
16
|
+
})}
|
|
17
|
+
}
|
|
18
|
+
`;
|
|
19
|
+
}
|
|
20
|
+
})]);
|
|
21
|
+
expect(res).toBe(d`
|
|
22
|
+
package me.test.code;
|
|
23
|
+
|
|
24
|
+
public class TestClass {
|
|
25
|
+
public TestClass() {}
|
|
26
|
+
}
|
|
27
|
+
`);
|
|
28
|
+
});
|
|
29
|
+
it("takes name from class", () => {
|
|
30
|
+
const res = toSourceText([_$createComponent(Declaration, {
|
|
31
|
+
name: "TestClass",
|
|
32
|
+
get children() {
|
|
33
|
+
return code`
|
|
34
|
+
public class TestClass {
|
|
35
|
+
${_$createComponent(jv.Constructor, {
|
|
36
|
+
"public": true
|
|
37
|
+
})}
|
|
38
|
+
}
|
|
39
|
+
`;
|
|
40
|
+
}
|
|
41
|
+
})]);
|
|
42
|
+
expect(res).toBe(d`
|
|
43
|
+
package me.test.code;
|
|
44
|
+
|
|
45
|
+
public class TestClass {
|
|
46
|
+
public TestClass() {}
|
|
47
|
+
}
|
|
48
|
+
`);
|
|
49
|
+
});
|
|
50
|
+
it("declares parameters", () => {
|
|
51
|
+
const res = testRender([_$createComponent(jv.SourceFile, {
|
|
52
|
+
path: "Model.java",
|
|
53
|
+
get children() {
|
|
54
|
+
return _$createComponent(jv.Declaration, {
|
|
55
|
+
name: "Model",
|
|
56
|
+
children: code`
|
|
57
|
+
public class Model {
|
|
58
|
+
}
|
|
59
|
+
`
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}), _$createComponent(jv.PackageDirectory, {
|
|
63
|
+
"package": "imports",
|
|
64
|
+
get children() {
|
|
65
|
+
return _$createComponent(jv.SourceFile, {
|
|
66
|
+
path: "TestClass.java",
|
|
67
|
+
get children() {
|
|
68
|
+
return _$createComponent(Declaration, {
|
|
69
|
+
name: "TestClass",
|
|
70
|
+
get children() {
|
|
71
|
+
return code`
|
|
72
|
+
public class TestClass {
|
|
73
|
+
${_$createComponent(jv.Constructor, {
|
|
74
|
+
"public": true,
|
|
75
|
+
get parameters() {
|
|
76
|
+
return {
|
|
77
|
+
type: refkey("Model"),
|
|
78
|
+
age: "int"
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
})}
|
|
82
|
+
}
|
|
83
|
+
`;
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
})]);
|
|
90
|
+
assertFileContents(res, {
|
|
91
|
+
"TestClass.java": d`
|
|
92
|
+
package me.test.code.imports;
|
|
93
|
+
|
|
94
|
+
import me.test.code.Model;
|
|
95
|
+
|
|
96
|
+
public class TestClass {
|
|
97
|
+
public TestClass(Model type, int age) {}
|
|
98
|
+
}
|
|
99
|
+
`
|
|
100
|
+
});
|
|
101
|
+
});
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { createComponent as _$createComponent, createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { code, refkey } from "@alloy-js/core";
|
|
3
|
+
import { d } from "@alloy-js/core/testing";
|
|
4
|
+
import { expect, it } from "vitest";
|
|
5
|
+
import * as jv from "../src/components/index.js";
|
|
6
|
+
import { assertFileContents, testRender, toSourceText } from "./utils.js";
|
|
7
|
+
it("works", () => {
|
|
8
|
+
const res = toSourceText(_$createComponent(jv.Enum, {
|
|
9
|
+
"public": true,
|
|
10
|
+
name: "TestEnum"
|
|
11
|
+
}));
|
|
12
|
+
expect(res).toBe(d`
|
|
13
|
+
package me.test.code;
|
|
14
|
+
|
|
15
|
+
public enum TestEnum {}
|
|
16
|
+
`);
|
|
17
|
+
});
|
|
18
|
+
it("implements interfaces", () => {
|
|
19
|
+
const res = testRender([_$createComponent(jv.SourceFile, {
|
|
20
|
+
path: "InterfaceOne.java",
|
|
21
|
+
get children() {
|
|
22
|
+
return _$createComponent(jv.Declaration, {
|
|
23
|
+
name: "InterfaceOne",
|
|
24
|
+
children: code`
|
|
25
|
+
public interface InterfaceOne {
|
|
26
|
+
}
|
|
27
|
+
`
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}), _$createComponent(jv.SourceFile, {
|
|
31
|
+
path: "InterfaceTwo.java",
|
|
32
|
+
get children() {
|
|
33
|
+
return _$createComponent(jv.Declaration, {
|
|
34
|
+
name: "InterfaceTwo",
|
|
35
|
+
children: code`
|
|
36
|
+
public interface InterfaceTwo {
|
|
37
|
+
}
|
|
38
|
+
`
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}), _$createComponent(jv.PackageDirectory, {
|
|
42
|
+
"package": "import",
|
|
43
|
+
get children() {
|
|
44
|
+
return _$createComponent(jv.SourceFile, {
|
|
45
|
+
path: "TestEnum.java",
|
|
46
|
+
get children() {
|
|
47
|
+
return _$createComponent(jv.Enum, {
|
|
48
|
+
"public": true,
|
|
49
|
+
name: "TestEnum",
|
|
50
|
+
get ["implements"]() {
|
|
51
|
+
return [refkey("InterfaceOne"), refkey("InterfaceTwo")];
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
})], {
|
|
58
|
+
printWidth: 100
|
|
59
|
+
});
|
|
60
|
+
assertFileContents(res, {
|
|
61
|
+
"TestEnum.java": d`
|
|
62
|
+
package me.test.code.import;
|
|
63
|
+
|
|
64
|
+
import me.test.code.InterfaceOne;
|
|
65
|
+
import me.test.code.InterfaceTwo;
|
|
66
|
+
|
|
67
|
+
public enum TestEnum implements InterfaceOne, InterfaceTwo {}
|
|
68
|
+
`
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
it("declares members", () => {
|
|
72
|
+
const res = toSourceText(_$createComponent(jv.Enum, {
|
|
73
|
+
"public": true,
|
|
74
|
+
name: "TestEnum",
|
|
75
|
+
get children() {
|
|
76
|
+
return _$createComponent(jv.EnumMemberList, {
|
|
77
|
+
get children() {
|
|
78
|
+
return [_$createComponent(jv.EnumMember, {
|
|
79
|
+
name: "ONE"
|
|
80
|
+
}), _$createComponent(jv.EnumMember, {
|
|
81
|
+
name: "TWO"
|
|
82
|
+
})];
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}));
|
|
87
|
+
expect(res).toBe(d`
|
|
88
|
+
package me.test.code;
|
|
89
|
+
|
|
90
|
+
public enum TestEnum {
|
|
91
|
+
ONE,
|
|
92
|
+
TWO;
|
|
93
|
+
}
|
|
94
|
+
`);
|
|
95
|
+
});
|
|
96
|
+
it("declares members with arguments", () => {
|
|
97
|
+
const res = toSourceText(_$createComponent(jv.Enum, {
|
|
98
|
+
"public": true,
|
|
99
|
+
name: "TestEnum",
|
|
100
|
+
get children() {
|
|
101
|
+
return [_$createComponent(jv.EnumMemberList, {
|
|
102
|
+
get children() {
|
|
103
|
+
return [_$createComponent(jv.EnumMember, {
|
|
104
|
+
name: "ONE",
|
|
105
|
+
get args() {
|
|
106
|
+
return [_$createComponent(jv.Value, {
|
|
107
|
+
value: "One"
|
|
108
|
+
})];
|
|
109
|
+
}
|
|
110
|
+
}), _$createComponent(jv.EnumMember, {
|
|
111
|
+
name: "TWO",
|
|
112
|
+
get args() {
|
|
113
|
+
return [_$createComponent(jv.Value, {
|
|
114
|
+
value: "Two"
|
|
115
|
+
})];
|
|
116
|
+
}
|
|
117
|
+
})];
|
|
118
|
+
}
|
|
119
|
+
}), _$createIntrinsic("hbr", {}), _$createIntrinsic("hbr", {}), _$createComponent(jv.Constructor, {
|
|
120
|
+
parameters: {
|
|
121
|
+
value: "String"
|
|
122
|
+
}
|
|
123
|
+
})];
|
|
124
|
+
}
|
|
125
|
+
}));
|
|
126
|
+
expect(res).toBe(d`
|
|
127
|
+
package me.test.code;
|
|
128
|
+
|
|
129
|
+
public enum TestEnum {
|
|
130
|
+
ONE("One"),
|
|
131
|
+
TWO("Two");
|
|
132
|
+
|
|
133
|
+
TestEnum(String value) {}
|
|
134
|
+
}
|
|
135
|
+
`);
|
|
136
|
+
});
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { Output, render, StatementList } from "@alloy-js/core";
|
|
3
|
+
import { d } from "@alloy-js/core/testing";
|
|
4
|
+
import { expect, it } from "vitest";
|
|
5
|
+
import * as jv from "../src/components/index.js";
|
|
6
|
+
import { createLibrary } from "../src/index.js";
|
|
7
|
+
import { findFile } from "./utils.js";
|
|
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
|
+
const res = render(_$createComponent(Output, {
|
|
19
|
+
externals: [testLib],
|
|
20
|
+
get children() {
|
|
21
|
+
return _$createComponent(jv.PackageDirectory, {
|
|
22
|
+
"package": "me.test.code",
|
|
23
|
+
get children() {
|
|
24
|
+
return _$createComponent(jv.SourceFile, {
|
|
25
|
+
path: "TestImport.java",
|
|
26
|
+
get children() {
|
|
27
|
+
return _$createComponent(jv.Class, {
|
|
28
|
+
"public": true,
|
|
29
|
+
name: "TestImport",
|
|
30
|
+
get children() {
|
|
31
|
+
return _$createComponent(StatementList, {
|
|
32
|
+
get children() {
|
|
33
|
+
return [_$createComponent(jv.ObjectDeclaration, {
|
|
34
|
+
get type() {
|
|
35
|
+
return testLib["TestModel"];
|
|
36
|
+
},
|
|
37
|
+
name: "myTestModel"
|
|
38
|
+
}), _$createComponent(jv.ObjectDeclaration, {
|
|
39
|
+
get type() {
|
|
40
|
+
return testLib["TestClass"];
|
|
41
|
+
},
|
|
42
|
+
name: "myTestClass"
|
|
43
|
+
}), _$createComponent(jv.ObjectDeclaration, {
|
|
44
|
+
get type() {
|
|
45
|
+
return testLib["Tester"];
|
|
46
|
+
},
|
|
47
|
+
name: "myTester"
|
|
48
|
+
})];
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}));
|
|
59
|
+
expect(findFile(res, "TestImport.java").contents).toBe(d`
|
|
60
|
+
package me.test.code;
|
|
61
|
+
|
|
62
|
+
import me.test.testlib.models.TestModel;
|
|
63
|
+
import me.test.testlib.TestClass;
|
|
64
|
+
import me.test.testlib.Tester;
|
|
65
|
+
|
|
66
|
+
public class TestImport {
|
|
67
|
+
TestModel myTestModel = new TestModel();
|
|
68
|
+
TestClass myTestClass = new TestClass();
|
|
69
|
+
Tester myTester = new Tester();
|
|
70
|
+
}
|
|
71
|
+
`);
|
|
72
|
+
});
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { refkey } from "@alloy-js/core";
|
|
3
|
+
import { d } from "@alloy-js/core/testing";
|
|
4
|
+
import { expect, it } from "vitest";
|
|
5
|
+
import * as jv from "../src/components/index.js";
|
|
6
|
+
import { assertFileContents, testRender, toSourceText } from "./utils.js";
|
|
7
|
+
it("works", () => {
|
|
8
|
+
const res = toSourceText(_$createComponent(jv.Interface, {
|
|
9
|
+
"public": true,
|
|
10
|
+
name: "TestInterface"
|
|
11
|
+
}));
|
|
12
|
+
expect(res).toBe(d`
|
|
13
|
+
package me.test.code;
|
|
14
|
+
|
|
15
|
+
public interface TestInterface {}
|
|
16
|
+
`);
|
|
17
|
+
});
|
|
18
|
+
it("extends other interfaces", () => {
|
|
19
|
+
const res = testRender([_$createComponent(jv.SourceFile, {
|
|
20
|
+
path: "InterfaceOne.java",
|
|
21
|
+
get children() {
|
|
22
|
+
return _$createComponent(jv.Interface, {
|
|
23
|
+
name: "InterfaceOne"
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}), _$createComponent(jv.SourceFile, {
|
|
27
|
+
path: "InterfaceTwo.java",
|
|
28
|
+
get children() {
|
|
29
|
+
return _$createComponent(jv.Interface, {
|
|
30
|
+
name: "InterfaceTwo"
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}), _$createComponent(jv.PackageDirectory, {
|
|
34
|
+
"package": "import",
|
|
35
|
+
get children() {
|
|
36
|
+
return _$createComponent(jv.SourceFile, {
|
|
37
|
+
path: "TestInterface.java",
|
|
38
|
+
get children() {
|
|
39
|
+
return _$createComponent(jv.Interface, {
|
|
40
|
+
"public": true,
|
|
41
|
+
name: "TestInterface",
|
|
42
|
+
get ["extends"]() {
|
|
43
|
+
return [refkey("InterfaceOne"), refkey("InterfaceTwo")];
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
})]);
|
|
50
|
+
assertFileContents(res, {
|
|
51
|
+
"TestInterface.java": `
|
|
52
|
+
package me.test.code.import;
|
|
53
|
+
|
|
54
|
+
import me.test.code.InterfaceOne;
|
|
55
|
+
import me.test.code.InterfaceTwo;
|
|
56
|
+
|
|
57
|
+
public interface TestInterface extends InterfaceOne, InterfaceTwo {}
|
|
58
|
+
`
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
it("defines generics", () => {
|
|
62
|
+
const res = testRender([_$createComponent(jv.SourceFile, {
|
|
63
|
+
path: "TypeOne.java",
|
|
64
|
+
get children() {
|
|
65
|
+
return _$createComponent(jv.Interface, {
|
|
66
|
+
name: "TypeOne"
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}), _$createComponent(jv.SourceFile, {
|
|
70
|
+
path: "TypeTwo.java",
|
|
71
|
+
get children() {
|
|
72
|
+
return _$createComponent(jv.Interface, {
|
|
73
|
+
name: "TypeTwo"
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}), _$createComponent(jv.PackageDirectory, {
|
|
77
|
+
"package": "import",
|
|
78
|
+
get children() {
|
|
79
|
+
return _$createComponent(jv.SourceFile, {
|
|
80
|
+
path: "TestGenerics.java",
|
|
81
|
+
get children() {
|
|
82
|
+
return _$createComponent(jv.Interface, {
|
|
83
|
+
"public": true,
|
|
84
|
+
name: "TestGenerics",
|
|
85
|
+
get generics() {
|
|
86
|
+
return {
|
|
87
|
+
T: refkey("TypeOne"),
|
|
88
|
+
N: refkey("TypeTwo"),
|
|
89
|
+
J: "String",
|
|
90
|
+
K: ""
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
})], {
|
|
98
|
+
printWidth: 100
|
|
99
|
+
});
|
|
100
|
+
assertFileContents(res, {
|
|
101
|
+
"TestGenerics.java": d`
|
|
102
|
+
package me.test.code.import;
|
|
103
|
+
|
|
104
|
+
import me.test.code.TypeOne;
|
|
105
|
+
import me.test.code.TypeTwo;
|
|
106
|
+
|
|
107
|
+
public interface TestGenerics<T extends TypeOne, N extends TypeTwo, J extends String, K> {}
|
|
108
|
+
`
|
|
109
|
+
});
|
|
110
|
+
});
|