All Downloads are FREE. Search and download functionalities are using the official Maven repository.

framework.src.org.checkerframework.framework.type.treeannotator.DebugListTreeAnnotator Maven / Gradle / Ivy

Go to download

The Checker Framework enhances Java’s type system to make it more powerful and useful. This lets software developers detect and prevent errors in their Java programs. The Checker Framework includes compiler plug-ins ("checkers") that find bugs or verify their absence. It also permits you to write your own compiler plug-ins.

There is a newer version: 3.42.0
Show newest version
package org.checkerframework.framework.type.treeannotator;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

import com.sun.source.tree.Tree;
import com.sun.source.tree.Tree.Kind;
import org.checkerframework.framework.type.AnnotatedTypeMirror;

/** A ListTreeAnnotator implementation that additionally
 * outputs debugging information.
 */
public class DebugListTreeAnnotator extends ListTreeAnnotator {
    private final Set kinds;

    public DebugListTreeAnnotator(TreeAnnotator... annotators) {
        super(annotators);
        kinds = Collections.emptySet();
    }

    public DebugListTreeAnnotator(Tree.Kind[] kinds, TreeAnnotator... annotators) {
        super(annotators);
        this.kinds = new HashSet<>(Arrays.asList(kinds));
    }

    @Override
    public Void defaultAction(Tree node, AnnotatedTypeMirror type) {
        if (kinds.contains(node.getKind())) {
            System.out.println("DebugListTreeAnnotator input tree: " + node);
            System.out.println("    Initial type: " + type);
            for (TreeAnnotator annotator : annotators) {
                System.out.println("    Running annotator: " + annotator.getClass());
                annotator.visit(node, type);
                System.out.println("    Current type: " + type);
            }
        } else {
            super.defaultAction(node, type);
        }

        return null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy