Version 2.14.0-142.0.dev

Merge commit 'f56f9e8f3401fead5f41613d331c1f833314e383' into 'dev'
diff --git a/pkg/analysis_server/lib/src/services/correction/dart/convert_into_is_not.dart b/pkg/analysis_server/lib/src/services/correction/dart/convert_into_is_not.dart
index b81db26..4381b83 100644
--- a/pkg/analysis_server/lib/src/services/correction/dart/convert_into_is_not.dart
+++ b/pkg/analysis_server/lib/src/services/correction/dart/convert_into_is_not.dart
@@ -4,12 +4,14 @@
 
 import 'package:analysis_server/src/services/correction/assist.dart';
 import 'package:analysis_server/src/services/correction/dart/abstract_producer.dart';
+import 'package:analysis_server/src/services/correction/fix.dart';
 import 'package:analysis_server/src/services/correction/util.dart';
 import 'package:analyzer/dart/ast/ast.dart';
 import 'package:analyzer/dart/ast/precedence.dart';
 import 'package:analyzer/dart/ast/token.dart';
 import 'package:analyzer_plugin/utilities/assist/assist.dart';
 import 'package:analyzer_plugin/utilities/change_builder/change_builder_core.dart';
+import 'package:analyzer_plugin/utilities/fixes/fixes.dart';
 import 'package:analyzer_plugin/utilities/range_factory.dart';
 
 class ConvertIntoIsNot extends CorrectionProducer {
@@ -17,6 +19,12 @@
   AssistKind get assistKind => DartAssistKind.CONVERT_INTO_IS_NOT;
 
   @override
+  FixKind get fixKind => DartFixKind.CONVERT_TO_IS_NOT;
+
+  @override
+  FixKind get multiFixKind => DartFixKind.CONVERT_TO_IS_NOT_MULTI;
+
+  @override
   Future<void> compute(ChangeBuilder builder) async {
     // Find the is expression
     var isExpression = node.thisOrAncestorOfType<IsExpression>();
diff --git a/pkg/analysis_server/lib/src/services/correction/fix.dart b/pkg/analysis_server/lib/src/services/correction/fix.dart
index 365dc29..661861a 100644
--- a/pkg/analysis_server/lib/src/services/correction/fix.dart
+++ b/pkg/analysis_server/lib/src/services/correction/fix.dart
@@ -311,6 +311,10 @@
       'dart.fix.convert.toIntLiteral.multi',
       DartFixKindPriority.IN_FILE,
       'Convert to int literals everywhere in file');
+  static const CONVERT_TO_IS_NOT = FixKind(
+      'dart.fix.convert.isNot', DartFixKindPriority.DEFAULT, 'Convert to is!');
+  static const CONVERT_TO_IS_NOT_MULTI = FixKind('dart.fix.convert.isNot.multi',
+      DartFixKindPriority.IN_FILE, 'Convert to is! everywhere in file');
   static const CONVERT_TO_LINE_COMMENT = FixKind(
       'dart.fix.convert.toLineComment',
       DartFixKindPriority.DEFAULT,
diff --git a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
index 2ff9ef9..6359410 100644
--- a/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
+++ b/pkg/analysis_server/lib/src/services/correction/fix_internal.dart
@@ -805,11 +805,9 @@
         ],
       )
     ],
