Package net.sourceforge.javautil.bytecode.api

Examples of net.sourceforge.javautil.bytecode.api.TypeDescriptor


    context.popStack();
    context.popStack();
  }

  public void box(BytecodeContextMethodASM context) {
    TypeDescriptor type = context.getStack(0);
     
    if (!type.isPrimitive()) throw new BytecodeException("Cannot box a non-primitive: " + type);
   
    //Type unboxed = getType(type);
    //context.getTarget().box(unboxed);
    context.pop(type);
    context.push(type.getBoxedType());
  }
View Full Code Here


    context.pop(type);
    context.push(type.getBoxedType());
  }
 
  public void unbox(BytecodeContextMethodASM context) {
    TypeDescriptor type = context.getStack(0);
   
    if (type.isPrimitive()) throw new BytecodeException("Cannot unbox a primitive: " + type);
   
    //Type boxed = getType(type);
    //context.getTarget().unbox(boxed);
    context.pop(type);
    context.push(type.getUnboxedType());
  }
View Full Code Here

    context.getTarget().visitVarInsn(type.getOpcode(ISTORE), idx);
    context.popStack();
  }
 
  public void loadLocal (BytecodeContextMethodASM context, int idx) {
    TypeDescriptor ts = context.getLocalVariable(idx).getType();
    Type type = getType(ts);
    context.getTarget().visitVarInsn(type.getOpcode(ILOAD), idx);
    context.push(ts);
  }
View Full Code Here

    for (IBytecodeReferenceable length : indices) length.load(context);
    if (indices.length == 1) {
      context.getTarget().visitTypeInsn(ANEWARRAY, type.getName());
      context.push(type.getArrayType(1));
    } else {
      TypeDescriptor atype = type.getArrayType(indices.length);
      context.getTarget().visitMultiANewArrayInsn(atype.getName(), indices.length);
      context.push(atype);
    }
  }
View Full Code Here

    context.getTarget().visitMethodInsn(opcode, method.getDeclaringType().getType().getName(), method.getName(), desc);
   
    if (opcode != Opcodes.INVOKESTATIC) context.popStack();
    for (int i=0; i<method.getDescriptor().getParameters().length; i++) context.popStack();
   
    TypeDescriptor rt = method.getDescriptor().getReturnType();
    if (rt != null && rt != TypeDescriptor.VOID) context.push(rt);
  }
View Full Code Here

   */
  protected void setValue (String name, Object value) {
    if (value == null) throw new IllegalArgumentException("Annotation values cannot be null");
    if (!this.methods.containsKey(name)) throw new IllegalArgumentException("No such annotation value named: " + name + " for " + type);
   
    TypeDescriptor type = this.methods.get(name).getDescriptor().getReturnType();
    TypeDescriptor pt = TypeDescriptor.getFor(value.getClass());
   
    if (type.compareTo(pt) != 0) {
      if (pt.isArray() && type.compareTo(pt.getComponentType()) == 0) {
        value = Array.get(value, 0);
      } else if (type.isArray() && pt.compareTo(type.getComponentType()) == 0) {
        Object array = Array.newInstance(value.getClass(), 1);
        Array.set(array, 0, value);
        value = array;
      } else {
        throw new IllegalArgumentException(value + " is not of the expected annotation value type: " + type);
View Full Code Here

    super(descriptor);
    this.value = value;
  }

  public void load(BytecodeContextMethod context) {
    TypeDescriptor top = this.value.getType();
   
    if (top.isPrimitive() && descriptor.compareTo( TypeDescriptor.getFor(Object.class) ) == 0) {

      context.invoke(context.getResolutionPool().resolve(top.getBoxedType().getClassName()), "valueOf", this.value);

    } else if (descriptor.isPrimitive() && !top.isPrimitive()) {
     
      String methodName = null;

      if (descriptor == TypeDescriptor.INTEGER) { methodName = "intValue"; }
      else if (descriptor == TypeDescriptor.LONG) { methodName = "longValue"; }
      else if (descriptor == TypeDescriptor.SHORT) { methodName = "shortValue"; }
      else if (descriptor == TypeDescriptor.CHAR) { methodName = "charValue"; }
      else if (descriptor == TypeDescriptor.DOUBLE) { methodName = "doubleValue"; }
      else if (descriptor == TypeDescriptor.FLOAT) { methodName = "floatValue"; }
      else if (descriptor == TypeDescriptor.BOOLEAN) { methodName = "booleanValue"; }
      else if (descriptor == TypeDescriptor.BYTE) { methodName = "byteValue"; }
     
      context.invoke(context.createCast(descriptor.getBoxedType(), value), methodName);
     
    } else if (top.isPrimitive() && descriptor.isPrimitive()) {
     
      if (top != descriptor) {
       
      } else {
        value.load(context);
View Full Code Here

  /**
   * @param type The type to pop
   * @return The popped type if verified, otherwise throws an exception
   */
  public TypeDescriptor pop (TypeDescriptor type) {
    TypeDescriptor removed = this.stack.remove(0);
    if (!removed.equals(type)) throw new BytecodeException("Type removed from stack inconsistent: " + type.toDescriptorString() + ", expected: " + removed.toDescriptorString());
    return removed;
  }
View Full Code Here

   * @param indices The indices for the matrix point to load
   */
  public void get (IBytecodeReferenceable array, IBytecodeReferenceable... indices) {
    array.load(this);
   
    TypeDescriptor type = array.getType();
   
    for (int i=0; i<indices.length; i++) {
      indices[i].load(this);
      writer.arrayLoad(this, type);
      type = type.getComponentType();
    }
  }
View Full Code Here

   * @param indices The set matrix point
   */
  public void setArrayIndexValue (IBytecodeReferenceable array, IBytecodeReferenceable value, IBytecodeReferenceable... indices) {
    array.load(this);
   
    TypeDescriptor type = array.getType();
   
    int load = indices.length - 1;
    for (int i=0; i<load; i++) {
      indices[i].load(this);
      writer.arrayLoad(this, type);
      type = type.getComponentType();
    }
   
    indices[load].load(this);
    if (value == null) loadNull(); else value.load(this);
    writer.arrayStore(this);
View Full Code Here

TOP

Related Classes of net.sourceforge.javautil.bytecode.api.TypeDescriptor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.