Search in sources :

Example 11 with AccessFlags

use of org.jf.dexlib2.AccessFlags in project smali by JesusFreke.

the class FieldDefinition method writeTo.

public static void writeTo(BaksmaliOptions options, IndentingWriter writer, Field field, boolean setInStaticConstructor) throws IOException {
    EncodedValue initialValue = field.getInitialValue();
    int accessFlags = field.getAccessFlags();
    if (setInStaticConstructor && AccessFlags.STATIC.isSet(accessFlags) && AccessFlags.FINAL.isSet(accessFlags) && initialValue != null) {
        if (!EncodedValueUtils.isDefaultValue(initialValue)) {
            writer.write("# The value of this static final field might be set in the static constructor\n");
        } else {
            // don't write out the default initial value for static final fields that get set in the static
            // constructor
            initialValue = null;
        }
    }
    writer.write(".field ");
    writeAccessFlags(writer, field.getAccessFlags());
    writer.write(field.getName());
    writer.write(':');
    writer.write(field.getType());
    if (initialValue != null) {
        writer.write(" = ");
        String containingClass = null;
        if (options.implicitReferences) {
            containingClass = field.getDefiningClass();
        }
        EncodedValueAdaptor.writeTo(writer, initialValue, containingClass);
    }
    writer.write('\n');
    Collection<? extends Annotation> annotations = field.getAnnotations();
    if (annotations.size() > 0) {
        writer.indent(4);
        String containingClass = null;
        if (options.implicitReferences) {
            containingClass = field.getDefiningClass();
        }
        AnnotationFormatter.writeTo(writer, annotations, containingClass);
        writer.deindent(4);
        writer.write(".end field\n");
    }
}
Also used : EncodedValue(org.jf.dexlib2.iface.value.EncodedValue)

Aggregations

AccessFlags (org.jf.dexlib2.AccessFlags)7 Nonnull (javax.annotation.Nonnull)2 EncodedValue (org.jf.dexlib2.iface.value.EncodedValue)2 PsiElement (com.intellij.psi.PsiElement)1 StubBasedPsiElement (com.intellij.psi.StubBasedPsiElement)1 Matcher (java.util.regex.Matcher)1 Nullable (javax.annotation.Nullable)1 DexReader (org.jf.dexlib2.dexbacked.DexReader)1 ClassDef (org.jf.dexlib2.iface.ClassDef)1 Method (org.jf.dexlib2.iface.Method)1 ImmutableMethod (org.jf.dexlib2.immutable.ImmutableMethod)1 ImmutableMethodParameter (org.jf.dexlib2.immutable.ImmutableMethodParameter)1 ImmutableMethodReference (org.jf.dexlib2.immutable.reference.ImmutableMethodReference)1 AnnotatedBytes (org.jf.dexlib2.util.AnnotatedBytes)1 SmaliModifierListStub (org.jf.smalidea.psi.stub.SmaliModifierListStub)1