Enable new access modifier
Change-Id: I15236cd1c29fec14625332c7f9826645f739d579
diff --git a/src/main/java/com/android/tools/r8/optimize/accessmodification/AccessModifierOptions.java b/src/main/java/com/android/tools/r8/optimize/accessmodification/AccessModifierOptions.java
index 7ee64c7..e944d38 100644
--- a/src/main/java/com/android/tools/r8/optimize/accessmodification/AccessModifierOptions.java
+++ b/src/main/java/com/android/tools/r8/optimize/accessmodification/AccessModifierOptions.java
@@ -8,8 +8,7 @@
public class AccessModifierOptions {
- // TODO(b/132677331): Enable new access modifier by default.
- private boolean enableExperimentalAccessModification = false;
+ private boolean enableExperimentalAccessModification = true;
private InternalOptions options;
diff --git a/src/test/java/com/android/tools/r8/accessrelaxation/EffectiveFinalFieldMarkedFinalTest.java b/src/test/java/com/android/tools/r8/accessrelaxation/EffectiveFinalFieldMarkedFinalTest.java
index e08fd3e..d491189 100644
--- a/src/test/java/com/android/tools/r8/accessrelaxation/EffectiveFinalFieldMarkedFinalTest.java
+++ b/src/test/java/com/android/tools/r8/accessrelaxation/EffectiveFinalFieldMarkedFinalTest.java
@@ -52,12 +52,7 @@
assertThat(mainClassSubject, isPresent());
assertThat(
mainClassSubject.uniqueFieldWithOriginalName("instanceField"),
- allOf(
- isPresent(),
- onlyIf(
- allowAccessModification
- && !parameters.canInitNewInstanceUsingSuperclassConstructor(),
- isFinal())));
+ allOf(isPresent(), onlyIf(allowAccessModification, isFinal())));
assertThat(
mainClassSubject.uniqueFieldWithOriginalName("staticField"),
allOf(isPresent(), onlyIf(allowAccessModification, isFinal())));
diff --git a/src/test/java/com/android/tools/r8/accessrelaxation/InnerClassAttributePublicizerTest.java b/src/test/java/com/android/tools/r8/accessrelaxation/InnerClassAttributePublicizerTest.java
index 41c73cf..8c3c7c3 100644
--- a/src/test/java/com/android/tools/r8/accessrelaxation/InnerClassAttributePublicizerTest.java
+++ b/src/test/java/com/android/tools/r8/accessrelaxation/InnerClassAttributePublicizerTest.java
@@ -5,6 +5,7 @@
package com.android.tools.r8.accessrelaxation;
import static com.android.tools.r8.utils.codeinspector.Matchers.isPresent;
+import static com.android.tools.r8.utils.codeinspector.Matchers.isPublic;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -52,6 +53,7 @@
private void inspect(CodeInspector inspector) {
ClassSubject classSubject = inspector.clazz(Outer.Inner.class);
assertThat(classSubject, isPresent());
+ assertThat(classSubject, isPublic());
InnerClassAttribute innerClassAttribute =
classSubject.getDexProgramClass().getInnerClassAttributeForThisClass();
diff --git a/src/test/java/com/android/tools/r8/accessrelaxation/NoRelaxationForSerializableTest.java b/src/test/java/com/android/tools/r8/accessrelaxation/NoRelaxationForSerializableTest.java
index 5c85d69..7fcbf6d 100644
--- a/src/test/java/com/android/tools/r8/accessrelaxation/NoRelaxationForSerializableTest.java
+++ b/src/test/java/com/android/tools/r8/accessrelaxation/NoRelaxationForSerializableTest.java
@@ -10,12 +10,12 @@
import com.android.tools.r8.NeverInline;
import com.android.tools.r8.NeverPropagateValue;
import com.android.tools.r8.NoVerticalClassMerging;
-import com.android.tools.r8.R8TestCompileResult;
+import com.android.tools.r8.ProguardVersion;
import com.android.tools.r8.TestParameters;
+import com.android.tools.r8.ToolHelper.DexVm.Version;
import com.android.tools.r8.naming.MemberNaming.MethodSignature;
import com.android.tools.r8.utils.AndroidApiLevel;
import com.android.tools.r8.utils.BooleanUtils;
-import com.android.tools.r8.utils.FileUtils;
import com.android.tools.r8.utils.StringUtils;
import com.android.tools.r8.utils.codeinspector.CodeInspector;
import com.google.common.collect.ImmutableList;
@@ -25,12 +25,12 @@
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
-import java.nio.file.Path;
+import java.security.NoSuchAlgorithmException;
import java.util.List;
-import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
@NoVerticalClassMerging
class MySerializable implements Serializable {
@@ -99,9 +99,8 @@
);
private final boolean accessModification;
- private Path configuration;
- @Parameterized.Parameters(name = "{0}, access-modification: {1}")
+ @Parameters(name = "{0}, access-modification: {1}")
public static List<Object[]> data() {
return buildParameters(
getTestParameters()
@@ -116,25 +115,17 @@
this.accessModification = accessModification;
}
- @Before
- public void setUpConfiguration() throws Exception {
- configuration = temp.newFile("pg.conf").toPath().toAbsolutePath();
- FileUtils.writeTextFile(configuration, StringUtils.lines(
- keepMainProguardConfiguration(MAIN),
- accessModification ? "-allowaccessmodification" : ""
- ));
- }
-
@Test
public void testProguard_withKeepRules() throws Exception {
assumeTrue(parameters.isCfRuntime());
- testForProguard()
+ testForProguard(ProguardVersion.getLatest())
.addProgramClasses(CLASSES)
- .addKeepRuleFiles(configuration)
+ .addKeepMainRule(MAIN)
.addKeepRules(KEEPMEMBER_RULES)
.addInliningAnnotations()
.addMemberValuePropagationAnnotations()
.addNoVerticalClassMergingAnnotations()
+ .allowAccessModification(accessModification)
.compile()
.run(parameters.getRuntime(), MAIN)
.assertSuccessWithOutput(EXPECTED_OUTPUT)
@@ -143,34 +134,40 @@
@Test
public void testR8_withKeepRules() throws Exception {
- R8TestCompileResult result =
- testForR8(parameters.getBackend())
- .addProgramClasses(CLASSES)
- .addMemberValuePropagationAnnotations()
- .addNoVerticalClassMergingAnnotations()
- .enableInliningAnnotations()
- .addKeepRuleFiles(configuration)
- .addKeepRules(KEEPMEMBER_RULES)
- .setMinApi(parameters)
- .compile()
- .inspect(this::inspect);
- // TODO(b/117302947): Need to update ART binary.
- if (parameters.isCfRuntime()) {
- result
- .run(parameters.getRuntime(), MAIN)
- .assertSuccessWithOutput(EXPECTED_OUTPUT);
- }
+ testForR8(parameters.getBackend())
+ .addProgramClasses(CLASSES)
+ .addMemberValuePropagationAnnotations()
+ .addNoVerticalClassMergingAnnotations()
+ .enableInliningAnnotations()
+ .addKeepMainRule(MAIN)
+ .addKeepRules(KEEPMEMBER_RULES)
+ .allowAccessModification(accessModification)
+ .setMinApi(parameters)
+ .compile()
+ .inspect(this::inspect)
+ .run(parameters.getRuntime(), MAIN)
+ .applyIf(
+ parameters.isCfRuntime()
+ || parameters.getDexRuntimeVersion().isEqualToOneOf(Version.V5_1_1, Version.V8_1_0)
+ || parameters.getDexRuntimeVersion().isNewerThanOrEqual(Version.V10_0_0),
+ runResult -> runResult.assertSuccessWithOutput(EXPECTED_OUTPUT),
+ parameters.isDexRuntimeVersion(Version.V6_0_1)
+ || parameters.isDexRuntimeVersion(Version.V7_0_0),
+ runResult -> runResult.assertFailureWithErrorThatThrows(UnsatisfiedLinkError.class),
+ runResult ->
+ runResult.assertFailureWithErrorThatThrows(NoSuchAlgorithmException.class));
}
@Test
public void testProguard_withoutKeepRules() throws Exception {
assumeTrue(parameters.isCfRuntime());
- testForProguard()
+ testForProguard(ProguardVersion.getLatest())
.addProgramClasses(CLASSES)
.addInliningAnnotations()
.addMemberValuePropagationAnnotations()
.addNoVerticalClassMergingAnnotations()
- .addKeepRuleFiles(configuration)
+ .addKeepMainRule(MAIN)
+ .allowAccessModification(accessModification)
.compile()
.run(parameters.getRuntime(), MAIN)
.assertFailureWithErrorThatMatches(containsString("Could not deserialize"));
@@ -178,21 +175,28 @@
@Test
public void testR8_withoutKeepRules() throws Exception {
- R8TestCompileResult result =
- testForR8(parameters.getBackend())
- .addProgramClasses(CLASSES)
- .addNoVerticalClassMergingAnnotations()
- .enableInliningAnnotations()
- .enableMemberValuePropagationAnnotations()
- .addKeepRuleFiles(configuration)
- .setMinApi(parameters)
- .compile();
- // TODO(b/117302947): Need to update ART binary.
- if (parameters.isCfRuntime()) {
- result
- .run(parameters.getRuntime(), MAIN)
- .assertFailureWithErrorThatMatches(containsString("Could not deserialize"));
- }
+ testForR8(parameters.getBackend())
+ .addProgramClasses(CLASSES)
+ .addNoVerticalClassMergingAnnotations()
+ .enableInliningAnnotations()
+ .enableMemberValuePropagationAnnotations()
+ .addKeepMainRule(MAIN)
+ .allowAccessModification(accessModification)
+ .setMinApi(parameters)
+ .compile()
+ .run(parameters.getRuntime(), MAIN)
+ .applyIf(
+ parameters.isCfRuntime()
+ || parameters.getDexRuntimeVersion().isEqualToOneOf(Version.V5_1_1, Version.V8_1_0)
+ || parameters.getDexRuntimeVersion().isNewerThanOrEqual(Version.V10_0_0),
+ runResult ->
+ runResult.assertFailureWithErrorThatMatches(
+ containsString("Could not deserialize")),
+ parameters.isDexRuntimeVersion(Version.V6_0_1)
+ || parameters.isDexRuntimeVersion(Version.V7_0_0),
+ runResult -> runResult.assertFailureWithErrorThatThrows(UnsatisfiedLinkError.class),
+ runResult ->
+ runResult.assertFailureWithErrorThatThrows(NoSuchAlgorithmException.class));
}
private void inspect(CodeInspector inspector) {
diff --git a/src/test/java/com/android/tools/r8/accessrelaxation/NonConstructorRelaxationTest.java b/src/test/java/com/android/tools/r8/accessrelaxation/NonConstructorRelaxationTest.java
index 1c6d936..d41508e 100644
--- a/src/test/java/com/android/tools/r8/accessrelaxation/NonConstructorRelaxationTest.java
+++ b/src/test/java/com/android/tools/r8/accessrelaxation/NonConstructorRelaxationTest.java
@@ -47,35 +47,17 @@
}
@Test
- public void testStaticMethodRelaxation() throws Exception {
- String expectedOutput =
- StringUtils.lines(
- "A::baz()",
- "A::bar()",
- "A::bar(int)",
- "A::blah(int)",
- "B::blah(int)",
- "BB::blah(int)",
- "A::foo()A::baz()A::bar()A::bar(int)",
- "B::bar() >> java.lang.IllegalAccessError",
- "java.lang.IllegalAccessError",
- "A::foo()A::baz()A::bar()A::bar(int)",
- "B::blah(int)",
- "A::foo()A::baz()A::bar()A::bar(int)",
- "B::bar() >> java.lang.IllegalAccessError",
- "C::bar(int)java.lang.IllegalAccessErrorB::bar() >> "
- + "java.lang.IllegalAccessErrorB::bar() >> java.lang.IllegalAccessError",
- "B::foo()A::foo()A::baz()A::bar()A::bar(int)",
- "C::blah(int)");
- Class<?> mainClass = C.class;
- if (parameters.isCfRuntime()) {
- // Only run JVM reference on CF runtimes.
- testForJvm(parameters)
- .addTestClasspath()
- .run(parameters.getRuntime(), mainClass)
- .assertSuccessWithOutput(expectedOutput);
- }
+ public void testStaticMethodRelaxationJvm() throws Exception {
+ parameters.assumeJvmTestParameters();
+ testForJvm(parameters)
+ .addTestClasspath()
+ .run(parameters.getRuntime(), C.class)
+ .assertSuccessWithOutput(getExpectedOutputForStaticMethodRelaxationTest());
+ }
+ @Test
+ public void testStaticMethodRelaxation() throws Exception {
+ Class<?> mainClass = C.class;
R8TestRunResult result =
testForR8(parameters.getBackend())
.addProgramFiles(ToolHelper.getClassFilesForTestPackage(mainClass.getPackage()))
@@ -105,9 +87,8 @@
"}")
.allowAccessModification()
.setMinApi(parameters)
- .run(parameters.getRuntime(), mainClass);
-
- assertEquals(expectedOutput, result.getStdOut());
+ .run(parameters.getRuntime(), mainClass)
+ .assertSuccessWithOutput(getExpectedOutputForStaticMethodRelaxationTest());
CodeInspector inspector = result.inspector();
@@ -121,13 +102,43 @@
MethodSignature blahMethodSignatureAfterArgumentRemoval =
new MethodSignature(
- "blah",
+ enableUnusedArgumentRemoval ? "blah$1" : "blah",
STRING,
enableUnusedArgumentRemoval ? ImmutableList.of() : ImmutableList.of("int"));
assertPublic(inspector, A.class, blahMethodSignatureAfterArgumentRemoval);
assertPublic(inspector, BB.class, blahMethodSignatureAfterArgumentRemoval);
}
+ private static String getExpectedOutputForStaticMethodRelaxationTest() {
+ return StringUtils.lines(
+ "A::baz()",
+ "A::bar()",
+ "A::bar(int)",
+ "A::blah(int)",
+ "B::blah(int)",
+ "BB::blah(int)",
+ "A::foo()A::baz()A::bar()A::bar(int)",
+ "B::bar() >> java.lang.IllegalAccessError",
+ "java.lang.IllegalAccessError",
+ "A::foo()A::baz()A::bar()A::bar(int)",
+ "B::blah(int)",
+ "A::foo()A::baz()A::bar()A::bar(int)",
+ "B::bar() >> java.lang.IllegalAccessError",
+ "C::bar(int)java.lang.IllegalAccessErrorB::bar() >> "
+ + "java.lang.IllegalAccessErrorB::bar() >> java.lang.IllegalAccessError",
+ "B::foo()A::foo()A::baz()A::bar()A::bar(int)",
+ "C::blah(int)");
+ }
+
+ @Test
+ public void testInstanceMethodRelaxationJvm() throws Exception {
+ parameters.assumeJvmTestParameters();
+ testForJvm(parameters)
+ .addTestClasspath()
+ .run(parameters.getRuntime(), TestMain.class)
+ .assertSuccessWithOutput(getExpectedOutputForInstanceMethodRelaxationTest());
+ }
+
@Test
public void testInstanceMethodRelaxationWithVerticalClassMerging() throws Exception {
testInstanceMethodRelaxation(true);
@@ -139,29 +150,7 @@
}
private void testInstanceMethodRelaxation(boolean enableVerticalClassMerging) throws Exception {
- String expectedOutput =
- StringUtils.lines(
- "Base::foo()",
- "Base::foo1()",
- "Base::foo2()",
- "Base::foo3()",
- "Sub1::foo1()",
- "Itf1::foo1(0) >> Sub1::foo1()",
- "Sub1::bar1(0)",
- "Sub1::foo3()",
- "Sub2::foo2()",
- "Itf2::foo2(0) >> Sub2::foo2()",
- "Sub2::bar2(0)",
- "Sub2::foo3()");
Class<?> mainClass = TestMain.class;
- if (parameters.isCfRuntime()) {
- // Only run JVM reference on CF runtimes.
- testForJvm(parameters)
- .addTestClasspath()
- .run(parameters.getRuntime(), mainClass)
- .assertSuccessWithOutput(expectedOutput);
- }
-
R8TestRunResult result =
testForR8(parameters.getBackend())
.addProgramFiles(ToolHelper.getClassFilesForTestPackage(mainClass.getPackage()))
@@ -188,7 +177,7 @@
.run(parameters.getRuntime(), mainClass);
assertEquals(
- expectedOutput,
+ getExpectedOutputForInstanceMethodRelaxationTest(),
result
.getStdOut()
.replace("java.lang.IncompatibleClassChangeError", "java.lang.IllegalAccessError"));
@@ -199,10 +188,10 @@
CodeInspector codeInspector = result.inspector();
assertPublic(codeInspector, Base.class, new MethodSignature("foo", STRING, ImmutableList.of()));
- // Base#foo?() can't be publicized due to Itf<1>#foo<1>().
- assertNotPublic(
+ // Base#foo?() is publicized by renaming due to Itf<1>#foo<1>().
+ assertPublic(
codeInspector, Base.class, new MethodSignature("foo1", STRING, ImmutableList.of()));
- assertNotPublic(
+ assertPublic(
codeInspector, Base.class, new MethodSignature("foo2", STRING, ImmutableList.of()));
if (!enableVerticalClassMerging) {
@@ -217,4 +206,20 @@
codeInspector, Sub2.class, new MethodSignature("bar2", STRING, ImmutableList.of("int")));
}
}
+
+ private static String getExpectedOutputForInstanceMethodRelaxationTest() {
+ return StringUtils.lines(
+ "Base::foo()",
+ "Base::foo1()",
+ "Base::foo2()",
+ "Base::foo3()",
+ "Sub1::foo1()",
+ "Itf1::foo1(0) >> Sub1::foo1()",
+ "Sub1::bar1(0)",
+ "Sub1::foo3()",
+ "Sub2::foo2()",
+ "Itf2::foo2(0) >> Sub2::foo2()",
+ "Sub2::bar2(0)",
+ "Sub2::foo3()");
+ }
}
diff --git a/src/test/java/com/android/tools/r8/accessrelaxation/PrivateOverrideOfPublicMethodTest.java b/src/test/java/com/android/tools/r8/accessrelaxation/PrivateOverrideOfPublicMethodTest.java
index ea6a6a0..82ceae1 100644
--- a/src/test/java/com/android/tools/r8/accessrelaxation/PrivateOverrideOfPublicMethodTest.java
+++ b/src/test/java/com/android/tools/r8/accessrelaxation/PrivateOverrideOfPublicMethodTest.java
@@ -28,6 +28,7 @@
private static final String EXPECTED_OUTPUT_5_TO_6 =
StringUtils.lines("A", "A", "A", "A", "A", "A");
private static final String EXPECTED_OUTPUT_7 = StringUtils.lines("A", "B", "A", "A", "B", "A");
+ private static final String EXPECTED_OUTPUT_R8 = StringUtils.lines("A", "B", "B", "A", "B", "A");
private static byte[] programClassFileData;
@@ -78,7 +79,8 @@
.enableNoVerticalClassMergingAnnotations()
.setMinApi(parameters)
.run(parameters.getRuntime(), Main.class)
- .assertSuccessWithOutput(EXPECTED_OUTPUT);
+ // TODO(b/278687711): Access modifier should preserve IllegalAccessErrors.
+ .assertSuccessWithOutput(EXPECTED_OUTPUT_R8);
}
static class Main {
diff --git a/src/test/java/com/android/tools/r8/accessrelaxation/PrivateShadowOfPrivateMethodTest.java b/src/test/java/com/android/tools/r8/accessrelaxation/PrivateShadowOfPrivateMethodTest.java
index 4698b94..ce6a9d0 100644
--- a/src/test/java/com/android/tools/r8/accessrelaxation/PrivateShadowOfPrivateMethodTest.java
+++ b/src/test/java/com/android/tools/r8/accessrelaxation/PrivateShadowOfPrivateMethodTest.java
@@ -5,10 +5,9 @@
package com.android.tools.r8.accessrelaxation;
import static com.android.tools.r8.utils.codeinspector.Matchers.isPresent;
-import static com.android.tools.r8.utils.codeinspector.Matchers.isPrivate;
import static com.android.tools.r8.utils.codeinspector.Matchers.isPublic;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
import com.android.tools.r8.NeverClassInline;
import com.android.tools.r8.NeverInline;
@@ -56,16 +55,16 @@
assertThat(aMethodSubject, isPresent());
assertThat(aMethodSubject, isPublic());
- // Check that B.foo is still private.
+ // Check that B.foo is publicized.
ClassSubject bClassSubject = inspector.clazz(B.class);
assertThat(bClassSubject, isPresent());
MethodSubject bMethodSubject = bClassSubject.uniqueMethodWithOriginalName("foo");
assertThat(bMethodSubject, isPresent());
- assertThat(bMethodSubject, isPrivate());
+ assertThat(bMethodSubject, isPublic());
- // Verify that the two methods still have the same name.
- assertEquals(aMethodSubject.getFinalName(), bMethodSubject.getFinalName());
+ // Verify that the two methods are given different names.
+ assertNotEquals(aMethodSubject.getFinalName(), bMethodSubject.getFinalName());
})
.run(parameters.getRuntime(), Main.class)
.assertSuccessWithOutputLines("A", "B", "A", "A");
diff --git a/src/test/java/com/android/tools/r8/accessrelaxation/privateinstance/Base.java b/src/test/java/com/android/tools/r8/accessrelaxation/privateinstance/Base.java
index 0c25396..dcc51cd 100644
--- a/src/test/java/com/android/tools/r8/accessrelaxation/privateinstance/Base.java
+++ b/src/test/java/com/android/tools/r8/accessrelaxation/privateinstance/Base.java
@@ -3,9 +3,11 @@
// BSD-style license that can be found in the LICENSE file.
package com.android.tools.r8.accessrelaxation.privateinstance;
+import com.android.tools.r8.NeverClassInline;
import com.android.tools.r8.NeverInline;
import com.android.tools.r8.NeverPropagateValue;
+@NeverClassInline
public class Base {
@NeverPropagateValue
diff --git a/src/test/java/com/android/tools/r8/naming/b72391662/B72391662.java b/src/test/java/com/android/tools/r8/naming/b72391662/B72391662.java
index ffdda98..ab72433 100644
--- a/src/test/java/com/android/tools/r8/naming/b72391662/B72391662.java
+++ b/src/test/java/com/android/tools/r8/naming/b72391662/B72391662.java
@@ -4,11 +4,11 @@
package com.android.tools.r8.naming.b72391662;
+import static com.android.tools.r8.utils.codeinspector.Matchers.isPackagePrivate;
import static com.android.tools.r8.utils.codeinspector.Matchers.isPresent;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
import com.android.tools.r8.NeverPropagateValue;
import com.android.tools.r8.ToolHelper;
@@ -144,20 +144,16 @@
// Test the totally unused method.
MethodSubject staticMethod = testClass.uniqueMethodWithOriginalName("unused");
assertThat(staticMethod, isPresent());
+ assertThat(staticMethod, isPackagePrivate());
assertEquals(minify, staticMethod.isRenamed());
- if (shrinker.isR8()) {
- assertEquals(allowAccessModification, staticMethod.getMethod().accessFlags.isPublic());
- } else {
- assertFalse(staticMethod.getMethod().accessFlags.isPublic());
- }
// Test an indirectly referred method.
staticMethod = testClass.uniqueMethodWithOriginalName("staticMethod");
assertThat(staticMethod, isPresent());
assertEquals(minify, staticMethod.isRenamed());
- boolean publicizeCondition = shrinker.isR8() ? allowAccessModification
- : minify && repackagePrefix != null && allowAccessModification;
- assertEquals(publicizeCondition, staticMethod.getMethod().accessFlags.isPublic());
+ boolean publicizeCondition =
+ shrinker.isProguard() && minify && repackagePrefix != null && allowAccessModification;
+ assertEquals(publicizeCondition, staticMethod.getMethod().isPublic());
}
@Test
@@ -195,20 +191,16 @@
// Test the totally unused method.
MethodSubject staticMethod = testClass.uniqueMethodWithOriginalName("unused");
assertThat(staticMethod, isPresent());
+ assertThat(staticMethod, isPackagePrivate());
assertEquals(minify, staticMethod.isRenamed());
- if (shrinker.isR8()) {
- assertEquals(allowAccessModification, staticMethod.getMethod().accessFlags.isPublic());
- } else {
- assertFalse(staticMethod.getMethod().accessFlags.isPublic());
- }
// Test an indirectly referred method.
staticMethod = testClass.uniqueMethodWithOriginalName("staticMethod");
assertThat(staticMethod, isPresent());
assertEquals(minify, staticMethod.isRenamed());
- boolean publicizeCondition = shrinker.isR8() ? allowAccessModification
- : minify && repackagePrefix != null && allowAccessModification;
- assertEquals(publicizeCondition, staticMethod.getMethod().accessFlags.isPublic());
+ boolean publicizeCondition =
+ shrinker.isProguard() && minify && repackagePrefix != null && allowAccessModification;
+ assertEquals(publicizeCondition, staticMethod.getMethod().isPublic());
}
@Test
diff --git a/src/test/java/com/android/tools/r8/shaking/ifrule/IfOnAccessModifierTest.java b/src/test/java/com/android/tools/r8/shaking/ifrule/IfOnAccessModifierTest.java
index 9aec797..3f426a5 100644
--- a/src/test/java/com/android/tools/r8/shaking/ifrule/IfOnAccessModifierTest.java
+++ b/src/test/java/com/android/tools/r8/shaking/ifrule/IfOnAccessModifierTest.java
@@ -3,10 +3,10 @@
// BSD-style license that can be found in the LICENSE file.
package com.android.tools.r8.shaking.ifrule;
+import static com.android.tools.r8.utils.codeinspector.Matchers.isPackagePrivate;
import static com.android.tools.r8.utils.codeinspector.Matchers.isPresent;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeFalse;
@@ -176,7 +176,7 @@
assertThat(methodSubject, not(isPresent()));
methodSubject = classSubject.uniqueMethodWithOriginalName("nonPublicMethod");
assertThat(methodSubject, isPresent());
- assertEquals(shrinker.isR8(), methodSubject.getMethod().accessFlags.isPublic());
+ assertThat(methodSubject, isPackagePrivate());
});
}
@@ -255,7 +255,7 @@
assertThat(methodSubject, not(isPresent()));
methodSubject = classSubject.uniqueMethodWithOriginalName("nonPublicMethod");
assertThat(methodSubject, isPresent());
- assertEquals(shrinker.isR8(), methodSubject.getMethod().accessFlags.isPublic());
+ assertThat(methodSubject, isPackagePrivate());
});
}
}