@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
@@ -0,0 +1,23 @@
1
+ import { code } from "@alloy-js/core";
2
+ import { Child } from "@alloy-js/core/jsx-runtime";
3
+ import { collectNamedArguments } from "../arguments.js";
4
+
5
+ export interface AnnotationProps {
6
+ type: Child;
7
+ value?: Record<string, Child>; // Either single value or named values if many
8
+ }
9
+
10
+ /**
11
+ * Use an annotation in code, not declaring a new annotation.
12
+ * For instance, use this if you want to annotate a method with '\@Override'.
13
+ */
14
+ export function Annotation(props: AnnotationProps) {
15
+ const args =
16
+ props.value ?
17
+ Object.keys(props.value).length === 1 ?
18
+ Object.values(props.value)[0]
19
+ : collectNamedArguments(props.value as Record<string, Child>)
20
+ : "";
21
+ const supplyingArgs = props.value ? code`(${args})` : "";
22
+ return code`@${props.type}${supplyingArgs}`;
23
+ }
@@ -0,0 +1,8 @@
1
+ import { Children } from "@alloy-js/core";
2
+
3
+ export interface BlockProps {
4
+ children?: Children;
5
+ }
6
+ export function Block(props: BlockProps) {
7
+ return [`{`, props.children, `}`];
8
+ }
@@ -0,0 +1,33 @@
1
+ import { Children, code, Scope } from "@alloy-js/core";
2
+ import { collectArguments } from "../arguments.js";
3
+ import { collectGenerics, GenericTypes } from "../generics.js";
4
+ import { useJavaNamePolicy } from "../name-policy.js";
5
+ import { collectModifiers, ObjectModifiers } from "../object-modifiers.js";
6
+ import { Declaration, DeclarationProps } from "./Declaration.js";
7
+ import { Name } from "./Name.js";
8
+
9
+ export interface ClassProps
10
+ extends DeclarationProps,
11
+ ObjectModifiers,
12
+ GenericTypes {
13
+ extends?: Children;
14
+ implements?: Children;
15
+ }
16
+
17
+ export function Class(props: ClassProps) {
18
+ const name = useJavaNamePolicy().getName(props.name, "class");
19
+ const extendExpression = props.extends ? code` extends ${props.extends}` : "";
20
+ const collectedInterfaces = collectArguments(props.implements);
21
+ const implementsExpression = props.implements ?
22
+ code` implements ${collectedInterfaces}`
23
+ : "";
24
+ const generics = props.generics ? collectGenerics(props.generics) : "";
25
+ const modifiers = collectModifiers(props);
26
+ return <Declaration {...props} name={name}>
27
+ {modifiers}class <Name />{generics}{extendExpression}{implementsExpression} {"{"}
28
+ <Scope name={name} kind='class'>
29
+ {props.children}
30
+ </Scope>
31
+ {"}"}
32
+ </Declaration>;
33
+ }
@@ -0,0 +1,25 @@
1
+ import { code } from "@alloy-js/core";
2
+ import { Children } from "@alloy-js/core/jsx-runtime";
3
+ import { collectModifiers, ObjectModifiers } from "../object-modifiers.js";
4
+ import { Name } from "./Name.js";
5
+ import { Parameters } from "./Parameters.js";
6
+
7
+ export interface ConstructorProps extends ObjectModifiers {
8
+ name?: string;
9
+ parameters?: Record<string, Children>; // Map of parameter name to type
10
+ children?: Children;
11
+ }
12
+
13
+ /**
14
+ * Declare a constructor, usually for a class or enum
15
+ * If no name is provided, will try take name from class or enum declaration
16
+ */
17
+ export function Constructor(props: ConstructorProps) {
18
+ const params = <Parameters parameters={props.parameters}></Parameters>;
19
+ const modifiers = collectModifiers(props);
20
+ return code`
21
+ ${modifiers}${props.name ?? <Name />}(${params}) {
22
+ ${props.children}
23
+ }
24
+ `;
25
+ }
@@ -0,0 +1,24 @@
1
+ import {
2
+ Children,
3
+ Declaration as CoreDeclaration,
4
+ Refkey,
5
+ } from "@alloy-js/core";
6
+ import { createJavaSymbol } from "../symbols/index.js";
7
+
8
+ export interface DeclarationProps {
9
+ // Name of declaration, should be fully qualified name, e.g me.example.code.Main
10
+ name: string;
11
+ refkey?: Refkey;
12
+ children?: Children;
13
+ }
14
+
15
+ /**
16
+ * Declare a symbol in the program. Declaring classes, interfaces, enums, etc. Should also pass in
17
+ * access modifier so we can manage access
18
+ */
19
+ export function Declaration(props: DeclarationProps) {
20
+ const sym = createJavaSymbol(props);
21
+ return <CoreDeclaration symbol={sym}>
22
+ {props.children}
23
+ </CoreDeclaration>;
24
+ }
@@ -0,0 +1,40 @@
1
+ import { Children, code, Scope } from "@alloy-js/core";
2
+ import { collectArguments } from "../arguments.js";
3
+ import { useJavaNamePolicy } from "../name-policy.js";
4
+ import { collectModifiers, ObjectModifiers } from "../object-modifiers.js";
5
+ import { Declaration, DeclarationProps } from "./Declaration.js";
6
+ import { Name } from "./Name.js";
7
+
8
+ export interface EnumProps extends DeclarationProps, ObjectModifiers {
9
+ implements?: Children;
10
+ }
11
+
12
+ export function Enum(props: EnumProps) {
13
+ const name = useJavaNamePolicy().getName(props.name, "enum");
14
+ const collectedInterfaces = collectArguments(props.implements);
15
+ const implementsExpression = props.implements ?
16
+ code` implements ${collectedInterfaces}`
17
+ : "";
18
+ const modifiers = collectModifiers(props);
19
+
20
+ return <Declaration {...props} name={name}>
21
+ {modifiers}enum <Name />{implementsExpression} {"{"}
22
+ <Scope kind='enum'>
23
+ {props.children}
24
+ </Scope>
25
+ {"}"}
26
+ </Declaration>;
27
+ }
28
+
29
+ export interface EnumMemberProps extends ObjectModifiers {
30
+ name: string;
31
+ arguments?: Children;
32
+ }
33
+
34
+ export function EnumMember(props: EnumMemberProps) {
35
+ const collectedArgs = collectArguments(props.arguments);
36
+ const args = props.arguments ? code`(${collectedArgs})` : "";
37
+ const name = useJavaNamePolicy().getName(props.name, "enum-member");
38
+
39
+ return code`${name}${args}`;
40
+ }
@@ -0,0 +1,12 @@
1
+ import { Child, Children, code } from "@alloy-js/core";
2
+ import { passGenerics } from "../generics.js";
3
+
4
+ export interface GenericsProps {
5
+ types?: (Child | Record<"?", Children>)[];
6
+ }
7
+
8
+ export function Generics(props: GenericsProps) {
9
+ if (!props.types) return "<>";
10
+ const generics = passGenerics(props.types);
11
+ return code`<${generics}>`;
12
+ }
@@ -0,0 +1,21 @@
1
+ import { mapJoin, memo } from "@alloy-js/core";
2
+
3
+ export interface ImportSymbol {
4
+ package: string;
5
+ name?: string;
6
+ wildcard?: boolean;
7
+ }
8
+
9
+ export interface ImportStatementsProps {
10
+ imports: ImportSymbol[];
11
+ }
12
+
13
+ export function ImportStatements(props: ImportStatementsProps) {
14
+ return memo(() =>
15
+ mapJoin(props.imports, (importProp) =>
16
+ () => <ImportStatement {...importProp} />));
17
+ }
18
+
19
+ export function ImportStatement(props: ImportSymbol) {
20
+ return () => `import ${props.package}.${props.wildcard ? "*" : props.name};`;
21
+ }
@@ -0,0 +1,31 @@
1
+ import { Children, code, Scope } from "@alloy-js/core";
2
+ import { collectArguments } from "../arguments.js";
3
+ import { collectGenerics, GenericTypes } from "../generics.js";
4
+ import { useJavaNamePolicy } from "../name-policy.js";
5
+ import { collectModifiers, ObjectModifiers } from "../object-modifiers.js";
6
+ import { Declaration, DeclarationProps } from "./Declaration.js";
7
+ import { Name } from "./Name.js";
8
+
9
+ export interface InterfaceProps
10
+ extends DeclarationProps,
11
+ ObjectModifiers,
12
+ GenericTypes {
13
+ extends?: Children;
14
+ }
15
+
16
+ export function Interface(props: InterfaceProps) {
17
+ const name = useJavaNamePolicy().getName(props.name, "interface");
18
+ const collectedInterfaces = collectArguments(props.extends);
19
+ const implementsExpression = props.extends ?
20
+ code` extends ${collectedInterfaces}`
21
+ : "";
22
+ const modifiers = collectModifiers(props);
23
+ const generics = props.generics ? collectGenerics(props.generics) : "";
24
+ return <Declaration {...props} name={name}>
25
+ {modifiers}interface <Name />{generics}{implementsExpression} {"{"}
26
+ <Scope name={name} kind='interface'>
27
+ {props.children}
28
+ </Scope>
29
+ {"}"}
30
+ </Declaration>;
31
+ }
@@ -0,0 +1,151 @@
1
+ import { code, Indent, SourceFile } from "@alloy-js/core";
2
+ import { MavenProjectConfig } from "../symbols/index.js";
3
+ import { useProject } from "./ProjectDirectory.js";
4
+
5
+ export interface MavenProjectProps {
6
+ projectConfig: MavenProjectConfig;
7
+ }
8
+
9
+ /**
10
+ * Represents a maven project. Use if you want to generate a Java project
11
+ */
12
+ export function MavenProject(props: MavenProjectProps) {
13
+ return <PomFile projectConfig={props.projectConfig} />;
14
+ }
15
+
16
+ export interface PomFileProps {
17
+ projectConfig: MavenProjectConfig;
18
+ }
19
+
20
+ export function PomFile({ projectConfig }: PomFileProps) {
21
+ const scope = useProject().scope;
22
+
23
+ // The following spaghetti mess is so the final output is formatted correctly.
24
+ // Needs to be this way for when some options aren't provided, there's no random whitespace,
25
+ // and so that looped sections are indented correctly.
26
+ return <SourceFile path="pom.xml" filetype="xml">
27
+ {code`
28
+ <?xml version="1.0" encoding="UTF-8"?>
29
+ <project xmlns="http://maven.apache.org/POM/4.0.0"
30
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
31
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
32
+
33
+ ${<Indent>
34
+ {code`
35
+ <modelVersion>4.0.0</modelVersion>
36
+ <groupId>${projectConfig.groupId}</groupId>
37
+ <artifactId>${projectConfig.artifactId}</artifactId>
38
+ <version>${projectConfig.version}</version>
39
+
40
+ <properties>
41
+ <maven.compiler.source>${projectConfig?.javaVersion}</maven.compiler.source>
42
+ <maven.compiler.target>${projectConfig?.javaVersion}</maven.compiler.target>
43
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
44
+ </properties>
45
+ `}
46
+ </Indent>}${projectConfig?.repositories && code`
47
+
48
+
49
+ <repositories>${projectConfig?.repositories.map(repo => code`
50
+
51
+ <repository>
52
+ <id>${repo.id}</id>
53
+ <url>${repo.url}</url>
54
+ </repository>
55
+ `)}
56
+ </repositories>
57
+ `}${<Indent>{projectConfig?.pluginRepositories && code`
58
+
59
+
60
+ <pluginRepositories>${projectConfig?.pluginRepositories.map(repo => code`
61
+
62
+ <pluginRepository>
63
+ <id>${repo.id}</id>
64
+ <url>${repo.url}</url>
65
+ </pluginRepository>
66
+ `)}
67
+ </pluginRepositories>
68
+ `}</Indent>}${scope.dependencies.size > 0 ? code`
69
+
70
+
71
+ <dependencies>${Array.from(scope.dependencies.values()).map(dep => code`
72
+
73
+ <dependency>
74
+ <groupId>${dep.groupId}</groupId>
75
+ <artifactId>${dep.artifactId}</artifactId>
76
+ ${dep.version !== undefined ? `<version>${dep.version}</version>` : undefined}
77
+ <scope>${dep.scope ?? "provided"}</scope>
78
+ </dependency>
79
+ `)}
80
+ </dependencies>
81
+ ` : undefined}${projectConfig?.build && code`
82
+
83
+
84
+ <build>
85
+ ${projectConfig?.build?.plugins && code`
86
+ <plugins>${projectConfig?.build?.plugins.map(plugin => code`
87
+
88
+ <plugin>
89
+ <groupId>${plugin.groupId}</groupId>
90
+ <artifactId>${plugin.artifactId}</artifactId>
91
+ ${plugin.version !== undefined ? `<version>${plugin.version}</version>` : undefined}
92
+ ${plugin.executions && code`
93
+ <executions>${plugin.executions.map(execution => code`
94
+
95
+ <execution>
96
+ ${execution.id ? `<id>${execution.id}</id>` : undefined}
97
+ ${execution.phase ? `<phase>${execution.phase}</phase>` : undefined}
98
+ ${execution.goals && code`
99
+ <goals>${execution.goals.map(goal => code`
100
+
101
+ <goal>${goal}</goal>
102
+ `)}
103
+ </goals>
104
+ `}
105
+ </execution>
106
+ `)}
107
+ </executions>
108
+ `}${plugin.configuration && code`
109
+
110
+ <configuration>${Object.entries(plugin.configuration).map(([key, value]) => code`
111
+
112
+ <${key}>${value}</${key}>
113
+ `)}
114
+ </configuration>
115
+ `}
116
+ </plugin>
117
+ `)}
118
+ </plugins>
119
+ `}${projectConfig?.build?.resources && code`
120
+
121
+ <resources>${projectConfig?.build?.resources.map(resource => code`
122
+
123
+ <resource>
124
+ <directory>${resource.directory}</directory>${resource.includes && code`
125
+
126
+ <includes>${resource.includes.map(include => code`
127
+
128
+ <include>${include}</include>
129
+ `)}
130
+ </includes>
131
+ `}${resource.excludes && code`
132
+
133
+ <excludes>${resource.excludes.map(exclude => code`
134
+
135
+ <exclude>${exclude}</exclude>
136
+ `)}
137
+ </excludes>
138
+ `}${resource.filtering !== undefined ? `
139
+ <filtering>${resource.filtering}</filtering>` : undefined}${resource.targetPath !== undefined ? `
140
+ <targetPath>${resource.targetPath}</targetPath>` : undefined}
141
+ </resource>
142
+ `)}
143
+ </resources>
144
+ `}
145
+ </build>
146
+ `}
147
+
148
+ </project>
149
+ `}
150
+ </SourceFile>;
151
+ }
@@ -0,0 +1,31 @@
1
+ import { Children, code } from "@alloy-js/core";
2
+ import { collectGenerics, GenericTypes } from "../generics.js";
3
+ import { useJavaNamePolicy } from "../name-policy.js";
4
+ import { collectModifiers, ObjectModifiers } from "../object-modifiers.js";
5
+ import { Parameters } from "./Parameters.js";
6
+
7
+ export interface MethodProps extends ObjectModifiers, GenericTypes {
8
+ name: string;
9
+ return?: Children;
10
+ parameters?: Record<string, Children>;
11
+ children?: Children;
12
+ }
13
+
14
+ export function Method(props: MethodProps) {
15
+ const params = <Parameters parameters={props.parameters}></Parameters>;
16
+ const name = useJavaNamePolicy().getName(props.name, "method");
17
+ const modifiers = collectModifiers(props);
18
+ const generics = props.generics ?
19
+ code`${collectGenerics(props.generics)}${" "}`
20
+ : "";
21
+ const sBody = props.children !== undefined ?
22
+ code`
23
+ ${" "}{
24
+ ${props.children}
25
+ }
26
+ `
27
+ : ";";
28
+ return code`
29
+ ${modifiers}${generics}${props.return ?? "void"} ${name}(${params})${sBody}
30
+ `;
31
+ }
@@ -0,0 +1,10 @@
1
+ import { DeclarationContext, useContext } from "@alloy-js/core";
2
+
3
+ export function Name() {
4
+ const declSymbol = useContext(DeclarationContext);
5
+ if (!declSymbol) {
6
+ return "";
7
+ }
8
+
9
+ return <>{declSymbol.name}</>;
10
+ }
@@ -0,0 +1,22 @@
1
+ import { Children, code } from "@alloy-js/core";
2
+ import { collectArguments } from "../arguments.js";
3
+ import { ObjectModifiers } from "../object-modifiers.js";
4
+ import { DeclarationProps } from "./Declaration.js";
5
+ import { Variable } from "./Variable.js";
6
+
7
+ export interface ObjectDeclarationProps
8
+ extends DeclarationProps,
9
+ ObjectModifiers {
10
+ type: Children;
11
+ arguments?: Children;
12
+ }
13
+
14
+ /**
15
+ * Shorthand to instantiate a new object.
16
+ * Declares it with 'new' and passes arguments to the constructor of the object, if any
17
+ */
18
+ export function ObjectDeclaration(props: ObjectDeclarationProps) {
19
+ const args = props.arguments ? collectArguments(props.arguments) : "";
20
+ const value = code`new ${props.type}(${args})`;
21
+ return <Variable {...props} value={value} />;
22
+ }
@@ -0,0 +1,84 @@
1
+ import {
2
+ Children,
3
+ ComponentContext,
4
+ createContext,
5
+ Scope,
6
+ SourceDirectory,
7
+ SourceDirectoryContext,
8
+ useBinder,
9
+ useContext,
10
+ useScope,
11
+ } from "@alloy-js/core";
12
+ import {
13
+ createJavaPackageScope,
14
+ JavaPackageScope,
15
+ } from "../symbols/java-package-scope.js";
16
+
17
+ export interface PackageDirectoryContext {
18
+ scope: JavaPackageScope;
19
+ // Full package path, e.g src/main/java/me/example/code
20
+ path: string;
21
+ // Name of package, usually name of this directory
22
+ name: string;
23
+ // Full qualified name of package, e.g me.example.code
24
+ qualifiedName: string;
25
+ }
26
+
27
+ export const PackageDirectoryContext: ComponentContext<PackageDirectoryContext> =
28
+ createContext();
29
+
30
+ export function usePackage() {
31
+ return useContext(PackageDirectoryContext);
32
+ }
33
+
34
+ export interface PackageDirectoryProps {
35
+ package: string; // Package name, if includes '.', will declare sub directories for you
36
+ children?: Children;
37
+ }
38
+
39
+ export function PackageDirectory(props: PackageDirectoryProps) {
40
+ const sourceDirectory = useContext(SourceDirectoryContext);
41
+ const parentPackage = usePackage();
42
+
43
+ const packageNames = props.package.split(".");
44
+ const packageName = packageNames[0];
45
+
46
+ const fullyQualifiedPackageName = parentPackage ?
47
+ parentPackage.qualifiedName + "." + packageName
48
+ : packageName;
49
+
50
+ const scope = createJavaPackageScope(
51
+ useBinder(),
52
+ useScope(),
53
+ fullyQualifiedPackageName,
54
+ );
55
+
56
+ const packagePath = sourceDirectory?.path + "/" + packageName;
57
+ const packageContext: PackageDirectoryContext = {
58
+ scope,
59
+ path: packagePath,
60
+ name: packageName,
61
+ qualifiedName: fullyQualifiedPackageName,
62
+ };
63
+
64
+ /**
65
+ * Recursively defines package directories if we pass name like 'one.two.three'
66
+ */
67
+ function ChildPackageDirectory() {
68
+ if (packageNames.length > 1) {
69
+ return <PackageDirectory package={packageNames.slice(1, packageNames.length).join(".")}>
70
+ {props.children}
71
+ </PackageDirectory>;
72
+ } else {
73
+ return props.children;
74
+ }
75
+ }
76
+
77
+ return <PackageDirectoryContext.Provider value={packageContext}>
78
+ <Scope value={scope}>
79
+ <SourceDirectory path={packageName}>
80
+ <ChildPackageDirectory />
81
+ </SourceDirectory>
82
+ </Scope>
83
+ </PackageDirectoryContext.Provider>;
84
+ }
@@ -0,0 +1,21 @@
1
+ import { Child, mapJoin } from "@alloy-js/core";
2
+
3
+ export interface ParametersProps {
4
+ parameters?: Record<string, Child>; // Map parameter name to type
5
+ }
6
+
7
+ /**
8
+ * Render a set of parameters for a method or constructor
9
+ *
10
+ * @param props - Takes record of parameter name to type
11
+ */
12
+ export function Parameters(props: ParametersProps) {
13
+ const { parameters = {} } = props;
14
+ return mapJoin(
15
+ new Map(Object.entries(parameters)),
16
+ (name, type) => {
17
+ return [type, " ", name];
18
+ },
19
+ { joiner: ", " },
20
+ );
21
+ }
@@ -0,0 +1,76 @@
1
+ import {
2
+ Children,
3
+ ComponentContext,
4
+ createContext,
5
+ Scope,
6
+ SourceDirectory,
7
+ useBinder,
8
+ useContext,
9
+ useScope,
10
+ } from "@alloy-js/core";
11
+ import {
12
+ createJavaProjectScope,
13
+ GradleProjectConfig,
14
+ JavaProjectScope,
15
+ MavenProjectConfig,
16
+ } from "../symbols/index.js";
17
+ import { MavenProject } from "./MavenProject.js";
18
+
19
+ export interface ProjectContext {
20
+ scope: JavaProjectScope;
21
+ }
22
+
23
+ export const ProjectContext: ComponentContext<ProjectContext> = createContext();
24
+
25
+ export function useProject() {
26
+ return useContext(ProjectContext)!;
27
+ }
28
+
29
+ export interface ProjectDirectoryProps {
30
+ name: string;
31
+
32
+ /**
33
+ * Specify project configuration for either maven or gradle.
34
+ * If not specified, will create generic Java project
35
+ */
36
+ mavenProjectConfig?: MavenProjectConfig;
37
+ gradleProjectConfig?: GradleProjectConfig;
38
+
39
+ children?: Children;
40
+ }
41
+
42
+ /**
43
+ * Represents a java project directory. Use if you want to generate a Java project
44
+ * with a build tool included (maven, gradle etc).
45
+ */
46
+ export function ProjectDirectory(props: ProjectDirectoryProps) {
47
+ const scope = createJavaProjectScope(
48
+ useBinder(),
49
+ useScope(),
50
+ props.name,
51
+ props.mavenProjectConfig,
52
+ props.gradleProjectConfig,
53
+ );
54
+
55
+ const projectContext: ProjectContext = {
56
+ scope,
57
+ };
58
+
59
+ const usingBuildSystem =
60
+ props.mavenProjectConfig !== undefined ||
61
+ props.gradleProjectConfig !== undefined;
62
+ const defaultCodePath = usingBuildSystem ? "src/main/java" : "src";
63
+
64
+ return <>
65
+ <Scope value={scope}>
66
+ <ProjectContext.Provider value={projectContext}>
67
+ <SourceDirectory path={defaultCodePath}>
68
+ {props.children}
69
+ </SourceDirectory>
70
+ {scope.mavenProjectConfig ? (
71
+ <MavenProject projectConfig={scope.mavenProjectConfig} />
72
+ ) : undefined}
73
+ </ProjectContext.Provider>
74
+ </Scope>
75
+ </>;
76
+ }
@@ -0,0 +1,12 @@
1
+ import { Refkey } from "@alloy-js/core";
2
+ import { ref } from "../symbols/index.js";
3
+
4
+ export interface ReferenceProps {
5
+ refkey: Refkey;
6
+ }
7
+
8
+ export function Reference(props: ReferenceProps) {
9
+ const reference = ref(props.refkey);
10
+
11
+ return <>{reference}</>;
12
+ }