e2bc5513f0
The new data structure, called `DecoratedClassHierarchy`, computes and caches the variable substitutions necessary to relate a class to one of its superclasses. In future CLs, we'll use this information to create the appropriate contraints for override relationships, and to compute the correct types when a method dispatch resolves to a method declared in a superclass. Note that the analyzer uses `InhertanceManager2` both to determine what a method call resolves to and to record the appropriate substitutions. We can take advantage of its determination of what a method call resolves to (that information is stored in the resolved AST), but we need to cmopute the substitutions separately because the substitutions need to be decorated with nullability nodes. Change-Id: Ifb334972e509b77151d41f7e0700cd590d7b5417 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/106800 Commit-Queue: Paul Berry <paulberry@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Reviewed-by: Dan Rubel <danrubel@google.com>
64 lines
2.3 KiB
Dart
64 lines
2.3 KiB
Dart
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
import 'package:analyzer/dart/analysis/results.dart';
|
|
import 'package:analyzer/dart/ast/ast.dart';
|
|
import 'package:analyzer/dart/element/element.dart';
|
|
import 'package:analyzer/error/error.dart';
|
|
import 'package:analyzer/src/error/codes.dart';
|
|
import 'package:analyzer/src/generated/source.dart';
|
|
import 'package:analyzer/src/test_utilities/find_element.dart';
|
|
import 'package:analyzer/src/test_utilities/find_node.dart';
|
|
import 'package:test/test.dart';
|
|
|
|
import 'abstract_context.dart';
|
|
|
|
/// TODO(paulberry): this logic is duplicated from other packages. Find a way
|
|
/// share it, or avoid relying on it.
|
|
class AbstractSingleUnitTest extends AbstractContextTest {
|
|
bool verifyNoTestUnitErrors = true;
|
|
|
|
String testCode;
|
|
String testFile;
|
|
Source testSource;
|
|
ResolvedUnitResult testAnalysisResult;
|
|
CompilationUnit testUnit;
|
|
CompilationUnitElement testUnitElement;
|
|
LibraryElement testLibraryElement;
|
|
FindNode findNode;
|
|
FindElement findElement;
|
|
|
|
void addTestSource(String code, [Uri uri]) {
|
|
testCode = code;
|
|
testSource = addSource(testFile, code, uri);
|
|
}
|
|
|
|
Future<void> resolveTestUnit(String code) async {
|
|
addTestSource(code);
|
|
testAnalysisResult = await session.getResolvedUnit(testFile);
|
|
testUnit = testAnalysisResult.unit;
|
|
if (verifyNoTestUnitErrors) {
|
|
expect(testAnalysisResult.errors.where((AnalysisError error) {
|
|
return error.errorCode != HintCode.DEAD_CODE &&
|
|
error.errorCode != HintCode.UNUSED_CATCH_CLAUSE &&
|
|
error.errorCode != HintCode.UNUSED_CATCH_STACK &&
|
|
error.errorCode != HintCode.UNUSED_ELEMENT &&
|
|
error.errorCode != HintCode.UNUSED_FIELD &&
|
|
error.errorCode != HintCode.UNUSED_IMPORT &&
|
|
error.errorCode != HintCode.UNUSED_LOCAL_VARIABLE;
|
|
}), isEmpty);
|
|
}
|
|
testUnitElement = testUnit.declaredElement;
|
|
testLibraryElement = testUnitElement.library;
|
|
findNode = FindNode(code, testUnit);
|
|
findElement = FindElement(testUnit);
|
|
}
|
|
|
|
@override
|
|
void setUp() {
|
|
super.setUp();
|
|
testFile = convertPath('/home/test/lib/test.dart');
|
|
}
|
|
}
|