Code generation method and device, electronic equipment and computer readable storage medium

By automatically determining and generating property declaration code, the problem of low efficiency in manually writing property declaration code in TypeScript is solved, thus improving development efficiency and accuracy.

CN115237420BActive Publication Date: 2026-06-23BEIJING BAIDU NETCOM SCI & TECH CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
BEIJING BAIDU NETCOM SCI & TECH CO LTD
Filing Date
2022-07-22
Publication Date
2026-06-23

Smart Images

  • Figure CN115237420B_ABST
    Figure CN115237420B_ABST
Patent Text Reader

Abstract

The present disclosure provides a code generation method and device, electronic equipment and computer readable storage medium, relates to the field of computers, in particular to the technical field of source code. The specific implementation scheme is: obtaining a to-be-declared attribute in an attribute of an object in a code segment that meets a preset attribute condition; determining a data type of the to-be-declared attribute based on an attribute name of the to-be-declared attribute; determining first attribute declaration code corresponding to the to-be-declared attribute based on the data type of the to-be-declared attribute, the first attribute declaration code being used to define the data type of the to-be-declared attribute. Based on the present scheme, the attribute declaration code corresponding to the to-be-declared attribute can be automatically determined, which can replace the manual writing of the attribute declaration code, thereby improving the development efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the field of computer technology, and more particularly to the field of source code technology. Specifically, this disclosure relates to a code generation method, apparatus, electronic device, and computer-readable storage medium. Background Technology

[0002] TypeScript is a superset of JavaScript, adding a type system to JavaScript to become a strongly typed language.

[0003] When writing code using TypeScript, data types need to be declared. In related technologies, this is typically done by manually writing the declaration code. Summary of the Invention

[0004] To address at least one of the aforementioned deficiencies, this disclosure provides a code generation method, apparatus, electronic device, and computer-readable storage medium.

[0005] According to a first aspect of this disclosure, a code processing method is provided, the method comprising:

[0006] Retrieves the undeclared properties of an object in the code segment that meet the preset property conditions;

[0007] Determine the data type of the attribute to be declared based on its name;

[0008] Based on the data type of the attribute to be declared, the first attribute declaration code corresponding to the attribute to be declared is determined. The first attribute declaration code is used to define the data type of the attribute to be declared.

[0009] According to a second aspect of this disclosure, a code processing apparatus is provided, the apparatus comprising:

[0010] The module for retrieving undeclared properties is used to retrieve undeclared properties from the properties of objects in the code segment that meet the preset property conditions.

[0011] The data type determination module is used to determine the data type of the attribute to be declared based on the attribute name.

[0012] The declaration code determination module is used to determine the first attribute declaration code corresponding to the attribute to be declared based on the data type of the attribute to be declared. The first attribute declaration code is used to define the data type of the attribute to be declared.

[0013] According to a third aspect of this disclosure, an electronic device is provided, the electronic device comprising:

[0014] At least one processor; and

[0015] A memory communicatively connected to at least one of the aforementioned processors; wherein,

[0016] The memory stores instructions that can be executed by at least one processor, and the instructions are executed by at least one processor to enable at least one processor to perform the code processing method.

[0017] According to a fourth aspect of this disclosure, a non-transitory computer-readable storage medium is provided storing computer instructions, wherein the computer instructions are used to cause a computer to execute the above-described code processing method.

[0018] According to a fifth aspect of this disclosure, a computer program product is provided, including a computer program that, when executed by a processor, implements the above-described code processing method.

[0019] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of this disclosure, nor is it intended to limit the scope of this disclosure. Other features of this disclosure will become readily apparent from the following description. Attached Figure Description

[0020] The accompanying drawings are provided to better understand this solution and do not constitute a limitation of this disclosure. Wherein:

[0021] Figure 1 This is a flowchart illustrating a code processing method provided in an embodiment of this disclosure;

[0022] Figure 2 This is a flowchart illustrating a specific implementation of the code processing method provided in this disclosure.

[0023] Figure 3 This is a flowchart illustrating another code processing method provided in an embodiment of this disclosure;

[0024] Figure 4 This is a flowchart illustrating yet another code processing method provided in an embodiment of this disclosure;

[0025] Figure 5 This is a schematic diagram of the structure of a code processing device provided in an embodiment of this disclosure;

[0026] Figure 6 This is a schematic diagram of another code processing device provided in an embodiment of this disclosure;

[0027] Figure 7 This is a schematic diagram of the structure of another code processing device provided in the embodiments of this disclosure;

[0028] Figure 8This is a block diagram of an electronic device used to implement the code processing method of the embodiments of this disclosure. Detailed Implementation

[0029] The exemplary embodiments of this disclosure are described below with reference to the accompanying drawings, including various details of the embodiments to aid understanding, and should be considered merely exemplary. Therefore, those skilled in the art will recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of this disclosure. Similarly, for clarity and brevity, descriptions of well-known functions and structures are omitted in the following description.

[0030] In TypeScript development, after editing object properties, the data type of each property needs to be declared. Common methods for this are to manually write the property declaration code, which is inefficient. Furthermore, since the same property declaration code may appear multiple times, repeatedly writing this code manually results in a significant amount of repetitive work, impacting development efficiency.

[0031] In practical use, manually written attribute declaration code may contain errors. If the manually written attribute declaration code can be automatically validated, the number of errors in the code can be reduced and the development efficiency can be improved.

[0032] The code processing methods, apparatus, electronic devices, and computer-readable storage media provided in this disclosure are intended to solve at least one of the above-mentioned technical problems of the prior art.

[0033] Figure 1 A flowchart illustrating a code processing method provided in an embodiment of this disclosure is shown, such as... Figure 1 As shown, the method can mainly include:

[0034] Step S110: Obtain the properties to be declared from the properties of the object in the code segment that meet the preset property conditions.

[0035] Step S120: Determine the data type of the attribute to be declared based on the attribute name.

[0036] Step S130: Based on the data type of the attribute to be declared, determine the first attribute declaration code corresponding to the attribute to be declared. The first attribute declaration code is used to define the data type of the attribute to be declared.

[0037] In this context, a code segment can be a piece of code developed using the TypeScript language to implement a specific program function. An object is a data object within the code segment, a data structure representing key-value pairs. An object typically has one or more properties.

[0038] The property declaration code is the code used in the declaration code to define the data type of the property.

[0039] In this embodiment of the disclosure, the data type can be a basic data type of the Typescript language, including but not limited to number, string, and generic (any) types.

[0040] The attribute to be declared is the attribute whose data type needs to be defined through attribute declaration code.

[0041] In this embodiment of the disclosure, preset attribute conditions can be pre-configured to identify all attributes of an object in the code segment that satisfy the preset attribute conditions as attributes to be declared. The first attribute declaration code is used to define the data type of the attribute to be declared.

[0042] As an example, the object is "User: Zhang San" and the attribute to be declared is "Age: 18". The data type of "Age: 18" needs to be defined in the first attribute declaration code. For example, the data type of the attribute to be declared "Age: 18" can be defined as numeric through the first attribute declaration code.

[0043] An attribute includes an attribute name and an attribute value. The attribute name identifies the attribute. There is a certain relationship between an attribute and its data type. Therefore, the data type of the attribute to be declared can be determined from the attribute name. For example, based on the attribute name "age", the data type of the attribute to be declared is determined to be numeric.

[0044] In this embodiment of the disclosure, after determining the data type of the attribute to be declared, a first attribute declaration code can be generated based on the data type of the attribute to be declared, so that the first attribute declaration code is used to define the data type of the attribute to be declared.

[0045] Specifically, the first property declaration code can be generated according to the predefined format of the property declaration code, so that the first property declaration code can conform to the specifications in the Typescript language.

[0046] As an example, the predefined format for property declaration code can be "let [property name]: [data type] = property value". Entering the property name, property value, and data type of the property to be declared into the above predefined format will yield the first property declaration code.

[0047] The method provided in this disclosure obtains the attributes to be declared from the properties of an object in a code segment that meet preset attribute conditions. Based on the attribute name of the attribute to be declared, the data type of the attribute to be declared is determined. Based on the data type of the attribute to be declared, a first attribute declaration code corresponding to the attribute to be declared is determined. The first attribute declaration code is used to define the data type of the attribute to be declared. Based on this solution, the attribute declaration code corresponding to the attribute to be declared can be automatically determined, which can replace the method of manually writing attribute declaration code and improve development efficiency.

[0048] In one optional approach of this disclosure, determining the data type of the attribute to be declared based on its attribute name includes:

[0049] Based on the preset correspondence between attribute names and data types, and based on the attribute name of the attribute to be declared, the data type of the attribute to be declared is determined.

[0050] In this embodiment of the disclosure, since each attribute generally corresponds to a fixed data type, the correspondence between attribute names and data types can be pre-configured so that the data type of the attribute to be declared can be quickly determined based on the attribute name of the attribute to be declared.

[0051] As an example, the data type corresponding to the attribute name "age" is numeric, and the data type corresponding to the attribute name "gender" is string.

[0052] In one optional method of this disclosure, the preset conditions include: the property to be declared is the adjusted property of the object in the code segment;

[0053] Before retrieving the properties to be declared from the properties of the object in the code segment that meet the preset property conditions, the method also includes:

[0054] The text monitoring function of the editor is used to monitor the properties of objects in the code segment;

[0055] In response to the detection that an object's property in the code segment has been adjusted, the adjusted property is identified as a property to be declared.

[0056] As an example, the method provided in this disclosure can be applied to scenarios where code segments are edited in an editor. Specifically, users can adjust the original properties of objects in a code segment within the editor. After the original properties of the object are adjusted, the data types corresponding to the original properties may change, requiring adjustments to the corresponding property declaration code. Therefore, the adjusted properties can be identified as properties to be declared.

[0057] In this embodiment of the disclosure, adjusting the attribute includes adding or modifying the attribute name and attribute value.

[0058] In this embodiment of the disclosure, the editor can be a programming tool that supports a type server. The editor provides a text listening application programming interface (API) for listening to adjustments in the text within the editor, so as to quickly detect adjustments to the properties of objects in the code segment.

[0059] In one optional embodiment of this disclosure, after determining the first attribute declaration code corresponding to the attribute to be declared based on the attribute name, the method further includes:

[0060] Adjust the code segment containing the second property declaration corresponding to the property to be declared before the adjustment to the first property declaration code.

[0061] In this embodiment of the disclosure, the attribute declaration code used to define the data type of the original attribute before adjusting the attribute can be referred to as the second attribute declaration code.

[0062] After determining the first property declaration code corresponding to the property to be declared, that is, after determining the property declaration code corresponding to the adjusted property, the second property declaration code can be adjusted to the first property declaration code.

[0063] In this embodiment of the disclosure, after monitoring the adjustment of the object's attribute in the code segment, the first attribute declaration code corresponding to the adjusted attribute can be determined, and the second attribute declaration code corresponding to the original attribute can be automatically adjusted to the first attribute declaration code, thereby updating the declaration code part of the currently edited object.

[0064] Specifically, adjustments to the properties of an object in a code segment can include adding new properties. In this case, updating the declaration code of the currently edited object can add the property declaration code corresponding to the new property to the declaration code of the currently edited object.

[0065] In practical use, the property declaration code for the same attribute may appear repeatedly in the code segment. To avoid manually rewriting the property declaration code for the same attribute, which would cause a lot of repetitive work, the property code corresponding to the same attribute in the code segment can be automatically updated after the property declaration code of the currently edited object is updated, thereby improving development efficiency.

[0066] In one alternative embodiment of this disclosure, the method further includes:

[0067] In response to the second attribute declaration code corresponding to the attribute to be declared before the adjustment in the code segment, it is adjusted to the first attribute declaration code. It is determined whether the abstract syntax tree corresponding to the code segment contains a second declaration node that is transformed from the same code as the first declaration node. The first declaration node is transformed from the second attribute declaration code.

[0068] In response to the presence of a second declaration node in the abstract syntax tree, determine the declaration code in the code segment that needs to be adjusted to obtain the second declaration node;

[0069] Adjust the declaration code to be adjusted to the first attribute declaration code.

[0070] In this embodiment of the disclosure, the code segment can be analyzed in advance and converted into an abstract syntax tree (AST). An abstract syntax tree is a tree-like representation of the abstract syntax structure of source code, where each node in the tree represents a structure in the source code.

[0071] In this embodiment, a listener can be pre-registered for the declaration code corresponding to all objects in the code segment to detect changes in the declaration code in a timely manner. When it is detected that the second attribute declaration code corresponding to the attribute to be declared before adjustment has been adjusted to the first attribute declaration code, the automatic update of the attribute declaration code corresponding to the attribute with the same name as the attribute to be declared in the code segment can be triggered.

[0072] Specifically, the node obtained from the second property declaration code in the abstract syntax tree can be recorded as the first declaration node. The second declaration node obtained from the same code as the first declaration node is searched in the abstract syntax tree. If the second declaration node can be found, the declaration code to be adjusted for the second declaration node is determined in the code segment. The declaration code to be adjusted is then adjusted to the first property declaration code, so as to automatically update the property declaration code corresponding to the property with the same property to be declared in the code segment.

