< prev index next >

src/java.base/share/classes/jdk/internal/org/objectweb/asm/util/TraceSignatureVisitor.java

Print this page




  53  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  54  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  55  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  56  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  57  * THE POSSIBILITY OF SUCH DAMAGE.
  58  */
  59 package jdk.internal.org.objectweb.asm.util;
  60 
  61 import jdk.internal.org.objectweb.asm.Opcodes;
  62 import jdk.internal.org.objectweb.asm.signature.SignatureVisitor;
  63 
  64 /**
  65  * A {@link SignatureVisitor} that prints a disassembled view of the signature
  66  * it visits.
  67  *
  68  * @author Eugene Kuleshov
  69  * @author Eric Bruneton
  70  */
  71 public final class TraceSignatureVisitor extends SignatureVisitor {
  72 
  73     private final StringBuffer declaration;
  74 
  75     private boolean isInterface;
  76 
  77     private boolean seenFormalParameter;
  78 
  79     private boolean seenInterfaceBound;
  80 
  81     private boolean seenParameter;
  82 
  83     private boolean seenInterface;
  84 
  85     private StringBuffer returnType;
  86 
  87     private StringBuffer exceptions;
  88 
  89     /**
  90      * Stack used to keep track of class types that have arguments. Each element
  91      * of this stack is a boolean encoded in one bit. The top of the stack is
  92      * the lowest order bit. Pushing false = *2, pushing true = *2+1, popping =
  93      * /2.
  94      */
  95     private int argumentStack;
  96 
  97     /**
  98      * Stack used to keep track of array class types. Each element of this stack
  99      * is a boolean encoded in one bit. The top of the stack is the lowest order
 100      * bit. Pushing false = *2, pushing true = *2+1, popping = /2.
 101      */
 102     private int arrayStack;
 103 
 104     private String separator = "";
 105 
 106     public TraceSignatureVisitor(final int access) {
 107         super(Opcodes.ASM5);
 108         isInterface = (access & Opcodes.ACC_INTERFACE) != 0;
 109         this.declaration = new StringBuffer();
 110     }
 111 
 112     private TraceSignatureVisitor(final StringBuffer buf) {
 113         super(Opcodes.ASM5);
 114         this.declaration = buf;
 115     }
 116 
 117     @Override
 118     public void visitFormalTypeParameter(final String name) {
 119         declaration.append(seenFormalParameter ? ", " : "<").append(name);
 120         seenFormalParameter = true;
 121         seenInterfaceBound = false;
 122     }
 123 
 124     @Override
 125     public SignatureVisitor visitClassBound() {
 126         separator = " extends ";
 127         startType();
 128         return this;
 129     }
 130 
 131     @Override
 132     public SignatureVisitor visitInterfaceBound() {


 158         endFormals();
 159         if (seenParameter) {
 160             declaration.append(", ");
 161         } else {
 162             seenParameter = true;
 163             declaration.append('(');
 164         }
 165         startType();
 166         return this;
 167     }
 168 
 169     @Override
 170     public SignatureVisitor visitReturnType() {
 171         endFormals();
 172         if (seenParameter) {
 173             seenParameter = false;
 174         } else {
 175             declaration.append('(');
 176         }
 177         declaration.append(')');
 178         returnType = new StringBuffer();
 179         return new TraceSignatureVisitor(returnType);
 180     }
 181 
 182     @Override
 183     public SignatureVisitor visitExceptionType() {
 184         if (exceptions == null) {
 185             exceptions = new StringBuffer();
 186         } else {
 187             exceptions.append(", ");
 188         }
 189         // startType();
 190         return new TraceSignatureVisitor(exceptions);
 191     }
 192 
 193     @Override
 194     public void visitBaseType(final char descriptor) {
 195         switch (descriptor) {
 196         case 'V':
 197             declaration.append("void");
 198             break;
 199         case 'B':
 200             declaration.append("byte");
 201             break;
 202         case 'J':
 203             declaration.append("long");
 204             break;
 205         case 'Z':




  53  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  54  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  55  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  56  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  57  * THE POSSIBILITY OF SUCH DAMAGE.
  58  */
  59 package jdk.internal.org.objectweb.asm.util;
  60 
  61 import jdk.internal.org.objectweb.asm.Opcodes;
  62 import jdk.internal.org.objectweb.asm.signature.SignatureVisitor;
  63 
  64 /**
  65  * A {@link SignatureVisitor} that prints a disassembled view of the signature
  66  * it visits.
  67  *
  68  * @author Eugene Kuleshov
  69  * @author Eric Bruneton
  70  */
  71 public final class TraceSignatureVisitor extends SignatureVisitor {
  72 
  73     private final StringBuilder declaration;
  74 
  75     private boolean isInterface;
  76 
  77     private boolean seenFormalParameter;
  78 
  79     private boolean seenInterfaceBound;
  80 
  81     private boolean seenParameter;
  82 
  83     private boolean seenInterface;
  84 
  85     private StringBuilder returnType;
  86 
  87     private StringBuilder exceptions;
  88 
  89     /**
  90      * Stack used to keep track of class types that have arguments. Each element
  91      * of this stack is a boolean encoded in one bit. The top of the stack is
  92      * the lowest order bit. Pushing false = *2, pushing true = *2+1, popping =
  93      * /2.
  94      */
  95     private int argumentStack;
  96 
  97     /**
  98      * Stack used to keep track of array class types. Each element of this stack
  99      * is a boolean encoded in one bit. The top of the stack is the lowest order
 100      * bit. Pushing false = *2, pushing true = *2+1, popping = /2.
 101      */
 102     private int arrayStack;
 103 
 104     private String separator = "";
 105 
 106     public TraceSignatureVisitor(final int access) {
 107         super(Opcodes.ASM5);
 108         isInterface = (access & Opcodes.ACC_INTERFACE) != 0;
 109         this.declaration = new StringBuilder();
 110     }
 111 
 112     private TraceSignatureVisitor(final StringBuilder buf) {
 113         super(Opcodes.ASM5);
 114         this.declaration = buf;
 115     }
 116 
 117     @Override
 118     public void visitFormalTypeParameter(final String name) {
 119         declaration.append(seenFormalParameter ? ", " : "<").append(name);
 120         seenFormalParameter = true;
 121         seenInterfaceBound = false;
 122     }
 123 
 124     @Override
 125     public SignatureVisitor visitClassBound() {
 126         separator = " extends ";
 127         startType();
 128         return this;
 129     }
 130 
 131     @Override
 132     public SignatureVisitor visitInterfaceBound() {


 158         endFormals();
 159         if (seenParameter) {
 160             declaration.append(", ");
 161         } else {
 162             seenParameter = true;
 163             declaration.append('(');
 164         }
 165         startType();
 166         return this;
 167     }
 168 
 169     @Override
 170     public SignatureVisitor visitReturnType() {
 171         endFormals();
 172         if (seenParameter) {
 173             seenParameter = false;
 174         } else {
 175             declaration.append('(');
 176         }
 177         declaration.append(')');
 178         returnType = new StringBuilder();
 179         return new TraceSignatureVisitor(returnType);
 180     }
 181 
 182     @Override
 183     public SignatureVisitor visitExceptionType() {
 184         if (exceptions == null) {
 185             exceptions = new StringBuilder();
 186         } else {
 187             exceptions.append(", ");
 188         }
 189         // startType();
 190         return new TraceSignatureVisitor(exceptions);
 191     }
 192 
 193     @Override
 194     public void visitBaseType(final char descriptor) {
 195         switch (descriptor) {
 196         case 'V':
 197             declaration.append("void");
 198             break;
 199         case 'B':
 200             declaration.append("byte");
 201             break;
 202         case 'J':
 203             declaration.append("long");
 204             break;
 205         case 'Z':


< prev index next >