CN113420531B - Code text conversion method, device and storage medium - Google Patents

Code text conversion method, device and storage medium Download PDF

Info

Publication number
CN113420531B
CN113420531B CN202110702137.1A CN202110702137A CN113420531B CN 113420531 B CN113420531 B CN 113420531B CN 202110702137 A CN202110702137 A CN 202110702137A CN 113420531 B CN113420531 B CN 113420531B
Authority
CN
China
Prior art keywords
class
attribute
data type
type
initial data
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202110702137.1A
Other languages
Chinese (zh)
Other versions
CN113420531A (en
Inventor
李亚东
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Dajia Internet Information Technology Co Ltd
Original Assignee
Beijing Dajia Internet Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Dajia Internet Information Technology Co Ltd filed Critical Beijing Dajia Internet Information Technology Co Ltd
Priority to CN202110702137.1A priority Critical patent/CN113420531B/en
Publication of CN113420531A publication Critical patent/CN113420531A/en
Application granted granted Critical
Publication of CN113420531B publication Critical patent/CN113420531B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/10Text processing
    • G06F40/12Use of codes for handling textual entities
    • G06F40/151Transformation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/20Natural language analysis
    • G06F40/205Parsing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/20Natural language analysis
    • G06F40/253Grammatical analysis; Style critique

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Health & Medical Sciences (AREA)
  • Artificial Intelligence (AREA)
  • Audiology, Speech & Language Pathology (AREA)
  • Computational Linguistics (AREA)
  • General Health & Medical Sciences (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
  • Document Processing Apparatus (AREA)

Abstract

The application discloses a method, a device and a storage medium for converting code text, which relate to the field of computers, and the method comprises the following steps: the electronic equipment analyzes the type script class file to obtain an abstract syntax tree of the type script class file, traverses the abstract syntax tree to obtain metadata of the type script class file, sets a predefined attribute conversion function in the class constructor after obtaining class attributes and class constructors recorded in the metadata, wherein the class attributes record initial data types, in the conversion process, the electronic equipment inserts the class attributes into the class constructors based on the initial data types to carry out assignment to obtain assigned target class attributes, and respectively converts the initial data types and assignment corresponding to the target class attributes based on the attribute conversion function and the preset target data types, so that a large number of redundant codes are reduced in generated conversion codes, and the maintenance cost of project codes is reduced.

Description

Code text conversion method, device and storage medium
Technical Field
The present disclosure relates to the field of computers, and in particular, to a method and apparatus for converting code text, and a storage medium.
Background
Modern front-end engineering projects increasingly use Typescript (type script) as a main development language, where Typescript is a static type language and is run by translating into JavaScript (an transliteration script language), but the translated JavaScript is a dynamic language, so that the type information defined by Typescript is lost. In real-world systems, data obtained from outside the engineering code may be inconsistent with the types defined in the code (pre-translation Typescript), and in the case that these types are lost in the running code (post-translation JavaScript), it is necessary to check or type-convert everywhere the type inconsistency may occur.
In the related art, the search parameters are de-serialized into corresponding data structures and converted where class attributes are used, but a large amount of redundant code is caused because conversion is performed every time class attributes are used.
Disclosure of Invention
The embodiment of the application provides a method, a device and a storage medium for converting code text, which are used for reducing redundant codes and lowering project code maintenance cost when converting type scripts.
According to a first aspect of an embodiment of the present application, there is provided a method for converting code text, including:
analyzing the type script class file to obtain an abstract syntax tree of the type script class file;
traversing the abstract syntax tree to obtain metadata of the type script class file;
obtaining class attributes and class constructors recorded in metadata, and setting a predefined attribute conversion function in the class constructors, wherein the class attributes are recorded with initial data types;
based on the initial data type, inserting the class attribute into a class constructor for assignment, and obtaining an assigned target class attribute;
and respectively converting the initial data type and the assignment corresponding to the target class attribute based on the attribute conversion function and the preset target data type.
In one possible implementation, the type script class file comprises a class file with a tag;
traversing the abstract syntax tree to obtain metadata of the type script class file, including:
traversing the abstract syntax tree to obtain metadata of the class file with the mark in the type script class file.
In one possible implementation, the storage path of the attribute transfer function is custom;
the method further comprises the steps of obtaining class attributes and class constructors recorded in the metadata, and before setting a predefined attribute conversion function in the class constructors:
the attribute transfer function is obtained from a custom storage path.
In one possible implementation manner, based on the initial data type, inserting the class attribute into the class constructor to perform assignment, and obtaining the assigned target class attribute includes:
determining an initial data type of the class attribute;
and inserting the class attribute into a class constructor for assignment, and combining the initial data type to obtain the assigned target class attribute.
In one possible implementation manner, based on the attribute conversion function and a preset target data type, converting an initial data type and an assignment corresponding to the target class attribute respectively includes:
determining an attribute conversion function corresponding to the target class attribute in the class constructor according to the corresponding relation between the target class attribute and the attribute conversion function;
assembling the initial data type and assignment corresponding to the target class attribute into a conversion statement according to the format of the attribute conversion function;
based on the target data type, the conversion statement is input into an attribute conversion function for conversion.
According to a second aspect of embodiments of the present application, there is provided a code text conversion device, including:
the analysis unit is used for analyzing the type script class file to obtain an abstract syntax tree of the type script class file;
the obtaining unit is used for traversing the abstract syntax tree and obtaining metadata of the type script class file;
a setting unit, configured to obtain a class attribute and a class constructor recorded in metadata, and set a predefined attribute conversion function in the class constructor, where an initial data type is recorded in the class attribute;
the assignment unit is used for inserting the class attribute into the class constructor for assignment based on the initial data type, and obtaining the assigned target class attribute;
and the conversion unit is used for respectively converting the initial data type and the assignment corresponding to the target class attribute based on the attribute conversion function and the preset target data type.
In one possible implementation, the type script class file comprises a class file with a tag;
and the acquisition unit is used for traversing the abstract syntax tree and acquiring metadata of the class file with the mark in the type script class file.
In one possible implementation, the storage path of the transfer function is custom; the apparatus further comprises:
and the pre-acquisition unit is used for acquiring the attribute conversion function from the self-defined storage path.
In a possible implementation, the assigning unit is configured to:
determining an initial data type of the class attribute;
and inserting the class attribute into a class constructor for assignment, and combining the initial data type to obtain the assigned target class attribute.
In a possible implementation, the conversion unit is configured to:
determining an attribute conversion function corresponding to the target class attribute in the class constructor according to the corresponding relation between the target class attribute and the attribute conversion function;
assembling the initial data type and assignment corresponding to the target class attribute into a conversion statement according to the format of the attribute conversion function;
based on the target data type, the conversion statement is input into an attribute conversion function for conversion.
According to a third aspect of embodiments of the present application, there is provided an electronic device, including:
a processor;
a memory for storing the processor-executable instructions;
wherein the processor is configured to execute the instructions to implement a method of converting code text;
according to a fourth aspect of embodiments of the present application, there is provided a computer readable storage medium, which when executed by a processor, causes the processor to perform the method of any one of the first aspects above;
according to a fifth aspect of embodiments of the present application, there is provided a computer program product comprising executable instructions which, when executed by a processor, enable the method of any one of the above-mentioned first aspects.
In summary, in the embodiment of the present disclosure, the electronic device parses the type script class file to obtain an abstract syntax tree of the type script class file, and traverses the abstract syntax tree to obtain metadata of the type script class file, after obtaining a class attribute and a class constructor recorded in the metadata, the electronic device sets a predefined attribute conversion function in the class constructor, where an initial data type is recorded in the class attribute, in a conversion process of the code text, the electronic device inserts the class attribute into the class constructor based on the initial data type to perform assignment, to obtain an assigned target class attribute, and converts the initial data type and assignment corresponding to the target class attribute based on the attribute conversion function and a preset target data type, respectively, so that the metadata is converted by using the predefined attribute conversion function to obtain conversion data, and the type and assignment of the class attribute after conversion can be obtained in an automatic batch, thereby reducing a large amount of redundant codes in the generated conversion code, and reducing maintenance cost of the project code.
Additional features and advantages of the application will be set forth in the description which follows, and in part will be obvious from the description, or may be learned by practice of the application. The objectives and other advantages of the application will be realized and attained by the structure particularly pointed out in the written description and claims thereof as well as the appended drawings.
Drawings
The accompanying drawings, which are included to provide a further understanding of the application and are incorporated in and constitute a part of this application, illustrate embodiments of the application and together with the description serve to explain the application and do not constitute an undue limitation to the application. In the drawings:
fig. 1 is a flow chart of a method for converting code text according to an embodiment of the present application;
fig. 2 is a schematic flow chart of converting a code text based on an attribute conversion function and a preset target data type in the embodiment of the present application;
FIG. 3 is a logic diagram of a method for converting code text according to an embodiment of the present application;
fig. 4 is a schematic structural diagram of a code text conversion device in an embodiment of the present application;
FIG. 5 is a schematic structural diagram of another code text conversion device according to an embodiment of the present application;
fig. 6 is a schematic structural diagram of an electronic device in an embodiment of the present application.
Detailed Description
In order to reduce redundant codes and reduce project code maintenance cost during type script conversion, the embodiment of the application provides a code text conversion method, a code text conversion device and a storage medium. In order to better understand the technical solution provided in the embodiments of the present application, the basic principle of the solution is briefly described here:
it should be noted that the terms "first," "second," and the like in the description and claims of the present application and the above figures are used for distinguishing between similar objects and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used may be interchanged where appropriate such that embodiments of the present application described herein may be implemented in sequences other than those illustrated or otherwise described herein. The implementations described in the following exemplary examples are not representative of all implementations consistent with the present application. Rather, they are merely examples of apparatus and methods consistent with some aspects of the present application as detailed in the accompanying claims.
The following describes the technical scheme provided by the embodiment of the application with reference to the accompanying drawings.
Typescript is used as a main development language in modern front-end engineering projects, and is a static type language and is run by translating into JavaScript, but the translated JavaScript is a dynamic language, so that the type information defined by the Typescript is lost. In real-world systems, data obtained from outside the engineering code may be inconsistent with the types defined in the code (pre-translation Typescript), and in the case that these types are lost in the running code (post-translation JavaScript), it is necessary to check or type-convert everywhere the type inconsistency may occur.
For example: obtaining retrieval parameters from url:
http://www.kuaishou.comgroupNum=1&tag=tag1&subquery%5Bcount%5D=11&subquery%5Bname%5D=name1;
the groupName, name, age, count is parsed into the character string type, because the url specification has lost the basic type information of the original fields, and the parameters need to be manually type-converted, so that the code for type conversion and assignment can be automatically complemented according to the types defined by the fields by using the scheme.
In the related art, the search parameters are deserialized into a simple internet-generic data structure, and the conversion is performed where the class attribute is used, but since the class conversion is performed every time the attribute is used, a large amount of redundant codes are caused.
In order to solve the above problems, the present application discloses a method, an apparatus and a storage medium for converting code text, and hereinafter, preferred embodiments of the present application are described in conjunction with the accompanying drawings, it should be understood that the preferred embodiments described herein are merely for illustrating and explaining the present application, are not intended to limit the present application, and embodiments of the present application and features of the embodiments may be combined with each other without conflict.
The method for converting the code text provided by the embodiment of the application is further explained below. Referring to fig. 1, the method comprises the following steps.
Step 101: and the electronic equipment analyzes the type script class file to obtain an abstract syntax tree of the type script class file.
The following type script files, namely Typescript files, are introduced first, the code text in the application refers to Typescript files, namely, class files formed by adding static type definitions on the basis of JavaScript, and metadata of different structure types are included in the class files.
In order to accurately determine the class file to be converted, the type script class file includes a class file with a tag, and in an implementation process, an electronic device (e.g., a computer) can quickly acquire the class file to be converted according to the tag. It should be noted that, the marks may be flexibly set according to the actual application scenario.
In the implementation process, the electronic device analyzes the type script class file, for example, the electronic device can analyze the type script class file according to the mark of the class file, so as to obtain an abstract syntax tree of the type script class file.
Here, an abstract syntax tree is an abstract representation of the syntax structure of source code, which represents the syntax structure of a programming language in the form of a tree, each node on the tree representing a structure in the source code. I.e. obtaining multiple types of type script class files in batches through an abstract syntax tree.
For example, when the type of the conversion code includes an array and a structure type, the abstract syntax tree obtained by the electronic device includes at least metadata a of the type array and metadata B of the type of the structure, and it is assumed here that the same subscript in the metadata a and the metadata B is data for describing different aspects of the same object.
Step 102: the electronic equipment traverses the abstract syntax tree to obtain metadata of the type script class file.
In order to quickly acquire metadata, the electronic device traverses the abstract syntax tree, namely, screens the whole abstract syntax tree, and because a class constructor, a class attribute, a class method and the like are described in the metadata, the electronic device acquires the metadata of the class file with the mark in the class script class file, so that code text which needs to be converted and simultaneously comprises types and assignments can be quickly acquired.
Step 103: the electronic device obtains class attributes and class constructors recorded in the metadata, and sets a predefined attribute transfer function in the class constructors, wherein the class attributes have an initial data type recorded therein.
Metadata involved in front-end engineering projects is of the order of magnitude, and in existing processing modes, metadata needs to be manually converted into a target type each time conversion is needed so as to meet a use scene, and in the process, code writing is obviously needed for many times, so that a great deal of redundancy of codes is caused. For this purpose, in the embodiment of the present application, an attribute conversion function is predefined, and the function of the attribute conversion function may convert metadata into a corresponding type.
In the implementation process, the storage path of the attribute conversion function is self-defined. I.e. the location (i.e. the storage path) of the attribute transfer function can be customized in order to make a faster determination of the transfer function. Thus, after the storage path of the attribute conversion function is customized, the attribute conversion function can be obtained from the customized storage path.
After the attribute conversion function is acquired, the object specifically applying the attribute conversion function needs to be further acquired, and in the implementation process, the electronic device acquires the class attribute and the class constructor recorded in the metadata, wherein the class attribute is recorded with the initial data type, and the specific parameters of the metadata are inherited through the class constructor.
For example, the initial data types recorded in the class attribute are a floating point type examination score, a character type student name, and an integer type student age, the electronic device acquires the array member examination score A0 and examination score A1 of the metadata A of the above type array through the class constructor, and acquires the B0 student name, B0 student age, B1 student name, B1 student age of the metadata B of the above type structure through the class constructor.
Step 104: and the electronic equipment inserts the class attribute into the class constructor for assignment based on the initial data type, and obtains the assigned target class attribute.
In the implementation process, specific data is acquired through the class constructor in step 103, but the class attributes are all null, so that the electronic device needs to further assign a value to the class attributes. In the assignment process, the electronic device determines an initial data type of the class attribute, namely, carries out specific assignment according to the initial data type.
Further, the electronic device inserts the class attribute into the class constructor to perform assignment, and the above example is still described in combination with the initial data type, and when the class constructor is scattered with data of "B0 Zhang Sanzhang", "B1 Liqu", "B1 12", "B0 11", "A0 80.5", "A1 90.0", the electronic device performs assignment for the class attribute with the value being null according to the initial data type floating point type, character type and integer, so as to obtain assigned target class attributes of "Zhang Sanzhan", "11", "80.5", "Liqu, 12" and "90.0", respectively. Considering that the same subscript in the metadata a and the metadata B is the data for describing different aspects of the same object, the object class attributes may be continuously integrated to obtain the final object class attributes of "Zhang san, 11, 80.5" and "Lisi, 12, 90.0".
Step 105: the electronic equipment respectively converts the initial data type and the assignment corresponding to the target class attribute based on the attribute conversion function and the preset target data type.
It should be noted that, as shown in fig. 2, the step of converting the electronic device specifically includes:
step 1051: and the electronic equipment determines the attribute conversion function corresponding to the target class attribute in the class constructor according to the corresponding relation between the target class attribute and the attribute conversion function.
Because the number of parameters of different classes of attributes is large in variability, in order to be matched with the attribute conversion function, the electronic equipment determines the attribute conversion function corresponding to the target class attribute in the class constructor according to the corresponding relation between the target class attribute and the attribute conversion function, wherein the corresponding relation is pre-bound, and the attribute conversion function is pre-defined in the class constructor, and after the corresponding attribute conversion function is acquired, the target class attribute is further input into the corresponding attribute conversion function.
Step 1052: and the electronic equipment assembles the initial data type and the assignment corresponding to the target class attribute into a conversion statement according to the format of the attribute conversion function.
In the conversion process, the attribute conversion function comprises conversion of the type and the assignment of the target class attribute, so that before conversion, the electronic equipment needs to assemble the initial data type and the assignment corresponding to the target class attribute into a conversion statement according to the format of the attribute conversion function.
Still referring to the above example, considering the initial data type corresponding to the target class attribute, the target class attribute is assembled into a conversion statement in the format of an attribute conversion function, where the conversion statement is "(str) Zhang san, (int) 11, (float) 80.5" and "(str) Lifour, (int) 12, (float) 90.0".
Step 1053: the electronic device inputs the conversion statement into the attribute conversion function for conversion based on the target data type.
In the implementation process, the electronic device converts the initial data type into the target data type through the attribute conversion function, and correspondingly, the assignment is changed through the conversion of the attribute conversion function.
Still to explain the above example, assuming that the target data types are str, float, and int, respectively, the converted sentences "(str) Zhang San, (int) 11, (float) 80.5" and "(str) Liqu, (int) 12, (float) 90.0" are input into the attribute conversion function to be converted, and then the converted code sentences are "(str) Zhang San, (float) 11.0, (int) 80" and "(str) Liqu, (float) 12.0, (int) 90".
It should be noted that, the attribute conversion function in the above solution may be implemented in the form of a babel plugin, so that the plugin may be configured into a babel configuration file in an item.
The above embodiments are described in further detail below with reference to fig. 3, which illustrates a specific application scenario.
Application scenario 1:
the computer analyzes the type script class file A to obtain an abstract syntax tree B of the type script class file A, and the type script class file A comprises a plurality of code texts, so that the code texts needing to be converted can be marked in advance for effectively screening out, and the mark is C. In this way, in the process of traversing the abstract syntax tree B, the metadata C in the type script class file a with the tag can be directly obtained, i.e. the metadata marked as C', C-and the like can be filtered out.
After the metadata C is obtained, the computer continues to extract the class attribute D and the class constructor E recorded in the metadata, and supposing that the class attribute D is a weather state and the initial type of the weather state is a character type; meanwhile, assuming that the storage path of the attribute transfer function is a D disk, the computer reads from the D diskAcquiring attribute transfer functions
Because the class attribute D is directly inherited from the abstract syntax tree B, the class attribute D is assigned a null value, i.e., a "weather state". In order to obtain a specific assignment of the class attribute D, the computer inputs the class attribute D "weather status" of floating point type as null into the class constructor E, where it is assumed that when the time is between 6:00 and 12:00, the assigned target class attribute F is obtained as "weather status=sunny"; when the time is between 12:01 and 24:00, the assigned target class attribute F is 'weather state=negative'; when the time is between 00:01 and 05:59, the assigned target class attribute F is "weather state=rain".
Assuming that the preset target data type is integer, the computer respectively converts weather state=sunny, weather state=cloudy and weather state=rainy, specifically, according to the corresponding relation between the target class attribute and the attribute conversion function, determining the attribute conversion function corresponding to the target class attribute in the class constructor, namely, finding the attribute conversion functionThe computer assembles the initial data type and assignment corresponding to the target class attribute according to the format of the attribute conversion function to form a conversion statement, namely, the weather state=sunny, the weather state=cloudy and the weather state=rainy are assembled according to the format of f (x), so as to obtain the conversion statement ++>Based on the target data type integer, the conversion statement +.>To attribute transfer function->Is converted to obtain conversionAs a result->
Based on the same inventive concept, the application also provides a code text conversion device. Referring to fig. 4 and fig. 5, a code text conversion device provided in the present application includes:
the parsing unit 410 is configured to parse the type script class file to obtain an abstract syntax tree of the type script class file;
an obtaining unit 420, configured to traverse the abstract syntax tree and obtain metadata of the type script class file;
a setting unit 430 for obtaining a class attribute and a class constructor recorded in the metadata, and setting a predefined attribute conversion function in the class constructor, wherein an initial data type is recorded in the class attribute;
the assigning unit 440 is configured to insert the class attribute into the class constructor to perform assignment based on the initial data type, and obtain an assigned target class attribute;
and the conversion unit 450 is configured to convert the initial data type and the assignment corresponding to the target class attribute based on the attribute conversion function and the preset target data type, respectively.
In one possible implementation, the type script class file comprises a class file with a tag;
and an obtaining unit 420, configured to traverse the abstract syntax tree and obtain metadata of the class file with the tag in the type script class file.
In one possible implementation, the storage path of the transfer function is custom; the apparatus further comprises:
the pre-acquisition unit 400 is configured to acquire an attribute conversion function from a custom storage path.
In a possible implementation, the assignment unit 440 is configured to:
determining an initial data type of the class attribute;
and inserting the class attribute into a class constructor for assignment, and combining the initial data type to obtain the assigned target class attribute.
In one possible implementation, the conversion unit 450 is configured to:
determining an attribute conversion function corresponding to the target class attribute in the class constructor according to the corresponding relation between the target class attribute and the attribute conversion function;
assembling the initial data type and assignment corresponding to the target class attribute into a conversion statement according to the format of the attribute conversion function;
based on the target data type, the conversion statement is input into an attribute conversion function for conversion.
Based on the same inventive concept, referring to fig. 6, an embodiment of the present disclosure provides an electronic device 600, for example, the electronic device 600 may be a mobile phone, a computer, a digital broadcasting terminal, a messaging device, a game console, a tablet device, a medical device, an exercise device, a personal digital assistant, or the like.
The electronic device 600 may include one or more of the following components: a processing component 602, a memory 604, a power component 606, a multimedia component 608, an audio component 610, an input/output (I/O) interface 612, a sensor component 614, and a communication component 616.
The processing component 602 generally controls overall operation of the electronic device 600, such as operations associated with display, telephone calls, data communications, camera operations, and recording operations. The processing component 602 may include one or more processors 620 to execute instructions to perform all or part of the steps of the methods described above. Further, the processing component 602 can include one or more modules that facilitate interaction between the processing component 602 and other components. For example, the processing component 602 may include a multimedia module to facilitate interaction between the multimedia component 608 and the processing component 602.
The memory 604 is configured to store various types of data to support operations at the electronic device 600. Examples of such data include instructions for any application or method operating on the electronic device 600, contact data, phonebook data, messages, pictures, videos, and so forth. The memory 604 may be implemented by any type or combination of volatile or nonvolatile memory devices 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 or optical disk.
The power supply component 606 provides power to the various components of the electronic device 600. The power supply components 606 can include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power for the electronic device 600.
The multimedia component 608 includes a screen between the electronic device 600 and the user that provides an output interface. 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 a user. The touch panel includes one or more touch sensors to sense touches, swipes, and gestures on the touch panel. The touch sensor may sense not only the boundary of a touch or slide action, but also the duration and pressure associated with the touch or slide operation. In some embodiments, the multimedia component 608 includes a front camera and/or a rear camera. When the electronic device 600 is in an operational 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 focal length and optical zoom capabilities.
The audio component 610 is configured to output and/or input audio signals. For example, the audio component 610 includes a Microphone (MIC) configured to receive external audio signals when the electronic device 600 is in an operational mode, such as a call mode, a recording mode, and a voice recognition mode. The received audio signals may be further stored in the memory 604 or transmitted via the communication component 616. In some embodiments, audio component 610 further includes a speaker for outputting audio signals.
The I/O interface 612 provides an interface between the processing component 602 and peripheral interface modules, which may be a keyboard, click wheel, buttons, etc. These buttons may include, but are not limited to: homepage button, volume button, start button, and lock button.
The sensor assembly 614 includes one or more sensors for providing status assessment of various aspects of the electronic device 600. For example, the sensor assembly 614 may detect an on/off state of the electronic device 600, a relative positioning of the components, such as a display and keypad of the electronic device 600, the sensor assembly 614 may also detect a change in position of the electronic device 600 or a component of the electronic device 600, the presence or absence of a user's contact with the electronic device 600, an orientation or acceleration/deceleration of the electronic device 600, and a change in temperature of the electronic device 600. The sensor assembly 614 may include a proximity sensor configured to detect the presence of nearby objects in the absence of any physical contact. The sensor assembly 614 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 614 may also include an acceleration sensor, a gyroscopic sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.
The communication component 616 is configured to facilitate communication between the electronic device 600 and other devices, either wired or wireless. The electronic device 600 may access a wireless network based on a communication standard, such as WiFi, an operator network (e.g., 2G, 3G, 4G, or 5G), or a combination thereof. In one exemplary embodiment, the communication component 616 receives broadcast signals or broadcast-related information from an external broadcast management system via a broadcast channel. In one exemplary embodiment, the communication component 616 further includes a Near Field Communication (NFC) module to facilitate short range communications. For example, the NFC module may be implemented based on Radio Frequency Identification (RFID) technology, infrared data association (IrDA) technology, ultra Wideband (UWB) technology, bluetooth (BT) technology, and other technologies.
In an exemplary embodiment, the electronic device 600 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 elements for executing any one of the methods of the first aspect described above.
Based on the same inventive concept, embodiments of the present application provide a computer-readable storage medium, which when executed by a processor, causes the processor to perform the method of any one of the above-described first aspects.
Based on the same inventive concept, embodiments of the present application provide a computer program product comprising executable instructions that, when executed by a processor, are capable of implementing a method according to any of the above-mentioned first aspects.
In summary, in the embodiment of the present disclosure, the electronic device parses the type script class file to obtain an abstract syntax tree of the type script class file, and traverses the abstract syntax tree to obtain metadata of the type script class file, after obtaining a class attribute and a class constructor recorded in the metadata, the electronic device sets a predefined attribute conversion function in the class constructor, where an initial data type is recorded in the class attribute, in a conversion process of the code text, the electronic device inserts the class attribute into the class constructor based on the initial data type to perform assignment, to obtain an assigned target class attribute, and converts the initial data type and assignment corresponding to the target class attribute based on the attribute conversion function and a preset target data type, respectively, so that the metadata is converted by using the predefined attribute conversion function to obtain conversion data, and the type and assignment of the class attribute after conversion can be obtained in an automatic batch, thereby reducing a large amount of redundant codes in the generated conversion code, and reducing maintenance cost of the project code.
It will be appreciated by those skilled in the art that embodiments of the present application may be provided as a method, system, or computer program product system. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product system embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) having computer-usable program code embodied therein.
The present application is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems) and computer program product systems according to the application. It will be understood that each flow and/or block of the flowchart illustrations and/or block diagrams, and combinations of flows and/or blocks in the flowchart illustrations and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks. It will be apparent to those skilled in the art that various modifications and variations can be made in the present application without departing from the spirit or scope of the application. Thus, if such modifications and variations of the present application fall within the scope of the claims and the equivalents thereof, the present application is intended to cover such modifications and variations.

Claims (12)

1. A method for converting code text, the method comprising:
analyzing the type script class file to obtain an abstract syntax tree of the type script class file;
traversing the abstract syntax tree to obtain metadata of the type script class file;
obtaining class attributes and class constructors recorded in the metadata, and setting a predefined attribute conversion function in the class constructors, wherein the class attributes are recorded with initial data types;
inserting the class attribute into the class constructor for assignment based on the initial data type, and obtaining an assigned target class attribute;
and respectively converting the initial data type and the assignment corresponding to the target class attribute based on the attribute conversion function and the preset target data type.
2. The method of claim 1, wherein the type script class file comprises a class file having a tag;
the traversing the abstract syntax tree to obtain metadata of the type script class file comprises the following steps:
traversing the abstract syntax tree to obtain metadata of the class file with the mark in the type script class file.
3. The method of claim 1, wherein the storage path of the attribute transfer function is custom;
the method further includes, before obtaining the class attribute and the class constructor recorded in the metadata and setting a predefined attribute transfer function in the class constructor:
and acquiring the attribute conversion function from the customized storage path.
4. The method of claim 1, wherein inserting the class attribute into the class constructor for assignment based on the initial data type to obtain an assigned target class attribute comprises:
determining the initial data type of the class attribute;
and inserting the class attribute into the class constructor for assignment, and combining the initial data type to obtain the assigned target class attribute.
5. The method of claim 4, wherein the converting, based on the attribute conversion function and a preset target data type, the initial data type and the assignment corresponding to the target class attribute respectively includes:
determining the attribute conversion function corresponding to the target class attribute in the class constructor according to the corresponding relation between the target class attribute and the attribute conversion function;
assembling the initial data type and the assignment corresponding to the target class attribute into a conversion statement according to the format of the attribute conversion function;
and inputting the conversion statement into the attribute conversion function for conversion based on the target data type.
6. A code text conversion apparatus, the apparatus comprising:
the analyzing unit is used for analyzing the type script class file to obtain an abstract syntax tree of the type script class file;
the obtaining unit is used for traversing the abstract syntax tree and obtaining metadata of the script type file;
a setting unit, configured to obtain a class attribute and a class constructor recorded in the metadata, and set a predefined attribute conversion function in the class constructor, where an initial data type is recorded in the class attribute;
the assignment unit is used for inserting the class attribute into the class constructor for assignment based on the initial data type to obtain an assigned target class attribute;
and the conversion unit is used for respectively converting the initial data type and the assignment corresponding to the target class attribute based on the attribute conversion function and the preset target data type.
7. The apparatus of claim 6, wherein the type script class file comprises a class file having a tag;
the obtaining unit is used for traversing the abstract syntax tree and obtaining metadata of the class file with the mark in the type script class file.
8. The apparatus of claim 6, wherein the storage path of the transfer function is custom; the apparatus further comprises:
and the pre-acquisition unit is used for acquiring the attribute conversion function from the self-defined storage path.
9. The apparatus of claim 6, wherein the assignment unit is configured to:
determining the initial data type of the class attribute;
and inserting the class attribute into the class constructor for assignment, and combining the initial data type to obtain the assigned target class attribute.
10. The apparatus of claim 9, wherein the conversion unit is configured to:
determining the attribute conversion function corresponding to the target class attribute in the class constructor according to the corresponding relation between the target class attribute and the attribute conversion function;
assembling the initial data type and the assignment corresponding to the target class attribute into a conversion statement according to the format of the attribute conversion function;
and inputting the conversion statement into the attribute conversion function for conversion based on the target data type.
11. An electronic device, comprising:
a processor;
a memory for storing the processor-executable instructions;
wherein the processor is configured to execute the instructions to implement the method of converting code text according to any of claims 1-5.
12. A computer readable storage medium, wherein instructions in the storage medium, when executed by a processor, enable the processor to perform the method of any one of claims 1-5.
CN202110702137.1A 2021-06-24 2021-06-24 Code text conversion method, device and storage medium Active CN113420531B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110702137.1A CN113420531B (en) 2021-06-24 2021-06-24 Code text conversion method, device and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110702137.1A CN113420531B (en) 2021-06-24 2021-06-24 Code text conversion method, device and storage medium

