com.google.testing.instrumentation
Class InstrumentedClassLoader

java.lang.Object
  extended by java.lang.ClassLoader
      extended by com.google.testing.instrumentation.InstrumentedClassLoader

public final class InstrumentedClassLoader
extends ClassLoader

A custom ClassLoader that performs byte-code instrumentation on all loaded classes.

Author:
alasdair.mackintosh@gmail.com (Alasdair Mackintosh)

Constructor Summary
InstrumentedClassLoader(Instrumenter instrumenter)
          Creates a new instrumented class loader using the given Instrumenter.
 
Method Summary
 Class<?> findClass(String className)
           
 Class<?> getExpectedClass(String name)
          Loads a class, and throws an IllegalArgumentException if the class cannot be loaded.
protected  Class<?> loadClass(String name, boolean resolve)
           
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findResource, findResources, findSystemClass, getPackage, getPackages, getParent, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InstrumentedClassLoader

public InstrumentedClassLoader(Instrumenter instrumenter)
Creates a new instrumented class loader using the given Instrumenter. All classes loaded by this loader will have their byte-code passed through the Instrumenter.instrument(java.lang.String, byte[]) method.

Parameters:
instrumenter - the instrumenter
Method Detail

getExpectedClass

public Class<?> getExpectedClass(String name)
Loads a class, and throws an IllegalArgumentException if the class cannot be loaded. Useful for classes which we expect to be able to find, e.g. for currently loaded classes that are being reloaded by this InstrumentedClassLoader.

Parameters:
name - the full name of the class
Returns:
the loaded class

loadClass

protected Class<?> loadClass(String name,
                             boolean resolve)
                      throws ClassNotFoundException
Overrides:
loadClass in class ClassLoader
Throws:
ClassNotFoundException

findClass

public Class<?> findClass(String className)
                   throws ClassNotFoundException
Overrides:
findClass in class ClassLoader
Throws:
ClassNotFoundException


Copyright © 2013. All Rights Reserved.