Пример #1
0
 String javap(String... args) throws Exception {
   StringWriter sw = new StringWriter();
   PrintWriter pw = new PrintWriter(sw);
   int rc = com.sun.tools.javap.Main.run(args, pw);
   if (rc != 0) throw new Exception("javap failed, rc=" + rc);
   return sw.toString();
 }
Пример #2
0
 String javap(String... args) {
   StringWriter sw = new StringWriter();
   PrintWriter out = new PrintWriter(sw);
   // sun.tools.javap.Main.entry(args);
   int rc = com.sun.tools.javap.Main.run(args, out);
   if (rc != (args.length == 0 ? 2 : 0)) throw new Error("javap failed. rc=" + rc);
   out.close();
   return sw.toString();
 }
 void check(String... params) {
   StringWriter s;
   String out;
   try (PrintWriter pw = new PrintWriter(s = new StringWriter())) {
     com.sun.tools.javap.Main.run(params, pw);
     out = s.toString();
   }
   if (out.contains("ldc_w")) {
     throw new AssertionError(assertionErrorMsg);
   }
 }
  public void run() {
    String[] args = {"-classpath", System.getProperty("test.classes", "."), "-v", "Test"};
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    int rc = com.sun.tools.javap.Main.run(args, pw);
    if (rc != 0) throw new Error("javap failed; exit " + rc);

    String out = sw.toString();
    System.out.println(out);

    for (String line : out.split("(\\n|\\r\\n?)")) {
      String match =
          "[ \t]+[0-9]+:[ \t]+invokevirtual[ \t]+#[0-9]+[ \t]+// Method \"\\[Ljava/lang/String;\".clone:\\(\\)Ljava/lang/Object;";
      if (line.matches(match)) return;
    }
    throw new Error("expected string not found in javap output");
  }