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 engine.resolver.element_resolver; | 5 library engine.resolver.element_resolver; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 | 8 |
9 import 'error.dart'; | 9 import 'error.dart'; |
10 import 'scanner.dart' as sc; | 10 import 'scanner.dart' as sc; |
(...skipping 850 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
861 identifier.staticElement = importedLibrary.loadLibraryFunction; | 861 identifier.staticElement = importedLibrary.loadLibraryFunction; |
862 return null; | 862 return null; |
863 } | 863 } |
864 // | 864 // |
865 // Check to see whether the prefix is really a prefix. | 865 // Check to see whether the prefix is really a prefix. |
866 // | 866 // |
867 Element prefixElement = prefix.staticElement; | 867 Element prefixElement = prefix.staticElement; |
868 if (prefixElement is PrefixElement) { | 868 if (prefixElement is PrefixElement) { |
869 Element element = _resolver.nameScope.lookup(node, _definingLibrary); | 869 Element element = _resolver.nameScope.lookup(node, _definingLibrary); |
870 if (element == null && identifier.inSetterContext()) { | 870 if (element == null && identifier.inSetterContext()) { |
871 element = _resolver.nameScope.lookup(new ElementResolver_SyntheticIdenti
fier("${node.name}="), _definingLibrary); | 871 element = _resolver.nameScope.lookup(new SyntheticIdentifier( |
| 872 "${node.name}=", node), |
| 873 _definingLibrary); |
872 } | 874 } |
873 if (element == null) { | 875 if (element == null) { |
874 if (identifier.inSetterContext()) { | 876 if (identifier.inSetterContext()) { |
875 _resolver.reportErrorForNode(StaticWarningCode.UNDEFINED_SETTER, ident
ifier, [identifier.name, prefixElement.name]); | 877 _resolver.reportErrorForNode(StaticWarningCode.UNDEFINED_SETTER, ident
ifier, [identifier.name, prefixElement.name]); |
876 } else if (node.parent is Annotation) { | 878 } else if (node.parent is Annotation) { |
877 Annotation annotation = node.parent as Annotation; | 879 Annotation annotation = node.parent as Annotation; |
878 _resolver.reportErrorForNode(CompileTimeErrorCode.INVALID_ANNOTATION,
annotation, []); | 880 _resolver.reportErrorForNode(CompileTimeErrorCode.INVALID_ANNOTATION,
annotation, []); |
879 return null; | 881 return null; |
880 } else { | 882 } else { |
881 _resolver.reportErrorForNode(StaticWarningCode.UNDEFINED_GETTER, ident
ifier, [identifier.name, prefixElement.name]); | 883 _resolver.reportErrorForNode(StaticWarningCode.UNDEFINED_GETTER, ident
ifier, [identifier.name, prefixElement.name]); |
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1322 * | 1324 * |
1323 * @param identifier the identifier that might have been imported using a pref
ix | 1325 * @param identifier the identifier that might have been imported using a pref
ix |
1324 * @return the element that was found | 1326 * @return the element that was found |
1325 */ | 1327 */ |
1326 Element _findImportWithoutPrefix(SimpleIdentifier identifier) { | 1328 Element _findImportWithoutPrefix(SimpleIdentifier identifier) { |
1327 Element element = null; | 1329 Element element = null; |
1328 Scope nameScope = _resolver.nameScope; | 1330 Scope nameScope = _resolver.nameScope; |
1329 for (ImportElement importElement in _definingLibrary.imports) { | 1331 for (ImportElement importElement in _definingLibrary.imports) { |
1330 PrefixElement prefixElement = importElement.prefix; | 1332 PrefixElement prefixElement = importElement.prefix; |
1331 if (prefixElement != null) { | 1333 if (prefixElement != null) { |
1332 Identifier prefixedIdentifier = new ElementResolver_SyntheticIdentifier(
"${prefixElement.name}.${identifier.name}"); | 1334 Identifier prefixedIdentifier = new SyntheticIdentifier( |
| 1335 "${prefixElement.name}.${identifier.name}", |
| 1336 identifier); |
1333 Element importedElement = nameScope.lookup(prefixedIdentifier, _defining
Library); | 1337 Element importedElement = nameScope.lookup(prefixedIdentifier, _defining
Library); |
1334 if (importedElement != null) { | 1338 if (importedElement != null) { |
1335 if (element == null) { | 1339 if (element == null) { |
1336 element = importedElement; | 1340 element = importedElement; |
1337 } else { | 1341 } else { |
1338 element = MultiplyDefinedElementImpl.fromElements(_definingLibrary.c
ontext, element, importedElement); | 1342 element = MultiplyDefinedElementImpl.fromElements(_definingLibrary.c
ontext, element, importedElement); |
1339 } | 1343 } |
1340 } | 1344 } |
1341 } | 1345 } |
1342 } | 1346 } |
(...skipping 1005 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2348 } | 2352 } |
2349 return element; | 2353 return element; |
2350 } else if (target is SimpleIdentifier) { | 2354 } else if (target is SimpleIdentifier) { |
2351 Element targetElement = target.staticElement; | 2355 Element targetElement = target.staticElement; |
2352 if (targetElement is PrefixElement) { | 2356 if (targetElement is PrefixElement) { |
2353 // | 2357 // |
2354 // Look to see whether the name of the method is really part of a prefix
ed identifier for an | 2358 // Look to see whether the name of the method is really part of a prefix
ed identifier for an |
2355 // imported top-level function or top-level getter that returns a functi
on. | 2359 // imported top-level function or top-level getter that returns a functi
on. |
2356 // | 2360 // |
2357 String name = "${target.name}.$methodName"; | 2361 String name = "${target.name}.$methodName"; |
2358 Identifier functionName = new ElementResolver_SyntheticIdentifier(name); | 2362 Identifier functionName = new SyntheticIdentifier(name, methodName); |
2359 Element element = _resolver.nameScope.lookup(functionName, _definingLibr
ary); | 2363 Element element = _resolver.nameScope.lookup(functionName, _definingLibr
ary); |
2360 if (element != null) { | 2364 if (element != null) { |
2361 // TODO(brianwilkerson) This isn't a method invocation, it's a functio
n invocation where | 2365 // TODO(brianwilkerson) This isn't a method invocation, it's a functio
n invocation where |
2362 // the function name is a prefixed identifier. Consider re-writing the
AST. | 2366 // the function name is a prefixed identifier. Consider re-writing the
AST. |
2363 return element; | 2367 return element; |
2364 } | 2368 } |
2365 } | 2369 } |
2366 } | 2370 } |
2367 // TODO(brianwilkerson) Report this error. | 2371 // TODO(brianwilkerson) Report this error. |
2368 return null; | 2372 return null; |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2480 // | 2484 // |
2481 ClassElement enclosingClass = _resolver.enclosingClass; | 2485 ClassElement enclosingClass = _resolver.enclosingClass; |
2482 if (enclosingClass != null) { | 2486 if (enclosingClass != null) { |
2483 setter = _lookUpSetter(null, enclosingClass.type, node.name); | 2487 setter = _lookUpSetter(null, enclosingClass.type, node.name); |
2484 } | 2488 } |
2485 } | 2489 } |
2486 if (setter != null) { | 2490 if (setter != null) { |
2487 element = setter; | 2491 element = setter; |
2488 } | 2492 } |
2489 } | 2493 } |
2490 } else if (element == null && (node.inSetterContext() || node.parent is Comm
entReference)) { | 2494 } else if (element == null |
2491 element = _resolver.nameScope.lookup(new ElementResolver_SyntheticIdentifi
er("${node.name}="), _definingLibrary); | 2495 && (node.inSetterContext() || node.parent is CommentReference)) { |
| 2496 element = _resolver.nameScope.lookup( |
| 2497 new SyntheticIdentifier("${node.name}=", node), |
| 2498 _definingLibrary); |
2492 } | 2499 } |
2493 ClassElement enclosingClass = _resolver.enclosingClass; | 2500 ClassElement enclosingClass = _resolver.enclosingClass; |
2494 if (element == null && enclosingClass != null) { | 2501 if (element == null && enclosingClass != null) { |
2495 InterfaceType enclosingType = enclosingClass.type; | 2502 InterfaceType enclosingType = enclosingClass.type; |
2496 if (element == null && (node.inSetterContext() || node.parent is CommentRe
ference)) { | 2503 if (element == null && (node.inSetterContext() || node.parent is CommentRe
ference)) { |
2497 element = _lookUpSetter(null, enclosingType, node.name); | 2504 element = _lookUpSetter(null, enclosingType, node.name); |
2498 } | 2505 } |
2499 if (element == null && node.inGetterContext()) { | 2506 if (element == null && node.inGetterContext()) { |
2500 element = _lookUpGetter(null, enclosingType, node.name); | 2507 element = _lookUpGetter(null, enclosingType, node.name); |
2501 } | 2508 } |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2584 */ | 2591 */ |
2585 bool _shouldReportMissingMember(DartType type, Element member) { | 2592 bool _shouldReportMissingMember(DartType type, Element member) { |
2586 if (member != null || type == null || type.isDynamic || type.isBottom) { | 2593 if (member != null || type == null || type.isDynamic || type.isBottom) { |
2587 return false; | 2594 return false; |
2588 } | 2595 } |
2589 return true; | 2596 return true; |
2590 } | 2597 } |
2591 } | 2598 } |
2592 | 2599 |
2593 /** | 2600 /** |
2594 * Instances of the class `SyntheticIdentifier` implement an identifier that can
be used to | 2601 * A `SyntheticIdentifier` is an identifier that can be used to look up names in |
2595 * look up names in the lexical scope when there is no identifier in the AST str
ucture. There is | 2602 * the lexical scope when there is no identifier in the AST structure. There is |
2596 * no identifier in the AST when the parser could not distinguish between a meth
od invocation and | 2603 * no identifier in the AST when the parser could not distinguish between a |
2597 * an invocation of a top-level function imported with a prefix. | 2604 * method invocation and an invocation of a top-level function imported with a |
| 2605 * prefix. |
2598 */ | 2606 */ |
2599 class ElementResolver_SyntheticIdentifier extends Identifier { | 2607 class SyntheticIdentifier extends Identifier { |
2600 /** | 2608 /** |
2601 * The name of the synthetic identifier. | 2609 * The name of the synthetic identifier. |
2602 */ | 2610 */ |
2603 final String name; | 2611 final String name; |
2604 | 2612 |
2605 /** | 2613 /** |
2606 * Initialize a newly created synthetic identifier to have the given name. | 2614 * The identifier to be highlighted in case of an error |
2607 * | |
2608 * @param name the name of the synthetic identifier | |
2609 */ | 2615 */ |
2610 ElementResolver_SyntheticIdentifier(this.name); | 2616 final Identifier identifier; |
| 2617 |
| 2618 /** |
| 2619 * Initialize a newly created synthetic identifier to have the given [name] |
| 2620 * and [identifier]. |
| 2621 */ |
| 2622 SyntheticIdentifier(this.name, this.identifier); |
2611 | 2623 |
2612 @override | 2624 @override |
2613 accept(AstVisitor visitor) => null; | 2625 accept(AstVisitor visitor) => null; |
2614 | 2626 |
2615 @override | 2627 @override |
2616 sc.Token get beginToken => null; | 2628 sc.Token get beginToken => null; |
2617 | 2629 |
2618 @override | 2630 @override |
2619 Element get bestElement => null; | 2631 Element get bestElement => null; |
2620 | 2632 |
2621 @override | 2633 @override |
2622 sc.Token get endToken => null; | 2634 sc.Token get endToken => null; |
2623 | 2635 |
2624 @override | 2636 @override |
| 2637 int get length => identifier.length; |
| 2638 |
| 2639 @override |
| 2640 int get offset => identifier.offset; |
| 2641 |
| 2642 @override |
2625 int get precedence => 16; | 2643 int get precedence => 16; |
2626 | 2644 |
2627 @override | 2645 @override |
2628 Element get propagatedElement => null; | 2646 Element get propagatedElement => null; |
2629 | 2647 |
2630 @override | 2648 @override |
2631 Element get staticElement => null; | 2649 Element get staticElement => null; |
2632 | 2650 |
2633 @override | 2651 @override |
2634 void visitChildren(AstVisitor visitor) { | 2652 void visitChildren(AstVisitor visitor) { |
2635 } | 2653 } |
2636 } | 2654 } |
2637 | |
OLD | NEW |