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

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

Issue 2235373003: Fix summary handling of unresolved imports, exports, and parts. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Simplify `allowMissingFiles` Created 4 years, 4 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
« no previous file with comments | « pkg/analyzer/lib/src/summary/index_unit.dart ('k') | pkg/analyzer/lib/src/task/dart.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/token.dart'; 10 import 'package:analyzer/dart/ast/token.dart';
11 import 'package:analyzer/dart/element/element.dart'; 11 import 'package:analyzer/dart/element/element.dart';
12 import 'package:analyzer/dart/element/type.dart'; 12 import 'package:analyzer/dart/element/type.dart';
13 import 'package:analyzer/src/dart/element/element.dart'; 13 import 'package:analyzer/src/dart/element/element.dart';
14 import 'package:analyzer/src/dart/element/handle.dart'; 14 import 'package:analyzer/src/dart/element/handle.dart';
15 import 'package:analyzer/src/dart/element/member.dart'; 15 import 'package:analyzer/src/dart/element/member.dart';
16 import 'package:analyzer/src/dart/element/type.dart'; 16 import 'package:analyzer/src/dart/element/type.dart';
17 import 'package:analyzer/src/generated/engine.dart'; 17 import 'package:analyzer/src/generated/engine.dart';
18 import 'package:analyzer/src/generated/resolver.dart'; 18 import 'package:analyzer/src/generated/resolver.dart';
19 import 'package:analyzer/src/generated/source_io.dart'; 19 import 'package:analyzer/src/generated/source_io.dart';
20 import 'package:analyzer/src/generated/testing/ast_factory.dart'; 20 import 'package:analyzer/src/generated/testing/ast_factory.dart';
21 import 'package:analyzer/src/generated/testing/token_factory.dart'; 21 import 'package:analyzer/src/generated/testing/token_factory.dart';
22 import 'package:analyzer/src/summary/format.dart';
22 import 'package:analyzer/src/summary/idl.dart'; 23 import 'package:analyzer/src/summary/idl.dart';
23 24
24 /** 25 /**
25 * Implementation of [ElementResynthesizer] used when resynthesizing an element 26 * Implementation of [ElementResynthesizer] used when resynthesizing an element
26 * model from summaries. 27 * model from summaries.
27 */ 28 */
28 abstract class SummaryResynthesizer extends ElementResynthesizer { 29 abstract class SummaryResynthesizer extends ElementResynthesizer {
29 /** 30 /**
30 * The parent [SummaryResynthesizer] which is asked to resynthesize elements 31 * The parent [SummaryResynthesizer] which is asked to resynthesize elements
31 * and get summaries before this resynthesizer attempts to do this. 32 * and get summaries before this resynthesizer attempts to do this.
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 } 145 }
145 CompilationUnitElementImpl unitElement = libraryMap[unitUri]; 146 CompilationUnitElementImpl unitElement = libraryMap[unitUri];
146 // Fill elements in the unit map. 147 // Fill elements in the unit map.
147 if (unitElement != null) { 148 if (unitElement != null) {
148 elementsInUnit = new HashMap<String, Element>(); 149 elementsInUnit = new HashMap<String, Element>();
149 void putElement(Element e) { 150 void putElement(Element e) {
150 String id = 151 String id =
151 e is PropertyAccessorElementImpl ? e.identifier : e.name; 152 e is PropertyAccessorElementImpl ? e.identifier : e.name;
152 elementsInUnit[id] = e; 153 elementsInUnit[id] = e;
153 } 154 }
155
154 unitElement.accessors.forEach(putElement); 156 unitElement.accessors.forEach(putElement);
155 unitElement.enums.forEach(putElement); 157 unitElement.enums.forEach(putElement);
156 unitElement.functions.forEach(putElement); 158 unitElement.functions.forEach(putElement);
157 unitElement.functionTypeAliases.forEach(putElement); 159 unitElement.functionTypeAliases.forEach(putElement);
158 unitElement.topLevelVariables.forEach(putElement); 160 unitElement.topLevelVariables.forEach(putElement);
159 unitElement.types.forEach(putElement); 161 unitElement.types.forEach(putElement);
160 unitsInLibrary[unitUri] = elementsInUnit; 162 unitsInLibrary[unitUri] = elementsInUnit;
161 } 163 }
162 } 164 }
163 // Get the element. 165 // Get the element.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 199
198 /** 200 /**
199 * Get the [LibraryElement] for the given [uri], resynthesizing it if it 201 * Get the [LibraryElement] for the given [uri], resynthesizing it if it
200 * hasn't been resynthesized already. 202 * hasn't been resynthesized already.
201 */ 203 */
202 LibraryElement getLibraryElement(String uri) { 204 LibraryElement getLibraryElement(String uri) {
203 if (parent != null && parent._hasLibrarySummary(uri)) { 205 if (parent != null && parent._hasLibrarySummary(uri)) {
204 return parent.getLibraryElement(uri); 206 return parent.getLibraryElement(uri);
205 } 207 }
206 return _resynthesizedLibraries.putIfAbsent(uri, () { 208 return _resynthesizedLibraries.putIfAbsent(uri, () {
207 LinkedLibrary serializedLibrary = _getLinkedSummaryOrThrow(uri); 209 LinkedLibrary serializedLibrary = _getLinkedSummaryOrNull(uri);
208 List<UnlinkedUnit> serializedUnits = <UnlinkedUnit>[
209 _getUnlinkedSummaryOrThrow(uri)
210 ];
211 Source librarySource = _getSource(uri); 210 Source librarySource = _getSource(uri);
211 if (serializedLibrary == null) {
212 LibraryElementImpl libraryElement =
213 new LibraryElementImpl(context, '', -1, 0);
214 libraryElement.synthetic = true;
215 CompilationUnitElementImpl unitElement =
216 new CompilationUnitElementImpl(librarySource.shortName);
217 libraryElement.definingCompilationUnit = unitElement;
218 unitElement.source = librarySource;
219 unitElement.librarySource = librarySource;
220 return libraryElement..synthetic = true;
221 }
222 UnlinkedUnit unlinkedSummary = _getUnlinkedSummaryOrNull(uri);
223 if (unlinkedSummary == null) {
224 throw new StateError('Unable to find unlinked summary: $uri');
225 }
226 List<UnlinkedUnit> serializedUnits = <UnlinkedUnit>[unlinkedSummary];
212 for (String part in serializedUnits[0].publicNamespace.parts) { 227 for (String part in serializedUnits[0].publicNamespace.parts) {
213 Source partSource = sourceFactory.resolveUri(librarySource, part); 228 Source partSource = sourceFactory.resolveUri(librarySource, part);
214 String partAbsUri = partSource.uri.toString(); 229 String partAbsUri = partSource.uri.toString();
215 serializedUnits.add(_getUnlinkedSummaryOrThrow(partAbsUri)); 230 serializedUnits.add(_getUnlinkedSummaryOrNull(partAbsUri) ??
231 new UnlinkedUnitBuilder(codeRange: new CodeRangeBuilder()));
216 } 232 }
217 _LibraryResynthesizer libraryResynthesizer = new _LibraryResynthesizer( 233 _LibraryResynthesizer libraryResynthesizer = new _LibraryResynthesizer(
218 this, serializedLibrary, serializedUnits, librarySource); 234 this, serializedLibrary, serializedUnits, librarySource);
219 LibraryElement library = libraryResynthesizer.buildLibrary(); 235 LibraryElement library = libraryResynthesizer.buildLibrary();
220 _resynthesizedUnits[uri] = libraryResynthesizer.resynthesizedUnits; 236 _resynthesizedUnits[uri] = libraryResynthesizer.resynthesizedUnits;
221 return library; 237 return library;
222 }); 238 });
223 } 239 }
224 240
225 /** 241 /**
(...skipping 11 matching lines...) Expand all
237 UnlinkedUnit getUnlinkedSummary(String uri); 253 UnlinkedUnit getUnlinkedSummary(String uri);
238 254
239 /** 255 /**
240 * Return `true` if this resynthesizer can provide summaries of the libraries 256 * Return `true` if this resynthesizer can provide summaries of the libraries
241 * with the given [uri]. Caller has already checked that 257 * with the given [uri]. Caller has already checked that
242 * `parent.hasLibrarySummary(uri)` returns `false`. 258 * `parent.hasLibrarySummary(uri)` returns `false`.
243 */ 259 */
244 bool hasLibrarySummary(String uri); 260 bool hasLibrarySummary(String uri);
245 261
246 /** 262 /**
247 * Return the [LinkedLibrary] for the given [uri] or throw [StateError] if it 263 * Return the [LinkedLibrary] for the given [uri] or return `null` if it
248 * could not be found. 264 * could not be found.
249 */ 265 */
250 LinkedLibrary _getLinkedSummaryOrThrow(String uri) { 266 LinkedLibrary _getLinkedSummaryOrNull(String uri) {
251 if (parent != null && parent._hasLibrarySummary(uri)) { 267 if (parent != null && parent._hasLibrarySummary(uri)) {
252 return parent._getLinkedSummaryOrThrow(uri); 268 return parent._getLinkedSummaryOrNull(uri);
253 } 269 }
254 LinkedLibrary summary = getLinkedSummary(uri); 270 return getLinkedSummary(uri);
255 if (summary != null) {
256 return summary;
257 }
258 throw new StateError('Unable to find linked summary: $uri');
259 } 271 }
260 272
261 /** 273 /**
262 * Get the [Source] object for the given [uri]. 274 * Get the [Source] object for the given [uri].
263 */ 275 */
264 Source _getSource(String uri) { 276 Source _getSource(String uri) {
265 return _sources.putIfAbsent(uri, () => sourceFactory.forUri(uri)); 277 return _sources.putIfAbsent(uri, () => sourceFactory.forUri(uri));
266 } 278 }
267 279
268 /** 280 /**
269 * Return the [UnlinkedUnit] for the given [uri] or throw [StateError] if it 281 * Return the [UnlinkedUnit] for the given [uri] or return `null` if it
270 * could not be found. 282 * could not be found.
271 */ 283 */
272 UnlinkedUnit _getUnlinkedSummaryOrThrow(String uri) { 284 UnlinkedUnit _getUnlinkedSummaryOrNull(String uri) {
273 if (parent != null && parent._hasLibrarySummary(uri)) { 285 if (parent != null && parent._hasLibrarySummary(uri)) {
274 return parent._getUnlinkedSummaryOrThrow(uri); 286 return parent._getUnlinkedSummaryOrNull(uri);
275 } 287 }
276 UnlinkedUnit summary = getUnlinkedSummary(uri); 288 return getUnlinkedSummary(uri);
277 if (summary != null) {
278 return summary;
279 }
280 throw new StateError('Unable to find unlinked summary: $uri');
281 } 289 }
282 290
283 /** 291 /**
284 * Return `true` if this resynthesizer can provide summaries of the libraries 292 * Return `true` if this resynthesizer can provide summaries of the libraries
285 * with the given [uri]. 293 * with the given [uri].
286 */ 294 */
287 bool _hasLibrarySummary(String uri) { 295 bool _hasLibrarySummary(String uri) {
288 if (parent != null && parent._hasLibrarySummary(uri)) { 296 if (parent != null && parent._hasLibrarySummary(uri)) {
289 return true; 297 return true;
290 } 298 }
(...skipping 982 matching lines...) Expand 10 before | Expand all | Expand 10 after
1273 for (int i = 0; i < numTypeParameters; i++) { 1281 for (int i = 0; i < numTypeParameters; i++) {
1274 typeArguments[i] = getTypeArgument(i); 1282 typeArguments[i] = getTypeArgument(i);
1275 } 1283 }
1276 } 1284 }
1277 InterfaceTypeImpl type = 1285 InterfaceTypeImpl type =
1278 new InterfaceTypeImpl.elementWithNameAndArgs(element, name, () { 1286 new InterfaceTypeImpl.elementWithNameAndArgs(element, name, () {
1279 if (typeArguments == null) { 1287 if (typeArguments == null) {
1280 typeArguments = element.typeParameters.map((typeParameter) { 1288 typeArguments = element.typeParameters.map((typeParameter) {
1281 DartType bound = typeParameter.bound; 1289 DartType bound = typeParameter.bound;
1282 return libraryResynthesizer.summaryResynthesizer.strongMode && 1290 return libraryResynthesizer.summaryResynthesizer.strongMode &&
1283 instantiateToBoundsAllowed && 1291 instantiateToBoundsAllowed &&
1284 bound != null ? bound : DynamicTypeImpl.instance; 1292 bound != null
1293 ? bound
1294 : DynamicTypeImpl.instance;
1285 }).toList(); 1295 }).toList();
1286 } 1296 }
1287 return typeArguments; 1297 return typeArguments;
1288 }); 1298 });
1289 // Mark the type as having implicit type arguments, so that we don't 1299 // Mark the type as having implicit type arguments, so that we don't
1290 // attempt to request them during constant expression resynthesizing. 1300 // attempt to request them during constant expression resynthesizing.
1291 if (typeArguments == null) { 1301 if (typeArguments == null) {
1292 libraryResynthesizer.typesWithImplicitTypeArguments.add(type); 1302 libraryResynthesizer.typesWithImplicitTypeArguments.add(type);
1293 } 1303 }
1294 // Done. 1304 // Done.
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
1566 new FunctionElementImpl_forLUB(unit, typeParameterContext, type); 1576 new FunctionElementImpl_forLUB(unit, typeParameterContext, type);
1567 return element.type; 1577 return element.type;
1568 } else { 1578 } else {
1569 DartType getTypeArgument(int i) { 1579 DartType getTypeArgument(int i) {
1570 if (i < type.typeArguments.length) { 1580 if (i < type.typeArguments.length) {
1571 return buildType(type.typeArguments[i], typeParameterContext); 1581 return buildType(type.typeArguments[i], typeParameterContext);
1572 } else { 1582 } else {
1573 return DynamicTypeImpl.instance; 1583 return DynamicTypeImpl.instance;
1574 } 1584 }
1575 } 1585 }
1586
1576 _ReferenceInfo referenceInfo = getReferenceInfo(type.reference); 1587 _ReferenceInfo referenceInfo = getReferenceInfo(type.reference);
1577 return referenceInfo.buildType( 1588 return referenceInfo.buildType(
1578 instantiateToBoundsAllowed, 1589 instantiateToBoundsAllowed,
1579 type.typeArguments.length, 1590 type.typeArguments.length,
1580 getTypeArgument, 1591 getTypeArgument,
1581 type.implicitFunctionTypeIndices); 1592 type.implicitFunctionTypeIndices);
1582 } 1593 }
1583 } 1594 }
1584 1595
1585 UnitExplicitTopLevelAccessors buildUnitExplicitTopLevelAccessors() { 1596 UnitExplicitTopLevelAccessors buildUnitExplicitTopLevelAccessors() {
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
1837 static String _getElementIdentifier(String name, ReferenceKind kind) { 1848 static String _getElementIdentifier(String name, ReferenceKind kind) {
1838 if (kind == ReferenceKind.topLevelPropertyAccessor || 1849 if (kind == ReferenceKind.topLevelPropertyAccessor ||
1839 kind == ReferenceKind.propertyAccessor) { 1850 kind == ReferenceKind.propertyAccessor) {
1840 if (!name.endsWith('=')) { 1851 if (!name.endsWith('=')) {
1841 return name + '?'; 1852 return name + '?';
1842 } 1853 }
1843 } 1854 }
1844 return name; 1855 return name;
1845 } 1856 }
1846 } 1857 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/index_unit.dart ('k') | pkg/analyzer/lib/src/task/dart.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698