org.jf.dexlib2.iface.Field Java Examples

The following examples show how to use org.jf.dexlib2.iface.Field. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ImmutableClassDef.java    From ZjDroid with Apache License 2.0 6 votes vote down vote up
public ImmutableClassDef(@Nonnull String type,
                         int accessFlags,
                         @Nullable String superclass,
                         @Nullable Collection<String> interfaces,
                         @Nullable String sourceFile,
                         @Nullable Collection<? extends Annotation> annotations,
                         @Nullable Iterable<? extends Field> staticFields,
                         @Nullable Iterable<? extends Field> instanceFields,
                         @Nullable Iterable<? extends Method> directMethods,
                         @Nullable Iterable<? extends Method> virtualMethods) {
    this.type = type;
    this.accessFlags = accessFlags;
    this.superclass = superclass;
    this.interfaces = interfaces==null ? ImmutableSet.<String>of() : ImmutableSet.copyOf(interfaces);
    this.sourceFile = sourceFile;
    this.annotations = ImmutableAnnotation.immutableSetOf(annotations);
    this.staticFields = ImmutableField.immutableSetOf(staticFields);
    this.instanceFields = ImmutableField.immutableSetOf(instanceFields);
    this.directMethods = ImmutableMethod.immutableSetOf(directMethods);
    this.virtualMethods = ImmutableMethod.immutableSetOf(virtualMethods);
}
 
Example #2
Source File: ClassReIClassDef.java    From atlas with Apache License 2.0 6 votes vote down vote up
@Override
protected Field reField(Field field) {
    String name = field.getName();
    String newType;
    boolean isBasic = false;
    boolean isArray = false;
    if (field.getType().startsWith("[")) {
        isArray = true;
    }
    if (basicType.containsKey(field.getType())) {
        newType = field.getType();
        isBasic = true;
    } else {

        newType = DefineUtils.getDalvikClassName(field.getType());
    }
    String defineClass = DefineUtils.getDalvikClassName(field.getDefiningClass());
    return new ImmutableField(
            reType,
            classProcessor.filedProcess(defineClass, isBasic ? basicType.get(newType) : newType + (isArray ? "[]" : ""), name).fieldName,
            isBasic ? newType :
                    DefineUtils.getDefineClassName(classProcessor.classProcess(isBasic ? basicType.get(newType) : newType).className, isArray),
            field.getAccessFlags(),
            field.getInitialValue(),
            getAnnotation(field.getAnnotations()));
}
 
Example #3
Source File: ImmutableClassDef.java    From zjdroid with Apache License 2.0 6 votes vote down vote up
public ImmutableClassDef(@Nonnull String type,
                         int accessFlags,
                         @Nullable String superclass,
                         @Nullable Collection<String> interfaces,
                         @Nullable String sourceFile,
                         @Nullable Collection<? extends Annotation> annotations,
                         @Nullable Iterable<? extends Field> fields,
                         @Nullable Iterable<? extends Method> methods) {
    if (fields == null) {
        fields = ImmutableList.of();
    }
    if (methods == null) {
        methods = ImmutableList.of();
    }

    this.type = type;
    this.accessFlags = accessFlags;
    this.superclass = superclass;
    this.interfaces = interfaces==null ? ImmutableSet.<String>of() : ImmutableSet.copyOf(interfaces);
    this.sourceFile = sourceFile;
    this.annotations = ImmutableAnnotation.immutableSetOf(annotations);
    this.staticFields = ImmutableField.immutableSetOf(Iterables.filter(fields, FieldUtil.FIELD_IS_STATIC));
    this.instanceFields = ImmutableField.immutableSetOf(Iterables.filter(fields, FieldUtil.FIELD_IS_INSTANCE));
    this.directMethods = ImmutableMethod.immutableSetOf(Iterables.filter(methods, MethodUtil.METHOD_IS_DIRECT));
    this.virtualMethods = ImmutableMethod.immutableSetOf(Iterables.filter(methods, MethodUtil.METHOD_IS_VIRTUAL));
}
 
Example #4
Source File: ImmutableClassDef.java    From zjdroid with Apache License 2.0 6 votes vote down vote up
public ImmutableClassDef(@Nonnull String type,
                         int accessFlags,
                         @Nullable String superclass,
                         @Nullable Collection<String> interfaces,
                         @Nullable String sourceFile,
                         @Nullable Collection<? extends Annotation> annotations,
                         @Nullable Iterable<? extends Field> staticFields,
                         @Nullable Iterable<? extends Field> instanceFields,
                         @Nullable Iterable<? extends Method> directMethods,
                         @Nullable Iterable<? extends Method> virtualMethods) {
    this.type = type;
    this.accessFlags = accessFlags;
    this.superclass = superclass;
    this.interfaces = interfaces==null ? ImmutableSet.<String>of() : ImmutableSet.copyOf(interfaces);
    this.sourceFile = sourceFile;
    this.annotations = ImmutableAnnotation.immutableSetOf(annotations);
    this.staticFields = ImmutableField.immutableSetOf(staticFields);
    this.instanceFields = ImmutableField.immutableSetOf(instanceFields);
    this.directMethods = ImmutableMethod.immutableSetOf(directMethods);
    this.virtualMethods = ImmutableMethod.immutableSetOf(virtualMethods);
}
 
Example #5
Source File: ReflectionClassDef.java    From ZjDroid with Apache License 2.0 6 votes vote down vote up
@Nonnull @Override public Set<? extends Field> getFields() {
    return new AbstractSet<Field>() {
        @Nonnull @Override public Iterator<Field> iterator() {
            return Iterators.transform(Iterators.forArray(cls.getDeclaredFields()),
                    new Function<java.lang.reflect.Field, Field>() {
                        @Nullable @Override public Field apply(@Nullable java.lang.reflect.Field input) {
                            return new ReflectionField(input);
                        }
                    });
        }

        @Override public int size() {
            return cls.getDeclaredFields().length;
        }
    };
}
 
Example #6
Source File: ReflectionClassDef.java    From ZjDroid with Apache License 2.0 6 votes vote down vote up
@Nonnull @Override public Set<? extends Field> getFields() {
    return new AbstractSet<Field>() {
        @Nonnull @Override public Iterator<Field> iterator() {
            return Iterators.transform(Iterators.forArray(cls.getDeclaredFields()),
                    new Function<java.lang.reflect.Field, Field>() {
                        @Nullable @Override public Field apply(@Nullable java.lang.reflect.Field input) {
                            return new ReflectionField(input);
                        }
                    });
        }

        @Override public int size() {
            return cls.getDeclaredFields().length;
        }
    };
}
 
Example #7
Source File: ReflectionClassDef.java    From HeyGirl with Apache License 2.0 6 votes vote down vote up
@Nonnull @Override public Set<? extends Field> getFields() {
    return new AbstractSet<Field>() {
        @Nonnull @Override public Iterator<Field> iterator() {
            return Iterators.transform(Iterators.forArray(cls.getDeclaredFields()),
                    new Function<java.lang.reflect.Field, Field>() {
                        @Nullable @Override public Field apply(@Nullable java.lang.reflect.Field input) {
                            return new ReflectionField(input);
                        }
                    });
        }

        @Override public int size() {
            return cls.getDeclaredFields().length;
        }
    };
}
 
Example #8
Source File: ImmutableClassDef.java    From HeyGirl with Apache License 2.0 6 votes vote down vote up
public ImmutableClassDef(@Nonnull String type,
                         int accessFlags,
                         @Nullable String superclass,
                         @Nullable Collection<String> interfaces,
                         @Nullable String sourceFile,
                         @Nullable Collection<? extends Annotation> annotations,
                         @Nullable Iterable<? extends Field> staticFields,
                         @Nullable Iterable<? extends Field> instanceFields,
                         @Nullable Iterable<? extends Method> directMethods,
                         @Nullable Iterable<? extends Method> virtualMethods) {
    this.type = type;
    this.accessFlags = accessFlags;
    this.superclass = superclass;
    this.interfaces = interfaces==null ? ImmutableSet.<String>of() : ImmutableSet.copyOf(interfaces);
    this.sourceFile = sourceFile;
    this.annotations = ImmutableAnnotation.immutableSetOf(annotations);
    this.staticFields = ImmutableField.immutableSetOf(staticFields);
    this.instanceFields = ImmutableField.immutableSetOf(instanceFields);
    this.directMethods = ImmutableMethod.immutableSetOf(directMethods);
    this.virtualMethods = ImmutableMethod.immutableSetOf(virtualMethods);
}
 
Example #9
Source File: ImmutableClassDef.java    From HeyGirl with Apache License 2.0 6 votes vote down vote up
public ImmutableClassDef(@Nonnull String type,
                         int accessFlags,
                         @Nullable String superclass,
                         @Nullable Collection<String> interfaces,
                         @Nullable String sourceFile,
                         @Nullable Collection<? extends Annotation> annotations,
                         @Nullable Iterable<? extends Field> fields,
                         @Nullable Iterable<? extends Method> methods) {
    if (fields == null) {
        fields = ImmutableList.of();
    }
    if (methods == null) {
        methods = ImmutableList.of();
    }

    this.type = type;
    this.accessFlags = accessFlags;
    this.superclass = superclass;
    this.interfaces = interfaces==null ? ImmutableSet.<String>of() : ImmutableSet.copyOf(interfaces);
    this.sourceFile = sourceFile;
    this.annotations = ImmutableAnnotation.immutableSetOf(annotations);
    this.staticFields = ImmutableField.immutableSetOf(Iterables.filter(fields, FieldUtil.FIELD_IS_STATIC));
    this.instanceFields = ImmutableField.immutableSetOf(Iterables.filter(fields, FieldUtil.FIELD_IS_INSTANCE));
    this.directMethods = ImmutableMethod.immutableSetOf(Iterables.filter(methods, MethodUtil.METHOD_IS_DIRECT));
    this.virtualMethods = ImmutableMethod.immutableSetOf(Iterables.filter(methods, MethodUtil.METHOD_IS_VIRTUAL));
}
 
Example #10
Source File: MetaObjectDex.java    From android-classyshark with Apache License 2.0 6 votes vote down vote up
@Override
public FieldInfo[] getDeclaredFields() {
    List<FieldInfo> result = new ArrayList<>();
    Iterable<? extends Field> implFields = classDef.getFields();

    for (Field field : implFields) {
        FieldInfo fi = new FieldInfo();
        fi.typeName = DexlibAdapter.getTypeName(field.getType());
        fi.modifiers = field.getAccessFlags();
        fi.annotations = convertAnnotations(field.getAnnotations());
        fi.name = field.getName();

        result.add(fi);
    }

    FieldInfo[] array = new FieldInfo[result.size()];
    return result.toArray(array);
}
 
Example #11
Source File: MetaObjectDex.java    From android-classyshark with Apache License 2.0 6 votes vote down vote up
@Override
public Iterable<? extends Field> getStaticFields() {
    return new Iterable<Field>() {
        @Override
        public Iterator<Field> iterator() {
            return new Iterator<Field>() {
                @Override
                public boolean hasNext() {
                    return false;
                }

                @Override
                public Field next() {
                    return null;
                }

                @Override
                public void remove() {

                }
            };
        }
    };
}
 
Example #12
Source File: MetaObjectDex.java    From android-classyshark with Apache License 2.0 6 votes vote down vote up
@Override
public Iterable<? extends Field> getInstanceFields() {
    return new Iterable<Field>() {
        @Override
        public Iterator<Field> iterator() {
            return new Iterator<Field>() {
                @Override
                public boolean hasNext() {
                    return false;
                }

                @Override
                public Field next() {
                    return null;
                }

                @Override
                public void remove() {

                }
            };
        }
    };
}
 
Example #13
Source File: MetaObjectDex.java    From android-classyshark with Apache License 2.0 6 votes vote down vote up
@Override
public Iterable<? extends Field> getFields() {
    return new Iterable<Field>() {
        @Override
        public Iterator<Field> iterator() {
            return new Iterator<Field>() {
                @Override
                public boolean hasNext() {
                    return false;
                }

                @Override
                public Field next() {
                    return null;
                }

                @Override
                public void remove() {

                }
            };
        }
    };
}
 
Example #14
Source File: ReflectionClassDef.java    From zjdroid with Apache License 2.0 6 votes vote down vote up
@Nonnull @Override public Set<? extends Field> getFields() {
    return new AbstractSet<Field>() {
        @Nonnull @Override public Iterator<Field> iterator() {
            return Iterators.transform(Iterators.forArray(cls.getDeclaredFields()),
                    new Function<java.lang.reflect.Field, Field>() {
                        @Nullable @Override public Field apply(@Nullable java.lang.reflect.Field input) {
                            return new ReflectionField(input);
                        }
                    });
        }

        @Override public int size() {
            return cls.getDeclaredFields().length;
        }
    };
}
 
Example #15
Source File: ImmutableClassDef.java    From ZjDroid with Apache License 2.0 6 votes vote down vote up
public ImmutableClassDef(@Nonnull String type,
                         int accessFlags,
                         @Nullable String superclass,
                         @Nullable Collection<String> interfaces,
                         @Nullable String sourceFile,
                         @Nullable Collection<? extends Annotation> annotations,
                         @Nullable Iterable<? extends Field> fields,
                         @Nullable Iterable<? extends Method> methods) {
    if (fields == null) {
        fields = ImmutableList.of();
    }
    if (methods == null) {
        methods = ImmutableList.of();
    }

    this.type = type;
    this.accessFlags = accessFlags;
    this.superclass = superclass;
    this.interfaces = interfaces==null ? ImmutableSet.<String>of() : ImmutableSet.copyOf(interfaces);
    this.sourceFile = sourceFile;
    this.annotations = ImmutableAnnotation.immutableSetOf(annotations);
    this.staticFields = ImmutableField.immutableSetOf(Iterables.filter(fields, FieldUtil.FIELD_IS_STATIC));
    this.instanceFields = ImmutableField.immutableSetOf(Iterables.filter(fields, FieldUtil.FIELD_IS_INSTANCE));
    this.directMethods = ImmutableMethod.immutableSetOf(Iterables.filter(methods, MethodUtil.METHOD_IS_DIRECT));
    this.virtualMethods = ImmutableMethod.immutableSetOf(Iterables.filter(methods, MethodUtil.METHOD_IS_VIRTUAL));
}
 
Example #16
Source File: ClassDefRewriter.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public Iterable<? extends Field> getFields() {
    return new Iterable<Field>() {
        @Nonnull
        @Override
        public Iterator<Field> iterator() {
            return Iterators.concat(getStaticFields().iterator(), getInstanceFields().iterator());
        }
    };
}
 
Example #17
Source File: DexField.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
/**
 *
 * @return the Soot equivalent of a field
 */
public static SootField makeSootField(Field f) {
    String name = f.getName();
    Type type = DexType.toSoot(f.getType());
    int flags = f.getAccessFlags();
    SootField sf = new SootField(name, type, flags);
    if (Modifier.isFinal(flags))
        DexField.addConstantTag(sf, f);
    return sf;
}
 
Example #18
Source File: FieldDefinition.java    From HeyGirl with Apache License 2.0 5 votes vote down vote up
public static void writeTo(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(" = ");
        EncodedValueAdaptor.writeTo(writer, initialValue);
    }

    writer.write('\n');

    Collection<? extends Annotation> annotations = field.getAnnotations();
    if (annotations.size() > 0) {
        writer.indent(4);
        AnnotationFormatter.writeTo(writer, annotations);
        writer.deindent(4);
        writer.write(".end field\n");
    }
}
 
Example #19
Source File: PoolClassDef.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
@Nonnull @Override public Collection<Field> getFields() {
    return new AbstractCollection<Field>() {
        @Nonnull @Override public Iterator<Field> iterator() {
            return Iterators.mergeSorted(
                    ImmutableList.of(staticFields.iterator(), instanceFields.iterator()),
                    Ordering.natural());
        }

        @Override public int size() {
            return staticFields.size() + instanceFields.size();
        }
    };
}
 
