Package org.apache.bcel.classfile

Examples of org.apache.bcel.classfile.LineNumberTable


                    }
                }
            }
        }
        BitSet linesMentionedMultipleTimes = classContext.linesMentionedMultipleTimes(method);
        LineNumberTable lineNumberTable = methodGen.getLineNumberTable(methodGen.getConstantPool());
        Map<BugAnnotation, String> instanceOfChecks = new HashMap<BugAnnotation, String>();
        String constantClass = null;
        boolean methodInvocationWasGeneric = false;

        int pcForConstantClass = -1;
        for (Iterator<Location> i = cfg.locationIterator(); i.hasNext();) {
            Location location = i.next();

            InstructionHandle handle = location.getHandle();
            int pc = handle.getPosition();
            Instruction ins = handle.getInstruction();

            boolean wasMethodInvocationWasGeneric = methodInvocationWasGeneric;
            methodInvocationWasGeneric = false;
            if (ins instanceof InvokeInstruction) {
                InvokeInstruction iinv = (InvokeInstruction) ins;
                XMethod m = XFactory.createXMethod(iinv, cpg);
                if (m != null) {
                    String sourceSignature = m.getSourceSignature();
                    methodInvocationWasGeneric = sourceSignature != null
                            && (sourceSignature.startsWith("<") || sourceSignature.indexOf("java/lang/Class") >= 0);
                    if (DEBUG && methodInvocationWasGeneric) {
                        System.out.println(m + " has source signature " + sourceSignature);
                    }
                }

            }
            if (ins instanceof LDC) {
                LDC ldc = (LDC) ins;
                Object value = ldc.getValue(cpg);
                if (value instanceof ConstantClass) {
                    ConstantClass cc = (ConstantClass) value;
                    constantClass = cc.getBytes(classContext.getJavaClass().getConstantPool());
                    pcForConstantClass = pc;
                }
            }

            if (!(ins instanceof CHECKCAST) && !(ins instanceof INSTANCEOF)) {
                continue;
            }

            boolean isCast = ins instanceof CHECKCAST;
            int occurrences = cfg.getLocationsContainingInstructionWithOffset(pc).size();
            boolean split = occurrences > 1;
            if (lineNumberTable != null) {
                int line = lineNumberTable.getSourceLine(handle.getPosition());
                if (line > 0 && linesMentionedMultipleTimes.get(line)) {
                    split = true;
                }
            }
View Full Code Here


        addPropertiesForMethodContainingWarning(propertySet);
    }

    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;
                }
            }
        }
View Full Code Here

    @Override
    public void visit(Code obj) {

        CodeException[] exp = obj.getExceptionTable();
        LineNumberTable lineNumbers = obj.getLineNumberTable();
        if (exp == null) {
            return;
        }
        byte[] code = obj.getCode();

        for (CodeException aExp : exp) {
            int handled = aExp.getHandlerPC();
            int start = aExp.getStartPC();
            int end = aExp.getEndPC();
            int cause = aExp.getCatchType();
            boolean exitInTryBlock = false;
            if (DEBUG) {
                System.out.println("start = " + start + ", end = " + end + ", codeLength = " + code.length + ", handled = "
                        + handled);
            }

            for (int j = start; j <= end && j < code.length;) {
                int opcode = asUnsignedByte(code[j]);
                if (NO_OF_OPERANDS[opcode] < 0) {
                    exitInTryBlock = true;
                    break;
                }
                j += 1 + NO_OF_OPERANDS[opcode];
                if (opcode >= IRETURN && opcode <= RETURN || opcode >= IFEQ && opcode <= GOTO && (opcode != GOTO || j < end)) {
                    exitInTryBlock = true;
                    if (DEBUG) {
                        System.out.println("\texit: " + opcode + " in " + getFullyQualifiedMethodName());
                    }
                    break;
                }

            }

            if (exitInTryBlock) {
                if (DEBUG) {
                    System.out.println("Exit in try block");
                }
                continue;
            }
            if (handled < 5) {
                continue;
            }
            @DottedClassName String causeName;
            if (cause == 0) {
                causeName = "java.lang.Throwable";
            } else {
                causeName = Utility.compactClassName(getConstantPool().getConstantString(cause, CONSTANT_Class), false);
                if (!isChecked(causeName)) {
                    continue;
                }
            }

            int jumpAtEnd = 0;
            if (end < code.length && asUnsignedByte(code[end]) == GOTO) {
                jumpAtEnd = getUnsignedShort(code, end + 1);
                if (jumpAtEnd < handled) {
                    jumpAtEnd = 0;
                }
            }

            int opcode = asUnsignedByte(code[handled]);
            int afterHandler = 0;
            if (DEBUG) {
                System.out.println("DE:\topcode is " + OPCODE_NAMES[opcode] + ", " + asUnsignedByte(code[handled + 1]));
            }
            boolean drops = false;
            boolean startsWithASTORE03 = opcode >= ASTORE_0 && opcode <= ASTORE_3;
            if (startsWithASTORE03 && asUnsignedByte(code[handled + 1]) == RETURN) {
                if (DEBUG) {
                    System.out.println("Drop 1");
                }
                drops = true;
                afterHandler = handled + 1;
            }
            if (handled + 2 < code.length && opcode == ASTORE && asUnsignedByte(code[handled + 2]) == RETURN) {
                drops = true;
                afterHandler = handled + 2;
                if (DEBUG) {
                    System.out.println("Drop 2");
                }
            }
            if (handled + 3 < code.length && !exitInTryBlock) {
                if (DEBUG) {
                    System.out.println("DE: checking for jumps");
                }
                if (startsWithASTORE03 && asUnsignedByte(code[handled - 3]) == GOTO) {
                    int offsetBefore = getUnsignedShort(code, handled - 2);
                    if (DEBUG) {
                        System.out.println("offset before = " + offsetBefore);
                    }
                    if (offsetBefore == 4) {
                        drops = true;
                        afterHandler = handled + 1;
                        if (DEBUG) {
                            System.out.println("Drop 3");
                        }
                    }
                }
                if (opcode == ASTORE && asUnsignedByte(code[handled - 3]) == GOTO) {
                    int offsetBefore = getUnsignedShort(code, handled - 2);
                    if (offsetBefore == 5) {
                        drops = true;
                        afterHandler = handled + 2;
                        if (DEBUG) {
                            System.out.println("Drop 4");
                        }
                    }
                }
                if (startsWithASTORE03 && asUnsignedByte(code[handled + 1]) == GOTO && asUnsignedByte(code[handled - 3]) == GOTO) {
                    int offsetBefore = getUnsignedShort(code, handled - 2);
                    int offsetAfter = getUnsignedShort(code, handled + 2);

                    if (offsetAfter > 0 && offsetAfter + 4 == offsetBefore) {
                        drops = true;
                        afterHandler = handled + 4;
                        if (DEBUG) {
                            System.out.println("Drop 5");
                        }
                    }
                }

                if (opcode == ASTORE && asUnsignedByte(code[handled + 2]) == GOTO && asUnsignedByte(code[handled - 3]) == GOTO) {
                    int offsetBefore = getUnsignedShort(code, handled - 2);
                    int offsetAfter = getUnsignedShort(code, handled + 3);

                    if (offsetAfter > 0 && offsetAfter + 5 == offsetBefore) {
                        drops = true;
                        afterHandler = handled + 5;
                        if (DEBUG) {
                            System.out.println("Drop 6");
                        }
                    }
                }

            }

            boolean multiLineHandler = false;
            if (DEBUG) {
                System.out.println("afterHandler = " + afterHandler + ", handled = " + handled);
            }
            if (afterHandler > handled && lineNumbers != null) {
                int startHandlerLinenumber = lineNumbers.getSourceLine(handled);

                int endHandlerLinenumber = getNextExecutableLineNumber(lineNumbers, afterHandler) - 1;
                if (DEBUG) {
                    System.out.println("Handler in lines " + startHandlerLinenumber + "-" + endHandlerLinenumber);
                }
View Full Code Here

    int codeLength = code.getCode().length;

    /////////////////////
    // LineNumberTable //
    /////////////////////
    LineNumberTable lnt = code.getLineNumberTable();
    if (lnt != null){
      LineNumber[] lineNumbers = lnt.getLineNumberTable();
      IntList offsets = new IntList();
      lineNumber_loop: for (int i=0; i < lineNumbers.length; i++){ // may appear in any order.
        for (int j=0; j < instructionPositions.length; j++){
          // TODO: Make this a binary search! The instructionPositions array is naturally ordered!
          int offset = lineNumbers[i].getStartPC();
View Full Code Here

                        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);
    }
View Full Code Here

                }
            }
        }
        BitSet foundOnce = new BitSet();
        BitSet afterHandler = new BitSet();
        LineNumberTable lineNumberTable = method.getLineNumberTable();
        int lineNum = -1;
        int prevStartPc = -1;
        if (lineNumberTable != null) {
            for (LineNumber line : lineNumberTable.getLineNumberTable()) {
                int newLine = line.getLineNumber();
                if (newLine == lineNum || newLine == -1) {
                    continue;
                }
                if (prevStartPc >= 0) {
View Full Code Here

            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++;
View Full Code Here

    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;
View Full Code Here

    {
        boolean ret = false;
        Method[] methods = javaClass.getMethods();
        for ( int i = 0; i < methods.length; i++ )
        {
            LineNumberTable linenumbers = methods[i].getLineNumberTable();
            if ( linenumbers != null && linenumbers.getLength() > 0 )
            {
                ret = true;
                break;
            }
        }
View Full Code Here

    design.checkClass(str);
  }

  //   
  public void visitCode(Code c) {
    LineNumberTable table = c.getLineNumberTable();
    // LocalVariableTable table = c.getLocalVariableTable();
    if (table == null)
      throw new BuildException(getNoDebugMsg(design.getCurrentClass()), location);
  }
View Full Code Here

TOP

Related Classes of org.apache.bcel.classfile.LineNumberTable

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.