@katana-project/laser 0.2.4 → 0.3.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/dist/resolver.d.ts +1 -0
- package/dist/resolver.js +20 -2
- package/dist/unit.d.ts +2 -3
- package/dist/unit.js +14 -7
- package/package.json +2 -2
package/dist/resolver.d.ts
CHANGED
package/dist/resolver.js
CHANGED
|
@@ -97,8 +97,10 @@ const resolveInUnit = (typeName, unit) => {
|
|
|
97
97
|
return null;
|
|
98
98
|
};
|
|
99
99
|
const resolveImported = (typeRef, unit, externalRefs) => {
|
|
100
|
+
// type imports
|
|
100
101
|
for (const imp of unit.imports) {
|
|
101
|
-
if (
|
|
102
|
+
if (imp.kind === "type" &&
|
|
103
|
+
(imp.importedName === typeRef.name || imp.importedName.endsWith(`.${typeRef.name}`))) {
|
|
102
104
|
return {
|
|
103
105
|
kind: "imported",
|
|
104
106
|
name: typeRef.name,
|
|
@@ -107,8 +109,9 @@ const resolveImported = (typeRef, unit, externalRefs) => {
|
|
|
107
109
|
};
|
|
108
110
|
}
|
|
109
111
|
}
|
|
112
|
+
// wildcard imports
|
|
110
113
|
for (const imp of unit.imports) {
|
|
111
|
-
if (imp.
|
|
114
|
+
if (imp.kind === "wildcard") {
|
|
112
115
|
const matchingExternal = externalRefs.find((ext) => `${imp.importedName}.${typeRef.name}` === ext.qualifiedName);
|
|
113
116
|
if (matchingExternal) {
|
|
114
117
|
return {
|
|
@@ -120,6 +123,21 @@ const resolveImported = (typeRef, unit, externalRefs) => {
|
|
|
120
123
|
}
|
|
121
124
|
}
|
|
122
125
|
}
|
|
126
|
+
// module imports
|
|
127
|
+
for (const imp of unit.imports) {
|
|
128
|
+
if (imp.kind === "module") {
|
|
129
|
+
const matchingExternal = externalRefs.find((ext) => ext.moduleName === imp.importedName &&
|
|
130
|
+
(ext.name === typeRef.name || ext.qualifiedName.endsWith(`.${typeRef.name}`)));
|
|
131
|
+
if (matchingExternal) {
|
|
132
|
+
return {
|
|
133
|
+
kind: "imported",
|
|
134
|
+
name: typeRef.name,
|
|
135
|
+
qualifiedName: matchingExternal.qualifiedName,
|
|
136
|
+
ref: typeRef,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
123
141
|
// same-package classes
|
|
124
142
|
let matchingExternal = externalRefs.find((ext) => ext.packageName === (unit.packageName ?? "") && ext.name === typeRef.name);
|
|
125
143
|
if (!matchingExternal) {
|
package/dist/unit.d.ts
CHANGED
|
@@ -3,16 +3,15 @@ import { SyntaxNode, Tree } from "@lezer/common";
|
|
|
3
3
|
* Represents an import statement in a Java source file.
|
|
4
4
|
*/
|
|
5
5
|
export interface ImportInfo {
|
|
6
|
+
kind: "type" | "wildcard" | "static" | "module";
|
|
6
7
|
importedName: string;
|
|
7
|
-
isStatic: boolean;
|
|
8
|
-
isWildcard: boolean;
|
|
9
8
|
node: SyntaxNode;
|
|
10
9
|
}
|
|
11
10
|
/**
|
|
12
11
|
* Represents a type declaration (class, interface, enum, annotation, module) in a Java source file.
|
|
13
12
|
*/
|
|
14
13
|
export interface TypeInfo {
|
|
15
|
-
kind: "class" | "interface" | "enum" | "annotation" | "module";
|
|
14
|
+
kind: "class" | "interface" | "enum" | "annotation" | "module" | "record";
|
|
16
15
|
name: string;
|
|
17
16
|
qualifiedName: string;
|
|
18
17
|
node: SyntaxNode;
|
package/dist/unit.js
CHANGED
|
@@ -42,16 +42,19 @@ export const parseUnit = (tree, source) => {
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
else if (node.name === "ImportDeclaration") {
|
|
45
|
-
const isStatic = !!findChild(node, (c) => c.name === "static");
|
|
46
|
-
const isWildcard = !!findChild(node, (c) => c.name === "Asterisk");
|
|
47
45
|
const nameNode = findChild(node, (c) => c.name === "Identifier" || c.name === "ScopedIdentifier");
|
|
48
46
|
if (nameNode) {
|
|
49
47
|
const importedName = source.slice(nameNode.from, nameNode.to);
|
|
50
48
|
if (importedName) {
|
|
51
49
|
unit.imports.push({
|
|
50
|
+
kind: findChild(node, (c) => c.name === "module")
|
|
51
|
+
? "module"
|
|
52
|
+
: findChild(node, (c) => c.name === "static")
|
|
53
|
+
? "static"
|
|
54
|
+
: findChild(node, (c) => c.name === "Asterisk")
|
|
55
|
+
? "wildcard"
|
|
56
|
+
: "type",
|
|
52
57
|
importedName,
|
|
53
|
-
isStatic,
|
|
54
|
-
isWildcard,
|
|
55
58
|
node,
|
|
56
59
|
});
|
|
57
60
|
}
|
|
@@ -61,7 +64,8 @@ export const parseUnit = (tree, source) => {
|
|
|
61
64
|
node.name === "InterfaceDeclaration" ||
|
|
62
65
|
node.name === "EnumDeclaration" ||
|
|
63
66
|
node.name === "AnnotationTypeDeclaration" ||
|
|
64
|
-
node.name === "ModuleDeclaration"
|
|
67
|
+
node.name === "ModuleDeclaration" ||
|
|
68
|
+
node.name === "RecordDeclaration") {
|
|
65
69
|
const defNode = findChild(node, (c) => c.name === "Definition" || c.name === "Identifier");
|
|
66
70
|
if (defNode) {
|
|
67
71
|
const name = source.slice(defNode.from, defNode.to);
|
|
@@ -76,7 +80,9 @@ export const parseUnit = (tree, source) => {
|
|
|
76
80
|
? "enum"
|
|
77
81
|
: node.name === "AnnotationTypeDeclaration"
|
|
78
82
|
? "annotation"
|
|
79
|
-
: "
|
|
83
|
+
: node.name === "ModuleDeclaration"
|
|
84
|
+
? "module"
|
|
85
|
+
: "record",
|
|
80
86
|
name,
|
|
81
87
|
qualifiedName,
|
|
82
88
|
node,
|
|
@@ -86,7 +92,8 @@ export const parseUnit = (tree, source) => {
|
|
|
86
92
|
c.name === "InterfaceBody" ||
|
|
87
93
|
c.name === "AnnotationTypeBody" ||
|
|
88
94
|
c.name === "ModuleBody" ||
|
|
89
|
-
c.name === "EnumBody"
|
|
95
|
+
c.name === "EnumBody" ||
|
|
96
|
+
c.name === "RecordBody");
|
|
90
97
|
if (classBody) {
|
|
91
98
|
let child = classBody.firstChild;
|
|
92
99
|
while (child) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@katana-project/laser",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "katana-project",
|
|
6
6
|
"license": "MIT",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"@lezer/common": "^1.5.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@lezer
|
|
29
|
+
"@run-slicer/lezer-java": "^1.2.1",
|
|
30
30
|
"@types/chai": "^5.2.3",
|
|
31
31
|
"@types/mocha": "^10.0.10",
|
|
32
32
|
"@types/node": "^25.0.5",
|