| 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 16 matching lines...) Expand all Loading... |
| 27 main() { | 27 main() { |
| 28 groupSep = ' | '; | 28 groupSep = ' | '; |
| 29 runReflectiveTests(SummarizeElementsTest); | 29 runReflectiveTests(SummarizeElementsTest); |
| 30 } | 30 } |
| 31 | 31 |
| 32 /** | 32 /** |
| 33 * Override of [SummaryTest] which creates summaries from the element model. | 33 * Override of [SummaryTest] which creates summaries from the element model. |
| 34 */ | 34 */ |
| 35 @reflectiveTest | 35 @reflectiveTest |
| 36 class SummarizeElementsTest extends ResolverTestCase with SummaryTest { | 36 class SummarizeElementsTest extends ResolverTestCase with SummaryTest { |
| 37 final BuilderContext builderContext = new BuilderContext(); | |
| 38 | |
| 39 /** | 37 /** |
| 40 * The list of absolute unit URIs corresponding to the compilation units in | 38 * The list of absolute unit URIs corresponding to the compilation units in |
| 41 * [unlinkedUnits]. | 39 * [unlinkedUnits]. |
| 42 */ | 40 */ |
| 43 List<String> unitUris; | 41 List<String> unitUris; |
| 44 | 42 |
| 45 @override | 43 @override |
| 46 bool get checkAstDerivedData => false; | 44 bool get checkAstDerivedData => false; |
| 47 | 45 |
| 48 /** | 46 /** |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 serializeLibraryElement(element.library); | 87 serializeLibraryElement(element.library); |
| 90 return findClass(element.name, failIfAbsent: true); | 88 return findClass(element.name, failIfAbsent: true); |
| 91 } | 89 } |
| 92 | 90 |
| 93 /** | 91 /** |
| 94 * Serialize the given [library] element, then deserialize it and store the | 92 * Serialize the given [library] element, then deserialize it and store the |
| 95 * resulting summary in [prelinked] and [unlinkedUnits]. | 93 * resulting summary in [prelinked] and [unlinkedUnits]. |
| 96 */ | 94 */ |
| 97 void serializeLibraryElement(LibraryElement library) { | 95 void serializeLibraryElement(LibraryElement library) { |
| 98 summarize_elements.LibrarySerializationResult serializedLib = | 96 summarize_elements.LibrarySerializationResult serializedLib = |
| 99 summarize_elements.serializeLibrary( | 97 summarize_elements.serializeLibrary(library, typeProvider); |
| 100 builderContext, library, typeProvider); | |
| 101 { | 98 { |
| 102 List<int> buffer = serializedLib.prelinked.toBuffer(); | 99 List<int> buffer = serializedLib.prelinked.toBuffer(); |
| 103 prelinked = new PrelinkedLibrary.fromBuffer(buffer); | 100 prelinked = new PrelinkedLibrary.fromBuffer(buffer); |
| 104 } | 101 } |
| 105 unlinkedUnits = serializedLib.unlinkedUnits.map((UnlinkedUnitBuilder b) { | 102 unlinkedUnits = serializedLib.unlinkedUnits.map((UnlinkedUnitBuilder b) { |
| 106 List<int> buffer = b.toBuffer(); | 103 List<int> buffer = b.toBuffer(); |
| 107 return new UnlinkedUnit.fromBuffer(buffer); | 104 return new UnlinkedUnit.fromBuffer(buffer); |
| 108 }).toList(); | 105 }).toList(); |
| 109 unitUris = serializedLib.unitUris; | 106 unitUris = serializedLib.unitUris; |
| 110 } | 107 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 for (int i = 0; i < unlinkedUnits.length; i++) { | 146 for (int i = 0; i < unlinkedUnits.length; i++) { |
| 150 Source source = analysisContext.sourceFactory.forUri(unitUris[i]); | 147 Source source = analysisContext.sourceFactory.forUri(unitUris[i]); |
| 151 String text = analysisContext.getContents(source).data; | 148 String text = analysisContext.getContents(source).data; |
| 152 CharacterReader reader = new CharSequenceReader(text); | 149 CharacterReader reader = new CharSequenceReader(text); |
| 153 Scanner scanner = | 150 Scanner scanner = |
| 154 new Scanner(source, reader, AnalysisErrorListener.NULL_LISTENER); | 151 new Scanner(source, reader, AnalysisErrorListener.NULL_LISTENER); |
| 155 Parser parser = new Parser(source, AnalysisErrorListener.NULL_LISTENER); | 152 Parser parser = new Parser(source, AnalysisErrorListener.NULL_LISTENER); |
| 156 parser.parseGenericMethods = true; | 153 parser.parseGenericMethods = true; |
| 157 CompilationUnit unit = parser.parseCompilationUnit(scanner.tokenize()); | 154 CompilationUnit unit = parser.parseCompilationUnit(scanner.tokenize()); |
| 158 UnlinkedPublicNamespace namespace = | 155 UnlinkedPublicNamespace namespace = |
| 159 new UnlinkedPublicNamespace.fromBuffer(public_namespace | 156 new UnlinkedPublicNamespace.fromBuffer( |
| 160 .computePublicNamespace(builderContext, unit) | 157 public_namespace.computePublicNamespace(unit).toBuffer()); |
| 161 .toBuffer()); | |
| 162 expect(canonicalize(namespace), | 158 expect(canonicalize(namespace), |
| 163 canonicalize(unlinkedUnits[i].publicNamespace), | 159 canonicalize(unlinkedUnits[i].publicNamespace), |
| 164 reason: 'publicNamespace(${unitUris[i]})'); | 160 reason: 'publicNamespace(${unitUris[i]})'); |
| 165 } | 161 } |
| 166 } | 162 } |
| 167 } | 163 } |
| 168 | 164 |
| 169 /** | 165 /** |
| 170 * Base class containing most summary tests. This allows summary tests to be | 166 * Base class containing most summary tests. This allows summary tests to be |
| 171 * re-used to exercise all the different ways in which summaries can be | 167 * re-used to exercise all the different ways in which summaries can be |
| (...skipping 2516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2688 UnlinkedVariable variable = | 2684 UnlinkedVariable variable = |
| 2689 serializeVariableText('int i;', variableName: 'i'); | 2685 serializeVariableText('int i;', variableName: 'i'); |
| 2690 checkTypeRef(variable.type, 'dart:core', 'dart:core', 'int'); | 2686 checkTypeRef(variable.type, 'dart:core', 'dart:core', 'int'); |
| 2691 } | 2687 } |
| 2692 | 2688 |
| 2693 test_varible_private() { | 2689 test_varible_private() { |
| 2694 serializeVariableText('int _i;', variableName: '_i'); | 2690 serializeVariableText('int _i;', variableName: '_i'); |
| 2695 expect(unlinkedUnits[0].publicNamespace.names, isEmpty); | 2691 expect(unlinkedUnits[0].publicNamespace.names, isEmpty); |
| 2696 } | 2692 } |
| 2697 } | 2693 } |
| OLD | NEW |