-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved Parameter mapping for query methods (#509)
* (refactor) streamline code generation, prepare for parameter insertion the parameter order had to be altered somewhat, therefore the tests had to be adapted a small bit * (refactor) pull out Query value object to be able to extend it more easily * (feature) Allow for parameter reuse and fix tests * (feature) Improve error messages and test coverage around query parameters * Apply suggestions from code review Co-authored-by: Vitus <[email protected]> * (refactor) address review issues - inline processParameters - improve error message for list<>notlist matching errors * (refactor) fix tests Co-authored-by: Vitus <[email protected]>
- Loading branch information
1 parent
7cc7b70
commit b0601d8
Showing
17 changed files
with
793 additions
and
188 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
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
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
69 changes: 69 additions & 0 deletions
69
floor_generator/lib/processor/error/query_processor_error.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,69 @@ | ||
// ignore_for_file: import_of_legacy_library_into_null_safe | ||
import 'package:analyzer/dart/element/element.dart'; | ||
import 'package:floor_generator/processor/error/processor_error.dart'; | ||
|
||
class QueryProcessorError { | ||
final MethodElement _methodElement; | ||
|
||
QueryProcessorError(final MethodElement methodElement) | ||
: _methodElement = methodElement; | ||
|
||
ProcessorError unusedQueryMethodParameter( | ||
final ParameterElement parameterElement, | ||
) { | ||
return ProcessorError( | ||
message: 'Query method parameters have to be used.', | ||
todo: 'Use ${parameterElement.displayName} in the query or remove it.', | ||
element: parameterElement, | ||
); | ||
} | ||
|
||
ProcessorError unknownQueryVariable( | ||
final String variableName, | ||
) { | ||
return ProcessorError( | ||
message: | ||
'Query variable `$variableName` has to exist as a method parameter.', | ||
todo: | ||
'Provide $variableName as a method parameter or remove it from the query.', | ||
element: _methodElement, | ||
); | ||
} | ||
|
||
ProcessorError queryMethodParameterIsListButVariableIsNot( | ||
final String varName, | ||
) { | ||
final name = varName.substring(1); | ||
return ProcessorError( | ||
message: | ||
'The parameter $name should be referenced like a list (`x IN ($varName)`)', | ||
todo: 'Change the type of $name to not be a List<> or' | ||
'reference it with ` IN ($varName)` (including the parentheses).', | ||
element: _methodElement, | ||
); | ||
} | ||
|
||
ProcessorError queryMethodParameterIsNormalButVariableIsList( | ||
final String varName, | ||
) { | ||
final name = varName.substring(1); | ||
return ProcessorError( | ||
message: 'The parameter $name should be referenced without `IN`', | ||
todo: 'Change the type of $name to be a List<> or' | ||
'reference it without `IN`, e.g. `IS $varName`.', | ||
element: _methodElement, | ||
); | ||
} | ||
|
||
ProcessorError queryMethodParameterIsNullable( | ||
final ParameterElement parameterElement, | ||
) { | ||
return ProcessorError( | ||
message: 'Query method parameters have to be non-nullable.', | ||
todo: 'Define ${parameterElement.displayName} as non-nullable.' | ||
'\nIf you want to assert null, change your query to use the `IS NULL`/' | ||
'`IS NOT NULL` operator without passing a nullable parameter.', | ||
element: parameterElement, | ||
); | ||
} | ||
} |
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
Oops, something went wrong.