Search in sources :

Example 6 with DeclaredTypeName

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);
}
Also used : DeclaredTypeName(com.yahoo.aptutils.model.DeclaredTypeName)

Example 7 with DeclaredTypeName

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);
    }
}
Also used : DeclaredTypeName(com.yahoo.aptutils.model.DeclaredTypeName) TypeName(com.yahoo.aptutils.model.TypeName) DeclaredTypeName(com.yahoo.aptutils.model.DeclaredTypeName) Expression(com.yahoo.aptutils.writer.expressions.Expression) ArrayList(java.util.ArrayList)

Example 8 with DeclaredTypeName

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);
}
Also used : DeclaredTypeName(com.yahoo.aptutils.model.DeclaredTypeName) Expression(com.yahoo.aptutils.writer.expressions.Expression)

Example 9 with DeclaredTypeName

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;
}
Also used : DeclaredTypeName(com.yahoo.aptutils.model.DeclaredTypeName)

Example 10 with DeclaredTypeName

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();
}
Also used : DeclaredTypeName(com.yahoo.aptutils.model.DeclaredTypeName)

Aggregations

DeclaredTypeName (com.yahoo.aptutils.model.DeclaredTypeName)12 Expression (com.yahoo.aptutils.writer.expressions.Expression)3 ArrayList (java.util.ArrayList)3 TypeName (com.yahoo.aptutils.model.TypeName)2 MethodDeclarationParameters (com.yahoo.aptutils.writer.parameters.MethodDeclarationParameters)2 TypeElement (javax.lang.model.element.TypeElement)2 VariableElement (javax.lang.model.element.VariableElement)2 TypeDeclarationParameters (com.yahoo.aptutils.writer.parameters.TypeDeclarationParameters)1 Implements (com.yahoo.squidb.annotations.Implements)1 ErrorInfo (com.yahoo.squidb.processor.data.ErrorInfo)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 AnnotationMirror (javax.lang.model.element.AnnotationMirror)1 AnnotationValue (javax.lang.model.element.AnnotationValue)1 Element (javax.lang.model.element.Element)1