mirror of
https://github.com/Guardsquare/proguard.git
synced 2026-03-13 09:50:34 +08:00
Ensure that Kotlin parameters are kept when using -keepparameternames
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
* ProGuard -- shrinking, optimization, obfuscation, and preverification
|
||||
* of Java bytecode.
|
||||
*
|
||||
* Copyright (c) 2002-2020 Guardsquare NV
|
||||
* Copyright (c) 2002-2022 Guardsquare NV
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
@@ -20,17 +20,32 @@
|
||||
*/
|
||||
package proguard.obfuscate.kotlin;
|
||||
|
||||
import proguard.classfile.*;
|
||||
import proguard.classfile.attribute.*;
|
||||
import proguard.classfile.attribute.visitor.*;
|
||||
import proguard.classfile.kotlin.*;
|
||||
import proguard.classfile.kotlin.visitor.*;
|
||||
import proguard.obfuscate.AttributeUsageMarker;
|
||||
import proguard.util.*;
|
||||
import proguard.classfile.Clazz;
|
||||
import proguard.classfile.Member;
|
||||
import proguard.classfile.ProgramClass;
|
||||
import proguard.classfile.ProgramMethod;
|
||||
import proguard.classfile.kotlin.KotlinClassKindMetadata;
|
||||
import proguard.classfile.kotlin.KotlinConstructorMetadata;
|
||||
import proguard.classfile.kotlin.KotlinDeclarationContainerMetadata;
|
||||
import proguard.classfile.kotlin.KotlinFunctionMetadata;
|
||||
import proguard.classfile.kotlin.KotlinMetadata;
|
||||
import proguard.classfile.kotlin.KotlinPropertyMetadata;
|
||||
import proguard.classfile.kotlin.KotlinSyntheticClassKindMetadata;
|
||||
import proguard.classfile.kotlin.KotlinValueParameterMetadata;
|
||||
import proguard.classfile.kotlin.visitor.AllPropertyVisitor;
|
||||
import proguard.classfile.kotlin.visitor.KotlinConstructorVisitor;
|
||||
import proguard.classfile.kotlin.visitor.KotlinFunctionVisitor;
|
||||
import proguard.classfile.kotlin.visitor.KotlinMetadataVisitor;
|
||||
import proguard.classfile.kotlin.visitor.KotlinPropertyVisitor;
|
||||
import proguard.classfile.kotlin.visitor.KotlinValueParameterVisitor;
|
||||
import proguard.classfile.visitor.MemberVisitor;
|
||||
import proguard.util.Processable;
|
||||
|
||||
import static proguard.util.ProcessingFlags.DONT_OBFUSCATE;
|
||||
|
||||
/**
|
||||
* This KotlinMetadataVisitor marks ValueParameters of constructors, properties and functions
|
||||
* based on markings by the {@link AttributeUsageMarker}.
|
||||
* if their referenced method is not obfuscated.
|
||||
*/
|
||||
public class KotlinValueParameterUsageMarker
|
||||
implements KotlinMetadataVisitor,
|
||||
@@ -39,7 +54,7 @@ implements KotlinMetadataVisitor,
|
||||
KotlinConstructorVisitor,
|
||||
KotlinPropertyVisitor,
|
||||
KotlinFunctionVisitor,
|
||||
AttributeVisitor,
|
||||
MemberVisitor,
|
||||
KotlinValueParameterVisitor
|
||||
{
|
||||
// A processing info flag to indicate the attribute is being used.
|
||||
@@ -47,8 +62,8 @@ implements KotlinMetadataVisitor,
|
||||
|
||||
private boolean keepParameterInfo;
|
||||
|
||||
|
||||
// Implementations for KotlinMetadataVisitor.
|
||||
|
||||
@Override
|
||||
public void visitAnyKotlinMetadata(Clazz clazz, KotlinMetadata kotlinMetadata) {}
|
||||
|
||||
@@ -75,16 +90,15 @@ implements KotlinMetadataVisitor,
|
||||
kotlinSyntheticClassKindMetadata.functionsAccept(clazz, this);
|
||||
}
|
||||
|
||||
|
||||
// Implementations for KotlinConstructorVisitor.
|
||||
|
||||
@Override
|
||||
public void visitConstructor(Clazz clazz,
|
||||
KotlinClassKindMetadata kotlinClassKindMetadata,
|
||||
KotlinConstructorMetadata kotlinConstructorMetadata)
|
||||
{
|
||||
keepParameterInfo = false;
|
||||
kotlinConstructorMetadata.referencedMethodAccept(clazz,
|
||||
new AllAttributeVisitor(true, this));
|
||||
kotlinConstructorMetadata.referencedMethodAccept(clazz, this);
|
||||
|
||||
if (keepParameterInfo)
|
||||
{
|
||||
@@ -92,15 +106,18 @@ implements KotlinMetadataVisitor,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Implementations for KotlinPropertyVisitor.
|
||||
|
||||
@Override
|
||||
public void visitAnyProperty(Clazz clazz,
|
||||
KotlinDeclarationContainerMetadata kotlinDeclarationContainerMetadata,
|
||||
KotlinPropertyMetadata kotlinPropertyMetadata)
|
||||
{
|
||||
keepParameterInfo = false;
|
||||
kotlinPropertyMetadata.setterParametersAccept(clazz, kotlinDeclarationContainerMetadata, this);
|
||||
if (kotlinPropertyMetadata.referencedSetterMethod != null)
|
||||
{
|
||||
kotlinPropertyMetadata.referencedSetterMethod.accept(clazz, this);
|
||||
}
|
||||
|
||||
if (keepParameterInfo)
|
||||
{
|
||||
@@ -108,16 +125,15 @@ implements KotlinMetadataVisitor,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Implementations for KotlinFunctionVisitor.
|
||||
|
||||
@Override
|
||||
public void visitAnyFunction(Clazz clazz,
|
||||
KotlinMetadata kotlinMetadata,
|
||||
KotlinFunctionMetadata kotlinFunctionMetadata)
|
||||
{
|
||||
keepParameterInfo = false;
|
||||
kotlinFunctionMetadata.referencedMethodAccept(clazz,
|
||||
new AllAttributeVisitor(true, this));
|
||||
kotlinFunctionMetadata.referencedMethodAccept(this);
|
||||
|
||||
if (keepParameterInfo)
|
||||
{
|
||||
@@ -125,28 +141,16 @@ implements KotlinMetadataVisitor,
|
||||
}
|
||||
}
|
||||
|
||||
// Implementations for MemberVisitor
|
||||
|
||||
// Implementations for AttributeVisitor.
|
||||
@Override
|
||||
public void visitAnyAttribute(Clazz clazz, Attribute attribute) {}
|
||||
public void visitAnyMember(Clazz clazz, Member member) {}
|
||||
|
||||
|
||||
@Override
|
||||
public void visitLocalVariableTableAttribute(Clazz clazz,
|
||||
Method method,
|
||||
CodeAttribute codeAttribute,
|
||||
LocalVariableTableAttribute localVariableTableAttribute)
|
||||
public void visitProgramMethod(ProgramClass programClass, ProgramMethod programMethod)
|
||||
{
|
||||
keepParameterInfo = keepParameterInfo || AttributeUsageMarker.isUsed(localVariableTableAttribute);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitLocalVariableTypeTableAttribute(Clazz clazz,
|
||||
Method method,
|
||||
CodeAttribute codeAttribute,
|
||||
LocalVariableTypeTableAttribute localVariableTypeTableAttribute)
|
||||
{
|
||||
keepParameterInfo = keepParameterInfo || AttributeUsageMarker.isUsed(localVariableTypeTableAttribute);
|
||||
keepParameterInfo = (programMethod.getProcessingFlags() & DONT_OBFUSCATE) != 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -505,6 +505,9 @@ This page lists all available options for ProGuard, grouped logically.
|
||||
[processing a library](examples.md#library). Some IDEs can use the
|
||||
information to assist developers who use the library, for example with tool
|
||||
tips or autocompletion. Only applicable when obfuscating.
|
||||
|
||||
When processing Kotlin metadata the Kotlin function, constructor and property setter
|
||||
parameter names are also kept.
|
||||
|
||||
`-renamesourcefileattribute`{: #renamesourcefileattribute} \[*string*\]
|
||||
: Specifies a constant string to be put in the `SourceFile` attributes (and
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
## Version 7.3.1
|
||||
|
||||
### Bugfixes
|
||||
|
||||
- Fix `-keepparameternames` to keep Kotlin function, constructor and property setter parameter names.
|
||||
|
||||
## Version 7.3.0
|
||||
|
||||
### Java support
|
||||
|
||||
Reference in New Issue
Block a user