Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
PropertyDescriptorSearcher |
|
|
3.0;3 |
1 | /* |
|
2 | * Copyright 2012-2013 smartics, Kronseder & Reiner GmbH |
|
3 | * |
|
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 | */ |
|
16 | package de.smartics.properties.report.qdox; |
|
17 | ||
18 | import java.util.List; |
|
19 | ||
20 | import com.thoughtworks.qdox.Searcher; |
|
21 | import com.thoughtworks.qdox.model.JavaAnnotation; |
|
22 | import com.thoughtworks.qdox.model.JavaClass; |
|
23 | ||
24 | import de.smartics.properties.api.core.annotations.PropertySet; |
|
25 | import de.smartics.util.lang.Arg; |
|
26 | import de.smartics.util.lang.NullArgumentException; |
|
27 | ||
28 | /** |
|
29 | * Filters interfaces that are annotated with the {@link PropertySet} |
|
30 | * annotation. |
|
31 | */ |
|
32 | 0 | public final class PropertyDescriptorSearcher implements Searcher |
33 | { |
|
34 | // ********************************* Fields ********************************* |
|
35 | ||
36 | // --- constants ------------------------------------------------------------ |
|
37 | ||
38 | /** |
|
39 | * The name of the annotation that identifies an interface as declaring |
|
40 | * properties. |
|
41 | */ |
|
42 | 0 | private static final String PROPERTY_SET_CLASS_NAME = PropertySet.class |
43 | .getName(); |
|
44 | ||
45 | // --- members -------------------------------------------------------------- |
|
46 | ||
47 | // ****************************** Initializer ******************************* |
|
48 | ||
49 | // ****************************** Constructors ****************************** |
|
50 | ||
51 | // ****************************** Inner Classes ***************************** |
|
52 | ||
53 | // ********************************* Methods ******************************** |
|
54 | ||
55 | // --- init ----------------------------------------------------------------- |
|
56 | ||
57 | // --- get&set -------------------------------------------------------------- |
|
58 | ||
59 | // --- business ------------------------------------------------------------- |
|
60 | ||
61 | /** |
|
62 | * {@inheritDoc} |
|
63 | * |
|
64 | * @see com.thoughtworks.qdox.Searcher#eval(com.thoughtworks.qdox.model.JavaClass) |
|
65 | * @throws NullArgumentException if {@code cls} is <code>null</code>. |
|
66 | */ |
|
67 | @Override |
|
68 | public boolean eval(final JavaClass cls) throws NullArgumentException |
|
69 | { |
|
70 | 0 | return hasPropertyAnnotation(cls); |
71 | } |
|
72 | ||
73 | /** |
|
74 | * Checks if the given class provides the {@link PropertySet} annotation that |
|
75 | * identifies an interfaces as declaring a property set. |
|
76 | * |
|
77 | * @param javaClass the class to check for being an interface and providing |
|
78 | * the {@link PropertySet} annotation. |
|
79 | * @return <code>true</code> if the class is a property set interface, |
|
80 | * <code>false</code> otherwise. |
|
81 | * @throws NullArgumentException if {@code javaClass} is <code>null</code>. |
|
82 | */ |
|
83 | public static boolean hasPropertyAnnotation(final JavaClass javaClass) |
|
84 | throws NullArgumentException |
|
85 | { |
|
86 | 0 | Arg.checkNotNull("javaClass", javaClass); |
87 | ||
88 | 0 | if (javaClass.isInterface()) |
89 | { |
|
90 | 0 | final List<JavaAnnotation> annotations = javaClass.getAnnotations(); |
91 | 0 | for (final JavaAnnotation annotation : annotations) |
92 | { |
|
93 | 0 | final String annotationClassName = |
94 | annotation.getType().getFullyQualifiedName(); |
|
95 | 0 | if (PROPERTY_SET_CLASS_NAME.equals(annotationClassName)) |
96 | { |
|
97 | 0 | return true; |
98 | } |
|
99 | 0 | } |
100 | } |
|
101 | 0 | return false; |
102 | } |
|
103 | ||
104 | // --- object basics -------------------------------------------------------- |
|
105 | ||
106 | } |