protected void annotateJavaElement(
      TopLevelClass topLevelClass, JavaElement javaElement, String tildSeparatedAnnotations) {
    List<String> lstUserAnnotations = new ArrayList<String>();
    StringBuilder sb = new StringBuilder();
    String annot = null, bracketFragment = null;

    if (javaElement instanceof TopLevelClass
        && !tildSeparatedAnnotations.contains(getXmlAccessTypeConstant()))
      tildSeparatedAnnotations += '~' + getXmlAccessTypeConstant();

    for (String annotation : tildSeparatedAnnotations.split("~")) {
      javaElement.addAnnotation(annotation);

      sb.append(annotation);
      sb.deleteCharAt(0); // remove the leading @ sign from the annotation.

      int ind = sb.indexOf("(");
      if (ind != -1) {
        annot = sb.substring(0, ind);
        bracketFragment = sb.substring(ind + 1);

        if (bracketFragment.startsWith("XmlAccessType."))
          lstUserAnnotations.add(
              "XmlAccessType"); // Add the import for XmlAccessType annotation that is inside the
        // parenthesis of XmlAccessorType: (XmlAccessType.FIELD) or
        // (XmlAccessType.PROPERTY). Example:
        // @XmlAccessorType(XmlAccessType.FIELD)
        else if (bracketFragment.startsWith("XmlAccessOrder."))
          lstUserAnnotations.add(
              "XmlAccessOrder"); // Add the import for XmlAccessOrder annotation that is inside the
        // parenthesis of XmlAccessorOrder: (XmlAccessorOrder.ALPHABETICAL)
        // or (XmlAccessorOrder.UNDEFINED). Example:
        // @XmlAccessorOrder(XmlAccessorOrder.ALPHABETICAL)
      } else annot = sb.toString();

      sb.delete(0, sb.length());

      if (!lstUserAnnotations.contains(annot)) lstUserAnnotations.add(annot);
    }

    addImportsForAnnotations(topLevelClass, lstUserAnnotations.toArray(new String[0]));
  }
Ejemplo n.º 2
0
 /** Adds the suppress type warnings annotation. */
 public void addSuppressTypeWarningsAnnotation() {
   addAnnotation("@SuppressWarnings(\"unchecked\")"); // $NON-NLS-1$
 }