diff options
| author | Piotr Gurgul <pgurgul@google.com> | 2010-09-23 11:30:14 -0700 |
|---|---|---|
| committer | Piotr Gurgul <pgurgul@google.com> | 2010-09-23 15:25:34 -0700 |
| commit | 7351211af4fdfc436eae69a3641c0880f8c8b608 (patch) | |
| tree | 19b5f22743e156259a1b9dfec7d780310ab77161 /dexgen | |
| parent | a7f5cee6539fbfd6fd145614a5970f05439a648f (diff) | |
Add user-friendly constructors to StdField
This is to simplify programmatic use of StdField to create dex fields
dynamically without knowledge of the dex internal format.
Change-Id: Ib11980509e0336d1e0253b6d480240d6832b73dd
Diffstat (limited to 'dexgen')
| -rw-r--r-- | dexgen/src/com/android/dexgen/rop/StdField.java | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/dexgen/src/com/android/dexgen/rop/StdField.java b/dexgen/src/com/android/dexgen/rop/StdField.java index 3084dcca4..9adcc30ad 100644 --- a/dexgen/src/com/android/dexgen/rop/StdField.java +++ b/dexgen/src/com/android/dexgen/rop/StdField.java @@ -18,6 +18,7 @@ package com.android.dexgen.rop; import com.android.dexgen.rop.cst.CstNat; import com.android.dexgen.rop.cst.CstType; +import com.android.dexgen.rop.cst.CstUtf8; import com.android.dexgen.rop.cst.TypedConstant; /** @@ -38,6 +39,34 @@ public final class StdField extends StdMember implements Field { super(definingClass, accessFlags, nat, attributes); } + /** + * Constructs an instance having Java field as its pattern. + * + * @param field {@code non-null;} pattern for dex field + */ + public StdField(java.lang.reflect.Field field) { + this(CstType.intern(field.getDeclaringClass()), + field.getModifiers(), + new CstNat(new CstUtf8(field.getName()), + CstType.intern(field.getType()).getDescriptor()), + new StdAttributeList(0)); + } + + /** + * Constructs an instance taking field description as user-friendly arguments. + * + * @param declaringClass {@code non-null;} the class field belongs to + * @param type {@code non-null;} type of the field + * @param name {@code non-null;} name of the field + * @param modifiers access flags of the field + */ + public StdField(Class definingClass, Class type, String name, int modifiers) { + this(CstType.intern(definingClass), + modifiers, + new CstNat(new CstUtf8(name), CstType.intern(type).getDescriptor()), + new StdAttributeList(0)); + } + /** {@inheritDoc} */ public TypedConstant getConstantValue() { AttributeList attribs = getAttributes(); @@ -50,4 +79,4 @@ public final class StdField extends StdMember implements Field { return cval.getConstantValue(); } -} +}
\ No newline at end of file |
