本文整理汇总了Java中org.apache.bcel.classfile.LineNumberTable.getLineNumberTable方法的典型用法代码示例。如果您正苦于以下问题:Java LineNumberTable.getLineNumberTable方法的具体用法?Java LineNumberTable.getLineNumberTable怎么用?Java LineNumberTable.getLineNumberTable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.bcel.classfile.LineNumberTable
的用法示例。
在下文中一共展示了LineNumberTable.getLineNumberTable方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createMessage
import org.apache.bcel.classfile.LineNumberTable; //导入方法依赖的package包/类
/**
* Create message for storage at message key. The message includes the
* provided message, the method name and, if obtainable, the line number.
*/
private String createMessage(Method method, String message) {
StringBuilder result = new StringBuilder();
result.append(method.getName());
LineNumberTable table = method.getLineNumberTable();
if (table != null) {
LineNumber[] lineNumbers = table.getLineNumberTable();
LineNumber linenumber = lineNumbers[0];
int number = linenumber.getLineNumber();
result.append(" [" + number + "]");
}
result.append(": ");
result.append(message);
return result.toString();
}
示例2: getSourceAnnotationForClass
import org.apache.bcel.classfile.LineNumberTable; //导入方法依赖的package包/类
/**
* @param className
* @return
*/
static SourceLineAnnotation getSourceAnnotationForClass(String className, String sourceFileName) {
int lastLine = -1;
int firstLine = Integer.MAX_VALUE;
try {
JavaClass targetClass = AnalysisContext.currentAnalysisContext().lookupClass(className);
for (Method m : targetClass.getMethods()) {
Code c = m.getCode();
if (c != null) {
LineNumberTable table = c.getLineNumberTable();
if (table != null)
for (LineNumber line : table.getLineNumberTable()) {
lastLine = Math.max(lastLine, line.getLineNumber());
firstLine = Math.min(firstLine, line.getLineNumber());
}
}
}
} catch (ClassNotFoundException e) {
AnalysisContext.reportMissingClass(e);
}
if (firstLine < Integer.MAX_VALUE)
return new SourceLineAnnotation(className, sourceFileName, firstLine, lastLine, -1, -1);
return SourceLineAnnotation.createUnknown(className, sourceFileName);
}
示例3: foundSwitchNoDefault
import org.apache.bcel.classfile.LineNumberTable; //导入方法依赖的package包/类
private void foundSwitchNoDefault(SourceLineAnnotation s) {
LineNumberTable table = getCode().getLineNumberTable();
if (table != null) {
int startLine = s.getStartLine();
int prev = Integer.MIN_VALUE;
for (LineNumber ln : table.getLineNumberTable()) {
int thisLineNumber = ln.getLineNumber();
if (thisLineNumber < startLine && thisLineNumber > prev && ln.getStartPC() < s.getStartBytecode())
prev = thisLineNumber;
}
int diff = startLine - prev;
if (diff > 5)
return;
bugAccumulator.accumulateBug(new BugInstance(this, "SF_SWITCH_NO_DEFAULT", NORMAL_PRIORITY).addClassAndMethod(this),
s);
}
}
示例4: forEntireMethod
import org.apache.bcel.classfile.LineNumberTable; //导入方法依赖的package包/类
private static SourceLineAnnotation forEntireMethod(String className, String sourceFile,
LineNumberTable lineNumberTable, int codeSize) {
LineNumber[] table = lineNumberTable.getLineNumberTable();
if (table != null && table.length > 0) {
LineNumber first = table[0];
LineNumber last = table[table.length - 1];
return new SourceLineAnnotation(className, sourceFile, first.getLineNumber(), last.getLineNumber(),
0, codeSize - 1);
} else {
return createUnknown(className, sourceFile, 0, codeSize - 1);
}
}
示例5: checkTable
import org.apache.bcel.classfile.LineNumberTable; //导入方法依赖的package包/类
private void checkTable(LineNumberTable table) {
if (DEBUG) System.out.println("line number table has length " + table.getTableLength());
LineNumber[] entries = table.getLineNumberTable();
int lastBytecode = -1;
for (int i = 0; i < entries.length; ++i) {
LineNumber ln = entries[i];
if (DEBUG) System.out.println("Entry " + i + ": pc=" + ln.getStartPC() + ", line=" + ln.getLineNumber());
int pc = ln.getStartPC();
if (pc <= lastBytecode) throw new IllegalStateException("LineNumberTable is not sorted");
}
}
示例6: visitLineNumberTable
import org.apache.bcel.classfile.LineNumberTable; //导入方法依赖的package包/类
@Override
public void visitLineNumberTable(LineNumberTable obj) {
super.visitLineNumberTable(obj);
LineNumber[] line_number_table = obj.getLineNumberTable();
for (LineNumber aLine_number_table : line_number_table)
aLine_number_table.accept(this);
}
示例7: forFirstLineOfMethod
import org.apache.bcel.classfile.LineNumberTable; //导入方法依赖的package包/类
/**
* Make a best-effort attempt to create a SourceLineAnnotation for the first
* line of a method.
*
* @param methodDescriptor
* a method
* @return SourceLineAnnotation describing the first line of the method
* (insofar as we can actually figure that out from the bytecode)
*/
public static SourceLineAnnotation forFirstLineOfMethod(MethodDescriptor methodDescriptor) {
SourceLineAnnotation result = null;
try {
Method m = Global.getAnalysisCache().getMethodAnalysis(Method.class, methodDescriptor);
XClass xclass = Global.getAnalysisCache().getClassAnalysis(XClass.class, methodDescriptor.getClassDescriptor());
LineNumberTable lnt = m.getLineNumberTable();
String sourceFile = xclass.getSource();
if (sourceFile != null && lnt != null) {
int firstLine = Integer.MAX_VALUE;
int bytecode = 0;
LineNumber[] entries = lnt.getLineNumberTable();
for (LineNumber entry : entries) {
if (entry.getLineNumber() < firstLine) {
firstLine = entry.getLineNumber();
bytecode = entry.getStartPC();
}
}
if (firstLine < Integer.MAX_VALUE) {
result = new SourceLineAnnotation(methodDescriptor.getClassDescriptor().toDottedClassName(), sourceFile,
firstLine, firstLine, bytecode, bytecode);
}
}
} catch (CheckedAnalysisException e) {
// ignore
}
if (result == null) {
result = createUnknown(methodDescriptor.getClassDescriptor().toDottedClassName());
}
return result;
}
示例8: getNextSourceLine
import org.apache.bcel.classfile.LineNumberTable; //导入方法依赖的package包/类
public static int getNextSourceLine(LineNumberTable lineNumbers, int sourceLine) {
int result = Integer.MAX_VALUE;
for (LineNumber ln : lineNumbers.getLineNumberTable()) {
int thisLine = ln.getLineNumber();
if (sourceLine < thisLine && thisLine < result)
result = thisLine;
}
return result;
}
示例9: checkTable
import org.apache.bcel.classfile.LineNumberTable; //导入方法依赖的package包/类
private void checkTable(LineNumberTable table) {
if (DEBUG)
System.out.println("line number table has length " + table.getTableLength());
LineNumber[] entries = table.getLineNumberTable();
int lastBytecode = -1;
for (int i = 0; i < entries.length; ++i) {
LineNumber ln = entries[i];
if (DEBUG)
System.out.println("Entry " + i + ": pc=" + ln.getStartPC() + ", line=" + ln.getLineNumber());
int pc = ln.getStartPC();
if (pc <= lastBytecode)
throw new IllegalStateException("LineNumberTable is not sorted");
}
}
示例10: getSizeOfSurroundingTryBlock
import org.apache.bcel.classfile.LineNumberTable; //导入方法依赖的package包/类
public static int getSizeOfSurroundingTryBlock(ConstantPool constantPool, Code code,
@CheckForNull String vmNameOfExceptionClass, int pc) {
int size = Integer.MAX_VALUE;
int tightStartPC = 0;
int tightEndPC = Integer.MAX_VALUE;
if (code.getExceptionTable() == null)
return size;
for (CodeException catchBlock : code.getExceptionTable()) {
if (vmNameOfExceptionClass != null) {
Constant catchType = constantPool.getConstant(catchBlock.getCatchType());
if (catchType == null || catchType instanceof ConstantClass
&& !((ConstantClass) catchType).getBytes(constantPool).equals(vmNameOfExceptionClass))
continue;
}
int startPC = catchBlock.getStartPC();
int endPC = catchBlock.getEndPC();
if (pc >= startPC && pc <= endPC) {
int thisSize = endPC - startPC;
if (size > thisSize) {
size = thisSize;
tightStartPC = startPC;
tightEndPC = endPC;
}
}
}
if (size == Integer.MAX_VALUE)
return size;
// try to guestimate number of lines that correspond
size = (size + 7) / 8;
LineNumberTable lineNumberTable = code.getLineNumberTable();
if (lineNumberTable == null)
return size;
int count = 0;
for (LineNumber line : lineNumberTable.getLineNumberTable()) {
if (line.getStartPC() > tightEndPC)
break;
if (line.getStartPC() >= tightStartPC)
count++;
}
return count;
}
示例11: getSizeOfSurroundingTryBlock
import org.apache.bcel.classfile.LineNumberTable; //导入方法依赖的package包/类
public static int getSizeOfSurroundingTryBlock(ConstantPool constantPool, Code code,
@CheckForNull @SlashedClassName String vmNameOfExceptionClass, int pc) {
int size = Integer.MAX_VALUE;
int tightStartPC = 0;
int tightEndPC = Integer.MAX_VALUE;
if (code.getExceptionTable() == null)
return size;
for (CodeException catchBlock : code.getExceptionTable()) {
if (vmNameOfExceptionClass != null) {
Constant catchType = constantPool.getConstant(catchBlock.getCatchType());
if (catchType == null) continue;
if (catchType instanceof ConstantClass) {
String name = ((ConstantClass) catchType).getBytes(constantPool);
if (!name.equals(vmNameOfExceptionClass))
continue;
}
}
int startPC = catchBlock.getStartPC();
int endPC = catchBlock.getEndPC();
if (pc >= startPC && pc <= endPC) {
int thisSize = endPC - startPC;
if (size > thisSize) {
size = thisSize;
tightStartPC = startPC;
tightEndPC = endPC;
}
}
}
if (size == Integer.MAX_VALUE)
return size;
// try to guestimate number of lines that correspond
size = (size + 7) / 8;
LineNumberTable lineNumberTable = code.getLineNumberTable();
if (lineNumberTable == null)
return size;
int count = 0;
for (LineNumber line : lineNumberTable.getLineNumberTable()) {
if (line.getStartPC() > tightEndPC)
break;
if (line.getStartPC() >= tightStartPC)
count++;
}
return count;
}
示例12: forEntireMethod
import org.apache.bcel.classfile.LineNumberTable; //导入方法依赖的package包/类
/**
* Create a SourceLineAnnotation covering an entire method.
*
* @param className
* name of the class the method is in
* @param sourceFile
* source file containing the method
* @param lineNumberTable
* the method's LineNumberTable
* @param codeSize
* size in bytes of the method's code
* @return a SourceLineAnnotation covering the entire method
*/
public static SourceLineAnnotation forEntireMethod(@DottedClassName String className, String sourceFile, LineNumberTable lineNumberTable,
int codeSize) {
LineNumber[] table = lineNumberTable.getLineNumberTable();
if (table != null && table.length > 0) {
LineNumber first = table[0];
LineNumber last = table[table.length - 1];
return new SourceLineAnnotation(className, sourceFile, first.getLineNumber(), last.getLineNumber(), 0, codeSize - 1);
} else {
return createUnknown(className, sourceFile, 0, codeSize - 1);
}
}