List of usage examples for java.lang.reflect Modifier INTERFACE
int INTERFACE
To view the source code for java.lang.reflect Modifier INTERFACE.
Click Source Link
From source file:Main.java
public static void main(String... args) throws Exception { Class<?> c = Class.forName("java.lang.String"); Constructor[] allConstructors = c.getDeclaredConstructors(); for (Constructor ctor : allConstructors) { int searchMod = Modifier.INTERFACE; int mods = accessModifiers(ctor.getModifiers()); if (searchMod == mods) { System.out.println(ctor); }/*w ww . j a v a 2 s.co m*/ } }
From source file:Main.java
/** * Helper method that checks if given class is a concrete one; * that is, not an interface or abstract class. *///from w w w . jav a2 s .c o m public static boolean isConcrete(Class<?> type) { int mod = type.getModifiers(); return (mod & (Modifier.INTERFACE | Modifier.ABSTRACT)) == 0; }
From source file:Main.java
public static boolean isConcrete(Member member) { int mod = member.getModifiers(); return (mod & (Modifier.INTERFACE | Modifier.ABSTRACT)) == 0; }
From source file:Main.java
private static int accessModifiers(int m) { return m & Modifier.INTERFACE; }
From source file:rubah.tools.ConversionClassGenerator.java
private byte[] getClassBytes(Clazz cl) { ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS); String[] interfaces = new String[cl.getInterfaces().size()]; {//from www .ja va 2 s.c o m int i = 0; for (Clazz iface : cl.getInterfaces()) { interfaces[i++] = this.getType(iface).getInternalName(); } } writer.visit(CLASS_VERSION, CLASS_ACCESS | (cl.isInterface() ? Modifier.INTERFACE : 0), this.getType(cl).getInternalName(), null, this.getType(cl.getParent()).getInternalName(), interfaces); for (Field f : cl.getFields()) { writer.visitField(Modifier.isStatic(f.getAccess()) ? FIELD_STATIC_ACCESS : FIELD_ACCESS, f.getName(), this.getType(f.getType()).getDescriptor(), null, null); } for (Method m : cl.getMethods()) { Type ret = this.getType(m.getRetType()); Type[] args = new Type[m.getArgTypes().size()]; { int i = 0; for (Clazz arg : m.getArgTypes()) { args[i++] = this.getType(arg); } } writer.visitMethod( (Modifier.isStatic(m.getAccess()) ? FIELD_STATIC_ACCESS : FIELD_ACCESS) | ACC_ABSTRACT, m.getName(), Type.getMethodDescriptor(ret, args), null, null); } writer.visitMethod(CONVERT_METHOD_ACCESS, UpdateClassGenerator.METHOD_NAME, Type.getMethodDescriptor(this.getType(cl, this.newPreffix)), null, null); writer.visitMethod(CONVERT_METHOD_ACCESS, UpdateClassGenerator.METHOD_NAME, Type.getMethodDescriptor(this.getType(cl, this.newPreffix), this.getType(cl, this.newPreffix)), null, null); if (this.newPreffix.equals("")) { writer.visitMethod(COPY_METHOD_ACCESS_STATIC, UpdateClassGenerator.COPY_METHOD_NAME_STATIC, Type.getMethodDescriptor(Type.VOID_TYPE), null, null); } Clazz arrayCl = this.namespace.getClass(cl.getASMType(), 1); writer.visitMethod(CONVERT_ARRAY_METHOD_ACCESS, UpdateClassGenerator.METHOD_NAME, Type.getMethodDescriptor(this.getType(arrayCl, this.newPreffix), this.getType(arrayCl)), null, null); writer.visitEnd(); return writer.toByteArray(); }
From source file:de.lmu.ifi.dbs.jfeaturelib.utils.PackageScanner.java
public List<Class<T>> scanForClass(Package thePackage, Class<T> needle) throws IOException, UnsupportedEncodingException, URISyntaxException { List<String> binaryNames = getNames(thePackage); List<Class<T>> list = new ArrayList<>(); ClassLoader loader = ClassLoader.getSystemClassLoader(); for (String binaryName : binaryNames) { if (binaryName.contains("$") && !includeInnerClasses) { log.debug("Skipped inner class: " + binaryName); continue; }// w w w . ja v a 2 s .c om try { Class<?> clazz = loader.loadClass(binaryName); int modifiers = clazz.getModifiers(); if ((modifiers & Modifier.INTERFACE) != 0 && !includeInterfaces) { log.debug("Skipped interface: " + binaryName); continue; } if ((modifiers & Modifier.ABSTRACT) != 0 && !includeAbstractClasses) { log.debug("Skipped abstract class: " + binaryName); continue; } if (needle.isAssignableFrom(clazz)) { log.debug("added class/interface/..: " + binaryName); list.add((Class<T>) clazz); } } catch (ClassNotFoundException e) { // This should never happen log.warn("couldn't find class (?!): " + binaryName, e); } } return list; }
From source file:hd3gtv.mydmam.db.orm.CassandraOrm.java
private ArrayList<Field> getOrmobjectUsableFields() { ArrayList<Field> result = new ArrayList<Field>(); Field[] fields = this.reference.getFields(); Field field;/*from w ww. j av a 2 s .co m*/ int mod; for (int pos_df = 0; pos_df < fields.length; pos_df++) { field = fields[pos_df]; if (field.isAnnotationPresent(Transient.class)) { /** * Is transient ? */ continue; } if (field.getName().equals("key")) { /** * Not this (primary key) */ continue; } mod = field.getModifiers(); if ((mod & Modifier.PROTECTED) != 0) continue; if ((mod & Modifier.PRIVATE) != 0) continue; if ((mod & Modifier.ABSTRACT) != 0) continue; if ((mod & Modifier.STATIC) != 0) continue; if ((mod & Modifier.FINAL) != 0) continue; if ((mod & Modifier.TRANSIENT) != 0) continue; if ((mod & Modifier.INTERFACE) != 0) continue; try { result.add(field); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (SecurityException e) { e.printStackTrace(); } } return result; }
From source file:com.izforge.izpack.util.SelfModifier.java
/** * Check the method for the required properties (public, static, params:(String[])). * * @param method the method/*from w w w . j av a 2s . c o m*/ * @throws NullPointerException if <code>method</code> is null * @throws IllegalArgumentException if <code>method</code> is not public, static, and take a * String array as it's only argument, or of it's declaring class is not public. * @throws SecurityException if access to the method is denied */ private void initMethod(Method method) { int mod = method.getModifiers(); if ((mod & Modifier.PUBLIC) == 0 || (mod & Modifier.STATIC) == 0) { throw new IllegalArgumentException("Method not public and static"); } Class[] params = method.getParameterTypes(); if (params.length != 1 || !params[0].isArray() || !"java.lang.String".equals(params[0].getComponentType().getName())) { throw new IllegalArgumentException("Method must accept String array"); } Class clazz = method.getDeclaringClass(); mod = clazz.getModifiers(); if ((mod & Modifier.PUBLIC) == 0 || (mod & Modifier.INTERFACE) != 0) { throw new IllegalArgumentException("Method must be in a public class"); } this.method = method; }
From source file:com.link_intersystems.lang.reflect.criteria.MemberCriteria.java
/** * Set the criterion that selects only {@link Member}s that exactly have the * specified modifiers. The access modifiers are set separately. Use * {@link #withAccess(AccessType...)} to set access modifiers. * * @param modifiers//from w w w . j ava 2 s . c om * @since 1.0.0.0 */ public void withModifiers(int modifiers) { if (Modifier.isPublic(modifiers) || Modifier.isProtected(modifiers) || Modifier.isPrivate(modifiers)) { throw new IllegalArgumentException( "access modifiers are not allowed as argument. Use withAccess() instead."); } int allowedModifiers = Modifier.ABSTRACT | Modifier.STATIC | Modifier.FINAL | Modifier.TRANSIENT | Modifier.VOLATILE | Modifier.SYNCHRONIZED | Modifier.NATIVE | Modifier.STRICT | Modifier.INTERFACE; if ((modifiers & allowedModifiers) == 0) { throw new IllegalArgumentException( "modifiers must be one of [" + Modifier.toString(allowedModifiers) + "]"); } this.modifiers = modifiers; }
From source file:org.tynamo.model.elasticsearch.util.ReflectionUtil.java
/** * Checks if is interface./*from w w w .j av a2 s . c o m*/ * * @param clazz * the clazz * @return true, if is interface */ public static boolean isInterface(Class<?> clazz) { int modifiers = clazz.getModifiers(); return (modifiers & Modifier.INTERFACE) > 0; }