anchor.diff:   * This class must not assume that the [CompilationUnitElement] passed to it is
    * any more complete than a [COMPILATION_UNIT_ELEMENT].
    */
  -class DeclarationResolver extends RecursiveAstVisitor<Object>
  -    with _ExistingElementResolver {
  -  /**
  -   * The elements that are reachable from the compilation unit element. When a
  -   * compilation unit has been resolved, this set should be empty.
  -   */
  -  Set<Element> _expectedElements;
  -
  -  /**
  -   * The function type alias containing the AST nodes being visited, or `null`
  -   * if we are not in the scope of a function type alias.
  -   */
  -  FunctionTypeAliasElement _enclosingAlias;
  -
  -  /**
  -   * The class containing the AST nodes being visited, or `null` if we are not
  -   * in the scope of a class.
  -   */
  -  ClassElement _enclosingClass;
  -
  -  /**
  -   * The method or function containing the AST nodes being visited, or `null` if
  -   * we are not in the scope of a method or function.
  -   */
  -  ExecutableElement _enclosingExecutable;
  -
  -  /**
  -   * The parameter containing the AST nodes being visited, or `null` if we are
  -   * not in the scope of a parameter.
  -   */
  -  ParameterElement _enclosingParameter;
  +class DeclarationResolver extends RecursiveAstVisitor<Object> {
  +  /**
  +   * The compilation unit containing the AST nodes being visited.
  +   */
  +  CompilationUnitElementImpl _enclosingUnit;
  +
  +  /**
  +   * The [ElementWalker] we are using to keep track of progress through the
  +   * element model.
  +   */
  +  ElementWalker _walker;
   
     /**
      * Resolve the declarations within the given compilation [unit] to the
  
positive.code: 
    @override
    Object visitTypeParameter(TypeParameter node) {
      SimpleIdentifier parameterName = node.name;
      Element element = null;
      if (_enclosingExecutable != null) {
        element = _findIdentifier(
            _enclosingExecutable.typeParameters, parameterName,
            required: false);
      }
      if (element == null) {
        if (_enclosingClass != null) {
          element =
              _findIdentifier(_enclosingClass.typeParameters, parameterName);
        } else if (_enclosingAlias != null) {
          element =
              _findIdentifier(_enclosingAlias.typeParameters, parameterName);
        }
      }
      if (element == null) {
        String name = parameterName.name;
        int offset = parameterName.offset;
        _mismatch(
            'Could not find type parameter with name "$name" at $offset', node);
      }
      super.visitTypeParameter(node);
      _resolveMetadata(node, node.metadata, element);
      return null;
  
negative.code:   }
  
    /**
     * Recurses through the element model and AST, verifying that all elements are
     * matched.
     *
     * Executes [callback] with [_walker] pointing to the given [walker] (which
     * should be a new instance of [ElementWalker]).  Once [callback] returns,
     * uses [ElementWalker.validate] to verify that all expected elements have
     * been matched.
     */
    void _walk(ElementWalker walker, void callback()) {
      ElementWalker outerWalker = _walker;
      _walker = walker;
      callback();
      walker.validate();
      _walker = outerWalker;
    }
  }
  
  /**
   * Keeps track of the set of non-synthetic child elements of an element,
   * yielding them one at a time in response to "get" method calls.
   */
  class ElementWalker {
    /**
     * The element whose child elements are being walked.
     */
    final Element element;
  
    List<PropertyAccessorElement> _accessors;
    int _accessorIndex = 0;
    List<ClassElement> _classes;
    int _classIndex = 0;
    List<ConstructorElement> _constructors;
    int _constructorIndex = 0;
    List<ClassElement> _enums;
    int _enumIndex = 0;
    List<ExecutableElement> _functions;
    int _functionIndex = 0;
    List<LabelElement> _labels;
    int _labelIndex = 0;
    List<ParameterElement> _parameters;
    int _parameterIndex = 0;
    List<FunctionTypeAliasElement> _typedefs;
    int _typedefIndex = 0;
    List<TypeParameterElement> _typeParameters;
    int _typeParameterIndex = 0;
    List<VariableElement> _variables;
    int _variableIndex = 0;
  
    /**
     * Creates an [ElementWalker] which walks the child elements of a class
     * element.
     */
    ElementWalker.forClass(ClassElement element)
        : element = element,
          _accessors = element.accessors.where(_isNotSynthetic).toList(),
          _constructors = element.isMixinApplication
              ? null
              : element.constructors.where(_isNotSynthetic).toList(),
          _functions = element.methods,
          _typeParameters = element.typeParameters,
          _variables = element.fields.where(_isNotSynthetic).toList();
  
    /**
     * Creates an [ElementWalker] which walks the child elements of a compilation
     * unit element.
     */
    ElementWalker.forCompilationUnit(CompilationUnitElement compilationUnit)
        : element = compilationUnit,
          _accessors = compilationUnit.accessors.where(_isNotSynthetic).toList(),
          _classes = compilationUnit.types,
          _enums = compilationUnit.enums,
          _functions = compilationUnit.functions,
          _typedefs = compilationUnit.functionTypeAliases,
          _variables =
              compilationUnit.topLevelVariables.where(_isNotSynthetic).toList();
  
    /**
     * Creates an [ElementWalker] which walks the child elements of a compilation
     * unit element.
     */
    ElementWalker.forExecutable(ExecutableElement element)
        : element = element,
          _functions = element.functions,
          _labels = element.labels,
          _parameters = element.parameters,
          _typeParameters = element.typeParameters,
          _variables = element.localVariables;
  
    /**
     * Creates an [ElementWalker] which walks the child elements of a parameter
     * element.
     */
    ElementWalker.forParameter(ParameterElement element)
        : element = element,
          _parameters = element.parameters;
  
    /**
     * Creates an [ElementWalker] which walks the child elements of a typedef
     * element.
     */
    ElementWalker.forTypedef(FunctionTypeAliasElement element)
        : element = element,
          _parameters = element.parameters,
          _typeParameters = element.typeParameters;
  
    /**
     * Returns the next non-synthetic child of [element] which is an accessor;
     * throws an [IndexError] if there are no more.
     */
    PropertyAccessorElement getAccessor() => _accessors[_accessorIndex++];
  
    /**
     * Returns the next non-synthetic child of [element] which is a class; throws
     * an [IndexError] if there are no more.
     */
    ClassElement getClass() => _classes[_classIndex++];
  
    /**
     * Returns the next non-synthetic child of [element] which is a constructor;
     * throws an [IndexError] if there are no more.
     */
    ConstructorElement getConstructor() => _constructors[_constructorIndex++];
  
    /**
     * Returns the next non-synthetic child of [element] which is an enum; throws
     * an [IndexError] if there are no more.
     */
    ClassElement getEnum() => _enums[_enumIndex++];
  
    /**
     * Returns the next non-synthetic child of [element] which is a top level
     * function, method, or local function; throws an [IndexError] if there are no
     * more.
     */
    ExecutableElement getFunction() => _functions[_functionIndex++];
  
    /**
     * Returns the next non-synthetic child of [element] which is a label; throws
     * an [IndexError] if there are no more.
     */
    LabelElement getLabel() => _labels[_labelIndex++];
  
    /**
     * Returns the next non-synthetic child of [element] which is a parameter;
     * throws an [IndexError] if there are no more.
     */
    ParameterElement getParameter() => _parameters[_parameterIndex++];
  
    /**
     * Returns the next non-synthetic child of [element] which is a typedef;
     * throws an [IndexError] if there are no more.
     */
    FunctionTypeAliasElement getTypedef() => _typedefs[_typedefIndex++];
  
    /**
     * Returns the next non-synthetic child of [element] which is a type
     * parameter; throws an [IndexError] if there are no more.
     */
    TypeParameterElement getTypeParameter() =>
        _typeParameters[_typeParameterIndex++];
  
    /**
     * Returns the next non-synthetic child of [element] which is a top level
     * variable, field, or local variable; throws an [IndexError] if there are no
     * more.
     */
    VariableElement getVariable() => _variables[_variableIndex++];
  
    /**
     * Verifies that all non-synthetic children of [element] have been obtained
     * from their corresponding "get" method calls; if not, throws a [StateError].
     */
    void validate() {
      void check(List<Element> elements, int index) {
        if (elements != null && elements.length != index) {
          throw new StateError(
              'Unmatched ${elements[index].runtimeType} ${elements[index]}');
        }
      }
  
      check(_accessors, _accessorIndex);
      check(_classes, _classIndex);
      check(_constructors, _constructorIndex);
      check(_enums, _enumIndex);
      check(_functions, _functionIndex);
      check(_labels, _labelIndex);
      check(_parameters, _parameterIndex);
      check(_typedefs, _typedefIndex);
      check(_typeParameters, _typeParameterIndex);
      check(_variables, _variableIndex);
    }
  
    static bool _isNotSynthetic(Element e) => !e.isSynthetic;
  }
  
  class _ElementMismatchException extends AnalysisException {
    /**
     * Creates an exception to refer to the given [compilationUnit], [element],
     * and [cause].
     */
    _ElementMismatchException(
        CompilationUnitElement compilationUnit, Element element,
        [CaughtException cause = null])
        : super('Element mismatch in $compilationUnit at $element', cause);
  }
  