public StringBuffer printBody(int indent, StringBuffer output) {

    if (isAbstract() || (this.modifiers & ExtraCompilerModifiers.AccSemicolonBody) != 0)
      return output.append(';');

    output.append(" {"); // $NON-NLS-1$
    if (this.statements != null) {
      for (int i = 0; i < this.statements.length; i++) {
        output.append('\n');
        this.statements[i].printStatement(indent, output);
      }
    }
    output.append('\n');
    printIndent(indent == 0 ? 0 : indent - 1, output).append('}');
    return output;
  }
  public StringBuffer print(int tab, StringBuffer output) {

    if (this.javadoc != null) {
      this.javadoc.print(tab, output);
    }
    printIndent(tab, output);
    printModifiers(this.modifiers, output);
    if (this.annotations != null) {
      printAnnotations(this.annotations, output);
      output.append(' ');
    }

    TypeParameter[] typeParams = typeParameters();
    if (typeParams != null) {
      output.append('<');
      int max = typeParams.length - 1;
      for (int j = 0; j < max; j++) {
        typeParams[j].print(0, output);
        output.append(", "); // $NON-NLS-1$
      }
      typeParams[max].print(0, output);
      output.append('>');
    }

    printReturnType(0, output).append(this.selector).append('(');
    if (this.receiver != null) {
      this.receiver.print(0, output);
    }
    if (this.arguments != null) {
      for (int i = 0; i < this.arguments.length; i++) {
        if (i > 0 || this.receiver != null) output.append(", "); // $NON-NLS-1$
        this.arguments[i].print(0, output);
      }
    }
    output.append(')');
    if (this.thrownExceptions != null) {
      output.append(" throws "); // $NON-NLS-1$
      for (int i = 0; i < this.thrownExceptions.length; i++) {
        if (i > 0) output.append(", "); // $NON-NLS-1$
        this.thrownExceptions[i].print(0, output);
      }
    }
    printBody(tab + 1, output);
    return output;
  }
Ejemplo n.º 3
0
 public String toString(int tab) {
   StringBuffer result = new StringBuffer(tabString(tab));
   result.append("Recovered method:\n"); // $NON-NLS-1$
   this.methodDeclaration.print(tab + 1, result);
   if (this.annotations != null) {
     for (int i = 0; i < this.annotationCount; i++) {
       result.append("\n"); // $NON-NLS-1$
       result.append(this.annotations[i].toString(tab + 1));
     }
   }
   if (this.localTypes != null) {
     for (int i = 0; i < this.localTypeCount; i++) {
       result.append("\n"); // $NON-NLS-1$
       result.append(this.localTypes[i].toString(tab + 1));
     }
   }
   if (this.methodBody != null) {
     result.append("\n"); // $NON-NLS-1$
     result.append(this.methodBody.toString(tab + 1));
   }
   return result.toString();
 }
  private void buildCUSource(String lineSeparator) {
    StringBuffer buffer = new StringBuffer();

    // package declaration
    if (this.snippetPackageName != null && this.snippetPackageName.length != 0) {
      buffer.append("package "); // $NON-NLS-1$
      buffer.append(this.snippetPackageName);
      buffer.append(";").append(lineSeparator); // $NON-NLS-1$
      this.lineNumberOffset++;
    }

    // import declarations
    char[][] imports = this.snippetImports;
    for (int i = 0; i < imports.length; i++) {
      buffer.append("import "); // $NON-NLS-1$
      buffer.append(imports[i]);
      buffer.append(';').append(lineSeparator);
      this.lineNumberOffset++;
    }

    // class declaration
    buffer.append("public class "); // $NON-NLS-1$
    buffer.append(this.snippetClassName);

    // super class is either a global variable class or the CodeSnippet class
    if (this.snippetVarClassName != null) {
      buffer.append(" extends "); // $NON-NLS-1$
      buffer.append(this.snippetVarClassName);
    } else {
      buffer.append(" extends "); // $NON-NLS-1$
      buffer.append(PACKAGE_NAME);
      buffer.append("."); // $NON-NLS-1$
      buffer.append(ROOT_CLASS_NAME);
    }
    buffer.append(" {").append(lineSeparator); // $NON-NLS-1$
    this.lineNumberOffset++;

    if (this.snippetDeclaringTypeName != null) {
      buffer.append("  "); // $NON-NLS-1$
      buffer.append(this.snippetDeclaringTypeName);
      buffer.append(" "); // $NON-NLS-1$
      buffer.append(DELEGATE_THIS); // val$this
      buffer.append(';').append(lineSeparator);
      this.lineNumberOffset++;
    }
    // add some storage location for local variable persisted state
    if (this.localVarNames != null) {
      for (int i = 0, max = this.localVarNames.length; i < max; i++) {
        buffer.append("    "); // $NON-NLS-1$
        buffer.append(this.localVarTypeNames[i]);
        buffer.append(" "); // $NON-NLS-1$
        buffer.append(LOCAL_VAR_PREFIX); // val$...
        buffer.append(this.localVarNames[i]);
        buffer.append(';').append(lineSeparator);
        this.lineNumberOffset++;
      }
    }
    // run() method declaration
    if (this.complianceVersion >= ClassFileConstants.JDK1_5) {
      buffer.append("@Override "); // $NON-NLS-1$
    }
    buffer.append("public void run() throws Throwable {").append(lineSeparator); // $NON-NLS-1$
    this.lineNumberOffset++;
    this.startPosOffset = buffer.length();
    buffer.append(this.codeSnippet);
    // a line separator is required after the code snippet source code
    // in case the code snippet source code ends with a line comment
    // http://dev.eclipse.org/bugs/show_bug.cgi?id=14838
    buffer.append(lineSeparator).append('}').append(lineSeparator);

    // end of class declaration
    buffer.append('}').append(lineSeparator);

    // store result
    int length = buffer.length();
    this.cuSource = new char[length];
    buffer.getChars(0, length, this.cuSource, 0);
  }