Java Code Examples for javax.lang.model.element.AnnotationValue#getValue()
The following examples show how to use
javax.lang.model.element.AnnotationValue#getValue() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TypeConverterMetaData.java From picocli with Apache License 2.0 | 6 votes |
/** * Returns the type converters from the annotations present on the specified element. * @param element the method or field annotated with {@code @Option} or {@code @Parameters} * @return the type converters or an empty array if not found */ @SuppressWarnings("unchecked") public static TypeConverterMetaData[] extract(Element element) { List<? extends AnnotationMirror> annotationMirrors = element.getAnnotationMirrors(); for (AnnotationMirror mirror : annotationMirrors) { DeclaredType annotationType = mirror.getAnnotationType(); if (TypeUtil.isOption(annotationType) || TypeUtil.isParameter(annotationType)) { Map<? extends ExecutableElement, ? extends AnnotationValue> elementValues = mirror.getElementValues(); for (ExecutableElement attribute : elementValues.keySet()) { if ("converter".equals(attribute.getSimpleName().toString())) { AnnotationValue list = elementValues.get(attribute); List<AnnotationValue> typeMirrors = (List<AnnotationValue>) list.getValue(); List<TypeConverterMetaData> result = new ArrayList<TypeConverterMetaData>(); for (AnnotationValue annotationValue : typeMirrors) { result.add(new TypeConverterMetaData((TypeMirror) annotationValue.getValue())); } return result.toArray(new TypeConverterMetaData[0]); } } } } return new TypeConverterMetaData[0]; }
Example 2
Source File: AnnotationParser.java From data-mediator with Apache License 2.0 | 5 votes |
public Object getValue(AnnotationValue elementValue) { Object value = elementValue.getValue(); if (value instanceof List) { @SuppressWarnings("unchecked") // NOI18N List<AnnotationValue> arrayMembers = (List<AnnotationValue>)value; if (checkMembers(arrayMembers)) { Object result = handler.handleArray(arrayMembers); if (result != null) { return result; } } } return getDefaultValue(); }
Example 3
Source File: AnnotationParser.java From netbeans with Apache License 2.0 | 5 votes |
protected boolean checkMembers(List<AnnotationValue> arrayMembers) { for (AnnotationValue arrayMember : arrayMembers) { Object value = arrayMember.getValue(); if (!(value instanceof TypeMirror)) { return false; } TypeMirror type = (TypeMirror)value; if (!TypeKind.DECLARED.equals(type.getKind())) { return false; } } return true; }
Example 4
Source File: AnnotationParser.java From netbeans with Apache License 2.0 | 5 votes |
protected boolean checkMembers(List<AnnotationValue> arrayMembers) { for (AnnotationValue arrayMember : arrayMembers) { Object value = arrayMember.getValue(); if (!type.isInstance(value)) { return false; } } return true; }
Example 5
Source File: AnnotationParser.java From netbeans with Apache License 2.0 | 5 votes |
public Object getValue(AnnotationValue elementValue) { Object value = elementValue.getValue(); if (value instanceof VariableElement) { VariableElement field = (VariableElement)value; TypeMirror enumType = field.getEnclosingElement().asType(); if (isSameAsTypeToCheck(enumType)) { return field.getSimpleName().toString(); } } return getDefaultValue(); }
Example 6
Source File: StithBinderProcess.java From stitch with Apache License 2.0 | 5 votes |
public Object getAutoLink(TypeElement foo) { AnnotationMirror am = getAnnotationMirror(foo, Exported.class); if (am == null) { return null; } AnnotationValue av = getAnnotationValue(am, "value"); if (av == null) { return null; } else { return av.getValue(); } }
Example 7
Source File: Util.java From Moxy with MIT License | 5 votes |
public static TypeMirror getAnnotationValueAsTypeMirror(AnnotationMirror annotationMirror, String key) { AnnotationValue av = getAnnotationValue(annotationMirror, key); if (av != null) { return (TypeMirror) av.getValue(); } else { return null; } }
Example 8
Source File: ConfiguredObjectRegistrationGenerator.java From qpid-broker-j with Apache License 2.0 | 5 votes |
private void processAnnotatedElement(final Elements elementUtils, final TypeElement annotationElement, final Element e) { if (e.getKind().equals(ElementKind.INTERFACE) || e.getKind().equals(ElementKind.CLASS)) { PackageElement packageElement = elementUtils.getPackageOf(e); String packageName = packageElement.getQualifiedName().toString(); String className = e.getSimpleName().toString(); AnnotationMirror annotation = getAnnotation(e, annotationElement); AnnotationValue registerValue = getAnnotationValue(annotation, "register"); if(registerValue == null || (Boolean) registerValue.getValue() ) { AnnotationValue typeValue = getAnnotationValue(annotation, "type"); if (typeValue != null) { _typeMap.put(packageName + "." + className, (String) typeValue.getValue()); processingEnv.getMessager() .printMessage(Diagnostic.Kind.NOTE, "looking for " + packageName + "." + className); _categoryMap.put(packageName + "." + className, getCategory((TypeElement) e)); } Set<String> classNames = _managedObjectClasses.get(packageName); if (classNames == null) { classNames = new HashSet<>(); _managedObjectClasses.put(packageName, classNames); } classNames.add(className); } } }
Example 9
Source File: AnnotationParser.java From netbeans with Apache License 2.0 | 5 votes |
public Object getValue(AnnotationValue elementValue) { Object value = elementValue.getValue(); if (value instanceof List) { @SuppressWarnings("unchecked") // NOI18N List<AnnotationValue> arrayMembers = (List<AnnotationValue>)value; if (checkMembers(arrayMembers)) { Object result = handler.handleArray(arrayMembers); if (result != null) { return result; } } } return getDefaultValue(); }
Example 10
Source File: JUnit5TestGenerator.java From netbeans with Apache License 2.0 | 5 votes |
/** * Returns fully qualified class name of a class given to an annotation * as (the only) argument. * * @param annValue annotation value * @return fully qualified name of a class represented by the given * annotation value, or {@code null} if the annotation value * does not represent a class */ private Name getAnnotationValueClassName(AnnotationValue annValue, Types types) { Object value = annValue.getValue(); if (value instanceof TypeMirror) { TypeMirror typeMirror = (TypeMirror) value; Element typeElement = types.asElement(typeMirror); if (typeElement.getKind() == ElementKind.CLASS) { return ((TypeElement) typeElement).getQualifiedName(); } } return null; }
Example 11
Source File: ErrorLoggingProcessor.java From squidb with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") private void logErrors(Element element) { AnnotationValue errorsArrayValue = utils.getAnnotationValue(element, ModelGenErrors.class, "value"); List<? extends AnnotationValue> errorsList = (List<? extends AnnotationValue>) errorsArrayValue.getValue(); for (AnnotationValue error : errorsList) { logSingleError(error); } }
Example 12
Source File: AnnotationParser.java From netbeans with Apache License 2.0 | 5 votes |
public Object getValue(AnnotationValue elementValue) { Object value = elementValue.getValue(); if (value instanceof TypeMirror) { TypeMirror type = (TypeMirror)value; if (TypeKind.DECLARED.equals(type.getKind())) { return ((TypeElement)(((DeclaredType)value).asElement())).getQualifiedName().toString(); } } return getDefaultValue(); }
Example 13
Source File: SubcomponentExtractor.java From Auto-Dagger2 with MIT License | 5 votes |
private boolean validateAnnotationValue(AnnotationValue value, String member) { if (!(value.getValue() instanceof TypeMirror)) { errors.addInvalid("%s cannot reference generated class. Use the class that applies the @AutoComponent annotation", member); return false; } return true; }
Example 14
Source File: JUnit4TestGenerator.java From netbeans with Apache License 2.0 | 5 votes |
/** * Checks that the given annotation is of type * <code>{@value #ANN_SUITE}.{@value #ANN_SUITE_MEMBERS}</code> * and contains the given list of classes as (the only) argument, * in the same order. * * @param annMirror annotation to be checked * @param suiteMembers list of fully qualified class names denoting * content of the test suite * @return {@code true} if the annotation meets the described criteria, * {@code false} otherwise */ private boolean checkSuiteMembersAnnotation(AnnotationMirror annMirror, List<String> suiteMembers, WorkingCopy workingCopy) { Map<? extends ExecutableElement,? extends AnnotationValue> annParams = annMirror.getElementValues(); if (annParams.size() != 1) { return false; } AnnotationValue annValue = annParams.values().iterator().next(); Object value = annValue.getValue(); if (value instanceof java.util.List) { List<? extends AnnotationValue> items = (List<? extends AnnotationValue>) value; if (items.size() != suiteMembers.size()) { return false; } Types types = workingCopy.getTypes(); Iterator<String> suiteMembersIt = suiteMembers.iterator(); for (AnnotationValue item : items) { Name suiteMemberName = getAnnotationValueClassName(item, types); if (suiteMemberName == null) { return false; } if (!suiteMemberName.contentEquals(suiteMembersIt.next())) { return false; } } return true; } return false; }
Example 15
Source File: AnnotationParser.java From data-mediator with Apache License 2.0 | 5 votes |
public Object getValue(AnnotationValue elementValue) { Object value = elementValue.getValue(); if (value instanceof TypeMirror) { TypeMirror type = (TypeMirror)value; if (TypeKind.DECLARED.equals(type.getKind())) { return ((TypeElement)(((DeclaredType)value).asElement())).getQualifiedName().toString(); } } return getDefaultValue(); }
Example 16
Source File: BasicAnnoTests.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
/** Get the position value from an @Test annotation mirror. */ static int getPosn(AnnotationMirror test) { AnnotationValue v = getValue(test, "posn"); return (Integer) v.getValue(); }
Example 17
Source File: BasicAnnoTests.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
/** Get the annoType value from an @Test annotation mirror. */ static String getAnnoType(AnnotationMirror test) { AnnotationValue v = getValue(test, "annoType"); TypeMirror m = (TypeMirror) v.getValue(); return m.toString(); }
Example 18
Source File: BasicAnnoTests.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
/** Get the annoType value from an @Test annotation mirror. */ static String getAnnoType(AnnotationMirror test) { AnnotationValue v = getValue(test, "annoType"); TypeMirror m = (TypeMirror) v.getValue(); return m.toString(); }
Example 19
Source File: BasicAnnoTests.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
/** Get the annoType value from an @Test annotation mirror. */ static String getAnnoType(AnnotationMirror test) { AnnotationValue v = getValue(test, "annoType"); TypeMirror m = (TypeMirror) v.getValue(); return m.toString(); }
Example 20
Source File: BasicAnnoTests.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
/** Get the position value from an @Test annotation mirror. */ static int getPosn(AnnotationMirror test) { AnnotationValue v = getValue(test, "posn"); return (Integer) v.getValue(); }