| 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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 * that summaries need, so that this flag is no longer needed. | 98 * that summaries need, so that this flag is no longer needed. |
| 99 */ | 99 */ |
| 100 bool get checkAstDerivedData; | 100 bool get checkAstDerivedData; |
| 101 | 101 |
| 102 /** | 102 /** |
| 103 * Get access to the prelinked defining compilation unit. | 103 * Get access to the prelinked defining compilation unit. |
| 104 */ | 104 */ |
| 105 PrelinkedUnit get definingUnit => lib.units[0]; | 105 PrelinkedUnit get definingUnit => lib.units[0]; |
| 106 | 106 |
| 107 /** | 107 /** |
| 108 * Get access to the "unlinked" section of the summary. | |
| 109 */ | |
| 110 UnlinkedLibrary get unlinked => lib.unlinked; | |
| 111 | |
| 112 /** | |
| 113 * Convert [path] to a suitably formatted absolute path URI for the current | 108 * Convert [path] to a suitably formatted absolute path URI for the current |
| 114 * platform. | 109 * platform. |
| 115 */ | 110 */ |
| 116 String absUri(String path) { | 111 String absUri(String path) { |
| 117 return FileUtilities2.createFile(path).toURI().toString(); | 112 return FileUtilities2.createFile(path).toURI().toString(); |
| 118 } | 113 } |
| 119 | 114 |
| 120 /** | 115 /** |
| 121 * Add the given source file so that it may be referenced by the file under | 116 * Add the given source file so that it may be referenced by the file under |
| 122 * test. | 117 * test. |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 * having the given [deBruijnIndex]. | 192 * having the given [deBruijnIndex]. |
| 198 */ | 193 */ |
| 199 void checkParamTypeRef(UnlinkedTypeRef typeRef, int deBruijnIndex) { | 194 void checkParamTypeRef(UnlinkedTypeRef typeRef, int deBruijnIndex) { |
| 200 expect(typeRef, new isInstanceOf<UnlinkedTypeRef>()); | 195 expect(typeRef, new isInstanceOf<UnlinkedTypeRef>()); |
| 201 expect(typeRef.reference, 0); | 196 expect(typeRef.reference, 0); |
| 202 expect(typeRef.typeArguments, isEmpty); | 197 expect(typeRef.typeArguments, isEmpty); |
| 203 expect(typeRef.paramReference, deBruijnIndex); | 198 expect(typeRef.paramReference, deBruijnIndex); |
| 204 } | 199 } |
| 205 | 200 |
| 206 /** | 201 /** |
| 202 * Verify that [prefixReference] is a valid reference to a prefix having the |
| 203 * given [name]. |
| 204 */ |
| 205 void checkPrefix(int prefixReference, String name) { |
| 206 expect(prefixReference, isNot(0)); |
| 207 expect( |
| 208 definingUnit.unlinked.references[prefixReference].prefixReference, 0); |
| 209 expect(definingUnit.unlinked.references[prefixReference].name, name); |
| 210 expect(definingUnit.references[prefixReference].dependency, 0); |
| 211 expect(definingUnit.references[prefixReference].kind, |
| 212 PrelinkedReferenceKind.prefix); |
| 213 expect(definingUnit.references[prefixReference].unit, 0); |
| 214 } |
| 215 |
| 216 /** |
| 207 * Verify that the given [typeRef] represents a reference to a type declared | 217 * Verify that the given [typeRef] represents a reference to a type declared |
| 208 * in a file reachable via [absoluteUri] and [relativeUri], having name | 218 * in a file reachable via [absoluteUri] and [relativeUri], having name |
| 209 * [expectedName]. If [expectedPrefix] is supplied, verify that the type is | 219 * [expectedName]. If [expectedPrefix] is supplied, verify that the type is |
| 210 * reached via the given prefix. If [allowTypeParameters] is true, allow the | 220 * reached via the given prefix. If [allowTypeParameters] is true, allow the |
| 211 * type reference to supply type parameters. [expectedKind] is the kind of | 221 * type reference to supply type parameters. [expectedKind] is the kind of |
| 212 * object referenced. [sourceUnit] is the compilation unit within which the | 222 * object referenced. [sourceUnit] is the compilation unit within which the |
| 213 * [typeRef] appears; if not specified it is assumed to be the defining | 223 * [typeRef] appears; if not specified it is assumed to be the defining |
| 214 * compilation unit. [expectedTargetUnit] is the index of the compilation | 224 * compilation unit. [expectedTargetUnit] is the index of the compilation |
| 215 * unit in which the target of the [typeRef] is expected to appear; if not | 225 * unit in which the target of the [typeRef] is expected to appear; if not |
| 216 * specified it is assumed to be the defining compilation unit. | 226 * specified it is assumed to be the defining compilation unit. |
| 217 */ | 227 */ |
| 218 void checkTypeRef(UnlinkedTypeRef typeRef, String absoluteUri, | 228 void checkTypeRef(UnlinkedTypeRef typeRef, String absoluteUri, |
| 219 String relativeUri, String expectedName, | 229 String relativeUri, String expectedName, |
| 220 {String expectedPrefix, | 230 {String expectedPrefix, |
| 221 bool allowTypeParameters: false, | 231 bool allowTypeParameters: false, |
| 222 PrelinkedReferenceKind expectedKind: PrelinkedReferenceKind.classOrEnum, | 232 PrelinkedReferenceKind expectedKind: PrelinkedReferenceKind.classOrEnum, |
| 223 int expectedTargetUnit: 0, | 233 int expectedTargetUnit: 0, |
| 224 PrelinkedUnit sourceUnit}) { | 234 PrelinkedUnit sourceUnit}) { |
| 225 sourceUnit ??= definingUnit; | 235 sourceUnit ??= definingUnit; |
| 226 expect(typeRef, new isInstanceOf<UnlinkedTypeRef>()); | 236 expect(typeRef, new isInstanceOf<UnlinkedTypeRef>()); |
| 227 expect(typeRef.paramReference, 0); | 237 expect(typeRef.paramReference, 0); |
| 228 int index = typeRef.reference; | 238 int index = typeRef.reference; |
| 229 UnlinkedReference reference = sourceUnit.unlinked.references[index]; | 239 UnlinkedReference reference = sourceUnit.unlinked.references[index]; |
| 230 PrelinkedReference referenceResolution = sourceUnit.references[index]; | 240 PrelinkedReference referenceResolution = sourceUnit.references[index]; |
| 231 if (index == 0) { | 241 if (index == 0) { |
| 232 // Index 0 is reserved for "dynamic". | 242 // Index 0 is reserved for "dynamic". |
| 233 expect(reference.name, isEmpty); | 243 expect(reference.name, isEmpty); |
| 234 expect(reference.prefix, 0); | 244 expect(reference.prefixReference, 0); |
| 235 } | 245 } |
| 236 if (absoluteUri == null) { | 246 if (absoluteUri == null) { |
| 237 expect(referenceResolution.dependency, 0); | 247 expect(referenceResolution.dependency, 0); |
| 238 } else { | 248 } else { |
| 239 checkDependency(referenceResolution.dependency, absoluteUri, relativeUri); | 249 checkDependency(referenceResolution.dependency, absoluteUri, relativeUri); |
| 240 } | 250 } |
| 241 if (!allowTypeParameters) { | 251 if (!allowTypeParameters) { |
| 242 expect(typeRef.typeArguments, isEmpty); | 252 expect(typeRef.typeArguments, isEmpty); |
| 243 } | 253 } |
| 244 if (expectedName == null) { | 254 if (expectedName == null) { |
| 245 expect(reference.name, isEmpty); | 255 expect(reference.name, isEmpty); |
| 246 } else { | 256 } else { |
| 247 expect(reference.name, expectedName); | 257 expect(reference.name, expectedName); |
| 248 } | 258 } |
| 249 if (checkAstDerivedData) { | 259 if (checkAstDerivedData) { |
| 250 if (expectedPrefix == null) { | 260 if (expectedPrefix == null) { |
| 251 expect(reference.prefix, 0); | 261 expect(reference.prefixReference, 0); |
| 252 expect(unlinked.prefixes[reference.prefix].name, isEmpty); | |
| 253 } else { | 262 } else { |
| 254 expect(reference.prefix, isNot(0)); | 263 checkPrefix(reference.prefixReference, expectedPrefix); |
| 255 expect(unlinked.prefixes[reference.prefix].name, expectedPrefix); | |
| 256 } | 264 } |
| 257 } | 265 } |
| 258 expect(referenceResolution.kind, expectedKind); | 266 expect(referenceResolution.kind, expectedKind); |
| 259 expect(referenceResolution.unit, expectedTargetUnit); | 267 expect(referenceResolution.unit, expectedTargetUnit); |
| 260 } | 268 } |
| 261 | 269 |
| 262 /** | 270 /** |
| 263 * Verify that the given [typeRef] represents a reference to an unresolved | 271 * Verify that the given [typeRef] represents a reference to an unresolved |
| 264 * type. | 272 * type. |
| 265 */ | 273 */ |
| (...skipping 1222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1488 checkCombinatorName( | 1496 checkCombinatorName( |
| 1489 definingUnit.unlinked.imports[0].combinators[0].hides[1], 'Stream'); | 1497 definingUnit.unlinked.imports[0].combinators[0].hides[1], 'Stream'); |
| 1490 } | 1498 } |
| 1491 | 1499 |
| 1492 test_import_implicit() { | 1500 test_import_implicit() { |
| 1493 // The implicit import of dart:core is represented in the model. | 1501 // The implicit import of dart:core is represented in the model. |
| 1494 serializeLibraryText(''); | 1502 serializeLibraryText(''); |
| 1495 expect(definingUnit.unlinked.imports, hasLength(1)); | 1503 expect(definingUnit.unlinked.imports, hasLength(1)); |
| 1496 checkDependency(lib.importDependencies[0], 'dart:core', 'dart:core'); | 1504 checkDependency(lib.importDependencies[0], 'dart:core', 'dart:core'); |
| 1497 expect(definingUnit.unlinked.imports[0].uri, isEmpty); | 1505 expect(definingUnit.unlinked.imports[0].uri, isEmpty); |
| 1498 expect(definingUnit.unlinked.imports[0].prefix, 0); | 1506 expect(definingUnit.unlinked.imports[0].prefixReference, 0); |
| 1499 expect(definingUnit.unlinked.imports[0].combinators, isEmpty); | 1507 expect(definingUnit.unlinked.imports[0].combinators, isEmpty); |
| 1500 expect(definingUnit.unlinked.imports[0].isImplicit, isTrue); | 1508 expect(definingUnit.unlinked.imports[0].isImplicit, isTrue); |
| 1501 } | 1509 } |
| 1502 | 1510 |
| 1503 test_import_no_combinators() { | 1511 test_import_no_combinators() { |
| 1504 serializeLibraryText('import "dart:async"; Future x;'); | 1512 serializeLibraryText('import "dart:async"; Future x;'); |
| 1505 // Second import is the implicit import of dart:core | 1513 // Second import is the implicit import of dart:core |
| 1506 expect(definingUnit.unlinked.imports, hasLength(2)); | 1514 expect(definingUnit.unlinked.imports, hasLength(2)); |
| 1507 expect(definingUnit.unlinked.imports[0].combinators, isEmpty); | 1515 expect(definingUnit.unlinked.imports[0].combinators, isEmpty); |
| 1508 } | 1516 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1540 serializeLibraryText(libraryText); | 1548 serializeLibraryText(libraryText); |
| 1541 expect( | 1549 expect( |
| 1542 definingUnit.unlinked.imports[0].offset, libraryText.indexOf('import')); | 1550 definingUnit.unlinked.imports[0].offset, libraryText.indexOf('import')); |
| 1543 } | 1551 } |
| 1544 | 1552 |
| 1545 test_import_prefix_name() { | 1553 test_import_prefix_name() { |
| 1546 String libraryText = 'import "dart:async" as a; a.Future x;'; | 1554 String libraryText = 'import "dart:async" as a; a.Future x;'; |
| 1547 serializeLibraryText(libraryText); | 1555 serializeLibraryText(libraryText); |
| 1548 // Second import is the implicit import of dart:core | 1556 // Second import is the implicit import of dart:core |
| 1549 expect(definingUnit.unlinked.imports, hasLength(2)); | 1557 expect(definingUnit.unlinked.imports, hasLength(2)); |
| 1550 expect(definingUnit.unlinked.imports[0].prefix, isNot(0)); | 1558 checkPrefix(definingUnit.unlinked.imports[0].prefixReference, 'a'); |
| 1551 expect( | |
| 1552 unlinked.prefixes[definingUnit.unlinked.imports[0].prefix].name, 'a'); | |
| 1553 } | 1559 } |
| 1554 | 1560 |
| 1555 test_import_prefix_none() { | 1561 test_import_prefix_none() { |
| 1556 serializeLibraryText('import "dart:async"; Future x;'); | 1562 serializeLibraryText('import "dart:async"; Future x;'); |
| 1557 // Second import is the implicit import of dart:core | 1563 // Second import is the implicit import of dart:core |
| 1558 expect(definingUnit.unlinked.imports, hasLength(2)); | 1564 expect(definingUnit.unlinked.imports, hasLength(2)); |
| 1559 expect(definingUnit.unlinked.imports[0].prefix, 0); | 1565 expect(definingUnit.unlinked.imports[0].prefixReference, 0); |
| 1560 expect(unlinked.prefixes[definingUnit.unlinked.imports[0].prefix].name, | |
| 1561 isEmpty); | |
| 1562 } | 1566 } |
| 1563 | 1567 |
| 1564 test_import_prefix_reference() { | 1568 test_import_prefix_reference() { |
| 1565 UnlinkedVariable variable = | 1569 UnlinkedVariable variable = |
| 1566 serializeVariableText('import "dart:async" as a; a.Future v;'); | 1570 serializeVariableText('import "dart:async" as a; a.Future v;'); |
| 1567 checkTypeRef(variable.type, 'dart:async', 'dart:async', 'Future', | 1571 checkTypeRef(variable.type, 'dart:async', 'dart:async', 'Future', |
| 1568 expectedPrefix: 'a'); | 1572 expectedPrefix: 'a'); |
| 1569 } | 1573 } |
| 1570 | 1574 |
| 1571 test_import_reference() { | 1575 test_import_reference() { |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1973 serializeClassText('class C { static int i; }').fields[0]; | 1977 serializeClassText('class C { static int i; }').fields[0]; |
| 1974 expect(variable.isStatic, isTrue); | 1978 expect(variable.isStatic, isTrue); |
| 1975 } | 1979 } |
| 1976 | 1980 |
| 1977 test_variable_type() { | 1981 test_variable_type() { |
| 1978 UnlinkedVariable variable = | 1982 UnlinkedVariable variable = |
| 1979 serializeVariableText('int i;', variableName: 'i'); | 1983 serializeVariableText('int i;', variableName: 'i'); |
| 1980 checkTypeRef(variable.type, 'dart:core', 'dart:core', 'int'); | 1984 checkTypeRef(variable.type, 'dart:core', 'dart:core', 'int'); |
| 1981 } | 1985 } |
| 1982 } | 1986 } |
| OLD | NEW |