[0073] As an example, consider the object "User: Zhang San". Its original attribute is "Gender: Male". The second attribute declaration code for the original attribute defines the data type of "Gender: Male", specifically "let[Gender]: [string] = Male". After the original attribute is adjusted, a new attribute to be declared is obtained: "Age: 18". The first attribute declaration code for this new attribute needs to define the data type of "Age: 18", specifically "let[Age]: [number] = 18". The second attribute declaration code is transformed into a first declaration node in the abstract syntax tree (AST). The AST is then searched for a second declaration node derived from the second attribute declaration code "let[Gender]: [string] = Male". If a second declaration node exists in the AST, the corresponding declaration code to be adjusted can be determined. This adjusted declaration code is the same as the code in the code segment "let[Gender]: [string] = Male". After determining the declaration codes to be adjusted, the declaration code to be adjusted can be changed from "let[gender]:[string] = male" to the first attribute declaration code "let[age]:[number] = 18".

[0074] In this embodiment of the disclosure, each listener may be pre-assigned a listener identifier, and each listener identifier is pre-associated with a node in the abstract syntax tree. Specifically, a node in the abstract syntax tree converted from a certain attribute declaration code can be associated with a listener used to listen to that attribute declaration code.

[0075] Based on the association between the listener identifier and the nodes in the abstract syntax tree, it is possible to quickly identify the first declaration node corresponding to the attribute being adjusted, and to quickly identify the declaration code to be adjusted from the code segment.

[0076] As an example, Figure 2 The diagram shows a flowchart illustrating a specific implementation of a code processing method provided in this embodiment.

[0077] like Figure 2 As shown, opening the editor launches a code editing tool that supports the TypeScript language.

[0078] Editing code refers to the process by which developers edit code using an editor.

[0079] Editor-Text Listening API refers to the text listening capabilities provided by the editor through the file listening API, which allows the editor to monitor the editing of objects in the code segment by the developer.

[0080] The processing service is activated when it detects that the code of an object has been edited. This service determines whether the object's properties have been adjusted in the code and automatically generates the property declaration code corresponding to the adjusted properties if such adjustments are made.

[0081] It can be updated, that is, it can determine whether the properties of an object in the code have been adjusted. If the properties of an object have been adjusted, the property declaration code corresponding to the adjusted properties can be updated.

[0082] Update the code, that is, update the property declaration code in the code segment that corresponds to the property before the property is adjusted to the property declaration code that corresponds to the property after the adjustment.

[0083] In one optional embodiment of this disclosure, the preset attribute conditions include:

[0084] In the corresponding property declaration code, the data type of the property is defined as the specified data type.

[0085] As an example, the method provided in this disclosure can be applied to scenarios where attribute declaration code is generated in batches for certain specific attributes in a code segment. Specifically, these specific attributes can be defined as specified data types, that is, the attribute declaration code corresponding to these specific attributes in the code segment is used to define the data type of these specific attributes as specified data types, and these specific attributes can be determined as attributes to be declared, thereby determining the first attribute declaration code corresponding to the attributes to be declared based on the scheme provided in this disclosure.

[0086] As an example, the data types of all "age: age value" and "height; height value" properties in the code snippet are predefined as specified data types, such as generics. That is, the property declaration code for the "age: age value" property is pre-written as "let[age]: [any] = age value", and the property declaration code for the "height; height value" property is pre-written as "let[height]: [any] = height value". All "age: age value" and "height; height value" properties are identified as properties to be declared, and then the corresponding first property declaration code is generated for each property. Specifically, the first property declaration code for the "age: age value" property is "let[age]: [number] = age value", and the first property declaration code for the "height; height value" property is "let[height]: [number] = height value".

[0087] In one alternative manner of this disclosure, the data type is specified as generic.

[0088] In this embodiment of the disclosure, since the TypeScript language supports generics (any), generics can be used as a specified data type, that is, the data type defined in the property declaration code corresponding to the property to be declared in the code segment is generic.

[0089] In one alternative embodiment of this disclosure, the method further includes:

[0090] Adjust the third property declaration code corresponding to the property to be declared in the code segment to the first property declaration code.

[0091] In this embodiment of the disclosure, the attribute declaration code corresponding to the attribute to be declared in the code segment can be referred to as the third attribute declaration code. The third attribute declaration code is used to define the attribute to be declared as a specified data type, such as generics.

[0092] After determining the actual first attribute declaration code corresponding to the attribute to be declared, the third attribute declaration code in the code segment can be adjusted to the first attribute declaration code, thus enabling the batch generation of attribute declaration codes corresponding to the attributes to be declared in the code segment.

[0093] As an example, the data type of all "age: age value" properties in the code snippet is predefined as "any", and the corresponding third property declaration code is pre-written as "let[age]:[any] = age value". Treating all "age: age value" properties as properties to be declared, the corresponding first property declaration code is specifically "let[age]:[number] = age value". The third property declaration code is then adjusted to the first property declaration code, that is, "let[age]:[any] = age value" is changed to "let[age]:[number] = age value".

[0094] In this embodiment of the disclosure, a user can edit a code segment through a terminal device and define the attribute to be declared as a specified data type in the third attribute declaration code corresponding to the attribute to be declared in the code segment. Then, the terminal device can send a code adjustment request to the backend server for the code segment. The backend server can determine the first attribute declaration code corresponding to the attribute to be declared, and then adjust the third attribute declaration code in the code segment to the first attribute declaration code to obtain the adjusted code segment, which is then returned to the user.

[0095] In this embodiment, when manually writing attribute declaration code to declare the data type of attributes, some attributes may be marginalized and easily overlooked by developers, resulting in the omission of attribute declaration code for these attributes. Based on this solution, since the attribute declaration code for all attributes to be declared is automatically determined, it ensures that the attribute declaration code for these marginalized attributes is not omitted.

[0096] In one optional embodiment of this disclosure, after determining the first attribute declaration code corresponding to the attribute to be declared based on the attribute name, the method further includes:

[0097] Obtain the declaration code of the attribute to be declared, and verify the declaration code of the attribute to be verified based on the first attribute declaration code.

[0098] In this embodiment of the disclosure, the attribute declaration code to be verified can be attribute declaration code manually written by the developer for the attribute to be declared.

[0099] The first attribute declaration code corresponding to the attribute to be declared, which is automatically determined by the scheme provided in this embodiment, can also be used to verify the manually written attribute declaration code to be verified.

[0100] Specifically, the first attribute declaration code corresponding to the same attribute to be declared can be compared with the attribute declaration code to be verified. If it is determined that there are differences between the attribute declaration code to be verified and the first attribute declaration code, a prompt message can be sent to the developers regarding the differences.

[0101] In this embodiment, a user can edit code via a terminal device, defining the attribute to be declared as a specified data type in the third attribute declaration code corresponding to the attribute to be declared in the code segment, thus obtaining a first code segment. Simultaneously, the user can manually write the attribute declaration code to be verified in the code segment, resulting in a second code segment. The terminal device can then send a verification request to the backend server for the attribute declaration code to be verified, carrying both the first and second code segments. The backend server can determine the first attribute declaration code corresponding to the attribute to be declared, and then adjust the third attribute declaration code in the first code segment to the first attribute declaration code, obtaining an adjusted first code segment. The adjusted first code segment is compared with the second code segment to verify the attribute declaration code to be verified. If the comparison reveals differences between the attribute declaration code to be verified and the first attribute declaration code, a prompt message can be generated and returned to the terminal device.

[0102] Figure 3 A flowchart illustrating another code processing method provided in an embodiment of this disclosure is shown, such as... Figure 3 As shown, the method can mainly include:

[0103] Step S310: Monitor the properties of objects in the code segment using the text monitoring function of the editor.

[0104] Step S320: In response to the detection that an object's property in the code segment has been adjusted, the adjusted property is determined as the property to be declared.

[0105] Step S330: Determine the data type of the attribute to be declared based on the attribute name.

[0106] Step S340: Based on the data type of the attribute to be declared, determine the first attribute declaration code corresponding to the attribute to be declared. The first attribute declaration code is used to define the data type of the attribute to be declared.

[0107] Step S350: Adjust the second attribute declaration code corresponding to the attribute to be declared before the adjustment in the code segment to the first attribute declaration code.

[0108] Step S360: In response to the second attribute declaration code corresponding to the attribute to be declared before adjustment in the code segment being adjusted to the first attribute declaration code, determine whether the abstract syntax tree corresponding to the code segment contains a second declaration node that is converted from the same code as the first declaration node. The first declaration node is converted from the second attribute declaration code.

[0109] Step S370: In response to the presence of a second declaration node in the abstract syntax tree, determine the declaration code to be adjusted in the code segment used to transform the second declaration node.

[0110] Step S380: Adjust the declaration code to be adjusted to the first attribute declaration code.

[0111] In this context, a code segment can be a piece of code developed using the TypeScript language to implement a specific program function. An object is a data object within the code segment, a data structure representing key-value pairs. An object typically has one or more properties.

[0112] The property declaration code is the code used in the declaration code to define the data type of the property.

[0113] In this embodiment of the disclosure, the data type can be a basic data type of the Typescript language, including but not limited to number, string, and generic (any) types.

[0114] The attribute to be declared is the attribute whose data type needs to be defined through attribute declaration code.

[0115] The first property declaration code is used to define the data type of the property to be declared.

[0116] As an example, the object is "User: Zhang San" and the attribute to be declared is "Age: 18". The data type of "Age: 18" needs to be defined in the first attribute declaration code. For example, the data type of the attribute to be declared "Age: 18" can be defined as numeric through the first attribute declaration code.

[0117] As an example, the method provided in this disclosure can be applied to scenarios where code segments are edited in an editor. Specifically, users can adjust the original properties of objects in a code segment within the editor. After the original properties of the object are adjusted, the data types corresponding to the original properties may change, requiring adjustments to the corresponding property declaration code. Therefore, the adjusted properties can be identified as properties to be declared.

[0118] In this embodiment of the disclosure, adjusting the attribute includes adding or modifying the attribute name and attribute value.

[0119] In this embodiment of the disclosure, the editor can be a programming tool that supports a type server. The editor provides a text listening application programming interface (API) for listening to adjustments in the text within the editor, so as to quickly detect adjustments to the properties of objects in the code segment.

[0120] An attribute includes an attribute name and an attribute value. The attribute name identifies the attribute. There is a certain relationship between an attribute and its data type. Therefore, the data type of the attribute to be declared can be determined from the attribute name. For example, based on the attribute name "age", the data type of the attribute to be declared is determined to be numeric.

[0121] In this embodiment of the disclosure, after determining the data type of the attribute to be declared, a first attribute declaration code can be generated based on the data type of the attribute to be declared, so that the first attribute declaration code is used to define the data type of the attribute to be declared.

[0122] Specifically, the first property declaration code can be generated according to the predefined format of the property declaration code, so that the first property declaration code can conform to the specifications in the Typescript language.

[0123] As an example, the predefined format for property declaration code can be "let [property name]: [data type] = property value". Entering the property name, property value, and data type of the property to be declared into the above predefined format will yield the first property declaration code.

[0124] The method provided in this disclosure obtains the attributes to be declared from the properties of an object in a code segment that meet preset attribute conditions. Based on the attribute name of the attribute to be declared, the data type of the attribute to be declared is determined. Based on the data type of the attribute to be declared, a first attribute declaration code corresponding to the attribute to be declared is determined. The first attribute declaration code is used to define the data type of the attribute to be declared. Based on this solution, the attribute declaration code corresponding to the attribute to be declared can be automatically determined, which can replace the method of manually writing attribute declaration code and improve development efficiency.

[0125] In this embodiment of the disclosure, the attribute declaration code used to define the data type of the original attribute before adjusting the attribute can be referred to as the second attribute declaration code.

[0126] After determining the first property declaration code corresponding to the property to be declared, that is, after determining the property declaration code corresponding to the adjusted property, the second property declaration code can be adjusted to the first property declaration code.

[0127] In this embodiment of the disclosure, after monitoring the adjustment of the object's attribute in the code segment, the first attribute declaration code corresponding to the adjusted attribute can be determined, and the second attribute declaration code corresponding to the original attribute can be automatically adjusted to the first attribute declaration code, thereby updating the declaration code part of the currently edited object.

[0128] Specifically, adjustments to the properties of an object in a code segment can include adding new properties. In this case, updating the declaration code of the currently edited object can add the property declaration code corresponding to the new property to the declaration code of the currently edited object.

[0129] In practical use, the property declaration code for the same attribute may appear repeatedly in the code segment. To avoid manually rewriting the property declaration code for the same attribute, which would cause a lot of repetitive work, the property code corresponding to the same attribute in the code segment can be automatically updated after the property declaration code of the currently edited object is updated, thereby improving development efficiency.

[0130] In this embodiment of the disclosure, the code segment can be analyzed in advance and converted into an abstract syntax tree (AST). An abstract syntax tree is a tree-like representation of the abstract syntax structure of source code, where each node in the tree represents a structure in the source code.

[0131] In this embodiment, a listener can be pre-registered for the declaration code corresponding to all objects in the code segment to detect changes in the declaration code in a timely manner. When it is detected that the second attribute declaration code corresponding to the attribute to be declared before adjustment has been adjusted to the first attribute declaration code, the automatic update of the attribute declaration code corresponding to the attribute with the same name as the attribute to be declared in the code segment can be triggered.

[0132] Specifically, the node obtained from the second property declaration code in the abstract syntax tree can be recorded as the first declaration node. The second declaration node obtained from the same code as the first declaration node is searched in the abstract syntax tree. If the second declaration node can be found, the declaration code to be adjusted for the second declaration node is determined in the code segment. The declaration code to be adjusted is then adjusted to the first property declaration code, so as to automatically update the property declaration code corresponding to the property with the same property to be declared in the code segment.

[0133] As an example, consider the object "User: Zhang San". Its original attribute is "Gender: Male". The second attribute declaration code for the original attribute defines the data type of "Gender: Male", specifically "let[Gender]: [string] = Male". After the original attribute is adjusted, a new attribute to be declared is obtained: "Age: 18". The first attribute declaration code for this new attribute needs to define the data type of "Age: 18", specifically "let[Age]: [number] = 18". The second attribute declaration code is transformed into a first declaration node in the abstract syntax tree (AST). The AST is then searched for a second declaration node derived from the second attribute declaration code "let[Gender]: [string] = Male". If a second declaration node exists in the AST, the corresponding declaration code to be adjusted can be determined. This adjusted declaration code is the same as the code in the code segment "let[Gender]: [string] = Male". After determining the declaration codes to be adjusted, the declaration code to be adjusted can be changed from "let[gender]:[string] = male" to the first attribute declaration code "let[age]:[number] = 18".

[0134] In this embodiment of the disclosure, each listener may be pre-assigned a listener identifier, and each listener identifier is pre-associated with a node in the abstract syntax tree. Specifically, a node in the abstract syntax tree converted from a certain attribute declaration code can be associated with a listener used to listen to that attribute declaration code.

[0135] Based on the association between the listener identifier and the nodes in the abstract syntax tree, it is possible to quickly identify the first declaration node corresponding to the attribute being adjusted, and to quickly identify the declaration code to be adjusted from the code segment.

[0136] Figure 4 A flowchart illustrating another code processing method provided in an embodiment of this disclosure is shown, such as... Figure 4 As shown, the method can mainly include:

[0137] Step S410: Obtain the properties to be declared from the properties of the object in the code segment that meet the preset property conditions. The preset property conditions include: the data type of the property is defined as a specified data type in the corresponding property declaration code.

[0138] Step S420: Determine the data type of the attribute to be declared based on the attribute name.

[0139] Step S430: Based on the data type of the attribute to be declared, determine the first attribute declaration code corresponding to the attribute to be declared. The first attribute declaration code is used to define the data type of the attribute to be declared.

[0140] Step S440: Adjust the third attribute declaration code corresponding to the attribute to be declared in the code segment to the first attribute declaration code.

[0141] In this context, a code segment can be a piece of code developed using the TypeScript language to implement a specific program function. An object is a data object within the code segment, a data structure representing key-value pairs. An object typically has one or more properties.

[0142] The property declaration code is the code used in the declaration code to define the data type of the property.

[0143] In this embodiment of the disclosure, the data type can be a basic data type of the Typescript language, including but not limited to number, string, and generic (any) types.

[0144] The attribute to be declared is the attribute whose data type needs to be defined through attribute declaration code.

[0145] In this embodiment of the disclosure, preset attribute conditions can be pre-configured to identify all attributes of an object in the code segment that satisfy the preset attribute conditions as attributes to be declared. The first attribute declaration code is used to define the data type of the attribute to be declared.

[0146] As an example, the object is "User: Zhang San" and the attribute to be declared is "Age: 18". The data type of "Age: 18" needs to be defined in the first attribute declaration code. For example, the data type of the attribute to be declared "Age: 18" can be defined as numeric through the first attribute declaration code.

[0147] An attribute includes an attribute name and an attribute value. The attribute name identifies the attribute. There is a certain relationship between an attribute and its data type. Therefore, the data type of the attribute to be declared can be determined from the attribute name. For example, based on the attribute name "age", the data type of the attribute to be declared is determined to be numeric.

[0148] As an example, the method provided in this disclosure can be applied to scenarios where attribute declaration code is generated in batches for certain specific attributes in a code segment. Specifically, these specific attributes can be defined as specified data types, that is, the attribute declaration code corresponding to these specific attributes in the code segment is used to define the data type of these specific attributes as specified data types, and these specific attributes can be determined as attributes to be declared, thereby determining the first attribute declaration code corresponding to the attributes to be declared based on the scheme provided in this disclosure.

[0149] As an example, the data types of all "age: age value" and "height; height value" properties in the code snippet are predefined as specified data types, such as generics. That is, the property declaration code for the "age: age value" property is pre-written as "let[age]: [any] = age value", and the property declaration code for the "height; height value" property is pre-written as "let[height]: [any] = height value". All "age: age value" and "height; height value" properties are identified as properties to be declared, and then the corresponding first property declaration code is generated for each property. Specifically, the first property declaration code for the "age: age value" property is "let[age]: [number] = age value", and the first property declaration code for the "height; height value" property is "let[height]: [number] = height value".

[0150] In this embodiment of the disclosure, after determining the data type of the attribute to be declared, a first attribute declaration code can be generated based on the data type of the attribute to be declared, so that the first attribute declaration code is used to define the data type of the attribute to be declared.

[0151] Specifically, the first property declaration code can be generated according to the predefined format of the property declaration code, so that the first property declaration code can conform to the specifications in the Typescript language.

[0152] As an example, the predefined format for property declaration code can be "let [property name]: [data type] = property value". Entering the property name, property value, and data type of the property to be declared into the above predefined format will yield the first property declaration code.

[0153] The method provided in this disclosure obtains the attributes to be declared from the properties of an object in a code segment that meet preset attribute conditions. Based on the attribute name of the attribute to be declared, the data type of the attribute to be declared is determined. Based on the data type of the attribute to be declared, a first attribute declaration code corresponding to the attribute to be declared is determined. The first attribute declaration code is used to define the data type of the attribute to be declared. Based on this solution, the attribute declaration code corresponding to the attribute to be declared can be automatically determined, which can replace the method of manually writing attribute declaration code and improve development efficiency.

[0154] In this embodiment of the disclosure, the attribute declaration code corresponding to the attribute to be declared in the code segment can be referred to as the third attribute declaration code. The third attribute declaration code is used to define the attribute to be declared as a specified data type, such as generics.

[0155] After determining the actual first attribute declaration code corresponding to the attribute to be declared, the third attribute declaration code in the code segment can be adjusted to the first attribute declaration code, thus enabling the batch generation of attribute declaration codes corresponding to the attributes to be declared in the code segment.

[0156] As an example, the data type of all "age: age value" properties in the code snippet is predefined as "any", and the corresponding third property declaration code is pre-written as "let[age]:[any] = age value". Treating all "age: age value" properties as properties to be declared, the corresponding first property declaration code is specifically "let[age]:[number] = age value". The third property declaration code is then adjusted to the first property declaration code, that is, "let[age]:[any] = age value" is changed to "let[age]:[number] = age value".

[0157] In this embodiment of the disclosure, a user can edit a code segment through a terminal device and define the attribute to be declared as a specified data type in the third attribute declaration code corresponding to the attribute to be declared in the code segment. Then, the terminal device can send a code adjustment request to the backend server for the code segment. The backend server can determine the first attribute declaration code corresponding to the attribute to be declared, and then adjust the third attribute declaration code in the code segment to the first attribute declaration code to obtain the adjusted code segment, which is then returned to the user.

[0158] In this embodiment, when manually writing attribute declaration code to declare the data type of attributes, some attributes may be marginalized and easily overlooked by developers, resulting in the omission of attribute declaration code for these attributes. Based on this solution, since the attribute declaration code for all attributes to be declared is automatically determined, it ensures that the attribute declaration code for these marginalized attributes is not omitted.

[0159] Based on and Figure 1 The method shown follows the same principle. Figure 5 A schematic diagram of the structure of a code processing apparatus provided in an embodiment of this disclosure is shown, such as... Figure 5 As shown, the code processing device 50 may include:

[0160] The undeclared property acquisition module 510 is used to acquire undeclared properties that meet preset property conditions from the properties of objects in the code segment;

[0161] The data type determination module 520 is used to determine the data type of the attribute to be declared based on the attribute name of the attribute to be declared;

[0162] The declaration code determination module 530 is used to determine the first attribute declaration code corresponding to the attribute to be declared based on the data type of the attribute to be declared. The first attribute declaration code is used to define the data type of the attribute to be declared.

[0163] The apparatus provided in this disclosure obtains attributes that satisfy preset attribute conditions from the properties of an object in a code segment, determines the data type of the attribute based on its attribute name, and determines the first attribute declaration code corresponding to the attribute based on its data type. The first attribute declaration code is used to define the data type of the attribute to be declared. Based on this solution, the attribute declaration code corresponding to the attribute to be declared can be automatically determined, which can replace the method of manually writing attribute declaration code and improve development efficiency.

[0164] Optionally, the data type determination module is specifically used for:

[0165] Based on the preset correspondence between attribute names and data types, and based on the attribute name of the attribute to be declared, the data type of the attribute to be declared is determined.

[0166] Optionally, the preset conditions include: the property to be declared is the adjusted property of the object in the code segment;

[0167] The device also includes a module for determining the attributes to be declared, which is used for:

[0168] Before retrieving the properties to be declared from the properties of objects in the code segment that meet the preset property conditions, the properties of objects in the code segment are monitored based on the text monitoring function of the editor.

[0169] In response to the detection that an object's property in the code segment has been adjusted, the adjusted property is identified as a property to be declared.

[0170] Optionally, the above apparatus further includes: a first code adjustment module, the first code adjustment module being used for:

[0171] After determining the first attribute declaration code corresponding to the attribute to be declared based on the attribute name, the second attribute declaration code corresponding to the attribute to be declared in the code segment before adjustment is adjusted to the first attribute declaration code.

[0172] Optionally, the first code adjustment module is also used for:

[0173] In response to the second attribute declaration code corresponding to the attribute to be declared before the adjustment in the code segment, it is adjusted to the first attribute declaration code. It is determined whether the abstract syntax tree corresponding to the code segment contains a second declaration node that is transformed from the same code as the first declaration node. The first declaration node is transformed from the second attribute declaration code.

[0174] In response to the presence of a second declaration node in the abstract syntax tree, determine the declaration code in the code segment that needs to be adjusted to obtain the second declaration node;

[0175] Adjust the declaration code to be adjusted to the first attribute declaration code.

[0176] Optionally, the preset attribute conditions include:

[0177] In the corresponding property declaration code, the data type of the property is defined as the specified data type.

[0178] Optionally, the data type can be specified as generic.

[0179] Optionally, the above-mentioned device further includes: a second code adjustment module, the second code adjustment module being used for:

[0180] Adjust the third property declaration code corresponding to the property to be declared in the code segment to the first property declaration code.

[0181] Optionally, the above apparatus further includes: a code verification module, the code verification module being used for:

[0182] After determining the first attribute declaration code corresponding to the attribute to be declared based on the attribute name, the attribute declaration code to be verified corresponding to the attribute to be declared is obtained, and the attribute declaration code to be verified is verified based on the first attribute declaration code.

[0183] It is understood that the above-described modules of the code processing apparatus in the embodiments of this disclosure have implementations Figure 1 The embodiments shown illustrate the functionality of corresponding steps in the code processing method. This functionality can be implemented in hardware or by hardware executing corresponding software. The hardware or software includes one or more modules corresponding to the above-described functions. These modules can be software and / or hardware; each module can be implemented individually or multiple modules can be integrated. For a detailed description of the functions of each module in the above-described code processing device, please refer to [link to relevant documentation]. Figure 1 The corresponding descriptions of the code processing methods in the embodiments shown are not repeated here.

[0184] Based on and Figure 3 The method shown follows the same principle. Figure 6 A schematic diagram of another code processing apparatus provided in an embodiment of this disclosure is shown, such as... Figure 6 As shown, the code processing device 60 may include:

[0185] The module 610 for determining properties to be declared is used to listen to the properties of objects in the code segment based on the text listening function of the editor; in response to the detection that the property of an object in the code segment has been adjusted, the adjusted property is determined as the property to be declared.

[0186] The data type determination module 620 determines the data type of the attribute to be declared based on the attribute name.

[0187] The declaration code determination module 630 is used to determine the first attribute declaration code corresponding to the attribute to be declared based on the data type of the attribute to be declared. The first attribute declaration code is used to define the data type of the attribute to be declared.

[0188] The first code adjustment module 640 is used to adjust the second attribute declaration code corresponding to the attribute to be declared before the adjustment in the code segment to the first attribute declaration code;

[0189] The second code adjustment module 650 is used to respond to the second attribute declaration code corresponding to the attribute to be declared before adjustment in the code segment being adjusted to the first attribute declaration code, to determine whether the abstract syntax tree corresponding to the code segment contains a second declaration node that is converted from the same code as the first declaration node, wherein the first declaration node is converted from the second attribute declaration code; in response to the inclusion of a second declaration node in the abstract syntax tree, to determine the declaration code to be adjusted in the code segment used to convert the second declaration node; and to adjust the declaration code to be adjusted to the first attribute declaration code.

[0190] The apparatus provided in this disclosure obtains attributes that satisfy preset attribute conditions from the properties of an object in a code segment, determines the data type of the attribute based on its attribute name, and determines the first attribute declaration code corresponding to the attribute based on its data type. The first attribute declaration code is used to define the data type of the attribute to be declared. Based on this solution, the attribute declaration code corresponding to the attribute to be declared can be automatically determined, which can replace the method of manually writing attribute declaration code and improve development efficiency.

[0191] It is understood that the above-described modules of the code processing apparatus in the embodiments of this disclosure have implementations Figure 3 The embodiments shown illustrate the functionality of corresponding steps in the code processing method. This functionality can be implemented in hardware or by hardware executing corresponding software. The hardware or software includes one or more modules corresponding to the above-described functions. These modules can be software and / or hardware; each module can be implemented individually or multiple modules can be integrated. For a detailed description of the functions of each module in the above-described code processing device, please refer to [link to relevant documentation]. Figure 3 The corresponding descriptions of the code processing methods in the embodiments shown are not repeated here.

