@alloy-js/java 0.10.0 → 0.12.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 +11 -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,251 @@
|
|
|
1
|
+
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { Output, render } from "@alloy-js/core";
|
|
3
|
+
import { it } from "vitest";
|
|
4
|
+
import { ProjectDirectory } from "../src/components/index.js";
|
|
5
|
+
import { assertFileContents } from "./utils.js";
|
|
6
|
+
it("generates barebones pom.xml file", () => {
|
|
7
|
+
const projectConfig = {
|
|
8
|
+
groupId: "me.example",
|
|
9
|
+
artifactId: "test",
|
|
10
|
+
version: "1.0.0",
|
|
11
|
+
javaVersion: 8
|
|
12
|
+
};
|
|
13
|
+
const res = render(_$createComponent(Output, {
|
|
14
|
+
get children() {
|
|
15
|
+
return _$createComponent(ProjectDirectory, {
|
|
16
|
+
name: "TestMavenProject",
|
|
17
|
+
mavenProjectConfig: projectConfig
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}));
|
|
21
|
+
assertFileContents(res, {
|
|
22
|
+
"pom.xml": `
|
|
23
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
24
|
+
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
25
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
26
|
+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
27
|
+
|
|
28
|
+
<modelVersion>4.0.0</modelVersion>
|
|
29
|
+
<groupId>me.example</groupId>
|
|
30
|
+
<artifactId>test</artifactId>
|
|
31
|
+
<version>1.0.0</version>
|
|
32
|
+
|
|
33
|
+
<properties>
|
|
34
|
+
<maven.compiler.source>8</maven.compiler.source>
|
|
35
|
+
<maven.compiler.target>8</maven.compiler.target>
|
|
36
|
+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
37
|
+
</properties>
|
|
38
|
+
</project>
|
|
39
|
+
`
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
it("generates complex configuration", () => {
|
|
43
|
+
// Some fields are duplicate, just to show it can handle array data
|
|
44
|
+
const projectConfig = {
|
|
45
|
+
groupId: "me.example",
|
|
46
|
+
artifactId: "test",
|
|
47
|
+
version: "1.0.0",
|
|
48
|
+
javaVersion: 8,
|
|
49
|
+
repositories: [{
|
|
50
|
+
id: "central",
|
|
51
|
+
url: "https://repo.maven.apache.org/maven2"
|
|
52
|
+
}, {
|
|
53
|
+
id: "central",
|
|
54
|
+
url: "https://repo.maven.apache.org/maven2"
|
|
55
|
+
}],
|
|
56
|
+
pluginRepositories: [{
|
|
57
|
+
id: "central",
|
|
58
|
+
url: "https://repo.maven.apache.org/maven2"
|
|
59
|
+
}, {
|
|
60
|
+
id: "central",
|
|
61
|
+
url: "https://repo.maven.apache.org/maven2"
|
|
62
|
+
}],
|
|
63
|
+
build: {
|
|
64
|
+
plugins: [{
|
|
65
|
+
groupId: "org.apache.maven.plugins",
|
|
66
|
+
artifactId: "maven-compiler-plugin",
|
|
67
|
+
version: "3.8.1",
|
|
68
|
+
executions: [{
|
|
69
|
+
id: "default-compile",
|
|
70
|
+
phase: "compile",
|
|
71
|
+
goals: ["compile", "test"]
|
|
72
|
+
}, {
|
|
73
|
+
id: "default-testCompile",
|
|
74
|
+
phase: "test-compile",
|
|
75
|
+
goals: ["testCompile", "test"]
|
|
76
|
+
}],
|
|
77
|
+
configuration: {
|
|
78
|
+
source: 8,
|
|
79
|
+
target: 8
|
|
80
|
+
}
|
|
81
|
+
}, {
|
|
82
|
+
groupId: "org.apache.maven.plugins",
|
|
83
|
+
artifactId: "maven-compiler-plugin",
|
|
84
|
+
version: "3.8.1",
|
|
85
|
+
executions: [{
|
|
86
|
+
id: "default-compile",
|
|
87
|
+
phase: "compile",
|
|
88
|
+
goals: ["compile", "test"]
|
|
89
|
+
}, {
|
|
90
|
+
id: "default-testCompile",
|
|
91
|
+
phase: "test-compile",
|
|
92
|
+
goals: ["testCompile", "test"]
|
|
93
|
+
}],
|
|
94
|
+
configuration: {
|
|
95
|
+
source: 8,
|
|
96
|
+
target: 8
|
|
97
|
+
}
|
|
98
|
+
}],
|
|
99
|
+
resources: [{
|
|
100
|
+
directory: "src/main/resources",
|
|
101
|
+
filtering: true,
|
|
102
|
+
targetPath: "target/classes",
|
|
103
|
+
includes: ["**/*.properties", "**/*.xml"],
|
|
104
|
+
excludes: ["**/*.xml", "**/*.json"]
|
|
105
|
+
}, {
|
|
106
|
+
directory: "src/main/resources",
|
|
107
|
+
filtering: true,
|
|
108
|
+
targetPath: "target/classes",
|
|
109
|
+
includes: ["**/*.properties", "**/*.xml"],
|
|
110
|
+
excludes: ["**/*.xml", "**/*.json"]
|
|
111
|
+
}]
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
const res = render(_$createComponent(Output, {
|
|
115
|
+
get children() {
|
|
116
|
+
return _$createComponent(ProjectDirectory, {
|
|
117
|
+
name: "TestMavenProject",
|
|
118
|
+
mavenProjectConfig: projectConfig
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}));
|
|
122
|
+
assertFileContents(res, {
|
|
123
|
+
"pom.xml": `
|
|
124
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
125
|
+
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
126
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
127
|
+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
128
|
+
|
|
129
|
+
<modelVersion>4.0.0</modelVersion>
|
|
130
|
+
<groupId>me.example</groupId>
|
|
131
|
+
<artifactId>test</artifactId>
|
|
132
|
+
<version>1.0.0</version>
|
|
133
|
+
|
|
134
|
+
<properties>
|
|
135
|
+
<maven.compiler.source>8</maven.compiler.source>
|
|
136
|
+
<maven.compiler.target>8</maven.compiler.target>
|
|
137
|
+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
138
|
+
</properties>
|
|
139
|
+
|
|
140
|
+
<repositories>
|
|
141
|
+
<repository>
|
|
142
|
+
<id>central</id>
|
|
143
|
+
<url>https://repo.maven.apache.org/maven2</url>
|
|
144
|
+
</repository>
|
|
145
|
+
<repository>
|
|
146
|
+
<id>central</id>
|
|
147
|
+
<url>https://repo.maven.apache.org/maven2</url>
|
|
148
|
+
</repository>
|
|
149
|
+
</repositories>
|
|
150
|
+
|
|
151
|
+
<pluginRepositories>
|
|
152
|
+
<pluginRepository>
|
|
153
|
+
<id>central</id>
|
|
154
|
+
<url>https://repo.maven.apache.org/maven2</url>
|
|
155
|
+
</pluginRepository>
|
|
156
|
+
<pluginRepository>
|
|
157
|
+
<id>central</id>
|
|
158
|
+
<url>https://repo.maven.apache.org/maven2</url>
|
|
159
|
+
</pluginRepository>
|
|
160
|
+
</pluginRepositories>
|
|
161
|
+
|
|
162
|
+
<build>
|
|
163
|
+
<plugins>
|
|
164
|
+
<plugin>
|
|
165
|
+
<groupId>org.apache.maven.plugins</groupId>
|
|
166
|
+
<artifactId>maven-compiler-plugin</artifactId>
|
|
167
|
+
<version>3.8.1</version>
|
|
168
|
+
<executions>
|
|
169
|
+
<execution>
|
|
170
|
+
<id>default-compile</id>
|
|
171
|
+
<phase>compile</phase>
|
|
172
|
+
<goals>
|
|
173
|
+
<goal>compile</goal>
|
|
174
|
+
<goal>test</goal>
|
|
175
|
+
</goals>
|
|
176
|
+
</execution>
|
|
177
|
+
<execution>
|
|
178
|
+
<id>default-testCompile</id>
|
|
179
|
+
<phase>test-compile</phase>
|
|
180
|
+
<goals>
|
|
181
|
+
<goal>testCompile</goal>
|
|
182
|
+
<goal>test</goal>
|
|
183
|
+
</goals>
|
|
184
|
+
</execution>
|
|
185
|
+
</executions>
|
|
186
|
+
<configuration>
|
|
187
|
+
<source>8</source>
|
|
188
|
+
<target>8</target>
|
|
189
|
+
</configuration>
|
|
190
|
+
</plugin>
|
|
191
|
+
<plugin>
|
|
192
|
+
<groupId>org.apache.maven.plugins</groupId>
|
|
193
|
+
<artifactId>maven-compiler-plugin</artifactId>
|
|
194
|
+
<version>3.8.1</version>
|
|
195
|
+
<executions>
|
|
196
|
+
<execution>
|
|
197
|
+
<id>default-compile</id>
|
|
198
|
+
<phase>compile</phase>
|
|
199
|
+
<goals>
|
|
200
|
+
<goal>compile</goal>
|
|
201
|
+
<goal>test</goal>
|
|
202
|
+
</goals>
|
|
203
|
+
</execution>
|
|
204
|
+
<execution>
|
|
205
|
+
<id>default-testCompile</id>
|
|
206
|
+
<phase>test-compile</phase>
|
|
207
|
+
<goals>
|
|
208
|
+
<goal>testCompile</goal>
|
|
209
|
+
<goal>test</goal>
|
|
210
|
+
</goals>
|
|
211
|
+
</execution>
|
|
212
|
+
</executions>
|
|
213
|
+
<configuration>
|
|
214
|
+
<source>8</source>
|
|
215
|
+
<target>8</target>
|
|
216
|
+
</configuration>
|
|
217
|
+
</plugin>
|
|
218
|
+
</plugins>
|
|
219
|
+
<resources>
|
|
220
|
+
<resource>
|
|
221
|
+
<directory>src/main/resources</directory>
|
|
222
|
+
<includes>
|
|
223
|
+
<include>**/*.properties</include>
|
|
224
|
+
<include>**/*.xml</include>
|
|
225
|
+
</includes>
|
|
226
|
+
<excludes>
|
|
227
|
+
<exclude>**/*.xml</exclude>
|
|
228
|
+
<exclude>**/*.json</exclude>
|
|
229
|
+
</excludes>
|
|
230
|
+
<filtering>true</filtering>
|
|
231
|
+
<targetPath>target/classes</targetPath>
|
|
232
|
+
</resource>
|
|
233
|
+
<resource>
|
|
234
|
+
<directory>src/main/resources</directory>
|
|
235
|
+
<includes>
|
|
236
|
+
<include>**/*.properties</include>
|
|
237
|
+
<include>**/*.xml</include>
|
|
238
|
+
</includes>
|
|
239
|
+
<excludes>
|
|
240
|
+
<exclude>**/*.xml</exclude>
|
|
241
|
+
<exclude>**/*.json</exclude>
|
|
242
|
+
</excludes>
|
|
243
|
+
<filtering>true</filtering>
|
|
244
|
+
<targetPath>target/classes</targetPath>
|
|
245
|
+
</resource>
|
|
246
|
+
</resources>
|
|
247
|
+
</build>
|
|
248
|
+
</project>
|
|
249
|
+
`
|
|
250
|
+
});
|
|
251
|
+
});
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import { memo as _$memo, createComponent as _$createComponent, createIntrinsic as _$createIntrinsic } 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 { describe, expect, it } from "vitest";
|
|
5
|
+
import * as jv from "../src/components/index.js";
|
|
6
|
+
import { assertFileContents, testRender, toSourceText } from "./utils.js";
|
|
7
|
+
it("declares basic empty function", () => {
|
|
8
|
+
const res = toSourceText(_$createComponent(jv.Declaration, {
|
|
9
|
+
name: "Test",
|
|
10
|
+
get children() {
|
|
11
|
+
return code`
|
|
12
|
+
class Test {
|
|
13
|
+
${_$createComponent(jv.Method, {
|
|
14
|
+
"public": true,
|
|
15
|
+
name: "testMethod",
|
|
16
|
+
children: "System.out.println(\"Test\");"
|
|
17
|
+
})}
|
|
18
|
+
}
|
|
19
|
+
`;
|
|
20
|
+
}
|
|
21
|
+
}));
|
|
22
|
+
expect(res).toBe(d`
|
|
23
|
+
package me.test.code;
|
|
24
|
+
|
|
25
|
+
class Test {
|
|
26
|
+
public void testMethod() {
|
|
27
|
+
System.out.println("Test");
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
`);
|
|
31
|
+
});
|
|
32
|
+
it("declares bodyless function", () => {
|
|
33
|
+
const res = toSourceText(_$createComponent(jv.Declaration, {
|
|
34
|
+
name: "Test",
|
|
35
|
+
get children() {
|
|
36
|
+
return code`
|
|
37
|
+
class Test {
|
|
38
|
+
${_$createComponent(jv.Method, {
|
|
39
|
+
"public": true,
|
|
40
|
+
name: "testMethod"
|
|
41
|
+
})}
|
|
42
|
+
}
|
|
43
|
+
`;
|
|
44
|
+
}
|
|
45
|
+
}));
|
|
46
|
+
expect(res).toBe(d`
|
|
47
|
+
package me.test.code;
|
|
48
|
+
|
|
49
|
+
class Test {
|
|
50
|
+
public void testMethod();
|
|
51
|
+
}
|
|
52
|
+
`);
|
|
53
|
+
});
|
|
54
|
+
describe("can throw errors", () => {
|
|
55
|
+
it("of generic Exception", () => {
|
|
56
|
+
const res = toSourceText(_$createComponent(jv.Declaration, {
|
|
57
|
+
name: "Test",
|
|
58
|
+
get children() {
|
|
59
|
+
return code`
|
|
60
|
+
class Test {
|
|
61
|
+
${_$createComponent(jv.Method, {
|
|
62
|
+
"public": true,
|
|
63
|
+
name: "testMethod",
|
|
64
|
+
throws: "Exception"
|
|
65
|
+
})}
|
|
66
|
+
}
|
|
67
|
+
`;
|
|
68
|
+
}
|
|
69
|
+
}));
|
|
70
|
+
expect(res).toBe(d`
|
|
71
|
+
package me.test.code;
|
|
72
|
+
|
|
73
|
+
class Test {
|
|
74
|
+
public void testMethod() throws Exception;
|
|
75
|
+
}
|
|
76
|
+
`);
|
|
77
|
+
});
|
|
78
|
+
it("of custom Exception", () => {
|
|
79
|
+
const res = testRender([_$createComponent(jv.SourceFile, {
|
|
80
|
+
path: "Test.java",
|
|
81
|
+
get children() {
|
|
82
|
+
return _$createComponent(jv.Declaration, {
|
|
83
|
+
name: "Test",
|
|
84
|
+
get children() {
|
|
85
|
+
return code`
|
|
86
|
+
class Test {
|
|
87
|
+
${_$createComponent(jv.Method, {
|
|
88
|
+
"public": true,
|
|
89
|
+
name: "testMethod",
|
|
90
|
+
get throws() {
|
|
91
|
+
return refkey("CustomError");
|
|
92
|
+
}
|
|
93
|
+
})}
|
|
94
|
+
}
|
|
95
|
+
`;
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}), _$createComponent(jv.PackageDirectory, {
|
|
100
|
+
"package": "errors",
|
|
101
|
+
get children() {
|
|
102
|
+
return _$createComponent(jv.SourceFile, {
|
|
103
|
+
path: "CustomError.java",
|
|
104
|
+
get children() {
|
|
105
|
+
return _$createComponent(jv.Declaration, {
|
|
106
|
+
name: "CustomError",
|
|
107
|
+
children: code`
|
|
108
|
+
public class CustomError extends Exception {
|
|
109
|
+
}
|
|
110
|
+
`
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
})]);
|
|
116
|
+
assertFileContents(res, {
|
|
117
|
+
"Test.java": d`
|
|
118
|
+
package me.test.code;
|
|
119
|
+
|
|
120
|
+
import me.test.code.errors.CustomError;
|
|
121
|
+
|
|
122
|
+
class Test {
|
|
123
|
+
public void testMethod() throws CustomError;
|
|
124
|
+
}
|
|
125
|
+
`
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
it("declares return type", () => {
|
|
130
|
+
const res = toSourceText(_$createComponent(jv.Declaration, {
|
|
131
|
+
name: "Test",
|
|
132
|
+
get children() {
|
|
133
|
+
return code`
|
|
134
|
+
class Test {
|
|
135
|
+
${_$createComponent(jv.Method, {
|
|
136
|
+
"public": true,
|
|
137
|
+
name: "testMethod",
|
|
138
|
+
"return": "String",
|
|
139
|
+
get children() {
|
|
140
|
+
return ["System.out.println(\"Test\");", _$createIntrinsic("hbr", {}), "return \"Test\";"];
|
|
141
|
+
}
|
|
142
|
+
})}
|
|
143
|
+
}
|
|
144
|
+
`;
|
|
145
|
+
}
|
|
146
|
+
}));
|
|
147
|
+
expect(res).toBe(d`
|
|
148
|
+
package me.test.code;
|
|
149
|
+
|
|
150
|
+
class Test {
|
|
151
|
+
public String testMethod() {
|
|
152
|
+
System.out.println("Test");
|
|
153
|
+
return "Test";
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
`);
|
|
157
|
+
});
|
|
158
|
+
it("declares parameters", () => {
|
|
159
|
+
const res = testRender([_$createComponent(jv.SourceFile, {
|
|
160
|
+
path: "Model.java",
|
|
161
|
+
get children() {
|
|
162
|
+
return _$createComponent(jv.Declaration, {
|
|
163
|
+
name: "Model",
|
|
164
|
+
children: code`
|
|
165
|
+
public class Model {
|
|
166
|
+
}
|
|
167
|
+
`
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
}), _$createComponent(jv.PackageDirectory, {
|
|
171
|
+
"package": "imports",
|
|
172
|
+
get children() {
|
|
173
|
+
return _$createComponent(jv.SourceFile, {
|
|
174
|
+
path: "Test.java",
|
|
175
|
+
get children() {
|
|
176
|
+
return _$createComponent(Declaration, {
|
|
177
|
+
name: "Test",
|
|
178
|
+
get children() {
|
|
179
|
+
return code`
|
|
180
|
+
public class Test {
|
|
181
|
+
${_$createComponent(jv.Method, {
|
|
182
|
+
"public": true,
|
|
183
|
+
name: "testMethod",
|
|
184
|
+
get parameters() {
|
|
185
|
+
return {
|
|
186
|
+
myModel: refkey("Model"),
|
|
187
|
+
name: "String"
|
|
188
|
+
};
|
|
189
|
+
},
|
|
190
|
+
children: "System.out.println(\"Test\");"
|
|
191
|
+
})}
|
|
192
|
+
}
|
|
193
|
+
`;
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
})]);
|
|
200
|
+
assertFileContents(res, {
|
|
201
|
+
"Test.java": d`
|
|
202
|
+
package me.test.code.imports;
|
|
203
|
+
|
|
204
|
+
import me.test.code.Model;
|
|
205
|
+
|
|
206
|
+
public class Test {
|
|
207
|
+
public void testMethod(Model myModel, String name) {
|
|
208
|
+
System.out.println("Test");
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
`
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
it("defines generics", () => {
|
|
215
|
+
const res = testRender([_$createComponent(jv.SourceFile, {
|
|
216
|
+
path: "Model.java",
|
|
217
|
+
get children() {
|
|
218
|
+
return _$createComponent(jv.Declaration, {
|
|
219
|
+
name: "Model",
|
|
220
|
+
children: code`
|
|
221
|
+
public class Model {
|
|
222
|
+
}
|
|
223
|
+
`
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
}), _$createComponent(jv.PackageDirectory, {
|
|
227
|
+
"package": "imports",
|
|
228
|
+
get children() {
|
|
229
|
+
return _$createComponent(jv.SourceFile, {
|
|
230
|
+
path: "Test.java",
|
|
231
|
+
get children() {
|
|
232
|
+
return _$createComponent(Declaration, {
|
|
233
|
+
name: "Test",
|
|
234
|
+
get children() {
|
|
235
|
+
return code`
|
|
236
|
+
public class Test {
|
|
237
|
+
${_$createComponent(jv.Method, {
|
|
238
|
+
"public": true,
|
|
239
|
+
get generics() {
|
|
240
|
+
return {
|
|
241
|
+
T: refkey("Model"),
|
|
242
|
+
N: "String",
|
|
243
|
+
K: ""
|
|
244
|
+
};
|
|
245
|
+
},
|
|
246
|
+
name: "testMethod",
|
|
247
|
+
children: "System.out.println(\"Test\");"
|
|
248
|
+
})}
|
|
249
|
+
}
|
|
250
|
+
`;
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
})]);
|
|
257
|
+
assertFileContents(res, {
|
|
258
|
+
"Test.java": d`
|
|
259
|
+
package me.test.code.imports;
|
|
260
|
+
|
|
261
|
+
import me.test.code.Model;
|
|
262
|
+
|
|
263
|
+
public class Test {
|
|
264
|
+
public <T extends Model, N extends String, K> void testMethod() {
|
|
265
|
+
System.out.println("Test");
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
`
|
|
269
|
+
});
|
|
270
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { expect, it } from "vitest";
|
|
3
|
+
import * as jv from "../src/components/index.js";
|
|
4
|
+
import { findFile, testRender } from "./utils.js";
|
|
5
|
+
it("emits correct package directory", () => {
|
|
6
|
+
const res = testRender([_$createComponent(jv.PackageDirectory, {
|
|
7
|
+
"package": "my.emit.package",
|
|
8
|
+
get children() {
|
|
9
|
+
return _$createComponent(jv.SourceFile, {
|
|
10
|
+
path: "Test.java"
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
})]);
|
|
14
|
+
|
|
15
|
+
// Assert directory file is in is correct
|
|
16
|
+
const testFile = findFile(res, "Test.java");
|
|
17
|
+
expect(testFile.path).toBe("me/test/code/my/emit/package/Test.java");
|
|
18
|
+
});
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { createComponent as _$createComponent, memo as _$memo, createIntrinsic as _$createIntrinsic } from "@alloy-js/core/jsx-runtime";
|
|
2
|
+
import { Block, refkey } from "@alloy-js/core";
|
|
3
|
+
import { it } from "vitest";
|
|
4
|
+
import * as jv from "../src/components/index.js";
|
|
5
|
+
import { assertFileContents, testRender } from "./utils.js";
|
|
6
|
+
it("imports reference to source file", () => {
|
|
7
|
+
const res = testRender([_$createComponent(jv.SourceFile, {
|
|
8
|
+
path: "TestReference.java",
|
|
9
|
+
get children() {
|
|
10
|
+
return _$createComponent(jv.Declaration, {
|
|
11
|
+
name: "TestReference",
|
|
12
|
+
get children() {
|
|
13
|
+
return ["public class TestReference", " ", _$createComponent(Block, {
|
|
14
|
+
get children() {
|
|
15
|
+
return ["public TestReference() ", "{}"];
|
|
16
|
+
}
|
|
17
|
+
})];
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}), _$createComponent(jv.PackageDirectory, {
|
|
22
|
+
"package": "import",
|
|
23
|
+
get children() {
|
|
24
|
+
return _$createComponent(jv.SourceFile, {
|
|
25
|
+
path: "TestImport.java",
|
|
26
|
+
get children() {
|
|
27
|
+
return _$createComponent(jv.Declaration, {
|
|
28
|
+
name: "TestImport",
|
|
29
|
+
get children() {
|
|
30
|
+
return ["public class TestImport", " ", _$createComponent(Block, {
|
|
31
|
+
get children() {
|
|
32
|
+
return [_$memo(() => refkey("TestReference")), " myImportedVariable;", _$createIntrinsic("hbr", {}), "public TestImport() ", "{}"];
|
|
33
|
+
}
|
|
34
|
+
})];
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
})]);
|
|
41
|
+
assertFileContents(res, {
|
|
42
|
+
"TestReference.java": `
|
|
43
|
+
package me.test.code;
|
|
44
|
+
|
|
45
|
+
public class TestReference {
|
|
46
|
+
public TestReference() {}
|
|
47
|
+
}
|
|
48
|
+
`,
|
|
49
|
+
"TestImport.java": `
|
|
50
|
+
package me.test.code.import;
|
|
51
|
+
|
|
52
|
+
import me.test.code.TestReference;
|
|
53
|
+
|
|
54
|
+
public class TestImport {
|
|
55
|
+
TestReference myImportedVariable;
|
|
56
|
+
public TestImport() {}
|
|
57
|
+
}
|
|
58
|
+
`
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
it("doesn't import if in same package", () => {
|
|
62
|
+
const res = testRender([_$createComponent(jv.SourceFile, {
|
|
63
|
+
path: "TestReference.java",
|
|
64
|
+
get children() {
|
|
65
|
+
return _$createComponent(jv.Declaration, {
|
|
66
|
+
name: "TestReference",
|
|
67
|
+
get children() {
|
|
68
|
+
return ["public class TestReference", " ", _$createComponent(Block, {
|
|
69
|
+
get children() {
|
|
70
|
+
return ["public TestReference() ", "{}"];
|
|
71
|
+
}
|
|
72
|
+
})];
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}), _$createComponent(jv.SourceFile, {
|
|
77
|
+
path: "TestImport.java",
|
|
78
|
+
get children() {
|
|
79
|
+
return _$createComponent(jv.Declaration, {
|
|
80
|
+
name: "TestImport",
|
|
81
|
+
get children() {
|
|
82
|
+
return ["public class TestImport", " ", _$createComponent(Block, {
|
|
83
|
+
get children() {
|
|
84
|
+
return [_$memo(() => refkey("TestReference")), " myImportedVariable;", _$createIntrinsic("hbr", {}), "public TestImport() ", "{}"];
|
|
85
|
+
}
|
|
86
|
+
})];
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
})]);
|
|
91
|
+
assertFileContents(res, {
|
|
92
|
+
"TestReference.java": `
|
|
93
|
+
package me.test.code;
|
|
94
|
+
|
|
95
|
+
public class TestReference {
|
|
96
|
+
public TestReference() {}
|
|
97
|
+
}
|
|
98
|
+
`,
|
|
99
|
+
"TestImport.java": `
|
|
100
|
+
package me.test.code;
|
|
101
|
+
|
|
102
|
+
public class TestImport {
|
|
103
|
+
TestReference myImportedVariable;
|
|
104
|
+
public TestImport() {}
|
|
105
|
+
}
|
|
106
|
+
`
|
|
107
|
+
});
|
|
108
|
+
});
|