|
| 1 | +/** |
| 2 | + * Copyright (C) 2006-2017 INRIA and contributors |
| 3 | + * Spoon - http://spoon.gforge.inria.fr/ |
| 4 | + * |
| 5 | + * This software is governed by the CeCILL-C License under French law and |
| 6 | + * abiding by the rules of distribution of free software. You can use, modify |
| 7 | + * and/or redistribute the software under the terms of the CeCILL-C license as |
| 8 | + * circulated by CEA, CNRS and INRIA at http://www.cecill.info. |
| 9 | + * |
| 10 | + * This program is distributed in the hope that it will be useful, but WITHOUT |
| 11 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | + * FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL-C License for more details. |
| 13 | + * |
| 14 | + * The fact that you are presently reading this means that you have had |
| 15 | + * knowledge of the CeCILL-C license and that you accept its terms. |
| 16 | + */ |
| 17 | +package spoon.metamodel; |
| 18 | + |
| 19 | +import java.util.List; |
| 20 | +import java.util.Map; |
| 21 | +import java.util.Set; |
| 22 | + |
| 23 | +/** |
| 24 | + * Represents type of container used for field value. |
| 25 | + */ |
| 26 | +public enum MMContainerType { |
| 27 | + /** |
| 28 | + * it is a single value field |
| 29 | + * Example: CtClassImpl.simpleName |
| 30 | + */ |
| 31 | + SINGLE, |
| 32 | + /** |
| 33 | + * It is a list of values |
| 34 | + * Example: CtClassImpl.typeMembers |
| 35 | + */ |
| 36 | + LIST, |
| 37 | + /** |
| 38 | + * It is a set of values |
| 39 | + * Example: CtPackageImpl.types |
| 40 | + */ |
| 41 | + SET, |
| 42 | + /** |
| 43 | + * It is a map<String, T> of values |
| 44 | + * Example: CtAnnotationImpl.elementValues |
| 45 | + */ |
| 46 | + MAP; |
| 47 | + |
| 48 | + public static MMContainerType valueOf(Class<?> valueClass) { |
| 49 | + if (List.class.isAssignableFrom(valueClass)) { |
| 50 | + return LIST; |
| 51 | + } |
| 52 | + if (Map.class.isAssignableFrom(valueClass)) { |
| 53 | + return MAP; |
| 54 | + } |
| 55 | + if (Set.class.isAssignableFrom(valueClass)) { |
| 56 | + return SET; |
| 57 | + } |
| 58 | + return SINGLE; |
| 59 | + } |
| 60 | +} |
0 commit comments