diff options
Diffstat (limited to 'luni/src')
3 files changed, 150 insertions, 289 deletions
diff --git a/luni/src/main/java/java/lang/reflect/Modifier.java b/luni/src/main/java/java/lang/reflect/Modifier.java index 28e9861..225ded1 100644 --- a/luni/src/main/java/java/lang/reflect/Modifier.java +++ b/luni/src/main/java/java/lang/reflect/Modifier.java @@ -111,6 +111,51 @@ public class Modifier { } /** + * Returns a mask of all the modifiers that may be applied to classes. + * @since 1.7 + * @hide 1.7 + */ + public static int classModifiers() { + return PUBLIC | PROTECTED | PRIVATE | ABSTRACT | STATIC | FINAL | STRICT; + } + + /** + * Returns a mask of all the modifiers that may be applied to constructors. + * @since 1.7 + * @hide 1.7 + */ + public static int constructorModifiers() { + return PUBLIC | PROTECTED | PRIVATE; + } + + /** + * Returns a mask of all the modifiers that may be applied to fields. + * @since 1.7 + * @hide 1.7 + */ + public static int fieldModifiers() { + return PUBLIC | PROTECTED | PRIVATE | STATIC | FINAL | TRANSIENT | VOLATILE; + } + + /** + * Returns a mask of all the modifiers that may be applied to interfaces. + * @since 1.7 + * @hide 1.7 + */ + public static int interfaceModifiers() { + return PUBLIC | PROTECTED | PRIVATE | ABSTRACT | STATIC | STRICT; + } + + /** + * Returns a mask of all the modifiers that may be applied to methods. + * @since 1.7 + * @hide 1.7 + */ + public static int methodModifiers() { + return PUBLIC | PROTECTED | PRIVATE | ABSTRACT | STATIC | FINAL | SYNCHRONIZED | NATIVE | STRICT; + } + + /** * Indicates whether or not the specified modifiers contain the {@code * abstract} modifier. * diff --git a/luni/src/test/java/libcore/java/lang/reflect/ModifierTest.java b/luni/src/test/java/libcore/java/lang/reflect/ModifierTest.java new file mode 100644 index 0000000..1bde157 --- /dev/null +++ b/luni/src/test/java/libcore/java/lang/reflect/ModifierTest.java @@ -0,0 +1,105 @@ +/* + * Copyright (C) 2011 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 libcore.java.lang.reflect; + +import java.lang.reflect.Modifier; + +public class ModifierTest extends junit.framework.TestCase { + public void test_classModifiers() { + assertEquals(0xc1f, Modifier.classModifiers()); + } + + public void test_constructorModifiers() { + assertEquals(0x007, Modifier.constructorModifiers()); + } + + public void test_fieldModifiers() { + assertEquals(0x0df, Modifier.fieldModifiers()); + } + + public void test_interfaceModifiers() { + assertEquals(0xc0f, Modifier.interfaceModifiers()); + } + + public void test_methodModifiers() { + assertEquals(0xd3f, Modifier.methodModifiers()); + } + + public void test_isAbstractI() { + assertTrue(Modifier.isAbstract(Modifier.ABSTRACT)); + assertTrue(!Modifier.isAbstract(-1 & ~Modifier.ABSTRACT)); + } + + public void test_isFinalI() { + assertTrue(Modifier.isFinal(Modifier.FINAL)); + assertTrue(!Modifier.isFinal(-1 & ~Modifier.FINAL)); + } + + public void test_isInterfaceI() { + assertTrue(Modifier.isInterface(Modifier.INTERFACE)); + assertTrue(!Modifier.isInterface(-1 & ~Modifier.INTERFACE)); + } + + public void test_isNativeI() { + assertTrue(Modifier.isNative(Modifier.NATIVE)); + assertTrue(!Modifier.isNative(-1 & ~Modifier.NATIVE)); + } + + public void test_isPrivateI() { + assertTrue(Modifier.isPrivate(Modifier.PRIVATE)); + assertTrue(!Modifier.isPrivate(-1 & ~Modifier.PRIVATE)); + } + + public void test_isProtectedI() { + assertTrue(Modifier.isProtected(Modifier.PROTECTED)); + assertTrue(!Modifier.isProtected(-1 & ~Modifier.PROTECTED)); + } + + public void test_isPublicI() { + assertTrue(Modifier.isPublic(Modifier.PUBLIC)); + assertTrue(!Modifier.isPublic(-1 & ~Modifier.PUBLIC)); + } + + public void test_isStaticI() { + assertTrue(Modifier.isStatic(Modifier.STATIC)); + assertTrue(!Modifier.isStatic(-1 & ~Modifier.STATIC)); + } + + public void test_isStrictI() { + assertTrue(Modifier.isStrict(Modifier.STRICT)); + assertTrue(!Modifier.isStrict(-1 & ~Modifier.STRICT)); + } + + public void test_isSynchronizedI() { + assertTrue(Modifier.isSynchronized(Modifier.SYNCHRONIZED)); + assertTrue(!Modifier.isSynchronized(-1 & ~Modifier.SYNCHRONIZED)); + } + + public void test_isTransientI() { + assertTrue(Modifier.isTransient(Modifier.TRANSIENT)); + assertTrue(!Modifier.isTransient(-1 & ~Modifier.TRANSIENT)); + } + + public void test_isVolatileI() { + assertTrue(Modifier.isVolatile(Modifier.VOLATILE)); + assertTrue(!Modifier.isVolatile(-1 & ~Modifier.VOLATILE)); + } + + public void test_toStringI() { + assertEquals("public abstract", Modifier.toString(Modifier.PUBLIC | Modifier.ABSTRACT)); + } +} diff --git a/luni/src/test/java/tests/api/java/lang/reflect/ModifierTest.java b/luni/src/test/java/tests/api/java/lang/reflect/ModifierTest.java deleted file mode 100644 index 8995139..0000000 --- a/luni/src/test/java/tests/api/java/lang/reflect/ModifierTest.java +++ /dev/null @@ -1,289 +0,0 @@ -/* - * 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 tests.api.java.lang.reflect; - -import dalvik.annotation.TestTargets; -import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTargetNew; -import dalvik.annotation.TestTargetClass; - -import java.lang.reflect.Modifier; - -@TestTargetClass(Modifier.class) -public class ModifierTest extends junit.framework.TestCase { - - private static final int ALL_FLAGS = 0x7FF; - - /** - * @tests java.lang.reflect.Modifier#Modifier() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "The only thing I can do", - method = "Modifier", - args = {} - ) - public void test_Constructor() { - assertNotNull(new Modifier()); - } - - /** - * @tests java.lang.reflect.Modifier#isAbstract(int) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "isAbstract", - args = {int.class} - ) - public void test_isAbstractI() { - // Test for method boolean java.lang.reflect.Modifier.isAbstract(int) - assertTrue("ABSTRACT returned false", Modifier.isAbstract(ALL_FLAGS)); - assertTrue("ABSTRACT returned false", Modifier - .isAbstract(Modifier.ABSTRACT)); - assertTrue("Non-ABSTRACT returned true", !Modifier - .isAbstract(Modifier.TRANSIENT)); - } - - /** - * @tests java.lang.reflect.Modifier#isFinal(int) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "isFinal", - args = {int.class} - ) - public void test_isFinalI() { - // Test for method boolean java.lang.reflect.Modifier.isFinal(int) - assertTrue("FINAL returned false", Modifier.isFinal(ALL_FLAGS)); - assertTrue("FINAL returned false", Modifier.isFinal(Modifier.FINAL)); - assertTrue("Non-FINAL returned true", !Modifier - .isFinal(Modifier.TRANSIENT)); - } - - /** - * @tests java.lang.reflect.Modifier#isInterface(int) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "isInterface", - args = {int.class} - ) - public void test_isInterfaceI() { - // Test for method boolean java.lang.reflect.Modifier.isInterface(int) - assertTrue("INTERFACE returned false", Modifier.isInterface(ALL_FLAGS)); - assertTrue("INTERFACE returned false", Modifier - .isInterface(Modifier.INTERFACE)); - assertTrue("Non-INTERFACE returned true", !Modifier - .isInterface(Modifier.TRANSIENT)); - } - - /** - * @tests java.lang.reflect.Modifier#isNative(int) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "isNative", - args = {int.class} - ) - public void test_isNativeI() { - // Test for method boolean java.lang.reflect.Modifier.isNative(int) - assertTrue("NATIVE returned false", Modifier.isNative(ALL_FLAGS)); - assertTrue("NATIVE returned false", Modifier.isNative(Modifier.NATIVE)); - assertTrue("Non-NATIVE returned true", !Modifier - .isNative(Modifier.TRANSIENT)); - } - - /** - * @tests java.lang.reflect.Modifier#isPrivate(int) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "isPrivate", - args = {int.class} - ) - public void test_isPrivateI() { - // Test for method boolean java.lang.reflect.Modifier.isPrivate(int) - assertTrue("PRIVATE returned false", Modifier.isPrivate(ALL_FLAGS)); - assertTrue("PRIVATE returned false", Modifier - .isPrivate(Modifier.PRIVATE)); - assertTrue("Non-PRIVATE returned true", !Modifier - .isPrivate(Modifier.TRANSIENT)); - } - - /** - * @tests java.lang.reflect.Modifier#isProtected(int) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "isProtected", - args = {int.class} - ) - public void test_isProtectedI() { - // Test for method boolean java.lang.reflect.Modifier.isProtected(int) - assertTrue("PROTECTED returned false", Modifier.isProtected(ALL_FLAGS)); - assertTrue("PROTECTED returned false", Modifier - .isProtected(Modifier.PROTECTED)); - assertTrue("Non-PROTECTED returned true", !Modifier - .isProtected(Modifier.TRANSIENT)); - } - - /** - * @tests java.lang.reflect.Modifier#isPublic(int) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "isPublic", - args = {int.class} - ) - public void test_isPublicI() { - // Test for method boolean java.lang.reflect.Modifier.isPublic(int) - assertTrue("PUBLIC returned false", Modifier.isPublic(ALL_FLAGS)); - assertTrue("PUBLIC returned false", Modifier.isPublic(Modifier.PUBLIC)); - assertTrue("Non-PUBLIC returned true", !Modifier - .isPublic(Modifier.TRANSIENT)); - } - - /** - * @tests java.lang.reflect.Modifier#isStatic(int) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "isStatic", - args = {int.class} - ) - public void test_isStaticI() { - // Test for method boolean java.lang.reflect.Modifier.isStatic(int) - assertTrue("STATIC returned false", Modifier.isStatic(ALL_FLAGS)); - assertTrue("STATIC returned false", Modifier.isStatic(Modifier.STATIC)); - assertTrue("Non-STATIC returned true", !Modifier - .isStatic(Modifier.TRANSIENT)); - } - - /** - * @tests java.lang.reflect.Modifier#isStrict(int) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "isStrict", - args = {int.class} - ) - public void test_isStrictI() { - // Test for method boolean java.lang.reflect.Modifier.isStrict(int) - assertTrue("STRICT returned false", Modifier.isStrict(Modifier.STRICT)); - assertTrue("Non-STRICT returned true", !Modifier - .isStrict(Modifier.TRANSIENT)); - } - - /** - * @tests java.lang.reflect.Modifier#isSynchronized(int) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "isSynchronized", - args = {int.class} - ) - public void test_isSynchronizedI() { - // Test for method boolean - // java.lang.reflect.Modifier.isSynchronized(int) - assertTrue("Synchronized returned false", Modifier - .isSynchronized(ALL_FLAGS)); - assertTrue("Non-Synchronized returned true", !Modifier - .isSynchronized(Modifier.VOLATILE)); - } - - /** - * @tests java.lang.reflect.Modifier#isTransient(int) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "isTransient", - args = {int.class} - ) - public void test_isTransientI() { - // Test for method boolean java.lang.reflect.Modifier.isTransient(int) - assertTrue("Transient returned false", Modifier.isTransient(ALL_FLAGS)); - assertTrue("Transient returned false", Modifier - .isTransient(Modifier.TRANSIENT)); - assertTrue("Non-Transient returned true", !Modifier - .isTransient(Modifier.VOLATILE)); - } - - /** - * @tests java.lang.reflect.Modifier#isVolatile(int) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "isVolatile", - args = {int.class} - ) - public void test_isVolatileI() { - // Test for method boolean java.lang.reflect.Modifier.isVolatile(int) - assertTrue("Volatile returned false", Modifier.isVolatile(ALL_FLAGS)); - assertTrue("Volatile returned false", Modifier - .isVolatile(Modifier.VOLATILE)); - assertTrue("Non-Volatile returned true", !Modifier - .isVolatile(Modifier.TRANSIENT)); - } - - /** - * @tests java.lang.reflect.Modifier#toString(int) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "toString", - args = {int.class} - ) - public void test_toStringI() { - // Test for method java.lang.String - // java.lang.reflect.Modifier.toString(int) - assertTrue("Returned incorrect string value: " - + Modifier.toString(java.lang.reflect.Modifier.PUBLIC - + java.lang.reflect.Modifier.ABSTRACT), Modifier - .toString( - java.lang.reflect.Modifier.PUBLIC - + java.lang.reflect.Modifier.ABSTRACT).equals( - "public abstract")); - } - - /** - * Sets up the fixture, for example, open a network connection. This method - * is called before a test is executed. - */ - protected void setUp() { - } - - /** - * Tears down the fixture, for example, close a network connection. This - * method is called after a test is executed. - */ - protected void tearDown() { - } -} |