18
18
19
19
import com .android .dexgen .rop .cst .CstNat ;
20
20
import com .android .dexgen .rop .cst .CstType ;
21
+ import com .android .dexgen .rop .cst .CstUtf8 ;
21
22
import com .android .dexgen .rop .cst .TypedConstant ;
22
23
23
24
/**
@@ -38,6 +39,34 @@ public StdField(CstType definingClass, int accessFlags, CstNat nat,
38
39
super (definingClass , accessFlags , nat , attributes );
39
40
}
40
41
42
+ /**
43
+ * Constructs an instance having Java field as its pattern.
44
+ *
45
+ * @param field {@code non-null;} pattern for dex field
46
+ */
47
+ public StdField (java .lang .reflect .Field field ) {
48
+ this (CstType .intern (field .getDeclaringClass ()),
49
+ field .getModifiers (),
50
+ new CstNat (new CstUtf8 (field .getName ()),
51
+ CstType .intern (field .getType ()).getDescriptor ()),
52
+ new StdAttributeList (0 ));
53
+ }
54
+
55
+ /**
56
+ * Constructs an instance taking field description as user-friendly arguments.
57
+ *
58
+ * @param declaringClass {@code non-null;} the class field belongs to
59
+ * @param type {@code non-null;} type of the field
60
+ * @param name {@code non-null;} name of the field
61
+ * @param modifiers access flags of the field
62
+ */
63
+ public StdField (Class definingClass , Class type , String name , int modifiers ) {
64
+ this (CstType .intern (definingClass ),
65
+ modifiers ,
66
+ new CstNat (new CstUtf8 (name ), CstType .intern (type ).getDescriptor ()),
67
+ new StdAttributeList (0 ));
68
+ }
69
+
41
70
/** {@inheritDoc} */
42
71
public TypedConstant getConstantValue () {
43
72
AttributeList attribs = getAttributes ();
@@ -50,4 +79,4 @@ public TypedConstant getConstantValue() {
50
79
51
80
return cval .getConstantValue ();
52
81
}
53
- }
82
+ }
0 commit comments