Remove support for -useuniqueclassmembernames
Bug: 112338230
Change-Id: Ic8869e991da8bdc3049c0c6a9b8fa9f73f900666
diff --git a/src/main/java/com/android/tools/r8/naming/FieldNameMinifier.java b/src/main/java/com/android/tools/r8/naming/FieldNameMinifier.java
index 9f70f37..b3ac259 100644
--- a/src/main/java/com/android/tools/r8/naming/FieldNameMinifier.java
+++ b/src/main/java/com/android/tools/r8/naming/FieldNameMinifier.java
@@ -150,8 +150,7 @@
}
if (!state.isReserved(field.name, field.type)) {
- renaming.put(
- field, state.assignNewNameFor(field, field.name, field.type, useUniqueMemberNames));
+ renaming.put(field, state.assignNewNameFor(field, field.name, field.type));
}
}
diff --git a/src/main/java/com/android/tools/r8/naming/InterfaceMethodNameMinifier.java b/src/main/java/com/android/tools/r8/naming/InterfaceMethodNameMinifier.java
index f6bcde1..661711f 100644
--- a/src/main/java/com/android/tools/r8/naming/InterfaceMethodNameMinifier.java
+++ b/src/main/java/com/android/tools/r8/naming/InterfaceMethodNameMinifier.java
@@ -19,7 +19,6 @@
import com.android.tools.r8.utils.Timing;
import com.google.common.base.Equivalence;
import com.google.common.base.Equivalence.Wrapper;
-import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import java.io.PrintStream;
import java.util.ArrayList;
@@ -260,23 +259,11 @@
// We use the origin state to allocate a name here so that we can reuse names between different
// unrelated interfaces. This saves some space. The alternative would be to use a global state
// for allocating names, which would save the work to search here.
- DexString previousCandidate = null;
DexString candidate;
do {
candidate = originState.assignNewName();
-
- // If the state returns the same candidate for two consecutive trials, it should be this case:
- // 1) an interface method with the same signature (name, param) but different return type
- // has been already renamed; and 2) -useuniqueclassmembernames is set.
- // The option forces the naming state to return the same renamed name for the same signature.
- // So, here we break the loop in an ad-hoc manner.
- if (candidate != null && candidate == previousCandidate) {
- assert minifierState.useUniqueMemberNames();
- break;
- }
for (MethodNamingState state : collectedStates) {
if (!state.isAvailable(candidate)) {
- previousCandidate = candidate;
candidate = null;
break;
}
@@ -333,10 +320,6 @@
}
private Set<NamingState<DexProto, ?>> getReachableStates(DexType type) {
- if (minifierState.useUniqueMemberNames()) {
- return ImmutableSet.of(minifierState.globalState());
- }
-
Set<DexType> reachableInterfaces = Sets.newIdentityHashSet();
reachableInterfaces.add(type);
collectSuperInterfaces(type, reachableInterfaces);
diff --git a/src/main/java/com/android/tools/r8/naming/MemberNameMinifier.java b/src/main/java/com/android/tools/r8/naming/MemberNameMinifier.java
index 058a3b7..2743616 100644
--- a/src/main/java/com/android/tools/r8/naming/MemberNameMinifier.java
+++ b/src/main/java/com/android/tools/r8/naming/MemberNameMinifier.java
@@ -26,7 +26,6 @@
protected final Map<MemberType, DexString> renaming = new IdentityHashMap<>();
protected final NamingState<StateType, ?> globalState;
- protected final boolean useUniqueMemberNames;
protected final boolean overloadAggressively;
protected final boolean useApplyMapping;
@@ -40,16 +39,9 @@
ProguardConfiguration proguardConfiguration = appView.options().getProguardConfiguration();
this.appView = appView;
this.dictionary = proguardConfiguration.getObfuscationDictionary();
- this.useUniqueMemberNames = proguardConfiguration.isUseUniqueClassMemberNames();
- this.overloadAggressively =
- proguardConfiguration.isOverloadAggressivelyWithoutUseUniqueClassMemberNames();
+ this.overloadAggressively = proguardConfiguration.isOverloadAggressively();
this.globalState =
- NamingState.createRoot(
- appView.dexItemFactory(),
- dictionary,
- getKeyTransform(),
- strategy,
- useUniqueMemberNames);
+ NamingState.createRoot(appView.dexItemFactory(), dictionary, getKeyTransform(), strategy);
this.useApplyMapping = proguardConfiguration.hasApplyMappingFile();
}
@@ -57,7 +49,7 @@
protected NamingState<StateType, ?> computeStateIfAbsent(
DexType type, Function<DexType, NamingState<StateType, ?>> f) {
- return useUniqueMemberNames ? globalState : states.computeIfAbsent(type, f);
+ return states.computeIfAbsent(type, f);
}
protected boolean alwaysReserveMemberNames(DexClass holder) {
@@ -77,24 +69,16 @@
}
NamingState<StateType, ?> getState(DexType type) {
- return useUniqueMemberNames ? globalState : states.get(type);
+ return states.get(type);
}
DexType getStateKey(NamingState<StateType, ?> state) {
return states.inverse().get(state);
}
- NamingState<StateType, ?> globalState() {
- return globalState;
- }
-
boolean isReservedInGlobalState(DexString name, StateType state) {
return globalState.isReserved(name, state);
}
-
- boolean useUniqueMemberNames() {
- return useUniqueMemberNames;
- }
}
interface MemberNamingStrategy {
diff --git a/src/main/java/com/android/tools/r8/naming/MethodNameMinifier.java b/src/main/java/com/android/tools/r8/naming/MethodNameMinifier.java
index 77d213b..15d550c 100644
--- a/src/main/java/com/android/tools/r8/naming/MethodNameMinifier.java
+++ b/src/main/java/com/android/tools/r8/naming/MethodNameMinifier.java
@@ -166,7 +166,7 @@
for (DexEncodedMethod method : holder.allMethodsSorted()) {
assignNameToMethod(method, state, renamingAtThisLevel, doPrivates);
}
- if (!doPrivates && !useUniqueMemberNames) {
+ if (!doPrivates) {
renamingAtThisLevel.forEach(
(key, candidate) -> {
DexMethod method = key.get();
@@ -195,8 +195,7 @@
DexString renamedName =
renamingAtThisLevel.computeIfAbsent(
equivalence.wrap(method),
- key ->
- state.assignNewNameFor(method, method.name, method.proto, useUniqueMemberNames));
+ key -> state.assignNewNameFor(method, method.name, method.proto));
renaming.put(method, renamedName);
}
}
@@ -238,11 +237,7 @@
ignore ->
parent == null
? NamingState.createRoot(
- appView.dexItemFactory(),
- dictionary,
- getKeyTransform(),
- strategy,
- useUniqueMemberNames)
+ appView.dexItemFactory(), dictionary, getKeyTransform(), strategy)
: parent.createChild());
DexClass holder = appView.definitionFor(type);
@@ -299,7 +294,7 @@
}
DexString assignNewName() {
- return parent.assignNewNameFor(method, name, proto, false);
+ return parent.assignNewNameFor(method, name, proto);
}
boolean isReserved() {
@@ -307,7 +302,7 @@
}
boolean isAvailable(DexString candidate) {
- return parent.isAvailable(name, proto, candidate);
+ return parent.isAvailable(proto, candidate);
}
void addRenaming(DexString newName) {
diff --git a/src/main/java/com/android/tools/r8/naming/NamingState.java b/src/main/java/com/android/tools/r8/naming/NamingState.java
index 502fae2..298144ef 100644
--- a/src/main/java/com/android/tools/r8/naming/NamingState.java
+++ b/src/main/java/com/android/tools/r8/naming/NamingState.java
@@ -13,7 +13,6 @@
import com.android.tools.r8.naming.MemberNameMinifier.MemberNamingStrategy;
import com.android.tools.r8.utils.StringUtils;
import com.google.common.collect.HashBasedTable;
-import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
import com.google.common.collect.Table;
import java.io.PrintStream;
@@ -33,16 +32,13 @@
private final List<String> dictionary;
private final Function<ProtoType, KeyType> keyTransform;
private final MemberNamingStrategy strategy;
- private final boolean useUniqueMemberNames;
static <S, T extends CachedHashValueDexItem> NamingState<T, S> createRoot(
DexItemFactory itemFactory,
List<String> dictionary,
Function<T, S> keyTransform,
- MemberNamingStrategy strategy,
- boolean useUniqueMemberNames) {
- return new NamingState<>(
- null, itemFactory, dictionary, keyTransform, strategy, useUniqueMemberNames);
+ MemberNamingStrategy strategy) {
+ return new NamingState<>(null, itemFactory, dictionary, keyTransform, strategy);
}
private NamingState(
@@ -50,19 +46,16 @@
DexItemFactory itemFactory,
List<String> dictionary,
Function<ProtoType, KeyType> keyTransform,
- MemberNamingStrategy strategy,
- boolean useUniqueMemberNames) {
+ MemberNamingStrategy strategy) {
this.parent = parent;
this.itemFactory = itemFactory;
this.dictionary = dictionary;
this.keyTransform = keyTransform;
this.strategy = strategy;
- this.useUniqueMemberNames = useUniqueMemberNames;
}
public NamingState<ProtoType, KeyType> createChild() {
- return new NamingState<>(
- this, itemFactory, dictionary, keyTransform, strategy, useUniqueMemberNames);
+ return new NamingState<>(this, itemFactory, dictionary, keyTransform, strategy);
}
private InternalState findInternalStateFor(KeyType key) {
@@ -92,13 +85,12 @@
return state.getAssignedNameFor(name, key);
}
- public DexString assignNewNameFor(
- DexReference source, DexString original, ProtoType proto, boolean markAsUsed) {
+ public DexString assignNewNameFor(DexReference source, DexString original, ProtoType proto) {
KeyType key = keyTransform.apply(proto);
DexString result = getAssignedNameFor(original, key);
if (result == null) {
InternalState state = getOrCreateInternalStateFor(key);
- result = state.getNameFor(source, original, key, markAsUsed);
+ result = state.getNewNameFor(source);
}
return result;
}
@@ -118,21 +110,15 @@
return state.isReserved(name);
}
- public boolean isAvailable(DexString original, ProtoType proto, DexString candidate) {
+ public boolean isAvailable(ProtoType proto, DexString candidate) {
KeyType key = keyTransform.apply(proto);
InternalState state = findInternalStateFor(key);
if (state == null) {
return true;
}
- assert !useUniqueMemberNames
- || isNullOrEqualTo(state.getAssignedNameFor(original, key), candidate);
return state.isAvailable(candidate);
}
- private static <T> boolean isNullOrEqualTo(T a, T b) {
- return a == null || a == b;
- }
-
public void addRenaming(DexString original, ProtoType proto, DexString newName) {
KeyType key = keyTransform.apply(proto);
InternalState state = getOrCreateInternalStateFor(key);
@@ -214,18 +200,7 @@
DexString getAssignedNameFor(DexString original, KeyType proto) {
DexString result = null;
if (renamings != null) {
- if (useUniqueMemberNames) {
- Map<KeyType, DexString> row = renamings.row(original);
- if (row != null) {
- // Either not renamed yet (0) or renamed (1). If renamed, return the same renamed name
- // so that other members with the same name can be renamed to the same renamed name.
- Set<DexString> renamedNames = Sets.newHashSet(row.values());
- assert renamedNames.size() <= 1;
- result = Iterables.getOnlyElement(renamedNames, null);
- }
- } else {
- result = renamings.get(original, proto);
- }
+ result = renamings.get(original, proto);
}
if (result == null && parentInternalState != null) {
result = parentInternalState.getAssignedNameFor(original, proto);
@@ -233,18 +208,11 @@
return result;
}
- DexString getNameFor(
- DexReference source, DexString original, KeyType proto, boolean markAsUsed) {
- DexString name = getAssignedNameFor(original, proto);
- if (name != null) {
- return name;
- }
+ private DexString getNewNameFor(DexReference source) {
+ DexString name;
do {
name = nextSuggestedName(source);
} while (!isAvailable(name) && !strategy.breakOnNotAvailable(source, name));
- if (markAsUsed) {
- addRenaming(original, proto, name);
- }
return name;
}
diff --git a/src/main/java/com/android/tools/r8/shaking/ProguardConfiguration.java b/src/main/java/com/android/tools/r8/shaking/ProguardConfiguration.java
index a767c86..894f4e8 100644
--- a/src/main/java/com/android/tools/r8/shaking/ProguardConfiguration.java
+++ b/src/main/java/com/android/tools/r8/shaking/ProguardConfiguration.java
@@ -51,7 +51,6 @@
private Path obfuscationDictionary;
private Path classObfuscationDictionary;
private Path packageObfuscationDictionary;
- private boolean useUniqueClassMemberNames;
private boolean keepParameterNames;
private Origin keepParameterNamesOptionOrigin;
private Position keepParameterNamesOptionPosition;
@@ -209,14 +208,6 @@
this.packageObfuscationDictionary = packageObfuscationDictionary;
}
- public void setUseUniqueClassMemberNames(boolean useUniqueClassMemberNames) {
- this.useUniqueClassMemberNames = useUniqueClassMemberNames;
- }
-
- boolean isUseUniqueClassMemberNames() {
- return useUniqueClassMemberNames;
- }
-
boolean isOverloadAggressively() {
return overloadAggressively;
}
@@ -323,7 +314,6 @@
DictionaryReader.readAllNames(obfuscationDictionary, reporter),
DictionaryReader.readAllNames(classObfuscationDictionary, reporter),
DictionaryReader.readAllNames(packageObfuscationDictionary, reporter),
- useUniqueClassMemberNames,
keepParameterNames,
adaptClassStrings.build(),
adaptResourceFilenames.build(),
@@ -389,7 +379,6 @@
private final ImmutableList<String> obfuscationDictionary;
private final ImmutableList<String> classObfuscationDictionary;
private final ImmutableList<String> packageObfuscationDictionary;
- private final boolean useUniqueClassMemberNames;
private final boolean keepParameterNames;
private final ProguardClassFilter adaptClassStrings;
private final ProguardPathFilter adaptResourceFilenames;
@@ -427,7 +416,6 @@
ImmutableList<String> obfuscationDictionary,
ImmutableList<String> classObfuscationDictionary,
ImmutableList<String> packageObfuscationDictionary,
- boolean useUniqueClassMemberNames,
boolean keepParameterNames,
ProguardClassFilter adaptClassStrings,
ProguardPathFilter adaptResourceFilenames,
@@ -463,7 +451,6 @@
this.obfuscationDictionary = obfuscationDictionary;
this.classObfuscationDictionary = classObfuscationDictionary;
this.packageObfuscationDictionary = packageObfuscationDictionary;
- this.useUniqueClassMemberNames = useUniqueClassMemberNames;
this.keepParameterNames = keepParameterNames;
this.adaptClassStrings = adaptClassStrings;
this.adaptResourceFilenames = adaptResourceFilenames;
@@ -579,8 +566,8 @@
return rules;
}
- public boolean isOverloadAggressivelyWithoutUseUniqueClassMemberNames() {
- return overloadAggressively && !useUniqueClassMemberNames;
+ public boolean isOverloadAggressively() {
+ return overloadAggressively;
}
public List<String> getObfuscationDictionary() {
@@ -595,10 +582,6 @@
return packageObfuscationDictionary;
}
- public boolean isUseUniqueClassMemberNames() {
- return useUniqueClassMemberNames;
- }
-
public boolean isKeepParameterNames() {
return keepParameterNames;
}
diff --git a/src/main/java/com/android/tools/r8/shaking/ProguardConfigurationParser.java b/src/main/java/com/android/tools/r8/shaking/ProguardConfigurationParser.java
index 62885b6..3857aca 100644
--- a/src/main/java/com/android/tools/r8/shaking/ProguardConfigurationParser.java
+++ b/src/main/java/com/android/tools/r8/shaking/ProguardConfigurationParser.java
@@ -85,9 +85,10 @@
// TODO(b/121340442): we may support this later.
"dump");
- private static final List<String> WARNED_FLAG_OPTIONS = ImmutableList.of(
- // TODO(b/73707846): add support -addconfigurationdebugging
- "addconfigurationdebugging");
+ private static final List<String> WARNED_FLAG_OPTIONS =
+ ImmutableList.of(
+ // TODO(b/73707846): add support -addconfigurationdebugging
+ "addconfigurationdebugging", "useuniqueclassmembernames");
private static final List<String> WARNED_CLASS_DESCRIPTOR_OPTIONS = ImmutableList.of(
// TODO(b/73708157): add support -assumenoexternalsideeffects <class_spec>
@@ -129,13 +130,6 @@
configurationBuilder.getKeepParameterNamesOptionOrigin(),
configurationBuilder.getKeepParameterNamesOptionPosition()));
}
- if (configurationBuilder.isOverloadAggressively()
- && configurationBuilder.isUseUniqueClassMemberNames()) {
- reporter.warning(
- new StringDiagnostic(
- "The -overloadaggressively flag has no effect if -useuniqueclassmembernames"
- + " is also specified."));
- }
}
/**
@@ -204,8 +198,7 @@
skipWhitespace();
} while (parseOption());
// Collect the parsed configuration.
- configurationBuilder.addParsedConfiguration(
- contents.substring(positionAfterInclude, contents.length()));
+ configurationBuilder.addParsedConfiguration(contents.substring(positionAfterInclude));
}
private boolean parseOption()
@@ -394,8 +387,6 @@
MemberValuePropagationRule rule =
parseMemberValuePropagationRule(MemberValuePropagationRule.Type.NEVER, optionStart);
configurationBuilder.addRule(rule);
- } else if (acceptString("useuniqueclassmembernames")) {
- configurationBuilder.setUseUniqueClassMemberNames(true);
} else if (acceptString("adaptclassstrings")) {
parseClassFilter(configurationBuilder::addAdaptClassStringsPattern);
} else if (acceptString("adaptresourcefilenames")) {
@@ -900,8 +891,7 @@
"Expected [!]interface|@interface|class|enum", origin, getPosition(start));
}
- private void parseClassType(
- ProguardClassSpecification.Builder builder) throws ProguardRuleParserException {
+ private void parseClassType(ProguardClassSpecification.Builder builder) {
skipWhitespace();
TextPosition start = getPosition();
if (acceptChar('!')) {
@@ -1183,7 +1173,7 @@
for (int i = 0; i < fileName.length(); i++) {
if (fileName.charAt(i) == '<') {
if (copied < i) {
- result.append(fileName.substring(copied, i));
+ result.append(fileName, copied, i);
copied = i;
}
start = i;
@@ -1839,11 +1829,6 @@
origin, getPosition(start)));
}
- private void failPartiallyImplementedOption(String optionName, TextPosition start) {
- throw reporter.fatalError(new StringDiagnostic(
- "Option " + optionName + " currently not supported", origin, getPosition(start)));
- }
-
private Position getPosition(TextPosition start) {
if (start.getOffset() == position) {
return start;
diff --git a/src/main/java/com/android/tools/r8/shaking/StaticClassMerger.java b/src/main/java/com/android/tools/r8/shaking/StaticClassMerger.java
index 7d3d52b..8b4bedb 100644
--- a/src/main/java/com/android/tools/r8/shaking/StaticClassMerger.java
+++ b/src/main/java/com/android/tools/r8/shaking/StaticClassMerger.java
@@ -209,8 +209,7 @@
InternalOptions options,
MainDexClasses mainDexClasses) {
this.appView = appView;
- if (options
- .getProguardConfiguration().isOverloadAggressivelyWithoutUseUniqueClassMemberNames()) {
+ if (options.getProguardConfiguration().isOverloadAggressively()) {
fieldEquivalence = FieldSignatureEquivalence.getEquivalenceIgnoreName();
methodEquivalence = MethodSignatureEquivalence.getEquivalenceIgnoreName();
} else {
diff --git a/src/test/java/com/android/tools/r8/naming/CovariantReturnTypeInSubInterfaceTest.java b/src/test/java/com/android/tools/r8/naming/CovariantReturnTypeInSubInterfaceTest.java
index 20f46b4..c26a227 100644
--- a/src/test/java/com/android/tools/r8/naming/CovariantReturnTypeInSubInterfaceTest.java
+++ b/src/test/java/com/android/tools/r8/naming/CovariantReturnTypeInSubInterfaceTest.java
@@ -75,7 +75,6 @@
overloadAggressively ? "-overloadaggressively" : "# Not overload aggressively";
List<String> config = ImmutableList.of(
"-printmapping",
- "-useuniqueclassmembernames",
aggressive,
"-keep class " + mainName + " {",
" public void main(...);",
diff --git a/src/test/java/com/android/tools/r8/naming/InterfaceRenamingTestRunner.java b/src/test/java/com/android/tools/r8/naming/InterfaceRenamingTestRunner.java
index 715de97..ecbafd6 100644
--- a/src/test/java/com/android/tools/r8/naming/InterfaceRenamingTestRunner.java
+++ b/src/test/java/com/android/tools/r8/naming/InterfaceRenamingTestRunner.java
@@ -24,85 +24,63 @@
@RunWith(VmTestRunner.class)
public class InterfaceRenamingTestRunner extends TestBase {
- static final Class CLASS = InterfaceRenamingTest.class;
- static final Class[] CLASSES = InterfaceRenamingTest.CLASSES;
+
+ private static final Class<?> CLASS = InterfaceRenamingTest.class;
+ private static final Class<?>[] CLASSES = InterfaceRenamingTest.CLASSES;
@Test
public void testCfNoMinify() throws Exception {
- testCf(MinifyMode.NONE, false);
+ testCf(MinifyMode.NONE);
}
@Test
public void testCfMinify() throws Exception {
- testCf(MinifyMode.JAVA, false);
- }
-
- @Test
- public void testCfMinify_useUniqueClassMemberNames() throws Exception {
- testCf(MinifyMode.JAVA, true);
+ testCf(MinifyMode.JAVA);
}
@Test
public void testCfMinifyAggressive() throws Exception {
- testCf(MinifyMode.AGGRESSIVE, false);
- }
-
- @Test
- public void testCfMinifyAggressive_useUniqueClassMemberNames() throws Exception {
- testCf(MinifyMode.AGGRESSIVE, true);
+ testCf(MinifyMode.AGGRESSIVE);
}
@Test
public void testDexNoMinify() throws Exception {
- testDex(MinifyMode.NONE, false);
+ testDex(MinifyMode.NONE);
}
@Test
public void testDexMinify() throws Exception {
- testDex(MinifyMode.JAVA, false);
- }
-
- @Test
- public void testDexMinify_useUniqueClassMemberNames() throws Exception {
- testDex(MinifyMode.JAVA, true);
+ testDex(MinifyMode.JAVA);
}
@Test
public void testDexMinifyAggressive() throws Exception {
- testDex(MinifyMode.AGGRESSIVE, false);
+ testDex(MinifyMode.AGGRESSIVE);
}
- @Test
- public void testDexMinifyAggressive_useUniqueClassMemberNames() throws Exception {
- testDex(MinifyMode.AGGRESSIVE, true);
- }
-
- private void testCf(MinifyMode minify, boolean useUniqueClassMemberNames) throws Exception {
+ private void testCf(MinifyMode minify) throws Exception {
ProcessResult runInput =
ToolHelper.runJava(ToolHelper.getClassPathForTests(), CLASS.getCanonicalName());
assertEquals(0, runInput.exitCode);
Path outCf = temp.getRoot().toPath().resolve("cf.zip");
- build(new ClassFileConsumer.ArchiveConsumer(outCf), minify, useUniqueClassMemberNames);
+ build(new ClassFileConsumer.ArchiveConsumer(outCf), minify);
ProcessResult runCf = ToolHelper.runJava(outCf, CLASS.getCanonicalName());
assertEquals(runInput.toString(), runCf.toString());
}
- private void testDex(MinifyMode minify, boolean useUniqueClassMemberNames) throws Exception {
+ private void testDex(MinifyMode minify) throws Exception {
ProcessResult runInput =
ToolHelper.runJava(ToolHelper.getClassPathForTests(), CLASS.getCanonicalName());
assertEquals(0, runInput.exitCode);
Path outDex = temp.getRoot().toPath().resolve("dex.zip");
- build(new DexIndexedConsumer.ArchiveConsumer(outDex), minify, useUniqueClassMemberNames);
+ build(new DexIndexedConsumer.ArchiveConsumer(outDex), minify);
ProcessResult runDex =
ToolHelper.runArtNoVerificationErrorsRaw(outDex.toString(), CLASS.getCanonicalName());
assertEquals(runInput.stdout, runDex.stdout);
assertEquals(runInput.exitCode, runDex.exitCode);
}
- private void build(
- ProgramConsumer consumer,
- MinifyMode minify,
- boolean useUniqueClassMemberNames) throws Exception {
+ private void build(ProgramConsumer consumer, MinifyMode minify) throws Exception {
List<String> config =
Arrays.asList(
"-keep public class " + CLASS.getCanonicalName() + " {",
@@ -115,7 +93,6 @@
pgConfig -> {
pgConfig.setPrintMapping(true);
pgConfig.setOverloadAggressively(minify == MinifyMode.AGGRESSIVE);
- pgConfig.setUseUniqueClassMemberNames(useUniqueClassMemberNames);
if (!minify.isMinify()) {
pgConfig.disableObfuscation();
}
diff --git a/src/test/java/com/android/tools/r8/naming/overloadaggressively/ValidNameConflictTest.java b/src/test/java/com/android/tools/r8/naming/overloadaggressively/ValidNameConflictTest.java
index f718cb6..eade0a5 100644
--- a/src/test/java/com/android/tools/r8/naming/overloadaggressively/ValidNameConflictTest.java
+++ b/src/test/java/com/android/tools/r8/naming/overloadaggressively/ValidNameConflictTest.java
@@ -138,64 +138,6 @@
}
@Test
- public void remainFieldNameConflict_useuniqueclassmembernames() throws Exception {
- JasminBuilder builder = buildFieldNameConflictClassFile();
- ProcessResult javaOutput = runOnJavaNoVerifyRaw(builder, CLASS_NAME);
- assertEquals(0, javaOutput.exitCode);
-
- List<String> pgConfigs = ImmutableList.of(
- keepMainProguardConfiguration(CLASS_NAME),
- "-useuniqueclassmembernames",
- "-dontshrink");
- AndroidApp app = compileWithR8(builder, pgConfigs, null, backend);
-
- CodeInspector codeInspector = new CodeInspector(app);
- ClassSubject clazz = codeInspector.clazz(CLASS_NAME);
- assertTrue(clazz.isPresent());
- FieldSubject f1 = clazz.field("java.lang.String", REPEATED_NAME);
- assertTrue(f1.isPresent());
- assertTrue(f1.isRenamed());
- FieldSubject f2 = clazz.field("java.lang.Object", REPEATED_NAME);
- assertTrue(f2.isPresent());
- assertTrue(f2.isRenamed());
- assertEquals(f1.getFinalName(), f2.getFinalName());
-
- ProcessResult output = runRaw(app, CLASS_NAME);
- assertEquals(0, output.exitCode);
- assertEquals(javaOutput.stdout, output.stdout);
- }
-
- @Test
- public void remainFieldNameConflict_useuniqueclassmembernames_overloadaggressively()
- throws Exception {
- JasminBuilder builder = buildFieldNameConflictClassFile();
- ProcessResult javaOutput = runOnJavaNoVerifyRaw(builder, CLASS_NAME);
- assertEquals(0, javaOutput.exitCode);
-
- List<String> pgConfigs = ImmutableList.of(
- keepMainProguardConfiguration(CLASS_NAME),
- "-useuniqueclassmembernames",
- "-overloadaggressively", // no-op
- "-dontshrink");
- AndroidApp app = compileWithR8(builder, pgConfigs, null, backend);
-
- CodeInspector codeInspector = new CodeInspector(app);
- ClassSubject clazz = codeInspector.clazz(CLASS_NAME);
- assertTrue(clazz.isPresent());
- FieldSubject f1 = clazz.field("java.lang.String", REPEATED_NAME);
- assertTrue(f1.isPresent());
- assertTrue(f1.isRenamed());
- FieldSubject f2 = clazz.field("java.lang.Object", REPEATED_NAME);
- assertTrue(f2.isPresent());
- assertTrue(f2.isRenamed());
- assertEquals(f1.getFinalName(), f2.getFinalName());
-
- ProcessResult output = runRaw(app, CLASS_NAME);
- assertEquals(0, output.exitCode);
- assertEquals(javaOutput.stdout, output.stdout);
- }
-
- @Test
public void resolveFieldNameConflict_no_options() throws Exception {
JasminBuilder builder = buildFieldNameConflictClassFile();
ProcessResult javaOutput = runOnJavaNoVerifyRaw(builder, CLASS_NAME);
@@ -305,64 +247,6 @@
}
@Test
- public void remainMethodNameConflict_useuniqueclassmembernames() throws Exception {
- JasminBuilder builder = buildMethodNameConflictClassFile();
- ProcessResult javaOutput = runOnJavaNoVerifyRaw(builder, CLASS_NAME);
- assertEquals(0, javaOutput.exitCode);
-
- List<String> pgConfigs = ImmutableList.of(
- keepMainProguardConfiguration(CLASS_NAME),
- "-useuniqueclassmembernames",
- "-dontshrink");
- AndroidApp app = compileWithR8(builder, pgConfigs, null, backend);
-
- CodeInspector codeInspector = new CodeInspector(app);
- ClassSubject clazz = codeInspector.clazz(ANOTHER_CLASS);
- assertTrue(clazz.isPresent());
- MethodSubject m1 = clazz.method("java.lang.String", REPEATED_NAME, ImmutableList.of());
- assertTrue(m1.isPresent());
- assertTrue(m1.isRenamed());
- MethodSubject m2 = clazz.method("java.lang.Object", REPEATED_NAME, ImmutableList.of());
- assertTrue(m2.isPresent());
- assertTrue(m2.isRenamed());
- assertEquals(m1.getFinalName(), m2.getFinalName());
-
- ProcessResult output = runRaw(app, CLASS_NAME);
- assertEquals(0, output.exitCode);
- assertEquals(javaOutput.stdout, output.stdout);
- }
-
- @Test
- public void remainMethodNameConflict_useuniqueclassmembernames_overloadaggressively()
- throws Exception {
- JasminBuilder builder = buildMethodNameConflictClassFile();
- ProcessResult javaOutput = runOnJavaNoVerifyRaw(builder, CLASS_NAME);
- assertEquals(0, javaOutput.exitCode);
-
- List<String> pgConfigs = ImmutableList.of(
- keepMainProguardConfiguration(CLASS_NAME),
- "-useuniqueclassmembernames",
- "-overloadaggressively", // no-op
- "-dontshrink");
- AndroidApp app = compileWithR8(builder, pgConfigs, null, backend);
-
- CodeInspector codeInspector = new CodeInspector(app);
- ClassSubject clazz = codeInspector.clazz(ANOTHER_CLASS);
- assertTrue(clazz.isPresent());
- MethodSubject m1 = clazz.method("java.lang.String", REPEATED_NAME, ImmutableList.of());
- assertTrue(m1.isPresent());
- assertTrue(m1.isRenamed());
- MethodSubject m2 = clazz.method("java.lang.Object", REPEATED_NAME, ImmutableList.of());
- assertTrue(m2.isPresent());
- assertTrue(m2.isRenamed());
- assertEquals(m1.getFinalName(), m2.getFinalName());
-
- ProcessResult output = runRaw(app, CLASS_NAME);
- assertEquals(0, output.exitCode);
- assertEquals(javaOutput.stdout, output.stdout);
- }
-
- @Test
public void resolveMethodNameConflict_no_options() throws Exception {
JasminBuilder builder = buildMethodNameConflictClassFile();
ProcessResult javaOutput = runOnJavaNoVerifyRaw(builder, CLASS_NAME);
@@ -507,92 +391,6 @@
}
@Test
- public void remainMethodNameConflictInHierarchy_useuniqueclassmembernames() throws Exception {
- JasminBuilder builder = buildMethodNameConflictInHierarchy();
- ProcessResult javaOutput = runOnJavaNoVerifyRaw(builder, CLASS_NAME);
- assertEquals(0, javaOutput.exitCode);
-
- List<String> pgConfigs = ImmutableList.of(
- keepMainProguardConfiguration(CLASS_NAME),
- "-useuniqueclassmembernames",
- "-dontshrink");
- AndroidApp app = compileWithR8(builder, pgConfigs, null, backend);
-
- CodeInspector codeInspector = new CodeInspector(app);
- ClassSubject sup = codeInspector.clazz(SUPER_CLASS);
- assertTrue(sup.isPresent());
- MethodSubject m1 = sup.method("java.lang.String", REPEATED_NAME, ImmutableList.of());
- assertTrue(m1.isPresent());
- assertTrue(m1.isRenamed());
- MethodSubject m2 = sup.method("java.lang.Object", REPEATED_NAME, ImmutableList.of());
- assertTrue(m2.isPresent());
- assertTrue(m2.isRenamed());
- assertEquals(m1.getFinalName(), m2.getFinalName());
-
- ClassSubject sub = codeInspector.clazz(ANOTHER_CLASS);
- assertTrue(sub.isPresent());
- MethodSubject subM1 = sub.method("java.lang.String", REPEATED_NAME, ImmutableList.of());
- assertTrue(subM1.isPresent());
- assertTrue(subM1.isRenamed());
- MethodSubject subM2 = sub.method("java.lang.Object", REPEATED_NAME, ImmutableList.of());
- assertTrue(subM2.isPresent());
- assertTrue(subM2.isRenamed());
- assertEquals(subM1.getFinalName(), subM2.getFinalName());
-
- // No matter what, overloading methods should be renamed to the same name.
- assertEquals(m1.getFinalName(), subM1.getFinalName());
- assertEquals(m2.getFinalName(), subM2.getFinalName());
-
- ProcessResult output = runRaw(app, CLASS_NAME);
- assertEquals(0, output.exitCode);
- assertEquals(javaOutput.stdout, output.stdout);
- }
-
- @Test
- public void remainMethodNameConflictInHierarchy_useuniqueclassmembernames_overloadaggressively()
- throws Exception {
- JasminBuilder builder = buildMethodNameConflictInHierarchy();
- ProcessResult javaOutput = runOnJavaNoVerifyRaw(builder, CLASS_NAME);
- assertEquals(0, javaOutput.exitCode);
-
- List<String> pgConfigs = ImmutableList.of(
- keepMainProguardConfiguration(CLASS_NAME),
- "-useuniqueclassmembernames",
- "-overloadaggressively", // no-op
- "-dontshrink");
- AndroidApp app = compileWithR8(builder, pgConfigs, null, backend);
-
- CodeInspector codeInspector = new CodeInspector(app);
- ClassSubject sup = codeInspector.clazz(SUPER_CLASS);
- assertTrue(sup.isPresent());
- MethodSubject m1 = sup.method("java.lang.String", REPEATED_NAME, ImmutableList.of());
- assertTrue(m1.isPresent());
- assertTrue(m1.isRenamed());
- MethodSubject m2 = sup.method("java.lang.Object", REPEATED_NAME, ImmutableList.of());
- assertTrue(m2.isPresent());
- assertTrue(m2.isRenamed());
- assertEquals(m1.getFinalName(), m2.getFinalName());
-
- ClassSubject sub = codeInspector.clazz(ANOTHER_CLASS);
- assertTrue(sub.isPresent());
- MethodSubject subM1 = sub.method("java.lang.String", REPEATED_NAME, ImmutableList.of());
- assertTrue(subM1.isPresent());
- assertTrue(subM1.isRenamed());
- MethodSubject subM2 = sub.method("java.lang.Object", REPEATED_NAME, ImmutableList.of());
- assertTrue(subM2.isPresent());
- assertTrue(subM2.isRenamed());
- assertEquals(subM1.getFinalName(), subM2.getFinalName());
-
- // No matter what, overloading methods should be renamed to the same name.
- assertEquals(m1.getFinalName(), subM1.getFinalName());
- assertEquals(m2.getFinalName(), subM2.getFinalName());
-
- ProcessResult output = runRaw(app, CLASS_NAME);
- assertEquals(0, output.exitCode);
- assertEquals(javaOutput.stdout, output.stdout);
- }
-
- @Test
public void resolveMethodNameConflictInHierarchy_no_options() throws Exception {
JasminBuilder builder = buildMethodNameConflictInHierarchy();
ProcessResult javaOutput = runOnJavaNoVerifyRaw(builder, CLASS_NAME);
diff --git a/src/test/java/com/android/tools/r8/naming/uniqueclassmembernames/UniqueFieldMemberNamesTest.java b/src/test/java/com/android/tools/r8/naming/uniqueclassmembernames/UniqueFieldMemberNamesTest.java
deleted file mode 100644
index c455fc4..0000000
--- a/src/test/java/com/android/tools/r8/naming/uniqueclassmembernames/UniqueFieldMemberNamesTest.java
+++ /dev/null
@@ -1,140 +0,0 @@
-// Copyright (c) 2019, the R8 project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-package com.android.tools.r8.naming.uniqueclassmembernames;
-
-import static com.android.tools.r8.utils.codeinspector.Matchers.isPresent;
-import static com.android.tools.r8.utils.codeinspector.Matchers.isRenamed;
-import static org.hamcrest.CoreMatchers.not;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-
-import com.android.tools.r8.TestBase;
-import com.android.tools.r8.TestShrinkerBuilder;
-import com.android.tools.r8.ToolHelper;
-import com.android.tools.r8.jasmin.JasminBuilder;
-import com.android.tools.r8.jasmin.JasminBuilder.ClassBuilder;
-import com.android.tools.r8.utils.codeinspector.ClassSubject;
-import com.android.tools.r8.utils.codeinspector.CodeInspector;
-import com.android.tools.r8.utils.codeinspector.FieldSubject;
-import java.nio.file.Path;
-import org.junit.BeforeClass;
-import org.junit.ClassRule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-
-public class UniqueFieldMemberNamesTest extends TestBase {
-
- @ClassRule public static TemporaryFolder tempFolder = ToolHelper.getTemporaryFolderForTest();
-
- private static Path programClassA;
- private static Path programClassB;
-
- @BeforeClass
- public static void setup() throws Exception {
- {
- JasminBuilder builder = new JasminBuilder();
- ClassBuilder classBuilder = builder.addClass("A", "java/lang/Object");
- classBuilder.addField("public", "a", "Ljava/lang/Object;", null);
- classBuilder.addField("public", "f", "Ljava/lang/Object;", null);
- programClassA = tempFolder.getRoot().toPath().resolve("a.jar");
- builder.writeJar(programClassA);
- }
- {
- JasminBuilder builder = new JasminBuilder();
- ClassBuilder classBuilder = builder.addClass("B", "java/lang/Object");
- classBuilder.addField("public", "f", "Ljava/lang/Object;", null);
- classBuilder.addField("public", "f", "Ljava/lang/String;", null);
- programClassB = tempFolder.getRoot().toPath().resolve("b.jar");
- builder.writeJar(programClassB);
- }
- }
-
- @Test
- public void testR8() throws Exception {
- runTest(testForR8(Backend.DEX), true);
- }
-
- @Test
- public void testR8WithLibrary() throws Exception {
- runTestWithLibrary(testForR8(Backend.DEX), true);
- }
-
- @Test
- public void testProguard() throws Exception {
- runTest(testForProguard(), false);
- }
-
- @Test
- public void testProguardWithLibrary() throws Exception {
- runTestWithLibrary(testForProguard(), false);
- }
-
- private void runTest(TestShrinkerBuilder<?, ?, ?, ?, ?> builder, boolean isR8) throws Exception {
- CodeInspector inspector =
- builder
- .addProgramFiles(programClassA, programClassB)
- .addKeepRules("-useuniqueclassmembernames")
- .addKeepRules("-keep class A { java.lang.Object a; }")
- .noTreeShaking()
- .compile()
- .inspector();
-
- ClassSubject aClassSubject = inspector.clazz("A");
- assertThat(aClassSubject, isPresent());
-
- ClassSubject bClassSubject = inspector.clazz("B");
- assertThat(bClassSubject, isPresent());
-
- FieldSubject fieldSubject1 = aClassSubject.field("java.lang.Object", "f");
- assertThat(fieldSubject1, isPresent());
- assertThat(fieldSubject1, isRenamed());
- assertNotEquals("a", fieldSubject1.getFinalName());
-
- FieldSubject fieldSubject2 = bClassSubject.field("java.lang.Object", "f");
- assertThat(fieldSubject2, isPresent());
- assertThat(fieldSubject2, isRenamed());
- assertEquals(fieldSubject2.getFinalName(), fieldSubject1.getFinalName());
-
- FieldSubject fieldSubject3 = bClassSubject.field("java.lang.String", "f");
- assertThat(fieldSubject3, isPresent());
- assertThat(fieldSubject3, isRenamed());
- if (isR8) {
- // TODO(b/128973195): Fields should be given distinct names due to -useuniqueclassmembernames.
- assertEquals(fieldSubject2.getFinalName(), fieldSubject3.getFinalName());
- } else {
- assertNotEquals(fieldSubject2.getFinalName(), fieldSubject3.getFinalName());
- }
- }
-
- private void runTestWithLibrary(TestShrinkerBuilder<?, ?, ?, ?, ?> builder, boolean isR8)
- throws Exception {
- CodeInspector inspector =
- builder
- .addProgramFiles(programClassB)
- .addLibraryFiles(programClassA, runtimeJar(Backend.DEX))
- .addKeepRules("-useuniqueclassmembernames")
- .addKeepRules("-keep class A { java.lang.Object a; }")
- .noTreeShaking()
- .compile()
- .inspector();
-
- ClassSubject bClassSubject = inspector.clazz("B");
- assertThat(bClassSubject, isPresent());
-
- FieldSubject fieldSubject2 = bClassSubject.field("java.lang.Object", "f");
- assertThat(fieldSubject2, isPresent());
- assertThat(fieldSubject2, not(isRenamed()));
-
- FieldSubject fieldSubject3 = bClassSubject.field("java.lang.String", "f");
- assertThat(fieldSubject3, isPresent());
- if (isR8) {
- // TODO(b/128973195): Fields should be given distinct names due to -useuniqueclassmembernames.
- assertThat(fieldSubject3, not(isRenamed()));
- } else {
- assertThat(fieldSubject3, isRenamed());
- }
- }
-}
diff --git a/src/test/java/com/android/tools/r8/naming/uniqueclassmembernames/UseUniqueMemberNameTest.java b/src/test/java/com/android/tools/r8/naming/uniqueclassmembernames/UseUniqueMemberNameTest.java
deleted file mode 100644
index 8656a71..0000000
--- a/src/test/java/com/android/tools/r8/naming/uniqueclassmembernames/UseUniqueMemberNameTest.java
+++ /dev/null
@@ -1,123 +0,0 @@
-// Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-package com.android.tools.r8.naming.uniqueclassmembernames;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-
-import com.android.tools.r8.graph.DexField;
-import com.android.tools.r8.graph.DexItemFactory;
-import com.android.tools.r8.graph.DexMethod;
-import com.android.tools.r8.graph.DexType;
-import com.android.tools.r8.naming.NamingLens;
-import com.android.tools.r8.naming.NamingTestBase;
-import com.android.tools.r8.utils.ListUtils;
-import com.android.tools.r8.utils.Timing;
-import java.nio.file.Paths;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.function.BiConsumer;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameters;
-
-@RunWith(Parameterized.class)
-public class UseUniqueMemberNameTest extends NamingTestBase {
-
- public UseUniqueMemberNameTest(
- String test,
- List<String> keepRulesFiles,
- BiConsumer<DexItemFactory, NamingLens> inspection) {
- super(test, keepRulesFiles, inspection, new Timing("UseUniqueMemberNameTest"));
- }
-
- @Test
- public void minifierTest() throws Exception {
- NamingLens naming = runMinifier(ListUtils.map(keepRulesFiles, Paths::get));
- inspection.accept(dexItemFactory, naming);
- }
-
- @Parameters(name = "test: {0} keep: {1}")
- public static Collection<Object[]> data() {
- List<String> tests = Arrays.asList("uniquemembernames");
-
- Map<String, BiConsumer<DexItemFactory, NamingLens>> inspections = new HashMap<>();
- inspections.put("uniquemembernames:keep-rules-1.txt", UseUniqueMemberNameTest::test00_rule1);
- inspections.put("uniquemembernames:keep-rules-2.txt", UseUniqueMemberNameTest::test00_rule2);
-
- return createTests(tests, inspections);
- }
-
- private static void test00_rule1(DexItemFactory dexItemFactory, NamingLens naming) {
- DexType a = dexItemFactory.createType("Luniquemembernames/ClsA;");
- assertNotEquals("Luniquemembernames/ClsA;", naming.lookupDescriptor(a).toSourceString());
-
- DexMethod foo = dexItemFactory.createMethod(
- a, dexItemFactory.createProto(dexItemFactory.intType), "foo");
- String foo_renamed = naming.lookupName(foo).toSourceString();
- assertNotEquals("foo", foo_renamed);
-
- DexType aa = dexItemFactory.createType("Luniquemembernames/AnotherCls;");
- assertNotEquals("Luniquemembernames/AnotherCls;", naming.lookupDescriptor(aa).toSourceString());
-
- DexMethod another_foo = dexItemFactory.createMethod(
- aa, dexItemFactory.createProto(dexItemFactory.intType), "foo");
- String another_foo_renamed = naming.lookupName(another_foo).toSourceString();
- assertNotEquals("foo", another_foo_renamed);
-
- // BaseCls#a and AnotherCls#b are kept.
- // Due to BaseCls#a, BaseCls#foo should not be renamed to a.
- // On the other hand, AnotherCls#foo should be renamed to a.
- assertNotEquals(foo_renamed, another_foo_renamed);
-
- DexType base = dexItemFactory.createType("Luniquemembernames/BaseCls;");
- DexField f2 = dexItemFactory.createField(base, dexItemFactory.doubleType, "f2");
- DexField another_f2 = dexItemFactory.createField(aa, dexItemFactory.intType, "f2");
- // Fields f2's are only fields that are allowed to be renamed. Thus, they would be renamed to
- // the same name as long as R8 is deterministic.
- assertEquals(
- naming.lookupName(f2).toSourceString(),
- naming.lookupName(another_f2).toSourceString());
- }
-
- // -useuniqueclassmembernames
- private static void test00_rule2(DexItemFactory dexItemFactory, NamingLens naming) {
- DexType a = dexItemFactory.createType("Luniquemembernames/ClsA;");
- assertNotEquals("Luniquemembernames/ClsA;", naming.lookupDescriptor(a).toSourceString());
-
- DexMethod foo = dexItemFactory.createMethod(
- a, dexItemFactory.createProto(dexItemFactory.intType), "foo");
- String foo_renamed = naming.lookupName(foo).toSourceString();
- assertNotEquals("foo", foo_renamed);
-
- DexType aa = dexItemFactory.createType("Luniquemembernames/AnotherCls;");
- assertNotEquals("Luniquemembernames/AnotherCls;", naming.lookupDescriptor(aa).toSourceString());
-
- DexMethod another_foo = dexItemFactory.createMethod(
- aa, dexItemFactory.createProto(dexItemFactory.intType), "foo");
- String another_foo_renamed = naming.lookupName(another_foo).toSourceString();
- assertNotEquals("foo", another_foo_renamed);
-
- // With -useuniquemembernames, foo() with the same signature should be renamed to the same name.
- assertEquals(foo_renamed, another_foo_renamed);
- // But, those cannot be renamed to c and b, as those are _globally_ reserved.
- assertNotEquals("c", foo_renamed);
- assertNotEquals("c", another_foo_renamed);
- assertNotEquals("b", foo_renamed);
- assertNotEquals("b", another_foo_renamed);
-
- DexType base = dexItemFactory.createType("Luniquemembernames/BaseCls;");
- DexField f2 = dexItemFactory.createField(base, dexItemFactory.doubleType, "f2");
- DexField another_f2 = dexItemFactory.createField(aa, dexItemFactory.intType, "f2");
- // They should renamed to the same name w/ -useuniqueclassmembernames.
- assertEquals(
- naming.lookupName(f2).toSourceString(),
- naming.lookupName(another_f2).toSourceString());
- }
-
-}
diff --git a/src/test/java/com/android/tools/r8/shaking/ProguardConfigurationParserTest.java b/src/test/java/com/android/tools/r8/shaking/ProguardConfigurationParserTest.java
index 586acad..430f263 100644
--- a/src/test/java/com/android/tools/r8/shaking/ProguardConfigurationParserTest.java
+++ b/src/test/java/com/android/tools/r8/shaking/ProguardConfigurationParserTest.java
@@ -127,8 +127,6 @@
VALID_PROGUARD_DIR + "optimizationpasses.flags";
private static final String OPTIMIZATION_PASSES_WITHOUT_N =
INVALID_PROGUARD_DIR + "optimizationpasses-without-n.flags";
- private static final String SKIP_NON_PUBLIC_LIBRARY_CLASSES =
- VALID_PROGUARD_DIR + "skipnonpubliclibraryclasses.flags";
private static final String PARSE_AND_SKIP_SINGLE_ARGUMENT =
VALID_PROGUARD_DIR + "parse-and-skip-single-argument.flags";
private static final String PRINT_USAGE =
@@ -787,7 +785,7 @@
}
@Test
- public void parseInvalidIncluding2() throws IOException {
+ public void parseInvalidIncluding2() {
Path path = Paths.get(INVALID_INCLUDING_2);
try {
new ProguardConfigurationParser(new DexItemFactory(), reporter)
@@ -799,7 +797,7 @@
}
@Test
- public void parseLibraryJars() throws Exception {
+ public void parseLibraryJars() {
ProguardConfigurationParser parser =
new ProguardConfigurationParser(new DexItemFactory(), reporter);
if (!ToolHelper.isLinux() && !ToolHelper.isMac()) {
@@ -811,7 +809,7 @@
}
@Test
- public void parseInvalidFilePattern() throws IOException {
+ public void parseInvalidFilePattern() {
try {
ProguardConfigurationParser parser =
new ProguardConfigurationParser(new DexItemFactory(), reporter);
@@ -859,7 +857,7 @@
}
@Test
- public void parseSeeds() throws Exception {
+ public void parseSeeds() {
ProguardConfigurationParser parser =
new ProguardConfigurationParser(new DexItemFactory(), reporter);
parser.parse(Paths.get(SEEDS));
@@ -870,7 +868,7 @@
}
@Test
- public void parseSeeds2() throws Exception {
+ public void parseSeeds2() {
ProguardConfigurationParser parser =
new ProguardConfigurationParser(new DexItemFactory(), reporter);
parser.parse(Paths.get(SEEDS_2));
@@ -881,7 +879,7 @@
}
@Test
- public void parseVerbose() throws Exception {
+ public void parseVerbose() {
ProguardConfigurationParser parser =
new ProguardConfigurationParser(new DexItemFactory(), reporter);
parser.parse(Paths.get(VERBOSE));
@@ -891,7 +889,7 @@
}
@Test
- public void parseKeepdirectories() throws Exception {
+ public void parseKeepdirectories() {
ProguardConfigurationParser parser =
new ProguardConfigurationParser(new DexItemFactory(), reporter, false);
parser.parse(Paths.get(KEEPDIRECTORIES));
@@ -899,7 +897,7 @@
}
@Test
- public void parseDontshrink() throws Exception {
+ public void parseDontshrink() {
ProguardConfigurationParser parser =
new ProguardConfigurationParser(new DexItemFactory(), reporter);
parser.parse(Paths.get(DONT_SHRINK));
@@ -909,7 +907,7 @@
}
@Test
- public void parseDontSkipNonPublicLibraryClasses() throws Exception {
+ public void parseDontSkipNonPublicLibraryClasses() {
ProguardConfigurationParser parser =
new ProguardConfigurationParser(new DexItemFactory(), reporter);
parser.parse(Paths.get(DONT_SKIP_NON_PUBLIC_LIBRARY_CLASSES));
@@ -917,7 +915,7 @@
}
@Test
- public void parseDontskipnonpubliclibraryclassmembers() throws Exception {
+ public void parseDontskipnonpubliclibraryclassmembers() {
ProguardConfigurationParser parser =
new ProguardConfigurationParser(new DexItemFactory(), reporter);
parser.parse(Paths.get(DONT_SKIP_NON_PUBLIC_LIBRARY_CLASS_MEMBERS));
@@ -925,7 +923,7 @@
}
@Test
- public void parseIdentifiernamestring() throws Exception {
+ public void parseIdentifiernamestring() {
ProguardConfigurationParser parser =
new ProguardConfigurationParser(new DexItemFactory(), reporter);
Path source = Paths.get(IDENTIFIER_NAME_STRING);
@@ -934,7 +932,7 @@
}
@Test
- public void parseOverloadAggressively() throws Exception {
+ public void parseOverloadAggressively() {
ProguardConfigurationParser parser =
new ProguardConfigurationParser(new DexItemFactory(), reporter);
parser.parse(Paths.get(OVERLOAD_AGGRESIVELY));
@@ -942,7 +940,7 @@
}
@Test
- public void parseDontOptimize() throws Exception {
+ public void parseDontOptimize() {
ProguardConfigurationParser parser =
new ProguardConfigurationParser(new DexItemFactory(), reporter);
parser.parse(Paths.get(DONT_OPTIMIZE));
@@ -952,7 +950,7 @@
}
@Test
- public void parseDontOptimizeOverridesPasses() throws Exception {
+ public void parseDontOptimizeOverridesPasses() {
ProguardConfigurationParser parser =
new ProguardConfigurationParser(new DexItemFactory(), reporter);
Path path = Paths.get(DONT_OPTIMIZE_OVERRIDES_PASSES);
@@ -963,7 +961,7 @@
}
@Test
- public void parseOptimizationPasses() throws Exception {
+ public void parseOptimizationPasses() {
ProguardConfigurationParser parser =
new ProguardConfigurationParser(new DexItemFactory(), reporter);
Path path = Paths.get(OPTIMIZATION_PASSES);
@@ -974,7 +972,7 @@
}
@Test
- public void parseOptimizationPassesError() throws Exception {
+ public void parseOptimizationPassesError() {
Path path = Paths.get(OPTIMIZATION_PASSES_WITHOUT_N);
try {
ProguardConfigurationParser parser =
@@ -987,21 +985,22 @@
}
@Test
- public void parseSkipNonPublicLibraryClasses() throws IOException {
- Path path = Paths.get(SKIP_NON_PUBLIC_LIBRARY_CLASSES);
+ public void parseSkipNonPublicLibraryClasses() {
+ testUnsupportedOption("-skipnonpubliclibraryclasses");
+ }
+
+ private void testUnsupportedOption(String option) {
try {
- ProguardConfigurationParser parser =
- new ProguardConfigurationParser(new DexItemFactory(), reporter);
- parser.parse(path);
- fail();
+ reset();
+ parser.parse(createConfigurationForTesting(ImmutableList.of(option)));
+ fail("Expect to fail due to unsupported option.");
} catch (AbortException e) {
- checkDiagnostics(handler.errors, path, 5, 1,
- "Unsupported option", "-skipnonpubliclibraryclasses");
+ checkDiagnostics(handler.errors, null, 1, 1, "Unsupported option", option);
}
}
@Test
- public void parseAndskipSingleArgument() throws Exception {
+ public void parseAndskipSingleArgument() {
ProguardConfigurationParser parser =
new ProguardConfigurationParser(new DexItemFactory(), reporter);
parser.parse(Paths.get(PARSE_AND_SKIP_SINGLE_ARGUMENT));
@@ -1009,7 +1008,7 @@
}
@Test
- public void parse_printconfiguration_noArguments() throws Exception {
+ public void parse_printconfiguration_noArguments() {
ProguardConfigurationParser parser =
new ProguardConfigurationParser(new DexItemFactory(), reporter);
parser.parse(createConfigurationForTesting(ImmutableList.of(
@@ -1022,7 +1021,7 @@
}
@Test
- public void parse_printconfiguration_argument() throws Exception {
+ public void parse_printconfiguration_argument() {
ProguardConfigurationParser parser =
new ProguardConfigurationParser(new DexItemFactory(), reporter);
parser.parse(createConfigurationForTesting(ImmutableList.of(
@@ -1103,7 +1102,7 @@
}
@Test
- public void parsePrintUsage() throws Exception {
+ public void parsePrintUsage() {
ProguardConfigurationParser parser =
new ProguardConfigurationParser(new DexItemFactory(), reporter);
parser.parse(Paths.get(PRINT_USAGE));
@@ -1114,7 +1113,7 @@
}
@Test
- public void parsePrintUsageToFile() throws Exception {
+ public void parsePrintUsageToFile() {
ProguardConfigurationParser parser =
new ProguardConfigurationParser(new DexItemFactory(), reporter);
parser.parse(Paths.get(PRINT_USAGE_TO_FILE));
@@ -1125,7 +1124,7 @@
}
@Test
- public void parseTarget() throws Exception {
+ public void parseTarget() {
ProguardConfigurationParser parser =
new ProguardConfigurationParser(new DexItemFactory(), reporter);
parser.parse(Paths.get(TARGET));
@@ -1276,7 +1275,7 @@
}
}
- private void testKeepattributes(List<String> expected, String config) throws Exception {
+ private void testKeepattributes(List<String> expected, String config) {
ProguardConfigurationParser parser =
new ProguardConfigurationParser(new DexItemFactory(), reporter);
parser.parse(createConfigurationForTesting(ImmutableList.of(config)));
@@ -1287,7 +1286,7 @@
}
@Test
- public void parseKeepattributes() throws Exception {
+ public void parseKeepattributes() {
List<String> xxxYYY = ImmutableList.of("xxx", "yyy");
testKeepattributes(xxxYYY, "-keepattributes xxx,yyy");
testKeepattributes(xxxYYY, "-keepattributes xxx, yyy");
@@ -1305,7 +1304,7 @@
}
@Test
- public void parseInvalidKeepattributes() throws Exception {
+ public void parseInvalidKeepattributes() {
try {
ProguardConfigurationParser parser =
new ProguardConfigurationParser(new DexItemFactory(), reporter);
@@ -1318,15 +1317,11 @@
}
@Test
- public void parseUseUniqueClassMemberNames() throws Exception {
- ProguardConfigurationParser parser =
- new ProguardConfigurationParser(new DexItemFactory(), reporter);
- parser.parse(createConfigurationForTesting(ImmutableList.of(
- "-useuniqueclassmembernames"
- )));
- verifyParserEndsCleanly();
- ProguardConfiguration config = parser.getConfig();
- assertTrue(config.isUseUniqueClassMemberNames());
+ public void parseUseUniqueClassMemberNames() throws IOException {
+ Path proguardConfig = writeTextToTempFile("-useuniqueclassmembernames");
+ new ProguardConfigurationParser(new DexItemFactory(), reporter).parse(proguardConfig);
+ checkDiagnostics(
+ handler.warnings, proguardConfig, 1, 1, "Ignoring", "-useuniqueclassmembernames");
}
@Test
@@ -2014,16 +2009,6 @@
verifyWithProguard(proguardConfig);
}
- public void testNotSupported(String option) {
- try {
- reset();
- parser.parse(createConfigurationForTesting(ImmutableList.of(option)));
- fail("Expect to fail due to unsupported option.");
- } catch (AbortException e) {
- checkDiagnostics(handler.errors, null, 1, 1, "Option " + option + " currently not supported");
- }
- }
-
private void checkRulesSourceSnippet(List<String> sourceRules) {
checkRulesSourceSnippet(sourceRules, sourceRules, false);
}
@@ -2242,7 +2227,7 @@
}
@Test
- public void pasteFlagWithFilenamesWithSystemProperty_empty() throws Exception {
+ public void pasteFlagWithFilenamesWithSystemProperty_empty() {
try {
parser.parse(createConfigurationForTesting(ImmutableList.of("-printusage <>")));
fail("Expect to fail due to the lack of file name.");
@@ -2252,7 +2237,7 @@
}
@Test
- public void pasteFlagWithFilenamesWithSystemProperty_notFound() throws Exception {
+ public void pasteFlagWithFilenamesWithSystemProperty_notFound() {
// Find a non-existent system property.
String property = "x";
while (System.getProperty(property) != null) {