List of usage examples for java.lang Class getModifiers
@HotSpotIntrinsicCandidate public native int getModifiers();
From source file:adalid.core.XS1.java
static Class<?> getConcreteSuperclass(Class<?> c) { if (c == null) { return null; }//from w w w . j a va 2s . co m Class<?> s = c.getSuperclass(); if (s == null) { return null; } if (c.isAnonymousClass()) { return getConcreteSuperclass(s); } int modifiers = s.getModifiers(); if (Modifier.isAbstract(modifiers)) { return null; } if (s.getSimpleName().equals(c.getSimpleName())) { return getConcreteSuperclass(s); } return s; }
From source file:org.zilverline.util.ClassFinder.java
/** * Finds all classes that extend the class, searching in the listAllClasses ArrayList. * /* w ww. ja v a 2 s.co m*/ * @param theClass the parent class * @param listAllClasses the collection of classes to search in * @param listSubClasses the collection of discovered subclasses * @param innerClasses indicates whether inners classes should be included in the search */ private static void findAllSubclassesOneClass(Class theClass, List listAllClasses, List listSubClasses, boolean innerClasses) { Iterator iterClasses = null; String strClassName = null; Class c = null; boolean bIsSubclass = false; iterClasses = listAllClasses.iterator(); while (iterClasses.hasNext()) { strClassName = (String) iterClasses.next(); // only check classes if they are not inner classes // or we intend to check for inner classes if ((strClassName.indexOf("$") == -1) || innerClasses) { // might throw an exception, assume this is ignorable try { c = Class.forName(strClassName, false, Thread.currentThread().getContextClassLoader()); if (!c.isInterface() && !Modifier.isAbstract(c.getModifiers())) { bIsSubclass = theClass.isAssignableFrom(c); } else { bIsSubclass = false; } if (bIsSubclass) { listSubClasses.add(strClassName); } } catch (Throwable ignored) { } } } }
From source file:stormy.pythian.service.description.ClassRepository.java
public Set<Class<? extends Component>> getComponentClasses() { return filter(reflections.getSubTypesOf(Component.class), new Predicate<Class<?>>() { public boolean apply(Class<?> input) { return !Modifier.isAbstract(input.getModifiers()); }/*from w w w .j a v a2 s. c om*/ }); }
From source file:stormy.pythian.service.description.ClassRepository.java
public Set<Class<? extends PythianState>> getStateClasses() { return filter(reflections.getSubTypesOf(PythianState.class), new Predicate<Class<?>>() { public boolean apply(Class<?> input) { return !Modifier.isAbstract(input.getModifiers()); }/*from w ww . ja va 2 s. co m*/ }); }
From source file:MyJavaP.java
/** * Format the fields and methods of one class, given its name. *//*from w w w .jav a 2 s . co m*/ protected void doClass(String className) { try { Class c = Class.forName(className); System.out.println(Modifier.toString(c.getModifiers()) + ' ' + c + " {"); int mods; Field fields[] = c.getDeclaredFields(); for (int i = 0; i < fields.length; i++) { if (!Modifier.isPrivate(fields[i].getModifiers()) && !Modifier.isProtected(fields[i].getModifiers())) System.out.println("\t" + fields[i]); } Constructor[] constructors = c.getConstructors(); for (int j = 0; j < constructors.length; j++) { Constructor constructor = constructors[j]; System.out.println("\t" + constructor); } Method methods[] = c.getDeclaredMethods(); for (int i = 0; i < methods.length; i++) { if (!Modifier.isPrivate(methods[i].getModifiers()) && !Modifier.isProtected(methods[i].getModifiers())) System.out.println("\t" + methods[i]); } System.out.println("}"); } catch (ClassNotFoundException e) { System.err.println("Error: Class " + className + " not found!"); } catch (Exception e) { System.err.println(e); } }
From source file:org.apache.camel.blueprint.PackageScanRouteBuilderFinder.java
/** * Returns true if the object is non-abstract and supports a zero argument constructor *//* w w w . ja v a 2s . c o m*/ protected boolean isValidClass(Class type) { if (!Modifier.isAbstract(type.getModifiers()) && !type.isInterface()) { return true; } return false; }
From source file:org.springframework.jdbc.core.JdbcOperationsUtils.java
public static final void validatePropertyValue(String id, String propName, Object propValue, ConversionService converter) {/*from www. ja v a 2 s . c om*/ if (StringUtils.isEmpty(propName)) { throw new IllegalStateException("validatePropertyValue(" + id + ") no property name"); } if (propValue == null) { throw new IllegalStateException("validatePropertyValue(" + id + ")[" + propName + "] no value"); } if (!(propValue instanceof Serializable)) { throw new IllegalStateException("validatePropertyValue(" + id + ")[" + propName + "] not serializable"); } Class<?> propType = resolveEffectivePropertyType(propValue); if (Date.class.isAssignableFrom(propType) || Calendar.class.isAssignableFrom(propType)) { return; // Date(s) have a special handling } if (propType == Class.class) { Class<?> valueClass = (Class<?>) propValue; if (Proxy.isProxyClass(valueClass)) { throw new IllegalStateException("validatePropertyValue(" + id + ")[" + propName + "] proxies N/A"); } if (valueClass.isAnonymousClass()) { throw new IllegalStateException("validatePropertyValue(" + id + ")[" + propName + "]" + " anonymous classes N/A: " + valueClass.getName()); } if (valueClass.isLocalClass()) { throw new IllegalStateException("validatePropertyValue(" + id + ")[" + propName + "]" + " local classes N/A: " + valueClass.getName()); } if (valueClass.isArray()) { throw new IllegalStateException("validatePropertyValue(" + id + ")[" + propName + "]" + " array classes N/A: " + valueClass.getName()); } int mods = valueClass.getModifiers(); if (!Modifier.isPublic(mods)) { throw new IllegalStateException("validatePropertyValue(" + id + ")[" + propName + "]" + " non-public classes N/A: " + valueClass.getName()); } } if (!converter.canConvert(String.class, propType)) { throw new IllegalStateException("validatePropertyValue(" + id + ")[" + propName + "]" + " cannot convert a string to a " + propType.getSimpleName()); } }
From source file:org.pentaho.reporting.engine.classic.core.metadata.ExpressionRegistry.java
public void registerExpression(final ExpressionMetaData metaData) { if (metaData == null) { throw new NullPointerException(); }// w w w .jav a 2 s . c o m final Class type = metaData.getExpressionType(); final int modifiers = type.getModifiers(); if (Modifier.isAbstract(modifiers) || Modifier.isInterface(modifiers)) { throw new IllegalArgumentException("Expression-Implementation cannot be abstract or an interface."); } this.backend.put(type.getName(), metaData); }
From source file:org.pentaho.reporting.engine.classic.core.metadata.ReportPreProcessorRegistry.java
public void registerReportPreProcessor(final ReportPreProcessorMetaData metaData) { if (metaData == null) { throw new NullPointerException(); }//w w w .j a va2s . c om final Class type = metaData.getPreProcessorType(); final int modifiers = type.getModifiers(); if (Modifier.isAbstract(modifiers) || Modifier.isInterface(modifiers)) { throw new IllegalArgumentException( "report-preprocessor-Implementation cannot be abstract or an interface."); } this.backend.put(type.getName(), metaData); }
From source file:cat.albirar.framework.proxy.ProxyFactory.java
/** * Create a proxy for the indicated type. * @param handler The handler/*from w w w . ja v a 2s . c om*/ * @param type The type, should to be a concrete class type * @return The proxy */ @SuppressWarnings("unchecked") private <T> T newProxyForConcreteClass(org.springframework.cglib.proxy.Callback handler, Class<T> type) { Enhancer enhancer; Assert.isTrue(!Modifier.isAbstract(type.getModifiers()), "The type should to be a concrete class"); enhancer = new Enhancer(); enhancer.setSuperclass(type); enhancer.setClassLoader(type.getClassLoader()); enhancer.setCallback(handler); return (T) enhancer.create(); }