Blade
Blade copied to clipboard
Generate assertions from standard Android annotations
When method parameter is annotated with @NonNull
-> generate runtime assertions in code like this:
void foo(@NonNull final String param) {
/* Code generated by Blade */
if (param == null) {
throw new AssertionError("text == null");
}
/* ~ */
// Actual method code here
}
Consider adding support for other Android support annotations e.g.:
@IntRange
:
void foo(@IntRange(from=0) final int index) {
/* Code generated by Blade */
if (index < 0) {
throw new AssertionError("index < 0");
}
/* ~ */
// Actual method code here
}
Other possible assertions for: @FloatRange, @Size, @UiThread, @WorkerThread, @RequiresApi
[idea] And what about when method has annotated return value like this:
@NonNull
public String foo() {
// Actual method code here
String returnVal = null;
/* Code modified by Blade */
if (returnVal == null) {
throw new AssertionError("return value of method foo is null");
}
return returnVal;
/* ~ */
}
@yuraj11 do you think there will be a need for an ignore mechanism or should the Blade process every method with supported annotation?
I think It's not needed right now or at least in the first implementation (will see in future).