private void emitSqlTableDeclaration(boolean view) throws IOException { writer.writeComment("--- " + (view ? "view" : "subquery") + " declaration"); String name = "\"" + modelSpec.viewName() + "\""; if (queryElement != null) { Expression queryReference = Expressions.staticReference(sourceElementName, queryElement.getSimpleName().toString()) .callMethod("selectMore", ALIASED_PROPERTY_ARRAY_NAME); if (viewQueryAnnotation.freeze()) { queryReference = queryReference.callMethod("freeze"); } writer.writeFieldDeclaration( TypeConstants.QUERY, QUERY_NAME, queryReference, TypeConstants.PUBLIC_STATIC_FINAL); Expression initializer = constructInitializer(name, view); writer.writeFieldDeclaration( view ? TypeConstants.VIEW : TypeConstants.SUBQUERY_TABLE, view ? VIEW_NAME : SUBQUERY_NAME, initializer, TypeConstants.PUBLIC_STATIC_FINAL); } else { writer.writeFieldDeclaration( CoreTypes.JAVA_STRING, view ? "VIEW_NAME" : "SUBQUERY_NAME", Expressions.fromString(name), TypeConstants.PUBLIC_STATIC_FINAL); } writer.writeNewline(); }
private boolean emitPropertyReferenceArrayBody(boolean alias) throws IOException { for (PropertyGenerator e : propertyGenerators) { Expression reference = Expressions.staticReference(sourceElementName, e.getPropertyName()); if (alias) { Alias aliasAnnotation = e.getElement().getAnnotation(Alias.class); if (aliasAnnotation != null && !AptUtils.isEmpty(aliasAnnotation.value())) { reference = reference.callMethod("as", "\"" + aliasAnnotation.value() + "\""); } } writer.writeExpression(reference); writer.appendString(",\n"); } return !AptUtils.isEmpty(propertyGenerators); }
private void emitSinglePropertyDeclaration(PropertyGenerator generator, int index) throws IOException { generator.beforeEmitPropertyDeclaration(writer); DeclaredTypeName type = generator.getPropertyType(); String fieldToQualify = ALIASED_PROPERTY_ARRAY_NAME + "[" + index + "]"; Expression expressionToCast; if (queryElement != null) { String callOn = modelSpec.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(); generator.afterEmitPropertyDeclaration(writer); }