Skip to content

[analysis_server] enhance generated code #49229

Closed
@asashour

Description

@asashour

As hinted in sdk/247557, formatting the generated files takes around 00:01:30.

There seems to be some areas of improvement:

  • use a single function to write the union from all similar places
  • the code of individual field inside canParse can also be unified
current
reporter.push('annotationId');
try {
  if (!obj.containsKey('annotationId')) {
    reporter.reportError('must not be undefined');
    return false;
  }
  final annotationId = obj['annotationId'];
  if (annotationId == null) {
    reporter.reportError('must not be null');
    return false;
  }
  if (annotationId is! String) {
    reporter.reportError('must be of type String');
    return false;
  }
} finally {
  reporter.pop();
}
to be
if (_validateString(obj, reporter, 'annotationId')) {
  return false;
}
  • ? No need for the trailing commas in parameters
  • No need for extra spaces which would be removed by the formatter
  • No need to ''' for string literals

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions