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

Side by Side Diff: pkg/analyzer/lib/src/generated/resolver.dart

Issue 1053013004: Rename UsedElements -> UsedLocalElements. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | 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) 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 engine.resolver; 5 library engine.resolver;
6 6
7 import "dart:math" as math; 7 import "dart:math" as math;
8 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import 'package:analyzer/src/generated/utilities_collection.dart'; 10 import 'package:analyzer/src/generated/utilities_collection.dart';
(...skipping 4332 matching lines...) Expand 10 before | Expand all | Expand 10 after
4343 */ 4343 */
4344 void _defineTypeParameters() { 4344 void _defineTypeParameters() {
4345 Scope typeParameterScope = enclosingScope; 4345 Scope typeParameterScope = enclosingScope;
4346 for (TypeParameterElement typeParameter in _typeElement.typeParameters) { 4346 for (TypeParameterElement typeParameter in _typeElement.typeParameters) {
4347 typeParameterScope.define(typeParameter); 4347 typeParameterScope.define(typeParameter);
4348 } 4348 }
4349 } 4349 }
4350 } 4350 }
4351 4351
4352 /** 4352 /**
4353 * An [AstVisitor] that fills [UsedElements]. 4353 * An [AstVisitor] that fills [UsedLocalElements].
4354 */ 4354 */
4355 class GatherUsedElementsVisitor extends RecursiveAstVisitor { 4355 class GatherUsedLocalElementsVisitor extends RecursiveAstVisitor {
4356 final UsedElements usedElements = new UsedElements(); 4356 final UsedLocalElements usedElements = new UsedLocalElements();
4357 4357
4358 final LibraryElement _enclosingLibrary; 4358 final LibraryElement _enclosingLibrary;
4359 ClassElement _enclosingClass; 4359 ClassElement _enclosingClass;
4360 ExecutableElement _enclosingExec; 4360 ExecutableElement _enclosingExec;
4361 4361
4362 GatherUsedElementsVisitor(this._enclosingLibrary); 4362 GatherUsedLocalElementsVisitor(this._enclosingLibrary);
4363 4363
4364 @override 4364 @override
4365 visitCatchClause(CatchClause node) { 4365 visitCatchClause(CatchClause node) {
4366 SimpleIdentifier exceptionParameter = node.exceptionParameter; 4366 SimpleIdentifier exceptionParameter = node.exceptionParameter;
4367 SimpleIdentifier stackTraceParameter = node.stackTraceParameter; 4367 SimpleIdentifier stackTraceParameter = node.stackTraceParameter;
4368 if (exceptionParameter != null) { 4368 if (exceptionParameter != null) {
4369 Element element = exceptionParameter.staticElement; 4369 Element element = exceptionParameter.staticElement;
4370 usedElements.addCatchException(element); 4370 usedElements.addCatchException(element);
4371 if (stackTraceParameter != null || node.onKeyword == null) { 4371 if (stackTraceParameter != null || node.onKeyword == null) {
4372 usedElements.addElement(element); 4372 usedElements.addElement(element);
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
4519 4519
4520 ImportsVerifier _importsVerifier; 4520 ImportsVerifier _importsVerifier;
4521 4521
4522 bool _enableDart2JSHints = false; 4522 bool _enableDart2JSHints = false;
4523 4523
4524 /** 4524 /**
4525 * The inheritance manager used to find overridden methods. 4525 * The inheritance manager used to find overridden methods.
4526 */ 4526 */
4527 InheritanceManager _manager; 4527 InheritanceManager _manager;
4528 4528
4529 GatherUsedElementsVisitor _usedElementsVisitor; 4529 GatherUsedLocalElementsVisitor _usedElementsVisitor;
4530 4530
4531 HintGenerator(this._compilationUnits, this._context, this._errorListener) { 4531 HintGenerator(this._compilationUnits, this._context, this._errorListener) {
4532 _library = _compilationUnits[0].element.library; 4532 _library = _compilationUnits[0].element.library;
4533 _importsVerifier = new ImportsVerifier(_library); 4533 _importsVerifier = new ImportsVerifier(_library);
4534 _enableDart2JSHints = _context.analysisOptions.dart2jsHint; 4534 _enableDart2JSHints = _context.analysisOptions.dart2jsHint;
4535 _manager = new InheritanceManager(_compilationUnits[0].element.library); 4535 _manager = new InheritanceManager(_compilationUnits[0].element.library);
4536 _usedElementsVisitor = new GatherUsedElementsVisitor(_library); 4536 _usedElementsVisitor = new GatherUsedLocalElementsVisitor(_library);
4537 } 4537 }
4538 4538
4539 void generateForLibrary() { 4539 void generateForLibrary() {
4540 PerformanceStatistics.hints.makeCurrentWhile(() { 4540 PerformanceStatistics.hints.makeCurrentWhile(() {
4541 for (int i = 0; i < _compilationUnits.length; i++) { 4541 for (int i = 0; i < _compilationUnits.length; i++) {
4542 CompilationUnitElement element = _compilationUnits[i].element; 4542 CompilationUnitElement element = _compilationUnits[i].element;
4543 if (element != null) { 4543 if (element != null) {
4544 if (i == 0) { 4544 if (i == 0) {
4545 _importsVerifier.inDefiningCompilationUnit = true; 4545 _importsVerifier.inDefiningCompilationUnit = true;
4546 _generateForCompilationUnit(_compilationUnits[i], element.source); 4546 _generateForCompilationUnit(_compilationUnits[i], element.source);
4547 _importsVerifier.inDefiningCompilationUnit = false; 4547 _importsVerifier.inDefiningCompilationUnit = false;
4548 } else { 4548 } else {
4549 _generateForCompilationUnit(_compilationUnits[i], element.source); 4549 _generateForCompilationUnit(_compilationUnits[i], element.source);
4550 } 4550 }
4551 } 4551 }
4552 } 4552 }
4553 ErrorReporter definingCompilationUnitErrorReporter = new ErrorReporter( 4553 ErrorReporter definingCompilationUnitErrorReporter = new ErrorReporter(
4554 _errorListener, _compilationUnits[0].element.source); 4554 _errorListener, _compilationUnits[0].element.source);
4555 _importsVerifier 4555 _importsVerifier
4556 .generateDuplicateImportHints(definingCompilationUnitErrorReporter); 4556 .generateDuplicateImportHints(definingCompilationUnitErrorReporter);
4557 _importsVerifier 4557 _importsVerifier
4558 .generateUnusedImportHints(definingCompilationUnitErrorReporter); 4558 .generateUnusedImportHints(definingCompilationUnitErrorReporter);
4559 _library.accept(new UnusedElementsVerifier( 4559 _library.accept(new UnusedLocalElementsVerifier(
4560 _errorListener, _usedElementsVisitor.usedElements)); 4560 _errorListener, _usedElementsVisitor.usedElements));
4561 }); 4561 });
4562 } 4562 }
4563 4563
4564 void _generateForCompilationUnit(CompilationUnit unit, Source source) { 4564 void _generateForCompilationUnit(CompilationUnit unit, Source source) {
4565 ErrorReporter errorReporter = new ErrorReporter(_errorListener, source); 4565 ErrorReporter errorReporter = new ErrorReporter(_errorListener, source);
4566 unit.accept(_importsVerifier); 4566 unit.accept(_importsVerifier);
4567 // dead code analysis 4567 // dead code analysis
4568 unit.accept(new DeadCodeVerifier(errorReporter)); 4568 unit.accept(new DeadCodeVerifier(errorReporter));
4569 unit.accept(_usedElementsVisitor); 4569 unit.accept(_usedElementsVisitor);
(...skipping 10373 matching lines...) Expand 10 before | Expand all | Expand 10 after
14943 return identical(parent.type, node); 14943 return identical(parent.type, node);
14944 } 14944 }
14945 if (parent is SimpleFormalParameter) { 14945 if (parent is SimpleFormalParameter) {
14946 return identical(parent.type, node); 14946 return identical(parent.type, node);
14947 } 14947 }
14948 return false; 14948 return false;
14949 } 14949 }
14950 } 14950 }
14951 14951
14952 /** 14952 /**
14953 * Instances of the class [UnusedElementsVerifier] traverse an element 14953 * Instances of the class [UnusedLocalElementsVerifier] traverse an element
14954 * structure looking for cases of [HintCode.UNUSED_ELEMENT] and 14954 * structure looking for cases of [HintCode.UNUSED_ELEMENT],
14955 * [HintCode.UNUSED_LOCAL_VARIABLE]. 14955 * [HintCode.UNUSED_FIELD], [HintCode.UNUSED_LOCAL_VARIABLE], etc.
14956 */ 14956 */
14957 class UnusedElementsVerifier extends RecursiveElementVisitor { 14957 class UnusedLocalElementsVerifier extends RecursiveElementVisitor {
14958 /** 14958 /**
14959 * The error listener to which errors will be reported. 14959 * The error listener to which errors will be reported.
14960 */ 14960 */
14961 final AnalysisErrorListener _errorListener; 14961 final AnalysisErrorListener _errorListener;
14962 14962
14963 /** 14963 /**
14964 * The elements know to be used. 14964 * The elements know to be used.
14965 */ 14965 */
14966 final UsedElements _usedElements; 14966 final UsedLocalElements _usedElements;
14967 14967
14968 /** 14968 /**
14969 * Create a new instance of the [UnusedElementsVerifier]. 14969 * Create a new instance of the [UnusedLocalElementsVerifier].
14970 */ 14970 */
14971 UnusedElementsVerifier(this._errorListener, this._usedElements); 14971 UnusedLocalElementsVerifier(this._errorListener, this._usedElements);
14972 14972
14973 @override 14973 @override
14974 visitClassElement(ClassElement element) { 14974 visitClassElement(ClassElement element) {
14975 if (!_isUsedElement(element)) { 14975 if (!_isUsedElement(element)) {
14976 _reportErrorForElement(HintCode.UNUSED_ELEMENT, element, [ 14976 _reportErrorForElement(HintCode.UNUSED_ELEMENT, element, [
14977 element.kind.displayName, 14977 element.kind.displayName,
14978 element.displayName 14978 element.displayName
14979 ]); 14979 ]);
14980 } 14980 }
14981 super.visitClassElement(element); 14981 super.visitClassElement(element);
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
15095 if (element != null) { 15095 if (element != null) {
15096 _errorListener.onError(new AnalysisError.con2(element.source, 15096 _errorListener.onError(new AnalysisError.con2(element.source,
15097 element.nameOffset, element.displayName.length, errorCode, 15097 element.nameOffset, element.displayName.length, errorCode,
15098 arguments)); 15098 arguments));
15099 } 15099 }
15100 } 15100 }
15101 } 15101 }
15102 15102
15103 /** 15103 /**
15104 * A container with sets of used [Element]s. 15104 * A container with sets of used [Element]s.
15105 * All these elements are defined in a single compilation unit or a library.
15105 */ 15106 */
15106 class UsedElements { 15107 class UsedLocalElements {
15107 /** 15108 /**
15108 * Resolved, locally defined elements that are used or potentially can be 15109 * Resolved, locally defined elements that are used or potentially can be
15109 * used. 15110 * used.
15110 */ 15111 */
15111 final HashSet<Element> elements = new HashSet<Element>(); 15112 final HashSet<Element> elements = new HashSet<Element>();
15112 15113
15113 /** 15114 /**
15114 * [LocalVariableElement]s that represent exceptions in [CatchClause]s. 15115 * [LocalVariableElement]s that represent exceptions in [CatchClause]s.
15115 */ 15116 */
15116 final HashSet<LocalVariableElement> catchExceptionElements = 15117 final HashSet<LocalVariableElement> catchExceptionElements =
(...skipping 10 matching lines...) Expand all
15127 * library. 15128 * library.
15128 */ 15129 */
15129 final HashSet<String> members = new HashSet<String>(); 15130 final HashSet<String> members = new HashSet<String>();
15130 15131
15131 /** 15132 /**
15132 * Names of resolved or unresolved class members that are read in the 15133 * Names of resolved or unresolved class members that are read in the
15133 * library. 15134 * library.
15134 */ 15135 */
15135 final HashSet<String> readMembers = new HashSet<String>(); 15136 final HashSet<String> readMembers = new HashSet<String>();
15136 15137
15137 UsedElements(); 15138 UsedLocalElements();
15138 15139
15139 factory UsedElements.merge(List<UsedElements> parts) { 15140 factory UsedLocalElements.merge(List<UsedLocalElements> parts) {
15140 UsedElements result = new UsedElements(); 15141 UsedLocalElements result = new UsedLocalElements();
15141 for (UsedElements part in parts) { 15142 for (UsedLocalElements part in parts) {
15142 result.elements.addAll(part.elements); 15143 result.elements.addAll(part.elements);
15143 result.catchExceptionElements.addAll(part.catchExceptionElements); 15144 result.catchExceptionElements.addAll(part.catchExceptionElements);
15144 result.catchStackTraceElements.addAll(part.catchStackTraceElements); 15145 result.catchStackTraceElements.addAll(part.catchStackTraceElements);
15145 result.members.addAll(part.members); 15146 result.members.addAll(part.members);
15146 result.readMembers.addAll(part.readMembers); 15147 result.readMembers.addAll(part.readMembers);
15147 } 15148 }
15148 return result; 15149 return result;
15149 } 15150 }
15150 15151
15151 void addCatchException(LocalVariableElement element) { 15152 void addCatchException(LocalVariableElement element) {
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
15483 nonFields.add(node); 15484 nonFields.add(node);
15484 return null; 15485 return null;
15485 } 15486 }
15486 15487
15487 @override 15488 @override
15488 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); 15489 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this);
15489 15490
15490 @override 15491 @override
15491 Object visitWithClause(WithClause node) => null; 15492 Object visitWithClause(WithClause node) => null;
15492 } 15493 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/task/dart.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698