MethodInfo.java 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /**********************************************************************/
  2. /* Method Info class for j2cps */
  3. /* */
  4. /* (c) copyright QUT, John Gough 2000-2012, John Gough, 2012-2017 */
  5. /**********************************************************************/
  6. package j2cps;
  7. import java.io.DataInputStream;
  8. import java.io.IOException;
  9. public class MethodInfo extends MemberInfo {
  10. public TypeDesc[] parTypes;
  11. public TypeDesc retType;
  12. public String userName;
  13. public boolean deprecated = false;
  14. public int retTypeFixUp = 0;
  15. public int[] parFixUps;
  16. public boolean overridding = false;
  17. public boolean isInitProc = false;
  18. public boolean isCLInitProc = false;
  19. public MethodInfo(ConstantPool cp,DataInputStream stream,
  20. ClassDesc thisClass) throws IOException {
  21. super(cp,stream,thisClass);
  22. this.parTypes = TypeDesc.GetParTypes(signature);
  23. this.retType = TypeDesc.GetType(signature,signature.indexOf(')')+1);
  24. if (this.name.equals("<init>")) {
  25. this.userName = "Init";
  26. this.isInitProc = true;
  27. if (!ConstantPool.isStatic(accessFlags)) {
  28. this.accessFlags = (this.accessFlags + ConstantPool.ACC_STATIC);
  29. }
  30. if ((this.parTypes.length == 0) &&
  31. (!ConstantPool.isPrivate(this.accessFlags))) {
  32. thisClass.hasNoArgConstructor = true;
  33. }
  34. this.retType = thisClass;
  35. } else if (this.name.equals("<clinit>")) {
  36. this.userName="CLInit";
  37. this.isCLInitProc = true;
  38. } else {
  39. this.userName=this.name;
  40. }
  41. if (ClassDesc.VERBOSE) {
  42. int parNm = this.parTypes.length;
  43. System.out.printf("Method %s has %d %s",
  44. this.name, parNm, (parNm != 1 ?
  45. "parameters" : "parameter"));
  46. }
  47. if (this.isExported()) {
  48. for (TypeDesc parType : this.parTypes) {
  49. //
  50. // The package of this type must be placed on
  51. // this package's import list iff:
  52. // * the par type is public or protected AND
  53. // * the method's package is not CURRENT.
  54. //
  55. if (parType.parentPkg != thisClass.parentPkg) {
  56. parType.blame = this;
  57. thisClass.TryImport(parType);
  58. }
  59. }
  60. if (this.retType.parentPkg != thisClass.parentPkg) {
  61. this.retType.blame = this;
  62. thisClass.TryImport(this.retType);
  63. }
  64. }
  65. }
  66. public MethodInfo(ClassDesc thisClass,String name,String jName,int acc) {
  67. super(thisClass,acc,jName);
  68. this.userName = name;
  69. if (name.equals("<init>")) {
  70. if (userName == null) {
  71. this.userName = "Init";
  72. }
  73. this.isInitProc = true;
  74. }
  75. }
  76. @Override
  77. public String toString() {
  78. return ConstantPool.GetAccessString(this.accessFlags) + " " +
  79. this.name + " " + this.signature;
  80. }
  81. }