Method and device for copying JAVA component, equipment and medium

By compiling JavaBean components into abstract syntax trees and modifying code to generate bytecode files, the problem of low memory usage and processing efficiency during the copying of JavaBean components is solved, and efficient component copying is achieved.

CN120045170APending Publication Date: 2025-05-27AVATR CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510137186.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-02-07
Publication Date
2025-05-27

AI Technical Summary

Technical Problem

The prior art requires line-by-line reflection of code when copying JavaBean components, which occupies device memory, resulting in low processing efficiency and frequent security detection, and reducing device performance.

Method used

Compile JavaBean components into abstract syntax trees, modify the code of the abstract syntax trees through pre-annotated elements, and generate bytecode files to avoid line-by-line processing and security detection.

Benefits of technology

Simplify processing flow, shorten processing time, improve processing efficiency, free up memory resources, and improve equipment performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120045170A_ABST
    Figure CN120045170A_ABST
Patent Text Reader

Abstract

The embodiment of the invention relates to the technical field of JAVA components, and discloses a copying method and device of a JAVA component, equipment and a medium, the method comprises the following steps: after obtaining the JAVA component to be copied, compiling the JAVA component to be copied into an abstract syntax tree; obtaining elements from preset annotation information, wherein the elements are modification codes for annotating and marking the abstract syntax tree by calling an annotation device by a user; and after codes of the abstract syntax tree are modified based on the elements, exporting a byte code file corresponding to the JAVA component to be copied according to the modified abstract syntax tree. By applying the technical scheme, the whole JAVA component to be copied can be directly processed, code content does not need to be processed line by line, the processing flow can be simplified, the processing time consumption can be shortened, and the processing efficiency can be improved; and the whole process does not need to additionally occupy a processing memory, computer resources can be released, and the utilization rate of the resources is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present invention relate to the technical field of JAVA components, and specifically relate to a method, apparatus, device and medium for copying JAVA components. Background Art

[0002] JavaBean is a reusable software component in the Java programming language. A JavaBean is a Java class that conforms to specific standards. It is usually used to encapsulate data and provide access to this data, and has features such as a public no-argument constructor, serializability, and properties.

[0003] Since JavaBean can encapsulate data and access data, in order to call the above components, the currently common method is: copy the component code, and then perform data encapsulation according to the component code on different platforms. One commonly used copying method is Java reflection. Specifically, when the device is running, the information of the component is dynamically obtained, and the class or object is operated through the information of the component, and then the code of the component can be called, accessed and modified, and finally copied down.

[0004] However, the above operation method has the following technical problems: The Java reflection method must perform reflection and copying during the operation of the device, and it is necessary to perform reflection on the code of the component line by line. This not only occupies the device memory, reduces the performance and processing efficiency of the device, but also during the parsing process, in order to ensure code security, it is necessary to perform security detection on the code of the component line by line, further reducing the processing efficiency. Summary of the Invention

[0005] In view of the above problems, the embodiments of the present invention provide a method, apparatus, device and medium for copying JAVA components, which are used to solve the technical problems that the prior art needs to occupy device memory and has low processing efficiency.

[0006] According to one aspect of the embodiments of the present invention, a method for copying a JAVA component is provided, and the method includes:

[0007] After obtaining the JAVA component to be copied, compile the JAVA component to be copied into an abstract syntax tree;

[0008] Obtain elements from the preset annotation information, where the elements are the modified code obtained by the user calling an annotator to perform annotation marking on the abstract syntax tree;

[0009] After modifying the code of the abstract syntax tree based on the elements, export the bytecode file corresponding to the JAVA component to be copied according to the modified abstract syntax tree.

[0010] In one embodiment, the present invention can compile the entire JAVA component to be copied into an abstract syntax tree; modify the code of the abstract syntax tree according to the pre-annotated elements, and generate and export a corresponding bytecode file from the modified abstract syntax tree, so as to directly copy the required component. Compared with copying line by line using JAVA reflection, the present invention does not need to process the code content line by line, which can simplify the processing flow, shorten the processing time, and improve the processing efficiency.

[0011] According to another aspect of the embodiments of the present invention, there is provided a copying device for JAVA components, including:

[0012] A compilation module, configured to compile the JAVA component to be copied into an abstract syntax tree after obtaining the JAVA component to be copied;

[0013] An element acquisition module, configured to acquire elements from preset annotation information, where the elements are modified codes obtained by a user invoking an annotator to annotate and mark the abstract syntax tree;

[0014] A copying module, configured to export a bytecode file corresponding to the JAVA component to be copied according to the modified abstract syntax tree after modifying the code of the abstract syntax tree based on the elements.

[0015] According to another aspect of the embodiments of the present invention, there is provided a copying device for JAVA components, including: a processor, a memory, a communication interface, and a communication bus. The processor, the memory, and the communication interface complete communication with each other through the communication bus;

[0016] The memory is used to store at least one executable instruction, and the executable instruction causes the processor to execute the copying method of the JAVA component as described above.

[0017] According to still another aspect of the embodiments of the present invention, there is provided a computer-readable storage medium, in which at least one executable instruction is stored, and the executable instruction causes the copying device / device of the JAVA component to perform the following operations:

[0018] After obtaining the JAVA component to be copied, compile the JAVA component to be copied into an abstract syntax tree;

[0019] Acquire elements from preset annotation information, where the elements are modified codes obtained by a user invoking an annotator to annotate and mark the abstract syntax tree;

[0020] After modifying the code of the abstract syntax tree based on the elements, export a bytecode file corresponding to the JAVA component to be copied according to the modified abstract syntax tree.

[0021] Traditional JAVA reflection requires calling the code of the memory line-by-line parsing and processing component, and continuous security detection is required during the processing to copy the code of the component. In the embodiments of the present invention, the JAVA component to be copied is compiled into an abstract syntax tree; the code of the abstract syntax tree is modified according to the pre-annotated elements, and the modified abstract syntax tree is generated into a corresponding bytecode file and exported, so as to directly copy the required component. The entire processing process can directly process the entire JAVA component to be copied, without processing the code content line by line, which can simplify the processing flow, shorten the processing time, and improve the processing efficiency; and the entire process does not require additional memory for processing, which can release the resources of the computer and improve the utilization rate of resources.

[0022] The above description is only an overview of the technical solution of the embodiments of the present invention. In order to be able to understand the technical means of the embodiments of the present invention more clearly, it can be implemented according to the content of the specification. And in order to make the above and other purposes, features and advantages of the embodiments of the present invention more obvious and understandable, the specific embodiments of the present invention are specifically exemplified below. BRIEF DESCRIPTION OF THE DRAWINGS

[0023] The drawings are only used to illustrate the embodiments and are not considered as a limitation of the present invention. And throughout the drawings, the same reference numerals are used to represent the same components. In the drawings:

[0024] Figure 1 The flowchart of the first embodiment of the method for copying a JAVA component provided by the present invention is shown;

[0025] Figure 2 The flowchart of the second embodiment of the method for copying a JAVA component provided by the present invention is shown;

[0026] Figure 3 The flowchart of the compilation of the JAVA compiler provided by the present invention is shown;

[0027] Figure 4 The flowchart of the third embodiment of the method for copying a JAVA component provided by the present invention is shown;

[0028] Figure 5 The structural schematic diagram of the first embodiment of the device for copying a JAVA component provided by the present invention is shown;

[0029] Figure 6 The structural schematic diagram of the embodiment of the device for copying a JAVA component provided by the present invention is shown. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0030] Exemplary embodiments of the present invention will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present invention are shown in the drawings, it should be understood that the present invention can be implemented in various forms and should not be limited by the embodiments set forth herein.

[0031] Figure 1 FIG. 1 shows a schematic flow chart of a first embodiment of a method for copying JAVA components provided by the present invention, which is executed by a copying device for JAVA components. The copying device for JAVA components can be a computer.

[0032] As Figure 1 shown, the method includes the following steps:

[0033] Step 110: After obtaining the JAVA component to be copied, compile the JAVA component to be copied into an abstract syntax tree.

[0034] Among them, the JAVA component to be copied can be a JavaBean or other different reusable software components in a programming language.

[0035] In actual operation, the user can import the JAVA component to be copied into the computer, and then can compile the entire JAVA component to be copied into an abstract syntax tree.

[0036] By compiling into an abstract syntax tree, the abstract syntax can be read, modified, and content added, so as to generate component code that meets the actual usage requirements of the user, and then directly export it to complete the copy. In this process, there is no need to process the code line by line, which can effectively improve the processing efficiency.

[0037] In order to accurately obtain the annotation content added by the user, among them, as an example, the obtaining of the JAVA component to be copied may include the following steps:

[0038] Step 1101: Obtain the JAVA file imported by the user in the computer, and extract the component to be copied from the JAVA file to obtain the JAVA component to be copied.

[0039] In actual operation, the user can import the JAVA file into the computer, and then extract the component to be copied from the JAVA file through the computer to obtain the JAVA component to be copied.

[0040] Optionally, the JAVA file contains multiple components to be copied, and the user can screen the components for this copy operation according to their actual needs to obtain the JAVA component to be copied.

[0041] Step 120: Obtain elements from the preset annotation information, where the elements are modification codes obtained by the user calling an annotator to annotate and mark the abstract syntax tree.

[0042] Among them, the preset annotation information can be a class for modifying codes preset by the user, or a compilation device for the JAVA component to be copied. The user calls an annotator to annotate the abstract syntax tree to mark the information to be modified, including the codes to be modified.

[0043] Specifically, the user can also customize the class to be annotated in advance, and then customize the content corresponding to each class, including the fields or values to be modified, etc.

[0044] In one embodiment, elements can be directly obtained from the preset annotation information, and the elements may be classes, variables, methods, etc.

[0045] In order to accurately obtain the annotation content added by the user, among them, by way of example, the operation of obtaining the preset annotation information may include the following steps:

[0046] Step 1201: Obtain the annotation code customized by the user;

[0047] Step 1202: Determine the information marked by the user on the elements of the annotation code to obtain the annotation information, and the elements include: classes, variables, and methods.

[0048] In specific operations, the user can first perform a customization operation according to their personal needs to customize the annotation code. After completing the customization, the customized code can be added to the computer, so that the annotation code customized by the user can be obtained.

[0049] For example, the user can customize the following annotation code:

[0050] @Retention(RetentionPolicy.SOURCE);

[0051] @Target(ElementType.TYPE);

[0052] public@interface MyAnnotation{String value()default"";};

[0053] During the customization process, the user can add marks to the code, and the annotation content corresponding to each element mark in the code. In one embodiment, the annotation marked by the user can be shown in the following code:

[0054] @MyAnnotation

[0055] public class User{private String name; private int age; / / getter and setter};

[0056] Subsequently, the information marked on the elements of the annotation code can be determined to obtain annotation information, where the elements include: classes, variables, and methods.

[0057] In actual operation, custom Annotations can be used to mark in the code, and subsequently, the annotation content can be determined based on the marks to obtain annotation information.

[0058] Step 130: After modifying the code of the abstract syntax tree based on the elements, export the bytecode file corresponding to the JAVA component to be copied according to the modified abstract syntax tree.

[0059] In one embodiment, after obtaining the elements, the code of the abstract syntax tree can be modified based on the content of the elements. Specifically, the code of the elements can be used to replace the code of the abstract syntax tree or added to the code of the abstract syntax tree.

[0060] After the modification is completed, export the bytecode file corresponding to the JAVA component to be copied according to the modified abstract syntax tree, so that the user can obtain a complete software component that meets their usage requirements to complete the copying operation.

[0061] In actual operation, the user may need to import the entire copied component into other systems or devices for application. In order to directly extract the file corresponding to the entire copied component and facilitate the user to apply it to other systems. As an example, the exporting of the bytecode file corresponding to the JAVA component to be copied according to the modified abstract syntax tree may include the following steps:

[0062] Step 1301: Obtain the file export address preset by the user.

[0063] Step 1302: Generate the generated bytecode file corresponding to the JAVA component to be copied according to the modified abstract syntax tree.

[0064] Step 1303: Export the bytecode file to the file export address for the user to extract.

[0065] Specifically, the user can preset the file export address in advance. For example, create a file export address (such as javax.annotation.processing.Prodcessor) in the directory of project META-INF / services. After obtaining the file export address, the bytecode file corresponding to the JAVA component to be copied can be generated according to the modified abstract syntax tree. Finally, the bytecode file is exported to the location of the file export address, so that the user can extract the file corresponding to the JAVA component to be copied at the location of the file export address to complete the copy.

[0066] Through the above method, not only can the copied file be directly extracted, but also the file can be directly imported into other systems or devices, which is convenient for applications with different functions.

[0067] Traditional JAVA reflection needs to call memory to parse and process the code of the component line by line, and continuous security detection is required during the processing to copy the code of the component. In the embodiment of the present invention, the JAVA component to be copied is compiled into an abstract syntax tree; the code of the abstract syntax tree is modified according to the pre-annotated elements, and the modified abstract syntax tree is generated into a corresponding bytecode file and exported, so that the required component can be directly copied. The entire processing process can directly process the entire JAVA component to be copied without processing the code content line by line, which can simplify the processing flow, shorten the processing time, and improve the processing efficiency; and the entire process does not need to additionally occupy the memory of the processing, which can release the resources of the computer and improve the utilization rate of the resources.

[0068] Figure 2 The flowchart of the second embodiment of the method for copying a JAVA component provided by the present invention is shown, and this method is executed by a copying device for a JAVA component. The copying device for a JAVA component can also be a computer.

[0069] As Figure 2 shown, the method includes the following steps:

[0070] Step 210: After obtaining the JAVA component to be copied, use a preset JAVA compiler to compile the JAVA source code of the JAVA component to be copied into an editable abstract syntax tree.

[0071] In specific operations, the JAVA source code of the JAVA component to be copied can be compiled into an editable abstract syntax tree through a JAVA compiler.

[0072] Refer to Figure 3 which shows the flowchart of the JAVA compiler compilation provided by the present invention.

[0073] Specifically, the JAVA source code of the JAVA component to be copied can be input into a preset JAVA compiler. The JAVA compiler can generate JAVA bytecode (i.e., virtual instructions) executable by the JAVA virtual machine (JVM) of the JAVA compiler, so that the binary machine code executable by the interpreter in the JAVA virtual machine (JVM), that is, the program, can be generated, and thus an editable abstract syntax tree can be generated.

[0074] Among them, since the JAVA compiler provides a complete set of API interfaces, users can easily perform dynamic compilation and adjustment using the API interfaces, so that component code that meets the actual usage requirements of users can be generated subsequently and can be copied out.

[0075] In an embodiment, the code of the JAVA component to be copied may be incorrect or abnormal. In order to eliminate the abnormal code to avoid errors during subsequent operation, among them, as an example, in the process of compiling the JAVA source code of the JAVA component to be copied into an editable abstract syntax tree using the preset JAVA compiler, the method may further include the following steps:

[0076] Step 31: Identify the name field of the JAVA source code of the JAVA component to be copied.

[0077] Step 32: If it is determined that the name field is abnormal, intercept the JAVA source code corresponding to the name field.

[0078] Specifically, in the process of compiling the JAVA source code of the JAVA component to be copied using the preset JAVA compiler, the name field of the JAVA source code is identified through the preset JAVA compiler. Specifically, the name field of each piece of code can be identified.

[0079] Then, each name field can be compared with the type field of the code. If it is determined that the name field is different from the type field of the code, it can be determined that the name field is abnormal. If it is determined that there is a missing field in the name field, it can also be determined that the name field is abnormal.

[0080] If it is determined that the name field is abnormal, the JAVA source code corresponding to the name field can be extracted at the compilation stage, specifically, this piece of code can be cleared. After clearing this piece of incorrect code, errors in the subsequently copied code can be avoided, and the situation of abnormal operation of the subsequently copied code can also be avoided.

[0081] Step 220: Obtain elements from the preset annotation information. The elements are the modified code obtained by the user calling the annotator to perform annotation marking on the abstract syntax tree.

[0082] In an embodiment, the above steps are the same as those in the above embodiment. Specifically, the parsing content of the above embodiment can be referred to. To avoid repetition, it will not be elaborated here.

[0083] Step 230: After inserting the code content of the element into the code of the abstract syntax tree by invoking a preset encoding plugin, export the bytecode file corresponding to the JAVA component to be copied according to the modified abstract syntax tree.

[0084] In one embodiment, inserting the code content of an element into the code of an abstract syntax tree by invoking a preset encoding plugin can specifically use the encoding plugin JSR269. JSR 269 is a specification introduced by the JDK. With it, it is possible to process annotations during compilation and read, modify, and add content in the abstract syntax tree, so that the content of the element can be added to the abstract syntax tree and the component can be rewritten, enabling the copied component to implement user-defined annotation processing logic, such as copying the attributes of a bean.

[0085] Specifically, a program using the JSR 269 API can be used to invoke the encoding plugin JSR269, so that the implemented annotation processor can be invoked during compilation.

[0086] In the embodiment of the present invention, the JAVA source code of the JAVA component to be copied is compiled into an editable abstract syntax tree by a JAVA compiler, annotations can be processed during compilation, and the content in the abstract syntax tree can be read and modified, so that user-defined annotation processing logic can be implemented. Moreover, by modifying through an encoding plugin, the entire abstract syntax tree can be processed during compilation, which can further simplify the processing flow, thus shortening the processing time and improving the processing efficiency.

[0087] Refer to Figure 4 , which shows a schematic flowchart of the third embodiment of the method for copying a JAVA component provided by the present invention. This method is executed by a copying device for a JAVA component. The copying device for a JAVA component can also be a computer.

[0088] As Figure 4 shown, the method includes the following steps:

[0089] First step, obtain the JAVA source code of the JAVA component to be copied.

[0090] Second step, parse and convert the JAVA source code to obtain an abstract syntax tree.

[0091] Third step, use an annotation processor to perform annotation processing on the abstract syntax tree, modify the abstract syntax tree according to the annotation elements, and copy the attributes to obtain a copied JAVA component.

[0092] In an embodiment of the present invention, the JAVA source code of the JAVA component to be copied is compiled into an editable abstract syntax tree, and annotations can be processed during compilation, and the content in the abstract syntax tree can be read and modified, so that the annotation processing logic defined by the user can be implemented, the processing flow can be further simplified, the processing time can be shortened, and the processing efficiency can be improved.

[0093] Figure 5 FIG. 4 shows a schematic structural diagram of a first embodiment of a copying device for a JAVA component provided by the present invention. As Figure 5 shown, the device 500 includes: a compilation module 510, an element acquisition module 520, and a copying module 530.

[0094] The compilation module is configured to compile the JAVA component to be copied into an abstract syntax tree after obtaining the JAVA component to be copied;

[0095] The element acquisition module is configured to acquire elements from preset annotation information, where the elements are modified codes obtained by the user calling an annotator to perform annotation marking on the abstract syntax tree;

[0096] The copying module is configured to, after modifying the code of the abstract syntax tree based on the elements, export a bytecode file corresponding to the JAVA component to be copied according to the modified abstract syntax tree.

[0097] In an optional manner, the compiling the JAVA component to be copied into an abstract syntax tree includes:

[0098] Compiling the JAVA source code of the JAVA component to be copied into an editable abstract syntax tree by using a preset JAVA compiler.

[0099] In an optional manner, the compiling the JAVA component to be copied into an abstract syntax tree further includes:

[0100] Identifying the name field of the JAVA source code of the JAVA component to be copied;

[0101] If it is determined that the name field is abnormal, intercept the JAVA source code corresponding to the name field.

[0102] In an optional manner, the modifying the code of the abstract syntax tree based on the elements includes:

[0103] Invoking a preset encoding plugin to insert the code content of the elements into the code of the abstract syntax tree.

[0104] In an optional manner, the exporting a bytecode file corresponding to the JAVA component to be copied according to the modified abstract syntax tree includes:

[0105] Obtaining the file export address preset by the user;

[0106] Generate the generated bytecode file corresponding to the JAVA component to be copied according to the modified abstract syntax tree;

[0107] Export the bytecode file to the file export address for the user to extract.

[0108] In an alternative manner, the operation of obtaining the preset annotation information includes:

[0109] Obtain the annotation code defined by the user;

[0110] Determine the information marked by the user on the elements of the annotation code to obtain the annotation information, where the elements include: classes, variables, and methods.

[0111] In an alternative manner, the obtaining of the JAVA component to be copied includes:

[0112] Obtain the JAVA file imported by the user into the computer, and extract the component to be copied from the JAVA file to obtain the JAVA component to be copied.

[0113] Figure 6 The structural schematic diagram of an embodiment of the copy device for JAVA components provided by the present invention is shown. The specific implementation of the copy device for JAVA components is not limited in the specific embodiments of the present invention.

[0114] As Figure 6 shown, the copy device for JAVA components may include: a processor 602, a communications interface 604, a memory 606, and a communication bus 608.

[0115] Wherein: the processor 602, the communications interface 604, and the memory 606 communicate with each other through the communication bus 608. The communications interface 604 is used to communicate with network elements of other devices such as clients or other servers. The processor 602 is used to execute the program 610, and specifically may execute the relevant steps in the above embodiments of the copy method for JAVA components.

[0116] Specifically, the program 610 may include program code, and the program code includes computer-executable instructions.

[0117] The processor 602 may be a central processing unit (CPU), or a specific application integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of the present invention. The one or more processors included in the copying device of the JAVA component may be of the same type of processor, such as one or more CPUs; or different types of processors, such as one or more CPUs and one or more ASICs.

[0118] A memory 606 for storing a program 610. The memory 606 may include a high-speed RAM memory, and may also include a non-volatile memory, such as at least one disk memory.

[0119] The program 610 can be specifically called by the processor 602 to cause the copying device of the JAVA component to perform the following operations:

[0120] After obtaining the JAVA component to be copied, compile the JAVA component to be copied into an abstract syntax tree;

[0121] Obtain elements from the preset annotation information, where the elements are the modified codes obtained by the user calling an annotator to perform annotation marking on the abstract syntax tree;

[0122] After modifying the code of the abstract syntax tree based on the elements, export a bytecode file corresponding to the JAVA component to be copied according to the modified abstract syntax tree.

[0123] In an alternative manner, the compiling the JAVA component to be copied into an abstract syntax tree includes:

[0124] Use a preset JAVA compiler to compile the JAVA source code of the JAVA component to be copied into an editable abstract syntax tree.

[0125] In an alternative manner, the compiling the JAVA component to be copied into an abstract syntax tree further includes:

[0126] Identify the name field of the JAVA source code of the JAVA component to be copied;

[0127] If it is determined that the name field is abnormal, intercept the JAVA source code corresponding to the name field.

[0128] In an alternative manner, the modifying the code of the abstract syntax tree based on the elements includes:

[0129] Call a preset coding plugin to insert the code content of the elements into the code of the abstract syntax tree.

[0130] In an alternative approach, exporting the bytecode file corresponding to the JAVA component to be copied based on the modified abstract syntax tree includes:

[0131] Obtaining the file export address preset by the user;

[0132] Generating the generated bytecode file corresponding to the JAVA component to be copied according to the modified abstract syntax tree;

[0133] Exporting the bytecode file to the file export address for the user to extract.

[0134] In an alternative approach, the operation of obtaining the preset annotation information includes:

[0135] Obtaining the annotation code defined by the user;

[0136] Determining the information marked by the user on the elements of the annotation code to obtain the annotation information, where the elements include: classes, variables, and methods.

[0137] In an alternative approach, obtaining the JAVA component to be copied includes:

[0138] Obtaining the JAVA file imported by the user into the computer and extracting the component to be copied from the JAVA file to obtain the JAVA component to be copied.

[0139] In an alternative approach, when the program 610 is called by the processor 602, the copying device of the JAVA component performs the following operations:

[0140] After obtaining the JAVA component to be copied, compiling the JAVA component to be copied into an abstract syntax tree;

[0141] Obtaining elements from the preset annotation information, where the elements are the modified code obtained by the user calling the annotator to annotate and mark the abstract syntax tree;

[0142] After modifying the code of the abstract syntax tree based on the elements, exporting the bytecode file corresponding to the JAVA component to be copied according to the modified abstract syntax tree.

[0143] In an alternative approach, compiling the JAVA component to be copied into an abstract syntax tree includes:

[0144] Using a preset JAVA compiler to compile the JAVA source code of the JAVA component to be copied into an editable abstract syntax tree.

[0145] In an alternative approach, compiling the JAVA component to be copied into an abstract syntax tree further includes:

[0146] Identify the name field of the JAVA source code of the JAVA component to be copied;

[0147] If it is determined that the name field is abnormal, intercept the JAVA source code corresponding to the name field.

[0148] In an alternative manner, the code for modifying the abstract syntax tree based on the element includes:

[0149] Call a preset encoding plugin to insert the code content of the element into the code of the abstract syntax tree.

[0150] In an alternative manner, the exporting of the bytecode file corresponding to the JAVA component to be copied according to the modified abstract syntax tree includes:

[0151] Obtain the file export address preset by the user;

[0152] Generate a generated bytecode file corresponding to the JAVA component to be copied according to the modified abstract syntax tree;

[0153] Export the bytecode file to the file export address for the user to extract.

[0154] In an alternative manner, the operation of obtaining the preset annotation information includes:

[0155] Obtain the annotation code defined by the user;

[0156] Determine the information marked by the user on the elements of the annotation code to obtain annotation information, where the elements include: classes, variables, and methods.

[0157] In an alternative manner, the obtaining of the JAVA component to be copied includes:

[0158] Obtain the JAVA file imported by the user into the computer, and extract the component to be copied from the JAVA file to obtain the JAVA component to be copied.

[0159] An embodiment of the present invention provides a computer-readable storage medium, and the storage medium stores at least one executable instruction. When the executable instruction runs on a copying device / device of a JAVA component, the copying device / device of the JAVA component executes the copying method of the JAVA component in any of the above method embodiments.

[0160] The executable instruction can specifically be used to cause the copying device / device of the JAVA component to perform the following operations:

[0161] After obtaining the JAVA component to be copied, compile the JAVA component to be copied into an abstract syntax tree;

[0162] Obtain elements from the preset annotation information, where the elements are the modified code obtained by the user invoking an annotator to annotate the abstract syntax tree;

[0163] After modifying the code of the abstract syntax tree based on the elements, export the bytecode file corresponding to the JAVA component to be copied according to the modified abstract syntax tree.

[0164] In an alternative manner, the compiling the JAVA component to be copied into an abstract syntax tree includes:

[0165] Use a preset JAVA compiler to compile the JAVA source code of the JAVA component to be copied into an editable abstract syntax tree.

[0166] In an alternative manner, the compiling the JAVA component to be copied into an abstract syntax tree further includes:

[0167] Identify the name field of the JAVA source code of the JAVA component to be copied;

[0168] If it is determined that the name field is abnormal, intercept the JAVA source code corresponding to the name field.

[0169] In an alternative manner, the modifying the code of the abstract syntax tree based on the elements includes:

[0170] Invoke a preset encoding plugin to insert the code content of the element into the code of the abstract syntax tree.

[0171] In an alternative manner, the exporting the bytecode file corresponding to the JAVA component to be copied according to the modified abstract syntax tree includes:

[0172] Obtain the file export address preset by the user;

[0173] Generate the generated bytecode file corresponding to the JAVA component to be copied according to the modified abstract syntax tree;

[0174] Export the bytecode file to the file export address for the user to extract.

[0175] In an alternative manner, the operation of obtaining the preset annotation information includes:

[0176] Obtain the annotation code defined by the user;

[0177] Determine the information marked by the user on the elements of the annotation code to obtain the annotation information, where the elements include: classes, variables, and methods.

[0178] In an alternative manner, the obtaining the JAVA component to be copied includes:

[0179] Obtain the JAVA files imported by the user on the computer, and extract the components to be copied from the JAVA files to obtain the JAVA components to be copied.

[0180] In an optional manner, the executable instructions cause the copying device / device of the JAVA component to perform the following operations:

[0181] After obtaining the JAVA components to be copied, compile the JAVA components to be copied into an abstract syntax tree;

[0182] Obtain elements from the preset annotation information, where the elements are the modified codes obtained by the user calling the annotator to annotate the abstract syntax tree;

[0183] After modifying the code of the abstract syntax tree based on the elements, export the bytecode file corresponding to the JAVA components to be copied according to the modified abstract syntax tree.

[0184] In an optional manner, the compiling the JAVA components to be copied into an abstract syntax tree includes:

[0185] Use a preset JAVA compiler to compile the JAVA source code of the JAVA components to be copied into an editable abstract syntax tree.

[0186] In an optional manner, the compiling the JAVA components to be copied into an abstract syntax tree further includes:

[0187] Identify the name field of the JAVA source code of the JAVA components to be copied;

[0188] If it is determined that the name field is abnormal, intercept the JAVA source code corresponding to the name field.

[0189] In an optional manner, the modifying the code of the abstract syntax tree based on the elements includes:

[0190] Call a preset encoding plugin to insert the code content of the elements into the code of the abstract syntax tree.

[0191] In an optional manner, the exporting the bytecode file corresponding to the JAVA components to be copied according to the modified abstract syntax tree includes:

[0192] Obtain the file export address preset by the user;

[0193] Generate the generated bytecode file corresponding to the JAVA components to be copied according to the modified abstract syntax tree;

[0194] Export the bytecode file to the file export address for the user to extract.

[0195] In an alternative manner, the operation of obtaining the preset annotation information includes:

[0196] Obtain the annotation code defined by the user;

[0197] Determine the information marked by the user on the elements of the annotation code to obtain the annotation information, where the elements include: class, variable, and method.

[0198] In an alternative manner, the operation of obtaining the JAVA component to be copied includes:

[0199] Obtain the JAVA file imported by the user into the computer, and extract the component to be copied from the JAVA file to obtain the JAVA component to be copied.

[0200] The algorithms or displays provided herein are not inherently related to any particular computer, virtual system, or other device. In addition, the embodiments of the present invention are not directed to any particular programming language.

