Search in sources :

Example 66 with Field

use of java.lang.reflect.Field in project freeline by alibaba.

the class ReflectUtil method fieldGet.

public static Object fieldGet(Object object, String fieldName) throws Exception {
    Field field = object.getClass().getDeclaredField(fieldName);
    field.setAccessible(true);
    return field.get(object);
}
Also used : Field(java.lang.reflect.Field)

Example 67 with Field

use of java.lang.reflect.Field in project freeline by alibaba.

the class ReflectUtil method fieldSet.

public static void fieldSet(Object object, Class<?> clazz, String fieldName, Object value) throws Exception {
    Field field = clazz.getDeclaredField(fieldName);
    field.setAccessible(true);
    field.set(object, value);
}
Also used : Field(java.lang.reflect.Field)

Example 68 with Field

use of java.lang.reflect.Field in project freeline by alibaba.

the class ReflectUtil method fieldGet.

public static Object fieldGet(Object object, Class<?> clazz, String fieldName) throws Exception {
    Field field = clazz.getDeclaredField(fieldName);
    field.setAccessible(true);
    return field.get(object);
}
Also used : Field(java.lang.reflect.Field)

Example 69 with Field

use of java.lang.reflect.Field in project freeline by alibaba.

the class FreelineCore method getPackageInfo.

private static Object getPackageInfo(Application app) throws NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
    Context contextImpl = app.getBaseContext();
    Field mPackageInfoField = contextImpl.getClass().getDeclaredField("mPackageInfo");
    mPackageInfoField.setAccessible(true);
    Object mPackageInfo = mPackageInfoField.get(contextImpl);
    return mPackageInfo;
}
Also used : Context(android.content.Context) Field(java.lang.reflect.Field)

Example 70 with Field

use of java.lang.reflect.Field in project dbeaver by serge-rider.

the class DBIcon method loadIcons.

public static void loadIcons(Class<?> aClass) {
    Bundle iconBundle = FrameworkUtil.getBundle(aClass);
    if (iconBundle == null) {
        log.error("Can't find bundle for class '" + aClass.getName() + "'");
        return;
    }
    for (Field field : aClass.getDeclaredFields()) {
        if ((field.getModifiers() & Modifier.STATIC) == 0 || field.getType() != DBIcon.class) {
            continue;
        }
        try {
            DBIcon icon = (DBIcon) field.get(null);
            if (!icon.path.startsWith("platform:")) {
                icon.path = "platform:/plugin/" + iconBundle.getSymbolicName() + "/icons/" + icon.path;
            }
            URL fileURL = FileLocator.toFileURL(new URL(icon.path));
            try {
                String filePath = fileURL.toString().replace(" ", "%20");
                File file = new File(new URI(filePath));
                if (!file.exists()) {
                    log.warn("Bad image '" + icon.getToken() + "' location: " + icon.getLocation());
                    continue;
                }
                DBIcon.iconMap.put(icon.getToken(), icon);
            } catch (URISyntaxException e) {
                throw new IOException("Bad local file path: " + fileURL, e);
            }
        } catch (Exception e) {
            log.error(e);
        }
    }
}
Also used : Field(java.lang.reflect.Field) Bundle(org.osgi.framework.Bundle) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) File(java.io.File) URI(java.net.URI) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException)

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