use of org.gradle.internal.logging.text.TreeFormatter in project gradle by gradle.
the class ToolChainAvailability method getUnavailableMessage.
public String getUnavailableMessage() {
TreeFormatter formatter = new TreeFormatter();
this.explain(formatter);
return formatter.toString();
}
use of org.gradle.internal.logging.text.TreeFormatter in project gradle by gradle.
the class AbstractValueProcessor method newValueSerializationException.
private ValueSnapshottingException newValueSerializationException(Class<?> valueType, Throwable cause) {
TreeFormatter formatter = new TreeFormatter();
formatter.node("Could not serialize value of type ");
formatter.appendType(valueType);
return new ValueSnapshottingException(formatter.toString(), cause);
}
use of org.gradle.internal.logging.text.TreeFormatter in project gradle by gradle.
the class Jsr330ConstructorSelector method vetoParameters.
@Override
public void vetoParameters(ClassGenerator.GeneratedConstructor<?> constructor, Object[] parameters) {
for (Object param : parameters) {
if (param == null) {
TreeFormatter formatter = new TreeFormatter();
formatter.node("Null value provided in parameters ");
formatter.appendValues(parameters);
throw new IllegalArgumentException(formatter.toString());
}
}
}
use of org.gradle.internal.logging.text.TreeFormatter in project gradle by gradle.
the class TypeValidationProblemRenderer method renderMinimalInformationAbout.
public static String renderMinimalInformationAbout(TypeValidationProblem problem, boolean renderDocLink, boolean renderSolutions) {
TreeFormatter formatter = new TreeFormatter();
formatter.node(introductionFor(problem.getWhere()) + maybeAppendDot(problem.getShortDescription()));
problem.getWhy().ifPresent(reason -> {
formatter.blankLine();
formatter.node("Reason: " + StringUtils.capitalize(maybeAppendDot(reason)));
});
if (renderSolutions) {
List<Solution> possibleSolutions = problem.getPossibleSolutions();
int solutionCount = possibleSolutions.size();
if (solutionCount > 0) {
formatter.blankLine();
if (solutionCount == 1) {
formatter.node("Possible solution: " + StringUtils.capitalize(maybeAppendDot(possibleSolutions.get(0).getShortDescription())));
} else {
formatter.node("Possible solutions");
formatter.startNumberedChildren();
possibleSolutions.forEach(solution -> formatter.node(StringUtils.capitalize(maybeAppendDot(solution.getShortDescription()))));
formatter.endChildren();
}
}
}
if (renderDocLink) {
problem.getDocumentationLink().ifPresent(docLink -> {
formatter.blankLine();
formatter.node("Please refer to ").append(docLink).append(" for more details about this problem.");
});
}
return formatter.toString();
}
use of org.gradle.internal.logging.text.TreeFormatter in project gradle by gradle.
the class AbstractClassGenerator method generateUnderLock.
private GeneratedClassImpl generateUnderLock(Class<?> type) {
List<CustomInjectAnnotationPropertyHandler> customAnnotationPropertyHandlers = new ArrayList<>(enabledAnnotations.size());
ServicesPropertyHandler servicesHandler = new ServicesPropertyHandler();
InjectAnnotationPropertyHandler injectionHandler = new InjectAnnotationPropertyHandler();
PropertyTypePropertyHandler propertyTypedHandler = new PropertyTypePropertyHandler();
ManagedPropertiesHandler managedPropertiesHandler = new ManagedPropertiesHandler();
NamePropertyHandler namePropertyHandler = new NamePropertyHandler();
ExtensibleTypePropertyHandler extensibleTypeHandler = new ExtensibleTypePropertyHandler();
DslMixInPropertyType dslMixInHandler = new DslMixInPropertyType(extensibleTypeHandler);
// Order is significant. Injection handler should be at the end
List<ClassGenerationHandler> handlers = new ArrayList<>(5 + enabledAnnotations.size() + disabledAnnotations.size());
handlers.add(extensibleTypeHandler);
handlers.add(dslMixInHandler);
handlers.add(propertyTypedHandler);
handlers.add(servicesHandler);
handlers.add(namePropertyHandler);
handlers.add(managedPropertiesHandler);
for (Class<? extends Annotation> annotation : enabledAnnotations) {
customAnnotationPropertyHandlers.add(new CustomInjectAnnotationPropertyHandler(annotation));
}
handlers.addAll(customAnnotationPropertyHandlers);
handlers.add(injectionHandler);
// Order is significant
List<ClassValidator> validators = new ArrayList<>(2 + disabledAnnotations.size());
for (Class<? extends Annotation> annotation : disabledAnnotations) {
validators.add(new DisabledAnnotationValidator(annotation));
}
validators.add(new InjectionAnnotationValidator(enabledAnnotations, allowedTypesForAnnotation));
Class<?> generatedClass;
try {
ClassInspectionVisitor inspectionVisitor = start(type);
inspectType(type, validators, handlers, extensibleTypeHandler);
for (ClassGenerationHandler handler : handlers) {
handler.applyTo(inspectionVisitor);
}
ClassGenerationVisitor generationVisitor = inspectionVisitor.builder();
for (ClassGenerationHandler handler : handlers) {
handler.applyTo(generationVisitor);
}
boolean shouldImplementNameProperty = namePropertyHandler.hasNameProperty();
if (type.isInterface()) {
if (shouldImplementNameProperty) {
generationVisitor.addNameConstructor();
} else {
generationVisitor.addDefaultConstructor();
}
} else {
for (Constructor<?> constructor : type.getConstructors()) {
generationVisitor.addConstructor(constructor, shouldImplementNameProperty);
}
}
generatedClass = generationVisitor.generate();
} catch (ClassGenerationException e) {
throw e;
} catch (Throwable e) {
TreeFormatter formatter = new TreeFormatter();
formatter.node("Could not generate a decorated class for type ");
formatter.appendType(type);
formatter.append(".");
throw new ClassGenerationException(formatter.toString(), e);
}
ImmutableList.Builder<Class<? extends Annotation>> annotationsTriggeringServiceInjection = ImmutableList.builder();
for (CustomInjectAnnotationPropertyHandler handler : customAnnotationPropertyHandlers) {
if (handler.isUsed()) {
annotationsTriggeringServiceInjection.add(handler.getAnnotation());
}
}
// This is expensive to calculate, so cache the result
Class<?> enclosingClass = type.getEnclosingClass();
Class<?> outerType;
if (enclosingClass != null && !Modifier.isStatic(type.getModifiers())) {
outerType = enclosingClass;
} else {
outerType = null;
}
return new GeneratedClassImpl(generatedClass, outerType, injectionHandler.getInjectedServices(), annotationsTriggeringServiceInjection.build());
}
Aggregations