mirror of
https://github.com/dart-lang/sdk
synced 2024-09-19 21:11:40 +00:00
analyzer: remove deprecated members of LinterContext
* `LinterContext.analysisOptions` * `LinterContext.declaredVariables` * `LinterContext.canBeConst` * `LinterContext.canBeConstConstructor` * `LinterContext.inTestDir` This is all private API; google3 is clean. Change-Id: I573037934889e24d0af1ef2a03bf65d7982a272d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/365521 Reviewed-by: Phil Quitslund <pquitslund@google.com> Commit-Queue: Samuel Rawlins <srawlins@google.com>
This commit is contained in:
parent
2e53eada36
commit
ba79c308d7
|
@ -365,11 +365,9 @@ class LibraryAnalyzer {
|
|||
var context = LinterContextImpl(
|
||||
allUnits,
|
||||
currentUnit,
|
||||
_declaredVariables,
|
||||
_typeProvider,
|
||||
_typeSystem,
|
||||
_inheritance,
|
||||
_analysisOptions,
|
||||
unitAnalysis.file.workspacePackage,
|
||||
);
|
||||
for (var linter in _analysisOptions.lintRules) {
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:analyzer/dart/analysis/declared_variables.dart';
|
||||
import 'package:analyzer/dart/analysis/features.dart';
|
||||
import 'package:analyzer/dart/ast/token.dart';
|
||||
import 'package:analyzer/dart/constant/value.dart';
|
||||
|
@ -31,7 +30,7 @@ import 'package:analyzer/src/dart/element/inheritance_manager3.dart';
|
|||
import 'package:analyzer/src/dart/element/type_system.dart';
|
||||
import 'package:analyzer/src/error/codes.dart';
|
||||
import 'package:analyzer/src/generated/engine.dart'
|
||||
show AnalysisErrorInfo, AnalysisErrorInfoImpl, AnalysisOptions;
|
||||
show AnalysisErrorInfo, AnalysisErrorInfoImpl;
|
||||
import 'package:analyzer/src/lint/analysis.dart';
|
||||
import 'package:analyzer/src/lint/io.dart';
|
||||
import 'package:analyzer/src/lint/linter_visitor.dart' show NodeLintRegistry;
|
||||
|
@ -39,7 +38,6 @@ import 'package:analyzer/src/lint/pub.dart';
|
|||
import 'package:analyzer/src/lint/registry.dart';
|
||||
import 'package:analyzer/src/lint/state.dart';
|
||||
import 'package:analyzer/src/services/lint.dart' show Linter;
|
||||
import 'package:analyzer/src/utilities/extensions/ast.dart';
|
||||
import 'package:analyzer/src/workspace/workspace.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
|
@ -188,18 +186,8 @@ class LinterConstantEvaluationResult {
|
|||
abstract class LinterContext {
|
||||
List<LinterContextUnit> get allUnits;
|
||||
|
||||
@Deprecated('This field is being removed; for access to the analysis options '
|
||||
'that apply to `allUnits`, use '
|
||||
'`currentUnit.unit.declaredElement?.session`.')
|
||||
AnalysisOptions get analysisOptions;
|
||||
|
||||
LinterContextUnit get currentUnit;
|
||||
|
||||
@Deprecated('This field is being removed; for access to the '
|
||||
'DeclaredVariables that apply to `allUnits`, use '
|
||||
'`currentUnit.unit.declaredElement?.session`.')
|
||||
DeclaredVariables get declaredVariables;
|
||||
|
||||
InheritanceManager3 get inheritanceManager;
|
||||
|
||||
WorkspacePackage? get package;
|
||||
|
@ -208,33 +196,7 @@ abstract class LinterContext {
|
|||
|
||||
TypeSystem get typeSystem;
|
||||
|
||||
/// Returns whether it would be valid for the given [expression] to have
|
||||
/// a `const` keyword.
|
||||
///
|
||||
/// The [expression] must be a node within one of the compilation units in
|
||||
/// [allUnits].
|
||||
///
|
||||
/// Note that this method can cause constant evaluation to occur, which can be
|
||||
/// computationally expensive.
|
||||
@Deprecated('Use `expression.canBeConst`')
|
||||
bool canBeConst(Expression expression);
|
||||
|
||||
/// Returns `true` if it would be valid for the given constructor declaration
|
||||
/// [node] to have a keyword of `const`.
|
||||
///
|
||||
/// The [node] is expected to be a node within one of the compilation units in
|
||||
/// [allUnits].
|
||||
///
|
||||
/// Note that this method can cause constant evaluation to occur, which can be
|
||||
/// computationally expensive.
|
||||
@Deprecated('Use `expression.canBeConstConstructor`')
|
||||
bool canBeConstConstructor(ConstructorDeclaration node);
|
||||
|
||||
/// Returns `true` if the given [unit] is in a test directory.
|
||||
@Deprecated('Use `CompilationUnitExtension.inTestDir`.')
|
||||
bool inTestDir(CompilationUnit unit);
|
||||
|
||||
/// Returns `true` if the [feature] is enabled in the library being linted.
|
||||
/// Returns whether the [feature] is enabled in the library being linted.
|
||||
bool isEnabled(Feature feature);
|
||||
}
|
||||
|
||||
|
@ -242,14 +204,9 @@ class LinterContextImpl implements LinterContext {
|
|||
@override
|
||||
final List<LinterContextUnit> allUnits;
|
||||
|
||||
// TODO(srawlins): Remove when the public accessor, `analysisOption`, is
|
||||
// removed.
|
||||
final AnalysisOptions _analysisOptions;
|
||||
@override
|
||||
final LinterContextUnit currentUnit;
|
||||
|
||||
final DeclaredVariables _declaredVariables;
|
||||
|
||||
@override
|
||||
final WorkspacePackage? package;
|
||||
@override
|
||||
|
@ -264,36 +221,11 @@ class LinterContextImpl implements LinterContext {
|
|||
LinterContextImpl(
|
||||
this.allUnits,
|
||||
this.currentUnit,
|
||||
DeclaredVariables declaredVariables,
|
||||
this.typeProvider,
|
||||
this.typeSystem,
|
||||
this.inheritanceManager,
|
||||
AnalysisOptions analysisOptions,
|
||||
this.package,
|
||||
) : _declaredVariables = declaredVariables,
|
||||
_analysisOptions = analysisOptions;
|
||||
|
||||
@override
|
||||
@Deprecated('This field is being removed; for access to the analysis options '
|
||||
'that apply to `allUnits`, use '
|
||||
'`currentUnit.unit.declaredElement?.session`.')
|
||||
AnalysisOptions get analysisOptions => _analysisOptions;
|
||||
|
||||
@override
|
||||
@Deprecated('This field is being removed; for access to the '
|
||||
'DeclaredVariables that apply to `allUnits`, use '
|
||||
'`currentUnit.unit.declaredElement?.session`.')
|
||||
DeclaredVariables get declaredVariables => _declaredVariables;
|
||||
|
||||
@override
|
||||
bool canBeConst(Expression expression) => expression.canBeConst;
|
||||
|
||||
@override
|
||||
bool canBeConstConstructor(covariant ConstructorDeclarationImpl node) =>
|
||||
node.canBeConst;
|
||||
|
||||
@override
|
||||
bool inTestDir(CompilationUnit unit) => unit.inTestDir;
|
||||
);
|
||||
|
||||
@override
|
||||
bool isEnabled(Feature feature) {
|
||||
|
@ -320,19 +252,6 @@ class LinterContextParsedImpl implements LinterContext {
|
|||
this.currentUnit,
|
||||
);
|
||||
|
||||
@override
|
||||
@Deprecated('This field is being removed; for access to the analysis options '
|
||||
'that apply to `allUnits`, use '
|
||||
'`currentUnit.unit.declaredElement?.session`.')
|
||||
AnalysisOptions get analysisOptions => throw UnimplementedError();
|
||||
|
||||
@override
|
||||
@Deprecated('This field is being removed; for access to the '
|
||||
'DeclaredVariables that apply to `allUnits`, use '
|
||||
'`currentUnit.unit.declaredElement?.session`.')
|
||||
DeclaredVariables get declaredVariables =>
|
||||
throw UnsupportedError('LinterContext with parsed results');
|
||||
|
||||
@override
|
||||
TypeProvider get typeProvider =>
|
||||
throw UnsupportedError('LinterContext with parsed results');
|
||||
|
@ -341,18 +260,6 @@ class LinterContextParsedImpl implements LinterContext {
|
|||
TypeSystem get typeSystem =>
|
||||
throw UnsupportedError('LinterContext with parsed results');
|
||||
|
||||
@override
|
||||
bool canBeConst(Expression expression) =>
|
||||
throw UnsupportedError('LinterContext with parsed results');
|
||||
|
||||
@override
|
||||
bool canBeConstConstructor(ConstructorDeclaration node) =>
|
||||
throw UnsupportedError('LinterContext with parsed results');
|
||||
|
||||
@override
|
||||
bool inTestDir(CompilationUnit unit) =>
|
||||
throw UnsupportedError('LinterContext with parsed results');
|
||||
|
||||
@override
|
||||
bool isEnabled(Feature feature) =>
|
||||
throw UnsupportedError('LinterContext with parsed results');
|
||||
|
|
|
@ -39,11 +39,9 @@ abstract class AbstractLinterContextTest extends PubPackageResolutionTest {
|
|||
context = LinterContextImpl(
|
||||
[contextUnit],
|
||||
contextUnit,
|
||||
result.session.declaredVariables,
|
||||
result.typeProvider,
|
||||
result.typeSystem as TypeSystemImpl,
|
||||
InheritanceManager3(),
|
||||
analysisOptions,
|
||||
// TODO(pq): test package or consider passing in null
|
||||
workspacePackage,
|
||||
);
|
||||
|
@ -55,7 +53,7 @@ class CanBeConstConstructorTest extends AbstractLinterContextTest {
|
|||
void assertCanBeConstConstructor(String search, bool expectedResult) {
|
||||
var constructor =
|
||||
findNode.constructor(search) as ConstructorDeclarationImpl;
|
||||
expect(context.canBeConstConstructor(constructor), expectedResult);
|
||||
expect(constructor.canBeConst, expectedResult);
|
||||
}
|
||||
|
||||
test_assertInitializer_parameter() async {
|
||||
|
@ -148,7 +146,7 @@ class C {
|
|||
class CanBeConstInstanceCreationTest extends AbstractLinterContextTest {
|
||||
void assertCanBeConst(String snippet, bool expectedResult) {
|
||||
var node = findNode.instanceCreation(snippet);
|
||||
expect(context.canBeConst(node), expectedResult);
|
||||
expect(node.canBeConst, expectedResult);
|
||||
}
|
||||
|
||||
void test_deferred_argument() async {
|
||||
|
@ -366,7 +364,7 @@ A f() => A();
|
|||
class CanBeConstTypedLiteralTest extends AbstractLinterContextTest {
|
||||
void assertCanBeConst(String snippet, bool expectedResult) {
|
||||
var node = findNode.typedLiteral(snippet);
|
||||
expect(context.canBeConst(node), expectedResult);
|
||||
expect(node.canBeConst, expectedResult);
|
||||
}
|
||||
|
||||
void test_listLiteral_false_forElement() async {
|
||||
|
|
Loading…
Reference in a new issue