@alloy-js/java 0.19.0 → 0.20.0-dev.1

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 (63) hide show
  1. package/dist/src/components/Class.d.ts.map +1 -1
  2. package/dist/src/components/Class.js +3 -3
  3. package/dist/src/components/Declaration.d.ts.map +1 -1
  4. package/dist/src/components/Declaration.js +6 -1
  5. package/dist/src/components/Enum.d.ts.map +1 -1
  6. package/dist/src/components/Enum.js +3 -3
  7. package/dist/src/components/Interface.d.ts.map +1 -1
  8. package/dist/src/components/Interface.js +3 -3
  9. package/dist/src/components/LexicalScope.d.ts +8 -0
  10. package/dist/src/components/LexicalScope.d.ts.map +1 -0
  11. package/dist/src/components/LexicalScope.js +23 -0
  12. package/dist/src/components/PackageDirectory.d.ts.map +1 -1
  13. package/dist/src/components/PackageDirectory.js +3 -2
  14. package/dist/src/components/SourceFile.d.ts.map +1 -1
  15. package/dist/src/components/SourceFile.js +3 -3
  16. package/dist/src/create-library.d.ts.map +1 -1
  17. package/dist/src/create-library.js +3 -5
  18. package/dist/src/index.d.ts +1 -0
  19. package/dist/src/index.d.ts.map +1 -1
  20. package/dist/src/index.js +2 -1
  21. package/dist/src/symbols/index.d.ts +1 -0
  22. package/dist/src/symbols/index.d.ts.map +1 -1
  23. package/dist/src/symbols/index.js +1 -0
  24. package/dist/src/symbols/java-lexical-scope.d.ts +6 -0
  25. package/dist/src/symbols/java-lexical-scope.d.ts.map +1 -0
  26. package/dist/src/symbols/java-lexical-scope.js +7 -0
  27. package/dist/src/symbols/java-output-symbol.d.ts +4 -2
  28. package/dist/src/symbols/java-output-symbol.d.ts.map +1 -1
  29. package/dist/src/symbols/java-output-symbol.js +13 -2
  30. package/dist/src/symbols/java-package-scope.d.ts +2 -0
  31. package/dist/src/symbols/java-package-scope.d.ts.map +1 -1
  32. package/dist/src/symbols/java-package-scope.js +4 -0
  33. package/dist/src/symbols/java-project-scope.js +1 -1
  34. package/dist/src/symbols/reference.js +2 -2
  35. package/dist/src/utils.d.ts +3 -0
  36. package/dist/src/utils.d.ts.map +1 -0
  37. package/dist/src/utils.js +12 -0
  38. package/dist/test/constructor.test.js +4 -4
  39. package/dist/test/method.test.js +3 -3
  40. package/dist/test/variables.test.js +3 -3
  41. package/dist/tsconfig.tsbuildinfo +1 -1
  42. package/package.json +7 -7
  43. package/src/components/Class.tsx +4 -3
  44. package/src/components/Declaration.tsx +7 -1
  45. package/src/components/Enum.tsx +4 -3
  46. package/src/components/Interface.tsx +4 -3
  47. package/src/components/LexicalScope.tsx +31 -0
  48. package/src/components/PackageDirectory.tsx +3 -1
  49. package/src/components/SourceFile.tsx +2 -4
  50. package/src/create-library.ts +2 -4
  51. package/src/index.ts +1 -0
  52. package/src/symbols/index.ts +1 -0
  53. package/src/symbols/java-lexical-scope.ts +9 -0
  54. package/src/symbols/java-output-symbol.ts +24 -3
  55. package/src/symbols/java-package-scope.ts +6 -0
  56. package/src/symbols/java-project-scope.ts +1 -1
  57. package/src/symbols/reference.ts +2 -2
  58. package/src/utils.ts +17 -0
  59. package/temp/api.json +290 -3
  60. package/test/constructor.test.tsx +7 -7
  61. package/test/method.test.tsx +5 -5
  62. package/test/variables.test.tsx +5 -5
  63. package/tsdoc-metadata.json +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alloy-js/java",