[0192] Based on and Figure 4 The method shown follows the same principle. Figure 7 A schematic diagram of the structure of another code processing apparatus provided in an embodiment of this disclosure is shown, such as... Figure 7 As shown, the code processing device 70 may include:

[0193] The undeclared property acquisition module 710 is used to acquire undeclared properties that meet preset property conditions from the properties of an object in the code segment. The preset property conditions include: the data type of the property is defined as a specified data type in the corresponding property declaration code.

[0194] The data type determination module 720 is used to determine the data type of the attribute to be declared based on the attribute name of the attribute to be declared;

[0195] The declaration code determination module 730 is used to determine the first attribute declaration code corresponding to the attribute to be declared based on the data type of the attribute to be declared. The first attribute declaration code is used to define the data type of the attribute to be declared.

[0196] The code adjustment module 740 is used to adjust the third attribute declaration code corresponding to the attribute to be declared in the code segment to the first attribute declaration code.

[0197] The apparatus provided in this disclosure obtains attributes that satisfy preset attribute conditions from the properties of an object in a code segment, determines the data type of the attribute based on its attribute name, and determines the first attribute declaration code corresponding to the attribute based on its data type. The first attribute declaration code is used to define the data type of the attribute to be declared. Based on this solution, the attribute declaration code corresponding to the attribute to be declared can be automatically determined, which can replace the method of manually writing attribute declaration code and improve development efficiency.

[0198] It is understood that the above-described modules of the code processing apparatus in the embodiments of this disclosure have implementations Figure 4 The embodiments shown illustrate the functionality of corresponding steps in the code processing method. This functionality can be implemented in hardware or by hardware executing corresponding software. The hardware or software includes one or more modules corresponding to the above-described functions. These modules can be software and / or hardware; each module can be implemented individually or multiple modules can be integrated. For a detailed description of the functions of each module in the above-described code processing device, please refer to [link to relevant documentation]. Figure 4 The corresponding descriptions of the code processing methods in the embodiments shown are not repeated here.

[0199] The collection, storage, use, processing, transmission, provision, and disclosure of user personal information involved in the technical solution disclosed herein comply with the provisions of relevant laws and regulations and do not violate public order and good morals.

[0200] According to embodiments of this disclosure, this disclosure also provides an electronic device, a readable storage medium, and a computer program product.

[0201] The electronic device includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, the instructions being executed by the at least one processor to enable the at least one processor to perform the code processing method provided in the embodiments of this disclosure.

[0202] Compared with existing technologies, this electronic device obtains the attributes to be declared from the properties of objects in the code segment that meet preset attribute conditions. Based on the attribute name, it determines the data type of the attribute to be declared, and based on the data type, it determines the corresponding first attribute declaration code. The first attribute declaration code is used to define the data type of the attribute to be declared. Based on this solution, the attribute declaration code corresponding to the attribute to be declared can be automatically determined, which can replace the method of manually writing attribute declaration code and improve development efficiency.

[0203] The readable storage medium is a non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to cause the computer to execute the code processing methods provided in the embodiments of this disclosure.

[0204] Compared with existing technologies, this readable storage medium obtains the properties to be declared from the attributes of an object in the code segment that meet preset property conditions. Based on the property name of the property to be declared, it determines the data type of the property to be declared. Based on the data type of the property to be declared, it determines the first property declaration code corresponding to the property to be declared. The first property declaration code is used to define the data type of the property to be declared. Based on this solution, the property declaration code corresponding to the property to be declared can be automatically determined, which can replace the method of manually writing property declaration code and improve development efficiency.

[0205] The computer program product includes a computer program that, when executed by a processor, implements the code processing methods provided in the embodiments of this disclosure.

[0206] Compared with existing technologies, this computer program product obtains the attributes to be declared from the properties of objects in the code segment that meet preset attribute conditions. Based on the attribute name, it determines the data type of the attribute to be declared, and based on the data type, it determines the corresponding first attribute declaration code. The first attribute declaration code is used to define the data type of the attribute to be declared. Based on this solution, the attribute declaration code corresponding to the attribute to be declared can be automatically determined, which can replace the method of manually writing attribute declaration code and improve development efficiency.

[0207] Figure 8 A schematic block diagram of an example electronic device 80 that can be used to implement embodiments of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device may also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the present disclosure described and / or claimed herein.

[0208] like Figure 8As shown, the electronic device 80 includes a computing unit 810, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 820 or a computer program loaded from a storage unit 880 into a random access memory (RAM) 830. The RAM 830 may also store various programs and data required for the operation of the device 80. The computing unit 810, ROM 820, and RAM 830 are interconnected via a bus 840. An input / output (I / O) interface 850 is also connected to the bus 840.

[0209] Multiple components in device 80 are connected to I / O interface 850, including: input unit 860, such as keyboard, mouse, etc.; output unit 870, such as various types of monitors, speakers, etc.; storage unit 880, such as disk, optical disk, etc.; and communication unit 890, such as network card, modem, wireless transceiver, etc. Communication unit 890 allows device 80 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.

[0210] The computing unit 810 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of the computing unit 810 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. The computing unit 810 executes the code processing methods provided in the embodiments of this disclosure. For example, in some embodiments, executing the code processing methods provided in the embodiments of this disclosure can be implemented as a computer software program tangibly contained in a machine-readable medium, such as storage unit 880. In some embodiments, part or all of the computer program can be loaded and / or installed on device 80 via ROM 820 and / or communication unit 890. When the computer program is loaded into RAM 830 and executed by the computing unit 810, one or more steps of the code processing methods provided in the embodiments of this disclosure can be performed. Alternatively, in other embodiments, the computing unit 810 can be configured to execute the code processing methods provided in the embodiments of this disclosure by any other suitable means (e.g., by means of firmware).

[0211] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SoCs), payload-programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.

[0212] The program code used to implement the methods of this disclosure may be written in any combination of one or more programming languages. This program code may be provided to a processor or controller of a general-purpose computer, special-purpose computer, or other programmable data processing apparatus, such that when executed by the processor or controller, the program code causes the functions / operations specified in the flowcharts and / or block diagrams to be implemented. The program code may be executed entirely on a machine, partially on a machine, as a standalone software package partially on a machine and partially on a remote machine, or entirely on a remote machine or server.

[0213] In the context of this disclosure, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can be, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, 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), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.

[0214] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device for displaying information to the user (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor); and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the computer. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).

[0215] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as a data server), or computing systems that include middleware components (e.g., an application server), or computing systems that include frontend components (e.g., a user computer with a graphical user interface or web browser through which a user can interact with embodiments of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., a communication network). Examples of communication networks include local area networks (LANs), wide area networks (WANs), and the Internet.

