"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var java_exports = {};
__export(java_exports, {
  springResolver: () => springResolver
});
module.exports = __toCommonJS(java_exports);
const springResolver = {
  name: "spring",
  detect(context) {
    for (const file of ["pom.xml", "build.gradle", "build.gradle.kts"]) {
      const content = context.readFile(file);
      if (content && (content.includes("spring-boot") || content.includes("springframework"))) return true;
    }
    for (const file of context.getAllFiles()) {
      if (file.endsWith(".java")) {
        const content = context.readFile(file);
        if (content && (content.includes("@SpringBootApplication") || content.includes("@RestController") || content.includes("@Service") || content.includes("@Repository"))) return true;
      }
    }
    return false;
  },
  resolve(ref, context) {
    if (ref.referenceName.endsWith("Service")) {
      const id = resolveInDirs(ref.referenceName, ["service", "services"], ".java", context);
      if (id) return { original: ref, targetNodeId: id, confidence: 0.85, resolvedBy: "framework" };
    }
    if (ref.referenceName.endsWith("Repository")) {
      const id = resolveInDirs(ref.referenceName, ["repository", "repositories"], ".java", context);
      if (id) return { original: ref, targetNodeId: id, confidence: 0.85, resolvedBy: "framework" };
    }
    if (ref.referenceName.endsWith("Controller")) {
      const id = resolveInDirs(ref.referenceName, ["controller", "controllers"], ".java", context);
      if (id) return { original: ref, targetNodeId: id, confidence: 0.85, resolvedBy: "framework" };
    }
    if (/^[A-Z][a-zA-Z]+$/.test(ref.referenceName)) {
      const id = resolveInDirs(ref.referenceName, ["entity", "entities", "model", "models", "domain"], ".java", context);
      if (id) return { original: ref, targetNodeId: id, confidence: 0.7, resolvedBy: "framework" };
    }
    return null;
  },
  extractNodes(filePath, content) {
    const nodes = [];
    const now = Date.now();
    const mappingPattern = /@(Get|Post|Put|Patch|Delete|Request)Mapping\s*\(\s*(?:(?:value|path)\s*=\s*)?["']([^"']+)["']/g;
    let match;
    while ((match = mappingPattern.exec(content)) !== null) {
      const [, type, path] = match;
      const method = type === "Request" ? "ANY" : type.toUpperCase();
      const line = content.slice(0, match.index).split("\n").length;
      nodes.push({ id: `route:${filePath}:${method}:${path}:${line}`, kind: "route", name: `${method} ${path}`, qualifiedName: `${filePath}::${method}:${path}`, filePath, startLine: line, endLine: line, startColumn: 0, endColumn: match[0].length, language: "java", updatedAt: now });
    }
    return nodes;
  }
};
function resolveInDirs(name, dirs, ext, context) {
  for (const file of context.getAllFiles()) {
    if (file.endsWith(ext) && dirs.some((d) => file.includes(`/${d}/`))) {
      const node = context.getNodesInFile(file).find(
        (n) => (n.kind === "class" || n.kind === "interface") && n.name === name
      );
      if (node) return node.id;
    }
  }
  return null;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  springResolver
});
//# sourceMappingURL=java.js.map
