-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(luthor_generator): added custom validator for generator
- Loading branch information
1 parent
55bdd42
commit 9eb1c10
Showing
6 changed files
with
70 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
packages/luthor_generator/lib/helpers/validations/custom_validations.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import 'package:analyzer/dart/element/element.dart'; | ||
import 'package:luthor_generator/checkers.dart'; | ||
import 'package:luthor_generator/helpers/validations/base_validations.dart'; | ||
|
||
void getCustomValidations(ParameterElement param, StringBuffer buffer) { | ||
_checkAndWriteCustomValidation(buffer, param); | ||
} | ||
|
||
void _checkAndWriteCustomValidation( | ||
StringBuffer buffer, | ||
ParameterElement param, | ||
) { | ||
final customAnnotation = getAnnotation(customValidatorChecker, param); | ||
if (customAnnotation != null) { | ||
buffer.write('.custom('); | ||
final message = customAnnotation.getField('message')?.toStringValue(); | ||
final customFuntion = | ||
customAnnotation.getField('customValidator')!.toFunctionValue()!.name; | ||
|
||
buffer.write(customFuntion); | ||
if (message != null) buffer.write(", message: '$message'"); | ||
buffer.write(')'); | ||
} | ||
} |