use of org.gradle.internal.logging.text.TreeFormatter in project gradle by gradle.
the class AbstractClassGenerator method assertNotAbstract.
private void assertNotAbstract(Class<?> type, Method method) {
if (Modifier.isAbstract(type.getModifiers()) && Modifier.isAbstract(method.getModifiers())) {
TreeFormatter formatter = new TreeFormatter();
formatter.node("Cannot have abstract method ");
formatter.appendMethod(method);
formatter.append(".");
throw new IllegalArgumentException(formatter.toString());
}
// Else, ignore abstract methods on non-abstract classes as some other tooling (e.g. the Groovy compiler) has decided this is ok
}
use of org.gradle.internal.logging.text.TreeFormatter in project gradle by gradle.
the class AsmBackedClassGenerator method start.
@Override
protected ClassInspectionVisitor start(Class<?> type) {
if (type.isAnnotation() || type.isEnum()) {
TreeFormatter formatter = new TreeFormatter();
formatter.node(type);
formatter.append(" is not a class or interface.");
throw new ClassGenerationException(formatter.toString());
}
return new ClassInspectionVisitorImpl(type, decorate, suffix, factoryId);
}
use of org.gradle.internal.logging.text.TreeFormatter in project gradle by gradle.
the class DependencyInjectingInstantiator method nullPrimitiveType.
private void nullPrimitiveType(int index, Class<?> paramType) {
TreeFormatter formatter = new TreeFormatter();
formatter.node("Unable to determine constructor argument #" + (index + 1) + ": null value is not assignable to type ");
formatter.appendType(paramType);
formatter.append(".");
throw new IllegalArgumentException(formatter.toString());
}
use of org.gradle.internal.logging.text.TreeFormatter in project gradle by gradle.
the class DependencyInjectingInstantiator method verifyParameters.
private Object[] verifyParameters(ClassGenerator.GeneratedConstructor<?> constructor, Object[] parameters) {
Class<?>[] parameterTypes = constructor.getParameterTypes();
for (int i = 0; i < parameterTypes.length; i++) {
Class<?> targetType = parameterTypes[i];
Object currentParameter = parameters[i];
if (targetType.isPrimitive()) {
if (currentParameter == null) {
nullPrimitiveType(i, targetType);
}
targetType = JavaReflectionUtil.getWrapperTypeForPrimitiveType(targetType);
} else if (currentParameter == null) {
// Null is ok if the ConstructorSelector says it's ok
continue;
}
if (!targetType.isInstance(currentParameter)) {
TreeFormatter formatter = new TreeFormatter();
formatter.node("Unable to determine constructor argument #" + (i + 1) + ": value ");
formatter.appendValue(currentParameter);
formatter.append(" not assignable to type ");
formatter.appendType(parameterTypes[i]);
formatter.append(".");
throw new IllegalArgumentException(formatter.toString());
}
}
return parameters;
}
use of org.gradle.internal.logging.text.TreeFormatter in project gradle by gradle.
the class DependencyInjectingInstantiator method addServicesToParameters.
private Object[] addServicesToParameters(Class<?> type, ClassGenerator.GeneratedConstructor<?> constructor, ServiceLookup services, Object[] parameters) {
Class<?>[] parameterTypes = constructor.getParameterTypes();
Type[] genericTypes = constructor.getGenericParameterTypes();
Object[] resolvedParameters = new Object[parameterTypes.length];
int pos = 0;
for (int i = 0; i < resolvedParameters.length; i++) {
Class<?> targetType = parameterTypes[i];
Type serviceType = genericTypes[i];
if (pos < parameters.length) {
Object parameter = parameters[pos];
if (targetType.isPrimitive()) {
if (parameter == null) {
nullPrimitiveType(i, targetType);
}
targetType = JavaReflectionUtil.getWrapperTypeForPrimitiveType(targetType);
}
if (parameter == null || targetType.isInstance(parameter)) {
resolvedParameters[i] = parameter;
pos++;
continue;
}
}
Object service = services.find(serviceType);
if (service != null) {
resolvedParameters[i] = service;
continue;
}
TreeFormatter formatter = new TreeFormatter();
formatter.node("Unable to determine constructor argument #" + (i + 1) + ": ");
if (pos < parameters.length) {
formatter.append("value ");
formatter.appendValue(parameters[pos]);
formatter.append(" is not assignable to type ");
formatter.appendType(parameterTypes[i]);
} else {
formatter.append("missing parameter of type ");
formatter.appendType(parameterTypes[i]);
}
formatter.append(", or no service of type ");
formatter.appendType(serviceType);
formatter.append(".");
throw new IllegalArgumentException(formatter.toString());
}
if (pos != parameters.length) {
TreeFormatter formatter = new TreeFormatter();
formatter.node("Unexpected parameter provided for constructor for ");
formatter.appendType(type);
throw new IllegalArgumentException(formatter.toString());
}
return resolvedParameters;
}
Aggregations