CN110764748B - Code calling method, device, terminal and storage medium - Google Patents

Code calling method, device, terminal and storage medium Download PDF

Info

Publication number
CN110764748B
CN110764748B CN201911009782.4A CN201911009782A CN110764748B CN 110764748 B CN110764748 B CN 110764748B CN 201911009782 A CN201911009782 A CN 201911009782A CN 110764748 B CN110764748 B CN 110764748B
Authority
CN
China
Prior art keywords
class
target
code
implementation
interface
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.)
Active
Application number
CN201911009782.4A
Other languages
Chinese (zh)
Other versions
CN110764748A (en
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 ByteDance Network Technology Co Ltd
Original Assignee
Beijing ByteDance Network 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 ByteDance Network Technology Co Ltd filed Critical Beijing ByteDance Network Technology Co Ltd
Priority to CN201911009782.4A priority Critical patent/CN110764748B/en
Publication of CN110764748A publication Critical patent/CN110764748A/en
Application granted granted Critical
Publication of CN110764748B publication Critical patent/CN110764748B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/31Programming languages or programming paradigms
    • G06F8/315Object-oriented languages
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/44Encoding
    • G06F8/443Optimisation
    • G06F8/4441Reducing the execution time required by the program code

Abstract

The embodiment of the disclosure provides a code calling method, a code calling device, a terminal and a storage medium. The code calling method comprises the following steps: designing an interface, and modifying a target class and a target attribute to be reflected on the interface through annotation; analyzing the annotated target class and the annotated target attribute through an annotation processor, and sorting the target class and the target attribute to be reflected into a file; generating an implementation class for the interface; traversing class files in the code, searching target classes in the class files, and changing the authority of target attributes in the target classes to be public; inserting direct call code for the target property into the null method in the implementation class. By adopting the code calling method disclosed by the invention, the tedious reflection search can be saved when the code of the private or protected target attribute is called, and the performance loss caused by reflection is relieved.

Description

Code calling method, device, terminal and storage medium
Technical Field
The embodiment of the disclosure relates to the technical field of computers, and more particularly, to a code calling method, a code calling device, a terminal and a storage medium.
Background
Syntax specification of some programming languages (e.g., java) provides different levels of access right modifiers for the member variable (field) and the member method (method) of a class, thereby better designing code in an object-oriented way. In addition, such languages usually suggest that developers only expose a small portion of necessary member methods and member variables to the outside, and set most of the member variables and member methods as private (private) or protected (protected) to avoid unexpected situations caused by other callers modifying these internal attributes arbitrarily, thereby ensuring the stability of the program.
Often, however, a piece of code cannot be designed to meet all future requirements from the beginning, and as the project evolves, the caller has to modify or invoke the private member variables or member methods of the class, which may be implemented by the reflection mechanism of the programming language (e.g., java).
However, the reflective mechanism has a severe performance penalty. Reflection execution requires searching for target member variables or member methods by traversing class files through character strings during operation, which is time consuming.
Disclosure of Invention
This summary is provided to introduce a selection of concepts in a simplified form that are further described below in the detailed description. This summary is not intended to identify key features or essential features of the claimed subject matter, nor is it intended to be used to limit the scope of the claimed subject matter.
In order to solve the above problems, the present disclosure provides a code calling method, a device, a terminal, and a storage medium, where the code calling method of the present disclosure can save cumbersome reflection search when calling a code of a private or protected target attribute, and alleviate performance loss caused by reflection.
According to an embodiment of the present disclosure, there is provided a code calling method including: designing an interface, and modifying a target class to be reflected and a target attribute in the target class through annotation on the interface, wherein the authority of the target attribute is private or protected; analyzing the annotated target class and the target attribute through an annotation processor, and sorting the target class and the target attribute to be reflected into a file; generating an implementation class for the interface, wherein methods in the implementation class are all null methods; traversing class files in the code, searching the target class in the class files, and changing the authority of the target attribute in the target class into public; inserting direct call code for the target property into the null method in the implementation class.
According to another embodiment of the present disclosure, there is provided a code calling apparatus including: an interface design module configured to design an interface, and modify a target class to be reflected and a target attribute in the target class through an annotation on the interface, wherein the authority of the target attribute is private or protected; the annotation processing module is configured to analyze the annotated target class and the annotated target attribute and sort the target class and the target attribute to be reflected into a file; an implementation class generation module configured to generate an implementation class for the interface, wherein methods in the implementation class are all null methods; a bytecode modification module configured to traverse a class file in a code, search the target class in the class file, and change the authority of the target attribute in the target class to public, the bytecode modification module being further configured to insert a direct call code for the target attribute into the null method in the implementation class.
According to another embodiment of the present disclosure, there is provided a terminal including: at least one memory and at least one processor; the memory is used for storing program codes, and the processor is used for calling the program codes stored in the memory to execute the code calling method.
According to another embodiment of the present disclosure, there is provided a computer storage medium storing program code for executing the code calling method.
By adopting the code calling method disclosed by the invention, the complicated reflection search can be saved when the code of the private or protected target attribute is called, the performance loss caused by reflection is relieved, and the reflection calling is convenient and quick as the common code calling.
Drawings
The above and other features, advantages and aspects of various embodiments of the present disclosure will become more apparent by referring to the following detailed description when taken in conjunction with the accompanying drawings. Throughout the drawings, the same or similar reference numbers refer to the same or similar elements. It should be understood that the drawings are schematic and that elements and features are not necessarily drawn to scale.
FIG. 1 shows a schematic flow chart diagram of a code invocation method of an embodiment of the present disclosure.
FIG. 2 shows a schematic flow chart diagram of a code invocation method of another embodiment of the present disclosure.
Fig. 3 shows a schematic diagram of a code invocation device of an embodiment of the present disclosure.
FIG. 4 illustrates a schematic structural diagram of an electronic device 400 suitable for use in implementing embodiments of the present disclosure.
Detailed Description
Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. While certain embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure may be embodied in various forms and should not be construed as limited to the embodiments set forth herein, but rather are provided for a more complete and thorough understanding of the present disclosure. It should be understood that the drawings and the embodiments of the disclosure are for illustration purposes only and are not intended to limit the scope of the disclosure.
It should be understood that the various steps recited in the method embodiments of the present disclosure may be performed in a different order, and/or performed in parallel. Moreover, method embodiments may include additional steps and/or omit performing the illustrated steps. The scope of the present disclosure is not limited in this respect.
The term "include" and variations thereof as used herein are open-ended, i.e., "including but not limited to". The term "based on" is "based, at least in part, on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". Relevant definitions for other terms will be given in the following description.
It should be noted that the terms "first", "second", and the like in the present disclosure are only used for distinguishing different devices, modules or units, and are not used for limiting the order or interdependence relationship of the functions performed by the devices, modules or units.
It is noted that references to "a", "an", and "the" modifications in this disclosure are intended to be illustrative rather than limiting, and that those skilled in the art will recognize that "one or more" may be used unless the context clearly dictates otherwise.
In the running state, for any class, all attributes of the class can be acquired, for any object, any attribute (including private attributes) of the class can be called, and the functions of the dynamically acquired information and the method for dynamically calling the object are called as a reflection mechanism. Reflection execution is very time consuming since it requires looking up the target property (e.g., member variable or member method) at runtime by traversing the class file through a string. For the problem of time consuming reflection implementation, most developers will spend more time and effort trying to try another solution to avoid using reflection, or be forced to accept its performance loss. In view of the very high use value of reflection, if the performance problem of reflection can be solved, the time and energy loss of developers can be greatly saved, and the program running performance can be greatly improved.
At present, after the reflection code is called for the first time, the reflection result can be cached, and the search time of the next reflection is saved. But this method performs at least one reflection finding operation that is very time consuming. In addition, even if subsequent reflection lookup operations are avoided by the cache, effort is required to maintain the cache.
In order to better solve the performance loss problem of the reflection call, the disclosure provides a code calling method. As shown in fig. 1, a code calling method is provided, which includes step S101 of designing an interface, and modifying a target class to be reflected and a target attribute in the target class by an annotation on the interface. Generally, the code calling method of the present disclosure is executed in an operating system of a terminal, however, the present disclosure is not limited thereto. In some embodiments, the terminal in the present disclosure may include, but is not limited to, mobile terminal devices such as a mobile phone, a smart phone, a notebook computer, a PDA (personal digital assistant), a PAD (tablet computer), a PMP (portable multimedia player), a navigation device, a vehicle-mounted terminal device, a vehicle-mounted display terminal, and the like, and fixed terminal devices such as a digital TV, a desktop computer, and the like. In some embodiments, the operating systems of the present disclosure include, but are not limited to, windows, IOS, and Android operating systems. In some embodiments, designing the interface includes executing by a program of the underlying code by calling a standard Application Program Interface (API) function of the operating system. The interface is typically designed during the encoding stage. For example, in some embodiments, modifying the target class to be reflected and the target attribute in the target class by the annotation on the interface includes adding the annotation @ RefTarget to the target class and adding the annotation @ get target attribute to the target attribute on the interface. Typically, the parameters of the annotations to the target class and target attributes correspond to the corresponding target class name and target attribute name.
In some embodiments, the rights for the target property are typically private or protected for non-public (non-public) code invocation issues that the present disclosure addresses. In some embodiments, the target attribute includes at least one of a member variable and a member method, however, the disclosure is not limited thereto.
As shown in fig. 1, the code calling method of the present disclosure further includes a step S102, parsing, by the annotation processor, the annotated target class and the annotated target attribute, and sorting the target class and the target attribute to be reflected into a file. Step 102 is typically performed during the compilation stage. In some embodiments, an annotation processor may be registered by calling a standard application function and specified for processing annotations. In some embodiments, in order to obtain the annotated information, the registered annotation processor is used to parse the annotated information of the target class and the target attribute, and the target class and the target attribute information to be reflected, such as a target class name and a target attribute name, are obtained through parsing. In addition, the annotation processor may summarize the parsed target class and target attribute information into a file, for example, generate a json file, where the json file includes the parsed target class and target attribute information.
As shown in fig. 1, the code calling method of the present disclosure further includes step S103 of generating an implementation class for the interface. In order for a designed interface to run and be implemented, an implementation class is generated for the interface. In some embodiments, various code generation techniques may be employed to generate an implementation class for an interface. In addition, since the target attribute to be reflected is private or protected, the methods in the current implementation class are all null methods for passing through in the compilation program, and there is no specific implementation inside.
As shown in fig. 1, the code invoking method of the present disclosure further includes step S104, traversing the class file in the code, finding the target class in the class file, and changing the authority of the target attribute in the target class to be public. In some embodiments, after compiling the code file containing the target property code into a class file, the target class is located by traversing a list of class files through a bytecode modifier. After the target class is found, a bytecode modifier can be used to modify the authority of the target attribute in the found target class to be public (public). In some embodiments, the bytecode modifier may employ javasissist, which is an open source class library that analyzes, edits, and creates Java bytecodes, however, the disclosure is not limited thereto. In some embodiments, before traversing the class file in the code, further comprising: reading a file (for example, a json file) finished by the annotation processor through a bytecode modifier, and acquiring a target class to be reflected for finding the target class in the class file.
In step S105, a direct call code for the target property is inserted into the null method in the implementation class to implement the call for the target property. In some embodiments, various calling codes that can be recognized by the operating system may be employed, so long as a call to the target property can be achieved. In some embodiments, after inserting direct calling code for the target property into the null method in the implementation class, the implementation class is obtained by the factory class and run. In some embodiments, the implementation class is generally run through a Factory class (Factory class) in the run phase, so as to obtain a specific implementation of the implementation class. The factory class is a class for implementing a corresponding interface, and when the corresponding implementation class is run, the corresponding factory class may be created, and then the implementation class of the corresponding interface is provided to the inside of the factory class, for example, through javasist. Thus, in the run phase, the implementation class is obtained by the factory class and run to implement the call to the target property. It should be understood that the above implementation-like operation is only an example and is not intended to limit the disclosure, and the disclosure may employ any other suitable operation.
When the implementation class is operated, because the access authority modifier of the target attribute to be reflected is already public, reflection search is not needed, and the target attribute can be directly called, and the calling is the same as that of ordinary code, and no performance loss exists. Therefore, the code calling method can realize the direct calling of the original private or protected target attribute, and greatly saves the time of reflection searching compared with the original reflection mechanism.
Embodiments of the present disclosure are further described below in conjunction with fig. 2. Fig. 2 illustrates an exemplary flow of an embodiment of a method of the present disclosure. In some embodiments, an interface is designed and a reflection is provided to reflect the method to be called. For example, an interface RefUser is designed by calling a standard application program function, a getName method is provided, and then the target attribute is called by the method. After the interface is designed, the interface is modified by annotations to provide the target class and target properties to be reflected. For example, add the annotation @ RefTarget on the interface, @ RefTarget has a parameter clazz, which represents the target class name to be decorated. For example, add the annotation @ GetField to the getName method, the argument of which is the name of the private or protected member variable that the reflection is expected to be. The above-mentioned stages are typically performed in the encoding stage.
Thereafter, an annotation processor is registered by calling standard application functions and is indicated for processing the annotation (e.g., @ RefTarget and @ GetField). And analyzing the annotation by the annotation processor to obtain the target class and the target attribute to be reflected, summarizing the target class and the target attribute, and generating a readable file, such as a json file. And then, generating an implementation class for the interface by using a code generation technology, wherein all internal methods of the implementation class are null methods.
Then, the json file is read by a bytecode modifier or module (usually javasist), and the information of the target class and the target attribute is obtained. Traversing the class file by using the obtained information of the target class and the target attribute through a bytecode modifier, searching the target class, and modifying the authority modifier of the target attribute in the target class into public. And then, inserting direct calling codes for the target attribute into the null method of the implementation class through the bytecode modifier. The implementation class after the calling code is inserted is the implementation class that can be used to call the target property. Which may be used to invoke the target property when implementing the class runtime. Thus, by modifying the permission modifier of the class, the time for the conventional reflected traversal character string to find the target attribute in the class is eliminated, and the efficiency of calling the private or protected target attribute code is greatly improved.
The embodiment of the present disclosure further provides a code calling apparatus 300, which includes an interface design module 301, an annotation processing module 302, an implementation class generation module 303, and a bytecode modification module 304. In some embodiments, the interface design module 301 is configured to design an interface and modify a target class to be reflected and target attributes in the target class over the interface with annotations, wherein the rights of the target attributes are private or protected. In some embodiments, annotation processing module or annotation processor 302 is configured to parse annotated target classes and target attributes and sort the target classes and target attributes to be reflected into a file. In some embodiments, the implementation class generation module 303 is configured to generate an implementation class for the interface, where methods in the implementation class are all null methods. In some embodiments, the bytecode modification module 304 is configured to traverse a class file in the code, find a target class in the class file, and change the permissions of the target attributes in the target class to public, and the bytecode modification module is further configured to insert direct-call code for the target attributes into null methods in the implementation class.
In some embodiments, the target attribute includes at least one of a member variable and a member method. In some embodiments, the code invoking device further comprises: and the implementation class running module is configured to acquire the implementation class of the direct calling code inserted with the target attribute and run the implementation class.
In addition, the present disclosure also provides a terminal, including: at least one memory and at least one processor; the memory is used for storing program codes, and the processor is used for calling the program codes stored in the memory to execute the code calling method.
In addition, the present disclosure also provides a computer storage medium storing program codes for executing the code calling method.
The reason that the conventional reflection is slow to execute is that the corresponding target class needs to be searched by traversing the class file, and all target attributes of the target class are traversed by comparing the character strings after the target class is found. The degree of time consumption increases as the number of class files and the number of target attributes increase. The larger the number, the more time-consuming the reflection search. A single item with only a few simple class files and target properties, a reflected call is about 25% slower than a direct call. For large projects this time will be higher.
By using the calling method disclosed by the invention, the step of traversing the character string to search the target attribute which is most time-consuming in the conventional reflection is omitted, so that the reflection calling is almost not different from the common calling. In some embodiments, the permission modifier of the target attribute is modified by the bytecode modifier, so that the direct calling of the code of the target attribute is allowed by the implementation class. By adopting the calling method disclosed by the invention, the calling of the private or protected target attribute is simplified, the time required by reflection search is greatly saved, and the efficiency is improved for program development.
Referring now to FIG. 4, a block diagram of an electronic device 400 suitable for use in implementing embodiments of the present disclosure is shown. The terminal device in the embodiments of the present disclosure may include, but is not limited to, a mobile terminal such as a mobile phone, a notebook computer, a digital broadcast receiver, a PDA (personal digital assistant), a PAD (tablet computer), a PMP (portable multimedia player), a vehicle terminal (e.g., a car navigation terminal), and the like, and a stationary terminal such as a digital TV, a desktop computer, and the like. The electronic device shown in fig. 4 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present disclosure.
As shown in fig. 4, electronic device 400 may include a processing device (e.g., central processing unit, graphics processor, etc.) 401 that may perform various appropriate actions and processes in accordance with a program stored in a Read Only Memory (ROM) 402 or a program loaded from a storage device 406 into a Random Access Memory (RAM) 403. In the RAM 403, various programs and data necessary for the operation of the electronic apparatus 400 are also stored. The processing device 401, the ROM 402, and the RAM 403 are connected to each other via a bus 404. An input/output (I/O) interface 405 is also connected to bus 404.
Generally, the following devices may be connected to the I/O interface 405: input devices 406 including, for example, a touch screen, touch pad, keyboard, mouse, camera, microphone, accelerometer, gyroscope, etc.; an output device 407 including, for example, a Liquid Crystal Display (LCD), a speaker, a vibrator, and the like; storage devices 406 including, for example, magnetic tape, hard disk, etc.; and a communication device 409. The communication means 409 may allow the electronic device 400 to communicate wirelessly or by wire with other devices to exchange data. While fig. 4 illustrates an electronic device 400 having various means, it is to be understood that not all illustrated means are required to be implemented or provided. More or fewer devices may be alternatively implemented or provided.
In particular, the processes described above with reference to the flow diagrams may be implemented as computer software programs, according to embodiments of the present disclosure. For example, embodiments of the present disclosure include a computer program product comprising a computer program carried on a non-transitory computer readable medium, the computer program containing program code for performing the method illustrated by the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network via the communication means 609, or may be installed from the storage means 406, or may be installed from the ROM 402. The computer program performs the above-described functions defined in the methods of the embodiments of the present disclosure when executed by the processing device 401.
It should be noted that the computer readable medium in the present disclosure 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 disclosure, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In contrast, in the present disclosure, a computer readable signal medium may comprise a propagated data signal with computer readable program code embodied therein, either in baseband or as part of a carrier wave. Such a propagated data signal may take any of a variety of forms, including, but not limited to, electro-magnetic, optical, or any suitable combination 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: electrical wires, optical cables, RF (radio frequency), etc., or any suitable combination of the foregoing.
In some embodiments, the clients, servers may communicate using any currently known or future developed network Protocol, such as HTTP (HyperText Transfer Protocol), and may interconnect with any form or medium of digital data communication (e.g., a communications network). Examples of communication networks include a local area network ("LAN"), a wide area network ("WAN"), the Internet (e.g., the Internet), and peer-to-peer networks (e.g., ad hoc peer-to-peer networks), as well as any currently known or future developed network.
The computer readable medium may be embodied in the electronic device; or may exist separately without being assembled into the electronic device.
The computer readable medium carries one or more programs which, when executed by the electronic device, cause the electronic device to: acquiring at least two internet protocol addresses; sending a node evaluation request comprising the at least two internet protocol addresses to node evaluation equipment, wherein the node evaluation equipment selects the internet protocol addresses from the at least two internet protocol addresses and returns the internet protocol addresses; receiving an internet protocol address returned by the node evaluation equipment; wherein the obtained internet protocol address indicates an edge node in the content distribution network.
Alternatively, the computer readable medium carries one or more programs which, when executed by the electronic device, cause the electronic device to: receiving a node evaluation request comprising at least two internet protocol addresses; selecting an internet protocol address from the at least two internet protocol addresses; returning the selected internet protocol address; wherein the received internet protocol address indicates an edge node in the content distribution network.
Computer program code for carrying out operations for the present disclosure may be written in any combination of one or more programming languages, including but not limited to an object oriented programming language such as Java, smalltalk, C + +, and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet service provider).
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 disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The units described in the embodiments of the present disclosure may be implemented by software or hardware. Where the name of a unit does not in some cases constitute a limitation of the unit itself, for example, the first retrieving unit may also be described as a "unit for retrieving at least two internet protocol addresses".
The functions described herein above may be performed, at least in part, by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field Programmable Gate Arrays (FPGAs), application Specific Integrated Circuits (ASICs), application Specific Standard Products (ASSPs), systems on a chip (SOCs), complex Programmable Logic Devices (CPLDs), and the like.
In the context of this disclosure, a machine-readable medium may be a tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. The machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
According to one or more embodiments of the present disclosure, there is provided a code calling method including: designing an interface, and modifying a target class to be reflected and a target attribute in the target class through annotation on the interface, wherein the authority of the target attribute is private or protected; analyzing the annotated target class and the annotated target attribute through an annotation processor, and sorting the target class and the target attribute to be reflected into a file; generating an implementation class for the interface, wherein methods in the implementation class are all null methods; traversing class files in the code, searching the target class in the class files, and changing the authority of the target attribute in the target class to be public; inserting direct call code for the target property into the null method in the implementation class.
According to one or more embodiments of the present disclosure, the target attribute includes at least one of a member variable and a member method.
According to one or more embodiments of the present disclosure, before parsing the target class and the target attribute of the annotation by the annotation processor, the method further comprises: the annotation processor is registered by calling a standard application function and is designated for processing the annotation.
According to one or more embodiments of the present disclosure, before traversing a class file in code, the method further comprises: reading the file sorted by the annotation processor through a bytecode modifier, and acquiring the target class to be reflected for searching the target class in the class file.
According to one or more embodiments of the present disclosure, further comprising: after inserting direct call code for the target property into the null method in the implementation class, obtaining the implementation class through a factory class and running the implementation class.
According to one or more embodiments of the present disclosure, there is also provided a code calling apparatus including: the interface design module is configured to design an interface, and modify a target class to be reflected and a target attribute in the target class through annotation on the interface, wherein the authority of the target attribute is private or protected; the annotation processing module is configured to analyze the annotated target class and the annotated target attribute and sort the target class and the target attribute to be reflected into a file; an implementation class generation module configured to generate an implementation class for the interface, wherein methods in the implementation class are all null methods; a bytecode modification module configured to traverse a class file in a code, search the target class in the class file, and change the authority of the target attribute in the target class to public, the bytecode modification module being further configured to insert a direct call code for the target attribute into the null method in the implementation class.
According to one or more embodiments of the present disclosure, the target attribute includes at least one of a member variable and a member method.
According to one or more embodiments of the present disclosure, further comprising: and the implementation class running module is configured to acquire the implementation class of the direct calling code inserted with the target attribute and run the implementation class.
According to one or more embodiments of the present disclosure, there is provided a terminal including: at least one memory and at least one processor; the memory is used for storing program codes, and the processor is used for calling the program codes stored in the memory to execute the code calling method.
According to one or more embodiments of the present disclosure, there is provided a computer storage medium storing program code for executing the above code calling method.
The foregoing description is only exemplary of the preferred embodiments of the disclosure and is illustrative of the principles of the technology employed. It will be appreciated by those skilled in the art that the scope of the disclosure herein is not limited to the particular combination of features described above, but also encompasses other combinations of features described above or equivalents thereof without departing from the spirit of the disclosure. For example, the above features and (but not limited to) the features disclosed in this disclosure having similar functions are replaced with each other to form the technical solution.
Further, while operations are depicted in a particular order, this should not be understood as requiring that such operations be performed in the particular order shown or in sequential order. Under certain circumstances, multitasking and parallel processing may be advantageous. Likewise, while several specific implementation details are included in the above discussion, these should not be construed as limitations on the scope of the disclosure. Certain features that are described in the context of separate embodiments can also be implemented in combination in a single embodiment. Conversely, various features that are described in the context of a single embodiment can also be implemented in multiple embodiments separately or in any suitable subcombination.
Although the subject matter has been described in language specific to structural features and/or methodological acts, it is to be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or acts described above. Rather, the specific features and acts described above are disclosed as example forms of implementing the claims.

Claims (10)

1. A code calling method, comprising:
designing an interface, and modifying a target class to be reflected and a target attribute in the target class through annotation on the interface, wherein the authority of the target attribute is private or protected;
analyzing the annotated target class and the annotated target attribute through an annotation processor, and sorting the target class and the target attribute to be reflected into a file;
generating an implementation class for the interface, wherein methods in the implementation class are all null methods;
traversing class files in the code, searching the target class in the class files, and changing the authority of the target attribute in the target class to be public;
inserting direct call code for the target property into the null method in the implementation class.
2. The code call method according to claim 1, wherein the target property comprises at least one of a member variable and a member method.
3. The code calling method according to claim 1, further comprising, before parsing the annotated target class and target attributes by the annotation processor:
the annotation processor is registered by calling a standard application function and is designated for processing the annotation.
4. The code calling method of claim 1, further comprising, prior to traversing a class file in the code:
reading the file sorted by the annotation processor through a bytecode modifier, and acquiring the target class to be reflected for searching the target class in the class file.
5. The code calling method according to claim 1, further comprising:
after inserting direct call code for the target property into the null method in the implementation class, obtaining the implementation class through a factory class and running the implementation class.
6. A code invocation apparatus, comprising:
an interface design module configured to design an interface, and modify a target class to be reflected and a target attribute in the target class through an annotation on the interface, wherein the authority of the target attribute is private or protected;
the annotation processing module is configured to analyze the annotated target class and the annotated target attribute and arrange the target class and the target attribute to be reflected into a file;
an implementation class generation module configured to generate an implementation class for the interface, wherein methods in the implementation class are all null methods;
a bytecode modification module configured to traverse a class file in a code, search the target class in the class file, and change the authority of the target attribute in the target class to public, the bytecode modification module being further configured to insert a direct call code for the target attribute into the null method in the implementation class.
7. The code invocation device according to claim 6, wherein the target property comprises at least one of a member variable and a member method.
8. The code calling apparatus of claim 6, further comprising:
and the implementation class running module is configured to acquire the implementation class of the direct calling code inserted with the target attribute and run the implementation class.
9. A terminal, characterized in that the terminal comprises:
at least one memory and at least one processor;
wherein the memory is configured to store program code, and the processor is configured to call the program code stored in the memory to perform the code calling method of any one of claims 1 to 5.
10. A computer storage medium characterized in that the computer storage medium stores program code for executing the code calling method of any one of claims 1 to 5.
CN201911009782.4A 2019-10-23 2019-10-23 Code calling method, device, terminal and storage medium Active CN110764748B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201911009782.4A CN110764748B (en) 2019-10-23 2019-10-23 Code calling method, device, terminal and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201911009782.4A CN110764748B (en) 2019-10-23 2019-10-23 Code calling method, device, terminal and storage medium

Publications (2)

Publication Number Publication Date
CN110764748A CN110764748A (en) 2020-02-07
CN110764748B true CN110764748B (en) 2023-03-14

Family

ID=69333017

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201911009782.4A Active CN110764748B (en) 2019-10-23 2019-10-23 Code calling method, device, terminal and storage medium

Country Status (1)

Country Link
CN (1) CN110764748B (en)

Families Citing this family (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113391860B (en) * 2020-03-11 2024-01-30 抖音视界有限公司 Service request processing method and device, electronic equipment and computer storage medium
CN113391811B (en) * 2020-03-13 2023-11-03 抖音视界有限公司 Function compiling method, function compiling device, electronic equipment and computer readable storage medium
CN112015394B (en) * 2020-08-27 2024-02-27 北京百度网讯科技有限公司 Android function module development method and device, computer system and storage medium
CN113051002A (en) * 2020-12-24 2021-06-29 完美世界(北京)软件科技发展有限公司 Data editing method, device and storage medium
CN112799954B (en) * 2021-02-09 2024-04-16 上海云轴信息科技有限公司 Method, apparatus and computer readable medium for quickly constructing test environment

Family Cites Families (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6016492A (en) * 1997-07-15 2000-01-18 Microsoft Corporation Forward extensible property modifiers for formatting information in a program module
GB0624033D0 (en) * 2006-12-01 2007-01-10 Iti Scotland Ltd Dynamic intervention with software applications
CN105573758A (en) * 2015-12-16 2016-05-11 福建星网智慧科技股份有限公司 Dynamic byte-code compilation technology-based codejson frame
CN108920179A (en) * 2017-04-12 2018-11-30 中国移动通信集团福建有限公司 Java reflects implementation method, device and system
KR101987048B1 (en) * 2017-09-15 2019-06-10 주식회사 티맥스 소프트 Easy-to-use type of compile-time dependency injection method and device in the java platform
CN108156022B (en) * 2017-12-04 2021-07-09 北京奇艺世纪科技有限公司 Service calling method and device and electronic equipment
CN110245030B (en) * 2019-05-29 2021-11-12 北京字节跳动网络技术有限公司 Data service providing method, device, medium and electronic equipment

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
花磊 ; 魏峻 ; 牛春雷 ; 郑浩然 ; .动态模板驱动的高性能SOAP处理.2006,(07),全文. *
袁鑫晨 ; 李海波 ; 王伟 ; 唐震 ; 任仲山 ; 郑莹莹 ; .基于程序分析的分布式应用自动化追踪方法.2016,(11),全文. *

Also Published As

Publication number Publication date
CN110764748A (en) 2020-02-07

Similar Documents

Publication Publication Date Title
CN110764748B (en) Code calling method, device, terminal and storage medium
US10042746B2 (en) Callpath finder
CN109062563B (en) Method and device for generating page
US20130061208A1 (en) Transformational context-aware data source management
CN109726217B (en) Database operation method, device, equipment and storage medium
CN112817657A (en) Application program starting item loading method, device and system and storage medium
CN114035805A (en) Code conversion method, apparatus, medium, and device for pre-compiler
CN111309304B (en) Method, device, medium and electronic equipment for generating IDL file
CN113407165B (en) SDK generation and self-upgrade method, device, readable medium and equipment
CN112416303B (en) Software development kit hot repair method and device and electronic equipment
CN108959294B (en) Method and device for accessing search engine
CN111796865B (en) Byte code file modification method, device, terminal equipment and medium
CN111124541A (en) Configuration file generation method, device, equipment and medium
CN113760969A (en) Data query method and device based on elastic search
CN108089852B (en) Method, medium, apparatus and computing device for establishing attribute access
CN112445820A (en) Data conversion method and device
CN112068814A (en) Method, device, system and medium for generating executable file
CN110069514B (en) Message processing method and device
CN111562913B (en) Method, device and equipment for pre-creating view component and computer readable medium
CN115563183B (en) Query method, query device and program product
CN112015394B (en) Android function module development method and device, computer system and storage medium
CN116795371A (en) Condition compiling method, device, equipment and medium
CN116009951A (en) Code processing method, device, equipment and storage medium
CN116450289A (en) Data processing method, device, storage medium and electronic equipment
CN115878091A (en) Data processing method, device, equipment and storage medium

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
GR01 Patent grant
GR01 Patent grant