mirror of
https://github.com/dart-lang/sdk
synced 2024-09-06 00:59:09 +00:00
Create a LineInfo when resynthesizing a CompilationUnitElement
Change-Id: I42c075eefacab22d519a646395ec0cdb7322a87b Reviewed-on: https://dart-review.googlesource.com/67702 Commit-Queue: Brian Wilkerson <brianwilkerson@google.com> Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
parent
2a23bc2e0b
commit
373ed6b47f
|
@ -43,6 +43,27 @@ main() {
|
|||
assertHasTarget('test = 0');
|
||||
}
|
||||
|
||||
test_fieldType() async {
|
||||
// This test mirrors test_navigation() from
|
||||
// test/integration/analysis/get_navigation_test.dart
|
||||
String text = r'''
|
||||
class Foo {}
|
||||
|
||||
class Bar {
|
||||
Foo foo;
|
||||
}
|
||||
''';
|
||||
addTestFile(text);
|
||||
await _getNavigation(testFile, text.indexOf('Foo foo'), 0);
|
||||
expect(targets, hasLength(1));
|
||||
NavigationTarget target = targets.first;
|
||||
expect(target.kind, ElementKind.CLASS);
|
||||
expect(target.offset, text.indexOf('Foo {'));
|
||||
expect(target.length, 3);
|
||||
expect(target.startLine, 1);
|
||||
expect(target.startColumn, 7);
|
||||
}
|
||||
|
||||
test_fileDoesNotExist() async {
|
||||
String file = '$projectPath/doesNotExist.dart';
|
||||
Request request = _createGetNavigationRequest(file, 0, 100);
|
||||
|
|
|
@ -72,10 +72,6 @@ class GetNavigationTest_UseCFE extends GetNavigationTest {
|
|||
@override
|
||||
bool get useCFE => true;
|
||||
|
||||
@override
|
||||
@failingTest
|
||||
test_navigation() => super.test_navigation();
|
||||
|
||||
@override
|
||||
@failingTest
|
||||
test_navigation_no_result() => super.test_navigation_no_result();
|
||||
|
|
|
@ -90,6 +90,7 @@ class KernelContext {
|
|||
// Remember Kernel libraries produced by the compiler.
|
||||
// There might be more libraries than we actually need.
|
||||
// This is probably OK, because we consume them lazily.
|
||||
var lineInfoMap = <String, LineInfo>{};
|
||||
var libraryMap = <String, kernel.Library>{};
|
||||
var libraryExistMap = <String, bool>{};
|
||||
bool coreFound = false;
|
||||
|
@ -98,8 +99,9 @@ class KernelContext {
|
|||
if (uriStr == 'dart:core') {
|
||||
coreFound = true;
|
||||
}
|
||||
libraryMap[uriStr] = library;
|
||||
FileState file = fsState.getFileForUri(library.importUri);
|
||||
lineInfoMap[uriStr] = file?.lineInfo ?? new LineInfo([0]);
|
||||
libraryMap[uriStr] = library;
|
||||
libraryExistMap[uriStr] = file?.exists ?? false;
|
||||
}
|
||||
if (!coreFound) {
|
||||
|
@ -123,8 +125,8 @@ class KernelContext {
|
|||
analysisContext.contentCache = new _ContentCacheWrapper(fsState);
|
||||
|
||||
// Create the resynthesizer bound to the analysis context.
|
||||
var resynthesizer =
|
||||
new KernelResynthesizer(analysisContext, libraryMap, libraryExistMap);
|
||||
var resynthesizer = new KernelResynthesizer(
|
||||
analysisContext, lineInfoMap, libraryMap, libraryExistMap);
|
||||
|
||||
return new KernelContext._(analysisContext, resynthesizer);
|
||||
});
|
||||
|
|
|
@ -7,6 +7,7 @@ import 'package:analyzer/dart/ast/standard_ast_factory.dart';
|
|||
import 'package:analyzer/dart/ast/token.dart';
|
||||
import 'package:analyzer/dart/element/element.dart';
|
||||
import 'package:analyzer/dart/element/type.dart';
|
||||
import 'package:analyzer/source/line_info.dart';
|
||||
import 'package:analyzer/src/context/context.dart' show AnalysisContextImpl;
|
||||
import 'package:analyzer/src/dart/element/element.dart';
|
||||
import 'package:analyzer/src/dart/element/handle.dart';
|
||||
|
@ -30,6 +31,7 @@ import 'package:path/path.dart' as pathos;
|
|||
*/
|
||||
class KernelResynthesizer implements ElementResynthesizer {
|
||||
final AnalysisContextImpl _analysisContext;
|
||||
final Map<String, LineInfo> _lineInfoMap;
|
||||
final Map<String, kernel.Library> _kernelMap;
|
||||
final Map<String, bool> _libraryExistMap;
|
||||
final Map<String, LibraryElementImpl> _libraryMap = {};
|
||||
|
@ -42,8 +44,8 @@ class KernelResynthesizer implements ElementResynthesizer {
|
|||
/// The type provider for this resynthesizer.
|
||||
SummaryTypeProvider _typeProvider;
|
||||
|
||||
KernelResynthesizer(
|
||||
this._analysisContext, this._kernelMap, this._libraryExistMap) {
|
||||
KernelResynthesizer(this._analysisContext, this._lineInfoMap, this._kernelMap,
|
||||
this._libraryExistMap) {
|
||||
_buildTypeProvider();
|
||||
_analysisContext.typeProvider = _typeProvider;
|
||||
}
|
||||
|
@ -200,14 +202,18 @@ class KernelResynthesizer implements ElementResynthesizer {
|
|||
|
||||
// Build the defining unit.
|
||||
var definingUnit = libraryContext._buildUnit(null).unit;
|
||||
definingUnit.lineInfo = _lineInfoMap[uriStr];
|
||||
libraryElement.definingCompilationUnit = definingUnit;
|
||||
|
||||
// Build units for parts.
|
||||
var parts = new List<CompilationUnitElementImpl>(kernel.parts.length);
|
||||
for (int i = 0; i < kernel.parts.length; i++) {
|
||||
var fileUri = kernel.fileUri.resolve(kernel.parts[i].partUri);
|
||||
var unitContext = libraryContext._buildUnit("$fileUri");
|
||||
parts[i] = unitContext.unit;
|
||||
var fileUriStr =
|
||||
kernel.fileUri.resolve(kernel.parts[i].partUri).toString();
|
||||
var unitContext = libraryContext._buildUnit(fileUriStr);
|
||||
var partUnit = unitContext.unit;
|
||||
partUnit.lineInfo = _lineInfoMap[fileUriStr];
|
||||
parts[i] = partUnit;
|
||||
}
|
||||
libraryElement.parts = parts;
|
||||
|
||||
|
|
|
@ -287,12 +287,14 @@ class C {
|
|||
LibraryCompilationResult libraryResult = await compiler.compile(testUri);
|
||||
|
||||
// Remember Kernel libraries produced by the compiler.
|
||||
var lineInfoMap = <String, LineInfo>{};
|
||||
var libraryMap = <String, kernel.Library>{};
|
||||
var libraryExistMap = <String, bool>{};
|
||||
for (var library in libraryResult.component.libraries) {
|
||||
String uriStr = library.importUri.toString();
|
||||
libraryMap[uriStr] = library;
|
||||
FileState file = fsState.getFileForUri(library.importUri);
|
||||
lineInfoMap[uriStr] = file?.lineInfo ?? new LineInfo([0]);
|
||||
libraryMap[uriStr] = library;
|
||||
libraryExistMap[uriStr] = file?.exists ?? false;
|
||||
}
|
||||
|
||||
|
@ -302,8 +304,8 @@ class C {
|
|||
print(_getLibraryText(library));
|
||||
}
|
||||
|
||||
var resynthesizer =
|
||||
new KernelResynthesizer(context, libraryMap, libraryExistMap);
|
||||
var resynthesizer = new KernelResynthesizer(
|
||||
context, lineInfoMap, libraryMap, libraryExistMap);
|
||||
return resynthesizer;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue