CN113742235A - Method and device for checking codes - Google Patents

Method and device for checking codes Download PDF

Info

Publication number
CN113742235A
CN113742235A CN202111053416.6A CN202111053416A CN113742235A CN 113742235 A CN113742235 A CN 113742235A CN 202111053416 A CN202111053416 A CN 202111053416A CN 113742235 A CN113742235 A CN 113742235A
Authority
CN
China
Prior art keywords
annotation
check
code
verification
checking
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
CN202111053416.6A
Other languages
Chinese (zh)
Inventor
谢继永
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Jingdong Century Trading Co Ltd
Beijing Wodong Tianjun Information Technology Co Ltd
Original Assignee
Beijing Jingdong Century Trading Co Ltd
Beijing Wodong Tianjun Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Jingdong Century Trading Co Ltd, Beijing Wodong Tianjun Information Technology Co Ltd filed Critical Beijing Jingdong Century Trading Co Ltd
Priority to CN202111053416.6A priority Critical patent/CN113742235A/en
Publication of CN113742235A publication Critical patent/CN113742235A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3668Software testing
    • G06F11/3672Test management
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/43Checking; Contextual analysis

Abstract

The invention discloses a method and a device for checking codes, and relates to the technical field of computers. One embodiment of the method comprises: the annotation of the service code can be acquired, the verification strategy of the code is analyzed from the annotation, and the corresponding verification code is called through the verification strategy to verify the service code; the problem of coupling of the check code and the service code is solved, so that the problems of poor flexibility and poor reusability of the check code are solved; the maintainability of the check code is improved; by reducing the labor cost and time cost of development, the development efficiency is improved.

Description

Method and device for checking codes
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a method and an apparatus for checking a code.
Background
With the popularization of internet applications, the functions of internet applications are more and more abundant, so the development complexity of internet applications is higher and higher, and generally, different types of checks, such as parameter validity check, logic validity check on business logic data, and the like, need to be performed on codes used for developing internet applications.
Currently, the method for checking codes is generally as follows: adding a check code for checking aiming at each service code segment needing to be checked so as to realize the checking of each code segment; the method causes the problems of poor flexibility, poor reusability, poor maintainability and the like of the check code because the check code used for checking is coupled with the service code; the labor cost and the time cost of development are improved, and the development efficiency is reduced.
Disclosure of Invention
In view of this, embodiments of the present invention provide a method and an apparatus for checking a code, which can analyze a checking policy for the code from an annotation by obtaining the annotation of the service code, and invoke a corresponding checking code through the checking policy to perform checking on the service code; the problem of coupling of the check code and the service code is solved, so that the problems of poor flexibility and poor reusability of the check code are solved; the maintainability of the check code is improved; by reducing the labor cost and time cost of development, the development efficiency is improved.
To achieve the above object, according to an aspect of an embodiment of the present invention, there is provided a method of checking a code, including: obtaining an annotation corresponding to a business code, analyzing an annotation type from the annotation, and obtaining a verification strategy associated with the annotation type from the annotation; and searching a first check code matched with the check strategy in multiple preset check codes, and calling the first check code to check the service code.
Optionally, the method of checking a code, characterized in that,
the annotation types include: method annotation and/or parameter annotation.
Optionally, the method for checking a code, where the parsing an annotation type from the annotation and obtaining a checking policy associated with the annotation type from the annotation includes: the annotation type is the method annotation, and the calling instruction is intercepted in response to the calling instruction of any business method in the business code; determining a method annotation of a business method corresponding to the calling instruction; and acquiring a verification strategy corresponding to the method annotation from the method annotation.
Optionally, the method for checking a code, wherein the parsing an annotation type from the annotation comprises: and the annotation type is the parameter annotation, the parameter entry field corresponding to the parameter annotation is determined, and the parameter value corresponding to the parameter entry field is obtained.
Optionally, the method for checking a code further includes: in response to the verification policy having a plurality of the verification rules, the first verification code includes a priority order in which to execute the verification rules; performing a check of the service code using the first check code, including: and based on the priority sequence, sequentially calling a second check code corresponding to the check rule to check the service code.
Optionally, the method of checking a code, characterized in that,
the first check code has a corresponding check context; further comprising: storing the data to be checked included in the service code to the checking context; and sharing the data to be checked for a plurality of second checking codes by using the checking context.
Optionally, the method of checking a code, characterized in that,
the first check code contains a check annotation; the check annotation comprises check rule identifications corresponding to a plurality of check rules; further comprising: matching each check rule identifier included in the check strategy with a plurality of check rule identifiers included in the check annotation; and according to the matching result, executing the step of sequentially calling a second check code corresponding to the check rule to check the service code.
To achieve the above object, according to a second aspect of embodiments of the present invention, there is provided an apparatus for checking a code, including: analyzing an annotation module and a check code module; wherein the content of the first and second substances,
the analysis annotation module is used for acquiring an annotation corresponding to the service code, analyzing an annotation type from the annotation, and acquiring a verification strategy associated with the annotation type from the annotation;
and the check code module is used for searching a first check code matched with the check strategy in multiple preset check codes and calling the first check code to check the service code.
Optionally, the means for verifying the code, wherein,
the annotation types include: method annotation and/or parameter annotation.
Optionally, the apparatus for checking a code, where the parsing an annotation type from the annotation and obtaining a checking policy associated with the annotation type from the annotation includes: the annotation type is the method annotation, and the calling instruction is intercepted in response to the calling instruction of any business method in the business code; determining a method annotation of a business method corresponding to the calling instruction; and acquiring a verification strategy corresponding to the method annotation from the method annotation.
Optionally, the apparatus for checking a code, wherein the parsing an annotation type from the annotation further comprises: and the annotation type is the parameter annotation, the parameter entry field corresponding to the parameter annotation is determined, and the parameter value corresponding to the parameter entry field is obtained.
Optionally, the apparatus for checking a code further comprises: in response to the verification policy having a plurality of the verification rules, the first verification code includes a priority order in which to execute the verification rules; performing a check of the service code using the first check code, including: and based on the priority sequence, sequentially calling a second check code corresponding to the check rule to check the service code.
Optionally, the means for verifying the code, wherein,
the first check code has a corresponding check context; further comprising: storing the data to be checked included in the service code to the checking context; and sharing the data to be checked for a plurality of second checking codes by using the checking context.
Optionally, the means for verifying the code, wherein,
the first check code contains a check annotation; the check annotation comprises check rule identifications corresponding to a plurality of check rules; further comprising: matching each check rule identifier included in the check strategy with a plurality of check rule identifiers included in the check annotation; and according to the matching result, executing the step of sequentially calling a second check code corresponding to the check rule to check the service code.
To achieve the above object, according to a third aspect of the embodiments of the present invention, there is provided an electronic device for checking a code, including: one or more processors; storage means for storing one or more programs which, when executed by the one or more processors, cause the one or more processors to carry out a method as claimed in any one of the above methods of checking a code.
To achieve the above object, according to a fourth aspect of the embodiments of the present invention, there is provided a computer readable medium having a computer program stored thereon, wherein the program, when executed by a processor, implements the method as in any one of the methods of checking a code described above.
One embodiment of the above invention has the following advantages or benefits: the annotation of the service code can be acquired, the verification strategy of the code is analyzed from the annotation, and the corresponding verification code is called through the verification strategy to verify the service code; the problem of coupling of the check code and the service code is solved, so that the problems of poor flexibility and poor reusability of the check code are solved; the maintainability of the check code is improved; by reducing the labor cost and time cost of development, the development efficiency is improved.
Further effects of the above-mentioned non-conventional alternatives will be described below in connection with the embodiments.
Drawings
The drawings are included to provide a better understanding of the invention and are not to be construed as unduly limiting the invention. Wherein:
FIG. 1 is a flow chart illustrating a method for checking a code according to an embodiment of the present invention;
FIG. 2 is a flow chart of a check code according to an embodiment of the present invention;
FIG. 3 is a schematic structural diagram of an apparatus for checking a code according to an embodiment of the present invention;
FIG. 4 is an exemplary system architecture diagram in which embodiments of the present invention may be employed;
fig. 5 is a schematic block diagram of a computer system suitable for use in implementing a terminal device or server of an embodiment of the invention.
Detailed Description
Exemplary embodiments of the present invention are described below with reference to the accompanying drawings, in which various details of embodiments of the invention are included to assist understanding, and which are to be considered as merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the invention. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
In view of this, as shown in fig. 1, an embodiment of the present invention provides a method for checking a code, where the method may include the following steps:
step S101: and acquiring an annotation corresponding to the service code, analyzing an annotation type from the annotation, and acquiring a verification strategy associated with the annotation type from the annotation.
Specifically, the service code is a source code for implementing an application; for example: the application is an electronic mall, and each page, each service logic and function of the electronic mall can be realized through the service code.
The annotation corresponding to the business code is added for the verification of the business code, the annotation is usually added into the business code segment, the annotation usually takes "@" as an identifier, and the obtained annotation corresponding to the business code can be used as a keyword for obtaining the annotation by searching the character "@" and the associated character string; for example, using "@ validation" to indicate the service code needing code check; the annotation may have one or more items depending on the type of verification and verification policy; the annotation comprises a predefined annotation type and a verification strategy used for verifying the business code, wherein the verification strategy is set based on the annotation type; that is, the annotation type may be parsed from the annotation, and the verification policy associated with the annotation type may be obtained from the annotation.
Further, annotation types include: method annotation and/or parameter annotation. Method annotation types are added to methods (e.g., functions, etc.) contained in the business code, such as: annotating the type by using the @ UserServiceValid identification method; judging the annotation type as method annotation by analyzing the key word of '@ UserServiceValid' from the code; parameter annotation is identified by @ UserFieldValid, and the annotation type is judged to be parameter annotation by parsing key words of @ UserFieldValid from the code.
Further, a verification policy associated with the annotation type is obtained from the annotation. It will be appreciated that the verification strategy employed is different for different annotation types, for example: for the parameter annotation, the verification policy associated with the parameter annotation corresponds to, for example, the validity of the verification parameter, such as non-empty verification of the parameter value, format verification of the parameter value, maximum and minimum values of the parameter value, and the like; for the method annotation, the verification policy associated with the method annotation is related to the actual service according to the application scenario, for example, the service method is an order call interface, and the corresponding verification policy is to verify whether an order number is legal or not, whether the stock of an order commodity is not 0 or not, and the like.
Verification policies are part of the annotation, for example: the service code fragment contains the parameter annotation @ UserFieldValid and one or more verification policies corresponding to the parameters, such as: @ rule _ empty (a checking policy for identifying whether a parameter is empty), @ rule _ length (a checking policy for identifying whether a parameter length is legal), and the like; the annotation also can be set to contain a type field aiming at the checking strategy and a field value corresponding to the type field and indicating the checking strategy so as to identify the specific type of the used checking strategy; it will be appreciated that the business code segment may contain either or both of a parameter annotation and a method annotation, as well as a verification policy corresponding to the parameter annotation and the method annotation. The method annotation, the parameter annotation and the verification strategy can be self-defined annotations, and the method annotation does not limit the annotation content contained in the business code, and the specific forms and contents of the method annotation, the parameter annotation and the verification strategy contained in the annotation.
Further, there are two methods for obtaining (parsing) the verification policy associated with the annotation type from the annotation:
the first method comprises the following steps: the annotation type is the method annotation, and the calling instruction is intercepted in response to the calling instruction of any business method in the business code; determining a method annotation of a business method corresponding to the calling instruction; and analyzing (acquiring) the verification strategy corresponding to the method annotation from the method annotation. Specifically, a call instruction, a request or call of any service method in the service code, that is, the call instruction, may be intercepted (that is, the call instruction) before the call or request processing, and information such as a parameter included in the service method and a check policy used for the service method (that is, a method annotation for determining the service method corresponding to the call instruction) is analyzed, so that the check code and the code logic of the service method are decoupled, and thus, flexibility and reusability of the check code are improved by setting the annotation.
The second method comprises the following steps: and the annotation type is the parameter annotation, the parameter entry field corresponding to the parameter annotation is determined, and the parameter value corresponding to the parameter entry field is obtained. Specifically, under the condition that the annotation type is parameter annotation, the entry field corresponding to the parameter annotation, that is, the entry field to be verified, can be obtained through parsing, and further, the parameter value corresponding to the entry field can be obtained through reflection (reflection technology is to obtain the attribute, method, annotation, parameter and the like in the class file corresponding to the bytecode object through the bytecode object); the parameter annotation field of the parameter annotation identifier may belong to each parameter of the service method and each parameter corresponding to the service request, and the parameter annotation field is obtained by parsing the parameter annotation, and the parameter value corresponding to the parameter annotation field is obtained, so as to further check the validity of the parameter value, for example: the parameter entry field is cell number, the corresponding parameter value is 12345678901, and after the parameter value is analyzed, whether the parameter value is a legal mobile phone number can be further checked.
Step S102: and searching a first check code matched with the check strategy in multiple preset check codes, and calling the first check code to check the service code.
Specifically, multiple check codes are preset according to applications and service scenes, the preset codes are checked on the set service codes, and the check codes are used for judging whether the checked method or parameters have preset legality through the logic of the check codes; wherein, the check code can be classified into one or more class files; for example: if the check strategy is "user information check", searching a "user information check code" (namely a first check code) corresponding to the "user information check" from the check code, and calling the first check code to check the user information corresponding to the service code. It can be understood that a plurality of applications or scenarios may have the same verification policy, a plurality of methods or parameters in one application may also have the same verification policy, and the first verification code corresponding to the verification policy is used, so that development of verification logic codes for each service code is reduced, and by decoupling the verification code from the service code, efficiency of code development and verification is improved.
Further, the verification policy contains a plurality of verification rules, such as: the verification policy is "user information verification", and includes: user name validity check, user identity card information validity check, user mobile phone number validity check and the like; thus, the check code (i.e. the second check code) corresponding to the check rule is looked up based on the respective check rule (which may be parsed from the annotation); the method for searching the second check code can be identified by the check rule; the check rule identification belongs to the first check code; furthermore, the first check code includes an annotation for identifying one or more check strategies and a plurality of check rules corresponding to the check code; that is, the first check code contains a check annotation; the check annotation comprises check rule identifications corresponding to a plurality of check rules; further comprising: matching each check rule identifier included in the check strategy with a plurality of check rule identifiers included in the check annotation; and according to the matching result, executing the step of sequentially calling a second check code corresponding to the check rule to check the service code. For example: the verification rule is that whether the parameter is null or not, and the verification annotation of the first verification code contains a second verification code of '@ rule _ null' for indicating whether the parameter is null or not; that is, the check annotation includes check rule identifiers corresponding to a plurality of check rules; each check rule identification is matched with a plurality of check rule identifications contained in the check annotation; according to the matching result, executing the step of sequentially calling a second check code corresponding to the check rule to check the service code; preferably, when the service is started, the annotations (including the verification rule identifiers) included in the first verification code are loaded into the memory, so as to match each verification rule identifier included in the verification policy with the plurality of verification rule identifiers included in the verification annotations, run the verification code corresponding to the verification rule identifier, and execute the step of sequentially calling the second verification code corresponding to the verification rule to verify the service code.
Further, in response to the checking policy having a plurality of the checking rules, the first checking code includes a priority order for executing the checking rules; performing a check of the service code using the first check code, including: and based on the priority sequence, sequentially calling a second check code corresponding to the check rule to check the service code. Specifically, in the case where there are a plurality of check rules, a priority order may be set for the check rules so that the step of the second check code to execute the check code according to the priority order, for example: the checking strategy is order checking; the priority order of the set check rules is as follows: firstly, checking the legality of the order number, then checking the validity of the order number, finally verifying the operation authority corresponding to the order number and the like; it is to be understood that the information of the priority order may be provided in the first check code.
Further, the first check code has a corresponding check context; further comprising: storing the data to be checked included in the service code to the checking context; and sharing the data to be checked for a plurality of second checking codes by using the checking context. Specifically, the check context is used to provide a source data object and a service data object for the check code, so as to achieve data exchange between different check codes, for example: if the two verification rules are both related to the data of the user information, the stored user information data (namely, the data to be verified) can be acquired from the verification context; for example, if the verification rule 1 is a verification user name, the second verification code corresponding to the verification user name may obtain user information from user information data stored in the verification context, and analyze the user name to perform verification; the verification rule 2 is to verify the mobile phone number of the user, and the second verification code corresponding to the mobile phone number of the verification user can directly acquire the mobile phone number information of the user from the user information stored in the verification context, so that data sharing is realized, namely, the data to be verified is shared by a plurality of second verification codes.
Preferably, techniques such as ConcurrentHashMap, ThreadLocal, etc. may be utilized to improve data security during data transfer using check context. Wherein the ConcurrentHashMap belongs to a java.util.current packet, and supports multithreading high-efficiency concurrency; thread local is a storage class inside a thread, and can store data in a specified thread, so that only the specified thread can obtain the stored data after the data storage is realized.
Therefore, the method and the device realize decoupling of the check rule, the check code and the service logic (service code) through code isolation, thereby improving the expansibility and flexibility of the check service code; the method and the device realize the inspection code based on the set annotation, and reduce development difficulty and complexity. Meanwhile, the flexibility of using the check rules is improved by utilizing the arrangement capacity of the check strategy (check rules) contained in the check codes; the annotation type comprises parameter annotation, the check granularity can be flexibly configured, and the flexibility and maintainability of the check code are further improved.
As shown in fig. 2, an embodiment of the present invention provides a method for checking a code, where the method may include the following steps:
step S201: multiple annotation types are obtained: method annotation, parameter annotation.
Specifically, the descriptions of the method annotation, the parameter annotation, and the check annotation are the same as those of step S101 to step S102, and are not repeated herein.
Step S202: calling a first check code for checking: the first check code comprises a plurality of second check codes corresponding to the check rules.
Specifically, the annotation is intercepted by AOP and/or parsed by reflection, where the annotation includes the annotation type described in step S201 and each verification policy, and a first verification code corresponding to the verification policy is invoked to perform verification according to the parsed annotation type and the corresponding verification policy.
Specific descriptions about the first check code, the second check code and the check rule; and the specific description of intercepting the annotation by AOP and parsing the annotation by reflection is consistent with that of step S102, and is not described herein again.
Step S203: shared data to be checked is provided by using the check context.
Specifically, when a first check code is called for checking, shared data to be checked is provided by using a check context; that is, the first check code has a corresponding check context; further comprising: storing the data to be checked included in the service code to the checking context; and sharing the data to be checked for a plurality of second checking codes by using the checking context.
Step S204: and generating a checking result.
Specifically, the first check code may be packaged as a checker engine, configured to package a code of a check policy (and multiple check rules included in the class file corresponding to the first check code); optionally, the priority order of the check rules may also be encapsulated. Preferably, the checker engine is used for packaging the check result return data so as to utilize the unified interface to feed back return information such as check failure, check success and check exception.
It is understood that the order of steps in this flow is illustrative and may be different from the order of execution.
As shown in fig. 3, an embodiment of the present invention provides an apparatus 300 for checking a code, including: a parsing annotation module 301 and a check code module 302; wherein the content of the first and second substances,
the parsing annotation module 301 is configured to obtain an annotation corresponding to a service code, parse an annotation type from the annotation, and obtain a verification policy associated with the annotation type from the annotation;
the check code module 302 is configured to search a first check code matching the check policy among a plurality of preset check codes, and call the first check code to check the service code.
Optionally, the parsing annotation module 301, where the annotation types include: method annotation and/or parameter annotation.
Optionally, the parsing annotation module 301 is further configured to, when the annotation type is the method annotation, respond to a call instruction of any business method in the business code, and intercept the call instruction; determining a method annotation of a business method corresponding to the calling instruction; and acquiring a verification strategy corresponding to the method annotation from the method annotation.
Optionally, the parsing annotation module 301 is further configured to, when the annotation type is the parameter annotation, determine a parameter entry field corresponding to the parameter annotation, and obtain a parameter value corresponding to the parameter entry field.
Optionally, the check code module 302 is further configured to respond to the check policy that a plurality of the check rules exist, where the first check code includes a priority order for executing the check rules; performing a check of the service code using the first check code, including: and based on the priority sequence, sequentially calling a second check code corresponding to the check rule to check the service code.
Optionally, the check code module 302 is further configured to enable the first check code to have a corresponding check context; further comprising: storing the data to be checked included in the service code to the checking context; and sharing the data to be checked for a plurality of second checking codes by using the checking context.
Optionally, the verification code module 302 is further configured to match each verification rule identifier included in the verification policy with a plurality of verification rule identifiers included in the verification annotation; and according to the matching result, executing the step of sequentially calling a second check code corresponding to the check rule to check the service code.
An embodiment of the present invention further provides an electronic device for checking a code, including: one or more processors; the storage device is used for storing one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors are enabled to realize the method provided by any one of the above embodiments.
Embodiments of the present invention further provide a computer-readable medium, on which a computer program is stored, where the computer program, when executed by a processor, implements the method provided in any of the above embodiments.
Fig. 4 shows an exemplary system architecture 400 to which the method of checking a code or the apparatus for checking a code of the embodiments of the present invention may be applied.
As shown in fig. 4, the system architecture 400 may include terminal devices 401, 402, 403, a network 404, and a server 405. The network 404 serves as a medium for providing communication links between the terminal devices 401, 402, 403 and the server 405. Network 404 may include various types of connections, such as wire, wireless communication links, or fiber optic cables, to name a few.
A user may use terminal devices 401, 402, 403 to interact with a server 405 over a network 404 to receive or send messages or the like. The terminal devices 401, 402, 403 may have various client applications installed thereon, such as an e-mall client application, a web browser application, a search-type application, an instant messaging tool, a mailbox client, and the like.
The terminal devices 401, 402, 403 may be various electronic devices having display screens and supporting various client applications, including but not limited to smart phones, tablet computers, laptop portable computers, desktop computers, and the like.
The server 405 may be a server providing various services, such as a background management server providing support for client applications used by users with the terminal devices 401, 402, 403. The background management server can process the request of receiving the check code and feed back the check result to the terminal equipment.
It should be noted that the method for verifying the code provided by the embodiment of the present invention is generally executed by the server 405, and the apparatus for verifying the code is generally disposed in the server 405.
It should be understood that the number of terminal devices, networks, and servers in fig. 4 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
Referring now to FIG. 5, shown is a block diagram of a computer system 500 suitable for use with a terminal device implementing an embodiment of the present invention. The terminal device shown in fig. 5 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present invention.
As shown in fig. 5, the computer system 500 includes a Central Processing Unit (CPU)501 that can 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 section 508 into a Random Access Memory (RAM) 503. In the RAM 503, various programs and data necessary for the operation of the system 500 are also stored. The CPU 501, ROM 502, and RAM 503 are connected to each other via a bus 504. An input/output (I/O) interface 505 is also connected to bus 504.
The following components are connected to the I/O interface 505: an input portion 506 including a keyboard, a mouse, and the like; an output portion 507 including a display such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; a storage portion 508 including a hard disk and the like; and a communication section 509 including a network interface card such as a LAN card, a modem, or the like. The communication section 509 performs communication processing via a network such as the internet. The driver 510 is also connected to the I/O interface 505 as necessary. A removable medium 511 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 510 as necessary, so that a computer program read out therefrom is mounted into the storage section 508 as necessary.
In particular, according to the embodiments of the present disclosure, the processes described above with reference to the 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 illustrated in the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network through the communication section 509, and/or installed from the removable medium 511. The computer program performs the above-described functions defined in the system of the present invention when executed by the Central Processing Unit (CPU) 501.
It should be noted that the computer readable medium shown in the present invention can be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination 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 present invention, 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 invention, however, a computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. 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: wireless, wire, fiber optic cable, RF, etc., or any suitable combination of the foregoing.
The flowchart 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 invention. 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 or flowchart illustration, and combinations of blocks in the block diagrams 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 modules and/or units described in the embodiments of the present invention may be implemented by software, and may also be implemented by hardware. The described modules and/or units may also be provided in a processor, and may be described as: a processor includes a parse annotation module and a check code module. For example, parsing the annotation module may be further described as "obtaining an annotation corresponding to the service code, parsing the annotation type from the annotation, and obtaining a verification policy module associated with the annotation type from the annotation".
As another aspect, the present invention also provides a computer-readable medium that may be contained in the apparatus described in the above embodiments; or may be separate and not incorporated into the device. The computer readable medium carries one or more programs which, when executed by a device, cause the device to comprise: obtaining an annotation corresponding to a business code, analyzing an annotation type from the annotation, and obtaining a verification strategy associated with the annotation type from the annotation; and searching a first check code matched with the check strategy in multiple preset check codes, and calling the first check code to check the service code.
According to the embodiment of the invention, the annotation of the business code can be obtained, the verification strategy of the code is analyzed from the annotation, and the corresponding verification code is called through the verification strategy to execute the verification of the business code; the problem of coupling of the check code and the service code is solved, so that the problems of poor flexibility and poor reusability of the check code are solved; the maintainability of the check code is improved; by reducing the labor cost and time cost of development, the development efficiency is improved.
The above-described embodiments should not be construed as limiting the scope of the invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions can occur, depending on design requirements and other factors. Any modification, equivalent replacement, and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims (10)

1. A method of checking a code, comprising:
obtaining an annotation corresponding to a business code, analyzing an annotation type from the annotation, and obtaining a verification strategy associated with the annotation type from the annotation;
and searching a first check code matched with the check strategy in multiple preset check codes, and calling the first check code to check the service code.
2. The method of claim 1,
the annotation types include: method annotation and/or parameter annotation.
3. The method of claim 2, wherein parsing an annotation type from the annotation and obtaining a verification policy associated with the annotation type from the annotation comprises:
the annotation type is an annotation of the method,
responding to a calling instruction of any business method in the business code, and intercepting the calling instruction;
determining a method annotation of a business method corresponding to the calling instruction;
and acquiring a verification strategy corresponding to the method annotation from the method annotation.
4. The method of claim 2, wherein the parsing annotation types from the annotations further comprises:
the annotation type is the parameter annotation,
and determining the parameter entry field corresponding to the parameter annotation, and acquiring the parameter value corresponding to the parameter entry field.
5. The method of claim 1, further comprising:
in response to the verification policy having a plurality of the verification rules, the first verification code includes a priority order in which to execute the verification rules;
performing a check of the service code using the first check code, including:
and based on the priority sequence, sequentially calling a second check code corresponding to the check rule to check the service code.
6. The method of claim 1,
the first check code has a corresponding check context;
further comprising: storing the data to be checked included in the service code to the checking context;
and sharing the data to be checked for a plurality of second checking codes by using the checking context.
7. The method of claim 5,
the first check code contains a check annotation; the check annotation comprises check rule identifications corresponding to a plurality of check rules;
further comprising:
matching each check rule identifier included in the check strategy with a plurality of check rule identifiers included in the check annotation;
and according to the matching result, executing the step of sequentially calling a second check code corresponding to the check rule to check the service code.
8. An apparatus for verifying a code, comprising: analyzing an annotation module and a check code module; wherein the content of the first and second substances,
the analysis annotation module is used for acquiring an annotation corresponding to the service code, analyzing an annotation type from the annotation, and acquiring a verification strategy associated with the annotation type from the annotation;
and the check code module is used for searching a first check code matched with the check strategy in multiple preset check codes and calling the first check code to check the service code.
9. An electronic device, comprising:
one or more processors;
a storage device for storing one or more programs,
when executed by the one or more processors, cause the one or more processors to implement the method of any one of claims 1-7.
10. A computer-readable medium, on which a computer program is stored, which, when being executed by a processor, carries out the method according to any one of claims 1-7.
CN202111053416.6A 2021-09-09 2021-09-09 Method and device for checking codes Pending CN113742235A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111053416.6A CN113742235A (en) 2021-09-09 2021-09-09 Method and device for checking codes

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111053416.6A CN113742235A (en) 2021-09-09 2021-09-09 Method and device for checking codes

Publications (1)

Publication Number Publication Date
CN113742235A true CN113742235A (en) 2021-12-03

Family

ID=78737444

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111053416.6A Pending CN113742235A (en) 2021-09-09 2021-09-09 Method and device for checking codes

Country Status (1)

Country Link
CN (1) CN113742235A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116822451A (en) * 2023-06-29 2023-09-29 成都融见软件科技有限公司 Method, equipment and medium for reusing and displaying annotation area of variable chip design code

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116822451A (en) * 2023-06-29 2023-09-29 成都融见软件科技有限公司 Method, equipment and medium for reusing and displaying annotation area of variable chip design code
CN116822451B (en) * 2023-06-29 2024-03-08 成都融见软件科技有限公司 Method, equipment and medium for reusing and displaying annotation area of variable chip design code

Similar Documents

Publication Publication Date Title
CN110601880B (en) Cloud platform, service processing method, command interface and computer equipment
CN110019080B (en) Data access method and device
CN112000730B (en) Tracing information writing and tracing information verification method and system based on block chain
CN113076153B (en) Interface calling method and device
CN110020358B (en) Method and device for generating dynamic page
CN111427701A (en) Workflow engine system and business processing method
CN111598575A (en) Business process control method and device, electronic equipment and readable storage medium
CN112463729A (en) Data file storage method and device, electronic equipment and medium
CN113742235A (en) Method and device for checking codes
CN113779004A (en) Data verification method and device
CN113778725A (en) Data verification method and device
CN112825096A (en) Data desensitization method and device
CN109145591A (en) The plug-in loading method of application program
CN111459819B (en) Software testing method and device, electronic equipment and computer readable medium
CN112783903B (en) Method and device for generating update log
CN109688174A (en) A kind of virtual service implementation method and device based on more agents service
CN113704222A (en) Method and device for processing service request
CN113535322A (en) Form verification method and device
CN111209014A (en) Parameter checking method and device
CN109376023B (en) Method and equipment for generating calling information and issuing return code group
CN115981609A (en) Service processing method and device, electronic equipment and computer readable medium
CN116436975A (en) Resource calling method, device, equipment and medium applied to server cluster
CN115168831A (en) Method and device for verifying access authority
CN112272211A (en) Service request processing method, device and system
CN113778969A (en) Log processing method and device

Legal Events

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