@Override public TypeElement apply(TypeMirror klass) { return MoreTypes.asTypeElement(klass); } }).toList();
/** * Returns the value named {@code name} from {@code annotationMirror}. * * @throws IllegalArgumentException unless that member represents a single type */ static Iterable<TypeMirror> getTypeValue(AnnotationMirror annotationMirror, String name) { return FluentIterable.from(asAnnotationValues(getAnnotationValue(annotationMirror, name))) .transform(new Function<AnnotationValue, TypeMirror>() { @Nullable @Override public TypeMirror apply(@Nullable AnnotationValue annotationValue) { return asType(annotationValue); } }).toList(); } }
private void findAndParseListener(RoundEnvironment env, Class<? extends Annotation> annotationClass, Map<TypeElement, BindingSet.Builder> builderMap, Set<TypeElement> erasedTargetNames) { for (Element element : env.getElementsAnnotatedWith(annotationClass)) { if (!SuperficialValidation.validateElement(element)) continue; try { parseListenerAnnotation(annotationClass, element, builderMap, erasedTargetNames); } catch (Exception e) { StringWriter stackTrace = new StringWriter(); e.printStackTrace(new PrintWriter(stackTrace)); error(element, "Unable to generate view binder for @%s.\n\n%s", annotationClass.getSimpleName(), stackTrace.toString()); } } }
roundEnv.getElementsAnnotatedWith(MoreElements.asType(customAnnotation))); DEEP_LINK_CLASS.getSimpleName()); ExecutableElement executableElement = MoreElements.asExecutable(element); TypeElement returnType = MoreTypes.asTypeElement(executableElement.getReturnType()); String qualifiedName = returnType.getQualifiedName().toString(); if (!qualifiedName.equals("android.content.Intent") for (Element deepLinkHandlerElement : deepLinkHandlerElements) { Optional<AnnotationMirror> annotationMirror = getAnnotationMirror(deepLinkHandlerElement, DeepLinkHandler.class); if (annotationMirror.isPresent()) { Iterable<TypeMirror> klasses = getTypeValue(annotationMirror.get(), "value");
private static boolean hasAnyOfAnnotation(ExecutableElement input, List<String> annotations) { return input.getAnnotationMirrors().stream() .map(annotationMirror -> asType(annotationMirror.getAnnotationType().asElement())) .anyMatch(type -> typeInAnnotations(type, annotations)); }
static Builder newBuilder(TypeElement enclosingElement) { TypeMirror typeMirror = enclosingElement.asType(); boolean isView = isSubtypeOfType(typeMirror, VIEW_TYPE); boolean isActivity = isSubtypeOfType(typeMirror, ACTIVITY_TYPE); boolean isDialog = isSubtypeOfType(typeMirror, DIALOG_TYPE); TypeName targetType = TypeName.get(typeMirror); if (targetType instanceof ParameterizedTypeName) { targetType = ((ParameterizedTypeName) targetType).rawType; } String packageName = getPackage(enclosingElement).getQualifiedName().toString(); String className = enclosingElement.getQualifiedName().toString().substring( packageName.length() + 1).replace('.', '$'); ClassName bindingClassName = ClassName.get(packageName, className + "_ViewBinding"); boolean isFinal = enclosingElement.getModifiers().contains(Modifier.FINAL); return new Builder(targetType, bindingClassName, isFinal, isView, isActivity, isDialog); }
private static List<String> enumerateCustomDeepLinks(Element element, Map<Element, String[]> prefixesMap) { Set<? extends AnnotationMirror> annotationMirrors = AnnotationMirrors.getAnnotatedAnnotations(element, DEEP_LINK_SPEC_CLASS); final List<String> deepLinks = new ArrayList<>(); for (AnnotationMirror customAnnotation : annotationMirrors) { List<? extends AnnotationValue> suffixes = asAnnotationValues(AnnotationMirrors.getAnnotationValue(customAnnotation, "value")); String[] prefixes = prefixesMap.get(customAnnotation.getAnnotationType().asElement()); for (String prefix : prefixes) { for (AnnotationValue suffix : suffixes) { deepLinks.add(prefix + suffix.getValue()); } } } return deepLinks; }
private void handleAnnotationMethods() { for (ExecutableElement method : ElementFilter.methodsIn(baseAnnotation.getEnclosedElements())) { elements.add(MoreElements.isAnnotationPresent(method, StringRes.class) ? modelFactory.fromStringResourceAnnotationMethod(method) : modelFactory.fromAnnotationMethod(method)); } }
private AutoValueExtension.Context createContext(TypeElement type) { String packageName = MoreElements.getPackage(type).getQualifiedName().toString(); Set<ExecutableElement> allMethods = MoreElements.getLocalAndInheritedMethods(type, elements); Set<ExecutableElement> methods = methodsToImplement(type, allMethods); Map<String, ExecutableElement> properties = new LinkedHashMap<String, ExecutableElement>(); for (ExecutableElement e : methods) { properties.put(e.getSimpleName().toString(), e); } return new TestContext(processingEnvironment, packageName, type, properties); }
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 int hashList(List<? extends TypeMirror> mirrors, Set<Element> visiting) { int result = HASH_SEED; for (TypeMirror mirror : mirrors) { result *= HASH_MULTIPLIER; result += hash(mirror, visiting); } return result; }
@Override public ElementName apply(Element element) { return ElementName.forAnnotatedElement(element); } }));
/** * An object representing an {@linkplain ElementKind#ANNOTATION_TYPE annotation} instance. If * {@code annotationType} has any annotation members, they must either be present in {@code * namedValues} or have default values. */ public static AnnotationMirror of( TypeElement annotationType, Map<String, ? extends AnnotationValue> namedValues) { return new SimpleAnnotationMirror(annotationType, namedValues); }
@Override public boolean process(@Nullable Set<? extends TypeElement> annotations, @NonNull RoundEnvironment roundEnv) { try { final ArrayList<? extends Element> annotatedElements = new ArrayList<>(roundEnv.getElementsAnnotatedWith(Configuration.class)); if (!annotatedElements.isEmpty()) { for (final Element e : annotatedElements) { if (e.getKind() == ElementKind.ANNOTATION_TYPE) { new ClassCreator(MoreElements.asType(e), e.getAnnotation(Configuration.class), processingEnv).createClasses(); } else { processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, String.format("%s is only supported on %s", Configuration.class.getName(), ElementKind.ANNOTATION_TYPE.name()), e); } } } } catch (Exception e) { e.printStackTrace(); processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Failed to generate acra classes"); } return true; }
ProvidersClass from(Element element) throws ValidationException { if (!SuperficialValidation.validateElement(element)) return null; if (element.getKind() != ElementKind.INTERFACE) return null; ClassName className = ClassName.get((TypeElement) element); List<ProvidersClass.Method> methods = getMethods(element); return new ProvidersClass(className, element, methods); }
.build(); String packageName = MoreElements.getPackage(type).getQualifiedName().toString(); String className = String.format("%sAdapter", type.getSimpleName()); TypeSpec adapterClass = TypeSpec.classBuilder(className)
public void createClasses() throws IOException { TypeElement baseBuilder; try { baseBuilder = processingEnv.getElementUtils().getTypeElement(configuration.baseBuilderClass().getName()); } catch (MirroredTypeException e) { baseBuilder = MoreTypes.asTypeElement(e.getTypeMirror()); } final List<Element> elements = new ModelBuilder(baseAnnotation, new ElementFactory(processingEnv.getElementUtils()), baseBuilder, processingEnv.getMessager()).build(); createBuilderClass(elements); createConfigClass(elements); if (configuration.isPlugin()) { createBuilderInterface(elements); createFactoryClass(); } }
if (!SuperficialValidation.validateElement(element)) continue; try { parseResourceAnimation(element, builderMap, erasedTargetNames); if (!SuperficialValidation.validateElement(element)) continue; try { parseResourceArray(element, builderMap, erasedTargetNames); if (!SuperficialValidation.validateElement(element)) continue; try { parseResourceBitmap(element, builderMap, erasedTargetNames); if (!SuperficialValidation.validateElement(element)) continue; try { parseResourceBool(element, builderMap, erasedTargetNames); if (!SuperficialValidation.validateElement(element)) continue; try { parseResourceColor(element, builderMap, erasedTargetNames); if (!SuperficialValidation.validateElement(element)) continue; try { parseResourceDimen(element, builderMap, erasedTargetNames); if (!SuperficialValidation.validateElement(element)) continue; try { parseResourceDrawable(element, builderMap, erasedTargetNames); if (!SuperficialValidation.validateElement(element)) continue;
String packageName = MoreElements.getPackage(type).getQualifiedName().toString(); executeName = StringUtils.capitalize(executeName); String className = String.format("%s%sHandler%s", type.getSimpleName(), executeName, "");