/**
   * Adds a static import for the member with name <code>qualifiedMemberName</code>. The member is
   * either a static field or a static method or a '*' to import all static members of a type.
   *
   * @param qualifiedMemberName the fully qualified name of the member to import or a qualified type
   *     name plus a '.*' suffix.
   * @return returns either the simple member name if the import was successful or else the
   *     qualified name.
   * @since 3.4
   */
  public String addStaticImport(String qualifiedMemberName) {
    if (isReadOnly()) return qualifiedMemberName;

    ICompilationUnit cu = getCompilationUnit();
    if (cu == null) return qualifiedMemberName;

    int memberOffset = qualifiedMemberName.lastIndexOf('.');
    if (memberOffset == -1) return qualifiedMemberName;

    String typeName = qualifiedMemberName.substring(0, memberOffset);
    String memberName =
        qualifiedMemberName.substring(memberOffset + 1, qualifiedMemberName.length());
    try {
      boolean isField;
      if ("*".equals(memberName)) { // $NON-NLS-1$
        isField = true;
      } else {
        IJavaProject javaProject = cu.getJavaProject();

        IType type = javaProject.findType(typeName);
        if (type == null) return qualifiedMemberName;

        IField field = type.getField(memberName);
        if (field.exists()) {
          isField = true;
        } else if (hasMethod(type, memberName)) {
          isField = false;
        } else {
          return qualifiedMemberName;
        }
      }

      CompilationUnit root = getASTRoot(cu);
      if (fImportRewrite == null) {
        if (root == null) {
          fImportRewrite = StubUtility.createImportRewrite(cu, true);
        } else {
          fImportRewrite = StubUtility.createImportRewrite(root, true);
        }
      }

      ImportRewriteContext context;
      if (root == null) context = null;
      else
        context =
            new ContextSensitiveImportRewriteContext(root, getCompletionOffset(), fImportRewrite);

      return fImportRewrite.addStaticImport(typeName, memberName, isField, context);
    } catch (JavaModelException e) {
      handleException(null, e);
      return typeName;
    }
  }
  private void addImports(final ICompilationUnit unit, ClipboardData data) throws CoreException {
    final ImportRewrite rewrite = StubUtility.createImportRewrite(unit, true);
    String[] imports = data.getTypeImports();
    for (int i = 0; i < imports.length; i++) {
      rewrite.addImport(imports[i]);
    }
    String[] staticImports = data.getStaticImports();
    for (int i = 0; i < staticImports.length; i++) {
      String name = Signature.getSimpleName(staticImports[i]);
      boolean isField = !name.endsWith("()"); // $NON-NLS-1$
      if (!isField) {
        name = name.substring(0, name.length() - 2);
      }
      String qualifier = Signature.getQualifier(staticImports[i]);
      rewrite.addStaticImport(qualifier, name, isField);
    }

    try {
      getProgressService()
          .busyCursorWhile(
              new IRunnableWithProgress() {
                public void run(IProgressMonitor monitor)
                    throws InvocationTargetException, InterruptedException {
                  try {
                    JavaModelUtil.applyEdit(unit, rewrite.rewriteImports(monitor), false, null);
                  } catch (CoreException e) {
                    throw new InvocationTargetException(e);
                  }
                }
              });
    } catch (InvocationTargetException e) {
      Throwable cause = e.getCause();
      if (cause instanceof CoreException) throw (CoreException) cause;
      throw new CoreException(
          new Status(
              IStatus.ERROR,
              JavaUI.ID_PLUGIN,
              IJavaStatusConstants.INTERNAL_ERROR,
              JavaUIMessages.JavaPlugin_internal_error,
              cause));
    } catch (InterruptedException e) {
      // Canceled by the user
    }
  }