The Gluster Blog

Gluster blog stories provide high-level spotlights on our users all over the world

Find class method dependencies in 8 seconds


Scouring through large amounts of source code using just “grep” is soooo 1990.  With git, pipes, and scripting languages, you can combine the convenience of grep with simpler and more flexible parsing tools.   Here’s a couple of ways to find dependencies given a java class name, without having to load all your code into an IDE.


You want to know which classes reference a particular compilation unit in your code.
But more and you want to know which methods in those classes are making the references.

How to do it with class info only using grep + perl/python/ettc

A way to start is to run: 

git grep -l MyClassName | grep “.java” | perl -pe ‘s!.*/!!’

This will give all the matching classes.

How to do it with method specific information using “git -p”

Using git’s code parser, you can run

git grep -p MyClassName | grep java

This will return a several lines per match: One for the match, and another specifically for the method which CONTAINS the match.  You can parse out the methods by scanning one row above the match itself. 

Moral of the story

You don’t have to use sed for everything.  Instead, consider

1) Piping into python and perl which can do a wonderful job reading from standard in and stream editing a file.  

2) Better yet, git comes stock with programmer specific grep utilities that understand the semantics of common programming languages.

That is all 🙂


  • 06 Dec 2020
    Looking back at 2020 – with g...

    2020 has not been a year we would have been able to predict. With a worldwide pandemic and lives thrown out of gear, as we head into 2021, we are thankful that our community and project continued to receive new developers, users and make small gains. For that and a...

    Read more
  • 27 Apr 2020
    Update from the team

    It has been a while since we provided an update to the Gluster community. Across the world various nations, states and localities have put together sets of guidelines around shelter-in-place and quarantine. We request our community members to stay safe, to care for their loved ones, to continue to be...

    Read more
  • 03 Feb 2020
    Building a longer term focus for Gl...

    The initial rounds of conversation around the planning of content for release 8 has helped the project identify one key thing – the need to stagger out features and enhancements over multiple releases. Thus, while release 8 is unlikely to be feature heavy as previous releases, it will be the...

    Read more