Skip to content

Instantly share code, notes, and snippets.

@artemave
Created April 20, 2012 09:09
Show Gist options
  • Save artemave/2427250 to your computer and use it in GitHub Desktop.
Save artemave/2427250 to your computer and use it in GitHub Desktop.
Filter out the code you don't need to read in java source code, to get better idea on sloc
#!/usr/bin/env perl
use strict;
use warnings;
use File::Basename;
for my $fname (@ARGV) {
open(my $file, $fname) or die $!;
my $in_constructor = 0;
my $fbase_name = basename($fname, '.java');
while(<$file>) {
if (/^[\s\t]*public *$fbase_name/) {
$in_constructor = 1;
}
if (/[\s\t]*}/) {
$in_constructor = 0;
}
next if $in_constructor; # assumes constructor only assigns fileds
next if /^[\s\t]*$/; # blank lines
next if /^[\s\t]*@/; # @Autowired, @Compenent, etc.
next if /^[\s\t]*import/; # imports
next if /^[\s\t]*(public|private|static|package)/; # fields and method declacations
print $_;
}
close $file;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment