Java Code Examples for org.springframework.core.annotation.AnnotatedElementUtils#getMergedRepeatableAnnotations()

The following examples show how to use org.springframework.core.annotation.AnnotatedElementUtils#getMergedRepeatableAnnotations() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SqlScriptsTestExecutionListener.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * 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);
	}
}
 
Example 2
Source File: SqlScriptsTestExecutionListener.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * 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);
	}
}
 
Example 3
Source File: AuthCheckerHandlerInterceptor.java    From stategen with GNU Affero General Public License v3.0 6 votes vote down vote up
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);
                }
            }
        }
    }
}
 
Example 4
Source File: EmbeddedPostgresContextCustomizerFactory.java    From embedded-database-spring-test with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 5
Source File: MvcInterceptorManager.java    From onetwo with Apache License 2.0 6 votes vote down vote up
/***
 * 直接查找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;
}
 
Example 6
Source File: XResponseViewManager.java    From onetwo with Apache License 2.0 5 votes vote down vote up
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));
}
 
Example 7
Source File: MvcInterceptorManager.java    From onetwo with Apache License 2.0 5 votes vote down vote up
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());
}
 
Example 8
Source File: MethodWrap.java    From stategen with GNU Affero General Public License v3.0 4 votes vote down vote up
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);
}