src/share/classes/com/sun/source/util/Trees.java

Print this page




  34 import javax.lang.model.element.ExecutableElement;
  35 import javax.lang.model.element.TypeElement;
  36 import javax.lang.model.type.DeclaredType;
  37 import javax.lang.model.type.ErrorType;
  38 import javax.lang.model.type.TypeMirror;
  39 import javax.tools.Diagnostic;
  40 import javax.tools.JavaCompiler.CompilationTask;
  41 
  42 import com.sun.source.tree.CatchTree;
  43 import com.sun.source.tree.ClassTree;
  44 import com.sun.source.tree.CompilationUnitTree;
  45 import com.sun.source.tree.MethodTree;
  46 import com.sun.source.tree.Scope;
  47 import com.sun.source.tree.Tree;
  48 
  49 /**
  50  * Bridges JSR 199, JSR 269, and the Tree API.
  51  *
  52  * @author Peter von der Ahé
  53  */
  54 @jdk.Supported
  55 public abstract class Trees {
  56     /**
  57      * Gets a Trees object for a given CompilationTask.
  58      * @param task the compilation task for which to get the Trees object
  59      * @throws IllegalArgumentException if the task does not support the Trees API.
  60      */
  61     public static Trees instance(CompilationTask task) {
  62         String taskClassName = task.getClass().getName();
  63         if (!taskClassName.equals("com.sun.tools.javac.api.JavacTaskImpl")
  64                 && !taskClassName.equals("com.sun.tools.javac.api.BasicJavacTask"))
  65             throw new IllegalArgumentException();
  66         return getJavacTrees(CompilationTask.class, task);
  67     }
  68 
  69     /**
  70      * Gets a Trees object for a given ProcessingEnvironment.
  71      * @param env the processing environment for which to get the Trees object
  72      * @throws IllegalArgumentException if the env does not support the Trees API.
  73      */
  74     public static Trees instance(ProcessingEnvironment env) {




  34 import javax.lang.model.element.ExecutableElement;
  35 import javax.lang.model.element.TypeElement;
  36 import javax.lang.model.type.DeclaredType;
  37 import javax.lang.model.type.ErrorType;
  38 import javax.lang.model.type.TypeMirror;
  39 import javax.tools.Diagnostic;
  40 import javax.tools.JavaCompiler.CompilationTask;
  41 
  42 import com.sun.source.tree.CatchTree;
  43 import com.sun.source.tree.ClassTree;
  44 import com.sun.source.tree.CompilationUnitTree;
  45 import com.sun.source.tree.MethodTree;
  46 import com.sun.source.tree.Scope;
  47 import com.sun.source.tree.Tree;
  48 
  49 /**
  50  * Bridges JSR 199, JSR 269, and the Tree API.
  51  *
  52  * @author Peter von der Ahé
  53  */
  54 @jdk.Exported
  55 public abstract class Trees {
  56     /**
  57      * Gets a Trees object for a given CompilationTask.
  58      * @param task the compilation task for which to get the Trees object
  59      * @throws IllegalArgumentException if the task does not support the Trees API.
  60      */
  61     public static Trees instance(CompilationTask task) {
  62         String taskClassName = task.getClass().getName();
  63         if (!taskClassName.equals("com.sun.tools.javac.api.JavacTaskImpl")
  64                 && !taskClassName.equals("com.sun.tools.javac.api.BasicJavacTask"))
  65             throw new IllegalArgumentException();
  66         return getJavacTrees(CompilationTask.class, task);
  67     }
  68 
  69     /**
  70      * Gets a Trees object for a given ProcessingEnvironment.
  71      * @param env the processing environment for which to get the Trees object
  72      * @throws IllegalArgumentException if the env does not support the Trees API.
  73      */
  74     public static Trees instance(ProcessingEnvironment env) {