[go: up one dir, main page]

CN117370144A - Code detection method, apparatus, storage medium, and program product - Google Patents

Code detection method, apparatus, storage medium, and program product Download PDF

Info

Publication number
CN117370144A
CN117370144A CN202210773081.3A CN202210773081A CN117370144A CN 117370144 A CN117370144 A CN 117370144A CN 202210773081 A CN202210773081 A CN 202210773081A CN 117370144 A CN117370144 A CN 117370144A
Authority
CN
China
Prior art keywords
code
function
detected
position information
keyword
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
CN202210773081.3A
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.)
Douyin Vision Beijing Co Ltd
Original Assignee
Douyin Vision Beijing 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 Douyin Vision Beijing Co Ltd filed Critical Douyin Vision Beijing Co Ltd
Priority to CN202210773081.3A priority Critical patent/CN117370144A/en
Publication of CN117370144A publication Critical patent/CN117370144A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Prevention of errors by analysis, debugging or testing of software
    • G06F11/3604Analysis of software for verifying properties of programs
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/903Querying
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Databases & Information Systems (AREA)
  • Software Systems (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Computational Linguistics (AREA)
  • Data Mining & Analysis (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The embodiment of the disclosure provides a code detection method, equipment, a storage medium and a program product, wherein the method comprises the steps of obtaining a code to be detected, scanning the code to be detected according to a keyword, obtaining position information of the keyword in the code to be detected, and searching function content corresponding to the keyword according to a target corresponding relation and the position information, wherein the target corresponding relation comprises a corresponding relation between the function content and the position information of the function content corresponding code in the code to be detected, and the target corresponding relation is established based on an abstract syntax tree. The method provided by the embodiment of the disclosure not only reduces labor cost, but also improves the efficiency of code detection.

Description

Code detection method, apparatus, storage medium, and program product
Technical Field
The embodiment of the disclosure relates to the technical field of computers, in particular to a code detection method, a code detection device, a storage medium and a program product.
Background
In the daily detection and maintenance process of service codes, in order to prevent and eliminate various possible problems in the codes, keyword detection needs to be carried out on the codes.
In the related art, after detecting a code line with a keyword, it is generally necessary to manually open a code file in which the code line is located, and determine whether the code line with the keyword does have a problem by combining the context of the code line.
However, the inventors found that the above-described manner has at least the following technical problems: the manpower cost is higher, and detection efficiency is lower.
Disclosure of Invention
The embodiment of the disclosure provides a code detection method, a device, a storage medium and a program product, which are used for solving the problem that the interaction efficiency between a user and a network side is poor because first default prompt information corresponding to an input box cannot be known when the user inputs the input box again after the user interrupts the input of the input box.
In a first aspect, an embodiment of the present disclosure provides a code detection method, including:
acquiring a code to be detected;
scanning the code to be detected according to the keywords to obtain the position information of the keywords in the code to be detected;
searching the function content corresponding to the keyword according to the target corresponding relation and the position information; the target corresponding relation comprises a corresponding relation between function content and position information of a function content corresponding code in the code to be detected; the target correspondence is established based on an abstract syntax tree.
In a second aspect, an embodiment of the present disclosure provides a code detection apparatus, including:
the acquisition module is used for acquiring the code to be detected;
the scanning module is used for scanning the code to be detected according to the keyword to obtain the position information of the keyword in the code to be detected;
the searching module is used for searching the function content corresponding to the keyword according to the target corresponding relation and the position information; the target corresponding relation comprises a corresponding relation between function content and position information of a function content corresponding code in the code to be detected; the target correspondence is established based on an abstract syntax tree.
In a third aspect, an embodiment of the present disclosure provides an electronic device, including: a processor and a memory;
the memory stores computer-executable instructions;
the processor executes computer-executable instructions stored in the memory to cause the at least one processor to perform the code detection method as described above in the first aspect and the various possible designs of the first aspect.
In a fourth aspect, embodiments of the present disclosure provide a computer-readable storage medium having stored therein computer-executable instructions which, when executed by a processor, implement the code detection method according to the first aspect and the various possible designs of the first aspect.
In a fifth aspect, embodiments of the present disclosure provide a computer program product comprising a computer program which, when executed by a processor, implements the code detection method according to the first aspect and the various possible designs of the first aspect.
The method includes the steps of obtaining a code to be detected, scanning the code to be detected according to a keyword, obtaining position information of the keyword in the code to be detected, and searching function content corresponding to the keyword according to a target corresponding relation and the position information, wherein the target corresponding relation comprises a corresponding relation between the function content and the position information of the code corresponding to the function content in the code to be detected, and the target corresponding relation is established based on an abstract syntax tree. According to the method and the device, the position information of the keywords in the code to be detected is determined based on the keywords, and further the function content corresponding to the position information of the keywords is called based on the corresponding relation between the function content and the position information of the code corresponding to the function content in the code to be detected, so that a detector can rapidly detect whether the keywords contained in the function content exist based on the function content, labor cost is reduced, and code detection efficiency is improved.
Drawings
In order to more clearly illustrate the embodiments of the present disclosure or the solutions in the prior art, a brief description will be given below of the drawings that are needed in the embodiments or the description of the prior art, it being obvious that the drawings in the following description are some embodiments of the present disclosure, and that other drawings may be obtained from these drawings without inventive effort to a person of ordinary skill in the art.
Fig. 1 is a schematic view of an application scenario provided in an embodiment of the present disclosure;
fig. 2 is a schematic flow chart of a code detection method according to an embodiment of the disclosure;
fig. 3 is a schematic diagram of a code detection method according to a second embodiment of the present disclosure;
fig. 4 is a block diagram of a code detection apparatus provided in an embodiment of the present disclosure;
fig. 5 is a schematic hardware structure of a code detection device according to an embodiment of the present disclosure.
Detailed Description
For the purposes of making the objects, technical solutions and advantages of the embodiments of the present disclosure more apparent, the technical solutions of the embodiments of the present disclosure will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present disclosure, and it is apparent that the described embodiments are some embodiments of the present disclosure, but not all embodiments. All other embodiments, which can be made by one of ordinary skill in the art without inventive effort, based on the embodiments in this disclosure are intended to be within the scope of this disclosure.
In the daily detection and maintenance process of service codes, in order to prevent and eliminate various possible problems in the codes, keyword detection needs to be carried out on the codes. In the related art, after detecting a code line with a keyword, it is generally required to manually open a code file in which the code line is located, and determine whether the code line with the keyword actually has a problem by combining the context of the code line, for example, when detecting the keyword of the code, when receiving a hit code line in which the keyword is located and a code file link corresponding to the hit code line, it is generally required to jump to the code file in which the hit code line is located by manually clicking the code file link, so as to find a function to which the hit code line belongs, and determine whether the hit code line has a problem based on the function to which the hit code line belongs.
In order to solve the technical problems, the inventor researches and discovers that the corresponding relation between the function content of each function in the code file and the position information of the codes corresponding to each function respectively can be established in advance, after the position information of the keywords in the codes to be detected is determined, the function content corresponding to the keywords can be locked quickly by inquiring the corresponding relation, and further whether the code row where the keywords are located has problems or not can be judged based on the function content. Based on the above, the embodiment of the disclosure provides a code detection method, which determines the position information of a keyword in a code to be detected based on the keyword, and further invokes the function content corresponding to the position information of the keyword based on the correspondence between the function content and the position information of the code corresponding to the function content in the code to be detected, so that a detector can quickly detect whether the keyword contained in the function content exists based on the function content, thereby not only reducing labor cost, but also improving the code detection efficiency.
Referring to fig. 1, fig. 1 is a schematic view of an application scenario provided in an embodiment of the present disclosure. As shown in fig. 1, the terminal 101 is communicatively connected to the server 102, the terminal 101 is configured to upload a code to be detected to the server 102, the server 102 is configured to determine location information of a keyword in the code to be detected, for example, a line number of a code line where the keyword is located, based on a plurality of related keywords predetermined according to a possible problem of the code, and further search function content corresponding to the location information of the keyword according to a correspondence between the function content and the location information of the code corresponding to the function content, and feed the function content back to the terminal 101, and the terminal 101 is further configured to display the function content corresponding to the location information of the keyword, so as to perform problem detection based on the function content. Optionally, the server 102 is further configured to determine and store a correspondence between the function content in the code file and the location information of the corresponding code. The determining of the correspondence may be determining the correspondence of a plurality of code files before the code to be detected is detected, or may be determining the correspondence of only the code file corresponding to the keyword after the code to be detected is started and the position information of the keyword is determined, specifically, may be selected according to actual needs, which is not limited in the disclosure.
In a specific implementation process, in response to a touch operation of a detection person, the terminal 101 sends a code to be detected to the server 102. The server 102 determines the position information of the keywords in the code to be detected, for example, the line number of the code line where the keywords are located, according to a plurality of keywords predetermined by the possible problems, further searches the function content corresponding to the position information of the keywords according to the corresponding relation between the function content and the position information of the code corresponding to the function content, and feeds back the function content to the terminal 101, and the terminal 101 displays the function content corresponding to the position information of the keywords so as to detect the problems based on the function content. In the embodiment of the present disclosure, a plurality of related keywords predetermined according to a possible problem of the code may be stored in the server 102 in advance, or may be sent to the server 102 through the terminal 101, which is not limited in the present disclosure.
Referring to fig. 2, fig. 2 is a schematic flow chart of a code detection method according to an embodiment of the disclosure. The method of the present embodiment may be applied to a terminal device or a server, and the code detection method includes:
201. and acquiring a code to be detected.
In this embodiment, the code to be detected may be a newly added code. The newly added code may be from a plurality of code files in a code repository.
Specifically, the code of the code file whose last update time is later than the last detection time may be determined as the code to be detected according to the last update time of the code file.
202. And scanning the code to be detected according to the keywords to obtain the position information of the keywords in the code to be detected.
In this embodiment, the keyword may be a word related to various problems to be detected. For example, because of temporary changes in design requirements, the active site in the business process needs to be changed, and any code related to the active site needs to be checked to see if it is needed to be corrected.
Specifically, the keywords can be searched in the code to be detected one by one, and the position information of the keywords is returned. Illustratively, a keyword table is formulated that violates the compliance rules based on the code compliance rules. Based on the keyword table, scanning the code to be detected, and if the keyword is hit, determining the keyword as a suspected illegal code. Based on the scanning result, the code segments corresponding to the keywords and the corresponding line numbers are collected, so that the query of the corresponding function content is performed from the corresponding relation between the function content and the position relation of the corresponding codes of the function content based on the line numbers.
The location information of the keyword may be a line number of a line where the keyword is located in the corresponding code file, or may be a line number of a line where the keyword is located in the corresponding code file, and a line number of a previous line and a line number of a next line, which is not limited in this disclosure.
203. Searching the function content corresponding to the keywords according to the target corresponding relation and the position information; the target corresponding relation comprises the corresponding relation between the function content and the position information of the function content corresponding code in the code to be detected; the target correspondence is established based on an abstract syntax tree.
In this embodiment, the target correspondence may be previously established for each code file in the code repository before detection, for example, the code repository includes 10 code files, a correspondence is established for each code file, and a correspondence of 10 code files is obtained, in subsequent detection, if it is determined that the keyword is from an a code file in the 10 code files, the correspondence corresponding to the a code file may be first found, and then function content corresponding to the location information of the keyword is found based on the correspondence. The target correspondence may also be established only for the code file in which the keyword is located after determining the position information of the keyword in the file to be detected, for example, the code repository includes 10 code files, and in the subsequent detection, if it is determined that the keyword is from the B code files in the 10 code files, the correspondence of the B code files may be established, and then the function content corresponding to the position information of the keyword is searched based on the correspondence. The specific manner of determining the target correspondence may be determined according to actual situations, which is not limited in the present disclosure.
Specifically, after the position information of the keyword is determined based on the keyword, a function corresponding to the position information of the keyword, that is, a function to which the keyword belongs, may be searched from the target correspondence based on the position information of the keyword, so that the entire function content is called. And detecting the whole function content corresponding to the keywords to obtain a detection result of whether the keywords have problems or not, and further finishing the detection of the code to be detected.
For example, in the target correspondence, the position information (m-th line to m+10-th line) of the code whose function content of the function y corresponds to the function y in the code file a is included. When the position information of the keyword is determined to be m+2 line in the code file a, since m+2 is greater than m and less than m+10, the function to which the keyword belongs can be determined to be the function y, and further the function content of the function y can be called as the function content corresponding to the keyword, so that the function content can be detected, whether the keyword has a problem or not is determined, the detection of the keyword is completed, and after the detection of each keyword of the code to be detected is completed, the detection of the code to be detected is completed.
As can be seen from the above description, in this embodiment, the location information of the keyword in the code to be detected is determined based on the keyword, and then the function content corresponding to the location information of the keyword is called based on the correspondence between the function content and the location information of the code corresponding to the function content in the code to be detected, so that a inspector can quickly detect whether the keyword contained in the function content exists based on the function content, thereby not only reducing labor cost, but also improving code detection efficiency.
In one embodiment of the present disclosure, the codes to be detected include codes other than functions, and if the position information of the keyword does not exist in the target correspondence, that is, the keyword is located in the codes corresponding to the non-functions, the plurality of lines of codes corresponding to the position information may be determined according to the position information of the keyword in the codes to be detected. Therefore, a detector can detect whether the keyword has a problem according to the returned multi-line codes, so that the codes at the positions of the keyword can be deleted or corrected.
In one embodiment of the present disclosure, to facilitate problem detection by a inspector, after finding function content corresponding to a keyword, a reminder message may be pushed to the inspector, so that the inspector detects and processes a problem code, and after step 203, the method may include: generating a reminding message according to the function content corresponding to the keyword and displaying the reminding message on a message reminding interface; may further include: and deleting or correcting the function content in response to the touch operation acted on the message reminding interface.
Specifically, after function content corresponding to the keywords is found, the function content can be pushed to a message reminding interface as a reminding message, for convenience in checking, the keywords in the function content can be highlighted, for example, the fonts can be enlarged, thickened and the like, optionally, for convenience in processing the function content, a deletion control or a modification control can be set on the reminding interface, if a detection person triggers the deletion control, the function content in a code to be detected is deleted, if the detection person triggers the modification control, an editing frame can be shot out in the reminding interface, so that the detection person inputs the modified content into the editing frame, after the editing is finished, the determination control is triggered, and the function content in the code to be detected can be automatically replaced by the content of the current editing frame.
Referring to fig. 3, fig. 3 is a second flowchart of a code detection method according to an embodiment of the disclosure. In one embodiment of the present disclosure, in order to reduce workload and resource consumption for establishing the target correspondence based on the embodiment shown in fig. 2, the determination of the target correspondence may be performed for a code file where the keyword is located after determining the location information of the keyword, where the code detection method includes:
301. and acquiring a code to be detected.
302. And scanning the code to be detected according to the keywords to obtain the position information of the keywords in the code to be detected.
Steps 301 to 302 in this embodiment are similar to steps 201 to 202 in the above embodiment, and will not be repeated here.
303. And determining the corresponding relation of the targets. The target correspondence includes correspondence between function content and position information of the function content correspondence code in the code to be detected.
In this embodiment, there may be a plurality of methods for determining the target correspondence.
In one implementation, the code file may be processed based on a regular expression to obtain a correspondence between the function content in the code file and the location information of the corresponding code. Specifically, a regular expression can be established based on rules such as a retraction format in the process of writing the functions, the code file is scanned based on the regular expression, code rows conforming to the regular expression are searched, and further, the start and stop rows of each function are determined, so that the corresponding relation between the function content of each function in the code file and the position information of the corresponding code is determined.
In another implementation manner, in order to improve accuracy, the determination of the target corresponding relationship may be performed by extracting an abstract syntax tree. Specifically, determining the target correspondence may include: extracting abstract syntax trees from codes to be detected; and according to the abstract syntax tree, establishing corresponding relations between a plurality of function contents in the code to be detected and the position information of the corresponding code, and obtaining the target corresponding relation.
The method for establishing the corresponding relation between the plurality of function contents in the code to be detected and the position information of the corresponding code according to the abstract syntax tree to obtain the target corresponding relation may include: monitoring each node of the abstract syntax tree to obtain a plurality of function nodes; aiming at the function corresponding to each function node, acquiring the function content of the function and the position information of the code corresponding to the function; and establishing corresponding relations between the function contents of the functions and the position information of the codes corresponding to the functions respectively, and obtaining target corresponding relations. Optionally, for the function corresponding to each function node, obtaining the function content of the function may include: and performing preamble traversal on the child nodes of the function node to obtain the function content of the function. Optionally, the location information of the function corresponding code includes a start line number and a stop line number of the function corresponding code.
Illustratively, the code file may be parsed by a parser, such as an Antlr tool, to obtain an abstract syntax tree corresponding to the code file. The abstract syntax tree comprises a plurality of nodes, each node can be detected to obtain a plurality of function nodes, the process can be carried out by adopting a monitoring tool, for example, the abstract syntax tree can be monitored by a Listener monitoring tool built in an Antlr tool to obtain a plurality of function nodes. And further, corresponding function information and function content can be obtained for each function node. The function information may include a function name and location information of the corresponding code, and the location information may include a start line number and a stop line number of the corresponding code of the function. In the process of acquiring the corresponding function content for each function node, each child node of the function node can be traversed to acquire the corresponding function content. The traversing may take a variety of forms, for example, a preamble traversing may be used.
304. And searching the function content corresponding to the keywords according to the target corresponding relation and the position information.
Step 304 in this embodiment is similar to step 203 in the above embodiment, and will not be repeated here.
From the above description, it can be known that, by establishing the target correspondence with respect to the code file in which the keyword is located after determining the position information of the keyword, the target correspondence can be established more specifically, and the computing resource can be saved by only establishing the target correspondence with respect to the code file in which the sensitive word exists.
Corresponding to the code detection method of the above embodiment, fig. 4 is a block diagram of the structure of the code detection apparatus provided by the embodiment of the present disclosure. For ease of illustration, only portions relevant to embodiments of the present disclosure are shown. Referring to fig. 4, the apparatus 40 includes: an acquisition module 401, a scanning module 402 and a search module 403.
The acquiring module 401 is configured to acquire a code to be detected.
And the scanning module 402 is configured to scan the code to be detected according to the keyword, and obtain the position information of the keyword in the code to be detected.
The searching module 403 is configured to search the function content corresponding to the keyword according to the target correspondence and the location information; the target corresponding relation comprises the corresponding relation between the function content and the position information of the function content corresponding code in the code to be detected; the target correspondence is established based on an abstract syntax tree. Keyword(s)
In one embodiment of the present disclosure, the apparatus 40 further comprises: a determining module 404, configured to determine a target correspondence.
In one embodiment of the present disclosure, the determining module 404 is specifically configured to:
extracting abstract syntax trees from codes to be detected;
and according to the abstract syntax tree, establishing corresponding relations between a plurality of function contents in the code to be detected and the position information of the corresponding code, and obtaining the target corresponding relation.
In one embodiment of the present disclosure, the determining module 404 is specifically configured to:
monitoring each node of the abstract syntax tree to obtain a plurality of function nodes;
aiming at the function corresponding to each function node, acquiring the function content of the function and the position information of the code corresponding to the function;
and establishing corresponding relations between the function contents of the functions and the position information of the codes corresponding to the functions respectively, and obtaining target corresponding relations.
In one embodiment of the present disclosure, the determining module 404 is specifically configured to:
and performing preamble traversal on the child nodes of the function node to obtain the function content of the function.
In one embodiment of the present disclosure, the location information of the function correspondence code includes a start line number and a stop line number of the function correspondence code.
In one embodiment of the present disclosure, the lookup module 403 is specifically configured to:
if the position information of the keyword in the code to be detected exists in the target corresponding relation, searching the function content corresponding to the keyword according to the target corresponding relation and the position information;
The method further comprises the steps of: and the multi-line code determining module is used for determining multi-line codes corresponding to the position information according to the position information of the keywords in the codes to be detected if the position information of the keywords in the codes to be detected does not exist in the target corresponding relation.
In one embodiment of the present disclosure, the apparatus further comprises: display module for
Generating a reminding message according to the function content corresponding to the keyword and displaying the reminding message on a message reminding interface;
and deleting or correcting the function content in response to the touch operation acted on the message reminding interface.
The device provided in this embodiment may be used to execute the technical solution of the foregoing method embodiment, and its implementation principle and technical effects are similar, and this embodiment will not be described herein again.
In order to achieve the above embodiments, the embodiments of the present disclosure further provide an electronic device.
Referring to fig. 5, a schematic diagram of a structure of an electronic device 500 suitable for use in implementing embodiments of the present disclosure is shown, where the electronic device 500 may be a terminal device or a server. The terminal device may include, but is not limited to, a mobile terminal such as a mobile phone, a notebook computer, a digital broadcast receiver, a personal digital assistant (Personal Digital Assistant, PDA for short), a tablet (Portable Android Device, PAD for short), a portable multimedia player (Portable Media Player, PMP for short), an in-vehicle terminal (e.g., an in-vehicle navigation terminal), and the like, and a fixed terminal such as a digital TV, a desktop computer, and the like. The electronic device shown in fig. 5 is merely an example and should not be construed to limit the functionality and scope of use of the disclosed embodiments.
As shown in fig. 5, the electronic apparatus 500 may include a processing device (e.g., a central processing unit, a graphics processor, etc.) 501 that may perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM) 502 or a program loaded from a storage device 508 into a random access Memory (Random Access Memory, RAM) 503. In the RAM 503, various programs and data required for the operation of the electronic apparatus 500 are also stored. The processing device 501, the ROM 502, and the RAM 503 are connected to each other via a bus 504. An input/output (I/O) interface 505 is also connected to bus 504.
In general, the following devices may be connected to the I/O interface 505: input devices 506 including, for example, a touch screen, touchpad, keyboard, mouse, camera, microphone, accelerometer, gyroscope, etc.; an output device 507 including, for example, a liquid crystal display (Liquid Crystal Display, abbreviated as LCD), a speaker, a vibrator, and the like; storage 508 including, for example, magnetic tape, hard disk, etc.; and communication means 509. The communication means 509 may allow the electronic device 500 to communicate with other devices wirelessly or by wire to exchange data. While fig. 5 shows an electronic device 500 having various means, it is to be understood that not all of the illustrated means are required to be implemented or provided. More or fewer devices may be implemented or provided instead.
In particular, according to embodiments of the present disclosure, the processes described above with reference to flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method shown in the flowcharts. In such an embodiment, the computer program may be downloaded and installed from a network via the communication means 509, or from the storage means 508, or from the ROM 502. The above-described functions defined in the methods of the embodiments of the present disclosure are performed when the computer program is executed by the processing device 501.
It should be noted that the computer readable medium described in the present disclosure may be a computer readable signal medium or a computer readable storage medium, or any combination of the two. The computer readable storage medium can be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or a combination of any of the foregoing. More specific examples of the computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the context of this disclosure, a computer-readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In the present disclosure, however, the computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, with the computer-readable program code embodied therein. Such a propagated data signal may take any of a variety of forms, including, but not limited to, electro-magnetic, optical, or any suitable combination of the foregoing. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: electrical wires, fiber optic cables, RF (radio frequency), and the like, or any suitable combination of the foregoing.
The computer readable medium may be contained in the electronic device; or may exist alone without being incorporated into the electronic device.
The computer-readable medium carries one or more programs which, when executed by the electronic device, cause the electronic device to perform the methods shown in the above-described embodiments.
Computer program code for carrying out operations of the present disclosure may be written in one or more programming languages, including an object oriented programming language such as Java, smalltalk, C ++ and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any kind of network, including a local area network (Local Area Network, LAN for short) or a wide area network (Wide Area Network, WAN for short), or it may be connected to an external computer (e.g., connected via the internet using an internet service provider).
The flowcharts and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The units involved in the embodiments of the present disclosure may be implemented by means of software, or may be implemented by means of hardware. The name of the unit does not in any way constitute a limitation of the unit itself, for example the first acquisition unit may also be described as "unit acquiring at least two internet protocol addresses".
The functions described above herein may be performed, at least in part, by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: a Field Programmable Gate Array (FPGA), an Application Specific Integrated Circuit (ASIC), an Application Specific Standard Product (ASSP), a system on a chip (SOC), a Complex Programmable Logic Device (CPLD), and the like.
In the context of this disclosure, a machine-readable medium may be a tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. The machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. The machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
According to a first aspect, according to one or more embodiments of the present disclosure, there is provided a code detection method, including:
acquiring a code to be detected;
scanning the code to be detected according to the keywords to obtain the position information of the keywords in the code to be detected;
searching the function content corresponding to the keywords according to the target corresponding relation and the position information; the target corresponding relation comprises the corresponding relation between the function content and the position information of the function content corresponding code in the code to be detected; the target correspondence is established based on an abstract syntax tree. Keyword(s)
According to one or more embodiments of the present disclosure, the method further comprises:
and determining the corresponding relation of the targets.
According to one or more embodiments of the present disclosure, determining a target correspondence includes: extracting abstract syntax trees from codes to be detected; and according to the abstract syntax tree, establishing corresponding relations between a plurality of function contents in the code to be detected and the position information of the corresponding code, and obtaining the target corresponding relation.
According to one or more embodiments of the present disclosure, according to an abstract syntax tree, a correspondence between a plurality of function contents in a code to be detected and position information of a corresponding code is established, and a target correspondence is obtained, including: monitoring each node of the abstract syntax tree to obtain a plurality of function nodes; aiming at the function corresponding to each function node, acquiring the function content of the function and the position information of the code corresponding to the function; and establishing corresponding relations between the function contents of the functions and the position information of the codes corresponding to the functions respectively, and obtaining target corresponding relations.
According to one or more embodiments of the present disclosure, for a function corresponding to each function node, obtaining function content of the function includes: and performing preamble traversal on the child nodes of the function node to obtain the function content of the function.
In accordance with one or more embodiments of the present disclosure, the location information of the function correspondence code includes a start line number and a stop line number of the function correspondence code.
According to one or more embodiments of the present disclosure, according to the target correspondence and the location information, searching the function content corresponding to the keyword includes: if the position information of the keyword in the code to be detected exists in the target corresponding relation, searching the function content corresponding to the keyword according to the target corresponding relation and the position information;
the method further comprises the steps of:
if the position information of the keyword in the code to be detected does not exist in the target corresponding relation, determining a plurality of lines of codes corresponding to the position information according to the position information of the keyword in the code to be detected.
According to one or more embodiments of the present disclosure, the method further comprises:
generating a reminding message according to the function content corresponding to the keyword and displaying the reminding message on a message reminding interface;
and deleting or correcting the function content in response to the touch operation acted on the message reminding interface.
In a second aspect, according to one or more embodiments of the present disclosure, there is provided a code detection apparatus including:
the acquisition module is used for acquiring the code to be detected;
the scanning module is used for scanning the code to be detected according to the keywords to obtain the position information of the keywords in the code to be detected;
the searching module is used for searching the function content corresponding to the keyword according to the target corresponding relation and the position information; the target corresponding relation comprises the corresponding relation between the function content and the position information of the function content corresponding code in the code to be detected; the target correspondence is established based on an abstract syntax tree. Keyword(s)
According to one or more embodiments of the present disclosure, the apparatus further comprises: and the determining module is used for determining the corresponding relation of the targets.
According to one or more embodiments of the present disclosure, the determining module is specifically configured to: extracting abstract syntax trees from codes to be detected; and according to the abstract syntax tree, establishing corresponding relations between a plurality of function contents in the code to be detected and the position information of the corresponding code, and obtaining the target corresponding relation.
According to one or more embodiments of the present disclosure, the determining module is specifically configured to: monitoring each node of the abstract syntax tree to obtain a plurality of function nodes; aiming at the function corresponding to each function node, acquiring the function content of the function and the position information of the code corresponding to the function; and establishing corresponding relations between the function contents of the functions and the position information of the codes corresponding to the functions respectively, and obtaining target corresponding relations.
According to one or more embodiments of the present disclosure, the determining module is specifically configured to: and performing preamble traversal on the child nodes of the function node to obtain the function content of the function.
In accordance with one or more embodiments of the present disclosure, the location information of the function correspondence code includes a start line number and a stop line number of the function correspondence code.
According to one or more embodiments of the present disclosure, the search module is specifically configured to: if the position information of the keyword in the code to be detected exists in the target corresponding relation, searching the function content corresponding to the keyword according to the target corresponding relation and the position information; the method further comprises the steps of: and the multi-line code determining module is used for determining multi-line codes corresponding to the position information according to the position information of the keywords in the codes to be detected if the position information of the keywords in the codes to be detected does not exist in the target corresponding relation.
According to one or more embodiments of the present disclosure, the apparatus further comprises: display module for
Generating a reminding message according to the function content corresponding to the keyword and displaying the reminding message on a message reminding interface;
and deleting or correcting the function content in response to the touch operation acted on the message reminding interface.
In a third aspect, according to one or more embodiments of the present disclosure, there is provided an electronic device comprising: at least one processor and memory;
The memory stores computer-executable instructions;
at least one processor executes computer-executable instructions stored in a memory, causing the at least one processor to perform the code detection method as described above in the first aspect and various possible designs of the first aspect.
In a fourth aspect, according to one or more embodiments of the present disclosure, there is provided a computer-readable storage medium having stored therein computer-executable instructions which, when executed by a processor, implement the code detection method of the first aspect and the various possible designs of the first aspect as above.
In a fifth aspect, according to one or more embodiments of the present disclosure, there is provided a computer program product comprising a computer program which, when executed by a processor, implements the code detection method of the above first aspect and the various possible designs of the first aspect
The foregoing description is only of the preferred embodiments of the present disclosure and description of the principles of the technology being employed. It will be appreciated by persons skilled in the art that the scope of the disclosure referred to in this disclosure is not limited to the specific combinations of features described above, but also covers other embodiments which may be formed by any combination of features described above or equivalents thereof without departing from the spirit of the disclosure. Such as those described above, are mutually substituted with the technical features having similar functions disclosed in the present disclosure (but not limited thereto).
Moreover, although operations are depicted in a particular order, this should not be understood as requiring that such operations be performed in the particular order shown or in sequential order. In certain circumstances, multitasking and parallel processing may be advantageous. Likewise, while several specific implementation details are included in the above discussion, these should not be construed as limiting the scope of the present disclosure. Certain features that are described in the context of separate embodiments can also be implemented in combination in a single embodiment. Conversely, various features that are described in the context of a single embodiment can also be implemented in multiple embodiments separately or in any suitable subcombination.
Although the subject matter has been described in language specific to structural features and/or methodological acts, it is to be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or acts described above. Rather, the specific features and acts described above are example forms of implementing the claims.

Claims (11)

1. A code detection method, comprising:
acquiring a code to be detected;
scanning the code to be detected according to the keywords to obtain the position information of the keywords in the code to be detected;
Searching the function content corresponding to the keyword according to the target corresponding relation and the position information; the target corresponding relation comprises a corresponding relation between function content and position information of a function content corresponding code in the code to be detected; the target correspondence is established based on an abstract syntax tree.
2. The method according to claim 1, wherein the method further comprises:
extracting an abstract syntax tree from the code to be detected;
and establishing a corresponding relation between function content in the code to be detected and position information of the function content corresponding code in the code to be detected according to the abstract syntax tree, and obtaining the target corresponding relation.
3. The method according to claim 2, wherein the establishing, according to the abstract syntax tree, a correspondence between function content in the code to be detected and location information of a function content corresponding code in the code to be detected, to obtain the target correspondence, includes:
monitoring each node of the abstract syntax tree to obtain a plurality of function nodes;
aiming at the function corresponding to each function node, acquiring the function content of the function and the position information of the code corresponding to the function;
And establishing corresponding relations between function contents of the functions and position information of codes corresponding to the functions respectively, and obtaining the target corresponding relations.
4. A method according to claim 3, wherein the obtaining, for each function corresponding to each function node, the function content of the function includes:
and performing precursor traversal on the child nodes of the function node to obtain the function content of the function.
5. A method according to claim 3, wherein the location information of the function corresponding code comprises a start line number and a stop line number of the function corresponding code.
6. The method according to any one of claims 1-5, wherein searching the function content corresponding to the keyword according to the target correspondence and the location information includes:
if the position information of the keyword in the code to be detected exists in the target corresponding relation, searching the function content corresponding to the keyword according to the target corresponding relation and the position information;
the method further comprises the steps of:
if the position information of the keyword in the code to be detected does not exist in the target corresponding relation, determining a plurality of lines of codes corresponding to the position information according to the position information of the keyword in the code to be detected.
7. The method according to any one of claims 1-5, further comprising:
generating a reminding message according to the function content corresponding to the keyword and displaying the reminding message on a message reminding interface;
and deleting or correcting the function content in response to touch operation acting on the message reminding interface.
8. A code detection apparatus, characterized by comprising:
the acquisition module is used for acquiring the code to be detected;
the scanning module is used for scanning the code to be detected according to the keyword to obtain the position information of the keyword in the code to be detected;
the searching module is used for searching the function content corresponding to the keyword according to the target corresponding relation and the position information; the target corresponding relation comprises a corresponding relation between function content and position information of a function content corresponding code in the code to be detected; the target correspondence is established based on an abstract syntax tree.
9. An electronic device, comprising: a processor and a memory;
the memory stores computer-executable instructions;
the processor executes computer-executable instructions stored in the memory, causing the processor to perform the code detection method of any one of claims 1 to 7.
10. A computer readable storage medium having stored therein computer executable instructions which, when executed by a processor, implement the code detection method of any of claims 1 to 7.
11. A computer program product comprising a computer program which, when executed by a processor, implements the method of code detection according to any one of claims 1 to 7.
CN202210773081.3A 2022-06-30 2022-06-30 Code detection method, apparatus, storage medium, and program product Pending CN117370144A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210773081.3A CN117370144A (en) 2022-06-30 2022-06-30 Code detection method, apparatus, storage medium, and program product

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210773081.3A CN117370144A (en) 2022-06-30 2022-06-30 Code detection method, apparatus, storage medium, and program product

Publications (1)

Publication Number Publication Date
CN117370144A true CN117370144A (en) 2024-01-09

Family

ID=89391613

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210773081.3A Pending CN117370144A (en) 2022-06-30 2022-06-30 Code detection method, apparatus, storage medium, and program product

Country Status (1)

Country Link
CN (1) CN117370144A (en)

Similar Documents

Publication Publication Date Title
US12313426B2 (en) Method of updating map data, electronic device and storage medium
CN111241823A (en) Dependency configuration management method and device, electronic equipment and storage medium
CN110781658B (en) Resume analysis method, resume analysis device, electronic equipment and storage medium
CN115757400A (en) Data table processing method and device, electronic equipment and computer readable medium
WO2022233311A1 (en) Display method and apparatus, and electronic device
CN111737040B (en) Program code repairing method and device
KR101767481B1 (en) Method and device for analyzing program
US20240069991A1 (en) Abnormal request processing method and apparatus, electronic device and storage medium
CN111124541A (en) Configuration file generation method, device, equipment and medium
CN110717126A (en) Page browsing method and device, electronic equipment and computer readable storage medium
CN114721656A (en) Interface structure extraction method, device, medium and electronic equipment
CN114064431A (en) Stuck detection method and device, readable medium and electronic equipment
CN110348226B (en) Engineering file scanning method and device, electronic equipment and storage medium
WO2024174907A1 (en) Content search method and apparatus, device, computer readable storage medium, and product
CN117370144A (en) Code detection method, apparatus, storage medium, and program product
US9244657B2 (en) System and method for an object instance acquirer
CN111782995B (en) Graphics paging loading method and device
CN116974888A (en) Interface testing method, device, equipment, medium and product
CN109284350B (en) Method and device for updating search content, storage medium and electronic equipment
CN114995720A (en) Page content processing method, device, equipment and readable medium
US12106244B2 (en) Method for determining a project flow, electronic device, and storage medium
CN111399902A (en) Client source file processing method and device, readable medium and electronic equipment
CN110826305A (en) Data processing method and device for online form, terminal and server
CN114741407B (en) Condition query method and device and electronic equipment
CN114116517B (en) Front-end item analysis method and device, medium and electronic equipment

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