< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/javac/api/BasicJavacTask.java

Print this page
rev 3028 : JDK-8058150


  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.tools.javac.api;
  27 
  28 import java.util.Collection;
  29 import java.util.LinkedHashSet;
  30 import java.util.Locale;
  31 import java.util.Set;

  32 
  33 import javax.annotation.processing.Processor;
  34 import javax.lang.model.element.Element;
  35 import javax.lang.model.type.TypeMirror;
  36 import javax.lang.model.util.Elements;
  37 import javax.lang.model.util.Types;
  38 import javax.tools.JavaFileObject;
  39 
  40 import com.sun.source.tree.CompilationUnitTree;
  41 import com.sun.source.tree.Tree;
  42 import com.sun.source.util.JavacTask;
  43 import com.sun.source.util.Plugin;
  44 import com.sun.source.util.TaskListener;
  45 import com.sun.tools.doclint.DocLint;
  46 import com.sun.tools.javac.main.JavaCompiler;
  47 import com.sun.tools.javac.model.JavacElements;
  48 import com.sun.tools.javac.model.JavacTypes;


  49 import com.sun.tools.javac.processing.JavacProcessingEnvironment;
  50 import com.sun.tools.javac.tree.JCTree;
  51 import com.sun.tools.javac.util.Context;
  52 import com.sun.tools.javac.util.DefinedBy;
  53 import com.sun.tools.javac.util.DefinedBy.Api;
  54 import com.sun.tools.javac.util.List;
  55 import com.sun.tools.javac.util.Log;
  56 import com.sun.tools.javac.util.PropagatedException;
  57 import com.sun.tools.javac.util.ServiceLoader;
  58 
  59 /**
  60  * Provides basic functionality for implementations of JavacTask.
  61  *
  62  * <p><b>This is NOT part of any supported API.
  63  * If you write code that depends on this, you do so at your own
  64  * risk.  This code and its internal interfaces are subject to change
  65  * or deletion without notice.</b></p>
  66  */
  67 public class BasicJavacTask extends JavacTask {
  68     protected Context context;


 154     @Override @DefinedBy(Api.COMPILER)
 155     public void setLocale(Locale locale) {
 156         throw new IllegalStateException();
 157     }
 158 
 159     @Override @DefinedBy(Api.COMPILER)
 160     public Boolean call() {
 161         throw new IllegalStateException();
 162     }
 163 
 164     /**
 165      * For internal use only.
 166      * This method will be removed without warning.
 167      * @return the context
 168      */
 169     public Context getContext() {
 170         return context;
 171     }
 172 
 173     public void initPlugins(Set<List<String>> pluginOpts) {
















 174         if (pluginOpts.isEmpty())
 175             return;
 176 
 177         Set<List<String>> pluginsToCall = new LinkedHashSet<>(pluginOpts);
 178         JavacProcessingEnvironment pEnv = JavacProcessingEnvironment.instance(context);
 179         ClassLoader cl = pEnv.getProcessorClassLoader();
 180         ServiceLoader<Plugin> sl = ServiceLoader.load(Plugin.class, cl);
 181         for (Plugin plugin : sl) {
 182             for (List<String> p : pluginsToCall) {
 183                 if (plugin.getName().equals(p.head)) {
 184                     pluginsToCall.remove(p);
 185                     try {
 186                         plugin.init(this, p.tail.toArray(new String[p.tail.size()]));
 187                     } catch (RuntimeException ex) {
 188                         throw new PropagatedException(ex);
 189                     }
 190                 }
 191             }
 192         }
 193         for (List<String> p: pluginsToCall) {


  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.tools.javac.api;
  27 
  28 import java.util.Collection;
  29 import java.util.LinkedHashSet;
  30 import java.util.Locale;
  31 import java.util.Set;
  32 import java.util.stream.Collectors;
  33 
  34 import javax.annotation.processing.Processor;
  35 import javax.lang.model.element.Element;
  36 import javax.lang.model.type.TypeMirror;
  37 import javax.lang.model.util.Elements;
  38 import javax.lang.model.util.Types;
  39 import javax.tools.JavaFileObject;
  40 
  41 import com.sun.source.tree.CompilationUnitTree;
  42 import com.sun.source.tree.Tree;
  43 import com.sun.source.util.JavacTask;
  44 import com.sun.source.util.Plugin;
  45 import com.sun.source.util.TaskListener;
  46 import com.sun.tools.doclint.DocLint;
  47 import com.sun.tools.javac.main.JavaCompiler;
  48 import com.sun.tools.javac.model.JavacElements;
  49 import com.sun.tools.javac.model.JavacTypes;
  50 import com.sun.tools.javac.platform.PlatformDescription;
  51 import com.sun.tools.javac.platform.PlatformDescription.PluginInfo;
  52 import com.sun.tools.javac.processing.JavacProcessingEnvironment;
  53 import com.sun.tools.javac.tree.JCTree;
  54 import com.sun.tools.javac.util.Context;
  55 import com.sun.tools.javac.util.DefinedBy;
  56 import com.sun.tools.javac.util.DefinedBy.Api;
  57 import com.sun.tools.javac.util.List;
  58 import com.sun.tools.javac.util.Log;
  59 import com.sun.tools.javac.util.PropagatedException;
  60 import com.sun.tools.javac.util.ServiceLoader;
  61 
  62 /**
  63  * Provides basic functionality for implementations of JavacTask.
  64  *
  65  * <p><b>This is NOT part of any supported API.
  66  * If you write code that depends on this, you do so at your own
  67  * risk.  This code and its internal interfaces are subject to change
  68  * or deletion without notice.</b></p>
  69  */
  70 public class BasicJavacTask extends JavacTask {
  71     protected Context context;


 157     @Override @DefinedBy(Api.COMPILER)
 158     public void setLocale(Locale locale) {
 159         throw new IllegalStateException();
 160     }
 161 
 162     @Override @DefinedBy(Api.COMPILER)
 163     public Boolean call() {
 164         throw new IllegalStateException();
 165     }
 166 
 167     /**
 168      * For internal use only.
 169      * This method will be removed without warning.
 170      * @return the context
 171      */
 172     public Context getContext() {
 173         return context;
 174     }
 175 
 176     public void initPlugins(Set<List<String>> pluginOpts) {
 177         PlatformDescription platformProvider = context.get(PlatformDescription.class);
 178 
 179         if (platformProvider != null) {
 180             for (PluginInfo<Plugin> pluginDesc : platformProvider.getPlugins()) {
 181                 java.util.List<String> options =
 182                         pluginDesc.getOptions().entrySet().stream()
 183                                                           .map(e -> e.getKey() + "=" + e.getValue())
 184                                                           .collect(Collectors.toList());
 185                 try {
 186                     pluginDesc.getPlugin().init(this, options.toArray(new String[options.size()]));
 187                 } catch (RuntimeException ex) {
 188                     throw new PropagatedException(ex);
 189                 }
 190             }
 191         }
 192 
 193         if (pluginOpts.isEmpty())
 194             return;
 195 
 196         Set<List<String>> pluginsToCall = new LinkedHashSet<>(pluginOpts);
 197         JavacProcessingEnvironment pEnv = JavacProcessingEnvironment.instance(context);
 198         ClassLoader cl = pEnv.getProcessorClassLoader();
 199         ServiceLoader<Plugin> sl = ServiceLoader.load(Plugin.class, cl);
 200         for (Plugin plugin : sl) {
 201             for (List<String> p : pluginsToCall) {
 202                 if (plugin.getName().equals(p.head)) {
 203                     pluginsToCall.remove(p);
 204                     try {
 205                         plugin.init(this, p.tail.toArray(new String[p.tail.size()]));
 206                     } catch (RuntimeException ex) {
 207                         throw new PropagatedException(ex);
 208                     }
 209                 }
 210             }
 211         }
 212         for (List<String> p: pluginsToCall) {
< prev index next >