| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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.generated.resolver; | 5 library analyzer.src.generated.resolver; |
| 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 1900 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1911 return null; | 1911 return null; |
| 1912 } | 1912 } |
| 1913 } | 1913 } |
| 1914 } | 1914 } |
| 1915 return super.visitConditionalExpression(node); | 1915 return super.visitConditionalExpression(node); |
| 1916 } | 1916 } |
| 1917 | 1917 |
| 1918 @override | 1918 @override |
| 1919 Object visitExportDirective(ExportDirective node) { | 1919 Object visitExportDirective(ExportDirective node) { |
| 1920 ExportElement exportElement = node.element; | 1920 ExportElement exportElement = node.element; |
| 1921 if (exportElement != null && exportElement.uriExists) { | 1921 if (exportElement != null) { |
| 1922 // The element is null when the URI is invalid | 1922 // The element is null when the URI is invalid |
| 1923 LibraryElement library = exportElement.exportedLibrary; | 1923 LibraryElement library = exportElement.exportedLibrary; |
| 1924 if (library != null) { | 1924 if (library != null && !library.isSynthetic) { |
| 1925 for (Combinator combinator in node.combinators) { | 1925 for (Combinator combinator in node.combinators) { |
| 1926 _checkCombinator(exportElement.exportedLibrary, combinator); | 1926 _checkCombinator(exportElement.exportedLibrary, combinator); |
| 1927 } | 1927 } |
| 1928 } | 1928 } |
| 1929 } | 1929 } |
| 1930 return super.visitExportDirective(node); | 1930 return super.visitExportDirective(node); |
| 1931 } | 1931 } |
| 1932 | 1932 |
| 1933 @override | 1933 @override |
| 1934 Object visitIfStatement(IfStatement node) { | 1934 Object visitIfStatement(IfStatement node) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1955 return null; | 1955 return null; |
| 1956 } | 1956 } |
| 1957 } | 1957 } |
| 1958 } | 1958 } |
| 1959 return super.visitIfStatement(node); | 1959 return super.visitIfStatement(node); |
| 1960 } | 1960 } |
| 1961 | 1961 |
| 1962 @override | 1962 @override |
| 1963 Object visitImportDirective(ImportDirective node) { | 1963 Object visitImportDirective(ImportDirective node) { |
| 1964 ImportElement importElement = node.element; | 1964 ImportElement importElement = node.element; |
| 1965 if (importElement != null && importElement.uriExists) { | 1965 if (importElement != null) { |
| 1966 // The element is null when the URI is invalid, but not when the URI is | 1966 // The element is null when the URI is invalid, but not when the URI is |
| 1967 // valid but refers to a non-existent file. | 1967 // valid but refers to a non-existent file. |
| 1968 LibraryElement library = importElement.importedLibrary; | 1968 LibraryElement library = importElement.importedLibrary; |
| 1969 if (library != null) { | 1969 if (library != null && !library.isSynthetic) { |
| 1970 for (Combinator combinator in node.combinators) { | 1970 for (Combinator combinator in node.combinators) { |
| 1971 _checkCombinator(library, combinator); | 1971 _checkCombinator(library, combinator); |
| 1972 } | 1972 } |
| 1973 } | 1973 } |
| 1974 } | 1974 } |
| 1975 return super.visitImportDirective(node); | 1975 return super.visitImportDirective(node); |
| 1976 } | 1976 } |
| 1977 | 1977 |
| 1978 @override | 1978 @override |
| 1979 Object visitSwitchCase(SwitchCase node) { | 1979 Object visitSwitchCase(SwitchCase node) { |
| (...skipping 2465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4445 void generateUnusedImportHints(ErrorReporter errorReporter) { | 4445 void generateUnusedImportHints(ErrorReporter errorReporter) { |
| 4446 int length = _unusedImports.length; | 4446 int length = _unusedImports.length; |
| 4447 for (int i = 0; i < length; i++) { | 4447 for (int i = 0; i < length; i++) { |
| 4448 ImportDirective unusedImport = _unusedImports[i]; | 4448 ImportDirective unusedImport = _unusedImports[i]; |
| 4449 // Check that the imported URI exists and isn't dart:core | 4449 // Check that the imported URI exists and isn't dart:core |
| 4450 ImportElement importElement = unusedImport.element; | 4450 ImportElement importElement = unusedImport.element; |
| 4451 if (importElement != null) { | 4451 if (importElement != null) { |
| 4452 LibraryElement libraryElement = importElement.importedLibrary; | 4452 LibraryElement libraryElement = importElement.importedLibrary; |
| 4453 if (libraryElement == null || | 4453 if (libraryElement == null || |
| 4454 libraryElement.isDartCore || | 4454 libraryElement.isDartCore || |
| 4455 !importElement.uriExists) { | 4455 libraryElement.isSynthetic) { |
| 4456 continue; | 4456 continue; |
| 4457 } | 4457 } |
| 4458 } | 4458 } |
| 4459 errorReporter.reportErrorForNode( | 4459 errorReporter.reportErrorForNode( |
| 4460 HintCode.UNUSED_IMPORT, unusedImport.uri); | 4460 HintCode.UNUSED_IMPORT, unusedImport.uri); |
| 4461 } | 4461 } |
| 4462 } | 4462 } |
| 4463 | 4463 |
| 4464 /** | 4464 /** |
| 4465 * Report an [HintCode.UNUSED_SHOWN_NAME] hint for each unused shown name. | 4465 * Report an [HintCode.UNUSED_SHOWN_NAME] hint for each unused shown name. |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4903 } | 4903 } |
| 4904 | 4904 |
| 4905 /** | 4905 /** |
| 4906 * Clear the type information assocated with [node]. | 4906 * Clear the type information assocated with [node]. |
| 4907 */ | 4907 */ |
| 4908 static void clearType(AstNode node) { | 4908 static void clearType(AstNode node) { |
| 4909 node?.setProperty(_typeProperty, null); | 4909 node?.setProperty(_typeProperty, null); |
| 4910 } | 4910 } |
| 4911 | 4911 |
| 4912 /** | 4912 /** |
| 4913 * Look for contextual type information attached to [node]. Returns |
| 4914 * the type if found, otherwise null. |
| 4915 * |
| 4916 * If [node] has a contextual union type like `T | Future<T>` this will be |
| 4917 * returned. You can use [getType] if you prefer to only get the `T`. |
| 4918 */ |
| 4919 static DartType getContext(AstNode node) => node?.getProperty(_typeProperty); |
| 4920 |
| 4921 /** |
| 4913 * Look for a single contextual type attached to [node], and returns the type | 4922 * Look for a single contextual type attached to [node], and returns the type |
| 4914 * if found, otherwise null. | 4923 * if found, otherwise null. |
| 4915 * | 4924 * |
| 4916 * If [node] has a contextual union type like `T | Future<T>` this will | 4925 * If [node] has a contextual union type like `T | Future<T>` this will |
| 4917 * simplify it to only return `T`. If the caller can handle a union type, | 4926 * simplify it to only return `T`. If the caller can handle a union type, |
| 4918 * [getContext] should be used instead. | 4927 * [getContext] should be used instead. |
| 4919 */ | 4928 */ |
| 4920 static DartType getType(AstNode node) { | 4929 static DartType getType(AstNode node) { |
| 4921 DartType t = getContext(node); | 4930 DartType t = getContext(node); |
| 4922 if (t is FutureUnionType) { | 4931 if (t is FutureUnionType) { |
| 4923 return t.type; | 4932 return t.type; |
| 4924 } | 4933 } |
| 4925 return t; | 4934 return t; |
| 4926 } | 4935 } |
| 4927 | 4936 |
| 4928 /** | 4937 /** |
| 4929 * Look for contextual type information attached to [node]. Returns | |
| 4930 * the type if found, otherwise null. | |
| 4931 * | |
| 4932 * If [node] has a contextual union type like `T | Future<T>` this will be | |
| 4933 * returned. You can use [getType] if you prefer to only get the `T`. | |
| 4934 */ | |
| 4935 static DartType getContext(AstNode node) => node?.getProperty(_typeProperty); | |
| 4936 | |
| 4937 /** | |
| 4938 * Like [getContext] but expands a union type into a list of types. | 4938 * Like [getContext] but expands a union type into a list of types. |
| 4939 */ | 4939 */ |
| 4940 static Iterable<DartType> getTypes(AstNode node) { | 4940 static Iterable<DartType> getTypes(AstNode node) { |
| 4941 DartType t = getContext(node); | 4941 DartType t = getContext(node); |
| 4942 if (t == null) { | 4942 if (t == null) { |
| 4943 return DartType.EMPTY_LIST; | 4943 return DartType.EMPTY_LIST; |
| 4944 } | 4944 } |
| 4945 if (t is FutureUnionType) { | 4945 if (t is FutureUnionType) { |
| 4946 return t.types; | 4946 return t.types; |
| 4947 } | 4947 } |
| (...skipping 6157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11105 return null; | 11105 return null; |
| 11106 } | 11106 } |
| 11107 if (identical(node.staticElement, variable)) { | 11107 if (identical(node.staticElement, variable)) { |
| 11108 if (node.inSetterContext()) { | 11108 if (node.inSetterContext()) { |
| 11109 result = true; | 11109 result = true; |
| 11110 } | 11110 } |
| 11111 } | 11111 } |
| 11112 return null; | 11112 return null; |
| 11113 } | 11113 } |
| 11114 } | 11114 } |
| OLD | NEW |