CN110795069A - Code analysis method, intelligent terminal and computer readable storage medium - Google Patents

Code analysis method, intelligent terminal and computer readable storage medium Download PDF

Info

Publication number
CN110795069A
CN110795069A CN201810872116.2A CN201810872116A CN110795069A CN 110795069 A CN110795069 A CN 110795069A CN 201810872116 A CN201810872116 A CN 201810872116A CN 110795069 A CN110795069 A CN 110795069A
Authority
CN
China
Prior art keywords
file
information
code
project
analysis
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
CN201810872116.2A
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.)
TCL Corp
TCL Research America Inc
Original Assignee
TCL Research America Inc
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 TCL Research America Inc filed Critical TCL Research America Inc
Priority to CN201810872116.2A priority Critical patent/CN110795069A/en
Publication of CN110795069A publication Critical patent/CN110795069A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/20Software design
    • G06F8/24Object-oriented
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Preventing errors by testing or debugging software
    • G06F11/3604Software analysis for verifying properties of programs
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/42Syntactic analysis
    • G06F8/427Parsing
    • 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)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Library & Information Science (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Stored Programmes (AREA)

Abstract

The invention is suitable for the technical field of code analysis, and provides a code analysis method, an intelligent terminal and a computer readable storage medium, wherein file summary information is generated by acquiring a preset project and traversing all code files in the preset project; analyzing all code files in a preset project according to a preset analysis rule according to file type information in the generated file summary information to obtain file analysis information, and generating a file information pool according to the file summary information and the file analysis information; and establishing a calling relationship between classes based on the file information pool, and generating a project architecture diagram through the calling relationship, so that a development team or an individual can clearly understand the overall architecture of the software development project according to the project architecture diagram, the calling relationship of the classes in the software development project can be clear, the efficiency of reading codes is improved, repeated development is avoided, the development progress of the project can be improved, the project development period is shortened, and the project development efficiency is improved.

Description

Code analysis method, intelligent terminal and computer readable storage medium
Technical Field
The invention belongs to the technical field of code analysis, and particularly relates to a code analysis method, an intelligent terminal and a computer readable storage medium.
Background
Java is an object-oriented programming language, not only absorbs various advantages of C + + language, but also abandons concepts such as multiple inheritance, pointers and the like which are difficult to understand in C + +, so that the Java language has two characteristics of strong function, simplicity and easiness in use. Thus, in modern software projects, there are a large number of software projects that use Java for programming.
When a development team or an individual takes over a software project provided by other groups or individuals, the early development does not participate, the project is not known, the project is composed of a plurality of code files, the code files are read and analyzed to know the progress and the overall condition of the current project, and the development progress of the project is correspondingly reduced due to the fact that the project contains a great number of code files and various calling relations exist among the code files, the time consumed for clearing the relations is very long, and the efficiency for reading codes is very low, so that the development progress of the project is prolonged and the project development period is low.
Disclosure of Invention
In view of this, embodiments of the present invention provide a code analysis method, an intelligent terminal, and a computer-readable storage medium, so as to solve the problems that the existing code analysis method fails to provide a comprehensive file relationship diagram and the code interpretation efficiency is low.
A first aspect of an embodiment of the present invention provides a code analysis method, including:
acquiring a preset project, traversing all code files in the preset project, and generating file summary information; the file summary information comprises file type information;
analyzing all code files in the preset project according to preset analysis rules according to the file type information to obtain file analysis information;
generating a file information pool according to the file summary information and the file analysis information;
and establishing a calling relationship between classes based on the file information pool, and generating a project architecture diagram through the calling relationship.
A second aspect of an embodiment of the present invention provides a code analysis apparatus, including:
the file summary information generating unit is used for acquiring a preset project, traversing all code files in the preset project and generating file summary information; the file summary information comprises file type information;
the file analysis processing unit is used for analyzing all code files in the preset project according to the file type information and a preset analysis rule to obtain file analysis information;
a file information pool generating unit, configured to generate a file information pool according to the file summary information and the file analysis information;
and the project architecture diagram generating unit is used for establishing a calling relationship between classes based on the file information pool and generating a project architecture diagram according to the calling relationship.
A third aspect of an embodiment of the present invention provides an intelligent terminal, including:
the code analysis method comprises a memory, a processor and a computer program stored in the memory and capable of running on the processor, wherein the processor implements the steps of the code analysis method provided by the first aspect of the embodiment of the present invention when executing the computer program.
Wherein the computer program comprises:
the file summary information generating unit is used for acquiring a preset project, traversing all code files in the preset project and generating file summary information; the file summary information comprises file type information;
the file analysis processing unit is used for analyzing all code files in the preset project according to the file type information and a preset analysis rule to obtain file analysis information;
a file information pool generating unit, configured to generate a file information pool according to the file summary information and the file analysis information;
and the project architecture diagram generating unit is used for establishing a calling relationship between classes based on the file information pool and generating a project architecture diagram according to the calling relationship.
A fourth aspect of the embodiments of the present invention provides a computer-readable storage medium storing a computer program, where the computer program, when executed by a processor, implements the steps of the code analysis method provided by the first aspect of the embodiments of the present invention.
Wherein the computer program comprises:
the file summary information generating unit is used for acquiring a preset project, traversing all code files in the preset project and generating file summary information; the file summary information comprises file type information;
the file analysis processing unit is used for analyzing all code files in the preset project according to the file type information and a preset analysis rule to obtain file analysis information;
a file information pool generating unit, configured to generate a file information pool according to the file summary information and the file analysis information;
and the project architecture diagram generating unit is used for establishing a calling relationship between classes based on the file information pool and generating a project architecture diagram according to the calling relationship.
Compared with the prior art, the embodiment of the invention has the following beneficial effects: generating file summary information by acquiring a preset project and traversing all code files in the preset project; analyzing all code files in a preset project according to a preset analysis rule according to file type information in the generated file summary information to obtain file analysis information, and generating a file information pool according to the file summary information and the file analysis information; and establishing a calling relationship between classes based on the file information pool, and generating a project file calling relationship diagram to obtain an overall architecture diagram of a preset project, so that a development team or an individual can clearly understand the overall architecture of the software development project according to the project architecture diagram, the calling relationship of the classes in the software development project can be clear, the efficiency of reading codes is improved, repeated development is avoided, the development progress of the project can be improved, the project development period is shortened, and the project development efficiency is improved. .
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings needed to be used in the embodiments or the prior art descriptions will be briefly described below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without inventive exercise.
FIG. 1 is a flowchart illustrating an implementation of a code analysis method according to an embodiment of the present invention;
FIG. 2 is a flowchart of an implementation of a method for generating document summary information according to an embodiment of the present invention;
fig. 3 is a flowchart of a specific implementation of a method for obtaining file parsing information according to file type information according to an embodiment of the present invention;
FIG. 4 is a diagram illustrating a project file call relationship diagram and a file analysis diagram of a single code file according to an embodiment of the present invention;
fig. 5 is a specific implementation flow of a method for establishing a class-to-class call relationship based on a file information pool according to an embodiment of the present invention;
FIG. 6 is a schematic diagram of a code analysis apparatus according to an embodiment of the present invention;
fig. 7 is a schematic diagram of an intelligent terminal according to an embodiment of the present invention.
Detailed Description
In the following description, for purposes of explanation and not limitation, specific details are set forth, such as particular system structures, techniques, etc. in order to provide a thorough understanding of the embodiments of the invention. It will be apparent, however, to one skilled in the art that the present invention may be practiced in other embodiments that depart from these specific details. In other instances, detailed descriptions of well-known systems, circuits, and methods are omitted so as not to obscure the description of the present invention with unnecessary detail.
In order to explain the technical means of the present invention, the following description will be given by way of specific examples. Referring to fig. 1, fig. 1 shows an implementation flow of a code analysis method provided by an embodiment of the present invention, which is detailed as follows:
in step S101, a preset item is acquired, and all code files in the preset item are traversed to generate file summary information; the file summary information includes file type information.
In the embodiment of the invention, the preset item is an item which needs to be subjected to code analysis currently, and the item comprises a plurality of code files with different file types.
It is understood that the preset project is a specific software development project, and is composed of all software code files written by a development team or an individual in the software development process. Here, the project referred to here is mainly a Java development project, and the code file included therein is a Java code file.
Here, the file summary information includes file name information, file code line number information, and file type information. The file types referred to herein include, but are not limited to, java files, properties files, yml files, json files.
Here, when a development team or an individual needs to interpret a software development project handed by the development team or the individual to know the current progress and completion of the project, all code files of the software development project are imported into the code analysis tool provided by the present invention, so that the code analysis tool provided by the present invention obtains all code files of the software development project and analyzes them to generate a project architecture diagram of the software development project, so that the development team or the individual can clearly understand the overall architecture of the software development project according to the project architecture diagram, and can clearly understand the calling relationship of classes in the software development project, thereby improving the efficiency of reading codes, avoiding repeated development, improving the development progress of the project, reducing the development period of the project, and improving the development efficiency of the project.
Preferably, an embodiment of the present invention provides specific implementation steps of a method for generating file summary information as shown in fig. 2, which are detailed as follows:
in step S201, all code files in the preset project are traversed, and file names of the code files are extracted and file name information is formed.
In the embodiment of the invention, all code files in the Java project are traversed, the file name of each code file is extracted one by one, and the file name information is formed according to the extracted file name.
Here, all code files in the Java project have their own corresponding file names, which may also be understood as file names, and these file names are extracted to form file name information. It is understood that the file name information specifically refers to combination information including a plurality of file names. The file name corresponding to each code file has uniqueness. In step S202, the file type of the code file is determined according to the file extension of the code file, and file type information is formed.
In the embodiment of the present invention, the file type of a code file in a Java project is mainly determined by the file extension of the code file, so that the file type of the code file can be determined according to the file extension of the code file, and after traversing all code files in the Java project, the corresponding file type is determined according to the file extension of the code file, where the file types include, but are not limited to, Java files, properties files, yml files, and json files.
Here, after the file type of the code file is determined, the corresponding parsing rule may be determined according to the file type, that is, the file type determines which parsing rule is used to parse the code file corresponding to the file type.
In step S203, the file code line number of each code file is counted one by one, and file code line number information is formed.
In the embodiment of the present invention, the number of file code lines is used as an important basis for determining whether the code file is analyzed completely, and runs through the whole code analysis process of the Java project, so that the number of file code lines of each code file needs to be counted, so as to determine whether the current code file is analyzed completely in the subsequent analysis process.
It is understood that the file code line number information includes information on the file code line numbers of the plurality of code files.
In step S204, the file name information, the file type information, and the file code line number information are integrated to generate file summary information.
In the embodiment of the present invention, the file name information, the file type information, and the file code line number information all include code identifiers, and according to the code identifiers, an association relationship among the file name, the file type, and the file code line number can be determined to perform corresponding matching, so as to generate the file summary information.
In step S102, according to the file type information, analyzing all code files in the preset project according to a preset analysis rule to obtain file analysis information.
In the embodiment of the invention, the preset analysis rule is composed of analysis rules corresponding to a plurality of code files with different file types, namely the file type determines which analysis rule is adopted to analyze the code files, so that the analysis rule of the code files can be determined according to the file type information.
It is understood that the preset parsing rule is a preset rule for parsing files of different file types. Here, rules for parsing files of different file types are provided by preset rule parsers, which cover programming specifications common in Java projects, the main parsers are as follows:
class range parser: the line beginning with "public class" or "public interface" or "public abstrate" is defined as the line stating class information and the line beginning line, and the line number of the ending position of the class range is found by using the characteristic that the java curly brace scope appears in pairs. And recording the line number of the class start line and the line number of the class end line for the interpretation of the information in the class.
The class attribute analyzer: within the range of the row to which the class belongs, judging to start with "public", "private", "protected" or a certain type declaration, and to start with "; "finished line" will be determined as class attribute. And analyzing the attribute name and the attribute type by using a character string segmentation tool.
The class method analyzer comprises the following steps: in the class range, judging whether the method starts with public, protected and private and contains "(", ") and other key symbols, and combining the characteristics of paired occurrence of curly brackets to obtain the name of the method, the type of the method, the line number of the starting line and the line number of the ending line of the method.
The file annotation parser: a single row starting with "//", and multiple rows starting with "/", and ending with "/", the row where these codes are located will be defined as the "annotation row".
properties file parser: when the file suffix is judged to be properties, the parser is used for parsing, and the configuration information (key value) in the file is parsed by using the properties file use specification.
Customizing a resolver: the implementation of the parser is based on the programming language or the specification of the configuration file, and the above list is only the most common parser, so that the implementation of the parser is completely similar to a regular expression, because the user can compile customized parsers belonging to the user according to different compiling rules of the project codes, and specific information can be parsed from the file.
Here, the file parsing information includes any one or more groups of information of class name, other package information introduced by the class, interface of class implementation, parent class of class inheritance, all attributes of the class, all methods of the class, internal class and static code;
it is to be understood that, when the code file includes a configuration file, the file parsing information further includes configuration parameter information.
Preferably, an embodiment of the present invention provides specific implementation steps of the method for obtaining file parsing information according to file type information, as shown in fig. 3, and the detailed steps are as follows:
in step S301, an analysis rule corresponding to each code file is determined according to the file type information.
In the embodiment of the invention, according to the file type of each code file, the corresponding analysis rule is determined so as to interpret the code file.
Preferably, step S301 specifically includes:
and traversing all code files in a preset project according to the file type information, and determining an analysis rule corresponding to each code file to analyze the code files.
In step S302, all code files in the preset project are analyzed according to the determined analysis rule, so as to obtain file analysis information.
In the embodiment of the invention, after the analysis rule corresponding to each code file is determined, the code file is analyzed according to the determined analysis rule to obtain the analysis information of each code file.
It can be understood that, in the parsing process, all code files in the preset project are continuously traversed according to the preset parsing rule, the file parsing information of each code file is parsed, and the file parsing information is stored in the file information pool.
In step S103, a file information pool is generated according to the file summary information and the file analysis information.
In the embodiment of the invention, the file information pool comprises total file information obtained by correlating and matching the file summary information and the file analysis information. The file information pool may also include file analysis information and file summary information obtained by analyzing a plurality of code files, and the file analysis information and the file summary information are associated with each other by a code identifier.
It is understood that the file information pool contains all the information of the read code file, including: class name, other package information introduced by the class, interface realized by the class, parent class inherited by the class, all attributes of the class, all methods of the class (recording method start line number and end line number), internal class, static code and the like. If the code file has a configuration file, the configuration parameters key and value information in the configuration file are recorded.
Preferably, step S103 is specifically:
and associating the file summary information with the file analysis information according to a one-to-one correspondence relationship to generate a file information pool.
In the embodiment of the invention, after the file summary information and the file analysis information are associated and matched according to the one-to-one corresponding relation according to the code identification, the associated files are stored to form a file information pool.
In step S104, a calling relationship between classes is established based on the file information pool, and a project architecture diagram is generated through the calling relationship.
In the embodiment of the invention, the file name has uniqueness; and taking the file name as the element name in the project file calling relation graph.
The file information pool contains detailed analysis information of all code files, the file information pool is used as the basis of all class relations, file names with incidence relations can be searched in the file information pool, then a calling relation between classes is established according to class method names in code files corresponding to the file names and other referenced class method names, so that an imaging tool can generate a project file calling relation graph according to the calling relation between the classes and the corresponding file names, and then a project architecture graph is generated based on the project file calling relation graph, so that a development team or an individual can clearly understand the whole architecture of a software development project according to the project architecture graph, the calling relation of the classes in the software development project can be clear, the efficiency of reading codes is improved, repeated development is avoided, and the development progress of the project can be improved, and the project development period is shortened, and the project development efficiency is improved. .
It is to be appreciated that when an unresolvable code file exists, the unresolvable code file is saved to a database of unsupported file types for easy interpretation by a development team or individual.
Preferably, an embodiment of the present invention provides specific implementation steps of a method for establishing a call relationship between classes and generating a project architecture diagram through the call relationship, as shown in fig. 5, and the detailed steps are as follows:
in step S501, the lines occupied by the class method of each class method name in the file information pool are read line by line, and the character strings in the lines occupied by the class method are divided by preset symbols to obtain sub-character strings.
In the embodiment of the present invention, the preset symbols include, but are not limited to, space symbols and ". quadrature..
In step S502, the substring is traversed to match the reference information in the code file.
In the embodiment of the present invention, all the sub-strings obtained after segmentation are traversed, and matching is performed from "import (reference) information" of the currently interpreted code file, so as to determine whether the sub-strings come from other types of methods or domains according to whether corresponding sub-strings can be matched.
In step S503, when the substring is matched in the reference information in the code file, the class method name related to the substring is searched from the file information pool according to the reference information.
In step S504, a calling relationship between classes is established according to each class method name and the searched class method name related to the substring.
In the embodiment of the invention, the calling relationship of the class corresponding to each class method name is determined according to each class method name and the searched class method name related to the substring, and the calling relationship between the classes is established.
In an application scenario, the file pool information includes all detail information of the file a and the file B, and after analyzing the detail information, the association of the two files is found, for example, a keyword in a certain method in the class a is consistent with a class B method name, and then a class relationship call between the two is established.
Optionally, the step of generating the project file call relationship graph through the call relationship specifically includes:
and imaging the calling relationship between the classes through an imaging tool to generate a corresponding project file calling relationship diagram.
In the embodiment of the present invention, classes corresponding to the call relationship between the established classes and the call relationship between the classes are imaged by using, for example, a grapeviz imaging tool, so as to generate a corresponding project file call relationship diagram as shown in fig. 4. Optionally, after step S104, the code analysis method provided in the embodiment of the present invention further includes the following steps:
and displaying the project architecture diagram on a user interface of the intelligent terminal so as to analyze the preset project according to the project architecture diagram.
In the embodiment of the invention, the generated project architecture diagram is displayed on the user interface of the intelligent terminal, so that a user can analyze the preset project according to the project architecture and search the corresponding code file according to the constituent elements of the project architecture diagram, the code analysis speed is increased, and the code reading efficiency of the user is improved. The constituent elements of the project architecture diagram referred to herein refer to the names of classes in the code file.
Optionally, the code analysis method provided in the present invention further includes the following steps:
and generating a file analysis graph of a single code file based on the file information pool.
In the embodiment of the present invention, the file information pool includes detailed parsing information of all code files, and based on the detailed parsing information, by using, for example, a grapeviz imaging tool, the parsing information corresponding to each code file can generate a corresponding file analysis graph, that is, the file analysis graph of a single code file as shown in fig. 4 is obtained.
In the embodiment of the invention, by acquiring the preset project, traversing all code files in the preset project to generate the file summary information; analyzing all code files in a preset project according to a preset analysis rule according to file type information in the generated file summary information to obtain file analysis information, and generating a file information pool according to the file summary information and the file analysis information; and establishing a calling relationship between classes based on the file information pool, and generating a project architecture diagram through the calling relationship, so that a development team or an individual can quickly know the progress and the overall condition of the current project, the efficiency of reading codes is improved, and the project can be better followed and developed.
It should be understood that, the sequence numbers of the steps in the foregoing embodiments do not imply an execution sequence, and the execution sequence of each process should be determined by its function and inherent logic, and should not constitute any limitation to the implementation process of the embodiments of the present invention.
Fig. 6 is a schematic diagram of a code analysis apparatus according to an embodiment of the present invention, which corresponds to a code analysis method according to the above embodiment, and only shows a part related to the embodiment of the present invention for convenience of description.
Referring to fig. 6, the apparatus includes:
the file summary information generating unit is used for acquiring a preset project, traversing all code files in the preset project and generating file summary information; the file summary information comprises file type information;
the file analysis processing unit is used for analyzing all code files in the preset project according to the file type information and a preset analysis rule to obtain file analysis information;
a file information pool generating unit, configured to generate a file information pool according to the file summary information and the file analysis information;
and the project architecture diagram generating unit is used for establishing a calling relationship between classes based on the file information pool and generating a project architecture diagram according to the calling relationship.
Preferably, the file summary information further includes file name information and file code line number information.
Preferably, the file summary information generating unit includes:
the file name extraction subunit is used for traversing all the code files in the preset project, extracting the file names of the code files and forming file name information;
the file type determining subunit is used for determining the file type of the code file according to the file extension name of the code file and forming file type information;
the file code line number counting subunit is used for counting the file code line number of each code file one by one and forming file code line number information;
and the file summary information generating subunit is used for integrating the file name information, the file type information and the file code line number information to generate file summary information.
Preferably, the file parsing information includes any one or more groups of information of class name, other package information introduced by the class, interface realized by the class, parent class inherited by the class, all attributes of the class, all methods of the class, internal class and static code;
when the code file contains a configuration file, the file analysis information also contains configuration parameter information.
Preferably, the preset parsing rule is composed of parsing rules corresponding to a plurality of code files of different file types.
Preferably, the file parsing processing unit includes:
the analysis rule determining subunit is used for determining an analysis rule corresponding to each code file according to the file type information;
and the file analysis processing subunit is used for analyzing all the code files in the preset project according to the determined analysis rule to obtain file analysis information.
Preferably, the file information pool generating unit is specifically configured to:
and associating the file summary information with the file analysis information according to a one-to-one correspondence relationship to generate a file information pool.
Preferably, the project architecture diagram generation unit includes:
the character string segmentation subunit is used for reading the lines occupied by the class method of each class method name in the file information pool line by line and segmenting the character strings in the lines occupied by the class method by preset symbols to obtain sub character strings;
a string traversal subunit, configured to traverse the sub-strings to match the reference information in the code file;
a class method name searching subunit, configured to search, when the substring is matched in the reference information in the code file, a class method name related to the substring from the file information pool according to the reference information;
and the calling relation establishing subunit is used for establishing a calling relation between classes according to each class method name and the searched class method name related to the substring.
In the embodiment of the invention, by acquiring the preset project, traversing all code files in the preset project to generate the file summary information; analyzing all code files in a preset project according to a preset analysis rule according to file type information in the generated file summary information to obtain file analysis information, and generating a file information pool according to the file summary information and the file analysis information; and establishing a calling relationship between classes based on the file information pool, and generating a project architecture diagram through the calling relationship, so that a development team or an individual can clearly understand the overall architecture of the software development project according to the project architecture diagram, the calling relationship of the classes in the software development project can be clear, the efficiency of reading codes is improved, repeated development is avoided, the development progress of the project can be improved, the project development period is shortened, and the project development efficiency is improved. .
Fig. 7 is a schematic diagram of a terminal according to an embodiment of the present invention. As shown in fig. 7, the intelligent terminal 7 of this embodiment includes: a processor 70, a memory 71 and a computer program 72 stored in said memory 71 and executable on said processor 70. The processor 70, when executing the computer program 72, implements the steps in the various code analysis method embodiments described above, such as the steps 101-104 shown in fig. 1. Alternatively, the processor 70, when executing the computer program 72, implements the functions of the units in the system embodiments, such as the functions of the modules 61 to 64 shown in fig. 6.
Illustratively, the computer program 72 may be divided into one or more units, which are stored in the memory 71 and executed by the processor 70 to accomplish the present invention. The one or more units may be a series of computer program instruction segments capable of performing specific functions, which are used to describe the execution process of the computer program 72 in the intelligent terminal 7. For example, the computer program 72 may be divided into a file summary information generating unit 61, a file analysis processing unit 62, a file information pool generating unit 63, and a project architecture diagram generating unit 64, and the specific functions of the units are as follows:
the file summary information generating unit 61 is configured to acquire a preset project, traverse all code files in the preset project, and generate file summary information; the file summary information comprises file type information;
the file analysis processing unit 62 is configured to analyze all code files in the preset project according to a preset analysis rule according to the file type information to obtain file analysis information;
a file information pool generating unit 63, configured to generate a file information pool according to the file summary information and the file analysis information;
and the project architecture diagram generating unit 64 is configured to establish a calling relationship between classes based on the file information pool, and generate a project architecture diagram according to the calling relationship.
Preferably, the file summary information further includes file name information and file code line number information.
Preferably, the file summary information generating unit 61 in the computer program 72 may be divided into a filename extracting subunit, a file type determining subunit, a file code line number statistics subunit, and a file summary information generating subunit, and each subunit functions as follows:
the file name extraction subunit is used for traversing all the code files in the preset project, extracting the file names of the code files and forming file name information;
the file type determining subunit is used for determining the file type of the code file according to the file extension name of the code file and forming file type information;
the file code line number counting subunit is used for counting the file code line number of each code file one by one and forming file code line number information;
and the file summary information generating subunit is used for integrating the file name information, the file type information and the file code line number information to generate file summary information.
Preferably, the file parsing information includes any one or more groups of information of class name, other package information introduced by the class, interface realized by the class, parent class inherited by the class, all attributes of the class, all methods of the class, internal class and static code;
when the code file contains a configuration file, the file analysis information also contains configuration parameter information.
Preferably, the preset parsing rule is composed of parsing rules corresponding to a plurality of code files of different file types.
Preferably, the file parsing unit 62 in the computer program 72 may be divided into a parsing rule determining subunit and a file parsing subunit, and each subunit functions as follows:
the analysis rule determining subunit is used for determining an analysis rule corresponding to each code file according to the file type information;
and the file analysis processing subunit is used for analyzing all the code files in the preset project according to the determined analysis rule to obtain file analysis information.
Preferably, the file information pool generating unit 63 is specifically configured to:
and associating the file summary information with the file analysis information according to a one-to-one correspondence relationship to generate a file information pool.
Preferably, the project architecture diagram generation unit 64 in the computer program 72 may be divided into a string division subunit, a string traversal subunit, a class method name lookup subunit, and a call relationship establishment subunit, where each subunit functions as follows:
the character string segmentation subunit is used for reading the lines occupied by the class method of each class method name in the file information pool line by line and segmenting the character strings in the lines occupied by the class method by preset symbols to obtain sub character strings;
a string traversal subunit, configured to traverse the sub-strings to match the reference information in the code file;
a class method name searching subunit, configured to search, when the substring is matched in the reference information in the code file, a class method name related to the substring from the file information pool according to the reference information;
and the calling relation establishing subunit is used for establishing a calling relation between classes according to each class method name and the searched class method name related to the substring.
The intelligent terminal 7 can be a desktop computer, a notebook computer, a palm computer, an intelligent mobile phone and other intelligent terminals. The intelligent terminal 7 may include, but is not limited to, a processor 70 and a memory 71. It will be appreciated by those skilled in the art that fig. 7 is merely an example of the intelligent terminal 7 and does not constitute a limitation of the intelligent terminal 7 and may include more or less components than those shown, or some components may be combined, or different components, for example the terminal may also include input output devices, network access devices, buses, etc.
The Processor 70 may be a Central Processing Unit (CPU), other general purpose Processor, a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field-Programmable Gate Array (FPGA) or other Programmable logic device, discrete Gate or transistor logic, discrete hardware components, etc. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
The storage 71 may be an internal storage unit of the intelligent terminal 7, such as a hard disk or a memory of the intelligent terminal 7. The memory 71 may also be an external storage device of the intelligent terminal 7, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), and the like, which are equipped on the intelligent terminal 7. Further, the memory 71 may also include both an internal storage unit and an external storage device of the smart terminal 7. The memory 71 is used for storing the computer program and other programs and data required by the terminal. The memory 71 may also be used to temporarily store data that has been output or is to be output.
It will be apparent to those skilled in the art that, for convenience and brevity of description, only the above-mentioned division of the functional units and modules is illustrated, and in practical applications, the above-mentioned function distribution may be performed by different functional units and modules according to needs, that is, the internal structure of the system is divided into different functional units or modules to perform all or part of the above-mentioned functions. Each functional unit and module in the embodiments may be integrated in one processing unit, or each unit may exist alone physically, or two or more units are integrated in one unit, and the integrated unit may be implemented in a form of hardware, or in a form of software functional unit. In addition, specific names of the functional units and modules are only for convenience of distinguishing from each other, and are not used for limiting the protection scope of the present application. The specific working processes of the units and modules in the system may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
In the above embodiments, the descriptions of the respective embodiments have respective emphasis, and reference may be made to the related descriptions of other embodiments for parts that are not described or illustrated in a certain embodiment.
Those of ordinary skill in the art will appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware or combinations of computer software and electronic hardware. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present invention.
In the embodiments provided in the present invention, it should be understood that the disclosed system/intelligent terminal and method can be implemented in other ways. For example, the above-described system/intelligent terminal embodiments are merely illustrative, and for example, the division of the modules or units is only one logical function division, and there may be other divisions when actually implemented, for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, systems or units, and may be in an electrical, mechanical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit.
The integrated modules/units, if implemented in the form of software functional units and sold or used as separate products, may be stored in a computer readable storage medium. Based on such understanding, all or part of the flow of the method according to the embodiments of the present invention may also be implemented by a computer program, which may be stored in a computer-readable storage medium, and when the computer program is executed by a processor, the steps of the method embodiments may be implemented. Wherein the computer program comprises computer program code, which may be in the form of source code, object code, an executable file or some intermediate form, etc. The computer-readable medium may include: any entity or system capable of carrying said computer program code, recording medium, usb disk, removable hard disk, magnetic disk, optical disk, computer Memory, Read-Only Memory (ROM), Random Access Memory (RAM), electrical carrier wave signals, telecommunications signals, software distribution medium, etc. It should be noted that the computer readable medium may contain content that is subject to appropriate increase or decrease as required by legislation and patent practice in jurisdictions, for example, in some jurisdictions, computer readable media does not include electrical carrier signals and telecommunications signals as is required by legislation and patent practice.
The above-mentioned embodiments are only used for illustrating the technical solutions of the present invention, and not for limiting the same; although the present invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; such modifications and substitutions do not substantially depart from the spirit and scope of the embodiments of the present invention, and are intended to be included within the scope of the present invention.

Claims (11)

1. A method of code analysis, the method comprising:
acquiring a preset project, traversing all code files in the preset project, and generating file summary information; the file summary information comprises file type information;
analyzing all code files in the preset project according to preset analysis rules according to the file type information to obtain file analysis information;
generating a file information pool according to the file summary information and the file analysis information;
and establishing a calling relationship between classes based on the file information pool, and generating a project architecture diagram through the calling relationship.
2. The method of claim 1, wherein the file summary information further comprises file name information and file code line number information.
3. The method of claim 2, wherein the step of traversing all code files in the predetermined project to generate file summary information comprises:
traversing all code files in a preset project, extracting file names of the code files and forming file name information;
determining the file type of the code file according to the file extension name of the code file, and forming file type information;
counting the file code line number of each code file one by one, and forming file code line number information;
and integrating the file name information, the file type information and the file code line number information to generate file summary information.
4. The method of claim 2, wherein the method further comprises:
and generating a file analysis graph of a single code file based on the file information pool.
5. The method according to any one of claims 1 to 4, wherein the predetermined parsing rule is composed of parsing rules corresponding to a plurality of code files of different file types.
6. The method of claim 5, wherein the step of parsing all code files in the preset project according to a preset parsing rule according to the file type information to obtain file parsing information comprises:
determining an analysis rule corresponding to each code file according to the file type information;
and analyzing all code files in the preset project according to the determined analysis rule to obtain file analysis information.
7. The method according to claim 1, wherein the step of generating a file information pool according to the file summary information and the file parsing information specifically comprises:
and associating the file summary information with the file analysis information according to a one-to-one correspondence relationship to generate a file information pool.
8. The method of claim 1, wherein the step of establishing a calling relationship between classes based on the file information pool comprises:
reading the lines occupied by the class method of each class method name in the file information pool line by line, and dividing character strings in the lines occupied by the class methods by preset symbols to obtain sub character strings;
traversing the substring to match reference information in the code file;
when the substrings are matched in the reference information in the code file, searching a class method name related to the substrings from the file information pool according to the reference information;
and establishing a calling relation between classes according to each class method name and the searched class method name related to the substring.
9. The method of claim 1, after the steps of establishing a calling relationship between classes based on the file information pool, and generating a project architecture diagram through the calling relationship, further comprising:
and displaying the project architecture diagram on a user interface of the intelligent terminal so as to analyze the preset project according to the project architecture diagram.
10. An intelligent terminal comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that the steps of the code analysis method according to any one of claims 1 to 9 are implemented when the computer program is executed by the processor.
11. A computer-readable storage medium, in which a computer program is stored which, when being executed by a processor, carries out the steps of a code analysis method according to any one of claims 1 to 9.
CN201810872116.2A 2018-08-02 2018-08-02 Code analysis method, intelligent terminal and computer readable storage medium Pending CN110795069A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201810872116.2A CN110795069A (en) 2018-08-02 2018-08-02 Code analysis method, intelligent terminal and computer readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201810872116.2A CN110795069A (en) 2018-08-02 2018-08-02 Code analysis method, intelligent terminal and computer readable storage medium

Publications (1)

Publication Number Publication Date
CN110795069A true CN110795069A (en) 2020-02-14

Family

ID=69425659

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201810872116.2A Pending CN110795069A (en) 2018-08-02 2018-08-02 Code analysis method, intelligent terminal and computer readable storage medium

Country Status (1)

Country Link
CN (1) CN110795069A (en)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111506747A (en) * 2020-04-16 2020-08-07 Oppo(重庆)智能科技有限公司 File analysis method and device, electronic equipment and storage medium
CN112965940A (en) * 2021-03-04 2021-06-15 中国邮政储蓄银行股份有限公司 Project file display method and device, electronic equipment and processor
CN113094036A (en) * 2021-04-19 2021-07-09 罗普特科技集团股份有限公司 Software engineering directory structure annotation aerial view generation method and system
CN113760690A (en) * 2020-06-05 2021-12-07 腾讯科技(深圳)有限公司 Method and device for analyzing program interface and computer equipment

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103927212A (en) * 2013-01-11 2014-07-16 腾讯科技(深圳)有限公司 Method and device for automatically analyzing source file information
CN104991773A (en) * 2015-06-30 2015-10-21 小米科技有限责任公司 Program generation method and apparatus
CN105243018A (en) * 2015-10-24 2016-01-13 北京航空航天大学 Object-oriented class test data generation method
CN106227668A (en) * 2016-07-29 2016-12-14 腾讯科技(深圳)有限公司 Data processing method and device
CN106469049A (en) * 2015-08-19 2017-03-01 腾讯科技(深圳)有限公司 A kind of method and device of file scan

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103927212A (en) * 2013-01-11 2014-07-16 腾讯科技(深圳)有限公司 Method and device for automatically analyzing source file information
CN104991773A (en) * 2015-06-30 2015-10-21 小米科技有限责任公司 Program generation method and apparatus
CN106469049A (en) * 2015-08-19 2017-03-01 腾讯科技(深圳)有限公司 A kind of method and device of file scan
CN105243018A (en) * 2015-10-24 2016-01-13 北京航空航天大学 Object-oriented class test data generation method
CN106227668A (en) * 2016-07-29 2016-12-14 腾讯科技(深圳)有限公司 Data processing method and device

Cited By (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111506747A (en) * 2020-04-16 2020-08-07 Oppo(重庆)智能科技有限公司 File analysis method and device, electronic equipment and storage medium
CN111506747B (en) * 2020-04-16 2023-09-08 Oppo(重庆)智能科技有限公司 File analysis method, device, electronic equipment and storage medium
CN113760690A (en) * 2020-06-05 2021-12-07 腾讯科技(深圳)有限公司 Method and device for analyzing program interface and computer equipment
CN112965940A (en) * 2021-03-04 2021-06-15 中国邮政储蓄银行股份有限公司 Project file display method and device, electronic equipment and processor
CN112965940B (en) * 2021-03-04 2024-05-28 中国邮政储蓄银行股份有限公司 Project file display method and device, electronic equipment and processor
CN113094036A (en) * 2021-04-19 2021-07-09 罗普特科技集团股份有限公司 Software engineering directory structure annotation aerial view generation method and system
CN113094036B (en) * 2021-04-19 2022-09-27 罗普特科技集团股份有限公司 Software engineering directory structure annotation aerial view generation method and system

Similar Documents

Publication Publication Date Title
CN110795069A (en) Code analysis method, intelligent terminal and computer readable storage medium
CN111241389B (en) Sensitive word filtering method and device based on matrix, electronic equipment and storage medium
CN110502227B (en) Code complement method and device, storage medium and electronic equipment
CN111249736B (en) Code processing method and device
CN107885501B (en) Method and device for obtaining mutual reference relationship of components in Android
CN113032362A (en) Data blood margin analysis method and device, electronic equipment and storage medium
CN111159329A (en) Sensitive word detection method and device, terminal equipment and computer-readable storage medium
CN111881094B (en) Method, device, terminal and storage medium for extracting key information in log
CN111273891A (en) Business decision method and device based on rule engine and terminal equipment
CN113672628A (en) Data blood margin analysis method, terminal device and medium
CN110147431A (en) Key word matching method, device, computer equipment and storage medium
CN103093147B (en) A kind of method identifying information and electronic installation
CN112671878B (en) Block chain information subscription method, device, server and storage medium
CN111324892B (en) Method, device and medium for generating software genes and script detection of script file
CN116933267B (en) Intelligent contract vulnerability detection method, system and equipment for symbol execution
CN112883088B (en) Data processing method, device, equipment and storage medium
CN117056347A (en) SQL sentence true injection detection method, SQL sentence true injection detection device, SQL sentence true injection detection computer equipment and SQL sentence true injection detection storage medium
CN116775488A (en) Abnormal data determination method, device, equipment, medium and product
CN116257850A (en) Virus file identification method and device, storage medium and electronic equipment
CN111382258A (en) Method and device for determining electronic reading object chapter
CN115390847A (en) Log processing method and device, computer readable storage medium and terminal
CN114065197A (en) Call sequence generation method and device, electronic equipment, storage medium and product
CN114157734A (en) Data analysis method and device, electronic equipment and storage medium
CN110471708B (en) Method and device for acquiring configuration items based on reusable components
CN107451050B (en) Function acquisition method and device and server

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
RJ01 Rejection of invention patent application after publication

Application publication date: 20200214

RJ01 Rejection of invention patent application after publication