Visitar URL original
Enum support in Pigeon by GaryQian · Pull Request #331 · flutter/packages · GitHub
Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use references to determine enums
  • Loading branch information
GaryQian committed May 14, 2021
commit 95dee6829ef81aa2a3172cf1bd0fab7576db98a9
28 changes: 20 additions & 8 deletions packages/pigeon/lib/pigeon_lib.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,6 @@ class FlutterApi {
const FlutterApi();
}

/// Metadata to annotate PigeonEnums with to distinguish it from other
/// enums that exist in the library.
class PigeonEnum {
const PigeonEnum();
}

/// Represents an error as a result of parsing and generating code.
class Error {
/// Parametric constructor for Error.
Expand Down Expand Up @@ -243,13 +237,12 @@ class Pigeon {
final Set<ClassMirror> classes = <ClassMirror>{};
final Set<ClassMirror> enums = <ClassMirror>{};
final List<ClassMirror> apis = <ClassMirror>[];
final Set<String> typesReferenced = <String>{};

for (final Type type in types) {
final ClassMirror classMirror = reflectClass(type);
if (_isApi(classMirror)) {
apis.add(classMirror);
} else if (_isEnum(classMirror)) {
enums.add(classMirror);
} else {
classes.add(classMirror);
}
Expand All @@ -276,6 +269,25 @@ class Pigeon {
}
}
}
// Parse referenced enum types out of classes.
for (final ClassMirror klass in classes) {
for (final DeclarationMirror declaration
in klass.declarations.values) {
if (declaration is MethodMirror && !declaration.isConstructor) {
if (!isVoid(declaration.returnType) && (declaration.returnType as ClassMirror).isEnum) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you have to check isVoid here?

enums.add(declaration.returnType as ClassMirror);
}
if (declaration.parameters.isNotEmpty && (declaration.parameters[0].type as ClassMirror).isEnum) {
enums.add(declaration.parameters[0].type as ClassMirror);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still for naked arguments, right?

} else if (declaration is VariableMirror) {
if ((declaration.type as ClassMirror).isEnum) {
enums.add(declaration.type as ClassMirror);
}
}

}
}
final Root root = Root(
classes:
_unique(_parseClassMirrors(classes), (Class x) => x.name).toList(),
Expand Down