visitVariableDeclaration method

  1. @override
void visitVariableDeclaration(
  1. VariableDeclaration node
)
override

Implementation

@override
void visitVariableDeclaration(VariableDeclaration node) {
  final expression = node.initializer;
  if (expression == null) return;
  if (expression.isDotShorthand) return;

  final variableList = node.thisOrAncestorOfType<VariableDeclarationList>();
  final variableListType = variableList?.type;
  final hasExplicitType = variableListType != null;

  if (!hasExplicitType && !settings.convertImplicitDeclaration) {
    return;
  }

  if (expression is RecordLiteral &&
      variableListType is RecordTypeAnnotation) {
    _checkRecordLiteralWithTypeAnnotation(expression, variableListType);
    return;
  }

  _checkAndReport(
    expression: expression,
    declaredType: node.declaredFragment?.element.type,
    canModifyDeclaredType: true,
  );
}