| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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.test.src.summary.summary_test; | 5 library analyzer.test.src.summary.summary_test; |
| 6 | 6 |
| 7 import 'package:analyzer/dart/element/element.dart'; | 7 import 'package:analyzer/dart/element/element.dart'; |
| 8 import 'package:analyzer/src/generated/engine.dart'; | 8 import 'package:analyzer/src/generated/engine.dart'; |
| 9 import 'package:analyzer/src/generated/java_engine_io.dart'; | 9 import 'package:analyzer/src/generated/java_engine_io.dart'; |
| 10 import 'package:analyzer/src/generated/source.dart'; | 10 import 'package:analyzer/src/generated/source.dart'; |
| (...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 | 485 |
| 486 /** | 486 /** |
| 487 * Serialize a type declaration using the given [text] as a type name, and | 487 * Serialize a type declaration using the given [text] as a type name, and |
| 488 * return a summary of the corresponding [UnlinkedTypeRef]. If the type | 488 * return a summary of the corresponding [UnlinkedTypeRef]. If the type |
| 489 * declaration needs to refer to types that are not available in core, those | 489 * declaration needs to refer to types that are not available in core, those |
| 490 * types may be declared in [otherDeclarations]. | 490 * types may be declared in [otherDeclarations]. |
| 491 */ | 491 */ |
| 492 UnlinkedTypeRef serializeTypeText(String text, | 492 UnlinkedTypeRef serializeTypeText(String text, |
| 493 {String otherDeclarations: '', bool allowErrors: false}) { | 493 {String otherDeclarations: '', bool allowErrors: false}) { |
| 494 return serializeVariableText('$otherDeclarations\n$text v;', | 494 return serializeVariableText('$otherDeclarations\n$text v;', |
| 495 allowErrors: allowErrors).type; | 495 allowErrors: allowErrors) |
| 496 .type; |
| 496 } | 497 } |
| 497 | 498 |
| 498 /** | 499 /** |
| 499 * Serialize the given library [text] and return the summary of the variable | 500 * Serialize the given library [text] and return the summary of the variable |
| 500 * with the given [variableName]. | 501 * with the given [variableName]. |
| 501 */ | 502 */ |
| 502 UnlinkedVariable serializeVariableText(String text, | 503 UnlinkedVariable serializeVariableText(String text, |
| 503 {String variableName: 'v', bool allowErrors: false}) { | 504 {String variableName: 'v', bool allowErrors: false}) { |
| 504 serializeLibraryText(text, allowErrors: allowErrors); | 505 serializeLibraryText(text, allowErrors: allowErrors); |
| 505 return findVariable(variableName, failIfAbsent: true); | 506 return findVariable(variableName, failIfAbsent: true); |
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 894 executables: serializeClassText('class C { C(this.x()); Function x; }') | 895 executables: serializeClassText('class C { C(this.x()); Function x; }') |
| 895 .executables); | 896 .executables); |
| 896 UnlinkedParam parameter = executable.parameters[0]; | 897 UnlinkedParam parameter = executable.parameters[0]; |
| 897 // Since the parameter is function-typed it is considered to have an | 898 // Since the parameter is function-typed it is considered to have an |
| 898 // explicit type, even though that explicit type itself has an implicit | 899 // explicit type, even though that explicit type itself has an implicit |
| 899 // return type. | 900 // return type. |
| 900 expect(parameter.hasImplicitType, isFalse); | 901 expect(parameter.hasImplicitType, isFalse); |
| 901 checkDynamicTypeRef(parameter.type); | 902 checkDynamicTypeRef(parameter.type); |
| 902 } | 903 } |
| 903 | 904 |
| 904 test_constructor_initializing_formal_function_typed_no_prameters() { | 905 test_constructor_initializing_formal_function_typed_no_parameters() { |
| 905 UnlinkedExecutable executable = findExecutable('', | 906 UnlinkedExecutable executable = findExecutable('', |
| 906 executables: serializeClassText('class C { C(this.x()); final x; }') | 907 executables: serializeClassText('class C { C(this.x()); final x; }') |
| 907 .executables); | 908 .executables); |
| 908 UnlinkedParam parameter = executable.parameters[0]; | 909 UnlinkedParam parameter = executable.parameters[0]; |
| 909 expect(parameter.parameters, isEmpty); | 910 expect(parameter.parameters, isEmpty); |
| 910 } | 911 } |
| 911 | 912 |
| 912 test_constructor_initializing_formal_function_typed_prameter() { | 913 test_constructor_initializing_formal_function_typed_parameter() { |
| 913 UnlinkedExecutable executable = findExecutable('', | 914 UnlinkedExecutable executable = findExecutable('', |
| 914 executables: serializeClassText('class C { C(this.x(a)); final x; }') | 915 executables: serializeClassText('class C { C(this.x(a)); final x; }') |
| 915 .executables); | 916 .executables); |
| 916 UnlinkedParam parameter = executable.parameters[0]; | 917 UnlinkedParam parameter = executable.parameters[0]; |
| 917 expect(parameter.parameters, hasLength(1)); | 918 expect(parameter.parameters, hasLength(1)); |
| 918 } | 919 } |
| 919 | 920 |
| 920 test_constructor_initializing_formal_function_typed_prameter_order() { | 921 test_constructor_initializing_formal_function_typed_parameter_order() { |
| 921 UnlinkedExecutable executable = findExecutable('', | 922 UnlinkedExecutable executable = findExecutable('', |
| 922 executables: serializeClassText('class C { C(this.x(a, b)); final x; }') | 923 executables: serializeClassText('class C { C(this.x(a, b)); final x; }') |
| 923 .executables); | 924 .executables); |
| 924 UnlinkedParam parameter = executable.parameters[0]; | 925 UnlinkedParam parameter = executable.parameters[0]; |
| 925 expect(parameter.parameters, hasLength(2)); | 926 expect(parameter.parameters, hasLength(2)); |
| 926 expect(parameter.parameters[0].name, 'a'); | 927 expect(parameter.parameters[0].name, 'a'); |
| 927 expect(parameter.parameters[1].name, 'b'); | 928 expect(parameter.parameters[1].name, 'b'); |
| 928 } | 929 } |
| 929 | 930 |
| 930 test_constructor_initializing_formal_implicit_type() { | 931 test_constructor_initializing_formal_implicit_type() { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 973 } | 974 } |
| 974 | 975 |
| 975 test_constructor_initializing_formal_required() { | 976 test_constructor_initializing_formal_required() { |
| 976 UnlinkedExecutable executable = findExecutable('', | 977 UnlinkedExecutable executable = findExecutable('', |
| 977 executables: | 978 executables: |
| 978 serializeClassText('class C { C(this.x); final x; }').executables); | 979 serializeClassText('class C { C(this.x); final x; }').executables); |
| 979 UnlinkedParam parameter = executable.parameters[0]; | 980 UnlinkedParam parameter = executable.parameters[0]; |
| 980 expect(parameter.kind, UnlinkedParamKind.required); | 981 expect(parameter.kind, UnlinkedParamKind.required); |
| 981 } | 982 } |
| 982 | 983 |
| 984 test_constructor_initializing_formal_typedef() { |
| 985 UnlinkedExecutable executable = findExecutable('', |
| 986 executables: serializeClassText( |
| 987 'typedef F<T>(T x); class C<X> { C(this.f); F<X> f; }') |
| 988 .executables); |
| 989 UnlinkedParam parameter = executable.parameters[0]; |
| 990 expect(parameter.parameters, hasLength(1)); |
| 991 } |
| 992 |
| 983 test_constructor_named() { | 993 test_constructor_named() { |
| 984 UnlinkedExecutable executable = findExecutable('foo', | 994 UnlinkedExecutable executable = findExecutable('foo', |
| 985 executables: serializeClassText('class C { C.foo(); }').executables); | 995 executables: serializeClassText('class C { C.foo(); }').executables); |
| 986 expect(executable.name, 'foo'); | 996 expect(executable.name, 'foo'); |
| 987 } | 997 } |
| 988 | 998 |
| 989 test_constructor_non_const() { | 999 test_constructor_non_const() { |
| 990 UnlinkedExecutable executable = findExecutable('', | 1000 UnlinkedExecutable executable = findExecutable('', |
| 991 executables: serializeClassText('class C { C(); }').executables); | 1001 executables: serializeClassText('class C { C(); }').executables); |
| 992 expect(executable.isConst, isFalse); | 1002 expect(executable.isConst, isFalse); |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1340 expect(executable.isConst, false); | 1350 expect(executable.isConst, false); |
| 1341 expect(executable.isFactory, false); | 1351 expect(executable.isFactory, false); |
| 1342 expect(executable.isStatic, false); | 1352 expect(executable.isStatic, false); |
| 1343 expect(executable.parameters, hasLength(1)); | 1353 expect(executable.parameters, hasLength(1)); |
| 1344 checkTypeRef(executable.returnType, 'dart:core', 'dart:core', 'bool'); | 1354 checkTypeRef(executable.returnType, 'dart:core', 'dart:core', 'bool'); |
| 1345 expect(executable.typeParameters, isEmpty); | 1355 expect(executable.typeParameters, isEmpty); |
| 1346 } | 1356 } |
| 1347 | 1357 |
| 1348 test_executable_operator_index_set() { | 1358 test_executable_operator_index_set() { |
| 1349 UnlinkedExecutable executable = serializeClassText( | 1359 UnlinkedExecutable executable = serializeClassText( |
| 1350 'class C { void operator[]=(int i, bool v) => null; }').executables[0]; | 1360 'class C { void operator[]=(int i, bool v) => null; }') |
| 1361 .executables[0]; |
| 1351 expect(executable.kind, UnlinkedExecutableKind.functionOrMethod); | 1362 expect(executable.kind, UnlinkedExecutableKind.functionOrMethod); |
| 1352 expect(executable.name, '[]='); | 1363 expect(executable.name, '[]='); |
| 1353 expect(executable.hasImplicitReturnType, false); | 1364 expect(executable.hasImplicitReturnType, false); |
| 1354 expect(executable.isAbstract, false); | 1365 expect(executable.isAbstract, false); |
| 1355 expect(executable.isConst, false); | 1366 expect(executable.isConst, false); |
| 1356 expect(executable.isFactory, false); | 1367 expect(executable.isFactory, false); |
| 1357 expect(executable.isStatic, false); | 1368 expect(executable.isStatic, false); |
| 1358 expect(executable.parameters, hasLength(2)); | 1369 expect(executable.parameters, hasLength(2)); |
| 1359 expect(executable.returnType, isNull); | 1370 expect(executable.returnType, isNull); |
| 1360 expect(executable.typeParameters, isEmpty); | 1371 expect(executable.typeParameters, isEmpty); |
| (...skipping 784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2145 serializeClassText('class C { static int i; }').fields[0]; | 2156 serializeClassText('class C { static int i; }').fields[0]; |
| 2146 expect(variable.isStatic, isTrue); | 2157 expect(variable.isStatic, isTrue); |
| 2147 } | 2158 } |
| 2148 | 2159 |
| 2149 test_variable_type() { | 2160 test_variable_type() { |
| 2150 UnlinkedVariable variable = | 2161 UnlinkedVariable variable = |
| 2151 serializeVariableText('int i;', variableName: 'i'); | 2162 serializeVariableText('int i;', variableName: 'i'); |
| 2152 checkTypeRef(variable.type, 'dart:core', 'dart:core', 'int'); | 2163 checkTypeRef(variable.type, 'dart:core', 'dart:core', 'int'); |
| 2153 } | 2164 } |
| 2154 } | 2165 } |
| OLD | NEW |