|
| 1 | +// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file |
| 2 | +// for details. All rights reserved. Use of this source code is governed by a |
| 3 | +// BSD-style license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +import 'package:analyzer/dart/ast/ast.dart'; |
| 6 | +import 'package:analyzer/dart/element/element.dart'; |
| 7 | +import 'package:analyzer/src/generated/source.dart'; |
| 8 | +import 'package:nnbd_migration/instrumentation.dart'; |
| 9 | +import 'package:nnbd_migration/nnbd_migration.dart'; |
| 10 | + |
| 11 | +/// The instrumentation information gathered from the migration engine. |
| 12 | +class InstrumentationInformation { |
| 13 | + /// The node used for type sources that are always `null`. |
| 14 | + NullabilityNodeInfo always; |
| 15 | + |
| 16 | + /// A map from elements outside of the code being migrated, to the nullability |
| 17 | + /// nodes associated with the type of the element. |
| 18 | + final Map<Element, DecoratedTypeInfo> externalDecoratedType = {}; |
| 19 | + |
| 20 | + /// A map from the graph edges between nullability nodes, to information about |
| 21 | + /// the edge that was created and why it was created. |
| 22 | + final Map<EdgeInfo, EdgeOriginInfo> edgeOrigin = {}; |
| 23 | + |
| 24 | + /// The node used for type sources that are never `null`. |
| 25 | + NullabilityNodeInfo never; |
| 26 | + |
| 27 | + /// A list of the steps in the propagation of nullability information through |
| 28 | + /// the nullability graph, to report details of the step that was performed |
| 29 | + /// and why it was performed. |
| 30 | + final List<PropagationInfo> propagationSteps = []; |
| 31 | + |
| 32 | + /// The instrumentation information that is specific to a single source. |
| 33 | + final Map<Source, SourceInformation> sourceInformation = {}; |
| 34 | + |
| 35 | + /// Initialize a newly created holder of instrumentation information. |
| 36 | + InstrumentationInformation(); |
| 37 | +} |
| 38 | + |
| 39 | +/// The instrumentation information gathered from the migration engine that is |
| 40 | +/// specific to a single source. |
| 41 | +class SourceInformation { |
| 42 | + /// A map from the type annotations found in the source code, to the |
| 43 | + /// nullability nodes that are associated with that type. |
| 44 | + final Map<TypeAnnotation, NullabilityNodeInfo> explicitTypeNullability = {}; |
| 45 | + |
| 46 | + /// A map from the fixes that were decided on to the reasons for the fix. |
| 47 | + final Map<SingleNullabilityFix, List<FixReasonInfo>> fixes = {}; |
| 48 | + |
| 49 | + /// A map from AST nodes that have an implicit return type to the nullability |
| 50 | + /// node associated with the implicit return type of the AST node. The node |
| 51 | + /// can be an |
| 52 | + /// - executable declaration, |
| 53 | + /// - function-typed formal parameter declaration, |
| 54 | + /// - function type alias declaration, |
| 55 | + /// - generic function type, or |
| 56 | + /// - function expression. |
| 57 | + final Map<AstNode, DecoratedTypeInfo> implicitReturnType = {}; |
| 58 | + |
| 59 | + /// A map from AST nodes that have an implicit type to the nullability node |
| 60 | + /// associated with the implicit type of the AST node. The node can be a |
| 61 | + /// - formal parameter, |
| 62 | + /// - declared identifier, or |
| 63 | + /// - variable in a variable declaration list. |
| 64 | + final Map<AstNode, DecoratedTypeInfo> implicitType = {}; |
| 65 | + |
| 66 | + /// Called whenever the migration engine encounters an AST node with implicit |
| 67 | + /// type arguments, to report the nullability nodes associated with the |
| 68 | + /// implicit type arguments of the AST node. |
| 69 | + /// |
| 70 | + /// A map from AST nodes that have implicit type arguments to the nullability |
| 71 | + /// nodes associated with the implicit type arguments of the AST node. The |
| 72 | + /// node can be a |
| 73 | + /// - constructor redirection, |
| 74 | + /// - function expression invocation, |
| 75 | + /// - method invocation, |
| 76 | + /// - instance creation expression, |
| 77 | + /// - list/map/set literal, or |
| 78 | + /// - type annotation. |
| 79 | + final Map<AstNode, List<DecoratedTypeInfo>> implicitTypeArguments = {}; |
| 80 | + |
| 81 | + /// Initialize a newly created holder of instrumentation information that is |
| 82 | + /// specific to a single source. |
| 83 | + SourceInformation(); |
| 84 | +} |
0 commit comments