Skip to content

Commit 3a0015d

Browse files
committed
refactor: change parseCompoundDeclaration signature
1 parent 387994e commit 3a0015d

4 files changed

Lines changed: 18 additions & 18 deletions

File tree

pkgs/swift2objc/lib/src/parser/_core/parsed_symbolgraph.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class ParsedSymbol {
6666
final InputConfig? source;
6767
final Json json;
6868
List<Declaration> declarations;
69+
Declaration get primaryDeclaration => declarations.first;
6970

7071
ParsedSymbol({
7172
required this.source,

pkgs/swift2objc/lib/src/parser/parsers/declaration_parsers/parse_compound_declaration.dart

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,13 @@ typedef CompoundTearOff<T extends CompoundDeclaration> =
2727
required List<AvailabilityInfo> availability,
2828
});
2929

30-
typedef ParsedCompound<T> = ({T compound, List<Declaration> excessMembers});
31-
32-
ParsedCompound<T> parseCompoundDeclaration<T extends CompoundDeclaration>(
30+
List<Declaration> parseCompoundDeclaration<T extends CompoundDeclaration>(
3331
Context context,
3432
ParsedSymbol symbol,
3533
ParsedSymbolgraph symbolgraph,
36-
CompoundTearOff<T> tearoffConstructor,
37-
) {
34+
CompoundTearOff<T> tearoffConstructor, {
35+
void Function(T compound, List<Declaration> excessMembers)? onExcessMembers,
36+
}) {
3837
final compoundId = parseSymbolId(symbol.json);
3938

4039
final compoundRelations =
@@ -126,15 +125,17 @@ ParsedCompound<T> parseCompoundDeclaration<T extends CompoundDeclaration>(
126125

127126
compound.nestedDeclarations.fillNestingParents(compound);
128127

129-
return (compound: compound, excessMembers: memberDeclarations);
128+
onExcessMembers?.call(compound, memberDeclarations);
129+
130+
return symbol.declarations;
130131
}
131132

132133
List<Declaration> parseClassDeclaration(
133134
Context context,
134135
ParsedSymbol classSymbol,
135136
ParsedSymbolgraph symbolgraph,
136137
) {
137-
parseCompoundDeclaration(
138+
return parseCompoundDeclaration(
138139
context,
139140
classSymbol,
140141
symbolgraph,
@@ -154,15 +155,14 @@ List<Declaration> parseClassDeclaration(
154155
nestedDeclarations: [],
155156
),
156157
);
157-
return classSymbol.declarations;
158158
}
159159

160160
List<Declaration> parseStructDeclaration(
161161
Context context,
162162
ParsedSymbol structSymbol,
163163
ParsedSymbolgraph symbolgraph,
164164
) {
165-
parseCompoundDeclaration(
165+
return parseCompoundDeclaration(
166166
context,
167167
structSymbol,
168168
symbolgraph,
@@ -182,5 +182,4 @@ List<Declaration> parseStructDeclaration(
182182
nestedDeclarations: [],
183183
),
184184
);
185-
return structSymbol.declarations;
186185
}

pkgs/swift2objc/lib/src/parser/parsers/declaration_parsers/parse_enum_declaration.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ List<Declaration> parseEnumDeclaration(
1717
ParsedSymbol symbol,
1818
ParsedSymbolgraph symbolgraph,
1919
) {
20-
final (compound: enumDecl, :excessMembers) = parseCompoundDeclaration(
20+
return parseCompoundDeclaration(
2121
context,
2222
symbol,
2323
symbolgraph,
@@ -37,9 +37,12 @@ List<Declaration> parseEnumDeclaration(
3737
initializers: [],
3838
nestedDeclarations: [],
3939
),
40+
onExcessMembers: (enumDecl, excessMembers) {
41+
enumDecl.cases.addAll(
42+
excessMembers.removeWhereType<EnumCaseDeclaration>(),
43+
);
44+
},
4045
);
41-
enumDecl.cases.addAll(excessMembers.removeWhereType<EnumCaseDeclaration>());
42-
return symbol.declarations;
4346
}
4447

4548
EnumCaseDeclaration parseEnumCaseDeclaration(

pkgs/swift2objc/lib/src/parser/parsers/parse_type.dart

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,8 @@ typedef PrefixParselet =
119119
);
120120
}
121121

122-
final type = parseDeclaration(
123-
context,
124-
symbol,
125-
symbolgraph,
126-
).first.asDeclaredType;
122+
parseDeclaration(context, symbol, symbolgraph);
123+
final type = symbol.primaryDeclaration.asDeclaredType;
127124
return (type, fragments);
128125
}
129126

0 commit comments

Comments
 (0)