AccessibleObject setAccessible - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for AccessibleObject setAccessible method.

This code example shows how to use the following methods:setAccessible, get
 
	private static int getImageViewFieldValue(Object object, String fieldName) {
		int value = 0;
		try { 
			Field field = ImageView.class.getDeclaredField(fieldName);
			field.setAccessible(true);
			int fieldValue = (Integer) field.get(object);
			if (fieldValue > 0 && fieldValue < Integer.MAX_VALUE) {
				value = fieldValue;
			} 
		} catch (Exception e) {
			L.e(e);
		} 
		return value;
	} 
 
	@Override 
	public boolean setImageDrawable(Drawable drawable) {
		ImageView imageView = imageViewRef.get();
		if (imageView != null) {
10
CodeRank
This code example shows how to use the following methods:setAccessible
		} 
 
		try { 
			cdBackgroundStateColorField = cdBackgroundStateField.getType()
					.getDeclaredField(COLOR_DRAWABLE_USE_COLOR_VAR);
			cdBackgroundStateColorField.setAccessible(true);
		} catch (Exception e) {
			Log.e(TAG,
					"Reflection failed while trying to determine background color of view.", 
					e);
			cdBackgroundStateColorField = null;
			return; 
		} 
 
	} 
 
	private int getColorFromColorDrawable(ColorDrawable colorDrawable)
	{ 
		if (IS_HONEYCOMB_OR_GREATER) {
			return getColorFromColorDrawableHC(colorDrawable);
9
CodeRank
This code example shows how to use the following methods:isAccessible, setAccessible, getName
    public void injectField (Field field, Object injectable)
    {            
        try 
        { 
            //validateInjection(field, injectable); 
            boolean accessibility = field.isAccessible();
            field.setAccessible(true);
            field.set(injectable, lookupInjectedValue());
            field.setAccessible(accessibility);
        } 
        catch (Exception e)
        { 
            Log.warn(e);
            throw new IllegalStateException("Inject failed for field "+field.getName());
        } 
    } 
     
    /** 
     * Inject value from jndi into a setter method of an instance 
     * @param method 
9
CodeRank
This code example shows how to use the following methods:setAccessible, get
public class ReflectionUtil { 
 
    public static Object getFieldValue(Object object, String fieldName) {
        try { 
            Field field = object.getClass().getDeclaredField(fieldName);
            field.setAccessible(true);
            return field.get(object);
        } catch (Exception e) {
            throw new RuntimeException(e);
        } 
    } 
} 
8
CodeRank
This code example shows how to use the following methods:setAccessible, get, getName
	} 
 
	@Override 
	public Object getFieldValue(Object object, Field field) {
		try { 
			field.setAccessible(true);
			return field.get(object);
		} catch (IllegalArgumentException e) {
			throw new InfinitumRuntimeException("Unable to access field '" + field.getName() + "' for object of type '"
					+ object.getClass().getName() + "'.", e);
		} catch (IllegalAccessException e) {
			throw new InfinitumRuntimeException("Unable to access field '" + field.getName() + "' for object of type '"
					+ object.getClass().getName() + "'.", e);
		} 
	} 
 
	@Override 
	public Object invokeMethod(Object receiver, Method method, Object... args) {
		try { 
			method.setAccessible(true);
8
CodeRank
This code example shows how to use the following methods:setAccessible
	  if (initialized)
	    return; 
	  initialized = true;
	  try { 
	    Field f = _NSUtilities.class.getDeclaredField("_classesByPartialName");
	    f.setAccessible(true);
	    classesByPartialName = f.get(null);
	    f = WOAction.class.getDeclaredField("_actionClasses");
	    f.setAccessible(true);
	    actionClassCache = (_NSThreadsafeMutableDictionary) f.get(null);
	  } catch (Exception e) {
	    e.printStackTrace();
	  } 
	} 
 
	static { 
	  initialize(); 
	} 
} 
8
CodeRank
This code example shows how to use the following methods:setAccessible
   
  private static Object getFactoryClassInstance(String factoryClassName) {
    try { 
      Class<?> clazz = Class.forName(factoryClassName);
      Method method = clazz.getMethod("get", null);
      method.setAccessible(true);
      return method.invoke(null, null);
    } catch (ClassNotFoundException e) {
      throw new YarnRuntimeException(e);
    } catch (NoSuchMethodException e) {
      throw new YarnRuntimeException(e);
    } catch (InvocationTargetException e) {
      throw new YarnRuntimeException(e);
    } catch (IllegalAccessException e) {
      throw new YarnRuntimeException(e);
    } 
  } 
} 
7
CodeRank
This code example shows how to use the following methods:setAccessible, get
This code example shows how to use the following methods:setAccessible, newInstance
    /** 
     * Returns an instance of T, constructed using this constructor, with the 
     * supplied arguments. 
     */ 
    public T newInstance(Object[] args) throws Throwable {
        constructor.setAccessible(true);
        try { 
            return constructor.newInstance(args);
        } catch (InvocationTargetException e) {
            throw e.getCause();
        } 
    } 
 
    @Override 
    public String toString() {
        return constructor.toString();
    } 
} 
8
CodeRank
This code example shows how to use the following methods:setAccessible, invoke

Related AccessibleObject setAccessible Questions & Answers:

setAccessible Method Overview
Set the accessible flag for this object to the indicated boolean value.
See Code Examples for other Java 8 AccessibleObject Methods: