Code positioning method and device based on multi-level structured annotation, equipment and medium

By using multi-level structured commenting standards and indexing technology, the problems of fragmented comment formats and inconsistent semantics in code location were solved, enabling precise location and rapid retrieval of code lines and improving the maintainability of the software system.

CN121996527BActive Publication Date: 2026-07-03HANGZHOU HAOLINK INTELLIGENT TECHNOLOGY CO LTD +1

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
HANGZHOU HAOLINK INTELLIGENT TECHNOLOGY CO LTD
Filing Date
2026-04-09
Publication Date
2026-07-03

AI Technical Summary

Technical Problem

Existing code location methods suffer from fragmented comment formats, inconsistent semantics, difficulty in machine parsing, and a lack of a multi-level semantic tag system, resulting in inaccurate code location and time consumption.

Method used

By adopting a multi-level structured commenting standard, we obtain the comment information and its location association from the source code file, generate an abstract syntax tree, align it with the code structure nodes, merge the comment information, generate a set of line-level semantic markup objects, and build a multi-dimensional index library for fast location.

Benefits of technology

It enables accurate and rapid location of lines of code, reduces troubleshooting and requirement change time, and improves the maintainability and traceability of large software systems.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121996527B_ABST
    Figure CN121996527B_ABST
Patent Text Reader

Abstract

This invention relates to the field of computer technology, and provides a code location method, apparatus, device, and medium based on multi-level structured comments. It can uniformly configure multi-level structured comment specifications, solving the problem of difficulty in machine parsing; it identifies the positional association information between comment information and corresponding code lines in source code files, ensuring the accuracy of comment-code position binding; it aligns comment information to the corresponding code structure nodes in the abstract syntax tree based on the positional association information, achieving precise alignment between comments and code structure nodes; it merges the comment information corresponding to each code structure node to avoid coarse-grained comments; and it responds to location requests based on a set of line-level semantic markup objects and a multi-dimensional index, thereby achieving accurate and rapid location of code lines.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer technology, and in particular to a code location method, apparatus, device, and medium based on multi-level structured annotations. Background Technology

[0002] In current software development processes, code location is a fundamental yet time-consuming task within debugging, troubleshooting, requirement changes, and code review. Developers typically rely on the following methods to locate code:

[0003] 1. Full-text search-based location: This method utilizes the full-text search functionality provided by an IDE (Integrated Development Environment) or code hosting platform to match keywords (such as interface paths, field names, error messages, etc.). Common problems with this approach include: keywords appearing in numerous files, resulting in a large list of results; certain key business logic lacking obvious keywords, making it difficult to find through simple searches; and the inability to directly establish a precise correspondence between "a specific line of code" and "business requirements and scenarios."

[0004] 2. Experience-based location based on function, class, and comment names: This method infers the location of business logic by reading class names, method names, and natural language comments written by developers. However, this approach typically has the following problems: inconsistent formatting, unstructured semantics, and difficulty in reliable machine parsing; the granularity of comments usually remains at the class or method level, making it difficult to pinpoint a specific line or block of code; and it is difficult to directly retrieve information such as "the business scenario, variable semantics, and requirement number corresponding to this line of code" from the comments.

[0005] 3. Lack of a unified "multi-level semantic tag" system: Some existing documentation generation tools support adding comments to classes and methods to generate documentation, but this approach has the following problems: it is mainly for documentation display rather than precise code location; it usually only focuses on the class and method level, without forming a multi-level, inheritable semantic tag structure from class to method to line of code; and it lacks fine-grained tagging capabilities for variables, conditional branches, local logic blocks, etc.

[0006] 4. Scattered Business Logic: In large systems, business logic is often scattered across multiple classes, methods, and even lines of code, and variable names do not always intuitively correspond to their business meanings. For example, a variable with the same name, `status`, may have completely different meanings in different modules (e.g., order status, payment status, approval status, etc.). It is difficult to accurately determine the true business semantics of a particular line of code simply by searching for its variable or method name. Summary of the Invention

[0007] In view of the above, it is necessary to provide a code location method, device, equipment and medium based on multi-level structured comments, which can accurately locate any line of code.

[0008] A code location method based on multi-level structured comments, the method comprising:

[0009] Obtain source code files generated based on multi-level structured commenting specifications, and identify the relationship between comment information and corresponding code line positions in the source code files;

[0010] The source code file is parsed to obtain an abstract syntax tree, and the comment information is aligned to the corresponding code structure node in the abstract syntax tree according to the position association information to obtain a code structure model;

[0011] According to the multi-level structured annotation specification, the annotation information corresponding to each code structure node in the code structure model is merged to obtain multi-level annotation hierarchy information;

[0012] A set of line-level semantic marker objects is generated based on the multi-level annotation hierarchy information and the code structure model;

[0013] In response to a location request triggered by the target code, the location request is responded to according to the set of line-level semantic markup objects and the multidimensional index library to obtain the located target code line.

[0014] A code location device based on multi-level structured annotations, the code location device based on multi-level structured annotations includes:

[0015] The identification unit is used to acquire source code files generated based on multi-level structured annotation specifications, and to identify the position association information between the annotation information and the corresponding code lines in the source code files;

[0016] The alignment unit is used to perform structural parsing on the source code file to obtain an abstract syntax tree, and to align the comment information to the corresponding code structure node in the abstract syntax tree according to the position association information to obtain a code structure model;

[0017] The merging unit is used to merge the annotation information corresponding to each code structure node in the code structure model according to the multi-level structured annotation specification to obtain multi-level annotation hierarchy information.

[0018] The generation unit is used to generate a set of line-level semantic tag objects based on the multi-level annotation hierarchy information and the code structure model.

[0019] The response unit is used to respond to a location request triggered based on the target code, and respond to the location request according to the set of line-level semantic markup objects and the multidimensional index library to obtain the located target code line.

[0020] A computer device, the computer device comprising:

[0021] A memory that stores at least one instruction; and a processor that executes the instructions stored in the memory to implement the code location method based on multi-level structured annotations.

[0022] A computer-readable storage medium storing at least one instruction, which is executed by a processor in a computer device to implement the code location method based on multi-level structured annotations.

[0023] As can be seen from the above technical solutions, this invention can uniformly configure multi-level structured comment specifications, solving the problems of fragmented comment formats, inconsistent semantics, and difficulty in machine parsing; it identifies the positional association information between comment information and corresponding code lines in source code files, ensuring the accuracy of the positional binding between comments and code; it aligns comment information to the corresponding code structure nodes in the abstract syntax tree based on the positional association information, achieving precise alignment between comments and code structure nodes, solving the problem of weak association between traditional comments and code; it merges the comment information corresponding to each code structure node in the code structure model according to the multi-level structured comment specifications, solving the problems of coarse granularity and semantic fragmentation in traditional comments; it generates a set of line-level semantic tag objects based on the multi-level comment hierarchy information and the code structure model, assigning standardized and structured semantic tags to each line of code; and it responds to location requests based on the set of line-level semantic tag objects and a multi-dimensional index library, thereby achieving accurate and rapid location of code lines. Attached Figure Description

[0024] Figure 1 This is a flowchart of a preferred embodiment of the code location method based on multi-level structured annotations of the present invention;

[0025] Figure 2 This is a functional block diagram of a preferred embodiment of the code location device based on multi-level structured annotation of the present invention;

[0026] Figure 3 This is a schematic diagram of the structure of a computer device that implements the code location method based on multi-level structured annotations according to a preferred embodiment of the present invention. Detailed Implementation

[0027] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be described in detail below with reference to the accompanying drawings and specific embodiments.

[0028] like Figure 1 The diagram shown is a flowchart of a preferred embodiment of the code location method based on multi-level structured annotations of the present invention. The order of the steps in this flowchart can be changed, and some steps can be omitted, depending on different requirements.

[0029] The code location method based on multi-level structured annotations is applied to one or more computer devices. The computer device is a device that can automatically perform numerical calculations and / or information processing according to pre-set or stored instructions. Its hardware includes, but is not limited to, microprocessors, application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), digital signal processors (DSPs), embedded devices, etc.

[0030] The computer device can be any electronic product that can interact with the user, such as a personal computer, tablet computer, smartphone, personal digital assistant (PDA), game console, interactive network television (IPTV), smart wearable device, etc.

[0031] The computer equipment may also include network equipment and / or user equipment. The network equipment includes, but is not limited to, a single network server, a server group consisting of multiple network servers, or a cloud based on cloud computing consisting of a large number of hosts or network servers.

[0032] The server can be a standalone server or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content delivery networks (CDN), and big data and artificial intelligence platforms.

[0033] Artificial intelligence (AI) is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results.

[0034] Foundational technologies for artificial intelligence generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing, operating / interactive systems, and mechatronics. AI software technologies mainly encompass computer vision, robotics, biometrics, speech processing, natural language processing, and machine learning / deep learning.

[0035] The network in which the computer device is located includes, but is not limited to, the Internet, wide area network, metropolitan area network, local area network, and virtual private network (VPN).

[0036] S10, obtain the source code file generated based on the multi-level structured annotation specification, and identify the position association information between the annotation information and the corresponding code line in the source code file.

[0037] In this embodiment, before obtaining the source code file generated based on the multi-level structured annotation specification, the method further includes:

[0038] Obtain the predefined multi-level structured annotation specification;

[0039] The multi-level structured annotation specification can include class level, method level, and line level.

[0040] The annotations are in a machine-readable format, and each annotation includes one or more of the following: reqIds, module, domain, scenario, logicId, and variable list.

[0041] The machine-parseable format may include JSON (JavaScript Object Notation), key-value pairs, and other parsable formats.

[0042] The requirement number is used to associate with product requirements or user stories; the module and the domain are used to identify business modules; the scenario identifier may include "create order" or "initiate refund"; the logic identifier is used to uniquely identify a certain logic segment; and the variable list represents the key variables involved in the current logic block.

[0043] Of course, each comment can also include other optional attribute fields, such as priority, security level, risk level, etc.

[0044] The multi-level structured annotation specification can be in any language. For example, the multi-level structured annotation specification can adopt the following format:

[0045] (1) Class Annotation:

[0046] / / @C_ANNOT: { "module": "order", "domain": "payment settlement", "reqIds": ["R-1001","R-1002"]}

[0047] public class OrderSettlementService { ...

[0048] }

[0049] (2) Method Annotation:

[0050] / / @M_ANNOT: { "scenario": "Create order", "entryType": "API", "reqIds":["R-1001"], "importantVars": ["totalAmount","discount"]}

[0051] public Order createOrder(...) { ...

[0052] }

[0053] (3) Line Annotation:

[0054] / / @L_ANNOT: { "logicId": "L-CreateOrder-DiscountCheck", "description": "Discount range verification", "vars": ["discount","maxDiscount"], "reqIds":["R-1001"]}

[0055] if (discount > maxDiscount) { ...

[0056] }

[0057] Through the above embodiments, a unified and structured annotation standard can be established, which solves the problems of fragmented traditional annotation formats, inconsistent semantics, and difficulty in machine parsing, laying the foundation for subsequent semantic extraction and association.

[0058] In this embodiment, the source code file can be obtained from a code repository or development environment, supporting various types such as backend code, frontend code, and script code.

[0059] Furthermore, comment areas and code areas can be identified through syntax analysis, preserving the positional association information between comment information and adjacent code lines, thereby ensuring that they are aligned when parsing using a syntax tree later.

[0060] S11, perform structural parsing on the source code file to obtain an abstract syntax tree (AST), and align the comment information to the corresponding code structure node in the abstract syntax tree according to the position association information to obtain a code structure model.

[0061] In this embodiment, aligning the annotation information to the corresponding code structure node in the abstract syntax tree based on the position association information to obtain the code structure model includes:

[0062] Traverse each code structure node in the abstract syntax tree and record the line number range of the corresponding code structure in the source code file at each code structure node;

[0063] Based on the line number range corresponding to each recorded code structure node and the position association information, determine the comment information corresponding to each code structure node;

[0064] Add the comment information corresponding to each code structure node to the corresponding code structure node to obtain the code structure model;

[0065] The code structure nodes include class nodes, method nodes, and line nodes.

[0066] The code structure model is a hierarchical model that includes classes, methods, lines of code, or blocks of statements. Through the code structure model, combined data of code structure nodes and comment text can be obtained.

[0067] Through the above embodiments, a hierarchical structure model of code can be established, achieving precise alignment between comment information and code structure nodes, solving the problem of weak correlation between traditional comments and code, and providing structural support for multi-level semantic merging.

[0068] S12, according to the multi-level structured annotation specification, merge the annotation information corresponding to each code structure node in the code structure model to obtain multi-level annotation hierarchy information.

[0069] In this embodiment, merging the comment information corresponding to each code structure node in the code structure model according to the multi-level structured comment specification to obtain multi-level comment hierarchy information includes:

[0070] Generating an annotation object corresponding to each code structure node includes: for class annotation information corresponding to each class node, identifying fragments in the class annotation information that conform to the multi-level structured annotation specification, and generating a class-level annotation object based on the identified fragments; for method annotation information corresponding to each method node, identifying fragments in the method annotation information that conform to the multi-level structured annotation specification, and generating a method-level annotation object based on the identified fragments; for line annotation information corresponding to each line node, identifying fragments in the line annotation information that conform to the multi-level structured annotation specification, and generating a line-level annotation object based on the identified fragments.

[0071] For any line node in the code structure model, the annotation objects corresponding to the arbitrary line node are merged according to the merging strategy to obtain the multi-level annotation hierarchy information;

[0072] The merging strategy includes: for each requirement number included in each annotation, calculating the union of the requirement numbers included in the corresponding class-level annotation object, method-level annotation object, and line-level annotation object as the merged requirement number; for each module or domain included in each annotation, taking the modules or domains included in the corresponding method-level annotation object or line-level annotation object as the merged module or domain, and taking the modules or domains included in the corresponding class-level annotation object as the merged module or domain when the corresponding method-level annotation object and line-level annotation object are missing; for each variable list included in each annotation, taking the variable list included in the corresponding line-level annotation object as the merged variable list, and adding the important declared variables included in the corresponding method-level annotation object to the merged variable list.

[0073] For example: the class-level annotation object can be represented as CAnnot, which contains class-level business semantic information (such as module, domain, reqIds, etc.); the method-level annotation object can be represented as MAnnot, which contains information such as scenario, entry type, method-level associated requirements and variables; the line-level annotation object can be represented as LAnnot, which contains logical identifier, line-level associated requirements, descriptive information and variables involved in the line of code.

[0074] Specifically, for any line of code, if the line itself contains a LAnnot, then Cannot, MAnnot, and LAnnot are merged according to their hierarchy. If the line does not contain all the information of the three levels of annotations (e.g., missing class-level or method-level annotation objects), then only the existing annotation objects of the current level in the line are used to construct the semantic information, rather than forcibly requiring all three levels of annotation objects to exist.

[0075] For each requirement number included in each comment, a weighted set of requirement numbers included in the corresponding class-level comment object, method-level comment object, and line-level comment object can be calculated and used as the merged requirement number.

[0076] Through the above embodiments, semantic fusion of multi-level comments can be achieved to form a complete business semantic context of the code line, which solves the problems of coarse granularity and semantic fragmentation of traditional comments and can support fine-grained semantic tracing.

[0077] S13, Generate a set of line-level semantic markup objects based on the multi-level annotation hierarchy information and the code structure model.

[0078] In this embodiment, generating a set of line-level semantic markup objects based on the multi-level annotation hierarchy information and the code structure model includes:

[0079] Extract basic location fields from the code structure model, and extract business semantic fields from the multi-level annotation hierarchy information;

[0080] Generate a line-level semantic tag object corresponding to each line of code based on the basic location field and the business semantic field;

[0081] The set of line-level semantic markup objects is generated based on the line-level semantic markup object corresponding to each line of code.

[0082] The basic fields may include, but are not limited to: line number (the line number of the code line node can be directly extracted), file path (the storage path of the source code file to which the code line node belongs can be extracted), class and method information (the class name and method name can be extracted through the node's hierarchy; if the class node contains a package path, the complete class path can be supplemented), etc.

[0083] The business semantic fields may include, but are not limited to:

[0084] (1) Inherited module and domain tags: Extracted according to the merging strategy, prioritizing module tags of method-level and line-level comments (such as "order"), and inheriting module tags of class-level comments (such as "order" of class-level CAnnot) when missing; the same applies to domain tags;

[0085] (2) Inherited scenario tags: mainly extract the scenario of method-level comments (such as "create order"). If there are fine-grained scenarios in the row-level comments (such as "discount verification sub-scenario"), they are added to the scenario field.

[0086] (3) The combined reqIds set: take the union of class, method, and line comment reqIds (e.g., ["R-1001", "R-1002"]).

[0087] (4) logicId (if any): Only extract the logicId of line-level comments (such as "L-CreateOrder-DiscountCheck"). This field is empty when there are no line-level comments.

[0088] (5) vars list and business meaning description: Extract the merged vars list and obtain the corresponding business meaning from MAnnot or LAnnot.

[0089] In cases where it is necessary to support code location based on variable name or business meaning, variable impact scope analysis, or key variables declared in line-level comments, it is also possible to further analyze the variable read and write behavior in that line of code (e.g., through variable reference analysis in AST), and bind the variable names appearing in the code to the business meanings corresponding to the vars field in line-level or method-level comments, thereby establishing a mapping relationship from variable name to business meaning.

[0090] Storing each line-level semantic tag object, LineSemanticMeta, into a line-level semantic tag collection can provide a data foundation for subsequent index building.

[0091] Through the above embodiments, each line of code is given a standardized and structured semantic label, which realizes the association between variable names and business meanings, solves the problem of ambiguous variable semantics (such as multiple meanings for variables with the same name), and provides core data for subsequent multidimensional index construction.

[0092] S14, in response to a location request triggered by the target code, respond to the location request according to the set of line-level semantic markup objects and the multidimensional index library to obtain the located target code line.

[0093] In this embodiment, before responding to the location request based on the row-level semantic tag object set and the multidimensional index library, the method further includes:

[0094] A multidimensional index library supporting row-level positioning is constructed based on the set of row-level semantic tag objects.

[0095] Specifically, constructing a multidimensional index library supporting row-level positioning based on the set of row-level semantic tag objects includes:

[0096] Configure multiple index dimensions;

[0097] The multidimensional index library is constructed based on the set of row-level semantic tag objects and the multiple index dimensions;

[0098] Specifically, for each index dimension of the row-level semantic tag object set corresponding to the enumerated multi-value field, an inverted index supporting fast retrieval by value inclusion is constructed for the enumerated multi-value field; for each index dimension of the row-level semantic tag object set corresponding to the unique mapping field, a key-value index supporting equality queries is constructed for the unique mapping field; and for each index dimension of the row-level semantic tag object set corresponding to the natural language field, a vector index supporting semantic similarity retrieval is constructed for the natural language field.

[0099] Specifically, the multidimensional index is incrementally updated at preset time intervals or when code changes are detected. For example, when only minor code changes occur, only the indexes of the affected rows can be updated, improving the system's usability and efficiency.

[0100] The index dimension may include, but is not limited to:

[0101] Indexed by request ID (reqId): Enables quick retrieval of all relevant lines of code from the request ID;

[0102] Create indexes based on business modules and domains;

[0103] Build indexes by scenario;

[0104] Create an index based on the logical identifier (logicId);

[0105] Create indexes by variable name or by the business meaning of the variable.

[0106] The enumerated multi-value fields may include, but are not limited to, enumerable multi-value fields such as requirement number, module identifier, domain identifier, scenario identifier, and logical identifier. By constructing an inverted index for the enumerated multi-value fields, fast retrieval by value can be supported.

[0107] The unique mapping field may include, but is not limited to, fields with approximately one-to-one mappings, such as logical identifiers, file paths plus line numbers, and line-level semantic markers. By constructing a key-value index for the unique mapping field, exact equality queries can be supported.

[0108] The natural language fields may include, but are not limited to, natural language description fields in class-level, method-level, and line-level comments, as well as variable business meaning description fields. By constructing vector indexes for the natural language fields, semantic similarity retrieval can be supported based on text vectors.

[0109] In addition, candidates can be filtered first using inverted indexes or key-value indexes according to actual needs, and then the candidate results can be sorted according to semantic relevance using vector indexes, thereby improving retrieval performance and semantic matching ability.

[0110] The index can be updated periodically or incrementally after code changes to ensure that the index is synchronized with the latest code status.

[0111] Through the above embodiments, an efficient and multi-dimensional retrieval index system can be constructed, supporting fast queries from multiple dimensions such as business semantics (requirements, scenarios) and technical identifiers (variable names, logicId), solving the problems of redundant results and inaccurate positioning in traditional full-text search.

[0112] In this embodiment, the target code can be the code to be located that is uploaded along with the location request.

[0113] In this embodiment, the location request can be triggered by relevant technical personnel (such as R&D personnel).

[0114] In this embodiment, responding to the location request based on the line-level semantic tag object set and the multidimensional index library to obtain the located target code line includes:

[0115] Parse the location request to obtain the request parameters;

[0116] The target index dimension is obtained from the plurality of index dimensions based on the request parameters;

[0117] Based on the target index dimension, a query is performed in the multidimensional index library to obtain the target row-level semantic tag object;

[0118] Extract the line position information of the target line-level semantic markup object;

[0119] The target code line is located in the target code based on the code line location information;

[0120] Specifically, the target code line is displayed according to a visibility display strategy, and the corresponding comment information of the target code line is displayed synchronously at a preset position.

[0121] The request parameters may include, but are not limited to, one or more of the following combinations: request number (e.g., "R-1001"); business scenario (e.g., "create order"); variable name or variable business meaning (e.g., "discount verification"); logical identifier (e.g., "L-CreateOrder-DiscountCheck"), etc.

[0122] The code line location information may include file path, line number range, etc.

[0123] When integrated into an IDE (Integrated Development Environment) or code browsing tool, the matched target code line can be highlighted and displayed in the sidebar or floating window, showing the class-level, method-level, and line-level comments inherited from that line, enabling developers to quickly understand the business semantics and variable meanings of that line of code.

[0124] Specifically, when the number of matching row-level results exceeds a preset threshold, or when the user chooses to browse the query results by class or method structure, the search results can be aggregated and displayed hierarchically by class, method, and row. Specifically, the matched classes and their target method lists can be displayed first. Only after receiving a user-triggered instruction to expand the corresponding methods can the corresponding row-level code results and their semantic tagging information be displayed.

[0125] Through the above embodiments, precise positioning and visualization from business semantics to lines of code can be achieved, supporting flexible multi-dimensional queries, reducing manual search time in troubleshooting, requirement changes, and code review, and improving the maintainability and traceability of large software systems.

[0126] As can be seen from the above technical solutions, this invention can uniformly configure multi-level structured comment specifications, solving the problems of fragmented comment formats, inconsistent semantics, and difficulty in machine parsing; it identifies the positional association information between comment information and corresponding code lines in source code files, ensuring the accuracy of the positional binding between comments and code; it aligns comment information to the corresponding code structure nodes in the abstract syntax tree based on the positional association information, achieving precise alignment between comments and code structure nodes, solving the problem of weak association between traditional comments and code; it merges the comment information corresponding to each code structure node in the code structure model according to the multi-level structured comment specifications, solving the problems of coarse granularity and semantic fragmentation in traditional comments; it generates a set of line-level semantic tag objects based on the multi-level comment hierarchy information and the code structure model, assigning standardized and structured semantic tags to each line of code; and it responds to location requests based on the set of line-level semantic tag objects and a multi-dimensional index library, thereby achieving accurate and rapid location of code lines.

[0127] like Figure 2 The diagram shown is a functional block diagram of a preferred embodiment of the code location device based on multi-level structured annotations of the present invention. The code location device 11 based on multi-level structured annotations includes an identification unit 110, an alignment unit 111, a merging unit 112, a generation unit 113, and a response unit 114. The module / unit referred to in this invention refers to a series of computer program segments that can be executed by a processor and perform a fixed function, and are stored in memory. In this embodiment, the functions of each module / unit will be described in detail in subsequent embodiments.

[0128] The identification unit 110 is used to obtain source code files generated based on multi-level structured annotation specifications, and to identify the position association information between the annotation information of the source code file and the corresponding code line.

[0129] The alignment unit 111 is used to perform structural parsing on the source code file to obtain an abstract syntax tree, and to align the comment information to the corresponding code structure node in the abstract syntax tree according to the position association information to obtain a code structure model.

[0130] The merging unit 112 is used to merge the annotation information corresponding to each code structure node in the code structure model according to the multi-level structured annotation specification to obtain multi-level annotation hierarchy information.

[0131] The generation unit 113 is used to generate a set of line-level semantic tag objects based on the multi-level annotation hierarchy information and the code structure model.

[0132] The response unit 114 is used to respond to a location request triggered by the target code, and respond to the location request according to the set of line-level semantic markup objects and the multidimensional index library to obtain the located target code line.

[0133] As can be seen from the above technical solutions, this invention can uniformly configure multi-level structured comment specifications, solving the problems of fragmented comment formats, inconsistent semantics, and difficulty in machine parsing; it identifies the positional association information between comment information and corresponding code lines in source code files, ensuring the accuracy of the positional binding between comments and code; it aligns comment information to the corresponding code structure nodes in the abstract syntax tree based on the positional association information, achieving precise alignment between comments and code structure nodes, solving the problem of weak association between traditional comments and code; it merges the comment information corresponding to each code structure node in the code structure model according to the multi-level structured comment specifications, solving the problems of coarse granularity and semantic fragmentation in traditional comments; it generates a set of line-level semantic tag objects based on the multi-level comment hierarchy information and the code structure model, assigning standardized and structured semantic tags to each line of code; and it responds to location requests based on the set of line-level semantic tag objects and a multi-dimensional index library, thereby achieving accurate and rapid location of code lines.

[0134] like Figure 3 The diagram shown is a schematic representation of the structure of a computer device that implements the code location method based on multi-level structured annotations according to a preferred embodiment of the present invention.

[0135] The computer device 1 may include a memory 12, a processor 13, and a bus (the arrow in the figure represents the bus), and may also include a computer program stored in the memory 12 and executable on the processor 13, such as a code locator based on multi-level structured annotations.

[0136] Those skilled in the art will understand that the schematic diagram is merely an example of computer device 1 and does not constitute a limitation on computer device 1. Computer device 1 can be either a bus topology or a star topology. Computer device 1 may also include more or fewer other hardware or software than shown in the diagram, or different component arrangements. For example, computer device 1 may also include input / output devices, network access devices, etc.

[0137] It should be noted that the computer device 1 described is merely an example. Other existing or future electronic products that are adaptable to this invention should also be included within the scope of protection of this invention and are incorporated herein by reference.

[0138] The memory 12 includes at least one type of readable storage medium, such as flash memory, portable hard drive, multimedia card, card-type memory (e.g., SD or DX memory), magnetic memory, magnetic disk, optical disk, etc. In some embodiments, the memory 12 can be an internal storage unit of the computer device 1, such as a portable hard drive of the computer device 1. In other embodiments, the memory 12 can be an external storage device of the computer device 1, such as a plug-in portable hard drive, Smart Media Card (SMC), Secure Digital (SD) card, Flash Card, etc., equipped on the computer device 1. Furthermore, the memory 12 can include both internal and external storage units of the computer device 1. The memory 12 can be used not only to store application software and various types of data installed on the computer device 1, such as code for code locators based on multi-level structured comments, but also to temporarily store data that has been output or will be output.

[0139] In some embodiments, the processor 13 may be composed of integrated circuits, such as a single packaged integrated circuit or multiple integrated circuits packaged with the same or different functions, including combinations of one or more central processing units (CPUs), microprocessors, digital processing chips, graphics processors, and various control chips. The processor 13 is the control unit of the computer device 1, connecting various components of the computer device 1 via various interfaces and lines. It executes programs or modules stored in the memory 12 (e.g., executing code location programs based on multi-level structured comments) and calls data stored in the memory 12 to perform various functions of the computer device 1 and process data.

[0140] The processor 13 executes the operating system of the computer device 1 and various installed applications. The processor 13 executes the applications to implement the steps in the above embodiments of the code location method based on multi-level structured annotations, for example... Figure 1 The steps are shown.

[0141] For example, the computer program may be divided into one or more modules / units, which are stored in the memory 12 and executed by the processor 13 to complete the present invention. The one or more modules / units may be a series of computer-readable instruction segments capable of performing a specific function, which describe the execution process of the computer program in the computer device 1. For example, the computer program may be divided into an identification unit 110, an alignment unit 111, a merging unit 112, a generation unit 113, and a response unit 114.

[0142] The integrated unit implemented as a software functional module described above can be stored in a computer-readable storage medium. This software functional module, stored in a storage medium, includes several instructions to cause a computer device (which may be a personal computer, computer equipment, or network device, etc.) or processor to execute portions of the code location method based on multi-level structured annotations described in various embodiments of the present invention.

[0143] If the modules / units integrated in the computer device 1 are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, all or part of the processes in the methods of the above embodiments of the present invention can also be implemented by a computer program instructing related hardware devices. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the various method embodiments described above.

[0144] The computer program includes computer program code, which may be in the form of source code, object code, executable file, or some intermediate form. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording media, USB flash drive, portable hard drive, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory, etc.

[0145] Furthermore, the computer-readable storage medium may primarily include a stored program area and a stored data area, wherein the stored program area may store the operating system, an application program required for at least one function, etc.; and the stored data area may store data created based on the use of blockchain nodes, etc.

[0146] The blockchain referred to in this invention is a novel application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanisms, and encryption algorithms. Essentially, a blockchain is a decentralized database, a chain of data blocks linked together using cryptographic methods. Each data block contains information about a batch of network transactions, used to verify the validity of the information (anti-counterfeiting) and generate the next block. A blockchain can include an underlying blockchain platform, a platform product service layer, and an application service layer.

[0147] The bus can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. This bus can be divided into address bus, data bus, control bus, etc. For ease of representation, in... Figure 3 The bus is represented by only one straight line, but this does not mean that there is only one bus or one type of bus. The bus is configured to enable communication between the memory 12 and at least one processor 13, etc.

[0148] Although not shown, the computer device 1 may also include a power supply (such as a battery) to power various components. Preferably, the power supply can be logically connected to the at least one processor 13 through a power management device, thereby enabling functions such as charging management, discharging management, and power consumption management. The power supply may also include one or more DC or AC power supplies, recharging devices, power fault detection circuits, power converters or inverters, power status indicators, and other arbitrary components. The computer device 1 may also include various sensors, Bluetooth modules, Wi-Fi modules, etc., which will not be described in detail here.

[0149] Furthermore, the computer device 1 may also include a network interface. Optionally, the network interface may include a wired interface and / or a wireless interface (such as a Wi-Fi interface, a Bluetooth interface, etc.), which is typically used to establish communication connections between the computer device 1 and other computer devices.

[0150] Optionally, the computer device 1 may further include a user interface, which may be a display, an input unit (such as a keyboard), and optionally, a standard wired interface or a wireless interface. Optionally, in some embodiments, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, or an OLED (Organic Light-Emitting Diode) touchscreen, etc. The display may also be appropriately referred to as a screen or display unit, used to display information processed in the computer device 1 and to display a visual user interface.

[0151] It should be understood that the embodiments described are for illustrative purposes only and are not limited to this structure in the scope of the patent application.

[0152] It will be understood by those skilled in the art that Figure 3 The structure shown does not constitute a limitation on the computer device 1, and may include fewer or more components than shown, or combine certain components, or have different component arrangements.

[0153] Combination Figure 1 The memory 12 in the computer device 1 stores multiple instructions to implement a code location method based on multi-level structured annotations, and the processor 13 can execute the multiple instructions to achieve:

[0154] Obtain source code files generated based on multi-level structured commenting specifications, and identify the relationship between comment information and corresponding code line positions in the source code files;

[0155] The source code file is parsed to obtain an abstract syntax tree, and the comment information is aligned to the corresponding code structure node in the abstract syntax tree according to the position association information to obtain a code structure model;

[0156] According to the multi-level structured annotation specification, the annotation information corresponding to each code structure node in the code structure model is merged to obtain multi-level annotation hierarchy information;

[0157] A set of line-level semantic marker objects is generated based on the multi-level annotation hierarchy information and the code structure model;

[0158] In response to a location request triggered by the target code, the location request is responded to according to the set of line-level semantic markup objects and the multidimensional index library to obtain the located target code line.

[0159] Specifically, the processor 13's implementation method for the above instructions can be found in [reference needed]. Figure 1 The descriptions of the relevant steps in the corresponding embodiments are not repeated here.

[0160] It should be noted that all the data involved in this case was legally obtained.

[0161] If any AI models, software tools, or components not belonging to this company appear in the embodiments of this invention, they are merely illustrative examples and do not represent actual use. All user personal information involved in the embodiments of this invention has been obtained by an entity authorized (with the knowledge and consent) or fully authorized by all parties through various legal and compliant means. The collection, storage, use, processing, transmission, provision, and disclosure of the information, data, and signals involved all comply with relevant laws and regulations and do not violate public order and good morals.

[0162] In the several embodiments provided by this invention, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of modules is only a logical functional division, and other division methods may be used in actual implementation.

[0163] This invention can be used in a wide variety of general-purpose or special-purpose computer system environments or configurations. Examples include: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, and distributed computing environments including any of the above systems or devices. This invention can be described in the general context of computer-executable instructions, such as program modules, that are executed by a computer. Generally, program modules include routines, programs, objects, components, data structures, etc., that perform specific tasks or implement specific abstract data types. This invention can also be practiced in distributed computing environments where tasks are performed by remote processing devices connected via a communication network. In distributed computing environments, program modules can reside in local and remote computer storage media, including storage devices.

[0164] The modules described as separate components may or may not be physically separate. The components shown as modules may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs.

[0165] Furthermore, the functional modules in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or in the form of hardware plus software functional modules.

[0166] It will be apparent to those skilled in the art that the present invention is not limited to the details of the exemplary embodiments described above, and that the present invention can be implemented in other specific forms without departing from the spirit or essential characteristics of the present invention.

[0167] Therefore, the embodiments should be considered exemplary and non-limiting in all respects, and the scope of the invention is defined by the appended claims rather than the foregoing description. Thus, all variations falling within the meaning and scope of equivalents of the claims are intended to be embraced within the invention. No appended diagram markings in the claims should be construed as limiting the scope of the claims.

[0168] Furthermore, it is clear that the word "comprising" does not exclude other units or steps, and the singular does not exclude the plural. Multiple units or devices described in this invention can also be implemented by a single unit or device through software or hardware. Terms such as "first," "second," etc., are used to indicate names and do not indicate any specific order.

[0169] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and are not intended to limit it. Although the present invention has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can be made to the technical solutions of the present invention without departing from the spirit and scope of the technical solutions of the present invention.

Claims

1. A code location method based on multi-level structured comments, characterized in that, The code location method based on multi-level structured annotations includes: Obtain source code files generated based on multi-level structured commenting specifications, and identify the relationship between comment information and corresponding code line positions in the source code files; The source code file is parsed to obtain an abstract syntax tree, and the comment information is aligned to the corresponding code structure node in the abstract syntax tree according to the position association information to obtain a code structure model; According to the multi-level structured annotation specification, the annotation information corresponding to each code structure node in the code structure model is merged to obtain multi-level annotation hierarchy information, including: generating class-level annotation objects, method-level annotation objects, and line-level annotation objects corresponding to each code structure node according to the multi-level structured annotation specification; for any line node in the code structure model, merging the annotation objects corresponding to any line node according to the merging strategy to obtain the multi-level annotation hierarchy information; wherein, the merging strategy includes: for the requirement number included in each annotation, calculating the corresponding class-level annotation object, method-level annotation object, and line-level annotation. The union of all requirement numbers included in the object is taken as the merged requirement number; for each module or domain included in each comment, the modules or domains included in the corresponding method-level comment object or line-level comment object are taken as the merged module or domain, and if the corresponding method-level comment object and line-level comment object are missing, the modules or domains included in the corresponding class-level comment object are taken as the merged module or domain; for each variable list included in each comment, the variable list included in the corresponding line-level comment object is taken as the merged variable list, and important declared variables included in the corresponding method-level comment object are added to the merged variable list; The process of generating a set of line-level semantic marker objects based on the multi-level annotation hierarchy information and the code structure model includes: extracting basic position fields from the code structure model and extracting business semantic fields from the multi-level annotation hierarchy information; generating a line-level semantic marker object corresponding to each line of code based on the basic position fields and the business semantic fields; and generating the set of line-level semantic marker objects based on the line-level semantic marker objects corresponding to each line of code. The basic position fields include line number, file path, class, and method information. The business semantic fields include inherited modules, domain tags, inherited scenario identifier tags, a comprehensive set of requirement numbers, logical identifiers, a variable list, and a description of business meaning. When there are no line-level annotation objects, the logical identifier is an empty field. In response to a location request triggered by the target code, the location request is responded to according to the set of line-level semantic markup objects and the multidimensional index library to obtain the located target code line.

2. The code location method based on multi-level structured annotations as described in claim 1, characterized in that, Before obtaining the source code file generated based on the multi-level structured annotation specification, the method further includes: Obtain the predefined multi-level structured annotation specification.

3. The code location method based on multi-level structured annotations as described in claim 2, characterized in that, The step of aligning the annotation information to the corresponding code structure node in the abstract syntax tree based on the position association information to obtain the code structure model includes: Traverse each code structure node in the abstract syntax tree and record the line number range of the corresponding code structure in the source code file at each code structure node; Based on the line number range corresponding to each recorded code structure node and the position association information, determine the comment information corresponding to each code structure node; Add the comment information corresponding to each code structure node to the corresponding code structure node to obtain the code structure model; The code structure nodes include class nodes, method nodes, and line nodes.

4. The code location method based on multi-level structured annotations as described in claim 1, characterized in that, Before responding to the location request based on the row-level semantic tag object set and the multidimensional index library, the method further includes: Configure multiple index dimensions; The multidimensional index library is constructed based on the set of row-level semantic tag objects and the multiple index dimensions; Specifically, for each index dimension of the row-level semantic tag object set corresponding to the enumerated multi-value field, an inverted index supporting fast retrieval by value inclusion is constructed for the enumerated multi-value field; for each index dimension of the row-level semantic tag object set corresponding to the unique mapping field, a key-value index supporting equality queries is constructed for the unique mapping field; and for each index dimension of the row-level semantic tag object set corresponding to the natural language field, a vector index supporting semantic similarity retrieval is constructed for the natural language field. Specifically, the multidimensional index library is incrementally updated every preset time interval or when a code change is detected.

5. The code location method based on multi-level structured annotations as described in claim 4, characterized in that, The step of responding to the location request based on the set of line-level semantic markup objects and the multidimensional index library to obtain the located target code line includes: Parse the location request to obtain the request parameters; The target index dimension is obtained from the plurality of index dimensions based on the request parameters; Based on the target index dimension, a query is performed in the multidimensional index library to obtain the target row-level semantic tag object; Extract the line position information of the target line-level semantic markup object; The target code line is located in the target code based on the code line location information; Specifically, the target code line is displayed according to a visibility display strategy, and the corresponding comment information of the target code line is displayed synchronously at a preset position.

6. A code location device based on multi-level structured annotations, characterized in that, The code location device based on multi-level structured annotations includes: The identification unit is used to acquire source code files generated based on multi-level structured annotation specifications, and to identify the position association information between the annotation information and the corresponding code lines in the source code files; The alignment unit is used to perform structural parsing on the source code file to obtain an abstract syntax tree, and to align the comment information to the corresponding code structure node in the abstract syntax tree according to the position association information to obtain a code structure model; The merging unit is used to merge the comment information corresponding to each code structure node in the code structure model according to the multi-level structured comment specification to obtain multi-level comment hierarchy information. This includes: generating class-level comment objects, method-level comment objects, and line-level comment objects corresponding to each code structure node according to the multi-level structured comment specification; for any line node in the code structure model, merging the comment objects corresponding to that line node according to a merging strategy to obtain the multi-level comment hierarchy information; wherein, the merging strategy includes: for each comment's requirement number, calculating the corresponding class-level comment object, method-level comment object, and line-level comment object. The union of all requirement numbers included in the line-level comment object is used as the merged requirement number; for each module or domain included in the comment, the module or domain included in the corresponding method-level comment object or line-level comment object is used as the merged module or domain, and if the corresponding method-level comment object and line-level comment object are missing, the module or domain included in the corresponding class-level comment object is used as the merged module or domain; for each variable list included in the comment, the variable list included in the corresponding line-level comment object is used as the merged variable list, and important declared variables included in the corresponding method-level comment object are added to the merged variable list; The generation unit is configured to generate a set of line-level semantic marker objects based on the multi-level annotation hierarchy information and the code structure model, including: extracting basic position fields from the code structure model and extracting business semantic fields from the multi-level annotation hierarchy information; generating a line-level semantic marker object corresponding to each line of code based on the basic position fields and the business semantic fields; and generating the set of line-level semantic marker objects based on the line-level semantic marker objects corresponding to each line of code. The basic position fields include line number, file path, class, and method information. The business semantic fields include inherited modules, domain tags, inherited scenario identifier tags, a comprehensive set of requirement numbers, logical identifiers, a variable list, and a description of business meaning; and the logical identifier is an empty field when there are no line-level annotation objects. The response unit is used to respond to a location request triggered based on the target code, and respond to the location request according to the set of line-level semantic markup objects and the multidimensional index library to obtain the located target code line.

7. A computer device, characterized in that, The computer device includes: A memory for storing at least one instruction; and a processor for executing the instructions stored in the memory to implement the code location method based on multi-level structured annotations as described in any one of claims 1 to 5.

8. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores at least one instruction, which is executed by a processor in a computer device to implement the code location method based on multi-level structured annotations as described in any one of claims 1 to 5.