net.sf.jode.decompiler
Class MethodAnalyzer

java.lang.Object
  extended by net.sf.jode.decompiler.MethodAnalyzer
All Implemented Interfaces:
ClassDeclarer, Scope

public class MethodAnalyzer
extends Object
implements Scope, ClassDeclarer

A method analyzer is the main class for analyzation of methods. There is exactly one MethodAnalyzer object for each method (even for abstract methods), that should be decompiled. Method analyzation is done in three passes:

analyze()
the main analyzation, decompiles the code of the method
analyzeInners()
This will analyze method scopes classes by calling their analyze() and analyzeInners() methods.
makeDeclaration()
This will determine when to declare variables. For constructors it will do special transformations like field initialization.


Field Summary
 
Fields inherited from interface net.sf.jode.decompiler.Scope
AMBIGUOUSNAME, CLASSNAME, CLASSSCOPE, FIELDNAME, LOCALNAME, METHODNAME, METHODSCOPE, NOSUPERFIELDNAME, NOSUPERMETHODNAME, PACKAGENAME
 
Constructor Summary
MethodAnalyzer(ClassAnalyzer cla, MethodInfo minfo, ImportHandler imports)
          This is the default constructor.
 
Method Summary
 void addAnonymousConstructor(InvokeOperator cop)
          Registers an anonymous constructor invokation.
 void addClassAnalyzer(ClassAnalyzer clazzAna)
           
 void analyze(ProgressListener pl, double done, double scale)
          This is the first pass of the analyzation.
 void analyzeInnerClasses()
          This is the second pass of the analyzation.
 void analyzeInvokeOperator(InvokeOperator cop)
           
 boolean conflicts(String name, int usageType)
          Checks if the specified name conflicts with an object in this scope.
 void dumpSource(TabbedPrintWriter writer)
          Dumps the source code for this method to the specified writer.
 void fillDeclarables(Collection used)
          We add the named method scoped classes to the declarables.
 ClassAnalyzer findAnonClass(String name)
          Checks if a method scoped class with the given name exists in this method (not in a parent method).
 LocalInfo findLocal(String name)
          Checks if the variable set contains a local with the given name.
 BasicBlocks getBasicBlocks()
          Returns the bytecode info for this method.
 ClassAnalyzer getClassAnalyzer()
          Get the class analyzer for the class containing this method.
 ClassAnalyzer getClassAnalyzer(ClassInfo cinfo)
          Get the class analyzer for the given class info.
 ClassInfo getClazz()
          Get the class info for the class containing this method.
 double getComplexity()
          Gets the complexity of this class.
 ImportHandler getImportHandler()
          Returns the import handler.
 LocalInfo getLocalInfo(LocalVariableInfo lvi)
          Create a local info for a local variable located at an instruction with the given address.
 FlowBlock getMethodHeader()
          Returns the first flow block of the code.
 MethodInfo getMethodInfo()
           
 String getName()
          Returns the name of this method.
 int getParamCount()
          Return the number of parameters for this method.
 LocalInfo getParamInfo(int nr)
          Get the local info for a parameter.
 ClassDeclarer getParent()
          Gets the parent scope, i.e.
 Type getReturnType()
          Get the return type of this method.
 SyntheticAnalyzer getSynthetic()
          Get the synthetic analyzer for this method.
 MethodType getType()
          Returns the type of this method.
 void insertStructuredBlock(StructuredBlock insertBlock)
          Inserts a structured block to the beginning of the method.
 boolean isAnonymousConstructor()
          Checks if this constructor can be omited, since it is implicit.
 boolean isConstructor()
          Checks if this method is a constructor, i.e.
 boolean isMoreOuterThan(ClassDeclarer declarer)
           
 boolean isScopeOf(Object obj, int scopeType)
          Checks if the specified object lies in this scope.
 boolean isStatic()
          Checks if this method is static.
 boolean isStrictFP()
          Checks if this method is strictfp
 boolean isSynthetic()
          Checks if this method is synthetic, i.e.
 void makeDeclaration(Set done)
          This is the third and last pass of the analyzation.
 void setAnonymousConstructor(boolean value)
          Tells if this constructor can be omited, since it is implicit.
 void setHasOuterValue(boolean value)
          Tells if this (constructor$xx) method has as first (implicit) parameter the instance of the outer class.
 void setJikesBlockInitializer(boolean value)
          Tells if this method is the block$xx method generated by jikes.
 void setJikesConstructor(MethodAnalyzer realConstr)
          Tells if this method is the constructor$xx method generated by jikes.
 boolean skipWriting()
          Tells if this method is synthetic or implicit or something else, so that it doesn't have to be written to the source code.
 String toString()
           
 void useType(Type type)
          Registers a type at the import handler.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MethodAnalyzer

public MethodAnalyzer(ClassAnalyzer cla,
                      MethodInfo minfo,
                      ImportHandler imports)
This is the default constructor.

Parameters:
cla - the ClassAnalyzer of the class that contains this method.
minfo - the method info structure for this method.
imports - the import handler that should be informed about types.
Method Detail

getName

public String getName()
Returns the name of this method.


getType

public MethodType getType()
Returns the type of this method.

Returns:
the type of this method.

getMethodHeader

public FlowBlock getMethodHeader()
Returns the first flow block of the code.

Returns:
the first flow block of the code.

getBasicBlocks

public final BasicBlocks getBasicBlocks()
Returns the bytecode info for this method.

Returns:
the bytecode info for this method, or null if it is abstract or native.

getMethodInfo

public final MethodInfo getMethodInfo()

getImportHandler

public final ImportHandler getImportHandler()
Returns the import handler. The import handler should be informed about all types we (or an expression in this method) use, so that the corresponding class can be imported.

Returns:
the import handler.

useType

public final void useType(Type type)
Registers a type at the import handler. This should be called if an expression needs to print the type name to the code. The corresponding class will be imported in that case (if used often enough).

Parameters:
type - the type that should be registered.

insertStructuredBlock

public void insertStructuredBlock(StructuredBlock insertBlock)
Inserts a structured block to the beginning of the method. This is called by transform constructors, to move the super call from the real constructor to the constructor$xx method (the jikes constructor).

Parameters:
insertBlock - the structured block that should be inserted.

isConstructor

public final boolean isConstructor()
Checks if this method is a constructor, i.e. getName() returns "" or "".

Returns:
true, iff this method is a real constructor.

isStatic

public final boolean isStatic()
Checks if this method is static.

Returns:
true, iff this method is static.

isSynthetic

public final boolean isSynthetic()
Checks if this method is synthetic, i.e. a synthetic attribute is present.

Returns:
true, iff this method is synthetic.

isStrictFP

public final boolean isStrictFP()
Checks if this method is strictfp

Returns:
true, iff this method is synthetic.

setJikesConstructor

public final void setJikesConstructor(MethodAnalyzer realConstr)
Tells if this method is the constructor$xx method generated by jikes.

Parameters:
realConstr - true, iff this method is the jikes constructor.

setJikesBlockInitializer

public final void setJikesBlockInitializer(boolean value)
Tells if this method is the block$xx method generated by jikes.

Parameters:
value - true, iff this method is the jikes block initializer.

setHasOuterValue

public final void setHasOuterValue(boolean value)
Tells if this (constructor$xx) method has as first (implicit) parameter the instance of the outer class.

Parameters:
value - true, this method has the implicit parameter.

setAnonymousConstructor

public final void setAnonymousConstructor(boolean value)
Tells if this constructor can be omited, since it is implicit.

Parameters:
value - true, this method is the implicit constructor.

isAnonymousConstructor

public final boolean isAnonymousConstructor()
Checks if this constructor can be omited, since it is implicit.

Returns:
true, this method is the implicit constructor.

getSynthetic

public final SyntheticAnalyzer getSynthetic()
Get the synthetic analyzer for this method.

Returns:
the synthetic analyzer, or null if this method isn't synthetic.

getReturnType

public Type getReturnType()
Get the return type of this method.


getClassAnalyzer

public ClassAnalyzer getClassAnalyzer()
Get the class analyzer for the class containing this method.


getClazz

public ClassInfo getClazz()
Get the class info for the class containing this method.


getParamInfo

public final LocalInfo getParamInfo(int nr)
Get the local info for a parameter. This call is valid after the analyze pass.

Parameters:
nr - the index of the parameter (start by zero and count the implicit this param for nonstatic method).
Returns:
the local info for the specified parameter.
See Also:
getLocalInfo(net.sf.jode.bytecode.LocalVariableInfo)

getParamCount

public final int getParamCount()
Return the number of parameters for this method. This call is valid after the analyze pass.


getLocalInfo

public LocalInfo getLocalInfo(LocalVariableInfo lvi)
Create a local info for a local variable located at an instruction with the given address.

Parameters:
lvi - the local variable info of the bytecode package.
Returns:
a new local info representing that local.

getComplexity

public double getComplexity()
Gets the complexity of this class. Must be called after it has been initialized. This is used for a nice progress bar.


analyze

public void analyze(ProgressListener pl,
                    double done,
                    double scale)
             throws ClassFormatError
This is the first pass of the analyzation. It will analyze the code of this method, but not the method scoped classes.

Throws:
ClassFormatError

analyzeInnerClasses

public void analyzeInnerClasses()
                         throws ClassFormatError
This is the second pass of the analyzation. It will analyze the method scoped classes.

Throws:
ClassFormatError

makeDeclaration

public void makeDeclaration(Set done)
This is the third and last pass of the analyzation. It will analyze the types and names of the local variables and where to declare them. It will also determine where to declare method scoped local variables.


skipWriting

public boolean skipWriting()
Tells if this method is synthetic or implicit or something else, so that it doesn't have to be written to the source code.

Returns:
true, iff it shouldn't be written to the source code.

dumpSource

public void dumpSource(TabbedPrintWriter writer)
                throws IOException
Dumps the source code for this method to the specified writer.

Parameters:
writer - the tabbed print writer the code should be written to.
Throws:
IOException, - if writer throws an exception.
IOException

findLocal

public LocalInfo findLocal(String name)
Checks if the variable set contains a local with the given name.

Returns:
the local info the has the given name, or null if it doesn't exists.

findAnonClass

public ClassAnalyzer findAnonClass(String name)
Checks if a method scoped class with the given name exists in this method (not in a parent method).

Returns:
the class analyzer with the given name, or null if it doesn' exists.

isScopeOf

public boolean isScopeOf(Object obj,
                         int scopeType)
Checks if the specified object lies in this scope.

Specified by:
isScopeOf in interface Scope
Parameters:
obj - the object.
scopeType - the type of this object.
Returns:
true if the given object is in this scope.

conflicts

public boolean conflicts(String name,
                         int usageType)
Checks if the specified name conflicts with an object in this scope.

Specified by:
conflicts in interface Scope
Parameters:
name - the name to check.
usageType - the usage type of this name, AMBIGUOUSNAME if it is ambiguous.

getParent

public ClassDeclarer getParent()
Gets the parent scope, i.e. the class analyzer for the class containing this method. XXX needed?

Specified by:
getParent in interface ClassDeclarer
Returns:
null if this is the outermost instance.

addAnonymousConstructor

public void addAnonymousConstructor(InvokeOperator cop)
Registers an anonymous constructor invokation. This should be called in the analyze or analyzeInner pass by invoke subexpressions.

Parameters:
cop - the constructor invokation, that creates the method scoped class.

analyzeInvokeOperator

public void analyzeInvokeOperator(InvokeOperator cop)

getClassAnalyzer

public ClassAnalyzer getClassAnalyzer(ClassInfo cinfo)
Get the class analyzer for the given class info. This searches the method scoped/anonymous classes in this method and all outer methods and the outer classes for the class analyzer.

Specified by:
getClassAnalyzer in interface ClassDeclarer
Parameters:
cinfo - the classinfo for which the analyzer is searched.
Returns:
the class analyzer, or null if there is not an outer class that equals cinfo, and not a method scope/inner class in an outer method.

addClassAnalyzer

public void addClassAnalyzer(ClassAnalyzer clazzAna)
Specified by:
addClassAnalyzer in interface ClassDeclarer

fillDeclarables

public void fillDeclarables(Collection used)
We add the named method scoped classes to the declarables.


isMoreOuterThan

public boolean isMoreOuterThan(ClassDeclarer declarer)

toString

public String toString()
Overrides:
toString in class Object