<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    閑人野居
    好好學習,天天向上
    posts - 57,  comments - 137,  trackbacks - 0
    收集了幾個常用的方面:

    NoCallsIntoTestFromOutside ?? ?禁止從產品包到測試包的引用

    public abstract aspect NoCallsIntoTestFromOutside {
    ?? ?//引用帶有test的包的所有可能操作
    ?? ?pointcut referToTestPackage():
    ?? ???? call(* *..test..*.*(..)) || call(*..test..*.new(..))
    ?? ???? || get(* *..test..*.*) || set(* *..test..*.*)
    ?? ???? || get(*..test..* *) || set(*..test..* *)
    ?? ???? || (staticinitialization(!*..test..*)
    ?? ??????? && staticinitialization(*..test..*+))
    ?? ???? || call(* *(*..test..*, ..))
    ?? ???? || call(* *(*, *..test..*, ..))
    ?? ???? || call(* *(*, *, *..test..*))
    ?? ???? || call(* *(.., *..test..*))
    ?? ???? || execution(* *(*..test..*, ..))
    ?? ???? || execution(* *(*, *..test..*, ..))
    ?? ???? || execution(* *(*, *, *..test..*, ..))
    ?? ???? || execution(* *(.., *..test..*))
    ?? ???? ;
    ?? ?// getcode scary-tests END

    ?? ?abstract protected pointcut withinTypes();

    ?? ?pointcut fromWithinNonTest(): within(!*..test..*);

    ?? ?declare error: withinTypes() && referToTestPackage()
    ?? ??? ?&& fromWithinNonTest(): "production code referring to test code";?? ?
    }

    UtilityClassEnforced ??? 禁止構造實用工具類


    public aspect UtilityClassEnforced {
    ?? ?
    ??? declare error :
    ??? ??? //定義非private 的構造器
    ??? ??? execution(!private (@UtilityClass *).new(..))
    ??? ??? //調用new 初始化方法
    ??? ??? || call((@UtilityClass *).new(..))
    ??? ??? //執行工具類的任何方法
    ??? ??? || execution((@UtilityClass *) *(..))??? ???
    ??? ??? : "no instances of utility classes";

    }

    @Retention(RetentionPolicy.RUNTIME)
    @Target({ElementType.TYPE})
    public @interface UtilityClass {

    }

    NoSystemOut ??? 禁止使用 System.err 或 System.out

    public abstract aspect NoSystemOut {
    ??? abstract protected pointcut withinTypes;
    ??? //讀取System.out對象
    ??? declare error: withinTypes() && get(PrintStream System.out) : "no System.out";
    ???? //讀取System.err對象
    ??? declare error: withinTypes() && get(PrintStream System.err) : "no System.err";
    ??? //讀取FileDescriptor.err
    ??? declare error: withinTypes() && get(PrintStream FileDescriptor.err) : "no FileDescriptor.err";
    ??? //讀取FileDescriptor.out
    ??? declare error: withinTypes() && get(PrintStream FileDescriptor.out) : "no FileDescriptor.out";
    ???? //執行Throwable.printStackTrace()方法
    ??? declare error: withinTypes() && call(void Throwable.printStackTrace()) : "no System.err";
    }

    GetterSetter ?? ?禁止在除初始化或 getter 方法以外進行字段讀取操作,禁止在初始化或 setter 方法以外進行字段寫操作

    public abstract aspect GetterSetter {
    ?? ?
    ?? ?abstract protected pointcut withinTypes();
    ?? ?//所有的sets 非public fields
    ?? ?pointcut sets() : set(!public * *);
    ?????? //所有的gets 非public fields
    ?? ?pointcut gets() : get(!public * *);
    ?? ?declare error : withinTypes() && gets() &&
    ?? ??? ?//在get*方法或者構造器以外地方使用
    ?? ??? ?!(withincode(!void get*()) || withincode(new(..)))
    ?? ??? ?: "non-public field-get outside constructor or getter method";
    ?? ?declare error : withinTypes() && sets() &&
    ?? ??? ?!(withincode(void set*(*)) || withincode(new(..)))
    ?? ??? ?: "non-public field-set outside constructor or setter method";
    }

    NoNullParameters ?? ?????? 在公共方法傳遞空參數時拋出異常

    public abstract aspect NoNullParameters {
    ?? ?abstract protected pointcut withinTypes();
    ?? ?
    ?? ?pointcut publicParameters() :
    ?? ??? ? //執行public 構造器或者public 方法
    ?? ??? ?(execution(public new(*,..)) || execution(public * *(*,..)))
    ?? ??? ? //除了執行非Object的參數,如原類型,int,long
    ?? ??? ?&& !(execution(* *(!Object+)) || execution(*.new(!Object+)));
    ?? ?//如果參數為null,則拋出例外?? ??? ??? ?
    ?? ?before() : withinTypes() && publicParameters() {
    ?? ??? ?Object[] args = thisJoinPoint.getArgs();
    ?? ??? ?for (int i = 0; i < args.length; i++) {
    ?? ??? ??? ?if (null == args[i]) {
    ?? ??? ??? ??? ?JoinPoint.StaticPart sp = thisJoinPointStaticPart;
    ?? ??? ??? ??? ?String name = AJReflect.getParameterName(sp, i);
    ?? ??? ??? ??? ?throw new IllegalArgumentException("null " + name);
    ?? ??? ??? ?}
    ?? ??? ?}
    ?? ?}
    }
    posted on 2006-11-16 18:56 布衣郎 閱讀(1077) 評論(0)  編輯  收藏 所屬分類: aop

    <2006年11月>
    2930311234
    567891011
    12131415161718
    19202122232425
    262728293012
    3456789

    常用鏈接

    留言簿(12)

    隨筆分類(59)

    隨筆檔案(57)

    blog

    java

    uml

    搜索

    •  

    積分與排名

    • 積分 - 358071
    • 排名 - 156

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 亚洲Av无码国产情品久久 | 亚洲日韩AV一区二区三区四区| 亚洲电影中文字幕| 亚洲中文字幕一二三四区苍井空 | 成年性生交大片免费看| 国产免费AV片无码永久免费| 久久久久亚洲精品中文字幕| 亚洲一区免费观看| 未满十八18禁止免费无码网站| 亚洲一区二区三区香蕉| 亚洲嫩草影院在线观看| 免费观看激色视频网站(性色)| 亚洲成人高清在线| 久久久久免费视频| 九月丁香婷婷亚洲综合色| 久久精品国产这里是免费| 亚洲国产日韩女人aaaaaa毛片在线| 免费三级毛片电影片| 亚洲AV综合永久无码精品天堂| 国产色爽免费无码视频| 久久久久亚洲AV无码专区首| 免费毛片a在线观看67194 | 亚洲成A人片在线观看无码3D | 两个人看的www高清免费视频| 亚洲精选在线观看| 一级特黄a免费大片| 亚洲成AV人片在| 青青在线久青草免费观看| 亚洲av无码日韩av无码网站冲| 亚洲精品亚洲人成在线观看下载| 国产无遮挡又黄又爽免费网站| 91亚洲国产成人精品下载| 女人18毛片特级一级免费视频| 免费的黄网站男人的天堂| 亚洲va久久久噜噜噜久久| 一区二区三区免费在线视频| 日韩一区二区在线免费观看| 亚洲国产免费综合| 亚洲区日韩区无码区| 3344永久在线观看视频免费首页| 亚洲AV无码专区在线播放中文|