List of usage examples for java.lang.reflect Modifier isAbstract
public static boolean isAbstract(int mod)
From source file:org.apache.ddlutils.TestAgainstLiveDatabaseBase.java
/** * Creates the test suite for the given test class which must be a sub class of * {@link RoundtripTestBase}. If the platform supports it, it will be tested * with both delimited and undelimited identifiers. * /*from w w w . j ava 2 s .c om*/ * @param testedClass The tested class * @return The tests */ protected static TestSuite getTests(Class testedClass) { if (!TestAgainstLiveDatabaseBase.class.isAssignableFrom(testedClass) || Modifier.isAbstract(testedClass.getModifiers())) { throw new DdlUtilsException("Cannot create parameterized tests for class " + testedClass.getName()); } TestSuite suite = new TestSuite(); Properties props = readTestProperties(); if (props == null) { return suite; } DataSource dataSource = initDataSourceFromProperties(props); String databaseName = determineDatabaseName(props, dataSource); try { Method[] methods = testedClass.getMethods(); PlatformInfo info = null; TestAgainstLiveDatabaseBase newTest; for (int idx = 0; (methods != null) && (idx < methods.length); idx++) { if (methods[idx].getName().startsWith("test") && ((methods[idx].getParameterTypes() == null) || (methods[idx].getParameterTypes().length == 0))) { newTest = (TestAgainstLiveDatabaseBase) testedClass.newInstance(); newTest.setName(methods[idx].getName()); newTest.setTestProperties(props); newTest.setDataSource(dataSource); newTest.setDatabaseName(databaseName); newTest.setUseDelimitedIdentifiers(false); suite.addTest(newTest); if (info == null) { info = PlatformFactory.createNewPlatformInstance(newTest.getDatabaseName()) .getPlatformInfo(); } if (info.isDelimitedIdentifiersSupported()) { newTest = (TestAgainstLiveDatabaseBase) testedClass.newInstance(); newTest.setName(methods[idx].getName()); newTest.setTestProperties(props); newTest.setDataSource(dataSource); newTest.setDatabaseName(databaseName); newTest.setUseDelimitedIdentifiers(true); suite.addTest(newTest); } } } } catch (Exception ex) { throw new DdlUtilsException(ex); } return suite; }
From source file:org.gradle.api.internal.AbstractClassGenerator.java
private <T> Class<? extends T> generateUnderLock(Class<T> type) { Map<Class<?>, Class<?>> cache = GENERATED_CLASSES.get(getClass()); if (cache == null) { // WeakHashMap won't work here. It keeps a strong reference to the mapping value, which is the generated class in this case // However, the generated class has a strong reference to the source class (by extending it), so the keys will always be // strongly reachable while this Class is strongly reachable. Use weak references for both key and value of the mapping instead. cache = new ReferenceMap(AbstractReferenceMap.WEAK, AbstractReferenceMap.WEAK); GENERATED_CLASSES.put(getClass(), cache); }// www . ja va 2s .c o m Class<?> generatedClass = cache.get(type); if (generatedClass != null) { return generatedClass.asSubclass(type); } if (Modifier.isPrivate(type.getModifiers())) { throw new GradleException( String.format("Cannot create a proxy class for private class '%s'.", type.getSimpleName())); } if (Modifier.isAbstract(type.getModifiers())) { throw new GradleException( String.format("Cannot create a proxy class for abstract class '%s'.", type.getSimpleName())); } Class<? extends T> subclass; try { ClassMetaData classMetaData = inspectType(type); ClassBuilder<T> builder = start(type, classMetaData); builder.startClass(); if (!DynamicObjectAware.class.isAssignableFrom(type)) { if (ExtensionAware.class.isAssignableFrom(type)) { throw new UnsupportedOperationException( "A type that implements ExtensionAware must currently also implement DynamicObjectAware."); } builder.mixInDynamicAware(); } if (!GroovyObject.class.isAssignableFrom(type)) { builder.mixInGroovyObject(); } builder.addDynamicMethods(); if (classMetaData.conventionAware && !IConventionAware.class.isAssignableFrom(type)) { builder.mixInConventionAware(); } Class noMappingClass = Object.class; for (Class<?> c = type; c != null && noMappingClass == Object.class; c = c.getSuperclass()) { if (c.getAnnotation(NoConventionMapping.class) != null) { noMappingClass = c; } } Set<PropertyMetaData> conventionProperties = new HashSet<PropertyMetaData>(); for (PropertyMetaData property : classMetaData.properties.values()) { if (SKIP_PROPERTIES.contains(property.name)) { continue; } if (property.injector) { builder.addInjectorProperty(property); for (Method getter : property.getters) { builder.applyServiceInjectionToGetter(property, getter); } for (Method setter : property.setters) { builder.applyServiceInjectionToSetter(property, setter); } continue; } boolean needsConventionMapping = false; if (classMetaData.isExtensible()) { for (Method getter : property.getters) { if (!Modifier.isFinal(getter.getModifiers()) && !getter.getDeclaringClass().isAssignableFrom(noMappingClass)) { needsConventionMapping = true; break; } } } if (needsConventionMapping) { conventionProperties.add(property); builder.addConventionProperty(property); for (Method getter : property.getters) { builder.applyConventionMappingToGetter(property, getter); } } if (needsConventionMapping) { for (Method setter : property.setters) { if (!Modifier.isFinal(setter.getModifiers())) { builder.applyConventionMappingToSetter(property, setter); } } } } Set<Method> actionMethods = classMetaData.missingOverloads; for (Method method : actionMethods) { builder.addActionMethod(method); } // Adds a set method for each mutable property for (PropertyMetaData property : classMetaData.properties.values()) { if (property.setters.isEmpty()) { continue; } if (Iterable.class.isAssignableFrom(property.getType())) { // Currently not supported continue; } if (property.setMethods.isEmpty()) { for (Method setter : property.setters) { builder.addSetMethod(property, setter); } } else if (conventionProperties.contains(property)) { for (Method setMethod : property.setMethods) { builder.applyConventionMappingToSetMethod(property, setMethod); } } } for (Constructor<?> constructor : type.getConstructors()) { if (Modifier.isPublic(constructor.getModifiers())) { builder.addConstructor(constructor); } } subclass = builder.generate(); } catch (Throwable e) { throw new GradleException( String.format("Could not generate a proxy class for class %s.", type.getName()), e); } cache.put(type, subclass); cache.put(subclass, subclass); return subclass; }
From source file:org.apache.camel.blueprint.PackageScanRouteBuilderFinder.java
/** * Returns true if the object is non-abstract and supports a zero argument constructor *//*from w ww. j ava 2s . c om*/ protected boolean isValidClass(Class type) { if (!Modifier.isAbstract(type.getModifiers()) && !type.isInterface()) { return true; } return false; }
From source file:uk.gov.gchq.gaffer.example.gettingstarted.walkthrough.WalkthroughRunner.java
private static void keepPublicConcreteClasses(final List classes) { if (null != classes) { final Iterator<Class> itr = classes.iterator(); for (Class clazz = null; itr.hasNext(); clazz = itr.next()) { if (null != clazz) { final int modifiers = clazz.getModifiers(); if (Modifier.isAbstract(modifiers) || Modifier.isInterface(modifiers) || Modifier.isPrivate(modifiers) || Modifier.isProtected(modifiers)) { itr.remove();/*from www.jav a 2 s . c om*/ } } } } }
From source file:com.kinglcc.spring.jms.core.Jackson2PayloadArgumentResolver.java
private Object convertFromMessage(MethodParameter parameter, Message<?> message) { Object payload = message.getPayload(); Class<?> targetClass = parameter.getParameterType(); if (targetClass.isInterface() || Modifier.isAbstract(targetClass.getModifiers())) { return payload; }//from www . j av a2 s .co m if (this.converter instanceof GenericMessageAdapterConverter) { payload = convertJavaTypeFromMessage(message, parameter); validate(message, parameter, payload); return payload; } payload = convertClassFromMessage(message, targetClass); validate(message, parameter, payload); return payload; }
From source file:org.gradle.model.internal.manage.schema.extract.ManagedImplTypeSchemaExtractionStrategySupport.java
public <R> ModelSchemaExtractionResult<R> extract(final ModelSchemaExtractionContext<R> extractionContext, ModelSchemaStore store, final ModelSchemaCache cache) { ModelType<R> type = extractionContext.getType(); Class<? super R> clazz = type.getRawClass(); if (isTarget(type)) { validateType(type, extractionContext); Iterable<Method> methods = Arrays.asList(clazz.getMethods()); if (!clazz.isInterface()) { methods = filterIgnoredMethods(methods); }/*w w w .j ava 2 s . c o m*/ ImmutableListMultimap<String, Method> methodsByName = Multimaps.index(methods, new Function<Method, String>() { public String apply(Method method) { return method.getName(); } }); ensureNoOverloadedMethods(extractionContext, methodsByName); List<ModelProperty<?>> properties = Lists.newLinkedList(); List<Method> handled = Lists.newArrayListWithCapacity(clazz.getMethods().length); ReturnTypeSpecializationOrdering returnTypeSpecializationOrdering = new ReturnTypeSpecializationOrdering(); for (String methodName : methodsByName.keySet()) { if (methodName.startsWith("get") && !methodName.equals("get")) { ImmutableList<Method> getterMethods = methodsByName.get(methodName); // The overload check earlier verified that all methods for are equivalent for our purposes // So, taking the first one with the most specialized return type is fine. Method sampleMethod = returnTypeSpecializationOrdering.max(getterMethods); boolean abstractGetter = Modifier.isAbstract(sampleMethod.getModifiers()); if (sampleMethod.getParameterTypes().length != 0) { throw invalidMethod(extractionContext, "getter methods cannot take parameters", sampleMethod); } Character getterPropertyNameFirstChar = methodName.charAt(3); if (!Character.isUpperCase(getterPropertyNameFirstChar)) { throw invalidMethod(extractionContext, "the 4th character of the getter method name must be an uppercase character", sampleMethod); } ModelType<?> returnType = ModelType.returnType(sampleMethod); String propertyNameCapitalized = methodName.substring(3); String propertyName = StringUtils.uncapitalize(propertyNameCapitalized); String setterName = "set" + propertyNameCapitalized; ImmutableList<Method> setterMethods = methodsByName.get(setterName); boolean isWritable = !setterMethods.isEmpty(); if (isWritable) { Method setter = setterMethods.get(0); if (!abstractGetter) { throw invalidMethod(extractionContext, "setters are not allowed for non-abstract getters", setter); } validateSetter(extractionContext, returnType, setter); handled.addAll(setterMethods); } if (abstractGetter) { ImmutableSet<ModelType<?>> declaringClasses = ImmutableSet .copyOf(Iterables.transform(getterMethods, new Function<Method, ModelType<?>>() { public ModelType<?> apply(Method input) { return ModelType.of(input.getDeclaringClass()); } })); boolean unmanaged = Iterables.any(getterMethods, new Predicate<Method>() { public boolean apply(Method input) { return input.getAnnotation(Unmanaged.class) != null; } }); properties.add(ModelProperty.of(returnType, propertyName, isWritable, declaringClasses, unmanaged)); } handled.addAll(getterMethods); } } Iterable<Method> notHandled = Iterables.filter(methodsByName.values(), Predicates.not(Predicates.in(handled))); // TODO - should call out valid getters without setters if (!Iterables.isEmpty(notHandled)) { throw invalidMethods(extractionContext, "only paired getter/setter methods are supported", notHandled); } Class<R> concreteClass = type.getConcreteClass(); final ModelSchema<R> schema = createSchema(extractionContext, store, type, properties, concreteClass); Iterable<ModelSchemaExtractionContext<?>> propertyDependencies = Iterables.transform(properties, new Function<ModelProperty<?>, ModelSchemaExtractionContext<?>>() { public ModelSchemaExtractionContext<?> apply(final ModelProperty<?> property) { return toPropertyExtractionContext(extractionContext, property, cache); } }); return new ModelSchemaExtractionResult<R>(schema, propertyDependencies); } else { return null; } }
From source file:li.klass.fhem.testsuite.category.CategorySuite.java
private static Class<?>[] getSuiteClasses() { String basePath = getBasePath(); File basePathFile = new File(basePath); Collection javaFiles = FileUtils.listFiles(basePathFile, new String[] { "java" }, true); ArrayList<Class<?>> result = new ArrayList<Class<?>>(); for (Object fileObject : javaFiles) { File file = (File) fileObject; Class<?> cls = toClass(file, basePath); if (cls == null || Modifier.isAbstract(cls.getModifiers())) { continue; }//from w ww . jav a 2 s. c o m result.add(cls); } return result.toArray(new Class<?>[result.size()]); }
From source file:com.qmetry.qaf.automation.step.JavaStepFinder.java
private static Set<Method> getAllMethodsWithAnnotation(Collection<Class<?>> classes, Class<? extends Annotation> annotation) { Set<Method> methods = new HashSet<Method>(); for (Class<?> cls : classes) { if (cls.isInterface() || Modifier.isAbstract(cls.getModifiers())) continue; boolean isStepProvider = cls.isAnnotationPresent(QAFTestStepProvider.class); for (Method method : cls.getMethods()) { if (isStepProvider || ClassUtil.hasAnnotation(method, annotation)) { methods.add(method);//from www. j a va 2s.co m } } } return methods; }
From source file:at.treedb.backup.Import.java
private static boolean ignoreClass(Class<?> c) { if (Modifier.isAbstract(c.getModifiers()) || c.equals(DBFSblock.class) || c.equals(DBinfo.class)) { return true; }/*w ww. j ava 2 s. co m*/ return false; }
From source file:com.github.mbenson.privileged.weaver.PrivilegedMethodWeaver.java
private static Set<CtMethod> getPrivilegedMethods(CtClass type) throws ClassNotFoundException { final TreeSet<CtMethod> result = new TreeSet<CtMethod>(CTMETHOD_COMPARATOR); for (final CtMethod m : type.getDeclaredMethods()) { if (Modifier.isAbstract(m.getModifiers()) || m.getAnnotation(Privileged.class) == null) { continue; }/*from w w w. j a va2 s.c o m*/ result.add(m); } return result; }