Example #20
Source File: ClassDefinition.java    From atlas with Apache License 2.0 5 votes vote down vote up
private Set<String> writeStaticFields(IndentingWriter writer) throws IOException {
    if (!fullMethod && !DexDiffInfo.addedClasses.contains(classDef)) {
        return null;
    }
    boolean wroteHeader = false;
    Set<String> writtenFields = new HashSet<String>();

    Iterable<? extends Field> staticFields;
    if (classDef instanceof DexBackedClassDef) {
        staticFields = ((DexBackedClassDef) classDef).getStaticFields(false);
    } else {
        staticFields = classDef.getStaticFields();
    }

    for (Field field : staticFields) {
        if (!wroteHeader) {
            writer.write("\n\n");
            writer.write("# static fields");
            wroteHeader = true;
        }
        writer.write('\n');

        boolean setInStaticConstructor;
        IndentingWriter fieldWriter = writer;
        String fieldString = ReferenceUtil.getShortFieldDescriptor(field);
        if (!writtenFields.add(fieldString)) {
            writer.write("# duplicate field ignored\n");
            fieldWriter = new CommentingIndentingWriter(writer);
            System.err.println(String.format("Ignoring duplicate field: %s->%s", classDef.getType(), fieldString));
            setInStaticConstructor = false;
        } else {
            setInStaticConstructor = fieldsSetInStaticConstructor.contains(fieldString);
        }
        FieldDefinition.writeTo(options, fieldWriter, field, setInStaticConstructor);
    }
    return writtenFields;
}
 
Example #21
Source File: FieldDefinition.java    From zjdroid with Apache License 2.0 5 votes vote down vote up
public static void writeTo(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(" = ");
        EncodedValueAdaptor.writeTo(writer, initialValue);
    }

    writer.write('\n');

    Collection<? extends Annotation> annotations = field.getAnnotations();
    if (annotations.size() > 0) {
        writer.indent(4);
        AnnotationFormatter.writeTo(writer, annotations);
        writer.deindent(4);
        writer.write(".end field\n");
    }
}
 
Example #22
Source File: ClassDefinition.java    From atlas with Apache License 2.0 5 votes vote down vote up
private void writeInstanceFields(IndentingWriter writer, Set<String> staticFields) throws IOException {
    if (!fullMethod&& !DexDiffInfo.addedClasses.contains(classDef)) {
        return;
    }
    boolean wroteHeader = false;
    Set<String> writtenFields = new HashSet<String>();

    Iterable<? extends Field> instanceFields;
    if (classDef instanceof DexBackedClassDef) {
        instanceFields = ((DexBackedClassDef) classDef).getInstanceFields(false);
    } else {
        instanceFields = classDef.getInstanceFields();
    }

    for (Field field : instanceFields) {
        if (!wroteHeader) {
            writer.write("\n\n");
            writer.write("# instance fields");
            wroteHeader = true;
        }
        writer.write('\n');

        IndentingWriter fieldWriter = writer;
        String fieldString = ReferenceUtil.getShortFieldDescriptor(field);
        if (!writtenFields.add(fieldString)) {
            writer.write("# duplicate field ignored\n");
            fieldWriter = new CommentingIndentingWriter(writer);
            System.err.println(String.format("Ignoring duplicate field: %s->%s", classDef.getType(), fieldString));
        } else if (staticFields.contains(fieldString)) {
            System.err.println(String.format("Duplicate static+instance field found: %s->%s",
                    classDef.getType(), fieldString));
            System.err.println("You will need to rename one of these fields, including all references.");

            writer.write("# There is both a static and instance field with this signature.\n" +
                    "# You will need to rename one of these fields, including all references.\n");
        }
        FieldDefinition.writeTo(options, fieldWriter, field, false);
    }
}
 
Example #23
Source File: DexField.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Add constant tag. Should only be called if field is final.
 * @param df
 * @param sf
 */
private static void addConstantTag(SootField df, Field sf) {
    Tag tag = null;

    EncodedValue ev = sf.getInitialValue();

    if (ev instanceof BooleanEncodedValue) {
      tag = new IntegerConstantValueTag(((BooleanEncodedValue) ev).getValue() ==true?1:0);
    } else if (ev instanceof ByteEncodedValue) {
      tag = new IntegerConstantValueTag(((ByteEncodedValue) ev).getValue());
    } else if (ev instanceof CharEncodedValue) {
      tag = new IntegerConstantValueTag(((CharEncodedValue) ev).getValue());
    } else if (ev instanceof DoubleEncodedValue) {
      tag = new DoubleConstantValueTag(((DoubleEncodedValue) ev).getValue());
    } else if (ev instanceof FloatEncodedValue) {
      tag = new FloatConstantValueTag(((FloatEncodedValue) ev).getValue());
    } else if (ev instanceof IntEncodedValue) {
      tag = new IntegerConstantValueTag(((IntEncodedValue) ev).getValue());
    } else if (ev instanceof LongEncodedValue) {
      tag = new LongConstantValueTag(((LongEncodedValue) ev).getValue());
    } else if (ev instanceof ShortEncodedValue) {
      tag = new IntegerConstantValueTag(((ShortEncodedValue) ev).getValue());
    } else if (ev instanceof StringEncodedValue) {
      tag = new StringConstantValueTag(((StringEncodedValue) ev).getValue());
    }

    if (tag != null)
      df.addTag(tag);
}
 
Example #24
Source File: PoolClassDef.java    From HeyGirl with Apache License 2.0 5 votes vote down vote up
@Nonnull @Override public Collection<Field> getFields() {
    return new AbstractCollection<Field>() {
        @Nonnull @Override public Iterator<Field> iterator() {
            return Iterators.mergeSorted(
                    ImmutableList.of(staticFields.iterator(), instanceFields.iterator()),
                    Ordering.natural());
        }

        @Override public int size() {
            return staticFields.size() + instanceFields.size();
        }
    };
}
 
Example #25
Source File: FieldDefinition.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
public static void writeTo(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(" = ");
        EncodedValueAdaptor.writeTo(writer, initialValue);
    }

    writer.write('\n');

    Collection<? extends Annotation> annotations = field.getAnnotations();
    if (annotations.size() > 0) {
        writer.indent(4);
        AnnotationFormatter.writeTo(writer, annotations);
        writer.deindent(4);
        writer.write(".end field\n");
    }
}
 
Example #26
Source File: PoolClassDef.java    From zjdroid with Apache License 2.0 5 votes vote down vote up
@Nonnull @Override public Collection<Field> getFields() {
    return new AbstractCollection<Field>() {
        @Nonnull @Override public Iterator<Field> iterator() {
            return Iterators.mergeSorted(
                    ImmutableList.of(staticFields.iterator(), instanceFields.iterator()),
                    Ordering.natural());
        }

        @Override public int size() {
            return staticFields.size() + instanceFields.size();
        }
    };
}
 
Example #27
Source File: PoolClassDef.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
@Nonnull @Override public Collection<Field> getFields() {
    return new AbstractCollection<Field>() {
        @Nonnull @Override public Iterator<Field> iterator() {
            return Iterators.mergeSorted(
                    ImmutableList.of(staticFields.iterator(), instanceFields.iterator()),
                    Ordering.natural());
        }

        @Override public int size() {
            return staticFields.size() + instanceFields.size();
        }
    };
}
 
Example #28
Source File: ImmutableField.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
public static ImmutableField of(Field field) {
    if (field instanceof  ImmutableField) {
        return (ImmutableField)field;
    }
    return new ImmutableField(
            field.getDefiningClass(),
            field.getName(),
            field.getType(),
            field.getAccessFlags(),
            field.getInitialValue(),
            field.getAnnotations());
}
 
Example #29
Source File: ImmutableField.java    From HeyGirl with Apache License 2.0 5 votes vote down vote up
public static ImmutableField of(Field field) {
    if (field instanceof  ImmutableField) {
        return (ImmutableField)field;
    }
    return new ImmutableField(
            field.getDefiningClass(),
            field.getName(),
            field.getType(),
            field.getAccessFlags(),
            field.getInitialValue(),
            field.getAnnotations());
}
 
Example #30
Source File: ClassDefRewriter.java    From zjdroid with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public Iterable<? extends Field> getFields() {
    return new Iterable<Field>() {
        @Nonnull
        @Override
        public Iterator<Field> iterator() {
            return Iterators.concat(getStaticFields().iterator(), getInstanceFields().iterator());
        }
    };
}