harpoon.ClassFile
Class Relinker

java.lang.Object
  extended by harpoon.ClassFile.Linker
      extended by harpoon.ClassFile.Relinker
All Implemented Interfaces:
Serializable, ReferenceUnique
Direct Known Subclasses:
AbstractClassFixupRelinker

public class Relinker
extends Linker
implements Serializable

A Relinker object is a Linker where one can globally replace references to a certain class with references to another, different, class.

Version:
$Id: Relinker.java,v 1.6 2004/02/08 05:09:46 cananian Exp $
Author:
C. Scott Ananian <cananian@alumni.princeton.edu>
See Also:
Serialized Form

Field Summary
protected  Linker linker
           
 
Fields inherited from class harpoon.ClassFile.Linker
descCache
 
Constructor Summary
Relinker(Linker linker)
          Creates a Relinker.
 
Method Summary
 HClass createMutableClass(String name, HClass template)
          Creates a mutable class with the given name which is based on the given template class.
protected  HClass forDescriptor0(String descriptor)
          Sub-classes will provide implementation for the forDescriptor0 method in order to implement a linking strategy.
protected  HClass makeArray(HClass baseType, int dims)
          Allow Linker subclass to substitute a different (mutable?)
 void move(HMember hm, HClass newDestination)
          Move HMember hm from its declaring class to some other class, newDestination.
 void relink(HClass oldClass, HClass newClass)
          Globally replace all references to oldClass with references to newClass, which may or may not have the same name.
 
Methods inherited from class harpoon.ClassFile.Linker
forClass, forDescriptor, forName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

linker

protected final Linker linker
Constructor Detail

Relinker

public Relinker(Linker linker)
Creates a Relinker.

Method Detail

forDescriptor0

protected HClass forDescriptor0(String descriptor)
Description copied from class: Linker
Sub-classes will provide implementation for the forDescriptor0 method in order to implement a linking strategy. This method is only passed descriptors for class types; never array or primitive type descriptors. (Hence neither primitive types or array types can be re-linked, which might violate java language semantics.)

Specified by:
forDescriptor0 in class Linker

makeArray

protected HClass makeArray(HClass baseType,
                           int dims)
Description copied from class: Linker
Allow Linker subclass to substitute a different (mutable?) array class type.

Overrides:
makeArray in class Linker

createMutableClass

public HClass createMutableClass(String name,
                                 HClass template)
Creates a mutable class with the given name which is based on the given template class. The name need not be unique. If a class with the given name already exists, all references to the existing class are changed to point to the new mutable class returned by this method.

Overrides:
createMutableClass in class Linker

relink

public void relink(HClass oldClass,
                   HClass newClass)
Globally replace all references to oldClass with references to newClass, which may or may not have the same name. The following constraint must hold:
  oldClass.getLinker()==newClass.getLinker()==this
  

WARNING: the hasBeenModified() method of HClassis not reliable after calling relink() if oldClass.getName() is not the same as newClass.getName(). The value returned by HClass.hasBeenModified() will not reflect changes due to the global replacement of oldClass with newClass done by this relink().


move

public void move(HMember hm,
                 HClass newDestination)
          throws DuplicateMemberException
Move HMember hm from its declaring class to some other class, newDestination. This usually only makes sense if you're moving a member from a class to its superclass, or vice-versa --- but we're not enforcing this (full foot-shooting power granted). The newDestination class must not already have a field named the same/method with the same signature as hm. All references to the member in the old class will be re-directed to point to the member in the new class, and in fact, upon return the given HMember hm will refer to the new member. WARNING: make sure that any methods which refer to this member have been converted to Bytecode form at least *before* invoking move(); otherwise field resolution will fail when we are parsing the bytecode file (we don't keep any record of the 'old' or 'canonical' name of the moved member).

Throws:
DuplicateMemberException