use of org.gradle.internal.reflect.PropertyDetails in project gradle by gradle.
the class AbstractClassGenerator method inspectType.
private void inspectType(Class<?> type, ClassMetaData classMetaData) {
ClassDetails classDetails = ClassInspector.inspect(type);
boolean hasGetServicesMethod = false;
for (Method method : classDetails.getAllMethods()) {
if (method.getAnnotation(Inject.class) != null) {
if (!Modifier.isPublic(method.getModifiers()) && !Modifier.isProtected(method.getModifiers())) {
throw new UnsupportedOperationException(String.format("Cannot attach @Inject to method %s.%s() as it is not public or protected.", method.getDeclaringClass().getSimpleName(), method.getName()));
}
if (Modifier.isStatic(method.getModifiers())) {
throw new UnsupportedOperationException(String.format("Cannot attach @Inject to method %s.%s() as it is static.", method.getDeclaringClass().getSimpleName(), method.getName()));
}
}
if ("getServices".equals(method.getName()) && (method.getParameterTypes().length == 0) && ServiceRegistry.class.equals(method.getReturnType())) {
hasGetServicesMethod = true;
}
}
for (PropertyDetails property : classDetails.getProperties()) {
PropertyMetaData propertyMetaData = classMetaData.property(property.getName());
for (Method method : property.getGetters()) {
propertyMetaData.addGetter(method);
}
for (Method method : property.getSetters()) {
propertyMetaData.addSetter(method);
}
}
for (Method method : classDetails.getInstanceMethods()) {
Class<?>[] parameterTypes = method.getParameterTypes();
if (parameterTypes.length == 1) {
classMetaData.addCandidateSetMethod(method);
}
if (parameterTypes.length > 0 && parameterTypes[parameterTypes.length - 1].equals(Action.class)) {
classMetaData.addActionMethod(method);
} else if (parameterTypes.length > 0 && parameterTypes[parameterTypes.length - 1].equals(Closure.class)) {
classMetaData.addClosureMethod(method);
}
}
if (!hasGetServicesMethod) {
for (PropertyMetaData metaData : classMetaData.properties.values()) {
if (metaData.injector) {
classMetaData.shouldImplementWithServiceRegistry = true;
}
}
}
}
Aggregations