Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Static code analyzers, detect code patterns

I have a number of occurrences in a new code base where there are a sequence of method calls like,

object o = something.foo();
bar(o);
something.foobar();

in consecutive lines. I would like to find / count the total number of such a sequence in my code where the name of object "something" could be different, but I want treated the same.

I want to pull these out as a method and see all the locations where this needs to be refactored. How do I go about doing something like this?

like image 630
user2163185 Avatar asked Sep 23 '13 04:09

user2163185


People also ask

What can static analysis not find?

There are things that static analysis can't identify. For instance, static analysis can't detect whether software requirements have been fulfilled or how a function will execute. You'll need dynamic testing for that. That's why static analysis and dynamic testing are complementary.

Which tool is used for static code analysis?

SonarQube is the popular static analysis tool for continuously inspecting the code quality and security of your codebases and guiding development teams during code reviews. SonarQube is used for automated code review with CI/CD Integration.

Can you identify security vulnerabilities with static code analyzers?

Conclusions: Despite recent advances in methods for static code analysis, the state-of-the-art tools are not very effective in detecting security vulnerabilities.

What is static code analysis code vulnerabilities?

Static code analysis, also known as Static Application Security Testing (SAST), is a vulnerability scanning methodology designed to work on source code rather than a compiled executable.


1 Answers

Intellij IDEA (incl. the free community version) does duplicated code detection & replacement.

If you carve out one of such occurrence into a method using its refactoring feature, it goes through the code base and asks you if you want to replace it in other places, too.

like image 140
Enno Shioji Avatar answered Oct 12 '22 23:10

Enno Shioji