org.openrewrite.java.TreeVisitingPrinter Maven / Gradle / Ivy
Show all versions of rewrite-java Show documentation
/*
* Copyright 2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.openrewrite.java;
import org.jspecify.annotations.Nullable;
import org.openrewrite.*;
import org.openrewrite.java.tree.*;
import java.util.*;
import java.util.stream.Collectors;
import static java.util.stream.Collectors.joining;
import static java.util.stream.StreamSupport.stream;
/**
* A visitor to print a tree visiting order and hierarchy in format like below.
*
* ----J.CompilationUnit
* |-------J.Import | "..."
* | \---J.FieldAccess | "..."
* | ...
* \---J.ClassDeclaration
* |---J.Identifier | "..."
* \---J.Block
* ...
*
*/
public class TreeVisitingPrinter extends TreeVisitor {
private static final String TAB = " ";
private static final String ELEMENT_PREFIX = "\\---";
private static final String CONTINUE_PREFIX = "----";
private static final String UNVISITED_PREFIX = "#";
private static final char BRANCH_CONTINUE_CHAR = '|';
private static final char BRANCH_END_CHAR = '\\';
private static final int CONTENT_MAX_LENGTH = 120;
private List