CN115756487A - Target type variable searching method, electronic equipment and storage medium - Google Patents

Target type variable searching method, electronic equipment and storage medium Download PDF

Info

Publication number
CN115756487A
CN115756487A CN202211443213.2A CN202211443213A CN115756487A CN 115756487 A CN115756487 A CN 115756487A CN 202211443213 A CN202211443213 A CN 202211443213A CN 115756487 A CN115756487 A CN 115756487A
Authority
CN
China
Prior art keywords
target
annotation
node
type variable
file
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
CN202211443213.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.)
Ping An Bank Co Ltd
Original Assignee
Ping An Bank 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 Ping An Bank Co Ltd filed Critical Ping An Bank Co Ltd
Priority to CN202211443213.2A priority Critical patent/CN115756487A/en
Publication of CN115756487A publication Critical patent/CN115756487A/en
Pending legal-status Critical Current

Links

Images

Abstract

The application discloses a target type variable searching method, electronic equipment and a storage medium, wherein the target type variable searching method comprises the following steps: analyzing the target file to obtain a corresponding syntax tree; if the syntax tree has annotation nodes, acquiring target attributes of the annotation nodes; if the target attribute is a preset attribute, acquiring all node information corresponding to the annotation node; and determining the target type variable searched in the target file in response to the fact that any node information contains target information. By the method, the target type variable searching method can automatically and accurately search the target type variable, and can avoid the problems of omission, misjudgment, long time consumption and the like in manual code checking.

Description

