Skip to content

Commit 169fe17

Browse files
authored
Merge pull request #144 from microsphere-projects/main
Release 0.1.0
2 parents aa5f4c3 + 24cbffe commit 169fe17

448 files changed

Lines changed: 28888 additions & 7076 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.

.github/workflows/maven-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ on:
1212
push:
1313
branches: [ "dev" ]
1414
pull_request:
15-
branches: [ "main" ]
15+
branches: [ "dev" , "main" ]
1616

1717
jobs:
1818
build:

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: 213 additions & 70 deletions
Large diffs are not rendered by default.

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,14 @@
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> {
3839

40+
/**
41+
* The singleton instance
42+
*/
3943
public static final ExecutableElementComparator INSTANCE = new ExecutableElementComparator();
4044

4145
private ExecutableElementComparator() {
@@ -60,7 +64,7 @@ public int compare(ExecutableElement e1, ExecutableElement e2) {
6064

6165
if (value == 0) { // Step 3
6266
for (int i = 0; i < ps1.size(); i++) {
63-
value = CharSequenceComparator.INSTANCE.compare(ps1.get(i).getSimpleName(), ps2.get(i).getSimpleName());
67+
value = CharSequenceComparator.INSTANCE.compare(ps1.get(i).asType().toString(), ps2.get(i).asType().toString());
6468
if (value != 0) {
6569
break;
6670
}

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

Lines changed: 57 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,25 @@
1616
*/
1717
package io.microsphere.annotation.processor.util;
1818

19+
import io.microsphere.util.Utils;
20+
1921
import javax.lang.model.element.Element;
2022
import javax.lang.model.element.Modifier;
2123
import javax.lang.model.element.VariableElement;
2224
import javax.lang.model.type.TypeMirror;
23-
import java.util.Collection;
2425
import java.util.List;
2526
import java.util.function.Predicate;
26-
import java.util.stream.Collectors;
2727

28+
import static io.microsphere.annotation.processor.util.MemberUtils.getAllDeclaredMembers;
2829
import static io.microsphere.annotation.processor.util.MemberUtils.getDeclaredMembers;
2930
import static io.microsphere.annotation.processor.util.MemberUtils.hasModifiers;
30-
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.MemberUtils.matchesElementKind;
3232
import static io.microsphere.annotation.processor.util.TypeUtils.isEnumType;
33+
import static io.microsphere.collection.CollectionUtils.isEmpty;
3334
import static io.microsphere.lang.function.Predicates.EMPTY_PREDICATE_ARRAY;
3435
import static io.microsphere.lang.function.Streams.filterAll;
3536
import static io.microsphere.lang.function.Streams.filterFirst;
37+
import static io.microsphere.util.ArrayUtils.isNotEmpty;
3638
import static java.util.Collections.emptyList;
3739
import static javax.lang.model.element.ElementKind.ENUM_CONSTANT;
3840
import static javax.lang.model.element.ElementKind.FIELD;
@@ -42,60 +44,79 @@
4244
/**
4345
* The utilities class for the field in the package "javax.lang.model."
4446
*
47+
* @author <a href="mailto:mercyblitz@gmail.com">Mercy<a/>
4548
* @since 1.0.0
4649
*/
47-
public interface FieldUtils {
50+
public interface FieldUtils extends Utils {
4851

49-
static List<VariableElement> getDeclaredFields(Element element, Predicate<VariableElement>... fieldFilters) {
50-
return element == null ? emptyList() : getDeclaredFields(element.asType(), fieldFilters);
52+
static VariableElement getDeclaredField(Element element, String fieldName) {
53+
return element == null ? null : getDeclaredField(element.asType(), fieldName);
5154
}
5255

53-
static List<VariableElement> getDeclaredFields(Element element) {
54-
return getDeclaredFields(element, EMPTY_PREDICATE_ARRAY);
56+
static VariableElement getDeclaredField(TypeMirror type, String fieldName) {
57+
return filterFirst(findDeclaredFields(type, field -> fieldName.equals(field.getSimpleName().toString())));
5558
}
5659

57-
static List<VariableElement> getDeclaredFields(TypeMirror type, Predicate<VariableElement>... fieldFilters) {
58-
return filterAll(fieldsIn(getDeclaredMembers(type)), fieldFilters);
60+
static List<VariableElement> getDeclaredFields(Element element) {
61+
return findDeclaredFields(element, EMPTY_PREDICATE_ARRAY);
5962
}
6063

6164
static List<VariableElement> getDeclaredFields(TypeMirror type) {
62-
return getDeclaredFields(type, EMPTY_PREDICATE_ARRAY);
65+
return findDeclaredFields(type, EMPTY_PREDICATE_ARRAY);
6366
}
6467

65-
static List<VariableElement> getAllDeclaredFields(Element element, Predicate<VariableElement>... fieldFilters) {
66-
return element == null ? emptyList() : getAllDeclaredFields(element.asType(), fieldFilters);
68+
static List<VariableElement> getAllDeclaredFields(Element element) {
69+
return findAllDeclaredFields(element, EMPTY_PREDICATE_ARRAY);
6770
}
6871

69-
static List<VariableElement> getAllDeclaredFields(Element element) {
70-
return getAllDeclaredFields(element, EMPTY_PREDICATE_ARRAY);
72+
static List<VariableElement> getAllDeclaredFields(TypeMirror type) {
73+
return findAllDeclaredFields(type, EMPTY_PREDICATE_ARRAY);
7174
}
7275

73-
static List<VariableElement> getAllDeclaredFields(TypeMirror type, Predicate<VariableElement>... fieldFilters) {
74-
return getHierarchicalTypes(type)
75-
.stream()
76-
.map(t -> getDeclaredFields(t, fieldFilters))
77-
.flatMap(Collection::stream)
78-
.collect(Collectors.toList());
76+
static VariableElement findField(Element element, String fieldName) {
77+
return element == null ? null : findField(element.asType(), fieldName);
7978
}
8079

81-
static List<VariableElement> getAllDeclaredFields(TypeMirror type) {
82-
return getAllDeclaredFields(type, EMPTY_PREDICATE_ARRAY);
80+
static VariableElement findField(TypeMirror type, String fieldName) {
81+
return filterFirst(findAllDeclaredFields(type, field -> equalsFieldName(field, fieldName)));
8382
}
8483

85-
static VariableElement getDeclaredField(Element element, String fieldName) {
86-
return element == null ? null : getDeclaredField(element.asType(), fieldName);
84+
static List<VariableElement> findDeclaredFields(Element element, Predicate<? super VariableElement>... fieldFilters) {
85+
return element == null ? emptyList() : findDeclaredFields(element.asType(), fieldFilters);
8786
}
8887

89-
static VariableElement getDeclaredField(TypeMirror type, String fieldName) {
90-
return filterFirst(getDeclaredFields(type, field -> fieldName.equals(field.getSimpleName().toString())));
88+
static List<VariableElement> findDeclaredFields(TypeMirror type, Predicate<? super VariableElement>... fieldFilters) {
89+
return filterDeclaredFields(type, false, fieldFilters);
9190
}
9291

93-
static VariableElement findField(Element element, String fieldName) {
94-
return element == null ? null : findField(element.asType(), fieldName);
92+
static List<VariableElement> findAllDeclaredFields(Element element, Predicate<? super VariableElement>... fieldFilters) {
93+
return element == null ? emptyList() : findAllDeclaredFields(element.asType(), fieldFilters);
9594
}
9695

97-
static VariableElement findField(TypeMirror type, String fieldName) {
98-
return filterFirst(getAllDeclaredFields(type, field -> equals(field, fieldName)));
96+
static List<VariableElement> findAllDeclaredFields(TypeMirror type, Predicate<? super VariableElement>... fieldFilters) {
97+
return filterDeclaredFields(type, true, fieldFilters);
98+
}
99+
100+
static List<VariableElement> filterDeclaredFields(TypeMirror type, boolean all, Predicate<? super VariableElement>... fieldFilters) {
101+
if (type == null) {
102+
return emptyList();
103+
}
104+
105+
List<? extends Element> declaredMembers = all ? getAllDeclaredMembers(type) : getDeclaredMembers(type);
106+
if (isEmpty(declaredMembers)) {
107+
return emptyList();
108+
}
109+
110+
List<VariableElement> fields = fieldsIn(declaredMembers);
111+
if (isEmpty(fields)) {
112+
return emptyList();
113+
}
114+
115+
if (isNotEmpty(fieldFilters)) {
116+
fields = filterAll(fields, fieldFilters);
117+
}
118+
119+
return isEmpty(fields) ? emptyList() : fields;
99120
}
100121

101122
/**
@@ -116,31 +137,30 @@ static boolean isNonStaticField(VariableElement field) {
116137
}
117138

118139
static boolean isField(VariableElement field) {
119-
return matches(field, FIELD) || isEnumMemberField(field);
140+
return matchesElementKind(field, FIELD) || isEnumMemberField(field);
120141
}
121142

122143
static boolean isField(VariableElement field, Modifier... modifiers) {
123144
return isField(field) && hasModifiers(field, modifiers);
124145
}
125146

126147
static List<VariableElement> getNonStaticFields(TypeMirror type) {
127-
return getDeclaredFields(type, FieldUtils::isNonStaticField);
148+
return findDeclaredFields(type, FieldUtils::isNonStaticField);
128149
}
129150

130151
static List<VariableElement> getNonStaticFields(Element element) {
131152
return element == null ? emptyList() : getNonStaticFields(element.asType());
132153
}
133154

134155
static List<VariableElement> getAllNonStaticFields(TypeMirror type) {
135-
return getAllDeclaredFields(type, FieldUtils::isNonStaticField);
156+
return findAllDeclaredFields(type, FieldUtils::isNonStaticField);
136157
}
137158

138159
static List<VariableElement> getAllNonStaticFields(Element element) {
139160
return element == null ? emptyList() : getAllNonStaticFields(element.asType());
140161
}
141162

142-
static boolean equals(VariableElement field, CharSequence fieldName) {
163+
static boolean equalsFieldName(VariableElement field, CharSequence fieldName) {
143164
return field != null && fieldName != null && field.getSimpleName().toString().equals(fieldName.toString());
144165
}
145-
146166
}

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

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

1919

20-
21-
2220
import io.microsphere.logging.Logger;
23-
import io.microsphere.logging.LoggerFactory;
21+
import io.microsphere.util.Utils;
2422

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

2725
/**
2826
* Logger Utils
2927
*
28+
* @author <a href="mailto:mercyblitz@gmail.com">Mercy<a/>
3029
* @since 1.0.0
3130
*/
32-
public interface LoggerUtils {
31+
public interface LoggerUtils extends Utils {
32+
33+
Logger LOGGER = getLogger("microsphere-annotation-processor");
34+
35+
static void trace(String format, Object... args) {
36+
LOGGER.trace(format, args);
37+
}
3338

34-
Logger LOGGER = LoggerFactory.getLogger(LoggerUtils.class);
39+
static void debug(String format, Object... args) {
40+
LOGGER.debug(format, args);
41+
}
3542

3643
static void info(String format, Object... args) {
37-
if (LOGGER.isInfoEnabled()) {
38-
LOGGER.info(format(format, args));
39-
}
44+
LOGGER.info(format, args);
4045
}
4146

4247
static void warn(String format, Object... args) {
43-
if (LOGGER.isWarnEnabled()) {
44-
LOGGER.warn(format(format, args));
45-
}
48+
LOGGER.warn(format, args);
49+
}
50+
51+
static void error(String format, Object... args) {
52+
LOGGER.error(format, args);
4653
}
4754
}

0 commit comments

Comments
 (0)