List of usage examples for java.lang Class getModifiers
@HotSpotIntrinsicCandidate public native int getModifiers();
From source file:org.opoo.util.ClassUtils.java
public static boolean isPublic(Class clazz, Member member) { return Modifier.isPublic(member.getModifiers()) && Modifier.isPublic(clazz.getModifiers()); }
From source file:org.apache.sling.scripting.sightly.impl.engine.runtime.RenderContextImpl.java
private static Method extractMethodInheritanceChain(Class type, Method m) { if (m == null || Modifier.isPublic(type.getModifiers())) { return m; }//from w w w .j a v a 2s. co m Class[] inf = type.getInterfaces(); Method mp; for (Class<?> iface : inf) { try { mp = iface.getMethod(m.getName(), m.getParameterTypes()); mp = extractMethodInheritanceChain(mp.getDeclaringClass(), mp); if (mp != null) { return mp; } } catch (NoSuchMethodException e) { // do nothing } } Class<?> sup = type.getSuperclass(); if (sup != null) { try { mp = sup.getMethod(m.getName(), m.getParameterTypes()); mp = extractMethodInheritanceChain(mp.getDeclaringClass(), mp); if (mp != null) { return mp; } } catch (NoSuchMethodException e) { // do nothing } } return null; }
From source file:org.hibernate.internal.util.ReflectHelper.java
/** * Determine is the given class is declared final. * * @param clazz The class to check.//w w w . ja v a 2s . co m * @return True if the class is final, flase otherwise. */ public static boolean isFinalClass(Class clazz) { return Modifier.isFinal(clazz.getModifiers()); }
From source file:com.sun.faces.el.impl.BeanInfoManager.java
/** * If the given class is public and has a Method that declares the * same name and arguments as the given method, then that method is * returned. Otherwise the superclass and interfaces are searched * recursively./*w w w. j av a 2 s .c o m*/ */ static Method getPublicMethod(Class pClass, Method pMethod) { // See if this is a public class declaring the method if (Modifier.isPublic(pClass.getModifiers())) { try { Method m; try { m = pClass.getDeclaredMethod(pMethod.getName(), pMethod.getParameterTypes()); } catch (java.security.AccessControlException ex) { // kludge to accommodate J2EE RI's default settings // TODO: see if we can simply replace // getDeclaredMethod() with getMethod() ...? m = pClass.getMethod(pMethod.getName(), pMethod.getParameterTypes()); } if (Modifier.isPublic(m.getModifiers())) { return m; } } catch (NoSuchMethodException exc) { } } // Search the interfaces { Class[] interfaces = pClass.getInterfaces(); if (interfaces != null) { for (int i = 0; i < interfaces.length; i++) { Method m = getPublicMethod(interfaces[i], pMethod); if (m != null) { return m; } } } } // Search the superclass { Class superclass = pClass.getSuperclass(); if (superclass != null) { Method m = getPublicMethod(superclass, pMethod); if (m != null) { return m; } } } return null; }
From source file:com.github.rinde.rinsim.scenario.measure.Metrics.java
/** * Computes the number of occurrences of each event type in the specified * {@link Scenario}.//from www .java 2 s . co m * @param s The scenario to check. * @return A {@link ImmutableMultiset} of event types. */ public static ImmutableMultiset<Class<?>> getEventTypeCounts(Scenario s) { final Multiset<Class<?>> set = LinkedHashMultiset.create(); for (final TimedEvent te : s.getEvents()) { set.add(te.getClass()); } final List<Class<?>> toMove = new ArrayList<>(); for (final Class<?> c : set.elementSet()) { if (!Modifier.isPublic(c.getModifiers()) && TimedEvent.class.isAssignableFrom(c.getSuperclass()) && !set.contains(c.getSuperclass())) { toMove.add(c); } } for (final Class<?> c : toMove) { set.add(c.getSuperclass(), set.count(c)); set.remove(c, set.count(c)); } return ImmutableMultiset.copyOf(set); }
From source file:org.assertj.assertions.generator.util.ClassUtil.java
/** * @param loadedClass//from w w w . ja v a2 s .c o m * @return */ private static boolean isClassCandidateToAssertionsGeneration(Class<?> loadedClass) { return loadedClass != null && isPublic(loadedClass.getModifiers()) && !loadedClass.isAnonymousClass() && !loadedClass.isLocalClass(); }
From source file:org.apache.ignite.spi.deployment.uri.GridUriDeploymentFileProcessor.java
/** * Check that class may be instantiated as {@link org.apache.ignite.compute.ComputeTask} and used * in deployment.// ww w . ja v a 2s .co m * * Loaded task class must implement interface {@link org.apache.ignite.compute.ComputeTask}. * Only non-abstract, non-interfaces and public classes allowed. * Inner static classes also allowed for loading. * * @param cls Class to check * @return {@code true} if class allowed for deployment. */ private static boolean isAllowedTaskClass(Class<?> cls) { if (!ComputeTask.class.isAssignableFrom(cls)) return false; int modifiers = cls.getModifiers(); return !Modifier.isAbstract(modifiers) && !Modifier.isInterface(modifiers) && (!cls.isMemberClass() || Modifier.isStatic(modifiers)) && Modifier.isPublic(modifiers); }
From source file:org.gridgain.grid.spi.deployment.uri.GridUriDeploymentFileProcessor.java
/** * Check that class may be instantiated as {@link GridComputeTask} and used * in deployment./*from w w w.j a v a 2s. c o m*/ * * Loaded task class must implement interface {@link GridComputeTask}. * Only non-abstract, non-interfaces and public classes allowed. * Inner static classes also allowed for loading. * * @param cls Class to check * @return {@code true} if class allowed for deployment. */ private static boolean isAllowedTaskClass(Class<?> cls) { if (!GridComputeTask.class.isAssignableFrom(cls)) return false; int modifiers = cls.getModifiers(); return !Modifier.isAbstract(modifiers) && !Modifier.isInterface(modifiers) && (!cls.isMemberClass() || Modifier.isStatic(modifiers)) && Modifier.isPublic(modifiers); }
From source file:com.github.cherimojava.data.mongo.entity.EntityFactory.java
/** * Sets a default class for a given Interface, which will be used if a Add method is invoked but no underlying * object is existing yet. Supplied class must provide a parameterless public constructor and must be not abstract * * @param interfaze on for which the given implementation will be invoked * @param implementation concrete implementation of the given interface of which a new instance might be created * must have a empty constructor and can't be abstract * @param <T>// w ww . ja va2 s .c o m */ public static <T> void setDefaultClass(Class<T> interfaze, Class<? extends T> implementation) { checkArgument(interfaze.isInterface(), "Can set default Classes only for interfaces"); checkArgument(!implementation.isInterface(), "Default class can't be an interface itself"); checkArgument(!Modifier.isAbstract(implementation.getModifiers()), "Implementation can't be abstract"); try { implementation.getConstructor(); } catch (NoSuchMethodException e) { throw new IllegalArgumentException( "Supplied implementation does not provide a parameterless constructor."); } interfaceImpls.put(interfaze, implementation); }
From source file:com.erudika.para.core.ParaObjectUtils.java
/** * Searches through the Para core package and {@code Config.CORE_PACKAGE_NAME} package for {@link ParaObject} * subclasses and adds their names them to the map. * * @return a map of simple class names (lowercase) to class objects *///from w ww . ja v a2 s .c o m public static Map<String, Class<? extends ParaObject>> getCoreClassesMap() { if (coreClasses.isEmpty()) { try { Set<Class<? extends ParaObject>> s = scanner .getComponentClasses(ParaObject.class.getPackage().getName()); if (!Config.CORE_PACKAGE_NAME.isEmpty()) { Set<Class<? extends ParaObject>> s2 = scanner.getComponentClasses(Config.CORE_PACKAGE_NAME); s.addAll(s2); } for (Class<? extends ParaObject> coreClass : s) { boolean isAbstract = Modifier.isAbstract(coreClass.getModifiers()); boolean isInterface = Modifier.isInterface(coreClass.getModifiers()); boolean isCoreObject = ParaObject.class.isAssignableFrom(coreClass); if (isCoreObject && !isAbstract && !isInterface) { coreClasses.put(coreClass.getSimpleName().toLowerCase(), coreClass); } } logger.debug("Found {} ParaObject classes: {}", coreClasses.size(), coreClasses); } catch (Exception ex) { logger.error(null, ex); } } return Collections.unmodifiableMap(coreClasses); }