Evaluating Software Design Patterns
— the "Gang of Four" patterns implemented in Java 6

dk.rode.thesis.meta.reflect
Class Caller.MemberContext

java.lang.Object
  extended by dk.rode.thesis.meta.reflect.Caller.MemberContext
Enclosing class:
Caller

public static final class Caller.MemberContext
extends Object

A member context represents a member in a given calling context, which may or may not be uniquely resolved.

The member represents a static initialiser block, an instance initialiser block, a constructor, or a method. The type is determined via the type attribute.

If the member is uniquely resolved, the resolved member is stored in the member attribute, and the resolved attribute is true. If not uniquely resolved, resolved is false, and member contains the first matching candidate.

It will not be possible to uniquely resolve a member in case the calling context represents an overloaded method; a constructor and/or instance initialisation block declared in a class that declares multiple constructors and/or initialisation blocks; or a static initialisation block declared in a class that declares several static initialisation blocks. Furthermore, there is no Member instance corresponding to an initialisation block, static or otherwise. For instance initialisation blocks, the Constructor class is used. For static initialisation blocks, member is null and the candidate array is empty, and type is set to Caller.CallerType.INITIALISATION.

The line number of the member in question is unique and is stored in the lineNumber attribute.

Author:
Gunni Rode / rode.dk

Field Summary
protected  Member[] candidates
          The possible member candidates for the member represented by this member context.
private  StackTraceElement element
          The stack trace element element identifying the member for this member context.
 int lineNumber
          The line number of the stack trace element identifying the member used by this member context.
 Member member
          The member represented by this member context.
 boolean resolved
          True if member has been uniquely resolved for this member context, false if not.
 Caller.CallerType type
          The identified member type of this member context.
 
Constructor Summary
Caller.MemberContext(StackTraceElement element)
          Constructor, which creates this member context to represent the member identified by the stack trace element supplied as element.
 
Method Summary
 boolean equals(Object object)
          Returns true if object is an instance of this class identifying a member based on an equal stack trace element, false if not.
 Member[] getCandidates()
          Returns the possible candidates that match the member this member context tries to identify.
 int hashCode()
          Returns the hash code of this member context.
 String toString()
          Returns the string representation of this member context.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

candidates

protected final Member[] candidates
The possible member candidates for the member represented by this member context.

If resolved is true, the single element contained is member.

If this member context represents a static initialisation block, the array is empty.

The order of the candidates is their declaration order.


element

private final StackTraceElement element
The stack trace element element identifying the member for this member context.

Never null.


lineNumber

public final int lineNumber
The line number of the stack trace element identifying the member used by this member context.


member

public final Member member
The member represented by this member context.

If resolved is true, the member is uniquely resolved, not if false.

If resolved is false, the possible candidates can be retrieved with getCandidates(), and the first member from the candidate array is stored in this attribute.

Will be null in case this member context represents a static initialisation block, but a Constructor instance in case this member context represents an instance initialisation block.


resolved

public final boolean resolved
True if member has been uniquely resolved for this member context, false if not.


type

public final Caller.CallerType type
The identified member type of this member context.

Never null.

Constructor Detail

Caller.MemberContext

Caller.MemberContext(StackTraceElement element)
Constructor, which creates this member context to represent the member identified by the stack trace element supplied as element.

Parameters:
element - The stack trace element identifying the member; cannot be null.
Throws:
NullPointerException - If element is null.
Method Detail

equals

public boolean equals(Object object)
Returns true if object is an instance of this class identifying a member based on an equal stack trace element, false if not.

Overrides:
equals in class Object

getCandidates

public Member[] getCandidates()
Returns the possible candidates that match the member this member context tries to identify.

If resolved is true, the returned array will only contain member.

If this member context represents a static initialisation block, the returned array will be empty. If it represents an instance initialisation block, the returned array contains all declared constructors.

The order of the candidates is their declaration order.

Modifying the returned array will not affect this member context.

Returns:
The candidates; never null, but but can be empty if this member context represents a static initialisation block.

hashCode

public int hashCode()
Returns the hash code of this member context.

Overrides:
hashCode in class Object
Returns:
The hash code.

toString

public String toString()
Returns the string representation of this member context.

The representation corresponds to that of the stack trace element used to identify the actual member.

Overrides:
toString in class Object
Returns:
The string representation; never null.

Gunni Rode / rode.dk

Feel free to use and/or modify the Java 6 source code developed for this thesis AT YOUR OWN RISK, but note that the source code comes WITHOUT ANY — and I do mean WITHOUT ANY — form of warranty WHAT SO EVER!

The original thesis and source code are available at rode.dk/thesis.