CN115878125B - Expansion method and device of generation class, storage medium and electronic equipment - Google Patents

Expansion method and device of generation class, storage medium and electronic equipment Download PDF

Info

Publication number
CN115878125B
CN115878125B CN202211414164.XA CN202211414164A CN115878125B CN 115878125 B CN115878125 B CN 115878125B CN 202211414164 A CN202211414164 A CN 202211414164A CN 115878125 B CN115878125 B CN 115878125B
Authority
CN
China
Prior art keywords
information
class
file
module
source file
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202211414164.XA
Other languages
Chinese (zh)
Other versions
CN115878125A (en
Inventor
曹鑫
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Yancheng Tianyanchawei Technology Co ltd
Original Assignee
Yancheng Tianyanchawei Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Yancheng Tianyanchawei Technology Co ltd filed Critical Yancheng Tianyanchawei Technology Co ltd
Priority to CN202211414164.XA priority Critical patent/CN115878125B/en
Publication of CN115878125A publication Critical patent/CN115878125A/en
Application granted granted Critical
Publication of CN115878125B publication Critical patent/CN115878125B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Stored Programmes (AREA)

Abstract

The invention provides an extension method, a device, a storage medium and electronic equipment for generating classes, wherein the method comprises the following steps: creating a data structure file, wherein the data structure file comprises first type information and first service information corresponding to the first type information; compiling the data structure file to generate a parameter conversion source file; compiling the parameter conversion source file to generate a parameter conversion class file; loading a parameter conversion type file, analyzing and screening out second type information and second service information corresponding to the second type information; generating an intermediate source file according to the second type information and the second service information; and calling the intermediate source file according to a preset calling method to generate a target source file. The extension method, the extension device, the storage medium and the electronic equipment of the generated class can obtain the same calling experience as that of calling the local service for the client side without increasing the compiling complexity.

Description

Expansion method and device of generation class, storage medium and electronic equipment
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a method and apparatus for generating class extension, a storage medium, and an electronic device.
Background
According to the twelve element theory of micro services, a good micro service framework should support a multi-language scenario, but it is not practical for each micro service development company to self-develop a framework supporting most of the main stream languages, so that selecting an existing micro service framework of a large manufacturer is more practical. The GRPC is a micro service RPC framework, and most micro service development companies have their own main language used when developing micro services or most micro services use a language such as JAVA. However, the Stub class of the native GRPC is not friendly to developers who are used to use JAVA, and development efficiency is low.
Disclosure of Invention
In view of the foregoing, the present invention provides an extension method, apparatus, storage medium and electronic device for generating class, so as to at least partially solve the foregoing problems.
According to a first aspect of the present invention, there is provided an extension method of generating a class, the method comprising:
creating a data structure file, wherein the data structure file comprises first type information and first service information corresponding to the first type information;
compiling the data structure file to generate a parameter conversion source file;
compiling the parameter conversion source file to generate a parameter conversion class file;
loading a parameter conversion type file, analyzing and screening out second type information and second service information corresponding to the second type information;
generating an intermediate source file according to the second type information and the second service information;
and calling the intermediate source file according to a preset calling method to generate a target source file.
Optionally, loading the parameter conversion class file, analyzing and screening out second class information and second service information corresponding to the second class information, including:
creating a class loader;
and analyzing and screening out the second type information and the second service information corresponding to the second type information through the class loader.
Optionally, analyzing and screening the second type information and the second service information corresponding to the second type information by the class loader includes:
analyzing the parameter conversion class file through a class loader to obtain class information to be screened and service information to be screened corresponding to the class information to be screened;
screening target class information from the class information to be screened according to a preset screening rule;
extracting naming information from target class information according to a preset class naming rule to obtain second class information;
and screening target service information corresponding to the second type of information from the service information to be screened to serve as second service information.
Optionally, screening the target class information from the class information to be screened according to a preset screening rule includes:
and screening the information to be screened, the suffix of which ends with the first preset class name and comprises the first preset character, from the information to be screened, and taking the information to be screened as target class information.
Optionally, extracting naming information from the target class information according to a preset class naming rule to obtain second class information, wherein the second class information comprises;
and taking at least one character in the target class information before the first preset class name as the class name of the second class information, and setting the class attribute of the second class information to be the same as the class attribute of the target class information to obtain the second class information.
Optionally, the method further comprises:
if the intermediate source file is successfully called according to the preset calling method, generating a service information name according to the service information naming rule of the parameter conversion class file, and taking the service information name and the intermediate source file which is successfully called as target source files.
Optionally, the method further comprises:
if the intermediate source file is failed to be called according to the preset calling method, generating calling exception information and sending the calling exception information to the client through a remote procedure calling protocol between the server and the client.
According to a second aspect of the present invention, there is provided an extension apparatus for generating a class, the apparatus comprising: the system comprises a data structure module, a first compiling module, a second compiling module, a loading analyzing module, a first generating module and a second generating module; wherein,
the data structure module is used for creating a data structure file, wherein the data structure file comprises first type information and first service information corresponding to the first type information;
the first compiling module is used for compiling the data structure file to generate a parameter conversion source file;
the second compiling module is used for compiling the parameter conversion source file to generate a parameter conversion class file;
the loading analysis module is used for loading the parameter conversion type file, analyzing and screening out second type information and second service information corresponding to the second type information;
the first generation module is used for generating an intermediate source file according to the second type information and the second service information;
and the second generation module is used for calling the intermediate source file according to a preset calling method to generate a target source file.
According to a third aspect of the present invention there is provided a computer readable storage medium having stored thereon a computer program which when executed by a processor implements an embodiment of any of the methods described above.
According to a fourth aspect of the present invention there is provided an electronic device comprising a memory for storing a computer executable program thereon and a processor for running the computer executable program to implement an embodiment of any of the methods described above.
The invention provides a method and a device for expanding a generation class, a storage medium and electronic equipment, and a data structure file is created, wherein the data structure file comprises first class information and first service information corresponding to the first class information; compiling the data structure file to generate a parameter conversion source file; compiling the parameter conversion source file to generate a parameter conversion class file; loading a parameter conversion type file, analyzing and screening out second type information and second service information corresponding to the second type information; generating an intermediate source file according to the second type information and the second service information; according to the preset calling method, the intermediate source file is called, and the target source file is generated, so that the same calling experience as that of calling the local service (method) can be obtained for the client side without increasing compiling complexity.
The technical scheme of the invention is further described in detail through the drawings and the embodiments.
Drawings
The above and other objects, features and advantages of the present invention will become more apparent by describing embodiments of the present invention in more detail with reference to the attached drawings. The accompanying drawings are included to provide a further understanding of embodiments of the invention and are incorporated in and constitute a part of this specification, illustrate the invention and together with the embodiments of the invention, and not constitute a limitation to the invention. In the drawings, like reference numerals generally refer to like parts or steps.
FIG. 1 is a schematic flow chart of an embodiment I of an extension method for generating classes according to an embodiment of the present invention;
FIG. 2a is another schematic flow chart of an embodiment I of an extension method for generating classes according to an embodiment of the present invention;
FIG. 2b is a schematic flow chart of a first embodiment of an extension method for generating classes according to an embodiment of the present invention;
FIG. 3a is a schematic flow chart of a second embodiment of an extension method for generating classes according to the present invention;
FIG. 3b is another schematic flow chart of a second embodiment of an extension method for generating classes according to an embodiment of the present invention;
FIG. 4 is a block diagram of an extension apparatus for generating classes according to an embodiment of the present invention;
fig. 5 is a schematic structural diagram of an electronic device according to an exemplary embodiment of the present invention.
Detailed Description
Hereinafter, exemplary embodiments according to the present invention will be described in detail with reference to the accompanying drawings. It should be apparent that the described embodiments are only some embodiments of the present invention and not all embodiments of the present invention, and it should be understood that the present invention is not limited by the example embodiments described herein.
It should be noted that: the relative arrangement of the components and steps, numerical expressions and numerical values set forth in these embodiments do not limit the scope of the present invention unless it is specifically stated otherwise.
It will be appreciated by those of skill in the art that the terms "first," "second," etc. in embodiments of the present invention are used merely to distinguish between different steps, devices or modules, etc., and do not represent any particular technical meaning nor necessarily logical order between them.
It should also be understood that in embodiments of the present invention, "plurality" may refer to two or more, and "at least one" may refer to one, two or more.
It should also be appreciated that any component, data, or structure referred to in an embodiment of the invention may be generally understood as one or more without explicit limitation or the contrary in the context.
In addition, the term "and/or" in the present invention is merely an association relationship describing the association object, and indicates that three relationships may exist, for example, a and/or B may indicate: a exists alone, A and B exist together, and B exists alone. In the present invention, the character "/" generally indicates that the front and rear related objects are an or relationship.
It should also be understood that the description of the embodiments of the present invention emphasizes the differences between the embodiments, and that the same or similar features may be referred to each other, and for brevity, will not be described in detail.
Meanwhile, it should be understood that the sizes of the respective parts shown in the drawings are not drawn in actual scale for convenience of description.
The following description of at least one exemplary embodiment is merely exemplary in nature and is in no way intended to limit the invention, its application, or uses.
Techniques, methods, and apparatus known to one of ordinary skill in the relevant art may not be discussed in detail, but where appropriate, the techniques, methods, and apparatus should be considered part of the specification.
It should be noted that: like reference numerals and letters denote like items in the following figures, and thus once an item is defined in one figure, no further discussion thereof is necessary in subsequent figures.
Embodiments of the invention are operational with numerous other general purpose or special purpose computing system environments or configurations with electronic devices, such as terminal devices, computer systems, servers, etc. Examples of well known terminal devices, computing systems, environments, and/or configurations that may be suitable for use with the terminal device, computer system, server, or other electronic device include, but are not limited to: personal computer systems, server computer systems, thin clients, thick clients, hand-held or laptop devices, microprocessor-based systems, set-top boxes, programmable consumer electronics, network personal computers, small computer systems, mainframe computer systems, and distributed cloud computing technology environments that include any of the foregoing, and the like.
Electronic devices such as terminal devices, computer systems, servers, etc. may be described in the general context of computer system-executable instructions, such as program modules, being executed by a computer system. Generally, program modules may include routines, programs, objects, components, logic, data structures, etc., that perform particular tasks or implement particular abstract data types. The computer system/server may be implemented in a distributed cloud computing environment in which tasks are performed by remote processing devices that are linked through a communications network. In a distributed cloud computing environment, program modules may be located in both local and remote computing system storage media including memory storage devices.
Exemplary method
Fig. 1 is a schematic flow chart of an embodiment one of an extension method of generating a class according to an embodiment of the present invention. The embodiment can be applied to an electronic device, as shown in fig. 1, and the method includes the following steps:
step S101: creating a data structure file, wherein the data structure file comprises first type information and first service information corresponding to the first type information;
step S102: compiling the data structure file to generate a parameter conversion source file;
step S103: compiling the parameter conversion source file to generate a parameter conversion class file;
step S104: loading a parameter conversion type file, analyzing and screening out second type information and second service information corresponding to the second type information;
optionally, as shown in fig. 2a, step S104 specifically includes:
step S1041: creating a class loader;
step S1042: and analyzing and screening out the second type information and the second service information corresponding to the second type information through the class loader.
Optionally, as shown in fig. 2b, step S1042 specifically includes:
step 10421: analyzing the parameter conversion class file through a class loader to obtain class information to be screened and service information to be screened corresponding to the class information to be screened;
step 10422: screening target class information from the class information to be screened according to a preset screening rule;
wherein, preset screening rules can be flexibly selected by a person skilled in the art according to actual needs, and are not limited herein. For example: the preset screening rule may be to screen the information of the class to be screened whose suffix ends with the first preset class name and includes the first preset character.
Specifically, step 10422 may include: and screening the information to be screened, the suffix of which ends with the first preset class name and comprises the first preset character, from the information to be screened, and taking the information to be screened as target class information.
In the embodiment of the present invention, the first preset class name and the first preset character are set according to the adopted micro service frame and language source code generation technology, taking the generation class based on the JAVA source code generation technology under the GRPC micro service frame as an example, the first preset class name can be set as an replbase, the first preset character can be set as a GRPC, and the first preset class name and the first preset character can be flexibly set by a person skilled in the art according to actual situations, which is not limited herein.
Step 10423: extracting naming information from target class information according to a preset class naming rule to obtain second class information;
optionally, step 10423 specifically includes;
and taking at least one character in the target class information before the first preset class name as the class name of the second class information, and setting the class attribute of the second class information to be the same as the class attribute of the target class information to obtain the second class information.
Step 10424: and screening target service information corresponding to the second type of information from the service information to be screened to serve as second service information.
Step S105: generating an intermediate source file according to the second type information and the second service information;
step S106: and calling the intermediate source file according to a preset calling method to generate a target source file.
When the intermediate source file is called according to a preset calling method, if the intermediate source file is successfully called according to the preset calling method, generating a service information name according to a service information naming rule of the parameter conversion class file, and taking the service information name and the intermediate source file which is successfully called as target source files; if the intermediate source file is failed to be called according to the preset calling method, generating calling exception information and sending the calling exception information to the client through a remote procedure calling protocol between the server and the client.
Step S101, step S102, and step S106 are performed in the first item, and step S103, step S104, and step S105 are performed in the second item. Taking class generation based on JAVA source code generation technology under the GRPC micro-service framework as an example, the first item refers to a maven item, and the second item refers to a JAVA item. Those skilled in the art may choose according to actual needs, and are not limited herein.
According to the extension method for generating the class, firstly, the service information in the first item is compiled, analyzed, screened and renamed in the second item, and secondly, the service information is called in the first item, so that the service information which accords with the calling method of the service information in the second item is generated, and the same calling experience as that of calling the local service (method) can be obtained for the client side without increasing the compiling complexity.
In order to enable those skilled in the art to more clearly understand the generation class extension method provided by the invention, the generation class extension method provided by the invention is described in detail by taking the generation class based on the JAVA source code generation technology under the GRPC micro-service framework as an example.
Technical terms and abbreviations related to the embodiment of the invention are as follows:
GRPC: is a high-performance, general-purpose open-source RPC framework developed by google, is mainly developed for mobile applications and is designed based on the HTTP/2 protocol standard, while supporting most popular programming languages.
RPC: remote Procedure Call, remote procedure call, is a protocol that requests services from a remote computer program over a network without requiring knowledge of underlying network technology.
JDK: java Development Kit is a Software Development Kit (SDK) in Java language that provides a developer with a development kit that includes, in addition to the complete JRE (Java Runtime Environment) Java runtime environment, other kits for use by the developer.
Fig. 3a is a schematic flow chart of a second embodiment of an extension method of generating a class according to an embodiment of the present invention. Fig. 3b is another schematic flow chart of an embodiment two of the method for generating an extension class according to the embodiment of the present invention. The embodiment can be applied to an electronic device, as shown in fig. 3a and 3b, and the method includes the following steps:
step S201: creating a proto file (i.e., a data structure file) according to service requirements, wherein the proto file is defined with message information (first type information) and service information (i.e., first service information) corresponding to the message information;
the message information is used for defining the class information of the in-parameter or the out-parameter, and the service is used for defining the method provided for the RPC service.
In the embodiment of the invention, after the proto file is created, the proto file is saved in a designated directory. Taking the example of saving the proto file in the maven item, the proto file is generally saved in the src/main/proto directory by default, and a person skilled in the art can flexibly select a saving position of the proto file according to actual needs, which is not limited herein.
Step S202: compiling the proto file to generate a Stub source file (i.e., a parameter conversion source file, which may also be referred to as Stub source code);
in the embodiment of the invention, a Protobuf compiler can be used for compiling the proto file to generate a Stub source file, and the Stub source file is stored in a designated directory. Taking the example of a Stub source file saved in a maven item, default is typically saved in target/generated-sources/Protob uf/grpc-java and target/generated-sources/Protobuf/java directories.
Step S203: compiling the Stub source file to generate a Stub CLASS file (i.e. a parameter conversion CLASS file);
in the embodiment of the invention, a Java compiler in the JDK can be used for compiling the Stub source file to generate a Stub CLASS file, and the Stub CLASS file is stored in a designated JAVA directory.
In the prior art, a regular expression is generally used for directly analyzing a Stub source file in a maven project (i.e. in the life cycle of maven), but because the regular expression is adopted for directly analyzing the Stub source file, errors are easy to occur, the Stub source file cannot be completely analyzed, if a part of Stub source file cannot be analyzed, and the manual mode is adopted for analyzing the Stub source file, time and effort are consumed, therefore, the method and the device automatically compile the Stub source file by using a Java compiler carried by JDK, jump out of the life cycle of maven and generate a Stub CLASS file. The method can automatically and completely analyze the Stub source file, does not need manual intervention, is easy to realize, and has high accuracy of analysis results.
Step S204: loading a Stub CLASS file, and analyzing and screening out second type information and second service information corresponding to the second type information;
in the embodiment of the invention, the Stub CLASS file can be loaded into the memory by using the JAVA loader, and then the second type information and the second service information corresponding to the second type information are analyzed and screened out.
In a specific implementation manner, after loading a Stub CLASS file, a JAVA loader firstly analyzes CLASS information in the Stub CLASS file, screens out second CLASS information conforming to preset rules from the CLASS information, simultaneously adopts a JAVA reflection technology to analyze a method set in the Stub CLASS file, and then screens out second service information corresponding to the second CLASS information from the analyzed method set in the Stub CLASS file according to the second CLASS information, thereby obtaining the second CLASS information and the second service information corresponding to the second CLASS information.
In an alternative embodiment, step S204 may specifically include:
step S2041: creating a JAVA loader (class loader);
step S2042: and analyzing and screening out the second type information and the second service information corresponding to the second type information through the JAVA loader.
Step S2042 may specifically include:
step 20421: analyzing the Stub CLASS file through a JAVA loader to obtain information of the CLASS to be screened and service information to be screened corresponding to the information of the CLASS to be screened;
specifically, after the JAVA loader is created, the JAVA loader loads the Stub CLASS file, firstly analyzes the Stub CLASS file to obtain information of the CLASS to be screened, and simultaneously adopts the JAVA reflection technology to analyze a method set (namely the service information to be screened) in the Stub CLASS file.
Step 20422: screening the class information to be screened, wherein the suffix of the class information to be screened ends with an impbase (namely a first preset class name) and comprises GRPC (namely a first preset character) as target class information;
the target CLASS information is CLASS information ending with an impbase and comprising GRPC in CLASS information to be screened which is analyzed from the Stub CLASS file.
In the embodiment of the invention, the class is generated based on the JAVA source code generation technology under the GRPC micro-service framework, so the first preset class name is imagebase, the first preset character is GRPC, if other micro-service frameworks and other language source code generation technologies are adopted, the first preset class name and the first preset character can be flexibly set by a person skilled in the art according to actual conditions, and the method is not limited herein.
Step 20423: taking at least one character before the impBase in the target class information as the class name of the second class information, and setting the class attribute of the second class information to be the same as the class attribute of the target class information to obtain the second class information;
step 20424: and screening target service information corresponding to the second type of information from the service information to be screened to serve as second service information.
Step S205: generating an intermediate source file according to the second type information and the second service information;
specifically, a class name (i.e., a method name of the second service information corresponding to the second class information), an input parameter type, and an output parameter type are obtained from the second class information, and an intermediate source file (i.e., an abstract method) of a style such as public abscission < output parameter > method name (input parameter) is generated.
Step S206: and calling the intermediate source file according to a preset calling method to generate a target source file.
Specifically, firstly, calling an intermediate source file, wherein the entering of the intermediate source file is the entering of the intermediate source file; secondly, writing the called intermediate source file into a streamObserver object; the onCompleted that invokes the streamObserver object completes the call.
After the completed call of the onCompleted of the streamObserver object is completed, there are specifically the following two cases:
first case: if the intermediate source file is successfully called according to a preset calling method, generating a service information name according to a service information naming rule of the parameter conversion class file, and taking the service information name and the intermediate source file which is successfully called as a target source file;
specifically, the class name (i.e., the method name of the second service information corresponding to the second class information), the parameter entering type and the parameter exiting type are obtained from the second class information, and the second service information of the method name Async (parameter entering parameter) of the pattern such as public ListenableFuture < parameter exiting > is generated for the client to initiate asynchronous call and use, wherein the code block is empty.
Second case: if the intermediate source file is failed to be called according to the preset calling method, generating calling exception information and sending the calling exception information to the client through a remote procedure calling protocol between the server and the client.
Specifically, if the intermediate source file is failed to be called according to the preset calling method, the server throws out the abnormal stack information (namely calling the abnormal information), and sends the abnormal stack information to the client in a GRPC response header mode.
It should be noted that, step S206 is performed in the maven item, and its function is to enable the intermediate source file generated in the JAVA item to be called in the maven item according to the method for calling the intermediate source file in the JAVA item, so as to obtain the same RPC calling experience as that of calling the local method. Step S201 and step S202 are performed in the maven item, and step S203, step S204 and step S205 are performed in the JAVA item.
According to the extension method for generating the CLASS, provided by the invention, the Stub source file is compiled by using a Java compiler with the JDK, so that traversal is provided for loading and analyzing a Stub CLASS file by using an independent CLASS loader at the back while the compiling life cycle of Maven is not damaged; the extension class can be used as an abstract class of a service end implementation class, can also be used as a portal for a client to call back-end service, is more in line with interface programming habit of JAVA engineers, and is convenient for the client to use a dynamic proxy technology for extension. In addition, the extension method of the generation class provided by the invention is integrated with the apache maven project management software, and the whole process is carried out in the GENERATE_SOURC ES stage, so that the same RPC calling experience as that of calling local service (method) can be obtained for the client side without increasing the compiling complexity.
It should be noted that, in the present invention, the first service information may also be referred to as a first service method, and the second service information may also be referred to as a second service method, that is, the service information substantially refers to a method for implementing the corresponding service function.
Exemplary apparatus
Fig. 4 is a block diagram of an extension apparatus for generating a class according to an embodiment of the present invention. As shown in fig. 4, the apparatus includes: the system comprises a data structure module 30, a first compiling module 31, a second compiling module 32, a loading analyzing module 33, a first generating module 34 and a second generating module 35; wherein,
a data structure module 30, configured to create a data structure file, where the data structure file includes first type information and first service information corresponding to the first type information;
a first compiling module 31, configured to compile a data structure file to generate a parameter conversion source file;
a second compiling module 32, configured to compile the parameter conversion source file to generate a parameter conversion class file;
the loading analysis module 33 is configured to load a parameter conversion class file, analyze and screen out second class information and second service information corresponding to the second class information;
a first generating module 34, configured to generate an intermediate source file according to the second class information and the second service information;
the second generating module 35 is configured to call the intermediate source file according to a preset call method, and generate a target source file.
Optionally, the load parsing module 33 is specifically configured to: creating a class loader; and analyzing and screening out the second type information and the second service information corresponding to the second type information through the class loader.
Optionally, the load parsing module 33 further includes: a parsing module (not shown), a first screening module (not shown), a naming module (not shown), and a second screening module (not shown); the analysis module is used for analyzing the parameter conversion class file through the class loader to obtain class information to be screened and service information to be screened corresponding to the class information to be screened; the first screening module is used for screening target class information from class information to be screened according to a preset screening rule; the naming module is used for extracting naming information from the target class information according to a preset class naming rule to obtain second class information; and the second screening module is used for screening target service information corresponding to the second type of information from the service information to be screened to serve as second service information.
Optionally, the first filtering module is specifically configured to filter, from the class information to be filtered, whose suffix ends with a first preset class name and includes a first preset character, as the target class information.
In the embodiment of the present invention, the first preset class name and the first preset character are set according to the adopted micro service frame and language source code generation technology, taking the generation class based on the JAVA source code generation technology under the GRPC micro service frame as an example, the first preset class name can be set as an replbase, the first preset character can be set as a GRPC, and the first preset class name and the first preset character can be flexibly set by a person skilled in the art according to actual situations, which is not limited herein.
Optionally, the naming module is specifically configured to use at least one character before the first preset class name in the target class information as a class name of the second class information, and set a class attribute of the second class information to be the same as a class attribute of the target class information, so as to obtain the second class information.
Optionally, the second generating module 35 is specifically configured to generate a service information name according to a service information naming rule of the parameter conversion class file if the intermediate source file is successfully called according to a preset calling method, and take the service information name and the intermediate source file that is successfully called as the target source file; if the intermediate source file is failed to be called according to the preset calling method, generating calling exception information and sending the calling exception information to the client through a remote procedure calling protocol between the server and the client.
It should be noted that, the generating class extension apparatus in this embodiment corresponds to the generating class extension method provided by the present invention, and other descriptions may refer to descriptions of the generating class extension method provided by the present invention, which are not repeated herein.
The invention provides a generation type expansion device, which is used for creating a data structure file, wherein the data structure file comprises first type information and first service information corresponding to the first type information; compiling the data structure file to generate a parameter conversion source file; compiling the parameter conversion source file to generate a parameter conversion class file; loading a parameter conversion type file, analyzing and screening out second type information and second service information corresponding to the second type information; generating an intermediate source file according to the second type information and the second service information; according to the preset calling method, the intermediate source file is called, and the target source file is generated, so that the same calling experience as that of calling the local service (method) can be obtained for the client side without increasing compiling complexity.
Exemplary electronic device
Fig. 5 is a schematic structural diagram of an electronic device according to an exemplary embodiment of the present invention. The electronic device may be either or both of the first device and the second device, or a stand-alone device independent thereof, which may communicate with the first device and the second device to receive the acquired input signals therefrom. As shown in fig. 5, the electronic device 40 includes one or more processors 41 and memory 42.
The processor 41 may be a Central Processing Unit (CPU) or other form of processing unit having data processing and/or instruction execution capabilities, and may control other components in the electronic device to perform desired functions.
Memory 42 may include one or more computer program products that may include various forms of computer-readable storage media, such as volatile memory and/or non-volatile memory. The volatile memory may include, for example, random Access Memory (RAM) and/or cache memory (cache), and the like. The non-volatile memory may include, for example, read Only Memory (ROM), hard disk, flash memory, and the like. One or more computer program instructions may be stored on the computer readable storage medium that may be executed by the processor 41 to implement the extension methods of the generation classes of software programs and/or other desired functions of the various embodiments of the present invention described above. In one example, the electronic device may further include: an input device 43 and an output device 44, which are interconnected by a bus system and/or other forms of connection mechanisms (not shown).
In addition, the input device 43 may also include, for example, a keyboard, a mouse, and the like. The output device 44 can output various information to the outside. The output device 44 may include, for example, a display, speakers, a printer, and a communication network and remote output apparatus connected thereto, etc.
Of course, only some of the components of the electronic device that are relevant to the present invention are shown in fig. 5 for simplicity, components such as buses, input/output interfaces, etc. being omitted. In addition, the electronic device may include any other suitable components depending on the particular application.
Exemplary computer program product and computer readable storage Medium
In addition to the methods and apparatus described above, embodiments of the invention may also be a computer program product comprising computer program instructions which, when executed by a processor, cause the processor to perform steps in an extension method of generating classes according to various embodiments of the invention described in the "exemplary methods" section of this specification.
The computer program product may write program code for performing operations of embodiments of the present invention in any combination of one or more programming languages, including an object oriented programming language such as Java, C++ or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computing device, partly on the user's device, as a stand-alone software package, partly on the user's computing device, partly on a remote computing device, or entirely on the remote computing device or server.
Furthermore, embodiments of the present invention may also be a computer-readable storage medium, having stored thereon computer program instructions, which when executed by a processor, cause the processor to perform the steps in an extension method of generating classes according to the various embodiments of the present invention described in the "exemplary methods" section above in this specification.
The computer readable storage medium may employ any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. The readable storage medium may include, for example, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or a combination of any of the foregoing. More specific examples (a non-exhaustive list) of the readable storage medium would include the following: an electrical connection having one or more wires, a portable disk, a hard disk, random Access Memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
The basic principles of the present invention have been described above in connection with specific embodiments, however, it should be noted that the advantages, benefits, effects, etc. mentioned in the present invention are merely examples and not intended to be limiting, and these advantages, benefits, effects, etc. are not to be considered as essential to the various embodiments of the present invention. Furthermore, the specific details disclosed herein are for purposes of illustration and understanding only, and are not intended to be limiting, as the invention is not necessarily limited to practice with the above described specific details.
In this specification, each embodiment is described in a progressive manner, and each embodiment is mainly described in a different manner from other embodiments, so that the same or similar parts between the embodiments are mutually referred to. For system embodiments, the description is relatively simple as it essentially corresponds to method embodiments, and reference should be made to the description of method embodiments for relevant points.
The block diagrams of the devices, apparatuses, devices, systems referred to in the present invention are only illustrative examples and are not intended to require or imply that the connections, arrangements, configurations must be made in the manner shown in the block diagrams. As will be appreciated by one of skill in the art, the devices, apparatuses, devices, systems may be connected, arranged, configured in any manner. Words such as "including," "comprising," "having," and the like are words of openness and mean "including but not limited to," and are used interchangeably therewith. The terms "or" and "as used herein refer to and are used interchangeably with the term" and/or "unless the context clearly indicates otherwise. The term "such as" as used herein refers to, and is used interchangeably with, the phrase "such as, but not limited to.
The method and apparatus of the present invention may be implemented in a number of ways. For example, the methods and apparatus of the present invention may be implemented by software, hardware, firmware, or any combination of software, hardware, firmware. The above-described sequence of steps for the method is for illustration only, and the steps of the method of the present invention are not limited to the sequence specifically described above unless specifically stated otherwise. Furthermore, in some embodiments, the present invention may also be embodied as programs recorded in a recording medium, the programs including machine-readable instructions for implementing the methods according to the present invention. Thus, the present invention also covers a recording medium storing a program for executing the method according to the present invention.
It is also noted that in the apparatus, devices and methods of the present invention, the components or steps may be disassembled and/or assembled. Such decomposition and/or recombination should be considered as equivalent aspects of the present invention. The previous description of the disclosed aspects is provided to enable any person skilled in the art to make or use the present invention. Various modifications to these aspects will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other aspects without departing from the scope of the invention. Thus, the present invention is not intended to be limited to the aspects shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
The foregoing description has been presented for purposes of illustration and description. Furthermore, this description is not intended to limit embodiments of the invention to the form disclosed herein. Although a number of example aspects and embodiments have been discussed above, a person of ordinary skill in the art will recognize certain variations, modifications, alterations, additions, and subcombinations thereof.

Claims (8)

1. An extension method for generating classes, the method comprising:
creating a data structure file, wherein the data structure file comprises first type information and first service information corresponding to the first type information;
compiling the data structure file to generate a parameter conversion source file;
compiling the parameter conversion source file to generate a parameter conversion class file;
loading the parameter conversion type file, analyzing and screening out second type information and second service information corresponding to the second type information;
generating an intermediate source file according to the second type information and the second service information;
calling the intermediate source file according to a preset calling method to generate a target source file;
the loading the parameter conversion type file, analyzing and screening out second type information and second service information corresponding to the second type information, including:
creating a class loader;
analyzing and screening out second type information and second service information corresponding to the second type information through the class loader;
the analyzing and screening the second class information and the second service information corresponding to the second class information by the class loader comprises the following steps:
analyzing the parameter conversion class file through the class loader to obtain class information to be screened and service information to be screened corresponding to the class information to be screened;
screening target class information from the class information to be screened according to a preset screening rule;
extracting naming information from the target class information according to a preset class naming rule to obtain the second class information;
and screening target service information corresponding to the second type of information from the service information to be screened to serve as second service information.
2. The method according to claim 1, wherein the screening the target class information from the class information to be screened according to a preset screening rule includes:
and screening the information to be screened, the suffix of which ends with a first preset class name and comprises a first preset character, from the information to be screened, and taking the information to be screened as the target class information.
3. The method according to claim 1, wherein extracting naming information from the target class information according to a preset class naming rule to obtain the second class information includes;
and taking at least one character before the first preset class name in the target class information as the class name of the second class information, and setting the class attribute of the second class information to be the same as the class attribute of the target class information to obtain the second class information.
4. The method according to claim 1, wherein the method further comprises:
and if the intermediate source file is successfully called according to the preset calling method, generating a service information name according to a service information naming rule of the parameter conversion class file, and taking the service information name and the intermediate source file which is successfully called as the target source file.
5. The method according to claim 1, wherein the method further comprises:
if the intermediate source file is failed to be called according to the preset calling method, generating abnormal calling information and sending the abnormal calling information to the client through a remote procedure calling protocol between the server and the client.
6. An extension apparatus for generating classes, the apparatus comprising: the system comprises a data structure module, a first compiling module, a second compiling module, a loading analyzing module, a first generating module and a second generating module; wherein,
the data structure module is used for creating a data structure file, wherein the data structure file comprises first type information and first service information corresponding to the first type information;
the first compiling module is used for compiling the data structure file to generate a parameter conversion source file;
the second compiling module is used for compiling the parameter conversion source file to generate a parameter conversion class file;
the loading analysis module is used for creating a class loader, loading the parameter conversion class file, analyzing and screening out second class information and second service information corresponding to the second class information;
the first generation module is used for generating an intermediate source file according to the second type information and the second service information;
the second generation module is used for calling the intermediate source file according to a preset calling method to generate a target source file;
the loading analysis module comprises: analysis module, first screening module, naming module and second screening module, wherein:
the analysis module is used for analyzing the parameter conversion class file through the class loader to obtain class information to be screened and service information to be screened corresponding to the class information to be screened;
the first screening module is used for screening target class information from the class information to be screened according to a preset screening rule;
the naming module is used for extracting naming information from the target class information according to a preset class naming rule to obtain the second class information;
and the second screening module is used for screening target service information corresponding to the second type of information from the service information to be screened to serve as second service information.
7. A computer readable storage medium, on which a computer program is stored, characterized in that the computer program, when being executed by a processor, implements the method of generating a class according to any of claims 1-5.
8. An electronic device comprising a memory for storing a computer executable program thereon and a processor for running the computer executable program to implement the method of generating a class extension of any of claims 1-5.
CN202211414164.XA 2022-11-11 2022-11-11 Expansion method and device of generation class, storage medium and electronic equipment Active CN115878125B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211414164.XA CN115878125B (en) 2022-11-11 2022-11-11 Expansion method and device of generation class, storage medium and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211414164.XA CN115878125B (en) 2022-11-11 2022-11-11 Expansion method and device of generation class, storage medium and electronic equipment

Publications (2)

Publication Number Publication Date
CN115878125A CN115878125A (en) 2023-03-31
CN115878125B true CN115878125B (en) 2024-02-06

Family

ID=85759770

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211414164.XA Active CN115878125B (en) 2022-11-11 2022-11-11 Expansion method and device of generation class, storage medium and electronic equipment

Country Status (1)

Country Link
CN (1) CN115878125B (en)

Citations (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7971194B1 (en) * 2005-06-16 2011-06-28 Sap Portals Israel Ltd. Programming language techniques for client-side development and execution
CN110333850A (en) * 2019-05-30 2019-10-15 重庆金融资产交易所有限责任公司 Generation method, device, computer equipment and the storage medium of interface document
CN110990019A (en) * 2019-11-20 2020-04-10 腾讯音乐娱乐科技(深圳)有限公司 Java class analysis method and device, storage medium and electronic equipment
CN111475477A (en) * 2019-01-23 2020-07-31 北京二六三企业通信有限公司 File format conversion method, client and format conversion server
US10983815B1 (en) * 2019-10-31 2021-04-20 Jpmorgan Chase Bank, N.A. System and method for implementing a generic parser module
CN112818176A (en) * 2021-02-08 2021-05-18 腾讯科技(深圳)有限公司 Data processing method, device, equipment and storage medium
CN113391791A (en) * 2020-03-12 2021-09-14 腾讯科技(深圳)有限公司 Data processing method, device and storage medium
CN113515319A (en) * 2021-04-20 2021-10-19 北京科东电力控制系统有限责任公司 Method for client to dynamically call server through GRPC
CN113778451A (en) * 2020-11-17 2021-12-10 北京沃东天骏信息技术有限公司 File loading method and device, computer system and computer readable storage medium
CN114281341A (en) * 2021-12-28 2022-04-05 苏州达家迎信息技术有限公司 Compiling method and device of data structure definition file, computer equipment and medium
CN114443051A (en) * 2022-01-21 2022-05-06 北京小米移动软件有限公司 Application program compiling and running method and device and storage medium
CN114816246A (en) * 2022-04-12 2022-07-29 盐城金堤科技有限公司 Proto file processing method and device

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9251026B2 (en) * 2012-03-31 2016-02-02 Bmc Software, Inc. Application instrumentation code extension
US11055072B2 (en) * 2019-08-08 2021-07-06 Jpmorgan Chase Bank, N.A. Generation of data model from protocol buffer compiler generated java classes

Patent Citations (13)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7971194B1 (en) * 2005-06-16 2011-06-28 Sap Portals Israel Ltd. Programming language techniques for client-side development and execution
CN111475477A (en) * 2019-01-23 2020-07-31 北京二六三企业通信有限公司 File format conversion method, client and format conversion server
CN110333850A (en) * 2019-05-30 2019-10-15 重庆金融资产交易所有限责任公司 Generation method, device, computer equipment and the storage medium of interface document
US10983815B1 (en) * 2019-10-31 2021-04-20 Jpmorgan Chase Bank, N.A. System and method for implementing a generic parser module
CN110990019A (en) * 2019-11-20 2020-04-10 腾讯音乐娱乐科技(深圳)有限公司 Java class analysis method and device, storage medium and electronic equipment
CN113391791A (en) * 2020-03-12 2021-09-14 腾讯科技(深圳)有限公司 Data processing method, device and storage medium
CN113778451A (en) * 2020-11-17 2021-12-10 北京沃东天骏信息技术有限公司 File loading method and device, computer system and computer readable storage medium
CN112818176A (en) * 2021-02-08 2021-05-18 腾讯科技(深圳)有限公司 Data processing method, device, equipment and storage medium
CN113515319A (en) * 2021-04-20 2021-10-19 北京科东电力控制系统有限责任公司 Method for client to dynamically call server through GRPC
WO2022222442A1 (en) * 2021-04-20 2022-10-27 北京科东电力控制系统有限责任公司 Method for client to dynamically call server by means of grpc
CN114281341A (en) * 2021-12-28 2022-04-05 苏州达家迎信息技术有限公司 Compiling method and device of data structure definition file, computer equipment and medium
CN114443051A (en) * 2022-01-21 2022-05-06 北京小米移动软件有限公司 Application program compiling and running method and device and storage medium
CN114816246A (en) * 2022-04-12 2022-07-29 盐城金堤科技有限公司 Proto file processing method and device

Also Published As

Publication number Publication date
CN115878125A (en) 2023-03-31

Similar Documents

Publication Publication Date Title
US9372688B1 (en) Automatic discovery of a JavaScript API
US9811325B2 (en) Systems and methods for dynamically replacing code objects for code pushdown
US8997070B2 (en) Extension mechanism for scripting language compiler
US11675575B2 (en) Checking source code validity at time of code update
US9032380B1 (en) Identifying function calls and object method calls
US8650532B2 (en) Change notification and information update based on uncompiled software development project
US20130104100A1 (en) Scripting Language for Business Applications
KR20140057547A (en) Runtime system
WO2022166669A1 (en) Hook method and apparatus at compile time, device, and storage medium
US20090328016A1 (en) Generalized expression trees
CN112685035A (en) Project development method and device, computer-readable storage medium and electronic device
CN113885849B (en) Application development method and device based on industrial internet platform and terminal equipment
Pedratscher et al. M2FaaS: Transparent and fault tolerant FaaSification of Node. js monolith code blocks
CN113094085B (en) Component integration method, device, computer readable storage medium and electronic equipment
CN110704025A (en) Method and device for generating coding specification tool, storage medium and electronic equipment
CN114217789A (en) Function component expansion method, device, equipment, storage medium and program product
CN115878125B (en) Expansion method and device of generation class, storage medium and electronic equipment
CN116578282A (en) Code generation method, device, electronic equipment and medium
US11947966B2 (en) Identifying computer instructions enclosed by macros and conflicting macros at build time
CN113094086B (en) Component integration method, device, computer readable storage medium and electronic equipment
Kano Kachako: A Hybrid-Cloud Unstructured Information Platform for Full Automation of Service Composition, Scalable Deployment and Evaluation: Natural Language Processing as an Example
CN115390846A (en) Compiling construction method and device, electronic equipment and storage medium
CN115268861A (en) Introduction method, system, equipment and storage medium of custom component
CN110659062B (en) Front-end scaffold configuration method and device, readable storage medium and electronic equipment
CN112882698A (en) Development environment generation method and device, computer storage medium and electronic device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
TA01 Transfer of patent application right

Effective date of registration: 20230804

Address after: 224008 Rooms 404-405 and 504, Building B-17-1, Big data Industrial Park, Kecheng Street, Yannan High tech Zone, Yancheng, Jiangsu Province

Applicant after: Yancheng Tianyanchawei Technology Co.,Ltd.

Address before: 224008 room 501-503, building b-17-1, Xuehai road big data Industrial Park, Kecheng street, Yannan high tech Zone, Yancheng City, Jiangsu Province (CNK)

Applicant before: Yancheng Jindi Technology Co.,Ltd.

TA01 Transfer of patent application right
GR01 Patent grant
GR01 Patent grant