|
21 | 21 | import java.util.Set; |
22 | 22 |
|
23 | 23 | import javax.annotation.processing.Messager; |
| 24 | +import javax.annotation.processing.ProcessingEnvironment; |
24 | 25 | import javax.annotation.processing.RoundEnvironment; |
25 | 26 | import javax.annotation.processing.SupportedSourceVersion; |
26 | 27 | import javax.lang.model.SourceVersion; |
|
145 | 146 | StringArrayRes.class }) |
146 | 147 | @SupportedSourceVersion(SourceVersion.RELEASE_6) |
147 | 148 | public class AndroidAnnotationProcessor extends AnnotatedAbstractProcessor { |
| 149 | + |
| 150 | + @Override |
| 151 | + public synchronized void init(ProcessingEnvironment processingEnv) { |
| 152 | + super.init(processingEnv); |
| 153 | + |
| 154 | + Messager messager = processingEnv.getMessager(); |
| 155 | + messager.printMessage(Diagnostic.Kind.NOTE, "Starting AndroidAnnotations compile time annotation processing"); |
| 156 | + } |
| 157 | + |
| 158 | + /** |
| 159 | + * We do not need multiple round processing, since the generated classes do |
| 160 | + * not need to be processed. |
| 161 | + */ |
| 162 | + private boolean alreadyProcessed = false; |
148 | 163 |
|
149 | 164 | @Override |
150 | 165 | public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { |
151 | | - Messager messager = processingEnv.getMessager(); |
152 | | - messager.printMessage(Diagnostic.Kind.NOTE, "AndroidAnnotations compile time annotation processing"); |
153 | 166 | try { |
154 | 167 | processThrowing(annotations, roundEnv); |
155 | 168 | } catch (Exception e) { |
156 | 169 | handleException(annotations, roundEnv, e); |
157 | 170 | } |
158 | | - return false; |
| 171 | + return true; |
159 | 172 | } |
160 | 173 |
|
161 | 174 | private void processThrowing(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) throws IOException { |
| 175 | + |
| 176 | + if (roundEnv.processingOver() || annotations.size() == 0 || alreadyProcessed) { |
| 177 | + return; |
| 178 | + } else { |
| 179 | + alreadyProcessed = true; |
| 180 | + } |
| 181 | + |
162 | 182 | AnnotationElementsHolder extractedModel = extractAnnotations(annotations, roundEnv); |
163 | 183 |
|
164 | 184 | AndroidManifest androidManifest = extractAndroidManifest(); |
165 | | - |
| 185 | + |
166 | 186 | IRClass rClass = findRClasses(androidManifest); |
167 | 187 |
|
168 | 188 | AndroidSystemServices androidSystemServices = new AndroidSystemServices(); |
|
0 commit comments