Publications (2)

Publication Number Publication Date
CN113420531A CN113420531A (en) 2021-09-21
CN113420531B true CN113420531B (en) 2024-03-12

Family

ID=77717586

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110702137.1A Active CN113420531B (en) 2021-06-24 2021-06-24 Code text conversion method, device and storage medium

Country Status (1)

Country Link
CN (1) CN113420531B (en)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109783074A (en) * 2018-12-11 2019-05-21 平安科技(深圳)有限公司 The data type conversion method of programming, electronic equipment
CN112230934A (en) * 2020-10-27 2021-01-15 北京人大金仓信息技术股份有限公司 Method and device for converting code language
CN112287013A (en) * 2020-12-24 2021-01-29 深圳市蓝凌软件股份有限公司 Data conversion method and adapter
CN112445468A (en) * 2020-12-16 2021-03-05 深圳市房多多网络科技有限公司 Typescript type file generation method, device, equipment and computer readable storage medium

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7954059B2 (en) * 2006-07-24 2011-05-31 National Instruments Corporation Automatic conversion of text-based code having function overloading and dynamic types into a graphical program for compiled execution

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109783074A (en) * 2018-12-11 2019-05-21 平安科技(深圳)有限公司 The data type conversion method of programming, electronic equipment
CN112230934A (en) * 2020-10-27 2021-01-15 北京人大金仓信息技术股份有限公司 Method and device for converting code language
CN112445468A (en) * 2020-12-16 2021-03-05 深圳市房多多网络科技有限公司 Typescript type file generation method, device, equipment and computer readable storage medium
CN112287013A (en) * 2020-12-24 2021-01-29 深圳市蓝凌软件股份有限公司 Data conversion method and adapter

Also Published As

Publication number Publication date
CN113420531A (en) 2021-09-21

Similar Documents

Publication Publication Date Title
CN106569800B (en) Front-end interface generation method and device
CN107423106B (en) Method and apparatus for supporting multi-frame syntax
CN106339384B (en) Storage process conversion method and device
CN111857903A (en) Display page processing method, device, equipment and storage medium
CN111767058A (en) Program compiling method and device, electronic equipment and storage medium
CN109558553B (en) Method and device for determining style
CN111061452A (en) Voice control method and device of user interface
CN105468606B (en) Webpage saving method and device
CN111079421B (en) Text information word segmentation processing method, device, terminal and storage medium
CN111209195B (en) Method and device for generating test case
CN113435205A (en) Semantic parsing method and device
CN113010157A (en) Code generation method and device
CN111324214B (en) Statement error correction method and device
CN113420531B (en) Code text conversion method, device and storage medium
CN111552688A (en) Data export method and device and electronic equipment
CN115982204A (en) Query statement conversion method and device, electronic equipment and storage medium
CN114691104A (en) Language conversion method and device, electronic equipment and storage medium
CN111667827B (en) Voice control method and device for application program and storage medium
CN110837741B (en) Machine translation method, device and system
CN111104110B (en) Global style sharing method, global style sharing device and electronic device
CN111240927B (en) Method, device and storage medium for detecting time consumption of method in program
CN113536180A (en) Item processing method, item processing device, electronic equipment, storage medium and program product
CN110765111B (en) Storage and reading method and device, electronic equipment and storage medium
CN107526683B (en) Method and device for detecting functional redundancy of application program and storage medium
CN111273910B (en) Method, device and storage medium for acquiring resource number identifier

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant