List of usage examples for java.lang.reflect Modifier isInterface
public static boolean isInterface(int mod)
From source file:com.discovery.darchrow.lang.ClassUtil.java
/** * ??.//from w w w . j a v a 2 s. com * * @param ownerClass * class * @return true * @see java.lang.Class#getModifiers() * @see java.lang.reflect.Modifier#isInterface(int) */ public static boolean isInterface(Class<?> ownerClass) { // ?? Java int flag = ownerClass.getModifiers(); // ?? return Modifier.isInterface(flag); }
From source file:edu.mit.media.funf.config.DefaultRuntimeTypeAdapterFactory.java
public static boolean isTypeInstatiable(Class<?> type) { int modifiers = type.getModifiers(); if (!(Modifier.isAbstract(modifiers) || Modifier.isInterface(modifiers))) { try {//from w w w .j a v a 2 s .co m Constructor<?> noArgConstructor = type.getConstructor(); return Modifier.isPublic(noArgConstructor.getModifiers()); } catch (SecurityException e) { } catch (NoSuchMethodException e) { } } return false; }
From source file:org.lmn.fc.common.utilities.pending.Utilities.java
/*********************************************************************************************** * Show the Member Modifiers.//from ww w .j av a 2 s .c o m * * @param member * * @return String */ public static String showModifiers(final Member member) { final int modifiers; final StringBuffer buffer; buffer = new StringBuffer(); if (member != null) { modifiers = member.getModifiers(); if (Modifier.isAbstract(modifiers)) { buffer.append("Abstract "); } if (Modifier.isFinal(modifiers)) { buffer.append("Final "); } if (Modifier.isInterface(modifiers)) { buffer.append("Interface "); } if (Modifier.isNative(modifiers)) { buffer.append("Native "); } if (Modifier.isPrivate(modifiers)) { buffer.append("Private "); } if (Modifier.isProtected(modifiers)) { buffer.append("Protected "); } if (Modifier.isPublic(modifiers)) { buffer.append("Public "); } if (Modifier.isStatic(modifiers)) { buffer.append("Static "); } if (Modifier.isStrict(modifiers)) { buffer.append("Strict "); } if (Modifier.isSynchronized(modifiers)) { buffer.append("Synchronized "); } if (Modifier.isTransient(modifiers)) { buffer.append("Transient "); } if (Modifier.isVolatile(modifiers)) { buffer.append("Volatile "); } } return (buffer.toString().trim()); }
From source file:org.apache.flink.api.java.typeutils.runtime.kryo.KryoSerializer.java
@Override public T createInstance() { if (Modifier.isAbstract(type.getModifiers()) || Modifier.isInterface(type.getModifiers())) { return null; } else {//from w ww . j ava 2 s . c om checkKryoInitialized(); try { return kryo.newInstance(type); } catch (Throwable e) { return null; } } }
From source file:org.lightjason.agentspeak.common.CCommon.java
/** * reads all methods by the action-annotations * for building agent-actions/* w w w . j av a 2s .c om*/ * * @param p_class class * @param p_root root class * @return stream of all methods with inheritance */ private static Stream<Method> methods(final Class<?> p_class, final Class<?> p_root) { final Pair<Boolean, IAgentAction.EAccess> l_classannotation = CCommon.isActionClass(p_class); if (!l_classannotation.getLeft()) return p_class.getSuperclass() == null ? Stream.of() : methods(p_class.getSuperclass(), p_root); final Predicate<Method> l_filter = IAgentAction.EAccess.WHITELIST.equals(l_classannotation.getRight()) ? i -> !CCommon.isActionFiltered(i, p_root) : i -> CCommon.isActionFiltered(i, p_root); return Stream.concat(Arrays.stream(p_class.getDeclaredMethods()).parallel().map(i -> { i.setAccessible(true); return i; }).filter(i -> !Modifier.isAbstract(i.getModifiers())).filter(i -> !Modifier.isInterface(i.getModifiers())) .filter(i -> !Modifier.isNative(i.getModifiers())).filter(i -> !Modifier.isStatic(i.getModifiers())) .filter(l_filter), methods(p_class.getSuperclass(), p_root)); }
From source file:com.eucalyptus.simpleworkflow.common.client.WorkflowClientStandalone.java
private void handleClassFile(final File f, final JarEntry j) throws IOException, RuntimeException { final String classGuess = j.getName().replaceAll("/", ".").replaceAll("\\.class.{0,1}", ""); try {//from w ww .j av a 2s . c om final Class candidate = ClassLoader.getSystemClassLoader().loadClass(classGuess); final Ats ats = Ats.inClassHierarchy(candidate); if ((this.allowedClassNames.isEmpty() || this.allowedClassNames.contains(candidate.getName()) || this.allowedClassNames.contains(candidate.getCanonicalName()) || this.allowedClassNames.contains(candidate.getSimpleName())) && (ats.has(Workflow.class) || ats.has(Activities.class)) && !Modifier.isAbstract(candidate.getModifiers()) && !Modifier.isInterface(candidate.getModifiers()) && !candidate.isLocalClass() && !candidate.isAnonymousClass()) { if (ats.has(Workflow.class)) { this.workflowClasses.add(candidate); LOG.debug("Discovered workflow implementation class: " + candidate.getName()); } else { this.activityClasses.add(candidate); LOG.debug("Discovered activity implementation class: " + candidate.getName()); } } } catch (final ClassNotFoundException e) { LOG.debug(e, e); } }
From source file:at.tuwien.ifs.somtoolbox.apps.SOMToolboxMain.java
/** * @param screenWidth the with of the screen * @param runnables {@link ArrayList} of available runnables. *//* www . j av a2s . c o m*/ private static void printAvailableRunnables(int screenWidth, ArrayList<Class<? extends SOMToolboxApp>> runnables) { Collections.sort(runnables, SOMToolboxApp.TYPE_GROUPED_COMPARATOR); ArrayList<Class<? extends SOMToolboxApp>> runnableClassList = new ArrayList<Class<? extends SOMToolboxApp>>(); ArrayList<String> runnableNamesList = new ArrayList<String>(); ArrayList<String> runnableDeskrList = new ArrayList<String>(); for (Class<? extends SOMToolboxApp> c : runnables) { try { // Ignore abstract classes and interfaces if (Modifier.isAbstract(c.getModifiers()) || Modifier.isInterface(c.getModifiers())) { continue; } runnableClassList.add(c); runnableNamesList.add(c.getSimpleName()); String desk = null; try { Field f = c.getDeclaredField("DESCRIPTION"); desk = (String) f.get(null); } catch (Exception e) { } if (desk != null) { runnableDeskrList.add(desk); } else { runnableDeskrList.add(""); } } catch (SecurityException e) { // Should not happen - no Security } catch (IllegalArgumentException e) { e.printStackTrace(); } } StringBuilder sb = new StringBuilder(); String lineSep = System.getProperty("line.separator", "\n"); int maxLen = StringUtils.getLongestStringLength(runnableNamesList); sb.append("Runnable classes:").append(lineSep); for (int i = 0; i < runnableNamesList.size(); i++) { final Type cType = Type.getType(runnableClassList.get(i)); if (i == 0 || !cType.equals(Type.getType(runnableClassList.get(i - 1)))) { sb.append(String.format("-- %s %s%s", cType.toString(), StringUtils.repeatString(screenWidth - (8 + cType.toString().length()), "-"), lineSep)); } sb.append(" "); sb.append(runnableNamesList.get(i)); sb.append(StringUtils.getSpaces(4 + maxLen - runnableNamesList.get(i).length())).append("- "); sb.append(runnableDeskrList.get(i)); sb.append(lineSep); } System.out.println(StringUtils.wrap(sb.toString(), screenWidth, StringUtils.getSpaces(maxLen + 10), true)); }
From source file:edu.cmu.tetrad.util.TetradSerializableUtils.java
/** * Finds all classes inside the stated scope that implement * TetradSerializable and serializes them out to the getCurrentDirectory() * directory. Abstract methods and interfaces are skipped over. For all * other classes C, it is assumed that C has a static constructor of the * following form:/*from ww w. j av a 2 s. co m*/ * <pre> * public static C serializableInstance() { * // Returns an instance of C. May be a mind-numbingly simple * // instance, no need to get fancy. * } * </pre> * The instance returned may be mind-numbingly simple; there is no need to * get fancy. It may change over time. The point is to make sure that * instances serialized out with earlier versions load with the * currentDirectory version. * * @throws RuntimeException if clazz cannot be serialized. This exception * has an informative message and wraps the * originally thrown exception as root cause. */ public void serializeCurrentDirectory() throws RuntimeException { clearCurrentDirectory(); @SuppressWarnings("Convert2Diamond") Map<String, List<String>> classFields = new TreeMap<>(); // Get the classes that implement SerializationCanonicalizer. List classes = getAssignableClasses(new File(getSerializableScope()), TetradSerializable.class); System.out.println( "Serializing exemplars of instantiable TetradSerializable " + "in " + getSerializableScope() + "."); System.out.println("Writing serialized examplars to " + getCurrentDirectory()); int index = -1; for (Object aClass : classes) { Class clazz = (Class) aClass; if (TetradSerializableExcluded.class.isAssignableFrom(clazz)) { continue; } if (Modifier.isAbstract(clazz.getModifiers())) { continue; } if (Modifier.isInterface(clazz.getModifiers())) { continue; } int numFields = getNumNonSerialVersionUIDFields(clazz); if (numFields > 0 && serializableInstanceMethod(clazz) == null) { throw new RuntimeException("Class " + clazz + " does not " + "\nhave a public static serializableInstance constructor."); } if (++index % 50 == 0) { System.out.println(index); } System.out.print("."); serializeClass(clazz, classFields); } try { File file = new File(getCurrentDirectory(), "class_fields.ser"); FileOutputStream out = new FileOutputStream(file); ObjectOutputStream objOut = new ObjectOutputStream(out); objOut.writeObject(classFields); out.close(); } catch (IOException e) { e.printStackTrace(); } System.out.println("\nFinished serializing exemplars."); }
From source file:org.kuali.rice.krad.bo.ModuleConfiguration.java
/** * @param externalizableBusinessObjectImplementations the externalizableBusinessObjectImplementations to set *///w w w. j a va 2 s. c om public void setExternalizableBusinessObjectImplementations( Map<Class, Class> externalizableBusinessObjectImplementations) { if (externalizableBusinessObjectImplementations != null) { for (Class implClass : externalizableBusinessObjectImplementations.values()) { int implModifiers = implClass.getModifiers(); if (Modifier.isInterface(implModifiers) || Modifier.isAbstract(implModifiers)) { throw new RuntimeException("Externalizable business object implementation class " + implClass.getName() + " must be a non-interface, non-abstract class"); } } } this.externalizableBusinessObjectImplementations = externalizableBusinessObjectImplementations; }
From source file:edu.cmu.tetradapp.util.TetradSerializableUtils.java
/** * Finds all classes inside the stated scope that implement * TetradSerializable and serializes them out to the getCurrentDirectory() * directory. Abstract methods and interfaces are skipped over. For all * other classes C, it is assumed that C has a static constructor of the * following form:/*w w w . j av a2s .c o m*/ * <pre> * public static C serializableInstance() { * // Returns an instance of C. May be a mind-numbingly simple * // instance, no need to get fancy. * } * </pre> * The instance returned may be mind-numbingly simple; there is no need to * get fancy. It may change over time. The point is to make sure that * instances serialized out with earlier versions load with the * currentDirectory version. * * @throws RuntimeException if clazz cannot be serialized. This exception * has an informative message and wraps the * originally thrown exception as root cause. */ public void serializeCurrentDirectory() throws RuntimeException { clearCurrentDirectory(); Map<String, List<String>> classFields = new TreeMap<String, List<String>>(); // Get the classes that implement SerializationCanonicalizer. List classes = getAssignableClasses(new File(getSerializableScope()), TetradSerializable.class); System.out.println( "Serializing exemplars of instantiable TetradSerializable " + "in " + getSerializableScope() + "."); System.out.println("Writing serialized examplars to " + getCurrentDirectory()); int index = -1; for (Object aClass : classes) { Class clazz = (Class) aClass; if (TetradSerializableExcluded.class.isAssignableFrom(clazz)) { continue; } if (Modifier.isAbstract(clazz.getModifiers())) { continue; } if (Modifier.isInterface(clazz.getModifiers())) { continue; } int numFields = getNumNonSerialVersionUIDFields(clazz); if (numFields > 0 && serializableInstanceMethod(clazz) == null) { throw new RuntimeException("Class " + clazz + " does not " + "\nhave a public static serializableInstance constructor."); } if (++index % 50 == 0) { System.out.println(index); } System.out.print("."); serializeClass(clazz, classFields); } try { File file = new File(getCurrentDirectory(), "class_fields.ser"); FileOutputStream out = new FileOutputStream(file); ObjectOutputStream objOut = new ObjectOutputStream(out); objOut.writeObject(classFields); out.close(); } catch (IOException e) { e.printStackTrace(); } System.out.println("\nFinished serializing exemplars."); }