List of usage examples for java.lang Class getModifiers
@HotSpotIntrinsicCandidate public native int getModifiers();
From source file:nl.knaw.huygens.timbuctoo.config.TypeRegistry.java
@SuppressWarnings("unchecked") public static Class<? extends Entity> getBaseClass(Class<? extends Entity> type) { Class<? extends Entity> lastType = type; while (type != null && !Modifier.isAbstract(type.getModifiers())) { lastType = type;//from w w w . j a va 2s . c o m type = (Class<? extends Entity>) type.getSuperclass(); } return lastType; }
From source file:com.sun.faces.el.impl.BeanInfoManager.java
/** * Returns a publicly-accessible version of the given method, by * searching for a public declaring class. *//*from w ww . ja v a 2 s . c om*/ static Method getPublicMethod(Method pMethod) { if (pMethod == null) { return null; } // See if the method is already available from a public class Class cl = pMethod.getDeclaringClass(); if (Modifier.isPublic(cl.getModifiers())) { return pMethod; } // Otherwise, try to find a public class that declares the method Method ret = getPublicMethod(cl, pMethod); if (ret != null) { return ret; } else { return pMethod; } }
From source file:com.cuubez.visualizer.resource.ResourceMetaDataScanner.java
public static boolean isResource(Class<?> clazz) { if (Modifier.isInterface(clazz.getModifiers()) || Modifier.isAbstract(clazz.getModifiers())) { return false; }/*from w ww .java 2 s . c o m*/ if (clazz.getAnnotation(Path.class) != null && clazz.getAnnotation(Group.class) != null) { return true; } Class<?> declaringClass = clazz; while (!declaringClass.equals(Object.class)) { // try a superclass Class<?> superclass = declaringClass.getSuperclass(); if (superclass.getAnnotation(Path.class) != null && clazz.getAnnotation(Group.class) != null) { return true; } // try interfaces Class<?>[] interfaces = declaringClass.getInterfaces(); for (Class<?> interfaceClass : interfaces) { if (interfaceClass.getAnnotation(Path.class) != null && clazz.getAnnotation(Group.class) != null) { return true; } } declaringClass = declaringClass.getSuperclass(); } return false; }
From source file:org.opoo.util.ClassUtils.java
public static boolean isAbstractClass(Class clazz) { int modifier = clazz.getModifiers(); return Modifier.isAbstract(modifier) || Modifier.isInterface(modifier); }
From source file:at.treedb.backup.Import.java
private static boolean ignoreClass(Class<?> c) { if (Modifier.isAbstract(c.getModifiers()) || c.equals(DBFSblock.class) || c.equals(DBinfo.class)) { return true; }// w w w . j av a 2 s . com return false; }
From source file:org.eclipse.wb.internal.swing.laf.LafUtils.java
/** * Opens given <code>jarFile</code>, loads every class inside own {@link ClassLoader} and checks * loaded class for to be instance of {@link LookAndFeel}. Returns the array of {@link LafInfo} * containing all found {@link LookAndFeel} classes. * /*from w ww . j a va 2 s . co m*/ * @param jarFileName * the absolute OS path pointing to source JAR file. * @param monitor * the progress monitor which checked for interrupt request. * @return the array of {@link UserDefinedLafInfo} containing all found {@link LookAndFeel} * classes. */ public static UserDefinedLafInfo[] scanJarForLookAndFeels(String jarFileName, IProgressMonitor monitor) throws Exception { List<UserDefinedLafInfo> lafList = Lists.newArrayList(); File jarFile = new File(jarFileName); URLClassLoader ucl = new URLClassLoader(new URL[] { jarFile.toURI().toURL() }); JarFile jar = new JarFile(jarFile); Enumeration<?> entries = jar.entries(); while (entries.hasMoreElements()) { JarEntry entry = (JarEntry) entries.nextElement(); String entryName = entry.getName(); if (entry.isDirectory() || !entryName.endsWith(".class") || entryName.indexOf('$') >= 0) { continue; } String className = entryName.replace('/', '.').replace('\\', '.'); className = className.substring(0, className.lastIndexOf('.')); Class<?> clazz = null; try { clazz = ucl.loadClass(className); } catch (Throwable e) { continue; } // check loaded class to be a non-abstract subclass of javax.swing.LookAndFeel class if (LookAndFeel.class.isAssignableFrom(clazz) && !Modifier.isAbstract(clazz.getModifiers())) { // use the class name as name of LAF String shortClassName = CodeUtils.getShortClass(className); // strip trailing "LookAndFeel" String lafName = StringUtils.chomp(shortClassName, "LookAndFeel"); lafList.add(new UserDefinedLafInfo(StringUtils.isEmpty(lafName) ? shortClassName : lafName, className, jarFileName)); } // check for Cancel button pressed if (monitor.isCanceled()) { return lafList.toArray(new UserDefinedLafInfo[lafList.size()]); } // update ui while (DesignerPlugin.getStandardDisplay().readAndDispatch()) { } } return lafList.toArray(new UserDefinedLafInfo[lafList.size()]); }
From source file:org.seedstack.seed.core.utils.BaseClassSpecifications.java
/** * @param modifier the expected modifier * @return a specification which checks the class modifier *///from ww w . ja v a 2 s. com public static Specification<Class<?>> classModifierIs(final int modifier) { return new AbstractSpecification<Class<?>>() { @Override public boolean isSatisfiedBy(Class<?> candidate) { return (candidate.getModifiers() & modifier) != 0; } }; }
From source file:com.puppycrawl.tools.checkstyle.AllChecksTest.java
/** * Checks whether a class may be considered as the checkstyle check. * Checkstyle's checks are nonabstract classes which names end with 'Check', * do not contain the word 'Input' (are not input files for UTs). * @param loadedClass class to check./*from w w w. j av a2 s. c o m*/ * @param className class name to check. * @return true if a class may be considered as the checkstyle check. */ private static boolean isCheckstyleNonAbstractCheck(Class<?> loadedClass, String className) { return !Modifier.isAbstract(loadedClass.getModifiers()) && className.endsWith("Check") && !className.contains("Input"); }
From source file:net.servicefixture.util.ReflectionUtils.java
private static boolean isConcreteSubclass(Class<?> baseClass, Class<?> clazz) { return baseClass.isAssignableFrom(clazz) && !baseClass.equals(clazz) && !clazz.isInterface() && !Modifier.isAbstract(clazz.getModifiers()); }
From source file:org.xulux.utils.ClassLoaderUtils.java
/** * Tries to find a constructor with the parameters specified in the list * If it cannot it will return the empty constructor. * * @param clazz the class//from w w w. ja va2 s.co m * @param parms the list of parameters as classes * @return the instantiated object */ public static Object getObjectFromClass(Class clazz, List parms) { try { if (parms != null && parms.size() > 0) { boolean cleanUp = false; if (isInner(clazz) && !Modifier.isStatic(clazz.getModifiers())) { parms.add(0, getParentObjectForInnerClass(clazz)); cleanUp = true; } Class[] clzList = new Class[parms.size()]; for (int i = 0; i < parms.size(); i++) { clzList[i] = parms.get(i).getClass(); } try { Constructor constructor = clazz.getConstructor(clzList); // clean up list.. Object retValue = constructor.newInstance(parms.toArray()); if (cleanUp) { parms.remove(0); } return retValue; } catch (NoSuchMethodException nsme) { // we should check alternative constructors // eg new ObjectImpl(Object object) is an ok constructor // when there is a String parameter. Constructor[] constructors = clazz.getConstructors(); for (int c = 0; c < constructors.length; c++) { Constructor constructor = constructors[c]; Class[] cclz = constructor.getParameterTypes(); boolean cStatus = true; if (clzList.length >= cclz.length) { for (int cc = 0; cc < cclz.length; cc++) { if (!cclz[cc].isAssignableFrom(clzList[cc])) { cStatus = false; } } } else { cStatus = false; } if (cStatus) { Object retValue = null; if (parms.size() == constructor.getParameterTypes().length) { retValue = constructor.newInstance(parms.toArray()); if (cleanUp) { parms.remove(0); } return retValue; } } } if (cleanUp) { parms.remove(0); } return null; } } } catch (Exception e) { if (log.isWarnEnabled()) { log.warn("Unknown error in getting object", e); } } return getObjectFromClass(clazz); }