org.springframework.core.annotation.AnnotatedElementUtils#getMergedRepeatableAnnotations ( )源码实例Demo

下面列出了org.springframework.core.annotation.AnnotatedElementUtils#getMergedRepeatableAnnotations ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

/**
 * Execute SQL scripts configured via {@link Sql @Sql} for the supplied
 * {@link TestContext} and {@link ExecutionPhase}.
 */
private void executeSqlScripts(TestContext testContext, ExecutionPhase executionPhase) throws Exception {
	boolean classLevel = false;

	Set<Sql> sqlAnnotations = AnnotatedElementUtils.getMergedRepeatableAnnotations(
			testContext.getTestMethod(), Sql.class, SqlGroup.class);
	if (sqlAnnotations.isEmpty()) {
		sqlAnnotations = AnnotatedElementUtils.getMergedRepeatableAnnotations(
				testContext.getTestClass(), Sql.class, SqlGroup.class);
		if (!sqlAnnotations.isEmpty()) {
			classLevel = true;
		}
	}

	for (Sql sql : sqlAnnotations) {
		executeSqlScripts(sql, executionPhase, testContext, classLevel);
	}
}
 
/**
 * Execute SQL scripts configured via {@link Sql @Sql} for the supplied
 * {@link TestContext} and {@link ExecutionPhase}.
 */
private void executeSqlScripts(TestContext testContext, ExecutionPhase executionPhase) throws Exception {
	boolean classLevel = false;

	Set<Sql> sqlAnnotations = AnnotatedElementUtils.getMergedRepeatableAnnotations(
			testContext.getTestMethod(), Sql.class, SqlGroup.class);
	if (sqlAnnotations.isEmpty()) {
		sqlAnnotations = AnnotatedElementUtils.getMergedRepeatableAnnotations(
				testContext.getTestClass(), Sql.class, SqlGroup.class);
		if (!sqlAnnotations.isEmpty()) {
			classLevel = true;
		}
	}

	for (Sql sql : sqlAnnotations) {
		executeSqlScripts(sql, executionPhase, testContext, classLevel);
	}
}
 
源代码3 项目: stategen   文件: AuthCheckerHandlerInterceptor.java
protected void scanCheckAnnos(AnnotatedElement annotatedElement, TagArrayList<Annotation> checkAnnos) {
    Annotation[] annotations = AnnotationUtils.getAnnotations(annotatedElement);
    if (CollectionUtil.isNotEmpty(annotations)) {
        for (Annotation annotation : annotations) {
            //在anno上查找,是否有anno标注为Check
            Check check = AnnotationUtils.getAnnotation(annotation, Check.class);
            if (check != null) {
                Repeatable repeatable = AnnotationUtils.getAnnotation(annotation, Repeatable.class);
                if (repeatable != null) {
                    Class<? extends Annotation> realCheckAnnoClazz = repeatable.value();
                    Set<? extends Annotation> realCheckAnnos = AnnotatedElementUtils.getMergedRepeatableAnnotations(annotatedElement,
                        realCheckAnnoClazz);
                    checkAnnos.addAll(realCheckAnnos);
                } else {
                    checkAnnos.add(annotation);
                }
            }
        }
    }
}
 
@Override
public ContextCustomizer createContextCustomizer(Class<?> testClass, List<ContextConfigurationAttributes> configAttributes) {
    Set<AutoConfigureEmbeddedDatabase> databaseAnnotations = AnnotatedElementUtils.getMergedRepeatableAnnotations(
            testClass, AutoConfigureEmbeddedDatabase.class, AutoConfigureEmbeddedDatabases.class);

    databaseAnnotations = databaseAnnotations.stream()
            .filter(distinctByKey(AutoConfigureEmbeddedDatabase::beanName))
            .filter(databaseAnnotation -> databaseAnnotation.type() == EmbeddedDatabaseType.POSTGRES)
            .filter(databaseAnnotation -> databaseAnnotation.replace() != Replace.NONE)
            .collect(Collectors.toCollection(LinkedHashSet::new));

    if (!databaseAnnotations.isEmpty()) {
        return new PreloadableEmbeddedPostgresContextCustomizer(databaseAnnotations);
    }

    return null;
}
 
源代码5 项目: onetwo   文件: MvcInterceptorManager.java
/***
 * 直接查找Interceptor
 * @author wayshall
 * @param hm
 * @return
 */
final protected Collection<AnnotationAttributes> findInterceptorAnnotationAttrsList(HandlerMethod hm){
	Set<Interceptor> inters = AnnotatedElementUtils.getMergedRepeatableAnnotations(hm.getMethod(), Interceptor.class);
	if(LangUtils.isEmpty(inters)){
		inters = AnnotatedElementUtils.getMergedRepeatableAnnotations(hm.getBeanType(), Interceptor.class);
	}
	if(LangUtils.isEmpty(inters)){
		return Collections.emptyList();
	}
	Collection<AnnotationAttributes> attrs = inters.stream()
													.map(inter->org.springframework.core.annotation.AnnotationUtils.getAnnotationAttributes(null, inter))
													.collect(Collectors.toSet());
	boolean hasDisabledFlag = attrs.stream()
									.anyMatch(attr->asMvcInterceptorMeta(attr).getInterceptorType()==DisableMvcInterceptor.class);
	if(hasDisabledFlag){
		return Collections.emptyList();
	}
	return attrs;
}
 
源代码6 项目: onetwo   文件: XResponseViewManager.java
static Map<String, XResponseViewData> findXResponseViewData(HandlerMethod hm){
	Set<XResponseView> attrs = AnnotatedElementUtils.getMergedRepeatableAnnotations(hm.getMethod(), XResponseView.class);
	if(LangUtils.isEmpty(attrs)){
		attrs = AnnotatedElementUtils.getMergedRepeatableAnnotations(hm.getBeanType(), XResponseView.class);
		if(LangUtils.isEmpty(attrs)){
			return Collections.emptyMap();
		}
	}
	return attrs.stream().map(view->{
		return new XResponseViewData(view.value(), view.wrapper());
	})
	.collect(Collectors.toMap(e->e.getViewName(), e->e));
}
 
源代码7 项目: onetwo   文件: MvcInterceptorManager.java
final protected Collection<AnnotationAttributes> derectFindInterceptorAnnotationAttrsList(HandlerMethod hm){
	//间接包含了@Interceptor的,也能找到……
	Set<Interceptor> inters = AnnotatedElementUtils.getMergedRepeatableAnnotations(hm.getMethod(), Interceptor.class);
	if(LangUtils.isEmpty(inters)){
		inters = AnnotatedElementUtils.getMergedRepeatableAnnotations(hm.getBeanType(), Interceptor.class);
	}
	if(LangUtils.isEmpty(inters)){
		return Collections.emptyList();
	}
	return inters.stream()
				.map(inter->org.springframework.core.annotation.AnnotationUtils.getAnnotationAttributes(null, inter))
				.collect(Collectors.toSet());
}
 
源代码8 项目: stategen   文件: MethodWrap.java
private void genState() {
    //todo 如查泛型没定义,应该报一个异常
    Class<?> returnClz = returnWrap.getIsGeneric() ? returnWrap.getGeneric().getClazz() : returnWrap.getClazz();
    boolean stateFieldAdded = false;

    DataOpt dataOpt = DataOpt.APPEND_OR_UPDATE;
    Set<String> areaExtraProps = null;
    Set<String> stateExtraProps = null;
    Boolean init = false;
    Boolean isSetted = false;
    Boolean genEffect = true;
    Boolean genReducer = true;
    Boolean initCheck = true;
    BaseWrap areaTemp = null;
    Boolean genRefresh = false;

    StateWrap stateWrap = new StateWrap();
    this.setState(stateWrap);
    Set<AreaExtraProp> areaExtraPropAnnos = AnnotatedElementUtils.getMergedRepeatableAnnotations(methodFun, AreaExtraProp.class);
    areaExtraProps = CollectionUtil.toSet(areaExtraPropAnnos, AreaExtraProp::value);

    Set<StateExtraProp> stateExtraPropAnnos = AnnotatedElementUtils.getMergedRepeatableAnnotations(methodFun, StateExtraProp.class);
    stateExtraProps = CollectionUtil.toSet(stateExtraPropAnnos, StateExtraProp::value);

    genEffect = AnnotationUtil.getAnnotationValueFormMembers(GenEffect.class, GenEffect::value, false, methodFun);
    genReducer = AnnotationUtil.getAnnotationValueFormMembers(GenReducer.class, GenReducer::value, false, methodFun);
    genRefresh = AnnotationUtil.getAnnotationValueFormMembers(GenRefresh.class, GenRefresh::value, false, methodFun);

    State stateAnno = AnnotatedElementUtils.getMergedAnnotation(methodFun, State.class);
    if (stateAnno != null) {
        init = stateAnno.init();
        dataOpt = stateAnno.dataOpt();
        isSetted = true;
        initCheck = stateAnno.initCheck();
        Class<?> stateAreaClass = stateAnno.area();
        if (stateAreaClass != Object.class) {
            if (stateAreaClass != returnClz) {
                areaTemp = GenContext.wrapContainer.add(stateAreaClass, false);
                stateFieldAdded = true;
            }
        }
    }

    if (stateAnno!=null && !stateFieldAdded && area == null) {
        if (returnClz != Object.class && GenContext.wrapContainer.checkIsOrgSimpleOrEnum(returnClz) && ((ApiWrap) apiWrap).getGenModel()) {
            String errMessage = "未指定area,如 @State(area=User.class),只有返回值是非基本类型、SimpleResponse、Object可以不指定area"
                                + ReflectionUtil.getJavaConsoleLink(methodFun);
            AssertUtil.throwException(errMessage);
        }
        areaTemp = GenContext.wrapContainer.add(returnClz, false);
    }

    if (areaTemp != null && !SimpleResponse.class.isAssignableFrom(areaTemp.getClazz())) {
        apiWrap.addArea(areaTemp);
        this.area = areaTemp;
    }

    if (areaTemp == null) {

    }

    stateWrap.setInit(init);
    stateWrap.setAreaExtraProps(areaExtraProps);
    stateWrap.setStateExtraProps(stateExtraProps);
    stateWrap.setDataOpt(dataOpt);
    stateWrap.setIsSetted(isSetted);
    stateWrap.setGenEffect(genEffect);
    stateWrap.setInitCheck(initCheck);
    stateWrap.setGenRefresh(genRefresh);
    stateWrap.setGenReducer(genReducer);
}