use of ru.curs.celesta.score.Parameter in project celesta by CourseOrchestra.
the class CursorGenerator method buildConstructors.
private static List<MethodSpec> buildConstructors(GrainElement ge, TypeName columnsClassType) {
List<MethodSpec> results = new ArrayList<>();
ParameterSpec contextParam = ParameterSpec.builder(CallContext.class, "context").build();
ParameterSpec fieldsParam = ParameterSpec.builder(ParameterizedTypeName.get(Set.class, String.class), "fields").build();
ParameterSpec columnsParam = ParameterSpec.builder(ArrayTypeName.of(ParameterizedTypeName.get(ClassName.get(ColumnMeta.class), WildcardTypeName.subtypeOf(Object.class))), "columns").build();
ParameterSpec parametersParam = ParameterSpec.builder(ParameterizedTypeName.get(Map.class, String.class, Object.class), "parameters").build();
Supplier<MethodSpec.Builder> msp = () -> MethodSpec.constructorBuilder().addModifiers(Modifier.PUBLIC).addParameter(contextParam);
// Common constructor
MethodSpec.Builder builder = msp.get();
if (ge instanceof ParameterizedView) {
builder.addParameter(parametersParam);
builder.addStatement("super(context, parameters)");
} else {
builder.addStatement("super(context)");
}
results.add(builder.build());
if (ge instanceof SequenceElement) {
return results;
}
// Constructor with columns limitation
builder = msp.get();
if (ge instanceof ParameterizedView) {
builder.addParameter(parametersParam);
builder.addParameter(columnsParam).varargs();
builder.addStatement("super(context, parameters, columns)");
} else {
builder.addParameter(columnsParam).varargs();
builder.addStatement("super(context, columns)");
}
results.add(builder.build());
// Deprecated constructor with fields limitation
builder = msp.get();
if (ge instanceof ParameterizedView) {
builder.addParameter(fieldsParam);
builder.addParameter(parametersParam);
builder.addStatement("super(context, fields, parameters)");
} else {
builder.addParameter(fieldsParam);
builder.addStatement("super(context, fields)");
}
results.add(builder.addAnnotation(Deprecated.class).build());
// ParameterizedView constructors
if (ge instanceof ParameterizedView) {
ParameterizedView pv = (ParameterizedView) ge;
builder = msp.get();
for (Parameter parameter : pv.getParameters().values()) {
builder.addParameter(ParameterSpec.builder(parameter.getJavaClass(), parameter.getName()).build());
}
String spec = "super (context, paramsMap(" + pv.getParameters().values().stream().map(c -> "$N").collect(Collectors.joining(", ")) + "))";
builder.addStatement(spec, pv.getParameters().keySet().toArray());
results.add(builder.build());
builder = msp.get();
for (Parameter parameter : pv.getParameters().values()) {
builder.addParameter(ParameterSpec.builder(parameter.getJavaClass(), parameter.getName()).build());
}
builder.addParameter(columnsParam).varargs();
spec = "super (context, paramsMap(" + pv.getParameters().values().stream().map(c -> "$N").collect(Collectors.joining(", ")) + "), columns)";
builder.addStatement(spec, pv.getParameters().keySet().toArray());
results.add(builder.build());
results.add(getParameterizedViewTypedConstructorHelper(pv));
}
return results;
}
use of ru.curs.celesta.score.Parameter in project celesta by CourseOrchestra.
the class CursorGenerator method getParameterizedViewTypedConstructorHelper.
private static MethodSpec getParameterizedViewTypedConstructorHelper(ParameterizedView pv) {
MethodSpec.Builder builder = MethodSpec.methodBuilder("paramsMap").addModifiers(Modifier.PRIVATE, Modifier.STATIC).returns(ParameterizedTypeName.get(Map.class, String.class, Object.class));
builder.addStatement("$T<$T,$T> params = new $T<>()", Map.class, String.class, Object.class, HashMap.class);
for (Parameter parameter : pv.getParameters().values()) {
String paramName = parameter.getName();
builder.addParameter(ParameterSpec.builder(parameter.getJavaClass(), paramName).build());
builder.addStatement("params.put($S, $N)", paramName, paramName);
}
builder.addStatement("return params");
return builder.build();
}
Aggregations