Re: Cleaning up import statements
Correction: Perl script. #!/usr/bin/perl $verbose = 0; $classdir = ""; $getclassdir = 0; fileloop: foreach $i (@ARGV) { if ($i eq "-v"){ $verbose = 1; next; } if ($i eq "-d"){ $getclassdir = 1; next; } if ($getclassdir){ $classdir = $i; if ($verbose){ print "Look for classes in: $classdir\n"; } $getclassdir = 0; next; } if ($verbose){ print STDOUT "$i\n"; } my $imports = ""; my $classfile; if ($i =~ /^(.*)\.java$/) { $classfile = $1 . ".class"; if ($classdir ne ""){ print "oldclass: $classfile\n" if ($verbose); $classfile =~ s/^(.*\/)?([^\/]*\.class)/$classdir\/$2/; print "newclass: $classfile\n" if ($verbose); } } else { print STDERR "$i is not a java file... skipping\n"; next; } print "classfile: $classfile\n" if ($verbose); if (! -f $classfile){ print STDERR "$i must be compiled first... skipping\n"; next; } open(JAD, "jad -p -pi999 $classfile 2>&1 |") || die "Can't run jad: $!\n"; my $fucked = 0; while (){ if (/^import /){ $imports .= $_; } if (/JavaClassFileParseException/){ $fucked = 1; print STDERR $_; last; } } close JAD || die "Error running jad: see jad error above: $!\n"; if ($fucked){ print STDERR "jad error... skipping\n"; next; } unlink("$i.prejiffy"); rename($i, "$i.prejiffy") || die "Can't rename original file $i: $!\n"; open(FILEOUT, ">$i") || die "Can't open $i for writing: $!\n"; open(FILEIN, "<$i.prejiffy") || die "Can't open $i.prejiffy for reading: $!\n"; while (){ if (/^import /){ print FILEOUT $imports; $imports = ""; } else { print FILEOUT; } } close FILEOUT; close FILEIN; }
RE: Cleaning up import statements
> You might consider one of the pure java decompilers, such as > BCEL http://jakarta.apache.org/bcel/manual.html > or jode http://sourceforge.net/projects/jode/, > or ClassFile http://home.earthlink.net/~shvets/. > These could even be called from the BeanShell. When I wrote it, I wasn't considering how it might work in the JDE. A pure java decompiler would be OK if the beanshell is already going, but for running over 100 class/source files, there is no way you are going to beat my script with jad for speed and jad is far and away the best decompiler that I have used. I use the script to run over many source files at once - especially looking at other peoples code, I find it much easier to understand if I can see the package context of the referenced classes. Matt IMPORTANT NOTICE: This e-mail and any attachment to it is intended only to be read or used by the named addressee. It is confidential and may contain legally privileged information. No confidentiality or privilege is waived or lost by any mistaken transmission to you. If you receive this e-mail in error, please immediately delete it from your system and notify the sender. You must not disclose, copy or use any part of this e-mail if you are not the intended recipient. The RTA is not responsible for any unauthorised alterations to this e-mail or attachment to it.
RE: Cleaning up import statements
You might consider one of the pure java decompilers, such as BCEL http://jakarta.apache.org/bcel/manual.html or jode http://sourceforge.net/projects/jode/, or ClassFile http://home.earthlink.net/~shvets/. These could even be called from the BeanShell. > -Original Message- > From: James Sinnamon [mailto:[EMAIL PROTECTED]] > Sent: Monday, April 08, 2002 8:02 PM > To: [EMAIL PROTECTED]; WATSON Matt; [EMAIL PROTECTED] > Subject: Re: Cleaning up import statements > > > Matt, > > On Tue, 9 Apr 2002 10:50, WATSON Matt wrote: > > Not jde related, but I wrote a shell script to wrap jad which would > > decompile your class files, extract all the import > statements it makes and > > replace the imports in your source with the ones jad comes > up with. Using > > the right jad options, this allows you to have a full list > of all the > > classes you are using with no "import XXX.*;"s - I > personally hate them. > > If anyone's interested, I'll dig it out from home and post it here. > > > > Could I see your shell script? Either directly or > through the jde list. BTW, where do I find jad? Can't get to > http://kpdus.tripod.com/jad.html at the moment. > > Thank you. > > regards, > > James >
Re: Cleaning up import statements
Matt, On Tue, 9 Apr 2002 10:50, WATSON Matt wrote: > Not jde related, but I wrote a shell script to wrap jad which would > decompile your class files, extract all the import statements it makes and > replace the imports in your source with the ones jad comes up with. Using > the right jad options, this allows you to have a full list of all the > classes you are using with no "import XXX.*;"s - I personally hate them. > If anyone's interested, I'll dig it out from home and post it here. > Could I see your shell script? Either directly or through the jde list. BTW, where do I find jad? Can't get to http://kpdus.tripod.com/jad.html at the moment. Thank you. regards, James
RE: Cleaning up import statements
Not jde related, but I wrote a shell script to wrap jad which would decompile your class files, extract all the import statements it makes and replace the imports in your source with the ones jad comes up with. Using the right jad options, this allows you to have a full list of all the classes you are using with no "import XXX.*;"s - I personally hate them. If anyone's interested, I'll dig it out from home and post it here. Matt IMPORTANT NOTICE: This e-mail and any attachment to it is intended only to be read or used by the named addressee. It is confidential and may contain legally privileged information. No confidentiality or privilege is waived or lost by any mistaken transmission to you. If you receive this e-mail in error, please immediately delete it from your system and notify the sender. You must not disclose, copy or use any part of this e-mail if you are not the intended recipient. The RTA is not responsible for any unauthorised alterations to this e-mail or attachment to it.