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