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 test.computer.element; | 5 library test.computer.element; |
6 | 6 |
7 import 'package:analysis_server/src/computer/element.dart'; | 7 import 'package:analysis_server/src/computer/element.dart'; |
8 import 'package:analysis_server/src/constants.dart'; | 8 import 'package:analysis_server/src/constants.dart'; |
9 import 'package:analyzer/src/generated/ast.dart'; | 9 import 'package:analyzer/src/generated/ast.dart'; |
10 import 'package:analyzer/src/generated/element.dart' as engine; | 10 import 'package:analyzer/src/generated/element.dart' as engine; |
(...skipping 30 matching lines...) Expand all Loading... |
41 ElementKind.COMPILATION_UNIT); | 41 ElementKind.COMPILATION_UNIT); |
42 expect(ElementKind.valueOf(ElementKind.CONSTRUCTOR.name), | 42 expect(ElementKind.valueOf(ElementKind.CONSTRUCTOR.name), |
43 ElementKind.CONSTRUCTOR); | 43 ElementKind.CONSTRUCTOR); |
44 expect(ElementKind.valueOf(ElementKind.FIELD.name), ElementKind.FIELD); | 44 expect(ElementKind.valueOf(ElementKind.FIELD.name), ElementKind.FIELD); |
45 expect(ElementKind.valueOf(ElementKind.FUNCTION.name), | 45 expect(ElementKind.valueOf(ElementKind.FUNCTION.name), |
46 ElementKind.FUNCTION); | 46 ElementKind.FUNCTION); |
47 expect(ElementKind.valueOf(ElementKind.FUNCTION_TYPE_ALIAS.name), | 47 expect(ElementKind.valueOf(ElementKind.FUNCTION_TYPE_ALIAS.name), |
48 ElementKind.FUNCTION_TYPE_ALIAS); | 48 ElementKind.FUNCTION_TYPE_ALIAS); |
49 expect(ElementKind.valueOf(ElementKind.GETTER.name), ElementKind.GETTER); | 49 expect(ElementKind.valueOf(ElementKind.GETTER.name), ElementKind.GETTER); |
50 expect(ElementKind.valueOf(ElementKind.LIBRARY.name), ElementKind.LIBRARY); | 50 expect(ElementKind.valueOf(ElementKind.LIBRARY.name), ElementKind.LIBRARY); |
| 51 expect(ElementKind.valueOf(ElementKind.LOCAL_VARIABLE.name), |
| 52 ElementKind.LOCAL_VARIABLE); |
51 expect(ElementKind.valueOf(ElementKind.METHOD.name), ElementKind.METHOD); | 53 expect(ElementKind.valueOf(ElementKind.METHOD.name), ElementKind.METHOD); |
52 expect(ElementKind.valueOf(ElementKind.SETTER.name), ElementKind.SETTER); | 54 expect(ElementKind.valueOf(ElementKind.SETTER.name), ElementKind.SETTER); |
53 expect(ElementKind.valueOf(ElementKind.TOP_LEVEL_VARIABLE.name), | 55 expect(ElementKind.valueOf(ElementKind.TOP_LEVEL_VARIABLE.name), |
54 ElementKind.TOP_LEVEL_VARIABLE); | 56 ElementKind.TOP_LEVEL_VARIABLE); |
55 expect(ElementKind.valueOf(ElementKind.UNIT_TEST_CASE.name), | 57 expect(ElementKind.valueOf(ElementKind.UNIT_TEST_CASE.name), |
56 ElementKind.UNIT_TEST_CASE); | 58 ElementKind.UNIT_TEST_CASE); |
57 expect(ElementKind.valueOf(ElementKind.UNIT_TEST_GROUP.name), | 59 expect(ElementKind.valueOf(ElementKind.UNIT_TEST_GROUP.name), |
58 ElementKind.UNIT_TEST_GROUP); | 60 ElementKind.UNIT_TEST_GROUP); |
59 expect(ElementKind.valueOf(ElementKind.UNKNOWN.name), ElementKind.UNKNOWN); | 61 expect(ElementKind.valueOf(ElementKind.UNKNOWN.name), ElementKind.UNKNOWN); |
60 expect(() { | 62 expect(() { |
(...skipping 11 matching lines...) Expand all Loading... |
72 expect(ElementKind.valueOfEngine(engine.ElementKind.FIELD), | 74 expect(ElementKind.valueOfEngine(engine.ElementKind.FIELD), |
73 ElementKind.FIELD); | 75 ElementKind.FIELD); |
74 expect(ElementKind.valueOfEngine(engine.ElementKind.FUNCTION), | 76 expect(ElementKind.valueOfEngine(engine.ElementKind.FUNCTION), |
75 ElementKind.FUNCTION); | 77 ElementKind.FUNCTION); |
76 expect(ElementKind.valueOfEngine(engine.ElementKind.FUNCTION_TYPE_ALIAS), | 78 expect(ElementKind.valueOfEngine(engine.ElementKind.FUNCTION_TYPE_ALIAS), |
77 ElementKind.FUNCTION_TYPE_ALIAS); | 79 ElementKind.FUNCTION_TYPE_ALIAS); |
78 expect(ElementKind.valueOfEngine(engine.ElementKind.GETTER), | 80 expect(ElementKind.valueOfEngine(engine.ElementKind.GETTER), |
79 ElementKind.GETTER); | 81 ElementKind.GETTER); |
80 expect(ElementKind.valueOfEngine(engine.ElementKind.LIBRARY), | 82 expect(ElementKind.valueOfEngine(engine.ElementKind.LIBRARY), |
81 ElementKind.LIBRARY); | 83 ElementKind.LIBRARY); |
| 84 expect(ElementKind.valueOfEngine(engine.ElementKind.LOCAL_VARIABLE), |
| 85 ElementKind.LOCAL_VARIABLE); |
82 expect(ElementKind.valueOfEngine(engine.ElementKind.METHOD), | 86 expect(ElementKind.valueOfEngine(engine.ElementKind.METHOD), |
83 ElementKind.METHOD); | 87 ElementKind.METHOD); |
84 expect(ElementKind.valueOfEngine(engine.ElementKind.SETTER), | 88 expect(ElementKind.valueOfEngine(engine.ElementKind.SETTER), |
85 ElementKind.SETTER); | 89 ElementKind.SETTER); |
86 expect(ElementKind.valueOfEngine(engine.ElementKind.TOP_LEVEL_VARIABLE), | 90 expect(ElementKind.valueOfEngine(engine.ElementKind.TOP_LEVEL_VARIABLE), |
87 ElementKind.TOP_LEVEL_VARIABLE); | 91 ElementKind.TOP_LEVEL_VARIABLE); |
88 expect(ElementKind.valueOfEngine(engine.ElementKind.ANGULAR_COMPONENT), | 92 expect(ElementKind.valueOfEngine(engine.ElementKind.ANGULAR_COMPONENT), |
89 ElementKind.UNKNOWN); | 93 ElementKind.UNKNOWN); |
90 } | 94 } |
91 } | 95 } |
(...skipping 22 matching lines...) Expand all Loading... |
114 expect(element.flags, Element.FLAG_ABSTRACT | Element.FLAG_DEPRECATED | | 118 expect(element.flags, Element.FLAG_ABSTRACT | Element.FLAG_DEPRECATED | |
115 Element.FLAG_PRIVATE); | 119 Element.FLAG_PRIVATE); |
116 } | 120 } |
117 | 121 |
118 void test_fromElement_CONSTRUCTOR() { | 122 void test_fromElement_CONSTRUCTOR() { |
119 Source source = addSource('/test.dart', ''' | 123 Source source = addSource('/test.dart', ''' |
120 class A { | 124 class A { |
121 const A.myConstructor(int a, [String b]); | 125 const A.myConstructor(int a, [String b]); |
122 }'''); | 126 }'''); |
123 CompilationUnit unit = resolveLibraryUnit(source); | 127 CompilationUnit unit = resolveLibraryUnit(source); |
124 engine.ConstructorElement engineElement = findElementInUnit(unit, 'myConstru
ctor'); | 128 engine.ConstructorElement engineElement = findElementInUnit(unit, |
| 129 'myConstructor'); |
125 // create notification Element | 130 // create notification Element |
126 Element element = new Element.fromEngine(engineElement); | 131 Element element = new Element.fromEngine(engineElement); |
127 expect(element.kind, ElementKind.CONSTRUCTOR); | 132 expect(element.kind, ElementKind.CONSTRUCTOR); |
128 expect(element.name, 'myConstructor'); | 133 expect(element.name, 'myConstructor'); |
129 { | 134 { |
130 Location location = element.location; | 135 Location location = element.location; |
131 expect(location.file, '/test.dart'); | 136 expect(location.file, '/test.dart'); |
132 expect(location.offset, 20); | 137 expect(location.offset, 20); |
133 expect(location.length, 'myConstructor'.length); | 138 expect(location.length, 'myConstructor'.length); |
134 expect(location.startLine, 2); | 139 expect(location.startLine, 2); |
(...skipping 27 matching lines...) Expand all Loading... |
162 expect(element.returnType, isNull); | 167 expect(element.returnType, isNull); |
163 expect(element.flags, Element.FLAG_CONST | Element.FLAG_STATIC); | 168 expect(element.flags, Element.FLAG_CONST | Element.FLAG_STATIC); |
164 } | 169 } |
165 | 170 |
166 void test_fromElement_GETTER() { | 171 void test_fromElement_GETTER() { |
167 Source source = addSource('/test.dart', ''' | 172 Source source = addSource('/test.dart', ''' |
168 class A { | 173 class A { |
169 String myGetter => 42; | 174 String myGetter => 42; |
170 }'''); | 175 }'''); |
171 CompilationUnit unit = resolveLibraryUnit(source); | 176 CompilationUnit unit = resolveLibraryUnit(source); |
172 engine.PropertyAccessorElement engineElement = findElementInUnit(unit, 'myGe
tter', engine.ElementKind.GETTER); | 177 engine.PropertyAccessorElement engineElement = findElementInUnit(unit, |
| 178 'myGetter', engine.ElementKind.GETTER); |
173 // create notification Element | 179 // create notification Element |
174 Element element = new Element.fromEngine(engineElement); | 180 Element element = new Element.fromEngine(engineElement); |
175 expect(element.kind, ElementKind.GETTER); | 181 expect(element.kind, ElementKind.GETTER); |
176 expect(element.name, 'myGetter'); | 182 expect(element.name, 'myGetter'); |
177 { | 183 { |
178 Location location = element.location; | 184 Location location = element.location; |
179 expect(location.file, '/test.dart'); | 185 expect(location.file, '/test.dart'); |
180 expect(location.offset, 19); | 186 expect(location.offset, 19); |
181 expect(location.length, 'myGetter'.length); | 187 expect(location.length, 'myGetter'.length); |
182 expect(location.startLine, 2); | 188 expect(location.startLine, 2); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 }, | 269 }, |
264 FLAGS: Element.FLAG_DEPRECATED | Element.FLAG_PRIVATE | | 270 FLAGS: Element.FLAG_DEPRECATED | Element.FLAG_PRIVATE | |
265 Element.FLAG_STATIC, | 271 Element.FLAG_STATIC, |
266 PARAMETERS: '(int a, String b)', | 272 PARAMETERS: '(int a, String b)', |
267 RETURN_TYPE: 'List<String>' | 273 RETURN_TYPE: 'List<String>' |
268 }; | 274 }; |
269 Element element = new Element.fromJson(json); | 275 Element element = new Element.fromJson(json); |
270 expect(element.toJson(), equals(json)); | 276 expect(element.toJson(), equals(json)); |
271 } | 277 } |
272 } | 278 } |
OLD | NEW |