You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

extractInterface.pl 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/usr/bin/perl
  2. ## Just a perl script to extract an interface from a class.
  3. ## It extract all public methods and copies the javadoc.
  4. ## - With the option --lazy it does the work for Lazy classes
  5. ## and generates the file with the 'Lazy' prefix
  6. ## - Without --lazy it generates a file with the 'I' prefix
  7. my ($i, $o, $lazy);
  8. foreach (@ARGV) {
  9. if (/^--input=(.*)$/) {
  10. $o = $i = $1;
  11. } elsif (/^--lazy$/) {
  12. $lazy = 1;
  13. }
  14. }
  15. my $iclass = $1 if ($i =~ /^.*\/([^\.]+)\.java$/);
  16. my $oclass = ($lazy ? "Lazy" : "I") . $iclass;
  17. $o =~ s/$iclass/$oclass/;
  18. my $c = 0;
  19. open(F, $i) || die $!;
  20. my ($in, $com, $ingq, $inclass, $inh, $head, $body, $inmeth, $meth, $dep) = (0, "", 0, 0, 1, "", "", 0, "", 0);
  21. my ($a, $b) = (0,0);
  22. while(<F>) {
  23. s/\r+//g;
  24. s/^\s+//g;
  25. s/^(\*.*)$/ $1/g;
  26. $inh = 0 if (/^\/\*\*/);
  27. $head .= $_ if ($inh);
  28. $inclass=1 if (!$in && $ingq && m/(^|\s+|\()(class|enum|new) /);
  29. if ($ingq && !$inclass) {
  30. $in = 1 if (/^\/\**\s*$/);
  31. $com = "" if (/^\/\**\s*$/);
  32. $dep = 1 if (/^\s*\@Deprecated/);
  33. next if /static/;
  34. next if /$iclass\s*\(/;
  35. $inmeth = 1 if (!$inmeth && !$in && /(public .*?\(.*)\s*$/);
  36. $dep = $inmeth = 0 if ($dep && $inmeth);
  37. $dep = $in = 0 if ($dep && $in);
  38. $meth .= $_ if ($inmeth);
  39. if ($inmeth && /\{/) {
  40. $meth =~ s/final\s+//g;
  41. $meth =~ s/public\s+//g;
  42. $meth =~ s/\{\s*//g;
  43. $meth =~ s/\s+$//g;
  44. if (!/$oclass/) {
  45. $meth =~ s/([^\(]*?)$iclass(\s+.*\()/$1$oclass<T>$2/g if ($lazy);
  46. $meth =~ s/\n/ /g;
  47. $meth =~ s/ +/ /g;
  48. $body .= "$com" if (!$in);
  49. $body .= " " .$meth . ";\n\n";
  50. }
  51. $com = "";
  52. $meth = "";
  53. $inmeth = 0;
  54. }
  55. $com .= " " . $_ if ($in);
  56. $in = 0 if (/^\s+\*\/\s*$/);
  57. }
  58. if ($inclass) {
  59. my $l = $_;
  60. $a ++ while($l =~ /(\{)/g);
  61. $b ++ while($l =~ /(\})/g);
  62. $inclass = $a = $b = 0 if ($a == $b);
  63. }
  64. $ingq = 1 if (!$ingq && m/(^|\s+)class /);
  65. #$body .= "$c $ingq $inclass $a $b\n";
  66. $c ++;
  67. }
  68. close(F);
  69. my $class = "/**\n * $oclass.\n * \@param <T>\n */\npublic interface $oclass";
  70. if ($lazy) {
  71. $class .= "<T> extends LazyBase<T>" if ($lazy);
  72. $head .= "import com.google.gwt.query.client.GQuery.*;\n";
  73. $head .= "import com.google.gwt.query.client.LazyBase;\n\n";
  74. }
  75. open(F, ">$o") || die $!;
  76. print F $head . $class . "{\n\n" . $body . "}\n";
  77. close(F);