de.uka.ipd.sdq.ByCounter.utils
Class MethodDescriptor

java.lang.Object
  extended by de.uka.ipd.sdq.ByCounter.utils.MethodDescriptor
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<MethodDescriptor>

public final class MethodDescriptor
extends java.lang.Object
implements java.lang.Comparable<MethodDescriptor>, java.io.Serializable

Unambiguous description for a method in bytecode compatible format. Such a signature can be constructed through the constructor MethodDescriptor(..) and for constructor descriptions through the method forConstructor(..). The descriptor returned by getDescriptor() does not contain a reference to the containing class anymore.

Since:
0.1
Version:
1.3
Author:
Michael Kuperberg, Martin Krogmann, Florian Schreier
See Also:
MethodDescriptor(String, String), Serialized Form

Constructor Summary
MethodDescriptor(java.lang.reflect.Constructor<?> c)
          Constructs a MethodDescriptor directly from a Java reflection Constructor.
MethodDescriptor(java.lang.reflect.Method m)
          Constructs a MethodDescriptor directly from a Java reflection Method.
MethodDescriptor(java.lang.String canonicalClassName, java.lang.String signature)
          Construct a MethodDescriptor from a Java method signature.
 
Method Summary
static MethodDescriptor _constructMethodDescriptorFromASM(java.lang.String owner, java.lang.String name, java.lang.String desc)
          Construct a MethodDescriptor instance from the details known by ASM.
static java.lang.String[] canonicalClassNameToPackageAndSimpleName(java.lang.String className)
          Splits the canonical classname to the package name and the simple class name.
 int compareTo(MethodDescriptor o)
           
 boolean equals(java.lang.Object obj)
          Checks for equaling class name, method name, package name and descriptor.
static int findMethodInList(java.util.List<MethodDescriptor> listToSearch, java.lang.String canonicalClassName, java.lang.String name, java.lang.String desc)
          Check whether a method matching the given description is contained in the list of methods to instrument and return it's index.
 java.lang.String getCanonicalClassName()
           
 java.lang.String getCanonicalMethodName()
           
 java.lang.String getClassName()
           
 LineNumberRange[] getCodeAreasToInstrument()
          When the specified areas are not null and not empty, only these areas of the method will be instrumented.
 java.util.UUID getContext()
           
 java.lang.String getDescriptor()
          Gets the descriptor string as used in Java bytecode for descriptor.
 boolean getIsConstructor()
           
 boolean getMethodIsStatic()
           
 java.lang.String getMethodSignature()
          Gets the simple method signature of the described method (i.e. without package and/or class names).
 java.lang.String getPackageName()
           
static JavaType[] getParametersTypesFromDesc(java.lang.String desc)
           
 java.lang.String getQualifyingMethodName()
          Gets the qualifying method name of the described method (yet without the descriptors, i.e. without the input/output parameters).
 java.lang.String getQualifyingMethodSignature()
          Gets the qualifying method signature of the described method.
static JavaType getReturnTypeFromDesc(java.lang.String desc)
           
 java.lang.String getSimpleClassName()
           
 java.lang.String getSimpleMethodName()
          Gets the simple method name of the described method.
 boolean isConstructor()
           
 boolean isInlineImmediately()
           
 boolean isInvariant()
           
static java.lang.String removeGenericTyping(java.lang.String signature)
          Used for parsing from a Java signature.
 void setCodeAreasToInstrument(LineNumberRange[] codeAreasToInstrument)
          When the specified areas are not null and not empty, only these areas of the method will be instrumented.
 void setContext(java.util.UUID context)
           
 void setInlineImmediately(boolean inlineImmediately)
          Some methods (e.g. those invariant w.r.t. bytecode counts, irrespective of parameters, if any) may not warrant an own CountingResult object, and their counts should be "inlined" immediately instead.
 void setInvariant(boolean isInvariant)
          Some methods are invariant w.r.t. bytecode counts, i.e. their runtime bytecode counts is constant (invariant) irrespective of method input parameters (if any).
 void setPackageName(java.lang.String packageName)
          Change the package name to describe a different method.
 void setSimpleClassName(java.lang.String className)
          Change the class name to describe a different method.
 java.lang.String toString_Linebreaks()
          Multi line string with the basic properties of this MethodDescriptor.
 java.lang.String toString()
          One line string with the basic properties of this MethodDescriptor.
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MethodDescriptor

