/**
   * Create an AST type node with a type string (possibly partitioned with "." and "[]").
   *
   * @param ast The {@link org.eclipse.jdt.core.dom.AST} object.
   * @param type The type.
   * @return The AST type node.
   */
  public static org.eclipse.jdt.core.dom.Type createType(AST ast, String type) {
    String elementName = Type.getElementType(type);

    org.eclipse.jdt.core.dom.Type elementType;

    if (Type.isPrimitive(elementName)) {
      elementType = ast.newPrimitiveType(PrimitiveType.toCode(elementName));
    } else {
      Name element = createName(ast, elementName);
      elementType = ast.newSimpleType(element);
    }

    org.eclipse.jdt.core.dom.Type returnType = elementType;

    for (int i = 0; i < Type.dimensions(type); i++) {
      returnType = ast.newArrayType(returnType);
    }

    return returnType;
  }
  /**
   * Get the shortest possible name of the a class. If there is no conflict, the class is first
   * imported, and only the simple class is returned; otherwise, the its full name is returned.
   *
   * @param name The full class name.
   * @param state The state of the type analyzer.
   * @param root The root of the AST. If there is no conflict and the class has not been imported
   *     yet, a new {@link org.eclipse.jdt.core.dom.ImportDeclaration} is added to it.
   * @return The shortest possible class name.
   */
  public static String getClassName(String name, TypeAnalyzerState state, CompilationUnit root) {
    int dimensions = Type.dimensions(name);

    if (dimensions > 0) {
      name = Type.getElementType(name);
    }

    name = _getNonarrayClassName(name, state, root);

    if (dimensions > 0) {
      Type type = Type.createType(name);

      for (int i = 0; i < dimensions; i++) {
        type = type.addOneDimension();
      }

      name = type.getName();
    }

    return name;
  }