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

Side by Side Diff: pkg/analyzer/lib/src/task/dart.dart

Issue 1768713002: Fixes to associating existing elements with an AST (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Address comments Created 4 years, 9 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 analyzer.src.task.dart; 5 library analyzer.src.task.dart;
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';
(...skipping 986 matching lines...) Expand 10 before | Expand all | Expand 10 after
997 CompilationUnit libraryUnit = getRequiredInput(UNIT_INPUT_NAME); 997 CompilationUnit libraryUnit = getRequiredInput(UNIT_INPUT_NAME);
998 Map<Source, LibraryElement> importLibraryMap = 998 Map<Source, LibraryElement> importLibraryMap =
999 getRequiredInput(IMPORTS_LIBRARY_ELEMENT_INPUT_NAME); 999 getRequiredInput(IMPORTS_LIBRARY_ELEMENT_INPUT_NAME);
1000 Map<Source, LibraryElement> exportLibraryMap = 1000 Map<Source, LibraryElement> exportLibraryMap =
1001 getRequiredInput(EXPORTS_LIBRARY_ELEMENT_INPUT_NAME); 1001 getRequiredInput(EXPORTS_LIBRARY_ELEMENT_INPUT_NAME);
1002 Map<Source, SourceKind> importSourceKindMap = 1002 Map<Source, SourceKind> importSourceKindMap =
1003 getRequiredInput(IMPORTS_SOURCE_KIND_INPUT_NAME); 1003 getRequiredInput(IMPORTS_SOURCE_KIND_INPUT_NAME);
1004 Map<Source, SourceKind> exportSourceKindMap = 1004 Map<Source, SourceKind> exportSourceKindMap =
1005 getRequiredInput(EXPORTS_SOURCE_KIND_INPUT_NAME); 1005 getRequiredInput(EXPORTS_SOURCE_KIND_INPUT_NAME);
1006 // 1006 //
1007 // Build elements. 1007 // Try to get the existing LibraryElement.
1008 // 1008 //
1009 DirectiveElementBuilder builder = new DirectiveElementBuilder( 1009 LibraryElement element;
1010 context, 1010 {
1011 libraryElement, 1011 InternalAnalysisContext internalContext =
1012 importLibraryMap, 1012 context as InternalAnalysisContext;
1013 importSourceKindMap, 1013 AnalysisCache analysisCache = internalContext.analysisCache;
1014 exportLibraryMap, 1014 CacheEntry cacheEntry = internalContext.getCacheEntry(target);
1015 exportSourceKindMap); 1015 element = analysisCache.getValue(target, LIBRARY_ELEMENT2);
1016 libraryUnit.accept(builder); 1016 if (element == null &&
1017 // See commentary in the computation of the LIBRARY_CYCLE result 1017 internalContext.aboutToComputeResult(cacheEntry, LIBRARY_ELEMENT2)) {
1018 // for details on library cycle invalidation. 1018 element = analysisCache.getValue(target, LIBRARY_ELEMENT2);
1019 libraryElement.invalidateLibraryCycles(); 1019 }
1020 }
1021 //
1022 // Build or reuse the directive elements.
1023 //
1024 List<AnalysisError> errors;
1025 if (element == null) {
1026 DirectiveElementBuilder builder = new DirectiveElementBuilder(
1027 context,
1028 libraryElement,
1029 importLibraryMap,
1030 importSourceKindMap,
1031 exportLibraryMap,
1032 exportSourceKindMap);
1033 libraryUnit.accept(builder);
1034 // See the commentary in the computation of the LIBRARY_CYCLE result
1035 // for details on library cycle invalidation.
1036 libraryElement.invalidateLibraryCycles();
1037 errors = builder.errors;
1038 } else {
1039 DirectiveResolver resolver = new DirectiveResolver();
1040 libraryUnit.accept(resolver);
1041 }
1020 // 1042 //
1021 // Record outputs. 1043 // Record outputs.
1022 // 1044 //
1023 outputs[LIBRARY_ELEMENT2] = libraryElement; 1045 outputs[LIBRARY_ELEMENT2] = libraryElement;
1024 outputs[BUILD_DIRECTIVES_ERRORS] = builder.errors; 1046 outputs[BUILD_DIRECTIVES_ERRORS] = errors;
1025 } 1047 }
1026 1048
1027 /** 1049 /**
1028 * Return a map from the names of the inputs of this kind of task to the task 1050 * Return a map from the names of the inputs of this kind of task to the task
1029 * input descriptors describing those inputs for a task with the 1051 * input descriptors describing those inputs for a task with the
1030 * given library [libSource]. 1052 * given library [libSource].
1031 */ 1053 */
1032 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 1054 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
1033 Source source = target; 1055 Source source = target;
1034 return <String, TaskInput>{ 1056 return <String, TaskInput>{
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
1376 } 1398 }
1377 // 1399 //
1378 // Create a new LibraryElement. 1400 // Create a new LibraryElement.
1379 // 1401 //
1380 if (libraryElement == null) { 1402 if (libraryElement == null) {
1381 libraryElement = 1403 libraryElement =
1382 new LibraryElementImpl.forNode(owningContext, libraryNameNode); 1404 new LibraryElementImpl.forNode(owningContext, libraryNameNode);
1383 libraryElement.definingCompilationUnit = definingCompilationUnitElement; 1405 libraryElement.definingCompilationUnit = definingCompilationUnitElement;
1384 libraryElement.entryPoint = entryPoint; 1406 libraryElement.entryPoint = entryPoint;
1385 libraryElement.parts = sourcedCompilationUnits; 1407 libraryElement.parts = sourcedCompilationUnits;
1386 for (Directive directive in directivesToResolve) { 1408 libraryElement.hasExtUri = _hasExtUri(definingCompilationUnit);
1387 directive.element = libraryElement;
1388 }
1389 BuildLibraryElementUtils.patchTopLevelAccessors(libraryElement); 1409 BuildLibraryElementUtils.patchTopLevelAccessors(libraryElement);
1390 // set the library documentation to the docs associated with the first 1410 // set the library documentation to the docs associated with the first
1391 // directive in the compilation unit. 1411 // directive in the compilation unit.
1392 if (definingCompilationUnit.directives.isNotEmpty) { 1412 if (definingCompilationUnit.directives.isNotEmpty) {
1393 setElementDocumentationComment( 1413 setElementDocumentationComment(
1394 libraryElement, definingCompilationUnit.directives.first); 1414 libraryElement, definingCompilationUnit.directives.first);
1395 } 1415 }
1396 } 1416 }
1397 // 1417 //
1418 // Resolve the relevant directives to the library element.
1419 //
1420 // TODO(brianwilkerson) This updates the state of the AST structures but
1421 // does not associate a new result with it.
1422 //
1423 for (Directive directive in directivesToResolve) {
1424 directive.element = libraryElement;
1425 }
1426 //
1398 // Record outputs. 1427 // Record outputs.
1399 // 1428 //
1400 outputs[BUILD_LIBRARY_ERRORS] = errors; 1429 outputs[BUILD_LIBRARY_ERRORS] = errors;
1401 outputs[LIBRARY_ELEMENT1] = libraryElement; 1430 outputs[LIBRARY_ELEMENT1] = libraryElement;
1402 outputs[IS_LAUNCHABLE] = entryPoint != null; 1431 outputs[IS_LAUNCHABLE] = entryPoint != null;
1403 } 1432 }
1404 1433
1405 /** 1434 /**
1406 * Return the top-level [FunctionElement] entry point, or `null` if the given 1435 * Return the top-level [FunctionElement] entry point, or `null` if the given
1407 * [element] does not define an entry point. 1436 * [element] does not define an entry point.
(...skipping 19 matching lines...) Expand all
1427 LibraryIdentifier libraryName = directive.libraryName; 1456 LibraryIdentifier libraryName = directive.libraryName;
1428 if (libraryName != null) { 1457 if (libraryName != null) {
1429 return libraryName.name; 1458 return libraryName.name;
1430 } 1459 }
1431 } 1460 }
1432 } 1461 }
1433 return null; 1462 return null;
1434 } 1463 }
1435 1464
1436 /** 1465 /**
1466 * Return `true` if the given compilation [unit] contains at least one
1467 * import directive with a `dart-ext:` URI.
1468 */
1469 bool _hasExtUri(CompilationUnit unit) {
1470 for (Directive directive in unit.directives) {
1471 if (directive is ImportDirective) {
1472 if (DartUriResolver.isDartExtUri(directive.uriContent)) {
1473 return true;
1474 }
1475 }
1476 }
1477 return false;
1478 }
1479
1480 /**
1437 * Return a map from the names of the inputs of this kind of task to the task 1481 * Return a map from the names of the inputs of this kind of task to the task
1438 * input descriptors describing those inputs for a task with the given 1482 * input descriptors describing those inputs for a task with the given
1439 * [libSource]. 1483 * [libSource].
1440 */ 1484 */
1441 static Map<String, TaskInput> buildInputs(AnalysisTarget target) { 1485 static Map<String, TaskInput> buildInputs(AnalysisTarget target) {
1442 Source source = target; 1486 Source source = target;
1443 return <String, TaskInput>{ 1487 return <String, TaskInput>{
1444 DEFINING_UNIT_INPUT: 1488 DEFINING_UNIT_INPUT:
1445 RESOLVED_UNIT1.of(new LibrarySpecificUnit(source, source)), 1489 RESOLVED_UNIT1.of(new LibrarySpecificUnit(source, source)),
1446 PARTS_UNIT_INPUT: INCLUDED_PARTS.of(source).toList((Source unit) { 1490 PARTS_UNIT_INPUT: INCLUDED_PARTS.of(source).toList((Source unit) {
(...skipping 3811 matching lines...) Expand 10 before | Expand all | Expand 10 after
5258 5302
5259 @override 5303 @override
5260 bool moveNext() { 5304 bool moveNext() {
5261 if (_newSources.isEmpty) { 5305 if (_newSources.isEmpty) {
5262 return false; 5306 return false;
5263 } 5307 }
5264 currentTarget = _newSources.removeLast(); 5308 currentTarget = _newSources.removeLast();
5265 return true; 5309 return true;
5266 } 5310 }
5267 } 5311 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/resolver.dart ('k') | pkg/analyzer/test/generated/declaration_resolver_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698