List of usage examples for java.lang.reflect Modifier isAbstract
public static boolean isAbstract(int mod)
From source file:org.apache.tapestry.enhance.ComponentClassFactory.java
/** * @return true if m is not null and is abstract. *///from ww w . j a va 2 s.com public boolean isAbstract(Method m) { if (m == null) return false; return Modifier.isAbstract(m.getModifiers()); }
From source file:org.mabb.fontverter.FontVerter.java
private static List<Class> removeAbstractClasses(List<Class> classes) { List<Class> filtered = new ArrayList<Class>(); for (Class adapterOn : classes) { if (!Modifier.isAbstract(adapterOn.getModifiers())) filtered.add(adapterOn);// w ww . ja v a2s.c om } return filtered; }
From source file:ome.services.graphs.AbstractHierarchyGraphSpec.java
/** * Performs sanity checks on the entries found in {@link ExtendedMetadata}. * Primarily, this prevents new types from not being properly specified * in spec.xml./* w w w .ja v a 2 s.c o m*/ */ @Override public void setExtendedMetadata(ExtendedMetadata em) { super.setExtendedMetadata(em); // First calculate the number of unique top-level paths List<String> uniquePaths = new ArrayList<String>(); for (GraphEntry entry : entries) { String topLevel = entry.path("")[0]; if (!uniquePaths.contains(topLevel)) { uniquePaths.add(topLevel); } } // Now we check if this represents all the hierarchy types // in the system. Set<Class<IObject>> types = getTypes(em); if (types.size() != uniquePaths.size()) { throw new FatalBeanException( "Mismatch between types defined and those found: " + entries + "<> " + types); } TYPE: for (Class<?> type : types) { String simpleName = type.getSimpleName(); for (int i = 0; i < entries.size(); i++) { GraphEntry entry = entries.get(i); if (entry.path("").length > 1) { // This not part of our hierarchy, but some subpath // ignore it. continue; } if (simpleName.equals(entry.getName().substring(1))) { this.types[i] = type; if (Modifier.isAbstract(type.getModifiers())) { this.isAbstract[i] = true; } continue TYPE; } } throw new FatalBeanException("Could not find entry: " + simpleName); } }
From source file:org.gvnix.service.roo.addon.addon.ws.export.WSExportXmlElementMetadata.java
public WSExportXmlElementMetadata(String id, JavaType aspectName, PhysicalTypeMetadata physicalType, List<FieldMetadata> fields, JavaParserService javaParserService) { super(id, aspectName, physicalType); // Validate metadata identifier is of type gvNIX xml element metadata Validate.isTrue(isValid(id), "Metadata identification string '" + id + "' does not appear to be valid"); if (!isValid()) { return;/* w w w . j a v a 2s .co m*/ } // Get the gvNIX xml element annotation AnnotationMetadata annotation = governorTypeDetails .getTypeAnnotation(new JavaType(GvNIXXmlElement.class.getName())); if (annotation != null) { // Add to class XmlRoot, XmlType and XmlEnum or XmlAccessorType List<AnnotationMetadata> annotationTypeList = getAnnotations(annotation, fields); for (AnnotationMetadata annotationMetadata : annotationTypeList) { builder.addAnnotation(annotationMetadata); } // If is not a enumeration type if (!governorTypeDetails.getPhysicalTypeCategory().equals(PhysicalTypeCategory.ENUMERATION)) { // Add XmlElement annotation for each field List<DeclaredFieldAnnotationDetails> declaredFields = getXmlElementAnnotations(fields, javaParserService); for (DeclaredFieldAnnotationDetails declaredField : declaredFields) { builder.addFieldAnnotation(declaredField); } // Avoid if abstract class or interface (can't add method) if (!Modifier.isAbstract(governorTypeDetails.getModifier()) && !Modifier.isInterface(governorTypeDetails.getModifier())) { // Add annotation and method to avoid cycles convert to XML addCycleDetection(id); } } } // Build the aspect Java defined into builder itdTypeDetails = builder.build(); }
From source file:com.linecorp.armeria.common.thrift.text.StructContext.java
private static boolean isAbstract(Class clazz) { return Modifier.isAbstract(clazz.getModifiers()); }
From source file:com.flipkart.polyguice.dropwiz.PolyguiceApp.java
private Object createResource(Class<?> cls, T config, Environment env) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { LOGGER.debug("creating object of type {}", cls); try {// w w w. j a v a 2 s . co m Constructor<?> ctor = cls.getConstructor(Configuration.class, Environment.class); int mod = ctor.getModifiers(); if (Modifier.isPublic(mod) && !Modifier.isAbstract(mod)) { LOGGER.debug("using ctor {}", ctor.toGenericString()); return ctor.newInstance(config, env); } } catch (NoSuchMethodException exep) { //NOOP, not even log } try { Constructor<?> ctor = cls.getConstructor(Environment.class, Configuration.class); int mod = ctor.getModifiers(); if (Modifier.isPublic(mod) && !Modifier.isAbstract(mod)) { LOGGER.debug("using ctor {}", ctor.toGenericString()); return ctor.newInstance(env, config); } } catch (NoSuchMethodException exep) { //NOOP, not even log } try { Constructor<?> ctor = cls.getConstructor(Configuration.class); int mod = ctor.getModifiers(); if (Modifier.isPublic(mod) && !Modifier.isAbstract(mod)) { LOGGER.debug("using ctor {}", ctor.toGenericString()); return ctor.newInstance(config); } } catch (NoSuchMethodException exep) { //NOOP, not even log } try { Constructor<?> ctor = cls.getConstructor(Environment.class); int mod = ctor.getModifiers(); if (Modifier.isPublic(mod) && !Modifier.isAbstract(mod)) { LOGGER.debug("using ctor {}", ctor.toGenericString()); return ctor.newInstance(env); } } catch (NoSuchMethodException exep) { //NOOP, not even log } try { Constructor<?> ctor = cls.getConstructor(); int mod = ctor.getModifiers(); if (Modifier.isPublic(mod) && !Modifier.isAbstract(mod)) { LOGGER.debug("using ctor {}", ctor.toGenericString()); return ctor.newInstance(); } } catch (NoSuchMethodException exep) { //NOOP, not even log } return null; }
From source file:fi.vm.sade.organisaatio.service.converter.ConverterFactory.java
public <DTO> DTO convertToDTO(OrganisaatioBaseEntity entity, Class<? extends DTO> resultClass) { DTO dto = null;//ww w.j a v a2 s.c o m // if resultClass is abstractclass, get resultclass from entity, but ensure it is resultclass' subclass if (Modifier.isAbstract(resultClass.getModifiers())) { Class temp = entity.getDTOClass(); if (!resultClass.isAssignableFrom(temp)) { throw new IllegalArgumentException( "cannot convert, resultClass is abstract and not not assignable from entity's dtoclass, resultClass: " + resultClass + ", entity.dtoclass: " + entity.getDTOClass()); } resultClass = temp; } // create object and convert basic fields with dozer if (entity != null) { dto = mapper.map(entity, resultClass); } // convert other fields with custom converter Converter converter = getConverterForDto(resultClass); if (converter != null) { converter.setValuesToDTO(entity, dto); } if (entity instanceof Puhelinnumero) { ((PuhelinnumeroDTO) dto).setTyyppi(PuhelinNumeroTyyppi.fromValue(((Puhelinnumero) entity).getTyyppi())); } else if (entity instanceof Osoite) { ((OsoiteDTO) dto).setOsoiteTyyppi(OsoiteTyyppi.fromValue(((Osoite) entity).getOsoiteTyyppi())); } else if (entity instanceof YhteystietoElementti) { ((YhteystietoElementtiDTO) dto) .setTyyppi(YhteystietoElementtiTyyppi.fromValue(((YhteystietoElementti) entity).getTyyppi())); } //DEBUGSAWAY:log.debug("convertToDTO: " + entity + " -> " + dto); return dto; }
From source file:org.gradle.model.internal.manage.schema.extract.StructStrategy.java
public <R> ModelSchemaExtractionResult<R> extract(final ModelSchemaExtractionContext<R> extractionContext, final ModelSchemaCache cache) { ModelType<R> type = extractionContext.getType(); Class<? super R> clazz = type.getRawClass(); if (clazz.isAnnotationPresent(Managed.class)) { validateType(type, extractionContext); Iterable<Method> methods = Arrays.asList(clazz.getMethods()); if (!clazz.isInterface()) { methods = filterIgnoredMethods(methods); }//from w w w. j av a 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(); Class<? extends R> implClass = classGenerator.generate(concreteClass); final ModelStructSchema<R> schema = ModelSchema.struct(type, properties, implClass); extractionContext.addValidator(new Action<ModelSchemaExtractionContext<R>>() { @Override public void execute(ModelSchemaExtractionContext<R> validatorModelSchemaExtractionContext) { ensureCanBeInstantiated(extractionContext, schema); } }); 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:org.apache.cactus.integration.maven.CactusScanner.java
/** * @param theClassName the fully qualified name of the class to check * @param theClasspath the classpaths needed to load the test classes * @return true if the class is a JUnit test case *//*from w w w .j a v a2 s . co m*/ private boolean isJUnitTestCase(String theClassName, Path theClasspath) { Class clazz = loadClass(theClassName, theClasspath); if (clazz == null) { return false; } Class testCaseClass = null; try { testCaseClass = clazz.getClassLoader().loadClass(TestCase.class.getName()); } catch (ClassNotFoundException e) { log.debug("Cannot load class", e); return false; } if (!testCaseClass.isAssignableFrom(clazz)) { log.debug("Not a JUnit test as class [" + theClassName + "] does " + "not inherit from [" + TestCase.class.getName() + "]"); return false; } // the class must not be abstract if (Modifier.isAbstract(clazz.getModifiers())) { log.debug("Not a JUnit test as class [" + theClassName + "] is " + "abstract"); return false; } // the class must have at least one test, i.e. a public method // starting with "test" and that takes no parameters boolean hasTestMethod = false; Method[] methods = clazz.getMethods(); for (int i = 0; i < methods.length; i++) { if (methods[i].getName().startsWith("test") && (methods[i].getReturnType() == Void.TYPE) && (methods[i].getParameterTypes().length == 0)) { hasTestMethod = true; break; } } if (!hasTestMethod) { log.debug("Not a JUnit test as class [" + theClassName + "] has " + "no method that start with \"test\", returns void and has " + "no parameters"); return false; } return true; }
From source file:org.apache.tapestry.enhance.ComponentClassFactory.java
/** * @return true if m is not null and not abstract *//* w w w. j ava 2s . c om*/ public boolean isImplemented(Method m) { if (m == null) return false; return !Modifier.isAbstract(m.getModifiers()); }