Java 类com.sun.javadoc.AnnotationDesc.ElementValuePair 实例源码

项目:wrdocletbase    文件:AbstractDocBuilder.java   
protected void processAnnotations(AnnotationDesc annotation, APIParameter apiParameter) {
    if (annotation.annotationType().qualifiedName().startsWith("org.springframework.web.bind.annotation.")) {
        for (ElementValuePair pair : annotation.elementValues()) {
            if (pair.element().name().equals("value") || pair.element().name().equals("name")) {
                if (pair.value() != null) {
                    apiParameter.setName(pair.value().toString().replace("\"", ""));
                }
            }
            if (pair.element().name().equals("required")) {
                if (pair.value().value().equals(true)) {
                    apiParameter.setParameterOccurs(ParameterOccurs.REQUIRED);
                } else {
                    apiParameter.setParameterOccurs(ParameterOccurs.OPTIONAL);
                }
            }
        }
    }
}
项目:wrdocletbase    文件:SOAPDocBuilder.java   
@Override
protected RequestMapping parseRequestMapping(MethodDoc method) {
    RequestMapping mapping = new RequestMapping();
    mapping.setContainerName(method.containingClass().simpleTypeName());
    AnnotationDesc[] annotations = method.annotations();
    String url = method.toString().replaceFirst(
            method.containingClass().qualifiedName() + ".", "");
    for (int i = 0; i < annotations.length; i++) {
        if (annotations[i].annotationType().name().equals("WebMethod")) {
            for (ElementValuePair p : annotations[i].elementValues()) {
                if (p.element().name().equals("operationName")) {
                    url = url.replace(method.name(), p.value().value()
                            .toString().replace("\"", ""));
                }
            }
        }
    }
    mapping.setUrl(url);
    mapping.setTooltip(method.containingClass().simpleTypeName());
    mapping.setContainerName(method.containingClass().simpleTypeName());
    return mapping;
}
项目:wrdocletbase    文件:AbstractDocBuilder.java   
protected String getFieldValidatorDesc(FieldDoc fieldDoc) {
    StringBuilder strBuilder = new StringBuilder();
    for (AnnotationDesc annotationDesc : fieldDoc.annotations()) {
        if (annotationDesc.annotationType().qualifiedTypeName().startsWith("org.hibernate.validator.constraints")
                || annotationDesc.annotationType().qualifiedTypeName().startsWith("javax.validation.constraints")
                || annotationDesc.annotationType().qualifiedTypeName().startsWith("lombok.NonNull")) {
            strBuilder.append("@");
            strBuilder.append(annotationDesc.annotationType().name());
            if (annotationDesc.elementValues().length > 0) {
                strBuilder.append("(");
                boolean isFirstElement = true;
                for (AnnotationDesc.ElementValuePair elementValuePair : annotationDesc.elementValues()) {
                    if (!isFirstElement) {
                        strBuilder.append(",");
                    }
                    strBuilder.append(elementValuePair.element().name());
                    strBuilder.append("=");
                    strBuilder.append(
                            net.winroad.wrdoclet.utils.Util.decodeUnicode(elementValuePair.value().toString()));
                    isFirstElement = false;
                }
                strBuilder.append(")");
            }
            strBuilder.append(" ");
        }
    }
    return strBuilder.toString();
}
项目:wrdocletbase    文件:SOAPDocBuilder.java   
@Override
protected APIParameter getOutputParam(MethodDoc method) {
    APIParameter apiParameter = null;
    if (method.returnType() != null) {
        apiParameter = new APIParameter();
        AnnotationDesc[] annotations = method.annotations();
        boolean isResNameCustomized = false;
        for (int i = 0; i < annotations.length; i++) {
            if (annotations[i].annotationType().name().equals("WebResult")) {
                for (ElementValuePair p : annotations[i].elementValues()) {
                    if (p.element().name().equals("name")) {
                        apiParameter.setName(p.value().value().toString());
                        isResNameCustomized = true;
                    }
                }
            }
        }
        if (!isResNameCustomized) {
            apiParameter.setName("return");
        }
        apiParameter.setParameterOccurs(ParameterOccurs.REQUIRED);
        apiParameter.setType(this.getTypeName(method.returnType(), false));
        for (Tag tag : method.tags("return")) {
            apiParameter.setDescription(tag.text());
        }
        HashSet<String> processingClasses = new HashSet<String>();
        apiParameter.setFields(this.getFields(method.returnType(),
                ParameterType.Response, processingClasses));
        apiParameter.setHistory(this.getModificationHistory(method
                .returnType()));
    }
    return apiParameter;
}
项目:azuki-doclet-jaxrs    文件:DocletUtility.java   
public static Object getAnnotationValue(final AnnotationDesc annotation, final String name) {
    for (final ElementValuePair elementValuePair : annotation.elementValues()) {
        if (elementValuePair.element().name().equals(name)) {
            return elementValuePair.value().value();
        }
    }
    return null;
}
项目:xmldoclet    文件:XMLDoclet.java   
/**
 *
 * @return an "annotation" XML node for the annotation.
 */
private static XMLNode toAnnotationNode(AnnotationDesc annotation) {
  if (annotation == null) return null;
  XMLNode node = new XMLNode("annotation");
  node.attribute("name", annotation.annotationType().name());
  for (ElementValuePair pair : annotation.elementValues()) {
    node.child(toPairNode(pair));
  }
  return node;
}
项目:xmldoclet    文件:XMLDoclet.java   
/**
 *
 * @return an "element" XML node for the element value pair.
 */
private static XMLNode toPairNode(ElementValuePair pair) {
  if (pair == null) return null;
  XMLNode node = new XMLNode("element");
  AnnotationTypeElementDoc element = pair.element();
  node.attribute("name", element.name());
  node.child(toComment(element));
  node.child(toAnnotationValueNode(pair.value()));
  return node;
}
项目:api-resolver    文件:DocletUtil.java   
public static Object getAnnotationDescValue(AnnotationDesc annotationDesc, String name) {
    for (ElementValuePair elementValuePair : annotationDesc.elementValues()) {
        if (elementValuePair.element().name().equals(name)) {
            return elementValuePair.value().value();
        }
    };
    return null;
}
项目:conqat    文件:ConQATTaglet.java   
/**
 * Get annotation value.
 * 
 * @returns the value or <code>null</code> if key was not found.
 */
private String getValue(AnnotationDesc annotation, String key) {
    for (ElementValuePair pair : annotation.elementValues()) {
        if (pair.element().name().equals(key)) {
            // double call to value is correct as this returns the actual
            // value object.
            return pair.value().value().toString();
        }
    }
    return null;
}
项目:performance_javadoc    文件:AnnotationParser.java   
/**
 * Method to return the String annotation value, that belongs to some key
 *
 * @param annotation
 * @param key
 * @return the value, that belongs to the key or null, if no such exists
 */
public static String getAnnotationValueString(AnnotationDesc annotation, String key) {
    ElementValuePair[] evp = annotation.elementValues();

    for (ElementValuePair e : evp) {
        if (e.element().toString().equals(key)) {
            return e.value().toString().substring(1, e.value().toString().length() - 1);
        }
    }

    return null;
}
项目:performance_javadoc    文件:AnnotationParser.java   
/**
 * Method to return the Double annotation value, that belongs to some key
 *
 * @param annotation
 * @param key
 * @return the value, that belongs to the key or null, if no such exists
 */
public static double getAnnotationValueDouble(AnnotationDesc annotation, String key) throws NumberFormatException {
    ElementValuePair[] evp = annotation.elementValues();

    for (ElementValuePair e : evp) {
        if (e.element().toString().equals(key)) {
            return Double.parseDouble(e.value().toString());
        }
    }

    //to indicate, that nothing was found
    return Double.MIN_VALUE;
}
项目:performance_javadoc    文件:AnnotationParser.java   
/**
 * Method to return the boolean annotation value, that belongs to some key
 *
 * @param annotation
 * @param key
 * @return the value, that belongs to the key or null, if no such exists
 */
public static boolean getAnnotationValueBoolean(AnnotationDesc annotation, String key) throws NumberFormatException {
    ElementValuePair[] evp = annotation.elementValues();

    for (ElementValuePair e : evp) {
        if (e.element().toString().equals(key)) {
            return Boolean.parseBoolean(e.value().toString());
        }
    }

    //default value of axis is true
    return true;
}
项目:bazooka-wo-xmldoclet    文件:XMLDoclet.java   
/**
 *
 * @return an "annotation" XML node for the annotation.
 */
private static XMLNode toAnnotationNode(AnnotationDesc annotation) {
  if (annotation == null) return null;
  XMLNode node = new XMLNode("annotation");
  node.attribute("name", annotation.annotationType().name());
  for (ElementValuePair pair : annotation.elementValues()) {
    node.child(toPairNode(pair));
  }
  return node;
}
项目:bazooka-wo-xmldoclet    文件:XMLDoclet.java   
/**
 *
 * @return an "element" XML node for the element value pair.
 */
private static XMLNode toPairNode(ElementValuePair pair) {
  if (pair == null) return null;
  XMLNode node = new XMLNode("element");
  AnnotationTypeElementDoc element = pair.element();
  node.attribute("name", element.name());
  node.child(toShortComment(element));
  node.child(toComment(element));
  node.child(toAnnotationValueNode(pair.value()));
  return node;
}
项目:closure-maven-plugin    文件:PluginConfigDoclet.java   
void renderDocsFor(Crawl crawl, Configurable c, File outDir)
throws IOException {
  Element e;
  {
    Element.Builder eb = Element.newBuilder();
    eb.setClassName(c.configurableClass.qualifiedName());
    String commentText = c.configurableClass.commentText();
    if (!Strings.isNullOrEmpty(commentText)) {
      eb.setCommentHtml(commentToHtml(commentText));
    }
    eb.setIsEnum(c.configurableClass.isEnum());
    eb.setIsMojo(c.isMojo);
    if (c.isMojo) {
      String goal = null;
      Optional<AnnotationDesc> mojoAnnot = annotationNamed(
          c.configurableClass, MOJO_ANNOTATION_NAME);
      if (mojoAnnot.isPresent()) {
        for (ElementValuePair p : mojoAnnot.get().elementValues()) {
          if ("name".equals(p.element().name())) {
            goal = (String) p.value().value();
          }
        }
      }
      if (goal != null) {
        eb.setGoal(goal);
      }
    }
    eb.addAllTagName(c.tagNames);
    // Present in lexicographic order.
    for (String paramName : Sets.newTreeSet(c.params.keySet())) {
      ParameterInfo pi = c.params.get(paramName);
      Parameter.Builder pb = Parameter.newBuilder();
      pb.setName(pi.name);
      if (pi.field.isPresent()) {
        FieldDoc fd = pi.field.get();
        pb.setField(fd.containingClass().qualifiedName() + "#" + fd.name());

      }
      if (pi.setter.isPresent()) {
        MethodDoc s = pi.setter.get();
        pb.setMethod(
            s.containingClass().qualifiedName()
            + "#" + s.name() + s.flatSignature());
      }
      pb.setSourcePosition(pi.source().position().toString());
      Type t = pi.getType();
      pb.setType(t.simpleTypeName());
      Optional<Configurable> tc = crawl.foundConfigurable(pi.source(), t);
      if (tc.isPresent()) {
        pb.setTypeUrl(urlFor(tc.get()));
      }
      String pCommentText = pi.getCommentText();
      if (!Strings.isNullOrEmpty(pCommentText)) {
        pb.setCommentHtml(commentToHtml(pCommentText));
      }
      eb.addParam(pb);
    }
    e = eb.build();
  }


  ImmutableMap<String, Object> data =
      ImmutableMap.<String, Object>of("e", e);
  SoySauce.Renderer renderer = soySauce
      .renderTemplate("com.google.closure.doclet.soy.Configurable")
      .setData(data)
      ;

  Continuation<String> renderedHtml = renderer.render();
  while (!renderedHtml.result().isDone()) {
    renderedHtml = renderedHtml.continueRender();
  }

  File outFile = new File(outDir.toURI().resolve(urlFor(c)));

  CharSink dest = Files.asCharSink(outFile, Charsets.UTF_8);
  try (Writer out = dest.openBufferedStream()) {
    out.write(renderedHtml.get());
  }
}