Ejemplo n.º 1
0
  /**
   * Builds a new {@link ClassInstanceCreation} instance.
   *
   * @param typeBinding the type binding of the instantiated type
   * @param arguments the constructor invocation arguments
   * @return a new class instance creation
   */
  public ClassInstanceCreation new0(ITypeBinding typeBinding, Expression... arguments) {
    final String className = typeBinding.getName();
    final int ltIdx = className.indexOf('<');
    if (ltIdx == -1) {
      final ClassInstanceCreation cic = ast.newClassInstanceCreation();
      cic.setType(newSimpleType(className));
      addAll(arguments(cic), arguments);
      return cic;
    }

    final String erasedClassName = className.substring(0, ltIdx);
    final int gtIdx = className.indexOf('>', ltIdx);
    final String typeParams = className.substring(ltIdx + 1, gtIdx);

    final ClassInstanceCreation cic = ast.newClassInstanceCreation();
    final ParameterizedType type = ast.newParameterizedType(newSimpleType(erasedClassName));
    addNewTypesFromTypeParameters(typeArguments(type), typeParams);
    cic.setType(type);
    addAll(arguments(cic), arguments);
    return cic;
  }
Ejemplo n.º 2
0
 /**
  * Builds a new {@link ClassInstanceCreation} instance.
  *
  * @param typeName the instantiated type name
  * @param arguments the constructor invocation arguments
  * @return a new class instance creation
  */
 public ClassInstanceCreation new0(String typeName, Expression... arguments) {
   final ClassInstanceCreation cic = ast.newClassInstanceCreation();
   cic.setType(newSimpleType(typeName));
   addAll(arguments(cic), arguments);
   return cic;
 }