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

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

Issue 734403004: cleanup hints (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month 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
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 'ast.dart'; 10 import 'ast.dart';
(...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 String text = literal.stringValue; 693 String text = literal.stringValue;
694 return parseSelector(offset, text); 694 return parseSelector(offset, text);
695 } 695 }
696 } 696 }
697 697
698 /** 698 /**
699 * Instances of the class `BestPracticesVerifier` traverse an AST structure look ing for 699 * Instances of the class `BestPracticesVerifier` traverse an AST structure look ing for
700 * violations of Dart best practices. 700 * violations of Dart best practices.
701 */ 701 */
702 class BestPracticesVerifier extends RecursiveAstVisitor<Object> { 702 class BestPracticesVerifier extends RecursiveAstVisitor<Object> {
703 static String _HASHCODE_GETTER_NAME = "hashCode"; 703 // static String _HASHCODE_GETTER_NAME = "hashCode";
704 704
705 static String _NULL_TYPE_NAME = "Null"; 705 static String _NULL_TYPE_NAME = "Null";
706 706
707 static String _TO_INT_METHOD_NAME = "toInt"; 707 static String _TO_INT_METHOD_NAME = "toInt";
708 708
709 /** 709 /**
710 * The class containing the AST nodes being visited, or `null` if we are not i n the scope of 710 * The class containing the AST nodes being visited, or `null` if we are not i n the scope of
711 * a class. 711 * a class.
712 */ 712 */
713 ClassElement _enclosingClass; 713 ClassElement _enclosingClass;
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after
1247 } 1247 }
1248 1248
1249 /** 1249 /**
1250 * Check for the passed class declaration for the 1250 * Check for the passed class declaration for the
1251 * [HintCode.OVERRIDE_EQUALS_BUT_NOT_HASH_CODE] hint code. 1251 * [HintCode.OVERRIDE_EQUALS_BUT_NOT_HASH_CODE] hint code.
1252 * 1252 *
1253 * @param node the class declaration to check 1253 * @param node the class declaration to check
1254 * @return `true` if and only if a hint code is generated on the passed node 1254 * @return `true` if and only if a hint code is generated on the passed node
1255 * See [HintCode.OVERRIDE_EQUALS_BUT_NOT_HASH_CODE]. 1255 * See [HintCode.OVERRIDE_EQUALS_BUT_NOT_HASH_CODE].
1256 */ 1256 */
1257 bool _checkForOverrideEqualsButNotHashCode(ClassDeclaration node) { 1257 // bool _checkForOverrideEqualsButNotHashCode(ClassDeclaration node) {
1258 ClassElement classElement = node.element; 1258 // ClassElement classElement = node.element;
1259 if (classElement == null) { 1259 // if (classElement == null) {
1260 return false; 1260 // return false;
1261 } 1261 // }
1262 MethodElement equalsOperatorMethodElement = 1262 // MethodElement equalsOperatorMethodElement =
1263 classElement.getMethod(sc.TokenType.EQ_EQ.lexeme); 1263 // classElement.getMethod(sc.TokenType.EQ_EQ.lexeme);
1264 if (equalsOperatorMethodElement != null) { 1264 // if (equalsOperatorMethodElement != null) {
1265 PropertyAccessorElement hashCodeElement = 1265 // PropertyAccessorElement hashCodeElement =
1266 classElement.getGetter(_HASHCODE_GETTER_NAME); 1266 // classElement.getGetter(_HASHCODE_GETTER_NAME);
1267 if (hashCodeElement == null) { 1267 // if (hashCodeElement == null) {
1268 _errorReporter.reportErrorForNode( 1268 // _errorReporter.reportErrorForNode(
1269 HintCode.OVERRIDE_EQUALS_BUT_NOT_HASH_CODE, 1269 // HintCode.OVERRIDE_EQUALS_BUT_NOT_HASH_CODE,
1270 node.name, 1270 // node.name,
1271 [classElement.displayName]); 1271 // [classElement.displayName]);
1272 return true; 1272 // return true;
1273 } 1273 // }
1274 } 1274 // }
1275 return false; 1275 // return false;
1276 } 1276 // }
1277 1277
1278 /** 1278 /**
1279 * Check for the passed as expression for the [HintCode.UNNECESSARY_CAST] hint code. 1279 * Check for the passed as expression for the [HintCode.UNNECESSARY_CAST] hint code.
1280 * 1280 *
1281 * @param node the as expression to check 1281 * @param node the as expression to check
1282 * @return `true` if and only if a hint code is generated on the passed node 1282 * @return `true` if and only if a hint code is generated on the passed node
1283 * See [HintCode.UNNECESSARY_CAST]. 1283 * See [HintCode.UNNECESSARY_CAST].
1284 */ 1284 */
1285 bool _checkForUnnecessaryCast(AsExpression node) { 1285 bool _checkForUnnecessaryCast(AsExpression node) {
1286 Expression expression = node.expression; 1286 Expression expression = node.expression;
(...skipping 9987 matching lines...) Expand 10 before | Expand all | Expand 10 after
11274 // no Element 11274 // no Element
11275 return null; 11275 return null;
11276 } 11276 }
11277 } 11277 }
11278 11278
11279 /** 11279 /**
11280 * Instances of the class `PubVerifier` traverse an AST structure looking for de viations from 11280 * Instances of the class `PubVerifier` traverse an AST structure looking for de viations from
11281 * pub best practices. 11281 * pub best practices.
11282 */ 11282 */
11283 class PubVerifier extends RecursiveAstVisitor<Object> { 11283 class PubVerifier extends RecursiveAstVisitor<Object> {
11284 static String _PUBSPEC_YAML = "pubspec.yaml"; 11284 // static String _PUBSPEC_YAML = "pubspec.yaml";
11285 11285
11286 /** 11286 /**
11287 * The analysis context containing the sources to be analyzed 11287 * The analysis context containing the sources to be analyzed
11288 */ 11288 */
11289 final AnalysisContext _context; 11289 final AnalysisContext _context;
11290 11290
11291 /** 11291 /**
11292 * The error reporter by which errors will be reported. 11292 * The error reporter by which errors will be reported.
11293 */ 11293 */
11294 final ErrorReporter _errorReporter; 11294 final ErrorReporter _errorReporter;
11295 11295
11296 PubVerifier(this._context, this._errorReporter); 11296 PubVerifier(this._context, this._errorReporter);
11297 11297
11298 @override 11298 @override
11299 Object visitImportDirective(ImportDirective directive) { 11299 Object visitImportDirective(ImportDirective directive) {
11300 return null; 11300 return null;
11301 } 11301 }
11302 11302
11303 /** 11303 /**
11304 * This verifies that the passed file import directive is not contained in a s ource inside a 11304 * This verifies that the passed file import directive is not contained in a s ource inside a
11305 * package "lib" directory hierarchy referencing a source outside that package "lib" directory 11305 * package "lib" directory hierarchy referencing a source outside that package "lib" directory
11306 * hierarchy. 11306 * hierarchy.
11307 * 11307 *
11308 * @param uriLiteral the import URL (not `null`) 11308 * @param uriLiteral the import URL (not `null`)
11309 * @param path the file path being verified (not `null`) 11309 * @param path the file path being verified (not `null`)
11310 * @return `true` if and only if an error code is generated on the passed node 11310 * @return `true` if and only if an error code is generated on the passed node
11311 * See [PubSuggestionCode.FILE_IMPORT_INSIDE_LIB_REFERENCES_FILE_OUTSIDE]. 11311 * See [PubSuggestionCode.FILE_IMPORT_INSIDE_LIB_REFERENCES_FILE_OUTSIDE].
11312 */ 11312 */
11313 bool 11313 // bool
11314 _checkForFileImportInsideLibReferencesFileOutside(StringLiteral uriLiteral , 11314 // _checkForFileImportInsideLibReferencesFileOutside(StringLiteral uriLiter al,
11315 String path) { 11315 // String path) {
11316 Source source = _getSource(uriLiteral); 11316 // Source source = _getSource(uriLiteral);
11317 String fullName = _getSourceFullName(source); 11317 // String fullName = _getSourceFullName(source);
11318 if (fullName != null) { 11318 // if (fullName != null) {
11319 int pathIndex = 0; 11319 // int pathIndex = 0;
11320 int fullNameIndex = fullName.length; 11320 // int fullNameIndex = fullName.length;
11321 while (pathIndex < path.length && 11321 // while (pathIndex < path.length &&
11322 StringUtilities.startsWith3(path, pathIndex, 0x2E, 0x2E, 0x2F)) { 11322 // StringUtilities.startsWith3(path, pathIndex, 0x2E, 0x2E, 0x2F)) {
11323 fullNameIndex = JavaString.lastIndexOf(fullName, '/', fullNameIndex); 11323 // fullNameIndex = JavaString.lastIndexOf(fullName, '/', fullNameIndex);
11324 if (fullNameIndex < 4) { 11324 // if (fullNameIndex < 4) {
11325 return false; 11325 // return false;
11326 } 11326 // }
11327 // Check for "/lib" at a specified place in the fullName 11327 // // Check for "/lib" at a specified place in the fullName
11328 if (StringUtilities.startsWith4( 11328 // if (StringUtilities.startsWith4(
11329 fullName, 11329 // fullName,
11330 fullNameIndex - 4, 11330 // fullNameIndex - 4,
11331 0x2F, 11331 // 0x2F,
11332 0x6C, 11332 // 0x6C,
11333 0x69, 11333 // 0x69,
11334 0x62)) { 11334 // 0x62)) {
11335 String relativePubspecPath = 11335 // String relativePubspecPath =
11336 path.substring(0, pathIndex + 3) + 11336 // path.substring(0, pathIndex + 3) +
11337 _PUBSPEC_YAML; 11337 // _PUBSPEC_YAML;
11338 Source pubspecSource = 11338 // Source pubspecSource =
11339 _context.sourceFactory.resolveUri(source, relativePubspecPath); 11339 // _context.sourceFactory.resolveUri(source, relativePubspecPath);
11340 if (_context.exists(pubspecSource)) { 11340 // if (_context.exists(pubspecSource)) {
11341 // Files inside the lib directory hierarchy should not reference 11341 // // Files inside the lib directory hierarchy should not reference
11342 // files outside 11342 // // files outside
11343 _errorReporter.reportErrorForNode( 11343 // _errorReporter.reportErrorForNode(
11344 HintCode.FILE_IMPORT_INSIDE_LIB_REFERENCES_FILE_OUTSIDE, 11344 // HintCode.FILE_IMPORT_INSIDE_LIB_REFERENCES_FILE_OUTSIDE,
11345 uriLiteral); 11345 // uriLiteral);
11346 } 11346 // }
11347 return true; 11347 // return true;
11348 } 11348 // }
11349 pathIndex += 3; 11349 // pathIndex += 3;
11350 } 11350 // }
11351 } 11351 // }
11352 return false; 11352 // return false;
11353 } 11353 // }
11354 11354
11355 /** 11355 /**
11356 * This verifies that the passed file import directive is not contained in a s ource outside a 11356 * This verifies that the passed file import directive is not contained in a s ource outside a
11357 * package "lib" directory hierarchy referencing a source inside that package "lib" directory 11357 * package "lib" directory hierarchy referencing a source inside that package "lib" directory
11358 * hierarchy. 11358 * hierarchy.
11359 * 11359 *
11360 * @param uriLiteral the import URL (not `null`) 11360 * @param uriLiteral the import URL (not `null`)
11361 * @param path the file path being verified (not `null`) 11361 * @param path the file path being verified (not `null`)
11362 * @return `true` if and only if an error code is generated on the passed node 11362 * @return `true` if and only if an error code is generated on the passed node
11363 * See [PubSuggestionCode.FILE_IMPORT_OUTSIDE_LIB_REFERENCES_FILE_INSIDE]. 11363 * See [PubSuggestionCode.FILE_IMPORT_OUTSIDE_LIB_REFERENCES_FILE_INSIDE].
11364 */ 11364 */
11365 bool 11365 // bool
11366 _checkForFileImportOutsideLibReferencesFileInside(StringLiteral uriLiteral , 11366 // _checkForFileImportOutsideLibReferencesFileInside(StringLiteral uriLiter al,
11367 String path) { 11367 // String path) {
11368 if (StringUtilities.startsWith4(path, 0, 0x6C, 0x69, 0x62, 0x2F)) { 11368 // if (StringUtilities.startsWith4(path, 0, 0x6C, 0x69, 0x62, 0x2F)) {
11369 if (_checkForFileImportOutsideLibReferencesFileInsideAtIndex( 11369 // if (_checkForFileImportOutsideLibReferencesFileInsideAtIndex(
11370 uriLiteral, 11370 // uriLiteral,
11371 path, 11371 // path,
11372 0)) { 11372 // 0)) {
11373 return true; 11373 // return true;
11374 } 11374 // }
11375 } 11375 // }
11376 int pathIndex = 11376 // int pathIndex =
11377 StringUtilities.indexOf5(path, 0, 0x2F, 0x6C, 0x69, 0x62, 0x2F); 11377 // StringUtilities.indexOf5(path, 0, 0x2F, 0x6C, 0x69, 0x62, 0x2F);
11378 while (pathIndex != -1) { 11378 // while (pathIndex != -1) {
11379 if (_checkForFileImportOutsideLibReferencesFileInsideAtIndex( 11379 // if (_checkForFileImportOutsideLibReferencesFileInsideAtIndex(
11380 uriLiteral, 11380 // uriLiteral,
11381 path, 11381 // path,
11382 pathIndex + 1)) { 11382 // pathIndex + 1)) {
11383 return true; 11383 // return true;
11384 } 11384 // }
11385 pathIndex = 11385 // pathIndex =
11386 StringUtilities.indexOf5(path, pathIndex + 4, 0x2F, 0x6C, 0x69, 0x62, 0x2F); 11386 // StringUtilities.indexOf5(path, pathIndex + 4, 0x2F, 0x6C, 0x69, 0x62 , 0x2F);
11387 } 11387 // }
11388 return false; 11388 // return false;
11389 } 11389 // }
11390 11390
11391 bool 11391 // bool
11392 _checkForFileImportOutsideLibReferencesFileInsideAtIndex(StringLiteral uri Literal, 11392 // _checkForFileImportOutsideLibReferencesFileInsideAtIndex(StringLiteral u riLiteral,
11393 String path, int pathIndex) { 11393 // String path, int pathIndex) {
11394 Source source = _getSource(uriLiteral); 11394 // Source source = _getSource(uriLiteral);
11395 String relativePubspecPath = path.substring(0, pathIndex) + _PUBSPEC_YAML; 11395 // String relativePubspecPath = path.substring(0, pathIndex) + _PUBSPEC_YAML;
11396 Source pubspecSource = 11396 // Source pubspecSource =
11397 _context.sourceFactory.resolveUri(source, relativePubspecPath); 11397 // _context.sourceFactory.resolveUri(source, relativePubspecPath);
11398 if (!_context.exists(pubspecSource)) { 11398 // if (!_context.exists(pubspecSource)) {
11399 return false; 11399 // return false;
11400 } 11400 // }
11401 String fullName = _getSourceFullName(source); 11401 // String fullName = _getSourceFullName(source);
11402 if (fullName != null) { 11402 // if (fullName != null) {
11403 if (StringUtilities.indexOf5(fullName, 0, 0x2F, 0x6C, 0x69, 0x62, 0x2F) < 11403 // if (StringUtilities.indexOf5(fullName, 0, 0x2F, 0x6C, 0x69, 0x62, 0x2F) <
11404 0) { 11404 // 0) {
11405 // Files outside the lib directory hierarchy should not reference files 11405 // // Files outside the lib directory hierarchy should not reference file s
11406 // inside ... use package: url instead 11406 // // inside ... use package: url instead
11407 _errorReporter.reportErrorForNode( 11407 // _errorReporter.reportErrorForNode(
11408 HintCode.FILE_IMPORT_OUTSIDE_LIB_REFERENCES_FILE_INSIDE, 11408 // HintCode.FILE_IMPORT_OUTSIDE_LIB_REFERENCES_FILE_INSIDE,
11409 uriLiteral); 11409 // uriLiteral);
11410 return true; 11410 // return true;
11411 } 11411 // }
11412 } 11412 // }
11413 return false; 11413 // return false;
11414 } 11414 // }
11415 11415
11416 /** 11416 /**
11417 * This verifies that the passed package import directive does not contain ".. " 11417 * This verifies that the passed package import directive does not contain ".. "
11418 * 11418 *
11419 * @param uriLiteral the import URL (not `null`) 11419 * @param uriLiteral the import URL (not `null`)
11420 * @param path the path to be validated (not `null`) 11420 * @param path the path to be validated (not `null`)
11421 * @return `true` if and only if an error code is generated on the passed node 11421 * @return `true` if and only if an error code is generated on the passed node
11422 * See [PubSuggestionCode.PACKAGE_IMPORT_CONTAINS_DOT_DOT]. 11422 * See [PubSuggestionCode.PACKAGE_IMPORT_CONTAINS_DOT_DOT].
11423 */ 11423 */
11424 bool _checkForPackageImportContainsDotDot(StringLiteral uriLiteral, 11424 // bool _checkForPackageImportContainsDotDot(StringLiteral uriLiteral,
11425 String path) { 11425 // String path) {
11426 if (StringUtilities.startsWith3(path, 0, 0x2E, 0x2E, 0x2F) || 11426 // if (StringUtilities.startsWith3(path, 0, 0x2E, 0x2E, 0x2F) ||
11427 StringUtilities.indexOf4(path, 0, 0x2F, 0x2E, 0x2E, 0x2F) >= 0) { 11427 // StringUtilities.indexOf4(path, 0, 0x2F, 0x2E, 0x2E, 0x2F) >= 0) {
11428 // Package import should not to contain ".." 11428 // // Package import should not to contain ".."
11429 _errorReporter.reportErrorForNode( 11429 // _errorReporter.reportErrorForNode(
11430 HintCode.PACKAGE_IMPORT_CONTAINS_DOT_DOT, 11430 // HintCode.PACKAGE_IMPORT_CONTAINS_DOT_DOT,
11431 uriLiteral); 11431 // uriLiteral);
11432 return true; 11432 // return true;
11433 } 11433 // }
11434 return false; 11434 // return false;
11435 } 11435 // }
11436 11436
11437 /** 11437 /**
11438 * Answer the source associated with the compilation unit containing the given AST node. 11438 * Answer the source associated with the compilation unit containing the given AST node.
11439 * 11439 *
11440 * @param node the node (not `null`) 11440 * @param node the node (not `null`)
11441 * @return the source or `null` if it could not be determined 11441 * @return the source or `null` if it could not be determined
11442 */ 11442 */
11443 Source _getSource(AstNode node) { 11443 // Source _getSource(AstNode node) {
11444 Source source = null; 11444 // Source source = null;
11445 CompilationUnit unit = node.getAncestor((node) => node is CompilationUnit); 11445 // CompilationUnit unit = node.getAncestor((node) => node is CompilationUnit) ;
11446 if (unit != null) { 11446 // if (unit != null) {
11447 CompilationUnitElement element = unit.element; 11447 // CompilationUnitElement element = unit.element;
11448 if (element != null) { 11448 // if (element != null) {
11449 source = element.source; 11449 // source = element.source;
11450 } 11450 // }
11451 } 11451 // }
11452 return source; 11452 // return source;
11453 } 11453 // }
11454 11454
11455 /** 11455 /**
11456 * Answer the full name of the given source. The returned value will have all 11456 * Answer the full name of the given source. The returned value will have all
11457 * [File.separatorChar] replace by '/'. 11457 * [File.separatorChar] replace by '/'.
11458 * 11458 *
11459 * @param source the source 11459 * @param source the source
11460 * @return the full name or `null` if it could not be determined 11460 * @return the full name or `null` if it could not be determined
11461 */ 11461 */
11462 String _getSourceFullName(Source source) { 11462 // String _getSourceFullName(Source source) {
11463 if (source != null) { 11463 // if (source != null) {
11464 String fullName = source.fullName; 11464 // String fullName = source.fullName;
11465 if (fullName != null) { 11465 // if (fullName != null) {
11466 return fullName.replaceAll(r'\', '/'); 11466 // return fullName.replaceAll(r'\', '/');
11467 } 11467 // }
11468 } 11468 // }
11469 return null; 11469 // return null;
11470 } 11470 // }
11471 } 11471 }
11472 11472
11473 class RecursiveAstVisitor_AngularCompilationUnitBuilder_parseViews extends 11473 class RecursiveAstVisitor_AngularCompilationUnitBuilder_parseViews extends
11474 RecursiveAstVisitor<Object> { 11474 RecursiveAstVisitor<Object> {
11475 List<AngularViewElement> views; 11475 List<AngularViewElement> views;
11476 11476
11477 RecursiveAstVisitor_AngularCompilationUnitBuilder_parseViews(this.views) 11477 RecursiveAstVisitor_AngularCompilationUnitBuilder_parseViews(this.views)
11478 : super(); 11478 : super();
11479 11479
11480 @override 11480 @override
(...skipping 5716 matching lines...) Expand 10 before | Expand all | Expand 10 after
17197 * library. 17197 * library.
17198 */ 17198 */
17199 final HashSet<String> members = new HashSet<String>(); 17199 final HashSet<String> members = new HashSet<String>();
17200 17200
17201 /** 17201 /**
17202 * Names of resolved or unresolved class members that are read in the 17202 * Names of resolved or unresolved class members that are read in the
17203 * library. 17203 * library.
17204 */ 17204 */
17205 final HashSet<String> readMembers = new HashSet<String>(); 17205 final HashSet<String> readMembers = new HashSet<String>();
17206 } 17206 }
OLDNEW
« pkg/analyzer/lib/src/generated/engine.dart ('K') | « pkg/analyzer/lib/src/generated/engine.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698