/* * Copyright (C) 2021 The Dagger Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package dagger.internal.codegen.javac; import com.google.common.collect.ImmutableMap; import java.util.Locale; import javax.annotation.processing.Filer; import javax.annotation.processing.Messager; import javax.annotation.processing.ProcessingEnvironment; import javax.lang.model.SourceVersion; import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.AnnotationValue; import javax.lang.model.element.Element; import javax.lang.model.util.Elements; // ALLOW_TYPES_ELEMENTS since in interface API import javax.lang.model.util.Types; // ALLOW_TYPES_ELEMENTS since in interface API import javax.tools.Diagnostic; import javax.tools.FileObject; import javax.tools.JavaFileManager.Location; import javax.tools.JavaFileObject; /** * An implementation of {@link ProcessingEnvironment} that runs in a javac plugin environment. * *
This environment runs after the classes are already compiled, so parts of the {@link
* ProcessingEnvironment} API like {@link Filer}, {@link Messager} don't make sense in this
* environment, so they've been replaced with throwing and no-op implementations respectively.
*/
final class JavacPluginProcessingEnvironment implements ProcessingEnvironment {
private final Elements elements;
private final Types types;
private final Filer filer = new ThrowingFiler();
private final Messager messager = new NoopMessager();
JavacPluginProcessingEnvironment(Elements elements, Types types) {
this.elements = elements;
this.types = types;
}
@Override
public Elements getElementUtils() {
return elements;
}
@Override
public Types getTypeUtils() {
return types;
}
@Override
public Filer getFiler() {
return filer;
}
@Override
public Locale getLocale() {
// Null means there's no locale in effect
return null;
}
@Override
public Messager getMessager() {
return messager;
}
@Override
public ImmutableMap