tech.harmonysoft.oss.traute.javac.text.DefaultParameterExceptionTextGenerator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of traute-javac Show documentation
Show all versions of traute-javac Show documentation
A Javac plugin which inserts null-checks into generated bytecode
package tech.harmonysoft.oss.traute.javac.text;
import org.jetbrains.annotations.NotNull;
import tech.harmonysoft.oss.traute.javac.instrumentation.parameter.ParameterToInstrumentInfo;
public class DefaultParameterExceptionTextGenerator implements ExceptionTextGenerator {
@NotNull
@Override
public String generate(@NotNull ParameterToInstrumentInfo context) {
String parameterName = context.getMethodParameter().getName().toString();
String notNullAnnotation = context.getNotNullAnnotation();
if (notNullAnnotation == null) {
return String.format(
"Argument '%s' of type %s (#%d out of %d, zero-based) must be not-null (implied by the %s) "
+ "but got null for it",
parameterName, context.getMethodParameter().getType(), context.getMethodParameterIndex(),
context.getMethodParametersNumber(), context.getNotNullByDefaultAnnotationDescription()
);
} else {
return String.format(
"Argument '%s' of type %s (#%d out of %d, zero-based) is marked by @%s but got null for it",
parameterName, context.getMethodParameter().getType(), context.getMethodParameterIndex(),
context.getMethodParametersNumber(), notNullAnnotation
);
}
}
}