Minor: Fix inspection warnings in 'kotlin-annotation-processing-base'
This commit is contained in:
@@ -73,6 +73,7 @@ open class KaptContext(
|
|||||||
put(Option.PROC, "only") // Only process annotations
|
put(Option.PROC, "only") // Only process annotations
|
||||||
|
|
||||||
if (!withJdk) {
|
if (!withJdk) {
|
||||||
|
@Suppress("SpellCheckingInspection")
|
||||||
putJavacOption("BOOTCLASSPATH", "BOOT_CLASS_PATH", "") // No boot classpath
|
putJavacOption("BOOTCLASSPATH", "BOOT_CLASS_PATH", "") // No boot classpath
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,6 +83,8 @@ open class KaptContext(
|
|||||||
|
|
||||||
putJavacOption("CLASSPATH", "CLASS_PATH",
|
putJavacOption("CLASSPATH", "CLASS_PATH",
|
||||||
paths.compileClasspath.joinToString(File.pathSeparator) { it.canonicalPath })
|
paths.compileClasspath.joinToString(File.pathSeparator) { it.canonicalPath })
|
||||||
|
|
||||||
|
@Suppress("SpellCheckingInspection")
|
||||||
putJavacOption("PROCESSORPATH", "PROCESSOR_PATH",
|
putJavacOption("PROCESSORPATH", "PROCESSOR_PATH",
|
||||||
paths.annotationProcessingClasspath.joinToString(File.pathSeparator) { it.canonicalPath })
|
paths.annotationProcessingClasspath.joinToString(File.pathSeparator) { it.canonicalPath })
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,6 @@ class ProcessorLoader(
|
|||||||
return processors
|
return processors
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun tryLoadProcessor(fqName: String, classLoader: ClassLoader): Processor? {
|
private fun tryLoadProcessor(fqName: String, classLoader: ClassLoader): Processor? {
|
||||||
val annotationProcessorClass = try {
|
val annotationProcessorClass = try {
|
||||||
Class.forName(fqName, true, classLoader)
|
Class.forName(fqName, true, classLoader)
|
||||||
@@ -92,5 +91,6 @@ private fun clearJarURLCache() {
|
|||||||
|
|
||||||
clearMap(jarFileFactory.getDeclaredField("fileCache"))
|
clearMap(jarFileFactory.getDeclaredField("fileCache"))
|
||||||
clearMap(jarFileFactory.getDeclaredField("urlCache"))
|
clearMap(jarFileFactory.getDeclaredField("urlCache"))
|
||||||
} catch (ignore: Exception) {}
|
} catch (ignore: Exception) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+19
-14
@@ -25,9 +25,9 @@ import kotlin.system.measureTimeMillis
|
|||||||
import com.sun.tools.javac.util.List as JavacList
|
import com.sun.tools.javac.util.List as JavacList
|
||||||
|
|
||||||
fun KaptContext.doAnnotationProcessing(
|
fun KaptContext.doAnnotationProcessing(
|
||||||
javaSourceFiles: List<File>,
|
javaSourceFiles: List<File>,
|
||||||
processors: List<Processor>,
|
processors: List<Processor>,
|
||||||
additionalSources: JavacList<JCTree.JCCompilationUnit> = JavacList.nil()
|
additionalSources: JavacList<JCTree.JCCompilationUnit> = JavacList.nil()
|
||||||
) {
|
) {
|
||||||
val processingEnvironment = JavacProcessingEnvironment.instance(context)
|
val processingEnvironment = JavacProcessingEnvironment.instance(context)
|
||||||
val wrappedProcessors = processors.map { ProcessorWrapper(it) }
|
val wrappedProcessors = processors.map { ProcessorWrapper(it) }
|
||||||
@@ -37,8 +37,7 @@ fun KaptContext.doAnnotationProcessing(
|
|||||||
if (isJava9OrLater()) {
|
if (isJava9OrLater()) {
|
||||||
val initProcessAnnotationsMethod = JavaCompiler::class.java.declaredMethods.single { it.name == "initProcessAnnotations" }
|
val initProcessAnnotationsMethod = JavaCompiler::class.java.declaredMethods.single { it.name == "initProcessAnnotations" }
|
||||||
initProcessAnnotationsMethod.invoke(compiler, wrappedProcessors, emptyList<JavaFileObject>(), emptyList<String>())
|
initProcessAnnotationsMethod.invoke(compiler, wrappedProcessors, emptyList<JavaFileObject>(), emptyList<String>())
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
compiler.initProcessAnnotations(wrappedProcessors)
|
compiler.initProcessAnnotations(wrappedProcessors)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,14 +46,14 @@ fun KaptContext.doAnnotationProcessing(
|
|||||||
compilerAfterAP = try {
|
compilerAfterAP = try {
|
||||||
javaLog.interceptorData.files = parsedJavaFiles.map { it.sourceFile to it }.toMap()
|
javaLog.interceptorData.files = parsedJavaFiles.map { it.sourceFile to it }.toMap()
|
||||||
val analyzedFiles = compiler.stopIfErrorOccurred(
|
val analyzedFiles = compiler.stopIfErrorOccurred(
|
||||||
CompileState.PARSE, compiler.enterTrees(parsedJavaFiles + additionalSources))
|
CompileState.PARSE, compiler.enterTrees(parsedJavaFiles + additionalSources)
|
||||||
|
)
|
||||||
|
|
||||||
if (isJava9OrLater()) {
|
if (isJava9OrLater()) {
|
||||||
val processAnnotationsMethod = compiler.javaClass.getMethod("processAnnotations", JavacList::class.java)
|
val processAnnotationsMethod = compiler.javaClass.getMethod("processAnnotations", JavacList::class.java)
|
||||||
processAnnotationsMethod.invoke(compiler, analyzedFiles)
|
processAnnotationsMethod.invoke(compiler, analyzedFiles)
|
||||||
compiler
|
compiler
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
compiler.processAnnotations(analyzedFiles)
|
compiler.processAnnotations(analyzedFiles)
|
||||||
}
|
}
|
||||||
} catch (e: AnnotationProcessingError) {
|
} catch (e: AnnotationProcessingError) {
|
||||||
@@ -138,10 +137,15 @@ private class ProcessorWrapper(private val delegate: Processor) : Processor by d
|
|||||||
fun KaptContext.parseJavaFiles(javaSourceFiles: List<File>): JavacList<JCTree.JCCompilationUnit> {
|
fun KaptContext.parseJavaFiles(javaSourceFiles: List<File>): JavacList<JCTree.JCCompilationUnit> {
|
||||||
val javaFileObjects = fileManager.getJavaFileObjectsFromFiles(javaSourceFiles)
|
val javaFileObjects = fileManager.getJavaFileObjectsFromFiles(javaSourceFiles)
|
||||||
|
|
||||||
return compiler.stopIfErrorOccurred(CompileState.PARSE,
|
return compiler.stopIfErrorOccurred(
|
||||||
initModulesIfNeeded(
|
CompileState.PARSE,
|
||||||
compiler.stopIfErrorOccurred(CompileState.PARSE,
|
initModulesIfNeeded(
|
||||||
compiler.parseFiles(javaFileObjects))))
|
compiler.stopIfErrorOccurred(
|
||||||
|
CompileState.PARSE,
|
||||||
|
compiler.parseFiles(javaFileObjects)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun KaptContext.initModulesIfNeeded(files: JavacList<JCTree.JCCompilationUnit>): JavacList<JCTree.JCCompilationUnit> {
|
private fun KaptContext.initModulesIfNeeded(files: JavacList<JCTree.JCCompilationUnit>): JavacList<JCTree.JCCompilationUnit> {
|
||||||
@@ -150,8 +154,9 @@ private fun KaptContext.initModulesIfNeeded(files: JavacList<JCTree.JCCompilatio
|
|||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
return compiler.stopIfErrorOccurred(
|
return compiler.stopIfErrorOccurred(
|
||||||
CompileState.PARSE,
|
CompileState.PARSE,
|
||||||
initModulesMethod.invoke(compiler, files) as JavacList<JCTree.JCCompilationUnit>)
|
initModulesMethod.invoke(compiler, files) as JavacList<JCTree.JCCompilationUnit>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return files
|
return files
|
||||||
|
|||||||
@@ -126,15 +126,13 @@ class KaptJavaLog(
|
|||||||
if (nerrors > oldErrors) {
|
if (nerrors > oldErrors) {
|
||||||
_reportedDiagnostics += diagnostic
|
_reportedDiagnostics += diagnostic
|
||||||
}
|
}
|
||||||
}
|
} else if (diagnostic.kind == Diagnostic.Kind.WARNING) {
|
||||||
else if (diagnostic.kind == Diagnostic.Kind.WARNING) {
|
|
||||||
val oldWarnings = nwarnings
|
val oldWarnings = nwarnings
|
||||||
super.report(diagnostic)
|
super.report(diagnostic)
|
||||||
if (nwarnings > oldWarnings) {
|
if (nwarnings > oldWarnings) {
|
||||||
_reportedDiagnostics += diagnostic
|
_reportedDiagnostics += diagnostic
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
super.report(diagnostic)
|
super.report(diagnostic)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -153,14 +151,14 @@ class KaptJavaLog(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val formattedMessage = diagnosticFormatter.format(diagnostic, javacMessages.currentLocale)
|
val formattedMessage = diagnosticFormatter.format(diagnostic, javacMessages.currentLocale)
|
||||||
.lines()
|
.lines()
|
||||||
.joinToString(LINE_SEPARATOR) { original ->
|
.joinToString(LINE_SEPARATOR) { original ->
|
||||||
// Kotlin location is put as a sub-diagnostic, so the formatter indents it with four additional spaces (6 in total).
|
// Kotlin location is put as a sub-diagnostic, so the formatter indents it with four additional spaces (6 in total).
|
||||||
// It looks weird, especially in the build log inside IntelliJ, so let's make things a bit better.
|
// It looks weird, especially in the build log inside IntelliJ, so let's make things a bit better.
|
||||||
val trimmed = original.trimStart()
|
val trimmed = original.trimStart()
|
||||||
// Typically, javac places additional details about the diagnostics indented by two spaces
|
// Typically, javac places additional details about the diagnostics indented by two spaces
|
||||||
if (trimmed.startsWith(KOTLIN_LOCATION_PREFIX)) " " + trimmed else original
|
if (trimmed.startsWith(KOTLIN_LOCATION_PREFIX)) " " + trimmed else original
|
||||||
}
|
}
|
||||||
|
|
||||||
writer.print(formattedMessage)
|
writer.print(formattedMessage)
|
||||||
writer.flush()
|
writer.flush()
|
||||||
@@ -170,8 +168,7 @@ class KaptJavaLog(
|
|||||||
return if (pos.isRelativePath) {
|
return if (pos.isRelativePath) {
|
||||||
val basePath = this.projectBaseDir
|
val basePath = this.projectBaseDir
|
||||||
if (basePath != null) File(basePath, pos.path) else null
|
if (basePath != null) File(basePath, pos.path) else null
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
File(pos.path)
|
File(pos.path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -237,23 +234,23 @@ fun KaptContext.reportKaptError(vararg line: String) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun JCDiagnostic.Factory.errorJava9Aware(
|
private fun JCDiagnostic.Factory.errorJava9Aware(
|
||||||
source: DiagnosticSource?,
|
source: DiagnosticSource?,
|
||||||
pos: JCDiagnostic.DiagnosticPosition?,
|
pos: JCDiagnostic.DiagnosticPosition?,
|
||||||
key: String,
|
key: String,
|
||||||
vararg args: String
|
vararg args: String
|
||||||
): JCDiagnostic {
|
): JCDiagnostic {
|
||||||
return if (isJava9OrLater()) {
|
return if (isJava9OrLater()) {
|
||||||
val errorMethod = this::class.java.getDeclaredMethod(
|
val errorMethod = this::class.java.getDeclaredMethod(
|
||||||
"error",
|
"error",
|
||||||
JCDiagnostic.DiagnosticFlag::class.java,
|
JCDiagnostic.DiagnosticFlag::class.java,
|
||||||
DiagnosticSource::class.java,
|
DiagnosticSource::class.java,
|
||||||
JCDiagnostic.DiagnosticPosition::class.java,
|
JCDiagnostic.DiagnosticPosition::class.java,
|
||||||
String::class.java,
|
String::class.java,
|
||||||
Array<Any>::class.java)
|
Array<Any>::class.java
|
||||||
|
)
|
||||||
|
|
||||||
errorMethod.invoke(this, JCDiagnostic.DiagnosticFlag.MANDATORY, source, pos, key, args) as JCDiagnostic
|
errorMethod.invoke(this, JCDiagnostic.DiagnosticFlag.MANDATORY, source, pos, key, args) as JCDiagnostic
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
this.error(source, pos, key, *args)
|
this.error(source, pos, key, *args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,5 +21,5 @@ class FileInfo(private val lineInfo: LineInfoMap, private val signatureInfo: Map
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun getPositionFor(fqName: String) = lineInfo[fqName]
|
fun getPositionFor(fqName: String) = lineInfo[fqName]
|
||||||
fun getMethodDescriptor(decl: JCTree.JCMethodDecl) = signatureInfo[decl.getJavacSignature()]
|
fun getMethodDescriptor(declaration: JCTree.JCMethodDecl) = signatureInfo[declaration.getJavacSignature()]
|
||||||
}
|
}
|
||||||
@@ -35,7 +35,9 @@ fun Options.putJavacOption(jdk8Name: String, jdk9Name: String, value: String) {
|
|||||||
put(option, value)
|
put(option, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("FunctionName")
|
||||||
fun TreeMaker.TopLevelJava9Aware(packageClause: JCTree.JCExpression?, declarations: JavacList<JCTree>): JCTree.JCCompilationUnit {
|
fun TreeMaker.TopLevelJava9Aware(packageClause: JCTree.JCExpression?, declarations: JavacList<JCTree>): JCTree.JCCompilationUnit {
|
||||||
|
@Suppress("SpellCheckingInspection")
|
||||||
return if (isJava9OrLater()) {
|
return if (isJava9OrLater()) {
|
||||||
val topLevelMethod = TreeMaker::class.java.declaredMethods.single { it.name == "TopLevel" }
|
val topLevelMethod = TreeMaker::class.java.declaredMethods.single { it.name == "TopLevel" }
|
||||||
val packageDecl: JCTree? = packageClause?.let {
|
val packageDecl: JCTree? = packageClause?.let {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.kapt3.base.util
|
package org.jetbrains.kotlin.kapt3.base.util
|
||||||
|
|
||||||
inline fun <T> measureTimeMillisWithResult(block: () -> T) : Pair<Long, T> {
|
inline fun <T> measureTimeMillisWithResult(block: () -> T): Pair<Long, T> {
|
||||||
val start = System.currentTimeMillis()
|
val start = System.currentTimeMillis()
|
||||||
val result = block()
|
val result = block()
|
||||||
return Pair(System.currentTimeMillis() - start, result)
|
return Pair(System.currentTimeMillis() - start, result)
|
||||||
|
|||||||
Reference in New Issue
Block a user