Project code conversion method, device, equipment and storage medium

By using an automated plugin conversion method, the problem of low efficiency in project code conversion was solved, achieving efficient conversion from XML to JAVA code.

CN115437643BActive Publication Date: 2026-11-27PINGAN YIQIANBAO E COMMERCE CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211083700.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-09-06
Publication Date
2026-11-27
Estimated Expiration
2042-09-06

AI Technical Summary

Technical Problem

In existing technologies, project code conversion requires manual operation, which results in a large amount of manpower consumption and low efficiency.

Method used

By obtaining the project's conversion requirements, the pre-configured plugin is invoked to automatically convert the XML code file, generate the JAVA code file, and then copy and paste it into the target project in response to user commands.

Benefits of technology

It enables automatic conversion of project code, improving conversion efficiency and reducing manual intervention.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115437643B_ABST
    Figure CN115437643B_ABST
Patent Text Reader

Abstract

The application belongs to the technical field of project development, and provides a project code conversion method, device, equipment and storage medium, wherein the method comprises the following steps: obtaining a project to be converted; determining a conversion requirement of the project; calling a pre-configured plug-in according to the conversion requirement; converting an XML code file in the project according to the plug-in to obtain a JAVA code file; and in response to a copy-paste instruction of a user on the JAVA code file, copying and pasting the JAVA code file to a target project, so that the XML code file in the project is automatically converted into an XML code file through the pre-constructed plug-in, without the aid of manual work, and the conversion efficiency of the project code is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of project development technology, and more specifically, to a project code conversion method, apparatus, device, and storage medium. Background Technology

[0002] With the rapid development of the IT industry and the continuous upgrading of cutting-edge technologies, distributed systems, characterized by high fault tolerance, elastic scalability, resource sharing, flexible configuration, and rapid computing, have emerged and are widely used in various fields of the Internet. Traditional centralized mainframe systems are facing the need for rapid system operation and maintenance transformation and upgrades, and are gradually being phased out.

[0003] The transformation and upgrading of traditional mainframe systems inevitably requires rewriting existing code during the transformation process because the system framework and technical components differ from the programming languages ​​used in mainstream distributed architectures. This involves converting between the two programming languages, such as converting XML code files in a Spring Cloud project to Java code files. However, current code conversion is done manually, which is labor-intensive and inefficient. Summary of the Invention

[0004] The main objective of this application is to provide a project code conversion method, apparatus, device, and storage medium to improve the conversion efficiency of project code.

[0005] To achieve the above-mentioned objectives, this application provides a project code conversion method, including:

[0006] Get the items to be converted;

[0007] Determine the conversion requirements for the project;

[0008] According to the conversion requirements, a pre-configured plugin is invoked, and the XML code file in the project is converted according to the plugin to obtain a JAVA code file;

[0009] In response to the user's copy and paste command for the JAVA code file, the JAVA code file is copied and pasted into the target project.

[0010] Preferably, the step of converting the XML code file in the project according to the plugin to obtain the JAVA code file includes:

[0011] The XML code file is parsed to obtain an XML parsing file;

[0012] Identify XML nodes with the BEAN identifier in the XML parsing file;

[0013] All attributes in the XML node are identified, and the plugin is invoked to adjust all attributes in the XML node to obtain the JAVA code file.

[0014] Preferably, the step of calling the plugin to adjust all attributes in the XML node to obtain a JAVA code file includes:

[0015] The plugin is invoked to compare all attributes in the XML node with a pre-built set of supported attributes, and the comparison result is obtained.

[0016] Based on the comparison results, all attributes in the XML node are distinguished into supported attributes supported by the JAVA code file and unsupported attributes not supported by the JAVA code file.

[0017] Adjust the unsupported attributes in the XML node to obtain the JAVA code file.

[0018] Preferably, adjusting the unsupported attributes in the XML node to obtain the JAVA code file includes:

[0019] Parse attribute values ​​that are not supported during code conversion;

[0020] Adjust the values ​​of unsupported attributes to the values ​​of supported attributes in the Java code file to obtain the Java code file.

[0021] Furthermore, before invoking the pre-configured plugin according to the conversion requirement, the process also includes:

[0022] Load all code files and JAR package files in the system;

[0023] Select the XML code files belonging to the system's own project from all the code files and JAR package files.

[0024] Furthermore, after copying and pasting the JAVA code file into the target project, the process also includes:

[0025] The layout loading method is determined based on the converted JAVA code file;

[0026] The interface layout of the JAVA code file copied and pasted into the target project is performed according to the loading layout method.

[0027] Furthermore, after copying and pasting the JAVA code file into the target project, the process also includes:

[0028] The copied and pasted JAVA code file into the target project is then tested, and the test results are obtained.

[0029] After determining that the JAVA code file meets the preset conversion requirements based on the detection results, output the conversion success message of the XML code file in the project.

[0030] This application also provides a project code conversion apparatus, the apparatus comprising:

[0031] The acquisition module is used to acquire the items to be converted;

[0032] The determination module is used to determine the conversion requirements of the project;

[0033] The conversion module is used to call pre-configured plugins according to the conversion requirements, and convert the XML code files in the project into JAVA code files according to the plugins;

[0034] The copy and paste module is used to copy and paste the JAVA code file to the target project in response to the user's copy and paste command for the JAVA code file.

[0035] This application also provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps of any of the methods described above.

[0036] This application also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps of any of the methods described above.

[0037] This application provides a project code conversion method, apparatus, device, and storage medium. By acquiring the project to be converted, determining the conversion requirements of the project, and calling a pre-configured plugin according to the conversion requirements, the plugin converts the XML code file in the project into a JAVA code file. In response to a user's copy-paste command for the JAVA code file, the JAVA code file is copied and pasted into the target project. Thus, the pre-built plugin automatically converts the XML code file in the project into an XML code file, eliminating the need for manual intervention and improving the efficiency of project code conversion. Attached Figure Description

[0038] Figure 1 This is a flowchart illustrating a project code conversion method according to an embodiment of this application;

[0039] Figure 2 This is a schematic block diagram of the structure of a project code conversion device according to an embodiment of this application;

[0040] Figure 3 This is a schematic block diagram of the structure of a computer device according to an embodiment of this application.

[0041] The realization of the purpose, functional features and advantages of this application will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation

[0042] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.

[0043] With the development of Internet technology, more and more projects are gradually being converted from old projects to new projects using the Spring Boot framework or Spring Cloud framework. However, old projects often define a SpringBean object, which contains a lot of XML configurations. These XML configurations need to be converted into Java formats that conform to the new project format.

[0044] Currently, developers translate XML code files one by one into Java code files. They also need to pay attention to field naming and other issues during the conversion process. As a result, the conversion efficiency is low and the conversion is prone to errors.

[0045] Spring Boot is a project development framework designed to simplify the initial setup and development process of new Spring applications. This framework uses a specific configuration method, eliminating the need for developers to define boilerplate configurations. Spring Boot integrates numerous frameworks with default configurations. Within this framework, developers can create software projects. For example, they can input project code, and the front-end development tool can compile it, including the framework language, CSS, and images. The tool also provides feedback on code quality and errors. This front-end development tool performs real-time compilation and sends the compiled code to the client (browser), allowing the browser to display the corresponding page in real time. In other words, when a developer modifies the code, the front-end development tool compiles the modified code, and the browser displays the corresponding page in real-time, enabling developers to see the changes immediately and further refine the code based on these changes.

[0046] Spring Cloud is a service governance toolkit based on Spring Boot. In a microservice architecture, it is used to manage and coordinate services within a single project, which involves breaking down a monolithic project into multiple microservices. Each microservice can independently choose its technology, develop, deploy, and maintain itself, and these microservices can coordinate and cooperate with each other.

[0047] Spring Cloud is an ordered collection of frameworks that cleverly simplifies the development of distributed system infrastructure by leveraging the development convenience of Spring Boot. Features such as service discovery and registration, configuration center, message bus, load balancing, circuit breaker, and data monitoring can all be started and deployed with a single click using the Spring Boot development style.

[0048] Spring Bean objects are objects that are instantiated, assembled, and managed by the Spring container.

[0049] Therefore, this application proposes a project code conversion method, with the terminal device as the execution entity. This method aims to solve the technical problem that current manual conversion methods require a large amount of manpower and have low development efficiency. (Reference) Figure 1 In one embodiment, this application provides a project code conversion method, the method comprising:

[0050] S11. Obtain the items to be converted;

[0051] S12. Determine the conversion requirements of the project;

[0052] S13. According to the conversion requirements, call the pre-configured plugin, and convert the XML code file in the project according to the plugin to obtain the JAVA code file;

[0053] S14. In response to the user's copy and paste command for the JAVA code file, copy and paste the JAVA code file to the target project.

[0054] As described in step S11 above, the terminal device in this step can obtain the project to be converted from the project library and download and install the front-end development tool from the remote server. Specifically, the front-end development tool can be a command-line tool in the Node.js environment.

[0055] As described in step S12 above, developers can input conversion requirements into the front-end development tool. These requirements include the project to be converted, the desired code format after conversion, and so on. The front-end development tool can prompt developers to input the project name and description, select the framework used in the project, choose the corresponding conversion plugin, and specify the target server, which can be the final release platform for the software project.

[0056] In one embodiment, after acquiring the project, the project can be initialized. When the front-end development tool receives an initialization command, it sequentially acquires the project name, project description, framework used by the project, plugins corresponding to the framework, and the platform on which the project will be published. The project name and description can be defined by the developer, the framework used by the project can be selected by the developer, and the plugins corresponding to the framework are determined by the developer based on the selected framework. Further, the front-end development tool downloads the initialization plugin and decompresses it into a temporary file. This temporary file includes a default template file and configuration information. The front-end development tool locates the default template file in the initialization plugin, which can be used to initialize the project directory. Further, the front-end development tool can also replace the default template file in the initialization plugin with a new template file, and install the third-party files required by the framework according to the framework and plugins. These third-party files need to be downloaded to the local project, thereby completing the project initialization process.

[0057] As described in step S13 above, the terminal device downloads a plugin from a remote server that corresponds to the framework used in the project and the conversion requirement, based on the user's input. The plugin then converts the XML code files in the project to obtain Java code files. Therefore, for developers, they only need to reference the conversion plugin in the system to automatically obtain Java code files.

[0058] Java, an object-oriented programming language, not only incorporates the advantages of C++ but also eliminates concepts like multiple inheritance and pointers that are difficult to understand in C++. Therefore, Java is both powerful and easy to use. Java is characterized by simplicity, object-oriented programming, distributed computing, robustness, security, platform independence and portability, multithreading, and dynamism.

[0059] XML (Extensible Markup Language) is a subset of Standard Generalized Markup Language (SGML) used to mark up electronic documents to give them structure.

[0060] As described in step S14 above, developers only need to copy and paste the obtained JAVA code file into the project, and after checking that it is correct, the code conversion task of the project can be completed. The operation is simple and efficient.

[0061] The project code conversion method provided in this application obtains the project to be converted, determines the conversion requirements of the project, calls a pre-configured plugin according to the conversion requirements, and converts the XML code file in the project to obtain a JAVA code file according to the plugin. In response to the user's copy and paste instruction for the JAVA code file, the JAVA code file is copied and pasted to the target project. Thus, the XML code file in the project is automatically converted to an XML code file through a pre-built plugin, without manual intervention, thereby improving the conversion efficiency of project code.

