Skip to content

Commit 88d74f7

Browse files
brettchabotAndroid Git Automerger
authored and
Android Git Automerger
committed
am 4cd5f4e: Merge "Add user-friendly constructors to StdField"
Merge commit '4cd5f4e3732f5fc5f4f13aeefc1a479f2bf77618' into dalvik-dev * commit '4cd5f4e3732f5fc5f4f13aeefc1a479f2bf77618': Add user-friendly constructors to StdField
2 parents f6fd271 + 4cd5f4e commit 88d74f7

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

dexgen/src/com/android/dexgen/rop/StdField.java

+30-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.android.dexgen.rop.cst.CstNat;
2020
import com.android.dexgen.rop.cst.CstType;
21+
import com.android.dexgen.rop.cst.CstUtf8;
2122
import com.android.dexgen.rop.cst.TypedConstant;
2223

2324
/**
@@ -38,6 +39,34 @@ public StdField(CstType definingClass, int accessFlags, CstNat nat,
3839
super(definingClass, accessFlags, nat, attributes);
3940
}
4041

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+
4170
/** {@inheritDoc} */
4271
public TypedConstant getConstantValue() {
4372
AttributeList attribs = getAttributes();
@@ -50,4 +79,4 @@ public TypedConstant getConstantValue() {
5079

5180
return cval.getConstantValue();
5281
}
53-
}
82+
}

0 commit comments

Comments
 (0)