Code component definition consistency detection method and device, electronic equipment and storage medium

By receiving the associated information of the code management tool and the static analysis tool to generate an abstract syntax tree, and automatically compare the code warehouse and tool definition information, it solves the inefficiency and error-prone problems in code component definition inconsistency detection, and achieves efficient and accurate automatic detection.

CN120540689APending Publication Date: 2025-08-26BEIJING KINGSOFT CLOUD NETWORK TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510646604.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-05-19
Publication Date
2025-08-26

AI Technical Summary

Technical Problem

Existing code management tools are inefficient and error-prone in detecting inconsistencies in code component definition information, especially in large projects, which is difficult to ensure the timeliness and accuracy of detection.

Method used

By receiving the associated information provided by the code management tool, we regularly obtain the definition information of the code warehouse and code class files, use static analysis tools to generate an abstract syntax tree, and automatically compare the component definition information with the tool definition information to realize the consistency detection of code component definitions.

Benefits of technology

It realizes automatic detection of code component definition information, improves detection efficiency and accuracy, and reduces the inefficiency and error-proneness of manual detection.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120540689A_ABST
    Figure CN120540689A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a code component definition consistency detection method and device, electronic equipment and a storage medium, and the method comprises the steps: in a program design stage, receiving associated information which is provided by a code management tool and is related to a to-be-detected code component, and the associated information comprises a code warehouse address, a code class file path and a class name; in the program development stage, tool definition information of a to-be-detected code component defined in the code management tool is obtained regularly, and component definition information of the to-be-detected code component is obtained based on a code warehouse address, a code class file path and a class name; and performing consistency detection on the to-be-detected code component definition based on information comparison of the component definition information and the tool definition information. According to the technical scheme, the component definition information and the tool definition information are obtained regularly, automatic comparison between the component definition information and the tool definition information is achieved, and therefore automatic detection of code component definition consistency is completed, and low efficiency and error-prone performance of traditional manual field-by-field detection are completely replaced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the field of computer data processing technology, and in particular to a method, device, electronic device, and storage medium for detecting consistency of code component definitions. Background Art

[0002] In the current software development process, the design and management of code components (such as interfaces, frameworks, modules, and tool classes) face severe challenges. Although existing code management tools (such as the Dubbo management tool) can provide basic code component management capabilities, these tools have obvious limitations: when developers bypass the code management tool and directly modify files related to the definition information of code components, the definition information set in the code management tool and the definition information in the file will be inconsistent. This inconsistency can seriously affect team collaboration efficiency because the definition information obtained by other developers based on the code management tool may be outdated or inaccurate.

[0003] Currently, the primary technical solution to this problem relies on manual field-by-field testing, a method that is both inefficient and error-prone. Especially in large projects with a large number of code components and complex relationships, the workload of manual testing increases exponentially, making it difficult to ensure timely and accurate testing. Summary of the Invention

[0004] In view of this, the embodiments of the present application provide a method, device, electronic device and storage medium for detecting the consistency of code component definitions, which can automatically and accurately detect the consistency of code component definitions, effectively alleviating the technical problems of low detection efficiency and easy detection errors caused by manual detection.

[0005] In a first aspect, an embodiment of the present application provides a method for detecting consistency of code component definitions, the method comprising:

[0006] During the program design phase, the code management tool receives associated information related to the code component to be detected, wherein the associated information includes the code repository address, the code class file path, and the class name corresponding to the code component to be detected;

[0007] During the program development phase, tool definition information of the code component to be detected defined in the code management tool is periodically obtained, and component definition information of the code component to be detected is obtained based on the code repository address, the code class file path, and the class name;

[0008] The consistency check of the code component definition to be checked is performed based on the information comparison between the component definition information and the tool definition information.

[0009] Optionally, as in the aforementioned method, obtaining the component definition information of the code component to be detected based on the code repository address, the code class file path, and the class name includes:

[0010] Determine a code class file according to the code repository address and the code class file path; wherein the code class file includes definition information corresponding to each code component;

[0011] Component definition information of the code component to be detected is obtained based on the code class file and the class name.

[0012] Optionally, as in the aforementioned method, determining the code class file according to the code repository address and the code class file path includes:

[0013] Accessing a code repository based on the code repository address; wherein the code repository stores all code files and the file paths corresponding to each of the code files;

[0014] Searching the code repository for a first target file path that matches the code class file path;

[0015] The code file corresponding to the first target file path is determined as a code class file.

[0016] Optionally, as in the aforementioned method, obtaining the component definition information of the code component to be detected based on the code class file and the class name includes:

[0017] Using a static analysis tool to convert the code class file into an abstract syntax tree; wherein the abstract syntax tree includes a plurality of tree nodes, each of the tree nodes represents a syntax structure in the code class file;

[0018] Traversing the tree nodes of the abstract syntax tree to find a target tree node containing the class name;

[0019] Component definition information of the code component to be detected is obtained from the target tree node.

[0020] Optionally, as in the aforementioned method, converting the code class file into an abstract syntax tree using a static analysis tool includes:

[0021] Load the code class file from the local into the memory;

[0022] Performing lexical analysis on the code class file stored in the memory to obtain a lexical unit stream;

[0023] Organizing the lexical unit stream into a grammatical structure to generate a preliminary grammar tree;

[0024] Abstract processing is performed on the preliminary syntax tree to obtain an abstract syntax tree.

[0025] Optionally, as in the aforementioned method, performing consistency detection of the code component definition to be detected based on the information comparison between the component definition information and the tool definition information includes:

[0026] comparing whether the amount of information in the component definition information is the same as the amount of information in the tool definition information;

[0027] In the case where the amount of information in the component definition information is different from the amount of information in the tool definition information, detecting that the definition of the code component to be detected is inconsistent;

[0028] When the number of information in the component definition information is the same as the number of information in the tool definition information, comparing each data in the component definition information with the corresponding data in the tool definition information to see whether they are the same;

[0029] When comparing each data in the component definition information with each corresponding data in the tool definition information, detecting that the definitions of the code component to be detected are consistent;

[0030] In the case that at least one data in the component definition information is different from the corresponding data in the tool definition information, it is detected that the definition of the code component to be detected is inconsistent.

[0031] Optionally, as in the aforementioned method, after detecting that the definition of the code component to be detected is inconsistent, the method further includes:

[0032] Generate prompt information;

[0033] The prompt information is sent to the user end, so that the user can modify the component definition information in the code class file or modify the tool definition information in the code management tool, so that the component definition information is consistent with the tool definition information.

[0034] In a second aspect, an embodiment of the present application provides a device for detecting consistency of code component definitions, the device comprising:

[0035] A receiving module is used to receive, during the program design phase, association information related to the code component to be detected provided by a code management tool, wherein the association information includes the code repository address, the code class file path, and the class name corresponding to the code component to be detected;

[0036] an acquisition module, configured to periodically acquire tool definition information of the code component to be detected defined in the code management tool during a program development phase, and to acquire component definition information of the code component to be detected based on the code repository address, the code class file path, and the class name;

[0037] The detection module is used to perform consistency detection of the code component definition to be detected based on the comparison of the component definition information with the tool definition information.

[0038] In a third aspect, an embodiment of the present application provides an electronic device, which includes: a processor and a memory, the processor being used to execute a program for code component definition consistency detection stored in the memory to implement the above-mentioned code component definition consistency detection method.

[0039] In a fourth aspect, an embodiment of the present application provides a storage medium, wherein the storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to implement the above-mentioned method for code component definition consistency detection.

[0040] The embodiments of the present application provide a method, device, electronic device and storage medium for detecting the consistency of code component definitions. The method includes: in the program design stage, receiving associated information related to the code component to be detected provided by the code management tool, wherein the associated information includes the code warehouse address, the code class file path and the class name corresponding to the code component to be detected; in the program development stage, regularly obtaining the tool definition information of the code component to be detected defined in the code management tool, and, based on the code warehouse address, the code class file path and the class name, obtaining the component definition information of the code component to be detected; and performing consistency detection of the definition of the code component to be detected based on the information comparison between the component definition information and the tool definition information. In the above technical solution, by regularly obtaining the component definition information and the tool definition information in the code management tool, an automatic comparison between the two is realized, thereby completing the automatic detection of the consistency of the code component definition. This method completely replaces the inefficiency and error-proneness of traditional manual field-by-field detection, thereby improving the efficiency and accuracy of detection. BRIEF DESCRIPTION OF THE DRAWINGS

[0041] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.

[0042] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0043] Figure 1 A flowchart of an embodiment of a method for detecting consistency of code component definitions provided in an embodiment of the present application;

[0044] Figure 2 A flowchart of another embodiment of a method for detecting consistency of code component definitions provided in an embodiment of the present application;

[0045] Figure 3 A flowchart of another embodiment of a method for detecting consistency of code component definitions provided in an embodiment of the present application;

[0046] Figure 4 A flowchart of another embodiment of a method for detecting consistency of code component definitions provided in an embodiment of the present application;

[0047] Figure 5 A flowchart of another embodiment of a method for detecting consistency of code component definitions provided in an embodiment of the present application;

[0048] Figure 6 A block diagram of an embodiment of a device for detecting consistency of code component definitions provided in an embodiment of the present application;

[0049] Figure 7 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0050] To make the purpose, technical solutions, and advantages of the embodiments of this application more clear, the technical solutions in the embodiments of this application will be clearly and completely described below in conjunction with the drawings in the embodiments of this application. Obviously, the described embodiments are part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.

[0051] It should be noted that the terms "first", "second", etc. in the description and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that the numbers used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0052] References to "one embodiment" or "some embodiments" in this specification mean that a particular feature, structure, or characteristic described in conjunction with that embodiment is included in one or more embodiments of the present application. Thus, phrases such as "in one embodiment," "in some embodiments," "in other embodiments," and "in other embodiments" appearing in various places in this specification do not necessarily refer to the same embodiment, but rather mean "one or more but not all embodiments," unless otherwise specifically emphasized. The terms "including," "comprising," "having," and variations thereof all mean "including but not limited to," unless otherwise specifically emphasized.

[0053] The embodiments of the present application can acquire and process relevant data based on artificial intelligence technology. Artificial intelligence refers to the theories, methods, technologies, and application systems that use digital computers or machines controlled by digital computers to simulate, extend, and expand human intelligence, perceive the environment, acquire knowledge, and use knowledge to achieve optimal results.

[0054] Fundamental AI technologies generally include sensors, dedicated AI chips, cloud computing, storage, big data processing, operating / interaction systems, and mechatronics. AI software technologies primarily encompass computer vision, robotics, biometrics, speech processing, natural language processing, and machine learning / deep learning.

[0055] It should be understood that the size of the serial numbers of the steps in the following embodiments does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application.

[0056] To facilitate understanding of the embodiments of the present application, further explanation will be given below with reference to specific embodiments in conjunction with the accompanying drawings. The embodiments do not constitute a limitation on the embodiments of the present application.

[0057] The present application embodiment provides a method for detecting consistency of code component definitions. The method is applied to a code export tool, which is an independent platform or application, for detecting consistency of code component definitions in the present embodiment. Figure 1 , Figure 1 A flowchart of an embodiment of a method for detecting consistency of code component definitions provided in an embodiment of the present application. Figure 1 The process shown may include the following steps:

[0058] Step 101: During the program design phase, receive association information related to the code component to be detected provided by a code management tool, wherein the association information includes the code repository address, the code class file path, and the class name corresponding to the code component to be detected;

[0059] In actual application, the aforementioned code management tool communicates with the code export tool, so that after the developer completes the design and definition of the definition information of the code component to be checked (such as the name, type, scope, and other metadata used to describe and constrain the code component) using the code management tool during the program design phase, the developer will send the associated information related to the code component to be checked to the code export tool to provide a data foundation for subsequent code component definition consistency testing. The process of designing and defining the definition information of the code component using the code management tool is prior art content and will not be described in detail here.

[0060] The code repository address in the above-mentioned associated information is the remote repository location where the code files are stored, usually presented in the form of a URL (Uniform Resource Locator); the code class file path refers to the specific location of the code class file that stores the definition information corresponding to each code component (the directory structure in the code repository), which is used to clearly specify the storage location of the file; the class name is a logical name that uniquely identifies the code component to be detected. In object-oriented programming, the class name must follow the language specifications (such as Java's class name and file name are mandatory to be consistent) and project conventions, so it has strong uniqueness and standardization. Because the class name usually remains unchanged during the code life cycle, using the class name as a benchmark can reduce the volatility of the logic during detection.

[0061] Step 102: During the program development phase, tool definition information of the code component to be detected defined in the code management tool is periodically obtained, and component definition information of the code component to be detected is obtained based on the code repository address, code class file path, and class name.

[0062] In order to ensure the accuracy of the online program, it is necessary to perform consistency testing of code component definitions during the program development phase. In specific implementation, the code export tool periodically obtains the tool definition information of the code component to be tested in the code management tool through the class name. The tool definition information can be understood as the definition information designed by the developer for the code component to be tested using the code management tool; and the code export tool obtains the component definition information based on the above-mentioned association information. The component definition information refers to the definition information about the code component to be tested that objectively exists in the code class file.

[0063] The above timing can be set according to actual needs, such as 3 minutes, 5 minutes or 10 minutes, etc., which is not limited here.

[0064] In actual application, in addition to obtaining component definition information and tool definition information through timing, the code export tool can also obtain tool definition information and component definition information when the developer triggers the detection control in the code export tool.

[0065] Step 103 : performing consistency detection of the code component definition to be detected based on the information comparison between the component definition information and the tool definition information.

[0066] After the code export tool obtains the tool definition information and component definition information through step 102, it can automatically detect whether the definition in the code management tool is consistent with the objectively existing definition based on the information comparison of the component definition information and the tool definition information. The information comparison includes the comparison of the quantity and specific data of the tool definition information and the component definition information. The specific information comparison process is described in the following embodiment and is not described in detail here. In this embodiment, since no manual detection is required in the process of detecting the consistency of code component definitions according to the above steps 101 to 103, the inefficiency and error-proneness of manual detection are greatly reduced, thereby improving the efficiency and accuracy of detection.

[0067] Through the method in this embodiment, the code export tool can periodically obtain component definition information and tool definition information in the code management tool, realize automatic comparison between the two, and thereby complete automatic detection of code component definition consistency. This method completely replaces the inefficiency and error-proneness of traditional manual field-by-field detection, thereby improving the efficiency and accuracy of detection.

[0068] like Figure 2 As shown, as an optional implementation, as in the aforementioned method, step 102 of obtaining component definition information of the code component to be detected based on the code repository address, code class file path, and class name includes the following steps:

[0069] Step 201: Determine a code class file based on the code repository address and the code class file path; wherein the code class file includes definition information corresponding to each code component;

[0070] like Figure 3 As shown, as an optional implementation, the implementation process of step 201 can be implemented through the following steps:

[0071] Step 301: access the code repository based on the code repository address; wherein the code repository stores all code files and the file paths corresponding to each code file;

[0072] In practice, you can clone or remotely access a code repository based on its address using command-line tools, graphical tools, or the code hosting platform's website. This allows you to retrieve all code files stored in the repository, along with the file paths corresponding to each file. For local analysis, you can use git clone to download the entire repository locally. If you only need to read files, some tools, such as the GitHub API (Application Programming Interface), support direct remote access.

[0073] Step 302: searching the code repository for a first target file path that matches the code class file path.

[0074] Since the file path corresponding to each code file in the code repository is unique, the code class file can be found from multiple code files through the code class file path. In specific implementation, all file paths can be recursively listed through git ls-files or the file system API, and then regular expressions or wildcard libraries (such as glob) can be used to filter out the first target file path that matches the code class file path.

[0075] Step 303: Determine the code file corresponding to the first target file path as a code class file.

[0076] The code file corresponding to the first target file path found in step 302 is determined as a code class file for subsequent use. This method of directly determining the code class file through path matching can avoid manual search and reduce errors.

[0077] Step 202: Obtain component definition information of the code component to be detected based on the code class file and the class name.

[0078] like Figure 4 As shown, as an optional implementation, the implementation process of step 202 can be implemented through the following steps:

[0079] Step 401, using a static analysis tool to convert the code class file into an abstract syntax tree;

[0080] Among them, the abstract syntax tree includes multiple tree nodes, each tree node represents a grammatical structure in the code-like file; the abstract syntax tree strips away redundant symbols (such as brackets and semicolons) in the code-like file in a tree structure, retaining only key grammatical elements such as definitions and expressions, and represents the code logic with a hierarchical relationship of the tree, realizing accurate semantic analysis and automated processing for easy subsequent use.

[0081] The specific process of converting the code class file into an abstract syntax tree can be achieved through steps A1 to A4:

[0082] Step A1: Load the code class file from the local computer into the memory;

[0083] In actual applications, in order to speed up the loading speed, the code repository needs to be downloaded locally, and then the code class files stored locally are loaded into the memory to avoid network delays and reduce the overhead of repeatedly downloading the code repository.

[0084] Step A2, performing lexical analysis on the code class file stored in the memory to obtain a lexical unit stream;

[0085] Specifically, a lexer (lexer / scanner) can be used to scan the source code strings in the code class files, so as to ignore irrelevant content (such as spaces, comments) and decompose continuous character sequences into meaningful lexical units to obtain an ordered lexical unit stream. Each lexical unit includes type and value (the value is the specific text content corresponding to the lexical unit) information. For code class files, since the code class files systematically record the complete definition information of each code component, the types that may be identified include: keywords (such as var, let, const, etc.), identifiers (class names), operators (=, :, etc.), separators (commas, semicolons, brackets, etc.), literals (numbers, strings, etc.), etc.

[0086] Step A3, organizing the lexical unit stream into a grammatical structure and generating a preliminary grammar tree;

[0087] This process can use a parser to receive a stream of lexical units as input, and analyze the lexical unit sequence according to the grammatical rules of the language (usually described in BNF (Backus-Naur Form) or similar forms) to construct a preliminary syntax tree (also called a concrete syntax tree or parse tree). Since the preliminary syntax tree usually contains more grammatical details and may contain redundancy, it is necessary to perform the subsequent step A4 to remove the redundancy.

[0088] Step A4: abstract the preliminary syntax tree to obtain an abstract syntax tree.

[0089] Unify the semantic expression, remove nodes that are only used for grammatical structure but do not carry semantic information to remove unnecessary grammatical details (such as pure grammatical elements such as semicolons and brackets), retain the core elements of the code logical structure, and convert the preliminary syntax tree into a more abstract representation. This abstract processing not only retains the complete program semantics, but also avoids the interference of specific grammatical details, which is convenient for subsequent applications.

[0090] Step 402, traverse the tree nodes of the abstract syntax tree to find the target tree node containing the class name;

[0091] Since each tree node includes the type of identifier (class name), the target tree node can be found from multiple tree nodes of the abstract syntax tree by matching the identifier with the class name of the code component to be detected.

[0092] Step 403: Obtain component definition information of the code component to be detected from the target tree node.

[0093] In this embodiment, the component definition information of the code component to be detected included in the target tree node can be obtained by direct access.

[0094] Through the above steps, the definition information of the component to be tested can be accurately extracted from the source code based on the code class file and class name. In addition, the code export tool is based on static code technology when obtaining component definition information. Since there is no need to run the entire project, the export efficiency is greatly improved compared to the existing export of definition information using the reflection mechanism.

[0095] like Figure 5 As shown, as an optional implementation, as in the aforementioned method, step 103 of performing consistency detection of the code component definition to be detected based on the information comparison between the component definition information and the tool definition information includes the following steps:

[0096] Step 501 , comparing the number of information in the component definition information and the number of information in the tool definition information to see if they are the same;

[0097] This information quantity refers to the number of fields. Consistency in the amount of information is a prerequisite for data completeness. Differences in quantity can directly expose structural deviations and trigger alarms without in-depth field-level inspections. The primary line of defense established through quantity comparison can significantly reduce the complexity of subsequent field-level detection and is a key strategy for balancing detection accuracy and execution efficiency.

[0098] When the amount of information in the comparison component definition information is different from the amount of information in the tool definition information, step 502 is executed to detect inconsistency in the definition of the code component to be detected, that is, the tool definition information defined in the code management tool and the component definition information objectively existing in the code class file are inconsistent, and subsequent field-level comparison is terminated to improve detection efficiency.

[0099] When the amount of information in the comparison component definition information is the same as the amount of information in the tool definition information, step 503 is executed to further perform field-level comparison detection.

[0100] Step 502: Detect inconsistency in the definition of the code component to be detected;

[0101] Step 503: Compare the contents of each field in the component definition information with the contents of the corresponding fields in the tool definition information to see if they are the same;

[0102] It is triggered only when the number of information is consistent to ensure that the comparison dimensions are aligned. The comparison range is to compare the field content of each field in the component definition information with the corresponding field content in the tool definition information one by one. For example, the field content corresponding to the type in the component definition information is compared with the field content corresponding to the type in the tool definition information, and the field content corresponding to the scope in the component definition information is compared with the field content corresponding to the scope in the tool definition information. These are not described in detail here.

[0103] When the contents of each field in the component definition information are identical to the contents of the corresponding fields in the tool definition information, that is, the contents of all corresponding fields in the component definition information and the tool definition information are completely consistent, step 504 is executed to detect whether the definition of the code component to be detected is consistent.

[0104] In the case where the content of at least one field in the compared component definition information is different from the corresponding field content in the tool definition information, for example, the content of the field corresponding to the type in the component definition information is different from the content of the field corresponding to the type in the tool definition information, or the content of the field corresponding to the scope in the component definition information is different from the content of the field corresponding to the scope in the tool definition information, or the content of the field corresponding to the type in the component definition information is different from the content of the field corresponding to the type in the tool definition information and the content of the field corresponding to the scope in the component definition information is different from the content of the field corresponding to the scope in the tool definition information, execute step 505 to detect inconsistency in the definition of the code component to be detected.

[0105] Step 504: Check if the definitions of the code components to be checked are consistent;

[0106] Step 505: Detect whether the definitions of the code components to be detected are inconsistent.

[0107] In actual application, in order to ensure the consistency of tool design and objective definition, a prompt message can be generated after detecting inconsistency in the definition of the code component to be detected; the prompt message is sent to the user end so that the user can modify the component definition information in the code class file or modify the tool definition information in the code management tool to make the component definition information consistent with the tool definition information.

[0108] The prompt information may carry the specific content of the inconsistency in the definition of the code component to be detected, and the prompt information may be sent to the user terminal used by the user, such as a mobile phone, computer, or tablet, so that the user can modify the component definition information in the code class file or modify the tool definition information in the code management tool according to the content, so that the component definition information is consistent with the tool definition information, so as to avoid the inconvenience caused by the inconsistency between the tool definition information defined by other relevant personnel in the reference code management tool and the component definition information objectively existing in the code class file.

[0109] This hierarchical detection strategy significantly improves detection efficiency by progressively analyzing quantity first and then content, and is particularly suitable for scenarios involving large-scale code component definition detection.

[0110] See also Figure 6 , is a block diagram of an embodiment of a device for detecting consistency of code component definitions provided in an embodiment of the present application. Figure 6 As shown, the device includes:

[0111] Receiving module 601 is used to receive association information related to the code component to be detected provided by the code management tool during the program design phase, wherein the association information includes the code repository address, the code class file path and the class name corresponding to the code component to be detected;

[0112] An acquisition module 602 is configured to periodically acquire tool definition information of a code component to be detected defined in a code management tool during a program development phase, and to acquire component definition information of the code component to be detected based on a code repository address, a code class file path, and a class name;

[0113] The detection module 603 is used to perform consistency detection of the code component definition to be detected based on the information comparison between the component definition information and the tool definition information.

[0114] Specifically, the specific process of each module in the device of the embodiment of the present invention realizing its function can be referred to the relevant description in the method embodiment, which will not be repeated here.

[0115] As an optional implementation, the acquisition module 602 includes:

[0116] A first determining module is configured to determine a code class file according to the code repository address and the code class file path; wherein the code class file includes definition information corresponding to each code component;

[0117] The first acquisition module is used to acquire component definition information of the code component to be detected based on the code class file and the class name.

[0118] Specifically, the specific process of each module in the device of the embodiment of the present invention realizing its function can be referred to the relevant description in the method embodiment, which will not be repeated here.

[0119] As an optional implementation manner, the first determining module is further configured to:

[0120] Access the code repository based on the code repository address; the code repository stores all code files and the file paths corresponding to each code file;

[0121] Search the code repository for the first target file path that matches the code class file path;

[0122] The code file corresponding to the first target file path is determined as a code class file.

[0123] Specifically, the specific process of each module in the device of the embodiment of the present invention realizing its function can be referred to the relevant description in the method embodiment, which will not be repeated here.

[0124] As an optional implementation manner, the first acquisition module further includes:

[0125] A conversion module, configured to convert the code class file into an abstract syntax tree using a static analysis tool; wherein the abstract syntax tree includes a plurality of tree nodes, each tree node representing a syntax structure in the code class file;

[0126] The traversal module is used to traverse the tree nodes of the abstract syntax tree and find the target tree node containing the class name;

[0127] The second acquisition module is used to acquire component definition information of the code component to be detected from the target tree node.

[0128] Specifically, the specific process of each module in the device of the embodiment of the present invention realizing its function can be referred to the relevant description in the method embodiment, which will not be repeated here.

[0129] As an optional implementation, the conversion module is further configured to:

[0130] Load the code class file from the local into the memory;

[0131] Perform lexical analysis on the code class file stored in the memory to obtain a lexical unit stream;

[0132] Organize the lexical unit stream into a grammatical structure and generate a preliminary grammar tree;

[0133] Perform abstract processing on the preliminary syntax tree to obtain an abstract syntax tree.

[0134] Specifically, the specific process of each module in the device of the embodiment of the present invention realizing its function can be referred to the relevant description in the method embodiment, which will not be repeated here.

[0135] As an optional implementation, the detection module is further configured to:

[0136] Compare the number of information in the component definition information with the number of information in the tool definition information;

[0137] In the case where the amount of information in the comparison component definition information is different from the amount of information in the tool definition information, the code component definition to be detected is inconsistent;

[0138] When the number of information in the compared component definition information is the same as the number of information in the tool definition information, comparing whether the content of each field in the component definition information is the same as the content of each corresponding field in the tool definition information;

[0139] If the contents of each field in the comparison component definition information are identical to the contents of the corresponding fields in the tool definition information, the definitions of the code components to be detected are consistent;

[0140] In the case where the content of at least one field in the comparison component definition information is different from the content of the corresponding field in the tool definition information, it is detected that the definition of the code component to be detected is inconsistent.

[0141] Specifically, the specific process of each module in the device of the embodiment of the present invention realizing its function can be referred to the relevant description in the method embodiment, which will not be repeated here.

[0142] As an optional implementation, the above device further includes:

[0143] A generation module, used to generate prompt information;

[0144] The modification module is used to send prompt information to the user end so that the user can modify the component definition information in the code class file or modify the tool definition information in the code management tool so that the component definition information is consistent with the tool definition information.

[0145] Figure 7 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Figure 7 The electronic device 1200 shown includes: at least one processor 1201, a memory 1202, at least one network interface 1204 and another user interface 1203. The various components in the electronic device 1200 are coupled together via a bus system 1205. It is understood that the bus system 1205 is used to achieve connection and communication between these components. In addition to including a data bus, the bus system 1205 also includes a power bus, a control bus, and a status signal bus. However, for the sake of clarity, the bus system 1205 is not described in detail. Figure 7 Various buses are labeled as bus system 1205.

[0146] The user interface 1203 may include a display, a keyboard, or a pointing device (eg, a mouse, a trackball, a touchpad, or a touch screen).

[0147] It is understood that the memory 1202 in the embodiment of the present application can be a volatile memory or a non-volatile memory, or can include both volatile and non-volatile memories. Among them, the non-volatile memory can be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory can be a random access memory (RAM), which is used as an external cache. By way of example and not limitation, many forms of RAM are available, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate synchronous DRAM (DDRSDRAM), enhanced synchronous DRAM (ESDRAM), synchronous link DRAM (SLDRAM), and direct RAM bus random access memory (DRRAM). The memory 1202 described herein is intended to include, but is not limited to, these and any other suitable types of memory.

[0148] In some embodiments, the memory 1202 stores the following elements, executable units, or data structures, or a subset thereof, or an extended set thereof: an operating system 12021 and application programs 12022 .

[0149] Among them, the operating system 12021 includes various system programs, such as the framework layer, core library layer, and driver layer, which are used to implement various basic services and handle hardware-based tasks. Application 12022 includes various application programs, such as media players and browsers, which are used to implement various application services. The program that implements the method of the embodiment of the present application can be included in application 12022.

[0150] In an embodiment of the present application, by calling a program or instruction stored in the memory 1202, specifically, a program or instruction stored in the application 12022, the processor 1201 is used to execute the method steps provided by each method embodiment.

[0151] The methods disclosed in the above embodiments of the present application can be applied to or implemented by processor 1201. Processor 1201 may be an integrated circuit chip with signal processing capabilities. During implementation, each step of the above method can be completed by hardware integrated logic circuits in processor 1201 or by software instructions. The above processor 1201 may be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. The various methods, steps, and logic block diagrams disclosed in the embodiments of the present application can be implemented or executed. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the methods disclosed in the embodiments of the present application can be directly implemented and executed by a hardware decoding processor, or by a combination of hardware and software units in the decoding processor. The software units can be located in a storage medium mature in the art, such as random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, etc. The storage medium is located in the memory 1202 , and the processor 1201 reads the information in the memory 1202 and completes the steps of the above method in combination with its hardware.

[0152] It is understood that the embodiments described herein may be implemented using hardware, software, firmware, middleware, microcode, or a combination thereof. For hardware implementation, the processing unit may be implemented in one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field-programmable gate arrays (FPGAs), general-purpose processors, controllers, microcontrollers, microprocessors, other electronic units for performing the functions described herein, or a combination thereof.

[0153] For software implementation, the technology described herein can be implemented by a unit that performs the functions described herein. The software code can be stored in a memory and executed by a processor. The memory can be implemented in the processor or outside the processor.

[0154] The electronic device provided in this embodiment may be Figure 7 The electronic device shown in FIG. 1 can perform the following operations: Figure 1-5 The code component defines all the steps of the consistency detection method, thereby achieving Figure 1-6 The technical effects of the code component definition consistency detection method shown are as follows. Figure 1-6 For the sake of brevity, the relevant description will not be repeated here.

[0155] The present application also provides a storage medium (computer-readable storage medium). The storage medium stores one or more programs. The storage medium may include volatile memory, such as random access memory; the memory may also include non-volatile memory, such as read-only memory, flash memory, hard disk, or solid-state drive; and the memory may also include a combination of the aforementioned types of memory.

[0156] When one or more programs in the storage medium can be executed by one or more processors, the above-mentioned method for detecting consistency of code component definitions can be implemented.

[0157] The processor is used to execute the program for code component definition consistency detection stored in the memory to implement the steps of the code component definition consistency detection method.

[0158] Professionals should also be further aware that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the above description has generally described the components and steps of each example according to their functions. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0159] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein may be implemented using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.

[0160] The specific implementation methods described above further illustrate the purpose, technical solutions and beneficial effects of this application. It should be understood that the above description is only the specific implementation methods of this application and is not intended to limit the scope of protection of this application. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of this application should be included in the scope of protection of this application.

Claims

1. A method for detecting consistency of code component definitions, characterized in that: The method comprises: During the program design phase, the code management tool receives associated information related to the code component to be detected, wherein the associated information includes the code repository address, the code class file path, and the class name corresponding to the code component to be detected; During the program development phase, tool definition information of the code component to be detected defined in the code management tool is periodically obtained, and component definition information of the code component to be detected is obtained based on the code repository address, the code class file path, and the class name; The consistency check of the code component definition to be checked is performed based on the information comparison between the component definition information and the tool definition information.

2. The method according to claim 1, characterized in that The obtaining component definition information of the code component to be detected based on the code repository address, the code class file path, and the class name includes: Determine a code class file according to the code repository address and the code class file path; wherein the code class file includes definition information corresponding to each code component; Component definition information of the code component to be detected is obtained based on the code class file and the class name.

3. The method according to claim 2, characterized in that The determining of the code class file according to the code warehouse address and the code class file path includes: Accessing a code repository based on the code repository address; wherein the code repository stores all code files and the file paths corresponding to each of the code files; Searching the code repository for a first target file path that matches the code class file path; The code file corresponding to the first target file path is determined as a code class file.

4. The method according to claim 2, characterized in that The obtaining component definition information of the code component to be detected based on the code class file and the class name includes: Using a static analysis tool to convert the code class file into an abstract syntax tree; wherein the abstract syntax tree includes a plurality of tree nodes, each of the tree nodes represents a syntax structure in the code class file; Traversing the tree nodes of the abstract syntax tree to find a target tree node containing the class name; Component definition information of the code component to be detected is obtained from the target tree node.

5. The method according to claim 4, characterized in that The converting the code class file into an abstract syntax tree using a static analysis tool includes: Load the code class file from the local into the memory; Performing lexical analysis on the code class file stored in the memory to obtain a lexical unit stream; Organizing the lexical unit stream into a grammatical structure to generate a preliminary grammar tree; Abstract processing is performed on the preliminary syntax tree to obtain an abstract syntax tree.

6. The method according to claim 2, characterized in that The performing consistency detection of the code component definition to be detected based on the information comparison between the component definition information and the tool definition information includes: comparing whether the amount of information in the component definition information is the same as the amount of information in the tool definition information; In the case where the amount of information in the component definition information is different from the amount of information in the tool definition information, detecting that the definition of the code component to be detected is inconsistent; When the number of information in the component definition information is the same as the number of information in the tool definition information, comparing the content of each field in the component definition information with the content of each corresponding field in the tool definition information to see whether they are the same; When the contents of each field in the component definition information are compared to the contents of each corresponding field in the tool definition information, detecting that the definitions of the code component to be detected are consistent; In the case that the content of at least one field in the component definition information is different from the content of the corresponding field in the tool definition information, it is detected that the definition of the code component to be detected is inconsistent.

7. The method according to claim 6, characterized in that After detecting that the definition of the code component to be detected is inconsistent, the method further includes: Generate prompt information; The prompt information is sent to the user end, so that the user can modify the component definition information in the code class file or modify the tool definition information in the code management tool, so that the component definition information is consistent with the tool definition information.

8. A device for detecting consistency of code component definitions, characterized in that: The device comprises: A receiving module is used to receive, during the program design phase, association information related to the code component to be detected provided by a code management tool, wherein the association information includes the code repository address, the code class file path, and the class name corresponding to the code component to be detected; an acquisition module, configured to periodically acquire tool definition information of the code component to be detected defined in the code management tool during a program development phase, and to acquire component definition information of the code component to be detected based on the code repository address, the code class file path, and the class name; The detection module is used to perform consistency detection of the code component definition to be detected based on information comparison between the component definition information and the tool definition information.

9. An electronic device, characterized in that: include: A processor and a memory, wherein the processor is configured to execute a program for detecting consistency of code component definitions stored in the memory, so as to implement the method for detecting consistency of code component definitions according to any one of claims 1 to 7.

10. A storage medium, characterized in that: The storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to implement the method for detecting consistency of code component definitions according to any one of claims 1 to 7.