use of org.gradle.internal.logging.text.TreeFormatter in project gradle by gradle.
the class InjectUtil method selectConstructor.
/**
* Selects the single injectable constructor for the given type.
* The type must either have only one public or package-private default constructor,
* or it should have a single constructor annotated with {@literal @}{@link Inject}.
*
* @param type the type to find the injectable constructor of.
* @param reportAs errors are reported against this type, useful when the real type is generated, and we'd like to show the original type in messages instead.
*/
public static <T> ClassGenerator.GeneratedConstructor<T> selectConstructor(ClassGenerator.GeneratedClass<T> type, Class<?> reportAs) {
List<ClassGenerator.GeneratedConstructor<T>> constructors = type.getConstructors();
if (constructors.size() == 1) {
ClassGenerator.GeneratedConstructor<T> constructor = constructors.get(0);
if (constructor.getParameterTypes().length == 0 && isPublicOrPackageScoped(type.getGeneratedClass(), constructor)) {
return constructor;
}
if (constructor.getAnnotation(Inject.class) != null) {
return constructor;
}
if (constructor.getParameterTypes().length == 0) {
TreeFormatter formatter = new TreeFormatter();
formatter.node("The constructor for type ");
formatter.appendType(reportAs);
formatter.append(" should be public or package protected or annotated with @Inject.");
throw new IllegalArgumentException(formatter.toString());
} else {
TreeFormatter formatter = new TreeFormatter();
formatter.node("The constructor for type ");
formatter.appendType(reportAs);
formatter.append(" should be annotated with @Inject.");
throw new IllegalArgumentException(formatter.toString());
}
}
List<ClassGenerator.GeneratedConstructor<T>> injectConstructors = new ArrayList<ClassGenerator.GeneratedConstructor<T>>();
for (ClassGenerator.GeneratedConstructor<T> constructor : constructors) {
if (constructor.getAnnotation(Inject.class) != null) {
injectConstructors.add(constructor);
}
}
if (injectConstructors.isEmpty()) {
TreeFormatter formatter = new TreeFormatter();
formatter.node(reportAs);
formatter.append(" has no constructor that is annotated with @Inject.");
throw new IllegalArgumentException(formatter.toString());
}
if (injectConstructors.size() > 1) {
TreeFormatter formatter = new TreeFormatter();
formatter.node(reportAs);
formatter.append(" has multiple constructors that are annotated with @Inject.");
throw new IllegalArgumentException(formatter.toString());
}
return injectConstructors.get(0);
}
use of org.gradle.internal.logging.text.TreeFormatter in project gradle by gradle.
the class IsolationScheme method parameterTypeFor.
/**
* Determines the parameters type found at the given type argument index for the given implementation.
*
* @return The parameters type, or {@code null} when the implementation takes no parameters.
*/
@Nullable
public <T extends IMPLEMENTATION, P extends PARAMS> Class<P> parameterTypeFor(Class<T> implementationType, int typeArgumentIndex) {
if (implementationType == interfaceType) {
return null;
}
Class<P> parametersType = inferParameterType(implementationType, typeArgumentIndex);
if (parametersType == paramsType) {
TreeFormatter formatter = new TreeFormatter();
formatter.node("Could not create the parameters for ");
formatter.appendType(implementationType);
formatter.append(": must use a sub-type of ");
formatter.appendType(parametersType);
formatter.append(" as the parameters type. Use ");
formatter.appendType(noParamsType);
formatter.append(" as the parameters type for implementations that do not take parameters.");
throw new IllegalArgumentException(formatter.toString());
}
if (parametersType == noParamsType) {
return null;
}
return parametersType;
}
use of org.gradle.internal.logging.text.TreeFormatter in project gradle by gradle.
the class DefaultValueSourceProviderFactory method couldNotCreateProviderOf.
private String couldNotCreateProviderOf(Class<?> valueSourceType) {
TreeFormatter formatter = new TreeFormatter();
formatter.node("Could not create provider for value source ");
formatter.appendType(valueSourceType);
formatter.append(".");
return formatter.toString();
}
use of org.gradle.internal.logging.text.TreeFormatter in project gradle by gradle.
the class UnavailablePlatformToolProvider method failure.
private RuntimeException failure() {
TreeFormatter formatter = new TreeFormatter();
this.explain(formatter);
return new GradleException(formatter.toString());
}
use of org.gradle.internal.logging.text.TreeFormatter in project gradle by gradle.
the class InvalidPublicationChecker method validate.
public void validate() {
if (variants.isEmpty()) {
failWith("This publication must publish at least one variant");
}
checkVariantDependencyVersions();
if (errors != null) {
TreeFormatter formatter = new TreeFormatter();
formatter.node("Invalid publication '" + publicationName + "'");
formatter.startChildren();
for (String error : errors) {
formatter.node(error);
}
formatter.endChildren();
if (explanations != null) {
for (String explanation : explanations) {
formatter.node(explanation);
}
}
throw new InvalidUserCodeException(formatter.toString());
}
}
Aggregations