Changeset 3051


Ignore:
Timestamp:
08/06/07 16:30:27 (13 years ago)
Author:
curtis
Message:

Add option to brute force past accessibility restrictions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/loci/formats/ReflectedUniverse.java

    r3050 r3051  
    4646  /** Class loader for imported classes. */ 
    4747  protected ClassLoader loader; 
     48 
     49  /** Whether to force our way past restrictive access modifiers. */ 
     50  protected boolean force; 
    4851 
    4952  /** Debugging flag. */ 
     
    8992  } 
    9093 
    91   // -- API methods -- 
     94  // -- ReflectedUniverse API methods -- 
    9295 
    9396  /** 
     
    200203      Constructor[] c = cl.getConstructors(); 
    201204      for (int i=0; i<c.length; i++) { 
     205        if (force) c[i].setAccessible(true); 
    202206        Class[] params = c[i].getParameterTypes(); 
    203207        if (params.length == args.length) { 
     
    254258      Method[] m = varClass.getMethods(); 
    255259      for (int i=0; i<m.length; i++) { 
     260        if (force) m[i].setAccessible(true); 
    256261        if (methodName.equals(m[i].getName())) { 
    257262          Class[] params = m[i].getParameterTypes(); 
     
    388393      try { 
    389394        field = varClass.getField(fieldName); 
     395        if (force) field.setAccessible(true); 
    390396      } 
    391397      catch (NoSuchFieldException exc) { 
     
    409415    } 
    410416  } 
     417 
     418  /** Sets whether access modifiers (protected, private, etc.) are ignored. */ 
     419  public void setAccessibilityIgnored(boolean ignore) { force = ignore; } 
     420 
     421  /** Gets whether access modifiers (protected, private, etc.) are ignored. */ 
     422  public boolean isAccessibilityIgnored() { return force; } 
    411423 
    412424  /** Enables or disables extended debugging output. */ 
     
    425437    LogTools.println("Reflected universe test environment. " + 
    426438      "Type commands, or press ^D to quit."); 
     439    if (args.length > 0) { 
     440      r.setAccessibilityIgnored(true); 
     441      LogTools.println("Ignoring accessibility modifiers."); 
     442    } 
    427443    BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); 
    428444    while (true) { 
Note: See TracChangeset for help on using the changeset viewer.