Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dart: get heuristics #359

Merged
merged 2 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions example/dart/lib/lib.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions feature_tests/dart/lib/lib.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions tool/src/dart/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,11 @@ impl<'a, 'dartcx, 'tcx: 'dartcx> TyGenContext<'a, 'dartcx, 'tcx> {
&& params.is_empty()
{
"@override\n String toString()".to_string()
} else if method.name.as_str() == "get"
&& method.output.return_type().is_some()
&& method.params.len() == 1
{
format!("{return_ty} operator []({params})")
} else {
let method_name = self.cx.formatter.fmt_method_name(method);
format!("{return_ty} {method_name}({params})")
Expand Down
2 changes: 1 addition & 1 deletion tool/src/dart/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl<'tcx> DartFormatter<'tcx> {

pub fn fmt_constructor_name(&self, method: &hir::Method) -> Option<String> {
let mut name = &*self.fmt_method_name(method);
for prefix in ["create", "new", "default"] {
for prefix in ["create", "new", "default", "get"] {
name = name.strip_prefix(prefix).unwrap_or(name);
}
let name = name.to_lower_camel_case();
Expand Down
2 changes: 2 additions & 0 deletions tool/templates/dart/base.dart.jinja
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// generated by diplomat-tool

// https://github.com/dart-lang/sdk/issues/53946
// ignore_for_file: non_native_function_type_argument_to_pointer

Expand Down
Loading