CN113885938A - Code modification method and device, electronic equipment and storage medium - Google Patents

Code modification method and device, electronic equipment and storage medium Download PDF

Info

Publication number
CN113885938A
CN113885938A CN202110968845.XA CN202110968845A CN113885938A CN 113885938 A CN113885938 A CN 113885938A CN 202110968845 A CN202110968845 A CN 202110968845A CN 113885938 A CN113885938 A CN 113885938A
Authority
CN
China
Prior art keywords
source file
annotation
processed
control
code
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.)
Pending
Application number
CN202110968845.XA
Other languages
Chinese (zh)
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 CN202110968845.XA priority Critical patent/CN113885938A/en
Publication of CN113885938A publication Critical patent/CN113885938A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/72Code refactoring
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/60Software deployment
    • G06F8/65Updates
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/71Version control; Configuration management

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computer Security & Cryptography (AREA)
  • Stored Programmes (AREA)

Abstract

The disclosure relates to a code modification method, a code modification device, an electronic device and a storage medium. The method comprises the following steps: when the source file to be processed comprises the annotation aiming at the control, adding a source code equivalent to the annotation into the first control initialization method to obtain a second control initialization method, replacing the annotation of the source file to be processed by adopting the second control initialization method, automatically realizing the replacement of the annotation, avoiding the manual replacement of developers, and improving the efficiency; and the subsequent developer can completely initialize the corresponding control by directly calling the second control initialization method, so that the condition that the initialization of the control is incomplete due to omission of source codes equivalent to annotations is avoided.

Description

Code modification method and device, electronic equipment and storage medium
Technical Field
The present disclosure relates to the field of computer processing technologies, and in particular, to a code modification method and apparatus, an electronic device, and a storage medium.
Background
With the development of computer processing technology, code annotation technology has emerged; through the code annotation mode, developers can write a small amount of codes in the source file, the same operation as the operation of the original codes can be realized, and the development efficiency is improved. When a developer annotates code, a specified annotation library is typically used. However, if the annotation library is removed or replaced, the developer needs to manually replace the annotations belonging to the original annotation library in the source file with the corresponding source code, which results in low processing efficiency.
Disclosure of Invention
The present disclosure provides a code modification method, apparatus, electronic device, and storage medium, to at least solve the problem of low efficiency in replacing annotations of a source file in the related art. The technical scheme of the disclosure is as follows:
according to a first aspect of embodiments of the present disclosure, there is provided a code modification method, including:
obtaining a source file to be processed;
when the source file to be processed comprises an annotation aiming at a control, acquiring a first control initialization method;
adding a source code equivalent to the annotation into the first control initialization method to obtain a second control initialization method;
and replacing the annotation of the source file to be processed by adopting the second control initialization method.
In one embodiment, the obtaining a first control initialization method when the source file to be processed includes an annotation for a control includes:
when the source file to be processed comprises an annotation aiming at a control and a declared class in the source file to be processed inherits a parent class with a fixed life cycle, taking a method specified by an operating system for the parent class as a first control initialization method;
and when the source file to be processed comprises an annotation aiming at the control and the declared class in the source file to be processed inherits a parent class with a non-fixed life cycle, taking a user preset method as a first control initialization method.
In one embodiment, the initializing the method specified by the operating system for the parent class as the first control initialization method includes:
and when the source file to be processed does not comprise the method specified by the operating system for the parent class, creating the method specified by the operating system for the parent class, and taking the created method as a first control initialization method.
In one embodiment, the obtaining the source file to be processed includes:
acquiring a source file set;
traversing suffix name types of source files in the source file set;
and taking the source file of which the suffix name type corresponds to the language type supported by the annotation as the source file to be processed.
In one embodiment, after the obtaining the pending source file, the method further includes:
analyzing a code structure of the source file to be processed;
and determining that the source file to be processed comprises an annotation aiming at the control according to the result of the code structure analysis.
In one embodiment, after the replacing the annotation of the source file to be processed with the second control initialization method, the method further includes:
deleting a package reference code of an annotation library and an interface calling code of the annotation library; wherein the annotation repository is a repository to which the annotation belongs.
According to a second aspect of the embodiments of the present disclosure, there is provided a code modification apparatus including:
the source file acquisition module is configured to acquire a source file to be processed;
the first control initialization method acquisition module is configured to acquire a first control initialization method when the source file to be processed comprises an annotation aiming at a control;
the second control initialization method acquisition module is configured to add a source code equivalent to the annotation into the first control initialization method to obtain a second control initialization method;
and the annotation replacing module is configured to execute replacing the annotation of the source file to be processed by adopting the second control initializing method.
In one embodiment, the first control initialization method obtaining module is further configured to execute, when the source file to be processed includes an annotation for a control and a declared class in the source file to be processed inherits from a parent class with a fixed life cycle, taking a method specified by an operating system for the parent class as a first control initialization method; and when the source file to be processed comprises an annotation aiming at the control and the declared class in the source file to be processed inherits a parent class with a non-fixed life cycle, taking a user preset method as a first control initialization method.
In one embodiment, the first control initialization method obtaining module is further configured to, when the source file to be processed does not include a method specified by an operating system for the parent class, create the method specified by the operating system for the parent class, and use the created method as the first control initialization method.
In one embodiment, the source file fetching module is further configured to execute fetching a source file set; traversing suffix name types of source files in the source file set; and taking the source file of which the suffix name type corresponds to the language type supported by the annotation as the source file to be processed.
In one embodiment, the apparatus further includes a code structure parsing module configured to perform code structure parsing on the source file to be processed; and determining that the source file to be processed comprises an annotation aiming at the control according to the result of the code structure analysis.
In one embodiment, the apparatus further comprises a deletion module configured to perform deleting the package reference code of the annotation library and the interface call code of the annotation library; wherein the annotation repository is a repository to which the annotation belongs.
According to a third aspect of the embodiments of the present disclosure, there is provided an electronic device, including a memory and a processor, where the memory stores a computer program, and the processor implements the code modification method according to the first aspect or any one of the possible implementations of the first aspect when executing the computer program.
According to a fourth aspect of embodiments of the present disclosure, there is provided a storage medium having stored thereon a computer program which, when executed by a processor, implements a code modification method as described in the first aspect or any one of the possible implementations of the first aspect.
According to a fifth aspect of embodiments of the present disclosure, there is provided a computer program product comprising a computer program stored in a readable storage medium, from which at least one processor of a device reads and executes the computer program, causing the device to perform the code modification method described in any one of the embodiments of the first aspect.
The technical scheme provided by the embodiment of the disclosure at least brings the following beneficial effects: when the source file to be processed comprises the annotation aiming at the control, adding a source code equivalent to the annotation into the first control initialization method to obtain a second control initialization method, replacing the annotation of the source file to be processed by adopting the second control initialization method, automatically realizing the replacement of the annotation, avoiding the manual replacement of developers, and improving the efficiency; and moreover, the source code equivalent to the annotation is added into the control initialization method, and a subsequent developer can completely initialize the corresponding control by directly calling the control initialization method, so that the condition that the control is incompletely initialized due to omission of the source code equivalent to the annotation is avoided.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the disclosure.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the disclosure and are not to be construed as limiting the disclosure.
FIG. 1 is a diagram of an application environment illustrating a method of code modification in accordance with an exemplary embodiment.
FIG. 2 is a flow diagram illustrating a method of code modification in accordance with an exemplary embodiment.
FIG. 3 is a flow diagram illustrating a method of code modification in accordance with an exemplary embodiment.
FIG. 4 is a block diagram illustrating a code modification apparatus according to an example embodiment.
Fig. 5 is an internal block diagram of an electronic device shown in accordance with an example embodiment.
Detailed Description
In order to make the technical solutions of the present disclosure better understood by those of ordinary skill in the art, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below with reference to the accompanying drawings.
It should be noted that the terms "first," "second," and the like in the description and claims of the present disclosure and in the above-described drawings 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 disclosure described herein are capable of operation in sequences other than those illustrated or otherwise described herein. The implementations described in the exemplary embodiments below are not intended to represent all implementations consistent with the present disclosure.
The code modification method provided by the disclosure can be applied to electronic equipment, wherein the electronic equipment can be a personal computer, a notebook computer, a tablet computer and a server.
The code modification method provided by the present disclosure is described below with reference to fig. 1 and 2, and may include the following steps:
in step S201, the electronic device acquires a source file to be processed.
In step S202, when the source file to be processed includes an annotation for a control, the electronic device obtains a first control initialization method.
Some properties (such as color and id of the control) or methods (such as a listening event clicking the control) can be bound for the control by way of annotation. In the step, if the source file to be processed comprises an annotation aiming at the control, acquiring a control initialization method; the control initialization method is mainly used for initializing the controls on the user interface, such as onCreate, onViewCreated, initViews and other methods.
In step S203, a source code equivalent to the annotation is added to the first control initialization method to obtain a second control initialization method.
For example, if the annotation is: @ BindView (R.id.xx) TextView t, the source code equivalent to this annotation is t ═ findViewById (R.id.xx), and this equivalent source code is written in the first control initialization method. If the annotation is: @ OnClick (R.id.xx) void test () { }, the source code equivalent to this annotation is findViewById (R.id.xx). setOnClickListener (new android. view. View. OnClickListener () { test () }), and this equivalent source code is written in the first control initialization method.
As shown in fig. 1, if the source code of y equivalent to the annotation is x3, adding the source code x3 to the control initialization method results in: control initialization method { x3 }; then, after the method { x3} is initialized with the control, annotation y in the source file to be processed is replaced.
In step S204, the annotation of the source file to be processed is replaced by the second control initialization method.
In the method, when the source file to be processed comprises the annotation aiming at the control, the source code equivalent to the annotation is added into the first control initialization method to obtain the second control initialization method, the annotation of the source file to be processed is replaced by the second control initialization method, the annotation is automatically replaced, the manual replacement of a developer is not needed, and the efficiency is improved; and moreover, the source code equivalent to the annotation is added into the control initialization method, and a subsequent developer can completely initialize the corresponding control by directly calling the control initialization method, so that the condition that the control is incompletely initialized due to omission of the source code equivalent to the annotation is avoided.
In some embodiments, when the source file to be processed includes an annotation for a control, the obtaining of the first control initialization method may specifically include the following steps: when the source file to be processed comprises annotations aiming at the control and the declared class in the source file to be processed inherits from a parent class with a fixed life cycle, taking a method specified by an operating system for the parent class as a first control initialization method; and when the source file to be processed comprises the annotation aiming at the control and the declared class in the source file to be processed inherits the father class with the non-fixed life cycle, taking a user preset method as a first control initialization method.
The class with a fixed life cycle refers to that when an operating system processes the class, the executed method (method may also be referred to as a function) is fixed, for example, two classes, namely Activity and Fragment; these fixed methods performed by the operating system may be referred to as methods specified by the operating system for the class. The class with an unfixed life cycle means that when the operating system processes a process corresponding to the class, an executed method is not fixed, and the executed method can be set by a developer according to requirements.
If the declared class in the source file to be processed inherits from a parent class with fixed life cycle of Activity, an onCreate method specified by an operating system for the parent class can be used as a first control initialization method; if the declared class in the source file to be processed inherits from the parent class of Fragment, which has a fixed life cycle, the onViewcreated method specified by the operating system for the parent class can be used as the first control initialization method.
If the declared class in the source file to be processed is a parent class which inherits from a non-fixed life cycle, an initviews method preset by a developer can be used as a first control initialization method.
In the above manner, based on whether the life cycle of the parent class inherited by the declared class in the source file to be processed is fixed, the corresponding control initialization method is determined, and on the basis of meeting the execution logic of the operating system, the execution logic set by a developer according to actual requirements is also met.
Further, the method for specifying the operating system as the parent class as the first control initialization method may specifically include the following steps: and when the source file to be processed does not comprise the method specified by the operating system for the parent class, creating the method specified by the operating system for the parent class, and taking the created method as the first control initialization method.
Illustratively, if a declared class in the source file to be processed inherits Activity and an onCreate method specified by the operating system for the parent class is not included in the source file to be processed, the onCreate method may be created and used as the first control initialization method.
In the above manner, the corresponding method is created when the source file to be processed does not include the control initialization method specified by the operating system for the parent class, it is ensured that the source code equivalent to the annotation is added to the control initialization method, it is ensured that the annotation is replaced, and the source code of the source file is normally executed.
In some embodiments, the obtaining of the source file to be processed may specifically include: acquiring a source file set; traversing suffix name types of source files in a source file set; and taking the source file with the suffix name type corresponding to the language type supported by the annotation as the source file to be processed.
The suffix name type of the source file can be determined according to a programming language used by a developer when writing the source file, for example, the source file written by using Java, wherein the suffix name type of the source file is Java, and for example, the source file written by using kotlin, wherein the suffix name type of the source file is kt.
If an annotation can be used in a source file written in the Java or kotlin programming languages, it is understood that the annotation supports both Java and kotlin programming language types.
The source file set may include a plurality of source files, different kinds of source files being written in different programming languages; after the source file set is obtained, the suffix name type of each source file in the source file set can be traversed, and if the suffix name type is Java or kt and corresponds to the language type Java or kotlin supported by annotation, the source file can be used as a source file to be processed.
In the above manner, the suffix type of the source file is analyzed first, if the suffix type of the source file does not correspond to the language type supported by the annotation, the source file does not include the annotation, the source file is not used as the source file to be processed for annotation analysis, and if the suffix type of the source file corresponds to the language type supported by the annotation, the source file may include the annotation, and the source file is subjected to annotation analysis, so that the annotation replacement efficiency is improved.
In some embodiments, after obtaining the pending source file, the electronic device may further perform the following steps: analyzing a code structure of a source file to be processed; and determining that the source file to be processed comprises an annotation aiming at the control according to the result of the code structure analysis.
Because the source file is formed by a programming language, codes in the source file have a certain syntactic structure; in this embodiment, a PSI (Program Structure Interface) may be called to perform code Structure analysis on a source file, so as to obtain a code node tree, where the code node tree is used as a result of the code Structure analysis; in the code node tree, if the name of one node is an annotation node name, it can be determined that the source file to be processed includes an annotation for the control; for example, if the name of one of the nodes in the code node tree is psiannode, it may be determined that the source file to be processed includes an annotation for a control. The code node tree may further include other nodes, such as PsiClass (corresponding to the whole Java file), psiinportstatement (corresponding to the Java import statement), psimethodcallexpress (corresponding to the method call in ButterKnife), PsiField (corresponding to the Java member variable), and PsiMethod (corresponding to the Java method)
In the mode, the code structure of the source file is analyzed, whether the source file comprises the annotation is automatically determined based on the analysis result of the code structure, manual analysis and determination are not needed, and annotation replacement efficiency is improved.
In some embodiments, the electronic device may further perform the steps of: deleting a package reference code of the annotation library and an interface calling code of the annotation library; wherein the annotation library is a library to which the annotation belongs, such as a library of ButterKnife annotations.
In the above manner, when the source file to be processed has no annotation, the annotation library and the interface calling code may be removed, so as to reduce the volume of the application program installation package corresponding to the source file to be processed.
The present disclosure also provides an application example, in the application example, the source file is a view development source file of an Android system (Android), and the source file is written by a Java type (hereinafter, may be referred to as a Java file), and the annotations in the source file belong to a ButterKnife annotation library. The application example is described below with reference to fig. 3:
step S301, an Android Studio UI presentation layer (Android development view presentation layer): for Android project usage, if the ButterKnife annotation library is not maintained any more and is replaced by the Viewbinding annotation library, at this time, the ButterKnife annotation library needs to be removed. After a developer clicks a right mouse button in a blank of an Android Studio file, the electronic equipment can display a menu option for removing a ButterKnife annotation library; after the developer clicks and selects the menu option, the electronic equipment removes the ButterKnife annotation library.
Step S302, traversing a source file of the current view development project, namely the source file stored in a disk of a file being edited in an Android Studio status bar; since the ButterKnife annotation library is suitable for both Java and Kotlin language types, the electronic device can judge whether the suffix name type of the source file is Java or kt.
Step S303, if the suffix name type of the source file is java or kt, performing code structure analysis on the source file through a PSI interface provided by idea sdk (an application program) to obtain a code node tree, and if it is determined that the source file includes an annotation based on the code node tree, then step S304 is performed. Wherein, the nodes included in the code node tree may include: the butterknit is used to annotate the corresponding PsiClass (corresponding to the whole Java file), psiinportstatement (corresponding to the imported statement of Java), psimethodcallexpress (corresponding to the method call in butterknit), PsiAnnotation (corresponding to the annotation of Java), PsiField (corresponding to the member variable of Java), and PsiMethod (corresponding to the method of Java).
Step S304, according to the code node tree, determining the annotation used by the source file, generating a source code equivalent to the annotation, and adding the equivalent source code into the first control initialization method to obtain a second control initialization method.
For example, the source file includes a code statement "@ BindView (r.id.xx) TextView t" annotating variables, and corresponding r.id.xx and t are found according to PsiAnnotation (annotation node) and PsiField (variable node) in the code node tree, and the equivalent source code of the annotation is determined to be t ═ findViewById (r.id.xx).
For another example, the source file includes a code statement "@ oncolick (r.id.xx) void test () { } annotating a method, and the r.id.xx and the method are obtained according to psianontation and PsiMethod (method node), and the equivalent source code annotated as findViewById (r.id.xx) setoncolick Lister (new android. view. clicksener () { test () }) is determined.
Next, the electronic device may determine whether the class declared in the current source file inherits from the parent class according to PsiClass (class node). If the declared class in the current source file is inherited from the parent class and the parent class is Activity, judging whether the current source file has an onCreate method member or not, if not, creating the onCreate method member, and then adding the equivalent source code into the onCreate method member to obtain a second control initialization method; if the declared class in the current source file is inherited from the parent class and the parent class is Fragment, judging whether the current source file has an onViewcreated method member, if not, creating the onViewcreated method member, and then adding the equivalent source code into the onViewcreated method member to obtain a second control initialization method. And if the declared class in the current source file is inherited from the parent class and the parent class is other than Activity and Fragment, creating an initViews method member, and adding the equivalent source code into the initViews method member to obtain a second control initialization method.
Step S305, replacing the annotation by a second control initialization method, and deleting the package reference code of the annotation library of ButterKnife and the interface calling code of the annotation library of ButterKnife); and the electronic equipment saves the modified source file as a target source file.
In the application example, PSI is used for analyzing the code structure of a source file, whether the source file comprises an annotation is automatically determined based on a code node tree, a source code equivalent to the annotation is generated, the source code equivalent to the annotation is added into a corresponding control initialization method, the annotation is replaced, and the annotation removal of the source file is realized; different from the removal of the ButterKnife annotation in the class file, the ButterKnife annotation at the source code level is removed by the application example, and when the ButterKnife annotation does not exist in the view development project, the package reference code and the interface calling code of the ButterKnife annotation library can be removed, so that the compiling time is saved, the volume of an apk (Android application package) is reduced, and the time and the labor are saved.
It should be noted that, for the specific limitations of the above steps, reference may be made to the above specific limitations of a code modification method, which is not described herein again.
It should be understood that, although the steps in the flowcharts of fig. 1 to 3 are shown in sequence as indicated by the arrows, the steps are not necessarily performed in sequence as indicated by the arrows. The steps are not performed in the exact order shown and described, and may be performed in other orders, unless explicitly stated otherwise. Moreover, at least some of the steps in fig. 1 to 3 may include multiple steps or multiple stages, which are not necessarily performed at the same time, but may be performed at different times, and the order of performing the steps or stages is not necessarily sequential, but may be performed alternately or alternately with other steps or at least some of the other steps or stages.
FIG. 4 is a block diagram illustrating a code modification apparatus according to an example embodiment, the apparatus comprising:
a source file obtaining module 401 configured to perform obtaining a source file to be processed;
a first control initialization method obtaining module 402, configured to obtain a first control initialization method when the source file to be processed includes an annotation for a control;
a second control initialization method obtaining module 403, configured to add a source code equivalent to the annotation to the first control initialization method to obtain a second control initialization method;
an annotation replacing module 404 configured to perform replacing the annotation of the source file to be processed with the second control initialization method.
In an exemplary embodiment, the first control initialization method obtaining module 402 is further configured to execute, when the source file to be processed includes an annotation for a control and a declared class in the source file to be processed inherits from a parent class with a fixed life cycle, taking a method specified by an operating system for the parent class as a first control initialization method; and when the source file to be processed comprises an annotation aiming at the control and the declared class in the source file to be processed inherits a parent class with a non-fixed life cycle, taking a user preset method as a first control initialization method.
In an exemplary embodiment, the first control initialization method obtaining module 402 is further configured to, when the source file to be processed does not include a method specified by an operating system for the parent class, create the method specified by the operating system for the parent class, and use the created method as the first control initialization method.
In an exemplary embodiment, the source file fetching module 401 is further configured to execute fetching a source file set; traversing suffix name types of source files in the source file set; and taking the source file of which the suffix name type corresponds to the language type supported by the annotation as the source file to be processed.
In an exemplary embodiment, the apparatus further includes a code structure parsing module configured to perform code structure parsing on the source file to be processed; and determining that the source file to be processed comprises an annotation aiming at the control according to the result of the code structure analysis.
In an exemplary embodiment, the apparatus further comprises a deletion module configured to perform deleting a package reference code of an annotation library and an interface call code of the annotation library; wherein the annotation repository is a repository to which the annotation belongs.
With regard to the apparatus in the above-described embodiment, the specific manner in which each module performs the operation has been described in detail in the embodiment related to the method, and will not be elaborated here.
Fig. 5 is a block diagram illustrating an electronic device 500 for a code modification method according to an example embodiment. For example, the electronic device 500 may be a mobile phone, a computer, a digital broadcast terminal, a messaging device, a gaming console, a tablet device, a medical device, a fitness device, a personal digital assistant, and so forth.
Referring to fig. 5, electronic device 500 may include one or more of the following components: a processing component 502, a memory 504, a power component 506, a multimedia component 508, an audio component 510, an interface for input/output (I/O) 512, a sensor component 514, and a communication component 516.
The processing component 502 generally controls overall operation of the electronic device 500, such as operations associated with display, telephone calls, data communications, camera operations, and recording operations. The processing components 502 may include one or more processors 520 to execute instructions to perform all or a portion of the steps of the methods described above. Further, the processing component 502 can include one or more modules that facilitate interaction between the processing component 502 and other components. For example, the processing component 502 can include a multimedia module to facilitate interaction between the multimedia component 508 and the processing component 502.
The memory 504 is configured to store various types of data to support operations at the electronic device 500. Examples of such data include instructions for any application or method operating on the electronic device 500, contact data, phonebook data, messages, pictures, videos, and so forth. The memory 504 may be implemented by any type or combination of volatile or non-volatile storage 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.
The power supply component 506 provides power to the various components of the electronic device 500. The power components 506 may include a power management system, one or more power sources, and other components associated with generating, managing, and distributing power for the electronic device 500.
The multimedia component 508 includes a screen that provides an output interface between the electronic device 500 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 508 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 500 is in an operating 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 510 is configured to output and/or input audio signals. For example, the audio component 510 includes a Microphone (MIC) configured to receive external audio signals when the electronic device 500 is in an operational mode, such as a call mode, a recording mode, and a voice recognition mode. The received audio signals may further be stored in the memory 504 or transmitted via the communication component 516. In some embodiments, audio component 510 further includes a speaker for outputting audio signals.
The I/O interface 512 provides an interface between the processing component 502 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 assembly 514 includes one or more sensors for providing various aspects of status assessment for the electronic device 500. For example, the sensor assembly 514 may detect an open/closed state of the electronic device 500, the relative positioning of components, such as a display and keypad of the electronic device 500, the sensor assembly 514 may detect a change in the position of the electronic device 500 or a component of the electronic device 500, the presence or absence of user contact with the electronic device 500, orientation or acceleration/deceleration of the electronic device 500, and a change in the temperature of the electronic device 500. The sensor assembly 514 may include a proximity sensor configured to detect the presence of a nearby object without any physical contact. The sensor assembly 514 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 514 may also include an acceleration sensor, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.
The communication component 516 is configured to facilitate wired or wireless communication between the electronic device 500 and other devices. The electronic device 500 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 516 receives a broadcast signal or broadcast related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 516 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 500 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 the above-described methods.
In an exemplary embodiment, a computer-readable storage medium comprising instructions, such as the memory 504 comprising instructions, executable by the processor 520 of the electronic device 500 to perform the above-described method is also provided. Alternatively, the computer readable storage medium may be a ROM, a Random Access Memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, and the like.
In an exemplary embodiment, a computer program product is also provided, comprising a computer program stored in a computer readable storage medium, the computer program being executable by the processor 520 of the electronic device 500 to perform the above-mentioned method.
Other embodiments of the disclosure will be apparent to those skilled in the art from consideration of the specification and practice of the disclosure disclosed herein. This application is intended to cover any variations, uses, or adaptations of the disclosure following, in general, the principles of the disclosure and including such departures from the present disclosure as come within known or customary practice within the art to which the disclosure pertains. It is intended that the specification and examples be considered as exemplary only, with a true scope and spirit of the disclosure being indicated by the following claims.
It will be understood that the present disclosure is not limited to the precise arrangements described above and shown in the drawings and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.

Claims (10)

1. A method of code modification, the method comprising:
obtaining a source file to be processed;
when the source file to be processed comprises an annotation aiming at a control, acquiring a first control initialization method;
adding a source code equivalent to the annotation into the first control initialization method to obtain a second control initialization method;
and replacing the annotation of the source file to be processed by adopting the second control initialization method.
2. The code modification method according to claim 1, wherein when the source file to be processed includes an annotation for a control, acquiring a first control initialization method includes:
when the source file to be processed comprises an annotation aiming at a control and a declared class in the source file to be processed inherits a parent class with a fixed life cycle, taking a method specified by an operating system for the parent class as a first control initialization method;
and when the source file to be processed comprises an annotation aiming at the control and the declared class in the source file to be processed inherits a parent class with a non-fixed life cycle, taking a user preset method as a first control initialization method.
3. The code modification method according to claim 2, wherein the initializing a method specified by an operating system for the parent class as a first control initialization method comprises:
and when the source file to be processed does not comprise the method specified by the operating system for the parent class, creating the method specified by the operating system for the parent class, and taking the created method as a first control initialization method.
4. The code modification method according to claim 1, wherein the obtaining a source file to be processed comprises:
acquiring a source file set;
traversing suffix name types of source files in the source file set;
and taking the source file of which the suffix name type corresponds to the language type supported by the annotation as the source file to be processed.
5. A code modification method according to claim 1, wherein after said obtaining a pending source file, said method further comprises:
analyzing a code structure of the source file to be processed;
and determining that the source file to be processed comprises an annotation aiming at the control according to the result of the code structure analysis.
6. A code modification method according to claim 1, wherein after said replacing the annotation of the source file to be processed with the second control initialization method, the method further comprises:
deleting a package reference code of an annotation library and an interface calling code of the annotation library; wherein the annotation repository is a repository to which the annotation belongs.
7. A code modification apparatus, comprising:
the source file acquisition module is configured to acquire a source file to be processed;
the first control initialization method acquisition module is configured to acquire a first control initialization method when the source file to be processed comprises an annotation aiming at a control;
the second control initialization method acquisition module is configured to add a source code equivalent to the annotation into the first control initialization method to obtain a second control initialization method;
and the annotation replacing module is configured to execute replacing the annotation of the source file to be processed by adopting the second control initializing method.
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 code modification method of any one of claims 1 to 6.
9. A computer-readable storage medium, wherein instructions in the computer-readable storage medium, when executed by a processor of an electronic device, enable the electronic device to perform the code modification method of any of claims 1-6.
10. A computer program product comprising a computer program, characterized in that the computer program realizes the code modification method of any one of claims 1 to 6 when executed by a processor.
CN202110968845.XA 2021-08-23 2021-08-23 Code modification method and device, electronic equipment and storage medium Pending CN113885938A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110968845.XA CN113885938A (en) 2021-08-23 2021-08-23 Code modification method and device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110968845.XA CN113885938A (en) 2021-08-23 2021-08-23 Code modification method and device, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
CN113885938A true CN113885938A (en) 2022-01-04

Family

ID=79011219

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110968845.XA Pending CN113885938A (en) 2021-08-23 2021-08-23 Code modification method and device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN113885938A (en)

Similar Documents

Publication Publication Date Title
CN106406956B (en) Application program installation method and device
CN111736916A (en) Dynamic expansion method and device based on Java language, electronic equipment and storage medium
CN111538502A (en) Installation package processing method and device, electronic equipment and storage medium
CN111767058A (en) Program compiling method and device, electronic equipment and storage medium
CN116069612A (en) Abnormality positioning method and device and electronic equipment
CN113010157A (en) Code generation method and device
CN112114814A (en) Compiled file determining method and device and application program generating method and device
CN111580824B (en) Program optimization method, device and storage medium
CN111209195A (en) Method and device for generating test case
CN110851370A (en) Program testing method and device, and storage medium
CN113885938A (en) Code modification method and device, electronic equipment and storage medium
CN114691104A (en) Language conversion method and device, electronic equipment and storage medium
CN108427568B (en) User interface updating method and device
CN113590091A (en) Data processing method and device, electronic equipment and storage medium
CN108549570B (en) User interface updating method and device
CN109933357B (en) Application program upgrading method and device
CN112631695A (en) Data verification method and device, electronic equipment and storage medium
CN111597106A (en) Point burying management method and device
CN111596949B (en) Method and device for developing application program
CN113535183B (en) Code processing method, device, electronic equipment and storage medium
CN113934452B (en) Data processing method and device, electronic equipment and storage medium
CN113342355B (en) Code compiling method and device, electronic equipment and storage medium
CN110311968B (en) Method and device for loading file in streaming mode and intelligent equipment
CN114020694B (en) Header file address acquisition method and device, electronic equipment and storage medium
CN109726118B (en) Application program development method and device, electronic equipment and storage medium

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