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

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

Issue 1372673003: Use Element.nameLength where possible. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 2 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
« no previous file with comments | « pkg/analyzer/lib/src/generated/error_verifier.dart ('k') | no next file » | 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:collection'; 7 import 'dart:collection';
8 8
9 import 'ast.dart'; 9 import 'ast.dart';
10 import 'constant.dart'; 10 import 'constant.dart';
(...skipping 745 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 _defineMembers(typeElement); 756 _defineMembers(typeElement);
757 } 757 }
758 758
759 @override 759 @override
760 AnalysisError getErrorForDuplicate(Element existing, Element duplicate) { 760 AnalysisError getErrorForDuplicate(Element existing, Element duplicate) {
761 if (existing is PropertyAccessorElement && duplicate is MethodElement) { 761 if (existing is PropertyAccessorElement && duplicate is MethodElement) {
762 if (existing.nameOffset < duplicate.nameOffset) { 762 if (existing.nameOffset < duplicate.nameOffset) {
763 return new AnalysisError( 763 return new AnalysisError(
764 duplicate.source, 764 duplicate.source,
765 duplicate.nameOffset, 765 duplicate.nameOffset,
766 duplicate.displayName.length, 766 duplicate.nameLength,
767 CompileTimeErrorCode.METHOD_AND_GETTER_WITH_SAME_NAME, 767 CompileTimeErrorCode.METHOD_AND_GETTER_WITH_SAME_NAME,
768 [existing.displayName]); 768 [existing.displayName]);
769 } else { 769 } else {
770 return new AnalysisError( 770 return new AnalysisError(
771 existing.source, 771 existing.source,
772 existing.nameOffset, 772 existing.nameOffset,
773 existing.displayName.length, 773 existing.nameLength,
774 CompileTimeErrorCode.GETTER_AND_METHOD_WITH_SAME_NAME, 774 CompileTimeErrorCode.GETTER_AND_METHOD_WITH_SAME_NAME,
775 [existing.displayName]); 775 [existing.displayName]);
776 } 776 }
777 } 777 }
778 return super.getErrorForDuplicate(existing, duplicate); 778 return super.getErrorForDuplicate(existing, duplicate);
779 } 779 }
780 780
781 /** 781 /**
782 * Define the instance members defined by the class. 782 * Define the instance members defined by the class.
783 * 783 *
(...skipping 5564 matching lines...) Expand 10 before | Expand all | Expand 10 after
6348 // One has the function type '() -> int' and one has the function 6348 // One has the function type '() -> int' and one has the function
6349 // type '() -> String'. Since neither is a subtype of the other, 6349 // type '() -> String'. Since neither is a subtype of the other,
6350 // we create a warning, and have this class inherit nothing. 6350 // we create a warning, and have this class inherit nothing.
6351 // 6351 //
6352 if (!classHasMember) { 6352 if (!classHasMember) {
6353 String firstTwoFuntionTypesStr = 6353 String firstTwoFuntionTypesStr =
6354 "${executableElementTypes[0]}, ${executableElementTypes[1]}" ; 6354 "${executableElementTypes[0]}, ${executableElementTypes[1]}" ;
6355 _reportError( 6355 _reportError(
6356 classElt, 6356 classElt,
6357 classElt.nameOffset, 6357 classElt.nameOffset,
6358 classElt.displayName.length, 6358 classElt.nameLength,
6359 StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE, 6359 StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE,
6360 [key, firstTwoFuntionTypesStr]); 6360 [key, firstTwoFuntionTypesStr]);
6361 } 6361 }
6362 } else { 6362 } else {
6363 // 6363 //
6364 // Example: class A inherits 2 methods named 'm'. 6364 // Example: class A inherits 2 methods named 'm'.
6365 // One has the function type '(int) -> dynamic' and one has the 6365 // One has the function type '(int) -> dynamic' and one has the
6366 // function type '(num) -> dynamic'. Since they are both a subtype 6366 // function type '(num) -> dynamic'. Since they are both a subtype
6367 // of the other, a synthetic function '(dynamic) -> dynamic' is 6367 // of the other, a synthetic function '(dynamic) -> dynamic' is
6368 // inherited. 6368 // inherited.
6369 // Tests: test_getMapOfMembersInheritedFromInterfaces_ 6369 // Tests: test_getMapOfMembersInheritedFromInterfaces_
6370 // union_multipleSubtypes_* 6370 // union_multipleSubtypes_*
6371 // 6371 //
6372 List<ExecutableElement> elementArrayToMerge = new List< 6372 List<ExecutableElement> elementArrayToMerge = new List<
6373 ExecutableElement>(subtypesOfAllOtherTypesIndexes.length); 6373 ExecutableElement>(subtypesOfAllOtherTypesIndexes.length);
6374 for (int i = 0; i < elementArrayToMerge.length; i++) { 6374 for (int i = 0; i < elementArrayToMerge.length; i++) {
6375 elementArrayToMerge[i] = 6375 elementArrayToMerge[i] =
6376 elements[subtypesOfAllOtherTypesIndexes[i]]; 6376 elements[subtypesOfAllOtherTypesIndexes[i]];
6377 } 6377 }
6378 ExecutableElement mergedExecutableElement = 6378 ExecutableElement mergedExecutableElement =
6379 _computeMergedExecutableElement(elementArrayToMerge); 6379 _computeMergedExecutableElement(elementArrayToMerge);
6380 resultMap.put(key, mergedExecutableElement); 6380 resultMap.put(key, mergedExecutableElement);
6381 } 6381 }
6382 } 6382 }
6383 } else { 6383 } else {
6384 _reportError( 6384 _reportError(
6385 classElt, 6385 classElt,
6386 classElt.nameOffset, 6386 classElt.nameOffset,
6387 classElt.displayName.length, 6387 classElt.nameLength,
6388 StaticWarningCode.INCONSISTENT_METHOD_INHERITANCE_GETTER_AND_METHO D, 6388 StaticWarningCode.INCONSISTENT_METHOD_INHERITANCE_GETTER_AND_METHO D,
6389 [key]); 6389 [key]);
6390 } 6390 }
6391 } 6391 }
6392 }); 6392 });
6393 return resultMap; 6393 return resultMap;
6394 } 6394 }
6395 6395
6396 /** 6396 /**
6397 * Loop through all of the members in some [MemberMap], performing type parame ter 6397 * Loop through all of the members in some [MemberMap], performing type parame ter
(...skipping 2594 matching lines...) Expand 10 before | Expand all | Expand 10 after
8992 int offset = duplicate.nameOffset; 8992 int offset = duplicate.nameOffset;
8993 if (duplicate is PropertyAccessorElement) { 8993 if (duplicate is PropertyAccessorElement) {
8994 PropertyAccessorElement accessor = duplicate; 8994 PropertyAccessorElement accessor = duplicate;
8995 if (accessor.isSynthetic) { 8995 if (accessor.isSynthetic) {
8996 offset = accessor.variable.nameOffset; 8996 offset = accessor.variable.nameOffset;
8997 } 8997 }
8998 } 8998 }
8999 return new AnalysisError( 8999 return new AnalysisError(
9000 duplicate.source, 9000 duplicate.source,
9001 offset, 9001 offset,
9002 duplicate.displayName.length, 9002 duplicate.nameLength,
9003 CompileTimeErrorCode.PREFIX_COLLIDES_WITH_TOP_LEVEL_MEMBER, 9003 CompileTimeErrorCode.PREFIX_COLLIDES_WITH_TOP_LEVEL_MEMBER,
9004 [existing.displayName]); 9004 [existing.displayName]);
9005 } 9005 }
9006 return super.getErrorForDuplicate(existing, duplicate); 9006 return super.getErrorForDuplicate(existing, duplicate);
9007 } 9007 }
9008 9008
9009 /** 9009 /**
9010 * Add to this scope all of the public top-level names that are defined in the given compilation 9010 * Add to this scope all of the public top-level names that are defined in the given compilation
9011 * unit. 9011 * unit.
9012 * 9012 *
(...skipping 2923 matching lines...) Expand 10 before | Expand all | Expand 10 after
11936 * @param existing the first element to be declared with the conflicting name 11936 * @param existing the first element to be declared with the conflicting name
11937 * @param duplicate another element declared with the conflicting name 11937 * @param duplicate another element declared with the conflicting name
11938 * @return the error code used to report duplicate names within a scope 11938 * @return the error code used to report duplicate names within a scope
11939 */ 11939 */
11940 AnalysisError getErrorForDuplicate(Element existing, Element duplicate) { 11940 AnalysisError getErrorForDuplicate(Element existing, Element duplicate) {
11941 // TODO(brianwilkerson) Customize the error message based on the types of 11941 // TODO(brianwilkerson) Customize the error message based on the types of
11942 // elements that share the same name. 11942 // elements that share the same name.
11943 // TODO(jwren) There are 4 error codes for duplicate, but only 1 is being 11943 // TODO(jwren) There are 4 error codes for duplicate, but only 1 is being
11944 // generated. 11944 // generated.
11945 Source source = duplicate.source; 11945 Source source = duplicate.source;
11946 return new AnalysisError( 11946 return new AnalysisError(source, duplicate.nameOffset, duplicate.nameLength,
11947 source, 11947 CompileTimeErrorCode.DUPLICATE_DEFINITION, [existing.displayName]);
11948 duplicate.nameOffset,
11949 duplicate.displayName.length,
11950 CompileTimeErrorCode.DUPLICATE_DEFINITION,
11951 [existing.displayName]);
11952 } 11948 }
11953 11949
11954 /** 11950 /**
11955 * Return the source that contains the given identifier, or the source associa ted with this scope 11951 * Return the source that contains the given identifier, or the source associa ted with this scope
11956 * if the source containing the identifier could not be determined. 11952 * if the source containing the identifier could not be determined.
11957 * 11953 *
11958 * @param identifier the identifier whose source is to be returned 11954 * @param identifier the identifier whose source is to be returned
11959 * @return the source that contains the given identifier 11955 * @return the source that contains the given identifier
11960 */ 11956 */
11961 Source getSource(AstNode node) { 11957 Source getSource(AstNode node) {
(...skipping 3186 matching lines...) Expand 10 before | Expand all | Expand 10 after
15148 if (t is InterfaceType) { 15144 if (t is InterfaceType) {
15149 ClassElement element = t.element; 15145 ClassElement element = t.element;
15150 InheritanceManager manager = new InheritanceManager(element.library); 15146 InheritanceManager manager = new InheritanceManager(element.library);
15151 FunctionType callType = manager.lookupMemberType(t, "call"); 15147 FunctionType callType = manager.lookupMemberType(t, "call");
15152 return callType; 15148 return callType;
15153 } 15149 }
15154 return null; 15150 return null;
15155 } 15151 }
15156 15152
15157 /** 15153 /**
15158 * Check that [f1] is a subtype of [f2]. 15154 * Check that [f1] is a subtype of [f2].
15159 * [fuzzyArrows] indicates whether or not the f1 and f2 should be 15155 * [fuzzyArrows] indicates whether or not the f1 and f2 should be
15160 * treated as fuzzy arrow types (and hence dynamic parameters to f2 treated 15156 * treated as fuzzy arrow types (and hence dynamic parameters to f2 treated
15161 * as bottom). 15157 * as bottom).
15162 */ 15158 */
15163 bool _isFunctionSubtypeOf(FunctionType f1, FunctionType f2, 15159 bool _isFunctionSubtypeOf(FunctionType f1, FunctionType f2,
15164 {bool fuzzyArrows: true}) { 15160 {bool fuzzyArrows: true}) {
15165 final r1s = f1.normalParameterTypes; 15161 final r1s = f1.normalParameterTypes;
15166 final o1s = f1.optionalParameterTypes; 15162 final o1s = f1.optionalParameterTypes;
15167 final n1s = f1.namedParameterTypes; 15163 final n1s = f1.namedParameterTypes;
15168 final r2s = f2.normalParameterTypes; 15164 final r2s = f2.normalParameterTypes;
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
15527 } 15523 }
15528 if (_usedElements.members.contains(element.displayName)) { 15524 if (_usedElements.members.contains(element.displayName)) {
15529 return true; 15525 return true;
15530 } 15526 }
15531 return _usedElements.elements.contains(element); 15527 return _usedElements.elements.contains(element);
15532 } 15528 }
15533 15529
15534 void _reportErrorForElement( 15530 void _reportErrorForElement(
15535 ErrorCode errorCode, Element element, List<Object> arguments) { 15531 ErrorCode errorCode, Element element, List<Object> arguments) {
15536 if (element != null) { 15532 if (element != null) {
15537 _errorListener.onError(new AnalysisError( 15533 _errorListener.onError(new AnalysisError(element.source,
15538 element.source, 15534 element.nameOffset, element.nameLength, errorCode, arguments));
15539 element.nameOffset,
15540 element.displayName.length,
15541 errorCode,
15542 arguments));
15543 } 15535 }
15544 } 15536 }
15545 } 15537 }
15546 15538
15547 /** 15539 /**
15548 * A container with information about used imports prefixes and used imported 15540 * A container with information about used imports prefixes and used imported
15549 * elements. 15541 * elements.
15550 */ 15542 */
15551 class UsedImportedElements { 15543 class UsedImportedElements {
15552 /** 15544 /**
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
15955 nonFields.add(node); 15947 nonFields.add(node);
15956 return null; 15948 return null;
15957 } 15949 }
15958 15950
15959 @override 15951 @override
15960 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); 15952 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this);
15961 15953
15962 @override 15954 @override
15963 Object visitWithClause(WithClause node) => null; 15955 Object visitWithClause(WithClause node) => null;
15964 } 15956 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/error_verifier.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698