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

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

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

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

    NoCallsIntoTestFromOutside ?? ?禁止從產(chǎn)品包到測試包的引用

    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 ??? 禁止構(gòu)造實(shí)用工具類


    public aspect UtilityClassEnforced {
    ?? ?
    ??? declare error :
    ??? ??? //定義非private 的構(gòu)造器
    ??? ??? execution(!private (@UtilityClass *).new(..))
    ??? ??? //調(diào)用new 初始化方法
    ??? ??? || call((@UtilityClass *).new(..))
    ??? ??? //執(zhí)行工具類的任何方法
    ??? ??? || 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";
    ???? //執(zhí)行Throwable.printStackTrace()方法
    ??? declare error: withinTypes() && call(void Throwable.printStackTrace()) : "no System.err";
    }

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

    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*方法或者構(gòu)造器以外地方使用
    ?? ??? ?!(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 ?? ?????? 在公共方法傳遞空參數(shù)時拋出異常

    public abstract aspect NoNullParameters {
    ?? ?abstract protected pointcut withinTypes();
    ?? ?
    ?? ?pointcut publicParameters() :
    ?? ??? ? //執(zhí)行public 構(gòu)造器或者public 方法
    ?? ??? ?(execution(public new(*,..)) || execution(public * *(*,..)))
    ?? ??? ? //除了執(zhí)行非Object的參數(shù),如原類型,int,long
    ?? ??? ?&& !(execution(* *(!Object+)) || execution(*.new(!Object+)));
    ?? ?//如果參數(shù)為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

    搜索

    •  

    積分與排名

    • 積分 - 358070
    • 排名 - 156

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 亚洲成人高清在线观看| 国产亚洲综合一区柠檬导航| 亚洲免费视频网址| 中文字幕在线亚洲精品 | 亚洲免费中文字幕| 可以免费看黄的网站| 免费吃奶摸下激烈视频| 亚洲一区二区三区高清| 黄床大片30分钟免费看| 国产又大又黑又粗免费视频| 曰皮全部过程视频免费国产30分钟| 亚洲深深色噜噜狠狠网站| 五月天婷婷精品免费视频| 精品无码免费专区毛片| 亚洲女人初试黑人巨高清| 午夜宅男在线永久免费观看网| 亚洲精品国产国语| 国产免费一区二区三区VR| 一级一级一片免费高清| 精品亚洲综合在线第一区| 无码色偷偷亚洲国内自拍| 国产又大又黑又粗免费视频| 国产成人无码精品久久久免费| 亚洲线精品一区二区三区影音先锋 | 国产免费久久久久久无码| 亚洲国产精品无码久久久秋霞2| 久久久精品免费视频| 亚洲中文无码线在线观看| 亚洲欧美在线x视频| 亚洲国产综合无码一区二区二三区| 永久免费无码日韩视频| 亚洲AV人无码激艳猛片| 国产精品久久久久免费a∨| 国产精品成人亚洲| 午夜寂寞在线一级观看免费| 亚洲国产超清无码专区| 天天摸天天碰成人免费视频| fc2免费人成在线| 亚洲福利电影一区二区?| 精品无码人妻一区二区免费蜜桃| 91亚洲性爱在线视频|