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


Java CodeException.getEndPC方法代码示例

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


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

示例1: getSurroundingCaughtExceptions

import org.apache.bcel.classfile.CodeException; //导入方法依赖的package包/类
public Set<String> getSurroundingCaughtExceptions(int pc, int maxTryBlockSize) {
    HashSet<String> result = new HashSet<String>();
    if (code == null)
        throw new IllegalStateException("Not visiting Code");
    int size = maxTryBlockSize;
    if (code.getExceptionTable() == null)
        return result;
    for (CodeException catchBlock : code.getExceptionTable()) {
        int startPC = catchBlock.getStartPC();
        int endPC = catchBlock.getEndPC();
        if (pc >= startPC && pc <= endPC) {
            int thisSize = endPC - startPC;
            if (size > thisSize) {
                result.clear();
                size = thisSize;
                Constant kind = constantPool.getConstant(catchBlock.getCatchType());
                result.add("C" + catchBlock.getCatchType());
            } else if (size == thisSize)
                result.add("C" + catchBlock.getCatchType());
        }
    }
    return result;
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:24,代码来源:PreorderVisitor.java

示例2: getSurroundingTryBlock

import org.apache.bcel.classfile.CodeException; //导入方法依赖的package包/类
public static @CheckForNull
CodeException getSurroundingTryBlock(ConstantPool constantPool, Code code, @CheckForNull String vmNameOfExceptionClass, int pc) {
    int size = Integer.MAX_VALUE;
    if (code.getExceptionTable() == null)
        return null;
    CodeException result = null;
    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;
                result = catchBlock;
            }
        }
    }
    return result;
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:26,代码来源:Util.java

示例3: getSizeOfSurroundingTryBlock

import org.apache.bcel.classfile.CodeException; //导入方法依赖的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

示例4: sawOpcode

import org.apache.bcel.classfile.CodeException; //导入方法依赖的package包/类
@Override
public void sawOpcode(int seen) {
    // System.out.println(state + " " + getPC() + " " + OPCODE_NAMES[seen]);
    if (countDown == 2 && seen == GOTO) {
        CodeException tryBlock = getSurroundingTryBlock(getPC());
        if (tryBlock != null && tryBlock.getEndPC() == getPC())
            pendingBug.lowerPriority();
    }
    if (countDown > 0) {
        countDown--;
        if (countDown == 0) {
            if (seen == MONITOREXIT)
                pendingBug.lowerPriority();

            bugReporter.reportBug(pendingBug);
            pendingBug = null;
        }
    }
    if (seen == PUTFIELD) {

        if (syncField != null && getPrevOpcode(1) != ALOAD_0 && syncField.equals(getXFieldOperand())) {
            OpcodeStack.Item value = stack.getStackItem(0);
            int priority = Priorities.HIGH_PRIORITY;
            if (value.isNull())
                priority = Priorities.NORMAL_PRIORITY;
            pendingBug = new BugInstance(this, "ML_SYNC_ON_FIELD_TO_GUARD_CHANGING_THAT_FIELD", priority)
                    .addClassAndMethod(this).addField(syncField).addSourceLine(this);
            countDown = 2;

        }

    }
    if (seen == MONITOREXIT) {
        pendingBug = null;
        countDown = 0;
    }

    if (seen == MONITORENTER)
        syncField = null;

    switch (state) {
    case 0:
        if (seen == ALOAD_0)
            state = 1;
        break;
    case 1:
        if (seen == GETFIELD) {
            state = 2;
            field = getXFieldOperand();
        } else
            state = 0;
        break;
    case 2:
        if (seen == DUP)
            state = 3;
        else
            state = 0;
        break;
    case 3:
        if (isRegisterStore())
            state = 4;
        else
            state = 0;
        break;
    case 4:
        if (seen == MONITORENTER) {
            state = 0;
            syncField = field;
        } else
            state = 0;
        break;

    }

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

示例5: examineRedundantBranches

import org.apache.bcel.classfile.CodeException; //导入方法依赖的package包/类
/**
 * Examine redundant branches.
 */
private void examineRedundantBranches() {
    for (RedundantBranch redundantBranch : redundantBranchList) {
        if (DEBUG)
            System.out.println("Redundant branch: " + redundantBranch);
        int lineNumber = redundantBranch.lineNumber;

        // The source to bytecode compiler may sometimes duplicate blocks of
        // code along different control paths. So, to report the bug,
        // we check to ensure that the branch is REALLY determined each
        // place it is duplicated, and that it is determined in the same
        // way.

        boolean confused = undeterminedBranchSet.get(lineNumber)
                || (definitelySameBranchSet.get(lineNumber) && definitelyDifferentBranchSet.get(lineNumber));

        // confused if there is JSR confusion or multiple null checks with
        // different results on the same line

        boolean reportIt = true;

        if (lineMentionedMultipleTimes.get(lineNumber) && confused)
            reportIt = false;
        else if (redundantBranch.location.getBasicBlock().isInJSRSubroutine() /*
                                                                               * occurs
                                                                               * in
                                                                               * a
                                                                               * JSR
                                                                               */
                && confused)
            reportIt = false;
        else {
            int pc = redundantBranch.location.getHandle().getPosition();
            for (CodeException e : method.getCode().getExceptionTable()) {
                if (e.getCatchType() == 0 && e.getStartPC() != e.getHandlerPC() && e.getEndPC() <= pc
                        && pc <= e.getEndPC() + 5)
                    reportIt = false;
            }
        }

        if (reportIt) {
            collector.foundRedundantNullCheck(redundantBranch.location, redundantBranch);
        }
    }
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:48,代码来源:NullDerefAndRedundantComparisonFinder.java

示例6: getSizeOfSurroundingTryBlock

import org.apache.bcel.classfile.CodeException; //导入方法依赖的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


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