OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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.declaration_resolver; | 5 library analyzer.src.generated.declaration_resolver; |
6 | 6 |
7 import 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
8 import 'package:analyzer/dart/ast/token.dart'; | 8 import 'package:analyzer/dart/ast/token.dart'; |
9 import 'package:analyzer/dart/ast/visitor.dart'; | 9 import 'package:analyzer/dart/ast/visitor.dart'; |
10 import 'package:analyzer/dart/element/element.dart'; | 10 import 'package:analyzer/dart/element/element.dart'; |
11 import 'package:analyzer/exception/exception.dart'; | 11 import 'package:analyzer/exception/exception.dart'; |
| 12 import 'package:analyzer/src/dart/element/builder.dart'; |
12 import 'package:analyzer/src/dart/element/element.dart'; | 13 import 'package:analyzer/src/dart/element/element.dart'; |
| 14 import 'package:analyzer/src/generated/resolver.dart'; |
13 | 15 |
14 /** | 16 /** |
15 * A visitor that resolves declarations in an AST structure to already built | 17 * A visitor that resolves declarations in an AST structure to already built |
16 * elements. | 18 * elements. |
17 * | 19 * |
18 * The resulting AST must have everything resolved that would have been resolved | 20 * The resulting AST must have everything resolved that would have been resolved |
19 * by a [CompilationUnitBuilder] (that is, must be a valid [RESOLVED_UNIT1]). | 21 * by a [CompilationUnitBuilder] (that is, must be a valid [RESOLVED_UNIT1]). |
20 * This class must not assume that the [CompilationUnitElement] passed to it is | 22 * This class must not assume that the [CompilationUnitElement] passed to it is |
21 * any more complete than a [COMPILATION_UNIT_ELEMENT]. | 23 * any more complete than a [COMPILATION_UNIT_ELEMENT]. |
22 */ | 24 */ |
(...skipping 21 matching lines...) Expand all Loading... |
44 try { | 46 try { |
45 unit.accept(this); | 47 unit.accept(this); |
46 _walker.validate(); | 48 _walker.validate(); |
47 } on Error catch (e, st) { | 49 } on Error catch (e, st) { |
48 throw new _ElementMismatchException( | 50 throw new _ElementMismatchException( |
49 element, _walker.element, new CaughtException(e, st)); | 51 element, _walker.element, new CaughtException(e, st)); |
50 } | 52 } |
51 } | 53 } |
52 | 54 |
53 @override | 55 @override |
| 56 Object visitAnnotation(Annotation node) { |
| 57 // Annotations can only contain elements in certain erroneous situations, |
| 58 // in which case the elements are disconnected from the rest of the element |
| 59 // model, thus we can't reconnect to them. To avoid crashes, just create |
| 60 // fresh elements. |
| 61 ElementHolder elementHolder = new ElementHolder(); |
| 62 new ElementBuilder(elementHolder, _enclosingUnit).visitAnnotation(node); |
| 63 return null; |
| 64 } |
| 65 |
| 66 @override |
54 Object visitCatchClause(CatchClause node) { | 67 Object visitCatchClause(CatchClause node) { |
55 SimpleIdentifier exceptionParameter = node.exceptionParameter; | 68 SimpleIdentifier exceptionParameter = node.exceptionParameter; |
56 if (exceptionParameter != null) { | 69 if (exceptionParameter != null) { |
57 _match(exceptionParameter, _walker.getVariable()); | 70 _match(exceptionParameter, _walker.getVariable()); |
58 SimpleIdentifier stackTraceParameter = node.stackTraceParameter; | 71 SimpleIdentifier stackTraceParameter = node.stackTraceParameter; |
59 if (stackTraceParameter != null) { | 72 if (stackTraceParameter != null) { |
60 _match(stackTraceParameter, _walker.getVariable()); | 73 _match(stackTraceParameter, _walker.getVariable()); |
61 } | 74 } |
62 } | 75 } |
63 return super.visitCatchClause(node); | 76 return super.visitCatchClause(node); |
(...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
619 class _ElementMismatchException extends AnalysisException { | 632 class _ElementMismatchException extends AnalysisException { |
620 /** | 633 /** |
621 * Creates an exception to refer to the given [compilationUnit], [element], | 634 * Creates an exception to refer to the given [compilationUnit], [element], |
622 * and [cause]. | 635 * and [cause]. |
623 */ | 636 */ |
624 _ElementMismatchException( | 637 _ElementMismatchException( |
625 CompilationUnitElement compilationUnit, Element element, | 638 CompilationUnitElement compilationUnit, Element element, |
626 [CaughtException cause = null]) | 639 [CaughtException cause = null]) |
627 : super('Element mismatch in $compilationUnit at $element', cause); | 640 : super('Element mismatch in $compilationUnit at $element', cause); |
628 } | 641 } |
OLD | NEW |