List of usage examples for java.lang.reflect Modifier isInterface
public static boolean isInterface(int mod)
From source file:com.sunchenbin.store.feilong.core.lang.ClassUtil.java
/** * ??./*from w w w . jav a 2 s . c om*/ * * @param ownerClass * class * @return true * @see java.lang.Class#getModifiers() * @see java.lang.reflect.Modifier#isInterface(int) */ public static boolean isInterface(Class<?> ownerClass) { int flag = ownerClass.getModifiers();// ?? Java return Modifier.isInterface(flag);// ?? }
From source file:org.glowroot.agent.weaving.ClassAnalyzer.java
boolean isWeavingRequired() { checkNotNull(methodAdvisors);//from w w w . j a v a 2 s .c o m checkNotNull(methodsThatOnlyNowFulfillAdvice); if (Modifier.isInterface(thinClass.access())) { // FIXME only need to return true if any default methods have advice return !methodAdvisors.isEmpty() || !matchedMixinTypes.reweavable().isEmpty(); } return !methodAdvisors.isEmpty() || !methodsThatOnlyNowFulfillAdvice.isEmpty() || !matchedShimTypes.isEmpty() || !matchedMixinTypes.reweavable().isEmpty() || hasMainMethod || isClassLoader; }
From source file:org.hibernate.internal.util.ReflectHelper.java
/** * Determine if the given class is declared abstract. * * @param clazz The class to check./*from ww w . j a va2 s . c o m*/ * @return True if the class is abstract, false otherwise. */ public static boolean isAbstractClass(Class clazz) { int modifier = clazz.getModifiers(); return Modifier.isAbstract(modifier) || Modifier.isInterface(modifier); }
From source file:com.addthis.codec.config.Configs.java
/** should be roughly analagous to a removed method */ private static ConfigValue resolveType(Class<?> type, ConfigValue configValue, PluginMap pluginMap) { String classField = pluginMap.classField(); if (configValue.valueType() != ConfigValueType.OBJECT) { if ((type == null) || Modifier.isAbstract(type.getModifiers()) || Modifier.isInterface(type.getModifiers())) { if (configValue.valueType() == ConfigValueType.LIST) { Class<?> arrayType = pluginMap.arraySugar(); if (arrayType != null) { ConfigObject aliasDefaults = pluginMap.aliasDefaults("_array"); String arrayFieldName = aliasDefaults.toConfig().getString("_primary"); String arraySugarName = pluginMap.getLastAlias("_array"); return ConfigFactory.empty().root() .withValue(classField, ConfigValueFactory.fromAnyRef(arraySugarName, pluginMap.category() + " array sugar : " + pluginMap.config().root().get("_array").origin().description())) .withValue(arrayFieldName, configValue).withFallback(aliasDefaults); }//from ww w.j a v a 2 s . c om } } return configValue; } ConfigObject root = (ConfigObject) configValue; ConfigValue classValue = root.get(classField); // normal, explicit typing if ((classValue != null) && (classValue.valueType() == ConfigValueType.STRING)) { String classValueString = (String) classValue.unwrapped(); ConfigObject aliasDefaults = pluginMap.aliasDefaults(classValueString); return root.withFallback(aliasDefaults); } if ((type == null) || Modifier.isAbstract(type.getModifiers()) || Modifier.isInterface(type.getModifiers())) { // single key as type if (root.size() == 1) { String onlyKey = root.keySet().iterator().next(); try { pluginMap.getClass(onlyKey); // make sure key is a valid type ConfigValue onlyKeyValue = root.values().iterator().next(); ConfigObject aliasDefaults = pluginMap.aliasDefaults(onlyKey); if (onlyKeyValue.valueType() != ConfigValueType.OBJECT) { if (aliasDefaults.get("_primary") != null) { onlyKeyValue = onlyKeyValue.atPath((String) aliasDefaults.get("_primary").unwrapped()) .root(); } else { throw new ConfigException.WrongType(onlyKeyValue.origin(), onlyKey, "OBJECT", onlyKeyValue.valueType().toString()); } } ConfigObject fieldValues = (ConfigObject) onlyKeyValue; return fieldValues .withValue(classField, ConfigValueFactory.fromAnyRef(onlyKey, "single key to type from " + root.origin().description())) .withFallback(aliasDefaults); } catch (ClassNotFoundException ignored) { } } // inlined type String matched = null; for (String alias : pluginMap.inlinedAliases()) { if (root.get(alias) != null) { if (matched != null) { String message = String.format( "no type specified, more than one key, and both %s and %s match for inlined types.", matched, alias); throw new ConfigException.Parse(root.origin(), message); } matched = alias; } } if (matched != null) { ConfigObject aliasDefaults = pluginMap.aliasDefaults(matched); ConfigValue inlinedValue = root.get(matched); String primaryField = (String) aliasDefaults.get("_primary").unwrapped(); ConfigObject fieldValues = root.toConfig().withValue(primaryField, inlinedValue).root() .withoutKey(matched).withFallback(aliasDefaults); return fieldValues.withValue(classField, ConfigValueFactory.fromAnyRef(matched, "inlined key to type from " + root.origin().description())); } // default type ConfigValue defaultObject = pluginMap.config().root().get("_default"); if (defaultObject != null) { String defaultName = pluginMap.getLastAlias("_default"); ConfigObject aliasDefaults = pluginMap.aliasDefaults("_default"); return root .withValue(classField, ConfigValueFactory.fromAnyRef(defaultName, pluginMap.category() + " default type : " + defaultObject.origin().description())) .withFallback(aliasDefaults); } } return root; }
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 ww .j a v a2 s . com*/ * * 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: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./*from w w w . ja v a2 s .c o 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: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 */// w w w . j ava 2 s.com 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); }
From source file:org.deeplearning4j.nn.conf.NeuralNetConfiguration.java
private static synchronized void registerSubtypes(ObjectMapper mapper) { //Register concrete subtypes for JSON serialization List<Class<?>> classes = Arrays.<Class<?>>asList(InputPreProcessor.class, ILossFunction.class, IActivation.class, Layer.class, GraphVertex.class, ReconstructionDistribution.class); List<String> classNames = new ArrayList<>(6); for (Class<?> c : classes) classNames.add(c.getName());//w ww . j a v a 2 s .com // First: scan the classpath and find all instances of the 'baseClasses' classes if (subtypesClassCache == null) { //Check system property: String prop = System.getProperty(CUSTOM_FUNCTIONALITY); if (prop != null && !Boolean.parseBoolean(prop)) { subtypesClassCache = Collections.emptySet(); } else { List<Class<?>> interfaces = Arrays.<Class<?>>asList(InputPreProcessor.class, ILossFunction.class, IActivation.class, ReconstructionDistribution.class); List<Class<?>> classesList = Arrays.<Class<?>>asList(Layer.class, GraphVertex.class); Collection<URL> urls = ClasspathHelper.forClassLoader(); List<URL> scanUrls = new ArrayList<>(); for (URL u : urls) { String path = u.getPath(); if (!path.matches(".*/jre/lib/.*jar")) { //Skip JRE/JDK JARs scanUrls.add(u); } } Reflections reflections = new Reflections( new ConfigurationBuilder().filterInputsBy(new FilterBuilder().exclude("^(?!.*\\.class$).*$") //Consider only .class files (to avoid debug messages etc. on .dlls, etc //Exclude the following: the assumption here is that no custom functionality will ever be present // under these package name prefixes. These are all common dependencies for DL4J .exclude("^org.nd4j.*").exclude("^org.datavec.*").exclude("^org.bytedeco.*") //JavaCPP .exclude("^com.fasterxml.*")//Jackson .exclude("^org.apache.*") //Apache commons, Spark, log4j etc .exclude("^org.projectlombok.*").exclude("^com.twelvemonkeys.*") .exclude("^org.joda.*").exclude("^org.slf4j.*").exclude("^com.google.*") .exclude("^org.reflections.*").exclude("^ch.qos.*") //Logback ).addUrls(scanUrls).setScanners(new DL4JSubTypesScanner(interfaces, classesList))); org.reflections.Store store = reflections.getStore(); Iterable<String> subtypesByName = store.getAll(DL4JSubTypesScanner.class.getSimpleName(), classNames); Set<? extends Class<?>> subtypeClasses = Sets.newHashSet(ReflectionUtils.forNames(subtypesByName)); subtypesClassCache = new HashSet<>(); for (Class<?> c : subtypeClasses) { if (Modifier.isAbstract(c.getModifiers()) || Modifier.isInterface(c.getModifiers())) { //log.info("Skipping abstract/interface: {}",c); continue; } subtypesClassCache.add(c); } } } //Second: get all currently registered subtypes for this mapper Set<Class<?>> registeredSubtypes = new HashSet<>(); for (Class<?> c : classes) { AnnotatedClass ac = AnnotatedClass.construct(c, mapper.getSerializationConfig().getAnnotationIntrospector(), null); Collection<NamedType> types = mapper.getSubtypeResolver().collectAndResolveSubtypes(ac, mapper.getSerializationConfig(), mapper.getSerializationConfig().getAnnotationIntrospector()); for (NamedType nt : types) { registeredSubtypes.add(nt.getType()); } } //Third: register all _concrete_ subtypes that are not already registered List<NamedType> toRegister = new ArrayList<>(); for (Class<?> c : subtypesClassCache) { //Check if it's concrete or abstract... if (Modifier.isAbstract(c.getModifiers()) || Modifier.isInterface(c.getModifiers())) { //log.info("Skipping abstract/interface: {}",c); continue; } if (!registeredSubtypes.contains(c)) { String name; if (ClassUtils.isInnerClass(c)) { Class<?> c2 = c.getDeclaringClass(); name = c2.getSimpleName() + "$" + c.getSimpleName(); } else { name = c.getSimpleName(); } toRegister.add(new NamedType(c, name)); if (log.isDebugEnabled()) { for (Class<?> baseClass : classes) { if (baseClass.isAssignableFrom(c)) { log.debug("Registering class for JSON serialization: {} as subtype of {}", c.getName(), baseClass.getName()); break; } } } } } mapper.registerSubtypes(toRegister.toArray(new NamedType[toRegister.size()])); }
From source file:sx.blah.discord.modules.ModuleLoader.java
/** * Manually adds a module class to be considered for loading. * * @param clazz The module class./*from www . j a v a2s. c o m*/ */ public static void addModuleClass(Class<? extends IModule> clazz) { if (!Modifier.isAbstract(clazz.getModifiers()) && !Modifier.isInterface(clazz.getModifiers()) && !modules.contains(clazz)) { modules.add(clazz); } }