All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.malinskiy.sheldon.codegen.validator.GetValidator Maven / Gradle / Ivy

There is a newer version: 1.0.1
Show newest version
package com.malinskiy.sheldon.codegen.validator;

import com.google.auto.common.MoreTypes;

import com.malinskiy.sheldon.annotation.Get;
import com.malinskiy.sheldon.codegen.ProcessingException;
import com.malinskiy.sheldon.codegen.Utils;
import com.malinskiy.sheldon.codegen.model.DefaultValue;

import java.util.List;
import java.util.Map;

import javax.annotation.Nonnull;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.VariableElement;

import rx.Observable;

public class GetValidator {
    public static void checkValidGetter(@Nonnull ExecutableElement method, Map defaultsMap) throws ProcessingException {
        List parameters = method.getParameters();
        if (parameters.size() != 0) {
            throw new ProcessingException(method,
                    "Invalid number of parameters for getter. Should be zero parameters");
        }

        if (method.getAnnotation(Get.class) == null) {
            throw new ProcessingException(
                    method,
                    "No annotation @Get present. Did you annotate your method?"
            );
        }

        if (!MoreTypes.isTypeOf(Observable.class, method.getReturnType())) {
            throw new ProcessingException(
                    method,
                    "Should return Observable"
            );
        }

        if (!defaultsMap.containsKey(Utils.getName(method))) {
            throw new ProcessingException(
                    method,
                    "No default value found"
            );
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy