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);
  }