本文整理汇总了Java中com.thoughtworks.qdox.model.expression.AnnotationValue类的典型用法代码示例。如果您正苦于以下问题:Java AnnotationValue类的具体用法?Java AnnotationValue怎么用?Java AnnotationValue使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AnnotationValue类属于com.thoughtworks.qdox.model.expression包,在下文中一共展示了AnnotationValue类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createContentTypeAnnotation
import com.thoughtworks.qdox.model.expression.AnnotationValue; //导入依赖的package包/类
private AnnotationSpec createContentTypeAnnotation(
EvaluatingVisitor evaluatingVisitor,
JavaAnnotation consumesAnnotation) {
AnnotationValue annotationValue = consumesAnnotation.getProperty("value");
String stringAnnotationValue = annotationValue.getParameterValue().toString();
String value = null;
if (stringAnnotationValue.startsWith(MediaType.class.getSimpleName() + ".")) {
String[] token = stringAnnotationValue.split("\\.");
try {
value = (String) MediaType.class.getDeclaredField(token[1]).get(null);
} catch (Exception e) {
e.printStackTrace(System.err);
}
} else {
value = consumesAnnotation.getProperty("value").accept(evaluatingVisitor).toString();
}
return AnnotationSpec.builder(Headers.class)
.addMember("value", "\"Content-type: " + value + "\"")
.build();
}
示例2: build
import com.thoughtworks.qdox.model.expression.AnnotationValue; //导入依赖的package包/类
/**
* Builds the descriptor.
* @return The built portlet descriptor.
*/
public PortletTypeDescriptor build() {
AnnotationValue id = anno.getProperty(ID_PROPERTY_NAME);
AnnotationValue title = anno.getProperty(TITLE_PROPERTY_NAME);
AnnotationValue tooltip = anno.getProperty(TOOLTIP_PROPERTY_NAME);
return new PortletTypeDescriptor(
cls.getCanonicalName(),
cls.getName(),
cls.getPackageName(),
annotationValueToString(id),
annotationValueToString(title),
annotationValueToString(tooltip));
}
示例3: annotationValueToString
import com.thoughtworks.qdox.model.expression.AnnotationValue; //导入依赖的package包/类
/**
* Converts a possibly null annotation value to a non-null (possibly empty) string.
* @param annotationValue The annotation value to be converted.
* @return The String value of the annotation.
*/
private static String annotationValueToString(AnnotationValue annotationValue) {
if(annotationValue == null) {
return "";
}
else if(annotationValue.getParameterValue() instanceof String) {
String parameterValue = (String) annotationValue.getParameterValue();
return parameterValue.substring(1, parameterValue.length() - 1);
}
else {
return annotationValue.getParameterValue().toString();
}
}
示例4: createPathAnnotation
import com.thoughtworks.qdox.model.expression.AnnotationValue; //导入依赖的package包/类
private AnnotationSpec createPathAnnotation(
EvaluatingVisitor evaluatingVisitor,
HttpMethod method,
JavaAnnotation classPath,
JavaAnnotation methodPath) {
AnnotationValue pathExpression = classPath.getProperty("value");
if (methodPath != null) {
pathExpression = new Add(pathExpression, methodPath.getProperty("value"));
}
String value = pathExpression.accept(evaluatingVisitor).toString();
Matcher matcher = pathRegexPattern.matcher(value);
StringBuilder regexFreeValue = new StringBuilder();
while (matcher.find()) {
regexFreeValue.append("/");
String regexValue = matcher.group(0);
if (regexValue.startsWith("{")) regexFreeValue
.append("{")
.append(matcher.group(1))
.append("}");
else regexFreeValue.append(matcher.group(1));
}
return AnnotationSpec.builder(method.getRetrofitClass())
.addMember("value", "\"" + regexFreeValue.toString() + "\"")
.build();
}
示例5: extractImplementations
import com.thoughtworks.qdox.model.expression.AnnotationValue; //导入依赖的package包/类
/**
* <p>If a field is marked as @XmlElements, then it should contain the list of implementations.</p>
*
* <p>For example, </br>
*
* <pre>
* @XmlElements({
* @XmlElement(name = "FirstClass"),
* @XmlElement(name = "SecondClass", type = SecondClass.class),
* @XmlElement(name = "ThirdClass", type = ThirdClass.class),
* @XmlElement(name = "FourthClass", type = FourthClass.class),
* @XmlElement(name = "FifthClass", type = FifthClass.class),
* })
* @Generated(value = "com.sun.tools.xjc.Driver", date = "2015-02-20T03:52:29+00:00", comments = "JAXB RI v2.2.10-b140310.1920")
* protected List<FirstClass> lstField;
* </pre>
*
* As you can see, that given field has several implementations:
* SecondClass, ThirdClass, FourthClass and FifthClass. This method allows
* to extract the list containing these classes
* </p>
*
* <p>Note, that the very first class ("FirstClass" in this case) should be ommitted,
* because it is generic class and doesn't contain "type" attribute.</p>
*
* <p>Please refer to unit tests</p>
* @param field
* @return
*/
public static Set<String> extractImplementations(JavaField field) {
// search for @XmlElements annotation
final Optional<JavaAnnotation> optElementsAnnotation = field.getAnnotations()
.stream()
.filter((annotation) -> annotation.getType().isA(XmlElements.class.getCanonicalName()))
.findFirst();
if (optElementsAnnotation.isPresent()) {
// get list of all the inner @XmlElement elements
final AnnotationValue value = optElementsAnnotation.get().getProperty("value");
final List<AnnotationValue> annotationValueList = ((AnnotationValueList) value).getValueList();
// ...and collect values from these annotations
return annotationValueList
.stream()
.map((val) -> (DefaultJavaAnnotation) val.getParameterValue())
.filter((ann) -> ann.getPropertyMap().containsKey("type"))
.map( (ann) -> ann.getProperty("name").getParameterValue().toString().replaceAll("\"", ""))
.collect(Collectors.toSet());
}
else {
return ImmutableSet.of();
}
}