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

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

Issue 1577413002: Patch together getters/setters in different parts. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 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 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/element/element.dart'; 9 import 'package:analyzer/dart/element/element.dart';
10 import 'package:analyzer/dart/element/type.dart'; 10 import 'package:analyzer/dart/element/type.dart';
(...skipping 1470 matching lines...) Expand 10 before | Expand all | Expand 10 after
1481 owningContext = internalContext.getContextFor(librarySource); 1481 owningContext = internalContext.getContextFor(librarySource);
1482 } 1482 }
1483 LibraryElementImpl libraryElement = 1483 LibraryElementImpl libraryElement =
1484 new LibraryElementImpl.forNode(owningContext, libraryNameNode); 1484 new LibraryElementImpl.forNode(owningContext, libraryNameNode);
1485 libraryElement.definingCompilationUnit = definingCompilationUnitElement; 1485 libraryElement.definingCompilationUnit = definingCompilationUnitElement;
1486 libraryElement.entryPoint = entryPoint; 1486 libraryElement.entryPoint = entryPoint;
1487 libraryElement.parts = sourcedCompilationUnits; 1487 libraryElement.parts = sourcedCompilationUnits;
1488 for (Directive directive in directivesToResolve) { 1488 for (Directive directive in directivesToResolve) {
1489 directive.element = libraryElement; 1489 directive.element = libraryElement;
1490 } 1490 }
1491 if (sourcedCompilationUnits.isNotEmpty) { 1491 BuildLibraryElementUtils.patchTopLevelAccessors(libraryElement);
1492 _patchTopLevelAccessors(libraryElement);
1493 }
1494 if (libraryDirective != null) { 1492 if (libraryDirective != null) {
1495 _setDoc(libraryElement, libraryDirective); 1493 _setDoc(libraryElement, libraryDirective);
1496 } 1494 }
1497 // 1495 //
1498 // Record outputs. 1496 // Record outputs.
1499 // 1497 //
1500 outputs[BUILD_LIBRARY_ERRORS] = errors; 1498 outputs[BUILD_LIBRARY_ERRORS] = errors;
1501 outputs[LIBRARY_ELEMENT1] = libraryElement; 1499 outputs[LIBRARY_ELEMENT1] = libraryElement;
1502 outputs[IS_LAUNCHABLE] = entryPoint != null; 1500 outputs[IS_LAUNCHABLE] = entryPoint != null;
1503 } 1501 }
1504 1502
1505 /** 1503 /**
1506 * Add all of the non-synthetic [getters] and [setters] defined in the given
1507 * [unit] that have no corresponding accessor to one of the given collections.
1508 */
1509 void _collectAccessors(Map<String, PropertyAccessorElement> getters,
1510 List<PropertyAccessorElement> setters, CompilationUnitElement unit) {
1511 for (PropertyAccessorElement accessor in unit.accessors) {
1512 if (accessor.isGetter) {
1513 if (!accessor.isSynthetic && accessor.correspondingSetter == null) {
1514 getters[accessor.displayName] = accessor;
1515 }
1516 } else {
1517 if (!accessor.isSynthetic && accessor.correspondingGetter == null) {
1518 setters.add(accessor);
1519 }
1520 }
1521 }
1522 }
1523
1524 /**
1525 * Return the top-level [FunctionElement] entry point, or `null` if the given 1504 * Return the top-level [FunctionElement] entry point, or `null` if the given
1526 * [element] does not define an entry point. 1505 * [element] does not define an entry point.
1527 */ 1506 */
1528 FunctionElement _findEntryPoint(CompilationUnitElementImpl element) { 1507 FunctionElement _findEntryPoint(CompilationUnitElementImpl element) {
1529 for (FunctionElement function in element.functions) { 1508 for (FunctionElement function in element.functions) {
1530 if (function.isEntryPoint) { 1509 if (function.isEntryPoint) {
1531 return function; 1510 return function;
1532 } 1511 }
1533 } 1512 }
1534 return null; 1513 return null;
(...skipping 11 matching lines...) Expand all
1546 LibraryIdentifier libraryName = directive.libraryName; 1525 LibraryIdentifier libraryName = directive.libraryName;
1547 if (libraryName != null) { 1526 if (libraryName != null) {
1548 return libraryName.name; 1527 return libraryName.name;
1549 } 1528 }
1550 } 1529 }
1551 } 1530 }
1552 return null; 1531 return null;
1553 } 1532 }
1554 1533
1555 /** 1534 /**
1556 * Look through all of the compilation units defined for the given [library],
1557 * looking for getters and setters that are defined in different compilation
1558 * units but that have the same names. If any are found, make sure that they
1559 * have the same variable element.
1560 */
1561 void _patchTopLevelAccessors(LibraryElementImpl library) {
1562 HashMap<String, PropertyAccessorElement> getters =
1563 new HashMap<String, PropertyAccessorElement>();
1564 List<PropertyAccessorElement> setters = <PropertyAccessorElement>[];
1565 _collectAccessors(getters, setters, library.definingCompilationUnit);
1566 for (CompilationUnitElement unit in library.parts) {
1567 _collectAccessors(getters, setters, unit);
1568 }
1569 for (PropertyAccessorElement setter in setters) {
1570 PropertyAccessorElement getter = getters[setter.displayName];
1571 if (getter != null) {
1572 TopLevelVariableElementImpl variable = getter.variable;
1573 TopLevelVariableElementImpl setterVariable = setter.variable;
1574 CompilationUnitElementImpl setterUnit = setterVariable.enclosingElement;
1575 setterUnit.replaceTopLevelVariable(setterVariable, variable);
1576 variable.setter = setter;
1577 (setter as PropertyAccessorElementImpl).variable = variable;
1578 }
1579 }
1580 }
1581
1582 /**
1583 * If the given [node] has a documentation comment, remember its content 1535 * If the given [node] has a documentation comment, remember its content
1584 * and range into the given [element]. 1536 * and range into the given [element].
1585 */ 1537 */
1586 void _setDoc(ElementImpl element, AnnotatedNode node) { 1538 void _setDoc(ElementImpl element, AnnotatedNode node) {
1587 Comment comment = node.documentationComment; 1539 Comment comment = node.documentationComment;
1588 if (comment != null && comment.isDocumentation) { 1540 if (comment != null && comment.isDocumentation) {
1589 element.documentationComment = 1541 element.documentationComment =
1590 comment.tokens.map((Token t) => t.lexeme).join('\n'); 1542 comment.tokens.map((Token t) => t.lexeme).join('\n');
1591 element.setDocRange(comment.offset, comment.length); 1543 element.setDocRange(comment.offset, comment.length);
1592 } 1544 }
(...skipping 3893 matching lines...) Expand 10 before | Expand all | Expand 10 after
5486 5438
5487 @override 5439 @override
5488 bool moveNext() { 5440 bool moveNext() {
5489 if (_newSources.isEmpty) { 5441 if (_newSources.isEmpty) {
5490 return false; 5442 return false;
5491 } 5443 }
5492 currentTarget = _newSources.removeLast(); 5444 currentTarget = _newSources.removeLast();
5493 return true; 5445 return true;
5494 } 5446 }
5495 } 5447 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698