Search in sources :

Example 11 with ProcessorException

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);
}
Also used : ExecutableType(javax.lang.model.type.ExecutableType) AnnotationMirror(javax.lang.model.element.AnnotationMirror) ProcessorException(org.realityforge.proton.ProcessorException) ExecutableElement(javax.lang.model.element.ExecutableElement) ArrayList(java.util.ArrayList)

Example 12 with ProcessorException

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);
        }
    }
}
Also used : TypeName(com.squareup.javapoet.TypeName) ProcessorException(org.realityforge.proton.ProcessorException) ExecutableElement(javax.lang.model.element.ExecutableElement) VariableElement(javax.lang.model.element.VariableElement)

Example 13 with ProcessorException

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);
    }
}
Also used : Arrays(java.util.Arrays) SupportedOptions(javax.annotation.processing.SupportedOptions) Modifier(javax.lang.model.element.Modifier) VariableElement(javax.lang.model.element.VariableElement) DeferredElementSet(org.realityforge.proton.DeferredElementSet) HashMap(java.util.HashMap) TypeElement(javax.lang.model.element.TypeElement) SupportedAnnotationTypes(javax.annotation.processing.SupportedAnnotationTypes) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ElementsUtil(org.realityforge.proton.ElementsUtil) SupportedSourceVersion(javax.annotation.processing.SupportedSourceVersion) Matcher(java.util.regex.Matcher) Diagnostic(javax.tools.Diagnostic) Map(java.util.Map) DeclaredType(javax.lang.model.type.DeclaredType) ProcessorException(org.realityforge.proton.ProcessorException) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) ArrayType(javax.lang.model.type.ArrayType) ElementKind(javax.lang.model.element.ElementKind) ExecutableType(javax.lang.model.type.ExecutableType) Collection(java.util.Collection) ExecutableElement(javax.lang.model.element.ExecutableElement) Set(java.util.Set) IOException(java.io.IOException) Element(javax.lang.model.element.Element) Types(javax.lang.model.util.Types) AnnotationsUtil(org.realityforge.proton.AnnotationsUtil) Collectors(java.util.stream.Collectors) AnnotationMirror(javax.lang.model.element.AnnotationMirror) TypeParameterElement(javax.lang.model.element.TypeParameterElement) TypeKind(javax.lang.model.type.TypeKind) AbstractStandardProcessor(org.realityforge.proton.AbstractStandardProcessor) SourceVersion(javax.lang.model.SourceVersion) List(java.util.List) TypeMirror(javax.lang.model.type.TypeMirror) MemberChecks(org.realityforge.proton.MemberChecks) RoundEnvironment(javax.annotation.processing.RoundEnvironment) TypeName(com.squareup.javapoet.TypeName) TypeVariable(javax.lang.model.type.TypeVariable) AnnotationValue(javax.lang.model.element.AnnotationValue) Pattern(java.util.regex.Pattern) Collections(java.util.Collections) ProcessorException(org.realityforge.proton.ProcessorException) VariableElement(javax.lang.model.element.VariableElement)

Aggregations

ProcessorException (org.realityforge.proton.ProcessorException)13 ExecutableElement (javax.lang.model.element.ExecutableElement)12 Nonnull (javax.annotation.Nonnull)8 AnnotationMirror (javax.lang.model.element.AnnotationMirror)7 VariableElement (javax.lang.model.element.VariableElement)7 TypeName (com.squareup.javapoet.TypeName)6 ArrayList (java.util.ArrayList)6 Element (javax.lang.model.element.Element)6 TypeElement (javax.lang.model.element.TypeElement)6 TypeParameterElement (javax.lang.model.element.TypeParameterElement)6 ExecutableType (javax.lang.model.type.ExecutableType)6 TypeMirror (javax.lang.model.type.TypeMirror)6 ArrayType (javax.lang.model.type.ArrayType)5 DeclaredType (javax.lang.model.type.DeclaredType)5 TypeVariable (javax.lang.model.type.TypeVariable)5 IOException (java.io.IOException)4 Arrays (java.util.Arrays)4 Collection (java.util.Collection)4 Collections (java.util.Collections)4 HashMap (java.util.HashMap)4