• Nem Talált Eredményt

Finding Matching Source Code Elements in an AST Using Position Information

N/A
N/A
Protected

Academic year: 2022

Ossza meg "Finding Matching Source Code Elements in an AST Using Position Information"

Copied!
1
0
0

Teljes szövegt

(1)

Finding Matching Source Code Elements in an AST Using Position Information

Gábor Sz ˝oke

To decrease software maintenance cost software development companies use static source code analysis techniques. Static analysis tools are capable of finding potential bugs, anti- patterns, coding rule violations and they can enforce coding style standards. To achieve this the tools create a hierarchical representation of the source code calledAbstract Syntax Tree(AST).

In this structure each node of the tree denotes a construct occurring in the source code. The AST can be represented in various ways and most static analysis tools build their own AST representation, typically which fits them the best for their given purpose.

Sometimes it is necessary to create a mapping between two different ASTs, e.g. finding matching source code elements in an AST using just position information. We met this problem in a project where we developed a refactoring tool which was meant to be able to refactor coding issues based on source code position. In this study, we present an approach which addresses this problem. Our solution takes source code position and type information of a node from one AST and uses this information toreverse searchthe matching node on the other AST.

To make reverse searching possible, aspatial databaseis used, which is created by transforming the source code into geometric space. Line numbers and column positions from the AST are used to define areas. These areas are used to createR-trees, where area based reverse searching is possible.

findings Third-party bug detection tool

+

*

a 3

AST1 b

* Line:p5 Column:p38

Bugpindicated by source code

position

detection

SourcepCode

input input Refactoring tool

+

*

a 3

b

AST2

buildp spatialp

index R-Tree input

Reverse-

search *

Line:p5 Column:p38

Buggy sourcep codepelement input

output

output

To evaluate our approach we use the output of thePMD[1] source code analyzer tool and use its bug report’s position information as the source data and then we pick theColumbus[2]

AST as target AST to find the matching source code element in the syntax tree. We used this technique in a project, where the found element was used as input in an automated refactoring transformation on the target AST. The transformation modified the syntax tree in a way which fixed the bug reported by the PMD static analyzer tool. As the final step, the refactored version of the source code got generated from the target AST and developers could review the changes.

The evaluation showed that our approach can be adapted to a real-life scenario, and it can provide viable results. Our tool was used in a project where it assisted in more than 4,000 automated refactorings covering systems ranging from 200 to 2,500 kLOC.

References

[1] PMD website: https://pmd.github.io/

[2] Ferenc, Rudolf and Beszédes, Árpád and Tarkiainen, Mikko and Gyimóthy, Tibor,Columbus – Reverse Engineering Tool and Schema for C++, Proceedings of the 18th International Confer- ence on Software Maintenance (ICSM’02), pp. 172-181, 2002.

59

Hivatkozások

KAPCSOLÓDÓ DOKUMENTUMOK

After generating promo code and storing data, user is redirected to the company’s web page that shows more information of campaign and also the generated promo code.. With this

Bug reports can be used to identify the wrong and the previously fixed source code parts, thus the bugs can be characterized by static source code metrics or by other

(Instead, a few reference photos could also be taken and their information fused to provide better reference features for the matching.) Our task is to locate the label in an

We used software metrics, rule violations and code duplications to estimate the maintainability of RPG software systems and to reveal various source code issues.. As a validation of

When the node where the island can be found exchanges information with another node (according to the epidemic protocol of the DRM) the island checks if the peer node already has

The algorithms are tested on 402 130 image pairs from the 1DSfM dataset and they speed up the feature matching 17 times and pose esti- mation 5 times.. Source

This application can be used to search a big database for the source of a given image, but the same mechanism can also be used to display additional information to an image,

Since the source positions of the elements are known in the actual version, the algorithm can determine which source code elements (e.g. classes, methods) are affected by the