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
|
||||
|
||||
if (!withJdk) {
|
||||
@Suppress("SpellCheckingInspection")
|
||||
putJavacOption("BOOTCLASSPATH", "BOOT_CLASS_PATH", "") // No boot classpath
|
||||
}
|
||||
|
||||
@@ -82,6 +83,8 @@ open class KaptContext(
|
||||
|
||||
putJavacOption("CLASSPATH", "CLASS_PATH",
|
||||
paths.compileClasspath.joinToString(File.pathSeparator) { it.canonicalPath })
|
||||
|
||||
@Suppress("SpellCheckingInspection")
|
||||
putJavacOption("PROCESSORPATH", "PROCESSOR_PATH",
|
||||
paths.annotationProcessingClasspath.joinToString(File.pathSeparator) { it.canonicalPath })
|
||||
|
||||
|
||||
@@ -45,7 +45,6 @@ class ProcessorLoader(
|
||||
return processors
|
||||
}
|
||||
|
||||
|
||||
private fun tryLoadProcessor(fqName: String, classLoader: ClassLoader): Processor? {
|
||||
val annotationProcessorClass = try {
|
||||
Class.forName(fqName, true, classLoader)
|
||||
@@ -92,5 +91,6 @@ private fun clearJarURLCache() {
|
||||
|
||||
clearMap(jarFileFactory.getDeclaredField("fileCache"))
|
||||
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
|
||||
|
||||
fun KaptContext.doAnnotationProcessing(
|
||||
javaSourceFiles: List<File>,
|
||||
processors: List<Processor>,
|
||||
additionalSources: JavacList<JCTree.JCCompilationUnit> = JavacList.nil()
|
||||
javaSourceFiles: List<File>,
|
||||
processors: List<Processor>,
|
||||
additionalSources: JavacList<JCTree.JCCompilationUnit> = JavacList.nil()
|
||||
) {
|
||||
val processingEnvironment = JavacProcessingEnvironment.instance(context)
|
||||
val wrappedProcessors = processors.map { ProcessorWrapper(it) }
|
||||
@@ -37,8 +37,7 @@ fun KaptContext.doAnnotationProcessing(
|
||||
if (isJava9OrLater()) {
|
||||
val initProcessAnnotationsMethod = JavaCompiler::class.java.declaredMethods.single { it.name == "initProcessAnnotations" }
|
||||
initProcessAnnotationsMethod.invoke(compiler, wrappedProcessors, emptyList<JavaFileObject>(), emptyList<String>())
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
compiler.initProcessAnnotations(wrappedProcessors)
|
||||
}
|
||||
|
||||
@@ -47,14 +46,14 @@ fun KaptContext.doAnnotationProcessing(
|
||||
compilerAfterAP = try {
|
||||
javaLog.interceptorData.files = parsedJavaFiles.map { it.sourceFile to it }.toMap()
|
||||
val analyzedFiles = compiler.stopIfErrorOccurred(
|
||||
CompileState.PARSE, compiler.enterTrees(parsedJavaFiles + additionalSources))
|
||||
CompileState.PARSE, compiler.enterTrees(parsedJavaFiles + additionalSources)
|
||||
)
|
||||
|
||||
if (isJava9OrLater()) {
|
||||
val processAnnotationsMethod = compiler.javaClass.getMethod("processAnnotations", JavacList::class.java)
|
||||
processAnnotationsMethod.invoke(compiler, analyzedFiles)
|
||||
compiler
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
compiler.processAnnotations(analyzedFiles)
|
||||
}
|
||||
} 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> {
|
||||
val javaFileObjects = fileManager.getJavaFileObjectsFromFiles(javaSourceFiles)
|
||||
|
||||
return compiler.stopIfErrorOccurred(CompileState.PARSE,
|
||||
initModulesIfNeeded(
|
||||
compiler.stopIfErrorOccurred(CompileState.PARSE,
|
||||
compiler.parseFiles(javaFileObjects))))
|
||||
return compiler.stopIfErrorOccurred(
|
||||
CompileState.PARSE,
|
||||
initModulesIfNeeded(
|
||||
compiler.stopIfErrorOccurred(
|
||||
CompileState.PARSE,
|
||||
compiler.parseFiles(javaFileObjects)
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
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")
|
||||
return compiler.stopIfErrorOccurred(
|
||||
CompileState.PARSE,
|
||||
initModulesMethod.invoke(compiler, files) as JavacList<JCTree.JCCompilationUnit>)
|
||||
CompileState.PARSE,
|
||||
initModulesMethod.invoke(compiler, files) as JavacList<JCTree.JCCompilationUnit>
|
||||
)
|
||||
}
|
||||
|
||||
return files
|
||||
|
||||
@@ -126,15 +126,13 @@ class KaptJavaLog(
|
||||
if (nerrors > oldErrors) {
|
||||
_reportedDiagnostics += diagnostic
|
||||
}
|
||||
}
|
||||
else if (diagnostic.kind == Diagnostic.Kind.WARNING) {
|
||||
} else if (diagnostic.kind == Diagnostic.Kind.WARNING) {
|
||||
val oldWarnings = nwarnings
|
||||
super.report(diagnostic)
|
||||
if (nwarnings > oldWarnings) {
|
||||
_reportedDiagnostics += diagnostic
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
super.report(diagnostic)
|
||||
}
|
||||
}
|
||||
@@ -153,14 +151,14 @@ class KaptJavaLog(
|
||||
}
|
||||
|
||||
val formattedMessage = diagnosticFormatter.format(diagnostic, javacMessages.currentLocale)
|
||||
.lines()
|
||||
.joinToString(LINE_SEPARATOR) { original ->
|
||||
// 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.
|
||||
val trimmed = original.trimStart()
|
||||
// Typically, javac places additional details about the diagnostics indented by two spaces
|
||||
if (trimmed.startsWith(KOTLIN_LOCATION_PREFIX)) " " + trimmed else original
|
||||
}
|
||||
.lines()
|
||||
.joinToString(LINE_SEPARATOR) { original ->
|
||||
// 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.
|
||||
val trimmed = original.trimStart()
|
||||
// Typically, javac places additional details about the diagnostics indented by two spaces
|
||||
if (trimmed.startsWith(KOTLIN_LOCATION_PREFIX)) " " + trimmed else original
|
||||
}
|
||||
|
||||
writer.print(formattedMessage)
|
||||
writer.flush()
|
||||
@@ -170,8 +168,7 @@ class KaptJavaLog(
|
||||
return if (pos.isRelativePath) {
|
||||
val basePath = this.projectBaseDir
|
||||
if (basePath != null) File(basePath, pos.path) else null
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
File(pos.path)
|
||||
}
|
||||
}
|
||||
@@ -237,23 +234,23 @@ fun KaptContext.reportKaptError(vararg line: String) {
|
||||
}
|
||||
|
||||
private fun JCDiagnostic.Factory.errorJava9Aware(
|
||||
source: DiagnosticSource?,
|
||||
pos: JCDiagnostic.DiagnosticPosition?,
|
||||
key: String,
|
||||
vararg args: String
|
||||
source: DiagnosticSource?,
|
||||
pos: JCDiagnostic.DiagnosticPosition?,
|
||||
key: String,
|
||||
vararg args: String
|
||||
): JCDiagnostic {
|
||||
return if (isJava9OrLater()) {
|
||||
val errorMethod = this::class.java.getDeclaredMethod(
|
||||
"error",
|
||||
JCDiagnostic.DiagnosticFlag::class.java,
|
||||
DiagnosticSource::class.java,
|
||||
JCDiagnostic.DiagnosticPosition::class.java,
|
||||
String::class.java,
|
||||
Array<Any>::class.java)
|
||||
"error",
|
||||
JCDiagnostic.DiagnosticFlag::class.java,
|
||||
DiagnosticSource::class.java,
|
||||
JCDiagnostic.DiagnosticPosition::class.java,
|
||||
String::class.java,
|
||||
Array<Any>::class.java
|
||||
)
|
||||
|
||||
errorMethod.invoke(this, JCDiagnostic.DiagnosticFlag.MANDATORY, source, pos, key, args) as JCDiagnostic
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
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 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)
|
||||
}
|
||||
|
||||
@Suppress("FunctionName")
|
||||
fun TreeMaker.TopLevelJava9Aware(packageClause: JCTree.JCExpression?, declarations: JavacList<JCTree>): JCTree.JCCompilationUnit {
|
||||
@Suppress("SpellCheckingInspection")
|
||||
return if (isJava9OrLater()) {
|
||||
val topLevelMethod = TreeMaker::class.java.declaredMethods.single { it.name == "TopLevel" }
|
||||
val packageDecl: JCTree? = packageClause?.let {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
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 result = block()
|
||||
return Pair(System.currentTimeMillis() - start, result)
|
||||
|
||||
Reference in New Issue
Block a user