mirror of
https://github.com/revanced/smali.git
synced 2025-05-02 07:34:28 +02:00
Add convenience constructor for ImmutableClassDef
This commit is contained in:
parent
8979759556
commit
ddf18a996e
@ -33,12 +33,15 @@ package org.jf.dexlib2.immutable;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.ImmutableSortedSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Iterators;
|
||||
import org.jf.dexlib2.base.reference.BaseTypeReference;
|
||||
import org.jf.dexlib2.iface.Annotation;
|
||||
import org.jf.dexlib2.iface.ClassDef;
|
||||
import org.jf.dexlib2.iface.Field;
|
||||
import org.jf.dexlib2.iface.Method;
|
||||
import org.jf.dexlib2.util.FieldUtil;
|
||||
import org.jf.dexlib2.util.MethodUtil;
|
||||
import org.jf.util.ImmutableConverter;
|
||||
import org.jf.util.ImmutableUtils;
|
||||
|
||||
@ -60,6 +63,26 @@ public class ImmutableClassDef extends BaseTypeReference implements ClassDef {
|
||||
@Nonnull protected final ImmutableSortedSet<? extends ImmutableMethod> directMethods;
|
||||
@Nonnull protected final ImmutableSortedSet<? extends ImmutableMethod> virtualMethods;
|
||||
|
||||
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) {
|
||||
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));
|
||||
}
|
||||
|
||||
public ImmutableClassDef(@Nonnull String type,
|
||||
int accessFlags,
|
||||
@Nullable String superclass,
|
||||
|
@ -31,12 +31,26 @@
|
||||
|
||||
package org.jf.dexlib2.util;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import org.jf.dexlib2.AccessFlags;
|
||||
import org.jf.dexlib2.iface.Field;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public final class FieldUtil {
|
||||
public static Predicate<Field> FIELD_IS_STATIC = new Predicate<Field>() {
|
||||
@Override public boolean apply(@Nullable Field input) {
|
||||
return input!=null && isStatic(input);
|
||||
}
|
||||
};
|
||||
|
||||
public static Predicate<Field> FIELD_IS_INSTANCE = new Predicate<Field>() {
|
||||
@Override public boolean apply(@Nullable Field input) {
|
||||
return input!= null && !isStatic(input);
|
||||
}
|
||||
};
|
||||
|
||||
public static boolean isStatic(@Nonnull Field field) {
|
||||
return AccessFlags.STATIC.isSet(field.getAccessFlags());
|
||||
}
|
||||
|
@ -31,16 +31,30 @@
|
||||
|
||||
package org.jf.dexlib2.util;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import org.jf.dexlib2.AccessFlags;
|
||||
import org.jf.dexlib2.iface.Method;
|
||||
import org.jf.dexlib2.iface.reference.MethodReference;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public final class MethodUtil {
|
||||
private static int directMask = AccessFlags.STATIC.getValue() | AccessFlags.PRIVATE.getValue() |
|
||||
AccessFlags.CONSTRUCTOR.getValue();
|
||||
|
||||
public static Predicate<Method> METHOD_IS_DIRECT = new Predicate<Method>() {
|
||||
@Override public boolean apply(@Nullable Method input) {
|
||||
return input != null && isDirect(input);
|
||||
}
|
||||
};
|
||||
|
||||
public static Predicate<Method> METHOD_IS_VIRTUAL = new Predicate<Method>() {
|
||||
@Override public boolean apply(@Nullable Method input) {
|
||||
return input != null && !isDirect(input);
|
||||
}
|
||||
};
|
||||
|
||||
public static boolean isDirect(@Nonnull Method method) {
|
||||
return (method.getAccessFlags() & directMask) != 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user