Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
Visibility |
|
| 3.0;3 |
1 | 0 | package com.lexicalscope.fluentreflection; |
2 | ||
3 | import java.lang.reflect.Modifier; | |
4 | ||
5 | /* | |
6 | * Copyright 2011 Tim Wood | |
7 | * | |
8 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
9 | * you may not use this file except in compliance with the License. | |
10 | * You may obtain a copy of the License at | |
11 | * | |
12 | * http://www.apache.org/licenses/LICENSE-2.0 | |
13 | * | |
14 | * Unless required by applicable law or agreed to in writing, software | |
15 | * distributed under the License is distributed on an "AS IS" BASIS, | |
16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
17 | * See the License for the specific language governing permissions and | |
18 | * limitations under the License. | |
19 | */ | |
20 | ||
21 | 6 | /** |
22 | 6 | * An enum describing the different levels of visibility offered by Java |
23 | 6 | * |
24 | 6 | * @author tim |
25 | 6 | */ |
26 | 2 | public enum Visibility { |
27 | 2 | PUBLIC("public"), |
28 | 2 | PRIVATE("private"), |
29 | 26 | DEFAULT(""), |
30 | 26 | PROTECTED("protected"), ; |
31 | 24 | |
32 | private final String visibility; | |
33 | ||
34 | 284 | private Visibility(final String visibility) { |
35 | 8 | this.visibility = visibility; |
36 | 8 | } |
37 | ||
38 | 324 | @Override public String toString() { |
39 | 92 | return visibility; |
40 | 72 | } |
41 | ||
42 | 252 | static Visibility visibilityFromModifiers(final int modifiers) { |
43 | 108 | if (Modifier.isPublic(modifiers)) |
44 | 24 | { |
45 | 24 | return Visibility.PUBLIC; |
46 | 228 | } |
47 | 84 | if (Modifier.isPrivate(modifiers)) |
48 | 24 | { |
49 | 8 | return Visibility.PRIVATE; |
50 | 204 | } |
51 | 76 | if (Modifier.isProtected(modifiers)) |
52 | { | |
53 | 8 | return Visibility.PROTECTED; |
54 | } | |
55 | 68 | return Visibility.DEFAULT; |
56 | } | |
57 | } |