CN112612516A - Code processing method and device - Google Patents

Code processing method and device Download PDF

Info

Publication number
CN112612516A
CN112612516A CN202011629194.3A CN202011629194A CN112612516A CN 112612516 A CN112612516 A CN 112612516A CN 202011629194 A CN202011629194 A CN 202011629194A CN 112612516 A CN112612516 A CN 112612516A
Authority
CN
China
Prior art keywords
class
function
outdated
referenced
functions
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202011629194.3A
Other languages
Chinese (zh)
Other versions
CN112612516B (en
Inventor
荆东伟
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Ruiting Network Technology Shanghai Co ltd
Original Assignee
Ruiting Network Technology Shanghai 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 Ruiting Network Technology Shanghai Co ltd filed Critical Ruiting Network Technology Shanghai Co ltd
Priority to CN202011629194.3A priority Critical patent/CN112612516B/en
Publication of CN112612516A publication Critical patent/CN112612516A/en
Application granted granted Critical
Publication of CN112612516B publication Critical patent/CN112612516B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

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/70Software maintenance or management
    • G06F8/75Structural analysis for program understanding
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/448Execution paradigms, e.g. implementations of programming paradigms
    • G06F9/4482Procedural
    • G06F9/4484Executing subprograms

Landscapes

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

Abstract

The application discloses a code processing method and device. And performing Gitdiff verification on the computer program codes in the project to obtain Gitdiff information, wherein the Gitdiff information comprises identification information of the changed classes in the computer program codes in the project. The classes of variation include at least: class where code is modified or added. It is detected whether the identification information of the class in the item is located in the Gitdiff information. If so, checking whether the functions referenced in the class include outdated functions. And in the case that the functions quoted in the class comprise outdated functions, outputting a detection report, wherein the detection report is used for prompting that the functions quoted in the class comprise outdated functions. The method can detect whether the computer program codes in the changed classes in the project refer to outdated functions or not, and can not detect whether all the computer program codes in the project refer to outdated functions or not, so that the aim of incremental detection (class with unchanged codes can be ignored) is fulfilled.

Description

Code processing method and device
Technical Field
The present application relates to the field of computer technologies, and in particular, to a code processing method and apparatus.
Background
Currently, various APPs (applications) on a mobile phone are widely used, and as the requirements of people on the functions of APPs are increasing, manufacturers of APPs need to update iterative APPs continuously, and in the process of updating iterative APPs, existing outdated functions in source codes of APPs often need to be updated, for example, new functions are used to gradually replace outdated functions in codes, so that the outdated functions in the source codes of APPs are gradually abandoned. In order to maintain the APP conveniently later, it is necessary to refer to a new function instead of referring to an outdated function in the source code of the APP in the course of iterative update of the APP later.
Disclosure of Invention
In order to quote a new function instead of the outdated function in the source code of the APP in the subsequent iterative update process of the APP, after a technician updates the source code of the APP, whether the outdated function is quoted in the source code of the APP needs to be detected, and under the condition that the outdated function is quoted in the source code of the APP, the technician can be prompted in time so as to modify the source code of the APP and further ensure that the source code of the APP does not quote the outdated function but quotes the new function,
the application discloses a code processing method and device.
In a first aspect, the present application shows a method of code processing, the method comprising:
performing Gitdiff verification on computer program codes in a project to obtain Gitdiff information, wherein the Gitdiff information comprises identification information of a changed class in the computer program codes in the project; the classes of variation include at least: classes in which code is modified or added;
for any class in the computer program code in the project, detecting whether identification information of the class in the project is located in the Gitdiff information;
in the case where the identification information of the class in the item is located in the Gitdiff information, checking whether the function referenced in the class includes a function that is outdated;
in the case that the functions referenced in the class include outdated functions, outputting a detection report for prompting that the functions referenced in the class include outdated functions.
In an optional implementation manner, the checking whether the functions referenced in the class include obsolete functions includes:
detecting a referenced function in the class;
determining whether the referenced function is stored in a preset outdated list, wherein the preset outdated list is used for recording outdated functions;
determining the referenced function as a stale function if the referenced function is stored in the preset stale list.
In an alternative implementation, the Gitdiff information includes a line number of modified or added code in a class of changes in computer program code in the project;
the detecting a referenced function in the class includes:
screening the computer program code corresponding to the line number in the class;
and detecting the referenced function in the computer program code corresponding to the line number.
In an optional implementation manner, after detecting the referenced function in the class, the method further includes:
determining whether the referenced function is located in a preset data packet configured in advance;
in a case where the referenced function is located in a preset data packet configured in advance, the step of determining whether the referenced function is stored in a preset obsolete list is performed.
In an alternative implementation, the detection report includes at least one of: the outdated function, a line number of the outdated function in the computer program code of the project, a code screenshot of a class in which the outdated function resides, a severity of an event referencing the outdated function in the class;
the output detection report includes:
and storing the detection report in a preset file, and/or displaying the detection report.
In a second aspect, the present application shows a code processing apparatus comprising:
the system comprises a first checking module, a second checking module and a third checking module, wherein the first checking module is used for carrying out Gitdiff checking on computer program codes in a project to obtain Gitdiff information, and the Gitdiff information comprises identification information of a changed class in the computer program codes in the project; the classes of variation include at least: classes in which code is modified or added;
a detection module, configured to detect, for any class in the computer program code in the project, whether identification information of the class in the project is located in the Gitdiff information;
a second checking module, configured to, in a case that identification information of the class in the item is located in the Gitdiff information, check whether a function referenced in the class includes a function that is outdated;
and the output module is used for outputting a detection report under the condition that the functions quoted in the class comprise outdated functions, wherein the detection report is used for prompting that the functions quoted in the class comprise the outdated functions.
In an optional implementation manner, the second check module includes:
a detection unit for detecting a referenced function in the class;
a first determining unit configured to determine whether the referenced function is stored in a preset obsolete list, where the preset obsolete list is used for recording obsolete functions;
a second determining unit configured to determine the referenced function as an outdated function in a case where the referenced function is stored in the preset outdated list.
In an alternative implementation, the Gitdiff information includes a line number of modified or added code in a class of changes in computer program code in the project;
the detection unit includes:
a screening subunit, configured to screen the computer program code corresponding to the line number in the class;
a detection subunit, configured to detect a referenced function in the computer program code corresponding to the line number.
In an optional implementation manner, the second check module further includes:
a third determining unit, configured to determine whether the referenced function is located in a preset data packet configured in advance;
the first determination unit is further configured to determine whether the referenced function is stored in a preset obsolete list in a case where the referenced function is located in a preset packet configured in advance.
In an alternative implementation, the detection report includes at least one of: the outdated function, a line number of the outdated function in the computer program code of the project, a code screenshot of a class in which the outdated function resides, a severity of an event referencing the outdated function in the class;
the output module includes:
the storage unit is used for storing the detection report in a preset file;
and the display unit is used for displaying the detection report.
In a third aspect, the present application shows an electronic device comprising:
a processor;
a memory for storing processor-executable instructions;
wherein the processor is configured to perform the code processing method of the first aspect.
In a fourth aspect, the present application illustrates a non-transitory computer-readable storage medium having instructions which, when executed by a processor of an electronic device, enable the electronic device to perform the code processing method of the first aspect.
In a fifth aspect, the present application shows a computer program product, in which instructions, when executed by a processor of an electronic device, enable the electronic device to perform the code processing method according to the first aspect.
The technical scheme provided by the application can comprise the following beneficial effects:
in the present application, a Gitdiff check is performed on the computer program codes in the project to obtain Gitdiff information, and the Gitdiff information includes identification information of a class of a change in the computer program codes in the project. The classes of variation include at least: class where code is modified or added. It is detected whether the identification information of the class in the item is located in the Gitdiff information. In the case where the identification information of the class in the item is located in the Gitdiff information, it is checked whether the function referenced in the class includes a function that is outdated. And in the case that the functions quoted in the class comprise outdated functions, outputting a detection report, wherein the detection report is used for prompting that the functions quoted in the class comprise outdated functions.
By the method and the device, whether the outdated function is referenced in the computer program code in the changed class (the class with the modified or added code) in the project can be detected, and whether the outdated function is referenced in all the computer program codes in the project can not be detected, so that the purpose of incremental detection (the class with unchanged code can be ignored) is achieved.
The method comprises the steps of detecting whether an outdated function is cited in a class in a project based on the lint detection, for example, calling a lint detection tool, and configuring detection logic (including the processes from step S101 to step S104 and the like) of the method for the lint detection tool, so that the purpose of detecting whether the outdated function is cited in the class in the project based on the detection logic can be achieved by the lint detection tool.
The lint detection tool has a default configuration, and after the lint detection tool is started, the lint detection tool loads the default configuration in the lint detection tool, and then the lint detection tool usually executes detection operation according to the default configuration.
However, in the present application, after the lint detection tool loads the default configuration in the lint detection tool, the detection logic of the present application may be used as the configuration to replace the default configuration loaded by the lint detection tool, so that the lint detection tool may use the detection logic of the present application as the configuration, and further the lint detection tool may perform detection according to the detection logic of the present application, for example, the purpose of detecting whether an outdated function is referenced in a class in a project of the present application is achieved, and the detection may not be performed according to the default configuration.
However, the method and the device do not change the lint detection tool and the default configuration in the lint detection tool, and the detection logic of the method and the device is used as the configuration to replace the default configuration loaded by the lint detection tool when the purpose of detecting whether the outdated function is cited in the class of the project is required to be achieved, so that the detection logic of the method and the device can be used as the configuration by the lint detection tool, and the purpose of detecting whether the outdated function is cited in the class of the project can be achieved by the lint detection tool according to the detection logic of the method and the device.
And under the condition that the purpose of detecting whether the outdated function is cited in the classes in the project is not required to be realized, the detection logic of the application is not used as the configuration to replace the default configuration loaded by the lint detection tool, so that the lint detection tool can execute the detection operation according to the default configuration, or the lint detection tool can not be influenced by the detection logic of the application, or the lint detection tool can execute the detection of other service logic.
Therefore, the method does not influence the fact that the lint detection tool executes detection operation or other services according to the default configuration.
Drawings
FIG. 1 is a flow chart of the steps of a code processing method of the present application;
FIG. 2 is a block diagram of a code processing apparatus according to the present application;
FIG. 3 is a block diagram of an electronic device shown in the present application;
fig. 4 is a block diagram of an electronic device shown in the present application.
Detailed Description
In order to make the aforementioned objects, features and advantages of the present application more comprehensible, the present application is described in further detail with reference to the accompanying drawings and the detailed description.
Referring to fig. 1, a flowchart illustrating steps of a code processing method according to the present application is shown, where the method may specifically include the following steps:
in step S101, a Gitdiff check is performed on the computer program codes in the project to obtain Gitdiff information, where the Gitdiff information includes identification information of a class of a change in the computer program codes in the project. The classes of variation include at least: class where code is modified or added.
The Gitdiff check of the computer program code in the project is performed to detect a class in which the code is modified or added in the project, and after the Gitdiff check of the computer program code in the project, Gitdiff information is output. The Gitdiff information may or may not be empty.
In the event that there is a class in the computer program code in the project, where the code is modified and/or added, the identification information of the class in the project is included in the Gitdiff information, that is, the Gitdiff information is not null. Or, in the case that there is no class in which the code is modified and no code is added in the computer program code in the project, the identification information of any one class in the computer program code in the project is not included in the Gitdiff information, that is, the Gitdiff information is null.
Thereafter, the following flow of steps S102 to S104 may be executed for any one class of the computer program code in the project, as is the case for each of the other classes of the computer program code in the project. The specific process is as follows:
in step S102, it is detected whether the identification information of the type in the item is located in the Gitdiff information.
In the present application, the identification information of the class in the item includes: the path of the category in the project or the name of the category in the project, etc., and the identification information of different categories in the project is different.
In this step, the identification information of the type in the item may be acquired, and then the identification information of the type in the item is searched for in the Gitdiff information, so as to determine whether the identification information of the type in the item is located in the Gitdiff information.
In the case that the identification information of the class in the item is located in the Gitdiff information, the code in the class is modified and/or added, and then step S103 may be executed.
Alternatively, in the case where the identification information of the class in the item is not located in the Gitdiff information, it is described that there is no modification and no addition of the code in the class, and the flow may be ended for the class, and then the flow of steps S102 to S104 may be started for the other classes in the item.
In the case where the identification information of the class in the item is located in the Gitdiff information, in step S103, it is checked whether the function referenced in the class includes a function that is outdated.
In an embodiment of the application, a visitCallExpression method in a MethodVisitHandler class can be called to detect expressions in the class, then whether referenced functions exist in each expression is detected, and whether each detected referenced function is a outdated function is checked, so that whether the referenced functions in the class include outdated functions can be detected.
Wherein, in case that the function referred to in the class includes an outdated function, step S104 may be executed, or in case that the function referred to in the class does not include an outdated function, the flow may be ended for the class, and then the flow of steps S102 to S104 may be started for other classes in the project.
Wherein, in a case where no expression is detected in the class, or in a case where an expression is detected in the class but no referenced function exists in the expression, or in a case where an expression is detected in the class, and there are referenced functions in the expression but all referenced functions are non-outdated functions, it may be determined that there is no case where the referenced functions in the class include outdated functions.
In one embodiment of the present application, a technician may develop other projects besides the project mentioned in the development step S101, where the projects may include different function blocks in an application program, and if a certain function is an outdated function in the computer program code of each project, the technician may label the function to identify the function as an outdated function, where the label may be "// predicted", and so on. In one example, "// predicted" may be added at the end of the line where the function is located to label the function in the line as a stale function, etc.
Thus, when checking whether the functions referenced in the class include outdated functions, the computer program codes in all items may be traversed, and when traversing to "// predicted", it is determined whether the functions in the row where "// predicted" is located are the functions referenced in the class, and if the functions in the row where "// predicted" is located are the functions referenced in the class, the functions referenced in the class may be determined to be outdated functions. If the function in the row where "// predicted" is located is not a function referenced in the class, then the traversal may continue until it is determined that none of the functions in the row where "// predicted" is located in the computer program code in all of the items are functions referenced in the class, then it may be determined that the functions referenced in the class do not include outdated functions.
However, in the above manner, computer program codes in all items need to be traversed, and if the number of computer program codes in all items is large, it takes a long time to check whether functions referenced in the class include outdated functions, so that it is inefficient to check whether functions referenced in the class include outdated functions.
Therefore, in order to improve the efficiency of checking whether the functions cited in the class include outdated functions, in another embodiment of the present application, a technician may count the outdated functions in advance, and then store the outdated functions in a preset outdated list, so when checking whether the functions cited in the class include outdated functions, the following procedure may be implemented, including:
1031. the referenced function is detected in the class.
In embodiments of the present application, the computer program code in the class may include a plurality of lines, some of which are added or modified, and some of which are old code, e.g., not added and not modified. To accurately determine the functions referenced in the new or modified code in the class, in another embodiment of the present application, the Gitdiff information includes the line number of the modified or added code in the class of the change in the computer program code in the project; thus, the computer program code corresponding to the line number may be screened in the class, and then the referenced function may be detected in the computer program code corresponding to the line number.
1032. It is determined whether the referenced function is stored in a preset obsolete list, the preset obsolete list being used to record obsolete functions.
1033. In the case where the referenced function is stored in a preset obsolete list, the referenced function is determined to be a obsolete function.
1034. In the case where the referenced function is not stored in the preset obsolete list, the referenced function is determined not to be a obsolete function.
In this case, although the referenced function is an outdated function, the technician does not need to care whether the referenced function is an outdated function, that is, the referenced function can be tolerated as an outdated function, that is, the referenced function does not need to be modified into an outdated function.
In this case, the technician can configure in advance exactly which outdated functions to refer to can be tolerated, and which outdated functions to refer to cannot be tolerated, etc.
Logic in the computer program code in this application includes, among other things, "items" → "packets" → "classes" → "functions".
Thus, in one embodiment, which obsolete functions are referred to may be configured according to a "packet" dimension, for example, a preset packet may be configured in advance, and the functions included in the preset packet are obsolete functions and may not be referred to, that is, the functions in the preset packet may not be referred to.
Thus, on the basis of the foregoing embodiment, the method further includes: after detecting the referenced function in the class, determining whether the referenced function is located in a preset data packet configured in advance, and determining whether the referenced function is stored in a preset obsolete list in case that the referenced function is located in the preset data packet configured in advance. In the case where the referenced function is not located in a preset packet configured in advance, the flow may be ended.
By the method and the device, which functions quoted in the class can be accurately detected.
In the case where the function referenced in the class includes a function that is outdated, in step S104, a detection report for prompting that the function referenced in the class includes a function that is outdated is output.
In the present application, in the case where the function referenced in the class includes an outdated function, then a detection report may be output to prompt a technician that the function referenced in the class includes an outdated function so that the technician may perceive that the function referenced in the class includes an outdated function, and then modify the outdated function into an outdated function so that the outdated function is no longer referenced in the class.
In one embodiment of the present application, the detection report includes at least one of: the outdated function, the line number of the outdated function in the computer program code of the project, the code screenshot of the class in which the outdated function resides, and the severity of the event that references the outdated function in the class.
When the detection report is output, the detection report can be stored in a preset file, and/or the detection report can be displayed so as to be viewed by a technician, or the detection report can be played through a loudspeaker box so as to be perceived by the technician, or the detection report can be sent to a terminal device used by the technician so that the technician can view the detection report on the terminal device used by the technician. The method can be specifically sent by means of mails, internet instant messaging tools, short messages or PUSH and the like, and the specific sending mode is not limited in the application.
Through the application, the technical personnel do not need to manually acquire the detection report, so that the burden of the technical personnel can be reduced, and the labor cost is reduced.
In the present application, a Gitdiff check is performed on the computer program codes in the project to obtain Gitdiff information, and the Gitdiff information includes identification information of a class of a change in the computer program codes in the project. The classes of variation include at least: class where code is modified or added. It is detected whether the identification information of the class in the item is located in the Gitdiff information. In the case where the identification information of the class in the item is located in the Gitdiff information, it is checked whether the function referenced in the class includes a function that is outdated. And in the case that the functions quoted in the class comprise outdated functions, outputting a detection report, wherein the detection report is used for prompting that the functions quoted in the class comprise outdated functions.
By the method and the device, whether the outdated function is referenced in the computer program code in the changed class (the class with the modified or added code) in the project can be detected, and whether the outdated function is referenced in all the computer program codes in the project can not be detected, so that the purpose of incremental detection (the class with unchanged code can be ignored) is achieved.
The method comprises the steps of detecting whether an outdated function is cited in a class in a project based on the lint detection, for example, calling a lint detection tool, and configuring detection logic (including the processes from step S101 to step S104 and the like) of the method for the lint detection tool, so that the purpose of detecting whether the outdated function is cited in the class in the project based on the detection logic can be achieved by the lint detection tool.
The lint detection tool has a default configuration, and after the lint detection tool is started, the lint detection tool loads the default configuration in the lint detection tool, and then the lint detection tool usually executes detection operation according to the default configuration.
However, in the present application, after the lint detection tool loads the default configuration in the lint detection tool, the detection logic of the present application may be used as the configuration to replace the default configuration loaded by the lint detection tool, so that the lint detection tool may use the detection logic of the present application as the configuration, and further the lint detection tool may perform detection according to the detection logic of the present application, for example, the purpose of detecting whether an outdated function is referenced in a class in a project of the present application is achieved, and the detection may not be performed according to the default configuration.
However, the method and the device do not change the lint detection tool and the default configuration in the lint detection tool, and the detection logic of the method and the device is used as the configuration to replace the default configuration loaded by the lint detection tool when the purpose of detecting whether the outdated function is cited in the class of the project is required to be achieved, so that the detection logic of the method and the device can be used as the configuration by the lint detection tool, and the purpose of detecting whether the outdated function is cited in the class of the project can be achieved by the lint detection tool according to the detection logic of the method and the device.
And under the condition that the purpose of detecting whether the outdated function is cited in the classes in the project is not required to be realized, the detection logic of the application is not used as the configuration to replace the default configuration loaded by the lint detection tool, so that the lint detection tool can execute the detection operation according to the default configuration, or the lint detection tool can not be influenced by the detection logic of the application, or the lint detection tool can execute the detection of other service logic.
Therefore, the method does not influence the fact that the lint detection tool executes detection operation or other services according to the default configuration.
It is noted that, for simplicity of explanation, the method embodiments are described as a series of acts or combination of acts, but those skilled in the art will appreciate that the present application is not limited by the order of acts, as some steps may, in accordance with the present application, occur in other orders and concurrently. Further, those skilled in the art will also appreciate that the embodiments described in the specification are exemplary and that no action is necessarily required in this application.
Referring to fig. 2, a block diagram of a code processing apparatus according to the present application is shown, and the apparatus may specifically include the following modules:
a first verification module 11, configured to perform a Gitdiff verification on a computer program code in a project to obtain a Gitdiff information, where the Gitdiff information includes identification information of a changed class in the computer program code in the project; the classes of variation include at least: classes in which code is modified or added;
a detecting module 12, configured to detect, for any class in the computer program code in the project, whether identification information of the class in the project is located in the Gitdiff information;
a second checking module 13, configured to, in a case that the identification information of the class in the item is located in the Gitdiff information, check whether the function referenced in the class includes a function that is outdated;
an output module 14, configured to output a detection report if the function referenced in the class includes an outdated function, where the detection report is used to prompt that the function referenced in the class includes an outdated function.
In an optional implementation manner, the second check module includes:
a detection unit for detecting a referenced function in the class;
a first determining unit configured to determine whether the referenced function is stored in a preset obsolete list, where the preset obsolete list is used for recording obsolete functions;
a second determining unit configured to determine the referenced function as an outdated function in a case where the referenced function is stored in the preset outdated list.
In an alternative implementation, the Gitdiff information includes a line number of modified or added code in a class of changes in computer program code in the project;
the detection unit includes:
a screening subunit, configured to screen the computer program code corresponding to the line number in the class;
a detection subunit, configured to detect a referenced function in the computer program code corresponding to the line number.
In an optional implementation manner, the second check module further includes:
a third determining unit, configured to determine whether the referenced function is located in a preset data packet configured in advance;
the first determination unit is further configured to determine whether the referenced function is stored in a preset obsolete list in a case where the referenced function is located in a preset packet configured in advance.
In an alternative implementation, the detection report includes at least one of: the outdated function, a line number of the outdated function in the computer program code of the project, a code screenshot of a class in which the outdated function resides, a severity of an event referencing the outdated function in the class;
the output module includes:
the storage unit is used for storing the detection report in a preset file;
and the display unit is used for displaying the detection report.
In the present application, a Gitdiff check is performed on the computer program codes in the project to obtain Gitdiff information, and the Gitdiff information includes identification information of a class of a change in the computer program codes in the project. The classes of variation include at least: class where code is modified or added. It is detected whether the identification information of the class in the item is located in the Gitdiff information. In the case where the identification information of the class in the item is located in the Gitdiff information, it is checked whether the function referenced in the class includes a function that is outdated. And in the case that the functions quoted in the class comprise outdated functions, outputting a detection report, wherein the detection report is used for prompting that the functions quoted in the class comprise outdated functions.
By the method and the device, whether the outdated function is referenced in the computer program code in the changed class (the class with the modified or added code) in the project can be detected, and whether the outdated function is referenced in all the computer program codes in the project can not be detected, so that the purpose of incremental detection (the class with unchanged code can be ignored) is achieved.
The method comprises the steps of detecting whether an outdated function is cited in a class in a project based on the lint detection, for example, calling a lint detection tool, and configuring detection logic (including the processes from step S101 to step S104 and the like) of the method for the lint detection tool, so that the purpose of detecting whether the outdated function is cited in the class in the project based on the detection logic can be achieved by the lint detection tool.
The lint detection tool has a default configuration, and after the lint detection tool is started, the lint detection tool loads the default configuration in the lint detection tool, and then the lint detection tool usually executes detection operation according to the default configuration.
However, in the present application, after the lint detection tool loads the default configuration in the lint detection tool, the detection logic of the present application may be used as the configuration to replace the default configuration loaded by the lint detection tool, so that the lint detection tool may use the detection logic of the present application as the configuration, and further the lint detection tool may perform detection according to the detection logic of the present application, for example, the purpose of detecting whether an outdated function is referenced in a class in a project of the present application is achieved, and the detection may not be performed according to the default configuration.
However, the method and the device do not change the lint detection tool and the default configuration in the lint detection tool, and the detection logic of the method and the device is used as the configuration to replace the default configuration loaded by the lint detection tool when the purpose of detecting whether the outdated function is cited in the class of the project is required to be achieved, so that the detection logic of the method and the device can be used as the configuration by the lint detection tool, and the purpose of detecting whether the outdated function is cited in the class of the project can be achieved by the lint detection tool according to the detection logic of the method and the device.
And under the condition that the purpose of detecting whether the outdated function is cited in the classes in the project is not required to be realized, the detection logic of the application is not used as the configuration to replace the default configuration loaded by the lint detection tool, so that the lint detection tool can execute the detection operation according to the default configuration, or the lint detection tool can not be influenced by the detection logic of the application, or the lint detection tool can execute the detection of other service logic.
Therefore, the method does not influence the fact that the lint detection tool executes detection operation or other services according to the default configuration.
For the device embodiment, since it is basically similar to the method embodiment, the description is simple, and for the relevant points, refer to the partial description of the method embodiment.
Fig. 3 is a block diagram of an electronic device 800 shown in the present application. For example, the electronic device 800 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. 3, electronic device 800 may include one or more of the following components: a processing component 802, a memory 804, a power component 806, a multimedia component 808, an audio component 810, an input/output (I/O) interface 812, a sensor component 814, and a communication component 816.
The processing component 802 generally controls overall operation of the electronic device 800, such as operations associated with display, telephone calls, data communications, camera operations, and recording operations. The processing components 802 may include one or more processors 820 to execute instructions to perform all or a portion of the steps of the methods described above. Further, the processing component 802 can include one or more modules that facilitate interaction between the processing component 802 and other components. For example, the processing component 802 can include a multimedia module to facilitate interaction between the multimedia component 808 and the processing component 802.
The memory 804 is configured to store various types of data to support operation at the device 800. Examples of such data include instructions for any application or method operating on the electronic device 800, contact data, phonebook data, messages, images, videos, and so forth. The memory 804 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 supply component 806 provides power to the various components of the electronic device 800. The power components 806 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power for the electronic device 800.
The multimedia component 808 includes a screen that provides an output interface between the electronic device 800 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 808 includes a front facing camera and/or a rear facing camera. The front-facing camera and/or the rear-facing camera may receive external multimedia data when the device 800 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 810 is configured to output and/or input audio signals. For example, the audio component 810 includes a Microphone (MIC) configured to receive external audio signals when the electronic device 800 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 804 or transmitted via the communication component 816. In some embodiments, audio component 810 also includes a speaker for outputting audio signals.
The I/O interface 812 provides an interface between the processing component 802 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 814 includes one or more sensors for providing various aspects of state assessment for the electronic device 800. For example, the sensor assembly 814 may detect an open/closed state of the device 800, the relative positioning of components, such as a display and keypad of the electronic device 800, the sensor assembly 814 may also detect a change in the position of the electronic device 800 or a component of the electronic device 800, the presence or absence of user contact with the electronic device 800, orientation or acceleration/deceleration of the electronic device 800, and a change in the temperature of the electronic device 800. Sensor assembly 814 may include a proximity sensor configured to detect the presence of a nearby object without any physical contact. The sensor assembly 814 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 814 may also include an acceleration sensor, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.
The communication component 816 is configured to facilitate wired or wireless communication between the electronic device 800 and other devices. The electronic device 800 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 816 receives broadcast signals or broadcast operation information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 816 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 800 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 non-transitory computer-readable storage medium comprising instructions, such as the memory 804 comprising instructions, executable by the processor 820 of the electronic device 800 to perform the above-described method is also provided. For example, the non-transitory 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.
Fig. 4 is a block diagram of an electronic device 1900 shown in the present application. For example, the electronic device 1900 may be provided as a server.
Referring to fig. 4, electronic device 1900 includes a processing component 1922 further including one or more processors and memory resources, represented by memory 1932, for storing instructions, e.g., applications, executable by processing component 1922. The application programs stored in memory 1932 may include one or more modules that each correspond to a set of instructions. Further, the processing component 1922 is configured to execute instructions to perform the above-described method.
The electronic device 1900 may also include a power component 1926 configured to perform power management of the electronic device 1900, a wired or wireless network interface 1950 configured to connect the electronic device 1900 to a network, and an input/output (I/O) interface 1958. The electronic device 1900 may operate based on an operating system stored in memory 1932, such as Windows Server, Mac OS XTM, UnixTM, LinuxTM, FreeBSDTM, or the like.
The embodiments in the present specification are described in a progressive manner, each embodiment focuses on differences from other embodiments, and the same and similar parts among the embodiments are referred to each other.
As will be appreciated by one skilled in the art, embodiments of the present application may be provided as a method, apparatus, or computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present application is described with reference to flowchart illustrations and/or block diagrams of methods, terminal devices (systems), and computer program products according to the application. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing terminal to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing terminal, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing terminal to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing terminal to cause a series of operational steps to be performed on the computer or other programmable terminal to produce a computer implemented process such that the instructions which execute on the computer or other programmable terminal provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
While the preferred embodiments of the present application have been described, additional variations and modifications in those embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. Therefore, it is intended that the appended claims be interpreted as including preferred embodiments and all alterations and modifications as fall within the scope of the application.
Finally, it should also be noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or terminal that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or terminal. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or terminal that comprises the element.
The above detailed description is given to a code processing method and apparatus provided by the present application, and a specific example is applied in the present application to explain the principle and the implementation of the present application, and the description of the above embodiment is only used to help understand the method and the core idea of the present application; meanwhile, for a person skilled in the art, according to the idea of the present application, there may be variations in the specific embodiments and the application scope, and in summary, the content of the present specification should not be construed as a limitation to the present application.

Claims (12)

1. A method of code processing, the method comprising:
performing Gitdiff verification on computer program codes in a project to obtain Gitdiff information, wherein the Gitdiff information comprises identification information of a changed class in the computer program codes in the project; the classes of variation include at least: classes in which code is modified or added;
for any class in the computer program code in the project, detecting whether identification information of the class in the project is located in the Gitdiff information;
in the case where the identification information of the class in the item is located in the Gitdiff information, checking whether the function referenced in the class includes a function that is outdated;
in the case that the functions referenced in the class include outdated functions, outputting a detection report for prompting that the functions referenced in the class include outdated functions.
2. The method of claim 1, wherein said checking whether the functions referenced in the class include outdated functions comprises:
detecting a referenced function in the class;
determining whether the referenced function is stored in a preset outdated list, wherein the preset outdated list is used for recording outdated functions;
determining the referenced function as a stale function if the referenced function is stored in the preset stale list.
3. The method of claim 2, wherein the Gitdiff information includes a line number of modified or added code in a class of changes in computer program code in the project;
the detecting a referenced function in the class includes:
screening the computer program code corresponding to the line number in the class;
and detecting the referenced function in the computer program code corresponding to the line number.
4. The method of claim 2, wherein after detecting the referenced function in the class, further comprising:
determining whether the referenced function is located in a preset data packet configured in advance;
in a case where the referenced function is located in a preset data packet configured in advance, the step of determining whether the referenced function is stored in a preset obsolete list is performed.
5. The method of claim 1, wherein the detection report comprises at least one of: the outdated function, a line number of the outdated function in the computer program code of the project, a code screenshot of a class in which the outdated function resides, a severity of an event referencing the outdated function in the class;
the output detection report includes:
and storing the detection report in a preset file, and/or displaying the detection report.
6. A code processing apparatus, characterized in that the apparatus comprises:
the system comprises a first checking module, a second checking module and a third checking module, wherein the first checking module is used for carrying out Gitdiff checking on computer program codes in a project to obtain Gitdiff information, and the Gitdiff information comprises identification information of a changed class in the computer program codes in the project; the classes of variation include at least: classes in which code is modified or added;
a detection module, configured to detect, for any class in the computer program code in the project, whether identification information of the class in the project is located in the Gitdiff information;
a second checking module, configured to, in a case that identification information of the class in the item is located in the Gitdiff information, check whether a function referenced in the class includes a function that is outdated;
and the output module is used for outputting a detection report under the condition that the functions quoted in the class comprise outdated functions, wherein the detection report is used for prompting that the functions quoted in the class comprise the outdated functions.
7. The apparatus of claim 6, wherein the second check-up module comprises:
a detection unit for detecting a referenced function in the class;
a first determining unit configured to determine whether the referenced function is stored in a preset obsolete list, where the preset obsolete list is used for recording obsolete functions;
a second determining unit configured to determine the referenced function as an outdated function in a case where the referenced function is stored in the preset outdated list.
8. The apparatus of claim 7, wherein the Gitdiff information includes a line number of modified or added code in a class of changes in computer program code in the project;
the detection unit includes:
a screening subunit, configured to screen the computer program code corresponding to the line number in the class;
a detection subunit, configured to detect a referenced function in the computer program code corresponding to the line number.
9. The apparatus of claim 7, wherein the second check-up module further comprises:
a third determining unit, configured to determine whether the referenced function is located in a preset data packet configured in advance;
the first determination unit is further configured to determine whether the referenced function is stored in a preset obsolete list in a case where the referenced function is located in a preset packet configured in advance.
10. The apparatus of claim 6, wherein the detection report comprises at least one of: the outdated function, a line number of the outdated function in the computer program code of the project, a code screenshot of a class in which the outdated function resides, a severity of an event referencing the outdated function in the class;
the output module includes:
the storage unit is used for storing the detection report in a preset file;
and the display unit is used for displaying the detection report.
11. An electronic device, characterized in that the electronic device comprises:
a processor;
a memory for storing processor-executable instructions;
wherein the processor is configured to perform the code processing method of any one of claims 1-5.
12. A non-transitory computer-readable storage medium, wherein instructions of the storage medium, when executed by a processor of an electronic device, enable the electronic device to perform the code processing method of any one of claims 1-5.
CN202011629194.3A 2020-12-30 2020-12-30 Code processing method and device Active CN112612516B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011629194.3A CN112612516B (en) 2020-12-30 2020-12-30 Code processing method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011629194.3A CN112612516B (en) 2020-12-30 2020-12-30 Code processing method and device

Publications (2)

Publication Number Publication Date
CN112612516A true CN112612516A (en) 2021-04-06
CN112612516B CN112612516B (en) 2024-05-03

Family

ID=75253095

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011629194.3A Active CN112612516B (en) 2020-12-30 2020-12-30 Code processing method and device

Country Status (1)

Country Link
CN (1) CN112612516B (en)

Citations (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20120079452A1 (en) * 2010-09-28 2012-03-29 International Business Machines Corporation Provision of Code Base Modification Using Automatic Learning of Code Changes
WO2014112303A1 (en) * 2013-01-21 2014-07-24 日産自動車株式会社 Missed-data-update review device, missed-data-update review method, and missed-data-update review program
JP2014153777A (en) * 2013-02-05 2014-08-25 Tokyo Kogei Univ Source code inspection device
US20150033202A1 (en) * 2013-07-26 2015-01-29 Fujitsu Limited Method and apparatus for porting source code
CN105677415A (en) * 2016-01-06 2016-06-15 网易(杭州)网络有限公司 Hot updating method and device
CN107292168A (en) * 2016-03-30 2017-10-24 阿里巴巴集团控股有限公司 Detect method and device, the server of program code
CN108932192A (en) * 2017-05-22 2018-12-04 南京大学 A kind of Python Program Type defect inspection method based on abstract syntax tree
CN109508204A (en) * 2018-11-15 2019-03-22 四川长虹电器股份有限公司 A kind of front-end code quality determining method and device
CN109918127A (en) * 2019-03-07 2019-06-21 扬州大学 A kind of defect error correction method based on code revision pattern differentials
CN110209568A (en) * 2018-04-24 2019-09-06 腾讯科技(深圳)有限公司 Coverage rate test method, apparatus and storage equipment
CN112100072A (en) * 2020-09-16 2020-12-18 广州虎牙科技有限公司 Static detection method, device, equipment and medium for application program codes
CN112148602A (en) * 2020-09-17 2020-12-29 云南电网有限责任公司信息中心 Source code security analysis method based on history optimization feature intelligent learning

Patent Citations (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20120079452A1 (en) * 2010-09-28 2012-03-29 International Business Machines Corporation Provision of Code Base Modification Using Automatic Learning of Code Changes
WO2014112303A1 (en) * 2013-01-21 2014-07-24 日産自動車株式会社 Missed-data-update review device, missed-data-update review method, and missed-data-update review program
JP2014153777A (en) * 2013-02-05 2014-08-25 Tokyo Kogei Univ Source code inspection device
US20150033202A1 (en) * 2013-07-26 2015-01-29 Fujitsu Limited Method and apparatus for porting source code
CN105677415A (en) * 2016-01-06 2016-06-15 网易(杭州)网络有限公司 Hot updating method and device
CN107292168A (en) * 2016-03-30 2017-10-24 阿里巴巴集团控股有限公司 Detect method and device, the server of program code
CN108932192A (en) * 2017-05-22 2018-12-04 南京大学 A kind of Python Program Type defect inspection method based on abstract syntax tree
CN110209568A (en) * 2018-04-24 2019-09-06 腾讯科技(深圳)有限公司 Coverage rate test method, apparatus and storage equipment
CN109508204A (en) * 2018-11-15 2019-03-22 四川长虹电器股份有限公司 A kind of front-end code quality determining method and device
CN109918127A (en) * 2019-03-07 2019-06-21 扬州大学 A kind of defect error correction method based on code revision pattern differentials
CN112100072A (en) * 2020-09-16 2020-12-18 广州虎牙科技有限公司 Static detection method, device, equipment and medium for application program codes
CN112148602A (en) * 2020-09-17 2020-12-29 云南电网有限责任公司信息中心 Source code security analysis method based on history optimization feature intelligent learning

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
里欧·法尼尼 等: "《 Red Hat Linux 6.1技术大全》", 北京:北京希望电子出版社, pages: 261 - 262 *

Also Published As

Publication number Publication date
CN112612516B (en) 2024-05-03

Similar Documents

Publication Publication Date Title
CN107423106B (en) Method and apparatus for supporting multi-frame syntax
US9648152B2 (en) Methods and devices for labeling a number
EP3041205A2 (en) Method, device and system for displaying content of short message, method and device for determining display of short message
EP3176999A1 (en) Method and device for processing information
EP3089436A1 (en) Methods and devices for calling based on cloud card
CN107463372B (en) Data-driven page updating method and device
CN116069612A (en) Abnormality positioning method and device and electronic equipment
CN111221593A (en) Dynamic loading method and device
CN107241439B (en) Message pushing method and device for H5 page
CN106354595B (en) Mobile terminal, hardware component state detection method and device
CN110457084B (en) Loading method and device
CN112333233B (en) Event information reporting method and device, electronic equipment and storage medium
CN112612516B (en) Code processing method and device
CN111241134B (en) Data processing method and device
CN107241432B (en) Message receiving method and device, electronic equipment and computer storage medium
CN111597106A (en) Point burying management method and device
CN107257384B (en) Service state monitoring method and device
CN106846050B (en) Method, device and system for sending display notification
EP3211868B1 (en) Method and device for processing information
CN113946346B (en) Data processing method and device, electronic equipment and storage medium
CN114489641B (en) Data processing method and device, electronic equipment and storage medium
CN113934452B (en) Data processing method and device, electronic equipment and storage medium
EP3869845B1 (en) System updating method applied to a mobile terminal and to a test server, a mobile terminal and a test server
CN114020504B (en) Data processing method and device, electronic equipment and storage medium
CN114416218B (en) Data processing 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
GR01 Patent grant
GR01 Patent grant