List of usage examples for java.lang.reflect Modifier isAbstract
public static boolean isAbstract(int mod)
From source file:org.apache.asterix.om.typecomputer.ExceptionTest.java
@Test public void test() throws Exception { // Tests all usual type computers. Reflections reflections = new Reflections("org.apache.asterix.om.typecomputer", new SubTypesScanner(false)); Set<Class<? extends IResultTypeComputer>> classes = reflections.getSubTypesOf(IResultTypeComputer.class); int numTypeComputers = 0; for (Class<? extends IResultTypeComputer> c : classes) { if (Modifier.isAbstract(c.getModifiers())) { continue; }/*from w w w . j a v a 2 s . c o m*/ testTypeComputer(c); ++numTypeComputers; } // Currently, there are 78 type computers. Assert.assertTrue(numTypeComputers >= 78); }
From source file:org.pentaho.reporting.libraries.resourceloader.factory.drawable.DrawableWrapper.java
public DrawableWrapper(final Object maybeDrawable) { if (maybeDrawable == null) { throw new NullPointerException("Drawable must not be null"); }/* w ww . j a v a 2 s .c o m*/ if (maybeDrawable instanceof DrawableWrapper) { throw new IllegalArgumentException("Cannot wrap around a drawable-wrapper"); } final Class<?> aClass = maybeDrawable.getClass(); try { drawMethod = aClass.getMethod("draw", PARAMETER_TYPES); final int modifiers = drawMethod.getModifiers(); if (Modifier.isPublic(modifiers) == false || Modifier.isAbstract(modifiers) || Modifier.isStatic(modifiers)) { if (logger.isWarnEnabled()) { logger.warn(String.format("DrawMethod is not valid: %s#%s", aClass, drawMethod)); // NON-NLS } drawMethod = null; } } catch (NoSuchMethodException e) { // ignore exception if (logger.isWarnEnabled()) { logger.warn(String.format("The object is not a drawable: %s", aClass)); // NON-NLS } drawMethod = null; } if (drawMethod != null) { try { isKeepAspectRatioMethod = aClass.getMethod("isPreserveAspectRatio", EMPTY_PARAMS); final int modifiers = isKeepAspectRatioMethod.getModifiers(); if (Modifier.isPublic(modifiers) == false || Modifier.isAbstract(modifiers) || Modifier.isStatic(modifiers) || Boolean.TYPE.equals(isKeepAspectRatioMethod.getReturnType()) == false) { isKeepAspectRatioMethod = null; } } catch (NoSuchMethodException e) { // ignored .. } try { getPreferredSizeMethod = aClass.getMethod("getPreferredSize", EMPTY_PARAMS); final int modifiers = getPreferredSizeMethod.getModifiers(); if (Modifier.isPublic(modifiers) == false || Modifier.isAbstract(modifiers) || Modifier.isStatic(modifiers) || Dimension.class.isAssignableFrom(getPreferredSizeMethod.getReturnType()) == false) { getPreferredSizeMethod = null; } } catch (NoSuchMethodException e) { // ignored .. } } backend = maybeDrawable; }
From source file:cat.albirar.framework.proxy.ProxyFactory.java
/** * Create a proxy for the indicated type. * @param handler The handler//from w ww . ja v a 2s.c o m * @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(); }
From source file:com.agimatec.validation.jsr303.util.SecureActions.java
private static void setAccessibility(Field field) { if (!Modifier.isPublic(field.getModifiers()) || (Modifier.isPublic(field.getModifiers()) && Modifier.isAbstract(field.getModifiers()))) { field.setAccessible(true);//from w w w. j a v a2s . c o m } }
From source file:controllers.ModuleController.java
private static List<ModuleModel> getNextModules(String input) { // get all the supplied view models. List<ViewModel> suppliedViewModels = Lists.newArrayList(); JsonNode inputJson = Json.parse(input); // convert json nodes to view models. if (inputJson != null && inputJson.isArray()) { suppliedViewModels = Lists/*w ww . j a v a 2s . co m*/ .newArrayList(Iterators.transform(inputJson.getElements(), new Function<JsonNode, ViewModel>() { @Override @Nullable public ViewModel apply(@Nullable JsonNode input) { if (!input.isTextual()) { return null; } return createViewModelQuietly( fetchResource(UuidUtils.create(input.asText()), PersistentObject.class), null); } })); } else if (inputJson != null && inputJson.isObject()) { suppliedViewModels.add(createViewModelQuietly(inputJson, null)); } suppliedViewModels = Lists.newArrayList(Iterables.filter(suppliedViewModels, Predicates.notNull())); // get all the modules that can use these inputs. Map<Module, Double> nullModulesMap = Maps.newHashMap(); Map<Module, Double> modulesMap = Maps.newHashMap(); Reflections reflections = new Reflections("controllers.modules", Play.application().classloader()); for (Class<? extends Module> moduleClass : reflections.getSubTypesOf(Module.class)) { // we're not interested in abstract classes. if (Modifier.isAbstract(moduleClass.getModifiers())) { continue; } // get the Module.Requires/Requireses annotation for each module class. // the requirements within each Module.Require are ANDed. // the requirements across multiple Module.Require annotations are ORed. List<Module.Requires> requireds = Lists.newArrayList(); if (moduleClass.isAnnotationPresent(Module.Requires.class)) { requireds.add(moduleClass.getAnnotation(Module.Requires.class)); } if (moduleClass.isAnnotationPresent(Module.Requireses.class)) { Collections.addAll(requireds, moduleClass.getAnnotation(Module.Requireses.class).value()); } if (requireds.size() == 0) { requireds.add(null); } for (Module.Requires required : requireds) { final Set<Class<? extends ViewModel>> requiredViewModelClasses = Sets.newHashSet(); if (required != null) { Collections.addAll(requiredViewModelClasses, required.value()); } // get all the supplied view modules that are relevant to this module. List<ViewModel> usefulViewModels = Lists .newArrayList(Iterables.filter(suppliedViewModels, new Predicate<ViewModel>() { @Override public boolean apply(@Nullable ViewModel input) { // if this class is required, then return true. if (requiredViewModelClasses.contains(input.getClass())) { return true; } // if any of its super classes are required, that also works. for (Class<?> superClass : ClassUtils.getAllSuperclasses(input.getClass())) { if (requiredViewModelClasses.contains(superClass)) { return true; } } return false; } })); // if all the requirements were satisfied. if (usefulViewModels.size() >= requiredViewModelClasses.size()) { // try to create an instance of the module. Module module = null; try { module = moduleClass.newInstance(); module.setViewModels(usefulViewModels); } catch (InstantiationException | IllegalAccessException | IllegalArgumentException e) { module = null; } finally { // if no module was created, just ignore. if (module == null) { continue; } } // let's not divide by zero! double relevancyScore = suppliedViewModels.size() != 0 ? usefulViewModels.size() / (double) suppliedViewModels.size() : 1.0; // keep null modules separate. Map<Module, Double> targetModulesMap = null; if (requiredViewModelClasses.size() > 0) { // if a module of this type does not exist, add it. if (Maps.filterKeys(modulesMap, Predicates.instanceOf(moduleClass)).size() == 0) { targetModulesMap = modulesMap; } } else { targetModulesMap = nullModulesMap; } if (targetModulesMap != null) { targetModulesMap.put(module, relevancyScore); } } } } // use null modules only if there are no regular ones. if (modulesMap.size() == 0) { modulesMap = nullModulesMap; } // convert to view models. Set<ModuleModel> moduleViewModels = Sets.newHashSet( Iterables.transform(modulesMap.entrySet(), new Function<Entry<Module, Double>, ModuleModel>() { @Override @Nullable public ModuleModel apply(@Nullable Entry<Module, Double> input) { return new ModuleModel(input.getKey()).setRelevancyScore(input.getValue()); } })); // order first by relevance and then by name. return Ordering.from(new Comparator<ModuleModel>() { @Override public int compare(ModuleModel o1, ModuleModel o2) { int relDiff = (int) Math.round((o2.relevancyScore - o1.relevancyScore) * 1000); if (relDiff == 0) { return o1.name.compareTo(o2.name); } return relDiff; } }).sortedCopy(moduleViewModels); }
From source file:com.threewks.thundr.injection.InjectionContextImpl.java
@Override public <T> InjectorBuilder<T> inject(Class<T> type) { if (!TypeIntrospector.isABasicType(type) && (type.isInterface() || Modifier.isAbstract(type.getModifiers()))) { throw new InjectionException( "Unable to inject the type '%s' - you cannot inject interfaces or abstract classes", type.getName());//from w w w . jav a 2 s.co m } return new InjectorBuilder<T>(this, type); }
From source file:org.mule.util.ClassUtils.java
public static boolean isConcrete(Class<?> clazz) { if (clazz == null) { throw new IllegalArgumentException("clazz may not be null"); }//from ww w . j a v a 2s . com return !(clazz.isInterface() || Modifier.isAbstract(clazz.getModifiers())); }
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 ww w . ja v a 2 s.c om*/ * @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:net.udidb.engine.ops.impls.help.HelpMessageProvider.java
@Inject public HelpMessageProvider(@Named("OP_PACKAGES") String[] opPackages) { Set<URL> packages = new HashSet<>(); for (String opPackage : opPackages) { packages.addAll(ClasspathHelper.forPackage(opPackage)); }// w ww.ja v a 2s.co m Reflections reflections = new Reflections(packages, new SubTypesScanner()); for (Class<? extends Operation> opClass : reflections.getSubTypesOf(Operation.class)) { if (Modifier.isAbstract(opClass.getModifiers())) continue; HelpMessage[] helpMessages = opClass.getAnnotationsByType(HelpMessage.class); DisplayName displayName = opClass.getAnnotation(DisplayName.class); if (helpMessages.length == 0 || displayName == null) { throw new RuntimeException(opClass.getSimpleName() + " is an invalid Operation"); } String name = displayName.value(); HelpMessageDescriptor descriptor = new HelpMessageDescriptor(); descriptor.global = opClass.isAnnotationPresent(GlobalOperation.class); descriptor.shortMessage = selectMessage(helpMessages); descriptor.longMessage = createLongMessage(name, descriptor.shortMessage, opClass); helpMessageDescriptors.put(name, descriptor); } }
From source file:cz.lbenda.common.ClassLoaderHelper.java
@SuppressWarnings("unchecked") public static List<String> instancesOfClass(Class clazz, List<String> libs, boolean abstractClass, boolean interf) { List<String> classNames = new ArrayList<>(); ClassLoader clr = createClassLoader(libs, false); List<String> result = new ArrayList<>(); libs.forEach(lib -> {//from w ww.j av a2 s .c o m try (ZipFile file = new ZipFile(lib)) { file.stream().forEach(entry -> { if (entry.getName().equals("META-INF/services/" + clazz.getName())) { try { String string = IOUtils.toString(file.getInputStream(entry)); String[] lines = string.split("\n"); for (String line : lines) { result.add(line.trim()); } } catch (IOException e) { throw new RuntimeException(e); } } else if (entry.getName().endsWith(".class")) { String className = entry.getName().substring(0, entry.getName().length() - 6).replace("/", "."); classNames.add(className); } }); } catch (IOException e) { throw new RuntimeException(e); } }); classNames.forEach(cc -> { try { Class cla = clr.loadClass(cc); if ((interf || !cla.isInterface()) && (abstractClass || !Modifier.isAbstract(cla.getModifiers())) && clazz.isAssignableFrom(cla)) { if (!result.contains(cc)) { result.add(cc); } } } catch (ClassNotFoundException | NoClassDefFoundError e) { /* It's common to try to create class which haven't class which need*/ } }); return result; }