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

javacutil.src.org.checkerframework.javacutil.BasicTypeProcessor 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.javacutil;

import javax.lang.model.element.TypeElement;

import com.sun.source.tree.CompilationUnitTree;

import com.sun.source.util.TreePath;
import com.sun.source.util.TreePathScanner;

/**
 * Process the types in an AST in a trivial manner, with hooks for derived classes
 * to actually do something.
 */
public abstract class BasicTypeProcessor extends AbstractTypeProcessor {
    /** The source tree that's being scanned. */
    protected CompilationUnitTree currentRoot;

    /**
     * Create a TreePathScanner at the given root.
     */
    protected abstract TreePathScanner createTreePathScanner(CompilationUnitTree root);

    /**
     * Visit the tree path for the type element.
     */
    @Override
    public void typeProcess(TypeElement e, TreePath p) {
        currentRoot = p.getCompilationUnit();

        TreePathScanner scanner = null;
        try {
            scanner = createTreePathScanner(currentRoot);
            scanner.scan(p, null);
        } catch (Throwable t) {
            System.err.println("BasicTypeProcessor.typeProcess: unexpected Throwable (" +
                    t.getClass().getSimpleName() + ")  when processing "
                    + currentRoot.getSourceFile().getName() +
                    (t.getMessage()!=null ? "; message: " + t.getMessage() : ""));
        }
    }

}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy