aboutsummaryrefslogtreecommitdiffhomepage
path: root/third_party/checker_framework_javacutil/java/org/checkerframework/javacutil/BasicTypeProcessor.java
blob: 6b68fa4dc23be351ea972548220854be111dfe43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package org.checkerframework.javacutil;

import com.sun.source.tree.CompilationUnitTree;
import com.sun.source.util.TreePath;
import com.sun.source.util.TreePathScanner;
import javax.lang.model.element.TypeElement;

/**
 * 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() : ""));
        }
    }
}