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

198 天前
 Sherman07
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()方法紧跟在调用它的位置下方的代码顺序。
这种代码顺序的选择是基于团队良好的代码风格还是通过工具进行自动调整的?另外想了解有没有代码风格的最佳实践以及优化代码顺序的相关工具?
613 次点击
所在节点    Java
1 条回复
Rache1
198 天前
Jetbrains IDE 的 Code Style 最后面 Arrangement 里面可以调整。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/984899

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX