CN111638907A - Method, device, terminal and storage medium for replacing third-party code segment - Google Patents

Method, device, terminal and storage medium for replacing third-party code segment Download PDF

Info

Publication number
CN111638907A
CN111638907A CN202010312452.9A CN202010312452A CN111638907A CN 111638907 A CN111638907 A CN 111638907A CN 202010312452 A CN202010312452 A CN 202010312452A CN 111638907 A CN111638907 A CN 111638907A
Authority
CN
China
Prior art keywords
code segment
party
code
native
segment
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
CN202010312452.9A
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 CN202010312452.9A priority Critical patent/CN111638907A/en
Publication of CN111638907A publication Critical patent/CN111638907A/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/73Program documentation

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Library & Information Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The application provides a method, a device, a terminal and a storage medium for replacing a third-party code segment, which comprise the following steps: determining the code segment with the preset third party identification tag in the class file as a third party code segment; determining a target native code segment corresponding to a third-party code segment according to a preset corresponding relation between the third-party code segment and the native code segment; and replacing the third-party code segment in the class file with the target native code segment. According to the method and the device, after the target native code segment which can realize the logic rule corresponding to the third-party code segment is determined, the third-party code segment is automatically replaced by the target native code segment, the process of replacing the third-party code segment in batch and automatically is realized while the package size and the package compiling speed of the third-party code segment are optimized through the native code segment, the time consumed in the replacement process is shortened, the error probability in the replacement process is reduced, and the efficiency of the process of replacing the third-party code segment is improved.

Description

Method, device, terminal and storage medium for replacing third-party code segment
Technical Field
The present application relates to the field of computer technologies, and in particular, to a method and an apparatus for replacing a third-party code segment, a terminal, and a storage medium.
Background
In the Android programming process, when a large number of layout or click events are written, more and more users can simplify codes by using corresponding annotations in a third-party library in a mode of a butter knife (butter knife) and the like, and development efficiency is improved.
Currently, a mode of a third party library such as button, etc. is adopted, the packet size of an Android code is increased, and the packaging and compiling speed of the Android main station code is slowed down, so that annotations of the third party library need to be replaced by native code logic.
However, in the current scheme, the process of replacing the third-party library code is performed manually, and meanwhile, the existence of a large amount of class files requires manual judgment on whether the content related to the annotation exists or not, and the annotation needs to be manually replaced by the native code logic capable of realizing the annotation logic function, so that the replacement process of the third-party library code is long in time consumption and is prone to errors.
Disclosure of Invention
In order to overcome the problems in the related art, the application provides a method, a device, a terminal and a storage medium for replacing a third-party code segment.
According to a first aspect of embodiments of the present application, there is provided a method for replacing a third-party code fragment, including:
selecting class files from all files included in the file directory;
determining a code segment with a preset third party identification tag in the class file as a third party code segment, wherein the third party code segment is used for calling a target file corresponding to the third party code segment from a third party library;
determining a target native code segment corresponding to a third-party code segment according to a preset corresponding relation between the third-party code segment and a native code segment, wherein at least a logic rule contained in the target file is defined in the target native code segment;
and replacing the third party code segment in the class file with the target native code segment.
In one possible embodiment, the third party code snippet includes: declaring a code segment and a method code segment, the target native code segment including a native method code segment;
the step of determining a target native code segment corresponding to a third-party code segment according to a preset corresponding relationship between the third-party code segment and a native code segment specifically includes:
determining a native method code segment corresponding to a declaration code segment and a method code segment according to a preset corresponding relationship between the declaration code segment and the method code segment;
packaging the native method code segments, and adding inheritance interfaces for the packaged native method code segments;
the step of replacing the third-party code segment in the class file with the target native code segment specifically includes:
deleting the declaration code segment and the method code segment, and adding the inheritance interface and the encapsulated native method code segment corresponding to the inheritance interface into the class file.
In one possible embodiment, the third party code snippet further includes: a third party bound piece of code, the target native piece of code further comprising: native binding code fragments;
the step of determining a target native code segment corresponding to a third-party code segment according to a preset corresponding relationship between the third-party code segment and a native code segment specifically includes:
determining the native binding code segment according to the encapsulated native method code segment;
the step of replacing the third-party code segment in the class file with the target native code segment specifically includes:
replacing the third party bound code snippet with the native bound code snippet.
In one possible embodiment, the third party code snippet further includes: a third party referencing a piece of code, the target native code piece further comprising: a native reference code fragment;
after the step of replacing the declarative code segments and method code segments with an inheritance interface containing the encapsulated native method code segments, the method further includes:
traversing the class file, determining a reference library related to codes in the class file, and generating the native reference code segment according to the reference library;
replacing the third party reference code segment with the native reference code segment.
In a possible embodiment, before the step of determining the code segment having the preset third party identification tag in the class file as a third party code segment, the method further includes:
detecting unconventional code segments in the codes of the class files according to a preset detection rule;
and correcting the unconventional code segment according to a preset correction rule to obtain a conventional code segment, and replacing the unconventional code segment with the conventional code segment.
In one possible embodiment, the third party code snippet includes: third party binding code fragments;
after the step of determining the code segment with the preset third party identification tag in the class file as a third party code segment, the method further includes:
detecting whether the third-party code segment is a code segment with an inheritance relationship or not, wherein the code segment with the inheritance relationship comprises a parent code segment and a child code segment;
determining a parent code segment and a child code segment in the third-party code segment when the code segment with the inheritance relationship exists in the third-party code segment;
replacing the child code segment with a target native code segment corresponding to the child code segment, and then replacing the parent code segment with a target native code segment corresponding to the parent code segment;
and generating an inheritance binding code segment according to the third-party binding code segment, and replacing the third-party binding code segment with the inheritance binding code segment.
According to a second aspect of the embodiments of the present application, there is provided an apparatus for replacing a third-party code segment, including:
the selecting module is used for selecting class files from all files included in the file directory;
the first determining module is used for determining a code segment with a preset third party identification tag in the class file as a third party code segment, and the third party code segment is used for calling a target file corresponding to the third party code segment from a third party library;
the second determining module is used for determining a target native code segment corresponding to a third-party code segment according to a preset corresponding relation between the third-party code segment and a native code segment, wherein at least logic rules contained in the target file are defined in the target native code segment;
a first replacement module, configured to replace the third-party code segment in the class file with the target native code segment.
In one possible embodiment, the third party code snippet includes: declaring a code segment and a method code segment, the target native code segment including a native method code segment;
the second determining module includes:
the first determining submodule is used for determining a native method code segment corresponding to the declaration code segment and the method code segment according to the corresponding relation among the preset declaration code segment, the method code segment and the native method code segment;
the encapsulation submodule is used for encapsulating the native method code segment and adding an inheritance interface for the encapsulated native method code segment;
the first replacement module comprising:
and the first replacement submodule is used for deleting the statement code segment and the method code segment and adding the inheritance interface and the encapsulated native method code segment corresponding to the inheritance interface into the class file.
In one possible embodiment, the third party code snippet further includes: a third party bound piece of code, the target native piece of code further comprising: native binding code fragments;
the second determining module includes:
the second determining submodule is used for determining the native binding code segment according to the encapsulated native method code segment;
the first replacement module comprising:
and the second replacement submodule is used for replacing the third-party binding code segment with the native binding code segment.
In one possible embodiment, the third party code snippet further includes: a third party referencing a piece of code, the target native code piece further comprising: a native reference code fragment;
the device further comprises:
the generation module is used for traversing the class file, determining a reference library related to codes in the class file and generating the native reference code segment according to the reference library;
a second replacement module to replace the third party reference code segment with the native reference code segment.
In one possible embodiment, the apparatus further comprises:
the first detection module is used for detecting unconventional code segments in the codes of the class files according to a preset detection rule;
and the correction module is used for correcting the unconventional code segment according to a preset correction rule to obtain a conventional code segment, and replacing the unconventional code segment with the conventional code segment.
In one possible embodiment, the third party code snippet includes: third party binding code fragments; the device further comprises:
the second detection module is used for detecting whether the third-party code segment is a code segment with inheritance relationship or not, wherein the code segment with inheritance relationship comprises a parent code segment and a child code segment;
a third determining module, configured to determine, when a code segment having the inheritance relationship exists in the third-party code segment, a parent code segment and a child code segment in the third-party code segment;
a third replacement module, configured to replace the child code segment with a target native code segment corresponding to the child code segment, and then replace the parent code segment with a target native code segment corresponding to the parent code segment;
and the fourth replacement module is used for generating an inheritance binding code segment according to the third-party binding code segment and replacing the third-party binding code segment with the inheritance binding code segment.
According to a third aspect of embodiments of the present application, there is provided a terminal, including:
a processor;
a memory for storing the processor-executable instructions;
wherein the processor is configured to perform operations performed to implement the alternative methods of third party code snippet as provided herein.
According to a fourth aspect of embodiments herein, there is provided a non-transitory computer-readable storage medium having instructions thereon, which, when executed by a processor of a terminal, enable the terminal to perform operations performed to implement an alternative method of third party code snippet as provided herein.
According to a fifth aspect of embodiments herein, there is provided an application comprising one or more instructions which, when executed by a processor of a terminal, enable the terminal to perform operations performed to implement an alternative method of third party code snippet as provided herein.
The technical scheme provided by the embodiment of the application at least has the following beneficial effects:
selecting class files from all files included in the file directory; determining a code segment with a preset third party identification tag in the class file as a third party code segment, wherein the third party code segment is used for calling a target file corresponding to the third party code segment from a third party library; determining a target native code segment corresponding to the third-party code segment according to a preset corresponding relation between the third-party code segment and the native code segment, wherein at least a logic rule contained in a target file is defined in the target native code segment; according to the method and the device, after the target native code segment which can realize the logic rule corresponding to the third-party code segment is determined according to the corresponding relation between the third-party code segment and the native code segment in the preset class file, the third-party code segment is automatically replaced by the target native code segment, the process of batch and automatic replacement of the third-party code segment is realized while the packet size and the packaging and compiling speed of the third-party code segment are optimized through the native code segment, and therefore the time consumption and the time duration of the replacement process are shortened, the error probability in the replacement process is reduced, and the efficiency of the process of replacing the third-party code segment is improved.
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 application.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the application and are not to be construed as limiting the application.
FIG. 1 is a flow diagram illustrating an alternative method for third party code snippets in accordance with an exemplary embodiment;
FIG. 2 is a schematic diagram illustrating a third party code in accordance with an illustrative embodiment;
FIG. 3 is a schematic diagram illustrating native code in accordance with an illustrative embodiment;
FIG. 4 is a flow diagram illustrating another alternative method for third party code snippets in accordance with one illustrative embodiment;
FIG. 5 is a diagram illustrating a create inheritance interface in accordance with an exemplary embodiment;
FIG. 6 is a flow diagram illustrating another alternative method for third party code snippets in accordance with one illustrative embodiment;
FIG. 7 is an illustration of a script directory, according to an exemplary embodiment;
FIG. 8 is an illustration of script run command code in accordance with an exemplary embodiment;
FIG. 9 is a block diagram illustrating an alternative apparatus for third party code snippet in accordance with an exemplary embodiment;
FIG. 10 is a block diagram illustrating a terminal in accordance with an exemplary embodiment;
fig. 11 is a block diagram illustrating another terminal according to an example embodiment.
Detailed Description
Reference will now be made in detail to the exemplary embodiments, examples of which are illustrated in the accompanying drawings. When the following description refers to the accompanying drawings, like numbers in different drawings represent the same or similar elements unless otherwise indicated. 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.
FIG. 1 is a flowchart illustrating an alternative method for third party code snippets, according to an example embodiment, as shown in FIG. 1, including the steps of:
step 101, selecting class files from all files included in the file directory.
In this step, the file directory may be processed by running the compiled script file, and the class (class) file may be selected from all files included in the file directory.
The class file is named as Java class file, so that a computer programming language (Java) is more suitable for a network mainly in the aspects of platform independence and network mobility, and the tasks of the class file in the aspect of platform independence are as follows: the method provides binary-form service independent of an underlying host platform for the Java program, the class file is not a local executable program, and when the Java program is run, a Java Virtual Machine (JVM) is run firstly, and then the class file is loaded into the JVM for running.
Specifically, the class file is a file with the filename suffix, so that the file with the filename suffix field java can be screened from a file directory in a regular matching mode and determined as a class file.
In the embodiment of the application, the perl language can be used for realizing the regular matching process, the perl language is flexible and portable, the regular matching can be added in each judgment condition, the perl is cross-cultural and can be easily transplanted to different platforms, and the most important characteristic is that the function of the regular expression is integrated in the perl language, so that the efficiency of the regular matching process can be improved by using the perl language. In addition, programming languages such as python, shell and the like can also be selected to realize the regular matching.
And 102, determining the code segment with the preset third party identification tag in the class file as a third party code segment, wherein the third party code segment is used for calling a target file corresponding to the third party code segment from a third party library.
In this step, the class file may be traversed first, a code segment having a preset third party identification tag in the class file is determined, and the code segment is determined as a third party code segment, where the third party code segment is used to invoke a target file corresponding to the third party code segment from a third party library.
It should be noted that although only the third-party code segment is recorded in the class file, in order to implement the logic rule corresponding to the third-party code segment, the target file corresponding to the third-party code segment needs to be called from the third-party library, and in the actual service implementation process, tens of thousands of third-party library files may be called, so that the process of implementing the logic rule corresponding to the third-party code segment is time-consuming and occupies a large space, the packet size of the Android code is increased, and the packaging and compiling speed of the Android master station code is slowed down.
In the embodiment of the application, the process of determining the code segments with the preset third party identification tags in the class file as the third party code segments can be realized in a regular matching mode, and when the third party library is button, the third party codes in the class file all have certain third party identification tags, so that when traversing the codes in the class file, if the third party identification tags are matched, the code segments containing the third party identification tags can be determined as the third party code segments.
For example, fig. 2 is a schematic diagram of a third-party code according to an exemplary embodiment, as shown in fig. 2, where code snippet a1 is a code snippet declaratively defined for an in-class injection named "Test" in a class file Test file, and a corresponding third-party identification label is "@ Bindview", that is, after a regular matching is performed to a field corresponding to the third-party identification label "@ Bindview" in the code in the class file, a row (15 rows) where the third-party identification label is located and a code snippet contained in a next row (16) may be determined as the third-party code snippet.
Wherein, the code segment A1 is:
@BindView(R2.id.test)
TextView mTestTextView;
for another example, as shown in fig. 2, the code segment B1 is a code segment defined by a method for annotating in a class named "Test" in a class file Test file, and the corresponding third party identification tag is "@ OnClick", that is, after a field corresponding to the third party identification tag "OnClick" is regularly matched in the code in the class file, the code segment included in the row (23 rows) where the third party identification tag is located may be determined as the third party code segment.
Wherein, the code segment B1 is:
@OnClick(R2.id.test)
further, as shown in fig. 2, the code segment C1 is a code segment that is specified to be bound and annotated in a class named "Test" in the class file Test file, and the corresponding third party identification tag is "button knefe.
Wherein, code segment C1 is:
ButterKnife.bind(this,view);
step 103, determining a target native code segment corresponding to a third party code segment according to a preset corresponding relationship between the third party code segment and a native code segment, wherein at least a logic rule contained in the target file is defined in the target native code segment.
In this step, a target native code segment corresponding to a third-party code segment may be determined according to a preset correspondence between the third-party code segment and a native code segment, where at least a logic rule included in the target file is defined in the target native code segment.
Specifically, the corresponding relationship between the third-party code segment and the native code segment may be determined in advance and stored in the script, and when the script is run to replace the third-party code segment, the third-party code segment may be automatically replaced with the native code segment.
In this embodiment of the present application, fig. 3 is a schematic diagram of a native code shown according to an exemplary embodiment, fig. 3 is a schematic diagram of a code after replacing a third-party code segment in fig. 2 with a target native code, and correspondingly, for third-party code segments a1 and B1, the corresponding replaced target native code segment is a2, for third-party code segment C1, the corresponding replaced target native code segment is C2, and for third-party code segment D1, the corresponding replaced target native code segment is D2.
Wherein, the code segment A2 is:
mTestTextView=(TextView)view.findViewById(R.id.test)
if(view.findViewById(R.id.test)!-null){
view.findViewById(R.id.test).setOnClickListener(v->{TestClick((View)v
);})
code fragment C2 is: doBindView (view);
code fragment D1 is: import com.yxcorp.gifshow.profile.r 2;
import android.widget.TestView;
import android.view.View;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.onClick;
code fragment D2 is: import com.yxcorp.gifshow.profile.r 2;
import com.yxcorp.gifshow.profile.R;
import com.smile.gifmaker.mvps.IviewBinder;
import android.view.View;
import android.widget.TestView;
import android.view.View;
taking the example that the third-party code segments a1 and B1 are replaced with the target native code segment a2, the logic rule implemented by the third-party code segment a1 defines an annotation named mTestTextView, the type of the annotation is TextView, the annotation needs to call a target file stored in a third-party library to implement a certain logic rule, the address of the target file stored in the third library is r2.id.test, the logic rule implemented by the third-party code segment B1 returns an interface response with a returned value type of void and a name of testClick after a click event is executed for the address of r2. id.test. To implement the same logic rules as those of a1 and B1, the native code fragment corresponding to the definition process of type TextView annotation, i.e. the third party code fragment, may be set in advance:
@ BindView (Address character)
TextView notes name character
And native code fragment:
comment name character (TextView) view
The corresponding relation between the two;
and presetting a native code segment corresponding to the click event with the return value type of void, namely a third-party code segment:
@ OnClick (Address character)
void click event name character (View v)
And native code fragment:
if (view. findViewById (Address character)!null) retaining pocket
View, findViewById (Address character), setOnClickListener (v- > { click event name character (View) v); });
and replacing the third-party code segment with the corresponding native code segment after the third-party code segment is detected in the code.
And 104, replacing the third party code segment in the class file with the target native code segment.
In this step, the third party code segment in the class file is replaced with the target native code segment.
It should be noted that, in the replacement process, attention needs to be paid to the insertion position of the target native code, for example, referring to fig. 2 and 3, if the third-party code fragment is C1, the target native code C2 may be directly inserted into the position where the third-party code fragment is C1, and the third-party code fragment C1 may be deleted.
However, if the third-party code fragment is a1, the target native code fragment mTestTextView is directly inserted into the declared code fragment of the "Test" class, i.e., the next line of the public class Test is inserted, and the third-party code fragment is deleted as the first line in a1, and the second line is retained.
In the embodiment of the application, the third-party code fragments in the class file are replaced in batches by the running script, and compared with the class file containing the third-party code fragments before replacement, the class file containing the target native code fragments after replacement optimizes the package size and the package compiling speed of the Android codes, in one implementation mode, the package size of the Android codes can be reduced by 560.84 kilobytes by replacing the third-party code fragments with the target native code fragments, and the package compiling speed can be improved by nearly 2 minutes.
To sum up, the method for replacing a third-party code fragment provided by the embodiment of the present application includes: selecting class files from all files included in the file directory; determining a code segment with a preset third party identification tag in the class file as a third party code segment, wherein the third party code segment is used for calling a target file corresponding to the third party code segment from a third party library; determining a target native code segment corresponding to the third-party code segment according to a preset corresponding relation between the third-party code segment and the native code segment, wherein at least a logic rule contained in a target file is defined in the target native code segment; the third-party code segments in the class files can be replaced by the target native code segments, in the embodiment of the application, after the target native code segments which can realize the logic rules corresponding to the third-party code segments are determined according to the corresponding relation between the preset third-party code segments and the native code segments, the third-party code segments can be automatically replaced by the target native code segments, the process of batch and automatic replacement of the third-party code segments is realized while the packet size and the packaging and compiling speed of the third-party code segments are optimized through the native code segments, the time-consuming duration of the replacement process is shortened, the error probability in the replacement process is reduced, and the efficiency of the process of replacing the third-party code segments is improved.
FIG. 4 is a flowchart illustrating another alternative method for third party code snippets, according to an example embodiment, as shown in FIG. 4, including the steps of:
step 201, selecting class files from all files included in the file directory.
This step can refer to step 101, and is not described herein.
Step 202, detecting an unconventional code segment in the code of the class file according to a preset detection rule.
In this step, a detection rule may be written in the script file in advance, so that in the process of replacing the third-party code segment in the class file by running the compiled script file, the code in the class file is first detected according to the preset detection rule, and an irregular code segment is detected in the code in the class file.
The detection rule may be an extra space existing in the code of the class file, or a spelling error of a regular code segment existing in the code of the class file.
And 203, correcting the unconventional code segment according to a preset correction rule to obtain a conventional code segment, and replacing the unconventional code segment with the conventional code segment.
In this step, a modification rule matching the detection rule may be written in the script file in advance, so that after an unconventional code segment is detected in the code of the class file by the detection rule, the unconventional code segment may be modified according to the preset modification rule to obtain a conventional code segment, and the unconventional code segment is replaced by the conventional code segment, thereby avoiding an influence on a replacement process of a third party code due to an error written in the code of the class file by a human factor.
When the detection rule is used for detecting redundant spaces in the codes of the class file, the corresponding correction rule is used for deleting the spaces, and when the detection rule is used for detecting spelling errors of conventional code segments in the codes of the class file, the corresponding correction rule is used for correcting the spelling errors according to the context code segments.
And 204, determining the code segment with the preset third party identification tag in the class file as a third party code segment, wherein the third party code segment is used for calling a target file corresponding to the third party code segment from a third party library.
This step can refer to step 103, and is not described herein.
Step 205, determining a native method code segment corresponding to the declaration code segment and the method code segment according to a preset corresponding relationship between the declaration code segment and the method code segment.
The third party code snippet includes: declaring a code segment and a method code segment, the target native code segment including a native method code segment.
In this step, a native method code segment corresponding to a declaration code segment and a method code segment may be determined according to a preset correspondence between the declaration code segment and the method code segment.
Specifically, referring to fig. 2 and fig. 3, the declaration code segment a1 is a code segment for performing declaration definition on an annotation, a specific logic rule of the declaration code segment a1 is to define an annotation named mTestTextView, the type of the annotation is TextView, the annotation needs to call a target file stored in a third-party library to implement a certain logic rule, the target file has an address of r2.id.test stored in the third library, the method code segment B1 is a code segment defined by a method corresponding to the annotation, and a specific logic rule of the method code segment B1 is to return an interface response with a return value type of void and a name of testClick after a click event is performed on the annotation with an address of r2. id.test.
According to the preset corresponding relationship among the declaration code segment, the method code segment and the native method code segment, the native method code segment corresponding to the declaration code segment and the method code segment, which can implement the same logic rules as those of A1 and B1, is determined to be A2.
Native method code fragment A2 may also implement defining an annotation named mTestTextView, the type of the annotation being TextView, the address of the annotation being R.id.test, and the click event of the annotation being an interface response with a return value type of void and a name of testClick.
Note that, in the above example, the addresses R2.id.test and r.id.test corresponding to the annotations are substantially the same address, and there is a difference between R2 and R only based on the writing rule of address characters in different environments.
And step 206, packaging the native method code segment, and adding an inheritance interface for the packaged native method code segment.
In this step, the native method code segment determined in the above step may be encapsulated, and an inheritance interface may be added to the encapsulated native method code segment.
In the embodiment of the application, in order to enable the native method code segment with the common logic rule to have the inheritance property, the native method code segment can be repeatedly executed, so that the native method code segment can be encapsulated to form a method description, and an inheritance interface is added to the method description.
Specifically, an inheritance interface IViewBinder can be defined in the base level library mvp library, and an open source tool (gradle) is automatically constructed by referring to the items of the base level library, the third party library or the official library, and the base level library mvp library containing the inheritance interface IViewBinder is referred, so that the inheritance interface IViewBinder can be directly used in the process of replacing third party code segments.
For example, referring to fig. 3, the native method code fragment a2 is encapsulated into a method description doBindView, which is then added to the inheritance interface IViewBinder.
FIG. 5 is a schematic diagram illustrating the creation of an inheritance interface according to an exemplary embodiment, where, as shown in FIG. 5, a library containing the inheritance interface IViewBinder is referenced in a gradle tool, and the code fragments defining the inheritance interface are:
Public interface IviewBinder{
Void doBindView(View rootView);
}
in the embodiment of the application, the mode of defining the inheritance interface in the bottom layer library can simplify the replacement code and improve the efficiency of the process of replacing the third-party code fragment.
Step 207, deleting the statement code segment and the method code segment, and adding the inheritance interface and the encapsulated native method code segment corresponding to the inheritance interface into the class file.
In this step, the declaration code section and the method code section are deleted, and the inheritance interface and the encapsulated native method code section corresponding to the inheritance interface are added to the corresponding position in the class file.
Specifically, referring to fig. 2 and 3, replacing declaration code segment a1 and method code segment B1 with inheritance interface B2 containing the encapsulated native method code segment, and inserting B2 into declared code segment public classttest of "Test" class in class file, we obtain:
Figure BDA0002458363340000151
Figure BDA0002458363340000161
and 208, determining the native binding code segment according to the encapsulated native method code segment.
The third party code snippet further comprising: a third party bound piece of code, the target native piece of code further comprising: and native binding code fragments.
In this step, the native binding code fragment may be determined from the encapsulated native method code fragment.
Referring to fig. 3, after encapsulating a native method code fragment into a method description doBindView, the native bound code fragment may be determined to be C2: doBindView (view).
Specifically, the function of the native binding code segment is to execute the logic rule contained in the encapsulated native method code segment corresponding to the native binding code segment after detecting the line of code.
And step 209, replacing the third party binding code segment with the native binding code segment.
In this step, the third party bound code segment is replaced with a native bound code segment, which, with reference to fig. 2 and 3, is to say that the third party bound code segment C2: doBindView (view) insert third party binding code fragment C1: bind (this, view) and delete the third party binding code fragment C1.
Step 210, traversing the class file, determining a reference library related to the code in the class file, and generating the native reference code segment according to the reference library.
The third party code snippet further comprising: a third party referencing a piece of code, the target native code piece further comprising: the code fragment is referenced natively.
In this step, after replacing declaration code segments and method code segments in the code with inheritance interfaces containing the encapsulated native method code segments and replacing third-party binding code segments with native binding code segments, the class file after replacement may be traversed, all reference libraries used in the class file are determined according to the specific contents in the class file, and the native reference code segments referencing the reference libraries are generated.
In the embodiment of the application, since the annotation for calling the third-party library is used in the class file before replacement, the reference code fragment thereof necessarily contains the third-party reference code fragment for referring to the third-party library. For example, referring to fig. 2, since the test. java class file references the third-party library button, the third-party reference code segment D1 includes a reference code segment that references the button and a reference code segment that references other base-layer libraries.
And by traversing the class file after replacement, the native reference code fragment D2 in the class file after replacement that references the reference library is determined.
And step 211, replacing the third party reference code segment with the native reference code segment.
In this step, the third-party reference code segment is replaced with the native reference code segment, that is, the native reference code segment D2 is inserted into the position of the third-party reference code segment D1, and the third-party reference code segment D1 is deleted with reference to fig. 2 and 3.
To sum up, another method for replacing a third-party code fragment provided in the embodiment of the present application includes: selecting class files from all files included in the file directory; determining a code segment with a preset third party identification tag in the class file as a third party code segment, wherein the third party code segment is used for calling a target file corresponding to the third party code segment from a third party library; determining a target native code segment corresponding to the third-party code segment according to a preset corresponding relation between the third-party code segment and the native code segment, wherein at least a logic rule contained in a target file is defined in the target native code segment; the third-party code segments in the class files can be replaced by the target native code segments, in the embodiment of the application, after the target native code segments which can realize the logic rules corresponding to the third-party code segments are determined according to the corresponding relation between the preset third-party code segments and the native code segments, the third-party code segments can be automatically replaced by the target native code segments, the process of batch and automatic replacement of the third-party code segments is realized while the packet size and the packaging and compiling speed of the third-party code segments are optimized through the native code segments, the time-consuming duration of the replacement process is shortened, the error probability in the replacement process is reduced, and the efficiency of the process of replacing the third-party code segments is improved.
In addition, the native method code segments can be packaged, and an inheritance interface is added to the packaged native method code segments, so that the native method code segments with the common logic rules have inheritance properties and can be repeatedly executed, and the efficiency of the process of replacing third-party code segments can be further improved.
Fig. 6 is a flowchart illustrating another third party code segment replacement method according to an exemplary embodiment, where as shown in fig. 6, the information reminding method is applied to a third party code segment replacement system, and includes the following steps:
step 301, selecting class files from all files included in the file directory.
This step can be referred to specifically as step 101.
It should be noted that, in the embodiment of the present application, all files may be copied to the local of the computer, and the replacement process of the third-party code segments in all class files is implemented in the computer by running multiple scripts, or replacement logics included in multiple scripts may be written in a unified script, and only one script needs to be run, so that the replacement process of the third-party code segments in all class files can be implemented.
FIG. 7 is a script directory, shown in FIG. 7, for completing the replacement process of the third-party code segment in the class file, according to an exemplary embodiment, where the script to be run includes: perl, and main, perl, wherein the script main is composed of a sub-script checkusebf.
Fig. 8 is a view illustrating a script execution command code according to an exemplary embodiment, and as shown in fig. 8, after the command code included in fig. 8 is input in a computer terminal, a replacement process of a third party code fragment in all class files may be automatically performed by executing a script removebt.
Step 302, detecting an unconventional code segment in the code of the class file according to a preset detection rule.
This step can be referred to specifically as step 202.
It should be noted that, in this embodiment of the present application, the step of detecting an irregular code segment in the code of the class file according to a preset detection rule may be implemented by running a script.
Step 303, according to a preset correction rule, correcting the irregular code segment to obtain a conventional code segment, and replacing the irregular code segment with the conventional code segment.
This step can be referred to specifically as step 203.
It should be noted that, in the embodiment of the present application, the step of modifying the irregular code segment according to a preset modification rule to obtain a conventional code segment and replacing the irregular code segment with the conventional code segment may be implemented by running a script prefix.
And 304, determining the code segment with the preset third party identification tag in the class file as a third party code segment, wherein the third party code segment is used for calling a target file corresponding to the third party code segment from a third party library.
This step can be referred to specifically as step 102.
It should be noted that, in the embodiment of the present application, the conventional code segment obtained after the detection and the correction may be compared with the preset third party identification tag, so as to determine the third party code segment from the conventional code segment.
And 305, detecting whether the third-party code segment is a code segment with an inheritance relationship, wherein the code segment with the inheritance relationship comprises a parent code segment and a child code segment.
In this step, a sub-script checkusebf. perl in a script main. perl may be run to detect whether the third-party code segment is a code segment having an inheritance relationship, and determine a parent code segment and a child code segment in the third-party code segment, where the code segment having an inheritance relationship includes the parent code segment and the child code segment.
Wherein, the inherited concepts in the inheritance relationship are: in the process of constructing the object-oriented object, the child class needs to be constructed first and then the parent class is constructed, so that the influence on the child class is avoided in the process of constructing the parent class first, and similarly, in the process of replacing the third-party code segment, whether the parent-class code segment and the child-class code segment with inheritance relationship exist in the class file needs to be determined first, if the parent-class code segment and the child-class code segment with inheritance relationship exist, the third-party code segment needs to be replaced first in order to avoid the influence on the child-class code segment in the process of replacing the parent-class code segment first, so that the third-party code segment needs to be replaced first in the step of replacing the child-class code segment, and then the third-party code segment is replaced in the step of replacing the parent-class code segment, i.e. the class file is replaced from the inside out by a third party code fragment.
Step 306, in the case that the third-party code segment has a code segment with the inheritance relationship, determining a parent code segment and a child code segment in the third-party code segment.
In this step, when it is determined that the third-party code segment has a code segment having the inheritance relationship, a parent code segment and a child code segment in the third-party code segment are determined, that is, the third-party code segment included in the parent class in the class file is determined as the parent code segment, and the third-party code segment included in the child class included in the parent class in the class file is determined as the child code segment.
Step 307, after replacing the subclass code segment with a target native code segment corresponding to the subclass code segment, replacing the parent code segment with a target native code segment corresponding to the parent code segment.
In this step, in order to avoid the influence on the subclass code segments in the process of replacing the parent code segments first, the subclass code segments are replaced by target native code segments corresponding to the subclass code segments first and then the parent code segments are replaced by target native code segments corresponding to the parent code segments by running a script singleremoveamplitude lines.
Specifically, the method can comprise the following steps:
sub-step 3071, replacing the sub-class code segment with a target native code segment corresponding to the sub-class code segment.
In this step, the process of replacing the subclass code segment with the target native code segment corresponding to the subclass code segment may specifically refer to the process of replacing the third party code segment in the class file with the target native code segment in the present application, which includes the following steps, and is not described in detail here.
(1) Determining a native method code segment corresponding to a declaration code segment and a method code segment according to a preset corresponding relationship between the declaration code segment and the method code segment;
(2) packaging the native method code segments, and adding inheritance interfaces for the packaged native method code segments;
(3) replacing the declaration code section and the method code section with an inheritance interface containing the encapsulated native method code section;
(4) determining the native binding code segment according to the encapsulated native method code segment;
(5) replacing the third party bound code snippet with the native bound code snippet;
substep 3072, replacing the parent code segment with a target native code segment corresponding to the parent code segment.
In this step, the process of replacing the parent code segment with the target native code segment corresponding to the parent code segment may specifically refer to the process of replacing the third party code segment in the class file with the target native code segment in the present application, which includes the following steps, and details are not described here.
(1) Determining a native method code segment corresponding to a declaration code segment and a method code segment according to a preset corresponding relationship between the declaration code segment and the method code segment;
(2) packaging the native method code segments, and adding inheritance interfaces for the packaged native method code segments;
(3) replacing the declaration code section and the method code section with an inheritance interface containing the encapsulated native method code section;
(4) determining the native binding code segment according to the encapsulated native method code segment;
(5) replacing the third party bound code snippet with the native bound code snippet.
And 308, generating an inheritance binding code segment according to the third-party binding code segment, and replacing the third-party binding code segment with the inheritance binding code segment.
In this step, after the subclass code segment and the parent code segment with the inheritance relationship are replaced by the corresponding target native code segments, because the inheritance relationship exists in the class file, the third-party binding code segment needs to be replaced by the inheritance binding code segment, and the inheritance binding code segment not only contains the logic rule corresponding to the third-party binding code segment after the line of code is detected, namely, the logic rule is executed, but also contains the inheritance logic rule, namely, the subclass can inherit some state and behavior of the parent class.
It should be noted that, in the class file having an inheritance relationship, before replacement, the third-party bound code segment only exists in the parent-class code segment, and the third-party bound code segment may not exist in the child-class code segment by default, and correspondingly, after replacement, the inheritance bound code segment also only exists in the parent-class code segment, and the child-class code segment does not exist in the inheritance bound code segment.
In the embodiment of the application, the third-party bound code segment can be replaced by the inherited bound code segment by running the script addsuper.
Specifically, referring to fig. 2 and 3, if the third party binding code segment is C1: bind (this, view), the corresponding determined native binding code fragment is C2: doBindView (view), further, adding a character super in front of the native bound code fragment to generate an inherited bound code fragment C3: super DoBindView (view).
Further, the third-party binding code segment is replaced by an inherited binding code segment, that is, the inherited binding code segment C3 is inserted into the position of the third-party binding code segment C1, and the third-party binding code segment C1 is deleted.
Optionally, if a special condition such as a script operation error occurs in the process of replacing the third-party code segment, and the replacement process is not completed, a note prompting the occurrence of the special condition, for example, "perlcheck" may be inserted into the class file, so that the computer can quickly locate the class file with the special condition, and prompt a technician to perform processing in time.
To sum up, the method for replacing a third-party code fragment provided by the embodiment of the present application includes: selecting class files from all files included in the file directory; determining a code segment with a preset third party identification tag in the class file as a third party code segment, wherein the third party code segment is used for calling a target file corresponding to the third party code segment from a third party library; determining a target native code segment corresponding to the third-party code segment according to a preset corresponding relation between the third-party code segment and the native code segment, wherein at least a logic rule contained in a target file is defined in the target native code segment; the third-party code segments in the class files can be replaced by the target native code segments, in the embodiment of the application, after the target native code segments which can realize the logic rules corresponding to the third-party code segments are determined according to the corresponding relation between the preset third-party code segments and the native code segments, the third-party code segments can be automatically replaced by the target native code segments, the process of batch and automatic replacement of the third-party code segments is realized while the packet size and the packaging and compiling speed of the third-party code segments are optimized through the native code segments, the time-consuming duration of the replacement process is shortened, the error probability in the replacement process is reduced, and the efficiency of the process of replacing the third-party code segments is improved.
In addition, before the third-party code segment is automatically replaced by the target native code segment, whether the third-party code segment is a code segment with an inheritance relationship is judged, so that the child code segment in the inheritance relationship can be replaced by the target native code segment corresponding to the child code segment, and then the parent code segment in the inheritance relationship is replaced by the target native code segment corresponding to the parent code segment, and the inside-outside replacement process is realized, so that the influence on the child code segment in the process of replacing the parent code segment in advance is avoided, and the accuracy of the third-party code segment replacement process is improved.
Fig. 9 is a block diagram illustrating an alternative apparatus for third party code snippets according to an example embodiment, and as shown in fig. 9, the apparatus 40 may include:
a selecting module 401, configured to select a class file from all files included in the file directory;
a first determining module 402, configured to determine a code segment having a preset third party identifier tag in the class file as a third party code segment, where the third party code segment is used to invoke a target file corresponding to the third party code segment from a third party library;
a second determining module 403, configured to determine, according to a preset correspondence between a third-party code segment and a native code segment, a target native code segment corresponding to the third-party code segment, where at least a logic rule included in the target file is defined in the target native code segment;
a first replacement module 404, configured to replace the third-party code segment in the class file with the target native code segment.
The first determining module 402 is connected to the selecting module 401, the second determining module 403 is connected to the first determining module 402, and the first replacing module 404 is connected to the second determining module 403.
The device provided by the embodiment of the application selects the class files from all the files contained in the file directory; determining a code segment with a preset third party identification tag in the class file as a third party code segment, wherein the third party code segment is used for calling a target file corresponding to the third party code segment from a third party library; determining a target native code segment corresponding to the third-party code segment according to a preset corresponding relation between the third-party code segment and the native code segment, wherein at least a logic rule contained in a target file is defined in the target native code segment; the third-party code segments in the class files can be replaced by the target native code segments, in the embodiment of the application, after the target native code segments which can realize the logic rules corresponding to the third-party code segments are determined according to the corresponding relation between the preset third-party code segments and the native code segments, the third-party code segments can be automatically replaced by the target native code segments, the process of batch and automatic replacement of the third-party code segments is realized while the packet size and the packaging and compiling speed of the third-party code segments are optimized through the native code segments, the time-consuming duration of the replacement process is shortened, the error probability in the replacement process is reduced, and the efficiency of the process of replacing the third-party code segments is improved.
In one possible embodiment, the third party code snippet includes: declaring a code segment and a method code segment, the target native code segment including a native method code segment;
the second determining module 403 includes:
the first determining submodule is used for determining a native method code segment corresponding to the declaration code segment and the method code segment according to the corresponding relation among the preset declaration code segment, the method code segment and the native method code segment;
the encapsulation submodule is used for encapsulating the native method code segment and adding an inheritance interface for the encapsulated native method code segment;
the first replacement module 404, comprising:
and the first replacement submodule is used for deleting the statement code segment and the method code segment and adding the inheritance interface and the encapsulated native method code segment corresponding to the inheritance interface into the class file.
In one possible embodiment, the third party code snippet further includes: a third party bound piece of code, the target native piece of code further comprising: native binding code fragments;
the second determining module 403 includes:
the second determining submodule is used for determining the native binding code segment according to the encapsulated native method code segment;
the first replacement module 404, comprising:
and the second replacement submodule is used for replacing the third-party binding code segment with the native binding code segment.
In one possible embodiment, the third party code snippet further includes: a third party referencing a piece of code, the target native code piece further comprising: a native reference code fragment;
the apparatus 40 further comprises:
the generation module is used for traversing the class file, determining a reference library related to codes in the class file and generating the native reference code segment according to the reference library;
a second replacement module to replace the third party reference code segment with the native reference code segment.
In a possible embodiment, the device 40 further comprises:
the first detection module is used for detecting unconventional code segments in the codes of the class files according to a preset detection rule;
and the correction module is used for correcting the unconventional code segment according to a preset correction rule to obtain a conventional code segment, and replacing the unconventional code segment with the conventional code segment.
In one possible embodiment, the third party code snippet includes: third party binding code fragments; the apparatus 40 further comprises:
the second detection module is used for detecting whether the third-party code segment is a code segment with inheritance relationship or not, wherein the code segment with inheritance relationship comprises a parent code segment and a child code segment;
a third determining module, configured to determine, when a code segment having the inheritance relationship exists in the third-party code segment, a parent code segment and a child code segment in the third-party code segment;
a third replacement module, configured to replace the child code segment with a target native code segment corresponding to the child code segment, and then replace the parent code segment with a target native code segment corresponding to the parent code segment;
and the fourth replacement module is used for generating an inheritance binding code segment according to the third-party binding code segment and replacing the third-party binding code segment with the inheritance binding code segment.
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. 10 is a block diagram illustrating a terminal according to an example embodiment. For example, the terminal 500 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.
Referring to fig. 10, terminal 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 input/output (I/O) interface 512, a sensor component 514, and a communication component 516.
The processing component 502 generally controls overall operation of the terminal 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 terminal 500. Examples of such data include instructions for any application or method operating on terminal 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 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.
The power components 506 provide power to the various components of the terminal 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 terminal 500.
The multimedia component 508 includes a screen providing an output interface between the terminal 500 and the user. In some embodiments, the screen may include a Liquid Crystal Display (LCD) and a Touch Panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive 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 terminal 500 is in an operation mode, such as a photographing 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 terminal 500 is in an operating 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 terminal 500. For example, sensor assembly 514 can detect an open/closed state of terminal 500, relative positioning of components, such as a display and keypad of terminal 500, position changes of terminal 500 or a component of terminal 500, presence or absence of user contact with terminal 500, orientation or acceleration/deceleration of terminal 500, and temperature changes of terminal 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 communications between the terminal 500 and other devices in a wired or wireless manner. The terminal 500 may access a wireless network based on a communication standard, such as WiFi, an operator 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 terminal 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 steps of the above-mentioned information alerting method when the terminal 500 is provided as the aforementioned first terminal.
In an exemplary embodiment, a non-transitory storage medium including instructions, such as the memory 504 including instructions, executable by the processor 520 of the terminal 500 to perform the above-described third party code segment replacement method is also provided. For example, the non-transitory 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, the present application further provides an application program, which includes one or more instructions that can be executed by a processor of a terminal, so that the terminal can execute an operation performed by the method for implementing the third-party code segment as provided in the present application.
Fig. 11 is a block diagram illustrating another terminal according to an example embodiment. Referring to fig. 11, terminal 600 includes a processing component 622 that further includes one or more processors and memory resources, represented by memory 632, for storing instructions, such as application programs, that are executable by the processing component 622. The application programs stored in memory 632 may include one or more modules that each correspond to a set of instructions. Further, the processing component 622 is configured to execute instructions to perform the steps in the above-described third party code snippet replacement method.
The terminal 600 may also include a power component 626 configured to perform power management for the terminal 600, a wired or wireless network interface 650 configured to connect the terminal 600 to a network, and an input/output (I/O) interface 658. The terminal 600 may operate based on an operating system stored in the memory 632, such as Windows Server, Mac OS XTM, UnixTM, LinuxTM, FreeBSDTM, or the like.
Other embodiments of the present application will be apparent to those skilled in the art from consideration of the specification and practice of the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of the invention following, in general, the principles of the application and including such departures from the present disclosure as come within known or customary practice within the art to which the invention pertains. It is intended that the specification and examples be considered as exemplary only, with a true scope and spirit of the application being indicated by the following claims.
It will be understood that the present application 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 application is limited only by the appended claims.

Claims (10)

1. A method for replacing third party code snippets, the method comprising:
selecting class files from all files included in the file directory;
determining a code segment with a preset third party identification tag in the class file as a third party code segment, wherein the third party code segment is used for calling a target file corresponding to the third party code segment from a third party library;
determining a target native code segment corresponding to a third-party code segment according to a preset corresponding relation between the third-party code segment and a native code segment, wherein at least a logic rule contained in the target file is defined in the target native code segment;
and replacing the third party code segment in the class file with the target native code segment.
2. The method of claim 1, wherein the third party code snippet comprises: declaring a code segment and a method code segment, the target native code segment including a native method code segment;
the step of determining a target native code segment corresponding to a third-party code segment according to a preset corresponding relationship between the third-party code segment and a native code segment specifically includes:
determining a native method code segment corresponding to a declaration code segment and a method code segment according to a preset corresponding relationship between the declaration code segment and the method code segment;
packaging the native method code segments, and adding inheritance interfaces for the packaged native method code segments;
the step of replacing the third-party code segment in the class file with the target native code segment specifically includes:
deleting the declaration code segment and the method code segment, and adding the inheritance interface and the encapsulated native method code segment corresponding to the inheritance interface into the class file.
3. The method of claim 2, wherein the third party code snippet further comprises: a third party bound piece of code, the target native piece of code further comprising: native binding code fragments;
the step of determining a target native code segment corresponding to a third-party code segment according to a preset corresponding relationship between the third-party code segment and a native code segment specifically includes:
determining the native binding code segment according to the encapsulated native method code segment;
the step of replacing the third-party code segment in the class file with the target native code segment specifically includes:
replacing the third party bound code snippet with the native bound code snippet.
4. The method of claim 2, wherein the third party code snippet further comprises: a third party referencing a piece of code, the target native code piece further comprising: a native reference code fragment;
after the step of replacing the declarative code segments and method code segments with an inheritance interface containing the encapsulated native method code segments, the method further includes:
traversing the class file, determining a reference library related to codes in the class file, and generating the native reference code segment according to the reference library;
replacing the third party reference code segment with the native reference code segment.
5. The method of claim 1, wherein before the step of determining the code segment having the preset third party identification tag in the class file as a third party code segment, the method further comprises:
detecting unconventional code segments in the codes of the class files according to a preset detection rule;
and correcting the unconventional code segment according to a preset correction rule to obtain a conventional code segment, and replacing the unconventional code segment with the conventional code segment.
6. The method of claim 1, wherein the third party code snippet comprises: third party binding code fragments;
after the step of determining the code segment with the preset third party identification tag in the class file as a third party code segment, the method further includes:
detecting whether the third-party code segment is a code segment with an inheritance relationship or not, wherein the code segment with the inheritance relationship comprises a parent code segment and a child code segment;
determining a parent code segment and a child code segment in the third-party code segment when the code segment with the inheritance relationship exists in the third-party code segment;
replacing the child code segment with a target native code segment corresponding to the child code segment, and then replacing the parent code segment with a target native code segment corresponding to the parent code segment;
and generating an inheritance binding code segment according to the third-party binding code segment, and replacing the third-party binding code segment with the inheritance binding code segment.
7. An apparatus for replacing third party code snippets, the apparatus comprising:
the selecting module is used for selecting class files from all files included in the file directory;
the first determining module is used for determining a code segment with a preset third party identification tag in the class file as a third party code segment, and the third party code segment is used for calling a target file corresponding to the third party code segment from a third party library;
the second determining module is used for determining a target native code segment corresponding to a third-party code segment according to a preset corresponding relation between the third-party code segment and a native code segment, wherein at least logic rules contained in the target file are defined in the target native code segment;
a first replacement module, configured to replace the third-party code segment in the class file with the target native code segment.
8. The apparatus of claim 7, wherein the third party code snippet comprises: declaring a code segment and a method code segment, the target native code segment including a native method code segment;
the second determining module includes:
the first determining submodule is used for determining a native method code segment corresponding to the declaration code segment and the method code segment according to the corresponding relation among the preset declaration code segment, the method code segment and the native method code segment;
the encapsulation submodule is used for encapsulating the native method code segment and adding an inheritance interface for the encapsulated native method code segment;
the first replacement module comprising:
and the first replacement submodule is used for deleting the statement code segment and the method code segment and adding the inheritance interface and the encapsulated native method code segment corresponding to the inheritance interface into the class file.
9. A terminal, comprising:
a processor;
a memory for storing the processor-executable instructions;
wherein the processor is configured to perform operations performed to implement the replacement method of the third party code snippet of any of claims 1-6.
10. A non-transitory computer-readable storage medium having instructions therein, which, when executed by a processor of a terminal, enable the terminal to perform operations performed to implement the replacement method of the third party code segment of any one of claims 1 to 6.
CN202010312452.9A 2020-04-20 2020-04-20 Method, device, terminal and storage medium for replacing third-party code segment Pending CN111638907A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010312452.9A CN111638907A (en) 2020-04-20 2020-04-20 Method, device, terminal and storage medium for replacing third-party code segment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010312452.9A CN111638907A (en) 2020-04-20 2020-04-20 Method, device, terminal and storage medium for replacing third-party code segment

Publications (1)

Publication Number Publication Date
CN111638907A true CN111638907A (en) 2020-09-08

Family

ID=72332756

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010312452.9A Pending CN111638907A (en) 2020-04-20 2020-04-20 Method, device, terminal and storage medium for replacing third-party code segment

Country Status (1)

Country Link
CN (1) CN111638907A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112631695A (en) * 2020-12-22 2021-04-09 北京达佳互联信息技术有限公司 Data verification method and device, electronic equipment and storage medium
CN113626051A (en) * 2021-07-27 2021-11-09 北京达佳互联信息技术有限公司 Byte code updating method and device and electronic equipment

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6895581B1 (en) * 2000-03-30 2005-05-17 Microsoft Corporation Replaceable classes and virtual constructors for object-oriented programming languages
CN109683906A (en) * 2018-12-25 2019-04-26 北京小米移动软件有限公司 Handle the method and device of HTML code segment
CN109947431A (en) * 2019-03-28 2019-06-28 北京字节跳动网络技术有限公司 A kind of code generating method, device, equipment and storage medium
CN110262818A (en) * 2019-05-29 2019-09-20 北京达佳互联信息技术有限公司 The hot update method of Java code, device, electronic equipment and storage medium
CN110275712A (en) * 2019-06-27 2019-09-24 深圳前海微众银行股份有限公司 A kind of text replacement method, device and equipment
CN110333898A (en) * 2019-05-27 2019-10-15 北京达佳互联信息技术有限公司 A kind of code relation generation method, device, electronic equipment and storage medium

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6895581B1 (en) * 2000-03-30 2005-05-17 Microsoft Corporation Replaceable classes and virtual constructors for object-oriented programming languages
CN109683906A (en) * 2018-12-25 2019-04-26 北京小米移动软件有限公司 Handle the method and device of HTML code segment
CN109947431A (en) * 2019-03-28 2019-06-28 北京字节跳动网络技术有限公司 A kind of code generating method, device, equipment and storage medium
CN110333898A (en) * 2019-05-27 2019-10-15 北京达佳互联信息技术有限公司 A kind of code relation generation method, device, electronic equipment and storage medium
CN110262818A (en) * 2019-05-29 2019-09-20 北京达佳互联信息技术有限公司 The hot update method of Java code, device, electronic equipment and storage medium
CN110275712A (en) * 2019-06-27 2019-09-24 深圳前海微众银行股份有限公司 A kind of text replacement method, device and equipment

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112631695A (en) * 2020-12-22 2021-04-09 北京达佳互联信息技术有限公司 Data verification method and device, electronic equipment and storage medium
CN112631695B (en) * 2020-12-22 2024-06-11 北京达佳互联信息技术有限公司 Data verification method and device, electronic equipment and storage medium
CN113626051A (en) * 2021-07-27 2021-11-09 北京达佳互联信息技术有限公司 Byte code updating method and device and electronic equipment

Similar Documents

Publication Publication Date Title
CN110990105B (en) Interface display method and device, electronic equipment and storage medium
US10817282B2 (en) Application configuration file generation method and apparatus, application page display method and apparatus and storage medium
CN109542417B (en) Method, device, terminal and storage medium for rendering webpage through DOM
CN111736916A (en) Dynamic expansion method and device based on Java language, electronic equipment and storage medium
US10817355B2 (en) Method and apparatus for communication between webpage and operating system
CN110704053B (en) Style information processing method and device
CN111427622B (en) Execution method and device of script codes in application program
CN111638907A (en) Method, device, terminal and storage medium for replacing third-party code segment
CN113434134B (en) Component processing method and device, electronic equipment and storage medium
CN105468606B (en) Webpage saving method and device
CN110851370B (en) Program testing method and device and storage medium
CN113010157A (en) Code generation method and device
CN108563487B (en) User interface updating method and device
CN111580873B (en) Page updating method and device, terminal and storage medium
CN112631695B (en) Data verification method and device, electronic equipment and storage medium
CN113590091A (en) Data processing method and device, electronic equipment and storage medium
CN110569037B (en) Data writing method and device
CN109933357B (en) Application program upgrading method and device
CN113536180A (en) Item processing method, item processing device, electronic equipment, storage medium and program product
CN112860625A (en) Data acquisition method, data storage method, device, equipment and storage medium
CN113778440B (en) Data processing method and device, electronic equipment and storage medium
CN111131000A (en) Information transmission method, device, server and terminal
CN111104110A (en) Global style sharing method, global style sharing device and electronic device
CN110795444B (en) DOM data updating method, page updating method and device
CN110659081B (en) File processing method and device for program object and electronic equipment

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