|
16 | 16 |
|
17 | 17 | package org.jetbrains.kotlin.kapt3
|
18 | 18 |
|
| 19 | +import com.sun.tools.javac.comp.CompileStates |
19 | 20 | import com.sun.tools.javac.file.JavacFileManager
|
| 21 | +import com.sun.tools.javac.main.JavaCompiler |
20 | 22 | import com.sun.tools.javac.main.Option
|
21 | 23 | import com.sun.tools.javac.processing.AnnotationProcessingError
|
22 | 24 | import com.sun.tools.javac.processing.JavacFiler
|
23 | 25 | import com.sun.tools.javac.processing.JavacProcessingEnvironment
|
24 | 26 | import com.sun.tools.javac.tree.JCTree
|
25 |
| -import com.sun.tools.javac.util.Log |
26 | 27 | import org.jetbrains.kotlin.kapt3.diagnostic.KaptError
|
27 | 28 | import java.io.File
|
28 | 29 | import javax.annotation.processing.Processor
|
@@ -56,28 +57,26 @@ fun KaptContext.doAnnotationProcessing(
|
56 | 57 | val fileManager = context.get(JavaFileManager::class.java) as JavacFileManager
|
57 | 58 | val processingEnvironment = JavacProcessingEnvironment.instance(context)
|
58 | 59 |
|
| 60 | + val compilerAfterAP: JavaCompiler |
59 | 61 | try {
|
60 | 62 | compiler.initProcessAnnotations(processors)
|
61 | 63 |
|
62 | 64 | val javaFileObjects = fileManager.getJavaFileObjectsFromFiles(javaSourceFiles)
|
63 | 65 | val parsedJavaFiles = compiler.parseFiles(javaFileObjects)
|
64 | 66 |
|
65 |
| - val log = Log.instance(context) |
66 |
| - |
67 |
| - val warningsBeforeAp: Int |
68 |
| - try { |
69 |
| - val analyzedFiles = compiler.enterTrees(parsedJavaFiles + additionalSources) |
70 |
| - |
71 |
| - warningsBeforeAp = log.nwarnings |
72 |
| - |
| 67 | + compilerAfterAP = try { |
| 68 | + val analyzedFiles = compiler.stopIfErrorOccurred( |
| 69 | + CompileStates.CompileState.PARSE, compiler.enterTrees(parsedJavaFiles + additionalSources)) |
73 | 70 | compiler.processAnnotations(analyzedFiles)
|
74 | 71 | } catch (e: AnnotationProcessingError) {
|
75 | 72 | throw KaptError(KaptError.Kind.EXCEPTION, e.cause ?: e)
|
76 | 73 | }
|
77 | 74 |
|
| 75 | + val log = compilerAfterAP.log |
| 76 | + |
78 | 77 | val filer = processingEnvironment.filer as JavacFiler
|
79 | 78 | val errorCount = log.nerrors
|
80 |
| - val warningCount = log.nwarnings - warningsBeforeAp |
| 79 | + val warningCount = log.nwarnings |
81 | 80 |
|
82 | 81 | logger.info { "Annotation processing complete, errors: $errorCount, warnings: $warningCount" }
|
83 | 82 | if (logger.isVerbose) {
|
|
0 commit comments