Skip to content

[native_doc_dartifier] Fix format issue + Adding more test cases #2431

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
44 changes: 27 additions & 17 deletions pkgs/native_doc_dartifier/lib/src/prompts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ JNIgen handles various syntactic and semantic differences between Java/Kotlin an
* Pass each interface method as a named closure argument within the `\$InterfaceName` factory constructor.
* Example: `InterfaceName.implement(\$InterfaceName(method1: (param1) { /* ... */ }))`
* **Reusable Implementations:**
* If the Java/Kotlin code defines a class that `implements` an interface, translate it to a Dart `final class` that `with` (mixes in) the corresponding `\$`-prefixed interface (e.g., `final class MyPrinter with \$Runnable`).
* The Dart class should override the interface methods as required.
* Instantiate and pass this class to the `implement` factory: `InterfaceName.implement(MyClassImplementingInterface(...))`
* If the Java/Kotlin code defines a class that `implements` an interface, To translate it to Dart make this class to be 'final class with' \$InterfaceName, as JNIgen make a mixin class \$InterfaceName that handles this, Don't make it to implements InterfaceName only use the mixin class.
* **Asynchronous Listener Methods:**
* For `void`-returning methods in implemented interfaces that should be non-blocking (listeners), explicitly set the `<methodName>\$async` parameter to `true` when using the inline implementation (e.g., `run\$async: true`).
* If using a reusable class (mixin), override the `<methodName>\$async` getter to return `true` (e.g., `bool get run\$async => true;`).
Expand Down Expand Up @@ -108,14 +106,20 @@ $_schema

@override
String getParsedResponse(String response) {
response = response.replaceAll(r'\$', r'$').replaceAll('\\\'', '\'');
print('Response: $response');
final json = jsonDecode(response) as Map<String, dynamic>;
if (!json.containsKey('dartCode')) {
try {
final json = jsonDecode(response) as Map<String, dynamic>;
if (!json.containsKey('dartCode')) {
return '';
}
final dartCode = json['dartCode'].toString();
print('Dart Code: $dartCode');
return dartCode;
} catch (e) {
print('Error decoding JSON: $e');
return '';
}
final dartCode = json['dartCode'].toString();
print('Dart Code: $dartCode');
return dartCode;
}
}

Expand Down Expand Up @@ -156,17 +160,23 @@ Output the response in JSON format:

@override
FixResponse getParsedResponse(String response) {
response = response.replaceAll(r'\$', r'$').replaceAll('\\\'', '\'');
print('Response: $response');
final json = jsonDecode(response) as Map<String, dynamic>;
var mainDartCode = '';
var tempDartCode = '';
if (json.containsKey('mainDartCode')) {
mainDartCode = json['mainDartCode'].toString();
try {
final json = jsonDecode(response) as Map<String, dynamic>;
var mainDartCode = '';
var tempDartCode = '';
if (json.containsKey('mainDartCode')) {
mainDartCode = json['mainDartCode'].toString();
}
if (json.containsKey('helperDartCode')) {
tempDartCode = json['helperDartCode'].toString();
}
return FixResponse(mainCode: mainDartCode, helperCode: tempDartCode);
} catch (e) {
print('Error decoding JSON: $e');
return FixResponse(mainCode: '', helperCode: '');
}
if (json.containsKey('helperDartCode')) {
tempDartCode = json['helperDartCode'].toString();
}
return FixResponse(mainCode: mainDartCode, helperCode: tempDartCode);
}
}

Expand Down
Loading
Loading