144 references to WriteLine
Aspire.Hosting.CodeGeneration.Java (144)
AtsJavaCodeGenerator.cs (144)
96WriteLine("// Aspire.java - Capability-based Aspire SDK"); 97WriteLine("// GENERATED CODE - DO NOT EDIT"); 98WriteLine(); 99WriteLine("package aspire;"); 100WriteLine(); 101WriteLine("import java.util.*;"); 102WriteLine("import java.util.function.*;"); 103WriteLine(); 118WriteLine("// ============================================================================"); 119WriteLine("// Enums"); 120WriteLine("// ============================================================================"); 121WriteLine(); 131WriteLine($"/** {enumType.Name} enum. */"); 132WriteLine($"enum {enumName} {{"); 139WriteLine($" {memberName}(\"{member}\"){suffix}"); 141WriteLine(); 142WriteLine(" private final String value;"); 143WriteLine(); 144WriteLine($" {enumName}(String value) {{"); 145WriteLine(" this.value = value;"); 146WriteLine(" }"); 147WriteLine(); 148WriteLine(" public String getValue() { return value; }"); 149WriteLine(); 150WriteLine($" public static {enumName} fromValue(String value) {{"); 151WriteLine($" for ({enumName} e : values()) {{"); 152WriteLine(" if (e.value.equals(value)) return e;"); 153WriteLine(" }"); 154WriteLine(" throw new IllegalArgumentException(\"Unknown value: \" + value);"); 155WriteLine(" }"); 156WriteLine("}"); 157WriteLine(); 168WriteLine("// ============================================================================"); 169WriteLine("// DTOs"); 170WriteLine("// ============================================================================"); 171WriteLine(); 182WriteLine($"/** {dto.Name} DTO. */"); 183WriteLine($"class {dtoName} {{"); 190WriteLine($" private {fieldType} {fieldName};"); 192WriteLine(); 201WriteLine($" public {fieldType} get{methodName}() {{ return {fieldName}; }}"); 202WriteLine($" public void set{methodName}({fieldType} value) {{ this.{fieldName} = value; }}"); 204WriteLine(); 207WriteLine(" public Map<String, Object> toMap() {"); 208WriteLine(" Map<String, Object> map = new HashMap<>();"); 212WriteLine($" map.put(\"{property.Name}\", AspireClient.serializeValue({fieldName}));"); 214WriteLine(" return map;"); 215WriteLine(" }"); 217WriteLine("}"); 218WriteLine(); 231WriteLine("// ============================================================================"); 232WriteLine("// Handle Wrappers"); 233WriteLine("// ============================================================================"); 234WriteLine(); 239WriteLine($"/** Wrapper for {handleType.TypeId}. */"); 240WriteLine($"class {handleType.ClassName} extends {baseClass} {{"); 241WriteLine($" {handleType.ClassName}(Handle handle, AspireClient client) {{"); 242WriteLine(" super(handle, client);"); 243WriteLine(" }"); 244WriteLine(); 254WriteLine("}"); 255WriteLine(); 297WriteLine($" /** {capability.Description} */"); 300WriteLine($" public {returnType} {methodName}({paramList}) {{"); 301WriteLine(" Map<String, Object> reqArgs = new HashMap<>();"); 302WriteLine($" reqArgs.put(\"{targetParamName}\", AspireClient.serializeValue(getHandle()));"); 309WriteLine($" if ({paramName} != null) {{"); 310WriteLine($" reqArgs.put(\"{parameter.Name}\", getClient().registerCallback({paramName}));"); 311WriteLine(" }"); 317WriteLine($" if ({paramName} != null) {{"); 318WriteLine($" reqArgs.put(\"{parameter.Name}\", getClient().registerCancellation({paramName}));"); 319WriteLine(" }"); 325WriteLine($" if ({paramName} != null) {{"); 326WriteLine($" reqArgs.put(\"{parameter.Name}\", AspireClient.serializeValue({paramName}));"); 327WriteLine(" }"); 331WriteLine($" reqArgs.put(\"{parameter.Name}\", AspireClient.serializeValue({paramName}));"); 337WriteLine($" return ({returnType}) getClient().invokeCapability(\"{capability.CapabilityId}\", reqArgs);"); 341WriteLine($" getClient().invokeCapability(\"{capability.CapabilityId}\", reqArgs);"); 344WriteLine(" }"); 345WriteLine(); 389WriteLine($" /** {capability.Description} */"); 393WriteLine($" private {fullType} {fieldName};"); 394WriteLine($" public {fullType} {methodName}() {{"); 395WriteLine($" if ({fieldName} == null) {{"); 396WriteLine($" {fieldName} = new {wrapperType}<>(getHandle(), getClient(), \"{capability.CapabilityId}\");"); 397WriteLine(" }"); 398WriteLine($" return {fieldName};"); 399WriteLine(" }"); 400WriteLine(); 423WriteLine("// ============================================================================"); 424WriteLine("// Handle wrapper registrations"); 425WriteLine("// ============================================================================"); 426WriteLine(); 427WriteLine("/** Static initializer to register handle wrappers. */"); 428WriteLine("class AspireRegistrations {"); 429WriteLine(" static {"); 433WriteLine($" AspireClient.registerHandleWrapper(\"{handleType.TypeId}\", (h, c) -> new {handleType.ClassName}(h, c));"); 439WriteLine($" AspireClient.registerHandleWrapper(\"{typeId}\", (h, c) -> new {wrapperType}(h, c));"); 442WriteLine(" }"); 443WriteLine(); 444WriteLine(" static void ensureRegistered() {"); 445WriteLine(" // Called to trigger static initializer"); 446WriteLine(" }"); 447WriteLine("}"); 448WriteLine(); 457WriteLine("// ============================================================================"); 458WriteLine("// Connection Helpers"); 459WriteLine("// ============================================================================"); 460WriteLine(); 461WriteLine("/** Main entry point for Aspire SDK. */"); 462WriteLine("public class Aspire {"); 463WriteLine(" /** Connect to the AppHost server. */"); 464WriteLine(" public static AspireClient connect() throws Exception {"); 465WriteLine(" AspireRegistrations.ensureRegistered();"); 466WriteLine(" String socketPath = System.getenv(\"REMOTE_APP_HOST_SOCKET_PATH\");"); 467WriteLine(" if (socketPath == null || socketPath.isEmpty()) {"); 468WriteLine(" throw new RuntimeException(\"REMOTE_APP_HOST_SOCKET_PATH environment variable not set. Run this application using `aspire run`.\");"); 469WriteLine(" }"); 470WriteLine(" AspireClient client = new AspireClient(socketPath);"); 471WriteLine(" client.connect();"); 472WriteLine(" client.onDisconnect(() -> System.exit(1));"); 473WriteLine(" return client;"); 474WriteLine(" }"); 475WriteLine(); 476WriteLine($" /** Create a new distributed application builder. */"); 477WriteLine($" public static {builderClassName} createBuilder(CreateBuilderOptions options) throws Exception {{"); 478WriteLine(" AspireClient client = connect();"); 479WriteLine(" Map<String, Object> resolvedOptions = new HashMap<>();"); 480WriteLine(" if (options != null) {"); 481WriteLine(" resolvedOptions.putAll(options.toMap());"); 482WriteLine(" }"); 483WriteLine(" if (!resolvedOptions.containsKey(\"Args\")) {"); 484WriteLine(" // Note: Java doesn't have easy access to command line args from here"); 485WriteLine(" resolvedOptions.put(\"Args\", new String[0]);"); 486WriteLine(" }"); 487WriteLine(" if (!resolvedOptions.containsKey(\"ProjectDirectory\")) {"); 488WriteLine(" resolvedOptions.put(\"ProjectDirectory\", System.getProperty(\"user.dir\"));"); 489WriteLine(" }"); 490WriteLine(" Map<String, Object> args = new HashMap<>();"); 491WriteLine(" args.put(\"options\", resolvedOptions);"); 492WriteLine($" return ({builderClassName}) client.invokeCapability(\"Aspire.Hosting/createBuilderWithOptions\", args);"); 493WriteLine(" }"); 494WriteLine("}"); 495WriteLine();