[0062] In one embodiment, the step of converting the XML code file in the project according to the plugin to obtain the JAVA code file may specifically include:

[0063] The XML code file is parsed to obtain an XML parsing file;

[0064] Identify XML nodes with the BEAN identifier in the XML parsing file;

[0065] All attributes in the XML node are identified, and the plugin is invoked to adjust all attributes in the XML node to obtain the JAVA code file.

[0066] This embodiment extracts the XML code file from the project, parses the XML code file to obtain an XML parsing file, then identifies the XML nodes with BEAN identifiers in the XML parsing file, determines all attributes in the XML nodes, and calls the plugin to adjust all attributes in the XML nodes to obtain the JAVA code file.

[0067] For example, the `Xmlns` attribute of a `Schema` element in a project has two usage scenarios: one is to represent the default namespace, with the attribute name being `Xmlns`, and the default namespace appears at most once in the `Schema` element; the other is an `Xmlns` attribute with a namespace prefix, with the attribute name starting with "Xmlns:", followed by the namespace prefix, and the `Xmlns` attribute with the namespace prefix can appear multiple times in the `Schema` element. Therefore, an `Xmlns` variable with a `String` data type and an initial value of `Null` is defined in the `Schema` class to store the default namespace; and a `NameSpace` variable with a `HashMap` data type is defined.<String,String> The initial value is null.<key,value> The `<namespace, namespace prefix>` property stores the `xmlns` attribute with a namespace prefix. The plugin is invoked to adjust the `Xmlns` attribute in the XML node to conform to the attributes of the Java code file.

[0068] In one embodiment, the step of calling the plugin to adjust all attributes in the XML node to obtain a JAVA code file may specifically include:

[0069] The plugin is invoked to compare all attributes in the XML node with a pre-built set of supported attributes, and the comparison result is obtained.

[0070] Based on the comparison results, all attributes in the XML node are distinguished into supported attributes supported by the JAVA code file and unsupported attributes not supported by the JAVA code file.

[0071] Adjust the unsupported attributes in the XML node to obtain the JAVA code file.

[0072] For the following reasons, unsupported attributes may exist in XML code files: For example, an XML code file may initially use LinearLayout and define an Orientation attribute. Later, due to changes in requirements, it may need to be changed from LinearLayout to RelativeLayout. At this time, it is easy to forget to delete the Orientation attribute. The remaining Orientation attribute will then be an unsupported attribute for the Java code file.

[0073] Therefore, in this embodiment, a plugin can be invoked to compare all attributes in an XML node with a pre-built set of supported attributes to obtain a comparison result. Based on the comparison result, all attributes in the XML node are distinguished into supported attributes supported by the JAVA code file and unsupported attributes not supported by the JAVA code file. The unsupported attributes in the XML node are then adjusted to obtain the JAVA code file.

[0074] In one embodiment, adjusting the unsupported attributes in the XML node to obtain the JAVA code file may specifically include:

[0075] Parse attribute values ​​that are not supported during code conversion;

[0076] Adjust the values ​​of unsupported attributes to the values ​​of supported attributes in the Java code file to obtain the Java code file.

