Search in sources :

Example 61 with Field

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 + "!");
            }
        }
    }
}
Also used : Field(java.lang.reflect.Field) Annotation(java.lang.annotation.Annotation)

Example 62 with Field

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);
            }
        }
    }
}
Also used : Field(java.lang.reflect.Field) Annotation(java.lang.annotation.Annotation)

Example 63 with 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);
    }
}
Also used : Field(java.lang.reflect.Field) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 64 with Field

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;
    }
}
Also used : Field(java.lang.reflect.Field) DexClassLoader(dalvik.system.DexClassLoader) DexFile(dalvik.system.DexFile)

Example 65 with Field

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;
}
Also used : Field(java.lang.reflect.Field)

Aggregations

Field (java.lang.reflect.Field)5144 Method (java.lang.reflect.Method)613 Test (org.junit.Test)538 ArrayList (java.util.ArrayList)490 IOException (java.io.IOException)318 HashMap (java.util.HashMap)318 Map (java.util.Map)296 InvocationTargetException (java.lang.reflect.InvocationTargetException)176 List (java.util.List)171 Pattern (java.util.regex.Pattern)122 Matcher (java.util.regex.Matcher)117 HashSet (java.util.HashSet)109 File (java.io.File)107 Annotation (java.lang.annotation.Annotation)98 Support_Field (tests.support.Support_Field)82 Collection (java.util.Collection)81 Test (org.testng.annotations.Test)68 Type (java.lang.reflect.Type)67 SienaException (siena.SienaException)65 Before (org.junit.Before)62