private ImmutableSetMultimap<TypeElement, Element> getWellFormedElementsByAnnotationType(
      RoundEnvironment roundEnv) {
    ImmutableSet<ElementFactory> deferredEnclosingElementsCopy =
        ImmutableSet.copyOf(deferredEnclosingElements);
    deferredEnclosingElements.clear();

    ImmutableSetMultimap.Builder<TypeElement, Element> prevIllFormedElementsBuilder =
        ImmutableSetMultimap.builder();
    for (ElementFactory deferredElementFactory : deferredEnclosingElementsCopy) {
      Element deferredElement = deferredElementFactory.getElement(elementUtils);
      if (deferredElement != null) {
        findAnnotatedElements(
            deferredElement, getSupportedAnnotationTypeElements(), prevIllFormedElementsBuilder);
      } else {
        deferredEnclosingElements.add(deferredElementFactory);
      }
    }

    ImmutableSetMultimap<TypeElement, Element> prevIllFormedElements =
        prevIllFormedElementsBuilder.build();

    ImmutableSetMultimap.Builder<TypeElement, Element> wellFormedElementsBuilder =
        ImmutableSetMultimap.builder();

    // For optimization purposes, the ElementFactory instances for packages and types that have
    // already been verified to be well-formed are stored.
    Set<ElementFactory> wellFormedPackageOrTypeElements = new LinkedHashSet<>();

    /* Look at
     *   1. the previously ill-formed elements which have a present enclosing type (in case of
     *      Package element, the package itself), and
     *   2. the new elements from this round
     * and validate them.
     */
    for (TypeElement annotationType : getSupportedAnnotationTypeElements()) {
      Set<? extends Element> roundElements = roundEnv.getElementsAnnotatedWith(annotationType);

      for (Element element : Sets.union(roundElements, prevIllFormedElements.get(annotationType))) {
        // For every element that is not module/package, to be well-formed its
        // enclosing-type in its entirety should be well-formed. Since modules
        // don't get annotated (and not supported here) they can be ignored.
        Element enclosing = (element.getKind() == PACKAGE) ? element : getEnclosingType(element);
        ElementFactory enclosingFactory = ElementFactory.forAnnotatedElement(enclosing, messager);

        boolean isWellFormedElement =
            wellFormedPackageOrTypeElements.contains(enclosingFactory)
                || (!deferredEnclosingElements.contains(enclosingFactory)
                    && validateElement(enclosing));
        if (isWellFormedElement) {
          wellFormedElementsBuilder.put(annotationType, element);
          wellFormedPackageOrTypeElements.add(enclosingFactory);
        } else {
          deferredEnclosingElements.add(enclosingFactory);
        }
      }
    }

    return wellFormedElementsBuilder.build();
  }
Returns the superficially validated annotated elements of this round, including the validated
previously ill-formed elements. Also update {@link #deferredEnclosingElements}.

<p>Note that the elements deferred by processing steps are guaranteed to be well-formed;
therefore, they are ignored (not returned) here, and they will be considered directly in the
{@link #process(ImmutableSetMultimap)} method.
common/src/main/java/com/google/auto/common/BasicAnnotationProcessor.java