• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 The Dagger Authors.
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 dagger.android.processor;
18 
19 import static net.ltgt.gradle.incap.IncrementalAnnotationProcessorType.ISOLATING;
20 
21 import androidx.room.compiler.processing.XProcessingEnv;
22 import androidx.room.compiler.processing.XProcessingStep;
23 import androidx.room.compiler.processing.javac.JavacBasicAnnotationProcessor;
24 import com.google.auto.service.AutoService;
25 import com.google.common.collect.ImmutableSet;
26 import javax.annotation.processing.Processor;
27 import javax.lang.model.SourceVersion;
28 import net.ltgt.gradle.incap.IncrementalAnnotationProcessor;
29 
30 /**
31  * An {@linkplain javax.annotation.processing.Processor annotation processor} to verify usage of
32  * {@code dagger.android} code.
33  *
34  * <p>Additionally, if {@code -Adagger.android.experimentalUseStringKeys} is passed to the
35  * compilation, a file will be generated to support obfuscated injected Android types used with
36  * {@code @AndroidInjectionKey}. The fact that this is generated is deliberate: not all versions of
37  * ProGuard/R8 support {@code -identifiernamestring}, so we can't include a ProGuard file in the
38  * dagger-android artifact Instead, we generate the file in {@code META-INF/proguard} only when
39  * users enable the flag. They should only be enabling it if their shrinker supports those files,
40  * and any version that does so will also support {@code -identifiernamestring}. This was added to
41  * R8 in <a href="https://r8.googlesource.com/r8/+/389123dfcc11e6dda0eec31ab62e1b7eb0da80d2">May
42  * 2018</a>.
43  */
44 @IncrementalAnnotationProcessor(ISOLATING)
45 @AutoService(Processor.class)
46 public final class AndroidProcessor extends JavacBasicAnnotationProcessor {
47   private final DelegateAndroidProcessor delegate = new DelegateAndroidProcessor();
48 
49   @Override
initialize(XProcessingEnv env)50   public void initialize(XProcessingEnv env) {
51     delegate.initialize(env);
52   }
53 
54   @Override
processingSteps()55   public Iterable<XProcessingStep> processingSteps() {
56     return delegate.processingSteps();
57   }
58 
59   @Override
getSupportedOptions()60   public final ImmutableSet<String> getSupportedOptions() {
61     return ImmutableSet.of(DelegateAndroidProcessor.FLAG_EXPERIMENTAL_USE_STRING_KEYS);
62   }
63 
64   @Override
getSupportedSourceVersion()65   public SourceVersion getSupportedSourceVersion() {
66     return SourceVersion.latestSupported();
67   }
68 }
69