[0077] In this embodiment, when parsing attribute values ​​that do not support attributes, if the attribute value is a literal, it can be directly used as the attribute value. If the attribute value is a reference to a resource, the attribute value can be determined by analyzing the resource value corresponding to the referenced resource. In this embodiment, when determining the attribute value by analyzing the resource value corresponding to the referenced resource, if the resource value has only one definition, it can be used as the attribute value; otherwise, if the resource value has multiple definitions, the attribute value can be obtained by running `android.content.res.Resources`. Here, a literal is a representation of a fixed value in the source code. Literals are fixed, immutable, and their values ​​are known. Almost all computer programming languages ​​have literal representations of basic values, such as integers, floating-point numbers, and strings. For example, "1" and "2" are integer literals, "abc" is a string literal, and "true" and "false" are boolean literals. Here, `android.content.res.Resources` is the resource folder in the Android application. When determining unsupported attribute values ​​by analyzing the resource values ​​corresponding to the referenced resource, if there is only one definition of the resource value, that resource value is used as the unsupported attribute value; if there are multiple definitions of the resource value, the unsupported attribute value is obtained by running `android.content.res.Resources`. Specifically, "one" and "multiple" here mean: Android supports defining different values ​​for the same resource name under different configurations. For example, the text displayed on a button (button_text): We can define only one value, "click," because there is only one value (i.e., one definition), which can be determined at compile time; or we can define multiple values ​​according to the system language configuration, such as "Click" in Chinese, "click" in English, etc. (i.e., multiple definitions), in which case the resource value needs to be obtained at runtime. Here, the resource value can be obtained at runtime using methods in `android.content.res.Resources`.

[0078] Finally, adjust the values ​​of unsupported attributes to the values ​​of supported attributes in the Java code file to obtain the Java code file.

[0079] In one embodiment, before invoking the pre-configured plugin according to the conversion requirement, the following may also be included:

[0080] Load all code files and JAR package files in the system;

[0081] Select the XML code files belonging to the system's own project from all the code files and JAR package files.

[0082] This embodiment loads all code files and JAR package files in the system, filters out XML code files belonging to the system's own project from all the code files and JAR package files, and converts the XML code files in the project into JAVA code files.

[0083] In one embodiment, after copying and pasting the JAVA code file to the target project, the process may further include:

[0084] The layout loading method is determined based on the converted JAVA code file;

[0085] The interface layout of the JAVA code file copied and pasted into the target project is performed according to the loading layout method.

[0086] This embodiment determines the layout loading method based on the converted JAVA code file, and performs the interface layout on the JAVA code file copied and pasted into the target project according to the layout loading method. Therefore, developers do not need to manually change the layout loading method, and it can be fully automated. It automatically determines whether to load the layout from the generated JAVA code file or from XML resources through Android's inflate method, without requiring developers to manually change the call.

[0087] In one embodiment, after copying and pasting the JAVA code file to the target project, the process may further include:

[0088] The copied and pasted JAVA code file into the target project is then tested, and the test results are obtained.

[0089] After determining that the JAVA code file meets the preset conversion requirements based on the detection results, output the conversion success message of the XML code file in the project.

[0090] This embodiment can detect whether the Java code file copied and pasted into the target project meets the requirements after conversion, and generate corresponding detection results. Based on the detection results, it determines whether the Java code file meets the preset conversion requirements. If the detection results determine that the Java code file meets the preset conversion requirements, it outputs a successful conversion message for the XML code file in the project. If the detection results determine that the Java code file does not meet the preset conversion requirements, it detects an error message indicating that the Java code file does not meet the preset conversion requirements, adjusts the Java code file according to the error message, obtains a code file that meets the preset conversion requirements, and then copies and pastes the Java code file into the target project. The preset conversion requirements can be customized and are not specifically limited here.

[0091] With the development of Internet technology, more and more projects are gradually being converted from old projects to new projects using the Spring Boot framework or Spring Cloud framework. However, old projects often define a SpringBean object, which contains a lot of XML configurations. These XML configurations need to be converted into Java formats that conform to the new project format.

[0092] Currently, developers translate XML code files one by one into Java code files. They also need to pay attention to field naming and other issues during the conversion process. As a result, the conversion efficiency is low and the conversion is prone to errors.

[0093] Spring Boot is a project development framework designed to simplify the initial setup and development process of new Spring applications. This framework uses a specific configuration method, eliminating the need for developers to define boilerplate configurations. Spring Boot integrates numerous frameworks with default configurations. Within this framework, developers can create software projects. For example, they can input project code, and the front-end development tool can compile it, including the framework language, CSS, and images. The tool also provides feedback on code quality and errors. This front-end development tool performs real-time compilation and sends the compiled code to the client (browser), allowing the browser to display the corresponding page in real time. In other words, when a developer modifies the code, the front-end development tool compiles the modified code, and the browser displays the corresponding page in real-time, enabling developers to see the changes immediately and further refine the code based on these changes.

[0094] Spring Cloud is a service governance toolkit based on Spring Boot. In a microservice architecture, it is used to manage and coordinate services within a single project, which involves breaking down a monolithic project into multiple microservices. Each microservice can independently choose its technology, develop, deploy, and maintain itself, and these microservices can coordinate and cooperate with each other.

[0095] Spring Cloud is an ordered collection of frameworks that cleverly simplifies the development of distributed system infrastructure by leveraging the development convenience of Spring Boot. Features such as service discovery and registration, configuration center, message bus, load balancing, circuit breaker, and data monitoring can all be started and deployed with a single click using the Spring Boot development style.

[0096] Spring Bean objects are objects that are instantiated, assembled, and managed by the Spring container.

[0097] Therefore, this application proposes a project code conversion device to solve the technical problem that current manual conversion methods require a large amount of manpower and have low development efficiency. (Refer to...) Figure 2 This application also provides a project code conversion device, the device comprising:

[0098] Module 11 is used to obtain the items to be converted;

[0099] Module 12 is used to determine the conversion requirements of the project;

[0100] The conversion module 13 is used to call a pre-configured plugin according to the conversion requirements, and convert the XML code file in the project according to the plugin to obtain the JAVA code file;

[0101] The copy and paste module 14 is used to copy and paste the JAVA code file to the target project in response to the user's copy and paste command for the JAVA code file.

[0102] The terminal device in this embodiment can obtain the project to be converted from the project library and download and install the front-end development tool from the remote server. Specifically, the front-end development tool can be a command-line tool in the Node.js environment.

[0103] Developers can input their conversion requirements into this front-end development tool. These requirements include the project to be converted, the desired code format, and more. The tool prompts developers to enter the project name and description, select the framework used in the project, choose the corresponding conversion plugin, and specify the target server, which can be the final deployment platform for the software project.

[0104] In one embodiment, after acquiring the project, the project can be initialized. When the front-end development tool receives an initialization command, it sequentially acquires the project name, project description, framework used by the project, plugins corresponding to the framework, and the platform on which the project will be published. The project name and description can be defined by the developer, the framework used by the project can be selected by the developer, and the plugins corresponding to the framework are determined by the developer based on the selected framework. Further, the front-end development tool downloads the initialization plugin and decompresses it into a temporary file. This temporary file includes a default template file and configuration information. The front-end development tool locates the default template file in the initialization plugin, which can be used to initialize the project directory. Further, the front-end development tool can also replace the default template file in the initialization plugin with a new template file, and install the third-party files required by the framework according to the framework and plugins. These third-party files need to be downloaded to the local project, thereby completing the project initialization process.

[0105] The terminal device downloads a plugin from a remote server that matches the framework used in the project and the conversion requirements, based on the user's input. The plugin then converts the XML code files in the project into Java code files. Therefore, for developers, they only need to reference the conversion plugin in their system to automatically obtain the Java code files.

[0106] Java, an object-oriented programming language, not only incorporates the advantages of C++ but also eliminates concepts like multiple inheritance and pointers that are difficult to understand in C++. Therefore, Java is both powerful and easy to use. Java is characterized by simplicity, object-oriented programming, distributed computing, robustness, security, platform independence and portability, multithreading, and dynamism.

[0107] XML (Extensible Markup Language) is a subset of Standard Generalized Markup Language (SGML) used to mark up electronic documents to give them structure.

[0108] Developers only need to copy and paste the obtained JAVA code files into the project, and after checking for errors, the code conversion task is completed. The operation is simple and efficient.