public MethodDescriptor(java.lang.reflect.Constructor<?> c)
Constructs a MethodDescriptor directly from a Java reflection Constructor.

Parameters:
c - Constructor that is described by the MethodDescriptor.

MethodDescriptor

public MethodDescriptor(java.lang.reflect.Method m)
Constructs a MethodDescriptor directly from a Java reflection Method.

Parameters:
m - Method that is described by the MethodDescriptor.

MethodDescriptor

public MethodDescriptor(java.lang.String canonicalClassName,
                        java.lang.String signature)
Construct a MethodDescriptor from a Java method signature. It is able to handle both static and non-static method and constructors.

Parameters:
canonicalClassName - The canonical name of the class declaring the method.
signature - A string containing a standard Java method signature with fully qualified types. For example: public static java.lang.String[] canonicalClassNameToPackageAndSimpleName(java.lang.String className)

Qualifiers defining visibility (like public) may be omitted (and are ignored), while the qualifier static is handled. For method parameters, it is allowed to provide just the type or the type and its name (example: int[] or int[] abc). Generic types may be omitted (and are ignored) so that List and List<Integer> are treated as the same since bytecode signatures ignore generics. It is advised to take the method signature from source code or from documentation and only adapt it, if necessary.

Important: The names of object types need to be adapted! So instead of giving the String String myString, this has to be expanded to java.lang.String myString. Note that inner/nested classes need to be specified using the '$' symbol as in the following example: my.packagename.OutClass$InnerClass.

Method Detail

_constructMethodDescriptorFromASM

public static MethodDescriptor _constructMethodDescriptorFromASM(java.lang.String owner,
                                                                 java.lang.String name,
                                                                 java.lang.String desc)
Construct a MethodDescriptor instance from the details known by ASM.
Build for internal use only.

Parameters:
owner -
name -
desc -
Returns:
The MethodDescriptor for the specified method.

canonicalClassNameToPackageAndSimpleName

public static java.lang.String[] canonicalClassNameToPackageAndSimpleName(java.lang.String className)
Splits the canonical classname to the package name and the simple class name.

Parameters:
className - Canonical class name.
Returns:
An array of two string. The first element is the package name. The second element is the simple class name.

findMethodInList

public static int findMethodInList(java.util.List<MethodDescriptor> listToSearch,
                                   java.lang.String canonicalClassName,
                                   java.lang.String name,
                                   java.lang.String desc)
Check whether a method matching the given description is contained in the list of methods to instrument and return it's index.

Parameters:
listToSearch - The MethodDescriptor list to search.
canonicalClassName - The fully qualified class name of the class containing the method.
name - Simple method name (not qualified). For example: getIndexOfMethodMatch.
desc - A method descriptor as used by Java bytecode. For example: (Ljava/lang/String;Ljava/lang/String;)Z
Returns:
The index of the method if it matches a method description in the InstrumentationParameters. When no matching method is found, -1 is returned.

getParametersTypesFromDesc

public static JavaType[] getParametersTypesFromDesc(java.lang.String desc)
Parameters:
desc - A parameter descriptor string as used in Java bytecode.
Returns:
An array with length=(nr of parameters) where the entry at index i reflects the type of the parameter at index i.

getReturnTypeFromDesc

public static JavaType getReturnTypeFromDesc(java.lang.String desc)
Parameters:
desc - A return value descriptor string as used in Java bytecode.
Returns:
The type that of the return value.

removeGenericTyping

public static java.lang.String removeGenericTyping(java.lang.String signature)
Used for parsing from a Java signature. Since generic types are not respected at bytecode signature level, remove those declarations from the signature.

Parameters:
signature - A Java signature.
Returns:
The cleaned signature.

compareTo

public int compareTo(MethodDescriptor o)
Specified by:
compareTo in interface java.lang.Comparable<MethodDescriptor>

equals

public boolean equals(java.lang.Object obj)
Checks for equaling class name, method name, package name and descriptor.

Overrides:
equals in class java.lang.Object

getCanonicalClassName

public java.lang.String getCanonicalClassName()
Returns:
The canonical name of the class declaring the method.

getCanonicalMethodName

public java.lang.String getCanonicalMethodName()
Returns:
A descriptor string to uniquely identify methods consisting of the canonical classname, the method name and the method descriptor.

getClassName

public java.lang.String getClassName()
Returns:
Simple name of the class containing the method.

getCodeAreasToInstrument

public LineNumberRange[] getCodeAreasToInstrument()
When the specified areas are not null and not empty, only these areas of the method will be instrumented.

Returns:
Line numbers that define the instruction blocks that are to be considered as range blocks.
See Also:
InstrumentationParameters.getUseBasicBlocks()

getContext

public java.util.UUID getContext()
Returns:
A UUID for this instance of the MethodDescriptor. This can be used to provide context to the counting of the specified method. Used for debugging at this point.

getDescriptor

public java.lang.String getDescriptor()
Gets the descriptor string as used in Java bytecode for descriptor. The descriptor returned does not contain a reference to the containing class anymore.

Returns:
The method descriptor string.

getIsConstructor

public boolean getIsConstructor()
Returns:
True if the described method is a constructor; false otherwise.

getMethodIsStatic

public boolean getMethodIsStatic()
Returns:
When true, the method described is static.

getMethodSignature

public java.lang.String getMethodSignature()
Gets the simple method signature of the described method (i.e. without package and/or class names).

Returns:
The method signature.

getPackageName

public java.lang.String getPackageName()
Returns:
The package name.

getQualifyingMethodName

public java.lang.String getQualifyingMethodName()
Gets the qualifying method name of the described method (yet without the descriptors, i.e. without the input/output parameters).

Returns:
The method name.

getQualifyingMethodSignature

public java.lang.String getQualifyingMethodSignature()
Gets the qualifying method signature of the described method. This consists of the qualifying method name ( getQualifyingMethodName()) and the descriptor (getDescriptor(); i.e. with the types of input/output parameters).

Returns:
The method signature.

getSimpleClassName

public java.lang.String getSimpleClassName()
Returns:
The simple name of the class declaring the method.

getSimpleMethodName

public java.lang.String getSimpleMethodName()
Gets the simple method name of the described method.

Returns:
The method name.

isConstructor

public boolean isConstructor()
Returns:
True iff the method was found to be a constructor.

isInlineImmediately

public boolean isInlineImmediately()
See Also:
setInlineImmediately(boolean)

isInvariant

public boolean isInvariant()
See Also:
setInvariant(boolean)

setCodeAreasToInstrument

public void setCodeAreasToInstrument(LineNumberRange[] codeAreasToInstrument)
When the specified areas are not null and not empty, only these areas of the method will be instrumented.

Parameters:
codeAreasToInstrument - Line numbers that define the instruction blocks that are to be considered as range blocks.
See Also:
InstrumentationParameters.getUseBasicBlocks()

setContext

public void setContext(java.util.UUID context)
Parameters:
context - A new context UUID to set, replacing the old one.
See Also:
getContext()

setInlineImmediately

public void setInlineImmediately(boolean inlineImmediately)
Some methods (e.g. those invariant w.r.t. bytecode counts, irrespective of parameters, if any) may not warrant an own CountingResult object, and their counts should be "inlined" immediately instead.

Parameters:
inlineImmediately - When true, inlining of this method is active.

setInvariant

public void setInvariant(boolean isInvariant)
Some methods are invariant w.r.t. bytecode counts, i.e. their runtime bytecode counts is constant (invariant) irrespective of method input parameters (if any).

Parameters:
isInvariant - True marks the method as invariant.

setPackageName

public void setPackageName(java.lang.String packageName)
Change the package name to describe a different method.

Parameters:
packageName - The package name to change to.
See Also:
getPackageName()

setSimpleClassName

public void setSimpleClassName(java.lang.String className)
Change the class name to describe a different method.

Parameters:
className - The class name to change to.
See Also:
getSimpleClassName()

toString

public java.lang.String toString()
One line string with the basic properties of this MethodDescriptor.

Overrides:
toString in class java.lang.Object

toString_Linebreaks

public java.lang.String toString_Linebreaks()
Multi line string with the basic properties of this MethodDescriptor.