Home / Class/ Tree Class — spring-boot Architecture

Tree Class — spring-boot Architecture

Architecture documentation for the Tree class in Tree.java from the spring-boot codebase.

Entity Profile

Source Code

configuration-metadata/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/fieldvalues/javac/Tree.java lines 28–75

class Tree extends ReflectionWrapper {

	private final Class<?> treeVisitorType = findClass("com.sun.source.tree.TreeVisitor");

	private final Method acceptMethod = findMethod("accept", this.treeVisitorType, Object.class);

	private final Method getClassTreeMembers = findMethod(findClass("com.sun.source.tree.ClassTree"), "getMembers");

	Tree(Object instance) {
		super("com.sun.source.tree.Tree", instance);
	}

	void accept(TreeVisitor visitor) throws Exception {
		this.acceptMethod.invoke(getInstance(), Proxy.newProxyInstance(getInstance().getClass().getClassLoader(),
				new Class<?>[] { this.treeVisitorType }, new TreeVisitorInvocationHandler(visitor)), 0);
	}

	/**
	 * {@link InvocationHandler} to call the {@link TreeVisitor}.
	 */
	private class TreeVisitorInvocationHandler implements InvocationHandler {

		private TreeVisitor treeVisitor;

		TreeVisitorInvocationHandler(TreeVisitor treeVisitor) {
			this.treeVisitor = treeVisitor;
		}

		@Override
		@SuppressWarnings("rawtypes")
		public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
			if (method.getName().equals("visitClass") && (Integer) args[1] == 0) {
				Iterable members = (Iterable) Tree.this.getClassTreeMembers.invoke(args[0]);
				for (Object member : members) {
					if (member != null) {
						Tree.this.acceptMethod.invoke(member, proxy, ((Integer) args[1]) + 1);
					}
				}
			}
			if (method.getName().equals("visitVariable")) {
				this.treeVisitor.visitVariable(new VariableTree(args[0]));
			}
			return null;
		}

	}

}

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free