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


Java LineNumberTable.getSourceLine方法代码示例

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


在下文中一共展示了LineNumberTable.getSourceLine方法的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: 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:OpenNTF,项目名称:FindBug-for-Domino-Designer,代码行数:26,代码来源:FindUselessControlFlow.java

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

示例4: 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:OpenNTF,项目名称:FindBug-for-Domino-Designer,代码行数:33,代码来源:SourceLineAnnotation.java

示例5: 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:OpenNTF,项目名称:FindBug-for-Domino-Designer,代码行数:30,代码来源:FindNullDeref.java

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

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

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

示例9: 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:OpenNTF,项目名称:FindBug-for-Domino-Designer,代码行数:32,代码来源:FindNullDeref.java

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

示例11: getLineNumber

import org.apache.bcel.classfile.LineNumberTable; //导入方法依赖的package包/类
private static int getLineNumber(Method method, InstructionHandle handle) {
	LineNumberTable table = method.getCode().getLineNumberTable();
	if (table == null)
		return -1;
	return table.getSourceLine(handle.getPosition());
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:7,代码来源:FindNullDeref.java

示例12: build

import org.apache.bcel.classfile.LineNumberTable; //导入方法依赖的package包/类
/**
 * Build the line number information.
 * Should be called before any other methods.
 */
public void build() {
	int numGood = 0, numBytecodes = 0;

	if (DEBUG) {
		System.out.println("Method: " + methodGen.getName() + " - " + methodGen.getSignature() +
		        "in class " + methodGen.getClassName());
	}

	// Associate line number information with each InstructionHandle
	LineNumberTable table = methodGen.getLineNumberTable(methodGen.getConstantPool());

	if (table != null && table.getTableLength() > 0) {
		checkTable(table);
		InstructionHandle handle = methodGen.getInstructionList().getStart();
		while (handle != null) {
			int bytecodeOffset = handle.getPosition();
			if (bytecodeOffset < 0)
				throw new IllegalStateException("Bad bytecode offset: " + bytecodeOffset);
			if (DEBUG) System.out.println("Looking for source line for bytecode offset " + bytecodeOffset);
			int sourceLine;
			try {
				sourceLine = table.getSourceLine(bytecodeOffset);
			} catch (ArrayIndexOutOfBoundsException e) {
				if (LINE_NUMBER_BUG)
					throw e;
				else
					sourceLine = -1;
			}
			if (sourceLine >= 0)
				++numGood;
			lineNumberMap.put(handle,
			        new LineNumber(bytecodeOffset, sourceLine));
			handle = handle.getNext();
			++numBytecodes;
		}
		hasLineNumbers = true;

		if (DEBUG) System.out.println("\t" + numGood + "/" + numBytecodes + " had valid line numbers");
	}
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:45,代码来源:LineNumberMap.java

示例13: getLineNumber

import org.apache.bcel.classfile.LineNumberTable; //导入方法依赖的package包/类
private static int getLineNumber(Method method, InstructionHandle handle) {
    LineNumberTable table = method.getCode().getLineNumberTable();
    if (table == null)
        return -1;
    return table.getSourceLine(handle.getPosition());
}
 
开发者ID:OpenNTF,项目名称:FindBug-for-Domino-Designer,代码行数:7,代码来源:NullDerefAndRedundantComparisonFinder.java

示例14: build

import org.apache.bcel.classfile.LineNumberTable; //导入方法依赖的package包/类
/**
 * Build the line number information. Should be called before any other
 * methods.
 */
public void build() {
    int numGood = 0, numBytecodes = 0;

    if (DEBUG) {
        System.out.println("Method: " + methodGen.getName() + " - " + methodGen.getSignature() + "in class "
                + methodGen.getClassName());
    }

    // Associate line number information with each InstructionHandle
    LineNumberTable table = methodGen.getLineNumberTable(methodGen.getConstantPool());

    if (table != null && table.getTableLength() > 0) {
        checkTable(table);
        InstructionHandle handle = methodGen.getInstructionList().getStart();
        while (handle != null) {
            int bytecodeOffset = handle.getPosition();
            if (bytecodeOffset < 0)
                throw new IllegalStateException("Bad bytecode offset: " + bytecodeOffset);
            if (DEBUG)
                System.out.println("Looking for source line for bytecode offset " + bytecodeOffset);
            int sourceLine;
            try {
                sourceLine = table.getSourceLine(bytecodeOffset);
            } catch (ArrayIndexOutOfBoundsException e) {
                if (LINE_NUMBER_BUG)
                    throw e;
                else
                    sourceLine = -1;
            }
            if (sourceLine >= 0)
                ++numGood;
            lineNumberMap.put(handle, new LineNumber(bytecodeOffset, sourceLine));
            handle = handle.getNext();
            ++numBytecodes;
        }
        hasLineNumbers = true;

        if (DEBUG)
            System.out.println("\t" + numGood + "/" + numBytecodes + " had valid line numbers");
    }
}
 
开发者ID:OpenNTF,项目名称:FindBug-for-Domino-Designer,代码行数:46,代码来源:LineNumberMap.java

示例15: analyzeNullCheck

import org.apache.bcel.classfile.LineNumberTable; //导入方法依赖的package包/类
private void analyzeNullCheck(IsNullValueDataflow invDataflow, BasicBlock basicBlock) throws DataflowAnalysisException,
        CFGBuilderException {
    // Look for null checks where the value checked is definitely
    // null or null on some path.

    InstructionHandle exceptionThrowerHandle = basicBlock.getExceptionThrower();
    Instruction exceptionThrower = exceptionThrowerHandle.getInstruction();

    // Get the stack values at entry to the null check.
    IsNullValueFrame frame = invDataflow.getStartFact(basicBlock);
    if (!frame.isValid())
        return;

    // Could the reference be null?
    IsNullValue refValue = frame.getInstance(exceptionThrower, classContext.getConstantPoolGen());
    if (DEBUG) {
        System.out.println("For basic block " + basicBlock + " value is " + refValue);
    }
    if (refValue.isDefinitelyNotNull())
        return;
    if (false && !refValue.mightBeNull())
        return;

    if (!refValue.isDefinitelyNull())
        return;
    // Get the value number
    ValueNumberFrame vnaFrame = classContext.getValueNumberDataflow(method).getStartFact(basicBlock);
    if (!vnaFrame.isValid())
        return;
    ValueNumber valueNumber = vnaFrame.getInstance(exceptionThrower, classContext.getConstantPoolGen());
    Location location = new Location(exceptionThrowerHandle, basicBlock);
    if (DEBUG)
        System.out.println("Warning: VN " + valueNumber + " invf: " + frame + " @ " + location);

    boolean isConsistent = true;
    Iterator<BasicBlock> bbIter = invDataflow.getCFG().blockIterator();
    LineNumberTable table = method.getLineNumberTable();
    int position = exceptionThrowerHandle.getPosition();
    int line = table == null ? 0 : table.getSourceLine(position);
    while (bbIter.hasNext()) {
        BasicBlock bb = bbIter.next();

        if (!bb.isNullCheck())
            continue;

        InstructionHandle eth = bb.getExceptionThrower();
        if (eth == exceptionThrowerHandle)
            continue;
        if (eth.getInstruction().getOpcode() != exceptionThrower.getOpcode())
            continue;

        int ePosition = eth.getPosition();
        if (ePosition == position || table != null && line == table.getSourceLine(ePosition)) {

            IsNullValueFrame frame2 = invDataflow.getStartFact(bb);
            if (!frame2.isValid())
                continue;
            // apparent clone
            IsNullValue rv = frame2.getInstance(eth.getInstruction(), classContext.getConstantPoolGen());
            if (!rv.equals(refValue))
                isConsistent = false;
        }

    }
    // Issue a warning
    collector.foundNullDeref(location, valueNumber, refValue, vnaFrame, isConsistent);
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:68,代码来源:NullDerefAndRedundantComparisonFinder.java


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