Code Processing Method, Device, Storage Medium, and Electronic Device

By analyzing the code weaving and reflection technology of multi-section functional code, generating the call relationship between the target classes and prompting the class, the problem that the existing weaving design pattern cannot provide intelligent prompts is solved, and more efficient code writing and design is achieved.

CN114840274BActive Publication Date: 2025-07-01NETEASE (HANGZHOU) NETWORK CO LTD

Patent Information

Application Number
CN202210395650.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-04-14
Publication Date
2025-07-01
Estimated Expiration
2042-04-14

AI Technical Summary

Technical Problem

The existing weaving design pattern cannot understand the correlation between classes during compilation, resulting in the inability to provide intelligent prompts, affecting the efficiency of code writing.

Method used

By code-woven into multiple functional code, the target class is generated, and the target class is parsed using reflection technology to obtain the target interface. Then create an empty class, claiming that the empty class implements the target interface, and inherits the empty class through the target class to prompt the call relationship between classes.

Benefits of technology

It realizes providing intelligent tips when writing code, reduces the tedious process of manually checking different methods, saves manpower and time costs, and improves code writing and design efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114840274B_ABST
    Figure CN114840274B_ABST
Patent Text Reader

Abstract

The present disclosure belongs to the field of computer technology, and relates to a code processing method, an apparatus, a storage medium, and an electronic device. The method includes: performing code weaving on multiple segments of functional code to obtain a target class, and performing parsing processing on the target class to obtain a target interface corresponding to the target class; creating an empty class, and claiming that the empty class implements the target interface; using the target class to inherit the empty class to prompt the call relationship between target classes. The present disclosure can realize the intelligent prompting function of the weaving design pattern during code writing by using the inheritance of the target class from the empty class, getting rid of the cumbersome process of manually consulting the methods of different classes and then making calls in the previous design process, saving labor costs and time costs, improving the efficiency of code writing and design. The way of prompting the call relationship between target classes has very low invasiveness, does not bring a burden on processing performance, and can be supported by all dynamic programming languages, making it easier to implement and apply, enriching the application scenarios of the intelligent prompting function.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of computer technologies, and in particular, to a code processing method, a code processing device, a computer-readable storage medium, and an electronic device. Background Art

[0002] In object-oriented languages, in order to reuse methods between classes, inheritance is often used for reuse. However, in reality, it is desired that methods can be plugged into classes as needed like individual components. And the relationship between classes is not necessarily inheritance. The aspect weaving design pattern is used to solve this problem.

[0003] In most languages, the aspect weaving pattern will implement the methods of class A and class B separately, and then assign the methods of class B to class A one by one at runtime to enable class A to call the methods of class B. However, the biggest problem with the existing aspect weaving design pattern is that the correlation between class A and class B cannot be known during compilation, making it impossible to obtain intelligent prompts when writing code.

[0004] In view of this, there is an urgent need in the art to develop a new code processing method and device.

[0005] It should be noted that the information disclosed in the above background art section is only used to enhance the understanding of the background of the present disclosure, and thus may include information that does not constitute the prior art known to those of ordinary skill in the art. Summary of the Invention

[0006] The purpose of the present disclosure is to provide a code processing method, a code processing device, a computer-readable storage medium, and an electronic device, so as to at least to some extent overcome the technical problems of being unable to know the code correlation and unable to obtain intelligent prompts due to the limitations of related technologies.

[0007] Other features and advantages of the present disclosure will become apparent through the following detailed description, or will be partially learned through the practice of the present disclosure.

[0008] According to the first aspect of the embodiments of the present invention, a code processing method is provided, and the method includes:

[0009] Perform code weaving on multiple segments of functional code to obtain a target class, and perform parsing processing on the target class to obtain a target interface corresponding to the target class;

[0010] Create an empty class, and claim that the empty class implements the target interface;

[0011] Use the target class to inherit from the empty class to prompt the call relationship between the target classes.

[0012] In an exemplary embodiment of the present invention, the obtaining of the target class by weaving code into multiple segments of functional code includes:

[0013] Running multiple segments of functional code and weaving code into the multiple segments of functional code to obtain a target class.

[0014] In an exemplary embodiment of the present invention, the obtaining of the target class by weaving code into the multiple segments of functional code includes:

[0015] Determining target functional code and other functional code other than the target functional code in the multiple segments of functional code;

[0016] Weaving the other functional code into the target functional code to obtain a target class.

[0017] In an exemplary embodiment of the present invention, the parsing and processing of the target class to obtain a target interface corresponding to the target class includes:

[0018] Using reflection technology to parse and process the target class to obtain a target interface corresponding to the target class.

[0019] In an exemplary embodiment of the present invention, the claiming that the empty class implements the target interface includes:

[0020] If the multiple segments of functional code are in a first language, using a target file corresponding to the first language to claim that the empty class implements the target interface.

[0021] In an exemplary embodiment of the present invention, the first language includes: python, and the target file includes: pyi file.

[0022] In an exemplary embodiment of the present invention, the claiming that the empty class implements the target interface includes:

[0023] If the multiple segments of functional code are in a second language, using a target keyword corresponding to the second language to claim that the empty class implements the target interface.

[0024] In an exemplary embodiment of the present invention, the second language includes: TypeScript, and the target keyword includes: implements.

[0025] According to a second aspect of the embodiments of the present invention, there is provided a code processing apparatus, including:

[0026] A code weaving module configured to weave code into multiple segments of functional code to obtain a target class and parse and process the target class to obtain a target interface corresponding to the target class;

[0027] An empty class claiming module, configured to create an empty class and claim that the empty class implements the target interface;

[0028] A relationship prompting module, configured to inherit the empty class with the target class to prompt the call relationship between the target classes.

[0029] In an exemplary embodiment of the present invention, the obtaining the target class by code weaving the multi-segment function code includes:

[0030] Running the multi-segment function code and performing code weaving on the multi-segment function code to obtain the target class.

[0031] In an exemplary embodiment of the present invention, the obtaining the target class by code weaving the multi-segment function code includes:

[0032] Determining target function code and other function code except the target function code in the multi-segment function code;

[0033] Weaving the other function code into the target function code to obtain the target class.

[0034] In an exemplary embodiment of the present invention, the parsing the target class to obtain the target interface corresponding to the target class includes:

[0035] Using reflection technology to parse the target class to obtain the target interface corresponding to the target class.

[0036] In an exemplary embodiment of the present invention, the claiming that the empty class implements the target interface includes:

[0037] If the multi-segment function code is the first language, claiming that the empty class implements the target interface by using the target file corresponding to the first language.

[0038] In an exemplary embodiment of the present invention, the first language includes: python, and the target file includes: pyi file.

[0039] In an exemplary embodiment of the present invention, the claiming that the empty class implements the target interface includes:

[0040] If the multi-segment function code is the second language, claiming that the empty class implements the target interface by using the target keyword corresponding to the second language.

[0041] In an exemplary embodiment of the present invention, the second language includes: TypeScript, and the target keyword includes: implements.

[0042] According to a third aspect of an embodiment of the present invention, an electronic device is provided, including: a processor and a memory; wherein, computer-readable instructions are stored on the memory, and when the computer-readable instructions are executed by the processor, the code processing method in any of the above exemplary embodiments is implemented.

[0043] According to a fourth aspect of an embodiment of the present invention, a computer-readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the code processing method in any of the above exemplary embodiments is implemented.

[0044] As can be seen from the above technical solutions, the code processing method, code processing device, computer storage medium, and electronic device in the exemplary embodiments of the present disclosure at least have the following advantages and positive effects:

[0045] In the method and device provided in the exemplary embodiments of the present disclosure, by using the inheritance of a target class from an empty class, the intelligent prompting function of the aspect design pattern during code writing can be realized, getting rid of the cumbersome process of manually consulting the methods of different classes and then making calls in the previous design process, saving labor costs and time costs, and improving the efficiency of code writing and design. Further, the method of prompting the call relationship between target classes has very low invasiveness, does not bring a burden on processing performance, and can be supported by all dynamic programming languages, making it easier to implement and apply, and enriching the application scenarios of the intelligent prompting function.

[0046] It should be understood that the above general description and the following detailed description are only exemplary and explanatory, and cannot limit the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS

[0047] The accompanying drawings herein are incorporated into the specification and constitute a part of the specification, showing embodiments consistent with the present disclosure, and are used together with the specification to explain the principles of the present disclosure. Obviously, the accompanying drawings in the following description are only some embodiments of the present disclosure, and those of ordinary skill in the art can obtain other drawings based on these drawings without creative efforts.

[0048] Figure 1 A schematic flowchart showing a code processing method in an exemplary embodiment of the present disclosure;

[0049] Figure 2 A schematic flowchart showing a method of aspect weaving in an exemplary embodiment of the present disclosure;

[0050] Figure 3 A schematic flowchart showing a method of obtaining a target class through aspect weaving in an exemplary embodiment of the present disclosure;

[0051] Figure 4Schematically shows a flowchart of a method for parsing a target class to obtain a target interface in an exemplary embodiment of the present disclosure;

[0052] Figure 5 Schematically shows a flowchart of a method for claiming that an empty class implements a target interface in an exemplary embodiment of the present disclosure;

[0053] Figure 6 Schematically shows a flowchart of a method for prompting a call relationship between target classes in an exemplary embodiment of the present disclosure;

[0054] Figure 7 Schematically shows a structural diagram of a code processing device in an exemplary embodiment of the present disclosure;

[0055] Figure 8 Schematically shows an electronic device for implementing a code processing method in an exemplary embodiment of the present disclosure;

[0056] Figure 9 Schematically shows a computer-readable storage medium for implementing a code processing method in an exemplary embodiment of the present disclosure. Detailed implementation manners

[0057] Example embodiments will now be described more fully with reference to the accompanying drawings. However, the example embodiments can be implemented in various forms and should not be construed as limited to the examples set forth herein; rather, these embodiments are provided so that this disclosure will be more complete and comprehensive, and will fully convey the concept of the example embodiments to those skilled in the art. The described features, structures, or characteristics can be combined in any suitable manner in one or more embodiments. In the following description, numerous specific details are provided to give a thorough understanding of the embodiments of the present disclosure. However, those skilled in the art will realize that the technical solutions of the present disclosure can be practiced without one or more of the specific details, or other methods, components, devices, steps, etc. can be adopted. In other cases, well-known technical solutions are not shown or described in detail to avoid obscuring the various aspects of the present disclosure.

[0058] As used in this specification, the terms "a", "an", "the", and "said" are used to denote the presence of one or more elements / components / etc.; the terms "comprising" and "having" are used to mean an open inclusion and mean that there may be additional elements / components / etc. in addition to the listed elements / components / etc.; the terms "first" and "second", etc. are used only as labels and are not a limitation on the quantity of their objects.

[0059] In addition, the accompanying drawings are only schematic illustrations of the present disclosure and are not necessarily drawn to scale. The same reference numerals in the drawings denote the same or similar parts, and thus repeated descriptions thereof will be omitted. Some of the block diagrams shown in the drawings are functional entities and do not necessarily correspond to physically or logically independent entities.

[0060] In object-oriented languages, in order to reuse methods between classes, inheritance is often used for reuse. However, in reality, it is desired that methods can be plugged into classes as needed like individual components. And the relationship between classes is not necessarily an inheritance relationship. The weaving design pattern is used to solve this problem.

[0061] The weaving pattern will separately implement the methods of class A and class B in most languages, and then assign the methods of class B to class A one by one at runtime to enable class A to call the methods of class B. However, the biggest problem with the existing weaving design pattern is that the correlation between class A and class B cannot be known at compile time, making it impossible to obtain intelligent prompts when writing code.

[0062] For example, in a game application, each avatar often has many different functions, such as Mail, Battle, and Bag functions.

[0063] Among them, the various different functions are not completely separated. For example, the send_mail method may need to call call_client_action of Avatar to notify the client to perform certain actions, and sending an email may consume items, and thus it is necessary to call on_item_change in the bag to notify the client of the change of items.

[0064] However, since the weaving method separates the classes, when writing code in the Mail class, it is impossible to know that the Mail class can actually call call_client_action, let alone know that there are other classes in the class, such as the on_item_change method of the Bag class.

[0065] Furthermore, most languages will also prompt that the called function does not exist through a Warning, such as calling call_client_action in send_mail will prompt that the method does not exist. However, it is impossible to prompt the call relationship between classes, and all language writing ignores this serious problem.

[0066] In view of the problems existing in the related art, the present disclosure proposes a code processing method. Figure 1 The flowchart of the code processing method is shown as Figure 1As shown in the figure, the code processing method at least includes the following steps:

[0067] Step S110. Perform code weaving on multiple segments of functional code to obtain a target class, and perform parsing processing on the target class to obtain a target interface corresponding to the target class.

[0068] Step S120. Create an empty class, and claim that the empty class implements the target interface.

[0069] Step S130. Use the target class to inherit from the empty class to prompt the call relationship between target classes.

[0070] In an exemplary embodiment of the present disclosure, by using the inheritance of the target class from the empty class, the intelligent prompting function of the weaving design pattern during code writing can be realized, getting rid of the cumbersome process of manually consulting the methods of different classes and then making calls in the previous design process, saving labor costs and time costs, and improving the efficiency of code writing and design. Further, the way of prompting the call relationship between target classes has very low invasiveness, does not bring a burden on processing performance, and can be supported by all dynamic programming languages, making it easier to implement and apply, and enriching the application scenarios of the intelligent prompting function.

[0071] The following will explain each step of the code processing method in detail.

[0072] In step S110, perform code weaving on multiple segments of functional code to obtain a target class, and perform parsing processing on the target class to obtain a target interface corresponding to the target class.

[0073] In an exemplary embodiment of the present disclosure, the multiple segments of functional code may be program code for implementing multiple functions.

[0074] For example, in a game application, each character often has many different functions, such as functions for mail, combat, and backpack. Therefore, the multiple segments of functional code may be code for implementing characters, mail, combat, and backpack.

[0075] To obtain the target class according to the multiple segments of functional code, code weaving can be used.

[0076] In an optional embodiment, run the multiple segments of functional code, and perform code weaving on the multiple segments of functional code to obtain a target class.

[0077] The running of the multiple segments of functional code can be implemented according to the logic of running normal program code.

[0078] Further, the target class can be obtained by using code weaving.

[0079] Mix-in is a design pattern in object-oriented languages that allows the methods of one class to be used by other classes without those other classes having to inherit from it.

[0080] Therefore, a mix-in is a small class that only defines a set of additional methods that other classes might need, without defining its own instance attributes. Additionally, it does not require users to call its _init_ constructor.

[0081] Correspondingly, the key points of mix-in components are: if the effect can be achieved with mix-in components, do not use multiple inheritance; implement each function as a pluggable mix-in component, and then let the relevant classes inherit the components they need to customize the behavior that the class instances should have; encapsulate simple behaviors into mix-in components, and then complex behaviors can be combined from multiple mix-ins.

[0082] In an alternative embodiment, Figure 2 a flowchart showing the method of code weaving is presented, as Figure 2 shown. The method at least includes the following steps: In step S210, the target function code and other function codes except the target function code are determined among multiple segments of function codes.

[0083] For a game application, the function code corresponding to the character function can be the target function code, and the function codes corresponding to emails, battles, backpacks, etc. related to the character function can be other function codes.

[0084] In step S220, the other function codes are woven into the target function code to obtain the target class.

[0085] For functions such as emails, battles, and backpacks that each character has, the function codes for emails, battles, and backpacks can be woven into the character function code to obtain the finally woven runtime class, that is, the target class.

[0086] Figure 3 A flowchart showing the method of obtaining the target class through code weaving is presented, as Figure 3 shown. For the email, battle, and backpack functions that each character has in a game application, in order to organize the logic according to different functions, different methods can be written in the corresponding classes, and finally the Avatar can be obtained through code weaving.

[0087] Among them, the various different functions are not completely separated. For example, the send_mail method may need to call Avatar's call_client_action to notify the client to perform certain actions, and sending an email may consume items, and thus it is necessary to call on_item_change in the backpack to notify the client of the item change.

[0088] After obtaining the target class corresponding to the multi-segment function code, the target class can be parsed to obtain the target interface.

[0089] In an alternative embodiment, reflection technology is used to parse the target class to obtain the target interface corresponding to the target class.

[0090] When the function code is implemented in a language such as Java (a computer programming language), reflection technology can be used to parse the target class.

[0091] The core of the Java reflection mechanism is to dynamically load classes and obtain detailed information about the classes at runtime, so as to operate on the attributes and methods of the classes or objects. In essence, after the JVM (Java Virtual Machine) obtains the class (compiled executable file such as class or interface) object, it performs decompilation through the class object to obtain various information of the object.

[0092] Java is a language that compiles first and then runs. The types of objects in the program are determined at compile time, and when the program is running, some classes may need to be dynamically loaded. Since these classes were not needed before, they were not loaded into the JVM.

[0093] Through reflection, objects can be dynamically created and their attributes can be called at runtime, without having to know in advance at compile time which object will be run.

[0094] Using reflection technology to obtain various contents of a class at runtime and perform decompilation, for languages such as Java that compile first and then run, it is very convenient to create flexible code.

[0095] These codes can be assembled at runtime without the need to link source codes between components, making it easier to implement object orientation.

[0096] Therefore, using reflection technology can obtain the target interface corresponding to the target class. The target interface contains the parameters and return values of the methods of the target class without specific implementations.

[0097] Figure 4 A flowchart showing the method of parsing the target class to obtain the target interface is as follows Figure 4As shown, at runtime, the class of Avarar includes methods such as call_client_action, send_mail, start_battle_success, and on_item_change. After parsing the target class using reflection technology, it can be obtained that the method interfaces of Avarar can also include methods such as call_client_action, send_mail, start_battle_success, and on_item_change.

[0098] Specifically, call_client_action is a method for sending character data or information, send_mail is a method for sending emails, start_battle_success is a method for starting a battle, and on_item_change is a method for changing a character's items.

[0099] In step S120, an empty class is created, and it is claimed that the empty class implements the target interface.

[0100] In an exemplary embodiment of the present disclosure, generally speaking, dynamic languages separate interfaces from implementations, so an empty class can be created.

[0101] Among them, dynamic-typed languages are generally scripting languages, such as Perl, Ruby, Python, PHP, JavaScript, etc.

[0102] Scripting languages are computer programming languages created to shorten the traditional edit-compile-link-run process. Although many scripting languages have gone beyond the field of simple computer task automation and are mature enough to write sophisticated programs, they are still called scripts.

[0103] There is a scripting language at almost every level of all computer systems. This includes the operating system level, such as computer games, web applications, word processing documents, network software, etc. In many aspects, high-level programming languages and scripting languages intersect with each other, and there is no clear boundary between the two. A script can automate interactive operations that would otherwise be performed using a keyboard.

[0104] A Shell script is mainly composed of commands that would originally be entered at the command line. Or in a text editor, users can use scripts to combine some common operations into a sequence. The language mainly used to write such scripts is called a scripting language. Many scripting languages actually go beyond simple user command sequences and can also write more complex programs.

[0105] After creating an empty class, it can be claimed that the empty class implements the target interface.

[0106] In an alternative embodiment, if the multi-segment functional code is in a first language, use the target file corresponding to the first language to claim that the empty class implements the target interface.

[0107] When the functional code is implemented in a first language, the corresponding target file can be used to claim that the empty class implements the target interface.

[0108] In an alternative embodiment, the first language includes: python, and the target file includes: pyi file.

[0109] In the python language, the PEP 484 document provides a temporary module (i.e., a stub file) to supplement some places where the current annotations are not clearly defined.

[0110] The overall purpose of PEP 484 is to help users perform type checking.

[0111] Python itself is a dynamic language and cannot perform type checking at compile time like a static language. Therefore, PEP 484 can assist users in giving suggested type hints when writing code through such stub files and annotations. This can not only enable faster development but also reduce type errors at runtime.

[0112] Therefore, through the pyi file of the PEP 484 document, the empty class can be declared to indicate that the target interface exists in the empty class to implement the target interface.

[0113] In an alternative embodiment, if the multi-segment functional code is in a second language, use the target keyword corresponding to the second language to claim that the empty class implements the target interface.

[0114] When the functional code is implemented in a second language, the corresponding target keyword can be used to claim that the empty class implements the target interface.

[0115] In an alternative embodiment, the second language includes: TypeScript, and the target keyword includes: implements.

[0116] In the TypeScript (a language for application-level JavaScript) language, implements (implement) is a new class that implements all properties and methods from a parent class or interface. At the same time, properties and methods can be overridden, including some new functions.

[0117] A class can declare itself to use one or more interfaces through the keyword implements.

[0118] Therefore, using "implements" as the target keyword enables claiming that the created empty class implements the target interface.

[0119] Figure 5 A flowchart showing the method of claiming that an empty class implements a target interface is shown, as Figure 5 shown, the empty class of the created Avatar is Avatar Interface Object, and it is claimed through a pyi file or the "implements" keyword that this empty class implements the method interface of Avatar. However, claiming that this empty class implements the method interface of Avatar does not mean that this empty class truly implements the corresponding method interface.

[0120] It should be noted that when multiple segments of functional code are implemented in a language other than the first language or the second language, the claiming method of the corresponding language can also be used to achieve the effect of generating an empty class to implement the target interface, and this exemplary embodiment does not make special limitations on this.

[0121] In step S130, use the target class to inherit the empty class to prompt the call relationship between the target classes.

[0122] In the exemplary embodiment of the present disclosure, inheritance is the second major feature of object-oriented languages.

[0123] Inheritance is one of the most prominent features of object orientation. Inheritance is to derive a new class from an existing class, and the new class can absorb the data attributes and behaviors of the existing class and can expand new capabilities.

[0124] Therefore, using the target class to inherit the empty class can determine that there is an association between multiple segments of target code through inheritance. Then, it can be obtained that the target classes can call each other according to requirements, thereby prompting the specific call relationship.

[0125] Figure 6 A flowchart showing the method of prompting the call relationship between the target classes is shown, as Figure 6 shown, use the target classes corresponding to Mail, Battle, and Bag to integrate the empty class Avatar Interface Object, that is, to associate Mail, Battle, and Bag with Avatar. After that, the target classes of Mail, Battle, and Bag woven into Avatar can know that it can call methods such as call_client_action or send_mail, thus realizing the function of intelligent prompting for the target classes of Mail, Battle, and Bag.

[0126] In the code processing method of the exemplary embodiment of the present disclosure, by using the inheritance of a target class from an empty class, the intelligent prompting function of the weaving design pattern during code writing can be realized, getting rid of the cumbersome process of manually looking up the methods of different classes and then making calls in the previous design process, saving labor costs and time costs, and improving the efficiency of code writing and design. Further, the method of prompting the call relationship between target classes has very low invasiveness, does not bring a burden on processing performance, and can be supported by all dynamic programming languages, making it easier to implement and apply, and enriching the application scenarios of the intelligent prompting function.

[0127] In addition, in the exemplary embodiment of the present disclosure, a code processing device is also provided. Figure 7 The structural schematic diagram of the code processing device is shown, as Figure 7 shown, the code processing device 700 may include: a code weaving module 710, an empty class claiming module 720, and a relationship prompting module 730. Among them:

[0128] The code weaving module 710 is configured to perform code weaving on multiple segments of functional code to obtain a target class, and perform parsing processing on the target class to obtain a target interface corresponding to the target class;

[0129] The empty class claiming module 720 is configured to create an empty class and claim that the empty class implements the target interface;

[0130] The relationship prompting module 730 is configured to inherit the empty class by using the target class to prompt the call relationship between the target classes.

[0131] In an exemplary embodiment of the present invention, the performing code weaving on multiple segments of functional code to obtain a target class includes:

[0132] Running multiple segments of functional code and performing code weaving on the multiple segments of functional code to obtain a target class.

[0133] In an exemplary embodiment of the present invention, the performing code weaving on the multiple segments of functional code to obtain a target class includes:

[0134] Determining target functional code and other functional code except the target functional code in the multiple segments of functional code;

[0135] Weaving the other functional code into the target functional code to obtain a target class.

[0136] In an exemplary embodiment of the present invention, the performing parsing processing on the target class to obtain a target interface corresponding to the target class includes:

[0137] The target class is parsed using reflection technology to obtain a target interface corresponding to the target class.

[0138] In an exemplary embodiment of the present invention, the claim that the empty class implements the target interface includes:

[0139] If the multi-segment function code is in the first language, use the target file corresponding to the first language to claim that the empty class implements the target interface.

[0140] In an exemplary embodiment of the present invention, the first language includes: python, and the target file includes: pyi file.

[0141] In an exemplary embodiment of the present invention, the claim that the empty class implements the target interface includes:

[0142] If the multi-segment function code is in the second language, use the target keyword corresponding to the second language to claim that the empty class implements the target interface.

[0143] In an exemplary embodiment of the present invention, the second language includes: TypeScript, and the target keyword includes: implements.

[0144] The specific details of the above code processing device 700 have been described in detail in the corresponding code processing method, so they will not be repeated here.

[0145] It should be noted that although several modules or units of the code processing device 700 are mentioned in the above detailed description, this division is not mandatory. In fact, according to the embodiments of the present disclosure, the features and functions of the two or more modules or units described above can be embodied in one module or unit. Conversely, the features and functions of one module or unit described above can be further divided into multiple modules or units for embodiment.

[0146] In addition, in an exemplary embodiment of the present disclosure, an electronic device capable of implementing the above method is also provided.

[0147] Next, refer to Figure 8 to describe the electronic device 800 according to this embodiment of the present invention. Figure 8 The electronic device 800 shown is only an example and should not impose any limitations on the functions and usage scope of the embodiments of the present invention.

[0148] Such as Figure 8As shown, the electronic device 800 is presented in the form of a general-purpose computing device. The components of the electronic device 800 may include, but are not limited to: at least one of the above-mentioned processing units 810, at least one of the above-mentioned storage units 820, a bus 830 connecting different system components (including the storage unit 820 and the processing unit 810), and a display unit 840.

[0149] Among them, the storage unit stores program code, and the program code can be executed by the processing unit 810, so that the processing unit 810 executes the steps according to various exemplary embodiments of the present invention described in the "Exemplary Method" section of the present specification.

[0150] The storage unit 820 may include a readable medium in the form of a volatile storage unit, such as a random access storage unit (RAM) 821 and / or a cache storage unit 822, and may further include a read-only storage unit (ROM) 823.

[0151] The storage unit 820 may also include a program / utility 824 having a set (at least one) of program modules 825. Such program modules 825 include, but are not limited to: an operating system, one or more application programs, other program modules, and program data. Each or some combination of these examples may include the implementation of a network environment.

[0152] The bus 830 may represent one or more of several types of bus structures, including a storage unit bus or a storage unit controller, a peripheral bus, a graphics acceleration port, a processing unit, or a local bus using any bus structure in a variety of bus structures.

[0153] The electronic device 800 can also communicate with one or more external devices 1000 (such as a keyboard, a pointing device, a Bluetooth device, etc.), and can also communicate with one or more devices that enable a user to interact with the electronic device 800, and / or communicate with any device that enables the electronic device 800 to communicate with one or more other computing devices (such as a router, a modem, etc.). Such communication can be carried out through an input / output (I / O) interface 850. And, the electronic device 800 can also communicate with one or more networks (such as a local area network (LAN), a wide area network (WAN), and / or a public network, such as the Internet) through a network adapter 860. As shown in the figure, the network adapter 860 communicates with other modules of the electronic device 800 through the bus 830. It should be understood that although not shown in the figure, other hardware and / or software modules can be used in combination with the electronic device 800, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems, etc.

[0154] Through the description of the above embodiments, those skilled in the art can easily understand that the exemplary embodiments described herein can be implemented by software or by a combination of software and necessary hardware. Therefore, the technical solutions according to the embodiments of the present disclosure can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a portable hard disk, etc.) or on a network, and includes several instructions to enable a computing device (which can be a personal computer, a server, a terminal device, or a network device, etc.) to execute the method according to the embodiments of the present disclosure.

[0155] In an exemplary embodiment of the present disclosure, there is also provided a computer-readable storage medium, on which a program product capable of implementing the above method of this specification is stored. In some possible embodiments, various aspects of the present invention can also be implemented in the form of a program product, which includes program code. When the program product runs on a terminal device, the program code is used to cause the terminal device to execute the steps according to various exemplary embodiments of the present invention described in the above "Exemplary Method" section of this specification.

[0156] Refer to Figure 9 As shown, a program product 900 for implementing the above method according to an embodiment of the present invention is described, which can adopt a portable compact disc read-only memory (CD-ROM) and includes program code, and can run on a terminal device, such as a personal computer. However, the program product of the present invention is not limited thereto. In this document, the readable storage medium can be any tangible medium that contains or stores a program, and the program can be used by or in combination with an instruction execution system, apparatus, or device.

[0157] The program product can adopt any combination of one or more readable media. The readable media can be a readable signal medium or a readable storage medium. The readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the above. More specific examples (non-exhaustive list) of the readable storage medium include: an electrical connection with one or more wires, a portable disk, 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 above.

[0158] A computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, in which readable program code is carried. Such a propagated data signal may take many forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the foregoing. The readable signal medium may also be any readable medium other than a readable storage medium, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device.

[0159] The program code contained on the readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wired, optical fiber cable, RF, etc., or any suitable combination of the foregoing.

[0160] The program code for performing the operations of the present invention may be written in any combination of one or more programming languages, including object-oriented programming languages such as Java, C++, etc., and also including conventional procedural programming languages such as the "C" language or similar programming languages. The program code may be executed entirely on the user's computing device, partially on the user's device, executed as a stand-alone software package, partially on the user's computing device and partially on a remote computing device, or entirely on the remote computing device or server. In the case of a remote computing device, the remote computing device may be connected to the user's computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computing device (e.g., by using an Internet service provider to connect through the Internet).

[0161] Other embodiments of the present disclosure will be readily apparent to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of the present disclosure that follow the general principles of the present disclosure and include known common knowledge or conventional technical means in the technical field not disclosed herein. The specification and embodiments are to be considered exemplary only, and the true scope and spirit of the present disclosure are pointed out by the claims.

Claims

1. A code processing method, characterized in that, The method includes: Performing code weaving on multiple segments of functional code to obtain a target class, and performing parsing processing on the target class to obtain a target interface corresponding to the target class; Creating an empty class and claiming that the empty class implements the target interface; Using the classes woven into the target class to inherit the empty class to prompt the call relationship between the target class and the woven classes.

2. The code processing method according to claim 1, wherein The performing code weaving on multiple segments of functional code to obtain a target class includes: Running multiple segments of functional code and performing code weaving on the multiple segments of functional code to obtain a target class.

3. The code processing method according to claim 2, wherein The performing code weaving on the multiple segments of functional code to obtain a target class includes: Determining target functional code and other functional code except the target functional code in the multiple segments of functional code; Weaving the other functional code into the target functional code to obtain a target class.

4. The code processing method according to claim 1, characterized in that The performing parsing processing on the target class to obtain a target interface corresponding to the target class includes: Using reflection technology to perform parsing processing on the target class to obtain a target interface corresponding to the target class.

5. The code processing method according to claim 1, characterized in that, The claiming that the empty class implements the target interface includes: If the multiple segments of functional code are in a first language, using a target file corresponding to the first language to claim that the empty class implements the target interface.

6. The code processing method according to claim 5, wherein The first language includes: python, and the target file includes: pyi file.

7. The code processing method according to claim 1, wherein The claiming that the empty class implements the target interface includes: If the multiple segments of functional code are in a second language, using a target keyword corresponding to the second language to claim that the empty class implements the target interface.

8. The code processing method according to claim 7, characterized in that The second language includes: TypeScript, and the target keyword includes: implements.

9. A code processing device, characterized in that, Includes: A code weaving module configured to perform code weaving on multiple segments of functional code to obtain a target class, and perform parsing processing on the target class to obtain a target interface corresponding to the target class; An empty class claiming module configured to create an empty class and claim that the empty class implements the target interface; A relationship prompting module configured to use the classes woven into the target class to inherit the empty class to prompt the call relationship between the target class and the woven classes.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the code processing method described in any one of claims 1-8.

11. An electronic device, characterized in that, Includes: A processor; A memory for storing executable instructions of the processor; Wherein, the processor is configured to execute the code processing method described in any one of claims 1-8 by executing the executable instructions.

Citation Information

Patent Citations

  • Code calling method and device, terminal and storage medium

    CN110764748A

  • Software development kit SDK access method, device and system

    CN111638906A

Cited By

  • Code weaving method for multi-model co-simulation

    CN120491965A