Chromium Code Reviews| 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/ast.dart'; | 8 import 'package:analyzer/src/generated/ast.dart'; |
| 9 import 'package:analyzer/src/generated/engine.dart'; | 9 import 'package:analyzer/src/generated/engine.dart'; |
| 10 import 'package:analyzer/src/generated/error.dart'; | 10 import 'package:analyzer/src/generated/error.dart'; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 <String, UnlinkedPublicNamespace>{}; | 105 <String, UnlinkedPublicNamespace>{}; |
| 106 List<LibraryElement> libraries = [ | 106 List<LibraryElement> libraries = [ |
| 107 analysisContext.typeProvider.objectType.element.library, | 107 analysisContext.typeProvider.objectType.element.library, |
| 108 analysisContext.typeProvider.futureType.element.library | 108 analysisContext.typeProvider.futureType.element.library |
| 109 ]; | 109 ]; |
| 110 for (LibraryElement library in libraries) { | 110 for (LibraryElement library in libraries) { |
| 111 summarize_elements.LibrarySerializationResult serializedLibrary = | 111 summarize_elements.LibrarySerializationResult serializedLibrary = |
| 112 summarize_elements.serializeLibrary( | 112 summarize_elements.serializeLibrary( |
| 113 library, analysisContext.typeProvider); | 113 library, analysisContext.typeProvider); |
| 114 for (int i = 0; i < serializedLibrary.unlinkedUnits.length; i++) { | 114 for (int i = 0; i < serializedLibrary.unlinkedUnits.length; i++) { |
| 115 uriToNamespace[ | 115 uriToNamespace[serializedLibrary.unitUris[i]] = |
| 116 serializedLibrary.unitUris[i]] = new UnlinkedUnit.fromBuffer( | 116 new UnlinkedUnit.fromBuffer( |
| 117 serializedLibrary.unlinkedUnits[i].toBuffer()).publicNamespace; | 117 serializedLibrary.unlinkedUnits[i].toBuffer()) |
| 118 .publicNamespace; | |
| 118 } | 119 } |
| 119 } | 120 } |
| 120 return uriToNamespace; | 121 return uriToNamespace; |
| 121 } catch (_) { | 122 } catch (_) { |
| 122 return null; | 123 return null; |
| 123 } | 124 } |
| 124 }(); | 125 }(); |
| 125 | 126 |
| 126 final Map<String, UnlinkedPublicNamespace> uriToPublicNamespace = | 127 final Map<String, UnlinkedPublicNamespace> uriToPublicNamespace = |
| 127 <String, UnlinkedPublicNamespace>{}; | 128 <String, UnlinkedPublicNamespace>{}; |
| (...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 757 | 758 |
| 758 /** | 759 /** |
| 759 * Serialize a type declaration using the given [text] as a type name, and | 760 * Serialize a type declaration using the given [text] as a type name, and |
| 760 * return a summary of the corresponding [UnlinkedTypeRef]. If the type | 761 * return a summary of the corresponding [UnlinkedTypeRef]. If the type |
| 761 * declaration needs to refer to types that are not available in core, those | 762 * declaration needs to refer to types that are not available in core, those |
| 762 * types may be declared in [otherDeclarations]. | 763 * types may be declared in [otherDeclarations]. |
| 763 */ | 764 */ |
| 764 UnlinkedTypeRef serializeTypeText(String text, | 765 UnlinkedTypeRef serializeTypeText(String text, |
| 765 {String otherDeclarations: '', bool allowErrors: false}) { | 766 {String otherDeclarations: '', bool allowErrors: false}) { |
| 766 return serializeVariableText('$otherDeclarations\n$text v;', | 767 return serializeVariableText('$otherDeclarations\n$text v;', |
| 767 allowErrors: allowErrors).type; | 768 allowErrors: allowErrors) |
| 769 .type; | |
| 768 } | 770 } |
| 769 | 771 |
| 770 /** | 772 /** |
| 771 * Serialize the given library [text] and return the summary of the variable | 773 * Serialize the given library [text] and return the summary of the variable |
| 772 * with the given [variableName]. | 774 * with the given [variableName]. |
| 773 */ | 775 */ |
| 774 UnlinkedVariable serializeVariableText(String text, | 776 UnlinkedVariable serializeVariableText(String text, |
| 775 {String variableName: 'v', bool allowErrors: false}) { | 777 {String variableName: 'v', bool allowErrors: false}) { |
| 776 serializeLibraryText(text, allowErrors: allowErrors); | 778 serializeLibraryText(text, allowErrors: allowErrors); |
| 777 return findVariable(variableName, failIfAbsent: true); | 779 return findVariable(variableName, failIfAbsent: true); |
| (...skipping 1005 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1783 expect(executable.isConst, false); | 1785 expect(executable.isConst, false); |
| 1784 expect(executable.isFactory, false); | 1786 expect(executable.isFactory, false); |
| 1785 expect(executable.isStatic, false); | 1787 expect(executable.isStatic, false); |
| 1786 expect(executable.parameters, hasLength(1)); | 1788 expect(executable.parameters, hasLength(1)); |
| 1787 checkTypeRef(executable.returnType, 'dart:core', 'dart:core', 'bool'); | 1789 checkTypeRef(executable.returnType, 'dart:core', 'dart:core', 'bool'); |
| 1788 expect(executable.typeParameters, isEmpty); | 1790 expect(executable.typeParameters, isEmpty); |
| 1789 } | 1791 } |
| 1790 | 1792 |
| 1791 test_executable_operator_index_set() { | 1793 test_executable_operator_index_set() { |
| 1792 UnlinkedExecutable executable = serializeClassText( | 1794 UnlinkedExecutable executable = serializeClassText( |
| 1793 'class C { void operator[]=(int i, bool v) => null; }').executables[0]; | 1795 'class C { void operator[]=(int i, bool v) => null; }') |
| 1796 .executables[0]; | |
| 1794 expect(executable.kind, UnlinkedExecutableKind.functionOrMethod); | 1797 expect(executable.kind, UnlinkedExecutableKind.functionOrMethod); |
| 1795 expect(executable.name, '[]='); | 1798 expect(executable.name, '[]='); |
| 1796 expect(executable.hasImplicitReturnType, false); | 1799 expect(executable.hasImplicitReturnType, false); |
| 1797 expect(executable.isAbstract, false); | 1800 expect(executable.isAbstract, false); |
| 1798 expect(executable.isConst, false); | 1801 expect(executable.isConst, false); |
| 1799 expect(executable.isFactory, false); | 1802 expect(executable.isFactory, false); |
| 1800 expect(executable.isStatic, false); | 1803 expect(executable.isStatic, false); |
| 1801 expect(executable.parameters, hasLength(2)); | 1804 expect(executable.parameters, hasLength(2)); |
| 1802 expect(executable.returnType, isNull); | 1805 expect(executable.returnType, isNull); |
| 1803 expect(executable.typeParameters, isEmpty); | 1806 expect(executable.typeParameters, isEmpty); |
| (...skipping 751 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2555 test_type_reference_from_part() { | 2558 test_type_reference_from_part() { |
| 2556 addNamedSource('/a.dart', 'part of foo; C v;'); | 2559 addNamedSource('/a.dart', 'part of foo; C v;'); |
| 2557 serializeLibraryText('library foo; part "a.dart"; class C {}'); | 2560 serializeLibraryText('library foo; part "a.dart"; class C {}'); |
| 2558 checkTypeRef(findVariable('v', variables: unlinkedUnits[1].variables).type, | 2561 checkTypeRef(findVariable('v', variables: unlinkedUnits[1].variables).type, |
| 2559 null, null, 'C', | 2562 null, null, 'C', |
| 2560 expectedKind: PrelinkedReferenceKind.classOrEnum, | 2563 expectedKind: PrelinkedReferenceKind.classOrEnum, |
| 2561 prelinkedSourceUnit: prelinked.units[1], | 2564 prelinkedSourceUnit: prelinked.units[1], |
| 2562 unlinkedSourceUnit: unlinkedUnits[1]); | 2565 unlinkedSourceUnit: unlinkedUnits[1]); |
| 2563 } | 2566 } |
| 2564 | 2567 |
| 2568 test_type_reference_from_part_withPrefix() { | |
| 2569 addNamedSource('/a.dart', 'class C {}'); | |
|
Paul Berry
2016/01/11 21:39:54
(Capturing a discussion we just had in person): le
| |
| 2570 addNamedSource('/p.dart', 'part of foo; C v; a.C v2;'); | |
| 2571 serializeLibraryText( | |
| 2572 'library foo; import "a.dart"; import "a.dart" as a; part "p.dart";'); | |
| 2573 checkTypeRef(findVariable('v2', variables: unlinkedUnits[1].variables).type, | |
| 2574 absUri('/a.dart'), 'a.dart', 'C', | |
| 2575 expectedPrefix: 'a', | |
| 2576 prelinkedSourceUnit: prelinked.units[1], | |
| 2577 unlinkedSourceUnit: unlinkedUnits[1]); | |
| 2578 } | |
| 2579 | |
| 2565 test_type_reference_to_class_argument() { | 2580 test_type_reference_to_class_argument() { |
| 2566 UnlinkedClass cls = serializeClassText('class C<T, U> { T t; U u; }'); | 2581 UnlinkedClass cls = serializeClassText('class C<T, U> { T t; U u; }'); |
| 2567 { | 2582 { |
| 2568 UnlinkedTypeRef typeRef = | 2583 UnlinkedTypeRef typeRef = |
| 2569 findVariable('t', variables: cls.fields, failIfAbsent: true).type; | 2584 findVariable('t', variables: cls.fields, failIfAbsent: true).type; |
| 2570 checkParamTypeRef(typeRef, 2); | 2585 checkParamTypeRef(typeRef, 2); |
| 2571 } | 2586 } |
| 2572 { | 2587 { |
| 2573 UnlinkedTypeRef typeRef = | 2588 UnlinkedTypeRef typeRef = |
| 2574 findVariable('u', variables: cls.fields, failIfAbsent: true).type; | 2589 findVariable('u', variables: cls.fields, failIfAbsent: true).type; |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2867 UnlinkedVariable variable = | 2882 UnlinkedVariable variable = |
| 2868 serializeVariableText('int i;', variableName: 'i'); | 2883 serializeVariableText('int i;', variableName: 'i'); |
| 2869 checkTypeRef(variable.type, 'dart:core', 'dart:core', 'int'); | 2884 checkTypeRef(variable.type, 'dart:core', 'dart:core', 'int'); |
| 2870 } | 2885 } |
| 2871 | 2886 |
| 2872 test_varible_private() { | 2887 test_varible_private() { |
| 2873 serializeVariableText('int _i;', variableName: '_i'); | 2888 serializeVariableText('int _i;', variableName: '_i'); |
| 2874 expect(unlinkedUnits[0].publicNamespace.names, isEmpty); | 2889 expect(unlinkedUnits[0].publicNamespace.names, isEmpty); |
| 2875 } | 2890 } |
| 2876 } | 2891 } |
| OLD | NEW |