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


Java LineNumberTable类代码示例

本文整理汇总了Java中org.apache.bcel.classfile.LineNumberTable的典型用法代码示例。如果您正苦于以下问题:Java LineNumberTable类的具体用法?Java LineNumberTable怎么用?Java LineNumberTable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


LineNumberTable类属于org.apache.bcel.classfile包,在下文中一共展示了LineNumberTable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: adviseSync

import org.apache.bcel.classfile.LineNumberTable; //导入依赖的package包/类
void adviseSync(Analyzer analyzer) throws SyncInsertionProposalFailure {
    d.log(0, "adviseSync %s\n", getName());
    d.log(1, "trying to find sync statement location(s)\n");
    InstructionHandle[] ihs = 
        analyzer.proposeSyncInsertion(this, new Debug(d.turnedOn(), d.getStartLevel() + 2));

    LineNumberTable t = getLineNumberTable(getConstantPool());
    
    for (InstructionHandle ih : ihs) {
        InstructionHandle h = ih.getNext();
        if (h == null) {
            h = ih;
        }
        int l = t.getSourceLine(h.getPosition());
        System.out.println("Insert a sync() in method "
                + getName() + " at line "+ l + " in class " + getClassName());
    }
}
 
开发者ID:pieterhijma,项目名称:cashmere,代码行数:19,代码来源:SpawningMethod.java

示例2: 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

示例3: fromVisitedInstructionRange

import org.apache.bcel.classfile.LineNumberTable; //导入依赖的package包/类
/**
 * Factory method for creating a source line annotation describing the
 * source line numbers for a range of instructions in the method being
 * visited by the given visitor.
 *
 * @param classContext
 *            the ClassContext
 * @param visitor
 *            a BetterVisitor which is visiting the method
 * @param startPC
 *            the bytecode offset of the start instruction in the range
 * @param endPC
 *            the bytecode offset of the end instruction in the range
 * @return the SourceLineAnnotation, or null if we do not have line number
 *         information for the instruction
 */
public static @Nonnull SourceLineAnnotation fromVisitedInstructionRange(ClassContext classContext, PreorderVisitor visitor,
        int startPC, int endPC) {
    if (startPC > endPC)
        throw new IllegalArgumentException("Start pc " + startPC + " greater than end pc " + endPC);

    LineNumberTable lineNumberTable = getLineNumberTable(visitor);
    String className = visitor.getDottedClassName();
    String sourceFile = visitor.getSourceFile();

    if (lineNumberTable == null)
        return createUnknown(className, sourceFile, startPC, endPC);

    int startLine = lineNumberTable.getSourceLine(startPC);
    int endLine = lineNumberTable.getSourceLine(endPC);
    return new SourceLineAnnotation(className, sourceFile, startLine, endLine, startPC, endPC);
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:33,代码来源:SourceLineAnnotation.java

示例4: 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

示例5: uniqueLocations

import org.apache.bcel.classfile.LineNumberTable; //导入依赖的package包/类
/**
 * @param derefLocationSet
 * @return
 */
private boolean uniqueLocations(Collection<Location> derefLocationSet) {
    boolean uniqueDereferenceLocations = false;
    LineNumberTable table = method.getLineNumberTable();
    if (table == null)
        uniqueDereferenceLocations = true;
    else {
        BitSet linesMentionedMultipleTimes = classContext.linesMentionedMultipleTimes(method);
        for (Location loc : derefLocationSet) {
            int lineNumber = table.getSourceLine(loc.getHandle().getPosition());
            if (!linesMentionedMultipleTimes.get(lineNumber))
                uniqueDereferenceLocations = true;
        }
    }
    return uniqueDereferenceLocations;
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:20,代码来源:NoiseNullDeref.java

示例6: sawOpcode

import org.apache.bcel.classfile.LineNumberTable; //导入依赖的package包/类
@Override
public void sawOpcode(int seen) {
    if (ifInstructionSet.get(seen)) {
        if (getBranchTarget() == getBranchFallThrough()) {
            int priority = NORMAL_PRIORITY;

            LineNumberTable lineNumbers = getCode().getLineNumberTable();
            if (lineNumbers != null) {
                int branchLineNumber = lineNumbers.getSourceLine(getPC());
                int targetLineNumber = lineNumbers.getSourceLine(getBranchFallThrough());
                int nextLine = getNextSourceLine(lineNumbers, branchLineNumber);

                if (branchLineNumber + 1 == targetLineNumber || branchLineNumber == targetLineNumber
                        && nextLine == branchLineNumber + 1)
                    priority = HIGH_PRIORITY;
                else if (branchLineNumber + 2 < Math.max(targetLineNumber, nextLine))
                    priority = LOW_PRIORITY;
            } else
                priority = LOW_PRIORITY;
            bugAccumulator.accumulateBug(new BugInstance(this,
                    priority == HIGH_PRIORITY ? "UCF_USELESS_CONTROL_FLOW_NEXT_LINE" : "UCF_USELESS_CONTROL_FLOW", priority)
                    .addClassAndMethod(this), this);
        }
    }
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:26,代码来源:FindUselessControlFlow.java

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

示例8: uniqueLocations

import org.apache.bcel.classfile.LineNumberTable; //导入依赖的package包/类
/**
 * @param derefLocationSet
 * @return
 */
private boolean uniqueLocations(Collection<Location> derefLocationSet) {
    boolean uniqueDereferenceLocations = false;
    CodeException[] exceptionTable = method.getCode().getExceptionTable();
    if (exceptionTable == null)
        return true;
    checkForCatchAll: {
        for (CodeException e : exceptionTable)
            if (e.getCatchType() == 0)
                break checkForCatchAll;
        return true;
    }

    LineNumberTable table = method.getLineNumberTable();
    if (table == null)
        uniqueDereferenceLocations = true;
    else {
        BitSet linesMentionedMultipleTimes = classContext.linesMentionedMultipleTimes(method);
        for (Location loc : derefLocationSet) {
            int lineNumber = table.getSourceLine(loc.getHandle().getPosition());
            if (lineNumber > 0 && !linesMentionedMultipleTimes.get(lineNumber))
                uniqueDereferenceLocations = true;
        }
    }
    return uniqueDereferenceLocations;
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:30,代码来源:FindNullDeref.java

示例9: fromVisitedMethod

import org.apache.bcel.classfile.LineNumberTable; //导入依赖的package包/类
/**
 * Factory method for creating a source line annotation describing
 * an entire method.
 *
 * @param visitor a BetterVisitor which is visiting the method
 * @return the SourceLineAnnotation
 */
public static SourceLineAnnotation fromVisitedMethod(PreorderVisitor visitor) {
	LineNumberTable lineNumberTable = getLineNumberTable(visitor);
	String className = visitor.getDottedClassName();
	String sourceFile = visitor.getSourceFile();
	Code code = visitor.getMethod().getCode();
	int codeSize = (code != null) ? code.getCode().length : 0;
	if (lineNumberTable == null)
		return createUnknown(className, sourceFile, 0, codeSize - 1);
	return forEntireMethod(className, sourceFile, lineNumberTable, codeSize);
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:18,代码来源:SourceLineAnnotation.java

示例10: 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

示例11: fromVisitedInstructionRange

import org.apache.bcel.classfile.LineNumberTable; //导入依赖的package包/类
/**
 * Factory method for creating a source line annotation describing the
 * source line numbers for a range of instructions in the method being
 * visited by the given visitor.
 *
 * @param visitor a BetterVisitor which is visiting the method
 * @param startPC the bytecode offset of the start instruction in the range
 * @param endPC   the bytecode offset of the end instruction in the range
 * @return the SourceLineAnnotation, or null if we do not have line number information
 *         for the instruction
 */
public static SourceLineAnnotation fromVisitedInstructionRange(PreorderVisitor visitor, int startPC, int endPC) {
	LineNumberTable lineNumberTable = getLineNumberTable(visitor);
	String className = visitor.getDottedClassName();
	String sourceFile = visitor.getSourceFile();

	if (lineNumberTable == null)
		return createUnknown(className, sourceFile, startPC, endPC);

	int startLine = lineNumberTable.getSourceLine(startPC);
	int endLine = lineNumberTable.getSourceLine(endPC);
	return new SourceLineAnnotation(className, sourceFile, startLine, endLine, startPC, endPC);
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:24,代码来源:SourceLineAnnotation.java

示例12: fromVisitedInstruction

import org.apache.bcel.classfile.LineNumberTable; //导入依赖的package包/类
/**
 * Factory method for creating a source line annotation describing the
 * source line number for a visited instruction.
 *
 * @param methodGen the MethodGen object representing the method
 * @param handle    the InstructionHandle containing the visited instruction
 * @return the SourceLineAnnotation, or null if we do not have line number information
 *         for the instruction
 */
public static SourceLineAnnotation fromVisitedInstruction(MethodGen methodGen, String sourceFile, InstructionHandle handle) {
	LineNumberTable table = methodGen.getLineNumberTable(methodGen.getConstantPool());
	String className = methodGen.getClassName();

	int bytecodeOffset = handle.getPosition();

	if (table == null)
		return createUnknown(className, sourceFile, bytecodeOffset, bytecodeOffset);

	int lineNumber = table.getSourceLine(handle.getPosition());
	return new SourceLineAnnotation(className, sourceFile, lineNumber, lineNumber, bytecodeOffset, bytecodeOffset);
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:22,代码来源:SourceLineAnnotation.java

示例13: 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

示例14: 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

示例15: forEntireMethod

import org.apache.bcel.classfile.LineNumberTable; //导入依赖的package包/类
/**
 * Create a SourceLineAnnotation covering an entire method.
 *
 * @param javaClass
 *            JavaClass containing the method
 * @param method
 *            the method
 * @return a SourceLineAnnotation for the entire method
 */
public static SourceLineAnnotation forEntireMethod(JavaClass javaClass, @CheckForNull Method method) {
    String sourceFile = javaClass.getSourceFileName();
    if (method == null)
        return createUnknown(javaClass.getClassName(), sourceFile);
    Code code = method.getCode();
    LineNumberTable lineNumberTable = method.getLineNumberTable();
    if (code == null || lineNumberTable == null) {
        return createUnknown(javaClass.getClassName(), sourceFile);
    }

    return forEntireMethod(javaClass.getClassName(), sourceFile, lineNumberTable, code.getLength());
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:22,代码来源:SourceLineAnnotation.java


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