@alloy-js/java 0.9.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.
Files changed (95) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/src/builtins/util.js +1 -2
  3. package/dist/src/components/Annotation.js +2 -4
  4. package/dist/src/components/ArgumentList.js +2 -5
  5. package/dist/src/components/Class.js +2 -6
  6. package/dist/src/components/Constructor.js +2 -4
  7. package/dist/src/components/Declaration.js +1 -2
  8. package/dist/src/components/Enum.js +2 -5
  9. package/dist/src/components/ExtendsClause.js +2 -5
  10. package/dist/src/components/ImplementsClause.js +2 -5
  11. package/dist/src/components/ImportStatement.js +1 -2
  12. package/dist/src/components/Interface.js +2 -5
  13. package/dist/src/components/MavenProject.js +2 -6
  14. package/dist/src/components/Method.js +1 -2
  15. package/dist/src/components/Modifiers.js +1 -2
  16. package/dist/src/components/Name.js +1 -2
  17. package/dist/src/components/NamedArgumentList.js +2 -4
  18. package/dist/src/components/ObjectDeclaration.js +2 -4
  19. package/dist/src/components/PackageDirectory.js +2 -4
  20. package/dist/src/components/Parameters.js +1 -2
  21. package/dist/src/components/ProjectDirectory.js +2 -4
  22. package/dist/src/components/Reference.js +1 -2
  23. package/dist/src/components/SourceFile.js +2 -5
  24. package/dist/src/components/TypeArguments.js +2 -5
  25. package/dist/src/components/TypeParameters.js +2 -5
  26. package/dist/src/components/Value.js +1 -2
  27. package/dist/src/components/Variable.js +1 -2
  28. package/dist/src/components/index.js +1 -2
  29. package/dist/src/components/stc/index.js +1 -2
  30. package/dist/src/create-library.js +1 -2
  31. package/dist/src/index.js +1 -2
  32. package/dist/src/name-policy.js +1 -2
  33. package/dist/src/symbols/index.js +1 -2
  34. package/dist/src/symbols/java-output-symbol.js +1 -2
  35. package/dist/src/symbols/java-package-scope.js +1 -2
  36. package/dist/src/symbols/java-project-scope.js +1 -2
  37. package/dist/src/symbols/reference.js +1 -2
  38. package/dist/test/annotation.test.js +77 -0
  39. package/dist/test/class.test.js +164 -0
  40. package/dist/test/constructor.test.js +101 -0
  41. package/dist/test/enum.test.js +136 -0
  42. package/dist/test/externals.test.js +72 -0
  43. package/dist/test/interface.test.js +110 -0
  44. package/dist/test/maven.test.js +251 -0
  45. package/dist/test/method.test.js +270 -0
  46. package/dist/test/package.test.js +18 -0
  47. package/dist/test/reference.test.js +108 -0
  48. package/dist/test/type-arguments.test.js +83 -0
  49. package/dist/test/utils.js +61 -0
  50. package/dist/test/values.test.js +32 -0
  51. package/dist/test/variables.test.js +143 -0
  52. package/dist/test/vitest.d.js +1 -0
  53. package/dist/tsconfig.tsbuildinfo +1 -1
  54. package/package.json +12 -17
  55. package/temp/api.json +1 -1
  56. package/tsdoc-metadata.json +1 -1
  57. package/babel.config.cjs +0 -4
  58. package/dist/src/builtins/index.js.map +0 -1
  59. package/dist/src/builtins/util.js.map +0 -1
  60. package/dist/src/components/Annotation.js.map +0 -1
  61. package/dist/src/components/ArgumentList.js.map +0 -1
  62. package/dist/src/components/Class.js.map +0 -1
  63. package/dist/src/components/Constructor.js.map +0 -1
  64. package/dist/src/components/Declaration.js.map +0 -1
  65. package/dist/src/components/Enum.js.map +0 -1
  66. package/dist/src/components/ExtendsClause.js.map +0 -1
  67. package/dist/src/components/ImplementsClause.js.map +0 -1
  68. package/dist/src/components/ImportStatement.js.map +0 -1
  69. package/dist/src/components/Interface.js.map +0 -1
  70. package/dist/src/components/MavenProject.js.map +0 -1
  71. package/dist/src/components/Method.js.map +0 -1
  72. package/dist/src/components/Modifiers.js.map +0 -1
  73. package/dist/src/components/Name.js.map +0 -1
  74. package/dist/src/components/NamedArgumentList.js.map +0 -1
  75. package/dist/src/components/ObjectDeclaration.js.map +0 -1
  76. package/dist/src/components/PackageDirectory.js.map +0 -1
  77. package/dist/src/components/Parameters.js.map +0 -1
  78. package/dist/src/components/ProjectDirectory.js.map +0 -1
  79. package/dist/src/components/Reference.js.map +0 -1
  80. package/dist/src/components/SourceFile.js.map +0 -1
  81. package/dist/src/components/TypeArguments.js.map +0 -1
  82. package/dist/src/components/TypeParameters.js.map +0 -1
  83. package/dist/src/components/Value.js.map +0 -1
  84. package/dist/src/components/Variable.js.map +0 -1
  85. package/dist/src/components/index.js.map +0 -1
  86. package/dist/src/components/stc/index.js.map +0 -1
  87. package/dist/src/create-library.js.map +0 -1
  88. package/dist/src/index.js.map +0 -1
  89. package/dist/src/name-policy.js.map +0 -1
  90. package/dist/src/symbols/index.js.map +0 -1
  91. package/dist/src/symbols/java-output-symbol.js.map +0 -1
  92. package/dist/src/symbols/java-package-scope.js.map +0 -1
  93. package/dist/src/symbols/java-project-scope.js.map +0 -1
  94. package/dist/src/symbols/reference.js.map +0 -1
  95. package/dist/src/symbols/scopes.js.map +0 -1
@@ -0,0 +1,83 @@
1
+ import { createComponent as _$createComponent, memo as _$memo } from "@alloy-js/core/jsx-runtime";
2
+ import { code, refkey } from "@alloy-js/core";
3
+ import { d } from "@alloy-js/core/testing";
4
+ import { it } from "vitest";
5
+ import * as jv from "../src/components/index.js";
6
+ import { assertFileContents, testRender } from "./utils.js";
7
+ it("passes types", () => {
8
+ const res = testRender([_$createComponent(jv.SourceFile, {
9
+ path: "TypeOne.java",
10
+ get children() {
11
+ return _$createComponent(jv.Declaration, {
12
+ name: "TypeOne",
13
+ children: code`
14
+ public interface TypeOne {
15
+ }
16
+ `
17
+ });
18
+ }
19
+ }), _$createComponent(jv.SourceFile, {
20
+ path: "TypeTwo.java",
21
+ get children() {
22
+ return _$createComponent(jv.Declaration, {
23
+ name: "TypeTwo",
24
+ children: code`
25
+ public interface TypeTwo {
26
+ }
27
+ `
28
+ });
29
+ }
30
+ }), _$createComponent(jv.PackageDirectory, {
31
+ "package": "import",
32
+ get children() {
33
+ return _$createComponent(jv.SourceFile, {
34
+ path: "TestGenerics.java",
35
+ get children() {
36
+ return _$createComponent(jv.Class, {
37
+ "public": true,
38
+ name: "TestGenerics",
39
+ get children() {
40
+ return code`
41
+ public TestGenerics() {
42
+ List${_$createComponent(jv.TypeArguments, {
43
+ get args() {
44
+ return [refkey("TypeOne")];
45
+ }
46
+ })} list = new ArrayList${_$createComponent(jv.TypeArguments, {})}();
47
+ List${_$createComponent(jv.TypeArguments, {
48
+ get args() {
49
+ return [{
50
+ extends: refkey("TypeTwo")
51
+ }];
52
+ }
53
+ })} list2 = new ArrayList${_$createComponent(jv.TypeArguments, {})}();
54
+ List${_$createComponent(jv.TypeArguments, {
55
+ args: [{
56
+ wildcard: true
57
+ }]
58
+ })} list3 = new ArrayList${_$createComponent(jv.TypeArguments, {})}();
59
+ }
60
+ `;
61
+ }
62
+ });
63
+ }
64
+ });
65
+ }
66
+ })]);
67
+ assertFileContents(res, {
68
+ "TestGenerics.java": d`
69
+ package me.test.code.import;
70
+
71
+ import me.test.code.TypeOne;
72
+ import me.test.code.TypeTwo;
73
+
74
+ public class TestGenerics {
75
+ public TestGenerics() {
76
+ List<TypeOne> list = new ArrayList<>();
77
+ List<? extends TypeTwo> list2 = new ArrayList<>();
78
+ List<?> list3 = new ArrayList<>();
79
+ }
80
+ }
81
+ `
82
+ });
83
+ });
@@ -0,0 +1,61 @@
1
+ import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
+ import { Output, render } from "@alloy-js/core";
3
+ import { dedent } from "@alloy-js/core/testing";
4
+ import { expect } from "vitest";
5
+ import * as jv from "../src/index.js";
6
+ export function toSourceText(c, options) {
7
+ const res = render(_$createComponent(Output, {
8
+ get children() {
9
+ return _$createComponent(jv.PackageDirectory, {
10
+ "package": "me.test.code",
11
+ get children() {
12
+ return _$createComponent(jv.SourceFile, {
13
+ path: "Test.java",
14
+ children: c
15
+ });
16
+ }
17
+ });
18
+ }
19
+ }), options);
20
+ const file = findFile(res, "Test.java");
21
+ return file.contents;
22
+ }
23
+ export function testRender(c, options) {
24
+ return render(_$createComponent(Output, {
25
+ get children() {
26
+ return _$createComponent(jv.PackageDirectory, {
27
+ "package": "me.test.code",
28
+ children: c
29
+ });
30
+ }
31
+ }), options);
32
+ }
33
+ export function findFile(res, path) {
34
+ const result = findFileWorker(res, path);
35
+ if (!result) {
36
+ throw new Error("Expected to find file " + path);
37
+ }
38
+ return result;
39
+ function findFileWorker(res, path) {
40
+ for (const item of res.contents) {
41
+ if (item.kind === "file") {
42
+ if (item.path.includes(path)) {
43
+ return item;
44
+ }
45
+ continue;
46
+ } else {
47
+ const found = findFileWorker(item, path);
48
+ if (found) {
49
+ return found;
50
+ }
51
+ }
52
+ }
53
+ return null;
54
+ }
55
+ }
56
+ export function assertFileContents(res, expectedFiles) {
57
+ for (const [path, contents] of Object.entries(expectedFiles)) {
58
+ const file = findFile(res, path);
59
+ expect(file.contents).toBe(dedent(contents));
60
+ }
61
+ }
@@ -0,0 +1,32 @@
1
+ import { createComponent as _$createComponent } from "@alloy-js/core/jsx-runtime";
2
+ import "@alloy-js/core/testing";
3
+ import { expect, it } from "vitest";
4
+ import * as jv from "../src/components/index.js";
5
+ it("renders string value", () => {
6
+ expect(_$createComponent(jv.Value, {
7
+ value: "Test"
8
+ })).toRenderTo('"Test"');
9
+ });
10
+ it("renders null/undefined object", () => {
11
+ expect(_$createComponent(jv.Value, {
12
+ value: undefined
13
+ })).toRenderTo("null");
14
+ });
15
+ it("renders number", () => {
16
+ expect(_$createComponent(jv.Value, {
17
+ value: 123
18
+ })).toRenderTo("123");
19
+ });
20
+ it("renders boolean", () => {
21
+ expect(_$createComponent(jv.Value, {
22
+ value: true
23
+ })).toRenderTo("true");
24
+ });
25
+ it("renders other objects", () => {
26
+ function Test() {
27
+ return ["Test"];
28
+ }
29
+ expect(_$createComponent(jv.Value, {
30
+ value: Test
31
+ })).toRenderTo("Test");
32
+ });
@@ -0,0 +1,143 @@
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(jv.Declaration, {
9
+ name: "Test",
10
+ get children() {
11
+ return code`
12
+ class Test {
13
+ ${_$createComponent(jv.Variable, {
14
+ "public": true,
15
+ "static": true,
16
+ final: true,
17
+ type: "String",
18
+ name: "myVar",
19
+ get value() {
20
+ return _$createComponent(jv.Value, {
21
+ value: "Test"
22
+ });
23
+ }
24
+ })};
25
+ }
26
+ `;
27
+ }
28
+ }));
29
+ expect(res).toBe(d`
30
+ package me.test.code;
31
+
32
+ class Test {
33
+ public static final String myVar = "Test";
34
+ }
35
+ `);
36
+ });
37
+ it("works with external type", () => {
38
+ const res = testRender([_$createComponent(jv.SourceFile, {
39
+ path: "Model.java",
40
+ get children() {
41
+ return _$createComponent(jv.Declaration, {
42
+ name: "Model",
43
+ children: code`
44
+ public class Model {
45
+ }
46
+ `
47
+ });
48
+ }
49
+ }), _$createComponent(jv.PackageDirectory, {
50
+ "package": "imports",
51
+ get children() {
52
+ return _$createComponent(jv.SourceFile, {
53
+ path: "Test.java",
54
+ get children() {
55
+ return _$createComponent(Declaration, {
56
+ name: "Test",
57
+ get children() {
58
+ return code`
59
+ public class Test {
60
+ ${_$createComponent(jv.Variable, {
61
+ "public": true,
62
+ "static": true,
63
+ get type() {
64
+ return refkey("Model");
65
+ },
66
+ name: "myModel"
67
+ })};
68
+ }
69
+ `;
70
+ }
71
+ });
72
+ }
73
+ });
74
+ }
75
+ })]);
76
+ assertFileContents(res, {
77
+ "Test.java": `
78
+ package me.test.code.imports;
79
+
80
+ import me.test.code.Model;
81
+
82
+ public class Test {
83
+ public static Model myModel;
84
+ }
85
+ `
86
+ });
87
+ });
88
+ it("declares new object", () => {
89
+ const res = testRender([_$createComponent(jv.SourceFile, {
90
+ path: "Model.java",
91
+ get children() {
92
+ return _$createComponent(jv.Declaration, {
93
+ name: "Model",
94
+ children: code`
95
+ public class Model {
96
+ }
97
+ `
98
+ });
99
+ }
100
+ }), _$createComponent(jv.PackageDirectory, {
101
+ "package": "imports",
102
+ get children() {
103
+ return _$createComponent(jv.SourceFile, {
104
+ path: "Test.java",
105
+ get children() {
106
+ return _$createComponent(Declaration, {
107
+ name: "Test",
108
+ get children() {
109
+ return code`
110
+ public class Test {
111
+ ${_$createComponent(jv.ObjectDeclaration, {
112
+ "public": true,
113
+ "static": true,
114
+ get type() {
115
+ return refkey("Model");
116
+ },
117
+ name: "myModel",
118
+ get args() {
119
+ return [_$createComponent(jv.Value, {
120
+ value: "initValue"
121
+ })];
122
+ }
123
+ })};
124
+ }
125
+ `;
126
+ }
127
+ });
128
+ }
129
+ });
130
+ }
131
+ })]);
132
+ assertFileContents(res, {
133
+ "Test.java": `
134
+ package me.test.code.imports;
135
+
136
+ import me.test.code.Model;
137
+
138
+ public class Test {
139
+ public static Model myModel = new Model("initValue");
140
+ }
141
+ `
142
+ });
143
+ });
@@ -0,0 +1 @@
1
+ import "vitest";