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

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

Issue 2809523002: Issue 29288. Resynthesize Import/Export/PartElement for every directive. (Closed)
Patch Set: Created 3 years, 8 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 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 libraryElement.exportNamespace = new Namespace({}); 206 libraryElement.exportNamespace = new Namespace({});
207 return libraryElement; 207 return libraryElement;
208 } 208 }
209 UnlinkedUnit unlinkedSummary = getUnlinkedSummary(uri); 209 UnlinkedUnit unlinkedSummary = getUnlinkedSummary(uri);
210 if (unlinkedSummary == null) { 210 if (unlinkedSummary == null) {
211 throw new StateError('Unable to find unlinked summary: $uri'); 211 throw new StateError('Unable to find unlinked summary: $uri');
212 } 212 }
213 List<UnlinkedUnit> serializedUnits = <UnlinkedUnit>[unlinkedSummary]; 213 List<UnlinkedUnit> serializedUnits = <UnlinkedUnit>[unlinkedSummary];
214 for (String part in serializedUnits[0].publicNamespace.parts) { 214 for (String part in serializedUnits[0].publicNamespace.parts) {
215 Source partSource = sourceFactory.resolveUri(librarySource, part); 215 Source partSource = sourceFactory.resolveUri(librarySource, part);
216 if (partSource == null) { 216 UnlinkedUnit partUnlinkedUnit;
217 serializedUnits.add(null); 217 if (partSource != null) {
218 } else {
219 String partAbsUri = partSource.uri.toString(); 218 String partAbsUri = partSource.uri.toString();
220 serializedUnits.add(getUnlinkedSummary(partAbsUri) ?? 219 partUnlinkedUnit = getUnlinkedSummary(partAbsUri);
221 new UnlinkedUnitBuilder(codeRange: new CodeRangeBuilder()));
222 } 220 }
221 serializedUnits.add(partUnlinkedUnit ??
222 new UnlinkedUnitBuilder(codeRange: new CodeRangeBuilder()));
223 } 223 }
224 _LibraryResynthesizer libraryResynthesizer = new _LibraryResynthesizer( 224 _LibraryResynthesizer libraryResynthesizer = new _LibraryResynthesizer(
225 this, serializedLibrary, serializedUnits, librarySource); 225 this, serializedLibrary, serializedUnits, librarySource);
226 LibraryElement library = libraryResynthesizer.buildLibrary(); 226 LibraryElement library = libraryResynthesizer.buildLibrary();
227 _resynthesizedUnits[uri] = libraryResynthesizer.resynthesizedUnits; 227 _resynthesizedUnits[uri] = libraryResynthesizer.resynthesizedUnits;
228 return library; 228 return library;
229 }); 229 });
230 } 230 }
231 231
232 /** 232 /**
(...skipping 797 matching lines...) Expand 10 before | Expand all | Expand 10 after
1030 } 1030 }
1031 1031
1032 /** 1032 /**
1033 * Create a [_UnitResynthesizer] that will resynthesize the part with the 1033 * Create a [_UnitResynthesizer] that will resynthesize the part with the
1034 * given [uri]. Return `null` if the [uri] is invalid. 1034 * given [uri]. Return `null` if the [uri] is invalid.
1035 */ 1035 */
1036 _UnitResynthesizer buildPart(_UnitResynthesizer definingUnitResynthesizer, 1036 _UnitResynthesizer buildPart(_UnitResynthesizer definingUnitResynthesizer,
1037 String uri, UnlinkedPart partDecl, int unitNum) { 1037 String uri, UnlinkedPart partDecl, int unitNum) {
1038 Source unitSource = 1038 Source unitSource =
1039 summaryResynthesizer.sourceFactory.resolveUri(librarySource, uri); 1039 summaryResynthesizer.sourceFactory.resolveUri(librarySource, uri);
1040 if (unitSource == null) {
1041 return null;
1042 }
1043 _UnitResynthesizer partResynthesizer = 1040 _UnitResynthesizer partResynthesizer =
1044 createUnitResynthesizer(unitNum, unitSource, partDecl); 1041 createUnitResynthesizer(unitNum, unitSource, partDecl);
1045 CompilationUnitElementImpl partUnit = partResynthesizer.unit; 1042 CompilationUnitElementImpl partUnit = partResynthesizer.unit;
1046 partUnit.uriOffset = partDecl.uriOffset; 1043 partUnit.uriOffset = partDecl.uriOffset;
1047 partUnit.uriEnd = partDecl.uriEnd; 1044 partUnit.uriEnd = partDecl.uriEnd;
1048 partUnit.source = unitSource; 1045 partUnit.source = unitSource;
1049 partUnit.librarySource = librarySource; 1046 partUnit.librarySource = librarySource;
1050 partUnit.uri = uri; 1047 partUnit.uri = uri;
1051 return partResynthesizer; 1048 return partResynthesizer;
1052 } 1049 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1094 partUri = partSource.uri.toString(); 1091 partUri = partSource.uri.toString();
1095 } else { 1092 } else {
1096 partUri = referencedLibraryUri; 1093 partUri = referencedLibraryUri;
1097 } 1094 }
1098 return <String>[referencedLibraryUri, partUri, name]; 1095 return <String>[referencedLibraryUri, partUri, name];
1099 } 1096 }
1100 1097
1101 /** 1098 /**
1102 * Remember the absolute URI to the corresponding unit mapping. 1099 * Remember the absolute URI to the corresponding unit mapping.
1103 */ 1100 */
1104 void rememberUriToUnit(_UnitResynthesizer unitResynthesized) { 1101 void rememberUriToUnit(_UnitResynthesizer unitResynthesizer) {
1105 CompilationUnitElementImpl unit = unitResynthesized.unit; 1102 CompilationUnitElementImpl unit = unitResynthesizer.unit;
1106 String absoluteUri = unit.source.uri.toString(); 1103 Source source = unit.source;
1107 resynthesizedUnits[absoluteUri] = unit; 1104 if (source != null) {
1105 String absoluteUri = source.uri.toString();
1106 resynthesizedUnits[absoluteUri] = unit;
1107 }
1108 } 1108 }
1109 } 1109 }
1110 1110
1111 /** 1111 /**
1112 * Implementation of [LibraryResynthesizerContext] for [_LibraryResynthesizer]. 1112 * Implementation of [LibraryResynthesizerContext] for [_LibraryResynthesizer].
1113 */ 1113 */
1114 class _LibraryResynthesizerContext implements LibraryResynthesizerContext { 1114 class _LibraryResynthesizerContext implements LibraryResynthesizerContext {
1115 final _LibraryResynthesizer resynthesizer; 1115 final _LibraryResynthesizer resynthesizer;
1116 1116
1117 _LibraryResynthesizerContext(this.resynthesizer); 1117 _LibraryResynthesizerContext(this.resynthesizer);
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
1505 ResynthesizerContext _resynthesizerContext; 1505 ResynthesizerContext _resynthesizerContext;
1506 1506
1507 _UnitResynthesizer(this.libraryResynthesizer, this.unlinkedUnit, 1507 _UnitResynthesizer(this.libraryResynthesizer, this.unlinkedUnit,
1508 this.linkedUnit, Source unitSource, UnlinkedPart unlinkedPart) { 1508 this.linkedUnit, Source unitSource, UnlinkedPart unlinkedPart) {
1509 _resynthesizerContext = new _ResynthesizerContext(this); 1509 _resynthesizerContext = new _ResynthesizerContext(this);
1510 unit = new CompilationUnitElementImpl.forSerialized( 1510 unit = new CompilationUnitElementImpl.forSerialized(
1511 libraryResynthesizer.library, 1511 libraryResynthesizer.library,
1512 _resynthesizerContext, 1512 _resynthesizerContext,
1513 unlinkedUnit, 1513 unlinkedUnit,
1514 unlinkedPart, 1514 unlinkedPart,
1515 unitSource.shortName); 1515 unitSource?.shortName);
1516 1516
1517 { 1517 {
1518 List<int> lineStarts = unlinkedUnit.lineStarts; 1518 List<int> lineStarts = unlinkedUnit.lineStarts;
1519 if (lineStarts.isEmpty) { 1519 if (lineStarts.isEmpty) {
1520 lineStarts = const <int>[0]; 1520 lineStarts = const <int>[0];
1521 } 1521 }
1522 unit.lineInfo = new LineInfo(lineStarts); 1522 unit.lineInfo = new LineInfo(lineStarts);
1523 } 1523 }
1524 1524
1525 for (EntityRef t in linkedUnit.types) { 1525 for (EntityRef t in linkedUnit.types) {
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
1962 static String _getElementIdentifier(String name, ReferenceKind kind) { 1962 static String _getElementIdentifier(String name, ReferenceKind kind) {
1963 if (kind == ReferenceKind.topLevelPropertyAccessor || 1963 if (kind == ReferenceKind.topLevelPropertyAccessor ||
1964 kind == ReferenceKind.propertyAccessor) { 1964 kind == ReferenceKind.propertyAccessor) {
1965 if (!name.endsWith('=')) { 1965 if (!name.endsWith('=')) {
1966 return name + '?'; 1966 return name + '?';
1967 } 1967 }
1968 } 1968 }
1969 return name; 1969 return name;
1970 } 1970 }
1971 } 1971 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698