Added the "AnnotationTypes" example, which gives some examples of how to create and retrieve the various types of annotations (class, method, field, parameter)

git-svn-id: https://smali.googlecode.com/svn/trunk@67 55b6fa8a-2a1e-11de-a435-ffa8d773f76a
This commit is contained in:
JesusFreke@JesusFreke.com 2009-06-03 05:05:52 +00:00
parent e391894f1b
commit cf396faa1a
5 changed files with 153 additions and 0 deletions

View File

@ -0,0 +1,4 @@
.class public abstract interface annotation LClassAnnotation;
.super Ljava/lang/Object;
.implements Ljava/lang/annotation/Annotation;

View File

@ -0,0 +1,4 @@
.class public abstract interface annotation LFieldAnnotation;
.super Ljava/lang/Object;
.implements Ljava/lang/annotation/Annotation;

View File

@ -0,0 +1,138 @@
.class public LMain;
.super Ljava/lang/Object;
;expected output:
;@ClassAnnotation()
;@MethodAnnotation()
;@FieldAnnotation()
;@ParameterAnnotation()
.method public static main([Ljava/lang/String;)V
.registers 1
invoke-static {}, LMain;->testClassAnnotation()V
invoke-static {}, LMain;->testMethodAnnotation()V
invoke-static {}, LMain;->testFieldAnnotation()V
const-string v0, ""
invoke-static {v0}, LMain;->testParameterAnnotation(Ljava/lang/String;)V
return-void
.end method
.annotation runtime LClassAnnotation;
.end annotation
.method public static testClassAnnotation()V
.registers 3
sget-object v0, Ljava/lang/System;->out:Ljava/io/PrintStream;
const-class v1, LMain;
const-class v2, LClassAnnotation;
invoke-virtual {v1, v2}, Ljava/lang/Class;->getAnnotation(Ljava/lang/Class;)Ljava/lang/annotation/Annotation;
move-result-object v1
invoke-virtual {v0, v1}, Ljava/io/PrintStream;->println(Ljava/lang/Object;)V
return-void
.end method
.method public static testMethodAnnotation()V
.registers 4
.annotation runtime LMethodAnnotation;
.end annotation
sget-object v0, Ljava/lang/System;->out:Ljava/io/PrintStream;
const-class v1, LMain;
const-string v2, "testMethodAnnotation"
const/4 v3, 0
new-array v3, v3, [Ljava/lang/Class;
invoke-virtual {v1, v2, v3}, Ljava/lang/Class;->getMethod(Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Method;
move-result-object v1
const-class v2, LMethodAnnotation;
invoke-virtual {v1, v2}, Ljava/lang/reflect/Method;->getAnnotation(Ljava/lang/Class;)Ljava/lang/annotation/Annotation;
move-result-object v1
invoke-virtual {v0, v1}, Ljava/io/PrintStream;->println(Ljava/lang/Object;)V
return-void
.end method
.field public static fieldAnnotationTest:Ljava/lang/Object;
.annotation runtime LFieldAnnotation;
.end annotation
.end field
.method public static testFieldAnnotation()V
.registers 3
sget-object v0, Ljava/lang/System;->out:Ljava/io/PrintStream;
const-class v1, LMain;
const-string v2, "fieldAnnotationTest"
invoke-virtual {v1, v2}, Ljava/lang/Class;->getField(Ljava/lang/String;)Ljava/lang/reflect/Field;
move-result-object v1
const-class v2, LFieldAnnotation;
invoke-virtual {v1, v2}, Ljava/lang/reflect/Field;->getAnnotation(Ljava/lang/Class;)Ljava/lang/annotation/Annotation;
move-result-object v1
invoke-virtual {v0, v1}, Ljava/io/PrintStream;->println(Ljava/lang/Object;)V
return-void
.end method
.method public static testParameterAnnotation(Ljava/lang/String;)V
.registers 6
.parameter
.annotation runtime LParameterAnnotation;
.end annotation
.end parameter
sget-object v0, Ljava/lang/System;->out:Ljava/io/PrintStream;
const-class v1, LMain;
const-string v2, "testParameterAnnotation"
const/4 v3, 1
new-array v3, v3, [Ljava/lang/Class;
const-class v4, Ljava/lang/String;
const/4 v5, 0
aput-object v4, v3, v5
invoke-virtual {v1, v2, v3}, Ljava/lang/Class;->getMethod(Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Method;
move-result-object v1
invoke-virtual {v1}, Ljava/lang/reflect/Method;->getParameterAnnotations()[[Ljava/lang/annotation/Annotation;
move-result-object v1
aget-object v1, v1, v5
aget-object v1, v1, v5
invoke-virtual {v0, v1}, Ljava/io/PrintStream;->println(Ljava/lang/Object;)V
return-void
.end method

View File

@ -0,0 +1,4 @@
.class public abstract interface annotation LMethodAnnotation;
.super Ljava/lang/Object;
.implements Ljava/lang/annotation/Annotation;

View File

@ -0,0 +1,3 @@
.class public abstract interface annotation LParameterAnnotation;
.super Ljava/lang/Object;
.implements Ljava/lang/annotation/Annotation;