use of org.realityforge.proton.ProcessorException in project react4j by react4j.
the class React4jProcessor method determinePublishMethods.
private void determinePublishMethods(@Nonnull final TypeElement typeElement, @Nonnull final ViewDescriptor descriptor) {
final List<PublishDescriptor> descriptors = new ArrayList<>();
for (final ExecutableElement method : getMethods(typeElement)) {
final AnnotationMirror annotation = AnnotationsUtil.findAnnotationByType(method, Constants.PUBLISH_CLASSNAME);
if (null != annotation) {
MemberChecks.mustBeSubclassCallable(typeElement, Constants.VIEW_CLASSNAME, Constants.PUBLISH_CLASSNAME, method);
MemberChecks.mustNotHaveAnyParameters(Constants.PUBLISH_CLASSNAME, method);
MemberChecks.mustNotHaveAnyTypeParameters(Constants.PUBLISH_CLASSNAME, method);
MemberChecks.mustReturnAValue(Constants.PUBLISH_CLASSNAME, method);
MemberChecks.mustNotThrowAnyExceptions(Constants.PUBLISH_CLASSNAME, method);
final String qualifier = AnnotationsUtil.getAnnotationValueValue(annotation, "qualifier");
final ExecutableType methodType = resolveMethodType(descriptor, method);
if (TypeKind.TYPEVAR == methodType.getReturnType().getKind()) {
throw new ProcessorException(MemberChecks.mustNot(Constants.PUBLISH_CLASSNAME, "return a type variable"), method);
}
descriptors.add(new PublishDescriptor(qualifier, method, methodType));
}
}
descriptor.setPublishDescriptors(descriptors);
}
use of org.realityforge.proton.ProcessorException in project react4j by react4j.
the class React4jProcessor method determineOnErrorMethod.
private void determineOnErrorMethod(@Nonnull final TypeElement typeElement, @Nonnull final ViewDescriptor descriptor) {
for (final ExecutableElement method : getMethods(typeElement)) {
if (AnnotationsUtil.hasAnnotationOfType(method, Constants.ON_ERROR_CLASSNAME)) {
MemberChecks.mustNotBeAbstract(Constants.ON_ERROR_CLASSNAME, method);
MemberChecks.mustBeSubclassCallable(typeElement, Constants.VIEW_CLASSNAME, Constants.ON_ERROR_CLASSNAME, method);
MemberChecks.mustNotReturnAnyValue(Constants.ON_ERROR_CLASSNAME, method);
MemberChecks.mustNotThrowAnyExceptions(Constants.ON_ERROR_CLASSNAME, method);
boolean infoFound = false;
boolean errorFound = false;
for (final VariableElement parameter : method.getParameters()) {
final TypeName typeName = TypeName.get(parameter.asType());
if (typeName.toString().equals(Constants.ERROR_INFO_CLASSNAME)) {
if (infoFound) {
throw new ProcessorException("@OnError target has multiple parameters of type " + Constants.ERROR_INFO_CLASSNAME, method);
}
infoFound = true;
} else if (typeName.toString().equals(Constants.JS_ERROR_CLASSNAME)) {
if (errorFound) {
throw new ProcessorException("@OnError target has multiple parameters of type " + Constants.JS_ERROR_CLASSNAME, method);
}
errorFound = true;
} else {
throw new ProcessorException("@OnError target has parameter of invalid type named " + parameter.getSimpleName().toString(), parameter);
}
}
descriptor.setOnError(method);
}
}
}
use of org.realityforge.proton.ProcessorException in project react4j by react4j.
the class React4jProcessor method determineDefaultInputsFields.
private void determineDefaultInputsFields(@Nonnull final ViewDescriptor descriptor) {
final List<VariableElement> defaultInputsFields = ElementsUtil.getFields(descriptor.getElement()).stream().filter(m -> AnnotationsUtil.hasAnnotationOfType(m, Constants.INPUT_DEFAULT_CLASSNAME)).collect(Collectors.toList());
for (final VariableElement field : defaultInputsFields) {
final String name = deriveInputDefaultName(field);
final InputDescriptor input = descriptor.findInputNamed(name);
if (null == input) {
throw new ProcessorException("@InputDefault target for input named '" + name + "' has no corresponding " + "@Input annotated method.", field);
}
if (!processingEnv.getTypeUtils().isAssignable(field.asType(), input.getMethodType().getReturnType())) {
throw new ProcessorException("@InputDefault target has a type that is not assignable to the " + "return type of the associated @Input annotated method.", field);
}
MemberChecks.mustBeStaticallySubclassCallable(descriptor.getElement(), Constants.VIEW_CLASSNAME, Constants.INPUT_DEFAULT_CLASSNAME, field);
MemberChecks.mustBeFinal(Constants.INPUT_DEFAULT_CLASSNAME, field);
input.setDefaultField(field);
}
}
Aggregations