3
- "version": "0.19.0",
3
+ "version": "0.20.0-dev.1",
4
4
  "description": "",
5
5
  "exports": {
6
6
  ".": {
@@ -14,18 +14,18 @@
14
14
  "author": "brian.terlson@microsoft.com",
15
15
  "license": "MIT",
16
16
  "dependencies": {
17
+ "@alloy-js/core": "~0.19.0 || >= 0.20.0-dev.6",
17
18
  "change-case": "^5.4.4",
18
- "pathe": "^2.0.3",
19
- "@alloy-js/core": "~0.19.0"
19
+ "pathe": "^2.0.3"
20
20
  },
21
21
  "devDependencies": {
22
+ "@alloy-js/cli": "~0.19.0 || >= 0.20.0-dev.0",
23
+ "@alloy-js/rollup-plugin": "~0.1.0 || >= 0.1.1-dev.0",
22
24
  "@microsoft/api-extractor": "~7.52.8",
23
25
  "@rollup/plugin-typescript": "^12.1.2",
24
- "concurrently": "^9.1.2",
26
+ "concurrently": "^9.2.0",
25
27
  "typescript": "^5.8.3",
26
- "vitest": "^3.2.4",
27
- "@alloy-js/cli": "~0.19.0",
28
- "@alloy-js/rollup-plugin": "~0.1.0"
28
+ "vitest": "^3.2.4"
29
29
  },
30
30
  "type": "module",
31
31
  "scripts": {
@@ -1,8 +1,9 @@
1
- import { Block, Children, Scope, Show } from "@alloy-js/core";
1
+ import { Block, Children, Show } from "@alloy-js/core";
2
2
  import { useJavaNamePolicy } from "../name-policy.js";
3
3
  import { Declaration, DeclarationProps } from "./Declaration.js";
4
4
  import { ExtendsClause } from "./ExtendsClause.js";
5
5
  import { ImplementsClause } from "./ImplementsClause.js";
6
+ import { LexicalScope } from "./LexicalScope.jsx";
6
7
  import { ModifierProps, Modifiers } from "./Modifiers.jsx";
7
8
  import { Name } from "./Name.js";
8
9
  import { TypeParameters, TypeParametersProps } from "./TypeParameters.jsx";
@@ -28,9 +29,9 @@ export function Class(props: ClassProps) {
28
29
  </Show>
29
30
  <ExtendsClause extends={props.extends ? [props.extends] : []} />
30
31
  <ImplementsClause interfaces={props.implements} />{" "}
31
- <Scope name={name} kind="class">
32
+ <LexicalScope name={name}>
32
33
  <Block>{props.children}</Block>
33
- </Scope>
34
+ </LexicalScope>
34
35
  </group>
35
36
  </Declaration>
36
37
  );
@@ -4,6 +4,7 @@ import {
4
4
  Refkey,
5
5
  } from "@alloy-js/core";
6
6
  import { JavaOutputSymbol } from "../symbols/java-output-symbol.js";
7
+ import { useLexicalScope } from "../utils.js";
7
8
 
8
9
  export interface DeclarationProps {
9
10
  // Name of declaration, should be fully qualified name, e.g me.example.code.Main
@@ -17,7 +18,12 @@ export interface DeclarationProps {
17
18
  * access modifier so we can manage access
18
19
  */
19
20
  export function Declaration(props: DeclarationProps) {
20
- const sym = new JavaOutputSymbol(props.name, {
21
+ const scope = useLexicalScope();
22
+ if (!scope) {
23
+ throw new Error("A lexical scope is required for declaration");
24
+ }
25
+
26
+ const sym = new JavaOutputSymbol(props.name, scope.symbols, {
21
27
  refkeys: props.refkey,
22
28
  });
23
29
  return <CoreDeclaration symbol={sym}>{props.children}</CoreDeclaration>;
@@ -1,8 +1,9 @@
1
- import { Block, Children, List, Scope } from "@alloy-js/core";
1
+ import { Block, Children, List } from "@alloy-js/core";
2
2
  import { useJavaNamePolicy } from "../name-policy.js";
3
3
  import { ArgumentList } from "./ArgumentList.jsx";
4
4
  import { Declaration, DeclarationProps } from "./Declaration.js";
5
5
  import { ImplementsClause } from "./ImplementsClause.jsx";
6
+ import { LexicalScope } from "./LexicalScope.jsx";
6
7
  import { ModifierProps, Modifiers } from "./Modifiers.jsx";
7
8
  import { Name } from "./Name.js";
8
9
 
@@ -20,9 +21,9 @@ export function Enum(props: EnumProps) {
20
21
  enum <Name />
21
22
  <ImplementsClause interfaces={props.implements} />
22
23
  </group>{" "}
23
- <Scope kind="enum">
24
+ <LexicalScope>
24
25
  <Block>{props.children}</Block>
25
- </Scope>
26
+ </LexicalScope>
26
27
  </Declaration>
27
28
  );
28
29
  }
@@ -1,7 +1,8 @@
1
- import { Block, Children, Scope } from "@alloy-js/core";
1
+ import { Block, Children } from "@alloy-js/core";
2
2
  import { useJavaNamePolicy } from "../name-policy.js";
3
3
  import { Declaration, DeclarationProps } from "./Declaration.js";
4
4
  import { ExtendsClause } from "./ExtendsClause.jsx";
5
+ import { LexicalScope } from "./LexicalScope.jsx";
5
6
  import { ModifierProps, Modifiers } from "./Modifiers.jsx";
6
7
  import { Name } from "./Name.js";
7
8
  import { TypeParameters, TypeParametersProps } from "./TypeParameters.jsx";
@@ -23,9 +24,9 @@ export function Interface(props: InterfaceProps) {
23
24
  <TypeParameters generics={props.generics} />
24
25
  <ExtendsClause extends={props.extends} />{" "}
25
26
  </group>
26
- <Scope name={name} kind="interface">
27
+ <LexicalScope name={name}>
27
28
  <Block>{props.children}</Block>
28
- </Scope>
29
+ </LexicalScope>
29
30
  </Declaration>
30
31
  );
31
32
  }
@@ -0,0 +1,31 @@
1
+ import {
2
+ Scope,
3
+ ScopePropsWithInfo,
4
+ ScopePropsWithValue,
5
+ useScope,
6
+ } from "@alloy-js/core";
7
+ import { JavaLexicalScope } from "../symbols/index.js";
8
+
9
+ export interface LexicalScopePropsWithScopeValue extends ScopePropsWithValue {}
10
+ export interface LeixcalScopePropsWithScopeInfo extends ScopePropsWithInfo {}
11
+
12
+ export type LexicalScopeProps =
13
+ | LexicalScopePropsWithScopeValue
14
+ | LeixcalScopePropsWithScopeInfo;
15
+
16
+ export function LexicalScope(props: LexicalScopeProps) {
17
+ let scope;
18
+ if ("value" in props) {
19
+ if (!(props.value instanceof JavaLexicalScope)) {
20
+ throw new Error("LexicalScope value must be a TSLexicalScope instance");
21
+ }
22
+ scope = props.value;
23
+ } else {
24
+ const parentScope = useScope();
25
+ scope = new JavaLexicalScope(props.name ?? "lexical scope", parentScope, {
26
+ ...props,
27
+ });
28
+ }
29
+
30
+ return <Scope value={scope}>{props.children}</Scope>;
31
+ }
@@ -6,6 +6,7 @@ import {
6
6
  SourceDirectory,
7
7
  SourceDirectoryContext,
8
8
  useContext,
9
+ useScope,
9
10
  } from "@alloy-js/core";
10
11
  import { JavaPackageScope } from "../symbols/java-package-scope.js";
11
12
 
@@ -43,7 +44,8 @@ export function PackageDirectory(props: PackageDirectoryProps) {
43
44
  parentPackage.qualifiedName + "." + packageName
44
45
  : packageName;
45
46
 
46
- const scope = new JavaPackageScope(fullyQualifiedPackageName);
47
+ const parentScope = useScope();
48
+ const scope = new JavaPackageScope(fullyQualifiedPackageName, parentScope);
47
49
 
48
50
  const packagePath = sourceDirectory?.path + "/" + packageName;
49
51
  const packageContext: PackageDirectoryContext = {
@@ -4,11 +4,11 @@ import {
4
4
  createContext,
5
5
  OutputSymbol,
6
6
  reactive,
7
- Scope,
8
7
  } from "@alloy-js/core";
9
8
  import { Children } from "@alloy-js/core/jsx-runtime";
10
9
  import { JavaOutputSymbol } from "../symbols/index.js";
11
10
  import { ImportStatements, ImportSymbol } from "./ImportStatement.js";
11
+ import { LexicalScope } from "./LexicalScope.jsx";
12
12
  import { usePackage } from "./PackageDirectory.js";
13
13
  import { Reference } from "./Reference.js";
14
14
 
@@ -79,9 +79,7 @@ export function SourceFile(props: SourceFileProps) {
79
79
  </>
80
80
  : undefined}
81
81
  <SourceFileContext.Provider value={sfContext}>
82
- <Scope name={props.path} kind="source-file">
83
- {props.children}
84
- </Scope>
82
+ <LexicalScope name={props.path}>{props.children}</LexicalScope>
85
83
  </SourceFileContext.Provider>
86
84
  </CoreSourceFile>
87
85
  );
@@ -26,15 +26,13 @@ function createSymbols(
26
26
  const projectScope = new JavaProjectScope(props.groupId, { binder });
27
27
 
28
28
  for (const [pkg, symbols] of Object.entries(props.descriptor)) {
29
- const packageScope = new JavaPackageScope(pkg, {
29
+ const packageScope = new JavaPackageScope(pkg, projectScope, {
30
30
  binder,
31
- parent: projectScope,
32
31
  });
33
32
 
34
33
  for (const symB of symbols) {
35
- new JavaOutputSymbol(symB, {
34
+ new JavaOutputSymbol(symB, packageScope.symbols, {
36
35
  binder,
37
- scope: packageScope,
38
36
  refkeys: refkeys[symB],
39
37
  package: packageScope.name,
40
38
  });
package/src/index.ts CHANGED
@@ -3,3 +3,4 @@ export * from "./components/index.js";
3
3
  export * from "./create-library.js";
4
4
  export * from "./name-policy.js";
5
5
  export * from "./symbols/index.js";
6
+ export * from "./utils.js";
@@ -1,3 +1,4 @@
1
+ export * from "./java-lexical-scope.js";
1
2
  export * from "./java-output-symbol.js";
2
3
  export * from "./java-package-scope.js";
3
4
  export * from "./java-project-scope.js";
@@ -0,0 +1,9 @@
1
+ import { OutputScope } from "@alloy-js/core";
2
+
3
+ export class JavaLexicalScope extends OutputScope {
4
+ public static readonly declarationSpaces = ["symbols"];
5
+
6
+ get symbols() {
7
+ return this.spaceFor("symbols")!;
8
+ }
9
+ }
@@ -1,4 +1,9 @@
1
- import { OutputSymbol, OutputSymbolOptions, refkey } from "@alloy-js/core";
1
+ import {
2
+ OutputSpace,
3
+ OutputSymbol,
4
+ OutputSymbolOptions,
5
+ refkey,
6
+ } from "@alloy-js/core";
2
7
  import { usePackage } from "../components/PackageDirectory.jsx";
3
8
 
4
9
  export interface JavaOutputSymbolOptions extends OutputSymbolOptions {
@@ -9,6 +14,8 @@ export interface JavaOutputSymbolOptions extends OutputSymbolOptions {
9
14
  * Not considered exported if private
10
15
  */
11
16
  export class JavaOutputSymbol extends OutputSymbol {
17
+ static memberSpaces = ["static", "instance"] as const;
18
+
12
19
  /**
13
20
  * Fully qualified package name
14
21
  */
@@ -17,11 +24,15 @@ export class JavaOutputSymbol extends OutputSymbol {
17
24
  }
18
25
  #package?: string;
19
26
 
20
- constructor(name: string, options: JavaOutputSymbolOptions = {}) {
27
+ constructor(
28
+ name: string,
29
+ spaces: OutputSpace[] | OutputSpace | undefined,
30
+ options: JavaOutputSymbolOptions = {},
31
+ ) {
21
32
  if (options.refkeys === undefined) {
22
33
  options.refkeys = [refkey(name)];
23
34
  }
24
- super(name, options);
35
+ super(name, spaces, options);
25
36
 
26
37
  if (options.package) {
27
38
  this.#package = options.package;
@@ -33,4 +44,14 @@ export class JavaOutputSymbol extends OutputSymbol {
33
44
  : "";
34
45
  }
35
46
  }
47
+
48
+ copy() {
49
+ const options = this.getCopyOptions();
50
+ const copy = new JavaOutputSymbol(this.name, undefined, {
51
+ ...options,
52
+ package: this.#package,
53
+ });
54
+ this.initializeCopy(copy);
55
+ return copy;
56
+ }
36
57
  }
@@ -1,7 +1,13 @@
1
1
  import { OutputScope } from "@alloy-js/core";
2
2
 
3
3
  export class JavaPackageScope extends OutputScope {
4
+ public static readonly declarationSpaces = ["symbols"] as const;
5
+
4
6
  get kind() {
5
7
  return "package";
6
8
  }
9
+
10
+ get symbols() {
11
+ return this.spaceFor("symbols")!;
12
+ }
7
13
  }
@@ -136,7 +136,7 @@ export class JavaProjectScope extends OutputScope {
136
136
  #gradleProjectConfig?: GradleProjectConfig;
137
137
 
138
138
  constructor(name: string, options: JavaProjectScopeOptions = {}) {
139
- super(name, options);
139
+ super(name, undefined, options);
140
140
 
141
141
  this.#mavenProjectConfig = options.mavenProjectConfig;
142
142
  this.#gradleProjectConfig = options.gradleProjectConfig;
@@ -17,8 +17,8 @@ export function ref(refkey: Refkey) {
17
17
  return "<Unresolved Symbol>";
18
18
  }
19
19
 
20
- const { targetDeclaration } = result.value;
20
+ const { symbol } = result.value;
21
21
 
22
- return untrack(() => sourceFile!.addImport(targetDeclaration));
22
+ return untrack(() => sourceFile!.addImport(symbol));
23
23
  });
24
24
  }
package/src/utils.ts ADDED
@@ -0,0 +1,17 @@
1
+ import { useScope } from "@alloy-js/core";
2
+ import { JavaLexicalScope } from "./symbols/java-lexical-scope.js";
3
+
4
+ export function useLexicalScope(): JavaLexicalScope | undefined {
5
+ const scopeContext = useScope();
6
+ if (!scopeContext) {
7
+ return undefined;
8
+ }
9
+
10
+ if (!(scopeContext instanceof JavaLexicalScope)) {
11
+ throw new Error(
12
+ "A lexical scope is required but the current scope is not a lexical scope",
13
+ );
14
+ }
15
+
16
+ return scopeContext;
17
+ }