Structural Search Question: One statement followed by any code not containing another statement.
I have a question related to Structural Search which I'm very new to.
I'm trying to eliminate a code problem which occurs where a resultset is assigned but not followed by a util class call to close it
The code should look like this:
good code example:
ResultSet rs;
rs = something;
any number of lines of code follow;
SomeUtilClass.close(rs);
bad code example:
ResultSet rs;
rs = something;
any number of lines of code follow;
// the statement "SomeUtilClass.close(rs);" is not contained within the scope of "rs"
I'm trying to write SSR to identify the bad code examples so I can fix them. I'm having trouble making a structural search which even describes the "good" code fragment because of the "any number of code lines".
I can write SSR to match this
rs = something;
SomeUtilClass.close(rs);
using the SSR pattern
$rs$ = $assignement$;
SomeUtilClass.close($rs$);
[where $rs$ has attributes "java expression type = ResultSet within type hierarchy"]
I am, however, unable to figure out how to express "any number of lines of code follows;". Furthermore I know how to express the negation of an entire statement of the form SomeUtilClass.close($rs$);
Is it possible to do either using SSR?
请先登录再写评论。