Skip to content

Commit cae6eac

Browse files
authored
Merge pull request #33 from microsphere-projects/dev
Release 0.0.8
2 parents fa1a730 + c8d62bb commit cae6eac

16 files changed

+1446
-25
lines changed

microsphere-java-core/src/main/java/io/microsphere/lang/Deprecation.java

Lines changed: 90 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
*/
1717
package io.microsphere.lang;
1818

19+
import io.microsphere.util.Version;
20+
1921
import javax.annotation.Nonnull;
2022
import javax.annotation.Nullable;
2123
import java.io.Serializable;
@@ -32,8 +34,10 @@
3234
*/
3335
public final class Deprecation implements Serializable {
3436

37+
private static final long serialVersionUID = 6380988834632455932L;
38+
3539
@Nullable
36-
private final String since;
40+
private final Version since;
3741

3842
@Nullable
3943
private final String replacement;
@@ -57,6 +61,11 @@ public final class Deprecation implements Serializable {
5761

5862
Deprecation(@Nullable String since, @Nullable String replacement, @Nullable String reason,
5963
@Nullable String link, @Nullable Level level) {
64+
this(Version.of(since), replacement, reason, link, level);
65+
}
66+
67+
Deprecation(@Nullable Version since, @Nullable String replacement, @Nullable String reason,
68+
@Nullable String link, @Nullable Level level) {
6069
this.since = since;
6170
this.replacement = replacement;
6271
this.reason = reason;
@@ -65,7 +74,7 @@ public final class Deprecation implements Serializable {
6574
}
6675

6776
@Nullable
68-
public String getSince() {
77+
public Version getSince() {
6978
return since;
7079
}
7180

@@ -133,6 +142,78 @@ public static enum Level {
133142
REMOVAL,
134143
}
135144

145+
/**
146+
* The Builder class for {@link Deprecation}
147+
*/
148+
public static class Builder {
149+
150+
@Nullable
151+
private Version since;
152+
153+
@Nullable
154+
private String replacement;
155+
156+
@Nullable
157+
private String reason;
158+
159+
@Nullable
160+
private String link;
161+
162+
@Nonnull
163+
private Level level;
164+
165+
protected Builder() {
166+
}
167+
168+
public Builder since(@Nullable String since) {
169+
return since(Version.of(since));
170+
}
171+
172+
public Builder since(@Nullable Version since) {
173+
this.since = since;
174+
return this;
175+
}
176+
177+
public Builder replacement(@Nullable String replacement) {
178+
this.replacement = replacement;
179+
return this;
180+
}
181+
182+
public Builder reason(@Nullable String reason) {
183+
this.reason = reason;
184+
return this;
185+
}
186+
187+
public Builder link(@Nullable String link) {
188+
this.link = link;
189+
return this;
190+
}
191+
192+
public Builder level(@Nullable Level level) {
193+
this.level = level == null ? DEFAULT : level;
194+
return this;
195+
}
196+
197+
198+
/**
199+
* Build an instance of {@link Deprecation}
200+
*
201+
* @return non-null
202+
*/
203+
public Deprecation build() {
204+
return new Deprecation(since, replacement, reason, link, level);
205+
}
206+
}
207+
208+
/**
209+
* Create a new instance of {@link Deprecation.Builder}
210+
*
211+
* @return non-null
212+
*/
213+
public static Deprecation.Builder builder() {
214+
return new Builder();
215+
}
216+
136217
public static Deprecation of(String since) {
137218
return of(since, null);
138219
}
@@ -150,6 +231,12 @@ public static Deprecation of(String since, String replacement, String reason, St
150231
}
151232

152233
public static Deprecation of(String since, String replacement, String reason, String link, Level level) {
153-
return new Deprecation(since, replacement, reason, link, level);
234+
return builder()
235+
.since(since)
236+
.replacement(replacement)
237+
.reason(reason)
238+
.link(link)
239+
.level(level)
240+
.build();
154241
}
155242
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package io.microsphere.reflect;
18+
19+
import io.microsphere.lang.Deprecation;
20+
import io.microsphere.util.Version;
21+
22+
import javax.annotation.Nonnull;
23+
import javax.annotation.Nullable;
24+
25+
/**
26+
* The definition class for {@link Class}
27+
*
28+
* @author <a href="mailto:[email protected]">Mercy<a/>
29+
* @see Class
30+
* @see ReflectiveDefinition
31+
* @since 1.0.0
32+
*/
33+
public class ClassDefinition extends ReflectiveDefinition {
34+
35+
/**
36+
* @param since the 'since' version
37+
* @param className the name of class
38+
*/
39+
public ClassDefinition(@Nonnull String since, @Nonnull String className) {
40+
super(since, className);
41+
}
42+
43+
/**
44+
* @param since the 'since' version
45+
* @param deprecation the deprecation
46+
* @param className the name of class
47+
*/
48+
public ClassDefinition(@Nonnull String since, @Nullable Deprecation deprecation, @Nonnull String className) {
49+
super(since, deprecation, className);
50+
}
51+
52+
/**
53+
* @param since the 'since' version
54+
* @param className the name of class
55+
*/
56+
public ClassDefinition(@Nonnull Version since, @Nonnull String className) {
57+
super(since, className);
58+
}
59+
60+
/**
61+
* @param since the 'since' version
62+
* @param deprecation the deprecation
63+
* @param className the name of class
64+
*/
65+
public ClassDefinition(@Nonnull Version since, @Nullable Deprecation deprecation, @Nonnull String className) {
66+
super(since, deprecation, className);
67+
}
68+
69+
@Override
70+
public final boolean isPresent() {
71+
return super.getResolvedClass() != null;
72+
}
73+
74+
@Override
75+
public String toString() {
76+
return "ClassDefinition{" +
77+
"since=" + super.since +
78+
", deprecation=" + super.deprecation +
79+
", className='" + this.getClassName() + '\'' +
80+
", resolvedClass=" + super.getResolvedClass() +
81+
'}';
82+
}
83+
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package io.microsphere.reflect;
18+
19+
import io.microsphere.lang.Deprecation;
20+
import io.microsphere.util.Version;
21+
22+
import java.lang.reflect.Constructor;
23+
import java.util.Arrays;
24+
25+
import static io.microsphere.reflect.ConstructorUtils.findConstructor;
26+
27+
/**
28+
* The definition class for {@link Constructor}
29+
*
30+
* @author <a href="mailto:[email protected]">Mercy<a/>
31+
* @see Constructor
32+
* @since 1.0.0
33+
*/
34+
public class ConstructorDefinition extends ExecutableDefinition<Constructor> {
35+
36+
/**
37+
* @param since the 'since' version
38+
* @param declaredClassName The declared class name of the method
39+
* @param parameterClassNames the class names of parameters
40+
*/
41+
public ConstructorDefinition(String since, String declaredClassName, String... parameterClassNames) {
42+
super(since, declaredClassName, declaredClassName, parameterClassNames);
43+
}
44+
45+
/**
46+
* @param since the 'since' version
47+
* @param deprecation the deprecation
48+
* @param declaredClassName The declared class name of the method
49+
* @param parameterClassNames the parameter class names
50+
*/
51+
public ConstructorDefinition(String since, Deprecation deprecation, String declaredClassName, String... parameterClassNames) {
52+
super(since, deprecation, declaredClassName, declaredClassName, parameterClassNames);
53+
}
54+
55+
/**
56+
* @param since the 'since' version
57+
* @param declaredClassName The declared class name of the method
58+
* @param parameterClassNames the class names of parameters
59+
*/
60+
public ConstructorDefinition(Version since, String declaredClassName, String... parameterClassNames) {
61+
super(since, declaredClassName, declaredClassName, parameterClassNames);
62+
}
63+
64+
/**
65+
* @param since the 'since' version
66+
* @param deprecation the deprecation
67+
* @param declaredClassName The declared class name of the method
68+
* @param parameterClassNames the parameter class names
69+
*/
70+
public ConstructorDefinition(Version since, Deprecation deprecation, String declaredClassName, String... parameterClassNames) {
71+
super(since, deprecation, declaredClassName, declaredClassName, parameterClassNames);
72+
}
73+
74+
@Override
75+
protected Constructor resolveMember() {
76+
return findConstructor(super.getDeclaredClass(), super.getParameterTypes());
77+
}
78+
79+
/**
80+
* Get the {@link Constructor}
81+
*
82+
* @return <code>null</code> if the {@link Constructor} can't be resolved.
83+
*/
84+
public Constructor<?> getConstructor() {
85+
return getMember();
86+
}
87+
88+
/**
89+
* Create an instance by the specified {@link Constructor} and arguments
90+
*
91+
* @param args the {@link Constructor Constructors} arguments
92+
* @param <T> the type of instance
93+
* @return non-null
94+
*/
95+
public <T> T newInstance(Object... args) {
96+
return ConstructorUtils.newInstance((Constructor<T>) getConstructor(), args);
97+
}
98+
99+
@Override
100+
public String toString() {
101+
return "ConstructorDefinition{" +
102+
"since=" + super.since +
103+
", deprecation=" + super.deprecation +
104+
", declaredClassName='" + super.getDeclaredClassName() + '\'' +
105+
", declaredClass=" + super.getDeclaredClass() +
106+
", parameterClassName=" + Arrays.toString(super.parameterClassNames) +
107+
", parameterTypes=" + Arrays.toString(super.getParameterTypes()) +
108+
'}';
109+
}
110+
}

0 commit comments

Comments
 (0)