Skip to content

Instantly share code, notes, and snippets.

@jesperronn
Created January 21, 2014 10:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jesperronn/8537714 to your computer and use it in GitHub Desktop.
Save jesperronn/8537714 to your computer and use it in GitHub Desktop.
Duplicate java class finder Finds java classes with same name and counts occurrences
# Find all java classes in tree. (including auto-generated classes in 'target' folders:
find . -name "*.java" | xargs egrep -o "class [A-Z]\w+" | awk '{print $2}' | sort | uniq -c | sort -n | grep -v 1
# Use git (faster).
#Ignores any auto-generated classes since they are typically inside ignored 'target' folders
git grep --extended-regexp --no-index "class [A-Z]\w+" | egrep -o "class [A-Z]\w+" | awk '{print $2}' | sort | uniq -c | sort -n | grep -v 1
#example output:
find . -name "*.java" | xargs egrep -o "class [A-Z]\w+" | awk '{print $2}' | sort | uniq -c | sort -n | grep -v 1
6 HeightGroup
6 LengthGroup
6 MeasureGroup
6 Price
6 WeightGroup
7 Adapter1
8 SOAPExceptionBean
10 FaultMessage
12 Location
55 Factory
63 ObjectFactory
git grep --extended-regexp --no-index "class [A-Z]\w+" | egrep -o "class [A-Z]\w+" | awk '{print $2}' | sort | uniq -c | sort -n | grep -v 1
3 Main
3 UnitTestDataCreator
4 DataTypeConverter
6 Location
6 ObjectFactory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment