aboutsummaryrefslogtreecommitdiffhomepage
path: root/third_party/checker_framework_javacutil/java/org/checkerframework/javacutil/AbstractTypeProcessor.java
diff options
context:
space:
mode:
authorGravatar Liam Miller-Cushon <cushon@google.com>2017-10-15 23:31:56 -0700
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2017-10-16 14:16:39 +0200
commit6bf3f268f4a01963a2ee13f60178664bb056a802 (patch)
tree32a870dc293e07af88f52b241c75d9cbd462f63f /third_party/checker_framework_javacutil/java/org/checkerframework/javacutil/AbstractTypeProcessor.java
parent80a34dc97799961201e6dce20fd58dd08022c032 (diff)
Update checker framework dataflow and javacutils to 2.1.14
Change-Id: I62ad827fc4bbd54d022097003af63e351e44b98c
Diffstat (limited to 'third_party/checker_framework_javacutil/java/org/checkerframework/javacutil/AbstractTypeProcessor.java')
-rw-r--r--third_party/checker_framework_javacutil/java/org/checkerframework/javacutil/AbstractTypeProcessor.java184
1 files changed, 82 insertions, 102 deletions
diff --git a/third_party/checker_framework_javacutil/java/org/checkerframework/javacutil/AbstractTypeProcessor.java b/third_party/checker_framework_javacutil/java/org/checkerframework/javacutil/AbstractTypeProcessor.java
index 04389039e8..114ce6d0b6 100644
--- a/third_party/checker_framework_javacutil/java/org/checkerframework/javacutil/AbstractTypeProcessor.java
+++ b/third_party/checker_framework_javacutil/java/org/checkerframework/javacutil/AbstractTypeProcessor.java
@@ -1,136 +1,117 @@
package org.checkerframework.javacutil;
-import java.util.HashSet;
-import java.util.Set;
-
-import javax.annotation.processing.*;
-import javax.lang.model.element.Name;
-import javax.lang.model.element.TypeElement;
-import javax.lang.model.util.ElementFilter;
-
-import com.sun.tools.javac.main.JavaCompiler;
-import com.sun.tools.javac.comp.CompileStates.CompileState;
-import com.sun.tools.javac.processing.JavacProcessingEnvironment;
-import com.sun.tools.javac.util.Context;
-import com.sun.tools.javac.util.Log;
-
import com.sun.source.tree.ClassTree;
import com.sun.source.util.JavacTask;
import com.sun.source.util.TaskEvent;
import com.sun.source.util.TaskListener;
import com.sun.source.util.TreePath;
import com.sun.source.util.Trees;
+import com.sun.tools.javac.comp.CompileStates.CompileState;
+import com.sun.tools.javac.main.JavaCompiler;
+import com.sun.tools.javac.processing.JavacProcessingEnvironment;
+import com.sun.tools.javac.util.Context;
+import com.sun.tools.javac.util.Log;
+import java.util.HashSet;
+import java.util.Set;
+import javax.annotation.processing.AbstractProcessor;
+import javax.annotation.processing.ProcessingEnvironment;
+import javax.annotation.processing.Processor;
+import javax.annotation.processing.RoundEnvironment;
+import javax.lang.model.element.Name;
+import javax.lang.model.element.TypeElement;
+import javax.lang.model.util.ElementFilter;
/**
- * This class is an abstract annotation processor designed to be a
- * convenient superclass for concrete "type processors", processors that
- * require the type information in the processed source.
+ * This class is an abstract annotation processor designed to be a convenient superclass for
+ * concrete "type processors", processors that require the type information in the processed source.
*
- * <p>Type processing occurs in one round after the tool (e.g. Java compiler)
- * analyzes the source (all sources taken as input to the tool and sources
- * generated by other annotation processors).
+ * <p>Type processing occurs in one round after the tool (e.g. Java compiler) analyzes the source
+ * (all sources taken as input to the tool and sources generated by other annotation processors).
*
- * <p>The tool infrastructure will interact with classes extending this abstract
- * class as follows.
+ * <p>The tool infrastructure will interact with classes extending this abstract class as follows.
*
- * <p>
- * 1-3 are Identical to the {@link Processor} life cycle.
- * 4-5 are unique to {@code AbstractTypeProcessor} subclasses.
+ * <p>1-3 are identical to the {@link Processor} life cycle. 4-5 are unique to {@code
+ * AbstractTypeProcessor} subclasses.
*
* <ol>
- *
- * <li>If an existing {@code Processor} object is not being used, to
- * create an instance of a processor the tool calls the no-arg
- * constructor of the processor class.
- *
- * <li>Next, the tool calls the {@link #init init} method with
- * an appropriate {@code ProcessingEnvironment}.
- *
- * <li>Afterwards, the tool calls {@link #getSupportedAnnotationTypes
- * getSupportedAnnotationTypes}, {@link #getSupportedOptions
- * getSupportedOptions}, and {@link #getSupportedSourceVersion
- * getSupportedSourceVersion}. These methods are only called once per
- * run, not on each round.
- *
- *
- * <li>For each class containing a supported annotation, the tool calls
- * {@link #typeProcess(TypeElement, TreePath) typeProcess} method on the
- * {@code Processor}. The class is guaranteed to be type-checked Java code
- * and all the tree type and symbol information is resolved.
- *
- * <li>Finally, the tools calls the
- * {@link #typeProcessingOver() typeProcessingOver} method
- * on the {@code Processor}.
- *
+ * <li>If an existing {@code Processor} object is not being used, to create an instance of a
+ * processor the tool calls the no-arg constructor of the processor class.
+ * <li>Next, the tool calls the {@link #init init} method with an appropriate {@code
+ * ProcessingEnvironment}.
+ * <li>Afterwards, the tool calls {@link #getSupportedAnnotationTypes
+ * getSupportedAnnotationTypes}, {@link #getSupportedOptions getSupportedOptions}, and {@link
+ * #getSupportedSourceVersion getSupportedSourceVersion}. These methods are only called once
+ * per run, not on each round.
+ * <li>For each class containing a supported annotation, the tool calls {@link
+ * #typeProcess(TypeElement, TreePath) typeProcess} method on the {@code Processor}. The class
+ * is guaranteed to be type-checked Java code and all the tree type and symbol information is
+ * resolved.
+ * <li>Finally, the tools calls the {@link #typeProcessingOver() typeProcessingOver} method on the
+ * {@code Processor}.
* </ol>
*
- * <p>The tool is permitted to ask type processors to process a class once
- * it is analyzed before the rest of classes are analyzed. The tool is also
- * permitted to stop type processing immediately if any errors are raised,
- * without invoking {@code typeProcessingOver}
+ * <p>The tool is permitted to ask type processors to process a class once it is analyzed before the
+ * rest of classes are analyzed. The tool is also permitted to stop type processing immediately if
+ * any errors are raised, without invoking {@code typeProcessingOver}
*
- * <p>A subclass may override any of the methods in this class, as long as the
- * general {@link javax.annotation.processing.Processor Processor}
- * contract is obeyed, with one notable exception.
- * {@link #process(Set, RoundEnvironment)} may not be overridden, as it
- * is called during the declaration annotation phase before classes are analyzed.
+ * <p>A subclass may override any of the methods in this class, as long as the general {@link
+ * javax.annotation.processing.Processor Processor} contract is obeyed, with one notable exception.
+ * {@link #process(Set, RoundEnvironment)} may not be overridden, as it is called during the
+ * declaration annotation phase before classes are analyzed.
*
* @author Mahmood Ali
* @author Werner Dietl
*/
public abstract class AbstractTypeProcessor extends AbstractProcessor {
/**
- * The set of fully-qualified element names that should be type-checked.
- * We store the names of the elements, in order to prevent
- * possible confusion between different Element instantiations.
+ * The set of fully-qualified element names that should be type-checked. We store the names of
+ * the elements, in order to prevent possible confusion between different Element
+ * instantiations.
*/
private final Set<Name> elements = new HashSet<Name>();
/**
- * Method {@link #typeProcessingStart()} must be invoked exactly once,
- * before any invocation of {@link #typeProcess(TypeElement, TreePath)}.
+ * Method {@link #typeProcessingStart()} must be invoked exactly once, before any invocation of
+ * {@link #typeProcess(TypeElement, TreePath)}.
*/
private boolean hasInvokedTypeProcessingStart = false;
/**
- * Method {@link #typeProcessingOver()} must be invoked exactly once,
- * after the last invocation of {@link #typeProcess(TypeElement, TreePath)}.
+ * Method {@link #typeProcessingOver()} must be invoked exactly once, after the last invocation
+ * of {@link #typeProcess(TypeElement, TreePath)}.
*/
private static boolean hasInvokedTypeProcessingOver = false;
- /**
- * The TaskListener registered for completion of attribution.
- */
+ /** The TaskListener registered for completion of attribution. */
private final AttributionTaskListener listener = new AttributionTaskListener();
- /**
- * Constructor for subclasses to call.
- */
- protected AbstractTypeProcessor() { }
+ /** Constructor for subclasses to call. */
+ protected AbstractTypeProcessor() {}
/**
* {@inheritDoc}
*
- * Register a TaskListener that will get called after FLOW.
+ * <p>Register a TaskListener that will get called after FLOW.
*/
@Override
- public void init(ProcessingEnvironment env) {
+ public synchronized void init(ProcessingEnvironment env) {
super.init(env);
JavacTask.instance(env).addTaskListener(listener);
Context ctx = ((JavacProcessingEnvironment) processingEnv).getContext();
JavaCompiler compiler = JavaCompiler.instance(ctx);
- compiler.shouldStopPolicyIfNoError = CompileState.max(compiler.shouldStopPolicyIfNoError,
- CompileState.FLOW);
+ compiler.shouldStopPolicyIfNoError =
+ CompileState.max(compiler.shouldStopPolicyIfNoError, CompileState.FLOW);
+ compiler.shouldStopPolicyIfError =
+ CompileState.max(compiler.shouldStopPolicyIfError, CompileState.FLOW);
}
/**
- * The use of this method is obsolete in type processors. The method is
- * called during declaration annotation processing phase only.
- * It registers the names of elements to process.
+ * The use of this method is obsolete in type processors. The method is called during
+ * declaration annotation processing phase only. It registers the names of elements to process.
*/
@Override
- public final boolean process(Set<? extends TypeElement> annotations,
- RoundEnvironment roundEnv) {
+ public final boolean process(
+ Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
for (TypeElement elem : ElementFilter.typesIn(roundEnv.getRootElements())) {
elements.add(elem.getQualifiedName());
}
@@ -145,39 +126,35 @@ public abstract class AbstractTypeProcessor extends AbstractProcessor {
public void typeProcessingStart() {}
/**
- * Processes a fully analyzed class that contains a supported annotation
- * (look {@link #getSupportedAnnotationTypes()}).
+ * Processes a fully-analyzed class that contains a supported annotation (see {@link
+ * #getSupportedAnnotationTypes()}).
*
* <p>The passed class is always valid type-checked Java code.
*
- * @param element element of the analyzed class
- * @param tree the tree path to the element, with the leaf being a
- * {@link ClassTree}
+ * @param element element of the analyzed class
+ * @param tree the tree path to the element, with the leaf being a {@link ClassTree}
*/
public abstract void typeProcess(TypeElement element, TreePath tree);
/**
- * A method to be called once all the classes are processed and no error
- * is reported.
+ * A method to be called once all the classes are processed and no error is reported.
*
- * <p>Subclasses may override this method to do any aggregate analysis
- * (e.g. generate report, persistence) or resource deallocation.
+ * <p>Subclasses may override this method to do any aggregate analysis (e.g. generate report,
+ * persistence) or resource deallocation.
*
- * <p>If an error (a Java error or a processor error) is reported, this
- * method is not guaranteed to be invoked.
+ * <p>If an error (a Java error or a processor error) is reported, this method is not guaranteed
+ * to be invoked.
*/
- public void typeProcessingOver() { }
+ public void typeProcessingOver() {}
- /**
- * A task listener that invokes the processor whenever a class is fully
- * analyzed.
- */
+ /** A task listener that invokes the processor whenever a class is fully analyzed. */
private final class AttributionTaskListener implements TaskListener {
@Override
public void finished(TaskEvent e) {
- if (e.getKind() != TaskEvent.Kind.ANALYZE)
+ if (e.getKind() != TaskEvent.Kind.ANALYZE) {
return;
+ }
if (!hasInvokedTypeProcessingStart) {
typeProcessingStart();
@@ -191,13 +168,16 @@ public abstract class AbstractTypeProcessor extends AbstractProcessor {
hasInvokedTypeProcessingOver = true;
}
- if (e.getTypeElement() == null)
+ if (e.getTypeElement() == null) {
throw new AssertionError("event task without a type element");
- if (e.getCompilationUnit() == null)
+ }
+ if (e.getCompilationUnit() == null) {
throw new AssertionError("event task without compilation unit");
+ }
- if (!elements.remove(e.getTypeElement().getQualifiedName()))
+ if (!elements.remove(e.getTypeElement().getQualifiedName())) {
return;
+ }
TypeElement elem = e.getTypeElement();
TreePath p = Trees.instance(processingEnv).getPath(elem);
@@ -211,6 +191,6 @@ public abstract class AbstractTypeProcessor extends AbstractProcessor {
}
@Override
- public void started(TaskEvent e) { }
+ public void started(TaskEvent e) {}
}
}