[0109] The project code conversion device provided in this application can obtain the project to be converted, determine the conversion requirements of the project, call a pre-configured plugin according to the conversion requirements, convert the XML code file in the project to obtain JAVA code file according to the plugin, and in response to the user's copy and paste instruction for the JAVA code file, copy and paste the JAVA code file to the target project. Thus, the XML code file in the project is automatically converted to an XML code file through the pre-built plugin, without manual intervention, thereby improving the conversion efficiency of project code.

[0110] As described above, it is understood that each component of the project code conversion device proposed in this application can realize the function of any of the project code conversion methods described above, and the specific structure will not be described in detail.

[0111] Reference Figure 3 This application also provides a computer device whose internal structure can be as follows: Figure 3 As shown. The computer device includes a processor, memory, network interface, and database connected via a system bus. The processor is designed to provide computing and control capabilities. The memory includes a storage medium and internal memory. The storage medium stores the operating system, computer programs, and database. The internal memory provides an environment for the operation of the operating system and computer programs stored in the storage medium. The database stores data related to the project code conversion method. The network interface is used to communicate with external terminals via a network connection. When the computer program is executed by the processor, it implements a project code conversion method.

[0112] The processor described above executes the project code conversion method described above, the method including:

[0113] Get the items to be converted;

[0114] Determine the conversion requirements for the project;

[0115] According to the conversion requirements, a pre-configured plugin is invoked, and the XML code file in the project is converted according to the plugin to obtain a JAVA code file;

[0116] In response to the user's copy and paste command for the JAVA code file, the JAVA code file is copied and pasted into the target project.

[0117] One embodiment of this application also provides a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements a project code conversion method, the method comprising:

[0118] Get the items to be converted;

[0119] Determine the conversion requirements for the project;

[0120] According to the conversion requirements, a pre-configured plugin is invoked, and the XML code file in the project is converted according to the plugin to obtain a JAVA code file;

[0121] In response to the user's copy and paste command for the JAVA code file, the JAVA code file is copied and pasted into the target project.

[0122] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed, it can include the processes of the embodiments of the methods described above. Any references to memory, storage, databases, or other media provided in this application and used in the embodiments can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual-rate SDRAM (SSRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), Rambus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.

[0123] In summary, the greatest benefit of this application is that:

[0124] This application provides a project code conversion method, apparatus, device, and storage medium. By acquiring the project to be converted, determining the conversion requirements of the project, and calling a pre-configured plugin according to the conversion requirements, the plugin converts the XML code file in the project into a JAVA code file. In response to a user's copy-paste command for the JAVA code file, the JAVA code file is copied and pasted into the target project. Thus, the pre-built plugin automatically converts the XML code file in the project into an XML code file, eliminating the need for manual intervention and improving the efficiency of project code conversion.

[0125] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, apparatus, article, or method that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, apparatus, article, or method. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, apparatus, article, or method that includes that element.

[0126] The above description is only a preferred embodiment of this application and does not limit the patent scope of this application. Any equivalent structural or procedural changes made based on the content of this application's specification and drawings, or direct or indirect applications in other related technical fields, are similarly included within the patent protection scope of this application.

Claims

1. A project code conversion method, characterized in that, include: Get the items to be converted; Determine the conversion requirements for the project; According to the conversion requirements, a pre-configured plugin is invoked, and the XML code file in the project is converted according to the plugin to obtain a JAVA code file; In response to the user's copy and paste command for the JAVA code file, the JAVA code file is copied and pasted into the target project; After copying and pasting the JAVA code file into the target project, the process also includes: The layout loading method is determined based on the converted JAVA code file; The interface layout of the JAVA code file copied and pasted into the target project is performed according to the loading layout method, specifically including: automatically determining whether to load the layout from the generated JAVA code file or to load it from XML resources through Android's inflate method; The step of converting the XML code file in the project according to the plugin to obtain the JAVA code file includes: The XML code file is parsed to obtain an XML parsing file; Identify XML nodes with the BEAN identifier in the XML parsing file; Determine all attributes in the XML node, and call the plugin to compare all attributes in the XML node with a pre-built set of supported attributes to obtain the comparison result; Based on the comparison results, all attributes in the XML node are distinguished into supported attributes supported by the JAVA code file and unsupported attributes not supported by the JAVA code file. Parse attribute values ​​that are not supported during code conversion; Adjust the values ​​of unsupported attributes to the values ​​of supported attributes in the Java code file to obtain the Java code file; Specifically, when parsing the attribute value of an unsupported attribute, if the attribute value is a literal, the literal is directly used as the attribute value of the unsupported attribute. If the attribute value is a reference to a resource, the attribute value of the unsupported attribute is determined by analyzing the resource value corresponding to the referenced resource. The literal is a representation used to express a fixed value in the source code. When determining the unsupported attribute value by analyzing the resource value corresponding to the referenced resource, if there is only one definition of the resource value, the resource value is used as the attribute value of the unsupported attribute; if there are multiple definitions of the resource value, the attribute value of the unsupported attribute is obtained by running the referenced resource.

2. The method according to claim 1, characterized in that, Before invoking the pre-configured plugin according to the conversion requirements, the process also includes: Load all code files and JAR package files in the system; Select the XML code files belonging to the system's own project from all the code files and JAR package files.

3. The method according to claim 1, characterized in that, After copying and pasting the JAVA code file into the target project, the process also includes: The copied and pasted JAVA code file into the target project is then tested, and the test results are obtained. After determining that the JAVA code file meets the preset conversion requirements based on the detection results, output the conversion success message of the XML code file in the project.

4. A project code conversion device, characterized in that, include: The acquisition module is used to acquire the items to be converted; The determination module is used to determine the conversion requirements of the project; The conversion module is used to call pre-configured plugins according to the conversion requirements, and convert the XML code files in the project into JAVA code files according to the plugins; The copy and paste module is used to copy and paste the JAVA code file to the target project in response to the user's copy and paste command for the JAVA code file; the copy and paste module is also used to determine the loading layout method based on the converted JAVA code file; The interface layout of the JAVA code file copied and pasted into the target project is performed according to the loading layout method, specifically including: automatically determining whether to load the layout from the generated JAVA code file or to load it from XML resources through Android's inflate method; The conversion module is specifically used to parse the XML code file to obtain an XML parsing file. Identify XML nodes with the BEAN identifier in the XML parsing file; Determine all attributes in the XML node, and call the plugin to compare all attributes in the XML node with a pre-built set of supported attributes to obtain the comparison result; Based on the comparison results, all attributes in the XML node are distinguished into supported attributes supported by the JAVA code file and unsupported attributes not supported by the JAVA code file. Parse attribute values ​​that are not supported during code conversion; Adjust the values ​​of unsupported attributes to the values ​​of supported attributes in the Java code file to obtain the Java code file; Specifically, when parsing the value of an unsupported attribute, if the attribute value is a literal, the literal is directly used as the attribute value of the unsupported attribute. If the attribute value is a reference to a resource, the attribute value of the unsupported attribute is determined by analyzing the resource value corresponding to the referenced resource. The literal is a representation used to express a fixed value in the source code. When determining the attribute value of an unsupported attribute by analyzing the resource value corresponding to the referenced resource, if the resource value has only one definition, the resource value is used as the attribute value of the unsupported attribute. If the resource value has multiple definitions, the attribute value of the unsupported attribute is obtained by running the referenced resource.

5. A computer device, characterized in that, include: processor; Memory; The memory stores a computer program, and the processor executes the computer program to implement the project code conversion method according to any one of claims 1 to 3.

6. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the project code conversion method according to any one of claims 1-3.

Citation Information

Patent Citations

  • Interface layout method and device for Android application

    CN110442419A

  • Managing Non-Common Features for Program Code Translation

    US20120204160A1