Section programming method and device, electronic equipment and readable storage medium
By pre-encapsulating aspect programming tools and shielding the underlying bytecode from modification, simple, convenient, and efficient aspect programming is achieved, solving the problems of high cost and low efficiency in existing technologies.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- BEIJING 58 INFORMATION TECH
- Filing Date
- 2022-07-20
- Publication Date
- 2026-06-16
AI Technical Summary
Existing aspect programming techniques are costly, inefficient, and difficult for developers to learn, resulting in low efficiency.
This provides an aspect programming tool that pre-encapsulates several aspect programming capabilities. By reading and parsing the application's aspect configuration file, it calls the target aspect programming capabilities, shielding the complex modifications at the underlying bytecode level. Developers only need to configure it to implement aspect programming.
It simplifies the aspect programming process, making it simpler, more convenient, and more efficient, reducing the risk of exceptions, and providing stable and high-quality aspect programming capabilities.
Smart Images

Figure CN115328474B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of Internet technology, and in particular to an aspect programming method, an aspect programming device, an electronic device, and a computer-readable storage medium. Background Technology
[0002] In the software industry, Aspect-Oriented Programming (AOP) is a technique that uses pre-compilation and runtime dynamic proxies to achieve unified maintenance of program functionality.
[0003] In existing technologies, implementing aspect-oriented programming (AOP) for applications is costly and involves high investment with low returns. This is because existing technologies perform low-level processing and require modifications to complex bytecode calls, making it difficult for developers to learn, inconvenient to use, and with a high barrier to entry, resulting in low efficiency for AOP. Summary of the Invention
[0004] The present invention provides an aspect-oriented programming method, apparatus, electronic device, and computer-readable storage medium to solve the problem of low efficiency in aspect-oriented programming.
[0005] This invention discloses an aspect programming method applied to an aspect programming tool, wherein the aspect programming tool pre-encapsulates several aspect programming capabilities, and the method includes:
[0006] Read the aspect configuration file configured for the application;
[0007] The aspect configuration file is parsed to determine the aspect configuration content for the application and the target aspect programming capabilities corresponding to the aspect configuration content;
[0008] The target aspect programming capability in the aspect programming tool is invoked to perform aspect programming on the application according to the aspect configuration content.
[0009] Optionally, the aspect programming tool includes an entry plugin for accessing the application. The step of calling the target aspect programming capability in the aspect programming tool to perform aspect programming on the application according to the aspect configuration includes:
[0010] The bytecode file of the application is read through the entry plugin;
[0011] The target aspect programming capability in the aspect programming tool is invoked to perform aspect programming on the bytecode file according to the aspect configuration content;
[0012] Write the bytecode file, after completing aspect programming, into the application.
[0013] Optionally, the aspect programming tool is pre-configured with a thread pool, which includes several threads. The step of invoking the target aspect programming capability in the aspect programming tool to perform aspect programming on the bytecode file according to the aspect configuration includes:
[0014] The threads read the bytecode files respectively and call the target aspect programming capability in the aspect programming tool to perform aspect programming on the bytecode files according to the aspect configuration content.
[0015] Optionally, the aspect programming capabilities each have a corresponding processing priority. After parsing the aspect configuration file and determining the aspect configuration content for the application and the target aspect programming capabilities corresponding to the aspect configuration content, the method includes:
[0016] When there are at least two target aspect programming capabilities, the target aspect programming capabilities are sorted according to their processing priorities.
[0017] The step of invoking the target aspect programming capability in the aspect programming tool to perform aspect programming on the application according to the aspect configuration content includes:
[0018] The target aspect programming capabilities in the aspect programming tool are invoked sequentially according to the order, so as to perform aspect programming on the application according to the corresponding aspect configuration content.
[0019] Optionally, after reading the aspect configuration file configured for the application, the method further includes:
[0020] If parsing the aspect configuration file fails, an error message indicating a configuration error in the aspect configuration file will be output.
[0021] Optionally, the entry plugin is configured in the developer toolkit (SDK) of the aspect programming tool;
[0022] The aspect programming tool supports multiple build systems, including at least one of the following: Gradle and Maven; the aspect configuration file format supported by the aspect programming tool includes at least one of the following: JSON, YAML, gradle DSL, and annotations.
[0023] Optionally, the aspect programming capability includes at least one of the following: method replacement, setting the method body content to null, inserting specified code into the method body, deleting method calls, object replacement, exception handling, and adding methods.
[0024] This invention also discloses an aspect programming device applied to an aspect programming tool, wherein the aspect programming tool pre-encapsulates several aspect programming capabilities, and the device includes:
[0025] The aspect configuration file reading module is used to read the aspect configuration file configured for the application.
[0026] The aspect configuration file parsing module is used to parse the aspect configuration file to determine the aspect configuration content for the application and the target aspect programming capability corresponding to the aspect configuration content;
[0027] The aspect programming capability invocation module is used to invoke the target aspect programming capability in the aspect programming tool to perform aspect programming on the application according to the aspect configuration content.
[0028] Optionally, the aspect programming tool includes an entry plugin for accessing the application, and the aspect programming capability invocation module is specifically used for:
[0029] The bytecode file of the application is read through the entry plugin;
[0030] The target aspect programming capability in the aspect programming tool is invoked to perform aspect programming on the bytecode file according to the aspect configuration content;
[0031] Write the bytecode file, after completing aspect programming, into the application.
[0032] Optionally, the aspect programming tool is pre-configured with a thread pool, which includes several threads. The aspect programming capability invocation module is specifically used for:
[0033] The threads read the bytecode files respectively and call the target aspect programming capability in the aspect programming tool to perform aspect programming on the bytecode files according to the aspect configuration content.
[0034] Optionally, the aspect programming capabilities each have a corresponding processing priority, which includes: an aspect programming capability sorting module, used to: when there are at least two target aspect programming capabilities, sort the target aspect programming capabilities according to the processing priority corresponding to the target aspect programming capabilities; and the aspect programming capability invocation module, specifically used to: sequentially invoke the target aspect programming capabilities in the aspect programming tool according to the sorting, so as to perform aspect programming on the application according to the corresponding aspect configuration content.
[0035] Optionally, the device further includes:
[0036] The configuration error message module is used to output a message indicating an error in the configuration of the aspect configuration file if the parsing of the aspect configuration file fails.
[0037] Optionally, the entry plugin is configured in the developer toolkit (SDK) of the aspect programming tool; the aspect programming tool supports multiple compilation and build systems, including at least one of the following: Gradle and Maven; the aspect configuration file format supported by the aspect programming tool includes at least one of the following: JSON, YAML, gradleDSL, and annotations.
[0038] Optionally, the aspect programming capability includes at least one of the following: method replacement, setting the method body content to null, inserting specified code into the method body, deleting method calls, object replacement, exception handling, and adding methods.
[0039] This invention also discloses an electronic device, including a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus;
[0040] The memory is used to store computer programs;
[0041] When the processor executes a program stored in the memory, it implements the method described in the embodiments of the present invention.
[0042] This invention also discloses a computer program product stored in a storage medium, which is executed by at least one processor to implement the method described in this invention.
[0043] This invention also discloses a computer-readable storage medium storing instructions that, when executed by one or more processors, cause the processors to perform the methods described in this invention.
[0044] The embodiments of the present invention have the following advantages:
[0045] In this embodiment of the invention, an aspect-oriented programming (AOP) tool is provided for developers. This AOP tool pre-encapsulates several AOP capabilities. When AOP is required for an application, developers can configure a corresponding AOP configuration file for the application. The AOP tool reads the configuration file and parses it to determine the AOP configuration content and the corresponding target AOP capabilities. Then, the target AOP capabilities can be invoked to perform AOP on the application according to the configuration content. The AOP tool in this embodiment encapsulates several AOP capabilities, shielding developers from the complex bytecode-level modifications involved in low-level AOP processing. Developers can fulfill their AOP development needs by configuring and invoking the tool's capabilities, making AOP simpler, more convenient, and more efficient. Furthermore, the AOP tool provides developers with more stable and high-quality AOP capabilities, reducing the risk of exceptions associated with using AOP during development. Attached Figure Description
[0046] Figure 1 This is a schematic diagram of an application environment provided in an embodiment of the present invention;
[0047] Figure 2 This is a flowchart illustrating the steps of an aspect programming method provided in an embodiment of the present invention;
[0048] Figure 3 This is a structural block diagram of an aspect programming tool provided in an embodiment of the present invention;
[0049] Figure 4 This is a structural block diagram of an AOP Handler processing chain provided in an embodiment of the present invention;
[0050] Figure 5 This is a structural block diagram of a section programming device provided in an embodiment of the present invention;
[0051] Figure 6 This is a schematic diagram of the hardware structure of an electronic device that implements various embodiments of the present invention. Detailed Implementation
[0052] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, the present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments.
[0053] First, some terms used in the embodiments of the present invention will be introduced.
[0054] ASM: ASM is an open-source, general-purpose Java bytecode manipulation and analysis framework that can be used to implement AOP (Aspect-Oriented Programming) capabilities during the application's code compilation phase.
[0055] Java: Java is a widely used computer programming language with cross-platform, object-oriented, and generic programming features. It is widely used in enterprise-level web application development and mobile application development.
[0056] Android: Android is an open-source mobile operating system based on the Linux kernel and other open-source software.
[0057] Android App: App is short for Application. An Android App is an application that runs on a terminal device running the Android operating system. Android Apps can be written and developed using the Java language.
[0058] Gradle: Gradle is an open-source tool for automating project builds based on the concepts of Apache Ant (a tool that links and automates software compilation, testing, deployment, and other steps) and Apache Maven (a Java project build tool).
[0059] Android Gradle Plugin: The Android Gradle Plugin is a plugin that enables custom build logic under the Gradle build rules.
[0060] Maven manages the build of software development projects based on POM (Project Object Model). POM is Maven's description of a single software project, usually existing in the form of a pom.xml file.
[0061] Maven Plugin: A Maven Plugin is a plugin that enables custom build logic under Maven build rules.
[0062] SDK: SDK stands for Software Development Kit. It is a collection of development tools that software engineers use to build applications for specific software packages, software frameworks, hardware platforms, operating systems, etc.
[0063] The aspect programming method provided in this embodiment of the invention can be applied to, for example... Figure 1In the application environment shown, electronic device 101 is equipped with an aspect programming tool. The aspect programming tool pre-encapsulates several aspect programming capabilities. The aspect programming tool reads the aspect configuration file configured for the application, parses the aspect configuration file, determines the aspect configuration content for the application and the target aspect programming capabilities corresponding to the aspect configuration content, and calls the target aspect programming capabilities in the aspect programming tool to perform aspect programming on the application according to the aspect configuration content.
[0064] In practical applications, electronic device 101 may include, but is not limited to, various personal computers, laptops, smartphones, tablets, vehicle terminals, portable wearable devices or servers. The server may be an independently operating server or a server cluster composed of multiple servers, wherein the server may be a cloud server.
[0065] Reference Figure 2 The diagram illustrates a flowchart of an aspect programming method provided in an embodiment of the present invention, applied to an aspect programming tool. The aspect programming tool pre-encapsulates several aspect programming capabilities, specifically including the following steps:
[0066] Step 201: Read the aspect configuration file for the application.
[0067] Step 202: Parse the aspect configuration file to determine the aspect configuration content for the application and the target aspect programming capability corresponding to the aspect configuration content.
[0068] Step 203: Invoke the target aspect programming capability in the aspect programming tool to perform aspect programming on the application according to the aspect configuration content.
[0069] The aspect-oriented programming (AOP) tool, also known as EasyAOP, provides developers with several general AOP capabilities. In this embodiment, the AOP tool shields developers from the complex bytecode-level modifications involved in the underlying AOP process. Developers only need to generate an AOP configuration file based on their needs, submit it to the AOP tool, and then, after successful parsing, invoke the corresponding AOP capabilities to implement the AOP. The AOP tool supports at least one of the following formats for its AOP configuration files: JSON, YAML, Gradle DSL, and annotations.
[0070] For example, aspect-oriented programming tools can provide developers with at least one of the following aspect-oriented programming capabilities: method substitution (proxies), setting method bodies to null, inserting specified code into method bodies, deleting method calls, object substitution, exception handling, and adding methods. Here, aspect configuration content refers to the specific aspect-oriented programming content that developers configure in the aspect configuration file, specifying the desired implementation. For example, they might want to proxy method calls from method A to method B through aspect substitution, insert specified code into the application, delete method calls from the application, add method D to the application, and so on.
[0071] As specific examples, the following are descriptions of aspect programming capabilities and examples of aspect configuration files:
[0072] I. Method proxy (replacement):
[0073] Description: Replace method A calls with method B calls via aspect programming. Aspect-based method replacement supports both static and object methods.
[0074] An example of an aspect configuration file used for method proxy (replacement) calls is shown below:
[0075]
[0076]
[0077] The aspect configuration file mentioned above replaces the call proxy of method d in the android.util.Log class with the call proxy of method d in the com.xxx.LogProxy class. Therefore, the target aspect programming capability is the method proxy (replacement) in the aspect programming tool.
[0078] 2. Set the method body content to empty.
[0079] Note: For the specified method, emptying the contents of the method body will make the original method an empty method, and all calls to this method will return the set value or the default value.
[0080] An example of an aspect configuration file used to set the content of a method call to null is shown below:
[0081]
[0082] The aspect configuration file mentioned above sets the content of the test method body in the com.xxx.MainActivity class to empty.
[0083] III. Inserting specified code into the method body
[0084] Note: For the selected method body, specific code is inserted during the entry and exit phases.
[0085] An aspect configuration file used to insert specified code into the body of a called method, as shown in the following example:
[0086]
[0087]
[0088] The aspect configuration file mentioned above is used to insert specified method calls into the onClick and getMsg methods of the com.xxx.MainActivity class when entering and exiting.
[0089] IV. Method Call Deletion
[0090] Note: This feature uses aspect-oriented programming to remove calls to a specified method. If the method has a return value, it returns the default value or the specified value.
[0091] V. Object Replacement (Adding an Intermediate Layer)
[0092] Explanation: For object A, if we replace the construction of class A during the call with object B that inherits from A, then we can add an intermediate layer on object A.
[0093] 6. Add try...catch code protection (exception handling)
[0094] Note: Adding try...catch code to a specified method for exception handling protection can ensure that subsequent code executes normally.
[0095] VII. New Methods
[0096] Note: Adds a method to the specified object. The method can be a static method or an object method.
[0097] It should be noted that the aspect programming capabilities of the aforementioned aspect programming tools are merely examples. Aspect programming tools can also support the extension of other general aspect programming capabilities, enabling continuous iteration of aspect programming tools to meet the more common development needs of developers in aspect programming.
[0098] In this embodiment of the invention, if developers need to perform aspect programming on an application, they can configure an aspect configuration file for the application to call aspect programming capabilities in the aspect programming tool. The aspect programming tool reads and parses this aspect configuration file to determine the target aspect programming capability to be called and the aspect configuration content, and then performs aspect programming on the application according to the aspect configuration content. Optionally, the aspect programming tool can also provide developers with templates for aspect configuration files to call the corresponding aspect programming capabilities, enabling developers to quickly complete the configuration based on the templates, which not only improves the configuration efficiency of developers but also improves the accuracy of the configuration.
[0099] In the aforementioned aspect-oriented programming (AOP) method, an AOP tool is provided for developers. This tool pre-encapsulates several AOP capabilities. When AOP is required for an application, developers can configure a corresponding AOP configuration file for the application. The AOP tool reads this configuration file, parses it to determine the AOP configuration content and the corresponding target AOP capabilities, and then calls the target AOP capabilities to implement AOP for the application based on the configuration content. The AOP tool in this embodiment encapsulates several AOP capabilities, shielding developers from the complex bytecode-level modifications involved in low-level AOP processing. Developers can fulfill their AOP development needs by configuring and calling the tool's capabilities, making AOP simpler, more convenient, and more efficient. Furthermore, the AOP tool provides developers with more stable and high-quality AOP capabilities, reducing the risk of exceptions associated with AOP during development.
[0100] Based on the above embodiments, modified embodiments of the above embodiments are proposed. It should be noted that, in order to keep the description brief, only the differences from the above embodiments are described in the modified embodiments.
[0101] In an exemplary embodiment, the aspect programming tool includes an entry plugin for accessing the application. Step 203, invoking the target aspect programming capability in the aspect programming tool to perform aspect programming on the application according to the aspect configuration content, may include the following steps:
[0102] The bytecode file of the application is read through the entry plugin;
[0103] The target aspect programming capability in the aspect programming tool is invoked to perform aspect programming on the bytecode file according to the aspect configuration content;
[0104] Write the bytecode file, after completing aspect programming, into the application.
[0105] The aspect programming tool includes an entry plugin. The entry plugin reads the aspect configuration file input by the developer and iterates through the application's class files (binary bytecode files) input by the build system. After parsing the aspect configuration file to determine the aspect configuration content and target aspect programming capabilities, it can call the target aspect programming capabilities in the aspect programming tool, perform aspect programming on the bytecode file according to the aspect configuration content, and rewrite the bytecode file after aspect programming is completed into the application.
[0106] In practical implementation, both Gradle and Maven are Java project management, compilation, packaging, and building tools; that is, both are compilation and build systems with compilation capabilities. Gradle is widely used in Android App building, while Maven is widely used in packaging and building backend (Server) projects. As an example, aspect-oriented programming (AOP) tools can set corresponding entry plugins for different compilation and build systems. For example, an entry plugin called Android Gradle Plugin can be set for the Gradle compilation and build system, enabling AOP tools to access the bytecode files of Android Apps. Similarly, an entry plugin called Maven Plugin can be set for the Maven compilation and build system, enabling AOP tools to access the bytecode files of Maven projects. Optionally, AOP tools can also set other entry plugins. For example, a Test entry point can be set, which can serve as the test entry point for the AOP tool to test logic. The entry plugins in this embodiment of the invention are diverse, allowing AOP tools to easily support (be compatible with) multiple compilation and build systems. With the addition of compatible entry plugins, AOP tools can support aspect-oriented programming for all compilation and build systems using Java as the language.
[0107] In practical implementation, the entry plugin for aspect programming tools can be uniformly encapsulated in the entry point of the aspect programming tool's SDK. In this way, the common aspect programming capabilities encapsulated in the aspect programming tool can be called through a unified entry point, and the SDK facilitates the reuse and updating of aspect programming tools, etc.
[0108] Reference Figure 3 This is a structural block diagram of aspect-oriented programming provided in an embodiment of the present invention. Figure 3This includes an entry point for aspect-oriented programming (AOP) tools. This entry point has corresponding plugins for different build systems and requirements, such as the Android Gradle Plugin, Maven Plugin, and Test entry point. Furthermore, the AOP tools provide various AOP capabilities, including method proxy (replacement), setting method bodies to null, inserting specified code into method bodies, deleting method calls, object replacement (adding an intermediate layer), adding try...catch code protection, and adding new methods. Developers configure aspect configuration files as needed, and then the entry point reads and parses the application's class files and aspect configuration files. If parsing is successful, the corresponding target aspect-oriented programming capability can be invoked to complete the aspect-oriented programming on the class file, and the aspect-oriented class file with completed aspect-oriented programming is then rewritten into the application.
[0109] In the above exemplary embodiments, the aspect programming tool can read bytecode files of various compilation and build system applications through the entry plugin, and can also call the target aspect programming capabilities in the aspect programming tool through the entry plugin to perform aspect programming on the bytecode files, and write the bytecode files after aspect programming is completed into the application. Since the entry plugin of this embodiment is encapsulated in the entry point of a unified SDK, the aspect programming capabilities in the aspect programming tool can be called uniformly through the entry point of the SDK, and the aspect programming tool can be conveniently updated and extended based on the SDK.
[0110] In an exemplary embodiment, the aspect programming capabilities each have a corresponding processing priority. After parsing the aspect configuration file and determining the aspect configuration content for the application and the target aspect programming capabilities corresponding to the aspect configuration content, the method may further include the following steps:
[0111] When there are at least two target aspect programming capabilities, the target aspect programming capabilities are sorted according to their processing priorities.
[0112] The step of invoking the target aspect programming capability in the aspect programming tool to perform aspect programming on the application according to the aspect configuration content may include the following steps:
[0113] The target aspect programming capabilities in the aspect programming tool are invoked sequentially according to the order, so as to perform aspect programming on the application according to the corresponding aspect configuration content.
[0114] In practical implementation, aspect programming tools can provide a variety of aspect programming capabilities. These aspect programming capabilities can be used individually or in combination. Multiple aspect programming capabilities can be configured for the same bytecode file for aspect programming.
[0115] In this embodiment of the invention, the input aspect configuration file is validated and parsed. If the aspect configuration file is configured correctly, and parsing reveals that a single aspect configuration file contains multiple aspect configurations, then multiple target aspect programming capabilities need to be invoked when processing the same class file. Therefore, further preprocessing is required. Specifically, preprocessing involves sorting the execution order of the target aspect programming capabilities to optimize the aspect programming logic, reduce unnecessary aspect programming, or improve aspect programming efficiency. For example, if a class file configures method deletion, method body nulling, and method call proxy for method A, it's understandable that if method A is deleted, there's no need to perform subsequent aspect programming such as method body nulling and method call proxying for method A. This would only increase unnecessary processing and create redundancy in the aspect programming logic. To address this issue, this embodiment of the invention sets corresponding processing priorities for different aspect programming capabilities. For example, the priority of method deletion can be higher than that of method body nulling, and the priority of method body nulling can be higher than that of method call proxying. Of course, in specific implementations, the processing priority can be adjusted according to actual needs, and the embodiments of the present invention do not impose any restrictions on this.
[0116] Specifically, if an aspect configuration file contains multiple aspect configurations, then there are also multiple target aspect programming capabilities that need to be invoked. When processing the same class file, the target aspect programming capabilities need to be sorted according to processing priority. After sorting, an aspect programming sequence (AOP Handler processing chain) for that class file can be obtained. Each aspect programming process can be called an AOP Handler.
[0117] In this embodiment of the invention, the aspect-oriented programming (AOP) tool iterates through and reads class files in the build system. These class files exist in multiple locations within the build system, such as class files generated from Java source code and class files within JAR packages (various SDKs). The AOP tool's entry point collects all these class files together. Each class file is read into memory only once. After reading, the class files are processed sequentially according to the AOP Handler processing chain. After processing in the AOP Handler chain, the processed class files are written back into the build system. Each class file can have a corresponding descriptor object containing the aspect modification configuration and various other data to assist in aspect-oriented programming.
[0118] In the above exemplary embodiment, a corresponding processing priority is set for each aspect programming capability. Then, when there are at least two target aspect programming capabilities, aspect programming is performed on the bytecode file sequentially according to the processing priority corresponding to the target aspect programming capabilities, thereby optimizing the aspect programming processing logic and improving the overall aspect programming efficiency.
[0119] In an exemplary embodiment, the aspect programming tool is pre-configured with a thread pool, which includes several threads. Calling the target aspect programming capability in the aspect programming tool to perform aspect programming on the bytecode file according to the aspect configuration may include the following steps:
[0120] The threads read the bytecode files respectively and call the target aspect programming capability in the aspect programming tool to perform aspect programming on the bytecode files according to the aspect configuration content.
[0121] In this embodiment of the invention, in order to improve the efficiency of aspect programming, a thread pool is set in the aspect programming tool. The thread pool can include several threads. When multiple bytecode files of the application need to be read, the bytecode files can be read simultaneously by the threads in the thread pool. Furthermore, the threads can also be used to execute in parallel the calling of the target aspect programming capabilities in the aspect programming tool, as well as to perform aspect programming on the bytecode files according to the aspect configuration content.
[0122] Figure 4This is a structural block diagram of an AOP Handler processing chain provided in an embodiment of the present invention. The aspect programming tool can obtain class A, class B, and class C from the class files in the compilation and build system. The thread pool of the aspect programming tool can include Thread1, Thread2, and Thread3. For class A, Thread1 can perform aspect programming according to the AOP Handler processing chain composed of Handler_a, Handler_b, and Handler_c to obtain the aspect-programmed class A'. For class B, Thread2 can perform aspect programming according to the AOP Handler processing chain composed of Handler_b and Handler_c to obtain the aspect-programmed class B'. For class C, Thread3 can perform aspect programming according to the AOP Handler processing chain composed of Handler_d, Handler_e, and Handler_f to obtain the aspect-programmed class C'.
[0123] In the above exemplary embodiments, the efficiency of aspect programming can be improved by using several threads set in the aspect programming tool to process the application's bytecode file in parallel.
[0124] In one exemplary embodiment, after reading the aspect configuration file for the application configuration, the method may further include the following steps:
[0125] If parsing the aspect configuration file fails, an error message indicating a configuration error in the aspect configuration file will be output.
[0126] In this embodiment of the invention, the input aspect configuration file is validated and parsed. If the aspect configuration file is configured incorrectly, the aspect programming tool can provide developers with a prompt indicating the configuration error, so as to remind developers to reconfigure.
[0127] In the exemplary embodiments described above, by providing error messages for the aspect configuration file, developers can be reminded to reconfigure it to ensure that aspect programming of the application proceeds normally.
[0128] In summary, the aspect programming tool of this invention allows developers to fulfill aspect programming development needs more simply, conveniently, and efficiently through configuration-based methods. The tool supports a rich set of general-purpose aspect programming capabilities, meeting over 80% of developers' daily aspect requirements. Furthermore, the tool supports the expansion of these general-purpose capabilities, and with continuous iteration, it can satisfy even more everyday aspect needs.
[0129] It should be noted that, for the sake of simplicity, the method embodiments are all described as a series of actions. However, those skilled in the art should understand that the embodiments of the present invention are not limited to the described order of actions, because according to the embodiments of the present invention, some steps can be performed in other orders or simultaneously. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are preferred embodiments, and the actions involved are not necessarily essential to the embodiments of the present invention.
[0130] Reference Figure 5 The diagram illustrates a structural block diagram of an aspect programming device provided in an embodiment of the present invention. This device is applied to an aspect programming tool, which pre-encapsulates several aspect programming capabilities. Specifically, the device may include the following modules:
[0131] Aspect configuration file reading module 501 is used to read the aspect configuration file configured for the application;
[0132] The aspect configuration file parsing module 502 is used to parse the aspect configuration file to determine the aspect configuration content for the application and the target aspect programming capability corresponding to the aspect configuration content;
[0133] The aspect programming capability invocation module 503 is used to invoke the target aspect programming capability in the aspect programming tool to perform aspect programming on the application according to the aspect configuration content.
[0134] In one exemplary embodiment, the aspect programming tool includes an entry plugin for accessing the application, and the aspect programming capability invocation module 503 is specifically used for:
[0135] The bytecode file of the application is read through the entry plugin;
[0136] The target aspect programming capability in the aspect programming tool is invoked to perform aspect programming on the bytecode file according to the aspect configuration content;
[0137] Write the bytecode file, after completing aspect programming, into the application.
[0138] In an exemplary embodiment, the aspect programming tool is pre-configured with a thread pool, which includes several threads. The aspect programming capability invocation module 503 is specifically used for:
[0139] The threads read the bytecode files respectively and call the target aspect programming capability in the aspect programming tool to perform aspect programming on the bytecode files according to the aspect configuration content.
[0140] In one exemplary embodiment, the aspect programming capabilities each have a corresponding processing priority. This includes: an aspect programming capability sorting module, configured to: when there are at least two target aspect programming capabilities, sort the target aspect programming capabilities according to their corresponding processing priorities; and an aspect programming capability invocation module 503, specifically configured to: sequentially invoke the target aspect programming capabilities in the aspect programming tool according to the sorting, so as to perform aspect programming on the application according to the corresponding aspect configuration content.
[0141] In one exemplary embodiment, the apparatus may further include:
[0142] The configuration error message module is used to output a message indicating an error in the configuration of the aspect configuration file if the parsing of the aspect configuration file fails.
[0143] In one exemplary embodiment, the entry plugin is configured in the developer toolkit (SDK) of the aspect programming tool; the aspect programming tool supports multiple build systems, including at least one of the following: Gradle and Maven; the aspect configuration file format supported by the aspect programming tool includes at least one of the following: JSON, YAML, gradle DSL, and annotations.
[0144] In one exemplary embodiment, the aspect programming capability includes at least one of the following: method replacement, setting the method body content to null, inserting specified code into the method body, deleting method calls, object replacement, exception handling, and adding methods.
[0145] The aspect programming tool in this embodiment of the invention encapsulates several aspect programming capabilities. Since the aspect programming tool shields the complex bytecode-level modifications involved in the underlying aspect programming process, developers can call the aspect programming capabilities of the aspect programming tool through configuration to complete the development requirements of aspect programming classes, making aspect programming simpler, more convenient, and more efficient. In addition, since the aspect programming tool can provide developers with more stable and high-quality aspect programming capabilities, it reduces the risk of anomalies caused by using aspect programming in the development process.
[0146] As the device embodiment is basically similar to the method embodiment, the description is relatively simple, and relevant parts can be found in the description of the method embodiment.
[0147] In addition, this invention also provides an electronic device, including: a processor, a memory, and a computer program stored in the memory and executable on the processor. When the computer program is executed by the processor, it implements the various processes of the above-described aspect programming method embodiments and achieves the same technical effect. To avoid repetition, it will not be described again here.
[0148] This invention also provides a computer-readable storage medium storing a computer program. When the computer program is executed by a processor, it implements the various processes of the above-described aspect-oriented programming method embodiments and achieves the same technical effects. To avoid repetition, it will not be described again here. The computer-readable storage medium may be a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.
[0149] This invention also provides a computer program product, which is stored in a storage medium and executed by at least one processor to implement the various processes of the aspect programming method embodiments described above, and can achieve the same technical effect. To avoid repetition, it will not be described again here.
[0150] Figure 6 A schematic diagram of the hardware structure of an electronic device for implementing various embodiments of the present invention.
[0151] The electronic device 600 includes, but is not limited to, components such as: a radio frequency unit 601, a network module 602, an audio output unit 603, an input unit 604, a sensor 605, a display unit 606, a user input unit 607, an interface unit 608, a memory 609, a processor 610, and a power supply 611. Those skilled in the art will understand that... Figure 6 The electronic device structures shown are not intended to limit the electronic device. An electronic device may include more or fewer components than shown, or combine certain components, or have different component arrangements. In embodiments of the present invention, the electronic device includes, but is not limited to, mobile phones, tablet computers, laptops, PDAs, in-vehicle terminals, wearable devices, and pedometers.
[0152] It should be understood that, in this embodiment of the invention, the radio frequency unit 601 can be used for receiving and transmitting signals during information transmission or calls. Specifically, it receives downlink data from the base station and processes it with the processor 610; additionally, it transmits uplink data to the base station. Typically, the radio frequency unit 601 includes, but is not limited to, an antenna, at least one amplifier, a transceiver, a coupler, a low-noise amplifier, a duplexer, etc. Furthermore, the radio frequency unit 601 can also communicate with networks and other devices through a wireless communication system.
[0153] The electronic device provides users with wireless broadband internet access through the network module 602, such as helping users send and receive emails, browse web pages, and access streaming media.
[0154] The audio output unit 603 can convert audio data received by the radio frequency unit 601 or the network module 602 or stored in the memory 609 into audio signals and output them as sound. Furthermore, the audio output unit 603 can also provide audio output related to specific functions performed by the electronic device 600 (e.g., call signal reception sound, message reception sound, etc.). The audio output unit 603 includes a speaker, a buzzer, and a receiver, etc.
[0155] Input unit 604 is used to receive audio or video signals. Input unit 604 may include a graphics processing unit (GPU) 6041 and a microphone 6042. GPU 6041 processes image data of still images or videos acquired by an image capture device (such as a camera) in video capture mode or image capture mode. The processed image frames can be displayed on display unit 606. The image frames processed by GPU 6041 can be stored in memory 609 (or other storage medium) or transmitted via radio frequency unit 601 or network module 602. Microphone 6042 can receive sound and process such sound into audio data. The processed audio data can be converted into a format that can be transmitted to a mobile communication base station via radio frequency unit 601 in telephone call mode.
[0156] The electronic device 600 also includes at least one sensor 605, such as a light sensor, a motion sensor, and other sensors. Specifically, the light sensor includes an ambient light sensor and a proximity sensor. The ambient light sensor can adjust the brightness of the display panel 6061 according to the ambient light level, and the proximity sensor can turn off the display panel 6061 and / or backlight when the electronic device 600 is moved to the ear. As a type of motion sensor, an accelerometer sensor can detect the magnitude of acceleration in various directions (generally three axes). When stationary, it can detect the magnitude and direction of gravity and can be used to identify the posture of the electronic device (such as landscape / portrait switching, related games, magnetometer posture calibration), vibration recognition related functions (such as pedometer, tapping), etc. The sensor 605 may also include a fingerprint sensor, pressure sensor, iris sensor, molecular sensor, gyroscope, barometer, hygrometer, thermometer, infrared sensor, etc., which will not be described in detail here.
[0157] The display unit 606 is used to display information input by the user or information provided to the user. The display unit 606 may include a display panel 6061, which may be configured in the form of a liquid crystal display (LCD), an organic light-emitting diode (OLED), or the like.
[0158] User input unit 607 can be used to receive input numerical or character information, and to generate key signal inputs related to user settings and function control of electronic devices. Specifically, user input unit 607 includes a touch panel 6071 and other input devices 6072. Touch panel 6071, also known as a touch screen, can collect touch operations performed by the user on or near it (such as operations performed by the user using a finger, stylus, or any suitable object or accessory on or near touch panel 6071). Touch panel 6071 may include two parts: a touch detection device and a touch controller. The touch detection device detects the user's touch position and the signal generated by the touch operation, and transmits the signal to the touch controller; the touch controller receives touch information from the touch detection device, converts it into touch point coordinates, and sends it to the processor 610, which receives and executes commands from the processor 610. In addition, touch panel 6071 can be implemented using various types such as resistive, capacitive, infrared, and surface acoustic wave. Besides touch panel 6071, user input unit 607 may also include other input devices 6072. Specifically, other input devices 6072 may include, but are not limited to, physical keyboards, function keys (such as volume control buttons, power buttons, etc.), trackballs, mice, joysticks, etc., which will not be described in detail here.
[0159] Furthermore, the touch panel 6071 can cover the display panel 6061. When the touch panel 6071 detects a touch operation on or near it, it transmits the information to the processor 610 to determine the type of touch event. Subsequently, the processor 610 provides corresponding visual output on the display panel 6061 based on the type of touch event. Although in Figure 6 In this embodiment, the touch panel 6071 and the display panel 6061 are two independent components to realize the input and output functions of the electronic device. However, in some embodiments, the touch panel 6071 and the display panel 6061 can be integrated to realize the input and output functions of the electronic device. The specific implementation is not limited here.
[0160] Interface unit 608 serves as an interface for connecting external devices to electronic device 600. For example, external devices may include a wired or wireless headphone port, an external power supply (or battery charger) port, a wired or wireless data port, a memory card port, a port for connecting a device with an identification module, an audio input / output (I / O) port, a video I / O port, a headphone port, and so on. Interface unit 608 can be used to receive input from external devices (e.g., data, power, etc.) and transmit the received input to one or more components within electronic device 600, or it can be used to transmit data between electronic device 600 and external devices.
[0161] The memory 609 can be used to store software programs and various data. The memory 609 may primarily include a program storage area and a data storage area. The program storage area may store the operating system, applications required for at least one function (such as sound playback, image playback, etc.), etc.; the data storage area may store data created based on the use of the mobile phone (such as audio data, phonebook, etc.). Furthermore, the memory 609 may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other volatile solid-state storage device.
[0162] The processor 610 is the control center of the electronic device. It connects various parts of the electronic device via various interfaces and lines. By running or executing software programs and / or modules stored in the memory 609, and by calling data stored in the memory 609, it performs various functions and processes data, thereby providing overall monitoring of the electronic device. The processor 610 may include one or more processing units; preferably, the processor 610 may integrate an application processor and a modem processor. The application processor mainly handles the operating system, user interface, and applications, while the modem processor mainly handles wireless communication. It is understood that the modem processor may not be integrated into the processor 610.
[0163] The electronic device 600 may also include a power supply 611 (such as a battery) for supplying power to various components. Preferably, the power supply 611 is logically connected to the processor 610 through a power management system, thereby enabling functions such as managing charging, discharging, and power consumption through the power management system.
[0164] In addition, the electronic device 600 includes some functional modules not shown, which will not be described in detail here.
[0165] 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, method, article, or apparatus 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, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.
[0166] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes several instructions to cause a terminal (which may be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in the various embodiments of the present invention.
[0167] The embodiments of the present invention have been described above with reference to the accompanying drawings. However, the present invention is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of the present invention without departing from the spirit and scope of the claims, and all of these forms are within the protection scope of the present invention.
[0168] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed in this invention can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this invention.
[0169] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0170] In the embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative. For instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.
[0171] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0172] In addition, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.
[0173] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this invention, essentially, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, ROM, RAM, magnetic disks, or optical disks.
[0174] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in the present invention should be included within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.
Claims
1. An aspect-oriented programming method, characterized in that, This is applied to an aspect-oriented programming (AOP) tool, which pre-encapsulates several AOP capabilities and includes an entry point plugin for integrating with an application. The AOP capabilities include at least one of the following: method replacement, setting the method body to null, inserting specified code into the method body, deleting method calls, object replacement, exception handling, and adding methods. The entry point plugin is configured for different compilation and build systems. The methods include: Read the aspect configuration file for the application; the aspect configuration file is configured according to the template provided by the aspect programming tool; The aspect configuration file is parsed to determine the aspect configuration content for the application and the target aspect programming capabilities corresponding to the aspect configuration content; each aspect programming capability has a corresponding processing priority; the processing priority includes the priority of method deletion being higher than the priority of method body nullification, and the priority of method body nullification being higher than the priority of method call proxy. When there are at least two target aspect programming capabilities, the target aspect programming capabilities are sorted according to their processing priority to reduce redundancy in aspect programming logic. The target aspect programming capabilities in the aspect programming tool are invoked sequentially according to the stated order to perform aspect programming on the application based on the aspect configuration content. This includes: reading the application's bytecode file through the entry plugin; each bytecode file corresponds to a description object, which includes the aspect modification configuration of the bytecode file to assist in aspect programming; invoking the target aspect programming capabilities in the aspect programming tool sequentially according to the stated order to perform aspect programming on the bytecode file based on the aspect configuration content; and writing the bytecode file after aspect programming is completed into the application.
2. The method according to claim 1, characterized in that, The aspect programming tool is pre-configured with a thread pool containing several threads. Calling the target aspect programming capability within the tool to perform aspect programming on the bytecode file according to the aspect configuration includes: The threads read the bytecode files respectively and call the target aspect programming capability in the aspect programming tool to perform aspect programming on the bytecode files according to the aspect configuration content.
3. The method according to claim 1, characterized in that, After reading the aspect configuration file configured for the application, the method further includes: If parsing the aspect configuration file fails, an error message indicating a configuration error in the aspect configuration file will be output.
4. The method according to claim 1, characterized in that, The entry plugin is configured in the developer toolkit (SDK) of the aspect programming tool; The aspect-oriented programming tool supports multiple build systems, including at least one of the following: Gradle and Maven; The aspect programming tool supports aspect configuration file formats that include at least one of the following: JSON, YAML, gradle DSL, and annotations.
5. A section programming device, characterized in that, An aspect-oriented programming (AOP) tool is provided, which pre-encapsulates several AOP capabilities and includes an entry point plugin for integrating with an application. These AOP capabilities include at least one of the following: method replacement, setting a method body to null, inserting specified code into a method body, deleting method calls, object replacement, exception handling, and adding methods. The entry point plugin is configured for different compilation and build systems. The device includes: An aspect configuration file reading module is used to read the aspect configuration file configured for the application; the aspect configuration file is configured according to the template provided by the aspect programming tool; An aspect configuration file parsing module is used to parse the aspect configuration file to determine the aspect configuration content for the application and the target aspect programming capability corresponding to the aspect configuration content; the aspect programming capability has a corresponding processing priority; the processing priority includes the priority of method deletion being higher than the priority of method body nullification, and the priority of method body nullification being higher than the priority of method call proxy; The aspect programming capability sorting module is used to sort the target aspect programming capabilities according to the processing priority corresponding to the target aspect programming capabilities when there are at least two target aspect programming capabilities, so as to reduce the redundancy of aspect programming logic. The aspect programming capability invocation module is used to sequentially invoke the target aspect programming capabilities in the aspect programming tool according to the stated order, so as to perform aspect programming on the application according to the aspect configuration content. This includes: reading the application's bytecode file through the entry plugin; each bytecode file corresponds to a description object, which includes the aspect modification configuration of the bytecode file to assist in aspect programming; sequentially invoking the target aspect programming capabilities in the aspect programming tool according to the stated order, so as to perform aspect programming on the bytecode file according to the aspect configuration content; and writing the bytecode file after aspect programming is completed into the application.
6. An electronic device, characterized in that, It includes a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus; The memory is used to store computer programs; When the processor executes a program stored in the memory, it implements the method as described in any one of claims 1-4.
7. A computer-readable storage medium having instructions stored thereon that, when executed by one or more processors, cause the processors to perform the method as described in any one of claims 1-4.