Object conversion method and system, electronic equipment and storage medium

By generating abstract syntax trees and listening to target operation instructions, the object conversion code is automatically generated, which solves the problems of cumbersome, error-prone and low performance in Java software development, and efficient and easy-to-maintain code generation is achieved, which significantly improves development efficiency.

CN119861914APending Publication Date: 2025-04-22INNOVATION CENTER OF YANGTZE RIVER DELTA ZHEJIANG UNIVERSITY
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411924722.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-25
Publication Date
2025-04-22

AI Technical Summary

Technical Problem

The prior art is cumbersome and time-consuming in the object conversion process in Java software development, prone to errors, and has low performance, especially in business scenarios where object conversion is frequent.

Method used

Generate an abstract syntax tree by obtaining the source code of the project, listen to target operation instructions in the integrated development environment, extract attribute information of the source object and the target object, and automatically generate conversion code based on preset matching rules.

Benefits of technology

It realizes automatic generation of class conversion code, avoids the cumbersome and error-prone problems of manual encoding, improves the readability and maintenance of the code, significantly improves the overall efficiency of software development, and has better performance than solutions such as dependency reflection mechanisms.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119861914A_ABST
    Figure CN119861914A_ABST
Patent Text Reader

Abstract

The invention provides an object conversion method and system, electronic equipment and a storage medium, and the method comprises the steps: obtaining a source code of a project, and generating an abstract syntax tree of the project based on the source code; monitoring a target operation instruction in the integrated development environment, wherein the target operation instruction comprises a source object and a target object; obtaining attribute information of the source object and the target object from the abstract syntax tree; and generating a conversion code in an implementation class according to the attribute information of the source object and the target object and a preset matching rule.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of computer technology, and in particular to an object conversion method, system, electronic device and storage medium. Background Art

[0002] In Java software development, in order to improve the maintainability and scalability of the system, layered architecture design is widely used, including the Controller layer, Service layer, and DAO layer. In this architecture, for the same business object, classes with different responsibilities need to be used at different levels, such as Persistent Object (PO), View Object (VO), and Data Transfer Object (DTO). Although these classes have similar underlying grammatical structures, they each have different responsibilities, so conversions between them are often required.

[0003] However, there are some problems with existing object conversion methods. For example, it is not only tedious and time-consuming for programmers to convert code by hand, but also prone to errors. At the same time, a large amount of manual conversion code will also reduce the readability and maintainability of the code. Alternatively, although the use of mapping tools, serialization + deserialization and other conversion methods can reduce some manual coding, they rely on the reflection mechanism at runtime and have low performance. Especially in business scenarios with frequent object conversions, performance bottlenecks become more prominent. Summary of the invention

[0004] The present disclosure provides an object conversion method, system, electronic device and storage medium to at least solve the above technical problems existing in the prior art.

[0005] According to a first aspect of the present disclosure, there is provided an object conversion method, the method comprising:

[0006] Obtaining source code of a project, and generating an abstract syntax tree of the project based on the source code;

[0007] In an integrated development environment, a target operation instruction is monitored, wherein the target operation instruction includes a source object and a target object;

[0008] Acquire attribute information of the source object and the target object from the abstract syntax tree;

[0009] According to the attribute information of the source object and the target object and the preset matching rules, a conversion code is generated in the implementation class.

[0010] In one possible implementation, generating an abstract syntax tree of the project based on the source code includes:

[0011] According to the source code, parsing the project structure of the project;

[0012] Each class in the project structure is analyzed, and an abstract syntax tree of the class is generated and stored in a database.

[0013] In one possible implementation, monitoring the target operation instruction in the integrated development environment includes:

[0014] The user operation is monitored in the integrated development environment, and when one of the following user operations is monitored in the integrated development environment, code conversion prompt information is fed back:

[0015] Copy a class file to another class file;

[0016] Use code generators to generate multiple classes for the same object;

[0017] Write conversion methods for classes that contain multiple properties with the same name;

[0018] Create a new POJO class with more than three attributes, and traverse the entire project to find other classes with similar class names and attribute names and convertible types;

[0019] Receive the code conversion operation instruction from the user and obtain the target operation instruction.

[0020] In one possible implementation, monitoring the target operation instruction in the integrated development environment further includes:

[0021] The user's selection instructions and code conversion operation instructions for two class files in the integrated development environment are received to obtain the target operation instructions.

[0022] In one possible implementation, when the attribute information of the source object and the target object meets one of the preset matching rules, a conversion code is generated in the implementation class;

[0023] The preset matching rules include:

[0024] The types of the attribute information of the source object and the target object match;

[0025] Matching of basic type and packaging type in the attribute information of the source object and the target object;

[0026] The class of the attribute information of the target object is the parent class of the attribute information of the source object;

[0027] The attribute information of the source object and the target object are both of set type, and the element types in the set can be converted;

[0028] The source object and the target object both contain nested objects, and the attribute names and types of the nested objects match.

[0029] In one possible implementation, when the attribute information of the source object and the target object does not conform to a preset matching rule, the generating of the conversion code in the implementation class includes:

[0030] Generate and feedback manual matching prompt information;

[0031] In response to the user's matching operation instruction, the conversion code is generated in the implementation class.

[0032] In one embodiment, the method further comprises:

[0033] A conversion method is generated according to the conversion code and the class conversion relationship set, and the conversion method is configured as a template; the class conversion relationship set is a plurality of combined conversion relationships based on the conversion code.

[0034] According to a second aspect of the present disclosure, there is provided an object conversion system, the system comprising:

[0035] A processing unit, configured to obtain source code of a project and generate an abstract syntax tree of the project based on the source code;

[0036] A monitoring unit, used for monitoring a target operation instruction in an integrated development environment, wherein the target operation instruction includes a source object and a target object;

[0037] An acquisition unit, configured to acquire attribute information of the source object and the target object from the abstract syntax tree;

[0038] The generation unit is used to generate conversion code in the implementation class according to the attribute information of the source object and the target object and the preset matching rules.

[0039] According to a third aspect of the present disclosure, there is provided an electronic device, including:

[0040] at least one processor; and

[0041] a memory communicatively connected to the at least one processor; wherein,

[0042] The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method described in the present disclosure.

[0043] According to a fourth aspect of the present disclosure, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to cause the computer to execute the method described in the present disclosure.

[0044] The object conversion method, system, electronic device and storage medium disclosed in the present invention can be seamlessly integrated into an integrated development environment. An abstract syntax tree is constructed from the source code of the project, and the user's target operation instructions are listened to in the IDE, and the instructions include the source object and the target object; the attribute information of the source object and the target object is extracted from the abstract syntax tree, and the conversion code is automatically generated according to the attribute information of the source object and the target object and the preset matching rules. In this way, by automatically generating class conversion codes, the tedious and error-prone problems of manual coding are avoided. This not only improves the readability and maintainability of the code, but also significantly improves the overall efficiency of software development. In addition, since the implementation class of the conversion code is generated during the compilation stage, it only needs to be compiled once to run multiple times. Therefore, compared with solutions such as relying on reflection mechanisms, CGLIB dynamic proxies, and serialization / deserialization, the performance of the solution disclosed in the present invention is superior.

[0045] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present disclosure, nor is it intended to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS

[0046] The above and other objects, features and advantages of the exemplary embodiments of the present disclosure will become readily understood by reading the detailed description below with reference to the accompanying drawings. In the accompanying drawings, several embodiments of the present disclosure are shown in an exemplary and non-limiting manner, in which:

[0047] In the drawings, the same or corresponding reference numerals represent the same or corresponding parts.

[0048] Figure 1 A schematic diagram of the implementation process of the object conversion method according to the embodiment of the present disclosure is shown;

[0049] Figure 2 A schematic diagram of the implementation process of generating an abstract syntax tree of a project according to an embodiment of the present disclosure is shown;

[0050] Figure 3 A schematic diagram of the implementation process of monitoring target operation instructions according to an embodiment of the present disclosure is shown;

[0051] Figure 4 A schematic diagram of the implementation process of generating conversion codes according to an embodiment of the present disclosure is shown;

[0052] Figure 5 A schematic diagram of the structure of the object conversion system according to an embodiment of the present disclosure is shown;

[0053] Figure 6 A schematic diagram of the structure of an electronic device according to an embodiment of the present disclosure is shown. DETAILED DESCRIPTION

[0054] In order to make the purpose, features, and advantages of the present disclosure more obvious and easy to understand, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings in the embodiments of the present disclosure. Obviously, the described embodiments are only part of the embodiments of the present disclosure, not all of the embodiments. Based on the embodiments in the present disclosure, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present disclosure.

[0055] The present disclosure provides an object conversion method, which can be developed as a plug-in and seamlessly embedded in an integrated development environment (IDE). An integrated development environment is an application used to provide a program development environment. By integrating the method of the present disclosure into a general IDE, object conversion operations can be automatically and intelligently triggered. Specifically, Figure 1 As shown, the method includes:

[0056] Step 101: Obtain the source code of the project, and generate an abstract syntax tree of the project based on the source code.

[0057] In this example, a project is a software project that contains a series of source code files, and source code is a code file written in various programming languages ​​(such as Java). Before the project is compiled, the project's source code is parsed to build the project's Abstract Syntax Tree (AST). The Abstract Syntax Tree is an abstract representation of the project structure, which represents the programming language in a tree-like form, where each node represents an element in the source code (such as a class, method, variable declaration, etc.).

[0058] Step 102: monitoring a target operation instruction in an integrated development environment, where the target operation instruction includes a source object and a target object.

[0059] During the project compilation phase, the user's target operation instructions are captured in real time by setting a listener in the IDE. For example, the API or plug-in interface provided by the IDE is used to monitor various user operations, such as clicks, keyboard input, menu selection, etc. The code conversion operation instruction contains all the necessary information required for object conversion, including the source object and the target object. The source object is the original object that needs to be converted. It can be an instance of a class, a data structure (such as a dictionary, a list), or a variable, which contains the data that needs to be migrated or converted; and the target object is the form that the converted object should have, usually an instance of another class or a data structure, which receives the data converted from the source object.

[0060] Step 103: Obtain attribute information of the source object and the target object from the abstract syntax tree.

[0061] In this example, the AST constructed in step 101 is accessed, and the AST is traversed to find nodes representing source objects and target objects, which can be achieved by algorithms such as depth-first search or breadth-first search (BFS). If a node of a source object or a target object is identified during the traversal process, the attribute information in the node is extracted. The attribute information generally includes the name, type, value, and location of the attribute in the object (such as whether it belongs to a specific class or interface).

[0062] Step 104: Generate conversion code in the implementation class according to the attribute information of the source object and the target object and the preset matching rules.

[0063] In this example, the attributes of the source object and the target object are matched according to the preset matching rules, and the native Java getter and setter methods are used to generate executable conversion code in the implementation class. Specifically, the attribute value is obtained by calling the getter method of the source object, and then the setter method of the target object is called to set the value, and the attribute conversion from the source object to the target object is realized by using the conversion code.

[0064] The present disclosure proposes an object conversion method that can be seamlessly integrated into an integrated development environment. An abstract syntax tree is constructed from the source code of the project, and the user's target operation instructions are listened to in the IDE, and the instructions contain source objects and target objects; the attribute information of the source object and the target object is extracted from the abstract syntax tree, and the conversion code is automatically generated according to the attribute information of the source object and the target object and the preset matching rules. In this way, by automatically generating class conversion codes, the tedious and error-prone problems of manual coding are avoided. This not only improves the readability and maintainability of the code, but also significantly improves the overall efficiency of software development. In addition, since the implementation class of the conversion code is generated during the compilation stage, it only needs to be compiled once and can be run multiple times. Therefore, compared with solutions that rely on reflection mechanisms, CGLIB dynamic proxies, and serialization / deserialization, the performance of the solution disclosed in the present disclosure is superior.

[0065] In one example, an implementation process of generating an abstract syntax tree of a project based on source code, such as Figure 2 As shown, including:

[0066] Step 201: Analyze the project structure of the project according to the source code.

[0067] In this example, check out the project code from the version control system or load the code file from the file system, and use tools or write scripts to parse the structure of the project, such as identifying the location of the source code files, dependencies, and the project's build scripts. In the project structure, identify all files containing source code.

[0068] Step 202: Analyze each class in the project structure, generate an abstract syntax tree of the class and store it in a database.

[0069] In this example, a code analysis tool (such as Eclipse JDT for Java code) is used to parse the file content, including identifying class definitions, method definitions, field definitions, etc. in the file, and converting the source code into an abstract syntax tree. In the present disclosure, each node on the abstract syntax tree represents a class structure in the source code, which can be used for subsequent analysis and object conversion based on the content in the abstract syntax tree.

[0070] In order to facilitate access and operation of the abstract syntax tree, the abstract syntax tree can be serialized and stored in a relational database or file system, or directly stored in the memory system for fast access. At the same time, code analysis tools such as Eclipse JDT provide APIs for accessing and operating the abstract syntax tree.

[0071] In one example, the implementation process of monitoring the target operation instruction in the integrated development environment, such as Figure 3 As shown, including:

[0072] Step 301: Monitor user operations in the integrated development environment, and feedback code conversion prompt information when one of the following user operations is monitored in the integrated development environment: copying a class file to another class file; using a code generator to generate multiple classes from the same object; writing a conversion method for multiple classes with the same attribute names; creating a new POJO class with more than three attributes, and traversing the entire project to find other classes with similar class names and attribute names and convertible types.

[0073] In this example, after the user performs an operation, in the listener callback function, it is determined whether the user intends to convert the object based on the captured event. Specifically,

[0074] When copying a class file to another class file, such as copying a PO class to a VO class, make sure the user has the intention to perform the object conversion. Or,

[0075] When generating multiple classes for the same business object at the same time, such as VO, PO, DTO, etc., by using code generators, etc., make sure that the user has the intention to convert the object. Or,

[0076] When a conversion method is detected that contains multiple classes with the same property name, the getter and setter methods are called for three or more properties with the same name in two classes:

[0077] a.setParam1(b.getParam1());

[0078] a.setParam2(b.getParam2());

[0079] a.setParam3(b.getParam3());

[0080] At this point, it is determined that the user has the intention to convert the object.

[0081] When a user creates a POJO class with more than three attributes, a scan operation of the project is triggered. When other classes with similar names to the class are found, the names of the attributes are highly similar and the types can be automatically converted, it is determined that the user intends to convert the object.

[0082] After the user's intention is confirmed, code conversion prompt information is immediately fed back to the user through the IDE UI interface.

[0083] Step 302: Receive the code conversion operation instruction from the user and obtain the target operation instruction.

[0084] In this example, after receiving the code conversion prompt information in the integrated development environment, the user will decide whether to perform code conversion according to the prompt content. If the user decides to perform the conversion, the code conversion operation is triggered, and the IDE or related plug-ins / tools will generate code conversion operation instructions. The code conversion operation instruction is the target operation instruction, and the corresponding code conversion process is automatically executed by receiving and parsing the code conversion operation instruction.

[0085] In one example, monitoring the target operation instruction in the integrated development environment further includes: receiving a selection instruction and a code conversion operation instruction of two class files from a user in the integrated development environment to obtain the target operation instruction.

[0086] In this example, a configuration command is added to the integrated development environment, and the target operation instruction is obtained by monitoring and receiving the instructions of the two Java class files to be converted selected by the user in the IDE, as well as the code conversion operation instruction. According to the target operation instruction, the corresponding code conversion process is automatically executed.

[0087] In one example, when the attribute information of the source object and the target object meets one of the preset matching rules, the conversion code is generated in the implementation class.

[0088] In the process of object conversion, especially when it comes to attribute mapping from source objects to target objects, in order to ensure the accuracy and efficiency of the conversion, a series of matching rules are preset in this example to automatically match the corresponding attributes in the source object and the target object, thereby reducing the manual work of the programmer. Specifically, the preset matching rules include:

[0089] The types of the attribute information of the source object and the target object match. When the type of an attribute in the source object is exactly the same as or compatible with that of an attribute in the target object, the two attributes are automatically matched. For example, if the age attribute in the source object is of type int, and the age attribute in the target object is of type long, long can hold the value of int, and the two attributes are automatically matched.

[0090] Matching of primitive types and wrapper types in the attribute information of the source and target objects. In Java, primitive types (such as int, char, etc.) have corresponding wrapper types (such as Integer, Character, etc.). If the attribute of the source object is a primitive type and the attribute of the target object is a corresponding wrapper type, or vice versa, the two attributes will also be automatically matched.

[0091] The class of the target object's attribute information is the parent class of the source object's attribute information. If the class of an attribute of the target object is the parent class of the class of an attribute of the source object (or vice versa, but usually the conversion from child class to parent class is considered), then the two attributes are also considered to match. For example, if the child attribute in the source object is the Girl class, and the child attribute in the target object is the Person class, and the Person class is the parent class of the Girl class, then the two are automatically matched.

[0092] The source and target object's attribute information are both of collection type, and the element types in the collection can be converted. When the source and target object's attributes are both of collection type (such as List, Set, etc.), and the element types in these collections can also be converted according to the above rules, the two collection attributes are considered to match. For example, the List <string>Can be automatically mapped to the List in the target object <string>.

[0093] Both the source and target objects contain nested objects, and the attribute names and types of the nested objects match. If both the source and target objects contain nested objects (that is, the attributes of the objects themselves are also objects), and the attribute names and types of these nested objects also meet any of the above rules (type matching, basic type and packaging type matching, inheritance relationship matching, etc.), then these nested objects will also be considered matched. For example, if the source object has an address attribute of type Address, and the target object also has an address attribute of type Address, then the two attributes will automatically match.

[0094] When the attribute information of the source object and the target object meets any of the above preset matching rules, Java native getter and setter methods are used to generate executable conversion code in the implementation class. The conversion code can convert the attribute value of the source object to the corresponding attribute of the target object. In this way, users do not need to manually write these conversion codes, thereby improving development efficiency and code quality.

[0095] In one example, when the attribute information of the source object and the target object does not conform to the preset matching rules, the user needs to be prompted to perform manual matching and generate conversion code in the implementation class, such as Figure 4 As shown, the process includes:

[0096] Step 401: Generate and feedback prompt information for manual matching.

[0097] In this example, all automatically matched attributes are excluded based on the attribute information of the source object and the target object. If there are still attributes with type matching and names that are not exactly the same but similar (can be obtained using the edit distance algorithm), a manual matching prompt message is generated and feedback is given to prompt the programmer whether to perform manual matching.

[0098] Step 402: In response to the user's matching operation instruction, a conversion code is generated in the implementation class.

[0099] In this example, for attributes that cannot be matched automatically, users can manually match and generate corresponding matching operation instructions. For example:

[0100] @Transformer(from="param",to="param1")

[0101] @Transformer(from="param2",to="param2",method="method1")

[0102] AVO toAVO (APO aPO);

[0103] The above Java code defines a conversion relationship toAVO, which is used to convert an APO object into an AVO object. The param attribute of the APO object will be converted to the param1 attribute of the AVO object, and after calling the method1 method on the param2 attribute of the APO object, it will be converted to the param2 attribute of the AVO object.

[0104] By receiving and responding to the user's matching operation instructions, the Java native getter and setter methods are used to generate executable conversion codes in the implementation class.

[0105] In one example, the method further includes: generating a conversion method according to the conversion code and the class conversion relationship set, and configuring the conversion method as a template; the class conversion relationship set is a plurality of combined conversion relationships based on the conversion code.

[0106] Before compiling the project, you can combine and define more complex conversion relationships based on the basic class conversion relationships to obtain a class conversion relationship set. For example, converting an APO class object to an AVO class object is a basic class conversion relationship. By combining and defining (the conversion relationship is represented by the "->" symbol below), you can obtain a complex conversion relationship set, such as: AVO->APO, List <apo>->List <avo>、List <avo>->List <apo>、Set <apo>->Set <avo>、Set <avo>->Set <apo>, Array {AVO}->Array {APO}, Array {APO}->Array {AVO}, Map<K,APO> ->Map<K,AVO> 、Map<K,AVO> ->Map<K,APO> , and so on. The above can be regarded as the conversion relationship set between APO class and AVO class, and the conversion relationship set is saved in the form of configuration file. In addition, users can also choose to save their accustomed conversion relationship set as a template so that they can be quickly applied when needed. At the same time, it can also be applied to other class conversion relationships, such as BPO class and BVO class.

[0107] The conversion code generated in the above example is based on the class conversion relationship. During the project compilation phase, the generated conversion code and the class conversion relationship set are combined to automatically generate the conversion method, and the conversion method is configured as a template. In this way, based on the most basic class conversion relationship, more flexible and complex conversion relationships can be combined, and users can save the customary combination method as a template to achieve automatic combination conversion of more business objects, and can also customize different combinations for different business objects, thereby simplifying code writing and improving efficiency.

[0108] The present disclosure also provides an object conversion system, such as Figure 5 As shown, the system includes:

[0109] A first generating unit 501 is used to obtain source code of a project and generate an abstract syntax tree of the project based on the source code;

[0110] A monitoring unit 502 is used to monitor a target operation instruction in an integrated development environment, where the target operation instruction includes a source object and a target object;

[0111] An acquisition unit 503 is used to acquire attribute information of a source object and a target object from an abstract syntax tree;

[0112] The second generating unit 504 is used to generate conversion code in the implementation class according to the attribute information of the source object and the target object and the preset matching rule.

[0113] In an example, when generating an abstract syntax tree of a project based on source code, the first generating unit 501 is specifically used to: parse the project structure of the project according to the source code; analyze each class in the project structure, generate an abstract syntax tree of the class and store it in a database.

[0114] In one example, the monitoring unit 502 is specifically used to: monitor user operations in an integrated development environment, and when one of the following user operations is monitored in the integrated development environment, feedback code conversion prompt information: copying a class file to another class file; using a code generator to generate multiple classes from the same object; writing a conversion method for multiple classes with the same attribute names; creating a new POJO class with more than three attributes, traversing the entire project to find other classes with similar class names and attribute names and convertible types; receiving the user's code conversion operation instructions and obtaining the target operation instructions.

[0115] In an example, the monitoring unit 502 is further specifically used to: receive a selection instruction and a code conversion operation instruction of two class files from a user in an integrated development environment, and obtain a target operation instruction.

[0116] In one example, the generation unit 504 is specifically used to generate conversion code in the implementation class when the attribute information of the source object and the target object meets one of the preset matching rules; the preset matching rules include: type matching of the attribute information of the source object and the target object; matching of the basic type and the packaging type in the attribute information of the source object and the target object; the class of the attribute information of the target object is the parent class of the attribute information of the source object; the attribute information of the source object and the target object are both collection types, and the element type in the collection can be converted; the source object and the target object both contain nested objects, and the attribute names and types of the nested objects match.

[0117] In one example, the second generation unit 504 is specifically used to generate conversion code in the implementation class, generate and feedback manual matching prompt information when the attribute information of the source object and the target object does not meet the preset matching rules; and generate conversion code in the implementation class in response to the user's matching operation instructions.

[0118] In one example, the system further includes: a third generating unit 505, which is used to generate a conversion method according to the conversion code and a class conversion relationship set, and configure the conversion method as a template; the class conversion relationship set is a plurality of combined conversion relationships based on the conversion code.

[0119] According to an embodiment of the present disclosure, the present disclosure also provides an electronic device and a readable storage medium.

[0120] Figure 6 A schematic block diagram of an example electronic device 800 that can be used to implement an embodiment of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present disclosure described and / or required herein.

[0121] like Figure 6 As shown, the electronic device 800 includes a computing unit 801, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 802 or a computer program loaded from a storage unit 808 into a random access memory (RAM) 803. In the RAM 803, various programs and data required for the operation of the device 800 can also be stored. The computing unit 801, the ROM 802, and the RAM 803 are connected to each other via a bus 804. An input / output (I / O) interface 805 is also connected to the bus 804.

[0122] A number of components in the device 800 are connected to the I / O interface 805, including: an input unit 806, such as a keyboard, a mouse, etc.; an output unit 807, such as various types of displays, speakers, etc.; a storage unit 808, such as a disk, an optical disk, etc.; and a communication unit 809, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 809 allows the device 800 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.

[0123] The computing unit 801 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 801 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The computing unit 801 performs the various methods and processes described above, such as the object conversion method. For example, in some embodiments, the object conversion method may be implemented as a computer software program, which is tangibly contained in a machine-readable medium, such as a storage unit 808. In some embodiments, part or all of the computer program may be loaded and / or installed on the device 800 via ROM 802 and / or communication unit 809. When the computer program is loaded into RAM 803 and executed by the computing unit 801, one or more steps of the object conversion method described above may be performed. Alternatively, in other embodiments, the computing unit 801 may be configured to perform the object conversion method in any other appropriate manner (e.g., by means of firmware).

[0124] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.

[0125] The program code for implementing the method of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that the program code, when executed by the processor or controller, enables the functions / operations specified in the flow chart and / or block diagram to be implemented. The program code may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.

[0126] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A 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, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer 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 disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0127] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).

[0128] The systems and techniques described herein may be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), and the Internet.

[0129] A computer system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The relationship of client and server is generated by computer programs running on respective computers and having a client-server relationship with each other. The server may be a cloud server, a server of a distributed system, or a server combined with a blockchain.

[0130] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this disclosure can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solutions disclosed in this disclosure can be achieved, and this document does not limit this.

[0131] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Therefore, a feature defined as "first" or "second" may explicitly or implicitly include at least one of the features. In the description of the present disclosure, "plurality" means two or more, unless otherwise clearly and specifically defined.

[0132] The above is only a specific embodiment of the present disclosure, but the protection scope of the present disclosure is not limited thereto. Any person skilled in the art who is familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present disclosure, which should be included in the protection scope of the present disclosure. Therefore, the protection scope of the present disclosure should be based on the protection scope of the claims.< / apo> < / avo> < / avo> < / apo> < / apo> < / avo> < / avo> < / apo> < / string> < / string>

Claims

1. An object conversion method, characterized in that: The method comprises: Obtaining source code of a project, and generating an abstract syntax tree of the project based on the source code; In an integrated development environment, a target operation instruction is monitored, wherein the target operation instruction includes a source object and a target object; Acquire attribute information of the source object and the target object from the abstract syntax tree; According to the attribute information of the source object and the target object and the preset matching rules, a conversion code is generated in the implementation class.

2. The method according to claim 1, characterized in that The step of generating an abstract syntax tree of the project based on the source code includes: According to the source code, parsing the project structure of the project; Each class in the project structure is analyzed, and an abstract syntax tree of the class is generated and stored in a database.

3. The method according to claim 1, characterized in that The step of monitoring the target operation instruction in the integrated development environment includes: The user operation is monitored in the integrated development environment, and when one of the following user operations is monitored in the integrated development environment, code conversion prompt information is fed back: Copy a class file to another class file; Use code generators to generate multiple classes for the same object; Write conversion methods for classes that contain multiple properties with the same name; Create a new POJO class with more than three attributes, and traverse the entire project to find other classes with similar class names and attribute names and convertible types; Receive the code conversion operation instruction from the user and obtain the target operation instruction.

4. The method according to claim 1, characterized in that The monitoring of target operation instructions in the integrated development environment also includes: The user's selection instructions and code conversion operation instructions for two class files in the integrated development environment are received to obtain the target operation instructions.

5. The method according to claim 1, characterized in that When the attribute information of the source object and the target object meets one of the preset matching rules, a conversion code is generated in the implementation class; The preset matching rules include: The types of the attribute information of the source object and the target object match; Matching of basic type and packaging type in the attribute information of the source object and the target object; The class of the attribute information of the target object is the parent class of the attribute information of the source object; The attribute information of the source object and the target object are both of set type, and the element types in the set can be converted; The source object and the target object both contain nested objects, and the attribute names and types of the nested objects match.

6. The method according to claim 1, characterized in that When the attribute information of the source object and the target object does not conform to the preset matching rule, the generating of the conversion code in the implementation class includes: Generate and feedback manual matching prompt information; In response to the user's matching operation instruction, the conversion code is generated in the implementation class.

7. The method according to claim 1, characterized in that The method further comprises: A conversion method is generated according to the conversion code and the class conversion relationship set, and the conversion method is configured as a template; the class conversion relationship set is a plurality of combined conversion relationships based on the conversion code.

8. An object conversion system, characterized in that: The system comprises: A processing unit, configured to obtain source code of a project and generate an abstract syntax tree of the project based on the source code; A monitoring unit, used for monitoring a target operation instruction in an integrated development environment, wherein the target operation instruction includes a source object and a target object; An acquisition unit, configured to acquire attribute information of the source object and the target object from the abstract syntax tree; The generation unit is used to generate conversion code in the implementation class according to the attribute information of the source object and the target object and the preset matching rules.

9. An electronic device, characterized in that: include: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 7.

10. A non-transitory computer-readable storage medium storing computer instructions, characterized in that: The computer instructions are used to cause the computer to execute the method according to any one of claims 1-7.