• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2019 Google Inc. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.google.turbine.processing;
18 
19 import java.util.Locale;
20 import java.util.Map;
21 import javax.annotation.processing.Filer;
22 import javax.annotation.processing.Messager;
23 import javax.annotation.processing.ProcessingEnvironment;
24 import javax.lang.model.SourceVersion;
25 import javax.lang.model.util.Elements;
26 import javax.lang.model.util.Types;
27 import org.checkerframework.checker.nullness.qual.Nullable;
28 
29 /** Turbine's {@link ProcessingEnvironment). */
30 public class TurbineProcessingEnvironment implements ProcessingEnvironment {
31 
32   private final Filer filer;
33   private final Types types;
34   private final Map<String, String> processorOptions;
35   private final Elements elements;
36   private final Map<String, byte[]> statistics;
37   private final SourceVersion sourceVersion;
38   private final Messager messager;
39   private final ClassLoader processorLoader;
40 
TurbineProcessingEnvironment( Filer filer, Types types, Elements elements, Messager messager, Map<String, String> processorOptions, SourceVersion sourceVersion, @Nullable ClassLoader processorLoader, Map<String, byte[]> statistics)41   public TurbineProcessingEnvironment(
42       Filer filer,
43       Types types,
44       Elements elements,
45       Messager messager,
46       Map<String, String> processorOptions,
47       SourceVersion sourceVersion,
48       @Nullable ClassLoader processorLoader,
49       Map<String, byte[]> statistics) {
50     this.filer = filer;
51     this.types = types;
52     this.processorOptions = processorOptions;
53     this.sourceVersion = sourceVersion;
54     this.elements = elements;
55     this.statistics = statistics;
56     this.messager = messager;
57     this.processorLoader = processorLoader;
58   }
59 
60   @Override
getOptions()61   public Map<String, String> getOptions() {
62     return processorOptions;
63   }
64 
65   @Override
getMessager()66   public Messager getMessager() {
67     return messager;
68   }
69 
70   @Override
getFiler()71   public Filer getFiler() {
72     return filer;
73   }
74 
75   @Override
getElementUtils()76   public Elements getElementUtils() {
77     return elements;
78   }
79 
80   @Override
getTypeUtils()81   public Types getTypeUtils() {
82     return types;
83   }
84 
85   @Override
getSourceVersion()86   public SourceVersion getSourceVersion() {
87     return sourceVersion;
88   }
89 
90   @Override
getLocale()91   public Locale getLocale() {
92     return Locale.ENGLISH;
93   }
94 
processorLoader()95   public ClassLoader processorLoader() {
96     return processorLoader;
97   }
98 
addStatistics(String key, byte[] extension)99   public void addStatistics(String key, byte[] extension) {
100     byte[] existing = statistics.put(key, extension);
101     if (existing != null) {
102       throw new IllegalStateException("duplicate statistics reported for " + key);
103     }
104   }
105 }
106