Skip to content

Commit 461ea44

Browse files
MiloszSobczykcopybara-github
authored andcommitted
refactor: standardize AutoValue Builder setter names
Updates AutoValue Builders to use the `property(value)` naming convention for setters, instead of the `setProperty(value)` convention. This change promotes consistency across the codebase. Deprecated `setProperty()` methods are retained where necessary for backward compatibility, and now delegate to the new `property()` methods. PiperOrigin-RevId: 889256135
1 parent b064539 commit 461ea44

File tree

5 files changed

+356
-79
lines changed

5 files changed

+356
-79
lines changed

core/src/main/java/com/google/adk/agents/RunConfig.java

Lines changed: 80 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -76,59 +76,115 @@ public enum ToolExecutionMode {
7676

7777
public static Builder builder() {
7878
return new AutoValue_RunConfig.Builder()
79-
.setSaveInputBlobsAsArtifacts(false)
80-
.setResponseModalities(ImmutableList.of())
81-
.setStreamingMode(StreamingMode.NONE)
82-
.setToolExecutionMode(ToolExecutionMode.NONE)
83-
.setMaxLlmCalls(500)
84-
.setAutoCreateSession(false);
79+
.saveInputBlobsAsArtifacts(false)
80+
.responseModalities(ImmutableList.of())
81+
.streamingMode(StreamingMode.NONE)
82+
.toolExecutionMode(ToolExecutionMode.NONE)
83+
.maxLlmCalls(500)
84+
.autoCreateSession(false);
8585
}
8686

8787
public static Builder builder(RunConfig runConfig) {
8888
return new AutoValue_RunConfig.Builder()
89-
.setSaveInputBlobsAsArtifacts(runConfig.saveInputBlobsAsArtifacts())
90-
.setStreamingMode(runConfig.streamingMode())
91-
.setToolExecutionMode(runConfig.toolExecutionMode())
92-
.setMaxLlmCalls(runConfig.maxLlmCalls())
93-
.setResponseModalities(runConfig.responseModalities())
94-
.setSpeechConfig(runConfig.speechConfig())
95-
.setOutputAudioTranscription(runConfig.outputAudioTranscription())
96-
.setInputAudioTranscription(runConfig.inputAudioTranscription())
97-
.setAutoCreateSession(runConfig.autoCreateSession());
89+
.saveInputBlobsAsArtifacts(runConfig.saveInputBlobsAsArtifacts())
90+
.streamingMode(runConfig.streamingMode())
91+
.toolExecutionMode(runConfig.toolExecutionMode())
92+
.maxLlmCalls(runConfig.maxLlmCalls())
93+
.responseModalities(runConfig.responseModalities())
94+
.speechConfig(runConfig.speechConfig())
95+
.outputAudioTranscription(runConfig.outputAudioTranscription())
96+
.inputAudioTranscription(runConfig.inputAudioTranscription())
97+
.autoCreateSession(runConfig.autoCreateSession());
9898
}
9999

100100
/** Builder for {@link RunConfig}. */
101101
@AutoValue.Builder
102102
public abstract static class Builder {
103103

104+
@Deprecated
104105
@CanIgnoreReturnValue
105-
public abstract Builder setSpeechConfig(@Nullable SpeechConfig speechConfig);
106+
public final Builder setSpeechConfig(@Nullable SpeechConfig speechConfig) {
107+
return speechConfig(speechConfig);
108+
}
109+
110+
@CanIgnoreReturnValue
111+
public abstract Builder speechConfig(@Nullable SpeechConfig speechConfig);
112+
113+
@Deprecated
114+
@CanIgnoreReturnValue
115+
public final Builder setResponseModalities(Iterable<Modality> responseModalities) {
116+
return responseModalities(responseModalities);
117+
}
118+
119+
@CanIgnoreReturnValue
120+
public abstract Builder responseModalities(Iterable<Modality> responseModalities);
106121

122+
@Deprecated
107123
@CanIgnoreReturnValue
108-
public abstract Builder setResponseModalities(Iterable<Modality> responseModalities);
124+
public final Builder setSaveInputBlobsAsArtifacts(boolean saveInputBlobsAsArtifacts) {
125+
return saveInputBlobsAsArtifacts(saveInputBlobsAsArtifacts);
126+
}
109127

110128
@CanIgnoreReturnValue
111-
public abstract Builder setSaveInputBlobsAsArtifacts(boolean saveInputBlobsAsArtifacts);
129+
public abstract Builder saveInputBlobsAsArtifacts(boolean saveInputBlobsAsArtifacts);
112130

131+
@Deprecated
113132
@CanIgnoreReturnValue
114-
public abstract Builder setStreamingMode(StreamingMode streamingMode);
133+
public final Builder setStreamingMode(StreamingMode streamingMode) {
134+
return streamingMode(streamingMode);
135+
}
115136

116137
@CanIgnoreReturnValue
117-
public abstract Builder setToolExecutionMode(ToolExecutionMode toolExecutionMode);
138+
public abstract Builder streamingMode(StreamingMode streamingMode);
118139

140+
@Deprecated
119141
@CanIgnoreReturnValue
120-
public abstract Builder setOutputAudioTranscription(
142+
public final Builder setToolExecutionMode(ToolExecutionMode toolExecutionMode) {
143+
return toolExecutionMode(toolExecutionMode);
144+
}
145+
146+
@CanIgnoreReturnValue
147+
public abstract Builder toolExecutionMode(ToolExecutionMode toolExecutionMode);
148+
149+
@Deprecated
150+
@CanIgnoreReturnValue
151+
public final Builder setOutputAudioTranscription(
152+
@Nullable AudioTranscriptionConfig outputAudioTranscription) {
153+
return outputAudioTranscription(outputAudioTranscription);
154+
}
155+
156+
@CanIgnoreReturnValue
157+
public abstract Builder outputAudioTranscription(
121158
@Nullable AudioTranscriptionConfig outputAudioTranscription);
122159

160+
@Deprecated
161+
@CanIgnoreReturnValue
162+
public final Builder setInputAudioTranscription(
163+
@Nullable AudioTranscriptionConfig inputAudioTranscription) {
164+
return inputAudioTranscription(inputAudioTranscription);
165+
}
166+
123167
@CanIgnoreReturnValue
124-
public abstract Builder setInputAudioTranscription(
168+
public abstract Builder inputAudioTranscription(
125169
@Nullable AudioTranscriptionConfig inputAudioTranscription);
126170

171+
@Deprecated
127172
@CanIgnoreReturnValue
128-
public abstract Builder setMaxLlmCalls(int maxLlmCalls);
173+
public final Builder setMaxLlmCalls(int maxLlmCalls) {
174+
return maxLlmCalls(maxLlmCalls);
175+
}
176+
177+
@CanIgnoreReturnValue
178+
public abstract Builder maxLlmCalls(int maxLlmCalls);
179+
180+
@Deprecated
181+
@CanIgnoreReturnValue
182+
public final Builder setAutoCreateSession(boolean autoCreateSession) {
183+
return autoCreateSession(autoCreateSession);
184+
}
129185

130186
@CanIgnoreReturnValue
131-
public abstract Builder setAutoCreateSession(boolean autoCreateSession);
187+
public abstract Builder autoCreateSession(boolean autoCreateSession);
132188

133189
abstract RunConfig autoBuild();
134190

core/src/main/java/com/google/adk/memory/SearchMemoryResponse.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.google.auto.value.AutoValue;
2020
import com.google.common.collect.ImmutableList;
21+
import com.google.errorprone.annotations.CanIgnoreReturnValue;
2122
import java.util.List;
2223

2324
/** Represents the response from a memory search. */
@@ -29,20 +30,28 @@ public abstract class SearchMemoryResponse {
2930

3031
/** Creates a new builder for {@link SearchMemoryResponse}. */
3132
public static Builder builder() {
32-
return new AutoValue_SearchMemoryResponse.Builder().setMemories(ImmutableList.of());
33+
return new AutoValue_SearchMemoryResponse.Builder().memories(ImmutableList.of());
3334
}
3435

3536
/** Builder for {@link SearchMemoryResponse}. */
3637
@AutoValue.Builder
3738
public abstract static class Builder {
3839

39-
abstract Builder setMemories(ImmutableList<MemoryEntry> memories);
40+
@Deprecated
41+
@CanIgnoreReturnValue
42+
public final Builder setMemories(ImmutableList<MemoryEntry> memories) {
43+
return memories(memories);
44+
}
4045

4146
/** Sets the list of memory entries using a list. */
42-
public Builder setMemories(List<MemoryEntry> memories) {
43-
return setMemories(ImmutableList.copyOf(memories));
47+
@CanIgnoreReturnValue
48+
public Builder memories(List<MemoryEntry> memories) {
49+
return memories(ImmutableList.copyOf(memories));
4450
}
4551

52+
@CanIgnoreReturnValue
53+
public abstract Builder memories(ImmutableList<MemoryEntry> memories);
54+
4655
/** Builds the immutable {@link SearchMemoryResponse} object. */
4756
public abstract SearchMemoryResponse build();
4857
}

core/src/main/java/com/google/adk/models/VertexCredentials.java

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.google.auth.oauth2.GoogleCredentials;
2020
import com.google.auto.value.AutoValue;
21+
import com.google.errorprone.annotations.CanIgnoreReturnValue;
2122
import java.util.Optional;
2223
import org.jspecify.annotations.Nullable;
2324

@@ -39,11 +40,32 @@ public static Builder builder() {
3940
@AutoValue.Builder
4041
public abstract static class Builder {
4142

42-
public abstract Builder setProject(@Nullable String value);
43+
@Deprecated
44+
@CanIgnoreReturnValue
45+
public final Builder setProject(@Nullable String value) {
46+
return project(value);
47+
}
4348

44-
public abstract Builder setLocation(@Nullable String value);
49+
@CanIgnoreReturnValue
50+
public abstract Builder project(@Nullable String value);
4551

46-
public abstract Builder setCredentials(@Nullable GoogleCredentials value);
52+
@Deprecated
53+
@CanIgnoreReturnValue
54+
public final Builder setLocation(@Nullable String value) {
55+
return location(value);
56+
}
57+
58+
@CanIgnoreReturnValue
59+
public abstract Builder location(@Nullable String value);
60+
61+
@Deprecated
62+
@CanIgnoreReturnValue
63+
public final Builder setCredentials(@Nullable GoogleCredentials value) {
64+
return credentials(value);
65+
}
66+
67+
@CanIgnoreReturnValue
68+
public abstract Builder credentials(@Nullable GoogleCredentials value);
4769

4870
public abstract VertexCredentials build();
4971
}

0 commit comments

Comments
 (0)