blob: baf91f71e3cc06a5fdea47e0d383885955029e58 [file] [log] [blame]
Yuta HIGUCHI5f3c0332017-01-09 17:41:07 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Yuta HIGUCHI5f3c0332017-01-09 17:41:07 -08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.cli.net.completer;
17
18import java.lang.reflect.Modifier;
19import java.util.Arrays;
20import java.util.List;
21import java.util.Objects;
22import java.util.stream.Collectors;
23
Ray Milkey0068fd02018-10-11 15:45:39 -070024import org.apache.karaf.shell.api.action.lifecycle.Service;
Yuta HIGUCHI5f3c0332017-01-09 17:41:07 -080025import org.onosproject.cli.AbstractChoicesCompleter;
26import org.onosproject.net.AnnotationKeys;
27
28/**
29 * Completer for annotation keys declared in {@link AnnotationKeys}.
30 */
Ray Milkey0068fd02018-10-11 15:45:39 -070031@Service
Yuta HIGUCHI5f3c0332017-01-09 17:41:07 -080032public class AnnotationKeysCompleter extends AbstractChoicesCompleter {
33
34
35 @Override
36 protected List<String> choices() {
37
38 return Arrays.asList(AnnotationKeys.class.getFields())
39 .stream()
40 .filter(f -> f.getType() == String.class)
41 .filter(f -> Modifier.isStatic(f.getModifiers()))
42 .map(f -> {
43 try {
44 return (String) f.get(null);
45 } catch (IllegalArgumentException | IllegalAccessException e) {
46 return null;
47 }
48 })
49 .filter(Objects::nonNull)
50 .collect(Collectors.toList());
51 }
52
53}