@SuppressWarnings("unchecked")
  private int addMemberField(AbstractTypeDeclaration typeNode, AST ast, ASTRewrite astRewrite) {
    // Construct a member variable declaration.
    SimpleName varType = ast.newSimpleName(CREATED_VARIABLE_TYPE);
    SimpleName varName = ast.newSimpleName(CREATED_VARIABLE_NAME);
    SimpleType variableType = ast.newSimpleType(varType);
    VariableDeclarationFragment vdf = ast.newVariableDeclarationFragment();
    vdf.setName(varName);
    FieldDeclaration fieldDeclaration = ast.newFieldDeclaration(vdf);
    fieldDeclaration.modifiers().add(
        ast.newModifier(ModifierKeyword.PRIVATE_KEYWORD));
    fieldDeclaration.modifiers().add(
        ast.newModifier(ModifierKeyword.FINAL_KEYWORD));
    fieldDeclaration.setType(variableType);
    ListRewrite listRewrite =
        astRewrite.getListRewrite(typeNode, typeNode
            .getBodyDeclarationsProperty());
    List<Object> originalList = listRewrite.getOriginalList();
    int positionOfLastMemberFieldFound = 0;
    // We only consider the static fields that appear before the non-static
    // fields -- all others are ignored.
    int positionOfLastStaticFieldBeforeMemberFieldsFound = 0;
    for (int i = 0; i < originalList.size() - 1; i++) {
      final Object node = originalList.get(i);
      if (node instanceof FieldDeclaration) {
        FieldDeclaration field = (FieldDeclaration)node;
        if (isStatic(field)) {
          if (positionOfLastMemberFieldFound == 0) {
            positionOfLastStaticFieldBeforeMemberFieldsFound = i + 1;
          } 
        } else {
          positionOfLastMemberFieldFound = i + 1;
        }
      }
    }
    
    listRewrite.insertAt(fieldDeclaration, positionOfLastStaticFieldBeforeMemberFieldsFound, null);
    return Math.max(positionOfLastMemberFieldFound, positionOfLastStaticFieldBeforeMemberFieldsFound);
  }