edu.umd.cs.findbugs.ba
Class InnerClassAccessMap

java.lang.Object
  extended by edu.umd.cs.findbugs.ba.InnerClassAccessMap

public class InnerClassAccessMap
extends java.lang.Object

Singleton class to determine which methods are accessors used by inner classes to access fields in their enclosing classes. This has been tested with javac from the Sun JDK 1.4.x, but will probably not work with other source to bytecode compilers.

Author:
David Hovemeyer
See Also:
InnerClassAccess

Nested Class Summary
private static class InnerClassAccessMap.InstructionCallback
          Callback to scan an access method to determine what field it accesses, and whether the field is loaded or stored.
private static class InnerClassAccessMap.LookupFailure
           
 
Field Summary
private  java.util.Map<java.lang.String,java.util.Map<java.lang.String,InnerClassAccess>> classToAccessMap
          Map of class names to maps of method names to InnerClassAccess objects representing access methods.
private static boolean DEBUG
           
private static java.util.Map<java.lang.String,InnerClassAccess> emptyMap
           
private static InnerClassAccessMap instance
          The single instance.
 
Constructor Summary
private InnerClassAccessMap()
          Constructor.
 
Method Summary
 void clearCache()
          Clear the cache.
private  java.util.Map<java.lang.String,InnerClassAccess> getAccessMapForClass(java.lang.String className)
          Return a map of inner-class member access method names to the fields that they access for given class name.
private static int getIndex(byte[] instructionList, int index)
          Get an unsigned 16 bit constant pool index from a byte array.
 InnerClassAccess getInnerClassAccess(org.apache.bcel.generic.INVOKESTATIC inv, org.apache.bcel.generic.ConstantPoolGen cpg)
          Get the inner class access object for given invokestatic instruction.
 InnerClassAccess getInnerClassAccess(java.lang.String className, java.lang.String methodName)
          Get the InnerClassAccess in given class with the given method name.
static InnerClassAccessMap instance()
          Get the single instance.
private static int toInt(byte b)
          Convert byte to unsigned int.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

private static final boolean DEBUG

classToAccessMap

private java.util.Map<java.lang.String,java.util.Map<java.lang.String,InnerClassAccess>> classToAccessMap
Map of class names to maps of method names to InnerClassAccess objects representing access methods.


instance

private static InnerClassAccessMap instance
The single instance.


emptyMap

private static final java.util.Map<java.lang.String,InnerClassAccess> emptyMap
Constructor Detail

InnerClassAccessMap

private InnerClassAccessMap()
Constructor.

Method Detail

instance

public static InnerClassAccessMap instance()
Get the single instance.


getInnerClassAccess

public InnerClassAccess getInnerClassAccess(java.lang.String className,
                                            java.lang.String methodName)
                                     throws java.lang.ClassNotFoundException
Get the InnerClassAccess in given class with the given method name.

Parameters:
className - the name of the class
methodName - the name of the access method
Returns:
the InnerClassAccess object for the method, or null if the method doesn't seem to be an inner class access
Throws:
java.lang.ClassNotFoundException

getInnerClassAccess

public InnerClassAccess getInnerClassAccess(org.apache.bcel.generic.INVOKESTATIC inv,
                                            org.apache.bcel.generic.ConstantPoolGen cpg)
                                     throws java.lang.ClassNotFoundException
Get the inner class access object for given invokestatic instruction. Returns null if the called method is not an inner class access.

Parameters:
inv - the invokestatic instruction
cpg - the ConstantPoolGen for the method
Returns:
the InnerClassAccess, or null if the call is not an inner class access
Throws:
java.lang.ClassNotFoundException

clearCache

public void clearCache()
Clear the cache.


toInt

private static int toInt(byte b)
Convert byte to unsigned int.


getIndex

private static int getIndex(byte[] instructionList,
                            int index)
Get an unsigned 16 bit constant pool index from a byte array.


getAccessMapForClass

private java.util.Map<java.lang.String,InnerClassAccess> getAccessMapForClass(java.lang.String className)
                                                                       throws java.lang.ClassNotFoundException
Return a map of inner-class member access method names to the fields that they access for given class name.

Parameters:
className - the name of the class
Returns:
map of access method names to the fields they access
Throws:
java.lang.ClassNotFoundException