CN107015813A - Method, device and electronic equipment that code is repaired - Google Patents

Method, device and electronic equipment that code is repaired Download PDF

Info

Publication number
CN107015813A
CN107015813A CN201710256580.4A CN201710256580A CN107015813A CN 107015813 A CN107015813 A CN 107015813A CN 201710256580 A CN201710256580 A CN 201710256580A CN 107015813 A CN107015813 A CN 107015813A
Authority
CN
China
Prior art keywords
node
code
repaired
syntax tree
abstract syntax
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201710256580.4A
Other languages
Chinese (zh)
Inventor
衣建中
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Netease Hangzhou Network Co Ltd
Original Assignee
Netease Hangzhou Network Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Netease Hangzhou Network Co Ltd filed Critical Netease Hangzhou Network Co Ltd
Priority to CN201710256580.4A priority Critical patent/CN107015813A/en
Publication of CN107015813A publication Critical patent/CN107015813A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/75Structural analysis for program understanding
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/72Code refactoring
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/77Software metrics

Landscapes

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

Abstract

The application is related to method, device and the electronic equipment of code reparation, and method includes:Parsing code file to be repaired, obtains the abstract syntax tree of the code file to be repaired;Recurrence is carried out to the node in the abstract syntax tree to enumerate, and is inquired about and is obtained node corresponding with syntactic structure to be checked;The node inquired about and got is scanned using custom logic, and in scanning to the node for not meeting the custom logic, generation error information, wherein, the custom logic is to carry out customized code execution logic according to real needs;The node of the custom logic is not met described in repairing.The technical scheme of the application can be automatically changed the custom code specification mistake in project, it is to avoid efficiency caused by artificial reparation is low, the problems such as easily malfunction.

Description

Method, device and electronic equipment that code is repaired
Technical field
The application is related to software automated testing technical field, method, device and the electricity repaired in particular to code Sub- equipment.
Background technology
In correlation technique, for the static code inspection of certain programmed language, it is generally used for realizing certain code specification Check.For example, for the code file write using python language, the static generation of language is generally carried out using flake8 Code is checked.
However, after some customized mistakes are checked, often also need to developer and remove file according to error, OK Number and wrong content, carry out manual lookup and modification, then submit and whether wrong check again for again.The step one To take time and effort, two come in the case where code error is more, are easy to unmodified or modification error situation occur, seriously Reduce development efficiency.
For example, in development of games, there is strict regulation for daily record (log) record format of game, for example Each daily record need to indicate the rank (such as critical, info and debug) of daily record, the time, author (optional), with And content etc., but in actual exploitation, program is debugged for convenience, is often used and is simply beaten in python scripts Print (print) method to print some daily records, this has been resulted in inside the code after submitting, it is possible to include nonstandard printing Method, it is therefore desirable to which program is looked for and deleted line by line, submits to each code and adds extra work, and bring The further hidden danger of modification error.
The content of the invention
The method that disclosure code is repaired, the problems such as can avoiding caused by artificial repair that efficiency is low, easily malfunction.
Other characteristics and advantage of the present invention will be apparent from by following detailed description, or partially by the present invention Practice and acquistion.
According to an aspect of the present invention there is provided a kind of method that code is repaired, including:
Parsing code file to be repaired, obtains the abstract syntax tree of the code file to be repaired;
Recurrence is carried out to the node in the abstract syntax tree to enumerate, and is inquired about and is obtained corresponding with syntactic structure to be checked Node;
The node inquired about and got is scanned using custom logic, and in scanning to not meeting State the node of custom logic, generation error information, wherein, the custom logic is made by oneself according to real needs The code execution logic of justice;
The node of the custom logic is not met described in repairing.
According to some embodiments, the syntactic structure to be checked includes one or more of:Exception control to, class, Function.
According to some embodiments, the node of the custom logic is not met described in the reparation to be included:To the node In do not meet the node of the custom logic and deleted and/or changed.
According to some embodiments, obtaining the abstract syntax tree of the code file to be repaired includes:Obtained by Flake8 Take the abstract syntax tree of the code file to be repaired.
According to another aspect of the present invention there is provided a kind of code repair device, it include abstract syntax tree acquiring unit, Node acquiring unit, node scan unit and node repair unit, wherein:
Abstract syntax tree acquiring unit, the code file to be repaired for parsing obtains the code file to be repaired Abstract syntax tree;
Node acquiring unit, enumerates for carrying out recurrence to the node in the abstract syntax tree, inquires about and obtain and treat The corresponding node of syntactic structure of inspection;
Node scan unit, for being scanned using custom logic to the node inquired about and got, And scanning to the node for not meeting the custom logic, generation error information, wherein, the custom logic is root Customized code execution logic is carried out according to real needs;
Node repairs unit, for repairing the node for not meeting the custom logic.
According to some embodiments, the syntactic structure to be checked includes one or more of:Exception control to, class, Function.
According to some embodiments, the node, which repairs unit, to be used for:To not meeting the custom logic in the node Node deleted and/or changed.
According to some embodiments, the abstract syntax tree acquiring unit is used for:Obtain described to be repaired by Flake8 The abstract syntax tree of code file.
According to another aspect of the invention there is provided a kind of electronic equipment, including:Processor;Memory, is stored for described The instruction of operation of the processor control as described in above-mentioned any one of first aspect.
According to another aspect of the invention there is provided a kind of computer-readable recording medium, computer program is stored thereon with, The program realizes step when being executed by processor:
Parsing code file to be repaired, obtains the abstract syntax tree of the code file to be repaired;
Recurrence is carried out to the node in the abstract syntax tree to enumerate, and is inquired about and is obtained corresponding with syntactic structure to be checked Node;
The node inquired about and got is scanned using custom logic, and in scanning to not meeting State the node of custom logic, generation error information, wherein, the custom logic is made by oneself according to real needs The code execution logic of justice;
The node of the custom logic is not met described in repairing.
The technical scheme that embodiments herein is provided can include the following benefits:
The technical scheme that embodiments herein is provided is carried out automatic to the custom code specification mistake in code file Modification, it is to avoid the efficiency of artificial reparation is low, it is easy wrong the problems such as.
It should be appreciated that the general description of the above and detailed description hereinafter are only exemplary, this can not be limited Invention.
Brief description of the drawings
Its example embodiment is described in detail by referring to accompanying drawing, above and other feature of the invention and advantage will become more Plus substantially.
Fig. 1 shows the method that code according to an embodiment of the invention is repaired;
Fig. 2 shows the method that code according to another embodiment of the present invention is repaired;
Fig. 3 shows the code according to another embodiment of the present invention for being used to help install self-defined flake8 expansion plugins Schematic diagram;
Fig. 4 shows the method exemplary flow that code according to another embodiment of the present invention is repaired;
Fig. 5 shows the block diagram for the device that code according to an embodiment of the invention is repaired;
Fig. 6 shows electronic equipment according to an embodiment of the invention.
Embodiment
Example embodiment is described more fully with referring now to accompanying drawing.However, example embodiment can be real in a variety of forms Apply, and be not understood as limited to embodiment set forth herein;On the contrary, thesing embodiments are provided so that the present invention will be comprehensively and complete It is whole, and the design of example embodiment is comprehensively conveyed into those skilled in the art.Identical reference is represented in figure Same or similar part, thus repetition thereof will be omitted.
Implement in addition, described feature, structure or characteristic can be combined in any suitable manner one or more In example.Embodiments of the invention are fully understood so as to provide there is provided many details in the following description.However, It will be appreciated by persons skilled in the art that technical scheme can be put into practice without one or more in specific detail, Or can be using other methods, constituent element, device, step etc..In other cases, it is not shown in detail or describes known side Method, device, realization operate to avoid fuzzy each aspect of the present invention.
Block diagram shown in accompanying drawing is only functional entity, not necessarily must be corresponding with physically separate entity. I.e., it is possible to realize these functional entitys using software form, or realized in one or more hardware modules or integrated circuit These functional entitys, or realize in heterogeneous networks and/or processor device and/or microcontroller device these functional entitys.
Flow chart shown in accompanying drawing is merely illustrative, it is not necessary to including all contents and operation/step, It is not required to perform by described order.For example, some operation/steps can also be decomposed, and some operation/steps can be closed And or part merge, therefore the actual order performed is possible to be changed according to actual conditions.
Fig. 1 shows the method that code according to an embodiment of the invention is repaired, and the present embodiment is applicable to according to setting The situation that rule is repaired automatically to code file, as shown in figure 1, the method for the code reparation described in the present embodiment includes:
In step s 110, code file to be repaired is parsed, the abstract syntax of the code file to be repaired is obtained Tree.
It should be noted that the code file described in the present embodiment refers to the source code file write with programming language, The technical scheme of the present embodiment is applied to the code file of multilingual, as long as can realize in code file and abstract syntax tree Between mutually conversion, specific language that the present embodiment is used to code file is simultaneously not construed as limiting.
Abstract syntax tree (abstract syntax tree are abbreviated as AST), is the abstract syntax structure of source code Tree-shaped expression, each node on tree represents a kind of structure in source code.Specifically, the code to be repaired is obtained The abstract syntax tree of file can be obtained especially by Flake8.
In the step s 120, in the abstract syntax tree node carry out recurrence enumerate, inquire about and obtain with it is to be checked The corresponding node of syntactic structure.
The syntactic structure to be checked include it is a variety of, such as exception control to, class and function.
In step s 130, the node inquired about and got is scanned using custom logic, and Scan the node for not meeting the custom logic, generation error information, wherein, the custom logic is according to tool Body demand carries out customized code execution logic.
In step S140, the node of the custom logic is not met described in reparation.
For example the node that the custom logic is not met in the node is deleted and/or changed.
The scope involved by reparation described in the present embodiment covers a variety of, includes deletion, the modification of node etc. of node.Example Such as, the corresponding child node of the setting function in the node that setting function has such as been used in abstract syntax tree is deleted, will be abstract Useless reference storehouse deletes, the A functions overall situation in abstract syntax tree is replaced with into B functions etc. in syntax tree.
For example, games log form has strict regulation, do not allow typically using print, it is necessary to which developer is submitting Before code file, the print methods added in oneself debugging are deleted, and submit the general frequency of operation of code file very high, because This can be deleted the object containing such as ast.Print in the corresponding abstract syntax tree of code file.
Parsing, search have been carried out to the abstract syntax tree in code file and has been handled, the code specification of setting is not met Mistake, is obtained for automatic reparation, so as to obtain new abstract syntax tree.On this basis, this step is used for according to new Abstract syntax tree generate the code file after new reparation.
The present embodiment by do not met in the abstract syntax tree to the code file being repaired setting specification node according to Establishing method is repaired, and code file is generated according to the new abstract syntax tree generated after reparation.Artificial repair is avoided to draw The efficiency that rises is low, the problems such as easily malfunction.
The technical scheme of the present embodiment is applied to the code file of multilingual, as long as can realize in code file and take out As mutually being changed between syntax tree, the specific language that the present embodiment is used to code file is simultaneously not construed as limiting.
Fig. 2 shows the method that code according to another embodiment of the present invention is repaired, code of the present embodiment to be repaired File be python code files exemplified by, illustrate the technical scheme of the present embodiment.As shown in Fig. 2 the code described in the present embodiment The method of reparation includes:
In step S210, code file to be repaired is parsed, the python generations to be repaired are obtained by Flake8 The abstract syntax tree of code file.
Python is a kind of explanation type computer programming language of object-oriented.Using python abstract syntax Set module (AST modules) and abstract syntax tree is generated according to python code files.Compiled for code file for python language For the code file write, it can directly pass through the corresponding ast modules of python language, you can obtain corresponding according to code file Abstract syntax tree.
In the prior art, it is the most commonly used with flake8 for the static code inspection of python language, its biggest advantage It is expansible, can freely writes plug-in unit to realize the inspection of certain code specification.Therefore, the technical scheme of the present embodiment, can Enter line code in the form of being arranged to flake8 plug-in units to repair automatically, it is static to both be carried out to code file by flake8 Check, repaired automatically using the customized flake8 plug-in units of the present embodiment again.
According to this mode, pip install are run by windows consoles or linux shell first The flake8 that flake8 installs python relies on storehouse.Next setup.py is write, the code specification inspection based on flake8 is added Look into plug-in unit and entrance is installed, then write inspection script using AST (abstract syntax tree), and pass through python setup.py Then install Installing of Command starts code check into flake8 extension, finally to check mistake (the application with Exemplified by print methods) repaired automatically, and generate the code file after repairing.Specifically, for installing flake8, Under windows or linux, it can be installed by python pip instruments, i.e., by performing pip install flake8 Installing of Command.For writing setup.py, in order to which extension checks the function of specification on the basis of flake8, inspection is being write Look into before script, it is necessary to write setup.py, this document is to aid in installing the expansion plugin that the script is flake8.Specifically Writing example can be realized using code as shown in Figure 3.
In code, name (title), version (version), description (description), author (author) is this The customized field of embodiment, for identifying some personal information, does not influence in itself for inspection.Py_module field lists Show the title of the expansion plugin, may be defined as flake8_custom, entry_points fields and it The content of flake8.extentsion fields, represents that the plug-in unit is a flake8 expansion plugin, the information such as follow-up CT00 In CT00/CT01/CT02 represent that mistake of the inspections specification of extension in error is numbered, the information behind "=" number represents this Mistake is produced by the Custom_Checker classes in flake8_custom modules.
When calling flake8 to be checked, the specification script that the present embodiment is write can be also called to customized Specification is checked., can incoming two parameters, abstract syntax tree tree and code file when flake8 calls customized script Filename filename.
In step S220, in the abstract syntax tree node carry out recurrence enumerate, inquire about and obtain with it is to be checked The corresponding node of syntactic structure.
Using the abstract syntax tree of the flake8 current files passed over, first to section all in the abstract syntax tree Point (node) is enumerated.The node of abstract syntax tree represents significant some special grammar structures, example in this document herein Such as the try-except (exception control to) in python, class (class), function (function) etc..Using python's The enumeration function ast.walk carried in ast storehouses carries out the scanning of outermost node layer.It should be noted that in abstract syntax tree Node is recursive nestings, i.e., may include and be defined very in more syntactic structures, such as class inside each syntactic structure Multi-method.
In step S230, the node inquired about and got is scanned using custom logic, and Scan the node for not meeting the custom logic, generation error information.
After completion is scanned to all nodes, next just syntax check, example can be carried out according to self-defined specification Such as, search that print has been used in which enforcement, then only need in node.body sentences, search whether containing ast.Print pairs As.
In step S240, the node that the custom logic is not met in the node is deleted and/or changed.
Check after customized mistake, the reparation of specification is carried out using abstract syntax tree, equally by taking print as an example: After some node searches print nodes, directly ast.Print objects all in node.body sentences are deleted, so that Obtain new abstract syntax tree.
In step S230, in step s 250, code file is generated using the to_source methods in Codegen storehouses.
Parsed, searched for and handled by the abstract syntax tree to original code, corresponding code specification mistake is all obtained Automatic reparation.This following step needs, according to new abstract syntax tree, to generate the code after new reparation: Codegen.to_source(new_ast)
The step have invoked the to_source methods in codegen storehouses, and the incoming value new_ast of this method is previous step institute The new abstract syntax tree obtained, the output of this method is exactly new python source code files, now write back corresponding Code file.
For example, so that code file is python code files as an example, the to_source methods in Codegen storehouses can be used Code file is generated according to the new abstract syntax tree.
Fig. 4 shows the method exemplary flow that code according to another embodiment of the present invention is repaired, as shown in figure 4, originally showing Being used to delete the method for the object for having used ast.Print in example includes:
In step S410, abstract syntax tree is obtained.
In the step s 420, recurrence is carried out to the node in the abstract syntax tree to enumerate.
In step S430, judge whether contain error object in the node, if so, then performing step S440, otherwise Perform step S450.
In step S440, the error object detected is deleted.
In step S450, reparation is finished.
Specifically, it can be represented by code below:
Def_init_ (self, tree, filename=' (none) ', built-ins=None):
Self.tree=tree
Self.filename=filename
For example, when calling script by flake8, it will usually incoming two parameters.As represented by above-mentioned code, definition When class is initialized, incoming two parameters tree and filename.Wherein, parameter tree represents that flake8 passes to script AST structures, parameter filename represents the file name checked.
Node recurrence is enumerated:
All nodes in AST structures are enumerated.For example, utilizing the enumeration function carried in python ast storehouses Ast.walk carries out the scanning of outermost node layer, exists because node is recurrence, may be comprising more inside each syntactic structure Many methods are defined in many syntactic structures, such as class.
for node in ast.walk(tree):
if isinstance(node,ast.TryExcept):
Haslog=False
In previous step, all nodes can be scanned.Then grammer is carried out for the mistake being likely to occur Check.For example, wanting to look up in code which is exercised has used print, then only need to search whether in containing The object of ast.Print sentences.
for subnode in node.body:
if isinstance(subnode,ast.Print):
Check after all self-defined mistakes, the reparation of specification is carried out by ast trees.For example, by where the mistake The output of the information such as filename, line number, then find the wrong corresponding file of institute and line number changed one by one, submit again Code and inspection.Specially:
Node.body=[x for x in content.body if not isinstance (x, ast.Print)]
Ast.Print objects all in node.body are deleted.
Finally by above-mentioned steps, corresponding code specification mistake is obtained for reparation, so as to be generated according to new ast new Reparation after code.Example code is as follows:
codegen.to_source(new_ast)
It has invoked the to_source methods in codegen storehouses herein, incoming value therein is after the completion of repairing in previous step Ast trees, so as to obtain new python source codes, be written into corresponding code file.
In addition, in embodiments of the present invention, the practical programming language of citing is Python, corresponding static code checks storehouse For flake8.It should be appreciated that the present invention is also applied to other programming languages, such as C, C++, Lisp, Java, Perl, Ruby etc., these schemes will not be described here within protection scope of the present invention.
The present embodiment passes through the python to being repaired exemplified by by the ast.Print objects in python code files The node that setting specification is not met in the abstract syntax tree of code file is repaired according to establishing method, is generated according to after reparation New abstract syntax tree generation code file.The problems such as avoiding caused by artificial repair that efficiency is low, easily malfunction.
Fig. 5 shows the block diagram for the device that code according to an embodiment of the invention is repaired, as shown in figure 5, the present embodiment The device that described code is repaired includes abstract syntax tree acquiring unit 510, node acquiring unit 520, node scan unit 530 and node repair unit 540.
The abstract syntax tree acquiring unit 510 is configured to parse code file to be repaired, obtains described to be repaired The abstract syntax tree of multiple code file;
The node acquiring unit 520 is configured to enumerate the node progress recurrence in the abstract syntax tree, looks into Ask and obtain node corresponding with syntactic structure to be checked;
The node scan unit 530 is configured to inquire about and described in getting described using custom logic Node is scanned, and is being scanned to the node for not meeting the custom logic, generation error information, wherein, it is described Custom logic is to carry out customized code execution logic according to real needs;
The node repairs the node that unit 540 is configured to not meet the custom logic described in reparation.
According to some embodiments of the present invention, the syntactic structure to be checked includes one or more of:Abnormal control System to, class, function.
According to some embodiments of the present invention, the node, which repairs unit 540, to be used for:It is described to not met in the node The node of custom logic is deleted and/or changed.
According to some embodiments of the present invention, the abstract syntax tree acquiring unit 510 is used for:Institute is obtained by Flake8 State the abstract syntax tree of code file to be repaired.
On the device in above-described embodiment, wherein unit performs the concrete mode of operation in relevant this method Embodiment in be described in detail, explanation will be not set forth in detail herein.
The device for the code reparation that the present embodiment is provided can perform the code reparation that the inventive method embodiment is provided Method, possesses the corresponding functional module of execution method and beneficial effect.
Fig. 6 shows electronic equipment according to an embodiment of the invention, includes script module and native applications suitable for operation The mixing application of module.
As shown in fig. 6, electronic equipment 600 may include processor 610, memory 620, transmitter 630 and receiver 640.
Memory 620 can store the instruction for the processing of the control operation of processor 610.Memory 620 may include volatibility Or nonvolatile memory, such as static RAM (SRAM), Electrically Erasable Read Only Memory (EEPROM), Erasable Programmable Read Only Memory EPROM (EPROM), programmable read only memory (PROM), read-only storage (ROM) etc., the present invention It is not limited in this respect.
Processor 610 can call the instruction stored in memory 620 to control associative operation.According to an embodiment, memory 620 store and control the instruction that operates below for processor 610:
Parsing code file to be repaired, obtains the abstract syntax tree of the code file to be repaired;
Recurrence is carried out to the node in the abstract syntax tree to enumerate, and is inquired about and is obtained corresponding with syntactic structure to be checked Node;
The node inquired about and got is scanned using custom logic, and in scanning to not meeting State the node of custom logic, generation error information, wherein, the custom logic is made by oneself according to real needs The code execution logic of justice;
The node of the custom logic is not met described in repairing.
It can be readily appreciated that memory 620, which can also be stored, controls other operations according to embodiments of the present invention for processor 610 Instruction, repeat no more here.
Processor 610 also can control transmitter 630 and receiver 640 carries out signal transmitting and receiving etc..
According to some embodiments, the present invention also provides a kind of non-transitorycomputer readable storage medium, such as including referring to The memory of order, above-mentioned instruction can complete the above method by the computing device of device.For example, non-transitory is computer-readable Storage medium can be ROM, random access memory (RAM), CD-ROM, tape, floppy disk and optical data storage devices etc..When depositing Instruction in storage media by the computing device of terminal when so that terminal is able to carry out following methods:Parsing code to be repaired File, obtains the abstract syntax tree of the code file to be repaired;Recurrence piece is carried out to the node in the abstract syntax tree Lift, inquire about and obtain node corresponding with syntactic structure to be checked;Inquire about and get to described using custom logic The node is scanned, and is being scanned to the node for not meeting the custom logic, generation error information, wherein, The custom logic is to carry out customized code execution logic according to real needs;Do not met described in repairing described self-defined The node of logic.
It will be understood by those skilled in the art that accompanying drawing is the schematic diagram of example embodiment, module or flow in accompanying drawing Not necessarily implement the present invention necessary, therefore cannot be used for limiting the scope of the invention.
It will be appreciated by those skilled in the art that above-mentioned each module can be distributed in device according to the description of embodiment, also may be used To carry out respective change uniquely different from one or more devices of the present embodiment.The module of above-described embodiment can be merged into One module, can also be further split into multiple submodule.
The exemplary embodiment of the present invention is particularly shown and described above.It should be understood that public the invention is not restricted to institute The embodiment opened, on the contrary, it is intended to cover comprising various modifications in the spirit and scope of the appended claims and wait Effect arrangement.

Claims (10)

1. a kind of method that code is repaired, it is characterised in that including:
Parsing code file to be repaired, obtains the abstract syntax tree of the code file to be repaired;
Recurrence is carried out to the node in the abstract syntax tree to enumerate, and is inquired about and is obtained section corresponding with syntactic structure to be checked Point;
Inquired about and the node that gets is scanned to described using custom logic, and scanning to do not meet it is described oneself The node of definition logic, generation error information, wherein, the custom logic is customized according to real needs progress Code execution logic;
The node of the custom logic is not met described in repairing.
2. code restorative procedure as claimed in claim 1, it is characterised in that the syntactic structure to be checked is included with next Plant or a variety of:Exception control to, class, function.
3. the method as described in claim 1, it is characterised in that the node of the custom logic is not met described in the reparation Including:The node that the custom logic is not met in the node is deleted and/or changed.
4. the method as described in claim 1, it is characterised in that obtain the abstract syntax tree bag of the code file to be repaired Include:The abstract syntax tree of the code file to be repaired is obtained by Flake8.
5. the device that a kind of code is repaired, it is characterised in that including:
Abstract syntax tree acquiring unit, the code file to be repaired for parsing obtains taking out for the code file to be repaired As syntax tree;
Node acquiring unit, in the abstract syntax tree node carry out recurrence enumerate, inquire about and obtain with it is to be checked The corresponding node of syntactic structure;
Node scan unit, for being scanned using custom logic to the node inquired about and got, and Scan the node for not meeting the custom logic, generation error information, wherein, the custom logic is according to tool Body demand carries out customized code execution logic;
Node repairs unit, for repairing the node for not meeting the custom logic.
6. code prosthetic device as claimed in claim 5, it is characterised in that the syntactic structure to be checked is included with next Plant or a variety of:Exception control to, class, function.
7. device as claimed in claim 5, it is characterised in that the node, which repairs unit, to be used for:To not being inconsistent in the node The node for closing the custom logic is deleted and/or changed.
8. device as claimed in claim 5, it is characterised in that the abstract syntax tree acquiring unit is used for:Pass through Flake8 Obtain the abstract syntax tree of the code file to be repaired.
9. a kind of electronic equipment, it is characterised in that including:Processor;Memory, is stored for the processor control such as right It is required that the instruction of the operation described in any one of 1-4.
10. a kind of computer-readable recording medium, is stored thereon with computer program, step is realized when the program is executed by processor Suddenly:
Parsing code file to be repaired, obtains the abstract syntax tree of the code file to be repaired;
Recurrence is carried out to the node in the abstract syntax tree to enumerate, and is inquired about and is obtained section corresponding with syntactic structure to be checked Point;
Inquired about and the node that gets is scanned to described using custom logic, and scanning to do not meet it is described oneself The node of definition logic, generation error information, wherein, the custom logic is customized according to real needs progress Code execution logic;
The node of the custom logic is not met described in repairing.
CN201710256580.4A 2017-04-19 2017-04-19 Method, device and electronic equipment that code is repaired Pending CN107015813A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201710256580.4A CN107015813A (en) 2017-04-19 2017-04-19 Method, device and electronic equipment that code is repaired

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201710256580.4A CN107015813A (en) 2017-04-19 2017-04-19 Method, device and electronic equipment that code is repaired

Publications (1)

Publication Number Publication Date
CN107015813A true CN107015813A (en) 2017-08-04

Family

ID=59448154

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201710256580.4A Pending CN107015813A (en) 2017-04-19 2017-04-19 Method, device and electronic equipment that code is repaired

Country Status (1)

Country Link
CN (1) CN107015813A (en)

Cited By (13)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109144517A (en) * 2018-08-01 2019-01-04 北京京东金融科技控股有限公司 A kind of method and apparatus checking coding
CN109491884A (en) * 2018-09-26 2019-03-19 平安普惠企业管理有限公司 Code method for testing performance, device, computer equipment and medium
CN110244954A (en) * 2019-05-22 2019-09-17 平安国际智慧城市科技股份有限公司 A kind of Compilation Method and equipment of application program
CN110286912A (en) * 2019-07-03 2019-09-27 广东三维家信息科技有限公司 Code detection method, device and electronic equipment
CN110349477A (en) * 2019-07-16 2019-10-18 湖南酷得网络科技有限公司 A kind of misprogrammed restorative procedure, system and server based on history learning behavior
CN110609693A (en) * 2019-08-15 2019-12-24 平安国际智慧城市科技股份有限公司 Code updating method and device based on data standardization and terminal equipment
CN110908677A (en) * 2019-11-29 2020-03-24 安徽智恒信科技股份有限公司 Method for optimizing size of Flutter application installation package and storage medium
CN111078568A (en) * 2019-12-20 2020-04-28 广州华多网络科技有限公司 Code specification method and device, computer equipment and storage medium
CN111858113A (en) * 2019-04-30 2020-10-30 北京达佳互联信息技术有限公司 Application program repairing method, device, service system and storage medium
CN112286557A (en) * 2020-11-05 2021-01-29 苏州帝博信息技术有限公司 Method and device for updating code content in non-covering mode
CN112947985A (en) * 2021-01-29 2021-06-11 北京航空航天大学 Method and system for intelligently detecting and repairing codes
CN113485715A (en) * 2021-07-30 2021-10-08 浙江大华技术股份有限公司 Code prompting method and system based on data center platform and data computing platform
CN114579203A (en) * 2022-03-07 2022-06-03 网易(杭州)网络有限公司 Script file checking method and device, electronic equipment and storage medium

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6149318A (en) * 1997-04-15 2000-11-21 Samuel C. Kendall Link-time and run-time error detection, and program instrumentation
CN102799520A (en) * 2012-06-27 2012-11-28 清华大学 Static checking method and device for source code pairing
US20150135166A1 (en) * 2013-11-12 2015-05-14 Microsoft Corporation Source code generation, completion, checking, correction
CN106354636A (en) * 2016-08-25 2017-01-25 上海卓易科技股份有限公司 Method and device for code testing
CN106371997A (en) * 2016-09-07 2017-02-01 网易(杭州)网络有限公司 Code checking method and device

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6149318A (en) * 1997-04-15 2000-11-21 Samuel C. Kendall Link-time and run-time error detection, and program instrumentation
CN102799520A (en) * 2012-06-27 2012-11-28 清华大学 Static checking method and device for source code pairing
US20150135166A1 (en) * 2013-11-12 2015-05-14 Microsoft Corporation Source code generation, completion, checking, correction
CN106354636A (en) * 2016-08-25 2017-01-25 上海卓易科技股份有限公司 Method and device for code testing
CN106371997A (en) * 2016-09-07 2017-02-01 网易(杭州)网络有限公司 Code checking method and device

Cited By (19)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109144517A (en) * 2018-08-01 2019-01-04 北京京东金融科技控股有限公司 A kind of method and apparatus checking coding
CN109491884A (en) * 2018-09-26 2019-03-19 平安普惠企业管理有限公司 Code method for testing performance, device, computer equipment and medium
CN111858113A (en) * 2019-04-30 2020-10-30 北京达佳互联信息技术有限公司 Application program repairing method, device, service system and storage medium
CN111858113B (en) * 2019-04-30 2024-03-12 北京达佳互联信息技术有限公司 Application program repairing method and device, service system and storage medium
CN110244954A (en) * 2019-05-22 2019-09-17 平安国际智慧城市科技股份有限公司 A kind of Compilation Method and equipment of application program
CN110244954B (en) * 2019-05-22 2022-12-09 深圳赛安特技术服务有限公司 Compiling method and equipment for application program
CN110286912A (en) * 2019-07-03 2019-09-27 广东三维家信息科技有限公司 Code detection method, device and electronic equipment
CN110286912B (en) * 2019-07-03 2023-08-18 广东三维家信息科技有限公司 Code detection method and device and electronic equipment
CN110349477A (en) * 2019-07-16 2019-10-18 湖南酷得网络科技有限公司 A kind of misprogrammed restorative procedure, system and server based on history learning behavior
CN110609693A (en) * 2019-08-15 2019-12-24 平安国际智慧城市科技股份有限公司 Code updating method and device based on data standardization and terminal equipment
CN110908677A (en) * 2019-11-29 2020-03-24 安徽智恒信科技股份有限公司 Method for optimizing size of Flutter application installation package and storage medium
CN111078568A (en) * 2019-12-20 2020-04-28 广州华多网络科技有限公司 Code specification method and device, computer equipment and storage medium
CN111078568B (en) * 2019-12-20 2023-10-31 广州华多网络科技有限公司 Code specification method, apparatus, computer device and storage medium
CN112286557A (en) * 2020-11-05 2021-01-29 苏州帝博信息技术有限公司 Method and device for updating code content in non-covering mode
CN112286557B (en) * 2020-11-05 2024-03-22 苏州帝博信息技术有限公司 Method and device for updating code content in non-coverage mode
CN112947985A (en) * 2021-01-29 2021-06-11 北京航空航天大学 Method and system for intelligently detecting and repairing codes
CN113485715A (en) * 2021-07-30 2021-10-08 浙江大华技术股份有限公司 Code prompting method and system based on data center platform and data computing platform
CN114579203A (en) * 2022-03-07 2022-06-03 网易(杭州)网络有限公司 Script file checking method and device, electronic equipment and storage medium
CN114579203B (en) * 2022-03-07 2024-03-15 网易(杭州)网络有限公司 Script file checking method and device, electronic equipment and storage medium

Similar Documents

Publication Publication Date Title
CN107015813A (en) Method, device and electronic equipment that code is repaired
CN108614707B (en) Static code checking method, device, storage medium and computer equipment
US5691925A (en) Deriving tractable sub-system for model of larger system
US8850415B2 (en) Generating a transition system for use with model checking
CN110399300B (en) Python software fuzzy test method based on dynamic type perception
US11307975B2 (en) Machine code analysis for identifying software defects
CN107678748A (en) A kind of source code file Compilation Method and device
CN101866315A (en) Test method and system of software development tool
JP4951416B2 (en) Program verification method and program verification apparatus
Di Ruscio et al. Managing the coupled evolution of metamodels and textual concrete syntax specifications
Denney et al. Explaining verification conditions
JP2010140408A (en) Source code converting device
Liuying et al. Test selection from UML statecharts
US10846059B2 (en) Automated generation of software bindings
CN114153447B (en) Automatic AI training code generation method
Dalibor et al. Mind the gap: lessons learned from translating grammars between MontiCore and Xtext
Akhigbe et al. Consistency Analysis for User Requirements Notation Models.
CN115033266A (en) IDE development system based on Loongson instruction set
CN115310095A (en) Block chain intelligent contract mixed formal verification method and system
CN114116471A (en) Automatic code scanning method, system, electronic equipment and storage medium
BELL et al. Model-based mutation testing using pushdown automata
CN113807077A (en) Natural language test script parsing processing method and device and electronic equipment
Mokni et al. An evolution management model for multi-level component-based software architectures
US10445078B2 (en) Layered software architecture model for translation of assembler language to target language
Bourdonov et al. Interaction semantics with refusals, divergence, and destruction

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
RJ01 Rejection of invention patent application after publication

Application publication date: 20170804

RJ01 Rejection of invention patent application after publication