| OLD | NEW |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 import 'package:analyzer/dart/ast/ast.dart'; | 5 import 'package:analyzer/dart/ast/ast.dart'; |
| 6 import 'package:analyzer/dart/ast/visitor.dart'; | 6 import 'package:analyzer/dart/ast/visitor.dart'; |
| 7 import 'package:analyzer/dart/element/type.dart'; | 7 import 'package:analyzer/dart/element/type.dart'; |
| 8 | 8 |
| 9 /// Visitor that applies resolution data from the front end (obtained via | 9 /// Visitor that applies resolution data from the front end (obtained via |
| 10 /// [ResolutionStorer]) to an analyzer AST. | 10 /// [ResolutionStorer]) to an analyzer AST. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 } | 22 } |
| 23 } | 23 } |
| 24 | 24 |
| 25 @override | 25 @override |
| 26 void visitExpression(Expression node) { | 26 void visitExpression(Expression node) { |
| 27 visitNode(node); | 27 visitNode(node); |
| 28 node.staticType = _getTypeFor(node); | 28 node.staticType = _getTypeFor(node); |
| 29 } | 29 } |
| 30 | 30 |
| 31 @override | 31 @override |
| 32 void visitInstanceCreationExpression(InstanceCreationExpression node) { |
| 33 node.argumentList?.accept(this); |
| 34 // TODO(paulberry): store resolution of node.constructorName. |
| 35 node.staticType = _getTypeFor(node.constructorName); |
| 36 } |
| 37 |
| 38 @override |
| 32 void visitMethodInvocation(MethodInvocation node) { | 39 void visitMethodInvocation(MethodInvocation node) { |
| 33 node.target?.accept(this); | 40 node.target?.accept(this); |
| 34 // TODO(paulberry): store resolution of node.methodName. | 41 // TODO(paulberry): store resolution of node.methodName. |
| 35 // TODO(paulberry): store resolution of node.typeArguments. | 42 // TODO(paulberry): store resolution of node.typeArguments. |
| 36 node.argumentList.accept(this); | 43 node.argumentList.accept(this); |
| 37 node.staticType = _getTypeFor(node); | 44 node.staticType = _getTypeFor(node.methodName); |
| 38 } | 45 } |
| 39 | 46 |
| 40 @override | 47 @override |
| 48 void visitVariableDeclaration(VariableDeclaration node) { |
| 49 if (node.parent is VariableDeclarationList && |
| 50 node.parent.parent is TopLevelVariableDeclaration) { |
| 51 // Don't visit the name; resolution for it will come from the outline. |
| 52 } else { |
| 53 node.name.accept(this); |
| 54 } |
| 55 node.initializer?.accept(this); |
| 56 } |
| 57 |
| 58 @override |
| 41 void visitVariableDeclarationList(VariableDeclarationList node) { | 59 void visitVariableDeclarationList(VariableDeclarationList node) { |
| 42 if (node.parent is TopLevelVariableDeclaration) { | 60 if (node.parent is TopLevelVariableDeclaration) { |
| 43 node.variables.accept(this); | 61 node.variables.accept(this); |
| 44 } else { | 62 } else { |
| 45 if (node.variables.length != 1) { | 63 if (node.variables.length != 1) { |
| 46 // TODO(paulberry): handle this case | 64 // TODO(paulberry): handle this case |
| 47 throw new UnimplementedError('Multiple variables in one declaration'); | 65 throw new UnimplementedError('Multiple variables in one declaration'); |
| 48 } | 66 } |
| 49 if (node.metadata.isNotEmpty) { | 67 if (node.metadata.isNotEmpty) { |
| 50 // TODO(paulberry): handle this case | 68 // TODO(paulberry): handle this case |
| 51 throw new UnimplementedError('Metadata on a variable declaration list'); | 69 throw new UnimplementedError('Metadata on a variable declaration list'); |
| 52 } | 70 } |
| 53 node.variables.accept(this); | 71 node.variables.accept(this); |
| 54 if (node.type != null) { | 72 if (node.type != null) { |
| 55 _applyToTypeAnnotation(node.variables[0].name.staticType, node.type); | 73 _applyToTypeAnnotation(node.variables[0].name.staticType, node.type); |
| 56 } | 74 } |
| 57 } | 75 } |
| 58 } | 76 } |
| 59 | 77 |
| 60 @override | |
| 61 void visitVariableDeclaration(VariableDeclaration node) { | |
| 62 if (node.parent is VariableDeclarationList && | |
| 63 node.parent.parent is TopLevelVariableDeclaration) { | |
| 64 // Don't visit the name; resolution for it will come from the outline. | |
| 65 } else { | |
| 66 node.name.accept(this); | |
| 67 } | |
| 68 node.initializer?.accept(this); | |
| 69 } | |
| 70 | |
| 71 void _applyToTypeAnnotation(DartType type, TypeAnnotation typeAnnotation) { | 78 void _applyToTypeAnnotation(DartType type, TypeAnnotation typeAnnotation) { |
| 72 // TODO(paulberry): implement this. | 79 // TODO(paulberry): implement this. |
| 73 } | 80 } |
| 74 | 81 |
| 75 DartType _getTypeFor(AstNode node) { | 82 DartType _getTypeFor(AstNode node) { |
| 76 return _types[_typeIndex++]; | 83 return _types[_typeIndex++]; |
| 77 } | 84 } |
| 78 } | 85 } |
| 79 | 86 |
| 80 /// Visitor that applies resolution data from the front end (obtained via | 87 /// Visitor that applies resolution data from the front end (obtained via |
| (...skipping 20 matching lines...) Expand all Loading... |
| 101 DartType _getTypeFor(AstNode node) { | 108 DartType _getTypeFor(AstNode node) { |
| 102 if (_debug) print('Getting type for $node'); | 109 if (_debug) print('Getting type for $node'); |
| 103 if (node.offset != _typeOffsets[_typeIndex]) { | 110 if (node.offset != _typeOffsets[_typeIndex]) { |
| 104 throw new StateError( | 111 throw new StateError( |
| 105 'Expected a type for analyzer offset ${node.offset}; got one for ' | 112 'Expected a type for analyzer offset ${node.offset}; got one for ' |
| 106 'kernel offset ${_typeOffsets[_typeIndex]}'); | 113 'kernel offset ${_typeOffsets[_typeIndex]}'); |
| 107 } | 114 } |
| 108 return super._getTypeFor(node); | 115 return super._getTypeFor(node); |
| 109 } | 116 } |
| 110 } | 117 } |
| OLD | NEW |