V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Sherman07
V2EX  ›  Java

Spring 源码中的函数顺序是使用工具自动调整的吗?

  •  
  •   Sherman07 · 186 天前 · 605 次点击
    这是一个创建于 186 天前的主题,其中的信息可能已经有所发展或是发生改变。
    class OnWebApplicationCondition extends SpringBootCondition {
    	private static final String WEB_CONTEXT_CLASS = "org.springframework.web.context."
    			+ "support.GenericWebApplicationContext";
    
    	@Override
    	public ConditionOutcome getMatchOutcome(ConditionContext context,
    			AnnotatedTypeMetadata metadata) {
    		boolean required = metadata
    				.isAnnotated(ConditionalOnWebApplication.class.getName());
    		ConditionOutcome outcome = isWebApplication(context, metadata, required);
    		if (required && !outcome.isMatch()) {
    			return ConditionOutcome.noMatch(outcome.getConditionMessage());
    		}
    		if (!required && outcome.isMatch()) {
    			return ConditionOutcome.noMatch(outcome.getConditionMessage());
    		}
    		return ConditionOutcome.match(outcome.getConditionMessage());
    	}
    
    	private ConditionOutcome isWebApplication(ConditionContext context,
    			AnnotatedTypeMetadata metadata, boolean required) {
    		switch (deduceType(metadata)) {
    		case SERVLET:
    			return isServletWebApplication(context);
    		case REACTIVE:
    			return isReactiveWebApplication(context);
    		default:
    			return isAnyWebApplication(context, required);
    		}
    	}
    
    在 Spring 源码中,经常看到类似于 getMatchOutcome()方法调用 isWebApplication()方法,并且 isWebApplication()方法紧跟在调用它的位置下方的代码顺序。
    这种代码顺序的选择是基于团队良好的代码风格还是通过工具进行自动调整的?另外想了解有没有代码风格的最佳实践以及优化代码顺序的相关工具?
    
    1 条回复    2023-10-24 15:59:18 +08:00
    Rache1
        1
    Rache1  
       186 天前   ❤️ 1
    Jetbrains IDE 的 Code Style 最后面 Arrangement 里面可以调整。

    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2854 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 09:46 · PVG 17:46 · LAX 02:46 · JFK 05:46
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.