CN113420531A - Code text conversion method and device and storage medium - Google Patents

Code text conversion method and device and storage medium Download PDF

Info

Publication number
CN113420531A
CN113420531A CN202110702137.1A CN202110702137A CN113420531A CN 113420531 A CN113420531 A CN 113420531A CN 202110702137 A CN202110702137 A CN 202110702137A CN 113420531 A CN113420531 A CN 113420531A
Authority
CN
China
Prior art keywords
class
attribute
type
data type
conversion function
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.)
Granted
Application number
CN202110702137.1A
Other languages
Chinese (zh)
Other versions
CN113420531B (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

Images

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)
  • Document Processing Apparatus (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

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

Description

Code text conversion method and device and storage medium
Technical Field
The present application relates to the field of computers, and in particular, to a method and an apparatus for converting code text, and a storage medium.
Background
Modern front-end engineering projects increasingly use Typescript as a main development language, Typescript is a static type language and runs by translating into JavaScript (an transliterated scripting language), but the translated JavaScript is a dynamic language, and the type information defined by Typescript is lost. In a real-world system, data acquired through the outside of the engineering code may not be consistent with types defined in the code (pre-translation type), and in the case that the types are lost in the running code (post-translation JavaScript), verification or type conversion needs to be performed on every place where the type inconsistency may occur.
In the related art, the search parameters are deserialized into corresponding data structures and converted where class attributes are used, but since conversion is performed each time a class attribute is used, a large amount of redundant code is created.
Disclosure of Invention
The embodiment of the application provides a code text conversion method, a code text conversion device and a storage medium, so that redundant codes are reduced and the maintenance cost of project codes is reduced when a type script is converted.
According to a first aspect of embodiments of the present application, there is provided a method for converting a code text, including:
analyzing the type script file to obtain an abstract syntax tree of the type script file;
traversing the abstract syntax tree to obtain the metadata of the type script file;
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;
based on the initial data type, inserting the class attribute into a class constructor for assignment to obtain an assigned target class attribute;
and respectively converting the initial data type and 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 the metadata of the type script class file, wherein the metadata comprises the following steps:
and traversing the abstract syntax tree to obtain the metadata of the class file with the mark in the type script class file.
In one possible implementation, the storage path of the attribute conversion function is self-defined;
before obtaining the class attribute and the class constructor recorded in the metadata and setting the predefined attribute conversion function in the class constructor, the method further comprises:
and acquiring the attribute conversion function from the self-defined storage path.
In a possible implementation manner, based on an initial data type, inserting a class attribute into a class constructor for assignment, and obtaining an assigned target class attribute, the method includes:
determining an 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.
In a possible implementation manner, based on the attribute conversion function and a preset target data type, respectively converting an initial data type and an assignment corresponding to a target class attribute, including:
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;
splicing the initial data type and assignment corresponding to the target class attribute into a conversion statement according to the format of an attribute conversion function;
and inputting the conversion statement into the attribute conversion function for conversion based on the target data type.
According to a second aspect of embodiments of the present application, there is provided a code text conversion apparatus, including:
the parsing unit is used for parsing the type script file to obtain an abstract syntax tree of the type script file;
the obtaining unit is used for traversing the abstract syntax tree and obtaining the metadata of the type script file;
the setting unit is used for obtaining the class attribute and the class constructor recorded in the metadata and setting a predefined attribute conversion function in the class constructor, wherein the class attribute records an initial data type;
the assignment unit is used for inserting the class attributes into the class constructor for assignment based on the initial data type to obtain assigned target class attributes;
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 the metadata of the class file with the mark in the type script class file.
In one possible implementation, the storage path of the conversion function is self-defined; the device still includes:
and the pre-acquisition unit is used for acquiring the attribute conversion function from the self-defined storage path.
In one possible implementation, the assignment unit is configured to:
determining an 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.
In one 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;
splicing the initial data type and assignment corresponding to the target class attribute into a conversion statement according to the format of an attribute conversion function;
and inputting the conversion statement into the attribute conversion function for conversion based on the target data type.
According to a third aspect of embodiments of the present application, there is provided an electronic apparatus, 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 transcoding text;
according to a fourth aspect of embodiments herein, there is provided a computer-readable storage medium, wherein instructions, when executed by a processor, enable the processor to perform the method of any of the first aspect above;
according to a fifth aspect of embodiments of the present application, there is provided a computer program product comprising executable instructions capable of implementing the method of any one of the first aspect when executed by a processor.
To sum up, 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, 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 transformation function in the class constructor, where an initial data type is recorded in the class attribute, in a transformation process of a code text, the electronic device inserts the class attribute into the class constructor for assignment based on the initial data type to obtain an assigned target class attribute, and transforms the initial data type and the assignment corresponding to the target class attribute based on the attribute transformation function and a preset target data type, so as to transform the metadata by using the predefined attribute transformation function to obtain transformed data, the method and the device can automatically acquire the converted type and assignment of the class attribute in batch, thereby reducing a large amount of redundant codes in the generated conversion codes and reducing the maintenance cost of the project codes.
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 the practice of the application. The objectives and other advantages of the application may be realized and attained by the structure particularly pointed out in the written description and claims hereof 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 embodiment(s) of the application and together with the description serve to explain the application and not to limit the application. In the drawings:
fig. 1 is a schematic flowchart of a method for converting code text in an embodiment of the present application;
fig. 2 is a schematic flowchart illustrating a process of converting a code text based on an attribute conversion function and a preset target data type in an embodiment of the present application;
FIG. 3 is a logic diagram of a code text conversion method in an embodiment of the present application;
FIG. 4 is a schematic structural diagram of a device for converting code text in an embodiment of the present application;
FIG. 5 is a schematic structural diagram of another code text conversion apparatus 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 maintenance cost of project codes when converting type scripts, embodiments of the present application provide a method, an apparatus, and a storage medium for converting code texts. In order to better understand the technical solution provided by the embodiments of the present application, the following brief description is made on the basic principle of the solution:
it should be noted that the terms "first," "second," and the like in the description and claims of this application and in the drawings described above are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used is interchangeable under appropriate circumstances such that the embodiments of the application described herein are capable of operation in sequences other than those illustrated or described herein. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present application. Rather, they are merely examples of apparatus and methods consistent with certain aspects of the present application, as detailed in the appended claims.
The technical scheme provided by the embodiment of the application is described below with reference to the accompanying drawings.
In modern front-end engineering projects, Typescript is increasingly used as a main development language, the Typescript is a static type language and runs by translating into JavaScript, but the JavaScript after translation is a dynamic language, and the type information defined by the Typescript is lost. In a real-world system, data acquired through the outside of the engineering code may not be consistent with types defined in the code (pre-translation type), and in the case that the types are lost in the running code (post-translation JavaScript), verification or type conversion needs to be performed on every place where the type inconsistency may occur.
For example: retrieve parameters from url:
http://www.kuaishou.comgroupNum=1&tag=tag1&subquery%5Bcount%5D=11&subquery%5Bname%5D=name1;
the groupName, the name, the age and the count are all analyzed into character string types, and because the url specification loses the basic type information of the original field, the parameters need to be manually subjected to type conversion, and at the moment, the scheme can be used for automatically completing the codes of type conversion and assignment according to the types defined by the fields.
In the related art, the retrieval parameters are deserialized into a simple data structure common to the internet, and conversion is performed where the class attribute is used, but since type conversion is performed every time the attribute is used, a large amount of redundant code is caused.
In order to solve the above problems, the present application discloses a code text conversion method, device and storage medium, and the following describes preferred embodiments of the present application with reference to the drawings of the specification, it should be understood that the preferred embodiments described herein are only used for explaining and explaining the present application, and are not used for limiting the present application, and the embodiments and features of the embodiments in the present application can be combined with each other without conflict.
The following further explains the method for converting code text provided in the embodiments of the present application. Referring to fig. 1, the following steps are included.
Step 101: and the electronic equipment analyzes the type script file to obtain an abstract syntax tree of the type script file.
The code text in the application refers to the Typescript class file, that is, the class file formed by adding static type definitions on the basis of JavaScript, and the class file comprises metadata of different structural types.
In order to accurately determine the class file to be converted, the type script class file includes a class file with a mark, and in the implementation process, the electronic device (for example, a computer) can quickly acquire the class file to be converted according to the mark. Note that the flag here can be flexibly set according to the actual operation scenario.
In an implementation process, the electronic device parses the type script class file, for example, the type script class file may be parsed according to a tag of the class file, so as to obtain an abstract syntax tree of the type script class file.
Here, the abstract syntax tree is an abstract representation of the syntax structure of the source code, which represents the syntax structure of the programming language in the form of a tree, and each node on the tree represents a structure in the source code. Namely, the multiple types of the type script class files are obtained in batches through the abstract syntax tree.
For example, when the type of the transcoding includes an array and a structure type, the abstract syntax tree obtained by the electronic device at least includes metadata a with the type of the array and metadata B with the type of the structure, and it is assumed that the parts of the metadata a and the metadata B with the same subscript are data describing different aspects of the same object.
Step 102: and traversing the abstract syntax tree by the electronic equipment to acquire the metadata of the type script file.
In order to quickly acquire the metadata, the electronic device traverses the abstract syntax tree, namely, a complete abstract syntax tree is screened, and because a class constructor, class attributes, a class method and the like are described in the metadata, the electronic device acquires the metadata of the class file with the marks in the type script class file, so that the code text which needs to be converted and simultaneously comprises the type and the assignment can be quickly acquired.
Step 103: the electronic equipment obtains the class attribute and the class constructor recorded in the metadata, and sets a predefined attribute conversion function in the class constructor, wherein the initial data type is recorded in the class attribute.
Metadata related in a front-end engineering project is of an order of magnitude, and in the existing processing mode, when conversion is needed each time, the metadata needs to be manually converted into a target type so as to meet a use scene. For this purpose, in the embodiment of the present application, an attribute conversion function is predefined, and a function of the attribute conversion function may convert the metadata into a corresponding type.
In the implementation process, the storage path of the attribute conversion function is self-defined. That is, in order to determine the conversion function more quickly, the location (i.e., storage path) of the attribute conversion function may be customized. Therefore, after the storage path of the attribute conversion function is customized, the attribute conversion function can be acquired from the customized storage path.
After the attribute conversion function is obtained, an object specifically applying the attribute conversion function needs to be further obtained, and in the implementation process, the electronic device obtains a class attribute and a class constructor recorded in the metadata, wherein the class attribute records an initial data type and inherits specific parameters of the metadata through the class constructor.
For example, the initial data types recorded in the class attribute are examination score of floating point type, student name of character type and student age of integer type, the electronic device acquires examination score A0 and examination score A1 of the array member of metadata A whose type is array by the class constructor, and acquires student name B0, student age B0, student name B1 and student age B1 of metadata B whose type is structure by 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 to obtain 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, and therefore, the electronic device needs to further assign values to the class constructor. In the assignment process, the electronic device determines an initial data type of the class attribute, namely, performs specific assignment according to the initial data type.
Furthermore, the electronic device inserts the class attribute into the class constructor for assignment, and combines the initial data type, still the above example explains, when the data "B0 zhangsan", "B1 lie si", "B1 12", "B0 11", "a 0 80.5" and "a 1 90.0" are dispersed in the class constructor, the electronic device assigns the class attribute whose assignment is empty according to the initial data type, floating point type, character type and integer type, and obtains the assigned target class attributes of zhangsan, 11 "," 80.5 "," lie si, 12 "and" 90.0 ", respectively. Considering that the parts with the same subscript in the metadata a and the metadata B are assumed to be data for describing different aspects of the same object, the target class attributes may be continued to be integrated to obtain final target class attributes of "zhang san, 11, 80.5" and "lie si, 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, referring to fig. 2, the step of converting by 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 the parameters of different attributes has large difference, in order to match with the attribute conversion function, the electronic device determines the attribute conversion function corresponding to the target attribute in the class constructor according to the corresponding relationship between the target attribute and the attribute conversion function, wherein the corresponding relationship is bound in advance.
Step 1052: and the electronic equipment assembles 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.
In the conversion process, the attribute conversion function includes conversion of the type and assignment of the target class attribute, so that before conversion, the electronic device needs to assemble 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.
Still in the above example, considering the initial data type corresponding to the target class attribute, the target class attribute is assembled into the conversion statements of "(str) zhangsan, (int)11, (float) 80.5" and "(str) liqu, (int)12, (float) 90.0" according to the format of the attribute conversion function.
Step 1053: and the electronic equipment 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 accordingly, the assignment value is changed through the conversion of the attribute conversion function.
Still in the above example, assuming that the target data types are str, float and int, respectively, the conversion statements "(str) three, (int)11, (float) 80.5" and "(str) lie four, (int)12, (float) 90.0" are input into the attribute conversion function to be converted, and then the converted code statements are "(str) three, (float)11.0, (int) 80" and "(str) lie four, (float)12.0, (int) 90" are obtained.
It should be added that, the attribute conversion function in the above scheme may be implemented in the form of a babel plug-in, so that the plug-in can be configured into a babel configuration file in a project and used.
Referring to fig. 3, a specific application scenario is described below to further detail the above embodiment.
Application scenario 1:
the computer analyzes the type script file A to obtain an abstract syntax tree B of the type script file A, and because the type script file A comprises a plurality of code texts, the code texts which need to be converted can be marked in advance in order to effectively screen out the code texts, and the code texts are supposed to be marked as 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 marks can be directly obtained, i.e. the metadata marked as C', C-, etc. are filtered out.
After the metadata C is obtained, the computer continuously extracts 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 conversion function is a D disk, the computer acquires the attribute conversion function from the D disk
Figure BDA0003130528390000101
Since the class attribute D is directly carried over from the abstract syntax tree B, the assignment of the class attribute D is null, i.e., the "weather state". In order to obtain a specific assignment of the class attribute D, the computer inputs the floating-point type class attribute D with a weather state of null into the class constructor E, wherein it is assumed that when the time is between 6:00 and 12:00, the assigned target class attribute F is a weather state of fine; when the time is between 12:01 and 24:00, the assigned target class attribute F is obtained as 'weather state is negative'; when the time is between 00:01 and 05:59, the assigned target class attribute F is obtained as "weather state ═ rain".
Assuming that the preset target data type is integer, the computer converts "weather state is clear", "weather state is negative", and "weather state is rain", specifically, according to the corresponding relationship between the target class attribute and the attribute conversion function, the attribute conversion function corresponding to the target class attribute in the class constructor is determined, that is, the attribute conversion function is found outNumber of
Figure BDA0003130528390000102
The computer assembles 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, namely, the weather state is clear, the weather state is yin and the weather state is rain according to the format of f (x), so as to obtain the conversion statement
Figure BDA0003130528390000103
Converting the statement based on the target data type integer
Figure BDA0003130528390000104
To attribute conversion function
Figure BDA0003130528390000111
The conversion result is obtained as
Figure BDA0003130528390000112
Based on the same inventive concept, the application also provides a device for converting the code text. Referring to fig. 4 and 5, a device for converting code text provided by the present application includes:
the parsing unit 410 is configured to parse the type script file to obtain an abstract syntax tree of the type script file;
an obtaining unit 420, configured to traverse the abstract syntax tree and obtain metadata of the type script file;
a setting unit 430, configured to obtain a class attribute and a class constructor recorded in the metadata, and set a predefined attribute transformation function in the class constructor, where 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 for assigning based on the initial data type, and obtain an assigned target class attribute;
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.
In one possible implementation, the type script class file comprises a class file with a tag;
the obtaining unit 420 is configured to traverse the abstract syntax tree and obtain metadata of a class file with a tag in the type script class file.
In one possible implementation, the storage path of the conversion function is self-defined; the device still includes:
a pre-obtaining unit 400, configured to obtain the attribute conversion function from the customized storage path.
In one possible implementation, the assigning unit 440 is configured to:
determining an 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.
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;
splicing the initial data type and assignment corresponding to the target class attribute into a conversion statement according to the format of an attribute conversion function;
and inputting the conversion statement into the attribute conversion function for conversion based on the target data type.
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 broadcast terminal, a messaging device, a game console, a tablet device, a medical device, an exercise device, a personal digital assistant, and the like.
The electronic device 600 may include one or more of the following components: processing component 602, memory 604, power component 606, multimedia component 608, audio component 610, input/output (I/O) interface 612, sensor component 614, and 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 a portion 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 can 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 non-volatile 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 disks.
Power supply component 606 provides power to the various components of electronic device 600. The power components 606 may 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 that provides an output interface between the electronic device 600 and a user. In some embodiments, the screen may include a Liquid Crystal Display (LCD) and a Touch Panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive an input signal from a user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundary of a touch or slide action, but also detect the duration and pressure associated with the touch or slide operation. In some embodiments, the multimedia component 608 includes a front facing camera and/or a rear facing camera. The front camera and/or the rear camera may receive external multimedia data when the electronic device 600 is in an operation mode, such as a shooting mode or a video mode. Each front camera and rear camera may be a fixed optical lens system or have a focal length and optical zoom capability.
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 signal may further be 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 keyboards, click wheels, buttons, etc. These buttons may include, but are not limited to: a home button, a volume button, a start button, and a lock button.
The sensor component 614 includes one or more sensors for providing status assessment of various aspects of the electronic device 600. For example, the sensor component 614 may detect an open/closed state of the electronic device 600, the relative positioning of components, such as a display and keypad of the electronic device 600, the sensor component 614 may also detect a change in the position of the electronic device 600 or a component of the electronic device 600, the presence or absence of user contact with the electronic device 600, orientation or acceleration/deceleration of the electronic device 600, and a change in the temperature of the electronic device 600. The sensor assembly 614 may include a proximity sensor configured to detect the presence of a nearby object without 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 gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.
The communication component 616 is configured to facilitate communications between the electronic device 600 and other devices in a wired or wireless manner. The electronic device 600 may access a wireless network based on a communication standard, such as WiFi, a carrier network (such as 2G, 3G, 4G, or 5G), or a combination thereof. In an exemplary embodiment, the communication component 616 receives broadcast signals or broadcast related information from an external broadcast management system via a broadcast channel. In an 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, micro-controllers, microprocessors or other electronic components for performing any 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, wherein instructions of the storage medium, when executed by a processor, enable the processor to perform the method of any one of the first aspect.
Based on the same inventive concept, embodiments of the present application provide a computer program product comprising executable instructions, which when executed by a processor, enable the method according to any of the above first aspects to be implemented.
To sum up, 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, 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 transformation function in the class constructor, where an initial data type is recorded in the class attribute, in a transformation process of a code text, the electronic device inserts the class attribute into the class constructor for assignment based on the initial data type to obtain an assigned target class attribute, and transforms the initial data type and the assignment corresponding to the target class attribute based on the attribute transformation function and a preset target data type, so as to transform the metadata by using the predefined attribute transformation function to obtain transformed data, the method and the device can automatically acquire the converted type and assignment of the class attribute in batch, thereby reducing a large amount of redundant codes in the generated conversion codes and reducing the maintenance cost of the project codes.
As will be appreciated by one skilled in the art, 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 flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams 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 changes and modifications may be made in the present application without departing from the spirit and scope of the application. Thus, if such modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is intended to include such modifications and variations as well.

Claims (10)

1. A method for transcoding text, the method comprising:
analyzing the type script file to obtain an abstract syntax tree of the type script file;
traversing the abstract syntax tree to obtain the metadata of the type script file;
obtaining class attributes and a class constructor recorded in the metadata, and setting a predefined attribute conversion function in the class constructor, wherein the class attributes record initial data types;
based on the initial data type, inserting the class attribute into the class constructor for assignment to obtain an assigned target class attribute;
and respectively converting the initial data type and assignment corresponding to the target class attribute based on the attribute conversion function and a preset target data type.
2. The method of claim 1, wherein the type script class file comprises a class file having markup;
traversing the abstract syntax tree to obtain the metadata of the type script class file, wherein the metadata comprises:
and traversing the abstract syntax tree to obtain the 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 conversion function is custom;
before obtaining the class attribute and the class constructor recorded in the metadata and setting a predefined attribute conversion function in the class constructor, the method further includes:
and acquiring the attribute conversion function from the customized storage path.
4. The method according to claim 1, wherein the 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 obtaining the assigned target class attribute by combining the initial data type.
5. The method according to claim 4, wherein the converting the initial data type and the assignment corresponding to the target class attribute based on the attribute conversion function and a preset target data type respectively comprises:
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;
splicing the initial data type and the assignment corresponding to the target class attribute into the 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. An apparatus for converting a code text, the apparatus comprising:
the parsing unit is used for parsing the type script file to obtain an abstract syntax tree of the type script file;
the obtaining unit is used for traversing the abstract syntax tree and obtaining the metadata of the type script file;
the setting unit is used for obtaining the class attribute and the class constructor recorded in the metadata and setting a predefined attribute conversion function in the class constructor, wherein the class attribute records an initial data type;
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 markup;
and the obtaining unit is used for traversing the abstract syntax tree and obtaining the metadata of the class file with the mark in the type script class file.
8. 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 transcoding text of any of claims 1-5.
9. 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 of claims 1-5.
10. A computer program product comprising executable instructions capable, when executed by a processor, of performing the method of any one of claims 1 to 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 true CN113420531A (en) 2021-09-21
CN113420531B 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 (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20080022264A1 (en) * 2006-07-24 2008-01-24 Macklem Grant V Automatic Conversion of Text-Based Code Having Function Overloading and Dynamic Types into a Graphical Program for Compiled Execution
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

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20080022264A1 (en) * 2006-07-24 2008-01-24 Macklem Grant V Automatic Conversion of Text-Based Code Having Function Overloading and Dynamic Types into a Graphical Program for Compiled Execution
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
CN113420531B (en) 2024-03-12

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
CN108008955B (en) Method and device for displaying user-defined control information
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
CN113010157A (en) Code generation method and device
CN111079421B (en) Text information word segmentation processing method, device, terminal and storage medium
CN113157256A (en) Interface code generation method and device, electronic equipment, storage medium and product
CN113420531B (en) Code text conversion method, device and storage medium
CN111104110B (en) Global style sharing method, global style sharing device and electronic device
CN112860625A (en) Data acquisition method, data storage method, device, equipment and storage medium
CN113128181A (en) Information processing method and device
CN109670160B (en) Typesetting processing method and device for files
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
CN112711420B (en) Code conversion method and device
CN113778440B (en) Data processing method and device, electronic equipment and storage medium
CN110084065B (en) Data desensitization method and device
CN111596949B (en) Method and device for developing application program
CN114691104A (en) Language conversion method and device, electronic equipment and storage medium
CN117539887A (en) Database statement conversion method, device, equipment and storage medium
CN114416094A (en) Language information conversion method and device

Legal Events

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