Target type variable searching method, electronic equipment and storage medium
Technical Field
The present application relates to the field of computer processing technologies, and in particular, to a target type variable searching method, an electronic device, and a storage medium.
Background
In the process of developing a project according to project requirements, a developer can use corresponding data types to define some variables in the process of writing codes, but due to experience problems of different developers, a compiling error may not be triggered at present when the codes are written, but in the following, compiling problems such as syntax errors and the like may occur when codes compiled by other developers are added, at this time, corresponding errors often need to be searched manually for correction, but problems such as omission, misjudgment and the like often exist in a manual searching mode, and time is consumed.
Disclosure of Invention
The application provides a target type variable searching method, electronic equipment and a storage medium, which can realize automatic and accurate searching of a target type variable so as to remind a user of modifying the target type variable, and can avoid the problems of omission, misjudgment, long time consumption and the like in manual code checking.
In order to solve the technical problem, the present application adopts a technical solution that: a target type variable searching method is provided, and the method comprises the following steps: analyzing the target file to obtain a corresponding syntax tree; if the syntax tree has annotation nodes, acquiring target attributes of the annotation nodes; if the target attribute is a preset attribute, acquiring all node information corresponding to the annotation node; and determining the target type variable searched in the target file in response to the fact that any node information contains the target information.
Wherein, before parsing the target file and obtaining the corresponding syntax tree, the method further comprises: acquiring an original folder, wherein the original folder comprises a plurality of files; a target document is determined from the plurality of documents.
Wherein, determining the target file from the plurality of files comprises: acquiring file names of a plurality of files; and determining the file with the file name meeting the preset requirement as the target file.
If the syntax tree has an annotation node, before acquiring the target attribute of the annotation node, the method includes: and traversing the syntax tree and judging whether annotation nodes exist in the syntax tree.
The preset attribute is at least one of @ data, @ getter and @ setter.
Wherein, all node information corresponding to the annotation node is obtained, including: obtaining the statement of a body corresponding to the annotation node in the grammar tree; adding the declaration of the body as node information to a file list; and traversing the body statement in the file list, and acquiring corresponding node information from the body statement.
The node information is at least one of type declaration, field declaration and basic type declaration.
Wherein, in response to any node information containing target information, determining the target type variable found in the target file includes: and in response to the fact that any type statement, field statement and basic type statement are not null, determining that the target type variable exists in the annotation node corresponding to the node information.
Wherein the target type variable is a basic type variable.
In order to solve the technical problem, the present application adopts a technical solution that: there is provided an electronic device comprising a memory for storing a computer program and a processor for executing the computer program to implement the above-mentioned target type variable lookup method.
In order to solve the technical problem, the present application adopts a technical solution that: there is provided a computer readable storage medium for storing a computer program for implementing the above-mentioned target type variable lookup method when executed by a processor.
The beneficial effect of this application is: different from the prior art, the target type variable searching method provided by the application can obtain a corresponding syntax tree by analyzing a target file, then judge whether the syntax tree contains annotation nodes, if the annotation nodes exist in the syntax tree, obtain the target attributes of the annotation nodes, further judge whether the target attributes of the annotation nodes are preset data, if the target attributes are the preset attributes, obtain all node information corresponding to the annotation nodes, and finally, in response to any node information containing the target information, determine the mode of searching the target type variable in the target file, so that the target type variable can be automatically searched, the problems of omission, misjudgment, long time consumption and the like in manual code checking are reduced, and the efficiency of searching the target type variable is improved.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed to be used in the description of the embodiments are briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present application, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts. Wherein:
FIG. 1 is a schematic flow chart diagram illustrating a first embodiment of a target type variable searching method provided in the present application;
FIG. 2 is a flowchart illustrating a second embodiment of a target type variable searching method provided in the present application;
FIG. 3 is a flowchart illustrating a target type variable searching method according to a third embodiment of the present disclosure;
FIG. 4 is a schematic flowchart of a fourth embodiment of a target type variable searching method provided in the present application;
FIG. 5 is a schematic structural diagram of an embodiment of an electronic device provided in the present application;
FIG. 6 is a block diagram of an embodiment of a computer-readable storage medium provided in the present application.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
Referring to fig. 1, fig. 1 is a schematic flowchart of a first embodiment of a target type variable searching method provided in the present application, where the method includes:
step 11: and analyzing the target file to obtain a corresponding syntax tree.
In some embodiments, a repository (e.g., gitlab) is managed based on project source code, using git clone instructions (or automation scripts) to obtain the project source code, and then traversing the folders corresponding to the project source code to determine the target files from the folders. Wherein, the target file can be a file with a suffix of java.
In addition, files obtained by traversing the folder of the project source code may be saved to a file list, such as a java file list. Also, in order to reduce the time for specifying the target file, the file names of the files in the file list may be unified, such as converting characters of the file names into lower case letters.
In some embodiments, the file with the file name ending in the field of DTO, PO, VO, etc. is used as the target file by determining whether the file name of the file in the file list includes the field of DTO, PO, VO, etc., e.g., determining whether the file name ends in the field of DTO, PO, VO, etc.
Among them, a DTO (Data Transfer Object) may Transfer an intermediate Object for converting "PO → VO" or "VO → PO" between the view layer and the service layer; the PO (Persistent Object) is positioned in a Persistent layer, the PO and the data structure of the Persistent layer form a one-to-one mapping relation, if the Persistent layer is a relational database, one or a plurality of fields of a data table in the database correspond to one or a plurality of attributes of the PO; VO (View Object) is located in the View layer, and can encapsulate all data of a certain page or component.
And, DTO, PO, VO belong to the class of POJO (Plain original Java Object/Plain Old Java Object), POJO being a transparent component that does not contain business logic, having private variables as attributes, and can access the attributes of the POJO class using a getter method or a setter method. The getter method and the setter method are mainly used for hiding the implementation details of the class and protecting the data of the class.
In some embodiments, the object file may be parsed into a Syntax Tree, such as an Abstract Syntax Tree (AST) for a Java file, where each node in the Syntax Tree is capable of corresponding to a Java Syntax, that is, a Java file is composed of several nodes.
Step 12: and if the annotation node exists in the syntax tree, acquiring the target attribute of the annotation node.
Wherein, the Annotation node is represented by Annotation in the code, and the data in the Annotation node is related to the data of the meta-program but not belongs to the data of the meta-program. Where Annotation is an interface, a program may obtain an Annotation object specifying a program element by reflection, and then obtain metadata inside the Annotation by the Annotation object.
In some embodiments, the target attribute of the annotation node refers to the name attribute, i.e., the name attribute of the Maker annotation.
Step 13: and if the target attribute is a preset attribute, acquiring all node information corresponding to the annotation node.
The associated syntax of the annotation node is basically consistent with the syntax inherent to Java, except for the use of the @ symbol.
Specifically, the preset attribute is at least one of @ data, @ get and @ setter. Wherein, the @ data annotation can act on the class and provides a getter method, a setter method, an equals method, a canEqual method, a hashCode method and a toString method for all the attributes; the @ getter annotation is on an attribute, and a getter method can be provided for the attribute; the @ setter annotation is on an attribute, and a setter method may be provided for the attribute.
In some embodiments, node information for annotation nodes may be extracted through an xpath syntax. Specifically, the node information is at least one of a type declaration, a field declaration, and a basic type declaration. Wherein the type Declaration is represented in code by Field Declaration; the field Declaration is represented in the code by Type Declaration; the basic type Declaration is represented in code by Primitive Declaration.
In some embodiments, the corresponding node information may be obtained from the declaration of the body by obtaining the declaration of the body in the syntax tree corresponding to the annotation node, then adding the declaration of the body as node information to the file list, and traversing the declaration of the body in the file list. The Declaration of the Body corresponding to the annotation node is represented by Class Or Interfaces Body Declaration in the code, and all node information corresponding to the annotation node can be obtained by cycling through all Declaration lists under the Class Or Interfaces Body.
Step 14: and determining the target type variable searched in the target file in response to the fact that any node information contains target information.
In some embodiments, the target information may be a setting of a related statement, such as non-null or null. And in response to any type declaration, field declaration and/or basic type declaration not being empty, determining that the target type variable exists in the annotation node corresponding to the node information.
Specifically, the target type variable is a basic type variable, that is, a private type variable, which includes bolean (boolean), char (character), byte (byte), short (short integer), int (integer), long (long integer), float (single precision floating point), and the like.
In other embodiments, whether a target type variable exists in an annotation node may be determined by judging whether node information of the annotation node is non-empty, and if the node information is non-empty, it indicates that the target type variable exists in the annotation node, and further indicates that the target type variable exists in the target file, at this time, corresponding prompt information or warning information may be generated to remind a user to modify a variable type in a corresponding code in the target file.
Different from the prior art, the target type variable searching method provided by the application can obtain the syntax tree by analyzing the target file, further obtain all node information corresponding to the annotation node when the annotation node exists in the syntax tree and the target attribute of the annotation node is the preset attribute, and further determine the target type variable in the target file by judging whether the node information contains the target information. By the method, the target type variable can be searched in an automatic mode so as to remind a user of modifying the target type variable, and the problems of omission, misjudgment, long time consumption and the like in manual code checking can be solved.
Referring to fig. 2, fig. 2 is a schematic flowchart of a second embodiment of a target type variable searching method provided in the present application, where the method includes:
step 21: acquiring an original folder; wherein the original folder includes a plurality of files.
Specifically, the original folder is a folder that contains the project source code. The project source code can be obtained from the project source code management warehouse gitlab through a git clone command.
In some embodiments, the original folder contains a plurality of files, which are files suffixed with the suffix.
Step 22: a target document is determined from the plurality of documents.
In some embodiments, the target file may be determined by obtaining file names of a plurality of files and determining the file with the file name meeting a preset requirement as the target file.
For example, when code is written in the JAVA language, files with a suffix name of.java may be determined by traversing the original folder, and then target JAVA files may be determined from these.
For example, when writing code in the C language, the original folder is traversed to determine files with suffix name.c, and then the target code file is determined from these.c files.
Step 23: and analyzing the target file to obtain a corresponding syntax tree.
Step 24: and if the annotation node exists in the syntax tree, acquiring the target attribute of the annotation node.
Step 25: and if the target attribute is a preset attribute, acquiring all node information corresponding to the annotation node.
Step 26: and determining the target type variable searched in the target file in response to the fact that any node information contains target information.
Steps 23 to 26 may have the same or similar technical features in the above embodiments, and are not described herein again.
Different from the prior art, the target type variable searching method provided by the application can accurately search the target type variable in an automatic mode so as to remind a user of modifying the target type variable, and can avoid the problems of omission, misjudgment, long time consumption and the like in manual code checking.
Referring to fig. 3, fig. 3 is a schematic flowchart of a third embodiment of a target type variable searching method provided in the present application, where the method includes:
step 31: acquiring an original folder; wherein the original folder includes a plurality of files.
Step 32: a target document is determined from the plurality of documents.
Step 33: and analyzing the target file to obtain a corresponding syntax tree.
Step 34: and traversing the syntax tree and judging whether the syntax tree has annotation nodes.
If yes, go to step 35, otherwise go back to step 32, determine the next target file from multiple files again.
It can be understood that if there is no annotation node in the syntax tree, it indicates that there is no annotation in the target file, that is, the target file is not a POJO file, and at this time, target type variable lookup may be continued on the next target file. The POJO file is derived from the POJO component described above.
Step 35: and traversing all the annotation nodes to obtain the target attribute of each annotation node.
Step 36: and judging whether the target attribute of the annotation node is a preset attribute.
In response to the target attribute of any annotation node being the preset attribute, step 37 is executed, and if the target attributes of all annotation nodes are not the preset attribute, step 32 is returned.
It can be understood that, if the target attributes of all annotation nodes are not the preset attributes, it indicates that the target file is not the POJO file, and at this time, the target type variable lookup may be continued for the next target file.
Step 37: and acquiring all node information corresponding to the annotation nodes.
Step 38: and traversing all the node information, and judging whether the node information contains the target information.
In response to any node information containing the target information, step 39 is executed, and if all node information does not contain the target information, step 32 is returned.
It can be understood that when it is determined that the current node information does not include the target information, the next node information may continue to be verified/judged, and when all the node information does not include the target information, the next target file may continue to be searched for the target type variable.
Step 39: and determining the target type variable found in the target file.
Steps 31 to 39 may have the same or similar technical features as any of the above embodiments, and are not described herein again.
In any of the above embodiments, the method for finding the target type variable includes: after the syntax tree is obtained, whether annotation nodes meeting requirements exist in the syntax tree is verified firstly, and then whether node information corresponding to the annotation nodes meets the requirements is verified.
In other embodiments, the declaration of the corresponding body in the syntax tree may be obtained first after the syntax tree is obtained; adding the declaration of the body as node information to a file list; traversing the body statement in the file list, acquiring corresponding node information from the body statement, then verifying whether the corresponding node in the node information is an annotation node, and then when the node is an annotation node, implementing the corresponding node according to the relevant steps shown in fig. 4, where fig. 4 is a flowchart of a fourth embodiment of the target type variable searching method provided by the present application, the method includes:
step 41: and analyzing the target file to obtain a corresponding syntax tree.
In some embodiments, before parsing the target file, an original folder containing a plurality of files is obtained, and then the target file is determined from the plurality of files.
Specifically, file names of a plurality of files are obtained, files with file names meeting preset requirements are determined as target files, for example, files with file names ending in DTO, PO or VO are determined from files with suffixes of java, and the files are used as target files.
Step 42: node information of all nodes of the syntax tree is obtained.
In some embodiments, step 42 may include the following flow (not shown):
s1: a declaration of the body of all nodes in the syntax tree is obtained.
S2: the declaration of the body is added as node information to the file list.
S3: and traversing the statement of the body in the file list, and acquiring corresponding node information from the statement of the body.
The node information is at least one of type declaration, field declaration and basic type declaration.
Step S1 to step S3 may have the same or similar technical features as any of the above embodiments, and are not described herein again.
Step 43: and verifying whether the corresponding node in the node information is an annotation node.
If yes, go to step 44.
Step 44: and acquiring the target attribute of the annotation node.
In some embodiments, the target attribute of the annotation node refers to the name attribute, i.e., the maker annotation/name attribute.
Step 45: and if the target attribute is the preset attribute, acquiring all node information corresponding to the annotation node.
The preset attribute is at least one of @ data, @ getter and @ setter.
Step 46: and determining the target type variable searched in the target file in response to the fact that the node information contains the target information.
The node information may be a type declaration, a field declaration, or a basic type declaration. And determining to find the target type variable in the target file in response to the type statement, the field statement and the basic type statement of any node not being null.
The target type variable is a basic type variable, namely a prime type variable, wherein the prime type variable comprises bolean, char, byte, short, int, long, float and the like.
Different from the prior art, the target type variable searching method provided by the application can be used for verifying whether the node information of all nodes in the syntax tree meets the requirements or not and judging whether the nodes corresponding to the node information meeting the requirements are annotation nodes or not, the target type variable can be searched in the same way, the target type variable can be accurately searched in an automatic way so as to remind a user of modifying the target type variable, and the problems of omission, misjudgment, long time consumption and the like in the process of manually checking codes can be solved.
Referring to fig. 5, fig. 5 is a schematic structural diagram of an embodiment of an electronic device provided in the present application, where the electronic device 50 includes a memory 501 and a processor 502, the memory 501 is used to store a computer program, and the processor 502 is used to execute the computer program to implement the target type variable searching method according to any of the above embodiments, which is not described herein again.
Referring to fig. 6, fig. 6 is a schematic structural diagram of an embodiment of a computer-readable storage medium 60 provided in the present application, where the computer-readable storage medium is used to store a computer program 601, and the computer program 601 is used to implement the target type variable searching method according to any of the above embodiments when being executed by a processor, and details are not repeated here.
In summary, the target type variable searching method can realize searching the target type variable in an automatic manner, can avoid the problems of omission, misjudgment, long time consumption and the like when a code is manually checked, and can remind a user to modify the target type variable by using the searched target type variable.
The processor referred to in this application may be referred to as a Central Processing Unit (CPU), may be an integrated circuit chip, or may be a 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, a discrete gate or transistor logic device, or a discrete hardware component.
The storage medium used in the present application includes various media that can store program codes, such as a usb disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), or an optical disk.
The above description is only for the purpose of illustrating embodiments of the present application and is not intended to limit the scope of the present application, and all modifications of equivalent structures and equivalent processes, which are made by the contents of the specification and the drawings of the present application or are directly or indirectly applied to other related technical fields, are also included in the scope of the present application.

