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

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

Issue 1932583002: Use ErrorReporter in many places. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 7 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/parser.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 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 7490 matching lines...) Expand 10 before | Expand all | Expand 10 after
7501 * The element for the library containing the compilation unit being visited. 7501 * The element for the library containing the compilation unit being visited.
7502 */ 7502 */
7503 final LibraryElement definingLibrary; 7503 final LibraryElement definingLibrary;
7504 7504
7505 /** 7505 /**
7506 * The source representing the compilation unit being visited. 7506 * The source representing the compilation unit being visited.
7507 */ 7507 */
7508 final Source source; 7508 final Source source;
7509 7509
7510 /** 7510 /**
7511 * The error listener that will be informed of any errors that are found durin g resolution. 7511 * The object used to access the types from the core library.
7512 */ 7512 */
7513 final AnalysisErrorListener errorListener; 7513 final TypeProvider typeProvider;
7514
7515 /**
7516 * The error reporter that will be informed of any errors that are found
7517 * during resolution.
7518 */
7519 final ErrorReporter errorReporter;
7514 7520
7515 /** 7521 /**
7516 * The scope used to resolve identifiers. 7522 * The scope used to resolve identifiers.
7517 */ 7523 */
7518 Scope nameScope; 7524 Scope nameScope;
7519 7525
7520 /** 7526 /**
7521 * The object used to access the types from the core library.
7522 */
7523 final TypeProvider typeProvider;
7524
7525 /**
7526 * The scope used to resolve unlabeled `break` and `continue` statements. 7527 * The scope used to resolve unlabeled `break` and `continue` statements.
7527 */ 7528 */
7528 ImplicitLabelScope _implicitLabelScope = ImplicitLabelScope.ROOT; 7529 ImplicitLabelScope _implicitLabelScope = ImplicitLabelScope.ROOT;
7529 7530
7530 /** 7531 /**
7531 * The scope used to resolve labels for `break` and `continue` statements, or 7532 * The scope used to resolve labels for `break` and `continue` statements, or
7532 * `null` if no labels have been defined in the current context. 7533 * `null` if no labels have been defined in the current context.
7533 */ 7534 */
7534 LabelScope labelScope; 7535 LabelScope labelScope;
7535 7536
(...skipping 11 matching lines...) Expand all
7547 * compilation unit being visited. 7548 * compilation unit being visited.
7548 * [source] is the source representing the compilation unit being visited. 7549 * [source] is the source representing the compilation unit being visited.
7549 * [typeProvider] is the object used to access the types from the core 7550 * [typeProvider] is the object used to access the types from the core
7550 * library. 7551 * library.
7551 * [errorListener] is the error listener that will be informed of any errors 7552 * [errorListener] is the error listener that will be informed of any errors
7552 * that are found during resolution. 7553 * that are found during resolution.
7553 * [nameScope] is the scope used to resolve identifiers in the node that will 7554 * [nameScope] is the scope used to resolve identifiers in the node that will
7554 * first be visited. If `null` or unspecified, a new [LibraryScope] will be 7555 * first be visited. If `null` or unspecified, a new [LibraryScope] will be
7555 * created based on [definingLibrary] and [typeProvider]. 7556 * created based on [definingLibrary] and [typeProvider].
7556 */ 7557 */
7557 ScopedVisitor( 7558 ScopedVisitor(this.definingLibrary, Source source, this.typeProvider,
7558 this.definingLibrary, this.source, this.typeProvider, this.errorListener, 7559 AnalysisErrorListener errorListener,
7559 {Scope nameScope}) { 7560 {Scope nameScope})
7561 : source = source,
7562 errorReporter = new ErrorReporter(errorListener, source) {
7560 if (nameScope == null) { 7563 if (nameScope == null) {
7561 this.nameScope = new LibraryScope(definingLibrary, errorListener); 7564 this.nameScope = new LibraryScope(definingLibrary, errorListener);
7562 } else { 7565 } else {
7563 this.nameScope = nameScope; 7566 this.nameScope = nameScope;
7564 } 7567 }
7565 } 7568 }
7566 7569
7567 /** 7570 /**
7568 * Return the implicit label scope in which the current node is being 7571 * Return the implicit label scope in which the current node is being
7569 * resolved. 7572 * resolved.
(...skipping 14 matching lines...) Expand all
7584 * Pushes a new [Scope] into the visitor. 7587 * Pushes a new [Scope] into the visitor.
7585 * 7588 *
7586 * @return the new [Scope]. 7589 * @return the new [Scope].
7587 */ 7590 */
7588 Scope pushNameScope() { 7591 Scope pushNameScope() {
7589 Scope newScope = new EnclosedScope(nameScope); 7592 Scope newScope = new EnclosedScope(nameScope);
7590 nameScope = newScope; 7593 nameScope = newScope;
7591 return nameScope; 7594 return nameScope;
7592 } 7595 }
7593 7596
7594 /**
7595 * Report an error with the given error code and arguments.
7596 *
7597 * @param errorCode the error code of the error to be reported
7598 * @param node the node specifying the location of the error
7599 * @param arguments the arguments to the error, used to compose the error mess age
7600 */
7601 void reportErrorForNode(ErrorCode errorCode, AstNode node,
7602 [List<Object> arguments]) {
7603 errorListener.onError(new AnalysisError(
7604 source, node.offset, node.length, errorCode, arguments));
7605 }
7606
7607 /**
7608 * Report an error with the given error code and arguments.
7609 *
7610 * @param errorCode the error code of the error to be reported
7611 * @param offset the offset of the location of the error
7612 * @param length the length of the location of the error
7613 * @param arguments the arguments to the error, used to compose the error mess age
7614 */
7615 void reportErrorForOffset(ErrorCode errorCode, int offset, int length,
7616 [List<Object> arguments]) {
7617 errorListener.onError(
7618 new AnalysisError(source, offset, length, errorCode, arguments));
7619 }
7620
7621 /**
7622 * Report an error with the given error code and arguments.
7623 *
7624 * @param errorCode the error code of the error to be reported
7625 * @param token the token specifying the location of the error
7626 * @param arguments the arguments to the error, used to compose the error mess age
7627 */
7628 void reportErrorForToken(ErrorCode errorCode, Token token,
7629 [List<Object> arguments]) {
7630 errorListener.onError(new AnalysisError(
7631 source, token.offset, token.length, errorCode, arguments));
7632 }
7633
7634 @override 7597 @override
7635 Object visitBlock(Block node) { 7598 Object visitBlock(Block node) {
7636 Scope outerScope = nameScope; 7599 Scope outerScope = nameScope;
7637 try { 7600 try {
7638 EnclosedScope enclosedScope = new EnclosedScope(nameScope); 7601 EnclosedScope enclosedScope = new EnclosedScope(nameScope);
7639 _hideNamesDefinedInBlock(enclosedScope, node); 7602 _hideNamesDefinedInBlock(enclosedScope, node);
7640 nameScope = enclosedScope; 7603 nameScope = enclosedScope;
7641 super.visitBlock(node); 7604 super.visitBlock(node);
7642 } finally { 7605 } finally {
7643 nameScope = outerScope; 7606 nameScope = outerScope;
(...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after
8406 /** 8369 /**
8407 * Helper for resolving [TypeName]s. 8370 * Helper for resolving [TypeName]s.
8408 * 8371 *
8409 * The client must set [nameScope] before calling [resolveTypeName]. 8372 * The client must set [nameScope] before calling [resolveTypeName].
8410 */ 8373 */
8411 class TypeNameResolver { 8374 class TypeNameResolver {
8412 final TypeSystem typeSystem; 8375 final TypeSystem typeSystem;
8413 final DartType dynamicType; 8376 final DartType dynamicType;
8414 final DartType undefinedType; 8377 final DartType undefinedType;
8415 final LibraryElement definingLibrary; 8378 final LibraryElement definingLibrary;
8416 final Source source; 8379 final ErrorReporter errorReporter;
8417 final AnalysisErrorListener errorListener;
8418 8380
8419 Scope nameScope; 8381 Scope nameScope;
8420 8382
8421 TypeNameResolver(this.typeSystem, TypeProvider typeProvider, 8383 TypeNameResolver(this.typeSystem, TypeProvider typeProvider,
8422 this.definingLibrary, this.source, this.errorListener) 8384 this.definingLibrary, this.errorReporter)
8423 : dynamicType = typeProvider.dynamicType, 8385 : dynamicType = typeProvider.dynamicType,
8424 undefinedType = typeProvider.undefinedType; 8386 undefinedType = typeProvider.undefinedType;
8425 8387
8426 /** 8388 /**
8427 * Report an error with the given error code and arguments.
8428 *
8429 * @param errorCode the error code of the error to be reported
8430 * @param node the node specifying the location of the error
8431 * @param arguments the arguments to the error, used to compose the error mess age
8432 */
8433 void reportErrorForNode(ErrorCode errorCode, AstNode node,
8434 [List<Object> arguments]) {
8435 errorListener.onError(new AnalysisError(
8436 source, node.offset, node.length, errorCode, arguments));
8437 }
8438
8439 /**
8440 * Resolve the given [TypeName] - set its element and static type. Only the 8389 * Resolve the given [TypeName] - set its element and static type. Only the
8441 * given [node] is resolved, all its children must be already resolved. 8390 * given [node] is resolved, all its children must be already resolved.
8442 * 8391 *
8443 * The client must set [nameScope] before calling [resolveTypeName]. 8392 * The client must set [nameScope] before calling [resolveTypeName].
8444 */ 8393 */
8445 void resolveTypeName(TypeName node) { 8394 void resolveTypeName(TypeName node) {
8446 Identifier typeName = node.name; 8395 Identifier typeName = node.name;
8447 _setElement(typeName, null); // Clear old Elements from previous run. 8396 _setElement(typeName, null); // Clear old Elements from previous run.
8448 TypeArgumentList argumentList = node.typeArguments; 8397 TypeArgumentList argumentList = node.typeArguments;
8449 Element element = nameScope.lookup(typeName, definingLibrary); 8398 Element element = nameScope.lookup(typeName, definingLibrary);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
8488 PrefixedIdentifier prefixedIdentifier = 8437 PrefixedIdentifier prefixedIdentifier =
8489 typeName as PrefixedIdentifier; 8438 typeName as PrefixedIdentifier;
8490 SimpleIdentifier prefix = prefixedIdentifier.prefix; 8439 SimpleIdentifier prefix = prefixedIdentifier.prefix;
8491 element = nameScope.lookup(prefix, definingLibrary); 8440 element = nameScope.lookup(prefix, definingLibrary);
8492 if (element is PrefixElement) { 8441 if (element is PrefixElement) {
8493 AstNode grandParent = parent.parent; 8442 AstNode grandParent = parent.parent;
8494 if (grandParent is InstanceCreationExpression && 8443 if (grandParent is InstanceCreationExpression &&
8495 grandParent.isConst) { 8444 grandParent.isConst) {
8496 // If, if this is a const expression, then generate a 8445 // If, if this is a const expression, then generate a
8497 // CompileTimeErrorCode.CONST_WITH_NON_TYPE error. 8446 // CompileTimeErrorCode.CONST_WITH_NON_TYPE error.
8498 reportErrorForNode( 8447 errorReporter.reportErrorForNode(
8499 CompileTimeErrorCode.CONST_WITH_NON_TYPE, 8448 CompileTimeErrorCode.CONST_WITH_NON_TYPE,
8500 prefixedIdentifier.identifier, 8449 prefixedIdentifier.identifier,
8501 [prefixedIdentifier.identifier.name]); 8450 [prefixedIdentifier.identifier.name]);
8502 } else { 8451 } else {
8503 // Else, if this expression is a new expression, report a 8452 // Else, if this expression is a new expression, report a
8504 // NEW_WITH_NON_TYPE warning. 8453 // NEW_WITH_NON_TYPE warning.
8505 reportErrorForNode( 8454 errorReporter.reportErrorForNode(
8506 StaticWarningCode.NEW_WITH_NON_TYPE, 8455 StaticWarningCode.NEW_WITH_NON_TYPE,
8507 prefixedIdentifier.identifier, 8456 prefixedIdentifier.identifier,
8508 [prefixedIdentifier.identifier.name]); 8457 [prefixedIdentifier.identifier.name]);
8509 } 8458 }
8510 _setElement(prefix, element); 8459 _setElement(prefix, element);
8511 return; 8460 return;
8512 } else if (element != null) { 8461 } else if (element != null) {
8513 // 8462 //
8514 // Rewrite the constructor name. The parser, when it sees a 8463 // Rewrite the constructor name. The parser, when it sees a
8515 // constructor named "a.b", cannot tell whether "a" is a prefix and 8464 // constructor named "a.b", cannot tell whether "a" is a prefix and
(...skipping 12 matching lines...) Expand all
8528 // check element 8477 // check element
8529 bool elementValid = element is! MultiplyDefinedElement; 8478 bool elementValid = element is! MultiplyDefinedElement;
8530 if (elementValid && 8479 if (elementValid &&
8531 element is! ClassElement && 8480 element is! ClassElement &&
8532 _isTypeNameInInstanceCreationExpression(node)) { 8481 _isTypeNameInInstanceCreationExpression(node)) {
8533 SimpleIdentifier typeNameSimple = _getTypeSimpleIdentifier(typeName); 8482 SimpleIdentifier typeNameSimple = _getTypeSimpleIdentifier(typeName);
8534 InstanceCreationExpression creation = 8483 InstanceCreationExpression creation =
8535 node.parent.parent as InstanceCreationExpression; 8484 node.parent.parent as InstanceCreationExpression;
8536 if (creation.isConst) { 8485 if (creation.isConst) {
8537 if (element == null) { 8486 if (element == null) {
8538 reportErrorForNode( 8487 errorReporter.reportErrorForNode(
8539 CompileTimeErrorCode.UNDEFINED_CLASS, typeNameSimple, [typeName]); 8488 CompileTimeErrorCode.UNDEFINED_CLASS, typeNameSimple, [typeName]);
8540 } else { 8489 } else {
8541 reportErrorForNode(CompileTimeErrorCode.CONST_WITH_NON_TYPE, 8490 errorReporter.reportErrorForNode(
8542 typeNameSimple, [typeName]); 8491 CompileTimeErrorCode.CONST_WITH_NON_TYPE,
8492 typeNameSimple,
8493 [typeName]);
8543 } 8494 }
8544 elementValid = false; 8495 elementValid = false;
8545 } else { 8496 } else {
8546 if (element != null) { 8497 if (element != null) {
8547 reportErrorForNode( 8498 errorReporter.reportErrorForNode(
8548 StaticWarningCode.NEW_WITH_NON_TYPE, typeNameSimple, [typeName]); 8499 StaticWarningCode.NEW_WITH_NON_TYPE, typeNameSimple, [typeName]);
8549 elementValid = false; 8500 elementValid = false;
8550 } 8501 }
8551 } 8502 }
8552 } 8503 }
8553 if (elementValid && element == null) { 8504 if (elementValid && element == null) {
8554 // We couldn't resolve the type name. 8505 // We couldn't resolve the type name.
8555 // TODO(jwren) Consider moving the check for 8506 // TODO(jwren) Consider moving the check for
8556 // CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE from the 8507 // CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE from the
8557 // ErrorVerifier, so that we don't have two errors on a built in 8508 // ErrorVerifier, so that we don't have two errors on a built in
8558 // identifier being used as a class name. 8509 // identifier being used as a class name.
8559 // See CompileTimeErrorCodeTest.test_builtInIdentifierAsType(). 8510 // See CompileTimeErrorCodeTest.test_builtInIdentifierAsType().
8560 SimpleIdentifier typeNameSimple = _getTypeSimpleIdentifier(typeName); 8511 SimpleIdentifier typeNameSimple = _getTypeSimpleIdentifier(typeName);
8561 RedirectingConstructorKind redirectingConstructorKind; 8512 RedirectingConstructorKind redirectingConstructorKind;
8562 if (_isBuiltInIdentifier(node) && _isTypeAnnotation(node)) { 8513 if (_isBuiltInIdentifier(node) && _isTypeAnnotation(node)) {
8563 reportErrorForNode(CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE, 8514 errorReporter.reportErrorForNode(
8564 typeName, [typeName.name]); 8515 CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE,
8516 typeName,
8517 [typeName.name]);
8565 } else if (typeNameSimple.name == "boolean") { 8518 } else if (typeNameSimple.name == "boolean") {
8566 reportErrorForNode( 8519 errorReporter.reportErrorForNode(
8567 StaticWarningCode.UNDEFINED_CLASS_BOOLEAN, typeNameSimple, []); 8520 StaticWarningCode.UNDEFINED_CLASS_BOOLEAN, typeNameSimple, []);
8568 } else if (_isTypeNameInCatchClause(node)) { 8521 } else if (_isTypeNameInCatchClause(node)) {
8569 reportErrorForNode(StaticWarningCode.NON_TYPE_IN_CATCH_CLAUSE, typeName, 8522 errorReporter.reportErrorForNode(
8523 StaticWarningCode.NON_TYPE_IN_CATCH_CLAUSE,
8524 typeName,
8570 [typeName.name]); 8525 [typeName.name]);
8571 } else if (_isTypeNameInAsExpression(node)) { 8526 } else if (_isTypeNameInAsExpression(node)) {
8572 reportErrorForNode( 8527 errorReporter.reportErrorForNode(
8573 StaticWarningCode.CAST_TO_NON_TYPE, typeName, [typeName.name]); 8528 StaticWarningCode.CAST_TO_NON_TYPE, typeName, [typeName.name]);
8574 } else if (_isTypeNameInIsExpression(node)) { 8529 } else if (_isTypeNameInIsExpression(node)) {
8575 reportErrorForNode(StaticWarningCode.TYPE_TEST_WITH_UNDEFINED_NAME, 8530 errorReporter.reportErrorForNode(
8576 typeName, [typeName.name]); 8531 StaticWarningCode.TYPE_TEST_WITH_UNDEFINED_NAME,
8532 typeName,
8533 [typeName.name]);
8577 } else if ((redirectingConstructorKind = 8534 } else if ((redirectingConstructorKind =
8578 _getRedirectingConstructorKind(node)) != 8535 _getRedirectingConstructorKind(node)) !=
8579 null) { 8536 null) {
8580 ErrorCode errorCode = 8537 ErrorCode errorCode =
8581 (redirectingConstructorKind == RedirectingConstructorKind.CONST 8538 (redirectingConstructorKind == RedirectingConstructorKind.CONST
8582 ? CompileTimeErrorCode.REDIRECT_TO_NON_CLASS 8539 ? CompileTimeErrorCode.REDIRECT_TO_NON_CLASS
8583 : StaticWarningCode.REDIRECT_TO_NON_CLASS); 8540 : StaticWarningCode.REDIRECT_TO_NON_CLASS);
8584 reportErrorForNode(errorCode, typeName, [typeName.name]); 8541 errorReporter.reportErrorForNode(errorCode, typeName, [typeName.name]);
8585 } else if (_isTypeNameInTypeArgumentList(node)) { 8542 } else if (_isTypeNameInTypeArgumentList(node)) {
8586 reportErrorForNode(StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT, 8543 errorReporter.reportErrorForNode(
8587 typeName, [typeName.name]); 8544 StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT,
8545 typeName,
8546 [typeName.name]);
8588 } else { 8547 } else {
8589 reportErrorForNode( 8548 errorReporter.reportErrorForNode(
8590 StaticWarningCode.UNDEFINED_CLASS, typeName, [typeName.name]); 8549 StaticWarningCode.UNDEFINED_CLASS, typeName, [typeName.name]);
8591 } 8550 }
8592 elementValid = false; 8551 elementValid = false;
8593 } 8552 }
8594 if (!elementValid) { 8553 if (!elementValid) {
8595 if (element is MultiplyDefinedElement) { 8554 if (element is MultiplyDefinedElement) {
8596 _setElement(typeName, element); 8555 _setElement(typeName, element);
8597 } 8556 }
8598 typeName.staticType = undefinedType; 8557 typeName.staticType = undefinedType;
8599 node.type = undefinedType; 8558 node.type = undefinedType;
(...skipping 17 matching lines...) Expand all
8617 } else if (element is MultiplyDefinedElement) { 8576 } else if (element is MultiplyDefinedElement) {
8618 List<Element> elements = element.conflictingElements; 8577 List<Element> elements = element.conflictingElements;
8619 type = _getTypeWhenMultiplyDefined(elements); 8578 type = _getTypeWhenMultiplyDefined(elements);
8620 if (type != null) { 8579 if (type != null) {
8621 node.type = type; 8580 node.type = type;
8622 } 8581 }
8623 } else { 8582 } else {
8624 // The name does not represent a type. 8583 // The name does not represent a type.
8625 RedirectingConstructorKind redirectingConstructorKind; 8584 RedirectingConstructorKind redirectingConstructorKind;
8626 if (_isTypeNameInCatchClause(node)) { 8585 if (_isTypeNameInCatchClause(node)) {
8627 reportErrorForNode(StaticWarningCode.NON_TYPE_IN_CATCH_CLAUSE, typeName, 8586 errorReporter.reportErrorForNode(
8587 StaticWarningCode.NON_TYPE_IN_CATCH_CLAUSE,
8588 typeName,
8628 [typeName.name]); 8589 [typeName.name]);
8629 } else if (_isTypeNameInAsExpression(node)) { 8590 } else if (_isTypeNameInAsExpression(node)) {
8630 reportErrorForNode( 8591 errorReporter.reportErrorForNode(
8631 StaticWarningCode.CAST_TO_NON_TYPE, typeName, [typeName.name]); 8592 StaticWarningCode.CAST_TO_NON_TYPE, typeName, [typeName.name]);
8632 } else if (_isTypeNameInIsExpression(node)) { 8593 } else if (_isTypeNameInIsExpression(node)) {
8633 reportErrorForNode(StaticWarningCode.TYPE_TEST_WITH_NON_TYPE, typeName, 8594 errorReporter.reportErrorForNode(
8595 StaticWarningCode.TYPE_TEST_WITH_NON_TYPE,
8596 typeName,
8634 [typeName.name]); 8597 [typeName.name]);
8635 } else if ((redirectingConstructorKind = 8598 } else if ((redirectingConstructorKind =
8636 _getRedirectingConstructorKind(node)) != 8599 _getRedirectingConstructorKind(node)) !=
8637 null) { 8600 null) {
8638 ErrorCode errorCode = 8601 ErrorCode errorCode =
8639 (redirectingConstructorKind == RedirectingConstructorKind.CONST 8602 (redirectingConstructorKind == RedirectingConstructorKind.CONST
8640 ? CompileTimeErrorCode.REDIRECT_TO_NON_CLASS 8603 ? CompileTimeErrorCode.REDIRECT_TO_NON_CLASS
8641 : StaticWarningCode.REDIRECT_TO_NON_CLASS); 8604 : StaticWarningCode.REDIRECT_TO_NON_CLASS);
8642 reportErrorForNode(errorCode, typeName, [typeName.name]); 8605 errorReporter.reportErrorForNode(errorCode, typeName, [typeName.name]);
8643 } else if (_isTypeNameInTypeArgumentList(node)) { 8606 } else if (_isTypeNameInTypeArgumentList(node)) {
8644 reportErrorForNode(StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT, 8607 errorReporter.reportErrorForNode(
8645 typeName, [typeName.name]); 8608 StaticTypeWarningCode.NON_TYPE_AS_TYPE_ARGUMENT,
8609 typeName,
8610 [typeName.name]);
8646 } else { 8611 } else {
8647 AstNode parent = typeName.parent; 8612 AstNode parent = typeName.parent;
8648 while (parent is TypeName) { 8613 while (parent is TypeName) {
8649 parent = parent.parent; 8614 parent = parent.parent;
8650 } 8615 }
8651 if (parent is ExtendsClause || 8616 if (parent is ExtendsClause ||
8652 parent is ImplementsClause || 8617 parent is ImplementsClause ||
8653 parent is WithClause || 8618 parent is WithClause ||
8654 parent is ClassTypeAlias) { 8619 parent is ClassTypeAlias) {
8655 // Ignored. The error will be reported elsewhere. 8620 // Ignored. The error will be reported elsewhere.
8656 } else { 8621 } else {
8657 reportErrorForNode( 8622 errorReporter.reportErrorForNode(
8658 StaticWarningCode.NOT_A_TYPE, typeName, [typeName.name]); 8623 StaticWarningCode.NOT_A_TYPE, typeName, [typeName.name]);
8659 } 8624 }
8660 } 8625 }
8661 typeName.staticType = dynamicType; 8626 typeName.staticType = dynamicType;
8662 node.type = dynamicType; 8627 node.type = dynamicType;
8663 return; 8628 return;
8664 } 8629 }
8665 if (argumentList != null) { 8630 if (argumentList != null) {
8666 NodeList<TypeName> arguments = argumentList.arguments; 8631 NodeList<TypeName> arguments = argumentList.arguments;
8667 int argumentCount = arguments.length; 8632 int argumentCount = arguments.length;
8668 List<DartType> parameters = typeSystem.typeFormalsAsTypes(type); 8633 List<DartType> parameters = typeSystem.typeFormalsAsTypes(type);
8669 int parameterCount = parameters.length; 8634 int parameterCount = parameters.length;
8670 List<DartType> typeArguments = new List<DartType>(parameterCount); 8635 List<DartType> typeArguments = new List<DartType>(parameterCount);
8671 if (argumentCount == parameterCount) { 8636 if (argumentCount == parameterCount) {
8672 for (int i = 0; i < parameterCount; i++) { 8637 for (int i = 0; i < parameterCount; i++) {
8673 TypeName argumentTypeName = arguments[i]; 8638 TypeName argumentTypeName = arguments[i];
8674 DartType argumentType = _getType(argumentTypeName); 8639 DartType argumentType = _getType(argumentTypeName);
8675 if (argumentType == null) { 8640 if (argumentType == null) {
8676 argumentType = dynamicType; 8641 argumentType = dynamicType;
8677 } 8642 }
8678 typeArguments[i] = argumentType; 8643 typeArguments[i] = argumentType;
8679 } 8644 }
8680 } else { 8645 } else {
8681 reportErrorForNode(_getInvalidTypeParametersErrorCode(node), node, 8646 errorReporter.reportErrorForNode(
8647 _getInvalidTypeParametersErrorCode(node),
8648 node,
8682 [typeName.name, parameterCount, argumentCount]); 8649 [typeName.name, parameterCount, argumentCount]);
8683 for (int i = 0; i < parameterCount; i++) { 8650 for (int i = 0; i < parameterCount; i++) {
8684 typeArguments[i] = dynamicType; 8651 typeArguments[i] = dynamicType;
8685 } 8652 }
8686 } 8653 }
8687 type = typeSystem.instantiateType(type, typeArguments); 8654 type = typeSystem.instantiateType(type, typeArguments);
8688 } else { 8655 } else {
8689 type = typeSystem.instantiateToBounds(type); 8656 type = typeSystem.instantiateToBounds(type);
8690 } 8657 }
8691 typeName.staticType = type; 8658 typeName.staticType = type;
(...skipping 1048 matching lines...) Expand 10 before | Expand all | Expand 10 after
9740 */ 9707 */
9741 TypeResolverVisitor(LibraryElement definingLibrary, Source source, 9708 TypeResolverVisitor(LibraryElement definingLibrary, Source source,
9742 TypeProvider typeProvider, AnalysisErrorListener errorListener, 9709 TypeProvider typeProvider, AnalysisErrorListener errorListener,
9743 {Scope nameScope}) 9710 {Scope nameScope})
9744 : super(definingLibrary, source, typeProvider, errorListener, 9711 : super(definingLibrary, source, typeProvider, errorListener,
9745 nameScope: nameScope) { 9712 nameScope: nameScope) {
9746 _dynamicType = typeProvider.dynamicType; 9713 _dynamicType = typeProvider.dynamicType;
9747 _undefinedType = typeProvider.undefinedType; 9714 _undefinedType = typeProvider.undefinedType;
9748 _strongMode = definingLibrary.context.analysisOptions.strongMode; 9715 _strongMode = definingLibrary.context.analysisOptions.strongMode;
9749 _typeSystem = TypeSystem.create(definingLibrary.context); 9716 _typeSystem = TypeSystem.create(definingLibrary.context);
9750 _typeNameResolver = new TypeNameResolver( 9717 _typeNameResolver = new TypeNameResolver(_typeSystem, typeProvider,
9751 _typeSystem, typeProvider, definingLibrary, source, errorListener); 9718 definingLibrary, new ErrorReporter(errorListener, source));
9752 } 9719 }
9753 9720
9754 @override 9721 @override
9755 Object visitAnnotation(Annotation node) { 9722 Object visitAnnotation(Annotation node) {
9756 // 9723 //
9757 // Visit annotations, if the annotation is @proxy, on a class, and "proxy" 9724 // Visit annotations, if the annotation is @proxy, on a class, and "proxy"
9758 // resolves to the proxy annotation in dart.core, then resolve the 9725 // resolves to the proxy annotation in dart.core, then resolve the
9759 // ElementAnnotation. 9726 // ElementAnnotation.
9760 // 9727 //
9761 // Element resolution is done in the ElementResolver, and this work will be 9728 // Element resolution is done in the ElementResolver, and this work will be
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after
10265 TypeName typeName = interfaces[i]; 10232 TypeName typeName = interfaces[i];
10266 if (!detectedRepeatOnIndex[i]) { 10233 if (!detectedRepeatOnIndex[i]) {
10267 Element element = typeName.name.staticElement; 10234 Element element = typeName.name.staticElement;
10268 for (int j = i + 1; j < count; j++) { 10235 for (int j = i + 1; j < count; j++) {
10269 TypeName typeName2 = interfaces[j]; 10236 TypeName typeName2 = interfaces[j];
10270 Identifier identifier2 = typeName2.name; 10237 Identifier identifier2 = typeName2.name;
10271 String name2 = identifier2.name; 10238 String name2 = identifier2.name;
10272 Element element2 = identifier2.staticElement; 10239 Element element2 = identifier2.staticElement;
10273 if (element != null && element == element2) { 10240 if (element != null && element == element2) {
10274 detectedRepeatOnIndex[j] = true; 10241 detectedRepeatOnIndex[j] = true;
10275 reportErrorForNode( 10242 errorReporter.reportErrorForNode(
10276 CompileTimeErrorCode.IMPLEMENTS_REPEATED, typeName2, [name2]); 10243 CompileTimeErrorCode.IMPLEMENTS_REPEATED, typeName2, [name2]);
10277 } 10244 }
10278 } 10245 }
10279 } 10246 }
10280 } 10247 }
10281 } 10248 }
10282 } 10249 }
10283 10250
10284 /** 10251 /**
10285 * Return the type specified by the given name. 10252 * Return the type specified by the given name.
10286 * 10253 *
10287 * @param typeName the type name specifying the type to be returned 10254 * @param typeName the type name specifying the type to be returned
10288 * @param nonTypeError the error to produce if the type name is defined to be something other than 10255 * @param nonTypeError the error to produce if the type name is defined to be something other than
10289 * a type 10256 * a type
10290 * @param enumTypeError the error to produce if the type name is defined to be an enum 10257 * @param enumTypeError the error to produce if the type name is defined to be an enum
10291 * @param dynamicTypeError the error to produce if the type name is "dynamic" 10258 * @param dynamicTypeError the error to produce if the type name is "dynamic"
10292 * @return the type specified by the type name 10259 * @return the type specified by the type name
10293 */ 10260 */
10294 InterfaceType _resolveType(TypeName typeName, ErrorCode nonTypeError, 10261 InterfaceType _resolveType(TypeName typeName, ErrorCode nonTypeError,
10295 ErrorCode enumTypeError, ErrorCode dynamicTypeError) { 10262 ErrorCode enumTypeError, ErrorCode dynamicTypeError) {
10296 DartType type = typeName.type; 10263 DartType type = typeName.type;
10297 if (type is InterfaceType) { 10264 if (type is InterfaceType) {
10298 ClassElement element = type.element; 10265 ClassElement element = type.element;
10299 if (element != null && element.isEnum) { 10266 if (element != null && element.isEnum) {
10300 reportErrorForNode(enumTypeError, typeName); 10267 errorReporter.reportErrorForNode(enumTypeError, typeName);
10301 return null; 10268 return null;
10302 } 10269 }
10303 return type; 10270 return type;
10304 } 10271 }
10305 // If the type is not an InterfaceType, then visitTypeName() sets the type 10272 // If the type is not an InterfaceType, then visitTypeName() sets the type
10306 // to be a DynamicTypeImpl 10273 // to be a DynamicTypeImpl
10307 Identifier name = typeName.name; 10274 Identifier name = typeName.name;
10308 if (name.name == Keyword.DYNAMIC.syntax) { 10275 if (name.name == Keyword.DYNAMIC.syntax) {
10309 reportErrorForNode(dynamicTypeError, name, [name.name]); 10276 errorReporter.reportErrorForNode(dynamicTypeError, name, [name.name]);
10310 } else { 10277 } else {
10311 reportErrorForNode(nonTypeError, name, [name.name]); 10278 errorReporter.reportErrorForNode(nonTypeError, name, [name.name]);
10312 } 10279 }
10313 return null; 10280 return null;
10314 } 10281 }
10315 10282
10316 /** 10283 /**
10317 * Resolve the types in the given list of type names. 10284 * Resolve the types in the given list of type names.
10318 * 10285 *
10319 * @param typeNames the type names to be resolved 10286 * @param typeNames the type names to be resolved
10320 * @param nonTypeError the error to produce if the type name is defined to be something other than 10287 * @param nonTypeError the error to produce if the type name is defined to be something other than
10321 * a type 10288 * a type
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after
10895 return null; 10862 return null;
10896 } 10863 }
10897 if (identical(node.staticElement, variable)) { 10864 if (identical(node.staticElement, variable)) {
10898 if (node.inSetterContext()) { 10865 if (node.inSetterContext()) {
10899 result = true; 10866 result = true;
10900 } 10867 }
10901 } 10868 }
10902 return null; 10869 return null;
10903 } 10870 }
10904 } 10871 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/parser.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698