Search in sources :

Example 1 with UriCompleter

use of org.apache.karaf.shell.support.completers.UriCompleter in project karaf by apache.

the class ArgumentCompleter method getDefaultCompleter.

@SuppressWarnings({ "unchecked", "rawtypes" })
private Completer getDefaultCompleter(Field field, boolean multi) {
    Completer completer = null;
    Class<?> type = field.getType();
    GenericType genericType = new GenericType(field.getGenericType());
    if (Collection.class.isAssignableFrom(genericType.getRawClass()) && multi) {
        type = genericType.getActualTypeArgument(0).getRawClass();
    }
    if (type.isAssignableFrom(URI.class)) {
        completer = new UriCompleter();
    } else if (type.isAssignableFrom(File.class)) {
        completer = new FileCompleter();
    } else if (type.isAssignableFrom(Boolean.class) || type.isAssignableFrom(boolean.class)) {
        completer = new StringsCompleter(Arrays.asList("false", "true"));
    } else if (Enum.class.isAssignableFrom(type)) {
        Set<String> values = new HashSet<>();
        for (Object o : EnumSet.allOf((Class<Enum>) type)) {
            values.add(o.toString());
        }
        completer = new StringsCompleter(values);
    }
    return completer;
}
Also used : GenericType(org.apache.karaf.shell.support.converter.GenericType) HashSet(java.util.HashSet) EnumSet(java.util.EnumSet) Set(java.util.Set) FileCompleter(org.apache.karaf.shell.support.completers.FileCompleter) UriCompleter(org.apache.karaf.shell.support.completers.UriCompleter) Completer(org.apache.karaf.shell.api.console.Completer) NullCompleter(org.apache.karaf.shell.support.completers.NullCompleter) UriCompleter(org.apache.karaf.shell.support.completers.UriCompleter) StringsCompleter(org.apache.karaf.shell.support.completers.StringsCompleter) FileCompleter(org.apache.karaf.shell.support.completers.FileCompleter) StringsCompleter(org.apache.karaf.shell.support.completers.StringsCompleter) Collection(java.util.Collection) File(java.io.File)

Aggregations

File (java.io.File)1 Collection (java.util.Collection)1 EnumSet (java.util.EnumSet)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Completer (org.apache.karaf.shell.api.console.Completer)1 FileCompleter (org.apache.karaf.shell.support.completers.FileCompleter)1 NullCompleter (org.apache.karaf.shell.support.completers.NullCompleter)1 StringsCompleter (org.apache.karaf.shell.support.completers.StringsCompleter)1 UriCompleter (org.apache.karaf.shell.support.completers.UriCompleter)1 GenericType (org.apache.karaf.shell.support.converter.GenericType)1