use of com.yahoo.aptutils.model.DeclaredTypeName in project squidb by yahoo.
the class PropertyGenerator method registerRequiredImports.
/**
* @param imports an accumulator set of type names to import
*/
public void registerRequiredImports(Set<DeclaredTypeName> imports) {
imports.add(getPropertyType());
DeclaredTypeName accessorType = getTypeForAccessors();
if (!TypeConstants.isPrimitiveType(accessorType)) {
imports.add(accessorType);
}
registerAdditionalImports(imports);
}
use of com.yahoo.aptutils.model.DeclaredTypeName in project squidb by yahoo.
the class JSONPropertyGenerator method getTypeExpression.
private Expression getTypeExpression(DeclaredTypeName fieldType) {
List<? extends TypeName> typeArgs = fieldType.getTypeArgs();
if (AptUtils.isEmpty(typeArgs)) {
return Expressions.classObject(fieldType);
} else {
List<Expression> parameterizedTypeBuilderArgs = new ArrayList<>();
parameterizedTypeBuilderArgs.add(Expressions.classObject(fieldType));
for (TypeName typeArg : typeArgs) {
// The cast to DeclaredTypeName is safe because we recursively check all type args before constructing
// an instance of this property generator
parameterizedTypeBuilderArgs.add(getTypeExpression((DeclaredTypeName) typeArg));
}
return Expressions.staticMethod(JSONTypes.PARAMETERIZED_TYPE_BUILDER, "build", parameterizedTypeBuilderArgs);
}
}
use of com.yahoo.aptutils.model.DeclaredTypeName in project squidb by yahoo.
the class ViewModelFileWriter method emitSinglePropertyDeclaration.
private void emitSinglePropertyDeclaration(PropertyGenerator generator, int index) throws IOException {
modelSpec.getPluginBundle().beforeEmitPropertyDeclaration(writer, generator);
DeclaredTypeName type = generator.getPropertyType();
String fieldToQualify = ALIASED_PROPERTY_ARRAY_NAME + "[" + index + "]";
Expression expressionToCast;
if (modelSpec.getQueryElement() != null) {
String callOn = modelSpec.getSpecAnnotation().isSubquery() ? SUBQUERY_NAME : VIEW_NAME;
expressionToCast = Expressions.callMethodOn(callOn, "qualifyField", fieldToQualify);
} else {
expressionToCast = Expressions.reference(fieldToQualify);
}
writer.writeFieldDeclaration(type, generator.getPropertyName(), expressionToCast.cast(type), TypeConstants.PUBLIC_STATIC_FINAL).writeNewline();
modelSpec.getPluginBundle().afterEmitPropertyDeclaration(writer, generator);
}
use of com.yahoo.aptutils.model.DeclaredTypeName in project squidb by yahoo.
the class EnumPropertyGenerator method getPropertyType.
@Override
public DeclaredTypeName getPropertyType() {
DeclaredTypeName enumProperty = ENUM_PROPERTY.clone();
enumProperty.setTypeArgs(Collections.singletonList(enumType));
return enumProperty;
}
use of com.yahoo.aptutils.model.DeclaredTypeName in project squidb by yahoo.
the class AndroidModelPlugin method afterEmitMethods.
@Override
public void afterEmitMethods(JavaFileWriter writer) throws IOException {
// emit creator for parcelable
writer.writeComment("--- parcelable helpers");
List<DeclaredTypeName> genericList = Collections.singletonList(modelSpec.getGeneratedClassName());
DeclaredTypeName creatorType = TypeConstants.CREATOR.clone();
DeclaredTypeName modelCreatorType = TypeConstants.MODEL_CREATOR.clone();
creatorType.setTypeArgs(genericList);
modelCreatorType.setTypeArgs(genericList);
writer.writeFieldDeclaration(creatorType, "CREATOR", Expressions.callConstructor(modelCreatorType, Expressions.classObject(modelSpec.getGeneratedClassName())), TypeConstants.PUBLIC_STATIC_FINAL).writeNewline();
}
Aggregations