Do not try to remove source annotations from not .class file

This commit is contained in:
Alexey Tsvetkov
2016-09-09 18:53:48 +03:00
parent d2677c0500
commit 1bac872047
3 changed files with 8 additions and 3 deletions
@@ -8,6 +8,7 @@ class AnnotationsRemover(annotations: Iterable<String>) {
private val annotations = annotations.mapTo(HashSet()) { "L$it;" }
fun transformClassFile(inputFile: File, outputFile: File) {
assert(inputFile.extension.toLowerCase() == "class") { "Expected class file: $inputFile" }
val bytes = inputFile.readBytes()
val reader = ClassReader(bytes)
val classWriter = ClassWriter(0)
@@ -144,11 +144,12 @@ open class SyncOutputTask : DefaultTask() {
if (!fileInKotlinDir.isFile) return
fileInJavaDir.parentFile.mkdirs()
if (sourceAnnotations.isEmpty()) {
fileInKotlinDir.copyTo(fileInJavaDir, overwrite = true)
if (sourceAnnotations.isNotEmpty() && fileInKotlinDir.extension.toLowerCase() == "class") {
logger.kotlinDebug { "Removing source annotations from class: $fileInKotlinDir" }
annotationsRemover.transformClassFile(fileInKotlinDir, fileInJavaDir)
}
else {
annotationsRemover.transformClassFile(fileInKotlinDir, fileInJavaDir)
fileInKotlinDir.copyTo(fileInJavaDir, overwrite = true)
}
timestamps[fileInJavaDir] = fileInJavaDir.lastModified()
@@ -0,0 +1,3 @@
package foo
fun topLevelDummyFun() {}