Code cleanup in reflection.jvm, generator scripts

This commit is contained in:
Alexander Udalov
2015-11-06 16:22:21 +03:00
parent 75bb15a9fc
commit 596a74d288
17 changed files with 65 additions and 64 deletions
@@ -24,7 +24,7 @@ package kotlin.reflect
* *
* @see [kotlin.reflect.jvm.isAccessible] * @see [kotlin.reflect.jvm.isAccessible]
*/ */
public class IllegalCallableAccessException(cause: IllegalAccessException) : Exception(cause.getMessage()) { public class IllegalCallableAccessException(cause: IllegalAccessException) : Exception(cause.message) {
init { init {
@Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN") @Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN")
(this as java.lang.Throwable).initCause(cause) (this as java.lang.Throwable).initCause(cause)
@@ -27,5 +27,5 @@ import kotlin.reflect.jvm.internal.KClassImpl
*/ */
public val KClass<*>.jvmName: String public val KClass<*>.jvmName: String
get() { get() {
return (this as KClassImpl).jClass.getName() return (this as KClassImpl).jClass.name
} }
@@ -36,8 +36,8 @@ internal abstract class FunctionCaller<out M : Member>(
abstract fun call(args: Array<*>): Any? abstract fun call(args: Array<*>): Any?
protected open fun checkArguments(args: Array<*>) { protected open fun checkArguments(args: Array<*>) {
if (parameterTypes.size() != args.size()) { if (parameterTypes.size != args.size) {
throw IllegalArgumentException("Callable expects ${parameterTypes.size()} arguments, but ${args.size()} were provided.") throw IllegalArgumentException("Callable expects ${parameterTypes.size} arguments, but ${args.size} were provided.")
} }
} }
@@ -95,7 +95,7 @@ internal abstract class FunctionCaller<out M : Member>(
class InstanceMethod(method: ReflectMethod) : Method(method) { class InstanceMethod(method: ReflectMethod) : Method(method) {
override fun call(args: Array<*>): Any? { override fun call(args: Array<*>): Any? {
checkArguments(args) checkArguments(args)
return callMethod(args[0], args.asList().subList(1, args.size()).toTypedArray()) return callMethod(args[0], args.asList().subList(1, args.size).toTypedArray())
} }
} }
@@ -103,7 +103,7 @@ internal abstract class FunctionCaller<out M : Member>(
override fun call(args: Array<*>): Any? { override fun call(args: Array<*>): Any? {
checkArguments(args) checkArguments(args)
checkObjectInstance(args.firstOrNull()) checkObjectInstance(args.firstOrNull())
return callMethod(null, args.asList().subList(1, args.size()).toTypedArray()) return callMethod(null, args.asList().subList(1, args.size).toTypedArray())
} }
} }
@@ -68,7 +68,7 @@ internal interface KCallableImpl<out R> : KCallable<R>, KAnnotatedElementImpl {
// See ArgumentGenerator#generate // See ArgumentGenerator#generate
override fun callBy(args: Map<KParameter, Any?>): R { override fun callBy(args: Map<KParameter, Any?>): R {
val parameters = parameters val parameters = parameters
val arguments = ArrayList<Any?>(parameters.size()) val arguments = ArrayList<Any?>(parameters.size)
var mask = 0 var mask = 0
val masks = ArrayList<Int>(1) val masks = ArrayList<Int>(1)
var index = 0 var index = 0
@@ -42,7 +42,7 @@ internal class KClassImpl<T : Any>(override val jClass: Class<T>) : KDeclaration
val classId = classId val classId = classId
val descriptor = val descriptor =
if (classId.isLocal()) moduleData.localClassResolver.resolveLocalClass(classId) if (classId.isLocal) moduleData.localClassResolver.resolveLocalClass(classId)
else moduleData.module.findClassAcrossModuleDependencies(classId) else moduleData.module.findClassAcrossModuleDependencies(classId)
descriptor ?: throw KotlinReflectionInternalError("Class not resolved: $jClass") descriptor ?: throw KotlinReflectionInternalError("Class not resolved: $jClass")
@@ -67,8 +67,8 @@ internal class KClassImpl<T : Any>(override val jClass: Class<T>) : KDeclaration
override val constructorDescriptors: Collection<ConstructorDescriptor> override val constructorDescriptors: Collection<ConstructorDescriptor>
get() { get() {
val descriptor = descriptor val descriptor = descriptor
if (descriptor.getKind() == ClassKind.CLASS || descriptor.getKind() == ClassKind.ENUM_CLASS) { if (descriptor.kind == ClassKind.CLASS || descriptor.kind == ClassKind.ENUM_CLASS) {
return descriptor.getConstructors() return descriptor.constructors
} }
return emptyList() return emptyList()
} }
@@ -76,39 +76,39 @@ internal class KClassImpl<T : Any>(override val jClass: Class<T>) : KDeclaration
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
override fun getProperties(name: Name): Collection<PropertyDescriptor> = override fun getProperties(name: Name): Collection<PropertyDescriptor> =
(memberScope.getContributedVariables(name, NoLookupLocation.FROM_REFLECTION) + (memberScope.getContributedVariables(name, NoLookupLocation.FROM_REFLECTION) +
staticScope.getContributedVariables(name, NoLookupLocation.FROM_REFLECTION)) as Collection<PropertyDescriptor> staticScope.getContributedVariables(name, NoLookupLocation.FROM_REFLECTION))
override fun getFunctions(name: Name): Collection<FunctionDescriptor> = override fun getFunctions(name: Name): Collection<FunctionDescriptor> =
memberScope.getContributedFunctions(name, NoLookupLocation.FROM_REFLECTION) + memberScope.getContributedFunctions(name, NoLookupLocation.FROM_REFLECTION) +
staticScope.getContributedFunctions(name, NoLookupLocation.FROM_REFLECTION) staticScope.getContributedFunctions(name, NoLookupLocation.FROM_REFLECTION)
override val simpleName: String? get() { override val simpleName: String? get() {
if (jClass.isAnonymousClass()) return null if (jClass.isAnonymousClass) return null
val classId = classId val classId = classId
return when { return when {
classId.isLocal() -> calculateLocalClassName(jClass) classId.isLocal -> calculateLocalClassName(jClass)
else -> classId.getShortClassName().asString() else -> classId.shortClassName.asString()
} }
} }
private fun calculateLocalClassName(jClass: Class<*>): String { private fun calculateLocalClassName(jClass: Class<*>): String {
val name = jClass.getSimpleName() val name = jClass.simpleName
jClass.getEnclosingMethod()?.let { method -> jClass.enclosingMethod?.let { method ->
return name.substringAfter(method.getName() + "$") return name.substringAfter(method.name + "$")
} }
jClass.getEnclosingConstructor()?.let { constructor -> jClass.enclosingConstructor?.let { constructor ->
return name.substringAfter(constructor.getName() + "$") return name.substringAfter(constructor.name + "$")
} }
return name.substringAfter('$') return name.substringAfter('$')
} }
override val qualifiedName: String? get() { override val qualifiedName: String? get() {
if (jClass.isAnonymousClass()) return null if (jClass.isAnonymousClass) return null
val classId = classId val classId = classId
return when { return when {
classId.isLocal() -> null classId.isLocal -> null
else -> classId.asSingleFqName().asString() else -> classId.asSingleFqName().asString()
} }
} }
@@ -165,9 +165,9 @@ internal class KClassImpl<T : Any>(override val jClass: Class<T>) : KDeclaration
override fun toString(): String { override fun toString(): String {
return "class " + classId.let { classId -> return "class " + classId.let { classId ->
val packageFqName = classId.getPackageFqName() val packageFqName = classId.packageFqName
val packagePrefix = if (packageFqName.isRoot()) "" else packageFqName.asString() + "." val packagePrefix = if (packageFqName.isRoot) "" else packageFqName.asString() + "."
val classSuffix = classId.getRelativeClassName().asString().replace('.', '$') val classSuffix = classId.relativeClassName.asString().replace('.', '$')
packagePrefix + classSuffix packagePrefix + classSuffix
} }
} }
@@ -56,9 +56,9 @@ internal abstract class KDeclarationContainerImpl : ClassBasedDeclarationContain
fun getMembers(scope: MemberScope, declaredOnly: Boolean, nonExtensions: Boolean, extensions: Boolean): Sequence<KCallable<*>> { fun getMembers(scope: MemberScope, declaredOnly: Boolean, nonExtensions: Boolean, extensions: Boolean): Sequence<KCallable<*>> {
val visitor = object : DeclarationDescriptorVisitorEmptyBodies<KCallable<*>?, Unit>() { val visitor = object : DeclarationDescriptorVisitorEmptyBodies<KCallable<*>?, Unit>() {
private fun skipCallable(descriptor: CallableMemberDescriptor): Boolean { private fun skipCallable(descriptor: CallableMemberDescriptor): Boolean {
if (declaredOnly && !descriptor.getKind().isReal()) return true if (declaredOnly && !descriptor.kind.isReal) return true
val isExtension = descriptor.getExtensionReceiverParameter() != null val isExtension = descriptor.extensionReceiverParameter != null
if (isExtension && !extensions) return true if (isExtension && !extensions) return true
if (!isExtension && !nonExtensions) return true if (!isExtension && !nonExtensions) return true
@@ -80,7 +80,7 @@ internal abstract class KDeclarationContainerImpl : ClassBasedDeclarationContain
return scope.getContributedDescriptors().asSequence() return scope.getContributedDescriptors().asSequence()
.filter { descriptor -> .filter { descriptor ->
descriptor !is MemberDescriptor || descriptor.getVisibility() != Visibilities.INVISIBLE_FAKE descriptor !is MemberDescriptor || descriptor.visibility != Visibilities.INVISIBLE_FAKE
} }
.map { descriptor -> .map { descriptor ->
descriptor.accept(visitor, Unit) descriptor.accept(visitor, Unit)
@@ -115,11 +115,11 @@ internal abstract class KDeclarationContainerImpl : ClassBasedDeclarationContain
RuntimeTypeMapper.mapPropertySignature(descriptor).asString() == signature RuntimeTypeMapper.mapPropertySignature(descriptor).asString() == signature
} }
if (properties.size() != 1) { if (properties.size != 1) {
val debugText = "'$name' (JVM signature: $signature)" val debugText = "'$name' (JVM signature: $signature)"
throw KotlinReflectionInternalError( throw KotlinReflectionInternalError(
if (properties.isEmpty()) "Property $debugText not resolved in $this" if (properties.isEmpty()) "Property $debugText not resolved in $this"
else "${properties.size()} properties $debugText resolved in $this: $properties" else "${properties.size} properties $debugText resolved in $this: $properties"
) )
} }
@@ -132,11 +132,11 @@ internal abstract class KDeclarationContainerImpl : ClassBasedDeclarationContain
RuntimeTypeMapper.mapSignature(descriptor).asString() == signature RuntimeTypeMapper.mapSignature(descriptor).asString() == signature
} }
if (functions.size() != 1) { if (functions.size != 1) {
val debugText = "'$name' (JVM signature: $signature)" val debugText = "'$name' (JVM signature: $signature)"
throw KotlinReflectionInternalError( throw KotlinReflectionInternalError(
if (functions.isEmpty()) "Function $debugText not resolved in $this" if (functions.isEmpty()) "Function $debugText not resolved in $this"
else "${functions.size()} functions $debugText resolved in $this: $functions" else "${functions.size} functions $debugText resolved in $this: $functions"
) )
} }
@@ -197,7 +197,7 @@ internal abstract class KDeclarationContainerImpl : ClassBasedDeclarationContain
private fun addParametersAndMasks(result: MutableList<Class<*>>, desc: String) { private fun addParametersAndMasks(result: MutableList<Class<*>>, desc: String) {
val valueParameters = loadParameterTypes(desc) val valueParameters = loadParameterTypes(desc)
result.addAll(valueParameters) result.addAll(valueParameters)
repeat((valueParameters.size() + Integer.SIZE - 1) / Integer.SIZE) { repeat((valueParameters.size + Integer.SIZE - 1) / Integer.SIZE) {
result.add(Integer.TYPE) result.add(Integer.TYPE)
} }
} }
@@ -251,7 +251,7 @@ internal abstract class KDeclarationContainerImpl : ClassBasedDeclarationContain
): Field? { ): Field? {
val owner = implClassForCallable(nameResolver, proto) ?: val owner = implClassForCallable(nameResolver, proto) ?:
if (proto.hasExtension(JvmProtoBuf.propertySignature) && if (proto.hasExtension(JvmProtoBuf.propertySignature) &&
proto.getExtension(JvmProtoBuf.propertySignature).let { it.hasField() && it.field.getIsStaticInOuter() }) { proto.getExtension(JvmProtoBuf.propertySignature).let { it.hasField() && it.field.isStaticInOuter }) {
jClass.enclosingClass ?: throw KotlinReflectionInternalError("Inconsistent metadata for field $name in $jClass") jClass.enclosingClass ?: throw KotlinReflectionInternalError("Inconsistent metadata for field $name in $jClass")
} else jClass } else jClass
@@ -27,11 +27,11 @@ import kotlin.reflect.KotlinReflectionInternalError
internal class KFunctionFromReferenceImpl( internal class KFunctionFromReferenceImpl(
val reference: FunctionReference val reference: FunctionReference
): KFunctionImpl( ): KFunctionImpl(
reference.getOwner() as? KDeclarationContainerImpl ?: EmptyContainerForLocal, reference.owner as? KDeclarationContainerImpl ?: EmptyContainerForLocal,
reference.name, reference.name,
reference.getSignature() reference.signature
) { ) {
override fun getArity() = reference.getArity() override fun getArity() = reference.arity
override val name = reference.name override val name = reference.name
@@ -99,7 +99,7 @@ internal open class KFunctionImpl protected constructor(
} }
override fun getArity(): Int { override fun getArity(): Int {
return descriptor.valueParameters.size() + return descriptor.valueParameters.size +
(if (descriptor.dispatchReceiverParameter != null) 1 else 0) + (if (descriptor.dispatchReceiverParameter != null) 1 else 0) +
(if (descriptor.extensionReceiverParameter != null) 1 else 0) (if (descriptor.extensionReceiverParameter != null) 1 else 0)
} }
@@ -14,6 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
@file:Suppress("DEPRECATION")
package kotlin.reflect.jvm.internal package kotlin.reflect.jvm.internal
import org.jetbrains.kotlin.descriptors.ConstructorDescriptor import org.jetbrains.kotlin.descriptors.ConstructorDescriptor
@@ -45,7 +46,7 @@ internal class KPackageImpl(override val jClass: Class<*>, val moduleName: Strin
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
override fun getProperties(name: Name): Collection<PropertyDescriptor> = override fun getProperties(name: Name): Collection<PropertyDescriptor> =
scope.getContributedVariables(name, NoLookupLocation.FROM_REFLECTION) as Collection<PropertyDescriptor> scope.getContributedVariables(name, NoLookupLocation.FROM_REFLECTION)
override fun getFunctions(name: Name): Collection<FunctionDescriptor> = override fun getFunctions(name: Name): Collection<FunctionDescriptor> =
scope.getContributedFunctions(name, NoLookupLocation.FROM_REFLECTION) scope.getContributedFunctions(name, NoLookupLocation.FROM_REFLECTION)
@@ -57,8 +58,8 @@ internal class KPackageImpl(override val jClass: Class<*>, val moduleName: Strin
jClass.hashCode() jClass.hashCode()
override fun toString(): String { override fun toString(): String {
val name = jClass.getName() val name = jClass.name
return "package " + if (jClass.isAnnotationPresent(javaClass<KotlinPackage>())) { return "package " + if (jClass.isAnnotationPresent(KotlinPackage::class.java)) {
if (name == "_DefaultPackage") "<default>" else name.substringBeforeLast(".") if (name == "_DefaultPackage") "<default>" else name.substringBeforeLast(".")
} }
else name else name
@@ -27,8 +27,8 @@ import java.lang.ref.WeakReference;
public static abstract class Val<T> { public static abstract class Val<T> {
private static final Object NULL_VALUE = new Object() {}; private static final Object NULL_VALUE = new Object() {};
@SuppressWarnings("UnusedParameters") @SuppressWarnings({"UnusedParameters", "unused"})
public T get(Object instance, Object metadata) { public final T getValue(Object instance, Object metadata) {
return invoke(); return invoke();
} }
@@ -58,17 +58,17 @@ internal object ReflectionObjectRenderer {
// TODO: include visibility // TODO: include visibility
fun renderProperty(descriptor: PropertyDescriptor): String { fun renderProperty(descriptor: PropertyDescriptor): String {
return StringBuilder { return buildString {
append(if (descriptor.isVar) "var " else "val ") append(if (descriptor.isVar) "var " else "val ")
appendReceiversAndName(descriptor) appendReceiversAndName(descriptor)
append(": ") append(": ")
append(renderType(descriptor.type)) append(renderType(descriptor.type))
}.toString() }
} }
fun renderFunction(descriptor: FunctionDescriptor): String { fun renderFunction(descriptor: FunctionDescriptor): String {
return StringBuilder { return buildString {
append("fun ") append("fun ")
appendReceiversAndName(descriptor) appendReceiversAndName(descriptor)
@@ -78,11 +78,11 @@ internal object ReflectionObjectRenderer {
append(": ") append(": ")
append(renderType(descriptor.returnType!!)) append(renderType(descriptor.returnType!!))
}.toString() }
} }
fun renderParameter(parameter: KParameterImpl): String { fun renderParameter(parameter: KParameterImpl): String {
return StringBuilder { return buildString {
when (parameter.kind) { when (parameter.kind) {
KParameter.Kind.EXTENSION_RECEIVER -> append("extension receiver") KParameter.Kind.EXTENSION_RECEIVER -> append("extension receiver")
KParameter.Kind.INSTANCE -> append("instance") KParameter.Kind.INSTANCE -> append("instance")
@@ -91,7 +91,7 @@ internal object ReflectionObjectRenderer {
append(" of ") append(" of ")
append(renderCallable(parameter.callable.descriptor)) append(renderCallable(parameter.callable.descriptor))
}.toString() }
} }
fun renderType(type: KotlinType): String { fun renderType(type: KotlinType): String {
@@ -209,7 +209,7 @@ internal object RuntimeTypeMapper {
val parameters = function.valueParameters val parameters = function.valueParameters
when (function.name.asString()) { when (function.name.asString()) {
"equals" -> if (parameters.size() == 1 && KotlinBuiltIns.isNullableAny(parameters.single().type)) { "equals" -> if (parameters.size == 1 && KotlinBuiltIns.isNullableAny(parameters.single().type)) {
return JvmFunctionSignature.BuiltInFunction.Predefined("equals(Ljava/lang/Object;)Z", return JvmFunctionSignature.BuiltInFunction.Predefined("equals(Ljava/lang/Object;)Z",
Any::class.java.getDeclaredMethod("equals", Any::class.java)) Any::class.java.getDeclaredMethod("equals", Any::class.java))
} }
@@ -240,7 +240,7 @@ internal object RuntimeTypeMapper {
} }
val classId = klass.classId val classId = klass.classId
if (!classId.isLocal()) { if (!classId.isLocal) {
JavaToKotlinClassMap.INSTANCE.mapJavaToKotlin(classId.asSingleFqName())?.let { return it.classId } JavaToKotlinClassMap.INSTANCE.mapJavaToKotlin(classId.asSingleFqName())?.let { return it.classId }
} }
@@ -248,5 +248,5 @@ internal object RuntimeTypeMapper {
} }
private val Class<*>.primitiveType: PrimitiveType? private val Class<*>.primitiveType: PrimitiveType?
get() = if (isPrimitive()) JvmPrimitiveType.get(getSimpleName()).getPrimitiveType() else null get() = if (isPrimitive) JvmPrimitiveType.get(simpleName).primitiveType else null
} }
@@ -17,7 +17,6 @@
package kotlin.reflect.jvm.internal package kotlin.reflect.jvm.internal
import java.lang.ref.WeakReference import java.lang.ref.WeakReference
import kotlin.reflect.KClass
import kotlin.reflect.jvm.internal.pcollections.HashPMap import kotlin.reflect.jvm.internal.pcollections.HashPMap
// TODO: collect nulls periodically // TODO: collect nulls periodically
@@ -29,7 +28,7 @@ private var K_CLASS_CACHE = HashPMap.empty<String, Any>()
// This function is invoked on each reflection access to Java classes, properties, etc. Performance is critical here. // This function is invoked on each reflection access to Java classes, properties, etc. Performance is critical here.
internal fun <T : Any> getOrCreateKotlinClass(jClass: Class<T>): KClassImpl<T> { internal fun <T : Any> getOrCreateKotlinClass(jClass: Class<T>): KClassImpl<T> {
val name = jClass.getName() val name = jClass.name
val cached = K_CLASS_CACHE[name] val cached = K_CLASS_CACHE[name]
if (cached is WeakReference<*>) { if (cached is WeakReference<*>) {
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
@@ -40,7 +39,8 @@ internal fun <T : Any> getOrCreateKotlinClass(jClass: Class<T>): KClassImpl<T> {
} }
else if (cached != null) { else if (cached != null) {
// If the cached value is not a weak reference, it's an array of weak references // If the cached value is not a weak reference, it's an array of weak references
cached as Array<WeakReference<KClassImpl<T>>> @Suppress("UNCHECKED_CAST")
(cached as Array<WeakReference<KClassImpl<T>>>)
for (ref in cached) { for (ref in cached) {
val kClass = ref.get() val kClass = ref.get()
if (kClass?.jClass == jClass) { if (kClass?.jClass == jClass) {
@@ -50,7 +50,7 @@ internal fun <T : Any> getOrCreateKotlinClass(jClass: Class<T>): KClassImpl<T> {
// This is the most unlikely case: we found a cached array of references of length at least 2 (can't be 1 because // This is the most unlikely case: we found a cached array of references of length at least 2 (can't be 1 because
// the single element would be cached instead), and none of those classes is the one we're looking for // the single element would be cached instead), and none of those classes is the one we're looking for
val size = cached.size() val size = cached.size
// Don't use Array constructor because it creates a lambda // Don't use Array constructor because it creates a lambda
val newArray = arrayOfNulls<WeakReference<KClassImpl<*>>>(size + 1) val newArray = arrayOfNulls<WeakReference<KClassImpl<*>>>(size + 1)
// Don't use Arrays.copyOf because it works reflectively // Don't use Arrays.copyOf because it works reflectively
@@ -21,7 +21,7 @@ fun main(args: Array<String>) {
val INCLUDE_END = ".java</include>" val INCLUDE_END = ".java</include>"
val POM_PATH = "META-INF/maven/com.google.protobuf/protobuf-java/pom.xml" val POM_PATH = "META-INF/maven/com.google.protobuf/protobuf-java/pom.xml"
if (args.size() != 2) { if (args.size != 2) {
error("Usage: kotlinc -script build-protobuf-lite.kts <path-to-protobuf-jar> <output-path>") error("Usage: kotlinc -script build-protobuf-lite.kts <path-to-protobuf-jar> <output-path>")
} }
@@ -67,7 +67,7 @@ fun loadVersion(library: File): IntArray {
} }
fun main(args: Array<String>) { fun main(args: Array<String>) {
if (args.size() != 2) { if (args.size != 2) {
error("Usage: kotlinc -script check-library-abi-version.kts <jar-1> <jar-2>") error("Usage: kotlinc -script check-library-abi-version.kts <jar-1> <jar-2>")
} }
@@ -22,7 +22,7 @@ import java.io.File
fun main(args: Array<String>) { fun main(args: Array<String>) {
val filePathDefault = "updated-version.txt" val filePathDefault = "updated-version.txt"
if (args.isEmpty() || args.size() > 2) { if (args.isEmpty() || args.size > 2) {
error("Usage: kotlinc -script increment-version.kts " + error("Usage: kotlinc -script increment-version.kts " +
"<version> " + "<version> " +
"<file-path='$filePathDefault'>") "<file-path='$filePathDefault'>")
@@ -31,7 +31,7 @@ fun main(args: Array<String>) {
var versionStr = args[0] var versionStr = args[0]
val incrementPartStr = versionStr.takeLastWhile { it.isDigit() } val incrementPartStr = versionStr.takeLastWhile { it.isDigit() }
val versionPrefix = versionStr.take(versionStr.length() - incrementPartStr.length()) val versionPrefix = versionStr.take(versionStr.length - incrementPartStr.length)
val incrementPart = incrementPartStr.toInt() val incrementPart = incrementPartStr.toInt()
var filePath = args.getOrNull(1) ?: filePathDefault var filePath = args.getOrNull(1) ?: filePathDefault
@@ -27,7 +27,7 @@ import java.util.zip.ZipOutputStream
*/ */
fun main(args: Array<String>) { fun main(args: Array<String>) {
if (args.size() != 4) { if (args.size != 4) {
error("Usage: kotlinc -script strip-kotlin-annotations.kts <annotation-internal-name-regex> <class-internal-name-regex> <path-to-in-jar> <path-to-out-jar>") error("Usage: kotlinc -script strip-kotlin-annotations.kts <annotation-internal-name-regex> <class-internal-name-regex> <path-to-in-jar> <path-to-out-jar>")
} }
@@ -70,8 +70,8 @@ fun main(args: Array<String>) {
val inBytes = inJar.getInputStream(entry).readBytes() val inBytes = inJar.getInputStream(entry).readBytes()
val outBytes = transform(entry.getName(), inBytes) val outBytes = transform(entry.getName(), inBytes)
if (inBytes.size() < outBytes.size()) { if (inBytes.size < outBytes.size) {
error("Size increased for ${entry.getName()}: was ${inBytes.size()} bytes, became ${outBytes.size()} bytes") error("Size increased for ${entry.getName()}: was ${inBytes.size} bytes, became ${outBytes.size} bytes")
} }
entry.setCompressedSize(-1L) entry.setCompressedSize(-1L)