1 29 30 package com.caucho.amber.field; 31 32 import com.caucho.bytecode.JClass; 33 import com.caucho.bytecode.JMethod; 34 import com.caucho.config.ConfigException; 35 import com.caucho.java.JavaWriter; 36 import com.caucho.util.L10N; 37 import com.caucho.util.Log; 38 39 import java.io.IOException ; 40 import java.util.logging.Logger ; 41 42 45 public class StubMethod { 46 private static final L10N L = new L10N(StubMethod.class); 47 protected static final Logger log = Log.open(StubMethod.class); 48 49 private JMethod _method; 50 51 public StubMethod(JMethod method) 52 { 53 _method = method; 54 } 55 56 59 public void init() 60 throws ConfigException 61 { 62 } 63 64 67 public void generate(JavaWriter out) 68 throws IOException 69 { 70 out.println(); 71 out.print("public "); 72 out.print(_method.getReturnType().getPrintName()); 73 out.print(" " + _method.getName() + "("); 74 75 JClass []paramTypes = _method.getParameterTypes(); 76 for (int i = 0; i < paramTypes.length; i++) { 77 if (i != 0) 78 out.print(", "); 79 80 out.print(paramTypes[i].getPrintName()); 81 out.print(" a" + i); 82 } 83 out.println(")"); 84 85 JClass []exnTypes = _method.getExceptionTypes(); 86 for (int i = 0; i < exnTypes.length; i++) { 87 if (i == 0) 88 out.print(" throws "); 89 else 90 out.print(", "); 91 92 out.print(exnTypes[i].getPrintName()); 93 } 94 if (exnTypes.length > 0) 95 out.println(); 96 97 out.println("{"); 98 JClass retType = _method.getReturnType(); 99 100 if ("void".equals(retType.getName())) { 101 } 102 else if (retType.isPrimitive()) 103 out.println(" return 0;"); 104 else 105 out.println(" return null;"); 106 107 out.println("}"); 108 } 109 } 110 | Popular Tags |