Ejemplo n.º 1
0
  /**
   * Generates a printable string that represents the given ActionScript 3 code.
   *
   * @param resolvedCode The ActionScript 3 code to turn into a string.
   * @param code The raw ActionScript 3 code.
   * @param prefix The prefix to write before every printed line.
   * @return The generated ActionScript 3 code string.
   */
  private static String getCodeText(
      final ResolvedCode resolvedCode, final AS3Code code, final String prefix) {

    if (code.getInstructions().size() == 0) {
      return "";
    }

    final StringBuilder sb = new StringBuilder();

    final AS3Instruction firstInstruction = code.getInstructions().get(0);

    final int firstOffset = firstInstruction.getBitPosition();

    for (final AS3Instruction instruction : code.getInstructions()) {

      final int absoluteOffset = instruction.getBitPosition() / 8;
      final int relativeOffset = absoluteOffset - firstOffset / 8;
      sb.append(prefix);
      sb.append(String.format("%08X %08X  ", absoluteOffset, relativeOffset));

      addInstructionText(sb, instruction, resolvedCode, firstOffset / 8);

      sb.append('\n');
    }

    return sb.toString();
  }
Ejemplo n.º 2
0
  /**
   * Generates a printable string that represents all code in a given resolved ActionScript 3 code
   * snippet.
   *
   * @param code The resolved code to display.
   * @return The generated ActionScript 3 code string.
   */
  public static String getCodeText(final ResolvedCode code) {
    final StringBuilder sb = new StringBuilder();

    for (final ResolvedClass resolvedClass : code.getClasses()) {

      // Start out with the class definition.
      addClassHeader(resolvedClass, sb);

      boolean hadCode = false;

      // Start preparing all the methods for printing. Add the instance
      // constructor and the class constructor for printing.
      final ResolvedMethod staticConstructor = resolvedClass.getStaticConstructor();
      final ResolvedMethod constructor = resolvedClass.getConstructor();

      final List<ResolvedMethod> resolvedMethods = resolvedClass.getMethods();

      resolvedMethods.add(0, constructor);

      if (staticConstructor.getCode() != null) {
        // Only add the static constructor if it actually has code.
        resolvedMethods.add(0, staticConstructor);
      }

      final String className = ActionScript3Helpers.flattenNamespaceName(resolvedClass.getName());

      // Print the individual methods now.
      for (final ResolvedMethod resolvedMethod : resolvedMethods) {

        if (resolvedMethod != resolvedMethods.get(0)) {
          if (hadCode || resolvedMethod.getCode() != null) {
            sb.append("\n");
          }
        }

        hadCode = addMethod(code, resolvedMethod, className, sb);
      }

      addClassFooter(sb);
    }

    return sb.toString();
  }