Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

Side by Side Diff: pkg/analyzer/lib/src/summary/resynthesize.dart

Issue 2615903003: Fix for resynthesizing libraries with invalid part URIs. (Closed)
Patch Set: Un-fail other tests. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library summary_resynthesizer; 5 library summary_resynthesizer;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; 10 import 'package:analyzer/dart/ast/standard_ast_factory.dart';
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 libraryElement.exportNamespace = new Namespace({}); 223 libraryElement.exportNamespace = new Namespace({});
224 return libraryElement; 224 return libraryElement;
225 } 225 }
226 UnlinkedUnit unlinkedSummary = _getUnlinkedSummaryOrNull(uri); 226 UnlinkedUnit unlinkedSummary = _getUnlinkedSummaryOrNull(uri);
227 if (unlinkedSummary == null) { 227 if (unlinkedSummary == null) {
228 throw new StateError('Unable to find unlinked summary: $uri'); 228 throw new StateError('Unable to find unlinked summary: $uri');
229 } 229 }
230 List<UnlinkedUnit> serializedUnits = <UnlinkedUnit>[unlinkedSummary]; 230 List<UnlinkedUnit> serializedUnits = <UnlinkedUnit>[unlinkedSummary];
231 for (String part in serializedUnits[0].publicNamespace.parts) { 231 for (String part in serializedUnits[0].publicNamespace.parts) {
232 Source partSource = sourceFactory.resolveUri(librarySource, part); 232 Source partSource = sourceFactory.resolveUri(librarySource, part);
233 String partAbsUri = partSource.uri.toString(); 233 if (partSource == null) {
234 serializedUnits.add(_getUnlinkedSummaryOrNull(partAbsUri) ?? 234 serializedUnits.add(null);
235 new UnlinkedUnitBuilder(codeRange: new CodeRangeBuilder())); 235 } else {
236 String partAbsUri = partSource.uri.toString();
237 serializedUnits.add(_getUnlinkedSummaryOrNull(partAbsUri) ??
238 new UnlinkedUnitBuilder(codeRange: new CodeRangeBuilder()));
239 }
236 } 240 }
237 _LibraryResynthesizer libraryResynthesizer = new _LibraryResynthesizer( 241 _LibraryResynthesizer libraryResynthesizer = new _LibraryResynthesizer(
238 this, serializedLibrary, serializedUnits, librarySource); 242 this, serializedLibrary, serializedUnits, librarySource);
239 LibraryElement library = libraryResynthesizer.buildLibrary(); 243 LibraryElement library = libraryResynthesizer.buildLibrary();
240 _resynthesizedUnits[uri] = libraryResynthesizer.resynthesizedUnits; 244 _resynthesizedUnits[uri] = libraryResynthesizer.resynthesizedUnits;
241 return library; 245 return library;
242 }); 246 });
243 } 247 }
244 248
245 /** 249 /**
(...skipping 781 matching lines...) Expand 10 before | Expand all | Expand 10 after
1027 List<_UnitResynthesizer> partResynthesizers = <_UnitResynthesizer>[]; 1031 List<_UnitResynthesizer> partResynthesizers = <_UnitResynthesizer>[];
1028 UnlinkedUnit unlinkedDefiningUnit = unlinkedUnits[0]; 1032 UnlinkedUnit unlinkedDefiningUnit = unlinkedUnits[0];
1029 assert(unlinkedDefiningUnit.publicNamespace.parts.length + 1 == 1033 assert(unlinkedDefiningUnit.publicNamespace.parts.length + 1 ==
1030 linkedLibrary.units.length); 1034 linkedLibrary.units.length);
1031 for (int i = 1; i < linkedLibrary.units.length; i++) { 1035 for (int i = 1; i < linkedLibrary.units.length; i++) {
1032 _UnitResynthesizer partResynthesizer = buildPart( 1036 _UnitResynthesizer partResynthesizer = buildPart(
1033 definingUnitResynthesizer, 1037 definingUnitResynthesizer,
1034 unlinkedDefiningUnit.publicNamespace.parts[i - 1], 1038 unlinkedDefiningUnit.publicNamespace.parts[i - 1],
1035 unlinkedDefiningUnit.parts[i - 1], 1039 unlinkedDefiningUnit.parts[i - 1],
1036 i); 1040 i);
1037 partResynthesizers.add(partResynthesizer); 1041 if (partResynthesizer != null) {
1042 partResynthesizers.add(partResynthesizer);
1043 }
1038 } 1044 }
1039 library.parts = partResynthesizers.map((r) => r.unit).toList(); 1045 library.parts = partResynthesizers.map((r) => r.unit).toList();
1040 // Populate units. 1046 // Populate units.
1041 rememberUriToUnit(definingUnitResynthesizer); 1047 rememberUriToUnit(definingUnitResynthesizer);
1042 for (_UnitResynthesizer partResynthesizer in partResynthesizers) { 1048 for (_UnitResynthesizer partResynthesizer in partResynthesizers) {
1043 rememberUriToUnit(partResynthesizer); 1049 rememberUriToUnit(partResynthesizer);
1044 } 1050 }
1045 // Create the synthetic element for `loadLibrary`. 1051 // Create the synthetic element for `loadLibrary`.
1046 // Until the client received dart:core and dart:async, we cannot do this, 1052 // Until the client received dart:core and dart:async, we cannot do this,
1047 // because the TypeProvider is not fully initialized. So, it is up to the 1053 // because the TypeProvider is not fully initialized. So, it is up to the
1048 // Dart SDK client to initialize TypeProvider and finish the dart:core and 1054 // Dart SDK client to initialize TypeProvider and finish the dart:core and
1049 // dart:async libraries creation. 1055 // dart:async libraries creation.
1050 if (library.name != 'dart.core' && library.name != 'dart.async') { 1056 if (library.name != 'dart.core' && library.name != 'dart.async') {
1051 library.createLoadLibraryFunction(summaryResynthesizer.typeProvider); 1057 library.createLoadLibraryFunction(summaryResynthesizer.typeProvider);
1052 } 1058 }
1053 // Done. 1059 // Done.
1054 return library; 1060 return library;
1055 } 1061 }
1056 1062
1057 /** 1063 /**
1058 * Create, but do not populate, the [CompilationUnitElement] for a part other 1064 * Create a [_UnitResynthesizer] that will resynthesize the part with the
1059 * than the defining compilation unit. 1065 * given [uri]. Return `null` if the [uri] is invalid.
1060 */ 1066 */
1061 _UnitResynthesizer buildPart(_UnitResynthesizer definingUnitResynthesizer, 1067 _UnitResynthesizer buildPart(_UnitResynthesizer definingUnitResynthesizer,
1062 String uri, UnlinkedPart partDecl, int unitNum) { 1068 String uri, UnlinkedPart partDecl, int unitNum) {
1063 Source unitSource = 1069 Source unitSource =
1064 summaryResynthesizer.sourceFactory.resolveUri(librarySource, uri); 1070 summaryResynthesizer.sourceFactory.resolveUri(librarySource, uri);
1071 if (unitSource == null) {
1072 return null;
1073 }
1065 _UnitResynthesizer partResynthesizer = 1074 _UnitResynthesizer partResynthesizer =
1066 createUnitResynthesizer(unitNum, unitSource, partDecl); 1075 createUnitResynthesizer(unitNum, unitSource, partDecl);
1067 CompilationUnitElementImpl partUnit = partResynthesizer.unit; 1076 CompilationUnitElementImpl partUnit = partResynthesizer.unit;
1068 partUnit.uriOffset = partDecl.uriOffset; 1077 partUnit.uriOffset = partDecl.uriOffset;
1069 partUnit.uriEnd = partDecl.uriEnd; 1078 partUnit.uriEnd = partDecl.uriEnd;
1070 partUnit.source = unitSource; 1079 partUnit.source = unitSource;
1071 partUnit.librarySource = librarySource; 1080 partUnit.librarySource = librarySource;
1072 partUnit.uri = uri; 1081 partUnit.uri = uri;
1073 return partResynthesizer; 1082 return partResynthesizer;
1074 } 1083 }
(...skipping 828 matching lines...) Expand 10 before | Expand all | Expand 10 after
1903 static String _getElementIdentifier(String name, ReferenceKind kind) { 1912 static String _getElementIdentifier(String name, ReferenceKind kind) {
1904 if (kind == ReferenceKind.topLevelPropertyAccessor || 1913 if (kind == ReferenceKind.topLevelPropertyAccessor ||
1905 kind == ReferenceKind.propertyAccessor) { 1914 kind == ReferenceKind.propertyAccessor) {
1906 if (!name.endsWith('=')) { 1915 if (!name.endsWith('=')) {
1907 return name + '?'; 1916 return name + '?';
1908 } 1917 }
1909 } 1918 }
1910 return name; 1919 return name;
1911 } 1920 }
1912 } 1921 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698