1 package org.pojomatic.internal; 2 3 import org.objectweb.asm.Label; 4 import org.objectweb.asm.MethodVisitor; 5 import org.objectweb.asm.Opcodes; 6 import org.objectweb.asm.Type; 7 8 class LocalVariable { 9 private final String name; 10 private final String signature; 11 private Label scopeStart; 12 private Label scopeEnd; 13 private final int position; 14 private final Type type; 15 16 public LocalVariable(String name, Class<?> type, String signature, int position) { 17 super(); 18 this.name = name; 19 this.type = Type.getType(Type.getDescriptor(type)); 20 this.signature = signature; 21 this.position = position; 22 } 23 24 public LocalVariable(String name, String typeDescriptor, String signature, int position) { 25 super(); 26 this.name = name; 27 this.type = Type.getType(typeDescriptor); 28 this.signature = signature; 29 this.position = position; 30 } 31 32 public LocalVariable withScope(Label start, Label end) { 33 if (this.scopeStart != null) { 34 throw new IllegalStateException("scopeStart already set"); 35 } 36 if (this.scopeEnd != null) { 37 throw new IllegalStateException("scopeEnd already set"); 38 } 39 this.scopeStart = start; 40 this.scopeEnd = end; 41 return this; 42 } 43 44 public void acceptLocalVariable(MethodVisitor mv) { 45 if (scopeStart == null) { 46 throw new IllegalStateException("scopeStart not set"); 47 } 48 if (scopeEnd == null) { 49 throw new IllegalStateException("scopeEnd not set"); 50 } 51 mv.visitLocalVariable(name, type.getDescriptor(), signature, scopeStart, scopeEnd, position); 52 } 53 54 public void acceptStore(MethodVisitor mv) { 55 mv.visitVarInsn(type.getOpcode(Opcodes.ISTORE), position); 56 } 57 58 public void acceptLoad(MethodVisitor mv) { 59 mv.visitVarInsn(type.getOpcode(Opcodes.ILOAD), position); 60 } 61 }