CN117010345A - Method, device, equipment and storage medium for generating function document - Google Patents

Method, device, equipment and storage medium for generating function document Download PDF

Info

Publication number
CN117010345A
CN117010345A CN202311029803.5A CN202311029803A CN117010345A CN 117010345 A CN117010345 A CN 117010345A CN 202311029803 A CN202311029803 A CN 202311029803A CN 117010345 A CN117010345 A CN 117010345A
Authority
CN
China
Prior art keywords
function
file
target
code
abstract syntax
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202311029803.5A
Other languages
Chinese (zh)
Inventor
杨泽伟
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Netease Hangzhou Network Co Ltd
Original Assignee
Netease Hangzhou Network Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Netease Hangzhou Network Co Ltd filed Critical Netease Hangzhou Network Co Ltd
Priority to CN202311029803.5A priority Critical patent/CN117010345A/en
Publication of CN117010345A publication Critical patent/CN117010345A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/10Text processing
    • G06F40/166Editing, e.g. inserting or deleting
    • G06F40/169Annotation, e.g. comment data or footnotes
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/13File access structures, e.g. distributed indices
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/16File or folder operations, e.g. details of user interfaces specifically adapted to file systems
    • G06F16/164File meta data generation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/10Text processing
    • G06F40/12Use of codes for handling textual entities
    • G06F40/14Tree-structured documents

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Audiology, Speech & Language Pathology (AREA)
  • Computational Linguistics (AREA)
  • General Health & Medical Sciences (AREA)
  • Health & Medical Sciences (AREA)
  • Artificial Intelligence (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • Human Computer Interaction (AREA)
  • Stored Programmes (AREA)

Abstract

The application provides a method, a device, equipment and a storage medium for generating a function document, wherein the method comprises the following steps: acquiring a file path corresponding to each function file in a target programming item from an item catalog of the target programming item, and generating a target path tree of the target programming item according to the file path corresponding to each function file; reading and analyzing the code content of each function file in the target path tree, and analyzing the code content of each function file into an abstract syntax tree taking the paraphrasing information of each function as a node; based on the paraphrase information of the functions contained in each abstract syntax tree, a function document for assisting in the explanation of each function in the target programming item is generated. Therefore, the method and the device realize automatic generation of the function document by means of the code characteristics of the function under the condition that a developer does not need to write annotation information for the function manually in advance, so that the generation efficiency and the content accuracy of the function document can be effectively improved.

Description

Method, device, equipment and storage medium for generating function document
Technical Field
The present application relates to the field of computer technologies, and in particular, to a method, an apparatus, a device, and a storage medium for generating a function document.
Background
For a programming item, since a large number of functions with different functions are often required to be used in the programming item, in order to facilitate reading and fast grasp of the roles of the different functions in the programming item, it is often required to sort information such as a use method, parameters, return values and the like of each function in the programming item for specifying the functions into a function document to which the programming item is applicable.
At present, when a function document is generated, the function document is mainly realized by two modes of manually writing by a developer or automatically extracting information based on annotation content compiled in advance by the developer for each function; in this case, in both the manual writing by a developer and the automatic extraction of the information, the developer needs to add comments to the top of each function to describe the relevant information such as the usage method, parameters, and return values of the function in advance during encoding, and the difference is only that after the programming project is completed, the comments are manually checked or automatically extracted by an automated document generation tool. At this time, the workload of the developer is increased due to the annotation writing and adding work, and the accuracy of the content cannot be ensured due to the annotation content manually written by the developer, so that the problems of low function document generating efficiency and low document content accuracy cannot be solved by the two ways of generating the function document.
Disclosure of Invention
Accordingly, the present application is directed to a method, apparatus, device, and storage medium for generating a function document, which can automatically generate a function document by means of code features of a function without requiring a developer to manually write annotation information for the function, so as to effectively improve the efficiency of generating the function document and the accuracy of document content.
In order to make the above objects, features and advantages of the present application more comprehensible, preferred embodiments accompanied with figures are described in detail below.
In a first aspect, an embodiment of the present application provides a method for generating a function document, where the generating method includes:
acquiring a file path corresponding to each function file in a target programming item from an item catalog of the target programming item, and generating a target path tree of the target programming item according to the file path corresponding to each function file; wherein the function file characterizes project files containing function codes;
reading and analyzing the code content of each function file in the target path tree, and analyzing the code content of each function file into an abstract syntax tree taking the paraphrasing information of each function as a node;
Based on paraphrase information of functions contained in each of the abstract syntax trees, a function document for assisting in the explanation of each function in the target programming item is generated.
In a second aspect, an embodiment of the present application provides a generating device for a function document, where the generating device includes:
the path acquisition module is used for acquiring a file path corresponding to each function file in a target programming project from a project catalog of the target programming project, and generating a target path tree of the target programming project according to the file path corresponding to each function file; wherein the function file characterizes project files containing function codes;
the code analysis module is used for analyzing the code content of each function file into an abstract syntax tree taking the paraphrasing information of each function as a node by reading and analyzing the code content of each function file in the target path tree;
and the document generation module is used for generating a function document for carrying out auxiliary explanation on each function in the target programming project based on the paraphrase information of the function contained in each abstract syntax tree.
In a third aspect, an embodiment of the present application provides a computer device, including a memory, a processor, and a computer program stored in the memory and capable of running on the processor, where the processor implements the steps of the method for generating a function document described above when the processor executes the computer program.
In a fourth aspect, an embodiment of the present application provides a computer readable storage medium having stored thereon a computer program which, when executed by a processor, performs the steps of the method for generating a function document described above.
The technical scheme provided by the embodiment of the application can comprise the following beneficial effects:
the embodiment of the application provides a method, a device, equipment and a storage medium for generating a function document, which are used for acquiring a file path corresponding to each function file in a target programming project from a project catalog of the target programming project and generating a target path tree of the target programming project according to the file path corresponding to each function file; reading and analyzing the code content of each function file in the target path tree, and analyzing the code content of each function file into an abstract syntax tree taking the paraphrasing information of each function as a node; based on the paraphrase information of the functions contained in each abstract syntax tree, a function document for assisting in the explanation of each function in the target programming item is generated. Therefore, the method and the device realize automatic generation of the function document by means of the code characteristics of the function under the condition that a developer does not need to write annotation information for the function manually in advance, so that the generation efficiency and the content accuracy of the function document can be effectively improved.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings that are needed in the embodiments will be briefly described below, it being understood that the following drawings only illustrate some embodiments of the present application and therefore should not be considered as limiting the scope, and other related drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
FIG. 1 shows a schematic flow chart of a method for generating a function document according to an embodiment of the present application;
FIG. 2 illustrates a flowchart of a method for generating a target path tree for a target programming item, provided by an embodiment of the present application;
FIG. 3 is a flow chart of another method for obtaining paraphrase information for each function in a target programming item according to an embodiment of the present application;
FIG. 4 is a flowchart illustrating a method for obtaining function codes of each function in a target programming item for problem detection according to an embodiment of the present application;
FIG. 5 is a schematic diagram of a function document generating device according to an embodiment of the present application;
fig. 6 is a schematic structural diagram of an electronic device 600 according to an embodiment of the present application.
Detailed Description
For the purpose of making the objects, technical solutions and advantages of the embodiments of the present application more apparent, the technical solutions of the embodiments of the present application will be clearly and completely described with reference to the accompanying drawings in the embodiments of the present application, and it should be understood that the drawings in the present application are for the purpose of illustration and description only and are not intended to limit the scope of the present application. In addition, it should be understood that the schematic drawings are not drawn to scale. A flowchart, as used in this disclosure, illustrates operations implemented according to some embodiments of the present application. It should be understood that the operations of the flow diagrams may be implemented out of order and that steps without logical context may be performed in reverse order or concurrently. Moreover, one or more other operations may be added to or removed from the flow diagrams by those skilled in the art under the direction of the present disclosure.
In addition, the described embodiments are only some, but not all, embodiments of the application. The components of the embodiments of the present application generally described and illustrated in the figures herein may be arranged and designed in a wide variety of different configurations. Thus, the following detailed description of the embodiments of the application, as presented in the figures, is not intended to limit the scope of the application, as claimed, but is merely representative of selected embodiments of the application. All other embodiments, which can be made by a person skilled in the art without making any inventive effort, are intended to be within the scope of the present application.
It should be noted that the term "comprising" will be used in embodiments of the application to indicate the presence of the features stated hereafter, but not to exclude the addition of other features.
At present, when a function document is generated, the function document is mainly realized by two modes of manually writing by a developer or automatically extracting information based on annotation content compiled in advance by the developer for each function; in this case, in both the manual writing by a developer and the automatic extraction of the information, the developer needs to add comments to the top of each function to describe the relevant information such as the usage method, parameters, and return values of the function in advance during encoding, and the difference is only that after the programming project is completed, the comments are manually checked or automatically extracted by an automated document generation tool. At this time, the workload of the developer is increased due to the annotation writing and adding work, and the accuracy of the content cannot be ensured due to the annotation content manually written by the developer, so that the problems of low function document generating efficiency and low document content accuracy cannot be solved by the two ways of generating the function document.
Based on the above, the embodiment of the application provides a method, a device, equipment and a storage medium for generating a function document, which can realize automatic generation of the function document by means of code characteristics of the function under the condition that a developer does not need to write annotation information for the function manually in advance, thereby effectively improving the generation efficiency and the content accuracy of the function document.
In one embodiment of the present application, a method for generating a function document may be run on a terminal device or a server; the terminal device may be a local terminal device, and when the method for generating the function document operates on the server, the method for generating the function document may be implemented and executed based on a cloud interaction system, where the cloud interaction system includes the server and a client device (i.e., the terminal device); based on this, the embodiment of the present application is not limited in any way with respect to the specific device type of the electronic device running the above-described function document generation method.
In order to facilitate understanding of the embodiments of the present application, a method, an apparatus, a device, and a storage medium for generating a function document provided in the embodiments of the present application are described in detail below.
Referring to fig. 1, fig. 1 shows a flow chart of a method for generating a function document according to an embodiment of the present application, where the control method includes steps S101 to S103; specific:
S101, acquiring a file path corresponding to each function file in a target programming item from an item catalog of the target programming item, and generating a target path tree of the target programming item according to the file path corresponding to each function file.
S102, reading and analyzing the code content of each function file in the target path tree, and analyzing the code content of each function file into an abstract syntax tree taking the paraphrase information of each function as a node.
S103, generating a function document for assisting in explanation of each function in the target programming project based on paraphrase information of the function contained in each abstract syntax tree.
According to the method for generating the function document, provided by the embodiment of the application, a file path corresponding to each function file in a target programming project is obtained from a project catalog of the target programming project, and a target path tree of the target programming project is generated according to the file path corresponding to each function file; reading and analyzing the code content of each function file in the target path tree, and analyzing the code content of each function file into an abstract syntax tree taking the paraphrasing information of each function as a node; based on the paraphrase information of the functions contained in each abstract syntax tree, a function document for assisting in the explanation of each function in the target programming item is generated. Therefore, the method and the device realize automatic generation of the function document by means of the code characteristics of the function under the condition that a developer does not need to write annotation information for the function manually in advance, so that the generation efficiency and the content accuracy of the function document can be effectively improved.
It should be noted that, in a preferred implementation manner, the method for generating a function document provided by the embodiment of the present application may be specifically applied to an operating environment of a target programming language (the operating environment may be installed in the terminal device/the server); the method comprises the steps that through built-in modules and plug-ins with different functions in an operation environment, a file path of each function file can be obtained (namely, the step S101 can be executed), code content of each function file can be read and analyzed (namely, the step S102 can be executed, and meanwhile, the step S103 can be continuously executed according to the abstract syntax tree obtained through analysis); that is, all steps involved in the method for generating the function document can be realized through built-in modules and plug-ins with different functions in the operation environment, and other third party tools except the operation environment are not needed, so that the method is easy to maintain and update, the software and hardware resources required to be consumed for generating the function document can be effectively reduced, and the maintenance cost is saved.
Specifically, the target programming language characterizes a programming language adopted by a target programming project; for example, the target programming language may be JavaScript (a lightweight, interpreted or just-in-time compiled programming language with functional preference) or Python (a widely used interpreted, high-level, and general-purpose programming language); the embodiment of the present application is not limited in any way as to the specific language type to which the target programming language belongs.
Specifically, the operating environments applicable to programming languages based on different language types are different, so that the specific type of the operating environment can be determined according to the specific language type to which the target programming language belongs; for example, when the target programming language belongs to the JavaScript language, the above-mentioned running environment may select a node. Js (an open source JavaScript running environment) running environment applicable to the JavaScript language; when the target programming language belongs to the Python language, the operating environment can select a PyCharm (an integrated development environment) operating environment applicable to the Python language; the embodiments of the present application are also not limited in any way with respect to the specific types of operating environments described above.
The following takes JavaScript as an example of a target programming language adopted by the target programming project, and exemplary descriptions are respectively made for each step in the method for generating the function document according to the embodiment of the present application:
s101, acquiring a file path corresponding to each function file in a target programming item from an item catalog of the target programming item, and generating a target path tree of the target programming item according to the file path corresponding to each function file.
Here, the target programming item may be a conventional programming item such as a build website, or may be a specific programming item that builds a tool function library based on a plurality of packaged tool functions; wherein, the tool function refers to a function which has a certain function and can be called as required at any time like a tool (the function of certain specific functions is not specified); the embodiment of the present application is not limited in any way with respect to the specific item types represented by the target programming item described above.
Specifically, no matter what programming language is adopted to write the target programming item, the target programming item comprises various different types of item files, and the item files can be files independently stored in the target programming item or subfiles nested under a certain folder, and each item file and a corresponding file path of each item file in the target programming item jointly form an item catalog of the target programming item.
Based on this, in the running environment of the target programming language (e.g., node. Js running environment applicable to JavaScript language), by scanning the project directory of the target programming project, the file extension (i.e., suffix name, included in the file name of the project file) and the file path (i.e., absolute path of the project file in the project directory, where the absolute path is used to completely describe the file position of the project file under the project directory) of each project file can be read, at this time, since the function file refers to a project file of a specific type including a function code, the function file can be screened out from all the project files according to the file extension of each project file of different types (e.g., when the target programming language is JavaScript language, the file extension of the project file including the function code is. Js), and the file path corresponding to each function file is obtained to generate the target path tree of the target programming project (i.e., including the tree structure of the file path of each function file in the target programming project).
S102, reading and analyzing the code content of each function file in the target path tree, and analyzing the code content of each function file into an abstract syntax tree taking the paraphrase information of each function as a node.
Here, in the running environment of the target programming language, the code content of each function file in the target path tree can be read out by traversing the target path tree by a code reading tool in the running environment (e.g., an fs module in the node. Js running environment); wherein the code reading tools used in different types of operating environments are different; the embodiment of the present application is not limited in any way with respect to the specific tool type of the code reading tool described above.
Here, after the code content of each function file is read out in the running environment of the target programming language, the code content of each function file can still be parsed by using a compiler in the running environment (for example, in the node. Js running environment, a babel compiler applicable to JavaScript language can be used), without using any other third party tool except the running environment; wherein the code parsing tools (i.e., the compilers described above) used in different types of runtime environments are also different (e.g., the PyCharm runtime environment also includes a Python compiler adapted for Python language); the embodiment of the present application is also not limited in any way with respect to the specific tool types of the code parsing tools described above.
Specifically, when the compiler is used to parse the code content of each function file, the code content of each function file may be parsed into a form of Abstract Syntax Tree (abstract syntax tree); wherein the abstract syntax tree is a tree representation of an abstract syntax structure of a text written in a formal language (typically source code), each node on the abstract syntax tree representing a structure occurring in the text; at this time, since the abstract syntax tree in the embodiment of the present application is obtained by parsing the code content of each function file, in step S102, each function file is parsed into an abstract syntax tree, and each node in each parsed abstract syntax tree represents a structure appearing in each function file.
In the embodiment of the application, the paraphrasing information of the function characterizes the related information for describing the function in detail; wherein, as an alternative embodiment, the paraphrasing information of the function may include, but is not limited to, at least one of the following: function name of the function, parameter name and parameter type of each parameter contained in the function, return value of the function; at this time, the paraphrasing information of the function may be understood as related information that needs to be recorded in the function document according to the actual requirement of the developer, so that the specific information content represented by the paraphrasing information of the function may be determined according to the actual viewing requirement of the developer on the function document, and the embodiment of the present application is not limited in any way.
Based on this, taking an abstract syntax tree parsed by a function file as an example, each node in the abstract syntax tree corresponds to a structure appearing in the function file, and the function file includes function codes of at least one function (i.e., the function file characterizes a project file including the function codes), so in the abstract syntax tree, each function code of the function corresponds to a specific type node (e.g., a node whose type is a Function Declaration function declaration type) for representing the structure of the function code, and under each specific type node, the paraphrasing information (e.g., a function name, a parameter type, a return value of the function, etc.) of the function belongs to a different structure appearing in the function code of the function, so that under each specific type node in the abstract syntax tree, there are different branch nodes capable of representing paraphrasing information of the function of different types, and thus, an abstract syntax tree in which the paraphrasing information of each function is a node is obtained.
S103, generating a function document for assisting in explanation of each function in the target programming project based on paraphrase information of the function contained in each abstract syntax tree.
Here, as is known in conjunction with the description of the step S102, one function file is not entirely composed of function codes (i.e., the code content of the function file includes function codes and also includes codes other than function codes), that is, the abstract syntax tree parsed by the function file also includes other invalid nodes (i.e., nodes unrelated to the generation of the function document) other than the nodes corresponding to the paraphrasing information of the function; based on the above, when generating the function document corresponding to the target programming item, the paraphrase information (such as the function name, the parameter type, the return value of the function, etc.) of each function only needs to be obtained from the abstract syntax tree parsed by each function file.
Specifically, after the paraphrase information of each function in the target programming item is obtained from the abstract syntax tree parsed from each function file, the function document may be generated according to the method described in the following steps a1-a 4:
step a1, aiming at each abstract syntax tree, obtaining an editable code corresponding to a function file of the abstract syntax tree.
Here, the editable codes corresponding to different function files are the same; from the view of code composition structure, the editable code corresponding to each function file consists of blank positions to be filled and filled code contents; the filled code content is used for forming a display style (such as a font style, a character size, a typesetting format and the like) of the function document, and the blank positions needing to be filled represent position areas of paraphrase information needing to be filled in functions in the editable code; that is, the above-mentioned editable code can be understood as a code template for generating a function document.
Here, from the code type point of view, the above-mentioned editable code belongs to the underlying code that can be converted into a visualized HTML template (i.e., web page form), and for example, the editable code may be a markdown (a lightweight markup language) file; embodiments of the present application are not limited in any way with respect to the specific code types of the editable code.
And a2, filling the paraphrase information of the function contained in the abstract syntax tree in the blank positions corresponding to the respective matched type to be filled according to the type to be filled corresponding to each blank position in the editable code, and obtaining the completely filled editable code.
Here, the code content at the filled position in each editable code is determined according to a preset function document display style (such as font style, word size, typesetting format, etc.); the function document display style can be set according to the actual viewing requirement of a developer on the function document, and the embodiment of the application is not limited in any way for specific code content at the filled position in the editable code.
And a3, splicing the editable codes of each function file which are completely filled to obtain a bottom code file corresponding to the function file.
And a4, converting the bottom code file into a target webpage, and displaying the visualized function document to a user through the converted target webpage.
Specifically, taking the example that the editable code belongs to a markdown file, splicing the editable code filled with each complete function file to obtain a complete bottom code file corresponding to the function file, and converting the bottom code file into an HTML template (i.e. the target webpage) based on the complete bottom code file to obtain a visual function file, so that a user (i.e. a developer) can conveniently view the visual function file.
The following details are respectively given for the specific implementation process of each step in the embodiment of the present application:
for the specific implementation process of the step S101, as shown in fig. 2, fig. 2 shows a flowchart of a method for generating a target path tree of a target programming item according to an embodiment of the present application, and when executing the step S101, the method includes steps S201 to S203, specifically:
s201, reading the file extension of each item file in the item directory, and determining the item file with the file extension belonging to the target extension as the function file.
Here, the target extension is determined according to a programming language employed by the target programming item (i.e., target programming language); for example, when the target programming language is JavaScript language, then the target extension is. Js; when the target programming language is the Python language, then the target extension is. Py.
It should be noted that, in different types of programming languages, the target extension for representing the function file is also different, and the specific name of the target extension is not limited in any way in the embodiments of the present application.
S202, obtaining a file path corresponding to each function file from the item catalog, and constructing a first key value pair corresponding to each function file by taking the file name of each function file as a key and the file path corresponding to each function file as a value.
Specifically, taking JavaScript language as an example, in the node.js running environment, an fs module may be used to read an src folder (a folder for storing all java source programs) under a project directory, traverse all project files included under the src folder, use a path module (a module for processing a path in the node.js) in the node.js to obtain an absolute path (i.e. the above-mentioned file path) of each project file, and when a file extension of one project file is read to be.js (i.e. a target extension), determine that the project file belongs to a function file, use a file name of the project file as a key, and use an absolute path of the project file as a value to obtain a first key value pair corresponding to the project file.
S203, generating a target path tree of the target programming item based on the first key value pair corresponding to each function file.
Here, the first key value pair corresponding to each function file is composed of a key (i.e. the file name of the function file) and a value (i.e. the file path of the function file), so that in the finally generated target path tree, only the file name of any one function file needs to be input, the file path of the function file can be returned, and a developer can conveniently and quickly search the file paths of different function files based on the generated target path tree.
For the implementation process of the steps S102 to S103, after the step S102 is performed (i.e., the code content of each function file is parsed into an abstract syntax tree with the paraphrasing information of each function as a node), the paraphrasing information of each function in the target programming item needs to be acquired for generating the function file, at this time, in addition to directly acquiring the paraphrasing information of each function from the abstract syntax tree parsed from each function file, as shown in fig. 3, fig. 3 shows a flowchart of another method for acquiring the paraphrasing information of each function in the target programming item according to the embodiment of the present application, and when performing step S103, the method includes steps S301 to S303, specifically:
S301, traversing each node in the abstract syntax tree aiming at the abstract syntax tree analyzed by each function file, and reading out the paraphrasing information of the function represented by each branch node under the target node from the code content covered under the target node representing the function statement.
Here, the target node characterizes a node of type Function Declaration (function declaration) in the abstract syntax tree; the code content covered under the target node is a function code of a function, and based on the function code, each branch node under the target node corresponds to a structure (e.g., paraphrasing information of functions such as function names, parameter names, etc.) in the function code, so that according to a specific structure in the function code represented by each branch node under each target node, specific paraphrasing information (e.g., function names, parameter names, etc.) of a function represented by each specific structure can be read.
For example, traversing the abstract syntax tree, when encountering a target node with type Function Declaration, determining that structures within the target node belong to function codes, entering the target node at the moment, and continuing traversing; when a first node with a type Assignment Pattern (allocation mode) is encountered, determining that the code content in the first node belongs to the code content related to the function parameter, analyzing the code content in the first node to obtain a parameter default value corresponding to the function parameter, and analyzing the parameter default value through the type of the function provided in JavaScript to obtain the parameter type; the type of function is used for returning the type information as a character string, for example, a parameter default value x is input into the type of function, and when the obtained return value is string, the parameter type is represented as the character string; when the obtained return value is "number", it indicates that the parameter type is a number.
S302, taking a file path of a function file corresponding to the abstract syntax tree as an input parameter of an objective function, and taking paraphrasing information of the function read from the abstract syntax tree as an output parameter of the objective function, and defining to obtain the objective function.
Here, an objective function may be predefined (for example, an analysis File function is defined in advance, a function name of the objective function is not defined in a mandatory manner), a File path of a function File corresponding to each abstract syntax tree is used as an input parameter (i.e., an input parameter) of the objective function, and the reading and parsing steps for the abstract syntax tree in the step S301 are performed on the defined objective function content, so that paraphrase information of the function read in the abstract syntax tree may be used as an output parameter of the objective function; at this time, the defined objective function can output the paraphrase information of the function contained in each function file according to the file path (i.e. input parameters) of each input function file.
S303, traversing the target path tree, obtaining a file path of a function file corresponding to the abstract syntax tree, transmitting the obtained file path into the target function, and outputting and obtaining definition information of the function contained in the abstract syntax tree through the target function.
Specifically, by defining the objective function, the paraphrase information of the function such as the function name, the parameter type, the return value, etc. can be stored in one object (i.e. the function variable of the objective function), which is advantageous to more conveniently display and use the paraphrase information of the function obtained by analysis than the way of outputting only the text result (i.e. directly obtaining the paraphrase information of each function from the abstract syntax tree parsed by each function file).
As can be seen from the specific implementation content of the step S103, in the embodiment of the present application, the basic function of the function document is to assist in explaining each function in the target programming project, and on this basis, besides the paraphrase information (such as the function name, the parameter type, the return value of the function, etc.) of the function, the developer can customize the analysis scheme of the code content of each function document more flexibly according to the actual viewing requirement of the function document, so that other key information (key information that does not overlap with the paraphrase information of the function) meeting the actual requirement can be obtained from the code content of each function document through the customized analysis scheme, and the obtained other key information and the paraphrase information of the function are recorded in the function document together, so that the finally generated function document can practically meet the personalized customization requirement of the developer for the function document.
Based on this, taking an example of an object code detection tool (a tool for performing problem searching and repairing on a code written in an object programming language) built in an operating environment of the object programming language, when a developer wants to perform problem detection on a function code of each function in the object programming project, and records a problem detection result of each function in a function document, as an optional implementation manner, as shown in fig. 4, fig. 4 shows a flowchart of a method for obtaining a function code of each function in the object programming project to perform problem detection according to an embodiment of the present application, when executing step S103, the method further includes steps S401-S403, specifically:
s401, detecting the function code content belonging to the function in each function file by using an object code detection tool to obtain the total number of the function code lines of each function in each function file and the number of error function code lines with errors.
Here, the object code detection tool is determined from the programming language of the object programming item (i.e., the object programming language); for example, when the target programming language is JavaScript language, then the target code detection tool may be an eslin tool (for finding and repairing problems in JavaScript code); when the target programming language is the Python language, then the eslin tool need only be replaced adaptively with a relevant code detection tool that is adapted to find and fix the problem in the Python code.
Specifically, taking an eslin tool as an example, the purpose of code detection in the application is mainly related to generating a function document, so that compared with the whole analysis of the code content of a function file, the method can lock the partial code content of the function between the starting line and the ending line in the code content of the function file as the function code content of the function file belonging to the function, thereby using the eslin tool to only detect problems of the function code content of the function in each function file, analyzing the error rate of each function, knowing the code quality more comprehensively and avoiding the limitation of detecting the error rate of the whole function file.
S402, calculating the code error rate of each function in each function file according to the proportion of the error function code line number of each function in each function file in the total function code line number.
For example, the error function code line number of a function is 2 lines, the total function code line number is 10 line examples, and the code error rate of the function is 20%.
S403, storing the total number of the function codes, the number of the error function codes and the code error rate of each function in each function file into the function file.
Here, in combination with the description about the objective function in the steps S301 to S303, similar to the explanation information of the function, the total number of the function codes, the number of the error function codes, and the code error rate of each function in a function file may be used as the output parameters of the objective function taking the file name of the function file as the input parameter, so as to store the problem detection result of the function code (i.e., the total number of the function codes, the number of the error function codes, and the code error rate of each function) and the explanation information of the function together into the same object (i.e., the function variable of the objective function), which is convenient for the subsequent data management and data display of the function file.
On the basis of the above steps S401-S403, as another optional implementation manner, besides the problem detection result in the function codes (i.e. the total number of function codes, the number of error function codes and the code error rate of each function), by means of the rule dictionary in the object code detection tool, it is also possible to detect whether the naming of each function meets the naming rule specified in the rule dictionary according to the method described in the following steps b1-b2, so that the obtained naming detection result of each function is also stored in the finally generated function document, so that it is convenient for the developer to check and correct the function code corresponding to the function whose naming has an error in time, specifically:
And b1, detecting whether the naming format of each function and/or the spelling of the function name in each function file accords with the code rules defined in the rule dictionary by utilizing a rule dictionary in an object code detection tool, and obtaining a naming detection result of each function in each function file.
Here, in the target code detection tool, code rules to be complied with by different functions in the target programming language are specified in the rule dictionary; code rules include, but are not limited to: the function needs to conform to a specific naming format (for example, the function is named by using English lowercase letters), and the function name needs to conform to a grammar spelling rule (for example, the function name needs to belong to an actually existing English vocabulary, and cannot be a custom semantic-free vocabulary).
Based on this, in addition to detecting the code error rate in the function code according to the method described in the above steps S401 to S403, it is also possible to detect whether there is an error in the naming format of each function and/or the spelling of the function name (i.e., does not conform to the code rules defined in the rule dictionary) using the rule dictionary in the object code detection tool.
And b2, storing the naming detection result of each function in each function file into the function file.
Here, the embodiment of step b2 is the same as the above-mentioned step S403, and the repetition is not repeated here.
For the method for generating the function document described in the above steps S101 to S103, it should be noted that, for a target programming project, it is considered that the target programming language adopted by the target programming project generally belongs to a dynamic language (for example, javaScript speech is just a dynamic language), and the paraphrase information such as the parameter type of the function and the type of the function return value in the dynamic language may change.
Based on the method for generating the function document provided by the embodiment of the application, a file path corresponding to each function file in a target programming project is obtained from a project catalog of the target programming project, and a target path tree of the target programming project is generated according to the file path corresponding to each function file; reading and analyzing the code content of each function file in the target path tree, and analyzing the code content of each function file into an abstract syntax tree taking the paraphrasing information of each function as a node; based on the paraphrase information of the functions contained in each abstract syntax tree, a function document for assisting in the explanation of each function in the target programming item is generated. Therefore, the method and the device realize automatic generation of the function document by means of the code characteristics of the function under the condition that a developer does not need to write annotation information for the function manually in advance, so that the generation efficiency and the content accuracy of the function document can be effectively improved.
Based on the same inventive concept, the application also provides a generating device corresponding to the generating method of the function document, and because the principle of the generating device in the embodiment of the application for solving the problem is similar to that of the generating method of the function document in the embodiment of the application, the implementation of the generating device can refer to the implementation of the generating method, and the repetition is omitted.
Referring to fig. 5, fig. 5 shows a schematic structural diagram of a function document generating apparatus according to an embodiment of the present application, where the generating apparatus includes:
the path obtaining module 501 is configured to obtain a file path corresponding to each function file in a target programming item from an item directory of the target programming item, and generate a target path tree of the target programming item according to the file path corresponding to each function file; wherein the function file characterizes project files containing function codes;
a code parsing module 502, configured to parse the code content of each function file into an abstract syntax tree with the paraphrasing information of each function as a node by reading and parsing the code content of each function file in the target path tree;
A document generating module 503, configured to generate a function document for performing an auxiliary description on each function in the target programming item based on paraphrase information of the function included in each abstract syntax tree.
In an alternative embodiment, the path acquisition module 501 is configured to generate the target path tree of the target programming item by:
reading a file extension of each item file in the item directory, and determining the item file with the file extension belonging to the target extension as the function file; the target extension name is determined according to a programming language adopted by the target programming item;
acquiring a file path corresponding to each function file from the item catalog, and constructing a first key value pair corresponding to each function file by taking the file name of each function file as a key and the file path corresponding to each function file as a value;
and generating a target path tree of the target programming item based on the first key value pair corresponding to each function file.
In an alternative embodiment, the document generating module 503 is configured to obtain paraphrase information of the functions included in each abstract syntax tree by:
Traversing each node in the abstract syntax tree aiming at the abstract syntax tree analyzed by each function file, and reading out paraphrasing information of functions represented by each branch node under a target node representing function statement from code content covered under the target node;
the method comprises the steps of taking a file path of a function file corresponding to the abstract syntax tree as an input parameter of an objective function, taking paraphrasing information of the function read from the abstract syntax tree as an output parameter of the objective function, and defining to obtain the objective function;
traversing the target path tree, obtaining a file path of a function file corresponding to the abstract syntax tree, transmitting the obtained file path into the target function, and outputting and obtaining definition information of the function contained in the abstract syntax tree through the target function.
In an alternative embodiment, when generating the function document for assisting in describing each function in the target programming item based on the paraphrase information of the function included in each abstract syntax tree, the document generating module 503 is configured to:
aiming at each abstract syntax tree, obtaining an editable code corresponding to a function file of the abstract syntax tree; wherein the editable codes corresponding to different function files are the same;
According to the to-be-filled type corresponding to each blank position in the editable code, filling the paraphrasing information of the function contained in the abstract syntax tree in the blank positions corresponding to the respectively matched to-be-filled types respectively to obtain a completely filled editable code; the code content at the filled position in the editable code is determined according to a preset function document display style;
splicing the editable codes of each function file which are completely filled to obtain a bottom code file corresponding to the function file;
and converting the bottom code file into a target webpage, and displaying the visualized function document to a user through the converted target webpage.
In an alternative embodiment, the generating device further comprises a code detection module, wherein the code detection module is configured to:
detecting the function code content belonging to the function in each function file by using an object code detection tool to obtain the total number of the function code lines of each function in each function file and the number of error function code lines with errors; wherein the object code detection tool is determined according to a programming language of the object programming item;
Calculating the code error rate of each function in each function file according to the proportion of the error function code line number of each function in each function file in the total function code line number;
and storing the total number of the function codes, the number of the error function codes and the code error rate of each function in each function file into the function file.
In an alternative embodiment, the code detection module is further configured to:
detecting whether the naming format and/or the spelling of the function name of each function in each function file accords with the code rules defined in the rule dictionary by utilizing a rule dictionary in an object code detection tool to obtain a naming detection result of each function in each function file;
and storing the naming detection result of each function in each function file into the function file.
In an optional implementation manner, the generating device is applied to an operation environment of a target programming language, wherein a file path of each function file is obtained and code content of each function file is read and analyzed through built-in modules and plug-ins with different functions in the operation environment; the target programming language characterizes a programming language employed by the target programming project.
Based on the generating device of the function document provided by the embodiment of the application, a file path corresponding to each function file in a target programming project is obtained from a project catalog of the target programming project, and a target path tree of the target programming project is generated according to the file path corresponding to each function file; reading and analyzing the code content of each function file in the target path tree, and analyzing the code content of each function file into an abstract syntax tree taking the paraphrasing information of each function as a node; based on the paraphrase information of the functions contained in each abstract syntax tree, a function document for assisting in the explanation of each function in the target programming item is generated. Therefore, the method and the device realize automatic generation of the function document by means of the code characteristics of the function under the condition that a developer does not need to write annotation information for the function manually in advance, so that the generation efficiency and the content accuracy of the function document can be effectively improved.
Based on the same inventive concept, the application also provides an electronic device corresponding to the method for generating the function document, and since the principle of solving the problem of the electronic device in the embodiment of the application is similar to that of the method for generating the function document in the embodiment of the application, the implementation of the electronic device can refer to the implementation of the method for generating the function document, and the repetition is omitted.
Fig. 6 is a schematic structural diagram of an electronic device 600 according to an embodiment of the present application, including: the electronic device comprises a processor 601, a memory 602 and a bus 603, wherein the memory 602 stores machine-readable instructions executable by the processor 601, when the electronic device runs a method for generating a function document as in the embodiment, the processor 601 and the memory 602 communicate through the bus 603, the processor 601 executes the machine-readable instructions, and the processor 601 executes the machine-readable instructions to implement the following steps:
acquiring a file path corresponding to each function file in a target programming item from an item catalog of the target programming item, and generating a target path tree of the target programming item according to the file path corresponding to each function file; wherein the function file characterizes project files containing function codes;
reading and analyzing the code content of each function file in the target path tree, and analyzing the code content of each function file into an abstract syntax tree taking the paraphrasing information of each function as a node;
based on paraphrase information of functions contained in each of the abstract syntax trees, a function document for assisting in the explanation of each function in the target programming item is generated.
In an alternative embodiment, processor 601 is configured to generate a target path tree for the target programming item by:
reading a file extension of each item file in the item directory, and determining the item file with the file extension belonging to the target extension as the function file; the target extension name is determined according to a programming language adopted by the target programming item;
acquiring a file path corresponding to each function file from the item catalog, and constructing a first key value pair corresponding to each function file by taking the file name of each function file as a key and the file path corresponding to each function file as a value;
and generating a target path tree of the target programming item based on the first key value pair corresponding to each function file.
In an alternative embodiment, the processor 601 is configured to obtain the paraphrase information of the functions included in each abstract syntax tree after parsing the code content of each function file into the abstract syntax tree with the paraphrase information of each function as a node by:
traversing each node in the abstract syntax tree aiming at the abstract syntax tree analyzed by each function file, and reading out paraphrasing information of functions represented by each branch node under a target node representing function statement from code content covered under the target node;
The method comprises the steps of taking a file path of a function file corresponding to the abstract syntax tree as an input parameter of an objective function, taking paraphrasing information of the function read from the abstract syntax tree as an output parameter of the objective function, and defining to obtain the objective function;
traversing the target path tree, obtaining a file path of a function file corresponding to the abstract syntax tree, transmitting the obtained file path into the target function, and outputting and obtaining definition information of the function contained in the abstract syntax tree through the target function.
In an alternative embodiment, in generating the function document for assisting in describing each function in the target programming item based on paraphrase information of the function included in each of the abstract syntax trees, the processor 601 is configured to:
aiming at each abstract syntax tree, obtaining an editable code corresponding to a function file of the abstract syntax tree; wherein the editable codes corresponding to different function files are the same;
according to the to-be-filled type corresponding to each blank position in the editable code, filling the paraphrasing information of the function contained in the abstract syntax tree in the blank positions corresponding to the respectively matched to-be-filled types respectively to obtain a completely filled editable code; the code content at the filled position in the editable code is determined according to a preset function document display style;
Splicing the editable codes of each function file which are completely filled to obtain a bottom code file corresponding to the function file;
and converting the bottom code file into a target webpage, and displaying the visualized function document to a user through the converted target webpage.
In an alternative embodiment, processor 601 is further configured to:
detecting the function code content belonging to the function in each function file by using an object code detection tool to obtain the total number of the function code lines of each function in each function file and the number of error function code lines with errors; wherein the object code detection tool is determined according to a programming language of the object programming item;
calculating the code error rate of each function in each function file according to the proportion of the error function code line number of each function in each function file in the total function code line number;
and storing the total number of the function codes, the number of the error function codes and the code error rate of each function in each function file into the function file.
In an alternative embodiment, processor 601 is further configured to:
Detecting whether the naming format and/or the spelling of the function name of each function in each function file accords with the code rules defined in the rule dictionary by utilizing a rule dictionary in an object code detection tool to obtain a naming detection result of each function in each function file;
and storing the naming detection result of each function in each function file into the function file.
In an alternative embodiment, the processor 601 is applied to an operating environment of a target programming language, where a file path of each function file is obtained and code content of each function file is read and parsed through built-in modules and plug-ins with different functions in the operating environment; the target programming language characterizes a programming language employed by the target programming project.
Based on the electronic equipment provided by the embodiment of the application, a file path corresponding to each function file in a target programming item is obtained from an item catalog of the target programming item, and a target path tree of the target programming item is generated according to the file path corresponding to each function file; reading and analyzing the code content of each function file in the target path tree, and analyzing the code content of each function file into an abstract syntax tree taking the paraphrasing information of each function as a node; based on the paraphrase information of the functions contained in each abstract syntax tree, a function document for assisting in the explanation of each function in the target programming item is generated. Therefore, the method and the device realize automatic generation of the function document by means of the code characteristics of the function under the condition that a developer does not need to write annotation information for the function manually in advance, so that the generation efficiency and the content accuracy of the function document can be effectively improved.
Based on the same inventive concept, the embodiments of the present application also provide a computer readable storage medium having stored thereon a computer program, which when executed by a processor performs the steps of:
acquiring a file path corresponding to each function file in a target programming item from an item catalog of the target programming item, and generating a target path tree of the target programming item according to the file path corresponding to each function file; wherein the function file characterizes project files containing function codes;
reading and analyzing the code content of each function file in the target path tree, and analyzing the code content of each function file into an abstract syntax tree taking the paraphrasing information of each function as a node;
based on paraphrase information of functions contained in each of the abstract syntax trees, a function document for assisting in the explanation of each function in the target programming item is generated.
In an alternative embodiment, the processor is configured to generate a target path tree for the target programming item by:
Reading a file extension of each item file in the item directory, and determining the item file with the file extension belonging to the target extension as the function file; the target extension name is determined according to a programming language adopted by the target programming item;
acquiring a file path corresponding to each function file from the item catalog, and constructing a first key value pair corresponding to each function file by taking the file name of each function file as a key and the file path corresponding to each function file as a value;
and generating a target path tree of the target programming item based on the first key value pair corresponding to each function file.
In an alternative embodiment, the processor is configured to obtain the paraphrase information of the functions included in each abstract syntax tree after parsing the code content of each function file into the abstract syntax tree with the paraphrase information of each function as a node by:
traversing each node in the abstract syntax tree aiming at the abstract syntax tree analyzed by each function file, and reading out paraphrasing information of functions represented by each branch node under a target node representing function statement from code content covered under the target node;
The method comprises the steps of taking a file path of a function file corresponding to the abstract syntax tree as an input parameter of an objective function, taking paraphrasing information of the function read from the abstract syntax tree as an output parameter of the objective function, and defining to obtain the objective function;
traversing the target path tree, obtaining a file path of a function file corresponding to the abstract syntax tree, transmitting the obtained file path into the target function, and outputting and obtaining definition information of the function contained in the abstract syntax tree through the target function.
In an alternative embodiment, in generating the function document for assisting in describing each function in the target programming item based on paraphrase information of the function contained in each of the abstract syntax trees, the processor is configured to:
aiming at each abstract syntax tree, obtaining an editable code corresponding to a function file of the abstract syntax tree; wherein the editable codes corresponding to different function files are the same;
according to the to-be-filled type corresponding to each blank position in the editable code, filling the paraphrasing information of the function contained in the abstract syntax tree in the blank positions corresponding to the respectively matched to-be-filled types respectively to obtain a completely filled editable code; the code content at the filled position in the editable code is determined according to a preset function document display style;
Splicing the editable codes of each function file which are completely filled to obtain a bottom code file corresponding to the function file;
and converting the bottom code file into a target webpage, and displaying the visualized function document to a user through the converted target webpage.
In an alternative embodiment, the processor is further configured to:
detecting the function code content belonging to the function in each function file by using an object code detection tool to obtain the total number of the function code lines of each function in each function file and the number of error function code lines with errors; wherein the object code detection tool is determined according to a programming language of the object programming item;
calculating the code error rate of each function in each function file according to the proportion of the error function code line number of each function in each function file in the total function code line number;
and storing the total number of the function codes, the number of the error function codes and the code error rate of each function in each function file into the function file.
In an alternative embodiment, the processor is further configured to:
Detecting whether the naming format and/or the spelling of the function name of each function in each function file accords with the code rules defined in the rule dictionary by utilizing a rule dictionary in an object code detection tool to obtain a naming detection result of each function in each function file;
and storing the naming detection result of each function in each function file into the function file.
In an optional implementation manner, the processor is applied to an operation environment of a target programming language, wherein a file path of each function file is obtained and code content of each function file is read and analyzed through built-in modules and plug-ins with different functions in the operation environment; the target programming language characterizes a programming language employed by the target programming project.
According to the computer readable storage medium provided by the embodiment of the application, a file path corresponding to each function file in a target programming project is obtained from a project catalog of the target programming project, and a target path tree of the target programming project is generated according to the file path corresponding to each function file; reading and analyzing the code content of each function file in the target path tree, and analyzing the code content of each function file into an abstract syntax tree taking the paraphrasing information of each function as a node; based on the paraphrase information of the functions contained in each abstract syntax tree, a function document for assisting in the explanation of each function in the target programming item is generated. Therefore, the method and the device realize automatic generation of the function document by means of the code characteristics of the function under the condition that a developer does not need to write annotation information for the function manually in advance, so that the generation efficiency and the content accuracy of the function document can be effectively improved.
In the embodiment of the present application, the computer readable storage medium may further execute other machine readable instructions when executed by the processor to perform the method for generating a function document as described in other embodiments, and the specific implementation of the steps and principles of the generating method are referred to in the description of the method side embodiment, and are not repeated herein.
In the embodiments provided herein, it should be understood that the disclosed systems and methods may be implemented in other ways. The system embodiments described above are merely illustrative, e.g., the division of the elements is merely a logical functional division, and there may be additional divisions in actual implementation, and e.g., multiple elements or components may be combined or integrated into another system, or some features may be omitted, or not performed. Alternatively, the coupling or direct coupling or communication connection shown or discussed with each other may be through some communication interface, system or unit indirect coupling or communication connection, which may be in electrical, mechanical or other form.
The units described as separate units may or may not be physically separate, and units shown as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
In addition, each functional unit in the embodiments provided in the present application may be integrated in one processing unit, or each unit may exist alone physically, or two or more units may be integrated in one unit.
The functions, if implemented in the form of software functional units and sold or used as a stand-alone product, may be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application may be embodied essentially or in a part contributing to the prior art or in a part of the technical solution, in the form of a software product stored in a storage medium, comprising several instructions for causing a computer device (which may be a personal computer, a server, a network device, etc.) to perform all or part of the steps of the method according to the embodiments of the present application. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a random access Memory (Random Access Memory, RAM), a magnetic disk, or an optical disk, or other various media capable of storing program codes.
It should be noted that: like reference numerals and letters in the following figures denote like items, and thus once an item is defined in one figure, no further definition or explanation of it is required in the following figures, and furthermore, the terms "first," "second," "third," etc. are used merely to distinguish one description from another and are not to be construed as indicating or implying relative importance.
Finally, it should be noted that: the above examples are only specific embodiments of the present application, and are not intended to limit the scope of the present application, but it should be understood by those skilled in the art that the present application is not limited thereto, and that the present application is described in detail with reference to the foregoing examples: any person skilled in the art may modify or easily conceive of the technical solution described in the foregoing embodiments, or perform equivalent substitution of some of the technical features, while remaining within the technical scope of the present disclosure; such modifications, changes or substitutions do not depart from the spirit and scope of the corresponding technical solutions. Are intended to be encompassed within the scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.

Claims (10)

1. A method for generating a function document, the method comprising:
acquiring a file path corresponding to each function file in a target programming item from an item catalog of the target programming item, and generating a target path tree of the target programming item according to the file path corresponding to each function file; wherein the function file characterizes project files containing function codes;
Reading and analyzing the code content of each function file in the target path tree, and analyzing the code content of each function file into an abstract syntax tree taking the paraphrasing information of each function as a node;
based on paraphrase information of functions contained in each of the abstract syntax trees, a function document for assisting in the explanation of each function in the target programming item is generated.
2. The method of generating of claim 1, wherein the target path tree for the target programming item is generated by:
reading a file extension of each item file in the item directory, and determining the item file with the file extension belonging to the target extension as the function file; the target extension name is determined according to a programming language adopted by the target programming item;
acquiring a file path corresponding to each function file from the item catalog, and constructing a first key value pair corresponding to each function file by taking the file name of each function file as a key and the file path corresponding to each function file as a value;
and generating a target path tree of the target programming item based on the first key value pair corresponding to each function file.
3. The method according to claim 1, wherein after said parsing the code content of each of said function files into abstract syntax trees having paraphrasing information of each function as nodes, paraphrasing information of functions contained in each of said abstract syntax trees is obtained by:
traversing each node in the abstract syntax tree aiming at the abstract syntax tree analyzed by each function file, and reading out paraphrasing information of functions represented by each branch node under a target node representing function statement from code content covered under the target node;
the method comprises the steps of taking a file path of a function file corresponding to the abstract syntax tree as an input parameter of an objective function, taking paraphrasing information of the function read from the abstract syntax tree as an output parameter of the objective function, and defining to obtain the objective function;
traversing the target path tree, obtaining a file path of a function file corresponding to the abstract syntax tree, transmitting the obtained file path into the target function, and outputting and obtaining definition information of the function contained in the abstract syntax tree through the target function.
4. The method according to claim 1, wherein generating a function document for assisting in the description of each function in the target programming item based on paraphrase information of the function contained in each abstract syntax tree comprises:
Aiming at each abstract syntax tree, obtaining an editable code corresponding to a function file of the abstract syntax tree; wherein the editable codes corresponding to different function files are the same;
according to the to-be-filled type corresponding to each blank position in the editable code, filling the paraphrasing information of the function contained in the abstract syntax tree in the blank positions corresponding to the respectively matched to-be-filled types respectively to obtain a completely filled editable code; the code content at the filled position in the editable code is determined according to a preset function document display style;
splicing the editable codes of each function file which are completely filled to obtain a bottom code file corresponding to the function file;
and converting the bottom code file into a target webpage, and displaying the visualized function document to a user through the converted target webpage.
5. The generation method according to claim 1, characterized in that the generation method further comprises:
detecting the function code content belonging to the function in each function file by using an object code detection tool to obtain the total number of the function code lines of each function in each function file and the number of error function code lines with errors; wherein the object code detection tool is determined according to a programming language of the object programming item;
Calculating the code error rate of each function in each function file according to the proportion of the error function code line number of each function in each function file in the total function code line number;
and storing the total number of the function codes, the number of the error function codes and the code error rate of each function in each function file into the function file.
6. The generation method according to claim 1, characterized in that the generation method further comprises:
detecting whether the naming format and/or the spelling of the function name of each function in each function file accords with the code rules defined in the rule dictionary by utilizing a rule dictionary in an object code detection tool to obtain a naming detection result of each function in each function file;
and storing the naming detection result of each function in each function file into the function file.
7. The generating method according to claim 1, wherein the generating method is applied to an operating environment of a target programming language, wherein a file path of each function file is obtained and code content of each function file is read and parsed through built-in modules and plug-ins with different functions in the operating environment; the target programming language characterizes a programming language employed by the target programming project.
8. A function document generating apparatus, characterized in that the generating apparatus includes:
the path acquisition module is used for acquiring a file path corresponding to each function file in a target programming project from a project catalog of the target programming project, and generating a target path tree of the target programming project according to the file path corresponding to each function file; wherein the function file characterizes project files containing function codes;
the code analysis module is used for analyzing the code content of each function file into an abstract syntax tree taking the paraphrasing information of each function as a node by reading and analyzing the code content of each function file in the target path tree;
and the document generation module is used for generating a function document for carrying out auxiliary explanation on each function in the target programming project based on the paraphrase information of the function contained in each abstract syntax tree.
9. An electronic device, comprising: a processor, a memory and a bus, said memory storing machine readable instructions executable by said processor, said processor and said memory communicating over the bus when the electronic device is running, said machine readable instructions when executed by said processor performing the steps of the method of generating a functional document according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that the computer-readable storage medium has stored thereon a computer program which, when executed by a processor, performs the steps of the method of generating a function document according to any of claims 1 to 7.
CN202311029803.5A 2023-08-15 2023-08-15 Method, device, equipment and storage medium for generating function document Pending CN117010345A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311029803.5A CN117010345A (en) 2023-08-15 2023-08-15 Method, device, equipment and storage medium for generating function document

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311029803.5A CN117010345A (en) 2023-08-15 2023-08-15 Method, device, equipment and storage medium for generating function document

Publications (1)

Publication Number Publication Date
CN117010345A true CN117010345A (en) 2023-11-07

Family

ID=88563425

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311029803.5A Pending CN117010345A (en) 2023-08-15 2023-08-15 Method, device, equipment and storage medium for generating function document

Country Status (1)

Country Link
CN (1) CN117010345A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117573140A (en) * 2024-01-16 2024-02-20 成都安世赛斯特软件技术有限公司 Method, system and device for generating document by scanning codes

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117573140A (en) * 2024-01-16 2024-02-20 成都安世赛斯特软件技术有限公司 Method, system and device for generating document by scanning codes
CN117573140B (en) * 2024-01-16 2024-04-02 成都安世赛斯特软件技术有限公司 Method, system and device for generating document by scanning codes

Similar Documents

Publication Publication Date Title
CN106919434B (en) Code generation method and device
US11645576B2 (en) Code completion for languages with hierarchical structures
US8032822B1 (en) Method and system for explaining dependencies on a document
EP3365772B1 (en) Missing include suggestions for external files
JP5592591B2 (en) A system for creating relationships between items and navigating items
CN108762743B (en) Data table operation code generation method and device
US8364696B2 (en) Efficient incremental parsing of context sensitive programming languages
EP3891599B1 (en) Code completion of method parameters with machine learning
CN112148356B (en) Document generation method, interface development method, device, server and storage medium
US9141344B2 (en) Hover help support for application source code
CN111831384A (en) Language switching method and device, equipment and storage medium
CN117010345A (en) Method, device, equipment and storage medium for generating function document
CN111656453A (en) Hierarchical entity recognition and semantic modeling framework for information extraction
CN113760266B (en) Method and device for creating function module file and electronic equipment
WO2022068556A1 (en) Code translation method and apparatus, and device
CN109325217B (en) File conversion method, system, device and computer readable storage medium
CN110275712B (en) Text replacement method, device and equipment
Aivaloglou et al. A grammar for spreadsheet formulas evaluated on two large datasets
CN115599388B (en) API (application program interface) document generation method, storage medium and electronic equipment
KR102614967B1 (en) Automation system and method for extracting intermediate representation based semantics of javascript
Aivaloglou et al. Parsing excel formulas: A grammar and its application on 4 large datasets
Ribeiro et al. A mechanized textbook proof of a type unification algorithm
Schubanz Custom-MADE-Leveraging Agile Rationale Management by Employing Domain-Specific Languages.
CN112650479A (en) Webpage CSS structure automatic generation method and storage medium
CN110618809B (en) Front-end webpage input constraint extraction method and device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination