diff options
author | Yohann Roussel <yroussel@google.com> | 2014-03-19 16:25:37 +0100 |
---|---|---|
committer | Yohann Roussel <yroussel@google.com> | 2014-03-20 15:13:33 +0100 |
commit | 4eceb95409e844fdc33c9c706e1dc307bfd40303 (patch) | |
tree | ee9f4f3fc79f757c79081c336bce4f1782c6ccd8 /jack-tests/tests/com/android/jack/annotation | |
parent | 3d2402901b1a6462e2cf47a6fd09711f327961c3 (diff) | |
download | toolchain_jack-4eceb95409e844fdc33c9c706e1dc307bfd40303.zip toolchain_jack-4eceb95409e844fdc33c9c706e1dc307bfd40303.tar.gz toolchain_jack-4eceb95409e844fdc33c9c706e1dc307bfd40303.tar.bz2 |
Initial Jack import.
Change-Id: I953cf0a520195a7187d791b2885848ad0d5a9b43
Diffstat (limited to 'jack-tests/tests/com/android/jack/annotation')
49 files changed, 1967 insertions, 0 deletions
diff --git a/jack-tests/tests/com/android/jack/annotation/test001/dx/Tests.java b/jack-tests/tests/com/android/jack/annotation/test001/dx/Tests.java new file mode 100644 index 0000000..f5fe544 --- /dev/null +++ b/jack-tests/tests/com/android/jack/annotation/test001/dx/Tests.java @@ -0,0 +1,238 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.annotation.test001.dx; + +import com.android.jack.annotation.test001.jack.Annotated1; +import com.android.jack.annotation.test001.jack.Annotated2; +import com.android.jack.annotation.test001.jack.Annotated3; +import com.android.jack.annotation.test001.jack.Annotated4; +import com.android.jack.annotation.test001.jack.Annotated5; +import com.android.jack.annotation.test001.jack.Annotation1; +import com.android.jack.annotation.test001.jack.Annotation10; +import com.android.jack.annotation.test001.jack.Annotation11; +import com.android.jack.annotation.test001.jack.Annotation12; +import com.android.jack.annotation.test001.jack.Annotation13; +import com.android.jack.annotation.test001.jack.Annotation14; +import com.android.jack.annotation.test001.jack.Annotation2; +import com.android.jack.annotation.test001.jack.Annotation3; +import com.android.jack.annotation.test001.jack.Annotation4; +import com.android.jack.annotation.test001.jack.Annotation5; +import com.android.jack.annotation.test001.jack.Annotation6; +import com.android.jack.annotation.test001.jack.Annotation7; +import com.android.jack.annotation.test001.jack.Annotation8; +import com.android.jack.annotation.test001.jack.Annotation9; + +import org.junit.Assert; +import org.junit.Ignore; +import org.junit.Test; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Field; +import java.lang.reflect.Method; + +public class Tests { + + @Test + public void test1() { + Class<Annotation1> annotation1 = Annotation1.class; + Assert.assertTrue(annotation1.isAnnotation()); + Field[] declaredFields = annotation1.getDeclaredFields(); + Assert.assertEquals(0, declaredFields.length); + Method[] declaredMethods = annotation1.getDeclaredMethods(); + Assert.assertEquals(0, declaredMethods.length); + Assert.assertNull(annotation1.getSuperclass()); + Assert.assertEquals(1, annotation1.getInterfaces().length); + Assert.assertEquals(Annotation.class, annotation1.getInterfaces()[0]); + } + @Test + public void test2() { + Class<Annotation2> annotation2 = Annotation2.class; + Assert.assertTrue(annotation2.isAnnotation()); + Field[] declaredFields = annotation2.getDeclaredFields(); + Assert.assertEquals(0, declaredFields.length); + Method[] declaredMethods = annotation2.getDeclaredMethods(); + Assert.assertEquals(1, declaredMethods.length); + Method value = declaredMethods[0]; + Assert.assertEquals("value", value.getName()); + Assert.assertEquals(0, value.getParameterTypes().length); + Assert.assertEquals(Integer.TYPE, value.getReturnType()); + + + Assert.assertNull(annotation2.getSuperclass()); + Assert.assertEquals(1, annotation2.getInterfaces().length); + Assert.assertEquals(Annotation.class, annotation2.getInterfaces()[0]); + } + + @Test + public void test3() { + Class<Annotation2> annotation1 = Annotation2.class; + + Method[] declaredMethods = annotation1.getDeclaredMethods(); + Method value = declaredMethods[0]; + Assert.assertEquals(Integer.valueOf(6), value.getDefaultValue()); + } + @Test + public void test4() { + Class<Annotation3> annotation3 = Annotation3.class; + Assert.assertTrue(annotation3.isAnnotation()); + Field[] declaredFields = annotation3.getDeclaredFields(); + Assert.assertEquals(0, declaredFields.length); + Method[] declaredMethods = annotation3.getDeclaredMethods(); + Assert.assertEquals(2, declaredMethods.length); + for (Method method : declaredMethods) { + if ("annotationValue1".equals(method.getName())) { + Assert.assertEquals(Annotation1.class, method.getReturnType()); + Assert.assertNull(method.getDefaultValue()); + } else { + Assert.assertEquals(Annotation2.class, method.getReturnType()); + Assert.assertEquals("annotationValue2", method.getName()); + } + } + + Assert.assertNull(annotation3.getSuperclass()); + Assert.assertEquals(1, annotation3.getInterfaces().length); + Assert.assertEquals(Annotation.class, annotation3.getInterfaces()[0]); + } + + @Test + public void test5() { + Class<Annotation3> annotation3 = Annotation3.class; + Method[] declaredMethods = annotation3.getDeclaredMethods(); + for (Method method : declaredMethods) { + if ("annotationValue1".equals(method.getName())) { + // checked in test4 + } else { + Assert.assertTrue(method.getDefaultValue() instanceof Annotation2); + } + } + } + + @Test + public void test6() { + printAllAnnotations(Annotation1.class); + printAllAnnotations(Annotation2.class); + printAllAnnotations(Annotation3.class); + printAllAnnotations(Annotation4.class); + printAllAnnotations(Annotation5.class); + printAllAnnotations(Annotation6.class); + printAllAnnotations(Annotation7.class); + printAllAnnotations(Annotation8.class); + printAllAnnotations(Annotation9.class); + printAllAnnotations(Annotation10.class); + printAllAnnotations(Annotation11.class); + printAllAnnotations(Annotation12.class); + printAllAnnotations(Annotation13.class); + printAllAnnotations(Annotation14.class); + printAllAnnotations(Annotated2.class); + printAllAnnotations(Annotated3.class); + printAllAnnotations(Annotated1.class); + printAllAnnotations(Annotated4.class); + + } + + @Test + public void test7() { + Class<Annotated4> annotated = Annotated4.class; + Annotation11 annotation = annotated.getAnnotation(Annotation11.class); + Assert.assertEquals(void.class, annotation.value()); + } + + @Test + public void test8() { + Class<Annotated5> annotated = Annotated5.class; + Annotation12 annotation = annotated.getAnnotation(Annotation12.class); + Assert.assertTrue(annotation.value()); + } + + @Test + public void test9() { + printAnnotation(Annotation1.class); + printAnnotation(Annotation2.class); + printAnnotation(Annotation3.class); + printAnnotation(Annotation4.class); + printAnnotation(Annotation5.class); + printAnnotation(Annotation6.class); + printAnnotation(Annotation7.class); + printAnnotation(Annotation8.class); + printAnnotation(Annotation9.class); + printAnnotation(Annotation10.class); + printAnnotation(Annotation11.class); + printAnnotation(Annotation12.class); + printAnnotation(Annotation13.class); + printAnnotation(Annotation14.class); + } + + private static void printAllAnnotations(Class<?> clazz) { + printAnnotations(clazz.getAnnotations()); + System.out.println("class " + clazz.getName() + " {"); + System.out.println(); + + for (Field field : clazz.getDeclaredFields()) { + printAnnotations(field.getAnnotations()); + System.out.println(" " + field.getType() + " " + field.getName() + ";"); + System.out.println(); + } + + for (Method method : clazz.getDeclaredMethods()) { + printAnnotations(method.getAnnotations()); + System.out.print(" " + method.getReturnType() + " " + method.getName() + "("); + Annotation[][] parameterAnnotations = method.getParameterAnnotations(); + Class<?>[] parameterTypes = method.getParameterTypes(); + for (int i = 0; i < parameterTypes.length; i++) { + printAnnotations(parameterAnnotations[i]); + System.out.print(parameterTypes[i] + " arg" + i); + if (i < parameterTypes.length - 1) { + System.out.print(", "); + } + } + System.out.print(")"); + if (method.getDefaultValue() != null) { + System.out.print(" = " + method.getDefaultValue()); + } + System.out.println(); + System.out.println(); + } + System.out.println("}"); + } + + private static void printAnnotation(Class<?> annotationClass) { + System.out.println("@interface " + annotationClass.getName() + " {"); + + for (Method method : annotationClass.getDeclaredMethods()) { + System.out.print(" " + method.getReturnType() + " " + method.getName()); + Object defaultValue = method.getDefaultValue(); + if (defaultValue != null) { + System.out.print(" default " + defaultValue); + } + System.out.println(";"); + } + System.out.println("}"); + + } + + private static void printAnnotations(Annotation[] annotations) { + for (Annotation annotation : annotations) { + printAnnotation(annotation); + } + } + /** + * @param annotation + */ + private static void printAnnotation(Annotation annotation) { + System.out.println(annotation); + } +} diff --git a/jack-tests/tests/com/android/jack/annotation/test001/jack/Annotated1.java b/jack-tests/tests/com/android/jack/annotation/test001/jack/Annotated1.java new file mode 100644 index 0000000..1fc4fc2 --- /dev/null +++ b/jack-tests/tests/com/android/jack/annotation/test001/jack/Annotated1.java @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.annotation.test001.jack; + +@Annotation9(OneEnum.C) +@Annotation7(Annotation1.class) +@Annotation1 +@Annotation2 +@Annotation3(annotationValue1 = @Annotation1) +@Annotation4 +@Annotation5 +@Annotation6(annotationValue1 = {@Annotation1, @Annotation1, @Annotation1()}, +annotationValue2 = {@Annotation2(1), @Annotation2(5), @Annotation2(Constants.C3), @Annotation2}) +@Annotation8({1, 2 ,4 , (byte) 255}) +public class Annotated1 { + + @Annotation1 + private int field; + + @Deprecated + public void method() { + + } + + public int method2(int a, @Annotation1 int b) { + @Annotation5 + int result = 0; + for (@Annotation4 int i = 0; i < 3; i++) { + result ++; + } + + new Runnable() { + + @Override + public void run() { + } + }; + return result; + } + + @Annotation1 + private static class Annotated2 { + + @Annotation1 + private int field; + + @Deprecated + public void method() { + + } + + public int method2(int a, @Annotation1 int b) { + @Annotation5 + int result = 0; + for (@Annotation4 int i = 0; i < 3; i++) { + result ++; + } + return result; + } + } + + @Annotation11(int.class) + public void method3() { + + } +} diff --git a/jack-tests/tests/com/android/jack/annotation/test001/jack/Annotated2.java b/jack-tests/tests/com/android/jack/annotation/test001/jack/Annotated2.java new file mode 100644 index 0000000..f6e2d55 --- /dev/null +++ b/jack-tests/tests/com/android/jack/annotation/test001/jack/Annotated2.java @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.annotation.test001.jack; + +@Annotation8({1, 2 ,4 , (byte) 255}) +public class Annotated2 { +} diff --git a/jack-tests/tests/com/android/jack/annotation/test001/jack/Annotated3.java b/jack-tests/tests/com/android/jack/annotation/test001/jack/Annotated3.java new file mode 100644 index 0000000..c485d0a --- /dev/null +++ b/jack-tests/tests/com/android/jack/annotation/test001/jack/Annotated3.java @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.annotation.test001.jack; + +@Annotation7(String.class) +public class Annotated3 { +} diff --git a/jack-tests/tests/com/android/jack/annotation/test001/jack/Annotated4.java b/jack-tests/tests/com/android/jack/annotation/test001/jack/Annotated4.java new file mode 100644 index 0000000..aff7236 --- /dev/null +++ b/jack-tests/tests/com/android/jack/annotation/test001/jack/Annotated4.java @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.annotation.test001.jack; + +@Annotation11(void.class) +public class Annotated4 { +} diff --git a/jack-tests/tests/com/android/jack/annotation/test001/jack/Annotated5.java b/jack-tests/tests/com/android/jack/annotation/test001/jack/Annotated5.java new file mode 100644 index 0000000..d28f71e --- /dev/null +++ b/jack-tests/tests/com/android/jack/annotation/test001/jack/Annotated5.java @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.annotation.test001.jack; + +@Annotation12(true) +public class Annotated5 { +} diff --git a/jack-tests/tests/com/android/jack/annotation/test001/jack/Annotation1.java b/jack-tests/tests/com/android/jack/annotation/test001/jack/Annotation1.java new file mode 100644 index 0000000..8bb6f5e --- /dev/null +++ b/jack-tests/tests/com/android/jack/annotation/test001/jack/Annotation1.java @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.annotation.test001.jack; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) +public @interface Annotation1 { + +} diff --git a/jack-tests/tests/com/android/jack/annotation/test001/jack/Annotation10.java b/jack-tests/tests/com/android/jack/annotation/test001/jack/Annotation10.java new file mode 100644 index 0000000..ea8556e --- /dev/null +++ b/jack-tests/tests/com/android/jack/annotation/test001/jack/Annotation10.java @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.annotation.test001.jack; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) +public @interface Annotation10 { + long[] value() default {1, 2, ' ', (byte) 4}; + float[] v2() default {1, 2, 3.0f, (byte)4, 'e'}; + double[] v3() default {1, 2.4, 3.0f, (byte)4, 'e'}; +} diff --git a/jack-tests/tests/com/android/jack/annotation/test001/jack/Annotation11.java b/jack-tests/tests/com/android/jack/annotation/test001/jack/Annotation11.java new file mode 100644 index 0000000..e4a9a13 --- /dev/null +++ b/jack-tests/tests/com/android/jack/annotation/test001/jack/Annotation11.java @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.annotation.test001.jack; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) +public @interface Annotation11 { + Class<?> value() default int.class; +} diff --git a/jack-tests/tests/com/android/jack/annotation/test001/jack/Annotation12.java b/jack-tests/tests/com/android/jack/annotation/test001/jack/Annotation12.java new file mode 100644 index 0000000..781e9ab --- /dev/null +++ b/jack-tests/tests/com/android/jack/annotation/test001/jack/Annotation12.java @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.annotation.test001.jack; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) +public @interface Annotation12 { + boolean value() default false; +} diff --git a/jack-tests/tests/com/android/jack/annotation/test001/jack/Annotation13.java b/jack-tests/tests/com/android/jack/annotation/test001/jack/Annotation13.java new file mode 100644 index 0000000..db8b9c1 --- /dev/null +++ b/jack-tests/tests/com/android/jack/annotation/test001/jack/Annotation13.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.annotation.test001.jack; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) +public @interface Annotation13 { + byte value1() default 1; + char value2() default 0x32; + char value3() default '3'; + short value4() default 4; +} diff --git a/jack-tests/tests/com/android/jack/annotation/test001/jack/Annotation14.java b/jack-tests/tests/com/android/jack/annotation/test001/jack/Annotation14.java new file mode 100644 index 0000000..5f59366 --- /dev/null +++ b/jack-tests/tests/com/android/jack/annotation/test001/jack/Annotation14.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.annotation.test001.jack; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) +public @interface Annotation14 { + byte[] value1() default 1; + char[] value2() default 0x32; + char[] value3() default '3'; + short[] value4() default 4; +} diff --git a/jack-tests/tests/com/android/jack/annotation/test001/jack/Annotation2.java b/jack-tests/tests/com/android/jack/annotation/test001/jack/Annotation2.java new file mode 100644 index 0000000..f6c3d4a --- /dev/null +++ b/jack-tests/tests/com/android/jack/annotation/test001/jack/Annotation2.java @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.annotation.test001.jack; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) +public @interface Annotation2 { + int value() default 1 + 5; + +} diff --git a/jack-tests/tests/com/android/jack/annotation/test001/jack/Annotation3.java b/jack-tests/tests/com/android/jack/annotation/test001/jack/Annotation3.java new file mode 100644 index 0000000..b8b33b4 --- /dev/null +++ b/jack-tests/tests/com/android/jack/annotation/test001/jack/Annotation3.java @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.annotation.test001.jack; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) +public @interface Annotation3 { + + Annotation1 annotationValue1(); + Annotation2 annotationValue2() default @Annotation2; +} diff --git a/jack-tests/tests/com/android/jack/annotation/test001/jack/Annotation4.java b/jack-tests/tests/com/android/jack/annotation/test001/jack/Annotation4.java new file mode 100644 index 0000000..c4afbdd --- /dev/null +++ b/jack-tests/tests/com/android/jack/annotation/test001/jack/Annotation4.java @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.annotation.test001.jack; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.CLASS) +public @interface Annotation4 { + +} diff --git a/jack-tests/tests/com/android/jack/annotation/test001/jack/Annotation5.java b/jack-tests/tests/com/android/jack/annotation/test001/jack/Annotation5.java new file mode 100644 index 0000000..22fdf9f --- /dev/null +++ b/jack-tests/tests/com/android/jack/annotation/test001/jack/Annotation5.java @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.annotation.test001.jack; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.SOURCE) +public @interface Annotation5 { + +} diff --git a/jack-tests/tests/com/android/jack/annotation/test001/jack/Annotation6.java b/jack-tests/tests/com/android/jack/annotation/test001/jack/Annotation6.java new file mode 100644 index 0000000..edf3e3c --- /dev/null +++ b/jack-tests/tests/com/android/jack/annotation/test001/jack/Annotation6.java @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.annotation.test001.jack; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) +public @interface Annotation6 { + + Annotation1[] annotationValue1() default {}; + Annotation2[] annotationValue2() default {@Annotation2, @Annotation2(1)}; +} diff --git a/jack-tests/tests/com/android/jack/annotation/test001/jack/Annotation7.java b/jack-tests/tests/com/android/jack/annotation/test001/jack/Annotation7.java new file mode 100644 index 0000000..ce255d3 --- /dev/null +++ b/jack-tests/tests/com/android/jack/annotation/test001/jack/Annotation7.java @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.annotation.test001.jack; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) +public @interface Annotation7 { + Class<?>[] value() default Object.class; +} diff --git a/jack-tests/tests/com/android/jack/annotation/test001/jack/Annotation8.java b/jack-tests/tests/com/android/jack/annotation/test001/jack/Annotation8.java new file mode 100644 index 0000000..aff4cbb --- /dev/null +++ b/jack-tests/tests/com/android/jack/annotation/test001/jack/Annotation8.java @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.annotation.test001.jack; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) +public @interface Annotation8 { + byte[] value() default {1, 2, 3, 4}; +} diff --git a/jack-tests/tests/com/android/jack/annotation/test001/jack/Annotation9.java b/jack-tests/tests/com/android/jack/annotation/test001/jack/Annotation9.java new file mode 100644 index 0000000..f6f1235 --- /dev/null +++ b/jack-tests/tests/com/android/jack/annotation/test001/jack/Annotation9.java @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.annotation.test001.jack; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) +public @interface Annotation9 { + OneEnum value() default OneEnum.B; +} diff --git a/jack-tests/tests/com/android/jack/annotation/test001/jack/Constants.java b/jack-tests/tests/com/android/jack/annotation/test001/jack/Constants.java new file mode 100644 index 0000000..053dd18 --- /dev/null +++ b/jack-tests/tests/com/android/jack/annotation/test001/jack/Constants.java @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.annotation.test001.jack; + +public class Constants { + + public static final int C1 = 0; + public static final int C2 = C1 + 2; + public static final int C3 = C1 + C2; + public static final int C4 = 14; + +} diff --git a/jack-tests/tests/com/android/jack/annotation/test001/jack/OneEnum.java b/jack-tests/tests/com/android/jack/annotation/test001/jack/OneEnum.java new file mode 100644 index 0000000..2045827 --- /dev/null +++ b/jack-tests/tests/com/android/jack/annotation/test001/jack/OneEnum.java @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.annotation.test001.jack; + +public enum OneEnum { + A, B, C, D; + +} diff --git a/jack-tests/tests/com/android/jack/annotation/test002/dx/Tests.java b/jack-tests/tests/com/android/jack/annotation/test002/dx/Tests.java new file mode 100644 index 0000000..f70c4e9 --- /dev/null +++ b/jack-tests/tests/com/android/jack/annotation/test002/dx/Tests.java @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.annotation.test002.dx; + +import com.android.jack.annotation.test002.jack.Annotated; + +import junit.framework.Assert; + +import org.junit.Test; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + + +public class Tests { + + @Test + public void test1() { + Class<Annotated> annotated = Annotated.class; + Retention retention = annotated.getAnnotation(Retention.class); + Assert.assertNotNull(retention); + Assert.assertEquals(RetentionPolicy.CLASS, retention.value()); + } +} diff --git a/jack-tests/tests/com/android/jack/annotation/test002/jack/Annotated.java b/jack-tests/tests/com/android/jack/annotation/test002/jack/Annotated.java new file mode 100644 index 0000000..1d2f5e3 --- /dev/null +++ b/jack-tests/tests/com/android/jack/annotation/test002/jack/Annotated.java @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.annotation.test002.jack; + +import static java.lang.annotation.RetentionPolicy.CLASS; + +import java.lang.annotation.Retention; + +@Retention(CLASS) +public @interface Annotated { + +} diff --git a/jack-tests/tests/com/android/jack/annotation/test003/dx/Tests.java b/jack-tests/tests/com/android/jack/annotation/test003/dx/Tests.java new file mode 100644 index 0000000..1aaf63c --- /dev/null +++ b/jack-tests/tests/com/android/jack/annotation/test003/dx/Tests.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.annotation.test003.dx; + +import junit.framework.Assert; + +import org.junit.Test; + +import com.android.jack.annotation.test003.jack.Target; + + +public class Tests { + + @Test + public void test1() { + Class<Target> annotated = Target.class; + Assert.assertTrue(annotated.isInterface()); + } +} diff --git a/jack-tests/tests/com/android/jack/annotation/test003/jack/Target.java b/jack-tests/tests/com/android/jack/annotation/test003/jack/Target.java new file mode 100644 index 0000000..e6af2ed --- /dev/null +++ b/jack-tests/tests/com/android/jack/annotation/test003/jack/Target.java @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.annotation.test003.jack; + +import java.lang.annotation.ElementType; + +@Target(ElementType.ANNOTATION_TYPE) +public @interface Target { + ElementType[] value(); +} diff --git a/jack-tests/tests/com/android/jack/annotation/test004/jack/Data.java b/jack-tests/tests/com/android/jack/annotation/test004/jack/Data.java new file mode 100644 index 0000000..72d176c --- /dev/null +++ b/jack-tests/tests/com/android/jack/annotation/test004/jack/Data.java @@ -0,0 +1,31 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.annotation.test004.jack; + + + +@SuppressWarnings("") +final class Data<E extends Enum<E>> { + + @SuppressWarnings("") + public E f; + + @SuppressWarnings("") + public static <E extends Enum<E>> E get() { + return null; + } +} diff --git a/jack-tests/tests/com/android/jack/annotation/test005/dx/Tests.java b/jack-tests/tests/com/android/jack/annotation/test005/dx/Tests.java new file mode 100644 index 0000000..50ee60b --- /dev/null +++ b/jack-tests/tests/com/android/jack/annotation/test005/dx/Tests.java @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.annotation.test005.dx; + +import com.android.jack.annotation.test005.jack.PackageAnnotation; + +import junit.framework.Assert; + +import org.junit.Ignore; +import org.junit.Test; + + +public class Tests { + + @Test + public void refTest001() { + checkPackage(com.android.jack.annotation.test005.dx.sub.Dummy.class.getPackage()); + checkPackage("com.android.jack.annotation005.dx.sub"); + } + + @Test + @Ignore("An empty package is not \"observable\"") + public void refTest002() { + checkPackage("com.android.jack.annotation005.dx.empty"); + } + + @Test + public void test001() { + checkPackage(com.android.jack.annotation.test005.jack.sub.Dummy.class.getPackage()); + checkPackage("com.android.jack.annotation005.jack.sub"); + } + + @Test + @Ignore("An empty package is not \"observable\"") + public void test002() { + checkPackage("com.android.jack.annotation005.jack.empty"); + } + + void checkPackage(String packageName) { + Package empty = Package.getPackage(packageName); + checkPackage(empty); + } + + void checkPackage(Package empty) { + PackageAnnotation annotation = empty.getAnnotation(PackageAnnotation.class); + Assert.assertNotNull(annotation); + } +} diff --git a/jack-tests/tests/com/android/jack/annotation/test005/dx/empty/package-info.java b/jack-tests/tests/com/android/jack/annotation/test005/dx/empty/package-info.java new file mode 100644 index 0000000..21ee4b7 --- /dev/null +++ b/jack-tests/tests/com/android/jack/annotation/test005/dx/empty/package-info.java @@ -0,0 +1,3 @@ +@com.android.jack.annotation.test005.jack.PackageAnnotation +package com.android.jack.annotation.test005.dx.empty; + diff --git a/jack-tests/tests/com/android/jack/annotation/test005/dx/sub/Dummy.java b/jack-tests/tests/com/android/jack/annotation/test005/dx/sub/Dummy.java new file mode 100644 index 0000000..c6e5fa4 --- /dev/null +++ b/jack-tests/tests/com/android/jack/annotation/test005/dx/sub/Dummy.java @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.annotation.test005.dx.sub; + +public class Dummy { + +} diff --git a/jack-tests/tests/com/android/jack/annotation/test005/dx/sub/package-info.java b/jack-tests/tests/com/android/jack/annotation/test005/dx/sub/package-info.java new file mode 100644 index 0000000..c771ba8 --- /dev/null +++ b/jack-tests/tests/com/android/jack/annotation/test005/dx/sub/package-info.java @@ -0,0 +1,3 @@ +@com.android.jack.annotation.test005.jack.PackageAnnotation +package com.android.jack.annotation.test005.dx.sub; + diff --git a/jack-tests/tests/com/android/jack/annotation/test005/jack/PackageAnnotation.java b/jack-tests/tests/com/android/jack/annotation/test005/jack/PackageAnnotation.java new file mode 100644 index 0000000..2c452e1 --- /dev/null +++ b/jack-tests/tests/com/android/jack/annotation/test005/jack/PackageAnnotation.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.annotation.test005.jack; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.PACKAGE) +@Retention(RetentionPolicy.RUNTIME) +public @interface PackageAnnotation { + +} diff --git a/jack-tests/tests/com/android/jack/annotation/test005/jack/empty/package-info.java b/jack-tests/tests/com/android/jack/annotation/test005/jack/empty/package-info.java new file mode 100644 index 0000000..be99454 --- /dev/null +++ b/jack-tests/tests/com/android/jack/annotation/test005/jack/empty/package-info.java @@ -0,0 +1,3 @@ +@com.android.jack.annotation.test005.jack.PackageAnnotation +package com.android.jack.annotation.test005.jack.empty; + diff --git a/jack-tests/tests/com/android/jack/annotation/test005/jack/sub/Dummy.java b/jack-tests/tests/com/android/jack/annotation/test005/jack/sub/Dummy.java new file mode 100644 index 0000000..39d4083 --- /dev/null +++ b/jack-tests/tests/com/android/jack/annotation/test005/jack/sub/Dummy.java @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.annotation.test005.jack.sub; + +public class Dummy { + +} diff --git a/jack-tests/tests/com/android/jack/annotation/test005/jack/sub/package-info.java b/jack-tests/tests/com/android/jack/annotation/test005/jack/sub/package-info.java new file mode 100644 index 0000000..45ca2c8 --- /dev/null +++ b/jack-tests/tests/com/android/jack/annotation/test005/jack/sub/package-info.java @@ -0,0 +1,3 @@ +@com.android.jack.annotation.test005.jack.PackageAnnotation +package com.android.jack.annotation.test005.jack.sub; + diff --git a/jack-tests/tests/com/android/jack/annotation/test006/dx/Tests.java b/jack-tests/tests/com/android/jack/annotation/test006/dx/Tests.java new file mode 100644 index 0000000..60309bb --- /dev/null +++ b/jack-tests/tests/com/android/jack/annotation/test006/dx/Tests.java @@ -0,0 +1,328 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.annotation.test006.dx; + + + +import com.android.jack.annotation.test006.jack.ReflectAnnotationsTest; +import com.android.jack.annotation.test006.jack.ReflectAnnotationsTest2; + +import org.junit.Assert; +import org.junit.Test; + +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Type; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + + +public class Tests { + + @Test + public void test001() { + ReflectAnnotationsTest test = new ReflectAnnotationsTest(); + Class<?> testClass = test.getClass(); + + Assert.assertEquals("com.android.jack.annotation.test006.jack.ReflectAnnotationsTest", testClass.getName()); + Assert.assertEquals("com.android.jack.annotation.test006.jack.ReflectAnnotationsTest", testClass.getCanonicalName()); + Assert.assertEquals("ReflectAnnotationsTest", testClass.getSimpleName()); + Assert.assertEquals("class java.lang.Object", testClass.getSuperclass().toString()); + Assert.assertEquals("class java.lang.Object", testClass.getGenericSuperclass().toString()); + Assert.assertNull(testClass.getDeclaringClass()); + Assert.assertNull(testClass.getEnclosingClass()); + Assert.assertNull(testClass.getEnclosingConstructor()); + Assert.assertNull(testClass.getEnclosingMethod()); + Assert.assertEquals(testClass.getModifiers(), 1); + Assert.assertEquals("package com.android.jack.annotation.test006.jack", testClass.getPackage().toString()); + String declaredClasses = stringifyTypeArray(testClass.getDeclaredClasses()); + boolean testDeclaredClasses = declaredClasses.contains("[2]"); + testDeclaredClasses = testDeclaredClasses && declaredClasses.contains("class com.android.jack.annotation.test006.jack.ReflectAnnotationsTest$InnerClass"); + testDeclaredClasses = testDeclaredClasses && declaredClasses.contains("class com.android.jack.annotation.test006.jack.ReflectAnnotationsTest$InnerClassStatic"); + Assert.assertTrue(testDeclaredClasses); + String memberClasses = stringifyTypeArray(testClass.getClasses()); + boolean memberClassesTest = memberClasses.contains("[2]"); + memberClassesTest = memberClassesTest && memberClasses.contains("class com.android.jack.annotation.test006.jack.ReflectAnnotationsTest$InnerClass"); + memberClassesTest = memberClassesTest && memberClasses.contains("class com.android.jack.annotation.test006.jack.ReflectAnnotationsTest$InnerClassStatic"); + Assert.assertTrue(memberClassesTest); + Assert.assertFalse(testClass.isAnnotation()); + Assert.assertFalse(testClass.isAnonymousClass()); + Assert.assertFalse(testClass.isArray()); + Assert.assertFalse(testClass.isEnum()); + Assert.assertFalse(testClass.isInterface()); + Assert.assertFalse(testClass.isLocalClass()); + Assert.assertFalse(testClass.isMemberClass()); + Assert.assertFalse(testClass.isPrimitive()); + Assert.assertFalse(testClass.isSynthetic()); + Assert.assertEquals("[0]", stringifyTypeArray(testClass.getGenericInterfaces())); + Assert.assertEquals("[0]", stringifyTypeArray(testClass.getTypeParameters())); + + + testClass = test.getLocal(3).getClass(); + + Assert.assertEquals("com.android.jack.annotation.test006.jack.ReflectAnnotationsTest$1C", testClass.getName()); + Assert.assertNull(testClass.getCanonicalName()); + Assert.assertEquals("C", testClass.getSimpleName()); + Assert.assertEquals("class java.lang.Object", testClass.getSuperclass().toString()); + Assert.assertEquals("class java.lang.Object", testClass.getGenericSuperclass().toString()); + Assert.assertNull(testClass.getDeclaringClass()); + Assert.assertEquals("class com.android.jack.annotation.test006.jack.ReflectAnnotationsTest", testClass.getEnclosingClass().toString()); + Assert.assertNull(testClass.getEnclosingConstructor()); + Assert.assertEquals("public java.lang.Object com.android.jack.annotation.test006.jack.ReflectAnnotationsTest.getLocal(int)", testClass.getEnclosingMethod().toString()); + Assert.assertEquals(testClass.getModifiers(), 0); + Assert.assertEquals("package com.android.jack.annotation.test006.jack", testClass.getPackage().toString()); + Assert.assertEquals("[0]", stringifyTypeArray(testClass.getDeclaredClasses())); + Assert.assertEquals("[0]", stringifyTypeArray(testClass.getClasses())); + Assert.assertFalse(testClass.isAnnotation()); + Assert.assertFalse(testClass.isAnonymousClass()); + Assert.assertFalse(testClass.isArray()); + Assert.assertFalse(testClass.isEnum()); + Assert.assertFalse(testClass.isInterface()); + Assert.assertTrue(testClass.isLocalClass()); + Assert.assertFalse(testClass.isMemberClass()); + Assert.assertFalse(testClass.isPrimitive()); + Assert.assertFalse(testClass.isSynthetic()); + Assert.assertEquals("[0]", stringifyTypeArray(testClass.getGenericInterfaces())); + Assert.assertEquals("[0]", stringifyTypeArray(testClass.getTypeParameters())); + + + testClass = test.new InnerClass().getClass(); + + Assert.assertEquals("com.android.jack.annotation.test006.jack.ReflectAnnotationsTest$InnerClass", testClass.getName()); + Assert.assertEquals("com.android.jack.annotation.test006.jack.ReflectAnnotationsTest.InnerClass", testClass.getCanonicalName()); + Assert.assertEquals("InnerClass", testClass.getSimpleName()); + Assert.assertEquals("class java.lang.Object", testClass.getSuperclass().toString()); + Assert.assertEquals("class java.lang.Object", testClass.getGenericSuperclass().toString()); + Assert.assertEquals("class com.android.jack.annotation.test006.jack.ReflectAnnotationsTest", testClass.getDeclaringClass().toString()); + Assert.assertEquals("class com.android.jack.annotation.test006.jack.ReflectAnnotationsTest", testClass.getEnclosingClass().toString()); + Assert.assertNull(testClass.getEnclosingConstructor()); + Assert.assertNull(testClass.getEnclosingMethod()); + Assert.assertEquals(testClass.getModifiers(), 1); + Assert.assertEquals("package com.android.jack.annotation.test006.jack", testClass.getPackage().toString()); + Assert.assertEquals("[0]", stringifyTypeArray(testClass.getDeclaredClasses())); + Assert.assertEquals("[0]", stringifyTypeArray(testClass.getClasses())); + Assert.assertFalse(testClass.isAnnotation()); + Assert.assertFalse(testClass.isAnonymousClass()); + Assert.assertFalse(testClass.isArray()); + Assert.assertFalse(testClass.isEnum()); + Assert.assertFalse(testClass.isInterface()); + Assert.assertFalse(testClass.isLocalClass()); + Assert.assertTrue(testClass.isMemberClass()); + Assert.assertFalse(testClass.isPrimitive()); + Assert.assertFalse(testClass.isSynthetic()); + Assert.assertEquals("[0]", stringifyTypeArray(testClass.getGenericInterfaces())); + Assert.assertEquals("[0]", stringifyTypeArray(testClass.getTypeParameters())); + + // --- static inner with inheritance --- + testClass = new ReflectAnnotationsTest.InnerClassStatic().getClass(); + + Assert.assertEquals("com.android.jack.annotation.test006.jack.ReflectAnnotationsTest$InnerClassStatic", testClass.getName()); + Assert.assertEquals("com.android.jack.annotation.test006.jack.ReflectAnnotationsTest.InnerClassStatic", testClass.getCanonicalName()); + Assert.assertEquals("InnerClassStatic", testClass.getSimpleName()); + Assert.assertEquals("class com.android.jack.annotation.test006.jack.SuperClass", testClass.getSuperclass().toString()); + Assert.assertEquals("class com.android.jack.annotation.test006.jack.SuperClass", testClass.getGenericSuperclass().toString()); + Assert.assertEquals("class com.android.jack.annotation.test006.jack.ReflectAnnotationsTest", testClass.getDeclaringClass().toString()); + Assert.assertEquals("class com.android.jack.annotation.test006.jack.ReflectAnnotationsTest", testClass.getEnclosingClass().toString()); + Assert.assertNull(testClass.getEnclosingConstructor()); + Assert.assertNull(testClass.getEnclosingMethod()); + Assert.assertEquals(testClass.getModifiers(), 9); + Assert.assertEquals("package com.android.jack.annotation.test006.jack", testClass.getPackage().toString()); + Assert.assertEquals("[0]", stringifyTypeArray(testClass.getDeclaredClasses())); + Assert.assertEquals("[0]", stringifyTypeArray(testClass.getClasses())); + Assert.assertFalse(testClass.isAnnotation()); + Assert.assertFalse(testClass.isAnonymousClass()); + Assert.assertFalse(testClass.isArray()); + Assert.assertFalse(testClass.isEnum()); + Assert.assertFalse(testClass.isInterface()); + Assert.assertFalse(testClass.isLocalClass()); + Assert.assertTrue(testClass.isMemberClass()); + Assert.assertFalse(testClass.isPrimitive()); + Assert.assertFalse(testClass.isSynthetic()); + String genInterfaces = stringifyTypeArray(testClass.getGenericInterfaces()); + boolean testGenInterfaces = genInterfaces.contains("[2]"); + testGenInterfaces = testGenInterfaces && genInterfaces.contains("com.android.jack.annotation.test006.jack.SuperInterface1"); + testGenInterfaces = testGenInterfaces && genInterfaces.contains("com.android.jack.annotation.test006.jack.SuperInterface2"); + Assert.assertTrue(testGenInterfaces); + Assert.assertEquals("[0]", stringifyTypeArray(testClass.getTypeParameters())); + } + + @Test + public void test002() { + Class<?> testClass = ReflectAnnotationsTest2.class; + + Assert.assertEquals("com.android.jack.annotation.test006.jack.ReflectAnnotationsTest2", testClass.getName()); + Assert.assertEquals("com.android.jack.annotation.test006.jack.ReflectAnnotationsTest2", testClass.getCanonicalName()); + Assert.assertEquals("ReflectAnnotationsTest2", testClass.getSimpleName()); + Assert.assertEquals("class java.lang.Object", testClass.getSuperclass().toString()); + Assert.assertEquals("class java.lang.Object", testClass.getGenericSuperclass().toString()); + Assert.assertNull(testClass.getDeclaringClass()); + Assert.assertNull(testClass.getEnclosingClass()); + Assert.assertNull(testClass.getEnclosingConstructor()); + Assert.assertNull(testClass.getEnclosingMethod()); + Assert.assertEquals(testClass.getModifiers(), 1); + Assert.assertEquals("package com.android.jack.annotation.test006.jack", testClass.getPackage().toString()); + String declaredClasses = stringifyTypeArray(testClass.getDeclaredClasses()); + boolean testDeclared = declaredClasses.contains("[2]"); + testDeclared = testDeclared && declaredClasses.contains("com.android.jack.annotation.test006.jack.ReflectAnnotationsTest2$Generic2"); + testDeclared = testDeclared && declaredClasses.contains("com.android.jack.annotation.test006.jack.ReflectAnnotationsTest2$Generic1"); + Assert.assertTrue(testDeclared); + Assert.assertEquals("[0]", stringifyTypeArray(testClass.getClasses())); + Assert.assertFalse(testClass.isAnnotation()); + Assert.assertFalse(testClass.isAnonymousClass()); + Assert.assertFalse(testClass.isArray()); + Assert.assertFalse(testClass.isEnum()); + Assert.assertFalse(testClass.isInterface()); + Assert.assertFalse(testClass.isLocalClass()); + Assert.assertFalse(testClass.isMemberClass()); + Assert.assertFalse(testClass.isPrimitive()); + Assert.assertFalse(testClass.isSynthetic()); + Assert.assertEquals("[0]", stringifyTypeArray(testClass.getGenericInterfaces())); + Assert.assertEquals("[0]", stringifyTypeArray(testClass.getTypeParameters())); + + + ReflectAnnotationsTest2 test = new ReflectAnnotationsTest2(); + testClass = test.consInnerNamed.getClass(); + + Assert.assertEquals("com.android.jack.annotation.test006.jack.ReflectAnnotationsTest2$1ConsInnerNamed", testClass.getName()); + Assert.assertNull(testClass.getCanonicalName()); + Assert.assertEquals("ConsInnerNamed", testClass.getSimpleName()); + Assert.assertEquals("class java.lang.Object", testClass.getSuperclass().toString()); + Assert.assertEquals("class java.lang.Object", testClass.getGenericSuperclass().toString()); + Assert.assertNull(testClass.getDeclaringClass()); + Assert.assertEquals("class com.android.jack.annotation.test006.jack.ReflectAnnotationsTest2", testClass.getEnclosingClass().toString()); + Assert.assertEquals("public com.android.jack.annotation.test006.jack.ReflectAnnotationsTest2()", testClass.getEnclosingConstructor().toString()); + Assert.assertNull(testClass.getEnclosingMethod()); + Assert.assertEquals(testClass.getModifiers(), 0); + Assert.assertEquals("package com.android.jack.annotation.test006.jack", testClass.getPackage().toString()); + Assert.assertEquals("[0]", stringifyTypeArray(testClass.getDeclaredClasses())); + Assert.assertEquals("[0]", stringifyTypeArray(testClass.getClasses())); + Assert.assertFalse(testClass.isAnnotation()); + Assert.assertFalse(testClass.isAnonymousClass()); + Assert.assertFalse(testClass.isArray()); + Assert.assertFalse(testClass.isEnum()); + Assert.assertFalse(testClass.isInterface()); + Assert.assertTrue(testClass.isLocalClass()); + Assert.assertFalse(testClass.isMemberClass()); + Assert.assertFalse(testClass.isPrimitive()); + Assert.assertFalse(testClass.isSynthetic()); + Assert.assertEquals("[0]", stringifyTypeArray(testClass.getGenericInterfaces())); + Assert.assertEquals("[0]", stringifyTypeArray(testClass.getTypeParameters())); + + Object gen = test.getGeneric(); + testClass = gen.getClass(); + + Assert.assertEquals("com.android.jack.annotation.test006.jack.ReflectAnnotationsTest2$Generic2", testClass.getName()); + Assert.assertEquals("com.android.jack.annotation.test006.jack.ReflectAnnotationsTest2.Generic2", testClass.getCanonicalName()); + Assert.assertEquals("Generic2", testClass.getSimpleName()); + Assert.assertEquals("class com.android.jack.annotation.test006.jack.ReflectAnnotationsTest2$Generic1", testClass.getSuperclass().toString()); + Assert.assertEquals("com.android.jack.annotation.test006.jack.ReflectAnnotationsTest2$Generic1<K, java.lang.String>", testClass.getGenericSuperclass().toString()); + Assert.assertEquals("class com.android.jack.annotation.test006.jack.ReflectAnnotationsTest2", testClass.getDeclaringClass().toString()); + Assert.assertEquals("class com.android.jack.annotation.test006.jack.ReflectAnnotationsTest2", testClass.getEnclosingClass().toString()); + Assert.assertNull(testClass.getEnclosingConstructor()); + Assert.assertNull(testClass.getEnclosingMethod()); + Assert.assertEquals(testClass.getModifiers(), 2); + Assert.assertEquals("package com.android.jack.annotation.test006.jack", testClass.getPackage().toString()); + Assert.assertEquals("[0]", stringifyTypeArray(testClass.getDeclaredClasses())); + String memberClasses = stringifyTypeArray(testClass.getClasses()); + boolean testMemberClasses = memberClasses.contains("java.util.AbstractMap$SimpleEntry"); + testMemberClasses = testMemberClasses && memberClasses.contains("java.util.AbstractMap$SimpleImmutableEntry"); + Assert.assertTrue(testMemberClasses); + Assert.assertFalse(testClass.isAnnotation()); + Assert.assertFalse(testClass.isAnonymousClass()); + Assert.assertFalse(testClass.isArray()); + Assert.assertFalse(testClass.isEnum()); + Assert.assertFalse(testClass.isInterface()); + Assert.assertFalse(testClass.isLocalClass()); + Assert.assertTrue(testClass.isMemberClass()); + Assert.assertFalse(testClass.isPrimitive()); + Assert.assertFalse(testClass.isSynthetic()); + Assert.assertEquals("[0]", stringifyTypeArray(testClass.getGenericInterfaces())); + String typeParameters = stringifyTypeArray(testClass.getTypeParameters()); + boolean testTypeParameters = typeParameters.contains("[1]"); + testTypeParameters = testTypeParameters && typeParameters.contains("K"); + Assert.assertTrue(testTypeParameters); + + + Method meth; + try { + meth = ReflectAnnotationsTest2.class.getMethod("foo", (Class[]) null); + Assert.assertNull(getSignature(meth)); + + Field field; + field = ReflectAnnotationsTest2.class.getField("consInnerNamed"); + Assert.assertNull(getSignature(field)); + + meth = ReflectAnnotationsTest2.class.getMethod("getGeneric", (Class[]) null); + Assert.assertEquals("()Lcom/android/jack/annotation/test006/jack/ReflectAnnotationsTest2$Generic2<Ljava/lang/String;>;", getSignature(meth)); + Class<?>[] exceptions = meth.getExceptionTypes(); + Assert.assertTrue(exceptions.length == 2); + List<Class<?>> exceptionsList = Arrays.asList(exceptions); + Assert.assertTrue(exceptionsList.contains(OutOfMemoryError.class)); + Assert.assertTrue(exceptionsList.contains(AssertionError.class)); + + field = ReflectAnnotationsTest2.class.getField("genField"); + Assert.assertEquals("Ljava/util/List<Ljava/lang/String;>;", getSignature(field)); + + } catch (SecurityException e) { + System.out.println(e.getMessage()); + } catch (NoSuchMethodException e) { + System.out.println(e.getMessage()); + } catch (NoSuchFieldException e) { + System.out.println(e.getMessage()); + } + } + + private static String getSignature(Object obj) { + Method method; + try { + Class<? extends Object> c = obj.getClass(); + method = c.getDeclaredMethod("getSignatureAttribute"); + method.setAccessible(true); + } catch (Exception ex) { + throw new RuntimeException(ex); + } + + try { + return (String) method.invoke(obj); + } catch (IllegalAccessException ex) { + throw new RuntimeException(ex); + } catch (InvocationTargetException ex) { + throw new RuntimeException(ex); + } + } + + private static String stringifyTypeArray(Type[] types) { + StringBuilder stb = new StringBuilder(); + boolean first = true; + + stb.append("[" + types.length + "]"); + + for (Type t: types) { + if (first) { + stb.append(" "); + first = false; + } else { + stb.append(", "); + } + stb.append(t.toString()); + } + + return stb.toString(); + } +} diff --git a/jack-tests/tests/com/android/jack/annotation/test006/jack/ReflectAnnotationsTest.java b/jack-tests/tests/com/android/jack/annotation/test006/jack/ReflectAnnotationsTest.java new file mode 100644 index 0000000..2ea4c25 --- /dev/null +++ b/jack-tests/tests/com/android/jack/annotation/test006/jack/ReflectAnnotationsTest.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.annotation.test006.jack; + + + +import java.io.Serializable; +import java.util.List; + +public class ReflectAnnotationsTest { + + public Object getLocal(int i) { + class C {} + C c = new C(); + return c; + } + + public class InnerClass { + void f(List<String> l) throws OutOfMemoryError, AssertionError{ + + } + } + + public static class InnerClassStatic extends SuperClass + implements SuperInterface1, SuperInterface2 { + } + +} diff --git a/jack-tests/tests/com/android/jack/annotation/test006/jack/ReflectAnnotationsTest2.java b/jack-tests/tests/com/android/jack/annotation/test006/jack/ReflectAnnotationsTest2.java new file mode 100644 index 0000000..9b65f2f --- /dev/null +++ b/jack-tests/tests/com/android/jack/annotation/test006/jack/ReflectAnnotationsTest2.java @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.annotation.test006.jack; + + + + + + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class ReflectAnnotationsTest2 { + + public Object consInnerNamed; + public List<String> genField; + + public ReflectAnnotationsTest2() { + /* local, not anonymous, not member */ + class ConsInnerNamed { + public void m() { + } + } + consInnerNamed = new ConsInnerNamed(); + } + + public void foo() { + /* anonymous, not local, not member */ + SuperInterface1 c = new SuperInterface1() { + SuperClass f = new SuperClass(); + }; + } + + public Generic2<String> getGeneric() throws OutOfMemoryError, AssertionError{ + return new Generic2<String>(); + } + + public void genMeht(List<String> l){} + + abstract class Generic1<K, V> extends HashMap<K,V> implements Map<K,V> {} + private class Generic2<K> extends Generic1<K, String> {} + +} diff --git a/jack-tests/tests/com/android/jack/annotation/test006/jack/SuperClass.java b/jack-tests/tests/com/android/jack/annotation/test006/jack/SuperClass.java new file mode 100644 index 0000000..8eee54d --- /dev/null +++ b/jack-tests/tests/com/android/jack/annotation/test006/jack/SuperClass.java @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.annotation.test006.jack; + +public class SuperClass { +} diff --git a/jack-tests/tests/com/android/jack/annotation/test006/jack/SuperInterface1.java b/jack-tests/tests/com/android/jack/annotation/test006/jack/SuperInterface1.java new file mode 100644 index 0000000..50a8783 --- /dev/null +++ b/jack-tests/tests/com/android/jack/annotation/test006/jack/SuperInterface1.java @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.annotation.test006.jack; + +public interface SuperInterface1 { + +} diff --git a/jack-tests/tests/com/android/jack/annotation/test006/jack/SuperInterface2.java b/jack-tests/tests/com/android/jack/annotation/test006/jack/SuperInterface2.java new file mode 100644 index 0000000..eb96c17 --- /dev/null +++ b/jack-tests/tests/com/android/jack/annotation/test006/jack/SuperInterface2.java @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.annotation.test006.jack; + +public interface SuperInterface2 { + +} diff --git a/jack-tests/tests/com/android/jack/annotation/test007/dx/Tests.java b/jack-tests/tests/com/android/jack/annotation/test007/dx/Tests.java new file mode 100644 index 0000000..a5af72e --- /dev/null +++ b/jack-tests/tests/com/android/jack/annotation/test007/dx/Tests.java @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.annotation.test007.dx; + +import com.android.jack.annotation.test007.jack.Thrower; + +import junit.framework.Assert; + +import org.junit.Test; + +import java.io.IOException; +import java.lang.reflect.Constructor; +import java.lang.reflect.Type; +import java.util.Arrays; + +public class Tests { + + @Test + public void testGenericExceptionsOfConstructorsWithTypeParameters() throws Exception { + Constructor constructor = Thrower.class.getConstructor(); + Assert.assertEquals(Arrays.<Type>asList(IOException.class), + Arrays.asList(constructor.getGenericExceptionTypes())); + } + +} diff --git a/jack-tests/tests/com/android/jack/annotation/test007/jack/Thrower.java b/jack-tests/tests/com/android/jack/annotation/test007/jack/Thrower.java new file mode 100644 index 0000000..af755f5 --- /dev/null +++ b/jack-tests/tests/com/android/jack/annotation/test007/jack/Thrower.java @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.annotation.test007.jack; + +import java.io.IOException; + +public class Thrower { + public Thrower() throws IOException {} +} diff --git a/jack-tests/tests/com/android/jack/annotation/test008/dx/Ref008.java b/jack-tests/tests/com/android/jack/annotation/test008/dx/Ref008.java new file mode 100644 index 0000000..187161d --- /dev/null +++ b/jack-tests/tests/com/android/jack/annotation/test008/dx/Ref008.java @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.annotation.test008.dx; + +public class Ref008 { + + public static Class<?> getAnonymousClass() { + return new Object() { + }.getClass(); + } + + public static Object anonymousClass2 = new Object() {}; +} diff --git a/jack-tests/tests/com/android/jack/annotation/test008/dx/Tests.java b/jack-tests/tests/com/android/jack/annotation/test008/dx/Tests.java new file mode 100644 index 0000000..62bc6db --- /dev/null +++ b/jack-tests/tests/com/android/jack/annotation/test008/dx/Tests.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.annotation.test008.dx; + +import com.android.jack.annotation.test008.jack.Annotation008; + +import junit.framework.Assert; + +import org.junit.Test; + +import java.lang.reflect.Modifier; + +public class Tests { + @Test + public void testref001() throws Exception { + Class<?> anonymousClass = Ref008.getAnonymousClass(); + Assert.assertTrue(anonymousClass.isAnonymousClass()); + Assert.assertFalse(Modifier.isFinal(anonymousClass.getModifiers())); + } + @Test + public void test001() throws Exception { + Class<?> anonymousClass = Annotation008.getAnonymousClass1(); + Assert.assertTrue(anonymousClass.isAnonymousClass()); + Assert.assertFalse(Modifier.isFinal(anonymousClass.getModifiers())); + } + @Test + public void testref002() throws Exception { + Class<?> anonymousClass = Ref008.anonymousClass2.getClass(); + Assert.assertTrue(anonymousClass.isAnonymousClass()); + Assert.assertFalse(Modifier.isFinal(anonymousClass.getModifiers())); + } + @Test + public void test002() throws Exception { + Class<?> anonymousClass = Annotation008.anonymousClass2.getClass(); + Assert.assertTrue(anonymousClass.isAnonymousClass()); + Assert.assertFalse(Modifier.isFinal(anonymousClass.getModifiers())); + } + +} diff --git a/jack-tests/tests/com/android/jack/annotation/test008/jack/Annotation008.java b/jack-tests/tests/com/android/jack/annotation/test008/jack/Annotation008.java new file mode 100644 index 0000000..0176f75 --- /dev/null +++ b/jack-tests/tests/com/android/jack/annotation/test008/jack/Annotation008.java @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.annotation.test008.jack; + +public class Annotation008 { + + public static Class<?> getAnonymousClass1() { + return new Object() { + }.getClass(); + } + + public static Object anonymousClass2 = new Object() {}; +} diff --git a/jack-tests/tests/com/android/jack/annotation/test009/dx/Annotation009Ref.java b/jack-tests/tests/com/android/jack/annotation/test009/dx/Annotation009Ref.java new file mode 100644 index 0000000..d5306b1 --- /dev/null +++ b/jack-tests/tests/com/android/jack/annotation/test009/dx/Annotation009Ref.java @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.annotation.test009.dx; + +interface I { + Class<?> get(); +} + +public class Annotation009Ref { + + public Annotation009Ref() { + } + + public Annotation009Ref(Object o) { + } + + public static Class<?> getLocalClass1() { + class C { + class D {} + } + return C.D.class; + } + + public static Class<?> getLocalClass2() { + return localClass2.get(); + } + + public static Class<?> getLocalClass3() { + return new Annotation009Ref().localClass3.get(); + } + + public static Class<?> getLocalClass4() { + return localClass2.getClass(); + } + + public static Class<?> getLocalClass5() { + return new Annotation009Ref().localClass3.getClass(); + } + + private static I localClass2 = new I() { + class D {} + @Override + public java.lang.Class<?> get() { + return D.class; + } + }; + + private I localClass3 = new I() { + class D {} + @Override + public java.lang.Class<?> get() { + return D.class; + } + }; +} diff --git a/jack-tests/tests/com/android/jack/annotation/test009/dx/Tests.java b/jack-tests/tests/com/android/jack/annotation/test009/dx/Tests.java new file mode 100644 index 0000000..d2c2345 --- /dev/null +++ b/jack-tests/tests/com/android/jack/annotation/test009/dx/Tests.java @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.annotation.test009.dx; + +import com.android.jack.annotation.test009.jack.Annotation009; + +import junit.framework.Assert; + +import org.junit.Test; + +public class Tests { + @Test + public void test001() throws Exception { + Class<?> clazz = Annotation009.getLocalClass1(); + Class<?> ref = Annotation009Ref.getLocalClass1(); + Assert.assertNull(clazz.getEnclosingMethod()); + Assert.assertEquals(clazz.getEnclosingMethod() == null, ref.getEnclosingMethod() == null); + } + + @Test + public void test002() throws Exception { + Class<?> clazz = Annotation009.getLocalClass2(); + Class<?> ref = Annotation009Ref.getLocalClass2(); + Assert.assertEquals(clazz.getEnclosingMethod() == null, ref.getEnclosingMethod() == null); + } + + @Test + public void test003() throws Exception { + Class<?> clazz = Annotation009.getLocalClass3(); + Class<?> ref = Annotation009Ref.getLocalClass3(); + Assert.assertEquals(clazz.getEnclosingMethod() == null, ref.getEnclosingMethod() == null); + } + + @Test + public void test004() throws Exception { + Class<?> clazz = Annotation009.getLocalClass4(); + Class<?> ref = Annotation009Ref.getLocalClass4(); + Assert.assertEquals(clazz.getEnclosingMethod() == null, ref.getEnclosingMethod() == null); + } + + @Test + public void test005() throws Exception { + Class<?> clazz = Annotation009.getLocalClass5(); + Class<?> ref = Annotation009Ref.getLocalClass5(); + Assert.assertEquals(clazz.getEnclosingMethod() == null, ref.getEnclosingMethod() == null); + } +} diff --git a/jack-tests/tests/com/android/jack/annotation/test009/jack/Annotation009.java b/jack-tests/tests/com/android/jack/annotation/test009/jack/Annotation009.java new file mode 100644 index 0000000..5dba0b1 --- /dev/null +++ b/jack-tests/tests/com/android/jack/annotation/test009/jack/Annotation009.java @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.jack.annotation.test009.jack; + +interface I { + Class<?> get(); +} + +public class Annotation009 { + + public Annotation009() { + } + + public Annotation009(Object o) { + } + + public static Class<?> getLocalClass1() { + class C { + class D {} + } + return C.D.class; + } + + public static Class<?> getLocalClass2() { + return localClass2.get(); + } + + public static Class<?> getLocalClass3() { + return new Annotation009().localClass3.get(); + } + + public static Class<?> getLocalClass4() { + return localClass2.getClass(); + } + + public static Class<?> getLocalClass5() { + return new Annotation009().localClass3.getClass(); + } + + private static I localClass2 = new I() { + class D {} + @Override + public java.lang.Class<?> get() { + return D.class; + } + }; + + private I localClass3 = new I() { + class D {} + @Override + public java.lang.Class<?> get() { + return D.class; + } + }; +} |