Examples of FakeMethodVisitor


Examples of org.springsource.loaded.test.infra.FakeMethodVisitor

  /**
   * Check the sequence of instructions created for a cast and unbox for all primitives
   */
  @Test
  public void testUnboxing() {
    FakeMethodVisitor fmv = new FakeMethodVisitor();
    // First variant checks passing string rather than just one char
    Utils.insertUnboxInsnsIfNecessary(fmv, "F", true);
    assertEquals("visitTypeInsn(CHECKCAST,java/lang/Float) visitMethodInsn(INVOKEVIRTUAL,java/lang/Float,floatValue,()F)",
        fmv.getEvents());
    fmv.clearEvents();
    Utils.insertUnboxInsns(fmv, 'F', true);
    assertEquals("visitTypeInsn(CHECKCAST,java/lang/Float) visitMethodInsn(INVOKEVIRTUAL,java/lang/Float,floatValue,()F)",
        fmv.getEvents());
    fmv.clearEvents();
    Utils.insertUnboxInsns(fmv, 'Z', true);
    assertEquals(
        "visitTypeInsn(CHECKCAST,java/lang/Boolean) visitMethodInsn(INVOKEVIRTUAL,java/lang/Boolean,booleanValue,()Z)",
        fmv.getEvents());
    fmv.clearEvents();
    Utils.insertUnboxInsns(fmv, 'S', true);
    assertEquals("visitTypeInsn(CHECKCAST,java/lang/Short) visitMethodInsn(INVOKEVIRTUAL,java/lang/Short,shortValue,()S)",
        fmv.getEvents());
    fmv.clearEvents();
    Utils.insertUnboxInsns(fmv, 'J', true);
    assertEquals("visitTypeInsn(CHECKCAST,java/lang/Long) visitMethodInsn(INVOKEVIRTUAL,java/lang/Long,longValue,()J)",
        fmv.getEvents());
    fmv.clearEvents();
    Utils.insertUnboxInsns(fmv, 'D', true);
    assertEquals("visitTypeInsn(CHECKCAST,java/lang/Double) visitMethodInsn(INVOKEVIRTUAL,java/lang/Double,doubleValue,()D)",
        fmv.getEvents());
    fmv.clearEvents();
    Utils.insertUnboxInsns(fmv, 'C', true);
    assertEquals(
        "visitTypeInsn(CHECKCAST,java/lang/Character) visitMethodInsn(INVOKEVIRTUAL,java/lang/Character,charValue,()C)",
        fmv.getEvents());
    fmv.clearEvents();
    Utils.insertUnboxInsns(fmv, 'B', true);
    assertEquals("visitTypeInsn(CHECKCAST,java/lang/Byte) visitMethodInsn(INVOKEVIRTUAL,java/lang/Byte,byteValue,()B)",
        fmv.getEvents());
    fmv.clearEvents();
    Utils.insertUnboxInsns(fmv, 'I', true);
    assertEquals("visitTypeInsn(CHECKCAST,java/lang/Integer) visitMethodInsn(INVOKEVIRTUAL,java/lang/Integer,intValue,()I)",
        fmv.getEvents());
    fmv.clearEvents();

    Utils.insertUnboxInsnsIfNecessary(fmv, "Rubbish", true);
    // should be a nop as nothing to do
    assertEquals(0, fmv.getEvents().length());
    fmv.clearEvents();

    try {
      Utils.insertUnboxInsns(fmv, '[', true);
      Assert.fail("Should have blown up due to invalid primitive being passed in");
    } catch (IllegalArgumentException iae) {
View Full Code Here

Examples of org.springsource.loaded.test.infra.FakeMethodVisitor

  /**
   * Check the sequence of instructions created for an unbox (no cast)
   */
  @Test
  public void testUnboxingNoCast() {
    FakeMethodVisitor fmv = new FakeMethodVisitor();
    Utils.insertUnboxInsns(fmv, 'F', false);
    assertEquals("visitMethodInsn(INVOKEVIRTUAL,java/lang/Float,floatValue,()F)", fmv.getEvents());
    fmv.clearEvents();
    Utils.insertUnboxInsns(fmv, 'Z', false);
    assertEquals("visitMethodInsn(INVOKEVIRTUAL,java/lang/Boolean,booleanValue,()Z)", fmv.getEvents());
    fmv.clearEvents();
    Utils.insertUnboxInsns(fmv, 'S', false);
    assertEquals("visitMethodInsn(INVOKEVIRTUAL,java/lang/Short,shortValue,()S)", fmv.getEvents());
    fmv.clearEvents();
    Utils.insertUnboxInsns(fmv, 'J', false);
    assertEquals("visitMethodInsn(INVOKEVIRTUAL,java/lang/Long,longValue,()J)", fmv.getEvents());
    fmv.clearEvents();
    Utils.insertUnboxInsns(fmv, 'D', false);
    assertEquals("visitMethodInsn(INVOKEVIRTUAL,java/lang/Double,doubleValue,()D)", fmv.getEvents());
    fmv.clearEvents();
    Utils.insertUnboxInsns(fmv, 'C', false);
    assertEquals("visitMethodInsn(INVOKEVIRTUAL,java/lang/Character,charValue,()C)", fmv.getEvents());
    fmv.clearEvents();
    Utils.insertUnboxInsns(fmv, 'B', false);
    assertEquals("visitMethodInsn(INVOKEVIRTUAL,java/lang/Byte,byteValue,()B)", fmv.getEvents());
    fmv.clearEvents();
    Utils.insertUnboxInsns(fmv, 'I', false);
    assertEquals("visitMethodInsn(INVOKEVIRTUAL,java/lang/Integer,intValue,()I)", fmv.getEvents());
    fmv.clearEvents();
  }
View Full Code Here

Examples of org.springsource.loaded.test.infra.FakeMethodVisitor

  /**
   * Check the sequence of instructions created for an unbox (no cast)
   */
  @Test
  public void testBoxing() {
    FakeMethodVisitor fmv = new FakeMethodVisitor();
    Utils.insertBoxInsns(fmv, 'F');
    assertEquals("visitMethodInsn(INVOKESTATIC,java/lang/Float,valueOf,(F)Ljava/lang/Float;)", fmv.getEvents());
    fmv.clearEvents();
    Utils.insertBoxInsns(fmv, 'Z');
    assertEquals("visitMethodInsn(INVOKESTATIC,java/lang/Boolean,valueOf,(Z)Ljava/lang/Boolean;)", fmv.getEvents());
    fmv.clearEvents();
    Utils.insertBoxInsns(fmv, 'S');
    assertEquals("visitMethodInsn(INVOKESTATIC,java/lang/Short,valueOf,(S)Ljava/lang/Short;)", fmv.getEvents());
    fmv.clearEvents();
    Utils.insertBoxInsns(fmv, 'J');
    assertEquals("visitMethodInsn(INVOKESTATIC,java/lang/Long,valueOf,(J)Ljava/lang/Long;)", fmv.getEvents());
    fmv.clearEvents();
    Utils.insertBoxInsns(fmv, 'D');
    assertEquals("visitMethodInsn(INVOKESTATIC,java/lang/Double,valueOf,(D)Ljava/lang/Double;)", fmv.getEvents());
    fmv.clearEvents();
    Utils.insertBoxInsns(fmv, 'C');
    assertEquals("visitMethodInsn(INVOKESTATIC,java/lang/Character,valueOf,(C)Ljava/lang/Character;)", fmv.getEvents());
    fmv.clearEvents();
    Utils.insertBoxInsns(fmv, 'B');
    assertEquals("visitMethodInsn(INVOKESTATIC,java/lang/Byte,valueOf,(B)Ljava/lang/Byte;)", fmv.getEvents());
    fmv.clearEvents();
    Utils.insertBoxInsns(fmv, 'I');
    assertEquals("visitMethodInsn(INVOKESTATIC,java/lang/Integer,valueOf,(I)Ljava/lang/Integer;)", fmv.getEvents());
    fmv.clearEvents();
  }
View Full Code Here

Examples of org.springsource.loaded.test.infra.FakeMethodVisitor

    fmv.clearEvents();
  }

  @Test
  public void loads() {
    FakeMethodVisitor fmv = new FakeMethodVisitor();
    Utils.createLoadsBasedOnDescriptor(fmv, "(Ljava/lang/String;)V", 0);
    assertEquals("visitVarInsn(ALOAD,0)", fmv.getEvents());
    fmv.clearEvents();
    Utils.createLoadsBasedOnDescriptor(fmv, "(B)V", 0);
    assertEquals("visitVarInsn(ILOAD,0)", fmv.getEvents());
    fmv.clearEvents();
    Utils.createLoadsBasedOnDescriptor(fmv, "(C)V", 0);
    assertEquals("visitVarInsn(ILOAD,0)", fmv.getEvents());
    fmv.clearEvents();
    Utils.createLoadsBasedOnDescriptor(fmv, "(D)V", 0);
    assertEquals("visitVarInsn(DLOAD,0)", fmv.getEvents());
    fmv.clearEvents();
    Utils.createLoadsBasedOnDescriptor(fmv, "(Z)V", 0);
    assertEquals("visitVarInsn(ILOAD,0)", fmv.getEvents());
    fmv.clearEvents();
    Utils.createLoadsBasedOnDescriptor(fmv, "(J)V", 0);
    assertEquals("visitVarInsn(LLOAD,0)", fmv.getEvents());
    fmv.clearEvents();
    Utils.createLoadsBasedOnDescriptor(fmv, "(F)V", 0);
    assertEquals("visitVarInsn(FLOAD,0)", fmv.getEvents());
    fmv.clearEvents();
    Utils.createLoadsBasedOnDescriptor(fmv, "(S)V", 0);
    assertEquals("visitVarInsn(ILOAD,0)", fmv.getEvents());
    fmv.clearEvents();
    Utils.createLoadsBasedOnDescriptor(fmv, "(I)V", 0);
    assertEquals("visitVarInsn(ILOAD,0)", fmv.getEvents());
    fmv.clearEvents();
    Utils.createLoadsBasedOnDescriptor(fmv, "([[S)V", 0);
    assertEquals("visitVarInsn(ALOAD,0)", fmv.getEvents());
    fmv.clearEvents();
    Utils.createLoadsBasedOnDescriptor(fmv, "([[Ljava/lang/String;)V", 0);
    assertEquals("visitVarInsn(ALOAD,0)", fmv.getEvents());
  }
View Full Code Here

Examples of org.springsource.loaded.test.infra.FakeMethodVisitor

    assertEquals("visitVarInsn(ALOAD,0)", fmv.getEvents());
  }

  @Test
  public void loads2() {
    FakeMethodVisitor fmv = new FakeMethodVisitor();
    Utils.createLoadsBasedOnDescriptor(fmv, "(BCDS)V", 0);
    assertEquals("visitVarInsn(ILOAD,0) visitVarInsn(ILOAD,1) visitVarInsn(DLOAD,2) visitVarInsn(ILOAD,4)", fmv.getEvents());
    fmv.clearEvents();
    Utils.createLoadsBasedOnDescriptor(fmv, "(Ljava/lang/String;J[I)V", 0);
    assertEquals("visitVarInsn(ALOAD,0) visitVarInsn(LLOAD,1) visitVarInsn(ALOAD,3)", fmv.getEvents());
    fmv.clearEvents();
    Utils.createLoadsBasedOnDescriptor(fmv, "(Ljava/lang/String;J[I)V", 4);
    assertEquals("visitVarInsn(ALOAD,4) visitVarInsn(LLOAD,5) visitVarInsn(ALOAD,7)", fmv.getEvents());
    fmv.clearEvents();
  }