[0216] Computer systems can include clients and servers. Clients and servers are generally located far apart and typically interact via communication networks. Client-server relationships are created by computer programs running on the respective computers and having a client-server relationship with each other. Servers can be cloud servers, servers in distributed systems, or servers incorporating blockchain technology.

[0217] It should be understood that the various forms of processes shown above can be used to rearrange, add, or delete steps. For example, the steps described in this disclosure can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution disclosed in this disclosure can be achieved, and this is not limited herein.

[0218] The specific embodiments described above do not constitute a limitation on the scope of protection of this disclosure. Those skilled in the art should understand that various adjustments, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any adjustments, equivalent substitutions, and improvements made within the spirit and principles of this disclosure should be included within the scope of protection of this disclosure.

Claims

1. A code processing method, comprising: Retrieves the undeclared properties of an object in a TypeScript code snippet that meet the preset property conditions; The preset attribute condition is as follows: in the code segment, the attribute to be declared has been defined as a specified data type in the corresponding attribute declaration code; the specified data type is generic. Based on the attribute name of the attribute to be declared, determine the data type of the attribute to be declared; Based on the data type of the attribute to be declared and the predefined format of the attribute declaration in the Typescript language, the first attribute declaration code corresponding to the attribute to be declared is determined. The first attribute declaration code is used to accurately define the data type of the attribute to be declared. It is determined that the abstract syntax tree corresponding to the code segment contains a declaration node corresponding to the third attribute declaration code, wherein the third attribute declaration code is the attribute declaration code in the code segment that defines the data type of the attribute to be declared as generic; Based on the declaration nodes in the abstract syntax tree, locate the positions of all declaration codes to be adjusted in the code segment; Replace all located declaration codes that need adjustment with the first attribute declaration code; The preset attribute conditions include: the attribute to be declared is the adjusted attribute among the attributes of the object in the code segment; wherein, adjusting the attribute includes adding or modifying the attribute name and attribute value; Before retrieving the properties to be declared from the properties of the object in the code segment that meet the preset property conditions, the method further includes: The text listening function of the editor is used to listen to the properties of objects in the code segment; In response to the detection that an object's property in the code segment has been adjusted, the adjusted property is determined as the property to be declared. After determining the first attribute declaration code corresponding to the attribute to be declared based on the attribute name, the method further includes: The second attribute declaration code corresponding to the attribute to be declared in the code segment before the adjustment is changed to the first attribute declaration code.

2. The method according to claim 1, wherein, Determining the data type of the attribute to be declared based on its attribute name includes: Based on the preset correspondence between attribute names and data types, and based on the attribute name of the attribute to be declared, the data type of the attribute to be declared is determined.

3. The method according to claim 1, further comprising: In response to the second attribute declaration code corresponding to the attribute to be declared before the code segment is adjusted to the first attribute declaration code, it is determined whether the abstract syntax tree corresponding to the code segment contains a second declaration node that is converted from the same code as the first declaration node, wherein the first declaration node is converted from the second attribute declaration code; In response to the inclusion of the second declaration node in the abstract syntax tree, the adjustment declaration code in the code segment used to transform to obtain the second declaration node is determined; Adjust the declaration code to be adjusted to the first attribute declaration code.

4. The method according to claim 1, after determining the first attribute declaration code corresponding to the attribute to be declared based on the attribute name of the attribute to be declared, the method further includes: Obtain the attribute declaration code to be verified corresponding to the attribute to be declared, and verify the attribute declaration code to be verified based on the first attribute declaration code.

5. A code processing apparatus, comprising: The module for retrieving undeclared properties is used to retrieve undeclared properties from the properties of an object in a Typescript code segment that meet preset property conditions. The preset attribute condition is as follows: in the code segment, the attribute to be declared has been defined as a specified data type in the corresponding attribute declaration code; the specified data type is generic. The data type determination module is used to determine the data type of the attribute to be declared based on the attribute name of the attribute to be declared; The declaration code determination module is used to determine the first attribute declaration code corresponding to the attribute to be declared based on the data type of the attribute to be declared and the predefined format of attribute declaration in the Typescript language. The first attribute declaration code is used to accurately define the data type of the attribute to be declared. It is determined that the abstract syntax tree corresponding to the code segment contains a declaration node corresponding to the third attribute declaration code, wherein the third attribute declaration code is the attribute declaration code in the code segment that defines the data type of the attribute to be declared as generic; Based on the declaration nodes in the abstract syntax tree, locate the positions of all declaration codes to be adjusted in the code segment; Replace all located declaration codes that need adjustment with the first attribute declaration code; The preset attribute conditions include: the attribute to be declared is the adjusted attribute among the attributes of the object in the code segment; wherein, adjusting the attribute includes adding or modifying the attribute name and attribute value; The device further includes a module for determining attributes to be declared, which is used for: Before obtaining the properties to be declared that meet the preset property conditions from the properties of the objects in the code segment, the properties of the objects in the code segment are monitored based on the text monitoring function of the editor. In response to the detection that an object's property in the code segment has been adjusted, the adjusted property is determined as the property to be declared. The device further includes: a first code adjustment module, the first code adjustment module being used for: After determining the first attribute declaration code corresponding to the attribute to be declared based on the attribute name, the second attribute declaration code corresponding to the attribute to be declared in the code segment before adjustment is adjusted to the first attribute declaration code.

6. The apparatus according to claim 5, wherein, The data type determination module is specifically used for: Based on the preset correspondence between attribute names and data types, and based on the attribute name of the attribute to be declared, the data type of the attribute to be declared is determined.

7. The apparatus according to claim 5, wherein, The first code adjustment module is also used for: In response to the second attribute declaration code corresponding to the attribute to be declared before the code segment is adjusted to the first attribute declaration code, it is determined whether the abstract syntax tree corresponding to the code segment contains a second declaration node that is converted from the same code as the first declaration node, wherein the first declaration node is converted from the second attribute declaration code; In response to the inclusion of the second declaration node in the abstract syntax tree, the adjustment declaration code in the code segment used to transform to obtain the second declaration node is determined; Adjust the declaration code to be adjusted to the first attribute declaration code.

8. The apparatus according to claim 5, further comprising: The code verification module is used for: After determining the first attribute declaration code corresponding to the attribute to be declared based on the attribute name of the attribute to be declared, the attribute declaration code to be verified corresponding to the attribute to be declared is obtained, and the attribute declaration code to be verified is verified based on the first attribute declaration code.

9. An electronic device, comprising: At least one processor; as well as A memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor to enable the at least one processor to perform the method of any one of claims 1-4.

10. A non-transitory computer-readable storage medium storing computer instructions, wherein, The computer instructions are used to cause the computer to perform the method according to any one of claims 1-4.

11. A computer program product comprising a computer program that, when executed by a processor, implements the method according to any one of claims 1-4.