blob: d42d3ada38e5aaf89b2de4e47f6e772f1fbe1923 [file] [log] [blame]
// Copyright (c) 2020, 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.shaking.enums;
import com.android.tools.r8.TestBase;
import com.android.tools.r8.TestParameters;
import com.android.tools.r8.TestParametersCollection;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
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 EnumInAnnotationTest extends TestBase {
private final TestParameters parameters;
@Parameters(name = "{0}")
public static TestParametersCollection data() {
return getTestParameters().withAllRuntimesAndApiLevels().build();
}
public EnumInAnnotationTest(TestParameters parameters) {
this.parameters = parameters;
}
@Test
public void testRuntime() throws Exception {
testForRuntime(parameters)
.addInnerClasses(EnumInAnnotationTest.class)
.run(parameters.getRuntime(), Main.class)
.assertSuccessWithOutputLines("TEST_ONE");
}
@Test
public void testR8() throws Exception {
testForR8(parameters.getBackend())
.addInnerClasses(EnumInAnnotationTest.class)
.addKeepMainRule(Main.class)
.setMinApi(parameters.getApiLevel())
.addKeepRuntimeVisibleAnnotations()
.run(parameters.getRuntime(), Main.class)
.assertSuccessWithOutputLines("TEST_ONE");
}
public enum Enum {
TEST_ONE,
TEST_TWO
}
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
public @interface MyAnnotation {
Enum value();
}
@MyAnnotation(value = Enum.TEST_ONE)
public static class Main {
public static void main(String[] args) {
System.out.println(Main.class.getAnnotation(MyAnnotation.class).value());
}
}
}