View Full Code Here

Examples of org.springsource.loaded.test.infra.FakeMethodVisitor

    fmv.clearEvents();
  }

  @Test
  public void generateInstructionsToUnpackArrayAccordingToDescriptor() {
    FakeMethodVisitor fmv = new FakeMethodVisitor();
    Utils.generateInstructionsToUnpackArrayAccordingToDescriptor(fmv, "(Ljava/lang/String;)V", 1);
    assertEquals("visitVarInsn(ALOAD,1) visitLdcInsn(0) visitInsn(AALOAD) visitTypeInsn(CHECKCAST,java/lang/String)",
        fmv.getEvents());
    fmv.clearEvents();
    Utils.generateInstructionsToUnpackArrayAccordingToDescriptor(fmv, "(I)V", 1);
    assertEquals(
        "visitVarInsn(ALOAD,1) visitLdcInsn(0) visitInsn(AALOAD) visitTypeInsn(CHECKCAST,java/lang/Integer) visitMethodInsn(INVOKEVIRTUAL,java/lang/Integer,intValue,()I)",
        fmv.getEvents());
    fmv.clearEvents();
    Utils.generateInstructionsToUnpackArrayAccordingToDescriptor(fmv, "(Ljava/lang/String;Ljava/lang/Integer;)V", 2);
    assertEquals(
        "visitVarInsn(ALOAD,2) visitLdcInsn(0) visitInsn(AALOAD) visitTypeInsn(CHECKCAST,java/lang/String) visitVarInsn(ALOAD,2) visitLdcInsn(1) visitInsn(AALOAD) visitTypeInsn(CHECKCAST,java/lang/Integer)",
        fmv.getEvents());
    fmv.clearEvents();
    Utils.generateInstructionsToUnpackArrayAccordingToDescriptor(fmv, "([Ljava/lang/String;)V", 2);
    assertEquals("visitVarInsn(ALOAD,2) visitLdcInsn(0) visitInsn(AALOAD) visitTypeInsn(CHECKCAST,[Ljava/lang/String;)",
        fmv.getEvents());
    fmv.clearEvents();
    Utils.generateInstructionsToUnpackArrayAccordingToDescriptor(fmv, "([[I)V", 2);
    assertEquals("visitVarInsn(ALOAD,2) visitLdcInsn(0) visitInsn(AALOAD) visitTypeInsn(CHECKCAST,[[I)", fmv.getEvents());
    fmv.clearEvents();
    try {
      Utils.generateInstructionsToUnpackArrayAccordingToDescriptor(fmv, "(Y)V", 1);
      fail();
    } catch (IllegalStateException ise) {
    }
View Full Code Here

Examples of org.springsource.loaded.test.infra.FakeMethodVisitor

  /**
   * Test the helper that adds the correct return instructions based on the descriptor in use.
   */
  @Test
  public void testReturning() {
    FakeMethodVisitor fmv = new FakeMethodVisitor();
    Utils.addCorrectReturnInstruction(fmv, ReturnType.ReturnTypeVoid, true);
    assertEquals("visitInsn(RETURN)", fmv.getEvents());
    fmv.clearEvents();
    Utils.addCorrectReturnInstruction(fmv, ReturnType.ReturnTypeFloat, true);
    assertEquals("visitInsn(FRETURN)", fmv.getEvents());
    fmv.clearEvents();
    Utils.addCorrectReturnInstruction(fmv, ReturnType.ReturnTypeBoolean, true);
    assertEquals("visitInsn(IRETURN)", fmv.getEvents());
    fmv.clearEvents();
    Utils.addCorrectReturnInstruction(fmv, ReturnType.ReturnTypeShort, true);
    assertEquals("visitInsn(IRETURN)", fmv.getEvents());
    fmv.clearEvents();
    Utils.addCorrectReturnInstruction(fmv, ReturnType.ReturnTypeLong, true);
    assertEquals("visitInsn(LRETURN)", fmv.getEvents());
    fmv.clearEvents();
    Utils.addCorrectReturnInstruction(fmv, ReturnType.ReturnTypeDouble, true);
    assertEquals("visitInsn(DRETURN)", fmv.getEvents());
    fmv.clearEvents();
    Utils.addCorrectReturnInstruction(fmv, ReturnType.ReturnTypeChar, true);
    assertEquals("visitInsn(IRETURN)", fmv.getEvents());
    fmv.clearEvents();
    Utils.addCorrectReturnInstruction(fmv, ReturnType.ReturnTypeByte, true);
    assertEquals("visitInsn(IRETURN)", fmv.getEvents());
    fmv.clearEvents();
    Utils.addCorrectReturnInstruction(fmv, ReturnType.ReturnTypeInt, true);
    assertEquals("visitInsn(IRETURN)", fmv.getEvents());
    fmv.clearEvents();
    Utils.addCorrectReturnInstruction(fmv, ReturnType.getReturnType("java/lang/String", ReturnType.Kind.REFERENCE), true);
    assertEquals("visitTypeInsn(CHECKCAST,java/lang/String) visitInsn(ARETURN)", fmv.getEvents());
    fmv.clearEvents();
    Utils.addCorrectReturnInstruction(fmv, ReturnType.getReturnType("[[I", ReturnType.Kind.ARRAY), true);
    assertEquals("visitTypeInsn(CHECKCAST,[[I) visitInsn(ARETURN)", fmv.getEvents());
    fmv.clearEvents();
    Utils.addCorrectReturnInstruction(fmv, ReturnType.getReturnType("[[Ljava/lang/String;", ReturnType.Kind.ARRAY), true);
    assertEquals("visitTypeInsn(CHECKCAST,[[Ljava/lang/String;) visitInsn(ARETURN)", fmv.getEvents());
    fmv.clearEvents();
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.