| 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_common; | 5 library analyzer.test.src.summary.summary_common; |
| 6 | 6 |
| 7 import 'package:analyzer/analyzer.dart'; | 7 import 'package:analyzer/analyzer.dart'; |
| 8 import 'package:analyzer/dart/ast/ast.dart'; | 8 import 'package:analyzer/dart/ast/ast.dart'; |
| 9 import 'package:analyzer/dart/element/element.dart'; | 9 import 'package:analyzer/dart/element/element.dart'; |
| 10 import 'package:analyzer/src/dart/scanner/reader.dart'; | 10 import 'package:analyzer/src/dart/scanner/reader.dart'; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 /** | 36 /** |
| 37 * Convert a summary object (or a portion of one) into a canonical form that | 37 * Convert a summary object (or a portion of one) into a canonical form that |
| 38 * can be easily compared using [expect]. If [orderByName] is true, and the | 38 * can be easily compared using [expect]. If [orderByName] is true, and the |
| 39 * object is a [List], it is sorted by the `name` field of its elements. | 39 * object is a [List], it is sorted by the `name` field of its elements. |
| 40 */ | 40 */ |
| 41 Object canonicalize(Object obj, {bool orderByName: false}) { | 41 Object canonicalize(Object obj, {bool orderByName: false}) { |
| 42 if (obj is SummaryClass) { | 42 if (obj is SummaryClass) { |
| 43 Map<String, Object> result = <String, Object>{}; | 43 Map<String, Object> result = <String, Object>{}; |
| 44 obj.toMap().forEach((String key, Object value) { | 44 obj.toMap().forEach((String key, Object value) { |
| 45 bool orderByName = false; | 45 bool orderByName = false; |
| 46 if (obj is UnlinkedPublicNamespace && key == 'names') { | 46 if (obj is UnlinkedPublicNamespace && key == 'names' || |
| 47 obj is UnlinkedPublicName && key == 'members') { |
| 47 orderByName = true; | 48 orderByName = true; |
| 48 } | 49 } |
| 49 result[key] = canonicalize(value, orderByName: orderByName); | 50 result[key] = canonicalize(value, orderByName: orderByName); |
| 50 }); | 51 }); |
| 51 return result; | 52 return result; |
| 52 } else if (obj is List) { | 53 } else if (obj is List) { |
| 53 List<Object> result = <Object>[]; | 54 List<Object> result = <Object>[]; |
| 54 for (Object item in obj) { | 55 for (Object item in obj) { |
| 55 result.add(canonicalize(item)); | 56 result.add(canonicalize(item)); |
| 56 } | 57 } |
| (...skipping 1092 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1149 expect(cls.isAbstract, false); | 1150 expect(cls.isAbstract, false); |
| 1150 expect(unlinkedUnits[0].publicNamespace.names, hasLength(1)); | 1151 expect(unlinkedUnits[0].publicNamespace.names, hasLength(1)); |
| 1151 UnlinkedPublicName className = unlinkedUnits[0].publicNamespace.names[0]; | 1152 UnlinkedPublicName className = unlinkedUnits[0].publicNamespace.names[0]; |
| 1152 expect(className.kind, ReferenceKind.classOrEnum); | 1153 expect(className.kind, ReferenceKind.classOrEnum); |
| 1153 expect(className.name, 'C'); | 1154 expect(className.name, 'C'); |
| 1154 expect(className.numTypeParameters, 0); | 1155 expect(className.numTypeParameters, 0); |
| 1155 // executables | 1156 // executables |
| 1156 Map<String, UnlinkedPublicName> executablesMap = | 1157 Map<String, UnlinkedPublicName> executablesMap = |
| 1157 <String, UnlinkedPublicName>{}; | 1158 <String, UnlinkedPublicName>{}; |
| 1158 className.members.forEach((e) => executablesMap[e.name] = e); | 1159 className.members.forEach((e) => executablesMap[e.name] = e); |
| 1159 expect(executablesMap, hasLength(2)); | 1160 expect(executablesMap, hasLength(4)); |
| 1160 { | 1161 Map<String, ReferenceKind> expectedExecutableKinds = |
| 1161 UnlinkedPublicName executable = executablesMap['fieldStaticConst']; | 1162 <String, ReferenceKind>{ |
| 1162 expect(executable.kind, ReferenceKind.propertyAccessor); | 1163 'fieldStaticConst': ReferenceKind.propertyAccessor, |
| 1164 'fieldStaticFinal': ReferenceKind.propertyAccessor, |
| 1165 'fieldStatic': ReferenceKind.propertyAccessor, |
| 1166 'methodStaticPublic': ReferenceKind.method, |
| 1167 }; |
| 1168 expectedExecutableKinds.forEach((String name, ReferenceKind expectedKind) { |
| 1169 UnlinkedPublicName executable = executablesMap[name]; |
| 1170 expect(executable.kind, expectedKind); |
| 1163 expect(executable.members, isEmpty); | 1171 expect(executable.members, isEmpty); |
| 1164 } | 1172 }); |
| 1165 { | |
| 1166 UnlinkedPublicName executable = executablesMap['methodStaticPublic']; | |
| 1167 expect(executable.kind, ReferenceKind.method); | |
| 1168 expect(executable.members, isEmpty); | |
| 1169 } | |
| 1170 } | 1173 } |
| 1171 | 1174 |
| 1172 test_class_constMembers_constructors() { | 1175 test_class_constMembers_constructors() { |
| 1173 UnlinkedClass cls = serializeClassText(''' | 1176 UnlinkedClass cls = serializeClassText(''' |
| 1174 class C { | 1177 class C { |
| 1175 const C(); | 1178 const C(); |
| 1176 const C.constructorNamedPublicConst(); | 1179 const C.constructorNamedPublicConst(); |
| 1177 C.constructorNamedPublic(); | 1180 C.constructorNamedPublic(); |
| 1178 C._constructorNamedPrivate(); | 1181 C._constructorNamedPrivate(); |
| 1179 } | 1182 } |
| (...skipping 5759 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6939 test_field() { | 6942 test_field() { |
| 6940 UnlinkedClass cls = serializeClassText('class C { int i; }'); | 6943 UnlinkedClass cls = serializeClassText('class C { int i; }'); |
| 6941 UnlinkedVariable variable = findVariable('i', variables: cls.fields); | 6944 UnlinkedVariable variable = findVariable('i', variables: cls.fields); |
| 6942 expect(variable, isNotNull); | 6945 expect(variable, isNotNull); |
| 6943 expect(variable.isConst, isFalse); | 6946 expect(variable.isConst, isFalse); |
| 6944 expect(variable.isStatic, isFalse); | 6947 expect(variable.isStatic, isFalse); |
| 6945 expect(variable.isFinal, isFalse); | 6948 expect(variable.isFinal, isFalse); |
| 6946 expect(variable.constExpr, isNull); | 6949 expect(variable.constExpr, isNull); |
| 6947 expect(findExecutable('i', executables: cls.executables), isNull); | 6950 expect(findExecutable('i', executables: cls.executables), isNull); |
| 6948 expect(findExecutable('i=', executables: cls.executables), isNull); | 6951 expect(findExecutable('i=', executables: cls.executables), isNull); |
| 6952 expect(unlinkedUnits[0].publicNamespace.names, hasLength(1)); |
| 6953 expect(unlinkedUnits[0].publicNamespace.names[0].name, 'C'); |
| 6954 expect(unlinkedUnits[0].publicNamespace.names[0].members, isEmpty); |
| 6949 } | 6955 } |
| 6950 | 6956 |
| 6951 test_field_const() { | 6957 test_field_const() { |
| 6952 UnlinkedVariable variable = | 6958 UnlinkedVariable variable = |
| 6953 serializeClassText('class C { static const int i = 0; }').fields[0]; | 6959 serializeClassText('class C { static const int i = 0; }').fields[0]; |
| 6954 expect(variable.isConst, isTrue); | 6960 expect(variable.isConst, isTrue); |
| 6955 _assertUnlinkedConst(variable.constExpr, | 6961 _assertUnlinkedConst(variable.constExpr, |
| 6956 operators: [UnlinkedConstOperation.pushInt], ints: [0]); | 6962 operators: [UnlinkedConstOperation.pushInt], ints: [0]); |
| 6957 } | 6963 } |
| 6958 | 6964 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7089 UnlinkedVariable v = | 7095 UnlinkedVariable v = |
| 7090 serializeClassText('class C { final v = 0; }').fields[0]; | 7096 serializeClassText('class C { final v = 0; }').fields[0]; |
| 7091 checkLinkedTypeSlot(v.propagatedTypeSlot, 'dart:core', 'dart:core', 'int'); | 7097 checkLinkedTypeSlot(v.propagatedTypeSlot, 'dart:core', 'dart:core', 'int'); |
| 7092 } | 7098 } |
| 7093 | 7099 |
| 7094 test_field_static() { | 7100 test_field_static() { |
| 7095 UnlinkedVariable variable = | 7101 UnlinkedVariable variable = |
| 7096 serializeClassText('class C { static int i; }').fields[0]; | 7102 serializeClassText('class C { static int i; }').fields[0]; |
| 7097 expect(variable.isStatic, isTrue); | 7103 expect(variable.isStatic, isTrue); |
| 7098 expect(variable.constExpr, isNull); | 7104 expect(variable.constExpr, isNull); |
| 7105 expect(unlinkedUnits[0].publicNamespace.names, hasLength(1)); |
| 7106 expect(unlinkedUnits[0].publicNamespace.names[0].name, 'C'); |
| 7107 expect(unlinkedUnits[0].publicNamespace.names[0].members, hasLength(1)); |
| 7108 expect(unlinkedUnits[0].publicNamespace.names[0].members[0].name, 'i'); |
| 7109 expect(unlinkedUnits[0].publicNamespace.names[0].members[0].kind, |
| 7110 ReferenceKind.propertyAccessor); |
| 7111 expect( |
| 7112 unlinkedUnits[0].publicNamespace.names[0].members[0].numTypeParameters, |
| 7113 0); |
| 7114 expect( |
| 7115 unlinkedUnits[0].publicNamespace.names[0].members[0].members, isEmpty); |
| 7099 } | 7116 } |
| 7100 | 7117 |
| 7101 test_field_static_final() { | 7118 test_field_static_final() { |
| 7102 UnlinkedVariable variable = | 7119 UnlinkedVariable variable = |
| 7103 serializeClassText('class C { static final int i = 0; }').fields[0]; | 7120 serializeClassText('class C { static final int i = 0; }').fields[0]; |
| 7104 expect(variable.isStatic, isTrue); | 7121 expect(variable.isStatic, isTrue); |
| 7105 expect(variable.isFinal, isTrue); | 7122 expect(variable.isFinal, isTrue); |
| 7106 expect(variable.constExpr, isNull); | 7123 expect(variable.constExpr, isNull); |
| 7107 } | 7124 } |
| 7108 | 7125 |
| (...skipping 2626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9735 class _PrefixExpectation { | 9752 class _PrefixExpectation { |
| 9736 final ReferenceKind kind; | 9753 final ReferenceKind kind; |
| 9737 final String name; | 9754 final String name; |
| 9738 final String absoluteUri; | 9755 final String absoluteUri; |
| 9739 final String relativeUri; | 9756 final String relativeUri; |
| 9740 final int numTypeParameters; | 9757 final int numTypeParameters; |
| 9741 | 9758 |
| 9742 _PrefixExpectation(this.kind, this.name, | 9759 _PrefixExpectation(this.kind, this.name, |
| 9743 {this.absoluteUri, this.relativeUri, this.numTypeParameters: 0}); | 9760 {this.absoluteUri, this.relativeUri, this.numTypeParameters: 0}); |
| 9744 } | 9761 } |
| OLD | NEW |