@Override public Map<? extends ExecutableElement, ? extends AnnotationValue> getElementValues() { Map<? extends ExecutableElement, ? extends AnnotationValue> vs = elementValues; if (vs == null) { vs = delegate.getElementValues(); elementValues = vs; } return vs; }
private static Map<String, Object> annotationKeyValues(AnnotationMirror mirror) { Map<String, Object> result = new LinkedHashMap<>(); for (ExecutableElement key : mirror.getElementValues().keySet()) { result.put(key.getSimpleName().toString(), mirror.getElementValues().get(key).getValue()); } return result; } }
private static AnnotationValue getAnnotationValue(AnnotationMirror annotationMirror, String key) { for (Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : annotationMirror .getElementValues().entrySet()) { if (entry.getKey().getSimpleName().toString().equals(key)) { return entry.getValue(); } } return null; }
private AnnotationValue getAnnotationValue(AnnotationMirror mirror, String key) { for (Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : mirror.getElementValues().entrySet()) { if (entry.getKey().getSimpleName().contentEquals(key)) { return entry.getValue(); } } return null; }
public static AnnotationValue getAnnotationTypeMirrorValue(AnnotationMirror annotationMirror, String key) { for (Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : annotationMirror.getElementValues().entrySet()) { if (entry.getKey().getSimpleName().contentEquals(key)) { return entry.getValue(); } } return null; }
public DeclaredType extractAnnotationClassParameter(Element element, String annotationName, String methodName) { AnnotationMirror annotationMirror = findAnnotationMirror(element, annotationName); Map<? extends ExecutableElement, ? extends AnnotationValue> elementValues = annotationMirror.getElementValues(); for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : elementValues.entrySet()) { /* * "methodName" is unset when the default value is used */ if (methodName.equals(entry.getKey().getSimpleName().toString())) { AnnotationValue annotationValue = entry.getValue(); return (DeclaredType) annotationValue.getValue(); } } return null; }
static Optional<AnnotationValue> findAnnotationValue(AnnotationMirror mirror, String name) { return mirror.getElementValues() == null ? Optional.empty() : mirror.getElementValues().entrySet().stream() .filter(entry -> entry.getKey().getSimpleName().contentEquals(name)) .map(entry -> (AnnotationValue)entry.getValue()).findFirst(); }
public static Object getAnnotationValue(AnnotationMirror annotationMirror, String parameterValue) { assert annotationMirror != null; assert parameterValue != null; Object returnValue = null; for ( Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : annotationMirror.getElementValues() .entrySet() ) { if ( parameterValue.equals( entry.getKey().getSimpleName().toString() ) ) { returnValue = entry.getValue().getValue(); break; } } return returnValue; }
private static void qualifierToString(AnnotationMirror qualifier, StringBuilder result) { // TODO: guarantee that element values are sorted by name (if there are multiple) result.append('@'); typeToString(qualifier.getAnnotationType(), result, '$'); result.append('('); for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : qualifier.getElementValues().entrySet()) { result.append(entry.getKey().getSimpleName()); result.append('='); result.append(entry.getValue().getValue()); } result.append(")/"); }
public static TypeMirror getAnnotationValueAsTypeMirror(AnnotationMirror mirror, String method) { for (Map.Entry<? extends ExecutableElement,? extends AnnotationValue> entry : mirror.getElementValues().entrySet()) { if (entry.getKey().getSimpleName().toString().equals(method)) { return (TypeMirror) entry.getValue().getValue(); } } return null; }
private List<TypeMirror> extractListenerTypeMirrors(Element activityElement) { List<? extends AnnotationMirror> annotationMirrors = activityElement.getAnnotationMirrors(); String annotationName = RoboGuice.class.getName(); for (AnnotationMirror annotationMirror : annotationMirrors) { if (annotationName.equals(annotationMirror.getAnnotationType().toString())) { for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : annotationMirror.getElementValues().entrySet()) { if ("value".equals(entry.getKey().getSimpleName().toString())) { AnnotationValue action = entry.getValue(); @SuppressWarnings("unchecked") List<AnnotationValue> elements = (List<AnnotationValue>) action.getValue(); List<TypeMirror> listenerTypeMirrors = new ArrayList<>(elements.size()); for (AnnotationValue annotationValue : elements) { listenerTypeMirrors.add((TypeMirror) annotationValue.getValue()); } return listenerTypeMirrors; } } } } return Collections.emptyList(); }
public List<DeclaredType> extractAnnotationClassArrayParameter(Element element, String annotationName, String methodName) { AnnotationMirror annotationMirror = findAnnotationMirror(element, annotationName); Map<? extends ExecutableElement, ? extends AnnotationValue> elementValues = annotationMirror.getElementValues(); for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : elementValues.entrySet()) { /* * "methodName" is unset when the default value is used */ if (methodName.equals(entry.getKey().getSimpleName().toString())) { AnnotationValue annotationValue = entry.getValue(); @SuppressWarnings("unchecked") List<AnnotationValue> annotationClassArray = (List<AnnotationValue>) annotationValue.getValue(); List<DeclaredType> result = new ArrayList<>(annotationClassArray.size()); for (AnnotationValue annotationClassValue : annotationClassArray) { result.add((DeclaredType) annotationClassValue.getValue()); } return result; } } return null; }
private AnnotationValue findAnnotationValue(AnnotationMirror annotation, String name) { for (Map.Entry<? extends ExecutableElement,? extends AnnotationValue> entry : annotation.getElementValues().entrySet()) { if (entry.getKey().getSimpleName().contentEquals(name)) { return entry.getValue(); } } return null; }
public static AnnotationSpec get(AnnotationMirror annotation) { TypeElement element = (TypeElement) annotation.getAnnotationType().asElement(); AnnotationSpec.Builder builder = AnnotationSpec.builder(ClassName.get(element)); Visitor visitor = new Visitor(builder); for (ExecutableElement executableElement : annotation.getElementValues().keySet()) { String name = executableElement.getSimpleName().toString(); AnnotationValue value = annotation.getElementValues().get(executableElement); value.accept(visitor, name); } return builder.build(); }
@SuppressWarnings("unchecked") public static Set<TypeElement> getAnnotationValuesAsElements(AnnotationMirror mirror, String method) { Set<TypeElement> elements = new HashSet<TypeElement>(); for (Map.Entry<? extends ExecutableElement,? extends AnnotationValue> entry : mirror.getElementValues().entrySet()) { if (entry.getKey().getSimpleName().toString().equals(method)) { List<AnnotationValue> values = ((List) entry.getValue().getValue()); for (AnnotationValue value : values) { DeclaredType type = (DeclaredType) value.getValue(); elements.add((TypeElement) type.asElement()); } } } return elements; }
annotationMirror.getElementValues().entrySet();
public void copyAnnotation(IJAnnotatable annotatable, AnnotationMirror annotationMirror) { Map<? extends ExecutableElement, ? extends AnnotationValue> parameters = annotationMirror.getElementValues(); if (!hasAnnotation(annotatable, annotationMirror) || annotatable instanceof JAnnotationArrayMember) { AbstractJClass annotation = typeMirrorToJClass(annotationMirror.getAnnotationType()); JAnnotationUse annotate = annotatable.annotate(annotation); for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> param : parameters.entrySet()) { param.getValue().accept(new AnnotationParamExtractor(annotate, this), param.getKey().getSimpleName().toString()); } } }
private void handleBaseBuilder() { if (!MoreTypes.isTypeOf(Object.class, baseBuilder.asType())) { final List<ExecutableElement> constructors = ElementFilter.constructorsIn(baseBuilder.getEnclosedElements()); Optional<ExecutableElement> constructor = constructors.stream().filter(c -> c.getParameters().size() == 0).findAny(); if (constructor.isPresent()) { elements.add(modelFactory.fromDelegateConstructor(constructor.get(), false)); } else { constructor = constructors.stream().filter(c -> c.getParameters().size() == 1 && Types.CONTEXT.equals(TypeName.get(c.getParameters().get(0).asType()))).findAny(); if (constructor.isPresent()) { elements.add(modelFactory.fromDelegateConstructor(constructor.get(), true)); } else { final AnnotationMirror mirror = baseAnnotation.getAnnotationMirrors().stream() .filter(m -> MoreTypes.isTypeOf(Configuration.class, m.getAnnotationType())) .findAny().orElseThrow(IllegalArgumentException::new); messager.printMessage(Diagnostic.Kind.ERROR, "Classes used as base builder must have a constructor which takes no arguments, " + "or exactly one argument of type Class", baseAnnotation, mirror, mirror.getElementValues().entrySet().stream() .filter(entry -> entry.getKey().getSimpleName().toString().equals("builderSuperClass")).findAny().map(Map.Entry::getValue).orElse(null)); throw new IllegalArgumentException(); } } handleBaseBuilderMethods(); } }
private static List<AnnotationSpec> getExternalAnnotations(VariableElement param) { final List<? extends AnnotationMirror> annotationMirrors = param.getAnnotationMirrors(); final List<AnnotationSpec> annotations = new ArrayList<>(); for (AnnotationMirror annotationMirror : annotationMirrors) { if (annotationMirror.getAnnotationType().toString().startsWith(COMPONENTS_PACKAGE)) { continue; } final AnnotationSpec.Builder annotationSpec = AnnotationSpec.builder( ClassName.bestGuess(annotationMirror.getAnnotationType().toString())); Map<? extends ExecutableElement, ? extends AnnotationValue> elementValues = annotationMirror.getElementValues(); for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> elementValue : elementValues.entrySet()) { annotationSpec.addMember( elementValue.getKey().getSimpleName().toString(), elementValue.getValue().toString()); } annotations.add(annotationSpec.build()); } return annotations; }
static ImmutableValueImmutableInfo infoFrom(ImmutableMirror input) { return ImmutableValueImmutableInfo.theOf( input.builder(), input.copy(), input.intern(), input.prehash(), input.singleton()) .withIsDefault(input.getAnnotationMirror().getElementValues().isEmpty()); } }