• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java LineNumberTable类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


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


示例17: 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 classContext
 *            the ClassContext
 * @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(ClassContext classContext, MethodGen methodGen, String sourceFile,
        @Nonnull 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:ytus,项目名称:findbugs-all-the-bugs,代码行数:27,代码来源:SourceLineAnnotation.java


示例18: getLocalVariableAnnotation

import org.apache.bcel.classfile.LineNumberTable; //导入依赖的package包/类
public static LocalVariableAnnotation getLocalVariableAnnotation(Method method, int local, int position1, int position2) {

        LocalVariableTable localVariableTable = method.getLocalVariableTable();
        String localName = "?";
        if (localVariableTable != null) {
            LocalVariable lv1 = localVariableTable.getLocalVariable(local, position1);
            if (lv1 == null) {
                lv1 = localVariableTable.getLocalVariable(local, position2);
                position1 = position2;
            }
            if (lv1 != null)
                localName = lv1.getName();
            else
                for (LocalVariable lv : localVariableTable.getLocalVariableTable()) {
                    if (lv.getIndex() == local) {
                        if (!localName.equals("?") && !localName.equals(lv.getName())) {
                            // not a single consistent name
                            localName = "?";
                            break;
                        }
                        localName = lv.getName();
                    }
                }
        }
        LineNumberTable lineNumbers = method.getLineNumberTable();
        if (lineNumbers == null)
            return new LocalVariableAnnotation(localName, local, position1);
        int line = lineNumbers.getSourceLine(position1);
        return new LocalVariableAnnotation(localName, local, position1, line);
    }
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:31,代码来源:LocalVariableAnnotation.java


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


示例20: callToAssertionMethod

import org.apache.bcel.classfile.LineNumberTable; //导入依赖的package包/类
boolean callToAssertionMethod(Location loc) {

        InstructionHandle h = loc.getHandle();
        int firstPos = h.getPosition();

        LineNumberTable ln = method.getLineNumberTable();
        int firstLine = ln == null ? -1 : ln.getSourceLine(firstPos);

        while (h != null) {
            int pos = h.getPosition();

            if (ln == null) {
                if (pos > firstPos + 15)
                    break;
            } else {
                int line = ln.getSourceLine(pos);
                if (line != firstLine)
                    break;
            }
            Instruction i = h.getInstruction();
            if (i instanceof InvokeInstruction) {
                InvokeInstruction ii = (InvokeInstruction) i;
                String name = ii.getMethodName(classContext.getConstantPoolGen());
                if (name.startsWith("check") || name.startsWith("assert"))
                    return true;
            }
            h = h.getNext();
        }

        return false;
    }
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:32,代码来源:FindNullDeref.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java VerificationError类代码示例发布时间:2022-05-22
下一篇:
Java StringItem类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap