Class NameRecoverer
- java.lang.Object
-
- com.tonic.analysis.source.recovery.NameRecoverer
-
public class NameRecoverer extends Object
Recovers variable names from debug info or generates synthetic names.
-
-
Constructor Summary
Constructors Constructor Description NameRecoverer(IRMethod irMethod, MethodEntry sourceMethod, NameRecoveryStrategy strategy)Creates a recoverer and eagerly indexes the method's local variable table and lifted instruction offsets.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringdebugDescriptorAt(int slot, int offset)The LocalVariableTable type descriptor in scope forslotat bytecodeoffset- the declared type of the variable there (e.g.StringdebugDescriptorAtStore(int slot, int storeOffset)AsdebugNameAtStore(int, int)for the entry's descriptor.StringdebugNameAt(int slot, int offset)The LocalVariableTable name in scope forslotat bytecodeoffset- the entry whose[startPc, startPc + length)range contains the offset - or null when there is no debug info or no entry covers it.StringdebugNameAtStore(int slot, int storeOffset)The LVT name forslotat the pc where a STORE atstoreOffsettakes effect - the following instruction, which is where javac opens the variable's range.StringgenerateSyntheticName(SSAValue value)Generates a synthetic name based on the value's type.NameRecoveryStrategygetStrategy()intnextOffsetAfter(int off)The smallest instruction offset strictly greater thanoff, oroff + 1if none known.StringunambiguousDebugName(int slot)The LVT name forslotwhen every entry for that slot agrees on a single name, else null.
-
-
-
Constructor Detail
-
NameRecoverer
public NameRecoverer(IRMethod irMethod, MethodEntry sourceMethod, NameRecoveryStrategy strategy)
Creates a recoverer and eagerly indexes the method's local variable table and lifted instruction offsets.- Parameters:
irMethod- the lifted methodsourceMethod- the method the IR came fromstrategy- whether debug names are preferred over synthetic ones- Throws:
NullPointerException- if the source method has no owning class file
-
-
Method Detail
-
nextOffsetAfter
public int nextOffsetAfter(int off)
The smallest instruction offset strictly greater thanoff, oroff + 1if none known.- Parameters:
off- the bytecode offset to search past- Returns:
- the next known instruction offset, or one past the given offset
-
debugNameAtStore
public String debugNameAtStore(int slot, int storeOffset)
The LVT name forslotat the pc where a STORE atstoreOffsettakes effect - the following instruction, which is where javac opens the variable's range.- Parameters:
slot- the local slot writtenstoreOffset- the bytecode offset of the store- Returns:
- the name in scope, falling back to the name at the store itself, or null when neither has an entry
-
debugDescriptorAtStore
public String debugDescriptorAtStore(int slot, int storeOffset)
AsdebugNameAtStore(int, int)for the entry's descriptor.- Parameters:
slot- the local slot writtenstoreOffset- the bytecode offset of the store- Returns:
- the declared descriptor in scope, falling back to the one at the store itself, or null when neither has an entry
-
getStrategy
public NameRecoveryStrategy getStrategy()
- Returns:
- the strategy
-
unambiguousDebugName
public String unambiguousDebugName(int slot)
The LVT name forslotwhen every entry for that slot agrees on a single name, else null.- Parameters:
slot- the local slot to name- Returns:
- the single agreed name, or null when the entries disagree or the strategy forbids it
-
debugNameAt
public String debugNameAt(int slot, int offset)
The LocalVariableTable name in scope forslotat bytecodeoffset- the entry whose[startPc, startPc + length)range contains the offset - or null when there is no debug info or no entry covers it.- Parameters:
slot- the local slot to nameoffset- the bytecode offset the name must be in scope at- Returns:
- the name in scope, or null when no entry covers the offset
-
debugDescriptorAt
public String debugDescriptorAt(int slot, int offset)
The LocalVariableTable type descriptor in scope forslotat bytecodeoffset- the declared type of the variable there (e.g."C"forchar), or null when no debug info or no entry covers it.- Parameters:
slot- the local slot to typeoffset- the bytecode offset the entry must be in scope at- Returns:
- the declared descriptor, or null when no entry covers the offset
-
-