CN112148581A - Code specification checking method, device, system and storage medium - Google Patents

Code specification checking method, device, system and storage medium Download PDF

Info

Publication number
CN112148581A
CN112148581A CN201910562438.1A CN201910562438A CN112148581A CN 112148581 A CN112148581 A CN 112148581A CN 201910562438 A CN201910562438 A CN 201910562438A CN 112148581 A CN112148581 A CN 112148581A
Authority
CN
China
Prior art keywords
code
source code
exists
file
attribute
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
CN201910562438.1A
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.)
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information Technology Co Ltd
Original Assignee
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information Technology 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 Beijing Jingdong Century Trading Co Ltd, Beijing Jingdong Shangke Information Technology Co Ltd filed Critical Beijing Jingdong Century Trading Co Ltd
Priority to CN201910562438.1A priority Critical patent/CN112148581A/en
Publication of CN112148581A publication Critical patent/CN112148581A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3604Software analysis for verifying properties of programs
    • G06F11/3616Software analysis for verifying properties of programs using software metrics

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Stored Programmes (AREA)

Abstract

The invention provides a code specification checking method, a device, a system and a storage medium, wherein the method comprises the following steps: carrying out syntactic analysis on a source code to be detected to generate an abstract syntactic tree; determining all method call nodes in the abstract syntax tree; if the method calling node exists, searching whether a matched method exists in an attribute method list of the local cache; and if the matched method does not exist, marking the code information corresponding to the method calling node. Therefore, in the code scanning process, the attribute method list of the local cache can be automatically obtained for comparison, and the accuracy of the code scanning result is ensured.

Description

Code specification checking method, device, system and storage medium
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a method, an apparatus, a system, and a storage medium for code specification checking.
Background
Developers are often involved in the modification of code during the development and maintenance of applications. Although many companies have corresponding requirements for code specification, various code specification problems still exist when the codes are actually executed, so that the readability of the codes is poor.
Currently, the scanning of the code is generally performed by a static code scanning tool, and then the error or irregular place of the code is recorded for the maintenance of the developer.
However, the existing code scanning tool has high false alarm rate, and some programming problems which are not wrong are marked as exceptions.
Disclosure of Invention
The invention provides a code specification checking method, a device, a system and a storage medium, which can automatically acquire a local cache attribute method list for comparison in the code scanning process and ensure the accuracy of a code scanning result.
In a first aspect, an embodiment of the present invention provides a code specification checking method, including:
carrying out syntactic analysis on a source code to be detected to generate an abstract syntactic tree;
determining all method call nodes in the abstract syntax tree;
if the method calling node exists, searching whether a matched method exists in an attribute method list of the local cache;
and if the matched method does not exist, marking the code information corresponding to the method calling node.
In one possible design, before searching the locally cached attribute method list for a matching method, the method further includes:
searching whether an original document file exists from a local specified directory;
if the original document file does not exist, the official document acquired from the online is used as the original document and is stored in a local specified directory;
and cleaning and sorting the original document file to obtain an integral attribute method list without redundant information, wherein the attribute method list is used for recording all methods normally used by the source code at present.
In one possible design, parsing the source code to be detected to generate an abstract syntax tree includes:
performing manual syntax analysis on a source code to be detected through an application programming interface provided by a compiler;
generating a corresponding abstract syntax tree for each file in the source code to be detected; wherein each node on the abstract syntax spanning tree characterizes the parsed source code data.
In one possible design, further comprising:
acquiring configuration parameters required by code specification checking logic from an engineering directory; the configuration parameters set under the engineering target keep information synchronization with the terminal of a developer through a management tool;
performing code specification checking on each syntax node on the abstract syntax tree through the configuration parameters;
and if the code specification is not met, marking the code information.
In one possible design, further comprising:
generating a code specification inspection report according to the marked file and code line number of the code corresponding to the calling node of the method and the marked file and code line number of the code;
and displaying the code specification checking report in a compiling result column of the integrated development environment.
In a second aspect, an embodiment of the present invention provides a code specification checking apparatus, including:
the analysis module is used for carrying out syntactic analysis on the source code to be detected and generating an abstract syntactic tree;
a determining module, configured to determine all method call nodes in the abstract syntax tree;
the comparison module is used for searching whether a matched method exists in the attribute method list of the local cache when the method calling node exists;
and the first marking module is used for marking the code information corresponding to the method calling node when no matched method exists.
In one possible design, further comprising: an acquisition module to:
searching whether an original document file exists from a local specified directory;
if the original document file does not exist, the official document acquired from the online is used as the original document and is stored in a local specified directory;
and cleaning and sorting the original document file to obtain an integral attribute method list without redundant information, wherein the attribute method list is used for recording all methods normally used by the source code at present.
In one possible design, the analysis module is specifically configured to:
performing manual syntax analysis on a source code to be detected through an application programming interface provided by a compiler;
generating a corresponding abstract syntax tree for each file in the source code to be detected; wherein each node on the abstract syntax spanning tree characterizes the parsed source code data.
In one possible design, further comprising: a second labeling module to:
acquiring configuration parameters required by code specification checking logic from an engineering directory; the configuration parameters set under the engineering target keep information synchronization with the terminal of a developer through a management tool;
performing code specification checking on each syntax node on the abstract syntax tree through the configuration parameters;
and if the code specification is not met, marking the code information.
In one possible design, further comprising: a report generation module to:
generating a code specification inspection report according to the marked file and code line number of the code corresponding to the calling node of the method and the marked file and code line number of the code;
and displaying the code specification checking report in a compiling result column of the integrated development environment.
In a third aspect, an embodiment of the present invention provides a code specification checking system, including: the device comprises a memory and a processor, wherein the memory stores executable instructions of the processor; wherein the processor is configured to perform the code specification checking method of any one of the first aspect via execution of the executable instructions.
In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements the code specification checking method according to any one of the first aspects.
In a fifth aspect, an embodiment of the present invention provides a program product, where the program product includes: a computer program stored in a readable storage medium, the computer program being readable from the readable storage medium by at least one processor of a server, execution of the computer program by the at least one processor causing the server to perform the code specification checking method of any one of the first aspect.
The invention provides a code specification checking method, a device, a system and a storage medium, which generate an abstract syntax tree by carrying out syntax analysis on a source code to be detected; determining all method call nodes in the abstract syntax tree; if the method calling node exists, searching whether a matched method exists in an attribute method list of the local cache; and if the matched method does not exist, marking the code information corresponding to the method calling node. Therefore, in the code scanning process, the attribute method list of the local cache can be automatically obtained for comparison, the abandoned method used in the code can be accurately scanned, the accuracy of the code scanning result is ensured, and the omission of the self-checking of the IDE is made up. In addition, the whole checking method is simple in configuration, can be synchronized to a development team through a git and other management tools, is easy to integrate with the IDE, and is convenient for developers to use at any time in the development process.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings needed to be used in the description of the embodiments or the prior art will be briefly introduced below, and it is obvious that the drawings in the following description are some embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to these drawings without creative efforts.
FIG. 1 is a schematic diagram of an application scenario of the present invention;
FIG. 2 is a flowchart of a code specification checking method according to an embodiment of the present invention;
FIG. 3 is a diagram of an abstract syntax tree according to an embodiment of the present invention;
FIG. 4 is a flowchart of a code specification checking method according to a second embodiment of the present invention;
fig. 5 is a schematic structural diagram of a code specification checking apparatus according to a third embodiment of the present invention;
fig. 6 is a schematic structural diagram of a code specification checking apparatus according to a fourth embodiment of the present invention;
fig. 7 is a schematic structural diagram of a code specification checking system according to a fifth embodiment of the present invention.
With the foregoing drawings in mind, certain embodiments of the disclosure have been shown and described in more detail below. These drawings and written description are not intended to limit the scope of the disclosed concepts in any way, but rather to illustrate the concepts of the disclosure to those skilled in the art by reference to specific embodiments.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
The terms "first," "second," "third," "fourth," and the like in the description and in the claims, as well as in the drawings, if any, are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used is interchangeable under appropriate circumstances such that the embodiments of the invention described herein are, for example, capable of operation in sequences other than those illustrated or otherwise described herein. Furthermore, the terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed, but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus.
To facilitate understanding of the technical solution, the terms appearing in the present invention are explained.
1) The Clang Static Analyzer is a Static code scanning tool, and is specially used for analyzing programs aiming at C, C + + and Objective-C. The method is integrated by Xcode, can directly use the Xcode to perform static code scanning analysis, and can also be independently used under a command line and provide an output report in an html format and a result file in an xml format for convenient integration into Jenkins for display. However, csa has few inspectors available for oc, which are only 16 inspectors, and most of the inspectors are core-to-core errors such as null pointer detection, type conversion detection, null decision detection and memory leak detection, which have to be broken, and have few or no code style-dependent errors and poor configurability.
2) An Integrated Development Environment (IDE) is an application program for providing a program Development Environment, and generally includes tools such as a code editor, a compiler, a debugger, and a graphical user interface. The integrated development software service set integrates a code compiling function, an analyzing function, a compiling function, a debugging function and the like. All software or software suite (group) with the characteristic can be called an integrated development environment.
3) Xcode is an integrated development tool (IDE) running on the operating system Mac OS X, developed by Apple Inc. Xcode is the fastest way to develop macOS and iOS applications. The Xcode has a uniform user interface design, and the encoding, the testing and the debugging are completed in a simple window.
4) An API (Application Programming Interface) is a predefined function that is intended to provide applications and developers the ability to access a set of routines based on certain software or hardware, without having to access source code or understand the details of the internal workings.
The technical solution of the present invention will be described in detail below with specific examples. The following several specific embodiments may be combined with each other, and details of the same or similar concepts or processes may not be repeated in some embodiments.
Developers are often involved in the modification of code during the development and maintenance of applications. Although many companies have corresponding requirements for code specification, various code specification problems still exist when the codes are actually executed, so that the readability of the codes is poor. Currently, the scanning of the code is generally performed by a static code scanning tool, and then the error or irregular place of the code is recorded for the maintenance of the developer. However, the existing code scanning tool has high false alarm rate, and some programming problems which are not wrong are marked as exceptions. And cannot support custom configuration, only scan out the most common coding problems that inevitably lead to crash, and have few functions related to code style check. The flexibility is poor, and the mainstream code scanning tool can only scan out common code errors, such as cyclic reference, parameters are empty, and the customized function for a specific scene is lacked. For example, if some methods are abandoned and not identified in the IDE, these code scanning tools and the configurations they can provide are also unrecognizable, requiring a more customized solution.
Aiming at the technical problem, the invention provides a method, which can automatically acquire the attribute method list of the local cache for comparison in the code scanning process, accurately scan out the abandoned method used in the code, ensure the accuracy of the code scanning result and make up for the omission of the self-inspection of the IDE. In addition, the whole checking method is simple in configuration, can be synchronized to a development team through a git and other management tools, is easy to integrate with the IDE, and is convenient for developers to use at any time in the development process. The embodiment is described by taking the development of the iOS application as an example, and the method provided in the embodiment can be applied to the code specification check of the iOS application. Regarding the mainstream development language Objective-C currently used for iOS application development, the main Static code scanning tool currently on the market is the Clang Static Analyzer. The method provided by the invention is based on IDE plug-in unit compiled into dylib format by Clang, is directly integrated into the project, does not need secondary configuration, and can automatically scan and output results when the project is compiled each time. Fig. 1 is a schematic diagram illustrating an application scenario of the present invention, and as shown in fig. 1, an application programming interface API provided by a compiler Clang performs manual syntax analysis on a source code to be detected, and generates a corresponding abstract syntax tree AST for each file in the source code to be detected; wherein each node on the abstract syntax spanning tree characterizes the source code data being parsed. Meanwhile, whether an original document file exists or not is automatically searched under an Xcode directory on a local machine, if the original document file does not exist, an official document on an apple line is tried to be accessed, and the official document obtained from the apple line is used as the original document and is stored in a local specified directory. And then, cleaning and sorting the original text data by using a script language to obtain a complete attribute method list without redundant information, and storing the attribute method list as a local file. And finally, judging all method calling nodes through the AST node. When the method calling node is scanned, whether a matched method exists is searched in the attribute method list of the local cache. If the method exists, the method is proved not to be abandoned, and a target version is supported; if not, the method is a method which is not supported by the target version, and the method is marked and recorded. According to the obtained AST, code scanning logic can be further realized by using C + +, configuration parameters to be used by the specification checking logic are obtained by reading configuration preset in an engineering directory, and code specification checking is performed on each grammar node on the AST according to the current configuration parameters. And marking out the nodes which do not meet the code specification, recording the file and the code line number of the code to which the section of code belongs, and outputting a later inspection report. The configuration can be modified at any time and synchronized through git to the entire development team. The step can further check the code specification of each grammar node, and has the advantages of simple configuration and good portability. The configuration can be uploaded to a remote code library through a code management tool, so that separate configurations on different development machines can be eliminated.
The following describes the technical solutions of the present invention and how to solve the above technical problems with specific embodiments. The following several specific embodiments may be combined with each other, and details of the same or similar concepts or processes may not be repeated in some embodiments. Embodiments of the present invention will be described below with reference to the accompanying drawings.
Fig. 2 is a flowchart of a code specification checking method according to an embodiment of the present invention, and as shown in fig. 2, the method in this embodiment may include:
s101, carrying out syntactic analysis on a source code to be detected, and generating an abstract syntactic tree.
The embodiment is described by taking the development of the iOS application as an example, and the method provided in the embodiment can be applied to the code specification check of the iOS application. Regarding the mainstream development language Objective-C currently used for iOS application development, the main Static code scanning tool currently on the market is the Clang Static Analyzer. The method provided by the invention can be compiled into an IDE plug-in with a dylib format based on Clang, and the IDE plug-in is directly integrated into a project without secondary configuration, and the scanning and the result output can be automatically carried out during each project compiling.
In one possible embodiment of the method according to the invention,
specifically, the source code is manually parsed by using the API method provided by Clang, and a corresponding AST (abstract syntax tree) is generated for each source code file, where each node on the AST is the original code data that needs to be parsed. Fig. 3 is a schematic diagram of an abstract syntax tree according to an embodiment of the present invention, and as shown in fig. 3, each node in the abstract syntax tree represents source code data to be analyzed and processed. In the subsequent steps, each node on the abstract syntax tree needs to be checked.
And S102, determining all method calling nodes in the abstract syntax tree.
S103, if the method calling node exists, whether a matched method exists is searched in the attribute method list of the local cache.
And S104, if the matched method does not exist, marking code information corresponding to the method calling node.
In this embodiment, all the method call nodes are determined by the AST node. When the method calling node is scanned, whether a matched method exists is searched in the attribute method list of the local cache. If the method exists, the method is proved not to be abandoned, and a target version is supported; if not, the method is a method which is not supported by the target version, and the method is marked and recorded. The marked code information may be information such as a file to which the code belongs and the number of code lines. The present embodiment does not limit the specific content of the code information, and any information capable of locating the code position may be applied in the present embodiment. Specifically, for example, a method decrefexpr exists in the source code file a, and a calling node exists in the source code file B, which calls the decrefexpr method in the source code file a. If the method decrefexpr is deleted in the upgrade of the source code file a, it is determined in step S102 that a decrefexpr method invocation node exists in the source code file B, and a method decrefexpr is not matched in the source code file a in step S103. Then in step S104, it is stated that the decrefexpr method is a method that is not supported by the target version, and it is marked and recorded. The method provided by the invention can accurately scan the abandoned method used in the code by pulling and sorting the apple officer document as comparison, and effectively makes up for the omission of the self inspection of the IDE.
In a possible implementation, before searching whether there is a matching method from the locally cached attribute method list, the method further includes: searching whether an original document file exists from a local specified directory; if the original document file does not exist, the official document acquired from the online is used as the original document and is stored in a local specified directory; and cleaning and sorting the original document file to obtain an integral attribute method list without redundant information, wherein the attribute method list is used for recording all methods currently and normally used by the source code.
Specifically, the method automatically searches whether an original document file exists in an Xcode directory on a local machine, if the original document file does not exist in the Xcode directory, an official document on an apple line is tried to be accessed, and the official document acquired from the apple line is used as the original document and is stored in a local specified directory. And then, cleaning and sorting the original text data by using a script language to obtain a complete attribute method list without redundant information, and storing the attribute method list as a local file. After the two steps are completed, a processed document file is generated locally, and the processed document file is cached locally for the convenience of next use, so that all documents are guaranteed to be downloaded only once. The method provided by the invention can support the method of scanning out the abandoned apple official, and can automatically pull and arrange the apple officer document as the original document to carry out code specification inspection.
The invention provides a code specification checking method, a device, a system and a storage medium, which generate an abstract syntax tree by carrying out syntax analysis on a source code to be detected; determining all method call nodes in the abstract syntax tree; if the method calling node exists, searching whether a matched method exists in an attribute method list of the local cache; and if the matched method does not exist, marking the file and the code line number to which the code corresponding to the method calling node belongs. Therefore, in the code scanning process, the attribute method list of the local cache can be automatically obtained for comparison, the abandoned method used in the code can be accurately scanned, the accuracy of the code scanning result is ensured, and the omission of the self-checking of the IDE is made up. In addition, the whole checking method is simple in configuration, can be synchronized to a development team through a git and other management tools, is easy to integrate with the IDE, and is convenient for developers to use at any time in the development process.
Fig. 4 is a flowchart of a code specification checking method provided in the second embodiment of the present invention, and as shown in fig. 4, the method in this embodiment may include:
s201, carrying out syntactic analysis on the source code to be detected, and generating an abstract syntactic tree.
S202, determining all method calling nodes in the abstract syntax tree.
S203, if the method calling node exists, whether a matched method exists is searched in the attribute method list of the local cache.
And S204, if the matched method does not exist, marking code information corresponding to the method calling node.
In this embodiment, please refer to the relevant description in step S101 to step S104 in the method shown in fig. 2 for the specific implementation process and technical principle of step S201 to step S204, which is not described herein again.
And S205, carrying out code specification check on each grammar node on the abstract grammar tree through the configuration parameters.
In this embodiment, configuration parameters required by the code specification checking logic may also be acquired from the project directory; the configuration parameters set under the engineering target keep information synchronization with the terminal of a developer through a management tool; code specification inspection is carried out on each grammar node on the abstract grammar tree through configuration parameters; if the code specification is not met, marking the file to which the code belongs and the code line number.
Specifically, according to the obtained AST, the code scanning logic is implemented by using C + + (since Clang only supports native C/C + + calls), the configuration parameters to be used by the specification checking logic are obtained by reading the configuration preset in the engineering directory, and the code specification is checked for each syntax node on the AST according to the current configuration parameters. And marking out the nodes which do not meet the code specification, recording the file and the code line number of the code to which the section of code belongs, and outputting a later inspection report. The configuration can be modified at any time and synchronized through git to the entire development team. The step can further check the code specification of each grammar node, and has the advantages of simple configuration and good portability. The configuration can be uploaded to a remote code library through a code management tool, so that separate configurations on different development machines can be eliminated.
And S206, generating a code specification checking report.
In the embodiment, a code specification inspection report is generated according to the marked method, the file and the code line number to which the code corresponding to the node belongs, and the marked file and the marked code line number to which the code belongs; and displaying a code specification checking report in a compiling result column of the integrated development environment.
Specifically, after the whole process is finished, an inspection report is exported, and the marked method calls the file and the code line number to which the code belongs and marks the file and the code line number to which the code belongs. The method provided by the invention can be used independently, and can also be directly integrated into an IDE (integrated development environment) based on an IDE plug-in board compiled into a dylib format by Clang for use. If the option is integrated with the IDE, the report of the inspection result can be printed on the compiling result column of the IDE at the same time, so that the developer can conveniently look up the report. The step can lead the method provided by the invention to be directly integrated into a mainstream development tool IDE, dynamically give the scanning result when a developer compiles the code, and support the code segment which is possibly problematic to be marked in the code, thereby being convenient for the developer to modify in time.
The invention provides a code specification checking method, a device, a system and a storage medium, which generate an abstract syntax tree by carrying out syntax analysis on a source code to be detected; determining all method call nodes in the abstract syntax tree; if the method calling node exists, searching whether a matched method exists in an attribute method list of the local cache; and if the matched method does not exist, marking the code information corresponding to the method calling node. Therefore, in the code scanning process, the attribute method list of the local cache can be automatically obtained for comparison, the abandoned method used in the code can be accurately scanned, the accuracy of the code scanning result is ensured, and the omission of the self-checking of the IDE is made up. In addition, the whole checking method is simple in configuration, can be synchronized to a development team through a git and other management tools, is easy to integrate with the IDE, and is convenient for developers to use at any time in the development process.
In addition, the present embodiment may also perform code specification check on each syntax node in the abstract syntax tree through configuration parameters; and generating a code specification inspection report. Therefore, the code specification of each grammar node can be further checked, and the method has the advantages of simple configuration and good portability. The configuration can be uploaded to a remote code library through a code management tool, so that separate configurations on different development machines can be eliminated. The method can also be directly integrated into a mainstream development tool IDE, dynamically gives a scanning result when a developer compiles the code, and supports marking code segments with possible problems in the code, thereby facilitating the timely modification of the developer.
Fig. 5 is a schematic structural diagram of a code specification checking apparatus provided in a third embodiment of the present invention, and as shown in fig. 5, the code specification checking apparatus of the present embodiment may include:
the analysis module 31 is configured to perform syntax analysis on the source code to be detected to generate an abstract syntax tree;
a determining module 32, configured to determine all method call nodes in the abstract syntax tree;
a comparison module 33, configured to, when a method call node exists, search whether a matching method exists in the attribute method list of the local cache;
and the first marking module 34 is configured to mark code information corresponding to the method calling node when there is no matching method.
In one possible design, the analysis module 31 is specifically configured to:
performing manual syntax analysis on a source code to be detected through an application programming interface provided by a compiler;
generating a corresponding abstract syntax tree for each file in the source code to be detected; wherein each node on the abstract syntax spanning tree characterizes the source code data being parsed.
The code specification checking apparatus of this embodiment may execute the technical solution in the method shown in fig. 2, and for the specific implementation process and the technical principle, reference is made to the relevant description in the method shown in fig. 2, which is not described herein again.
The invention provides a code specification checking method, a device, a system and a storage medium, which generate an abstract syntax tree by carrying out syntax analysis on a source code to be detected; determining all method call nodes in the abstract syntax tree; if the method calling node exists, searching whether a matched method exists in an attribute method list of the local cache; and if the matched method does not exist, marking the code information corresponding to the method calling node. Therefore, in the code scanning process, the attribute method list of the local cache can be automatically obtained for comparison, the abandoned method used in the code can be accurately scanned, the accuracy of the code scanning result is ensured, and the omission of the self-checking of the IDE is made up. In addition, the whole checking method is simple in configuration, can be synchronized to a development team through a git and other management tools, is easy to integrate with the IDE, and is convenient for developers to use at any time in the development process.
Fig. 6 is a schematic structural diagram of a code specification checking apparatus according to a fourth embodiment of the present invention, as shown in fig. 6, the code specification checking apparatus according to the present embodiment may further include, on the basis of the apparatus shown in fig. 5:
an obtaining module 35, configured to:
searching whether an original document file exists from a local specified directory;
if the original document file does not exist, the official document acquired from the online is used as the original document and is stored in a local specified directory;
and cleaning and sorting the original document file to obtain an integral attribute method list without redundant information, wherein the attribute method list is used for recording all methods currently and normally used by the source code.
In one possible design, further comprising: a second marking module 36 for:
acquiring configuration parameters required by code specification checking logic from an engineering directory; the configuration parameters set under the engineering target keep information synchronization with the terminal of a developer through a management tool;
code specification inspection is carried out on each grammar node on the abstract grammar tree through configuration parameters;
and if the code specification is not met, marking the code information.
In one possible design, further comprising: a report generation module 37 to:
calling a file and a code line number to which the code corresponding to the node belongs according to the marked method, marking the file and the code line number to which the code belongs, and generating a code specification inspection report;
and displaying a code specification checking report in a compiling result column of the integrated development environment.
The code specification checking apparatus of this embodiment may execute the technical solutions in the methods shown in fig. 2 and fig. 4, and the specific implementation process and technical principle of the technical solutions refer to the related descriptions in the methods shown in fig. 2 and fig. 4, which are not described herein again.
The invention provides a code specification checking method, a device, a system and a storage medium, which generate an abstract syntax tree by carrying out syntax analysis on a source code to be detected; determining all method call nodes in the abstract syntax tree; if the method calling node exists, searching whether a matched method exists in an attribute method list of the local cache; and if the matched method does not exist, marking the code information corresponding to the method calling node. Therefore, in the code scanning process, the attribute method list of the local cache can be automatically obtained for comparison, the abandoned method used in the code can be accurately scanned, the accuracy of the code scanning result is ensured, and the omission of the self-checking of the IDE is made up. In addition, the whole checking method is simple in configuration, can be synchronized to a development team through a git and other management tools, is easy to integrate with the IDE, and is convenient for developers to use at any time in the development process.
In addition, the present embodiment may also perform code specification check on each syntax node in the abstract syntax tree through configuration parameters; and generating a code specification inspection report. Therefore, the code specification of each grammar node can be further checked, and the method has the advantages of simple configuration and good portability. The configuration can be uploaded to a remote code library through a code management tool, so that separate configurations on different development machines can be eliminated. The method can also be directly integrated into a mainstream development tool IDE, dynamically gives a scanning result when a developer compiles the code, and supports marking code segments with possible problems in the code, thereby facilitating the timely modification of the developer.
Fig. 7 is a schematic structural diagram of a code specification checking system provided in the fifth embodiment of the present invention, and as shown in fig. 7, the code specification checking system 40 of the present embodiment may include: a processor 41 and a memory 42.
A memory 42 for storing programs; the Memory 42 may include a volatile Memory (RAM), such as a Static Random Access Memory (SRAM), a Double Data Rate Synchronous Dynamic Random Access Memory (DDR SDRAM), and the like; the memory may also comprise a non-volatile memory, such as a flash memory. The memory 42 is used to store computer programs (e.g., applications, functional modules, etc. that implement the above-described methods), computer instructions, etc., which may be stored in one or more of the memories 42 in a partitioned manner. And the above-mentioned computer program, computer instructions, data, etc. can be called by the processor 41.
The computer programs, computer instructions, etc. described above may be stored in one or more memories 42 in partitions. And the above-mentioned computer program, computer instructions, data, etc. can be called by the processor 41.
A processor 41 for executing the computer program stored in the memory 42 to implement the steps of the method according to the above embodiments.
Reference may be made in particular to the description relating to the preceding method embodiment.
The processor 41 and the memory 42 may be separate structures or may be integrated structures integrated together. When the processor 41 and the memory 42 are separate structures, the memory 42 and the processor 41 may be coupled by a bus 43.
The code specification checking system of this embodiment may execute the technical solutions in the methods shown in fig. 2 and fig. 4, and the specific implementation process and technical principle of the technical solutions refer to the related descriptions in the methods shown in fig. 2 and fig. 4, which are not described herein again.
In addition, embodiments of the present application further provide a computer-readable storage medium, in which computer-executable instructions are stored, and when at least one processor of the user equipment executes the computer-executable instructions, the user equipment performs the above-mentioned various possible methods.
Computer-readable media includes both computer storage media and communication media including any medium that facilitates transfer of a computer program from one place to another. A storage media may be any available media that can be accessed by a general purpose or special purpose computer. An exemplary storage medium is coupled to the processor such the processor can read information from, and write information to, the storage medium. Of course, the storage medium may also be integral to the processor. The processor and the storage medium may reside in an ASIC. Additionally, the ASIC may reside in user equipment. Of course, the processor and the storage medium may reside as discrete components in a communication device.
The present application further provides a program product comprising a computer program stored in a readable storage medium, from which the computer program can be read by at least one processor of a server, the execution of the computer program by the at least one processor causing the server to carry out the method of any of the embodiments of the invention described above.
Those of ordinary skill in the art will understand that: all or a portion of the steps of implementing the above-described method embodiments may be performed by hardware associated with program instructions. The program may be stored in a computer-readable storage medium. When executed, the program performs steps comprising the method embodiments described above; and the aforementioned storage medium includes: various media that can store program codes, such as ROM, RAM, magnetic or optical disks.
Finally, it should be noted that: the above embodiments are only used to illustrate the technical solution of the present invention, and not to limit the same; while the invention has been described in detail and with reference to the foregoing embodiments, it will be understood by those skilled in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some or all of the technical features may be equivalently replaced; and the modifications or the substitutions do not make the essence of the corresponding technical solutions depart from the scope of the technical solutions of the embodiments of the present invention.

Claims (10)

1. A code specification checking method, comprising:
carrying out syntactic analysis on a source code to be detected to generate an abstract syntactic tree;
determining all method call nodes in the abstract syntax tree;
if the method calling node exists, searching whether a matched method exists in an attribute method list of the local cache;
and if the matched method does not exist, marking the code information corresponding to the method calling node.
2. The method of claim 1, wherein prior to looking up whether there is a matching method from the locally cached attribute method list, further comprising:
searching whether an original document file exists from a local specified directory;
if the original document file does not exist, the official document acquired from the online is used as the original document and is stored in a local specified directory;
and cleaning and sorting the original document file to obtain an integral attribute method list without redundant information, wherein the attribute method list is used for recording all methods normally used by the source code at present.
3. The method of claim 1, wherein parsing the source code to be detected to generate an abstract syntax tree comprises:
performing manual syntax analysis on a source code to be detected through an application programming interface provided by a compiler;
generating a corresponding abstract syntax tree for each file in the source code to be detected; wherein each node on the abstract syntax spanning tree characterizes the parsed source code data.
4. The method according to any one of claims 1-3, further comprising:
acquiring configuration parameters required by code specification checking logic from an engineering directory; the configuration parameters set under the engineering target keep information synchronization with the terminal of a developer through a management tool;
performing code specification checking on each syntax node on the abstract syntax tree through the configuration parameters;
and if the code specification is not met, marking the code information.
5. The method of claim 4, further comprising:
generating a code specification inspection report according to the marked file and code line number of the code corresponding to the calling node of the method and the marked file and code line number of the code;
and displaying the code specification checking report in a compiling result column of the integrated development environment.
6. A code specification checking apparatus, comprising:
the analysis module is used for carrying out syntactic analysis on the source code to be detected and generating an abstract syntactic tree;
a determining module, configured to determine all method call nodes in the abstract syntax tree;
the comparison module is used for searching whether a matched method exists in the attribute method list of the local cache when the method calling node exists;
and the first marking module is used for marking the code information corresponding to the method calling node when no matched method exists.
7. The apparatus of claim 6, further comprising: an acquisition module to:
searching whether an original document file exists from a local specified directory;
if the original document file does not exist, the official document acquired from the online is used as the original document and is stored in a local specified directory;
and cleaning and sorting the original document file to obtain an integral attribute method list without redundant information, wherein the attribute method list is used for recording all methods normally used by the source code at present.
8. The apparatus of claim 6, wherein the analysis module is specifically configured to:
performing manual syntax analysis on a source code to be detected through an application programming interface provided by a compiler;
generating a corresponding abstract syntax tree for each file in the source code to be detected; wherein each node on the abstract syntax spanning tree characterizes the parsed source code data.
9. A code specification checking system, comprising: the device comprises a memory and a processor, wherein the memory stores executable instructions of the processor; wherein the processor is configured to perform the code specification checking method of any one of claims 1-5 via execution of the executable instructions.
10. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the code specification checking method of any one of claims 1 to 5.
CN201910562438.1A 2019-06-26 2019-06-26 Code specification checking method, device, system and storage medium Pending CN112148581A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910562438.1A CN112148581A (en) 2019-06-26 2019-06-26 Code specification checking method, device, system and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910562438.1A CN112148581A (en) 2019-06-26 2019-06-26 Code specification checking method, device, system and storage medium

