Sherman07
V2EX  ›  Java

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

  •  
  •   Sherman07 · Oct 24, 2023 · 2421 views
    This topic created in 956 days ago, the information mentioned may be changed or developed.
    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 replies    2023-10-24 15:59:18 +08:00
    Rache1
        1
    Rache1  
       Oct 24, 2023   ❤️ 1
    Jetbrains IDE 的 Code Style 最后面 Arrangement 里面可以调整。

    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2583 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 11:03 · PVG 19:03 · LAX 04:03 · JFK 07:03
    ♥ Do have faith in what you're doing.