ClassFileAnalyzer (Can)
Home

 

Example: TestCanRuntimeVisibleAnnotations2

Test directive .annotation visible

 

/* TestCanAnnotation.java */ 

import java.lang.annotation.*;

@Retention(value = RetentionPolicy.RUNTIME)
@Target(value = { ElementType.ANNOTATION_TYPE,
                  ElementType.CONSTRUCTOR,
                  ElementType.FIELD,
                  ElementType.LOCAL_VARIABLE,
                  ElementType.METHOD,
                  ElementType.PACKAGE,
                  ElementType.PARAMETER,
                  ElementType.TYPE 
                })

public @interface TestCanAnnotation {
  byte byteValue();
  char[] charValue();
  double doubleValue();
  float floatValue();
  int[] intValue();
  long longValue();
  short shortValue();
  boolean[] booleanValue();
  String[] stringValue();
}

 

/* TestCanRuntimeVisibleAnnotations2.java */ 


@TestCanAnnotation(byteValue = 1, 
                     charValue = { 'a', 'b', 'c' },
                     doubleValue = 1.23,
                     floatValue = 4.56f,
                     intValue = { 2, 3, 4 },
                     longValue = 5,
                     shortValue = 6,
                     booleanValue = { true },
                     stringValue = { "Hello World!" }
                    )
public class TestCanRuntimeVisibleAnnotations2 {
  
  
  @TestCanAnnotation(byteValue = 7, 
                       charValue = { 'd', 'e' },
                       doubleValue = 7.89,
                       floatValue = 10.1112f,
                       intValue = { 8 },
                       longValue = 9,
                       shortValue = 10,
                       booleanValue = { false, true },
                       stringValue = { "Java" }
                      )
  String str = "Hello";
  

  @TestCanAnnotation(byteValue = 11, 
                       charValue = { 'f' },
                       doubleValue = 13.1415,
                       floatValue = 16.1718f,
                       intValue = { 12 },
                       longValue = 13,
                       shortValue = 14,
                       booleanValue = { false },
                       stringValue = { "Hello", "Can!" }
                      )
  public void method1(String s) {
    System.out.println(str + s);
  }
  
  
  public static void main(String[] args) {
    TestCanRuntimeVisibleAnnotations2 tcrva = 
            new TestCanRuntimeVisibleAnnotations2(); 
    tcrva.method1(" Java!");
  }
}

 

> javac TestCanAnnotation.java
> javac TestCanRuntimeVisibleAnnotations2.java

> java ClassFileAnalyzer TestCanAnnotation.class
> java ClassFileAnalyzer TestCanRuntimeVisibleAnnotations2.class

 

; TestCanAnnotation.j

; Generated by ClassFileAnalyzer (Can)
; Analyzer and Disassembler for Java class files
; (Jasmin syntax 2, http://jasmin.sourceforge.net)
;
; ClassFileAnalyzer, version 0.7.0 


.bytecode 50.0
.source TestCanAnnotation.java
.interface public abstract annotation TestCanAnnotation
; Flag ACC_SUPER not set, see JVM spec

.super java/lang/Object
.implements java/lang/annotation/Annotation
.annotation visible Ljava/lang/annotation/Retention;
  value e Ljava/lang/annotation/RetentionPolicy; = RUNTIME
  .end annotation
.annotation visible Ljava/lang/annotation/Target;
  ; one line
  value [e Ljava/lang/annotation/ElementType; = ANNOTATION_TYPE CONSTRUCTOR
          FIELD LOCAL_VARIABLE METHOD PACKAGE PARAMETER TYPE
  .end annotation

.method public abstract byteValue()B
.end method

.method public abstract charValue()[C
.end method

.method public abstract doubleValue()D
.end method

.method public abstract floatValue()F
.end method

.method public abstract intValue()[I
.end method

.method public abstract longValue()J
.end method

.method public abstract shortValue()S
.end method

.method public abstract booleanValue()[Z
.end method

.method public abstract stringValue()[Ljava/lang/String;
.end method

 

; TestCanRuntimeVisibleAnnotations2.j

; Generated by ClassFileAnalyzer (Can)
; Analyzer and Disassembler for Java class files
; (Jasmin syntax 2, http://jasmin.sourceforge.net)
;
; ClassFileAnalyzer, version 0.7.0 


.bytecode 50.0
.source TestCanRuntimeVisibleAnnotations2.java
.class public TestCanRuntimeVisibleAnnotations2
.super java/lang/Object
.annotation visible LTestCanAnnotation;
  byteValue B = 1
  charValue [C = 97 98 99
  doubleValue D = 1.23
  floatValue F = 4.56
  intValue [I = 2 3 4
  longValue J = 5
  shortValue S = 6
  booleanValue [Z = 1
  stringValue [s = "Hello World!"
  .end annotation

.field str Ljava/lang/String;
  .annotation visible LTestCanAnnotation;
    byteValue B = 7
    charValue [C = 100 101
    doubleValue D = 7.89
    floatValue F = 10.1112
    intValue [I = 8
    longValue J = 9
    shortValue S = 10
    booleanValue [Z = 0 1
    stringValue [s = "Java"
    .end annotation
  .end field

.method public <init>()V
  .limit stack 2
  .limit locals 1
  .line 14
  0: aload_0
  1: invokespecial java/lang/Object/<init>()V
  .line 17
  4: aload_0
  5: ldc "Hello"
  7: putfield TestCanRuntimeVisibleAnnotations2/str Ljava/lang/String;
  10: return
.end method

.method public method1(Ljava/lang/String;)V
  .limit stack 3
  .limit locals 2
  .line 41
  0: getstatic java/lang/System/out Ljava/io/PrintStream;
  3: new java/lang/StringBuilder
  6: dup
  7: invokespecial java/lang/StringBuilder/<init>()V
  10: aload_0
  11: getfield TestCanRuntimeVisibleAnnotations2/str Ljava/lang/String;
  ; one line
  14: invokevirtual java/lang/StringBuilder/append(Ljava/lang/String;)
      Ljava/lang/StringBuilder;
  17: aload_1
  ; one line
  18: invokevirtual java/lang/StringBuilder/append(Ljava/lang/String;)
      Ljava/lang/StringBuilder;
  21: invokevirtual java/lang/StringBuilder/toString()Ljava/lang/String;
  24: invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V
  .line 42
  27: return
  .annotation visible LTestCanAnnotation;
    byteValue B = 11
    charValue [C = 102
    doubleValue D = 13.1415
    floatValue F = 16.1718
    intValue [I = 12
    longValue J = 13
    shortValue S = 14
    booleanValue [Z = 0
    stringValue [s = "Hello" "Can!"
    .end annotation
.end method

.method public static main([Ljava/lang/String;)V
  .limit stack 2
  .limit locals 2
  .line 46
  0: new TestCanRuntimeVisibleAnnotations2
  3: dup
  4: invokespecial TestCanRuntimeVisibleAnnotations2/<init>()V
  7: astore_1
  .line 48
  8: aload_1
  9: ldc " Java!"
  11: invokevirtual TestCanRuntimeVisibleAnnotations2/method1(Ljava/lang/String;)V
  .line 49
  14: return
.end method