Publications (1)

Publication Number Publication Date
CN112148581A true CN112148581A (en) 2020-12-29

Family

ID=73869868

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910562438.1A Pending CN112148581A (en) 2019-06-26 2019-06-26 Code specification checking method, device, system and storage medium

Country Status (1)

Country Link
CN (1) CN112148581A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113010183A (en) * 2021-04-30 2021-06-22 中国工商银行股份有限公司 Code conversion method and device

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113010183A (en) * 2021-04-30 2021-06-22 中国工商银行股份有限公司 Code conversion method and device

Similar Documents

Publication Publication Date Title
US9898387B2 (en) Development tools for logging and analyzing software bugs
US8627290B2 (en) Test case pattern matching
CN110704297B (en) Code review method, device, computer equipment and storage medium
CN111078568B (en) Code specification method, apparatus, computer device and storage medium
CN111459495B (en) Unit test code file generation method, electronic device and storage medium
CN106371997B (en) Code checking method and device
US11327722B1 (en) Programming language corpus generation
JP2018505506A (en) Machine-based instruction editing
CN105512021A (en) Method and device for Diff analysis used for software testing
CN113867704A (en) Code test processing method and device, electronic equipment and storage medium
Risberg Alaküla et al. Property Probes: Source Code Based Exploration of Program Analysis Results
CN113094252B (en) Test case generation method and device, computer equipment and storage medium
CN112148581A (en) Code specification checking method, device, system and storage medium
CN112540925A (en) New characteristic compatibility detection system and method, electronic device and readable storage medium
US11740895B2 (en) Generation of software program repair explanations
US9747085B2 (en) Source code generation from prototype source
Ben Charrada et al. An automated hint generation approach for supporting the evolution of requirements specifications
CN114895914A (en) Log output code generation method and device, electronic equipment and storage medium
CN115705297A (en) Code call detection method, device, computer equipment and storage medium
CN113760291A (en) Log output method and device
CN111078574A (en) Method and device for generating influence analysis report
CN111722996B (en) Interactive standard compliance testing method and device
KR102523329B1 (en) Method for visualizing performance improvement element and changing software code for power improvement
CN116774988B (en) Method and device for releasing frame package mode symbol dependence
CN112035367B (en) Method and system for checking workflow correctness of big data platform

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