当前位置: 首页>>代码示例>>Java>>正文


Java LineNumberTable.getLineNumberTable方法代码示例

本文整理汇总了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();
}
 
开发者ID:vimaier,项目名称:conqat,代码行数:23,代码来源:MethodAssessorBase.java

示例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);
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:30,代码来源:SourceLineAnnotation.java

示例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);
    }

}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:21,代码来源:SwitchFallthrough.java

示例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);
	}
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:13,代码来源:SourceLineAnnotation.java

示例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");
	}
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:12,代码来源:LineNumberMap.java

示例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);
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:8,代码来源:PreorderVisitor.java

示例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;
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:43,代码来源:SourceLineAnnotation.java

示例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;

}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:12,代码来源:FindUselessControlFlow.java

示例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");
    }
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:15,代码来源:LineNumberMap.java

示例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;

}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:45,代码来源:Util.java

示例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;

}
 
开发者ID:OpenNTF,项目名称:FindBug-for-Domino-Designer,代码行数:48,代码来源:Util.java

示例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);
    }
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:25,代码来源:SourceLineAnnotation.java


注:本文中的org.apache.bcel.classfile.LineNumberTable.getLineNumberTable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。