1 30 package com.sleepycat.asm.signature; 31 32 38 public class SignatureWriter implements SignatureVisitor { 39 40 43 private final StringBuffer buf = new StringBuffer (); 44 45 48 private boolean hasFormals; 49 50 53 private boolean hasParameters; 54 55 61 private int argumentStack; 62 63 66 public SignatureWriter() { 67 } 68 69 73 public void visitFormalTypeParameter(String name) { 74 if (!hasFormals) { 75 hasFormals = true; 76 buf.append('<'); 77 } 78 buf.append(name); 79 buf.append(':'); 80 } 81 82 public SignatureVisitor visitClassBound() { 83 return this; 84 } 85 86 public SignatureVisitor visitInterfaceBound() { 87 buf.append(':'); 88 return this; 89 } 90 91 public SignatureVisitor visitSuperclass() { 92 endFormals(); 93 return this; 94 } 95 96 public SignatureVisitor visitInterface() { 97 return this; 98 } 99 100 public SignatureVisitor visitParameterType() { 101 endFormals(); 102 if (!hasParameters) { 103 hasParameters = true; 104 buf.append('('); 105 } 106 return this; 107 } 108 109 public SignatureVisitor visitReturnType() { 110 endFormals(); 111 if (!hasParameters) { 112 buf.append('('); 113 } 114 buf.append(')'); 115 return this; 116 } 117 118 public SignatureVisitor visitExceptionType() { 119 buf.append('^'); 120 return this; 121 } 122 123 public void visitBaseType(char descriptor) { 124 buf.append(descriptor); 125 } 126 127 public void visitTypeVariable(String name) { 128 buf.append('T'); 129 buf.append(name); 130 buf.append(';'); 131 } 132 133 public SignatureVisitor visitArrayType() { 134 buf.append('['); 135 return this; 136 } 137 138 public void visitClassType(String name) { 139 buf.append('L'); 140 buf.append(name); 141 argumentStack *= 2; 142 } 143 144 public void visitInnerClassType(String name) { 145 endArguments(); 146 buf.append('.'); 147 buf.append(name); 148 argumentStack *= 2; 149 } 150 151 public void visitTypeArgument() { 152 if (argumentStack % 2 == 0) { 153 ++argumentStack; 154 buf.append('<'); 155 } 156 buf.append('*'); 157 } 158 159 public SignatureVisitor visitTypeArgument(char wildcard) { 160 if (argumentStack % 2 == 0) { 161 ++argumentStack; 162 buf.append('<'); 163 } 164 if (wildcard != '=') { 165 buf.append(wildcard); 166 } 167 return this; 168 } 169 170 public void visitEnd() { 171 endArguments(); 172 buf.append(';'); 173 } 174 175 180 public String toString() { 181 return buf.toString(); 182 } 183 184 188 191 private void endFormals() { 192 if (hasFormals) { 193 hasFormals = false; 194 buf.append('>'); 195 } 196 } 197 198 201 private void endArguments() { 202 if (argumentStack % 2 == 1) { 203 buf.append('>'); 204 } 205 argumentStack /= 2; 206 } 207 } 208 | Popular Tags |