mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
添加@ForceAliasFor注解
This commit is contained in:
parent
491c53e7dd
commit
17b48024ad
@ -3,12 +3,12 @@ package cn.hutool.core.annotation;
|
|||||||
import java.lang.annotation.*;
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>表示“原始属性”将作为“关联属性”的别名。
|
* <p>{@link Link}的子注解。表示“原始属性”将作为“关联属性”的别名。
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>当“原始属性”为默认值时,获取“关联属性”将返回“关联属性”本身的值;</li>
|
* <li>当“原始属性”为默认值时,获取“关联属性”将返回“关联属性”本身的值;</li>
|
||||||
* <li>当“原始属性”不为默认值时,获取“关联属性”将返回“原始属性”的值;</li>
|
* <li>当“原始属性”不为默认值时,获取“关联属性”将返回“原始属性”的值;</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
* <b>注意,该注解与{@link Link}或{@link MirrorFor}一起使用时,将只有被声明在最上面的注解会生效</b>
|
* <b>注意,该注解与{@link Link}、{@link ForceAliasFor}或{@link MirrorFor}一起使用时,将只有被声明在最上面的注解会生效</b>
|
||||||
*
|
*
|
||||||
* @author huangchengxing
|
* @author huangchengxing
|
||||||
* @see Link
|
* @see Link
|
||||||
|
@ -0,0 +1,31 @@
|
|||||||
|
package cn.hutool.core.annotation;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>{@link Link}的子注解。表示“原始属性”将强制作为“关联属性”的别名。效果等同于在“原始属性”上添加{@link Alias}注解,
|
||||||
|
* 任何情况下,获取“关联属性”的值都将直接返回“原始属性”的值
|
||||||
|
* <b>注意,该注解与{@link Link}、{@link AliasFor}或{@link MirrorFor}一起使用时,将只有被声明在最上面的注解会生效</b>
|
||||||
|
*
|
||||||
|
* @author huangchengxing
|
||||||
|
* @see Link
|
||||||
|
* @see RelationType#FORCE_ALIAS_FOR
|
||||||
|
*/
|
||||||
|
@Link(type = RelationType.FORCE_ALIAS_FOR)
|
||||||
|
@Documented
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE})
|
||||||
|
public @interface ForceAliasFor {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 产生关联的注解类型,当不指定时,默认指注释的属性所在的类
|
||||||
|
*/
|
||||||
|
@Link(annotation = Link.class, attribute = "annotation", type = RelationType.FORCE_ALIAS_FOR)
|
||||||
|
Class<? extends Annotation> annotation() default Annotation.class;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link #annotation()}指定注解中关联的属性
|
||||||
|
*/
|
||||||
|
@Link(annotation = Link.class, attribute = "attribute", type = RelationType.FORCE_ALIAS_FOR)
|
||||||
|
String attribute() default "";
|
||||||
|
}
|
@ -5,11 +5,20 @@ import java.lang.annotation.*;
|
|||||||
/**
|
/**
|
||||||
* <p>用于在同一注解中,或具有一定关联的不同注解的属性中,表明这些属性之间具有特定的关联关系。
|
* <p>用于在同一注解中,或具有一定关联的不同注解的属性中,表明这些属性之间具有特定的关联关系。
|
||||||
* 在通过{@link SyntheticAnnotation}获取合成注解后,合成注解获取属性值时会根据该注解进行调整。<br />
|
* 在通过{@link SyntheticAnnotation}获取合成注解后,合成注解获取属性值时会根据该注解进行调整。<br />
|
||||||
* <b>注意:该注解的优先级低于{@link Alias};且与{@link MirrorFor}或{@link AliasFor}一起使用时,将只有被声明在最上面的注解会生效</b>
|
*
|
||||||
|
* <p>该注解存在三个字注解:{@link MirrorFor}、{@link ForceAliasFor}或{@link AliasFor},
|
||||||
|
* 使用三个子注解等同于{@link Link}。但是需要注意的是,
|
||||||
|
* 当注解中的属性同时存在多个{@link Link}或基于{@link Link}的子注解时,
|
||||||
|
* 仅有声明在被注解的属性最上方的注解会生效,其余注解都将被忽略。
|
||||||
|
*
|
||||||
|
* <b>注意:该注解的优先级低于{@link Alias}</b>
|
||||||
*
|
*
|
||||||
* @author huangchengxing
|
* @author huangchengxing
|
||||||
* @see SyntheticAnnotation
|
* @see SyntheticAnnotation
|
||||||
* @see RelationType
|
* @see RelationType
|
||||||
|
* @see AliasFor
|
||||||
|
* @see MirrorFor
|
||||||
|
* @see ForceAliasFor
|
||||||
*/
|
*/
|
||||||
@Documented
|
@Documented
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@ -3,7 +3,7 @@ package cn.hutool.core.annotation;
|
|||||||
import java.lang.annotation.*;
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>表示注解的属性与指定的属性互为镜像,通过一个属性将能够获得对方的值。<br>
|
* <p>{@link Link}的子注解。表示注解的属性与指定的属性互为镜像,通过一个属性将能够获得对方的值。<br>
|
||||||
* 它们遵循下述规则:
|
* 它们遵循下述规则:
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>互为镜像的两个属性,必须同时通过指定模式为{@code MIRROR_FOR}的{@link Link}注解指定对方;</li>
|
* <li>互为镜像的两个属性,必须同时通过指定模式为{@code MIRROR_FOR}的{@link Link}注解指定对方;</li>
|
||||||
@ -11,7 +11,7 @@ import java.lang.annotation.*;
|
|||||||
* <li>互为镜像的两个属性在获取值,且两者的值皆不同时,必须且仅允许有一个非默认值,该值被优先返回;</li>
|
* <li>互为镜像的两个属性在获取值,且两者的值皆不同时,必须且仅允许有一个非默认值,该值被优先返回;</li>
|
||||||
* <li>互为镜像的两个属性,在值都为默认值或都不为默认值时,两者的值必须相等;</li>
|
* <li>互为镜像的两个属性,在值都为默认值或都不为默认值时,两者的值必须相等;</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
* <b>注意,该注解与{@link Link}或{@link AliasFor}一起使用时,将只有被声明在最上面的注解会生效</b>
|
* <b>注意,该注解与{@link Link}、{@link ForceAliasFor}或{@link AliasFor}一起使用时,将只有被声明在最上面的注解会生效</b>
|
||||||
*
|
*
|
||||||
* @author huangchengxing
|
* @author huangchengxing
|
||||||
* @see Link
|
* @see Link
|
||||||
|
@ -222,11 +222,12 @@ public class SyntheticMetaAnnotationTest {
|
|||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Target({ ElementType.METHOD, ElementType.TYPE })
|
@Target({ ElementType.METHOD, ElementType.TYPE })
|
||||||
@interface AnnotationForceForAliasForTest {
|
@interface AnnotationForceForAliasForTest {
|
||||||
@Link(
|
//@Link(
|
||||||
annotation = MetaAnnotationForForceAliasForTest.class,
|
// annotation = MetaAnnotationForForceAliasForTest.class,
|
||||||
attribute = "name",
|
// attribute = "name",
|
||||||
type = RelationType.FORCE_ALIAS_FOR
|
// type = RelationType.FORCE_ALIAS_FOR
|
||||||
)
|
//)
|
||||||
|
@ForceAliasFor(annotation = MetaAnnotationForForceAliasForTest.class, attribute = "name")
|
||||||
String value() default "";
|
String value() default "";
|
||||||
}
|
}
|
||||||
@AnnotationForceForAliasForTest
|
@AnnotationForceForAliasForTest
|
||||||
|
Loading…
x
Reference in New Issue
Block a user