-    // todo (pq): note this is not in lintProducerMap
     LintNames.prefer_is_not_operator: [
       FixInfo(
-        // todo (pq): consider enabling
-        canBeAppliedToFile: false,
+        canBeAppliedToFile: true,
         canBeBulkApplied: true,
         generators: [
           ConvertIntoIsNot.newInstance,
diff --git a/pkg/analysis_server/test/src/services/correction/fix/fix_processor_map_test.dart b/pkg/analysis_server/test/src/services/correction/fix/fix_processor_map_test.dart
new file mode 100644
index 0000000..3f86540
--- /dev/null
+++ b/pkg/analysis_server/test/src/services/correction/fix/fix_processor_map_test.dart
@@ -0,0 +1,44 @@
+// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'package:analysis_server/src/services/correction/fix_internal.dart';
+import 'package:test/test.dart';
+import 'package:test_reflective_loader/test_reflective_loader.dart';
+
+void main() {
+  defineReflectiveSuite(() {
+    defineReflectiveTests(FixProcessorMapTest);
+  });
+}
+
+@reflectiveTest
+class FixProcessorMapTest {
+  void test_lintProducerMap() {
+    _testMap(FixProcessor.lintProducerMap.values);
+  }
+
+  void test_nonLintProducerMap() {
+    _testMap(FixProcessor.nonLintProducerMap.values);
+  }
+
+  void _testInfo(FixInfo info) {
+    for (var generator in info.generators) {
+      var producer = generator();
+      var className = producer.runtimeType.toString();
+      expect(producer.fixKind, isNotNull, reason: '$className.fixKind');
+      if (info.canBeAppliedToFile) {
+        expect(producer.multiFixKind, isNotNull,
+            reason: '$className.multiFixKind');
+      }
+    }
+  }
+
+  void _testMap(Iterable<List<FixInfo>> values) {
+    for (var list in values) {
+      for (var info in list) {
+        _testInfo(info);
+      }
+    }
+  }
+}
diff --git a/pkg/analysis_server/test/src/services/correction/fix/test_all.dart b/pkg/analysis_server/test/src/services/correction/fix/test_all.dart
index e520510..acc1caf 100644
--- a/pkg/analysis_server/test/src/services/correction/fix/test_all.dart
+++ b/pkg/analysis_server/test/src/services/correction/fix/test_all.dart
@@ -83,6 +83,7 @@
 import 'data_driven/test_all.dart' as data_driven;
 import 'extend_class_for_mixin_test.dart' as extend_class_for_mixin;
 import 'fix_in_file_test.dart' as fix_in_file;
+import 'fix_processor_map_test.dart' as fix_processor_map;
 import 'fix_test.dart' as fix;
 import 'import_async_test.dart' as import_async;
 import 'import_library_prefix_test.dart' as import_library_prefix;
@@ -250,6 +251,7 @@
     extend_class_for_mixin.main();
     fix.main();
     fix_in_file.main();
+    fix_processor_map.main();
     import_async.main();
     import_library_prefix.main();
     import_library_project.main();
diff --git a/pkg/analyzer/lib/src/dart/element/element.dart b/pkg/analyzer/lib/src/dart/element/element.dart
index e31e14d..3fd6aab 100644
--- a/pkg/analyzer/lib/src/dart/element/element.dart
+++ b/pkg/analyzer/lib/src/dart/element/element.dart
@@ -16,7 +16,6 @@
 import 'package:analyzer/error/error.dart';
 import 'package:analyzer/src/dart/analysis/experiments.dart';
 import 'package:analyzer/src/dart/analysis/session.dart';
-import 'package:analyzer/src/dart/ast/ast.dart';
 import 'package:analyzer/src/dart/ast/ast_factory.dart';
 import 'package:analyzer/src/dart/ast/token.dart';
 import 'package:analyzer/src/dart/constant/compute.dart';
@@ -44,7 +43,6 @@
 import 'package:analyzer/src/generated/utilities_general.dart';
 import 'package:analyzer/src/summary2/ast_binary_tokens.dart';
 import 'package:analyzer/src/summary2/bundle_reader.dart';
-import 'package:analyzer/src/summary2/linked_unit_context.dart';
 import 'package:analyzer/src/summary2/reference.dart';
 import 'package:analyzer/src/task/inference_error.dart';
 
@@ -68,15 +66,6 @@
   /// given [offset] in the file that contains the declaration of this element.
   AbstractClassElementImpl(String name, int offset) : super(name, offset);
 
-  AbstractClassElementImpl.forLinkedNode(
-      ElementImpl enclosing, Reference reference, AstNode linkedNode)
-      : super.forLinkedNode(enclosing, reference, linkedNode);
-
-  /// Initialize using the given serialized information.
-  AbstractClassElementImpl.forSerialized(
-      CompilationUnitElementImpl enclosingUnit)
-      : super.forSerialized(enclosingUnit);
-
   /// Set the accessors contained in this class to the given [accessors].
   set accessors(List<PropertyAccessorElement> accessors) {
     assert(!isMixinApplication);
@@ -929,9 +918,6 @@
 /// A concrete implementation of a [CompilationUnitElement].
 class CompilationUnitElementImpl extends UriReferencedElementImpl
     implements CompilationUnitElement {
-  @override
-  final LinkedUnitContext? linkedContext;
-
   /// The source that corresponds to this compilation unit.
   @override
   late Source source;
@@ -985,16 +971,7 @@
 
   /// Initialize a newly created compilation unit element to have the given
   /// [name].
-  CompilationUnitElementImpl()
-      : linkedContext = null,
-        super(null, -1);
-
-  CompilationUnitElementImpl.forLinkedNode(LibraryElementImpl enclosingLibrary,
-      this.linkedContext, Reference reference, CompilationUnitImpl? linkedNode)
-      : super.forLinkedNode(enclosingLibrary, reference, linkedNode) {
-    _nameOffset = -1;
-    linkedNode?.declaredElement = this;
-  }
+  CompilationUnitElementImpl() : super(null, -1);
 
   @override
   List<PropertyAccessorElement> get accessors {
@@ -1089,14 +1066,6 @@
   String get identifier => '${source.uri}';
 
   @override
-  bool get isSynthetic {
-    if (linkedContext != null) {
-      return linkedContext!.isSynthetic;
-    }
-    return super.isSynthetic;
-  }
-
-  @override
   ElementKind get kind => ElementKind.COMPILATION_UNIT;
 
   @override
@@ -1600,24 +1569,10 @@
   /// initializers.  However, analyzer also needs to handle incorrect Dart code,
   /// in which case there might be some constant variables that lack
   /// initializers.
-  Expression? _constantInitializer;
+  Expression? constantInitializer;
 
   EvaluationResultImpl? _evaluationResult;
 
-  Expression? get constantInitializer {
-    if (_constantInitializer != null) return _constantInitializer!;
-
-    if (linkedNode != null) {
-      return _constantInitializer = linkedContext!.getInitializer(linkedNode!);
-    }
-
-    return _constantInitializer;
-  }
-
-  set constantInitializer(Expression? constantInitializer) {
-    _constantInitializer = constantInitializer;
-  }
-
   EvaluationResultImpl? get evaluationResult => _evaluationResult;
 
   set evaluationResult(EvaluationResultImpl? evaluationResult) {
@@ -1993,7 +1948,6 @@
   ElementImpl? _enclosingElement;
 
   Reference? reference;
-  final AstNode? linkedNode;
 
   /// The name of this element.
   String? _name;
@@ -2006,7 +1960,7 @@
   int _modifiers = 0;
 
   /// A list containing all of the metadata associated with this element.
-  List<ElementAnnotation> _metadata = _Sentinel.elementAnnotation;
+  List<ElementAnnotation> _metadata = const [];
 
   /// A cached copy of the calculated hashCode for this element.
   int? _cachedHashCode;
@@ -2029,23 +1983,11 @@
 
   /// Initialize a newly created element to have the given [name] at the given
   /// [_nameOffset].
-  ElementImpl(String? name, this._nameOffset, {this.reference})
-      : linkedNode = null {
+  ElementImpl(String? name, this._nameOffset, {this.reference}) {
     _name = name != null ? StringUtilities.intern(name) : null;
     reference?.element = this;
   }
 
-  /// Initialize from linked node.
-  ElementImpl.forLinkedNode(
-      this._enclosingElement, this.reference, this.linkedNode) {
-    reference?.element ??= this;
-  }
-
-  /// Initialize from serialized information.
-  ElementImpl.forSerialized(this._enclosingElement)
-      : reference = null,
-        linkedNode = null;
-
   /// The length of the element's code, or `null` if the element is synthetic.
   int? get codeLength => _codeLength;
 
@@ -2343,9 +2285,6 @@
 
   @override
   bool get isSynthetic {
-    if (linkedNode != null) {
-      return linkedNode!.isSynthetic;
-    }
     return hasModifier(Modifier.SYNTHETIC);
   }
 
@@ -2360,10 +2299,6 @@
   @override
   Source? get librarySource => library?.source;
 
-  LinkedUnitContext? get linkedContext {
-    return (enclosingElement as ElementImpl).linkedContext;
-  }
-
   @override
   ElementLocation get location {
     return _cachedLocation ??= ElementLocationImpl.con1(this);
@@ -2371,15 +2306,6 @@
 
   @override
   List<ElementAnnotation> get metadata {
-    if (!identical(_metadata, _Sentinel.elementAnnotation)) {
-      return _metadata;
-    }
-
-    if (linkedNode != null) {
-      var metadata = linkedContext!.getMetadata(linkedNode!);
-      return _metadata = _buildAnnotations2(enclosingUnit, metadata);
-    }
-
     return _metadata;
   }
 
@@ -2532,24 +2458,6 @@
   void visitChildren(ElementVisitor visitor) {
     // There are no children to visit
   }
-
-  /// Return annotations for the given [nodeList] in the [unit].
-  List<ElementAnnotation> _buildAnnotations2(
-      CompilationUnitElementImpl unit, List<Annotation> nodeList) {
-    var length = nodeList.length;
-    if (length == 0) {
-      return const <ElementAnnotation>[];
-    }
-
-    var annotations = <ElementAnnotation>[];
-    for (int i = 0; i < length; i++) {
-      var ast = nodeList[i];
-      annotations.add(ElementAnnotationImpl(unit)
-        ..annotationAst = ast
-        ..element = ast.element);
-    }
-    return annotations;
-  }
 }
 
 /// Abstract base class for elements whose type is guaranteed to be a function
@@ -3643,10 +3551,6 @@
   @override
   late TypeSystemImpl typeSystem;
 
-  /// The context of the defining unit.
-  @override
-  final LinkedUnitContext? linkedContext;
-
   LibraryElementLinkedData? linkedData;
 
   @override
@@ -3697,26 +3601,9 @@
   /// the given [name] and [offset].
   LibraryElementImpl(this.context, this.session, String name, int offset,
       this.nameLength, this.featureSet)
-      : linkedContext = null,
-        linkedData = null,
+      : linkedData = null,
         super(name, offset);
 
-  LibraryElementImpl.forLinkedNode(
-    this.context,
-    this.session,
-    String name,
-    int offset,
-    this.nameLength,
-    this.linkedContext,
-    Reference reference,
-    CompilationUnit? linkedNode,
-    FeatureSet featureSet,
-  )   : featureSet = featureSet,
-        super.forLinkedNode(null, reference, linkedNode) {
-    _name = name;
-    _nameOffset = offset;
-  }
-
   @override
   CompilationUnitElement get definingCompilationUnit =>
       _definingCompilationUnit;
@@ -3737,17 +3624,6 @@
   @override
   FunctionElement? get entryPoint {
     linkedData?.read(this);
-    if (_entryPoint != null) return _entryPoint!;
-
-    if (linkedContext != null) {
-      var namespace = library.exportNamespace;
-      var entryPoint = namespace.get(FunctionElement.MAIN_FUNCTION_NAME);
-      if (entryPoint is FunctionElement) {
-        return _entryPoint = entryPoint;
-      }
-      return null;
-    }
-
     return _entryPoint;
   }
 
@@ -3777,11 +3653,6 @@
       return _exportNamespace = elements.buildExportNamespace(source.uri);
     }
 
-    if (linkedNode != null) {
-      var elements = linkedContext!.elementFactory;
-      return _exportNamespace = elements.buildExportNamespace(source.uri);
-    }
-
     return _exportNamespace!;
   }
 
@@ -3792,18 +3663,6 @@
   @override
   List<ExportElement> get exports {
     linkedData?.read(this);
-    if (!identical(_exports, _Sentinel.exportElement)) {
-      return _exports;
-    }
-
-    if (linkedNode != null) {
-      var unit = linkedContext!.unit;
-      return _exports = unit.directives
-          .whereType<ExportDirective>()
-          .map((node) => node.element!)
-          .toList();
-    }
-
     return _exports;
   }
 
@@ -3822,22 +3681,6 @@
 
   @override
   bool get hasExtUri {
-    if (linkedNode != null) {
-      var unit = linkedContext!.unit;
-      for (var import in unit.directives) {
-        if (import is ImportDirective) {
-          var uriLiteral = import.uri;
-          if (uriLiteral is SimpleStringLiteral) {
-            var uriStr = uriLiteral.value;
-            if (DartUriResolver.isDartExtUri(uriStr)) {
-              return true;
-            }
-          }
-        }
-      }
-      return false;
-    }
-
     return hasModifier(Modifier.HAS_EXT_URI);
   }
 
@@ -3883,31 +3726,6 @@
   @override
   List<ImportElement> get imports {
     linkedData?.read(this);
-    if (!identical(_imports, _Sentinel.importElement)) {
-      return _imports;
-    }
-
-    if (linkedNode != null) {
-      var unit = linkedContext!.unit;
-      _imports = unit.directives
-          .whereType<ImportDirective>()
-          .map((node) => node.element!)
-          .toList();
-      var hasCore = _imports.any((import) {
-        return import.importedLibrary?.isDartCore ?? false;
-      });
-      if (!hasCore) {
-        var elements = linkedContext!.elementFactory;
-        _imports.add(
-          ImportElementImpl(-1)
-            ..importedLibrary = elements.libraryOfUri2('dart:core')
-            ..isSynthetic = true
-            ..uri = 'dart:core',
-        );
-      }
-      return _imports;
-    }
-
     return _imports;
   }
 
@@ -3980,31 +3798,14 @@
   }
 
   @override
-  bool get isSynthetic {
-    if (linkedNode != null) {
-      return linkedContext!.isSynthetic;
-    }
-    return super.isSynthetic;
-  }
-
-  @override
   ElementKind get kind => ElementKind.LIBRARY;
 
   @override
   LibraryLanguageVersion get languageVersion {
-    if (_languageVersion != null) return _languageVersion!;
-
-    if (linkedNode != null) {
-      _languageVersion =
-          linkedContext!.getLanguageVersion(linkedNode as CompilationUnit);
-      return _languageVersion!;
-    }
-
-    _languageVersion = LibraryLanguageVersion(
+    return _languageVersion ??= LibraryLanguageVersion(
       package: ExperimentStatus.currentVersion,
       override: null,
     );
-    return _languageVersion!;
   }
 
   set languageVersion(LibraryLanguageVersion languageVersion) {
@@ -4022,15 +3823,6 @@
   @override
   List<ElementAnnotation> get metadata {
     linkedData?.read(this);
-    if (!identical(_metadata, _Sentinel.elementAnnotation)) {
-      return _metadata;
-    }
-
-    if (linkedNode != null) {
-      var metadata = linkedContext!.getLibraryMetadata();
-      return _metadata = _buildAnnotations2(_definingCompilationUnit, metadata);
-    }
-
     return super.metadata;
   }
 
@@ -4061,11 +3853,6 @@
           NamespaceBuilder().createPublicNamespaceForLibrary(this);
     }
 
-    if (linkedNode != null) {
-      return _publicNamespace =
-          NamespaceBuilder().createPublicNamespaceForLibrary(this);
-    }
-
     return _publicNamespace!;
   }
 
@@ -5184,22 +4971,13 @@
 
   @override
   FunctionType get typeInternal {
-    if (_type != null) return _type!;
-
-    var type = FunctionTypeImpl(
+    return _type ??= FunctionTypeImpl(
       typeFormals: const <TypeParameterElement>[],
       parameters: const <ParameterElement>[],
       returnType: returnType,
       nullabilitySuffix: _noneOrStarSuffix,
       element: this,
     );
-
-    // Don't cache, because types change during top-level inference.
-    if (linkedContext != null && !linkedContext!.isLinking) {
-      _type = type;
-    }
-
-    return type;
   }
 }
 
@@ -5257,22 +5035,13 @@
 
   @override
   FunctionType get typeInternal {
-    if (_type != null) return _type!;
-
-    var type = FunctionTypeImpl(
+    return _type ??= FunctionTypeImpl(
       typeFormals: const <TypeParameterElement>[],
       parameters: parameters,
       returnType: returnType,
       nullabilitySuffix: _noneOrStarSuffix,
       element: this,
     );
-
-    // Don't cache, because types change during top-level inference.
-    if (linkedContext != null && !linkedContext!.isLinking) {
-      _type = type;
-    }
-
-    return type;
   }
 }
 
@@ -5321,6 +5090,23 @@
   DartType get type => ElementTypeProvider.current.getFieldType(this);
 
   @override
+  set type(DartType type) {
+    super.type = type;
+    // Reset cached types of synthetic getters and setters.
+    // TODO(scheglov) Consider not caching these types.
+    if (!isSynthetic) {
+      var getter = this.getter;
+      if (getter is PropertyAccessorElementImpl_ImplicitGetter) {
+        getter._type = null;
+      }
+      var setter = this.setter;
+      if (setter is PropertyAccessorElementImpl_ImplicitSetter) {
+        setter._type = null;
+      }
+    }
+  }
+
+  @override
   DartType get typeInternal {
     linkedData?.read(this);
     if (_type != null) return _type!;
@@ -5734,14 +5520,6 @@
   /// [offset]. The offset may be `-1` if the element is synthetic.
   UriReferencedElementImpl(String? name, int offset) : super(name, offset);
 
-  UriReferencedElementImpl.forLinkedNode(
-      ElementImpl enclosing, Reference? reference, AstNode? linkedNode)
-      : super.forLinkedNode(enclosing, reference, linkedNode);
-
-  /// Initialize using the given serialized information.
-  UriReferencedElementImpl.forSerialized(ElementImpl enclosingElement)
-      : super.forSerialized(enclosingElement);
-
   /// Return the URI that is specified by this directive.
   @override
   String? get uri => _uri;
@@ -5827,9 +5605,6 @@
 
   @override
   bool get isConst {
-    if (linkedNode != null) {
-      return enclosingUnit.linkedContext!.isConst(linkedNode!);
-    }
     return hasModifier(Modifier.CONST);
   }
 
@@ -5848,9 +5623,6 @@
 
   @override
   bool get isFinal {
-    if (linkedNode != null) {
-      return enclosingUnit.linkedContext!.isFinal(linkedNode!);
-    }
     return hasModifier(Modifier.FINAL);
   }
 
@@ -5895,14 +5667,6 @@
 abstract class _ExistingElementImpl extends ElementImpl with _HasLibraryMixin {
   _ExistingElementImpl(String? name, int offset, {Reference? reference})
       : super(name, offset, reference: reference);
-
-  _ExistingElementImpl.forLinkedNode(
-      ElementImpl? enclosingElement, Reference? reference, AstNode? linkedNode)
-      : super.forLinkedNode(enclosingElement, reference, linkedNode);
-
-  /// Initialize using the given serialized information.
-  _ExistingElementImpl.forSerialized(ElementImpl enclosingUnit)
-      : super.forSerialized(enclosingUnit);
 }
 
 mixin _HasLibraryMixin on ElementImpl {
@@ -5921,8 +5685,6 @@
 class _Sentinel {
   static final List<ConstructorElement> constructorElement =
       List.unmodifiable([]);
-  static final List<ElementAnnotation> elementAnnotation =
-      List.unmodifiable([]);
   static final List<ExportElement> exportElement = List.unmodifiable([]);
   static final List<FieldElement> fieldElement = List.unmodifiable([]);
   @Deprecated('Use TypeAliasElement instead')
diff --git a/pkg/analyzer/lib/src/summary2/element_builder.dart b/pkg/analyzer/lib/src/summary2/element_builder.dart
index cdfde28..e9a453d 100644
--- a/pkg/analyzer/lib/src/summary2/element_builder.dart
+++ b/pkg/analyzer/lib/src/summary2/element_builder.dart
@@ -9,10 +9,12 @@
 import 'package:analyzer/src/dart/ast/ast.dart';
 import 'package:analyzer/src/dart/element/element.dart';
 import 'package:analyzer/src/dart/element/type.dart';
+import 'package:analyzer/src/generated/source.dart';
 import 'package:analyzer/src/generated/utilities_dart.dart';
 import 'package:analyzer/src/summary2/library_builder.dart';
 import 'package:analyzer/src/summary2/link.dart';
 import 'package:analyzer/src/summary2/reference.dart';
+import 'package:collection/collection.dart';
 
 class ElementBuilder extends ThrowingAstVisitor<void> {
   final LibraryBuilder _libraryBuilder;
@@ -21,6 +23,8 @@
   final _exports = <ExportElement>[];
   final _imports = <ImportElement>[];
   var _hasCoreImport = false;
+  var _hasExtUri = false;
+  var _partDirectiveIndex = 0;
 
   _EnclosingContext _enclosingContext;
   var _nextUnnamedExtensionId = 0;
@@ -57,9 +61,10 @@
     _unitElement.types = _enclosingContext.classes;
   }
 
-  /// This method should be invoked after visiting directive nodes, it
-  /// will set created exports and imports into [_libraryElement].
-  void setExportsImports() {
+  /// Build exports and imports, metadata into [_libraryElement].
+  void buildLibraryElementChildren(CompilationUnit unit) {
+    unit.directives.accept(this);
+
     _libraryElement.exports = _exports;
 
     if (!_hasCoreImport) {
@@ -72,6 +77,12 @@
       );
     }
     _libraryElement.imports = _imports;
+    _libraryElement.hasExtUri = _hasExtUri;
+
+    var firstDirective = unit.directives.firstOrNull;
+    if (firstDirective != null) {
+      _libraryElement.metadata = _buildAnnotations(firstDirective.metadata);
+    }
   }
 
   @override
@@ -559,12 +570,14 @@
 
   @override
   void visitImportDirective(covariant ImportDirectiveImpl node) {
+    var uriStr = node.uri.stringValue;
+
     var element = ImportElementImpl(node.keyword.offset);
     element.combinators = _buildCombinators(node.combinators);
     element.importedLibrary = _selectLibrary(node);
     element.isDeferred = node.deferredKeyword != null;
     element.metadata = _buildAnnotations(node.metadata);
-    element.uri = node.uri.stringValue;
+    element.uri = uriStr;
 
     var prefixNode = node.prefix;
     if (prefixNode != null) {
@@ -580,10 +593,11 @@
     node.element = element;
 
     _imports.add(element);
-    if (!_hasCoreImport) {
-      if (node.uri.stringValue == 'dart:core') {
-        _hasCoreImport = true;
-      }
+
+    if (uriStr == 'dart:core') {
+      _hasCoreImport = true;
+    } else if (DartUriResolver.isDartExtUri(uriStr)) {
+      _hasExtUri = true;
     }
   }
 
@@ -689,7 +703,15 @@
   }
 
   @override
-  void visitPartDirective(PartDirective node) {}
+  void visitPartDirective(PartDirective node) {
+    var index = _partDirectiveIndex++;
+    // TODO(scheglov) With invalid URIs we will associate metadata incorrectly
+    if (index < _libraryElement.parts.length) {
+      var partElement = _libraryElement.parts[index];
+      partElement as CompilationUnitElementImpl;
+      partElement.metadata = _buildAnnotations(node.metadata);
+    }
+  }
 
   @override
   void visitPartOfDirective(PartOfDirective node) {
diff --git a/pkg/analyzer/lib/src/summary2/library_builder.dart b/pkg/analyzer/lib/src/summary2/library_builder.dart
index 318f25f..b4e210f 100644
--- a/pkg/analyzer/lib/src/summary2/library_builder.dart
+++ b/pkg/analyzer/lib/src/summary2/library_builder.dart
@@ -9,6 +9,7 @@
 import 'package:analyzer/src/dart/ast/mixin_super_invoked_names.dart';
 import 'package:analyzer/src/dart/element/element.dart';
 import 'package:analyzer/src/dart/element/scope.dart';
+import 'package:analyzer/src/dart/resolver/scope.dart';
 import 'package:analyzer/src/summary2/combinator.dart';
 import 'package:analyzer/src/summary2/constructor_initializer_resolver.dart';
 import 'package:analyzer/src/summary2/default_value_resolver.dart';
@@ -142,8 +143,7 @@
         unitElement: unitContext.element,
       );
       if (unitContext.indexInLibrary == 0) {
-        unitContext.unit.directives.accept(elementBuilder);
-        elementBuilder.setExportsImports();
+        elementBuilder.buildLibraryElementChildren(unitContext.unit);
       }
       elementBuilder.buildDeclarationElements(unitContext.unit);
     }
@@ -190,10 +190,11 @@
   }
 
   void resolveMetadata() {
-    for (var unit in element.units) {
-      var unitImpl = unit as CompilationUnitElementImpl;
-      var resolver = MetadataResolver(linker, scope, unit);
-      unitImpl.linkedNode!.accept(resolver);
+    for (var unitContext in context.units) {
+      var unitElement =
+          unitContext.reference.element as CompilationUnitElementImpl;
+      var resolver = MetadataResolver(linker, scope, unitElement);
+      unitContext.unit.accept(resolver);
     }
   }
 
@@ -216,13 +217,22 @@
 
   void storeExportScope() {
     exports = exportScope.map.values.toList();
-    linker.elementFactory.linkingExports['$uri'] = exports;
 
-    // TODO(scheglov) store for serialization
-    // for (var reference in exportScope.map.values) {
-    //   var index = linkingBundleContext.indexOfReference(reference);
-    //   context.exports.add(index);
-    // }
+    var definedNames = <String, Element>{};
+    for (var entry in exportScope.map.entries) {
+      var element = linker.elementFactory.elementOfReference(entry.value);
+      if (element != null) {
+        definedNames[entry.key] = element;
+      }
+    }
+
+    var namespace = Namespace(definedNames);
+    element.exportNamespace = namespace;
+
+    var entryPoint = namespace.get(FunctionElement.MAIN_FUNCTION_NAME);
+    if (entryPoint is FunctionElement) {
+      element.entryPoint = entryPoint;
+    }
   }
 
   static void build(Linker linker, LinkInputLibrary inputLibrary) {
@@ -245,7 +255,7 @@
           uriStr,
           reference,
           inputUnit.isSynthetic,
-          unit: inputUnit.unit,
+          unit: inputUnit.unit as ast.CompilationUnitImpl,
         ),
       );
     }
diff --git a/pkg/analyzer/lib/src/summary2/link.dart b/pkg/analyzer/lib/src/summary2/link.dart
index 65975220..a6ee88f 100644
--- a/pkg/analyzer/lib/src/summary2/link.dart
+++ b/pkg/analyzer/lib/src/summary2/link.dart
@@ -67,8 +67,7 @@
   /// If the [element] is part of a library being linked, return the node
   /// from which it was created.
   ast.AstNode? getLinkingNode(Element element) {
-    var node = elementNodes[element];
-    return node ?? (element as ElementImpl).linkedNode;
+    return elementNodes[element];
   }
 
   void link(List<LinkInputLibrary> inputLibraries) {
diff --git a/pkg/analyzer/lib/src/summary2/linked_element_factory.dart b/pkg/analyzer/lib/src/summary2/linked_element_factory.dart
index edf31e0..fcd971f 100644
--- a/pkg/analyzer/lib/src/summary2/linked_element_factory.dart
+++ b/pkg/analyzer/lib/src/summary2/linked_element_factory.dart
@@ -6,7 +6,6 @@
 import 'package:analyzer/dart/element/element.dart';
 import 'package:analyzer/src/context/context.dart';
 import 'package:analyzer/src/dart/analysis/session.dart';
-import 'package:analyzer/src/dart/ast/ast.dart';
 import 'package:analyzer/src/dart/element/element.dart';
 import 'package:analyzer/src/dart/element/type_provider.dart';
 import 'package:analyzer/src/dart/resolver/scope.dart';
@@ -18,7 +17,6 @@
   final AnalysisContextImpl analysisContext;
   final AnalysisSessionImpl analysisSession;
   final Reference rootReference;
-  final Map<String, List<Reference>> linkingExports = {};
   final Map<String, LibraryReader> libraryReaders = {};
 
   bool isApplyingInformativeData = false;
@@ -80,7 +78,7 @@
     // The URI cannot be resolved, we don't know the library.
     if (librarySource == null) return null;
 
-    var definingUnitContext = libraryContext.units[0];
+    var definingUnitContext = libraryContext.definingUnit;
     var definingUnitNode = definingUnitContext.unit;
 
     // TODO(scheglov) Do we need this?
@@ -96,44 +94,39 @@
       }
     }
 
-    var libraryElement = LibraryElementImpl.forLinkedNode(
+    var libraryElement = LibraryElementImpl(
       analysisContext,
       analysisSession,
       name,
       nameOffset,
       nameLength,
-      definingUnitContext,
-      libraryContext.reference,
-      definingUnitNode,
       definingUnitNode.featureSet,
     );
+    libraryElement.isSynthetic = definingUnitContext.isSynthetic;
+    libraryElement.languageVersion = definingUnitNode.languageVersion!;
+    _bindReference(libraryContext.reference, libraryElement);
     _setLibraryTypeSystem(libraryElement);
 
     var units = <CompilationUnitElementImpl>[];
-    var unitContainerRef = libraryContext.reference.getChild('@unit');
     for (var unitContext in libraryContext.units) {
-      var unitNode = unitContext.unit as CompilationUnitImpl;
+      var unitNode = unitContext.unit;
 
       var unitSource = sourceFactory.forUri(unitContext.uriStr);
       if (unitSource == null) continue;
 
-      var unitElement = CompilationUnitElementImpl.forLinkedNode(
-        libraryElement,
-        unitContext,
-        unitContext.reference,
-        unitNode,
-      );
+      var unitElement = CompilationUnitElementImpl();
+      unitElement.isSynthetic = unitContext.isSynthetic;
+      unitElement.librarySource = librarySource;
       unitElement.lineInfo = unitNode.lineInfo;
       unitElement.source = unitSource;
-      unitElement.librarySource = librarySource;
       unitElement.uri = unitContext.partUriStr;
+      _bindReference(unitContext.reference, unitElement);
+
       units.add(unitElement);
-      unitContainerRef.getChild(unitContext.uriStr).element = unitElement;
     }
 
     libraryElement.definingCompilationUnit = units[0];
     libraryElement.parts = units.skip(1).toList();
-    libraryContext.reference.element = libraryElement;
 
     return libraryElement;
   }
@@ -222,11 +215,6 @@
   }
 
   List<Reference> exportsOfLibrary(String uriStr) {
-    var linkingExportedReferences = linkingExports[uriStr];
-    if (linkingExportedReferences != null) {
-      return linkingExportedReferences;
-    }
-
     var library = libraryReaders[uriStr];
     if (library == null) return const [];
 
@@ -281,7 +269,6 @@
   void removeLibraries(Set<String> uriStrSet) {
     for (var uriStr in uriStrSet) {
       libraryReaders.remove(uriStr);
-      linkingExports.remove(uriStr);
       rootReference.removeChild(uriStr);
     }
 
@@ -314,4 +301,9 @@
 
     libraryElement.createLoadLibraryFunction();
   }
+
+  static void _bindReference(Reference reference, ElementImpl element) {
+    reference.element = element;
+    element.reference = reference;
+  }
 }
diff --git a/pkg/analyzer/lib/src/summary2/linked_unit_context.dart b/pkg/analyzer/lib/src/summary2/linked_unit_context.dart
index 99a7f3b..fc490d7 100644
--- a/pkg/analyzer/lib/src/summary2/linked_unit_context.dart
+++ b/pkg/analyzer/lib/src/summary2/linked_unit_context.dart
@@ -21,7 +21,7 @@
   final String uriStr;
   final Reference reference;
   final bool isSynthetic;
-  final CompilationUnit unit;
+  final CompilationUnitImpl unit;
 
   LinkedUnitContext(this.libraryContext, this.indexInLibrary, this.partUriStr,
       this.uriStr, this.reference, this.isSynthetic,
diff --git a/tools/VERSION b/tools/VERSION
index c0a8ee3..ea67459 100644
--- a/tools/VERSION
+++ b/tools/VERSION
@@ -27,5 +27,5 @@
 MAJOR 2
 MINOR 14
 PATCH 0
-PRERELEASE 141
+PRERELEASE 142
 PRERELEASE_PATCH 0
\ No newline at end of file