Skip to content

Commit d39ccfd

Browse files
authored
Merge pull request #124 from mercyblitz/dev
Test coverage
2 parents c5a3c7b + 7826297 commit d39ccfd

122 files changed

Lines changed: 4624 additions & 1305 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

microsphere-annotation-processor/pom.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
<dependencies>
2727

28-
<!-- microsphere-->
28+
<!-- Microsphere Java Core -->
2929
<dependency>
3030
<groupId>io.github.microsphere-projects</groupId>
3131
<artifactId>microsphere-java-core</artifactId>
@@ -45,6 +45,13 @@
4545
<scope>test</scope>
4646
</dependency>
4747

48+
<!-- Logback -->
49+
<dependency>
50+
<groupId>ch.qos.logback</groupId>
51+
<artifactId>logback-classic</artifactId>
52+
<scope>test</scope>
53+
</dependency>
54+
4855
<!-- JAX-RS API -->
4956
<dependency>
5057
<groupId>javax.ws.rs</groupId>

microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/util/AnnotationUtils.java

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,21 @@
3232
import java.util.Map;
3333
import java.util.Objects;
3434
import java.util.function.Predicate;
35-
import java.util.stream.Collectors;
3635

36+
import static io.microsphere.annotation.processor.util.TypeUtils.isSameType;
37+
import static io.microsphere.annotation.processor.util.TypeUtils.isTypeElement;
38+
import static io.microsphere.annotation.processor.util.TypeUtils.ofTypeElement;
3739
import static io.microsphere.lang.function.Predicates.EMPTY_PREDICATE_ARRAY;
3840
import static io.microsphere.lang.function.Streams.filterAll;
3941
import static io.microsphere.lang.function.Streams.filterFirst;
4042
import static java.lang.Enum.valueOf;
4143
import static java.util.Collections.emptyList;
44+
import static java.util.stream.Collectors.toList;
4245

4346
/**
4447
* The utilities class for annotation in the package "javax.lang.model.*"
4548
*
49+
* @author <a href="mailto:mercyblitz@gmail.com">Mercy<a/>
4650
* @since 1.0.0
4751
*/
4852
public abstract class AnnotationUtils {
@@ -61,85 +65,90 @@ public static List<AnnotationMirror> getAnnotations(AnnotatedConstruct annotated
6165
}
6266

6367
public static List<AnnotationMirror> getAnnotations(AnnotatedConstruct annotatedConstruct, CharSequence annotationClassName) {
64-
return getAnnotations(annotatedConstruct, annotation -> TypeUtils.isSameType(annotation.getAnnotationType(), annotationClassName));
68+
return findAnnotations(annotatedConstruct, annotation -> isSameType(annotation.getAnnotationType(), annotationClassName));
6569
}
6670

6771
public static List<AnnotationMirror> getAnnotations(AnnotatedConstruct annotatedConstruct) {
68-
return getAnnotations(annotatedConstruct, EMPTY_PREDICATE_ARRAY);
69-
}
70-
71-
public static List<AnnotationMirror> getAnnotations(AnnotatedConstruct annotatedConstruct, Predicate<AnnotationMirror>... annotationFilters) {
72-
73-
AnnotatedConstruct actualAnnotatedConstruct = annotatedConstruct;
74-
75-
if (annotatedConstruct instanceof TypeMirror) {
76-
actualAnnotatedConstruct = TypeUtils.ofTypeElement((TypeMirror) actualAnnotatedConstruct);
77-
}
78-
79-
return actualAnnotatedConstruct == null ? emptyList() : filterAll((List<AnnotationMirror>) actualAnnotatedConstruct.getAnnotationMirrors(), annotationFilters);
72+
return findAnnotations(annotatedConstruct, EMPTY_PREDICATE_ARRAY);
8073
}
8174

8275
public static List<AnnotationMirror> getAllAnnotations(TypeMirror type) {
83-
return getAllAnnotations(TypeUtils.ofTypeElement(type));
76+
return getAllAnnotations(ofTypeElement(type));
8477
}
8578

8679
public static List<AnnotationMirror> getAllAnnotations(Element element) {
87-
return getAllAnnotations(element, EMPTY_PREDICATE_ARRAY);
80+
return findAllAnnotations(element, EMPTY_PREDICATE_ARRAY);
8881
}
8982

9083
public static List<AnnotationMirror> getAllAnnotations(TypeMirror type, Class<? extends Annotation> annotationClass) {
91-
return getAllAnnotations(TypeUtils.ofTypeElement(type), annotationClass);
84+
return getAllAnnotations(ofTypeElement(type), annotationClass);
9285
}
9386

9487
public static List<AnnotationMirror> getAllAnnotations(Element element, Class<? extends Annotation> annotationClass) {
9588
return element == null || annotationClass == null ? emptyList() : getAllAnnotations(element, annotationClass.getTypeName());
9689
}
9790

9891
public static List<AnnotationMirror> getAllAnnotations(TypeMirror type, CharSequence annotationClassName) {
99-
return getAllAnnotations(TypeUtils.ofTypeElement(type), annotationClassName);
92+
return getAllAnnotations(ofTypeElement(type), annotationClassName);
10093
}
10194

10295
public static List<AnnotationMirror> getAllAnnotations(Element element, CharSequence annotationClassName) {
103-
return getAllAnnotations(element, annotation -> TypeUtils.isSameType(annotation.getAnnotationType(), annotationClassName));
96+
return findAllAnnotations(element, annotation -> isSameType(annotation.getAnnotationType(), annotationClassName));
10497
}
10598

106-
public static List<AnnotationMirror> getAllAnnotations(TypeMirror type, Predicate<AnnotationMirror>... annotationFilters) {
107-
return getAllAnnotations(TypeUtils.ofTypeElement(type), annotationFilters);
99+
public static List<AnnotationMirror> getAllAnnotations(ProcessingEnvironment processingEnv, Type annotatedType) {
100+
return findAllAnnotations(processingEnv, annotatedType, EMPTY_PREDICATE_ARRAY);
108101
}
109102

110-
public static List<AnnotationMirror> getAllAnnotations(Element element, Predicate<AnnotationMirror>... annotationFilters) {
103+
public static List<AnnotationMirror> findAnnotations(AnnotatedConstruct annotatedConstruct, Predicate<? super AnnotationMirror>... annotationFilters) {
104+
105+
AnnotatedConstruct actualAnnotatedConstruct = annotatedConstruct;
111106

112-
List<AnnotationMirror> allAnnotations = TypeUtils.isTypeElement(element) ? TypeUtils.getHierarchicalTypes(TypeUtils.ofTypeElement(element)).stream().map(AnnotationUtils::getAnnotations).flatMap(Collection::stream).collect(Collectors.toList()) : element == null ? emptyList() : (List<AnnotationMirror>) element.getAnnotationMirrors();
107+
if (annotatedConstruct instanceof TypeMirror) {
108+
actualAnnotatedConstruct = ofTypeElement((TypeMirror) actualAnnotatedConstruct);
109+
}
113110

114-
return filterAll(allAnnotations, annotationFilters);
111+
return actualAnnotatedConstruct == null ? emptyList() : filterAll((List<AnnotationMirror>) actualAnnotatedConstruct.getAnnotationMirrors(), annotationFilters);
115112
}
116113

117-
public static List<AnnotationMirror> getAllAnnotations(ProcessingEnvironment processingEnv, Type annotatedType) {
118-
return getAllAnnotations(processingEnv, annotatedType, EMPTY_PREDICATE_ARRAY);
114+
public static List<AnnotationMirror> findAllAnnotations(TypeMirror type, Predicate<? super AnnotationMirror>... annotationFilters) {
115+
return findAllAnnotations(ofTypeElement(type), annotationFilters);
119116
}
120117

121-
public static List<AnnotationMirror> getAllAnnotations(ProcessingEnvironment processingEnv, Type annotatedType, Predicate<AnnotationMirror>... annotationFilters) {
122-
return annotatedType == null ? emptyList() : getAllAnnotations(processingEnv, annotatedType.getTypeName(), annotationFilters);
118+
public static List<AnnotationMirror> findAllAnnotations(ProcessingEnvironment processingEnv, Type annotatedType, Predicate<? super AnnotationMirror>... annotationFilters) {
119+
return annotatedType == null ? emptyList() : findAllAnnotations(processingEnv, annotatedType.getTypeName(), annotationFilters);
123120
}
124121

125-
public static List<AnnotationMirror> getAllAnnotations(ProcessingEnvironment processingEnv, CharSequence annotatedTypeName, Predicate<AnnotationMirror>... annotationFilters) {
126-
return getAllAnnotations(TypeUtils.getType(processingEnv, annotatedTypeName), annotationFilters);
122+
public static List<AnnotationMirror> findAllAnnotations(ProcessingEnvironment processingEnv, CharSequence annotatedTypeName, Predicate<? super AnnotationMirror>... annotationFilters) {
123+
return findAllAnnotations(TypeUtils.getTypeElement(processingEnv, annotatedTypeName), annotationFilters);
124+
}
125+
126+
public static List<AnnotationMirror> findAllAnnotations(Element element, Predicate<? super AnnotationMirror>... annotationFilters) {
127+
128+
List<AnnotationMirror> allAnnotations = isTypeElement(element) ?
129+
TypeUtils.getAllTypeElements(ofTypeElement(element))
130+
.stream()
131+
.map(AnnotationUtils::getAnnotations)
132+
.flatMap(Collection::stream)
133+
.collect(toList()) : element == null ? emptyList() : (List<AnnotationMirror>) element.getAnnotationMirrors();
134+
135+
return filterAll(allAnnotations, annotationFilters);
127136
}
128137

129138
public static AnnotationMirror findAnnotation(TypeMirror type, Class<? extends Annotation> annotationClass) {
130139
return annotationClass == null ? null : findAnnotation(type, annotationClass.getTypeName());
131140
}
132141

133142
public static AnnotationMirror findAnnotation(TypeMirror type, CharSequence annotationClassName) {
134-
return findAnnotation(TypeUtils.ofTypeElement(type), annotationClassName);
143+
return findAnnotation(ofTypeElement(type), annotationClassName);
135144
}
136145

137146
public static AnnotationMirror findAnnotation(Element element, Class<? extends Annotation> annotationClass) {
138147
return annotationClass == null ? null : findAnnotation(element, annotationClass.getTypeName());
139148
}
140149

141150
public static AnnotationMirror findAnnotation(Element element, CharSequence annotationClassName) {
142-
return filterFirst(getAllAnnotations(element, annotation -> TypeUtils.isSameType(annotation.getAnnotationType(), annotationClassName)));
151+
return filterFirst(findAllAnnotations(element, annotation -> isSameType(annotation.getAnnotationType(), annotationClassName)));
143152
}
144153

145154
public static AnnotationMirror findMetaAnnotation(Element annotatedConstruct, CharSequence metaAnnotationClassName) {

microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/util/ExecutableElementComparator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
* <li>Comparing to the type names of parameters {@link String#compareTo(String) lexicographically}</li>
3333
* </ol>
3434
*
35+
* @author <a href="mailto:mercyblitz@gmail.com">Mercy<a/>
3536
* @since 1.0.0
3637
*/
3738
public class ExecutableElementComparator implements Comparator<ExecutableElement> {

microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/util/FieldUtils.java

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import static io.microsphere.annotation.processor.util.MemberUtils.getDeclaredMembers;
2929
import static io.microsphere.annotation.processor.util.MemberUtils.hasModifiers;
3030
import static io.microsphere.annotation.processor.util.MemberUtils.matches;
31-
import static io.microsphere.annotation.processor.util.TypeUtils.getHierarchicalTypes;
31+
import static io.microsphere.annotation.processor.util.TypeUtils.getAllDeclaredTypes;
3232
import static io.microsphere.annotation.processor.util.TypeUtils.isEnumType;
3333
import static io.microsphere.lang.function.Predicates.EMPTY_PREDICATE_ARRAY;
3434
import static io.microsphere.lang.function.Streams.filterAll;
@@ -42,60 +42,61 @@
4242
/**
4343
* The utilities class for the field in the package "javax.lang.model."
4444
*
45+
* @author <a href="mailto:mercyblitz@gmail.com">Mercy<a/>
4546
* @since 1.0.0
4647
*/
4748
public interface FieldUtils {
4849

49-
static List<VariableElement> getDeclaredFields(Element element, Predicate<VariableElement>... fieldFilters) {
50-
return element == null ? emptyList() : getDeclaredFields(element.asType(), fieldFilters);
50+
static List<VariableElement> getDeclaredFields(Element element) {
51+
return findDeclaredFields(element, EMPTY_PREDICATE_ARRAY);
5152
}
5253

53-
static List<VariableElement> getDeclaredFields(Element element) {
54-
return getDeclaredFields(element, EMPTY_PREDICATE_ARRAY);
54+
static List<VariableElement> getDeclaredFields(TypeMirror type) {
55+
return findDeclaredFields(type, EMPTY_PREDICATE_ARRAY);
5556
}
5657

57-
static List<VariableElement> getDeclaredFields(TypeMirror type, Predicate<VariableElement>... fieldFilters) {
58-
return filterAll(fieldsIn(getDeclaredMembers(type)), fieldFilters);
58+
static List<VariableElement> getAllDeclaredFields(Element element) {
59+
return findAllDeclaredFields(element, EMPTY_PREDICATE_ARRAY);
5960
}
6061

61-
static List<VariableElement> getDeclaredFields(TypeMirror type) {
62-
return getDeclaredFields(type, EMPTY_PREDICATE_ARRAY);
62+
static List<VariableElement> getAllDeclaredFields(TypeMirror type) {
63+
return findAllDeclaredFields(type, EMPTY_PREDICATE_ARRAY);
6364
}
6465

65-
static List<VariableElement> getAllDeclaredFields(Element element, Predicate<VariableElement>... fieldFilters) {
66-
return element == null ? emptyList() : getAllDeclaredFields(element.asType(), fieldFilters);
66+
static List<VariableElement> findDeclaredFields(Element element, Predicate<? super VariableElement>... fieldFilters) {
67+
return element == null ? emptyList() : findDeclaredFields(element.asType(), fieldFilters);
6768
}
6869

69-
static List<VariableElement> getAllDeclaredFields(Element element) {
70-
return getAllDeclaredFields(element, EMPTY_PREDICATE_ARRAY);
70+
static List<VariableElement> findDeclaredFields(TypeMirror type, Predicate<? super VariableElement>... fieldFilters) {
71+
return filterAll(fieldsIn(getDeclaredMembers(type)), fieldFilters);
72+
}
73+
74+
static List<VariableElement> findAllDeclaredFields(Element element, Predicate<? super VariableElement>... fieldFilters) {
75+
return element == null ? emptyList() : findAllDeclaredFields(element.asType(), fieldFilters);
7176
}
7277

73-
static List<VariableElement> getAllDeclaredFields(TypeMirror type, Predicate<VariableElement>... fieldFilters) {
74-
return getHierarchicalTypes(type)
78+
static List<VariableElement> findAllDeclaredFields(TypeMirror type, Predicate<? super VariableElement>... fieldFilters) {
79+
return getAllDeclaredTypes(type)
7580
.stream()
76-
.map(t -> getDeclaredFields(t, fieldFilters))
81+
.map(t -> findDeclaredFields(t, fieldFilters))
7782
.flatMap(Collection::stream)
7883
.collect(Collectors.toList());
7984
}
8085

81-
static List<VariableElement> getAllDeclaredFields(TypeMirror type) {
82-
return getAllDeclaredFields(type, EMPTY_PREDICATE_ARRAY);
83-
}
84-
8586
static VariableElement getDeclaredField(Element element, String fieldName) {
8687
return element == null ? null : getDeclaredField(element.asType(), fieldName);
8788
}
8889

8990
static VariableElement getDeclaredField(TypeMirror type, String fieldName) {
90-
return filterFirst(getDeclaredFields(type, field -> fieldName.equals(field.getSimpleName().toString())));
91+
return filterFirst(findDeclaredFields(type, field -> fieldName.equals(field.getSimpleName().toString())));
9192
}
9293

9394
static VariableElement findField(Element element, String fieldName) {
9495
return element == null ? null : findField(element.asType(), fieldName);
9596
}
9697

9798
static VariableElement findField(TypeMirror type, String fieldName) {
98-
return filterFirst(getAllDeclaredFields(type, field -> equals(field, fieldName)));
99+
return filterFirst(findAllDeclaredFields(type, field -> equals(field, fieldName)));
99100
}
100101

101102
/**
@@ -124,15 +125,15 @@ static boolean isField(VariableElement field, Modifier... modifiers) {
124125
}
125126

126127
static List<VariableElement> getNonStaticFields(TypeMirror type) {
127-
return getDeclaredFields(type, FieldUtils::isNonStaticField);
128+
return findDeclaredFields(type, FieldUtils::isNonStaticField);
128129
}
129130

130131
static List<VariableElement> getNonStaticFields(Element element) {
131132
return element == null ? emptyList() : getNonStaticFields(element.asType());
132133
}
133134

134135
static List<VariableElement> getAllNonStaticFields(TypeMirror type) {
135-
return getAllDeclaredFields(type, FieldUtils::isNonStaticField);
136+
return findAllDeclaredFields(type, FieldUtils::isNonStaticField);
136137
}
137138

138139
static List<VariableElement> getAllNonStaticFields(Element element) {

microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/util/LoggerUtils.java

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,47 @@
1717
package io.microsphere.annotation.processor.util;
1818

1919

20-
21-
2220
import io.microsphere.logging.Logger;
23-
import io.microsphere.logging.LoggerFactory;
2421

25-
import static java.lang.String.format;
22+
import static io.microsphere.logging.LoggerFactory.getLogger;
2623

2724
/**
2825
* Logger Utils
2926
*
27+
* @author <a href="mailto:mercyblitz@gmail.com">Mercy<a/>
3028
* @since 1.0.0
3129
*/
3230
public interface LoggerUtils {
3331

34-
Logger LOGGER = LoggerFactory.getLogger(LoggerUtils.class);
32+
Logger LOGGER = getLogger("microsphere-annotation-processor");
33+
34+
static void trace(String format, Object... args) {
35+
if (LOGGER.isTraceEnabled()) {
36+
LOGGER.trace(format, args);
37+
}
38+
}
39+
40+
static void debug(String format, Object... args) {
41+
if (LOGGER.isDebugEnabled()) {
42+
LOGGER.debug(format, args);
43+
}
44+
}
3545

3646
static void info(String format, Object... args) {
3747
if (LOGGER.isInfoEnabled()) {
38-
LOGGER.info(format(format, args));
48+
LOGGER.info(format, args);
3949
}
4050
}
4151

4252
static void warn(String format, Object... args) {
4353
if (LOGGER.isWarnEnabled()) {
44-
LOGGER.warn(format(format, args));
54+
LOGGER.warn(format, args);
55+
}
56+
}
57+
58+
static void error(String format, Object... args) {
59+
if (LOGGER.isErrorEnabled()) {
60+
LOGGER.error(format, args);
4561
}
4662
}
4763
}

microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/util/MemberUtils.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,18 @@
2626
import java.util.List;
2727
import java.util.Objects;
2828
import java.util.Set;
29-
import java.util.stream.Collectors;
3029

30+
import static io.microsphere.annotation.processor.util.TypeUtils.getAllDeclaredTypes;
31+
import static io.microsphere.annotation.processor.util.TypeUtils.ofTypeElement;
3132
import static java.util.Collections.emptyList;
33+
import static java.util.stream.Collectors.toList;
3234
import static javax.lang.model.element.Modifier.PUBLIC;
3335
import static javax.lang.model.element.Modifier.STATIC;
3436

3537
/**
3638
* The utilities class for the members in the package "javax.lang.model.", such as "field", "method", "constructor"
3739
*
40+
* @author <a href="mailto:mercyblitz@gmail.com">Mercy<a/>
3841
* @since 1.0.0
3942
*/
4043
public interface MemberUtils {
@@ -61,16 +64,16 @@ static boolean hasModifiers(Element member, Modifier... modifiers) {
6164
}
6265

6366
static List<? extends Element> getDeclaredMembers(TypeMirror type) {
64-
TypeElement element = TypeUtils.ofTypeElement(type);
67+
TypeElement element = ofTypeElement(type);
6568
return element == null ? emptyList() : element.getEnclosedElements();
6669
}
6770

6871
static List<? extends Element> getAllDeclaredMembers(TypeMirror type) {
69-
return TypeUtils.getHierarchicalTypes(type)
72+
return getAllDeclaredTypes(type)
7073
.stream()
7174
.map(MemberUtils::getDeclaredMembers)
7275
.flatMap(Collection::stream)
73-
.collect(Collectors.toList());
76+
.collect(toList());
7477
}
7578

7679
static boolean matchParameterTypes(List<? extends VariableElement> parameters, CharSequence... parameterTypes) {

0 commit comments

Comments
 (0)