ClassFileAnalyzer (Can)
Home

 

Example: TestCanAnnotationDefault3

Test directive .annotation default

 

/* 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();
}

 

/* TestCanAnnotation2.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 TestCanAnnotation2 {
  
  enum Direction { NORTH, SOUTH, WEST, EAST };
  Direction value1();
  
  Class value2();
  Class<? extends Number>[] value3();
}

 

/* TestCanAnnotationDefault3.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 TestCanAnnotationDefault3 {
  
  TestCanAnnotation[] value1() default {
    @TestCanAnnotation(byteValue = 1, intValue = 4),
    @TestCanAnnotation(charValue = { 'a', 'b' }, booleanValue = { true }),
    @TestCanAnnotation(floatValue = 1.23f, stringValue = { "Hello", "World!" })
  };
   
  TestCanAnnotation2[] value2() default {
    @TestCanAnnotation2(value1 = TestCanAnnotation2.Direction.NORTH,
                          value2 = Object.class,
                          value3 = { Byte.class, Integer.class }),
    @TestCanAnnotation2(value1 = TestCanAnnotation2.Direction.SOUTH,
                          value2 = StringBuffer.class,
                          value3 = { Float.class, Double.class })  
  };
}

 

> javac TestCanAnnotation.java
> javac TestCanAnnotation2.java
> javac TestCanAnnotationDefault3.java

> java ClassFileAnalyzer TestCanAnnotation.class
> java ClassFileAnalyzer TestCanAnnotation2.class
> java ClassFileAnalyzer TestCanAnnotationDefault2.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

 

; TestCanAnnotation2.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 TestCanAnnotation2.java
.interface public abstract annotation TestCanAnnotation2
; 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
; one line
.inner class public static final enum Direction
        inner TestCanAnnotation2$Direction outer TestCanAnnotation2

.method public abstract value1()LTestCanAnnotation2$Direction;
.end method

.method public abstract value2()Ljava/lang/Class;
.end method

.method public abstract value3()[Ljava/lang/Class;
  .signature "()[Ljava/lang/Class<+Ljava/lang/Number;>;"
.end method

 

; TestCanAnnotationDefault3.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 TestCanAnnotationDefault3.java
.interface public abstract annotation TestCanAnnotationDefault3
; 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
; one line
.inner class public static final enum Direction
        inner TestCanAnnotation2$Direction outer TestCanAnnotation2

.method public abstract value1()[LTestCanAnnotation;
  .annotation default
    [@ LTestCanAnnotation; = .annotation
    byteValue B = 1
    intValue [I = 4
    .end annotation
    .annotation
    charValue [C = 97 98
    booleanValue [Z = 1
    .end annotation
    .annotation
    floatValue F = 1.23
    stringValue [s = "Hello" "World!"
    .end annotation
    .end annotation
.end method

.method public abstract value2()[LTestCanAnnotation2;
  .annotation default
    [@ LTestCanAnnotation2; = .annotation
    value1 e LTestCanAnnotation2$Direction; = NORTH
    value2 c = Ljava/lang/Object;
    value3 [c = Ljava/lang/Byte; Ljava/lang/Integer;
    .end annotation
    .annotation
    value1 e LTestCanAnnotation2$Direction; = SOUTH
    value2 c = Ljava/lang/StringBuffer;
    value3 [c = Ljava/lang/Float; Ljava/lang/Double;
    .end annotation
    .end annotation
.end method