List of usage examples for java.lang Class getModifiers
@HotSpotIntrinsicCandidate public native int getModifiers();
From source file:edu.northwestern.bioinformatics.studycalendar.xml.writers.ChangeableXmlSerializerFactoryTest.java
@SuppressWarnings({ "RawUseOfParameterizedType" }) public void testASerializerCanBeBuiltForEveryChangeable() throws Exception { List<String> errors = new ArrayList<String>(); for (Class<? extends Changeable> aClass : domainReflections.getSubTypesOf(Changeable.class)) { if (!Modifier.isAbstract(aClass.getModifiers()) && !aClass.isAnonymousClass()) { Changeable c = aClass.newInstance(); try { factory.createXmlSerializer(c); } catch (StudyCalendarError sce) { errors.add(String.format("Failure with %s: %s", c, sce.getMessage())); }//w ww . j a va 2 s. c om } } if (!errors.isEmpty()) { fail(StringUtils.join(errors.iterator(), '\n')); } }
From source file:edu.northwestern.bioinformatics.studycalendar.xml.writers.ChangeableXmlSerializerFactoryTest.java
@SuppressWarnings({ "RawUseOfParameterizedType" }) public void testASerializerCanBeBuiltForEveryElementCorrespondingToAChangeable() throws Exception { List<String> errors = new ArrayList<String>(); for (Class<? extends Changeable> aClass : domainReflections.getSubTypesOf(Changeable.class)) { if (!Modifier.isAbstract(aClass.getModifiers()) && !aClass.isAnonymousClass()) { XsdElement x = XsdElement.forCorrespondingClass(aClass); try { factory.createXmlSerializer(x.create()); } catch (StudyCalendarError sce) { errors.add(String.format("Failure with %s: %s", x, sce.getMessage())); }/*from ww w.j ava2 s . c om*/ } } if (!errors.isEmpty()) { fail(StringUtils.join(errors.iterator(), '\n')); } }
From source file:alluxio.shell.AlluxioShell.java
/** * Uses reflection to get all the {@link ShellCommand} classes and store them in a map. *///from w ww .j av a2 s . co m private void loadCommands() { String pkgName = ShellCommand.class.getPackage().getName(); Reflections reflections = new Reflections(pkgName); for (Class<? extends ShellCommand> cls : reflections.getSubTypesOf(ShellCommand.class)) { // Only instantiate a concrete class if (!Modifier.isAbstract(cls.getModifiers())) { ShellCommand cmd; try { cmd = CommonUtils.createNewClassInstance(cls, new Class[] { Configuration.class, FileSystem.class }, new Object[] { mConfiguration, mFileSystem }); } catch (Exception e) { throw Throwables.propagate(e); } mCommands.put(cmd.getCommandName(), cmd); } } }
From source file:org.apache.syncope.client.console.init.ImplementationClassNamesLoader.java
@Override @SuppressWarnings("unchecked") public void load() { previewers = new ArrayList<>(); extPanels = new ArrayList<>(); ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider( false);/*from w ww.ja v a2s. c om*/ scanner.addIncludeFilter(new AssignableTypeFilter(AbstractBinaryPreviewer.class)); scanner.addIncludeFilter(new AssignableTypeFilter(AbstractExtensionPanel.class)); for (BeanDefinition bd : scanner.findCandidateComponents(StringUtils.EMPTY)) { try { Class<?> clazz = ClassUtils.resolveClassName(bd.getBeanClassName(), ClassUtils.getDefaultClassLoader()); boolean isAbsractClazz = Modifier.isAbstract(clazz.getModifiers()); if (AbstractBinaryPreviewer.class.isAssignableFrom(clazz) && !isAbsractClazz) { previewers.add((Class<? extends AbstractBinaryPreviewer>) clazz); } else if (AbstractExtensionPanel.class.isAssignableFrom(clazz) && !isAbsractClazz) { extPanels.add((Class<? extends AbstractExtensionPanel>) clazz); } } catch (Throwable t) { LOG.warn("Could not inspect class {}", bd.getBeanClassName(), t); } } previewers = Collections.unmodifiableList(previewers); extPanels = Collections.unmodifiableList(extPanels); LOG.debug("Binary previewers found: {}", previewers); LOG.debug("Extension panels found: {}", extPanels); }
From source file:com.geodevv.testing.irmina.IrminaContextLoader.java
private boolean isStaticNonPrivateAndNonFinal(Class<?> clazz) { Assert.notNull(clazz, "Class must not be null"); int modifiers = clazz.getModifiers(); return (Modifier.isStatic(modifiers) && !Modifier.isPrivate(modifiers) && !Modifier.isFinal(modifiers)); }
From source file:org.makersoft.mvc.builder.PackageBasedUrlPathBuilder.java
/** * Interfaces, enums, annotations, and abstract classes cannot be instantiated. * /*from w ww . j a v a 2 s .c o m*/ * @param controllerClass * class to check * @return returns true if the class cannot be instantiated or should be ignored */ protected boolean cannotInstantiate(Class<?> controllerClass) { return controllerClass.isAnnotation() || controllerClass.isInterface() || controllerClass.isEnum() || (controllerClass.getModifiers() & Modifier.ABSTRACT) != 0 || controllerClass.isAnonymousClass(); }
From source file:org.syncope.core.rest.controller.ConfigurationController.java
@PreAuthorize("hasRole('CONFIGURATION_LIST')") @RequestMapping(method = RequestMethod.GET, value = "/validators") public ModelAndView getValidators() { CachingMetadataReaderFactory cachingMetadataReaderFactory = new CachingMetadataReaderFactory(); Set<String> validators = new HashSet<String>(); try {//w w w .j av a 2s .c o m for (Resource resource : resResolver .getResources("classpath:org/syncope/core/persistence/validation/" + "attrvalue/*.class")) { ClassMetadata metadata = cachingMetadataReaderFactory.getMetadataReader(resource) .getClassMetadata(); if (ArrayUtils.contains(metadata.getInterfaceNames(), Validator.class.getName()) || AbstractValidator.class.getName().equals(metadata.getSuperClassName())) { try { Class jobClass = Class.forName(metadata.getClassName()); if (!Modifier.isAbstract(jobClass.getModifiers())) { validators.add(jobClass.getName()); } } catch (ClassNotFoundException e) { LOG.error("Could not load class {}", metadata.getClassName(), e); } } } } catch (IOException e) { LOG.error("While searching for class implementing {}", Validator.class.getName(), e); } return new ModelAndView().addObject(validators); }
From source file:org.unitils.inject.core.TestedObjectService.java
/** * Creates an instance of the tested object with the given type. * * @param testedObjectType The type of the tested object, not null * @return The instance, null if it could not be created *///w w w .ja v a 2s.c om public Object createTestedObject(Class<?> testedObjectType) { if (testedObjectType.isInterface()) { logger.warn( "Tested object could not be created. Tested object type is an interface: " + testedObjectType); return null; } if (isAbstract(testedObjectType.getModifiers())) { logger.warn("Tested object is not automatically created. Tested object type is an abstract class: " + testedObjectType); return null; } try { ClassWrapper classWrapper = new ClassWrapper(testedObjectType); return classWrapper.createInstance(); } catch (Exception e) { logger.warn("Tested object could not be created. " + e.getMessage()); return null; } }
From source file:com.thoughtworks.go.server.service.MagicalMaterialAndMaterialConfigConversionTest.java
private boolean isNotAConcrete_NonTest_MaterialConfigImplementation(Class aClass) { return Pattern.matches(".*(Test|Dummy).*", aClass.toString()) || Modifier.isAbstract(aClass.getModifiers()); }
From source file:com.googlecode.jsonschema2pojo.rules.ObjectRule.java
private boolean isFinal(JType superType) { try {//from w w w. ja v a2 s . c o m Class<?> javaClass = Class.forName(superType.fullName()); return Modifier.isFinal(javaClass.getModifiers()); } catch (ClassNotFoundException e) { return false; } }