mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 00:13:50 +00:00
Remove some unnecessary null checks
These were found using the unnecessary-null-checks lint. It has a bug that prevents us from enabling it at the moment, but we should consider enabling it once the bug has been fixed. Change-Id: Ice250b5a6a8723c5f08dec5b07ae738e17c842cc Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/196550 Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
parent
8a0897c165
commit
eb1ce5d640
|
@ -440,7 +440,7 @@ class KytheDartVisitor extends GeneralizingAstVisitor<void> with OutputUtils {
|
|||
void visitEnumConstantDeclaration(EnumConstantDeclaration node) {
|
||||
// constant node
|
||||
var constDeclVName =
|
||||
addNodeAndFacts(schema.CONSTANT_KIND, element: node.declaredElement!);
|
||||
addNodeAndFacts(schema.CONSTANT_KIND, element: node.declaredElement);
|
||||
|
||||
// anchor- defines/binding, defines
|
||||
addAnchorEdgesContainingEdge(
|
||||
|
|
|
@ -123,7 +123,7 @@ class FixesCodeActionsTest extends AbstractCodeActionsTest {
|
|||
CodeActionKind('quickfix.create.file'), "Create file 'newfile.dart'")!;
|
||||
|
||||
final edit = fixAction.edit!;
|
||||
expect(edit.documentChanges!, isNotNull);
|
||||
expect(edit.documentChanges, isNotNull);
|
||||
|
||||
// Ensure applying the changes creates the file and with the expected content.
|
||||
final contents = {
|
||||
|
|
|
@ -110,7 +110,7 @@ class SocketServerTest {
|
|||
null);
|
||||
|
||||
server.createAnalysisServer(channel);
|
||||
errorNotifier.server = server.analysisServer!;
|
||||
errorNotifier.server = server.analysisServer;
|
||||
AnalysisEngine.instance.instrumentationService = errorNotifier;
|
||||
|
||||
return server;
|
||||
|
|
|
@ -23,7 +23,7 @@ const String _SERVER_DIR = ".dartServer";
|
|||
String? _getStandardStateLocation() {
|
||||
final Map<String, String> env = io.Platform.environment;
|
||||
if (env.containsKey('ANALYZER_STATE_LOCATION_OVERRIDE')) {
|
||||
return env['ANALYZER_STATE_LOCATION_OVERRIDE']!;
|
||||
return env['ANALYZER_STATE_LOCATION_OVERRIDE'];
|
||||
}
|
||||
|
||||
final home = io.Platform.isWindows ? env['LOCALAPPDATA'] : env['HOME'];
|
||||
|
|
|
@ -94,7 +94,7 @@ class ElementNameComponents {
|
|||
String? classMemberName;
|
||||
if (element.enclosingElement is ClassElement ||
|
||||
element.enclosingElement is ExtensionElement) {
|
||||
classMemberName = element.name!;
|
||||
classMemberName = element.name;
|
||||
element = element.enclosingElement!;
|
||||
}
|
||||
|
||||
|
|
|
@ -85,7 +85,7 @@ class GatherUsedLocalElementsVisitor extends RecursiveAstVisitor<void> {
|
|||
@override
|
||||
void visitFunctionExpression(FunctionExpression node) {
|
||||
if (node.parent is! FunctionDeclaration) {
|
||||
usedElements.addElement(node.declaredElement!);
|
||||
usedElements.addElement(node.declaredElement);
|
||||
}
|
||||
super.visitFunctionExpression(node);
|
||||
}
|
||||
|
|
|
@ -467,10 +467,10 @@ class AstBuilder extends StackListener {
|
|||
target = target.function;
|
||||
} else if (target is MethodInvocation) {
|
||||
argumentList = target.argumentList;
|
||||
target = target.target!;
|
||||
target = target.target;
|
||||
} else if (target is PropertyAccess) {
|
||||
argumentList = null;
|
||||
target = target.target!;
|
||||
target = target.target;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -561,7 +561,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
|
|||
void visitEnumDeclaration(EnumDeclaration node) {
|
||||
var outerEnum = _enclosingEnum;
|
||||
try {
|
||||
_enclosingEnum = node.declaredElement!;
|
||||
_enclosingEnum = node.declaredElement;
|
||||
_duplicateDefinitionVerifier.checkEnum(node);
|
||||
super.visitEnumDeclaration(node);
|
||||
} finally {
|
||||
|
|
|
@ -1221,7 +1221,7 @@ class ResolverVisitor extends ScopedVisitor with ErrorDetectionHelpers {
|
|||
@override
|
||||
void visitConstructorDeclaration(ConstructorDeclaration node) {
|
||||
var outerFunction = _enclosingFunction;
|
||||
_enclosingFunction = node.declaredElement!;
|
||||
_enclosingFunction = node.declaredElement;
|
||||
|
||||
flowAnalysis!.topLevelDeclaration_enter(node, node.parameters, node.body);
|
||||
flowAnalysis!.executableDeclaration_enter(node, node.parameters, false);
|
||||
|
@ -1510,7 +1510,7 @@ class ResolverVisitor extends ScopedVisitor with ErrorDetectionHelpers {
|
|||
@override
|
||||
void visitFunctionExpression(covariant FunctionExpressionImpl node) {
|
||||
var outerFunction = _enclosingFunction;
|
||||
_enclosingFunction = node.declaredElement!;
|
||||
_enclosingFunction = node.declaredElement;
|
||||
|
||||
if (node.parent is FunctionDeclaration) {
|
||||
_functionExpressionResolver.resolve(node);
|
||||
|
@ -1711,7 +1711,7 @@ class ResolverVisitor extends ScopedVisitor with ErrorDetectionHelpers {
|
|||
@override
|
||||
void visitMethodDeclaration(MethodDeclaration node) {
|
||||
var outerFunction = _enclosingFunction;
|
||||
_enclosingFunction = node.declaredElement!;
|
||||
_enclosingFunction = node.declaredElement;
|
||||
|
||||
flowAnalysis!.topLevelDeclaration_enter(node, node.parameters, node.body);
|
||||
flowAnalysis!.executableDeclaration_enter(node, node.parameters, false);
|
||||
|
|
|
@ -303,7 +303,7 @@ class _PSNode implements PSNode {
|
|||
@override
|
||||
Source get source => (resourceProvider ?? PhysicalResourceProvider.INSTANCE)
|
||||
.getFile(span.sourceUrl!.toFilePath())
|
||||
.createSource(span.sourceUrl!);
|
||||
.createSource(span.sourceUrl);
|
||||
|
||||
@override
|
||||
String toString() => '$text';
|
||||
|
|
|
@ -62,7 +62,7 @@ class ReferenceResolver extends ThrowingAstVisitor<void> {
|
|||
var outerReference = reference;
|
||||
|
||||
var element = node.declaredElement as ClassElementImpl;
|
||||
reference = element.reference!;
|
||||
reference = element.reference;
|
||||
element.accessors; // create elements
|
||||
element.constructors; // create elements
|
||||
element.methods; // create elements
|
||||
|
@ -91,7 +91,7 @@ class ReferenceResolver extends ThrowingAstVisitor<void> {
|
|||
var outerReference = reference;
|
||||
|
||||
var element = node.declaredElement as ClassElementImpl;
|
||||
reference = element.reference!;
|
||||
reference = element.reference;
|
||||
|
||||
_createTypeParameterElements(element, node.typeParameters);
|
||||
scope = TypeParameterScope(scope, element.typeParameters);
|
||||
|
@ -119,7 +119,7 @@ class ReferenceResolver extends ThrowingAstVisitor<void> {
|
|||
var outerReference = reference;
|
||||
|
||||
var element = node.declaredElement as ConstructorElementImpl;
|
||||
reference = element.reference!;
|
||||
reference = element.reference;
|
||||
element.parameters; // create elements
|
||||
|
||||
scope = TypeParameterScope(scope, element.typeParameters);
|
||||
|
@ -153,7 +153,7 @@ class ReferenceResolver extends ThrowingAstVisitor<void> {
|
|||
var outerReference = reference;
|
||||
|
||||
var element = node.declaredElement as ExtensionElementImpl;
|
||||
reference = element.reference!;
|
||||
reference = element.reference;
|
||||
|
||||
_createTypeParameterElements(element, node.typeParameters);
|
||||
scope = TypeParameterScope(scope, element.typeParameters);
|
||||
|
@ -208,7 +208,7 @@ class ReferenceResolver extends ThrowingAstVisitor<void> {
|
|||
var outerReference = reference;
|
||||
|
||||
var element = node.declaredElement as ExecutableElementImpl;
|
||||
reference = element.reference!;
|
||||
reference = element.reference;
|
||||
element.parameters; // create elements
|
||||
|
||||
_createTypeParameterElements(
|
||||
|
@ -238,7 +238,7 @@ class ReferenceResolver extends ThrowingAstVisitor<void> {
|
|||
var outerReference = reference;
|
||||
|
||||
var element = node.declaredElement as TypeAliasElementImpl;
|
||||
reference = element.reference!;
|
||||
reference = element.reference;
|
||||
|
||||
_createTypeParameterElements(element, node.typeParameters);
|
||||
scope = TypeParameterScope(outerScope, element.typeParameters);
|
||||
|
@ -247,7 +247,7 @@ class ReferenceResolver extends ThrowingAstVisitor<void> {
|
|||
node.typeParameters?.accept(this);
|
||||
|
||||
var function = element.aliasedElement as GenericFunctionTypeElementImpl;
|
||||
reference = function.reference!;
|
||||
reference = function.reference;
|
||||
function.parameters; // create elements
|
||||
node.parameters.accept(this);
|
||||
|
||||
|
@ -291,7 +291,7 @@ class ReferenceResolver extends ThrowingAstVisitor<void> {
|
|||
|
||||
var element = GenericFunctionTypeElementImpl.forLinkedNode(
|
||||
unitReference.element as CompilationUnitElementImpl,
|
||||
reference!,
|
||||
reference,
|
||||
node,
|
||||
);
|
||||
element.parameters; // create elements
|
||||
|
@ -318,7 +318,7 @@ class ReferenceResolver extends ThrowingAstVisitor<void> {
|
|||
var outerReference = reference;
|
||||
|
||||
var element = node.declaredElement as TypeAliasElementImpl;
|
||||
reference = element.reference!;
|
||||
reference = element.reference;
|
||||
|
||||
_createTypeParameterElements(element, node.typeParameters);
|
||||
scope = TypeParameterScope(outerScope, element.typeParameters);
|
||||
|
@ -349,7 +349,7 @@ class ReferenceResolver extends ThrowingAstVisitor<void> {
|
|||
var outerReference = reference;
|
||||
|
||||
var element = node.declaredElement as ExecutableElementImpl;
|
||||
reference = element.reference!;
|
||||
reference = element.reference;
|
||||
element.parameters; // create elements
|
||||
|
||||
_createTypeParameterElements(element, node.typeParameters);
|
||||
|
@ -372,7 +372,7 @@ class ReferenceResolver extends ThrowingAstVisitor<void> {
|
|||
var outerReference = reference;
|
||||
|
||||
var element = node.declaredElement as MixinElementImpl;
|
||||
reference = element.reference!;
|
||||
reference = element.reference;
|
||||
element.accessors; // create elements
|
||||
element.constructors; // create elements
|
||||
element.methods; // create elements
|
||||
|
|
|
@ -1636,7 +1636,7 @@ class B {}
|
|||
expect(result.units, hasLength(1));
|
||||
expect(result.units![0].path, testFile);
|
||||
expect(result.units![0].content, content);
|
||||
expect(result.units![0].unit!, isNotNull);
|
||||
expect(result.units![0].unit, isNotNull);
|
||||
expect(result.units![0].errors, isEmpty);
|
||||
}
|
||||
|
||||
|
@ -1689,7 +1689,7 @@ class B {}
|
|||
expect(result.uri.toString(), 'package:test/test.dart');
|
||||
expect(result.state, ResultState.VALID);
|
||||
expect(result.content, content);
|
||||
expect(result.unit!, isNotNull);
|
||||
expect(result.unit, isNotNull);
|
||||
expect(result.errors, hasLength(0));
|
||||
|
||||
var f = result.unit!.declarations[0] as FunctionDeclaration;
|
||||
|
@ -2135,7 +2135,7 @@ var A2 = B1;
|
|||
|
||||
var result = await resultFuture;
|
||||
expect(result.path, testFile);
|
||||
expect(result.unit!, isNotNull);
|
||||
expect(result.unit, isNotNull);
|
||||
}
|
||||
|
||||
test_getResult_twoPendingFutures() async {
|
||||
|
@ -2150,7 +2150,7 @@ var A2 = B1;
|
|||
ResolvedUnitResult result2 = await future2;
|
||||
expect(result2, same(result1));
|
||||
expect(result1.path, testFile);
|
||||
expect(result1.unit!, isNotNull);
|
||||
expect(result1.unit, isNotNull);
|
||||
}
|
||||
|
||||
@deprecated
|
||||
|
@ -3158,7 +3158,7 @@ var b = new B();
|
|||
// A and B references.
|
||||
ResolvedUnitResult result = await driver.getResultValid(c);
|
||||
expect(result.errors, isNotEmpty);
|
||||
expect(result.unit!, isNotNull);
|
||||
expect(result.unit, isNotNull);
|
||||
}
|
||||
|
||||
test_part_getUnitElement2_afterLibrary() async {
|
||||
|
@ -3536,7 +3536,7 @@ var b = new B();
|
|||
// analyze the delayed parts.
|
||||
ResolvedUnitResult result = allResults.lastWhere((r) => r.path == c);
|
||||
expect(result.errors, isEmpty);
|
||||
expect(result.unit!, isNotNull);
|
||||
expect(result.unit, isNotNull);
|
||||
}
|
||||
|
||||
test_removeFile_changeFile_implicitlyAnalyzed() async {
|
||||
|
@ -3786,7 +3786,7 @@ class F extends X {}
|
|||
expect(result.path, testFile);
|
||||
expect(result.uri.toString(), 'package:test/test.dart');
|
||||
expect(result.content, content);
|
||||
expect(result.unit!, isNotNull);
|
||||
expect(result.unit, isNotNull);
|
||||
expect(result.errors, hasLength(0));
|
||||
|
||||
var f = result.unit!.declarations[0] as FunctionDeclaration;
|
||||
|
@ -3811,7 +3811,7 @@ class F extends X {}
|
|||
expect(allResults, hasLength(3));
|
||||
ResolvedUnitResult result = allResults[0];
|
||||
expect(result.path, b);
|
||||
expect(result.unit!, isNotNull);
|
||||
expect(result.unit, isNotNull);
|
||||
expect(result.errors, hasLength(0));
|
||||
}
|
||||
|
||||
|
|
|
@ -324,7 +324,7 @@ mixin ResolutionTest implements ResourceProviderMixin {
|
|||
}) {
|
||||
assertElement(node, element);
|
||||
assertType(node.extendedType, extendedType);
|
||||
assertElementTypeStrings(node.typeArgumentTypes!, typeArgumentTypes);
|
||||
assertElementTypeStrings(node.typeArgumentTypes, typeArgumentTypes);
|
||||
}
|
||||
|
||||
void assertFunctionExpressionInvocation(
|
||||
|
|
|
@ -569,7 +569,7 @@ void f() {
|
|||
assertBinaryExpression(
|
||||
findNode.binary('=='),
|
||||
element: elementMatcher(
|
||||
objectElement.getMethod('==')!,
|
||||
objectElement.getMethod('=='),
|
||||
isLegacy: isNullSafetySdkAndLegacyLibrary,
|
||||
),
|
||||
type: 'bool',
|
||||
|
@ -619,7 +619,7 @@ void f() {
|
|||
assertSimpleIdentifier(
|
||||
findNode.simple('toString'),
|
||||
element: elementMatcher(
|
||||
objectElement.getMethod('toString')!,
|
||||
objectElement.getMethod('toString'),
|
||||
isLegacy: isNullSafetySdkAndLegacyLibrary,
|
||||
),
|
||||
type: 'String Function()',
|
||||
|
@ -636,7 +636,7 @@ void f() {
|
|||
assertSimpleIdentifier(
|
||||
findNode.simple('hashCode'),
|
||||
element: elementMatcher(
|
||||
objectElement.getGetter('hashCode')!,
|
||||
objectElement.getGetter('hashCode'),
|
||||
isLegacy: isNullSafetySdkAndLegacyLibrary,
|
||||
),
|
||||
type: 'int',
|
||||
|
|
|
@ -504,7 +504,7 @@ m(B b) {
|
|||
writeElement: findElement.setter('x'),
|
||||
writeType: 'int',
|
||||
operatorElement: elementMatcher(
|
||||
numElement.getMethod('+')!,
|
||||
numElement.getMethod('+'),
|
||||
isLegacy: isNullSafetySdkAndLegacyLibrary,
|
||||
),
|
||||
type: 'int',
|
||||
|
@ -517,7 +517,7 @@ m(B b) {
|
|||
writeElement: findElement.setter('y'),
|
||||
writeType: 'int?',
|
||||
operatorElement: elementMatcher(
|
||||
numElement.getMethod('+')!,
|
||||
numElement.getMethod('+'),
|
||||
isLegacy: isNullSafetySdkAndLegacyLibrary,
|
||||
),
|
||||
type: 'int',
|
||||
|
@ -560,7 +560,7 @@ m(B b) {
|
|||
writeElement: findElement.setter('x'),
|
||||
writeType: 'int',
|
||||
operatorElement: elementMatcher(
|
||||
numElement.getMethod('+')!,
|
||||
numElement.getMethod('+'),
|
||||
isLegacy: isNullSafetySdkAndLegacyLibrary,
|
||||
),
|
||||
type: 'int?',
|
||||
|
@ -573,7 +573,7 @@ m(B b) {
|
|||
writeElement: findElement.setter('x'),
|
||||
writeType: 'int',
|
||||
operatorElement: elementMatcher(
|
||||
numElement.getMethod('+')!,
|
||||
numElement.getMethod('+'),
|
||||
isLegacy: isNullSafetySdkAndLegacyLibrary,
|
||||
),
|
||||
type: 'int',
|
||||
|
@ -607,7 +607,7 @@ m(int x, int? y) {
|
|||
writeElement: findElement.parameter('x'),
|
||||
writeType: 'int',
|
||||
operatorElement: elementMatcher(
|
||||
numElement.getMethod('+')!,
|
||||
numElement.getMethod('+'),
|
||||
isLegacy: isNullSafetySdkAndLegacyLibrary,
|
||||
),
|
||||
type: 'int',
|
||||
|
@ -620,7 +620,7 @@ m(int x, int? y) {
|
|||
writeElement: findElement.parameter('y'),
|
||||
writeType: 'int?',
|
||||
operatorElement: elementMatcher(
|
||||
numElement.getMethod('+')!,
|
||||
numElement.getMethod('+'),
|
||||
isLegacy: isNullSafetySdkAndLegacyLibrary,
|
||||
),
|
||||
type: 'int',
|
||||
|
|
|
@ -583,7 +583,7 @@ class _ElementWriter {
|
|||
writeNode(e.name);
|
||||
if (e.constructorName != null) {
|
||||
buffer.write('.');
|
||||
writeNode(e.constructorName!);
|
||||
writeNode(e.constructorName);
|
||||
}
|
||||
if (e.arguments != null) {
|
||||
writeList('(', ')', e.arguments!.arguments, ', ', writeNode,
|
||||
|
@ -598,7 +598,7 @@ class _ElementWriter {
|
|||
writeNode(e.condition);
|
||||
if (e.message != null) {
|
||||
buffer.write(', ');
|
||||
writeNode(e.message!);
|
||||
writeNode(e.message);
|
||||
}
|
||||
buffer.write(')');
|
||||
} else if (e is BinaryExpression) {
|
||||
|
@ -623,13 +623,13 @@ class _ElementWriter {
|
|||
writeNode(e.type);
|
||||
if (e.name != null) {
|
||||
buffer.write('.');
|
||||
writeNode(e.name!);
|
||||
writeNode(e.name);
|
||||
}
|
||||
} else if (e is DoubleLiteral) {
|
||||
buffer.write(e.value);
|
||||
} else if (e is GenericFunctionType) {
|
||||
if (e.returnType != null) {
|
||||
writeNode(e.returnType!);
|
||||
writeNode(e.returnType);
|
||||
buffer.write(' ');
|
||||
}
|
||||
buffer.write('Function');
|
||||
|
|
Loading…
Reference in a new issue