List of usage examples for java.lang.reflect Modifier isAbstract
public static boolean isAbstract(int mod)
From source file:jef.tools.collection.CollectionUtil.java
/** * ????/*w w w . jav a 2 s. c o m*/ */ @SuppressWarnings("rawtypes") public static Object createContainerInstance(ClassEx collectionType, int size) { Class raw = collectionType.getWrappered(); try { if (collectionType.isArray()) { if (size < 0) size = 0; Object array = Array.newInstance(GenericUtils.getRawClass(collectionType.getComponentType()), size); return array; } else if (!Modifier.isAbstract(collectionType.getModifiers())) {// ?? Object c = raw.newInstance(); return c; } else if (Object.class == raw || raw == List.class || raw == AbstractList.class) { return new ArrayList(); } else if (raw == Set.class || raw == AbstractSet.class) { return new HashSet(); } else if (raw == Map.class || raw == AbstractMap.class) { return new HashMap(); } else if (raw == Queue.class || raw == AbstractQueue.class) { return new LinkedList(); } else { throw new IllegalArgumentException( "Unknown collection class for create:" + collectionType.getName()); } } catch (InstantiationException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } }
From source file:org.eclipse.wb.internal.rcp.databinding.model.beans.bindables.BeanSupport.java
/** * @return {@link PropertyDescriptor} properties for given bean {@link Class}. *//*from w w w.j ava2 s. c o m*/ public static List<PropertyDescriptor> getPropertyDescriptors(Class<?> beanClass) throws Exception { List<PropertyDescriptor> descriptors = Lists.newArrayList(); // handle interfaces if (beanClass.isInterface() || Modifier.isAbstract(beanClass.getModifiers())) { List<Class<?>> interfaces = CoreUtils.cast(ClassUtils.getAllInterfaces(beanClass)); for (Class<?> i : interfaces) { BeanInfo beanInfo = Introspector.getBeanInfo(i); addDescriptors(descriptors, beanInfo.getPropertyDescriptors()); } } // handle bean BeanInfo beanInfo = Introspector.getBeanInfo(beanClass); addDescriptors(descriptors, beanInfo.getPropertyDescriptors()); // return descriptors; }
From source file:com.datatorrent.stram.client.StramAppLauncher.java
/** * Scan the application jar file entries for configuration classes. * This needs to occur in a class loader with access to the application dependencies. *//*from w ww. j a v a2 s . co m*/ private void findAppConfigClasses(List<String> classFileNames) { URLClassLoader cl = URLClassLoader .newInstance(launchDependencies.toArray(new URL[launchDependencies.size()])); for (final String classFileName : classFileNames) { final String className = classFileName.replace('/', '.').substring(0, classFileName.length() - 6); try { final Class<?> clazz = cl.loadClass(className); if (!Modifier.isAbstract(clazz.getModifiers()) && StreamingApplication.class.isAssignableFrom(clazz)) { final AppFactory appConfig = new AppFactory() { @Override public String getName() { return classFileName; } @Override public String getDisplayName() { ApplicationAnnotation an = clazz.getAnnotation(ApplicationAnnotation.class); if (an != null) { return an.name(); } else { return classFileName; } } @Override public LogicalPlan createApp(LogicalPlanConfiguration conf) { // load class from current context class loader Class<? extends StreamingApplication> c = StramUtils.classForName(className, StreamingApplication.class); StreamingApplication app = StramUtils.newInstance(c); LogicalPlan dag = new LogicalPlan(); conf.prepareDAG(dag, app, getName()); return dag; } }; appResourceList.add(appConfig); } } catch (Throwable e) { // java.lang.NoClassDefFoundError LOG.error("Unable to load class: " + className + " " + e); } } }
From source file:org.apache.ojb.broker.metadata.ClassDescriptor.java
/** * sets the class object described by this descriptor. * @param c the class to describe//from w w w. j a v a 2s .c o m */ public void setClassOfObject(Class c) { m_Class = c; isAbstract = Modifier.isAbstract(m_Class.getModifiers()); // TODO : Shouldn't the HashMap in DescriptorRepository be updated as well? }
From source file:grails.plugins.DefaultGrailsPluginManager.java
private List<GrailsPlugin> findCorePlugins() { CorePluginFinder finder = new CorePluginFinder(application); finder.setParentApplicationContext(parentCtx); List<GrailsPlugin> grailsCorePlugins = new ArrayList<GrailsPlugin>(); final Class<?>[] corePluginClasses = finder.getPluginClasses(); for (Class<?> pluginClass : corePluginClasses) { if (pluginClass != null && !Modifier.isAbstract(pluginClass.getModifiers()) && pluginClass != DefaultGrailsPlugin.class) { final BinaryGrailsPluginDescriptor binaryDescriptor = finder.getBinaryDescriptor(pluginClass); GrailsPlugin plugin;//from ww w . j a v a 2 s . c om if (binaryDescriptor != null) { plugin = createBinaryGrailsPlugin(pluginClass, binaryDescriptor); } else { plugin = createGrailsPlugin(pluginClass); } plugin.setApplicationContext(applicationContext); grailsCorePlugins.add(plugin); } } return grailsCorePlugins; }
From source file:adalid.core.Operation.java
void initialiseFields(Class<?> clazz) { Class<?> c;//from w ww.ja v a 2 s.co m int d, r; String name; Class<?> type; int modifiers; boolean restricted; Object o; int depth = depth(); int round = round(); Class<?>[] classes = new Class<?>[] { Parameter.class, Expression.class }; Class<?> dac = getClass(); Class<?> top = Operation.class; int i = ArrayUtils.indexOf(classes, clazz); if (i != ArrayUtils.INDEX_NOT_FOUND) { c = classes[i]; for (Field field : XS1.getFields(dac, top)) { field.setAccessible(true); logger.trace(field); name = field.getName(); type = field.getType(); if (!c.isAssignableFrom(type)) { continue; } modifiers = type.getModifiers(); if (type.isInterface() && Expression.class.isAssignableFrom(type)) { restricted = false; } else { restricted = Modifier.isAbstract(modifiers); } restricted = restricted || !Modifier.isPublic(modifiers); if (restricted) { continue; } modifiers = field.getModifiers(); restricted = Modifier.isStatic(modifiers) || Modifier.isFinal(modifiers); if (restricted) { continue; } String errmsg = "failed to create a new instance of field \"" + field + "\" at " + this; try { o = field.get(this); if (o == null) { logger.debug(message(type, name, o, depth, round)); o = XS1.initialiseField(this, field); if (o == null) { logger.debug(message(type, name, o, depth, round)); // throw new RuntimeException(message(type, name, o, depth, round)); } else { logger.debug(message(type, name, o, depth, round)); field.set(this, o); } } } catch (IllegalArgumentException | IllegalAccessException ex) { throw new InstantiationRuntimeException(errmsg, ex); } } } }
From source file:com.visural.stereotyped.ui.service.StereotypeServiceImpl.java
@Cache public List<Class<? extends StereotypeRenderer>> getRenderers() { try {/*from w w w.ja v a 2 s .c o m*/ List<Class<? extends StereotypeRenderer>> buildList = new ArrayList<Class<? extends StereotypeRenderer>>(); ClassFinder cf = new ClassFinder("", true); cf.addInterfaceFilter(StereotypeRenderer.class); Set<Class> results = cf.find(); for (Class clazz : results) { // mustn't add abstract classes or stereotypes if (!Modifier.isAbstract(clazz.getModifiers())) { buildList.add(clazz); } } Collections.sort(buildList, new Comparator() { public int compare(Object o1, Object o2) { Class c1 = (Class) o1; Class c2 = (Class) o2; return c1.getName().compareTo(c2.getName()); } }); return buildList; } catch (ClassNotFoundException ex) { Logger.getLogger(PrototypeEditor.class.getName()).log(Level.SEVERE, null, ex); throw new IllegalStateException("Unable to load list of components.", ex); } }
From source file:org.gradle.model.internal.manage.schema.extract.ManagedImplTypeSchemaExtractionStrategySupport.java
private void validateType(ModelType<?> type, ModelSchemaExtractionContext<?> extractionContext) { Class<?> typeClass = type.getConcreteClass(); if (!typeClass.isInterface() && !Modifier.isAbstract(typeClass.getModifiers())) { throw new InvalidManagedModelElementTypeException(extractionContext, "must be defined as an interface or an abstract class."); }//w w w.j a v a2 s . c o m if (typeClass.getTypeParameters().length > 0) { throw new InvalidManagedModelElementTypeException(extractionContext, "cannot be a parameterized type."); } Constructor<?> customConstructor = findCustomConstructor(typeClass); if (customConstructor != null) { throw invalidMethod(extractionContext, "custom constructors are not allowed", customConstructor); } ensureNoInstanceScopedFields(extractionContext, typeClass); ensureNoProtectedOrPrivateMethods(extractionContext, typeClass); }
From source file:adalid.core.EntityAtlas.java
@SuppressWarnings("deprecation") void initialiseFields(Class<?> clazz) { track("initialiseFields", _declaringArtifact, clazz.getSimpleName()); Class<?> c;/*from ww w. j a v a 2 s.c o m*/ int d, r; String name; String key; String pattern = "there are several fields for operation {0}"; String message; Class<?> type; Class<?> decl; Class<?> operationClass; Field operationField; int modifiers; boolean restricted; Object o; int depth = _declaringArtifact.depth(); int round = _declaringArtifact.round(); Class<?>[] classes = new Class<?>[] { Property.class, Key.class, Tab.class, View.class, Instance.class, NamedValue.class, Expression.class, Transition.class, Operation.class, Trigger.class }; Class<?> dac = _declaringArtifact.getClass(); Class<?> top = Entity.class; int i = ArrayUtils.indexOf(classes, clazz); if (i != ArrayUtils.INDEX_NOT_FOUND) { c = classes[i]; for (Field field : XS1.getFields(dac, top)) { field.setAccessible(true); logger.trace(field); name = field.getName(); type = field.getType(); decl = field.getDeclaringClass(); if (!c.isAssignableFrom(type)) { continue; } if (c.equals(Expression.class) && Property.class.isAssignableFrom(type)) { continue; } // TODO: extension handling if (field.isAnnotationPresent(Extension.class) && Entity.class.isAssignableFrom(type)) { // if (!dac.equals(decl) || !dac.isAssignableFrom(type)) { // continue; // } continue; } modifiers = type.getModifiers(); if (NamedValue.class.isAssignableFrom(type) || Expression.class.isAssignableFrom(type)) { restricted = false; } else { restricted = type.isInterface() || Modifier.isAbstract(modifiers); } restricted = restricted || !Modifier.isPublic(modifiers); if (restricted) { continue; } modifiers = field.getModifiers(); restricted = Modifier.isPrivate(modifiers); if (restricted) { continue; } restricted = Modifier.isStatic(modifiers) || Modifier.isFinal(modifiers); if (restricted) { continue; } if (Operation.class.isAssignableFrom(type)) { key = type.getSimpleName(); operationClass = _operationClasses.get(key); if (operationClass != null) { operationField = _operationFields.get(key); if (operationField == null) { _operationFields.put(key, field); } else { message = MessageFormat.format(pattern, operationClass.getName()); logger.warn(message); TLC.getProject().getParser().increaseWarningCount(); } } } String errmsg = "failed to create a new instance of field \"" + field + "\" at " + _declaringArtifact; try { o = field.get(_declaringArtifact); if (o == null) { logger.debug(message(type, name, o, depth, round)); o = XS1.initialiseField(_declaringArtifact, field); if (o == null) { logger.debug(message(type, name, o, depth, round)); // throw new RuntimeException(message(type, name, o, depth, round)); } else { logger.debug(message(type, name, o, depth, round)); field.set(_declaringArtifact, o); } } } catch (IllegalArgumentException | IllegalAccessException ex) { throw new InstantiationRuntimeException(errmsg, ex); } } } }
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 ww w . j a 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); }