Code generation method, device, electronic device and storage medium
By obtaining and using the template identification field to generate a target code template, the problem of low code generation efficiency is solved, a method of quickly generating code with similar structure is realized, and the user's work efficiency is improved.
Patent Information
- Application Number
- CN202110532653.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-05-17
- Publication Date
- 2024-09-20
- Estimated Expiration
- 2041-05-17
AI Technical Summary
Existing code generation methods are inefficient and users need to repeatedly write codes with similar structures.
By obtaining the second code selected in the coding tool, including the template identification field, the code template corresponding to the template identification field is obtained, the target code template is generated, and the target code template is inserted into the editing file. The user only needs to fill in the fields to be edited. Complete code can be generated.
This avoids repeated writing of codes with similar structures and improves code generation efficiency. Users can quickly generate code that meets specific requirements.
Smart Images

Figure CN113238752B
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer technology, and in particular to a code generation method, device, electronic device and storage medium. Background Art
[0002] In the related art, a user can edit codes to achieve various effects on a computer.
[0003] Codes used to achieve similar effects usually have similar code structures. However, current code generation methods require users to repeatedly write such codes with similar structures, resulting in low code generation efficiency. Summary of the invention
[0004] The present disclosure provides a code generation method, device, electronic device and storage medium to at least solve the problem of low code generation efficiency in the related art. The technical solution of the present disclosure is as follows:
[0005] According to a first aspect of an embodiment of the present disclosure, there is provided a code generation method, comprising:
[0006] Acquire a second code selected in an encoding tool for generating a first code, wherein the second code includes a template identification field;
[0007] Obtaining a code template corresponding to the template identification field;
[0008] Based on the code template, generating a target code template corresponding to the second code, inserting the target code template into an editing file of the encoding tool, wherein the target code template includes a field to be edited;
[0009] A code parameter input for the field to be edited is obtained, and a first code corresponding to the second code is generated in the editing file.
[0010] In an exemplary embodiment, the first code is a code for generating an interface element; the template identification field is used to identify the element type of the interface element; the second code also includes the element name of the interface element; the obtaining of the code template corresponding to the template identification field includes: obtaining the code template corresponding to the element type; the generating of the target code template corresponding to the second code based on the code template includes: generating the target code template based on the code template corresponding to the element type and the element name of the interface element.
[0011] In an exemplary embodiment, the interface element includes a text box element; the code parameters input for the field to be edited are obtained, and a first code corresponding to the second code is generated in the editing file, including: obtaining the font color, font size, and the maximum number of lines of the text box element corresponding to the text box element; filling in the font color, font size, and the maximum number of lines of the text box element at the corresponding position of the field to be edited in the text box code template to generate the first code.
[0012] In an exemplary embodiment, the interface element includes: a picture element; the code parameters input for the field to be edited are obtained, and a first code corresponding to the second code is generated in the editing file, including: obtaining the picture width, picture height, and rounded corner attribute value corresponding to the picture element; filling in the picture width, picture height, and rounded corner attribute value corresponding to the picture element at the corresponding position of the field to be edited in the picture code template to generate the first code.
[0013] In an exemplary embodiment, before obtaining the code template corresponding to the template identification field, it also includes: in response to an update operation on the preset code template, obtaining an updated code template; obtaining the code template corresponding to the template identification field includes: based on the template identification field, obtaining the code template corresponding to the template identification field from the updated code template.
[0014] In an exemplary embodiment, the acquiring of the second code selected in the encoding tool for generating the first code includes: acquiring the second code selected in the current editing file of the encoding tool as the second code for generating the first code.
[0015] In an exemplary embodiment, before acquiring the code template corresponding to the template identification field, the method further includes: detecting a shortcut key signal triggered by the encoding tool, and reading the template identification field from the second code.
[0016] In an exemplary embodiment, the number of the second codes is multiple; inserting the target code template into the editing file of the encoding tool includes: determining the code order of each second code; and inserting the target code template corresponding to each second code in the current editing file according to the code order.
[0017] According to a second aspect of an embodiment of the present disclosure, there is provided a code generating device, including:
[0018] A second code acquisition unit is configured to execute acquisition of a second code selected in the encoding tool for generating the first code, wherein the second code includes a template identification field;
[0019] A code template acquisition unit, configured to acquire a code template corresponding to the template identification field;
[0020] a target template acquisition unit, configured to generate a target code template corresponding to the second code based on the code template, and insert the target code template into an editing file of the encoding tool, wherein the target code template includes a field to be edited;
[0021] The first code generating unit is configured to obtain a code parameter input for the field to be edited, and generate a first code corresponding to the second code in the editing file.
[0022] In an exemplary embodiment, the first code is a code for generating an interface element; the template identification field is used to identify the element type of the interface element; the second code also includes the element name of the interface element; the code template acquisition unit is further configured to execute acquisition of a code template corresponding to the element type; the target template acquisition unit is further configured to execute generation of the target code template based on the code template corresponding to the element type and the element name of the interface element.
[0023] In an exemplary embodiment, the interface element includes a text box element; the first code generation unit is further configured to execute the acquisition of the font color, font size, and maximum number of lines corresponding to the text box element; fill in the font color, font size, and maximum number of lines of the text box element in the corresponding position of the field to be edited in the text box code template to generate the first code.
[0024] In an exemplary embodiment, the interface element includes: a picture element; the first code generation unit is further configured to execute the acquisition of the picture width, picture height, and rounded corner attribute value corresponding to the picture element; fill in the picture width, picture height, and rounded corner attribute value corresponding to the picture element in the corresponding position of the field to be edited in the picture code template to generate the first code.
[0025] In an exemplary embodiment, the code generation device also includes: a code template updating unit, configured to execute an update operation in response to the preset code template to obtain an updated code template; the code template acquisition unit is further configured to execute based on the template identification field, and obtain the code template corresponding to the template identification field from the updated code template.
[0026] In an exemplary embodiment, the second code acquisition unit is further configured to execute acquisition of a second code selected in a current editing file of the encoding tool as the second code for generating the first code.
[0027] In an exemplary embodiment, the code generating apparatus further includes: a shortcut key signal detection module configured to detect a shortcut key signal triggered by the encoding tool and read the template identification field from the second code.
[0028] In an exemplary embodiment, there are multiple second codes; the target template acquisition unit is further configured to determine the code sequence of each second code; and insert the target code template corresponding to each second code into the current editing file according to the code sequence.
[0029] According to a third aspect of an embodiment of the present disclosure, there is provided an electronic device, comprising: a processor; and a memory for storing instructions executable by the processor; wherein the processor is configured to execute the instructions to implement the code generation method as described in any one of the embodiments of the first aspect.
[0030] According to a fourth aspect of an embodiment of the present disclosure, a computer-readable storage medium is provided. When instructions in the computer-readable storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute the code generation method as described in any one of the embodiments of the first aspect.
[0031] According to a fifth aspect of an embodiment of the present disclosure, a computer program product is provided, including a computer program, wherein when the computer program is executed by a processor, the code generation method as described in any one of the embodiments of the first aspect is implemented.
[0032] The technical solution provided by the embodiments of the present disclosure brings at least the following beneficial effects:
[0033] By obtaining the second code selected in the coding tool for generating the first code, the second code includes a template identification field; obtaining a code template corresponding to the template identification field; based on the code template, generating a target code template corresponding to the second code, inserting the target code template into the editing file of the coding tool, the target code template includes a field to be edited; obtaining the code parameters input for the field to be edited, and generating the first code corresponding to the second code in the editing file. The code generation method provided by the present disclosure can find the corresponding code template through the template identification field in the second code, and automatically generate the target code template based on the code template. The user only needs to fill in the relevant code parameters in the field to be edited of the target code template to realize the generation of the first code with a complete structure, so that the user can avoid repeatedly writing codes with similar structures, thereby improving the efficiency of code generation.
[0034] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] The drawings herein are incorporated into and constitute a part of the specification, illustrate embodiments consistent with the present disclosure, and together with the description are used to explain the principles of the present disclosure, and do not constitute improper limitations on the present disclosure.
[0036] Figure 1 The present invention is a flowchart of a code generation method according to an exemplary embodiment.
[0037] Figure 2 The invention is a flowchart of generating a first code corresponding to a second code according to an exemplary embodiment.
[0038] Figure 3 is a flowchart of generating a first code corresponding to a second code according to another exemplary embodiment.
[0039] Figure 4 The figure is a flowchart of inserting a target code template according to an exemplary embodiment.
[0040] Figure 5 is a flowchart of a code generation method according to another exemplary embodiment.
[0041] Figure 6 The invention is a block diagram of a code generating device according to an exemplary embodiment.
[0042] Figure 7 It is a block diagram of an electronic device according to an exemplary embodiment. DETAILED DESCRIPTION
[0043] In order to enable ordinary persons in the art to better understand the technical solutions of the present disclosure, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the accompanying drawings.
[0044] It should be noted that the terms "first", "second", etc. in the specification and claims of the present disclosure and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present disclosure described herein can be implemented in an order other than those illustrated or described herein. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.
[0045] Figure 1is a flowchart of a code generation method according to an exemplary embodiment. Figure 1 As shown, the code generation method is used in a terminal installed with a coding plug-in, and includes the following steps.
[0046] In step S101, the terminal obtains a second code selected in an encoding tool for generating a first code, wherein the second code includes a template identification field.
[0047] Among them, the coding plug-in can be a plug-in pre-installed in the terminal, used to assist the user in editing the code through the coding tool. The plug-in can pre-store a variety of different code templates, read the code selected by the user, find the code template corresponding to the code selected by the user, and implement code editing through the code template. The terminal can be, but is not limited to, various personal computers, laptops, smart phones, tablet computers and portable wearable devices installed with the above-mentioned live broadcast auxiliary application. The second code can be a simple code written by the user in the coding tool in advance to generate the final complete code, that is, the first code, with the assistance of the coding plug-in. The second code can carry an identification field corresponding to the code template to be called, that is, a template identification field. Specifically, the terminal can call the pre-installed coding plug-in and use the coding plug-in to read the second code selected by the user in the coding tool for generating the first code. The second code can carry a template identification field so that the coding plug-in can determine the corresponding code template based on the template identification field.
[0048] In step S102, the terminal obtains a code template corresponding to the template identification field;
[0049] In step S103, the terminal generates a target code template corresponding to the second code based on the code template, and inserts the target code template into the editing file of the encoding tool, wherein the target code template includes a field to be edited.
[0050] After the terminal obtains the simple template identification field through the encoding plug-in, the encoding plug-in can obtain a code template corresponding to the template identification field from multiple pre-stored code templates based on the obtained template identification field, and use the code template in combination with the read second code to generate a target code template corresponding to the second code, and insert the target code template into the file being edited by the encoding tool. The target code template is provided with a field to be edited that can be used for editing by the user.
[0051] In step S104, the terminal obtains the code parameter input for the field to be edited, and generates a first code corresponding to the second code in the editing file.
[0052] Finally, after obtaining the target code template, the terminal can also obtain the parameters input by the user for the field to be edited in the target code template as code parameters, and fill them in the corresponding position of the field to be edited, thereby generating the corresponding first code in the editing file.
[0053] In the above code generation method, the second code selected in the coding tool for generating the first code is obtained, and the second code includes a template identification field; a code template corresponding to the template identification field is obtained; based on the code template, a target code template corresponding to the second code is generated, and the target code template is inserted into the editing file of the coding tool, and the target code template includes a field to be edited; the code parameters input for the field to be edited are obtained, and the first code corresponding to the second code is generated in the editing file. The code generation method provided by the present disclosure can find the corresponding code template through the template identification field in the second code, and automatically generate the target code template based on the code template. The user only needs to fill in the relevant code parameters in the field to be edited of the target code template to realize the generation of the first code with a complete structure, so that the user can avoid repeated writing of codes with similar structures, thereby improving the efficiency of code generation.
[0054] In an exemplary embodiment, the first code is a code for generating an interface element; the template identification field is used to identify the element type of the interface element; the second code also includes the element name of the interface element; step S102 may further include: the terminal obtains a code template corresponding to the element type; step S103 may further include: the terminal generates a target code template based on the code template corresponding to the element type and the element name of the interface element.
[0055] In this embodiment, the first code generated can be a code used to generate an interface element displayed on the interface, and the generated interface element can be a text box or a picture, etc. The template identification field can be a field used to identify the element type of the generated interface element, for example, it can include a text box type field used to identify the generated text box, or a picture type field used to identify the generated picture. Generally speaking, since the codes for generating different element types generally use different coding structures, the codes for generating the same element type generally have similar coding structures. For example, the code usually used to generate a text box element and the code used to generate a picture element generally use different coding structures, and for the code that is also used to generate a picture element, its coding structure is generally similar, so the identification field for identifying the element type of the interface element can be set to the template identification field. The element name refers to the name of the interface element to be generated, for example, the name of the text box element can be the user's name, user age, user gender, etc., and for the picture type, it can be the user's avatar, user background, user photo, etc.
[0056] Specifically, the second code obtained by the terminal in step S101 may include the element name of the interface element to be generated and an element type identification field for identifying the element type of the interface element to be generated. The terminal can then find the corresponding code template according to the element type of the interface element to be generated through the encoding plug-in, and generate the target code template corresponding to the second code based on the code template corresponding to the element type and the above-mentioned element name.
[0057] In this embodiment, the code generation method can be applied to the code editing of the generated interface elements, and through the template identification field used to identify the element type of the generated interface element, the code template corresponding to the element type is found, and the target code template is generated using the code template and the element name of the generated interface element, thereby improving the generation efficiency of the interface elements.
[0058] Furthermore, the interface element may include a text box element; Figure 2 As shown, step S104 may further include:
[0059] In step S201, the terminal obtains the font color and font size corresponding to the text box element, and the maximum number of lines of the text box element.
[0060] Specifically, when the interface element is a text box element, the fields to be edited in the corresponding target code template may include the font color and font size of the font displayed in the text box element to be generated, as well as the maximum number of lines in which the font can be displayed in the text box element, etc. The user can enter the font color, font size and maximum number of lines corresponding to the text box element to be generated in the editing file of the encoding tool, so that the terminal can obtain the font color, font size and maximum number of lines corresponding to the text box element.
[0061] In step S202, the terminal fills in the font color, font size, and the maximum number of lines of the text box element at the corresponding position of the field to be edited in the text box code template to generate a first code.
[0062] Finally, the terminal can enter the font color, font size, and maximum number of lines of the text box element obtained in step S201 into the target code template corresponding to the text box element in the editing file of the encoding tool, that is, the field to be edited in the text box code template, thereby generating the final first code for generating the text box element.
[0063] In this embodiment, the user can fill in the font color, font size, and maximum number of lines of the text box element corresponding to the corresponding position of the field to be edited in the text box code template, so as to quickly generate text box elements that meet certain targeted requirements and improve the generation efficiency of text box elements that meet targeted requirements.
[0064] Furthermore, the interface elements may include: picture elements; Figure 3 As shown, step S104 may further include:
[0065] In step S301, the terminal obtains the picture width and picture height corresponding to the picture element, and the rounded corner attribute value corresponding to the picture element.
[0066] If the interface element is a picture element, the fields to be edited in the corresponding target code template may include the picture width, picture height, and the rounded corner attribute value corresponding to the picture element to be generated, etc. The user can enter the picture width, picture height, and rounded corner attribute value corresponding to the picture element to be generated in the editing file of the encoding tool, so that the terminal can obtain the picture width, picture height, and rounded corner attribute value corresponding to the picture element.
[0067] In step S302, the terminal fills in the image width, image height, and the rounded corner attribute value corresponding to the image element at the corresponding position of the field to be edited in the image code template to generate a first code.
[0068] Afterwards, the terminal enters the image width, image height, and maximum number of lines of the text box element obtained in step S301 into the target code template corresponding to the image element in the editing file of the encoding tool, that is, the field to be edited in the image code template, thereby generating the final first code for generating the image element.
[0069] In this embodiment, the user can fill in the slice width, picture height, and rounded corner attribute value corresponding to the picture element in the corresponding position of the field to be edited in the picture code template, so as to quickly generate picture elements that meet certain targeted requirements and improve the generation efficiency of picture elements that meet targeted requirements.
[0070] In an exemplary embodiment, before step S102, it may also include: the terminal obtains an updated code template in response to an update operation on a preset code template; step S102 may further include: the terminal obtains a code template corresponding to the template identification field from the updated code template based on the template identification field.
[0071] If the pre-designed code template needs to be changed, for example, different users may have different coding habits, and the code template can be modified accordingly when used by different users, or when a new code template with better performance is developed, the user can update the preset code template, trigger the code template update operation to the terminal's coding plug-in, input the updated code template into the terminal's coding plug-in, and the terminal can respond to the update operation, obtain the updated code template and store it in the coding plug-in. Afterwards, the terminal can obtain the updated code template by calling the coding plug-in, and find the code template corresponding to the template identification field from the updated code template.
[0072] In this embodiment, the user can also update the preset code template to achieve customized modification of the code template, which can meet the different needs of users and improve the applicability of the code generation method.
[0073] In an exemplary embodiment, step S101 may further include: the terminal obtains a second code selected in a current editing file of the encoding tool as the second code used to generate the first code.
[0074] Among them, the currently edited file refers to the encoded file that the user is editing through the encoding tool. Specifically, the user can select one or more second codes in the encoded file being edited. For example, the code can be selected by the mouse and the code selected by the mouse in the file currently being edited can be used as the second code for generating the first code.
[0075] In this embodiment, the user can select the code of the currently edited file and use the selected code as the second code for generating the first code, which can reduce the user's operation of entering the second code into the terminal and improve the efficiency of the terminal in obtaining the second code.
[0076] In an exemplary embodiment, before step S102, the method may further include: the terminal detects a shortcut key signal triggered by the encoding tool, and reads a template identification field from the second code.
[0077] Among them, the shortcut key signal is a signal triggered by the user by clicking the shortcut key in the currently edited file, and the shortcut key signal can be used to trigger the terminal to call the encoding plug-in. Specifically, when the user wants to generate the target code template corresponding to the second code through the encoding plug-in, the user can first select the second code used to generate the first code by, for example, selecting a section of the code of the currently edited file in the encoding tool with the mouse, and then trigger the shortcut key signal to the terminal by using the pre-set shortcut key for calling the encoding plug-in. After the terminal detects the shortcut key signal, it can call the encoding plug-in, and the encoding plug-in reads the template identification field in the second code to find the corresponding code template.
[0078] In this embodiment, the user can directly trigger the shortcut key signal so that the encoding plug-in can read the template identification field, thereby generating the first code more quickly and further improving the generation efficiency of the first code.
[0079] In an exemplary embodiment, the number of the second codes is multiple; Figure 4 As shown, step S103 may further include:
[0080] In step S401, the terminal determines a code sequence of each second code.
[0081] Specifically, the number of second codes selected by the user may also be multiple, for example, the user may select multiple consecutive lines of second codes with the mouse to select multiple second codes at the same time, and then the terminal may determine the arrangement order of each selected second code as the code order of each second code. For example, the user may write multiple consecutive lines of second codes in the editing file of the encoding tool, and after the user selects the second code, the terminal may read the number of code lines corresponding to each line of the second code as the code order of each second code.
[0082] In step S402, the terminal inserts the target code templates corresponding to the second codes into the current editing file according to the code sequence.
[0083] Afterwards, the terminal can obtain the target code template corresponding to each second code by calling the encoding plug-in, and insert the corresponding target code template into the current editing file according to the code order of each second code. For example, the multiple second codes are second code A, second code B and second code C, and their code order is second code A-second code B-second code C, and their corresponding target code templates are target code template A, target code template B and target code template C, then the order of the target code templates finally inserted into the current editing file is target code template A-target code template B-target code template C.
[0084] In this embodiment, the user can select multiple second codes at the same time, and the terminal can insert the corresponding target code template according to the code sequence of the multiple second codes in the current editing, thereby improving the neatness of the generated target code template.
[0085] Figure 5 It is a flowchart of a code generation method according to an exemplary embodiment. As shown in 5, the code generation method is used in a terminal installed with a coding plug-in, and includes the following steps.
[0086] In step S501, the terminal obtains the second code selected in the current editing file of the encoding tool as the second code for generating the first code of the interface element; the second code includes a template identification field for identifying the element type of the interface element, and the element name of the interface element;
[0087] In step S502, the terminal detects a shortcut key signal triggered by the encoding tool, reads a template identification field from the second code, and acquires a code template corresponding to the element type from the code template based on the template identification field;
[0088] In step S503, the terminal generates a target code template based on the code template corresponding to the element type and the element name of the interface element; the target code template includes a field to be edited;
[0089] In step S504, the terminal determines the code sequence of each selected second code; and inserts the target code template corresponding to each second code into the current editing file according to the code sequence;
[0090] In step S505, if the interface element is a text box element, the terminal obtains the font color, font size, and maximum number of lines of the text box element corresponding to the text box element; fills the font color, font size, and maximum number of lines of the text box element in the corresponding position of the field to be edited in the text box code template to generate a first code;
[0091] In step S506, if the interface element is a picture element, the terminal obtains the picture width, picture height, and rounded corner attribute value corresponding to the picture element; fills in the picture width, picture height, and rounded corner attribute value corresponding to the picture element in the corresponding position of the field to be edited in the picture code template to generate the first code.
[0092] In this embodiment, the terminal can find the corresponding code template through the template identification field in the second code, and automatically generate the target code template based on the code template. The user only needs to fill in the relevant code parameters in the field to be edited of the target code template to realize the generation of the first code of the complete structure, so that the user can avoid repeated writing of codes with similar structures, and improve the efficiency of code generation for generating picture elements and text box elements. At the same time, the user can also select the code of the currently edited file and use the selected code as the second code for generating the first code, which can reduce the user operation of the user inputting the second code into the terminal and improve the efficiency of the terminal obtaining the second code, and can directly trigger the shortcut key signal so that the coding plug-in can read the template identification field, so that the first code can be generated more quickly, further improving the generation efficiency of the first code. And the user can select multiple second codes at the same time, and the terminal can insert the corresponding target code template according to the code order of the multiple second codes in the current editing according to the above code order, so as to improve the neatness of the generated target code template.
[0093] In an exemplary embodiment, a UI template code generator based on Xcode Source Editor Extension technology is also provided. Based on Source Editor Extension technology, a plug-in is written. The plug-in will first read the code selected by the engineer's mouse. The selected code can be multiple lines, such as two text boxes plus a picture, which is a total of three lines. Then the plug-in will determine that the three lines of code represent text box No. 1, text box No. 2, and picture No. 1, respectively, and then insert the three sections of code into the current XCode file respectively. After generation, the engineer needs to fill in specific field values in the generated code. For example, if the designer requires the font size of text box No. 1 to be 12, then the engineer needs to write 12 in the corresponding position. Similarly, the color value and the maximum number of lines need to be written.
[0094] Specifically, the first step for engineers to use the plug-in is to define the required UI content in advance in XCode. For example, if a user avatar, a nickname, and an age are needed, then the only three lines of code they need to write are:
[0095] userPhotoImageView
[0096] nameLabel
[0097] ageLabel
[0098] Note that ImageView and Label are agreed suffixes, which are fixed values and represent types. ImageView is a picture, Label is a text box, userPhoto represents the name of the user's avatar, and name and age represent the names of the two text boxes, nickname and age, respectively.
[0099] Then the engineer needs to select these three lines of code with the mouse and click on a menu generated by the plug-in (this menu is in the upper left corner of XCode). After clicking the menu, the plug-in will start reading these three lines of code and generate many lines of code and insert them into the file currently edited by the engineer.
[0100] Taking the complete code for generating a user avatar as an example, by entering userPhotoImageView in XCode, the complete code generated is as follows:
[0101]
[0102] Finally, the engineer manually modified it to the value or color required by the designer. The final complete code is as follows:
[0103]
[0104]
[0105] In addition, this plug-in can be used not only to automatically generate UI module code, but also to automatically generate data model module code. By templating the data model module code, the data model module code can be quickly generated. At the same time, this plug-in can also act on multiple code files at the same time. Since a Class in Objective C language usually needs to define two code files, this plug-in can also be used in conjunction with shell scripts or python scripts to achieve the purpose of modifying two files at the same time.
[0106] In summary, this solution properly utilizes the capabilities provided by Source Editor Extension: 1. Get the content selected by the mouse; 2. Flexible insertion of code in Xcode through the plug-in, realizing the development of the plug-in, and can achieve the following functions:
[0107] 1. The functions of the plug-in can be bound to Xcode shortcut keys, which can be more convenient.
[0108] 2. There is no need to switch to other apps during the code writing process, you can operate in Xcode throughout the process.
[0109] 3. Customized modification, because the public basic framework of each iOS technical team is different. For example, the function used by company A to set the font size of a text box is function a, while the function used by company B to set the font size of a text box is function b. Then, simply modifying the plug-in code can adapt to the development habits of the technical teams of the two companies.
[0110] In this embodiment, a coding plug-in is provided for code editing. Compared with traditional manual writing, it is no longer cumbersome, frees the hands of engineers, and quickly generates the desired code. In addition, the menu can be bound to shortcut keys. After the engineer writes a few lines of key code, he can select them with the mouse and then use a shortcut key to quickly generate UI code.
[0111] It should be understood that although Figure 1-5 The steps in the flowchart are shown in sequence as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified in this document, there is no strict order restriction for the execution of these steps, and these steps can be executed in other orders. Moreover, Figure 1-5 At least part of the steps may include multiple steps or multiple stages. These steps or stages are not necessarily performed at the same time, but can be performed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed in turn or alternately with other steps or at least part of the steps or stages in other steps.
[0112] Figure 6 is a block diagram of a code generation device according to an exemplary embodiment. Figure 6 The device includes a second code acquisition unit 601, a code template acquisition unit 602, a target template acquisition unit 603 and a first code generation unit 604.
[0113] A second code acquisition unit 601 is configured to execute acquisition of a second code selected in an encoding tool for generating a first code, wherein the second code includes a template identification field;
[0114] The code template acquiring unit 602 is configured to acquire the code template corresponding to the template identification field;
[0115] The target template acquisition unit 603 is configured to generate a target code template corresponding to the second code based on the code template, and insert the target code template into the editing file of the encoding tool, wherein the target code template includes a field to be edited;
[0116] The first code generating unit 604 is configured to obtain a code parameter input for the field to be edited, and generate a first code corresponding to the second code in the editing file.
[0117] In an exemplary embodiment, the first code is a code for generating an interface element; the template identification field is used to identify the element type of the interface element; the second code also includes the element name of the interface element; the code template acquisition unit 602 is further configured to execute acquisition of the code template corresponding to the element type; the target template acquisition unit 603 is further configured to execute generation of a target code template based on the code template corresponding to the element type and the element name of the interface element.
[0118] In an exemplary embodiment, the interface element includes a text box element; the first code generation unit 604 is further configured to execute the acquisition of the font color, font size, and maximum number of lines corresponding to the text box element; fill in the font color, font size, and maximum number of lines of the text box element in the corresponding position of the field to be edited in the text box code template to generate the first code.
[0119] In an exemplary embodiment, the interface elements include: a picture element; a first code generation unit 604, further configured to execute the acquisition of the picture width, picture height, and rounded corner attribute value corresponding to the picture element; fill in the picture width, picture height, and rounded corner attribute value corresponding to the picture element in the corresponding position of the field to be edited in the picture code template to generate a first code.
[0120] In an exemplary embodiment, the code generation device also includes: a code template updating unit, configured to execute an update operation in response to a preset code template to obtain an updated code template; a code template acquisition unit 602, further configured to execute based on the template identification field, to obtain a code template corresponding to the template identification field from the updated code template.
[0121] In an exemplary embodiment, the second code acquisition unit 601 is further configured to execute acquisition of a second code selected in a current editing file of the encoding tool as the second code for generating the first code.
[0122] In an exemplary embodiment, the code generating apparatus further includes: a shortcut key signal detection module configured to detect a shortcut key signal triggered by a coding tool and read a template identification field from the second code.
[0123] In an exemplary embodiment, there are multiple second codes; the target template acquisition unit 603 is further configured to determine the code sequence of each second code; and insert the target code template corresponding to each second code into the current editing file according to the code sequence.
[0124] Regarding the device in the above embodiment, the specific manner in which each unit performs the operation has been described in detail in the embodiment of the method, and will not be elaborated here.
[0125] Figure 7 700 is a block diagram of a device for code generation according to an exemplary embodiment. For example, the device 700 may be a mobile phone, a computer, a digital broadcast terminal, a messaging device, a game console, a tablet device, a medical device, a fitness device, a personal digital assistant, etc.
[0126] Reference Figure 7 , device 700 may include one or more of the following components: a processing component 702 , a memory 704 , a power component 706 , a multimedia component 708 , an audio component 710 , an input / output (I / O) interface 712 , a sensor component 714 , and a communication component 716 .
[0127] The processing component 702 generally controls the overall operation of the device 700, such as operations associated with display, phone calls, data communications, camera operations, and recording operations. The processing component 702 may include one or more processors 720 to execute instructions to complete all or part of the steps of the above-mentioned method. In addition, the processing component 702 may include one or more units to facilitate the interaction between the processing component 702 and other components. For example, the processing component 702 may include a multimedia unit to facilitate the interaction between the multimedia component 708 and the processing component 702.
[0128] The memory 704 is configured to store various types of data to support operations on the device 700. Examples of such data include instructions for any application or method operating on the device 700, contact data, phone book data, messages, pictures, videos, etc. The memory 704 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk, or optical disk.
[0129] The power supply component 706 provides power to the various components of the device 700. The power supply component 706 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power to the device 700.
[0130] The multimedia component 708 includes a screen that provides an output interface between the device 700 and the user. In some embodiments, the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundaries of the touch or slide action, but also detect the duration and pressure associated with the touch or slide operation. In some embodiments, the multimedia component 708 includes a front camera and / or a rear camera. When the device 700 is in an operating mode, such as a shooting mode or a video mode, the front camera and / or the rear camera may receive external multimedia data. Each front camera and rear camera may be a fixed optical lens system or have a focal length and optical zoom capability.
[0131] The audio component 710 is configured to output and / or input audio signals. For example, the audio component 710 includes a microphone (MIC), and when the device 700 is in an operating mode, such as a call mode, a recording mode, and a speech recognition mode, the microphone is configured to receive an external audio signal. The received audio signal can be further stored in the memory 704 or sent via the communication component 716. In some embodiments, the audio component 710 also includes a speaker for outputting audio signals.
[0132] I / O interface 712 provides an interface between processing component 702 and peripheral interface units, such as keyboards, click wheels, buttons, etc. These buttons may include but are not limited to: a home button, a volume button, a start button, and a lock button.
[0133] The sensor assembly 714 includes one or more sensors for providing various aspects of status assessment for the device 700. For example, the sensor assembly 714 can detect the open / closed state of the device 700, the relative positioning of components, such as the display and keypad of the device 700, and the sensor assembly 714 can also detect the position change of the device 700 or a component of the device 700, the presence or absence of user contact with the device 700, the orientation or acceleration / deceleration of the device 700, and the temperature change of the device 700. The sensor assembly 714 may include a proximity sensor configured to detect the presence of nearby objects without any physical contact. The sensor assembly 714 may also include a light sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, the sensor assembly 714 may also include an acceleration sensor, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.
[0134] The communication component 716 is configured to facilitate wired or wireless communication between the device 700 and other devices. The device 700 can access a wireless network based on a communication standard, such as WiFi, a carrier network (such as 2G, 3G, 4G or 5G), or a combination thereof. In an exemplary embodiment, the communication component 716 receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 716 also includes a near field communication (NFC) unit to facilitate short-range communication. For example, the NFC unit can be implemented based on radio frequency identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology and other technologies.
[0135] In an exemplary embodiment, the device 700 may be implemented by one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors, or other electronic components to perform the above methods.
[0136] In an exemplary embodiment, a computer-readable storage medium including instructions is also provided, such as a memory 704 including instructions, which can be executed by a processor 720 of the device 700 to perform the above method. For example, the computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.
[0137] In an exemplary embodiment, a computer program product is further provided, including a computer program, and when the computer program is executed by a processor, the code generation method as described in any of the above embodiments is implemented.
[0138] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the invention disclosed herein. The present disclosure is intended to cover any variations, uses or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary techniques in the art that are not disclosed in the present disclosure. The description and examples are to be considered exemplary only, and the true scope and spirit of the present disclosure are indicated by the following claims.
[0139] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.
Claims
1. A code generation method, characterized in that: include: Acquire a second code selected in an encoding tool for generating a first code, wherein the second code includes a template identification field; The code content of the first code includes the code content of the second code; The second code is pre-written by a user in a coding tool; Obtaining a code template corresponding to the template identification field; Based on the code template, generating a target code template corresponding to the second code, inserting the target code template into an editing file of the encoding tool, wherein the target code template includes a field to be edited; A code parameter input for the field to be edited is obtained, and a first code corresponding to the second code is generated in the editing file.
2. The method according to claim 1, characterized in that The first code is a code for generating an interface element; the template identification field is used to identify the element type of the interface element; the second code also includes the element name of the interface element; The acquiring of the code template corresponding to the template identification field comprises: Obtain a code template corresponding to the element type; The step of generating a target code template corresponding to the second code based on the code template includes: The target code template is generated based on the code template corresponding to the element type and the element name of the interface element.
3. The method according to claim 2, characterized in that The interface elements include text box elements; The acquiring of the code parameter input for the field to be edited, and generating a first code corresponding to the second code in the edit file, comprises: Get the font color, font size, and maximum number of lines of the text box element; The font color, font size, and the maximum number of lines of the text box element are filled in the corresponding position of the field to be edited in the text box code template to generate the first code.
4. The method according to claim 2, characterized in that: The interface elements include: picture elements; The acquiring of the code parameter input for the field to be edited, and generating a first code corresponding to the second code in the edit file, comprises: Get the image width, image height, and rounded corner attribute value corresponding to the image element; Fill in the image width, image height, and the rounded corner attribute value corresponding to the image element at the corresponding position of the field to be edited in the image code template to generate the first code.
5. The method according to claim 1, characterized in that Before obtaining the code template corresponding to the template identification field, the method further includes: In response to an update operation on a preset code template, obtaining an updated code template; The acquiring the code template corresponding to the template identification field includes: Based on the template identification field, a code template corresponding to the template identification field is obtained from the updated code template.
6. The method according to any one of claims 1 to 5, characterized in that: The step of obtaining the second code selected in the encoding tool for generating the first code includes: A second code selected in a current editing file of the encoding tool is obtained as the second code used to generate the first code.
7. The method according to claim 6, characterized in that Before obtaining the code template corresponding to the template identification field, the method further includes: A shortcut key signal triggered by the encoding tool is detected, and the template identification field is read from the second code.
8. The method according to claim 6, characterized in that The number of the second codes is multiple; inserting the target code template into the editing file of the encoding tool includes: determining a code sequence of each second code; According to the code sequence, the target code templates corresponding to the second codes are inserted into the current editing file.
9. A code generating device, characterized in that: include: A second code acquisition unit is configured to execute acquisition of a second code selected in an encoding tool for generating a first code, wherein the second code includes a template identification field; and the code content of the first code includes the code content of the second code; The second code is pre-written by a user in a coding tool; A code template acquisition unit, configured to acquire a code template corresponding to the template identification field; a target template acquisition unit, configured to generate a target code template corresponding to the second code based on the code template, and insert the target code template into an editing file of the encoding tool, wherein the target code template includes a field to be edited; The first code generating unit is configured to obtain a code parameter input for the field to be edited, and generate a first code corresponding to the second code in the editing file.
10. The device according to claim 9, characterized in that The first code is a code for generating an interface element; the template identification field is used to identify the element type of the interface element; the second code also includes the element name of the interface element; the code template acquisition unit is further configured to execute acquisition of a code template corresponding to the element type; The target template acquisition unit is further configured to generate the target code template based on the code template corresponding to the element type and the element name of the interface element.
11. The device according to claim 10, characterized in that The interface element includes a text box element; the first code generation unit is further configured to execute the acquisition of the font color and font size corresponding to the text box element, and the maximum number of lines of the text box element; The font color, font size, and the maximum number of lines of the text box element are filled in the corresponding position of the field to be edited in the text box code template to generate the first code.
12. The device according to claim 10, characterized in that The interface element includes: a picture element; the first code generation unit is further configured to execute obtaining the picture width, picture height, and rounded corner attribute value corresponding to the picture element; fill in the picture width, picture height, and rounded corner attribute value corresponding to the picture element in the corresponding position of the field to be edited in the picture code template to generate the first code.
13. The device according to claim 9, characterized in that Also includes: A code template updating unit, configured to execute an update operation in response to a preset code template and obtain an updated code template; The code template acquisition unit is further configured to acquire the code template corresponding to the template identification field from the updated code template based on the template identification field.
14. The device according to any one of claims 9 to 13, characterized in that The second code acquisition unit is further configured to execute acquisition of a second code selected in a current editing file of the encoding tool as the second code for generating the first code.
15. The device according to claim 14, characterized in that Also includes: The shortcut key signal detection module is configured to detect the shortcut key signal triggered by the encoding tool and read the template identification field from the second code.
16. The device according to claim 14, characterized in that The number of the second codes is multiple; the target template acquisition unit is further configured to determine the code order of each second code; According to the code sequence, the target code templates corresponding to the second codes are inserted into the current editing file.
17. An electronic device, characterized in that: include: processor; a memory for storing instructions executable by the processor; The processor is configured to execute the instructions to implement the code generation method according to any one of claims 1 to 8.
18. A computer-readable storage medium, characterized in that: When the instructions in the computer-readable storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute the code generation method according to any one of claims 1 to 8.
19. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the code generation method according to any one of claims 1 to 8 is implemented.
Citation Information
Patent Citations
Code generation method and apparatus
CN106293664A
Converting visual diagrams into code
CN109074245A
Script code generation method, apparatus, computer device, and storage medium
CN109101231A
Code writing method and device and computer equipment
CN111292721A
Code processing method and device and storage medium
CN112130837A