Claims (10)

1. A method for target type variable lookup, the method comprising:
analyzing the target file to obtain a corresponding syntax tree;
if the grammar tree has annotation nodes, acquiring target attributes of the annotation nodes;
if the target attribute is a preset attribute, acquiring all node information corresponding to the annotation node;
and determining the target type variable searched in the target file in response to the fact that any node information contains target information.
2. The method of claim 1, wherein before parsing the target file to obtain the corresponding syntax tree, further comprising:
acquiring an original folder; the original folder comprises a plurality of files;
determining the target file from the plurality of files.
3. The method of claim 2, wherein said determining the target document from the plurality of documents comprises:
acquiring file names of the files;
and determining the file with the file name meeting the preset requirement as the target file.
4. The method according to claim 1, wherein before obtaining the target attribute of the annotation node if the annotation node exists in the syntax tree, the method comprises:
and traversing the syntax tree and judging whether the annotation node exists in the syntax tree.
5. The method of claim 1, wherein the preset attribute is at least one of @ data, @ getter and @ setter.
6. The method according to claim 1, wherein the obtaining all node information corresponding to the annotation node comprises:
obtaining a statement of a body corresponding to the annotation node in the syntax tree;
adding the declaration of the body as node information to a file list;
and traversing the statement of the body in the file list, and acquiring corresponding node information from the statement of the body.
7. The method of claim 1, wherein the node information is at least one of a type declaration, a field declaration, and a basic type declaration, and the determining that a target type variable in the target file is found in response to any one of the node information including target information comprises:
and in response to any one of the type declaration, the field declaration and the basic type declaration not being empty, determining that the target type variable exists in an annotation node corresponding to the node information.
8. The method of claim 1, wherein the target type variable is a base type variable.
9. An electronic device, characterized in that the electronic device comprises a memory for storing a computer program and a processor for executing the computer program to implement the method according to any of claims 1-8.
10. A computer-readable storage medium, characterized in that the computer-readable storage medium is used to store a computer program, which, when being executed by a processor, is used to carry out the method according to any one of claims 1-8.
CN202211443213.2A 2022-11-16 2022-11-16 Target type variable searching method, electronic equipment and storage medium Pending CN115756487A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211443213.2A CN115756487A (en) 2022-11-16 2022-11-16 Target type variable searching method, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211443213.2A CN115756487A (en) 2022-11-16 2022-11-16 Target type variable searching method, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
CN115756487A true CN115756487A (en) 2023-03-07

Family

ID=85373006

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211443213.2A Pending CN115756487A (en) 2022-11-16 2022-11-16 Target type variable searching method, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN115756487A (en)

Similar Documents

Publication Publication Date Title
US9852133B2 (en) Scalable, schemaless document query model
US10324909B2 (en) Omega names: name generation and derivation utilizing nested three or more attributes
US7836100B2 (en) Calculating and storing data structures including using calculated columns associated with a database system
US7412436B2 (en) System and interface for manipulating a database
US7162469B2 (en) Querying an object for properties
US7096216B2 (en) Performing operations on a set of objects in a database system
US7082433B2 (en) Translation of object queries involving inheritence
US7478087B2 (en) Translation of object queries involving inheritence
CN109933571B (en) Database design document generation method, device and computer readable storage medium
US7359912B2 (en) Result set formatting and processing
US9043757B2 (en) Identifying differences between source codes of different versions of a software when each source code is organized using incorporated files
US7254808B2 (en) Method for specifying and parsing expressions
CN106951231B (en) Computer software development method and device
US10552127B2 (en) Method and system for developing relation-context specific software applications
US20080295065A1 (en) System and method for resolving interdependencies between heterogeneous artifacts in a software system
JP2012529711A (en) Software extension analysis method and system
CN114138748A (en) Database mapping file generation method, device, equipment and storage medium
CN112835638A (en) Configuration information management method and device based on embedded application program
CN115756487A (en) Target type variable searching method, electronic equipment and storage medium
CN112596719A (en) Method and system for generating front-end and back-end codes
CN112883044A (en) Data processing method and device for database and computer readable medium
CN114691110A (en) Database statement generation method and device and electronic equipment
CN113704289A (en) Method, system, equipment and medium based on DBIO interface
CN111177240A (en) API (application program interface) data importing method and system and Mock data generating method
CN117372182A (en) Insurance management system based on rapid development persistent layer code auxiliary method

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