Clean up lazy_ast a bit.
R=brianwilkerson@google.com
Change-Id: Idf4ca6535088e5646474ac8728dbc6cff44eac4e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/105348
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
diff --git a/pkg/analyzer/lib/src/summary2/lazy_ast.dart b/pkg/analyzer/lib/src/summary2/lazy_ast.dart
index 57fa474..9537838 100644
--- a/pkg/analyzer/lib/src/summary2/lazy_ast.dart
+++ b/pkg/analyzer/lib/src/summary2/lazy_ast.dart
@@ -115,9 +115,8 @@
LinkedUnitContext context,
ClassDeclaration node,
) {
- var lazy = LazyClassDeclaration.get(node);
+ var lazy = get(node);
if (lazy != null) {
- var lazy = get(node);
return context.getInformativeData(lazy.data)?.codeLength ?? 0;
}
return node.length;
@@ -127,9 +126,8 @@
LinkedUnitContext context,
ClassDeclaration node,
) {
- var lazy = LazyClassDeclaration.get(node);
+ var lazy = get(node);
if (lazy != null) {
- var lazy = get(node);
return context.getInformativeData(lazy.data)?.codeOffset ?? 0;
}
return node.offset;
@@ -139,7 +137,7 @@
LinkedUnitContext context,
ClassDeclaration node,
) {
- var lazy = LazyClassDeclaration.get(node);
+ var lazy = get(node);
if (lazy != null && !lazy._hasDocumentationComment) {
node.documentationComment = context.createComment(lazy.data);
lazy._hasDocumentationComment = true;
@@ -163,7 +161,7 @@
AstBinaryReader reader,
ClassDeclaration node,
) {
- var lazy = LazyClassDeclaration.get(node);
+ var lazy = get(node);
if (lazy != null && !lazy._hasImplementsClause) {
node.implementsClause = reader.readNode(
lazy.data.classOrMixinDeclaration_implementsClause,
@@ -176,7 +174,7 @@
AstBinaryReader reader,
ClassDeclaration node,
) {
- var lazy = LazyClassDeclaration.get(node);
+ var lazy = get(node);
if (lazy != null && !lazy._hasMembers) {
var dataList = lazy.data.classOrMixinDeclaration_members;
for (var i = 0; i < dataList.length; ++i) {
@@ -191,7 +189,7 @@
AstBinaryReader reader,
ClassDeclaration node,
) {
- var lazy = LazyClassDeclaration.get(node);
+ var lazy = get(node);
if (lazy != null && !lazy._hasMetadata) {
var dataList = lazy.data.annotatedNode_metadata;
for (var i = 0; i < dataList.length; ++i) {
@@ -206,7 +204,7 @@
AstBinaryReader reader,
ClassDeclaration node,
) {
- var lazy = LazyClassDeclaration.get(node);
+ var lazy = get(node);
if (lazy != null && !lazy._hasWithClause) {
node.withClause = reader.readNode(
lazy.data.classDeclaration_withClause,
@@ -242,9 +240,8 @@
LinkedUnitContext context,
ClassTypeAlias node,
) {
- var lazy = LazyClassTypeAlias.get(node);
+ var lazy = get(node);
if (lazy != null) {
- var lazy = get(node);
return context.getInformativeData(lazy.data)?.codeLength ?? 0;
}
return node.length;
@@ -254,9 +251,8 @@
LinkedUnitContext context,
ClassTypeAlias node,
) {
- var lazy = LazyClassTypeAlias.get(node);
+ var lazy = get(node);
if (lazy != null) {
- var lazy = get(node);
return context.getInformativeData(lazy.data)?.codeOffset ?? 0;
}
return node.offset;
@@ -266,7 +262,7 @@
LinkedUnitContext context,
ClassTypeAlias node,
) {
- var lazy = LazyClassTypeAlias.get(node);
+ var lazy = get(node);
if (lazy != null && !lazy._hasDocumentationComment) {
node.documentationComment = context.createComment(lazy.data);
lazy._hasDocumentationComment = true;
@@ -277,7 +273,7 @@
AstBinaryReader reader,
ClassTypeAlias node,
) {
- var lazy = LazyClassTypeAlias.get(node);
+ var lazy = get(node);
if (lazy != null && !lazy._hasImplementsClause) {
node.implementsClause = reader.readNode(
lazy.data.classTypeAlias_implementsClause,
@@ -305,14 +301,12 @@
AstBinaryReader reader,
ClassTypeAlias node,
) {
- if (reader.isLazy) {
- var lazy = get(node);
- if (!lazy._hasSuperclass) {
- node.superclass = reader.readNode(
- lazy.data.classTypeAlias_superclass,
- );
- lazy._hasSuperclass = true;
- }
+ var lazy = get(node);
+ if (lazy != null && !lazy._hasSuperclass) {
+ node.superclass = reader.readNode(
+ lazy.data.classTypeAlias_superclass,
+ );
+ lazy._hasSuperclass = true;
}
}
@@ -320,7 +314,7 @@
AstBinaryReader reader,
ClassTypeAlias node,
) {
- var lazy = LazyClassTypeAlias.get(node);
+ var lazy = get(node);
if (lazy != null && !lazy._hasWithClause) {
node.withClause = reader.readNode(
lazy.data.classTypeAlias_withClause,
@@ -350,9 +344,8 @@
LinkedUnitContext context,
CompilationUnit node,
) {
- var lazy = LazyCompilationUnit.get(node);
+ var lazy = get(node);
if (lazy != null) {
- var lazy = get(node);
return context.getInformativeData(lazy.data)?.codeLength ?? 0;
}
return node.length;
@@ -362,9 +355,8 @@
LinkedUnitContext context,
CompilationUnit node,
) {
- var lazy = LazyCompilationUnit.get(node);
+ var lazy = get(node);
if (lazy != null) {
- var lazy = get(node);
return context.getInformativeData(lazy.data)?.codeOffset ?? 0;
}
return node.offset;
@@ -397,9 +389,8 @@
LinkedUnitContext context,
ConstructorDeclaration node,
) {
- var lazy = LazyConstructorDeclaration.get(node);
+ var lazy = get(node);
if (lazy != null) {
- var lazy = get(node);
return context.getInformativeData(lazy.data)?.codeLength ?? 0;
}
return node.length;
@@ -409,9 +400,8 @@
LinkedUnitContext context,
ConstructorDeclaration node,
) {
- var lazy = LazyConstructorDeclaration.get(node);
+ var lazy = get(node);
if (lazy != null) {
- var lazy = get(node);
return context.getInformativeData(lazy.data)?.codeOffset ?? 0;
}
return node.offset;
@@ -434,7 +424,7 @@
LinkedUnitContext context,
ConstructorDeclaration node,
) {
- var lazy = LazyConstructorDeclaration.get(node);
+ var lazy = get(node);
if (lazy != null && !lazy._hasDocumentationComment) {
node.documentationComment = context.createComment(lazy.data);
lazy._hasDocumentationComment = true;
@@ -445,7 +435,7 @@
AstBinaryReader reader,
ConstructorDeclaration node,
) {
- var lazy = LazyConstructorDeclaration.get(node);
+ var lazy = get(node);
if (lazy != null && !lazy._hasFormalParameters) {
node.parameters = reader.readNode(
lazy.data.constructorDeclaration_parameters,
@@ -608,9 +598,8 @@
LinkedUnitContext context,
EnumDeclaration node,
) {
- var lazy = LazyEnumDeclaration.get(node);
+ var lazy = get(node);
if (lazy != null) {
- var lazy = get(node);
return context.getInformativeData(lazy.data)?.codeLength ?? 0;
}
return node.length;
@@ -620,9 +609,8 @@
LinkedUnitContext context,
EnumDeclaration node,
) {
- var lazy = LazyEnumDeclaration.get(node);
+ var lazy = get(node);
if (lazy != null) {
- var lazy = get(node);
return context.getInformativeData(lazy.data)?.codeOffset ?? 0;
}
return node.offset;
@@ -741,9 +729,8 @@
LinkedUnitContext context,
FormalParameter node,
) {
- var lazy = LazyFormalParameter.get(node);
+ var lazy = get(node);
if (lazy != null) {
- var lazy = get(node);
return context.getInformativeData(lazy.data)?.codeLength ?? 0;
}
return node.length;
@@ -753,9 +740,8 @@
LinkedUnitContext context,
FormalParameter node,
) {
- var lazy = LazyFormalParameter.get(node);
+ var lazy = get(node);
if (lazy != null) {
- var lazy = get(node);
return context.getInformativeData(lazy.data)?.codeOffset ?? 0;
}
return node.offset;
@@ -765,13 +751,11 @@
AstBinaryReader reader,
FormalParameter node,
) {
- if (reader.isLazy) {
- var lazy = get(node);
- if (!lazy._hasType) {
- var type = reader.readType(lazy.data.actualType);
- LazyAst.setType(node, type);
- lazy._hasType = true;
- }
+ var lazy = get(node);
+ if (lazy != null && !lazy._hasType) {
+ var type = reader.readType(lazy.data.actualType);
+ LazyAst.setType(node, type);
+ lazy._hasType = true;
}
return LazyAst.getType(node);
}
@@ -787,7 +771,7 @@
}
static bool hasDefaultValue(DefaultFormalParameter node) {
- var lazy = LazyFormalParameter.get(node);
+ var lazy = get(node);
if (lazy != null) {
return AstBinaryFlags.hasInitializer(lazy.data.flags);
} else {
@@ -799,14 +783,12 @@
AstBinaryReader reader,
DefaultFormalParameter node,
) {
- if (reader.isLazy) {
- var lazy = LazyFormalParameter.get(node);
- if (lazy != null && !lazy._hasDefaultValue) {
- node.defaultValue = reader.readNode(
- lazy.data.defaultFormalParameter_defaultValue,
- );
- lazy._hasDefaultValue = true;
- }
+ var lazy = get(node);
+ if (lazy != null && !lazy._hasDefaultValue) {
+ node.defaultValue = reader.readNode(
+ lazy.data.defaultFormalParameter_defaultValue,
+ );
+ lazy._hasDefaultValue = true;
}
}
@@ -848,16 +830,14 @@
AstBinaryReader reader,
FormalParameter node,
) {
- if (reader.isLazy) {
- var lazy = get(node);
- if (lazy != null && !lazy._hasTypeNode) {
- if (node is SimpleFormalParameter) {
- node.type = reader.readNode(
- lazy.data.simpleFormalParameter_type,
- );
- }
- lazy._hasTypeNode = true;
+ var lazy = get(node);
+ if (lazy != null && !lazy._hasTypeNode) {
+ if (node is SimpleFormalParameter) {
+ node.type = reader.readNode(
+ lazy.data.simpleFormalParameter_type,
+ );
}
+ lazy._hasTypeNode = true;
}
}
@@ -886,9 +866,8 @@
LinkedUnitContext context,
FunctionDeclaration node,
) {
- var lazy = LazyFunctionDeclaration.get(node);
+ var lazy = get(node);
if (lazy != null) {
- var lazy = get(node);
return context.getInformativeData(lazy.data)?.codeLength ?? 0;
}
return node.length;
@@ -898,9 +877,8 @@
LinkedUnitContext context,
FunctionDeclaration node,
) {
- var lazy = LazyFunctionDeclaration.get(node);
+ var lazy = get(node);
if (lazy != null) {
- var lazy = get(node);
return context.getInformativeData(lazy.data)?.codeOffset ?? 0;
}
return node.offset;
@@ -911,14 +889,14 @@
FunctionDeclaration node,
) {
readFunctionExpression(reader, node);
- if (reader.isLazy) {
- var lazy = get(node);
- if (!lazy._hasReturnType) {
- var type = reader.readType(lazy.data.actualReturnType);
- LazyAst.setReturnType(node, type);
- lazy._hasReturnType = true;
- }
+
+ var lazy = get(node);
+ if (lazy != null && !lazy._hasReturnType) {
+ var type = reader.readType(lazy.data.actualReturnType);
+ LazyAst.setReturnType(node, type);
+ lazy._hasReturnType = true;
}
+
return LazyAst.getReturnType(node);
}
@@ -926,7 +904,7 @@
LinkedUnitContext context,
FunctionDeclaration node,
) {
- var lazy = LazyFunctionDeclaration.get(node);
+ var lazy = get(node);
if (lazy != null && !lazy._hasDocumentationComment) {
node.documentationComment = context.createComment(lazy.data);
lazy._hasDocumentationComment = true;
@@ -938,7 +916,7 @@
FunctionDeclaration node,
) {
if (node.functionExpression == null) {
- var lazy = LazyFunctionDeclaration.get(node);
+ var lazy = get(node);
node.functionExpression = reader.readNode(
lazy.data.functionDeclaration_functionExpression,
);
@@ -1063,9 +1041,8 @@
LinkedUnitContext context,
FunctionTypeAlias node,
) {
- var lazy = LazyFunctionTypeAlias.get(node);
+ var lazy = get(node);
if (lazy != null) {
- var lazy = get(node);
return context.getInformativeData(lazy.data)?.codeLength ?? 0;
}
return node.length;
@@ -1075,9 +1052,8 @@
LinkedUnitContext context,
FunctionTypeAlias node,
) {
- var lazy = LazyFunctionTypeAlias.get(node);
+ var lazy = get(node);
if (lazy != null) {
- var lazy = get(node);
return context.getInformativeData(lazy.data)?.codeOffset ?? 0;
}
return node.offset;
@@ -1091,13 +1067,11 @@
AstBinaryReader reader,
FunctionTypeAlias node,
) {
- if (reader.isLazy) {
- var lazy = get(node);
- if (!lazy._hasReturnType) {
- var type = reader.readType(lazy.data.actualReturnType);
- LazyAst.setReturnType(node, type);
- lazy._hasReturnType = true;
- }
+ var lazy = get(node);
+ if (lazy != null && !lazy._hasReturnType) {
+ var type = reader.readType(lazy.data.actualReturnType);
+ LazyAst.setReturnType(node, type);
+ lazy._hasReturnType = true;
}
return LazyAst.getReturnType(node);
}
@@ -1117,7 +1091,7 @@
AstBinaryReader reader,
FunctionTypeAlias node,
) {
- var lazy = LazyFunctionTypeAlias.get(node);
+ var lazy = get(node);
if (lazy != null && !lazy._hasFormalParameters) {
node.parameters = reader.readNode(
lazy.data.functionTypeAlias_formalParameters,
@@ -1184,9 +1158,8 @@
LinkedUnitContext context,
GenericTypeAlias node,
) {
- var lazy = LazyGenericTypeAlias.get(node);
+ var lazy = get(node);
if (lazy != null) {
- var lazy = get(node);
return context.getInformativeData(lazy.data)?.codeLength ?? 0;
}
return node.length;
@@ -1196,9 +1169,8 @@
LinkedUnitContext context,
GenericTypeAlias node,
) {
- var lazy = LazyGenericTypeAlias.get(node);
+ var lazy = get(node);
if (lazy != null) {
- var lazy = get(node);
return context.getInformativeData(lazy.data)?.codeOffset ?? 0;
}
return node.offset;
@@ -1279,9 +1251,8 @@
LinkedUnitContext context,
MethodDeclaration node,
) {
- var lazy = LazyMethodDeclaration.get(node);
+ var lazy = get(node);
if (lazy != null) {
- var lazy = get(node);
return context.getInformativeData(lazy.data)?.codeLength ?? 0;
}
return node.length;
@@ -1291,9 +1262,8 @@
LinkedUnitContext context,
MethodDeclaration node,
) {
- var lazy = LazyMethodDeclaration.get(node);
+ var lazy = get(node);
if (lazy != null) {
- var lazy = get(node);
return context.getInformativeData(lazy.data)?.codeOffset ?? 0;
}
return node.offset;
@@ -1303,13 +1273,11 @@
AstBinaryReader reader,
MethodDeclaration node,
) {
- if (reader.isLazy) {
- var lazy = get(node);
- if (!lazy._hasReturnType) {
- var type = reader.readType(lazy.data.actualReturnType);
- LazyAst.setReturnType(node, type);
- lazy._hasReturnType = true;
- }
+ var lazy = get(node);
+ if (lazy != null && !lazy._hasReturnType) {
+ var type = reader.readType(lazy.data.actualReturnType);
+ LazyAst.setReturnType(node, type);
+ lazy._hasReturnType = true;
}
return LazyAst.getReturnType(node);
}
@@ -1358,7 +1326,7 @@
LinkedUnitContext context,
MethodDeclaration node,
) {
- var lazy = LazyMethodDeclaration.get(node);
+ var lazy = get(node);
if (lazy != null && !lazy._hasDocumentationComment) {
node.documentationComment = context.createComment(lazy.data);
lazy._hasDocumentationComment = true;
@@ -1369,7 +1337,7 @@
AstBinaryReader reader,
MethodDeclaration node,
) {
- var lazy = LazyMethodDeclaration.get(node);
+ var lazy = get(node);
if (lazy != null && !lazy._hasFormalParameters) {
node.parameters = reader.readNode(
lazy.data.methodDeclaration_formalParameters,
@@ -1455,9 +1423,8 @@
LinkedUnitContext context,
MixinDeclaration node,
) {
- var lazy = LazyMixinDeclaration.get(node);
+ var lazy = get(node);
if (lazy != null) {
- var lazy = get(node);
return context.getInformativeData(lazy.data)?.codeLength ?? 0;
}
return node.length;
@@ -1467,9 +1434,8 @@
LinkedUnitContext context,
MixinDeclaration node,
) {
- var lazy = LazyMixinDeclaration.get(node);
+ var lazy = get(node);
if (lazy != null) {
- var lazy = get(node);
return context.getInformativeData(lazy.data)?.codeOffset ?? 0;
}
return node.offset;
@@ -1518,7 +1484,7 @@
AstBinaryReader reader,
MixinDeclaration node,
) {
- var lazy = LazyMixinDeclaration.get(node);
+ var lazy = get(node);
if (lazy.data != null && !lazy._hasMetadata) {
var dataList = lazy.data.annotatedNode_metadata;
for (var i = 0; i < dataList.length; ++i) {
@@ -1607,9 +1573,8 @@
LinkedUnitContext context,
TypeParameter node,
) {
- var lazy = LazyTypeParameter.get(node);
+ var lazy = get(node);
if (lazy != null) {
- var lazy = get(node);
return context.getInformativeData(lazy.data)?.codeLength ?? 0;
}
return node.length;
@@ -1619,9 +1584,8 @@
LinkedUnitContext context,
TypeParameter node,
) {
- var lazy = LazyTypeParameter.get(node);
+ var lazy = get(node);
if (lazy != null) {
- var lazy = get(node);
return context.getInformativeData(lazy.data)?.codeOffset ?? 0;
}
return node.offset;
@@ -1685,9 +1649,8 @@
LinkedUnitContext context,
VariableDeclaration node,
) {
- var lazy = LazyVariableDeclaration.get(node);
+ var lazy = get(node);
if (lazy != null) {
- var lazy = get(node);
return context.getInformativeData(lazy.data)?.codeLength ?? 0;
}
VariableDeclarationList parent = node.parent;
@@ -1702,9 +1665,8 @@
LinkedUnitContext context,
VariableDeclaration node,
) {
- var lazy = LazyVariableDeclaration.get(node);
+ var lazy = get(node);
if (lazy != null) {
- var lazy = get(node);
return context.getInformativeData(lazy.data)?.codeOffset ?? 0;
}
VariableDeclarationList parent = node.parent;
@@ -1719,13 +1681,11 @@
AstBinaryReader reader,
VariableDeclaration node,
) {
- if (reader.isLazy) {
- var lazy = get(node);
- if (!lazy._hasType) {
- var type = reader.readType(lazy.data.actualType);
- LazyAst.setType(node, type);
- lazy._hasType = true;
- }
+ var lazy = get(node);
+ if (lazy != null && !lazy._hasType) {
+ var type = reader.readType(lazy.data.actualType);
+ LazyAst.setType(node, type);
+ lazy._hasType = true;
}
return LazyAst.getType(node);
}
@@ -1754,14 +1714,12 @@
AstBinaryReader reader,
VariableDeclaration node,
) {
- if (reader.isLazy) {
- var lazy = get(node);
- if (lazy != null && !lazy._hasInitializer) {
- node.initializer = reader.readNode(
- lazy.data.variableDeclaration_initializer,
- );
- lazy._hasInitializer = true;
- }
+ var lazy = get(node);
+ if (lazy != null && !lazy._hasInitializer) {
+ node.initializer = reader.readNode(
+ lazy.data.variableDeclaration_initializer,
+ );
+ lazy._hasInitializer = true;
}
}
@@ -1787,14 +1745,12 @@
AstBinaryReader reader,
VariableDeclarationList node,
) {
- if (reader.isLazy) {
- var lazy = get(node);
- if (!lazy._hasTypeNode) {
- node.type = reader.readNode(
- lazy.data.variableDeclarationList_type,
- );
- lazy._hasTypeNode = true;
- }
+ var lazy = get(node);
+ if (lazy != null && !lazy._hasTypeNode) {
+ node.type = reader.readNode(
+ lazy.data.variableDeclarationList_type,
+ );
+ lazy._hasTypeNode = true;
}
}