@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.
Files changed (232) hide show
  1. package/LICENSE.txt +7 -0
  2. package/api-extractor.json +4 -0
  3. package/babel.config.cjs +4 -0
  4. package/dist/src/arguments.d.ts +15 -0
  5. package/dist/src/arguments.d.ts.map +1 -0
  6. package/dist/src/arguments.js +27 -0
  7. package/dist/src/arguments.js.map +1 -0
  8. package/dist/src/builtins/index.d.ts +2 -0
  9. package/dist/src/builtins/index.d.ts.map +1 -0
  10. package/dist/src/builtins/index.js +1 -0
  11. package/dist/src/builtins/index.js.map +1 -0
  12. package/dist/src/builtins/util.d.ts +4 -0
  13. package/dist/src/builtins/util.d.ts.map +1 -0
  14. package/dist/src/builtins/util.js +10 -0
  15. package/dist/src/builtins/util.js.map +1 -0
  16. package/dist/src/components/Annotation.d.ts +11 -0
  17. package/dist/src/components/Annotation.d.ts.map +1 -0
  18. package/dist/src/components/Annotation.js +12 -0
  19. package/dist/src/components/Annotation.js.map +1 -0
  20. package/dist/src/components/Block.d.ts +6 -0
  21. package/dist/src/components/Block.d.ts.map +1 -0
  22. package/dist/src/components/Block.js +4 -0
  23. package/dist/src/components/Block.js.map +1 -0
  24. package/dist/src/components/Class.d.ts +10 -0
  25. package/dist/src/components/Class.d.ts.map +1 -0
  26. package/dist/src/components/Class.js +36 -0
  27. package/dist/src/components/Class.js.map +1 -0
  28. package/dist/src/components/Constructor.d.ts +13 -0
  29. package/dist/src/components/Constructor.d.ts.map +1 -0
  30. package/dist/src/components/Constructor.js +23 -0
  31. package/dist/src/components/Constructor.js.map +1 -0
  32. package/dist/src/components/Declaration.d.ts +12 -0
  33. package/dist/src/components/Declaration.d.ts.map +1 -0
  34. package/dist/src/components/Declaration.js +18 -0
  35. package/dist/src/components/Declaration.js.map +1 -0
  36. package/dist/src/components/Enum.d.ts +13 -0
  37. package/dist/src/components/Enum.d.ts.map +1 -0
  38. package/dist/src/components/Enum.js +38 -0
  39. package/dist/src/components/Enum.js.map +1 -0
  40. package/dist/src/components/Generics.d.ts +6 -0
  41. package/dist/src/components/Generics.d.ts.map +1 -0
  42. package/dist/src/components/Generics.js +8 -0
  43. package/dist/src/components/Generics.js.map +1 -0
  44. package/dist/src/components/ImportStatement.d.ts +11 -0
  45. package/dist/src/components/ImportStatement.d.ts.map +1 -0
  46. package/dist/src/components/ImportStatement.js +9 -0
  47. package/dist/src/components/ImportStatement.js.map +1 -0
  48. package/dist/src/components/Interface.d.ts +9 -0
  49. package/dist/src/components/Interface.d.ts.map +1 -0
  50. package/dist/src/components/Interface.js +35 -0
  51. package/dist/src/components/Interface.js.map +1 -0
  52. package/dist/src/components/MavenProject.d.ts +13 -0
  53. package/dist/src/components/MavenProject.d.ts.map +1 -0
  54. package/dist/src/components/MavenProject.js +159 -0
  55. package/dist/src/components/MavenProject.js.map +1 -0
  56. package/dist/src/components/Method.d.ts +11 -0
  57. package/dist/src/components/Method.d.ts.map +1 -0
  58. package/dist/src/components/Method.js +25 -0
  59. package/dist/src/components/Method.js.map +1 -0
  60. package/dist/src/components/Name.d.ts +2 -0
  61. package/dist/src/components/Name.d.ts.map +1 -0
  62. package/dist/src/components/Name.js +10 -0
  63. package/dist/src/components/Name.js.map +1 -0
  64. package/dist/src/components/ObjectDeclaration.d.ts +13 -0
  65. package/dist/src/components/ObjectDeclaration.d.ts.map +1 -0
  66. package/dist/src/components/ObjectDeclaration.js +17 -0
  67. package/dist/src/components/ObjectDeclaration.js.map +1 -0
  68. package/dist/src/components/PackageDirectory.d.ts +16 -0
  69. package/dist/src/components/PackageDirectory.d.ts.map +1 -0
  70. package/dist/src/components/PackageDirectory.js +58 -0
  71. package/dist/src/components/PackageDirectory.js.map +1 -0
  72. package/dist/src/components/Parameters.d.ts +11 -0
  73. package/dist/src/components/Parameters.d.ts.map +1 -0
  74. package/dist/src/components/Parameters.js +17 -0
  75. package/dist/src/components/Parameters.js.map +1 -0
  76. package/dist/src/components/ProjectDirectory.d.ts +23 -0
  77. package/dist/src/components/ProjectDirectory.d.ts.map +1 -0
  78. package/dist/src/components/ProjectDirectory.js +42 -0
  79. package/dist/src/components/ProjectDirectory.js.map +1 -0
  80. package/dist/src/components/Reference.d.ts +6 -0
  81. package/dist/src/components/Reference.d.ts.map +1 -0
  82. package/dist/src/components/Reference.js +6 -0
  83. package/dist/src/components/Reference.js.map +1 -0
  84. package/dist/src/components/SourceFile.d.ts +17 -0
  85. package/dist/src/components/SourceFile.d.ts.map +1 -0
  86. package/dist/src/components/SourceFile.js +70 -0
  87. package/dist/src/components/SourceFile.js.map +1 -0
  88. package/dist/src/components/Value.d.ts +5 -0
  89. package/dist/src/components/Value.d.ts.map +1 -0
  90. package/dist/src/components/Value.js +17 -0
  91. package/dist/src/components/Value.js.map +1 -0
  92. package/dist/src/components/Variable.d.ts +9 -0
  93. package/dist/src/components/Variable.d.ts.map +1 -0
  94. package/dist/src/components/Variable.js +9 -0
  95. package/dist/src/components/Variable.js.map +1 -0
  96. package/dist/src/components/index.d.ts +21 -0
  97. package/dist/src/components/index.d.ts.map +1 -0
  98. package/dist/src/components/index.js +21 -0
  99. package/dist/src/components/index.js.map +1 -0
  100. package/dist/src/components/stc/index.d.ts +86 -0
  101. package/dist/src/components/stc/index.d.ts.map +1 -0
  102. package/dist/src/components/stc/index.js +24 -0
  103. package/dist/src/components/stc/index.js.map +1 -0
  104. package/dist/src/create-library.d.ts +15 -0
  105. package/dist/src/create-library.d.ts.map +1 -0
  106. package/dist/src/create-library.js +34 -0
  107. package/dist/src/create-library.js.map +1 -0
  108. package/dist/src/generics.d.ts +28 -0
  109. package/dist/src/generics.d.ts.map +1 -0
  110. package/dist/src/generics.js +51 -0
  111. package/dist/src/generics.js.map +1 -0
  112. package/dist/src/index.d.ts +9 -0
  113. package/dist/src/index.d.ts.map +1 -0
  114. package/dist/src/index.js +9 -0
  115. package/dist/src/index.js.map +1 -0
  116. package/dist/src/name-policy.d.ts +5 -0
  117. package/dist/src/name-policy.d.ts.map +1 -0
  118. package/dist/src/name-policy.js +21 -0
  119. package/dist/src/name-policy.js.map +1 -0
  120. package/dist/src/object-modifiers.d.ts +24 -0
  121. package/dist/src/object-modifiers.d.ts.map +1 -0
  122. package/dist/src/object-modifiers.js +31 -0
  123. package/dist/src/object-modifiers.js.map +1 -0
  124. package/dist/src/symbols/index.d.ts +6 -0
  125. package/dist/src/symbols/index.d.ts.map +1 -0
  126. package/dist/src/symbols/index.js +6 -0
  127. package/dist/src/symbols/index.js.map +1 -0
  128. package/dist/src/symbols/java-output-symbol.d.ts +14 -0
  129. package/dist/src/symbols/java-output-symbol.d.ts.map +1 -0
  130. package/dist/src/symbols/java-output-symbol.js +21 -0
  131. package/dist/src/symbols/java-output-symbol.js.map +1 -0
  132. package/dist/src/symbols/java-package-scope.d.ts +6 -0
  133. package/dist/src/symbols/java-package-scope.d.ts.map +1 -0
  134. package/dist/src/symbols/java-package-scope.js +8 -0
  135. package/dist/src/symbols/java-package-scope.js.map +1 -0
  136. package/dist/src/symbols/java-project-scope.d.ts +67 -0
  137. package/dist/src/symbols/java-project-scope.d.ts.map +1 -0
  138. package/dist/src/symbols/java-project-scope.js +29 -0
  139. package/dist/src/symbols/java-project-scope.js.map +1 -0
  140. package/dist/src/symbols/reference.d.ts +8 -0
  141. package/dist/src/symbols/reference.d.ts.map +1 -0
  142. package/dist/src/symbols/reference.js +21 -0
  143. package/dist/src/symbols/reference.js.map +1 -0
  144. package/dist/src/symbols/scopes.d.ts +4 -0
  145. package/dist/src/symbols/scopes.d.ts.map +1 -0
  146. package/dist/src/symbols/scopes.js +1 -0
  147. package/dist/src/symbols/scopes.js.map +1 -0
  148. package/dist/test/annotation.test.d.ts +2 -0
  149. package/dist/test/annotation.test.d.ts.map +1 -0
  150. package/dist/test/class.test.d.ts +2 -0
  151. package/dist/test/class.test.d.ts.map +1 -0
  152. package/dist/test/constructor.test.d.ts +2 -0
  153. package/dist/test/constructor.test.d.ts.map +1 -0
  154. package/dist/test/enum.test.d.ts +2 -0
  155. package/dist/test/enum.test.d.ts.map +1 -0
  156. package/dist/test/externals.test.d.ts +2 -0
  157. package/dist/test/externals.test.d.ts.map +1 -0
  158. package/dist/test/generics.d.ts +2 -0
  159. package/dist/test/generics.d.ts.map +1 -0
  160. package/dist/test/interface.test.d.ts +2 -0
  161. package/dist/test/interface.test.d.ts.map +1 -0
  162. package/dist/test/maven.d.ts +2 -0
  163. package/dist/test/maven.d.ts.map +1 -0
  164. package/dist/test/method.test.d.ts +2 -0
  165. package/dist/test/method.test.d.ts.map +1 -0
  166. package/dist/test/package.test.d.ts +2 -0
  167. package/dist/test/package.test.d.ts.map +1 -0
  168. package/dist/test/reference.test.d.ts +2 -0
  169. package/dist/test/reference.test.d.ts.map +1 -0
  170. package/dist/test/utils.d.ts +6 -0
  171. package/dist/test/utils.d.ts.map +1 -0
  172. package/dist/test/values.test.d.ts +2 -0
  173. package/dist/test/values.test.d.ts.map +1 -0
  174. package/dist/test/variables.test.d.ts +2 -0
  175. package/dist/test/variables.test.d.ts.map +1 -0
  176. package/dist/tsconfig.tsbuildinfo +1 -0
  177. package/package.json +49 -0
  178. package/src/arguments.ts +30 -0
  179. package/src/builtins/index.ts +1 -0
  180. package/src/builtins/util.ts +117 -0
  181. package/src/components/Annotation.tsx +23 -0
  182. package/src/components/Block.tsx +8 -0
  183. package/src/components/Class.tsx +33 -0
  184. package/src/components/Constructor.tsx +25 -0
  185. package/src/components/Declaration.tsx +24 -0
  186. package/src/components/Enum.tsx +40 -0
  187. package/src/components/Generics.tsx +12 -0
  188. package/src/components/ImportStatement.tsx +21 -0
  189. package/src/components/Interface.tsx +31 -0
  190. package/src/components/MavenProject.tsx +151 -0
  191. package/src/components/Method.tsx +31 -0
  192. package/src/components/Name.tsx +10 -0
  193. package/src/components/ObjectDeclaration.tsx +22 -0
  194. package/src/components/PackageDirectory.tsx +84 -0
  195. package/src/components/Parameters.tsx +21 -0
  196. package/src/components/ProjectDirectory.tsx +76 -0
  197. package/src/components/Reference.tsx +12 -0
  198. package/src/components/SourceFile.tsx +84 -0
  199. package/src/components/Value.tsx +22 -0
  200. package/src/components/Variable.tsx +16 -0
  201. package/src/components/index.ts +20 -0
  202. package/src/components/stc/index.ts +24 -0
  203. package/src/create-library.ts +67 -0
  204. package/src/generics.ts +59 -0
  205. package/src/index.ts +8 -0
  206. package/src/name-policy.ts +33 -0
  207. package/src/object-modifiers.ts +48 -0
  208. package/src/symbols/index.ts +5 -0
  209. package/src/symbols/java-output-symbol.ts +30 -0
  210. package/src/symbols/java-package-scope.ts +17 -0
  211. package/src/symbols/java-project-scope.ts +104 -0
  212. package/src/symbols/reference.ts +24 -0
  213. package/src/symbols/scopes.ts +4 -0
  214. package/temp/api.json +5805 -0
  215. package/test/annotation.test.tsx +56 -0
  216. package/test/class.test.tsx +133 -0
  217. package/test/constructor.test.tsx +96 -0
  218. package/test/enum.test.tsx +105 -0
  219. package/test/externals.test.tsx +46 -0
  220. package/test/generics.tsx +58 -0
  221. package/test/interface.test.tsx +84 -0
  222. package/test/maven.tsx +261 -0
  223. package/test/method.test.tsx +162 -0
  224. package/test/package.test.tsx +18 -0
  225. package/test/reference.test.tsx +88 -0
  226. package/test/utils.tsx +72 -0
  227. package/test/values.test.tsx +29 -0
  228. package/test/variables.test.tsx +101 -0
  229. package/test/vitest.d.ts +10 -0
  230. package/tsconfig.json +11 -0
  231. package/tsdoc-metadata.json +11 -0
  232. package/vitest.config.ts +18 -0
package/test/maven.tsx ADDED
@@ -0,0 +1,261 @@
1
+ import { Output, render } from "@alloy-js/core";
2
+ import { it } from "vitest";
3
+ import { ProjectDirectory } from "../src/components/index.js";
4
+ import { MavenProjectConfig } from "../src/index.js";
5
+ import { assertFileContents } from "./utils.js";
6
+
7
+ it("generates barebones pom.xml file", () => {
8
+ const projectConfig: MavenProjectConfig = {
9
+ groupId: "me.example",
10
+ artifactId: "test",
11
+ version: "1.0.0",
12
+ javaVersion: 8,
13
+ };
14
+
15
+ const res = render(
16
+ <Output>
17
+ <ProjectDirectory name='TestMavenProject' mavenProjectConfig={projectConfig}>
18
+ </ProjectDirectory>
19
+ </Output>,
20
+ );
21
+
22
+ assertFileContents(res, {
23
+ "pom.xml": `
24
+ <?xml version="1.0" encoding="UTF-8"?>
25
+ <project xmlns="http://maven.apache.org/POM/4.0.0"
26
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
27
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
28
+
29
+ <modelVersion>4.0.0</modelVersion>
30
+ <groupId>me.example</groupId>
31
+ <artifactId>test</artifactId>
32
+ <version>1.0.0</version>
33
+
34
+ <properties>
35
+ <maven.compiler.source>8</maven.compiler.source>
36
+ <maven.compiler.target>8</maven.compiler.target>
37
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
38
+ </properties>
39
+
40
+ </project>
41
+ `,
42
+ });
43
+ });
44
+
45
+ it("generates complex configuration", () => {
46
+ // Some fields are duplicate, just to show it can handle array data
47
+ const projectConfig: MavenProjectConfig = {
48
+ groupId: "me.example",
49
+ artifactId: "test",
50
+ version: "1.0.0",
51
+ javaVersion: 8,
52
+ repositories: [
53
+ { id: "central", url: "https://repo.maven.apache.org/maven2" },
54
+ { id: "central", url: "https://repo.maven.apache.org/maven2" },
55
+ ],
56
+ pluginRepositories: [
57
+ { id: "central", url: "https://repo.maven.apache.org/maven2" },
58
+ { id: "central", url: "https://repo.maven.apache.org/maven2" },
59
+ ],
60
+ build: {
61
+ plugins: [
62
+ {
63
+ groupId: "org.apache.maven.plugins",
64
+ artifactId: "maven-compiler-plugin",
65
+ version: "3.8.1",
66
+ executions: [
67
+ {
68
+ id: "default-compile",
69
+ phase: "compile",
70
+ goals: ["compile", "test"],
71
+ },
72
+ {
73
+ id: "default-testCompile",
74
+ phase: "test-compile",
75
+ goals: ["testCompile", "test"],
76
+ },
77
+ ],
78
+ configuration: {
79
+ source: 8,
80
+ target: 8,
81
+ },
82
+ },
83
+ {
84
+ groupId: "org.apache.maven.plugins",
85
+ artifactId: "maven-compiler-plugin",
86
+ version: "3.8.1",
87
+ executions: [
88
+ {
89
+ id: "default-compile",
90
+ phase: "compile",
91
+ goals: ["compile", "test"],
92
+ },
93
+ {
94
+ id: "default-testCompile",
95
+ phase: "test-compile",
96
+ goals: ["testCompile", "test"],
97
+ },
98
+ ],
99
+ configuration: {
100
+ source: 8,
101
+ target: 8,
102
+ },
103
+ },
104
+ ],
105
+ resources: [
106
+ {
107
+ directory: "src/main/resources",
108
+ filtering: true,
109
+ targetPath: "target/classes",
110
+ includes: ["**/*.properties", "**/*.xml"],
111
+ excludes: ["**/*.xml", "**/*.json"],
112
+ },
113
+ {
114
+ directory: "src/main/resources",
115
+ filtering: true,
116
+ targetPath: "target/classes",
117
+ includes: ["**/*.properties", "**/*.xml"],
118
+ excludes: ["**/*.xml", "**/*.json"],
119
+ },
120
+ ],
121
+ },
122
+ };
123
+
124
+ const res = render(
125
+ <Output>
126
+ <ProjectDirectory name='TestMavenProject' mavenProjectConfig={projectConfig}>
127
+ </ProjectDirectory>
128
+ </Output>,
129
+ );
130
+
131
+ assertFileContents(res, {
132
+ "pom.xml": `
133
+ <?xml version="1.0" encoding="UTF-8"?>
134
+ <project xmlns="http://maven.apache.org/POM/4.0.0"
135
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
136
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
137
+
138
+ <modelVersion>4.0.0</modelVersion>
139
+ <groupId>me.example</groupId>
140
+ <artifactId>test</artifactId>
141
+ <version>1.0.0</version>
142
+
143
+ <properties>
144
+ <maven.compiler.source>8</maven.compiler.source>
145
+ <maven.compiler.target>8</maven.compiler.target>
146
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
147
+ </properties>
148
+
149
+ <repositories>
150
+ <repository>
151
+ <id>central</id>
152
+ <url>https://repo.maven.apache.org/maven2</url>
153
+ </repository>
154
+ <repository>
155
+ <id>central</id>
156
+ <url>https://repo.maven.apache.org/maven2</url>
157
+ </repository>
158
+ </repositories>
159
+
160
+ <pluginRepositories>
161
+ <pluginRepository>
162
+ <id>central</id>
163
+ <url>https://repo.maven.apache.org/maven2</url>
164
+ </pluginRepository>
165
+ <pluginRepository>
166
+ <id>central</id>
167
+ <url>https://repo.maven.apache.org/maven2</url>
168
+ </pluginRepository>
169
+ </pluginRepositories>
170
+
171
+ <build>
172
+ <plugins>
173
+ <plugin>
174
+ <groupId>org.apache.maven.plugins</groupId>
175
+ <artifactId>maven-compiler-plugin</artifactId>
176
+ <version>3.8.1</version>
177
+ <executions>
178
+ <execution>
179
+ <id>default-compile</id>
180
+ <phase>compile</phase>
181
+ <goals>
182
+ <goal>compile</goal>
183
+ <goal>test</goal>
184
+ </goals>
185
+ </execution>
186
+ <execution>
187
+ <id>default-testCompile</id>
188
+ <phase>test-compile</phase>
189
+ <goals>
190
+ <goal>testCompile</goal>
191
+ <goal>test</goal>
192
+ </goals>
193
+ </execution>
194
+ </executions>
195
+ <configuration>
196
+ <source>8</source>
197
+ <target>8</target>
198
+ </configuration>
199
+ </plugin>
200
+ <plugin>
201
+ <groupId>org.apache.maven.plugins</groupId>
202
+ <artifactId>maven-compiler-plugin</artifactId>
203
+ <version>3.8.1</version>
204
+ <executions>
205
+ <execution>
206
+ <id>default-compile</id>
207
+ <phase>compile</phase>
208
+ <goals>
209
+ <goal>compile</goal>
210
+ <goal>test</goal>
211
+ </goals>
212
+ </execution>
213
+ <execution>
214
+ <id>default-testCompile</id>
215
+ <phase>test-compile</phase>
216
+ <goals>
217
+ <goal>testCompile</goal>
218
+ <goal>test</goal>
219
+ </goals>
220
+ </execution>
221
+ </executions>
222
+ <configuration>
223
+ <source>8</source>
224
+ <target>8</target>
225
+ </configuration>
226
+ </plugin>
227
+ </plugins>
228
+ <resources>
229
+ <resource>
230
+ <directory>src/main/resources</directory>
231
+ <includes>
232
+ <include>**/*.properties</include>
233
+ <include>**/*.xml</include>
234
+ </includes>
235
+ <excludes>
236
+ <exclude>**/*.xml</exclude>
237
+ <exclude>**/*.json</exclude>
238
+ </excludes>
239
+ <filtering>true</filtering>
240
+ <targetPath>target/classes</targetPath>
241
+ </resource>
242
+ <resource>
243
+ <directory>src/main/resources</directory>
244
+ <includes>
245
+ <include>**/*.properties</include>
246
+ <include>**/*.xml</include>
247
+ </includes>
248
+ <excludes>
249
+ <exclude>**/*.xml</exclude>
250
+ <exclude>**/*.json</exclude>
251
+ </excludes>
252
+ <filtering>true</filtering>
253
+ <targetPath>target/classes</targetPath>
254
+ </resource>
255
+ </resources>
256
+ </build>
257
+
258
+ </project>
259
+ `,
260
+ });
261
+ });
@@ -0,0 +1,162 @@
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("declares basic empty function", () => {
8
+ const res = toSourceText(
9
+ <jv.Declaration name="Test">
10
+ {code`
11
+ class Test {
12
+ ${<jv.Method public name="testMethod">
13
+ System.out.println("Test");
14
+ </jv.Method>}
15
+ }
16
+ `}
17
+ </jv.Declaration>,
18
+ );
19
+
20
+ expect(res).toBe(d`
21
+ package me.test.code;
22
+
23
+ class Test {
24
+ public void testMethod() {
25
+ System.out.println("Test");
26
+ }
27
+ }
28
+ `);
29
+ });
30
+
31
+ it("declares bodyless function", () => {
32
+ const res = toSourceText(
33
+ <jv.Declaration name="Test">
34
+ {code`
35
+ class Test {
36
+ ${<jv.Method public name="testMethod" />}
37
+ }
38
+ `}
39
+ </jv.Declaration>,
40
+ );
41
+
42
+ expect(res).toBe(d`
43
+ package me.test.code;
44
+
45
+ class Test {
46
+ public void testMethod();
47
+ }
48
+ `);
49
+ });
50
+
51
+ it("declares return type", () => {
52
+ const res = toSourceText(
53
+ <jv.Declaration name="Test">
54
+ {code`
55
+ class Test {
56
+ ${<jv.Method public name="testMethod" return='String'>
57
+ System.out.println("Test");
58
+ return "Test";
59
+ </jv.Method>}
60
+ }
61
+ `}
62
+ </jv.Declaration>,
63
+ );
64
+
65
+ expect(res).toBe(d`
66
+ package me.test.code;
67
+
68
+ class Test {
69
+ public String testMethod() {
70
+ System.out.println("Test");
71
+ return "Test";
72
+ }
73
+ }
74
+ `);
75
+ });
76
+
77
+ it("declares parameters", () => {
78
+ const res = testRender(
79
+ <>
80
+ <jv.SourceFile path="Model.java">
81
+ <jv.Declaration name='Model'>
82
+ {code`
83
+ public class Model {
84
+ }
85
+ `}
86
+ </jv.Declaration>
87
+ </jv.SourceFile>
88
+ <jv.PackageDirectory package='imports'>
89
+ <jv.SourceFile path="Test.java">
90
+ <Declaration name="Test">
91
+ {code`
92
+ public class Test {
93
+ ${<jv.Method public name="testMethod" parameters={{
94
+ myModel: refkey("Model"),
95
+ name: "String"
96
+ }}>
97
+ System.out.println("Test");
98
+ </jv.Method>}
99
+ }
100
+ `}
101
+ </Declaration>
102
+ </jv.SourceFile>
103
+ </jv.PackageDirectory>
104
+ </>,
105
+ );
106
+
107
+ assertFileContents(res, {
108
+ "Test.java": d`
109
+ package me.test.code.imports;
110
+
111
+ import me.test.code.Model;
112
+
113
+ public class Test {
114
+ public void testMethod(Model myModel, String name) {
115
+ System.out.println("Test");
116
+ }
117
+ }
118
+ `,
119
+ });
120
+ });
121
+
122
+ it("defines generics", () => {
123
+ const res = testRender(
124
+ <>
125
+ <jv.SourceFile path="Model.java">
126
+ <jv.Declaration name='Model'>
127
+ {code`
128
+ public class Model {
129
+ }
130
+ `}
131
+ </jv.Declaration>
132
+ </jv.SourceFile>
133
+ <jv.PackageDirectory package='imports'>
134
+ <jv.SourceFile path="Test.java">
135
+ <Declaration name="Test">
136
+ {code`
137
+ public class Test {
138
+ ${<jv.Method public generics={{ T: refkey("Model"), N: 'String', K: ''}} name="testMethod">
139
+ System.out.println("Test");
140
+ </jv.Method>}
141
+ }
142
+ `}
143
+ </Declaration>
144
+ </jv.SourceFile>
145
+ </jv.PackageDirectory>
146
+ </>,
147
+ );
148
+
149
+ assertFileContents(res, {
150
+ "Test.java": d`
151
+ package me.test.code.imports;
152
+
153
+ import me.test.code.Model;
154
+
155
+ public class Test {
156
+ public <T extends Model, N extends String, K> void testMethod() {
157
+ System.out.println("Test");
158
+ }
159
+ }
160
+ `,
161
+ });
162
+ });
@@ -0,0 +1,18 @@
1
+ import { expect, it } from "vitest";
2
+ import * as jv from "../src/components/index.js";
3
+ import { findFile, testRender } from "./utils.js";
4
+
5
+ it("emits correct package directory", () => {
6
+ const res = testRender(
7
+ <>
8
+ <jv.PackageDirectory package='my.emit.package'>
9
+ <jv.SourceFile path="Test.java">
10
+ </jv.SourceFile>
11
+ </jv.PackageDirectory>
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,88 @@
1
+ import { refkey } from "@alloy-js/core";
2
+ import { it } from "vitest";
3
+ import * as jv from "../src/components/index.js";
4
+ import { assertFileContents, testRender } from "./utils.js";
5
+
6
+ it("imports reference to source file", () => {
7
+ const res = testRender(
8
+ <>
9
+ <jv.SourceFile path="TestReference.java">
10
+ <jv.Declaration name="TestReference">
11
+ public class TestReference {"{"}
12
+ public TestReference() {"{}"}
13
+ {"}"}
14
+ </jv.Declaration>
15
+ </jv.SourceFile>
16
+ <jv.PackageDirectory package='import'>
17
+ <jv.SourceFile path="TestImport.java">
18
+ <jv.Declaration name="TestImport">
19
+ public class TestImport {"{"}
20
+ {refkey("TestReference")} myImportedVariable;
21
+ public TestImport() {"{}"}
22
+ {"}"}
23
+ </jv.Declaration>
24
+ </jv.SourceFile>
25
+ </jv.PackageDirectory>
26
+ </>,
27
+ );
28
+
29
+ assertFileContents(res, {
30
+ "TestReference.java": `
31
+ package me.test.code;
32
+
33
+ public class TestReference {
34
+ public TestReference() {}
35
+ }
36
+ `,
37
+ "TestImport.java": `
38
+ package me.test.code.import;
39
+
40
+ import me.test.code.TestReference;
41
+
42
+ public class TestImport {
43
+ TestReference myImportedVariable;
44
+ public TestImport() {}
45
+ }
46
+ `,
47
+ });
48
+ });
49
+
50
+ it("doesn't import if in same package", () => {
51
+ const res = testRender(
52
+ <>
53
+ <jv.SourceFile path="TestReference.java">
54
+ <jv.Declaration name="TestReference">
55
+ public class TestReference {"{"}
56
+ public TestReference() {"{}"}
57
+ {"}"}
58
+ </jv.Declaration>
59
+ </jv.SourceFile>
60
+ <jv.SourceFile path="TestImport.java">
61
+ <jv.Declaration name="TestImport">
62
+ public class TestImport {"{"}
63
+ {refkey("TestReference")} myImportedVariable;
64
+ public TestImport() {"{}"}
65
+ {"}"}
66
+ </jv.Declaration>
67
+ </jv.SourceFile>
68
+ </>,
69
+ );
70
+
71
+ assertFileContents(res, {
72
+ "TestReference.java": `
73
+ package me.test.code;
74
+
75
+ public class TestReference {
76
+ public TestReference() {}
77
+ }
78
+ `,
79
+ "TestImport.java": `
80
+ package me.test.code;
81
+
82
+ public class TestImport {
83
+ TestReference myImportedVariable;
84
+ public TestImport() {}
85
+ }
86
+ `,
87
+ });
88
+ });
package/test/utils.tsx ADDED
@@ -0,0 +1,72 @@
1
+ import {
2
+ Children,
3
+ Output,
4
+ OutputDirectory,
5
+ OutputFile,
6
+ render,
7
+ } from "@alloy-js/core";
8
+ import { dedent } from "@alloy-js/core/testing";
9
+ import { expect } from "vitest";
10
+ import * as jv from "../src/index.js";
11
+
12
+ export function toSourceText(c: Children): string {
13
+ const res = render(
14
+ <Output>
15
+ <jv.PackageDirectory package='me.test.code'>
16
+ <jv.SourceFile path="Test.java">{c}</jv.SourceFile>
17
+ </jv.PackageDirectory>
18
+ </Output>,
19
+ );
20
+
21
+ const file = findFile(res, "Test.java");
22
+ return file.contents;
23
+ }
24
+
25
+ export function testRender(c: Children): OutputDirectory {
26
+ return render(
27
+ <Output>
28
+ <jv.PackageDirectory package='me.test.code'>
29
+ {c}
30
+ </jv.PackageDirectory>
31
+ </Output>,
32
+ );
33
+ }
34
+
35
+ export function findFile(res: OutputDirectory, path: string): OutputFile {
36
+ const result = findFileWorker(res, path);
37
+
38
+ if (!result) {
39
+ throw new Error("Expected to find file " + path);
40
+ }
41
+ return result;
42
+
43
+ function findFileWorker(
44
+ res: OutputDirectory,
45
+ path: string,
46
+ ): OutputFile | null {
47
+ for (const item of res.contents) {
48
+ if (item.kind === "file") {
49
+ if (item.path.includes(path)) {
50
+ return item;
51
+ }
52
+ continue;
53
+ } else {
54
+ const found = findFileWorker(item, path);
55
+ if (found) {
56
+ return found;
57
+ }
58
+ }
59
+ }
60
+ return null;
61
+ }
62
+ }
63
+
64
+ export function assertFileContents(
65
+ res: OutputDirectory,
66
+ expectedFiles: Record<string, string>,
67
+ ) {
68
+ for (const [path, contents] of Object.entries(expectedFiles)) {
69
+ const file = findFile(res, path);
70
+ expect(file.contents).toBe(dedent(contents));
71
+ }
72
+ }
@@ -0,0 +1,29 @@
1
+ import "@alloy-js/core/testing";
2
+ import { expect, it } from "vitest";
3
+ import * as jv from "../src/components/index.js";
4
+
5
+ it("renders string value", () => {
6
+ expect(<jv.Value value={"Test"} />).toRenderTo('"Test"');
7
+ });
8
+
9
+ it("renders null/undefined object", () => {
10
+ expect(<jv.Value value={undefined} />).toRenderTo("null");
11
+ });
12
+
13
+ it("renders number", () => {
14
+ expect(<jv.Value value={123} />).toRenderTo("123");
15
+ });
16
+
17
+ it("renders boolean", () => {
18
+ expect(<jv.Value value={true} />).toRenderTo("true");
19
+ });
20
+
21
+ it("renders other objects", () => {
22
+ function Test() {
23
+ return <>
24
+ Test
25
+ </>;
26
+ }
27
+
28
+ expect(<jv.Value value={Test} />).toRenderTo("Test");
29
+ });