use of java.lang.reflect.Field in project platform_frameworks_base by android.
the class Filter method addAndSetFinalPorts.
private final void addAndSetFinalPorts(KeyValueMap values) {
Class filterClass = getClass();
Annotation annotation;
for (Field field : filterClass.getDeclaredFields()) {
if ((annotation = field.getAnnotation(GenerateFinalPort.class)) != null) {
GenerateFinalPort generator = (GenerateFinalPort) annotation;
String name = generator.name().isEmpty() ? field.getName() : generator.name();
boolean hasDefault = generator.hasDefault();
addFieldPort(name, field, hasDefault, true);
if (values.containsKey(name)) {
setImmediateInputValue(name, values.get(name));
values.remove(name);
} else if (!generator.hasDefault()) {
throw new RuntimeException("No value specified for final input port '" + name + "' of filter " + this + "!");
}
}
}
}
use of java.lang.reflect.Field in project platform_frameworks_base by android.
the class Filter method addAnnotatedPorts.
private final void addAnnotatedPorts() {
Class filterClass = getClass();
Annotation annotation;
for (Field field : filterClass.getDeclaredFields()) {
if ((annotation = field.getAnnotation(GenerateFieldPort.class)) != null) {
GenerateFieldPort generator = (GenerateFieldPort) annotation;
addFieldGenerator(generator, field);
} else if ((annotation = field.getAnnotation(GenerateProgramPort.class)) != null) {
GenerateProgramPort generator = (GenerateProgramPort) annotation;
addProgramGenerator(generator, field);
} else if ((annotation = field.getAnnotation(GenerateProgramPorts.class)) != null) {
GenerateProgramPorts generators = (GenerateProgramPorts) annotation;
for (GenerateProgramPort generator : generators.value()) {
addProgramGenerator(generator, field);
}
}
}
}
use of java.lang.reflect.Field in project fastjson by alibaba.
the class NotExistsTest method test_0.
public void test_0() throws Exception {
Field field = TypeUtils.class.getDeclaredField("mappings");
field.setAccessible(true);
ConcurrentMap<String, Class<?>> mappings = (ConcurrentMap<String, Class<?>>) field.get(null);
System.out.println(mappings.size());
// ParserConfig.global.setAutoTypeSupport(true);
for (int i = 0; i < 10; ++i) {
long start = System.currentTimeMillis();
perf();
long millis = System.currentTimeMillis() - start;
System.out.println("millis : " + millis);
}
}
use of java.lang.reflect.Field in project freeline by alibaba.
the class DexUtils method inject.
public static boolean inject(PathClassLoader classLoader, File dex, File opt) {
Log.i(TAG, dex.getAbsolutePath() + " dex length: " + dex.length());
Log.i(TAG, opt.getAbsolutePath() + " opt length: " + opt.length());
DexFile[] dexFiles = null;
Field pathListField = null;
Field fDexElements = null;
Object dstObject = null;
try {
Object newDexElements;
int dexLength;
if (VERSION.SDK_INT >= 14) {
pathListField = ReflectUtil.fieldGetOrg(classLoader, Class.forName("dalvik.system.BaseDexClassLoader"), "pathList");
fDexElements = ReflectUtil.fieldGetOrg(pathListField.get(classLoader), "dexElements");
Object e = fDexElements.get(pathListField.get(classLoader));
dstObject = e;
dexFiles = new DexFile[Array.getLength(e)];
for (int i = 0; i < Array.getLength(e); ++i) {
newDexElements = Array.get(e, i);
dexFiles[i] = (DexFile) ReflectUtil.fieldGet(newDexElements, "dexFile");
}
} else {
pathListField = ReflectUtil.fieldGetOrg(classLoader, "mDexs");
dstObject = pathListField.get(classLoader);
dexFiles = new DexFile[Array.getLength(dstObject)];
for (dexLength = 0; dexLength < Array.getLength(dstObject); ++dexLength) {
dexFiles[dexLength] = (DexFile) Array.get(dstObject, dexLength);
}
}
dexLength = Array.getLength(dstObject) + 1;
newDexElements = Array.newInstance(fDexElements.getType().getComponentType(), dexLength);
DexClassLoader dynamicDex = new DexClassLoader(dex.getAbsolutePath(), opt.getAbsolutePath(), null, classLoader.getParent());
Log.i(TAG, "after opt, dex len:" + dex.length() + "; opt len:" + opt.length());
Object pathList = pathListField.get(dynamicDex);
Object dexElements = fDexElements.get(pathList);
Object firstDexElement = Array.get(dexElements, 0);
Array.set(newDexElements, 0, firstDexElement);
for (int i = 0; i < dexLength - 1; ++i) {
Object element = Array.get(dstObject, i);
Array.set(newDexElements, i + 1, element);
}
if (VERSION.SDK_INT >= 14) {
fDexElements.set(pathListField.get(classLoader), newDexElements);
} else {
pathListField.set(classLoader, newDexElements);
}
return true;
} catch (Exception e) {
Log.e(TAG, "fail to override classloader " + classLoader + " with " + dex.getAbsolutePath(), e);
return false;
}
}
use of java.lang.reflect.Field in project freeline by alibaba.
the class ReflectUtil method fieldGetOrg.
public static Field fieldGetOrg(Object object, String name) throws Exception {
Field field = object.getClass().getDeclaredField(name);
field.setAccessible(true);
return field;
}
Aggregations