Search in sources :

Example 1 with Filter

use of org.opensolaris.opengrok.index.Filter in project OpenGrok by OpenGrok.

the class ConfigurationHelp method getSampleValue.

private static Object getSampleValue(Method setter, Object defaultValue) {
    Class paramType = setter.getParameterTypes()[0];
    Type genType = setter.getGenericParameterTypes()[0];
    if (setter.getName().equals("setBugPattern")) {
        return "Sample Bug \\#(\\d+)";
    } else if (setter.getName().equals("setReviewPattern")) {
        return "Sample Issue \\#(\\d+)";
    } else if (paramType == String.class) {
        return "user-specified-value";
    } else if (paramType == int.class) {
        return 1 + (int) defaultValue;
    } else if (paramType == short.class) {
        return (short) (1 + (short) defaultValue);
    } else if (paramType == boolean.class) {
        if (defaultValue == null)
            return null;
        return !(boolean) defaultValue;
    } else if (paramType == double.class) {
        return 1 + (double) defaultValue;
    } else if (paramType == List.class) {
        return getSampleListValue(genType);
    } else if (paramType == Map.class) {
        return getSampleMapValue(genType);
    } else if (paramType == Set.class) {
        return getSampleSetValue(genType);
    } else if (paramType == AuthorizationStack.class) {
        AuthorizationStack astck = new AuthorizationStack(AuthControlFlag.REQUIRED, "user-specified-value");
        astck.add(new AuthorizationPlugin(AuthControlFlag.REQUISITE, "user-specified-value"));
        return astck;
    } else if (paramType == Filter.class) {
        Filter flt = new Filter();
        flt.add("user-specified-(patterns)*");
        flt.add("user-specified-filename");
        flt.add("user/specified/path");
        return flt;
    } else if (paramType == IgnoredNames.class) {
        IgnoredNames inm = new IgnoredNames();
        inm.add("f:user-specified-value");
        inm.add("d:user-specified-value");
        return inm;
    } else if (paramType.isEnum()) {
        for (Object value : paramType.getEnumConstants()) {
            if (!value.equals(defaultValue))
                return value;
        }
        return null;
    } else {
        throw new UnsupportedOperationException("getSampleValue() for " + paramType + ", " + genType);
    }
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) Set(java.util.Set) HashSet(java.util.HashSet) Filter(org.opensolaris.opengrok.index.Filter) AuthorizationStack(org.opensolaris.opengrok.authorization.AuthorizationStack) AuthorizationPlugin(org.opensolaris.opengrok.authorization.AuthorizationPlugin) IgnoredNames(org.opensolaris.opengrok.index.IgnoredNames) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 AuthorizationPlugin (org.opensolaris.opengrok.authorization.AuthorizationPlugin)1 AuthorizationStack (org.opensolaris.opengrok.authorization.AuthorizationStack)1 Filter (org.opensolaris.opengrok.index.Filter)1 IgnoredNames (org.opensolaris.opengrok.index.IgnoredNames)1