本文整理汇总了Java中javax.lang.model.element.AnnotationValue类的典型用法代码示例。如果您正苦于以下问题:Java AnnotationValue类的具体用法?Java AnnotationValue怎么用?Java AnnotationValue使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AnnotationValue类属于javax.lang.model.element包,在下文中一共展示了AnnotationValue类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitAnnotation
import javax.lang.model.element.AnnotationValue; //导入依赖的package包/类
@Override
public Void visitAnnotation(AnnotationMirror a, StringBuilder sb) {
sb.append('@').append(typeSimplifier.simplify(a.getAnnotationType()));
Map<ExecutableElement, AnnotationValue> map =
ImmutableMap.<ExecutableElement, AnnotationValue>copyOf(a.getElementValues());
if (!map.isEmpty()) {
sb.append('(');
String sep = "";
for (Map.Entry<ExecutableElement, AnnotationValue> entry : map.entrySet()) {
sb.append(sep).append(entry.getKey().getSimpleName()).append(" = ");
sep = ", ";
this.visit(entry.getValue(), sb);
}
sb.append(')');
}
return null;
}
示例2: findAnnotationValue
import javax.lang.model.element.AnnotationValue; //导入依赖的package包/类
protected static AnnotationValue findAnnotationValue(AnnotationMirror mirror, String name) {
ExecutableElement valueMethod = null;
for (ExecutableElement method : ElementFilter.methodsIn(mirror.getAnnotationType().asElement().getEnclosedElements())) {
if (method.getSimpleName().toString().equals(name)) {
valueMethod = method;
break;
}
}
if (valueMethod == null) {
return null;
}
AnnotationValue value = mirror.getElementValues().get(valueMethod);
if (value == null) {
value = valueMethod.getDefaultValue();
}
return value;
}
示例3: getClassType
import javax.lang.model.element.AnnotationValue; //导入依赖的package包/类
/*************当注解的参数为Class类型时,如果使用的apt技术,直接去获取Class会报异常,因为,此时jvm还没有运行,Class尚未加载*****************/
public void getClassType(TypeElement type, DUnit dUnit) {
if (dUnit != null){
// mErrorReporter.reportWaring("asType:" + type.asType() + " |getNestingKind:" + type.getNestingKind() + " |getAnnotation:" + type.getAnnotation(DUnitGroup.class) + " |getAnnotationMirrors:" + type.getAnnotationMirrors());
List<? extends AnnotationMirror> mirrors = type.getAnnotationMirrors();
AnnotationMirror mirror = mirrors.get(0);
Map<? extends ExecutableElement, ? extends AnnotationValue> map = mirror.getElementValues();
Set<? extends Map.Entry<? extends ExecutableElement, ? extends AnnotationValue>> entries = map.entrySet();
for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry :
entries) {
ExecutableElement executableElement = entry.getKey();
mErrorReporter.reportWaring("executableElement" + executableElement);
AnnotationValue annotationValue = entry.getValue();
Object object = annotationValue.getValue();
// boolean isClassType = object instanceof Type.ClassType;
// if (isClassType){
// Type.ClassType classType = (Type.ClassType) object;
// mErrorReporter.reportWaring(classType.toString() + " | " + classType.getOriginalType() + " | " + classType.getKind() + " | " + classType.getReturnType() + " | " + classType.getUpperBound());
// }
}
}
}
示例4: getAnnotationValue
import javax.lang.model.element.AnnotationValue; //导入依赖的package包/类
private static AnnotationValue getAnnotationValue(AnnotationMirror mirror, String name) {
ExecutableElement valueMethod = null;
for (ExecutableElement method : ElementFilter.methodsIn(mirror.getAnnotationType().asElement().getEnclosedElements())) {
if (method.getSimpleName().toString().equals(name)) {
valueMethod = method;
break;
}
}
if (valueMethod == null) {
return null;
}
AnnotationValue value = mirror.getElementValues().get(valueMethod);
if (value == null) {
value = valueMethod.getDefaultValue();
}
return value;
}
示例5: resolveAnnotationValue
import javax.lang.model.element.AnnotationValue; //导入依赖的package包/类
@SuppressWarnings({"unchecked"})
private static <T> T resolveAnnotationValue(Class<T> expectedType, AnnotationValue value) {
if (value == null) {
return null;
}
Object unboxedValue = value.accept(new AnnotationValueVisitorImpl(), null);
if (unboxedValue != null) {
if (expectedType == TypeMirror.class && unboxedValue instanceof String) {
return null;
}
if (!expectedType.isAssignableFrom(unboxedValue.getClass())) {
throw new ClassCastException(unboxedValue.getClass().getName() + " not assignable from " + expectedType.getName());
}
}
return (T) unboxedValue;
}
示例6: findAnnotationValue
import javax.lang.model.element.AnnotationValue; //导入依赖的package包/类
@Nullable
private static AnnotationValue findAnnotationValue( @Nonnull final Elements elements,
@Nonnull final Element typeElement,
@Nonnull final String annotationClassName,
@Nonnull final String parameterName )
{
final AnnotationMirror mirror = getAnnotationByType( typeElement, annotationClassName );
final Map<? extends ExecutableElement, ? extends AnnotationValue> values =
elements.getElementValuesWithDefaults( mirror );
final ExecutableElement annotationKey = values.keySet().stream().
filter( k -> parameterName.equals( k.getSimpleName().toString() ) ).findFirst().orElse( null );
return values.get( annotationKey );
}
示例7: computeAnnotationTree
import javax.lang.model.element.AnnotationValue; //导入依赖的package包/类
private AnnotationTree computeAnnotationTree(AnnotationMirror am) {
List<ExpressionTree> params = new LinkedList<ExpressionTree>();
for (Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : am.getElementValues().entrySet()) {
ExpressionTree val = createTreeForAnnotationValue(make, entry.getValue());
if (val == null) {
LOG.log(Level.WARNING, "Cannot create annotation for: {0}", entry.getValue());
continue;
}
ExpressionTree vt = make.Assignment(make.Identifier(entry.getKey().getSimpleName()), val);
params.add(vt);
}
return make.Annotation(make.Type(am.getAnnotationType()), params);
}
示例8: writeAnnotations
import javax.lang.model.element.AnnotationValue; //导入依赖的package包/类
private void writeAnnotations(Iterable<? extends AnnotationMirror> annotations) throws IOException {
for (AnnotationMirror ann : annotations) {
out.write("@");
write(ann.getAnnotationType());
if (!ann.getElementValues().isEmpty()) {
out.write("(");
Map<ExecutableElement, AnnotationValue> valuesMap = new TreeMap<>((a1, a2) -> a1.getSimpleName().toString().compareTo(a2.getSimpleName().toString()));
valuesMap.putAll(ann.getElementValues());
for (Entry<? extends ExecutableElement, ? extends AnnotationValue> ev : valuesMap.entrySet()) {
out.write(ev.getKey().getSimpleName().toString());
out.write(" = ");
out.write(ev.getValue().toString());
}
out.write(")");
}
}
}
示例9: appendAnnotation
import javax.lang.model.element.AnnotationValue; //导入依赖的package包/类
private void appendAnnotation(StringBuilder sb, AnnotationMirror annotationDesc, boolean topLevel) {
DeclaredType annotationType = annotationDesc.getAnnotationType();
if (annotationType != null && (!topLevel || isDocumented(annotationType))) {
appendType(sb, annotationType, false, false, true);
Map<? extends ExecutableElement, ? extends AnnotationValue> values = annotationDesc.getElementValues();
if (!values.isEmpty()) {
sb.append('('); //NOI18N
for (Iterator<? extends Map.Entry<? extends ExecutableElement, ? extends AnnotationValue>> it = values.entrySet().iterator(); it.hasNext();) {
Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> value = it.next();
createLink(sb, value.getKey(), value.getKey().getSimpleName());
sb.append('='); //NOI18N
appendAnnotationValue(sb, value.getValue());
if (it.hasNext())
sb.append(","); //NOI18N
}
sb.append(')'); //NOI18N
}
if (topLevel)
sb.append("<br>"); //NOI18N
}
}
示例10: appendAnnotationValue
import javax.lang.model.element.AnnotationValue; //导入依赖的package包/类
private void appendAnnotationValue(StringBuilder sb, AnnotationValue av) {
Object value = av.getValue();
if (value instanceof List) {
List<? extends AnnotationValue> list = (List<? extends AnnotationValue>)value;
if (list.size() > 1)
sb.append('{'); //NOI18N
for (Iterator<? extends AnnotationValue> it = list.iterator(); it.hasNext();) {
AnnotationValue val = it.next();
appendAnnotationValue(sb, val);
if (it.hasNext())
sb.append(","); //NOI18N
}
if (list.size() > 1)
sb.append('}'); //NOI18N
} else if (value instanceof String) {
sb.append('"').append(value).append('"'); //NOI18N
} else if (value instanceof TypeMirror) {
appendType(sb, (TypeMirror)value, false, false, false);
} else if (value instanceof VariableElement) {
createLink(sb, (VariableElement)value, ((VariableElement)value).getSimpleName());
} else if (value instanceof AnnotationMirror) {
appendAnnotation(sb, (AnnotationMirror)value, false);
} else {
sb.append(value.toString());
}
}
示例11: convertExclusion
import javax.lang.model.element.AnnotationValue; //导入依赖的package包/类
List<Pattern> convertExclusion(AnnotationValue exclAnnotationValue, Element element) {
if (exclAnnotationValue == null) return null;
return new SimpleAnnotationValueVisitor8<List<Pattern>, Void>() {
@Override
public List<Pattern> visitArray(List<? extends AnnotationValue> vals, Void aVoid) {
return vals.stream()
.map(x -> {
String value = (String) x.getValue();
Optional<Pattern> result = compileToPattern(value);
if (!result.isPresent())
env.getMessager().printMessage(Diagnostic.Kind.ERROR, "param not valid. Expecting a regular Expression. Got:" + x, element);
return result;
})
.filter(Optional::isPresent)
.map(Optional::get)
.collect(Collectors.toList());
}
}.visit(exclAnnotationValue);
}
示例12: checkRunWithSuiteAnnotation
import javax.lang.model.element.AnnotationValue; //导入依赖的package包/类
/**
* Checks that the given annotation is of type
* <code>{@value #ANN_RUN_WITH}</code> and contains argument
* <code>{@value #ANN_SUITE}{@literal .class}</code>.
*
* @param annMirror annotation to be checked
* @return {@code true} if the annotation meets the described criteria,
* {@code false} otherwise
*/
private boolean checkRunWithSuiteAnnotation(AnnotationMirror annMirror,
WorkingCopy workingCopy) {
Map<? extends ExecutableElement,? extends AnnotationValue> annParams
= annMirror.getElementValues();
if (annParams.size() != 1) {
return false;
}
AnnotationValue annValue = annParams.values().iterator().next();
Name annValueClsName = getAnnotationValueClassName(annValue,
workingCopy.getTypes());
return annValueClsName != null
? annValueClsName.contentEquals(ANN_SUITE)
: false;
}
示例13: refresh
import javax.lang.model.element.AnnotationValue; //导入依赖的package包/类
boolean refresh(TypeElement typeElement) {
class2 = typeElement.getQualifiedName().toString();
AnnotationModelHelper helper = getHelper();
Map<String, ? extends AnnotationMirror> annByType = helper.getAnnotationsByType(typeElement.getAnnotationMirrors());
AnnotationMirror embeddableAnn = annByType.get("javax.persistence.MappedSuperclass"); // NOI18N
AnnotationMirror entityAcc = annByType.get("javax.persistence.Access"); // NOI18N
if (entityAcc != null) {
entityAcc.getElementValues();
AnnotationParser parser = AnnotationParser.create(helper);
parser.expect("value", new ValueProvider() {
@Override
public Object getValue(AnnotationValue elementValue) {
return elementValue.toString();
}
@Override
public Object getDefaultValue() {
return null;
}
});//NOI18N
ParseResult parseResult = parser.parse(entityAcc);
accessType = parseResult.get("value", String.class);
}
return embeddableAnn != null;
}
示例14: isDeprecatedForRemoval
import javax.lang.model.element.AnnotationValue; //导入依赖的package包/类
/**
* Return true if the given Element is deprecated for removal.
*
* @param e the Element to check.
* @return true if the given Element is deprecated for removal.
*/
public boolean isDeprecatedForRemoval(Element e) {
List<? extends AnnotationMirror> annotationList = e.getAnnotationMirrors();
JavacTypes jctypes = ((DocEnvImpl) configuration.docEnv).toolEnv.typeutils;
for (AnnotationMirror anno : annotationList) {
if (jctypes.isSameType(anno.getAnnotationType().asElement().asType(), getDeprecatedType())) {
Map<? extends ExecutableElement, ? extends AnnotationValue> pairs = anno.getElementValues();
if (!pairs.isEmpty()) {
for (ExecutableElement element : pairs.keySet()) {
if (element.getSimpleName().contentEquals("forRemoval")) {
return Boolean.parseBoolean((pairs.get(element)).toString());
}
}
}
}
}
return false;
}
示例15: getJoinColumns
import javax.lang.model.element.AnnotationValue; //导入依赖的package包/类
public static List<JoinColumn> getJoinColumns(final AnnotationModelHelper helper, Map<String, ? extends AnnotationMirror> annByType) {
final List<JoinColumn> result = new ArrayList<JoinColumn>();
AnnotationMirror joinColumnAnn = annByType.get("javax.persistence.JoinColumn"); // NOI18N
if (joinColumnAnn != null) {
result.add(new JoinColumnImpl(helper, joinColumnAnn));
} else {
AnnotationMirror joinColumnsAnnotation = annByType.get("javax.persistence.JoinColumns"); // NOI18N
if (joinColumnsAnnotation != null) {
AnnotationParser jcParser = AnnotationParser.create(helper);
jcParser.expectAnnotationArray("value", helper.resolveType("javax.persistence.JoinColumn"), new ArrayValueHandler() { // NOI18N
public Object handleArray(List<AnnotationValue> arrayMembers) {
for (AnnotationValue arrayMember : arrayMembers) {
AnnotationMirror joinColumnAnnotation = (AnnotationMirror)arrayMember.getValue();
result.add(new JoinColumnImpl(helper, joinColumnAnnotation));
}
return null;
}
}, null);
jcParser.parse(joinColumnsAnnotation);
}
}
return result;
}