本文整理汇总了Java中org.apache.bcel.classfile.LineNumber.getStartPC方法的典型用法代码示例。如果您正苦于以下问题:Java LineNumber.getStartPC方法的具体用法?Java LineNumber.getStartPC怎么用?Java LineNumber.getStartPC使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.bcel.classfile.LineNumber
的用法示例。
在下文中一共展示了LineNumber.getStartPC方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: foundSwitchNoDefault
import org.apache.bcel.classfile.LineNumber; //导入方法依赖的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);
}
}
示例2: checkTable
import org.apache.bcel.classfile.LineNumber; //导入方法依赖的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");
}
}
示例3: forFirstLineOfMethod
import org.apache.bcel.classfile.LineNumber; //导入方法依赖的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;
}
示例4: checkTable
import org.apache.bcel.classfile.LineNumber; //导入方法依赖的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");
}
}
示例5: getSizeOfSurroundingTryBlock
import org.apache.bcel.classfile.LineNumber; //导入方法依赖的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;
}
示例6: getSizeOfSurroundingTryBlock
import org.apache.bcel.classfile.LineNumber; //导入方法依赖的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;
}