Prefer hasLibraryDirective over hasPartOfDirective.

R=brianwilkerson@google.com

Change-Id: Ic411bd057ef1befd1aecd1f05a485430ec16b89d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/101467
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
diff --git a/pkg/analyzer/lib/src/dart/analysis/file_state.dart b/pkg/analyzer/lib/src/dart/analysis/file_state.dart
index 8cbbf7d..b10801a 100644
--- a/pkg/analyzer/lib/src/dart/analysis/file_state.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/file_state.dart
@@ -246,7 +246,7 @@
       return !_fsState.externalSummaries.linkedMap.containsKey(uriStr);
     }
     if (_unlinked2 != null) {
-      return _unlinked2.isPartOf;
+      return !_unlinked2.hasLibraryDirective && _unlinked2.hasPartOfDirective;
     }
     return _unlinked.libraryNameOffset == 0 && _unlinked.isPartOf;
   }
@@ -861,7 +861,8 @@
     var exports = <String>[];
     var imports = <String>['dart:core'];
     var parts = <String>[];
-    var isPartOf = false;
+    var hasLibraryDirective = false;
+    var hasPartOfDirective = false;
     for (var directive in unit.directives) {
       if (directive is ExportDirective) {
         var uriStr = directive.uri.stringValue;
@@ -869,11 +870,13 @@
       } else if (directive is ImportDirective) {
         var uriStr = directive.uri.stringValue;
         imports.add(uriStr ?? '');
+      } else if (directive is LibraryDirective) {
+        hasLibraryDirective = true;
       } else if (directive is PartDirective) {
         var uriStr = directive.uri.stringValue;
         parts.add(uriStr ?? '');
       } else if (directive is PartOfDirective) {
-        isPartOf = true;
+        hasPartOfDirective = true;
       }
     }
     return UnlinkedUnit2Builder(
@@ -881,7 +884,8 @@
       exports: exports,
       imports: imports,
       parts: parts,
-      isPartOf: isPartOf,
+      hasLibraryDirective: hasLibraryDirective,
+      hasPartOfDirective: hasPartOfDirective,
       lineStarts: unit.lineInfo.lineStarts,
     );
   }
diff --git a/pkg/analyzer/lib/src/summary/format.dart b/pkg/analyzer/lib/src/summary/format.dart
index c0551e8..d655c4c 100644
--- a/pkg/analyzer/lib/src/summary/format.dart
+++ b/pkg/analyzer/lib/src/summary/format.dart
@@ -29274,8 +29274,9 @@
     implements idl.UnlinkedUnit2 {
   List<int> _apiSignature;
   List<String> _exports;
+  bool _hasLibraryDirective;
+  bool _hasPartOfDirective;
   List<String> _imports;
-  bool _isPartOf;
   List<int> _lineStarts;
   List<String> _parts;
 
@@ -29298,6 +29299,22 @@
   }
 
   @override
+  bool get hasLibraryDirective => _hasLibraryDirective ??= false;
+
+  /// Is `true` if the unit contains a `library` directive.
+  set hasLibraryDirective(bool value) {
+    this._hasLibraryDirective = value;
+  }
+
+  @override
+  bool get hasPartOfDirective => _hasPartOfDirective ??= false;
+
+  /// Is `true` if the unit contains a `part of` directive.
+  set hasPartOfDirective(bool value) {
+    this._hasPartOfDirective = value;
+  }
+
+  @override
   List<String> get imports => _imports ??= <String>[];
 
   /// URIs of `import` directives.
@@ -29306,14 +29323,6 @@
   }
 
   @override
-  bool get isPartOf => _isPartOf ??= false;
-
-  /// Is `true` if the unit contains a `part of` directive.
-  set isPartOf(bool value) {
-    this._isPartOf = value;
-  }
-
-  @override
   List<int> get lineStarts => _lineStarts ??= <int>[];
 
   /// Offsets of the first character of each line in the source code.
@@ -29333,14 +29342,16 @@
   UnlinkedUnit2Builder(
       {List<int> apiSignature,
       List<String> exports,
+      bool hasLibraryDirective,
+      bool hasPartOfDirective,
       List<String> imports,
-      bool isPartOf,
       List<int> lineStarts,
       List<String> parts})
       : _apiSignature = apiSignature,
         _exports = exports,
+        _hasLibraryDirective = hasLibraryDirective,
+        _hasPartOfDirective = hasPartOfDirective,
         _imports = imports,
-        _isPartOf = isPartOf,
         _lineStarts = lineStarts,
         _parts = parts;
 
@@ -29375,7 +29386,7 @@
         signature.addString(x);
       }
     }
-    signature.addBool(this._isPartOf == true);
+    signature.addBool(this._hasPartOfDirective == true);
     if (this._parts == null) {
       signature.addInt(0);
     } else {
@@ -29384,6 +29395,7 @@
         signature.addString(x);
       }
     }
+    signature.addBool(this._hasLibraryDirective == true);
   }
 
   List<int> toBuffer() {
@@ -29422,12 +29434,15 @@
     if (offset_exports != null) {
       fbBuilder.addOffset(1, offset_exports);
     }
+    if (_hasLibraryDirective == true) {
+      fbBuilder.addBool(6, true);
+    }
+    if (_hasPartOfDirective == true) {
+      fbBuilder.addBool(3, true);
+    }
     if (offset_imports != null) {
       fbBuilder.addOffset(2, offset_imports);
     }
-    if (_isPartOf == true) {
-      fbBuilder.addBool(3, true);
-    }
     if (offset_lineStarts != null) {
       fbBuilder.addOffset(5, offset_lineStarts);
     }
@@ -29461,8 +29476,9 @@
 
   List<int> _apiSignature;
   List<String> _exports;
+  bool _hasLibraryDirective;
+  bool _hasPartOfDirective;
   List<String> _imports;
-  bool _isPartOf;
   List<int> _lineStarts;
   List<String> _parts;
 
@@ -29481,6 +29497,20 @@
   }
 
   @override
+  bool get hasLibraryDirective {
+    _hasLibraryDirective ??=
+        const fb.BoolReader().vTableGet(_bc, _bcOffset, 6, false);
+    return _hasLibraryDirective;
+  }
+
+  @override
+  bool get hasPartOfDirective {
+    _hasPartOfDirective ??=
+        const fb.BoolReader().vTableGet(_bc, _bcOffset, 3, false);
+    return _hasPartOfDirective;
+  }
+
+  @override
   List<String> get imports {
     _imports ??= const fb.ListReader<String>(const fb.StringReader())
         .vTableGet(_bc, _bcOffset, 2, const <String>[]);
@@ -29488,12 +29518,6 @@
   }
 
   @override
-  bool get isPartOf {
-    _isPartOf ??= const fb.BoolReader().vTableGet(_bc, _bcOffset, 3, false);
-    return _isPartOf;
-  }
-
-  @override
   List<int> get lineStarts {
     _lineStarts ??=
         const fb.Uint32ListReader().vTableGet(_bc, _bcOffset, 5, const <int>[]);
@@ -29514,8 +29538,11 @@
     Map<String, Object> _result = <String, Object>{};
     if (apiSignature.isNotEmpty) _result["apiSignature"] = apiSignature;
     if (exports.isNotEmpty) _result["exports"] = exports;
+    if (hasLibraryDirective != false)
+      _result["hasLibraryDirective"] = hasLibraryDirective;
+    if (hasPartOfDirective != false)
+      _result["hasPartOfDirective"] = hasPartOfDirective;
     if (imports.isNotEmpty) _result["imports"] = imports;
-    if (isPartOf != false) _result["isPartOf"] = isPartOf;
     if (lineStarts.isNotEmpty) _result["lineStarts"] = lineStarts;
     if (parts.isNotEmpty) _result["parts"] = parts;
     return _result;
@@ -29525,8 +29552,9 @@
   Map<String, Object> toMap() => {
         "apiSignature": apiSignature,
         "exports": exports,
+        "hasLibraryDirective": hasLibraryDirective,
+        "hasPartOfDirective": hasPartOfDirective,
         "imports": imports,
-        "isPartOf": isPartOf,
         "lineStarts": lineStarts,
         "parts": parts,
       };
diff --git a/pkg/analyzer/lib/src/summary/format.fbs b/pkg/analyzer/lib/src/summary/format.fbs
index e724a26..b7053cb 100644
--- a/pkg/analyzer/lib/src/summary/format.fbs
+++ b/pkg/analyzer/lib/src/summary/format.fbs
@@ -3088,11 +3088,14 @@
   /// URIs of `export` directives.
   exports:[string] (id: 1);
 
-  /// URIs of `import` directives.
-  imports:[string] (id: 2);
+  /// Is `true` if the unit contains a `library` directive.
+  hasLibraryDirective:bool (id: 6);
 
   /// Is `true` if the unit contains a `part of` directive.
-  isPartOf:bool (id: 3);
+  hasPartOfDirective:bool (id: 3);
+
+  /// URIs of `import` directives.
+  imports:[string] (id: 2);
 
   /// Offsets of the first character of each line in the source code.
   lineStarts:[uint] (id: 5);
diff --git a/pkg/analyzer/lib/src/summary/idl.dart b/pkg/analyzer/lib/src/summary/idl.dart
index e89bba2..d0e04f4 100644
--- a/pkg/analyzer/lib/src/summary/idl.dart
+++ b/pkg/analyzer/lib/src/summary/idl.dart
@@ -4849,13 +4849,17 @@
   @Id(1)
   List<String> get exports;
 
-  /// URIs of `import` directives.
-  @Id(2)
-  List<String> get imports;
+  /// Is `true` if the unit contains a `library` directive.
+  @Id(6)
+  bool get hasLibraryDirective;
 
   /// Is `true` if the unit contains a `part of` directive.
   @Id(3)
-  bool get isPartOf;
+  bool get hasPartOfDirective;
+
+  /// URIs of `import` directives.
+  @Id(2)
+  List<String> get imports;
 
   /// Offsets of the first character of each line in the source code.
   @informative