Skip to content

Commit 03b7bf2

Browse files
Enable parsing of annotations on parameters
1 parent dbd6988 commit 03b7bf2

13 files changed

+177
-0
lines changed

jbmc/src/java_bytecode/java_bytecode_parse_tree.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,14 @@ struct java_bytecode_parse_treet
9898
return instructions.back();
9999
}
100100

101+
/// Java annotations that were applied to parameters of this method
102+
/// \remarks Each element in the vector corresponds to the annotations on
103+
/// the parameter of this method with the matching index. A parameter that
104+
/// does not have annotations can have an entry in this vector that is an
105+
/// empty annotationst. Trailing parameters that have no annotations may be
106+
/// entirely omitted from this vector.
107+
std::vector<annotationst> parameter_annotations;
108+
101109
struct exceptiont
102110
{
103111
exceptiont()

jbmc/src/java_bytecode/java_bytecode_parser.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,6 +1243,21 @@ void java_bytecode_parsert::rmethod_attribute(methodt &method)
12431243
{
12441244
rRuntimeAnnotation_attribute(method.annotations);
12451245
}
1246+
else if(
1247+
attribute_name == "RuntimeInvisibleParameterAnnotations" ||
1248+
attribute_name == "RuntimeVisibleParameterAnnotations")
1249+
{
1250+
u1 parameter_count = read_u1();
1251+
// There may be attributes for both runtime-visiible and rutime-invisible
1252+
// annotations, the length of either array may be longer than the other as
1253+
// trailing parameters without annotations are omitted.
1254+
// Extend our parameter_annotations if this one is longer than the one
1255+
// previously recorded (if any).
1256+
if(method.parameter_annotations.size() < parameter_count)
1257+
method.parameter_annotations.resize(parameter_count);
1258+
for(u2 param_no = 0; param_no < parameter_count; ++param_no)
1259+
rRuntimeAnnotation_attribute(method.parameter_annotations[param_no]);
1260+
}
12461261
else if(attribute_name == "Exceptions")
12471262
{
12481263
method.throws_exception_table = rexceptions_attribute();
Binary file not shown.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
@interface ClassAnnotation {
2+
}
3+
4+
@java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME)
5+
@interface RuntimeClassAnnotation {
6+
}
7+
8+
@interface FieldAnnotation {
9+
}
10+
11+
@java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME)
12+
@interface RuntimeFieldAnnotation {
13+
}
14+
15+
@interface MethodAnnotation {
16+
}
17+
18+
@java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME)
19+
@interface RuntimeMethodAnnotation {
20+
}
21+
22+
@interface ParameterAnnotation {
23+
}
24+
25+
@java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.RUNTIME)
26+
@interface RuntimeParameterAnnotation {
27+
}
28+
29+
@ClassAnnotation
30+
@RuntimeClassAnnotation
31+
public class AnnotationsEverywhere {
32+
@FieldAnnotation
33+
@RuntimeFieldAnnotation
34+
public int x;
35+
36+
@MethodAnnotation
37+
@RuntimeMethodAnnotation
38+
public void foo(
39+
@RuntimeParameterAnnotation int p,
40+
@ParameterAnnotation int q)
41+
{
42+
}
43+
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)