[0201] In the specification provided herein, a large number of specific details are set forth. However, it can be understood that the embodiments of the present invention may be practiced without these specific details. Similarly, in order to streamline the present invention and assist in understanding one or more of the various inventive aspects, in the above description of the exemplary embodiments of the present invention, the various features of the embodiments of the present invention are sometimes grouped together into a single embodiment, figure, or description thereof. Among them, the claims following the specific implementation manners are hereby expressly incorporated into the specific implementation manners, where each claim itself serves as a separate embodiment of the present invention.

[0202] Those skilled in the art can understand that the modules in the devices in the embodiments can be adaptively changed and disposed in one or more devices different from the embodiments. The modules or units or components in the embodiments can be combined into a module or unit or component, and in addition, they can be divided into multiple sub-modules or sub-units or sub-components. Except that at least some of such features and / or processes or units are mutually exclusive.

[0203] It should be noted that the above embodiments are illustrative of the present invention and not restrictive thereof, and alternative embodiments can be designed by those skilled in the art without departing from the scope of the appended claims. In the claims, any reference signs placed between parentheses shall not be construed as limiting the claim. The word "comprising" does not exclude the presence of elements or steps not listed in the claim. The word "a" or "an" preceding an element does not exclude the presence of a plurality of such elements. The present invention can be implemented by means of hardware including several different elements and by means of a suitably programmed computer. In the unit claims listing several devices, several of these devices can be embodied by the same item of hardware. The use of the words first, second, and third, etc. does not denote any order. These words can be interpreted as names. The steps in the above embodiments, unless otherwise specified, should not be construed as limiting the order of execution.

Claims

1. A method for copying a JAVA component, characterized in that: The method comprises: After obtaining the JAVA component to be copied, compile the JAVA component to be copied into an abstract syntax tree; Acquire an element from preset annotation information, where the element is a modified code that a user calls an annotator to annotate the abstract syntax tree; After the code of the abstract syntax tree is modified based on the element, a bytecode file corresponding to the JAVA component to be copied is exported according to the modified abstract syntax tree.

2. The method according to claim 1, characterized in that The step of compiling the JAVA component to be copied into an abstract syntax tree includes: The JAVA source code of the JAVA component to be copied is compiled into an editable abstract syntax tree using a preset JAVA compiler.

3. The method according to claim 2, characterized in that The step of compiling the JAVA component to be copied into an abstract syntax tree further includes: Identify the name field of the JAVA source code of the JAVA component to be copied; If it is determined that the name field is abnormal, the JAVA source code corresponding to the name field is intercepted.

4. The method according to claim 1, characterized in that: The code for modifying the abstract syntax tree based on the element includes: A preset encoding plug-in is called to insert the code content of the element into the code of the abstract syntax tree.

5. The method according to claim 1, characterized in that The step of exporting the bytecode file corresponding to the JAVA component to be copied according to the modified abstract syntax tree includes: Get the file export address preset by the user; Generate a bytecode file corresponding to the JAVA component to be copied according to the modified abstract syntax tree; The bytecode file is exported to the file export address for user extraction.

6. The method according to claim 1, characterized in that The operation of obtaining the preset annotation information includes: Get the user-defined annotation code; The information marked by the user on the elements of the annotation code is determined to obtain annotation information, wherein the elements include: classes, variables, and methods.

7. The method according to claim 1, characterized in that The obtaining of the JAVA component to be copied includes: A JAVA file imported by a user on a computer is obtained, and a component to be copied is extracted from the JAVA file to obtain the JAVA component to be copied.

8. A JAVA component copying device, characterized in that: The device comprises: A compiling module, used for compiling the JAVA component to be copied into an abstract syntax tree after obtaining the JAVA component to be copied; An element acquisition module is used to acquire an element from preset annotation information, wherein the element is a modification code that a user calls an annotator to annotate the abstract syntax tree; The copy module is used to modify the code of the abstract syntax tree based on the element, and then export the bytecode file corresponding to the JAVA component to be copied according to the modified abstract syntax tree.

9. A JAVA component copying device, characterized in that: include: A processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface communicate with each other via the communication bus; The memory is used to store at least one executable instruction, and the executable instruction enables the processor to execute the JAVA component copying method according to any one of claims 1-7.

10. A computer-readable storage medium, characterized in that: The storage medium stores at least one executable instruction, and when the executable instruction is executed on the electronic device / apparatus, the electronic device / apparatus executes the JAVA component copying method as described in any one of claims 1 to 7.