use of com.yahoo.aptutils.writer.expressions.Expression in project squidb by yahoo.
the class EnumPropertyGenerator method writeSetterBody.
@Override
protected void writeSetterBody(JavaFileWriter writer, MethodDeclarationParameters params) throws IOException {
String argName = params.getArgumentNames().get(0);
final String argAsString = argName + "AsString";
Expression condition = Expressions.fromString(argName + " == null");
Expression ifTrue = Expressions.fromString("null");
Expression ifFalse = Expressions.callMethodOn(argName, "name");
writer.writeFieldDeclaration(CoreTypes.JAVA_STRING, argAsString, new TernaryExpression(condition, ifTrue, ifFalse));
writer.writeStatement(Expressions.callMethod("set", propertyName, argAsString));
writer.writeStringStatement("return this");
}
use of com.yahoo.aptutils.writer.expressions.Expression in project squidb by yahoo.
the class ModelMethodPlugin method emitModelMethod.
private void emitModelMethod(JavaFileWriter writer, ExecutableElement e, Modifier... modifiers) throws IOException {
MethodDeclarationParameters params = utils.methodDeclarationParamsFromExecutableElement(e, modifiers);
ModelMethod methodAnnotation = e.getAnnotation(ModelMethod.class);
List<Object> arguments = new ArrayList<>();
if (methodAnnotation != null) {
String name = methodAnnotation.name();
if (!AptUtils.isEmpty(name)) {
params.setMethodName(name);
}
params.getArgumentTypes().remove(0);
params.getArgumentNames().remove(0);
arguments.add(0, "this");
}
arguments.addAll(params.getArgumentNames());
Expression methodCall = Expressions.staticMethod(modelSpec.getModelSpecName(), e.getSimpleName().toString(), arguments);
if (!CoreTypes.VOID.equals(params.getReturnType())) {
methodCall = methodCall.returnExpr();
}
JavadocPlugin.writeJavadocFromElement(pluginEnv, writer, e);
writer.beginMethodDefinition(params).writeStatement(methodCall).finishMethodDefinition();
}
Aggregations