org.apache.bcel.classfile.Method.getCode()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(9.8k)|赞(0)|评价(0)|浏览(141)

本文整理了Java中org.apache.bcel.classfile.Method.getCode()方法的一些代码示例,展示了Method.getCode()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Method.getCode()方法的具体详情如下:
包路径:org.apache.bcel.classfile.Method
类名称:Method
方法名:getCode

Method.getCode介绍

暂无

代码示例

代码示例来源:origin: spotbugs/spotbugs

/**
   * Dump the disassembled code of all methods in the class.
   */
  public static void printCode(Method[] methods) {
    for (Method m : methods) {
      System.out.println(m);
      Code code = m.getCode();
      if (code != null) {
        System.out.println(code);
      }

    }
  }
}

代码示例来源:origin: spotbugs/spotbugs

public static int getSizeOfSurroundingTryBlock(@CheckForNull Method method, @CheckForNull String vmNameOfExceptionClass, int pc) {
  if (method == null) {
    return Integer.MAX_VALUE;
  }
  return getSizeOfSurroundingTryBlock(method.getConstantPool(), method.getCode(), vmNameOfExceptionClass, pc);
}

代码示例来源:origin: spotbugs/spotbugs

private static LineNumberTable getLineNumberTable(PreorderVisitor visitor) {
  Code code = visitor.getMethod().getCode();
  if (code == null) {
    return null;
  }
  return code.getLineNumberTable();
}

代码示例来源:origin: spotbugs/spotbugs

/**
 * Compute hash on given method.
 *
 * @param method
 *            the method
 * @return this object
 */
public MethodHash computeHash(Method method) {
  final MessageDigest digest = Util.getMD5Digest();
  byte[] code;
  if (method.getCode() == null || method.getCode().getCode() == null) {
    code = new byte[0];
  } else {
    code = method.getCode().getCode();
  }
  BytecodeScanner.Callback callback = (opcode, index) -> digest.update((byte) opcode);
  BytecodeScanner bytecodeScanner = new BytecodeScanner();
  bytecodeScanner.scan(code, callback);
  hash = digest.digest();
  return this;
}

代码示例来源:origin: spotbugs/spotbugs

public InstructionHandleMap(MethodGen methodGen) {
  map = new Object[methodGen.getMethod().getCode().getLength()];
}

代码示例来源:origin: spotbugs/spotbugs

private static int getLineNumber(Method method, InstructionHandle handle) {
    LineNumberTable table = method.getCode().getLineNumberTable();
    if (table == null) {
      return -1;
    }
    return table.getSourceLine(handle.getPosition());
  }
}

代码示例来源:origin: spotbugs/spotbugs

@Override
  public CompactLocationNumbering analyze(IAnalysisCache analysisCache, MethodDescriptor descriptor)
      throws CheckedAnalysisException {
    Method method = analysisCache.getMethodAnalysis(Method.class, descriptor);

    if (method.getCode() == null) {
      return null;
    }

    CFG cfg = getCFG(analysisCache, descriptor);
    return new CompactLocationNumbering(cfg);
  }
}

代码示例来源:origin: spotbugs/spotbugs

@Override
public void visitClassContext(ClassContext classContext) {
  Method[] methodList = classContext.getJavaClass().getMethods();
  for (Method method : methodList) {
    if (method.getCode() == null) {
      continue;
    }
    try {
      analyzeMethod(classContext, method);
    } catch (CFGBuilderException e) {
      bugReporter.logError("Detector " + this.getClass().getName() + " caught exception", e);
    } catch (DataflowAnalysisException e) {
      // bugReporter.logError("Detector " + this.getClass().getName()
      // + " caught exception", e);
    }
  }
}

代码示例来源:origin: spotbugs/spotbugs

public boolean isCaught(ClassContext classContext, Method method, UnconditionalValueDerefSet entryFact, ValueNumber paramVN) {
  boolean caught = true;
  Set<Location> dereferenceSites
  = entryFact.getDerefLocationSet(paramVN);
  if (dereferenceSites != null && !dereferenceSites.isEmpty()) {
    ConstantPool cp = classContext.getJavaClass().getConstantPool();
    for(Location loc : dereferenceSites) {
      if (!FindNullDeref.catchesNull(cp, method.getCode(), loc)) {
        caught = false;
      }
    }
  }
  return caught;
}

代码示例来源:origin: spotbugs/spotbugs

@Override
public void visitClassContext(ClassContext classContext) {
  Method[] methodList = classContext.getJavaClass().getMethods();
  for (Method method : methodList) {
    if (method.getCode() == null) {
      continue;
    }
    try {
      analyzeMethod(classContext, method);
    } catch (MethodUnprofitableException mue) {
      if (SystemProperties.getBoolean("unprofitable.debug")) {
        // don't
        // report
        bugReporter.logError("skipping unprofitable method in " + getClass().getName());
      }
    } catch (CFGBuilderException e) {
      bugReporter.logError("Detector " + this.getClass().getName() + " caught exception", e);
    } catch (DataflowAnalysisException e) {
      bugReporter.logError("Detector " + this.getClass().getName() + " caught exception", e);
    }
  }
}

代码示例来源:origin: spotbugs/spotbugs

@Override
public @CheckForNull JumpInfo analyze(IAnalysisCache analysisCache, MethodDescriptor descriptor) throws CheckedAnalysisException {
  Method method = analysisCache.getMethodAnalysis(Method.class, descriptor);
  JavaClass jclass = getJavaClass(analysisCache, descriptor.getClassDescriptor());
  Code code = method.getCode();
  if (code == null) {
    return null;
  }
  JumpStackComputation branchAnalysis = new JumpStackComputation(descriptor);
  return computeJumpInfo(jclass, method, branchAnalysis);
}

代码示例来源:origin: spotbugs/spotbugs

@Override
public void visitClassContext(ClassContext classContext) {
  Method[] methodList = classContext.getJavaClass().getMethods();
  for (Method method : methodList) {
    if (method.getCode() == null) {
      continue;
    }
    try {
      analyzeMethod(classContext, method);
    } catch (CFGBuilderException e) {
      bugReporter.logError("Detector " + this.getClass().getName() + " caught exception", e);
    } catch (DataflowAnalysisException e) {
      // bugReporter.logError("Detector " + this.getClass().getName()
      // + " caught exception", e);
    }
    bugAccumulator.reportAccumulatedBugs();
  }
}

代码示例来源:origin: spotbugs/spotbugs

boolean inIndirectCatchNullBlock(Location loc) {
    int pc = loc.getHandle().getPosition();
    int catchSize = Util.getSizeOfSurroundingTryBlock(classContext.getJavaClass().getConstantPool(), method.getCode(),
        "java/lang/Exception", pc);
    if (catchSize < 5) {
      return true;
    }
    catchSize = Util.getSizeOfSurroundingTryBlock(classContext.getJavaClass().getConstantPool(), method.getCode(),
        "java/lang/RuntimeException", pc);
    if (catchSize < 5) {
      return true;
    }
    catchSize = Util.getSizeOfSurroundingTryBlock(classContext.getJavaClass().getConstantPool(), method.getCode(),
        "java/lang/Throwable", pc);
    if (catchSize < 5) {
      return true;
    }
    return false;
  }
}

代码示例来源:origin: spotbugs/spotbugs

boolean inExplictCatchNullBlock(Location loc) {
  int pc = loc.getHandle().getPosition();
  int catchSize = Util.getSizeOfSurroundingTryBlock(classContext.getJavaClass().getConstantPool(), method.getCode(),
      "java/lang/NullPointerException", pc);
  if (catchSize < Integer.MAX_VALUE) {
    return true;
  }
  return false;
}

代码示例来源:origin: spotbugs/spotbugs

@Override
public void visitClassContext(ClassContext classContext) {
  Method[] methodList = classContext.getJavaClass().getMethods();
  for (Method method : methodList) {
    if (method.getCode() == null) {
      continue;
    }
    try {
      analyzeMethod(classContext, method);
    } catch (CFGBuilderException e) {
      bugReporter.logError("Error compting field store types", e);
    } catch (DataflowAnalysisException e) {
      bugReporter.logError("Error compting field store types", e);
    }
  }
}

代码示例来源:origin: spotbugs/spotbugs

@Override
public void visitClassContext(ClassContext classContext) {
  JavaClass javaClass = classContext.getJavaClass();
  Method[] methodList = javaClass.getMethods();
  for (Method method : methodList) {
    if (method.getCode() == null) {
      continue;
    }
    try {
      analyzeMethod(classContext, method);
    } catch (MethodUnprofitableException e) {
      assert true; // move along; nothing to see
    } catch (CFGBuilderException e) {
      String msg = "Detector " + this.getClass().getName() + " caught exception while analyzing "
          + javaClass.getClassName() + "." + method.getName() + " : " + method.getSignature();
      bugReporter.logError(msg, e);
    } catch (DataflowAnalysisException e) {
      String msg = "Detector " + this.getClass().getName() + " caught exception while analyzing "
          + javaClass.getClassName() + "." + method.getName() + " : " + method.getSignature();
      bugReporter.logError(msg, e);
    }
  }
}

代码示例来源:origin: spotbugs/spotbugs

@Override
  public UnpackedCode analyze(IAnalysisCache analysisCache, MethodDescriptor descriptor) throws CheckedAnalysisException {
    Method method = getMethod(analysisCache, descriptor);
    Code code = method.getCode();
    if (code == null) {
      return null;
    }

    byte[] instructionList = code.getCode();

    // Create callback
    UnpackedBytecodeCallback callback = new UnpackedBytecodeCallback(instructionList.length);

    // Scan the method.
    BytecodeScanner scanner = new BytecodeScanner();
    scanner.scan(instructionList, callback);

    return callback.getUnpackedCode();

  }
}

代码示例来源:origin: spotbugs/spotbugs

@Override
public void visitClassContext(ClassContext classContext) {
  JavaClass javaClass = classContext.getJavaClass();
  Method[] methodList = javaClass.getMethods();
  for (Method method : methodList) {
    if (method.getCode() == null) {
      continue;
    }
    if (!prescreen(classContext, method)) {
      continue;
    }
    try {
      analyzeMethod(classContext, method);
    } catch (CFGBuilderException e) {
      bugReporter.logError("FindSleepWithLockHeld caught exception", e);
    } catch (DataflowAnalysisException e) {
      bugReporter.logError("FindSleepWithLockHeld caught exception", e);
    }
  }
}

代码示例来源:origin: spotbugs/spotbugs

/**
 * Create from Method and bytecode offset in a visited class.
 *
 * @param jclass
 *            JavaClass of visited class
 * @param method
 *            Method in visited class
 * @param pc
 *            bytecode offset in visited method
 * @return SourceLineAnnotation describing visited instruction
 */
public static SourceLineAnnotation fromVisitedInstruction(JavaClass jclass, Method method, int pc) {
  LineNumberTable lineNumberTable = method.getCode().getLineNumberTable();
  String className = jclass.getClassName();
  String sourceFile = jclass.getSourceFileName();
  if (lineNumberTable == null) {
    return createUnknown(className, sourceFile, pc, pc);
  }
  int startLine = lineNumberTable.getSourceLine(pc);
  return new SourceLineAnnotation(className, sourceFile, startLine, startLine, pc, pc);
}

代码示例来源:origin: spotbugs/spotbugs

@Override
public MethodBytecodeSet analyze(IAnalysisCache analysisCache, MethodDescriptor descriptor) throws CheckedAnalysisException {
  Method method = analysisCache.getMethodAnalysis(Method.class, descriptor);
  Code code = method.getCode();
  if (code == null) {
    return null;
  }
  byte[] instructionList = code.getCode();
  // Create callback
  UnpackedBytecodeCallback callback = new UnpackedBytecodeCallback(instructionList.length);
  // Scan the method.
  BytecodeScanner scanner = new BytecodeScanner();
  scanner.scan(instructionList, callback);
  UnpackedCode unpackedCode = callback.getUnpackedCode();
  MethodBytecodeSet result = null;
  if (unpackedCode != null) {
    result = unpackedCode.getBytecodeSet();
  }
  return result;
}

相关文章