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

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

Issue 2189783002: Record names of classes which unnamed constructor are used in SuperConstructorInvocation. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: 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
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 2638 matching lines...) Expand 10 before | Expand all | Expand 10 after
2649 // TODO(scheglov) Use only instantiations with default constructor. 2649 // TODO(scheglov) Use only instantiations with default constructor.
2650 for (String name in references.instantiatedNames) { 2650 for (String name in references.instantiatedNames) {
2651 for (ClassElementDelta classDelta in changedClasses.values) { 2651 for (ClassElementDelta classDelta in changedClasses.values) {
2652 if (classDelta.name == name && classDelta.hasUnnamedConstructorChange) { 2652 if (classDelta.name == name && classDelta.hasUnnamedConstructorChange) {
2653 _log(() => 2653 _log(() =>
2654 '$refLibrary is affected by the default constructor of $name'); 2654 '$refLibrary is affected by the default constructor of $name');
2655 return true; 2655 return true;
2656 } 2656 }
2657 } 2657 }
2658 } 2658 }
2659 for (String name in references.extendedUsedUnnamedConstructorNames) {
2660 for (ClassElementDelta classDelta in changedClasses.values) {
2661 if (classDelta.name == name && classDelta.hasUnnamedConstructorChange) {
2662 _log(() =>
2663 '$refLibrary is affected by the default constructor of $name');
2664 return true;
2665 }
2666 }
2667 }
2659 return false; 2668 return false;
2660 } 2669 }
2661 2670
2662 /** 2671 /**
2663 * Return `true` if the given [name], used in a unit of the [librarySource], 2672 * Return `true` if the given [name], used in a unit of the [librarySource],
2664 * is affected by a changed top-level element, excluding classes. 2673 * is affected by a changed top-level element, excluding classes.
2665 */ 2674 */
2666 bool isChanged(Source librarySource, String name) { 2675 bool isChanged(Source librarySource, String name) {
2667 if (_isPrivateName(name)) { 2676 if (_isPrivateName(name)) {
2668 if (changedPrivateNames[librarySource]?.contains(name) ?? false) { 2677 if (changedPrivateNames[librarySource]?.contains(name) ?? false) {
(...skipping 2112 matching lines...) Expand 10 before | Expand all | Expand 10 after
4781 * that extend, mix-in, or implement it. 4790 * that extend, mix-in, or implement it.
4782 * 4791 *
4783 * If the set of member of a class is changed, these changes might change 4792 * If the set of member of a class is changed, these changes might change
4784 * the list of unimplemented inherited members in the class and classes that 4793 * the list of unimplemented inherited members in the class and classes that
4785 * extend, mix-in, or implement it. So, we might need to report (or stop 4794 * extend, mix-in, or implement it. So, we might need to report (or stop
4786 * reporting) the corresponding warning. 4795 * reporting) the corresponding warning.
4787 */ 4796 */
4788 final Map<String, Set<String>> superToSubs = <String, Set<String>>{}; 4797 final Map<String, Set<String>> superToSubs = <String, Set<String>>{};
4789 4798
4790 /** 4799 /**
4800 * The names of extended classes for which the unnamed constructor is
4801 * invoked. Because we cannot use the name of the constructor to identify
4802 * whether the unit is affected, we need to use the class name.
4803 */
4804 final Set<String> extendedUsedUnnamedConstructorNames = new Set<String>();
4805
4806 /**
4791 * The names of instantiated classes. 4807 * The names of instantiated classes.
4792 * 4808 *
4793 * If one of these classes changes its set of members, it might change 4809 * If one of these classes changes its set of members, it might change
4794 * its list of unimplemented inherited members. So, we might need to report 4810 * its list of unimplemented inherited members. So, we might need to report
4795 * (or stop reporting) the corresponding warning. 4811 * (or stop reporting) the corresponding warning.
4796 */ 4812 */
4797 final Set<String> instantiatedNames = new Set<String>(); 4813 final Set<String> instantiatedNames = new Set<String>();
4798 4814
4799 /** 4815 /**
4800 * The set of names that are referenced by the library, both inside and 4816 * The set of names that are referenced by the library, both inside and
(...skipping 15 matching lines...) Expand all
4816 } 4832 }
4817 } 4833 }
4818 4834
4819 /** 4835 /**
4820 * A builder for creating [ReferencedNames]. 4836 * A builder for creating [ReferencedNames].
4821 */ 4837 */
4822 class ReferencedNamesBuilder extends GeneralizingAstVisitor { 4838 class ReferencedNamesBuilder extends GeneralizingAstVisitor {
4823 final Set<String> importPrefixNames = new Set<String>(); 4839 final Set<String> importPrefixNames = new Set<String>();
4824 final ReferencedNames names; 4840 final ReferencedNames names;
4825 4841
4842 String enclosingSuperClassName;
4826 ReferencedNamesScope scope = new ReferencedNamesScope(null); 4843 ReferencedNamesScope scope = new ReferencedNamesScope(null);
4827 4844
4828 int localLevel = 0; 4845 int localLevel = 0;
4829 Set<String> dependsOn; 4846 Set<String> dependsOn;
4830 4847
4831 ReferencedNamesBuilder(this.names); 4848 ReferencedNamesBuilder(this.names);
4832 4849
4833 ReferencedNames build(CompilationUnit unit) { 4850 ReferencedNames build(CompilationUnit unit) {
4834 unit.accept(this); 4851 unit.accept(this);
4835 return names; 4852 return names;
4836 } 4853 }
4837 4854
4838 @override 4855 @override
4839 visitBlock(Block node) { 4856 visitBlock(Block node) {
4840 ReferencedNamesScope outerScope = scope; 4857 ReferencedNamesScope outerScope = scope;
4841 try { 4858 try {
4842 scope = new ReferencedNamesScope.forBlock(scope, node); 4859 scope = new ReferencedNamesScope.forBlock(scope, node);
4843 super.visitBlock(node); 4860 super.visitBlock(node);
4844 } finally { 4861 } finally {
4845 scope = outerScope; 4862 scope = outerScope;
4846 } 4863 }
4847 } 4864 }
4848 4865
4849 @override 4866 @override
4850 visitClassDeclaration(ClassDeclaration node) { 4867 visitClassDeclaration(ClassDeclaration node) {
4851 ReferencedNamesScope outerScope = scope; 4868 ReferencedNamesScope outerScope = scope;
4852 try { 4869 try {
4853 scope = new ReferencedNamesScope.forClass(scope, node); 4870 scope = new ReferencedNamesScope.forClass(scope, node);
4854 dependsOn = new Set<String>(); 4871 dependsOn = new Set<String>();
4872 enclosingSuperClassName =
4873 _getSimpleName(node.extendsClause?.superclass?.name);
4855 super.visitClassDeclaration(node); 4874 super.visitClassDeclaration(node);
4856 String className = node.name.name; 4875 String className = node.name.name;
4857 names.userToDependsOn[className] = dependsOn; 4876 names.userToDependsOn[className] = dependsOn;
4858 _addSuperName(className, node.extendsClause?.superclass); 4877 _addSuperName(className, node.extendsClause?.superclass);
4859 _addSuperNames(className, node.withClause?.mixinTypes); 4878 _addSuperNames(className, node.withClause?.mixinTypes);
4860 _addSuperNames(className, node.implementsClause?.interfaces); 4879 _addSuperNames(className, node.implementsClause?.interfaces);
4861 } finally { 4880 } finally {
4881 enclosingSuperClassName = null;
4862 dependsOn = null; 4882 dependsOn = null;
4863 scope = outerScope; 4883 scope = outerScope;
4864 } 4884 }
4865 } 4885 }
4866 4886
4887 static String _getSimpleName(Identifier identifier) {
4888 if (identifier is SimpleIdentifier) {
4889 return identifier.name;
4890 }
4891 if (identifier is PrefixedIdentifier) {
4892 return identifier.identifier.name;
4893 }
4894 return null;
4895 }
4896
4867 @override 4897 @override
4868 visitClassTypeAlias(ClassTypeAlias node) { 4898 visitClassTypeAlias(ClassTypeAlias node) {
4869 ReferencedNamesScope outerScope = scope; 4899 ReferencedNamesScope outerScope = scope;
4870 try { 4900 try {
4871 scope = new ReferencedNamesScope.forClassTypeAlias(scope, node); 4901 scope = new ReferencedNamesScope.forClassTypeAlias(scope, node);
4872 dependsOn = new Set<String>(); 4902 dependsOn = new Set<String>();
4873 super.visitClassTypeAlias(node); 4903 super.visitClassTypeAlias(node);
4874 String className = node.name.name; 4904 String className = node.name.name;
4875 names.userToDependsOn[className] = dependsOn; 4905 names.userToDependsOn[className] = dependsOn;
4876 _addSuperName(className, node.superclass); 4906 _addSuperName(className, node.superclass);
4877 _addSuperNames(className, node.withClause?.mixinTypes); 4907 _addSuperNames(className, node.withClause?.mixinTypes);
4878 _addSuperNames(className, node.implementsClause?.interfaces); 4908 _addSuperNames(className, node.implementsClause?.interfaces);
4879 } finally { 4909 } finally {
4880 dependsOn = null; 4910 dependsOn = null;
4881 scope = outerScope; 4911 scope = outerScope;
4882 } 4912 }
4883 } 4913 }
4884 4914
4885 @override 4915 @override
4886 visitComment(Comment node) { 4916 visitComment(Comment node) {
4887 try { 4917 try {
4888 localLevel++; 4918 localLevel++;
4889 super.visitComment(node); 4919 super.visitComment(node);
4890 } finally { 4920 } finally {
4891 localLevel--; 4921 localLevel--;
4892 } 4922 }
4893 } 4923 }
4894 4924
4895 @override 4925 @override
4926 visitSuperConstructorInvocation(SuperConstructorInvocation node) {
4927 if (node.constructorName == null && enclosingSuperClassName != null) {
4928 names.extendedUsedUnnamedConstructorNames.add(enclosingSuperClassName);
4929 }
4930 super.visitSuperConstructorInvocation(node);
4931 }
4932
4933 @override
4896 visitConstructorName(ConstructorName node) { 4934 visitConstructorName(ConstructorName node) {
4897 if (node.parent is! ConstructorDeclaration) { 4935 if (node.parent is! ConstructorDeclaration) {
4898 super.visitConstructorName(node); 4936 super.visitConstructorName(node);
4899 } 4937 }
4900 } 4938 }
4901 4939
4902 @override 4940 @override
4903 visitFunctionBody(FunctionBody node) { 4941 visitFunctionBody(FunctionBody node) {
4904 try { 4942 try {
4905 localLevel++; 4943 localLevel++;
(...skipping 1618 matching lines...) Expand 10 before | Expand all | Expand 10 after
6524 6562
6525 @override 6563 @override
6526 bool moveNext() { 6564 bool moveNext() {
6527 if (_newSources.isEmpty) { 6565 if (_newSources.isEmpty) {
6528 return false; 6566 return false;
6529 } 6567 }
6530 currentTarget = _newSources.removeLast(); 6568 currentTarget = _newSources.removeLast();
6531 return true; 6569 return true;
6532 } 6570 }
6533 } 6571 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/src/context/context_test.dart » ('j') | pkg/analyzer/test/src/context/context_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698