@katana-project/laser 0.4.0 → 0.4.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.
- package/dist/resolver.js +25 -19
- package/package.json +1 -1
package/dist/resolver.js
CHANGED
|
@@ -320,6 +320,12 @@ const getUnqualifiedDescriptorName = (unit, name, externalRefs, context = null,
|
|
|
320
320
|
if (exactExternal) {
|
|
321
321
|
return exactExternal.qualifiedName.replace(/\./g, "/");
|
|
322
322
|
}
|
|
323
|
+
const qualifiedOrNestedExternal = externalRefs.find((external) => external.qualifiedName.endsWith(`.${name}`) ||
|
|
324
|
+
external.name === name ||
|
|
325
|
+
external.name === name.split(".")[name.split(".").length - 1]);
|
|
326
|
+
if (qualifiedOrNestedExternal) {
|
|
327
|
+
return qualifiedOrNestedExternal.qualifiedName.replace(/\./g, "/");
|
|
328
|
+
}
|
|
323
329
|
const javaLangExternal = externalRefs.find((external) => external.packageName === "java.lang" && external.name === name);
|
|
324
330
|
if (javaLangExternal) {
|
|
325
331
|
return javaLangExternal.qualifiedName.replace(/\./g, "/");
|
|
@@ -329,7 +335,9 @@ const getUnqualifiedDescriptorName = (unit, name, externalRefs, context = null,
|
|
|
329
335
|
return imp.importedName.replace(/\./g, "/");
|
|
330
336
|
}
|
|
331
337
|
}
|
|
332
|
-
const local = unit.types.find((type) => type.name === name
|
|
338
|
+
const local = unit.types.find((type) => type.name === name ||
|
|
339
|
+
type.qualifiedName === name ||
|
|
340
|
+
type.qualifiedName.endsWith(`.${name}`));
|
|
333
341
|
if (local) {
|
|
334
342
|
return getOwnerName(unit, local.node);
|
|
335
343
|
}
|
|
@@ -505,31 +513,29 @@ const resolveDeclarationInfo = (declaration, unit, externalRefs) => {
|
|
|
505
513
|
};
|
|
506
514
|
};
|
|
507
515
|
const declarationAtNode = (unit, offset, side, externalRefs) => {
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
if (!declaration) {
|
|
511
|
-
let nearest = null;
|
|
512
|
-
const findContainingDeclaration = (node) => {
|
|
513
|
-
if (DECLARATION_NAMES.has(node.name) && node.from <= offset && offset <= node.to) {
|
|
514
|
-
if (!nearest || node.to - node.from < nearest.to - nearest.from)
|
|
515
|
-
nearest = node;
|
|
516
|
-
}
|
|
517
|
-
let child = node.firstChild;
|
|
518
|
-
while (child) {
|
|
519
|
-
findContainingDeclaration(child);
|
|
520
|
-
child = child.nextSibling;
|
|
521
|
-
}
|
|
522
|
-
};
|
|
523
|
-
findContainingDeclaration(unit.tree.topNode);
|
|
524
|
-
declaration = nearest;
|
|
525
|
-
}
|
|
516
|
+
const resolvedNode = unit.tree.resolveInner(offset, side);
|
|
517
|
+
const declaration = findDeclarationAncestor(resolvedNode);
|
|
526
518
|
if (!declaration)
|
|
527
519
|
return null;
|
|
520
|
+
const isNameOffset = (nameNode) => nameNode !== null && nameNode.from <= offset && offset <= nameNode.to;
|
|
528
521
|
if (declaration.name === "FieldDeclaration") {
|
|
529
522
|
const fields = getFieldNameAndType(declaration, unit, unit.source, externalRefs);
|
|
530
523
|
const containing = fields.find((field) => field.node.from <= offset && offset <= field.node.to);
|
|
531
524
|
return containing ?? null;
|
|
532
525
|
}
|
|
526
|
+
if (declaration.name === "StaticInitializer") {
|
|
527
|
+
const staticNode = findChild(declaration, (node) => node.name === "static");
|
|
528
|
+
return isNameOffset(staticNode) ? resolveDeclarationInfo(declaration, unit, externalRefs) : null;
|
|
529
|
+
}
|
|
530
|
+
if (declaration.name === "EnumConstant" || declaration.name === "ConstantDeclaration") {
|
|
531
|
+
const definition = declaration.name === "EnumConstant"
|
|
532
|
+
? findDescendantDefinition(declaration)
|
|
533
|
+
: findDefinition(findChild(declaration, (node) => node.name === "VariableDeclarator") ?? declaration);
|
|
534
|
+
return isNameOffset(definition) ? resolveDeclarationInfo(declaration, unit, externalRefs) : null;
|
|
535
|
+
}
|
|
536
|
+
const definition = findDefinition(declaration);
|
|
537
|
+
if (!isNameOffset(definition))
|
|
538
|
+
return null;
|
|
533
539
|
return resolveDeclarationInfo(declaration, unit, externalRefs);
|
|
534
540
|
};
|
|
535
541
|
/**
|