Program annotation compilation method and corresponding device, equipment and medium
By extracting and filtering interface classes and implementing class code sets in software development applications, building the source code library of the target channel and creating class files, the problem of differentiated compilation in the existing technology is solved, and the code resources are simplified The reuse of multi-channel code resources improves development efficiency.
Patent Information
- Application Number
- CN202110170870.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-02-08
- Publication Date
- 2025-02-25
- Estimated Expiration
- 2041-02-08
AI Technical Summary
Existing software development applications cannot be compiled differently by channel, resulting in the development team being unable to customize the compilation according to needs, and there are redundant development resources in the code resources.
By extracting the code set annotated with interface class and implementation class identifiers, a summary source code library is built, and the source code library of the target channel is filtered out, the mapping relationship between interface class and implementation class is constructed, and corresponding class files are created to realize channel customization. Compile.
Differentiated compilation for target channels is achieved, redundancy of code resources is reduced, development efficiency is improved, and multi-channel code resources are supported.
Smart Images

Figure CN112817600B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer software development, and in particular to a program annotation compilation method, device and corresponding electronic equipment and non-volatile storage medium. Background Art
[0002] With the development of the Internet, the number of Internet users is also increasing day by day, and major Internet companies are also developing various types of applications to meet the needs of Internet users. Nowadays, Internet companies' software projects generally use existing software development applications to develop software development projects that meet corresponding needs, in order to save development time and development costs and improve the development efficiency of software projects.
[0003] However, the code resources of the same software development project compiled by today's software development applications cannot be compiled differently by channel, resulting in each development team being unable to customize the compilation of code resources to meet their development needs.
[0004] Secondly, the resources that developers compile for their development needs based on software development applications will include non-essential development resources such as code resources and image resources for other development needs, which will make the code resources and file resources contained in the code resources redundant.
[0005] In view of the various problems that affect software development in existing technologies, it is necessary to explore some effective solutions. Summary of the invention
[0006] One of the purposes of the present application is to solve at least one of the above problems and provide a program annotation compilation method and its corresponding device, electronic device, and non-volatile storage medium.
[0007] In order to meet the various objectives of this application, this application adopts the following technical solutions:
[0008] A program annotation compilation method provided for one of the purposes of this application comprises the following steps:
[0009] Extracting an interface class code set annotated with an interface class identifier and an implementation class code set annotated with an implementation class identifier from the code resources of the program to form a summary source code library;
[0010] Filtering the aggregated source code library to remove implementation class code sets that are not annotated with the target channel identifier, thereby obtaining the source code library of the target channel;
[0011] Based on the source code library of the target channel, construct a matching information table representing the mapping relationship between the code sets of the interface class and its implementation class;
[0012] Based on the mapping relationship between the interface class and the implementation class in the matching information table, a corresponding class file in the program is created according to a preset association class naming rule, so that after the program runs and loads the class file, the interface class is passed through a query interface provided to the class file, and the query interface queries and calls the instantiated object of the implementation class corresponding to the interface class in accordance with the association class naming rule.
[0013] In a further embodiment, the step of filtering the aggregated source code library to remove the implementation class code set that is not annotated with the target channel identifier, and obtaining the source code library of the target channel includes:
[0014] Calling the aggregated source code library, determining that only one of the pre-annotated multiple channel identifiers is in an activated state, and determining it as the target channel identifier;
[0015] Searching and deleting the annotation parameters in the channel annotation identifiers corresponding to each implementation class code set from the source code library, which do not belong to the implementation class code set of the target channel identifier;
[0016] The source code library after the deletion is used as the source code library of the target channel.
[0017] In a preferred embodiment, in the step of searching and deleting from the source code library the annotation parameters in the channel annotation identifier corresponding to each implementation class code set that do not belong to the implementation class code set of the target channel identifier, the annotation parameters in the channel annotation identifier corresponding to the implementation class code set include one or more, which are respectively used to describe a private implementation class owned by a single channel identifier or a shared implementation class owned by multiple channel identifiers.
[0018] In a preferred embodiment, before the step of constructing a matching information table representing the mapping relationship between the code sets of the interface class and its implementation class based on the source code library of the target channel, the method includes:
[0019] Verify whether the target channel source code library contains implementation class code sets corresponding to the interface classes therein. If so, the verification is passed to execute subsequent steps. Otherwise, the compilation is terminated and an alarm is issued.
[0020] In a further embodiment, the step of passing the interface class to the interface provided by the class file, and the interface following the association class naming rule to query and call the implementation class corresponding to the interface class in the class file according to the interface class includes:
[0021] Triggering the calling of one of the interface classes, querying the query interface for the interface class;
[0022] The query interface converts the interface class into an implementation class in the class file according to the association class naming rule;
[0023] The query interface instantiates the code set corresponding to the implementation class to obtain an instantiated object;
[0024] The query interface returns the instantiated object and executes it.
[0025] In a further embodiment, the following pre-steps are included:
[0026] Get the channel identifier set applicable to the current development project;
[0027] Creating corresponding annotation class information for each channel identifier in the channel identifier set;
[0028] The corresponding annotation class information is modified, and the channel identifier that is the same as the pre-specified current compilation identifier is marked as the target channel identifier, and the remaining channel identifiers are marked as non-target channel identifiers.
[0029] In a preferred embodiment, the following steps are included:
[0030] A corresponding code directory is created for each of the channel identifiers to store file resources or at least part of the code resources required by the corresponding channel identifier, and is added to the compilation path corresponding to the target channel identifier to participate in the compilation.
[0031] A program annotation compilation device provided for one of the purposes of the present application includes:
[0032] A source code library construction unit, used to extract an interface class code set annotated with an interface class identifier and an implementation class code set annotated with an implementation class identifier from the code resources of the program to form a summary source code library;
[0033] A source code library filtering unit is used to filter the aggregated source code library, filter out the implementation class code set that is not annotated with the target channel identifier, and obtain the source code library of the target channel;
[0034] An information table construction unit, used to construct a matching information table representing a mapping relationship between the code set of the interface class and its implementation class based on the source code library of the target channel;
[0035] A class file creation unit is used to create a corresponding class file in the program based on the mapping relationship between the interface class and the implementation class in the matching information table and according to a preset association class naming rule, so that after the program runs and loads the class file, the interface class is passed through a query interface provided to the class file, and the query interface queries and calls the instantiation object of the implementation class corresponding to the interface class in accordance with the association class naming rule.
[0036] In some embodiments, the source code library filtering unit includes:
[0037] An identification determination module, used for calling the aggregated source code library, determining that only one of the plurality of pre-annotated channel identifications is in an activated state, and determining it as the target channel identification;
[0038] A code filtering module, used for searching and deleting from the source code library the annotation parameters in the channel annotation identifiers corresponding to the various implementation class code sets that do not belong to the implementation class code set of the target channel identifier;
[0039] The source code library determination module is used to use the source code library after the deletion as the source code library of the target channel.
[0040] In some embodiments, the class file creation unit includes:
[0041] An interface class query module, used to trigger the call of one of the interface classes, and query the query interface for the interface class;
[0042] An interface class conversion module, used for converting the interface class into an implementation class in the class file according to the association class naming rule;
[0043] An instantiation module, used for the query interface to instantiate the code set corresponding to the implementation class to obtain an instantiated object;
[0044] The object returning module is used for the query interface to return and execute the instantiated object.
[0045] An electronic device provided to meet one of the purposes of the present application includes a central processing unit and a memory, wherein the central processing unit is used to call and run a computer program stored in the memory to execute the steps of the program annotation compilation method described in the present application.
[0046] A non-volatile storage medium is provided to meet another purpose of the present application, which stores a computer program implemented according to the program annotation compilation method in the form of computer-readable instructions. When the computer program is called and executed by a computer, the steps included in the method are executed.
[0047] Compared with the prior art, the advantages of this application are as follows:
[0048] First, this application provides a service for compiling for the target channel for the development method of parallel multi-channel development based on the same development project by constructing a channel customized compilation function. By extracting the interface class code set annotated with the interface class identifier and the implementation class code set annotated with the implementation class identifier from the code resources of the program, a summary source code library is constructed, and the implementation class code set that is not annotated with the target channel in the summary source code library is filtered out to form a source code library containing the implementation class code set to which the target channel belongs, and based on the mapping relationship between the implementation class code set and the interface class code set in the source code library, a matching information table is constructed so that the corresponding class file in the program is created according to the matching information table and in accordance with the naming rules of the associated class. Through this logic, when developers compile for a development project with multi-channel code resources, they can compile the code resources required for the channel for the target channel, so that the compilation of each channel is differentiated, and the code resources of other channels are prevented from existing in the class files of the target channel, causing data redundancy, and developers develop multi-channel codes in the same project. Become more systematic and safe.
[0049] Secondly, the present application constructs an annotation compilation capability, which provides corresponding annotation identifiers to confirm that the corresponding code resources are the code resources required by the target channel of the current compilation, and performs the above-mentioned channel-customized compilation for the code resources. When multiple channels are developed in parallel in the same development project, annotation identifiers of multiple different channels are written for the same code resource to achieve code resource reuse and improve the development efficiency of each channel. BRIEF DESCRIPTION OF THE DRAWINGS
[0050] The above and / or additional aspects and advantages of the present application will become apparent and easily understood from the following description of the embodiments in conjunction with the accompanying drawings, in which:
[0051] Figure 1 A schematic diagram of the compilation and execution logic architecture of the program annotation compilation method of the present application;
[0052] Figure 2 A flowchart of a typical embodiment of the program annotation compilation method of the present application;
[0053] Figure 3 for Figure 2 A schematic diagram of a flow chart formed by the specific steps of step S12;
[0054] Figure 4 for Figure 2 A schematic diagram of a flow chart formed by the specific steps of step S14;
[0055] Figure 5 A flowchart of an embodiment of the program annotation compilation method of the present application, which is composed of the added pre-steps;
[0056] Figure 6 A principle block diagram of a typical embodiment of the program annotation compilation device of the present application;
[0057] Figure 7 This is a basic structural block diagram of a computer device according to an embodiment of the present application. DETAILED DESCRIPTION
[0058] The embodiments of the present application are described in detail below, and examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present application, and cannot be interpreted as limiting the present application.
[0059] It will be understood by those skilled in the art that, unless expressly stated, the singular forms "one", "said", and "the" used herein may also include plural forms. It should be further understood that the term "comprising" used in the specification of the present application refers to the presence of the features, integers, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or groups thereof. It should be understood that when we refer to an element as being "connected" or "coupled" to another element, it may be directly connected or coupled to the other element, or there may be an intermediate element. In addition, the "connection" or "coupling" used herein may include wireless connection or wireless coupling. The term "and / or" used herein includes all or any unit and all combinations of one or more associated listed items.
[0060] It will be understood by those skilled in the art that, unless otherwise defined, all terms (including technical and scientific terms) used herein have the same meaning as those generally understood by those skilled in the art to which this application belongs. It should also be understood that terms such as those defined in general dictionaries should be understood to have meanings consistent with those in the context of the prior art, and will not be interpreted with idealized or overly formal meanings unless specifically defined as here.
[0061] It will be understood by those skilled in the art that the "client", "terminal" and "terminal device" used herein include both devices with wireless signal receivers, which are devices with only wireless signal receivers without transmission capabilities, and devices with receiving and transmitting hardware, which are devices with receiving and transmitting hardware capable of two-way communication on a two-way communication link. Such devices may include: cellular or other communication devices such as personal computers, tablet computers, which have single-line displays or multi-line displays or cellular or other communication devices without multi-line displays; PCS (Personal Communications Service, personal communication system), which can combine voice, data processing, fax and / or data communication capabilities; PDA (Personal Digital Assistant, personal digital assistant), which may include a radio frequency receiver, pager, Internet / intranet access, web browser, notepad, calendar and / or GPS (Global Positioning System, global positioning system) receiver; conventional laptop and / or palmtop computers or other devices, which have and / or include a conventional laptop and / or palmtop computer or other device with and / or including a radio frequency receiver. The "client", "terminal" and "terminal device" used herein may be portable, transportable, installed in a vehicle (air, sea and / or land), or suitable for and / or configured to run locally, and / or in a distributed form, at any other location on the earth and / or in space. The "client", "terminal" and "terminal device" used herein may also be a communication terminal, an Internet terminal, a music / video playing terminal, for example, a PDA, a MID (Mobile Internet Device) and / or a mobile phone with a music / video playing function, or a smart TV, a set-top box and other devices.
[0062] The hardware referred to by the names such as "server", "client", and "service node" in this application is essentially an electronic device with the equivalent capabilities of a personal computer. It is a hardware device with the necessary components revealed by the von Neumann principle, such as a central processing unit (including an arithmetic unit and a controller), a memory, an input device, and an output device. The computer program is stored in its memory, and the central processing unit calls the program stored in the external memory into the internal memory for execution, executes the instructions in the program, and interacts with the input and output devices to complete specific functions.
[0063] It should be pointed out that the concept of "server" referred to in this application can also be extended to the case of server clusters. According to the network deployment principle understood by those skilled in the art, the servers should be logically divided. In physical space, these servers can be independent of each other but can be called through interfaces, or integrated into a physical computer or a set of computer clusters. Those skilled in the art should understand this flexibility, and should not use it to restrict the implementation of the network deployment method of this application.
[0064] See also Figure 1 The execution logic of the relevant technical solution of this application is constructed according to the architecture shown in the figure, and the role and function of each part are revealed as follows:
[0065] The code resources 80 of the program referred to in this application include an interface class code set 81 annotated with an interface class identifier and an implementation class code set 82 annotated with an implementation class identifier, and the implementation class code set 82 has a reference relationship with the interface class code set 81.
[0066] The target channel source code library 83 referred to in this application is constructed and generated by filtering the implementation class code set 82, and filtering out the implementation class code set whose channel annotation identifier is not the target channel identifier in the implementation class code set 82 to obtain the implementation class code set that only contains the channel annotation identifier as the target channel identifier, thereby constructing the target channel source code library 83.
[0067] Based on the reference relationship between each implementation class in the target channel source code library 83 and the corresponding interface class in the interface class code set, a matching information table 84 referred to in this application is constructed so that a class file 85 can be created in accordance with the relationship between the implementation class and the interface class in the matching information table and in compliance with the naming rules of this association class.
[0068] There may be one or more class files 85 generated by the compilation for the target channel, and there may be one or more implementation classes and interface classes referenced by the implementation classes in the corresponding class files 85. When the class files 85 are loaded and run, they will provide a query interface for the application so that the application can pass the interface class through the query interface, and the query interface will query and call the instantiated object of the implementation class corresponding to the interface class in accordance with the associated class naming rules, thereby realizing the functions that the implementation class can realize.
[0069] The development device of the present application is equipped with relevant operating systems, such as Window, Mac, Linux, IOS, HMS (Hongmeng), Android and other operating systems that provide equivalent functions. With the support of such operating systems, applications adaptively developed for these operating systems can also run normally in the terminal devices. It is with the help of the operation of these applications that the terminal devices can realize human-computer interaction, remote interaction, and various indirect interactions with other terminals through remote servers.
[0070] The application referred to in this application generally means an application running on an electronic device such as a server or terminal device. These applications implement the relevant technical solutions of this application in a programming manner. Their program codes can be stored in a non-volatile storage medium recognizable by a computer in the form of computer executable instructions, and can be loaded into the memory by the central processing unit for execution. The relevant devices of this application are constructed by the operation of the application on the computer.
[0071] The code resources and code sets referred to in this application are used to describe source code data for implementation and development, which are written in a high-level computer language, such as Python, Java, C++, etc. Logically, they can form multiple branch processes with the help of transition statements such as if and case, and can be executed through execution statements, such as calling a method function through execution statements.
[0072] Those skilled in the art should be aware that, although the various methods of the present application are described based on the same concept and thus present commonality to each other, unless otherwise specified, these methods can be independently executed. Similarly, for each embodiment disclosed in the present application, they are all proposed based on the same inventive concept, therefore, concepts with the same expression, and concepts that are appropriately changed for convenience despite different expressions, should be understood as equivalent.
[0073] See also Figure 2 , a program annotation compilation method of the present application, in its typical embodiment, comprises the following steps:
[0074] Step S11, extracting an interface class code set annotated with an interface class identifier and an implementation class code set annotated with an implementation class identifier from the code resources of the program to form a summary source code library:
[0075] The aggregated source code library including the interface class code set and the implementation class code set is constructed by extracting the interface class code set annotated with the interface class identifier from the code resources of the program, and extracting one or more implementation class code sets annotated with the implementation class identifier from the code resources.
[0076] The interface class identifier and implementation class identifier are pre-set identifiers. For example, the interface class identifier can be set to @spdtExpect, and the implementation class identifier can be set to @spdtActual. When one or more interface class code sets annotated with the interface class identifier and one or more implementation class code sets annotated with the implementation class identifier exist in the code resource, the interface class code set and the implementation class code set will be extracted to form the aggregated source code library. Those skilled in the art can flexibly design the expressions of the interface class identifier and the implementation class identifier according to the actual business scenario, which will not be elaborated here.
[0077] There are one or more implementation class code sets in the aggregated source code library, and each implementation class code set carries a channel annotation identifier for characterizing its own channel, so that according to the channel annotation identifier of each implementation class code set, the implementation class code set that does not belong to the target channel is filtered, so that the data generated by the compilation operation performed according to the aggregated source code library is targeted and the computer storage memory occupied by the data is reduced. For the execution of the filtering, please refer to the subsequent steps, and this step will not be repeated.
[0078] The target channel refers to the channel targeted by the data generated by the compilation of the code resources of the current program. Developers can define the target channel targeted by the current compilation according to actual needs, so that the data generated by the compilation operation is the code resources required by the target channel, reducing the storage memory occupied by the code resources.
[0079] Step S12, filtering the aggregated source code library, filtering out the implementation class code set that is not annotated with the target channel identifier, and obtaining the source code library of the target channel:
[0080] After completing the construction of the aggregated source code library, one or more implementation class code sets whose channel identifiers are not the target channel identifiers will be filtered out according to the channel identifiers carried by each implementation class code set contained in the aggregated source code library to generate a source code library of the target channel that only contains the implementation class code sets to which the target channel belongs.
[0081] See also Figure 3 The specific implementation steps for filtering the target channel of the aggregated source code library are as follows:
[0082] Step S121, calling the aggregated source code library, determining that only one of the multiple pre-annotated channel identifiers is in an activated state, and determining it as the target channel identifier:
[0083] There are multiple pre-annotated channel identifiers in the aggregated source code library. By calling the aggregated source code library, the channel identifier is determined as the target channel identifier in the aggregated source code library based on the only channel identifier in the aggregated source code library that is in a collected state.
[0084] There are multiple channel identifiers in the aggregated source code library. Correspondingly, the implementation class code set in the aggregated source code library also contains implementation class code sets corresponding to each channel identifier, so as to develop the implementation class code sets and interface class code sets of multiple channels in parallel, and by activating the channel identifier, the class files constructed by the implementation class code set and interface class code set required for compiling the corresponding target channel are set to realize the functions for the corresponding target channel.
[0085] Specifically, the channel identifier may be expressed as:
[0086] @SpdtCurrentFlavor(value=false)
[0087] final class channel internal constructor():SpdtFlavor
[0088] The corresponding channel is written in the channel. For example, the channel for the game project is GAME (game) and its identifier is:
[0089] @SpdtCurrentFlavor(value=false)
[0090] final class GAME internal constructor():SpdtFlavor
[0091] The value is used to indicate the state of setting the channel identifier. When value=true, the channel identifier is in an activated state. When value=false, the channel identifier is in an inactivated state. Accordingly, there can only be one channel identifier in an activated state among the multiple channel identifiers in the aggregated source code library, so that the compilation operation is only performed for one target channel identifier. Those skilled in the art can design the expression of the channel identifier according to the actual business scenario, which will not be described in detail.
[0092] In one embodiment, the status of multiple channel identifiers in the aggregated source code library is checked. When there are more than one channel identifier in an activated state, a notification message indicating that the target channel is greater than 1 is displayed, and the compilation operation of the aggregated source code library is stopped.
[0093] Step S122, searching and deleting the annotation parameters in the channel annotation identifiers corresponding to the various implementation class code sets from the source code library, the implementation class code sets that do not belong to the target channel identifier:
[0094] According to the target channel identifier in the aggregated source code library, the implementation class code set in the aggregated source code library is queried, and one or more implementation class code sets whose annotation parameters of the channel annotation identifier are not associated with the target channel identifier are deleted.
[0095] Specifically, the expression of the channel annotation identifier of the implementation class code set may be:
[0096] @SpdtActual(annotation parameter::class)
[0097] The corresponding channel is written in the annotation parameter. For example, the expression of the channel annotation identifier of the game project whose annotation parameter is GAME is:
[0098] @SpdtActual(GAME::class)
[0099] When the target channel identifier is not GAME, the implementation class code set will be deleted. Correspondingly, if the target channel identifier is GAME, the implementation class code set will be retained.
[0100] In one embodiment, one or more annotation parameters may be provided in the channel annotation identifier carried by the implementation class code set. When there is one annotation parameter in the channel annotation identifier carried by the implementation class code set, the implementation class code set is a private implementation class, that is, an implementation class developed only for one channel. When there are more than one annotation parameters in the channel annotation identifier carried by the implementation class code set, the implementation class code set is a shared implementation class, that is, an implementation class developed for more than one channels, so as to achieve reuse of the implementation class code set and improve development efficiency.
[0101] Step S123, the source code library after the deletion is used as the source code library of the target channel:
[0102] After traversing the implementation class code sets of the aggregated source code library and deleting the implementation class code sets that do not belong to the target channel, the implementation class code sets that have not been deleted are used as the source code library of the target channel.
[0103] Step S13, based on the source code library of the target channel, construct a matching information table representing the mapping relationship between the code sets of the interface class and its implementation class:
[0104] After completing the filtering operation on the aggregated source code library and obtaining the source code library of the target channel, the matching information table for characterizing the mapping relationship between the implementation class code set and the interface class is constructed based on the interface class in the interface class code set referenced by each implementation class code set in the source code library of the target channel.
[0105] In one embodiment, before constructing the matching information table representing the mapping relationship between the code set of the interface class and its implementation class based on the source code library of the target channel, it is verified whether each interface class in the interface class code set is applied by each implementation class code set in the source code library of the target channel. If there is an application relationship, the matching information table is constructed. If there are one or more interface classes that are not referenced by the implementation class code set, the matching information table is not constructed, and a notification message is generated to represent the existence of a non-reference relationship, so as to repair the interface class code set, prevent code redundancy, and occupy unnecessary computer storage memory space, and at the same time improve the robustness of the application constructed by the source code library.
[0106] Step S14, based on the mapping relationship between the interface class and the implementation class in the matching information table, a corresponding class file in the program is created according to a preset association class naming rule, so that after the program runs and loads the class file, the interface class is passed to the query interface provided by the class file, and the query interface queries and calls the instantiation object of the implementation class corresponding to the interface class according to the association class naming rule:
[0107] After the construction of the matching information table is completed, the corresponding class file in the program is created according to the preset association class naming rule based on the mapping relationship between the interface class and the implementation class code set in the matching information table.
[0108] The class file is created according to the association class naming rule so that after the program to which the class file belongs is running and loading the class file, the interface class of the class file is passed through the query interface provided by the class file, and the query interface follows the association class naming rule to query and call the instantiated object of the implementation class corresponding to the interface class.
[0109] The class file includes one implementation class and the interface class it references or multiple implementation classes and the interface classes they reference respectively. The class file is created according to the association class naming rule so that the class file can implement the corresponding functions of the application.
[0110] For information about the class file being loaded by the program, see Figure 4 , the specific implementation steps are as follows:
[0111] Step S141, triggering the calling of one of the interface classes, querying the query interface for the interface class:
[0112] The program triggers a call event, triggering the class file pointed to by the call event to call one of the interface classes, so as to trigger the query interface program to query the interface class.
[0113] The call event is generated by the program executing the corresponding function, so in response to the call event, the corresponding class file is called to execute the function implemented by the class file. For example, when the call event is generated by the program executing the login function, the call event points to the class file that implements the login function to implement the login function.
[0114] Step S142, the query interface converts the interface class into an implementation class in the class file according to the association class naming rule:
[0115] The query interface converts the interface class into an implementation class in the class file according to the interface class and in accordance with the association class naming rule.
[0116] For example, the expression for converting the interface class into the implementation class in the class file may be:
[0117] LoginAction loginAction=Spdt.of(LoginAction.class);
[0118] Among them, LoginAction.class refers to the class file generated in accordance with the association class naming rule, Spdt.of is the query interface, and the function pointed to by the expression is the login function. It creates a loginAction object applied to the login function through LoginActionloginAction=Spdt.of(LoginAction.class), thereby completing the conversion of the interface class (class file generated in accordance with the association class naming rule) LoginAction.class into the implementation class loginAction object.
[0119] Step S143, the query interface instantiates the code set corresponding to the implementation class to obtain an instantiated object:
[0120] After the query interface completes converting the interface class into the implementation class in the class file, the corresponding code set of the implementation class is instantiated to obtain the corresponding instantiation object of the implementation class.
[0121] Referring to the expression in step S142, the instantiated expression may be:
[0122] loginAction.startLogin();
[0123] Through the loginAction object, the startLogin() implementation class used for starting the login function is referenced, and the implementation class is then instantiated, and feedback is obtained by instantiating the instantiated object of the implementation class (startLogin()).
[0124] Step S144, the query interface returns the instantiated object and executes:
[0125] After the query interface completes the instantiated object, the instantiated object is returned and executed to implement the corresponding function.
[0126] The above typical embodiments and their variant embodiments fully disclose the implementation scheme of the program annotation compilation method of the present application. However, various variant embodiments of the method can still be derived by transforming and amplifying some technical means. Other embodiments are briefly described as follows:
[0127] In one embodiment, see Figure 5 , the method comprises the following pre-steps:
[0128] Step S08, obtaining a channel identification set applicable to the current development project:
[0129] When the current development project starts development, a channel identification set applicable to the development function will be obtained so that development can be carried out for each channel identification contained in the channel identification set, so that the code resources in the development project can be applied to the channels pointed to by each channel identification, thereby realizing code resource reuse and improving development efficiency.
[0130] In one embodiment, a corresponding code directory is created for each channel identifier to store file resources or at least part of the code resources required by the corresponding channel identifier, which are added to the compilation path corresponding to the target channel identifier to participate in the compilation.
[0131] In one embodiment, a code directory is created for each channel identifier in the channel identifier set. The code directory is used to store file resources or at least part of the code resources required by the corresponding channel identifier, so that the corresponding code directory can be called during the development process of the development project, so that when compiling the class file of the channel pointed to by the corresponding channel identifier, the code directory belonging to the channel identifier is called for compilation.
[0132] Step S09, creating corresponding annotation information for each channel identifier in the channel identifier set:
[0133] In the current development project, the annotation class information of each channel identifier in the channel identifier set is automatically created according to the channel identifier set.
[0134] The expression of the annotation class information in the development project can be:
[0135] @SpdtCurrentFlavor(value=true)
[0136] final class xx internal constructor():SpdtFlavor;
[0137] In this expression, xx refers to the corresponding channel identifier. If the channel identifier includes aa, bb, and cc, the annotation class information belonging to each channel identifier will be created to determine the channels targeted by the current development project.
[0138] Step S10, modify the corresponding annotation class information, mark the channel identifier that is the same as the pre-specified current compilation identifier as the target channel identifier, and mark the remaining channel identifiers as non-target channel identifiers:
[0139] The current development project determines the target channel identifier specified when the current development project is compiled by modifying the corresponding annotation class information, and determines that other channel identifiers in the channel identifier set are non-target channel identifiers.
[0140] Referring to the expression in step S09, the current development function can determine the target channel identifier and the non-target channel identifier through the value in the expression. For example, when the value of the corresponding annotation class information is true, the channel identifier corresponding to the annotation class information will be determined as the target channel identifier, and the value of the remaining annotation class information is false, so that the channel identifiers corresponding to the remaining annotation class information are determined as the non-target channel identifiers. It should be noted that the target channel identifier is a unique item, so that the compilation process is only performed on one channel to perform differentiated compilation operations.
[0141] Furthermore, by functionalizing each step in the method disclosed in the above embodiments, a program annotation compilation device of the present application can be constructed. According to this idea, please refer to Figure 6In a typical embodiment, the device includes: a source code library construction unit 11, a source code library filtering unit 12, an information table construction unit 13 and a class file creation unit 14. Among them, the source code library construction unit 11 is used to extract the interface class code set annotated with the interface class identifier and the implementation class code set annotated with the implementation class identifier from the code resources of the program to form an aggregated source code library; the source code library filtering unit 12 is used to filter the aggregated source code library, filter out the implementation class code set that is not annotated with the target channel identifier, and obtain the source code library of the target channel; the information table construction unit 13 is used to construct a matching information table representing the mapping relationship between the interface class and the code set of its implementation class based on the source code library of the target channel; the class file creation unit 14 is used to create the corresponding class file in the program according to the preset association class naming rule based on the mapping relationship between the interface class and the implementation class in the matching information table, so that after the program runs and loads the class file, the interface class is passed through the query interface provided to the class file, and the query interface queries and calls the instantiation object of the implementation class corresponding to the interface class in accordance with the association class naming rule.
[0142] In one embodiment, the source code library filtering unit includes: an identification determination module, which is used to call the aggregated source code library, determine that only one of the multiple pre-annotated channel identifications is in an activated state, and determine it as the target channel identification; a code filtering module, which is used to search and delete from the source code library the annotation parameters in the channel annotation identification corresponding to each implementation class code set that do not belong to the implementation class code set of the target channel identification; and a source code library determination module, which is used to use the source code library after the deletion as the source code library of the target channel.
[0143] In another embodiment, the class file creation unit includes: an interface class query module, used to trigger the call of an interface class and query the query interface for the interface class; an interface class conversion module, used for the query interface to convert the interface class into an implementation class in the class file according to the associated class naming rule; an instantiation module, used for the query interface to instantiate the code set corresponding to the implementation class to obtain an instantiated object; and an object return module, used for the query interface to return and execute the instantiated object.
[0144] In order to solve the above technical problems, the embodiment of the present application also provides a computer device for running a computer program implemented according to the program annotation compilation method. Figure 7 , Figure 7 This is a basic structural block diagram of the computer device in this embodiment.
[0145] like Figure 7As shown, a schematic diagram of the internal structure of a computer device. The computer device includes a processor, a non-volatile storage medium, a memory, and a network interface connected via a system bus. Among them, the non-volatile storage medium of the computer device stores an operating system, a database, and computer-readable instructions. The database may store a control information sequence. When the computer-readable instructions are executed by the processor, the processor can implement a program annotation compilation method. The processor of the computer device is used to provide computing and control capabilities to support the operation of the entire computer device. The memory of the computer device may store computer-readable instructions. When the computer-readable instructions are executed by the processor, the processor can execute a program annotation compilation method. The network interface of the computer device is used to connect and communicate with a terminal. Those skilled in the art can understand that Figure 7 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0146] In this embodiment, the processor is used to execute the specific functions of each module / submodule of the program annotation compilation device of the present invention, and the memory stores the program code and various data required to execute the above modules. The network interface is used to transmit data between user terminals or servers. The memory in this embodiment stores the program code and data required to execute all modules / submodules in the program annotation compilation device, and the server can call the server's program code and data to execute the functions of all submodules.
[0147] The present application also provides a non-volatile storage medium, in which the program annotation compilation method is written into a computer program and stored in the storage medium in the form of computer-readable instructions. When the computer-readable instructions are executed by one or more processors, it means that the program is run in the computer, thereby enabling one or more processors to execute the steps of the program annotation compilation method of any of the above-mentioned embodiments.
[0148] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through a computer program, and the computer program can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, the aforementioned storage medium can be a non-volatile storage medium such as a disk, an optical disk, a read-only memory (ROM), or a random access memory (RAM).
[0149] In summary, this application constructs a multi-channel differentiated compilation function, which annotates the corresponding channels by annotation identifiers, and realizes compilation only for the code resources required by the target channels. At the same time, it realizes the function of reusing the same code resources in multiple channels, which helps to improve the development efficiency of software projects.
[0150] It should be understood that, although the steps in the flowchart of the accompanying drawings are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.
[0151] Those skilled in the art will appreciate that the various operations, methods, steps, measures, and schemes in the processes discussed in this application may be alternated, altered, combined, or deleted. Further, other steps, measures, and schemes in the various operations, methods, and processes discussed in this application may also be alternated, altered, rearranged, decomposed, combined, or deleted. Further, the steps, measures, and schemes in the prior art that are similar to those disclosed in this application may also be alternated, altered, rearranged, decomposed, combined, or deleted.
[0152] The above description is only a partial implementation method of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.
Claims
1. A program annotation compilation method, characterized in that: The steps include: Extracting an interface class code set annotated with an interface class identifier and an implementation class code set annotated with an implementation class identifier from the code resources of the program to form a summary source code library; The aggregated source code library is filtered to remove the implementation class code sets that are not annotated with the target channel identifier, and the source code library of the target channel is obtained, including: calling the aggregated source code library, determining that only one of the multiple pre-annotated channel identifiers is in an activated state, and determining it as the target channel identifier; searching and deleting the annotation parameters in the channel annotation identifiers corresponding to each implementation class code set from the source code library that do not belong to the implementation class code set of the target channel identifier, and the annotation parameters in the channel annotation identifier corresponding to the implementation class code set include one or more, respectively used to describe the private implementation class owned by a single channel identifier or the shared implementation class owned by multiple channel identifiers; and using the source code library after the deletion as the source code library of the target channel; Based on the source code library of the target channel, construct a matching information table representing the mapping relationship between the code sets of the interface class and its implementation class; Based on the mapping relationship between the interface class and the implementation class in the matching information table, a corresponding class file in the program is created according to a preset association class naming rule, so that after the program runs and loads the class file, the interface class is passed through a query interface provided to the class file, and the query interface queries and calls the instantiated object of the implementation class corresponding to the interface class in accordance with the association class naming rule.
2. The method according to claim 1, characterized in that Before the step of constructing a matching information table representing the mapping relationship between the code sets of the interface class and its implementation class based on the source code library of the target channel, the method includes: Verify whether the target channel source code library contains implementation class code sets corresponding to the interface classes therein. If so, the verification is passed to execute subsequent steps. Otherwise, the compilation is terminated and an alarm is issued.
3. The method according to claim 1 or 2, characterized in that: The step of passing the interface class to the interface provided by the class file, and the interface following the association class naming rule to query and call the implementation class corresponding to the interface class in the class file according to the interface class includes: Triggering the calling of one of the interface classes, querying the query interface for the interface class; The query interface converts the interface class into an implementation class in the class file according to the association class naming rule; The query interface instantiates the code set corresponding to the implementation class to obtain an instantiated object; The query interface returns the instantiated object and executes it.
4. The method according to claim 1 or 2, characterized in that: The following pre-steps are included: Get the channel identifier set applicable to the current development project; Creating corresponding annotation class information for each channel identifier in the channel identifier set; The corresponding annotation class information is modified, and the channel identifier that is the same as the pre-specified current compilation identifier is marked as the target channel identifier, and the remaining channel identifiers are marked as non-target channel identifiers.
5. The method according to claim 4, characterized in that The steps include: A corresponding code directory is created for each of the channel identifiers to store file resources or at least part of the code resources required by the corresponding channel identifier, and is added to the compilation path corresponding to the target channel identifier to participate in the compilation.
6. A program annotation compiling device, characterized in that: It includes: A source code library construction unit, used to extract an interface class code set annotated with an interface class identifier and an implementation class code set annotated with an implementation class identifier from the code resources of the program to form a summary source code library; The source code library filtering unit is used to filter the aggregated source code library, filter out the implementation class code sets that are not annotated with the target channel identifier, and obtain the source code library of the target channel, including: calling the aggregated source code library, determining that only one of the multiple pre-annotated channel identifiers is in an activated state, and determining it as the target channel identifier; searching and deleting from the source code library the annotation parameters in the channel annotation identifiers corresponding to each implementation class code set that do not belong to the implementation class code set of the target channel identifier, the annotation parameters in the channel annotation identifier corresponding to the implementation class code set include one or more, respectively used to describe the private implementation class owned by a single channel identifier or the shared implementation class owned by multiple channel identifiers; and using the source code library after the deletion as the source code library of the target channel; An information table construction unit, used to construct a matching information table representing a mapping relationship between the code set of the interface class and its implementation class based on the source code library of the target channel; A class file creation unit is used to create a corresponding class file in the program based on the mapping relationship between the interface class and the implementation class in the matching information table and according to a preset association class naming rule, so that after the program runs and loads the class file, the interface class is passed through a query interface provided to the class file, and the query interface queries and calls the instantiation object of the implementation class corresponding to the interface class in accordance with the association class naming rule.
7. The device according to claim 6, characterized in that The class file creation unit includes: An interface class query module, used to trigger the call of one of the interface classes, and query the query interface for the interface class; An interface class conversion module, used for converting the interface class into an implementation class in the class file according to the association class naming rule; An instantiation module is used for the query interface to instantiate the code set corresponding to the implementation class to obtain an instantiated object; The object returning module is used for the query interface to return and execute the instantiated object.
8. An electronic device, comprising a central processing unit and a memory, characterized in that: The central processing unit is used to call and run the computer program stored in the memory to execute the steps of the method according to any one of claims 1 to 5.
9. A non-volatile storage medium, characterized in that: It stores a computer program implemented according to the method described in any one of claims 1 to 5 in the form of computer-readable instructions, and when the computer program is called and executed by a computer, the steps included in the corresponding method are executed.
Citation Information
Patent Citations
Software release method and software release system
CN106775912A
Optimization processing method and device of application installation package and computer equipment
CN110083367A