日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

AspectJ Join Point Matching based on Annotations

發(fā)布時(shí)間:2025/3/21 编程问答 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 AspectJ Join Point Matching based on Annotations 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

為什么80%的碼農(nóng)都做不了架構(gòu)師?>>> ??

Annotation Patterns

For any kind of annotated element (type, method, constructor, package, etc.), an annotation pattern can be used to match against the set of annotations on the annotated element.An annotation pattern element has one of two basic forms:

  • @<qualified-name>, for example, @Foo, or @org.xyz.Foo.
  • @(<type-pattern>), for example, @(org.xyz..*), or @(Foo || Boo)

These simple elements may be negated using?!, and combined by simple concatentation. The pattern?@Foo @Boo?matches an annotated element that has both an annotation of type?Foo?and an annotation of type?Boo.

Some examples of annotation patterns follow:

@Immutable

Matches any annotated element which has an annotation of type?Immutable.

!@Persistent

Matches any annotated element which does not have an annotation of type?Persistent.

@Foo @Goo

Matches any annotated element which has both an annotation of type?Foo?and an annotation of type?Goo.

@(Foo || Goo)

Matches any annotated element which has either an annotation of a type matching the type pattern?(Foo || Goo). In other words, an annotated element with either an annotation of type?Foo?or an annotation of type?Goo?(or both). (The parenthesis are required in this example).

@(org.xyz..*)

Matches any annotated element which has either an annotation of a type matching the type pattern?(org.xyz..*). In other words, an annotated element with an annotation that is declared in the org.xyz package or a sub-package. (The parenthesis are required in this example).

?

Type Patterns

AspectJ 1.5 extends type patterns to allow an optional?AnnotationPattern?prefix.

TypePattern := SimpleTypePattern |'!' TypePattern |'(' AnnotationPattern? TypePattern ')'TypePattern '&&' TypePattern |TypePattern '||' TypePattern SimpleTypePattern := DottedNamePattern '+'? '[]'*DottedNamePattern := FullyQualifiedName RestOfNamePattern? |'*' NotStarNamePattern?RestOfNamePattern := '..' DottedNamePattern |'*' NotStarNamePattern?NotStarNamePattern := FullyQualifiedName RestOfNamePattern? |'..' DottedNamePattern FullyQualifiedName := JavaIdentifierCharacter+ ('.' JavaIdentifierCharacter+)*

Note that in most cases when annotations are used as part of a type pattern, the parenthesis are required (as in?(@Foo Hello+)). In some cases (such as a type pattern used within a?within?or?handler?pointcut expression), the parenthesis are optional:

OptionalParensTypePattern := AnnotationPattern? TypePattern

The following examples illustrate the use of annotations in type patterns:

(@Immutable *)

Matches any type with an?@Immutable?annotation.

(!@Immutable *)

Matches any type which does not have an?@Immutable?annotation.

(@Immutable (org.xyz.* || org.abc.*))

Matches any type in the?org.xyz?or?org.abc?packages with the?@Immutable?annotation.

((@Immutable Foo+) || Goo)

Matches a type?Foo?or any of its subtypes, which have the?@Immutable?annotation, or a type?Goo.

((@(Immutable || NonPersistent) org.xyz..*)

Matches any type in a package beginning with the prefix?org.xyz, which has either the?@Immutable?annotation or the?@NonPersistent?annotation.

(@Immutable @NonPersistent org.xyz..*)

Matches any type in a package beginning with the prefix?org.xyz, which has both an?@Immutable?annotation and an?@NonPersistent?annotation.

(@(@Inherited *) org.xyz..*)

Matches any type in a package beginning with the prefix?org.xyz, which has an inheritable annotation. The annotation pattern?@(@Inherited *)?matches any annotation of a type matching the type pattern?@Inherited *, which in turn matches any type with the?@Inherited?annotation.

?

Signature Patterns

?

Field Patterns

A?FieldPattern?can optionally specify an annotation-matching pattern as the first element:

FieldPattern := AnnotationPattern? FieldModifiersPattern? TypePattern (TypePattern DotOrDotDot)? SimpleNamePatternFieldModifiersPattern := '!'? FieldModifier FieldModifiersPattern*FieldModifier := 'public' | 'private' | 'protected' | 'static' | 'transient' | 'final' DotOrDotDot := '.' | '..' SimpleNamePattern := JavaIdentifierChar+ ('*' SimpleNamePattern)?

If present, the?AnnotationPattern?restricts matches to fields with annotations that match the pattern. For example:

@SensitiveData * *

Matches a field of any type and any name, that has an annotation of type?@SensitiveData

@SensitiveData List org.xyz..*.*

Matches a member field of a type in a package with prefix?org.xzy, where the field is of type?List, and has an annotation of type?@SensitiveData

(@SensitiveData *) org.xyz..*.*

Matches a member field of a type in a package with prefix?org.xzy, where the field is of a type which has a?@SensitiveData?annotation.

@Foo (@Goo *) (@Hoo *).*

Matches a field with an annotation?@Foo, of a type with an annotation?@Goo, declared in a type with annotation?@Hoo.

@Persisted @Classified * *

Matches a field with an annotation?@Persisted?and an annotation?@Classified.

?

Method and Constructor Patterns

A?MethodPattern?can optionally specify an annotation-matching pattern as the first element.

MethodPattern := AnnotationPattern? MethodModifiersPattern? TypePattern (TypePattern DotOrDotDot)? SimpleNamePattern '(' FormalsPattern ')'ThrowsPattern?MethodModifiersPattern := '!'? MethodModifier MethodModifiersPattern*MethodModifier := 'public' | 'private' | 'protected' | 'static' | 'synchronized' | 'final' FormalsPattern := '..' (',' FormalsPatternAfterDotDot)* |OptionalParensTypePattern (',' FormalsPattern)* |TypePattern '...'FormalsPatternAfterDotDot := OptionalParensTypePattern (',' FormalsPatternAfterDotDot)* |TypePattern '...'ThrowsPattern := 'throws' TypePatternListTypePatternList := TypePattern (',' TypePattern)*

A?ConstructorPattern?has the form

ConstructorPattern := AnnotationPattern? ConstructorModifiersPattern? (TypePattern DotOrDotDot)? 'new' '(' FormalsPattern ')'ThrowsPattern?ConstructorModifiersPattern := '!'? ConstructorModifier ConstructorModifiersPattern*ConstructorModifier := 'public' | 'private' | 'protected'

The optional?AnnotationPattern?at the beginning of a method or constructor pattern restricts matches to methods/constructors with annotations that match the pattern. For example:

@Oneway * *(..)

Matches a method with any return type and any name, that has an annotation of type?@Oneway.

@Transaction * (@Persistent org.xyz..*).*(..)

Matches a method with the?@Transaction?annotation, declared in a type with the?@Persistent?annotation, and in a package beginning with the?org.xyz?prefix.

* *.*(@Immutable *,..)

Matches any method taking at least one parameter, where the parameter type has an annotation?@Immutable.

?

Example Pointcuts

within(@Secure *)

Matches any join point where the code executing is declared in a type with an?@Secure?annotation. The format of the?within?pointcut designator in AspectJ 5 is?'within' '(' OptionalParensTypePattern ')'.

staticinitialization(@Persistent *)

Matches the staticinitialization join point of any type with the?@Persistent?annotation. The format of the?staticinitialization?pointcut designator in AspectJ 5 is?'staticinitialization' '(' OptionalParensTypePattern ')'.

call(@Oneway * *(..))

Matches a call to a method with a?@Oneway?annotation.

execution(public (@Immutable *) org.xyz..*.*(..))

The execution of any public method in a package with prefix?org.xyz, where the method returns an immutable result.

set(@Cachable * *)

Matches the set of any cachable field.

handler(!@Catastrophic *)

Matches the handler join point for the handling of any exception that is not?Catastrophic. The format of the?handler?pointcut designator in AspectJ 5 is?'handler' '(' OptionalParensTypePattern ')'.

?

Runtime type matching and context exposure

AspectJ 5 supports a set of "@" pointcut designators which can be used both to match based on the presence of an annotation at runtime, and to expose the annotation value as context in a pointcut or advice definition. These designators are?@args, @this, @target, @within, @withincode, and?@annotation

It is a compilation error to attempt to match on an annotation type that does not have runtime retention using?@this, @target?or?@args. It is a compilation error to attempt to use any of these designators to expose an annotation value that does not have runtime retention.

The?this(),?target(), and?args()?pointcut designators allow matching based on the runtime type of an object, as opposed to the statically declared type. In AspectJ 5, these designators are supplemented with three new designators :?@this()?(read, "this annotation"),?@target(), and?@args().

Like their counterparts, these pointcut designators can be used both for join point matching, and to expose context. The format of these new designators is:

AtThis := '@this' '(' AnnotationOrIdentifer ')'AtTarget := '@target' '(' AnnotationOrIdentifier ')'AnnotationOrIdentifier := FullyQualifiedName | IdentifierAtArgs := '@args' '(' AnnotationsOrIdentifiersPattern ')'AnnotationsOrIdentifiersPattern :='..' (',' AnnotationsOrIdentifiersPatternAfterDotDot)? |AnnotationOrIdentifier (',' AnnotationsOrIdentifiersPattern)* |'*' (',' AnnotationsOrIdentifiersPattern)*AnnotationsOrIdentifiersPatternAfterDotDot := AnnotationOrIdentifier (',' AnnotationsOrIdentifiersPatternAfterDotDot)* |'*' (',' AnnotationsOrIdentifiersPatternAfterDotDot)*

The forms of?@this()?and?@target()?that take a single annotation name are analogous to their counterparts that take a single type name. They match at join points where the object bound to?this?(or?target, respectively) has an annotation of the specified type. For example:

@this(Foo)

Matches any join point where the object currently bound to 'this' has an annotation of type?Foo.

call(* *(..)) && @target(Classified)

Matches a call to any object where the target of the call has a?@Classified?annotation.

Annotations can be exposed as context in the body of advice by using the forms of?@this(), @target()?and?@args()?that use bound variables in the place of annotation names. For example:

pointcut callToClassifiedObject(Classified classificationInfo) :call(* *(..)) && @target(classificationInfo);pointcut txRequiredMethod(Tx transactionAnnotation) :execution(* *(..)) && @this(transactionAnnotation) && if(transactionAnnotation.policy() == TxPolicy.REQUIRED);

The?@args?pointcut designator behaves as its?args?counterpart, matching join points based on number and position of arguments, and supporting the?*?wildcard and at most one?..?wildcard. An annotation at a given position in an?@args?expression indicates that the runtime type of the argument in that position at a join point must have an annotation of the indicated type. For example:

/*** matches any join point with at least one argument, and where the* type of the first argument has the @Classified annotation*/pointcut classifiedArgument() : @args(Classified,..);/*** matches any join point with three arguments, where the third* argument has an annotation of type @Untrusted.*/pointcut untrustedData(Untrusted untrustedDataSource) : @args(*,*,untrustedDataSource);

In addition to accessing annotation information at runtime through context binding, access to?AnnotatedElement?information is also available reflectively with the body of advice through the?thisJoinPoint,thisJoinPointStaticPart, and?thisEnclosingJoinPointStaticPart?variables. To access annotations on the arguments, or object bound to this or target at a join point you can use the following code fragments:

Annotation[] thisAnnotations = thisJoinPoint.getThis().getClass().getAnnotations();Annotation[] targetAnnotations = thisJoinPoint.getTarget().getClass().getAnnotations();Annotation[] firstParamAnnotations = thisJoinPoint.getArgs()[0].getClass().getAnnotations();

The?@within?and?@withincode?pointcut designators match any join point where the executing code is defined within a type (@within), or a method/constructor (@withincode) that has an annotation of the specified type. The form of these designators is:

AtWithin := '@within' '(' AnnotationOrIdentifier ')'AtWithinCode := '@withincode' '(' AnnotationOrIdentifier ')'

Some examples of using these designators follow:

@within(Foo)

Matches any join point where the executing code is defined within a type which has an annotation of type?Foo.

pointcut insideCriticalMethod(Critical c) : @withincode(c);

Matches any join point where the executing code is defined in a method or constructor which has an annotation of type?@Critical, and exposes the value of the annotation in the parameter?c.

The?@annotation?pointcut designator matches any join point where the?subject?of the join point has an annotation of the given type. Like the other @pcds, it can also be used for context exposure.

AtAnnotation := '@annotation' '(' AnnotationOrIdentifier ')'

The subject of a join point is defined in the table in chapter one of this guide.

Access to annotation information on members at a matched join point is also available through the?getSignature?method of the?JoinPoint?and?JoinPoint.StaticPart?interfaces. The?Signature?interfaces are extended with additional operations that provide access to the?java.lang.reflect?Method, Field?and?Constructor?objects on which annnotations can be queried. The following fragment illustrates an example use of this interface to access annotation information.

Signature sig = thisJoinPointStaticPart.getSignature();AnnotatedElement declaringTypeAnnotationInfo = sig.getDeclaringType();if (sig instanceof MethodSignature) {// this must be a call or execution join pointMethod method = ((MethodSignature)sig).getMethod();}

Note again that it would be nicer to add the method getAnnotationInfo directly to MemberSignature, but this would once more couple the runtime library to Java 5.

The?@this,@target?and?@args?pointcut designators can only be used to match against annotations that have runtime retention. The?@within, @withincode?and?@annotation?pointcut designators can only be used to match against annotations that have at least class-file retention, and if used in the binding form the annotation must have runtime retention.

?

Package and Parameter Annotations

Matching on package and parameter annotations is not supported in AspectJ 1.5.0. Support for this capability may be considered in a future release.

?

Annotation Inheritance and pointcut matching

According to the Java 5 specification, non-type annotations are not inherited, and annotations on types are only inherited if they have the?@Inherited?meta-annotation. Given the following program:

class C1 {@SomeAnnotationpublic void aMethod() {...}}class C2 extends C1 {public void aMethod() {...}}class Main {public static void main(String[] args) {C1 c1 = new C1();C2 c2 = new C2();c1.aMethod();c2.aMethod();}}aspect X {pointcut annotatedC2MethodCall() : call(@SomeAnnotation * C2.aMethod());pointcut annotatedMethodCall() :call(@SomeAnnotation * aMethod());}

The pointcut?annotatedC2MethodCall?will not match anything since the definition of?aMethod?in?C2?does not have the annotation.

The pointcut?annotatedMethodCall?matches?c1.aMethod()?but not?c2.aMethod(). The call to?c2.aMethod?is not matched because join point matching for modifiers (the visibility modifiers, annotations, and throws clause) is based on the subject of the join point (the method actually being called).

?

Matching based on annotation values

The?if?pointcut designator can be used to write pointcuts that match based on the values annotation members. For example:

pointcut txRequiredMethod(Tx transactionAnnotation) :execution(* *(..)) && @this(transactionAnnotation) && if(transactionAnnotation.policy() == TxPolicy.REQUIRED);

轉(zhuǎn)載于:https://my.oschina.net/yqz/blog/1604510

總結(jié)

以上是生活随笔為你收集整理的AspectJ Join Point Matching based on Annotations的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 人妻无码中文久久久久专区 | 一级黄色片在线免费观看 | 超碰人人99 | 国产精品视频一区二区三区在3 | 国产永久av| 美女扒开腿免费视频 | ass日本寡妇pics | 国产精品亚洲五月天丁香 | 国产aa视频 | 亚洲AV乱码国产精品观看麻豆 | 91免费网站入口 | 中文字幕一区二区三区乱码人妻 | 内谢少妇xxxxx8老少交视频 | 欧美久久久久久久久中文字幕 | 一道本无吗一区 | 欧美你懂得 | 国产成人av电影 | 午夜久久久久久 | 91视频免费 | a√在线观看 | 国产精品一区二区三区在线免费观看 | 超碰国产97| 91亚洲国产成人久久精品麻豆 | 国产精品伦子伦 | 日韩人妻精品一区二区三区视频 | 玩弄丰满少妇xxxxx性多毛 | 久久久高清视频 | 性的免费视频 | 亚洲高清在线观看视频 | 精品国产一区二区三区在线 | 中文字幕精品久久久久人妻红杏ⅰ | 91欧美日韩国产 | 久久澡| 都市激情校园春色亚洲 | 性一交一乱一透一a级 | 国产欧美一区二区三区鸳鸯浴 | 亚洲国产精品视频在线 | 国产又粗又长又黄 | 欧美一级欧美三级在线观看 | 一级黄色片免费 | 在线成人欧美 | 午夜精品久久久久久久第一页按摩 | 久久久在线观看 | 美女伊人网 | 高潮毛片又色又爽免费 | 欧美在线精品一区 | 国产第六页 | 成人性生交大片免费卡看 | 制服一区| 成人久久精品 | 玉蒲团在线 | 人妻射精一区二区 | 最近中文字幕在线免费观看 | 最新中文字幕第一页 | av中文字幕在线播放 | 亚洲第一成人在线 | 天堂网中文在线 | 日本不卡一区在线观看 | 日韩免费网址 | 蜜桃色一区二区三区 | 波多野结衣网站 | 亚洲性一区| 91在线免费看片 | 国产精品第五页 | 青青插 | 青青青在线视频观看 | 成人久久久 | 日本不卡在线观看 | 最新在线观看av | 欧美综合图片 | 91香焦视频| 阿v免费在线观看 | 91伊人久久| 中文字幕伦理 | 日韩经典一区二区三区 | 欧洲亚洲国产精品 | 欧美性xxxxx极品娇小 | 美日韩在线 | 欧美v日韩 | 黑人黄色大片 | 精品交短篇合集 | 交专区videossex非洲 | sm调教羞耻姿势图片 | 亚洲欧美视频在线观看 | av大全网站 | 五月天精品在线 | 亚洲午夜久久久 | 美女啪啪一区二区 | 蜜臀精品 | 成年人在线观看网站 | 国产高清精品在线 | 国产亚洲欧美一区二区三区 | 男同av在线观看一区二区三区 | 精品国产乱子伦一区二区 | 成人精品一区二区三区电影 | 国产精品99久久久久久久女警 | 97人人干| 亚洲精品黄色 | 草久久久久 |