1 /* 2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 package jdk.vm.ci.meta; 24 25 import static java.lang.reflect.Modifier.ABSTRACT; 26 import static java.lang.reflect.Modifier.FINAL; 27 import static java.lang.reflect.Modifier.INTERFACE; 28 import static java.lang.reflect.Modifier.NATIVE; 29 import static java.lang.reflect.Modifier.PRIVATE; 30 import static java.lang.reflect.Modifier.PROTECTED; 31 import static java.lang.reflect.Modifier.PUBLIC; 32 import static java.lang.reflect.Modifier.STATIC; 33 import static java.lang.reflect.Modifier.STRICT; 34 import static java.lang.reflect.Modifier.SYNCHRONIZED; 35 import static java.lang.reflect.Modifier.TRANSIENT; 36 import static java.lang.reflect.Modifier.VOLATILE; 37 38 import java.lang.reflect.Modifier; 39 40 /** 41 * A Java element (i.e., a class, interface, field or method) that is described by a set of Java 42 * language {@linkplain #getModifiers() modifiers}. 43 */ 44 public interface ModifiersProvider { 45 int BRIDGE = 0x0040; 46 int VARARGS = 0x0080; 47 int SYNTHETIC = 0x1000; 48 int ANNOTATION = 0x2000; 49 int ENUM = 0x4000; 50 51 /** 52 * Returns the Java Virtual Machine modifiers for this element. Note that this can differ from 53 * standard Java Reflection modifiers. For example at the JVM level, classes ( 54 * {@link ResolvedJavaType}) can not be private or protected. 55 */ 56 int getModifiers(); 57 58 /** 59 * @see Modifier#isInterface(int) 60 */ 61 default boolean isInterface() { 62 return Modifier.isInterface(getModifiers()); 63 } 64 65 /** 66 * @see Modifier#isSynchronized(int) 67 */ 68 default boolean isSynchronized() { 69 return Modifier.isSynchronized(getModifiers()); 70 } 71 72 /** 73 * @see Modifier#isStatic(int) 74 */ 75 default boolean isStatic() { 76 return Modifier.isStatic(getModifiers()); 77 } 78 79 /** 80 * The setting of the final modifier bit for types is somewhat confusing, so don't export 81 * isFinal by default. Subclasses like {@link ResolvedJavaField} and {@link ResolvedJavaMethod} 82 * can export it as isFinal, but {@link ResolvedJavaType} can provide a more sensible equivalent 83 * like {@link ResolvedJavaType#isLeaf}. 84 * 85 * @see Modifier#isFinal(int) 86 */ 87 default boolean isFinalFlagSet() { 88 return Modifier.isFinal(getModifiers()); 89 } 90 91 /** 92 * @see Modifier#isPublic(int) 93 */ 94 default boolean isPublic() { 95 return Modifier.isPublic(getModifiers()); 96 } 97 98 /** 99 * Determines if this element is neither {@linkplain #isPublic() public}, 100 * {@linkplain #isProtected() protected} nor {@linkplain #isPrivate() private}. 101 */ 102 default boolean isPackagePrivate() { 103 return ((PUBLIC | PROTECTED | PRIVATE) & getModifiers()) == 0; 104 } 105 106 /** 107 * @see Modifier#isPrivate(int) 108 */ 109 default boolean isPrivate() { 110 return Modifier.isPrivate(getModifiers()); 111 } 112 113 /** 114 * @see Modifier#isProtected(int) 115 */ 116 default boolean isProtected() { 117 return Modifier.isProtected(getModifiers()); 118 } 119 120 /** 121 * @see Modifier#isTransient(int) 122 */ 123 default boolean isTransient() { 124 return Modifier.isTransient(getModifiers()); 125 } 126 127 /** 128 * @see Modifier#isStrict(int) 129 */ 130 default boolean isStrict() { 131 return Modifier.isStrict(getModifiers()); 132 } 133 134 /** 135 * @see Modifier#isVolatile(int) 136 */ 137 default boolean isVolatile() { 138 return Modifier.isVolatile(getModifiers()); 139 } 140 141 /** 142 * @see Modifier#isNative(int) 143 */ 144 default boolean isNative() { 145 return Modifier.isNative(getModifiers()); 146 } 147 148 /** 149 * @see Modifier#isAbstract(int) 150 */ 151 default boolean isAbstract() { 152 return Modifier.isAbstract(getModifiers()); 153 } 154 155 /** 156 * Checks that the method is concrete and not abstract. 157 * 158 * @return whether the method is a concrete method 159 */ 160 default boolean isConcrete() { 161 return !isAbstract(); 162 } 163 164 static int jvmClassModifiers() { 165 // no SUPER 166 return PUBLIC | FINAL | INTERFACE | ABSTRACT | ANNOTATION | ENUM | SYNTHETIC; 167 } 168 169 static int jvmMethodModifiers() { 170 return PUBLIC | PRIVATE | PROTECTED | STATIC | FINAL | SYNCHRONIZED | BRIDGE | VARARGS | NATIVE | ABSTRACT | STRICT | SYNTHETIC; 171 } 172 173 static int jvmFieldModifiers() { 174 return PUBLIC | PRIVATE | PROTECTED | STATIC | FINAL | VOLATILE | TRANSIENT | ENUM | SYNTHETIC; 175 } 176 }